1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 //#include "XGUI_Constants.h"
4 #include "XGUI_Tools.h"
5 #include "XGUI_Workshop.h"
6 #include "XGUI_SelectionMgr.h"
7 #include "XGUI_Selection.h"
8 #include "XGUI_ObjectsBrowser.h"
9 #include "XGUI_Displayer.h"
10 #include "XGUI_OperationMgr.h"
11 #include "XGUI_SalomeConnector.h"
12 #include "XGUI_ActionsMgr.h"
13 #include "XGUI_ErrorDialog.h"
14 #include "XGUI_ViewerProxy.h"
15 #include "XGUI_PropertyPanel.h"
16 #include "XGUI_ContextMenuMgr.h"
17 #include "XGUI_ModuleConnector.h"
18 #include <XGUI_QtEvents.h>
19 #include <XGUI_HistoryMenu.h>
21 #include <AppElements_Workbench.h>
22 #include <AppElements_Viewer.h>
23 #include <AppElements_Command.h>
24 #include <AppElements_MainMenu.h>
25 #include <AppElements_MainWindow.h>
26 #include <AppElements_MenuGroupPanel.h>
27 #include <AppElements_Button.h>
29 #include <ModuleBase_IModule.h>
30 #include <ModuleBase_Preferences.h>
32 #include <ModelAPI_Events.h>
33 #include <ModelAPI_Session.h>
34 #include <ModelAPI_Feature.h>
35 #include <ModelAPI_Data.h>
36 #include <ModelAPI_AttributeDocRef.h>
37 #include <ModelAPI_Object.h>
38 #include <ModelAPI_Validator.h>
39 #include <ModelAPI_ResultGroup.h>
40 #include <ModelAPI_ResultConstruction.h>
41 #include <ModelAPI_ResultBody.h>
42 #include <ModelAPI_AttributeIntArray.h>
44 //#include <PartSetPlugin_Part.h>
46 #include <Events_Loop.h>
47 #include <Events_Error.h>
48 #include <Events_LongOp.h>
50 #include <ModuleBase_Operation.h>
51 #include <ModuleBase_Operation.h>
52 #include <ModuleBase_OperationDescription.h>
53 #include <ModuleBase_SelectionValidator.h>
54 #include <ModuleBase_WidgetFactory.h>
55 #include <ModuleBase_Tools.h>
56 #include <ModuleBase_IViewer.h>
57 #include<ModuleBase_FilterFactory.h>
58 #include <ModuleBase_PageBase.h>
60 #include <Config_Common.h>
61 #include <Config_FeatureMessage.h>
62 #include <Config_PointerMessage.h>
63 #include <Config_ModuleReader.h>
64 #include <Config_PropManager.h>
65 #include <Config_SelectionFilterMessage.h>
67 #include <QApplication>
68 #include <QFileDialog>
69 #include <QMessageBox>
70 #include <QMdiSubWindow>
71 #include <QPushButton>
72 #include <QDockWidget>
77 #include <QToolButton>
80 #include <QDialogButtonBox>
81 #include <QHBoxLayout>
82 #include <QtxColorButton.h>
95 QMap<QString, QString> XGUI_Workshop::myIcons;
98 QIcon XGUI_Workshop::featureIcon(const FeaturePtr& theFeature)
102 std::string aKind = theFeature->getKind();
103 QString aId(aKind.c_str());
104 if (!myIcons.contains(aId))
107 QString anIconString = myIcons[aId];
109 ModelAPI_ExecState aState = theFeature->data()->execState();
111 case ModelAPI_StateDone:
112 case ModelAPI_StateNothing: {
113 anIcon = QIcon(anIconString);
116 case ModelAPI_StateMustBeUpdated: {
117 anIcon = ModuleBase_Tools::lighter(anIconString);
120 case ModelAPI_StateExecFailed: {
121 anIcon = ModuleBase_Tools::composite(":pictures/exec_state_failed.png", anIconString);
124 case ModelAPI_StateInvalidArgument: {
125 anIcon = ModuleBase_Tools::composite(":pictures/exec_state_invalid_parameters.png",
134 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
136 myCurrentDir(QString()),
138 mySalomeConnector(theConnector),
142 myUpdatePrefs(false),
143 myPartActivating(false)
145 myMainWindow = mySalomeConnector ? 0 : new AppElements_MainWindow();
147 myDisplayer = new XGUI_Displayer(this);
149 mySelector = new XGUI_SelectionMgr(this);
150 //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
152 myOperationMgr = new XGUI_OperationMgr(this);
153 myActionsMgr = new XGUI_ActionsMgr(this);
154 myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
155 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
156 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
157 SLOT(onContextMenuCommand(const QString&, bool)));
159 myViewerProxy = new XGUI_ViewerProxy(this);
160 connect(myViewerProxy, SIGNAL(selectionChanged()),
161 myActionsMgr, SLOT(updateOnViewSelection()));
163 myModuleConnector = new XGUI_ModuleConnector(this);
165 connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
166 SLOT(onOperationStarted(ModuleBase_Operation*)));
167 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
168 SLOT(onOperationResumed(ModuleBase_Operation*)));
169 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
170 SLOT(onOperationStopped(ModuleBase_Operation*)));
171 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
172 SLOT(onOperationCommitted(ModuleBase_Operation*)));
173 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
174 SLOT(onOperationAborted(ModuleBase_Operation*)));
175 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
176 connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
179 //******************************************************
180 XGUI_Workshop::~XGUI_Workshop(void)
185 //******************************************************
186 void XGUI_Workshop::startApplication()
190 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
191 Config_Prop::Directory, "");
193 //Initialize event listening
194 Events_Loop* aLoop = Events_Loop::loop();
195 aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
196 aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
197 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
198 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
199 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
200 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
201 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
202 aLoop->registerListener(this, Events_LongOp::eventID());
203 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
204 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
205 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOSHOW));
206 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
207 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED));
209 registerValidators();
211 // Calling of loadCustomProps before activating module is required
212 // by Config_PropManger to restore user-defined path to plugins
213 ModuleBase_Preferences::loadCustomProps();
216 myMainWindow->show();
217 updateCommandStatus();
222 emit applicationStarted();
225 //******************************************************
226 void XGUI_Workshop::initMenu()
228 myContextMenuMgr->createActions();
230 if (isSalomeMode()) {
231 // Create only Undo, Redo commands
232 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
233 tr("Undo last command"),
234 QIcon(":pictures/undo.png"),
235 QKeySequence::Undo, false, "MEN_DESK_EDIT");
236 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
237 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
239 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
240 QIcon(":pictures/redo.png"), QKeySequence::Redo,
241 false, "MEN_DESK_EDIT");
242 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
243 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
245 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
246 aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
247 QIcon(":pictures/rebuild.png"), QKeySequence(),
248 false, "MEN_DESK_EDIT");
249 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
250 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
252 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export NewGeom..."), tr("Export the current document into a NewGeom file"),
253 QIcon(), QKeySequence(),
254 false, "MEN_DESK_FILE");
255 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
257 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import NewGeom..."), tr("Import a NewGeom file"),
258 QIcon(), QKeySequence(),
259 false, "MEN_DESK_FILE");
260 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
261 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
265 // File commands group
266 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
268 AppElements_Command* aCommand;
270 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
271 QIcon(":pictures/save.png"), QKeySequence::Save);
272 aCommand->connectTo(this, SLOT(onSave()));
273 //aCommand->disable();
275 QString aUndoId = "UNDO_CMD";
276 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
277 QIcon(":pictures/undo.png"), QKeySequence::Undo);
278 aCommand->connectTo(this, SLOT(onUndo()));
279 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
280 addHistoryMenu(aUndoButton,
281 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
284 QString aRedoId = "REDO_CMD";
285 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
286 QIcon(":pictures/redo.png"), QKeySequence::Redo);
287 aCommand->connectTo(this, SLOT(onRedo()));
288 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
289 addHistoryMenu(aRedoButton,
290 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
293 aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
294 QIcon(":pictures/rebuild.png"), QKeySequence());
295 aCommand->connectTo(this, SLOT(onRebuild()));
297 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
298 QIcon(":pictures/save.png"), QKeySequence());
299 aCommand->connectTo(this, SLOT(onSaveAs()));
300 //aCommand->disable();
302 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
303 QIcon(":pictures/open.png"), QKeySequence::Open);
304 aCommand->connectTo(this, SLOT(onOpen()));
306 //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
307 // QIcon(":pictures/new.png"), QKeySequence::New);
308 //aCommand->connectTo(this, SLOT(onNew()));
310 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
311 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
312 aCommand->connectTo(this, SLOT(onPreferences()));
314 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
315 QIcon(":pictures/close.png"), QKeySequence::Close);
316 aCommand->connectTo(this, SLOT(onExit()));
317 //FIXME: SBH's test action. Can be used for some GUI tests.
319 // aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
320 // QIcon(":pictures/close.png"), QKeySequence(), true);
321 // aCommand->connectTo(myMainWindow, SLOT(dockPythonConsole()));
325 //******************************************************
326 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
328 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
329 return aMenuBar->addWorkbench(theName);
332 //******************************************************
333 void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessage)
335 if (QApplication::instance()->thread() != QThread::currentThread()) {
337 std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
339 SessionPtr aMgr = ModelAPI_Session::get();
340 PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(theMessage);
341 QApplication::postEvent(this, aPostponeEvent);
345 //A message to start feature creation received.
346 if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
347 std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
348 std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
349 if (!aFeatureMsg->isInternal()) {
350 addFeature(aFeatureMsg);
353 // Process creation of Part
354 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
355 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
356 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
357 onFeatureCreatedMsg(aUpdMsg);
359 if (mySalomeConnector)
360 mySalomeConnector->createPreferences();
361 myUpdatePrefs = false;
364 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
365 myUpdatePrefs = true;
368 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
369 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
370 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
371 onFeatureRedisplayMsg(aUpdMsg);
373 //Update property panel on corresponding message. If there is no current operation (no
374 //property panel), or received message has different feature to the current - do nothing.
375 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
376 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
377 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
378 onFeatureUpdatedMsg(anUpdateMsg);
379 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
380 std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
381 std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
382 onObjectDeletedMsg(aDelMsg);
383 } else if (theMessage->eventID() == Events_LongOp::eventID()) {
384 if (Events_LongOp::isPerformed()) {
385 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
387 QApplication::restoreOverrideCursor();
389 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW)) {
390 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
391 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
392 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
393 QObjectPtrList aList;
394 std::set<ObjectPtr>::const_iterator aIt;
395 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
397 showObjects(aList, true);
398 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE)) {
399 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
400 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
401 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
402 QObjectPtrList aList;
403 std::set<ObjectPtr>::const_iterator aIt;
404 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
406 showObjects(aList, false);
408 //An operation passed by message. Start it, process and commit.
409 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
410 std::shared_ptr<Config_PointerMessage> aPartSetMsg =
411 std::dynamic_pointer_cast<Config_PointerMessage>(theMessage);
412 //myPropertyPanel->cleanContent();
413 ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
415 if (myOperationMgr->startOperation(anOperation)) {
416 myPropertyPanel->updateContentWidget(anOperation->feature());
417 if (!anOperation->getDescription()->hasXmlRepresentation()) {
418 if (anOperation->commit())
419 updateCommandStatus();
422 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
423 myActionsMgr->update();
424 // Find and Activate active part
425 if (myPartActivating)
427 SessionPtr aMgr = ModelAPI_Session::get();
428 DocumentPtr aActiveDoc = aMgr->activeDocument();
429 DocumentPtr aDoc = aMgr->moduleDocument();
430 if (aActiveDoc == aDoc) {
431 activatePart(ResultPartPtr());
434 std::string aGrpName = ModelAPI_ResultPart::group();
435 for (int i = 0; i < aDoc->size(aGrpName); i++) {
436 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
437 if (aPart->partDoc() == aActiveDoc) {
438 activatePart(aPart); // Activate a part which corresponds to active Doc
442 // If not found then activate global document
443 activatePart(ResultPartPtr());
446 else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) {
447 std::shared_ptr<Config_SelectionFilterMessage> aMsg =
448 std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
450 ModuleBase_FilterFactory* aFactory = moduleConnector()->selectionFilters();
451 if (!aMsg->attributeId().empty()) {
452 aFactory->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId(),
457 //Show error dialog if error message received.
458 std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
460 emit errorOccurred(QString::fromLatin1(anAppError->description()));
464 if (!isSalomeMode()) {
465 SessionPtr aMgr = ModelAPI_Session::get();
466 if (aMgr->isModified() != myMainWindow->isModifiedState())
467 myMainWindow->setModifiedState(aMgr->isModified());
471 //******************************************************
472 QMainWindow* XGUI_Workshop::desktop() const
474 return isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
477 //******************************************************
478 void XGUI_Workshop::onStartWaiting()
480 if (Events_LongOp::isPerformed()) {
481 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
485 //******************************************************
486 void XGUI_Workshop::onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
488 std::set<ObjectPtr> aFeatures = theMsg->objects();
489 if (myOperationMgr->hasOperation()) {
490 FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
491 std::set<ObjectPtr>::const_iterator aIt;
492 for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
493 ObjectPtr aNewFeature = (*aIt);
494 if (aNewFeature == aCurrentFeature) {
495 myPropertyPanel->updateContentWidget(aCurrentFeature);
500 myOperationMgr->onValidateOperation();
502 myObjectBrowser->processEvent(theMsg);
505 //******************************************************
506 void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
508 std::set<ObjectPtr> aObjects = theMsg->objects();
509 std::set<ObjectPtr>::const_iterator aIt;
510 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
511 ObjectPtr aObj = (*aIt);
513 bool aHide = !aObj->data() || !aObj->data()->isValid();
514 if (!aHide) { // check that this is not hidden result
515 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
516 aHide = aRes && aRes->isConcealed();
519 myDisplayer->erase(aObj, false);
521 if (myDisplayer->isVisible(aObj)) {
522 displayObject(aObj); // In order to update presentation
523 if (myOperationMgr->hasOperation()) {
524 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
525 if (!aOperation->isEditOperation() &&
526 aOperation->hasObject(aObj) && myDisplayer->isActive(aObj))
527 myDisplayer->deactivate(aObj);
530 if (myOperationMgr->hasOperation()) {
531 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
532 if (myModule->canDisplayObject(aObj)) {
534 // Deactivate object of current operation from selection
535 if (myDisplayer->isActive(aObj))
536 myDisplayer->deactivate(aObj);
542 myDisplayer->updateViewer();
545 //******************************************************
546 void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
548 std::set<ObjectPtr> aObjects = theMsg->objects();
550 std::set<ObjectPtr>::const_iterator aIt;
551 bool aHasPart = false;
552 bool isDisplayed = false;
553 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
555 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
558 // If a feature is created from the aplication's python console
559 // it doesn't stored in the operation mgr and doesn't displayed
560 } else if (myModule->canDisplayObject(*aIt)) {
566 myObjectBrowser->processEvent(theMsg);
568 myDisplayer->updateViewer();
569 //if (aHasPart) { // TODO: Avoid activate last part on loading of document
570 // activateLastPart();
574 //******************************************************
575 void XGUI_Workshop::onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg)
578 myObjectBrowser->processEvent(theMsg);
579 //std::set<ObjectPtr> aFeatures = theMsg->objects();
582 //******************************************************
583 void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
585 setNestedFeatures(theOperation);
587 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
588 connectWithOperation(theOperation);
589 setPropertyPanel(theOperation);
591 updateCommandStatus();
593 myModule->operationStarted(theOperation);
596 //******************************************************
597 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
599 setNestedFeatures(theOperation);
601 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
602 // connectWithOperation(theOperation); already connected
603 setPropertyPanel(theOperation);
605 updateCommandStatus();
607 myModule->operationResumed(theOperation);
611 //******************************************************
612 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
614 ModuleBase_ISelection* aSel = mySelector->selection();
615 QObjectPtrList aObj = aSel->selectedPresentations();
616 //!< No need for property panel
617 updateCommandStatus();
619 myPropertyPanel->cleanContent();
621 // Activate objects created by current operation
622 // in order to clean selection modes
624 myDisplayer->activateObjects(aModes);
625 myModule->operationStopped(theOperation);
629 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
631 myModule->operationCommitted(theOperation);
634 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
636 myModule->operationAborted(theOperation);
639 void XGUI_Workshop::setNestedFeatures(ModuleBase_Operation* theOperation)
641 if (this->isSalomeMode())
642 theOperation->setNestedFeatures(mySalomeConnector->nestedActions(theOperation->id()));
644 theOperation->setNestedFeatures(myActionsMgr->nestedCommands(theOperation->id()));
647 void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
650 QString aXmlRepr = theOperation->getDescription()->xmlRepresentation();
651 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
654 myPropertyPanel->cleanContent();
655 aFactory.createWidget(myPropertyPanel->contentWidget());
657 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
658 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
659 bool isStoreValue = !theOperation->isEditOperation() &&
660 !aWidget->getDefaultValue().empty() &&
661 !aWidget->isComputedDefault();
662 aWidget->setFeature(theOperation->feature(), isStoreValue);
663 aWidget->enableFocusProcessing();
666 myPropertyPanel->setModelWidgets(aWidgets);
667 theOperation->setPropertyPanel(myPropertyPanel);
669 myModule->propertyPanelDefined(theOperation);
671 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
674 bool XGUI_Workshop::event(QEvent * theEvent)
676 PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
678 std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
679 processEvent(aEventPtr);
688 void XGUI_Workshop::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
692 qDebug() << "XGUI_Workshop::addFeature: NULL message.";
696 ActionInfo aFeatureInfo;
697 aFeatureInfo.initFrom(theMessage);
698 // Remember features icons
699 myIcons[QString::fromStdString(theMessage->id())] = aFeatureInfo.iconFile;
701 QString aWchName = QString::fromStdString(theMessage->workbenchId());
702 QStringList aNestedFeatures =
703 QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
704 QString aDocKind = QString::fromStdString(theMessage->documentKind());
705 if (isSalomeMode()) {
706 QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureInfo);
707 salomeConnector()->setNestedActions(aFeatureInfo.id, aNestedFeatures);
708 salomeConnector()->setDocumentKind(aFeatureInfo.id, aDocKind);
710 myActionsMgr->addCommand(aAction);
711 myModule->actionCreated(aAction);
713 //Find or create Workbench
714 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
715 AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
717 aPage = addWorkbench(aWchName);
719 //Find or create Group
720 QString aGroupName = QString::fromStdString(theMessage->groupId());
721 AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
723 aGroup = aPage->addGroup(aGroupName);
725 // Check if hotkey sequence is already defined:
726 QKeySequence aHotKey = myActionsMgr->registerShortcut(aFeatureInfo.shortcut);
727 if(aHotKey != aFeatureInfo.shortcut) {
728 aFeatureInfo.shortcut = aHotKey;
731 AppElements_Command* aCommand = aGroup->addFeature(aFeatureInfo,
734 // Enrich created button with accept/abort buttons if necessary
735 AppElements_Button* aButton = aCommand->button();
736 if (aButton->isColumnButton()) {
737 QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
738 QList<QAction*> anActList;
739 if (aNestedActions.contains("accept")) {
740 QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, aButton);
741 connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(commitAllOperations()));
742 anActList << anAction;
744 if (aNestedActions.contains("abort")) {
745 QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, aButton);
746 connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(abortAllOperations()));
747 anActList << anAction;
749 aButton->setAdditionalButtons(anActList);
751 myActionsMgr->addCommand(aCommand);
752 myModule->actionCreated(aCommand);
757 * Makes a signal/slot connections between Property Panel
758 * and given operation. The given operation becomes a
759 * current operation and previous operation if exists
761 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
763 QAction* aCommand = 0;
764 if (isSalomeMode()) {
765 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
767 AppElements_MainMenu* aMenu = myMainWindow->menuObject();
768 FeaturePtr aFeature = theOperation->feature();
770 aCommand = aMenu->feature(QString::fromStdString(aFeature->getKind()));
772 //Abort operation on uncheck the command
774 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
779 * Saves document with given name.
781 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
783 QApplication::restoreOverrideCursor();
784 SessionPtr aMgr = ModelAPI_Session::get();
785 aMgr->save(theName.toLatin1().constData(), theFileNames);
786 QApplication::restoreOverrideCursor();
789 bool XGUI_Workshop::isActiveOperationAborted()
791 return myOperationMgr->abortAllOperations();
794 //******************************************************
795 void XGUI_Workshop::onExit()
797 SessionPtr aMgr = ModelAPI_Session::get();
798 if (aMgr->isModified()) {
799 int anAnswer = QMessageBox::question(
800 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
801 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
802 if (anAnswer == QMessageBox::Save) {
803 bool saved = onSave();
807 } else if (anAnswer == QMessageBox::Cancel) {
814 //******************************************************
815 void XGUI_Workshop::onNew()
817 QApplication::setOverrideCursor(Qt::WaitCursor);
818 if (objectBrowser() == 0) {
820 mySelector->connectViewers();
822 myViewerProxy->connectToViewer();
824 if (!isSalomeMode()) {
825 myMainWindow->showPythonConsole();
826 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
827 aWnd->showMaximized();
828 updateCommandStatus();
830 myContextMenuMgr->connectViewer();
831 QApplication::restoreOverrideCursor();
834 //******************************************************
835 void XGUI_Workshop::onOpen()
837 if(!isActiveOperationAborted())
839 //save current file before close if modified
840 SessionPtr aSession = ModelAPI_Session::get();
841 if (aSession->isModified()) {
842 //TODO(sbh): re-launch the app?
843 int anAnswer = QMessageBox::question(
844 myMainWindow, tr("Save current file"),
845 tr("The document is modified, save before opening another?"),
846 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
847 if (anAnswer == QMessageBox::Save) {
849 } else if (anAnswer == QMessageBox::Cancel) {
852 aSession->closeAll();
856 //show file dialog, check if readable and open
857 myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
858 if (myCurrentDir.isEmpty())
860 QFileInfo aFileInfo(myCurrentDir);
861 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
862 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
866 QApplication::setOverrideCursor(Qt::WaitCursor);
867 aSession->load(myCurrentDir.toLatin1().constData());
868 myObjectBrowser->rebuildDataTree();
870 updateCommandStatus();
871 QApplication::restoreOverrideCursor();
874 //******************************************************
875 bool XGUI_Workshop::onSave()
877 if(!isActiveOperationAborted())
879 if (myCurrentDir.isEmpty()) {
882 std::list<std::string> aFiles;
883 saveDocument(myCurrentDir, aFiles);
884 updateCommandStatus();
886 myMainWindow->setModifiedState(false);
890 //******************************************************
891 bool XGUI_Workshop::onSaveAs()
893 if(!isActiveOperationAborted())
895 QFileDialog dialog(mainWindow());
896 dialog.setWindowTitle(tr("Select directory to save files..."));
897 dialog.setFileMode(QFileDialog::Directory);
898 dialog.setFilter(tr("Folders (*)"));
899 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
900 dialog.setViewMode(QFileDialog::Detail);
902 if (!dialog.exec()) {
905 QString aTempDir = dialog.selectedFiles().first();
907 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
908 int answer = QMessageBox::question(
910 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
912 tr("The folder already contains some files, save anyway?"),
913 QMessageBox::Save | QMessageBox::Cancel);
914 if (answer == QMessageBox::Cancel) {
918 myCurrentDir = aTempDir;
919 if (!isSalomeMode()) {
920 myMainWindow->setCurrentDir(myCurrentDir, false);
921 myMainWindow->setModifiedState(false);
926 //******************************************************
927 void XGUI_Workshop::onUndo(int theTimes)
929 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
930 SessionPtr aMgr = ModelAPI_Session::get();
931 if (aMgr->isOperation())
932 operationMgr()->onAbortOperation();
933 for (int i = 0; i < theTimes; ++i) {
936 updateCommandStatus();
939 //******************************************************
940 void XGUI_Workshop::onRedo(int theTimes)
942 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
943 SessionPtr aMgr = ModelAPI_Session::get();
944 if (aMgr->isOperation())
945 operationMgr()->onAbortOperation();
946 for (int i = 0; i < theTimes; ++i) {
949 updateCommandStatus();
952 //******************************************************
953 void XGUI_Workshop::onRebuild()
955 SessionPtr aMgr = ModelAPI_Session::get();
956 bool aWasOperation = aMgr->isOperation(); // keep this value
957 if (!aWasOperation) {
958 aMgr->startOperation("Rebuild");
960 static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
961 Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
962 new Events_Message(aRebuildEvent, this)));
963 if (!aWasOperation) {
964 aMgr->finishOperation();
968 //******************************************************
969 void XGUI_Workshop::onPreferences()
971 ModuleBase_Prefs aModif;
972 ModuleBase_Preferences::editPreferences(aModif);
973 if (aModif.size() > 0) {
975 foreach (ModuleBase_Pref aPref, aModif)
977 aSection = aPref.first;
978 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
980 myMainWindow->viewer()->updateFromResources();
981 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
983 myMainWindow->menuObject()->updateFromResources();
989 //******************************************************
990 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
992 QString libName = QString::fromStdString(library(theModule.toStdString()));
993 if (libName.isEmpty()) {
994 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
999 CREATE_FUNC crtInst = 0;
1002 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
1006 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1007 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1008 QString aMsg((char*) &lpMsgBuf);
1009 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1010 ::LocalFree(lpMsgBuf);
1012 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1016 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1017 | FORMAT_MESSAGE_IGNORE_INSERTS,
1018 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1019 QString aMsg((char*) &lpMsgBuf);
1020 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1021 ::LocalFree(lpMsgBuf);
1025 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1027 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1029 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1031 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1036 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1038 if (!err.isEmpty()) {
1040 Events_Error::send(err.toStdString());
1042 qWarning(qPrintable(err));
1048 //******************************************************
1049 bool XGUI_Workshop::activateModule()
1051 Config_ModuleReader aModuleReader;
1052 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1053 myModule = loadModule(moduleName);
1057 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1058 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1059 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1060 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1062 myModule->createFeatures();
1063 myActionsMgr->update();
1067 //******************************************************
1068 void XGUI_Workshop::updateCommandStatus()
1070 QList<QAction*> aCommands;
1071 if (isSalomeMode()) { // update commands in SALOME mode
1072 aCommands = salomeConnector()->commandList();
1074 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1075 foreach (AppElements_Command* aCmd, aMenuBar->features())
1076 aCommands.append(aCmd);
1078 SessionPtr aMgr = ModelAPI_Session::get();
1079 if (aMgr->hasModuleDocument()) {
1080 QAction *aUndoCmd, *aRedoCmd;
1081 foreach(QAction* aCmd, aCommands) {
1082 QString aId = aCmd->data().toString();
1083 if (aId == "UNDO_CMD")
1085 else if (aId == "REDO_CMD")
1088 // Enable all commands
1089 aCmd->setEnabled(true);
1092 aUndoCmd->setEnabled(myModule->canUndo());
1093 aRedoCmd->setEnabled(myModule->canRedo());
1096 foreach(QAction* aCmd, aCommands) {
1097 QString aId = aCmd->data().toString();
1098 if (aId == "NEW_CMD")
1099 aCmd->setEnabled(true);
1100 else if (aId == "EXIT_CMD")
1101 aCmd->setEnabled(true);
1103 aCmd->setEnabled(false);
1106 myActionsMgr->update();
1107 emit commandStatusUpdated();
1110 void XGUI_Workshop::updateHistory()
1112 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1113 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1114 emit updateUndoHistory(aUndoRes);
1116 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1117 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1118 emit updateRedoHistory(aRedoRes);
1121 //******************************************************
1122 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1124 QDockWidget* aObjDock = new QDockWidget(theParent);
1125 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1126 aObjDock->setWindowTitle(tr("Object browser"));
1127 aObjDock->setStyleSheet(
1128 "::title { position: relative; padding-left: 5px; text-align: left center }");
1129 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1130 connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this,
1131 SLOT(changeCurrentDocument(ObjectPtr)));
1132 aObjDock->setWidget(myObjectBrowser);
1134 myContextMenuMgr->connectObjectBrowser();
1138 //******************************************************
1140 * Creates dock widgets, places them in corresponding area
1141 * and tabifies if necessary.
1143 void XGUI_Workshop::createDockWidgets()
1145 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1146 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1147 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1148 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
1149 myPropertyPanel->setupActions(myActionsMgr);
1150 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1151 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1152 hidePropertyPanel(); ///<! Invisible by default
1153 hideObjectBrowser();
1154 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1155 myPropertyPanel->installEventFilter(myOperationMgr);
1157 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1158 connect(aOkAct, SIGNAL(triggered()), myOperationMgr, SLOT(onCommitOperation()));
1159 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1160 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1161 connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets()));
1162 connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)),
1163 myOperationMgr, SLOT(onKeyReleased(QKeyEvent*)));
1164 connect(myOperationMgr, SIGNAL(validationStateChanged(bool)),
1165 aOkAct, SLOT(setEnabled(bool)));
1166 QAction* aAcceptAllAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll);
1167 connect(myOperationMgr, SIGNAL(nestedStateChanged(bool)),
1168 aAcceptAllAct, SLOT(setEnabled(bool)));
1172 //******************************************************
1173 void XGUI_Workshop::showPropertyPanel()
1175 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1176 ///<! Restore ability to close panel from the window's menu
1177 aViewAct->setEnabled(true);
1178 myPropertyPanel->show();
1179 myPropertyPanel->raise();
1182 //******************************************************
1183 void XGUI_Workshop::hidePropertyPanel()
1185 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1186 ///<! Do not allow to show empty property panel
1187 aViewAct->setEnabled(false);
1188 myPropertyPanel->hide();
1191 //******************************************************
1192 void XGUI_Workshop::showObjectBrowser()
1194 myObjectBrowser->parentWidget()->show();
1197 //******************************************************
1198 void XGUI_Workshop::hideObjectBrowser()
1200 myObjectBrowser->parentWidget()->hide();
1203 //******************************************************
1204 void XGUI_Workshop::onFeatureTriggered()
1206 QAction* aCmd = dynamic_cast<QAction*>(sender());
1208 QString aId = salomeConnector()->commandId(aCmd);
1210 myModule->launchOperation(aId);
1214 //******************************************************
1215 void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
1217 SessionPtr aMgr = ModelAPI_Session::get();
1219 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theObj);
1221 DocumentPtr aPartDoc = aPart->partDoc();
1223 aMgr->setActiveDocument(aPartDoc);
1228 aMgr->setActiveDocument(aMgr->moduleDocument());
1231 //******************************************************
1232 void XGUI_Workshop::salomeViewerSelectionChanged()
1234 emit salomeViewerSelection();
1237 //**************************************************************
1238 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1240 return mySalomeConnector->viewer();
1243 //**************************************************************
1244 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1246 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1247 if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) {
1248 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
1249 activatePart(aPart);
1250 } else if (theId == "DEACTIVATE_PART_CMD")
1251 activatePart(ResultPartPtr());
1252 else if (theId == "DELETE_CMD")
1253 deleteObjects(aObjects);
1254 else if (theId == "COLOR_CMD")
1255 changeColor(aObjects);
1256 else if (theId == "SHOW_CMD")
1257 showObjects(aObjects, true);
1258 else if (theId == "HIDE_CMD")
1259 showObjects(aObjects, false);
1260 else if (theId == "SHOW_ONLY_CMD")
1261 showOnlyObjects(aObjects);
1262 else if (theId == "SHADING_CMD")
1263 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1264 else if (theId == "WIREFRAME_CMD")
1265 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1266 else if (theId == "HIDEALL_CMD")
1267 myDisplayer->eraseAll();
1268 else if (theId == "EDIT_CMD") {
1269 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObjects.first());
1271 myModule->editFeature(aFeature);
1275 //**************************************************************
1276 void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
1278 if (!myPartActivating) {
1279 myPartActivating = true;
1281 theFeature->activate();
1282 changeCurrentDocument(theFeature);
1283 myObjectBrowser->activatePart(theFeature);
1284 myPartActivating = false;
1286 updateCommandStatus();
1289 //**************************************************************
1290 //void XGUI_Workshop::activateLastPart()
1292 // SessionPtr aMgr = ModelAPI_Session::get();
1293 // DocumentPtr aDoc = aMgr->moduleDocument();
1294 // std::string aGrpName = ModelAPI_ResultPart::group();
1295 // ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
1296 // ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
1298 // activatePart(aPart);
1302 //**************************************************************
1303 void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList)
1305 ModuleBase_IModule* aModule = module();
1306 if (aModule->deleteObjects())
1309 if (!isActiveOperationAborted())
1312 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1313 std::set<FeaturePtr> aRefFeatures;
1314 foreach (ObjectPtr aObj, theList)
1316 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1318 // TODO: check for what there is this condition. It is placed here historicaly because
1319 // ther is this condition during remove features.
1321 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1322 if (aFeature.get() != NULL) {
1323 aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
1328 if (!aRefFeatures.empty()) {
1329 QStringList aRefNames;
1330 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1331 aLast = aRefFeatures.end();
1332 for (; anIt != aLast; anIt++) {
1333 FeaturePtr aFeature = (*anIt);
1334 std::string aFName = aFeature->data()->name().c_str();
1335 std::string aName = (*anIt)->name().c_str();
1336 aRefNames.append((*anIt)->name().c_str());
1338 QString aNames = aRefNames.join(", ");
1340 QMessageBox::StandardButton aRes = QMessageBox::warning(
1341 aDesktop, tr("Delete features"),
1342 QString(tr("Selected features are used in the following features: %1.\
1343 These features will be deleted also. Would you like to continue?")).arg(aNames),
1344 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1345 if (aRes != QMessageBox::Yes)
1349 QString aDescription = tr("Delete %1");
1350 QStringList aObjectNames;
1351 foreach (ObjectPtr aObj, theList) {
1352 if (!aObj->data().get())
1354 aObjectNames << QString::fromStdString(aObj->data()->name());
1356 aDescription = aDescription.arg(aObjectNames.join(", "));
1357 SessionPtr aMgr = ModelAPI_Session::get();
1358 aMgr->startOperation(aDescription.toStdString());
1359 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1360 aLast = aRefFeatures.end();
1361 for (; anIt != aLast; anIt++) {
1362 FeaturePtr aRefFeature = (*anIt);
1363 DocumentPtr aDoc = aRefFeature->document();
1364 aDoc->removeFeature(aRefFeature);
1368 foreach (ObjectPtr aObj, theList)
1370 DocumentPtr aDoc = aObj->document();
1371 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1373 if (aDoc == aMgr->activeDocument()) {
1377 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1379 aDoc->removeFeature(aFeature);
1384 myDisplayer->updateViewer();
1385 aMgr->finishOperation();
1386 updateCommandStatus();
1389 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1391 bool isFoundResultType = false;
1392 foreach(ObjectPtr anObj, theObjects)
1394 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1395 if (aResult.get() == NULL)
1398 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1399 if (isFoundResultType)
1402 return isFoundResultType;
1405 //**************************************************************
1406 bool XGUI_Workshop::canChangeColor() const
1408 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1410 std::set<std::string> aTypes;
1411 aTypes.insert(ModelAPI_ResultGroup::group());
1412 aTypes.insert(ModelAPI_ResultConstruction::group());
1413 aTypes.insert(ModelAPI_ResultBody::group());
1414 return hasResults(aObjects, aTypes);
1417 //**************************************************************
1418 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1420 std::vector<int> aColor;
1421 foreach(ObjectPtr anObject, theObjects) {
1423 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1425 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1426 if (!aColor.empty())
1429 if (aColor.size() != 3)
1432 // 2. show the dialog to change the value
1433 QDialog* aDlg = new QDialog();
1434 QVBoxLayout* aLay = new QVBoxLayout(aDlg);
1436 QtxColorButton* aColorBtn = new QtxColorButton(aDlg);
1437 aColorBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
1439 aLay->addWidget(aColorBtn);
1440 aColorBtn->setColor(QColor(aColor[0], aColor[1], aColor[2]));
1442 QDialogButtonBox* aButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
1443 Qt::Horizontal, aDlg);
1444 connect(aButtons, SIGNAL(accepted()), aDlg, SLOT(accept()));
1445 connect(aButtons, SIGNAL(rejected()), aDlg, SLOT(reject()));
1446 aLay->addWidget(aButtons);
1448 aDlg->move(QCursor::pos());
1449 bool isDone = aDlg->exec() == QDialog::Accepted;
1453 QColor aColorResult = aColorBtn->color();
1454 int aRedResult = aColorResult.red(),
1455 aGreenResult = aColorResult.green(),
1456 aBlueResult = aColorResult.blue();
1458 if (aRedResult == aColor[0] && aGreenResult == aColor[1] && aBlueResult == aColor[2])
1461 // 3. abort the previous operation and start a new one
1462 SessionPtr aMgr = ModelAPI_Session::get();
1463 bool aWasOperation = aMgr->isOperation(); // keep this value
1464 if (!aWasOperation) {
1465 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
1466 aMgr->startOperation(aDescription.toStdString());
1469 // 4. set the value to all results
1470 AttributeIntArrayPtr aColorAttr;
1471 foreach(ObjectPtr anObj, theObjects) {
1472 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1473 if (aResult.get() != NULL) {
1474 aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1475 if (aColorAttr.get() != NULL) {
1476 if (!aColorAttr->size()) {
1477 aColorAttr->setSize(3);
1479 aColorAttr->setValue(0, aRedResult);
1480 aColorAttr->setValue(1, aGreenResult);
1481 aColorAttr->setValue(2, aBlueResult);
1486 aMgr->finishOperation();
1487 updateCommandStatus();
1490 //**************************************************************
1491 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1493 foreach (ObjectPtr aObj, theList)
1496 displayObject(aObj);
1498 myDisplayer->erase(aObj, false);
1501 myDisplayer->updateViewer();
1504 //**************************************************************
1505 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1507 myDisplayer->showOnly(theList);
1511 //**************************************************************
1512 void XGUI_Workshop::registerValidators() const
1514 SessionPtr aMgr = ModelAPI_Session::get();
1515 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1518 //**************************************************************
1519 void XGUI_Workshop::displayAllResults()
1521 SessionPtr aMgr = ModelAPI_Session::get();
1522 DocumentPtr aRootDoc = aMgr->moduleDocument();
1523 displayDocumentResults(aRootDoc);
1524 for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1525 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1526 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1527 displayDocumentResults(aPart->partDoc());
1529 myDisplayer->updateViewer();
1532 //**************************************************************
1533 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1537 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1538 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1541 //**************************************************************
1542 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1544 for (int i = 0; i < theDoc->size(theGroup); i++)
1545 displayObject(theDoc->object(theGroup, i));
1548 //**************************************************************
1549 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1551 foreach(ObjectPtr aObj, theList) {
1552 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1554 if (theList.size() > 0)
1555 myDisplayer->updateViewer();
1558 //**************************************************************
1559 void XGUI_Workshop::closeDocument()
1561 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1562 while (anOperation) {
1563 anOperation->abort();
1564 anOperation = operationMgr()->currentOperation();
1566 myDisplayer->closeLocalContexts();
1567 myDisplayer->eraseAll();
1568 objectBrowser()->clearContent();
1570 SessionPtr aMgr = ModelAPI_Session::get();
1572 objectBrowser()->clearContent();
1575 //**************************************************************
1576 void XGUI_Workshop::displayObject(ObjectPtr theObj)
1578 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
1579 if (aBody.get() != NULL) {
1580 int aNb = myDisplayer->objectsCount();
1581 myDisplayer->display(theObj, false);
1585 myDisplayer->display(theObj, false);
1588 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
1590 XGUI_HistoryMenu* aMenu = NULL;
1591 if (isSalomeMode()) {
1592 QAction* anAction = qobject_cast<QAction*>(theObject);
1595 aMenu = new XGUI_HistoryMenu(anAction);
1597 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
1598 aMenu = new XGUI_HistoryMenu(aButton);
1600 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
1601 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
1604 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
1606 QList<ActionInfo> aResult;
1607 std::list<std::string>::const_iterator it = theList.cbegin();
1608 for (; it != theList.cend(); it++) {
1609 QString anId = QString::fromStdString(*it);
1610 bool isEditing = anId.endsWith(ModuleBase_Operation::EditSuffix());
1612 anId.chop(ModuleBase_Operation::EditSuffix().size());
1614 ActionInfo anInfo = myActionsMgr->actionInfoById(anId);
1616 anInfo.text = anInfo.text.prepend("Modify ");