Salome HOME
Copyright update 2022
[modules/shaper.git] / src / XGUI / XGUI_ObjectsBrowser.cpp
index 2781c51f67fd90b73146ddc1790dfa1bacbab7dd..34c113f2cdc01ef0a3b68fe714316684678d9a95 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2022  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -31,6 +31,7 @@
 #include <ModuleBase_ITreeNode.h>
 
 #include <XGUI_Workshop.h>
+#include <XGUI_Displayer.h>
 
 #include <QLayout>
 #include <QLineEdit>
@@ -72,7 +73,7 @@ public:
       XGUI_DataModel* aModel = myTreedView->dataModel();
       ObjectPtr aObj = aModel->object(index);
       if (aObj.get() != NULL) {
-        aEditor->setText(aObj->data()->name().c_str());
+        aEditor->setText(QString::fromStdWString(aObj->data()->name()));
         return;
       }
     }
@@ -130,7 +131,7 @@ void XGUI_DataTree::commitData(QWidget* theEditor)
       if (XGUI_Tools::canRename(aObj, aName)) {
         SessionPtr aMgr = ModelAPI_Session::get();
         aMgr->startOperation("Rename");
-        aObj->data()->setName(qPrintable(aName));
+        aObj->data()->setName(aName.toStdWString());
         aMgr->finishOperation();
       }
     }
@@ -227,75 +228,37 @@ void XGUI_DataTree::processHistoryChange(const QModelIndex& theIndex)
     update(aModel->index(i, 1, aParent));
     update(aModel->index(i, 2, aParent));
   }
+  XGUI_ObjectsBrowser* aObjBrowser = qobject_cast<XGUI_ObjectsBrowser*>(parent());
+  aObjBrowser->workshop()->displayer()->updateViewer();
 }
 
 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
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+    update(theIndex);
     if (aObjBrowser) {
       aObjBrowser->onSelectionChanged();
     }
-    update(theIndex);
   }
 }
 
@@ -655,8 +618,8 @@ void XGUI_ObjectsBrowser::clearContent()
 }
 
 //***************************************************
-void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected,
-                                       const QItemSelection& theDeselected)
+void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& /*theSelected*/,
+                                             const QItemSelection& /*theDeselected*/)
 {
   onSelectionChanged();
 }