1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 //#include "XGUI_Constants.h"
4 #include "XGUI_Tools.h"
5 #include "XGUI_Workshop.h"
6 #include "XGUI_SelectionMgr.h"
7 #include "XGUI_Selection.h"
8 #include "XGUI_ObjectsBrowser.h"
9 #include "XGUI_Displayer.h"
10 #include "XGUI_OperationMgr.h"
11 #include "XGUI_SalomeConnector.h"
12 #include "XGUI_ActionsMgr.h"
13 #include "XGUI_ErrorDialog.h"
14 #include "XGUI_ViewerProxy.h"
15 #include "XGUI_PropertyPanel.h"
16 #include "XGUI_ContextMenuMgr.h"
17 #include "XGUI_ModuleConnector.h"
18 #include <XGUI_QtEvents.h>
19 #include <XGUI_HistoryMenu.h>
21 #include <AppElements_Workbench.h>
22 #include <AppElements_Viewer.h>
23 #include <AppElements_Command.h>
24 #include <AppElements_MainMenu.h>
25 #include <AppElements_MainWindow.h>
26 #include <AppElements_MenuGroupPanel.h>
27 #include <AppElements_Button.h>
29 #include <ModuleBase_IModule.h>
30 #include <ModuleBase_Preferences.h>
32 #include <ModelAPI_Events.h>
33 #include <ModelAPI_Session.h>
34 #include <ModelAPI_Feature.h>
35 #include <ModelAPI_Data.h>
36 #include <ModelAPI_AttributeDocRef.h>
37 #include <ModelAPI_Object.h>
38 #include <ModelAPI_Validator.h>
39 #include <ModelAPI_ResultGroup.h>
40 #include <ModelAPI_ResultConstruction.h>
41 #include <ModelAPI_ResultBody.h>
42 #include <ModelAPI_AttributeIntArray.h>
44 //#include <PartSetPlugin_Part.h>
46 #include <Events_Loop.h>
47 #include <Events_Error.h>
48 #include <Events_LongOp.h>
50 #include <ModuleBase_Operation.h>
51 #include <ModuleBase_Operation.h>
52 #include <ModuleBase_OperationDescription.h>
53 #include <ModuleBase_SelectionValidator.h>
54 #include <ModuleBase_WidgetFactory.h>
55 #include <ModuleBase_Tools.h>
56 #include <ModuleBase_IViewer.h>
57 #include<ModuleBase_FilterFactory.h>
58 #include <ModuleBase_PageBase.h>
60 #include <Config_Common.h>
61 #include <Config_FeatureMessage.h>
62 #include <Config_PointerMessage.h>
63 #include <Config_ModuleReader.h>
64 #include <Config_PropManager.h>
65 #include <Config_SelectionFilterMessage.h>
67 #include <QApplication>
68 #include <QFileDialog>
69 #include <QMessageBox>
70 #include <QMdiSubWindow>
71 #include <QPushButton>
72 #include <QDockWidget>
77 #include <QToolButton>
80 #include <QDialogButtonBox>
81 #include <QHBoxLayout>
82 #include <QtxColorButton.h>
95 //#define DEBUG_FEATURE_CREATED
96 //#define DEBUG_FEATURE_REDISPLAY
98 QString objectInfo(ObjectPtr theObj)
100 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
101 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
102 QString aFeatureStr = "feature";
104 aFeatureStr.append("(Result)");
105 aFeature = ModelAPI_Feature::feature(aRes);
107 if (aFeature.get()) {
108 aFeatureStr.append(QString(": %1").arg(aFeature->getKind().c_str()).toStdString().c_str());
114 QMap<QString, QString> XGUI_Workshop::myIcons;
117 QIcon XGUI_Workshop::featureIcon(const FeaturePtr& theFeature)
121 std::string aKind = theFeature->getKind();
122 QString aId(aKind.c_str());
123 if (!myIcons.contains(aId))
126 QString anIconString = myIcons[aId];
128 ModelAPI_ExecState aState = theFeature->data()->execState();
130 case ModelAPI_StateDone:
131 case ModelAPI_StateNothing: {
132 anIcon = QIcon(anIconString);
135 case ModelAPI_StateMustBeUpdated: {
136 anIcon = ModuleBase_Tools::lighter(anIconString);
139 case ModelAPI_StateExecFailed: {
140 anIcon = ModuleBase_Tools::composite(":pictures/exec_state_failed.png", anIconString);
143 case ModelAPI_StateInvalidArgument: {
144 anIcon = ModuleBase_Tools::composite(":pictures/exec_state_invalid_parameters.png",
153 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
155 myCurrentDir(QString()),
157 mySalomeConnector(theConnector),
161 myUpdatePrefs(false),
162 myPartActivating(false)
164 myMainWindow = mySalomeConnector ? 0 : new AppElements_MainWindow();
166 myDisplayer = new XGUI_Displayer(this);
168 mySelector = new XGUI_SelectionMgr(this);
169 //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
171 myOperationMgr = new XGUI_OperationMgr(this);
172 myActionsMgr = new XGUI_ActionsMgr(this);
173 myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
174 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
175 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
176 SLOT(onContextMenuCommand(const QString&, bool)));
178 myViewerProxy = new XGUI_ViewerProxy(this);
179 connect(myViewerProxy, SIGNAL(selectionChanged()),
180 myActionsMgr, SLOT(updateOnViewSelection()));
182 myModuleConnector = new XGUI_ModuleConnector(this);
184 connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
185 SLOT(onOperationStarted(ModuleBase_Operation*)));
186 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
187 SLOT(onOperationResumed(ModuleBase_Operation*)));
188 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
189 SLOT(onOperationStopped(ModuleBase_Operation*)));
190 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
191 SLOT(onOperationCommitted(ModuleBase_Operation*)));
192 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
193 SLOT(onOperationAborted(ModuleBase_Operation*)));
194 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
195 connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
198 //******************************************************
199 XGUI_Workshop::~XGUI_Workshop(void)
204 //******************************************************
205 void XGUI_Workshop::startApplication()
209 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
210 Config_Prop::Directory, "");
212 //Initialize event listening
213 Events_Loop* aLoop = Events_Loop::loop();
214 aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
215 aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
216 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
217 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
218 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
219 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
220 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
221 aLoop->registerListener(this, Events_LongOp::eventID());
222 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
223 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
224 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOSHOW));
225 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
226 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED));
228 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED));
229 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED));
231 registerValidators();
233 // Calling of loadCustomProps before activating module is required
234 // by Config_PropManger to restore user-defined path to plugins
235 ModuleBase_Preferences::loadCustomProps();
238 myMainWindow->show();
239 updateCommandStatus();
244 emit applicationStarted();
247 //******************************************************
248 void XGUI_Workshop::initMenu()
250 myContextMenuMgr->createActions();
252 if (isSalomeMode()) {
253 // Create only Undo, Redo commands
254 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
255 tr("Undo last command"),
256 QIcon(":pictures/undo.png"),
257 QKeySequence::Undo, false, "MEN_DESK_EDIT");
258 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
259 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
261 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
262 QIcon(":pictures/redo.png"), QKeySequence::Redo,
263 false, "MEN_DESK_EDIT");
264 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
265 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
267 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
268 aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
269 QIcon(":pictures/rebuild.png"), QKeySequence(),
270 false, "MEN_DESK_EDIT");
271 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
272 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
274 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export NewGeom..."), tr("Export the current document into a NewGeom file"),
275 QIcon(), QKeySequence(),
276 false, "MEN_DESK_FILE");
277 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
279 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import NewGeom..."), tr("Import a NewGeom file"),
280 QIcon(), QKeySequence(),
281 false, "MEN_DESK_FILE");
282 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
283 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
287 // File commands group
288 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
290 AppElements_Command* aCommand;
292 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
293 QIcon(":pictures/save.png"), QKeySequence::Save);
294 aCommand->connectTo(this, SLOT(onSave()));
295 //aCommand->disable();
297 QString aUndoId = "UNDO_CMD";
298 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
299 QIcon(":pictures/undo.png"), QKeySequence::Undo);
300 aCommand->connectTo(this, SLOT(onUndo()));
301 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
302 addHistoryMenu(aUndoButton,
303 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
306 QString aRedoId = "REDO_CMD";
307 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
308 QIcon(":pictures/redo.png"), QKeySequence::Redo);
309 aCommand->connectTo(this, SLOT(onRedo()));
310 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
311 addHistoryMenu(aRedoButton,
312 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
315 aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
316 QIcon(":pictures/rebuild.png"), QKeySequence());
317 aCommand->connectTo(this, SLOT(onRebuild()));
319 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
320 QIcon(":pictures/save.png"), QKeySequence());
321 aCommand->connectTo(this, SLOT(onSaveAs()));
322 //aCommand->disable();
324 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
325 QIcon(":pictures/open.png"), QKeySequence::Open);
326 aCommand->connectTo(this, SLOT(onOpen()));
328 //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
329 // QIcon(":pictures/new.png"), QKeySequence::New);
330 //aCommand->connectTo(this, SLOT(onNew()));
332 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
333 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
334 aCommand->connectTo(this, SLOT(onPreferences()));
336 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
337 QIcon(":pictures/close.png"), QKeySequence::Close);
338 aCommand->connectTo(this, SLOT(onExit()));
339 //FIXME: SBH's test action. Can be used for some GUI tests.
341 // aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
342 // QIcon(":pictures/close.png"), QKeySequence(), true);
343 // aCommand->connectTo(myMainWindow, SLOT(dockPythonConsole()));
347 //******************************************************
348 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
350 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
351 return aMenuBar->addWorkbench(theName);
354 //******************************************************
355 void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessage)
357 if (QApplication::instance()->thread() != QThread::currentThread()) {
359 std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
361 SessionPtr aMgr = ModelAPI_Session::get();
362 PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(theMessage);
363 QApplication::postEvent(this, aPostponeEvent);
367 //A message to start feature creation received.
368 if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
369 std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
370 std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
371 if (!aFeatureMsg->isInternal()) {
372 addFeature(aFeatureMsg);
375 // Process creation of Part
376 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
377 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
378 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
379 onFeatureCreatedMsg(aUpdMsg);
381 if (mySalomeConnector)
382 mySalomeConnector->createPreferences();
383 myUpdatePrefs = false;
386 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
387 myUpdatePrefs = true;
390 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
391 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
392 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
393 onFeatureRedisplayMsg(aUpdMsg);
395 //Update property panel on corresponding message. If there is no current operation (no
396 //property panel), or received message has different feature to the current - do nothing.
397 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
398 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
399 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
400 onFeatureUpdatedMsg(anUpdateMsg);
401 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
402 std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
403 std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
404 onObjectDeletedMsg(aDelMsg);
405 } else if (theMessage->eventID() == Events_LongOp::eventID()) {
406 if (Events_LongOp::isPerformed()) {
407 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
409 QApplication::restoreOverrideCursor();
411 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW)) {
412 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
413 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
414 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
415 QObjectPtrList aList;
416 std::set<ObjectPtr>::const_iterator aIt;
417 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
419 showObjects(aList, true);
420 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE)) {
421 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
422 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
423 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
424 QObjectPtrList aList;
425 std::set<ObjectPtr>::const_iterator aIt;
426 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
428 showObjects(aList, false);
430 //An operation passed by message. Start it, process and commit.
431 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
432 std::shared_ptr<Config_PointerMessage> aPartSetMsg =
433 std::dynamic_pointer_cast<Config_PointerMessage>(theMessage);
434 //myPropertyPanel->cleanContent();
435 ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
437 if (myOperationMgr->startOperation(anOperation)) {
438 myPropertyPanel->updateContentWidget(anOperation->feature());
439 if (!anOperation->getDescription()->hasXmlRepresentation()) {
440 if (anOperation->commit())
441 updateCommandStatus();
444 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
445 myActionsMgr->update();
446 // Find and Activate active part
447 if (myPartActivating)
449 SessionPtr aMgr = ModelAPI_Session::get();
450 DocumentPtr aActiveDoc = aMgr->activeDocument();
451 DocumentPtr aDoc = aMgr->moduleDocument();
452 if (aActiveDoc == aDoc) {
453 activatePart(ResultPartPtr());
456 std::string aGrpName = ModelAPI_ResultPart::group();
457 for (int i = 0; i < aDoc->size(aGrpName); i++) {
458 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
459 if (aPart->partDoc() == aActiveDoc) {
460 activatePart(aPart); // Activate a part which corresponds to active Doc
464 // If not found then activate global document
465 activatePart(ResultPartPtr());
468 else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) {
469 std::shared_ptr<Config_SelectionFilterMessage> aMsg =
470 std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
472 ModuleBase_FilterFactory* aFactory = moduleConnector()->selectionFilters();
473 if (!aMsg->attributeId().empty()) {
474 aFactory->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId(),
478 } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)) {
479 // the viewer's update context will not happens until viewer updated is emitted
480 myDisplayer->enableUpdateViewer(false);
481 } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)) {
482 // the viewer's update context is unblocked, the viewer's update works
483 myDisplayer->enableUpdateViewer(true);
485 //Show error dialog if error message received.
486 std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
488 emit errorOccurred(QString::fromLatin1(anAppError->description()));
492 if (!isSalomeMode()) {
493 SessionPtr aMgr = ModelAPI_Session::get();
494 if (aMgr->isModified() != myMainWindow->isModifiedState())
495 myMainWindow->setModifiedState(aMgr->isModified());
499 //******************************************************
500 QMainWindow* XGUI_Workshop::desktop() const
502 return isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
505 //******************************************************
506 void XGUI_Workshop::onStartWaiting()
508 if (Events_LongOp::isPerformed()) {
509 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
513 //******************************************************
514 void XGUI_Workshop::onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
516 std::set<ObjectPtr> aFeatures = theMsg->objects();
517 if (myOperationMgr->hasOperation()) {
518 FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
519 std::set<ObjectPtr>::const_iterator aIt;
520 for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
521 ObjectPtr aNewFeature = (*aIt);
522 if (aNewFeature == aCurrentFeature) {
523 myPropertyPanel->updateContentWidget(aCurrentFeature);
528 myOperationMgr->onValidateOperation();
530 myObjectBrowser->processEvent(theMsg);
533 //******************************************************
534 void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
536 std::set<ObjectPtr> aObjects = theMsg->objects();
537 std::set<ObjectPtr>::const_iterator aIt;
539 #ifdef DEBUG_FEATURE_REDISPLAY
541 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
542 anInfo.append(objectInfo((*aIt)));
544 QString anInfoStr = anInfo.join(", ");
545 qDebug(QString("onFeatureRedisplayMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
548 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
549 ObjectPtr aObj = (*aIt);
551 // Hide the object if it is invalid or concealed one
552 bool aHide = !aObj->data() || !aObj->data()->isValid();
553 if (!aHide) { // check that this is not hidden result
554 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
555 aHide = aRes && aRes->isConcealed();
558 myDisplayer->erase(aObj, false);
560 // Redisplay the visible object or the object of the current operation
561 bool isVisibleObject = myDisplayer->isVisible(aObj);
562 #ifdef DEBUG_FEATURE_REDISPLAY
563 QString anObjInfo = objectInfo((aObj));
564 qDebug(QString("visible=%1 : display= %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
567 if (isVisibleObject) { // redisplay visible object
568 displayObject(aObj); // In order to update presentation
569 if (myOperationMgr->hasOperation()) {
570 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
571 if (!aOperation->isEditOperation() &&
572 aOperation->hasObject(aObj) && myDisplayer->isActive(aObj))
573 myDisplayer->deactivate(aObj);
575 } else { // display object if the current operation has it
576 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
577 if (aOperation && aOperation->hasObject(aObj)) {
578 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
579 if (displayObject(aObj)) {
580 // Deactivate object of current operation from selection
581 if (myDisplayer->isActive(aObj))
582 myDisplayer->deactivate(aObj);
588 myDisplayer->updateViewer();
591 //******************************************************
592 void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
594 std::set<ObjectPtr> aObjects = theMsg->objects();
595 std::set<ObjectPtr>::const_iterator aIt;
596 #ifdef DEBUG_FEATURE_CREATED
598 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
599 anInfo.append(objectInfo((*aIt)));
601 QString anInfoStr = anInfo.join(", ");
602 qDebug(QString("onFeatureCreatedMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
605 //bool aHasPart = false;
606 bool isDisplayed = false;
607 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
609 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
612 // If a feature is created from the aplication's python console
613 // it doesn't stored in the operation mgr and doesn't displayed
615 isDisplayed = displayObject(*aIt);
619 myObjectBrowser->processEvent(theMsg);
621 myDisplayer->updateViewer();
622 //if (aHasPart) { // TODO: Avoid activate last part on loading of document
623 // activateLastPart();
627 //******************************************************
628 void XGUI_Workshop::onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg)
631 myObjectBrowser->processEvent(theMsg);
632 //std::set<ObjectPtr> aFeatures = theMsg->objects();
635 //******************************************************
636 void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
638 setNestedFeatures(theOperation);
640 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
641 connectWithOperation(theOperation);
642 setPropertyPanel(theOperation);
644 updateCommandStatus();
646 myModule->operationStarted(theOperation);
649 //******************************************************
650 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
652 setNestedFeatures(theOperation);
654 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
655 // connectWithOperation(theOperation); already connected
656 setPropertyPanel(theOperation);
658 updateCommandStatus();
660 myModule->operationResumed(theOperation);
664 //******************************************************
665 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
667 ModuleBase_ISelection* aSel = mySelector->selection();
668 QObjectPtrList aObj = aSel->selectedPresentations();
669 //!< No need for property panel
670 updateCommandStatus();
672 myPropertyPanel->cleanContent();
674 // Activate objects created by current operation
675 // in order to clean selection modes
677 myDisplayer->activateObjects(aModes);
678 myModule->operationStopped(theOperation);
682 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
684 myModule->operationCommitted(theOperation);
687 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
689 myModule->operationAborted(theOperation);
692 void XGUI_Workshop::setNestedFeatures(ModuleBase_Operation* theOperation)
694 if (this->isSalomeMode())
695 theOperation->setNestedFeatures(mySalomeConnector->nestedActions(theOperation->id()));
697 theOperation->setNestedFeatures(myActionsMgr->nestedCommands(theOperation->id()));
700 void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
703 QString aXmlRepr = theOperation->getDescription()->xmlRepresentation();
704 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
707 myPropertyPanel->cleanContent();
708 aFactory.createWidget(myPropertyPanel->contentWidget());
710 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
711 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
712 bool isStoreValue = !theOperation->isEditOperation() &&
713 !aWidget->getDefaultValue().empty() &&
714 !aWidget->isComputedDefault();
715 aWidget->setFeature(theOperation->feature(), isStoreValue);
716 aWidget->enableFocusProcessing();
719 myPropertyPanel->setModelWidgets(aWidgets);
720 theOperation->setPropertyPanel(myPropertyPanel);
722 myModule->propertyPanelDefined(theOperation);
724 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
727 bool XGUI_Workshop::event(QEvent * theEvent)
729 PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
731 std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
732 processEvent(aEventPtr);
741 void XGUI_Workshop::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
745 qDebug() << "XGUI_Workshop::addFeature: NULL message.";
749 ActionInfo aFeatureInfo;
750 aFeatureInfo.initFrom(theMessage);
751 // Remember features icons
752 myIcons[QString::fromStdString(theMessage->id())] = aFeatureInfo.iconFile;
754 QString aWchName = QString::fromStdString(theMessage->workbenchId());
755 QStringList aNestedFeatures =
756 QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
757 QString aDocKind = QString::fromStdString(theMessage->documentKind());
758 if (isSalomeMode()) {
759 QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureInfo);
760 salomeConnector()->setNestedActions(aFeatureInfo.id, aNestedFeatures);
761 salomeConnector()->setDocumentKind(aFeatureInfo.id, aDocKind);
763 myActionsMgr->addCommand(aAction);
764 myModule->actionCreated(aAction);
766 //Find or create Workbench
767 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
768 AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
770 aPage = addWorkbench(aWchName);
772 //Find or create Group
773 QString aGroupName = QString::fromStdString(theMessage->groupId());
774 AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
776 aGroup = aPage->addGroup(aGroupName);
778 // Check if hotkey sequence is already defined:
779 QKeySequence aHotKey = myActionsMgr->registerShortcut(aFeatureInfo.shortcut);
780 if(aHotKey != aFeatureInfo.shortcut) {
781 aFeatureInfo.shortcut = aHotKey;
784 AppElements_Command* aCommand = aGroup->addFeature(aFeatureInfo,
787 // Enrich created button with accept/abort buttons if necessary
788 AppElements_Button* aButton = aCommand->button();
789 if (aButton->isColumnButton()) {
790 QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
791 QList<QAction*> anActList;
792 if (aNestedActions.contains("accept")) {
793 QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, aButton);
794 connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(commitAllOperations()));
795 anActList << anAction;
797 if (aNestedActions.contains("abort")) {
798 QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, aButton);
799 connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(abortAllOperations()));
800 anActList << anAction;
802 aButton->setAdditionalButtons(anActList);
804 myActionsMgr->addCommand(aCommand);
805 myModule->actionCreated(aCommand);
810 * Makes a signal/slot connections between Property Panel
811 * and given operation. The given operation becomes a
812 * current operation and previous operation if exists
814 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
816 QAction* aCommand = 0;
817 if (isSalomeMode()) {
818 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
820 AppElements_MainMenu* aMenu = myMainWindow->menuObject();
821 FeaturePtr aFeature = theOperation->feature();
823 aCommand = aMenu->feature(QString::fromStdString(aFeature->getKind()));
825 //Abort operation on uncheck the command
827 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
832 * Saves document with given name.
834 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
836 QApplication::restoreOverrideCursor();
837 SessionPtr aMgr = ModelAPI_Session::get();
838 aMgr->save(theName.toLatin1().constData(), theFileNames);
839 QApplication::restoreOverrideCursor();
842 bool XGUI_Workshop::isActiveOperationAborted()
844 return myOperationMgr->abortAllOperations();
847 //******************************************************
848 void XGUI_Workshop::onExit()
850 SessionPtr aMgr = ModelAPI_Session::get();
851 if (aMgr->isModified()) {
852 int anAnswer = QMessageBox::question(
853 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
854 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
855 if (anAnswer == QMessageBox::Save) {
856 bool saved = onSave();
860 } else if (anAnswer == QMessageBox::Cancel) {
867 //******************************************************
868 void XGUI_Workshop::onNew()
870 QApplication::setOverrideCursor(Qt::WaitCursor);
871 if (objectBrowser() == 0) {
873 mySelector->connectViewers();
875 myViewerProxy->connectToViewer();
877 if (!isSalomeMode()) {
878 myMainWindow->showPythonConsole();
879 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
880 aWnd->showMaximized();
881 updateCommandStatus();
883 myContextMenuMgr->connectViewer();
884 QApplication::restoreOverrideCursor();
887 //******************************************************
888 void XGUI_Workshop::onOpen()
890 if(!isActiveOperationAborted())
892 //save current file before close if modified
893 SessionPtr aSession = ModelAPI_Session::get();
894 if (aSession->isModified()) {
895 //TODO(sbh): re-launch the app?
896 int anAnswer = QMessageBox::question(
897 myMainWindow, tr("Save current file"),
898 tr("The document is modified, save before opening another?"),
899 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
900 if (anAnswer == QMessageBox::Save) {
902 } else if (anAnswer == QMessageBox::Cancel) {
905 aSession->closeAll();
909 //show file dialog, check if readable and open
910 myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
911 if (myCurrentDir.isEmpty())
913 QFileInfo aFileInfo(myCurrentDir);
914 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
915 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
919 QApplication::setOverrideCursor(Qt::WaitCursor);
920 aSession->load(myCurrentDir.toLatin1().constData());
921 myObjectBrowser->rebuildDataTree();
923 updateCommandStatus();
924 QApplication::restoreOverrideCursor();
927 //******************************************************
928 bool XGUI_Workshop::onSave()
930 if(!isActiveOperationAborted())
932 if (myCurrentDir.isEmpty()) {
935 std::list<std::string> aFiles;
936 saveDocument(myCurrentDir, aFiles);
937 updateCommandStatus();
939 myMainWindow->setModifiedState(false);
943 //******************************************************
944 bool XGUI_Workshop::onSaveAs()
946 if(!isActiveOperationAborted())
948 QFileDialog dialog(mainWindow());
949 dialog.setWindowTitle(tr("Select directory to save files..."));
950 dialog.setFileMode(QFileDialog::Directory);
951 dialog.setFilter(tr("Folders (*)"));
952 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
953 dialog.setViewMode(QFileDialog::Detail);
955 if (!dialog.exec()) {
958 QString aTempDir = dialog.selectedFiles().first();
960 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
961 int answer = QMessageBox::question(
963 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
965 tr("The folder already contains some files, save anyway?"),
966 QMessageBox::Save | QMessageBox::Cancel);
967 if (answer == QMessageBox::Cancel) {
971 myCurrentDir = aTempDir;
972 if (!isSalomeMode()) {
973 myMainWindow->setCurrentDir(myCurrentDir, false);
974 myMainWindow->setModifiedState(false);
979 //******************************************************
980 void XGUI_Workshop::onUndo(int theTimes)
982 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
983 SessionPtr aMgr = ModelAPI_Session::get();
984 if (aMgr->isOperation())
985 operationMgr()->onAbortOperation();
986 for (int i = 0; i < theTimes; ++i) {
989 updateCommandStatus();
992 //******************************************************
993 void XGUI_Workshop::onRedo(int theTimes)
995 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
996 SessionPtr aMgr = ModelAPI_Session::get();
997 if (aMgr->isOperation())
998 operationMgr()->onAbortOperation();
999 for (int i = 0; i < theTimes; ++i) {
1002 updateCommandStatus();
1005 //******************************************************
1006 void XGUI_Workshop::onRebuild()
1008 SessionPtr aMgr = ModelAPI_Session::get();
1009 bool aWasOperation = aMgr->isOperation(); // keep this value
1010 if (!aWasOperation) {
1011 aMgr->startOperation("Rebuild");
1013 static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
1014 Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
1015 new Events_Message(aRebuildEvent, this)));
1016 if (!aWasOperation) {
1017 aMgr->finishOperation();
1021 //******************************************************
1022 void XGUI_Workshop::onPreferences()
1024 ModuleBase_Prefs aModif;
1025 ModuleBase_Preferences::editPreferences(aModif);
1026 if (aModif.size() > 0) {
1028 foreach (ModuleBase_Pref aPref, aModif)
1030 aSection = aPref.first;
1031 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
1032 if (!isSalomeMode())
1033 myMainWindow->viewer()->updateFromResources();
1034 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
1035 if (!isSalomeMode())
1036 myMainWindow->menuObject()->updateFromResources();
1042 //******************************************************
1043 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1045 QString libName = QString::fromStdString(library(theModule.toStdString()));
1046 if (libName.isEmpty()) {
1047 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1052 CREATE_FUNC crtInst = 0;
1055 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
1059 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1060 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1061 QString aMsg((char*) &lpMsgBuf);
1062 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1063 ::LocalFree(lpMsgBuf);
1065 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1069 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1070 | FORMAT_MESSAGE_IGNORE_INSERTS,
1071 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1072 QString aMsg((char*) &lpMsgBuf);
1073 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1074 ::LocalFree(lpMsgBuf);
1078 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1080 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1082 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1084 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1089 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1091 if (!err.isEmpty()) {
1093 Events_Error::send(err.toStdString());
1095 qWarning(qPrintable(err));
1101 //******************************************************
1102 bool XGUI_Workshop::activateModule()
1104 Config_ModuleReader aModuleReader;
1105 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1106 myModule = loadModule(moduleName);
1110 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1111 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1112 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1113 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1115 myModule->createFeatures();
1116 myActionsMgr->update();
1120 //******************************************************
1121 void XGUI_Workshop::updateCommandStatus()
1123 QList<QAction*> aCommands;
1124 if (isSalomeMode()) { // update commands in SALOME mode
1125 aCommands = salomeConnector()->commandList();
1127 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1128 foreach (AppElements_Command* aCmd, aMenuBar->features())
1129 aCommands.append(aCmd);
1131 SessionPtr aMgr = ModelAPI_Session::get();
1132 if (aMgr->hasModuleDocument()) {
1133 QAction *aUndoCmd, *aRedoCmd;
1134 foreach(QAction* aCmd, aCommands) {
1135 QString aId = aCmd->data().toString();
1136 if (aId == "UNDO_CMD")
1138 else if (aId == "REDO_CMD")
1141 // Enable all commands
1142 aCmd->setEnabled(true);
1145 aUndoCmd->setEnabled(myModule->canUndo());
1146 aRedoCmd->setEnabled(myModule->canRedo());
1149 foreach(QAction* aCmd, aCommands) {
1150 QString aId = aCmd->data().toString();
1151 if (aId == "NEW_CMD")
1152 aCmd->setEnabled(true);
1153 else if (aId == "EXIT_CMD")
1154 aCmd->setEnabled(true);
1156 aCmd->setEnabled(false);
1159 myActionsMgr->update();
1160 emit commandStatusUpdated();
1163 void XGUI_Workshop::updateHistory()
1165 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1166 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1167 emit updateUndoHistory(aUndoRes);
1169 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1170 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1171 emit updateRedoHistory(aRedoRes);
1174 //******************************************************
1175 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1177 QDockWidget* aObjDock = new QDockWidget(theParent);
1178 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1179 aObjDock->setWindowTitle(tr("Object browser"));
1180 aObjDock->setStyleSheet(
1181 "::title { position: relative; padding-left: 5px; text-align: left center }");
1182 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1183 connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this,
1184 SLOT(changeCurrentDocument(ObjectPtr)));
1185 aObjDock->setWidget(myObjectBrowser);
1187 myContextMenuMgr->connectObjectBrowser();
1191 //******************************************************
1193 * Creates dock widgets, places them in corresponding area
1194 * and tabifies if necessary.
1196 void XGUI_Workshop::createDockWidgets()
1198 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1199 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1200 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1201 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
1202 myPropertyPanel->setupActions(myActionsMgr);
1203 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1204 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1205 hidePropertyPanel(); ///<! Invisible by default
1206 hideObjectBrowser();
1207 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1208 myPropertyPanel->installEventFilter(myOperationMgr);
1210 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1211 connect(aOkAct, SIGNAL(triggered()), myOperationMgr, SLOT(onCommitOperation()));
1212 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1213 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1214 connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets()));
1215 connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)),
1216 myOperationMgr, SLOT(onKeyReleased(QKeyEvent*)));
1217 connect(myOperationMgr, SIGNAL(validationStateChanged(bool)),
1218 aOkAct, SLOT(setEnabled(bool)));
1219 QAction* aAcceptAllAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll);
1220 connect(myOperationMgr, SIGNAL(nestedStateChanged(bool)),
1221 aAcceptAllAct, SLOT(setEnabled(bool)));
1225 //******************************************************
1226 void XGUI_Workshop::showPropertyPanel()
1228 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1229 ///<! Restore ability to close panel from the window's menu
1230 aViewAct->setEnabled(true);
1231 myPropertyPanel->show();
1232 myPropertyPanel->raise();
1235 //******************************************************
1236 void XGUI_Workshop::hidePropertyPanel()
1238 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1239 ///<! Do not allow to show empty property panel
1240 aViewAct->setEnabled(false);
1241 myPropertyPanel->hide();
1244 //******************************************************
1245 void XGUI_Workshop::showObjectBrowser()
1247 myObjectBrowser->parentWidget()->show();
1250 //******************************************************
1251 void XGUI_Workshop::hideObjectBrowser()
1253 myObjectBrowser->parentWidget()->hide();
1256 //******************************************************
1257 void XGUI_Workshop::onFeatureTriggered()
1259 QAction* aCmd = dynamic_cast<QAction*>(sender());
1261 QString aId = salomeConnector()->commandId(aCmd);
1263 myModule->launchOperation(aId);
1267 //******************************************************
1268 void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
1270 SessionPtr aMgr = ModelAPI_Session::get();
1272 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theObj);
1274 DocumentPtr aPartDoc = aPart->partDoc();
1276 aMgr->setActiveDocument(aPartDoc);
1281 aMgr->setActiveDocument(aMgr->moduleDocument());
1284 //******************************************************
1285 void XGUI_Workshop::salomeViewerSelectionChanged()
1287 emit salomeViewerSelection();
1290 //**************************************************************
1291 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1293 return mySalomeConnector->viewer();
1296 //**************************************************************
1297 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1299 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1300 if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) {
1301 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
1302 activatePart(aPart);
1303 } else if (theId == "DEACTIVATE_PART_CMD")
1304 activatePart(ResultPartPtr());
1305 else if (theId == "DELETE_CMD")
1306 deleteObjects(aObjects);
1307 else if (theId == "COLOR_CMD")
1308 changeColor(aObjects);
1309 else if (theId == "SHOW_CMD")
1310 showObjects(aObjects, true);
1311 else if (theId == "HIDE_CMD")
1312 showObjects(aObjects, false);
1313 else if (theId == "SHOW_ONLY_CMD")
1314 showOnlyObjects(aObjects);
1315 else if (theId == "SHADING_CMD")
1316 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1317 else if (theId == "WIREFRAME_CMD")
1318 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1319 else if (theId == "HIDEALL_CMD")
1320 myDisplayer->eraseAll();
1321 else if (theId == "EDIT_CMD") {
1322 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObjects.first());
1324 myModule->editFeature(aFeature);
1328 //**************************************************************
1329 void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
1331 if (!myPartActivating) {
1332 myPartActivating = true;
1334 theFeature->activate();
1335 changeCurrentDocument(theFeature);
1336 myObjectBrowser->activatePart(theFeature);
1337 myPartActivating = false;
1339 updateCommandStatus();
1342 //**************************************************************
1343 //void XGUI_Workshop::activateLastPart()
1345 // SessionPtr aMgr = ModelAPI_Session::get();
1346 // DocumentPtr aDoc = aMgr->moduleDocument();
1347 // std::string aGrpName = ModelAPI_ResultPart::group();
1348 // ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
1349 // ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
1351 // activatePart(aPart);
1355 //**************************************************************
1356 void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList)
1358 ModuleBase_IModule* aModule = module();
1359 if (aModule->deleteObjects())
1362 if (!isActiveOperationAborted())
1365 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1366 std::set<FeaturePtr> aRefFeatures;
1367 foreach (ObjectPtr aObj, theList)
1369 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1371 // TODO: check for what there is this condition. It is placed here historicaly because
1372 // ther is this condition during remove features.
1374 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1375 if (aFeature.get() != NULL) {
1376 aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
1381 if (!aRefFeatures.empty()) {
1382 QStringList aRefNames;
1383 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1384 aLast = aRefFeatures.end();
1385 for (; anIt != aLast; anIt++) {
1386 FeaturePtr aFeature = (*anIt);
1387 std::string aFName = aFeature->data()->name().c_str();
1388 std::string aName = (*anIt)->name().c_str();
1389 aRefNames.append((*anIt)->name().c_str());
1391 QString aNames = aRefNames.join(", ");
1393 QMessageBox::StandardButton aRes = QMessageBox::warning(
1394 aDesktop, tr("Delete features"),
1395 QString(tr("Selected features are used in the following features: %1.\
1396 These features will be deleted also. Would you like to continue?")).arg(aNames),
1397 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1398 if (aRes != QMessageBox::Yes)
1402 QString aDescription = tr("Delete %1");
1403 QStringList aObjectNames;
1404 foreach (ObjectPtr aObj, theList) {
1405 if (!aObj->data().get())
1407 aObjectNames << QString::fromStdString(aObj->data()->name());
1409 aDescription = aDescription.arg(aObjectNames.join(", "));
1410 SessionPtr aMgr = ModelAPI_Session::get();
1411 aMgr->startOperation(aDescription.toStdString());
1412 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1413 aLast = aRefFeatures.end();
1414 for (; anIt != aLast; anIt++) {
1415 FeaturePtr aRefFeature = (*anIt);
1416 DocumentPtr aDoc = aRefFeature->document();
1417 aDoc->removeFeature(aRefFeature);
1421 foreach (ObjectPtr aObj, theList)
1423 DocumentPtr aDoc = aObj->document();
1424 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1426 if (aDoc == aMgr->activeDocument()) {
1430 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1432 aDoc->removeFeature(aFeature);
1437 myDisplayer->updateViewer();
1438 aMgr->finishOperation();
1439 updateCommandStatus();
1442 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1444 bool isFoundResultType = false;
1445 foreach(ObjectPtr anObj, theObjects)
1447 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1448 if (aResult.get() == NULL)
1451 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1452 if (isFoundResultType)
1455 return isFoundResultType;
1458 //**************************************************************
1459 bool XGUI_Workshop::canChangeColor() const
1461 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1463 std::set<std::string> aTypes;
1464 aTypes.insert(ModelAPI_ResultGroup::group());
1465 aTypes.insert(ModelAPI_ResultConstruction::group());
1466 aTypes.insert(ModelAPI_ResultBody::group());
1467 return hasResults(aObjects, aTypes);
1470 //**************************************************************
1471 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1473 std::vector<int> aColor;
1474 foreach(ObjectPtr anObject, theObjects) {
1476 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1478 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1479 if (!aColor.empty())
1482 if (aColor.size() != 3)
1485 // 2. show the dialog to change the value
1486 QDialog* aDlg = new QDialog();
1487 QVBoxLayout* aLay = new QVBoxLayout(aDlg);
1489 QtxColorButton* aColorBtn = new QtxColorButton(aDlg);
1490 aColorBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
1492 aLay->addWidget(aColorBtn);
1493 aColorBtn->setColor(QColor(aColor[0], aColor[1], aColor[2]));
1495 QDialogButtonBox* aButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
1496 Qt::Horizontal, aDlg);
1497 connect(aButtons, SIGNAL(accepted()), aDlg, SLOT(accept()));
1498 connect(aButtons, SIGNAL(rejected()), aDlg, SLOT(reject()));
1499 aLay->addWidget(aButtons);
1501 aDlg->move(QCursor::pos());
1502 bool isDone = aDlg->exec() == QDialog::Accepted;
1506 QColor aColorResult = aColorBtn->color();
1507 int aRedResult = aColorResult.red(),
1508 aGreenResult = aColorResult.green(),
1509 aBlueResult = aColorResult.blue();
1511 if (aRedResult == aColor[0] && aGreenResult == aColor[1] && aBlueResult == aColor[2])
1514 // 3. abort the previous operation and start a new one
1515 SessionPtr aMgr = ModelAPI_Session::get();
1516 bool aWasOperation = aMgr->isOperation(); // keep this value
1517 if (!aWasOperation) {
1518 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
1519 aMgr->startOperation(aDescription.toStdString());
1522 // 4. set the value to all results
1523 AttributeIntArrayPtr aColorAttr;
1524 foreach(ObjectPtr anObj, theObjects) {
1525 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1526 if (aResult.get() != NULL) {
1527 aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1528 if (aColorAttr.get() != NULL) {
1529 if (!aColorAttr->size()) {
1530 aColorAttr->setSize(3);
1532 aColorAttr->setValue(0, aRedResult);
1533 aColorAttr->setValue(1, aGreenResult);
1534 aColorAttr->setValue(2, aBlueResult);
1539 aMgr->finishOperation();
1540 updateCommandStatus();
1543 //**************************************************************
1544 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1546 foreach (ObjectPtr aObj, theList)
1549 displayObject(aObj);
1551 myDisplayer->erase(aObj, false);
1554 myDisplayer->updateViewer();
1557 //**************************************************************
1558 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1560 myDisplayer->showOnly(theList);
1564 //**************************************************************
1565 void XGUI_Workshop::registerValidators() const
1567 SessionPtr aMgr = ModelAPI_Session::get();
1568 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1571 //**************************************************************
1572 void XGUI_Workshop::displayAllResults()
1574 SessionPtr aMgr = ModelAPI_Session::get();
1575 DocumentPtr aRootDoc = aMgr->moduleDocument();
1576 displayDocumentResults(aRootDoc);
1577 for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1578 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1579 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1580 displayDocumentResults(aPart->partDoc());
1582 myDisplayer->updateViewer();
1585 //**************************************************************
1586 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1590 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1591 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1594 //**************************************************************
1595 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1597 for (int i = 0; i < theDoc->size(theGroup); i++)
1598 displayObject(theDoc->object(theGroup, i));
1601 //**************************************************************
1602 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1604 foreach(ObjectPtr aObj, theList) {
1605 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1607 if (theList.size() > 0)
1608 myDisplayer->updateViewer();
1611 //**************************************************************
1612 void XGUI_Workshop::closeDocument()
1614 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1615 while (anOperation) {
1616 anOperation->abort();
1617 anOperation = operationMgr()->currentOperation();
1619 myDisplayer->closeLocalContexts();
1620 myDisplayer->eraseAll();
1621 objectBrowser()->clearContent();
1623 SessionPtr aMgr = ModelAPI_Session::get();
1625 objectBrowser()->clearContent();
1628 //**************************************************************
1629 bool XGUI_Workshop::displayObject(ObjectPtr theObj)
1631 if (!myModule->canDisplayObject(theObj))
1634 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
1635 if (aBody.get() != NULL) {
1636 int aNb = myDisplayer->objectsCount();
1637 myDisplayer->display(theObj, false);
1641 myDisplayer->display(theObj, false);
1646 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
1648 XGUI_HistoryMenu* aMenu = NULL;
1649 if (isSalomeMode()) {
1650 QAction* anAction = qobject_cast<QAction*>(theObject);
1653 aMenu = new XGUI_HistoryMenu(anAction);
1655 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
1656 aMenu = new XGUI_HistoryMenu(aButton);
1658 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
1659 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
1662 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
1664 QList<ActionInfo> aResult;
1665 std::list<std::string>::const_iterator it = theList.cbegin();
1666 for (; it != theList.cend(); it++) {
1667 QString anId = QString::fromStdString(*it);
1668 bool isEditing = anId.endsWith(ModuleBase_Operation::EditSuffix());
1670 anId.chop(ModuleBase_Operation::EditSuffix().size());
1672 ActionInfo anInfo = myActionsMgr->actionInfoById(anId);
1674 anInfo.text = anInfo.text.prepend("Modify ");