X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FEvents%2FEvents_Loop.cpp;h=fda4aadca27f471169fd4bcdc7d1453074826fbc;hb=f96cf18f82e49fcad0d24c1f6ef5ceb7f2cc92ad;hp=eaaf57be809fbd0af2ed9812dd79848bd603ceef;hpb=423c10234142d14d0d5de89383f2f96a4ec5930f;p=modules%2Fshaper.git diff --git a/src/Events/Events_Loop.cpp b/src/Events/Events_Loop.cpp index eaaf57be8..fda4aadca 100644 --- a/src/Events/Events_Loop.cpp +++ b/src/Events/Events_Loop.cpp @@ -1,8 +1,22 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: Events_Loop.hxx -// Created: Thu Mar 13 2014 -// Author: Mikhail PONIKAROV +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// #include #include @@ -10,8 +24,6 @@ #include #include -using namespace std; - Events_Loop* Events_Loop::loop() { // initialized on initialization of the application @@ -22,10 +34,10 @@ Events_Loop* Events_Loop::loop() Events_ID Events_Loop::eventByName(const char* theName) { ///! All events created in this session, uniquely identified by the text and char pointer - static map CREATED_EVENTS; + static std::map CREATED_EVENTS; char* aResult; - string aName(theName); - map::iterator aFound = CREATED_EVENTS.find(aName); + std::string aName(theName); + std::map::iterator aFound = CREATED_EVENTS.find(aName); if (aFound == CREATED_EVENTS.end()) { //not created yet #ifdef WIN32 aResult = _strdup(theName); // copy to make unique internal pointer @@ -42,7 +54,8 @@ Events_ID Events_Loop::eventByName(const char* theName) void Events_Loop::sendProcessEvent(const std::shared_ptr& theMessage, std::list& theListeners, const bool theFlushedNow) { - for (list::iterator aL = theListeners.begin(); aL != theListeners.end(); aL++) { + std::list::iterator aL = theListeners.begin(); + for (; aL != theListeners.end(); aL++) { if (theFlushedNow && (*aL)->groupMessages()) { (*aL)->groupWhileFlush(theMessage); } else { @@ -75,10 +88,10 @@ void Events_Loop::send(const std::shared_ptr& theMessage, bool i } } // send - map > >::iterator aFindID = myListeners.find( - theMessage->eventID().eventText()); + std::map > >::iterator aFindID = + myListeners.find(theMessage->eventID().eventText()); if (aFindID != myListeners.end()) { - map >::iterator aFindSender = aFindID->second.find( + std::map >::iterator aFindSender = aFindID->second.find( theMessage->sender()); if (aFindSender != aFindID->second.end()) { sendProcessEvent(theMessage, aFindSender->second, isFlushedNow && isGroup); @@ -99,21 +112,22 @@ void Events_Loop::registerListener(Events_Listener* theListener, const Events_ID myImmediateListeners[theID.eventText()] = theListener; return; } - map > >::iterator aFindID = myListeners.find( - theID.eventText()); + std::map > >::iterator aFindID = + myListeners.find(theID.eventText()); if (aFindID == myListeners.end()) { // create container associated with ID - myListeners[theID.eventText()] = map >(); + myListeners[theID.eventText()] = std::map >(); aFindID = myListeners.find(theID.eventText()); } - map >::iterator aFindSender = aFindID->second.find(theSender); + std::map >::iterator aFindSender = + aFindID->second.find(theSender); if (aFindSender == aFindID->second.end()) { // create container associated with sender - aFindID->second[theSender] = list(); + aFindID->second[theSender] = std::list(); aFindSender = aFindID->second.find(theSender); } // check that listener was not registered wit hsuch parameters before - list& aListeners = aFindSender->second; - for (list::iterator aL = aListeners.begin(); aL != aListeners.end(); aL++) + std::list& aListeners = aFindSender->second; + for (std::list::iterator aL = aListeners.begin(); aL != aListeners.end(); aL++) if (*aL == theListener) return; // avoid duplicates @@ -171,6 +185,7 @@ void Events_Loop::flush(const Events_ID& theID) { if (!myFlushActive) return; + bool hasEventsToFlush = !myGroups.empty(); std::map >::iterator aMyGroup; for(aMyGroup = myGroups.find(theID.eventText()); aMyGroup != myGroups.end(); aMyGroup = myGroups.find(theID.eventText())) @@ -191,12 +206,13 @@ void Events_Loop::flush(const Events_ID& theID) } } // send accumulated messages to "groupListeners" - map > >::iterator aFindID = myListeners.find( - theID.eventText()); + std::map > >::iterator aFindID = + myListeners.find(theID.eventText()); if (aFindID != myListeners.end()) { - map >::iterator aFindSender = aFindID->second.begin(); + std::map >::iterator aFindSender = + aFindID->second.begin(); for(; aFindSender != aFindID->second.end(); aFindSender++) { - list::iterator aListener = aFindSender->second.begin(); + std::list::iterator aListener = aFindSender->second.begin(); for(; aListener != aFindSender->second.end(); aListener++) { if ((*aListener)->groupMessages()) { (*aListener)->flushGrouped(theID); @@ -205,6 +221,12 @@ void Events_Loop::flush(const Events_ID& theID) } } } + if (hasEventsToFlush && myGroups.empty() && myFlushed.empty()) { + // no more messages left in the queue, so, finalize the sketch processing + static Events_ID anID = Events_Loop::eventByName("SketchPrepared"); + std::shared_ptr aMsg(new Events_Message(anID, this)); + Events_Loop::loop()->send(aMsg, false); + } } void Events_Loop::eraseMessages(const Events_ID& theID) @@ -233,14 +255,6 @@ void Events_Loop::clear(const Events_ID& theID) } } -void Events_Loop::autoFlush(const Events_ID& theID, const bool theAuto) -{ - if (theAuto) - myFlushed.insert(theID.myID); - else - myFlushed.erase(myFlushed.find(theID.myID)); -} - bool Events_Loop::isFlushed(const Events_ID& theID) { return myFlushed.find(theID.myID) != myFlushed.end(); @@ -253,3 +267,8 @@ void Events_Loop::setFlushed(const Events_ID& theID, const bool theValue) else myFlushed.erase(myFlushed.find(theID.myID)); } + +bool Events_Loop::hasGrouppedEvent(const Events_ID& theID) +{ + return myGroups.find(theID.myID) != myGroups.end(); +} \ No newline at end of file