ModuleBase_WidgetExprEditor.h
ModuleBase_ParamSpinBox.h
ModuleBase_WidgetIntValue.h
+ ModuleBase_IDocumentDataModel.h
)
SET(PROJECT_SOURCES
--- /dev/null
+// 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 <QAbstractItemModel>
+#include <ModelAPI_Object.h>
+
+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
class ModuleBase_ModelWidget;\r
class ModuleBase_Operation;\r
class ModuleBase_IWorkshop;\r
+class ModuleBase_IDocumentDataModel;\r
\r
/**\r
* \ingroup GUI\r
/// \param theMenu a popup menu to be shown in the viewer\r
/// \param theStdActions a map of standard actions\r
/// \return true if items are added and there is no necessity to provide standard menu\r
- virtual bool addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const { return false; }\r
+ virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const { return false; }\r
\r
/// Add menu atems for object browser into the given menu\r
/// \param theMenu a popup menu to be shown in the object browser\r
- virtual void addObjectBrowserItems(QMenu* theMenu) const {};\r
+ virtual void addObjectBrowserMenu(QMenu* theMenu) const {};\r
\r
/// Called when it is necessary to update a command state (enable or disable it)\r
//virtual bool isFeatureEnabled(const QString& theCmdId) const = 0;\r
/// \returns true if the action is processed\r
virtual bool deleteObjects() { return false; };\r
\r
+ /// Returns data model object for representation of data tree in Object browser\r
+ virtual ModuleBase_IDocumentDataModel* dataModel() const = 0;\r
+\r
public slots:\r
/// Called on call of command corresponded to a feature\r
void onFeatureTriggered();\r
#include <ModelAPI_Data.h>
#include <ModelAPI_Attribute.h>
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_ResultParameter.h>
#include <GeomDataAPI_Point2D.h>
#include <Events_Error.h>
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<ModelAPI_Feature>(aObj);
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+ ResultParameterPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aResult);
+
+ hasResult = (aResult.get() != NULL);
+ hasFeature = (aFeature.get() != NULL);
+ hasParameter = (aConstruction.get() != NULL);
+ if (hasFeature && hasResult && hasParameter)
+ break;
+ }
+}
+
}
#define ModuleBase_Tools_H
#include "ModuleBase.h"
+#include "ModuleBase_Definitions.h"
#include <ModelAPI_Feature.h>
#include <TopAbs_ShapeEnum.hxx>
/// \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
//******************************************************
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);
}
PartSet_Filters.h
PartSet_SketcherMgr.h
PartSet_MenuMgr.h
+ PartSet_DocumentDataModel.h
+ PartSet_PartDataModel.h
+ PartSet_DataTreeModel.h
)
SET(PROJECT_SOURCES
PartSet_Filters.cpp
PartSet_SketcherMgr.cpp
PartSet_MenuMgr.cpp
+ PartSet_DocumentDataModel.cpp
+ PartSet_PartDataModel.cpp
)
SET(PROJECT_RESOURCES
${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
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+#ifndef PartSet_DataTreeModel_H
+#define PartSet_DataTreeModel_H
+
+#include "PartSet.h"
+
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_ResultPart.h>
+
+#include <QAbstractItemModel>
+#include <QColor>
+
+/**\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
--- /dev/null
+// 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 <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Events.h>
+#include <ModelAPI_Object.h>
+
+#include <Events_Loop.h>
+
+#include <Config_FeatureMessage.h>
+#include <ModuleBase_Tools.h>
+#include <ModuleBase_ActionInfo.h>
+
+#include <QIcon>
+#include <QString>
+#include <QBrush>
+
+#include <set>
+
+#define ACTIVE_COLOR QColor(0,72,140)
+#define PASSIVE_COLOR Qt::black
+
+QMap<QString, QString> 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<Events_Message>& theMessage)
+{
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+
+ // Created object event *******************
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
+ std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
+ std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+ std::set<ObjectPtr> aObjects = aUpdMsg->objects();
+
+ std::set<ObjectPtr>::const_iterator aIt;
+ for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
+ ObjectPtr aObject = (*aIt);
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(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<ModelAPI_ObjectDeletedMessage> aUpdMsg =
+ std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
+ DocumentPtr aDoc = aUpdMsg->document();
+ std::set<std::string> aGroups = aUpdMsg->groups();
+
+ std::set<std::string>::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<ModelAPI_ObjectUpdatedMessage> aUpdMsg = std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(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<Config_FeatureMessage> aFeatureMsg =
+ std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
+ if (!aFeatureMsg->isInternal()) {
+ ActionInfo aFeatureInfo;
+ aFeatureInfo.initFrom(aFeatureMsg);
+ // Remember features icons
+ myIcons[QString::fromStdString(aFeatureMsg->id())] = aFeatureInfo.iconFile;
+ }
+ } 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<ModelAPI_Feature>(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<QModelIndex*>(theProxy.internalPointer());
+ return aIndexPtr;
+}
+
+QModelIndex* PartSet_DocumentDataModel::findModelIndex(const QModelIndex& theIndex) const
+{
+ QList<QModelIndex*>::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<const PartSet_FeaturesModel*>(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<ModelAPI_Feature>(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;
+}
+
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+#ifndef PartSet_DocumentDataModel_H
+#define PartSet_DocumentDataModel_H
+
+#include "PartSet.h"
+#include <ModuleBase_Definitions.h>
+#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Feature.h>
+#include <ModuleBase_IDocumentDataModel.h>
+
+#include <Events_Listener.h>
+#include <QList>
+
+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<Events_Message>& 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<PartSet_PartModel*> myPartModels;
+
+ //! Active part in part editing mode
+ PartSet_PartModel* myActivePart;
+
+ QModelIndex myActivePartIndex;
+
+ //! List of saved QModelIndexes created by sub-models
+ QList<QModelIndex*> myIndexes;
+
+ int myHistoryBackOffset;
+
+ static QMap<QString, QString> myIcons;
+};
+
+#endif
#include <Events_Loop.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_ResultParameter.h>
#include <QAction>
#include <QMenu>
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;
}
}
-bool PartSet_MenuMgr::addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
+bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
{
ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation();
if (!PartSet_SketcherMgr::isSketchOperation(anOperation) &&
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<ModelAPI_ResultPart>(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<ModelAPI_Feature>(aObjects.first());
+ if (aFeature == NULL) {
+ ResultParameterPtr aParam =
+ std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aObjects.first());
+ if (aParam.get() != NULL) {
+ aFeature = ModelAPI_Feature::feature(aParam);
+ }
+ }
+ if (aFeature.get() != NULL)
+ myModule->editFeature(aFeature);
+}
/// \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<QString, QAction*>& theStdActions) const;
+ bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
public slots:
/// Processes the context menu action click
/// \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
// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
#include "PartSet_Module.h"
-#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_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 <PartSetPlugin_Remove.h>
+#include <PartSetPlugin_Part.h>
#include <ModuleBase_Operation.h>
#include <ModuleBase_IViewer.h>
#include <ModuleBase_IPropertyPanel.h>
#include <ModuleBase_WidgetEditor.h>
#include <ModuleBase_FilterFactory.h>
+#include <ModuleBase_Tools.h>
+
#include <GeomValidators_Edge.h>
#include <GeomValidators_EdgeOrVertex.h>
#include <GeomValidators_Face.h>
#include <XGUI_ModuleConnector.h>
#include <XGUI_ContextMenuMgr.h>
#include <XGUI_Tools.h>
+#include <XGUI_ObjectsBrowser.h>
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
#include <QApplication>
#include <QMessageBox>
#include <QMainWindow>
+#include <QLineEdit>
#include <GeomAlgoAPI_FaceBuilder.h>
#include <GeomDataAPI_Dir.h>
#include <QDebug>
#endif
+
+
/*!Create and return new instance of XGUI_Module*/
extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
{
}
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<XGUI_ModuleConnector*>(theWshop);
XGUI_Workshop* aWorkshop = aConnector->workshop();
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()
}
-bool PartSet_Module::addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
+bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
{
- return myMenuMgr->addViewerItems(theMenu, theStdActions);
+ return myMenuMgr->addViewerMenu(theMenu, theStdActions);
}
bool PartSet_Module::isMouseOverWindow()
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<XGUI_ModuleConnector*>(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<FeaturePtr> 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<XGUI_ModuleConnector*>(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<FeaturePtr> 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<ModelAPI_Feature>(aObj);
+ if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
+ std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
+ aMgr->startOperation(PartSetPlugin_Remove::ID());
+ FeaturePtr aFeature = aDoc->addFeature(PartSetPlugin_Remove::ID());
+ aFeature->execute();
+ aMgr->finishOperation();
+ }
+ }
+ }
return true;
}
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<ModelAPI_ResultPart>(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<Events_Message>& theMessage)
+{
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(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<ModelAPI_ResultPart>(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
#include <ModelAPI_Attribute.h>
#include <ModelAPI_CompositeFeature.h>
+#include <Events_Listener.h>
+
//#include <StdSelect_FaceFilter.hxx>
#include <TopoDS_Shape.hxx>
class ModuleBase_IViewWindow;
class PartSet_MenuMgr;
class PartSet_SketcherMgr;
+class PartSet_DocumentDataModel;
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
};
public:
+
/// Constructor
/// \param theWshop a pointer to a workshop
PartSet_Module(ModuleBase_IWorkshop* theWshop);
/// \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<QString, QAction*>& theStdActions) const;
+ virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& 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
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<Events_Message>& 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
/// \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<ModelAPI_ResultPart> theFeature);
+
private slots:
/// Processing of vertex selected
void onVertexSelected();
PartSet_MenuMgr* myMenuMgr;
int myVisualLayerId;
+
+ PartSet_DocumentDataModel* myDataModel;
};
#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+#include "PartSet_PartDataModel.h"
+#include "PartSet_Module.h"
+#include "PartSet_DocumentDataModel.h"
+
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeDocRef.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultParameter.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultGroup.h>
+#include <ModelAPI_AttributeDouble.h>
+
+#include <QIcon>
+#include <QBrush>
+
+
+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<ModelAPI_ResultParameter>(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<ModelAPI_Object>(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<ModelAPI_ResultParameter>(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<ModelAPI_Object>(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<ModelAPI_Feature>(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<ModelAPI_ResultPart>(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<ModelAPI_ResultPart>(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
--- /dev/null
+// 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
<file>icons/mirror.png</file>
<file>icons/translate.png</file>
<file>icons/rotate.png</file>
+ <file>icons/exec_state_failed.png</file>
+ <file>icons/exec_state_invalid_parameters.png</file>
+ <file>icons/activate.png</file>
+ <file>icons/deactivate.png</file>
+ <file>icons/edit.png</file>
</qresource>
</RCC>
/// 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();
};
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
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
#include "XGUI_ViewerProxy.h"
#include "XGUI_Selection.h"
#include "XGUI_SalomeConnector.h"
-#include "XGUI_Tools.h"
#include <AppElements_MainWindow.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Object.h>
-#include <ModelAPI_ResultPart.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_ResultGroup.h>
#include <ModelAPI_ResultParameter.h>
#include <ModuleBase_IModule.h>
+#include <ModuleBase_Tools.h>
#include <QAction>
#include <QContextMenuEvent>
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();
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<ModelAPI_ResultPart>(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)
}
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"));
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;
QMenu* XGUI_ContextMenuMgr::viewerMenu() const
{
QMenu* aMenu = new QMenu();
- addViewerItems(aMenu);
+ addViewerMenu(aMenu);
if (aMenu->actions().size() > 0) {
return aMenu;
}
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;
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"));
/// 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
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-#ifndef XGUI_DataTreeModel_H
-#define XGUI_DataTreeModel_H
-
-#include "XGUI.h"
-
-#include <ModelAPI_Document.h>
-#include <ModelAPI_Feature.h>
-#include <ModelAPI_ResultPart.h>
-
-#include <QAbstractItemModel>
-#include <QColor>
-
-/**\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
+++ /dev/null
-// 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 <ModelAPI_Session.h>
-#include <ModelAPI_Document.h>
-#include <ModelAPI_Feature.h>
-#include <ModelAPI_Data.h>
-#include <ModelAPI_ResultPart.h>
-#include <ModelAPI_Events.h>
-#include <ModelAPI_Object.h>
-
-#include <Events_Loop.h>
-
-#include <Config_FeatureMessage.h>
-
-#include <QIcon>
-#include <QString>
-#include <QBrush>
-
-#include <set>
-
-#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<Events_Message>& theMessage)
-{
- DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
-
- // Created object event *******************
- if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
- std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
- std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
- std::set<ObjectPtr> aObjects = aUpdMsg->objects();
-
- std::set<ObjectPtr>::const_iterator aIt;
- for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
- ObjectPtr aObject = (*aIt);
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(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<ModelAPI_ObjectDeletedMessage> aUpdMsg =
- std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
- DocumentPtr aDoc = aUpdMsg->document();
- std::set<std::string> aGroups = aUpdMsg->groups();
-
- std::set<std::string>::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<ModelAPI_ObjectUpdatedMessage> aUpdMsg = std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(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<ModelAPI_Feature>(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<QModelIndex*>(theProxy.internalPointer());
- return aIndexPtr;
-}
-
-QModelIndex* XGUI_DocumentDataModel::findModelIndex(const QModelIndex& theIndex) const
-{
- QList<QModelIndex*>::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<const XGUI_FeaturesModel*>(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<ModelAPI_Feature>(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);
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-#ifndef XGUI_DocumentDataModel_H
-#define XGUI_DocumentDataModel_H
-
-#include "XGUI.h"
-#include <ModuleBase_Definitions.h>
-#include <ModelAPI_ResultPart.h>
-
-#include <Events_Listener.h>
-
-#include <QAbstractItemModel>
-#include <QList>
-
-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<Events_Message>& 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<XGUI_PartModel*> myPartModels;
-
- //! Active part in part editing mode
- XGUI_PartModel* myActivePart;
-
- QModelIndex myActivePartIndex;
-
- //! List of saved QModelIndexes created by sub-models
- QList<QModelIndex*> myIndexes;
-
-};
-
-#endif
// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
#include "XGUI_ObjectsBrowser.h"
-#include "XGUI_DocumentDataModel.h"
#include "XGUI_Tools.h"
#include <ModelAPI_Data.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Document.h>
-#include <ModelAPI_Object.h>
#include <ModuleBase_Tools.h>
+#include <ModuleBase_IDocumentDataModel.h>
#include <QLayout>
#include <QLabel>
#include <QAction>
#include <QStyledItemDelegate>
+
+/// 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
{
QLineEdit* aEditor = dynamic_cast<QLineEdit*>(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());
: 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<XGUI_DocumentDataModel*>(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<ModelAPI_ResultPart>(aObject);
- if (aPart) {
- aPart->activate();
- }
- } else
- QTreeView::mouseDoubleClickEvent(theEvent);
+ return static_cast<ModuleBase_IDocumentDataModel*>(model());
}
void XGUI_DataTree::contextMenuEvent(QContextMenuEvent* theEvent)
QLineEdit* aEditor = dynamic_cast<QLineEdit*>(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);
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");
{
}
-//***************************************************
-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;
}
}
-//***************************************************
-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);
//***************************************************
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())
{
//***************************************************
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;
}
}
-//***************************************************
-void XGUI_ObjectsBrowser::onSelectionChanged()
-{
- myObjectsList = myTreeView->selectedObjects();
- emit selectionChanged();
-}
-
//***************************************************
void XGUI_ObjectsBrowser::rebuildDataTree()
{
}
//***************************************************
-void XGUI_ObjectsBrowser::processEvent(const std::shared_ptr<Events_Message>& 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();
}
#include <QWidget>
#include <QTreeView>
-class XGUI_DocumentDataModel;
+class ModuleBase_IDocumentDataModel;
class QLineEdit;
/**
/// 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);
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
virtual ~XGUI_ObjectsBrowser();
//! Returns Model which provides access to data objects
- XGUI_DocumentDataModel* dataModel() const
+ ModuleBase_IDocumentDataModel* dataModel() const
{
return myDocModel;
}
//! Returns list of currently selected objects
QObjectPtrList selectedObjects() const
{
- return myObjectsList;
+ return mySelectedData;
}
/// Set selected list of objects
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<Events_Message>& 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);
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);
//! 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
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-#include "XGUI_PartDataModel.h"
-#include "XGUI_Workshop.h"
-
-#include <ModelAPI_Session.h>
-#include <ModelAPI_Document.h>
-#include <ModelAPI_Feature.h>
-#include <ModelAPI_Result.h>
-#include <ModelAPI_Data.h>
-#include <ModelAPI_AttributeDocRef.h>
-#include <ModelAPI_Object.h>
-#include <ModelAPI_ResultPart.h>
-#include <ModelAPI_ResultConstruction.h>
-#include <ModelAPI_ResultParameter.h>
-#include <ModelAPI_ResultBody.h>
-#include <ModelAPI_ResultGroup.h>
-#include <ModelAPI_AttributeDouble.h>
-
-#include <QIcon>
-#include <QBrush>
-
-//ObjectPtr featureObj(const ObjectPtr& theFeature)
-//{
-// ObjectPtr aObject = std::dynamic_pointer_cast<ModelAPI_Object>(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<ModelAPI_ResultParameter>(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<ModelAPI_Object>(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<ModelAPI_ResultParameter>(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<ModelAPI_Object>(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<ModelAPI_Feature>(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<ModelAPI_ResultPart>(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<ModelAPI_ResultPart>(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
+++ /dev/null
-// 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
}*/
-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<ModelAPI_Feature>(aObj);
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
- ResultParameterPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aResult);
-
- hasResult = (aResult.get() != NULL);
- hasFeature = (aFeature.get() != NULL);
- hasParameter = (aConstruction.get() != NULL);
- if (hasFeature && hasResult && hasParameter)
- break;
- }
-}
-
}
#include <QRect>
#include <ModelAPI_Feature.h>
-#include <ModuleBase_Definitions.h>
#include <memory>
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
//#define DEBUG_FEATURE_CREATED
//#define DEBUG_FEATURE_REDISPLAY
-QMap<QString, QString> 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(),
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));
std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
onFeatureUpdatedMsg(anUpdateMsg);
- } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
- std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
- std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
- onObjectDeletedMsg(aDelMsg);
} else if (theMessage->eventID() == Events_LongOp::eventID()) {
if (Events_LongOp::isPerformed()) {
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
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<ModelAPI_ResultPart>(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<Config_SelectionFilterMessage> aMsg =
std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
}
}
myOperationMgr->onValidateOperation();
- if (myObjectBrowser)
- myObjectBrowser->processEvent(theMsg);
+ //if (myObjectBrowser)
+ // myObjectBrowser->processEvent(theMsg);
}
//******************************************************
isDisplayed = displayObject(*aIt);
//}
}
- if (myObjectBrowser)
- myObjectBrowser->processEvent(theMsg);
+ //if (myObjectBrowser)
+ // myObjectBrowser->processEvent(theMsg);
if (isDisplayed)
myDisplayer->updateViewer();
//if (aHasPart) { // TODO: Avoid activate last part on loading of document
//}
}
-//******************************************************
-void XGUI_Workshop::onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg)
-{
- if (myObjectBrowser)
- myObjectBrowser->processEvent(theMsg);
- //std::set<ObjectPtr> aFeatures = theMsg->objects();
-}
-
//******************************************************
void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
{
}
ActionInfo aFeatureInfo;
aFeatureInfo.initFrom(theMessage);
- // Remember features icons
- myIcons[QString::fromStdString(theMessage->id())] = aFeatureInfo.iconFile;
QString aWchName = QString::fromStdString(theMessage->workbenchId());
QStringList aNestedFeatures =
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();
}
}
-//******************************************************
-void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
-{
- SessionPtr aMgr = ModelAPI_Session::get();
- if (theObj) {
- ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theObj);
- if (aPart) {
- DocumentPtr aPartDoc = aPart->partDoc();
- if (aPartDoc) {
- aMgr->setActiveDocument(aPartDoc);
- return;
- }
- }
- }
- aMgr->setActiveDocument(aMgr->moduleDocument());
-}
-
//******************************************************
void XGUI_Workshop::salomeViewerSelectionChanged()
{
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<ModelAPI_ResultPart>(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);
setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
else if (theId == "HIDEALL_CMD")
myDisplayer->eraseAll();
- else if (theId == "EDIT_CMD") {
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObjects.first());
- if (aFeature == NULL) {
- ResultParameterPtr aParam =
- std::dynamic_pointer_cast<ModelAPI_ResultParameter>(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<ModelAPI_ResultPart>(aLastPart);
-// if (aPart) {
-// activatePart(aPart);
-// }
-//}
-
//**************************************************************
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;
/// \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<ModelAPI_ResultPart> theFeature);
-
//! Delete features
void deleteObjects();
/// 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();
/// Process feature redisplay message
void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
- /// Process feature delete message
- void onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& );
-
/// Display all results
void displayAllResults();
XGUI_ModuleConnector* myModuleConnector;
QString myCurrentDir;
- static QMap<QString, QString> myIcons;
bool myUpdatePrefs;
<file>pictures/button_help.png</file>
<file>pictures/button_ok.png</file>
- <file>pictures/edit.png</file>
- <file>pictures/exec_state_failed.png</file>
- <file>pictures/exec_state_invalid_parameters.png</file>
<file>pictures/assembly.png</file>
- <file>pictures/activate.png</file>
<file>pictures/delete.png</file>
<file>pictures/rename_edit.png</file>
<file>pictures/eye_pencil.png</file>