-//******************************************************
-void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessage)
-{
- if (QApplication::instance()->thread() != QThread::currentThread()) {
- #ifdef _DEBUG
- std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
- #endif
- SessionPtr aMgr = ModelAPI_Session::get();
- PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(theMessage);
- QApplication::postEvent(this, aPostponeEvent);
- return;
- }
-
- //A message to start feature creation received.
- if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
- std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
- std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
- if (!aFeatureMsg->isInternal()) {
- addFeature(aFeatureMsg);
- }
- }
- // Process creation of Part
- else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
- std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
- std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
- onFeatureCreatedMsg(aUpdMsg);
- if (myUpdatePrefs) {
- if (mySalomeConnector)
- mySalomeConnector->createPreferences();
- myUpdatePrefs = false;
- }
- }
- else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
- myUpdatePrefs = true;
- }
- // Redisplay feature
- else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
- std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
- std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
- onFeatureRedisplayMsg(aUpdMsg);
- }
- //Update property panel on corresponding message. If there is no current operation (no
- //property panel), or received message has different feature to the current - do nothing.
- else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
- std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
- std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
- onFeatureUpdatedMsg(anUpdateMsg);
- } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
- std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
- std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
- onObjectDeletedMsg(aDelMsg);
- } else if (theMessage->eventID() == Events_LongOp::eventID()) {
- if (Events_LongOp::isPerformed()) {
- QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
- } else {
- QApplication::restoreOverrideCursor();
- }
- } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW)) {
- std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
- std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
- const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
- QObjectPtrList aList;
- std::set<ObjectPtr>::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<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
- std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
- const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
- QObjectPtrList aList;
- std::set<ObjectPtr>::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)) {
- std::shared_ptr<Config_PointerMessage> aPartSetMsg =
- std::dynamic_pointer_cast<Config_PointerMessage>(theMessage);
- //myPropertyPanel->cleanContent();
- ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
-
- if (myOperationMgr->startOperation(anOperation)) {
- myPropertyPanel->updateContentWidget(anOperation->feature());
- if (!anOperation->getDescription()->hasXmlRepresentation()) {
- if (anOperation->commit())
- updateCommandStatus();
- }
- }
- } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
- myActionsMgr->update();
- // Find and Activate active part
- if (myPartActivating)
- return;
- SessionPtr aMgr = ModelAPI_Session::get();
- DocumentPtr aActiveDoc = aMgr->activeDocument();
- DocumentPtr aDoc = aMgr->moduleDocument();
- if (aActiveDoc == aDoc) {
- activatePart(ResultPartPtr());
- return;
- }
- std::string aGrpName = ModelAPI_ResultPart::group();
- for (int i = 0; i < aDoc->size(aGrpName); i++) {
- ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
- if (aPart->partDoc() == aActiveDoc) {
- activatePart(aPart); // Activate a part which corresponds to active Doc
- return;
- }
- }
- // If not found then activate global document
- activatePart(ResultPartPtr());
-
- }
- else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) {
- std::shared_ptr<Config_SelectionFilterMessage> aMsg =
- std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
- if (aMsg) {
- ModuleBase_FilterFactory* aFactory = moduleConnector()->selectionFilters();
- if (!aMsg->attributeId().empty()) {
- aFactory->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId(),
- aMsg->parameters());
- }
- }
- } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)) {
- // the viewer's update context will not happens until viewer updated is emitted
- myDisplayer->enableUpdateViewer(false);
- } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)) {
- // the viewer's update context is unblocked, the viewer's update works
- myDisplayer->enableUpdateViewer(true);
- } else {
- //Show error dialog if error message received.
- std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
- if (anAppError) {
- emit errorOccurred(QString::fromLatin1(anAppError->description()));
- }
- return;
- }
- if (!isSalomeMode()) {
- SessionPtr aMgr = ModelAPI_Session::get();
- if (aMgr->isModified() != myMainWindow->isModifiedState())
- myMainWindow->setModifiedState(aMgr->isModified());
- }
-}
-