From b1a9aba9a812f170668d0f4e04b3501d91da425e Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 30 Apr 2015 12:54:42 +0300 Subject: [PATCH] Transfer data model for object browser under module responsibility --- src/ModuleBase/CMakeLists.txt | 1 + .../ModuleBase_IDocumentDataModel.h | 36 +++ src/ModuleBase/ModuleBase_IModule.h | 8 +- src/ModuleBase/ModuleBase_Tools.cpp | 19 ++ src/ModuleBase/ModuleBase_Tools.h | 9 + src/NewGeom/NewGeom_Module.cpp | 2 +- src/PartSet/CMakeLists.txt | 6 + .../PartSet_DataTreeModel.h} | 20 +- .../PartSet_DocumentDataModel.cpp} | 282 ++++++++++++------ .../PartSet_DocumentDataModel.h} | 56 ++-- src/PartSet/PartSet_MenuMgr.cpp | 61 +++- src/PartSet/PartSet_MenuMgr.h | 11 +- src/PartSet/PartSet_Module.cpp | 223 ++++++++++---- src/PartSet/PartSet_Module.h | 25 +- .../PartSet_PartDataModel.cpp} | 78 +++-- .../PartSet_PartDataModel.h} | 24 +- src/PartSet/PartSet_icons.qrc | 5 + .../pictures => PartSet/icons}/activate.png | Bin src/PartSet/icons/deactivate.png | Bin 0 -> 3639 bytes src/{XGUI/pictures => PartSet/icons}/edit.png | Bin .../icons}/exec_state_failed.png | Bin .../icons}/exec_state_invalid_parameters.png | Bin src/PartSetPlugin/PartSetPlugin_Part.h | 6 - src/XGUI/CMakeLists.txt | 5 - src/XGUI/XGUI_ContextMenuMgr.cpp | 54 +--- src/XGUI/XGUI_ContextMenuMgr.h | 2 +- src/XGUI/XGUI_ObjectsBrowser.cpp | 181 ++++------- src/XGUI/XGUI_ObjectsBrowser.h | 60 ++-- src/XGUI/XGUI_Tools.cpp | 18 -- src/XGUI/XGUI_Tools.h | 10 - src/XGUI/XGUI_Workshop.cpp | 157 +--------- src/XGUI/XGUI_Workshop.h | 17 -- src/XGUI/XGUI_pictures.qrc | 4 - 33 files changed, 714 insertions(+), 666 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_IDocumentDataModel.h rename src/{XGUI/XGUI_DataTreeModel.h => PartSet/PartSet_DataTreeModel.h} (83%) rename src/{XGUI/XGUI_DocumentDataModel.cpp => PartSet/PartSet_DocumentDataModel.cpp} (64%) rename src/{XGUI/XGUI_DocumentDataModel.h => PartSet/PartSet_DocumentDataModel.h} (80%) rename src/{XGUI/XGUI_PartDataModel.cpp => PartSet/PartSet_PartDataModel.cpp} (86%) rename src/{XGUI/XGUI_PartDataModel.h => PartSet/PartSet_PartDataModel.h} (93%) rename src/{XGUI/pictures => PartSet/icons}/activate.png (100%) create mode 100644 src/PartSet/icons/deactivate.png rename src/{XGUI/pictures => PartSet/icons}/edit.png (100%) rename src/{XGUI/pictures => PartSet/icons}/exec_state_failed.png (100%) rename src/{XGUI/pictures => PartSet/icons}/exec_state_invalid_parameters.png (100%) diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 140a65d17..3b2c8a279 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -47,6 +47,7 @@ SET(PROJECT_HEADERS ModuleBase_WidgetExprEditor.h ModuleBase_ParamSpinBox.h ModuleBase_WidgetIntValue.h + ModuleBase_IDocumentDataModel.h ) SET(PROJECT_SOURCES diff --git a/src/ModuleBase/ModuleBase_IDocumentDataModel.h b/src/ModuleBase/ModuleBase_IDocumentDataModel.h new file mode 100644 index 000000000..b18866eea --- /dev/null +++ b/src/ModuleBase/ModuleBase_IDocumentDataModel.h @@ -0,0 +1,36 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: ModuleBase_IDocumentDataModel.h +// Created: 28 Apr 2015 +// Author: Vitaly SMETANNIKOV + + +#ifndef ModuleBase_IDocumentDataModel_H +#define ModuleBase_IDocumentDataModel_H + +#include "ModuleBase.h" +#include +#include + +class MODULEBASE_EXPORT ModuleBase_IDocumentDataModel : public QAbstractItemModel +{ +Q_OBJECT +public: + ModuleBase_IDocumentDataModel(QObject* theParent): QAbstractItemModel(theParent) {} + + //! Returns an object by the given Model index. + //! Returns 0 if the given index is not index of an object + virtual ObjectPtr object(const QModelIndex& theIndex) const = 0; + + //! Returns index of the object + //! \param theObject object to find + virtual QModelIndex objectIndex(const ObjectPtr theObject) const = 0; + + //! Clear internal data + virtual void clear() {} + + //! Rebuild data tree + virtual void rebuildDataTree() {} +}; + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 7ba5cfe1e..0e9b1feb0 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -23,6 +23,7 @@ class Config_WidgetAPI; class ModuleBase_ModelWidget; class ModuleBase_Operation; class ModuleBase_IWorkshop; +class ModuleBase_IDocumentDataModel; /** * \ingroup GUI @@ -78,11 +79,11 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// \param theMenu a popup menu to be shown in the viewer /// \param theStdActions a map of standard actions /// \return true if items are added and there is no necessity to provide standard menu - virtual bool addViewerItems(QMenu* theMenu, const QMap& theStdActions) const { return false; } + virtual bool addViewerMenu(QMenu* theMenu, const QMap& theStdActions) const { return false; } /// Add menu atems for object browser into the given menu /// \param theMenu a popup menu to be shown in the object browser - virtual void addObjectBrowserItems(QMenu* theMenu) const {}; + virtual void addObjectBrowserMenu(QMenu* theMenu) const {}; /// Called when it is necessary to update a command state (enable or disable it) //virtual bool isFeatureEnabled(const QString& theCmdId) const = 0; @@ -120,6 +121,9 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// \returns true if the action is processed virtual bool deleteObjects() { return false; }; + /// Returns data model object for representation of data tree in Object browser + virtual ModuleBase_IDocumentDataModel* dataModel() const = 0; + public slots: /// Called on call of command corresponded to a feature void onFeatureTriggered(); diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index b42db0d7f..5fa98fc5d 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -187,6 +188,24 @@ TopAbs_ShapeEnum shapeType(const QString& theType) return TopAbs_SHAPE; } +void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature, bool& hasParameter) +{ + hasResult = false; + hasFeature = false; + hasParameter = false; + foreach(ObjectPtr aObj, theObjects) { + FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); + ResultPtr aResult = std::dynamic_pointer_cast(aObj); + ResultParameterPtr aConstruction = std::dynamic_pointer_cast(aResult); + + hasResult = (aResult.get() != NULL); + hasFeature = (aFeature.get() != NULL); + hasParameter = (aConstruction.get() != NULL); + if (hasFeature && hasResult && hasParameter) + break; + } +} + } diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 7bb5ababf..410f01de2 100644 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -8,6 +8,7 @@ #define ModuleBase_Tools_H #include "ModuleBase.h" +#include "ModuleBase_Definitions.h" #include #include @@ -77,6 +78,14 @@ MODULEBASE_EXPORT QString objectInfo(const ObjectPtr& theObj, const bool isUseAt /// \return TopAbs_ShapeEnum value MODULEBASE_EXPORT TopAbs_ShapeEnum shapeType(const QString& theType); +/*! +Check types of objects which are in the given list +\param theObjects the list of objects +\param hasResult will be set to true if list contains Result objects +\param hasFeature will be set to true if list contains Feature objects +\param hasParameter will be set to true if list contains Parameter objects +*/ +MODULEBASE_EXPORT void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature, bool& hasParameter); } #endif diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp index cddf1a2a0..88d61de5b 100644 --- a/src/NewGeom/NewGeom_Module.cpp +++ b/src/NewGeom/NewGeom_Module.cpp @@ -506,7 +506,7 @@ void NewGeom_Module::selectionChanged() //****************************************************** void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle) { - myWorkshop->contextMenuMgr()->addViewerItems(theMenu); + myWorkshop->contextMenuMgr()->addViewerMenu(theMenu); LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle); } diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index d25419296..1b8a05bc2 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -20,6 +20,9 @@ SET(PROJECT_HEADERS PartSet_Filters.h PartSet_SketcherMgr.h PartSet_MenuMgr.h + PartSet_DocumentDataModel.h + PartSet_PartDataModel.h + PartSet_DataTreeModel.h ) SET(PROJECT_SOURCES @@ -36,6 +39,8 @@ SET(PROJECT_SOURCES PartSet_Filters.cpp PartSet_SketcherMgr.cpp PartSet_MenuMgr.cpp + PartSet_DocumentDataModel.cpp + PartSet_PartDataModel.cpp ) SET(PROJECT_RESOURCES @@ -85,6 +90,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI ${CMAKE_SOURCE_DIR}/src/SketchPlugin ${CMAKE_SOURCE_DIR}/src/SketcherPrs ${CMAKE_SOURCE_DIR}/src/FeaturesPlugin + ${CMAKE_SOURCE_DIR}/src/PartSetPlugin ${CMAKE_SOURCE_DIR}/src/GeomAPI ${CMAKE_SOURCE_DIR}/src/GeomValidators ${CMAKE_SOURCE_DIR}/src/AppElements diff --git a/src/XGUI/XGUI_DataTreeModel.h b/src/PartSet/PartSet_DataTreeModel.h similarity index 83% rename from src/XGUI/XGUI_DataTreeModel.h rename to src/PartSet/PartSet_DataTreeModel.h index fb28e59f8..cb71be87a 100644 --- a/src/XGUI/XGUI_DataTreeModel.h +++ b/src/PartSet/PartSet_DataTreeModel.h @@ -1,9 +1,9 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> -#ifndef XGUI_DataTreeModel_H -#define XGUI_DataTreeModel_H +#ifndef PartSet_DataTreeModel_H +#define PartSet_DataTreeModel_H -#include "XGUI.h" +#include "PartSet.h" #include #include @@ -12,16 +12,16 @@ #include #include -/**\class XGUI_FeaturesModel +/**\class PartSet_FeaturesModel * \ingroup GUI * \brief Abstaract class of model object which operates with features data. */ -class XGUI_EXPORT XGUI_FeaturesModel : public QAbstractItemModel +class PARTSET_EXPORT PartSet_FeaturesModel : public QAbstractItemModel { public: /// Constructor /// \param theParent a parent object - XGUI_FeaturesModel(QObject* theParent) + PartSet_FeaturesModel(QObject* theParent) : QAbstractItemModel(theParent), myItemsColor(Qt::black) { @@ -60,17 +60,17 @@ class XGUI_EXPORT XGUI_FeaturesModel : public QAbstractItemModel QColor myItemsColor; }; -/**\class XGUI_PartModel +/**\class PartSet_PartModel * \ingroup GUI * \brief Abstaract class of model object which operates with parts data. */ -class XGUI_PartModel : public XGUI_FeaturesModel +class PartSet_PartModel : public PartSet_FeaturesModel { public: /// Constructor /// \param theParent a parent object - XGUI_PartModel(QObject* theParent) - : XGUI_FeaturesModel(theParent) + PartSet_PartModel(QObject* theParent) + : PartSet_FeaturesModel(theParent) { } diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/PartSet/PartSet_DocumentDataModel.cpp similarity index 64% rename from src/XGUI/XGUI_DocumentDataModel.cpp rename to src/PartSet/PartSet_DocumentDataModel.cpp index 24434261b..2041d5cb0 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/PartSet/PartSet_DocumentDataModel.cpp @@ -1,9 +1,9 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> -#include "XGUI_DocumentDataModel.h" -#include "XGUI_PartDataModel.h" -#include "XGUI_Workshop.h" -#include "XGUI_Tools.h" +#include "PartSet_DocumentDataModel.h" +#include "PartSet_PartDataModel.h" +#include "PartSet_Module.h" +//#include "XGUI_Tools.h" #include #include @@ -16,6 +16,8 @@ #include #include +#include +#include #include #include @@ -26,28 +28,31 @@ #define ACTIVE_COLOR QColor(0,72,140) #define PASSIVE_COLOR Qt::black -XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent) - : QAbstractItemModel(theParent), - myActivePart(0) -{ - // Register in event loop - //Events_Loop* aLoop = Events_Loop::loop(); - //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED)); - //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED)); +QMap PartSet_DocumentDataModel::myIcons; + +PartSet_DocumentDataModel::PartSet_DocumentDataModel(QObject* theParent) + : ModuleBase_IDocumentDataModel(theParent), + myActivePart(0), myHistoryBackOffset(0) +{ // Create a top part of data tree model - myModel = new XGUI_TopDataModel(this); + myModel = new PartSet_TopDataModel(this); myModel->setItemsColor(ACTIVE_COLOR); + + Events_Loop* aLoop = Events_Loop::loop(); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + 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())); } -XGUI_DocumentDataModel::~XGUI_DocumentDataModel() +PartSet_DocumentDataModel::~PartSet_DocumentDataModel() { clearModelIndexes(); clearSubModels(); } -void XGUI_DocumentDataModel::processEvent(const std::shared_ptr& theMessage) +void PartSet_DocumentDataModel::processEvent(const std::shared_ptr& theMessage) { DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); @@ -69,10 +74,10 @@ void XGUI_DocumentDataModel::processEvent(const std::shared_ptr& if (aObject->groupName() == ModelAPI_ResultPart::group()) { // Update only Parts group // Add a new part int aStart = myPartModels.size(); - XGUI_PartDataModel* aModel = new XGUI_PartDataModel(this); + PartSet_PartDataModel* aModel = new PartSet_PartDataModel(this); aModel->setPartId(myPartModels.count()); myPartModels.append(aModel); - insertRow(aStart, partFolderNode()); + insertRow(aStart, partFolderNode(0)); } else { // Update top groups (other except parts QModelIndex aIndex = myModel->findParent(aObject); int aStart = myModel->rowCount(aIndex) - 1; @@ -82,8 +87,8 @@ void XGUI_DocumentDataModel::processEvent(const std::shared_ptr& insertRow(aStart, aIndex); } } else { // if sub-objects of first level nodes - XGUI_PartModel* aPartModel = 0; - foreach (XGUI_PartModel* aPart, myPartModels) { + PartSet_PartModel* aPartModel = 0; + foreach (PartSet_PartModel* aPart, myPartModels) { if (aPart->hasDocument(aDoc)) { aPartModel = aPart; break; @@ -113,7 +118,7 @@ void XGUI_DocumentDataModel::processEvent(const std::shared_ptr& int aStart = myPartModels.size() - 1; if (aStart >= 0) {// MPV: this could be reproduced on close removeSubModel(aStart); - removeRow(aStart, partFolderNode()); + removeRow(aStart, partFolderNode(0)); if (myActivePart && (!isPartSubModel(myActivePart))) { myActivePart = 0; myActivePartIndex = QModelIndex(); @@ -127,8 +132,8 @@ void XGUI_DocumentDataModel::processEvent(const std::shared_ptr& removeRow(aStart, aIndex); } } else { - XGUI_PartModel* aPartModel = 0; - foreach (XGUI_PartModel* aPart, myPartModels) { + PartSet_PartModel* aPartModel = 0; + foreach (PartSet_PartModel* aPart, myPartModels) { if (aPart->hasDocument(aDoc)) { aPartModel = aPart; break; @@ -153,12 +158,21 @@ void XGUI_DocumentDataModel::processEvent(const std::shared_ptr& emit dataChanged(aIndex, aIndex); // Reset whole tree ************************** + } else 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; + } } else { rebuildDataTree(); } } -void XGUI_DocumentDataModel::rebuildDataTree() +void PartSet_DocumentDataModel::rebuildDataTree() { DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); @@ -172,7 +186,7 @@ void XGUI_DocumentDataModel::rebuildDataTree() myPartModels.removeLast(); } while (myPartModels.size() < aNbParts) { - myPartModels.append(new XGUI_PartDataModel(this)); + myPartModels.append(new PartSet_PartDataModel(this)); } for (int i = 0; i < myPartModels.size(); i++) myPartModels.at(i)->setPartId(i); @@ -180,10 +194,23 @@ void XGUI_DocumentDataModel::rebuildDataTree() endResetModel(); } -QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) const +QVariant PartSet_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) const { if (!theIndex.isValid()) return QVariant(); + QModelIndex aParent = theIndex.parent(); + + if ((theIndex.column() == 1) ) { + if ((theIndex.internalId() == HistoryNode) && (!aParent.isValid())) { + switch (theRole) { + case Qt::DecorationRole: + if (theIndex.row() == lastHistoryRow()) + return QIcon(":pictures/arrow.png"); + } + } + return QVariant(); + } + switch (theIndex.internalId()) { case PartsFolder: switch (theRole) { @@ -195,56 +222,59 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) return tr("Parts folder"); case Qt::ForegroundRole: if (myActivePart) - return QBrush(PASSIVE_COLOR); + return QBrush(PASSIVE_COLOR); else - return QBrush(ACTIVE_COLOR); - default: - return QVariant(); - } - break; - case HistoryNode: - { - int aOffset = historyOffset(); - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - ObjectPtr aObj = aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset); - FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); - if (!aFeature) - return QVariant(); - switch (theRole) { - case Qt::DisplayRole: - if (aFeature) + return QBrush(ACTIVE_COLOR); + default: + return QVariant(); + } + break; + case HistoryNode: + { + int aOffset = historyOffset(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + ObjectPtr aObj = aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset); + FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); + if (!aFeature) + return QVariant(); + switch (theRole) { + case Qt::DisplayRole: + if (aFeature) return aFeature->data()->name().c_str(); - else + else return QVariant(); - case Qt::DecorationRole: - return XGUI_Workshop::featureIcon(aFeature); - case Qt::ToolTipRole: - return tr("Feature object"); - case Qt::ForegroundRole: + case Qt::DecorationRole: + return featureIcon(aFeature); + case Qt::ToolTipRole: + return tr("Feature object"); + case Qt::ForegroundRole: + if (theIndex.row() > lastHistoryRow()) + return QBrush(Qt::lightGray); + else { if (myActivePart) - return QBrush(PASSIVE_COLOR); + return QBrush(PASSIVE_COLOR); else - return QBrush(ACTIVE_COLOR); - default: - return QVariant(); + return QBrush(ACTIVE_COLOR); } - } - break; + default: + return QVariant(); } - QModelIndex aParent = theIndex.parent(); + } + break; + } if (aParent.isValid() && (aParent.internalId() == PartsFolder)) { return myPartModels.at(theIndex.row())->data(QModelIndex(), theRole); } return toSourceModelIndex(theIndex)->data(theRole); } -QVariant XGUI_DocumentDataModel::headerData(int theSection, Qt::Orientation theOrient, +QVariant PartSet_DocumentDataModel::headerData(int theSection, Qt::Orientation theOrient, int theRole) const { return QVariant(); } -int XGUI_DocumentDataModel::rowCount(const QModelIndex& theParent) const +int PartSet_DocumentDataModel::rowCount(const QModelIndex& theParent) const { if (!theParent.isValid()) { DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); @@ -273,12 +303,12 @@ int XGUI_DocumentDataModel::rowCount(const QModelIndex& theParent) const return aModel->rowCount(*aParent); } -int XGUI_DocumentDataModel::columnCount(const QModelIndex& theParent) const +int PartSet_DocumentDataModel::columnCount(const QModelIndex& theParent) const { return 1; } -QModelIndex XGUI_DocumentDataModel::index(int theRow, int theColumn, +QModelIndex PartSet_DocumentDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const { QModelIndex aIndex; @@ -289,7 +319,7 @@ QModelIndex XGUI_DocumentDataModel::index(int theRow, int theColumn, aIndex = createIndex(theRow, theColumn, (void*) getModelIndex(aIndex)); } else { if (theRow == aOffs) // Create Parts node - aIndex = partFolderNode(); + aIndex = partFolderNode(theColumn); else // create history node aIndex = createIndex(theRow, theColumn, HistoryNode); @@ -306,7 +336,7 @@ QModelIndex XGUI_DocumentDataModel::index(int theRow, int theColumn, return aIndex; } -QModelIndex XGUI_DocumentDataModel::parent(const QModelIndex& theIndex) const +QModelIndex PartSet_DocumentDataModel::parent(const QModelIndex& theIndex) const { if ((theIndex.internalId() == PartsFolder) || (theIndex.internalId() == HistoryNode)) return QModelIndex(); @@ -318,7 +348,7 @@ QModelIndex XGUI_DocumentDataModel::parent(const QModelIndex& theIndex) const if (isPartSubModel(aModel)) { if (!aModel->parent(*aIndex).isValid()) { - return partFolderNode(); + return partFolderNode(theIndex.column()); } } @@ -328,20 +358,20 @@ QModelIndex XGUI_DocumentDataModel::parent(const QModelIndex& theIndex) const return aIndex1; } -bool XGUI_DocumentDataModel::hasChildren(const QModelIndex& theParent) const +bool PartSet_DocumentDataModel::hasChildren(const QModelIndex& theParent) const { if (!theParent.isValid()) return true; return rowCount(theParent) > 0; } -QModelIndex* XGUI_DocumentDataModel::toSourceModelIndex(const QModelIndex& theProxy) const +QModelIndex* PartSet_DocumentDataModel::toSourceModelIndex(const QModelIndex& theProxy) const { QModelIndex* aIndexPtr = static_cast(theProxy.internalPointer()); return aIndexPtr; } -QModelIndex* XGUI_DocumentDataModel::findModelIndex(const QModelIndex& theIndex) const +QModelIndex* PartSet_DocumentDataModel::findModelIndex(const QModelIndex& theIndex) const { QList::const_iterator aIt; for (aIt = myIndexes.constBegin(); aIt != myIndexes.constEnd(); ++aIt) { @@ -352,32 +382,32 @@ QModelIndex* XGUI_DocumentDataModel::findModelIndex(const QModelIndex& theIndex) return 0; } -QModelIndex* XGUI_DocumentDataModel::getModelIndex(const QModelIndex& theIndex) const +QModelIndex* PartSet_DocumentDataModel::getModelIndex(const QModelIndex& theIndex) const { QModelIndex* aIndexPtr = findModelIndex(theIndex); if (!aIndexPtr) { aIndexPtr = new QModelIndex(theIndex); - XGUI_DocumentDataModel* that = (XGUI_DocumentDataModel*) this; + PartSet_DocumentDataModel* that = (PartSet_DocumentDataModel*) this; that->myIndexes.append(aIndexPtr); } return aIndexPtr; } -void XGUI_DocumentDataModel::clearModelIndexes() +void PartSet_DocumentDataModel::clearModelIndexes() { foreach (QModelIndex* aIndex, myIndexes) delete aIndex; myIndexes.clear(); } -void XGUI_DocumentDataModel::clearSubModels() +void PartSet_DocumentDataModel::clearSubModels() { - foreach (XGUI_PartModel* aPart, myPartModels) + foreach (PartSet_PartModel* aPart, myPartModels) delete aPart; myPartModels.clear(); } -ObjectPtr XGUI_DocumentDataModel::object(const QModelIndex& theIndex) const +ObjectPtr PartSet_DocumentDataModel::object(const QModelIndex& theIndex) const { if (theIndex.internalId() == PartsFolder) return ObjectPtr(); @@ -390,11 +420,11 @@ ObjectPtr XGUI_DocumentDataModel::object(const QModelIndex& theIndex) const if (!isSubModel(aIndex->model())) return ObjectPtr(); - const XGUI_FeaturesModel* aModel = dynamic_cast(aIndex->model()); + const PartSet_FeaturesModel* aModel = dynamic_cast(aIndex->model()); return aModel->object(*aIndex); } -bool XGUI_DocumentDataModel::insertRows(int theRow, int theCount, const QModelIndex& theParent) +bool PartSet_DocumentDataModel::insertRows(int theRow, int theCount, const QModelIndex& theParent) { beginInsertRows(theParent, theRow, theRow + theCount - 1); //endInsertRows(); @@ -408,16 +438,16 @@ bool XGUI_DocumentDataModel::insertRows(int theRow, int theCount, const QModelIn return true; } -bool XGUI_DocumentDataModel::removeRows(int theRow, int theCount, const QModelIndex& theParent) +bool PartSet_DocumentDataModel::removeRows(int theRow, int theCount, const QModelIndex& theParent) { beginRemoveRows(theParent, theRow, theRow + theCount - 1); endRemoveRows(); return true; } -void XGUI_DocumentDataModel::removeSubModel(int theModelId) +void PartSet_DocumentDataModel::removeSubModel(int theModelId) { - XGUI_PartModel* aModel = myPartModels.at(theModelId); + PartSet_PartModel* aModel = myPartModels.at(theModelId); QIntList aToRemove; for (int i = 0; i < myIndexes.size(); i++) { if (myIndexes.at(i)->model() == aModel) @@ -434,31 +464,31 @@ void XGUI_DocumentDataModel::removeSubModel(int theModelId) myPartModels.removeAt(theModelId); } -bool XGUI_DocumentDataModel::isSubModel(const QAbstractItemModel* theModel) const +bool PartSet_DocumentDataModel::isSubModel(const QAbstractItemModel* theModel) const { if (theModel == myModel) return true; return isPartSubModel(theModel); } -bool XGUI_DocumentDataModel::isPartSubModel(const QAbstractItemModel* theModel) const +bool PartSet_DocumentDataModel::isPartSubModel(const QAbstractItemModel* theModel) const { - return myPartModels.contains((XGUI_PartModel*) theModel); + return myPartModels.contains((PartSet_PartModel*) theModel); } -QModelIndex XGUI_DocumentDataModel::partFolderNode() const +QModelIndex PartSet_DocumentDataModel::partFolderNode(int theColumn) const { int aPos = myModel->rowCount(QModelIndex()); - return createIndex(aPos, columnCount() - 1, PartsFolder); + return createIndex(aPos, theColumn, PartsFolder); } -int XGUI_DocumentDataModel::historyOffset() const +int PartSet_DocumentDataModel::historyOffset() const { // Nb of rows of top model + Parts folder return myModel->rowCount(QModelIndex()) + 1; } -bool XGUI_DocumentDataModel::activatedIndex(const QModelIndex& theIndex) +bool PartSet_DocumentDataModel::activatePart(const QModelIndex& theIndex) { if ((theIndex.internalId() == PartsFolder) || (theIndex.internalId() == HistoryNode)) return false; @@ -479,7 +509,7 @@ bool XGUI_DocumentDataModel::activatedIndex(const QModelIndex& theIndex) myActivePart = 0; myActivePartIndex = QModelIndex(); } else { - myActivePart = (XGUI_PartModel*)aModel; + myActivePart = (PartSet_PartModel*)aModel; myActivePartIndex = theIndex; } @@ -494,14 +524,14 @@ bool XGUI_DocumentDataModel::activatedIndex(const QModelIndex& theIndex) return false; } -ResultPartPtr XGUI_DocumentDataModel::activePart() const +ResultPartPtr PartSet_DocumentDataModel::activePart() const { if (myActivePart) return myActivePart->part(); return ResultPartPtr(); } -void XGUI_DocumentDataModel::deactivatePart() +void PartSet_DocumentDataModel::deactivatePart() { if (myActivePart) myActivePart->setItemsColor(PASSIVE_COLOR); @@ -510,20 +540,25 @@ void XGUI_DocumentDataModel::deactivatePart() myModel->setItemsColor(ACTIVE_COLOR); } -Qt::ItemFlags XGUI_DocumentDataModel::flags(const QModelIndex& theIndex) const +Qt::ItemFlags PartSet_DocumentDataModel::flags(const QModelIndex& theIndex) const { - Qt::ItemFlags aFlags = QAbstractItemModel::flags(theIndex); + Qt::ItemFlags aFlags = QAbstractItemModel::flags(theIndex); //Qt::ItemIsSelectable; if (object(theIndex)) { aFlags |= Qt::ItemIsEditable; } + // Disable items which are below of last history row + // Do not disable second column + //if (theIndex.row() <= lastHistoryRow() || theIndex.column() == 1) { + // aFlags |= Qt::ItemIsEnabled; + //} return aFlags; } -QModelIndex XGUI_DocumentDataModel::partIndex(const ResultPartPtr& theObject) const +QModelIndex PartSet_DocumentDataModel::partIndex(const ResultPartPtr& theObject) const { int aRow = -1; - XGUI_PartModel* aModel = 0; - foreach (XGUI_PartModel* aPartModel, myPartModels) + PartSet_PartModel* aModel = 0; + foreach (PartSet_PartModel* aPartModel, myPartModels) { aRow++; if (aPartModel->part() == theObject) { @@ -537,7 +572,7 @@ QModelIndex XGUI_DocumentDataModel::partIndex(const ResultPartPtr& theObject) co return QModelIndex(); } -QModelIndex XGUI_DocumentDataModel::objectIndex(const ObjectPtr theObject) const +QModelIndex PartSet_DocumentDataModel::objectIndex(const ObjectPtr theObject) const { // Check that this feature belongs to root document DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); @@ -562,8 +597,8 @@ QModelIndex XGUI_DocumentDataModel::objectIndex(const ObjectPtr theObject) const QModelIndex(); } } else { - XGUI_PartModel* aPartModel = 0; - foreach(XGUI_PartModel* aModel, myPartModels) + PartSet_PartModel* aPartModel = 0; + foreach(PartSet_PartModel* aModel, myPartModels) { if (aModel->hasDocument(aDoc)) { aPartModel = aModel; @@ -582,7 +617,7 @@ QModelIndex XGUI_DocumentDataModel::objectIndex(const ObjectPtr theObject) const } -void XGUI_DocumentDataModel::clear() +void PartSet_DocumentDataModel::clear() { clearModelIndexes(); clearSubModels(); @@ -590,3 +625,58 @@ void XGUI_DocumentDataModel::clear() myActivePartIndex = QModelIndex(); myModel->setItemsColor(ACTIVE_COLOR); } + +int PartSet_DocumentDataModel::lastHistoryRow() const +{ + return rowCount() - 1 - myHistoryBackOffset; +} + +void PartSet_DocumentDataModel::setLastHistoryItem(const QModelIndex& theIndex) +{ + if (theIndex.internalId() == HistoryNode) { + myHistoryBackOffset = rowCount() - 1 - theIndex.row(); + } +} + +QModelIndex PartSet_DocumentDataModel::lastHistoryItem() const +{ + return index(lastHistoryRow(), 1); +} + + +QIcon PartSet_DocumentDataModel::featureIcon(const FeaturePtr& theFeature) +{ + QIcon anIcon; + + std::string aKind = theFeature->getKind(); + QString aId(aKind.c_str()); + if (!myIcons.contains(aId)) + return anIcon; + + QString anIconString = myIcons[aId]; + + ModelAPI_ExecState aState = theFeature->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; + } + return anIcon; +} + diff --git a/src/XGUI/XGUI_DocumentDataModel.h b/src/PartSet/PartSet_DocumentDataModel.h similarity index 80% rename from src/XGUI/XGUI_DocumentDataModel.h rename to src/PartSet/PartSet_DocumentDataModel.h index 63fa17a9f..942d157ba 100644 --- a/src/XGUI/XGUI_DocumentDataModel.h +++ b/src/PartSet/PartSet_DocumentDataModel.h @@ -1,34 +1,34 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> -#ifndef XGUI_DocumentDataModel_H -#define XGUI_DocumentDataModel_H +#ifndef PartSet_DocumentDataModel_H +#define PartSet_DocumentDataModel_H -#include "XGUI.h" +#include "PartSet.h" #include #include +#include +#include #include - -#include #include class ModelAPI_Document; -class XGUI_PartModel; -class XGUI_TopDataModel; +class PartSet_PartModel; +class PartSet_TopDataModel; -/**\class XGUI_DocumentDataModel +/**\class PartSet_DocumentDataModel * \ingroup GUI * \brief This is a proxy data model for Object Browser (QTreeView). * It contains several sub-models for generation of each sub-part of data tree. */ -class XGUI_EXPORT XGUI_DocumentDataModel : public QAbstractItemModel, public Events_Listener +class PARTSET_EXPORT PartSet_DocumentDataModel : public ModuleBase_IDocumentDataModel, public Events_Listener { Q_OBJECT public: /// Constructor /// \param theParent a parent object - XGUI_DocumentDataModel(QObject* theParent); - virtual ~XGUI_DocumentDataModel(); + PartSet_DocumentDataModel(QObject* theParent); + virtual ~PartSet_DocumentDataModel(); /// Event Listener method /// \param theMessage an event message @@ -87,15 +87,15 @@ Q_OBJECT /// Returns the item flags for the given index. /// \param theIndex a model index - Qt::ItemFlags flags(const QModelIndex& theIndex) const; + virtual Qt::ItemFlags flags(const QModelIndex& theIndex) const; //! Returns an object by the given Model index. //! Returns 0 if the given index is not index of an object - ObjectPtr object(const QModelIndex& theIndex) const; + virtual ObjectPtr object(const QModelIndex& theIndex) const; //! Returns index of the object //! \param theObject object to find - QModelIndex objectIndex(const ObjectPtr theObject) const; + virtual QModelIndex objectIndex(const ObjectPtr theObject) const; //! Returns QModelIndex which corresponds to the given part //! If the object is not found then index is not valid @@ -105,7 +105,7 @@ Q_OBJECT //! Activates a part data model if the index is a Part node index. //! Returns true if active part changed. //! \param theIndex a model index - bool activatedIndex(const QModelIndex& theIndex); + bool activatePart(const QModelIndex& theIndex); //! Retrurns active part ResultPartPtr activePart() const; @@ -120,11 +120,19 @@ Q_OBJECT void deactivatePart(); //! Rebuild data tree - void rebuildDataTree(); + virtual void rebuildDataTree(); //! Clear internal data - void clear(); + virtual void clear(); + + //! Set an Index which will be considered as a last history index + //! \param theIndex a last index for history + void setLastHistoryItem(const QModelIndex& theIndex); + + QModelIndex lastHistoryItem() const; + //! Returns icon name according to feature + static QIcon featureIcon(const FeaturePtr& theFeature); private: @@ -159,24 +167,30 @@ Q_OBJECT bool isPartSubModel(const QAbstractItemModel* theModel) const; //! Returns Parts Folder node - QModelIndex partFolderNode() const; + //! \param theColumn an Id of column + QModelIndex partFolderNode(int theColumn) const; + + int lastHistoryRow() const; int historyOffset() const; //! Data model of top part of data tree (not parts object) - XGUI_TopDataModel* myModel; + PartSet_TopDataModel* myModel; //! Data models for Parts data tree representation (one data model per a one part) - QList myPartModels; + QList myPartModels; //! Active part in part editing mode - XGUI_PartModel* myActivePart; + PartSet_PartModel* myActivePart; QModelIndex myActivePartIndex; //! List of saved QModelIndexes created by sub-models QList myIndexes; + int myHistoryBackOffset; + + static QMap myIcons; }; #endif diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index 42f95fb33..e453a5525 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include @@ -60,11 +62,28 @@ void PartSet_MenuMgr::addAction(const QString& theId, QAction* theAction) void PartSet_MenuMgr::createActions() { - QAction* anAction; + QAction* aAction; - anAction = new QAction(tr("Auxiliary"), this); - anAction->setCheckable(true); - addAction("AUXILIARY_CMD", anAction); + aAction = new QAction(tr("Auxiliary"), this); + aAction->setCheckable(true); + addAction("AUXILIARY_CMD", aAction); + + aAction = new QAction(QIcon(":icons/activate.png"), tr("Activate"), this); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onActivatePart(bool))); + myActions["ACTIVATE_PART_CMD"] = aAction; + + aAction = new QAction(QIcon(":icons/deactivate.png"), tr("Deactivate"), this); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onActivatePartSet(bool))); + myActions["DEACTIVATE_PART_CMD"] = aAction; + + // Activate PartSet + aAction = new QAction(QIcon(":icons/activate.png"), tr("Activate"), this); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onActivatePartSet(bool))); + myActions["ACTIVATE_PARTSET_CMD"] = aAction; + + aAction = new QAction(QIcon(":icons/edit.png"), tr("Edit..."), this); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onEdit(bool))); + myActions["EDIT_CMD"] = aAction; } @@ -137,7 +156,7 @@ void findCoincidences(FeaturePtr theStartCoin, QList& theList, std:: } -bool PartSet_MenuMgr::addViewerItems(QMenu* theMenu, const QMap& theStdActions) const +bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap& theStdActions) const { ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation(); if (!PartSet_SketcherMgr::isSketchOperation(anOperation) && @@ -446,3 +465,35 @@ bool PartSet_MenuMgr::canSetAuxiliary(bool& theValue) const theValue = anObjects.size() && !isNotAuxiliaryFound; return anEnabled; } + +void PartSet_MenuMgr::onActivatePart(bool) +{ + QObjectPtrList aObjects = myModule->workshop()->selection()->selectedObjects(); + if (aObjects.size() > 0) { + ResultPartPtr aPart = std::dynamic_pointer_cast(aObjects.first()); + if (aPart) { + aPart->activate(); + } + } +} + +void PartSet_MenuMgr::onActivatePartSet(bool) +{ + SessionPtr aMgr = ModelAPI_Session::get(); + aMgr->setActiveDocument(aMgr->moduleDocument()); +} + +void PartSet_MenuMgr::onEdit(bool) +{ + QObjectPtrList aObjects = myModule->workshop()->selection()->selectedObjects(); + FeaturePtr aFeature = std::dynamic_pointer_cast(aObjects.first()); + if (aFeature == NULL) { + ResultParameterPtr aParam = + std::dynamic_pointer_cast(aObjects.first()); + if (aParam.get() != NULL) { + aFeature = ModelAPI_Feature::feature(aParam); + } + } + if (aFeature.get() != NULL) + myModule->editFeature(aFeature); +} diff --git a/src/PartSet/PartSet_MenuMgr.h b/src/PartSet/PartSet_MenuMgr.h index 117098644..93f545360 100644 --- a/src/PartSet/PartSet_MenuMgr.h +++ b/src/PartSet/PartSet_MenuMgr.h @@ -40,7 +40,7 @@ public: /// \param theMenu a popup menu to be shown in the viewer /// \param theStdActions a map of standard actions /// \return true if items are added and there is no necessity to provide standard menu - bool addViewerItems(QMenu* theMenu, const QMap& theStdActions) const; + bool addViewerMenu(QMenu* theMenu, const QMap& theStdActions) const; public slots: /// Processes the context menu action click @@ -60,6 +60,15 @@ private slots: /// \param theAction an action of the selected item void onLineDetach(QAction* theAction); + /// A slot called on Part activation command + void onActivatePart(bool); + + /// A slot called on PartSet activation command + void onActivatePartSet(bool); + + /// A slot called on edit of feature + void onEdit(bool); + private: /// Returns true if the current operation is sketch entity create operation /// \param theValue the current auxiliary value diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 7ae10661d..9077aaaff 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1,16 +1,20 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D #include "PartSet_Module.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include "PartSet_WidgetSketchLabel.h" +#include "PartSet_Validators.h" +#include "PartSet_Tools.h" +#include "PartSet_WidgetPoint2d.h" +#include "PartSet_WidgetPoint2dDistance.h" +#include "PartSet_WidgetShapeSelector.h" +#include "PartSet_WidgetMultiSelector.h" +#include "PartSet_WidgetEditor.h" #include "PartSet_SketcherMgr.h" #include "PartSet_MenuMgr.h" +#include "PartSet_DocumentDataModel.h" + +#include +#include #include #include @@ -18,6 +22,8 @@ #include #include #include +#include + #include #include #include @@ -42,6 +48,7 @@ #include #include #include +#include #include #include @@ -76,6 +83,7 @@ #include #include #include +#include #include #include @@ -84,6 +92,8 @@ #include #endif + + /*!Create and return new instance of XGUI_Module*/ extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop) { @@ -91,10 +101,11 @@ extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* } PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) - : ModuleBase_IModule(theWshop), + : ModuleBase_IModule(theWshop), myRestartingMode(RM_None), myVisualLayerId(0) { mySketchMgr = new PartSet_SketcherMgr(this); + myDataModel = new PartSet_DocumentDataModel(this); XGUI_ModuleConnector* aConnector = dynamic_cast(theWshop); XGUI_Workshop* aWorkshop = aConnector->workshop(); @@ -111,6 +122,9 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) SLOT(onViewTransformed(int))); myMenuMgr = new PartSet_MenuMgr(this); + + Events_Loop* aLoop = Events_Loop::loop(); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED)); } PartSet_Module::~PartSet_Module() @@ -283,9 +297,9 @@ bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const } -bool PartSet_Module::addViewerItems(QMenu* theMenu, const QMap& theStdActions) const +bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap& theStdActions) const { - return myMenuMgr->addViewerItems(theMenu, theStdActions); + return myMenuMgr->addViewerMenu(theMenu, theStdActions); } bool PartSet_Module::isMouseOverWindow() @@ -478,60 +492,73 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th bool PartSet_Module::deleteObjects() { + SessionPtr aMgr = ModelAPI_Session::get(); // 1. check whether the delete should be processed in the module ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation), isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation); - if (!isSketchOp && !isNestedOp) - return false; - - // 2. find selected presentations - // selected objects should be collected before the current operation abort because - // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue - XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); - XGUI_Workshop* aWorkshop = aConnector->workshop(); - ModuleBase_ISelection* aSel = workshop()->selection(); - QObjectPtrList aSelectedObj = aSel->selectedPresentations(); - // if there are no selected objects in the viewer, that means that the selection in another - // place cased this method. It is necessary to return the false value to understande in above - // method that delete is not processed - if (aSelectedObj.count() == 0) - return false; - - // avoid delete of the objects, which are not belong to the current sketch - // in order to do not delete results of other sketches - QObjectPtrList aSketchObjects; - QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end(); - for ( ; anIt != aLast; anIt++) { - ObjectPtr anObject = *anIt; - if (mySketchMgr->isObjectOfSketch(anObject)) - aSketchObjects.append(anObject); - } - // if the selection contains only local selected presentations from other sketches, - // the Delete operation should not be done at all - if (aSketchObjects.size() == 0) - return true; - - // the active nested sketch operation should be aborted unconditionally - if (isNestedOp) - anOperation->abort(); - - // 3. start operation - QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text(); - SessionPtr aMgr = ModelAPI_Session::get(); - aMgr->startOperation(aDescription.toStdString()); - - // 4. delete features - // sketch feature should be skipped, only sub-features can be removed - // when sketch operation is active - std::set anIgnoredFeatures; - anIgnoredFeatures.insert(mySketchMgr->activeSketch()); - aWorkshop->deleteFeatures(aSketchObjects, anIgnoredFeatures); + if (isSketchOp && isNestedOp) { + // 2. find selected presentations + // selected objects should be collected before the current operation abort because + // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue + XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + ModuleBase_ISelection* aSel = workshop()->selection(); + QObjectPtrList aSelectedObj = aSel->selectedPresentations(); + // if there are no selected objects in the viewer, that means that the selection in another + // place cased this method. It is necessary to return the false value to understande in above + // method that delete is not processed + if (aSelectedObj.count() == 0) + return false; + + // avoid delete of the objects, which are not belong to the current sketch + // in order to do not delete results of other sketches + QObjectPtrList aSketchObjects; + QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end(); + for ( ; anIt != aLast; anIt++) { + ObjectPtr anObject = *anIt; + if (mySketchMgr->isObjectOfSketch(anObject)) + aSketchObjects.append(anObject); + } + // if the selection contains only local selected presentations from other sketches, + // the Delete operation should not be done at all + if (aSketchObjects.size() == 0) + return true; + + // the active nested sketch operation should be aborted unconditionally + if (isNestedOp) + anOperation->abort(); + + // 3. start operation + QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text(); + aMgr->startOperation(aDescription.toStdString()); + + // 4. delete features + // sketch feature should be skipped, only sub-features can be removed + // when sketch operation is active + std::set anIgnoredFeatures; + anIgnoredFeatures.insert(mySketchMgr->activeSketch()); + aWorkshop->deleteFeatures(aSketchObjects, anIgnoredFeatures); - // 5. stop operation - aWorkshop->displayer()->updateViewer(); - aMgr->finishOperation(); - + // 5. stop operation + aWorkshop->displayer()->updateViewer(); + aMgr->finishOperation(); + } else { + // Delete part with help of PartSet plugin + // TODO: the deleted objects has to be processed by multiselection + QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects(); + if (aObjects.size() == 1) { + ObjectPtr aObj = aObjects.first(); + FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); + if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) { + std::shared_ptr aDoc = aMgr->activeDocument(); + aMgr->startOperation(PartSetPlugin_Remove::ID()); + FeaturePtr aFeature = aDoc->addFeature(PartSetPlugin_Remove::ID()); + aFeature->execute(); + aMgr->finishOperation(); + } + } + } return true; } @@ -600,3 +627,79 @@ void PartSet_Module::onViewTransformed(int theTrsfType) if (isModified) aDisplayer->updateViewer(); } + +ModuleBase_IDocumentDataModel* PartSet_Module::dataModel() const +{ + return myDataModel; +} + + +void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const +{ + QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects(); + int aSelected = aObjects.size(); + if (aSelected == 1) { + bool hasResult = false; + bool hasFeature = false; + bool hasParameter = false; + ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter); + + SessionPtr aMgr = ModelAPI_Session::get(); + ObjectPtr aObject = aObjects.first(); + if (aObject) { + ResultPartPtr aPart = std::dynamic_pointer_cast(aObject); + if (aPart) { + if (aMgr->activeDocument() == aPart->partDoc()) + theMenu->addAction(myMenuMgr->action("DEACTIVATE_PART_CMD")); + else + theMenu->addAction(myMenuMgr->action("ACTIVATE_PART_CMD")); + } else if (aObject->document() == aMgr->activeDocument()) { + if (hasParameter || hasFeature) + theMenu->addAction(myMenuMgr->action("EDIT_CMD")); + } + } else { // If feature is 0 the it means that selected root object (document) + if (aMgr->activeDocument() != aMgr->moduleDocument()) + theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD")); + } + } +} + +void PartSet_Module::processEvent(const std::shared_ptr& theMessage) +{ + if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) { + XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView(); + QLineEdit* aLabel = aWorkshop->objectBrowser()->activeDocLabel(); + QPalette aPalet = aLabel->palette(); + + SessionPtr aMgr = ModelAPI_Session::get(); + DocumentPtr aActiveDoc = aMgr->activeDocument(); + DocumentPtr aDoc = aMgr->moduleDocument(); + QModelIndex aOldIndex = myDataModel->activePartIndex(); + if (aActiveDoc == aDoc) { + if (aOldIndex.isValid()) + aTreeView->setExpanded(aOldIndex, false); + myDataModel->deactivatePart(); + aPalet.setColor(QPalette::Text, QColor(0, 72, 140)); + } else { + std::string aGrpName = ModelAPI_ResultPart::group(); + for (int i = 0; i < aDoc->size(aGrpName); i++) { + ResultPartPtr aPart = std::dynamic_pointer_cast(aDoc->object(aGrpName, i)); + if (aPart->partDoc() == aActiveDoc) { + QModelIndex aIndex = myDataModel->partIndex(aPart); + if ((aOldIndex != aIndex) && aOldIndex.isValid()) { + aTreeView->setExpanded(aOldIndex, false); + } + if (myDataModel->activatePart(aIndex)) { + aTreeView->setExpanded(aIndex.parent(), true); + aTreeView->setExpanded(aIndex, true); + aPalet.setColor(QPalette::Text, Qt::black); + } + break; + } + } + } + aLabel->setPalette(aPalet); + } +} \ No newline at end of file diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 3120798c6..fc41521cd 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -12,6 +12,8 @@ #include #include +#include + //#include #include @@ -27,6 +29,7 @@ class ModuleBase_Operation; class ModuleBase_IViewWindow; class PartSet_MenuMgr; class PartSet_SketcherMgr; +class PartSet_DocumentDataModel; class QAction; @@ -34,7 +37,7 @@ class QAction; * \ingroup Modules * Implementation of Partset module */ -class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule +class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener { Q_OBJECT @@ -47,6 +50,7 @@ enum RestartingMode { }; public: + /// Constructor /// \param theWshop a pointer to a workshop PartSet_Module(ModuleBase_IWorkshop* theWshop); @@ -97,11 +101,15 @@ public: /// \param theObject a model object virtual bool canDisplayObject(const ObjectPtr& theObject) const; + /// Add menu atems for object browser into the given menu + /// \param theMenu a popup menu to be shown in the object browser + virtual void addObjectBrowserMenu(QMenu* theMenu) const; + /// Add menu atems for viewer into the given menu /// \param theMenu a popup menu to be shown in the viewer /// \param theStdActions a map of standard actions /// \return true if items are added and there is no necessity to provide standard menu - virtual bool addViewerItems(QMenu* theMenu, const QMap& theStdActions) const; + virtual bool addViewerMenu(QMenu* theMenu, const QMap& theStdActions) const; /// Returns whether the mouse enter the viewer's window /// \return true if items are added and there is no necessity to provide standard menu @@ -109,6 +117,13 @@ public: PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; } + /// Returns data model object for representation of data tree in Object browser + virtual ModuleBase_IDocumentDataModel* dataModel() const; + + /// Event Listener method + /// \param theMessage an event message + virtual void processEvent(const std::shared_ptr& theMessage); + public slots: /// SLOT, that is called by no more widget signal emitted by property panel /// Set a specific flag to restart the sketcher operation @@ -150,6 +165,10 @@ protected slots: /// \param theOperation the operation virtual void sendOperation(ModuleBase_Operation* theOperation); + //! Activates or deactivates a part + //! If PartPtr is Null pointer then PartSet will be activated + //void activatePart(std::shared_ptr theFeature); + private slots: /// Processing of vertex selected void onVertexSelected(); @@ -180,6 +199,8 @@ protected slots: PartSet_MenuMgr* myMenuMgr; int myVisualLayerId; + + PartSet_DocumentDataModel* myDataModel; }; #endif diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/PartSet/PartSet_PartDataModel.cpp similarity index 86% rename from src/XGUI/XGUI_PartDataModel.cpp rename to src/PartSet/PartSet_PartDataModel.cpp index bbf0ef9fc..21896e81a 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/PartSet/PartSet_PartDataModel.cpp @@ -1,7 +1,8 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> -#include "XGUI_PartDataModel.h" -#include "XGUI_Workshop.h" +#include "PartSet_PartDataModel.h" +#include "PartSet_Module.h" +#include "PartSet_DocumentDataModel.h" #include #include @@ -20,24 +21,17 @@ #include #include -//ObjectPtr featureObj(const ObjectPtr& theFeature) -//{ -// ObjectPtr aObject = std::dynamic_pointer_cast(theFeature); -// if (aObject) -// return aObject->featureRef(); -// return theFeature; -//} -XGUI_TopDataModel::XGUI_TopDataModel(QObject* theParent) - : XGUI_FeaturesModel(theParent) +PartSet_TopDataModel::PartSet_TopDataModel(QObject* theParent) + : PartSet_FeaturesModel(theParent) { } -XGUI_TopDataModel::~XGUI_TopDataModel() +PartSet_TopDataModel::~PartSet_TopDataModel() { } -QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const +QVariant PartSet_TopDataModel::data(const QModelIndex& theIndex, int theRole) const { switch (theRole) { case Qt::DisplayRole: @@ -106,12 +100,12 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const return QVariant(); } -QVariant XGUI_TopDataModel::headerData(int section, Qt::Orientation orientation, int role) const +QVariant PartSet_TopDataModel::headerData(int section, Qt::Orientation orientation, int role) const { return QVariant(); } -int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const +int PartSet_TopDataModel::rowCount(const QModelIndex& theParent) const { if (!theParent.isValid()) return 2; // In case of groups using it has to be +1 @@ -129,12 +123,12 @@ int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const return 0; } -int XGUI_TopDataModel::columnCount(const QModelIndex &parent) const +int PartSet_TopDataModel::columnCount(const QModelIndex &parent) const { return 1; } -QModelIndex XGUI_TopDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const +QModelIndex PartSet_TopDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const { if (!theParent.isValid()) { switch (theRow) { @@ -158,7 +152,7 @@ QModelIndex XGUI_TopDataModel::index(int theRow, int theColumn, const QModelInde return QModelIndex(); } -QModelIndex XGUI_TopDataModel::parent(const QModelIndex& theIndex) const +QModelIndex PartSet_TopDataModel::parent(const QModelIndex& theIndex) const { int aId = (int) theIndex.internalId(); switch (aId) { @@ -176,12 +170,12 @@ QModelIndex XGUI_TopDataModel::parent(const QModelIndex& theIndex) const return QModelIndex(); } -bool XGUI_TopDataModel::hasChildren(const QModelIndex& theParent) const +bool PartSet_TopDataModel::hasChildren(const QModelIndex& theParent) const { return rowCount(theParent) > 0; } -ObjectPtr XGUI_TopDataModel::object(const QModelIndex& theIndex) const +ObjectPtr PartSet_TopDataModel::object(const QModelIndex& theIndex) const { switch (theIndex.internalId()) { case ParamsFolder: @@ -203,12 +197,12 @@ ObjectPtr XGUI_TopDataModel::object(const QModelIndex& theIndex) const return ObjectPtr(); } -QModelIndex XGUI_TopDataModel::findParent(const ObjectPtr& theObject) const +QModelIndex PartSet_TopDataModel::findParent(const ObjectPtr& theObject) const { return findGroup(theObject->groupName().c_str()); } -QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const +QModelIndex PartSet_TopDataModel::findGroup(const std::string& theGroup) const { if (theGroup == ModelAPI_ResultParameter::group()) return createIndex(0, 0, (qint32) ParamsFolder); @@ -219,7 +213,7 @@ QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const return QModelIndex(); } -QModelIndex XGUI_TopDataModel::objectIndex(const ObjectPtr& theObject) const +QModelIndex PartSet_TopDataModel::objectIndex(const ObjectPtr& theObject) const { QModelIndex aIndex; if (theObject) { @@ -248,16 +242,16 @@ QModelIndex XGUI_TopDataModel::objectIndex(const ObjectPtr& theObject) const //****************************************************************** //****************************************************************** //****************************************************************** -XGUI_PartDataModel::XGUI_PartDataModel(QObject* theParent) - : XGUI_PartModel(theParent) +PartSet_PartDataModel::PartSet_PartDataModel(QObject* theParent) + : PartSet_PartModel(theParent) { } -XGUI_PartDataModel::~XGUI_PartDataModel() +PartSet_PartDataModel::~PartSet_PartDataModel() { } -QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) const +QVariant PartSet_PartDataModel::data(const QModelIndex& theIndex, int theRole) const { switch (theRole) { case Qt::DisplayRole: @@ -342,7 +336,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber()); FeaturePtr aFeature = std::dynamic_pointer_cast(aObject); if (aFeature) - return XGUI_Workshop::featureIcon(aFeature); + return PartSet_DocumentDataModel::featureIcon(aFeature); } } break; @@ -356,12 +350,12 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons return QVariant(); } -QVariant XGUI_PartDataModel::headerData(int section, Qt::Orientation orientation, int role) const +QVariant PartSet_PartDataModel::headerData(int section, Qt::Orientation orientation, int role) const { return QVariant(); } -int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const +int PartSet_PartDataModel::rowCount(const QModelIndex& parent) const { if (!parent.isValid()) { DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); @@ -391,12 +385,12 @@ int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const return 0; } -int XGUI_PartDataModel::columnCount(const QModelIndex &parent) const +int PartSet_PartDataModel::columnCount(const QModelIndex &parent) const { return 1; } -QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const +QModelIndex PartSet_PartDataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const { if (!theParent.isValid()) return createIndex(theRow, 0, (qint32) MyRoot); @@ -434,7 +428,7 @@ QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelInd return QModelIndex(); } -QModelIndex XGUI_PartDataModel::parent(const QModelIndex& theIndex) const +QModelIndex PartSet_PartDataModel::parent(const QModelIndex& theIndex) const { switch (theIndex.internalId()) { case MyRoot: @@ -458,12 +452,12 @@ QModelIndex XGUI_PartDataModel::parent(const QModelIndex& theIndex) const return QModelIndex(); } -bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const +bool PartSet_PartDataModel::hasChildren(const QModelIndex& theParent) const { return rowCount(theParent) > 0; } -DocumentPtr XGUI_PartDataModel::partDocument() const +DocumentPtr PartSet_PartDataModel::partDocument() const { DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId); @@ -473,7 +467,7 @@ DocumentPtr XGUI_PartDataModel::partDocument() const return DocumentPtr(); // null if not found } -ObjectPtr XGUI_PartDataModel::object(const QModelIndex& theIndex) const +ObjectPtr PartSet_PartDataModel::object(const QModelIndex& theIndex) const { switch (theIndex.internalId()) { case MyRoot: { @@ -500,17 +494,17 @@ ObjectPtr XGUI_PartDataModel::object(const QModelIndex& theIndex) const return ObjectPtr(); } -bool XGUI_PartDataModel::hasDocument(const DocumentPtr& theDoc) const +bool PartSet_PartDataModel::hasDocument(const DocumentPtr& theDoc) const { return (partDocument() == theDoc); } -QModelIndex XGUI_PartDataModel::findParent(const ObjectPtr& theObject) const +QModelIndex PartSet_PartDataModel::findParent(const ObjectPtr& theObject) const { return findGroup(theObject->groupName().c_str()); } -QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const +QModelIndex PartSet_PartDataModel::findGroup(const std::string& theGroup) const { if (theGroup == ModelAPI_ResultParameter::group()) return createIndex(0, 0, (qint32) ParamsFolder); @@ -523,14 +517,14 @@ QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const return QModelIndex(); } -ResultPartPtr XGUI_PartDataModel::part() const +ResultPartPtr PartSet_PartDataModel::part() const { DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); ObjectPtr aObj = aRootDoc->object(ModelAPI_ResultPart::group(), myId); return std::dynamic_pointer_cast(aObj); } -QModelIndex XGUI_PartDataModel::objectIndex(const ObjectPtr& theObject) const +QModelIndex PartSet_PartDataModel::objectIndex(const ObjectPtr& theObject) const { QModelIndex aIndex; if (theObject) { @@ -564,7 +558,7 @@ QModelIndex XGUI_PartDataModel::objectIndex(const ObjectPtr& theObject) const } -int XGUI_PartDataModel::getRowsNumber() const +int PartSet_PartDataModel::getRowsNumber() const { int aSize = partDocument()->size(ModelAPI_ResultGroup::group()); if (aSize == 0) // If there are no groups then do not show group folder diff --git a/src/XGUI/XGUI_PartDataModel.h b/src/PartSet/PartSet_PartDataModel.h similarity index 93% rename from src/XGUI/XGUI_PartDataModel.h rename to src/PartSet/PartSet_PartDataModel.h index 56f28ad5e..fc61ec1c5 100644 --- a/src/XGUI/XGUI_PartDataModel.h +++ b/src/PartSet/PartSet_PartDataModel.h @@ -1,24 +1,24 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> -#ifndef XGUI_PartDataModel_H -#define XGUI_PartDataModel_H +#ifndef PartSet_PartDataModel_H +#define PartSet_PartDataModel_H -#include "XGUI.h" -#include "XGUI_DataTreeModel.h" +#include "PartSet.h" +#include "PartSet_DataTreeModel.h" -/**\class XGUI_TopDataModel +/**\class PartSet_TopDataModel * \ingroup GUI * \brief This is a data model for Object Browser (QTreeView). * It represents only upper part of data tree (non-parts tree items) */ -class XGUI_EXPORT XGUI_TopDataModel : public XGUI_FeaturesModel +class PARTSET_EXPORT PartSet_TopDataModel : public PartSet_FeaturesModel { Q_OBJECT public: /// Constructor /// \param theParent a parent object - XGUI_TopDataModel(QObject* theParent); - virtual ~XGUI_TopDataModel(); + PartSet_TopDataModel(QObject* theParent); + virtual ~PartSet_TopDataModel(); // Reimpl from QAbstractItemModel @@ -89,19 +89,19 @@ Q_OBJECT }; -/**\class XGUI_PartDataModel +/**\class PartSet_PartDataModel * \ingroup GUI * \brief This is a data model for Object Browser (QTreeView). * It represents data tree only of a one part */ -class XGUI_PartDataModel : public XGUI_PartModel +class PartSet_PartDataModel : public PartSet_PartModel { Q_OBJECT public: /// Constructor /// \param theParent a parent object - XGUI_PartDataModel(QObject* theParent); - virtual ~XGUI_PartDataModel(); + PartSet_PartDataModel(QObject* theParent); + virtual ~PartSet_PartDataModel(); // Reimpl from QAbstractItemModel diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index 58ee9fa2f..35d20306a 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -45,5 +45,10 @@ icons/mirror.png icons/translate.png icons/rotate.png + icons/exec_state_failed.png + icons/exec_state_invalid_parameters.png + icons/activate.png + icons/deactivate.png + icons/edit.png diff --git a/src/XGUI/pictures/activate.png b/src/PartSet/icons/activate.png similarity index 100% rename from src/XGUI/pictures/activate.png rename to src/PartSet/icons/activate.png diff --git a/src/PartSet/icons/deactivate.png b/src/PartSet/icons/deactivate.png new file mode 100644 index 0000000000000000000000000000000000000000..1b1c71aaab5fc2c7286a760425375636253e8067 GIT binary patch literal 3639 zcmV-74#@F|P)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq3?Wo(Y?l$ge?uXo;%ru`Vo>?<<(8I_>;8Eq#KMS9gFl*neeosSB zfoHYnBQIkwkyowPu(zdms`p{<7e4kra-ZWq<2*OsGTvEV%s0Td$hXT+!*8Bnh2KMe zBmZRodjHV?r+_5^X9J0WL4jKW`}lf%A-|44I@@LTvf1rHjG(ze6+w@Jt%Bvjts!X0 z?2xS?_ve_-kiKB_KiJlZ$9G`c^=E@oNG)mWWaNo-3TIW8)$Hg0Ub-~8?KhvJ>$ z3*&nim@mj(aCxE5!t{lw7O5^0EIO7zOo&c6l<+|iDySBWCGrz@C5{St!X3hAA}`T4 z(TLbXTq+(;@<=L8dXnssyft|w#WSTW<++3>sgS%(4NTpeI-VAqb|7ssJvzNHgOZVu zaYCvgO_R1~>SyL=cFU|~g|hy|Zi}}s9+d~lYqOB71z9Z$wnC=pR9Yz4DhIM>Wmjgu z&56o6maCpC&F##y%G;1PobR9i?GnNg;gYtchD%p19a!eQtZF&3JaKv33gZ<8D~47E ztUS1iwkmDaPpj=$m#%)jCVEY4fnLGNg2A-`YwHVD3gv};>)hAvT~AmqS>Lr``i7kw zJ{5_It`yrBmlc25DBO7E8;5VoznR>Ww5hAaxn$2~(q`%A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=00004XF*Lt006O$eEU(80000WV@Og>004R=004l4008;_004mL004C` z008P>0026e000+nl3&F}000A0Nkl;35RKx(%o0o7!$ydE*xt;Zwh;o%#hE~9Vls&jiwTqx#6~BH1B0D^Nqb92 z2lR*1dr9vt(4X6HPZ)LcBwzA9oQHG1b3TTM@PE_P)YM?J*_H}0nnN$+ad-iJ zeSP}r>FJcwX#D(0<55j+ZVq^!Khx3Cakr$TB)`4AJ@PDHMMMAqhr`hq42REfEE~yt zH80;(SC>yjP^)uMP*8voheL`>Qew;I&6_-4@3}Us^%4Mph@jKyn9k15SR@=KxBD-O z2?8xfqZIgOjzZxuMHUw+E=eRO610{~(cs|V-|H3_0Eoq6S(nRo<=*stR8>_%5JUuK z0|*2H2!%qBWf_X1Ae~M_Q8MW7@4vckfmvS;o6U6$bmBBPH41R6l%3uz21;5 zE-r@K?M5=0f}$w+xW4}2(<8LCwKa5icSk*5Z^k#{r^(4F8ox14L`3F#i`8H-oOX_m zMwbMErl#)ELNG+U&zI@#?Tyyf)*fO!9`D{0r&{z`0-IP_K`Ncb_8p}-a`e-I(Gka` zvG3cL9$vjTDGDM|=?pTNG`O4`_T;G+JsxXA_N@iG&34D>bY6J2c^Box3e7JBY5b;(7Nb#m z@bD42dU|NA{7p)niilwu_1EW2@Nc=!iF5Y;^IMPPO|+11r`{WN6` zd{MglwTcfv!Q-2Q(3&=UgqMBUua_@-=I7_h@As40Y<2@U58&q(26JQE%81Tipf9T` z&OTM}A{d6zwYIii0RX$*-a#Oc02$8002ov JPDHLkV1iSH(2@WE literal 0 HcmV?d00001 diff --git a/src/XGUI/pictures/edit.png b/src/PartSet/icons/edit.png similarity index 100% rename from src/XGUI/pictures/edit.png rename to src/PartSet/icons/edit.png diff --git a/src/XGUI/pictures/exec_state_failed.png b/src/PartSet/icons/exec_state_failed.png similarity index 100% rename from src/XGUI/pictures/exec_state_failed.png rename to src/PartSet/icons/exec_state_failed.png diff --git a/src/XGUI/pictures/exec_state_invalid_parameters.png b/src/PartSet/icons/exec_state_invalid_parameters.png similarity index 100% rename from src/XGUI/pictures/exec_state_invalid_parameters.png rename to src/PartSet/icons/exec_state_invalid_parameters.png diff --git a/src/PartSetPlugin/PartSetPlugin_Part.h b/src/PartSetPlugin/PartSetPlugin_Part.h index 0a24df58e..d679d9ccf 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.h +++ b/src/PartSetPlugin/PartSetPlugin_Part.h @@ -46,12 +46,6 @@ class PartSetPlugin_Part : public ModelAPI_Feature /// Part must be added only to PartSet PARTSETPLUGIN_EXPORT virtual const std::string& documentToAdd(); - /// Returns true if this feature must be displayed in the history (top level of Part tree) - PARTSETPLUGIN_EXPORT virtual bool isInHistory() - { - return false; - } - /// Use plugin manager for features creation PartSetPlugin_Part(); }; diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index 060d58af8..d570650ef 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -9,14 +9,11 @@ SET(PROJECT_HEADERS XGUI_ColorDialog.h XGUI_ContextMenuMgr.h XGUI_CustomPrs.h - XGUI_DataTreeModel.h XGUI_Displayer.h - XGUI_DocumentDataModel.h XGUI_ErrorDialog.h XGUI_ModuleConnector.h XGUI_ObjectsBrowser.h XGUI_OperationMgr.h - XGUI_PartDataModel.h XGUI_PropertyPanel.h XGUI_QtEvents.h XGUI_SalomeConnector.h @@ -38,12 +35,10 @@ SET(PROJECT_SOURCES XGUI_ContextMenuMgr.cpp XGUI_CustomPrs.cpp XGUI_Displayer.cpp - XGUI_DocumentDataModel.cpp XGUI_ErrorDialog.cpp XGUI_ModuleConnector.cpp XGUI_ObjectsBrowser.cpp XGUI_OperationMgr.cpp - XGUI_PartDataModel.cpp XGUI_PropertyPanel.cpp XGUI_QtEvents.cpp XGUI_Selection.cpp diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 494ecf28d..ff696de22 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -8,7 +8,6 @@ #include "XGUI_ViewerProxy.h" #include "XGUI_Selection.h" #include "XGUI_SalomeConnector.h" -#include "XGUI_Tools.h" #include @@ -17,12 +16,12 @@ #include #include #include -#include #include #include #include #include +#include #include #include @@ -41,16 +40,7 @@ XGUI_ContextMenuMgr::~XGUI_ContextMenuMgr() void XGUI_ContextMenuMgr::createActions() { - QAction* aAction = new QAction(QIcon(":pictures/edit.png"), tr("Edit..."), this); - addAction("EDIT_CMD", aAction); - - aAction = new QAction(QIcon(":pictures/activate.png"), tr("Activate"), this); - addAction("ACTIVATE_PART_CMD", aAction); - - aAction = new QAction(QIcon(":pictures/assembly.png"), tr("Deactivate"), this); - addAction("DEACTIVATE_PART_CMD", aAction); - - aAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this); + QAction* aAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this); QMainWindow* aDesktop = myWorkshop->mainWindow(); if (!aDesktop) aDesktop = myWorkshop->salomeConnector()->desktop(); @@ -155,21 +145,13 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const bool hasResult = false; bool hasFeature = false; bool hasParameter = false; - XGUI_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter); + ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter); //Process Feature if (aSelected == 1) { ObjectPtr aObject = aObjects.first(); if (aObject) { - ResultPartPtr aPart = std::dynamic_pointer_cast(aObject); - if (aPart) { - if (aMgr->activeDocument() == aPart->partDoc()) - aMenu->addAction(action("DEACTIVATE_PART_CMD")); - else - aMenu->addAction(action("ACTIVATE_PART_CMD")); - } else if (hasFeature && aObject->document() == aMgr->activeDocument()) { - aMenu->addAction(action("EDIT_CMD")); - } else { + if (!hasFeature) { if (aDisplayer->isVisible(aObject)) { if (aDisplayer->canBeShaded(aObject)) { if (aDisplayer->displayMode(aObject) == XGUI_Displayer::Shading) @@ -179,18 +161,13 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const } aMenu->addSeparator(); aMenu->addAction(action("HIDE_CMD")); - } else if (!hasParameter) { + } else if (hasResult && (!hasParameter)) { aMenu->addAction(action("SHOW_CMD")); } - if (hasParameter) - aMenu->addAction(action("EDIT_CMD")); - else + if (!(hasParameter || hasFeature)) aMenu->addAction(action("SHOW_ONLY_CMD")); } - } else { // If feature is 0 the it means that selected root object (document) - if (aMgr->activeDocument() != aMgr->moduleDocument()) - aMenu->addAction(action("ACTIVATE_PART_CMD")); - } + } } else { if (hasResult && (!hasParameter)) { aMenu->addAction(action("SHOW_CMD")); @@ -208,11 +185,13 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const aMenu->addAction(action("COLOR_CMD")); aMenu->addSeparator(); + ModuleBase_IModule* aModule = myWorkshop->module(); + if (aModule) { + aModule->addObjectBrowserMenu(aMenu); + aMenu->addSeparator(); + } aMenu->addActions(myWorkshop->objectBrowser()->actions()); - ModuleBase_IModule* aModule = myWorkshop->module(); - if (aModule) - aModule->addObjectBrowserItems(aMenu); if (aMenu->actions().size() > 0) { return aMenu; @@ -224,7 +203,7 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const QMenu* XGUI_ContextMenuMgr::viewerMenu() const { QMenu* aMenu = new QMenu(); - addViewerItems(aMenu); + addViewerMenu(aMenu); if (aMenu->actions().size() > 0) { return aMenu; } @@ -232,19 +211,17 @@ QMenu* XGUI_ContextMenuMgr::viewerMenu() const return 0; } -void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const +void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const { bool aIsDone = false; ModuleBase_IModule* aModule = myWorkshop->module(); if (aModule) - aIsDone = aModule->addViewerItems(theMenu, myActions); + aIsDone = aModule->addViewerMenu(theMenu, myActions); if (!aIsDone) { XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects(); if (aObjects.size() > 0) { - //if (aObjects.size() == 1) - // theMenu->addAction(action("EDIT_CMD")); bool isVisible = false; bool isShading = false; bool canBeShaded = false; @@ -270,7 +247,6 @@ void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const theMenu->addAction(action("HIDE_CMD")); } else theMenu->addAction(action("SHOW_CMD")); - //theMenu->addAction(action("DELETE_CMD")); } if (myWorkshop->displayer()->objectsCount() > 0) theMenu->addAction(action("HIDEALL_CMD")); diff --git a/src/XGUI/XGUI_ContextMenuMgr.h b/src/XGUI/XGUI_ContextMenuMgr.h index 5098ca1bb..3f490a59b 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.h +++ b/src/XGUI/XGUI_ContextMenuMgr.h @@ -51,7 +51,7 @@ Q_OBJECT /// Add menu atems for viewer into the given menu (used in SALOME mode) /// \param theMenu a popup menu to be shown in the viewer - void addViewerItems(QMenu* theMenu) const; + void addViewerMenu(QMenu* theMenu) const; signals: /// Signal aabout triggered action diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 75f6c32a9..3851b9fbe 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -1,15 +1,14 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> #include "XGUI_ObjectsBrowser.h" -#include "XGUI_DocumentDataModel.h" #include "XGUI_Tools.h" #include #include #include -#include #include +#include #include #include @@ -20,6 +19,11 @@ #include #include + +/// Width of second column (minimum acceptable = 27) +#define SECOND_COL_WIDTH 30 + + /** * \ingroup GUI * Tree item delegate for definition of data in column items editor @@ -38,7 +42,7 @@ public: { QLineEdit* aEditor = dynamic_cast(editor); if (aEditor) { - XGUI_DocumentDataModel* aModel = myTreedView->dataModel(); + ModuleBase_IDocumentDataModel* aModel = myTreedView->dataModel(); ObjectPtr aObj = aModel->object(index); if (aObj.get() != NULL) { aEditor->setText(aObj->data()->name().c_str()); @@ -57,53 +61,20 @@ XGUI_DataTree::XGUI_DataTree(QWidget* theParent) : QTreeView(theParent) { setHeaderHidden(true); - setModel(new XGUI_DocumentDataModel(this)); setEditTriggers(QAbstractItemView::NoEditTriggers); setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionMode(QAbstractItemView::ExtendedSelection); setItemDelegateForColumn(0, new XGUI_TreeViewItemDelegate(this)); - - connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), - this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&))); } XGUI_DataTree::~XGUI_DataTree() { } -XGUI_DocumentDataModel* XGUI_DataTree::dataModel() const +ModuleBase_IDocumentDataModel* XGUI_DataTree::dataModel() const { - return static_cast(model()); -} - -void XGUI_DataTree::onSelectionChanged(const QItemSelection& theSelected, - const QItemSelection& theDeselected) -{ - mySelectedData.clear(); - QModelIndexList aIndexes = selectionModel()->selectedIndexes(); - XGUI_DocumentDataModel* aModel = dataModel(); - QModelIndexList::const_iterator aIt; - for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) { - ObjectPtr aObject = aModel->object(*aIt); - if (aObject) - mySelectedData.append(aObject); - } - emit selectionChanged(); -} - -void XGUI_DataTree::mouseDoubleClickEvent(QMouseEvent* theEvent) -{ - if (theEvent->button() == Qt::LeftButton) { - QModelIndex aIndex = currentIndex(); - XGUI_DocumentDataModel* aModel = dataModel(); - ObjectPtr aObject = aModel->object(aIndex); - ResultPartPtr aPart = std::dynamic_pointer_cast(aObject); - if (aPart) { - aPart->activate(); - } - } else - QTreeView::mouseDoubleClickEvent(theEvent); + return static_cast(model()); } void XGUI_DataTree::contextMenuEvent(QContextMenuEvent* theEvent) @@ -116,27 +87,38 @@ void XGUI_DataTree::commitData(QWidget* theEditor) QLineEdit* aEditor = dynamic_cast(theEditor); if (aEditor) { QString aRes = aEditor->text(); - ObjectPtr aFeature = mySelectedData.first(); + QModelIndexList aIndexList = selectionModel()->selectedIndexes(); + ModuleBase_IDocumentDataModel* aModel = dataModel(); + ObjectPtr aObj = aModel->object(aIndexList.first()); SessionPtr aMgr = ModelAPI_Session::get(); aMgr->startOperation("Rename"); - aFeature->data()->setName(qPrintable(aRes)); + aObj->data()->setName(qPrintable(aRes)); aMgr->finishOperation(); } } void XGUI_DataTree::clear() { - mySelectedData.clear(); - XGUI_DocumentDataModel* aModel = dataModel(); + ModuleBase_IDocumentDataModel* aModel = dataModel(); aModel->clear(); reset(); } +void XGUI_DataTree::resizeEvent(QResizeEvent* theEvent) +{ + QSize aSize = theEvent->size(); + if (aSize.isValid()) { + setColumnWidth(0, aSize.width() - SECOND_COL_WIDTH); + setColumnWidth(1, SECOND_COL_WIDTH); + } +} + + //******************************************************************** //******************************************************************** //******************************************************************** XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) - : QWidget(theParent) + : QWidget(theParent), myDocModel(0) { QVBoxLayout* aLayout = new QVBoxLayout(this); ModuleBase_Tools::zeroMargins(aLayout); @@ -179,24 +161,14 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) myTreeView = new XGUI_DataTree(this); aLayout->addWidget(myTreeView); - myDocModel = myTreeView->dataModel(); - aLabelWgt->setFrameShape(myTreeView->frameShape()); aLabelWgt->setFrameShadow(myTreeView->frameShadow()); - connect(myTreeView, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - connect(myTreeView, SIGNAL(activePartChanged(ObjectPtr)), this, - SLOT(onActivePartChanged(ObjectPtr))); - connect(myTreeView, SIGNAL(activePartChanged(ObjectPtr)), this, - SIGNAL(activePartChanged(ObjectPtr))); - connect(myActiveDocLbl, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onLabelContextMenuRequested(const QPoint&))); connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this, SLOT(onContextMenuRequested(QContextMenuEvent*))); - onActivePartChanged(ObjectPtr()); - // Create internal actions QAction* aAction = new QAction(QIcon(":pictures/rename_edit.png"), tr("Rename"), this); aAction->setData("RENAME_CMD"); @@ -209,32 +181,11 @@ XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser() { } -//*************************************************** -void XGUI_ObjectsBrowser::onActivePartChanged(ObjectPtr thePart) -{ - QPalette aPalet = myActiveDocLbl->palette(); - if (thePart) { - aPalet.setColor(QPalette::Text, Qt::black); - } else { - aPalet.setColor(QPalette::Text, QColor(0, 72, 140)); - } - myActiveDocLbl->setPalette(aPalet); -} - //*************************************************** bool XGUI_ObjectsBrowser::eventFilter(QObject* obj, QEvent* theEvent) { if (obj == myActiveDocLbl) { - if (myActiveDocLbl->isReadOnly()) { - if (theEvent->type() == QEvent::MouseButtonDblClick) { - if (myDocModel->activePartIndex().isValid()) { - myTreeView->setExpanded(myDocModel->activePartIndex(), false); - } - myDocModel->deactivatePart(); - onActivePartChanged(ObjectPtr()); - emit activePartChanged(ObjectPtr()); - } - } else { + if (!myActiveDocLbl->isReadOnly()) { // End of editing by mouse click if (theEvent->type() == QEvent::MouseButtonRelease) { QMouseEvent* aEvent = (QMouseEvent*) theEvent; @@ -275,40 +226,10 @@ void XGUI_ObjectsBrowser::closeDocNameEditing(bool toSave) } } -//*************************************************** -void XGUI_ObjectsBrowser::activatePart(const ResultPartPtr& thePart) -{ - if (thePart) { - QModelIndex aIndex = myDocModel->partIndex(thePart); - - if ((myDocModel->activePartIndex() != aIndex) && myDocModel->activePartIndex().isValid()) { - myTreeView->setExpanded(myDocModel->activePartIndex(), false); - } - bool isChanged = myDocModel->activatedIndex(aIndex); - if (isChanged) { - if (myDocModel->activePartIndex().isValid()) { - myTreeView->setExpanded(aIndex.parent(), true); - myTreeView->setExpanded(aIndex, true); - onActivePartChanged(myDocModel->object(aIndex)); - } else { - onActivePartChanged(ObjectPtr()); - } - } - } else { - QModelIndex aIndex = myDocModel->activePartIndex(); - if (aIndex.isValid()) { - myDocModel->activatedIndex(aIndex); - myTreeView->setExpanded(aIndex, false); - onActivePartChanged(ObjectPtr()); - } - } -} - //*************************************************** void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent) { - myObjectsList = myTreeView->selectedObjects(); - bool toEnable = myObjectsList.size() == 1; + bool toEnable = mySelectedData.size() == 1; foreach(QAction* aCmd, actions()) { aCmd->setEnabled(toEnable); @@ -319,9 +240,9 @@ void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent) //*************************************************** void XGUI_ObjectsBrowser::onLabelContextMenuRequested(const QPoint& thePnt) { - myObjectsList.clear(); + mySelectedData.clear(); //Empty feature pointer means that selected root document - myObjectsList.append(ObjectPtr()); + mySelectedData.append(ObjectPtr()); foreach(QAction* aCmd, actions()) { @@ -334,8 +255,8 @@ void XGUI_ObjectsBrowser::onLabelContextMenuRequested(const QPoint& thePnt) //*************************************************** void XGUI_ObjectsBrowser::onEditItem() { - if (myObjectsList.size() > 0) { - ObjectPtr aFeature = myObjectsList.first(); + if (mySelectedData.size() > 0) { + ObjectPtr aFeature = mySelectedData.first(); if (aFeature) { // Selection happens in TreeView // Find index which corresponds the feature QModelIndex aIndex; @@ -361,13 +282,6 @@ void XGUI_ObjectsBrowser::onEditItem() } } -//*************************************************** -void XGUI_ObjectsBrowser::onSelectionChanged() -{ - myObjectsList = myTreeView->selectedObjects(); - emit selectionChanged(); -} - //*************************************************** void XGUI_ObjectsBrowser::rebuildDataTree() { @@ -392,15 +306,34 @@ void XGUI_ObjectsBrowser::setObjectsSelected(const QObjectPtrList& theObjects) } //*************************************************** -void XGUI_ObjectsBrowser::processEvent(const std::shared_ptr& theMessage) +void XGUI_ObjectsBrowser::clearContent() { - myDocModel->processEvent(theMessage); + mySelectedData.clear(); + myTreeView->clear(); } +void XGUI_ObjectsBrowser::setDataModel(ModuleBase_IDocumentDataModel* theModel) +{ + myDocModel = theModel; + myTreeView->setModel(myDocModel); + QItemSelectionModel* aSelMod = myTreeView->selectionModel(); + connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), + this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&))); +} -//*************************************************** -void XGUI_ObjectsBrowser::clearContent() -{ - myObjectsList.clear(); - myTreeView->clear(); +void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected, + const QItemSelection& theDeselected) +{ + mySelectedData.clear(); + QModelIndexList aIndexes = myTreeView->selectionModel()->selectedIndexes(); + ModuleBase_IDocumentDataModel* aModel = dataModel(); + QModelIndexList::const_iterator aIt; + for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) { + if ((*aIt).column() == 0) { + ObjectPtr aObject = aModel->object(*aIt); + if (aObject) + mySelectedData.append(aObject); + } + } + emit selectionChanged(); } diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index 93cc131be..169615c3d 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -12,7 +12,7 @@ #include #include -class XGUI_DocumentDataModel; +class ModuleBase_IDocumentDataModel; class QLineEdit; /** @@ -26,24 +26,13 @@ Q_OBJECT /// Constructor /// \param theParent a parent widget XGUI_DataTree(QWidget* theParent); - virtual ~XGUI_DataTree(); - //! Returns list of currently selected objects - QObjectPtrList selectedObjects() const - { - return mySelectedData; - } + virtual ~XGUI_DataTree(); /// Returns current data model - XGUI_DocumentDataModel* dataModel() const; + ModuleBase_IDocumentDataModel* dataModel() const; signals: - //! Emited when selection is changed - void selectionChanged(); - - //! Emited when active part changed - void activePartChanged(ObjectPtr thePart); - //! Emited on context menu request void contextMenuRequested(QContextMenuEvent* theEvent); @@ -52,23 +41,16 @@ public slots: virtual void clear(); protected slots: - /// Commit modified data (used for renaming of objects) + /// Commit modified data (used for renaming of objects) virtual void commitData(QWidget* theEditor); protected: - /// Redefinition of virtual method - virtual void mouseDoubleClickEvent(QMouseEvent* theEvent); - /// Redefinition of virtual method virtual void contextMenuEvent(QContextMenuEvent* theEvent); - private slots: - //! Called when selection in Data Tree is changed - void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected); + /// Redefinition of virtual method + virtual void resizeEvent(QResizeEvent* theEvent); - private: - //! List of currently selected data - QObjectPtrList mySelectedData; }; /**\class XGUI_ObjectsBrowser @@ -85,7 +67,7 @@ Q_OBJECT virtual ~XGUI_ObjectsBrowser(); //! Returns Model which provides access to data objects - XGUI_DocumentDataModel* dataModel() const + ModuleBase_IDocumentDataModel* dataModel() const { return myDocModel; } @@ -93,7 +75,7 @@ Q_OBJECT //! Returns list of currently selected objects QObjectPtrList selectedObjects() const { - return myObjectsList; + return mySelectedData; } /// Set selected list of objects @@ -112,26 +94,22 @@ Q_OBJECT return myTreeView; } - //! Activates currently selected part. Signal activePartChanged will not be sent - void activatePart(const ResultPartPtr& thePart); + /// Returns active doc label object + QLineEdit* activeDocLabel() const { return myActiveDocLbl; } /// Rebuild data tree void rebuildDataTree(); - /// Process application event - /// \param theMessage an event message - void processEvent(const std::shared_ptr& theMessage); - /// Resets the object browser into initial state void clearContent(); + /// Set Data Model for the Object Browser + void setDataModel(ModuleBase_IDocumentDataModel* theModel); + signals: //! Emited when selection is changed void selectionChanged(); - //! Emited when current active document is changed - void activePartChanged(ObjectPtr thePart); - //! Emited on context menu request void contextMenuRequested(QContextMenuEvent* theEvent); @@ -140,10 +118,6 @@ signals: virtual bool eventFilter(QObject* obj, QEvent* theEvent); private slots: - /// Activate part - /// \param thePart a part to activate - void onActivePartChanged(ObjectPtr thePart); - /// Show context menu /// \param theEvent a context menu event void onContextMenuRequested(QContextMenuEvent* theEvent); @@ -155,19 +129,19 @@ signals: //! Called on Edit command request void onEditItem(); - /// Process selection changed event - void onSelectionChanged(); + //! Called when selection in Data Tree is changed + void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected); private: void closeDocNameEditing(bool toSave); //! Internal model - XGUI_DocumentDataModel* myDocModel; + ModuleBase_IDocumentDataModel* myDocModel; QLineEdit* myActiveDocLbl; XGUI_DataTree* myTreeView; - QObjectPtrList myObjectsList; + QObjectPtrList mySelectedData; }; #endif diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 4ffac6dc7..42ddf7318 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -75,23 +75,5 @@ std::string featureInfo(FeaturePtr theFeature) }*/ -void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature, bool& hasParameter) -{ - hasResult = false; - hasFeature = false; - hasParameter = false; - foreach(ObjectPtr aObj, theObjects) { - FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); - ResultPtr aResult = std::dynamic_pointer_cast(aObj); - ResultParameterPtr aConstruction = std::dynamic_pointer_cast(aResult); - - hasResult = (aResult.get() != NULL); - hasFeature = (aFeature.get() != NULL); - hasParameter = (aConstruction.get() != NULL); - if (hasFeature && hasResult && hasParameter) - break; - } -} - } diff --git a/src/XGUI/XGUI_Tools.h b/src/XGUI/XGUI_Tools.h index e541ba2f0..1a5c7b05f 100644 --- a/src/XGUI/XGUI_Tools.h +++ b/src/XGUI/XGUI_Tools.h @@ -8,7 +8,6 @@ #include #include -#include #include @@ -66,15 +65,6 @@ bool XGUI_EXPORT isModelObject(FeaturePtr theFeature); std::string XGUI_EXPORT featureInfo(FeaturePtr theFeature); -/*! -Check types of objects which are in the given list -\param theObjects the list of objects -\param hasResult will be set to true if list contains Result objects -\param hasFeature will be set to true if list contains Feature objects -\param hasParameter will be set to true if list contains Parameter objects -*/ -void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature, bool& hasParameter); - }; #endif diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index b32a80bbc..8706c57b7 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -94,44 +94,6 @@ //#define DEBUG_FEATURE_CREATED //#define DEBUG_FEATURE_REDISPLAY -QMap XGUI_Workshop::myIcons; - - -QIcon XGUI_Workshop::featureIcon(const FeaturePtr& theFeature) -{ - QIcon anIcon; - - std::string aKind = theFeature->getKind(); - QString aId(aKind.c_str()); - if (!myIcons.contains(aId)) - return anIcon; - - QString anIconString = myIcons[aId]; - - ModelAPI_ExecState aState = theFeature->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(":pictures/exec_state_failed.png", anIconString); - } - break; - case ModelAPI_StateInvalidArgument: { - anIcon = ModuleBase_Tools::composite(":pictures/exec_state_invalid_parameters.png", - anIconString); - } - break; - default: break; - } - return anIcon; -} XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) : QObject(), @@ -201,10 +163,8 @@ void XGUI_Workshop::startApplication() aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); - aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED)); aLoop->registerListener(this, Events_LongOp::eventID()); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED)); - aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOSHOW)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOHIDE)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED)); @@ -382,10 +342,6 @@ void XGUI_Workshop::processEvent(const std::shared_ptr& theMessa std::shared_ptr anUpdateMsg = std::dynamic_pointer_cast(theMessage); onFeatureUpdatedMsg(anUpdateMsg); - } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { - std::shared_ptr aDelMsg = - std::dynamic_pointer_cast(theMessage); - onObjectDeletedMsg(aDelMsg); } else if (theMessage->eventID() == Events_LongOp::eventID()) { if (Events_LongOp::isPerformed()) { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); @@ -425,30 +381,7 @@ void XGUI_Workshop::processEvent(const std::shared_ptr& theMessa updateCommandStatus(); } } - } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) { - myActionsMgr->update(); - // Find and Activate active part - if (myPartActivating) - return; - SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aActiveDoc = aMgr->activeDocument(); - DocumentPtr aDoc = aMgr->moduleDocument(); - if (aActiveDoc == aDoc) { - activatePart(ResultPartPtr()); - return; - } - std::string aGrpName = ModelAPI_ResultPart::group(); - for (int i = 0; i < aDoc->size(aGrpName); i++) { - ResultPartPtr aPart = std::dynamic_pointer_cast(aDoc->object(aGrpName, i)); - if (aPart->partDoc() == aActiveDoc) { - activatePart(aPart); // Activate a part which corresponds to active Doc - return; - } - } - // If not found then activate global document - activatePart(ResultPartPtr()); - - } + } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) { std::shared_ptr aMsg = std::dynamic_pointer_cast(theMessage); @@ -510,8 +443,8 @@ void XGUI_Workshop::onFeatureUpdatedMsg(const std::shared_ptronValidateOperation(); - if (myObjectBrowser) - myObjectBrowser->processEvent(theMsg); + //if (myObjectBrowser) + // myObjectBrowser->processEvent(theMsg); } //****************************************************** @@ -611,8 +544,8 @@ void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptrprocessEvent(theMsg); + //if (myObjectBrowser) + // myObjectBrowser->processEvent(theMsg); if (isDisplayed) myDisplayer->updateViewer(); //if (aHasPart) { // TODO: Avoid activate last part on loading of document @@ -620,14 +553,6 @@ void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr& theMsg) -{ - if (myObjectBrowser) - myObjectBrowser->processEvent(theMsg); - //std::set aFeatures = theMsg->objects(); -} - //****************************************************** void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation) { @@ -752,8 +677,6 @@ void XGUI_Workshop::addFeature(const std::shared_ptr& the } ActionInfo aFeatureInfo; aFeatureInfo.initFrom(theMessage); - // Remember features icons - myIcons[QString::fromStdString(theMessage->id())] = aFeatureInfo.iconFile; QString aWchName = QString::fromStdString(theMessage->workbenchId()); QStringList aNestedFeatures = @@ -1206,8 +1129,9 @@ QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent) aObjDock->setStyleSheet( "::title { position: relative; padding-left: 5px; text-align: left center }"); myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock); - connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this, - SLOT(changeCurrentDocument(ObjectPtr))); + myObjectBrowser->setDataModel(myModule->dataModel()); + //connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this, + // SLOT(changeCurrentDocument(ObjectPtr))); aObjDock->setWidget(myObjectBrowser); myContextMenuMgr->connectObjectBrowser(); @@ -1290,23 +1214,6 @@ void XGUI_Workshop::onFeatureTriggered() } } -//****************************************************** -void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj) -{ - SessionPtr aMgr = ModelAPI_Session::get(); - if (theObj) { - ResultPartPtr aPart = std::dynamic_pointer_cast(theObj); - if (aPart) { - DocumentPtr aPartDoc = aPart->partDoc(); - if (aPartDoc) { - aMgr->setActiveDocument(aPartDoc); - return; - } - } - } - aMgr->setActiveDocument(aMgr->moduleDocument()); -} - //****************************************************** void XGUI_Workshop::salomeViewerSelectionChanged() { @@ -1323,12 +1230,7 @@ ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) { QObjectPtrList aObjects = mySelector->selection()->selectedObjects(); - if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) { - ResultPartPtr aPart = std::dynamic_pointer_cast(aObjects.first()); - activatePart(aPart); - } else if (theId == "DEACTIVATE_PART_CMD") - activatePart(ResultPartPtr()); - else if (theId == "DELETE_CMD") + if (theId == "DELETE_CMD") deleteObjects(); else if (theId == "COLOR_CMD") changeColor(aObjects); @@ -1344,47 +1246,8 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) setDisplayMode(aObjects, XGUI_Displayer::Wireframe); else if (theId == "HIDEALL_CMD") myDisplayer->eraseAll(); - else if (theId == "EDIT_CMD") { - FeaturePtr aFeature = std::dynamic_pointer_cast(aObjects.first()); - if (aFeature == NULL) { - ResultParameterPtr aParam = - std::dynamic_pointer_cast(aObjects.first()); - if (aParam.get() != NULL) { - aFeature = ModelAPI_Feature::feature(aParam); - } - } - if (aFeature.get() != NULL) - myModule->editFeature(aFeature); - } } -//************************************************************** -void XGUI_Workshop::activatePart(ResultPartPtr theFeature) -{ - if (!myPartActivating) { - myPartActivating = true; - if (theFeature) - theFeature->activate(); - changeCurrentDocument(theFeature); - myObjectBrowser->activatePart(theFeature); - myPartActivating = false; - } - updateCommandStatus(); -} - -//************************************************************** -//void XGUI_Workshop::activateLastPart() -//{ -// SessionPtr aMgr = ModelAPI_Session::get(); -// DocumentPtr aDoc = aMgr->moduleDocument(); -// std::string aGrpName = ModelAPI_ResultPart::group(); -// ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1); -// ResultPartPtr aPart = std::dynamic_pointer_cast(aLastPart); -// if (aPart) { -// activatePart(aPart); -// } -//} - //************************************************************** void XGUI_Workshop::deleteObjects() { @@ -1401,7 +1264,7 @@ void XGUI_Workshop::deleteObjects() bool hasResult = false; bool hasFeature = false; bool hasParameter = false; - XGUI_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter); + ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter); if (!(hasFeature || hasParameter)) return; diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 37c04437f..d4fd4a368 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -156,13 +156,6 @@ Q_OBJECT /// \return a desktop instance QMainWindow* desktop() const; - //! Returns icon name according to feature - static QIcon featureIcon(const FeaturePtr& theFeature); - - //! Activates or deactivates a part - //! If PartPtr is Null pointer then PartSet will be activated - void activatePart(std::shared_ptr theFeature); - //! Delete features void deleteObjects(); @@ -293,12 +286,6 @@ signals: /// Reaction on command call void onFeatureTriggered(); - /// Change active document - /// \param theObj a part object. If it is NULL then active document is a main document - void changeCurrentDocument(ObjectPtr theObj); - - //void activateLastPart(); - /// Close document void closeDocument(); @@ -333,9 +320,6 @@ signals: /// Process feature redisplay message void onFeatureRedisplayMsg(const std::shared_ptr& ); - /// Process feature delete message - void onObjectDeletedMsg(const std::shared_ptr& ); - /// Display all results void displayAllResults(); @@ -435,7 +419,6 @@ private: XGUI_ModuleConnector* myModuleConnector; QString myCurrentDir; - static QMap myIcons; bool myUpdatePrefs; diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index de9da1ce1..1f53d9536 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -31,11 +31,7 @@ pictures/button_help.png pictures/button_ok.png - pictures/edit.png - pictures/exec_state_failed.png - pictures/exec_state_invalid_parameters.png pictures/assembly.png - pictures/activate.png pictures/delete.png pictures/rename_edit.png pictures/eye_pencil.png -- 2.39.2