From: vsv Date: Wed, 19 Aug 2015 15:13:14 +0000 (+0300) Subject: Processing of complex objects in data tree X-Git-Tag: V_1.4.0_beta4~332 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5937f485e3cfb6fb386ad78b9010784ee654a3c0;p=modules%2Fshaper.git Processing of complex objects in data tree --- diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index 31e2b031b..2f4fba720 100644 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -188,7 +188,7 @@ CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature) ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub) { ResultBodyPtr aBody = std::dynamic_pointer_cast(theSub); - if (theSub.get()) { + if (aBody.get()) { FeaturePtr aFeatureOwner = aBody->document()->feature(aBody); if (aFeatureOwner.get()) { std::list >::const_iterator aResIter = diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 97269a351..faf2891e3 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -216,18 +216,7 @@ ObjectPtr XGUI_DataModel::object(const QModelIndex& theIndex) const if (getSubDocument(aObj)) // the selected index is a folder of sub-document return ObjectPtr(); - // We can not create the ObjectPtr directly because the pointer will be deleted - // with deletion of the ObjectPtr because its counter become to 0. - DocumentPtr aDoc = aObj->document(); - std::string aType = aObj->groupName(); - - ObjectPtr aObjPtr; - for (int i = 0; i < aDoc->size(aType); i++) { - aObjPtr = aDoc->object(aType, i); - if (aObjPtr.get() == aObj) - return aObjPtr; - } - return ObjectPtr(); + return aObj->data()->owner(); } //****************************************************** @@ -242,7 +231,7 @@ QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject) const if (aFeature.get()) { CompositeFeaturePtr aCompFea = ModelAPI_Tools::compositeOwner(aFeature); if (aCompFea.get()) { - for (int i = 0; i < aCompFea->numberOfSubs(); i++) { + for (int i = 0; i < aCompFea->numberOfSubs(true); i++) { if (aCompFea->subFeature(i, true) == theObject) { aRow = i; break; @@ -251,17 +240,17 @@ QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject) const } } else { ResultPtr aResult = std::dynamic_pointer_cast(theObject); - //if (aResult.get()) { - // ResultCompSolidPtr aCompRes = ModelAPI_Tools::compositeOwner(aResult); - // if (aCompRes.get()) { - // for (int i = 0; i < aCompRes->numberOfSubs(); i++) { - // if (aCompRes->subResult(i, true) == theObject) { - // aRow = i; - // break; - // } - // } - // } - //} + if (aResult.get()) { + ResultCompSolidPtr aCompRes = ModelAPI_Tools::compSolidOwner(aResult); + if (aCompRes.get()) { + for (int i = 0; i < aCompRes->numberOfSubs(true); i++) { + if (aCompRes->subResult(i, true) == theObject) { + aRow = i; + break; + } + } + } + } } if (aRow == -1) return QModelIndex(); @@ -509,7 +498,23 @@ QModelIndex XGUI_DataModel::parent(const QModelIndex& theIndex) const // It is a folder of sub-document return findDocumentRootIndex(aDoc); } - ModelAPI_Object* aObj = (ModelAPI_Object*) theIndex.internalPointer(); + ObjectPtr aObj = object(theIndex); + // Check is it object a sub-object of a complex object + FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); + if (aFeature.get()) { + CompositeFeaturePtr aCompFea = ModelAPI_Tools::compositeOwner(aFeature); + if (aCompFea.get()) { + return objectIndex(aCompFea); + } + } + ResultPtr aResult = std::dynamic_pointer_cast(aObj); + if (aResult.get()) { + ResultCompSolidPtr aCompRes = ModelAPI_Tools::compSolidOwner(aResult); + if (aCompRes.get()) { + return objectIndex(aCompRes); + } + } + // Use as ordinary object std::string aType = aObj->groupName(); SessionPtr aSession = ModelAPI_Session::get(); DocumentPtr aRootDoc = aSession->moduleDocument();