From ad549d49e18981f857cc3eea3790baa7c7d8fff8 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sat, 19 Dec 2020 09:43:38 +0100 Subject: [PATCH] Sketcher: ViewProviderSketch update of geometry extensions ========================================================== The order of any operation, including setedit is first solve() and then draw(). This is consistent with geometry addition. If ViewProviderSketch must insert its own extensions, for example for scaling weights, then it is its responsibility to set this information wherever needed. This includes the temporal geometry vector used in draw(true), the solver to enable dragging operations, and SketchObject Geometry property. --- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 29 +++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 9f378b3247..25b93ffc73 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -3769,6 +3769,16 @@ void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationlayer Coords.emplace_back(x, y, 0); // save scale factor for any prospective dragging operation + // 1. Solver must be updated, in case a dragging operation starts + // 2. if temp geometry is being used (with memory allocation), then the copy we have here must be updated. If + // no temp geometry is being used, then the normal geometry must be updated. + {// make solver be ready for a dragging operation + auto vpext = std::make_unique(); + vpext->setRepresentationFactor(scalefactor); + + getSketchObject()->getSolvedSketch().updateExtension(GeoId, std::move(vpext)); + } + if(!circle->hasExtension(SketcherGui::ViewProviderSketchGeometryExtension::getClassTypeId())) { // It is ok to add this kind of extension to a const geometry because: @@ -6101,14 +6111,17 @@ bool ViewProviderSketch::setEdit(int ModNum) getSketchObject()->validateExternalLinks(); } - // First drawing with non-temporal geometry, then updating solver information - // This ensures that any ViewProvider geometry extension is set before the geometry - // is loaded into the solver, which ensures that any prospective draw using temporal - // geometry (draw with first parameter true) has the right ViewProvider geometry extensions - // set - This fixes Weight constraint dragging on a just opened sketch. - getSketchObject()->solve(false); - UpdateSolverInformation(); - draw(false,true); + // There are geometry extensions introduced by the solver and geometry extensions introduced by the viewprovider. + // 1. It is important that the solver has geometry with updated extensions. + // 2. It is important that the viewprovider has up-to-date solver information + // + // The decision is to maintain the "first solve then draw" order, which is consistent with the rest of the Sketcher + // for example in geometry creation. Then, the ViewProvider is responsible for updating the solver geometry when + // appropriate, as it is the ViewProvider that is introducing its geometry extensions. + // + // In order to have updated solver information, solve must take "true", this cause the Geometry property to be updated + // with the solver information, including solver extensions, and triggers a draw(true) via ViewProvider::UpdateData. + getSketchObject()->solve(true); connectUndoDocument = getDocument() ->signalUndoDocument.connect(boost::bind(&ViewProviderSketch::slotUndoDocument, this, bp::_1));