From e95b3167dde3686ea2a295d26c1e00f87bf96578 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 2 Dec 2020 15:51:06 +0100 Subject: [PATCH] [TD] use PropertyQuantity for OverTolerance and UnderTolerance and add backward compatibility --- src/Mod/TechDraw/App/DrawViewDimension.cpp | 36 ++++++++++++++++++++++ src/Mod/TechDraw/App/DrawViewDimension.h | 5 +-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawViewDimension.cpp b/src/Mod/TechDraw/App/DrawViewDimension.cpp index 764f4a3a2c..acc9b53662 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.cpp +++ b/src/Mod/TechDraw/App/DrawViewDimension.cpp @@ -103,7 +103,9 @@ DrawViewDimension::DrawViewDimension(void) ADD_PROPERTY(MeasureType, ((long)1)); //Projected (or True) measurement ADD_PROPERTY_TYPE(TheoreticalExact,(false),"", App::Prop_Output,"Set for theoretical exact (basic) dimension"); ADD_PROPERTY_TYPE(OverTolerance ,(0.0),"", App::Prop_Output,"+ Tolerance value"); + OverTolerance.setUnit(Base::Unit::Length); ADD_PROPERTY_TYPE(UnderTolerance ,(0.0),"", App::Prop_Output,"- Tolerance value"); + UnderTolerance.setUnit(Base::Unit::Length); ADD_PROPERTY_TYPE(Inverted,(false),"", App::Prop_Output,"The dimensional value is displayed inverted"); //hide the properties the user can't edit in the property editor @@ -168,6 +170,16 @@ void DrawViewDimension::onChanged(const App::Property* prop) } } else if (prop == &Type) { //why?? FormatSpec.setValue(getDefaultFormatSpec().c_str()); + long type = Type.getValue(); + // Angle or Angle3Pt + if (type == 6 || type == 7) { + OverTolerance.setUnit(Base::Unit::Angle); + UnderTolerance.setUnit(Base::Unit::Angle); + } + else { + OverTolerance.setUnit(Base::Unit::Length); + UnderTolerance.setUnit(Base::Unit::Length); + } } else if ( (prop == &FormatSpec) || (prop == &Arbitrary) || (prop == &MeasureType) || @@ -187,6 +199,30 @@ void DrawViewDimension::onDocumentRestored() if (has3DReferences()) { setAll3DMeasurement(); } + + long type = Type.getValue(); + // Angle or Angle3Pt + if (type == 6 || type == 7) { + OverTolerance.setUnit(Base::Unit::Angle); + UnderTolerance.setUnit(Base::Unit::Angle); + } +} + +void DrawViewDimension::handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, App::Property * prop) +{ + if (prop == &OverTolerance && strcmp(TypeName, "App::PropertyFloat") == 0) { + App::PropertyFloat v; + v.Restore(reader); + OverTolerance.setValue(v.getValue()); + } + else if (prop == &UnderTolerance && strcmp(TypeName, "App::PropertyFloat") == 0) { + App::PropertyFloat v; + v.Restore(reader); + UnderTolerance.setValue(v.getValue()); + } + else { + TechDraw::DrawView::handleChangedPropertyType(reader, TypeName, prop); + } } diff --git a/src/Mod/TechDraw/App/DrawViewDimension.h b/src/Mod/TechDraw/App/DrawViewDimension.h index c1ca7ed180..75c4abfae9 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.h +++ b/src/Mod/TechDraw/App/DrawViewDimension.h @@ -105,8 +105,8 @@ public: App::PropertyString FormatSpecOverTolerance; App::PropertyBool Arbitrary; App::PropertyBool ArbitraryTolerances; - App::PropertyFloat OverTolerance; - App::PropertyFloat UnderTolerance; + App::PropertyQuantity OverTolerance; + App::PropertyQuantity UnderTolerance; enum RefType{ invalidRef, @@ -164,6 +164,7 @@ public: bool useDecimals() const; protected: + virtual void handleChangedPropertyType(Base::XMLReader &, const char * , App::Property * ) override; virtual void onChanged(const App::Property* prop) override; virtual void onDocumentRestored() override; std::string getPrefix() const;