Salome HOME
2.17. Improved management of overconstraint situation: VPA correction in symbol prs...
authornds <nds@opencascade.com>
Wed, 10 Feb 2016 07:52:43 +0000 (10:52 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:04:42 +0000 (17:04 +0300)
src/ModuleBase/ModuleBase_IModule.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_OverconstraintListener.cpp
src/PartSet/PartSet_OverconstraintListener.h
src/SketcherPrs/SketcherPrs_SymbolPrs.cpp
src/SketcherPrs/SketcherPrs_SymbolPrs.h
src/XGUI/XGUI_CustomPrs.cpp
src/XGUI/XGUI_CustomPrs.h

index a37a49c8c8f59234c778831bf86f3d05490333cc..da7ed2b31372d0bbb0a0986d5500b691d0300dcc 100755 (executable)
@@ -10,6 +10,7 @@
 #include <ModelAPI_Attribute.h>\r
 \r
 #include <GeomAPI_Shape.h>\r
+#include <GeomAPI_ICustomPrs.h>\r
 \r
 #include <QString>\r
 #include <QObject>\r
@@ -182,6 +183,10 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
   virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,\r
                                    const bool theUpdateViewer) {}\r
 \r
+  /// Modifies the given presentation in the custom way.\r
+  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,\r
+                                     GeomCustomPrsPtr theCustomPrs) { return false; };\r
+\r
   /// Update the object presentable properties such as color, lines width and other\r
   /// If the object is result with the color attribute value set, it is used,\r
   /// otherwise the customize is applyed to the object's feature if it is a custom prs\r
index 7067a781949e73a2710336fcd0c3de7876ba61f9..e49ff2ce18881bf3b16dc84a8ef8fb2ce8da6ae7 100755 (executable)
@@ -61,6 +61,7 @@
 #include <XGUI_SelectionMgr.h>
 #include <XGUI_DataModel.h>
 #include <XGUI_ErrorMgr.h>
+#include <XGUI_CustomPrs.h>
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Sketch.h>
@@ -778,6 +779,53 @@ void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag
   myCustomPrs->deactivate(theFlag, theUpdateViewer);
 }
 
+bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                           std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
+{
+  bool aCustomized = false;
+
+  if (theResult.get())
+    return aCustomized;
+
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+  ObjectPtr anObject = aDisplayer->getObject(thePrs);
+  if (anObject.get()) {
+    bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
+    // customize sketcy symbol presentation
+    if (thePrs.get()) {
+      Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
+      if (!anAISIO.IsNull()) {
+        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);
+            aCustomized = true;
+          }
+        }
+      }
+    }
+    // customize sketch dimension constraint presentation
+    if (!aCustomized) {
+      std::vector<int> aColor;
+      if (isConflicting) {
+        myOverconstraintListener->getConflictingColor(aColor);
+      }
+      if (aColor.empty())
+        XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
+      if (!aColor.empty()) {
+        thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+        aCustomized = true;
+      }
+    }
+  }
+
+  return aCustomized;
+}
+
 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
                                      const bool theUpdateViewer)
 {
index cf65860f7ea4d503e83f9fbdbebdcdd28532b0db..3cf93537c29ecae7a909299b48c0f8856ee9d907 100755 (executable)
@@ -204,6 +204,10 @@ public:
   virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
                                    const bool theUpdateViewer);
 
+  /// Modifies the given presentation in the custom way.
+  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                     std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
+
   /// Update the object presentable properties such as color, lines width and other
   /// If the object is result with the color attribute value set, it is used,
   /// otherwise the customize is applyed to the object's feature if it is a custom prs
index 33c0ba03350cd31c9c2f67552c0cf7393c30fbc9..435ceca002a1d682976bcb57d4dcc836ad721eb0 100755 (executable)
@@ -105,12 +105,14 @@ bool PartSet_OverconstraintListener::appendConflictingObjects(
                                                   const std::set<ObjectPtr>& theConflictingObjects)
 {
   std::set<ObjectPtr> aModifiedObjects;
+  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 anIt = theConflictingObjects.begin(), aLast = theConflictingObjects.end();
   for (; anIt != aLast; anIt++) {
     ObjectPtr anObject = *anIt;
     if (myConflictingObjects.find(anObject) == myConflictingObjects.end()) { // it is not found
-      setConflictingObject(anObject, true);
       aModifiedObjects.insert(anObject);
       myConflictingObjects.insert(anObject);
     }
@@ -131,7 +133,6 @@ bool PartSet_OverconstraintListener::repairConflictingObjects(
   for (anIt = theConflictingObjects.begin(), aLast = theConflictingObjects.end() ; anIt != aLast; anIt++) {
     ObjectPtr anObject = *anIt;
     if (theConflictingObjects.find(anObject) != theConflictingObjects.end()) { // it is found
-      setConflictingObject(anObject, false);
       myConflictingObjects.erase(anObject);
 
       aModifiedObjects.insert(anObject);
@@ -176,33 +177,6 @@ void PartSet_OverconstraintListener::redisplayObjects(
   aDisplayer->updateViewer();
 }
 
-void PartSet_OverconstraintListener::setConflictingObject(const ObjectPtr& theObject,
-                                                          const bool theConflicting)
-{
-  if (!theObject.get() || !theObject->data()->isValid())
-    return;
-
-  AISObjectPtr anAISObject;
-  GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
-
-  if (aPrs.get() != NULL) {
-    XGUI_Workshop* aWorkshop = workshop();
-    XGUI_Displayer* aDisplayer = aWorkshop->displayer();
-
-    anAISObject = aPrs->getAISObject(aDisplayer->getAISObject(theObject));
-    if (anAISObject.get()) {
-      Handle(AIS_InteractiveObject) anAISIO = anAISObject->impl<Handle(AIS_InteractiveObject)>();
-      if (!anAISIO.IsNull()) {
-        if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
-          Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
-          if (!aPrs.IsNull())
-            aPrs->SetConflictingConstraint(theConflicting);
-        }
-      }
-    }
-  }
-}
-
 XGUI_Workshop* PartSet_OverconstraintListener::workshop() const
 {
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
index 772d00987a8ec81eb3fe825566acdbfa8e2a9fd3..3e8e5616ec90365ea30cef7e88dae630f71310b2 100755 (executable)
@@ -61,11 +61,6 @@ protected:
   /// \return boolean value whether the list differs from the internal list
   bool repairConflictingObjects(const std::set<ObjectPtr>& theObjects);
 
-  /// Obtains the object custom AIS presentation and change conflicting state if it exists
-  /// \param theObject the object which presentation error state should be changed
-  /// \param theConflicting if true, the object state is erroneous, else correct
-  void setConflictingObject(const ObjectPtr& theObject, const bool theConflicting);
-
   /// Sends update object signal for each object in the container and flush it.
   /// \param theObjects a list of object to be redisplayed
   void redisplayObjects(const std::set<ObjectPtr>& theObjects);
index d4d0df3cee43eb7916c819d32fa5fde35c08032e..a00c59369cd8f51ba649955f3f01afa612f05a1a 100644 (file)
@@ -46,6 +46,8 @@
 /// Step between icons
 static const double MyDist = 0.02;
 
+//#define ICON_TO_DEBUG
+
 /// Function to convert opengl data type
 GLenum toGlDataType (const Graphic3d_TypeOfData theType, GLint& theNbComp)
 {
@@ -267,6 +269,7 @@ SketcherPrs_SymbolPrs::~SketcherPrs_SymbolPrs()
 
 Handle(Image_AlienPixMap) SketcherPrs_SymbolPrs::icon()
 {
+#ifdef ICON_TO_DEBUG
   if (myIsConflicting) {
     if (myErrorIcon.IsNull()) {
       char* aEnv = getenv("NEWGEOM_ROOT_DIR");
@@ -284,6 +287,7 @@ Handle(Image_AlienPixMap) SketcherPrs_SymbolPrs::icon()
     }
     return myErrorIcon;
   }
+#endif
 
   if (myIconsMap.count(iconName()) == 1) {
     return myIconsMap[iconName()];
@@ -421,7 +425,7 @@ void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)&
 
 
 void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
-                                            const Standard_Integer aMode)
+                                             const Standard_Integer aMode)
 {
   ClearSelected();
   if ((aMode == 0) || (aMode == SketcherPrs_Tools::Sel_Constraint)) {
@@ -430,18 +434,40 @@ void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)&
   }
 }
 
-void SketcherPrs_SymbolPrs::SetConflictingConstraint(const bool& theConflicting)
+void SketcherPrs_SymbolPrs::SetConflictingConstraint(const bool& theConflicting,
+                                                     const std::vector<int>& theColor)
 {
+#ifdef ICON_TO_DEBUG
   if (myIsConflicting != theConflicting) {
     myIsConflicting = theConflicting;
     Handle(Image_AlienPixMap) anIcon = icon();
     if (!anIcon.IsNull())
       myAspect->SetMarkerImage(new Graphic3d_MarkerImage(anIcon));
   }
+#else
+  if (theConflicting)
+  {
+    if (!myAspect.IsNull())
+      myAspect->SetColor (Quantity_Color (theColor[0] / 255., theColor[1] / 255., theColor[2] / 255.,
+                          Quantity_TOC_RGB));
+    myIsConflicting = true;
+  }
+  else
+  {
+    if (!myAspect.IsNull())
+      myAspect->SetColor (Quantity_Color (1.0, 1.0, 0.0, Quantity_TOC_RGB));
+    myIsConflicting = false;
+  }
+#endif
 }
 
 void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace) const
 {
+  // this method is a combination of OCCT OpenGL functions. The main purpose is to have
+  // equal distance from the source object to symbol indpendently of zoom.
+  // It is base on OCCT 6.9.1 and might need changes when using later OCCT versions.
+  // The specific SHAPER modifications are marked by ShaperModification:start/end, other is OCCT code
+
   // do not update presentation for invalid or already removed objects: the presentation
   // should be removed soon
   if (!myConstraint->data().get() || !myConstraint->data()->isValid())
@@ -451,10 +477,12 @@ void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace)
   const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
   Handle(OpenGl_View) aView = theWorkspace->ActiveView();
   
+  // ShaperModification:start
   double aScale = aView->Camera()->Scale();
   // Update points coordinate taking the viewer scale into account
   if (!updatePoints(MyDist * aScale))
     return;
+  // ShaperModification:end
 
   Handle(Graphic3d_Buffer) aAttribs = myPntArray->Attributes();
 
@@ -474,7 +502,14 @@ void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace)
   const Handle(OpenGl_PointSprite)& aSpriteNorm = anAspectMarker->SpriteRes(aCtx);
       
   if (!aSpriteNorm.IsNull() && !aSpriteNorm->IsDisplayList()) {
+#ifdef ICON_TO_DEBUG
     const bool toHilight = (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) != 0;
+#else
+    // ShaperModification:start : filling the presentation with color if there is a conflict
+    const bool toHilight = (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) != 0 || myIsConflicting;
+    // ShaperModification:end
+#endif
+
     const Handle(OpenGl_PointSprite)& aSprite = (toHilight && anAspectMarker->SpriteHighlightRes(aCtx)->IsValid())
                                               ? anAspectMarker->SpriteHighlightRes(aCtx)
                                               : aSpriteNorm;
index 56fc52770f1a1f6dd22fdad8307809c6652ef756..fb51129275e1b8ef28031c286b3efd082dc39235 100644 (file)
@@ -66,7 +66,8 @@ public:
   /// 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
-  Standard_EXPORT void SetConflictingConstraint(const bool& theConflicting);
+  /// \param theColor a color for conflicting object
+  Standard_EXPORT void SetConflictingConstraint(const bool& theConflicting, const std::vector<int>& theColor);
 
   /// Render of the presentation
   /// \param theWorkspace is OpenGl workspace
index 395c7288bb9baadd8b4fbbdfc89ee744b73dfc76..7948325d795e1442ceeff7b5521220b8d90e4605 100644 (file)
@@ -34,7 +34,8 @@ void getColor(ResultPtr theResult, std::vector<int>& theColor)
   }
 }
 
-void getDefaultColor(ObjectPtr theObject, std::vector<int>& theColor, const bool isEmptyColorValid)
+void XGUI_CustomPrs::getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
+                                     std::vector<int>& theColor)
 {
   theColor.clear();
   // get default color from the preferences manager for the given result
@@ -62,7 +63,7 @@ void XGUI_CustomPrs::getResultColor(ResultPtr theResult, std::vector<int>& theCo
 {
   getColor(theResult, theColor);
   if (theColor.empty())
-    getDefaultColor(theResult, theColor, false);
+    getDefaultColor(theResult, false, theColor);
 }
 
 bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
@@ -84,16 +85,9 @@ bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr the
     aCustomized = !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);
   }
   else {
-    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-    ObjectPtr anObject = aDisplayer->getObject(thePrs);
-    if (anObject.get()) {
-     std::vector<int> aColor;
-     ModuleBase_IModule* aModule = myWorkshop->module();
-     aModule->getColor(anObject, aColor);
-     if (aColor.empty())
-       getDefaultColor(anObject, aColor, true);
-     if (!aColor.empty())
-       thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+   if (!aCustomized) {
+      ModuleBase_IModule* aModule = myWorkshop->module();
+      aCustomized = aModule->customisePresentation(theResult, thePrs, theCustomPrs);
     }
   }
   return aCustomized;
index 83b1b951ec713f26b03db8cb0398d74fe1db80e3..d8b7147a267f3ee939c41b08f45f5186afb81eda 100644 (file)
@@ -36,6 +36,16 @@ public:
   /// \param theColor a color in form of RGB vector
   static void getResultColor(ResultPtr theResult, std::vector<int>& theColor);
 
+  /// Returns the default object color. It obtains colorConfigInfo of the object
+  /// and find it in preferences. If there are no this color in preference and an empty
+  /// color is interpreted as invalid, it shows error message
+  /// \param theObject an investigated object
+  /// \param isEmptyColorValid boolean state about interpretation of empty color
+  /// \param theColor the result color
+  static void XGUI_EXPORT getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
+                                          std::vector<int>& theColor);
+
+
 protected:
   XGUI_Workshop* myWorkshop; /// the current workshop
 };