Salome HOME
Get rid of compilation warnings. Part III. Eliminate rest of warnings.
[modules/shaper.git] / src / PartSet / PartSet_OverconstraintListener.cpp
old mode 100755 (executable)
new mode 100644 (file)
index fc40857..2dd82db
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2020  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
@@ -12,9 +12,9 @@
 //
 // 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
+// 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>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include <ModelAPI_Tools.h>
@@ -25,7 +25,6 @@
 #include <PartSet_SketcherMgr.h>
 #include <PartSet_SketcherReentrantMgr.h>
 
-#include "XGUI_CustomPrs.h"
 #include "XGUI_Displayer.h"
 #include "XGUI_ModuleConnector.h"
 #include "XGUI_OperationMgr.h"
@@ -74,8 +73,13 @@ void PartSet_OverconstraintListener::setActive(const bool& theActive)
     PartSet_Module* aModule = module();
     CompositeFeaturePtr aSketch = aModule->sketchMgr()->activeSketch();
     if (aSketch.get()) {
-      std::string aDOFMessage = aSketch->string(SketchPlugin_Sketch::SOLVER_DOF())->value();
-      myIsFullyConstrained = QString(aDOFMessage.c_str()).contains("DoF = 0");
+      QString aDOFMessage(aSketch->string(SketchPlugin_Sketch::SOLVER_DOF())->value().c_str());
+      if (aDOFMessage.contains('=')) {
+        // to support old data
+        aDOFMessage =
+          aDOFMessage.right(aDOFMessage.length() - aDOFMessage.lastIndexOf('=')).trimmed();
+      }
+      myIsFullyConstrained = (aDOFMessage == "0");
     }
   }
 }
@@ -86,11 +90,13 @@ void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject,
   if (!myIsActive)
     return;
 
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+  std::string aFeatureName = aFeature->data()->name();
+
   if (myConflictingObjects.find(theObject) != myConflictingObjects.end()) {
     theColor = Config_PropManager::color("Visualization", "sketch_overconstraint_color");
   }
   if (myIsFullyConstrained) {
-    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
     // only entity features has custom color when sketch is fully constrained
     if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind()) &&
         !PartSet_SketcherMgr::isExternalFeature(aFeature)) {
@@ -103,11 +109,13 @@ void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject,
   }
 }
 
-void PartSet_OverconstraintListener::processEvent(
-                                                 const std::shared_ptr<Events_Message>& theMessage)
+void PartSet_OverconstraintListener::processEvent(const std::shared_ptr<Events_Message>& theMessage)
 {
-  if (!myIsActive)
-    return;
+  // #2271 open document: if sketch has confilcting elements, solver sends message with the
+  // elements by opening the document. Sketch is not active, but an internal container should
+  // be updated. So, we should not check whether the listener is active here
+  //if (!myIsActive)
+  //  return;
 
 #ifdef DEBUG_FEATURE_OVERCONSTRAINT_LISTENER
   bool isRepaired = theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_REPAIRED);
@@ -136,13 +144,12 @@ void PartSet_OverconstraintListener::processEvent(
       anEventID == Events_Loop::eventByName(EVENT_SOLVER_REPAIRED)) {
     std::shared_ptr<ModelAPI_SolverFailedMessage> anErrorMsg =
                    std::dynamic_pointer_cast<ModelAPI_SolverFailedMessage>(theMessage);
-    bool anUpdated = false;
     if (anErrorMsg.get()) {
       const std::set<ObjectPtr>& aConflictingObjects = anErrorMsg->objects();
       if (anEventID == Events_Loop::eventByName(EVENT_SOLVER_FAILED))
-        anUpdated = appendConflictingObjects(aConflictingObjects);
+        appendConflictingObjects(aConflictingObjects);
       else
-        anUpdated = repairConflictingObjects(aConflictingObjects);
+        repairConflictingObjects(aConflictingObjects);
     }
   }
   else if (anEventID == Events_Loop::eventByName(EVENT_SKETCH_UNDER_CONSTRAINED) ||
@@ -154,8 +161,21 @@ void PartSet_OverconstraintListener::processEvent(
       std::set<ObjectPtr> aModifiedObjects;
       PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
       CompositeFeaturePtr aSketch = aModule->sketchMgr()->activeSketch();
+
+      // check the sketch in the message and the active sketch are the same
+      std::shared_ptr<ModelAPI_SolverFailedMessage> anErrorMsg =
+          std::dynamic_pointer_cast<ModelAPI_SolverFailedMessage>(theMessage);
+      if (aSketch && anErrorMsg && !anErrorMsg->objects().empty()) {
+        ObjectPtr anObject = *anErrorMsg->objects().begin();
+        CompositeFeaturePtr aSketchFromMsg =
+            std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(anObject);
+        if (!aSketchFromMsg || aSketchFromMsg != aSketch)
+          aSketch = CompositeFeaturePtr();
+      }
+
       if (aSketch.get()) {
-        for (int i = 0; i < aSketch->numberOfSubs(); i++) {
+        int aNumberOfSubs = aSketch->numberOfSubs();
+        for (int i = 0; i < aNumberOfSubs; i++) {
           FeaturePtr aFeature = aSketch->subFeature(i);
           aModifiedObjects.insert(aFeature); // is necessary to redisplay presentations
           std::list<ResultPtr> aResults = aFeature->results();
@@ -260,14 +280,18 @@ void PartSet_OverconstraintListener::redisplayObjects(
 {
   static Events_Loop* aLoop = Events_Loop::loop();
 
-  static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_VISUAL_ATTRIBUTES);
+  static Events_ID EVENT_REDISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
 
   std::set<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
-  for (; anIt != aLast; anIt++)
-    aECreator->sendUpdated(*anIt, EVENT_DISP);
-
+  for (; anIt != aLast; anIt++) {
+    ObjectPtr aObj = *anIt;
+    aECreator->sendUpdated(aObj, EVENT_DISP);
+    aECreator->sendUpdated(aObj, EVENT_REDISP);
+  }
   aLoop->flush(EVENT_DISP);
+  aLoop->flush(EVENT_REDISP);
 }
 
 PartSet_Module* PartSet_OverconstraintListener::module() const