1 //#include "XGUI_Constants.h"
2 #include "XGUI_Tools.h"
3 #include "XGUI_Workshop.h"
4 #include "XGUI_SelectionMgr.h"
5 #include "XGUI_Selection.h"
6 #include "XGUI_ObjectsBrowser.h"
7 #include "XGUI_Displayer.h"
8 #include "XGUI_OperationMgr.h"
9 #include "XGUI_SalomeConnector.h"
10 #include "XGUI_ActionsMgr.h"
11 #include "XGUI_ErrorDialog.h"
12 #include "XGUI_ViewerProxy.h"
13 #include "XGUI_PropertyPanel.h"
14 #include "XGUI_ContextMenuMgr.h"
15 #include "XGUI_ModuleConnector.h"
16 #include <XGUI_QtEvents.h>
18 #include <AppElements_Workbench.h>
19 #include <AppElements_Viewer.h>
20 #include <AppElements_Command.h>
21 #include <AppElements_MainMenu.h>
22 #include <AppElements_MainWindow.h>
23 #include <AppElements_MenuGroupPanel.h>
25 #include <ModuleBase_IModule.h>
26 #include <ModuleBase_Preferences.h>
28 #include <ModelAPI_Events.h>
29 #include <ModelAPI_Session.h>
30 #include <ModelAPI_Feature.h>
31 #include <ModelAPI_Data.h>
32 #include <ModelAPI_AttributeDocRef.h>
33 #include <ModelAPI_Object.h>
34 #include <ModelAPI_Validator.h>
35 #include <ModelAPI_ResultConstruction.h>
36 #include <ModelAPI_ResultBody.h>
38 //#include <PartSetPlugin_Part.h>
40 #include <Events_Loop.h>
41 #include <Events_Error.h>
42 #include <Events_LongOp.h>
44 #include <ModuleBase_Operation.h>
45 #include <ModuleBase_Operation.h>
46 #include <ModuleBase_OperationDescription.h>
47 #include <ModuleBase_SelectionValidator.h>
48 #include <ModuleBase_WidgetFactory.h>
49 #include <ModuleBase_Tools.h>
50 #include <ModuleBase_IViewer.h>
51 #include<ModuleBase_FilterFactory.h>
53 #include <Config_Common.h>
54 #include <Config_FeatureMessage.h>
55 #include <Config_PointerMessage.h>
56 #include <Config_ModuleReader.h>
57 #include <Config_PropManager.h>
58 #include <Config_SelectionFilterMessage.h>
60 #include <QApplication>
61 #include <QFileDialog>
62 #include <QMessageBox>
63 #include <QMdiSubWindow>
64 #include <QPushButton>
65 #include <QDockWidget>
81 QMap<QString, QString> XGUI_Workshop::myIcons;
84 QIcon XGUI_Workshop::featureIcon(const FeaturePtr& theFeature)
88 std::string aKind = theFeature->getKind();
89 QString aId(aKind.c_str());
90 if (!myIcons.contains(aId))
93 QString anIconString = myIcons[aId];
95 ModelAPI_ExecState aState = theFeature->data()->execState();
97 case ModelAPI_StateDone:
98 case ModelAPI_StateNothing:
99 anIcon = QIcon(anIconString);
100 case ModelAPI_StateMustBeUpdated: {
101 anIcon = ModuleBase_Tools::lighter(anIconString);
104 case ModelAPI_StateExecFailed: {
105 anIcon = ModuleBase_Tools::composite(":pictures/exec_state_failed.png", anIconString);
108 case ModelAPI_StateInvalidArgument: {
109 anIcon = ModuleBase_Tools::composite(":pictures/exec_state_invalid_parameters.png",
118 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
120 myCurrentDir(QString()),
122 mySalomeConnector(theConnector),
126 myUpdatePrefs(false),
127 myPartActivating(false)
129 myMainWindow = mySalomeConnector ? 0 : new AppElements_MainWindow();
131 myDisplayer = new XGUI_Displayer(this);
133 mySelector = new XGUI_SelectionMgr(this);
134 //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
136 myOperationMgr = new XGUI_OperationMgr(this);
137 myActionsMgr = new XGUI_ActionsMgr(this);
138 myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
139 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
140 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
141 SLOT(onContextMenuCommand(const QString&, bool)));
143 myViewerProxy = new XGUI_ViewerProxy(this);
144 connect(myViewerProxy, SIGNAL(selectionChanged()), this, SLOT(updateCommandsOnViewSelection()));
146 myModuleConnector = new XGUI_ModuleConnector(this);
148 connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
149 SLOT(onOperationStarted()));
150 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)), SLOT(onOperationStarted()));
151 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
152 SLOT(onOperationStopped(ModuleBase_Operation*)));
153 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
154 // TODO(sbh): It seems that application works properly without update on operationStarted
155 connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
156 myActionsMgr, SLOT(update()));
157 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
158 myActionsMgr, SLOT(update()));
159 connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
162 //******************************************************
163 XGUI_Workshop::~XGUI_Workshop(void)
168 //******************************************************
169 void XGUI_Workshop::startApplication()
173 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
174 Config_Prop::Directory, "");
176 //Initialize event listening
177 Events_Loop* aLoop = Events_Loop::loop();
178 aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
179 aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
180 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
181 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
182 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
183 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
184 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
185 aLoop->registerListener(this, Events_Loop::eventByName("LongOperation"));
186 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
187 aLoop->registerListener(this, Events_Loop::eventByName("CurrentDocumentChanged"));
188 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOSHOW));
189 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
190 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED));
192 registerValidators();
194 // Calling of loadCustomProps before activating module is required
195 // by Config_PropManger to restore user-defined path to plugins
196 ModuleBase_Preferences::loadCustomProps();
199 myMainWindow->show();
200 updateCommandStatus();
206 //******************************************************
207 void XGUI_Workshop::initMenu()
209 myContextMenuMgr->createActions();
211 if (isSalomeMode()) {
212 // Create only Undo, Redo commands
213 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
214 tr("Undo last command"),
215 QIcon(":pictures/undo.png"),
216 QKeySequence::Undo, false, "MEN_DESK_EDIT");
217 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
218 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
219 QIcon(":pictures/redo.png"), QKeySequence::Redo,
220 false, "MEN_DESK_EDIT");
221 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
222 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
223 aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
224 QIcon(":pictures/rebuild.png"), QKeySequence(),
225 false, "MEN_DESK_EDIT");
226 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
227 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
229 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export NewGeom..."), tr("Export the current document into a NewGeom file"),
230 QIcon(), QKeySequence(),
231 false, "MEN_DESK_FILE");
232 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
234 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import NewGeom..."), tr("Import a NewGeom file"),
235 QIcon(), QKeySequence(),
236 false, "MEN_DESK_FILE");
237 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
238 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
242 // File commands group
243 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
245 AppElements_Command* aCommand;
247 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
248 QIcon(":pictures/save.png"), QKeySequence::Save);
249 aCommand->connectTo(this, SLOT(onSave()));
250 //aCommand->disable();
252 aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
253 QIcon(":pictures/undo.png"), QKeySequence::Undo);
254 aCommand->connectTo(this, SLOT(onUndo()));
256 aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
257 QIcon(":pictures/redo.png"), QKeySequence::Redo);
258 aCommand->connectTo(this, SLOT(onRedo()));
260 aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
261 QIcon(":pictures/rebuild.png"), QKeySequence());
262 aCommand->connectTo(this, SLOT(onRebuild()));
264 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
265 QIcon(":pictures/save.png"), QKeySequence());
266 aCommand->connectTo(this, SLOT(onSaveAs()));
267 //aCommand->disable();
269 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
270 QIcon(":pictures/open.png"), QKeySequence::Open);
271 aCommand->connectTo(this, SLOT(onOpen()));
273 //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
274 // QIcon(":pictures/new.png"), QKeySequence::New);
275 //aCommand->connectTo(this, SLOT(onNew()));
277 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
278 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
279 aCommand->connectTo(this, SLOT(onPreferences()));
281 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
282 QIcon(":pictures/close.png"), QKeySequence::Close);
283 aCommand->connectTo(this, SLOT(onExit()));
284 //FIXME: SBH's test action. Can be used for some GUI tests.
286 // aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
287 // QIcon(":pictures/close.png"), QKeySequence(), true);
288 // aCommand->connectTo(myMainWindow, SLOT(dockPythonConsole()));
292 //******************************************************
293 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
295 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
296 return aMenuBar->addWorkbench(theName);
299 //******************************************************
300 void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessage)
302 if (QApplication::instance()->thread() != QThread::currentThread()) {
304 std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
306 SessionPtr aMgr = ModelAPI_Session::get();
307 PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(theMessage);
308 QApplication::postEvent(this, aPostponeEvent);
312 //A message to start feature creation received.
313 if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
314 std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
315 std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
316 if (!aFeatureMsg->isInternal()) {
317 addFeature(aFeatureMsg);
321 // Process creation of Part
322 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
323 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
324 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
325 onFeatureCreatedMsg(aUpdMsg);
327 if (mySalomeConnector)
328 mySalomeConnector->createPreferences();
329 myUpdatePrefs = false;
332 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
333 myUpdatePrefs = true;
337 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
338 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
339 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
340 onFeatureRedisplayMsg(aUpdMsg);
343 //Update property panel on corresponding message. If there is no current operation (no
344 //property panel), or received message has different feature to the current - do nothing.
345 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
346 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
347 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
348 onFeatureUpdatedMsg(anUpdateMsg);
351 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
352 std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
353 std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
354 onObjectDeletedMsg(aDelMsg);
357 else if (theMessage->eventID() == Events_LongOp::eventID()) {
358 if (Events_LongOp::isPerformed())
359 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
361 QApplication::restoreOverrideCursor();
364 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW)) {
365 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
366 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
367 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
368 QObjectPtrList aList;
369 std::set<ObjectPtr>::const_iterator aIt;
370 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
372 showObjects(aList, true);
375 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE)) {
376 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
377 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
378 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
379 QObjectPtrList aList;
380 std::set<ObjectPtr>::const_iterator aIt;
381 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
383 showObjects(aList, false);
386 //An operation passed by message. Start it, process and commit.
387 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
388 std::shared_ptr<Config_PointerMessage> aPartSetMsg =
389 std::dynamic_pointer_cast<Config_PointerMessage>(theMessage);
390 //myPropertyPanel->cleanContent();
391 ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
393 if (myOperationMgr->startOperation(anOperation)) {
394 myPropertyPanel->updateContentWidget(anOperation->feature());
395 if (!anOperation->getDescription()->hasXmlRepresentation()) {
396 if (anOperation->commit())
397 updateCommandStatus();
401 else if (theMessage->eventID() == Events_Loop::loop()->eventByName("CurrentDocumentChanged")) {
402 myActionsMgr->update();
403 // Find and Activate active part
404 if (myPartActivating)
406 SessionPtr aMgr = ModelAPI_Session::get();
407 DocumentPtr aActiveDoc = aMgr->activeDocument();
408 DocumentPtr aDoc = aMgr->moduleDocument();
409 if (aActiveDoc == aDoc) {
410 activatePart(ResultPartPtr());
413 std::string aGrpName = ModelAPI_ResultPart::group();
414 for (int i = 0; i < aDoc->size(aGrpName); i++) {
415 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
416 if (aPart->partDoc() == aActiveDoc) {
417 activatePart(aPart); // Activate a part which corresponds to active Doc
421 // If not found then activate global document
422 activatePart(ResultPartPtr());
425 else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) {
426 std::shared_ptr<Config_SelectionFilterMessage> aMsg =
427 std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
429 if (aMsg->attributeId().empty()) { // feature validator
430 moduleConnector()->selectionFilters()->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId());
431 } else { // attribute validator
432 moduleConnector()->selectionFilters()->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId());
439 //Show error dialog if error message received.
440 std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
442 emit errorOccurred(QString::fromLatin1(anAppError->description()));
445 if (!isSalomeMode()) {
446 SessionPtr aMgr = ModelAPI_Session::get();
447 if (aMgr->isModified() != myMainWindow->isModifiedState())
448 myMainWindow->setModifiedState(aMgr->isModified());
453 //******************************************************
454 void XGUI_Workshop::onStartWaiting()
456 if (Events_LongOp::isPerformed()) {
457 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
461 //******************************************************
462 void XGUI_Workshop::onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
464 std::set<ObjectPtr> aFeatures = theMsg->objects();
465 if (myOperationMgr->hasOperation()) {
466 FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
467 std::set<ObjectPtr>::const_iterator aIt;
468 for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
469 ObjectPtr aNewFeature = (*aIt);
470 if (aNewFeature == aCurrentFeature) {
471 myPropertyPanel->updateContentWidget(aCurrentFeature);
476 myOperationMgr->onValidateOperation();
478 myObjectBrowser->processEvent(theMsg);
481 //******************************************************
482 void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
484 std::set<ObjectPtr> aObjects = theMsg->objects();
485 std::set<ObjectPtr>::const_iterator aIt;
486 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
487 ObjectPtr aObj = (*aIt);
488 bool aHide = !aObj->data() || !aObj->data()->isValid();
489 if (!aHide) { // check that this is not hidden result
490 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
491 aHide = aRes && aRes->isConcealed();
494 myDisplayer->erase(aObj, false);
496 if (myDisplayer->isVisible(aObj)) {
497 myDisplayer->display(aObj, false); // In order to update presentation
498 if (myOperationMgr->hasOperation()) {
499 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
500 if (aOperation->hasObject(aObj) && myDisplayer->isActive(aObj))
501 myDisplayer->deactivate(aObj);
504 if (myOperationMgr->hasOperation()) {
505 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
506 // Display only current operation results if operation has preview
507 if (aOperation->hasObject(aObj)/* && aOperation->hasPreview()*/) {
508 myDisplayer->display(aObj, false);
509 // Deactivate object of current operation from selection
510 if (myDisplayer->isActive(aObj))
511 myDisplayer->deactivate(aObj);
517 myDisplayer->updateViewer();
520 //******************************************************
521 void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
523 std::set<ObjectPtr> aObjects = theMsg->objects();
525 std::set<ObjectPtr>::const_iterator aIt;
526 bool aHasPart = false;
527 bool isDisplayed = false;
528 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
529 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
532 // If a feature is created from the aplication's python console
533 // it doesn't stored in the operation mgr and doesn't displayed
534 } else if (myOperationMgr->hasOperation()) {
535 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
536 if (aOperation->hasObject(*aIt)) { // Display only current operation results
537 myDisplayer->display(*aIt, false);
543 myObjectBrowser->processEvent(theMsg);
545 myDisplayer->updateViewer();
546 //if (aHasPart) { // TODO: Avoid activate last part on loading of document
547 // activateLastPart();
551 //******************************************************
552 void XGUI_Workshop::onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg)
555 myObjectBrowser->processEvent(theMsg);
556 //std::set<ObjectPtr> aFeatures = theMsg->objects();
559 //******************************************************
560 void XGUI_Workshop::onOperationStarted()
562 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
563 if (this->isSalomeMode())
564 aOperation->setNestedFeatures(mySalomeConnector->nestedActions(aOperation->id()));
566 aOperation->setNestedFeatures(myActionsMgr->nestedCommands(aOperation->id()));
568 if (aOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
569 connectWithOperation(aOperation);
572 QString aXmlRepr = aOperation->getDescription()->xmlRepresentation();
573 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
576 myPropertyPanel->cleanContent();
577 aFactory.createWidget(myPropertyPanel->contentWidget());
578 ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget());
580 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
581 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
582 aWidget->setFeature(aOperation->feature());
583 aWidget->enableFocusProcessing();
584 QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
585 // Init default values
586 if (!aOperation->isEditOperation() && !aWidget->isComputedDefault()) {
587 aWidget->storeValue();
591 myPropertyPanel->setModelWidgets(aWidgets);
592 aOperation->setPropertyPanel(myPropertyPanel);
593 // Do not activate widgets by default if the current operation is editing operation
594 // Because we don't know which widget is going to be edited.
595 if ((!aOperation->isEditOperation())) {
596 if (!aOperation->activateByPreselection())
597 myPropertyPanel->activateNextWidget(NULL);
599 // Set final definitions if they are necessary
600 myModule->propertyPanelDefined(aOperation);
602 // Widget activation (from the previous method) may commit the current operation
603 // if pre-selection is enougth for it. So we shouldn't update prop panel's title
604 if(myOperationMgr->isCurrentOperation(aOperation)) {
605 myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
608 updateCommandStatus();
611 //******************************************************
612 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
614 //!< No need for property panel
615 updateCommandStatus();
617 myPropertyPanel->cleanContent();
619 // Activate objects created by current operation
620 FeaturePtr aFeature = theOperation->feature();
621 myDisplayer->activate(aFeature);
622 const std::list<ResultPtr>& aResults = aFeature->results();
623 std::list<ResultPtr>::const_iterator aIt;
624 for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
625 myDisplayer->activate(*aIt);
629 bool XGUI_Workshop::event(QEvent * theEvent)
631 PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
633 std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
634 processEvent(aEventPtr);
643 void XGUI_Workshop::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
647 qDebug() << "XGUI_Workshop::addFeature: NULL message.";
651 // Remember features icons
652 myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon());
654 //Find or create Workbench
655 QString aWchName = QString::fromStdString(theMessage->workbenchId());
656 QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
657 bool isUsePropPanel = theMessage->isUseInput();
658 QString aFeatureId = QString::fromStdString(theMessage->id());
659 if (isSalomeMode()) {
660 QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureId,
661 QString::fromStdString(theMessage->text()),
662 QString::fromStdString(theMessage->tooltip()),
663 QIcon(theMessage->icon().c_str()),
666 salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ", QString::SkipEmptyParts));
667 salomeConnector()->setDocumentKind(aFeatureId, QString::fromStdString(theMessage->documentKind()));
669 myActionsMgr->addCommand(aAction);
670 myModule->actionCreated(aAction);
673 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
674 AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
676 aPage = addWorkbench(aWchName);
678 //Find or create Group
679 QString aGroupName = QString::fromStdString(theMessage->groupId());
680 AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
682 aGroup = aPage->addGroup(aGroupName);
684 QString aDocKind = QString::fromStdString(theMessage->documentKind());
685 // Check if hotkey sequence is already defined:
686 QKeySequence aHotKey = myActionsMgr->registerShortcut(
687 QString::fromStdString(theMessage->keysequence()));
689 AppElements_Command* aCommand = aGroup->addFeature(aFeatureId,
690 QString::fromStdString(theMessage->text()),
691 QString::fromStdString(theMessage->tooltip()),
692 QIcon(theMessage->icon().c_str()),
696 aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts));
697 myActionsMgr->addCommand(aCommand);
698 myModule->actionCreated(aCommand);
703 * Makes a signal/slot connections between Property Panel
704 * and given operation. The given operation becomes a
705 * current operation and previous operation if exists
707 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
709 QAction* aCommand = 0;
710 if (isSalomeMode()) {
711 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
713 AppElements_MainMenu* aMenu = myMainWindow->menuObject();
714 FeaturePtr aFeature = theOperation->feature();
716 aCommand = aMenu->feature(QString::fromStdString(aFeature->getKind()));
718 //Abort operation on uncheck the command
720 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
725 * Saves document with given name.
727 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
729 QApplication::restoreOverrideCursor();
730 SessionPtr aMgr = ModelAPI_Session::get();
731 aMgr->save(theName.toLatin1().constData(), theFileNames);
732 QApplication::restoreOverrideCursor();
735 bool XGUI_Workshop::isActiveOperationAborted()
737 return myOperationMgr->abortAllOperations();
740 //******************************************************
741 void XGUI_Workshop::onExit()
743 SessionPtr aMgr = ModelAPI_Session::get();
744 if (aMgr->isModified()) {
745 int anAnswer = QMessageBox::question(
746 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
747 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
748 if (anAnswer == QMessageBox::Save) {
749 bool saved = onSave();
753 } else if (anAnswer == QMessageBox::Cancel) {
760 //******************************************************
761 void XGUI_Workshop::onNew()
763 QApplication::setOverrideCursor(Qt::WaitCursor);
764 if (objectBrowser() == 0) {
766 mySelector->connectViewers();
768 myViewerProxy->connectToViewer();
770 if (!isSalomeMode()) {
771 myMainWindow->showPythonConsole();
772 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
773 aWnd->showMaximized();
774 updateCommandStatus();
776 myContextMenuMgr->connectViewer();
777 QApplication::restoreOverrideCursor();
780 //******************************************************
781 void XGUI_Workshop::onOpen()
783 if(!isActiveOperationAborted())
785 //save current file before close if modified
786 SessionPtr aSession = ModelAPI_Session::get();
787 if (aSession->isModified()) {
788 //TODO(sbh): re-launch the app?
789 int anAnswer = QMessageBox::question(
790 myMainWindow, tr("Save current file"),
791 tr("The document is modified, save before opening another?"),
792 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
793 if (anAnswer == QMessageBox::Save) {
795 } else if (anAnswer == QMessageBox::Cancel) {
798 aSession->closeAll();
802 //show file dialog, check if readable and open
803 myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
804 if (myCurrentDir.isEmpty())
806 QFileInfo aFileInfo(myCurrentDir);
807 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
808 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
812 QApplication::setOverrideCursor(Qt::WaitCursor);
813 aSession->load(myCurrentDir.toLatin1().constData());
814 myObjectBrowser->rebuildDataTree();
816 updateCommandStatus();
817 QApplication::restoreOverrideCursor();
820 //******************************************************
821 bool XGUI_Workshop::onSave()
823 if(!isActiveOperationAborted())
825 if (myCurrentDir.isEmpty()) {
828 std::list<std::string> aFiles;
829 saveDocument(myCurrentDir, aFiles);
830 updateCommandStatus();
832 myMainWindow->setModifiedState(false);
836 //******************************************************
837 bool XGUI_Workshop::onSaveAs()
839 if(!isActiveOperationAborted())
841 QFileDialog dialog(mainWindow());
842 dialog.setWindowTitle(tr("Select directory to save files..."));
843 dialog.setFileMode(QFileDialog::Directory);
844 dialog.setFilter(tr("Folders (*)"));
845 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
846 dialog.setViewMode(QFileDialog::Detail);
848 if (!dialog.exec()) {
851 QString aTempDir = dialog.selectedFiles().first();
853 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
854 int answer = QMessageBox::question(
856 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
858 tr("The folder already contains some files, save anyway?"),
859 QMessageBox::Save | QMessageBox::Cancel);
860 if (answer == QMessageBox::Cancel) {
864 myCurrentDir = aTempDir;
865 if (!isSalomeMode()) {
866 myMainWindow->setCurrentDir(myCurrentDir, false);
867 myMainWindow->setModifiedState(false);
872 //******************************************************
873 void XGUI_Workshop::onUndo()
875 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
876 SessionPtr aMgr = ModelAPI_Session::get();
877 if (aMgr->isOperation())
878 operationMgr()->onAbortOperation();
880 updateCommandStatus();
883 //******************************************************
884 void XGUI_Workshop::onRedo()
886 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
887 SessionPtr aMgr = ModelAPI_Session::get();
888 if (aMgr->isOperation())
889 operationMgr()->onAbortOperation();
891 updateCommandStatus();
894 //******************************************************
895 void XGUI_Workshop::onRebuild()
897 SessionPtr aMgr = ModelAPI_Session::get();
898 bool aWasOperation = aMgr->isOperation(); // keep this value
899 if (!aWasOperation) {
900 aMgr->startOperation();
902 static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
903 Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
904 new Events_Message(aRebuildEvent, this)));
905 if (!aWasOperation) {
906 aMgr->finishOperation();
910 //******************************************************
911 void XGUI_Workshop::onPreferences()
913 ModuleBase_Prefs aModif;
914 ModuleBase_Preferences::editPreferences(aModif);
915 if (aModif.size() > 0) {
917 foreach (ModuleBase_Pref aPref, aModif)
919 aSection = aPref.first;
920 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
922 myMainWindow->viewer()->updateFromResources();
923 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
925 myMainWindow->menuObject()->updateFromResources();
931 //******************************************************
932 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
934 QString libName = QString::fromStdString(library(theModule.toStdString()));
935 if (libName.isEmpty()) {
936 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
941 CREATE_FUNC crtInst = 0;
944 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
948 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
949 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
950 QString aMsg((char*) &lpMsgBuf);
951 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
952 ::LocalFree(lpMsgBuf);
954 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
958 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
959 | FORMAT_MESSAGE_IGNORE_INSERTS,
960 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
961 QString aMsg((char*) &lpMsgBuf);
962 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
963 ::LocalFree(lpMsgBuf);
967 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
969 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
971 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
973 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
978 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
980 if (!err.isEmpty()) {
982 Events_Error::send(err.toStdString());
984 qWarning(qPrintable(err));
990 //******************************************************
991 bool XGUI_Workshop::activateModule()
993 Config_ModuleReader aModuleReader;
994 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
995 myModule = loadModule(moduleName);
998 myModule->createFeatures();
999 myActionsMgr->update();
1003 //******************************************************
1004 void XGUI_Workshop::updateCommandStatus()
1006 QList<QAction*> aCommands;
1007 if (isSalomeMode()) { // update commands in SALOME mode
1008 aCommands = salomeConnector()->commandList();
1010 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1011 foreach (AppElements_Command* aCmd, aMenuBar->features())
1012 aCommands.append(aCmd);
1014 SessionPtr aMgr = ModelAPI_Session::get();
1015 if (aMgr->hasModuleDocument()) {
1016 QAction *aUndoCmd, *aRedoCmd;
1017 foreach(QAction* aCmd, aCommands) {
1018 QString aId = aCmd->data().toString();
1019 if (aId == "UNDO_CMD")
1021 else if (aId == "REDO_CMD")
1024 // Enable all commands
1025 aCmd->setEnabled(true);
1027 aUndoCmd->setEnabled(aMgr->canUndo() && !aMgr->isOperation());
1028 aRedoCmd->setEnabled(aMgr->canRedo() && !aMgr->isOperation());
1030 foreach(QAction* aCmd, aCommands) {
1031 QString aId = aCmd->data().toString();
1032 if (aId == "NEW_CMD")
1033 aCmd->setEnabled(true);
1034 else if (aId == "EXIT_CMD")
1035 aCmd->setEnabled(true);
1037 aCmd->setEnabled(false);
1040 myActionsMgr->update();
1043 //******************************************************
1044 QList<QAction*> XGUI_Workshop::getModuleCommands() const
1046 QList<QAction*> aCommands;
1047 if (isSalomeMode()) { // update commands in SALOME mode
1048 aCommands = salomeConnector()->commandList();
1050 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1051 foreach(AppElements_Command* aCmd, aMenuBar->features())
1053 aCommands.append(aCmd);
1059 //******************************************************
1060 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1062 QDockWidget* aObjDock = new QDockWidget(theParent);
1063 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1064 aObjDock->setWindowTitle(tr("Object browser"));
1065 aObjDock->setStyleSheet(
1066 "::title { position: relative; padding-left: 5px; text-align: left center }");
1067 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1068 connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this,
1069 SLOT(changeCurrentDocument(ObjectPtr)));
1070 aObjDock->setWidget(myObjectBrowser);
1072 myContextMenuMgr->connectObjectBrowser();
1076 //******************************************************
1078 * Creates dock widgets, places them in corresponding area
1079 * and tabifies if necessary.
1081 void XGUI_Workshop::createDockWidgets()
1083 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1084 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1085 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1086 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
1087 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1089 connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets()));
1091 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1092 hidePropertyPanel(); //<! Invisible by default
1093 hideObjectBrowser();
1094 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1095 myPropertyPanel->installEventFilter(myOperationMgr);
1097 QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(PROP_PANEL_OK);
1098 connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
1099 QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(PROP_PANEL_CANCEL);
1100 connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
1101 connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr,
1102 SLOT(onKeyReleased(QKeyEvent*)));
1103 connect(myOperationMgr, SIGNAL(operationValidated(bool)), myPropertyPanel,
1104 SLOT(setAcceptEnabled(bool)));
1108 //******************************************************
1109 void XGUI_Workshop::showPropertyPanel()
1111 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1112 //<! Restore ability to close panel from the window's menu
1113 aViewAct->setEnabled(true);
1114 myPropertyPanel->show();
1115 myPropertyPanel->raise();
1118 //******************************************************
1119 void XGUI_Workshop::hidePropertyPanel()
1121 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1122 //<! Do not allow to show empty property panel
1123 aViewAct->setEnabled(false);
1124 myPropertyPanel->hide();
1127 //******************************************************
1128 void XGUI_Workshop::showObjectBrowser()
1130 myObjectBrowser->parentWidget()->show();
1133 //******************************************************
1134 void XGUI_Workshop::hideObjectBrowser()
1136 myObjectBrowser->parentWidget()->hide();
1139 //******************************************************
1140 void XGUI_Workshop::onFeatureTriggered()
1142 QAction* aCmd = dynamic_cast<QAction*>(sender());
1144 QString aId = salomeConnector()->commandId(aCmd);
1146 myModule->launchOperation(aId);
1150 //******************************************************
1151 void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
1153 SessionPtr aMgr = ModelAPI_Session::get();
1155 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theObj);
1157 DocumentPtr aPartDoc = aPart->partDoc();
1159 aMgr->setActiveDocument(aPartDoc);
1164 aMgr->setActiveDocument(aMgr->moduleDocument());
1167 //******************************************************
1168 void XGUI_Workshop::salomeViewerSelectionChanged()
1170 emit salomeViewerSelection();
1173 //**************************************************************
1174 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1176 return mySalomeConnector->viewer();
1179 //**************************************************************
1180 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1182 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1183 if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) {
1184 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
1185 activatePart(aPart);
1186 } else if (theId == "DEACTIVATE_PART_CMD")
1187 activatePart(ResultPartPtr());
1188 else if (theId == "DELETE_CMD")
1189 deleteObjects(aObjects);
1190 else if (theId == "SHOW_CMD")
1191 showObjects(aObjects, true);
1192 else if (theId == "HIDE_CMD")
1193 showObjects(aObjects, false);
1194 else if (theId == "SHOW_ONLY_CMD")
1195 showOnlyObjects(aObjects);
1196 else if (theId == "SHADING_CMD")
1197 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1198 else if (theId == "WIREFRAME_CMD")
1199 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1200 else if (theId == "HIDEALL_CMD")
1201 myDisplayer->eraseAll();
1202 else if (theId == "EDIT_CMD") {
1203 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObjects.first());
1205 myModule->editFeature(aFeature);
1209 //**************************************************************
1210 void XGUI_Workshop::onWidgetValuesChanged()
1212 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1213 FeaturePtr aFeature = anOperation->feature();
1215 ModuleBase_ModelWidget* aSenderWidget = dynamic_cast<ModuleBase_ModelWidget*>(sender());
1217 // aCustom->storeValue(aFeature);
1219 const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
1220 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
1221 for (; anIt != aLast; anIt++) {
1222 ModuleBase_ModelWidget* aCustom = *anIt;
1223 if (aCustom && (/*!aCustom->isInitialized(aFeature) ||*/aCustom == aSenderWidget)) {
1224 //aCustom->storeValue(aFeature);
1225 aCustom->storeValue();
1230 //**************************************************************
1231 void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
1233 if (!myPartActivating) {
1234 myPartActivating = true;
1236 theFeature->activate();
1237 changeCurrentDocument(theFeature);
1238 myObjectBrowser->activatePart(theFeature);
1239 myPartActivating = false;
1243 //**************************************************************
1244 void XGUI_Workshop::activateLastPart()
1246 SessionPtr aMgr = ModelAPI_Session::get();
1247 DocumentPtr aDoc = aMgr->moduleDocument();
1248 std::string aGrpName = ModelAPI_ResultPart::group();
1249 ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
1250 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
1252 activatePart(aPart);
1256 //**************************************************************
1257 void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList)
1259 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1260 QMessageBox::StandardButton aRes = QMessageBox::warning(
1261 aDesktop, tr("Delete features"), tr("Seleted features will be deleted. Continue?"),
1262 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1263 // ToDo: definbe deleting method
1264 if (aRes == QMessageBox::Yes) {
1265 SessionPtr aMgr = ModelAPI_Session::get();
1266 aMgr->startOperation();
1267 foreach (ObjectPtr aObj, theList)
1269 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1271 DocumentPtr aDoc = aPart->document();
1272 if (aDoc == aMgr->activeDocument()) {
1275 //aMgr->moduleDocument()->removeFeature(aPart->owner());
1277 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1279 aObj->document()->removeFeature(aFeature);
1282 myDisplayer->updateViewer();
1283 aMgr->finishOperation();
1287 //**************************************************************
1288 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1290 foreach (ObjectPtr aObj, theList)
1293 myDisplayer->display(aObj, false);
1295 myDisplayer->erase(aObj, false);
1298 myDisplayer->updateViewer();
1301 //**************************************************************
1302 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1304 myDisplayer->showOnly(theList);
1308 //**************************************************************
1309 void XGUI_Workshop::updateCommandsOnViewSelection()
1311 XGUI_Selection* aSelection = mySelector->selection();
1312 if (aSelection->getSelected().size() == 0)
1315 // Restrict validators to manage only nested (child) features
1316 // of the current feature i.e. if current feature is Sketch -
1317 // Sketch Features & Constraints can be validated.
1318 QStringList aNestedIds;
1319 if(myOperationMgr->hasOperation()) {
1320 FeaturePtr aFeature = myOperationMgr->currentOperation()->feature();
1322 aNestedIds << myActionsMgr->nestedCommands(QString::fromStdString(aFeature->getKind()));
1325 SessionPtr aMgr = ModelAPI_Session::get();
1326 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1327 QList<QAction*> aActions = getModuleCommands();
1328 foreach(QAction* aAction, aActions) {
1329 QString aId = aAction->data().toString();
1330 if(!aNestedIds.contains(aId))
1332 std::list<ModelAPI_Validator*> aValidators;
1333 std::list<std::list<std::string> > anArguments;
1334 aFactory->validators(aId.toStdString(), aValidators, anArguments);
1335 std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
1336 for (; aValidator != aValidators.end(); aValidator++) {
1338 const ModuleBase_SelectionValidator* aSelValidator =
1339 dynamic_cast<const ModuleBase_SelectionValidator*>(*aValidator);
1340 if (aSelValidator) {
1341 aAction->setEnabled(aSelValidator->isValid(aSelection));
1348 //**************************************************************
1349 void XGUI_Workshop::registerValidators() const
1351 SessionPtr aMgr = ModelAPI_Session::get();
1352 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1355 //**************************************************************
1356 void XGUI_Workshop::displayAllResults()
1358 SessionPtr aMgr = ModelAPI_Session::get();
1359 DocumentPtr aRootDoc = aMgr->moduleDocument();
1360 displayDocumentResults(aRootDoc);
1361 for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1362 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1363 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1364 displayDocumentResults(aPart->partDoc());
1366 myDisplayer->updateViewer();
1369 //**************************************************************
1370 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1374 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1375 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1378 //**************************************************************
1379 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1381 for (int i = 0; i < theDoc->size(theGroup); i++)
1382 myDisplayer->display(theDoc->object(theGroup, i), false);
1385 //**************************************************************
1386 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1388 foreach(ObjectPtr aObj, theList) {
1389 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1391 if (theList.size() > 0)
1392 myDisplayer->updateViewer();
1395 //**************************************************************
1396 void XGUI_Workshop::closeDocument()
1398 myDisplayer->closeLocalContexts();
1399 myDisplayer->eraseAll();
1400 objectBrowser()->clearContent();
1402 SessionPtr aMgr = ModelAPI_Session::get();
1404 objectBrowser()->clearContent();