Salome HOME
Issue #2148: Moving an arc displays a circle
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintLength.cpp
index 3d1d1bf22e6426e664c8a6d1b9256c0ebccbefeb..1a4be5072b2ef7059654f2a949fa04fbc31c847b 100644 (file)
@@ -1,36 +1,28 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 #include <SketchSolver_ConstraintLength.h>
-#include <SketchSolver_Group.h>
 #include <SketchSolver_Error.h>
 
+#include <SketchPlugin_Line.h>
+
 
-void SketchSolver_ConstraintLength::process()
+void SketchSolver_ConstraintLength::getAttributes(
+    EntityWrapperPtr& theValue,
+    std::vector<EntityWrapperPtr>& theAttributes)
 {
-  cleanErrorMsg();
-  if (!myBaseConstraint || !myStorage || myGroup == 0) {
-    /// TODO: Put error message here
+  SketchSolver_Constraint::getAttributes(theValue, theAttributes);
+  if (!myErrorMsg.empty() || !theAttributes[2] ||
+      theAttributes[2]->type() != ENTITY_LINE) {
+    theAttributes.clear();
     return;
   }
-  if (!mySlvsConstraints.empty()) // some data is changed, update constraint
-    update(myBaseConstraint);
 
-  double aValue;
-  std::vector<Slvs_hEntity> anEntities;
-  getAttributes(aValue, anEntities);
-  if (!myErrorMsg.empty())
-    return;
+  AttributeRefAttrPtr aRefAttr = myBaseConstraint->refattr(SketchPlugin_Constraint::ENTITY_A());
+  FeaturePtr aLine = ModelAPI_Feature::feature(aRefAttr->object());
 
-  // Check the entity is a line
-  Slvs_Entity aLine = myStorage->getEntity(anEntities[2]);
-  if (aLine.type != SLVS_E_LINE_SEGMENT){
-    myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
-    return;
-  }
+  theAttributes[0] = myStorage->entity(aLine->attribute(SketchPlugin_Line::START_ID()));
+  theAttributes[1] = myStorage->entity(aLine->attribute(SketchPlugin_Line::END_ID()));
 
-  Slvs_Constraint aConstraint = Slvs_MakeConstraint(SLVS_C_UNKNOWN, myGroup->getId(),
-      getType(), myGroup->getWorkplaneId(), aValue,
-      aLine.point[0], aLine.point[1], SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
-  aConstraint.h = myStorage->addConstraint(aConstraint);
-  mySlvsConstraints.push_back(aConstraint.h);
-  adjustConstraint();
+  myType = CONSTRAINT_PT_PT_DISTANCE;
 }