]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Updating of constraint presentations while feature edit, and error handling
authorazv <azv@opencascade.com>
Wed, 25 Jun 2014 11:39:02 +0000 (15:39 +0400)
committerazv <azv@opencascade.com>
Wed, 25 Jun 2014 11:39:02 +0000 (15:39 +0400)
src/SketchSolver/SketchSolver_ConstraintGroup.cpp
src/SketchSolver/SketchSolver_ConstraintGroup.h
src/SketchSolver/SketchSolver_ConstraintManager.cpp

index 5aa275391c5ff3366deca2f4d8dcd81c3e982bd0..0676bd58c6faf2a0b30803007f2cc0da08121245 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <SketchSolver_Constraint.h>
 
+#include <Events_Error.h>
 #include <Events_Loop.h>
 #include <GeomDataAPI_Dir.h>
 #include <GeomDataAPI_Point.h>
@@ -30,6 +31,8 @@
 /// Tolerance for value of parameters
 const double tolerance = 1.e-10;
 
+const std::string ERROR_SOLVE_CONSTRAINTS = "Conflicting constraints";
+
 /// This value is used to give unique index to the groups
 static Slvs_hGroup myGroupIndexer = 0;
 
@@ -559,7 +562,8 @@ void SketchSolver_ConstraintGroup::resolveConstraints()
     for ( ; anEntIter != myEntityAttrMap.end(); anEntIter++)
       updateAttribute(anEntIter->first, anEntIter->second);
   }
-  /// \todo Implement error handling
+  else if (!myConstraints.empty())
+    Events_Error::send(ERROR_SOLVE_CONSTRAINTS, this);
 
   removeTemporaryConstraints();
   myNeedToSolve = false;
@@ -855,6 +859,8 @@ void SketchSolver_ConstraintGroup::updateEntityIfPossible(
 
     // Restore flag of changes
     myNeedToSolve = myNeedToSolve || aNeedToSolveCopy;
+
+    updateRelatedConstraints(theEntity);
   }
 }
 
@@ -1090,6 +1096,61 @@ bool SketchSolver_ConstraintGroup::addCoincidentPoints(
 }
 
 
+// ============================================================================
+//  Function: updateRelatedConstraints
+//  Class:    SketchSolver_ConstraintGroup
+//  Purpose:  emit the signal to update constraints
+// ============================================================================
+void SketchSolver_ConstraintGroup::updateRelatedConstraints(
+                    boost::shared_ptr<ModelAPI_Attribute> theEntity) const
+{
+  std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::const_iterator
+    aConstrIter = myConstraintMap.begin();
+  for ( ; aConstrIter != myConstraintMap.end(); aConstrIter++)
+  {
+    std::list< boost::shared_ptr<ModelAPI_Attribute> > anAttributes = 
+      aConstrIter->first->data()->attributes(theEntity->attributeType());
+
+    std::list< boost::shared_ptr<ModelAPI_Attribute> >::iterator
+      anAttrIter = anAttributes.begin();
+    for ( ; anAttrIter != anAttributes.end(); anAttrIter++)
+      if (*anAttrIter == theEntity)
+      {
+        static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+        Model_FeatureUpdatedMessage aMsg(aConstrIter->first, anEvent);
+        Events_Loop::loop()->send(aMsg, true);
+        break;
+      }
+  }
+}
+
+void SketchSolver_ConstraintGroup::updateRelatedConstraints(
+                    boost::shared_ptr<ModelAPI_Feature> theFeature) const
+{
+  std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::const_iterator
+    aConstrIter = myConstraintMap.begin();
+  for ( ; aConstrIter != myConstraintMap.end(); aConstrIter++)
+  {
+    std::list< boost::shared_ptr<ModelAPI_Attribute> > anAttributes = 
+      aConstrIter->first->data()->attributes(std::string());
+
+    std::list< boost::shared_ptr<ModelAPI_Attribute> >::iterator
+      anAttrIter = anAttributes.begin();
+    for ( ; anAttrIter != anAttributes.end(); anAttrIter++)
+    {
+      boost::shared_ptr<ModelAPI_AttributeRefAttr> aRefAttr = 
+        boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
+      if (aRefAttr && aRefAttr->isFeature() && aRefAttr->feature() == theFeature)
+      {
+        static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+        Model_FeatureUpdatedMessage aMsg(aConstrIter->first, anEvent);
+        Events_Loop::loop()->send(aMsg, true);
+        break;
+      }
+    }
+  }
+}
+
 
 
 // ========================================================
index 69c1a7c04584e6894796a4ab1fcc4f85a1da8e8b..36d3d12ed692346cc5a4aa2a6e7f39b4a4eb5671 100644 (file)
@@ -94,6 +94,12 @@ public:
    */
   void resolveConstraints();
 
+  /** \brief Searches the constraints built on the entity and emit the signal to update them
+   *  \param[in] theEntity attribute of the constraint
+   */
+  void updateRelatedConstraints(boost::shared_ptr<ModelAPI_Attribute> theEntity)  const;
+  void updateRelatedConstraints(boost::shared_ptr<ModelAPI_Feature>   theFeature) const;
+
 protected:
   /** \brief Adds or updates an entity in the group
    *
index e91d65a16bc5491c0473d65a62b2f1fcc3283b15..0e39b5a42331166176c3a2184c9c99c2b9d4068e 100644 (file)
@@ -293,6 +293,11 @@ void SketchSolver_ConstraintManager::updateEntity(boost::shared_ptr<SketchPlugin
       (*aGroupIter)->updateEntityIfPossible(anAttribute);
     }
   }
+
+  std::vector<SketchSolver_ConstraintGroup*>::iterator aGroupIter;
+  for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++)
+    if (!(*aGroupIter)->isEmpty())
+      (*aGroupIter)->updateRelatedConstraints(theFeature);
 }