From eab1d28845bc0f288292661f59c6ac428eabb8ed Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 29 Jan 2019 16:43:58 +0300 Subject: [PATCH] Optimization in the frames of issue #1668 --- src/Model/Model_Events.cpp | 16 ++++++++++++++++ src/Model/Model_Events.h | 6 +++++- src/Model/Model_ResultPart.cpp | 2 ++ src/Model/Model_Update.cpp | 7 +++++-- src/ModelAPI/ModelAPI_Events.h | 10 ++++++---- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/Model/Model_Events.cpp b/src/Model/Model_Events.cpp index e113d3ae7..9b5295da0 100644 --- a/src/Model/Model_Events.cpp +++ b/src/Model/Model_Events.cpp @@ -33,6 +33,22 @@ void Model_EventCreator::sendUpdated(const ObjectPtr& theObject, const Events_ID Events_Loop::loop()->send(aMsg, isGroupped); } +void Model_EventCreator::sendUpdated(const std::list& theObjects, + const Events_ID& theEvent, const bool isGroupped) const +{ + if (theObjects.empty()) + return; + std::list::const_iterator anObj = theObjects.cbegin(); + std::shared_ptr aMsg( + new Model_ObjectUpdatedMessage(*anObj, theEvent)); + for(anObj++; anObj != theObjects.cend(); anObj++) { + std::shared_ptr aJoined( + new Model_ObjectUpdatedMessage(*anObj, theEvent)); + aMsg->Join(aJoined); + } + Events_Loop::loop()->send(aMsg, isGroupped); +} + void Model_EventCreator::sendDeleted(const std::shared_ptr& theDoc, const std::string& theGroup) const { diff --git a/src/Model/Model_Events.h b/src/Model/Model_Events.h index c0ed01254..510a9e9a2 100644 --- a/src/Model/Model_Events.h +++ b/src/Model/Model_Events.h @@ -26,13 +26,17 @@ #include -/// Allovs to create ModelAPI messages +/// Allows to create ModelAPI messages class Model_EventCreator : public ModelAPI_EventCreator { public: /// creates created, updated or moved messages and sends to the loop virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent, const bool isGroupped = true) const; + + /// creates created, updated or moved messages with the objects collection and sends to the loop + virtual void sendUpdated(const std::list& theObjects, const Events_ID& theEvent, + const bool isGroupped = true) const; /// creates deleted message and sends to the loop virtual void sendDeleted(const std::shared_ptr& theDoc, const std::string& theGroup) const; diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index 3c53dc54e..db3cc0b3d 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -66,6 +66,8 @@ std::shared_ptr Model_ResultPart::partDoc() if (myTrsf.get() && baseRef().get()) { // the second condition is due to #2035 return baseRef()->partDoc(); } + if (!data()->isValid()) + return DocumentPtr(); DocumentPtr aRes = data()->document(DOC_REF())->value(); return aRes; } diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 25a6b6e43..fdc61c6e8 100755 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -301,16 +301,19 @@ void Model_Update::processEvent(const std::shared_ptr& theMessag std::dynamic_pointer_cast(theMessage); const std::set& anObjs = aMsg->objects(); std::set::const_iterator anObjIter = anObjs.cbegin(); + std::list aFeatures, aResults; for(; anObjIter != anObjs.cend(); anObjIter++) { if (std::dynamic_pointer_cast((*anObjIter)->document())->executeFeatures()) { if ((*anObjIter)->groupName() == ModelAPI_Feature::group()) { // results creation means enabling, not update - ModelAPI_EventCreator::get()->sendUpdated(*anObjIter, kUpdatedEvent); + aFeatures.push_back(*anObjIter); } else { - ModelAPI_EventCreator::get()->sendUpdated(*anObjIter, kRedisplayEvent); + aResults.push_back(*anObjIter); } } } + ModelAPI_EventCreator::get()->sendUpdated(aFeatures, kUpdatedEvent); + ModelAPI_EventCreator::get()->sendUpdated(aResults, kRedisplayEvent); return; } if (theMessage->eventID() == kUpdatedEvent) { diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index ddef5a2d3..cf8794d80 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -56,7 +56,7 @@ static const char * EVENT_PLUGIN_LOADED = "PluginLoaded"; static const char * EVENT_DOCUMENT_CHANGED = "CurrentDocumentChanged"; /// Event ID that order of objects in group is changed, -/// so, tree must be fully rectreated (movement of feature) +/// so, tree must be fully recreated (movement of feature) static const char * EVENT_ORDER_UPDATED = "OrderUpdated"; /// Event ID that the sketch is prepared and all grouped messages for the solver may be flushed static const char * EVENT_UPDATE_SELECTION = "UpdateSelection"; @@ -142,7 +142,7 @@ public: /// Returns the identifier of the kind of a message virtual const Events_ID messageId() = 0; - /// Appenad to this message the given one. + /// Appends to this message the given one. virtual void Join(const std::shared_ptr& theJoined) = 0; }; @@ -170,6 +170,9 @@ public: /// creates created, updated or moved messages and sends to the loop virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent, const bool isGroupped = true) const = 0; + /// creates created, updated or moved messages with the objects collection and sends to the loop + virtual void sendUpdated(const std::list& theObjects, const Events_ID& theEvent, + const bool isGroupped = true) const = 0; /// creates deleted message and sends to the loop virtual void sendDeleted(const std::shared_ptr& theDoc, const std::string& theGroup) const = 0; @@ -183,7 +186,6 @@ public: static void set(const ModelAPI_EventCreator* theCreator); }; -// TODO(sbh): Move this message into a separate package, like "GuiAPI" /// Contains the state information about the feature: is it enabled or disabled. class ModelAPI_FeatureStateMessage : public Events_Message { @@ -470,7 +472,7 @@ private: int myDOF; }; -/// Message sent when feature or attrubute has been moved. +/// Message sent when feature or attribute has been moved. /// Stores the moving object/attribute, original and new positions of mouse. class ModelAPI_ObjectMovedMessage : public Events_Message { -- 2.39.2