Salome HOME
Change icons for chamfer
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMultiRotation.cpp
index 96beef3a2abbabcaca6b54e93d1c488510afddb2..cf2cac48aab28cee9cf02c1e0e9a49e9574ff8d0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -12,9 +12,9 @@
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include <SketchSolver_ConstraintMultiRotation.h>
@@ -34,7 +34,7 @@
 
 void SketchSolver_ConstraintMultiRotation::getAttributes(
     EntityWrapperPtr& theCenter, ScalarWrapperPtr& theAngle,
-    bool& theFullValue, std::list<EntityWrapperPtr>& theEntities)
+    bool& theFullValue, bool& theReversed, std::list<EntityWrapperPtr>& theEntities)
 {
   AttributePtr anAngleAttr = myBaseConstraint->attribute(SketchPlugin_MultiRotation::ANGLE_ID());
   PlaneGCSSolver_AttributeBuilder aValueBuilder;
@@ -58,6 +58,8 @@ void SketchSolver_ConstraintMultiRotation::getAttributes(
       myBaseConstraint->string(SketchPlugin_MultiRotation::ANGLE_TYPE());
   theFullValue = aMethodTypeAttr->value() != "SingleAngle";
 
+  theReversed = myBaseConstraint->boolean(SketchPlugin_MultiRotation::REVERSED_ID())->value();
+
   getEntities(theEntities);
 
   // add owner of central point of Multi-Rotation to the list of monitored features
@@ -76,7 +78,7 @@ void SketchSolver_ConstraintMultiRotation::process()
 
   EntityWrapperPtr aRotationCenter;
   std::list<EntityWrapperPtr> aBaseEntities;
-  getAttributes(aRotationCenter, myAngle, myIsFullValue, aBaseEntities);
+  getAttributes(aRotationCenter, myAngle, myIsFullValue, myIsRevered, aBaseEntities);
   if (!myErrorMsg.empty())
     return;
 
@@ -89,10 +91,12 @@ void SketchSolver_ConstraintMultiRotation::process()
 void SketchSolver_ConstraintMultiRotation::updateLocal()
 {
   double aValue = myBaseConstraint->real(SketchPlugin_MultiRotation::ANGLE_ID())->value();
-  if (fabs(myAngle->value() - aValue) > tolerance)
+  bool isReversed = myBaseConstraint->boolean(SketchPlugin_MultiRotation::REVERSED_ID())->value();
+  if (fabs(myAngle->value() - aValue) > tolerance || isReversed != myIsRevered)
     myAdjusted = false;
   // update angle value
   myAngle->setValue(aValue);
+  myIsRevered = isReversed;
 
   // update center
   DataPtr aData = myBaseConstraint->data();
@@ -122,17 +126,38 @@ void SketchSolver_ConstraintMultiRotation::adjustConstraint()
     myStorage->setNeedToResolve(false);
     return;
   }
+  if (myIsRevered)
+    anAngleValue *= -1.0;
 
   // Obtain coordinates of rotation center
+  AttributeRefAttrPtr aCenterAttr =
+      myBaseConstraint->refattr(SketchPlugin_MultiRotation::CENTER_ID());
   std::shared_ptr<PlaneGCSSolver_PointWrapper> aRotCenter =
-      std::dynamic_pointer_cast<PlaneGCSSolver_PointWrapper>(myStorage->entity(
-      myBaseConstraint->attribute(SketchPlugin_MultiRotation::CENTER_ID())));
-  GCSPointPtr aCenterPoint = aRotCenter->point();
-  myCenterCoord[0] = *(aCenterPoint->x);
-  myCenterCoord[1] = *(aCenterPoint->y);
+      std::dynamic_pointer_cast<PlaneGCSSolver_PointWrapper>(
+      myStorage->entity(AttributePtr(aCenterAttr)));
+  if (aRotCenter)
+  {
+    GCSPointPtr aCenterPoint = aRotCenter->point();
+    myCenterCoord[0] = *(aCenterPoint->x);
+    myCenterCoord[1] = *(aCenterPoint->y);
+  }
+  else
+  {
+    AttributePoint2DPtr aCenterPnt =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aCenterAttr->attr());
+    myCenterCoord[0] = aCenterPnt->x();
+    myCenterCoord[1] = aCenterPnt->y();
+  }
 
   if (myIsFullValue && myNumberOfCopies > 0)
-    anAngleValue /= myNumberOfCopies;
+  {
+    // if the full angle value is equal to 360, then distribute rotated items
+    // to avoid superposition of original feature and last copy
+    if (fabs(anAngleValue - 360.0) < 1.e-7)
+      anAngleValue /= (myNumberOfCopies + 1);
+    else
+      anAngleValue /= myNumberOfCopies;
+  }
 
   myRotationVal[0] = sin(anAngleValue * PI / 180.0);
   myRotationVal[1] = cos(anAngleValue * PI / 180.0);