diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 3f087acfe..0756414d4 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -88,6 +88,8 @@ SketchObject::SketchObject() lastHasRedundancies=false; lastSolverStatus=0; lastSolveTime=0; + + noRecomputes=false; } SketchObject::~SketchObject() @@ -344,18 +346,25 @@ int SketchObject::toggleDriving(int ConstrId) return 0; } -int SketchObject::movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toPoint, bool relative) +int SketchObject::movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toPoint, bool relative, bool updateGeometry) { - // if we are moving a point, we need to start from a solved sketch - // if we have conflicts we can forget about moving + // if we are moving a point at SketchObject level, we need to start from a solved sketch + // if we have conflicts we can forget about moving. However, there is the possibility that we + // need to do programatically moves of new geometry that has not been solved yet and that because + // they were programmetically generated won't generate a conflict. This is the case of Fillet for + // example. This is why exceptionally, it may be required to update the sketch geometry to that of + // of SketchObject upon moving. => use updateGeometry parameter = true then - /*lastDoF = solvedSketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), - getExternalGeometryCount()); - lastHasConflict = solvedSketch.hasConflicts(); - lastHasRedundancies = solvedSketch.hasRedundancies(); - lastConflicting=solvedSketch.getConflicting(); - lastRedundant=solvedSketch.getRedundant();*/ + if(updateGeometry) { + lastDoF = solvedSketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), + getExternalGeometryCount()); + + lastHasConflict = solvedSketch.hasConflicts(); + lastHasRedundancies = solvedSketch.hasRedundancies(); + lastConflicting=solvedSketch.getConflicting(); + lastRedundant=solvedSketch.getRedundant(); + } if (lastDoF < 0) // over-constrained sketch return -1; @@ -479,6 +488,10 @@ int SketchObject::addGeometry(const std::vector &geoList) Geometry.setValues(newVals); Constraints.acceptGeometry(getCompleteGeometry()); rebuildVertexIndex(); + + if(noRecomputes) // if we do not have a recompute after the geometry creation, the sketch must be solved to update the DoF of the solver + solve(); + return Geometry.getSize()-1; } @@ -493,6 +506,10 @@ int SketchObject::addGeometry(const Part::Geometry *geo) Constraints.acceptGeometry(getCompleteGeometry()); delete geoNew; rebuildVertexIndex(); + + if(noRecomputes) // if we do not have a recompute after the geometry creation, the sketch must be solved to update the DoF of the solver + solve(); + return Geometry.getSize()-1; } @@ -871,14 +888,14 @@ int SketchObject::fillet(int GeoId1, int GeoId2, if (dist1.Length() < dist2.Length()) { tangent1->SecondPos = start; tangent2->SecondPos = end; - movePoint(GeoId1, PosId1, arc->getStartPoint(/*emulateCCW=*/true)); - movePoint(GeoId2, PosId2, arc->getEndPoint(/*emulateCCW=*/true)); + movePoint(GeoId1, PosId1, arc->getStartPoint(/*emulateCCW=*/true),false,true); + movePoint(GeoId2, PosId2, arc->getEndPoint(/*emulateCCW=*/true),false,true); } else { tangent1->SecondPos = end; tangent2->SecondPos = start; - movePoint(GeoId1, PosId1, arc->getEndPoint(/*emulateCCW=*/true)); - movePoint(GeoId2, PosId2, arc->getStartPoint(/*emulateCCW=*/true)); + movePoint(GeoId1, PosId1, arc->getEndPoint(/*emulateCCW=*/true),false,true); + movePoint(GeoId2, PosId2, arc->getStartPoint(/*emulateCCW=*/true),false,true); } addConstraint(tangent1); @@ -887,6 +904,10 @@ int SketchObject::fillet(int GeoId1, int GeoId2, delete tangent2; } delete arc; + + if(noRecomputes) // if we do not have a recompute after the geometry creation, the sketch must be solved to update the DoF of the solver + solve(); + return 0; } return -1; @@ -930,8 +951,8 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) // go through all constraints and replace the point (GeoId,end) with (newGeoId,end) transferConstraints(GeoId, end, newGeoId, end); - movePoint(GeoId, end, point1); - movePoint(newGeoId, start, point2); + movePoint(GeoId, end, point1,false,true); + movePoint(newGeoId, start, point2,false,true); PointPos secondPos1 = Sketcher::none, secondPos2 = Sketcher::none; ConstraintType constrType1 = Sketcher::PointOnObject, constrType2 = Sketcher::PointOnObject; @@ -1017,7 +1038,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) if (x1 > x0) { // trim line start delConstraintOnPoint(GeoId, start, false); - movePoint(GeoId, start, point1); + movePoint(GeoId, start, point1,false,true); // constrain the trimming point on the corresponding geometry Sketcher::Constraint *newConstr = new Sketcher::Constraint(); @@ -1035,7 +1056,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) } else if (x1 < x0) { // trim line end delConstraintOnPoint(GeoId, end, false); - movePoint(GeoId, end, point1); + movePoint(GeoId, end, point1,false,true); Sketcher::Constraint *newConstr = new Sketcher::Constraint(); newConstr->Type = constrType; newConstr->First = GeoId; @@ -2459,11 +2480,18 @@ double SketchObject::calculateAngleViaPoint(int GeoId1, int GeoId2, double px, d { // Temporary sketch based calculation. Slow, but guaranteed consistency with constraints. Sketcher::Sketch sk; - int i1 = sk.addGeometry(this->getGeometry(GeoId1)); - int i2 = sk.addGeometry(this->getGeometry(GeoId2)); - - return sk.calculateAngleViaPoint(i1,i2,px,py); + + const Part::Geometry *p1=this->getGeometry(GeoId1); + const Part::Geometry *p2=this->getGeometry(GeoId2); + + if(p1!=0 && p2!=0) { + int i1 = sk.addGeometry(this->getGeometry(GeoId1)); + int i2 = sk.addGeometry(this->getGeometry(GeoId2)); + return sk.calculateAngleViaPoint(i1,i2,px,py); + } + else + throw Base::Exception("Null geometry in calculateAngleViaPoint"); /* // OCC-based calculation. It is faster, but it was removed due to problems diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index c8f4bf241..d599646cf 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -59,6 +59,16 @@ public: return "SketcherGui::ViewProviderSketch"; } //@} + + /** SketchObject can work in two modes: Recompute Mode and noRecomputes Mode + - In Recompute Mode, a recompute is necessary after each geometry addition to update the solver DoF (default) + - In NoRecomputes Mode, no recompute is necessary after a geometry addition. If a recompute is triggered + it is just less efficient. + + This flag does not regulate whether this object will recompute or not if execute() or a recompute() is actually executed, + it just regulates whether the solver is called upon geometry addition or not (relies on the solve of execute for the calculation) + */ + bool noRecomputes; /// add unspecified geometry int addGeometry(const Part::Geometry *geo); @@ -119,7 +129,7 @@ public: /// toggle the driving status of this constraint int toggleDriving(int ConstrId); /// move this point to a new location and solve - int movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toPoint, bool relative=false); + int movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toPoint, bool relative=false, bool updateGeometry=false); /// retrieves the coordinates of a point Base::Vector3d getPoint(int GeoId, PointPos PosId) const; diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index 44fee1a8d..2cf642d52 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -155,7 +155,12 @@ void openEditDatumDialog(Sketcher::SketchObject* sketch, int ConstrNbr) sketch->getNameInDocument(), ConstrNbr, newDatum, (const char*)newQuant.getUnit().getString().toUtf8()); Gui::Command::commitCommand(); - Gui::Command::updateActive(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); } catch (const Base::Exception& e) { QMessageBox::critical(qApp->activeWindow(), QObject::tr("Dimensional constraint"), QString::fromUtf8(e.what())); @@ -201,7 +206,12 @@ void finishDistanceConstraint(Gui::Command* cmd, Sketcher::SketchObject* sketch, cmd->commitCommand(); } - //updateActive(); + //ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + cmd->getSelection().clearSelection(); } @@ -344,7 +354,12 @@ void SketcherGui::makeTangentToEllipseviaNewPoint(const Sketcher::SketchObject* } Gui::Command::commitCommand(); - Gui::Command::updateActive(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); } /// Makes a simple tangency constraint using extra point + tangent via point /// geom1 => an arc of ellipse @@ -406,7 +421,12 @@ void SketcherGui::makeTangentToArcOfEllipseviaNewPoint(const Sketcher::SketchObj } Gui::Command::commitCommand(); - Gui::Command::updateActive(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); } namespace SketcherGui { @@ -581,7 +601,12 @@ void CmdSketcherConstrainHorizontal::activated(int iMsg) } // finish the transaction and update commitCommand(); - updateActive(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); // clear the selection (convenience) getSelection().clearSelection(); @@ -673,7 +698,12 @@ void CmdSketcherConstrainVertical::activated(int iMsg) } // finish the transaction and update commitCommand(); - updateActive(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); // clear the selection (convenience) getSelection().clearSelection(); @@ -755,7 +785,12 @@ void CmdSketcherConstrainLock::activated(int iMsg) // finish the transaction and update commitCommand(); - updateActive(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); // clear the selection (convenience) getSelection().clearSelection(); @@ -867,7 +902,11 @@ void CmdSketcherConstrainCoincident::activated(int iMsg) else abortCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); // clear the selection (convenience) getSelection().clearSelection(); @@ -1553,7 +1592,12 @@ void CmdSketcherConstrainParallel::activated(int iMsg) } // finish the transaction and update commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); // clear the selection (convenience) @@ -1675,7 +1719,12 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) } commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); getSelection().clearSelection(); @@ -1700,7 +1749,12 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Perpendicular',%d,%d,%d,%d)) ", selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2); commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); getSelection().clearSelection(); return; @@ -1723,7 +1777,13 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Perpendicular',%d,%d,%d)) ", selection[0].getFeatName(),GeoId1,PosId1,GeoId2); commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + getSelection().clearSelection(); return; } @@ -1810,7 +1870,13 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) } commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + getSelection().clearSelection(); return; @@ -1821,7 +1887,13 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Perpendicular',%d,%d)) ", selection[0].getFeatName(),GeoId1,GeoId2); commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + getSelection().clearSelection(); return; } @@ -1949,7 +2021,13 @@ void CmdSketcherConstrainTangent::activated(int iMsg) } commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + getSelection().clearSelection(); return; @@ -1973,7 +2051,13 @@ void CmdSketcherConstrainTangent::activated(int iMsg) Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Tangent',%d,%d,%d,%d)) ", selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2); commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + getSelection().clearSelection(); return; } @@ -1995,7 +2079,13 @@ void CmdSketcherConstrainTangent::activated(int iMsg) Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Tangent',%d,%d,%d)) ", selection[0].getFeatName(),GeoId1,PosId1,GeoId2); commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + getSelection().clearSelection(); return; } @@ -2055,7 +2145,13 @@ void CmdSketcherConstrainTangent::activated(int iMsg) Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Tangent',%d,%d)) ", selection[0].getFeatName(),GeoId1,GeoId2); commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + getSelection().clearSelection(); return; } @@ -2305,7 +2401,13 @@ void CmdSketcherConstrainRadius::activated(int iMsg) } } commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + commitNeeded=false; updateNeeded=false; } @@ -2332,8 +2434,13 @@ void CmdSketcherConstrainRadius::activated(int iMsg) if(commitNeeded) commitCommand(); - //if(updateNeeded) - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + if(updateNeeded) { + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + } } @@ -2721,8 +2828,12 @@ void CmdSketcherConstrainEqual::activated(int iMsg) } // finish the transaction and update commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + if(autoRecompute) + Gui::Command::updateActive(); // clear the selection (convenience) getSelection().clearSelection(); @@ -2802,7 +2913,12 @@ void CmdSketcherConstrainSymmetric::activated(int iMsg) // finish the transaction and update commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); // clear the selection (convenience) @@ -2854,7 +2970,12 @@ void CmdSketcherConstrainSymmetric::activated(int iMsg) // finish the transaction and update commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); // clear the selection (convenience) @@ -2871,7 +2992,12 @@ void CmdSketcherConstrainSymmetric::activated(int iMsg) // finish the transaction and update commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); // clear the selection (convenience) @@ -3013,7 +3139,12 @@ void CmdSketcherConstrainSnellsLaw::activated(int iMsg) }*/ commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); // clear the selection (convenience) @@ -3256,7 +3387,12 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) // finish the transaction and update commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); if(extra_elements){ @@ -3413,7 +3549,11 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) // finish the transaction and update commitCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); if(extra_elements){ @@ -3553,8 +3693,11 @@ void CmdSketcherToggleDrivingConstraint::activated(int iMsg) else abortCommand(); - //updateActive(); on adding constraints the updateActive's are unnecessary and introduce extra recomputes - + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); // clear the selection (convenience) getSelection().clearSelection(); diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index c279832ff..34c81ddb4 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -255,7 +255,6 @@ public: } Gui::Command::commitCommand(); - Gui::Command::updateActive(); // add auto constraints for the line segment start if (sugConstr1.size() > 0) { @@ -268,11 +267,17 @@ public: createAutoConstraints(sugConstr2, getHighestCurveIndex(), Sketcher::end); sugConstr2.clear(); } + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); EditCurve.clear(); sketchgui->drawEdit(EditCurve); - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + //ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); if(continuousMode){ @@ -507,10 +512,8 @@ public: firstCurve+3); } - Gui::Command::commitCommand(); - Gui::Command::updateActive(); - + // add auto constraints at the start of the first side if (sugConstr1.size() > 0) { createAutoConstraints(sugConstr1, getHighestCurveIndex() - 3 , Sketcher::start); @@ -522,8 +525,14 @@ public: createAutoConstraints(sugConstr2, getHighestCurveIndex() - 2, Sketcher::end); sugConstr2.clear(); } - + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + + //ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); if(continuousMode){ @@ -1016,7 +1025,12 @@ public: lastCurve,lastEndPosId,firstCurve,firstPosId); } Gui::Command::commitCommand(); - Gui::Command::updateActive(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); } if(addedGeometry && geometryCreationMode==Construction) { @@ -1070,8 +1084,7 @@ public: } else { Gui::Command::commitCommand(); - Gui::Command::updateActive(); - + // Add auto constraints if (sugConstr1.size() > 0) { // this is relevant only to the very first point createAutoConstraints(sugConstr1, getHighestCurveIndex(), Sketcher::start); @@ -1083,6 +1096,12 @@ public: sugConstr2.clear(); } + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + // remember the vertex for the next rounds constraint.. previousCurve = getHighestCurveIndex(); previousPosId = (SegmentMode == SEGMENT_MODE_Arc && startAngle > endAngle) ? @@ -1383,8 +1402,7 @@ public: } Gui::Command::commitCommand(); - Gui::Command::updateActive(); - + // Auto Constraint center point if (sugConstr1.size() > 0) { createAutoConstraints(sugConstr1, getHighestCurveIndex(), Sketcher::mid); @@ -1404,6 +1422,12 @@ public: } ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + + //ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); if(continuousMode){ @@ -1680,8 +1704,7 @@ public: } Gui::Command::commitCommand(); - Gui::Command::updateActive(); - + // Auto Constraint first picked point if (sugConstr1.size() > 0) { createAutoConstraints(sugConstr1, getHighestCurveIndex(), arcPos1); @@ -1699,8 +1722,14 @@ public: createAutoConstraints(sugConstr3, getHighestCurveIndex(), Sketcher::none); sugConstr3.clear(); } - + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + + //ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); if(continuousMode){ @@ -1986,7 +2015,6 @@ public: } Gui::Command::commitCommand(); - Gui::Command::updateActive(); // add auto constraints for the center point if (sugConstr1.size() > 0) { @@ -1999,8 +2027,14 @@ public: createAutoConstraints(sugConstr2, getHighestCurveIndex(), Sketcher::none); sugConstr2.clear(); } - + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + + //ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); if(continuousMode){ @@ -2797,7 +2831,6 @@ private: } Gui::Command::commitCommand(); - Gui::Command::updateActive(); if (method == CENTER_PERIAPSIS_B) { // add auto constraints for the center point @@ -2829,34 +2862,40 @@ private: sugConstr3.clear(); } } + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + // This code enables the continuous creation mode. + if (constrMethod == 0) { + method = CENTER_PERIAPSIS_B; + mode = STATUS_SEEK_CENTROID; + } else { + method = PERIAPSIS_APOAPSIS_B; + mode = STATUS_SEEK_PERIAPSIS; + } + editCurve.clear(); + sketchgui->drawEdit(editCurve); + + //ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); + + + if(continuousMode){ // This code enables the continuous creation mode. - if (constrMethod == 0) { - method = CENTER_PERIAPSIS_B; - mode = STATUS_SEEK_CENTROID; - } else { - method = PERIAPSIS_APOAPSIS_B; - mode = STATUS_SEEK_PERIAPSIS; - } - editCurve.clear(); - sketchgui->drawEdit(editCurve); - - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); - bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); - - - if(continuousMode){ - // This code enables the continuous creation mode. - editCurve.resize(33); - applyCursor(); - /* It is ok not to call to purgeHandler - * in continuous creation mode because the - * handler is destroyed by the quit() method on pressing the - * right button of the mouse */ - } - else{ - sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider - } + editCurve.resize(33); + applyCursor(); + /* It is ok not to call to purgeHandler + * in continuous creation mode because the + * handler is destroyed by the quit() method on pressing the + * right button of the mouse */ + } + else{ + sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + } } }; @@ -3209,7 +3248,6 @@ public: } Gui::Command::commitCommand(); - Gui::Command::updateActive(); // add auto constraints for the center point if (sugConstr1.size() > 0) { @@ -3234,8 +3272,14 @@ public: createAutoConstraints(sugConstr4, currentgeoid, isOriginalArcCCW?Sketcher::end:Sketcher::start); sugConstr4.clear(); } - + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + + //ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); if(continuousMode){ @@ -3577,7 +3621,6 @@ public: } Gui::Command::commitCommand(); - Gui::Command::updateActive(); // Auto Constraint first picked point if (sugConstr1.size() > 0) { @@ -3598,6 +3641,12 @@ public: } ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + + //ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); if(continuousMode){ @@ -3832,15 +3881,20 @@ public: EditPoint.fX,EditPoint.fY); Gui::Command::commitCommand(); - Gui::Command::updateActive(); // add auto constraints for the line segment start if (sugConstr.size() > 0) { createAutoConstraints(sugConstr, getHighestCurveIndex(), Sketcher::start); sugConstr.clear(); } + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + //ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); if(continuousMode){ @@ -4058,10 +4112,10 @@ public: virtual bool releaseButton(Base::Vector2D onSketchPos) { + bool construction=false; int VtId = sketchgui->getPreselectPoint(); if (Mode == STATUS_SEEK_First && VtId != -1) { int GeoId; - bool construction=false; Sketcher::PointPos PosId=Sketcher::none; sketchgui->getSketchObject()->getGeoVertexIndex(VtId,GeoId,PosId); const Part::Geometry *geom = sketchgui->getSketchObject()->getGeometry(GeoId); @@ -4111,7 +4165,12 @@ public: } Gui::Command::commitCommand(); - Gui::Command::updateActive(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); } return true; } @@ -4148,6 +4207,8 @@ public: double radius = Part::suggestFilletRadius(lineSeg1, lineSeg2, refPnt1, refPnt2); if (radius < 0) return false; + + construction=lineSeg1->Construction && lineSeg2->Construction; // create fillet between lines Gui::Command::openCommand("Create fillet"); @@ -4158,9 +4219,14 @@ public: firstPos.fX, firstPos.fY, secondPos.fX, secondPos.fY, radius); Gui::Command::commitCommand(); - Gui::Command::updateActive(); - if(lineSeg1->Construction && lineSeg2->Construction) { + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + + if(construction) { Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.toggleConstruction(%d) ", sketchgui->getObject()->getNameInDocument(), @@ -4330,7 +4396,12 @@ public: sketchgui->getObject()->getNameInDocument(), GeoId, onSketchPos.fX, onSketchPos.fY); Gui::Command::commitCommand(); - Gui::Command::updateActive(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); @@ -4504,7 +4575,13 @@ public: sketchgui->getObject()->getNameInDocument(), msg.pObjectName, msg.pSubName); Gui::Command::commitCommand(); - Gui::Command::updateActive(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + Gui::Selection().clearSelection(); /* this is ok not to call to purgeHandler * in continuous creation mode because the @@ -4758,7 +4835,6 @@ public: } Gui::Command::commitCommand(); - Gui::Command::updateActive(); // add auto constraints at the start of the first side if (sugConstr1.size() > 0) { @@ -4771,6 +4847,12 @@ public: createAutoConstraints(sugConstr2, getHighestCurveIndex() - 2, Sketcher::end); sugConstr2.clear(); } + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); @@ -4993,8 +5075,10 @@ public: } Gui::Command::commitCommand(); - Gui::Command::updateActive(); - + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + // add auto constraints at the center of the polygon if (sugConstr1.size() > 0) { createAutoConstraints(sugConstr1, getHighestCurveIndex(), Sketcher::mid); @@ -5006,6 +5090,9 @@ public: createAutoConstraints(sugConstr2, getHighestCurveIndex() - 1, Sketcher::end); sugConstr2.clear(); } + + if(autoRecompute) + Gui::Command::updateActive(); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index 12019ffb5..97a95974e 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -500,7 +500,7 @@ void DrawSketchHandler::createAutoConstraints(const std::vector } Gui::Command::commitCommand(); - Gui::Command::updateActive(); + //Gui::Command::updateActive(); // There is already an recompute in each command creation, this is redundant. } } } diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp index 45f8cf28f..6a64589d1 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp @@ -161,7 +161,12 @@ void EditDatumDialog::exec(bool atCursor) sketch->getNameInDocument(), ConstrNbr, newDatum, (const char*)newQuant.getUnit().getString().toUtf8()); Gui::Command::commitCommand(); - Gui::Command::updateActive(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); } catch (const Base::Exception& e) { QMessageBox::critical(qApp->activeWindow(), QObject::tr("Dimensional constraint"), QString::fromUtf8(e.what())); diff --git a/src/Mod/Sketcher/Gui/TaskSketcherMessages.cpp b/src/Mod/Sketcher/Gui/TaskSketcherMessages.cpp index 0bb72cd37..ee29e724c 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherMessages.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherMessages.cpp @@ -38,6 +38,8 @@ #include +#include + #include "ViewProviderSketch.h" using namespace SketcherGui; @@ -60,10 +62,25 @@ TaskSketcherMessages::TaskSketcherMessages(ViewProviderSketch *sketchView) ui->labelConstrainStatus->setOpenExternalLinks(false); - QObject::connect( + ui->autoUpdate->onRestore(); + + if(ui->autoUpdate->isChecked()) + sketchView->getSketchObject()->noRecomputes=false; + else + sketchView->getSketchObject()->noRecomputes=true; + + /*QObject::connect( ui->labelConstrainStatus, SIGNAL(linkActivated(const QString &)), this , SLOT (on_labelConstrainStatus_linkActivated(const QString &)) ); + QObject::connect( + ui->autoUpdate, SIGNAL(stateChanged(int)), + this , SLOT (on_autoUpdate_stateChanged(int)) + ); + QObject::connect( + ui->manualUpdate, SIGNAL(clicked(bool)), + this , SLOT (on_manualUpdate_clicked(bool)) + );*/ } TaskSketcherMessages::~TaskSketcherMessages() @@ -92,5 +109,21 @@ void TaskSketcherMessages::on_labelConstrainStatus_linkActivated(const QString & Gui::Application::Instance->commandManager().runCommandByName("Sketcher_SelectRedundantConstraints"); } +void TaskSketcherMessages::on_autoUpdate_stateChanged(int state) +{ + if(state==Qt::Checked) { + sketchView->getSketchObject()->noRecomputes=false; + ui->autoUpdate->onSave(); + } + else if (state==Qt::Unchecked) { + sketchView->getSketchObject()->noRecomputes=true; + ui->autoUpdate->onSave(); + } +} + +void TaskSketcherMessages::on_manualUpdate_clicked(bool checked) +{ + Gui::Command::updateActive(); +} #include "moc_TaskSketcherMessages.cpp" diff --git a/src/Mod/Sketcher/Gui/TaskSketcherMessages.h b/src/Mod/Sketcher/Gui/TaskSketcherMessages.h index 198fddf54..591db25a8 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherMessages.h +++ b/src/Mod/Sketcher/Gui/TaskSketcherMessages.h @@ -52,6 +52,8 @@ public: private Q_SLOTS: void on_labelConstrainStatus_linkActivated(const QString &); + void on_autoUpdate_stateChanged(int state); + void on_manualUpdate_clicked(bool checked); protected: ViewProviderSketch *sketchView; diff --git a/src/Mod/Sketcher/Gui/TaskSketcherMessages.ui b/src/Mod/Sketcher/Gui/TaskSketcherMessages.ui index eb40e2701..67c6bb173 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherMessages.ui +++ b/src/Mod/Sketcher/Gui/TaskSketcherMessages.ui @@ -6,8 +6,8 @@ 0 0 - 228 - 89 + 253 + 115 @@ -46,8 +46,55 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Auto Update + + + false + + + AutoRecompute + + + Mod/Sketcher + + + + + + + Update + + + + + + + + Gui::PrefCheckBox + QCheckBox +
Gui/PrefWidgets.h
+
+
diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index b5eb47589..22839d61e 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -706,7 +706,12 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe ,GeoId, PosId, x-xInit, y-yInit, relative ? 1 : 0 ); Gui::Command::commitCommand(); - Gui::Command::updateActive(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); } catch (const Base::Exception& e) { Gui::Command::abortCommand(); @@ -735,7 +740,11 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe ,edit->DragCurve, Sketcher::none, x-xInit, y-yInit, relative ? 1 : 0 ); Gui::Command::commitCommand(); - Gui::Command::updateActive(); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); } catch (const Base::Exception& e) { Gui::Command::abortCommand(); @@ -4744,7 +4753,7 @@ bool ViewProviderSketch::onDelete(const std::vector &subList) } } - Gui::Command::updateActive(); + getSketchObject()->getSolvedSketch().solve(); this->drawConstraintIcons(); this->updateColor();