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();
210 emit applicationStarted();
213 //******************************************************
214 void XGUI_Workshop::initMenu()
216 myContextMenuMgr->createActions();
218 if (isSalomeMode()) {
219 // Create only Undo, Redo commands
220 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
221 tr("Undo last command"),
222 QIcon(":pictures/undo.png"),
223 QKeySequence::Undo, false, "MEN_DESK_EDIT");
224 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
225 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
226 QIcon(":pictures/redo.png"), QKeySequence::Redo,
227 false, "MEN_DESK_EDIT");
228 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
229 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
230 aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
231 QIcon(":pictures/rebuild.png"), QKeySequence(),
232 false, "MEN_DESK_EDIT");
233 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
234 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
236 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export NewGeom..."), tr("Export the current document into a NewGeom file"),
237 QIcon(), QKeySequence(),
238 false, "MEN_DESK_FILE");
239 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
241 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import NewGeom..."), tr("Import a NewGeom file"),
242 QIcon(), QKeySequence(),
243 false, "MEN_DESK_FILE");
244 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
245 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
249 // File commands group
250 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
252 AppElements_Command* aCommand;
254 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
255 QIcon(":pictures/save.png"), QKeySequence::Save);
256 aCommand->connectTo(this, SLOT(onSave()));
257 //aCommand->disable();
259 aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
260 QIcon(":pictures/undo.png"), QKeySequence::Undo);
261 aCommand->connectTo(this, SLOT(onUndo()));
263 aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
264 QIcon(":pictures/redo.png"), QKeySequence::Redo);
265 aCommand->connectTo(this, SLOT(onRedo()));
267 aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
268 QIcon(":pictures/rebuild.png"), QKeySequence());
269 aCommand->connectTo(this, SLOT(onRebuild()));
271 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
272 QIcon(":pictures/save.png"), QKeySequence());
273 aCommand->connectTo(this, SLOT(onSaveAs()));
274 //aCommand->disable();
276 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
277 QIcon(":pictures/open.png"), QKeySequence::Open);
278 aCommand->connectTo(this, SLOT(onOpen()));
280 //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
281 // QIcon(":pictures/new.png"), QKeySequence::New);
282 //aCommand->connectTo(this, SLOT(onNew()));
284 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
285 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
286 aCommand->connectTo(this, SLOT(onPreferences()));
288 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
289 QIcon(":pictures/close.png"), QKeySequence::Close);
290 aCommand->connectTo(this, SLOT(onExit()));
291 //FIXME: SBH's test action. Can be used for some GUI tests.
293 // aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
294 // QIcon(":pictures/close.png"), QKeySequence(), true);
295 // aCommand->connectTo(myMainWindow, SLOT(dockPythonConsole()));
299 //******************************************************
300 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
302 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
303 return aMenuBar->addWorkbench(theName);
306 //******************************************************
307 void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessage)
309 if (QApplication::instance()->thread() != QThread::currentThread()) {
311 std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
313 SessionPtr aMgr = ModelAPI_Session::get();
314 PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(theMessage);
315 QApplication::postEvent(this, aPostponeEvent);
319 //A message to start feature creation received.
320 if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
321 std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
322 std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
323 if (!aFeatureMsg->isInternal()) {
324 addFeature(aFeatureMsg);
327 // Process creation of Part
328 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
329 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
330 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
331 onFeatureCreatedMsg(aUpdMsg);
333 if (mySalomeConnector)
334 mySalomeConnector->createPreferences();
335 myUpdatePrefs = false;
338 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
339 myUpdatePrefs = true;
342 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
343 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
344 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
345 onFeatureRedisplayMsg(aUpdMsg);
347 //Update property panel on corresponding message. If there is no current operation (no
348 //property panel), or received message has different feature to the current - do nothing.
349 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
350 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
351 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
352 onFeatureUpdatedMsg(anUpdateMsg);
353 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
354 std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
355 std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
356 onObjectDeletedMsg(aDelMsg);
357 } else if (theMessage->eventID() == Events_LongOp::eventID()) {
358 if (Events_LongOp::isPerformed()) {
359 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
361 QApplication::restoreOverrideCursor();
363 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW)) {
364 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
365 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
366 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
367 QObjectPtrList aList;
368 std::set<ObjectPtr>::const_iterator aIt;
369 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
371 showObjects(aList, true);
372 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE)) {
373 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
374 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
375 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
376 QObjectPtrList aList;
377 std::set<ObjectPtr>::const_iterator aIt;
378 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
380 showObjects(aList, false);
382 //An operation passed by message. Start it, process and commit.
383 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
384 std::shared_ptr<Config_PointerMessage> aPartSetMsg =
385 std::dynamic_pointer_cast<Config_PointerMessage>(theMessage);
386 //myPropertyPanel->cleanContent();
387 ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
389 if (myOperationMgr->startOperation(anOperation)) {
390 myPropertyPanel->updateContentWidget(anOperation->feature());
391 if (!anOperation->getDescription()->hasXmlRepresentation()) {
392 if (anOperation->commit())
393 updateCommandStatus();
396 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
397 myActionsMgr->update();
398 // Find and Activate active part
399 if (myPartActivating)
401 SessionPtr aMgr = ModelAPI_Session::get();
402 DocumentPtr aActiveDoc = aMgr->activeDocument();
403 DocumentPtr aDoc = aMgr->moduleDocument();
404 if (aActiveDoc == aDoc) {
405 activatePart(ResultPartPtr());
408 std::string aGrpName = ModelAPI_ResultPart::group();
409 for (int i = 0; i < aDoc->size(aGrpName); i++) {
410 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
411 if (aPart->partDoc() == aActiveDoc) {
412 activatePart(aPart); // Activate a part which corresponds to active Doc
416 // If not found then activate global document
417 activatePart(ResultPartPtr());
420 else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) {
421 std::shared_ptr<Config_SelectionFilterMessage> aMsg =
422 std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
424 ModuleBase_FilterFactory* aFactory = moduleConnector()->selectionFilters();
425 if (!aMsg->attributeId().empty()) {
426 aFactory->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId(),
434 //Show error dialog if error message received.
435 std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
437 emit errorOccurred(QString::fromLatin1(anAppError->description()));
440 if (!isSalomeMode()) {
441 SessionPtr aMgr = ModelAPI_Session::get();
442 if (aMgr->isModified() != myMainWindow->isModifiedState())
443 myMainWindow->setModifiedState(aMgr->isModified());
447 //******************************************************
448 QMainWindow* XGUI_Workshop::desktop() const
450 return isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
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);
489 bool aHide = !aObj->data() || !aObj->data()->isValid();
490 if (!aHide) { // check that this is not hidden result
491 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
492 aHide = aRes && aRes->isConcealed();
495 myDisplayer->erase(aObj, false);
497 if (myDisplayer->isVisible(aObj)) {
498 displayObject(aObj); // In order to update presentation
499 if (myOperationMgr->hasOperation()) {
500 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
501 if (!aOperation->isEditOperation() &&
502 aOperation->hasObject(aObj) && myDisplayer->isActive(aObj))
503 myDisplayer->deactivate(aObj);
506 if (myOperationMgr->hasOperation()) {
507 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
508 if (myModule->canDisplayObject(aObj)) {
510 // Deactivate object of current operation from selection
511 if (myDisplayer->isActive(aObj))
512 myDisplayer->deactivate(aObj);
518 myDisplayer->updateViewer();
521 //******************************************************
522 void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
524 std::set<ObjectPtr> aObjects = theMsg->objects();
526 std::set<ObjectPtr>::const_iterator aIt;
527 bool aHasPart = false;
528 bool isDisplayed = false;
529 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
531 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
534 // If a feature is created from the aplication's python console
535 // it doesn't stored in the operation mgr and doesn't displayed
536 } else if (myModule->canDisplayObject(*aIt)) {
542 myObjectBrowser->processEvent(theMsg);
544 myDisplayer->updateViewer();
545 //if (aHasPart) { // TODO: Avoid activate last part on loading of document
546 // activateLastPart();
550 //******************************************************
551 void XGUI_Workshop::onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg)
554 myObjectBrowser->processEvent(theMsg);
555 //std::set<ObjectPtr> aFeatures = theMsg->objects();
558 //******************************************************
559 void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
561 setNestedFeatures(theOperation);
563 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
564 connectWithOperation(theOperation);
565 setPropertyPanel(theOperation);
567 updateCommandStatus();
569 myModule->operationStarted(theOperation);
572 //******************************************************
573 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
575 setNestedFeatures(theOperation);
577 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
578 connectWithOperation(theOperation);
579 setPropertyPanel(theOperation);
581 updateCommandStatus();
583 myModule->operationResumed(theOperation);
587 //******************************************************
588 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
590 ModuleBase_ISelection* aSel = mySelector->selection();
591 QObjectPtrList aObj = aSel->selectedPresentations();
592 //!< No need for property panel
593 updateCommandStatus();
595 myPropertyPanel->cleanContent();
597 // Activate objects created by current operation
598 // in order to clean selection modes
600 myDisplayer->activateObjects(aModes);
601 myModule->operationStopped(theOperation);
605 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
607 myModule->operationCommitted(theOperation);
610 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
612 myModule->operationAborted(theOperation);
615 void XGUI_Workshop::setNestedFeatures(ModuleBase_Operation* theOperation)
617 if (this->isSalomeMode())
618 theOperation->setNestedFeatures(mySalomeConnector->nestedActions(theOperation->id()));
620 theOperation->setNestedFeatures(myActionsMgr->nestedCommands(theOperation->id()));
623 void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
626 QString aXmlRepr = theOperation->getDescription()->xmlRepresentation();
627 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
630 myPropertyPanel->cleanContent();
631 aFactory.createWidget(myPropertyPanel->contentWidget());
632 ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget());
634 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
635 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
636 aWidget->setFeature(theOperation->feature());
637 aWidget->enableFocusProcessing();
638 QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
639 // Init default values
640 if (!theOperation->isEditOperation() && aWidget->isValueDefault() && !aWidget->isComputedDefault()) {
641 aWidget->storeValue();
645 myPropertyPanel->setModelWidgets(aWidgets);
646 theOperation->setPropertyPanel(myPropertyPanel);
648 myModule->propertyPanelDefined(theOperation);
650 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
653 bool XGUI_Workshop::event(QEvent * theEvent)
655 PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
657 std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
658 processEvent(aEventPtr);
667 void XGUI_Workshop::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
671 qDebug() << "XGUI_Workshop::addFeature: NULL message.";
675 // Remember features icons
676 myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon());
678 //Find or create Workbench
679 QString aWchName = QString::fromStdString(theMessage->workbenchId());
680 QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
681 bool isUsePropPanel = theMessage->isUseInput();
682 QString aFeatureId = QString::fromStdString(theMessage->id());
683 if (isSalomeMode()) {
684 QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureId,
685 QString::fromStdString(theMessage->text()),
686 QString::fromStdString(theMessage->tooltip()),
687 QIcon(theMessage->icon().c_str()),
690 salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ", QString::SkipEmptyParts));
691 salomeConnector()->setDocumentKind(aFeatureId, QString::fromStdString(theMessage->documentKind()));
693 myActionsMgr->addCommand(aAction);
694 myModule->actionCreated(aAction);
697 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
698 AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
700 aPage = addWorkbench(aWchName);
702 //Find or create Group
703 QString aGroupName = QString::fromStdString(theMessage->groupId());
704 AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
706 aGroup = aPage->addGroup(aGroupName);
708 QString aDocKind = QString::fromStdString(theMessage->documentKind());
709 // Check if hotkey sequence is already defined:
710 QKeySequence aHotKey = myActionsMgr->registerShortcut(
711 QString::fromStdString(theMessage->keysequence()));
713 AppElements_Command* aCommand = aGroup->addFeature(aFeatureId,
714 QString::fromStdString(theMessage->text()),
715 QString::fromStdString(theMessage->tooltip()),
716 QIcon(theMessage->icon().c_str()),
720 aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts));
721 myActionsMgr->addCommand(aCommand);
722 myModule->actionCreated(aCommand);
727 * Makes a signal/slot connections between Property Panel
728 * and given operation. The given operation becomes a
729 * current operation and previous operation if exists
731 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
733 QAction* aCommand = 0;
734 if (isSalomeMode()) {
735 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
737 AppElements_MainMenu* aMenu = myMainWindow->menuObject();
738 FeaturePtr aFeature = theOperation->feature();
740 aCommand = aMenu->feature(QString::fromStdString(aFeature->getKind()));
742 //Abort operation on uncheck the command
744 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
749 * Saves document with given name.
751 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
753 QApplication::restoreOverrideCursor();
754 SessionPtr aMgr = ModelAPI_Session::get();
755 aMgr->save(theName.toLatin1().constData(), theFileNames);
756 QApplication::restoreOverrideCursor();
759 bool XGUI_Workshop::isActiveOperationAborted()
761 return myOperationMgr->abortAllOperations();
764 //******************************************************
765 void XGUI_Workshop::onExit()
767 SessionPtr aMgr = ModelAPI_Session::get();
768 if (aMgr->isModified()) {
769 int anAnswer = QMessageBox::question(
770 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
771 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
772 if (anAnswer == QMessageBox::Save) {
773 bool saved = onSave();
777 } else if (anAnswer == QMessageBox::Cancel) {
784 //******************************************************
785 void XGUI_Workshop::onNew()
787 QApplication::setOverrideCursor(Qt::WaitCursor);
788 if (objectBrowser() == 0) {
790 mySelector->connectViewers();
792 myViewerProxy->connectToViewer();
794 if (!isSalomeMode()) {
795 myMainWindow->showPythonConsole();
796 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
797 aWnd->showMaximized();
798 updateCommandStatus();
800 myContextMenuMgr->connectViewer();
801 QApplication::restoreOverrideCursor();
804 //******************************************************
805 void XGUI_Workshop::onOpen()
807 if(!isActiveOperationAborted())
809 //save current file before close if modified
810 SessionPtr aSession = ModelAPI_Session::get();
811 if (aSession->isModified()) {
812 //TODO(sbh): re-launch the app?
813 int anAnswer = QMessageBox::question(
814 myMainWindow, tr("Save current file"),
815 tr("The document is modified, save before opening another?"),
816 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
817 if (anAnswer == QMessageBox::Save) {
819 } else if (anAnswer == QMessageBox::Cancel) {
822 aSession->closeAll();
826 //show file dialog, check if readable and open
827 myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
828 if (myCurrentDir.isEmpty())
830 QFileInfo aFileInfo(myCurrentDir);
831 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
832 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
836 QApplication::setOverrideCursor(Qt::WaitCursor);
837 aSession->load(myCurrentDir.toLatin1().constData());
838 myObjectBrowser->rebuildDataTree();
840 updateCommandStatus();
841 QApplication::restoreOverrideCursor();
844 //******************************************************
845 bool XGUI_Workshop::onSave()
847 if(!isActiveOperationAborted())
849 if (myCurrentDir.isEmpty()) {
852 std::list<std::string> aFiles;
853 saveDocument(myCurrentDir, aFiles);
854 updateCommandStatus();
856 myMainWindow->setModifiedState(false);
860 //******************************************************
861 bool XGUI_Workshop::onSaveAs()
863 if(!isActiveOperationAborted())
865 QFileDialog dialog(mainWindow());
866 dialog.setWindowTitle(tr("Select directory to save files..."));
867 dialog.setFileMode(QFileDialog::Directory);
868 dialog.setFilter(tr("Folders (*)"));
869 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
870 dialog.setViewMode(QFileDialog::Detail);
872 if (!dialog.exec()) {
875 QString aTempDir = dialog.selectedFiles().first();
877 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
878 int answer = QMessageBox::question(
880 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
882 tr("The folder already contains some files, save anyway?"),
883 QMessageBox::Save | QMessageBox::Cancel);
884 if (answer == QMessageBox::Cancel) {
888 myCurrentDir = aTempDir;
889 if (!isSalomeMode()) {
890 myMainWindow->setCurrentDir(myCurrentDir, false);
891 myMainWindow->setModifiedState(false);
896 //******************************************************
897 void XGUI_Workshop::onUndo()
899 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
900 SessionPtr aMgr = ModelAPI_Session::get();
901 if (aMgr->isOperation())
902 operationMgr()->onAbortOperation();
904 updateCommandStatus();
907 //******************************************************
908 void XGUI_Workshop::onRedo()
910 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
911 SessionPtr aMgr = ModelAPI_Session::get();
912 if (aMgr->isOperation())
913 operationMgr()->onAbortOperation();
915 updateCommandStatus();
918 //******************************************************
919 void XGUI_Workshop::onRebuild()
921 SessionPtr aMgr = ModelAPI_Session::get();
922 bool aWasOperation = aMgr->isOperation(); // keep this value
923 if (!aWasOperation) {
924 aMgr->startOperation();
926 static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
927 Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
928 new Events_Message(aRebuildEvent, this)));
929 if (!aWasOperation) {
930 aMgr->finishOperation();
934 //******************************************************
935 void XGUI_Workshop::onPreferences()
937 ModuleBase_Prefs aModif;
938 ModuleBase_Preferences::editPreferences(aModif);
939 if (aModif.size() > 0) {
941 foreach (ModuleBase_Pref aPref, aModif)
943 aSection = aPref.first;
944 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
946 myMainWindow->viewer()->updateFromResources();
947 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
949 myMainWindow->menuObject()->updateFromResources();
955 //******************************************************
956 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
958 QString libName = QString::fromStdString(library(theModule.toStdString()));
959 if (libName.isEmpty()) {
960 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
965 CREATE_FUNC crtInst = 0;
968 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
972 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
973 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
974 QString aMsg((char*) &lpMsgBuf);
975 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
976 ::LocalFree(lpMsgBuf);
978 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
982 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
983 | FORMAT_MESSAGE_IGNORE_INSERTS,
984 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
985 QString aMsg((char*) &lpMsgBuf);
986 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
987 ::LocalFree(lpMsgBuf);
991 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
993 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
995 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
997 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1002 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1004 if (!err.isEmpty()) {
1006 Events_Error::send(err.toStdString());
1008 qWarning(qPrintable(err));
1014 //******************************************************
1015 bool XGUI_Workshop::activateModule()
1017 Config_ModuleReader aModuleReader;
1018 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1019 myModule = loadModule(moduleName);
1022 myModule->createFeatures();
1023 myActionsMgr->update();
1027 //******************************************************
1028 void XGUI_Workshop::updateCommandStatus()
1030 QList<QAction*> aCommands;
1031 if (isSalomeMode()) { // update commands in SALOME mode
1032 aCommands = salomeConnector()->commandList();
1034 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1035 foreach (AppElements_Command* aCmd, aMenuBar->features())
1036 aCommands.append(aCmd);
1038 SessionPtr aMgr = ModelAPI_Session::get();
1039 if (aMgr->hasModuleDocument()) {
1040 QAction *aUndoCmd, *aRedoCmd;
1041 foreach(QAction* aCmd, aCommands) {
1042 QString aId = aCmd->data().toString();
1043 if (aId == "UNDO_CMD")
1045 else if (aId == "REDO_CMD")
1048 // Enable all commands
1049 aCmd->setEnabled(true);
1051 aUndoCmd->setEnabled(aMgr->canUndo() && !aMgr->isOperation());
1052 aRedoCmd->setEnabled(aMgr->canRedo() && !aMgr->isOperation());
1054 foreach(QAction* aCmd, aCommands) {
1055 QString aId = aCmd->data().toString();
1056 if (aId == "NEW_CMD")
1057 aCmd->setEnabled(true);
1058 else if (aId == "EXIT_CMD")
1059 aCmd->setEnabled(true);
1061 aCmd->setEnabled(false);
1064 myActionsMgr->update();
1065 emit commandStatusUpdated();
1068 //******************************************************
1069 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1071 QDockWidget* aObjDock = new QDockWidget(theParent);
1072 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1073 aObjDock->setWindowTitle(tr("Object browser"));
1074 aObjDock->setStyleSheet(
1075 "::title { position: relative; padding-left: 5px; text-align: left center }");
1076 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1077 connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this,
1078 SLOT(changeCurrentDocument(ObjectPtr)));
1079 aObjDock->setWidget(myObjectBrowser);
1081 myContextMenuMgr->connectObjectBrowser();
1085 //******************************************************
1087 * Creates dock widgets, places them in corresponding area
1088 * and tabifies if necessary.
1090 void XGUI_Workshop::createDockWidgets()
1092 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1093 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1094 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1095 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
1096 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1098 connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets()));
1100 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1101 hidePropertyPanel(); ///<! Invisible by default
1102 hideObjectBrowser();
1103 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1104 myPropertyPanel->installEventFilter(myOperationMgr);
1106 QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(PROP_PANEL_OK);
1107 connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
1108 QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(PROP_PANEL_CANCEL);
1109 connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
1110 connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr,
1111 SLOT(onKeyReleased(QKeyEvent*)));
1112 connect(myOperationMgr, SIGNAL(applyEnableChanged(bool)), myPropertyPanel,
1113 SLOT(setAcceptEnabled(bool)));
1117 //******************************************************
1118 void XGUI_Workshop::showPropertyPanel()
1120 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1121 ///<! Restore ability to close panel from the window's menu
1122 aViewAct->setEnabled(true);
1123 myPropertyPanel->show();
1124 myPropertyPanel->raise();
1127 //******************************************************
1128 void XGUI_Workshop::hidePropertyPanel()
1130 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1131 ///<! Do not allow to show empty property panel
1132 aViewAct->setEnabled(false);
1133 myPropertyPanel->hide();
1136 //******************************************************
1137 void XGUI_Workshop::showObjectBrowser()
1139 myObjectBrowser->parentWidget()->show();
1142 //******************************************************
1143 void XGUI_Workshop::hideObjectBrowser()
1145 myObjectBrowser->parentWidget()->hide();
1148 //******************************************************
1149 void XGUI_Workshop::onFeatureTriggered()
1151 QAction* aCmd = dynamic_cast<QAction*>(sender());
1153 QString aId = salomeConnector()->commandId(aCmd);
1155 myModule->launchOperation(aId);
1159 //******************************************************
1160 void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
1162 SessionPtr aMgr = ModelAPI_Session::get();
1164 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theObj);
1166 DocumentPtr aPartDoc = aPart->partDoc();
1168 aMgr->setActiveDocument(aPartDoc);
1173 aMgr->setActiveDocument(aMgr->moduleDocument());
1176 //******************************************************
1177 void XGUI_Workshop::salomeViewerSelectionChanged()
1179 emit salomeViewerSelection();
1182 //**************************************************************
1183 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1185 return mySalomeConnector->viewer();
1188 //**************************************************************
1189 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1191 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1192 if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) {
1193 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
1194 activatePart(aPart);
1195 } else if (theId == "DEACTIVATE_PART_CMD")
1196 activatePart(ResultPartPtr());
1197 else if (theId == "DELETE_CMD")
1198 deleteObjects(aObjects);
1199 else if (theId == "SHOW_CMD")
1200 showObjects(aObjects, true);
1201 else if (theId == "HIDE_CMD")
1202 showObjects(aObjects, false);
1203 else if (theId == "SHOW_ONLY_CMD")
1204 showOnlyObjects(aObjects);
1205 else if (theId == "SHADING_CMD")
1206 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1207 else if (theId == "WIREFRAME_CMD")
1208 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1209 else if (theId == "HIDEALL_CMD")
1210 myDisplayer->eraseAll();
1211 else if (theId == "EDIT_CMD") {
1212 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObjects.first());
1214 myModule->editFeature(aFeature);
1218 //**************************************************************
1219 void XGUI_Workshop::onWidgetValuesChanged()
1221 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1222 FeaturePtr aFeature = anOperation->feature();
1224 ModuleBase_ModelWidget* aSenderWidget = dynamic_cast<ModuleBase_ModelWidget*>(sender());
1226 const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
1227 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
1228 for (; anIt != aLast; anIt++) {
1229 ModuleBase_ModelWidget* aCustom = *anIt;
1230 if (aCustom && (aCustom == aSenderWidget)) {
1231 aCustom->storeValue();
1236 //**************************************************************
1237 void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
1239 if (!myPartActivating) {
1240 myPartActivating = true;
1242 theFeature->activate();
1243 changeCurrentDocument(theFeature);
1244 myObjectBrowser->activatePart(theFeature);
1245 myPartActivating = false;
1247 updateCommandStatus();
1250 //**************************************************************
1251 //void XGUI_Workshop::activateLastPart()
1253 // SessionPtr aMgr = ModelAPI_Session::get();
1254 // DocumentPtr aDoc = aMgr->moduleDocument();
1255 // std::string aGrpName = ModelAPI_ResultPart::group();
1256 // ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
1257 // ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
1259 // activatePart(aPart);
1263 //**************************************************************
1264 void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList)
1266 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1268 std::set<FeaturePtr> aRefFeatures;
1269 foreach (ObjectPtr aObj, theList)
1271 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1273 // TODO: check for what there is this condition. It is placed here historicaly because
1274 // ther is this condition during remove features.
1276 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1277 if (aFeature.get() != NULL) {
1278 aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
1283 if (!aRefFeatures.empty()) {
1284 QStringList aRefNames;
1285 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1286 aLast = aRefFeatures.end();
1287 for (; anIt != aLast; anIt++) {
1288 FeaturePtr aFeature = (*anIt);
1289 std::string aFName = aFeature->data()->name().c_str();
1290 std::string aName = (*anIt)->name().c_str();
1291 aRefNames.append((*anIt)->name().c_str());
1293 QString aNames = aRefNames.join(", ");
1295 QMessageBox::StandardButton aRes = QMessageBox::warning(
1296 aDesktop, tr("Delete features"),
1297 QString(tr("Selected features are used in the following features: %1.\
1298 These features will be deleted also. Would you like to continue?")).arg(aNames),
1299 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1300 if (aRes != QMessageBox::Yes)
1304 SessionPtr aMgr = ModelAPI_Session::get();
1305 aMgr->startOperation();
1306 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1307 aLast = aRefFeatures.end();
1308 for (; anIt != aLast; anIt++) {
1309 FeaturePtr aRefFeature = (*anIt);
1310 DocumentPtr aDoc = aRefFeature->document();
1311 aDoc->removeFeature(aRefFeature);
1315 foreach (ObjectPtr aObj, theList)
1317 DocumentPtr aDoc = aObj->document();
1318 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1320 if (aDoc == aMgr->activeDocument()) {
1324 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1326 aDoc->removeFeature(aFeature);
1331 myDisplayer->updateViewer();
1332 aMgr->finishOperation();
1335 //**************************************************************
1336 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1338 foreach (ObjectPtr aObj, theList)
1341 displayObject(aObj);
1343 myDisplayer->erase(aObj, false);
1346 myDisplayer->updateViewer();
1349 //**************************************************************
1350 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1352 myDisplayer->showOnly(theList);
1356 //**************************************************************
1357 void XGUI_Workshop::registerValidators() const
1359 SessionPtr aMgr = ModelAPI_Session::get();
1360 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1363 //**************************************************************
1364 void XGUI_Workshop::displayAllResults()
1366 SessionPtr aMgr = ModelAPI_Session::get();
1367 DocumentPtr aRootDoc = aMgr->moduleDocument();
1368 displayDocumentResults(aRootDoc);
1369 for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1370 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1371 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1372 displayDocumentResults(aPart->partDoc());
1374 myDisplayer->updateViewer();
1377 //**************************************************************
1378 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1382 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1383 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1386 //**************************************************************
1387 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1389 for (int i = 0; i < theDoc->size(theGroup); i++)
1390 displayObject(theDoc->object(theGroup, i));
1393 //**************************************************************
1394 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1396 foreach(ObjectPtr aObj, theList) {
1397 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1399 if (theList.size() > 0)
1400 myDisplayer->updateViewer();
1403 //**************************************************************
1404 void XGUI_Workshop::closeDocument()
1406 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1407 while (anOperation) {
1408 anOperation->abort();
1409 anOperation = operationMgr()->currentOperation();
1411 myDisplayer->closeLocalContexts();
1412 myDisplayer->eraseAll();
1413 objectBrowser()->clearContent();
1415 SessionPtr aMgr = ModelAPI_Session::get();
1417 objectBrowser()->clearContent();
1420 //**************************************************************
1421 void XGUI_Workshop::displayObject(ObjectPtr theObj)
1423 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
1424 if (aBody.get() != NULL) {
1425 int aNb = myDisplayer->objectsCount();
1426 myDisplayer->display(theObj, false);
1430 myDisplayer->display(theObj, false);