[TD]add light text on dark page mode

- some visually impaired users need white graphics on
  dark page.

- revise Annotation dialog to respect dark style
This commit is contained in:
wandererfan
2022-12-17 07:41:37 -05:00
committed by WandererFan
parent ed8e45ac9b
commit d63ac0f7f6
34 changed files with 3257 additions and 2160 deletions

View File

@@ -23,9 +23,9 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <iostream>
# include <sstream>
# include <Precision.hxx>
#include <Precision.hxx>
#include <iostream>
#include <sstream>
#endif
#include <App/Application.h>
@@ -34,7 +34,7 @@
#include <Base/Parameter.h>
#include "DrawPage.h"
#include "DrawPagePy.h" // generated from DrawPagePy.xml
#include "DrawPagePy.h"// generated from DrawPagePy.xml
#include "DrawProjGroup.h"
#include "DrawTemplate.h"
#include "DrawView.h"
@@ -50,49 +50,59 @@ using namespace TechDraw;
// DrawPage
//===========================================================================
App::PropertyFloatConstraint::Constraints DrawPage::scaleRange = {Precision::Confusion(),
std::numeric_limits<double>::max(),
(0.1)}; // increment by 0.1
App::PropertyFloatConstraint::Constraints DrawPage::scaleRange = {
Precision::Confusion(), std::numeric_limits<double>::max(), (0.1)};// increment by 0.1
PROPERTY_SOURCE(TechDraw::DrawPage, App::DocumentObject)
const char* DrawPage::ProjectionTypeEnums[] = { "First Angle",
"Third Angle",
nullptr };
const char* DrawPage::ProjectionTypeEnums[] = {"First Angle", "Third Angle", nullptr};
DrawPage::DrawPage(void)
{
static const char *group = "Page";
static const char* group = "Page";
nowUnsetting = false;
forceRedraw(false);
ADD_PROPERTY_TYPE(KeepUpdated, (Preferences::keepPagesUpToDate()),
group, (App::PropertyType)(App::Prop_Output), "Keep page in sync with model");
ADD_PROPERTY_TYPE(Template, (nullptr), group, (App::PropertyType)(App::Prop_None), "Attached Template");
ADD_PROPERTY_TYPE(KeepUpdated,
(Preferences::keepPagesUpToDate()),
group,
(App::PropertyType)(App::Prop_Output),
"Keep page in sync with model");
ADD_PROPERTY_TYPE(
Template, (nullptr), group, (App::PropertyType)(App::Prop_None), "Attached Template");
Template.setScope(App::LinkScope::Global);
ADD_PROPERTY_TYPE(Views, (nullptr), group, (App::PropertyType)(App::Prop_None), "Attached Views");
ADD_PROPERTY_TYPE(
Views, (nullptr), group, (App::PropertyType)(App::Prop_None), "Attached Views");
Views.setScope(App::LinkScope::Global);
// Projection Properties
ProjectionType.setEnums(ProjectionTypeEnums);
ADD_PROPERTY(ProjectionType, ((long)Preferences::projectionAngle()));
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/TechDraw/General");
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
double defScale = hGrp->GetFloat("DefaultScale", 1.0);
ADD_PROPERTY_TYPE(Scale, (defScale), group, (App::PropertyType)(App::Prop_None), "Scale factor for this Page");
ADD_PROPERTY_TYPE(Scale,
(defScale),
group,
(App::PropertyType)(App::Prop_None),
"Scale factor for this Page");
ADD_PROPERTY_TYPE(NextBalloonIndex, (1), group, (App::PropertyType)(App::Prop_None),
"Auto-numbering for Balloons");
ADD_PROPERTY_TYPE(NextBalloonIndex,
(1),
group,
(App::PropertyType)(App::Prop_None),
"Auto-numbering for Balloons");
Scale.setConstraints(&scaleRange);
balloonParent = nullptr;
}
DrawPage::~DrawPage()
{
}
{}
void DrawPage::onBeforeChange(const App::Property* prop)
{
@@ -101,53 +111,56 @@ void DrawPage::onBeforeChange(const App::Property* prop)
void DrawPage::onChanged(const App::Property* prop)
{
if ((prop == &KeepUpdated) &&
KeepUpdated.getValue()) {
if (!isRestoring() &&
!isUnsetting()) {
if ((prop == &KeepUpdated) && KeepUpdated.getValue()) {
if (!isRestoring() && !isUnsetting()) {
//would be nice if this message was displayed immediately instead of after the recomputeFeature
Base::Console().Message("Rebuilding Views for: %s/%s\n", getNameInDocument(), Label.getValue());
Base::Console().Message(
"Rebuilding Views for: %s/%s\n", getNameInDocument(), Label.getValue());
updateAllViews();
purgeTouched();
}
} else if (prop == &Template) {
if (!isRestoring() &&
!isUnsetting()) {
}
else if (prop == &Template) {
if (!isRestoring() && !isUnsetting()) {
//nothing to page to do??
}
} else if(prop == &Scale) {
}
else if (prop == &Scale) {
// touch all views in the Page as they may be dependent on this scale
// WF: not sure this loop is required. Views figure out their scale as required. but maybe
// this is needed just to mark the Views to recompute??
if (!isRestoring()) {
const std::vector<App::DocumentObject*> &vals = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = vals.begin(); it < vals.end(); ++it) {
TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(*it);
const std::vector<App::DocumentObject*>& vals = Views.getValues();
for (std::vector<App::DocumentObject*>::const_iterator it = vals.begin();
it < vals.end();
++it) {
TechDraw::DrawView* view = dynamic_cast<TechDraw::DrawView*>(*it);
if (view && view->ScaleType.isValue("Page")) {
if(std::abs(view->Scale.getValue() - Scale.getValue()) > FLT_EPSILON) {
view->Scale.setValue(Scale.getValue());
if (std::abs(view->Scale.getValue() - Scale.getValue()) > FLT_EPSILON) {
view->Scale.setValue(Scale.getValue());
}
}
}
}
} else if (prop == &ProjectionType) {
// touch all ortho views in the Page as they may be dependent on Projection Type //(is this true?)
const std::vector<App::DocumentObject*> &vals = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = vals.begin(); it < vals.end(); ++it) {
TechDraw::DrawProjGroup *view = dynamic_cast<TechDraw::DrawProjGroup *>(*it);
if (view && view->ProjectionType.isValue("Default")) {
view->ProjectionType.touch();
}
}
// TODO: Also update Template graphic.
}
else if (prop == &ProjectionType) {
// touch all ortho views in the Page as they may be dependent on Projection Type //(is this true?)
const std::vector<App::DocumentObject*>& vals = Views.getValues();
for (std::vector<App::DocumentObject*>::const_iterator it = vals.begin(); it < vals.end();
++it) {
TechDraw::DrawProjGroup* view = dynamic_cast<TechDraw::DrawProjGroup*>(*it);
if (view && view->ProjectionType.isValue("Default")) {
view->ProjectionType.touch();
}
}
// TODO: Also update Template graphic.
}
App::DocumentObject::onChanged(prop);
}
//Page is just a container. It doesn't "do" anything.
App::DocumentObjectExecReturn *DrawPage::execute(void)
App::DocumentObjectExecReturn* DrawPage::execute(void)
{
return App::DocumentObject::execute();
}
@@ -157,10 +170,8 @@ short DrawPage::mustExecute() const
{
short result = 0;
if (!isRestoring()) {
result = (Views.isTouched() ||
Scale.isTouched() ||
ProjectionType.isTouched() ||
Template.isTouched());
result = (Views.isTouched() || Scale.isTouched() || ProjectionType.isTouched()
|| Template.isTouched());
if (result) {
return result;
}
@@ -168,9 +179,9 @@ short DrawPage::mustExecute() const
return App::DocumentObject::mustExecute();
}
PyObject *DrawPage::getPyObject(void)
PyObject* DrawPage::getPyObject(void)
{
if (PythonObject.is(Py::_None())){
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new DrawPagePy(this), true);
}
@@ -180,13 +191,12 @@ PyObject *DrawPage::getPyObject(void)
bool DrawPage::hasValidTemplate() const
{
App::DocumentObject *obj = nullptr;
App::DocumentObject* obj = nullptr;
obj = Template.getValue();
if(obj && obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate *templ = static_cast<TechDraw::DrawTemplate *>(obj);
if (templ->getWidth() > 0. &&
templ->getHeight() > 0.) {
if (obj && obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate* templ = static_cast<TechDraw::DrawTemplate*>(obj);
if (templ->getWidth() > 0. && templ->getHeight() > 0.) {
return true;
}
}
@@ -196,11 +206,11 @@ bool DrawPage::hasValidTemplate() const
double DrawPage::getPageWidth() const
{
App::DocumentObject *obj = nullptr;
App::DocumentObject* obj = nullptr;
obj = Template.getValue();
if( obj && obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId()) ) {
TechDraw::DrawTemplate *templ = static_cast<TechDraw::DrawTemplate *>(obj);
if (obj && obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate* templ = static_cast<TechDraw::DrawTemplate*>(obj);
return templ->getWidth();
}
@@ -209,12 +219,12 @@ double DrawPage::getPageWidth() const
double DrawPage::getPageHeight() const
{
App::DocumentObject *obj = nullptr;
App::DocumentObject* obj = nullptr;
obj = Template.getValue();
if(obj) {
if(obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate *templ = static_cast<TechDraw::DrawTemplate *>(obj);
if (obj) {
if (obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate* templ = static_cast<TechDraw::DrawTemplate*>(obj);
return templ->getHeight();
}
}
@@ -223,16 +233,16 @@ double DrawPage::getPageHeight() const
}
//orientation as text
const char * DrawPage::getPageOrientation() const
const char* DrawPage::getPageOrientation() const
{
App::DocumentObject *obj;
App::DocumentObject* obj;
obj = Template.getValue();
if(obj) {
if(obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate *templ = static_cast<TechDraw::DrawTemplate *>(obj);
if (obj) {
if (obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate* templ = static_cast<TechDraw::DrawTemplate*>(obj);
return templ->Orientation.getValueAsString();
return templ->Orientation.getValueAsString();
}
}
throw Base::RuntimeError("Template not set for Page");
@@ -241,41 +251,43 @@ const char * DrawPage::getPageOrientation() const
//orientation as 0(Portrait) or 1(Landscape)
int DrawPage::getOrientation() const
{
App::DocumentObject *obj;
App::DocumentObject* obj;
obj = Template.getValue();
if(obj) {
if(obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate *templ = static_cast<TechDraw::DrawTemplate *>(obj);
if (obj) {
if (obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
TechDraw::DrawTemplate* templ = static_cast<TechDraw::DrawTemplate*>(obj);
return templ->Orientation.getValue();
return templ->Orientation.getValue();
}
}
throw Base::RuntimeError("Template not set for Page");
}
int DrawPage::addView(App::DocumentObject *docObj)
int DrawPage::addView(App::DocumentObject* docObj)
{
if(!docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId()))
if (!docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
return -1;
}
DrawView* view = static_cast<DrawView*>(docObj);
//position all new views in center of Page (exceptDVDimension)
if (!docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()) &&
!docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())) {
view->X.setValue(getPageWidth()/2.0);
view->Y.setValue(getPageHeight()/2.0);
//position all new views in center of Page (exceptDVDimension)
if (!docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())
&& !docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())) {
view->X.setValue(getPageWidth() / 2.0);
view->Y.setValue(getPageHeight() / 2.0);
}
//add view to list
const std::vector<App::DocumentObject *> currViews = Views.getValues();
std::vector<App::DocumentObject *> newViews(currViews);
const std::vector<App::DocumentObject*> currViews = Views.getValues();
std::vector<App::DocumentObject*> newViews(currViews);
newViews.push_back(docObj);
Views.setValues(newViews);
//check if View fits on Page
if ( !view->checkFit(this) ) {
Base::Console().Warning("%s is larger than page. Will be scaled.\n", view->getNameInDocument());
if (!view->checkFit(this)) {
Base::Console().Warning("%s is larger than page. Will be scaled.\n",
view->getNameInDocument());
view->ScaleType.setValue("Automatic");
}
@@ -285,10 +297,11 @@ int DrawPage::addView(App::DocumentObject *docObj)
}
//Note Views might be removed from document elsewhere so need to check if a View is still in Document here
int DrawPage::removeView(App::DocumentObject *docObj)
int DrawPage::removeView(App::DocumentObject* docObj)
{
if(!docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId()))
if (!docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
return -1;
}
App::Document* doc = docObj->getDocument();
if (!doc) {
@@ -297,7 +310,7 @@ int DrawPage::removeView(App::DocumentObject *docObj)
const char* name = docObj->getNameInDocument();
if (!name) {
return -1;
return -1;
}
const std::vector<App::DocumentObject*> currViews = Views.getValues();
std::vector<App::DocumentObject*> newViews;
@@ -334,7 +347,7 @@ void DrawPage::onDocumentRestored()
void DrawPage::redrawCommand()
{
// Base::Console().Message("DP::redrawCommand()\n");
// Base::Console().Message("DP::redrawCommand()\n");
forceRedraw(true);
updateAllViews();
forceRedraw(false);
@@ -342,12 +355,13 @@ void DrawPage::redrawCommand()
void DrawPage::updateAllViews()
{
// Base::Console().Message("DP::updateAllViews()\n");
std::vector<App::DocumentObject*> featViews = getAllViews(); //unordered list of views within page
// Base::Console().Message("DP::updateAllViews()\n");
std::vector<App::DocumentObject*> featViews =
getAllViews();//unordered list of views within page
//first, make sure all the Parts have been executed so GeometryObjects exist
for(auto& v: featViews) {
TechDraw::DrawViewPart *part = dynamic_cast<TechDraw::DrawViewPart *>(v);
for (auto& v : featViews) {
TechDraw::DrawViewPart* part = dynamic_cast<TechDraw::DrawViewPart*>(v);
if (part) {
//view, section, detail, dpgi
part->recomputeFeature();
@@ -355,8 +369,8 @@ void DrawPage::updateAllViews()
}
//second, do the rest of the views that may depend on a part view
//TODO: check if we have 2 layers of dependency (ex. leader > weld > tile?)
for(auto& v: featViews) {
TechDraw::DrawViewPart *part = dynamic_cast<TechDraw::DrawViewPart *>(v);
for (auto& v : featViews) {
TechDraw::DrawViewPart* part = dynamic_cast<TechDraw::DrawViewPart*>(v);
if (part) {
continue;
}
@@ -371,15 +385,15 @@ void DrawPage::updateAllViews()
std::vector<App::DocumentObject*> DrawPage::getAllViews(void)
{
auto views = Views.getValues(); //list of docObjects
auto views = Views.getValues();//list of docObjects
std::vector<App::DocumentObject*> allViews;
for (auto& v: views) {
for (auto& v : views) {
allViews.push_back(v);
if (v->isDerivedFrom(TechDraw::DrawProjGroup::getClassTypeId())) {
TechDraw::DrawProjGroup* dpg = static_cast<TechDraw::DrawProjGroup*>(v);
if (dpg) { //can't really happen!
std::vector<App::DocumentObject*> pgViews = dpg->Views.getValues();
allViews.insert(allViews.end(), pgViews.begin(), pgViews.end());
if (dpg) {//can't really happen!
std::vector<App::DocumentObject*> pgViews = dpg->Views.getValues();
allViews.insert(allViews.end(), pgViews.begin(), pgViews.end());
}
}
}
@@ -397,31 +411,34 @@ void DrawPage::unsetupObject()
try {
const std::vector<App::DocumentObject*> currViews = Views.getValues();
for (auto& v: currViews) {
for (auto& v : currViews) {
//NOTE: the order of objects in Page.Views does not reflect the object hierarchy
// this means that a ProjGroup could be deleted before it's child ProjGroupItems.
// this causes problems when removing objects from document
if (v->isAttachedToDocument()) {
std::string viewName = v->getNameInDocument();
Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")",
docName.c_str(), viewName.c_str());
} else {
Base::Console().Log("DP::unsetupObject - v(%s) is not in document. skipping\n", pageName.c_str());
docName.c_str(),
viewName.c_str());
}
else {
Base::Console().Log("DP::unsetupObject - v(%s) is not in document. skipping\n",
pageName.c_str());
}
}
std::vector<App::DocumentObject*> emptyViews; //probably superfluous
std::vector<App::DocumentObject*> emptyViews;//probably superfluous
Views.setValues(emptyViews);
}
catch (...) {
Base::Console().Warning("DP::unsetupObject - %s - error while deleting children\n", getNameInDocument());
}
}
catch (...) {
Base::Console().Warning("DP::unsetupObject - %s - error while deleting children\n",
getNameInDocument());
}
App::DocumentObject* tmp = Template.getValue();
if (tmp) {
std::string templateName = Template.getValue()->getNameInDocument();
Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")",
docName.c_str(), templateName.c_str());
Base::Interpreter().runStringArg(
"App.getDocument(\"%s\").removeObject(\"%s\")", docName.c_str(), templateName.c_str());
}
Template.setValue(nullptr);
}
@@ -434,21 +451,23 @@ int DrawPage::getNextBalloonIndex(void)
return result;
}
void DrawPage::handleChangedPropertyType(
Base::XMLReader &reader, const char * TypeName, App::Property * prop)
void DrawPage::handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName,
App::Property* prop)
{
if (prop == &Scale) {
App::PropertyFloat tmp;
if (strcmp(tmp.getTypeId().getName(), TypeName)==0) { //property in file is Float
if (strcmp(tmp.getTypeId().getName(), TypeName) == 0) {//property in file is Float
tmp.setContainer(this);
tmp.Restore(reader);
double tmpValue = tmp.getValue();
if (tmpValue > 0.0) {
Scale.setValue(tmpValue);
} else {
}
else {
Scale.setValue(1.0);
}
} else {
}
else {
// has Scale prop that isn't Float!
Base::Console().Log("DrawPage::Restore - old Document Scale is Not Float!\n");
// no idea
@@ -459,12 +478,10 @@ void DrawPage::handleChangedPropertyType(
bool DrawPage::canUpdate() const
{
bool result = false;
if (GlobalUpdateDrawings() &&
KeepUpdated.getValue()) {
if (GlobalUpdateDrawings() && KeepUpdated.getValue()) {
result = true;
} else if (!GlobalUpdateDrawings() &&
AllowPageOverride() &&
KeepUpdated.getValue()) {
}
else if (!GlobalUpdateDrawings() && AllowPageOverride() && KeepUpdated.getValue()) {
result = true;
}
return result;
@@ -486,8 +503,11 @@ bool DrawPage::hasObject(App::DocumentObject* obj)
//allow/prevent drawing updates for all Pages
bool DrawPage::GlobalUpdateDrawings(void)
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General");
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
bool result = hGrp->GetBool("GlobalUpdateDrawings", true);
return result;
}
@@ -495,8 +515,11 @@ bool DrawPage::GlobalUpdateDrawings(void)
//allow/prevent a single page to update despite GlobalUpdateDrawings setting
bool DrawPage::AllowPageOverride(void)
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General");
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
bool result = hGrp->GetBool("AllowPageOverride", true);
return result;
}
@@ -504,14 +527,16 @@ bool DrawPage::AllowPageOverride(void)
// Python Drawing feature ---------------------------------------------------------
namespace App {
namespace App
{
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawPagePython, TechDraw::DrawPage)
template<> const char* TechDraw::DrawPagePython::getViewProviderName(void) const {
template<> const char* TechDraw::DrawPagePython::getViewProviderName(void) const
{
return "TechDrawGui::ViewProviderPage";
}
/// @endcond
// explicit template instantiation
template class TechDrawExport FeaturePythonT<TechDraw::DrawPage>;
}
}// namespace App