1 #include "ModuleBase_IModule.h"
2 #include "XGUI_Constants.h"
3 #include "XGUI_Command.h"
4 #include "XGUI_MainMenu.h"
5 #include "XGUI_MainWindow.h"
6 #include "XGUI_MenuGroupPanel.h"
7 #include "XGUI_Tools.h"
8 #include "XGUI_Workbench.h"
9 #include "XGUI_Workshop.h"
10 #include "XGUI_Viewer.h"
11 #include "XGUI_SelectionMgr.h"
12 #include "XGUI_Selection.h"
13 #include "XGUI_ObjectsBrowser.h"
14 #include "XGUI_Displayer.h"
15 #include "XGUI_OperationMgr.h"
16 #include "XGUI_SalomeConnector.h"
17 #include "XGUI_ActionsMgr.h"
18 #include "XGUI_ErrorDialog.h"
19 #include "XGUI_ViewerProxy.h"
20 #include "XGUI_PropertyPanel.h"
21 #include "XGUI_ContextMenuMgr.h"
22 #include "XGUI_ModuleConnector.h"
23 #include "XGUI_Preferences.h"
24 #include <XGUI_QtEvents.h>
26 #include <ModelAPI_Events.h>
27 #include <ModelAPI_Session.h>
28 #include <ModelAPI_Feature.h>
29 #include <ModelAPI_Data.h>
30 #include <ModelAPI_AttributeDocRef.h>
31 #include <ModelAPI_Object.h>
32 #include <ModelAPI_Validator.h>
33 #include <ModelAPI_ResultConstruction.h>
34 #include <ModelAPI_ResultBody.h>
36 #include <PartSetPlugin_Part.h>
38 #include <Events_Loop.h>
39 #include <Events_Error.h>
40 #include <Events_LongOp.h>
42 #include <ModuleBase_Operation.h>
43 #include <ModuleBase_Operation.h>
44 #include <ModuleBase_OperationDescription.h>
45 #include <ModuleBase_SelectionValidator.h>
46 #include <ModuleBase_WidgetFactory.h>
47 #include <ModuleBase_Tools.h>
48 #include <ModuleBase_IViewer.h>
50 #include <Config_Common.h>
51 #include <Config_FeatureMessage.h>
52 #include <Config_PointerMessage.h>
53 #include <Config_ModuleReader.h>
55 #include <QApplication>
56 #include <QFileDialog>
57 #include <QMessageBox>
58 #include <QMdiSubWindow>
59 #include <QPushButton>
60 #include <QDockWidget>
76 QMap<QString, QString> XGUI_Workshop::myIcons;
78 QString XGUI_Workshop::featureIcon(const std::string& theId)
80 QString aId(theId.c_str());
81 if (myIcons.contains(aId))
86 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
88 myCurrentDir(QString()),
90 mySalomeConnector(theConnector),
95 myPartActivating(false)
97 myMainWindow = mySalomeConnector ? 0 : new XGUI_MainWindow();
99 myDisplayer = new XGUI_Displayer(this);
101 mySelector = new XGUI_SelectionMgr(this);
102 //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
104 myOperationMgr = new XGUI_OperationMgr(this);
105 myActionsMgr = new XGUI_ActionsMgr(this);
106 myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
107 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
108 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
109 SLOT(onContextMenuCommand(const QString&, bool)));
111 myViewerProxy = new XGUI_ViewerProxy(this);
112 connect(myViewerProxy, SIGNAL(selectionChanged()), this, SLOT(updateCommandsOnViewSelection()));
114 myModuleConnector = new XGUI_ModuleConnector(this);
116 connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
117 SLOT(onOperationStarted()));
118 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)), SLOT(onOperationStarted()));
119 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
120 SLOT(onOperationStopped(ModuleBase_Operation*)));
121 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
122 // TODO(sbh): It seems that application works properly without update on operationStarted
123 connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
124 myActionsMgr, SLOT(update()));
125 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
126 myActionsMgr, SLOT(update()));
127 connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
130 //******************************************************
131 XGUI_Workshop::~XGUI_Workshop(void)
136 //******************************************************
137 void XGUI_Workshop::startApplication()
140 //Initialize event listening
141 Events_Loop* aLoop = Events_Loop::loop();
142 aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
143 aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
144 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
145 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
146 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
147 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
148 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
149 aLoop->registerListener(this, Events_Loop::eventByName("LongOperation"));
150 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
151 aLoop->registerListener(this, Events_Loop::eventByName("CurrentDocumentChanged"));
152 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOSHOW));
153 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
155 registerValidators();
158 myMainWindow->show();
159 updateCommandStatus();
161 XGUI_Preferences::loadCustomProps();
165 //******************************************************
166 void XGUI_Workshop::initMenu()
168 myContextMenuMgr->createActions();
170 if (isSalomeMode()) {
171 // Create only Undo, Redo commands
172 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
173 tr("Undo last command"),
174 QIcon(":pictures/undo.png"),
175 QKeySequence::Undo, false, "MEN_DESK_EDIT");
176 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
177 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
178 QIcon(":pictures/redo.png"), QKeySequence::Redo,
179 false, "MEN_DESK_EDIT");
180 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
181 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
182 aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
183 QIcon(":pictures/rebuild.png"), QKeySequence(),
184 false, "MEN_DESK_EDIT");
185 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
186 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
188 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export NewGeom..."), tr("Export the current document into a NewGeom file"),
189 QIcon(), QKeySequence(),
190 false, "MEN_DESK_FILE");
191 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
193 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import NewGeom..."), tr("Import a NewGeom file"),
194 QIcon(), QKeySequence(),
195 false, "MEN_DESK_FILE");
196 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
197 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
201 // File commands group
202 XGUI_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
204 XGUI_Command* aCommand;
206 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
207 QIcon(":pictures/save.png"), QKeySequence::Save);
208 aCommand->connectTo(this, SLOT(onSave()));
209 //aCommand->disable();
211 aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
212 QIcon(":pictures/undo.png"), QKeySequence::Undo);
213 aCommand->connectTo(this, SLOT(onUndo()));
215 aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
216 QIcon(":pictures/redo.png"), QKeySequence::Redo);
217 aCommand->connectTo(this, SLOT(onRedo()));
219 aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
220 QIcon(":pictures/rebuild.png"), QKeySequence());
221 aCommand->connectTo(this, SLOT(onRebuild()));
223 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
224 QIcon(":pictures/save.png"), QKeySequence());
225 aCommand->connectTo(this, SLOT(onSaveAs()));
226 //aCommand->disable();
228 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
229 QIcon(":pictures/open.png"), QKeySequence::Open);
230 aCommand->connectTo(this, SLOT(onOpen()));
232 //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
233 // QIcon(":pictures/new.png"), QKeySequence::New);
234 //aCommand->connectTo(this, SLOT(onNew()));
236 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
237 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
238 aCommand->connectTo(this, SLOT(onPreferences()));
240 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
241 QIcon(":pictures/close.png"), QKeySequence::Close);
242 aCommand->connectTo(this, SLOT(onExit()));
243 //FIXME: SBH's test action. Can be used for some GUI tests.
245 // aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
246 // QIcon(":pictures/close.png"), QKeySequence(), true);
247 // aCommand->connectTo(myMainWindow, SLOT(dockPythonConsole()));
251 //******************************************************
252 XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
254 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
255 return aMenuBar->addWorkbench(theName);
258 //******************************************************
259 void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessage)
261 if (QApplication::instance()->thread() != QThread::currentThread()) {
263 std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
265 SessionPtr aMgr = ModelAPI_Session::get();
266 PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(theMessage);
267 QApplication::postEvent(this, aPostponeEvent);
271 //A message to start feature creation received.
272 if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
273 std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
274 std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
275 if (!aFeatureMsg->isInternal()) {
276 addFeature(aFeatureMsg);
280 // Process creation of Part
281 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
282 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
283 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
284 onFeatureCreatedMsg(aUpdMsg);
286 if (mySalomeConnector)
287 mySalomeConnector->createPreferences();
288 myUpdatePrefs = false;
291 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
292 myUpdatePrefs = true;
296 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
297 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
298 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
299 onFeatureRedisplayMsg(aUpdMsg);
302 //Update property panel on corresponding message. If there is no current operation (no
303 //property panel), or received message has different feature to the current - do nothing.
304 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
305 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
306 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
307 onFeatureUpdatedMsg(anUpdateMsg);
310 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
311 std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
312 std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
313 onObjectDeletedMsg(aDelMsg);
316 else if (theMessage->eventID() == Events_LongOp::eventID()) {
317 if (Events_LongOp::isPerformed())
318 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
320 QApplication::restoreOverrideCursor();
323 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW)) {
324 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
325 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
326 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
327 QObjectPtrList aList;
328 std::set<ObjectPtr>::const_iterator aIt;
329 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
331 showObjects(aList, true);
334 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE)) {
335 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
336 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
337 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
338 QObjectPtrList aList;
339 std::set<ObjectPtr>::const_iterator aIt;
340 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
342 showObjects(aList, false);
345 //An operation passed by message. Start it, process and commit.
346 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
347 std::shared_ptr<Config_PointerMessage> aPartSetMsg =
348 std::dynamic_pointer_cast<Config_PointerMessage>(theMessage);
349 //myPropertyPanel->cleanContent();
350 ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
352 if (myOperationMgr->startOperation(anOperation)) {
353 myPropertyPanel->updateContentWidget(anOperation->feature());
354 if (!anOperation->getDescription()->hasXmlRepresentation()) {
355 if (anOperation->commit())
356 updateCommandStatus();
360 else if (theMessage->eventID() == Events_Loop::loop()->eventByName("CurrentDocumentChanged")) {
361 myActionsMgr->update();
362 // Find and Activate active part
363 if (myPartActivating)
365 SessionPtr aMgr = ModelAPI_Session::get();
366 DocumentPtr aActiveDoc = aMgr->activeDocument();
367 DocumentPtr aDoc = aMgr->moduleDocument();
368 if (aActiveDoc == aDoc) {
369 activatePart(ResultPartPtr());
372 std::string aGrpName = ModelAPI_ResultPart::group();
373 for (int i = 0; i < aDoc->size(aGrpName); i++) {
374 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
375 if (aPart->partDoc() == aActiveDoc) {
376 activatePart(aPart); // Activate a part which corresponds to active Doc
380 // If not found then activate global document
381 activatePart(ResultPartPtr());
384 //Show error dialog if error message received.
385 std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
387 emit errorOccurred(QString::fromLatin1(anAppError->description()));
390 if (!isSalomeMode()) {
391 SessionPtr aMgr = ModelAPI_Session::get();
392 if (aMgr->isModified() != myMainWindow->isModifiedState())
393 myMainWindow->setModifiedState(aMgr->isModified());
398 //******************************************************
399 void XGUI_Workshop::onStartWaiting()
401 if (Events_LongOp::isPerformed()) {
402 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
406 //******************************************************
407 void XGUI_Workshop::onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
409 std::set<ObjectPtr> aFeatures = theMsg->objects();
410 if (myOperationMgr->hasOperation()) {
411 FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
412 std::set<ObjectPtr>::const_iterator aIt;
413 for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
414 ObjectPtr aNewFeature = (*aIt);
415 if (aNewFeature == aCurrentFeature) {
416 myPropertyPanel->updateContentWidget(aCurrentFeature);
421 myOperationMgr->onValidateOperation();
423 myObjectBrowser->processEvent(theMsg);
426 //******************************************************
427 void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
429 std::set<ObjectPtr> aObjects = theMsg->objects();
430 std::set<ObjectPtr>::const_iterator aIt;
431 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
432 ObjectPtr aObj = (*aIt);
433 bool aHide = !aObj->data() || !aObj->data()->isValid();
434 if (!aHide) { // check that this is not hidden result
435 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
436 aHide = aRes && aRes->isConcealed();
439 myDisplayer->erase(aObj, false);
441 if (myDisplayer->isVisible(aObj)) {
442 myDisplayer->display(aObj, false); // In order to update presentation
443 if (myOperationMgr->hasOperation()) {
444 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
445 if (aOperation->hasObject(aObj) && myDisplayer->isActive(aObj))
446 myDisplayer->deactivate(aObj);
449 if (myOperationMgr->hasOperation()) {
450 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
451 // Display only current operation results if operation has preview
452 if (aOperation->hasObject(aObj)/* && aOperation->hasPreview()*/) {
453 myDisplayer->display(aObj, false);
454 // Deactivate object of current operation from selection
455 if (myDisplayer->isActive(aObj))
456 myDisplayer->deactivate(aObj);
462 myDisplayer->updateViewer();
465 //******************************************************
466 void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
468 std::set<ObjectPtr> aObjects = theMsg->objects();
470 std::set<ObjectPtr>::const_iterator aIt;
471 bool aHasPart = false;
472 bool isDisplayed = false;
473 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
474 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
477 // If a feature is created from the aplication's python console
478 // it doesn't stored in the operation mgr and doesn't displayed
479 } else if (myOperationMgr->hasOperation()) {
480 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
481 if (aOperation->hasObject(*aIt)) { // Display only current operation results
482 myDisplayer->display(*aIt, false);
488 myObjectBrowser->processEvent(theMsg);
490 myDisplayer->updateViewer();
491 //if (aHasPart) { // TODO: Avoid activate last part on loading of document
492 // activateLastPart();
496 //******************************************************
497 void XGUI_Workshop::onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg)
500 myObjectBrowser->processEvent(theMsg);
501 //std::set<ObjectPtr> aFeatures = theMsg->objects();
504 //******************************************************
505 void XGUI_Workshop::onOperationStarted()
507 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
508 if (this->isSalomeMode())
509 aOperation->setNestedFeatures(mySalomeConnector->nestedActions(aOperation->id()));
511 aOperation->setNestedFeatures(myActionsMgr->nestedCommands(aOperation->id()));
513 if (aOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
514 connectWithOperation(aOperation);
517 QString aXmlRepr = aOperation->getDescription()->xmlRepresentation();
518 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
521 myPropertyPanel->cleanContent();
522 aFactory.createWidget(myPropertyPanel->contentWidget());
523 ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget());
525 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
526 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
527 aWidget->setFeature(aOperation->feature());
528 aWidget->enableFocusProcessing();
529 QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
530 // Init default values
531 if (!aOperation->isEditOperation() && !aWidget->isComputedDefault()) {
532 aWidget->storeValue();
536 myPropertyPanel->setModelWidgets(aWidgets);
537 aOperation->setPropertyPanel(myPropertyPanel);
538 // Do not activate widgets by default if the current operation is editing operation
539 // Because we don't know which widget is going to be edited.
540 if ((!aOperation->isEditOperation())) {
541 if (!aOperation->activateByPreselection())
542 myPropertyPanel->activateNextWidget(NULL);
544 // Set final definitions if they are necessary
545 myModule->propertyPanelDefined(aOperation);
547 // Widget activation (from the previous method) may commit the current operation
548 // if pre-selection is enougth for it. So we shouldn't update prop panel's title
549 if(myOperationMgr->isCurrentOperation(aOperation)) {
550 myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
553 updateCommandStatus();
556 //******************************************************
557 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
559 //!< No need for property panel
560 updateCommandStatus();
562 myPropertyPanel->cleanContent();
564 // Activate objects created by current operation
565 FeaturePtr aFeature = theOperation->feature();
566 myDisplayer->activate(aFeature);
567 const std::list<ResultPtr>& aResults = aFeature->results();
568 std::list<ResultPtr>::const_iterator aIt;
569 for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
570 myDisplayer->activate(*aIt);
574 bool XGUI_Workshop::event(QEvent * theEvent)
576 PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
578 std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
579 processEvent(aEventPtr);
588 void XGUI_Workshop::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
592 qDebug() << "XGUI_Workshop::addFeature: NULL message.";
596 // Remember features icons
597 myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon());
599 //Find or create Workbench
600 QString aWchName = QString::fromStdString(theMessage->workbenchId());
601 QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
602 bool isUsePropPanel = theMessage->isUseInput();
603 QString aFeatureId = QString::fromStdString(theMessage->id());
604 if (isSalomeMode()) {
605 QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureId,
606 QString::fromStdString(theMessage->text()),
607 QString::fromStdString(theMessage->tooltip()),
608 QIcon(theMessage->icon().c_str()),
611 salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ", QString::SkipEmptyParts));
612 salomeConnector()->setDocumentKind(aFeatureId, QString::fromStdString(theMessage->documentKind()));
614 myActionsMgr->addCommand(aAction);
615 myModule->actionCreated(aAction);
618 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
619 XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
621 aPage = addWorkbench(aWchName);
623 //Find or create Group
624 QString aGroupName = QString::fromStdString(theMessage->groupId());
625 XGUI_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
627 aGroup = aPage->addGroup(aGroupName);
629 QString aDocKind = QString::fromStdString(theMessage->documentKind());
630 // Check if hotkey sequence is already defined:
631 QKeySequence aHotKey = myActionsMgr->registerShortcut(
632 QString::fromStdString(theMessage->keysequence()));
634 XGUI_Command* aCommand = aGroup->addFeature(aFeatureId,
635 QString::fromStdString(theMessage->text()),
636 QString::fromStdString(theMessage->tooltip()),
637 QIcon(theMessage->icon().c_str()),
641 aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts));
642 myActionsMgr->addCommand(aCommand);
643 myModule->actionCreated(aCommand);
648 * Makes a signal/slot connections between Property Panel
649 * and given operation. The given operation becomes a
650 * current operation and previous operation if exists
652 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
654 QAction* aCommand = 0;
655 if (isSalomeMode()) {
656 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
658 XGUI_MainMenu* aMenu = myMainWindow->menuObject();
659 FeaturePtr aFeature = theOperation->feature();
661 aCommand = aMenu->feature(QString::fromStdString(aFeature->getKind()));
663 //Abort operation on uncheck the command
665 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
670 * Saves document with given name.
672 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
674 QApplication::restoreOverrideCursor();
675 SessionPtr aMgr = ModelAPI_Session::get();
676 aMgr->save(theName.toLatin1().constData(), theFileNames);
677 QApplication::restoreOverrideCursor();
680 bool XGUI_Workshop::isActiveOperationAborted()
682 return myOperationMgr->abortAllOperations();
685 //******************************************************
686 void XGUI_Workshop::onExit()
688 SessionPtr aMgr = ModelAPI_Session::get();
689 if (aMgr->isModified()) {
690 int anAnswer = QMessageBox::question(
691 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
692 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
693 if (anAnswer == QMessageBox::Save) {
694 bool saved = onSave();
698 } else if (anAnswer == QMessageBox::Cancel) {
705 //******************************************************
706 void XGUI_Workshop::onNew()
708 QApplication::setOverrideCursor(Qt::WaitCursor);
709 if (objectBrowser() == 0) {
711 mySelector->connectViewers();
713 myViewerProxy->connectToViewer();
715 if (!isSalomeMode()) {
716 myMainWindow->showPythonConsole();
717 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
718 aWnd->showMaximized();
719 updateCommandStatus();
721 myContextMenuMgr->connectViewer();
722 QApplication::restoreOverrideCursor();
725 //******************************************************
726 void XGUI_Workshop::onOpen()
728 if(!isActiveOperationAborted())
730 //save current file before close if modified
731 SessionPtr aSession = ModelAPI_Session::get();
732 if (aSession->isModified()) {
733 //TODO(sbh): re-launch the app?
734 int anAnswer = QMessageBox::question(
735 myMainWindow, tr("Save current file"),
736 tr("The document is modified, save before opening another?"),
737 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
738 if (anAnswer == QMessageBox::Save) {
740 } else if (anAnswer == QMessageBox::Cancel) {
743 aSession->closeAll();
747 //show file dialog, check if readable and open
748 myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
749 if (myCurrentDir.isEmpty())
751 QFileInfo aFileInfo(myCurrentDir);
752 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
753 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
757 QApplication::setOverrideCursor(Qt::WaitCursor);
758 aSession->load(myCurrentDir.toLatin1().constData());
759 myObjectBrowser->rebuildDataTree();
761 updateCommandStatus();
762 QApplication::restoreOverrideCursor();
765 //******************************************************
766 bool XGUI_Workshop::onSave()
768 if(!isActiveOperationAborted())
770 if (myCurrentDir.isEmpty()) {
773 std::list<std::string> aFiles;
774 saveDocument(myCurrentDir, aFiles);
775 updateCommandStatus();
777 myMainWindow->setModifiedState(false);
781 //******************************************************
782 bool XGUI_Workshop::onSaveAs()
784 if(!isActiveOperationAborted())
786 QFileDialog dialog(mainWindow());
787 dialog.setWindowTitle(tr("Select directory to save files..."));
788 dialog.setFileMode(QFileDialog::Directory);
789 dialog.setFilter(tr("Folders (*)"));
790 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
791 dialog.setViewMode(QFileDialog::Detail);
793 if (!dialog.exec()) {
796 QString aTempDir = dialog.selectedFiles().first();
798 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
799 int answer = QMessageBox::question(
801 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
803 tr("The folder already contains some files, save anyway?"),
804 QMessageBox::Save | QMessageBox::Cancel);
805 if (answer == QMessageBox::Cancel) {
809 myCurrentDir = aTempDir;
810 if (!isSalomeMode()) {
811 myMainWindow->setCurrentDir(myCurrentDir, false);
812 myMainWindow->setModifiedState(false);
817 //******************************************************
818 void XGUI_Workshop::onUndo()
820 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
821 SessionPtr aMgr = ModelAPI_Session::get();
822 if (aMgr->isOperation())
823 operationMgr()->onAbortOperation();
825 updateCommandStatus();
828 //******************************************************
829 void XGUI_Workshop::onRedo()
831 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
832 SessionPtr aMgr = ModelAPI_Session::get();
833 if (aMgr->isOperation())
834 operationMgr()->onAbortOperation();
836 updateCommandStatus();
839 //******************************************************
840 void XGUI_Workshop::onRebuild()
842 SessionPtr aMgr = ModelAPI_Session::get();
843 bool aWasOperation = aMgr->isOperation(); // keep this value
844 if (!aWasOperation) {
845 aMgr->startOperation();
847 static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
848 Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
849 new Events_Message(aRebuildEvent, this)));
850 if (!aWasOperation) {
851 aMgr->finishOperation();
855 //******************************************************
856 void XGUI_Workshop::onPreferences()
859 XGUI_Preferences::editPreferences(aModif);
860 if (aModif.size() > 0) {
862 foreach (XGUI_Pref aPref, aModif)
864 aSection = aPref.first;
865 if (aSection == XGUI_Preferences::VIEWER_SECTION) {
867 myMainWindow->viewer()->updateFromResources();
868 } else if (aSection == XGUI_Preferences::MENU_SECTION) {
870 myMainWindow->menuObject()->updateFromResources();
876 //******************************************************
877 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
879 QString libName = QString::fromStdString(library(theModule.toStdString()));
880 if (libName.isEmpty()) {
881 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
886 CREATE_FUNC crtInst = 0;
889 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
893 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
894 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
895 QString aMsg((char*) &lpMsgBuf);
896 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
897 ::LocalFree(lpMsgBuf);
899 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
903 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
904 | FORMAT_MESSAGE_IGNORE_INSERTS,
905 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
906 QString aMsg((char*) &lpMsgBuf);
907 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
908 ::LocalFree(lpMsgBuf);
912 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
914 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
916 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
918 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
923 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
925 if (!err.isEmpty()) {
927 Events_Error::send(err.toStdString());
929 qWarning(qPrintable(err));
935 //******************************************************
936 bool XGUI_Workshop::activateModule()
938 Config_ModuleReader aModuleReader;
939 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
940 myModule = loadModule(moduleName);
943 myModule->createFeatures();
944 myActionsMgr->update();
948 //******************************************************
949 void XGUI_Workshop::updateCommandStatus()
951 QList<QAction*> aCommands;
952 if (isSalomeMode()) { // update commands in SALOME mode
953 aCommands = salomeConnector()->commandList();
955 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
956 foreach (XGUI_Command* aCmd, aMenuBar->features())
957 aCommands.append(aCmd);
959 SessionPtr aMgr = ModelAPI_Session::get();
960 if (aMgr->hasModuleDocument()) {
961 QAction *aUndoCmd, *aRedoCmd;
962 foreach(QAction* aCmd, aCommands) {
963 QString aId = aCmd->data().toString();
964 if (aId == "UNDO_CMD")
966 else if (aId == "REDO_CMD")
969 // Enable all commands
970 aCmd->setEnabled(true);
972 aUndoCmd->setEnabled(aMgr->canUndo() && !aMgr->isOperation());
973 aRedoCmd->setEnabled(aMgr->canRedo() && !aMgr->isOperation());
975 foreach(QAction* aCmd, aCommands) {
976 QString aId = aCmd->data().toString();
977 if (aId == "NEW_CMD")
978 aCmd->setEnabled(true);
979 else if (aId == "EXIT_CMD")
980 aCmd->setEnabled(true);
982 aCmd->setEnabled(false);
985 myActionsMgr->update();
988 //******************************************************
989 QList<QAction*> XGUI_Workshop::getModuleCommands() const
991 QList<QAction*> aCommands;
992 if (isSalomeMode()) { // update commands in SALOME mode
993 aCommands = salomeConnector()->commandList();
995 XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
996 foreach(XGUI_Command* aCmd, aMenuBar->features())
998 aCommands.append(aCmd);
1004 //******************************************************
1005 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1007 QDockWidget* aObjDock = new QDockWidget(theParent);
1008 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1009 aObjDock->setWindowTitle(tr("Object browser"));
1010 aObjDock->setStyleSheet(
1011 "::title { position: relative; padding-left: 5px; text-align: left center }");
1012 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1013 connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this,
1014 SLOT(changeCurrentDocument(ObjectPtr)));
1015 aObjDock->setWidget(myObjectBrowser);
1017 myContextMenuMgr->connectObjectBrowser();
1021 //******************************************************
1023 * Creates dock widgets, places them in corresponding area
1024 * and tabifies if necessary.
1026 void XGUI_Workshop::createDockWidgets()
1028 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1029 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1030 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1031 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
1032 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1033 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1034 hidePropertyPanel(); //<! Invisible by default
1035 hideObjectBrowser();
1036 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1037 myPropertyPanel->installEventFilter(myOperationMgr);
1039 QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
1040 connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
1041 QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
1042 connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
1043 connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr,
1044 SLOT(onKeyReleased(QKeyEvent*)));
1045 connect(myOperationMgr, SIGNAL(operationValidated(bool)), myPropertyPanel,
1046 SLOT(setAcceptEnabled(bool)));
1050 //******************************************************
1051 void XGUI_Workshop::showPropertyPanel()
1053 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1054 //<! Restore ability to close panel from the window's menu
1055 aViewAct->setEnabled(true);
1056 myPropertyPanel->show();
1057 myPropertyPanel->raise();
1060 //******************************************************
1061 void XGUI_Workshop::hidePropertyPanel()
1063 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1064 //<! Do not allow to show empty property panel
1065 aViewAct->setEnabled(false);
1066 myPropertyPanel->hide();
1069 //******************************************************
1070 void XGUI_Workshop::showObjectBrowser()
1072 myObjectBrowser->parentWidget()->show();
1075 //******************************************************
1076 void XGUI_Workshop::hideObjectBrowser()
1078 myObjectBrowser->parentWidget()->hide();
1081 //******************************************************
1082 void XGUI_Workshop::onFeatureTriggered()
1084 QAction* aCmd = dynamic_cast<QAction*>(sender());
1086 QString aId = salomeConnector()->commandId(aCmd);
1088 myModule->launchOperation(aId);
1092 //******************************************************
1093 void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
1095 SessionPtr aMgr = ModelAPI_Session::get();
1097 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theObj);
1099 DocumentPtr aPartDoc = aPart->partDoc();
1101 aMgr->setActiveDocument(aPartDoc);
1106 aMgr->setActiveDocument(aMgr->moduleDocument());
1109 //******************************************************
1110 void XGUI_Workshop::salomeViewerSelectionChanged()
1112 emit salomeViewerSelection();
1115 //**************************************************************
1116 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1118 return mySalomeConnector->viewer();
1121 //**************************************************************
1122 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1124 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1125 if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) {
1126 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
1127 activatePart(aPart);
1128 } else if (theId == "DEACTIVATE_PART_CMD")
1129 activatePart(ResultPartPtr());
1130 else if (theId == "DELETE_CMD")
1131 deleteObjects(aObjects);
1132 else if (theId == "SHOW_CMD")
1133 showObjects(aObjects, true);
1134 else if (theId == "HIDE_CMD")
1135 showObjects(aObjects, false);
1136 else if (theId == "SHOW_ONLY_CMD")
1137 showOnlyObjects(aObjects);
1138 else if (theId == "SHADING_CMD")
1139 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1140 else if (theId == "WIREFRAME_CMD")
1141 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1142 else if (theId == "HIDEALL_CMD")
1143 myDisplayer->eraseAll();
1144 else if (theId == "EDIT_CMD") {
1145 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObjects.first());
1147 myModule->editFeature(aFeature);
1151 //**************************************************************
1152 void XGUI_Workshop::onWidgetValuesChanged()
1154 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1155 FeaturePtr aFeature = anOperation->feature();
1157 ModuleBase_ModelWidget* aSenderWidget = dynamic_cast<ModuleBase_ModelWidget*>(sender());
1159 // aCustom->storeValue(aFeature);
1161 const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
1162 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
1163 for (; anIt != aLast; anIt++) {
1164 ModuleBase_ModelWidget* aCustom = *anIt;
1165 if (aCustom && (/*!aCustom->isInitialized(aFeature) ||*/aCustom == aSenderWidget)) {
1166 //aCustom->storeValue(aFeature);
1167 aCustom->storeValue();
1172 //**************************************************************
1173 void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
1175 if (!myPartActivating) {
1176 myPartActivating = true;
1178 theFeature->activate();
1179 changeCurrentDocument(theFeature);
1180 myObjectBrowser->activatePart(theFeature);
1181 myPartActivating = false;
1185 //**************************************************************
1186 void XGUI_Workshop::activateLastPart()
1188 SessionPtr aMgr = ModelAPI_Session::get();
1189 DocumentPtr aDoc = aMgr->moduleDocument();
1190 std::string aGrpName = ModelAPI_ResultPart::group();
1191 ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
1192 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
1194 activatePart(aPart);
1198 //**************************************************************
1199 void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList)
1201 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1202 QMessageBox::StandardButton aRes = QMessageBox::warning(
1203 aDesktop, tr("Delete features"), tr("Seleted features will be deleted. Continue?"),
1204 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1205 // ToDo: definbe deleting method
1206 if (aRes == QMessageBox::Yes) {
1207 SessionPtr aMgr = ModelAPI_Session::get();
1208 aMgr->startOperation();
1209 foreach (ObjectPtr aObj, theList)
1211 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1213 DocumentPtr aDoc = aPart->document();
1214 if (aDoc == aMgr->activeDocument()) {
1217 //aMgr->moduleDocument()->removeFeature(aPart->owner());
1219 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1221 aObj->document()->removeFeature(aFeature);
1224 myDisplayer->updateViewer();
1225 aMgr->finishOperation();
1229 //**************************************************************
1230 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1232 foreach (ObjectPtr aObj, theList)
1234 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
1237 myDisplayer->display(aRes, false);
1239 myDisplayer->erase(aRes, false);
1243 myDisplayer->updateViewer();
1246 //**************************************************************
1247 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1249 myDisplayer->eraseAll(false);
1250 showObjects(theList, true);
1254 //**************************************************************
1255 void XGUI_Workshop::updateCommandsOnViewSelection()
1257 XGUI_Selection* aSelection = mySelector->selection();
1258 if (aSelection->getSelected().size() == 0)
1261 // Restrict validators to manage only nested (child) features
1262 // of the current feature i.e. if current feature is Sketch -
1263 // Sketch Features & Constraints can be validated.
1264 QStringList aNestedIds;
1265 if(myOperationMgr->hasOperation()) {
1266 FeaturePtr aFeature = myOperationMgr->currentOperation()->feature();
1268 aNestedIds << myActionsMgr->nestedCommands(QString::fromStdString(aFeature->getKind()));
1271 SessionPtr aMgr = ModelAPI_Session::get();
1272 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1273 QList<QAction*> aActions = getModuleCommands();
1274 foreach(QAction* aAction, aActions) {
1275 QString aId = aAction->data().toString();
1276 if(!aNestedIds.contains(aId))
1278 std::list<ModelAPI_Validator*> aValidators;
1279 std::list<std::list<std::string> > anArguments;
1280 aFactory->validators(aId.toStdString(), aValidators, anArguments);
1281 std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
1282 for (; aValidator != aValidators.end(); aValidator++) {
1284 const ModuleBase_SelectionValidator* aSelValidator =
1285 dynamic_cast<const ModuleBase_SelectionValidator*>(*aValidator);
1286 if (aSelValidator) {
1287 aAction->setEnabled(aSelValidator->isValid(aSelection));
1294 //**************************************************************
1295 void XGUI_Workshop::registerValidators() const
1297 SessionPtr aMgr = ModelAPI_Session::get();
1298 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1301 //**************************************************************
1302 void XGUI_Workshop::displayAllResults()
1304 SessionPtr aMgr = ModelAPI_Session::get();
1305 DocumentPtr aRootDoc = aMgr->moduleDocument();
1306 displayDocumentResults(aRootDoc);
1307 for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1308 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1309 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1310 displayDocumentResults(aPart->partDoc());
1312 myDisplayer->updateViewer();
1315 //**************************************************************
1316 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1320 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1321 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1324 //**************************************************************
1325 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1327 for (int i = 0; i < theDoc->size(theGroup); i++)
1328 myDisplayer->display(theDoc->object(theGroup, i), false);
1331 //**************************************************************
1332 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1334 foreach(ObjectPtr aObj, theList) {
1335 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1337 if (theList.size() > 0)
1338 myDisplayer->updateViewer();
1341 //**************************************************************
1342 void XGUI_Workshop::closeDocument()
1344 myDisplayer->closeLocalContexts();
1345 myDisplayer->eraseAll();
1346 objectBrowser()->clearContent();
1348 SessionPtr aMgr = ModelAPI_Session::get();
1350 objectBrowser()->clearContent();