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