1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 //#include "XGUI_Constants.h"
4 #include "XGUI_Workshop.h"
6 #include "XGUI_ActionsMgr.h"
7 #include "XGUI_MenuMgr.h"
8 #include "XGUI_ColorDialog.h"
9 #include "XGUI_ContextMenuMgr.h"
10 #include "XGUI_Displayer.h"
11 #include "XGUI_ErrorDialog.h"
12 #include "XGUI_ErrorMgr.h"
13 #include "XGUI_ModuleConnector.h"
14 #include "XGUI_ObjectsBrowser.h"
15 #include "XGUI_OperationMgr.h"
16 #include "XGUI_PropertyPanel.h"
17 #include "XGUI_SalomeConnector.h"
18 #include "XGUI_Selection.h"
19 #include "XGUI_SelectionMgr.h"
20 #include "XGUI_Tools.h"
21 #include "XGUI_ViewerProxy.h"
22 #include "XGUI_WorkshopListener.h"
23 #include <XGUI_CustomPrs.h>
24 #include <XGUI_HistoryMenu.h>
25 #include <XGUI_QtEvents.h>
28 #include <AppElements_Button.h>
29 #include <AppElements_Command.h>
30 #include <AppElements_MainMenu.h>
31 #include <AppElements_MainWindow.h>
32 #include <AppElements_MenuGroupPanel.h>
33 #include <AppElements_Viewer.h>
34 #include <AppElements_Workbench.h>
37 #include <ModelAPI_AttributeDocRef.h>
38 #include <ModelAPI_AttributeIntArray.h>
39 #include <ModelAPI_Data.h>
40 #include <ModelAPI_Events.h>
41 #include <ModelAPI_Feature.h>
42 #include <ModelAPI_Object.h>
43 #include <ModelAPI_ResultBody.h>
44 #include <ModelAPI_ResultConstruction.h>
45 #include <ModelAPI_ResultGroup.h>
46 #include <ModelAPI_ResultParameter.h>
47 #include <ModelAPI_Session.h>
48 #include <ModelAPI_Validator.h>
49 #include <ModelAPI_ResultCompSolid.h>
50 #include <ModelAPI_Tools.h>
52 //#include <PartSetPlugin_Part.h>
54 #include <Events_Loop.h>
55 #include <Events_InfoMessage.h>
56 #include <Events_LongOp.h>
58 #include <ModuleBase_FilterFactory.h>
59 #include <ModuleBase_IModule.h>
60 #include <ModuleBase_IViewer.h>
61 #include <ModuleBase_Operation.h>
62 #include <ModuleBase_OperationDescription.h>
63 #include <ModuleBase_PageBase.h>
64 #include <ModuleBase_Preferences.h>
65 #include <ModuleBase_SelectionValidator.h>
66 #include <ModuleBase_Tools.h>
67 #include <ModuleBase_WidgetFactory.h>
68 #include <ModuleBase_OperationFeature.h>
69 #include <ModuleBase_OperationAction.h>
70 #include <ModuleBase_PagedContainer.h>
71 #include <ModuleBase_WidgetValidated.h>
72 #include <ModuleBase_ModelWidget.h>
74 #include <Config_Common.h>
75 #include <Config_FeatureMessage.h>
76 #include <Config_ModuleReader.h>
77 #include <Config_PointerMessage.h>
78 #include <Config_PropManager.h>
79 #include <Config_SelectionFilterMessage.h>
80 #include <Config_DataModelReader.h>
81 #include <Config_Translator.h>
83 #include <SUIT_ResourceMgr.h>
85 #include <QApplication>
86 #include <QFileDialog>
87 #include <QMessageBox>
88 #include <QMdiSubWindow>
89 #include <QMainWindow>
90 #include <QPushButton>
91 #include <QDockWidget>
96 #include <QToolButton>
98 #include <QDesktopWidget>
113 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
115 //#define DEBUG_DELETE
116 //#define DEBUG_FEATURE_NAME
117 //#define DEBUG_CLEAN_HISTORY
119 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
121 myCurrentDir(QString()),
123 mySalomeConnector(theConnector),
127 //myViewerSelMode(TopAbs_FACE)
129 mySelector = new XGUI_SelectionMgr(this);
130 myModuleConnector = new XGUI_ModuleConnector(this);
131 myOperationMgr = new XGUI_OperationMgr(this, 0);
132 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
133 // Has to be defined first in order to get errors and messages from other components
134 myEventsListener = new XGUI_WorkshopListener(aWorkshop);
137 myMainWindow = new AppElements_MainWindow();
139 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
140 bool aCloc = aResMgr->booleanValue("language", "locale", true);
142 QLocale::setDefault( QLocale::c() );
144 QLocale::setDefault( QLocale::system() );
146 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
150 QStringList aFilters;
151 aFilters << "*_en.ts";
152 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
153 foreach(QString aFileName, aTsFiles) {
154 Config_Translator::load(aFileName.toStdString());
157 myDataModelXMLReader = new Config_DataModelReader();
158 //myDataModelXMLReader->readAll();
160 myDisplayer = new XGUI_Displayer(this);
162 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
164 myActionsMgr = new XGUI_ActionsMgr(this);
165 myMenuMgr = new XGUI_MenuMgr(this);
166 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
167 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
168 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
169 SLOT(onContextMenuCommand(const QString&, bool)));
171 myViewerProxy = new XGUI_ViewerProxy(this);
172 //connect(myViewerProxy, SIGNAL(selectionChanged()),
173 // myActionsMgr, SLOT(updateOnViewSelection()));
175 myOperationMgr->setWorkshop(aWorkshop);
177 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
179 connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
180 SLOT(onOperationStarted(ModuleBase_Operation*)));
181 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
182 SLOT(onOperationResumed(ModuleBase_Operation*)));
183 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
184 SLOT(onOperationStopped(ModuleBase_Operation*)));
185 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
186 SLOT(onOperationCommitted(ModuleBase_Operation*)));
187 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
188 SLOT(onOperationAborted(ModuleBase_Operation*)));
191 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
192 onTrihedronVisibilityChanged(true);
195 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
196 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
198 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
199 // Config_Prop::Color, "225,225,225");
201 Config_PropManager::registerProp("Visualization", "result_body_color", "Body color",
202 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
203 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
204 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
205 Config_PropManager::registerProp("Visualization", "result_construction_color", "Construction color",
206 Config_Prop::Color, ModelAPI_ResultConstruction::DEFAULT_COLOR());
207 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
208 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
210 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
211 myViewerSelMode.append(TopAbs_FACE);
212 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
213 myViewerSelMode.append(TopAbs_EDGE);
214 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
215 myViewerSelMode.append(TopAbs_VERTEX);
218 //******************************************************
219 XGUI_Workshop::~XGUI_Workshop(void)
222 #ifdef MISSED_TRANSLATION
223 // Save Missed translations
224 Config_Translator::saveMissedTranslations();
229 delete myDataModelXMLReader;
232 //******************************************************
233 void XGUI_Workshop::startApplication()
235 //Initialize event listening
236 myEventsListener->initializeEventListening();
238 myDataModelXMLReader->readAll();
241 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
242 Config_Prop::Directory, "");
245 registerValidators();
247 // Calling of loadCustomProps before activating module is required
248 // by Config_PropManger to restore user-defined path to plugins
249 ModuleBase_Preferences::loadCustomProps();
253 myMainWindow->show();
254 updateCommandStatus();
259 myViewerProxy->connectViewProxy();
260 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
261 SLOT(onTrihedronVisibilityChanged(bool)));
263 emit applicationStarted();
266 void XGUI_Workshop::activateModule()
268 myModule->activateSelectionFilters();
270 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
271 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
272 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
273 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
275 updateCommandStatus();
277 // TODO: get default selection mode
279 // activate visualized objects in the viewer
280 activateObjectsSelection(displayer()->displayedObjects());
281 myOperationMgr->activate();
284 void XGUI_Workshop::deactivateModule()
286 myModule->deactivateSelectionFilters();
288 // remove internal displayer filter
289 displayer()->deactivateSelectionFilters();
291 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
292 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
293 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
294 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
296 XGUI_Displayer* aDisplayer = displayer();
297 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
298 aDisplayer->deactivateObjects(aDisplayed, true);
300 myOperationMgr->deactivate();
303 //******************************************************
304 void XGUI_Workshop::initMenu()
306 myContextMenuMgr->createActions();
309 // Create only Undo, Redo commands
310 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
311 tr("Undo last command"),
312 QIcon(":pictures/undo.png"),
313 QKeySequence::Undo, false, "MEN_DESK_EDIT");
314 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
315 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
317 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
318 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
320 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
321 QIcon(":pictures/redo.png"), QKeySequence::Redo,
322 false, "MEN_DESK_EDIT");
323 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
325 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
326 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
328 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
329 //aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
330 // QIcon(":pictures/rebuild.png"), QKeySequence(),
331 // false, "MEN_DESK_EDIT");
332 //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
334 //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
335 //salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
337 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."), tr("Export the current document into a native file"),
338 QIcon(), QKeySequence(),
339 false, "MEN_DESK_FILE");
340 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
342 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."), tr("Import native file"),
343 QIcon(), QKeySequence(),
344 false, "MEN_DESK_FILE");
345 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
346 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
349 // File commands group
350 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
352 AppElements_Command* aCommand;
354 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
355 QIcon(":pictures/save.png"), QKeySequence::Save);
356 aCommand->connectTo(this, SLOT(onSave()));
357 //aCommand->disable();
359 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
360 QIcon(":pictures/save.png"), QKeySequence());
361 aCommand->connectTo(this, SLOT(onSaveAs()));
363 QString aUndoId = "UNDO_CMD";
364 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
365 QIcon(":pictures/undo.png"), QKeySequence::Undo);
366 aCommand->connectTo(this, SLOT(onUndo()));
367 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
368 addHistoryMenu(aUndoButton,
369 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
372 QString aRedoId = "REDO_CMD";
373 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
374 QIcon(":pictures/redo.png"), QKeySequence::Redo);
375 aCommand->connectTo(this, SLOT(onRedo()));
376 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
377 addHistoryMenu(aRedoButton,
378 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
381 //aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
382 // QIcon(":pictures/rebuild.png"), QKeySequence());
383 //aCommand->connectTo(this, SLOT(onRebuild()));
385 //aCommand->disable();
387 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
388 QIcon(":pictures/open.png"), QKeySequence::Open);
389 aCommand->connectTo(this, SLOT(onOpen()));
391 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
392 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
393 aCommand->connectTo(this, SLOT(onPreferences()));
395 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
396 QIcon(":pictures/close.png"), QKeySequence::Close);
397 aCommand->connectTo(this, SLOT(onExit()));
402 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
404 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
405 return aMenuBar->addWorkbench(theName);
409 //******************************************************
410 QMainWindow* XGUI_Workshop::desktop() const
413 return salomeConnector()->desktop();
419 //******************************************************
420 void XGUI_Workshop::onStartWaiting()
422 if (Events_LongOp::isPerformed()) {
423 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
427 //******************************************************
428 void XGUI_Workshop::onAcceptActionClicked()
430 QAction* anAction = dynamic_cast<QAction*>(sender());
431 XGUI_OperationMgr* anOperationMgr = operationMgr();
432 if (anOperationMgr) {
433 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
434 (anOperationMgr->currentOperation());
436 //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
437 myOperationMgr->onCommitOperation();
442 //******************************************************
443 void XGUI_Workshop::onPreviewActionClicked()
445 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
447 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
448 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
449 anActiveWidget->storeValue();
452 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
453 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
454 Events_Loop::loop()->send(aMsg);
457 //******************************************************
458 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
460 if (!myModule->canActivateSelection(theObject)) {
461 if (myDisplayer->isActive(theObject)) {
462 QObjectPtrList anObjects;
463 anObjects.append(theObject);
464 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
469 //******************************************************
470 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
472 bool aHasNested = false;
473 std::string aFeatureKind = theFeature->getKind();
475 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
476 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
479 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
480 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
481 if (aCommand && aCommand->button()->additionalButtonWidget())
487 void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
489 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
494 myPropertyPanel->cleanContent();
496 QList<ModuleBase_ModelWidget*> aWidgets;
497 if (!module()->createWidgets(theOperation, aWidgets)) {
498 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
499 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
500 aFactory.createWidget(myPropertyPanel->contentWidget());
501 aWidgets = aFactory.getModelWidgets();
504 // check compatibility of feature and widgets
505 FeaturePtr aFeature = aFOperation->feature();
506 std::string aFeatureKind = aFeature->getKind();
507 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
508 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
509 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
510 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
511 .arg(aFeatureKind).arg(aWidget->attributeID()).arg(aWidget->metaObject()->className()).send();
512 myPropertyPanel->cleanContent();
516 // for performance purpose, flush should be done after all controls are filled
517 bool isUpdateFlushed = false;
518 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
519 bool isStoreValue = !aFOperation->isEditOperation() &&
520 !aWidget->getDefaultValue().empty() &&
521 !aWidget->isComputedDefault();
522 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
524 aWidget->restoreValue();
525 aWidget->enableFocusProcessing();
527 ModuleBase_Tools::flushUpdated(aFeature);
529 // update visible state of Preview button
531 bool anIsAutoPreview = mySalomeConnector->featureInfo(aFeatureKind.c_str())->isAutoPreview();
533 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
534 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
535 bool anIsAutoPreview = aCommand && aCommand->featureMessage()->isAutoPreview();
537 if (!anIsAutoPreview) {
538 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
539 // send signal about preview should not be computed automatically, click on preview
540 // button should initiate it
541 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
542 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
543 Events_Loop::loop()->send(aMsg);
545 myPropertyPanel->setModelWidgets(aWidgets);
546 aFOperation->setPropertyPanel(myPropertyPanel);
548 myModule->propertyPanelDefined(theOperation);
550 #ifndef DEBUG_FEATURE_NAME
551 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
553 std::string aFeatureName = aFeature->name();
554 myPropertyPanel->setWindowTitle(QString("%1: %2").arg(theOperation->getDescription()->description())
555 .arg(aFeatureName.c_str()));
558 myErrorMgr->setPropertyPanel(myPropertyPanel);
561 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
563 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
564 if (aPropertyPanel) {
565 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
566 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
567 myModule->connectToPropertyPanel(aWidget, isToConnect);
569 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
570 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
571 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
574 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
575 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
576 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
582 //******************************************************
583 void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
585 setGrantedFeatures(theOperation);
586 myModule->operationStarted(theOperation);
589 //******************************************************
590 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
592 setGrantedFeatures(theOperation);
594 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
595 setPropertyPanel(theOperation);
596 connectToPropertyPanel(true);
598 updateCommandStatus();
600 myModule->operationResumed(theOperation);
604 //******************************************************
605 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
607 updateCommandStatus();
609 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
614 ModuleBase_ISelection* aSel = mySelector->selection();
615 QObjectPtrList aObj = aSel->selectedPresentations();
616 //!< No need for property panel
618 myPropertyPanel->cleanContent();
620 connectToPropertyPanel(false);
621 myModule->operationStopped(aFOperation);
623 // the deactivated objects of the current operation should be activated back.
624 // They were deactivated on operation start or an object redisplay
625 QObjectPtrList anObjects;
626 FeaturePtr aFeature = aFOperation->feature();
627 if (aFeature.get()) { // feature may be not created (plugin load fail)
628 if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature))
629 anObjects.append(aFeature);
630 std::list<ResultPtr> aResults = aFeature->results();
631 std::list<ResultPtr>::const_iterator aIt;
632 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
633 ResultPtr anObject = *aIt;
634 if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) {
635 anObjects.append(anObject);
639 activateObjectsSelection(anObjects);
643 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
645 myModule->operationCommitted(theOperation);
648 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
650 myModule->operationAborted(theOperation);
653 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
655 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
659 QStringList aGrantedIds;
660 if (isSalomeMode()) {
661 const std::shared_ptr<Config_FeatureMessage>& anInfo =
662 mySalomeConnector->featureInfo(theOperation->id());
664 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
665 .split(" ", QString::SkipEmptyParts);
668 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
670 ModuleBase_IModule* aModule = module();
672 aModule->grantedOperationIds(theOperation, aGrantedIds);
674 aFOperation->setGrantedOperationIds(aGrantedIds);
679 * Saves document with given name.
681 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
683 QApplication::restoreOverrideCursor();
684 SessionPtr aMgr = ModelAPI_Session::get();
685 aMgr->save(theName.toLatin1().constData(), theFileNames);
686 QApplication::restoreOverrideCursor();
689 bool XGUI_Workshop::abortAllOperations()
691 return myOperationMgr->abortAllOperations();
694 //******************************************************
695 void XGUI_Workshop::onOpen()
697 if(!abortAllOperations())
699 //save current file before close if modified
700 SessionPtr aSession = ModelAPI_Session::get();
701 if (aSession->isModified()) {
702 //TODO(sbh): re-launch the app?
703 int anAnswer = QMessageBox::question(
704 desktop(), tr("Save current file"),
705 tr("The document is modified, save before opening another?"),
706 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
707 if (anAnswer == QMessageBox::Save) {
709 } else if (anAnswer == QMessageBox::Cancel) {
715 //show file dialog, check if readable and open
716 myCurrentDir = QFileDialog::getExistingDirectory(desktop(), tr("Select directory"));
717 if (myCurrentDir.isEmpty())
719 QFileInfo aFileInfo(myCurrentDir);
720 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
721 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
725 QApplication::setOverrideCursor(Qt::WaitCursor);
726 aSession->closeAll();
727 aSession->load(myCurrentDir.toLatin1().constData());
728 myObjectBrowser->rebuildDataTree();
729 updateCommandStatus();
730 QApplication::restoreOverrideCursor();
733 //******************************************************
734 void XGUI_Workshop::onNew()
736 QApplication::setOverrideCursor(Qt::WaitCursor);
737 if (objectBrowser() == 0) {
739 mySelector->connectViewers();
741 myViewerProxy->connectToViewer();
744 myMainWindow->showPythonConsole();
745 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
746 aWnd->showMaximized();
747 updateCommandStatus();
749 myContextMenuMgr->connectViewer();
750 QApplication::restoreOverrideCursor();
754 //******************************************************
755 void XGUI_Workshop::onExit()
757 SessionPtr aMgr = ModelAPI_Session::get();
758 if (aMgr->isModified()) {
759 int anAnswer = QMessageBox::question(
760 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
761 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
762 if (anAnswer == QMessageBox::Save) {
763 bool saved = onSave();
767 } else if (anAnswer == QMessageBox::Cancel) {
774 //******************************************************
775 void XGUI_Workshop::onPreferences()
777 ModuleBase_Prefs aModif;
778 ModuleBase_Preferences::editPreferences(aModif);
779 if (aModif.size() > 0) {
781 foreach (ModuleBase_Pref aPref, aModif)
783 aSection = aPref.first;
784 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
785 myMainWindow->viewer()->updateFromResources();
786 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
787 myMainWindow->menuObject()->updateFromResources();
790 displayer()->redisplayObjects();
795 //******************************************************
796 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
798 XGUI_Displayer* aDisplayer = displayer();
800 aDisplayer->displayTrihedron(theState);
803 //******************************************************
804 bool XGUI_Workshop::onSave()
806 if(!abortAllOperations())
808 if (myCurrentDir.isEmpty()) {
811 std::list<std::string> aFiles;
812 saveDocument(myCurrentDir, aFiles);
813 updateCommandStatus();
815 myMainWindow->setModifiedState(false);
820 //******************************************************
821 bool XGUI_Workshop::onSaveAs()
823 if(!abortAllOperations())
825 QFileDialog dialog(desktop());
826 dialog.setWindowTitle(tr("Select directory to save files..."));
827 dialog.setFileMode(QFileDialog::Directory);
828 dialog.setFilter(tr("Directories (*)"));
829 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
830 dialog.setViewMode(QFileDialog::Detail);
832 if (!dialog.exec()) {
836 QString aTempDir = dialog.selectedFiles().first();
838 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
839 int answer = QMessageBox::question(
841 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
843 tr("The directory already contains some files, save anyway?"),
844 QMessageBox::Save | QMessageBox::Cancel);
845 if (answer == QMessageBox::Cancel) {
849 myCurrentDir = aTempDir;
851 myMainWindow->setCurrentDir(myCurrentDir, false);
852 myMainWindow->setModifiedState(false);
857 //******************************************************
858 void XGUI_Workshop::onUndo(int theTimes)
860 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
861 SessionPtr aMgr = ModelAPI_Session::get();
862 std::list<std::string> aUndoList = aMgr->undoList();
863 if (aMgr->isOperation()) {
864 /// this is important for nested operations
865 /// when sketch operation is active, this condition is false and
866 /// the sketch operation is not aborted
867 operationMgr()->onAbortOperation();
869 std::list<std::string>::const_iterator aIt = aUndoList.cbegin();
870 for (int i = 0; (i < theTimes) && (aIt != aUndoList.cend()); ++i, ++aIt) {
872 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
873 myObjectBrowser->rebuildDataTree();
876 operationMgr()->updateApplyOfOperations();
877 updateCommandStatus();
880 //******************************************************
881 void XGUI_Workshop::onRedo(int theTimes)
883 // the viewer update should be blocked in order to avoid the features blinking. For the created
884 // feature a results are created, the flush of the created signal caused the viewer redisplay for
885 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked until
886 // redo of all possible objects happens
887 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
889 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
890 SessionPtr aMgr = ModelAPI_Session::get();
891 std::list<std::string> aRedoList = aMgr->redoList();
892 if (aMgr->isOperation()) {
893 /// this is important for nested operations
894 /// when sketch operation is active, this condition is false and
895 /// the sketch operation is not aborted
896 operationMgr()->onAbortOperation();
898 std::list<std::string>::const_iterator aIt = aRedoList.cbegin();
899 for (int i = 0; (i < theTimes) && (aIt != aRedoList.cend()); ++i, ++aIt) {
901 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
902 myObjectBrowser->rebuildDataTree();
904 operationMgr()->updateApplyOfOperations();
905 updateCommandStatus();
907 // unblock the viewer update functionality and make update on purpose
908 myDisplayer->enableUpdateViewer(isUpdateEnabled);
909 myDisplayer->updateViewer();
912 //******************************************************
913 //void XGUI_Workshop::onRebuild()
915 // SessionPtr aMgr = ModelAPI_Session::get();
916 // bool aWasOperation = aMgr->isOperation(); // keep this value
917 // if (!aWasOperation) {
918 // aMgr->startOperation("Rebuild");
920 // static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
921 // Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
922 // new Events_Message(aRebuildEvent, this)));
923 // if (!aWasOperation) {
924 // aMgr->finishOperation();
926 // updateCommandStatus();
929 //******************************************************
930 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
932 ModuleBase_ModelWidget* anActiveWidget = 0;
933 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
935 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
937 anActiveWidget = aPanel->activeWidget();
940 operationMgr()->onValidateOperation();
942 myModule->widgetStateChanged(thePreviousState);
945 //******************************************************
946 void XGUI_Workshop::onValuesChanged()
948 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
949 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
952 ModuleBase_ModelWidget* anActiveWidget = 0;
953 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
955 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
957 anActiveWidget = aPanel->activeWidget();
959 if (anActiveWidget) {
960 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
962 if (aWidgetValidated)
963 aWidgetValidated->clearValidatedCash();
967 void XGUI_Workshop::onWidgetObjectUpdated()
969 operationMgr()->onValidateOperation();
972 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
974 QString libName = QString::fromStdString(library(theModule.toStdString()));
975 if (libName.isEmpty()) {
976 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
981 CREATE_FUNC crtInst = 0;
984 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
988 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
989 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
990 QString aMsg((char*) &lpMsgBuf);
991 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
992 ::LocalFree(lpMsgBuf);
994 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
998 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
999 | FORMAT_MESSAGE_IGNORE_INSERTS,
1000 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1001 QString aMsg((char*) &lpMsgBuf);
1002 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1003 ::LocalFree(lpMsgBuf);
1007 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1009 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1011 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1013 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1018 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1020 if (!err.isEmpty()) {
1022 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1024 qWarning(qPrintable(err));
1030 //******************************************************
1031 bool XGUI_Workshop::createModule()
1033 Config_ModuleReader aModuleReader;
1034 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1035 myModule = loadModule(moduleName);
1039 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1040 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1041 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1042 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1044 myModule->createFeatures();
1046 salomeConnector()->createFeatureActions();
1048 //myActionsMgr->update();
1052 //******************************************************
1053 void XGUI_Workshop::updateCommandStatus()
1055 QList<QAction*> aCommands;
1057 aCommands = salomeConnector()->commandList();
1059 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1060 foreach (AppElements_Command* aCmd, aMenuBar->features())
1061 aCommands.append(aCmd);
1063 SessionPtr aMgr = ModelAPI_Session::get();
1064 if (aMgr->hasModuleDocument()) {
1065 foreach(QAction* aCmd, aCommands) {
1066 QString aId = aCmd->data().toString();
1067 if (aId == "UNDO_CMD")
1068 aCmd->setEnabled(myModule->canUndo());
1069 else if (aId == "REDO_CMD")
1070 aCmd->setEnabled(myModule->canRedo());
1072 // Enable all commands
1073 aCmd->setEnabled(true);
1077 foreach(QAction* aCmd, aCommands) {
1078 QString aId = aCmd->data().toString();
1079 if (aId == "NEW_CMD")
1080 aCmd->setEnabled(true);
1081 else if (aId == "EXIT_CMD")
1082 aCmd->setEnabled(true);
1084 aCmd->setEnabled(false);
1087 myActionsMgr->updateCommandsStatus();
1088 emit commandStatusUpdated();
1091 void XGUI_Workshop::updateHistory()
1093 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1094 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1095 emit updateUndoHistory(aUndoRes);
1097 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1098 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1099 emit updateRedoHistory(aRedoRes);
1102 //******************************************************
1103 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1105 QDockWidget* aObjDock = new QDockWidget(theParent);
1106 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1107 aObjDock->setWindowTitle(tr("Object browser"));
1108 aObjDock->setStyleSheet(
1109 "::title { position: relative; padding-left: 5px; text-align: left center }");
1110 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1111 myObjectBrowser->setXMLReader(myDataModelXMLReader);
1112 myModule->customizeObjectBrowser(myObjectBrowser);
1113 aObjDock->setWidget(myObjectBrowser);
1115 myContextMenuMgr->connectObjectBrowser();
1119 //******************************************************
1121 * Creates dock widgets, places them in corresponding area
1122 * and tabifies if necessary.
1124 void XGUI_Workshop::createDockWidgets()
1126 QMainWindow* aDesktop = desktop();
1127 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1128 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1129 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1130 myPropertyPanel->setupActions(myActionsMgr);
1131 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1132 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1133 hidePropertyPanel(); ///<! Invisible by default
1134 hideObjectBrowser();
1135 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1136 myPropertyPanel->installEventFilter(myOperationMgr);
1138 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1139 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1141 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1142 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1144 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1145 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1147 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1148 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1149 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1150 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1153 //******************************************************
1154 void XGUI_Workshop::showPropertyPanel()
1156 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1157 ///<! Restore ability to close panel from the window's menu
1158 aViewAct->setEnabled(true);
1159 myPropertyPanel->show();
1160 myPropertyPanel->raise();
1162 // The next code is necessary to made the property panel the active window
1163 // in order to operation manager could process key events of the panel.
1164 // otherwise they are ignored. It happens only if the same(activateWindow) is
1165 // not happened by property panel activation(e.g. resume operation of Sketch)
1166 ModuleBase_Tools::activateWindow(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1167 ModuleBase_Tools::setFocus(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1170 //******************************************************
1171 void XGUI_Workshop::hidePropertyPanel()
1173 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1174 ///<! Do not allow to show empty property panel
1175 aViewAct->setEnabled(false);
1176 myPropertyPanel->hide();
1178 // the property panel is active window of the desktop, when it is
1179 // hidden, it is undefined which window becomes active. By this reason
1180 // it is defined to perform the desktop as the active window.
1181 // in SALOME mode, workstack made the PyConsole the active window,
1182 // set the focus on it. As a result, shortcuts of the application, like
1183 // are processed by this console. For example Undo actions.
1184 // It is possible that this code is to be moved to SHAPER package
1185 QMainWindow* aDesktop = desktop();
1186 ModuleBase_Tools::activateWindow(aDesktop, "XGUI_Workshop::hidePropertyPanel()");
1187 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::showPropertyPanel()");
1190 //******************************************************
1191 void XGUI_Workshop::showObjectBrowser()
1193 if (!isSalomeMode())
1194 myObjectBrowser->parentWidget()->show();
1197 //******************************************************
1198 void XGUI_Workshop::hideObjectBrowser()
1200 if (!isSalomeMode())
1201 myObjectBrowser->parentWidget()->hide();
1204 //******************************************************
1205 void XGUI_Workshop::salomeViewerSelectionChanged()
1207 emit salomeViewerSelection();
1210 //**************************************************************
1211 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1213 return mySalomeConnector->viewer();
1216 //**************************************************************
1217 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1219 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1220 if (theId == "DELETE_CMD")
1222 else if (theId == "CLEAN_HISTORY_CMD")
1224 else if (theId == "MOVE_CMD")
1226 else if (theId == "COLOR_CMD")
1227 changeColor(aObjects);
1228 else if (theId == "SHOW_CMD") {
1229 showObjects(aObjects, true);
1230 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1232 else if (theId == "HIDE_CMD")
1233 showObjects(aObjects, false);
1234 else if (theId == "SHOW_ONLY_CMD") {
1235 showOnlyObjects(aObjects);
1236 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1238 else if (theId == "SHADING_CMD")
1239 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1240 else if (theId == "WIREFRAME_CMD")
1241 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1242 else if (theId == "HIDEALL_CMD") {
1243 QObjectPtrList aList = myDisplayer->displayedObjects();
1244 foreach (ObjectPtr aObj, aList) {
1245 if (module()->canEraseObject(aObj))
1246 aObj->setDisplayed(false);
1248 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1249 } else if (theId == "SELECT_VERTEX_CMD") {
1250 setViewerSelectionMode(TopAbs_VERTEX);
1251 } else if (theId == "SELECT_EDGE_CMD") {
1252 setViewerSelectionMode(TopAbs_EDGE);
1253 } else if (theId == "SELECT_FACE_CMD") {
1254 setViewerSelectionMode(TopAbs_FACE);
1255 } else if (theId == "SELECT_RESULT_CMD") {
1256 setViewerSelectionMode(-1);
1257 } else if (theId == "SHOW_RESULTS_CMD") {
1258 highlightResults(aObjects);
1259 } else if (theId == "SHOW_FEATURE_CMD") {
1260 highlightFeature(aObjects);
1264 //**************************************************************
1265 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1268 myViewerSelMode.clear();
1270 if (myViewerSelMode.contains(theMode))
1271 myViewerSelMode.removeAll(theMode);
1273 myViewerSelMode.append(theMode);
1275 activateObjectsSelection(myDisplayer->displayedObjects());
1278 //**************************************************************
1279 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1282 module()->activeSelectionModes(aModes);
1283 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1284 aModes.append(myViewerSelMode);
1285 myDisplayer->activateObjects(aModes, theList);
1288 //**************************************************************
1289 void XGUI_Workshop::deleteObjects()
1291 ModuleBase_IModule* aModule = module();
1292 // allow the module to delete objects, do nothing if it has succeed
1293 if (aModule->deleteObjects()) {
1294 updateCommandStatus();
1298 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1299 if (!abortAllOperations())
1301 // check whether the object can be deleted. There should not be parts which are not loaded
1302 if (!XGUI_Tools::canRemoveOrRename(desktop(), anObjects))
1305 bool hasResult = false;
1306 bool hasFeature = false;
1307 bool hasParameter = false;
1308 bool hasCompositeOwner = false;
1309 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner);
1310 if (!(hasFeature || hasParameter))
1314 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1315 std::set<FeaturePtr> aFeatures;
1316 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1317 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1320 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1321 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1322 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1324 operationMgr()->startOperation(anOpAction);
1326 std::set<FeaturePtr> aFeatureRefsToDelete;
1327 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1328 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1329 // It is necessary to clear selection in order to avoid selection changed event during
1330 // deletion and negative consequences connected with processing of already deleted items
1331 mySelector->clearSelection();
1333 if (!aFeatureRefsToDelete.empty())
1334 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1335 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1338 operationMgr()->commitOperation();
1340 operationMgr()->abortOperation(operationMgr()->currentOperation());
1343 //**************************************************************
1344 void addRefsToFeature(const FeaturePtr& theFeature,
1345 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1346 std::set<FeaturePtr>& theReferences)
1348 //if (theReferences.find(theFeature) != theReferences.end())
1350 if (theMainList.find(theFeature) == theMainList.end())
1351 return; // this feature is not in the selection list, so exists without references to it
1352 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1354 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1355 aLast = aMainReferences.end();
1356 for (; anIt != aLast; anIt++) {
1357 FeaturePtr aRefFeature = *anIt;
1358 if (theReferences.find(aRefFeature) == theReferences.end())
1359 theReferences.insert(aRefFeature);
1360 addRefsToFeature(aRefFeature, theMainList, theReferences);
1364 //**************************************************************
1365 void XGUI_Workshop::cleanHistory()
1367 if (!abortAllOperations())
1370 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1371 std::set<FeaturePtr> aFeatures;
1372 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1374 #ifdef DEBUG_CLEAN_HISTORY
1376 std::set<FeaturePtr>::const_iterator aFIt;
1377 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1378 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1379 anInfo.append(aFeature->name().c_str());
1381 QString anInfoStr = anInfo.join(";\t");
1382 qDebug(QString("cleanHistory for: [%1] - %2").arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1385 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1386 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1387 // find for each object whether all reference values are in the map as key, that means that there is
1388 // no other reference in the model to this object, so it might be removed by cleaning history
1389 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1
1390 // ext_1(bool_1, sk_3) - cann't be deleted, dependency to bool_1
1392 // sk_2(ext_2) + (bool_1) - cann't be deleted, dependency to bool_1
1393 // ext_2(bool_1) - cann't be deleted, dependency to bool_1
1395 // Information: bool_1 is not selected
1396 std::set<FeaturePtr> anUnusedObjects;
1397 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1398 aMainLast = aReferences.end();
1399 for (; aMainIt != aMainLast; aMainIt++) {
1400 FeaturePtr aMainListFeature = aMainIt->first;
1401 std::set<FeaturePtr> aMainRefList = aMainIt->second;
1402 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(), aRefLast = aMainRefList.end();
1403 bool aFeatureOutOfTheList = false;
1404 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1405 FeaturePtr aRefFeature = *aRefIt;
1406 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1408 if (!aFeatureOutOfTheList)
1409 anUnusedObjects.insert(aMainListFeature);
1412 #ifdef DEBUG_CLEAN_HISTORY
1414 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1415 FeaturePtr aFeature = *aFIt;
1416 anInfo.append(aFeature->name().c_str());
1418 qDebug(QString("unused objects: [%1] - %2").arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1421 // warn about the references remove, break the delete operation if the user chose it
1422 if (!anUnusedObjects.empty()) {
1424 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1425 aNames.append(aFeature->name().c_str());
1428 QString anUnusedNames = aNames.join(", ");
1430 QString anActionId = "CLEAN_HISTORY_CMD";
1431 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1433 QMessageBox aMessageBox(desktop());
1434 aMessageBox.setWindowTitle(aDescription);
1435 aMessageBox.setIcon(QMessageBox::Warning);
1436 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1437 aMessageBox.setDefaultButton(QMessageBox::No);
1439 QString aText = QString(tr("Unused features are the following: %1.\nThese features will be deleted.\nWould you like to continue?")
1440 .arg(anUnusedNames));
1441 aMessageBox.setText(aText);
1442 if (aMessageBox.exec() == QMessageBox::No)
1445 // 1. start operation
1446 aDescription += "by deleting of " + aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1447 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1448 operationMgr()->startOperation(anOpAction);
1450 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1451 // It is necessary to clear selection in order to avoid selection changed event during
1452 // deletion and negative consequences connected with processing of already deleted items
1453 mySelector->clearSelection();
1455 std::set<FeaturePtr> anIgnoredFeatures;
1456 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
1457 operationMgr()->commitOperation();
1460 operationMgr()->abortOperation(operationMgr()->currentOperation());
1464 QString anActionId = "CLEAN_HISTORY_CMD";
1465 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1467 QMessageBox aMessageBox(desktop());
1468 aMessageBox.setWindowTitle(aDescription);
1469 aMessageBox.setIcon(QMessageBox::Warning);
1470 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1471 aMessageBox.setDefaultButton(QMessageBox::No);
1474 aMessageBox.setStandardButtons(QMessageBox::Ok);
1475 aMessageBox.setDefaultButton(QMessageBox::Ok);
1477 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1478 aMessageBox.setText(aText);
1480 if (aMessageBox.exec() == QMessageBox::No)
1485 //**************************************************************
1486 void XGUI_Workshop::moveObjects()
1488 if (!abortAllOperations())
1491 SessionPtr aMgr = ModelAPI_Session::get();
1493 QString anActionId = "MOVE_CMD";
1494 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1495 aMgr->startOperation(aDescription.toStdString());
1497 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1498 // It is necessary to clear selection in order to avoid selection changed event during
1499 // moving and negative consequences connected with processing of already moved items
1500 mySelector->clearSelection();
1501 // check whether the object can be moved. There should not be parts which are not loaded
1502 if (!XGUI_Tools::canRemoveOrRename(desktop(), anObjects))
1505 DocumentPtr anActiveDocument = aMgr->activeDocument();
1506 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1507 foreach (ObjectPtr aObject, anObjects) {
1508 if (!myModule->canApplyAction(aObject, anActionId))
1511 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1512 if (aFeature.get()) {
1513 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1514 aCurrentFeature = anActiveDocument->currentFeature(true);
1517 aMgr->finishOperation();
1520 //**************************************************************
1521 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
1523 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1524 std::set<FeaturePtr> aFeatures;
1525 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
1527 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
1530 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1532 bool isFoundResultType = false;
1533 foreach(ObjectPtr anObj, theObjects)
1535 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1536 if (aResult.get() == NULL)
1539 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1540 if (isFoundResultType)
1543 return isFoundResultType;
1546 //**************************************************************
1547 // Returns the list of all features for theDocument and all features of
1548 // all nested parts.
1549 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
1551 std::list<FeaturePtr> aResultList;
1552 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
1553 foreach (const FeaturePtr& aFeature, anAllFeatures) {
1554 // The order of appending features of the part and the part itself is important
1556 // Append features from a part feature
1557 foreach (const ResultPtr& aResult, aFeature->results()) {
1558 ResultPartPtr aResultPart =
1559 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
1560 if (aResultPart.get() && aResultPart->partDoc().get()) {
1562 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
1563 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
1567 aResultList.push_back(aFeature);
1572 //**************************************************************
1573 // Returns the list of features placed between theObject and the current feature
1574 // in the same document. Excludes theObject, includes the current feature.
1575 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1577 std::list<FeaturePtr> aResult;
1578 DocumentPtr aDocument = theObject->document();
1579 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
1580 // find the object iterator
1581 std::list<FeaturePtr>::iterator aObjectIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1582 if (aObjectIt == anAllFeatures.end())
1584 // find the current feature iterator
1585 std::list<FeaturePtr>::iterator aCurrentIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
1586 if (aCurrentIt == anAllFeatures.end())
1588 // check the right order
1589 if (std::distance(aObjectIt, anAllFeatures.end()) <= std::distance(aCurrentIt, anAllFeatures.end()))
1591 // exclude the object
1592 std::advance(aObjectIt, 1);
1593 // include the current feature
1594 std::advance(aCurrentIt, 1);
1595 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
1598 bool XGUI_Workshop::canMoveFeature()
1600 QString anActionId = "MOVE_CMD";
1602 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1603 QObjectPtrList aValidatedObjects;
1604 foreach (ObjectPtr aObject, aObjects) {
1605 if (!myModule->canApplyAction(aObject, anActionId))
1607 // To be moved feature should be in active document
1608 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
1610 aValidatedObjects.append(aObject);
1612 if (aValidatedObjects.size() != aObjects.size())
1613 aObjects = aValidatedObjects;
1615 bool aCanMove = !aObjects.empty();
1617 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
1618 for (; anIt != aLast && aCanMove; anIt++) {
1619 ObjectPtr aObject = *anIt;
1620 // 1. Get features placed between selected and current in the document
1621 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
1622 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
1623 if (aFeaturesBetween.empty())
1626 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
1627 // 2. Get all reference features to the selected object in the document
1628 std::set<FeaturePtr> aRefFeatures;
1629 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
1631 if (aRefFeatures.empty())
1634 // 3. Find any placed features in all reference features
1635 std::set<FeaturePtr> aIntersectionFeatures;
1636 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
1637 aPlacedFeatures.begin(), aPlacedFeatures.end(),
1638 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
1639 // 4. Return false if any reference feature is placed before current feature
1640 if (!aIntersectionFeatures.empty())
1648 //**************************************************************
1649 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
1651 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
1652 if (!aCanBeShaded) {
1653 ResultCompSolidPtr aCompsolidResult =
1654 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
1655 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1656 for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
1657 aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
1660 return aCanBeShaded;
1663 //**************************************************************
1664 bool XGUI_Workshop::canChangeColor() const
1666 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1668 std::set<std::string> aTypes;
1669 aTypes.insert(ModelAPI_ResultGroup::group());
1670 aTypes.insert(ModelAPI_ResultConstruction::group());
1671 aTypes.insert(ModelAPI_ResultBody::group());
1672 aTypes.insert(ModelAPI_ResultPart::group());
1674 return hasResults(aObjects, aTypes);
1677 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
1679 if (!theResult.get())
1682 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1683 if (aColorAttr.get() != NULL) {
1684 if (!aColorAttr->size()) {
1685 aColorAttr->setSize(3);
1687 aColorAttr->setValue(0, theColor[0]);
1688 aColorAttr->setValue(1, theColor[1]);
1689 aColorAttr->setValue(2, theColor[2]);
1693 //**************************************************************
1694 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1697 AttributeIntArrayPtr aColorAttr;
1698 // 1. find the current color of the object. This is a color of AIS presentation
1699 // The objects are iterated until a first valid color is found
1700 std::vector<int> aColor;
1701 foreach(ObjectPtr anObject, theObjects) {
1702 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1703 if (aResult.get()) {
1704 XGUI_CustomPrs::getResultColor(aResult, aColor);
1707 // TODO: remove the obtaining a color from the AIS object
1708 // this does not happen never because:
1709 // 1. The color can be changed only on results
1710 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1711 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1712 if (anAISObj.get()) {
1714 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1717 if (!aColor.empty())
1720 if (aColor.size() != 3)
1723 if (!abortAllOperations())
1725 // 2. show the dialog to change the value
1726 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
1727 aDlg->setColor(aColor);
1728 aDlg->move(QCursor::pos());
1729 bool isDone = aDlg->exec() == QDialog::Accepted;
1733 bool isRandomColor = aDlg->isRandomColor();
1735 // 3. abort the previous operation and start a new one
1736 SessionPtr aMgr = ModelAPI_Session::get();
1737 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
1738 aMgr->startOperation(aDescription.toStdString());
1740 // 4. set the value to all results
1741 std::vector<int> aColorResult = aDlg->getColor();
1742 foreach(ObjectPtr anObj, theObjects) {
1743 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1744 if (aResult.get() != NULL) {
1745 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1746 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1747 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1748 setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult : aDlg->getRandomColor());
1751 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
1754 aMgr->finishOperation();
1755 updateCommandStatus();
1758 //**************************************************************
1759 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
1760 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
1761 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
1763 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1765 foreach (ObjectPtr aObj, theList) {
1767 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1769 DocumentPtr aDoc = aPartRes->partDoc();
1770 SET_DISPLAY_GROUP(ModelAPI_ResultBody::group(), isVisible)
1771 SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), isVisible)
1772 SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), isVisible)
1775 aObj->setDisplayed(isVisible);
1778 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1781 //**************************************************************
1782 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1784 // Hide all displayed objects
1785 QObjectPtrList aList = myDisplayer->displayedObjects();
1786 foreach (ObjectPtr aObj, aList) {
1787 if (module()->canEraseObject(aObj))
1788 aObj->setDisplayed(false);
1791 // Show only objects from the list
1792 foreach (ObjectPtr aObj, theList) {
1794 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1796 DocumentPtr aDoc = aPartRes->partDoc();
1797 SET_DISPLAY_GROUP(ModelAPI_ResultBody::group(), true)
1798 SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), true)
1799 SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), true)
1802 aObj->setDisplayed(true);
1805 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1810 //**************************************************************
1811 void XGUI_Workshop::registerValidators() const
1813 SessionPtr aMgr = ModelAPI_Session::get();
1814 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1817 //**************************************************************
1818 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1822 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1823 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1826 //**************************************************************
1827 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1829 for (int i = 0; i < theDoc->size(theGroup); i++)
1830 theDoc->object(theGroup, i)->setDisplayed(true);
1831 //displayObject(theDoc->object(theGroup, i));
1832 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1835 //**************************************************************
1836 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1838 foreach(ObjectPtr aObj, theList) {
1839 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1841 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
1842 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1843 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1844 myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
1845 (XGUI_Displayer::DisplayMode)theMode, false);
1849 if (theList.size() > 0)
1850 myDisplayer->updateViewer();
1853 //**************************************************************
1854 void XGUI_Workshop::closeDocument()
1856 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1857 while (anOperation) {
1858 anOperation->abort();
1859 anOperation = operationMgr()->currentOperation();
1861 myDisplayer->closeLocalContexts();
1862 myDisplayer->eraseAll();
1863 objectBrowser()->clearContent();
1865 module()->closeDocument();
1867 SessionPtr aMgr = ModelAPI_Session::get();
1871 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
1873 XGUI_HistoryMenu* aMenu = NULL;
1874 if (isSalomeMode()) {
1875 QAction* anAction = qobject_cast<QAction*>(theObject);
1878 aMenu = new XGUI_HistoryMenu(anAction);
1880 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
1881 aMenu = new XGUI_HistoryMenu(aButton);
1883 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
1884 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
1887 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
1889 QList<ActionInfo> aResult;
1890 std::list<std::string>::const_iterator it = theList.cbegin();
1891 for (; it != theList.cend(); it++) {
1892 QString anId = QString::fromStdString(*it);
1893 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
1895 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
1898 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
1899 if (aContextMenuAct) {
1900 anInfo.initFrom(aContextMenuAct);
1902 anInfo = myActionsMgr->actionInfoById(anId);
1905 anInfo.text = anInfo.text.prepend("Modify ");
1912 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
1915 salomeConnector()->putInfo(theMessage, -1);
1917 myMainWindow->putInfo(theMessage, -1);
1921 void XGUI_Workshop::synchronizeViewer()
1923 SessionPtr aMgr = ModelAPI_Session::get();
1924 DocumentPtr aDoc = aMgr->activeDocument();
1926 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
1927 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
1928 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
1929 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
1932 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
1933 const std::string& theGroup,
1934 bool theUpdateViewer)
1937 int aSize = theDoc->size(theGroup);
1938 for (int i = 0; i < aSize; i++) {
1939 aObj = theDoc->object(theGroup, i);
1940 if (aObj->isDisplayed()) {
1941 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
1942 // be changed to the object becomes visible when the shape becomes not empty
1943 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
1944 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
1946 myDisplayer->display(aObj, false);
1949 if (theUpdateViewer)
1950 myDisplayer->updateViewer();
1953 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
1955 FeaturePtr aFeature;
1956 QObjectPtrList aSelList = theObjects;
1957 std::list<ResultPtr> aResList;
1958 bool aHasHidden = false;
1959 foreach(ObjectPtr aObj, theObjects) {
1960 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1961 if (aFeature.get()) {
1962 aResList = aFeature->results();
1963 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
1964 for(aIt = aResList.cbegin(); aIt != aResList.cend(); aIt++) {
1965 aHasHidden |= (*aIt)->isConcealed();
1966 aSelList.append(*aIt);
1970 if (aSelList.count() > theObjects.count()) {
1971 // if something was found
1972 bool aBlocked = objectBrowser()->blockSignals(true);
1973 objectBrowser()->setObjectsSelected(aSelList);
1974 objectBrowser()->blockSignals(aBlocked);
1977 QMessageBox::information(desktop(), tr("Find results"),
1978 tr("Results not found"), QMessageBox::Ok);
1981 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
1984 QObjectPtrList aSelList = theObjects;
1985 FeaturePtr aFeature;
1986 foreach(ObjectPtr aObj, theObjects) {
1987 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
1988 if (aResult.get()) {
1989 aFeature = ModelAPI_Feature::feature(aResult);
1990 if (aFeature.get()) {
1991 aSelList.append(aFeature);
1995 if (aSelList.count() > theObjects.count()) {
1996 // if something was found
1997 bool aBlocked = objectBrowser()->blockSignals(true);
1998 objectBrowser()->setObjectsSelected(aSelList);
1999 objectBrowser()->blockSignals(aBlocked);