From 95fad03ee2bf82fbc965b6b939bf4fe7040efd0a Mon Sep 17 00:00:00 2001 From: Tomas Pavlicek Date: Sat, 23 Dec 2023 14:06:58 +0100 Subject: [PATCH] [TechDraw] Tree view update refactoring (#11815) --- src/Mod/TechDraw/Gui/CommandCreateDims.cpp | 46 ++++++------------- src/Mod/TechDraw/Gui/CommandDecorate.cpp | 11 ++--- src/Mod/TechDraw/Gui/CommandExtensionDims.cpp | 6 +-- 3 files changed, 20 insertions(+), 43 deletions(-) diff --git a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp index a222310437..f786803e32 100644 --- a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp @@ -239,10 +239,6 @@ void execRadius(Gui::Command* cmd) //build the dimension // DrawViewDimension* dim = dimensionMaker(partFeat, "Radius", references2d, references3d); - - //Horrible hack to force Tree update - double x = partFeat->X.getValue(); - partFeat->X.setValue(x); } //=========================================================================== @@ -365,10 +361,6 @@ void execDiameter(Gui::Command* cmd) //build the dimension // DrawViewDimension* dim = dimensionMaker(partFeat, "Diameter", references2d, references3d); - - //Horrible hack to force Tree update - double x = partFeat->X.getValue(); - partFeat->X.setValue(x); } //=========================================================================== @@ -464,10 +456,6 @@ void execDistance(Gui::Command* cmd) //position the Dimension text on the view positionDimText(dim); - - //Horrible hack to force Tree update (claimChildren) - double x = partFeat->X.getValue(); - partFeat->X.setValue(x); } //=========================================================================== @@ -560,13 +548,8 @@ void execDistanceX(Gui::Command* cmd) //build the dimension DrawViewDimension* dim = dimensionMaker(partFeat, "DistanceX", references2d, references3d); - //position the Dimension text on the view positionDimText(dim); - - //Horrible hack to force Tree update (claimChildren) - double x = partFeat->X.getValue(); - partFeat->X.setValue(x); } //=========================================================================== @@ -660,10 +643,6 @@ void execDistanceY(Gui::Command* cmd) //position the Dimension text on the view positionDimText(dim); - - //Horrible hack to force Tree update (claimChildren) - double x = partFeat->X.getValue(); - partFeat->X.setValue(x); } //=========================================================================== @@ -756,10 +735,6 @@ void execAngle(Gui::Command* cmd) //position the Dimension text on the view positionDimText(dim); - - //Horrible hack to force Tree update (claimChildren) - double x = partFeat->X.getValue(); - partFeat->X.setValue(x); } //=========================================================================== @@ -849,12 +824,9 @@ void execAngle3Pt(Gui::Command* cmd) //build the dimension DrawViewDimension* dim = dimensionMaker(partFeat, "Angle3Pt", references2d, references3d); + //position the Dimension text on the view positionDimText(dim); - - //Horrible hack to force Tree update (claimChildren) - double x = partFeat->X.getValue(); - partFeat->X.setValue(x); } //! link 3D geometry to Dimension(s) on a Page @@ -1337,11 +1309,11 @@ void CmdTechDrawLandmarkDimension::activated(int iMsg) FeatName.c_str()); commitCommand(); - dim->recomputeFeature(); - //Horrible hack to force Tree update - double x = dvp->X.getValue(); - dvp->X.setValue(x); + // Touch the parent feature so the dimension in tree view appears as a child + dvp->touch(true); + + dim->recomputeFeature(); } bool CmdTechDrawLandmarkDimension::isActive() @@ -1416,6 +1388,14 @@ DrawViewDimension* dimensionMaker(TechDraw::DrawViewPart* dvp, std::string dimTy dimName.c_str()); Gui::Command::commitCommand(); + + // Touch the parent feature so the dimension in tree view appears as a child + dvp->touch(true); + + // Select only the newly created dimension + Gui::Selection().clearSelection(); + Gui::Selection().addSelection(dvp->getDocument()->getName(), dim->getNameInDocument()); + dim->recomputeFeature(); return dim; } diff --git a/src/Mod/TechDraw/Gui/CommandDecorate.cpp b/src/Mod/TechDraw/Gui/CommandDecorate.cpp index 4765fbedb5..2deeb5b3a2 100644 --- a/src/Mod/TechDraw/Gui/CommandDecorate.cpp +++ b/src/Mod/TechDraw/Gui/CommandDecorate.cpp @@ -143,10 +143,8 @@ void CmdTechDrawHatch::activated(int iMsg) // dialog to fill in hatch values Gui::Control().showDialog(new TaskDlgHatch(partFeat, subNames)); - //Horrible hack to force Tree update ??still required?? - //WF: yes. ViewProvider will not claim children without this! - double x = partFeat->X.getValue(); - partFeat->X.setValue(x); + // Touch the parent feature so the hatching in tree view appears as a child + partFeat->touch(); getDocument()->recompute(); } @@ -216,9 +214,8 @@ void CmdTechDrawGeometricHatch::activated(int iMsg) commitCommand(); - //Horrible hack to force Tree update ??still required?? - double x = objFeat->X.getValue(); - objFeat->X.setValue(x); + // Touch the parent feature so the hatching in tree view appears as a child + objFeat->touch(); getDocument()->recompute(); } diff --git a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp index c913299791..3f7f5f8cb9 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp @@ -2334,10 +2334,10 @@ namespace TechDrawGui { throw Base::TypeError("CmdTechDrawExtensionCreateLinDimension - dim not found\n"); dim->References2D.setValues(objs, subs); cmd->doCommand(cmd->Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str()); + + // Touch the parent feature so the dimension in tree view appears as a child + objFeat->touch(); dim->recomputeFeature(); - //Horrible hack to force Tree update - double x = objFeat->X.getValue(); - objFeat->X.setValue(x); return dim; }