1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 #include "PartSet_DocumentDataModel.h"
4 #include "PartSet_PartDataModel.h"
5 #include "PartSet_Module.h"
6 //#include "XGUI_Tools.h"
8 #include <ModelAPI_Session.h>
9 #include <ModelAPI_Document.h>
10 #include <ModelAPI_Feature.h>
11 #include <ModelAPI_Data.h>
12 #include <ModelAPI_ResultPart.h>
13 #include <ModelAPI_Events.h>
14 #include <ModelAPI_Object.h>
16 #include <Events_Loop.h>
18 #include <Config_FeatureMessage.h>
19 #include <ModuleBase_Tools.h>
20 #include <ModuleBase_ActionInfo.h>
22 #include <PartSetPlugin_Part.h>
31 #define ACTIVE_COLOR QColor(0,72,140)
32 #define PASSIVE_COLOR Qt::black
34 QMap<QString, QString> PartSet_DocumentDataModel::myIcons;
37 PartSet_DocumentDataModel::PartSet_DocumentDataModel(QObject* theParent)
38 : ModuleBase_IDocumentDataModel(theParent),
41 // Create a top part of data tree model
42 myModel = new PartSet_TopDataModel(this);
43 myModel->setItemsColor(ACTIVE_COLOR);
45 Events_Loop* aLoop = Events_Loop::loop();
46 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
47 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
48 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
49 aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
52 PartSet_DocumentDataModel::~PartSet_DocumentDataModel()
58 void PartSet_DocumentDataModel::processEvent(const std::shared_ptr<Events_Message>& theMessage)
60 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
63 // Created object event *******************
64 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
65 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
66 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
67 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
69 std::set<ObjectPtr>::const_iterator aIt;
70 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
71 ObjectPtr aObject = (*aIt);
72 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
73 if (aFeature && (!aFeature->isInHistory()))
76 DocumentPtr aDoc = aObject->document();
77 if (aDoc == aRootDoc) { // If root objects
78 if (aObject->groupName() == ModelAPI_ResultPart::group()) { // Update only Parts group
80 int aStart = aRootDoc->size(ModelAPI_ResultPart::group());
82 FeaturePtr aPartFeature = ModelAPI_Feature::feature(aObject);
83 PartSet_PartDataModel* aModel = new PartSet_PartDataModel(this);
84 int anId = aRootDoc->index(aPartFeature);
85 aModel->setPart(aPartFeature);
86 myPartModels.append(aModel);
87 insertRow(aStart, partFolderNode(0));
89 } else { // Update top groups (other except parts
90 QModelIndex aIndex = myModel->findParent(aObject);
91 int aStart = myModel->rowCount(aIndex) - 1;
94 aIndex = createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex));
95 insertRow(aStart, aIndex);
97 } else { // if sub-objects of first level nodes
98 PartSet_PartModel* aPartModel = 0;
99 foreach (PartSet_PartModel* aPart, myPartModels) {
100 if (aPart->hasDocument(aDoc)) {
106 QModelIndex aIndex = aPartModel->findParent(aObject);
107 int aStart = aPartModel->rowCount(aIndex); // check this index
108 aIndex = createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex));
109 insertRow(aStart, aIndex);
114 // Deleted object event ***********************
115 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
116 std::shared_ptr<ModelAPI_ObjectDeletedMessage> aUpdMsg =
117 std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
118 DocumentPtr aDoc = aUpdMsg->document();
119 std::set<std::string> aGroups = aUpdMsg->groups();
121 std::set<std::string>::const_iterator aIt;
122 for (aIt = aGroups.begin(); aIt != aGroups.end(); ++aIt) {
123 std::string aGroup = (*aIt);
124 if (aDoc == aRootDoc) { // If root objects
125 if (aGroup == ModelAPI_ResultPart::group()) { // Update only Parts group
126 PartSet_PartModel* aDelPartModel = 0;
127 foreach (PartSet_PartModel* aPartModel, myPartModels) {
128 if (aPartModel->position() == -1) {
129 aDelPartModel = aPartModel;
135 int aStart = myPartModels.size() - 1;
136 removeSubModel(aDelPartModel);
137 removeRow(aStart, partFolderNode(0));
139 } else { // Update top groups (other except parts
140 QModelIndex aIndex = myModel->findGroup(aGroup);
141 int aStart = myModel->rowCount(aIndex);
142 aIndex = createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex));
143 removeRow(aStart, aIndex);
146 PartSet_PartModel* aPartModel = 0;
147 foreach (PartSet_PartModel* aPart, myPartModels) {
148 if (aPart->hasDocument(aDoc)) {
154 QModelIndex aIndex = aPartModel->findGroup(aGroup);
155 int aStart = aPartModel->rowCount(aIndex);
156 aIndex = createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex));
157 removeRow(aStart, aIndex);
161 // Deleted object event ***********************
162 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
163 //std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg = std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
164 //ObjectPtr aFeature = aUpdMsg->feature();
165 //DocumentPtr aDoc = aFeature->document();
167 // TODO: Identify the necessary index by the modified feature
169 emit dataChanged(aIndex, aIndex);
171 // Reset whole tree **************************
172 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
173 std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
174 std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
175 if (!aFeatureMsg->isInternal()) {
176 ActionInfo aFeatureInfo;
177 aFeatureInfo.initFrom(aFeatureMsg);
178 // Remember features icons
179 myIcons[QString::fromStdString(aFeatureMsg->id())] = aFeatureInfo.iconFile;
186 void PartSet_DocumentDataModel::rebuildDataTree()
188 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
193 // Delete extra models
196 QList<PartSet_PartModel*> aDelList;
197 foreach (PartSet_PartModel* aPartModel, myPartModels) {
198 if (aPartModel->position() == -1)
199 aDelList.append(aPartModel);
201 foreach (PartSet_PartModel* aPartModel, aDelList) {
202 removeSubModel(aPartModel);
204 // Add non existing models
205 int aHistNb = aRootDoc->size(ModelAPI_Feature::group());
206 for (int i = 0; i < aHistNb; i++) {
207 aObj = aRootDoc->object(ModelAPI_Feature::group(), i);
208 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
209 if (aFeature->getKind() == PartSetPlugin_Part::ID()) {
210 if (!findPartModel(aFeature)) {
211 PartSet_PartDataModel* aModel = new PartSet_PartDataModel(this);
212 aModel->setPart(aFeature);
213 myPartModels.append(aModel);
220 QVariant PartSet_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) const
222 if (!theIndex.isValid())
225 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
226 QModelIndex aParent = theIndex.parent();
227 if ((theIndex.column() == 1) ) {
228 if ((theIndex.internalId() >= PartsFolder) && (theIndex.internalId() <= PartResult)) {
229 if (ModelAPI_Session::get()->activeDocument() == aRootDoc) {
230 if (!aParent.isValid()) {
232 case Qt::DecorationRole:
233 if (theIndex.row() == lastHistoryRow())
234 return QIcon(":pictures/arrow.png");
239 QModelIndex* aIndex = toSourceModelIndex(theIndex);
240 const QAbstractItemModel* aModel = aIndex->model();
241 if (isPartSubModel(aModel)) {
242 return aModel->data(*aIndex, theRole);
248 switch (theIndex.internalId()) {
251 case Qt::DisplayRole:
252 return tr("Parts") + QString(" (%1)").arg(rowCount(theIndex));
253 case Qt::DecorationRole:
254 return QIcon(":pictures/constr_folder.png");
255 case Qt::ToolTipRole:
256 return tr("Parts folder");
257 case Qt::ForegroundRole:
258 if (myActivePartIndex.isValid())
259 return QBrush(PASSIVE_COLOR);
261 return QBrush(ACTIVE_COLOR);
268 int aOffset = historyOffset();
269 ObjectPtr aObj = aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset);
270 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
274 case Qt::DisplayRole:
276 return aFeature->data()->name().c_str();
279 case Qt::DecorationRole:
280 return featureIcon(aFeature);
281 case Qt::ToolTipRole:
282 return tr("Feature object");
283 case Qt::ForegroundRole:
284 if (theIndex.row() > lastHistoryRow())
285 return QBrush(Qt::lightGray);
287 if (myActivePartIndex.isValid())
288 return QBrush(PASSIVE_COLOR);
290 return QBrush(ACTIVE_COLOR);
299 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), theIndex.row());
302 case Qt::DisplayRole:
303 return std::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
304 case Qt::DecorationRole:
305 return QIcon(":pictures/part_ico.png");
306 case Qt::ForegroundRole:
308 if (theIndex == myActivePartIndex)
309 return QBrush(ACTIVE_COLOR);
311 return QBrush(PASSIVE_COLOR);
320 if (aParent.internalId() == HistoryNode) {
321 int aId = aParent.row() - historyOffset();
322 QModelIndex* aIndex = toSourceModelIndex(theIndex);
323 return findPartModel(aId)->data(*aIndex, theRole);
325 return toSourceModelIndex(theIndex)->data(theRole);
328 QVariant PartSet_DocumentDataModel::headerData(int theSection, Qt::Orientation theOrient,
334 int PartSet_DocumentDataModel::rowCount(const QModelIndex& theParent) const
336 SessionPtr aSession = ModelAPI_Session::get();
337 if (!aSession->hasModuleDocument())
339 DocumentPtr aRootDoc = aSession->moduleDocument();
340 if (!theParent.isValid()) {
341 // Size of external models
342 int aVal = historyOffset();
344 aVal += aRootDoc->size(ModelAPI_Feature::group());
347 if (theParent.internalId() == PartsFolder) {
348 return aRootDoc->size(ModelAPI_ResultPart::group());
349 //int aSize = myPartModels.size();
350 //return myPartModels.size();
352 if (theParent.internalId() == HistoryNode) {
353 int aId = theParent.row() - historyOffset();
354 PartSet_PartModel* aModel = findPartModel(aId);
356 return aModel->rowCount(QModelIndex());
359 if (theParent.internalId() == PartResult)
362 QModelIndex* aParent = toSourceModelIndex(theParent);
363 const QAbstractItemModel* aModel = aParent->model();
364 if (!isSubModel(aModel))
367 /*if (isPartSubModel(aModel)) {
368 if (aModel != myActivePart)
371 return aModel->rowCount(*aParent);
374 int PartSet_DocumentDataModel::columnCount(const QModelIndex& theParent) const
379 QModelIndex PartSet_DocumentDataModel::index(int theRow, int theColumn,
380 const QModelIndex& theParent) const
383 if (!theParent.isValid()) {
384 int aOffs = myModel->rowCount();
385 if (theRow < aOffs) {
386 aIndex = myModel->index(theRow, theColumn, theParent);
387 aIndex = createIndex(theRow, theColumn, (void*) getModelIndex(aIndex));
389 if (theRow == aOffs) // Create Parts node
390 aIndex = partFolderNode(theColumn);
392 // create history node
393 aIndex = createIndex(theRow, theColumn, HistoryNode);
397 if (theParent.internalId() == PartsFolder) {
398 aIndex = createIndex(theRow, theColumn, PartResult);
400 if (theParent.internalId() == HistoryNode) {
401 int aId = theParent.row() - historyOffset();
402 aIndex = findPartModel(aId)->index(theRow, theColumn, QModelIndex());
404 QModelIndex* aParent = (QModelIndex*) theParent.internalPointer();
405 aIndex = aParent->model()->index(theRow, theColumn, (*aParent));
407 aIndex = createIndex(theRow, theColumn, (void*) getModelIndex(aIndex));
413 QModelIndex PartSet_DocumentDataModel::parent(const QModelIndex& theIndex) const
415 if ((theIndex.internalId() == PartsFolder) || (theIndex.internalId() == HistoryNode))
416 return QModelIndex();
418 if (theIndex.internalId() == PartResult)
419 return partFolderNode(0);
421 QModelIndex* aIndex = toSourceModelIndex(theIndex);
422 const QAbstractItemModel* aModel = aIndex->model();
423 if (!isSubModel(aModel))
424 return QModelIndex();
426 QModelIndex aIndex1 = aModel->parent(*aIndex);
427 const PartSet_PartModel* aPartModel = dynamic_cast<const PartSet_PartModel*>(aModel);
428 if (aPartModel && (!aIndex1.isValid())) {
429 int aId = aPartModel->position();
430 int aRow = aId + historyOffset();
431 return createIndex(aRow, 0, (qint32) HistoryNode);
434 if (aIndex1.isValid())
435 return createIndex(aIndex1.row(), 0, (void*) getModelIndex(aIndex1));
439 bool PartSet_DocumentDataModel::hasChildren(const QModelIndex& theParent) const
441 if (!theParent.isValid())
443 return rowCount(theParent) > 0;
446 QModelIndex* PartSet_DocumentDataModel::toSourceModelIndex(const QModelIndex& theProxy) const
448 QModelIndex* aIndexPtr = static_cast<QModelIndex*>(theProxy.internalPointer());
452 QModelIndex* PartSet_DocumentDataModel::findModelIndex(const QModelIndex& theIndex) const
454 QList<QModelIndex*>::const_iterator aIt;
455 for (aIt = myIndexes.constBegin(); aIt != myIndexes.constEnd(); ++aIt) {
456 QModelIndex* aIndex = (*aIt);
457 if ((*aIndex) == theIndex)
463 QModelIndex* PartSet_DocumentDataModel::getModelIndex(const QModelIndex& theIndex) const
465 QModelIndex* aIndexPtr = findModelIndex(theIndex);
467 aIndexPtr = new QModelIndex(theIndex);
468 PartSet_DocumentDataModel* that = (PartSet_DocumentDataModel*) this;
469 that->myIndexes.append(aIndexPtr);
474 void PartSet_DocumentDataModel::clearModelIndexes()
476 foreach (QModelIndex* aIndex, myIndexes)
481 void PartSet_DocumentDataModel::clearSubModels()
483 foreach (PartSet_PartModel* aPart, myPartModels)
485 myPartModels.clear();
486 myActivePartModel = 0;
489 ObjectPtr PartSet_DocumentDataModel::object(const QModelIndex& theIndex) const
491 if (theIndex.internalId() == PartsFolder)
493 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
494 if (theIndex.internalId() == HistoryNode) {
495 int aOffset = historyOffset();
496 return aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset);
498 if (theIndex.internalId() == PartResult) {
499 return aRootDoc->object(ModelAPI_ResultPart::group(), theIndex.row());
501 QModelIndex* aIndex = toSourceModelIndex(theIndex);
502 if (!isSubModel(aIndex->model()))
505 const PartSet_FeaturesModel* aModel = dynamic_cast<const PartSet_FeaturesModel*>(aIndex->model());
506 return aModel->object(*aIndex);
509 bool PartSet_DocumentDataModel::insertRows(int theRow, int theCount, const QModelIndex& theParent)
511 beginInsertRows(theParent, theRow, theRow + theCount - 1);
516 int aRow = rowCount(aRoot);
517 beginInsertRows(aRoot, aRow, aRow);
523 bool PartSet_DocumentDataModel::removeRows(int theRow, int theCount, const QModelIndex& theParent)
525 beginRemoveRows(theParent, theRow, theRow + theCount - 1);
530 void PartSet_DocumentDataModel::removeSubModel(int theModelId)
532 PartSet_PartModel* aModel = myPartModels.at(theModelId);
533 removeSubModel(aModel);
536 void PartSet_DocumentDataModel::removeSubModel(PartSet_PartModel* theModel)
539 for (int i = 0; i < myIndexes.size(); i++) {
540 if (myIndexes.at(i)->model() == theModel)
544 while (aToRemove.size() > 0) {
545 aId = aToRemove.last();
546 delete myIndexes.at(aId);
547 myIndexes.removeAt(aId);
548 aToRemove.removeLast();
550 if (theModel == myActivePartModel)
551 myActivePartModel = 0;
552 myPartModels.removeAll(theModel);
557 bool PartSet_DocumentDataModel::isSubModel(const QAbstractItemModel* theModel) const
559 if (theModel == myModel)
561 return isPartSubModel(theModel);
564 bool PartSet_DocumentDataModel::isPartSubModel(const QAbstractItemModel* theModel) const
566 return myPartModels.contains((PartSet_PartModel*) theModel);
569 QModelIndex PartSet_DocumentDataModel::partFolderNode(int theColumn) const
571 int aPos = myModel->rowCount(QModelIndex());
572 return createIndex(aPos, theColumn, PartsFolder);
575 int PartSet_DocumentDataModel::historyOffset() const
577 // Nb of rows of top model + Parts folder
578 return myModel->rowCount(QModelIndex()) + 1;
581 bool PartSet_DocumentDataModel::activatePart(const QModelIndex& theIndex)
583 if ((theIndex.internalId() == PartsFolder) || (theIndex.internalId() == HistoryNode))
586 if (theIndex.isValid() && (theIndex.internalId() == PartResult)) {
587 myActivePartIndex = theIndex;
588 myModel->setItemsColor(PASSIVE_COLOR);
589 if (myActivePartModel)
590 myActivePartModel->setItemsColor(PASSIVE_COLOR);
592 // Find activated part feature by its ID
593 ResultPartPtr aPartRes = activePart();
594 FeaturePtr aFeature = ModelAPI_Feature::feature(aPartRes);
595 if (aFeature.get()) {
596 myActivePartModel = findPartModel(aFeature);
597 myActivePartModel->setItemsColor(ACTIVE_COLOR);
603 ResultPartPtr PartSet_DocumentDataModel::activePart() const
605 if (myActivePartIndex.isValid()) {
606 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
607 ObjectPtr aObj = aRootDoc->object(ModelAPI_ResultPart::group(), myActivePartIndex.row());
608 return std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
610 return ResultPartPtr();
613 QModelIndex PartSet_DocumentDataModel::activePartTree() const
615 if (myActivePartModel) {
616 return createIndex(myActivePartModel->position() + historyOffset(), 0, HistoryNode);
618 return QModelIndex();
621 void PartSet_DocumentDataModel::deactivatePart()
623 if (myActivePartIndex.isValid()) {
624 if (myActivePartModel)
625 myActivePartModel->setItemsColor(PASSIVE_COLOR);
626 myActivePartModel = 0;
627 myActivePartIndex = QModelIndex();
628 myModel->setItemsColor(ACTIVE_COLOR);
632 Qt::ItemFlags PartSet_DocumentDataModel::flags(const QModelIndex& theIndex) const
634 if ((theIndex.internalId() >= PartsFolder) && (theIndex.internalId() <= PartResult)) {
635 Qt::ItemFlags aFlags = Qt::ItemIsSelectable;
636 if (object(theIndex)) {
637 aFlags |= Qt::ItemIsEditable;
639 // Disable items which are below of last history row
640 // Do not disable second column
641 if (theIndex.internalId() == HistoryNode) {
642 if (theIndex.row() <= lastHistoryRow() || (theIndex.column() == 1))
643 aFlags |= Qt::ItemIsEnabled;
645 aFlags |= Qt::ItemIsEnabled;
648 QModelIndex* aIndex = toSourceModelIndex(theIndex);
649 const QAbstractItemModel* aModel = aIndex->model();
650 Qt::ItemFlags aFlags = aModel->flags(*aIndex);
651 if (aModel == myModel) {
652 if (myModel->object(*aIndex))
653 aFlags |= Qt::ItemIsEditable;
659 QModelIndex PartSet_DocumentDataModel::partIndex(const ResultPartPtr& theObject) const
661 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
662 int aNb = aRootDoc->size(ModelAPI_ResultPart::group());
663 for (int aId = 0; aId < aNb; aId++) {
664 if (theObject == aRootDoc->object(ModelAPI_ResultPart::group(), aId))
665 return createIndex(aId, 0, PartResult);
667 return QModelIndex();
670 QModelIndex PartSet_DocumentDataModel::objectIndex(const ObjectPtr theObject) const
672 // Check that this feature belongs to root document
673 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
674 DocumentPtr aDoc = theObject->document();
675 if (aDoc == aRootDoc) {
676 // This feature belongs to histrory or top model
677 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
680 int aNb = aRootDoc->size(ModelAPI_Feature::group());
681 for (aId = 0; aId < aNb; aId++) {
682 if (theObject == aRootDoc->object(ModelAPI_Feature::group(), aId))
686 return index(aId + historyOffset(), 0, QModelIndex());
688 QModelIndex aIndex = myModel->objectIndex(theObject);
691 createIndex(aIndex.row(), 0, (void*) getModelIndex(aIndex)) :
695 PartSet_PartModel* aPartModel = 0;
696 foreach(PartSet_PartModel* aModel, myPartModels) {
697 if (aModel->hasDocument(aDoc)) {
703 QModelIndex aIndex = aPartModel->objectIndex(theObject);
704 return aIndex.isValid() ?
705 createIndex(aIndex.row(), 0, (void*) getModelIndex(aIndex)) :
709 return QModelIndex();
713 void PartSet_DocumentDataModel::clear()
718 myActivePartIndex = QModelIndex();
719 myModel->setItemsColor(ACTIVE_COLOR);
722 int PartSet_DocumentDataModel::lastHistoryRow() const
724 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
725 FeaturePtr aFeature = aRootDoc->currentFeature(true);
727 return historyOffset() + aRootDoc->index(aFeature);
729 return historyOffset() - 1;
732 void PartSet_DocumentDataModel::setLastHistoryItem(const QModelIndex& theIndex)
734 SessionPtr aMgr = ModelAPI_Session::get();
735 DocumentPtr aRootDoc = aMgr->moduleDocument();
736 std::string aOpName = tr("History change").toStdString();
737 if (theIndex.internalId() == HistoryNode) {
738 ObjectPtr aObject = object(theIndex);
739 aMgr->startOperation(aOpName);
740 aRootDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject), true);
741 aMgr->finishOperation();
743 aMgr->startOperation(aOpName);
744 aRootDoc->setCurrentFeature(FeaturePtr(), true);
745 aMgr->finishOperation();
749 QModelIndex PartSet_DocumentDataModel::lastHistoryItem() const
751 return index(lastHistoryRow(), 1);
755 QIcon PartSet_DocumentDataModel::featureIcon(const FeaturePtr& theFeature)
759 std::string aKind = theFeature->getKind();
760 QString aId(aKind.c_str());
761 if (!myIcons.contains(aId))
764 QString anIconString = myIcons[aId];
766 ModelAPI_ExecState aState = theFeature->data()->execState();
768 case ModelAPI_StateDone:
769 case ModelAPI_StateNothing: {
770 anIcon = QIcon(anIconString);
773 case ModelAPI_StateMustBeUpdated: {
774 anIcon = ModuleBase_Tools::lighter(anIconString);
777 case ModelAPI_StateExecFailed: {
778 anIcon = ModuleBase_Tools::composite(":icons/exec_state_failed.png", anIconString);
781 case ModelAPI_StateInvalidArgument: {
782 anIcon = ModuleBase_Tools::composite(":icons/exec_state_invalid_parameters.png",
791 void PartSet_DocumentDataModel::onMouseDoubleClick(const QModelIndex& theIndex)
793 if (theIndex.column() != 1)
795 QTreeView* aTreeView = dynamic_cast<QTreeView*>(sender());
796 if ((theIndex.internalId() >= PartsFolder) && (theIndex.internalId() <= PartResult)) {
797 if (myActivePartModel)
798 // It means that the root document is not active
800 QModelIndex aNewIndex;
801 if (theIndex.internalId() == HistoryNode)
802 aNewIndex = theIndex;
803 int aOldId = lastHistoryRow();
804 setLastHistoryItem(theIndex);
805 int aStartRow = std::min(aOldId, theIndex.row());
806 int aEndRow = std::max(aOldId, theIndex.row());
807 for (int i = aStartRow; i <= aEndRow; i++) {
808 aTreeView->update(createIndex(i, 0, HistoryNode));
809 aTreeView->update(createIndex(i, 1, HistoryNode));
813 QModelIndex* aIndex = toSourceModelIndex(theIndex);
814 const QAbstractItemModel* aModel = aIndex->model();
815 if (isPartSubModel(aModel)) {
816 PartSet_PartDataModel* aPartModel = (PartSet_PartDataModel*)aModel;
817 QModelIndex aOldItem = aPartModel->lastHistoryItem();
818 aPartModel->setLastHistoryItem(*aIndex);
819 QModelIndex aOldIndex = createIndex(aOldItem.row(), aOldItem.column(), (void*) getModelIndex(aOldItem));
820 int aStartRow = std::min(aOldItem.row(), aIndex->row());
821 int aEndRow = std::max(aOldItem.row(), aIndex->row());
822 for (int i = aStartRow; i <= aEndRow; i++) {
823 QModelIndex aInd1 = aPartModel->index(i, 0);
824 QModelIndex aInd2 = createIndex(i, 0, (void*) getModelIndex(aInd1));
825 aTreeView->update(aInd2);
826 aInd1 = aPartModel->index(i, 1);
827 aInd2 = createIndex(i, 1, (void*) getModelIndex(aInd1));
828 aTreeView->update(aInd2);
835 PartSet_PartModel* PartSet_DocumentDataModel::findPartModel(FeaturePtr thePart) const
837 foreach (PartSet_PartModel* aModel, myPartModels) {
838 if (aModel->part() == thePart)
844 PartSet_PartModel* PartSet_DocumentDataModel::findPartModel(int thePosition) const
846 foreach (PartSet_PartModel* aModel, myPartModels) {
847 if (aModel->position() == thePosition)