Salome HOME
Refresh menu size after chnges in preferences
[modules/shaper.git] / src / XGUI / XGUI_PartDataModel.cpp
index 7ce708e65fe4e12e7c3faf5fbeb521512428d71e..d67c2ec4fc27861b06324b3a0489dfec000ee27f 100644 (file)
@@ -4,15 +4,20 @@
 #include <ModelAPI_PluginManager.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_AttributeDocRef.h>
 #include <ModelAPI_Object.h>
+#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultParameters.h>
+#include <ModelAPI_ResultBody.h>
 
 #include <QIcon>
 #include <QBrush>
 
 
-//FeaturePtr featureObj(const FeaturePtr& theFeature)
+//ObjectPtr featureObj(const ObjectPtr& theFeature)
 //{
 //  ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
 //  if (aObject)
@@ -42,18 +47,29 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
     case ParamObject:
       {
         DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
-        FeaturePtr aFeature = aRootDoc->feature(PARAMETERS_GROUP, theIndex.row());
-        if (aFeature)
-          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
+        ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row());
+        if (aObject)
+          return aObject->data()->name().c_str();
       } 
+      break;
     case ConstructFolder:
         return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex));
     case ConstructObject:
       {
         DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
-        FeaturePtr aFeature = aRootDoc->feature(CONSTRUCTIONS_GROUP, theIndex.row());
-        if (aFeature)
-          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
+        ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row());
+        if (aObject)
+          return aObject->data()->name().c_str();
+      }
+      break;
+    case BodiesFolder:
+        return tr("Bodies") + QString(" (%1)").arg(rowCount(theIndex));
+    case BodiesObject:
+      {
+        DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+        ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultBody::group(), theIndex.row());
+        if (aObject)
+          return aObject->data()->name().c_str();
       }
     }
     break;
@@ -63,15 +79,12 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
     switch (theIndex.internalId()) {
     case ParamsFolder:
       return QIcon(":pictures/params_folder.png");
+    case BodiesFolder:
     case ConstructFolder:
       return QIcon(":pictures/constr_folder.png");
     case ConstructObject:
-      {
-        DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
-        FeaturePtr aFeature = aRootDoc->feature(CONSTRUCTIONS_GROUP, theIndex.row());
-        if (aFeature)
-          return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
-      }
+    case BodiesObject:
+      return QIcon(":pictures/constr_object.png");
     }
     break;
 
@@ -93,15 +106,17 @@ QVariant XGUI_TopDataModel::headerData(int section, Qt::Orientation orientation,
 int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const
 {
   if (!theParent.isValid()) 
-    return 2;
+    return 3;
 
   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());
 
+  if (theParent.internalId() == BodiesFolder)
+    return aRootDoc->size(ModelAPI_ResultBody::group());
   return 0;
 }
 
@@ -118,6 +133,8 @@ QModelIndex XGUI_TopDataModel::index(int theRow, int theColumn, const QModelInde
       return createIndex(theRow, theColumn, (qint32) ParamsFolder);
     case 1:
       return createIndex(theRow, theColumn, (qint32) ConstructFolder);
+    case 2:
+      return createIndex(theRow, theColumn, (qint32) BodiesFolder);
     }
   } else {
     if (theParent.internalId() == ParamsFolder)
@@ -125,6 +142,9 @@ QModelIndex XGUI_TopDataModel::index(int theRow, int theColumn, const QModelInde
 
     if (theParent.internalId() == ConstructFolder)
       return createIndex(theRow, theColumn, (qint32) ConstructObject);
+
+    if (theParent.internalId() == BodiesFolder)
+      return createIndex(theRow, theColumn, (qint32) BodiesObject);
   }
   return QModelIndex();
 }
@@ -135,11 +155,14 @@ QModelIndex XGUI_TopDataModel::parent(const QModelIndex& theIndex) const
   switch (aId) {
   case ParamsFolder:
   case ConstructFolder:
+  case BodiesFolder:
     return QModelIndex();
   case ParamObject:
     return createIndex(0, 0, (qint32) ParamsFolder);
   case ConstructObject:
     return createIndex(1, 0, (qint32) ConstructFolder);
+  case BodiesObject:
+    return createIndex(2, 0, (qint32) BodiesFolder);
   }
   return QModelIndex();
 }
@@ -149,60 +172,70 @@ bool XGUI_TopDataModel::hasChildren(const QModelIndex& theParent) const
   return rowCount(theParent) > 0;
 }
 
-FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const
+ObjectPtr XGUI_TopDataModel::object(const QModelIndex& theIndex) const
 {
   switch (theIndex.internalId()) {
   case ParamsFolder:
   case ConstructFolder:
-    return FeaturePtr();
+  case BodiesFolder:
+    return ObjectPtr();
   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());
+    }
+  case BodiesObject:
+    {
+      DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+      return aRootDoc->object(ModelAPI_ResultBody::group(), theIndex.row());
     }
   }
-  return FeaturePtr();
+  return ObjectPtr();
 }
 
 
-QModelIndex XGUI_TopDataModel::findParent(const FeaturePtr& 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 == ModelAPI_ResultParameters::group())
     return createIndex(0, 0, (qint32) ParamsFolder);
-  if (theGroup.compare(CONSTRUCTIONS_GROUP) == 0)
+  if (theGroup == ModelAPI_ResultConstruction::group())
     return createIndex(1, 0, (qint32) ConstructFolder);
+  if (theGroup == ModelAPI_ResultBody::group())
+    return createIndex(2, 0, (qint32) BodiesFolder);
   return QModelIndex();
 }
 
-QModelIndex XGUI_TopDataModel::featureIndex(const FeaturePtr& 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 == ModelAPI_ResultParameters::group())
         return createIndex(aRow, 0, (qint32) ParamObject);
-      if (aGroup.compare(CONSTRUCTIONS_GROUP) == 0)
+      if (aGroup == ModelAPI_ResultConstruction::group())
         return createIndex(aRow, 0, (qint32) ConstructObject);
+      if (aGroup == ModelAPI_ResultBody::group())
+        return createIndex(aRow, 0, (qint32) BodiesObject);
     }
   }
   return aIndex;
@@ -232,9 +265,9 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
     case MyRoot:
       {
         DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
-        FeaturePtr aFeature = aRootDoc->feature(PARTS_GROUP, myId);
-        if (aFeature)
-          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
+        ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
+        if (aObject)
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
       }
     case ParamsFolder:
       return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex));
@@ -244,21 +277,27 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
       return tr("Bodies") + QString(" (%1)").arg(rowCount(theIndex));
     case ParamObject:
       {
-        FeaturePtr aFeature = featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
-        if (aFeature)
-          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
+        ObjectPtr aObject = partDocument()->object(ModelAPI_ResultParameters::group(), theIndex.row());
+        if (aObject)
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
       }
     case ConstructObject:
       {
-        FeaturePtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
-        if (aFeature)
-          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
+        ObjectPtr aObject = partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row());
+        if (aObject)
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
+      }
+    case BodiesObject:
+      {
+        ObjectPtr aObject = partDocument()->object(ModelAPI_ResultBody::group(), theIndex.row());
+        if (aObject)
+          return aObject->data()->name().c_str();
       }
     case HistoryObject:
       {
-        FeaturePtr 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;
@@ -273,14 +312,12 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
     case BodiesFolder:
       return QIcon(":pictures/constr_folder.png");
     case ConstructObject:
-      {
-        FeaturePtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
-        if (aFeature)
-          return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
-      }
+    case BodiesObject:
+      return QIcon(":pictures/constr_object.png");
     case HistoryObject:
       {
-        FeaturePtr aFeature = featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3);
+        ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 3);
+        FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
         if (aFeature)
           return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
       }
@@ -305,20 +342,20 @@ 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;
+    return partDocument()->size(ModelAPI_ResultBody::group());
   }
   return 0;
 }
@@ -370,6 +407,8 @@ QModelIndex XGUI_PartDataModel::parent(const QModelIndex& theIndex) const
     return createIndex(0, 0, (qint32) ParamsFolder);
   case ConstructObject:
     return createIndex(1, 0, (qint32) ConstructFolder);
+  case BodiesObject:
+    return createIndex(2, 0, (qint32) BodiesFolder);
   }
   return QModelIndex();
 }
@@ -380,86 +419,94 @@ bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const
 }
 
 
-DocumentPtr XGUI_PartDataModel::featureDocument() const
+DocumentPtr XGUI_PartDataModel::partDocument() const
 {
   DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
-  FeaturePtr aFeature = aRootDoc->feature(PARTS_GROUP, myId, true);
-  return aFeature->data()->docRef("PartDocument")->value();
+  ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
+  ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
+  return aPart->partDoc();
 }
  
-FeaturePtr 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 FeaturePtr();
+    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());
-  //case BodiesObject:
-  //  return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+    return partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row());
+  case BodiesObject:
+    return partDocument()->object(ModelAPI_ResultBody::group(), theIndex.row());
   case HistoryObject:
-    return featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); 
+    return partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 3); 
   }
-  return FeaturePtr();
+  return ObjectPtr();
 }
 
 bool XGUI_PartDataModel::hasDocument(const DocumentPtr& theDoc) const
 {
-  return (featureDocument() == theDoc);
+  return (partDocument() == theDoc);
 }
 
 
-QModelIndex XGUI_PartDataModel::findParent(const FeaturePtr& 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);
+  if (theGroup.compare(ModelAPI_ResultBody::group()) == 0)
+    return createIndex(2, 0, (qint32) BodiesFolder);
   return QModelIndex();
 }
 
-FeaturePtr XGUI_PartDataModel::part() const
+ResultPartPtr XGUI_PartDataModel::part() const
 {
   DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
-  return aRootDoc->feature(PARTS_GROUP, myId, true);
+  ObjectPtr aObj = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
+  return boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
 }
 
-QModelIndex XGUI_PartDataModel::featureIndex(const FeaturePtr& theFeature) const
+QModelIndex XGUI_PartDataModel::objectIndex(const ObjectPtr& theObject) const
 {
   QModelIndex aIndex;
-  if (theFeature) {
-    if (part() == theFeature
+  if (theObject) {
+    if (part() == theObject
       return aIndex;
 
-    std::string aGroup = theFeature->getGroup();
-    DocumentPtr aDoc = theFeature->document();
+    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->feature(aGroup, i) == theFeature) {
+      if (aDoc->object(aGroup, i) == theObject) {
         aRow = i;
         break;
       }
     }
-    if (aRow != -1) {
-      if (aGroup.compare(PARAMETERS_GROUP) == 0)
+    if (aRow == -1)
+      return aIndex;
+    if (aGroup == ModelAPI_ResultParameters::group())
         return createIndex(aRow, 0, (qint32) ParamObject);
-      if (aGroup.compare(CONSTRUCTIONS_GROUP) == 0)
+    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
+      return createIndex(aRow + 3, 0, (qint32) HistoryObject);
   }
   return aIndex;
 }