Salome HOME
Copyright update 2021
[modules/shaper.git] / src / PartSet / PartSet_OverconstraintListener.cpp
index a0eff2c34b011e8f26821d22bb0df2b9553379b9..656593d9b5348f6c29fc554627f6d406c2002872 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2021  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
@@ -94,13 +94,11 @@ void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject,
     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)) {
@@ -113,8 +111,7 @@ 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)
 {
   // #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
@@ -149,13 +146,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) ||
@@ -202,7 +198,7 @@ void PartSet_OverconstraintListener::processEvent(
     // This Line's message should not be processed, as the reentrant operation is not for Line
     // It is not enoght of kind, the name should be used, e.g. restarted Lines on auxiliary
     // cirlce sometimes causes previous line change, kind the same, but feature line is different
-    std::string aCurrentFeatureName;
+    std::wstring aCurrentFeatureName;
     ModuleBase_Operation* anOperation =
                 XGUI_Tools::workshop(myWorkshop)->operationMgr()->currentOperation();
     if (anOperation) {
@@ -245,30 +241,32 @@ bool PartSet_OverconstraintListener::appendConflictingObjects(
   // set error state for new objects and append them in the internal map of objects
   std::set<ObjectPtr>::const_iterator
     anIt = theConflictingObjects.begin(), aLast = theConflictingObjects.end();
+  FeaturePtr aFeature;
+  bool isHVConstraint = false;
   for (; anIt != aLast; anIt++) {
     ObjectPtr anObject = *anIt;
     if (myConflictingObjects.find(anObject) == myConflictingObjects.end()) { // it is not found
       aModifiedObjects.insert(anObject);
       myConflictingObjects.insert(anObject);
     }
+    if (!isHVConstraint) {
+      aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
+      if (aFeature) {
+        std::string aType = aFeature->getKind();
+        isHVConstraint = (aType == SketchPlugin_ConstraintHorizontal::ID()) ||
+          (aType == SketchPlugin_ConstraintVertical::ID());
+      }
+    }
   }
   bool isUpdated = !aModifiedObjects.empty();
   if (isUpdated)
     redisplayObjects(aModifiedObjects);
 
-  if (myConflictingObjects.size() == 1) {
-    // If the conflicting object is an automatic constraint caused the conflict
-    // then it has to be deleted
-    ObjectPtr aObj = *theConflictingObjects.cbegin();
-    FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
-    if (aFeature) {
-      std::string aType = aFeature->getKind();
-      if ((aType == SketchPlugin_ConstraintHorizontal::ID()) ||
-        (aType == SketchPlugin_ConstraintVertical::ID())) {
-        PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
-        QTimer::singleShot(5, aModule, SLOT(onConflictingConstraints()));
-      }
-    }
+  // If the conflicting object is an automatic constraint caused the conflict
+  // then it has to be deleted
+  if (isHVConstraint) {
+    PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+    QTimer::singleShot(5, aModule, SLOT(onConflictingConstraints()));
   }
 
   return isUpdated;
@@ -301,13 +299,17 @@ void PartSet_OverconstraintListener::redisplayObjects(
   static Events_Loop* aLoop = Events_Loop::loop();
 
   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