+DocumentPtr XGUI_PartDataModel::partDocument() const
+{
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
+ if (aPart)
+ return aPart->partDoc();
+ return DocumentPtr(); // null if not found
+}
+
+ObjectPtr XGUI_PartDataModel::object(const QModelIndex& theIndex) const
+{
+ switch (theIndex.internalId()) {
+ case MyRoot: {
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ return aRootDoc->object(ModelAPI_ResultPart::group(), myId);
+ }
+ case ParamsFolder:
+ case ConstructFolder:
+ case BodiesFolder:
+ case GroupsFolder:
+ return ObjectPtr();
+
+ case ParamObject:
+ return partDocument()->object(ModelAPI_ResultParameter::group(), theIndex.row());
+ case ConstructObject:
+ return partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row());
+ case BodiesObject:
+ return partDocument()->object(ModelAPI_ResultBody::group(), theIndex.row());
+ case GroupObject:
+ return partDocument()->object(ModelAPI_ResultGroup::group(), theIndex.row());
+ case HistoryObject:
+ return partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber());
+ }
+ return ObjectPtr();
+}
+
+bool XGUI_PartDataModel::hasDocument(const DocumentPtr& theDoc) const
+{
+ return (partDocument() == theDoc);
+}
+
+QModelIndex XGUI_PartDataModel::findParent(const ObjectPtr& theObject) const
+{
+ return findGroup(theObject->groupName().c_str());
+}
+
+QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const
+{
+ if (theGroup == ModelAPI_ResultParameter::group())
+ return createIndex(0, 0, (qint32) ParamsFolder);
+ if (theGroup == ModelAPI_ResultConstruction::group())
+ return createIndex(1, 0, (qint32) ConstructFolder);
+ if (theGroup == ModelAPI_ResultBody::group())
+ return createIndex(2, 0, (qint32) BodiesFolder);
+ if (theGroup == ModelAPI_ResultGroup::group())
+ return createIndex(3, 0, (qint32) GroupsFolder);
+ return QModelIndex();
+}
+
+ResultPartPtr XGUI_PartDataModel::part() const
+{
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ ObjectPtr aObj = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
+ return std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
+}
+
+QModelIndex XGUI_PartDataModel::objectIndex(const ObjectPtr& theObject) const
+{
+ QModelIndex aIndex;
+ if (theObject) {
+ if (part() == theObject)
+ return aIndex;
+
+ std::string aGroup = theObject->groupName();
+ DocumentPtr aDoc = theObject->document();
+ int aNb = aDoc->size(aGroup);
+ int aRow = -1;
+ for (int i = 0; i < aNb; i++) {
+ if (aDoc->object(aGroup, i) == theObject) {
+ aRow = i;
+ break;
+ }
+ }
+ if (aRow == -1)
+ return aIndex;
+ if (aGroup == ModelAPI_ResultParameter::group())
+ return createIndex(aRow, 0, (qint32) ParamObject);
+ else if (aGroup == ModelAPI_ResultConstruction::group())
+ return createIndex(aRow, 0, (qint32) ConstructObject);
+ else if (aGroup == ModelAPI_ResultBody::group())
+ return createIndex(aRow, 0, (qint32) BodiesObject);
+ else if (aGroup == ModelAPI_ResultGroup::group())
+ return createIndex(aRow, 0, (qint32) GroupObject);
+ else
+ return createIndex(aRow + getRowsNumber(), 0, (qint32) HistoryObject);