From 04021f882c33f8871faf81e9b71089c3854149e7 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 3 Jul 2014 11:57:08 +0400 Subject: [PATCH] Redisplay feature event processing --- src/XGUI/XGUI_Displayer.cpp | 2 +- src/XGUI/XGUI_Workshop.cpp | 125 +++++++++++++++++++++--------------- src/XGUI/XGUI_Workshop.h | 6 ++ 3 files changed, 80 insertions(+), 53 deletions(-) diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index f93b9502d..fe49f7442 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -188,7 +188,7 @@ void XGUI_Displayer::redisplay(FeaturePtr theFeature, bool isUpdateViewer) if (aShapePtr) { boost::shared_ptr aAISObj = getAISObject(aFeature); Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(aAISObj->impl()); - if (!aAISShape.IsNull()) + if (aAISShape.IsNull()) return; aAISShape->Set(aShapePtr->impl()); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index ee311ff8f..81bb1d0a3 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -120,13 +120,12 @@ void XGUI_Workshop::startApplication() Events_Loop* aLoop = Events_Loop::loop(); aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors. //TODO(sbh): Implement static method to extract event id [SEID] - Events_ID aFeatureId = aLoop->eventByName(EVENT_FEATURE_LOADED); - aLoop->registerListener(this, aFeatureId); - Events_ID aPartSetId = aLoop->eventByName("PartSetModuleEvent"); - aLoop->registerListener(this, aPartSetId); - Events_ID aFeatureUpdatedId = aLoop->eventByName(EVENT_FEATURE_UPDATED); - aLoop->registerListener(this, aFeatureUpdatedId); + aLoop->registerListener(this, aLoop->eventByName(EVENT_FEATURE_LOADED)); + // TODO Is it good to use non standard event within workshop? + aLoop->registerListener(this, aLoop->eventByName("PartSetModuleEvent")); + aLoop->registerListener(this, aLoop->eventByName(EVENT_FEATURE_UPDATED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED)); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_TO_REDISPLAY)); activateModule(); if (myMainWindow) { @@ -222,28 +221,17 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) } return; } + // Process creation of Part if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) { const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); - std::set aFeatures = aUpdMsg->features(); + onFeatureCreatedMsg(aUpdMsg); + } - std::set::const_iterator aIt; - bool aHasPart = false; - for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) { - FeaturePtr aFeature = (*aIt); - if (aFeature->getKind() == PARTSET_PART_KIND) { - aHasPart = true; - //break; - } else { - myDisplayer->display(aFeature, false); - } - } - myDisplayer->updateViewer(); - if (aHasPart) { - //The created part will be created in Object Browser later and we have to activate it - // only when it is created everywere - QTimer::singleShot(50, this, SLOT(activateLastPart())); - } + // Redisplay feature + if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_TO_REDISPLAY)) { + const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); + onFeatureRedisplayMsg(aUpdMsg); } //Update property panel on corresponding message. If there is no current operation (no @@ -252,39 +240,14 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) if (theMessage->eventID() == aFeatureUpdatedId) { const Model_FeatureUpdatedMessage* anUpdateMsg = dynamic_cast(theMessage); - - std::set aFeatures = anUpdateMsg->features(); - if (myOperationMgr->hasOperation()) - { - FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature(); - std::set::const_iterator aIt; - for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) { - FeaturePtr aNewFeature = (*aIt); - if(aNewFeature == aCurrentFeature) { - myPropertyPanel->updateContentWidget(aCurrentFeature); - break; - } - } - } - // Redisplay feature if it is modified - std::set::const_iterator aIt; - for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) { - FeaturePtr aFeature = (*aIt); - if (aFeature->getKind() != PARTSET_PART_KIND) { - if (myDisplayer->isVisible(aFeature)) - myDisplayer->redisplay(aFeature, false); - else - myDisplayer->display(aFeature, false); - } - } - myDisplayer->updateViewer(); + onFeatureUpdatedMsg(anUpdateMsg); } + //An operation passed by message. Start it, process and commit. const Config_PointerMessage* aPartSetMsg = dynamic_cast(theMessage); if (aPartSetMsg) { myPropertyPanel->cleanContent(); - ModuleBase_Operation* anOperation = - (ModuleBase_Operation*)(aPartSetMsg->pointer()); + ModuleBase_Operation* anOperation = (ModuleBase_Operation*)aPartSetMsg->pointer(); if (myOperationMgr->startOperation(anOperation)) { myPropertyPanel->updateContentWidget(anOperation->feature()); @@ -300,9 +263,67 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) if (anAppError) { emit errorOccurred(QString::fromLatin1(anAppError->description())); } +} + +//****************************************************** +void XGUI_Workshop::onFeatureUpdatedMsg(const Model_FeatureUpdatedMessage* theMsg) +{ + std::set aFeatures = theMsg->features(); + if (myOperationMgr->hasOperation()) + { + FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature(); + std::set::const_iterator aIt; + for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) { + FeaturePtr aNewFeature = (*aIt); + if(aNewFeature == aCurrentFeature) { + myPropertyPanel->updateContentWidget(aCurrentFeature); + break; + } + } + } +} +//****************************************************** +void XGUI_Workshop::onFeatureRedisplayMsg(const Model_FeatureUpdatedMessage* theMsg) +{ + std::set aFeatures = theMsg->features(); + std::set::const_iterator aIt; + for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) { + FeaturePtr aFeature = (*aIt); + if (aFeature->getKind() != PARTSET_PART_KIND) { + if (myDisplayer->isVisible(aFeature)) + myDisplayer->redisplay(aFeature, false); + else + myDisplayer->display(aFeature, false); + } + } + myDisplayer->updateViewer(); } +//****************************************************** +void XGUI_Workshop::onFeatureCreatedMsg(const Model_FeatureUpdatedMessage* theMsg) +{ + std::set aFeatures = theMsg->features(); + + std::set::const_iterator aIt; + bool aHasPart = false; + for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) { + FeaturePtr aFeature = (*aIt); + if (aFeature->getKind() == PARTSET_PART_KIND) { + aHasPart = true; + //break; + } else { + myDisplayer->display(aFeature, false); + } + } + myDisplayer->updateViewer(); + if (aHasPart) { + //The created part will be created in Object Browser later and we have to activate it + // only when it is created everywere + QTimer::singleShot(50, this, SLOT(activateLastPart())); + } +} + //****************************************************** void XGUI_Workshop::onOperationStarted() { diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index cb4d64e1d..32a761f82 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -37,6 +37,8 @@ class Config_PointerMessage; class QWidget; class QDockWidget; +class Model_FeatureUpdatedMessage; + /**\class XGUI_Workshop * \ingroup GUI * \brief Class which defines a configuration of the application (Workshop) and launches it. @@ -147,6 +149,10 @@ protected: void connectWithOperation(ModuleBase_Operation* theOperation); void saveDocument(QString theName); + void onFeatureUpdatedMsg(const Model_FeatureUpdatedMessage* theMsg); + void onFeatureCreatedMsg(const Model_FeatureUpdatedMessage* theMsg); + void onFeatureRedisplayMsg(const Model_FeatureUpdatedMessage* theMsg); + protected slots: /// SLOT, that is called after the operation is started. Update workshop state according to /// the started operation, e.g. visualizes the property panel and connect to it. -- 2.39.2