]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/SketchSolver/SketchSolver_ConstraintLength.cpp
Salome HOME
Revert "First phase of SketchSolver refactoring"
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintLength.cpp
index 5c3bbc088637187d5ee63c0cd3d746e27c89196f..06d854d175ba7a4724bf8ef920249746be45ceea 100644 (file)
@@ -1,26 +1,44 @@
 #include <SketchSolver_ConstraintLength.h>
+#include <SketchSolver_Group.h>
 #include <SketchSolver_Error.h>
 
 
-void SketchSolver_ConstraintLength::getAttributes(
-    double& theValue,
-    std::vector<EntityWrapperPtr>& theAttributes)
+void SketchSolver_ConstraintLength::process()
 {
-  SketchSolver_Constraint::getAttributes(theValue, theAttributes);
-  if (!myErrorMsg.empty() || !theAttributes[2] || 
-      theAttributes[2]->type() != ENTITY_LINE) {
-    theAttributes.clear();
+  cleanErrorMsg();
+  if (!myBaseConstraint || !myStorage || myGroup == 0) {
+    /// TODO: Put error message here
     return;
   }
+  if (!mySlvsConstraints.empty()) // some data is changed, update constraint
+    update(myBaseConstraint);
 
-  // Get boundary points of line segment and create point-point distance constraint
-  std::list<EntityWrapperPtr> aSubs = theAttributes[2]->subEntities();
-  theAttributes.assign(theAttributes.size(), EntityWrapperPtr());
-  std::vector<EntityWrapperPtr>::iterator anAttrIt = theAttributes.begin();
-  std::list<EntityWrapperPtr>::const_iterator aSubIt = aSubs.begin();
-  for (; aSubIt != aSubs.end(); ++aSubIt, ++anAttrIt)
-    *anAttrIt = *aSubIt;
+  double aValue;
+  std::vector<Slvs_hEntity> anEntities;
+  getAttributes(aValue, anEntities);
+  if (!myErrorMsg.empty())
+    return;
+
+  // 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;
+  }
 
-  myType = CONSTRAINT_PT_PT_DISTANCE;
+  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();
+}
+
+void SketchSolver_ConstraintLength::adjustConstraint()
+{
+  // No need to store the line, which length is constrained
+  // Upd: The line need to be stored to check that constraint
+  //      is changed/unchanged during modifications in GUI
+  //myFeatureMap.clear();
 }