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);
1056 myModule->createFeatures();
1057 myActionsMgr->update();
1061 //******************************************************
1062 void XGUI_Workshop::updateCommandStatus()
1064 QList<QAction*> aCommands;
1065 if (isSalomeMode()) { // update commands in SALOME mode
1066 aCommands = salomeConnector()->commandList();
1068 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1069 foreach (AppElements_Command* aCmd, aMenuBar->features())
1070 aCommands.append(aCmd);
1072 SessionPtr aMgr = ModelAPI_Session::get();
1073 if (aMgr->hasModuleDocument()) {
1074 QAction *aUndoCmd, *aRedoCmd;
1075 foreach(QAction* aCmd, aCommands) {
1076 QString aId = aCmd->data().toString();
1077 if (aId == "UNDO_CMD")
1079 else if (aId == "REDO_CMD")
1082 // Enable all commands
1083 aCmd->setEnabled(true);
1086 aUndoCmd->setEnabled(myModule->canUndo());
1087 aRedoCmd->setEnabled(myModule->canRedo());
1090 foreach(QAction* aCmd, aCommands) {
1091 QString aId = aCmd->data().toString();
1092 if (aId == "NEW_CMD")
1093 aCmd->setEnabled(true);
1094 else if (aId == "EXIT_CMD")
1095 aCmd->setEnabled(true);
1097 aCmd->setEnabled(false);
1100 myActionsMgr->update();
1101 emit commandStatusUpdated();
1104 void XGUI_Workshop::updateHistory()
1106 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1107 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1108 emit updateUndoHistory(aUndoRes);
1110 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1111 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1112 emit updateRedoHistory(aRedoRes);
1115 //******************************************************
1116 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1118 QDockWidget* aObjDock = new QDockWidget(theParent);
1119 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1120 aObjDock->setWindowTitle(tr("Object browser"));
1121 aObjDock->setStyleSheet(
1122 "::title { position: relative; padding-left: 5px; text-align: left center }");
1123 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1124 connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this,
1125 SLOT(changeCurrentDocument(ObjectPtr)));
1126 aObjDock->setWidget(myObjectBrowser);
1128 myContextMenuMgr->connectObjectBrowser();
1132 //******************************************************
1134 * Creates dock widgets, places them in corresponding area
1135 * and tabifies if necessary.
1137 void XGUI_Workshop::createDockWidgets()
1139 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1140 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1141 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1142 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
1143 myPropertyPanel->setupActions(myActionsMgr);
1144 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1145 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1146 hidePropertyPanel(); ///<! Invisible by default
1147 hideObjectBrowser();
1148 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1149 myPropertyPanel->installEventFilter(myOperationMgr);
1151 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1152 connect(aOkAct, SIGNAL(triggered()), myOperationMgr, SLOT(onCommitOperation()));
1153 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1154 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1155 connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets()));
1156 connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)),
1157 myOperationMgr, SLOT(onKeyReleased(QKeyEvent*)));
1158 connect(myOperationMgr, SIGNAL(validationStateChanged(bool)),
1159 aOkAct, SLOT(setEnabled(bool)));
1160 QAction* aAcceptAllAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll);
1161 connect(myOperationMgr, SIGNAL(nestedStateChanged(bool)),
1162 aAcceptAllAct, SLOT(setEnabled(bool)));
1166 //******************************************************
1167 void XGUI_Workshop::showPropertyPanel()
1169 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1170 ///<! Restore ability to close panel from the window's menu
1171 aViewAct->setEnabled(true);
1172 myPropertyPanel->show();
1173 myPropertyPanel->raise();
1176 //******************************************************
1177 void XGUI_Workshop::hidePropertyPanel()
1179 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1180 ///<! Do not allow to show empty property panel
1181 aViewAct->setEnabled(false);
1182 myPropertyPanel->hide();
1185 //******************************************************
1186 void XGUI_Workshop::showObjectBrowser()
1188 myObjectBrowser->parentWidget()->show();
1191 //******************************************************
1192 void XGUI_Workshop::hideObjectBrowser()
1194 myObjectBrowser->parentWidget()->hide();
1197 //******************************************************
1198 void XGUI_Workshop::onFeatureTriggered()
1200 QAction* aCmd = dynamic_cast<QAction*>(sender());
1202 QString aId = salomeConnector()->commandId(aCmd);
1204 myModule->launchOperation(aId);
1208 //******************************************************
1209 void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
1211 SessionPtr aMgr = ModelAPI_Session::get();
1213 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theObj);
1215 DocumentPtr aPartDoc = aPart->partDoc();
1217 aMgr->setActiveDocument(aPartDoc);
1222 aMgr->setActiveDocument(aMgr->moduleDocument());
1225 //******************************************************
1226 void XGUI_Workshop::salomeViewerSelectionChanged()
1228 emit salomeViewerSelection();
1231 //**************************************************************
1232 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1234 return mySalomeConnector->viewer();
1237 //**************************************************************
1238 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1240 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1241 if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) {
1242 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
1243 activatePart(aPart);
1244 } else if (theId == "DEACTIVATE_PART_CMD")
1245 activatePart(ResultPartPtr());
1246 else if (theId == "DELETE_CMD")
1247 deleteObjects(aObjects);
1248 else if (theId == "COLOR_CMD")
1249 changeColor(aObjects);
1250 else if (theId == "SHOW_CMD")
1251 showObjects(aObjects, true);
1252 else if (theId == "HIDE_CMD")
1253 showObjects(aObjects, false);
1254 else if (theId == "SHOW_ONLY_CMD")
1255 showOnlyObjects(aObjects);
1256 else if (theId == "SHADING_CMD")
1257 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1258 else if (theId == "WIREFRAME_CMD")
1259 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1260 else if (theId == "HIDEALL_CMD")
1261 myDisplayer->eraseAll();
1262 else if (theId == "EDIT_CMD") {
1263 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObjects.first());
1265 myModule->editFeature(aFeature);
1269 //**************************************************************
1270 void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
1272 if (!myPartActivating) {
1273 myPartActivating = true;
1275 theFeature->activate();
1276 changeCurrentDocument(theFeature);
1277 myObjectBrowser->activatePart(theFeature);
1278 myPartActivating = false;
1280 updateCommandStatus();
1283 //**************************************************************
1284 //void XGUI_Workshop::activateLastPart()
1286 // SessionPtr aMgr = ModelAPI_Session::get();
1287 // DocumentPtr aDoc = aMgr->moduleDocument();
1288 // std::string aGrpName = ModelAPI_ResultPart::group();
1289 // ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
1290 // ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
1292 // activatePart(aPart);
1296 //**************************************************************
1297 void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList)
1299 ModuleBase_IModule* aModule = module();
1300 if (aModule->deleteObjects())
1303 if (!isActiveOperationAborted())
1306 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1307 std::set<FeaturePtr> aRefFeatures;
1308 foreach (ObjectPtr aObj, theList)
1310 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1312 // TODO: check for what there is this condition. It is placed here historicaly because
1313 // ther is this condition during remove features.
1315 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1316 if (aFeature.get() != NULL) {
1317 aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
1322 if (!aRefFeatures.empty()) {
1323 QStringList aRefNames;
1324 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1325 aLast = aRefFeatures.end();
1326 for (; anIt != aLast; anIt++) {
1327 FeaturePtr aFeature = (*anIt);
1328 std::string aFName = aFeature->data()->name().c_str();
1329 std::string aName = (*anIt)->name().c_str();
1330 aRefNames.append((*anIt)->name().c_str());
1332 QString aNames = aRefNames.join(", ");
1334 QMessageBox::StandardButton aRes = QMessageBox::warning(
1335 aDesktop, tr("Delete features"),
1336 QString(tr("Selected features are used in the following features: %1.\
1337 These features will be deleted also. Would you like to continue?")).arg(aNames),
1338 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1339 if (aRes != QMessageBox::Yes)
1343 QString aDescription = tr("Delete %1");
1344 QStringList aObjectNames;
1345 foreach (ObjectPtr aObj, theList) {
1346 if (!aObj->data().get())
1348 aObjectNames << QString::fromStdString(aObj->data()->name());
1350 aDescription = aDescription.arg(aObjectNames.join(", "));
1351 SessionPtr aMgr = ModelAPI_Session::get();
1352 aMgr->startOperation(aDescription.toStdString());
1353 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1354 aLast = aRefFeatures.end();
1355 for (; anIt != aLast; anIt++) {
1356 FeaturePtr aRefFeature = (*anIt);
1357 DocumentPtr aDoc = aRefFeature->document();
1358 aDoc->removeFeature(aRefFeature);
1362 foreach (ObjectPtr aObj, theList)
1364 DocumentPtr aDoc = aObj->document();
1365 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1367 if (aDoc == aMgr->activeDocument()) {
1371 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1373 aDoc->removeFeature(aFeature);
1378 myDisplayer->updateViewer();
1379 aMgr->finishOperation();
1380 updateCommandStatus();
1383 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1385 bool isFoundResultType = false;
1386 foreach(ObjectPtr anObj, theObjects)
1388 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1389 if (aResult.get() == NULL)
1392 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1393 if (isFoundResultType)
1396 return isFoundResultType;
1399 //**************************************************************
1400 bool XGUI_Workshop::canChangeColor() const
1402 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1404 std::set<std::string> aTypes;
1405 aTypes.insert(ModelAPI_ResultGroup::group());
1406 aTypes.insert(ModelAPI_ResultConstruction::group());
1407 aTypes.insert(ModelAPI_ResultBody::group());
1408 return hasResults(aObjects, aTypes);
1411 //**************************************************************
1412 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1414 std::vector<int> aColor;
1415 foreach(ObjectPtr anObject, theObjects) {
1417 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1419 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1420 if (!aColor.empty())
1423 if (aColor.size() != 3)
1426 // 2. show the dialog to change the value
1427 QDialog* aDlg = new QDialog();
1428 QVBoxLayout* aLay = new QVBoxLayout(aDlg);
1430 QtxColorButton* aColorBtn = new QtxColorButton(aDlg);
1431 aColorBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
1433 aLay->addWidget(aColorBtn);
1434 aColorBtn->setColor(QColor(aColor[0], aColor[1], aColor[2]));
1436 QDialogButtonBox* aButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
1437 Qt::Horizontal, aDlg);
1438 connect(aButtons, SIGNAL(accepted()), aDlg, SLOT(accept()));
1439 connect(aButtons, SIGNAL(rejected()), aDlg, SLOT(reject()));
1440 aLay->addWidget(aButtons);
1442 aDlg->move(QCursor::pos());
1443 bool isDone = aDlg->exec() == QDialog::Accepted;
1447 QColor aColorResult = aColorBtn->color();
1448 int aRedResult = aColorResult.red(),
1449 aGreenResult = aColorResult.green(),
1450 aBlueResult = aColorResult.blue();
1452 if (aRedResult == aColor[0] && aGreenResult == aColor[1] && aBlueResult == aColor[2])
1455 // 3. abort the previous operation and start a new one
1456 SessionPtr aMgr = ModelAPI_Session::get();
1457 bool aWasOperation = aMgr->isOperation(); // keep this value
1458 if (!aWasOperation) {
1459 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
1460 aMgr->startOperation(aDescription.toStdString());
1463 // 4. set the value to all results
1464 AttributeIntArrayPtr aColorAttr;
1465 foreach(ObjectPtr anObj, theObjects) {
1466 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1467 if (aResult.get() != NULL) {
1468 aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1469 if (aColorAttr.get() != NULL) {
1470 if (!aColorAttr->size()) {
1471 aColorAttr->setSize(3);
1473 aColorAttr->setValue(0, aRedResult);
1474 aColorAttr->setValue(1, aGreenResult);
1475 aColorAttr->setValue(2, aBlueResult);
1480 aMgr->finishOperation();
1481 updateCommandStatus();
1484 //**************************************************************
1485 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1487 foreach (ObjectPtr aObj, theList)
1490 displayObject(aObj);
1492 myDisplayer->erase(aObj, false);
1495 myDisplayer->updateViewer();
1498 //**************************************************************
1499 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1501 myDisplayer->showOnly(theList);
1505 //**************************************************************
1506 void XGUI_Workshop::registerValidators() const
1508 SessionPtr aMgr = ModelAPI_Session::get();
1509 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1512 //**************************************************************
1513 void XGUI_Workshop::displayAllResults()
1515 SessionPtr aMgr = ModelAPI_Session::get();
1516 DocumentPtr aRootDoc = aMgr->moduleDocument();
1517 displayDocumentResults(aRootDoc);
1518 for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1519 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1520 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1521 displayDocumentResults(aPart->partDoc());
1523 myDisplayer->updateViewer();
1526 //**************************************************************
1527 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1531 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1532 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1535 //**************************************************************
1536 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1538 for (int i = 0; i < theDoc->size(theGroup); i++)
1539 displayObject(theDoc->object(theGroup, i));
1542 //**************************************************************
1543 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1545 foreach(ObjectPtr aObj, theList) {
1546 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1548 if (theList.size() > 0)
1549 myDisplayer->updateViewer();
1552 //**************************************************************
1553 void XGUI_Workshop::closeDocument()
1555 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1556 while (anOperation) {
1557 anOperation->abort();
1558 anOperation = operationMgr()->currentOperation();
1560 myDisplayer->closeLocalContexts();
1561 myDisplayer->eraseAll();
1562 objectBrowser()->clearContent();
1564 SessionPtr aMgr = ModelAPI_Session::get();
1566 objectBrowser()->clearContent();
1569 //**************************************************************
1570 void XGUI_Workshop::displayObject(ObjectPtr theObj)
1572 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
1573 if (aBody.get() != NULL) {
1574 int aNb = myDisplayer->objectsCount();
1575 myDisplayer->display(theObj, false);
1579 myDisplayer->display(theObj, false);
1582 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
1584 XGUI_HistoryMenu* aMenu = NULL;
1585 if (isSalomeMode()) {
1586 QAction* anAction = qobject_cast<QAction*>(theObject);
1589 aMenu = new XGUI_HistoryMenu(anAction);
1591 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
1592 aMenu = new XGUI_HistoryMenu(aButton);
1594 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
1595 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
1598 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
1600 QList<ActionInfo> aResult;
1601 std::list<std::string>::const_iterator it = theList.cbegin();
1602 for (; it != theList.cend(); it++) {
1603 QString anId = QString::fromStdString(*it);
1604 bool isEditing = anId.endsWith(ModuleBase_Operation::EditSuffix());
1606 anId.chop(ModuleBase_Operation::EditSuffix().size());
1608 ActionInfo anInfo = myActionsMgr->actionInfoById(anId);
1610 anInfo.text = anInfo.text.prepend("Modify ");