]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix crash while updating number of copied of "Multi" constraints.
authorazv <azv@opencascade.com>
Wed, 17 May 2017 09:06:09 +0000 (12:06 +0300)
committerazv <azv@opencascade.com>
Wed, 17 May 2017 09:06:09 +0000 (12:06 +0300)
Fix unchangeable value of Multi-Rotation constraint.

src/SketchSolver/SketchSolver_ConstraintMulti.cpp
src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp
src/SketchSolver/SketchSolver_ConstraintMultiRotation.h

index c9b1a338bfba203ba0fc727ef1262103eb9f53e6..9c270943f3445772c9ec038337b8019f1cbfcb65 100644 (file)
@@ -86,7 +86,7 @@ bool SketchSolver_ConstraintMulti::remove()
           std::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
       if (anEntity->isExternal() && !aSketchFeature->isExternal())
         myStorage->makeNonExternal(anEntity);
-    } else
+    } else if ((*anIt)->data() && (*anIt)->data()->isValid())
       myStorage->update(*anIt, true);
   }
 
index 2a91c6285cf281479c864bea6bd7e0406e407923..59a095d71b66bb14e5f6e4703f32210dc7ce10b3 100644 (file)
 #include <cmath>
 
 void SketchSolver_ConstraintMultiRotation::getAttributes(
-    EntityWrapperPtr& theCenter, EntityWrapperPtr& theAngle,
+    EntityWrapperPtr& theCenter, ScalarWrapperPtr& theAngle,
     bool& theFullValue, std::list<EntityWrapperPtr>& theEntities)
 {
   AttributePtr anAngleAttr = myBaseConstraint->attribute(SketchPlugin_MultiRotation::ANGLE_ID());
   PlaneGCSSolver_AttributeBuilder aValueBuilder;
-  theAngle = aValueBuilder.createAttribute(anAngleAttr);
+  theAngle = std::dynamic_pointer_cast<PlaneGCSSolver_ScalarWrapper>(
+      aValueBuilder.createAttribute(anAngleAttr));
   myStorage->addEntity(anAngleAttr, theAngle);
 
   AttributeRefAttrPtr aCenterAttr =
@@ -56,15 +57,12 @@ void SketchSolver_ConstraintMultiRotation::process()
     return;
   }
 
-  EntityWrapperPtr anAngle;
   EntityWrapperPtr aRotationCenter;
   std::list<EntityWrapperPtr> aBaseEntities;
-  getAttributes(aRotationCenter, anAngle, myIsFullValue, aBaseEntities);
+  getAttributes(aRotationCenter, myAngle, myIsFullValue, aBaseEntities);
   if (!myErrorMsg.empty())
     return;
 
-  ScalarWrapperPtr anAngleVal = std::dynamic_pointer_cast<PlaneGCSSolver_ScalarWrapper>(anAngle);
-  myAngle = anAngleVal->value();
   myAdjusted = false;
   adjustConstraint();
 
@@ -74,10 +72,10 @@ void SketchSolver_ConstraintMultiRotation::process()
 void SketchSolver_ConstraintMultiRotation::updateLocal()
 {
   double aValue = myBaseConstraint->real(SketchPlugin_MultiRotation::ANGLE_ID())->value();
-  if (fabs(myAngle - aValue) > tolerance)
+  if (fabs(myAngle->value() - aValue) > tolerance)
     myAdjusted = false;
   // update angle value
-  myAngle = aValue;
+  myAngle->setValue(aValue);
 
   // update center
   DataPtr aData = myBaseConstraint->data();
@@ -102,7 +100,8 @@ void SketchSolver_ConstraintMultiRotation::adjustConstraint()
   if (myAdjusted)
     return;
 
-  if (fabs(myAngle) < tolerance) {
+  double anAngleValue = myAngle->value();
+  if (fabs(anAngleValue) < tolerance) {
     myStorage->setNeedToResolve(false);
     return;
   }
@@ -115,7 +114,6 @@ void SketchSolver_ConstraintMultiRotation::adjustConstraint()
   myCenterCoord[0] = *(aCenterPoint->x);
   myCenterCoord[1] = *(aCenterPoint->y);
 
-  double anAngleValue = myAngle;
   if (myIsFullValue && myNumberOfCopies > 0)
     anAngleValue /= myNumberOfCopies;
 
index 48f367deb459576de96d5eae418d534ab6595482..2806ded696b65a5ee0919e772f0156e643705415 100644 (file)
@@ -33,7 +33,7 @@ protected:
   /// \param[out] theFullValue  applying translation using the disstance as a full or single value
   /// \param[out] theEntities list of base entities
   void getAttributes(EntityWrapperPtr&            theCenter,
-                     EntityWrapperPtr&            theAngle,
+                     ScalarWrapperPtr&            theAngle,
                      bool&                        theFullValue,
                      std::list<EntityWrapperPtr>& theEntities);
 
@@ -58,7 +58,7 @@ private:
 
 private:
   AttributePoint2DPtr myCenterPointAttribute; ///< a center of rotation
-  double              myAngle;           ///< angle of rotation
+  ScalarWrapperPtr    myAngle;                ///< angle of rotation
 
   double myCenterCoord[2]; ///< coordinates of rotation center
   double myRotationVal[2]; ///< sinus and cosine of rotation angle