Salome HOME
Issue #1135 Hide all for GEOM objects
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 //#include "XGUI_Constants.h"
4 #include "XGUI_Workshop.h"
5
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>
27 #include <XGUI_DataModel.h>
28
29 #ifndef HAVE_SALOME
30 #include <AppElements_Button.h>
31 #include <AppElements_Command.h>
32 #include <AppElements_MainMenu.h>
33 #include <AppElements_MainWindow.h>
34 #include <AppElements_MenuGroupPanel.h>
35 #include <AppElements_Viewer.h>
36 #include <AppElements_Workbench.h>
37 #endif
38
39 #include <ModelAPI_AttributeDocRef.h>
40 #include <ModelAPI_AttributeIntArray.h>
41 #include <ModelAPI_AttributeDouble.h>
42 #include <ModelAPI_Data.h>
43 #include <ModelAPI_Events.h>
44 #include <ModelAPI_Feature.h>
45 #include <ModelAPI_Object.h>
46 #include <ModelAPI_ResultBody.h>
47 #include <ModelAPI_ResultConstruction.h>
48 #include <ModelAPI_ResultGroup.h>
49 #include <ModelAPI_ResultParameter.h>
50 #include <ModelAPI_ResultField.h>
51 #include <ModelAPI_Session.h>
52 #include <ModelAPI_Validator.h>
53 #include <ModelAPI_ResultCompSolid.h>
54 #include <ModelAPI_Tools.h>
55
56 //#include <PartSetPlugin_Part.h>
57
58 #include <Events_Loop.h>
59 #include <Events_InfoMessage.h>
60 #include <Events_LongOp.h>
61
62 #include <ModuleBase_IModule.h>
63 #include <ModuleBase_IViewer.h>
64 #include <ModuleBase_Operation.h>
65 #include <ModuleBase_OperationDescription.h>
66 #include <ModuleBase_PageBase.h>
67 #include <ModuleBase_Preferences.h>
68 #include <ModuleBase_SelectionValidator.h>
69 #include <ModuleBase_Tools.h>
70 #include <ModuleBase_WidgetFactory.h>
71 #include <ModuleBase_OperationFeature.h>
72 #include <ModuleBase_OperationAction.h>
73 #include <ModuleBase_PagedContainer.h>
74 #include <ModuleBase_WidgetValidated.h>
75 #include <ModuleBase_ModelWidget.h>
76 #include <ModuleBase_ResultPrs.h>
77
78 #include <Config_Common.h>
79 #include <Config_FeatureMessage.h>
80 #include <Config_ModuleReader.h>
81 #include <Config_PointerMessage.h>
82 #include <Config_PropManager.h>
83 #include <Config_DataModelReader.h>
84 #include <Config_Translator.h>
85 #include <Config_WidgetAPI.h>
86 #include <Config_Keywords.h>
87
88 #include <SUIT_ResourceMgr.h>
89
90 #include <AIS_Trihedron.hxx>
91 #ifdef BEFORE_TRIHEDRON_PATCH
92 #include <AIS_Point.hxx>
93 #include <AIS_Axis.hxx>
94 #endif
95
96 #include <QApplication>
97 #include <QFileDialog>
98 #include <QMessageBox>
99 #include <QMdiSubWindow>
100 #include <QMainWindow>
101 #include <QPushButton>
102 #include <QDockWidget>
103 #include <QLayout>
104 #include <QThread>
105 #include <QObject>
106 #include <QMenu>
107 #include <QToolButton>
108 #include <QAction>
109 #include <QDesktopWidget>
110
111 #include <iterator>
112
113 #ifdef TINSPECTOR
114 #include <CDF_Session.hxx>
115 #include <CDF_Application.hxx>
116 #include <TInspector_Communicator.hxx>
117 #include <VInspector_CallBack.hxx>
118 static TInspector_Communicator* MyTCommunicator;
119 static Handle(VInspector_CallBack) MyVCallBack;
120
121 #endif
122
123 #ifdef _DEBUG
124 #include <QDebug>
125 #include <iostream>
126 #endif
127
128 #ifdef WIN32
129 #include <windows.h>
130 #else
131 #include <dlfcn.h>
132 #endif
133
134 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
135
136 //#define DEBUG_DELETE
137 //#define DEBUG_FEATURE_NAME
138 //#define DEBUG_CLEAN_HISTORY
139
140 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
141     : QObject(),
142       myCurrentDir(QString()),
143       myModule(NULL),
144       mySalomeConnector(theConnector),
145       myPropertyPanel(0),
146       myObjectBrowser(0),
147       myDisplayer(0)
148       //myViewerSelMode(TopAbs_FACE)
149 {
150   mySelector = new XGUI_SelectionMgr(this);
151   myModuleConnector = new XGUI_ModuleConnector(this);
152   myOperationMgr = new XGUI_OperationMgr(this, 0);
153   ModuleBase_IWorkshop* aWorkshop = moduleConnector();
154   // Has to be defined first in order to get errors and messages from other components
155   myEventsListener = new XGUI_WorkshopListener(aWorkshop);
156
157   SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
158 #ifndef HAVE_SALOME
159   myMainWindow = new AppElements_MainWindow();
160
161   bool aCloc = aResMgr->booleanValue("language", "locale", true);
162   if (aCloc)
163     QLocale::setDefault( QLocale::c() );
164   else
165     QLocale::setDefault( QLocale::system() );
166 #endif
167   QString aPath = Config_XMLReader::pluginConfigFile().c_str();
168   QDir aDir(aPath);
169
170   // Load translations
171   QStringList aLangs;
172   aLangs << "*_en.ts"; // load by default eng translations
173   QString aCurrLang = aResMgr->stringValue("language", "language", "en");
174   if(aCurrLang != "en") {
175     aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
176   }
177
178   foreach(QString aLang, aLangs) {
179     QStringList aFilters;
180     aFilters << aLang;
181     QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
182     foreach(QString aFileName, aTsFiles) {
183       Config_Translator::load(aFileName.toStdString());
184     }
185   }
186
187   myDataModelXMLReader = new Config_DataModelReader();
188   //myDataModelXMLReader->readAll();
189
190   myDisplayer = new XGUI_Displayer(this);
191
192   connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
193
194   myActionsMgr = new XGUI_ActionsMgr(this);
195   myMenuMgr = new XGUI_MenuMgr(this);
196   myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
197   myContextMenuMgr = new XGUI_ContextMenuMgr(this);
198   connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
199           SLOT(onContextMenuCommand(const QString&, bool)));
200
201   myViewerProxy = new XGUI_ViewerProxy(this);
202   //connect(myViewerProxy, SIGNAL(selectionChanged()),
203   //        myActionsMgr,  SLOT(updateOnViewSelection()));
204
205   myOperationMgr->setWorkshop(aWorkshop);
206
207   myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
208
209   connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
210           SLOT(onOperationResumed(ModuleBase_Operation*)));
211   connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
212           SLOT(onOperationStopped(ModuleBase_Operation*)));
213   connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
214           SLOT(onOperationCommitted(ModuleBase_Operation*)));
215   connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
216           SLOT(onOperationAborted(ModuleBase_Operation*)));
217
218 #ifndef HAVE_SALOME
219   connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
220   onTrihedronVisibilityChanged(true);
221 #endif
222
223   connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
224           myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
225
226   //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
227   //                                 Config_Prop::Color, "225,225,225");
228
229   Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
230                                    Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
231   Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
232                                    Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
233   Config_PropManager::registerProp("Visualization", "result_construction_color",
234                                    "Construction color",
235                                    Config_Prop::Color,
236                                    ModelAPI_ResultConstruction::DEFAULT_COLOR());
237   Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
238                                    Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
239   Config_PropManager::registerProp("Visualization", "result_field_color", "Field color",
240                                    Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR());
241
242   if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
243     myViewerSelMode.append(TopAbs_FACE);
244   if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
245     myViewerSelMode.append(TopAbs_EDGE);
246   if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
247     myViewerSelMode.append(TopAbs_VERTEX);
248   //IMP: an attempt to use result selection with other selection modes
249   myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
250   myViewerSelMode.append(TopAbs_COMPSOLID);
251 }
252
253 //******************************************************
254 XGUI_Workshop::~XGUI_Workshop(void)
255 {
256 #ifdef _DEBUG
257 #ifdef MISSED_TRANSLATION
258   // Save Missed translations
259   Config_Translator::saveMissedTranslations();
260 #endif
261 #endif
262
263   delete myDisplayer;
264   delete myDataModelXMLReader;
265 }
266
267 //******************************************************
268 void XGUI_Workshop::startApplication()
269 {
270   //Initialize event listening
271   myEventsListener->initializeEventListening();
272
273   myDataModelXMLReader->readAll();
274   initMenu();
275
276   Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
277                                    Config_Prop::Directory, "");
278
279
280   registerValidators();
281
282   // Calling of  loadCustomProps before activating module is required
283   // by Config_PropManger to restore user-defined path to plugins
284   ModuleBase_Preferences::loadCustomProps();
285   createModule();
286
287 #ifndef HAVE_SALOME
288   myMainWindow->show();
289   updateCommandStatus();
290 #endif
291
292   onNew();
293
294   myViewerProxy->connectViewProxy();
295   connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
296           SLOT(onTrihedronVisibilityChanged(bool)));
297
298   emit applicationStarted();
299 }
300
301 void XGUI_Workshop::activateModule()
302 {
303   myModule->activateSelectionFilters();
304
305   connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
306     myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
307   connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
308     myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
309
310   updateCommandStatus();
311
312   // TODO: get default selection mode
313
314   // activate visualized objects in the viewer
315   activateObjectsSelection(displayer()->displayedObjects());
316   myOperationMgr->activate();
317 }
318
319 void XGUI_Workshop::deactivateModule()
320 {
321   myModule->deactivateSelectionFilters();
322
323   // remove internal displayer filter
324   displayer()->deactivateSelectionFilters();
325
326   disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
327     myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
328   disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
329     myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
330
331   XGUI_Displayer* aDisplayer = displayer();
332   QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
333   aDisplayer->deactivateObjects(aDisplayed, true);
334   Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
335   Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aDisplayer->getTrihedron());
336   /// deactivate trihedron in selection modes
337   TColStd_ListOfInteger aTColModes;
338   aContext->ActivatedModes(aTrihedron, aTColModes);
339   TColStd_ListIteratorOfListOfInteger itr( aTColModes );
340   for (; itr.More(); itr.Next() ) {
341     Standard_Integer aMode = itr.Value();
342     aContext->Deactivate(aTrihedron, aMode);
343   }
344 #ifdef BEFORE_TRIHEDRON_PATCH
345   /// Trihedron problem: objects stayed in the viewer, should be removed manually
346   /// otherwise in SALOME happens crash by HideAll in the viewer
347   aContext->Remove(aTrihedron->Position(), true);
348   aContext->Remove(aTrihedron->Axis(), true);
349   aContext->Remove(aTrihedron->XAxis(), true);
350   aContext->Remove(aTrihedron->YAxis(), true);
351 #endif
352
353   myOperationMgr->deactivate();
354 }
355
356 //******************************************************
357 void XGUI_Workshop::initMenu()
358 {
359   myContextMenuMgr->createActions();
360
361 #ifdef HAVE_SALOME
362   // Create only Undo, Redo commands
363   QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
364                                                         tr("Undo last command"),
365                                                         QIcon(":pictures/undo.png"),
366                                                         QKeySequence::Undo, false,
367                                                         "MEN_DESK_EDIT");
368   QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
369   salomeConnector()->addActionInToolbar( aAction,aToolBarTitle  );
370
371   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
372   addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
373
374   aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
375                                               QIcon(":pictures/redo.png"), QKeySequence::Redo,
376                                               false, "MEN_DESK_EDIT");
377   salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
378
379   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
380   addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
381
382   salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
383   //aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"),
384   //                                            tr("Rebuild data objects"),
385   //                                            QIcon(":pictures/rebuild.png"), QKeySequence(),
386   //                                            false, "MEN_DESK_EDIT");
387   //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
388
389   //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
390   //salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
391
392   aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."),
393                                              tr("Export the current document into a native file"),
394                                               QIcon(), QKeySequence(),
395                                               false, "MEN_DESK_FILE");
396   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
397
398   aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."),
399                                               tr("Import native file"),
400                                               QIcon(), QKeySequence(),
401                                               false, "MEN_DESK_FILE");
402   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
403   salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
404
405 #else
406   // File commands group
407   AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
408
409   AppElements_Command* aCommand;
410
411   aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
412                                 QIcon(":pictures/save.png"), QKeySequence::Save);
413   aCommand->connectTo(this, SLOT(onSave()));
414   //aCommand->disable();
415
416   aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
417                                 QIcon(":pictures/save.png"), QKeySequence());
418   aCommand->connectTo(this, SLOT(onSaveAs()));
419
420   QString aUndoId = "UNDO_CMD";
421   aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
422                                 QIcon(":pictures/undo.png"), QKeySequence::Undo);
423   aCommand->connectTo(this, SLOT(onUndo()));
424   AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
425   addHistoryMenu(aUndoButton,
426                  SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
427                  SLOT(onUndo(int)));
428
429   QString aRedoId = "REDO_CMD";
430   aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
431                                 QIcon(":pictures/redo.png"), QKeySequence::Redo);
432   aCommand->connectTo(this, SLOT(onRedo()));
433   AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
434   addHistoryMenu(aRedoButton,
435                  SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
436                  SLOT(onRedo(int)));
437
438   //aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
439   //  QIcon(":pictures/rebuild.png"), QKeySequence());
440   //aCommand->connectTo(this, SLOT(onRebuild()));
441
442   //aCommand->disable();
443
444   aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
445                                 QIcon(":pictures/open.png"), QKeySequence::Open);
446   aCommand->connectTo(this, SLOT(onOpen()));
447
448   aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
449                                 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
450   aCommand->connectTo(this, SLOT(onPreferences()));
451
452   aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
453                                 QIcon(":pictures/close.png"), QKeySequence::Close);
454   aCommand->connectTo(this, SLOT(onExit()));
455 #endif
456 }
457
458 #ifndef HAVE_SALOME
459 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
460 {
461   AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
462   return aMenuBar->addWorkbench(theName);
463 }
464 #endif
465
466 //******************************************************
467 QMainWindow* XGUI_Workshop::desktop() const
468 {
469 #ifdef HAVE_SALOME
470   return salomeConnector()->desktop();
471 #else
472   return myMainWindow;
473 #endif
474 }
475
476 //******************************************************
477 void XGUI_Workshop::onStartWaiting()
478 {
479   if (Events_LongOp::isPerformed()) {
480     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
481   }
482 }
483
484 //******************************************************
485 void XGUI_Workshop::onAcceptActionClicked()
486 {
487   QAction* anAction = dynamic_cast<QAction*>(sender());
488   XGUI_OperationMgr* anOperationMgr = operationMgr();
489   if (anOperationMgr) {
490     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
491                                                     (anOperationMgr->currentOperation());
492     if (aFOperation) {
493       //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
494       myOperationMgr->onCommitOperation();
495     }
496   }
497 }
498
499 //******************************************************
500 void XGUI_Workshop::onPreviewActionClicked()
501 {
502   ModuleBase_IPropertyPanel* aPanel = propertyPanel();
503   if (aPanel) {
504     ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
505     if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
506       anActiveWidget->storeValue();
507     }
508   }
509   std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
510                 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
511   Events_Loop::loop()->send(aMsg);
512 }
513
514 //******************************************************
515 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
516 {
517   if (!myModule->canActivateSelection(theObject)) {
518     if (myDisplayer->isActive(theObject)) {
519       QObjectPtrList anObjects;
520       anObjects.append(theObject);
521       myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
522     }
523   }
524 }
525
526 //******************************************************
527 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
528 {
529   bool aHasNested = false;
530   std::string aFeatureKind = theFeature->getKind();
531 #ifdef HAVE_SALOME
532     XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
533     if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
534       aHasNested = true;
535 #else
536     AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
537     AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
538     if (aCommand && aCommand->button()->additionalButtonWidget())
539       aHasNested = true;
540 #endif
541   return aHasNested;
542 }
543
544 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
545 {
546   ModuleBase_OperationFeature* aFOperation =
547     dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
548   if (!aFOperation)
549     return;
550
551   showPropertyPanel();
552   myPropertyPanel->cleanContent();
553
554   QList<ModuleBase_ModelWidget*> aWidgets;
555   if (!module()->createWidgets(theOperation, aWidgets)) {
556     QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
557     ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
558     aFactory.createWidget(myPropertyPanel->contentWidget());
559     aWidgets = aFactory.getModelWidgets();
560   }
561
562   // check compatibility of feature and widgets
563   FeaturePtr aFeature = aFOperation->feature();
564   std::string aFeatureKind = aFeature->getKind();
565   foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
566     if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
567       std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
568       Events_InfoMessage("XGUI_Workshop", anErrorMsg)
569         .arg(aFeatureKind).arg(aWidget->attributeID())
570         .arg(aWidget->metaObject()->className()).send();
571       myPropertyPanel->cleanContent();
572       return;
573     }
574   }
575   // for performance purpose, flush should be done after all controls are filled
576   bool isUpdateFlushed = false;
577   foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
578     bool isStoreValue = !aFOperation->isEditOperation() &&
579                         !aWidget->getDefaultValue().empty() &&
580                         !aWidget->isComputedDefault();
581     aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
582     if (!isStoreValue)
583       aWidget->restoreValue();
584     aWidget->enableFocusProcessing();
585   }
586   ModuleBase_Tools::flushUpdated(aFeature);
587
588   // update visible state of Preview button
589   std::shared_ptr<Config_FeatureMessage> aFeatureInfo;
590 #ifdef HAVE_SALOME
591   aFeatureInfo = mySalomeConnector->featureInfo(aFeatureKind.c_str());
592 #else
593   AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
594   AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
595   if (aCommand)
596     aFeatureInfo = aCommand->featureMessage();
597 #endif
598   bool anIsAutoPreview = true;
599   if (aFeatureInfo.get())
600     anIsAutoPreview = aFeatureInfo->isAutoPreview();
601   else {
602     std::string aXmlCfg, aDescription;
603     module()->getXMLRepresentation(aFeatureKind, aXmlCfg, aDescription);
604     ModuleBase_WidgetFactory aFactory(aXmlCfg, moduleConnector());
605     anIsAutoPreview = aFactory.widgetAPI()->getBooleanAttribute(FEATURE_AUTO_PREVIEW, true);
606   }
607
608   if (!anIsAutoPreview) {
609     myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
610     // send signal about preview should not be computed automatically, click on preview
611     // button should initiate it
612     std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
613                   new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
614     Events_Loop::loop()->send(aMsg);
615   }
616   myPropertyPanel->setModelWidgets(aWidgets);
617   aFOperation->setPropertyPanel(myPropertyPanel);
618
619   myModule->propertyPanelDefined(theOperation);
620
621 #ifndef DEBUG_FEATURE_NAME
622   myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
623 #else
624   std::string aFeatureName = aFeature->name();
625   myPropertyPanel->setWindowTitle(QString("%1: %2")
626     .arg(theOperation->getDescription()->description())
627     .arg(aFeatureName.c_str()));
628 #endif
629
630   myErrorMgr->setPropertyPanel(myPropertyPanel);
631 }
632
633 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
634 {
635   XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
636   if (aPropertyPanel) {
637     const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
638     foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
639        myModule->connectToPropertyPanel(aWidget, isToConnect);
640        if (isToConnect) {
641         connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
642         connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
643         connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
644        }
645       else {
646         disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
647         disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
648         disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
649       }
650     }
651   }
652 }
653
654 //******************************************************
655 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
656 {
657   setGrantedFeatures(theOperation);
658
659   if (theOperation->getDescription()->hasXmlRepresentation()) {  //!< No need for property panel
660     fillPropertyPanel(theOperation);
661     connectToPropertyPanel(true);
662   }
663   updateCommandStatus();
664
665   myModule->operationResumed(theOperation);
666 }
667
668
669 //******************************************************
670 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
671 {
672   updateCommandStatus();
673
674   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
675                                                                         (theOperation);
676   if (!aFOperation)
677     return;
678
679   ModuleBase_ISelection* aSel = mySelector->selection();
680   QObjectPtrList aObj = aSel->selectedPresentations();
681   //!< No need for property panel
682   hidePropertyPanel();
683   myPropertyPanel->cleanContent();
684
685   connectToPropertyPanel(false);
686   myModule->operationStopped(aFOperation);
687
688   // the deactivated objects of the current operation should be activated back.
689   // They were deactivated on operation start or an object redisplay
690   QObjectPtrList anObjects;
691   FeaturePtr aFeature = aFOperation->feature();
692   if (aFeature.get()) { // feature may be not created (plugin load fail)
693     if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature))
694       anObjects.append(aFeature);
695     std::list<ResultPtr> aResults;
696     ModelAPI_Tools::allResults(aFeature, aResults);
697     std::list<ResultPtr>::const_iterator aIt;
698     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
699       ResultPtr anObject = *aIt;
700       if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) {
701         anObjects.append(anObject);
702       }
703     }
704   }
705   activateObjectsSelection(anObjects);
706 }
707
708
709 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
710 {
711   myModule->operationCommitted(theOperation);
712 }
713
714 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
715 {
716   myModule->operationAborted(theOperation);
717 }
718
719 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
720 {
721   ModuleBase_OperationFeature* aFOperation =
722     dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
723   if (!aFOperation)
724     return;
725
726   QStringList aGrantedIds;
727   if (isSalomeMode()) {
728     const std::shared_ptr<Config_FeatureMessage>& anInfo =
729                          mySalomeConnector->featureInfo(theOperation->id());
730     if (anInfo.get())
731       aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
732                                    .split(" ", QString::SkipEmptyParts);
733   }
734   else
735     aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
736
737   ModuleBase_IModule* aModule = module();
738   if (aModule)
739     aModule->grantedOperationIds(theOperation, aGrantedIds);
740
741   aFOperation->setGrantedOperationIds(aGrantedIds);
742 }
743
744 //******************************************************
745 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
746 {
747   QApplication::restoreOverrideCursor();
748   SessionPtr aMgr = ModelAPI_Session::get();
749
750   std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
751   std::list<DocumentPtr>::const_iterator aIt;
752   for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
753     std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
754     (*aIt)->storeNodesState(aState);
755   }
756
757   aMgr->save(theName.toLatin1().constData(), theFileNames);
758
759   QApplication::restoreOverrideCursor();
760 }
761
762 //******************************************************
763 bool XGUI_Workshop::abortAllOperations()
764 {
765   return myOperationMgr->abortAllOperations();
766 }
767
768 //******************************************************
769 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
770 {
771   setGrantedFeatures(theOperation);
772   if (!theOperation->getDescription()->hasXmlRepresentation()) {  //!< No need for property panel
773     updateCommandStatus();
774   }
775   else {
776     myModule->operationStarted(theOperation);
777   }
778 }
779
780 //******************************************************
781 void XGUI_Workshop::onOpen()
782 {
783   if(!abortAllOperations())
784     return;
785   //save current file before close if modified
786   SessionPtr aSession = ModelAPI_Session::get();
787   if (aSession->isModified()) {
788     //TODO(sbh): re-launch the app?
789     int anAnswer = QMessageBox::question(
790         desktop(), tr("Save current file"),
791         tr("The document is modified, save before opening another?"),
792         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
793     if (anAnswer == QMessageBox::Save) {
794       onSave();
795     } else if (anAnswer == QMessageBox::Cancel) {
796       return;
797     }
798     myCurrentDir = "";
799   }
800
801   //show file dialog, check if readable and open
802   QString aDirectory = QFileDialog::getExistingDirectory(desktop(), tr("Select directory"));
803   openDirectory(aDirectory);
804 }
805
806 //******************************************************
807 void XGUI_Workshop::openDirectory(const QString& theDirectory)
808 {
809   myCurrentDir = theDirectory;
810   if (myCurrentDir.isEmpty())
811     return;
812
813   QFileInfo aFileInfo(myCurrentDir);
814   if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
815     QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
816     myCurrentDir = "";
817     return;
818   }
819
820   QApplication::setOverrideCursor(Qt::WaitCursor);
821   module()->closeDocument();
822   SessionPtr aSession = ModelAPI_Session::get();
823   aSession->closeAll();
824   aSession->load(myCurrentDir.toLatin1().constData());
825   myObjectBrowser->rebuildDataTree();
826
827   // Open first level of data tree
828   DocumentPtr aRootDoc = aSession->moduleDocument();
829   std::list<bool> aStates;
830   aRootDoc->restoreNodesState(aStates);
831   myObjectBrowser->setStateForDoc(aRootDoc, aStates);
832
833   updateCommandStatus();
834 #ifndef HAVE_SALOME
835   myMainWindow->setCurrentDir(myCurrentDir, true);
836 #endif
837   QApplication::restoreOverrideCursor();
838 }
839
840 //******************************************************
841 void XGUI_Workshop::onNew()
842 {
843   QApplication::setOverrideCursor(Qt::WaitCursor);
844   if (objectBrowser() == 0) {
845     createDockWidgets();
846     mySelector->connectViewers();
847   }
848   myViewerProxy->connectToViewer();
849   showObjectBrowser();
850 #ifndef HAVE_SALOME
851   myMainWindow->showPythonConsole();
852   QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
853   aWnd->showMaximized();
854   updateCommandStatus();
855 #endif
856   myContextMenuMgr->connectViewer();
857   QApplication::restoreOverrideCursor();
858 }
859
860 #ifndef HAVE_SALOME
861 //******************************************************
862 void XGUI_Workshop::onExit()
863 {
864   SessionPtr aMgr = ModelAPI_Session::get();
865   if (aMgr->isModified()) {
866     int anAnswer = QMessageBox::question(
867         myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
868         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
869     if (anAnswer == QMessageBox::Save) {
870       bool saved = onSave();
871       if (!saved) {
872         return;
873       }
874     } else if (anAnswer == QMessageBox::Cancel) {
875       return;
876     }
877   }
878   qApp->exit();
879 }
880
881 //******************************************************
882 void XGUI_Workshop::onPreferences()
883 {
884   ModuleBase_Prefs aModif;
885   ModuleBase_Preferences::editPreferences(aModif);
886   if (aModif.size() > 0) {
887     QString aSection;
888     foreach (ModuleBase_Pref aPref, aModif)
889     {
890       aSection = aPref.first;
891       if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
892         myMainWindow->viewer()->updateFromResources();
893       } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
894         myMainWindow->menuObject()->updateFromResources();
895       }
896     }
897     displayer()->redisplayObjects();
898   }
899 }
900 #endif
901
902 //******************************************************
903 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
904 {
905   XGUI_Displayer* aDisplayer = displayer();
906   if (aDisplayer)
907     aDisplayer->displayTrihedron(theState);
908 }
909
910 //******************************************************
911 bool XGUI_Workshop::onSave()
912 {
913   if(!abortAllOperations())
914     return false;
915   if (myCurrentDir.isEmpty()) {
916     return onSaveAs();
917   }
918   std::list<std::string> aFiles;
919   saveDocument(myCurrentDir, aFiles);
920   updateCommandStatus();
921 #ifndef HAVE_SALOME
922     myMainWindow->setModifiedState(false);
923 #endif
924   return true;
925 }
926
927 //******************************************************
928 bool XGUI_Workshop::onSaveAs()
929 {
930   if(!abortAllOperations())
931     return false;
932   QFileDialog dialog(desktop());
933   dialog.setWindowTitle(tr("Select directory to save files..."));
934   dialog.setFileMode(QFileDialog::Directory);
935   dialog.setFilter(QDir::AllDirs);
936   dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
937   dialog.setViewMode(QFileDialog::Detail);
938
939   if (!dialog.exec()) {
940     return false;
941   }
942
943   QString aTempDir = dialog.selectedFiles().first();
944   QDir aDir(aTempDir);
945   if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
946     int answer = QMessageBox::question(
947         desktop(),
948         // Title of the dialog which asks user if he wants to save study
949         // in existing non-empty folder
950         tr("Save"),
951         tr("The directory already contains some files, save anyway?"),
952         QMessageBox::Save | QMessageBox::Cancel);
953     if (answer == QMessageBox::Cancel) {
954       return false;
955     }
956   }
957   myCurrentDir = aTempDir;
958 #ifndef HAVE_SALOME
959     myMainWindow->setCurrentDir(myCurrentDir, false);
960     myMainWindow->setModifiedState(false);
961 #endif
962   return onSave();
963 }
964
965 //******************************************************
966 void XGUI_Workshop::onUndo(int theTimes)
967 {
968   objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
969   SessionPtr aMgr = ModelAPI_Session::get();
970   std::list<std::string> aUndoList = aMgr->undoList();
971   if (aMgr->isOperation()) {
972     /// this is important for nested operations
973     /// when sketch operation is active, this condition is false and
974     /// the sketch operation is not aborted
975     operationMgr()->onAbortOperation();
976   }
977   std::list<std::string>::const_iterator aIt = aUndoList.cbegin();
978   for (int i = 0; (i < theTimes) && (aIt != aUndoList.cend()); ++i, ++aIt) {
979     aMgr->undo();
980     if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
981       myObjectBrowser->rebuildDataTree();
982   }
983
984   operationMgr()->updateApplyOfOperations();
985   updateCommandStatus();
986 }
987
988 //******************************************************
989 void XGUI_Workshop::onRedo(int theTimes)
990 {
991   // the viewer update should be blocked in order to avoid the features blinking. For the created
992   // feature a results are created, the flush of the created signal caused the viewer redisplay for
993   // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
994   // until redo of all possible objects happens
995   bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
996
997   objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
998   SessionPtr aMgr = ModelAPI_Session::get();
999   std::list<std::string> aRedoList = aMgr->redoList();
1000   if (aMgr->isOperation()) {
1001     /// this is important for nested operations
1002     /// when sketch operation is active, this condition is false and
1003     /// the sketch operation is not aborted
1004     operationMgr()->onAbortOperation();
1005   }
1006   std::list<std::string>::const_iterator aIt = aRedoList.cbegin();
1007   for (int i = 0; (i < theTimes) && (aIt != aRedoList.cend()); ++i, ++aIt) {
1008     aMgr->redo();
1009     if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
1010       myObjectBrowser->rebuildDataTree();
1011   }
1012   operationMgr()->updateApplyOfOperations();
1013   updateCommandStatus();
1014
1015   // unblock the viewer update functionality and make update on purpose
1016   myDisplayer->enableUpdateViewer(isUpdateEnabled);
1017   myDisplayer->updateViewer();
1018 }
1019
1020 //******************************************************
1021 //void XGUI_Workshop::onRebuild()
1022 //{
1023 //  SessionPtr aMgr = ModelAPI_Session::get();
1024 //  bool aWasOperation = aMgr->isOperation(); // keep this value
1025 //  if (!aWasOperation) {
1026 //    aMgr->startOperation("Rebuild");
1027 //  }
1028 //  static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
1029 //  Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
1030 //    new Events_Message(aRebuildEvent, this)));
1031 //  if (!aWasOperation) {
1032 //    aMgr->finishOperation();
1033 //  }
1034 //  updateCommandStatus();
1035 //}
1036
1037 //******************************************************
1038 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
1039 {
1040   ModuleBase_ModelWidget* anActiveWidget = 0;
1041   ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1042   if (anOperation) {
1043     ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1044     if (aPanel)
1045       anActiveWidget = aPanel->activeWidget();
1046   }
1047   if (anActiveWidget)
1048     operationMgr()->onValidateOperation();
1049
1050   myModule->widgetStateChanged(thePreviousState);
1051 }
1052
1053 //******************************************************
1054 void XGUI_Workshop::onValuesChanged()
1055 {
1056   ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
1057   if (!aSenderWidget || aSenderWidget->canAcceptFocus())
1058     return;
1059
1060   ModuleBase_ModelWidget* anActiveWidget = 0;
1061   ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1062   if (anOperation) {
1063     ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1064     if (aPanel)
1065       anActiveWidget = aPanel->activeWidget();
1066   }
1067   if (anActiveWidget) {
1068     ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1069                                                                            (anActiveWidget);
1070     if (aWidgetValidated)
1071       aWidgetValidated->clearValidatedCash();
1072   }
1073 }
1074
1075 void XGUI_Workshop::onWidgetObjectUpdated()
1076 {
1077   operationMgr()->onValidateOperation();
1078 }
1079
1080 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1081 {
1082   QString libName = QString::fromStdString(library(theModule.toStdString()));
1083   if (libName.isEmpty()) {
1084     qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1085     return 0;
1086   }
1087
1088   QString err;
1089   CREATE_FUNC crtInst = 0;
1090
1091 #ifdef WIN32
1092   HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
1093   if (!modLib) {
1094     LPVOID lpMsgBuf;
1095     ::FormatMessage(
1096         FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1097         0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1098     QString aMsg((char*) &lpMsgBuf);
1099     err = QString("Failed to load  %1. %2").arg(libName).arg(aMsg);
1100     ::LocalFree(lpMsgBuf);
1101   } else {
1102     crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1103     if (!crtInst) {
1104       LPVOID lpMsgBuf;
1105       ::FormatMessage(
1106           FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1107               | FORMAT_MESSAGE_IGNORE_INSERTS,
1108           0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1109       QString aMsg((char*) &lpMsgBuf);
1110       err = QString("Failed to find  %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1111       ::LocalFree(lpMsgBuf);
1112     }
1113   }
1114 #else
1115   void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1116   if ( !modLib ) {
1117     err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1118   } else {
1119     crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1120     if ( !crtInst ) {
1121       err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1122     }
1123   }
1124 #endif
1125
1126   ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1127
1128   if (!err.isEmpty()) {
1129     if (desktop()) {
1130       Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1131     } else {
1132       qWarning(qPrintable(err));
1133     }
1134   }
1135   return aModule;
1136 }
1137
1138 //******************************************************
1139 bool XGUI_Workshop::createModule()
1140 {
1141   Config_ModuleReader aModuleReader;
1142   QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1143   myModule = loadModule(moduleName);
1144   if (!myModule)
1145     return false;
1146
1147   //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1148   //  myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1149   //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1150   //  myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1151
1152   myModule->createFeatures();
1153 #ifdef HAVE_SALOME
1154   salomeConnector()->createFeatureActions();
1155 #endif
1156   //myActionsMgr->update();
1157   return true;
1158 }
1159
1160 //******************************************************
1161 void XGUI_Workshop::updateCommandStatus()
1162 {
1163   QList<QAction*> aCommands;
1164 #ifdef HAVE_SALOME
1165     aCommands = salomeConnector()->commandList();
1166 #else
1167     AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1168     foreach (AppElements_Command* aCmd, aMenuBar->features())
1169       aCommands.append(aCmd);
1170 #endif
1171   SessionPtr aMgr = ModelAPI_Session::get();
1172   if (aMgr->hasModuleDocument()) {
1173     foreach(QAction* aCmd, aCommands) {
1174       QString aId = aCmd->data().toString();
1175       if (aId == "UNDO_CMD")
1176         aCmd->setEnabled(myModule->canUndo());
1177       else if (aId == "REDO_CMD")
1178         aCmd->setEnabled(myModule->canRedo());
1179       else
1180         // Enable all commands
1181         aCmd->setEnabled(true);
1182     }
1183     updateHistory();
1184   } else {
1185     foreach(QAction* aCmd, aCommands) {
1186       QString aId = aCmd->data().toString();
1187       if (aId == "NEW_CMD")
1188         aCmd->setEnabled(true);
1189       else if (aId == "EXIT_CMD")
1190         aCmd->setEnabled(true);
1191       else
1192         aCmd->setEnabled(false);
1193     }
1194   }
1195   myActionsMgr->updateCommandsStatus();
1196   emit commandStatusUpdated();
1197 }
1198
1199 void XGUI_Workshop::updateHistory()
1200 {
1201   std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1202   QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1203   emit updateUndoHistory(aUndoRes);
1204
1205   std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1206   QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1207   emit updateRedoHistory(aRedoRes);
1208 }
1209
1210 //******************************************************
1211 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1212 {
1213   QDockWidget* aObjDock = new QDockWidget(theParent);
1214   aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
1215                             Qt::RightDockWidgetArea |
1216                             Qt::BottomDockWidgetArea);
1217   aObjDock->setWindowTitle(tr("Object browser"));
1218   aObjDock->setStyleSheet(
1219       "::title { position: relative; padding-left: 5px; text-align: left center }");
1220   myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1221   myObjectBrowser->setXMLReader(myDataModelXMLReader);
1222   myModule->customizeObjectBrowser(myObjectBrowser);
1223   aObjDock->setWidget(myObjectBrowser);
1224
1225   myContextMenuMgr->connectObjectBrowser();
1226   return aObjDock;
1227 }
1228
1229 //******************************************************
1230 /*
1231  * Creates dock widgets, places them in corresponding area
1232  * and tabifies if necessary.
1233  */
1234 void XGUI_Workshop::createDockWidgets()
1235 {
1236   QMainWindow* aDesktop = desktop();
1237   QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1238   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1239   myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1240   myPropertyPanel->setupActions(myActionsMgr);
1241   myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1242                                    Qt::RightDockWidgetArea |
1243                                    Qt::BottomDockWidgetArea);
1244   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1245   hidePropertyPanel();  ///<! Invisible by default
1246   hideObjectBrowser();
1247   aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1248   myPropertyPanel->installEventFilter(myOperationMgr);
1249
1250   QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1251   connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1252
1253   QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1254   connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1255
1256   QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1257   connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1258
1259   connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1260           myOperationMgr,  SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1261   connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1262           myOperationMgr,  SLOT(onProcessEnter(QObject*)));
1263 }
1264
1265 //******************************************************
1266 void XGUI_Workshop::showPropertyPanel()
1267 {
1268   QAction* aViewAct = myPropertyPanel->toggleViewAction();
1269   ///<! Restore ability to close panel from the window's menu
1270   aViewAct->setEnabled(true);
1271   myPropertyPanel->show();
1272   myPropertyPanel->raise();
1273
1274   // The next code is necessary to made the property panel the active window
1275   // in order to operation manager could process key events of the panel.
1276   // otherwise they are ignored. It happens only if the same(activateWindow) is
1277   // not happened by property panel activation(e.g. resume operation of Sketch)
1278   ModuleBase_Tools::activateWindow(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1279   ModuleBase_Tools::setFocus(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1280 }
1281
1282 //******************************************************
1283 void XGUI_Workshop::hidePropertyPanel()
1284 {
1285   QAction* aViewAct = myPropertyPanel->toggleViewAction();
1286   ///<! Do not allow to show empty property panel
1287   aViewAct->setEnabled(false);
1288   myPropertyPanel->hide();
1289
1290   // the property panel is active window of the desktop, when it is
1291   // hidden, it is undefined which window becomes active. By this reason
1292   // it is defined to perform the desktop as the active window.
1293   // in SALOME mode, workstack made the PyConsole the active window,
1294   // set the focus on it. As a result, shortcuts of the application, like
1295   // are processed by this console. For example Undo actions.
1296   // It is possible that this code is to be moved to SHAPER package
1297   QMainWindow* aDesktop = desktop();
1298   ModuleBase_Tools::activateWindow(aDesktop, "XGUI_Workshop::hidePropertyPanel()");
1299   ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::showPropertyPanel()");
1300 }
1301
1302 //******************************************************
1303 void XGUI_Workshop::showObjectBrowser()
1304 {
1305   if (!isSalomeMode())
1306     myObjectBrowser->parentWidget()->show();
1307 }
1308
1309 //******************************************************
1310 void XGUI_Workshop::hideObjectBrowser()
1311 {
1312   if (!isSalomeMode())
1313     myObjectBrowser->parentWidget()->hide();
1314 }
1315
1316 //******************************************************
1317 void XGUI_Workshop::salomeViewerSelectionChanged()
1318 {
1319   emit salomeViewerSelection();
1320 }
1321
1322 //**************************************************************
1323 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1324 {
1325   return mySalomeConnector->viewer();
1326 }
1327
1328 //**************************************************************
1329 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1330 {
1331   QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1332   if (theId == "DELETE_CMD")
1333     deleteObjects();
1334   else if (theId == "CLEAN_HISTORY_CMD")
1335     cleanHistory();
1336   else if (theId == "MOVE_CMD")
1337     moveObjects();
1338   else if (theId == "COLOR_CMD")
1339     changeColor(aObjects);
1340   else if (theId == "DEFLECTION_CMD")
1341     changeDeflection(aObjects);
1342   else if (theId == "SHOW_CMD") {
1343     showObjects(aObjects, true);
1344     mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1345     updateCommandStatus();
1346   }
1347   else if (theId == "HIDE_CMD") {
1348     showObjects(aObjects, false);
1349     updateCommandStatus();
1350   }
1351   else if (theId == "SHOW_ONLY_CMD") {
1352     showOnlyObjects(aObjects);
1353     mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1354     updateCommandStatus();
1355   }
1356   else if (theId == "SHADING_CMD")
1357     setDisplayMode(aObjects, XGUI_Displayer::Shading);
1358   else if (theId == "WIREFRAME_CMD")
1359     setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1360   else if (theId == "HIDEALL_CMD") {
1361     QObjectPtrList aList = myDisplayer->displayedObjects();
1362     foreach (ObjectPtr aObj, aList) {
1363       if (module()->canEraseObject(aObj))
1364         aObj->setDisplayed(false);
1365     }
1366     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1367 #ifdef HAVE_SALOME
1368     //issue #2159 Hide all incomplete behavior
1369     viewer()->eraseAll();
1370 #endif
1371     updateCommandStatus();
1372   } else if (theId == "SELECT_VERTEX_CMD") {
1373     setViewerSelectionMode(TopAbs_VERTEX);
1374   } else if (theId == "SELECT_EDGE_CMD") {
1375     setViewerSelectionMode(TopAbs_EDGE);
1376   } else if (theId == "SELECT_FACE_CMD") {
1377     setViewerSelectionMode(TopAbs_FACE);
1378   } else if (theId == "SELECT_RESULT_CMD") {
1379     //setViewerSelectionMode(-1);
1380     //IMP: an attempt to use result selection with other selection modes
1381     setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1382     setViewerSelectionMode(TopAbs_COMPSOLID);
1383   } else if (theId == "SHOW_RESULTS_CMD") {
1384     highlightResults(aObjects);
1385   } else if (theId == "SHOW_FEATURE_CMD") {
1386     highlightFeature(aObjects);
1387   }
1388 #ifdef TINSPECTOR
1389   else if (theId == "TINSPECTOR_VIEW") {
1390     Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication();
1391     if (!anApplication.IsNull())
1392     {
1393       if (!MyTCommunicator)
1394       {
1395         MyTCommunicator = new TInspector_Communicator();
1396
1397         NCollection_List<Handle(Standard_Transient)> aParameters;
1398         aParameters.Append(anApplication);
1399         Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1400         if (!aContext.IsNull())
1401           aParameters.Append(aContext);
1402
1403         MyVCallBack = new VInspector_CallBack();
1404         myDisplayer->setCallBack(MyVCallBack);
1405         #ifndef HAVE_SALOME
1406         AppElements_Viewer* aViewer = mainWindow()->viewer();
1407         if (aViewer)
1408           aViewer->setCallBack(MyVCallBack);
1409         #endif
1410         aParameters.Append(MyVCallBack);
1411
1412         MyTCommunicator->registerPlugin("SMBrowser"); // custom plugin to view ModelAPI
1413
1414         MyTCommunicator->init(aParameters);
1415         MyTCommunicator->Activate("SMBrowser"); // to have button in TInspector
1416         MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1417         MyTCommunicator->Activate("TKDFBrowser");
1418       }
1419       MyTCommunicator->setVisible(true);
1420     }
1421   }
1422 #endif
1423 }
1424
1425 //**************************************************************
1426 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1427 {
1428   if (theMode == -1)
1429     myViewerSelMode.clear();
1430   else {
1431     if (myViewerSelMode.contains(theMode))
1432       myViewerSelMode.removeAll(theMode);
1433     else
1434       myViewerSelMode.append(theMode);
1435   }
1436   activateObjectsSelection(myDisplayer->displayedObjects());
1437 }
1438
1439 //**************************************************************
1440 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1441 {
1442   QIntList aModes;
1443   module()->activeSelectionModes(aModes);
1444   if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1445     aModes.append(myViewerSelMode);
1446   myDisplayer->activateObjects(aModes, theList);
1447 }
1448
1449 //**************************************************************
1450 void XGUI_Workshop::deleteObjects()
1451 {
1452   ModuleBase_IModule* aModule = module();
1453   // allow the module to delete objects, do nothing if it has succeed
1454   if (aModule->deleteObjects()) {
1455     updateCommandStatus();
1456     return;
1457   }
1458
1459   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1460   if (!abortAllOperations())
1461     return;
1462
1463   bool hasResult = false;
1464   bool hasFeature = false;
1465   bool hasParameter = false;
1466   bool hasCompositeOwner = false;
1467   bool hasResultInHistory = false;
1468   ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
1469                                  hasResultInHistory);
1470   if (!(hasFeature || hasParameter))
1471     return;
1472
1473   // delete objects
1474   std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1475   std::set<FeaturePtr> aFeatures;
1476   ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1477   ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1478
1479   bool aDone = false;
1480   QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1481   aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1482   ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1483
1484   operationMgr()->startOperation(anOpAction);
1485
1486   std::set<FeaturePtr> aFeatureRefsToDelete;
1487   if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1488     // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1489     // It is necessary to clear selection in order to avoid selection changed event during
1490     // deletion and negative consequences connected with processing of already deleted items
1491     mySelector->clearSelection();
1492
1493     if (!aFeatureRefsToDelete.empty())
1494       aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1495     aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1496   }
1497   if (aDone)
1498     operationMgr()->commitOperation();
1499   else
1500     operationMgr()->abortOperation(operationMgr()->currentOperation());
1501 }
1502
1503 //**************************************************************
1504 void addRefsToFeature(const FeaturePtr& theFeature,
1505                       const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1506                       std::set<FeaturePtr>& theReferences)
1507 {
1508   //if (theReferences.find(theFeature) != theReferences.end())
1509   //  return;
1510   if (theMainList.find(theFeature) == theMainList.end())
1511     return; // this feature is not in the selection list, so exists without references to it
1512   std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1513
1514   std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1515                                        aLast = aMainReferences.end();
1516   for (; anIt != aLast; anIt++) {
1517     FeaturePtr aRefFeature = *anIt;
1518     if (theReferences.find(aRefFeature) == theReferences.end())
1519       theReferences.insert(aRefFeature);
1520     addRefsToFeature(aRefFeature, theMainList, theReferences);
1521   }
1522 }
1523
1524 //**************************************************************
1525 void XGUI_Workshop::cleanHistory()
1526 {
1527   if (!abortAllOperations())
1528     return;
1529
1530   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1531   std::set<FeaturePtr> aFeatures;
1532   ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1533
1534 #ifdef DEBUG_CLEAN_HISTORY
1535   QStringList anInfo;
1536   std::set<FeaturePtr>::const_iterator aFIt;
1537   for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1538     FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1539     anInfo.append(aFeature->name().c_str());
1540   }
1541   QString anInfoStr = anInfo.join(";\t");
1542   qDebug(QString("cleanHistory for: [%1] - %2").
1543     arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1544 #endif
1545
1546   std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1547   ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1548   // find for each object whether all reference values are in the map as key, that means that there
1549   // is no other reference in the model to this object, so it might be removed by cleaning history
1550   // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1
1551   // ext_1(bool_1, sk_3)  - cann't be deleted, dependency to bool_1
1552   // vertex_1()
1553   // sk_2(ext_2) + (bool_1)  - cann't be deleted, dependency to bool_1
1554   // ext_2(bool_1)  - cann't be deleted, dependency to bool_1
1555   // sk_3()
1556   // Information: bool_1 is not selected
1557   std::set<FeaturePtr> anUnusedObjects;
1558   std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1559                                                               aMainLast = aReferences.end();
1560   for (; aMainIt != aMainLast; aMainIt++) {
1561     FeaturePtr aMainListFeature = aMainIt->first;
1562     std::set<FeaturePtr> aMainRefList = aMainIt->second;
1563     std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
1564                                                   aRefLast = aMainRefList.end();
1565     bool aFeatureOutOfTheList = false;
1566     for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1567       FeaturePtr aRefFeature = *aRefIt;
1568       aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1569     }
1570     if (!aFeatureOutOfTheList)
1571       anUnusedObjects.insert(aMainListFeature);
1572   }
1573
1574 #ifdef DEBUG_CLEAN_HISTORY
1575   anInfo.clear();
1576   for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1577     FeaturePtr aFeature = *aFIt;
1578     anInfo.append(aFeature->name().c_str());
1579   }
1580   qDebug(QString("unused objects: [%1] - %2").
1581     arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1582 #endif
1583
1584   // warn about the references remove, break the delete operation if the user chose it
1585   if (!anUnusedObjects.empty()) {
1586     QStringList aNames;
1587     foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1588       aNames.append(aFeature->name().c_str());
1589     }
1590     aNames.sort();
1591     QString anUnusedNames = aNames.join(", ");
1592
1593     QString anActionId = "CLEAN_HISTORY_CMD";
1594     QString aDescription = contextMenuMgr()->action(anActionId)->text();
1595
1596     QMessageBox aMessageBox(desktop());
1597     aMessageBox.setWindowTitle(aDescription);
1598     aMessageBox.setIcon(QMessageBox::Warning);
1599     aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1600     aMessageBox.setDefaultButton(QMessageBox::No);
1601
1602     const char* aKeyStr = "Unused features are the following: "
1603                           "%1.\nThese features will be deleted.\nWould you like to continue?";
1604     QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
1605     aMessageBox.setText(aText);
1606     if (aMessageBox.exec() == QMessageBox::No)
1607       return;
1608
1609     // 1. start operation
1610     aDescription += "by deleting of " +
1611       aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1612     ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1613     operationMgr()->startOperation(anOpAction);
1614
1615     // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1616     // It is necessary to clear selection in order to avoid selection changed event during
1617     // deletion and negative consequences connected with processing of already deleted items
1618     mySelector->clearSelection();
1619
1620     std::set<FeaturePtr> anIgnoredFeatures;
1621     if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
1622       operationMgr()->commitOperation();
1623     }
1624     else {
1625       operationMgr()->abortOperation(operationMgr()->currentOperation());
1626     }
1627   }
1628   else {
1629     QString anActionId = "CLEAN_HISTORY_CMD";
1630     QString aDescription = contextMenuMgr()->action(anActionId)->text();
1631
1632     QMessageBox aMessageBox(desktop());
1633     aMessageBox.setWindowTitle(aDescription);
1634     aMessageBox.setIcon(QMessageBox::Warning);
1635     aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1636     aMessageBox.setDefaultButton(QMessageBox::No);
1637
1638     QString aText;
1639     aMessageBox.setStandardButtons(QMessageBox::Ok);
1640     aMessageBox.setDefaultButton(QMessageBox::Ok);
1641
1642     aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1643     aMessageBox.setText(aText);
1644
1645     if (aMessageBox.exec() == QMessageBox::No)
1646       return;
1647   }
1648 }
1649
1650 //**************************************************************
1651 void XGUI_Workshop::moveObjects()
1652 {
1653   if (!abortAllOperations())
1654     return;
1655
1656   SessionPtr aMgr = ModelAPI_Session::get();
1657
1658   QString anActionId = "MOVE_CMD";
1659   QString aDescription = contextMenuMgr()->action(anActionId)->text();
1660   aMgr->startOperation(aDescription.toStdString());
1661
1662   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1663   // It is necessary to clear selection in order to avoid selection changed event during
1664   // moving and negative consequences connected with processing of already moved items
1665   mySelector->clearSelection();
1666   // check whether the object can be moved. There should not be parts which are not loaded
1667   std::set<FeaturePtr> aFeatures;
1668   ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1669   if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
1670     return;
1671
1672   DocumentPtr anActiveDocument = aMgr->activeDocument();
1673   FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1674   std::set<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
1675   for (; anIt != aLast; anIt++) {
1676     FeaturePtr aFeature = *anIt;
1677     if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
1678       continue;
1679
1680     anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1681     aCurrentFeature = anActiveDocument->currentFeature(true);
1682   }
1683   aMgr->finishOperation();
1684 }
1685
1686 //**************************************************************
1687 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
1688 {
1689   std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1690   std::set<FeaturePtr> aFeatures;
1691   ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
1692
1693   return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
1694 }
1695
1696 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1697 {
1698   bool isFoundResultType = false;
1699   foreach(ObjectPtr anObj, theObjects)
1700   {
1701     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1702     if (aResult.get() == NULL)
1703       continue;
1704
1705     isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1706     if (isFoundResultType)
1707       break;
1708   }
1709   return isFoundResultType;
1710 }
1711
1712 //**************************************************************
1713 // Returns the list of all features for theDocument and all features of
1714 // all nested parts.
1715 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
1716 {
1717   std::list<FeaturePtr> aResultList;
1718   std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
1719   foreach (const FeaturePtr& aFeature, anAllFeatures) {
1720     // The order of appending features of the part and the part itself is important
1721
1722     // Append features from a part feature
1723     std::list<ResultPtr> aResults;
1724     ModelAPI_Tools::allResults(aFeature, aResults);
1725     foreach (const ResultPtr& aResult, aResults) {
1726       ResultPartPtr aResultPart =
1727           std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
1728       if (aResultPart.get() && aResultPart->partDoc().get()) {
1729         // Recursion
1730         std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
1731         aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
1732       }
1733     }
1734
1735     aResultList.push_back(aFeature);
1736   }
1737   return aResultList;
1738 }
1739
1740 //**************************************************************
1741 // Returns the list of features placed between theObject and the current feature
1742 // in the same document. Excludes theObject, includes the current feature.
1743 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1744 {
1745   std::list<FeaturePtr> aResult;
1746   DocumentPtr aDocument = theObject->document();
1747   std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
1748   // find the object iterator
1749   std::list<FeaturePtr>::iterator aObjectIt =
1750     std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1751   if (aObjectIt == anAllFeatures.end())
1752     return aResult;
1753   // find the current feature iterator
1754   std::list<FeaturePtr>::iterator aCurrentIt =
1755     std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
1756   if (aCurrentIt == anAllFeatures.end())
1757     return aResult;
1758   // check the right order
1759   if (std::distance(aObjectIt, anAllFeatures.end()) <=
1760       std::distance(aCurrentIt, anAllFeatures.end()))
1761     return aResult;
1762   // exclude the object
1763   std::advance(aObjectIt, 1);
1764   // include the current feature
1765   std::advance(aCurrentIt, 1);
1766   return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
1767 }
1768
1769 bool XGUI_Workshop::canMoveFeature()
1770 {
1771   QString anActionId = "MOVE_CMD";
1772
1773   QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1774   QObjectPtrList aValidatedObjects;
1775   foreach (ObjectPtr aObject, aObjects) {
1776     if (!myModule->canApplyAction(aObject, anActionId))
1777       continue;
1778     // To be moved feature should be in active document
1779     if (aObject->document() != ModelAPI_Session::get()->activeDocument())
1780       continue;
1781     aValidatedObjects.append(aObject);
1782   }
1783   if (aValidatedObjects.size() != aObjects.size())
1784     aObjects = aValidatedObjects;
1785
1786   bool aCanMove = !aObjects.empty();
1787
1788   QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
1789   for (; anIt != aLast && aCanMove; anIt++) {
1790     ObjectPtr aObject = *anIt;
1791     // 1. Get features placed between selected and current in the document
1792     std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
1793     // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
1794     if (aFeaturesBetween.empty())
1795       aCanMove = false;
1796     else {
1797       std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
1798       // 2. Get all reference features to the selected object in the document
1799       std::set<FeaturePtr> aRefFeatures;
1800       ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
1801
1802       if (aRefFeatures.empty())
1803         continue;
1804       else {
1805         // 3. Find any placed features in all reference features
1806         std::set<FeaturePtr> aIntersectionFeatures;
1807         std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
1808                               aPlacedFeatures.begin(), aPlacedFeatures.end(),
1809                               std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
1810         // 4. Return false if any reference feature is placed before current feature
1811         if (!aIntersectionFeatures.empty())
1812           aCanMove = false;
1813       }
1814     }
1815   }
1816   return aCanMove;
1817 }
1818
1819 //**************************************************************
1820 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
1821 {
1822   bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
1823   if (!aCanBeShaded) {
1824     ResultCompSolidPtr aCompsolidResult =
1825                 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
1826     if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1827       for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
1828         aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
1829     }
1830   }
1831   return aCanBeShaded;
1832 }
1833
1834 //**************************************************************
1835 bool XGUI_Workshop::canChangeColor() const
1836 {
1837   QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1838
1839   std::set<std::string> aTypes;
1840   aTypes.insert(ModelAPI_ResultGroup::group());
1841   aTypes.insert(ModelAPI_ResultConstruction::group());
1842   aTypes.insert(ModelAPI_ResultBody::group());
1843   aTypes.insert(ModelAPI_ResultPart::group());
1844
1845   return hasResults(aObjects, aTypes);
1846 }
1847
1848 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
1849 {
1850   if (!theResult.get())
1851     return;
1852
1853   AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1854   if (aColorAttr.get() != NULL) {
1855     if (!aColorAttr->size()) {
1856       aColorAttr->setSize(3);
1857     }
1858     aColorAttr->setValue(0, theColor[0]);
1859     aColorAttr->setValue(1, theColor[1]);
1860     aColorAttr->setValue(2, theColor[2]);
1861   }
1862 }
1863
1864 //**************************************************************
1865 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1866 {
1867
1868   AttributeIntArrayPtr aColorAttr;
1869   // 1. find the current color of the object. This is a color of AIS presentation
1870   // The objects are iterated until a first valid color is found
1871   std::vector<int> aColor;
1872   foreach(ObjectPtr anObject, theObjects) {
1873     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1874     if (aResult.get()) {
1875       XGUI_CustomPrs::getResultColor(aResult, aColor);
1876     }
1877     else {
1878       // TODO: remove the obtaining a color from the AIS object
1879       // this does not happen never because:
1880       // 1. The color can be changed only on results
1881       // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1882       AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1883       if (anAISObj.get()) {
1884         aColor.resize(3);
1885         anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1886       }
1887     }
1888     if (!aColor.empty())
1889       break;
1890   }
1891   if (aColor.size() != 3)
1892     return;
1893
1894   if (!abortAllOperations())
1895   return;
1896   // 2. show the dialog to change the value
1897   XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
1898   aDlg->setColor(aColor);
1899   aDlg->move(QCursor::pos());
1900   bool isDone = aDlg->exec() == QDialog::Accepted;
1901   if (!isDone)
1902     return;
1903
1904   bool isRandomColor = aDlg->isRandomColor();
1905
1906   // 3. abort the previous operation and start a new one
1907   SessionPtr aMgr = ModelAPI_Session::get();
1908   QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
1909   aMgr->startOperation(aDescription.toStdString());
1910
1911   // 4. set the value to all results
1912   std::vector<int> aColorResult = aDlg->getColor();
1913   foreach(ObjectPtr anObj, theObjects) {
1914     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1915     if (aResult.get() != NULL) {
1916       ResultCompSolidPtr aCompsolidResult =
1917         std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1918       if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1919         for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1920           setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult :
1921                                                                     aDlg->getRandomColor());
1922         }
1923       }
1924       setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
1925     }
1926   }
1927   aMgr->finishOperation();
1928   updateCommandStatus();
1929 }
1930
1931 //**************************************************************
1932 bool XGUI_Workshop::canChangeDeflection() const
1933 {
1934   QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1935
1936   std::set<std::string> aTypes;
1937   aTypes.insert(ModelAPI_ResultGroup::group());
1938   aTypes.insert(ModelAPI_ResultConstruction::group());
1939   aTypes.insert(ModelAPI_ResultBody::group());
1940   aTypes.insert(ModelAPI_ResultPart::group());
1941
1942   return hasResults(aObjects, aTypes);
1943 }
1944
1945 void setDeflection(ResultPtr theResult, const double theDeflection)
1946 {
1947   if (!theResult.get())
1948     return;
1949
1950   AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
1951   if (aDeflectionAttr.get() != NULL)
1952     aDeflectionAttr->setValue(theDeflection);
1953 }
1954
1955
1956 //**************************************************************
1957 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
1958 {
1959   AttributeDoublePtr aDoubleAttr;
1960   // 1. find the current color of the object. This is a color of AIS presentation
1961   // The objects are iterated until a first valid color is found
1962   double aDeflection = -1;
1963   foreach(ObjectPtr anObject, theObjects) {
1964     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1965     if (aResult.get()) {
1966       aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
1967     }
1968     else {
1969       // TODO: remove the obtaining a color from the AIS object
1970       // this does not happen never because:
1971       // 1. The color can be changed only on results
1972       // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1973       AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1974       if (anAISObj.get()) {
1975         aDeflection = anAISObj->getDeflection();
1976       }
1977     }
1978     if (aDeflection > 0)
1979       break;
1980   }
1981   if (aDeflection < 0)
1982     return;
1983
1984   if (!abortAllOperations())
1985   return;
1986   // 2. show the dialog to change the value
1987   XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
1988   aDlg->setDeflection(aDeflection);
1989   aDlg->move(QCursor::pos());
1990   bool isDone = aDlg->exec() == QDialog::Accepted;
1991   if (!isDone)
1992     return;
1993
1994   // 3. abort the previous operation and start a new one
1995   SessionPtr aMgr = ModelAPI_Session::get();
1996   QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
1997   aMgr->startOperation(aDescription.toStdString());
1998
1999   // 4. set the value to all results
2000   aDeflection = aDlg->getDeflection();
2001   foreach(ObjectPtr anObj, theObjects) {
2002     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2003     if (aResult.get() != NULL) {
2004       ResultCompSolidPtr aCompsolidResult =
2005         std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2006       if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2007         for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2008           setDeflection(aCompsolidResult->subResult(i), aDeflection);
2009         }
2010       }
2011       setDeflection(aResult, aDeflection);
2012     }
2013   }
2014   aMgr->finishOperation();
2015   updateCommandStatus();
2016 }
2017
2018 //**************************************************************
2019 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
2020 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
2021   aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
2022 }
2023 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
2024 {
2025   foreach (ObjectPtr aObj, theList) {
2026     aObj->setDisplayed(isVisible);
2027   }
2028   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2029 }
2030
2031 //**************************************************************
2032 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2033 {
2034   // Hide all displayed objects
2035   QObjectPtrList aList = myDisplayer->displayedObjects();
2036   foreach (ObjectPtr aObj, aList) {
2037     if (module()->canEraseObject(aObj))
2038       aObj->setDisplayed(false);
2039   }
2040   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2041 #ifdef HAVE_SALOME
2042     //issue #2159 Hide all incomplete behavior
2043     viewer()->eraseAll();
2044 #endif
2045
2046   // Show only objects from the list
2047   foreach (ObjectPtr aObj, theList) {
2048     aObj->setDisplayed(true);
2049   }
2050   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2051 }
2052
2053
2054 //**************************************************************
2055 void XGUI_Workshop::registerValidators() const
2056 {
2057   SessionPtr aMgr = ModelAPI_Session::get();
2058   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2059 }
2060
2061 //**************************************************************
2062 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2063 {
2064   if (!theDoc)
2065     return;
2066   displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2067   displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2068 }
2069
2070 //**************************************************************
2071 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2072 {
2073   for (int i = 0; i < theDoc->size(theGroup); i++)
2074     theDoc->object(theGroup, i)->setDisplayed(true);
2075     //displayObject(theDoc->object(theGroup, i));
2076   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2077 }
2078
2079 //**************************************************************
2080 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2081 {
2082   foreach(ObjectPtr aObj, theList) {
2083     myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
2084
2085     ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
2086     if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2087       for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2088           myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
2089                                       (XGUI_Displayer::DisplayMode)theMode, false);
2090       }
2091     }
2092   }
2093   if (theList.size() > 0)
2094     myDisplayer->updateViewer();
2095 }
2096
2097 //**************************************************************
2098 void XGUI_Workshop::closeDocument()
2099 {
2100   ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2101   while (anOperation) {
2102     anOperation->abort();
2103     anOperation = operationMgr()->currentOperation();
2104   }
2105   //myDisplayer->closeLocalContexts();
2106   myDisplayer->eraseAll();
2107   objectBrowser()->clearContent();
2108
2109   module()->closeDocument();
2110
2111   // data model need not process the document's signals about objects modifications as
2112   // the document is closed
2113   //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2114
2115   SessionPtr aMgr = ModelAPI_Session::get();
2116   aMgr->closeAll();
2117
2118   //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2119 }
2120
2121 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2122 {
2123   XGUI_HistoryMenu* aMenu = NULL;
2124   if (isSalomeMode()) {
2125     QAction* anAction = qobject_cast<QAction*>(theObject);
2126     if (!anAction)
2127       return;
2128     aMenu = new XGUI_HistoryMenu(anAction);
2129   } else {
2130     QToolButton* aButton =  qobject_cast<QToolButton*>(theObject);
2131     aMenu = new XGUI_HistoryMenu(aButton);
2132   }
2133   connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2134   connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2135 }
2136
2137 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
2138 {
2139   QList<ActionInfo> aResult;
2140   std::list<std::string>::const_iterator it = theList.cbegin();
2141   for (; it != theList.cend(); it++) {
2142     QString anId = QString::fromStdString(*it);
2143     bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2144     if (isEditing) {
2145       anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2146     }
2147     ActionInfo anInfo;
2148     QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2149     if (aContextMenuAct) {
2150       anInfo.initFrom(aContextMenuAct);
2151     } else {
2152       anInfo = myActionsMgr->actionInfoById(anId);
2153     }
2154     if (isEditing) {
2155       anInfo.text = anInfo.text.prepend("Modify ");
2156     }
2157     aResult << anInfo;
2158   }
2159   return aResult;
2160 }
2161
2162 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2163 {
2164 #ifdef HAVE_SALOME
2165   salomeConnector()->putInfo(theMessage, -1);
2166 #else
2167   myMainWindow->putInfo(theMessage, -1);
2168 #endif
2169 }
2170
2171 void XGUI_Workshop::synchronizeViewer()
2172 {
2173   SessionPtr aMgr = ModelAPI_Session::get();
2174   QList<DocumentPtr> aDocs;
2175   aDocs.append(aMgr->activeDocument());
2176   aDocs.append(aMgr->moduleDocument());
2177
2178   foreach(DocumentPtr aDoc, aDocs) {
2179     synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
2180     synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
2181     synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
2182     synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
2183   }
2184 }
2185
2186 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2187                                              const std::string& theGroup,
2188                                              bool theUpdateViewer)
2189 {
2190   ObjectPtr aObj;
2191   int aSize = theDoc->size(theGroup);
2192   for (int i = 0; i < aSize; i++) {
2193     aObj = theDoc->object(theGroup, i);
2194     if (aObj->isDisplayed()) {
2195       // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2196       // be changed to the object becomes visible when the shape becomes not empty
2197       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2198       if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
2199         continue;
2200       myDisplayer->display(aObj, false);
2201     }
2202   }
2203   if (theUpdateViewer)
2204     myDisplayer->updateViewer();
2205 }
2206
2207 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2208 {
2209   FeaturePtr aFeature;
2210   QObjectPtrList aSelList = theObjects;
2211   bool aHasHidden = false;
2212   foreach(ObjectPtr aObj, theObjects) {
2213     aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2214     if (aFeature.get()) {
2215       std::list<ResultPtr> aResults;
2216       ModelAPI_Tools::allResults(aFeature, aResults);
2217       std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2218       for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2219         aHasHidden |= (*aIt)->isConcealed();
2220         aSelList.append(*aIt);
2221       }
2222     }
2223   }
2224   if (aSelList.count() > theObjects.count()) {
2225     // if something was found
2226     bool aBlocked = objectBrowser()->blockSignals(true);
2227     objectBrowser()->setObjectsSelected(aSelList);
2228     objectBrowser()->blockSignals(aBlocked);
2229   }
2230   if (aHasHidden)
2231     QMessageBox::information(desktop(), tr("Find results"),
2232                              tr("Results not found"), QMessageBox::Ok);
2233 }
2234
2235 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2236 {
2237   ResultPtr aResult;
2238   QObjectPtrList aSelList = theObjects;
2239   FeaturePtr aFeature;
2240   foreach(ObjectPtr aObj, theObjects) {
2241     aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2242     if (aResult.get()) {
2243       aFeature = ModelAPI_Feature::feature(aResult);
2244       if (aFeature.get()) {
2245         aSelList.append(aFeature);
2246       }
2247     }
2248   }
2249   if (aSelList.count() > theObjects.count()) {
2250     // if something was found
2251     bool aBlocked = objectBrowser()->blockSignals(true);
2252     objectBrowser()->setObjectsSelected(aSelList);
2253     objectBrowser()->blockSignals(aBlocked);
2254   }
2255 }