Salome HOME
Load module defined in XML, not hardcoded "PartSet" module.
[modules/shaper.git] / src / XGUI / XGUI_PartDataModel.cpp
index 127c3478f83b339946447f9506afa2adf9f28b6d..cc5b7395c17e8c856e4f9610eceb95040f72fc4d 100644 (file)
@@ -1,7 +1,7 @@
 #include "XGUI_PartDataModel.h"
+#include "XGUI_Workshop.h"
 
 #include <ModelAPI_PluginManager.h>
-#include <ModelAPI_Iterator.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Data.h>
@@ -9,7 +9,7 @@
 
 #include <QIcon>
 
-XGUI_TopDataModel::XGUI_TopDataModel(const std::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent)
+XGUI_TopDataModel::XGUI_TopDataModel(const boost::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent)
   : XGUI_FeaturesModel(theDocument, theParent)
 {
 }
@@ -26,18 +26,18 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
     // return a name
     switch (theIndex.internalId()) {
     case ParamsFolder:
-      return tr("Parameters");
+      return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex));
     case ParamObject:
       {
-        std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row());
+        boost::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row());
         if (aFeature)
           return aFeature->data()->getName().c_str();
       } 
     case ConstructFolder:
-        return tr("Constructions");
+        return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex));
     case ConstructObject:
       {
-        std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+        boost::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
         if (aFeature)
           return aFeature->data()->getName().c_str();
       }
@@ -48,11 +48,15 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
     // return an Icon
     switch (theIndex.internalId()) {
     case ParamsFolder:
-        return QIcon(":pictures/params_folder.png");
+      return QIcon(":pictures/params_folder.png");
     case ConstructFolder:
-        return QIcon(":pictures/constr_folder.png");
+      return QIcon(":pictures/constr_folder.png");
     case ConstructObject:
-        return QIcon(":pictures/point_ico.png");
+      {
+        FeaturePtr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+        if (aFeature)
+          return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
+      }
     }
     break;
 
@@ -74,10 +78,10 @@ int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const
     return 2;
 
   if (theParent.internalId() == ParamsFolder)
-    return myDocument->featuresIterator(PARAMETERS_GROUP)->numIterationsLeft();
+    return myDocument->size(PARAMETERS_GROUP);
 
   if (theParent.internalId() == ConstructFolder)
-    return myDocument->featuresIterator(CONSTRUCTIONS_GROUP)->numIterationsLeft();
+    return myDocument->size(CONSTRUCTIONS_GROUP);
 
   return 0;
 }
@@ -141,7 +145,7 @@ FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const
 }
 
 
-QModelIndex XGUI_TopDataModel::findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const
+QModelIndex XGUI_TopDataModel::findParent(const boost::shared_ptr<ModelAPI_Feature>& theFeature) const
 {
   QString aGroup(theFeature->getGroup().c_str());
 
@@ -165,7 +169,7 @@ QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const
 //******************************************************************
 //******************************************************************
 //******************************************************************
-XGUI_PartDataModel::XGUI_PartDataModel(const std::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent)
+XGUI_PartDataModel::XGUI_PartDataModel(const boost::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent)
   : XGUI_PartModel(theDocument, theParent)
 {
 }
@@ -183,28 +187,37 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
     switch (theIndex.internalId()) {
     case MyRoot:
       {
-        std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
+        boost::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
         if (aFeature)
           return aFeature->data()->getName().c_str();
       }
     case ParamsFolder:
-      return tr("Parameters");
+      return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex));
     case ConstructFolder:
-      return tr("Constructions");
+      return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex));
+    case BodiesFolder:
+      return tr("Bodies") + QString(" (%1)").arg(rowCount(theIndex));
     case ParamObject:
       {
-        std::shared_ptr<ModelAPI_Feature> aFeature = 
+        boost::shared_ptr<ModelAPI_Feature> aFeature = 
           featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
         if (aFeature)
           return aFeature->data()->getName().c_str();
       }
     case ConstructObject:
       {
-        std::shared_ptr<ModelAPI_Feature> aFeature = 
+        boost::shared_ptr<ModelAPI_Feature> aFeature = 
           featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
         if (aFeature)
           return aFeature->data()->getName().c_str();
       }
+    case HistoryObject:
+      {
+        boost::shared_ptr<ModelAPI_Feature> aFeature = 
+          featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3);
+        if (aFeature)
+          return aFeature->data()->getName().c_str();
+      }
     }
     break;
   case Qt::DecorationRole:
@@ -215,9 +228,21 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
     case ParamsFolder:
       return QIcon(":pictures/params_folder.png");
     case ConstructFolder:
+    case BodiesFolder:
       return QIcon(":pictures/constr_folder.png");
     case ConstructObject:
-        return QIcon(":pictures/point_ico.png");
+      {
+        FeaturePtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+        if (aFeature)
+          return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
+      }
+    case HistoryObject:
+      {
+        boost::shared_ptr<ModelAPI_Feature> aFeature = 
+          featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3);
+        if (aFeature)
+          return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
+      }
     }
    break;
   case Qt::ToolTipRole:
@@ -241,11 +266,13 @@ int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const
       return 0;
   switch (parent.internalId()) {
   case MyRoot:
-    return 2;
+    return 3 + featureDocument()->size(FEATURES_GROUP);
   case ParamsFolder:
-    return featureDocument()->featuresIterator(PARAMETERS_GROUP)->numIterationsLeft();
+    return featureDocument()->size(PARAMETERS_GROUP);
   case ConstructFolder:
-    return featureDocument()->featuresIterator(CONSTRUCTIONS_GROUP)->numIterationsLeft();
+    return featureDocument()->size(CONSTRUCTIONS_GROUP);
+  case BodiesFolder:
+    return 0;
   }
   return 0;
 }
@@ -268,11 +295,17 @@ QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelInd
       return createIndex(0, 0, (qint32) ParamsFolder);
     case 1:
       return createIndex(1, 0, (qint32) ConstructFolder);
+    case 2:
+      return createIndex(2, 0, (qint32) BodiesFolder);
+    default:
+      return createIndex(theRow, theColumn, (qint32) HistoryObject);
     }
   case ParamsFolder:
     return createIndex(theRow, 0, (qint32) ParamObject);
   case ConstructFolder:
     return createIndex(theRow, 0, (qint32) ConstructObject);
+  case BodiesFolder:
+    return createIndex(theRow, 0, (qint32) BodieswObject);
   }
   return QModelIndex();
 }
@@ -284,6 +317,8 @@ QModelIndex XGUI_PartDataModel::parent(const QModelIndex& theIndex) const
     return QModelIndex();
   case ParamsFolder:
   case ConstructFolder:
+  case BodiesFolder:
+  case HistoryObject:
     return createIndex(0, 0, (qint32) MyRoot);
   case ParamObject:
     return createIndex(0, 0, (qint32) ParamsFolder);
@@ -299,9 +334,9 @@ bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const
 }
 
 
-std::shared_ptr<ModelAPI_Document> XGUI_PartDataModel::featureDocument() const
+boost::shared_ptr<ModelAPI_Document> XGUI_PartDataModel::featureDocument() const
 {
-  std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
+  boost::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
   return aFeature->data()->docRef("PartDocument")->value();
 }
 
@@ -309,7 +344,10 @@ FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const
 {
   switch (theIndex.internalId()) {
   case MyRoot:
-    return myDocument->feature(PARTS_GROUP, myId);
+    if (theIndex.row() < 3)
+      return myDocument->feature(PARTS_GROUP, myId);
+    else 
+      return featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3);
   case ParamsFolder:
   case ConstructFolder:
     return FeaturePtr();
@@ -321,13 +359,13 @@ FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const
   return FeaturePtr();
 }
 
-bool XGUI_PartDataModel::hasDocument(const std::shared_ptr<ModelAPI_Document>& theDoc) const
+bool XGUI_PartDataModel::hasDocument(const boost::shared_ptr<ModelAPI_Document>& theDoc) const
 {
   return (featureDocument() == theDoc);
 }
 
 
-QModelIndex XGUI_PartDataModel::findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const
+QModelIndex XGUI_PartDataModel::findParent(const boost::shared_ptr<ModelAPI_Feature>& theFeature) const
 {
   QString aGroup(theFeature->getGroup().c_str());