Salome HOME
Make finishing operation in python console produce no warnings: isOperation of root...
authormpv <mikhail.ponikarov@opencascade.com>
Tue, 23 Sep 2014 08:09:02 +0000 (12:09 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Tue, 23 Sep 2014 08:09:02 +0000 (12:09 +0400)
src/Events/Events_Loop.cpp
src/Events/Events_Loop.h
src/Model/Model_Document.cpp
src/Model/Model_Session.cpp
src/XGUI/XGUI_OperationMgr.cpp

index 95e9ea6a9b2fcb350d7e252783475f873debdb61..b13472aee107dc9ade02cf43d3e3686597af9580 100644 (file)
@@ -39,6 +39,9 @@ Events_ID Events_Loop::eventByName(const char* theName)
 
 void Events_Loop::send(const boost::shared_ptr<Events_Message>& theMessage, bool isGroup)
 {
+  if (myImmediateListeners.find(theMessage->eventID().eventText()) != myImmediateListeners.end()) {
+    myImmediateListeners[theMessage->eventID().eventText()]->processEvent(theMessage);
+  }
   // if it is grouped message, just accumulate it
   if (isGroup) {
     boost::shared_ptr<Events_MessageGroup> aGroup = 
@@ -57,7 +60,7 @@ void Events_Loop::send(const boost::shared_ptr<Events_Message>& theMessage, bool
     }
   }
 
-  // TO DO: make it in thread and with usage of semaphores
+  // TODO: make it in thread and with usage of semaphores
 
   map<char*, map<void*, list<Events_Listener*> > >::iterator aFindID = myListeners.find(
       theMessage->eventID().eventText());
@@ -81,8 +84,12 @@ void Events_Loop::send(const boost::shared_ptr<Events_Message>& theMessage, bool
 }
 
 void Events_Loop::registerListener(Events_Listener* theListener, const Events_ID theID,
-                                   void* theSender)
+                                   void* theSender, bool theImmediate)
 {
+  if (theImmediate) { // just register as an immediate
+    myImmediateListeners[theID.eventText()] = theListener;
+    return;
+  }
   map<char*, map<void*, list<Events_Listener*> > >::iterator aFindID = myListeners.find(
       theID.eventText());
   if (aFindID == myListeners.end()) {  // create container associated with ID
index 3a02e16a659c6c4e1a2dcffa4bb948240434ecdd..b02c978c89109fd63c58a546f9bba937ae6559ae 100644 (file)
@@ -28,6 +28,9 @@ class Events_Loop
   /// map from event ID to sender pointer to listeners that must be called for this
   std::map<char*, std::map<void*, std::list<Events_Listener*> > > myListeners;
 
+  /// map from event ID to listeners which must process message without waiting for flush
+  std::map<char*, Events_Listener*> myImmediateListeners;
+
   /// map from event ID to groupped messages (accumulated on flush)
   std::map<char*, boost::shared_ptr<Events_Message> > myGroups;
 
@@ -51,7 +54,7 @@ class Events_Loop
   //! Registers (or adds if such listener is already registered) a listener 
   //! that will be called on the event and from the defined sender
   EVENTS_EXPORT void registerListener(Events_Listener* theListener, const Events_ID theID,
-                                      void* theSender = 0);
+                                      void* theSender = 0, bool theImmediate = false);
 
   //! Initializes sending of a group-message by the given ID
   EVENTS_EXPORT void flush(const Events_ID& theID);
index 08eb944fa8e84d39e687cce872e802912fc61f2a..8b792974cea3f10c2ac8c2efb494ce8231b7ea5c 100644 (file)
@@ -255,8 +255,12 @@ bool Model_Document::compactNested()
 
 void Model_Document::finishOperation()
 {
-  // just to be sure that everybody knows that changes were performed
+  // finish for all subs first: to avoid nested finishing and "isOperation" calls problems inside
+  std::set<std::string>::iterator aSubIter = mySubs.begin();
+  for (; aSubIter != mySubs.end(); aSubIter++)
+    subDoc(*aSubIter)->finishOperation();
 
+  // just to be sure that everybody knows that changes were performed
   if (!myDoc->HasOpenCommand() && myNestedNum != -1)
     boost::static_pointer_cast<Model_Session>(Model_Session::get())
         ->setCheckTransactions(false);  // for nested transaction commit
@@ -282,10 +286,6 @@ void Model_Document::finishOperation()
     myTransactionsAfterSave++;
   }
 
-  // finish for all subs
-  std::set<std::string>::iterator aSubIter = mySubs.begin();
-  for (; aSubIter != mySubs.end(); aSubIter++)
-    subDoc(*aSubIter)->finishOperation();
 }
 
 void Model_Document::abortOperation()
index 51f97e0f717c628408167d9eb638e4798cd07433..e63c97cabb2a1cb06744d8f8d8b5307a0be294c7 100644 (file)
@@ -204,9 +204,9 @@ Model_Session::Model_Session()
   Events_Loop* aLoop = Events_Loop::loop();
   static const Events_ID kFeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent");
   aLoop->registerListener(this, kFeatureEvent);
-  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));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED), 0, true);
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED), 0, true);
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED), 0, true);
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_VALIDATOR_LOADED));
 }
 
index 00cd7df254bdeed0603d4a63d9cdc41a7e6da39d..aa677172b91c507b175f94f58930dde2b4efeeea 100644 (file)
@@ -112,7 +112,7 @@ bool XGUI_OperationMgr::abortAllOperations()
 
 bool XGUI_OperationMgr::validateOperation(ModuleBase_Operation* theOperation)
 {
-  if(!theOperation)
+  if (!theOperation)
     return false;
   //Get operation feature to validate
   FeaturePtr aFeature = theOperation->feature();