From: vsv Date: Mon, 14 Jul 2014 07:49:38 +0000 (+0400) Subject: Migration on new model architecture X-Git-Tag: V_0.4.4~196 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3fc71e869245e8033a774a759df0e8f214183720;p=modules%2Fshaper.git Migration on new model architecture --- diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index 1fd594525..59c0e4537 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -33,6 +33,9 @@ public: static std::string group() {static std::string MY_GROUP = "Features"; return MY_GROUP;} + /// Returns the group identifier of this result + virtual std::string groupName() { return group(); } + /// Request for initialization of data model of the feature: adding all attributes virtual void initAttributes() = 0; diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h index 04a281b8f..907988393 100644 --- a/src/ModelAPI/ModelAPI_Object.h +++ b/src/ModelAPI/ModelAPI_Object.h @@ -40,6 +40,9 @@ public: virtual boost::shared_ptr document() {return myDoc;} + /// Returns the group identifier of this object + virtual std::string groupName() = 0; + protected: /// Sets the data manager of an object (document does) virtual void setData(boost::shared_ptr theData) diff --git a/src/ModelAPI/ModelAPI_Result.h b/src/ModelAPI/ModelAPI_Result.h index 01fa9dde9..97077b11d 100644 --- a/src/ModelAPI/ModelAPI_Result.h +++ b/src/ModelAPI/ModelAPI_Result.h @@ -22,7 +22,7 @@ public: //virtual boost::shared_ptr owner() = 0; /// Returns the group identifier of this result - virtual std::string groupName() = 0; + //virtual std::string groupName() = 0; }; //! Pointer on feature object diff --git a/src/ModelAPI/ModelAPI_ResultPart.h b/src/ModelAPI/ModelAPI_ResultPart.h index c922b1ef4..4e3058b6b 100644 --- a/src/ModelAPI/ModelAPI_ResultPart.h +++ b/src/ModelAPI/ModelAPI_ResultPart.h @@ -30,6 +30,6 @@ public: }; //! Pointer on feature object -typedef boost::shared_ptr ResultPart; +typedef boost::shared_ptr ResultPartPtr; #endif diff --git a/src/PartSet/PartSet_Listener.cpp b/src/PartSet/PartSet_Listener.cpp index 1b357fadb..1b597c4dc 100644 --- a/src/PartSet/PartSet_Listener.cpp +++ b/src/PartSet/PartSet_Listener.cpp @@ -42,23 +42,26 @@ void PartSet_Listener::processEvent(const Events_Message* theMessage) { const ModelAPI_ObjectUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); - std::set aFeatures = aUpdMsg->features(); - std::set::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); + std::set aFeatures = aUpdMsg->features(); + std::set::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); for (; anIt != aLast; anIt++) { - FeaturePtr aFeature = *anIt; - if (myModule->workshop()->displayer()->isVisible(aFeature) || - aType == EVENT_OBJECT_CREATED) { - myModule->visualizePreview(aFeature, true, false); - //if (aType == EVENT_OBJECT_CREATED) - myModule->activateFeature(aFeature, true); + ObjectPtr aObject = *anIt; + ResultPtr aResult = boost::dynamic_pointer_cast(aObject); + if (aResult) { + if (myModule->workshop()->displayer()->isVisible(aResult) || + aType == EVENT_OBJECT_CREATED) { + myModule->visualizePreview(aResult, true, false); + //if (aType == EVENT_OBJECT_CREATED) + myModule->activateFeature(aResult, true); + } } } myModule->workshop()->displayer()->updateViewer(); } if (aType == EVENT_OBJECT_DELETED) { - const ModelAPI_FeatureDeletedMessage* aDelMsg = - dynamic_cast(theMessage); + const ModelAPI_ObjectDeletedMessage* aDelMsg = + dynamic_cast(theMessage); boost::shared_ptr aDoc = aDelMsg->document(); std::set aGroups = aDelMsg->groups(); diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index d1d5d409b..dc9e868f3 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -148,7 +148,7 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle FeaturePtr aFeature; if (!theSelected.empty()) { ModuleBase_ViewerPrs aPrs = theSelected.front(); - aFeature = aPrs.feature(); + aFeature = aPrs.result(); } else aFeature = feature(); // for the widget distance only @@ -192,7 +192,7 @@ void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* t if ((myPreSelection.size() > 0) && myActiveWidget) { const ModuleBase_ViewerPrs& aPrs = myPreSelection.front(); ModuleBase_WidgetValueFeature aValue; - aValue.setFeature(aPrs.feature()); + aValue.setFeature(aPrs.result()); if (myActiveWidget->setValue(&aValue)) { myPreSelection.remove(aPrs); emit activateNextWidget(myActiveWidget); diff --git a/src/PartSet/PartSet_OperationFeatureEdit.cpp b/src/PartSet/PartSet_OperationFeatureEdit.cpp index 468eb635c..6705c0e6c 100644 --- a/src/PartSet/PartSet_OperationFeatureEdit.cpp +++ b/src/PartSet/PartSet_OperationFeatureEdit.cpp @@ -73,11 +73,11 @@ void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3 const std::list& theSelected, const std::list& theHighlighted) { - FeaturePtr aFeature; + ResultPtr aFeature; if (!theHighlighted.empty()) - aFeature = theHighlighted.front().feature(); + aFeature = theHighlighted.front().result(); if (!aFeature && !theSelected.empty()) // changed for a constrain - aFeature = theSelected.front().feature(); + aFeature = theSelected.front().result(); if (!aFeature || aFeature != feature()) { @@ -88,7 +88,7 @@ void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3 if(aHasShift && !theHighlighted.empty()) { QFeatureList aSelected; aSelected.push_back(feature()); - aSelected.push_back(theHighlighted.front().feature()); + aSelected.push_back(theHighlighted.front().result()); emit setSelection(aSelected); } else if (aFeature) { diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index aa3ac235a..24a726a90 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -152,17 +152,17 @@ FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theVie ModuleBase_ViewerPrs aPrs; for (; anIt != aLast; anIt++) { aPrs = *anIt; - if (!aPrs.feature()) + if (!aPrs.result()) continue; boost::shared_ptr aSketchFeature = - boost::dynamic_pointer_cast(aPrs.feature()); + boost::dynamic_pointer_cast(aPrs.result()); if (!aSketchFeature) continue; double aDelta = aSketchFeature->distanceToPoint( boost::shared_ptr(new GeomAPI_Pnt2d(aX, anY))); if (aMinDelta < 0 || aMinDelta > aDelta) { aMinDelta = aDelta; - aDeltaFeature = aPrs.feature(); + aDeltaFeature = aPrs.result(); } } return aDeltaFeature; diff --git a/src/XGUI/XGUI_DataTreeModel.h b/src/XGUI/XGUI_DataTreeModel.h index 1e187ed71..ece7040f6 100644 --- a/src/XGUI/XGUI_DataTreeModel.h +++ b/src/XGUI/XGUI_DataTreeModel.h @@ -23,14 +23,14 @@ public: //! Returns Feature object by the given Model index. //! Returns 0 if the given index is not index of a feature - virtual ObjectPtr feature(const QModelIndex& theIndex) const = 0; + 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 featureIndex(const ObjectPtr& theFeature) const = 0; + virtual QModelIndex objectIndex(const ObjectPtr& theFeature) const = 0; //! Returns parent index of the given feature - virtual QModelIndex findParent(const ObjectPtr& theFeature) const = 0; + virtual QModelIndex findParent(const ObjectPtr& theObject) const = 0; //! Returns index corresponded to the group virtual QModelIndex findGroup(const std::string& theGroup) const = 0; @@ -60,7 +60,7 @@ public: virtual bool hasDocument(const DocumentPtr& theDoc) const = 0; //! Return a Part object - virtual ObjectPtr part() const = 0; + virtual ResultPartPtr part() const = 0; protected: //! Id of the current part object in the document diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index 7857bd7a4..429012470 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -48,15 +49,15 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) // Created object event ******************* if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) { - const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); - std::set aFeatures = aUpdMsg->features(); + const Model_ObjectUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); + std::set aFeatures = aUpdMsg->features(); - std::set::const_iterator aIt; + std::set::const_iterator aIt; for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) { - FeaturePtr aFeature = (*aIt); + ObjectPtr aFeature = (*aIt); DocumentPtr aDoc = aFeature->document(); if (aDoc == aRootDoc) { // If root objects - if (aFeature->getGroup().compare(PARTS_GROUP) == 0) { // Update only Parts group + if (aFeature->groupName().compare(ModelAPI_ResultPart::group()) == 0) { // Update only Parts group // Add a new part int aStart = myPartModels.size(); XGUI_PartDataModel* aModel = new XGUI_PartDataModel(this); @@ -88,7 +89,7 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) } // Deleted object event *********************** } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { - const Model_FeatureDeletedMessage* aUpdMsg = dynamic_cast(theMessage); + const Model_ObjectDeletedMessage* aUpdMsg = dynamic_cast(theMessage); DocumentPtr aDoc = aUpdMsg->document(); std::set aGroups = aUpdMsg->groups(); @@ -96,7 +97,7 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) for (aIt = aGroups.begin(); aIt != aGroups.end(); ++aIt) { std::string aGroup = (*aIt); if (aDoc == aRootDoc) { // If root objects - if (aGroup.compare(PARTS_GROUP) == 0) { // Updsate only Parts group + if (aGroup.compare(ModelAPI_ResultPart::group()) == 0) { // Updsate only Parts group int aStart = myPartModels.size() - 1; removeSubModel(aStart); removeRow(aStart, partFolderNode()); @@ -130,8 +131,8 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) } // Deleted object event *********************** } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) { - //const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); - //FeaturePtr aFeature = aUpdMsg->feature(); + //const Model_ObjectUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); + //ObjectPtr aFeature = aUpdMsg->feature(); //DocumentPtr aDoc = aFeature->document(); // TODO: Identify the necessary index by the modified feature @@ -151,7 +152,7 @@ void XGUI_DocumentDataModel::rebuildDataTree() beginResetModel(); clearModelIndexes(); - int aNbParts = aRootDoc->size(PARTS_GROUP); + int aNbParts = aRootDoc->size(ModelAPI_ResultPart::group()); if (myPartModels.size() != aNbParts) { // resize internal models while (myPartModels.size() > aNbParts) { delete myPartModels.last(); @@ -192,13 +193,13 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) { int aOffset = historyOffset(); DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - FeaturePtr aFeature = aRootDoc->feature(FEATURES_GROUP, theIndex.row() - aOffset); + ObjectPtr aFeature = aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset); if (!aFeature) return QVariant(); switch (theRole) { case Qt::DisplayRole: if (aFeature) - return aFeature->data()->getName().c_str(); + return aFeature->data()->name().c_str(); else return QVariant(); case Qt::DecorationRole: @@ -236,7 +237,7 @@ int XGUI_DocumentDataModel::rowCount(const QModelIndex& theParent) const // Size of external models int aVal = historyOffset(); // Plus history size - aVal += aRootDoc->size(FEATURES_GROUP); + aVal += aRootDoc->size(ModelAPI_Feature::group()); return aVal; } if (theParent.internalId() == PartsFolder) { @@ -357,18 +358,18 @@ void XGUI_DocumentDataModel::clearModelIndexes() myIndexes.clear(); } -FeaturePtr XGUI_DocumentDataModel::feature(const QModelIndex& theIndex) const +ObjectPtr XGUI_DocumentDataModel::object(const QModelIndex& theIndex) const { if (theIndex.internalId() == PartsFolder) - return FeaturePtr(); + return ObjectPtr(); if (theIndex.internalId() == HistoryNode) { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); int aOffset = historyOffset(); - return aRootDoc->feature(FEATURES_GROUP, theIndex.row() - aOffset); + return aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset); } QModelIndex* aIndex = toSourceModelIndex(theIndex); if (!isSubModel(aIndex->model())) - return FeaturePtr(); + return ObjectPtr(); const XGUI_FeaturesModel* aModel = dynamic_cast(aIndex->model()); return aModel->feature(*aIndex); @@ -474,11 +475,11 @@ bool XGUI_DocumentDataModel::activatedIndex(const QModelIndex& theIndex) return false; } -FeaturePtr XGUI_DocumentDataModel::activePart() const +ObjectPtr XGUI_DocumentDataModel::activePart() const { if (myActivePart) return myActivePart->part(); - return FeaturePtr(); + return ObjectPtr(); } void XGUI_DocumentDataModel::deactivatePart() @@ -493,21 +494,19 @@ void XGUI_DocumentDataModel::deactivatePart() Qt::ItemFlags XGUI_DocumentDataModel::flags(const QModelIndex& theIndex) const { Qt::ItemFlags aFlags = QAbstractItemModel::flags(theIndex); - if (feature(theIndex)) { + if (object(theIndex)) { aFlags |= Qt::ItemIsEditable; } return aFlags; } -QModelIndex XGUI_DocumentDataModel::partIndex(const FeaturePtr& theFeature) const +QModelIndex XGUI_DocumentDataModel::partIndex(const ObjectPtr& theObject) const { - FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature); - int aRow = -1; XGUI_PartModel* aModel = 0; foreach (XGUI_PartModel* aPartModel, myPartModels) { aRow++; - if (aPartModel->part() == aFeature) { + if (aPartModel->part() == theObject) { aModel = aPartModel; break; } @@ -518,22 +517,22 @@ QModelIndex XGUI_DocumentDataModel::partIndex(const FeaturePtr& theFeature) cons return QModelIndex(); } -QModelIndex XGUI_DocumentDataModel::featureIndex(const FeaturePtr theFeature) const +QModelIndex XGUI_DocumentDataModel::featureIndex(const ObjectPtr theObject) const { // Check that this feature belongs to root document DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - DocumentPtr aDoc = theFeature->document(); + DocumentPtr aDoc = theObject->document(); if (aDoc == aRootDoc) { // This feature belongs to histrory or top model - if (theFeature->isInHistory()) { + if (theObject->isInHistory()) { int aId; - for (aId = 0; aId < aRootDoc->size(FEATURES_GROUP); aId++) { - if (theFeature == aRootDoc->feature(FEATURES_GROUP, aId)) + for (aId = 0; aId < aRootDoc->size(ModelAPI_Feature::group()); aId++) { + if (theObject == aRootDoc->object(ModelAPI_Feature::group(), aId)) break; } return index(aId + historyOffset(), 0, QModelIndex()); } else { - QModelIndex aIndex = myModel->featureIndex(theFeature); + QModelIndex aIndex = myModel->featureIndex(theObject); return aIndex.isValid()? createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)) : QModelIndex(); @@ -547,7 +546,7 @@ QModelIndex XGUI_DocumentDataModel::featureIndex(const FeaturePtr theFeature) co } } if (aPartModel) { - QModelIndex aIndex = aPartModel->featureIndex(theFeature); + QModelIndex aIndex = aPartModel->featureIndex(theObject); return aIndex.isValid()? createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)) : QModelIndex(); diff --git a/src/XGUI/XGUI_DocumentDataModel.h b/src/XGUI/XGUI_DocumentDataModel.h index c6b924bb4..225a7108f 100644 --- a/src/XGUI/XGUI_DocumentDataModel.h +++ b/src/XGUI/XGUI_DocumentDataModel.h @@ -54,20 +54,20 @@ public: //! Returns Feature object by the given Model index. //! Returns 0 if the given index is not index of a feature - FeaturePtr feature(const QModelIndex& theIndex) const; + ObjectPtr object(const QModelIndex& theIndex) const; - QModelIndex featureIndex(const FeaturePtr theFeature) const; + QModelIndex featureIndex(const ObjectPtr theFeature) const; //! Returns QModelIndex which corresponds to the given feature if this is a part //! If the feature is not found then index is not valid - QModelIndex partIndex(const FeaturePtr& theFeature) const; + QModelIndex partIndex(const ObjectPtr& theFeature) const; //! Activates a part data model if the index is a Part node index. //! Returns true if active part changed. bool activatedIndex(const QModelIndex& theIndex); //! Retrurns Feature which corresponds to active part - FeaturePtr activePart() const; + ObjectPtr activePart() const; //! Retrurns QModelIndex of active part QModelIndex activePartIndex() const { return myActivePartIndex; } diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index 0bd28f9d7..c9e98b5d4 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -45,18 +46,18 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const case ParamObject: { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - ObjectPtr aFeature = aRootDoc->object(PARAMETERS_GROUP, theIndex.row()); - if (aFeature) - return boost::dynamic_pointer_cast(aFeature)->data()->name().c_str(); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row()); + if (aObject) + return boost::dynamic_pointer_cast(aObject)->data()->name().c_str(); } case ConstructFolder: return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex)); case ConstructObject: { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - ObjectPtr aFeature = aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); - if (aFeature) - return boost::dynamic_pointer_cast(aFeature)->data()->name().c_str(); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); + if (aObject) + return boost::dynamic_pointer_cast(aObject)->data()->name().c_str(); } } break; @@ -71,9 +72,9 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const case ConstructObject: { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - ObjectPtr aFeature = aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); - if (aFeature) - return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); + if (aObject) + return QIcon(XGUI_Workshop::featureIcon(aObject->getKind())); } } break; @@ -100,10 +101,10 @@ int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); if (theParent.internalId() == ParamsFolder) - return aRootDoc->size(PARAMETERS_GROUP); + return aRootDoc->size(ModelAPI_ResultParameters::group()); if (theParent.internalId() == ConstructFolder) - return aRootDoc->size(CONSTRUCTIONS_GROUP); + return aRootDoc->size(ModelAPI_ResultConstruction::group()); return 0; } @@ -152,7 +153,7 @@ bool XGUI_TopDataModel::hasChildren(const QModelIndex& theParent) const return rowCount(theParent) > 0; } -ObjectPtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const +ObjectPtr XGUI_TopDataModel::object(const QModelIndex& theIndex) const { switch (theIndex.internalId()) { case ParamsFolder: @@ -161,50 +162,50 @@ ObjectPtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const case ParamObject: { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - return aRootDoc->feature(PARAMETERS_GROUP, theIndex.row()); + return aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row()); } case ConstructObject: { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - return aRootDoc->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + return aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); } } return ObjectPtr(); } -QModelIndex XGUI_TopDataModel::findParent(const ObjectPtr& theFeature) const +QModelIndex XGUI_TopDataModel::findParent(const ObjectPtr& theObject) const { - return findGroup(theFeature->getGroup().c_str()); + return findGroup(theObject->groupName().c_str()); } QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const { - if (theGroup.compare(PARAMETERS_GROUP) == 0) + if (theGroup.compare(ModelAPI_ResultParameters::group()) == 0) return createIndex(0, 0, (qint32) ParamsFolder); - if (theGroup.compare(CONSTRUCTIONS_GROUP) == 0) + if (theGroup.compare(ModelAPI_ResultConstruction::group()) == 0) return createIndex(1, 0, (qint32) ConstructFolder); return QModelIndex(); } -QModelIndex XGUI_TopDataModel::featureIndex(const ObjectPtr& theFeature) const +QModelIndex XGUI_TopDataModel::objectIndex(const ObjectPtr& theObject) const { QModelIndex aIndex; - if (theFeature) { + if (theObject) { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - std::string aGroup = theFeature->getGroup(); + std::string aGroup = theObject->groupName(); int aNb = aRootDoc->size(aGroup); int aRow = -1; for (int i = 0; i < aNb; i++) { - if (aRootDoc->feature(aGroup, i) == theFeature) { + if (aRootDoc->object(aGroup, i) == theObject) { aRow = i; break; } } if (aRow != -1) { - if (aGroup.compare(PARAMETERS_GROUP) == 0) + if (aGroup.compare(ModelAPI_ResultParameters::group()) == 0) return createIndex(aRow, 0, (qint32) ParamObject); - if (aGroup.compare(CONSTRUCTIONS_GROUP) == 0) + if (aGroup.compare(ModelAPI_ResultConstruction::group()) == 0) return createIndex(aRow, 0, (qint32) ConstructObject); } } @@ -235,9 +236,9 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons case MyRoot: { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - ObjectPtr aFeature = aRootDoc->feature(PARTS_GROUP, myId); - if (aFeature) - return boost::dynamic_pointer_cast(aFeature)->getName().c_str(); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId); + if (aObject) + return boost::dynamic_pointer_cast(aObject)->getName().c_str(); } case ParamsFolder: return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex)); @@ -247,21 +248,21 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons return tr("Bodies") + QString(" (%1)").arg(rowCount(theIndex)); case ParamObject: { - ObjectPtr aFeature = featureDocument()->feature(PARAMETERS_GROUP, theIndex.row()); - if (aFeature) - return boost::dynamic_pointer_cast(aFeature)->getName().c_str(); + ObjectPtr aObject = partDocument()->object(ModelAPI_ResultParameters::group(), theIndex.row()); + if (aObject) + return boost::dynamic_pointer_cast(aObject)->data()->name().c_str(); } case ConstructObject: { - ObjectPtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); - if (aFeature) - return boost::dynamic_pointer_cast(aFeature)->getName().c_str(); + ObjectPtr aObject = partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row()); + if (aObject) + return boost::dynamic_pointer_cast(aObject)->data()->name().c_str(); } case HistoryObject: { - ObjectPtr aFeature = featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); - if (aFeature) - return aFeature->data()->getName().c_str(); + ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 3); + if (aObject) + return aObject->data()->name().c_str(); } } break; @@ -277,15 +278,15 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons return QIcon(":pictures/constr_folder.png"); case ConstructObject: { - ObjectPtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); - if (aFeature) - return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); + ObjectPtr aObject = partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row()); + if (aObject) + return QIcon(XGUI_Workshop::featureIcon(aObject->getKind())); } case HistoryObject: { - ObjectPtr aFeature = featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); - if (aFeature) - return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); + ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 3); + if (aObject) + return QIcon(XGUI_Workshop::featureIcon(aObject->getKind())); } } break; @@ -308,18 +309,18 @@ int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const { if (!parent.isValid()) { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - if (aRootDoc->feature(PARTS_GROUP, myId)) + if (aRootDoc->object(ModelAPI_ResultPart::group(), myId)) return 1; else return 0; } switch (parent.internalId()) { case MyRoot: - return 3 + featureDocument()->size(FEATURES_GROUP); + return 3 + partDocument()->size(ModelAPI_Feature::group()); case ParamsFolder: - return featureDocument()->size(PARAMETERS_GROUP); + return partDocument()->size(ModelAPI_ResultParameters::group()); case ConstructFolder: - return featureDocument()->size(CONSTRUCTIONS_GROUP); + return partDocument()->size(ModelAPI_ResultConstruction::group()); case BodiesFolder: return 0; } @@ -383,53 +384,53 @@ bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const } -DocumentPtr XGUI_PartDataModel::featureDocument() const +DocumentPtr XGUI_PartDataModel::partDocument() const { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - ObjectPtr aFeature = aRootDoc->feature(PARTS_GROUP, myId, true); - return aFeature->data()->docRef("PartDocument")->value(); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId); + return aObject->data()->docRef("PartDocument")->value(); } -ObjectPtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const +ObjectPtr XGUI_PartDataModel::object(const QModelIndex& theIndex) const { switch (theIndex.internalId()) { case MyRoot: { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - return aRootDoc->feature(PARTS_GROUP, myId); + return aRootDoc->object(ModelAPI_ResultPart::group(), myId); } case ParamsFolder: case ConstructFolder: case BodiesFolder: return ObjectPtr(); case ParamObject: - return featureDocument()->feature(PARAMETERS_GROUP, theIndex.row()); + return partDocument()->object(ModelAPI_ResultParameters::group(), theIndex.row()); case ConstructObject: - return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + return partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row()); //case BodiesObject: - // return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + // return partDocument()->feature(ModelAPI_ResultConstruction::group(), theIndex.row()); case HistoryObject: - return featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); + return partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 3); } return ObjectPtr(); } bool XGUI_PartDataModel::hasDocument(const DocumentPtr& theDoc) const { - return (featureDocument() == theDoc); + return (partDocument() == theDoc); } -QModelIndex XGUI_PartDataModel::findParent(const ObjectPtr& theFeature) const +QModelIndex XGUI_PartDataModel::findParent(const ObjectPtr& theObject) const { - return findGroup(theFeature->getGroup().c_str()); + return findGroup(theObject->groupName().c_str()); } QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const { - if (theGroup.compare(PARAMETERS_GROUP) == 0) + if (theGroup.compare(ModelAPI_ResultParameters::group()) == 0) return createIndex(0, 0, (qint32) ParamsFolder); - if (theGroup.compare(CONSTRUCTIONS_GROUP) == 0) + if (theGroup.compare(ModelAPI_ResultConstruction::group()) == 0) return createIndex(1, 0, (qint32) ConstructFolder); return QModelIndex(); } @@ -440,7 +441,7 @@ ObjectPtr XGUI_PartDataModel::part() const return aRootDoc->object(ModelAPI_ResultPart::group(), myId); } -QModelIndex XGUI_PartDataModel::featureIndex(const ObjectPtr& theObject) const +QModelIndex XGUI_PartDataModel::objectIndex(const ObjectPtr& theObject) const { QModelIndex aIndex; if (theObject) { @@ -459,9 +460,9 @@ QModelIndex XGUI_PartDataModel::featureIndex(const ObjectPtr& theObject) const } if (aRow != -1) { return createIndex(aRow + 3, 0, (qint32) HistoryObject); -/* if (aGroup.compare(PARAMETERS_GROUP) == 0) +/* if (aGroup.compare(ModelAPI_ResultParameters::group()) == 0) return createIndex(aRow, 0, (qint32) ParamObject); - if (aGroup.compare(CONSTRUCTIONS_GROUP) == 0) + if (aGroup.compare(ModelAPI_ResultConstruction::group()) == 0) return createIndex(aRow, 0, (qint32) ConstructObject);*/ } } diff --git a/src/XGUI/XGUI_PartDataModel.h b/src/XGUI/XGUI_PartDataModel.h index 9ebf7669f..b1f808995 100644 --- a/src/XGUI/XGUI_PartDataModel.h +++ b/src/XGUI/XGUI_PartDataModel.h @@ -32,16 +32,16 @@ public: virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const; - //! Returns Feature object by the given Model index. - //! Returns 0 if the given index is not index of a feature - virtual ObjectPtr feature(const QModelIndex& theIndex) 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 feature - //! If the feature is not found then index is not valid - virtual QModelIndex featureIndex(const ObjectPtr& theFeature) 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 feature - virtual QModelIndex findParent(const ObjectPtr& theFeature) 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; @@ -85,19 +85,19 @@ public: virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const; - //! Returns Feature object by the given Model index. - //! Returns 0 if the given index is not index of a feature - virtual ObjectPtr feature(const QModelIndex& theIndex) 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 feature - //! If the feature is not found then index is not valid - virtual QModelIndex featureIndex(const ObjectPtr& theFeature) 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 feature - virtual QModelIndex findParent(const ObjectPtr& theFeature) 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; @@ -108,7 +108,7 @@ public: private: //! Returns document of the current part - DocumentPtr featureDocument() const; + DocumentPtr partDocument() const; //! Types of QModelIndexes enum DataIds {