+
+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);
+}