]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #22: History branch for parts and icons of features
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 12 May 2014 13:29:33 +0000 (17:29 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 12 May 2014 13:29:33 +0000 (17:29 +0400)
src/XGUI/XGUI_DocumentDataModel.cpp
src/XGUI/XGUI_DocumentDataModel.h
src/XGUI/XGUI_PartDataModel.cpp
src/XGUI/XGUI_PartDataModel.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 719b6f466d2dcb19e14eb6c49dc3a50d0e4bf253..16a56174e2c13013a8ac36e29399bd0ccc315719 100644 (file)
@@ -1,5 +1,6 @@
 #include "XGUI_DocumentDataModel.h"
 #include "XGUI_PartDataModel.h"
+#include "XGUI_Workshop.h"
 
 #include <ModelAPI_PluginManager.h>
 #include <ModelAPI_Document.h>
@@ -9,6 +10,7 @@
 
 #include <Events_Loop.h>
 
+#include <Config_FeatureMessage.h>
 
 #include <QIcon>
 #include <QString>
@@ -40,7 +42,7 @@ XGUI_DocumentDataModel::~XGUI_DocumentDataModel()
 void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage)
 {
   // Created object event *******************
-  if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_CREATED) {
+  if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
     const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
     boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
     boost::shared_ptr<ModelAPI_Document> aDoc = aFeature->document();
@@ -77,7 +79,7 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage)
     }
 
   // Deleted object event ***********************
-  } else if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_DELETED) {
+  } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED)) {
     const Model_FeatureDeletedMessage* aUpdMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
     boost::shared_ptr<ModelAPI_Document> aDoc = aUpdMsg->document();
 
@@ -110,11 +112,12 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage)
     }
 
   // Deleted object event ***********************
-  } else if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_UPDATED) {
-    const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
-    boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
-    boost::shared_ptr<ModelAPI_Document> aDoc = aFeature->document();
+  } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED)) {
+    //const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
+    //boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
+    //boost::shared_ptr<ModelAPI_Document> aDoc = aFeature->document();
     
+    // TODO: Identify the necessary index by the modified feature
     QModelIndex aIndex;
     emit dataChanged(aIndex, aIndex);
 
@@ -168,15 +171,7 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole)
         else 
           return QVariant();
       case Qt::DecorationRole:
-        {
-          std::string aType = aFeature->getKind();
-          if (aType.compare("Point") == 0)
-            return QIcon(":pictures/point_ico.png");
-          if (aType.compare("Part") == 0)
-            return QIcon(":pictures/part_ico.png");
-          if (aType.compare("Sketch") == 0)
-            return QIcon(":icons/sketch.png");
-        }
+        return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
       case Qt::ToolTipRole:
         return tr("Feature object");
       default:
index 3c90dcf1f5e6f7c54d964f7c506fb54fb10d5b4e..7214c82f4e443a68244b4e8428c49ad6618fb6bf 100644 (file)
@@ -97,6 +97,7 @@ private:
 
   //! List of saved QModelIndexes created by sub-models
   QList<QModelIndex*> myIndexes;
+
 };
 
 #endif
\ No newline at end of file
index 0e31dd7fd7bea98a67cfbad22ab9b509b21e0570..cc5b7395c17e8c856e4f9610eceb95040f72fc4d 100644 (file)
@@ -1,4 +1,5 @@
 #include "XGUI_PartDataModel.h"
+#include "XGUI_Workshop.h"
 
 #include <ModelAPI_PluginManager.h>
 #include <ModelAPI_Document.h>
@@ -47,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;
 
@@ -206,6 +211,13 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
         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:
@@ -219,7 +231,18 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
     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:
@@ -243,7 +266,7 @@ int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const
       return 0;
   switch (parent.internalId()) {
   case MyRoot:
-    return 3;
+    return 3 + featureDocument()->size(FEATURES_GROUP);
   case ParamsFolder:
     return featureDocument()->size(PARAMETERS_GROUP);
   case ConstructFolder:
@@ -273,7 +296,9 @@ QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelInd
     case 1:
       return createIndex(1, 0, (qint32) ConstructFolder);
     case 2:
-      return createIndex(1, 0, (qint32) BodiesFolder);
+      return createIndex(2, 0, (qint32) BodiesFolder);
+    default:
+      return createIndex(theRow, theColumn, (qint32) HistoryObject);
     }
   case ParamsFolder:
     return createIndex(theRow, 0, (qint32) ParamObject);
@@ -293,6 +318,7 @@ QModelIndex XGUI_PartDataModel::parent(const QModelIndex& theIndex) const
   case ParamsFolder:
   case ConstructFolder:
   case BodiesFolder:
+  case HistoryObject:
     return createIndex(0, 0, (qint32) MyRoot);
   case ParamObject:
     return createIndex(0, 0, (qint32) ParamsFolder);
@@ -318,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();
index ace36a74380f4ef33337d5dc9762b9c9a53f4281..abda0bfded8df3b8a616c6aee4b265d9e0a5dccb 100644 (file)
@@ -105,7 +105,8 @@ private:
     ConstructFolder,
     ConstructObject,
     BodiesFolder,
-    BodieswObject
+    BodieswObject,
+    HistoryObject
   };
 
 };
index 14d4c945941719e2f063cd210536316cbcf1b254..48a4615d20c320f770029b7b384d8d52c08dda94 100644 (file)
 #include <dlfcn.h>
 #endif
 
+
+QMap<QString, QString> XGUI_Workshop::myIcons;
+
+QString XGUI_Workshop::featureIcon(const std::string& theId)
+{
+  QString aId(theId.c_str());
+  if (myIcons.contains(aId))
+    return myIcons[aId];
+  return QString();
+}
+
 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   : QObject(),
   myCurrentFile(QString()),
@@ -270,6 +281,9 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
 #endif
     return;
   }
+  // Remember features icons
+  myIcons[QString(theMessage->id().c_str())] = QString(theMessage->icon().c_str());
+
   //Find or create Workbench
   QString aWchName = QString::fromStdString(theMessage->workbenchId());
   QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
index 0d6c8ff3da9a1a6a34725130e07a7b243e5da08e..922a4dd89726886200b87b5e1ebbedaa8bbf3aca 100644 (file)
@@ -90,6 +90,10 @@ public:
 
   XGUI_ViewerProxy* viewer() const { return myViewerProxy; }
 
+  //! Returns icon name according to feature Id
+  static QString featureIcon(const std::string& theId);
+
+
 signals:
   void salomeViewerSelection();
 
@@ -154,6 +158,9 @@ private:
   XGUI_SalomeConnector* mySalomeConnector;
   XGUI_ErrorDialog* myErrorDlg;
   XGUI_ViewerProxy* myViewerProxy;
+
+  static QMap<QString, QString> myIcons;
+
 };
 
 #endif