Salome HOME
Refactoring: static constants are replaced by inline functions in:
[modules/shaper.git] / src / XGUI / XGUI_PartDataModel.cpp
index 6610b64c58ff15dcbbe5b5268c7224188ad021c9..82dcc853209a70dcd63ecdac56af5df14c182336 100644 (file)
@@ -21,8 +21,8 @@
 //}
 
 
-XGUI_TopDataModel::XGUI_TopDataModel(const DocumentPtr& theDocument, QObject* theParent)
-  : XGUI_FeaturesModel(theDocument, theParent)
+XGUI_TopDataModel::XGUI_TopDataModel(QObject* theParent)
+  : XGUI_FeaturesModel(theParent)
 {
 }
   
@@ -41,17 +41,19 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
       return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex));
     case ParamObject:
       {
-        FeaturePtr aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row(), true);
+        DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+        FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::PARAMETERS_GROUP(), theIndex.row());
         if (aFeature)
-          return aFeature->data()->getName().c_str();
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
       } 
     case ConstructFolder:
         return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex));
     case ConstructObject:
       {
-        FeaturePtr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
+        DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+        FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row());
         if (aFeature)
-          return aFeature->data()->getName().c_str();
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
       }
     }
     break;
@@ -65,7 +67,8 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
       return QIcon(":pictures/constr_folder.png");
     case ConstructObject:
       {
-        FeaturePtr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
+        DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+        FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row());
         if (aFeature)
           return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
       }
@@ -92,11 +95,12 @@ int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const
   if (!theParent.isValid()) 
     return 2;
 
+  DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
   if (theParent.internalId() == ParamsFolder)
-    return myDocument->size(PARAMETERS_GROUP);
+    return aRootDoc->size(ModelAPI_Document::PARAMETERS_GROUP());
 
   if (theParent.internalId() == ConstructFolder)
-    return myDocument->size(CONSTRUCTIONS_GROUP);
+    return aRootDoc->size(ModelAPI_Document::CONSTRUCTIONS_GROUP());
 
   return 0;
 }
@@ -152,9 +156,15 @@ FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const
   case ConstructFolder:
     return FeaturePtr();
   case ParamObject:
-    return myDocument->feature(PARAMETERS_GROUP, theIndex.row(), true);
+    {
+      DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+      return aRootDoc->feature(ModelAPI_Document::PARAMETERS_GROUP(), theIndex.row());
+    }
   case ConstructObject:
-    return myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
+    {
+      DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+      return aRootDoc->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row());
+    }
   }
   return FeaturePtr();
 }
@@ -167,9 +177,9 @@ QModelIndex XGUI_TopDataModel::findParent(const FeaturePtr& theFeature) const
 
 QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const
 {
-  if (theGroup.compare(PARAMETERS_GROUP) == 0)
+  if (theGroup.compare(ModelAPI_Document::PARAMETERS_GROUP()) == 0)
     return createIndex(0, 0, (qint32) ParamsFolder);
-  if (theGroup.compare(CONSTRUCTIONS_GROUP) == 0)
+  if (theGroup.compare(ModelAPI_Document::CONSTRUCTIONS_GROUP()) == 0)
     return createIndex(1, 0, (qint32) ConstructFolder);
   return QModelIndex();
 }
@@ -178,19 +188,20 @@ QModelIndex XGUI_TopDataModel::featureIndex(const FeaturePtr& theFeature) const
 {
   QModelIndex aIndex;
   if (theFeature) {
+    DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
     std::string aGroup = theFeature->getGroup();
-    int aNb = myDocument->size(aGroup);
+    int aNb = aRootDoc->size(aGroup);
     int aRow = -1;
     for (int i = 0; i < aNb; i++) {
-      if (myDocument->feature(aGroup, i, true) == theFeature) {
+      if (aRootDoc->feature(aGroup, i) == theFeature) {
         aRow = i;
         break;
       }
     }
     if (aRow != -1) {
-      if (aGroup.compare(PARAMETERS_GROUP) == 0)
+      if (aGroup.compare(ModelAPI_Document::PARAMETERS_GROUP()) == 0)
         return createIndex(aRow, 0, (qint32) ParamObject);
-      if (aGroup.compare(CONSTRUCTIONS_GROUP) == 0)
+      if (aGroup.compare(ModelAPI_Document::CONSTRUCTIONS_GROUP()) == 0)
         return createIndex(aRow, 0, (qint32) ConstructObject);
     }
   }
@@ -202,8 +213,8 @@ QModelIndex XGUI_TopDataModel::featureIndex(const FeaturePtr& theFeature) const
 //******************************************************************
 //******************************************************************
 //******************************************************************
-XGUI_PartDataModel::XGUI_PartDataModel(const DocumentPtr& theDocument, QObject* theParent)
-  : XGUI_PartModel(theDocument, theParent)
+XGUI_PartDataModel::XGUI_PartDataModel(QObject* theParent)
+  : XGUI_PartModel(theParent)
 {
 }
 
@@ -220,9 +231,10 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
     switch (theIndex.internalId()) {
     case MyRoot:
       {
-        FeaturePtr aFeature = myDocument->feature(PARTS_GROUP, myId, true);
+        DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+        FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::PARTS_GROUP(), myId);
         if (aFeature)
-          return aFeature->data()->getName().c_str();
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
       }
     case ParamsFolder:
       return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex));
@@ -232,19 +244,19 @@ 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(), true);
+        FeaturePtr aFeature = featureDocument()->feature(ModelAPI_Document::PARAMETERS_GROUP(), theIndex.row());
         if (aFeature)
-          return aFeature->data()->getName().c_str();
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
       }
     case ConstructObject:
       {
-        FeaturePtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
+        FeaturePtr aFeature = featureDocument()->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row());
         if (aFeature)
-          return aFeature->data()->getName().c_str();
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
       }
     case HistoryObject:
       {
-        FeaturePtr aFeature = featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3, true);
+        FeaturePtr aFeature = featureDocument()->feature(ModelAPI_Document::FEATURES_GROUP(), theIndex.row() - 3);
         if (aFeature)
           return aFeature->data()->getName().c_str();
       }
@@ -262,13 +274,13 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
       return QIcon(":pictures/constr_folder.png");
     case ConstructObject:
       {
-        FeaturePtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
+        FeaturePtr aFeature = featureDocument()->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row());
         if (aFeature)
           return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
       }
     case HistoryObject:
       {
-        FeaturePtr aFeature = featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3, true);
+        FeaturePtr aFeature = featureDocument()->feature(ModelAPI_Document::FEATURES_GROUP(), theIndex.row() - 3);
         if (aFeature)
           return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
       }
@@ -291,18 +303,20 @@ QVariant XGUI_PartDataModel::headerData(int section, Qt::Orientation orientation
 
 int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const
 {
-  if (!parent.isValid()) 
-    if (myDocument->feature(PARTS_GROUP, myId, true))
+  if (!parent.isValid()) {
+    DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+    if (aRootDoc->feature(ModelAPI_Document::PARTS_GROUP(), myId))
       return 1;
     else 
       return 0;
+  }
   switch (parent.internalId()) {
   case MyRoot:
-    return 3 + featureDocument()->size(FEATURES_GROUP);
+    return 3 + featureDocument()->size(ModelAPI_Document::FEATURES_GROUP());
   case ParamsFolder:
-    return featureDocument()->size(PARAMETERS_GROUP);
+    return featureDocument()->size(ModelAPI_Document::PARAMETERS_GROUP());
   case ConstructFolder:
-    return featureDocument()->size(CONSTRUCTIONS_GROUP);
+    return featureDocument()->size(ModelAPI_Document::CONSTRUCTIONS_GROUP());
   case BodiesFolder:
     return 0;
   }
@@ -368,7 +382,8 @@ bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const
 
 DocumentPtr XGUI_PartDataModel::featureDocument() const
 {
-  FeaturePtr aFeature = myDocument->feature(PARTS_GROUP, myId, true);
+  DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+  FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::PARTS_GROUP(), myId, true);
   return aFeature->data()->docRef("PartDocument")->value();
 }
  
@@ -376,20 +391,22 @@ FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const
 {
   switch (theIndex.internalId()) {
   case MyRoot:
-    if (theIndex.row() < 3) {
-      return myDocument->feature(PARTS_GROUP, myId, true);
-    } else 
-      return featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3, true);
+    {
+      DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+      return aRootDoc->feature(ModelAPI_Document::PARTS_GROUP(), myId);
+    }
   case ParamsFolder:
   case ConstructFolder:
   case BodiesFolder:
     return FeaturePtr();
   case ParamObject:
-    return featureDocument()->feature(PARAMETERS_GROUP, theIndex.row(), true);
+    return featureDocument()->feature(ModelAPI_Document::PARAMETERS_GROUP(), theIndex.row());
   case ConstructObject:
-    return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
+    return featureDocument()->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row());
   //case BodiesObject:
-  //  return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
+  //  return featureDocument()->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row());
+  case HistoryObject:
+    return featureDocument()->feature(ModelAPI_Document::FEATURES_GROUP(), theIndex.row() - 3);
   }
   return FeaturePtr();
 }
@@ -407,16 +424,17 @@ QModelIndex XGUI_PartDataModel::findParent(const FeaturePtr& theFeature) const
 
 QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const
 {
-  if (theGroup.compare(PARAMETERS_GROUP) == 0)
+  if (theGroup.compare(ModelAPI_Document::PARAMETERS_GROUP()) == 0)
     return createIndex(0, 0, (qint32) ParamsFolder);
-  if (theGroup.compare(CONSTRUCTIONS_GROUP) == 0)
+  if (theGroup.compare(ModelAPI_Document::CONSTRUCTIONS_GROUP()) == 0)
     return createIndex(1, 0, (qint32) ConstructFolder);
   return QModelIndex();
 }
 
 FeaturePtr XGUI_PartDataModel::part() const
 {
-  return myDocument->feature(PARTS_GROUP, myId, true);
+  DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+  return aRootDoc->feature(ModelAPI_Document::PARTS_GROUP(), myId, true);
 }
 
 QModelIndex XGUI_PartDataModel::featureIndex(const FeaturePtr& theFeature) const
@@ -426,20 +444,22 @@ QModelIndex XGUI_PartDataModel::featureIndex(const FeaturePtr& theFeature) const
     if (part() == theFeature) 
       return aIndex;
 
-    std::string aGroup = theFeature->getGroup();
-    int aNb = myDocument->size(aGroup);
+    //std::string aGroup = theFeature->getGroup();
+    DocumentPtr aDoc = theFeature->document();
+    int aNb = aDoc->size(ModelAPI_Document::FEATURES_GROUP());
     int aRow = -1;
     for (int i = 0; i < aNb; i++) {
-      if (myDocument->feature(aGroup, i, true) == theFeature) {
+      if (aDoc->feature(ModelAPI_Document::FEATURES_GROUP(), i) == theFeature) {
         aRow = i;
         break;
       }
     }
     if (aRow != -1) {
-      if (aGroup.compare(PARAMETERS_GROUP) == 0)
+      return createIndex(aRow + 3, 0, (qint32) HistoryObject);
+/*      if (aGroup.compare(PARAMETERS_GROUP) == 0)
         return createIndex(aRow, 0, (qint32) ParamObject);
       if (aGroup.compare(CONSTRUCTIONS_GROUP) == 0)
-        return createIndex(aRow, 0, (qint32) ConstructObject);
+        return createIndex(aRow, 0, (qint32) ConstructObject);*/
     }
   }
   return aIndex;