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_ResultConstruction.h>
40 #include <ModelAPI_ResultBody.h>
42 //#include <PartSetPlugin_Part.h>
44 #include <Events_Loop.h>
45 #include <Events_Error.h>
46 #include <Events_LongOp.h>
48 #include <ModuleBase_Operation.h>
49 #include <ModuleBase_Operation.h>
50 #include <ModuleBase_OperationDescription.h>
51 #include <ModuleBase_SelectionValidator.h>
52 #include <ModuleBase_WidgetFactory.h>
53 #include <ModuleBase_Tools.h>
54 #include <ModuleBase_IViewer.h>
55 #include<ModuleBase_FilterFactory.h>
57 #include <Config_Common.h>
58 #include <Config_FeatureMessage.h>
59 #include <Config_PointerMessage.h>
60 #include <Config_ModuleReader.h>
61 #include <Config_PropManager.h>
62 #include <Config_SelectionFilterMessage.h>
64 #include <QApplication>
65 #include <QFileDialog>
66 #include <QMessageBox>
67 #include <QMdiSubWindow>
68 #include <QPushButton>
69 #include <QDockWidget>
74 #include <QToolButton>
88 QMap<QString, QString> XGUI_Workshop::myIcons;
91 QIcon XGUI_Workshop::featureIcon(const FeaturePtr& theFeature)
95 std::string aKind = theFeature->getKind();
96 QString aId(aKind.c_str());
97 if (!myIcons.contains(aId))
100 QString anIconString = myIcons[aId];
102 ModelAPI_ExecState aState = theFeature->data()->execState();
104 case ModelAPI_StateDone:
105 case ModelAPI_StateNothing: {
106 anIcon = QIcon(anIconString);
109 case ModelAPI_StateMustBeUpdated: {
110 anIcon = ModuleBase_Tools::lighter(anIconString);
113 case ModelAPI_StateExecFailed: {
114 anIcon = ModuleBase_Tools::composite(":pictures/exec_state_failed.png", anIconString);
117 case ModelAPI_StateInvalidArgument: {
118 anIcon = ModuleBase_Tools::composite(":pictures/exec_state_invalid_parameters.png",
127 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
129 myCurrentDir(QString()),
131 mySalomeConnector(theConnector),
135 myUpdatePrefs(false),
136 myPartActivating(false)
138 myMainWindow = mySalomeConnector ? 0 : new AppElements_MainWindow();
140 myDisplayer = new XGUI_Displayer(this);
142 mySelector = new XGUI_SelectionMgr(this);
143 //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
145 myOperationMgr = new XGUI_OperationMgr(this);
146 myActionsMgr = new XGUI_ActionsMgr(this);
147 myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
148 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
149 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
150 SLOT(onContextMenuCommand(const QString&, bool)));
152 myViewerProxy = new XGUI_ViewerProxy(this);
153 connect(myViewerProxy, SIGNAL(selectionChanged()),
154 myActionsMgr, SLOT(updateOnViewSelection()));
156 myModuleConnector = new XGUI_ModuleConnector(this);
158 connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
159 SLOT(onOperationStarted(ModuleBase_Operation*)));
160 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
161 SLOT(onOperationResumed(ModuleBase_Operation*)));
162 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
163 SLOT(onOperationStopped(ModuleBase_Operation*)));
164 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
165 SLOT(onOperationCommitted(ModuleBase_Operation*)));
166 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
167 SLOT(onOperationAborted(ModuleBase_Operation*)));
168 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
169 connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
172 //******************************************************
173 XGUI_Workshop::~XGUI_Workshop(void)
178 //******************************************************
179 void XGUI_Workshop::startApplication()
183 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
184 Config_Prop::Directory, "");
186 //Initialize event listening
187 Events_Loop* aLoop = Events_Loop::loop();
188 aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
189 aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
190 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
191 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
192 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
193 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
194 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
195 aLoop->registerListener(this, Events_LongOp::eventID());
196 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
197 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
198 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOSHOW));
199 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
200 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED));
202 registerValidators();
204 // Calling of loadCustomProps before activating module is required
205 // by Config_PropManger to restore user-defined path to plugins
206 ModuleBase_Preferences::loadCustomProps();
209 myMainWindow->show();
210 updateCommandStatus();
215 emit applicationStarted();
218 //******************************************************
219 void XGUI_Workshop::initMenu()
221 myContextMenuMgr->createActions();
223 if (isSalomeMode()) {
224 // Create only Undo, Redo commands
225 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
226 tr("Undo last command"),
227 QIcon(":pictures/undo.png"),
228 QKeySequence::Undo, false, "MEN_DESK_EDIT");
229 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
230 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
232 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
233 QIcon(":pictures/redo.png"), QKeySequence::Redo,
234 false, "MEN_DESK_EDIT");
235 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
236 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
238 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
239 aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
240 QIcon(":pictures/rebuild.png"), QKeySequence(),
241 false, "MEN_DESK_EDIT");
242 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
243 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
245 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export NewGeom..."), tr("Export the current document into a NewGeom file"),
246 QIcon(), QKeySequence(),
247 false, "MEN_DESK_FILE");
248 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
250 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import NewGeom..."), tr("Import a NewGeom file"),
251 QIcon(), QKeySequence(),
252 false, "MEN_DESK_FILE");
253 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
254 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
258 // File commands group
259 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
261 AppElements_Command* aCommand;
263 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
264 QIcon(":pictures/save.png"), QKeySequence::Save);
265 aCommand->connectTo(this, SLOT(onSave()));
266 //aCommand->disable();
268 QString aUndoId = "UNDO_CMD";
269 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
270 QIcon(":pictures/undo.png"), QKeySequence::Undo);
271 aCommand->connectTo(this, SLOT(onUndo()));
272 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
273 addHistoryMenu(aUndoButton,
274 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
277 QString aRedoId = "REDO_CMD";
278 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
279 QIcon(":pictures/redo.png"), QKeySequence::Redo);
280 aCommand->connectTo(this, SLOT(onRedo()));
281 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
282 addHistoryMenu(aRedoButton,
283 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
286 aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
287 QIcon(":pictures/rebuild.png"), QKeySequence());
288 aCommand->connectTo(this, SLOT(onRebuild()));
290 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
291 QIcon(":pictures/save.png"), QKeySequence());
292 aCommand->connectTo(this, SLOT(onSaveAs()));
293 //aCommand->disable();
295 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
296 QIcon(":pictures/open.png"), QKeySequence::Open);
297 aCommand->connectTo(this, SLOT(onOpen()));
299 //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
300 // QIcon(":pictures/new.png"), QKeySequence::New);
301 //aCommand->connectTo(this, SLOT(onNew()));
303 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
304 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
305 aCommand->connectTo(this, SLOT(onPreferences()));
307 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
308 QIcon(":pictures/close.png"), QKeySequence::Close);
309 aCommand->connectTo(this, SLOT(onExit()));
310 //FIXME: SBH's test action. Can be used for some GUI tests.
312 // aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
313 // QIcon(":pictures/close.png"), QKeySequence(), true);
314 // aCommand->connectTo(myMainWindow, SLOT(dockPythonConsole()));
318 //******************************************************
319 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
321 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
322 return aMenuBar->addWorkbench(theName);
325 //******************************************************
326 void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessage)
328 if (QApplication::instance()->thread() != QThread::currentThread()) {
330 std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
332 SessionPtr aMgr = ModelAPI_Session::get();
333 PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(theMessage);
334 QApplication::postEvent(this, aPostponeEvent);
338 //A message to start feature creation received.
339 if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
340 std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
341 std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
342 if (!aFeatureMsg->isInternal()) {
343 addFeature(aFeatureMsg);
346 // Process creation of Part
347 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
348 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
349 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
350 onFeatureCreatedMsg(aUpdMsg);
352 if (mySalomeConnector)
353 mySalomeConnector->createPreferences();
354 myUpdatePrefs = false;
357 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
358 myUpdatePrefs = true;
361 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
362 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
363 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
364 onFeatureRedisplayMsg(aUpdMsg);
366 //Update property panel on corresponding message. If there is no current operation (no
367 //property panel), or received message has different feature to the current - do nothing.
368 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
369 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
370 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
371 onFeatureUpdatedMsg(anUpdateMsg);
372 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
373 std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
374 std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
375 onObjectDeletedMsg(aDelMsg);
376 } else if (theMessage->eventID() == Events_LongOp::eventID()) {
377 if (Events_LongOp::isPerformed()) {
378 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
380 QApplication::restoreOverrideCursor();
382 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW)) {
383 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
384 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
385 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
386 QObjectPtrList aList;
387 std::set<ObjectPtr>::const_iterator aIt;
388 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
390 showObjects(aList, true);
391 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE)) {
392 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
393 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
394 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
395 QObjectPtrList aList;
396 std::set<ObjectPtr>::const_iterator aIt;
397 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
399 showObjects(aList, false);
401 //An operation passed by message. Start it, process and commit.
402 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
403 std::shared_ptr<Config_PointerMessage> aPartSetMsg =
404 std::dynamic_pointer_cast<Config_PointerMessage>(theMessage);
405 //myPropertyPanel->cleanContent();
406 ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
408 if (myOperationMgr->startOperation(anOperation)) {
409 myPropertyPanel->updateContentWidget(anOperation->feature());
410 if (!anOperation->getDescription()->hasXmlRepresentation()) {
411 if (anOperation->commit())
412 updateCommandStatus();
415 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
416 myActionsMgr->update();
417 // Find and Activate active part
418 if (myPartActivating)
420 SessionPtr aMgr = ModelAPI_Session::get();
421 DocumentPtr aActiveDoc = aMgr->activeDocument();
422 DocumentPtr aDoc = aMgr->moduleDocument();
423 if (aActiveDoc == aDoc) {
424 activatePart(ResultPartPtr());
427 std::string aGrpName = ModelAPI_ResultPart::group();
428 for (int i = 0; i < aDoc->size(aGrpName); i++) {
429 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
430 if (aPart->partDoc() == aActiveDoc) {
431 activatePart(aPart); // Activate a part which corresponds to active Doc
435 // If not found then activate global document
436 activatePart(ResultPartPtr());
439 else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) {
440 std::shared_ptr<Config_SelectionFilterMessage> aMsg =
441 std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
443 ModuleBase_FilterFactory* aFactory = moduleConnector()->selectionFilters();
444 if (!aMsg->attributeId().empty()) {
445 aFactory->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId(),
453 //Show error dialog if error message received.
454 std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
456 emit errorOccurred(QString::fromLatin1(anAppError->description()));
459 if (!isSalomeMode()) {
460 SessionPtr aMgr = ModelAPI_Session::get();
461 if (aMgr->isModified() != myMainWindow->isModifiedState())
462 myMainWindow->setModifiedState(aMgr->isModified());
466 //******************************************************
467 QMainWindow* XGUI_Workshop::desktop() const
469 return isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
472 //******************************************************
473 void XGUI_Workshop::onStartWaiting()
475 if (Events_LongOp::isPerformed()) {
476 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
480 //******************************************************
481 void XGUI_Workshop::onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
483 std::set<ObjectPtr> aFeatures = theMsg->objects();
484 if (myOperationMgr->hasOperation()) {
485 FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
486 std::set<ObjectPtr>::const_iterator aIt;
487 for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
488 ObjectPtr aNewFeature = (*aIt);
489 if (aNewFeature == aCurrentFeature) {
490 myPropertyPanel->updateContentWidget(aCurrentFeature);
495 myOperationMgr->onValidateOperation();
497 myObjectBrowser->processEvent(theMsg);
500 //******************************************************
501 void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
503 std::set<ObjectPtr> aObjects = theMsg->objects();
504 std::set<ObjectPtr>::const_iterator aIt;
505 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
506 ObjectPtr aObj = (*aIt);
508 bool aHide = !aObj->data() || !aObj->data()->isValid();
509 if (!aHide) { // check that this is not hidden result
510 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
511 aHide = aRes && aRes->isConcealed();
514 myDisplayer->erase(aObj, false);
516 if (myDisplayer->isVisible(aObj)) {
517 displayObject(aObj); // In order to update presentation
518 if (myOperationMgr->hasOperation()) {
519 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
520 if (!aOperation->isEditOperation() &&
521 aOperation->hasObject(aObj) && myDisplayer->isActive(aObj))
522 myDisplayer->deactivate(aObj);
525 if (myOperationMgr->hasOperation()) {
526 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
527 if (myModule->canDisplayObject(aObj)) {
529 // Deactivate object of current operation from selection
530 if (myDisplayer->isActive(aObj))
531 myDisplayer->deactivate(aObj);
537 myDisplayer->updateViewer();
540 //******************************************************
541 void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
543 std::set<ObjectPtr> aObjects = theMsg->objects();
545 std::set<ObjectPtr>::const_iterator aIt;
546 bool aHasPart = false;
547 bool isDisplayed = false;
548 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
550 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
553 // If a feature is created from the aplication's python console
554 // it doesn't stored in the operation mgr and doesn't displayed
555 } else if (myModule->canDisplayObject(*aIt)) {
561 myObjectBrowser->processEvent(theMsg);
563 myDisplayer->updateViewer();
564 //if (aHasPart) { // TODO: Avoid activate last part on loading of document
565 // activateLastPart();
569 //******************************************************
570 void XGUI_Workshop::onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg)
573 myObjectBrowser->processEvent(theMsg);
574 //std::set<ObjectPtr> aFeatures = theMsg->objects();
577 //******************************************************
578 void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
580 setNestedFeatures(theOperation);
582 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
583 connectWithOperation(theOperation);
584 setPropertyPanel(theOperation);
586 updateCommandStatus();
588 myModule->operationStarted(theOperation);
591 //******************************************************
592 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
594 setNestedFeatures(theOperation);
596 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
597 // connectWithOperation(theOperation); already connected
598 setPropertyPanel(theOperation);
600 updateCommandStatus();
602 myModule->operationResumed(theOperation);
606 //******************************************************
607 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
609 ModuleBase_ISelection* aSel = mySelector->selection();
610 QObjectPtrList aObj = aSel->selectedPresentations();
611 //!< No need for property panel
612 updateCommandStatus();
614 myPropertyPanel->cleanContent();
616 // Activate objects created by current operation
617 // in order to clean selection modes
619 myDisplayer->activateObjects(aModes);
620 myModule->operationStopped(theOperation);
624 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
626 myModule->operationCommitted(theOperation);
629 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
631 myModule->operationAborted(theOperation);
634 void XGUI_Workshop::setNestedFeatures(ModuleBase_Operation* theOperation)
636 if (this->isSalomeMode())
637 theOperation->setNestedFeatures(mySalomeConnector->nestedActions(theOperation->id()));
639 theOperation->setNestedFeatures(myActionsMgr->nestedCommands(theOperation->id()));
642 void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
645 QString aXmlRepr = theOperation->getDescription()->xmlRepresentation();
646 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
649 myPropertyPanel->cleanContent();
650 aFactory.createWidget(myPropertyPanel->contentWidget());
651 ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget());
653 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
654 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
655 bool isStoreValue = !theOperation->isEditOperation() &&
656 aWidget->isValueDefault() && !aWidget->isComputedDefault();
657 aWidget->setFeature(theOperation->feature(), isStoreValue);
658 aWidget->enableFocusProcessing();
661 myPropertyPanel->setModelWidgets(aWidgets);
662 theOperation->setPropertyPanel(myPropertyPanel);
664 myModule->propertyPanelDefined(theOperation);
666 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
669 bool XGUI_Workshop::event(QEvent * theEvent)
671 PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
673 std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
674 processEvent(aEventPtr);
683 void XGUI_Workshop::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
687 qDebug() << "XGUI_Workshop::addFeature: NULL message.";
691 ActionInfo aFeatureInfo;
692 aFeatureInfo.initFrom(theMessage);
693 // Remember features icons
694 myIcons[QString::fromStdString(theMessage->id())] = aFeatureInfo.iconFile;
696 QString aWchName = QString::fromStdString(theMessage->workbenchId());
697 QStringList aNestedFeatures =
698 QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
699 QString aDocKind = QString::fromStdString(theMessage->documentKind());
700 if (isSalomeMode()) {
701 QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureInfo);
702 salomeConnector()->setNestedActions(aFeatureInfo.id, aNestedFeatures);
703 salomeConnector()->setDocumentKind(aFeatureInfo.id, aDocKind);
705 myActionsMgr->addCommand(aAction);
706 myModule->actionCreated(aAction);
708 //Find or create Workbench
709 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
710 AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
712 aPage = addWorkbench(aWchName);
714 //Find or create Group
715 QString aGroupName = QString::fromStdString(theMessage->groupId());
716 AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
718 aGroup = aPage->addGroup(aGroupName);
720 // Check if hotkey sequence is already defined:
721 QKeySequence aHotKey = myActionsMgr->registerShortcut(aFeatureInfo.shortcut);
722 if(aHotKey != aFeatureInfo.shortcut) {
723 aFeatureInfo.shortcut = aHotKey;
726 AppElements_Command* aCommand = aGroup->addFeature(aFeatureInfo,
729 // Enrich created button with accept/abort buttons if necessary
730 AppElements_Button* aButton = aCommand->button();
731 if (aButton->isColumnButton()) {
732 QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
733 QList<QAction*> anActList;
734 if (aNestedActions.contains("accept")) {
735 QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, aButton);
736 connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(commitAllOperations()));
737 anActList << anAction;
739 if (aNestedActions.contains("abort")) {
740 QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, aButton);
741 connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(abortAllOperations()));
742 anActList << anAction;
744 aButton->setAdditionalButtons(anActList);
746 myActionsMgr->addCommand(aCommand);
747 myModule->actionCreated(aCommand);
752 * Makes a signal/slot connections between Property Panel
753 * and given operation. The given operation becomes a
754 * current operation and previous operation if exists
756 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
758 QAction* aCommand = 0;
759 if (isSalomeMode()) {
760 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
762 AppElements_MainMenu* aMenu = myMainWindow->menuObject();
763 FeaturePtr aFeature = theOperation->feature();
765 aCommand = aMenu->feature(QString::fromStdString(aFeature->getKind()));
767 //Abort operation on uncheck the command
769 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
774 * Saves document with given name.
776 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
778 QApplication::restoreOverrideCursor();
779 SessionPtr aMgr = ModelAPI_Session::get();
780 aMgr->save(theName.toLatin1().constData(), theFileNames);
781 QApplication::restoreOverrideCursor();
784 bool XGUI_Workshop::isActiveOperationAborted()
786 return myOperationMgr->abortAllOperations();
789 //******************************************************
790 void XGUI_Workshop::onExit()
792 SessionPtr aMgr = ModelAPI_Session::get();
793 if (aMgr->isModified()) {
794 int anAnswer = QMessageBox::question(
795 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
796 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
797 if (anAnswer == QMessageBox::Save) {
798 bool saved = onSave();
802 } else if (anAnswer == QMessageBox::Cancel) {
809 //******************************************************
810 void XGUI_Workshop::onNew()
812 QApplication::setOverrideCursor(Qt::WaitCursor);
813 if (objectBrowser() == 0) {
815 mySelector->connectViewers();
817 myViewerProxy->connectToViewer();
819 if (!isSalomeMode()) {
820 myMainWindow->showPythonConsole();
821 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
822 aWnd->showMaximized();
823 updateCommandStatus();
825 myContextMenuMgr->connectViewer();
826 QApplication::restoreOverrideCursor();
829 //******************************************************
830 void XGUI_Workshop::onOpen()
832 if(!isActiveOperationAborted())
834 //save current file before close if modified
835 SessionPtr aSession = ModelAPI_Session::get();
836 if (aSession->isModified()) {
837 //TODO(sbh): re-launch the app?
838 int anAnswer = QMessageBox::question(
839 myMainWindow, tr("Save current file"),
840 tr("The document is modified, save before opening another?"),
841 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
842 if (anAnswer == QMessageBox::Save) {
844 } else if (anAnswer == QMessageBox::Cancel) {
847 aSession->closeAll();
851 //show file dialog, check if readable and open
852 myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
853 if (myCurrentDir.isEmpty())
855 QFileInfo aFileInfo(myCurrentDir);
856 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
857 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
861 QApplication::setOverrideCursor(Qt::WaitCursor);
862 aSession->load(myCurrentDir.toLatin1().constData());
863 myObjectBrowser->rebuildDataTree();
865 updateCommandStatus();
866 QApplication::restoreOverrideCursor();
869 //******************************************************
870 bool XGUI_Workshop::onSave()
872 if(!isActiveOperationAborted())
874 if (myCurrentDir.isEmpty()) {
877 std::list<std::string> aFiles;
878 saveDocument(myCurrentDir, aFiles);
879 updateCommandStatus();
881 myMainWindow->setModifiedState(false);
885 //******************************************************
886 bool XGUI_Workshop::onSaveAs()
888 if(!isActiveOperationAborted())
890 QFileDialog dialog(mainWindow());
891 dialog.setWindowTitle(tr("Select directory to save files..."));
892 dialog.setFileMode(QFileDialog::Directory);
893 dialog.setFilter(tr("Folders (*)"));
894 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
895 dialog.setViewMode(QFileDialog::Detail);
897 if (!dialog.exec()) {
900 QString aTempDir = dialog.selectedFiles().first();
902 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
903 int answer = QMessageBox::question(
905 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
907 tr("The folder already contains some files, save anyway?"),
908 QMessageBox::Save | QMessageBox::Cancel);
909 if (answer == QMessageBox::Cancel) {
913 myCurrentDir = aTempDir;
914 if (!isSalomeMode()) {
915 myMainWindow->setCurrentDir(myCurrentDir, false);
916 myMainWindow->setModifiedState(false);
921 //******************************************************
922 void XGUI_Workshop::onUndo(int theTimes)
924 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
925 SessionPtr aMgr = ModelAPI_Session::get();
926 if (aMgr->isOperation())
927 operationMgr()->onAbortOperation();
928 for (int i = 0; i < theTimes; ++i) {
931 updateCommandStatus();
934 //******************************************************
935 void XGUI_Workshop::onRedo(int theTimes)
937 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
938 SessionPtr aMgr = ModelAPI_Session::get();
939 if (aMgr->isOperation())
940 operationMgr()->onAbortOperation();
941 for (int i = 0; i < theTimes; ++i) {
944 updateCommandStatus();
947 //******************************************************
948 void XGUI_Workshop::onRebuild()
950 SessionPtr aMgr = ModelAPI_Session::get();
951 bool aWasOperation = aMgr->isOperation(); // keep this value
952 if (!aWasOperation) {
953 aMgr->startOperation("Rebuild");
955 static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
956 Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
957 new Events_Message(aRebuildEvent, this)));
958 if (!aWasOperation) {
959 aMgr->finishOperation();
963 //******************************************************
964 void XGUI_Workshop::onPreferences()
966 ModuleBase_Prefs aModif;
967 ModuleBase_Preferences::editPreferences(aModif);
968 if (aModif.size() > 0) {
970 foreach (ModuleBase_Pref aPref, aModif)
972 aSection = aPref.first;
973 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
975 myMainWindow->viewer()->updateFromResources();
976 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
978 myMainWindow->menuObject()->updateFromResources();
984 //******************************************************
985 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
987 QString libName = QString::fromStdString(library(theModule.toStdString()));
988 if (libName.isEmpty()) {
989 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
994 CREATE_FUNC crtInst = 0;
997 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
1001 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1002 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1003 QString aMsg((char*) &lpMsgBuf);
1004 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1005 ::LocalFree(lpMsgBuf);
1007 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1011 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1012 | FORMAT_MESSAGE_IGNORE_INSERTS,
1013 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1014 QString aMsg((char*) &lpMsgBuf);
1015 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1016 ::LocalFree(lpMsgBuf);
1020 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1022 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1024 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1026 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1031 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1033 if (!err.isEmpty()) {
1035 Events_Error::send(err.toStdString());
1037 qWarning(qPrintable(err));
1043 //******************************************************
1044 bool XGUI_Workshop::activateModule()
1046 Config_ModuleReader aModuleReader;
1047 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1048 myModule = loadModule(moduleName);
1051 myModule->createFeatures();
1052 myActionsMgr->update();
1056 //******************************************************
1057 void XGUI_Workshop::updateCommandStatus()
1059 QList<QAction*> aCommands;
1060 if (isSalomeMode()) { // update commands in SALOME mode
1061 aCommands = salomeConnector()->commandList();
1063 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1064 foreach (AppElements_Command* aCmd, aMenuBar->features())
1065 aCommands.append(aCmd);
1067 SessionPtr aMgr = ModelAPI_Session::get();
1068 if (aMgr->hasModuleDocument()) {
1069 QAction *aUndoCmd, *aRedoCmd;
1070 foreach(QAction* aCmd, aCommands) {
1071 QString aId = aCmd->data().toString();
1072 if (aId == "UNDO_CMD")
1074 else if (aId == "REDO_CMD")
1077 // Enable all commands
1078 aCmd->setEnabled(true);
1080 aUndoCmd->setEnabled(myModule->canUndo());
1081 aRedoCmd->setEnabled(myModule->canRedo());
1086 foreach(QAction* aCmd, aCommands) {
1087 QString aId = aCmd->data().toString();
1088 if (aId == "NEW_CMD")
1089 aCmd->setEnabled(true);
1090 else if (aId == "EXIT_CMD")
1091 aCmd->setEnabled(true);
1093 aCmd->setEnabled(false);
1096 myActionsMgr->update();
1097 emit commandStatusUpdated();
1100 void XGUI_Workshop::updateHistory()
1102 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1103 std::list<std::string>::iterator it = aUndoList.begin();
1104 QList<ActionInfo> aUndoRes;
1105 for ( ; it != aUndoList.end(); it++) {
1106 QString anId = QString::fromStdString(*it);
1108 if (myIcons.contains(anId))
1109 aIcon = QIcon(myIcons[anId]);
1110 aUndoRes << ActionInfo(aIcon, anId);
1112 emit updateUndoHistory(aUndoRes);
1114 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1115 it = aRedoList.begin();
1116 QList<ActionInfo> aRedoRes;
1117 for ( ; it != aRedoList.end(); it++) {
1118 QString anId = QString::fromStdString(*it);
1120 if (myIcons.contains(anId))
1121 aIcon = QIcon(myIcons[anId]);
1122 aRedoRes << ActionInfo(aIcon, anId);
1124 emit updateRedoHistory(aUndoRes);
1127 //******************************************************
1128 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1130 QDockWidget* aObjDock = new QDockWidget(theParent);
1131 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1132 aObjDock->setWindowTitle(tr("Object browser"));
1133 aObjDock->setStyleSheet(
1134 "::title { position: relative; padding-left: 5px; text-align: left center }");
1135 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1136 connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this,
1137 SLOT(changeCurrentDocument(ObjectPtr)));
1138 aObjDock->setWidget(myObjectBrowser);
1140 myContextMenuMgr->connectObjectBrowser();
1144 //******************************************************
1146 * Creates dock widgets, places them in corresponding area
1147 * and tabifies if necessary.
1149 void XGUI_Workshop::createDockWidgets()
1151 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1152 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1153 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1154 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
1155 myPropertyPanel->setupActions(myActionsMgr);
1156 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1157 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1158 hidePropertyPanel(); ///<! Invisible by default
1159 hideObjectBrowser();
1160 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1161 myPropertyPanel->installEventFilter(myOperationMgr);
1163 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1164 connect(aOkAct, SIGNAL(triggered()), myOperationMgr, SLOT(onCommitOperation()));
1165 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1166 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1167 connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets()));
1168 connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)),
1169 myOperationMgr, SLOT(onKeyReleased(QKeyEvent*)));
1170 connect(myOperationMgr, SIGNAL(validationStateChanged(bool)),
1171 aOkAct, SLOT(setEnabled(bool)));
1172 QAction* aAcceptAllAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll);
1173 connect(myOperationMgr, SIGNAL(nestedStateChanged(bool)),
1174 aAcceptAllAct, SLOT(setEnabled(bool)));
1178 //******************************************************
1179 void XGUI_Workshop::showPropertyPanel()
1181 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1182 ///<! Restore ability to close panel from the window's menu
1183 aViewAct->setEnabled(true);
1184 myPropertyPanel->show();
1185 myPropertyPanel->raise();
1188 //******************************************************
1189 void XGUI_Workshop::hidePropertyPanel()
1191 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1192 ///<! Do not allow to show empty property panel
1193 aViewAct->setEnabled(false);
1194 myPropertyPanel->hide();
1197 //******************************************************
1198 void XGUI_Workshop::showObjectBrowser()
1200 myObjectBrowser->parentWidget()->show();
1203 //******************************************************
1204 void XGUI_Workshop::hideObjectBrowser()
1206 myObjectBrowser->parentWidget()->hide();
1209 //******************************************************
1210 void XGUI_Workshop::onFeatureTriggered()
1212 QAction* aCmd = dynamic_cast<QAction*>(sender());
1214 QString aId = salomeConnector()->commandId(aCmd);
1216 myModule->launchOperation(aId);
1220 //******************************************************
1221 void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
1223 SessionPtr aMgr = ModelAPI_Session::get();
1225 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theObj);
1227 DocumentPtr aPartDoc = aPart->partDoc();
1229 aMgr->setActiveDocument(aPartDoc);
1234 aMgr->setActiveDocument(aMgr->moduleDocument());
1237 //******************************************************
1238 void XGUI_Workshop::salomeViewerSelectionChanged()
1240 emit salomeViewerSelection();
1243 //**************************************************************
1244 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1246 return mySalomeConnector->viewer();
1249 //**************************************************************
1250 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1252 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1253 if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) {
1254 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
1255 activatePart(aPart);
1256 } else if (theId == "DEACTIVATE_PART_CMD")
1257 activatePart(ResultPartPtr());
1258 else if (theId == "DELETE_CMD")
1259 deleteObjects(aObjects);
1260 else if (theId == "SHOW_CMD")
1261 showObjects(aObjects, true);
1262 else if (theId == "HIDE_CMD")
1263 showObjects(aObjects, false);
1264 else if (theId == "SHOW_ONLY_CMD")
1265 showOnlyObjects(aObjects);
1266 else if (theId == "SHADING_CMD")
1267 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1268 else if (theId == "WIREFRAME_CMD")
1269 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1270 else if (theId == "HIDEALL_CMD")
1271 myDisplayer->eraseAll();
1272 else if (theId == "EDIT_CMD") {
1273 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObjects.first());
1275 myModule->editFeature(aFeature);
1279 //**************************************************************
1280 void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
1282 if (!myPartActivating) {
1283 myPartActivating = true;
1285 theFeature->activate();
1286 changeCurrentDocument(theFeature);
1287 myObjectBrowser->activatePart(theFeature);
1288 myPartActivating = false;
1290 updateCommandStatus();
1293 //**************************************************************
1294 //void XGUI_Workshop::activateLastPart()
1296 // SessionPtr aMgr = ModelAPI_Session::get();
1297 // DocumentPtr aDoc = aMgr->moduleDocument();
1298 // std::string aGrpName = ModelAPI_ResultPart::group();
1299 // ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
1300 // ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
1302 // activatePart(aPart);
1306 //**************************************************************
1307 void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList)
1309 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1311 std::set<FeaturePtr> aRefFeatures;
1312 foreach (ObjectPtr aObj, theList)
1314 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1316 // TODO: check for what there is this condition. It is placed here historicaly because
1317 // ther is this condition during remove features.
1319 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1320 if (aFeature.get() != NULL) {
1321 aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
1326 if (!aRefFeatures.empty()) {
1327 QStringList aRefNames;
1328 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1329 aLast = aRefFeatures.end();
1330 for (; anIt != aLast; anIt++) {
1331 FeaturePtr aFeature = (*anIt);
1332 std::string aFName = aFeature->data()->name().c_str();
1333 std::string aName = (*anIt)->name().c_str();
1334 aRefNames.append((*anIt)->name().c_str());
1336 QString aNames = aRefNames.join(", ");
1338 QMessageBox::StandardButton aRes = QMessageBox::warning(
1339 aDesktop, tr("Delete features"),
1340 QString(tr("Selected features are used in the following features: %1.\
1341 These features will be deleted also. Would you like to continue?")).arg(aNames),
1342 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1343 if (aRes != QMessageBox::Yes)
1347 SessionPtr aMgr = ModelAPI_Session::get();
1348 aMgr->startOperation("DeleteObjects");
1349 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1350 aLast = aRefFeatures.end();
1351 for (; anIt != aLast; anIt++) {
1352 FeaturePtr aRefFeature = (*anIt);
1353 DocumentPtr aDoc = aRefFeature->document();
1354 aDoc->removeFeature(aRefFeature);
1358 foreach (ObjectPtr aObj, theList)
1360 DocumentPtr aDoc = aObj->document();
1361 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1363 if (aDoc == aMgr->activeDocument()) {
1367 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1369 aDoc->removeFeature(aFeature);
1374 myDisplayer->updateViewer();
1375 aMgr->finishOperation();
1378 //**************************************************************
1379 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1381 foreach (ObjectPtr aObj, theList)
1384 displayObject(aObj);
1386 myDisplayer->erase(aObj, false);
1389 myDisplayer->updateViewer();
1392 //**************************************************************
1393 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1395 myDisplayer->showOnly(theList);
1399 //**************************************************************
1400 void XGUI_Workshop::registerValidators() const
1402 SessionPtr aMgr = ModelAPI_Session::get();
1403 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1406 //**************************************************************
1407 void XGUI_Workshop::displayAllResults()
1409 SessionPtr aMgr = ModelAPI_Session::get();
1410 DocumentPtr aRootDoc = aMgr->moduleDocument();
1411 displayDocumentResults(aRootDoc);
1412 for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1413 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1414 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1415 displayDocumentResults(aPart->partDoc());
1417 myDisplayer->updateViewer();
1420 //**************************************************************
1421 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1425 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1426 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1429 //**************************************************************
1430 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1432 for (int i = 0; i < theDoc->size(theGroup); i++)
1433 displayObject(theDoc->object(theGroup, i));
1436 //**************************************************************
1437 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1439 foreach(ObjectPtr aObj, theList) {
1440 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1442 if (theList.size() > 0)
1443 myDisplayer->updateViewer();
1446 //**************************************************************
1447 void XGUI_Workshop::closeDocument()
1449 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1450 while (anOperation) {
1451 anOperation->abort();
1452 anOperation = operationMgr()->currentOperation();
1454 myDisplayer->closeLocalContexts();
1455 myDisplayer->eraseAll();
1456 objectBrowser()->clearContent();
1458 SessionPtr aMgr = ModelAPI_Session::get();
1460 objectBrowser()->clearContent();
1463 //**************************************************************
1464 void XGUI_Workshop::displayObject(ObjectPtr theObj)
1466 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
1467 if (aBody.get() != NULL) {
1468 int aNb = myDisplayer->objectsCount();
1469 myDisplayer->display(theObj, false);
1473 myDisplayer->display(theObj, false);
1476 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
1478 XGUI_HistoryMenu* aMenu = NULL;
1479 if (isSalomeMode()) {
1480 QAction* anAction = qobject_cast<QAction*>(theObject);
1483 aMenu = new XGUI_HistoryMenu(anAction);
1485 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
1486 aMenu = new XGUI_HistoryMenu(aButton);
1488 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
1489 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);