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_DeflectionDialog.h"
10 #include "XGUI_ContextMenuMgr.h"
11 #include "XGUI_Displayer.h"
12 #include "XGUI_ErrorDialog.h"
13 #include "XGUI_ErrorMgr.h"
14 #include "XGUI_ModuleConnector.h"
15 #include "XGUI_ObjectsBrowser.h"
16 #include "XGUI_OperationMgr.h"
17 #include "XGUI_PropertyPanel.h"
18 #include "XGUI_SalomeConnector.h"
19 #include "XGUI_Selection.h"
20 #include "XGUI_SelectionMgr.h"
21 #include "XGUI_Tools.h"
22 #include "XGUI_ViewerProxy.h"
23 #include "XGUI_WorkshopListener.h"
24 #include <XGUI_CustomPrs.h>
25 #include <XGUI_HistoryMenu.h>
26 #include <XGUI_QtEvents.h>
29 #include <AppElements_Button.h>
30 #include <AppElements_Command.h>
31 #include <AppElements_MainMenu.h>
32 #include <AppElements_MainWindow.h>
33 #include <AppElements_MenuGroupPanel.h>
34 #include <AppElements_Viewer.h>
35 #include <AppElements_Workbench.h>
38 #include <ModelAPI_AttributeDocRef.h>
39 #include <ModelAPI_AttributeIntArray.h>
40 #include <ModelAPI_AttributeDouble.h>
41 #include <ModelAPI_Data.h>
42 #include <ModelAPI_Events.h>
43 #include <ModelAPI_Feature.h>
44 #include <ModelAPI_Object.h>
45 #include <ModelAPI_ResultBody.h>
46 #include <ModelAPI_ResultConstruction.h>
47 #include <ModelAPI_ResultGroup.h>
48 #include <ModelAPI_ResultParameter.h>
49 #include <ModelAPI_Session.h>
50 #include <ModelAPI_Validator.h>
51 #include <ModelAPI_ResultCompSolid.h>
52 #include <ModelAPI_Tools.h>
54 //#include <PartSetPlugin_Part.h>
56 #include <Events_Loop.h>
57 #include <Events_InfoMessage.h>
58 #include <Events_LongOp.h>
60 #include <ModuleBase_FilterFactory.h>
61 #include <ModuleBase_IModule.h>
62 #include <ModuleBase_IViewer.h>
63 #include <ModuleBase_Operation.h>
64 #include <ModuleBase_OperationDescription.h>
65 #include <ModuleBase_PageBase.h>
66 #include <ModuleBase_Preferences.h>
67 #include <ModuleBase_SelectionValidator.h>
68 #include <ModuleBase_Tools.h>
69 #include <ModuleBase_WidgetFactory.h>
70 #include <ModuleBase_OperationFeature.h>
71 #include <ModuleBase_OperationAction.h>
72 #include <ModuleBase_PagedContainer.h>
73 #include <ModuleBase_WidgetValidated.h>
74 #include <ModuleBase_ModelWidget.h>
75 #include <ModuleBase_ResultPrs.h>
77 #include <Config_Common.h>
78 #include <Config_FeatureMessage.h>
79 #include <Config_ModuleReader.h>
80 #include <Config_PointerMessage.h>
81 #include <Config_PropManager.h>
82 #include <Config_SelectionFilterMessage.h>
83 #include <Config_DataModelReader.h>
84 #include <Config_Translator.h>
86 #include <SUIT_ResourceMgr.h>
88 #include <QApplication>
89 #include <QFileDialog>
90 #include <QMessageBox>
91 #include <QMdiSubWindow>
92 #include <QMainWindow>
93 #include <QPushButton>
94 #include <QDockWidget>
99 #include <QToolButton>
101 #include <QDesktopWidget>
116 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
118 //#define DEBUG_DELETE
119 //#define DEBUG_FEATURE_NAME
120 //#define DEBUG_CLEAN_HISTORY
122 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
124 myCurrentDir(QString()),
126 mySalomeConnector(theConnector),
130 //myViewerSelMode(TopAbs_FACE)
132 mySelector = new XGUI_SelectionMgr(this);
133 myModuleConnector = new XGUI_ModuleConnector(this);
134 myOperationMgr = new XGUI_OperationMgr(this, 0);
135 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
136 // Has to be defined first in order to get errors and messages from other components
137 myEventsListener = new XGUI_WorkshopListener(aWorkshop);
140 myMainWindow = new AppElements_MainWindow();
142 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
143 bool aCloc = aResMgr->booleanValue("language", "locale", true);
145 QLocale::setDefault( QLocale::c() );
147 QLocale::setDefault( QLocale::system() );
149 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
153 QStringList aFilters;
154 aFilters << "*_en.ts";
155 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
156 foreach(QString aFileName, aTsFiles) {
157 Config_Translator::load(aFileName.toStdString());
160 myDataModelXMLReader = new Config_DataModelReader();
161 //myDataModelXMLReader->readAll();
163 myDisplayer = new XGUI_Displayer(this);
165 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
167 myActionsMgr = new XGUI_ActionsMgr(this);
168 myMenuMgr = new XGUI_MenuMgr(this);
169 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
170 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
171 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
172 SLOT(onContextMenuCommand(const QString&, bool)));
174 myViewerProxy = new XGUI_ViewerProxy(this);
175 //connect(myViewerProxy, SIGNAL(selectionChanged()),
176 // myActionsMgr, SLOT(updateOnViewSelection()));
178 myOperationMgr->setWorkshop(aWorkshop);
180 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
182 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
183 SLOT(onOperationResumed(ModuleBase_Operation*)));
184 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
185 SLOT(onOperationStopped(ModuleBase_Operation*)));
186 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
187 SLOT(onOperationCommitted(ModuleBase_Operation*)));
188 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
189 SLOT(onOperationAborted(ModuleBase_Operation*)));
192 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
193 onTrihedronVisibilityChanged(true);
196 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
197 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
199 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
200 // Config_Prop::Color, "225,225,225");
202 Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
203 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
204 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
205 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
206 Config_PropManager::registerProp("Visualization", "result_construction_color", "Construction color",
207 Config_Prop::Color, ModelAPI_ResultConstruction::DEFAULT_COLOR());
208 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
209 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
211 Config_PropManager::registerProp("Visualization", "result_deflection", "Result deflection",
212 Config_Prop::Double, "0.001");
214 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
215 myViewerSelMode.append(TopAbs_FACE);
216 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
217 myViewerSelMode.append(TopAbs_EDGE);
218 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
219 myViewerSelMode.append(TopAbs_VERTEX);
220 //IMP: an attempt to use result selection with other selection modes
221 myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
222 myViewerSelMode.append(TopAbs_COMPSOLID);
225 //******************************************************
226 XGUI_Workshop::~XGUI_Workshop(void)
229 #ifdef MISSED_TRANSLATION
230 // Save Missed translations
231 Config_Translator::saveMissedTranslations();
236 delete myDataModelXMLReader;
239 //******************************************************
240 void XGUI_Workshop::startApplication()
242 //Initialize event listening
243 myEventsListener->initializeEventListening();
245 myDataModelXMLReader->readAll();
248 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
249 Config_Prop::Directory, "");
252 registerValidators();
254 // Calling of loadCustomProps before activating module is required
255 // by Config_PropManger to restore user-defined path to plugins
256 ModuleBase_Preferences::loadCustomProps();
260 myMainWindow->show();
261 updateCommandStatus();
266 myViewerProxy->connectViewProxy();
267 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
268 SLOT(onTrihedronVisibilityChanged(bool)));
270 emit applicationStarted();
273 void XGUI_Workshop::activateModule()
275 myModule->activateSelectionFilters();
277 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
278 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
279 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
280 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
282 updateCommandStatus();
284 // TODO: get default selection mode
286 // activate visualized objects in the viewer
287 activateObjectsSelection(displayer()->displayedObjects());
288 myOperationMgr->activate();
291 void XGUI_Workshop::deactivateModule()
293 myModule->deactivateSelectionFilters();
295 // remove internal displayer filter
296 displayer()->deactivateSelectionFilters();
298 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
299 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
300 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
301 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
303 XGUI_Displayer* aDisplayer = displayer();
304 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
305 aDisplayer->deactivateObjects(aDisplayed, true);
307 myOperationMgr->deactivate();
310 //******************************************************
311 void XGUI_Workshop::initMenu()
313 myContextMenuMgr->createActions();
316 // Create only Undo, Redo commands
317 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
318 tr("Undo last command"),
319 QIcon(":pictures/undo.png"),
320 QKeySequence::Undo, false, "MEN_DESK_EDIT");
321 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
322 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
324 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
325 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
327 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
328 QIcon(":pictures/redo.png"), QKeySequence::Redo,
329 false, "MEN_DESK_EDIT");
330 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
332 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
333 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
335 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
336 //aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
337 // QIcon(":pictures/rebuild.png"), QKeySequence(),
338 // false, "MEN_DESK_EDIT");
339 //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
341 //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
342 //salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
344 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."), tr("Export the current document into a native file"),
345 QIcon(), QKeySequence(),
346 false, "MEN_DESK_FILE");
347 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
349 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."), tr("Import native file"),
350 QIcon(), QKeySequence(),
351 false, "MEN_DESK_FILE");
352 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
353 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
356 // File commands group
357 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
359 AppElements_Command* aCommand;
361 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
362 QIcon(":pictures/save.png"), QKeySequence::Save);
363 aCommand->connectTo(this, SLOT(onSave()));
364 //aCommand->disable();
366 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
367 QIcon(":pictures/save.png"), QKeySequence());
368 aCommand->connectTo(this, SLOT(onSaveAs()));
370 QString aUndoId = "UNDO_CMD";
371 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
372 QIcon(":pictures/undo.png"), QKeySequence::Undo);
373 aCommand->connectTo(this, SLOT(onUndo()));
374 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
375 addHistoryMenu(aUndoButton,
376 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
379 QString aRedoId = "REDO_CMD";
380 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
381 QIcon(":pictures/redo.png"), QKeySequence::Redo);
382 aCommand->connectTo(this, SLOT(onRedo()));
383 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
384 addHistoryMenu(aRedoButton,
385 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
388 //aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
389 // QIcon(":pictures/rebuild.png"), QKeySequence());
390 //aCommand->connectTo(this, SLOT(onRebuild()));
392 //aCommand->disable();
394 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
395 QIcon(":pictures/open.png"), QKeySequence::Open);
396 aCommand->connectTo(this, SLOT(onOpen()));
398 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
399 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
400 aCommand->connectTo(this, SLOT(onPreferences()));
402 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
403 QIcon(":pictures/close.png"), QKeySequence::Close);
404 aCommand->connectTo(this, SLOT(onExit()));
409 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
411 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
412 return aMenuBar->addWorkbench(theName);
416 //******************************************************
417 QMainWindow* XGUI_Workshop::desktop() const
420 return salomeConnector()->desktop();
426 //******************************************************
427 void XGUI_Workshop::onStartWaiting()
429 if (Events_LongOp::isPerformed()) {
430 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
434 //******************************************************
435 void XGUI_Workshop::onAcceptActionClicked()
437 QAction* anAction = dynamic_cast<QAction*>(sender());
438 XGUI_OperationMgr* anOperationMgr = operationMgr();
439 if (anOperationMgr) {
440 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
441 (anOperationMgr->currentOperation());
443 //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
444 myOperationMgr->onCommitOperation();
449 //******************************************************
450 void XGUI_Workshop::onPreviewActionClicked()
452 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
454 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
455 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
456 anActiveWidget->storeValue();
459 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
460 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
461 Events_Loop::loop()->send(aMsg);
464 //******************************************************
465 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
467 if (!myModule->canActivateSelection(theObject)) {
468 if (myDisplayer->isActive(theObject)) {
469 QObjectPtrList anObjects;
470 anObjects.append(theObject);
471 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
476 //******************************************************
477 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
479 bool aHasNested = false;
480 std::string aFeatureKind = theFeature->getKind();
482 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
483 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
486 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
487 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
488 if (aCommand && aCommand->button()->additionalButtonWidget())
494 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
496 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
501 myPropertyPanel->cleanContent();
503 QList<ModuleBase_ModelWidget*> aWidgets;
504 if (!module()->createWidgets(theOperation, aWidgets)) {
505 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
506 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
507 aFactory.createWidget(myPropertyPanel->contentWidget());
508 aWidgets = aFactory.getModelWidgets();
511 // check compatibility of feature and widgets
512 FeaturePtr aFeature = aFOperation->feature();
513 std::string aFeatureKind = aFeature->getKind();
514 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
515 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
516 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
517 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
518 .arg(aFeatureKind).arg(aWidget->attributeID()).arg(aWidget->metaObject()->className()).send();
519 myPropertyPanel->cleanContent();
523 // for performance purpose, flush should be done after all controls are filled
524 bool isUpdateFlushed = false;
525 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
526 bool isStoreValue = !aFOperation->isEditOperation() &&
527 !aWidget->getDefaultValue().empty() &&
528 !aWidget->isComputedDefault();
529 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
531 aWidget->restoreValue();
532 aWidget->enableFocusProcessing();
534 ModuleBase_Tools::flushUpdated(aFeature);
536 // update visible state of Preview button
538 bool anIsAutoPreview = mySalomeConnector->featureInfo(aFeatureKind.c_str())->isAutoPreview();
540 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
541 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
542 bool anIsAutoPreview = aCommand && aCommand->featureMessage()->isAutoPreview();
544 if (!anIsAutoPreview) {
545 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
546 // send signal about preview should not be computed automatically, click on preview
547 // button should initiate it
548 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
549 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
550 Events_Loop::loop()->send(aMsg);
552 myPropertyPanel->setModelWidgets(aWidgets);
553 aFOperation->setPropertyPanel(myPropertyPanel);
555 myModule->propertyPanelDefined(theOperation);
557 #ifndef DEBUG_FEATURE_NAME
558 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
560 std::string aFeatureName = aFeature->name();
561 myPropertyPanel->setWindowTitle(QString("%1: %2").arg(theOperation->getDescription()->description())
562 .arg(aFeatureName.c_str()));
565 myErrorMgr->setPropertyPanel(myPropertyPanel);
568 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
570 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
571 if (aPropertyPanel) {
572 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
573 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
574 myModule->connectToPropertyPanel(aWidget, isToConnect);
576 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
577 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
578 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
581 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
582 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
583 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
589 //******************************************************
590 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
592 setGrantedFeatures(theOperation);
594 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
595 fillPropertyPanel(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;
631 ModelAPI_Tools::allResults(aFeature, aResults);
632 std::list<ResultPtr>::const_iterator aIt;
633 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
634 ResultPtr anObject = *aIt;
635 if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) {
636 anObjects.append(anObject);
640 activateObjectsSelection(anObjects);
644 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
646 myModule->operationCommitted(theOperation);
649 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
651 myModule->operationAborted(theOperation);
654 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
656 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
660 QStringList aGrantedIds;
661 if (isSalomeMode()) {
662 const std::shared_ptr<Config_FeatureMessage>& anInfo =
663 mySalomeConnector->featureInfo(theOperation->id());
665 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
666 .split(" ", QString::SkipEmptyParts);
669 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
671 ModuleBase_IModule* aModule = module();
673 aModule->grantedOperationIds(theOperation, aGrantedIds);
675 aFOperation->setGrantedOperationIds(aGrantedIds);
678 //******************************************************
679 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
681 QApplication::restoreOverrideCursor();
682 SessionPtr aMgr = ModelAPI_Session::get();
683 aMgr->save(theName.toLatin1().constData(), theFileNames);
684 QApplication::restoreOverrideCursor();
687 //******************************************************
688 bool XGUI_Workshop::abortAllOperations()
690 return myOperationMgr->abortAllOperations();
693 //******************************************************
694 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
696 setGrantedFeatures(theOperation);
697 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
698 updateCommandStatus();
701 myModule->operationStarted(theOperation);
705 //******************************************************
706 void XGUI_Workshop::onOpen()
708 if(!abortAllOperations())
710 //save current file before close if modified
711 SessionPtr aSession = ModelAPI_Session::get();
712 if (aSession->isModified()) {
713 //TODO(sbh): re-launch the app?
714 int anAnswer = QMessageBox::question(
715 desktop(), tr("Save current file"),
716 tr("The document is modified, save before opening another?"),
717 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
718 if (anAnswer == QMessageBox::Save) {
720 } else if (anAnswer == QMessageBox::Cancel) {
726 //show file dialog, check if readable and open
727 QString aDirectory = QFileDialog::getExistingDirectory(desktop(), tr("Select directory"));
728 openDirectory(aDirectory);
731 //******************************************************
732 void XGUI_Workshop::openDirectory(const QString& theDirectory)
734 myCurrentDir = theDirectory;
735 if (myCurrentDir.isEmpty())
738 QFileInfo aFileInfo(myCurrentDir);
739 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
740 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
745 QApplication::setOverrideCursor(Qt::WaitCursor);
746 SessionPtr aSession = ModelAPI_Session::get();
747 aSession->closeAll();
748 aSession->load(myCurrentDir.toLatin1().constData());
749 myObjectBrowser->rebuildDataTree();
750 updateCommandStatus();
751 QApplication::restoreOverrideCursor();
754 //******************************************************
755 void XGUI_Workshop::onNew()
757 QApplication::setOverrideCursor(Qt::WaitCursor);
758 if (objectBrowser() == 0) {
760 mySelector->connectViewers();
762 myViewerProxy->connectToViewer();
765 myMainWindow->showPythonConsole();
766 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
767 aWnd->showMaximized();
768 updateCommandStatus();
770 myContextMenuMgr->connectViewer();
771 QApplication::restoreOverrideCursor();
775 //******************************************************
776 void XGUI_Workshop::onExit()
778 SessionPtr aMgr = ModelAPI_Session::get();
779 if (aMgr->isModified()) {
780 int anAnswer = QMessageBox::question(
781 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
782 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
783 if (anAnswer == QMessageBox::Save) {
784 bool saved = onSave();
788 } else if (anAnswer == QMessageBox::Cancel) {
795 //******************************************************
796 void XGUI_Workshop::onPreferences()
798 ModuleBase_Prefs aModif;
799 ModuleBase_Preferences::editPreferences(aModif);
800 if (aModif.size() > 0) {
802 foreach (ModuleBase_Pref aPref, aModif)
804 aSection = aPref.first;
805 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
806 myMainWindow->viewer()->updateFromResources();
807 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
808 myMainWindow->menuObject()->updateFromResources();
811 displayer()->redisplayObjects();
816 //******************************************************
817 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
819 XGUI_Displayer* aDisplayer = displayer();
821 aDisplayer->displayTrihedron(theState);
824 //******************************************************
825 bool XGUI_Workshop::onSave()
827 if(!abortAllOperations())
829 if (myCurrentDir.isEmpty()) {
832 std::list<std::string> aFiles;
833 saveDocument(myCurrentDir, aFiles);
834 updateCommandStatus();
836 myMainWindow->setModifiedState(false);
841 //******************************************************
842 bool XGUI_Workshop::onSaveAs()
844 if(!abortAllOperations())
846 QFileDialog dialog(desktop());
847 dialog.setWindowTitle(tr("Select directory to save files..."));
848 dialog.setFileMode(QFileDialog::Directory);
849 dialog.setFilter(tr("Directories (*)"));
850 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
851 dialog.setViewMode(QFileDialog::Detail);
853 if (!dialog.exec()) {
857 QString aTempDir = dialog.selectedFiles().first();
859 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
860 int answer = QMessageBox::question(
862 //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
864 tr("The directory already contains some files, save anyway?"),
865 QMessageBox::Save | QMessageBox::Cancel);
866 if (answer == QMessageBox::Cancel) {
870 myCurrentDir = aTempDir;
872 myMainWindow->setCurrentDir(myCurrentDir, false);
873 myMainWindow->setModifiedState(false);
878 //******************************************************
879 void XGUI_Workshop::onUndo(int theTimes)
881 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
882 SessionPtr aMgr = ModelAPI_Session::get();
883 std::list<std::string> aUndoList = aMgr->undoList();
884 if (aMgr->isOperation()) {
885 /// this is important for nested operations
886 /// when sketch operation is active, this condition is false and
887 /// the sketch operation is not aborted
888 operationMgr()->onAbortOperation();
890 std::list<std::string>::const_iterator aIt = aUndoList.cbegin();
891 for (int i = 0; (i < theTimes) && (aIt != aUndoList.cend()); ++i, ++aIt) {
893 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
894 myObjectBrowser->rebuildDataTree();
897 operationMgr()->updateApplyOfOperations();
898 updateCommandStatus();
901 //******************************************************
902 void XGUI_Workshop::onRedo(int theTimes)
904 // the viewer update should be blocked in order to avoid the features blinking. For the created
905 // feature a results are created, the flush of the created signal caused the viewer redisplay for
906 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked until
907 // redo of all possible objects happens
908 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
910 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
911 SessionPtr aMgr = ModelAPI_Session::get();
912 std::list<std::string> aRedoList = aMgr->redoList();
913 if (aMgr->isOperation()) {
914 /// this is important for nested operations
915 /// when sketch operation is active, this condition is false and
916 /// the sketch operation is not aborted
917 operationMgr()->onAbortOperation();
919 std::list<std::string>::const_iterator aIt = aRedoList.cbegin();
920 for (int i = 0; (i < theTimes) && (aIt != aRedoList.cend()); ++i, ++aIt) {
922 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
923 myObjectBrowser->rebuildDataTree();
925 operationMgr()->updateApplyOfOperations();
926 updateCommandStatus();
928 // unblock the viewer update functionality and make update on purpose
929 myDisplayer->enableUpdateViewer(isUpdateEnabled);
930 myDisplayer->updateViewer();
933 //******************************************************
934 //void XGUI_Workshop::onRebuild()
936 // SessionPtr aMgr = ModelAPI_Session::get();
937 // bool aWasOperation = aMgr->isOperation(); // keep this value
938 // if (!aWasOperation) {
939 // aMgr->startOperation("Rebuild");
941 // static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
942 // Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
943 // new Events_Message(aRebuildEvent, this)));
944 // if (!aWasOperation) {
945 // aMgr->finishOperation();
947 // updateCommandStatus();
950 //******************************************************
951 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
953 ModuleBase_ModelWidget* anActiveWidget = 0;
954 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
956 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
958 anActiveWidget = aPanel->activeWidget();
961 operationMgr()->onValidateOperation();
963 myModule->widgetStateChanged(thePreviousState);
966 //******************************************************
967 void XGUI_Workshop::onValuesChanged()
969 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
970 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
973 ModuleBase_ModelWidget* anActiveWidget = 0;
974 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
976 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
978 anActiveWidget = aPanel->activeWidget();
980 if (anActiveWidget) {
981 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
983 if (aWidgetValidated)
984 aWidgetValidated->clearValidatedCash();
988 void XGUI_Workshop::onWidgetObjectUpdated()
990 operationMgr()->onValidateOperation();
993 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
995 QString libName = QString::fromStdString(library(theModule.toStdString()));
996 if (libName.isEmpty()) {
997 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1002 CREATE_FUNC crtInst = 0;
1005 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
1009 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1010 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1011 QString aMsg((char*) &lpMsgBuf);
1012 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1013 ::LocalFree(lpMsgBuf);
1015 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1019 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1020 | FORMAT_MESSAGE_IGNORE_INSERTS,
1021 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1022 QString aMsg((char*) &lpMsgBuf);
1023 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1024 ::LocalFree(lpMsgBuf);
1028 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1030 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1032 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1034 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1039 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1041 if (!err.isEmpty()) {
1043 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1045 qWarning(qPrintable(err));
1051 //******************************************************
1052 bool XGUI_Workshop::createModule()
1054 Config_ModuleReader aModuleReader;
1055 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1056 myModule = loadModule(moduleName);
1060 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1061 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1062 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1063 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1065 myModule->createFeatures();
1067 salomeConnector()->createFeatureActions();
1069 //myActionsMgr->update();
1073 //******************************************************
1074 void XGUI_Workshop::updateCommandStatus()
1076 QList<QAction*> aCommands;
1078 aCommands = salomeConnector()->commandList();
1080 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1081 foreach (AppElements_Command* aCmd, aMenuBar->features())
1082 aCommands.append(aCmd);
1084 SessionPtr aMgr = ModelAPI_Session::get();
1085 if (aMgr->hasModuleDocument()) {
1086 foreach(QAction* aCmd, aCommands) {
1087 QString aId = aCmd->data().toString();
1088 if (aId == "UNDO_CMD")
1089 aCmd->setEnabled(myModule->canUndo());
1090 else if (aId == "REDO_CMD")
1091 aCmd->setEnabled(myModule->canRedo());
1093 // Enable all commands
1094 aCmd->setEnabled(true);
1098 foreach(QAction* aCmd, aCommands) {
1099 QString aId = aCmd->data().toString();
1100 if (aId == "NEW_CMD")
1101 aCmd->setEnabled(true);
1102 else if (aId == "EXIT_CMD")
1103 aCmd->setEnabled(true);
1105 aCmd->setEnabled(false);
1108 myActionsMgr->updateCommandsStatus();
1109 emit commandStatusUpdated();
1112 void XGUI_Workshop::updateHistory()
1114 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1115 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1116 emit updateUndoHistory(aUndoRes);
1118 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1119 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1120 emit updateRedoHistory(aRedoRes);
1123 //******************************************************
1124 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1126 QDockWidget* aObjDock = new QDockWidget(theParent);
1127 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1128 aObjDock->setWindowTitle(tr("Object browser"));
1129 aObjDock->setStyleSheet(
1130 "::title { position: relative; padding-left: 5px; text-align: left center }");
1131 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1132 myObjectBrowser->setXMLReader(myDataModelXMLReader);
1133 myModule->customizeObjectBrowser(myObjectBrowser);
1134 aObjDock->setWidget(myObjectBrowser);
1136 myContextMenuMgr->connectObjectBrowser();
1140 //******************************************************
1142 * Creates dock widgets, places them in corresponding area
1143 * and tabifies if necessary.
1145 void XGUI_Workshop::createDockWidgets()
1147 QMainWindow* aDesktop = desktop();
1148 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1149 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1150 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1151 myPropertyPanel->setupActions(myActionsMgr);
1152 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1153 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1154 hidePropertyPanel(); ///<! Invisible by default
1155 hideObjectBrowser();
1156 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1157 myPropertyPanel->installEventFilter(myOperationMgr);
1159 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1160 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1162 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1163 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1165 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1166 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1168 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1169 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1170 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1171 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1174 //******************************************************
1175 void XGUI_Workshop::showPropertyPanel()
1177 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1178 ///<! Restore ability to close panel from the window's menu
1179 aViewAct->setEnabled(true);
1180 myPropertyPanel->show();
1181 myPropertyPanel->raise();
1183 // The next code is necessary to made the property panel the active window
1184 // in order to operation manager could process key events of the panel.
1185 // otherwise they are ignored. It happens only if the same(activateWindow) is
1186 // not happened by property panel activation(e.g. resume operation of Sketch)
1187 ModuleBase_Tools::activateWindow(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1188 ModuleBase_Tools::setFocus(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1191 //******************************************************
1192 void XGUI_Workshop::hidePropertyPanel()
1194 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1195 ///<! Do not allow to show empty property panel
1196 aViewAct->setEnabled(false);
1197 myPropertyPanel->hide();
1199 // the property panel is active window of the desktop, when it is
1200 // hidden, it is undefined which window becomes active. By this reason
1201 // it is defined to perform the desktop as the active window.
1202 // in SALOME mode, workstack made the PyConsole the active window,
1203 // set the focus on it. As a result, shortcuts of the application, like
1204 // are processed by this console. For example Undo actions.
1205 // It is possible that this code is to be moved to SHAPER package
1206 QMainWindow* aDesktop = desktop();
1207 ModuleBase_Tools::activateWindow(aDesktop, "XGUI_Workshop::hidePropertyPanel()");
1208 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::showPropertyPanel()");
1211 //******************************************************
1212 void XGUI_Workshop::showObjectBrowser()
1214 if (!isSalomeMode())
1215 myObjectBrowser->parentWidget()->show();
1218 //******************************************************
1219 void XGUI_Workshop::hideObjectBrowser()
1221 if (!isSalomeMode())
1222 myObjectBrowser->parentWidget()->hide();
1225 //******************************************************
1226 void XGUI_Workshop::salomeViewerSelectionChanged()
1228 emit salomeViewerSelection();
1231 //**************************************************************
1232 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1234 return mySalomeConnector->viewer();
1237 //**************************************************************
1238 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1240 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1241 if (theId == "DELETE_CMD")
1243 else if (theId == "CLEAN_HISTORY_CMD")
1245 else if (theId == "MOVE_CMD")
1247 else if (theId == "COLOR_CMD")
1248 changeColor(aObjects);
1249 else if (theId == "SHOW_CMD") {
1250 showObjects(aObjects, true);
1251 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1253 else if (theId == "HIDE_CMD")
1254 showObjects(aObjects, false);
1255 else if (theId == "SHOW_ONLY_CMD") {
1256 showOnlyObjects(aObjects);
1257 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1259 else if (theId == "SHADING_CMD")
1260 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1261 else if (theId == "WIREFRAME_CMD")
1262 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1263 else if (theId == "HIDEALL_CMD") {
1264 QObjectPtrList aList = myDisplayer->displayedObjects();
1265 foreach (ObjectPtr aObj, aList) {
1266 if (module()->canEraseObject(aObj))
1267 aObj->setDisplayed(false);
1269 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1270 } else if (theId == "SELECT_VERTEX_CMD") {
1271 setViewerSelectionMode(TopAbs_VERTEX);
1272 } else if (theId == "SELECT_EDGE_CMD") {
1273 setViewerSelectionMode(TopAbs_EDGE);
1274 } else if (theId == "SELECT_FACE_CMD") {
1275 setViewerSelectionMode(TopAbs_FACE);
1276 } else if (theId == "SELECT_RESULT_CMD") {
1277 //setViewerSelectionMode(-1);
1278 //IMP: an attempt to use result selection with other selection modes
1279 setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1280 setViewerSelectionMode(TopAbs_COMPSOLID);
1281 } else if (theId == "SHOW_RESULTS_CMD") {
1282 highlightResults(aObjects);
1283 } else if (theId == "SHOW_FEATURE_CMD") {
1284 highlightFeature(aObjects);
1288 //**************************************************************
1289 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1292 myViewerSelMode.clear();
1294 if (myViewerSelMode.contains(theMode))
1295 myViewerSelMode.removeAll(theMode);
1297 myViewerSelMode.append(theMode);
1299 activateObjectsSelection(myDisplayer->displayedObjects());
1302 //**************************************************************
1303 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1306 module()->activeSelectionModes(aModes);
1307 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1308 aModes.append(myViewerSelMode);
1309 myDisplayer->activateObjects(aModes, theList);
1312 //**************************************************************
1313 void XGUI_Workshop::deleteObjects()
1315 ModuleBase_IModule* aModule = module();
1316 // allow the module to delete objects, do nothing if it has succeed
1317 if (aModule->deleteObjects()) {
1318 updateCommandStatus();
1322 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1323 if (!abortAllOperations())
1326 bool hasResult = false;
1327 bool hasFeature = false;
1328 bool hasParameter = false;
1329 bool hasCompositeOwner = false;
1330 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner);
1331 if (!(hasFeature || hasParameter))
1335 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1336 std::set<FeaturePtr> aFeatures;
1337 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1338 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1341 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1342 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1343 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1345 operationMgr()->startOperation(anOpAction);
1347 std::set<FeaturePtr> aFeatureRefsToDelete;
1348 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1349 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1350 // It is necessary to clear selection in order to avoid selection changed event during
1351 // deletion and negative consequences connected with processing of already deleted items
1352 mySelector->clearSelection();
1354 if (!aFeatureRefsToDelete.empty())
1355 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1356 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1359 operationMgr()->commitOperation();
1361 operationMgr()->abortOperation(operationMgr()->currentOperation());
1364 //**************************************************************
1365 void addRefsToFeature(const FeaturePtr& theFeature,
1366 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1367 std::set<FeaturePtr>& theReferences)
1369 //if (theReferences.find(theFeature) != theReferences.end())
1371 if (theMainList.find(theFeature) == theMainList.end())
1372 return; // this feature is not in the selection list, so exists without references to it
1373 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1375 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1376 aLast = aMainReferences.end();
1377 for (; anIt != aLast; anIt++) {
1378 FeaturePtr aRefFeature = *anIt;
1379 if (theReferences.find(aRefFeature) == theReferences.end())
1380 theReferences.insert(aRefFeature);
1381 addRefsToFeature(aRefFeature, theMainList, theReferences);
1385 //**************************************************************
1386 void XGUI_Workshop::cleanHistory()
1388 if (!abortAllOperations())
1391 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1392 std::set<FeaturePtr> aFeatures;
1393 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1395 #ifdef DEBUG_CLEAN_HISTORY
1397 std::set<FeaturePtr>::const_iterator aFIt;
1398 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1399 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1400 anInfo.append(aFeature->name().c_str());
1402 QString anInfoStr = anInfo.join(";\t");
1403 qDebug(QString("cleanHistory for: [%1] - %2").arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1406 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1407 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1408 // find for each object whether all reference values are in the map as key, that means that there is
1409 // no other reference in the model to this object, so it might be removed by cleaning history
1410 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1
1411 // ext_1(bool_1, sk_3) - cann't be deleted, dependency to bool_1
1413 // sk_2(ext_2) + (bool_1) - cann't be deleted, dependency to bool_1
1414 // ext_2(bool_1) - cann't be deleted, dependency to bool_1
1416 // Information: bool_1 is not selected
1417 std::set<FeaturePtr> anUnusedObjects;
1418 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1419 aMainLast = aReferences.end();
1420 for (; aMainIt != aMainLast; aMainIt++) {
1421 FeaturePtr aMainListFeature = aMainIt->first;
1422 std::set<FeaturePtr> aMainRefList = aMainIt->second;
1423 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(), aRefLast = aMainRefList.end();
1424 bool aFeatureOutOfTheList = false;
1425 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1426 FeaturePtr aRefFeature = *aRefIt;
1427 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1429 if (!aFeatureOutOfTheList)
1430 anUnusedObjects.insert(aMainListFeature);
1433 #ifdef DEBUG_CLEAN_HISTORY
1435 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1436 FeaturePtr aFeature = *aFIt;
1437 anInfo.append(aFeature->name().c_str());
1439 qDebug(QString("unused objects: [%1] - %2").arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1442 // warn about the references remove, break the delete operation if the user chose it
1443 if (!anUnusedObjects.empty()) {
1445 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1446 aNames.append(aFeature->name().c_str());
1449 QString anUnusedNames = aNames.join(", ");
1451 QString anActionId = "CLEAN_HISTORY_CMD";
1452 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1454 QMessageBox aMessageBox(desktop());
1455 aMessageBox.setWindowTitle(aDescription);
1456 aMessageBox.setIcon(QMessageBox::Warning);
1457 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1458 aMessageBox.setDefaultButton(QMessageBox::No);
1460 QString aText = QString(tr("Unused features are the following: %1.\nThese features will be deleted.\nWould you like to continue?")
1461 .arg(anUnusedNames));
1462 aMessageBox.setText(aText);
1463 if (aMessageBox.exec() == QMessageBox::No)
1466 // 1. start operation
1467 aDescription += "by deleting of " + aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1468 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1469 operationMgr()->startOperation(anOpAction);
1471 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1472 // It is necessary to clear selection in order to avoid selection changed event during
1473 // deletion and negative consequences connected with processing of already deleted items
1474 mySelector->clearSelection();
1476 std::set<FeaturePtr> anIgnoredFeatures;
1477 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
1478 operationMgr()->commitOperation();
1481 operationMgr()->abortOperation(operationMgr()->currentOperation());
1485 QString anActionId = "CLEAN_HISTORY_CMD";
1486 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1488 QMessageBox aMessageBox(desktop());
1489 aMessageBox.setWindowTitle(aDescription);
1490 aMessageBox.setIcon(QMessageBox::Warning);
1491 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1492 aMessageBox.setDefaultButton(QMessageBox::No);
1495 aMessageBox.setStandardButtons(QMessageBox::Ok);
1496 aMessageBox.setDefaultButton(QMessageBox::Ok);
1498 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1499 aMessageBox.setText(aText);
1501 if (aMessageBox.exec() == QMessageBox::No)
1506 //**************************************************************
1507 void XGUI_Workshop::moveObjects()
1509 if (!abortAllOperations())
1512 SessionPtr aMgr = ModelAPI_Session::get();
1514 QString anActionId = "MOVE_CMD";
1515 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1516 aMgr->startOperation(aDescription.toStdString());
1518 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1519 // It is necessary to clear selection in order to avoid selection changed event during
1520 // moving and negative consequences connected with processing of already moved items
1521 mySelector->clearSelection();
1522 // check whether the object can be moved. There should not be parts which are not loaded
1523 std::set<FeaturePtr> aFeatures;
1524 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1525 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
1528 DocumentPtr anActiveDocument = aMgr->activeDocument();
1529 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1530 std::set<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
1531 for (; anIt != aLast; anIt++) {
1532 FeaturePtr aFeature = *anIt;
1533 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
1536 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1537 aCurrentFeature = anActiveDocument->currentFeature(true);
1539 aMgr->finishOperation();
1542 //**************************************************************
1543 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
1545 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1546 std::set<FeaturePtr> aFeatures;
1547 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
1549 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
1552 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1554 bool isFoundResultType = false;
1555 foreach(ObjectPtr anObj, theObjects)
1557 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1558 if (aResult.get() == NULL)
1561 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1562 if (isFoundResultType)
1565 return isFoundResultType;
1568 //**************************************************************
1569 // Returns the list of all features for theDocument and all features of
1570 // all nested parts.
1571 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
1573 std::list<FeaturePtr> aResultList;
1574 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
1575 foreach (const FeaturePtr& aFeature, anAllFeatures) {
1576 // The order of appending features of the part and the part itself is important
1578 // Append features from a part feature
1579 std::list<ResultPtr> aResults;
1580 ModelAPI_Tools::allResults(aFeature, aResults);
1581 foreach (const ResultPtr& aResult, aResults) {
1582 ResultPartPtr aResultPart =
1583 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
1584 if (aResultPart.get() && aResultPart->partDoc().get()) {
1586 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
1587 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
1591 aResultList.push_back(aFeature);
1596 //**************************************************************
1597 // Returns the list of features placed between theObject and the current feature
1598 // in the same document. Excludes theObject, includes the current feature.
1599 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1601 std::list<FeaturePtr> aResult;
1602 DocumentPtr aDocument = theObject->document();
1603 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
1604 // find the object iterator
1605 std::list<FeaturePtr>::iterator aObjectIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1606 if (aObjectIt == anAllFeatures.end())
1608 // find the current feature iterator
1609 std::list<FeaturePtr>::iterator aCurrentIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
1610 if (aCurrentIt == anAllFeatures.end())
1612 // check the right order
1613 if (std::distance(aObjectIt, anAllFeatures.end()) <= std::distance(aCurrentIt, anAllFeatures.end()))
1615 // exclude the object
1616 std::advance(aObjectIt, 1);
1617 // include the current feature
1618 std::advance(aCurrentIt, 1);
1619 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
1622 bool XGUI_Workshop::canMoveFeature()
1624 QString anActionId = "MOVE_CMD";
1626 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1627 QObjectPtrList aValidatedObjects;
1628 foreach (ObjectPtr aObject, aObjects) {
1629 if (!myModule->canApplyAction(aObject, anActionId))
1631 // To be moved feature should be in active document
1632 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
1634 aValidatedObjects.append(aObject);
1636 if (aValidatedObjects.size() != aObjects.size())
1637 aObjects = aValidatedObjects;
1639 bool aCanMove = !aObjects.empty();
1641 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
1642 for (; anIt != aLast && aCanMove; anIt++) {
1643 ObjectPtr aObject = *anIt;
1644 // 1. Get features placed between selected and current in the document
1645 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
1646 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
1647 if (aFeaturesBetween.empty())
1650 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
1651 // 2. Get all reference features to the selected object in the document
1652 std::set<FeaturePtr> aRefFeatures;
1653 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
1655 if (aRefFeatures.empty())
1658 // 3. Find any placed features in all reference features
1659 std::set<FeaturePtr> aIntersectionFeatures;
1660 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
1661 aPlacedFeatures.begin(), aPlacedFeatures.end(),
1662 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
1663 // 4. Return false if any reference feature is placed before current feature
1664 if (!aIntersectionFeatures.empty())
1672 //**************************************************************
1673 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
1675 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
1676 if (!aCanBeShaded) {
1677 ResultCompSolidPtr aCompsolidResult =
1678 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
1679 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1680 for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
1681 aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
1684 return aCanBeShaded;
1687 //**************************************************************
1688 bool XGUI_Workshop::canChangeColor() const
1690 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1692 std::set<std::string> aTypes;
1693 aTypes.insert(ModelAPI_ResultGroup::group());
1694 aTypes.insert(ModelAPI_ResultConstruction::group());
1695 aTypes.insert(ModelAPI_ResultBody::group());
1696 aTypes.insert(ModelAPI_ResultPart::group());
1698 return hasResults(aObjects, aTypes);
1701 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
1703 if (!theResult.get())
1706 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1707 if (aColorAttr.get() != NULL) {
1708 if (!aColorAttr->size()) {
1709 aColorAttr->setSize(3);
1711 aColorAttr->setValue(0, theColor[0]);
1712 aColorAttr->setValue(1, theColor[1]);
1713 aColorAttr->setValue(2, theColor[2]);
1717 //**************************************************************
1718 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1721 AttributeIntArrayPtr aColorAttr;
1722 // 1. find the current color of the object. This is a color of AIS presentation
1723 // The objects are iterated until a first valid color is found
1724 std::vector<int> aColor;
1725 foreach(ObjectPtr anObject, theObjects) {
1726 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1727 if (aResult.get()) {
1728 XGUI_CustomPrs::getResultColor(aResult, aColor);
1731 // TODO: remove the obtaining a color from the AIS object
1732 // this does not happen never because:
1733 // 1. The color can be changed only on results
1734 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1735 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1736 if (anAISObj.get()) {
1738 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1741 if (!aColor.empty())
1744 if (aColor.size() != 3)
1747 if (!abortAllOperations())
1749 // 2. show the dialog to change the value
1750 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
1751 aDlg->setColor(aColor);
1752 aDlg->move(QCursor::pos());
1753 bool isDone = aDlg->exec() == QDialog::Accepted;
1757 bool isRandomColor = aDlg->isRandomColor();
1759 // 3. abort the previous operation and start a new one
1760 SessionPtr aMgr = ModelAPI_Session::get();
1761 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
1762 aMgr->startOperation(aDescription.toStdString());
1764 // 4. set the value to all results
1765 std::vector<int> aColorResult = aDlg->getColor();
1766 foreach(ObjectPtr anObj, theObjects) {
1767 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1768 if (aResult.get() != NULL) {
1769 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1770 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1771 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1772 setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult : aDlg->getRandomColor());
1775 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
1778 aMgr->finishOperation();
1779 updateCommandStatus();
1782 //**************************************************************
1783 bool XGUI_Workshop::canChangeDeflection() const
1785 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1787 std::set<std::string> aTypes;
1788 aTypes.insert(ModelAPI_ResultGroup::group());
1789 aTypes.insert(ModelAPI_ResultConstruction::group());
1790 aTypes.insert(ModelAPI_ResultBody::group());
1791 aTypes.insert(ModelAPI_ResultPart::group());
1793 return hasResults(aObjects, aTypes);
1796 void setDeflection(ResultPtr theResult, const double theDeflection)
1798 if (!theResult.get())
1801 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
1802 if (aDeflectionAttr.get() != NULL)
1803 aDeflectionAttr->setValue(theDeflection);
1807 //**************************************************************
1808 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
1810 AttributeDoublePtr aDoubleAttr;
1811 // 1. find the current color of the object. This is a color of AIS presentation
1812 // The objects are iterated until a first valid color is found
1813 double aDeflection = -1;
1814 foreach(ObjectPtr anObject, theObjects) {
1815 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1816 if (aResult.get()) {
1817 aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
1820 // TODO: remove the obtaining a color from the AIS object
1821 // this does not happen never because:
1822 // 1. The color can be changed only on results
1823 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1824 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1825 if (anAISObj.get()) {
1826 aDeflection = anAISObj->getDeflection();
1829 if (aDeflection > 0)
1832 if (aDeflection < 0)
1835 if (!abortAllOperations())
1837 // 2. show the dialog to change the value
1838 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
1839 aDlg->setDeflection(aDeflection);
1840 aDlg->move(QCursor::pos());
1841 bool isDone = aDlg->exec() == QDialog::Accepted;
1845 // 3. abort the previous operation and start a new one
1846 SessionPtr aMgr = ModelAPI_Session::get();
1847 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
1848 aMgr->startOperation(aDescription.toStdString());
1850 // 4. set the value to all results
1851 aDeflection = aDlg->getDeflection();
1852 foreach(ObjectPtr anObj, theObjects) {
1853 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1854 if (aResult.get() != NULL) {
1855 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1856 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1857 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1858 setDeflection(aCompsolidResult->subResult(i), aDeflection);
1861 setDeflection(aResult, aDeflection);
1864 aMgr->finishOperation();
1865 updateCommandStatus();
1868 //**************************************************************
1869 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
1870 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
1871 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
1873 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1875 foreach (ObjectPtr aObj, theList) {
1877 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1879 DocumentPtr aDoc = aPartRes->partDoc();
1880 SET_DISPLAY_GROUP(ModelAPI_ResultBody::group(), isVisible)
1881 SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), isVisible)
1882 SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), isVisible)
1885 aObj->setDisplayed(isVisible);
1888 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1891 //**************************************************************
1892 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1894 // Hide all displayed objects
1895 QObjectPtrList aList = myDisplayer->displayedObjects();
1896 foreach (ObjectPtr aObj, aList) {
1897 if (module()->canEraseObject(aObj))
1898 aObj->setDisplayed(false);
1901 // Show only objects from the list
1902 foreach (ObjectPtr aObj, theList) {
1904 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1906 DocumentPtr aDoc = aPartRes->partDoc();
1907 SET_DISPLAY_GROUP(ModelAPI_ResultBody::group(), true)
1908 SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), true)
1909 SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), true)
1912 aObj->setDisplayed(true);
1915 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1920 //**************************************************************
1921 void XGUI_Workshop::registerValidators() const
1923 SessionPtr aMgr = ModelAPI_Session::get();
1924 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1927 //**************************************************************
1928 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1932 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1933 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1936 //**************************************************************
1937 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1939 for (int i = 0; i < theDoc->size(theGroup); i++)
1940 theDoc->object(theGroup, i)->setDisplayed(true);
1941 //displayObject(theDoc->object(theGroup, i));
1942 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1945 //**************************************************************
1946 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1948 foreach(ObjectPtr aObj, theList) {
1949 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1951 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
1952 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1953 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1954 myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
1955 (XGUI_Displayer::DisplayMode)theMode, false);
1959 if (theList.size() > 0)
1960 myDisplayer->updateViewer();
1963 //**************************************************************
1964 void XGUI_Workshop::closeDocument()
1966 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1967 while (anOperation) {
1968 anOperation->abort();
1969 anOperation = operationMgr()->currentOperation();
1971 myDisplayer->closeLocalContexts();
1972 myDisplayer->eraseAll();
1973 objectBrowser()->clearContent();
1975 module()->closeDocument();
1977 SessionPtr aMgr = ModelAPI_Session::get();
1981 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
1983 XGUI_HistoryMenu* aMenu = NULL;
1984 if (isSalomeMode()) {
1985 QAction* anAction = qobject_cast<QAction*>(theObject);
1988 aMenu = new XGUI_HistoryMenu(anAction);
1990 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
1991 aMenu = new XGUI_HistoryMenu(aButton);
1993 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
1994 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
1997 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
1999 QList<ActionInfo> aResult;
2000 std::list<std::string>::const_iterator it = theList.cbegin();
2001 for (; it != theList.cend(); it++) {
2002 QString anId = QString::fromStdString(*it);
2003 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2005 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2008 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2009 if (aContextMenuAct) {
2010 anInfo.initFrom(aContextMenuAct);
2012 anInfo = myActionsMgr->actionInfoById(anId);
2015 anInfo.text = anInfo.text.prepend("Modify ");
2022 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2025 salomeConnector()->putInfo(theMessage, -1);
2027 myMainWindow->putInfo(theMessage, -1);
2031 void XGUI_Workshop::synchronizeViewer()
2033 SessionPtr aMgr = ModelAPI_Session::get();
2034 DocumentPtr aDoc = aMgr->activeDocument();
2036 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
2037 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
2038 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
2039 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
2042 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2043 const std::string& theGroup,
2044 bool theUpdateViewer)
2047 int aSize = theDoc->size(theGroup);
2048 for (int i = 0; i < aSize; i++) {
2049 aObj = theDoc->object(theGroup, i);
2050 if (aObj->isDisplayed()) {
2051 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2052 // be changed to the object becomes visible when the shape becomes not empty
2053 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2054 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
2056 myDisplayer->display(aObj, false);
2059 if (theUpdateViewer)
2060 myDisplayer->updateViewer();
2063 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2065 FeaturePtr aFeature;
2066 QObjectPtrList aSelList = theObjects;
2067 std::list<ResultPtr> aResList;
2068 bool aHasHidden = false;
2069 foreach(ObjectPtr aObj, theObjects) {
2070 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2071 if (aFeature.get()) {
2072 std::list<ResultPtr> aResults;
2073 ModelAPI_Tools::allResults(aFeature, aResults);
2074 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2075 for(aIt = aResList.cbegin(); aIt != aResList.cend(); aIt++) {
2076 aHasHidden |= (*aIt)->isConcealed();
2077 aSelList.append(*aIt);
2081 if (aSelList.count() > theObjects.count()) {
2082 // if something was found
2083 bool aBlocked = objectBrowser()->blockSignals(true);
2084 objectBrowser()->setObjectsSelected(aSelList);
2085 objectBrowser()->blockSignals(aBlocked);
2088 QMessageBox::information(desktop(), tr("Find results"),
2089 tr("Results not found"), QMessageBox::Ok);
2092 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2095 QObjectPtrList aSelList = theObjects;
2096 FeaturePtr aFeature;
2097 foreach(ObjectPtr aObj, theObjects) {
2098 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2099 if (aResult.get()) {
2100 aFeature = ModelAPI_Feature::feature(aResult);
2101 if (aFeature.get()) {
2102 aSelList.append(aFeature);
2106 if (aSelList.count() > theObjects.count()) {
2107 // if something was found
2108 bool aBlocked = objectBrowser()->blockSignals(true);
2109 objectBrowser()->setObjectsSelected(aSelList);
2110 objectBrowser()->blockSignals(aBlocked);