]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
ModuleBase_IconFactory class was created
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 28 Jul 2015 15:42:23 +0000 (18:42 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 28 Jul 2015 15:42:23 +0000 (18:42 +0300)
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_IconFactory.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_IconFactory.h [new file with mode: 0644]
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_IconFactory.cpp [new file with mode: 0644]
src/PartSet/PartSet_IconFactory.h [new file with mode: 0644]
src/PartSet/PartSet_MenuMgr.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/XGUI_DataModel.cpp
src/XGUI/XGUI_DataModel.h

index ebb3760725740ded73553811696a5e0e75f79acb..54fc7c1b1107f81bcb1ac7d5710c9bf8393e9c78 100644 (file)
@@ -49,6 +49,7 @@ SET(PROJECT_HEADERS
   ModuleBase_WidgetSwitch.h
   ModuleBase_WidgetToolbox.h
   ModuleBase_WidgetValidated.h
+  ModuleBase_IconFactory.h
 )
 
 SET(PROJECT_SOURCES
@@ -95,6 +96,7 @@ SET(PROJECT_SOURCES
   ModuleBase_WidgetSwitch.cpp
   ModuleBase_WidgetToolbox.cpp
   ModuleBase_WidgetValidated.cpp
+  ModuleBase_IconFactory.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/ModuleBase/ModuleBase_IconFactory.cpp b/src/ModuleBase/ModuleBase_IconFactory.cpp
new file mode 100644 (file)
index 0000000..f87fa91
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_IconFactory.cpp
+// Created:     28 Jul 2015
+// Author:      Vitaly SMETANNIKOV
+
+
+#include "ModuleBase_IconFactory.h"
+
+ModuleBase_IconFactory* MYIconFactory = 0;
+
+
+void ModuleBase_IconFactory::setFactory(ModuleBase_IconFactory* theFactory)
+{
+  if (MYIconFactory)
+    delete MYIconFactory;
+  MYIconFactory = theFactory;
+}
+
+ModuleBase_IconFactory* ModuleBase_IconFactory::get()
+{
+  if (!MYIconFactory) {
+    MYIconFactory = new ModuleBase_IconFactory();
+  }
+  return MYIconFactory;
+}
+
+QIcon ModuleBase_IconFactory::getIcon(ObjectPtr theIcon)
+{
+  return QIcon();
+}
diff --git a/src/ModuleBase/ModuleBase_IconFactory.h b/src/ModuleBase/ModuleBase_IconFactory.h
new file mode 100644 (file)
index 0000000..3a7c99d
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_IconFactory.h
+// Created:     28 Jul 2015
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef ModuleBase_IconFactory_H
+#define ModuleBase_IconFactory_H
+
+#include "ModuleBase.h"
+#include <ModelAPI_Object.h>
+#include <QIcon>
+
+/**\class ModuleBase_IconFactory
+ * \ingroup GUI
+ * \brief This is a class which provides icons of objects for object browser 
+ */
+class MODULEBASE_EXPORT ModuleBase_IconFactory
+{
+public:
+  /// Returns icons factory instance
+  static ModuleBase_IconFactory* get();
+
+  /// Returns Icon for the given object
+  /// \param theObj an object
+  virtual QIcon getIcon(ObjectPtr theObj);
+
+protected:
+  /// Set the current icons factory instance
+  /// \param theFactory a new factory
+  static void setFactory(ModuleBase_IconFactory* theFactory);
+};
+
+#endif
\ No newline at end of file
index eabe491f0f3c372c554bac781c6920f27175ea65..4bc8ebfcd35e5d660cfd1db301bb1b9b18e75f59 100644 (file)
@@ -31,6 +31,7 @@ SET(PROJECT_HEADERS
        PartSet_DataTreeModel.h
        PartSet_WidgetSketchCreator.h
        PartSet_TopDataModel.h
+       PartSet_IconFactory.h
 )
 
 SET(PROJECT_SOURCES
@@ -58,6 +59,7 @@ SET(PROJECT_SOURCES
        PartSet_DataTreeModel.cpp
        PartSet_WidgetSketchCreator.cpp
        PartSet_TopDataModel.cpp
+       PartSet_IconFactory.cpp
 )
 
 SET(PROJECT_RESOURCES 
diff --git a/src/PartSet/PartSet_IconFactory.cpp b/src/PartSet/PartSet_IconFactory.cpp
new file mode 100644 (file)
index 0000000..30fe5aa
--- /dev/null
@@ -0,0 +1,88 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        PartSet_IconFactory.cpp
+// Created:     28 Jul 2015
+// Author:      Vitaly SMETANNIKOV
+
+#include "PartSet_IconFactory.h"
+#include <ModuleBase_ActionInfo.h>
+#include <ModuleBase_Tools.h>
+
+#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultBody.h>
+
+#include <Config_FeatureMessage.h>
+#include <Events_Loop.h>
+
+QMap<QString, QString> PartSet_IconFactory::myIcons;
+
+PartSet_IconFactory::PartSet_IconFactory():ModuleBase_IconFactory()
+{
+  setFactory(this);
+  Events_Loop::loop()->registerListener(this, 
+    Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
+}
+
+
+QIcon PartSet_IconFactory::getIcon(ObjectPtr theObj)
+{
+  QIcon anIcon;
+
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
+  if (aFeature.get()) {
+    std::string aKind = aFeature->getKind();
+    QString aId(aKind.c_str());
+    if (!myIcons.contains(aId))
+      return anIcon;
+
+    QString anIconString = myIcons[aId];
+
+    ModelAPI_ExecState aState = aFeature->data()->execState();
+    switch(aState) {
+      case ModelAPI_StateDone:
+      case ModelAPI_StateNothing: {
+        anIcon = QIcon(anIconString);
+      }
+      break;
+      case ModelAPI_StateMustBeUpdated: {
+        anIcon = ModuleBase_Tools::lighter(anIconString);
+      }
+      break;
+      case ModelAPI_StateExecFailed: {
+        anIcon = ModuleBase_Tools::composite(":icons/exec_state_failed.png", anIconString);
+      }
+      break;
+      case ModelAPI_StateInvalidArgument: {
+        anIcon = ModuleBase_Tools::composite(":icons/exec_state_invalid_parameters.png",
+                                             anIconString);
+      }
+      break;
+      default: break;  
+    }
+  } else {
+    std::string aGroup = theObj->groupName();
+    if (aGroup == ModelAPI_ResultPart::group()) {
+      return QIcon(":pictures/part_ico.png");
+    } else {
+      if (theObj && theObj->data() && theObj->data()->execState() == ModelAPI_StateMustBeUpdated)
+        return QIcon(":pictures/constr_object_modified.png");
+      return QIcon(":pictures/constr_object.png");
+    }
+  }
+  return anIcon;  
+}
+
+void PartSet_IconFactory::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+{
+  if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
+    std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
+       std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
+    if (!aFeatureMsg->isInternal()) {
+      ActionInfo aFeatureInfo;
+      aFeatureInfo.initFrom(aFeatureMsg);
+      // Remember features icons
+      myIcons[QString::fromStdString(aFeatureMsg->id())] = aFeatureInfo.iconFile;
+    }
+  }
+}
\ No newline at end of file
diff --git a/src/PartSet/PartSet_IconFactory.h b/src/PartSet/PartSet_IconFactory.h
new file mode 100644 (file)
index 0000000..a6a51e2
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        PartSet_IconFactory.h
+// Created:     28 Jul 2015
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef PartSet_IconFactory_H
+#define PartSet_IconFactory_H
+
+#include "PartSet.h"
+#include <ModuleBase_IconFactory.h>
+#include <Events_Listener.h>
+
+#include <QMap>
+
+
+/**\class PartSet_IconFactory
+ * \ingroup GUI
+ * \brief This is a class is redefined in order to provide
+ * icons of objects for object browser specific for PartSetModule
+ */
+class PARTSET_EXPORT PartSet_IconFactory : public ModuleBase_IconFactory, public Events_Listener
+{
+public:
+  /// Constructor
+  PartSet_IconFactory();
+
+  /// Returns Icon for the given object
+  /// \param theObj an object
+  virtual QIcon getIcon(ObjectPtr theObj);
+
+  /// Event Listener method
+  /// \param theMessage an event message
+  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+
+private:
+  static QMap<QString, QString> myIcons;
+};
+
+#endif
\ No newline at end of file
index f232b9b4845a5fba8b2a5185f270c073d3c41a4c..c5ad640cbfc728b4feb850051c3a03585ba2b3c0 100644 (file)
@@ -26,6 +26,8 @@
 #include <XGUI_ModuleConnector.h>
 #include <XGUI_Workshop.h>
 #include <XGUI_Displayer.h>
+#include <XGUI_DataModel.h>
+#include <XGUI_ObjectsBrowser.h>
 
 #include <Events_Loop.h>
 #include <ModelAPI_Events.h>
index 255c6d97f78805d15a50399f723b732b0f180c8e..96083adb9213cff98f7a196af56a0bf18ce5f64c 100644 (file)
@@ -15,7 +15,8 @@
 #include "PartSet_WidgetSketchCreator.h"
 #include "PartSet_SketcherMgr.h"
 #include "PartSet_MenuMgr.h"
-#include <PartSet_CustomPrs.h>
+#include "PartSet_CustomPrs.h"
+#include "PartSet_IconFactory.h"
 
 #include "PartSet_Filters.h"
 #include "PartSet_FilterInfinite.h"
@@ -60,6 +61,7 @@
 #include <XGUI_Tools.h>
 #include <XGUI_ObjectsBrowser.h>
 #include <XGUI_SelectionMgr.h>
+#include <XGUI_DataModel.h>
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Sketch.h>
@@ -117,6 +119,8 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
   : ModuleBase_IModule(theWshop),
   myRestartingMode(RM_None), myVisualLayerId(0)
 {
+  new PartSet_IconFactory();
+
   mySketchMgr = new PartSet_SketcherMgr(this);
   myDataModel = new PartSet_DocumentDataModel(this);
 
@@ -863,8 +867,9 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
 
     SessionPtr aMgr = ModelAPI_Session::get();
     DocumentPtr aActiveDoc = aMgr->activeDocument();
-    DocumentPtr aDoc = aMgr->moduleDocument();
+#ifdef ModuleDataModel
     QModelIndex aOldIndex = myDataModel->activePartTree();
+    DocumentPtr aDoc = aMgr->moduleDocument();
     if (aActiveDoc == aDoc) {
       if (aOldIndex.isValid())
         aTreeView->setExpanded(aOldIndex, false);
@@ -886,6 +891,16 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
         }
       }
     }
+#else
+    // Problem with MPV: At first time on creation it doesn't work because Part feature
+    // creation event will be sent after
+    if (aActivePartIndex.isValid())
+      aTreeView->setExpanded(aActivePartIndex, false);
+    XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
+    aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
+    if (aActivePartIndex.isValid())
+      aTreeView->setExpanded(aActivePartIndex, true);
+#endif
     aLabel->setPalette(aPalet);
     aWorkshop->updateCommandStatus();
 
index a17c8559996a2bc0e8a8b42ccb89522cb8bc25e9..532e874f53465df94c5f9b273a3c26b1c2c1ee8a 100644 (file)
@@ -252,6 +252,8 @@ protected slots:
   int myVisualLayerId;
 
   PartSet_DocumentDataModel* myDataModel;
+
+  QModelIndex aActivePartIndex;
 };
 
 #endif
index 35cadb93c0fab97a8d1b51acd7794f83207f99cb..d07f8cc35c510e3c4ec65338b35e2a76e2f3a853 100644 (file)
@@ -6,6 +6,8 @@
 
 #include "XGUI_DataModel.h"
 
+#include <ModuleBase_IconFactory.h>
+
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_ResultParameter.h>
 #include <Events_Error.h>
 
 #include <QIcon>
+#include <QBrush>
+
+#define ACTIVE_COLOR QColor(0,72,140)
+#define PASSIVE_COLOR Qt::black
 
 /// Returns ResultPart object if the given object is a Part feature
 /// Otherwise returns NULL
@@ -51,7 +57,6 @@ XGUI_DataModel::XGUI_DataModel(QObject* theParent) : QAbstractItemModel(theParen
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
-  aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
 }
 
 //******************************************************
@@ -78,7 +83,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
       if (aDoc == aRootDoc) {
         int aRow = aRootDoc->size(aObjType) - 1;
         if (aObjType == aRootType) {
-          insertRow(aRow + aNbFolders);
+          insertRow(aRow + aNbFolders + 1);
         } else {
           int aFolderId = myXMLReader.rootFolderId(aObjType);
           if (aFolderId != -1) {
@@ -212,9 +217,29 @@ QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const
           QString(" (%1)").arg(rowCount(theIndex));
       case Qt::DecorationRole:
         return QIcon(myXMLReader.rootFolderIcon(theIndexRow).c_str());
+      case Qt::ForegroundRole:
+        if (aRootDoc->isActive())
+          return QBrush(ACTIVE_COLOR);
+        else
+          return QBrush(PASSIVE_COLOR);
     }
   } else {
     ModelAPI_Document* aSubDoc = getSubDocument(theIndex.internalPointer());
+
+    if (theRole == Qt::ForegroundRole) {
+      bool aIsActive = false;
+      if (aSubDoc)
+        aIsActive = aSubDoc->isActive();
+      else {
+        ModelAPI_Object* aObj = (ModelAPI_Object*)theIndex.internalPointer();
+        aIsActive = aObj->document()->isActive();
+      }
+      if (aIsActive)
+        return QBrush(ACTIVE_COLOR);
+      else
+        return QBrush(PASSIVE_COLOR);
+    }
+
     if (aSubDoc) { // this is a folder of sub document
       switch (theRole) {
         case Qt::DisplayRole:
@@ -235,6 +260,8 @@ QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const
           return aTitle + " = " + aVal;
         }
         return aObj->data()->name().c_str();
+      case Qt::DecorationRole:
+        return ModuleBase_IconFactory::get()->getIcon(object(theIndex));
       }
     }
   }
@@ -269,10 +296,9 @@ int XGUI_DataModel::rowCount(const QModelIndex& theParent) const
   if (aId == -1) { 
     // this is a folder under root
     int aParentPos = theParent.row();
-    if (aId == -1) { // first level of folders
-      std::string aType = myXMLReader.rootFolderType(aParentPos);
-      return aRootDoc->size(aType);
-    }
+    std::string aType = myXMLReader.rootFolderType(aParentPos);
+    //qDebug("### %s = %i\n", aType.c_str(), aRootDoc->size(aType));
+    return aRootDoc->size(aType);
   } else {
     // It is an object which could have children
     ModelAPI_Document* aDoc = getSubDocument(theParent.internalPointer());
@@ -509,3 +535,14 @@ QModelIndex XGUI_DataModel::findDocumentRootIndex(ModelAPI_Document* theDoc) con
   }
   return QModelIndex();
 }
+
+//******************************************************
+QModelIndex XGUI_DataModel::documentRootIndex(DocumentPtr theDoc) const
+{
+  SessionPtr aSession = ModelAPI_Session::get();
+  DocumentPtr aRootDoc = aSession->moduleDocument();
+  if (theDoc == aRootDoc)
+    return QModelIndex();
+  else 
+    return findDocumentRootIndex(theDoc.get());
+}
\ No newline at end of file
index 4f3dbd50e2e895f2ebaa0f03ac055e5aebeb7bd2..cff7b48816cdc072adfb806b1eae7f31e3da5e5f 100644 (file)
@@ -106,6 +106,9 @@ public:
   /// \param theIndex a model index
   virtual Qt::ItemFlags flags(const QModelIndex& theIndex) const;
 
+  /// Returns an index which is root of the given document
+  /// \param theDoc a document
+  QModelIndex documentRootIndex(DocumentPtr theDoc) const;
 
 private:
   QModelIndex findDocumentRootIndex(ModelAPI_Document* theDoc) const;