Salome HOME
Call show method of the error dialog in it's thread. Fixes #79
[modules/shaper.git] / src / XGUI / XGUI_PartDataModel.cpp
index 2ce2c5a26ffc773a40cde820cfc84b9cb513bdb8..dc09185cc52be72def60de75adb7ccdb4e99c953 100644 (file)
 #include <QIcon>
 #include <QBrush>
 
+
+//FeaturePtr featureObj(const FeaturePtr& theFeature)
+//{
+//  ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
+//  if (aObject)
+//    return aObject->featureRef();
+//  return theFeature;
+//}
+
+
 XGUI_TopDataModel::XGUI_TopDataModel(const DocumentPtr& theDocument, QObject* theParent)
   : XGUI_FeaturesModel(theDocument, theParent)
 {
@@ -33,7 +43,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
       {
         FeaturePtr aFeature = myDocument->feature(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));
@@ -41,7 +51,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
       {
         FeaturePtr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
         if (aFeature)
-          return aFeature->data()->getName().c_str();
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
       }
     }
     break;
@@ -152,13 +162,7 @@ FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const
 
 QModelIndex XGUI_TopDataModel::findParent(const FeaturePtr& theFeature) const
 {
-  QString aGroup(theFeature->getGroup().c_str());
-
-  if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
-    return createIndex(0, 0, (qint32) ParamsFolder);
-  if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
-    return createIndex(1, 0, (qint32) ConstructFolder);
-  return QModelIndex();
+  return findGroup(theFeature->getGroup().c_str());
 }
 
 QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const
@@ -170,6 +174,30 @@ QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const
   return QModelIndex();
 }
 
+QModelIndex XGUI_TopDataModel::featureIndex(const FeaturePtr& theFeature) const
+{
+  QModelIndex aIndex;
+  if (theFeature) {
+    std::string aGroup = theFeature->getGroup();
+    int aNb = myDocument->size(aGroup);
+    int aRow = -1;
+    for (int i = 0; i < aNb; i++) {
+      if (myDocument->feature(aGroup, i) == theFeature) {
+        aRow = i;
+        break;
+      }
+    }
+    if (aRow != -1) {
+      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 aIndex;
+}
+
+
 
 //******************************************************************
 //******************************************************************
@@ -194,7 +222,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
       {
         FeaturePtr aFeature = myDocument->feature(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));
@@ -206,13 +234,13 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
       {
         FeaturePtr aFeature = featureDocument()->feature(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());
         if (aFeature)
-          return aFeature->data()->getName().c_str();
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
       }
     case HistoryObject:
       {
@@ -309,7 +337,7 @@ QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelInd
   case ConstructFolder:
     return createIndex(theRow, 0, (qint32) ConstructObject);
   case BodiesFolder:
-    return createIndex(theRow, 0, (qint32) BodieswObject);
+    return createIndex(theRow, 0, (qint32) BodiesObject);
   }
   return QModelIndex();
 }
@@ -340,10 +368,7 @@ bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const
 
 DocumentPtr XGUI_PartDataModel::featureDocument() const
 {
-  FeaturePtr aFeature = myDocument->feature(PARTS_GROUP, myId);
-  ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
-  if (aObject)
-    return aObject->featureRef()->data()->docRef("PartDocument")->value();
+  FeaturePtr aFeature = myDocument->feature(PARTS_GROUP, myId, true);
   return aFeature->data()->docRef("PartDocument")->value();
 }
  
@@ -351,17 +376,19 @@ FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const
 {
   switch (theIndex.internalId()) {
   case MyRoot:
-    if (theIndex.row() < 3)
-      return myDocument->feature(PARTS_GROUP, myId);
-    else 
-      return featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3);
+    return myDocument->feature(PARTS_GROUP, myId);
   case ParamsFolder:
   case ConstructFolder:
+  case BodiesFolder:
     return FeaturePtr();
   case ParamObject:
     return featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
   case ConstructObject:
     return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+  //case BodiesObject:
+  //  return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+  case HistoryObject:
+    return featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); 
   }
   return FeaturePtr();
 }
@@ -374,13 +401,7 @@ bool XGUI_PartDataModel::hasDocument(const DocumentPtr& theDoc) const
 
 QModelIndex XGUI_PartDataModel::findParent(const FeaturePtr& theFeature) const
 {
-  QString aGroup(theFeature->getGroup().c_str());
-
-  if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
-    return createIndex(0, 0, (qint32) ParamsFolder);
-  if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
-    return createIndex(1, 0, (qint32) ConstructFolder);
-  return QModelIndex();
+  return findGroup(theFeature->getGroup().c_str());
 }
 
 QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const
@@ -394,5 +415,31 @@ QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const
 
 FeaturePtr XGUI_PartDataModel::part() const
 {
-  return myDocument->feature(PARTS_GROUP, myId);
-}
\ No newline at end of file
+  return myDocument->feature(PARTS_GROUP, myId, true);
+}
+
+QModelIndex XGUI_PartDataModel::featureIndex(const FeaturePtr& theFeature) const
+{
+  QModelIndex aIndex;
+  if (theFeature) {
+    if (part() == theFeature) 
+      return aIndex;
+
+    std::string aGroup = theFeature->getGroup();
+    int aNb = myDocument->size(aGroup);
+    int aRow = -1;
+    for (int i = 0; i < aNb; i++) {
+      if (myDocument->feature(aGroup, i) == theFeature) {
+        aRow = i;
+        break;
+      }
+    }
+    if (aRow != -1) {
+      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 aIndex;
+}