+}
+
+QModelIndex XGUI_DocumentDataModel::partIndex(const FeaturePtr& theFeature) const
+{
+ FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature);
+
+ int aRow = -1;
+ XGUI_PartModel* aModel = 0;
+ foreach (XGUI_PartModel* aPartModel, myPartModels) {
+ aRow++;
+ if (aPartModel->part() == aFeature) {
+ aModel = aPartModel;
+ break;
+ }
+ }
+ if (aModel) {
+ return createIndex(aRow, 0, (void*)getModelIndex(aModel->index(0, 0, QModelIndex())));
+ }
+ return QModelIndex();
+}
+
+QModelIndex XGUI_DocumentDataModel::featureIndex(const FeaturePtr theFeature) const
+{
+ // Check that this feature belongs to root document
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ DocumentPtr aDoc = theFeature->document();
+ if (aDoc == aRootDoc) {
+ // This feature belongs to histrory or top model
+ if (theFeature->isInHistory()) {
+ int aId;
+ for (aId = 0; aId < aRootDoc->size(FEATURES_GROUP); aId++) {
+ if (theFeature == aRootDoc->feature(FEATURES_GROUP, aId))
+ break;
+ }
+ return index(aId + historyOffset(), 0, QModelIndex());
+ } else {
+ QModelIndex aIndex = myModel->featureIndex(theFeature);
+ 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->featureIndex(theFeature);
+ return aIndex.isValid()?
+ createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)) :
+ QModelIndex();
+ }
+ }
+ return QModelIndex();