From a40996016f9768668a34d03495bb6aeffe092375 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Mon, 2 Apr 2018 19:55:53 -0400 Subject: [PATCH] Add #3337 Arbitrary Dimension --- src/Mod/TechDraw/App/DrawViewDimension.cpp | 31 +++++++++++++++++++++- src/Mod/TechDraw/App/DrawViewDimension.h | 2 ++ src/Mod/TechDraw/Gui/CommandCreateDims.cpp | 9 +++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Mod/TechDraw/App/DrawViewDimension.cpp b/src/Mod/TechDraw/App/DrawViewDimension.cpp index 38ba0440a3..fc3dbae2fa 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.cpp +++ b/src/Mod/TechDraw/App/DrawViewDimension.cpp @@ -96,6 +96,7 @@ DrawViewDimension::DrawViewDimension(void) References3D.setScope(App::LinkScope::Global); ADD_PROPERTY_TYPE(FormatSpec,(getDefaultFormatSpec().c_str()) , "Format",(App::PropertyType)(App::Prop_None),"Dimension Format"); + ADD_PROPERTY_TYPE(Arbitrary,(false) ,"Format",(App::PropertyType)(App::Prop_None),"Value specified by user"); Type.setEnums(TypeEnums); //dimension type: length, radius etc ADD_PROPERTY(Type,((long)0)); @@ -118,9 +119,24 @@ DrawViewDimension::DrawViewDimension(void) measurement = new Measure::Measurement(); //TODO: should have better initial datumLabel position than (0,0) in the DVP?? something closer to the object being measured? - //start/end point for linear measures + //initialize the descriptive geometry. + //TODO: should this be more like DVP with a "geometry object"? m_linearPoints.first = Base::Vector3d(0,0,0); m_linearPoints.second = Base::Vector3d(0,0,0); + + m_anglePoints.ends.first = Base::Vector3d(0,0,0); + m_anglePoints.ends.second = Base::Vector3d(0,0,0); + m_anglePoints.vertex = Base::Vector3d(0,0,0); + + m_arcPoints.isArc = false; + m_arcPoints.center = Base::Vector3d(0,0,0); + m_arcPoints.onCurve.first = Base::Vector3d(0,0,0); + m_arcPoints.onCurve.second = Base::Vector3d(0,0,0); + m_arcPoints.arcEnds.first = Base::Vector3d(0,0,0); + m_arcPoints.arcEnds.second = Base::Vector3d(0,0,0); + m_arcPoints.midArc = Base::Vector3d(0,0,0); + m_arcPoints.arcCW = false; + m_hasGeometry = false; } DrawViewDimension::~DrawViewDimension() @@ -148,6 +164,11 @@ void DrawViewDimension::onChanged(const App::Property* prop) } } } + if (prop == &Arbitrary) { + if (!Arbitrary.getValue()) { + FormatSpec.setValue(getDefaultFormatSpec().c_str()); //restore a useable FormatSpec + } + } DrawView::onChanged(prop); } @@ -221,6 +242,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void) } else if (getRefType() == vertexEdge) { m_linearPoints = getPointsEdgeVert(); } //else tarfu + m_hasGeometry = true; } else if(Type.isValue("Radius")){ int idx = DrawUtil::getIndexFromName(subElements[0]); TechDrawGeometry::BaseGeom* base = getViewPart()->getProjEdgeByIndex(idx); @@ -249,6 +271,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void) return App::DocumentObject::StdReturn; } m_arcPoints = pts; + m_hasGeometry = true; } else if(Type.isValue("Diameter")){ int idx = DrawUtil::getIndexFromName(subElements[0]); TechDrawGeometry::BaseGeom* base = getViewPart()->getProjEdgeByIndex(idx); @@ -278,6 +301,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void) return App::DocumentObject::StdReturn; } m_arcPoints = pts; + m_hasGeometry = true; } else if(Type.isValue("Angle")){ //TODO: do we need to distinguish inner vs outer angle? -wf if (getRefType() != twoEdge) { @@ -322,6 +346,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void) pts.ends.second = extPoint1; pts.vertex = apex; m_anglePoints = pts; + m_hasGeometry = true; } //TODO: if MeasureType = Projected and the Projected shape changes, the Dimension may become invalid (see tilted Cube example) @@ -333,6 +358,10 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void) std::string DrawViewDimension::getFormatedValue(bool obtuse) { std::string result; + if (Arbitrary.getValue()) { + return FormatSpec.getStrValue(); + } + QString specStr = QString::fromUtf8(FormatSpec.getStrValue().data(),FormatSpec.getStrValue().size()); double val = std::abs(getDimValue()); //internal units! diff --git a/src/Mod/TechDraw/App/DrawViewDimension.h b/src/Mod/TechDraw/App/DrawViewDimension.h index 8ccb9e4666..9afbee1699 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.h +++ b/src/Mod/TechDraw/App/DrawViewDimension.h @@ -75,6 +75,7 @@ public: App::PropertyLinkSubList References3D; //Points to 3D Geometry SubFeatures App::PropertyEnumeration Type; //DistanceX,DistanceY,Diameter, etc App::PropertyString FormatSpec; + App::PropertyBool Arbitrary; short mustExecute() const; bool has2DReferences(void) const; @@ -137,6 +138,7 @@ private: pointPair m_linearPoints; arcPoints m_arcPoints; anglePoints m_anglePoints; + bool m_hasGeometry; }; } //namespace TechDraw diff --git a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp index b509aa55c5..3a9f5407fd 100644 --- a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp @@ -97,6 +97,8 @@ char* _edgeTypeToText(int e); //bool _checkActive(Gui::Command* cmd, Base::Type classType, bool needSubs); +//NOTE: this is not shown in toolbar and doesn't always work right in the menu. +// should be removed. //=========================================================================== // TechDraw_NewDimension //=========================================================================== @@ -212,6 +214,7 @@ void CmdTechDrawNewDimension::activated(int iMsg) doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); commitCommand(); + dim->recomputeFeature(); //Horrible hack to force Tree update double x = objFeat->X.getValue(); @@ -299,6 +302,7 @@ void CmdTechDrawNewRadiusDimension::activated(int iMsg) doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); commitCommand(); + dim->recomputeFeature(); //Horrible hack to force Tree update double x = objFeat->X.getValue(); @@ -386,6 +390,7 @@ void CmdTechDrawNewDiameterDimension::activated(int iMsg) doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); commitCommand(); + dim->recomputeFeature(); //Horrible hack to force Tree update double x = objFeat->X.getValue(); @@ -494,6 +499,7 @@ void CmdTechDrawNewLengthDimension::activated(int iMsg) doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); commitCommand(); + dim->recomputeFeature(); //Horrible hack to force Tree update double x = objFeat->X.getValue(); @@ -602,6 +608,7 @@ void CmdTechDrawNewDistanceXDimension::activated(int iMsg) doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); commitCommand(); + dim->recomputeFeature(); //Horrible hack to force Tree update double x = objFeat->X.getValue(); @@ -709,6 +716,7 @@ void CmdTechDrawNewDistanceYDimension::activated(int iMsg) doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); commitCommand(); + dim->recomputeFeature(); //Horrible hack to force Tree update double x = objFeat->X.getValue(); @@ -796,6 +804,7 @@ void CmdTechDrawNewAngleDimension::activated(int iMsg) doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); commitCommand(); + dim->recomputeFeature(); //Horrible hack to force Tree update double x = objFeat->X.getValue();