Salome HOME
Issue #2029 Change the color of the Sketch when fully constrained
authornds <nds@opencascade.com>
Wed, 29 Mar 2017 11:47:27 +0000 (14:47 +0300)
committernds <nds@opencascade.com>
Wed, 29 Mar 2017 11:47:46 +0000 (14:47 +0300)
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OverconstraintListener.cpp
src/PartSet/PartSet_OverconstraintListener.h
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_SketchEntity.h
src/SketcherPrs/SketcherPrs_Coincident.cpp
src/SketcherPrs/SketcherPrs_Coincident.h
src/SketcherPrs/SketcherPrs_SymbolPrs.cpp
src/SketcherPrs/SketcherPrs_SymbolPrs.h

index e7e7e8fa487f6dcbe35914be6d531f8baf0a6966..fb64f4a7fcd61e0012af83c3a617150591c6fa91 100755 (executable)
@@ -1015,7 +1015,8 @@ bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr the
     return aCustomized;
 
   if (!theResult.get()) {
-    bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
+    std::vector<int> aColor;
+    bool isConflicting = myOverconstraintListener->hasCustomColor(anObject, aColor);
     // customize sketch symbol presentation
     if (thePrs.get()) {
       Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
@@ -1023,17 +1024,13 @@ bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr the
         if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
           Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
           if (!aPrs.IsNull()) {
-            std::vector<int> aColor;
-            myOverconstraintListener->getConflictingColor(aColor);
-            aPrs->SetConflictingConstraint(isConflicting, aColor);
+            aPrs->SetCustomColor(aColor);
             aCustomized = true;
           }
         } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
           Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
           if (!aPrs.IsNull()) {
-            std::vector<int> aColor;
-            myOverconstraintListener->getConflictingColor(aColor);
-            aPrs->SetConflictingConstraint(isConflicting, aColor);
+            aPrs->SetCustomColor(aColor);
             aCustomized = true;
           }
         }
@@ -1041,11 +1038,7 @@ bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr the
     }
     // customize sketch dimension constraint presentation
     if (!aCustomized) {
-      std::vector<int> aColor;
-      if (isConflicting) {
-        myOverconstraintListener->getConflictingColor(aColor);
-      }
-      if (aColor.empty())
+      if (!isConflicting)
         XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
       if (!aColor.empty()) {
         aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
index 876130044b1ac805dc6fb840ecc6a2c4a46e42f1..fa20c54908f0f3bc9a5404fd4f5a52af9393662d 100755 (executable)
@@ -4,11 +4,16 @@
 // Created:     20 August 2015
 // Author:      Vitaly SMETANNIKOV
 
+#include <ModelAPI_Tools.h>
+
 #include "PartSet_OverconstraintListener.h"
+#include <PartSet_Module.h>
+#include <PartSet_SketcherMgr.h>
 
 #include "XGUI_ModuleConnector.h"
 #include "XGUI_Workshop.h"
 #include "XGUI_Displayer.h"
+#include "XGUI_CustomPrs.h"
 
 #include "SketcherPrs_SymbolPrs.h"
 #include "SketchPlugin_SketchEntity.h"
@@ -29,19 +34,39 @@ PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorks
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_FAILED));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_REPAIRED));
-}
 
-bool PartSet_OverconstraintListener::isConflictingObject(const ObjectPtr& theObject)
-{
-  return myConflictingObjects.find(theObject) != myConflictingObjects.end();
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_UNDER_CONSTRAINED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED));
 }
 
-void PartSet_OverconstraintListener::getConflictingColor(std::vector<int>& theColor)
+bool PartSet_OverconstraintListener::hasCustomColor(const ObjectPtr& theObject,
+                                                    std::vector<int>& theColor)
 {
-  Quantity_Color aColor = ModuleBase_Tools::color("Visualization", "sketch_overconstraint_color");
-  theColor.push_back(aColor.Red()*255.);
-  theColor.push_back(aColor.Green()*255.);
-  theColor.push_back(aColor.Blue()*255.);
+  if (myConflictingObjects.find(theObject) != myConflictingObjects.end()) {
+    Quantity_Color aColor = ModuleBase_Tools::color("Visualization",
+                                                    "sketch_overconstraint_color");
+    theColor.push_back(aColor.Red()*255.);
+    theColor.push_back(aColor.Green()*255.);
+    theColor.push_back(aColor.Blue()*255.);
+    return true;
+  }
+  if (myIsFullyConstrained) {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+    if (aFeature.get()) {
+      PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+      CompositeFeaturePtr aCompositeFeature = aModule->sketchMgr()->activeSketch();
+      // the given object is sub feature of the current sketch(created or edited)
+      if (ModelAPI_Tools::compositeOwner(aFeature) == aCompositeFeature) {
+        Quantity_Color aColor = ModuleBase_Tools::color("Visualization",
+                                                        "sketch_fully_constrained_color");
+        theColor.push_back(aColor.Red()*255.);
+        theColor.push_back(aColor.Green()*255.);
+        theColor.push_back(aColor.Blue()*255.);
+        return true;
+      }
+    }
+  }
+  return false;
 }
 
 void PartSet_OverconstraintListener::processEvent(
@@ -69,30 +94,23 @@ void PartSet_OverconstraintListener::processEvent(
              .arg(aCurrentInfoStr).toStdString().c_str());
 #endif
 
-  if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_FAILED)) {
+  Events_ID anEventID = theMessage->eventID();
+  if (anEventID == Events_Loop::eventByName(EVENT_SOLVER_FAILED) ||
+      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();
-      anUpdated = appendConflictingObjects(aConflictingObjects);
-    }
-    else {
-      // there is a crash in the solver. All objects are invalid
-      //anUpdated = appendConflictingObjects(std::set<ObjectPtr>());
+      if (anEventID == Events_Loop::eventByName(EVENT_SOLVER_FAILED))
+        anUpdated = appendConflictingObjects(aConflictingObjects);
+      else
+        anUpdated = repairConflictingObjects(aConflictingObjects);
     }
   }
-   if (theMessage->eventID() == 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();
-      anUpdated = repairConflictingObjects(aConflictingObjects);
-    }
-    else {
-      // there is no repaired objects, do nothing
-    }
+  else if (anEventID == Events_Loop::eventByName(EVENT_SKETCH_UNDER_CONSTRAINED) ||
+           anEventID == Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED)) {
+    myIsFullyConstrained = anEventID == Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED);
   }
 
 #ifdef DEBUG_FEATURE_OVERCONSTRAINT_LISTENER
@@ -106,8 +124,8 @@ bool PartSet_OverconstraintListener::appendConflictingObjects(
                                                const std::set<ObjectPtr>& theConflictingObjects)
 {
   std::set<ObjectPtr> aModifiedObjects;
-  std::vector<int> aColor;
-  getConflictingColor(aColor);
+  //std::vector<int> aColor;
+  //getConflictingColor(aColor);
 
   // set error state for new objects and append them in the internal map of objects
   std::set<ObjectPtr>::const_iterator
index 1f0e8f01c7ca3347c5fe5fcc49393dce4819e72d..4eaf5c8059c48d7ae1ea839f7cb098468a58e9a1 100755 (executable)
@@ -40,12 +40,9 @@ public:
 
   /// Returns true if the object belongs to internal container of conflicting objects
   /// \param theObject an object to be checked
-  /// \return boolean result
-  bool isConflictingObject(const ObjectPtr& theObject);
-
-  /// Returns values of conflicting color
   /// \param theColor the output container to be filled in [red, green, blue] values
-  void getConflictingColor(std::vector<int>& theColor);
+  /// \return boolean result
+  bool hasCustomColor(const ObjectPtr& theObject, std::vector<int>& theColor);
 
   /// Redefinition of Events_Listener method
   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
@@ -79,6 +76,7 @@ private:
 private:
   std::set<ObjectPtr> myConflictingObjects;
   ModuleBase_IWorkshop* myWorkshop;
+  bool myIsFullyConstrained; /// state if Solver is fully constrained, DOF = 0
 };
 
 #endif
index 05ba4c5013be735bc688e289d5181bf33b650e22..774a961b949d681d67a3d8bebae251e35f6a53b2 100644 (file)
 #include <iostream>
 #endif
 
+#define SKETCH_ENTITY_COLOR "225,0,0"
+#define SKETCH_EXTERNAL_COLOR "170,0,225"
+#define SKETCH_AUXILIARY_COLOR "0,85,0"
+#define SKETCH_OVERCONSTRAINT_COLOR "0,0,0"
+#define SKETCH_FULLY_CONSTRAINED_COLOR "150,150,150"
+
 //#define SET_PLANES_COLOR_IN_PREFERENCES
 
 // the only created instance of this plugin
@@ -124,6 +130,10 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
                                    "Sketch overconstraint color",
                                    Config_Prop::Color, SKETCH_OVERCONSTRAINT_COLOR);
 
+  Config_PropManager::registerProp("Visualization", "sketch_fully_constrained_color",
+                                   "Sketch fully constrained color",
+                                   Config_Prop::Color, SKETCH_FULLY_CONSTRAINED_COLOR);
+
   // register sketcher properties
 #ifdef SET_PLANES_COLOR_IN_PREFERENCES
   Config_PropManager::registerProp("Visualization", "yz_plane_color", "YZ plane color",
index 54f9399c8ed8cb22da961fbd0020b9db6381e64b..1af4d28bbc9541abccb51ad2672cbaded7bc3f6b 100644 (file)
 
 #include <Config_PropManager.h>
 
-#define SKETCH_ENTITY_COLOR "225,0,0"
-#define SKETCH_EXTERNAL_COLOR "170,0,225"
-#define SKETCH_AUXILIARY_COLOR "0,85,0"
-#define SKETCH_OVERCONSTRAINT_COLOR "0,0,0"
-
 /**\class SketchPlugin_SketchEntity
  * \ingroup Plugins
  * \brief Sketch Entity for creation of the new feature in PartSet. 
index 84e6b130fc5c3e9b1ad19c6dccddcfcd13ee1b97..13ffbee742ff077fa9b7ca5e677160e1804a45d2 100644 (file)
@@ -34,7 +34,7 @@ IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject);
 SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint,
                                                const std::shared_ptr<GeomAPI_Ax3>& thePlane)
 : AIS_InteractiveObject(), myConstraint(theConstraint), mySketcherPlane(thePlane),
-  myPoint(gp_Pnt(0.0, 0.0, 0.0)), myIsConflicting(false)
+  myPoint(gp_Pnt(0.0, 0.0, 0.0)), myIsCustomColor(false)
 {
 }
 
@@ -76,12 +76,12 @@ void SketcherPrs_Coincident::Compute(
     myPoint = aPoint;
 
   // Create the presentation as a combination of standard point markers
-  bool aValid = !myIsConflicting;
+  bool aCustomColor = myIsCustomColor;
   // The external yellow contour
   Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d();
   aPtA->SetType(Aspect_TOM_RING3);
   aPtA->SetScale(2.);
-  aPtA->SetColor(aValid ? Quantity_NOC_YELLOW : myConflictingColor);
+  aPtA->SetColor(!aCustomColor ? Quantity_NOC_YELLOW : myCustomColor);
 
   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
   aGroup->SetPrimitivesAspect(aPtA);
@@ -93,7 +93,7 @@ void SketcherPrs_Coincident::Compute(
   aPtA = new Graphic3d_AspectMarker3d();
   aPtA->SetType(Aspect_TOM_RING1);
   aPtA->SetScale(1.);
-  aPtA->SetColor(aValid ? Quantity_NOC_BLACK : myConflictingColor);
+  aPtA->SetColor(!aCustomColor ? Quantity_NOC_BLACK : myCustomColor);
   aGroup->SetPrimitivesAspect(aPtA);
   aGroup->AddPrimitiveArray (aPntArray);
 
@@ -101,7 +101,7 @@ void SketcherPrs_Coincident::Compute(
   aPtA = new Graphic3d_AspectMarker3d();
   aPtA->SetType(Aspect_TOM_POINT);
   aPtA->SetScale(5.);
-  aPtA->SetColor(aValid ? Quantity_NOC_BLACK : myConflictingColor);
+  aPtA->SetColor(!aCustomColor ? Quantity_NOC_BLACK : myCustomColor);
   aGroup->SetPrimitivesAspect(aPtA);
   aGroup->AddPrimitiveArray (aPntArray);
 
@@ -128,10 +128,12 @@ void SketcherPrs_Coincident::SetColor(const Quantity_Color &aCol)
   myOwnColor=aCol;
 }
 
-void SketcherPrs_Coincident::SetConflictingConstraint(const bool& theConflicting,
-                                                     const std::vector<int>& theColor)
+void SketcherPrs_Coincident::SetCustomColor(const std::vector<int>& theColor)
 {
-  myIsConflicting = theConflicting;
-  myConflictingColor = Quantity_Color(theColor[0] / 255., theColor[1] / 255., theColor[2] / 255.,
-                                      Quantity_TOC_RGB);
+  myIsCustomColor = !theColor.empty();
+  if (myIsCustomColor)
+    myCustomColor = Quantity_Color(theColor[0] / 255., theColor[1] / 255.,
+                                   theColor[2] / 255., Quantity_TOC_RGB);
+  else
+    myCustomColor = Quantity_Color();
 }
index 773a9c5ea2415224976e3446857ca494a90354f8..f77aa8d9b5c8b7fd7f8d9dac69301d24c750ebf5 100644 (file)
@@ -38,14 +38,10 @@ public:
   /// \param aColor a color name
   Standard_EXPORT virtual void SetColor(const Quantity_NameOfColor aColor);
 
-  /// Set state of the presentation, in case of conflicting state, the icon of the presentation is
+  /// Set state of the presentation, in case of custom color, the icon of the presentation is
   /// visualized in error color.
-  /// The state is stored in an internal field, so should be changed when
-  /// constraint become not conflicting
-  /// \param theConflicting a state
-  /// \param theColor a color for conflicting object
-  Standard_EXPORT void SetConflictingConstraint(const bool& theConflicting,
-                                                const std::vector<int>& theColor);
+  /// \param theColor a custom color for object presentation
+  Standard_EXPORT void SetCustomColor(const std::vector<int>& theColor);
 
   /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
   /// \param theConstraint a constraint feature
@@ -74,8 +70,8 @@ private:
   ModelAPI_Feature* myConstraint;
   std::shared_ptr<GeomAPI_Ax3> mySketcherPlane;
   gp_Pnt myPoint;
-  bool myIsConflicting; /// state if the presentation is visualized in error state
-  Quantity_Color myConflictingColor; /// the color of mid ring if there is a conflict
+  bool myIsCustomColor; /// state if the presentation is visualized in custom color
+  Quantity_Color myCustomColor; /// the color of mid ring if there is a conflict
 };
 
 
index 48a0256e2195d07d4520ad277c0f5849407c711e..cc56dd55d9902ca6f2a5c93752fc83e3285bff7e 100644 (file)
@@ -103,7 +103,7 @@ std::map<const char*, Handle(Image_AlienPixMap)> SketcherPrs_SymbolPrs::myIconsM
 
 SketcherPrs_SymbolPrs::SketcherPrs_SymbolPrs(ModelAPI_Feature* theConstraint,
                                              const std::shared_ptr<GeomAPI_Ax3>& thePlane)
- : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane), myIsConflicting(false)
+ : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane), myIsCustomColor(false)
 {
   SetAutoHilight(Standard_False);
   myPntArray = new Graphic3d_ArrayOfPoints(1);
@@ -166,7 +166,7 @@ void SketcherPrs_SymbolPrs::prepareAspect()
     else
       myAspect = new Graphic3d_AspectMarker3d(aIcon);
 
-    myAspect->SetColor(myColor);
+    myAspect->SetColor(myCustomColor);
   }
 }
 
@@ -294,25 +294,17 @@ void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)&
 }
 
 //*********************************************************************************
-void SketcherPrs_SymbolPrs::SetConflictingConstraint(const bool& theConflicting,
-                                                     const std::vector<int>& theColor)
+void SketcherPrs_SymbolPrs::SetCustomColor(const std::vector<int>& theColor)
 {
-  if (theConflicting)
-  {
-    myColor = Quantity_Color (theColor[0] / 255., theColor[1] / 255.,
-                              theColor[2] / 255., Quantity_TOC_RGB);
-    //if (!myAspect.IsNull())
-    //  myAspect->SetColor (Quantity_Color (theColor[0] / 255., theColor[1] / 255.,
-    //                      theColor[2] / 255., Quantity_TOC_RGB));
-    //myIsConflicting = true;
-  }
+  myIsCustomColor = !theColor.empty();
+  if (myIsCustomColor)
+    myCustomColor = Quantity_Color(theColor[0] / 255., theColor[1] / 255.,
+                                   theColor[2] / 255., Quantity_TOC_RGB);
   else
-  {
-    myColor = Quantity_Color (1.0, 1.0, 0.0, Quantity_TOC_RGB);
-    //if (!myAspect.IsNull())
-    //  myAspect->SetColor (Quantity_Color (1.0, 1.0, 0.0, Quantity_TOC_RGB));
-    //myIsConflicting = false;
-  }
+    myCustomColor = Quantity_Color (1.0, 1.0, 0.0, Quantity_TOC_RGB);
+
+  if (!myAspect.IsNull())
+    myAspect->SetColor (myCustomColor);
 }
 
 //*********************************************************************************
index 4c852d5a4ec94816806f81fba34dcb81fe041efc..8bbae4ddadaaa4f504b1ba86a783cb81910e2c16 100644 (file)
@@ -68,10 +68,8 @@ public:
   /// Set state of the presentation, in case of conflicting state, the icon of the presentation is
   /// visualized in error color. The state is stored in an internal field, so should be changed
   /// when constraint become not conflicting
-  /// \param theConflicting a state
   /// \param theColor a color for conflicting object
-  Standard_EXPORT void SetConflictingConstraint(const bool& theConflicting,
-                                                const std::vector<int>& theColor);
+  Standard_EXPORT void SetCustomColor(const std::vector<int>& theColor);
 
   /// Add a bounding box of the presentation to common bounding box
   /// \param theBndBox the common bounding box to update
@@ -149,8 +147,11 @@ private:
 
   Select3D_EntitySequence mySPoints;
 
-  Quantity_Color myColor;
-  bool myIsConflicting; /// state if the presentation is visualized in error state
+  bool myIsCustomColor; /// state if the presentation is visualized in custom color
+  Quantity_Color myCustomColor; /// the color of mid ring if there is a conflict
+
+  //Quantity_Color myIsCustomColor;
+  //bool myIsConflicting; /// state if the presentation is visualized in error state
   Handle(Image_AlienPixMap) myErrorIcon;
   Handle(Graphic3d_MarkerImage) myErrorImage;