]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' of newgeom:newgeom
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 22 Sep 2014 09:04:37 +0000 (13:04 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 22 Sep 2014 09:04:37 +0000 (13:04 +0400)
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/shading.png [new file with mode: 0644]
src/XGUI/pictures/wireframe.png [new file with mode: 0644]

index 5f69add11a41e395d1a382899d325b2e9b5a8013..c278646e0cb04fb89265337edc7e26994a81e7f5 100644 (file)
@@ -51,6 +51,12 @@ void XGUI_ContextMenuMgr::createActions()
 
   aAction = new QAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"), this);
   addAction("HIDE_CMD", aAction);
+
+  aAction = new QAction(QIcon(":pictures/shading.png"), tr("Shading"), this);
+  addAction("SHADING_CMD", aAction);
+
+  aAction = new QAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"), this);
+  addAction("WIREFRAME_CMD", aAction);
 }
 
 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
@@ -134,9 +140,13 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
         } else if (hasFeature) {
           aMenu->addAction(action("EDIT_CMD"));
         } else {
-          if (aDisplayer->isVisible(aObject))
+          if (aDisplayer->isVisible(aObject)) {
             aMenu->addAction(action("HIDE_CMD"));
-          else {
+            if (aDisplayer->displayMode(aObject) == XGUI_Displayer::Shading)
+              aMenu->addAction(action("WIREFRAME_CMD"));
+            else
+              aMenu->addAction(action("SHADING_CMD"));
+          } else {
             aMenu->addAction(action("SHOW_CMD"));
           }
           aMenu->addAction(action("SHOW_ONLY_CMD"));
@@ -150,6 +160,9 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
         aMenu->addAction(action("SHOW_CMD"));
         aMenu->addAction(action("HIDE_CMD"));
         aMenu->addAction(action("SHOW_ONLY_CMD"));
+        aMenu->addSeparator();
+        aMenu->addAction(action("SHADING_CMD"));
+        aMenu->addAction(action("WIREFRAME_CMD"));
       }
     }
     if (hasFeature)
@@ -182,17 +195,23 @@ void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const
     //if (aObjects.size() == 1)
     //  theMenu->addAction(action("EDIT_CMD"));
     bool isVisible = false;
+    bool isShading = false;
     foreach(ObjectPtr aObject, aObjects)
     {
       ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObject);
       if (aRes && myWorkshop->displayer()->isVisible(aRes)) {
         isVisible = true;
+        isShading = (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);      
         break;
       }
     }
-    if (isVisible)
+    if (isVisible) {
       theMenu->addAction(action("HIDE_CMD"));
-    else
+      if (isShading)
+        theMenu->addAction(action("WIREFRAME_CMD"));
+      else
+        theMenu->addAction(action("SHADING_CMD"));
+    } else
       theMenu->addAction(action("SHOW_CMD"));
     //theMenu->addAction(action("DELETE_CMD"));
   }
index 7f1627c28eb9f0f0c2cd3bb87ad1989d15304788..83b2f0eb704ebb9b8c695ece351a013867dc6fcf 100644 (file)
@@ -35,7 +35,7 @@ XGUI_Displayer::~XGUI_Displayer()
 {
 }
 
-bool XGUI_Displayer::isVisible(ObjectPtr theObject)
+bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
 {
   return myResult2AISObjectMap.find(theObject) != myResult2AISObjectMap.end();
 }
@@ -441,4 +441,38 @@ void XGUI_Displayer::deactivateObjectsOutOfContext()
 
   aContext->RemoveFilters();
   aContext->NotUseDisplayedObjects();
-}
\ No newline at end of file
+}
+
+
+void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
+{
+  if (theMode == NoMode)
+    return;
+
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return;
+
+  boost::shared_ptr<GeomAPI_AISObject> aAISObj = getAISObject(theObject);
+  if (!aAISObj)
+    return;
+
+  Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+  aContext->SetDisplayMode(aAISIO, theMode, toUpdate);
+}
+
+
+XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return NoMode;
+
+  boost::shared_ptr<GeomAPI_AISObject> aAISObj = getAISObject(theObject);
+  if (!aAISObj)
+    return NoMode;
+
+  Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+  return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
+}
+
index 7d0970659d54dd6457c062562df919c0b58362c0..cf3a7679898e6a564ec868d3313e4a151fb9394a 100644 (file)
@@ -37,6 +37,8 @@ class XGUI_Workshop;
 class XGUI_EXPORT XGUI_Displayer
 {
  public:
+   enum DisplayMode { NoMode = -1, Wireframe, Shading };
+
   /// Constructor
   /// \param theViewer the viewer
   XGUI_Displayer(XGUI_Workshop* theWorkshop);
@@ -49,7 +51,7 @@ class XGUI_EXPORT XGUI_Displayer
 
   /// Returns the feature visibility state.
   /// \param theFeature a feature instance
-  bool isVisible(ObjectPtr theObject);
+  bool isVisible(ObjectPtr theObject) const;
 
   /// Display the feature. Obtain the visualized object from the feature.
   /// \param theFeature a feature instance
@@ -132,6 +134,14 @@ class XGUI_EXPORT XGUI_Displayer
 
   void deactivateObjectsOutOfContext();
 
+  /// Sets display mode for the given object if this object is displayed
+  void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
+
+  /// Returns current display mode for the given object.
+  /// If object is not displayed then returns NoMode.
+  DisplayMode displayMode(ObjectPtr theObject) const;
+
+
  protected:
   /// Deactivate local selection
   /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
index 51a66d026d2f96a973a92e281760ce8295834128..bbec2aabffb3728a5a56d887f0367edc010ab541 100644 (file)
@@ -1076,6 +1076,10 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     showObjects(aObjects, false);
   else if (theId == "SHOW_ONLY_CMD")
     showOnlyObjects(aObjects);
+  else if (theId == "SHADING_CMD")
+    setDisplayMode(aObjects, XGUI_Displayer::Shading);
+  else if (theId == "WIREFRAME_CMD")
+    setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
 }
 
 //**************************************************************
@@ -1257,3 +1261,13 @@ void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup
   for (int i = 0; i < theDoc->size(theGroup); i++)
     myDisplayer->display(theDoc->object(theGroup, i), false);
 }
+
+//**************************************************************
+void XGUI_Workshop::setDisplayMode(const QList<ObjectPtr>& theList, int theMode)
+{
+  foreach(ObjectPtr aObj, theList) {
+    myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
+  }
+  if (theList.size() > 0)
+    myDisplayer->updateViewer();
+}
index dbb6cb60ff6015e8d78449526378978014fb9a58..5a557db2bc5ddeb883d478c46bdbf98291ec483a 100644 (file)
@@ -157,6 +157,8 @@ Q_OBJECT
   //! Show the given features in 3d Viewer
   void showOnlyObjects(const QList<ObjectPtr>& theList);
 
+  void setDisplayMode(const QList<ObjectPtr>& theList, int theMode);
+
   ModuleBase_IModule* module() const
   {
     return myModule;
index dd4aa4808ef04660fb4f30c95921bef074af6a4a..6aaa267620b50aa984e140184e5c97758566d091 100644 (file)
@@ -64,5 +64,7 @@
    
      <file>pictures/view_prefs.png</file>
      <file>pictures/module.png</file>
+     <file>pictures/shading.png</file>
+     <file>pictures/wireframe.png</file>
  </qresource>
  </RCC>
diff --git a/src/XGUI/pictures/shading.png b/src/XGUI/pictures/shading.png
new file mode 100644 (file)
index 0000000..909df3d
Binary files /dev/null and b/src/XGUI/pictures/shading.png differ
diff --git a/src/XGUI/pictures/wireframe.png b/src/XGUI/pictures/wireframe.png
new file mode 100644 (file)
index 0000000..e500831
Binary files /dev/null and b/src/XGUI/pictures/wireframe.png differ