]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1383 Preview button: implementation on the Updater level
authormpv <mpv@opencascade.com>
Tue, 12 Apr 2016 10:24:00 +0000 (13:24 +0300)
committermpv <mpv@opencascade.com>
Tue, 12 Apr 2016 10:24:00 +0000 (13:24 +0300)
src/Model/Model_Data.cpp
src/Model/Model_Objects.cpp
src/Model/Model_Update.cpp
src/Model/Model_Update.h
src/ModelAPI/ModelAPI_CompositeFeature.cpp

index f292ccc75a5272dc01d417f7f7eb08b1a7c6ab4a..351f2e4d1dfdcf660d93b6608f9458692a6bd7cc 100644 (file)
@@ -303,17 +303,19 @@ void Model_Data::blockSendAttributeUpdated(const bool theBlock)
 void Model_Data::erase()
 {
   if (!myLab.IsNull()) {
-    // remove in order to clear back references in other objects
-    std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
-    referencesToObjects(aRefs);
-    std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator anAttrIter = aRefs.begin();
-    for(; anAttrIter != aRefs.end(); anAttrIter++) {
-      std::list<ObjectPtr>::iterator aReferenced = anAttrIter->second.begin();
-      for(; aReferenced != anAttrIter->second.end(); aReferenced++) {
-        if (aReferenced->get() && (*aReferenced)->data()->isValid()) {
-          std::shared_ptr<Model_Data> aData = 
-            std::dynamic_pointer_cast<Model_Data>((*aReferenced)->data());
-          aData->removeBackReference(myAttrs[anAttrIter->first]);
+    if (myLab.HasAttribute()) {
+      // remove in order to clear back references in other objects
+      std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
+      referencesToObjects(aRefs);
+      std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator anAttrIter = aRefs.begin();
+      for(; anAttrIter != aRefs.end(); anAttrIter++) {
+        std::list<ObjectPtr>::iterator aReferenced = anAttrIter->second.begin();
+        for(; aReferenced != anAttrIter->second.end(); aReferenced++) {
+          if (aReferenced->get() && (*aReferenced)->data()->isValid()) {
+            std::shared_ptr<Model_Data> aData = 
+              std::dynamic_pointer_cast<Model_Data>((*aReferenced)->data());
+            aData->removeBackReference(myAttrs[anAttrIter->first]);
+          }
         }
       }
     }
index d421d2161ecc21ac8a19a55711108694b87079cc..e2eeeea2e2f30f150c96d9912a57ff31b4c80b3c 100644 (file)
@@ -691,8 +691,7 @@ void Model_Objects::synchronizeFeatures(
         // redisplay also removed feature (used for sketch and AISObject)
         ModelAPI_EventCreator::get()->sendUpdated(aFeature, aRedispEvent);
         updateHistory(aFeature);
-        // don't call this because it will ask the internal attributes
-        //aFeature->erase();
+        aFeature->erase();
 
         // unbind after the "erase" call: on abort sketch is removes sub-objects that corrupts aFIter
         myFeatures.UnBind(aFIter.Key());
index 2daf3f645bb70e66507a4e6b59418991f8d36216..afe7e7c41cc927acfea100c38e73ac160063e5df 100644 (file)
@@ -52,11 +52,16 @@ Model_Update::Model_Update()
   aLoop->registerListener(this, kOpStartEvent);
   static const Events_ID kStabilityEvent = aLoop->eventByName(EVENT_STABILITY_CHANGED);
   aLoop->registerListener(this, kStabilityEvent);
+  static const Events_ID kPreviewBlockedEvent = aLoop->eventByName(EVENT_PREVIEW_BLOCKED);
+  aLoop->registerListener(this, kPreviewBlockedEvent);
+  static const Events_ID kPreviewRequestedEvent = aLoop->eventByName(EVENT_PREVIEW_REQUESTED);
+  aLoop->registerListener(this, kPreviewRequestedEvent);
 
   //  Config_PropManager::findProp("Model update", "automatic_rebuild")->value() == "true";
   myIsParamUpdated = false;
   myIsFinish = false;
   myIsProcessed = false;
+  myIsPreviewBlocked = false;
 }
 
 bool Model_Update::addModified(FeaturePtr theFeature, FeaturePtr theReason) {
@@ -158,6 +163,9 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
   static const Events_ID kOpAbortEvent = aLoop->eventByName("AbortOperation");
   static const Events_ID kOpStartEvent = aLoop->eventByName("StartOperation");
   static const Events_ID kStabilityEvent = aLoop->eventByName(EVENT_STABILITY_CHANGED);
+  static const Events_ID kPreviewBlockedEvent = aLoop->eventByName(EVENT_PREVIEW_BLOCKED);
+  static const Events_ID kPreviewRequestedEvent = aLoop->eventByName(EVENT_PREVIEW_REQUESTED);
+
 #ifdef DEB_UPDATE
   std::cout<<"****** Event "<<theMessage->eventID().eventText()<<std::endl;
 #endif
@@ -165,6 +173,18 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
     updateStability(theMessage->sender());
     return;
   }
+  if (theMessage->eventID() == kPreviewBlockedEvent) {
+    myIsPreviewBlocked = true;
+    return;
+  }
+  if (theMessage->eventID() == kPreviewRequestedEvent) {
+    if (myIsPreviewBlocked) {
+      myIsPreviewBlocked = false;
+      processFeatures();
+      myIsPreviewBlocked = true;
+    }
+    return;
+  }
   // creation is added to "update" to avoid recomputation twice: on create and immediately after on update
   if (theMessage->eventID() == kCreatedEvent) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aMsg =
@@ -217,6 +237,7 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
     }
   } else if (theMessage->eventID() == kOpFinishEvent || theMessage->eventID() == kOpAbortEvent ||
       theMessage->eventID() == kOpStartEvent) {
+    myIsPreviewBlocked = false;
 
     if (theMessage->eventID() == kOpFinishEvent) {
       myIsFinish = true;
@@ -260,7 +281,8 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
 
 void Model_Update::processFeatures()
 {
-  if (!myIsProcessed) { // perform update of everything if it is not performed right now
+   // perform update of everything if it is not performed right now or any preview is blocked
+  if (!myIsProcessed && !myIsPreviewBlocked) {
     myIsProcessed = true;
     #ifdef DEB_UPDATE
       std::cout<<"****** Start processing"<<std::endl;
index c9fe39ab7178ee1e1f01d07e215b22eafd17b654..f0586c9a25cb23a012246de77e4ca827a9c1992f 100644 (file)
@@ -41,6 +41,8 @@ class Model_Update : public Events_Listener
   std::set<std::shared_ptr<ModelAPI_Feature> > myProcessOnFinish;
   /// to avoid infinitive cycling: feature -> count of the processing periods during this update
   std::map<std::shared_ptr<ModelAPI_Feature>, int > myProcessed;
+  /// if preview in hte property panel is blocked and any update is postponed until the end of operation
+  bool myIsPreviewBlocked;
 
  public:
   /// Is called only once, on startup of the application
index 34066ecd23c61a970d8ac23d4491ed89c5548427..09b5919f371c8b1ffee31f8fc06b62b5739bdd16 100644 (file)
@@ -20,11 +20,13 @@ void ModelAPI_CompositeFeature::exchangeIDs(
 void ModelAPI_CompositeFeature::erase()
 {
   // erase all sub-features
-  for(int a = numberOfSubs(); a > 0; a--) {
-    FeaturePtr aFeature = subFeature(a - 1);
-    if (aFeature.get()) {
-      // subs are referenced from sketch, but must be removed for sure, so not checkings
-      aFeature->document()->removeFeature(aFeature);
+  if (data()->isValid()) {
+    for(int a = numberOfSubs(); a > 0; a--) {
+      FeaturePtr aFeature = subFeature(a - 1);
+      if (aFeature.get()) {
+        // subs are referenced from sketch, but must be removed for sure, so not checkings
+        aFeature->document()->removeFeature(aFeature);
+      }
     }
   }
   ModelAPI_Feature::erase();