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>
20 #include <AppElements_Workbench.h>
21 #include <AppElements_Viewer.h>
22 #include <AppElements_Command.h>
23 #include <AppElements_MainMenu.h>
24 #include <AppElements_MainWindow.h>
25 #include <AppElements_MenuGroupPanel.h>
27 #include <ModuleBase_IModule.h>
28 #include <ModuleBase_Preferences.h>
30 #include <ModelAPI_Events.h>
31 #include <ModelAPI_Session.h>
32 #include <ModelAPI_Feature.h>
33 #include <ModelAPI_Data.h>
34 #include <ModelAPI_AttributeDocRef.h>
35 #include <ModelAPI_Object.h>
36 #include <ModelAPI_Validator.h>
37 #include <ModelAPI_ResultConstruction.h>
38 #include <ModelAPI_ResultBody.h>
40 //#include <PartSetPlugin_Part.h>
42 #include <Events_Loop.h>
43 #include <Events_Error.h>
44 #include <Events_LongOp.h>
46 #include <ModuleBase_Operation.h>
47 #include <ModuleBase_Operation.h>
48 #include <ModuleBase_OperationDescription.h>
49 #include <ModuleBase_SelectionValidator.h>
50 #include <ModuleBase_WidgetFactory.h>
51 #include <ModuleBase_Tools.h>
52 #include <ModuleBase_IViewer.h>
53 #include<ModuleBase_FilterFactory.h>
55 #include <Config_Common.h>
56 #include <Config_FeatureMessage.h>
57 #include <Config_PointerMessage.h>
58 #include <Config_ModuleReader.h>
59 #include <Config_PropManager.h>
60 #include <Config_SelectionFilterMessage.h>
62 #include <QApplication>
63 #include <QFileDialog>
64 #include <QMessageBox>
65 #include <QMdiSubWindow>
66 #include <QPushButton>
67 #include <QDockWidget>
83 QMap<QString, QString> XGUI_Workshop::myIcons;
86 QIcon XGUI_Workshop::featureIcon(const FeaturePtr& theFeature)
90 std::string aKind = theFeature->getKind();
91 QString aId(aKind.c_str());
92 if (!myIcons.contains(aId))
95 QString anIconString = myIcons[aId];
97 ModelAPI_ExecState aState = theFeature->data()->execState();
99 case ModelAPI_StateDone:
100 case ModelAPI_StateNothing: {
101 anIcon = QIcon(anIconString);
104 case ModelAPI_StateMustBeUpdated: {
105 anIcon = ModuleBase_Tools::lighter(anIconString);
108 case ModelAPI_StateExecFailed: {
109 anIcon = ModuleBase_Tools::composite(":pictures/exec_state_failed.png", anIconString);
112 case ModelAPI_StateInvalidArgument: {
113 anIcon = ModuleBase_Tools::composite(":pictures/exec_state_invalid_parameters.png",
122 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
124 myCurrentDir(QString()),
126 mySalomeConnector(theConnector),
130 myUpdatePrefs(false),
131 myPartActivating(false)
133 myMainWindow = mySalomeConnector ? 0 : new AppElements_MainWindow();
135 myDisplayer = new XGUI_Displayer(this);
137 mySelector = new XGUI_SelectionMgr(this);
138 //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
140 myOperationMgr = new XGUI_OperationMgr(this);
141 myActionsMgr = new XGUI_ActionsMgr(this);
142 myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
143 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
144 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
145 SLOT(onContextMenuCommand(const QString&, bool)));
147 myViewerProxy = new XGUI_ViewerProxy(this);
148 connect(myViewerProxy, SIGNAL(selectionChanged()),
149 myActionsMgr, SLOT(updateOnViewSelection()));
151 myModuleConnector = new XGUI_ModuleConnector(this);
153 connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
154 SLOT(onOperationStarted(ModuleBase_Operation*)));
155 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
156 SLOT(onOperationResumed(ModuleBase_Operation*)));
157 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
158 SLOT(onOperationStopped(ModuleBase_Operation*)));
159 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
160 SLOT(onOperationCommitted(ModuleBase_Operation*)));
161 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
162 SLOT(onOperationAborted(ModuleBase_Operation*)));
163 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
164 connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
167 //******************************************************
168 XGUI_Workshop::~XGUI_Workshop(void)
173 //******************************************************
174 void XGUI_Workshop::startApplication()
178 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
179 Config_Prop::Directory, "");
181 //Initialize event listening
182 Events_Loop* aLoop = Events_Loop::loop();
183 aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
184 aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
185 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
186 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
187 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
188 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
189 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
190 aLoop->registerListener(this, Events_LongOp::eventID());
191 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
192 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
193 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOSHOW));
194 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
195 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED));
197 registerValidators();
199 // Calling of loadCustomProps before activating module is required
200 // by Config_PropManger to restore user-defined path to plugins
201 ModuleBase_Preferences::loadCustomProps();
204 myMainWindow->show();
205 updateCommandStatus();
211 //******************************************************
212 void XGUI_Workshop::initMenu()
214 myContextMenuMgr->createActions();
216 if (isSalomeMode()) {
217 // Create only Undo, Redo commands
218 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
219 tr("Undo last command"),
220 QIcon(":pictures/undo.png"),
221 QKeySequence::Undo, false, "MEN_DESK_EDIT");
222 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
223 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
224 QIcon(":pictures/redo.png"), QKeySequence::Redo,
225 false, "MEN_DESK_EDIT");
226 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
227 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
228 aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
229 QIcon(":pictures/rebuild.png"), QKeySequence(),
230 false, "MEN_DESK_EDIT");
231 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
232 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
234 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export NewGeom..."), tr("Export the current document into a NewGeom file"),
235 QIcon(), QKeySequence(),
236 false, "MEN_DESK_FILE");
237 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
239 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import NewGeom..."), tr("Import a NewGeom file"),
240 QIcon(), QKeySequence(),
241 false, "MEN_DESK_FILE");
242 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
243 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
247 // File commands group
248 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
250 AppElements_Command* aCommand;
252 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
253 QIcon(":pictures/save.png"), QKeySequence::Save);
254 aCommand->connectTo(this, SLOT(onSave()));
255 //aCommand->disable();
257 aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
258 QIcon(":pictures/undo.png"), QKeySequence::Undo);
259 aCommand->connectTo(this, SLOT(onUndo()));
261 aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
262 QIcon(":pictures/redo.png"), QKeySequence::Redo);
263 aCommand->connectTo(this, SLOT(onRedo()));
265 aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
266 QIcon(":pictures/rebuild.png"), QKeySequence());
267 aCommand->connectTo(this, SLOT(onRebuild()));
269 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
270 QIcon(":pictures/save.png"), QKeySequence());
271 aCommand->connectTo(this, SLOT(onSaveAs()));
272 //aCommand->disable();
274 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
275 QIcon(":pictures/open.png"), QKeySequence::Open);
276 aCommand->connectTo(this, SLOT(onOpen()));
278 //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
279 // QIcon(":pictures/new.png"), QKeySequence::New);
280 //aCommand->connectTo(this, SLOT(onNew()));
282 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
283 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
284 aCommand->connectTo(this, SLOT(onPreferences()));
286 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
287 QIcon(":pictures/close.png"), QKeySequence::Close);
288 aCommand->connectTo(this, SLOT(onExit()));
289 //FIXME: SBH's test action. Can be used for some GUI tests.
291 // aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
292 // QIcon(":pictures/close.png"), QKeySequence(), true);
293 // aCommand->connectTo(myMainWindow, SLOT(dockPythonConsole()));
297 //******************************************************
298 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
300 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
301 return aMenuBar->addWorkbench(theName);
304 //******************************************************
305 void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessage)
307 if (QApplication::instance()->thread() != QThread::currentThread()) {
309 std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
311 SessionPtr aMgr = ModelAPI_Session::get();
312 PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(theMessage);
313 QApplication::postEvent(this, aPostponeEvent);
317 //A message to start feature creation received.
318 if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
319 std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
320 std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
321 if (!aFeatureMsg->isInternal()) {
322 addFeature(aFeatureMsg);
325 // Process creation of Part
326 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
327 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
328 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
329 onFeatureCreatedMsg(aUpdMsg);
331 if (mySalomeConnector)
332 mySalomeConnector->createPreferences();
333 myUpdatePrefs = false;
336 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
337 myUpdatePrefs = true;
340 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
341 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
342 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
343 onFeatureRedisplayMsg(aUpdMsg);
345 //Update property panel on corresponding message. If there is no current operation (no
346 //property panel), or received message has different feature to the current - do nothing.
347 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
348 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
349 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
350 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);
355 } else if (theMessage->eventID() == Events_LongOp::eventID()) {
356 if (Events_LongOp::isPerformed()) {
357 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
359 QApplication::restoreOverrideCursor();
361 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW)) {
362 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
363 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
364 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
365 QObjectPtrList aList;
366 std::set<ObjectPtr>::const_iterator aIt;
367 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
369 showObjects(aList, true);
370 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE)) {
371 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
372 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
373 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
374 QObjectPtrList aList;
375 std::set<ObjectPtr>::const_iterator aIt;
376 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
378 showObjects(aList, false);
380 //An operation passed by message. Start it, process and commit.
381 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
382 std::shared_ptr<Config_PointerMessage> aPartSetMsg =
383 std::dynamic_pointer_cast<Config_PointerMessage>(theMessage);
384 //myPropertyPanel->cleanContent();
385 ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
387 if (myOperationMgr->startOperation(anOperation)) {
388 myPropertyPanel->updateContentWidget(anOperation->feature());
389 if (!anOperation->getDescription()->hasXmlRepresentation()) {
390 if (anOperation->commit())
391 updateCommandStatus();
394 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
395 myActionsMgr->update();
396 // Find and Activate active part
397 if (myPartActivating)
399 SessionPtr aMgr = ModelAPI_Session::get();
400 DocumentPtr aActiveDoc = aMgr->activeDocument();
401 DocumentPtr aDoc = aMgr->moduleDocument();
402 if (aActiveDoc == aDoc) {
403 activatePart(ResultPartPtr());
406 std::string aGrpName = ModelAPI_ResultPart::group();
407 for (int i = 0; i < aDoc->size(aGrpName); i++) {
408 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
409 if (aPart->partDoc() == aActiveDoc) {
410 activatePart(aPart); // Activate a part which corresponds to active Doc
414 // If not found then activate global document
415 activatePart(ResultPartPtr());
418 else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) {
419 std::shared_ptr<Config_SelectionFilterMessage> aMsg =
420 std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
422 ModuleBase_FilterFactory* aFactory = moduleConnector()->selectionFilters();
423 if (!aMsg->attributeId().empty()) {
424 aFactory->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId(),
432 //Show error dialog if error message received.
433 std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
435 emit errorOccurred(QString::fromLatin1(anAppError->description()));
438 if (!isSalomeMode()) {
439 SessionPtr aMgr = ModelAPI_Session::get();
440 if (aMgr->isModified() != myMainWindow->isModifiedState())
441 myMainWindow->setModifiedState(aMgr->isModified());
446 //******************************************************
447 void XGUI_Workshop::onStartWaiting()
449 if (Events_LongOp::isPerformed()) {
450 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
454 //******************************************************
455 void XGUI_Workshop::onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
457 std::set<ObjectPtr> aFeatures = theMsg->objects();
458 if (myOperationMgr->hasOperation()) {
459 FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
460 std::set<ObjectPtr>::const_iterator aIt;
461 for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
462 ObjectPtr aNewFeature = (*aIt);
463 if (aNewFeature == aCurrentFeature) {
464 myPropertyPanel->updateContentWidget(aCurrentFeature);
469 myOperationMgr->onValidateOperation();
471 myObjectBrowser->processEvent(theMsg);
474 //******************************************************
475 void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
477 std::set<ObjectPtr> aObjects = theMsg->objects();
478 std::set<ObjectPtr>::const_iterator aIt;
479 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
480 ObjectPtr aObj = (*aIt);
481 bool aHide = !aObj->data() || !aObj->data()->isValid();
482 if (!aHide) { // check that this is not hidden result
483 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
484 aHide = aRes && aRes->isConcealed();
487 myDisplayer->erase(aObj, false);
489 if (myDisplayer->isVisible(aObj)) {
490 displayObject(aObj); // In order to update presentation
491 if (myOperationMgr->hasOperation()) {
492 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
493 if (!aOperation->isEditOperation() &&
494 aOperation->hasObject(aObj) && myDisplayer->isActive(aObj))
495 myDisplayer->deactivate(aObj);
498 if (myOperationMgr->hasOperation()) {
499 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
500 // Display only current operation results if operation has preview
501 if (aOperation->hasObject(aObj)/* && aOperation->hasPreview()*/) {
503 // Deactivate object of current operation from selection
504 if (myDisplayer->isActive(aObj))
505 myDisplayer->deactivate(aObj);
511 myDisplayer->updateViewer();
514 //******************************************************
515 void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
517 std::set<ObjectPtr> aObjects = theMsg->objects();
519 std::set<ObjectPtr>::const_iterator aIt;
520 bool aHasPart = false;
521 bool isDisplayed = false;
522 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
523 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
526 // If a feature is created from the aplication's python console
527 // it doesn't stored in the operation mgr and doesn't displayed
528 } else if (myOperationMgr->hasOperation()) {
529 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
530 if (aOperation->hasObject(*aIt)) { // Display only current operation results
537 myObjectBrowser->processEvent(theMsg);
539 myDisplayer->updateViewer();
540 //if (aHasPart) { // TODO: Avoid activate last part on loading of document
541 // activateLastPart();
545 //******************************************************
546 void XGUI_Workshop::onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg)
549 myObjectBrowser->processEvent(theMsg);
550 //std::set<ObjectPtr> aFeatures = theMsg->objects();
553 //******************************************************
554 void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
556 setNestedFeatures(theOperation);
558 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
559 connectWithOperation(theOperation);
560 setPropertyPanel(theOperation);
562 updateCommandStatus();
564 myModule->operationStarted(theOperation);
567 //******************************************************
568 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
570 setNestedFeatures(theOperation);
572 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
573 connectWithOperation(theOperation);
574 setPropertyPanel(theOperation);
576 updateCommandStatus();
578 myModule->operationResumed(theOperation);
582 //******************************************************
583 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
585 ModuleBase_ISelection* aSel = mySelector->selection();
586 QObjectPtrList aObj = aSel->selectedPresentations();
587 //!< No need for property panel
588 updateCommandStatus();
590 myPropertyPanel->cleanContent();
592 // Activate objects created by current operation
593 // in order to clean selection modes
595 myDisplayer->activateObjects(aModes);
596 myModule->operationStopped(theOperation);
600 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
602 myModule->operationCommitted(theOperation);
605 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
607 myModule->operationAborted(theOperation);
610 void XGUI_Workshop::setNestedFeatures(ModuleBase_Operation* theOperation)
612 if (this->isSalomeMode())
613 theOperation->setNestedFeatures(mySalomeConnector->nestedActions(theOperation->id()));
615 theOperation->setNestedFeatures(myActionsMgr->nestedCommands(theOperation->id()));
618 void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
621 QString aXmlRepr = theOperation->getDescription()->xmlRepresentation();
622 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
625 myPropertyPanel->cleanContent();
626 aFactory.createWidget(myPropertyPanel->contentWidget());
627 ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget());
629 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
630 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
631 aWidget->setFeature(theOperation->feature());
632 aWidget->enableFocusProcessing();
633 QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
634 // Init default values
635 if (!theOperation->isEditOperation() && !aWidget->isComputedDefault()) {
636 aWidget->storeValue();
640 myPropertyPanel->setModelWidgets(aWidgets);
641 theOperation->setPropertyPanel(myPropertyPanel);
643 myModule->propertyPanelDefined(theOperation);
645 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
648 bool XGUI_Workshop::event(QEvent * theEvent)
650 PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
652 std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
653 processEvent(aEventPtr);
662 void XGUI_Workshop::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
666 qDebug() << "XGUI_Workshop::addFeature: NULL message.";
670 // Remember features icons
671 myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon());
673 //Find or create Workbench
674 QString aWchName = QString::fromStdString(theMessage->workbenchId());
675 QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
676 bool isUsePropPanel = theMessage->isUseInput();
677 QString aFeatureId = QString::fromStdString(theMessage->id());
678 if (isSalomeMode()) {
679 QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureId,
680 QString::fromStdString(theMessage->text()),
681 QString::fromStdString(theMessage->tooltip()),
682 QIcon(theMessage->icon().c_str()),
685 salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ", QString::SkipEmptyParts));
686 salomeConnector()->setDocumentKind(aFeatureId, QString::fromStdString(theMessage->documentKind()));
688 myActionsMgr->addCommand(aAction);
689 myModule->actionCreated(aAction);
692 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
693 AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
695 aPage = addWorkbench(aWchName);
697 //Find or create Group
698 QString aGroupName = QString::fromStdString(theMessage->groupId());
699 AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
701 aGroup = aPage->addGroup(aGroupName);
703 QString aDocKind = QString::fromStdString(theMessage->documentKind());
704 // Check if hotkey sequence is already defined:
705 QKeySequence aHotKey = myActionsMgr->registerShortcut(
706 QString::fromStdString(theMessage->keysequence()));
708 AppElements_Command* aCommand = aGroup->addFeature(aFeatureId,
709 QString::fromStdString(theMessage->text()),
710 QString::fromStdString(theMessage->tooltip()),
711 QIcon(theMessage->icon().c_str()),
715 aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts));
716 myActionsMgr->addCommand(aCommand);
717 myModule->actionCreated(aCommand);
722 * Makes a signal/slot connections between Property Panel
723 * and given operation. The given operation becomes a
724 * current operation and previous operation if exists
726 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
728 QAction* aCommand = 0;
729 if (isSalomeMode()) {
730 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
732 AppElements_MainMenu* aMenu = myMainWindow->menuObject();
733 FeaturePtr aFeature = theOperation->feature();
735 aCommand = aMenu->feature(QString::fromStdString(aFeature->getKind()));
737 //Abort operation on uncheck the command
739 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
744 * Saves document with given name.
746 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
748 QApplication::restoreOverrideCursor();
749 SessionPtr aMgr = ModelAPI_Session::get();
750 aMgr->save(theName.toLatin1().constData(), theFileNames);
751 QApplication::restoreOverrideCursor();
754 bool XGUI_Workshop::isActiveOperationAborted()
756 return myOperationMgr->abortAllOperations();
759 //******************************************************
760 void XGUI_Workshop::onExit()
762 SessionPtr aMgr = ModelAPI_Session::get();
763 if (aMgr->isModified()) {
764 int anAnswer = QMessageBox::question(
765 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
766 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
767 if (anAnswer == QMessageBox::Save) {
768 bool saved = onSave();
772 } else if (anAnswer == QMessageBox::Cancel) {
779 //******************************************************
780 void XGUI_Workshop::onNew()
782 QApplication::setOverrideCursor(Qt::WaitCursor);
783 if (objectBrowser() == 0) {
785 mySelector->connectViewers();
787 myViewerProxy->connectToViewer();
789 if (!isSalomeMode()) {
790 myMainWindow->showPythonConsole();
791 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
792 aWnd->showMaximized();
793 updateCommandStatus();
795 myContextMenuMgr->connectViewer();
796 QApplication::restoreOverrideCursor();
799 //******************************************************
800 void XGUI_Workshop::onOpen()
802 if(!isActiveOperationAborted())
804 //save current file before close if modified
805 SessionPtr aSession = ModelAPI_Session::get();
806 if (aSession->isModified()) {
807 //TODO(sbh): re-launch the app?
808 int anAnswer = QMessageBox::question(
809 myMainWindow, tr("Save current file"),
810 tr("The document is modified, save before opening another?"),
811 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
812 if (anAnswer == QMessageBox::Save) {
814 } else if (anAnswer == QMessageBox::Cancel) {
817 aSession->closeAll();
821 //show file dialog, check if readable and open
822 myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
823 if (myCurrentDir.isEmpty())
825 QFileInfo aFileInfo(myCurrentDir);
826 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
827 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
831 QApplication::setOverrideCursor(Qt::WaitCursor);
832 aSession->load(myCurrentDir.toLatin1().constData());
833 myObjectBrowser->rebuildDataTree();
835 updateCommandStatus();
836 QApplication::restoreOverrideCursor();
839 //******************************************************
840 bool XGUI_Workshop::onSave()
842 if(!isActiveOperationAborted())
844 if (myCurrentDir.isEmpty()) {
847 std::list<std::string> aFiles;
848 saveDocument(myCurrentDir, aFiles);
849 updateCommandStatus();
851 myMainWindow->setModifiedState(false);
855 //******************************************************
856 bool XGUI_Workshop::onSaveAs()
858 if(!isActiveOperationAborted())
860 QFileDialog dialog(mainWindow());
861 dialog.setWindowTitle(tr("Select directory to save files..."));
862 dialog.setFileMode(QFileDialog::Directory);
863 dialog.setFilter(tr("Folders (*)"));
864 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
865 dialog.setViewMode(QFileDialog::Detail);
867 if (!dialog.exec()) {
870 QString aTempDir = dialog.selectedFiles().first();
872 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
873 int answer = QMessageBox::question(
875 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
877 tr("The folder already contains some files, save anyway?"),
878 QMessageBox::Save | QMessageBox::Cancel);
879 if (answer == QMessageBox::Cancel) {
883 myCurrentDir = aTempDir;
884 if (!isSalomeMode()) {
885 myMainWindow->setCurrentDir(myCurrentDir, false);
886 myMainWindow->setModifiedState(false);
891 //******************************************************
892 void XGUI_Workshop::onUndo()
894 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
895 SessionPtr aMgr = ModelAPI_Session::get();
896 if (aMgr->isOperation())
897 operationMgr()->onAbortOperation();
899 updateCommandStatus();
902 //******************************************************
903 void XGUI_Workshop::onRedo()
905 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
906 SessionPtr aMgr = ModelAPI_Session::get();
907 if (aMgr->isOperation())
908 operationMgr()->onAbortOperation();
910 updateCommandStatus();
913 //******************************************************
914 void XGUI_Workshop::onRebuild()
916 SessionPtr aMgr = ModelAPI_Session::get();
917 bool aWasOperation = aMgr->isOperation(); // keep this value
918 if (!aWasOperation) {
919 aMgr->startOperation();
921 static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
922 Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
923 new Events_Message(aRebuildEvent, this)));
924 if (!aWasOperation) {
925 aMgr->finishOperation();
929 //******************************************************
930 void XGUI_Workshop::onPreferences()
932 ModuleBase_Prefs aModif;
933 ModuleBase_Preferences::editPreferences(aModif);
934 if (aModif.size() > 0) {
936 foreach (ModuleBase_Pref aPref, aModif)
938 aSection = aPref.first;
939 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
941 myMainWindow->viewer()->updateFromResources();
942 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
944 myMainWindow->menuObject()->updateFromResources();
950 //******************************************************
951 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
953 QString libName = QString::fromStdString(library(theModule.toStdString()));
954 if (libName.isEmpty()) {
955 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
960 CREATE_FUNC crtInst = 0;
963 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
967 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
968 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
969 QString aMsg((char*) &lpMsgBuf);
970 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
971 ::LocalFree(lpMsgBuf);
973 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
977 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
978 | FORMAT_MESSAGE_IGNORE_INSERTS,
979 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
980 QString aMsg((char*) &lpMsgBuf);
981 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
982 ::LocalFree(lpMsgBuf);
986 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
988 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
990 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
992 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
997 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
999 if (!err.isEmpty()) {
1001 Events_Error::send(err.toStdString());
1003 qWarning(qPrintable(err));
1009 //******************************************************
1010 bool XGUI_Workshop::activateModule()
1012 Config_ModuleReader aModuleReader;
1013 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1014 myModule = loadModule(moduleName);
1017 myModule->createFeatures();
1018 myActionsMgr->update();
1022 //******************************************************
1023 void XGUI_Workshop::updateCommandStatus()
1025 QList<QAction*> aCommands;
1026 if (isSalomeMode()) { // update commands in SALOME mode
1027 aCommands = salomeConnector()->commandList();
1029 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1030 foreach (AppElements_Command* aCmd, aMenuBar->features())
1031 aCommands.append(aCmd);
1033 SessionPtr aMgr = ModelAPI_Session::get();
1034 if (aMgr->hasModuleDocument()) {
1035 QAction *aUndoCmd, *aRedoCmd;
1036 foreach(QAction* aCmd, aCommands) {
1037 QString aId = aCmd->data().toString();
1038 if (aId == "UNDO_CMD")
1040 else if (aId == "REDO_CMD")
1043 // Enable all commands
1044 aCmd->setEnabled(true);
1046 aUndoCmd->setEnabled(aMgr->canUndo() && !aMgr->isOperation());
1047 aRedoCmd->setEnabled(aMgr->canRedo() && !aMgr->isOperation());
1049 foreach(QAction* aCmd, aCommands) {
1050 QString aId = aCmd->data().toString();
1051 if (aId == "NEW_CMD")
1052 aCmd->setEnabled(true);
1053 else if (aId == "EXIT_CMD")
1054 aCmd->setEnabled(true);
1056 aCmd->setEnabled(false);
1059 myActionsMgr->update();
1060 emit commandStatusUpdated();
1063 //******************************************************
1064 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1066 QDockWidget* aObjDock = new QDockWidget(theParent);
1067 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1068 aObjDock->setWindowTitle(tr("Object browser"));
1069 aObjDock->setStyleSheet(
1070 "::title { position: relative; padding-left: 5px; text-align: left center }");
1071 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1072 connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this,
1073 SLOT(changeCurrentDocument(ObjectPtr)));
1074 aObjDock->setWidget(myObjectBrowser);
1076 myContextMenuMgr->connectObjectBrowser();
1080 //******************************************************
1082 * Creates dock widgets, places them in corresponding area
1083 * and tabifies if necessary.
1085 void XGUI_Workshop::createDockWidgets()
1087 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1088 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1089 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1090 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
1091 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1093 connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets()));
1095 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1096 hidePropertyPanel(); //<! Invisible by default
1097 hideObjectBrowser();
1098 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1099 myPropertyPanel->installEventFilter(myOperationMgr);
1101 QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(PROP_PANEL_OK);
1102 connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
1103 QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(PROP_PANEL_CANCEL);
1104 connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
1105 connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr,
1106 SLOT(onKeyReleased(QKeyEvent*)));
1107 connect(myOperationMgr, SIGNAL(operationValidated(bool)), myPropertyPanel,
1108 SLOT(setAcceptEnabled(bool)));
1112 //******************************************************
1113 void XGUI_Workshop::showPropertyPanel()
1115 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1116 //<! Restore ability to close panel from the window's menu
1117 aViewAct->setEnabled(true);
1118 myPropertyPanel->show();
1119 myPropertyPanel->raise();
1122 //******************************************************
1123 void XGUI_Workshop::hidePropertyPanel()
1125 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1126 //<! Do not allow to show empty property panel
1127 aViewAct->setEnabled(false);
1128 myPropertyPanel->hide();
1131 //******************************************************
1132 void XGUI_Workshop::showObjectBrowser()
1134 myObjectBrowser->parentWidget()->show();
1137 //******************************************************
1138 void XGUI_Workshop::hideObjectBrowser()
1140 myObjectBrowser->parentWidget()->hide();
1143 //******************************************************
1144 void XGUI_Workshop::onFeatureTriggered()
1146 QAction* aCmd = dynamic_cast<QAction*>(sender());
1148 QString aId = salomeConnector()->commandId(aCmd);
1150 myModule->launchOperation(aId);
1154 //******************************************************
1155 void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
1157 SessionPtr aMgr = ModelAPI_Session::get();
1159 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theObj);
1161 DocumentPtr aPartDoc = aPart->partDoc();
1163 aMgr->setActiveDocument(aPartDoc);
1168 aMgr->setActiveDocument(aMgr->moduleDocument());
1171 //******************************************************
1172 void XGUI_Workshop::salomeViewerSelectionChanged()
1174 emit salomeViewerSelection();
1177 //**************************************************************
1178 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1180 return mySalomeConnector->viewer();
1183 //**************************************************************
1184 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1186 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1187 if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) {
1188 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
1189 activatePart(aPart);
1190 } else if (theId == "DEACTIVATE_PART_CMD")
1191 activatePart(ResultPartPtr());
1192 else if (theId == "DELETE_CMD")
1193 deleteObjects(aObjects);
1194 else if (theId == "SHOW_CMD")
1195 showObjects(aObjects, true);
1196 else if (theId == "HIDE_CMD")
1197 showObjects(aObjects, false);
1198 else if (theId == "SHOW_ONLY_CMD")
1199 showOnlyObjects(aObjects);
1200 else if (theId == "SHADING_CMD")
1201 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1202 else if (theId == "WIREFRAME_CMD")
1203 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1204 else if (theId == "HIDEALL_CMD")
1205 myDisplayer->eraseAll();
1206 else if (theId == "EDIT_CMD") {
1207 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObjects.first());
1209 myModule->editFeature(aFeature);
1213 //**************************************************************
1214 void XGUI_Workshop::onWidgetValuesChanged()
1216 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1217 FeaturePtr aFeature = anOperation->feature();
1219 ModuleBase_ModelWidget* aSenderWidget = dynamic_cast<ModuleBase_ModelWidget*>(sender());
1221 const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
1222 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
1223 for (; anIt != aLast; anIt++) {
1224 ModuleBase_ModelWidget* aCustom = *anIt;
1225 if (aCustom && (aCustom == aSenderWidget)) {
1226 aCustom->storeValue();
1231 //**************************************************************
1232 void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
1234 if (!myPartActivating) {
1235 myPartActivating = true;
1237 theFeature->activate();
1238 changeCurrentDocument(theFeature);
1239 myObjectBrowser->activatePart(theFeature);
1240 myPartActivating = false;
1242 updateCommandStatus();
1245 //**************************************************************
1246 void XGUI_Workshop::activateLastPart()
1248 SessionPtr aMgr = ModelAPI_Session::get();
1249 DocumentPtr aDoc = aMgr->moduleDocument();
1250 std::string aGrpName = ModelAPI_ResultPart::group();
1251 ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
1252 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
1254 activatePart(aPart);
1258 //**************************************************************
1259 void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList)
1261 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1262 QMessageBox::StandardButton aRes = QMessageBox::warning(
1263 aDesktop, tr("Delete features"), tr("Seleted features will be deleted. Continue?"),
1264 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1265 // ToDo: definbe deleting method
1266 if (aRes == QMessageBox::Yes) {
1267 SessionPtr aMgr = ModelAPI_Session::get();
1268 aMgr->startOperation();
1269 foreach (ObjectPtr aObj, theList)
1271 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1273 DocumentPtr aDoc = aPart->document();
1274 if (aDoc == aMgr->activeDocument()) {
1277 //aMgr->moduleDocument()->removeFeature(aPart->owner());
1279 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1281 aObj->document()->removeFeature(aFeature);
1284 myDisplayer->updateViewer();
1285 aMgr->finishOperation();
1289 //**************************************************************
1290 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1292 foreach (ObjectPtr aObj, theList)
1295 displayObject(aObj);
1297 myDisplayer->erase(aObj, false);
1300 myDisplayer->updateViewer();
1303 //**************************************************************
1304 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1306 myDisplayer->showOnly(theList);
1310 //**************************************************************
1311 void XGUI_Workshop::registerValidators() const
1313 SessionPtr aMgr = ModelAPI_Session::get();
1314 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1317 //**************************************************************
1318 void XGUI_Workshop::displayAllResults()
1320 SessionPtr aMgr = ModelAPI_Session::get();
1321 DocumentPtr aRootDoc = aMgr->moduleDocument();
1322 displayDocumentResults(aRootDoc);
1323 for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1324 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1325 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1326 displayDocumentResults(aPart->partDoc());
1328 myDisplayer->updateViewer();
1331 //**************************************************************
1332 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1336 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1337 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1340 //**************************************************************
1341 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1343 for (int i = 0; i < theDoc->size(theGroup); i++)
1344 displayObject(theDoc->object(theGroup, i));
1347 //**************************************************************
1348 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1350 foreach(ObjectPtr aObj, theList) {
1351 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1353 if (theList.size() > 0)
1354 myDisplayer->updateViewer();
1357 //**************************************************************
1358 void XGUI_Workshop::closeDocument()
1360 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1361 while (anOperation) {
1362 anOperation->abort();
1363 anOperation = operationMgr()->currentOperation();
1365 myDisplayer->closeLocalContexts();
1366 myDisplayer->eraseAll();
1367 objectBrowser()->clearContent();
1369 SessionPtr aMgr = ModelAPI_Session::get();
1371 objectBrowser()->clearContent();
1374 //**************************************************************
1375 void XGUI_Workshop::displayObject(ObjectPtr theObj)
1377 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
1378 if (aBody.get() != NULL) {
1379 int aNb = myDisplayer->objectsCount();
1380 myDisplayer->display(theObj, false);
1384 myDisplayer->display(theObj, false);