From: vsv Date: Tue, 28 Jul 2015 15:42:23 +0000 (+0300) Subject: ModuleBase_IconFactory class was created X-Git-Tag: V_1.4.0_beta4~448 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3e441258b4252ac2937ca4a4d77f56af7334be45;p=modules%2Fshaper.git ModuleBase_IconFactory class was created --- diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index ebb376072..54fc7c1b1 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -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 index 000000000..f87fa91f3 --- /dev/null +++ b/src/ModuleBase/ModuleBase_IconFactory.cpp @@ -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 index 000000000..3a7c99d4e --- /dev/null +++ b/src/ModuleBase/ModuleBase_IconFactory.h @@ -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 +#include + +/**\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 diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index eabe491f0..4bc8ebfcd 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -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 index 000000000..30fe5aa4b --- /dev/null +++ b/src/PartSet/PartSet_IconFactory.cpp @@ -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 +#include + +#include +#include +#include + +#include +#include + +QMap 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(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& theMessage) +{ + if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) { + std::shared_ptr aFeatureMsg = + std::dynamic_pointer_cast(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 index 000000000..a6a51e256 --- /dev/null +++ b/src/PartSet/PartSet_IconFactory.h @@ -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 +#include + +#include + + +/**\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& theMessage); + +private: + static QMap myIcons; +}; + +#endif \ No newline at end of file diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index f232b9b48..c5ad640cb 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 255c6d97f..96083adb9 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -15,7 +15,8 @@ #include "PartSet_WidgetSketchCreator.h" #include "PartSet_SketcherMgr.h" #include "PartSet_MenuMgr.h" -#include +#include "PartSet_CustomPrs.h" +#include "PartSet_IconFactory.h" #include "PartSet_Filters.h" #include "PartSet_FilterInfinite.h" @@ -60,6 +61,7 @@ #include #include #include +#include #include #include @@ -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& 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& 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(); diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index a17c85599..532e874f5 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -252,6 +252,8 @@ protected slots: int myVisualLayerId; PartSet_DocumentDataModel* myDataModel; + + QModelIndex aActivePartIndex; }; #endif diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 35cadb93c..d07f8cc35 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -6,6 +6,8 @@ #include "XGUI_DataModel.h" +#include + #include #include #include @@ -18,6 +20,10 @@ #include #include +#include + +#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& 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 diff --git a/src/XGUI/XGUI_DataModel.h b/src/XGUI/XGUI_DataModel.h index 4f3dbd50e..cff7b4881 100644 --- a/src/XGUI/XGUI_DataModel.h +++ b/src/XGUI/XGUI_DataModel.h @@ -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;