From 76ca7678fd8ced75927feff30ce02eaf8f1e62cc Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 21 May 2015 17:25:46 +0300 Subject: [PATCH] Replace Display/Erase by setDisplayed --- .../InitializationPlugin_Plugin.cpp | 5 +- src/Model/Model_Document.cpp | 1 - src/Model/Model_Update.cpp | 3 +- src/ModelAPI/ModelAPI_Events.h | 4 -- src/PartSet/PartSet_SketcherMgr.cpp | 54 ++++++++++--------- src/XGUI/XGUI_ContextMenuMgr.cpp | 4 +- src/XGUI/XGUI_Workshop.cpp | 36 +++++-------- 7 files changed, 46 insertions(+), 61 deletions(-) diff --git a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp index b2ced2b57..f3ef02d96 100644 --- a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp +++ b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp @@ -55,17 +55,16 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptreventByName(EVENT_OBJECT_TOHIDE); std::list::const_iterator aFIter = aFeatures.begin(); for (; aFIter != aFeatures.cend(); aFIter++) { FeaturePtr aPlane = *aFIter; const std::list >& aResults = aPlane->results(); std::list::const_iterator aRIter = aResults.begin(); for (; aRIter != aResults.cend(); aRIter++) { - ModelAPI_EventCreator::get()->sendUpdated(*aRIter, HIDE_DISP); + (*aRIter)->setDisplayed(false); } } - Events_Loop::loop()->flush(HIDE_DISP); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); // the viewer update should be unblocked in order to avoid the features blinking before they are // hidden diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index e5c87013e..b1477e5c8 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -324,7 +324,6 @@ bool Model_Document::finishOperation() aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); - aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TOHIDE)); aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED)); // this must be here just after everything is finished but before real transaction stop // to avoid messages about modifications outside of the transaction diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 30abf9ddf..7a8e5277b 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -144,8 +144,7 @@ void Model_Update::processOperation(const bool theTotalUpdate) for(int a = aBase->size() - 1; a >= 0; a--) { ResultPtr aSketchRes = aBase->value(a)->context(); if (aSketchRes) { - static Events_ID HIDE_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE); - ModelAPI_EventCreator::get()->sendUpdated(aSketchRes, HIDE_DISP); + aSketchRes->setDisplayed(false); } } } diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index 69153a988..89be2d899 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -36,10 +36,6 @@ static const char * EVENT_OBJECT_TO_REDISPLAY = "ObjectsToRedisplay"; static const char * EVENT_OPERATION_LAUNCHED = "OperationLaunched"; /// Event ID that plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage) static const char * EVENT_PLUGIN_LOADED = "PliginLoaded"; -/// Event ID that data of feature has to be shown (comes with ModelAPI_ObjectUpdatedMessage) -static const char * EVENT_OBJECT_TOSHOW = "ObjectShow"; -/// Event ID that data of feature has to be shown (comes with ModelAPI_ObjectUpdatedMessage) -static const char * EVENT_OBJECT_TOHIDE = "ObjectHide"; // static const char * EVENT_DOCUMENT_CHANGED = "CurrentDocumentChanged"; diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index f3d5bfa32..9394b1a6b 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -677,15 +677,14 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) // Display all sketcher sub-Objects myCurrentSketch = std::dynamic_pointer_cast(theOperation->feature()); XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); - XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); // Hide sketcher result std::list aResults = myCurrentSketch->results(); std::list::const_iterator aIt; for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { - aDisplayer->erase((*aIt), false); + (*aIt)->setDisplayed(false); } - aDisplayer->erase(myCurrentSketch, false); + myCurrentSketch->setDisplayed(false); // Display sketcher objects for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) { @@ -693,9 +692,9 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) std::list aResults = aFeature->results(); std::list::const_iterator aIt; for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { - aDisplayer->display((*aIt), false); + (*aIt)->setDisplayed(true); } - aDisplayer->display(aFeature, false); + aFeature->setDisplayed(true); } if (myPlaneFilter.IsNull()) @@ -707,7 +706,7 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) std::shared_ptr aPln = PartSet_Tools::sketchPlane(myCurrentSketch); myPlaneFilter->setPlane(aPln->impl()); } - aDisplayer->updateViewer(); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); // all sketch objects should be activated in the sketch selection modes by edit operation start if (theOperation->isEditOperation()) activateObjectsInSketchMode(true); @@ -722,10 +721,10 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) activateObjectsInSketchMode(false); XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); - XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); DataPtr aData = myCurrentSketch->data(); if ((!aData) || (!aData->isValid())) { + XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); // The sketch was aborted myCurrentSketch = CompositeFeaturePtr(); myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter); @@ -736,7 +735,7 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) foreach (ObjectPtr aObj, aObjects) { DataPtr aObjData = aObj->data(); if ((!aObjData) || (!aObjData->isValid())) - aDisplayer->erase(aObj); + aObj->setDisplayed(false); } return; } @@ -746,21 +745,21 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) std::list aResults = aFeature->results(); std::list::const_iterator aIt; for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { - aDisplayer->erase((*aIt), false); + (*aIt)->setDisplayed(false); } - aDisplayer->erase(aFeature, false); + aFeature->setDisplayed(false); } // Display sketcher result std::list aResults = myCurrentSketch->results(); std::list::const_iterator aIt; for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { - aDisplayer->display((*aIt), false); + (*aIt)->setDisplayed(true); } - aDisplayer->display(myCurrentSketch); + myCurrentSketch->setDisplayed(true); myCurrentSketch = CompositeFeaturePtr(); myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter); - aDisplayer->updateViewer(); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); } void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation) @@ -810,8 +809,9 @@ bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch // nested features can be visualized FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - if (aFeature.get() != NULL && aFeature == activeSketch()) + if (aFeature.get() != NULL && aFeature == activeSketch()) { aCanDisplay = false; + } } else { // there are no an active sketch // 2. sketch sub-features should not be visualized if the sketch operation is not active @@ -819,8 +819,9 @@ bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const if (aFeature.get() != NULL) { std::shared_ptr aSketchFeature = std::dynamic_pointer_cast(aFeature); - if (aSketchFeature.get()) + if (aSketchFeature.get()) { aCanDisplay = false; + } } } @@ -842,8 +843,10 @@ bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const } } } - if (!isObjectFound) + if (!isObjectFound) { + theObject->setDisplayed(aCanDisplay); // If it be set into True - set to False return aCanDisplay; + } // 4. For created nested feature operation do not display the created feature if // the mouse curstor leaves the OCC window. @@ -866,6 +869,7 @@ bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const } } #endif + theObject->setDisplayed(aCanDisplay); // If it be set into True - set to False return aCanDisplay; } @@ -1061,28 +1065,27 @@ void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation, ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); XGUI_ModuleConnector* aConnector = dynamic_cast(aWorkshop); - XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); // 1. change visibility of the object itself, here the presentable object is processed, // e.g. constraints features FeaturePtr aFeature = theOperation->feature(); std::list aResults = aFeature->results(); if (isToDisplay) - aDisplayer->display(aFeature, false); + aFeature->setDisplayed(true); else - aDisplayer->erase(aFeature, false); + aFeature->setDisplayed(false); // change visibility of the object results, e.g. non-constraint features std::list::const_iterator aIt; for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { if (isToDisplay) { - aDisplayer->display(*aIt, false); + (*aIt)->setDisplayed(true); } else { - aDisplayer->erase(*aIt, false); + (*aIt)->setDisplayed(false); } } - aDisplayer->updateViewer(); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); } void PartSet_SketcherMgr::activateObjectsInSketchMode(const bool isActive) @@ -1152,17 +1155,16 @@ void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn) ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); XGUI_ModuleConnector* aConnector = dynamic_cast(aWorkshop); - XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); const QStringList& aConstrIds = constraintsIdList(); for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) { FeaturePtr aSubFeature = myCurrentSketch->subFeature(i); if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) { if (myIsConstraintsShown) - aDisplayer->display(aSubFeature, false); + aSubFeature->setDisplayed(true); else - aDisplayer->erase(aSubFeature, false); + aSubFeature->setDisplayed(false); } } - aDisplayer->updateViewer(); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); } diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index ff696de22..88f167b96 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -152,7 +152,7 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const ObjectPtr aObject = aObjects.first(); if (aObject) { if (!hasFeature) { - if (aDisplayer->isVisible(aObject)) { + if (aObject->isDisplayed()) { if (aDisplayer->canBeShaded(aObject)) { if (aDisplayer->displayMode(aObject) == XGUI_Displayer::Shading) aMenu->addAction(action("WIREFRAME_CMD")); @@ -228,7 +228,7 @@ void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const foreach(ObjectPtr aObject, aObjects) { ResultPtr aRes = std::dynamic_pointer_cast(aObject); - if (aRes && myWorkshop->displayer()->isVisible(aRes)) { + if (aRes && aRes->isDisplayed()) { isVisible = true; canBeShaded = myWorkshop->displayer()->canBeShaded(aObject); isShading = (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index f1b617d85..9da339e98 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -165,8 +165,6 @@ void XGUI_Workshop::startApplication() aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); aLoop->registerListener(this, Events_LongOp::eventID()); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED)); - aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOSHOW)); - aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOHIDE)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)); @@ -348,24 +346,6 @@ void XGUI_Workshop::processEvent(const std::shared_ptr& theMessa } else { QApplication::restoreOverrideCursor(); } - } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW)) { - std::shared_ptr anUpdateMsg = - std::dynamic_pointer_cast(theMessage); - const std::set& aObjList = anUpdateMsg->objects(); - QObjectPtrList aList; - std::set::const_iterator aIt; - for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt) - aList.append(*aIt); - showObjects(aList, true); - } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE)) { - std::shared_ptr anUpdateMsg = - std::dynamic_pointer_cast(theMessage); - const std::set& aObjList = anUpdateMsg->objects(); - QObjectPtrList aList; - std::set::const_iterator aIt; - for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt) - aList.append(*aIt); - showObjects(aList, false); } //An operation passed by message. Start it, process and commit. else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) { @@ -1253,8 +1233,12 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) setDisplayMode(aObjects, XGUI_Displayer::Shading); else if (theId == "WIREFRAME_CMD") setDisplayMode(aObjects, XGUI_Displayer::Wireframe); - else if (theId == "HIDEALL_CMD") - myDisplayer->eraseAll(); + else if (theId == "HIDEALL_CMD") { + QObjectPtrList aList = myDisplayer->displayedObjects(); + foreach (ObjectPtr aObj, aList) + aObj->setDisplayed(false); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + } } //************************************************************** @@ -1524,7 +1508,13 @@ void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible) //************************************************************** void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList) { - myDisplayer->showOnly(theList); + QObjectPtrList aList = myDisplayer->displayedObjects(); + foreach (ObjectPtr aObj, aList) + aObj->setDisplayed(false); + foreach (ObjectPtr aObj, theList) + aObj->setDisplayed(true); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + } -- 2.39.2