Salome HOME
Pipe validator fix
[modules/shaper.git] / src / SketchSolver / SketchSolver_Constraint.cpp
index ef10bf57ebb2d0486037b89c2badc09ff86521d0..fcb2a1fc138371fb94e349c6886f9cd1b60249a1 100644 (file)
 
 #include <SketchPlugin_ConstraintAngle.h>
 #include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintCollinear.h>
 #include <SketchPlugin_ConstraintDistance.h>
 #include <SketchPlugin_ConstraintEqual.h>
 #include <SketchPlugin_ConstraintHorizontal.h>
 #include <SketchPlugin_ConstraintLength.h>
+#include <SketchPlugin_ConstraintMiddle.h>
 #include <SketchPlugin_ConstraintMirror.h>
 #include <SketchPlugin_ConstraintParallel.h>
 #include <SketchPlugin_ConstraintPerpendicular.h>
@@ -79,6 +81,10 @@ SketchSolver_ConstraintType SketchSolver_Constraint::TYPE(ConstraintPtr theConst
     return CONSTRAINT_RADIUS;
   else if (aType == SketchPlugin_ConstraintTangent::ID())
     return CONSTRAINT_TANGENT;
+  else if (aType == SketchPlugin_ConstraintCollinear::ID())
+    return CONSTRAINT_COLLINEAR;
+  else if (aType == SketchPlugin_ConstraintMiddle::ID())
+    return CONSTRAINT_MIDDLE_POINT;
   return CONSTRAINT_UNKNOWN;
 }
 
@@ -133,7 +139,13 @@ void SketchSolver_Constraint::update()
     if (aRefAttr) {
       if (aRefAttr->isObject()) {
         FeaturePtr aFeat = ModelAPI_Feature::feature(aRefAttr->object());
-        aFeatures.insert(aFeat);
+        if (myBaseConstraint->getKind() != SketchPlugin_ConstraintLength::ID())
+          aFeatures.insert(aFeat);
+        else {
+          // Workaround for the Length constraint: add points of line, not line itself
+          anAttributes.insert(aFeat->attribute(SketchPlugin_Line::START_ID()));
+          anAttributes.insert(aFeat->attribute(SketchPlugin_Line::END_ID()));
+        }
       } else
         anAttributes.insert(aRefAttr->attr());
     } else
@@ -179,6 +191,7 @@ void SketchSolver_Constraint::update()
 bool SketchSolver_Constraint::remove()
 {
   cleanErrorMsg();
+  myType = CONSTRAINT_UNKNOWN;
   return myStorage->removeConstraint(myBaseConstraint);
 }
 
@@ -188,6 +201,7 @@ void SketchSolver_Constraint::getAttributes(
 {
   static const int anInitNbOfAttr = 4;
   theAttributes.assign(anInitNbOfAttr, EntityWrapperPtr());
+  myAttributes.clear();
 
   DataPtr aData = myBaseConstraint->data();
   BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
@@ -212,6 +226,7 @@ void SketchSolver_Constraint::getAttributes(
 
     myStorage->update(*anIter/*, myGroupID*/);
     EntityWrapperPtr anEntity = myStorage->entity(*anIter);
+    myAttributes.push_back(anEntity);
 
     SketchSolver_EntityType aType = anEntity->type();
     if (aType == ENTITY_UNKNOWN)