Salome HOME
84d5f184d547f27e93dd0e7a80a74376cb3eedd5
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
1 #include "ModuleBase_IModule.h"
2 #include "XGUI_Constants.h"
3 #include "XGUI_Command.h"
4 #include "XGUI_MainMenu.h"
5 #include "XGUI_MainWindow.h"
6 #include "XGUI_MenuGroupPanel.h"
7 #include "XGUI_Tools.h"
8 #include "XGUI_Workbench.h"
9 #include "XGUI_Workshop.h"
10 #include "XGUI_Viewer.h"
11 #include "XGUI_SelectionMgr.h"
12 #include "XGUI_Selection.h"
13 #include "XGUI_ObjectsBrowser.h"
14 #include "XGUI_Displayer.h"
15 #include "XGUI_OperationMgr.h"
16 #include "XGUI_SalomeConnector.h"
17 #include "XGUI_SalomeViewer.h"
18 #include "XGUI_ActionsMgr.h"
19 #include "XGUI_ErrorDialog.h"
20 #include "XGUI_ViewerProxy.h"
21 #include "XGUI_PropertyPanel.h"
22 #include "XGUI_ContextMenuMgr.h"
23 #include "XGUI_ModuleConnector.h"
24 #include "XGUI_Preferences.h"
25
26 #include <ModelAPI_Events.h>
27 #include <ModelAPI_Session.h>
28 #include <ModelAPI_Feature.h>
29 #include <ModelAPI_Data.h>
30 #include <ModelAPI_AttributeDocRef.h>
31 #include <ModelAPI_Object.h>
32 #include <ModelAPI_Validator.h>
33 #include <ModelAPI_ResultConstruction.h>
34 #include <ModelAPI_ResultBody.h>
35
36 #include <PartSetPlugin_Part.h>
37
38 #include <Events_Loop.h>
39 #include <Events_Error.h>
40 #include <Events_LongOp.h>
41
42 #include <ModuleBase_Operation.h>
43 #include <ModuleBase_Operation.h>
44 #include <ModuleBase_OperationDescription.h>
45 #include <ModuleBase_SelectionValidator.h>
46 #include "ModuleBase_WidgetFactory.h"
47
48 #include <Config_Common.h>
49 #include <Config_FeatureMessage.h>
50 #include <Config_PointerMessage.h>
51 #include <Config_ModuleReader.h>
52
53 #include <QApplication>
54 #include <QFileDialog>
55 #include <QMessageBox>
56 #include <QMdiSubWindow>
57 #include <QPushButton>
58 #include <QDockWidget>
59 #include <QLayout>
60 #include <QTimer>
61
62 #ifdef _DEBUG
63 #include <QDebug>
64 #endif
65
66 #ifdef WIN32
67 #include <windows.h>
68 #else
69 #include <dlfcn.h>
70 #endif
71
72 QMap<QString, QString> XGUI_Workshop::myIcons;
73
74 QString XGUI_Workshop::featureIcon(const std::string& theId)
75 {
76   QString aId(theId.c_str());
77   if (myIcons.contains(aId))
78     return myIcons[aId];
79   return QString();
80 }
81
82 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
83     : QObject(),
84       myCurrentDir(QString()),
85       myModule(NULL),
86       mySalomeConnector(theConnector),
87       myPropertyPanel(0),
88       myObjectBrowser(0),
89       myDisplayer(0),
90       myUpdatePrefs(false)
91 {
92   myMainWindow = mySalomeConnector ? 0 : new XGUI_MainWindow();
93
94   myDisplayer = new XGUI_Displayer(this);
95
96   mySelector = new XGUI_SelectionMgr(this);
97   //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
98
99   myOperationMgr = new XGUI_OperationMgr(this);
100   myActionsMgr = new XGUI_ActionsMgr(this);
101   myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
102   myContextMenuMgr = new XGUI_ContextMenuMgr(this);
103   connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
104           SLOT(onContextMenuCommand(const QString&, bool)));
105
106   myViewerProxy = new XGUI_ViewerProxy(this);
107   connect(myViewerProxy, SIGNAL(selectionChanged()), this, SLOT(updateCommandsOnViewSelection()));
108
109   myModuleConnector = new XGUI_ModuleConnector(this);
110
111   connect(myOperationMgr, SIGNAL(operationStarted()), SLOT(onOperationStarted()));
112   connect(myOperationMgr, SIGNAL(operationResumed()), SLOT(onOperationStarted()));
113   connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
114           SLOT(onOperationStopped(ModuleBase_Operation*)));
115   connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
116   connect(myOperationMgr, SIGNAL(operationStarted()), myActionsMgr, SLOT(update()));
117   connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), myActionsMgr,
118           SLOT(update()));
119   connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
120 }
121
122 //******************************************************
123 XGUI_Workshop::~XGUI_Workshop(void)
124 {
125 }
126
127 //******************************************************
128 void XGUI_Workshop::startApplication()
129 {
130   initMenu();
131   //Initialize event listening
132   Events_Loop* aLoop = Events_Loop::loop();
133   aLoop->registerListener(this, Events_Error::errorID());  //!< Listening application errors.
134   //TODO(sbh): Implement static method to extract event id [SEID]
135   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_LOADED));
136   // TODO Is it good to use non standard event within workshop?
137   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
138   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
139   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
140   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
141   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
142   aLoop->registerListener(this, Events_Loop::eventByName("LongOperation"));
143   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
144
145   registerValidators();
146   activateModule();
147   if (myMainWindow) {
148     myMainWindow->show();
149     updateCommandStatus();
150   }
151   XGUI_Preferences::loadCustomProps();
152   onNew();
153 }
154
155 //******************************************************
156 void XGUI_Workshop::initMenu()
157 {
158   myContextMenuMgr->createActions();
159
160   if (isSalomeMode()) {
161     // Create only Undo, Redo commands
162     QAction* aAction = salomeConnector()->addEditCommand("UNDO_CMD", tr("Undo"),
163                                                          tr("Undo last command"),
164                                                          QIcon(":pictures/undo.png"),
165                                                          QKeySequence::Undo, false);
166     connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
167     aAction = salomeConnector()->addEditCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
168                                                 QIcon(":pictures/redo.png"), QKeySequence::Redo,
169                                                 false);
170     connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
171     salomeConnector()->addEditMenuSeparator();
172     return;
173   }
174   // File commands group
175   XGUI_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
176
177   XGUI_Command* aCommand;
178
179   aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
180                                 QIcon(":pictures/save.png"), QKeySequence::Save);
181   aCommand->connectTo(this, SLOT(onSave()));
182   //aCommand->disable();
183
184   aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
185                                 QIcon(":pictures/undo.png"), QKeySequence::Undo);
186   aCommand->connectTo(this, SLOT(onUndo()));
187
188   aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
189                                 QIcon(":pictures/redo.png"), QKeySequence::Redo);
190   aCommand->connectTo(this, SLOT(onRedo()));
191
192   aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
193                                 QIcon(":pictures/rebuild.png"));
194
195   aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
196                                 QIcon(":pictures/save.png"));
197   aCommand->connectTo(this, SLOT(onSaveAs()));
198   //aCommand->disable();
199
200   aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
201                                 QIcon(":pictures/open.png"), QKeySequence::Open);
202   aCommand->connectTo(this, SLOT(onOpen()));
203
204   //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
205   //                              QIcon(":pictures/new.png"), QKeySequence::New);
206   //aCommand->connectTo(this, SLOT(onNew()));
207
208   aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
209                                 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
210   aCommand->connectTo(this, SLOT(onPreferences()));
211
212   aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
213                                 QIcon(":pictures/close.png"), QKeySequence::Close);
214   aCommand->connectTo(this, SLOT(onExit()));
215   //FIXME: SBH's test action. Can be used for some GUI tests.
216 //  #ifdef _DEBUG
217 //    aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
218 //                                  QIcon(":pictures/close.png"), QKeySequence(), true);
219 //    aCommand->connectTo(myMainWindow, SLOT(dockPythonConsole()));
220 //  #endif
221 }
222
223 //******************************************************
224 XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
225 {
226   XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
227   return aMenuBar->addWorkbench(theName);
228 }
229
230 //******************************************************
231 void XGUI_Workshop::processEvent(const Events_Message* theMessage)
232 {
233   //A message to start feature creation received.
234   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_LOADED)) {
235     const Config_FeatureMessage* aFeatureMsg =
236         dynamic_cast<const Config_FeatureMessage*>(theMessage);
237     if (!aFeatureMsg->isInternal()) {
238       addFeature(aFeatureMsg);
239     }
240   }
241
242   // Process creation of Part
243   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
244     const ModelAPI_ObjectUpdatedMessage* aUpdMsg =
245         dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
246     onFeatureCreatedMsg(aUpdMsg);
247     if (myUpdatePrefs) {
248       if (mySalomeConnector)
249         mySalomeConnector->createPreferences();
250       myUpdatePrefs = false;
251     }
252   }
253   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
254     myUpdatePrefs = true;
255   }
256
257   // Redisplay feature
258   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
259     const ModelAPI_ObjectUpdatedMessage* aUpdMsg =
260         dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
261     onFeatureRedisplayMsg(aUpdMsg);
262   }
263
264   //Update property panel on corresponding message. If there is no current operation (no
265   //property panel), or received message has different feature to the current - do nothing.
266   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
267     const ModelAPI_ObjectUpdatedMessage* anUpdateMsg =
268         dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
269     onFeatureUpdatedMsg(anUpdateMsg);
270   }
271
272   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
273     const ModelAPI_ObjectDeletedMessage* aDelMsg =
274         dynamic_cast<const ModelAPI_ObjectDeletedMessage*>(theMessage);
275     onObjectDeletedMsg(aDelMsg);
276   }
277
278   else if (theMessage->eventID() == Events_LongOp::eventID()) {
279     if (Events_LongOp::isPerformed())
280       QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
281     //QTimer::singleShot(10, this, SLOT(onStartWaiting()));
282     else
283       QApplication::restoreOverrideCursor();
284   }
285
286   //An operation passed by message. Start it, process and commit.
287   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
288     const Config_PointerMessage* aPartSetMsg =
289         dynamic_cast<const Config_PointerMessage*>(theMessage);
290     //myPropertyPanel->cleanContent();
291     ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
292
293     if (myOperationMgr->startOperation(anOperation)) {
294       myPropertyPanel->updateContentWidget(anOperation->feature());
295       if (!anOperation->getDescription()->hasXmlRepresentation()) {
296         if (anOperation->commit())
297           updateCommandStatus();
298       }
299     }
300   } else {
301     //Show error dialog if error message received.
302     const Events_Error* anAppError = dynamic_cast<const Events_Error*>(theMessage);
303     if (anAppError) {
304       emit errorOccurred(QString::fromLatin1(anAppError->description()));
305     }
306   }
307   if (!isSalomeMode()) {
308     SessionPtr aMgr = ModelAPI_Session::get();
309     if (aMgr->isModified() != myMainWindow->isModifiedState())
310       myMainWindow->setModifiedState(aMgr->isModified());
311   }
312 }
313
314
315 //******************************************************
316 void XGUI_Workshop::onStartWaiting()
317 {
318   if (Events_LongOp::isPerformed()) {
319     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
320   }
321 }
322
323 //******************************************************
324 void XGUI_Workshop::onFeatureUpdatedMsg(const ModelAPI_ObjectUpdatedMessage* theMsg)
325 {
326   std::set<ObjectPtr> aFeatures = theMsg->objects();
327   if (myOperationMgr->hasOperation()) {
328     FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
329     std::set<ObjectPtr>::const_iterator aIt;
330     for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
331       ObjectPtr aNewFeature = (*aIt);
332       if (aNewFeature == aCurrentFeature) {
333         myPropertyPanel->updateContentWidget(aCurrentFeature);
334         break;
335       }
336     }
337   }
338   myOperationMgr->validateCurrentOperation();
339 }
340
341 //******************************************************
342 void XGUI_Workshop::onFeatureRedisplayMsg(const ModelAPI_ObjectUpdatedMessage* theMsg)
343 {
344   std::set<ObjectPtr> aObjects = theMsg->objects();
345   std::set<ObjectPtr>::const_iterator aIt;
346   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
347     ObjectPtr aObj = (*aIt);
348     if (!aObj->data() || !aObj->data()->isValid())
349       myDisplayer->erase(aObj, false);
350     else {
351       if (myDisplayer->isVisible(aObj))  // TODO VSV: Correction sketch drawing
352         myDisplayer->display(aObj, false);  // In order to update presentation
353       else {
354         if (myOperationMgr->hasOperation()) {
355           ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
356           if (aOperation->hasObject(aObj)) {  // Display only current operation results
357             myDisplayer->display(aObj, false);
358           }
359         }
360       }
361     }
362   }
363   myDisplayer->updateViewer();
364 }
365
366 //******************************************************
367 void XGUI_Workshop::onFeatureCreatedMsg(const ModelAPI_ObjectUpdatedMessage* theMsg)
368 {
369   std::set<ObjectPtr> aObjects = theMsg->objects();
370
371   std::set<ObjectPtr>::const_iterator aIt;
372   bool aHasPart = false;
373   bool isDisplayed = false;
374   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
375     ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
376     if (aPart) {
377       aHasPart = true;
378       // If a feature is created from the aplication's python console  
379       // it doesn't stored in the operation mgr and doesn't displayed
380     } else if (myOperationMgr->hasOperation()) {
381       ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
382       if (aOperation->hasObject(*aIt)) {  // Display only current operation results
383         myDisplayer->display(*aIt, false);
384         isDisplayed = true;
385       }
386     }
387   }
388   if (isDisplayed)
389     myDisplayer->updateViewer();
390   if (aHasPart) {
391     //The created part will be created in Object Browser later and we have to activate it
392     // only when it is created everywere
393     QTimer::singleShot(50, this, SLOT(activateLastPart()));
394   }
395 }
396
397 //******************************************************
398 void XGUI_Workshop::onObjectDeletedMsg(const ModelAPI_ObjectDeletedMessage* theMsg)
399 {
400   //std::set<ObjectPtr> aFeatures = theMsg->objects();
401 }
402
403 //******************************************************
404 void XGUI_Workshop::onOperationStarted()
405 {
406   ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
407   if (this->isSalomeMode()) 
408     aOperation->setNestedFeatures(mySalomeConnector->nestedActions(aOperation->id()));
409   else 
410     aOperation->setNestedFeatures(myActionsMgr->nestedCommands(aOperation->id()));
411   
412   if (aOperation->getDescription()->hasXmlRepresentation()) {  //!< No need for property panel
413     connectWithOperation(aOperation);
414
415     showPropertyPanel();
416     QString aXmlRepr = aOperation->getDescription()->xmlRepresentation();
417     ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
418                                                                  myModuleConnector);
419
420     myPropertyPanel->cleanContent();
421     aFactory.createWidget(myPropertyPanel->contentWidget());
422
423     QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
424     QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
425     ModuleBase_ModelWidget* aWidget;
426     for (; anIt != aLast; anIt++) {
427       aWidget = *anIt;
428       aWidget->setFeature(aOperation->feature());
429       QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
430       // Init default values
431       if (!aOperation->isEditOperation() && !aWidget->isComputedDefault()) {
432         aWidget->storeValue();
433       }
434     }
435
436     myPropertyPanel->setModelWidgets(aWidgets);
437     myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
438   }
439   updateCommandStatus();
440 }
441
442 //******************************************************
443 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
444 {
445   //!< No need for property panel
446   updateCommandStatus();
447   hidePropertyPanel();
448   myPropertyPanel->cleanContent();
449 }
450
451 /*
452  *
453  */
454 void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
455 {
456   if (!theMessage) {
457 #ifdef _DEBUG
458     qDebug() << "XGUI_Workshop::addFeature: NULL message.";
459 #endif
460     return;
461   }
462   // Remember features icons
463   myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon());
464
465   //Find or create Workbench
466   QString aWchName = QString::fromStdString(theMessage->workbenchId());
467   QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
468   bool isUsePropPanel = theMessage->isUseInput();
469   QString aFeatureId = QString::fromStdString(theMessage->id());
470   if (isSalomeMode()) {
471     QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureId,
472                                                      QString::fromStdString(theMessage->text()),
473                                                      QString::fromStdString(theMessage->tooltip()),
474                                                      QIcon(theMessage->icon().c_str()),
475                                                      QKeySequence(), isUsePropPanel);
476     salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ", QString::SkipEmptyParts));
477     myActionsMgr->addCommand(aAction);
478     myModule->featureCreated(aAction);
479   } else {
480
481     XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
482     XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
483     if (!aPage) {
484       aPage = addWorkbench(aWchName);
485     }
486     //Find or create Group
487     QString aGroupName = QString::fromStdString(theMessage->groupId());
488     XGUI_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
489     if (!aGroup) {
490       aGroup = aPage->addGroup(aGroupName);
491     }
492     // Check if hotkey sequence is already defined:
493     QKeySequence aHotKey = myActionsMgr->registerShortcut(
494         QString::fromStdString(theMessage->keysequence()));
495     // Create feature...
496     XGUI_Command* aCommand = aGroup->addFeature(aFeatureId,
497                                                 QString::fromStdString(theMessage->text()),
498                                                 QString::fromStdString(theMessage->tooltip()),
499                                                 QIcon(theMessage->icon().c_str()), aHotKey,
500                                                 isUsePropPanel);
501     aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts));
502     myActionsMgr->addCommand(aCommand);
503     myModule->featureCreated(aCommand);
504   }
505 }
506
507 /*
508  * Makes a signal/slot connections between Property Panel
509  * and given operation. The given operation becomes a
510  * current operation and previous operation if exists
511  */
512 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
513 {
514   QAction* aCommand = 0;
515   if (isSalomeMode()) {
516     aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
517   } else {
518     XGUI_MainMenu* aMenu = myMainWindow->menuObject();
519     aCommand = aMenu->feature(theOperation->getDescription()->operationId());
520   }
521   //Abort operation on uncheck the command
522   if (aCommand)
523     connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
524 }
525
526 /*
527  * Saves document with given name.
528  */
529 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
530 {
531   QApplication::restoreOverrideCursor();
532   SessionPtr aMgr = ModelAPI_Session::get();
533   aMgr->save(theName.toLatin1().constData(), theFileNames);
534   QApplication::restoreOverrideCursor();
535 }
536
537 bool XGUI_Workshop::isActiveOperationAborted()
538 {
539   if(!myOperationMgr->hasOperation())
540     return true;
541   return myOperationMgr->abortOperation();
542 }
543
544 //******************************************************
545 void XGUI_Workshop::onExit()
546 {
547   SessionPtr aMgr = ModelAPI_Session::get();
548   if (aMgr->isModified()) {
549     int anAnswer = QMessageBox::question(
550         myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
551         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
552     if (anAnswer == QMessageBox::Save) {
553       bool saved = onSave();
554       if (!saved) {
555         return;
556       }
557     } else if (anAnswer == QMessageBox::Cancel) {
558       return;
559     }
560   }
561   qApp->exit();
562 }
563
564 //******************************************************
565 void XGUI_Workshop::onNew()
566 {
567   QApplication::setOverrideCursor(Qt::WaitCursor);
568   if (objectBrowser() == 0) {
569     createDockWidgets();
570     mySelector->connectViewers();
571   }
572   myViewerProxy->connectToViewer();
573   showObjectBrowser();
574   if (!isSalomeMode()) {
575     myMainWindow->showPythonConsole();
576     QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
577     aWnd->showMaximized();
578     updateCommandStatus();
579   }
580   myContextMenuMgr->connectViewer();
581   QApplication::restoreOverrideCursor();
582 }
583
584 //******************************************************
585 void XGUI_Workshop::onOpen()
586 {
587   if(!isActiveOperationAborted())
588     return;
589   //save current file before close if modified
590   SessionPtr aSession = ModelAPI_Session::get();
591   if (aSession->isModified()) {
592     //TODO(sbh): re-launch the app?
593     int anAnswer = QMessageBox::question(
594         myMainWindow, tr("Save current file"),
595         tr("The document is modified, save before opening another?"),
596         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
597     if (anAnswer == QMessageBox::Save) {
598       onSave();
599     } else if (anAnswer == QMessageBox::Cancel) {
600       return;
601     }
602     aSession->moduleDocument()->close();
603     myCurrentDir = "";
604   }
605
606   //show file dialog, check if readable and open
607   myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
608   if (myCurrentDir.isEmpty())
609     return;
610   QFileInfo aFileInfo(myCurrentDir);
611   if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
612     QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
613     myCurrentDir = "";
614     return;
615   }
616   QApplication::setOverrideCursor(Qt::WaitCursor);
617   aSession->load(myCurrentDir.toLatin1().constData());
618   myObjectBrowser->rebuildDataTree();
619   displayAllResults();
620   updateCommandStatus();
621   QApplication::restoreOverrideCursor();
622 }
623
624 //******************************************************
625 bool XGUI_Workshop::onSave()
626 {
627   if(!isActiveOperationAborted())
628     return false;
629   if (myCurrentDir.isEmpty()) {
630     return onSaveAs();
631   }
632   std::list<std::string> aFiles;
633   saveDocument(myCurrentDir, aFiles);
634   updateCommandStatus();
635   myMainWindow->setModifiedState(false);
636   return true;
637 }
638
639 //******************************************************
640 bool XGUI_Workshop::onSaveAs()
641 {
642   if(!isActiveOperationAborted())
643     return false;
644   QFileDialog dialog(mainWindow());
645   dialog.setWindowTitle(tr("Select directory to save files..."));
646   dialog.setFileMode(QFileDialog::Directory);
647   dialog.setFilter(tr("Folders (*)"));
648   dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
649   dialog.setViewMode(QFileDialog::Detail);
650
651   if (!dialog.exec()) {
652     return false;
653   }
654   QString aTempDir = dialog.selectedFiles().first();
655   QDir aDir(aTempDir);
656   if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
657     int answer = QMessageBox::question(
658         myMainWindow,
659         //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
660         tr("Save"),
661         tr("The folder already contains some files, save anyway?"),
662         QMessageBox::Save | QMessageBox::Cancel);
663     if (answer == QMessageBox::Cancel) {
664       return false;
665     }
666   }
667   myCurrentDir = aTempDir;
668   if (!isSalomeMode()) {
669     myMainWindow->setCurrentDir(myCurrentDir, false);
670     myMainWindow->setModifiedState(false);
671   }
672   return onSave();
673 }
674
675 //******************************************************
676 void XGUI_Workshop::onUndo()
677 {
678   objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
679   SessionPtr aMgr = ModelAPI_Session::get();
680   if (aMgr->isOperation())
681     operationMgr()->abortOperation();
682   aMgr->undo();
683   updateCommandStatus();
684 }
685
686 //******************************************************
687 void XGUI_Workshop::onRedo()
688 {
689   objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
690   SessionPtr aMgr = ModelAPI_Session::get();
691   if (aMgr->isOperation())
692     operationMgr()->abortOperation();
693   aMgr->redo();
694   updateCommandStatus();
695 }
696
697 //******************************************************
698 void XGUI_Workshop::onPreferences()
699 {
700   XGUI_Prefs aModif;
701   XGUI_Preferences::editPreferences(aModif);
702   if (aModif.size() > 0) {
703     QString aSection;
704     foreach (XGUI_Pref aPref, aModif)
705     {
706       aSection = aPref.first;
707       if (aSection == XGUI_Preferences::VIEWER_SECTION) {
708         if (!isSalomeMode())
709           myMainWindow->viewer()->updateFromResources();
710       } else if (aSection == XGUI_Preferences::MENU_SECTION) {
711         if (!isSalomeMode())
712           myMainWindow->menuObject()->updateFromResources();
713       }
714     }
715   }
716 }
717
718 //******************************************************
719 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
720 {
721   QString libName = QString::fromStdString(library(theModule.toStdString()));
722   if (libName.isEmpty()) {
723     qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
724     return 0;
725   }
726
727   QString err;
728   CREATE_FUNC crtInst = 0;
729
730 #ifdef WIN32
731   HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
732   if (!modLib) {
733     LPVOID lpMsgBuf;
734     ::FormatMessage(
735         FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
736         0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
737     QString aMsg((char*) &lpMsgBuf);
738     err = QString("Failed to load  %1. %2").arg(libName).arg(aMsg);
739     ::LocalFree(lpMsgBuf);
740   } else {
741     crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
742     if (!crtInst) {
743       LPVOID lpMsgBuf;
744       ::FormatMessage(
745           FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
746               | FORMAT_MESSAGE_IGNORE_INSERTS,
747           0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
748       QString aMsg((char*) &lpMsgBuf);
749       err = QString("Failed to find  %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
750       ::LocalFree(lpMsgBuf);
751     }
752   }
753 #else
754   void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
755   if ( !modLib ) {
756     err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
757   } else {
758     crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
759     if ( !crtInst ) {
760       err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
761     }
762   }
763 #endif
764
765   ModuleBase_IModule* aModule = crtInst ? crtInst(this) : 0;
766
767   if (!err.isEmpty()) {
768     if (mainWindow()) {
769       QMessageBox::warning(mainWindow(), tr("Error"), err);
770     } else {
771       qWarning(qPrintable(err));
772     }
773   }
774   return aModule;
775 }
776
777 //******************************************************
778 bool XGUI_Workshop::activateModule()
779 {
780   Config_ModuleReader aModuleReader;
781   QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
782   myModule = loadModule(moduleName);
783   if (!myModule)
784     return false;
785   myModule->createFeatures();
786   myActionsMgr->update();
787   return true;
788 }
789
790 //******************************************************
791 void XGUI_Workshop::updateCommandStatus()
792 {
793   QList<QAction*> aCommands;
794   if (isSalomeMode()) {  // update commands in SALOME mode
795     aCommands = salomeConnector()->commandList();
796   } else {
797     XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
798     foreach (XGUI_Command* aCmd, aMenuBar->features())
799       aCommands.append(aCmd);
800   }
801   SessionPtr aMgr = ModelAPI_Session::get();
802   if (aMgr->hasModuleDocument()) {
803     QAction* aUndoCmd;
804     QAction* aRedoCmd;
805     foreach(QAction* aCmd, aCommands)
806     {
807       QString aId = aCmd->data().toString();
808       if (aId == "UNDO_CMD")
809         aUndoCmd = aCmd;
810       else if (aId == "REDO_CMD")
811         aRedoCmd = aCmd;
812       else
813         // Enable all commands
814         aCmd->setEnabled(true);
815     }
816     aUndoCmd->setEnabled(aMgr->canUndo());
817     aRedoCmd->setEnabled(aMgr->canRedo());
818   } else {
819     foreach(QAction* aCmd, aCommands)
820     {
821       QString aId = aCmd->data().toString();
822       if (aId == "NEW_CMD")
823         aCmd->setEnabled(true);
824       else if (aId == "EXIT_CMD")
825         aCmd->setEnabled(true);
826       else
827         aCmd->setEnabled(false);
828     }
829   }
830   myActionsMgr->update();
831 }
832
833 //******************************************************
834 QList<QAction*> XGUI_Workshop::getModuleCommands() const
835 {
836   QList<QAction*> aCommands;
837   if (isSalomeMode()) {  // update commands in SALOME mode
838     aCommands = salomeConnector()->commandList();
839   } else {
840     XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
841     foreach(XGUI_Command* aCmd, aMenuBar->features())
842     {
843       aCommands.append(aCmd);
844     }
845   }
846   return aCommands;
847 }
848
849 //******************************************************
850 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
851 {
852   QDockWidget* aObjDock = new QDockWidget(theParent);
853   aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
854   aObjDock->setWindowTitle(tr("Object browser"));
855   aObjDock->setStyleSheet(
856       "::title { position: relative; padding-left: 5px; text-align: left center }");
857   myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
858   connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this,
859           SLOT(changeCurrentDocument(ObjectPtr)));
860   aObjDock->setWidget(myObjectBrowser);
861
862   myContextMenuMgr->connectObjectBrowser();
863   return aObjDock;
864 }
865
866 //******************************************************
867 /*
868  * Creates dock widgets, places them in corresponding area
869  * and tabifies if necessary.
870  */
871 void XGUI_Workshop::createDockWidgets()
872 {
873   QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
874   QDockWidget* aObjDock = createObjectBrowser(aDesktop);
875   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
876   myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
877   myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
878   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
879   hidePropertyPanel();  //<! Invisible by default
880   hideObjectBrowser();
881   aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
882
883   QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
884   connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
885   QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
886   connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
887 //TODO(sbh): KeyReleasedProblem
888   connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr,
889           SLOT(onKeyReleased(QKeyEvent*)));
890
891   connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), myOperationMgr,
892           SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
893   connect(myOperationMgr, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), myPropertyPanel,
894           SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
895   connect(myOperationMgr, SIGNAL(operationValidated(bool)), myPropertyPanel,
896           SLOT(setAcceptEnabled(bool)));
897
898 }
899
900 //******************************************************
901 void XGUI_Workshop::showPropertyPanel()
902 {
903   QAction* aViewAct = myPropertyPanel->toggleViewAction();
904   //<! Restore ability to close panel from the window's menu
905   aViewAct->setEnabled(true);
906   myPropertyPanel->show();
907   myPropertyPanel->raise();
908 }
909
910 //******************************************************
911 void XGUI_Workshop::hidePropertyPanel()
912 {
913   QAction* aViewAct = myPropertyPanel->toggleViewAction();
914   //<! Do not allow to show empty property panel
915   aViewAct->setEnabled(false);
916   myPropertyPanel->hide();
917 }
918
919 //******************************************************
920 void XGUI_Workshop::showObjectBrowser()
921 {
922   myObjectBrowser->parentWidget()->show();
923 }
924
925 //******************************************************
926 void XGUI_Workshop::hideObjectBrowser()
927 {
928   myObjectBrowser->parentWidget()->hide();
929 }
930
931 //******************************************************
932 void XGUI_Workshop::onFeatureTriggered()
933 {
934   QAction* aCmd = dynamic_cast<QAction*>(sender());
935   if (aCmd) {
936     QString aId = salomeConnector()->commandId(aCmd);
937     if (!aId.isNull())
938       myModule->launchOperation(aId);
939   }
940 }
941
942 //******************************************************
943 void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
944 {
945   SessionPtr aMgr = ModelAPI_Session::get();
946   if (theObj) {
947     ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(theObj);
948     if (aPart) {
949       DocumentPtr aPartDoc = aPart->partDoc();
950       if (aPartDoc) {
951         aMgr->setActiveDocument(aPartDoc);
952         return;
953       }
954     }
955   }
956   aMgr->setActiveDocument(aMgr->moduleDocument());
957 }
958
959 //******************************************************
960 void XGUI_Workshop::salomeViewerSelectionChanged()
961 {
962   emit salomeViewerSelection();
963 }
964
965 //**************************************************************
966 XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const
967 {
968   return mySalomeConnector->viewer();
969 }
970
971 //**************************************************************
972 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
973 {
974   QList<ObjectPtr> aObjects = mySelector->selection()->selectedObjects();
975   if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) {
976     ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
977     activatePart(aPart);
978   } else if (theId == "DEACTIVATE_PART_CMD")
979     activatePart(ResultPartPtr());
980   else if (theId == "DELETE_CMD")
981     deleteObjects(aObjects);
982   else if (theId == "SHOW_CMD")
983     showObjects(aObjects, true);
984   else if (theId == "HIDE_CMD")
985     showObjects(aObjects, false);
986   else if (theId == "SHOW_ONLY_CMD")
987     showOnlyObjects(aObjects);
988 }
989
990 //**************************************************************
991 void XGUI_Workshop::onWidgetValuesChanged()
992 {
993   ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
994   FeaturePtr aFeature = anOperation->feature();
995
996   ModuleBase_ModelWidget* aSenderWidget = dynamic_cast<ModuleBase_ModelWidget*>(sender());
997   //if (aCustom)
998   //  aCustom->storeValue(aFeature);
999
1000   const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
1001   QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
1002   for (; anIt != aLast; anIt++) {
1003     ModuleBase_ModelWidget* aCustom = *anIt;
1004     if (aCustom && (/*!aCustom->isInitialized(aFeature) ||*/aCustom == aSenderWidget)) {
1005       //aCustom->storeValue(aFeature);
1006       aCustom->storeValue();
1007     }
1008   }
1009 }
1010
1011 //**************************************************************
1012 void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
1013 {
1014   if (theFeature)
1015     theFeature->activate();
1016   changeCurrentDocument(theFeature);
1017   myObjectBrowser->activatePart(theFeature);
1018 }
1019
1020 //**************************************************************
1021 void XGUI_Workshop::activateLastPart()
1022 {
1023   SessionPtr aMgr = ModelAPI_Session::get();
1024   DocumentPtr aDoc = aMgr->moduleDocument();
1025   std::string aGrpName = ModelAPI_ResultPart::group();
1026   ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
1027   ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
1028   if (aPart)
1029     activatePart(aPart);
1030 }
1031
1032 //**************************************************************
1033 void XGUI_Workshop::deleteObjects(const QList<ObjectPtr>& theList)
1034 {
1035   QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1036   QMessageBox::StandardButton aRes = QMessageBox::warning(
1037       aDesktop, tr("Delete features"), tr("Seleted features will be deleted. Continue?"),
1038       QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1039   // ToDo: definbe deleting method
1040   if (aRes == QMessageBox::Yes) {
1041     SessionPtr aMgr = ModelAPI_Session::get();
1042     aMgr->startOperation();
1043     foreach (ObjectPtr aObj, theList)
1044     {
1045       ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1046       if (aPart) {
1047         DocumentPtr aDoc = aPart->document();
1048         if (aDoc == aMgr->activeDocument()) {
1049           aDoc->close();
1050         }
1051         //aMgr->moduleDocument()->removeFeature(aPart->owner());
1052       } else {
1053         FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1054         if (aFeature)
1055           aObj->document()->removeFeature(aFeature);
1056       }
1057     }
1058     myDisplayer->updateViewer();
1059     aMgr->finishOperation();
1060   }
1061 }
1062
1063 //**************************************************************
1064 void XGUI_Workshop::showObjects(const QList<ObjectPtr>& theList, bool isVisible)
1065 {
1066   foreach (ObjectPtr aObj, theList)
1067   {
1068     ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObj);
1069     if (aRes) {
1070       if (isVisible) {
1071         myDisplayer->display(aRes, false);
1072       } else {
1073         myDisplayer->erase(aRes, false);
1074       }
1075     }
1076   }
1077   myDisplayer->updateViewer();
1078 }
1079
1080 //**************************************************************
1081 void XGUI_Workshop::showOnlyObjects(const QList<ObjectPtr>& theList)
1082 {
1083   myDisplayer->eraseAll(false);
1084   showObjects(theList, true);
1085 }
1086
1087
1088 //**************************************************************
1089 void XGUI_Workshop::updateCommandsOnViewSelection()
1090 {
1091   SessionPtr aMgr = ModelAPI_Session::get();
1092   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1093   XGUI_Selection* aSelection = mySelector->selection();
1094   if (aSelection->getSelected().size() == 0)
1095     return;
1096
1097   QList<QAction*> aActions = getModuleCommands();
1098   foreach(QAction* aAction, aActions)
1099   {
1100     QString aId = aAction->data().toString();
1101     std::list<ModelAPI_Validator*> aValidators;
1102     std::list<std::list<std::string> > anArguments;
1103     aFactory->validators(aId.toStdString(), aValidators, anArguments);
1104     std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
1105     for (; aValidator != aValidators.end(); aValidator++) {
1106       if (*aValidator) {
1107         const ModuleBase_SelectionValidator* aSelValidator =
1108             dynamic_cast<const ModuleBase_SelectionValidator*>(*aValidator);
1109         if (aSelValidator) {
1110           aAction->setEnabled(aSelValidator->isValid(aSelection));
1111         }
1112       }
1113     }
1114   }
1115 }
1116
1117 //**************************************************************
1118 void XGUI_Workshop::registerValidators() const
1119 {
1120   SessionPtr aMgr = ModelAPI_Session::get();
1121   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1122 }
1123
1124 //**************************************************************
1125 void XGUI_Workshop::displayAllResults()
1126 {
1127   SessionPtr aMgr = ModelAPI_Session::get();
1128   DocumentPtr aRootDoc = aMgr->moduleDocument();
1129   displayDocumentResults(aRootDoc);
1130   for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1131     ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1132     ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1133     displayDocumentResults(aPart->partDoc());
1134   }
1135   myDisplayer->updateViewer();
1136 }
1137
1138 //**************************************************************
1139 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1140 {
1141   if (!theDoc)
1142     return;
1143   displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1144   displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1145 }
1146
1147 //**************************************************************
1148 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1149 {
1150   for (int i = 0; i < theDoc->size(theGroup); i++)
1151     myDisplayer->display(theDoc->object(theGroup, i), false);
1152 }