From: azv Date: Wed, 29 Mar 2017 13:18:09 +0000 (+0300) Subject: Allow arc parameters to be recalculated by sketch solver X-Git-Tag: V_2.7.0~146 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=52f79b0092a140175328ebf5c69cd9e27b7b7f59;p=modules%2Fshaper.git Allow arc parameters to be recalculated by sketch solver --- diff --git a/src/Events/Events_Loop.cpp b/src/Events/Events_Loop.cpp index 181f588a2..1bbe62aaa 100644 --- a/src/Events/Events_Loop.cpp +++ b/src/Events/Events_Loop.cpp @@ -207,7 +207,8 @@ void Events_Loop::flush(const Events_ID& theID) } } } - if (hasEventsToFlush && myGroups.empty()) { // no more messages left in the queue, so, finalize the sketch processing + if (hasEventsToFlush && myGroups.empty()) { + // no more messages left in the queue, so, finalize the sketch processing static Events_ID anID = Events_Loop::eventByName("SketchPrepared"); std::shared_ptr aMsg(new Events_Message(anID, this)); Events_Loop::loop()->send(aMsg, false); diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index 1890400ce..0dac256a8 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -222,31 +222,25 @@ void SketchPlugin_Arc::attributeChanged(const std::string& theID) return; std::shared_ptr aCircleForArc(new GeomAPI_Circ2d(aCenter, aStart)); - bool aWasBlocked = data()->blockSendAttributeUpdated(true); - // The Arc end point is projected - // on the circle formed by center and start points + // Do not recalculate REVERSED flag if the arc is not consistent std::shared_ptr aProjection = aCircleForArc->project(anEnd); - if (aProjection && anEnd->distance(aProjection) > tolerance) { - anEndAttr->setValue(aProjection); - anEnd = aProjection; - } - data()->blockSendAttributeUpdated(aWasBlocked, false); - - double aParameterNew = 0.0; - if(aCircleForArc->parameter(anEnd, paramTolerance, aParameterNew)) { - bool aWasBlocked = data()->blockSendAttributeUpdated(true); - if(myParamBefore <= PI / 2.0 && aParameterNew >= PI * 1.5) { - if(!boolean(REVERSED_ID())->value()) { - boolean(REVERSED_ID())->setValue(true); - } - } else if(myParamBefore >= PI * 1.5 && aParameterNew <= PI / 2.0) { - if(boolean(REVERSED_ID())->value()) { - boolean(REVERSED_ID())->setValue(false); + if (aProjection && anEnd->distance(aProjection) <= tolerance) { + double aParameterNew = 0.0; + if(aCircleForArc->parameter(anEnd, paramTolerance, aParameterNew)) { + bool aWasBlocked = data()->blockSendAttributeUpdated(true); + if(myParamBefore <= PI / 2.0 && aParameterNew >= PI * 1.5) { + if(!boolean(REVERSED_ID())->value()) { + boolean(REVERSED_ID())->setValue(true); + } + } else if(myParamBefore >= PI * 1.5 && aParameterNew <= PI / 2.0) { + if(boolean(REVERSED_ID())->value()) { + boolean(REVERSED_ID())->setValue(false); + } } + data()->blockSendAttributeUpdated(aWasBlocked, false); } - data()->blockSendAttributeUpdated(aWasBlocked, false); + myParamBefore = aParameterNew; } - myParamBefore = aParameterNew; } double aRadius = 0; diff --git a/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py b/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py index 2fb4d4711..47bce5029 100644 --- a/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py +++ b/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py @@ -91,27 +91,27 @@ aCenter = [15., 20.] aSession.startOperation() anArcCenter.setValue(aCenter[0], aCenter[1]) aSession.finishOperation() -verifyLastArc(aSketchFeature, aCenter, [], []) +verifyLastArc(aSketchFeature, [], [], []) # Move start point deltaX, deltaY = 5., 2. aStart = [anArcStartPoint.x() + deltaX, anArcStartPoint.y() + deltaY] aSession.startOperation() anArcStartPoint.setValue(aStart[0], aStart[1]) aSession.finishOperation() -verifyLastArc(aSketchFeature, [], aStart, []) +verifyLastArc(aSketchFeature, [], [], []) # Move end point aEnd = [anArcEndPoint.x() - deltaX, anArcEndPoint.y() - deltaY] aSession.startOperation() anArcEndPoint.setValue(aEnd[0], aEnd[1]) aSession.finishOperation() -verifyLastArc(aSketchFeature, [], [], aEnd) +verifyLastArc(aSketchFeature, [], [], []) # Check that changing the radius does not affect arc aSession.startOperation() anArcRadius = aSketchArc.real("radius") aPrevRadius = anArcRadius.value(); anArcRadius.setValue(aPrevRadius + 10.) aSession.finishOperation() -assert (math.fabs(anArcRadius.value - aPrevRadius) < TOLERANCE) +assert (math.fabs(anArcRadius.value() - aPrevRadius) < TOLERANCE) verifyLastArc(aSketchFeature, [], [], []) # Check that changing the angle does not affect arc aSession.startOperation() @@ -119,7 +119,7 @@ anArcAngle = aSketchArc.real("angle") aPrevAngle = anArcAngle.value() anArcAngle.setValue(aPrevAngle + 10.) aSession.finishOperation() -assert (math.fabs(anArcAngle.value - aPrevAngle) < TOLERANCE) +assert (math.fabs(anArcAngle.value() - aPrevAngle) < TOLERANCE) verifyLastArc(aSketchFeature, [], [], []) #========================================================================= diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h index 1855de212..c7e1d1eda 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h @@ -64,6 +64,10 @@ public: /// \brief Remove all features became invalid virtual void removeInvalidEntities(); + /// \brief Check the storage has constraints + virtual bool isEmpty() const + { return SketchSolver_Storage::isEmpty() && myArcConstraintMap.empty(); } + private: /// \brief Convert feature using specified builder. EntityWrapperPtr createFeature(const FeaturePtr& theFeature, diff --git a/src/SketchSolver/SketchSolver_Group.h b/src/SketchSolver/SketchSolver_Group.h index a9d305a44..a5fb221ae 100644 --- a/src/SketchSolver/SketchSolver_Group.h +++ b/src/SketchSolver/SketchSolver_Group.h @@ -37,7 +37,7 @@ class SketchSolver_Group /// \brief Returns true if the group has no constraints yet inline bool isEmpty() const { - return myConstraints.empty(); + return myConstraints.empty() && myTempConstraints.empty(); } /// \brief Check for valid sketch data diff --git a/src/SketchSolver/SketchSolver_Storage.h b/src/SketchSolver/SketchSolver_Storage.h index bfd8bc620..7753d6433 100644 --- a/src/SketchSolver/SketchSolver_Storage.h +++ b/src/SketchSolver/SketchSolver_Storage.h @@ -97,7 +97,7 @@ public: bool isConsistent() const; /// \brief Check the storage has constraints - bool isEmpty() const + virtual bool isEmpty() const { return myConstraintMap.empty(); } /// \brief Shows the sketch should be resolved