From be5e79601a58e3f70194797acb8dd2f807a5f3ae Mon Sep 17 00:00:00 2001 From: Eivind Kvedalen Date: Sun, 25 Oct 2015 21:56:53 +0100 Subject: [PATCH] PartDesign: Fixed similar issue compared to #2302 with unit handling when using an expression for the chamfer size. --- src/Mod/PartDesign/App/FeatureChamfer.cpp | 41 ++++++++++++++++++++++- src/Mod/PartDesign/App/FeatureChamfer.h | 7 +++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureChamfer.cpp b/src/Mod/PartDesign/App/FeatureChamfer.cpp index cd16bd306..9f941f7eb 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.cpp +++ b/src/Mod/PartDesign/App/FeatureChamfer.cpp @@ -32,6 +32,8 @@ # include #endif +#include +#include #include #include "FeatureChamfer.h" @@ -42,11 +44,12 @@ using namespace PartDesign; PROPERTY_SOURCE(PartDesign::Chamfer, PartDesign::DressUp) -const App::PropertyFloatConstraint::Constraints floatSize = {0.0,FLT_MAX,0.1}; +const App::PropertyQuantityConstraint::Constraints floatSize = {0.0,FLT_MAX,0.1}; Chamfer::Chamfer() { ADD_PROPERTY(Size,(1.0)); + Size.setUnit(Base::Unit::Length); Size.setConstraints(&floatSize); } @@ -109,3 +112,39 @@ App::DocumentObjectExecReturn *Chamfer::execute(void) return new App::DocumentObjectExecReturn(e->GetMessageString()); } } + +void Chamfer::Restore(Base::XMLReader &reader) +{ + reader.readElement("Properties"); + int Cnt = reader.getAttributeAsInteger("Count"); + + for (int i=0 ;igetTypeId().getName(), TypeName) == 0) { + prop->Restore(reader); + } + else if (prop && strcmp(TypeName,"App::PropertyFloatConstraint") == 0 && + strcmp(prop->getTypeId().getName(), "App::PropertyQuantityConstraint") == 0) { + App::PropertyFloatConstraint p; + p.Restore(reader); + static_cast(prop)->setValue(p.getValue()); + } + } + 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()); + } + reader.readEndElement("Property"); + } + reader.readEndElement("Properties"); +} diff --git a/src/Mod/PartDesign/App/FeatureChamfer.h b/src/Mod/PartDesign/App/FeatureChamfer.h index bcd5b36f9..583513dfa 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.h +++ b/src/Mod/PartDesign/App/FeatureChamfer.h @@ -25,6 +25,7 @@ #define PARTDESIGN_FEATURECHAMFER_H #include +#include #include #include "FeatureDressUp.h" @@ -38,7 +39,7 @@ class PartDesignExport Chamfer : public DressUp public: Chamfer(); - App::PropertyFloatConstraint Size; + App::PropertyQuantityConstraint Size; /** @name methods override feature */ //@{ @@ -50,6 +51,10 @@ public: return "PartDesignGui::ViewProviderChamfer"; } //@} + +protected: + void Restore(Base::XMLReader &reader); + }; } //namespace Part