Salome HOME
Issue #2741: Undo of distance argument change produces crash
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintLength.cpp
index 714fe0cce0623eb8c117486c14cbed9269a09d76..4e423b2cd426bee427a8e790dc0f367edff799c9 100644 (file)
@@ -1,27 +1,45 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #include <SketchSolver_ConstraintLength.h>
 #include <SketchSolver_Error.h>
 
+#include <SketchPlugin_Line.h>
+
 
 void SketchSolver_ConstraintLength::getAttributes(
-    double& theValue,
+    EntityWrapperPtr& theValue,
     std::vector<EntityWrapperPtr>& theAttributes)
 {
   SketchSolver_Constraint::getAttributes(theValue, theAttributes);
-  if (!myErrorMsg.empty() || !theAttributes[2] || 
+  if (!myErrorMsg.empty() || !theAttributes[2] ||
       theAttributes[2]->type() != ENTITY_LINE) {
     theAttributes.clear();
     return;
   }
 
-  // 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;
+  AttributeRefAttrPtr aRefAttr = myBaseConstraint->refattr(SketchPlugin_Constraint::ENTITY_A());
+  FeaturePtr aLine = ModelAPI_Feature::feature(aRefAttr->object());
+
+  theAttributes[0] = myStorage->entity(aLine->attribute(SketchPlugin_Line::START_ID()));
+  theAttributes[1] = myStorage->entity(aLine->attribute(SketchPlugin_Line::END_ID()));
 
   myType = CONSTRAINT_PT_PT_DISTANCE;
 }