]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/Model/Model_Document.cpp
Salome HOME
No automatic rebuild: only on preview. Update of visualization behavior due to the...
[modules/shaper.git] / src / Model / Model_Document.cpp
index 4adcc0aa63996ff4489df3f22358d6906aa46ab7..57241b6b52926fa23f5ac029c2628988f5a2ee36 100644 (file)
@@ -461,13 +461,22 @@ static int RemoveFromRefArray(TDF_Label theArrayLab, TDF_Label theReferenced, co
 
 void Model_Document::removeFeature(FeaturePtr theFeature)
 {
+  // check the feature: it must have no depended objects on it
+  std::list<ResultPtr>::const_iterator aResIter = theFeature->results().cbegin();
+  for(; aResIter != theFeature->results().cend(); aResIter++) {
+    if (myConcealedResults.find(*aResIter) != myConcealedResults.end()) {
+      Events_Error::send("Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
+      return;
+    }
+  }
   boost::shared_ptr<Model_Data> aData = boost::static_pointer_cast<Model_Data>(theFeature->data());
   TDF_Label aFeatureLabel = aData->label().Father();
   if (myObjs.IsBound(aFeatureLabel))
     myObjs.UnBind(aFeatureLabel);
   else
     return;  // not found feature => do not remove
-
+  // erase fields
+  theFeature->erase();
   // erase all attributes under the label of feature
   aFeatureLabel.ForgetAllAttributes();
   // remove it from the references array
@@ -475,6 +484,7 @@ void Model_Document::removeFeature(FeaturePtr theFeature)
 
   // event: feature is deleted
   ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), ModelAPI_Feature::group());
+  /* this is in "erase"
   // results of this feature must be redisplayed
   static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
   const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = theFeature->results();
@@ -485,6 +495,7 @@ void Model_Document::removeFeature(FeaturePtr theFeature)
     ModelAPI_EventCreator::get()->sendUpdated(aRes, EVENT_DISP);
     ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), aRes->groupName());
   }
+  */
 }
 
 FeaturePtr Model_Document::feature(TDF_Label& theLabel)
@@ -745,14 +756,17 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
       static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
       const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
       std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
+      /*
       for (; aRIter != aResults.cend(); aRIter++) {
         boost::shared_ptr<ModelAPI_Result> aRes = *aRIter;
         //aRes->setData(boost::shared_ptr<ModelAPI_Data>()); // deleted flag
         ModelAPI_EventCreator::get()->sendUpdated(aRes, EVENT_DISP);
         ModelAPI_EventCreator::get()->sendDeleted(aThis, aRes->groupName());
       }
+      */
       // redisplay also removed feature (used for sketch and AISObject)
       ModelAPI_EventCreator::get()->sendUpdated(aFeature, EVENT_DISP);
+      aFeature->erase();
     } else
       aFIter.Next();
   }
@@ -913,6 +927,11 @@ void Model_Document::objectIsReferenced(const ObjectPtr& theObject)
       boost::shared_ptr<ModelAPI_Document> aThis = 
         Model_Application::getApplication()->getDocument(myID);
       ModelAPI_EventCreator::get()->sendDeleted(aThis, ModelAPI_ResultBody::group());
+
+      static Events_Loop* aLoop = Events_Loop::loop();
+      static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+      static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
+      aECreator->sendUpdated(aResult, EVENT_DISP);
     }
   }
 }
@@ -924,11 +943,12 @@ void Model_Document::objectIsNotReferenced(const ObjectPtr& theObject)
   if (aResult) {
     std::set<ResultPtr>::iterator aFind = myConcealedResults.find(aResult);
     if (aFind != myConcealedResults.end()) {
+      ResultPtr aFeature = *aFind;
       myConcealedResults.erase(aFind);
       boost::shared_ptr<ModelAPI_Document> aThis = 
         Model_Application::getApplication()->getDocument(myID);
       static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
-      ModelAPI_EventCreator::get()->sendUpdated(*aFind, anEvent, false);
+      ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent, false);
     } else {
       Events_Error::send(std::string("The object '") + aResult->data()->name() +
         "' was not referenced '");