From: vsv Date: Thu, 30 Apr 2015 09:54:42 +0000 (+0300) Subject: Transfer data model for object browser under module responsibility X-Git-Tag: V_1.2.0~177^2~1^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b1a9aba9a812f170668d0f4e04b3501d91da425e;p=modules%2Fshaper.git Transfer data model for object browser under module responsibility --- 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/PartSet/PartSet_DataTreeModel.h b/src/PartSet/PartSet_DataTreeModel.h new file mode 100644 index 000000000..cb71be87a --- /dev/null +++ b/src/PartSet/PartSet_DataTreeModel.h @@ -0,0 +1,96 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +#ifndef PartSet_DataTreeModel_H +#define PartSet_DataTreeModel_H + +#include "PartSet.h" + +#include +#include +#include + +#include +#include + +/**\class PartSet_FeaturesModel + * \ingroup GUI + * \brief Abstaract class of model object which operates with features data. + */ +class PARTSET_EXPORT PartSet_FeaturesModel : public QAbstractItemModel +{ + public: + /// Constructor + /// \param theParent a parent object + PartSet_FeaturesModel(QObject* theParent) + : QAbstractItemModel(theParent), + myItemsColor(Qt::black) + { + } + + //! Returns Feature object by the given Model index. + //! Returns 0 if the given index is not index of a feature + /// \param theIndex a model index + virtual ObjectPtr object(const QModelIndex& theIndex) const = 0; + + //! Returns QModelIndex which corresponds to the given feature + //! If the feature is not found then index is not valid + virtual QModelIndex objectIndex(const ObjectPtr& theFeature) const = 0; + + //! Returns parent index of the given feature + virtual QModelIndex findParent(const ObjectPtr& theObject) const = 0; + + //! Returns index corresponded to the group + //! \param theGroup a group name + virtual QModelIndex findGroup(const std::string& theGroup) const = 0; + + //! Set color of items + void setItemsColor(const QColor& theColor) + { + myItemsColor = theColor; + } + + //! Returns color of items + QColor itemsColor() const + { + return myItemsColor; + } + + protected: + /// Color of items + QColor myItemsColor; +}; + +/**\class PartSet_PartModel + * \ingroup GUI + * \brief Abstaract class of model object which operates with parts data. + */ +class PartSet_PartModel : public PartSet_FeaturesModel +{ + public: + /// Constructor + /// \param theParent a parent object + PartSet_PartModel(QObject* theParent) + : PartSet_FeaturesModel(theParent) + { + } + + /// Set part id + /// \param theId a new id + void setPartId(int theId) + { + myId = theId; + } + + //! Returns true if the given document is a sub-document of this tree + //! \param theDoc a document to check + virtual bool hasDocument(const DocumentPtr& theDoc) const = 0; + + //! Return a Part object + virtual ResultPartPtr part() const = 0; + + protected: + //! Id of the current part object in the document + int myId; +}; + +#endif diff --git a/src/PartSet/PartSet_DocumentDataModel.cpp b/src/PartSet/PartSet_DocumentDataModel.cpp new file mode 100644 index 000000000..2041d5cb0 --- /dev/null +++ b/src/PartSet/PartSet_DocumentDataModel.cpp @@ -0,0 +1,682 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +#include "PartSet_DocumentDataModel.h" +#include "PartSet_PartDataModel.h" +#include "PartSet_Module.h" +//#include "XGUI_Tools.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include + +#include + +#define ACTIVE_COLOR QColor(0,72,140) +#define PASSIVE_COLOR Qt::black + +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 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())); +} + +PartSet_DocumentDataModel::~PartSet_DocumentDataModel() +{ + clearModelIndexes(); + clearSubModels(); +} + +void PartSet_DocumentDataModel::processEvent(const std::shared_ptr& theMessage) +{ + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + + // Created object event ******************* + if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) { + std::shared_ptr aUpdMsg = + std::dynamic_pointer_cast(theMessage); + std::set aObjects = aUpdMsg->objects(); + + std::set::const_iterator aIt; + for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) { + ObjectPtr aObject = (*aIt); + FeaturePtr aFeature = std::dynamic_pointer_cast(aObject); + if (aFeature && (!aFeature->isInHistory())) + continue; + + DocumentPtr aDoc = aObject->document(); + if (aDoc == aRootDoc) { // If root objects + if (aObject->groupName() == ModelAPI_ResultPart::group()) { // Update only Parts group + // Add a new part + int aStart = myPartModels.size(); + PartSet_PartDataModel* aModel = new PartSet_PartDataModel(this); + aModel->setPartId(myPartModels.count()); + myPartModels.append(aModel); + insertRow(aStart, partFolderNode(0)); + } else { // Update top groups (other except parts + QModelIndex aIndex = myModel->findParent(aObject); + int aStart = myModel->rowCount(aIndex) - 1; + if (aStart < 0) + aStart = 0; + aIndex = createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)); + insertRow(aStart, aIndex); + } + } else { // if sub-objects of first level nodes + PartSet_PartModel* aPartModel = 0; + foreach (PartSet_PartModel* aPart, myPartModels) { + if (aPart->hasDocument(aDoc)) { + aPartModel = aPart; + break; + } + } + if (aPartModel) { + QModelIndex aIndex = aPartModel->findParent(aObject); + int aStart = aPartModel->rowCount(aIndex); // check this index + aIndex = createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)); + insertRow(aStart, aIndex); + } else + reset(); + } + } + // Deleted object event *********************** + } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { + std::shared_ptr aUpdMsg = + std::dynamic_pointer_cast(theMessage); + DocumentPtr aDoc = aUpdMsg->document(); + std::set aGroups = aUpdMsg->groups(); + + std::set::const_iterator aIt; + for (aIt = aGroups.begin(); aIt != aGroups.end(); ++aIt) { + std::string aGroup = (*aIt); + if (aDoc == aRootDoc) { // If root objects + if (aGroup == ModelAPI_ResultPart::group()) { // Update only Parts group + int aStart = myPartModels.size() - 1; + if (aStart >= 0) {// MPV: this could be reproduced on close + removeSubModel(aStart); + removeRow(aStart, partFolderNode(0)); + if (myActivePart && (!isPartSubModel(myActivePart))) { + myActivePart = 0; + myActivePartIndex = QModelIndex(); + myModel->setItemsColor(ACTIVE_COLOR); + } + } + } else { // Update top groups (other except parts + QModelIndex aIndex = myModel->findGroup(aGroup); + int aStart = myModel->rowCount(aIndex); + aIndex = createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)); + removeRow(aStart, aIndex); + } + } else { + PartSet_PartModel* aPartModel = 0; + foreach (PartSet_PartModel* aPart, myPartModels) { + if (aPart->hasDocument(aDoc)) { + aPartModel = aPart; + break; + } + } + if (aPartModel) { + QModelIndex aIndex = aPartModel->findGroup(aGroup); + int aStart = aPartModel->rowCount(aIndex); + aIndex = createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)); + removeRow(aStart, aIndex); + } + } + } + // Deleted object event *********************** + } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) { + //std::shared_ptr aUpdMsg = std::dynamic_pointer_cast(theMessage); + //ObjectPtr aFeature = aUpdMsg->feature(); + //DocumentPtr aDoc = aFeature->document(); + + // TODO: Identify the necessary index by the modified feature + QModelIndex aIndex; + 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 PartSet_DocumentDataModel::rebuildDataTree() +{ + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + + beginResetModel(); + clearModelIndexes(); + + int aNbParts = aRootDoc->size(ModelAPI_ResultPart::group()); + if (myPartModels.size() != aNbParts) { // resize internal models + while (myPartModels.size() > aNbParts) { + delete myPartModels.last(); + myPartModels.removeLast(); + } + while (myPartModels.size() < aNbParts) { + myPartModels.append(new PartSet_PartDataModel(this)); + } + for (int i = 0; i < myPartModels.size(); i++) + myPartModels.at(i)->setPartId(i); + } + endResetModel(); +} + +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) { + case Qt::DisplayRole: + return tr("Parts") + QString(" (%1)").arg(rowCount(theIndex)); + case Qt::DecorationRole: + return QIcon(":pictures/constr_folder.png"); + case Qt::ToolTipRole: + return tr("Parts folder"); + case Qt::ForegroundRole: + if (myActivePart) + 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 aFeature->data()->name().c_str(); + else + return QVariant(); + 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); + else + return QBrush(ACTIVE_COLOR); + } + default: + return QVariant(); + } + } + break; + } + if (aParent.isValid() && (aParent.internalId() == PartsFolder)) { + return myPartModels.at(theIndex.row())->data(QModelIndex(), theRole); + } + return toSourceModelIndex(theIndex)->data(theRole); +} + +QVariant PartSet_DocumentDataModel::headerData(int theSection, Qt::Orientation theOrient, + int theRole) const +{ + return QVariant(); +} + +int PartSet_DocumentDataModel::rowCount(const QModelIndex& theParent) const +{ + if (!theParent.isValid()) { + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + // Size of external models + int aVal = historyOffset(); + // Plus history size + aVal += aRootDoc->size(ModelAPI_Feature::group()); + return aVal; + } + if (theParent.internalId() == PartsFolder) { + int aSize = myPartModels.size(); + return myPartModels.size(); + } + if (theParent.internalId() == HistoryNode) { + return 0; + } + QModelIndex* aParent = toSourceModelIndex(theParent); + const QAbstractItemModel* aModel = aParent->model(); + if (!isSubModel(aModel)) + return 0; + + /*if (isPartSubModel(aModel)) { + if (aModel != myActivePart) + return 0; + }*/ + return aModel->rowCount(*aParent); +} + +int PartSet_DocumentDataModel::columnCount(const QModelIndex& theParent) const +{ + return 1; +} + +QModelIndex PartSet_DocumentDataModel::index(int theRow, int theColumn, + const QModelIndex& theParent) const +{ + QModelIndex aIndex; + if (!theParent.isValid()) { + int aOffs = myModel->rowCount(); + if (theRow < aOffs) { + aIndex = myModel->index(theRow, theColumn, theParent); + aIndex = createIndex(theRow, theColumn, (void*) getModelIndex(aIndex)); + } else { + if (theRow == aOffs) // Create Parts node + aIndex = partFolderNode(theColumn); + else + // create history node + aIndex = createIndex(theRow, theColumn, HistoryNode); + } + } else { + if (theParent.internalId() == PartsFolder) { + aIndex = myPartModels.at(theRow)->index(0, theColumn, QModelIndex()); + } else { + QModelIndex* aParent = (QModelIndex*) theParent.internalPointer(); + aIndex = aParent->model()->index(theRow, theColumn, (*aParent)); + } + aIndex = createIndex(theRow, theColumn, (void*) getModelIndex(aIndex)); + } + return aIndex; +} + +QModelIndex PartSet_DocumentDataModel::parent(const QModelIndex& theIndex) const +{ + if ((theIndex.internalId() == PartsFolder) || (theIndex.internalId() == HistoryNode)) + return QModelIndex(); + + QModelIndex* aIndex = toSourceModelIndex(theIndex); + const QAbstractItemModel* aModel = aIndex->model(); + if (!isSubModel(aModel)) + return QModelIndex(); + + if (isPartSubModel(aModel)) { + if (!aModel->parent(*aIndex).isValid()) { + return partFolderNode(theIndex.column()); + } + } + + QModelIndex aIndex1 = aModel->parent(*aIndex); + if (aIndex1.isValid()) + return createIndex(aIndex1.row(), aIndex1.column(), (void*) getModelIndex(aIndex1)); + return aIndex1; +} + +bool PartSet_DocumentDataModel::hasChildren(const QModelIndex& theParent) const +{ + if (!theParent.isValid()) + return true; + return rowCount(theParent) > 0; +} + +QModelIndex* PartSet_DocumentDataModel::toSourceModelIndex(const QModelIndex& theProxy) const +{ + QModelIndex* aIndexPtr = static_cast(theProxy.internalPointer()); + return aIndexPtr; +} + +QModelIndex* PartSet_DocumentDataModel::findModelIndex(const QModelIndex& theIndex) const +{ + QList::const_iterator aIt; + for (aIt = myIndexes.constBegin(); aIt != myIndexes.constEnd(); ++aIt) { + QModelIndex* aIndex = (*aIt); + if ((*aIndex) == theIndex) + return aIndex; + } + return 0; +} + +QModelIndex* PartSet_DocumentDataModel::getModelIndex(const QModelIndex& theIndex) const +{ + QModelIndex* aIndexPtr = findModelIndex(theIndex); + if (!aIndexPtr) { + aIndexPtr = new QModelIndex(theIndex); + PartSet_DocumentDataModel* that = (PartSet_DocumentDataModel*) this; + that->myIndexes.append(aIndexPtr); + } + return aIndexPtr; +} + +void PartSet_DocumentDataModel::clearModelIndexes() +{ + foreach (QModelIndex* aIndex, myIndexes) + delete aIndex; + myIndexes.clear(); +} + +void PartSet_DocumentDataModel::clearSubModels() +{ + foreach (PartSet_PartModel* aPart, myPartModels) + delete aPart; + myPartModels.clear(); +} + +ObjectPtr PartSet_DocumentDataModel::object(const QModelIndex& theIndex) const +{ + if (theIndex.internalId() == PartsFolder) + return ObjectPtr(); + if (theIndex.internalId() == HistoryNode) { + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + int aOffset = historyOffset(); + return aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset); + } + QModelIndex* aIndex = toSourceModelIndex(theIndex); + if (!isSubModel(aIndex->model())) + return ObjectPtr(); + + const PartSet_FeaturesModel* aModel = dynamic_cast(aIndex->model()); + return aModel->object(*aIndex); +} + +bool PartSet_DocumentDataModel::insertRows(int theRow, int theCount, const QModelIndex& theParent) +{ + beginInsertRows(theParent, theRow, theRow + theCount - 1); + //endInsertRows(); + + // Update history + QModelIndex aRoot; + int aRow = rowCount(aRoot); + beginInsertRows(aRoot, aRow, aRow); + endInsertRows(); + + return true; +} + +bool PartSet_DocumentDataModel::removeRows(int theRow, int theCount, const QModelIndex& theParent) +{ + beginRemoveRows(theParent, theRow, theRow + theCount - 1); + endRemoveRows(); + return true; +} + +void PartSet_DocumentDataModel::removeSubModel(int theModelId) +{ + PartSet_PartModel* aModel = myPartModels.at(theModelId); + QIntList aToRemove; + for (int i = 0; i < myIndexes.size(); i++) { + if (myIndexes.at(i)->model() == aModel) + aToRemove.append(i); + } + int aId; + while (aToRemove.size() > 0) { + aId = aToRemove.last(); + delete myIndexes.at(aId); + myIndexes.removeAt(aId); + aToRemove.removeLast(); + } + delete aModel; + myPartModels.removeAt(theModelId); +} + +bool PartSet_DocumentDataModel::isSubModel(const QAbstractItemModel* theModel) const +{ + if (theModel == myModel) + return true; + return isPartSubModel(theModel); +} + +bool PartSet_DocumentDataModel::isPartSubModel(const QAbstractItemModel* theModel) const +{ + return myPartModels.contains((PartSet_PartModel*) theModel); +} + +QModelIndex PartSet_DocumentDataModel::partFolderNode(int theColumn) const +{ + int aPos = myModel->rowCount(QModelIndex()); + return createIndex(aPos, theColumn, PartsFolder); +} + +int PartSet_DocumentDataModel::historyOffset() const +{ + // Nb of rows of top model + Parts folder + return myModel->rowCount(QModelIndex()) + 1; +} + +bool PartSet_DocumentDataModel::activatePart(const QModelIndex& theIndex) +{ + if ((theIndex.internalId() == PartsFolder) || (theIndex.internalId() == HistoryNode)) + return false; + + QModelIndex* aIndex = toSourceModelIndex(theIndex); + if (!aIndex) + return false; + + const QAbstractItemModel* aModel = aIndex->model(); + + if (isPartSubModel(aModel)) { + // if this is root node (Part item index) + if (!aIndex->parent().isValid()) { + if (myActivePart) + myActivePart->setItemsColor(PASSIVE_COLOR); + + if (myActivePart == aModel) { + myActivePart = 0; + myActivePartIndex = QModelIndex(); + } else { + myActivePart = (PartSet_PartModel*)aModel; + myActivePartIndex = theIndex; + } + + if (myActivePart) { + myActivePart->setItemsColor(ACTIVE_COLOR); + myModel->setItemsColor(PASSIVE_COLOR); + } else + myModel->setItemsColor(ACTIVE_COLOR); + return true; + } + } + return false; +} + +ResultPartPtr PartSet_DocumentDataModel::activePart() const +{ + if (myActivePart) + return myActivePart->part(); + return ResultPartPtr(); +} + +void PartSet_DocumentDataModel::deactivatePart() +{ + if (myActivePart) + myActivePart->setItemsColor(PASSIVE_COLOR); + myActivePart = 0; + myActivePartIndex = QModelIndex(); + myModel->setItemsColor(ACTIVE_COLOR); + } + +Qt::ItemFlags PartSet_DocumentDataModel::flags(const QModelIndex& theIndex) const +{ + 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 PartSet_DocumentDataModel::partIndex(const ResultPartPtr& theObject) const +{ + int aRow = -1; + PartSet_PartModel* aModel = 0; + foreach (PartSet_PartModel* aPartModel, myPartModels) + { + aRow++; + if (aPartModel->part() == theObject) { + aModel = aPartModel; + break; + } + } + if (aModel) { + return createIndex(aRow, 0, (void*) getModelIndex(aModel->index(0, 0, QModelIndex()))); + } + return QModelIndex(); +} + +QModelIndex PartSet_DocumentDataModel::objectIndex(const ObjectPtr theObject) const +{ + // Check that this feature belongs to root document + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + DocumentPtr aDoc = theObject->document(); + if (aDoc == aRootDoc) { + // This feature belongs to histrory or top model + FeaturePtr aFeature = std::dynamic_pointer_cast(theObject); + if (aFeature) { + int aId; + int aNb = aRootDoc->size(ModelAPI_Feature::group()); + for (aId = 0; aId < aNb; aId++) { + if (theObject == aRootDoc->object(ModelAPI_Feature::group(), aId)) + break; + } + if (aId < aNb) + return index(aId + historyOffset(), 0, QModelIndex()); + } else { + QModelIndex aIndex = myModel->objectIndex(theObject); + return + aIndex.isValid() ? + createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)) : + QModelIndex(); + } + } else { + PartSet_PartModel* aPartModel = 0; + foreach(PartSet_PartModel* aModel, myPartModels) + { + if (aModel->hasDocument(aDoc)) { + aPartModel = aModel; + break; + } + } + if (aPartModel) { + QModelIndex aIndex = aPartModel->objectIndex(theObject); + return + aIndex.isValid() ? + createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)) : + QModelIndex(); + } + } + return QModelIndex(); +} + + +void PartSet_DocumentDataModel::clear() +{ + clearModelIndexes(); + clearSubModels(); + myActivePart = 0; + 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/PartSet/PartSet_DocumentDataModel.h b/src/PartSet/PartSet_DocumentDataModel.h new file mode 100644 index 000000000..942d157ba --- /dev/null +++ b/src/PartSet/PartSet_DocumentDataModel.h @@ -0,0 +1,196 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +#ifndef PartSet_DocumentDataModel_H +#define PartSet_DocumentDataModel_H + +#include "PartSet.h" +#include +#include +#include +#include + +#include +#include + +class ModelAPI_Document; +class PartSet_PartModel; +class PartSet_TopDataModel; + +/**\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 PARTSET_EXPORT PartSet_DocumentDataModel : public ModuleBase_IDocumentDataModel, public Events_Listener +{ +Q_OBJECT + public: + /// Constructor + /// \param theParent a parent object + PartSet_DocumentDataModel(QObject* theParent); + virtual ~PartSet_DocumentDataModel(); + + /// Event Listener method + /// \param theMessage an event message + virtual void processEvent(const std::shared_ptr& theMessage); + + /// Returns the data stored under the given role for the item referred to by the index. + /// \param theIndex a model index + /// \param theRole a data role (see Qt::ItemDataRole) + virtual QVariant data(const QModelIndex& theIndex, int theRole) const; + + /// Returns the data for the given role and section in the header with the specified orientation. + /// \param theSection a section + /// \param theOrient an orientation + /// \param theRole a data role (see Qt::ItemDataRole) + virtual QVariant headerData(int theSection, Qt::Orientation theOrient, int theRole = + Qt::DisplayRole) const; + + /// Returns the number of rows under the given parent. When the parent is valid it means that + /// rowCount is returning the number of children of parent. + /// \param theParent a parent model index + virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const; + + /// Returns the number of columns for the children of the given parent. + /// It has a one column + /// \param theParent a parent model index + virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const; + + /// Returns the index of the item in the model specified by the given row, column and parent index. + /// \param theRow a row + /// \param theColumn a column + /// \param theParent a parent model index + virtual QModelIndex index(int theRow, int theColumn, const QModelIndex &theParent = + QModelIndex()) const; + + /// Returns the parent of the model item with the given index. + /// If the item has no parent, an invalid QModelIndex is returned. + /// \param theIndex a model index + virtual QModelIndex parent(const QModelIndex& theIndex) const; + + /// Returns true if parent has any children; otherwise returns false. + /// \param theParent a parent model index + virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const; + + /// Inserts count rows into the model before the given row. + /// Items in the new row will be children of the item represented by the parent model index. + /// \param theRow a start row + /// \param theCount a nember of rows to insert + /// \param theParent a parent model index + bool insertRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex()); + + /// Removes count rows starting with the given row under parent parent from the model. + /// \param theRow a start row + /// \param theCount a nember of rows to remove + /// \param theParent a parent model index + bool removeRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex()); + + /// Returns the item flags for the given index. + /// \param theIndex a model index + 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 + virtual ObjectPtr object(const QModelIndex& theIndex) const; + + //! Returns index of the object + //! \param theObject object to find + 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 + //! \param thePart a part for analysis + QModelIndex partIndex(const ResultPartPtr& thePart) const; + + //! 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 activatePart(const QModelIndex& theIndex); + + //! Retrurns active part + ResultPartPtr activePart() const; + + //! Retrurns QModelIndex of active part + QModelIndex activePartIndex() const + { + return myActivePartIndex; + } + + //! Deactivates a Part + void deactivatePart(); + + //! Rebuild data tree + virtual void rebuildDataTree(); + + //! Clear internal data + 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: + + enum + { + PartsFolder, + HistoryNode + }; + + //! Converts QModelIndex of this model to QModelIndex of a one of sub-models. + QModelIndex* toSourceModelIndex(const QModelIndex& theProxy) const; + + //! Finds a pointer on QModelIndex which is equal to the given one + QModelIndex* findModelIndex(const QModelIndex& theIndex) const; + + //! Returns pointer on QModelIndex which is equal to the given one. + QModelIndex* getModelIndex(const QModelIndex& theIndex) const; + + //! Deletes all saved pointers on QModelIndex objects. + void clearModelIndexes(); + + //! Deletes all saved pointers on QModelIndex objects. + void clearSubModels(); + + //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model + void removeSubModel(int theModelId); + + //! Returns true if the given model is a one of sub-models (of both types) + bool isSubModel(const QAbstractItemModel* theModel) const; + + //! Returns true if the given model is a one of sub-models of Part type + bool isPartSubModel(const QAbstractItemModel* theModel) const; + + //! Returns Parts Folder node + //! \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) + PartSet_TopDataModel* myModel; + + //! Data models for Parts data tree representation (one data model per a one part) + QList myPartModels; + + //! Active part in part editing mode + 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/PartSet/PartSet_PartDataModel.cpp b/src/PartSet/PartSet_PartDataModel.cpp new file mode 100644 index 000000000..21896e81a --- /dev/null +++ b/src/PartSet/PartSet_PartDataModel.cpp @@ -0,0 +1,567 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +#include "PartSet_PartDataModel.h" +#include "PartSet_Module.h" +#include "PartSet_DocumentDataModel.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +PartSet_TopDataModel::PartSet_TopDataModel(QObject* theParent) + : PartSet_FeaturesModel(theParent) +{ +} + +PartSet_TopDataModel::~PartSet_TopDataModel() +{ +} + +QVariant PartSet_TopDataModel::data(const QModelIndex& theIndex, int theRole) const +{ + switch (theRole) { + case Qt::DisplayRole: + // return a name + switch (theIndex.internalId()) { + case ParamsFolder: + return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex)); + case ParamObject: { + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameter::group(), theIndex.row()); + if (aObject) { + ResultParameterPtr aParam = std::dynamic_pointer_cast(aObject); + AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE()); + QString aVal = QString::number(aValueAttribute->value()); + QString aTitle = QString(aObject->data()->name().c_str()); + return aTitle + " = " + aVal; + } + } + break; + case ConstructFolder: + return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex)); + case ConstructObject: { + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), + theIndex.row()); + if (aObject) + return aObject->data()->name().c_str(); + } + break; + //case GroupsFolder: + // return tr("Groups") + QString(" (%1)").arg(rowCount(theIndex)); + //case GroupObject: { + // DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + // ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultGroup::group(), + // theIndex.row()); + // if (aObject) + // return aObject->data()->name().c_str(); + //} + // break; + } + break; + + case Qt::DecorationRole: + { + // return an Icon + switch (theIndex.internalId()) { + case ParamsFolder: + return QIcon(":pictures/params_folder.png"); + case ConstructFolder: + return QIcon(":pictures/constr_folder.png"); + case ConstructObject: + return QIcon(":pictures/constr_object.png"); + //case GroupsFolder: + // return QIcon(":pictures/constr_folder.png"); + } + } + break; + + case Qt::ToolTipRole: + // return Tooltip + break; + case Qt::ForegroundRole: + return QBrush(myItemsColor); + break; + } + return QVariant(); +} + +QVariant PartSet_TopDataModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + return QVariant(); +} + +int PartSet_TopDataModel::rowCount(const QModelIndex& theParent) const +{ + if (!theParent.isValid()) + return 2; // In case of groups using it has to be +1 + + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + if (theParent.internalId() == ParamsFolder) + return aRootDoc->size(ModelAPI_ResultParameter::group()); + + if (theParent.internalId() == ConstructFolder) + return aRootDoc->size(ModelAPI_ResultConstruction::group()); + + //if (theParent.internalId() == GroupsFolder) + // return aRootDoc->size(ModelAPI_ResultGroup::group()); + + return 0; +} + +int PartSet_TopDataModel::columnCount(const QModelIndex &parent) const +{ + return 1; +} + +QModelIndex PartSet_TopDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const +{ + if (!theParent.isValid()) { + switch (theRow) { + case 0: + return createIndex(theRow, theColumn, (qint32) ParamsFolder); + case 1: + return createIndex(theRow, theColumn, (qint32) ConstructFolder); + //case 2: + // return createIndex(theRow, theColumn, (qint32) GroupsFolder); + } + } else { + if (theParent.internalId() == ParamsFolder) + return createIndex(theRow, theColumn, (qint32) ParamObject); + + if (theParent.internalId() == ConstructFolder) + return createIndex(theRow, theColumn, (qint32) ConstructObject); + + //if (theParent.internalId() == GroupsFolder) + // return createIndex(theRow, theColumn, (qint32) GroupObject); + } + return QModelIndex(); +} + +QModelIndex PartSet_TopDataModel::parent(const QModelIndex& theIndex) const +{ + int aId = (int) theIndex.internalId(); + switch (aId) { + case ParamsFolder: + case ConstructFolder: + //case GroupsFolder: + return QModelIndex(); + case ParamObject: + return createIndex(0, 0, (qint32) ParamsFolder); + case ConstructObject: + return createIndex(1, 0, (qint32) ConstructFolder); + //case GroupObject: + // return createIndex(2, 0, (qint32) GroupsFolder); + } + return QModelIndex(); +} + +bool PartSet_TopDataModel::hasChildren(const QModelIndex& theParent) const +{ + return rowCount(theParent) > 0; +} + +ObjectPtr PartSet_TopDataModel::object(const QModelIndex& theIndex) const +{ + switch (theIndex.internalId()) { + case ParamsFolder: + case ConstructFolder: + return ObjectPtr(); + case ParamObject: { + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + return aRootDoc->object(ModelAPI_ResultParameter::group(), theIndex.row()); + } + case ConstructObject: { + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + return aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); + } + //case GroupObject: { + // DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + // return aRootDoc->object(ModelAPI_ResultGroup::group(), theIndex.row()); + //} + } + return ObjectPtr(); +} + +QModelIndex PartSet_TopDataModel::findParent(const ObjectPtr& theObject) const +{ + return findGroup(theObject->groupName().c_str()); +} + +QModelIndex PartSet_TopDataModel::findGroup(const std::string& theGroup) const +{ + if (theGroup == ModelAPI_ResultParameter::group()) + return createIndex(0, 0, (qint32) ParamsFolder); + if (theGroup == ModelAPI_ResultConstruction::group()) + return createIndex(1, 0, (qint32) ConstructFolder); + //if (theGroup == ModelAPI_ResultGroup::group()) + // return createIndex(2, 0, (qint32) ConstructFolder); + return QModelIndex(); +} + +QModelIndex PartSet_TopDataModel::objectIndex(const ObjectPtr& theObject) const +{ + QModelIndex aIndex; + if (theObject) { + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + std::string aGroup = theObject->groupName(); + int aNb = aRootDoc->size(aGroup); + int aRow = -1; + for (int i = 0; i < aNb; i++) { + if (aRootDoc->object(aGroup, i) == theObject) { + aRow = i; + break; + } + } + if (aRow != -1) { + if (aGroup == ModelAPI_ResultParameter::group()) + return createIndex(aRow, 0, (qint32) ParamObject); + if (aGroup == ModelAPI_ResultConstruction::group()) + return createIndex(aRow, 0, (qint32) ConstructObject); + //if (aGroup == ModelAPI_ResultGroup::group()) + // return createIndex(aRow, 0, (qint32) GroupObject); + } + } + return aIndex; +} + +//****************************************************************** +//****************************************************************** +//****************************************************************** +PartSet_PartDataModel::PartSet_PartDataModel(QObject* theParent) + : PartSet_PartModel(theParent) +{ +} + +PartSet_PartDataModel::~PartSet_PartDataModel() +{ +} + +QVariant PartSet_PartDataModel::data(const QModelIndex& theIndex, int theRole) const +{ + switch (theRole) { + case Qt::DisplayRole: + // return a name + switch (theIndex.internalId()) { + case MyRoot: { + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId); + if (aObject) + return std::dynamic_pointer_cast(aObject)->data()->name().c_str(); + } + case ParamsFolder: + return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex)); + case ConstructFolder: + return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex)); + case BodiesFolder: + return tr("Bodies") + QString(" (%1)").arg(rowCount(theIndex)); + case GroupsFolder: + return tr("Groups") + QString(" (%1)").arg(rowCount(theIndex)); + case ParamObject: { + ObjectPtr aObject = partDocument()->object(ModelAPI_ResultParameter::group(), + theIndex.row()); + if (aObject) { + ResultParameterPtr aParam = std::dynamic_pointer_cast(aObject); + AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE()); + QString aVal = QString::number(aValueAttribute->value()); + QString aTitle = QString(aObject->data()->name().c_str()); + return aTitle + " = " + aVal; + } + } + break; + case ConstructObject: { + ObjectPtr aObject = partDocument()->object(ModelAPI_ResultConstruction::group(), + theIndex.row()); + if (aObject) + return std::dynamic_pointer_cast(aObject)->data()->name().c_str(); + } + break; + case BodiesObject: { + ObjectPtr aObject = partDocument()->object(ModelAPI_ResultBody::group(), theIndex.row()); + if (aObject) + return aObject->data()->name().c_str(); + } + break; + case GroupObject: { + ObjectPtr aObject = partDocument()->object(ModelAPI_ResultGroup::group(), theIndex.row()); + if (aObject) + return aObject->data()->name().c_str(); + } + case HistoryObject: { + ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber()); + if (aObject) + return aObject->data()->name().c_str(); + } + } + break; + case Qt::DecorationRole: + // return an Icon + switch (theIndex.internalId()) { + case MyRoot: + return QIcon(":pictures/part_ico.png"); + case ParamsFolder: + return QIcon(":pictures/params_folder.png"); + case ConstructFolder: + case BodiesFolder: + return QIcon(":pictures/constr_folder.png"); + case GroupsFolder: + return QIcon(":pictures/constr_folder.png"); + case ConstructObject: + case GroupObject: + case BodiesObject: { + std::string aGroup = theIndex.internalId() == ConstructObject ? + ModelAPI_ResultConstruction::group() : ModelAPI_ResultBody::group(); + ObjectPtr anObject = partDocument()->object(aGroup, theIndex.row()); + if (anObject && anObject->data() && + anObject->data()->execState() == ModelAPI_StateMustBeUpdated) { + return QIcon(":pictures/constr_object_modified.png"); + } + return QIcon(":pictures/constr_object.png"); + } + case HistoryObject: { + ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber()); + FeaturePtr aFeature = std::dynamic_pointer_cast(aObject); + if (aFeature) + return PartSet_DocumentDataModel::featureIcon(aFeature); + } + } + break; + case Qt::ToolTipRole: + // return Tooltip + break; + case Qt::ForegroundRole: + return QBrush(myItemsColor); + break; + } + return QVariant(); +} + +QVariant PartSet_PartDataModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + return QVariant(); +} + +int PartSet_PartDataModel::rowCount(const QModelIndex& parent) const +{ + if (!parent.isValid()) { + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + if (aRootDoc->object(ModelAPI_ResultPart::group(), myId)) + return 1; + else + return 0; + } + switch (parent.internalId()) { + case MyRoot: + { + DocumentPtr aDoc = partDocument(); + if (aDoc) { + return getRowsNumber() + aDoc->size(ModelAPI_Feature::group()); + } else + return 0; + } + case ParamsFolder: + return partDocument()->size(ModelAPI_ResultParameter::group()); + case ConstructFolder: + return partDocument()->size(ModelAPI_ResultConstruction::group()); + case BodiesFolder: + return partDocument()->size(ModelAPI_ResultBody::group()); + case GroupsFolder: + return partDocument()->size(ModelAPI_ResultGroup::group()); + } + return 0; +} + +int PartSet_PartDataModel::columnCount(const QModelIndex &parent) const +{ + return 1; +} + +QModelIndex PartSet_PartDataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const +{ + if (!theParent.isValid()) + return createIndex(theRow, 0, (qint32) MyRoot); + + int aId = (int) theParent.internalId(); + switch (aId) { + case MyRoot: + switch (theRow) { + case 0: + return createIndex(theRow, 0, (qint32) ParamsFolder); + case 1: + return createIndex(theRow, 0, (qint32) ConstructFolder); + case 2: + return createIndex(theRow, 0, (qint32) BodiesFolder); + case 3: + { + int aSize = partDocument()->size(ModelAPI_ResultGroup::group()); + if (aSize > 0) + return createIndex(theRow, 0, (qint32) GroupsFolder); + else + return createIndex(theRow, theColumn, (qint32) HistoryObject); + } + default: + return createIndex(theRow, theColumn, (qint32) HistoryObject); + } + case ParamsFolder: + return createIndex(theRow, 0, (qint32) ParamObject); + case ConstructFolder: + return createIndex(theRow, 0, (qint32) ConstructObject); + case BodiesFolder: + return createIndex(theRow, 0, (qint32) BodiesObject); + case GroupsFolder: + return createIndex(theRow, 0, (qint32) GroupObject); + } + return QModelIndex(); +} + +QModelIndex PartSet_PartDataModel::parent(const QModelIndex& theIndex) const +{ + switch (theIndex.internalId()) { + case MyRoot: + return QModelIndex(); + case ParamsFolder: + case ConstructFolder: + case BodiesFolder: + case GroupsFolder: + case HistoryObject: + return createIndex(0, 0, (qint32) MyRoot); + + case ParamObject: + return createIndex(0, 0, (qint32) ParamsFolder); + case ConstructObject: + return createIndex(1, 0, (qint32) ConstructFolder); + case BodiesObject: + return createIndex(2, 0, (qint32) BodiesFolder); + case GroupObject: + return createIndex(3, 0, (qint32) GroupsFolder); + } + return QModelIndex(); +} + +bool PartSet_PartDataModel::hasChildren(const QModelIndex& theParent) const +{ + return rowCount(theParent) > 0; +} + +DocumentPtr PartSet_PartDataModel::partDocument() const +{ + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId); + ResultPartPtr aPart = std::dynamic_pointer_cast(aObject); + if (aPart) + return aPart->partDoc(); + return DocumentPtr(); // null if not found +} + +ObjectPtr PartSet_PartDataModel::object(const QModelIndex& theIndex) const +{ + switch (theIndex.internalId()) { + case MyRoot: { + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + return aRootDoc->object(ModelAPI_ResultPart::group(), myId); + } + case ParamsFolder: + case ConstructFolder: + case BodiesFolder: + case GroupsFolder: + return ObjectPtr(); + + case ParamObject: + return partDocument()->object(ModelAPI_ResultParameter::group(), theIndex.row()); + case ConstructObject: + return partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row()); + case BodiesObject: + return partDocument()->object(ModelAPI_ResultBody::group(), theIndex.row()); + case GroupObject: + return partDocument()->object(ModelAPI_ResultGroup::group(), theIndex.row()); + case HistoryObject: + return partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber()); + } + return ObjectPtr(); +} + +bool PartSet_PartDataModel::hasDocument(const DocumentPtr& theDoc) const +{ + return (partDocument() == theDoc); +} + +QModelIndex PartSet_PartDataModel::findParent(const ObjectPtr& theObject) const +{ + return findGroup(theObject->groupName().c_str()); +} + +QModelIndex PartSet_PartDataModel::findGroup(const std::string& theGroup) const +{ + if (theGroup == ModelAPI_ResultParameter::group()) + return createIndex(0, 0, (qint32) ParamsFolder); + if (theGroup == ModelAPI_ResultConstruction::group()) + return createIndex(1, 0, (qint32) ConstructFolder); + if (theGroup == ModelAPI_ResultBody::group()) + return createIndex(2, 0, (qint32) BodiesFolder); + if (theGroup == ModelAPI_ResultGroup::group()) + return createIndex(3, 0, (qint32) GroupsFolder); + return QModelIndex(); +} + +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 PartSet_PartDataModel::objectIndex(const ObjectPtr& theObject) const +{ + QModelIndex aIndex; + if (theObject) { + if (part() == theObject) + return aIndex; + + std::string aGroup = theObject->groupName(); + DocumentPtr aDoc = theObject->document(); + int aNb = aDoc->size(aGroup); + int aRow = -1; + for (int i = 0; i < aNb; i++) { + if (aDoc->object(aGroup, i) == theObject) { + aRow = i; + break; + } + } + if (aRow == -1) + return aIndex; + if (aGroup == ModelAPI_ResultParameter::group()) + return createIndex(aRow, 0, (qint32) ParamObject); + else if (aGroup == ModelAPI_ResultConstruction::group()) + return createIndex(aRow, 0, (qint32) ConstructObject); + else if (aGroup == ModelAPI_ResultBody::group()) + return createIndex(aRow, 0, (qint32) BodiesObject); + else if (aGroup == ModelAPI_ResultGroup::group()) + return createIndex(aRow, 0, (qint32) GroupObject); + else + return createIndex(aRow + getRowsNumber(), 0, (qint32) HistoryObject); + } + return aIndex; +} + + +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 + return 3; + return 4; +} \ No newline at end of file diff --git a/src/PartSet/PartSet_PartDataModel.h b/src/PartSet/PartSet_PartDataModel.h new file mode 100644 index 000000000..fc61ec1c5 --- /dev/null +++ b/src/PartSet/PartSet_PartDataModel.h @@ -0,0 +1,191 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +#ifndef PartSet_PartDataModel_H +#define PartSet_PartDataModel_H + +#include "PartSet.h" +#include "PartSet_DataTreeModel.h" + +/**\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 PARTSET_EXPORT PartSet_TopDataModel : public PartSet_FeaturesModel +{ +Q_OBJECT + public: + /// Constructor + /// \param theParent a parent object + PartSet_TopDataModel(QObject* theParent); + virtual ~PartSet_TopDataModel(); + + // Reimpl from QAbstractItemModel + + /// Returns the data stored under the given role for the item referred to by the index. + /// \param theIndex a model index + /// \param theRole a data role (see Qt::ItemDataRole) + virtual QVariant data(const QModelIndex& theIndex, int theRole) const; + + /// Returns the data for the given role and section in the header with the specified orientation. + /// \param theSection a section + /// \param theOrient an orientation + /// \param theRole a data role (see Qt::ItemDataRole) + virtual QVariant headerData(int theSection, Qt::Orientation theOrient, + int theRole = Qt::DisplayRole) const; + + /// Returns the number of rows under the given parent. When the parent is valid it means that + /// rowCount is returning the number of children of parent. + /// \param theParent a parent model index + virtual int rowCount(const QModelIndex &theParent = QModelIndex()) const; + + /// Returns the number of columns for the children of the given parent. + /// It has a one column + /// \param theParent a parent model index + virtual int columnCount(const QModelIndex &theParent = QModelIndex()) const; + + + /// Returns the index of the item in the model specified by the given row, column and parent index. + /// \param theRow a row + /// \param theColumn a column + /// \param theParent a parent model index + virtual QModelIndex index(int theRow, int theColumn, const QModelIndex& theParent = + QModelIndex()) const; + + /// Returns the parent of the model item with the given index. + /// If the item has no parent, an invalid QModelIndex is returned. + /// \param theIndex a model index + virtual QModelIndex parent(const QModelIndex& theIndex) const; + + /// Returns true if parent has any children; otherwise returns false. + /// \param theParent a parent model index + virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const; + + //! Returns object by the given Model index. + //! Returns 0 if the given index is not index of a object + virtual ObjectPtr object(const QModelIndex& theIndex) const; + + //! Returns QModelIndex which corresponds to the given object + //! If the object is not found then index is not valid + virtual QModelIndex objectIndex(const ObjectPtr& theObject) const; + + //! Returns parent index of the given object + virtual QModelIndex findParent(const ObjectPtr& theObject) const; + + //! Returns index corresponded to the group + virtual QModelIndex findGroup(const std::string& theGroup) const; + + private: + //! Types of QModelIndexes + enum DataIds + { + ParamsFolder, + ParamObject, + ConstructFolder, + ConstructObject + //GroupsFolder, + //GroupObject + }; + +}; + +/**\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 PartSet_PartDataModel : public PartSet_PartModel +{ +Q_OBJECT + public: + /// Constructor + /// \param theParent a parent object + PartSet_PartDataModel(QObject* theParent); + virtual ~PartSet_PartDataModel(); + + // Reimpl from QAbstractItemModel + + /// Returns the data stored under the given role for the item referred to by the index. + /// \param theIndex a model index + /// \param theRole a data role (see Qt::ItemDataRole) + virtual QVariant data(const QModelIndex& theIndex, int theRole) const; + + /// Returns the data for the given role and section in the header with the specified orientation. + /// \param theSection a section + /// \param theOrient an orientation + /// \param theRole a data role (see Qt::ItemDataRole) + virtual QVariant headerData(int theSection, Qt::Orientation theOrient, + int theRole = Qt::DisplayRole) const; + + /// Returns the number of rows under the given parent. When the parent is valid it means that + /// rowCount is returning the number of children of parent. + /// \param theParent a parent model index + virtual int rowCount(const QModelIndex &theParent = QModelIndex()) const; + + /// Returns the number of columns for the children of the given parent. + /// It has a one column + /// \param theParent a parent model index + virtual int columnCount(const QModelIndex &theParent = QModelIndex()) const; + + /// Returns the index of the item in the model specified by the given row, column and parent index. + /// \param theRow a row + /// \param theColumn a column + /// \param theParent a parent model index + virtual QModelIndex index(int theRow, int theColumn, const QModelIndex& theParent = + QModelIndex()) const; + + /// Returns the parent of the model item with the given index. + /// If the item has no parent, an invalid QModelIndex is returned. + /// \param theIndex a model index + virtual QModelIndex parent(const QModelIndex& theIndex) const; + + /// Returns true if parent has any children; otherwise returns false. + /// \param theParent a parent model index + virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const; + + //! Returns object by the given Model index. + //! Returns 0 if the given index is not index of a object + virtual ObjectPtr object(const QModelIndex& theIndex) const; + + //! Returns QModelIndex which corresponds to the given object + //! If the object is not found then index is not valid + virtual QModelIndex objectIndex(const ObjectPtr& theObject) const; + + //! Returns true if the given document is a sub-document of this tree + virtual bool hasDocument(const DocumentPtr& theDoc) const; + + //! Returns parent index of the given object + virtual QModelIndex findParent(const ObjectPtr& theObject) const; + + //! Returns index corresponded to the group + virtual QModelIndex findGroup(const std::string& theGroup) const; + + //! Return a Part object + virtual ResultPartPtr part() const; + + private: + + //! Returns document of the current part + DocumentPtr partDocument() const; + + //! Returns defult number of rows + int getRowsNumber() const; + + //! Types of QModelIndexes + enum DataIds + { + MyRoot, + ParamsFolder, + ParamObject, + ConstructFolder, + ConstructObject, + BodiesFolder, + BodiesObject, + GroupsFolder, + GroupObject, + HistoryObject + }; + +}; + +#endif 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/PartSet/icons/activate.png b/src/PartSet/icons/activate.png new file mode 100644 index 000000000..f82917927 Binary files /dev/null and b/src/PartSet/icons/activate.png differ diff --git a/src/PartSet/icons/deactivate.png b/src/PartSet/icons/deactivate.png new file mode 100644 index 000000000..1b1c71aaa Binary files /dev/null and b/src/PartSet/icons/deactivate.png differ diff --git a/src/PartSet/icons/edit.png b/src/PartSet/icons/edit.png new file mode 100644 index 000000000..43a317420 Binary files /dev/null and b/src/PartSet/icons/edit.png differ diff --git a/src/PartSet/icons/exec_state_failed.png b/src/PartSet/icons/exec_state_failed.png new file mode 100644 index 000000000..738f30371 Binary files /dev/null and b/src/PartSet/icons/exec_state_failed.png differ diff --git a/src/PartSet/icons/exec_state_invalid_parameters.png b/src/PartSet/icons/exec_state_invalid_parameters.png new file mode 100644 index 000000000..1346f9709 Binary files /dev/null and b/src/PartSet/icons/exec_state_invalid_parameters.png differ 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_DataTreeModel.h b/src/XGUI/XGUI_DataTreeModel.h deleted file mode 100644 index fb28e59f8..000000000 --- a/src/XGUI/XGUI_DataTreeModel.h +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -#ifndef XGUI_DataTreeModel_H -#define XGUI_DataTreeModel_H - -#include "XGUI.h" - -#include -#include -#include - -#include -#include - -/**\class XGUI_FeaturesModel - * \ingroup GUI - * \brief Abstaract class of model object which operates with features data. - */ -class XGUI_EXPORT XGUI_FeaturesModel : public QAbstractItemModel -{ - public: - /// Constructor - /// \param theParent a parent object - XGUI_FeaturesModel(QObject* theParent) - : QAbstractItemModel(theParent), - myItemsColor(Qt::black) - { - } - - //! Returns Feature object by the given Model index. - //! Returns 0 if the given index is not index of a feature - /// \param theIndex a model index - virtual ObjectPtr object(const QModelIndex& theIndex) const = 0; - - //! Returns QModelIndex which corresponds to the given feature - //! If the feature is not found then index is not valid - virtual QModelIndex objectIndex(const ObjectPtr& theFeature) const = 0; - - //! Returns parent index of the given feature - virtual QModelIndex findParent(const ObjectPtr& theObject) const = 0; - - //! Returns index corresponded to the group - //! \param theGroup a group name - virtual QModelIndex findGroup(const std::string& theGroup) const = 0; - - //! Set color of items - void setItemsColor(const QColor& theColor) - { - myItemsColor = theColor; - } - - //! Returns color of items - QColor itemsColor() const - { - return myItemsColor; - } - - protected: - /// Color of items - QColor myItemsColor; -}; - -/**\class XGUI_PartModel - * \ingroup GUI - * \brief Abstaract class of model object which operates with parts data. - */ -class XGUI_PartModel : public XGUI_FeaturesModel -{ - public: - /// Constructor - /// \param theParent a parent object - XGUI_PartModel(QObject* theParent) - : XGUI_FeaturesModel(theParent) - { - } - - /// Set part id - /// \param theId a new id - void setPartId(int theId) - { - myId = theId; - } - - //! Returns true if the given document is a sub-document of this tree - //! \param theDoc a document to check - virtual bool hasDocument(const DocumentPtr& theDoc) const = 0; - - //! Return a Part object - virtual ResultPartPtr part() const = 0; - - protected: - //! Id of the current part object in the document - int myId; -}; - -#endif diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp deleted file mode 100644 index 24434261b..000000000 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ /dev/null @@ -1,592 +0,0 @@ -// 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 -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include -#include -#include - -#include - -#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)); - - // Create a top part of data tree model - myModel = new XGUI_TopDataModel(this); - myModel->setItemsColor(ACTIVE_COLOR); -} - -XGUI_DocumentDataModel::~XGUI_DocumentDataModel() -{ - clearModelIndexes(); - clearSubModels(); -} - -void XGUI_DocumentDataModel::processEvent(const std::shared_ptr& theMessage) -{ - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - - // Created object event ******************* - if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) { - std::shared_ptr aUpdMsg = - std::dynamic_pointer_cast(theMessage); - std::set aObjects = aUpdMsg->objects(); - - std::set::const_iterator aIt; - for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) { - ObjectPtr aObject = (*aIt); - FeaturePtr aFeature = std::dynamic_pointer_cast(aObject); - if (aFeature && (!aFeature->isInHistory())) - continue; - - DocumentPtr aDoc = aObject->document(); - if (aDoc == aRootDoc) { // If root objects - 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); - aModel->setPartId(myPartModels.count()); - myPartModels.append(aModel); - insertRow(aStart, partFolderNode()); - } else { // Update top groups (other except parts - QModelIndex aIndex = myModel->findParent(aObject); - int aStart = myModel->rowCount(aIndex) - 1; - if (aStart < 0) - aStart = 0; - aIndex = createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)); - insertRow(aStart, aIndex); - } - } else { // if sub-objects of first level nodes - XGUI_PartModel* aPartModel = 0; - foreach (XGUI_PartModel* aPart, myPartModels) { - if (aPart->hasDocument(aDoc)) { - aPartModel = aPart; - break; - } - } - if (aPartModel) { - QModelIndex aIndex = aPartModel->findParent(aObject); - int aStart = aPartModel->rowCount(aIndex); // check this index - aIndex = createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)); - insertRow(aStart, aIndex); - } else - reset(); - } - } - // Deleted object event *********************** - } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { - std::shared_ptr aUpdMsg = - std::dynamic_pointer_cast(theMessage); - DocumentPtr aDoc = aUpdMsg->document(); - std::set aGroups = aUpdMsg->groups(); - - std::set::const_iterator aIt; - for (aIt = aGroups.begin(); aIt != aGroups.end(); ++aIt) { - std::string aGroup = (*aIt); - if (aDoc == aRootDoc) { // If root objects - if (aGroup == ModelAPI_ResultPart::group()) { // Update only Parts group - int aStart = myPartModels.size() - 1; - if (aStart >= 0) {// MPV: this could be reproduced on close - removeSubModel(aStart); - removeRow(aStart, partFolderNode()); - if (myActivePart && (!isPartSubModel(myActivePart))) { - myActivePart = 0; - myActivePartIndex = QModelIndex(); - myModel->setItemsColor(ACTIVE_COLOR); - } - } - } else { // Update top groups (other except parts - QModelIndex aIndex = myModel->findGroup(aGroup); - int aStart = myModel->rowCount(aIndex); - aIndex = createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)); - removeRow(aStart, aIndex); - } - } else { - XGUI_PartModel* aPartModel = 0; - foreach (XGUI_PartModel* aPart, myPartModels) { - if (aPart->hasDocument(aDoc)) { - aPartModel = aPart; - break; - } - } - if (aPartModel) { - QModelIndex aIndex = aPartModel->findGroup(aGroup); - int aStart = aPartModel->rowCount(aIndex); - aIndex = createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)); - removeRow(aStart, aIndex); - } - } - } - // Deleted object event *********************** - } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) { - //std::shared_ptr aUpdMsg = std::dynamic_pointer_cast(theMessage); - //ObjectPtr aFeature = aUpdMsg->feature(); - //DocumentPtr aDoc = aFeature->document(); - - // TODO: Identify the necessary index by the modified feature - QModelIndex aIndex; - emit dataChanged(aIndex, aIndex); - - // Reset whole tree ************************** - } else { - rebuildDataTree(); - } -} - -void XGUI_DocumentDataModel::rebuildDataTree() -{ - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - - beginResetModel(); - clearModelIndexes(); - - int aNbParts = aRootDoc->size(ModelAPI_ResultPart::group()); - if (myPartModels.size() != aNbParts) { // resize internal models - while (myPartModels.size() > aNbParts) { - delete myPartModels.last(); - myPartModels.removeLast(); - } - while (myPartModels.size() < aNbParts) { - myPartModels.append(new XGUI_PartDataModel(this)); - } - for (int i = 0; i < myPartModels.size(); i++) - myPartModels.at(i)->setPartId(i); - } - endResetModel(); -} - -QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) const -{ - if (!theIndex.isValid()) - return QVariant(); - switch (theIndex.internalId()) { - case PartsFolder: - switch (theRole) { - case Qt::DisplayRole: - return tr("Parts") + QString(" (%1)").arg(rowCount(theIndex)); - case Qt::DecorationRole: - return QIcon(":pictures/constr_folder.png"); - case Qt::ToolTipRole: - return tr("Parts folder"); - case Qt::ForegroundRole: - if (myActivePart) - 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 aFeature->data()->name().c_str(); - else - return QVariant(); - case Qt::DecorationRole: - return XGUI_Workshop::featureIcon(aFeature); - case Qt::ToolTipRole: - return tr("Feature object"); - case Qt::ForegroundRole: - if (myActivePart) - return QBrush(PASSIVE_COLOR); - else - return QBrush(ACTIVE_COLOR); - default: - return QVariant(); - } - } - break; - } - QModelIndex aParent = theIndex.parent(); - 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, - int theRole) const -{ - return QVariant(); -} - -int XGUI_DocumentDataModel::rowCount(const QModelIndex& theParent) const -{ - if (!theParent.isValid()) { - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - // Size of external models - int aVal = historyOffset(); - // Plus history size - aVal += aRootDoc->size(ModelAPI_Feature::group()); - return aVal; - } - if (theParent.internalId() == PartsFolder) { - int aSize = myPartModels.size(); - return myPartModels.size(); - } - if (theParent.internalId() == HistoryNode) { - return 0; - } - QModelIndex* aParent = toSourceModelIndex(theParent); - const QAbstractItemModel* aModel = aParent->model(); - if (!isSubModel(aModel)) - return 0; - - /*if (isPartSubModel(aModel)) { - if (aModel != myActivePart) - return 0; - }*/ - return aModel->rowCount(*aParent); -} - -int XGUI_DocumentDataModel::columnCount(const QModelIndex& theParent) const -{ - return 1; -} - -QModelIndex XGUI_DocumentDataModel::index(int theRow, int theColumn, - const QModelIndex& theParent) const -{ - QModelIndex aIndex; - if (!theParent.isValid()) { - int aOffs = myModel->rowCount(); - if (theRow < aOffs) { - aIndex = myModel->index(theRow, theColumn, theParent); - aIndex = createIndex(theRow, theColumn, (void*) getModelIndex(aIndex)); - } else { - if (theRow == aOffs) // Create Parts node - aIndex = partFolderNode(); - else - // create history node - aIndex = createIndex(theRow, theColumn, HistoryNode); - } - } else { - if (theParent.internalId() == PartsFolder) { - aIndex = myPartModels.at(theRow)->index(0, theColumn, QModelIndex()); - } else { - QModelIndex* aParent = (QModelIndex*) theParent.internalPointer(); - aIndex = aParent->model()->index(theRow, theColumn, (*aParent)); - } - aIndex = createIndex(theRow, theColumn, (void*) getModelIndex(aIndex)); - } - return aIndex; -} - -QModelIndex XGUI_DocumentDataModel::parent(const QModelIndex& theIndex) const -{ - if ((theIndex.internalId() == PartsFolder) || (theIndex.internalId() == HistoryNode)) - return QModelIndex(); - - QModelIndex* aIndex = toSourceModelIndex(theIndex); - const QAbstractItemModel* aModel = aIndex->model(); - if (!isSubModel(aModel)) - return QModelIndex(); - - if (isPartSubModel(aModel)) { - if (!aModel->parent(*aIndex).isValid()) { - return partFolderNode(); - } - } - - QModelIndex aIndex1 = aModel->parent(*aIndex); - if (aIndex1.isValid()) - return createIndex(aIndex1.row(), aIndex1.column(), (void*) getModelIndex(aIndex1)); - return aIndex1; -} - -bool XGUI_DocumentDataModel::hasChildren(const QModelIndex& theParent) const -{ - if (!theParent.isValid()) - return true; - return rowCount(theParent) > 0; -} - -QModelIndex* XGUI_DocumentDataModel::toSourceModelIndex(const QModelIndex& theProxy) const -{ - QModelIndex* aIndexPtr = static_cast(theProxy.internalPointer()); - return aIndexPtr; -} - -QModelIndex* XGUI_DocumentDataModel::findModelIndex(const QModelIndex& theIndex) const -{ - QList::const_iterator aIt; - for (aIt = myIndexes.constBegin(); aIt != myIndexes.constEnd(); ++aIt) { - QModelIndex* aIndex = (*aIt); - if ((*aIndex) == theIndex) - return aIndex; - } - return 0; -} - -QModelIndex* XGUI_DocumentDataModel::getModelIndex(const QModelIndex& theIndex) const -{ - QModelIndex* aIndexPtr = findModelIndex(theIndex); - if (!aIndexPtr) { - aIndexPtr = new QModelIndex(theIndex); - XGUI_DocumentDataModel* that = (XGUI_DocumentDataModel*) this; - that->myIndexes.append(aIndexPtr); - } - return aIndexPtr; -} - -void XGUI_DocumentDataModel::clearModelIndexes() -{ - foreach (QModelIndex* aIndex, myIndexes) - delete aIndex; - myIndexes.clear(); -} - -void XGUI_DocumentDataModel::clearSubModels() -{ - foreach (XGUI_PartModel* aPart, myPartModels) - delete aPart; - myPartModels.clear(); -} - -ObjectPtr XGUI_DocumentDataModel::object(const QModelIndex& theIndex) const -{ - if (theIndex.internalId() == PartsFolder) - return ObjectPtr(); - if (theIndex.internalId() == HistoryNode) { - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - int aOffset = historyOffset(); - return aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset); - } - QModelIndex* aIndex = toSourceModelIndex(theIndex); - if (!isSubModel(aIndex->model())) - return ObjectPtr(); - - const XGUI_FeaturesModel* aModel = dynamic_cast(aIndex->model()); - return aModel->object(*aIndex); -} - -bool XGUI_DocumentDataModel::insertRows(int theRow, int theCount, const QModelIndex& theParent) -{ - beginInsertRows(theParent, theRow, theRow + theCount - 1); - //endInsertRows(); - - // Update history - QModelIndex aRoot; - int aRow = rowCount(aRoot); - beginInsertRows(aRoot, aRow, aRow); - endInsertRows(); - - return true; -} - -bool XGUI_DocumentDataModel::removeRows(int theRow, int theCount, const QModelIndex& theParent) -{ - beginRemoveRows(theParent, theRow, theRow + theCount - 1); - endRemoveRows(); - return true; -} - -void XGUI_DocumentDataModel::removeSubModel(int theModelId) -{ - XGUI_PartModel* aModel = myPartModels.at(theModelId); - QIntList aToRemove; - for (int i = 0; i < myIndexes.size(); i++) { - if (myIndexes.at(i)->model() == aModel) - aToRemove.append(i); - } - int aId; - while (aToRemove.size() > 0) { - aId = aToRemove.last(); - delete myIndexes.at(aId); - myIndexes.removeAt(aId); - aToRemove.removeLast(); - } - delete aModel; - myPartModels.removeAt(theModelId); -} - -bool XGUI_DocumentDataModel::isSubModel(const QAbstractItemModel* theModel) const -{ - if (theModel == myModel) - return true; - return isPartSubModel(theModel); -} - -bool XGUI_DocumentDataModel::isPartSubModel(const QAbstractItemModel* theModel) const -{ - return myPartModels.contains((XGUI_PartModel*) theModel); -} - -QModelIndex XGUI_DocumentDataModel::partFolderNode() const -{ - int aPos = myModel->rowCount(QModelIndex()); - return createIndex(aPos, columnCount() - 1, PartsFolder); -} - -int XGUI_DocumentDataModel::historyOffset() const -{ - // Nb of rows of top model + Parts folder - return myModel->rowCount(QModelIndex()) + 1; -} - -bool XGUI_DocumentDataModel::activatedIndex(const QModelIndex& theIndex) -{ - if ((theIndex.internalId() == PartsFolder) || (theIndex.internalId() == HistoryNode)) - return false; - - QModelIndex* aIndex = toSourceModelIndex(theIndex); - if (!aIndex) - return false; - - const QAbstractItemModel* aModel = aIndex->model(); - - if (isPartSubModel(aModel)) { - // if this is root node (Part item index) - if (!aIndex->parent().isValid()) { - if (myActivePart) - myActivePart->setItemsColor(PASSIVE_COLOR); - - if (myActivePart == aModel) { - myActivePart = 0; - myActivePartIndex = QModelIndex(); - } else { - myActivePart = (XGUI_PartModel*)aModel; - myActivePartIndex = theIndex; - } - - if (myActivePart) { - myActivePart->setItemsColor(ACTIVE_COLOR); - myModel->setItemsColor(PASSIVE_COLOR); - } else - myModel->setItemsColor(ACTIVE_COLOR); - return true; - } - } - return false; -} - -ResultPartPtr XGUI_DocumentDataModel::activePart() const -{ - if (myActivePart) - return myActivePart->part(); - return ResultPartPtr(); -} - -void XGUI_DocumentDataModel::deactivatePart() -{ - if (myActivePart) - myActivePart->setItemsColor(PASSIVE_COLOR); - myActivePart = 0; - myActivePartIndex = QModelIndex(); - myModel->setItemsColor(ACTIVE_COLOR); - } - -Qt::ItemFlags XGUI_DocumentDataModel::flags(const QModelIndex& theIndex) const -{ - Qt::ItemFlags aFlags = QAbstractItemModel::flags(theIndex); - if (object(theIndex)) { - aFlags |= Qt::ItemIsEditable; - } - return aFlags; -} - -QModelIndex XGUI_DocumentDataModel::partIndex(const ResultPartPtr& theObject) const -{ - int aRow = -1; - XGUI_PartModel* aModel = 0; - foreach (XGUI_PartModel* aPartModel, myPartModels) - { - aRow++; - if (aPartModel->part() == theObject) { - aModel = aPartModel; - break; - } - } - if (aModel) { - return createIndex(aRow, 0, (void*) getModelIndex(aModel->index(0, 0, QModelIndex()))); - } - return QModelIndex(); -} - -QModelIndex XGUI_DocumentDataModel::objectIndex(const ObjectPtr theObject) const -{ - // Check that this feature belongs to root document - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - DocumentPtr aDoc = theObject->document(); - if (aDoc == aRootDoc) { - // This feature belongs to histrory or top model - FeaturePtr aFeature = std::dynamic_pointer_cast(theObject); - if (aFeature) { - int aId; - int aNb = aRootDoc->size(ModelAPI_Feature::group()); - for (aId = 0; aId < aNb; aId++) { - if (theObject == aRootDoc->object(ModelAPI_Feature::group(), aId)) - break; - } - if (aId < aNb) - return index(aId + historyOffset(), 0, QModelIndex()); - } else { - QModelIndex aIndex = myModel->objectIndex(theObject); - return - aIndex.isValid() ? - createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)) : - QModelIndex(); - } - } else { - XGUI_PartModel* aPartModel = 0; - foreach(XGUI_PartModel* aModel, myPartModels) - { - if (aModel->hasDocument(aDoc)) { - aPartModel = aModel; - break; - } - } - if (aPartModel) { - QModelIndex aIndex = aPartModel->objectIndex(theObject); - return - aIndex.isValid() ? - createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)) : - QModelIndex(); - } - } - return QModelIndex(); -} - - -void XGUI_DocumentDataModel::clear() -{ - clearModelIndexes(); - clearSubModels(); - myActivePart = 0; - myActivePartIndex = QModelIndex(); - myModel->setItemsColor(ACTIVE_COLOR); -} diff --git a/src/XGUI/XGUI_DocumentDataModel.h b/src/XGUI/XGUI_DocumentDataModel.h deleted file mode 100644 index 63fa17a9f..000000000 --- a/src/XGUI/XGUI_DocumentDataModel.h +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -#ifndef XGUI_DocumentDataModel_H -#define XGUI_DocumentDataModel_H - -#include "XGUI.h" -#include -#include - -#include - -#include -#include - -class ModelAPI_Document; -class XGUI_PartModel; -class XGUI_TopDataModel; - -/**\class XGUI_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 -{ -Q_OBJECT - public: - /// Constructor - /// \param theParent a parent object - XGUI_DocumentDataModel(QObject* theParent); - virtual ~XGUI_DocumentDataModel(); - - /// Event Listener method - /// \param theMessage an event message - virtual void processEvent(const std::shared_ptr& theMessage); - - /// Returns the data stored under the given role for the item referred to by the index. - /// \param theIndex a model index - /// \param theRole a data role (see Qt::ItemDataRole) - virtual QVariant data(const QModelIndex& theIndex, int theRole) const; - - /// Returns the data for the given role and section in the header with the specified orientation. - /// \param theSection a section - /// \param theOrient an orientation - /// \param theRole a data role (see Qt::ItemDataRole) - virtual QVariant headerData(int theSection, Qt::Orientation theOrient, int theRole = - Qt::DisplayRole) const; - - /// Returns the number of rows under the given parent. When the parent is valid it means that - /// rowCount is returning the number of children of parent. - /// \param theParent a parent model index - virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const; - - /// Returns the number of columns for the children of the given parent. - /// It has a one column - /// \param theParent a parent model index - virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const; - - /// Returns the index of the item in the model specified by the given row, column and parent index. - /// \param theRow a row - /// \param theColumn a column - /// \param theParent a parent model index - virtual QModelIndex index(int theRow, int theColumn, const QModelIndex &theParent = - QModelIndex()) const; - - /// Returns the parent of the model item with the given index. - /// If the item has no parent, an invalid QModelIndex is returned. - /// \param theIndex a model index - virtual QModelIndex parent(const QModelIndex& theIndex) const; - - /// Returns true if parent has any children; otherwise returns false. - /// \param theParent a parent model index - virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const; - - /// Inserts count rows into the model before the given row. - /// Items in the new row will be children of the item represented by the parent model index. - /// \param theRow a start row - /// \param theCount a nember of rows to insert - /// \param theParent a parent model index - bool insertRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex()); - - /// Removes count rows starting with the given row under parent parent from the model. - /// \param theRow a start row - /// \param theCount a nember of rows to remove - /// \param theParent a parent model index - bool removeRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex()); - - /// Returns the item flags for the given index. - /// \param theIndex a model index - 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; - - //! Returns index of the object - //! \param theObject object to find - 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 - //! \param thePart a part for analysis - QModelIndex partIndex(const ResultPartPtr& thePart) const; - - //! 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); - - //! Retrurns active part - ResultPartPtr activePart() const; - - //! Retrurns QModelIndex of active part - QModelIndex activePartIndex() const - { - return myActivePartIndex; - } - - //! Deactivates a Part - void deactivatePart(); - - //! Rebuild data tree - void rebuildDataTree(); - - //! Clear internal data - void clear(); - - - private: - - enum - { - PartsFolder, - HistoryNode - }; - - //! Converts QModelIndex of this model to QModelIndex of a one of sub-models. - QModelIndex* toSourceModelIndex(const QModelIndex& theProxy) const; - - //! Finds a pointer on QModelIndex which is equal to the given one - QModelIndex* findModelIndex(const QModelIndex& theIndex) const; - - //! Returns pointer on QModelIndex which is equal to the given one. - QModelIndex* getModelIndex(const QModelIndex& theIndex) const; - - //! Deletes all saved pointers on QModelIndex objects. - void clearModelIndexes(); - - //! Deletes all saved pointers on QModelIndex objects. - void clearSubModels(); - - //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model - void removeSubModel(int theModelId); - - //! Returns true if the given model is a one of sub-models (of both types) - bool isSubModel(const QAbstractItemModel* theModel) const; - - //! Returns true if the given model is a one of sub-models of Part type - bool isPartSubModel(const QAbstractItemModel* theModel) const; - - //! Returns Parts Folder node - QModelIndex partFolderNode() const; - - int historyOffset() const; - - //! Data model of top part of data tree (not parts object) - XGUI_TopDataModel* myModel; - - //! Data models for Parts data tree representation (one data model per a one part) - QList myPartModels; - - //! Active part in part editing mode - XGUI_PartModel* myActivePart; - - QModelIndex myActivePartIndex; - - //! List of saved QModelIndexes created by sub-models - QList myIndexes; - -}; - -#endif 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_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp deleted file mode 100644 index bbf0ef9fc..000000000 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ /dev/null @@ -1,573 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -#include "XGUI_PartDataModel.h" -#include "XGUI_Workshop.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#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) -{ -} - -XGUI_TopDataModel::~XGUI_TopDataModel() -{ -} - -QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const -{ - switch (theRole) { - case Qt::DisplayRole: - // return a name - switch (theIndex.internalId()) { - case ParamsFolder: - return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex)); - case ParamObject: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameter::group(), theIndex.row()); - if (aObject) { - ResultParameterPtr aParam = std::dynamic_pointer_cast(aObject); - AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE()); - QString aVal = QString::number(aValueAttribute->value()); - QString aTitle = QString(aObject->data()->name().c_str()); - return aTitle + " = " + aVal; - } - } - break; - case ConstructFolder: - return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex)); - case ConstructObject: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), - theIndex.row()); - if (aObject) - return aObject->data()->name().c_str(); - } - break; - //case GroupsFolder: - // return tr("Groups") + QString(" (%1)").arg(rowCount(theIndex)); - //case GroupObject: { - // DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - // ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultGroup::group(), - // theIndex.row()); - // if (aObject) - // return aObject->data()->name().c_str(); - //} - // break; - } - break; - - case Qt::DecorationRole: - { - // return an Icon - switch (theIndex.internalId()) { - case ParamsFolder: - return QIcon(":pictures/params_folder.png"); - case ConstructFolder: - return QIcon(":pictures/constr_folder.png"); - case ConstructObject: - return QIcon(":pictures/constr_object.png"); - //case GroupsFolder: - // return QIcon(":pictures/constr_folder.png"); - } - } - break; - - case Qt::ToolTipRole: - // return Tooltip - break; - case Qt::ForegroundRole: - return QBrush(myItemsColor); - break; - } - return QVariant(); -} - -QVariant XGUI_TopDataModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - return QVariant(); -} - -int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const -{ - if (!theParent.isValid()) - return 2; // In case of groups using it has to be +1 - - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - if (theParent.internalId() == ParamsFolder) - return aRootDoc->size(ModelAPI_ResultParameter::group()); - - if (theParent.internalId() == ConstructFolder) - return aRootDoc->size(ModelAPI_ResultConstruction::group()); - - //if (theParent.internalId() == GroupsFolder) - // return aRootDoc->size(ModelAPI_ResultGroup::group()); - - return 0; -} - -int XGUI_TopDataModel::columnCount(const QModelIndex &parent) const -{ - return 1; -} - -QModelIndex XGUI_TopDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const -{ - if (!theParent.isValid()) { - switch (theRow) { - case 0: - return createIndex(theRow, theColumn, (qint32) ParamsFolder); - case 1: - return createIndex(theRow, theColumn, (qint32) ConstructFolder); - //case 2: - // return createIndex(theRow, theColumn, (qint32) GroupsFolder); - } - } else { - if (theParent.internalId() == ParamsFolder) - return createIndex(theRow, theColumn, (qint32) ParamObject); - - if (theParent.internalId() == ConstructFolder) - return createIndex(theRow, theColumn, (qint32) ConstructObject); - - //if (theParent.internalId() == GroupsFolder) - // return createIndex(theRow, theColumn, (qint32) GroupObject); - } - return QModelIndex(); -} - -QModelIndex XGUI_TopDataModel::parent(const QModelIndex& theIndex) const -{ - int aId = (int) theIndex.internalId(); - switch (aId) { - case ParamsFolder: - case ConstructFolder: - //case GroupsFolder: - return QModelIndex(); - case ParamObject: - return createIndex(0, 0, (qint32) ParamsFolder); - case ConstructObject: - return createIndex(1, 0, (qint32) ConstructFolder); - //case GroupObject: - // return createIndex(2, 0, (qint32) GroupsFolder); - } - return QModelIndex(); -} - -bool XGUI_TopDataModel::hasChildren(const QModelIndex& theParent) const -{ - return rowCount(theParent) > 0; -} - -ObjectPtr XGUI_TopDataModel::object(const QModelIndex& theIndex) const -{ - switch (theIndex.internalId()) { - case ParamsFolder: - case ConstructFolder: - return ObjectPtr(); - case ParamObject: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - return aRootDoc->object(ModelAPI_ResultParameter::group(), theIndex.row()); - } - case ConstructObject: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - return aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); - } - //case GroupObject: { - // DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - // return aRootDoc->object(ModelAPI_ResultGroup::group(), theIndex.row()); - //} - } - return ObjectPtr(); -} - -QModelIndex XGUI_TopDataModel::findParent(const ObjectPtr& theObject) const -{ - return findGroup(theObject->groupName().c_str()); -} - -QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const -{ - if (theGroup == ModelAPI_ResultParameter::group()) - return createIndex(0, 0, (qint32) ParamsFolder); - if (theGroup == ModelAPI_ResultConstruction::group()) - return createIndex(1, 0, (qint32) ConstructFolder); - //if (theGroup == ModelAPI_ResultGroup::group()) - // return createIndex(2, 0, (qint32) ConstructFolder); - return QModelIndex(); -} - -QModelIndex XGUI_TopDataModel::objectIndex(const ObjectPtr& theObject) const -{ - QModelIndex aIndex; - if (theObject) { - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - std::string aGroup = theObject->groupName(); - int aNb = aRootDoc->size(aGroup); - int aRow = -1; - for (int i = 0; i < aNb; i++) { - if (aRootDoc->object(aGroup, i) == theObject) { - aRow = i; - break; - } - } - if (aRow != -1) { - if (aGroup == ModelAPI_ResultParameter::group()) - return createIndex(aRow, 0, (qint32) ParamObject); - if (aGroup == ModelAPI_ResultConstruction::group()) - return createIndex(aRow, 0, (qint32) ConstructObject); - //if (aGroup == ModelAPI_ResultGroup::group()) - // return createIndex(aRow, 0, (qint32) GroupObject); - } - } - return aIndex; -} - -//****************************************************************** -//****************************************************************** -//****************************************************************** -XGUI_PartDataModel::XGUI_PartDataModel(QObject* theParent) - : XGUI_PartModel(theParent) -{ -} - -XGUI_PartDataModel::~XGUI_PartDataModel() -{ -} - -QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) const -{ - switch (theRole) { - case Qt::DisplayRole: - // return a name - switch (theIndex.internalId()) { - case MyRoot: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId); - if (aObject) - return std::dynamic_pointer_cast(aObject)->data()->name().c_str(); - } - case ParamsFolder: - return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex)); - case ConstructFolder: - return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex)); - case BodiesFolder: - return tr("Bodies") + QString(" (%1)").arg(rowCount(theIndex)); - case GroupsFolder: - return tr("Groups") + QString(" (%1)").arg(rowCount(theIndex)); - case ParamObject: { - ObjectPtr aObject = partDocument()->object(ModelAPI_ResultParameter::group(), - theIndex.row()); - if (aObject) { - ResultParameterPtr aParam = std::dynamic_pointer_cast(aObject); - AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE()); - QString aVal = QString::number(aValueAttribute->value()); - QString aTitle = QString(aObject->data()->name().c_str()); - return aTitle + " = " + aVal; - } - } - break; - case ConstructObject: { - ObjectPtr aObject = partDocument()->object(ModelAPI_ResultConstruction::group(), - theIndex.row()); - if (aObject) - return std::dynamic_pointer_cast(aObject)->data()->name().c_str(); - } - break; - case BodiesObject: { - ObjectPtr aObject = partDocument()->object(ModelAPI_ResultBody::group(), theIndex.row()); - if (aObject) - return aObject->data()->name().c_str(); - } - break; - case GroupObject: { - ObjectPtr aObject = partDocument()->object(ModelAPI_ResultGroup::group(), theIndex.row()); - if (aObject) - return aObject->data()->name().c_str(); - } - case HistoryObject: { - ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber()); - if (aObject) - return aObject->data()->name().c_str(); - } - } - break; - case Qt::DecorationRole: - // return an Icon - switch (theIndex.internalId()) { - case MyRoot: - return QIcon(":pictures/part_ico.png"); - case ParamsFolder: - return QIcon(":pictures/params_folder.png"); - case ConstructFolder: - case BodiesFolder: - return QIcon(":pictures/constr_folder.png"); - case GroupsFolder: - return QIcon(":pictures/constr_folder.png"); - case ConstructObject: - case GroupObject: - case BodiesObject: { - std::string aGroup = theIndex.internalId() == ConstructObject ? - ModelAPI_ResultConstruction::group() : ModelAPI_ResultBody::group(); - ObjectPtr anObject = partDocument()->object(aGroup, theIndex.row()); - if (anObject && anObject->data() && - anObject->data()->execState() == ModelAPI_StateMustBeUpdated) { - return QIcon(":pictures/constr_object_modified.png"); - } - return QIcon(":pictures/constr_object.png"); - } - case HistoryObject: { - ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber()); - FeaturePtr aFeature = std::dynamic_pointer_cast(aObject); - if (aFeature) - return XGUI_Workshop::featureIcon(aFeature); - } - } - break; - case Qt::ToolTipRole: - // return Tooltip - break; - case Qt::ForegroundRole: - return QBrush(myItemsColor); - break; - } - return QVariant(); -} - -QVariant XGUI_PartDataModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - return QVariant(); -} - -int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const -{ - if (!parent.isValid()) { - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - if (aRootDoc->object(ModelAPI_ResultPart::group(), myId)) - return 1; - else - return 0; - } - switch (parent.internalId()) { - case MyRoot: - { - DocumentPtr aDoc = partDocument(); - if (aDoc) { - return getRowsNumber() + aDoc->size(ModelAPI_Feature::group()); - } else - return 0; - } - case ParamsFolder: - return partDocument()->size(ModelAPI_ResultParameter::group()); - case ConstructFolder: - return partDocument()->size(ModelAPI_ResultConstruction::group()); - case BodiesFolder: - return partDocument()->size(ModelAPI_ResultBody::group()); - case GroupsFolder: - return partDocument()->size(ModelAPI_ResultGroup::group()); - } - return 0; -} - -int XGUI_PartDataModel::columnCount(const QModelIndex &parent) const -{ - return 1; -} - -QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const -{ - if (!theParent.isValid()) - return createIndex(theRow, 0, (qint32) MyRoot); - - int aId = (int) theParent.internalId(); - switch (aId) { - case MyRoot: - switch (theRow) { - case 0: - return createIndex(theRow, 0, (qint32) ParamsFolder); - case 1: - return createIndex(theRow, 0, (qint32) ConstructFolder); - case 2: - return createIndex(theRow, 0, (qint32) BodiesFolder); - case 3: - { - int aSize = partDocument()->size(ModelAPI_ResultGroup::group()); - if (aSize > 0) - return createIndex(theRow, 0, (qint32) GroupsFolder); - else - return createIndex(theRow, theColumn, (qint32) HistoryObject); - } - default: - return createIndex(theRow, theColumn, (qint32) HistoryObject); - } - case ParamsFolder: - return createIndex(theRow, 0, (qint32) ParamObject); - case ConstructFolder: - return createIndex(theRow, 0, (qint32) ConstructObject); - case BodiesFolder: - return createIndex(theRow, 0, (qint32) BodiesObject); - case GroupsFolder: - return createIndex(theRow, 0, (qint32) GroupObject); - } - return QModelIndex(); -} - -QModelIndex XGUI_PartDataModel::parent(const QModelIndex& theIndex) const -{ - switch (theIndex.internalId()) { - case MyRoot: - return QModelIndex(); - case ParamsFolder: - case ConstructFolder: - case BodiesFolder: - case GroupsFolder: - case HistoryObject: - return createIndex(0, 0, (qint32) MyRoot); - - case ParamObject: - return createIndex(0, 0, (qint32) ParamsFolder); - case ConstructObject: - return createIndex(1, 0, (qint32) ConstructFolder); - case BodiesObject: - return createIndex(2, 0, (qint32) BodiesFolder); - case GroupObject: - return createIndex(3, 0, (qint32) GroupsFolder); - } - return QModelIndex(); -} - -bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const -{ - return rowCount(theParent) > 0; -} - -DocumentPtr XGUI_PartDataModel::partDocument() const -{ - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId); - ResultPartPtr aPart = std::dynamic_pointer_cast(aObject); - if (aPart) - return aPart->partDoc(); - return DocumentPtr(); // null if not found -} - -ObjectPtr XGUI_PartDataModel::object(const QModelIndex& theIndex) const -{ - switch (theIndex.internalId()) { - case MyRoot: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - return aRootDoc->object(ModelAPI_ResultPart::group(), myId); - } - case ParamsFolder: - case ConstructFolder: - case BodiesFolder: - case GroupsFolder: - return ObjectPtr(); - - case ParamObject: - return partDocument()->object(ModelAPI_ResultParameter::group(), theIndex.row()); - case ConstructObject: - return partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row()); - case BodiesObject: - return partDocument()->object(ModelAPI_ResultBody::group(), theIndex.row()); - case GroupObject: - return partDocument()->object(ModelAPI_ResultGroup::group(), theIndex.row()); - case HistoryObject: - return partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber()); - } - return ObjectPtr(); -} - -bool XGUI_PartDataModel::hasDocument(const DocumentPtr& theDoc) const -{ - return (partDocument() == theDoc); -} - -QModelIndex XGUI_PartDataModel::findParent(const ObjectPtr& theObject) const -{ - return findGroup(theObject->groupName().c_str()); -} - -QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const -{ - if (theGroup == ModelAPI_ResultParameter::group()) - return createIndex(0, 0, (qint32) ParamsFolder); - if (theGroup == ModelAPI_ResultConstruction::group()) - return createIndex(1, 0, (qint32) ConstructFolder); - if (theGroup == ModelAPI_ResultBody::group()) - return createIndex(2, 0, (qint32) BodiesFolder); - if (theGroup == ModelAPI_ResultGroup::group()) - return createIndex(3, 0, (qint32) GroupsFolder); - return QModelIndex(); -} - -ResultPartPtr XGUI_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 aIndex; - if (theObject) { - if (part() == theObject) - return aIndex; - - std::string aGroup = theObject->groupName(); - DocumentPtr aDoc = theObject->document(); - int aNb = aDoc->size(aGroup); - int aRow = -1; - for (int i = 0; i < aNb; i++) { - if (aDoc->object(aGroup, i) == theObject) { - aRow = i; - break; - } - } - if (aRow == -1) - return aIndex; - if (aGroup == ModelAPI_ResultParameter::group()) - return createIndex(aRow, 0, (qint32) ParamObject); - else if (aGroup == ModelAPI_ResultConstruction::group()) - return createIndex(aRow, 0, (qint32) ConstructObject); - else if (aGroup == ModelAPI_ResultBody::group()) - return createIndex(aRow, 0, (qint32) BodiesObject); - else if (aGroup == ModelAPI_ResultGroup::group()) - return createIndex(aRow, 0, (qint32) GroupObject); - else - return createIndex(aRow + getRowsNumber(), 0, (qint32) HistoryObject); - } - return aIndex; -} - - -int XGUI_PartDataModel::getRowsNumber() const -{ - int aSize = partDocument()->size(ModelAPI_ResultGroup::group()); - if (aSize == 0) // If there are no groups then do not show group folder - return 3; - return 4; -} \ No newline at end of file diff --git a/src/XGUI/XGUI_PartDataModel.h b/src/XGUI/XGUI_PartDataModel.h deleted file mode 100644 index 56f28ad5e..000000000 --- a/src/XGUI/XGUI_PartDataModel.h +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -#ifndef XGUI_PartDataModel_H -#define XGUI_PartDataModel_H - -#include "XGUI.h" -#include "XGUI_DataTreeModel.h" - -/**\class XGUI_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 -{ -Q_OBJECT - public: - /// Constructor - /// \param theParent a parent object - XGUI_TopDataModel(QObject* theParent); - virtual ~XGUI_TopDataModel(); - - // Reimpl from QAbstractItemModel - - /// Returns the data stored under the given role for the item referred to by the index. - /// \param theIndex a model index - /// \param theRole a data role (see Qt::ItemDataRole) - virtual QVariant data(const QModelIndex& theIndex, int theRole) const; - - /// Returns the data for the given role and section in the header with the specified orientation. - /// \param theSection a section - /// \param theOrient an orientation - /// \param theRole a data role (see Qt::ItemDataRole) - virtual QVariant headerData(int theSection, Qt::Orientation theOrient, - int theRole = Qt::DisplayRole) const; - - /// Returns the number of rows under the given parent. When the parent is valid it means that - /// rowCount is returning the number of children of parent. - /// \param theParent a parent model index - virtual int rowCount(const QModelIndex &theParent = QModelIndex()) const; - - /// Returns the number of columns for the children of the given parent. - /// It has a one column - /// \param theParent a parent model index - virtual int columnCount(const QModelIndex &theParent = QModelIndex()) const; - - - /// Returns the index of the item in the model specified by the given row, column and parent index. - /// \param theRow a row - /// \param theColumn a column - /// \param theParent a parent model index - virtual QModelIndex index(int theRow, int theColumn, const QModelIndex& theParent = - QModelIndex()) const; - - /// Returns the parent of the model item with the given index. - /// If the item has no parent, an invalid QModelIndex is returned. - /// \param theIndex a model index - virtual QModelIndex parent(const QModelIndex& theIndex) const; - - /// Returns true if parent has any children; otherwise returns false. - /// \param theParent a parent model index - virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const; - - //! Returns object by the given Model index. - //! Returns 0 if the given index is not index of a object - virtual ObjectPtr object(const QModelIndex& theIndex) const; - - //! Returns QModelIndex which corresponds to the given object - //! If the object is not found then index is not valid - virtual QModelIndex objectIndex(const ObjectPtr& theObject) const; - - //! Returns parent index of the given object - virtual QModelIndex findParent(const ObjectPtr& theObject) const; - - //! Returns index corresponded to the group - virtual QModelIndex findGroup(const std::string& theGroup) const; - - private: - //! Types of QModelIndexes - enum DataIds - { - ParamsFolder, - ParamObject, - ConstructFolder, - ConstructObject - //GroupsFolder, - //GroupObject - }; - -}; - -/**\class XGUI_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 -{ -Q_OBJECT - public: - /// Constructor - /// \param theParent a parent object - XGUI_PartDataModel(QObject* theParent); - virtual ~XGUI_PartDataModel(); - - // Reimpl from QAbstractItemModel - - /// Returns the data stored under the given role for the item referred to by the index. - /// \param theIndex a model index - /// \param theRole a data role (see Qt::ItemDataRole) - virtual QVariant data(const QModelIndex& theIndex, int theRole) const; - - /// Returns the data for the given role and section in the header with the specified orientation. - /// \param theSection a section - /// \param theOrient an orientation - /// \param theRole a data role (see Qt::ItemDataRole) - virtual QVariant headerData(int theSection, Qt::Orientation theOrient, - int theRole = Qt::DisplayRole) const; - - /// Returns the number of rows under the given parent. When the parent is valid it means that - /// rowCount is returning the number of children of parent. - /// \param theParent a parent model index - virtual int rowCount(const QModelIndex &theParent = QModelIndex()) const; - - /// Returns the number of columns for the children of the given parent. - /// It has a one column - /// \param theParent a parent model index - virtual int columnCount(const QModelIndex &theParent = QModelIndex()) const; - - /// Returns the index of the item in the model specified by the given row, column and parent index. - /// \param theRow a row - /// \param theColumn a column - /// \param theParent a parent model index - virtual QModelIndex index(int theRow, int theColumn, const QModelIndex& theParent = - QModelIndex()) const; - - /// Returns the parent of the model item with the given index. - /// If the item has no parent, an invalid QModelIndex is returned. - /// \param theIndex a model index - virtual QModelIndex parent(const QModelIndex& theIndex) const; - - /// Returns true if parent has any children; otherwise returns false. - /// \param theParent a parent model index - virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const; - - //! Returns object by the given Model index. - //! Returns 0 if the given index is not index of a object - virtual ObjectPtr object(const QModelIndex& theIndex) const; - - //! Returns QModelIndex which corresponds to the given object - //! If the object is not found then index is not valid - virtual QModelIndex objectIndex(const ObjectPtr& theObject) const; - - //! Returns true if the given document is a sub-document of this tree - virtual bool hasDocument(const DocumentPtr& theDoc) const; - - //! Returns parent index of the given object - virtual QModelIndex findParent(const ObjectPtr& theObject) const; - - //! Returns index corresponded to the group - virtual QModelIndex findGroup(const std::string& theGroup) const; - - //! Return a Part object - virtual ResultPartPtr part() const; - - private: - - //! Returns document of the current part - DocumentPtr partDocument() const; - - //! Returns defult number of rows - int getRowsNumber() const; - - //! Types of QModelIndexes - enum DataIds - { - MyRoot, - ParamsFolder, - ParamObject, - ConstructFolder, - ConstructObject, - BodiesFolder, - BodiesObject, - GroupsFolder, - GroupObject, - HistoryObject - }; - -}; - -#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 diff --git a/src/XGUI/pictures/activate.png b/src/XGUI/pictures/activate.png deleted file mode 100644 index f82917927..000000000 Binary files a/src/XGUI/pictures/activate.png and /dev/null differ diff --git a/src/XGUI/pictures/edit.png b/src/XGUI/pictures/edit.png deleted file mode 100644 index 43a317420..000000000 Binary files a/src/XGUI/pictures/edit.png and /dev/null differ diff --git a/src/XGUI/pictures/exec_state_failed.png b/src/XGUI/pictures/exec_state_failed.png deleted file mode 100644 index 738f30371..000000000 Binary files a/src/XGUI/pictures/exec_state_failed.png and /dev/null differ diff --git a/src/XGUI/pictures/exec_state_invalid_parameters.png b/src/XGUI/pictures/exec_state_invalid_parameters.png deleted file mode 100644 index 1346f9709..000000000 Binary files a/src/XGUI/pictures/exec_state_invalid_parameters.png and /dev/null differ