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>
43 #include <ModelAPI_ResultParameter.h>
45 //#include <PartSetPlugin_Part.h>
47 #include <Events_Loop.h>
48 #include <Events_Error.h>
49 #include <Events_LongOp.h>
51 #include <ModuleBase_Operation.h>
52 #include <ModuleBase_Operation.h>
53 #include <ModuleBase_OperationDescription.h>
54 #include <ModuleBase_SelectionValidator.h>
55 #include <ModuleBase_WidgetFactory.h>
56 #include <ModuleBase_Tools.h>
57 #include <ModuleBase_IViewer.h>
58 #include <ModuleBase_FilterFactory.h>
59 #include <ModuleBase_PageBase.h>
60 #include <ModuleBase_Tools.h>
62 #include <Config_Common.h>
63 #include <Config_FeatureMessage.h>
64 #include <Config_PointerMessage.h>
65 #include <Config_ModuleReader.h>
66 #include <Config_PropManager.h>
67 #include <Config_SelectionFilterMessage.h>
69 #include <QApplication>
70 #include <QFileDialog>
71 #include <QMessageBox>
72 #include <QMdiSubWindow>
73 #include <QPushButton>
74 #include <QDockWidget>
79 #include <QToolButton>
82 #include <QDialogButtonBox>
83 #include <QHBoxLayout>
84 #include <QtxColorButton.h>
97 //#define DEBUG_FEATURE_CREATED
98 //#define DEBUG_FEATURE_REDISPLAY
100 QMap<QString, QString> XGUI_Workshop::myIcons;
103 QIcon XGUI_Workshop::featureIcon(const FeaturePtr& theFeature)
107 std::string aKind = theFeature->getKind();
108 QString aId(aKind.c_str());
109 if (!myIcons.contains(aId))
112 QString anIconString = myIcons[aId];
114 ModelAPI_ExecState aState = theFeature->data()->execState();
116 case ModelAPI_StateDone:
117 case ModelAPI_StateNothing: {
118 anIcon = QIcon(anIconString);
121 case ModelAPI_StateMustBeUpdated: {
122 anIcon = ModuleBase_Tools::lighter(anIconString);
125 case ModelAPI_StateExecFailed: {
126 anIcon = ModuleBase_Tools::composite(":pictures/exec_state_failed.png", anIconString);
129 case ModelAPI_StateInvalidArgument: {
130 anIcon = ModuleBase_Tools::composite(":pictures/exec_state_invalid_parameters.png",
139 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
141 myCurrentDir(QString()),
143 mySalomeConnector(theConnector),
147 myUpdatePrefs(false),
148 myPartActivating(false),
149 myIsLoadingData(false)
151 myMainWindow = mySalomeConnector ? 0 : new AppElements_MainWindow();
153 myDisplayer = new XGUI_Displayer(this);
155 mySelector = new XGUI_SelectionMgr(this);
156 //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
158 myOperationMgr = new XGUI_OperationMgr(this);
159 myActionsMgr = new XGUI_ActionsMgr(this);
160 myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
161 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
162 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
163 SLOT(onContextMenuCommand(const QString&, bool)));
165 myViewerProxy = new XGUI_ViewerProxy(this);
166 connect(myViewerProxy, SIGNAL(selectionChanged()),
167 myActionsMgr, SLOT(updateOnViewSelection()));
169 myModuleConnector = new XGUI_ModuleConnector(this);
171 connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
172 SLOT(onOperationStarted(ModuleBase_Operation*)));
173 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
174 SLOT(onOperationResumed(ModuleBase_Operation*)));
175 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
176 SLOT(onOperationStopped(ModuleBase_Operation*)));
177 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
178 SLOT(onOperationCommitted(ModuleBase_Operation*)));
179 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
180 SLOT(onOperationAborted(ModuleBase_Operation*)));
181 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
182 connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
185 //******************************************************
186 XGUI_Workshop::~XGUI_Workshop(void)
191 //******************************************************
192 void XGUI_Workshop::startApplication()
196 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
197 Config_Prop::Directory, "");
199 //Initialize event listening
200 Events_Loop* aLoop = Events_Loop::loop();
201 aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
202 aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
203 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
204 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
205 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
206 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
207 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
208 aLoop->registerListener(this, Events_LongOp::eventID());
209 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
210 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
211 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOSHOW));
212 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
213 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED));
215 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED));
216 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED));
218 registerValidators();
220 // Calling of loadCustomProps before activating module is required
221 // by Config_PropManger to restore user-defined path to plugins
222 ModuleBase_Preferences::loadCustomProps();
225 myMainWindow->show();
226 updateCommandStatus();
231 emit applicationStarted();
234 //******************************************************
235 void XGUI_Workshop::initMenu()
237 myContextMenuMgr->createActions();
239 if (isSalomeMode()) {
240 // Create only Undo, Redo commands
241 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
242 tr("Undo last command"),
243 QIcon(":pictures/undo.png"),
244 QKeySequence::Undo, false, "MEN_DESK_EDIT");
245 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
246 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
248 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
249 QIcon(":pictures/redo.png"), QKeySequence::Redo,
250 false, "MEN_DESK_EDIT");
251 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
252 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
254 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
255 aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
256 QIcon(":pictures/rebuild.png"), QKeySequence(),
257 false, "MEN_DESK_EDIT");
258 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
259 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
261 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export NewGeom..."), tr("Export the current document into a NewGeom file"),
262 QIcon(), QKeySequence(),
263 false, "MEN_DESK_FILE");
264 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
266 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import NewGeom..."), tr("Import a NewGeom file"),
267 QIcon(), QKeySequence(),
268 false, "MEN_DESK_FILE");
269 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
270 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
274 // File commands group
275 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
277 AppElements_Command* aCommand;
279 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
280 QIcon(":pictures/save.png"), QKeySequence::Save);
281 aCommand->connectTo(this, SLOT(onSave()));
282 //aCommand->disable();
284 QString aUndoId = "UNDO_CMD";
285 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
286 QIcon(":pictures/undo.png"), QKeySequence::Undo);
287 aCommand->connectTo(this, SLOT(onUndo()));
288 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
289 addHistoryMenu(aUndoButton,
290 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
293 QString aRedoId = "REDO_CMD";
294 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
295 QIcon(":pictures/redo.png"), QKeySequence::Redo);
296 aCommand->connectTo(this, SLOT(onRedo()));
297 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
298 addHistoryMenu(aRedoButton,
299 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
302 aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
303 QIcon(":pictures/rebuild.png"), QKeySequence());
304 aCommand->connectTo(this, SLOT(onRebuild()));
306 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
307 QIcon(":pictures/save.png"), QKeySequence());
308 aCommand->connectTo(this, SLOT(onSaveAs()));
309 //aCommand->disable();
311 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
312 QIcon(":pictures/open.png"), QKeySequence::Open);
313 aCommand->connectTo(this, SLOT(onOpen()));
315 //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
316 // QIcon(":pictures/new.png"), QKeySequence::New);
317 //aCommand->connectTo(this, SLOT(onNew()));
319 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
320 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
321 aCommand->connectTo(this, SLOT(onPreferences()));
323 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
324 QIcon(":pictures/close.png"), QKeySequence::Close);
325 aCommand->connectTo(this, SLOT(onExit()));
326 //FIXME: SBH's test action. Can be used for some GUI tests.
328 // aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
329 // QIcon(":pictures/close.png"), QKeySequence(), true);
330 // aCommand->connectTo(myMainWindow, SLOT(dockPythonConsole()));
334 //******************************************************
335 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
337 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
338 return aMenuBar->addWorkbench(theName);
341 //******************************************************
342 void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessage)
344 if (QApplication::instance()->thread() != QThread::currentThread()) {
346 std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
348 SessionPtr aMgr = ModelAPI_Session::get();
349 PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(theMessage);
350 QApplication::postEvent(this, aPostponeEvent);
354 //A message to start feature creation received.
355 if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
356 std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
357 std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
358 if (!aFeatureMsg->isInternal()) {
359 addFeature(aFeatureMsg);
362 // Process creation of Part
363 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
364 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
365 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
366 onFeatureCreatedMsg(aUpdMsg);
368 if (mySalomeConnector)
369 mySalomeConnector->createPreferences();
370 myUpdatePrefs = false;
373 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
374 myUpdatePrefs = true;
377 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
378 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
379 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
380 onFeatureRedisplayMsg(aUpdMsg);
382 //Update property panel on corresponding message. If there is no current operation (no
383 //property panel), or received message has different feature to the current - do nothing.
384 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
385 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
386 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
387 onFeatureUpdatedMsg(anUpdateMsg);
388 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
389 std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
390 std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
391 onObjectDeletedMsg(aDelMsg);
392 } else if (theMessage->eventID() == Events_LongOp::eventID()) {
393 if (Events_LongOp::isPerformed()) {
394 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
396 QApplication::restoreOverrideCursor();
398 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW)) {
399 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
400 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
401 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
402 QObjectPtrList aList;
403 std::set<ObjectPtr>::const_iterator aIt;
404 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
406 showObjects(aList, true);
407 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE)) {
408 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
409 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
410 const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
411 QObjectPtrList aList;
412 std::set<ObjectPtr>::const_iterator aIt;
413 for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
415 showObjects(aList, false);
417 //An operation passed by message. Start it, process and commit.
418 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
419 std::shared_ptr<Config_PointerMessage> aPartSetMsg =
420 std::dynamic_pointer_cast<Config_PointerMessage>(theMessage);
421 //myPropertyPanel->cleanContent();
422 ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
424 if (myOperationMgr->startOperation(anOperation)) {
425 myPropertyPanel->updateContentWidget(anOperation->feature());
426 if (!anOperation->getDescription()->hasXmlRepresentation()) {
427 if (anOperation->commit())
428 updateCommandStatus();
431 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
432 myActionsMgr->update();
433 // Find and Activate active part
434 if (myPartActivating)
436 SessionPtr aMgr = ModelAPI_Session::get();
437 DocumentPtr aActiveDoc = aMgr->activeDocument();
438 DocumentPtr aDoc = aMgr->moduleDocument();
439 if (aActiveDoc == aDoc) {
440 activatePart(ResultPartPtr());
443 std::string aGrpName = ModelAPI_ResultPart::group();
444 for (int i = 0; i < aDoc->size(aGrpName); i++) {
445 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
446 if (aPart->partDoc() == aActiveDoc) {
447 activatePart(aPart); // Activate a part which corresponds to active Doc
451 // If not found then activate global document
452 activatePart(ResultPartPtr());
455 else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) {
456 std::shared_ptr<Config_SelectionFilterMessage> aMsg =
457 std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
459 ModuleBase_FilterFactory* aFactory = moduleConnector()->selectionFilters();
460 if (!aMsg->attributeId().empty()) {
461 aFactory->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId(),
465 } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)) {
466 // the viewer's update context will not happens until viewer updated is emitted
467 myDisplayer->enableUpdateViewer(false);
468 } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)) {
469 // the viewer's update context is unblocked, the viewer's update works
470 myDisplayer->enableUpdateViewer(true);
472 //Show error dialog if error message received.
473 std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
475 emit errorOccurred(QString::fromLatin1(anAppError->description()));
479 if (!isSalomeMode()) {
480 SessionPtr aMgr = ModelAPI_Session::get();
481 if (aMgr->isModified() != myMainWindow->isModifiedState())
482 myMainWindow->setModifiedState(aMgr->isModified());
486 //******************************************************
487 QMainWindow* XGUI_Workshop::desktop() const
489 return isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
492 //******************************************************
493 void XGUI_Workshop::onStartWaiting()
495 if (Events_LongOp::isPerformed()) {
496 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
500 //******************************************************
501 void XGUI_Workshop::onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
503 std::set<ObjectPtr> aFeatures = theMsg->objects();
504 if (myOperationMgr->hasOperation()) {
505 FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
506 std::set<ObjectPtr>::const_iterator aIt;
507 for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
508 ObjectPtr aNewFeature = (*aIt);
509 if (aNewFeature == aCurrentFeature) {
510 myPropertyPanel->updateContentWidget(aCurrentFeature);
515 myOperationMgr->onValidateOperation();
517 myObjectBrowser->processEvent(theMsg);
520 //******************************************************
521 void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
523 std::set<ObjectPtr> aObjects = theMsg->objects();
524 std::set<ObjectPtr>::const_iterator aIt;
526 #ifdef DEBUG_FEATURE_REDISPLAY
528 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
529 anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
531 QString anInfoStr = anInfo.join(", ");
532 qDebug(QString("onFeatureRedisplayMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
535 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
536 ObjectPtr aObj = (*aIt);
538 // Hide the object if it is invalid or concealed one
539 bool aHide = !aObj->data() || !aObj->data()->isValid();
540 if (!aHide) { // check that this is not hidden result
541 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
542 aHide = aRes && aRes->isConcealed();
545 myDisplayer->erase(aObj, false);
547 // Redisplay the visible object or the object of the current operation
548 bool isVisibleObject = myDisplayer->isVisible(aObj);
549 #ifdef DEBUG_FEATURE_REDISPLAY
550 //QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
551 //qDebug(QString("visible=%1 : display= %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
554 if (isVisibleObject) { // redisplay visible object
555 //displayObject(aObj); // In order to update presentation
556 // in order to avoid the check whether the object can be redisplayed, the exact method
557 // of redisplay is called. This modification is made in order to have the line is updated
558 // by creation of a horizontal constraint on the line by preselection
559 myDisplayer->redisplay(aObj, false);
560 if (myOperationMgr->hasOperation()) {
561 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
562 if (!aOperation->isEditOperation() &&
563 aOperation->hasObject(aObj) && myDisplayer->isActive(aObj))
564 myDisplayer->deactivate(aObj);
566 } else { // display object if the current operation has it
567 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
568 if (aOperation && aOperation->hasObject(aObj)) {
569 ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
570 #ifdef DEBUG_FEATURE_REDISPLAY
571 QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
572 qDebug(QString(" display object = %1").arg(anObjInfo).toStdString().c_str());
574 if (displayObject(aObj)) {
575 // Deactivate object of current operation from selection
576 if (myDisplayer->isActive(aObj))
577 myDisplayer->deactivate(aObj);
583 myDisplayer->updateViewer();
586 //******************************************************
587 void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
589 std::set<ObjectPtr> aObjects = theMsg->objects();
590 std::set<ObjectPtr>::const_iterator aIt;
591 #ifdef DEBUG_FEATURE_CREATED
593 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
594 anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
596 QString anInfoStr = anInfo.join(", ");
597 qDebug(QString("onFeatureCreatedMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
600 //bool aHasPart = false;
601 bool isDisplayed = false;
602 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
603 ObjectPtr anObject = *aIt;
604 // the validity of the data should be checked here in order to avoid display of the objects,
605 // which were created, then deleted, but flush for the creation event happens after that
606 if (!anObject->data() || !anObject->data()->isValid())
608 //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
611 // If a feature is created from the aplication's python console
612 // it doesn't stored in the operation mgr and doesn't displayed
614 isDisplayed = displayObject(*aIt);
618 myObjectBrowser->processEvent(theMsg);
620 myDisplayer->updateViewer();
621 //if (aHasPart) { // TODO: Avoid activate last part on loading of document
622 // activateLastPart();
626 //******************************************************
627 void XGUI_Workshop::onObjectDeletedMsg(const std::shared_ptr<ModelAPI_ObjectDeletedMessage>& theMsg)
630 myObjectBrowser->processEvent(theMsg);
631 //std::set<ObjectPtr> aFeatures = theMsg->objects();
634 //******************************************************
635 void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
637 setNestedFeatures(theOperation);
639 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
640 connectWithOperation(theOperation);
641 setPropertyPanel(theOperation);
643 updateCommandStatus();
645 myModule->operationStarted(theOperation);
648 //******************************************************
649 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
651 setNestedFeatures(theOperation);
653 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
654 // connectWithOperation(theOperation); already connected
655 setPropertyPanel(theOperation);
657 updateCommandStatus();
659 myModule->operationResumed(theOperation);
663 //******************************************************
664 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
666 ModuleBase_ISelection* aSel = mySelector->selection();
667 QObjectPtrList aObj = aSel->selectedPresentations();
668 //!< No need for property panel
669 updateCommandStatus();
671 myPropertyPanel->cleanContent();
673 // Activate objects created by current operation
674 // in order to clean selection modes
675 // the deactivation should be pefromed in the same place, where the mode is activated,
676 // e.g. activation in the current widget activation, deactivation - in the widget's deactivation
678 //myDisplayer->activateObjects(aModes);
679 myModule->operationStopped(theOperation);
683 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
685 myModule->operationCommitted(theOperation);
688 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
690 myModule->operationAborted(theOperation);
693 void XGUI_Workshop::setNestedFeatures(ModuleBase_Operation* theOperation)
695 if (this->isSalomeMode())
696 theOperation->setNestedFeatures(mySalomeConnector->nestedActions(theOperation->id()));
698 theOperation->setNestedFeatures(myActionsMgr->nestedCommands(theOperation->id()));
701 void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
704 QString aXmlRepr = theOperation->getDescription()->xmlRepresentation();
705 ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
708 myPropertyPanel->cleanContent();
709 aFactory.createWidget(myPropertyPanel->contentWidget());
711 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
712 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
713 bool isStoreValue = !theOperation->isEditOperation() &&
714 !aWidget->getDefaultValue().empty() &&
715 !aWidget->isComputedDefault();
716 aWidget->setFeature(theOperation->feature(), isStoreValue);
717 aWidget->enableFocusProcessing();
720 myPropertyPanel->setModelWidgets(aWidgets);
721 theOperation->setPropertyPanel(myPropertyPanel);
723 myModule->propertyPanelDefined(theOperation);
725 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
728 bool XGUI_Workshop::event(QEvent * theEvent)
730 PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
732 std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
733 processEvent(aEventPtr);
742 void XGUI_Workshop::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
746 qDebug() << "XGUI_Workshop::addFeature: NULL message.";
750 ActionInfo aFeatureInfo;
751 aFeatureInfo.initFrom(theMessage);
752 // Remember features icons
753 myIcons[QString::fromStdString(theMessage->id())] = aFeatureInfo.iconFile;
755 QString aWchName = QString::fromStdString(theMessage->workbenchId());
756 QStringList aNestedFeatures =
757 QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
758 QString aDocKind = QString::fromStdString(theMessage->documentKind());
759 if (isSalomeMode()) {
760 QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureInfo);
761 salomeConnector()->setNestedActions(aFeatureInfo.id, aNestedFeatures);
762 salomeConnector()->setDocumentKind(aFeatureInfo.id, aDocKind);
764 myActionsMgr->addCommand(aAction);
765 myModule->actionCreated(aAction);
767 //Find or create Workbench
768 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
769 AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
771 aPage = addWorkbench(aWchName);
773 //Find or create Group
774 QString aGroupName = QString::fromStdString(theMessage->groupId());
775 AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
777 aGroup = aPage->addGroup(aGroupName);
779 // Check if hotkey sequence is already defined:
780 QKeySequence aHotKey = myActionsMgr->registerShortcut(aFeatureInfo.shortcut);
781 if(aHotKey != aFeatureInfo.shortcut) {
782 aFeatureInfo.shortcut = aHotKey;
785 AppElements_Command* aCommand = aGroup->addFeature(aFeatureInfo,
788 // Enrich created button with accept/abort buttons if necessary
789 AppElements_Button* aButton = aCommand->button();
790 if (aButton->isColumnButton()) {
791 QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
792 QList<QAction*> anActList;
793 if (aNestedActions.contains("accept")) {
794 QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, aButton);
795 connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(commitAllOperations()));
796 anActList << anAction;
798 if (aNestedActions.contains("abort")) {
799 QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, aButton);
800 connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(abortAllOperations()));
801 anActList << anAction;
803 aButton->setAdditionalButtons(anActList);
805 myActionsMgr->addCommand(aCommand);
806 myModule->actionCreated(aCommand);
811 * Makes a signal/slot connections between Property Panel
812 * and given operation. The given operation becomes a
813 * current operation and previous operation if exists
815 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
817 QAction* aCommand = 0;
818 if (isSalomeMode()) {
819 aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
821 AppElements_MainMenu* aMenu = myMainWindow->menuObject();
822 FeaturePtr aFeature = theOperation->feature();
824 aCommand = aMenu->feature(QString::fromStdString(aFeature->getKind()));
826 //Abort operation on uncheck the command
828 connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
833 * Saves document with given name.
835 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
837 QApplication::restoreOverrideCursor();
838 SessionPtr aMgr = ModelAPI_Session::get();
839 aMgr->save(theName.toLatin1().constData(), theFileNames);
840 QApplication::restoreOverrideCursor();
843 bool XGUI_Workshop::isActiveOperationAborted()
845 return myOperationMgr->abortAllOperations();
848 //******************************************************
849 void XGUI_Workshop::onExit()
851 SessionPtr aMgr = ModelAPI_Session::get();
852 if (aMgr->isModified()) {
853 int anAnswer = QMessageBox::question(
854 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
855 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
856 if (anAnswer == QMessageBox::Save) {
857 bool saved = onSave();
861 } else if (anAnswer == QMessageBox::Cancel) {
868 //******************************************************
869 void XGUI_Workshop::onNew()
871 QApplication::setOverrideCursor(Qt::WaitCursor);
872 if (objectBrowser() == 0) {
874 mySelector->connectViewers();
876 myViewerProxy->connectToViewer();
878 if (!isSalomeMode()) {
879 myMainWindow->showPythonConsole();
880 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
881 aWnd->showMaximized();
882 updateCommandStatus();
884 myContextMenuMgr->connectViewer();
885 QApplication::restoreOverrideCursor();
888 //******************************************************
889 void XGUI_Workshop::onOpen()
891 if(!isActiveOperationAborted())
893 //save current file before close if modified
894 SessionPtr aSession = ModelAPI_Session::get();
895 if (aSession->isModified()) {
896 //TODO(sbh): re-launch the app?
897 int anAnswer = QMessageBox::question(
898 myMainWindow, tr("Save current file"),
899 tr("The document is modified, save before opening another?"),
900 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
901 if (anAnswer == QMessageBox::Save) {
903 } else if (anAnswer == QMessageBox::Cancel) {
906 aSession->closeAll();
910 //show file dialog, check if readable and open
911 myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
912 if (myCurrentDir.isEmpty())
914 QFileInfo aFileInfo(myCurrentDir);
915 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
916 QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
920 QApplication::setOverrideCursor(Qt::WaitCursor);
921 myIsLoadingData = true;
922 aSession->load(myCurrentDir.toLatin1().constData());
923 myObjectBrowser->rebuildDataTree();
925 updateCommandStatus();
926 myIsLoadingData = false;
927 QApplication::restoreOverrideCursor();
930 //******************************************************
931 bool XGUI_Workshop::onSave()
933 if(!isActiveOperationAborted())
935 if (myCurrentDir.isEmpty()) {
938 std::list<std::string> aFiles;
939 saveDocument(myCurrentDir, aFiles);
940 updateCommandStatus();
942 myMainWindow->setModifiedState(false);
946 //******************************************************
947 bool XGUI_Workshop::onSaveAs()
949 if(!isActiveOperationAborted())
951 QFileDialog dialog(mainWindow());
952 dialog.setWindowTitle(tr("Select directory to save files..."));
953 dialog.setFileMode(QFileDialog::Directory);
954 dialog.setFilter(tr("Folders (*)"));
955 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
956 dialog.setViewMode(QFileDialog::Detail);
958 if (!dialog.exec()) {
961 QString aTempDir = dialog.selectedFiles().first();
963 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
964 int answer = QMessageBox::question(
966 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
968 tr("The folder already contains some files, save anyway?"),
969 QMessageBox::Save | QMessageBox::Cancel);
970 if (answer == QMessageBox::Cancel) {
974 myCurrentDir = aTempDir;
975 if (!isSalomeMode()) {
976 myMainWindow->setCurrentDir(myCurrentDir, false);
977 myMainWindow->setModifiedState(false);
982 //******************************************************
983 void XGUI_Workshop::onUndo(int theTimes)
985 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
986 SessionPtr aMgr = ModelAPI_Session::get();
987 if (aMgr->isOperation())
988 operationMgr()->onAbortOperation();
989 for (int i = 0; i < theTimes; ++i) {
992 updateCommandStatus();
995 //******************************************************
996 void XGUI_Workshop::onRedo(int theTimes)
998 // the viewer update should be blocked in order to avoid the features blinking. For the created
999 // feature a results are created, the flush of the created signal caused the viewer redisplay for
1000 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked until
1001 // redo of all possible objects happens
1002 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
1004 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
1005 SessionPtr aMgr = ModelAPI_Session::get();
1006 if (aMgr->isOperation())
1007 operationMgr()->onAbortOperation();
1008 for (int i = 0; i < theTimes; ++i) {
1011 updateCommandStatus();
1013 // unblock the viewer update functionality and make update on purpose
1014 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1015 myDisplayer->updateViewer();
1018 //******************************************************
1019 void XGUI_Workshop::onRebuild()
1021 SessionPtr aMgr = ModelAPI_Session::get();
1022 bool aWasOperation = aMgr->isOperation(); // keep this value
1023 if (!aWasOperation) {
1024 aMgr->startOperation("Rebuild");
1026 static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
1027 Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
1028 new Events_Message(aRebuildEvent, this)));
1029 if (!aWasOperation) {
1030 aMgr->finishOperation();
1034 //******************************************************
1035 void XGUI_Workshop::onPreferences()
1037 ModuleBase_Prefs aModif;
1038 ModuleBase_Preferences::editPreferences(aModif);
1039 if (aModif.size() > 0) {
1041 foreach (ModuleBase_Pref aPref, aModif)
1043 aSection = aPref.first;
1044 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
1045 if (!isSalomeMode())
1046 myMainWindow->viewer()->updateFromResources();
1047 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
1048 if (!isSalomeMode())
1049 myMainWindow->menuObject()->updateFromResources();
1055 //******************************************************
1056 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1058 QString libName = QString::fromStdString(library(theModule.toStdString()));
1059 if (libName.isEmpty()) {
1060 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1065 CREATE_FUNC crtInst = 0;
1068 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
1072 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1073 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1074 QString aMsg((char*) &lpMsgBuf);
1075 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1076 ::LocalFree(lpMsgBuf);
1078 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1082 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1083 | FORMAT_MESSAGE_IGNORE_INSERTS,
1084 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1085 QString aMsg((char*) &lpMsgBuf);
1086 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1087 ::LocalFree(lpMsgBuf);
1091 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1093 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1095 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1097 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1102 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1104 if (!err.isEmpty()) {
1106 Events_Error::send(err.toStdString());
1108 qWarning(qPrintable(err));
1114 //******************************************************
1115 bool XGUI_Workshop::activateModule()
1117 Config_ModuleReader aModuleReader;
1118 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1119 myModule = loadModule(moduleName);
1123 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1124 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1125 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1126 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1128 myModule->createFeatures();
1129 myActionsMgr->update();
1133 //******************************************************
1134 void XGUI_Workshop::updateCommandStatus()
1136 QList<QAction*> aCommands;
1137 if (isSalomeMode()) { // update commands in SALOME mode
1138 aCommands = salomeConnector()->commandList();
1140 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1141 foreach (AppElements_Command* aCmd, aMenuBar->features())
1142 aCommands.append(aCmd);
1144 SessionPtr aMgr = ModelAPI_Session::get();
1145 if (aMgr->hasModuleDocument()) {
1146 QAction *aUndoCmd, *aRedoCmd;
1147 foreach(QAction* aCmd, aCommands) {
1148 QString aId = aCmd->data().toString();
1149 if (aId == "UNDO_CMD")
1151 else if (aId == "REDO_CMD")
1154 // Enable all commands
1155 aCmd->setEnabled(true);
1158 aUndoCmd->setEnabled(myModule->canUndo());
1159 aRedoCmd->setEnabled(myModule->canRedo());
1162 foreach(QAction* aCmd, aCommands) {
1163 QString aId = aCmd->data().toString();
1164 if (aId == "NEW_CMD")
1165 aCmd->setEnabled(true);
1166 else if (aId == "EXIT_CMD")
1167 aCmd->setEnabled(true);
1169 aCmd->setEnabled(false);
1172 myActionsMgr->update();
1173 emit commandStatusUpdated();
1176 void XGUI_Workshop::updateHistory()
1178 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1179 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1180 emit updateUndoHistory(aUndoRes);
1182 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1183 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1184 emit updateRedoHistory(aRedoRes);
1187 //******************************************************
1188 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1190 QDockWidget* aObjDock = new QDockWidget(theParent);
1191 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1192 aObjDock->setWindowTitle(tr("Object browser"));
1193 aObjDock->setStyleSheet(
1194 "::title { position: relative; padding-left: 5px; text-align: left center }");
1195 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1196 connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this,
1197 SLOT(changeCurrentDocument(ObjectPtr)));
1198 aObjDock->setWidget(myObjectBrowser);
1200 myContextMenuMgr->connectObjectBrowser();
1204 //******************************************************
1206 * Creates dock widgets, places them in corresponding area
1207 * and tabifies if necessary.
1209 void XGUI_Workshop::createDockWidgets()
1211 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1212 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1213 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1214 myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
1215 myPropertyPanel->setupActions(myActionsMgr);
1216 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1217 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1218 hidePropertyPanel(); ///<! Invisible by default
1219 hideObjectBrowser();
1220 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1221 myPropertyPanel->installEventFilter(myOperationMgr);
1223 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1224 connect(aOkAct, SIGNAL(triggered()), myOperationMgr, SLOT(onCommitOperation()));
1225 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1226 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1227 connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets()));
1228 connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)),
1229 myOperationMgr, SLOT(onKeyReleased(QKeyEvent*)));
1230 connect(myOperationMgr, SIGNAL(validationStateChanged(bool)),
1231 aOkAct, SLOT(setEnabled(bool)));
1232 QAction* aAcceptAllAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll);
1233 connect(myOperationMgr, SIGNAL(nestedStateChanged(bool)),
1234 aAcceptAllAct, SLOT(setEnabled(bool)));
1238 //******************************************************
1239 void XGUI_Workshop::showPropertyPanel()
1241 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1242 ///<! Restore ability to close panel from the window's menu
1243 aViewAct->setEnabled(true);
1244 myPropertyPanel->show();
1245 myPropertyPanel->raise();
1248 //******************************************************
1249 void XGUI_Workshop::hidePropertyPanel()
1251 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1252 ///<! Do not allow to show empty property panel
1253 aViewAct->setEnabled(false);
1254 myPropertyPanel->hide();
1257 //******************************************************
1258 void XGUI_Workshop::showObjectBrowser()
1260 myObjectBrowser->parentWidget()->show();
1263 //******************************************************
1264 void XGUI_Workshop::hideObjectBrowser()
1266 myObjectBrowser->parentWidget()->hide();
1269 //******************************************************
1270 void XGUI_Workshop::onFeatureTriggered()
1272 QAction* aCmd = dynamic_cast<QAction*>(sender());
1274 QString aId = salomeConnector()->commandId(aCmd);
1276 myModule->launchOperation(aId);
1280 //******************************************************
1281 void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
1283 SessionPtr aMgr = ModelAPI_Session::get();
1285 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theObj);
1287 DocumentPtr aPartDoc = aPart->partDoc();
1289 aMgr->setActiveDocument(aPartDoc);
1294 aMgr->setActiveDocument(aMgr->moduleDocument());
1297 //******************************************************
1298 void XGUI_Workshop::salomeViewerSelectionChanged()
1300 emit salomeViewerSelection();
1303 //**************************************************************
1304 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1306 return mySalomeConnector->viewer();
1309 //**************************************************************
1310 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1312 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1313 if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) {
1314 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
1315 activatePart(aPart);
1316 } else if (theId == "DEACTIVATE_PART_CMD")
1317 activatePart(ResultPartPtr());
1318 else if (theId == "DELETE_CMD")
1320 else if (theId == "COLOR_CMD")
1321 changeColor(aObjects);
1322 else if (theId == "SHOW_CMD")
1323 showObjects(aObjects, true);
1324 else if (theId == "HIDE_CMD")
1325 showObjects(aObjects, false);
1326 else if (theId == "SHOW_ONLY_CMD")
1327 showOnlyObjects(aObjects);
1328 else if (theId == "SHADING_CMD")
1329 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1330 else if (theId == "WIREFRAME_CMD")
1331 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1332 else if (theId == "HIDEALL_CMD")
1333 myDisplayer->eraseAll();
1334 else if (theId == "EDIT_CMD") {
1335 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObjects.first());
1336 if (aFeature == NULL) {
1337 ResultParameterPtr aParam =
1338 std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aObjects.first());
1339 if (aParam.get() != NULL) {
1340 aFeature = ModelAPI_Feature::feature(aParam);
1343 if (aFeature.get() != NULL)
1344 myModule->editFeature(aFeature);
1348 //**************************************************************
1349 void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
1351 if (!myPartActivating) {
1352 myPartActivating = true;
1354 theFeature->activate();
1355 changeCurrentDocument(theFeature);
1356 myObjectBrowser->activatePart(theFeature);
1357 myPartActivating = false;
1359 updateCommandStatus();
1362 //**************************************************************
1363 //void XGUI_Workshop::activateLastPart()
1365 // SessionPtr aMgr = ModelAPI_Session::get();
1366 // DocumentPtr aDoc = aMgr->moduleDocument();
1367 // std::string aGrpName = ModelAPI_ResultPart::group();
1368 // ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
1369 // ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
1371 // activatePart(aPart);
1375 //**************************************************************
1376 void XGUI_Workshop::deleteObjects()
1378 ModuleBase_IModule* aModule = module();
1379 // 1. allow the module to delete objects, do nothing if it has succeed
1380 if (aModule->deleteObjects())
1383 if (!isActiveOperationAborted())
1385 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1386 // 1. start operation
1387 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
1388 aDescription += tr(" %1");
1389 QStringList aObjectNames;
1390 foreach (ObjectPtr aObj, anObjects) {
1391 if (!aObj->data().get())
1393 aObjectNames << QString::fromStdString(aObj->data()->name());
1395 aDescription = aDescription.arg(aObjectNames.join(", "));
1397 SessionPtr aMgr = ModelAPI_Session::get();
1398 aMgr->startOperation(aDescription.toStdString());
1399 // 2. close the documents of the removed parts if the result part is in a list of selected objects
1400 foreach (ObjectPtr aObj, anObjects)
1402 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1404 DocumentPtr aDoc = aObj->document();
1405 if (aDoc == aMgr->activeDocument()) {
1410 // 3. delete objects
1411 QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1412 std::set<FeaturePtr> anIgnoredFeatures;
1413 if (deleteFeatures(anObjects, anIgnoredFeatures, aDesktop, true)) {
1414 myDisplayer->updateViewer();
1415 aMgr->finishOperation();
1416 updateCommandStatus();
1419 aMgr->abortOperation();
1423 //**************************************************************
1424 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList,
1425 std::set<FeaturePtr> theIgnoredFeatures,
1427 const bool theAskAboutDeleteReferences)
1429 // 1. find all referenced features
1430 std::set<FeaturePtr> aRefFeatures;
1431 foreach (ObjectPtr aObj, theList) {
1432 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
1433 if (aFeature.get() != NULL) {
1434 aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
1437 // 2. warn about the references remove, break the delete operation if the user chose it
1438 if (theAskAboutDeleteReferences && !aRefFeatures.empty()) {
1439 QStringList aRefNames;
1440 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1441 aLast = aRefFeatures.end();
1442 for (; anIt != aLast; anIt++) {
1443 aRefNames.append((*anIt)->name().c_str());
1445 QString aNames = aRefNames.join(", ");
1447 QMessageBox::StandardButton aRes = QMessageBox::warning(
1448 theParent, tr("Delete features"),
1449 QString(tr("Selected features are used in the following features: %1.\
1450 These features will be deleted also. Would you like to continue?")).arg(aNames),
1451 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1452 if (aRes != QMessageBox::Yes)
1456 // 3. remove referenced features
1457 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1458 aLast = aRefFeatures.end();
1459 for (; anIt != aLast; anIt++) {
1460 FeaturePtr aFeature = (*anIt);
1461 DocumentPtr aDoc = aFeature->document();
1462 if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end())
1463 aDoc->removeFeature(aFeature);
1466 // 4. remove the parameter features
1467 foreach (ObjectPtr aObj, theList) {
1468 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
1470 DocumentPtr aDoc = aObj->document();
1471 if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end())
1472 aDoc->removeFeature(aFeature);
1478 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1480 bool isFoundResultType = false;
1481 foreach(ObjectPtr anObj, theObjects)
1483 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1484 if (aResult.get() == NULL)
1487 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1488 if (isFoundResultType)
1491 return isFoundResultType;
1494 //**************************************************************
1495 bool XGUI_Workshop::canChangeColor() const
1497 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1499 std::set<std::string> aTypes;
1500 aTypes.insert(ModelAPI_ResultGroup::group());
1501 aTypes.insert(ModelAPI_ResultConstruction::group());
1502 aTypes.insert(ModelAPI_ResultBody::group());
1503 return hasResults(aObjects, aTypes);
1506 //**************************************************************
1507 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1509 std::vector<int> aColor;
1510 foreach(ObjectPtr anObject, theObjects) {
1512 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1514 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1515 if (!aColor.empty())
1518 if (aColor.size() != 3)
1521 // 2. show the dialog to change the value
1522 QDialog* aDlg = new QDialog();
1523 QVBoxLayout* aLay = new QVBoxLayout(aDlg);
1525 QtxColorButton* aColorBtn = new QtxColorButton(aDlg);
1526 aColorBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
1528 aLay->addWidget(aColorBtn);
1529 aColorBtn->setColor(QColor(aColor[0], aColor[1], aColor[2]));
1531 QDialogButtonBox* aButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
1532 Qt::Horizontal, aDlg);
1533 connect(aButtons, SIGNAL(accepted()), aDlg, SLOT(accept()));
1534 connect(aButtons, SIGNAL(rejected()), aDlg, SLOT(reject()));
1535 aLay->addWidget(aButtons);
1537 aDlg->move(QCursor::pos());
1538 bool isDone = aDlg->exec() == QDialog::Accepted;
1542 QColor aColorResult = aColorBtn->color();
1543 int aRedResult = aColorResult.red(),
1544 aGreenResult = aColorResult.green(),
1545 aBlueResult = aColorResult.blue();
1547 if (aRedResult == aColor[0] && aGreenResult == aColor[1] && aBlueResult == aColor[2])
1550 // 3. abort the previous operation and start a new one
1551 SessionPtr aMgr = ModelAPI_Session::get();
1552 bool aWasOperation = aMgr->isOperation(); // keep this value
1553 if (!aWasOperation) {
1554 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
1555 aMgr->startOperation(aDescription.toStdString());
1558 // 4. set the value to all results
1559 AttributeIntArrayPtr aColorAttr;
1560 foreach(ObjectPtr anObj, theObjects) {
1561 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1562 if (aResult.get() != NULL) {
1563 aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1564 if (aColorAttr.get() != NULL) {
1565 if (!aColorAttr->size()) {
1566 aColorAttr->setSize(3);
1568 aColorAttr->setValue(0, aRedResult);
1569 aColorAttr->setValue(1, aGreenResult);
1570 aColorAttr->setValue(2, aBlueResult);
1575 aMgr->finishOperation();
1576 updateCommandStatus();
1579 //**************************************************************
1580 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1582 foreach (ObjectPtr aObj, theList)
1585 displayObject(aObj);
1587 myDisplayer->erase(aObj, false);
1590 myDisplayer->updateViewer();
1593 //**************************************************************
1594 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1596 myDisplayer->showOnly(theList);
1600 //**************************************************************
1601 void XGUI_Workshop::registerValidators() const
1603 SessionPtr aMgr = ModelAPI_Session::get();
1604 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1607 //**************************************************************
1608 void XGUI_Workshop::displayAllResults()
1610 SessionPtr aMgr = ModelAPI_Session::get();
1611 DocumentPtr aRootDoc = aMgr->moduleDocument();
1612 displayDocumentResults(aRootDoc);
1613 for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1614 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1615 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1616 displayDocumentResults(aPart->partDoc());
1618 myDisplayer->updateViewer();
1621 //**************************************************************
1622 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1626 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1627 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1630 //**************************************************************
1631 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1633 for (int i = 0; i < theDoc->size(theGroup); i++)
1634 displayObject(theDoc->object(theGroup, i));
1637 //**************************************************************
1638 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1640 foreach(ObjectPtr aObj, theList) {
1641 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1643 if (theList.size() > 0)
1644 myDisplayer->updateViewer();
1647 //**************************************************************
1648 void XGUI_Workshop::closeDocument()
1650 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1651 while (anOperation) {
1652 anOperation->abort();
1653 anOperation = operationMgr()->currentOperation();
1655 myDisplayer->closeLocalContexts();
1656 myDisplayer->eraseAll();
1657 objectBrowser()->clearContent();
1659 SessionPtr aMgr = ModelAPI_Session::get();
1661 objectBrowser()->clearContent();
1664 //**************************************************************
1665 bool XGUI_Workshop::displayObject(ObjectPtr theObj)
1667 if (!myModule->canDisplayObject(theObj))
1670 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
1671 if (aBody.get() != NULL) {
1672 int aNb = myDisplayer->objectsCount();
1673 myDisplayer->display(theObj, false);
1676 } else if (!(myIsLoadingData || myPartActivating))
1677 myDisplayer->display(theObj, false);
1682 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
1684 XGUI_HistoryMenu* aMenu = NULL;
1685 if (isSalomeMode()) {
1686 QAction* anAction = qobject_cast<QAction*>(theObject);
1689 aMenu = new XGUI_HistoryMenu(anAction);
1691 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
1692 aMenu = new XGUI_HistoryMenu(aButton);
1694 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
1695 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
1698 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
1700 QList<ActionInfo> aResult;
1701 std::list<std::string>::const_iterator it = theList.cbegin();
1702 for (; it != theList.cend(); it++) {
1703 QString anId = QString::fromStdString(*it);
1704 bool isEditing = anId.endsWith(ModuleBase_Operation::EditSuffix());
1706 anId.chop(ModuleBase_Operation::EditSuffix().size());
1708 ActionInfo anInfo = myActionsMgr->actionInfoById(anId);
1710 anInfo.text = anInfo.text.prepend("Modify ");