Salome HOME
Issue #2029: Change the color of the Sketch when fully constrained.
authornds <nds@opencascade.com>
Mon, 3 Apr 2017 12:04:31 +0000 (15:04 +0300)
committernds <nds@opencascade.com>
Mon, 3 Apr 2017 12:04:53 +0000 (15:04 +0300)
Case: create two sketches, 2nd is fully defined, Edit 1st sketch. Result was that it was in green.

src/PartSet/PartSet_OverconstraintListener.cpp
src/PartSet/PartSet_OverconstraintListener.h
src/PartSet/PartSet_SketcherMgr.cpp
src/SketchSolver/SketchSolver_Group.cpp

index 768dff3c75c28107d59f18bc9839098e5d5878fe..1eff378359d69529ff52eba32e640742b7a9a680 100755 (executable)
@@ -5,6 +5,7 @@
 // Author:      Vitaly SMETANNIKOV
 
 #include <ModelAPI_Tools.h>
+#include <ModelAPI_AttributeString.h>
 
 #include "PartSet_OverconstraintListener.h"
 #include <PartSet_Module.h>
@@ -19,6 +20,7 @@
 #include "SketcherPrs_SymbolPrs.h"
 #include "SketchPlugin_SketchEntity.h"
 #include "SketchPlugin_MacroArcReentrantMessage.h"
+#include "SketchPlugin_Sketch.h"
 
 #include "Events_Loop.h"
 
@@ -32,7 +34,7 @@
 //#define DEBUG_FEATURE_OVERCONSTRAINT_LISTENER
 
 PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorkshop* theWorkshop)
-: myWorkshop(theWorkshop), myIsFullyConstrained(false)
+: myWorkshop(theWorkshop), myIsActive(false), myIsFullyConstrained(false)
 {
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_FAILED));
@@ -45,9 +47,30 @@ PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorks
   aLoop->registerListener(this, SketchPlugin_MacroArcReentrantMessage::eventId());
 }
 
+void PartSet_OverconstraintListener::setActive(const bool& theActive)
+{
+  if (myIsActive == theActive)
+    return;
+
+  myIsActive = theActive;
+  myIsFullyConstrained = false; /// returned to default state, no custom color for it
+
+  if (myIsActive) {
+    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");
+    }
+  }
+}
+
 void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject,
                                                     std::vector<int>& theColor)
 {
+  if (!myIsActive)
+    return;
+
   if (myConflictingObjects.find(theObject) != myConflictingObjects.end()) {
     theColor = Config_PropManager::color("Visualization", "sketch_overconstraint_color");
   }
@@ -55,10 +78,10 @@ void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject,
     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_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
-      CompositeFeaturePtr aCompositeFeature = aModule->sketchMgr()->activeSketch();
+      PartSet_Module* aModule = module();
+      CompositeFeaturePtr aSketch = aModule->sketchMgr()->activeSketch();
       // the given object is sub feature of the current sketch(created or edited)
-      if (ModelAPI_Tools::compositeOwner(aFeature) == aCompositeFeature)
+      if (ModelAPI_Tools::compositeOwner(aFeature) == aSketch)
         theColor = Config_PropManager::color("Visualization", "sketch_fully_constrained_color");
     }
   }
@@ -67,6 +90,9 @@ void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject,
 void PartSet_OverconstraintListener::processEvent(
                                                  const std::shared_ptr<Events_Message>& theMessage)
 {
+  if (!myIsActive)
+    return;
+
 #ifdef DEBUG_FEATURE_OVERCONSTRAINT_LISTENER
   bool isRepaired = theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_REPAIRED);
   int aCount = 0;
@@ -199,10 +225,9 @@ void PartSet_OverconstraintListener::redisplayObjects(
   aLoop->flush(EVENT_DISP);
 }
 
-XGUI_Workshop* PartSet_OverconstraintListener::workshop() const
+PartSet_Module* PartSet_OverconstraintListener::module() const
 {
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
-  return aConnector->workshop();
+  return dynamic_cast<PartSet_Module*>(myWorkshop->module());
 }
 
 #ifdef _DEBUG
index 9ce9a4e4cce7d9c9b85bba51cf1d23df497ba0af..0721d41d76017b918eef52f1502a43e472a314d2 100755 (executable)
@@ -12,7 +12,7 @@
 #include <ModelAPI_Object.h>
 
 class ModuleBase_IWorkshop;
-class XGUI_Workshop;
+class PartSet_Module;
 
 #include <QString>
 
@@ -33,10 +33,9 @@ public:
 
   virtual ~PartSet_OverconstraintListener() {};
 
-  // Set erroneous color for the presentation of object if the object is in the conflicting list
-  // \param theObject an object to be settled
-  // \param theUpdateViewer a boolean state whether the current viewer should be updated
-  //bool customizeObject(ObjectPtr theObject, const bool theUpdateViewer);
+  /// If active state is changed, update fully defined state and sketch sub-entities color
+  /// \param theActive a state
+  void setActive(const bool& theActive);
 
   /// Returns true if the object belongs to internal container of conflicting objects
   /// \param theObject an object to be checked
@@ -63,8 +62,8 @@ protected:
   void redisplayObjects(const std::set<ObjectPtr>& theObjects);
 
 private:
-  /// Returns workshop
-  XGUI_Workshop* workshop() const;
+  /// Returns module
+  PartSet_Module* module() const;
 
 #ifdef _DEBUG
   /// Unite objects in one string information
@@ -74,8 +73,9 @@ private:
 #endif
 
 private:
-  std::set<ObjectPtr> myConflictingObjects;
   ModuleBase_IWorkshop* myWorkshop;
+  bool myIsActive; /// state if sketch is active
+  std::set<ObjectPtr> myConflictingObjects;
   bool myIsFullyConstrained; /// state if Solver is fully constrained, DOF = 0
 };
 
index 05378d4a504c8e6f860c4cc32f28ce9946f50e1f..a63586cef8adb0c093ee969f3730e483d029477f 100755 (executable)
@@ -905,6 +905,9 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
     }
   }
 
+  // update state of overconstraint listener should be done before sketch features/results
+  // display (as the display will ask custom color from the listener)
+  myModule->overconstraintListener()->setActive(true);
   // Display sketcher objects
   QStringList anInfo;
   Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
@@ -1018,6 +1021,7 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
 
     Events_Loop::loop()->flush(aDispEvent);
   }
+  myModule->overconstraintListener()->setActive(false);
   // restore the module selection modes, which were changed on startSketch
   aConnector->activateModuleSelectionModes();
 }
index fb82f2cdefeebb980f2a0bdae23daa9dfaff3cec..05840ba95c936f7a36845a5761526b585d8523a2 100644 (file)
@@ -250,6 +250,8 @@ void SketchSolver_Group::computeDoF()
 {
   std::ostringstream aDoFMsg;
   int aDoF = mySketchSolver->dof();
+  /// "DoF = 0" content of string value is used in PartSet by Sketch edit
+  /// If it is changed, it should be corrected also there
   if (aDoF == 0)
     aDoFMsg << "Sketch is fully fixed (DoF = 0)";
   else