]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Provide pop-up menu for steps DISPLAY_FIELD_STEP
authorvsv <vsv@opencascade.com>
Mon, 8 Jul 2019 14:45:51 +0000 (17:45 +0300)
committervsv <vsv@opencascade.com>
Mon, 8 Jul 2019 14:45:51 +0000 (17:45 +0300)
src/ModelAPI/ModelAPI_ResultField.cpp
src/ModelAPI/ModelAPI_ResultField.h
src/ModuleBase/ModuleBase_Tools.cpp
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_Workshop.cpp

index 0b44d8c95eb53a34d0078af47c55469de0f70973..8a997866e99af0a38514a38de50f66cedcc3e41c 100644 (file)
@@ -38,8 +38,25 @@ void ModelAPI_ResultField::ModelAPI_FieldStep::setDisplayed(const bool theDispla
     static Events_Loop* aLoop = Events_Loop::loop();
     static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
     static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
-    if (field()) {
-      aECreator->sendUpdated(field()->step(id()), EVENT_DISP); // updated pointer to this
+    ModelAPI_ResultField* aField = field();
+    if (aField) {
+      aECreator->sendUpdated(aField->step(id()), EVENT_DISP); // updated pointer to this
+      if (myIsDisplayed) {
+        for (int i = 0; i < aField->stepsSize(); i++)
+          if (i != id())
+            aField->step(i)->setDisplayed(false);
+        aField->setDisplayed(false);
+      }
     }
   }
 }
+
+
+void ModelAPI_ResultField::setDisplayed(const bool theDisplay)
+{
+  ModelAPI_Result::setDisplayed(theDisplay);
+  if (isDisplayed()) {
+    for (int i = 0; i < stepsSize(); i++)
+      step(i)->setDisplayed(false);
+  }
+}
index 09698048dac2cacd49722cdc56efcda56b008c21..4e2be6a4090e102188bdd8b1e88978c490ba3b37 100644 (file)
@@ -108,6 +108,10 @@ public:
   /// \param theId an id of the object
   virtual std::shared_ptr<ModelAPI_ResultField::ModelAPI_FieldStep> step(int theId) const = 0;
 
+  /// Sets the displayed/hidden state of the object. If it is changed, sends the "redisplay"
+  /// signal.
+  MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay);
+
   /// To refresh the steps of a field
   MODELAPI_EXPORT virtual void updateSteps() = 0;
 };
index e49a994ff0fac288f86a4cd4dce494658c162234..3d47d3cde272b10d0441cdf0de12d8978a46c3a1 100644 (file)
@@ -40,6 +40,7 @@
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Expression.h>
+#include <ModelAPI_ResultField.h>
 #include <Events_Loop.h>
 
 #include <ModelAPI_Data.h>
@@ -397,8 +398,9 @@ void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFe
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
     FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aObj);
     ResultParameterPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aResult);
+    FieldStepPtr aStep = std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObj);
 
-    hasResult |= (aResult.get() != NULL);
+    hasResult |= ((aResult.get() != NULL) || (aStep.get() != NULL));
     hasFeature |= (aFeature.get() != NULL);
     hasFolder |= (aFolder.get() != NULL);
     hasParameter |= (aConstruction.get() != NULL);
index 55006b4281b08d56ed0018b9884eacf54d72535e..83db1b815154dae656ae8ad83b1652ed05b82884 100644 (file)
@@ -49,6 +49,7 @@
 #include <ModelAPI_ResultField.h>
 #include <ModelAPI_Folder.h>
 #include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_ResultField.h>
 
 #include <Config_DataModelReader.h>
 
@@ -506,8 +507,7 @@ void XGUI_ContextMenuMgr::updateViewerMenu()
     foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
       aObject = aPrs->object();
       GeomShapePtr aShape = aPrs->shape();
-      ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
-      if (aRes && aRes->isDisplayed()) {
+      if (aObject->isDisplayed()) {
         isVisible = true;
         canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
         isShading =
@@ -683,6 +683,13 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu()
   aList.append(action("DELETE_CMD"));
   myObjBrowserMenus[ModelAPI_Folder::group()] = aList;
 
+  //---------------------------------------
+  // Step objects menu
+  aList.clear();
+  aList.append(action("SHOW_CMD"));
+  aList.append(action("HIDE_CMD"));
+  aList.append(action("SHOW_ONLY_CMD"));
+  myObjBrowserMenus[ModelAPI_ResultField::ModelAPI_FieldStep::group()] = aList;
 }
 
 void XGUI_ContextMenuMgr::buildViewerMenu()
@@ -721,6 +728,10 @@ void XGUI_ContextMenuMgr::buildViewerMenu()
   myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
   myViewerMenu[ModelAPI_ResultField::group()] = aList;
   //-------------------------------------
+  // Step objects menu
+  aList.clear();
+  aList.append(action("HIDE_CMD"));
+  myViewerMenu[ModelAPI_ResultField::ModelAPI_FieldStep::group()] = aList;
 }
 
 
index 2781c51f67fd90b73146ddc1790dfa1bacbab7dd..a83a67251145cd80563734a6f633f691d16ae2d6 100644 (file)
@@ -231,70 +231,30 @@ void XGUI_DataTree::processHistoryChange(const QModelIndex& theIndex)
 
 void XGUI_DataTree::processEyeClick(const QModelIndex& theIndex)
 {
-  static Events_Loop* aLoop = Events_Loop::loop();
-  static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
-
+  XGUI_ObjectsBrowser* aObjBrowser = qobject_cast<XGUI_ObjectsBrowser*>(parent());
   XGUI_DataModel* aModel = dataModel();
   ObjectPtr aObj = aModel->object(theIndex);
   if (aObj.get()) {
-    XGUI_ObjectsBrowser* aObjBrowser = qobject_cast<XGUI_ObjectsBrowser*>(parent());
-    ResultFieldPtr aField = std::dynamic_pointer_cast<ModelAPI_ResultField>(aObj);
-    if (aField.get()) {
-      bool toDisplay = !aField->isDisplayed();
-      aField->setDisplayed(toDisplay);
-      if (toDisplay) {
-        for (int i = 0; i < aField->stepsSize(); i++) {
-          aField->step(i)->setDisplayed(false);
-        }
-      }
-      Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
-    }
-    else {
-      FieldStepPtr aStep =
-        std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObj);
-      if (aStep.get()) {
-        // Only one step from a field can be visible at once
-        bool toDisplay = !aStep->isDisplayed();
-        if (toDisplay) {
-          int aId = aStep->id();
-          ModelAPI_ResultField* aField = aStep->field();
-          aField->setDisplayed(false);
-          for (int i = 0; i < aField->stepsSize(); i++) {
-            aField->step(i)->setDisplayed(i == aId);
-          }
-        }
-        else {
-          aStep->setDisplayed(false);
-          aECreator->sendUpdated(aStep, EVENT_DISP);
-        }
-        Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
-      }
-      else {
-        ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
-        if (aResObj.get()) {
-          std::set<ObjectPtr> anObjects;
-          anObjects.insert(aResObj);
-
-          bool hasHiddenState = aModel->hasHiddenState(theIndex);
-          if (aObjBrowser && hasHiddenState && !aObjBrowser->workshop()->prepareForDisplay(anObjects))
-            return;
-          if (hasHiddenState) { // #issue 2335(hide all faces then show solid problem)
-            if (aResObj->isDisplayed())
-              aResObj->setDisplayed(false);
-            aResObj->setDisplayed(true);
-          }
-          else
-            aResObj->setDisplayed(!aResObj->isDisplayed());
-          Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
-        }
-      }
+    std::set<ObjectPtr> anObjects;
+    anObjects.insert(aObj);
+
+    bool hasHiddenState = aModel->hasHiddenState(theIndex);
+    if (aObjBrowser && hasHiddenState && !aObjBrowser->workshop()->prepareForDisplay(anObjects))
+      return;
+    if (hasHiddenState) { // #issue 2335(hide all faces then show solid problem)
+      if (aObj->isDisplayed())
+        aObj->setDisplayed(false);
+      aObj->setDisplayed(true);
     }
+    else
+      aObj->setDisplayed(!aObj->isDisplayed());
+
     // Update list of selected objects because this event happens after
     // selection event in object browser
     if (aObjBrowser) {
       aObjBrowser->onSelectionChanged();
     }
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
     update(theIndex);
   }
 }
index 1f5794a970fddc2ecfe07c912387e65f5dc45ed2..7544b455f3a0417801dbfddce0ee41af272b8727 100644 (file)
@@ -2475,11 +2475,6 @@ void XGUI_Workshop::onTransparencyValueChanged()
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
 }
 
-//**************************************************************
-#define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
-for (int i = 0; i < aDoc->size(aGroupName); i++) { \
-  aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
-}
 
 //******************************************************
 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)