Salome HOME
Task "Make the size of the selection area even bigger, especially for points"
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMultiRotation.cpp
index 5fc487e120e199815f7fae6f6b9486fbbaa03603..bd53679d9ae635b2882bc62374c5703e5b936a76 100644 (file)
@@ -10,8 +10,7 @@
 
 void SketchSolver_ConstraintMultiRotation::getAttributes(
     EntityWrapperPtr& theCenter, double& theAngle,
-    bool& theFullValue,
-    std::list< std::list<EntityWrapperPtr> >& theEntities)
+    bool& theFullValue, std::list<EntityWrapperPtr>& theEntities)
 {
   DataPtr aData = myBaseConstraint->data();
   theAngle = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
@@ -25,13 +24,13 @@ void SketchSolver_ConstraintMultiRotation::getAttributes(
 
   myType = CONSTRAINT_MULTI_ROTATION;
 
-  myStorage->update(aCenterAttr, GID_OUTOFGROUP);
+  myStorage->update(aCenterAttr);
   theCenter = myStorage->entity(aCenterAttr);
 
   AttributeStringPtr aMethodTypeAttr = aData->string(SketchPlugin_MultiRotation::ANGLE_TYPE());
   theFullValue = aMethodTypeAttr->value() != "SingleAngle";
 
-  getEntitiesAndCopies(theEntities);
+  getEntities(theEntities);
 }
 
 void SketchSolver_ConstraintMultiRotation::process()
@@ -44,19 +43,19 @@ void SketchSolver_ConstraintMultiRotation::process()
 
   EntityWrapperPtr aRotationCenter;
   bool isFullValue;
-  std::list<std::list<EntityWrapperPtr> > anEntitiesAndCopies;
-  getAttributes(aRotationCenter, myAngle, isFullValue, anEntitiesAndCopies);
+  std::list<EntityWrapperPtr> aBaseEntities;
+  getAttributes(aRotationCenter, myAngle, isFullValue, aBaseEntities);
   if (!myErrorMsg.empty())
     return;
 
   BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
   std::list<ConstraintWrapperPtr> aRotConstraints;
 
-  std::list< std::list<EntityWrapperPtr> >::iterator anEntIt = anEntitiesAndCopies.begin();
-  for (; anEntIt != anEntitiesAndCopies.end(); ++anEntIt) {
+  std::list<EntityWrapperPtr>::iterator anEntIt = aBaseEntities.begin();
+  for (; anEntIt != aBaseEntities.end(); ++anEntIt) {
     std::list<ConstraintWrapperPtr> aNewConstraints =
         aBuilder->createConstraint(myBaseConstraint, myGroupID, mySketchID, myType,
-        myAngle, isFullValue, aRotationCenter, EntityWrapperPtr(), *anEntIt);
+        myAngle, isFullValue, aRotationCenter, EntityWrapperPtr(), std::list<EntityWrapperPtr>(1, *anEntIt));
     aRotConstraints.insert(aRotConstraints.end(), aNewConstraints.begin(), aNewConstraints.end());
   }
   myStorage->addConstraint(myBaseConstraint, aRotConstraints);
@@ -124,6 +123,9 @@ void SketchSolver_ConstraintMultiRotation::updateLocal()
 
 void SketchSolver_ConstraintMultiRotation::adjustConstraint()
 {
+  if (myAdjusted)
+    return;
+
   if (fabs(myAngle) < tolerance) {
     myStorage->setNeedToResolve(false);
     return;
@@ -134,9 +136,46 @@ void SketchSolver_ConstraintMultiRotation::adjustConstraint()
   for (; aCIt != aConstraints.end(); ++aCIt)
     (*aCIt)->setValue(myAngle);
 
+  // Obtain coordinates of rotation center
+  EntityWrapperPtr aRotCenter = myStorage->entity(
+      myBaseConstraint->attribute(SketchPlugin_MultiRotation::CENTER_ID()));
+  std::list<ParameterWrapperPtr> aParams = aRotCenter->parameters();
+  myCenterCoord[0] = aParams.front()->value();
+  myCenterCoord[1] = aParams.back()->value();
+
+  double anAngleValue = myAngle;
+  if (myIsFullValue && myNumberOfCopies > 0)
+    anAngleValue /= myNumberOfCopies;
+
+  myRotationVal[0] = sin(anAngleValue * PI / 180.0);
+  myRotationVal[1] = cos(anAngleValue * PI / 180.0);
+
   SketchSolver_ConstraintMulti::adjustConstraint();
 }
 
+void SketchSolver_ConstraintMultiRotation::getRelative(
+    double theAbsX, double theAbsY, double& theRelX, double& theRelY)
+{
+  theRelX = theAbsX - myCenterCoord[0];
+  theRelY = theAbsY - myCenterCoord[1];
+}
+
+void SketchSolver_ConstraintMultiRotation::getAbsolute(
+    double theRelX, double theRelY, double& theAbsX, double& theAbsY)
+{
+  theAbsX = theRelX + myCenterCoord[0];
+  theAbsY = theRelY + myCenterCoord[1];
+}
+
+void SketchSolver_ConstraintMultiRotation::transformRelative(double& theX, double& theY)
+{
+  // rotate direction
+  // myRotationVal[0] = sinA, myRotationVal[1] = cosA
+  double aTemp = theX * myRotationVal[1] - theY * myRotationVal[0];
+  theY = theX * myRotationVal[0] + theY * myRotationVal[1];
+  theX = aTemp;
+}
+
 const std::string& SketchSolver_ConstraintMultiRotation::nameNbObjects()
 {
   return SketchPlugin_MultiRotation::NUMBER_OF_OBJECTS_ID();