ModuleBase_WidgetSwitch.h
ModuleBase_WidgetToolbox.h
ModuleBase_WidgetValidated.h
+ ModuleBase_IconFactory.h
)
SET(PROJECT_SOURCES
ModuleBase_WidgetSwitch.cpp
ModuleBase_WidgetToolbox.cpp
ModuleBase_WidgetValidated.cpp
+ ModuleBase_IconFactory.cpp
)
SET(PROJECT_LIBRARIES
--- /dev/null
+// 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();
+}
--- /dev/null
+// 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
PartSet_DataTreeModel.h
PartSet_WidgetSketchCreator.h
PartSet_TopDataModel.h
+ PartSet_IconFactory.h
)
SET(PROJECT_SOURCES
PartSet_DataTreeModel.cpp
PartSet_WidgetSketchCreator.cpp
PartSet_TopDataModel.cpp
+ PartSet_IconFactory.cpp
)
SET(PROJECT_RESOURCES
--- /dev/null
+// 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
--- /dev/null
+// 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
#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>
#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"
#include <XGUI_Tools.h>
#include <XGUI_ObjectsBrowser.h>
#include <XGUI_SelectionMgr.h>
+#include <XGUI_DataModel.h>
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
: ModuleBase_IModule(theWshop),
myRestartingMode(RM_None), myVisualLayerId(0)
{
+ new PartSet_IconFactory();
+
mySketchMgr = new PartSet_SketcherMgr(this);
myDataModel = new PartSet_DocumentDataModel(this);
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);
}
}
}
+#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();
int myVisualLayerId;
PartSet_DocumentDataModel* myDataModel;
+
+ QModelIndex aActivePartIndex;
};
#endif
#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
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()));
}
//******************************************************
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) {
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:
return aTitle + " = " + aVal;
}
return aObj->data()->name().c_str();
+ case Qt::DecorationRole:
+ return ModuleBase_IconFactory::get()->getIcon(object(theIndex));
}
}
}
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());
}
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
/// \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;