]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Improve movement of single point of a constrained feature.
authorazv <azv@opencascade.com>
Tue, 21 Mar 2017 07:02:28 +0000 (10:02 +0300)
committerazv <azv@opencascade.com>
Tue, 21 Mar 2017 07:02:28 +0000 (10:02 +0300)
This change caused by incorrect "conflicting constraints" message while moving the feature under Horizontal constraint. The problem is the fixing of the whole feature even in case of single point is moved. There has been implemented searching of the changed attribute and fixing it only.

src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_PointWrapper.h
src/SketchSolver/SketchSolver_ConstraintFixed.cpp

index 4e536d7a0f55c9c03142f0fa525d612e89a3a07e..8acd7df4b54a657828b6b94a489e3ffd42d3f295 100644 (file)
@@ -33,4 +33,6 @@ private:
   GCSPointPtr myPoint;
 };
 
+typedef std::shared_ptr<PlaneGCSSolver_PointWrapper> PointWrapperPtr;
+
 #endif
index 68200eb2e0d11eb8c13fda82118b5800486ad844..41ba5d46b5622a7abd141024db70631cb9d23c60 100644 (file)
@@ -7,17 +7,19 @@
 #include <PlaneGCSSolver_EdgeWrapper.h>
 #include <PlaneGCSSolver_PointWrapper.h>
 
+#include <GeomDataAPI_Point2D.h>
+
+#include <cmath>
+
+// Find parameters of the feature that have been updated during the movement
+static EntityWrapperPtr getChangedEntity(const FeaturePtr& theFeature,
+                                         const StoragePtr& theStorage);
+
 
 SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(ConstraintPtr theConstraint)
   : SketchSolver_Constraint(theConstraint)
 {
   myType = CONSTRAINT_FIXED;
-////  AttributeRefAttrPtr anAttribute =
-////      theConstraint->refattr(SketchPlugin_ConstraintRigid::ENTITY_A());
-////  if (anAttribute->isObject())
-////    myFixedFeature = ModelAPI_Feature::feature(anAttribute->object());
-////  else
-////    myFixedAttribute = anAttribute->attr();
 }
 
 SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(FeaturePtr theFeature)
@@ -25,7 +27,6 @@ SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(FeaturePtr theFeature
     myBaseFeature(theFeature)
 {
   myType = CONSTRAINT_FIXED;
-////  process();
 }
 
 void SketchSolver_ConstraintFixed::blockEvents(bool isBlocked)
@@ -125,8 +126,8 @@ void SketchSolver_ConstraintFixed::getAttributes(
 {
   if (myBaseFeature) {
     // The feature is fixed.
+    EntityWrapperPtr aSolverEntity = getChangedEntity(myBaseFeature, myStorage);
     myStorage->update(myBaseFeature);
-    EntityWrapperPtr aSolverEntity = myStorage->entity(myBaseFeature);
     if (aSolverEntity)
       theAttributes.push_back(aSolverEntity);
   } else if (myBaseConstraint) {
@@ -141,3 +142,40 @@ void SketchSolver_ConstraintFixed::getAttributes(
   } else
     myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
 }
+
+
+
+
+// ====================   Auxiliary functions   ===============================
+static bool isSameCoordinates(const AttributePoint2DPtr& thePointAttr,
+                              const PointWrapperPtr& thePointWrapper)
+{
+  GCSPointPtr aGCSPoint = thePointWrapper->point();
+  return fabs(*aGCSPoint->x - thePointAttr->x()) < tolerance &&
+         fabs(*aGCSPoint->y - thePointAttr->y()) < tolerance;
+}
+
+EntityWrapperPtr getChangedEntity(const FeaturePtr& theFeature,
+                                  const StoragePtr& theStorage)
+{
+  std::list<AttributePtr> aPoints = theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+  std::list<EntityWrapperPtr> aChangedPoints;
+
+  std::list<AttributePtr>::const_iterator aPIt = aPoints.begin();
+  for (; aPIt != aPoints.end(); ++aPIt) {
+    AttributePoint2DPtr aPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*aPIt);
+    EntityWrapperPtr anEnt = theStorage->entity(*aPIt);
+    if (!anEnt)
+      continue;
+    PointWrapperPtr aPW = std::dynamic_pointer_cast<PlaneGCSSolver_PointWrapper>(anEnt);
+    if (!isSameCoordinates(aPnt, aPW))
+      aChangedPoints.push_back(anEnt);
+  }
+
+  EntityWrapperPtr aChanged;
+  if (aChangedPoints.size() == 1)
+    aChanged = aChangedPoints.front();
+  else if (!aChangedPoints.empty()) // update whole feature
+    aChanged = theStorage->entity(theFeature);
+  return aChanged;
+}