From 79a5a6adde6870a25b6dc52966e984e8e60ea462 Mon Sep 17 00:00:00 2001 From: WandererFan Date: Tue, 31 Jan 2017 18:47:08 -0500 Subject: [PATCH] Change Scale to PropertyFloatConstaint to prevent OCC loop when Scale == 0 --- src/Mod/TechDraw/App/DrawGeomHatch.cpp | 10 ++++ src/Mod/TechDraw/App/DrawGeomHatch.h | 4 +- src/Mod/TechDraw/App/DrawHatch.cpp | 9 ++++ src/Mod/TechDraw/App/DrawHatch.h | 4 +- src/Mod/TechDraw/App/DrawPage.cpp | 75 +++++++++++++++++++++++++- src/Mod/TechDraw/App/DrawPage.h | 4 +- src/Mod/TechDraw/App/DrawView.cpp | 73 +++++++++++++++++++++++++ src/Mod/TechDraw/App/DrawView.h | 4 +- 8 files changed, 178 insertions(+), 5 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawGeomHatch.cpp b/src/Mod/TechDraw/App/DrawGeomHatch.cpp index a642155fd..20e6e9c66 100644 --- a/src/Mod/TechDraw/App/DrawGeomHatch.cpp +++ b/src/Mod/TechDraw/App/DrawGeomHatch.cpp @@ -52,6 +52,10 @@ #include #include #include +#include + +#include + #endif #include @@ -59,6 +63,7 @@ #include #include #include +#include #include "HatchLine.h" #include "DrawUtil.h" @@ -73,6 +78,10 @@ using namespace TechDraw; using namespace TechDrawGeometry; using namespace std; +App::PropertyFloatConstraint::Constraints DrawGeomHatch::scaleRange = {Precision::Confusion(), + std::numeric_limits::max(), + pow(10,- Base::UnitsApi::getDecimals())}; + PROPERTY_SOURCE(TechDraw::DrawGeomHatch, App::DocumentObject) @@ -84,6 +93,7 @@ DrawGeomHatch::DrawGeomHatch(void) ADD_PROPERTY_TYPE(FilePattern ,(""),vgroup,App::Prop_None,"The crosshatch pattern file for this area"); ADD_PROPERTY_TYPE(NamePattern,(""),vgroup,App::Prop_None,"The name of the pattern"); ADD_PROPERTY_TYPE(ScalePattern,(1.0),vgroup,App::Prop_None,"GeomHatch pattern size adjustment"); + ScalePattern.setConstraints(&scaleRange); getParameters(); diff --git a/src/Mod/TechDraw/App/DrawGeomHatch.h b/src/Mod/TechDraw/App/DrawGeomHatch.h index 767fb6291..d9885b16d 100644 --- a/src/Mod/TechDraw/App/DrawGeomHatch.h +++ b/src/Mod/TechDraw/App/DrawGeomHatch.h @@ -54,7 +54,7 @@ public: App::PropertyLinkSub Source; //the dvX & face(s) this crosshatch belongs to App::PropertyFile FilePattern; App::PropertyString NamePattern; - App::PropertyFloat ScalePattern; + App::PropertyFloatConstraint ScalePattern; virtual short mustExecute() const; virtual App::DocumentObjectExecReturn *execute(void); @@ -79,6 +79,8 @@ protected: std::vector m_lineSets; private: + static App::PropertyFloatConstraint::Constraints scaleRange; + }; typedef App::FeaturePythonT DrawGeomHatchPython; diff --git a/src/Mod/TechDraw/App/DrawHatch.cpp b/src/Mod/TechDraw/App/DrawHatch.cpp index 81e8437a9..dc31e931f 100644 --- a/src/Mod/TechDraw/App/DrawHatch.cpp +++ b/src/Mod/TechDraw/App/DrawHatch.cpp @@ -25,6 +25,9 @@ #ifndef _PreComp_ # include +#include +#include + #endif #include @@ -37,6 +40,7 @@ #include #include #include +#include #include "DrawViewPart.h" #include "DrawHatch.h" @@ -46,6 +50,10 @@ using namespace TechDraw; using namespace std; +App::PropertyFloatConstraint::Constraints DrawHatch::scaleRange = {Precision::Confusion(), + std::numeric_limits::max(), + pow(10,- Base::UnitsApi::getDecimals())}; + PROPERTY_SOURCE(TechDraw::DrawHatch, App::DocumentObject) @@ -62,6 +70,7 @@ DrawHatch::DrawHatch(void) ADD_PROPERTY_TYPE(HatchPattern ,(""),vgroup,App::Prop_None,"The hatch pattern file for this area"); ADD_PROPERTY_TYPE(HatchColor,(fcColor),vgroup,App::Prop_None,"The color of the hatch pattern"); ADD_PROPERTY_TYPE(HatchScale,(1.0),vgroup,App::Prop_None,"Hatch pattern size adjustment"); + HatchScale.setConstraints(&scaleRange); DirProjection.setStatus(App::Property::ReadOnly,true); hGrp = App::GetApplication().GetUserParameter() diff --git a/src/Mod/TechDraw/App/DrawHatch.h b/src/Mod/TechDraw/App/DrawHatch.h index 496cc15a4..b7c83123a 100644 --- a/src/Mod/TechDraw/App/DrawHatch.h +++ b/src/Mod/TechDraw/App/DrawHatch.h @@ -44,7 +44,7 @@ public: App::PropertyLinkSub Source; //the dvp & face this hatch belongs to App::PropertyFile HatchPattern; App::PropertyColor HatchColor; - App::PropertyFloat HatchScale; + App::PropertyFloatConstraint HatchScale; //short mustExecute() const; @@ -62,6 +62,8 @@ protected: void onChanged(const App::Property* prop); private: + static App::PropertyFloatConstraint::Constraints scaleRange; + }; typedef App::FeaturePythonT DrawHatchPython; diff --git a/src/Mod/TechDraw/App/DrawPage.cpp b/src/Mod/TechDraw/App/DrawPage.cpp index b03b03cf4..41462063f 100644 --- a/src/Mod/TechDraw/App/DrawPage.cpp +++ b/src/Mod/TechDraw/App/DrawPage.cpp @@ -27,12 +27,15 @@ # include # include # include +#include +#include #endif #include #include #include #include +#include #include #include @@ -57,6 +60,10 @@ using namespace std; // DrawPage //=========================================================================== +App::PropertyFloatConstraint::Constraints DrawPage::scaleRange = {Precision::Confusion(), + std::numeric_limits::max(), + pow(10,- Base::UnitsApi::getDecimals())}; + PROPERTY_SOURCE(TechDraw::DrawPage, App::DocumentObject) const char* DrawPage::ProjectionTypeEnums[] = { "First Angle", @@ -87,7 +94,7 @@ DrawPage::DrawPage(void) } ADD_PROPERTY_TYPE(Scale, (1.0), group, App::Prop_None, "Scale factor for this Page"); - //TODO: Page should create itself with default Template instead of Cmd figuring it out? + Scale.setConstraints(&scaleRange); } DrawPage::~DrawPage() @@ -328,9 +335,75 @@ void DrawPage::unsetupObject() } Views.setValues(emptyViews); + //no template crash here?? if Template.getValue is null or invalid, this will fail. std::string templateName = Template.getValue()->getNameInDocument(); Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")", docName.c_str(), templateName.c_str()); Template.setValue(nullptr); } +void DrawPage::Restore(Base::XMLReader &reader) +{ + reader.readElement("Properties"); + int Cnt = reader.getAttributeAsInteger("Count"); + + for (int i=0 ;igetTypeId().getName(), TypeName) == 0){ //if the property type in obj == type in schema + schemaProp->Restore(reader); //nothing special to do + } else { + if (strcmp(PropName, "Scale") == 0) { + if (schemaProp->isDerivedFrom(App::PropertyFloatConstraint::getClassTypeId())){ //right property type + schemaProp->Restore(reader); //nothing special to do + } else { //Scale, but not PropertyFloatConstraint + App::PropertyFloat tmp; + if (strcmp(tmp.getTypeId().getName(),TypeName)) { //property in file is Float + tmp.setContainer(this); + tmp.Restore(reader); + double tmpValue = tmp.getValue(); + if (tmpValue > 0.0) { + static_cast(schemaProp)->setValue(tmpValue); + } else { + static_cast(schemaProp)->setValue(1.0); + } + } else { + // has Scale prop that isn't Float! + Base::Console().Log("DrawPage::Restore - old Document Scale is Not Float!\n"); + // no idea + } + } + } else { + Base::Console().Log("DrawPage::Restore - old Document has unknown Property\n"); + } + } + } + } + catch (const Base::XMLParseException&) { + throw; // re-throw + } + catch (const Base::Exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const std::exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const char* e) { + Base::Console().Error("%s\n", e); + } +#ifndef FC_DEBUG + catch (...) { + Base::Console().Error("PropertyContainer::Restore: Unknown C++ exception thrown"); + } +#endif + + reader.readEndElement("Property"); + } + reader.readEndElement("Properties"); +} + + diff --git a/src/Mod/TechDraw/App/DrawPage.h b/src/Mod/TechDraw/App/DrawPage.h index cc6b1ff92..002da38ee 100644 --- a/src/Mod/TechDraw/App/DrawPage.h +++ b/src/Mod/TechDraw/App/DrawPage.h @@ -43,7 +43,7 @@ public: App::PropertyLinkList Views; App::PropertyLink Template; - App::PropertyFloat Scale; + App::PropertyFloatConstraint Scale; App::PropertyEnumeration ProjectionType; // First or Third Angle /** @name methods overide Feature */ @@ -51,6 +51,7 @@ public: /// recalculate the Feature virtual App::DocumentObjectExecReturn *execute(void); //@} + void Restore(Base::XMLReader &reader); int addView(App::DocumentObject *docObj); int removeView(App::DocumentObject* docObj); @@ -94,6 +95,7 @@ protected: private: static const char* ProjectionTypeEnums[]; bool nowDeleting; + static App::PropertyFloatConstraint::Constraints scaleRange; }; diff --git a/src/Mod/TechDraw/App/DrawView.cpp b/src/Mod/TechDraw/App/DrawView.cpp index 7df7f82cc..2b336ec16 100644 --- a/src/Mod/TechDraw/App/DrawView.cpp +++ b/src/Mod/TechDraw/App/DrawView.cpp @@ -26,6 +26,8 @@ #ifndef _PreComp_ # include # include +#include +#include #endif @@ -35,6 +37,7 @@ #include #include #include +#include #include "DrawView.h" #include "DrawPage.h" @@ -57,6 +60,10 @@ const char* DrawView::ScaleTypeEnums[]= {"Page", "Automatic", "Custom", NULL}; +App::PropertyFloatConstraint::Constraints DrawView::scaleRange = {Precision::Confusion(), + std::numeric_limits::max(), + pow(10,- Base::UnitsApi::getDecimals())}; + PROPERTY_SOURCE(TechDraw::DrawView, App::DocumentObject) @@ -74,6 +81,7 @@ DrawView::DrawView(void) ScaleType.setEnums(ScaleTypeEnums); ADD_PROPERTY_TYPE(ScaleType,((long)0),group, App::Prop_None, "Scale Type"); ADD_PROPERTY_TYPE(Scale ,(1.0),group,App::Prop_None,"Scale factor of the view"); + Scale.setConstraints(&scaleRange); ADD_PROPERTY_TYPE(KeepLabel ,(false),fgroup,App::Prop_None,"Keep Label on Page even if toggled off"); ADD_PROPERTY_TYPE(Caption ,(""),fgroup,App::Prop_None,"Short text about the view"); @@ -234,6 +242,71 @@ void DrawView::setPosition(double x, double y) //recompute.unlock() } +void DrawView::Restore(Base::XMLReader &reader) +{ + reader.readElement("Properties"); + int Cnt = reader.getAttributeAsInteger("Count"); + + for (int i=0 ;igetTypeId().getName(), TypeName) == 0){ //if the property type in obj == type in schema + schemaProp->Restore(reader); //nothing special to do + } else { + if (strcmp(PropName, "Scale") == 0) { + if (schemaProp->isDerivedFrom(App::PropertyFloatConstraint::getClassTypeId())){ //right property type + schemaProp->Restore(reader); //nothing special to do + } else { //Scale, but not PropertyFloatConstraint + App::PropertyFloat tmp; + if (strcmp(tmp.getTypeId().getName(),TypeName)) { //property in file is Float + tmp.setContainer(this); + tmp.Restore(reader); + double tmpValue = tmp.getValue(); + if (tmpValue > 0.0) { + static_cast(schemaProp)->setValue(tmpValue); + } else { + static_cast(schemaProp)->setValue(1.0); + } + } else { + // has Scale prop that isn't Float! + Base::Console().Log("DrawView::Restore - old Document Scale is Not Float!\n"); + // no idea + } + } + } else { + Base::Console().Log("DrawView::Restore - old Document has unknown Property\n"); + } + } + } + } + catch (const Base::XMLParseException&) { + throw; // re-throw + } + catch (const Base::Exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const std::exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const char* e) { + Base::Console().Error("%s\n", e); + } +#ifndef FC_DEBUG + catch (...) { + Base::Console().Error("PropertyContainer::Restore: Unknown C++ exception thrown"); + } +#endif + + reader.readEndElement("Property"); + } + reader.readEndElement("Properties"); +} + + PyObject *DrawView::getPyObject(void) { if (PythonObject.is(Py::_None())) { diff --git a/src/Mod/TechDraw/App/DrawView.h b/src/Mod/TechDraw/App/DrawView.h index ad6e131cd..2e2cff1bb 100644 --- a/src/Mod/TechDraw/App/DrawView.h +++ b/src/Mod/TechDraw/App/DrawView.h @@ -48,7 +48,7 @@ public: App::PropertyFloat X; App::PropertyFloat Y; - App::PropertyFloat Scale; + App::PropertyFloatConstraint Scale; App::PropertyEnumeration ScaleType; App::PropertyFloat Rotation; @@ -62,6 +62,7 @@ public: virtual void onDocumentRestored(); virtual short mustExecute() const; //@} + void Restore(Base::XMLReader &reader); bool isInClip(); @@ -90,6 +91,7 @@ protected: private: static const char* ScaleTypeEnums[]; + static App::PropertyFloatConstraint::Constraints scaleRange; }; typedef App::FeaturePythonT DrawViewPython;