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>
28 #include <ModuleBase_IModule.h>
29 #include <ModuleBase_Preferences.h>
31 #include <ModelAPI_Events.h>
32 #include <ModelAPI_Session.h>
33 #include <ModelAPI_Feature.h>
34 #include <ModelAPI_Data.h>
35 #include <ModelAPI_AttributeDocRef.h>
36 #include <ModelAPI_Object.h>
37 #include <ModelAPI_Validator.h>
38 #include <ModelAPI_ResultConstruction.h>
39 #include <ModelAPI_ResultBody.h>
41 //#include <PartSetPlugin_Part.h>
43 #include <Events_Loop.h>
44 #include <Events_Error.h>
45 #include <Events_LongOp.h>
47 #include <ModuleBase_Operation.h>
48 #include <ModuleBase_Operation.h>
49 #include <ModuleBase_OperationDescription.h>
50 #include <ModuleBase_SelectionValidator.h>
51 #include <ModuleBase_WidgetFactory.h>
52 #include <ModuleBase_Tools.h>
53 #include <ModuleBase_IViewer.h>
54 #include<ModuleBase_FilterFactory.h>
56 #include <Config_Common.h>
57 #include <Config_FeatureMessage.h>
58 #include <Config_PointerMessage.h>
59 #include <Config_ModuleReader.h>
60 #include <Config_PropManager.h>
61 #include <Config_SelectionFilterMessage.h>
63 #include <QApplication>
64 #include <QFileDialog>
65 #include <QMessageBox>
66 #include <QMdiSubWindow>
67 #include <QPushButton>
68 #include <QDockWidget>
73 #include <QToolButton>
87 QMap<QString, QString> XGUI_Workshop::myIcons;
90 QIcon XGUI_Workshop::featureIcon(const FeaturePtr& theFeature)
94 std::string aKind = theFeature->getKind();
95 QString aId(aKind.c_str());
96 if (!myIcons.contains(aId))
99 QString anIconString = myIcons[aId];
101 ModelAPI_ExecState aState = theFeature->data()->execState();
103 case ModelAPI_StateDone:
104 case ModelAPI_StateNothing: {
105 anIcon = QIcon(anIconString);
108 case ModelAPI_StateMustBeUpdated: {
109 anIcon = ModuleBase_Tools::lighter(anIconString);
112 case ModelAPI_StateExecFailed: {
113 anIcon = ModuleBase_Tools::composite(":pictures/exec_state_failed.png", anIconString);
116 case ModelAPI_StateInvalidArgument: {
117 anIcon = ModuleBase_Tools::composite(":pictures/exec_state_invalid_parameters.png",
126 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
128 myCurrentDir(QString()),
130 mySalomeConnector(theConnector),
134 myUpdatePrefs(false),
135 myPartActivating(false)
137 myMainWindow = mySalomeConnector ? 0 : new AppElements_MainWindow();
139 myDisplayer = new XGUI_Displayer(this);
141 mySelector = new XGUI_SelectionMgr(this);
142 //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
144 myOperationMgr = new XGUI_OperationMgr(this);
145 myActionsMgr = new XGUI_ActionsMgr(this);
146 myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
147 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
148 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
149 SLOT(onContextMenuCommand(const QString&, bool)));
151 myViewerProxy = new XGUI_ViewerProxy(this);
152 connect(myViewerProxy, SIGNAL(selectionChanged()),
153 myActionsMgr, SLOT(updateOnViewSelection()));
155 myModuleConnector = new XGUI_ModuleConnector(this);
157 connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
158 SLOT(onOperationStarted(ModuleBase_Operation*)));
159 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
160 SLOT(onOperationResumed(ModuleBase_Operation*)));
161 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
162 SLOT(onOperationStopped(ModuleBase_Operation*)));
163 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
164 SLOT(onOperationCommitted(ModuleBase_Operation*)));
165 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
166 SLOT(onOperationAborted(ModuleBase_Operation*)));
167 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
168 connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
171 //******************************************************
172 XGUI_Workshop::~XGUI_Workshop(void)
177 //******************************************************
178 void XGUI_Workshop::startApplication()
182 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
183 Config_Prop::Directory, "");
185 //Initialize event listening
186 Events_Loop* aLoop = Events_Loop::loop();
187 aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
188 aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
189 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
190 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
191 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
192 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
193 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
194 aLoop->registerListener(this, Events_LongOp::eventID());
195 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
196 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
197 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOSHOW));
198 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
199 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED));
201 registerValidators();
203 // Calling of loadCustomProps before activating module is required
204 // by Config_PropManger to restore user-defined path to plugins
205 ModuleBase_Preferences::loadCustomProps();
208 myMainWindow->show();
209 updateCommandStatus();
214 emit applicationStarted();
217 //******************************************************
218 void XGUI_Workshop::initMenu()
220 myContextMenuMgr->createActions();
222 if (isSalomeMode()) {
223 // Create only Undo, Redo commands
224 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
225 tr("Undo last command"),
226 QIcon(":pictures/undo.png"),
227 QKeySequence::Undo, false, "MEN_DESK_EDIT");
228 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
229 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
231 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
232 QIcon(":pictures/redo.png"), QKeySequence::Redo,
233 false, "MEN_DESK_EDIT");
234 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
235 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
237 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
238 aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
239 QIcon(":pictures/rebuild.png"), QKeySequence(),
240 false, "MEN_DESK_EDIT");
241 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
242 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
244 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export NewGeom..."), tr("Export the current document into a NewGeom file"),
245 QIcon(), QKeySequence(),
246 false, "MEN_DESK_FILE");
247 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
249 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import NewGeom..."), tr("Import a NewGeom file"),
250 QIcon(), QKeySequence(),
251 false, "MEN_DESK_FILE");
252 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
253 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
257 // File commands group
258 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
260 AppElements_Command* aCommand;
262 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
263 QIcon(":pictures/save.png"), QKeySequence::Save);
264 aCommand->connectTo(this, SLOT(onSave()));
265 //aCommand->disable();
267 QString aUndoId = "UNDO_CMD";
268 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
269 QIcon(":pictures/undo.png"), QKeySequence::Undo);
270 aCommand->connectTo(this, SLOT(onUndo()));
271 QToolButton* aUndoButton = qobject_cast<QToolButton*>(aGroup->widget(aUndoId));
272 addHistoryMenu(aUndoButton,
273 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
276 QString aRedoId = "REDO_CMD";
277 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
278 QIcon(":pictures/redo.png"), QKeySequence::Redo);
279 aCommand->connectTo(this, SLOT(onRedo()));
280 QToolButton* aRedoButton = qobject_cast<QToolButton*>(aGroup->widget(aRedoId));
281 addHistoryMenu(aRedoButton,
282 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
285 aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
286 QIcon(":pictures/rebuild.png"), QKeySequence());
287 aCommand->connectTo(this, SLOT(onRebuild()));
289 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
290 QIcon(":pictures/save.png"), QKeySequence());
291 aCommand->connectTo(this, SLOT(onSaveAs()));
292 //aCommand->disable();
294 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
295 QIcon(":pictures/open.png"), QKeySequence::Open);
296 aCommand->connectTo(this, SLOT(onOpen()));
298 //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
299 // QIcon(":pictures/new.png"), QKeySequence::New);
300 //aCommand->connectTo(this, SLOT(onNew()));
302 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
303 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
304 aCommand->connectTo(this, SLOT(onPreferences()));
306 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
307 QIcon(":pictures/close.png"), QKeySequence::Close);
308 aCommand->connectTo(this, SLOT(onExit()));
309 //FIXME: SBH's test action. Can be used for some GUI tests.
311 // aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
312 // QIcon(":pictures/close.png"), QKeySequence(), true);
313 // aCommand->connectTo(myMainWindow, SLOT(dockPythonConsole()));
317 //******************************************************
318 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
320 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
321 return aMenuBar->addWorkbench(theName);
324 //******************************************************
325 void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessage)
327 if (QApplication::instance()->thread() != QThread::currentThread()) {
329 std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
331 SessionPtr aMgr = ModelAPI_Session::get();
332 PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(theMessage);
333 QApplication::postEvent(this, aPostponeEvent);
337 //A message to start feature creation received.
338 if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
339 std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
340 std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
341 if (!aFeatureMsg->isInternal()) {
342 addFeature(aFeatureMsg);
345 // Process creation of Part
346 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
347 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
348 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
349 onFeatureCreatedMsg(aUpdMsg);
351 if (mySalomeConnector)
352 mySalomeConnector->createPreferences();
353 myUpdatePrefs = false;
356 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
357 myUpdatePrefs = true;
360 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
361 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
362 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
363 onFeatureRedisplayMsg(aUpdMsg);
365 //Update property panel on corresponding message. If there is no current operation (no
366 //property panel), or received message has different feature to the current - do nothing.
367 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
368 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
369 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
370 onFeatureUpdatedMsg(anUpdateMsg);
371 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
372 std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
373 std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
374 onObjectDeletedMsg(aDelMsg);
375 } else if (theMessage->eventID() == Events_LongOp::eventID()) {
376 if (Events_LongOp::isPerformed()) {
377 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
379 QApplication::restoreOverrideCursor();
381 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW)) {
382 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
383 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
384 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
385 QObjectPtrList aList;
386 std::set<ObjectPtr>::const_iterator aIt;
387 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
389 showObjects(aList, true);
390 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE)) {
391 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
392 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
393 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
394 QObjectPtrList aList;
395 std::set<ObjectPtr>::const_iterator aIt;
396 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
398 showObjects(aList, false);
400 //An operation passed by message. Start it, process and commit.
401 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
402 std::shared_ptr<Config_PointerMessage> aPartSetMsg =
403 std::dynamic_pointer_cast<Config_PointerMessage>(theMessage);
404 //myPropertyPanel->cleanContent();
405 ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
407 if (myOperationMgr->startOperation(anOperation)) {
408 myPropertyPanel->updateContentWidget(anOperation->feature());
409 if (!anOperation->getDescription()->hasXmlRepresentation()) {
410 if (anOperation->commit())
411 updateCommandStatus();
414 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
415 myActionsMgr->update();
416 // Find and Activate active part
417 if (myPartActivating)
419 SessionPtr aMgr = ModelAPI_Session::get();
420 DocumentPtr aActiveDoc = aMgr->activeDocument();
421 DocumentPtr aDoc = aMgr->moduleDocument();
422 if (aActiveDoc == aDoc) {
423 activatePart(ResultPartPtr());
426 std::string aGrpName = ModelAPI_ResultPart::group();
427 for (int i = 0; i < aDoc->size(aGrpName); i++) {
428 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
429 if (aPart->partDoc() == aActiveDoc) {
430 activatePart(aPart); // Activate a part which corresponds to active Doc
434 // If not found then activate global document
435 activatePart(ResultPartPtr());
438 else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) {
439 std::shared_ptr<Config_SelectionFilterMessage> aMsg =
440 std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
442 ModuleBase_FilterFactory* aFactory = moduleConnector()->selectionFilters();
443 if (!aMsg->attributeId().empty()) {
444 aFactory->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId(),
452 //Show error dialog if error message received.
453 std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
455 emit errorOccurred(QString::fromLatin1(anAppError->description()));
458 if (!isSalomeMode()) {
459 SessionPtr aMgr = ModelAPI_Session::get();
460 if (aMgr->isModified() != myMainWindow->isModifiedState())
461 myMainWindow->setModifiedState(aMgr->isModified());
465 //******************************************************
466 QMainWindow* XGUI_Workshop::desktop() const
468 return isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
471 //******************************************************
472 void XGUI_Workshop::onStartWaiting()
474 if (Events_LongOp::isPerformed()) {
475 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
479 //******************************************************
480 void XGUI_Workshop::onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
482 std::set<ObjectPtr> aFeatures = theMsg->objects();
483 if (myOperationMgr->hasOperation()) {
484 FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
485 std::set<ObjectPtr>::const_iterator aIt;
486 for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
487 ObjectPtr aNewFeature = (*aIt);
488 if (aNewFeature == aCurrentFeature) {
489 myPropertyPanel->updateContentWidget(aCurrentFeature);
494 myOperationMgr->onValidateOperation();
496 myObjectBrowser->processEvent(theMsg);
499 //******************************************************
500 void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
502 std::set<ObjectPtr> aObjects = theMsg->objects();
503 std::set<ObjectPtr>::const_iterator aIt;
504 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
505 ObjectPtr aObj = (*aIt);
507 bool aHide = !aObj->data() || !aObj->data()->isValid();
508 if (!aHide) { // check that this is not hidden result
509 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
510 aHide = aRes && aRes->isConcealed();
513 myDisplayer->erase(aObj, false);
515 if (myDisplayer->isVisible(aObj)) {
516 displayObject(aObj); // In order to update presentation
517 if (myOperationMgr->hasOperation()) {
518 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
519 if (!aOperation->isEditOperation() &&
520 aOperation->hasObject(aObj) && myDisplayer->isActive(aObj))
521 myDisplayer->deactivate(aObj);
524 if (myOperationMgr->hasOperation()) {
525 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
526 if (myModule->canDisplayObject(aObj)) {
528 // Deactivate object of current operation from selection
529 if (myDisplayer->isActive(aObj))
530 myDisplayer->deactivate(aObj);
536 myDisplayer->updateViewer();
539 //******************************************************
540 void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
542 std::set<ObjectPtr> aObjects = theMsg->objects();
544 std::set<ObjectPtr>::const_iterator aIt;
545 bool aHasPart = false;
546 bool isDisplayed = false;
547 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
549 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
552 // If a feature is created from the aplication's python console
553 // it doesn't stored in the operation mgr and doesn't displayed
554 } else if (myModule->canDisplayObject(*aIt)) {
560 myObjectBrowser->processEvent(theMsg);
562 myDisplayer->updateViewer();
563 //if (aHasPart) { // TODO: Avoid activate last part on loading of document
564 // activateLastPart();
568 //******************************************************
569 void XGUI_Workshop::onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg)
572 myObjectBrowser->processEvent(theMsg);
573 //std::set<ObjectPtr> aFeatures = theMsg->objects();
576 //******************************************************
577 void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
579 setNestedFeatures(theOperation);
581 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
582 connectWithOperation(theOperation);
583 setPropertyPanel(theOperation);
585 updateCommandStatus();
587 myModule->operationStarted(theOperation);
590 //******************************************************
591 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
593 setNestedFeatures(theOperation);
595 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
596 // connectWithOperation(theOperation); already connected
597 setPropertyPanel(theOperation);
599 updateCommandStatus();
601 myModule->operationResumed(theOperation);
605 //******************************************************
606 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
608 ModuleBase_ISelection* aSel = mySelector->selection();
609 QObjectPtrList aObj = aSel->selectedPresentations();
610 //!< No need for property panel
611 updateCommandStatus();
613 myPropertyPanel->cleanContent();
615 // Activate objects created by current operation
616 // in order to clean selection modes
618 myDisplayer->activateObjects(aModes);
619 myModule->operationStopped(theOperation);
623 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
625 myModule->operationCommitted(theOperation);
628 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
630 myModule->operationAborted(theOperation);
633 void XGUI_Workshop::setNestedFeatures(ModuleBase_Operation* theOperation)
635 if (this->isSalomeMode())
636 theOperation->setNestedFeatures(mySalomeConnector->nestedActions(theOperation->id()));
638 theOperation->setNestedFeatures(myActionsMgr->nestedCommands(theOperation->id()));
641 void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
644 QString aXmlRepr = theOperation->getDescription()->xmlRepresentation();
645 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
648 myPropertyPanel->cleanContent();
649 aFactory.createWidget(myPropertyPanel->contentWidget());
650 ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget());
652 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
653 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
654 bool isStoreValue = !theOperation->isEditOperation() &&
655 aWidget->isValueDefault() && !aWidget->isComputedDefault();
656 aWidget->setFeature(theOperation->feature(), isStoreValue);
657 aWidget->enableFocusProcessing();
660 myPropertyPanel->setModelWidgets(aWidgets);
661 theOperation->setPropertyPanel(myPropertyPanel);
663 myModule->propertyPanelDefined(theOperation);
665 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
668 bool XGUI_Workshop::event(QEvent * theEvent)
670 PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
672 std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
673 processEvent(aEventPtr);
682 void XGUI_Workshop::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
686 qDebug() << "XGUI_Workshop::addFeature: NULL message.";
690 ActionInfo aFeatureInfo;
691 aFeatureInfo.initFrom(theMessage);
692 // Remember features icons
693 myIcons[QString::fromStdString(theMessage->id())] = aFeatureInfo.iconFile;
695 QString aWchName = QString::fromStdString(theMessage->workbenchId());
696 QStringList aNestedFeatures =
697 QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
698 QString aDocKind = QString::fromStdString(theMessage->documentKind());
699 if (isSalomeMode()) {
700 QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureInfo);
701 salomeConnector()->setNestedActions(aFeatureInfo.id, aNestedFeatures);
702 salomeConnector()->setDocumentKind(aFeatureInfo.id, aDocKind);
704 myActionsMgr->addCommand(aAction);
705 myModule->actionCreated(aAction);
707 //Find or create Workbench
708 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
709 AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
711 aPage = addWorkbench(aWchName);
713 //Find or create Group
714 QString aGroupName = QString::fromStdString(theMessage->groupId());
715 AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
717 aGroup = aPage->addGroup(aGroupName);
719 // Check if hotkey sequence is already defined:
720 QKeySequence aHotKey = myActionsMgr->registerShortcut(aFeatureInfo.shortcut);
721 if(aHotKey != aFeatureInfo.shortcut) {
722 aFeatureInfo.shortcut = aHotKey;
725 AppElements_Command* aCommand = aGroup->addFeature(aFeatureInfo, aDocKind);
726 aCommand->setNestedCommands(aNestedFeatures);
727 myActionsMgr->addCommand(aCommand);
728 myModule->actionCreated(aCommand);
733 * Makes a signal/slot connections between Property Panel
734 * and given operation. The given operation becomes a
735 * current operation and previous operation if exists
737 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
739 QAction* aCommand = 0;
740 if (isSalomeMode()) {
741 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
743 AppElements_MainMenu* aMenu = myMainWindow->menuObject();
744 FeaturePtr aFeature = theOperation->feature();
746 aCommand = aMenu->feature(QString::fromStdString(aFeature->getKind()));
748 //Abort operation on uncheck the command
750 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
755 * Saves document with given name.
757 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
759 QApplication::restoreOverrideCursor();
760 SessionPtr aMgr = ModelAPI_Session::get();
761 aMgr->save(theName.toLatin1().constData(), theFileNames);
762 QApplication::restoreOverrideCursor();
765 bool XGUI_Workshop::isActiveOperationAborted()
767 return myOperationMgr->abortAllOperations();
770 //******************************************************
771 void XGUI_Workshop::onExit()
773 SessionPtr aMgr = ModelAPI_Session::get();
774 if (aMgr->isModified()) {
775 int anAnswer = QMessageBox::question(
776 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
777 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
778 if (anAnswer == QMessageBox::Save) {
779 bool saved = onSave();
783 } else if (anAnswer == QMessageBox::Cancel) {
790 //******************************************************
791 void XGUI_Workshop::onNew()
793 QApplication::setOverrideCursor(Qt::WaitCursor);
794 if (objectBrowser() == 0) {
796 mySelector->connectViewers();
798 myViewerProxy->connectToViewer();
800 if (!isSalomeMode()) {
801 myMainWindow->showPythonConsole();
802 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
803 aWnd->showMaximized();
804 updateCommandStatus();
806 myContextMenuMgr->connectViewer();
807 QApplication::restoreOverrideCursor();
810 //******************************************************
811 void XGUI_Workshop::onOpen()
813 if(!isActiveOperationAborted())
815 //save current file before close if modified
816 SessionPtr aSession = ModelAPI_Session::get();
817 if (aSession->isModified()) {
818 //TODO(sbh): re-launch the app?
819 int anAnswer = QMessageBox::question(
820 myMainWindow, tr("Save current file"),
821 tr("The document is modified, save before opening another?"),
822 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
823 if (anAnswer == QMessageBox::Save) {
825 } else if (anAnswer == QMessageBox::Cancel) {
828 aSession->closeAll();
832 //show file dialog, check if readable and open
833 myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
834 if (myCurrentDir.isEmpty())
836 QFileInfo aFileInfo(myCurrentDir);
837 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
838 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
842 QApplication::setOverrideCursor(Qt::WaitCursor);
843 aSession->load(myCurrentDir.toLatin1().constData());
844 myObjectBrowser->rebuildDataTree();
846 updateCommandStatus();
847 QApplication::restoreOverrideCursor();
850 //******************************************************
851 bool XGUI_Workshop::onSave()
853 if(!isActiveOperationAborted())
855 if (myCurrentDir.isEmpty()) {
858 std::list<std::string> aFiles;
859 saveDocument(myCurrentDir, aFiles);
860 updateCommandStatus();
862 myMainWindow->setModifiedState(false);
866 //******************************************************
867 bool XGUI_Workshop::onSaveAs()
869 if(!isActiveOperationAborted())
871 QFileDialog dialog(mainWindow());
872 dialog.setWindowTitle(tr("Select directory to save files..."));
873 dialog.setFileMode(QFileDialog::Directory);
874 dialog.setFilter(tr("Folders (*)"));
875 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
876 dialog.setViewMode(QFileDialog::Detail);
878 if (!dialog.exec()) {
881 QString aTempDir = dialog.selectedFiles().first();
883 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
884 int answer = QMessageBox::question(
886 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
888 tr("The folder already contains some files, save anyway?"),
889 QMessageBox::Save | QMessageBox::Cancel);
890 if (answer == QMessageBox::Cancel) {
894 myCurrentDir = aTempDir;
895 if (!isSalomeMode()) {
896 myMainWindow->setCurrentDir(myCurrentDir, false);
897 myMainWindow->setModifiedState(false);
902 //******************************************************
903 void XGUI_Workshop::onUndo(int theTimes)
905 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
906 SessionPtr aMgr = ModelAPI_Session::get();
907 if (aMgr->isOperation())
908 operationMgr()->onAbortOperation();
909 for (int i = 0; i < theTimes; ++i) {
912 updateCommandStatus();
915 //******************************************************
916 void XGUI_Workshop::onRedo(int theTimes)
918 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
919 SessionPtr aMgr = ModelAPI_Session::get();
920 if (aMgr->isOperation())
921 operationMgr()->onAbortOperation();
922 for (int i = 0; i < theTimes; ++i) {
925 updateCommandStatus();
928 //******************************************************
929 void XGUI_Workshop::onRebuild()
931 SessionPtr aMgr = ModelAPI_Session::get();
932 bool aWasOperation = aMgr->isOperation(); // keep this value
933 if (!aWasOperation) {
934 aMgr->startOperation("Rebuild");
936 static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
937 Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
938 new Events_Message(aRebuildEvent, this)));
939 if (!aWasOperation) {
940 aMgr->finishOperation();
944 //******************************************************
945 void XGUI_Workshop::onPreferences()
947 ModuleBase_Prefs aModif;
948 ModuleBase_Preferences::editPreferences(aModif);
949 if (aModif.size() > 0) {
951 foreach (ModuleBase_Pref aPref, aModif)
953 aSection = aPref.first;
954 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
956 myMainWindow->viewer()->updateFromResources();
957 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
959 myMainWindow->menuObject()->updateFromResources();
965 //******************************************************
966 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
968 QString libName = QString::fromStdString(library(theModule.toStdString()));
969 if (libName.isEmpty()) {
970 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
975 CREATE_FUNC crtInst = 0;
978 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
982 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
983 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
984 QString aMsg((char*) &lpMsgBuf);
985 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
986 ::LocalFree(lpMsgBuf);
988 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
992 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
993 | FORMAT_MESSAGE_IGNORE_INSERTS,
994 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
995 QString aMsg((char*) &lpMsgBuf);
996 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
997 ::LocalFree(lpMsgBuf);
1001 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1003 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1005 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1007 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1012 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1014 if (!err.isEmpty()) {
1016 Events_Error::send(err.toStdString());
1018 qWarning(qPrintable(err));
1024 //******************************************************
1025 bool XGUI_Workshop::activateModule()
1027 Config_ModuleReader aModuleReader;
1028 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1029 myModule = loadModule(moduleName);
1032 myModule->createFeatures();
1033 myActionsMgr->update();
1037 //******************************************************
1038 void XGUI_Workshop::updateCommandStatus()
1040 QList<QAction*> aCommands;
1041 if (isSalomeMode()) { // update commands in SALOME mode
1042 aCommands = salomeConnector()->commandList();
1044 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1045 foreach (AppElements_Command* aCmd, aMenuBar->features())
1046 aCommands.append(aCmd);
1048 SessionPtr aMgr = ModelAPI_Session::get();
1049 if (aMgr->hasModuleDocument()) {
1050 QAction *aUndoCmd, *aRedoCmd;
1051 foreach(QAction* aCmd, aCommands) {
1052 QString aId = aCmd->data().toString();
1053 if (aId == "UNDO_CMD")
1055 else if (aId == "REDO_CMD")
1058 // Enable all commands
1059 aCmd->setEnabled(true);
1061 aUndoCmd->setEnabled(aMgr->canUndo() && !aMgr->isOperation());
1062 aRedoCmd->setEnabled(aMgr->canRedo() && !aMgr->isOperation());
1067 foreach(QAction* aCmd, aCommands) {
1068 QString aId = aCmd->data().toString();
1069 if (aId == "NEW_CMD")
1070 aCmd->setEnabled(true);
1071 else if (aId == "EXIT_CMD")
1072 aCmd->setEnabled(true);
1074 aCmd->setEnabled(false);
1077 myActionsMgr->update();
1078 emit commandStatusUpdated();
1081 void XGUI_Workshop::updateHistory()
1083 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1084 std::list<std::string>::iterator it = aUndoList.begin();
1085 QList<ActionInfo> aUndoRes;
1086 for ( ; it != aUndoList.end(); it++) {
1087 QString anId = QString::fromStdString(*it);
1089 if (myIcons.contains(anId))
1090 aIcon = QIcon(myIcons[anId]);
1091 aUndoRes << ActionInfo(aIcon, anId);
1093 emit updateUndoHistory(aUndoRes);
1095 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1096 it = aRedoList.begin();
1097 QList<ActionInfo> aRedoRes;
1098 for ( ; it != aRedoList.end(); it++) {
1099 QString anId = QString::fromStdString(*it);
1101 if (myIcons.contains(anId))
1102 aIcon = QIcon(myIcons[anId]);
1103 aRedoRes << ActionInfo(aIcon, anId);
1105 emit updateRedoHistory(aUndoRes);
1108 //******************************************************
1109 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1111 QDockWidget* aObjDock = new QDockWidget(theParent);
1112 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1113 aObjDock->setWindowTitle(tr("Object browser"));
1114 aObjDock->setStyleSheet(
1115 "::title { position: relative; padding-left: 5px; text-align: left center }");
1116 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1117 connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this,
1118 SLOT(changeCurrentDocument(ObjectPtr)));
1119 aObjDock->setWidget(myObjectBrowser);
1121 myContextMenuMgr->connectObjectBrowser();
1125 //******************************************************
1127 * Creates dock widgets, places them in corresponding area
1128 * and tabifies if necessary.
1130 void XGUI_Workshop::createDockWidgets()
1132 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1133 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1134 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1135 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
1136 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1138 connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets()));
1140 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1141 hidePropertyPanel(); ///<! Invisible by default
1142 hideObjectBrowser();
1143 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1144 myPropertyPanel->installEventFilter(myOperationMgr);
1146 QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(PROP_PANEL_OK);
1147 connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
1148 QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(PROP_PANEL_CANCEL);
1149 connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
1150 connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr,
1151 SLOT(onKeyReleased(QKeyEvent*)));
1152 connect(myOperationMgr, SIGNAL(applyEnableChanged(bool)), myPropertyPanel,
1153 SLOT(setAcceptEnabled(bool)));
1157 //******************************************************
1158 void XGUI_Workshop::showPropertyPanel()
1160 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1161 ///<! Restore ability to close panel from the window's menu
1162 aViewAct->setEnabled(true);
1163 myPropertyPanel->show();
1164 myPropertyPanel->raise();
1167 //******************************************************
1168 void XGUI_Workshop::hidePropertyPanel()
1170 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1171 ///<! Do not allow to show empty property panel
1172 aViewAct->setEnabled(false);
1173 myPropertyPanel->hide();
1176 //******************************************************
1177 void XGUI_Workshop::showObjectBrowser()
1179 myObjectBrowser->parentWidget()->show();
1182 //******************************************************
1183 void XGUI_Workshop::hideObjectBrowser()
1185 myObjectBrowser->parentWidget()->hide();
1188 //******************************************************
1189 void XGUI_Workshop::onFeatureTriggered()
1191 QAction* aCmd = dynamic_cast<QAction*>(sender());
1193 QString aId = salomeConnector()->commandId(aCmd);
1195 myModule->launchOperation(aId);
1199 //******************************************************
1200 void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
1202 SessionPtr aMgr = ModelAPI_Session::get();
1204 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theObj);
1206 DocumentPtr aPartDoc = aPart->partDoc();
1208 aMgr->setActiveDocument(aPartDoc);
1213 aMgr->setActiveDocument(aMgr->moduleDocument());
1216 //******************************************************
1217 void XGUI_Workshop::salomeViewerSelectionChanged()
1219 emit salomeViewerSelection();
1222 //**************************************************************
1223 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1225 return mySalomeConnector->viewer();
1228 //**************************************************************
1229 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1231 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1232 if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) {
1233 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
1234 activatePart(aPart);
1235 } else if (theId == "DEACTIVATE_PART_CMD")
1236 activatePart(ResultPartPtr());
1237 else if (theId == "DELETE_CMD")
1238 deleteObjects(aObjects);
1239 else if (theId == "SHOW_CMD")
1240 showObjects(aObjects, true);
1241 else if (theId == "HIDE_CMD")
1242 showObjects(aObjects, false);
1243 else if (theId == "SHOW_ONLY_CMD")
1244 showOnlyObjects(aObjects);
1245 else if (theId == "SHADING_CMD")
1246 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1247 else if (theId == "WIREFRAME_CMD")
1248 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1249 else if (theId == "HIDEALL_CMD")
1250 myDisplayer->eraseAll();
1251 else if (theId == "EDIT_CMD") {
1252 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObjects.first());
1254 myModule->editFeature(aFeature);
1258 //**************************************************************
1259 void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
1261 if (!myPartActivating) {
1262 myPartActivating = true;
1264 theFeature->activate();
1265 changeCurrentDocument(theFeature);
1266 myObjectBrowser->activatePart(theFeature);
1267 myPartActivating = false;
1269 updateCommandStatus();
1272 //**************************************************************
1273 //void XGUI_Workshop::activateLastPart()
1275 // SessionPtr aMgr = ModelAPI_Session::get();
1276 // DocumentPtr aDoc = aMgr->moduleDocument();
1277 // std::string aGrpName = ModelAPI_ResultPart::group();
1278 // ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
1279 // ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
1281 // activatePart(aPart);
1285 //**************************************************************
1286 void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList)
1288 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1290 std::set<FeaturePtr> aRefFeatures;
1291 foreach (ObjectPtr aObj, theList)
1293 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1295 // TODO: check for what there is this condition. It is placed here historicaly because
1296 // ther is this condition during remove features.
1298 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1299 if (aFeature.get() != NULL) {
1300 aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
1305 if (!aRefFeatures.empty()) {
1306 QStringList aRefNames;
1307 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1308 aLast = aRefFeatures.end();
1309 for (; anIt != aLast; anIt++) {
1310 FeaturePtr aFeature = (*anIt);
1311 std::string aFName = aFeature->data()->name().c_str();
1312 std::string aName = (*anIt)->name().c_str();
1313 aRefNames.append((*anIt)->name().c_str());
1315 QString aNames = aRefNames.join(", ");
1317 QMessageBox::StandardButton aRes = QMessageBox::warning(
1318 aDesktop, tr("Delete features"),
1319 QString(tr("Selected features are used in the following features: %1.\
1320 These features will be deleted also. Would you like to continue?")).arg(aNames),
1321 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1322 if (aRes != QMessageBox::Yes)
1326 SessionPtr aMgr = ModelAPI_Session::get();
1327 aMgr->startOperation("DeleteObjects");
1328 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1329 aLast = aRefFeatures.end();
1330 for (; anIt != aLast; anIt++) {
1331 FeaturePtr aRefFeature = (*anIt);
1332 DocumentPtr aDoc = aRefFeature->document();
1333 aDoc->removeFeature(aRefFeature);
1337 foreach (ObjectPtr aObj, theList)
1339 DocumentPtr aDoc = aObj->document();
1340 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1342 if (aDoc == aMgr->activeDocument()) {
1346 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1348 aDoc->removeFeature(aFeature);
1353 myDisplayer->updateViewer();
1354 aMgr->finishOperation();
1357 //**************************************************************
1358 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1360 foreach (ObjectPtr aObj, theList)
1363 displayObject(aObj);
1365 myDisplayer->erase(aObj, false);
1368 myDisplayer->updateViewer();
1371 //**************************************************************
1372 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1374 myDisplayer->showOnly(theList);
1378 //**************************************************************
1379 void XGUI_Workshop::registerValidators() const
1381 SessionPtr aMgr = ModelAPI_Session::get();
1382 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1385 //**************************************************************
1386 void XGUI_Workshop::displayAllResults()
1388 SessionPtr aMgr = ModelAPI_Session::get();
1389 DocumentPtr aRootDoc = aMgr->moduleDocument();
1390 displayDocumentResults(aRootDoc);
1391 for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1392 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1393 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1394 displayDocumentResults(aPart->partDoc());
1396 myDisplayer->updateViewer();
1399 //**************************************************************
1400 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1404 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1405 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1408 //**************************************************************
1409 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1411 for (int i = 0; i < theDoc->size(theGroup); i++)
1412 displayObject(theDoc->object(theGroup, i));
1415 //**************************************************************
1416 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1418 foreach(ObjectPtr aObj, theList) {
1419 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1421 if (theList.size() > 0)
1422 myDisplayer->updateViewer();
1425 //**************************************************************
1426 void XGUI_Workshop::closeDocument()
1428 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1429 while (anOperation) {
1430 anOperation->abort();
1431 anOperation = operationMgr()->currentOperation();
1433 myDisplayer->closeLocalContexts();
1434 myDisplayer->eraseAll();
1435 objectBrowser()->clearContent();
1437 SessionPtr aMgr = ModelAPI_Session::get();
1439 objectBrowser()->clearContent();
1442 //**************************************************************
1443 void XGUI_Workshop::displayObject(ObjectPtr theObj)
1445 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
1446 if (aBody.get() != NULL) {
1447 int aNb = myDisplayer->objectsCount();
1448 myDisplayer->display(theObj, false);
1452 myDisplayer->display(theObj, false);
1455 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
1457 XGUI_HistoryMenu* aMenu = NULL;
1458 if (isSalomeMode()) {
1459 QAction* anAction = qobject_cast<QAction*>(theObject);
1462 aMenu = new XGUI_HistoryMenu(anAction);
1464 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
1465 aMenu = new XGUI_HistoryMenu(aButton);
1467 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
1468 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);