Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / XGUI / XGUI_DocumentDataModel.cpp
index 0fcbd794be563e6dd1c141aab7aeee2b3fc31fa0..2744d196d4114b08b7ae71f7ed55397bb2b75454 100644 (file)
@@ -29,9 +29,10 @@ XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent)
       myActivePart(0)
 {
   // Register in event loop
-  Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
-  Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-  Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+  //Events_Loop* aLoop = Events_Loop::loop();
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
 
   // Create a top part of data tree model
   myModel = new XGUI_TopDataModel(this);
@@ -43,14 +44,14 @@ XGUI_DocumentDataModel::~XGUI_DocumentDataModel()
   clearModelIndexes();
 }
 
-void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage)
+void XGUI_DocumentDataModel::processEvent(const boost::shared_ptr<Events_Message>& theMessage)
 {
-  DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
+  DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
 
   // Created object event *******************
   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
-    const ModelAPI_ObjectUpdatedMessage* aUpdMsg =
-        dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
+    boost::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
+        boost::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
     std::set<ObjectPtr> aObjects = aUpdMsg->objects();
 
     std::set<ObjectPtr>::const_iterator aIt;
@@ -96,8 +97,8 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage)
     }
     // Deleted object event ***********************
   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
-    const ModelAPI_ObjectDeletedMessage* aUpdMsg =
-        dynamic_cast<const ModelAPI_ObjectDeletedMessage*>(theMessage);
+    boost::shared_ptr<ModelAPI_ObjectDeletedMessage> aUpdMsg =
+        boost::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
     DocumentPtr aDoc = aUpdMsg->document();
     std::set<std::string> aGroups = aUpdMsg->groups();
 
@@ -139,7 +140,7 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage)
     }
     // Deleted object event ***********************
   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
-    //const ModelAPI_ObjectUpdatedMessage* aUpdMsg = dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
+    //boost::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg = boost::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
     //ObjectPtr aFeature = aUpdMsg->feature();
     //DocumentPtr aDoc = aFeature->document();
 
@@ -155,7 +156,7 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage)
 
 void XGUI_DocumentDataModel::rebuildDataTree()
 {
-  DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
+  DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
 
   beginResetModel();
   clearModelIndexes();
@@ -200,7 +201,7 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole)
           case HistoryNode:
           {
             int aOffset = historyOffset();
-            DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
+            DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
             ObjectPtr aObj = aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset);
             FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
             if (!aFeature)
@@ -242,7 +243,7 @@ QVariant XGUI_DocumentDataModel::headerData(int theSection, Qt::Orientation theO
 int XGUI_DocumentDataModel::rowCount(const QModelIndex& theParent) const
 {
   if (!theParent.isValid()) {
-    DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
+    DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
     // Size of external models
     int aVal = historyOffset();
     // Plus history size
@@ -371,7 +372,7 @@ ObjectPtr XGUI_DocumentDataModel::object(const QModelIndex& theIndex) const
   if (theIndex.internalId() == PartsFolder)
     return ObjectPtr();
   if (theIndex.internalId() == HistoryNode) {
-    DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
+    DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
     int aOffset = historyOffset();
     return aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset);
   }
@@ -476,7 +477,7 @@ bool XGUI_DocumentDataModel::activatedIndex(const QModelIndex& theIndex)
           myActivePart->setItemsColor(ACTIVE_COLOR);
           myModel->setItemsColor(PASSIVE_COLOR);
         } else
-        myModel->setItemsColor(ACTIVE_COLOR);
+          myModel->setItemsColor(ACTIVE_COLOR);
         return true;
       }
     }
@@ -529,7 +530,7 @@ QModelIndex XGUI_DocumentDataModel::partIndex(const ResultPartPtr& theObject) co
 QModelIndex XGUI_DocumentDataModel::objectIndex(const ObjectPtr theObject) const
 {
   // Check that this feature belongs to root document
-  DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument();
+  DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
   DocumentPtr aDoc = theObject->document();
   if (aDoc == aRootDoc) {
     // This feature belongs to histrory or top model