]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/SketchSolver/SketchSolver_ConstraintManager.cpp
Salome HOME
Add tools
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintManager.cpp
index ef725b5633fe6ddc5eb464c7313c3b84b018b737..682bbf23a48fdb89cbf4602e7e62115e9c5b045d 100644 (file)
 #include <ModelAPI_Attribute.h>
 
 #include <SketchPlugin_Constraint.h>
-#include <SketchPlugin_ConstraintCoincidence.h>
-#include <SketchPlugin_ConstraintFillet.h>
-#include <SketchPlugin_ConstraintMirror.h>
-#include <SketchPlugin_ConstraintTangent.h>
 
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_Circle.h>
@@ -38,6 +34,7 @@ SketchSolver_ConstraintManager* SketchSolver_ConstraintManager::_self = 0;
 /// Global constraint manager object
 SketchSolver_ConstraintManager* myManager = SketchSolver_ConstraintManager::Instance();
 
+
 // ========================================================
 // ========= SketchSolver_ConstraintManager ===============
 // ========================================================
@@ -86,7 +83,7 @@ void SketchSolver_ConstraintManager::processEvent(
     bool hasProperFeature = false;
 
     bool isMovedEvt = theMessage->eventID()
-        == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED);
+          == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED);
     if (isMovedEvt) {
       std::set<ObjectPtr>::iterator aFeatIter;
       for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) {
@@ -98,38 +95,17 @@ void SketchSolver_ConstraintManager::processEvent(
         }
       }
     } else {
-      std::set<ObjectPtr>::iterator aFeatIter;
-      // iterate sketchers fisrt to create all sketches before (on load may exist several sketches)
-      for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) {
-        FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*aFeatIter);
-        if (!aFeature)
-          continue;
-        const std::string& aFeatureKind = aFeature->getKind();
-        if (aFeatureKind.compare(SketchPlugin_Sketch::ID()) == 0) {
-          std::shared_ptr<ModelAPI_CompositeFeature> aSketch = std::dynamic_pointer_cast<
-              ModelAPI_CompositeFeature>(aFeature);
+      std::list<FeaturePtr> aSketchFeatures = SketchSolver_Group::selectApplicableFeatures(aFeatures);
+      std::list<FeaturePtr>::iterator aFeatIter = aSketchFeatures.begin();
+      for (; aFeatIter != aSketchFeatures.end(); ++aFeatIter) {
+        if ((*aFeatIter)->getKind() == SketchPlugin_Sketch::ID()) {
+          std::shared_ptr<ModelAPI_CompositeFeature> aSketch = 
+              std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aFeatIter);
           hasProperFeature = changeWorkplane(aSketch) || hasProperFeature;
-        }
-      }
-      // then get anything but not the sketch
-      std::set<ObjectPtr> aComplexConstraints;
-      // fillet and mirror an tangency constraints will be processed later
-      for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) {
-        std::shared_ptr<SketchPlugin_Feature> aFeature = 
-          std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
-        if (!aFeature)
-          continue;
-        if (SketchSolver_Group::isComplexConstraint(aFeature)) {
-          aComplexConstraints.insert(aFeature);
           continue;
         }
-        hasProperFeature = changeConstraintOrEntity(aFeature) || hasProperFeature;
-      }
-      // processing remain constraints
-      aFeatIter = aComplexConstraints.begin();
-      for (; aFeatIter != aComplexConstraints.end(); aFeatIter++) {
         std::shared_ptr<SketchPlugin_Feature> aFeature = 
-          std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
+            std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
         if (!aFeature)
           continue;
         hasProperFeature = changeConstraintOrEntity(aFeature) || hasProperFeature;
@@ -141,14 +117,14 @@ void SketchSolver_ConstraintManager::processEvent(
       resolveConstraints(isMovedEvt); // send update for movement in any case
   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
     std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDeleteMsg =
-        std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
+      std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
     const std::set<std::string>& aFeatureGroups = aDeleteMsg->groups();
 
     // Find SketchPlugin_Sketch::ID() in groups. The constraint groups should be updated when an object removed from Sketch
     std::set<std::string>::const_iterator aFGrIter;
     for (aFGrIter = aFeatureGroups.begin(); aFGrIter != aFeatureGroups.end(); aFGrIter++)
       if (aFGrIter->compare(ModelAPI_ResultConstruction::group()) == 0 ||
-          aFGrIter->compare(ModelAPI_Feature::group()) == 0)
+        aFGrIter->compare(ModelAPI_Feature::group()) == 0)
         break;
 
     if (aFGrIter != aFeatureGroups.end()) {
@@ -388,3 +364,4 @@ void SketchSolver_ConstraintManager::resolveConstraints(const bool theForceUpdat
   if (needToUpdate || theForceUpdate)
     Events_Loop::loop()->flush(anUpdateEvent);
 }
+