Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / Model / Model_Document.cxx
index 0e976420c45652ec8dd63448b16428dce0790e84..22641f4b3d7665376060fb4f3221448119503efd 100644 (file)
@@ -15,6 +15,8 @@
 #include <TDataStd_Comment.hxx>
 #include <TDF_ChildIDIterator.hxx>
 
+#include <climits>
+
 static const int UNDO_LIMIT = 10; // number of possible undo operations
 
 static const int TAG_GENERAL = 1; // general properties tag
@@ -222,7 +224,8 @@ void Model_Document::addFeature(const std::shared_ptr<ModelAPI_Feature> theFeatu
   TDF_Label anObjLab = aGroupLab.NewChild();
   std::shared_ptr<Model_Data> aData(new Model_Data);
   aData->setLabel(anObjLab);
-  aData->setDocument(Model_Application::getApplication()->getDocument(myID));
+  shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(myID);
+  aData->setDocument(aThis);
   theFeature->setData(aData);
   setUniqueName(theFeature);
   theFeature->initAttributes();
@@ -234,7 +237,7 @@ void Model_Document::addFeature(const std::shared_ptr<ModelAPI_Feature> theFeatu
 
   // event: feature is added
   static Event_ID anEvent = Event_Loop::eventByName(EVENT_FEATURE_CREATED);
-  ModelAPI_FeatureUpdatedMessage aMsg(theFeature, anEvent);
+  ModelAPI_FeatureUpdatedMessage aMsg(aThis, theFeature, anEvent);
   Event_Loop::loop()->send(aMsg);
 }
 
@@ -349,6 +352,7 @@ void Model_Document::setUniqueName(
 
 void Model_Document::synchronizeFeatures()
 {
+  shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(myID);
   // iterate groups labels
   TDF_ChildIDIterator aGroupsIter(myDoc->Main().FindChild(TAG_OBJECTS),
     TDataStd_Comment::GetID(), Standard_False);
@@ -362,9 +366,13 @@ void Model_Document::synchronizeFeatures()
   }
   // delete all groups left after the data model groups iteration
   while(aGroupNamesIter != myGroupsNames.end()) {
-    myFeatures.erase(*aGroupNamesIter);
-    myGroups.erase(*aGroupNamesIter);
+    string aGroupName = *aGroupNamesIter;
+    myFeatures.erase(aGroupName);
+    myGroups.erase(aGroupName);
     aGroupNamesIter = myGroupsNames.erase(aGroupNamesIter);
+    // say that features were deleted from group
+    ModelAPI_FeatureDeletedMessage aMsg(aThis, aGroupName);
+    Event_Loop::loop()->send(aMsg);
   }
   // create new groups basing on the following data model update
   for(; aGroupsIter.More(); aGroupsIter.Next()) {
@@ -387,7 +395,7 @@ void Model_Document::synchronizeFeatures()
     TDF_ChildIDIterator aFLabIter(
       aGroupsIter.Value()->Label(), TDataStd_Comment::GetID(), Standard_False);
     while(aFIter != aFeatures.end() || aFLabIter.More()) {
-      static const int INFINITE_TAG = MAXINT; // no label means that it exists somwhere in infinite
+      static const int INFINITE_TAG = INT_MAX; // no label means that it exists somwhere in infinite
       int aFeatureTag = INFINITE_TAG; 
       if (aFIter != aFeatures.end()) { // existing tag for feature
         shared_ptr<Model_Data> aData = dynamic_pointer_cast<Model_Data>((*aFIter)->data());
@@ -400,8 +408,7 @@ void Model_Document::synchronizeFeatures()
       if (aDSTag > aFeatureTag) { // feature is removed
         aFIter = aFeatures.erase(aFIter);
         // event: model is updated
-        ModelAPI_FeatureDeletedMessage aMsg(
-          Model_Application::getApplication()->getDocument(myID), aGroupName);
+        ModelAPI_FeatureDeletedMessage aMsg(aThis, aGroupName);
         Event_Loop::loop()->send(aMsg);
       } else if (aDSTag < aFeatureTag) { // a new feature is inserted
         // create a feature
@@ -417,7 +424,7 @@ void Model_Document::synchronizeFeatures()
         aFeature->initAttributes();
         // event: model is updated
         static Event_ID anEvent = Event_Loop::eventByName(EVENT_FEATURE_CREATED);
-        ModelAPI_FeatureUpdatedMessage aMsg(aFeature, anEvent);
+        ModelAPI_FeatureUpdatedMessage aMsg(aThis, aFeature, anEvent);
         Event_Loop::loop()->send(aMsg);
 
         if (aFIter == aFeatures.end()) {