]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp
Salome HOME
Prepare version 1.2.1: quick fix for iteration 2 release
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMultiTranslation.cpp
index e304a7e04f1fd0194c07d2bbcd5788bd51246326..a90354a84a5ef072c0cff929c0c918f1d92371cd 100644 (file)
@@ -6,9 +6,11 @@
 #include <SketchPlugin_MultiTranslation.h>
 
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_Data.h>
 
 #include <GeomAPI_Dir2d.h>
 #include <GeomAPI_XY.h>
@@ -44,8 +46,7 @@ void SketchSolver_ConstraintMultiTranslation::getAttributes(
   AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
       aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
   myNumberOfObjects = anInitialRefList->size();
-  myNumberOfCopies = (size_t)std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
-      aData->attribute(SketchPlugin_MultiTranslation::NUMBER_OF_COPIES_ID()))->value();
+  myNumberOfCopies = (size_t) aData->integer(SketchPlugin_MultiTranslation::NUMBER_OF_COPIES_ID())->value();
   AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
       myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
   if (!aRefList) {
@@ -163,17 +164,6 @@ void SketchSolver_ConstraintMultiTranslation::process()
     }
   }
 
-  // Set the translation line unchanged during constraint recalculation
-  for (int i = 0; i < 2; i++) {
-    if (myStorage->isPointFixed(aTranslationLine.point[i], aConstraint.h, true))
-      continue;
-    aConstraint = Slvs_MakeConstraint(
-        SLVS_E_UNKNOWN, myGroup->getId(), SLVS_C_WHERE_DRAGGED, myGroup->getWorkplaneId(), 0.0,
-        aTranslationLine.point[i], SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
-    aConstraint.h = myStorage->addConstraint(aConstraint);
-    mySlvsConstraints.push_back(aConstraint.h);
-  }
-
   adjustConstraint();
 }
 
@@ -183,7 +173,9 @@ void SketchSolver_ConstraintMultiTranslation::update(ConstraintPtr theConstraint
   if (!theConstraint || theConstraint == myBaseConstraint) {
     AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
         myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
-    if (anInitialRefList->size() != myNumberOfObjects) {
+    AttributeIntegerPtr aNbCopies = myBaseConstraint->integer(SketchPlugin_MultiTranslation::NUMBER_OF_COPIES_ID());
+    if (anInitialRefList->size() != myNumberOfObjects ||
+        (size_t)aNbCopies->value() != myNumberOfCopies) {
       remove(myBaseConstraint);
       process();
       return;
@@ -219,6 +211,18 @@ bool SketchSolver_ConstraintMultiTranslation::remove(ConstraintPtr theConstraint
 void SketchSolver_ConstraintMultiTranslation::adjustConstraint()
 {
   Slvs_Entity aTranslationLine = myStorage->getEntity(myTranslationLine);
+  Slvs_hConstraint aFixed; // temporary variable
+  // Set the translation line unchanged during constraint recalculation
+  for (int i = 0; i < 2; i++) {
+    if (myStorage->isPointFixed(aTranslationLine.point[i], aFixed, true))
+      continue;
+    Slvs_Constraint aConstraint = Slvs_MakeConstraint(
+        SLVS_E_UNKNOWN, myGroup->getId(), SLVS_C_WHERE_DRAGGED, myGroup->getWorkplaneId(), 0.0,
+        aTranslationLine.point[i], SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
+    aConstraint.h = myStorage->addConstraint(aConstraint);
+    myStorage->addTemporaryConstraint(aConstraint.h);
+  }
+
   // Check if the distance between point is 0, no need to resolve constraints (just wait another values)
   double aXY[4];
   for (int i = 0; i < 2; i++) {
@@ -236,7 +240,6 @@ void SketchSolver_ConstraintMultiTranslation::adjustConstraint()
   std::list<Slvs_Constraint> aParallel = myStorage->getConstraintsByType(SLVS_C_PARALLEL);
   std::list<Slvs_Constraint>::iterator aParIt = aParallel.begin();
   std::vector<Slvs_hConstraint>::iterator aCIt;
-  Slvs_hConstraint aFixed; // temporary variable
   for (; aParIt != aParallel.end(); aParIt++) {
     for (aCIt = mySlvsConstraints.begin(); aCIt != mySlvsConstraints.end(); aCIt++)
       if (aParIt->h == *aCIt)