Salome HOME
Using test for testing number of sub-shapes.
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMultiTranslation.cpp
index d5a08f06950028694e487d9efff6cff8e268574a..4f1741e7662916798ecae0c844f21434d02118ed 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 #include <SketchSolver_ConstraintMultiTranslation.h>
 #include <SketchSolver_Error.h>
 #include <SketchSolver_Manager.h>
@@ -10,7 +12,7 @@
 
 void SketchSolver_ConstraintMultiTranslation::getAttributes(
     EntityWrapperPtr& theStartPoint, EntityWrapperPtr& theEndPoint,
-    bool& theFullValue, std::list< std::list<EntityWrapperPtr> >& theEntities)
+    bool& theFullValue, std::list<EntityWrapperPtr>& theEntities)
 {
   DataPtr aData = myBaseConstraint->data();
   AttributePtr aStartPointAttr = aData->attribute(SketchPlugin_MultiTranslation::START_POINT_ID());
@@ -31,7 +33,7 @@ void SketchSolver_ConstraintMultiTranslation::getAttributes(
   AttributeStringPtr aMethodTypeAttr = aData->string(SketchPlugin_MultiTranslation::VALUE_TYPE());
   theFullValue = aMethodTypeAttr->value() != "SingleValue";
 
-  getEntitiesAndCopies(theEntities);
+  getEntities(theEntities);
 }
 
 void SketchSolver_ConstraintMultiTranslation::process()
@@ -44,29 +46,25 @@ void SketchSolver_ConstraintMultiTranslation::process()
 
   EntityWrapperPtr aStartPoint, aEndPoint;
   bool aFullValue;
-  std::list<std::list<EntityWrapperPtr> > anEntitiesAndCopies;
-  getAttributes(aStartPoint, aEndPoint, aFullValue, anEntitiesAndCopies);
+  std::list<EntityWrapperPtr> aBaseEntities;
+  getAttributes(aStartPoint, aEndPoint, aFullValue, aBaseEntities);
   if (!myErrorMsg.empty())
     return;
 
   AttributeStringPtr aMethodTypeAttr =
       myBaseConstraint->data()->string(SketchPlugin_MultiTranslation::VALUE_TYPE());
-  myIsFullValue = aMethodTypeAttr->value() != "SingleValue";
-
 
   BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
   std::list<ConstraintWrapperPtr> aTransConstraints;
 
-  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,
-        0.0, aFullValue, aStartPoint, aEndPoint, *anEntIt);
-    aTransConstraints.insert(aTransConstraints.end(), aNewConstraints.begin(), aNewConstraints.end());
+        0.0, aFullValue, aStartPoint, aEndPoint, std::list<EntityWrapperPtr>(1, *anEntIt));
+    aTransConstraints.insert(aTransConstraints.end(),
+                             aNewConstraints.begin(), aNewConstraints.end());
   }
-  std::list<ConstraintWrapperPtr>::iterator aTCIt = aTransConstraints.begin();
-  for (; aTCIt != aTransConstraints.end(); ++ aTCIt)
-    (*aTCIt)->setIsFullValue(myIsFullValue);
 
   myStorage->addConstraint(myBaseConstraint, aTransConstraints);
 
@@ -116,7 +114,8 @@ void SketchSolver_ConstraintMultiTranslation::updateLocal()
                                                   aSLast = aConstraintEntities.end();
       EntityWrapperPtr aStartEntity = *aSIt++;
       if (aStartPointChanged) {
-        AttributePtr aStartPointAttr = aData->attribute(SketchPlugin_MultiTranslation::START_POINT_ID());
+        AttributePtr aStartPointAttr =
+          aData->attribute(SketchPlugin_MultiTranslation::START_POINT_ID());
         myStorage->update(aStartPointAttr);
         aStartEntity = myStorage->entity(aStartPointAttr);
       }
@@ -124,7 +123,8 @@ void SketchSolver_ConstraintMultiTranslation::updateLocal()
 
       EntityWrapperPtr anEndEntity = *aSIt++;
       if (anEndPointChanged) {
-        AttributePtr anEndPointAttr = aData->attribute(SketchPlugin_MultiTranslation::END_POINT_ID());
+        AttributePtr anEndPointAttr =
+          aData->attribute(SketchPlugin_MultiTranslation::END_POINT_ID());
         myStorage->update(anEndPointAttr);
         anEndEntity = myStorage->entity(anEndPointAttr);
       }
@@ -141,3 +141,48 @@ void SketchSolver_ConstraintMultiTranslation::updateLocal()
   }
 }
 
+void SketchSolver_ConstraintMultiTranslation::adjustConstraint()
+{
+  if (myAdjusted)
+    return;
+
+  // Obtain delta between start and end points of translation
+  EntityWrapperPtr aStart = myStorage->entity(
+      myBaseConstraint->attribute(SketchPlugin_MultiTranslation::START_POINT_ID()));
+  std::list<ParameterWrapperPtr> aStartParams = aStart->parameters();
+  EntityWrapperPtr aEnd = myStorage->entity(
+      myBaseConstraint->attribute(SketchPlugin_MultiTranslation::END_POINT_ID()));
+  std::list<ParameterWrapperPtr> aEndParams = aEnd->parameters();
+
+  myDelta[0] = aEndParams.front()->value() - aStartParams.front()->value();
+  myDelta[1] = aEndParams.back()->value() - aStartParams.back()->value();
+
+  if (myIsFullValue && myNumberOfCopies > 0) {
+    myDelta[0] /= myNumberOfCopies;
+    myDelta[1] /= myNumberOfCopies;
+  }
+
+  SketchSolver_ConstraintMulti::adjustConstraint();
+}
+
+void SketchSolver_ConstraintMultiTranslation::getRelative(
+    double theAbsX, double theAbsY, double& theRelX, double& theRelY)
+{
+  theRelX = theAbsX;
+  theRelY = theAbsY;
+}
+
+void SketchSolver_ConstraintMultiTranslation::getAbsolute(
+    double theRelX, double theRelY, double& theAbsX, double& theAbsY)
+{
+  theAbsX = theRelX;
+  theAbsY = theRelY;
+}
+
+void SketchSolver_ConstraintMultiTranslation::transformRelative(double& theX, double& theY)
+{
+  // translate coordinates
+  theX += myDelta[0];
+  theY += myDelta[1];
+}
+