Salome HOME
0022614: [CEA 1146] SalomePyQt python API tabifyDockWidgets and findDockByWT
[modules/yacs.git] / src / genericgui / GenericGui.cxx
1 // Copyright (C) 2006-2014  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <Python.h>
21 #include "SALOME_ResourcesManager.hxx"
22 #include "SALOME_LifeCycleCORBA.hxx"
23
24 #include "RuntimeSALOME.hxx"
25 #include "Proc.hxx"
26 #include "InputPort.hxx"
27 #include "ServiceNode.hxx"
28 #include "parsers.hxx"
29 #include "Logger.hxx"
30 #include "YACSGuiLoader.hxx"
31 #include "ComponentInstance.hxx"
32
33 #include "SALOME_NamingService.hxx"
34 #include "SALOME_ModuleCatalog.hxx"
35 #include "SALOME_ModuleCatalog.hh"
36 #include "SALOMEDS_Tool.hxx"
37
38 #include "QtGuiContext.hxx"
39
40 #include "GuiEditor.hxx"
41 #include "GraphicsView.hxx"
42 #include "Scene.hxx"
43 #include "GenericGui.hxx"
44 #include "SceneItem.hxx"
45 #include "SceneNodeItem.hxx"
46 #include "SceneComposedNodeItem.hxx"
47 #include "ItemEdition.hxx"
48 #include "CatalogWidget.hxx"
49 #include "TreeView.hxx"
50 #include "VisitorSaveGuiSchema.hxx"
51 #include "TypeCode.hxx"
52 #include "LinkInfo.hxx"
53 #include "LogViewer.hxx"
54 #include "chrono.hxx"
55 #include "Resource.hxx"
56 #include "Message.hxx"
57 #include "ListJobs_GUI.hxx"
58
59 #include <QFileDialog>
60 #include <sstream>
61 #include <QDir>
62 #include <QDateTime>
63 #include <QMessageBox>
64 #include <QWhatsThis>
65
66 #include <cstdlib>
67
68 #include <ctime>
69
70 #ifdef WIN32
71 #define WEXITSTATUS(w)  ((int) ((w) & 0x40000000))
72 #endif
73
74 //#define _DEVDEBUG_
75 #include "YacsTrace.hxx"
76
77 using namespace std;
78 using namespace YACS::HMI;
79
80 GenericGui::GenericGui(YACS::HMI::SuitWrapper* wrapper, QMainWindow *parent)
81 {
82   _wrapper = wrapper;
83   _parent = parent;
84   _dwTree = 0;
85   _dwStacked = 0;
86   _dwCatalogs = 0;
87   _catalogsWidget = 0;
88   _sessionCatalog = 0;
89   _schemaCnt = 0;
90   _isSaved = false;
91   _mapViewContext.clear();
92   _machineList.clear();
93   _menuId = 190;
94   _BJLdialog = NULL;
95   QtGuiContext::_counters = new counters(100);
96   srand((unsigned)time(0)); 
97
98   GuiObserver::setEventMap();
99
100   string iconPath = getenv("YACS_ROOT_DIR");
101   iconPath += "/share/salome/resources/yacs";
102   DEBTRACE(iconPath);
103   QDir::addSearchPath("icons", iconPath.c_str());
104   
105   _guiEditor = new GuiEditor();
106
107   YACS::ENGINE::RuntimeSALOME::setRuntime();
108   _loader = new YACSGuiLoader();
109   _loader->registerProcCataLoader();
110   _builtinCatalog = YACS::ENGINE::getSALOMERuntime()->getBuiltinCatalog();
111
112   try
113     {
114       YACS::ENGINE::RuntimeSALOME* runTime = YACS::ENGINE::getSALOMERuntime();
115       CORBA::ORB_ptr orb = runTime->getOrb();
116       if (orb)
117         {
118           SALOME_NamingService namingService(orb);
119           CORBA::Object_ptr obj = namingService.Resolve("/Kernel/ModulCatalog");
120           SALOME_ModuleCatalog::ModuleCatalog_var aModuleCatalog =
121             SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
122           if (! CORBA::is_nil(aModuleCatalog))
123             {
124               DEBTRACE("SALOME_ModuleCatalog::ModuleCatalog found");
125               std::string anIOR = orb->object_to_string( aModuleCatalog );
126               _sessionCatalog = runTime->loadCatalog( "session", anIOR );
127               runTime->addCatalog(_sessionCatalog);
128               {
129                 std::map< std::string, YACS::ENGINE::ComponentDefinition * >::iterator it;
130                 for (it = _sessionCatalog->_componentMap.begin();
131                      it != _sessionCatalog->_componentMap.end(); ++it)
132                   DEBTRACE("Component: " <<(*it).first);
133               }
134               {
135                 std::map< std::string, YACS::ENGINE::TypeCode*>::iterator it;
136                 for (it = _sessionCatalog->_typeMap.begin();
137                      it != _sessionCatalog->_typeMap.end(); ++it)
138                   DEBTRACE("Type : " <<(*it).first
139                            << " " << (*it).second->getKindRepr()
140                            << " " << (*it).second->name()
141                            << " " << (*it).second->shortName()
142                            << " " << (*it).second->id() );
143               }
144               DEBTRACE("_sessionCatalog " << _sessionCatalog);
145             }
146         }
147     }
148   catch(ServiceUnreachable& e)
149     {
150       DEBTRACE("Caught Exception. "<<e);
151     }
152
153   _dwTree = new QDockWidget(_parent);
154   _dwTree->setVisible(false);
155   _dwTree->setWindowTitle("Tree View: edition mode");
156   _dwTree->setObjectName("yacsTreeViewDock");
157   _parent->addDockWidget(Qt::LeftDockWidgetArea, _dwTree);
158   _dwStacked = new QDockWidget(_parent);
159   _dwStacked->setVisible(false);
160   _dwStacked->setWindowTitle("Input Panel");
161   _dwStacked->setObjectName("yacsInputPanelDock");
162   _dwStacked->setMinimumWidth(270); // --- force a minimum until display
163   _parent->addDockWidget(Qt::RightDockWidgetArea, _dwStacked);
164   _dwCatalogs = new QDockWidget(_parent);
165   _dwCatalogs->setVisible(false);
166   _dwCatalogs->setWindowTitle("Catalogs");
167   _dwCatalogs->setObjectName("yacsCatalogsDock");
168   _parent->addDockWidget(Qt::RightDockWidgetArea, _dwCatalogs);
169   _catalogsWidget = new CatalogWidget(_dwCatalogs,
170                                       _builtinCatalog,
171                                       _sessionCatalog);
172   _dwCatalogs->setWidget(_catalogsWidget);
173
174   _parent->tabifyDockWidget(_dwStacked, _dwCatalogs);
175   _parent->tabifyDockWidget(_dwTree, _wrapper->objectBrowser());
176 #if QT_VERSION >= 0x040500
177   _parent->setTabPosition(Qt::AllDockWidgetAreas, Resource::tabPanelsUp? QTabWidget::North: QTabWidget::South);
178 #endif
179   //Import user catalog
180   std::string usercata=Resource::userCatalog.toStdString();
181   _catalogsWidget->addCatalogFromFile(usercata);
182 }
183
184 GenericGui::~GenericGui()
185 {
186   if(_BJLdialog) delete _BJLdialog;
187 }
188
189 void GenericGui::createActions()
190 {
191   //       QAction* createAction(const int id,
192   //                             const QString& toolTip,
193   //                             const QIcon& icon,
194   //                             const QString& menu,
195   //                             const QString& status,
196   //                             const int shortCut,
197   //                             QObject* parent =0,
198   //                             bool checkable = false,
199   //                             QObject* receiver =0,
200   //                             const char* member =0);
201
202   _newSchemaAct = _wrapper->createAction(getMenuId(), tr("Create a new YACS Schema"), QIcon("icons:schema.png"),
203                                          tr("New Schema"), tr("Create a new YACS Schema"),
204                                          0, _parent, false, this,  SLOT(onNewSchema()));
205   _newSchemaAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_N); // --- QKeySequence::New ambiguous in SALOME
206
207   _importSchemaAct = _wrapper->createAction(getMenuId(), tr("Import a YACS Schema for edition"), QIcon("icons:import_dataflow.png"),
208                                             tr("Import Schema"), tr("Import a YACS Schema for edition"),
209                                             0, _parent, false, this,  SLOT(onImportSchema()));
210   _importSchemaAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_O); // --- QKeySequence::Open ambiguous in SALOME
211   
212   _importSupervSchemaAct = _wrapper->createAction(getMenuId(), tr("Import a SUPERV Schema for edition"), QIcon("icons:import_superv_dataflow.png"),
213                                                   tr("Import SUPERV Schema"), tr("Import a SUPERV Schema for edition"),
214                                                   0, _parent, false, this,  SLOT(onImportSupervSchema()));
215   
216   _exportSchemaAct = _wrapper->createAction(getMenuId(), tr("Save the current YACS Schema"), QIcon("icons:save_dataflow.png"),
217                                             tr("Save Schema"), tr("Save the current YACS Schema"),
218                                             0, _parent, false, this,  SLOT(onExportSchema()));
219   _exportSchemaAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_S); // --- QKeySequence::Save ambiguous in SALOME
220   
221   _exportSchemaAsAct = _wrapper->createAction(getMenuId(), tr("Save the current YACS Schema As..."), QIcon("icons:export_dataflow.png"),
222                                               tr("Save Schema As"), tr("Save the current YACS Schema As..."),
223                                               0, _parent, false, this,  SLOT(onExportSchemaAs()));
224   //_exportSchemaAsAct->setShortcut(QKeySequence::SaveAs); // --- ambiguous in SALOME
225
226   _importCatalogAct = _wrapper->createAction(getMenuId(), tr("Import a Schema as a Catalog"), QIcon("icons:insert_file.png"),
227                                              tr("Import Catalog"), tr("Import a Schema as a Catalog"),
228                                              0, _parent, false, this,  SLOT(onImportCatalog()));
229
230
231   _runLoadedSchemaAct = _wrapper->createAction(getMenuId(), tr("Prepare the current edited schema for run"), QIcon("icons:run_active.png"),
232                                                tr("Run Current Schema"), tr("Prepare the current edited schema for run"),
233                                                0, _parent, false, this,  SLOT(onRunLoadedSchema()));
234
235   _loadRunStateSchemaAct = _wrapper->createAction(getMenuId(), tr("Load a previous run state for this schema, prepare to run"), QIcon("icons:load_execution_state.png"),
236                                                   tr("Load Run State"), tr("Load a previous run state for this schema, prepare to run"),
237                                                   0, _parent, false, this,  SLOT(onLoadRunStateSchema()));
238
239   _loadAndRunSchemaAct = _wrapper->createAction(getMenuId(), tr("Load a schema for run"), QIcon("icons:run.png"),
240                                                 tr("Load Schema to run"), tr("Load a schema for run"),
241                                                 0, _parent, false, this,  SLOT(onLoadAndRunSchema()));
242
243   _chooseBatchJobAct = _wrapper->createAction(getMenuId(), tr("Choose Batch Job to watch"), QIcon("icons:batch.png"),
244                                          tr("Choose Batch Job to watch"), tr("Choose Batch Job to watch"),
245                                          0, _parent, false, this,  SLOT(onChooseBatchJob()));
246
247   _startResumeAct = _wrapper->createAction(getMenuId(), tr("Start or Resume Schema execution"), QIcon("icons:suspend_resume.png"),
248                                            tr("Start/Resume execution"), tr("Start or Resume Schema execution"),
249                                            0, _parent, false, this,  SLOT(onStartResume()));
250
251   _abortAct = _wrapper->createAction(getMenuId(), tr("Abort the current execution"), QIcon("icons:kill.png"),
252                                      tr("Abort execution"), tr("Abort the current execution"),
253                                      0, _parent, false, this,  SLOT(onAbort()));
254
255   _pauseAct = _wrapper->createAction(getMenuId(), tr("Suspend the current execution"), QIcon("icons:pause.png"),
256                                      tr("Suspend execution"), tr("Suspend the current execution"),
257                                      0, _parent, false, this,  SLOT(onPause()));
258
259   _resetAct = _wrapper->createAction(getMenuId(), tr("Reset error nodes and restart the current execution"), QIcon("icons:reset.png"),
260                                      tr("Restart execution"), tr("Restart the current execution with reset of error nodes"),
261                                      0, _parent, false, this,  SLOT(onReset()));
262
263
264   _saveRunStateAct = _wrapper->createAction(getMenuId(), tr("Save the current run state"), QIcon("icons:save_dataflow_state.png"),
265                                             tr("Save State"), tr("Save the current run state"),
266                                             0, _parent, false, this,  SLOT(onSaveRunState()));
267
268   _newEditionAct = _wrapper->createAction(getMenuId(), tr("Edit again the current schema in a new context"), QIcon("icons:new_edition.png"),
269                                           tr("Edit Again"), tr("Edit again the current schema in a new context"),
270                                           0, _parent, false, this,  SLOT(onNewEdition()));
271
272
273   _getYacsContainerLogAct = _wrapper->createAction(getMenuId(), tr("get YACS container log"), QIcon("icons:change_informations.png"),
274                                                    tr("YACS Container Log"), tr("get YACS container log"),
275                                                    0, _parent, false, this,  SLOT(onGetYacsContainerLog()));
276
277   _getErrorReportAct = _wrapper->createAction(getMenuId(), tr("get Node Error Report"), QIcon("icons:filter_notification.png"),
278                                               tr("Node Error Report"), tr("get Node Error Report"),
279                                               0, _parent, false, this,  SLOT(onGetErrorReport()));
280
281   _getErrorDetailsAct = _wrapper->createAction(getMenuId(), tr("get Node Error Details"), QIcon("icons:icon_text.png"),
282                                                tr("Node Error Details"), tr("get Node Error Details"),
283                                                0, _parent, false, this,  SLOT(onGetErrorDetails()));
284
285   _getContainerLogAct = _wrapper->createAction(getMenuId(), tr("get Node Container Log"), QIcon("icons:change_informations.png"),
286                                                tr("Node Container Log"), tr("get Node Container Log"),
287                                                0, _parent, false, this,  SLOT(onGetContainerLog()));
288
289   _shutdownProcAct = _wrapper->createAction(getMenuId(), tr("Shutdown Proc"), QIcon("icons:kill.png"),
290                                              tr("Shutdown Proc"), tr("Shutdown Proc"),
291                                              0, _parent, false, this,  SLOT(onShutdownProc()));
292
293
294   _editDataTypesAct = _wrapper->createAction(getMenuId(), tr("Edit Data Types"), QIcon("icons:kill.png"),
295                                              tr("Edit Data Types"), tr("Edit Data Types"),
296                                              0, _parent, false, this,  SLOT(onEditDataTypes()));
297
298   _createDataTypeAct = _wrapper->createAction(getMenuId(), tr("Create Data Types"), QIcon("icons:kill.png"),
299                                               tr("Create Data Types"), tr("Create Data Types"),
300                                               0, _parent, false, this,  SLOT(onCreateDataType()));
301
302   _importDataTypeAct = _wrapper->createAction(getMenuId(), tr("Import Data Types, use drag and drop from catalog"), QIcon("icons:folder_cyan.png"),
303                                               tr("Import Data Types"), tr("Import Data Types, use drag and drop from catalog"),
304                                               0, _parent, false, this,  SLOT(onImportDataType()));
305
306   _newContainerAct = _wrapper->createAction(getMenuId(), tr("Create a New Container"), QIcon("icons:container.png"),
307                                             tr("Create Container"), tr("Create a New Container"),
308                                             0, _parent, false, this,  SLOT(onNewContainer()));
309
310   _selectComponentInstanceAct = _wrapper->createAction(getMenuId(), tr("Select a Component Instance"), QIcon("icons:icon_select.png"),
311                                                        tr("Select a Component Instance"), tr("Select a Component Instance"),
312                                                        0, _parent, false, this,  SLOT(onSelectComponentInstance()));
313
314   _newSalomeComponentAct = _wrapper->createAction(getMenuId(), tr("Create a New SALOME Component Instance"), QIcon("icons:new_salome_component.png"),
315                                                   tr("Create Component Instance"), tr("Create a New SALOME Component Instance"),
316                                                   0, _parent, false, this,  SLOT(onNewSalomeComponent()));
317
318   _newSalomePythonComponentAct = _wrapper->createAction(getMenuId(), tr("Create a New SALOME Python Component"), QIcon("icons:new_salomepy_component.png"),
319                                                         tr("SALOME Python Component"), tr("Create a New SALOME Python Component"),
320                                                         0, _parent, false, this,  SLOT(onNewSalomePythonComponent()));
321
322   _newCorbaComponentAct = _wrapper->createAction(getMenuId(), tr("Create a New CORBA Component"), QIcon("icons:new_corba_component.png"),
323                                                  tr("CORBA Component"), tr("Create a New CORBA Component"),
324                                                  0, _parent, false, this,  SLOT(onNewCorbaComponent()));
325
326   _salomeServiceNodeAct = _wrapper->createAction(getMenuId(), tr("Create a New SALOME Service Node"), QIcon("icons:new_salome_service_node.png"),
327                                                  tr("SALOME Service Node"), tr("Create a New SALOME Service Node"),
328                                                  0, _parent, false, this,  SLOT(onSalomeServiceNode()));
329
330   _serviceInlineNodeAct = _wrapper->createAction(getMenuId(), tr("Create a New Inline Service Node"), QIcon("icons:new_service_inline_node.png"),
331                                                  tr("Inline Service Node"), tr("Create a New Inline Service Node"),
332                                                  0, _parent, false, this,  SLOT(onServiceInlineNode()));
333
334   _CORBAServiceNodeAct = _wrapper->createAction(getMenuId(), tr("Create a New CORBA Service Node"), QIcon("icons:new_corba_service_node.png"),
335                                                 tr("CORBA Node"), tr("Create a New CORBA Service Node"),
336                                                 0, _parent, false, this,  SLOT(onCORBAServiceNode()));
337
338   _nodeNodeServiceNodeAct = _wrapper->createAction(getMenuId(), tr("Create a New Node referencing a Node"), QIcon("icons:new_nodenode_service_node.png"),
339                                                    tr("Ref on Node"), tr("Create a New Node referencing a Node"),
340                                                    0, _parent, false, this,  SLOT(onNodeNodeServiceNode()));
341
342   _cppNodeAct = _wrapper->createAction(getMenuId(), tr("Create a New C++ Node"), QIcon("icons:new_cpp_node.png"),
343                                        tr("Cpp Node"), tr("Create a New C++ Node"),
344                                        0, _parent, false, this,  SLOT(onCppNode()));
345
346   _inDataNodeAct = _wrapper->createAction(getMenuId(), tr("Create a New Input data Node"), QIcon("icons:node.png"),
347                                           tr("Input Data Node"), tr("Create a New Input data Node"),
348                                           0, _parent, false, this,  SLOT(onInDataNode()));
349
350   _outDataNodeAct = _wrapper->createAction(getMenuId(), tr("Create a New Output data Node"), QIcon("icons:node.png"),
351                                            tr("Output Data Node"), tr("Create a New Output data Node"),
352                                            0, _parent, false, this,  SLOT(onOutDataNode()));
353
354   _inStudyNodeAct = _wrapper->createAction(getMenuId(), tr("Create a New Input Study Node"), QIcon("icons:node.png"),
355                                            tr("Input Study Node"), tr("Create a New Input Study Node"),
356                                            0, _parent, false, this,  SLOT(onInStudyNode()));
357
358   _outStudyNodeAct = _wrapper->createAction(getMenuId(), tr("Create a New Output Study Node"), QIcon("icons:node.png"),
359                                             tr("Output Study Node"), tr("Create a New Output Study Node"),
360                                             0, _parent, false, this,  SLOT(onOutStudyNode()));
361
362   _inlineScriptNodeAct = _wrapper->createAction(getMenuId(), tr("Create a New Inline Python Script Node"), QIcon("icons:new_inline_script_node.png"),
363                                                 tr("Inline Script Node"), tr("Create a New Inline Python Script Node"),
364                                                 0, _parent, false, this,  SLOT(onInlineScriptNode()));
365
366   _inlineFunctionNodeAct = _wrapper->createAction(getMenuId(), tr("Create a New Inline Python Function Node"), QIcon("icons:new_inline_function_node.png"),
367                                                   tr("Inline Function Node"), tr("Create a New Inline Python Function Node"),
368                                                   0, _parent, false, this,  SLOT(onInlineFunctionNode()));
369
370   _blockNodeAct = _wrapper->createAction(getMenuId(), tr("Create a New Bloc Node"), QIcon("icons:new_block_node.png"),
371                                          tr("bloc Node"), tr("Create a New Bloc Node"),
372                                          0, _parent, false, this,  SLOT(onBlockNode()));
373
374   _FORNodeAct = _wrapper->createAction(getMenuId(), tr("Create a New For Loop Node"), QIcon("icons:new_for_loop_node.png"),
375                                        tr("For Loop Node"), tr("Create a New For Loop Node"),
376                                        0, _parent, false, this,  SLOT(onFORNode()));
377
378   _FOREACHNodeAct = _wrapper->createAction(getMenuId(), tr("Create a New For Each Loop Node"), QIcon("icons:new_foreach_loop_node.png"),
379                                            tr("For Each Loop Node"), tr("Create a New For Each Loop Node"),
380                                            0, _parent, false, this,  SLOT(onFOREACHNode()));
381
382   _WHILENodeAct = _wrapper->createAction(getMenuId(), tr("Create a New While Loop Node"), QIcon("icons:new_while_loop_node.png"),
383                                          tr("While Loop Node"), tr("Create a New While Loop Node"),
384                                          0, _parent, false, this,  SLOT(onWHILENode()));
385
386   _SWITCHNodeAct = _wrapper->createAction(getMenuId(), tr("Create a New Switch Node"), QIcon("icons:new_switch_loop_node.png"),
387                                           tr("Switch Node"), tr("Create a New Switch Node"),
388                                           0, _parent, false, this,  SLOT(onSWITCHNode()));
389
390   _OptimizerLoopAct = _wrapper->createAction(getMenuId(), tr("Create a New Optimizer Loop Node"), QIcon("icons:new_for_loop_node.png"),
391                                              tr("Optimizer Loop"), tr("Create a New Optimizer Loop"),
392                                              0, _parent, false, this,  SLOT(onOptimizerLoop()));
393
394   _nodeFromCatalogAct = _wrapper->createAction(getMenuId(), tr("Create a New Node from Catalog, use drag and drop from catalog"), QIcon("icons:new_from_library_node.png"),
395                                                tr("Node from Catalog"), tr("Create a New Node from Catalog, use drag and drop from catalog"),
396                                                0, _parent, false, this,  SLOT(onNodeFromCatalog()));
397
398   _deleteItemAct = _wrapper->createAction(getMenuId(), tr("Delete a Schema Item"), QIcon("icons:delete.png"),
399                                           tr("Delete Item"), tr("Delete a Schema Item"),
400                                           0, _parent, false, this,  SLOT(onDeleteItem()));
401   _deleteItemAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_D); // --- QKeySequence::Delete dangerous...
402
403   _cutItemAct = _wrapper->createAction(getMenuId(), tr("Cut a Schema Item"), QIcon("icons:cut.png"),
404                                        tr("Cut Item"), tr("Cut a Schema Item"),
405                                        0, _parent, false, this,  SLOT(onCutItem()));
406   _cutItemAct->setShortcut(QKeySequence::Cut);
407
408   _copyItemAct = _wrapper->createAction(getMenuId(), tr("Copy a Schema Item"), QIcon("icons:copy.png"),
409                                         tr("Copy Item"), tr("Copy a Schema Item"),
410                                         0, _parent, false, this,  SLOT(onCopyItem()));
411   _copyItemAct->setShortcut(QKeySequence::Copy);
412
413   _pasteItemAct = _wrapper->createAction(getMenuId(), tr("Paste a Schema Item"), QIcon("icons:paste.png"),
414                                          tr("Paste Item"), tr("Paste a Schema Item"),
415                                          0, _parent, false, this,  SLOT(onPasteItem()));
416   _pasteItemAct->setShortcut(QKeySequence::Paste);
417
418   _putInBlocAct = _wrapper->createAction(getMenuId(), tr("Put node in block"), QIcon("icons:paste.png"),
419                                          tr("Put node in block"), tr("Put node in block"),
420                                          0, _parent, false, this,  SLOT(onPutInBloc()));
421
422   _putGraphInBlocAct = _wrapper->createAction(getMenuId(), tr("Bloc"), QIcon("icons:new_block_node.png"),
423                                               tr("Bloc"), tr("Bloc"),
424                                               0, _parent, false, this,  SLOT(onPutGraphInBloc()));
425
426   _putGraphInForLoopAct = _wrapper->createAction(getMenuId(), tr("For Loop"), QIcon("icons:new_for_loop_node.png"),
427                                                  tr("For Loop"), tr("For Loop"),
428                                                  0, _parent, false, this,  SLOT(onPutGraphInForLoop()));
429
430   _putGraphInWhileLoopAct = _wrapper->createAction(getMenuId(), tr("While Loop"), QIcon("icons:new_while_loop_node.png"),
431                                                    tr("While Loop"), tr("While Loop"),
432                                                    0, _parent, false, this,  SLOT(onPutGraphInWhileLoop()));
433
434   _putGraphInOptimizerLoopAct = _wrapper->createAction(getMenuId(), tr("Optimizer Loop"), QIcon("icons:new_for_loop_node.png"),
435                                                        tr("Optimizer Loop"), tr("Optimizer Loop"),
436                                                        0, _parent, false, this,  SLOT(onPutGraphInOptimizerLoop()));
437
438   _arrangeLocalNodesAct = _wrapper->createAction(getMenuId(), tr("arrange nodes on that bloc level, without recursion"), QIcon("icons:arrange_nodes.png"),
439                                                  tr("arrange local nodes"), tr("arrange nodes on that bloc level, without recursion"),
440                                                  0, _parent, false, this,  SLOT(onArrangeLocalNodes()));
441
442   _arrangeRecurseNodesAct = _wrapper->createAction(getMenuId(), tr("arrange nodes on that bloc level, with recursion"), QIcon("icons:sample.png"),
443                                                    tr("arrange nodes recursion"), tr("arrange nodes on that bloc level, with recursion"),
444                                                    0, _parent, false, this,  SLOT(onArrangeRecurseNodes()));
445
446   _computeLinkAct = _wrapper->createAction(getMenuId(), tr("compute orthogonal links"), QIcon("icons:rebuild_links.png"),
447                                            tr("compute links"), tr("compute orthogonal links"),
448                                            0, _parent, false, this,  SLOT(onRebuildLinks()));
449
450   _zoomToBlocAct = _wrapper->createAction(getMenuId(), tr("zoom 2D view to selected bloc"), QIcon("icons:zoomToBloc.png"),
451                                           tr("zoom to bloc"), tr("zoom 2D view to the selected composed node"),
452                                           0, _parent, false, this,  SLOT(onZoomToBloc()));
453
454   _centerOnNodeAct = _wrapper->createAction(getMenuId(), tr("center 2D view on selected node"), QIcon("icons:centerOnNode.png"),
455                                             tr("center on node"), tr("center 2D view on selected node"),
456                                             0, _parent, false, this,  SLOT(onCenterOnNode()));
457   _centerOnNodeAct->setShortcut(QKeySequence::Find);
458
459   _shrinkExpand = _wrapper->createAction(getMenuId(), tr("shrink or expand the selected node"), QIcon("icons:shrinkExpand.png"),
460                                             tr("shrink/expand"), tr("shrink or expand the selected node"),
461                                             0, _parent, false, this,  SLOT(onShrinkExpand()));
462
463   _toggleStraightLinksAct = _wrapper->createAction(getMenuId(), tr("draw straight or orthogonal links"), QIcon("icons:straightLink.png"),
464                                                    tr("straight/orthogonal"), tr("draw straight or orthogonal links"),
465                                                    0, _parent, true, this,  SLOT(onToggleStraightLinks(bool)));
466   
467   _toggleStraightLinksAct->setChecked(Resource::straightLinks);
468   onToggleStraightLinks(Resource::straightLinks);
469
470   _toggleAutomaticComputeLinkAct = _wrapper->createAction(getMenuId(), tr("compute othogonal links automatically when nodes move"), QIcon("icons:autoComputeLink.png"),
471                                                           tr("automatic link"), tr("compute othogonal links automatically when nodes move"),
472                                                           0, _parent, true, this,  SLOT(onToggleAutomaticComputeLinks(bool)));
473
474   _toggleAutomaticComputeLinkAct->setChecked(Resource::autoComputeLinks);
475   onToggleAutomaticComputeLinks(Resource::autoComputeLinks); // Why is this needed ?
476
477   _toggleSimplifyLinkAct = _wrapper->createAction(getMenuId(), tr("simplify links by removing unnecessary direction changes"), QIcon("icons:simplifyLink.png"),
478                                                   tr("simplify links"), tr("simplify links by removing unnecessary direction changes"),
479                                                   0, _parent, true, this,  SLOT(onToggleSimplifyLinks(bool)));
480   _toggleSimplifyLinkAct->setChecked(Resource::simplifyLink);
481   onToggleSimplifyLinks(Resource::simplifyLink);
482
483   _toggleForce2NodesLinkAct = _wrapper->createAction(getMenuId(), tr("force orthogonal links by adding an edge on simples links"), QIcon("icons:force2nodeLink.png"),
484                                                      tr("force ortho links"), tr("force orthogonal links by adding an edge on simples links"),
485                                                      0, _parent, true, this,  SLOT(onToggleForce2NodesLinks(bool)));
486   _toggleForce2NodesLinkAct->setChecked(true);
487
488   _toggleAddRowColsAct = _wrapper->createAction(getMenuId(), tr("allow more path for the links, for a better separation"), QIcon("icons:addRowCols.png"),
489                                                 tr("separate links"), tr("allow more path for the links, for a better separation"),
490                                                 0, _parent, true, this,  SLOT(onToggleAddRowCols(bool)));
491   _toggleAddRowColsAct->setChecked(Resource::addRowCols);
492   onToggleAddRowCols(Resource::addRowCols);
493
494   _selectReferenceAct = _wrapper->createAction(getMenuId(), tr("select reference"), QIcon("icons:ob_service_node.png"),
495                                                tr("select reference"), tr("select reference"),
496                                                0, _parent, false, this,  SLOT(onSelectReference()));
497
498   _whatsThisAct = _wrapper->createAction(getMenuId(), tr("active whatsThis Mode to get help on widgets"), QIcon("icons:whatsThis.png"),
499                                          tr("whatsThis Mode"), tr("active whatsThis Mode to get help on widgets"),
500                                          0, _parent, false, this,  SLOT(onWhatsThis()));
501   _whatsThisAct->setShortcut(QKeySequence::WhatsThis);
502
503   _withoutStopModeAct = _wrapper->createAction(getMenuId(), tr("set execution mode without stop"), QIcon("icons:run_active.png"),
504                                                tr("mode without stop"), tr("set execution mode without stop"),
505                                                0, _parent, true, this,  SLOT(onWithoutStopMode(bool)));
506
507   _breakpointsModeAct = _wrapper->createAction(getMenuId(), tr("set execution mode with stop on breakpoints"), QIcon("icons:breakpoints_active.png"),
508                                                tr("mode breakpoints"), tr("set execution mode with stop on breakpoints"),
509                                                0, _parent, true, this,  SLOT(onBreakpointsMode(bool)));
510
511   _stepByStepModeAct = _wrapper->createAction(getMenuId(), tr("set execution mode step by step"), QIcon("icons:step_by_step_active.png"),
512                                               tr("mode step by step"), tr("set execution mode step by step"),
513                                               0, _parent, true, this,  SLOT(onStepByStepMode(bool)));
514
515   _toggleStopOnErrorAct = _wrapper->createAction(getMenuId(), tr("Force stop on first error during execution"), QIcon("icons:toggle_stop_on_error.png"),
516                                                  tr("stop on error"), tr("Force stop on first error during execution"),
517                                                  0, _parent, true, this,  SLOT(onToggleStopOnError(bool)));
518
519   _toggleSceneItemVisibleAct = _wrapper->createAction(getMenuId(), tr("toggle 2D scene item visibility"), QIcon("icons:toggleVisibility.png"),
520                                                       tr("visible/hidden"), tr("toggle 2D scene item visibility"),
521                                                       0, _parent, true, this,  SLOT(onToggleSceneItemVisible(bool)));
522
523
524
525   _showAllLinksAct = _wrapper->createAction(getMenuId(), tr("Show all the links"), QIcon("icons:showLink.png"),
526                                             tr("show all links"), tr("Show all the links"),
527                                             0, _parent, false, this,  SLOT(onShowAllLinks()));
528
529   _hideAllLinksAct = _wrapper->createAction(getMenuId(), tr("Hide all the links"), QIcon("icons:hideLink.png"),
530                                             tr("hide all links"), tr("Hide all the links"),
531                                             0, _parent, false, this,  SLOT(onHideAllLinks()));
532   
533
534   _showOnlyPortLinksAct = _wrapper->createAction(getMenuId(), tr("Show only links from/to this port"), QIcon("icons:showLink.png"),
535                                                  tr("show only links"), tr("Show only links from/to this port"),
536                                                  0, _parent, false, this,  SLOT(onShowOnlyPortLinks()));
537
538   _showPortLinksAct = _wrapper->createAction(getMenuId(), tr("Show links from/to this port"), QIcon("icons:showLink.png"),
539                                              tr("show links"), tr("Show links from/to this port"),
540                                              0, _parent, false, this,  SLOT(onShowPortLinks()));
541
542   _hidePortLinksAct = _wrapper->createAction(getMenuId(), tr("Hide links from/to this port"), QIcon("icons:hideLink.png"),
543                                              tr("hide links"), tr("Hide links from/to this port"),
544                                              0, _parent, false, this,  SLOT(onHidePortLinks()));
545   
546   
547   _showOnlyCtrlLinksAct = _wrapper->createAction(getMenuId(), tr("Show only control links from/to this node"), QIcon("icons:showLink.png"),
548                                                  tr("show only Control links"), tr("Show only control links from/to this node"),
549                                                  0, _parent, false, this,  SLOT(onShowOnlyCtrlLinks()));
550
551   _showCtrlLinksAct = _wrapper->createAction(getMenuId(), tr("Show control links from/to this node"), QIcon("icons:showLink.png"),
552                                              tr("show control links"), tr("Show control links from/to this node"),
553                                              0, _parent, false, this,  SLOT(onShowCtrlLinks()));
554
555   _hideCtrlLinksAct = _wrapper->createAction(getMenuId(), tr("Hide control links from/to this node"), QIcon("icons:hideLink.png"),
556                                              tr("hide control links"), tr("Hide control links from/to this node"),
557                                              0, _parent, false, this,  SLOT(onHideCtrlLinks()));
558
559   
560   _showOnlyLinkAct = _wrapper->createAction(getMenuId(), tr("Show only this link"), QIcon("icons:showLink.png"),
561                                             tr("show only"), tr("Show only this link"),
562                                             0, _parent, false, this,  SLOT(onShowOnlyLink()));
563
564   _showLinkAct = _wrapper->createAction(getMenuId(), tr("Show this link"), QIcon("icons:showLink.png"),
565                                         tr("show"), tr("Show this link"),
566                                         0, _parent, false, this,  SLOT(onShowLink()));
567   
568   _hideLinkAct = _wrapper->createAction(getMenuId(), tr("Hide this link"), QIcon("icons:hideLink.png"),
569                                         tr("hide"), tr("Hide this link"),
570                                         0, _parent, false, this,  SLOT(onHideLink()));
571
572
573   _emphasisPortLinksAct = _wrapper->createAction(getMenuId(), tr("emphasis on links from/to this port"), QIcon("icons:emphasisLink.png"),
574                                                  tr("emphasize links"), tr("emphasis on links from/to this port"),
575                                                  0, _parent, false, this,  SLOT(onEmphasisPortLinks()));
576   
577   _emphasisCtrlLinksAct = _wrapper->createAction(getMenuId(), tr("emphasis on control links from/to this node"), QIcon("icons:emphasisLink.png"),
578                                                  tr("emphasize control links"), tr("emphasis on control links from/to this node"),
579                                                  0, _parent, false, this,  SLOT(onEmphasisCtrlLinks()));
580   
581   _emphasisLinkAct = _wrapper->createAction(getMenuId(), tr("emphasis on this link"), QIcon("icons:emphasisLink.png"),
582                                             tr("emphasize"), tr("emphasis on this link"),
583                                             0, _parent, false, this,  SLOT(onEmphasisLink()));
584
585   _deEmphasizeAllAct = _wrapper->createAction(getMenuId(), tr("remove all emphasis"), QIcon("icons:deEmphasisLink.png"),
586                                               tr("remove all emphasis"), tr("remove all emphasis"),
587                                               0, _parent, false, this,  SLOT(onDeEmphasizeAll()));
588   
589
590   _undoAct = _wrapper->createAction(getMenuId(), tr("undo last action"), QIcon("icons:undo.png"),
591                                     tr("undo"), tr("undo last action"),
592                                     0, _parent, false, this,  SLOT(onUndo()));
593   _undoAct->setShortcut(QKeySequence::Undo);
594   
595   _redoAct = _wrapper->createAction(getMenuId(), tr("redo last action"), QIcon("icons:redo.png"),
596                                     tr("redo"), tr("redo last action"),
597                                     0, _parent, false, this,  SLOT(onRedo()));
598   _redoAct->setShortcut(QKeySequence::Redo);
599   
600   _showUndoAct = _wrapper->createAction(getMenuId(), tr("show undo commands"), QIcon("icons:undo.png"),
601                                         tr("show undo"), tr("show undo commands"),
602                                         0, _parent, false, this,  SLOT(onShowUndo()));
603   
604   _showRedoAct = _wrapper->createAction(getMenuId(), tr("show redo commands"), QIcon("icons:redo.png"),
605                                         tr("show redo"), tr("show redo commands"),
606                                         0, _parent, false, this,  SLOT(onShowRedo()));
607   
608
609   _execModeGroup = new QActionGroup(this);
610   _execModeGroup->addAction(_withoutStopModeAct);
611   _execModeGroup->addAction(_breakpointsModeAct);
612   _execModeGroup->addAction(_stepByStepModeAct);
613   _withoutStopModeAct->setChecked(true);
614 }
615
616 void GenericGui::createMenus()
617 {
618   int aMenuId;
619   aMenuId = _wrapper->createMenu( tr( "File" ), -1, -1 );
620   _wrapper->createMenu( _wrapper->separator(), aMenuId, -1, 10 );
621   aMenuId = _wrapper->createMenu( "YACS", aMenuId, -1, 10 );
622   _wrapper->createMenu( _newSchemaAct, aMenuId );
623   _wrapper->createMenu( _importSchemaAct, aMenuId );
624
625   aMenuId = _wrapper->createMenu( "YACS", -1, -1, 30 );
626   _wrapper->createMenu( _newSchemaAct, aMenuId );//, 10
627   _wrapper->createMenu( _importSchemaAct, aMenuId );
628   _wrapper->createMenu( _importSupervSchemaAct, aMenuId );
629   _wrapper->createMenu( _wrapper->separator(), aMenuId);
630   _wrapper->createMenu( _exportSchemaAct, aMenuId );
631   _wrapper->createMenu( _exportSchemaAsAct, aMenuId );
632   _wrapper->createMenu( _wrapper->separator(), aMenuId);
633   _wrapper->createMenu( _runLoadedSchemaAct, aMenuId );
634   _wrapper->createMenu( _loadRunStateSchemaAct, aMenuId );
635   _wrapper->createMenu( _loadAndRunSchemaAct, aMenuId );
636   _wrapper->createMenu( _chooseBatchJobAct, aMenuId );
637   _wrapper->createMenu( _wrapper->separator(), aMenuId);
638   _wrapper->createMenu( _undoAct, aMenuId );
639   _wrapper->createMenu( _redoAct, aMenuId );
640   _wrapper->createMenu( _showUndoAct, aMenuId );
641   _wrapper->createMenu( _showRedoAct, aMenuId );
642   _wrapper->createMenu( _wrapper->separator(), aMenuId);
643   _wrapper->createMenu( _startResumeAct, aMenuId );
644   _wrapper->createMenu( _abortAct, aMenuId );
645   _wrapper->createMenu( _pauseAct, aMenuId );
646   _wrapper->createMenu( _resetAct, aMenuId );
647   _wrapper->createMenu( _wrapper->separator(), aMenuId);
648   _wrapper->createMenu( _saveRunStateAct, aMenuId );
649   //_wrapper->createMenu( _newEditionAct, aMenuId );
650   _wrapper->createMenu( _wrapper->separator(), aMenuId);
651   _wrapper->createMenu( _withoutStopModeAct, aMenuId );
652   _wrapper->createMenu( _breakpointsModeAct, aMenuId );
653   _wrapper->createMenu( _stepByStepModeAct, aMenuId );
654   _wrapper->createMenu( _wrapper->separator(), aMenuId);
655   _wrapper->createMenu( _toggleStopOnErrorAct, aMenuId );
656   _wrapper->createMenu( _wrapper->separator(), aMenuId);
657   _wrapper->createMenu( _importCatalogAct, aMenuId );
658   _wrapper->createMenu( _wrapper->separator(), aMenuId);
659   _wrapper->createMenu( _toggleStraightLinksAct, aMenuId );
660   _wrapper->createMenu( _toggleAutomaticComputeLinkAct, aMenuId );
661   _wrapper->createMenu( _toggleSimplifyLinkAct, aMenuId );
662   _wrapper->createMenu( _toggleForce2NodesLinkAct, aMenuId );
663   _wrapper->createMenu( _toggleAddRowColsAct, aMenuId );
664   _wrapper->createMenu( _wrapper->separator(), aMenuId);
665   _wrapper->createMenu( _showAllLinksAct, aMenuId );
666   _wrapper->createMenu( _hideAllLinksAct, aMenuId );
667   _wrapper->createMenu( _wrapper->separator(), aMenuId);
668   _wrapper->createMenu( _whatsThisAct, aMenuId );
669 }
670
671 void GenericGui::createTools()
672 {
673   int aToolId = _wrapper->createTool ( tr( "YACS Toolbar" ) );
674   _wrapper->createTool( _newSchemaAct, aToolId );
675   _wrapper->createTool( _importSchemaAct, aToolId );
676   _wrapper->createTool( _wrapper->separator(), aToolId );
677   _wrapper->createTool( _exportSchemaAct, aToolId );
678   _wrapper->createTool( _exportSchemaAsAct, aToolId );
679   _wrapper->createTool( _wrapper->separator(), aToolId);
680   _wrapper->createTool( _runLoadedSchemaAct, aToolId );
681   _wrapper->createTool( _loadRunStateSchemaAct, aToolId );
682   _wrapper->createTool( _loadAndRunSchemaAct, aToolId );
683   _wrapper->createTool( _chooseBatchJobAct, aToolId );
684   _wrapper->createTool( _wrapper->separator(), aToolId );
685   _wrapper->createTool( _undoAct, aToolId );
686   _wrapper->createTool( _redoAct, aToolId );
687   _wrapper->createTool( _wrapper->separator(), aToolId );
688   _wrapper->createTool( _startResumeAct, aToolId );
689   _wrapper->createTool( _abortAct, aToolId );
690   _wrapper->createTool( _pauseAct, aToolId );
691   _wrapper->createTool( _resetAct, aToolId );
692   _wrapper->createTool( _wrapper->separator(), aToolId );
693   _wrapper->createTool( _saveRunStateAct, aToolId );
694   //_wrapper->createTool( _newEditionAct, aToolId );
695   _wrapper->createTool( _withoutStopModeAct, aToolId );
696   _wrapper->createTool( _breakpointsModeAct, aToolId );
697   _wrapper->createTool( _stepByStepModeAct, aToolId );
698   _wrapper->createTool( _wrapper->separator(), aToolId );
699   _wrapper->createTool( _toggleStopOnErrorAct, aToolId );
700   _wrapper->createTool( _wrapper->separator(), aToolId );
701   _wrapper->createTool( _importCatalogAct, aToolId );
702   _wrapper->createTool( _wrapper->separator(), aToolId );
703   _wrapper->createTool( _toggleStraightLinksAct, aToolId );
704   _wrapper->createTool( _toggleAutomaticComputeLinkAct, aToolId );
705   _wrapper->createTool( _toggleSimplifyLinkAct, aToolId );
706   //_wrapper->createTool( _toggleForce2NodesLinkAct, aToolId );
707   _wrapper->createTool( _toggleAddRowColsAct, aToolId );
708   _wrapper->createTool( _wrapper->separator(), aToolId );
709   _wrapper->createTool( _showAllLinksAct, aToolId );
710   _wrapper->createTool( _hideAllLinksAct, aToolId );
711   _wrapper->createTool( _wrapper->separator(), aToolId );
712   _wrapper->createTool( _whatsThisAct, aToolId );
713 }
714
715 void GenericGui::initialMenus()
716 {
717   showEditionMenus(false);
718   showExecMenus(false);
719   showCommonMenus(false);
720   showBaseMenus(true);
721 }
722
723 void GenericGui::hideAllMenus()
724 {
725   showBaseMenus   (false);
726   showCommonMenus (false);
727   showEditionMenus(false);
728   showExecMenus   (false);
729 }
730
731 void GenericGui::showBaseMenus(bool show)
732 {
733   DEBTRACE("GenericGui::showBaseMenus " << show);
734   _wrapper->setMenuShown(_newSchemaAct, show);
735   _wrapper->setToolShown(_newSchemaAct, show);
736   _wrapper->setMenuShown(_importSchemaAct, show);
737   _wrapper->setToolShown(_importSchemaAct, show);
738   _wrapper->setMenuShown(_importSupervSchemaAct, show);
739   _wrapper->setMenuShown(_loadAndRunSchemaAct, show);
740   _wrapper->setToolShown(_loadAndRunSchemaAct, show);
741   _wrapper->setMenuShown(_chooseBatchJobAct, show);
742   _wrapper->setToolShown(_chooseBatchJobAct, show);
743   _wrapper->setMenuShown(_whatsThisAct, show);
744   _wrapper->setToolShown(_whatsThisAct, show);
745 }
746
747 void GenericGui::showEditionMenus(bool show)
748 {
749   DEBTRACE("GenericGui::showEditionMenus " << show);
750   _wrapper->setMenuShown(_exportSchemaAct, show);
751   _wrapper->setToolShown(_exportSchemaAct, show);
752   _wrapper->setMenuShown(_exportSchemaAsAct, show);
753   _wrapper->setToolShown(_exportSchemaAsAct, show);
754   _wrapper->setMenuShown(_runLoadedSchemaAct, show);
755   _wrapper->setToolShown(_loadRunStateSchemaAct, show);
756   _wrapper->setMenuShown(_loadRunStateSchemaAct, show);
757   _wrapper->setToolShown(_runLoadedSchemaAct, show);
758   _wrapper->setMenuShown(_undoAct, show);
759   _wrapper->setToolShown(_undoAct, show);
760   _wrapper->setMenuShown(_redoAct, show);
761   _wrapper->setToolShown(_redoAct, show);
762   _wrapper->setMenuShown(_showUndoAct, show);
763   _wrapper->setMenuShown(_showRedoAct, show);
764   _wrapper->setMenuShown(_importCatalogAct, show);
765   _wrapper->setToolShown(_importCatalogAct, show);
766 }
767
768 void GenericGui::showExecMenus(bool show)
769 {
770   DEBTRACE("GenericGui::showExecMenus " << show);
771   _wrapper->setMenuShown(_startResumeAct, show);
772   _wrapper->setToolShown(_startResumeAct, show);
773   _wrapper->setMenuShown(_abortAct, show);
774   _wrapper->setToolShown(_abortAct, show);
775   _wrapper->setMenuShown(_pauseAct, show);
776   _wrapper->setToolShown(_pauseAct, show);
777   _wrapper->setMenuShown(_resetAct, show);
778   _wrapper->setToolShown(_resetAct, show);
779   _wrapper->setMenuShown(_saveRunStateAct, show);
780   _wrapper->setToolShown(_saveRunStateAct, show);
781   //_wrapper->setMenuShown(_newEditionAct, show);
782   //_wrapper->setToolShown(_newEditionAct, show);
783   _wrapper->setMenuShown(_withoutStopModeAct, show);
784   _wrapper->setToolShown(_withoutStopModeAct, show);
785   _wrapper->setMenuShown(_breakpointsModeAct, show);
786   _wrapper->setToolShown(_breakpointsModeAct, show);
787   _wrapper->setMenuShown(_stepByStepModeAct, show);
788   _wrapper->setToolShown(_stepByStepModeAct, show);
789   _wrapper->setMenuShown(_toggleStopOnErrorAct, show);
790   _wrapper->setToolShown(_toggleStopOnErrorAct, show);
791 }
792
793 void GenericGui::showCommonMenus(bool show)
794 {
795   DEBTRACE("GenericGui::showCommonMenus " << show);
796   _wrapper->setMenuShown(_toggleStraightLinksAct, show);
797   _wrapper->setToolShown(_toggleStraightLinksAct, show);
798   _wrapper->setMenuShown(_toggleAutomaticComputeLinkAct, show);
799   _wrapper->setToolShown(_toggleAutomaticComputeLinkAct, show);
800   _wrapper->setMenuShown(_toggleSimplifyLinkAct, show);
801   _wrapper->setToolShown(_toggleSimplifyLinkAct, show);
802   _wrapper->setMenuShown(_toggleForce2NodesLinkAct, show);
803   //_wrapper->setToolShown(_toggleForce2NodesLinkAct, show);
804   _wrapper->setMenuShown(_toggleAddRowColsAct, show);
805   _wrapper->setToolShown(_toggleAddRowColsAct, show);
806   _wrapper->setMenuShown(_showAllLinksAct, show);
807   _wrapper->setToolShown(_showAllLinksAct, show);
808   _wrapper->setMenuShown(_hideAllLinksAct, show);
809   _wrapper->setToolShown(_hideAllLinksAct, show);
810 }
811
812 void GenericGui::switchContext(QWidget *view, bool onExit)
813 {
814   DEBTRACE("GenericGui::switchContext " << view);
815   if (! _mapViewContext.count(view))
816     {
817       onExit ? hideAllMenus() : initialMenus();
818       _dwTree->setWidget(0);
819       _dwStacked->setWidget(0);
820       return;
821     }
822   QtGuiContext* newContext = _mapViewContext[view];
823
824   _dwTree->setWidget(newContext->getEditTree());
825   _dwTree->widget()->show();
826   _dwTree->raise();
827   _dwStacked->setWidget(newContext->getStackedWidget());
828
829   QtGuiContext::setQtCurrent(newContext);
830
831   if (newContext->isEdition())
832     {
833       showExecMenus(false);
834       showBaseMenus(true);
835       showEditionMenus(true);
836       showCommonMenus(true);
837       if (_dwTree) _dwTree->setWindowTitle("Tree View: edition mode");
838     }
839   else
840     {
841       showEditionMenus(false);
842       showBaseMenus(true);
843       showExecMenus(true);
844       showCommonMenus(true);
845       _withoutStopModeAct->setChecked(true);
846       if (_dwTree) _dwTree->setWindowTitle("Tree View: execution mode");
847     }
848   _dwStacked->setMinimumWidth(10);
849 }
850
851 bool GenericGui::closeContext(QWidget *view, bool onExit)
852 {
853   DEBTRACE("GenericGui::closeContext " << onExit);
854   if (! _mapViewContext.count(view))
855     return true;
856   QtGuiContext* context = _mapViewContext[view];
857   switchContext(view);
858
859   bool tryToSave = false;
860
861   if (QtGuiContext::getQtCurrent()->isEdition())
862     {
863       if (!QtGuiContext::getQtCurrent()->_setOfModifiedSubjects.empty())
864         {
865           QMessageBox msgBox;
866           msgBox.setText("Some elements are modified and not taken into account.");
867           string info = "do you want to apply your changes ?\n";
868           info += " - Save    : do not take into account edition in progress,\n";
869           info += "             but if there are other modifications, select a file name for save\n";
870           info += " - Discard : discard all modifications and close the schema";
871           if (!onExit)
872             info += "\n - Cancel  : do not close the schema, return to edition";
873           msgBox.setInformativeText(info.c_str());
874           if (!onExit)
875             {
876               msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
877               msgBox.setDefaultButton(QMessageBox::Cancel);
878             }
879           else
880             {
881               msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
882               msgBox.setDefaultButton(QMessageBox::Save);
883             }
884           int ret = msgBox.exec();
885           switch (ret)
886             {
887             case QMessageBox::Save:
888               tryToSave = true;
889               break;
890             case QMessageBox::Discard:
891               tryToSave = false;
892               break;
893             case QMessageBox::Cancel:
894             default:
895               DEBTRACE("Cancel or default");
896               return false;
897               break;
898             }
899         }
900       else
901         if (QtGuiContext::getQtCurrent()->isNotSaved())
902           {
903             QMessageBox msgBox;
904             msgBox.setWindowTitle("Close the active schema");
905             msgBox.setText("The schema has been modified");
906             string info = "do you want to save the schema ?\n";
907             info += " - Save    : select a file name for save\n";
908             info += " - Discard : discard all modifications and close the schema";
909             if (!onExit)
910               info += "\n - Cancel  : do not close the schema, return to edition";
911             msgBox.setInformativeText(info.c_str());
912             if (!onExit)
913               {
914                 msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
915                 msgBox.setDefaultButton(QMessageBox::Cancel);
916               }
917             else
918               {
919                 msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
920                 msgBox.setDefaultButton(QMessageBox::Save);
921               }
922             int ret = msgBox.exec();
923             switch (ret)
924               {
925               case QMessageBox::Save:
926                 tryToSave = true;
927                 break;
928               case QMessageBox::Discard:
929                 tryToSave = false;
930                 break;
931               case QMessageBox::Cancel:
932                 DEBTRACE("Cancel or default");
933               default:
934                 return false;
935                 break;
936               }
937           }
938
939       if (tryToSave)
940         {
941           onExportSchemaAs();
942           if ((!onExit) && (!_isSaved)) // --- probably, user has cancelled the save dialog. Do not close
943             return false;
944         }
945     }
946
947   map<QWidget*, YACS::HMI::QtGuiContext*>::iterator it = _mapViewContext.begin();
948   QtGuiContext* newContext = 0;
949   QWidget* newView = 0;
950   for (; it != _mapViewContext.end(); ++it)
951     {
952       if ((*it).second != context)
953         {
954           newView = (*it).first;
955           newContext = (*it).second;
956           break;
957         }
958     }
959   int studyId = _wrapper->activeStudyId();
960   if (context->getStudyId() == studyId)
961     {
962       _wrapper->deleteSchema(view);
963       DEBTRACE("delete context");
964       if (GuiExecutor* exec = context->getGuiExecutor())
965         {
966           exec->closeContext();
967         }
968       delete context;
969       _mapViewContext.erase(view);
970       switchContext(newView, onExit);
971     }
972   return true;
973 }
974
975 void GenericGui::showDockWidgets(bool isVisible)
976 {
977   DEBTRACE("GenericGui::showDockWidgets " << isVisible);
978   if (_dwTree) _dwTree->setVisible(isVisible);
979   if (_dwTree) _dwTree->toggleViewAction()->setVisible(isVisible);
980   if (_dwStacked) _dwStacked->setVisible(isVisible);
981   if (_dwStacked) _dwStacked->toggleViewAction()->setVisible(isVisible);
982   if (_dwCatalogs) _dwCatalogs->setVisible(isVisible);
983   if (_dwCatalogs) _dwCatalogs->toggleViewAction()->setVisible(isVisible);
984 }
985
986 void GenericGui::raiseStacked()
987 {
988   if (_dwStacked) _dwStacked->raise();
989 }
990
991 std::list<std::string> GenericGui::getMachineList()
992 {
993   if (!_machineList.empty()) return _machineList;
994
995   YACS::ENGINE::RuntimeSALOME* runTime = YACS::ENGINE::getSALOMERuntime();
996   CORBA::ORB_ptr orb = runTime->getOrb();
997   if (!orb) return _machineList;
998
999   SALOME_NamingService namingService(orb);
1000   SALOME_LifeCycleCORBA lcc(&namingService);
1001
1002   CORBA::Object_var obj =
1003     namingService.Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
1004   if (CORBA::is_nil(obj)) return _machineList;
1005
1006   Engines::ResourcesManager_var resManager = Engines::ResourcesManager::_narrow(obj);
1007   if(!resManager) return _machineList;
1008
1009   Engines::ResourceParameters params;
1010   lcc.preSet(params);
1011
1012   Engines::ResourceList* resourceList =
1013     resManager->GetFittingResources(params);
1014
1015   for (int i = 0; i < resourceList->length(); i++)
1016   {
1017     const char* aResource = (*resourceList)[i];
1018     _machineList.push_back(aResource);
1019   }
1020
1021   return _machineList;
1022 }
1023
1024 // -----------------------------------------------------------------------------
1025
1026 /*! a QtGuiContext instance is created for each schema in edition or each execution or run
1027  *  of a schema. The context stores references of a lot of objects related to the edition
1028  *  or execution.
1029  *  \param proc       the schema to run or edit, loaded from file or just created empty.
1030  *  \param schemaName filename of the schema in edition, also used in execution to publish
1031  *                    a run under the edition name in Salome object browser.
1032  *  \param runName    filename of the schema in execution, not used in edition.
1033  *  \param forEdition if true, edition mode, if false, execution mode.
1034  */
1035 void GenericGui::createContext(YACS::ENGINE::Proc* proc,
1036                                const QString& schemaName,
1037                                const QString& runName,
1038                                bool forEdition)
1039 {
1040   DEBTRACE("GenericGui::createContext");
1041   clock_t  start_t;
1042   clock_t  end_t;
1043   start_t = clock();
1044
1045
1046   QWidget* central = _parent->centralWidget();
1047   if (central)
1048     central->setFocus();
1049   else
1050     DEBTRACE("No Central Widget");
1051
1052   QString fileName;
1053   QWidget* refWindow = 0; // --- used only on run to refer to the schema in edition
1054   if (forEdition)
1055     {
1056       fileName = schemaName;
1057     }
1058   else
1059     {
1060       fileName = runName;
1061       if (QtGuiContext::getQtCurrent())
1062         refWindow = QtGuiContext::getQtCurrent()->getWindow();
1063     }
1064
1065   QtGuiContext* context = new QtGuiContext(this);
1066   QtGuiContext::setQtCurrent(context);
1067
1068   // --- catalogs
1069
1070   context->setEdition(forEdition);
1071   context->setSessionCatalog(_sessionCatalog);
1072   context->setFileName(fileName);
1073   context->setCurrentCatalog(_builtinCatalog);
1074
1075   // --- scene, viewWindow & GraphicsView
1076
1077   Scene *scene = new Scene();
1078   QWidget *viewWindow = _wrapper->getNewWindow(scene);
1079   _mapViewContext[viewWindow] = context;
1080   GraphicsView* gView = new GraphicsView(viewWindow);
1081   gView->setScene(scene);
1082   gView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
1083   int studyId = _wrapper->AssociateViewToWindow(gView, viewWindow);
1084   context->setStudyId(studyId);
1085   std::ostringstream value;
1086   value << studyId;
1087   proc->setProperty("DefaultStudyID",value.str());
1088   context->setScene(scene);
1089   context->setView(gView);
1090   context->setWindow(viewWindow);
1091   gView->show();
1092
1093   // --- Schema Model
1094
1095   SchemaModel *schemaModel = new SchemaModel(context, viewWindow);
1096   schemaModel->setEdition(forEdition);
1097   context->setSchemaModel(schemaModel);
1098   RootSceneItem *rootSceneItem = new RootSceneItem(context);
1099
1100   // --- tree associated to model
1101
1102   FormEditTree *editTree = new FormEditTree(_dwTree);
1103   editTree->setMinimumHeight(400);
1104   _dwTree->setWidget(editTree);
1105   editTree->show();
1106   context->setEditTree(editTree);
1107   editTree->tv_schema->setModel(schemaModel);
1108   context->setSelectionModel(editTree->tv_schema->selectionModel());
1109   _dwTree->raise();
1110
1111   QObject::connect(editTree->tv_schema->selectionModel(),
1112                    SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
1113                    schemaModel,
1114                    SLOT(updateSelection(const QItemSelection &, const QItemSelection &)));
1115
1116   // --- stacked widget
1117
1118   QStackedWidget *stacked = new QStackedWidget(_dwStacked);
1119   _dwStacked->setWidget(stacked);
1120   context->setStackedWidget(stacked);
1121   YACS::HMI::ItemEditionRoot* rootEdit = new YACS::HMI::ItemEditionRoot(context,
1122                                                                         0,
1123                                                                         context->getName().c_str());
1124   context->setEditionRoot(rootEdit);
1125
1126   QObject::connect(schemaModel,
1127                    SIGNAL(signalSelection(const QModelIndex &)),
1128                    editTree->tv_schema,
1129                    SLOT(viewSelection(const QModelIndex &)));
1130
1131   // --- load schema
1132
1133   proc->setEdition(forEdition);
1134
1135   {
1136     end_t = clock();
1137     double passe =  (end_t -start_t);
1138     passe = passe/CLOCKS_PER_SEC;
1139     DEBTRACE("create context -1- : " << passe);
1140     start_t = end_t;
1141   }
1142
1143   context->setLoading(true);
1144
1145   context->setProc(proc);
1146   setLoadedPresentation(proc);
1147
1148   {
1149     end_t = clock();
1150     double passe =  (end_t -start_t);
1151     passe = passe/CLOCKS_PER_SEC;
1152     DEBTRACE("create context - load proc- : " << passe);
1153     start_t = end_t;
1154   }
1155
1156   context->setLoading(false);
1157
1158   if (forEdition && _wrapper)  // --- Edition mode
1159     {
1160       _wrapper->createNewSchema(fileName, viewWindow);
1161     }
1162   else if (_wrapper)           // --- Execution Mode
1163     {
1164       GuiExecutor *guiExec = new GuiExecutor(proc);
1165       context->setGuiExecutor(guiExec);
1166       _wrapper->createNewRun(schemaName, fileName, refWindow, viewWindow);
1167     }
1168
1169
1170   QtGuiContext::getQtCurrent()->getSubjectProc()->update(UPDATE,
1171                                                          ProcInvoc::getTypeOfNode(proc),
1172                                                          0); // --- force validity check
1173
1174   // --- adjust widgets
1175
1176   TreeView *vtree = dynamic_cast<TreeView*>(editTree->tv_schema);
1177   YASSERT(vtree);
1178   vtree->resizeColumns();
1179   _catalogsWidget->setMinimumWidth(10); // --- reset the constraint on width
1180   editTree->setMinimumHeight(40);
1181   _dwStacked->setMinimumWidth(10);
1182   // --- show menus
1183
1184   if (forEdition)
1185     {
1186       showExecMenus(false);
1187       showEditionMenus(true);
1188       showCommonMenus(true);
1189       if (_dwTree) _dwTree->setWindowTitle("Tree View: edition mode");
1190     }
1191   else
1192     {
1193       showEditionMenus(false);
1194       showExecMenus(true);
1195       showCommonMenus(true);
1196       _withoutStopModeAct->setChecked(true);
1197       if (_dwTree) _dwTree->setWindowTitle("Tree View: execution mode");
1198     }
1199
1200   QtGuiContext::getQtCurrent()->setNotSaved(false);
1201   {
1202     end_t = clock();
1203     double passe =  (end_t -start_t);
1204     passe = passe/CLOCKS_PER_SEC;
1205     DEBTRACE("create context - end - : " << passe);
1206     start_t = end_t;
1207   }
1208 }
1209
1210 // -----------------------------------------------------------------------------
1211
1212 void GenericGui::setLoadedPresentation(YACS::ENGINE::Proc* proc)
1213 {
1214   DEBTRACE("GenericGui::setLoadedPresentation");
1215   QtGuiContext::getQtCurrent()->setLoadingPresentation(true);
1216   map<SceneNodeItem*, QPointF> nodesToMove;
1217   map<YACS::ENGINE::Node*, PrsData> presNodes = _loader->getPrsData(proc);
1218   if (!presNodes.empty())
1219     {
1220       map<YACS::ENGINE::Node*, PrsData>::iterator it = presNodes.begin();
1221       for (; it!= presNodes.end(); ++it)
1222         {
1223           YACS::ENGINE::Node* node = (*it).first;
1224           PrsData pres = (*it).second;
1225           SubjectNode *snode = QtGuiContext::getQtCurrent()->_mapOfSubjectNode[node];
1226           SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[snode];
1227           YASSERT(item);
1228           SceneNodeItem *inode = dynamic_cast<SceneNodeItem*>(item);
1229           YASSERT(inode);
1230           inode->setPos(QPointF(pres._x, pres._y));
1231           inode->setWidth(pres._width);
1232           inode->setHeight(pres._height);
1233           inode->setExpanded(pres._expanded);
1234           QPointF anExpandedPos = QPointF(pres._expx, pres._expy);
1235           if (anExpandedPos.isNull())
1236               anExpandedPos = inode->pos();
1237           inode->setExpandedPos(anExpandedPos);
1238           inode->setExpandedWH(pres._expWidth, pres._expHeight);
1239           inode->setShownState(shownState(pres._shownState));
1240
1241           // collect nodes to correct it's Y-position if this collides with parent's header
1242           if (inode->getParent() ) {
1243               qreal anX = inode->x();
1244               qreal anY = inode->y();
1245               if (inode->getShownState() == shrinkHidden) {
1246                 anX = inode->getExpandedX();
1247                 anY = inode->getExpandedY();
1248               }
1249               if (anY < inode->getParent()->getHeaderBottom())
1250                 nodesToMove[inode] = QPointF(anX, inode->getParent()->getHeaderBottom()+1);
1251             }
1252         }
1253     }
1254   QtGuiContext::getQtCurrent()->setLoadingPresentation(false);
1255   
1256   //after loading of presentation:
1257
1258   //move nodes because of progress bar, if any was added
1259   map<SceneNodeItem*, QPointF>::iterator it = nodesToMove.begin();
1260   for (; it!= nodesToMove.end(); ++it)
1261     {
1262       (*it).first->setTopLeft((*it).second);
1263     }
1264
1265   //update links
1266   if (Scene::_autoComputeLinks)
1267     _guiEditor->rebuildLinks();
1268   else
1269     {
1270       YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
1271       SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
1272       SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
1273       proc->updateLinks();
1274     }
1275 }
1276
1277 // -----------------------------------------------------------------------------
1278
1279 void GenericGui::onNewSchema()
1280 {
1281   DEBTRACE("GenericGui::onNewSchema");
1282
1283   std::stringstream name;
1284   name << "newSchema_" << ++_schemaCnt;
1285
1286   YACS::ENGINE::RuntimeSALOME* runTime = YACS::ENGINE::getSALOMERuntime();
1287   YACS::ENGINE::Proc *proc = runTime->createProc(name.str());
1288
1289   _loader->reset();
1290
1291   QString fileName = name.str().c_str();
1292   createContext(proc, fileName, "", true);
1293 }
1294
1295 void GenericGui::loadSchema(const std::string& filename,bool edit, bool arrangeLocalNodes)
1296 {
1297   YACS::ENGINE::Proc *proc = _loader->load(filename.c_str());
1298   if (!proc)
1299     return;
1300   YACS::ENGINE::Logger* logger= proc->getLogger("parser");
1301   if(!logger->isEmpty())
1302     {
1303       DEBTRACE(logger->getStr());
1304     }
1305   QString fn=QString::fromUtf8(filename.c_str());
1306   if(edit)
1307     createContext(proc, fn, "", true);
1308   else
1309     createContext(proc, fn, fn, false);
1310   if (arrangeLocalNodes)
1311   {
1312     _guiEditor->arrangeProc();
1313   }
1314 }
1315
1316 void GenericGui::onImportSchema()
1317 {
1318   clock_t  start_t;
1319   clock_t  end_t;
1320   start_t = clock();
1321   DEBTRACE("GenericGui::onImportSchema");
1322   QFileDialog dialog(_parent,
1323                      "Choose a filename to load" ,
1324                      QString::null,
1325                      tr( "XML-Files (*.xml);;All Files (*)" ));
1326
1327   dialog.setHistory(_wrapper->getQuickDirList());
1328
1329   QString fn;
1330   QStringList fileNames;
1331   if (dialog.exec())
1332     {
1333       fileNames = dialog.selectedFiles();
1334       if (!fileNames.isEmpty())
1335         fn = fileNames.first();
1336     }
1337
1338   if ( !fn.isEmpty() )
1339     {
1340       // add ".xml" suffix
1341       QFileInfo fi(fn);
1342       if (!fi.exists() && fi.suffix() != "xml")
1343         fn += ".xml";
1344
1345       DEBTRACE("file loaded : " <<fn.toUtf8().constData());
1346       YACS::ENGINE::Proc *proc = 0;
1347
1348       try {
1349          proc = _loader->load(fn.toUtf8().constData());
1350       }
1351       catch (...) {
1352       }
1353       
1354       {
1355         end_t = clock();
1356         double passe =  (end_t -start_t);
1357         passe = passe/CLOCKS_PER_SEC;
1358         DEBTRACE("load xml file : " << passe);
1359         start_t = end_t;
1360       }
1361
1362       if (!proc)
1363         {
1364           QMessageBox msgBox(QMessageBox::Critical,
1365                              "Import YACS Schema, native YACS XML format",
1366                              "The file has not the native YACS XML format or is not readable.");
1367           msgBox.exec();
1368           return;
1369         }
1370       YACS::ENGINE::Logger* logger= proc->getLogger("parser");
1371       if(!logger->isEmpty())
1372         {
1373           DEBTRACE(logger->getStr());
1374         }
1375       createContext(proc, fn, "", true);
1376     }
1377 }
1378
1379 void GenericGui::onImportSupervSchema()
1380 {
1381   DEBTRACE("GenericGui::onImportSupervSchema");
1382   QFileDialog dialog(_parent,
1383                      "Choose a  SUPERV filename to load" ,
1384                      QString::null,
1385                      tr( "XML-Files (*.xml);;All Files (*)" ));
1386
1387   dialog.setHistory(_wrapper->getQuickDirList());
1388
1389   QString fn;
1390   QStringList fileNames;
1391   if (dialog.exec())
1392     {
1393       fileNames = dialog.selectedFiles();
1394       if (!fileNames.isEmpty())
1395         fn = fileNames.first();
1396     }
1397
1398   if (fn.isEmpty()) return;
1399
1400   // add ".xml" suffix
1401   QFileInfo fi(fn);
1402   if (!fi.exists() && fi.suffix() != "xml")
1403     fn += ".xml";
1404
1405   DEBTRACE("file loaded : " <<fn.toStdString());
1406   QString tmpFileName;
1407   try
1408     {
1409 #ifdef WIN32
1410       QString tmpDir = getenv("TEMP");
1411           QString fileExt = "bat";
1412 #else
1413       QString tmpDir = "/tmp";
1414           QString fileExt = "sh";
1415 #endif
1416       QDir aTmpDir(tmpDir);
1417       aTmpDir.mkdir(QString("YACS_") + getenv("USER"));
1418       YASSERT(aTmpDir.cd(QString("YACS_") + getenv("USER")));
1419       QDateTime curTime = QDateTime::currentDateTime();   
1420       tmpFileName = "SUPERV_import_" + curTime.toString("yyyyMMdd_hhmmss") + ".xml";
1421       QString tmpOutput = "salomeloader_output";
1422       tmpFileName = aTmpDir.absoluteFilePath(tmpFileName);
1423       DEBTRACE(tmpFileName.toStdString());
1424       
1425       QString aCall = "salomeloader."+ fileExt+ " "+ fn + " " + tmpFileName + " > " + tmpOutput;
1426       DEBTRACE(aCall.toStdString());
1427       
1428       int ret = system(aCall.toAscii());
1429       if(ret != 0)
1430         {
1431           // --- read file with logs
1432           fstream f(tmpOutput.toAscii());
1433           stringstream hfile;
1434           hfile << f.rdbuf();
1435           f.close();
1436           
1437           // --- Problem in execution
1438           int status=WEXITSTATUS(ret);
1439           if(status == 1)
1440             {
1441               QString mes = "Problems in conversion: some errors but an incomplete proc has nevertheless been created.\n\n";
1442               mes += QString(hfile.str().c_str());
1443               QMessageBox msgBox(QMessageBox::Warning,
1444                                  "Import YACS Schema, SUPERV XML format",
1445                                  mes);
1446               msgBox.exec();
1447             }
1448           else if(status == 2)
1449             {
1450               QString mes = "Problems in conversion: a fatal error has been encountered. The proc can't be created.\n\n";
1451               mes += QString(hfile.str().c_str());
1452               QMessageBox msgBox(QMessageBox::Critical,
1453                                  "Import YACS Schema, SUPERV XML format",
1454                                  mes);
1455               msgBox.exec();
1456               return;
1457             }
1458           else
1459             {
1460               DEBTRACE("Unknown problem: " << ret );
1461               QMessageBox msgBox(QMessageBox::Critical,
1462                                  "Import YACS Schema, SUPERV XML format",
1463                                  "Unexpected exception in salomeloader.");
1464               msgBox.exec();
1465               return;
1466             }
1467         }
1468     }
1469   catch(...)
1470     {
1471       QMessageBox msgBox(QMessageBox::Critical,
1472                          "Import YACS Schema, SUPERV XML format",
1473                          "Unexpected exception in convertSupervFile");
1474       msgBox.exec();
1475       return;
1476     }
1477
1478   fn = tmpFileName;
1479   if (fn.isEmpty()) return; // must not happen
1480
1481   DEBTRACE("file loaded : " <<fn.toStdString());
1482   YACS::ENGINE::Proc *proc = _loader->load(fn.toLatin1());
1483   if (!proc)
1484     {
1485       QMessageBox msgBox(QMessageBox::Critical,
1486                          "Import YACS Schema, SUPERV file converted in native YACS XML format",
1487                          "The file has not the native YACS XML format or is not readable.");
1488       msgBox.exec();
1489       return;
1490     }
1491   YACS::ENGINE::Logger* logger= proc->getLogger("parser");
1492   if(!logger->isEmpty())
1493     {
1494       DEBTRACE(logger->getStr());
1495     }
1496   createContext(proc, fn, "", true);
1497 }
1498
1499 //! bug confirmOverwrite : correction Qt 4.3.5
1500 QString GenericGui::getSaveFileName(const QString& fileName)
1501 {
1502   QFileDialog dialog(_parent, "Save schema", fileName);
1503   QStringList filters;
1504   filters << "XML files (*.xml)"
1505           << "Any files (*)";
1506   dialog.setFileMode(QFileDialog::AnyFile);
1507   dialog.setFilters(filters);
1508   dialog.selectFilter("(*.xml)");
1509   dialog.setDefaultSuffix("xml");
1510   dialog.setConfirmOverwrite(true);
1511   //dialog.setConfirmOverwrite(false);  // bug Qt4.3.3
1512   dialog.setAcceptMode(QFileDialog::AcceptSave);
1513   QString selectedFile;
1514   QStringList fileNames;
1515   fileNames.clear();
1516   if (bool ret = dialog.exec())
1517     {
1518       DEBTRACE(ret << " " << dialog.confirmOverwrite());
1519       fileNames = dialog.selectedFiles();
1520       if (!fileNames.isEmpty())
1521         selectedFile = fileNames.first();
1522     }
1523   QString filteredName = _guiEditor->asciiFilter(selectedFile);
1524   DEBTRACE(filteredName.toStdString());
1525   return filteredName;
1526 }
1527
1528 void GenericGui::onExportSchema()
1529 {
1530   DEBTRACE("GenericGui::onExportSchema");
1531   if (!QtGuiContext::getQtCurrent()) return;
1532   YACS::ENGINE::Proc* proc = QtGuiContext::getQtCurrent()->getProc();
1533   QString fo = QtGuiContext::getQtCurrent()->getFileName();
1534   QString foo = fo;
1535   QString fn = fo;
1536   if (fo.startsWith("newSchema_"))
1537     {
1538       fo.clear();
1539       fn = getSaveFileName(fo);
1540     }
1541   if (fn.isEmpty()) return;
1542
1543   DEBTRACE("GenericGui::onExportSchema: " << fn.toUtf8().constData());
1544   //to be sure that all pending changes are effective
1545   _parent->setFocus();
1546   QtGuiContext::getQtCurrent()->setFileName(fn);
1547   VisitorSaveGuiSchema aWriter(proc);
1548   aWriter.openFileSchema( fn.toUtf8().constData() );
1549   aWriter.visitProc();
1550   aWriter.closeFileSchema();
1551   QtGuiContext::getQtCurrent()->setNotSaved(false);
1552
1553   if (fn.compare(foo) && _wrapper)
1554     _wrapper->renameSchema(foo, fn, QtGuiContext::getQtCurrent()->getWindow());
1555 }
1556
1557 void GenericGui::onExportSchemaAs()
1558 {
1559   DEBTRACE("GenericGui::onExportSchemaAs");
1560   _isSaved = false;
1561   if (!QtGuiContext::getQtCurrent()) return;
1562   YACS::ENGINE::Proc* proc = QtGuiContext::getQtCurrent()->getProc();
1563   QString fo = QtGuiContext::getQtCurrent()->getFileName();
1564   QString foo = fo;
1565   if (fo.startsWith("newSchema_")) fo.clear();
1566   QString fn = getSaveFileName(fo);
1567   if (fn.isEmpty()) return;
1568
1569   DEBTRACE("GenericGui::onExportSchemaAs: " << fn.toUtf8().constData());
1570   QtGuiContext::getQtCurrent()->setFileName(fn);
1571   VisitorSaveGuiSchema aWriter(proc);
1572   aWriter.openFileSchema(fn.toUtf8().constData());
1573   aWriter.visitProc();
1574   aWriter.closeFileSchema();
1575   _isSaved = true;
1576   QtGuiContext::getQtCurrent()->setNotSaved(false);
1577
1578   if (fn.compare(foo) && _wrapper)
1579     _wrapper->renameSchema(foo, fn, QtGuiContext::getQtCurrent()->getWindow());
1580 }
1581
1582 void GenericGui::onImportCatalog()
1583 {
1584   DEBTRACE("GenericGui::onImportCatalog");
1585   QFileDialog dialog(_parent,
1586                      "Choose a YACS Schema to load as a Catalog" ,
1587                      QString::null,
1588                      tr( "XML-Files (*.xml);;All Files (*)" ));
1589
1590   dialog.setHistory(_wrapper->getQuickDirList());
1591
1592   QString fn;
1593   QStringList fileNames;
1594   if (dialog.exec())
1595     {
1596       fileNames = dialog.selectedFiles();
1597       if (!fileNames.isEmpty())
1598         fn = fileNames.first();
1599     }
1600
1601   if ( !fn.isEmpty() )
1602     _catalogsWidget->addCatalogFromFile(fn.toStdString());
1603 }
1604   
1605 void GenericGui::onRunLoadedSchema(bool withState)
1606 {
1607   DEBTRACE("GenericGui::onRunLoadedSchema");
1608   if (!QtGuiContext::getQtCurrent()) return;
1609
1610   clock_t  start_t;
1611   clock_t  end_t;
1612   start_t = clock();
1613
1614   // --- check proc state (cf. editionProc)
1615
1616   if (!QtGuiContext::getQtCurrent()->_setOfModifiedSubjects.empty())
1617     {
1618       set<Subject*>::iterator it = QtGuiContext::getQtCurrent()->_setOfModifiedSubjects.begin();
1619       (*it)->select(true);
1620       return;
1621     }
1622
1623   YACS::ENGINE::Proc* proc = QtGuiContext::getQtCurrent()->getProc();
1624   if (!proc->isValid())
1625     {
1626       QtGuiContext::getQtCurrent()->getSubjectProc()->select(true);
1627       return;
1628     }
1629
1630   YACS::ENGINE::LinkInfo info(YACS::ENGINE::LinkInfo::ALL_STOP_ASAP);
1631   try
1632     {
1633       proc->checkConsistency(info);
1634     }
1635   catch (Exception &ex)
1636     {
1637       DEBTRACE(ex.what());
1638       QtGuiContext::getQtCurrent()->getSubjectProc()->select(true);
1639       return;
1640     }
1641   if (info.areWarningsOrErrors()) return;
1642  
1643   {
1644     end_t = clock();
1645     double passe =  (end_t -start_t);
1646     passe = passe/CLOCKS_PER_SEC;
1647     cerr <<"run schema -1- : " << passe << endl;
1648     start_t = end_t;
1649   }
1650   // --- save proc under a run name
1651
1652   QFileInfo fo = QtGuiContext::getQtCurrent()->getFileName();
1653   QString procName = fo.baseName();
1654   //QString tmpDir = SALOMEDS_Tool::GetTmpDir().c_str();
1655 #ifdef WIN32
1656   QString tmpDir = getenv("TEMP");
1657 #else
1658   QString tmpDir = "/tmp";
1659 #endif
1660   QDir aTmpDir(tmpDir);
1661   aTmpDir.mkdir(QString("YACS_") + getenv("USER"));
1662   YASSERT(aTmpDir.cd(QString("YACS_") + getenv("USER")));
1663   QDateTime curTime = QDateTime::currentDateTime();   
1664   QString aRunName = procName + "_" + curTime.toString("yyyyMMdd_hhmmss") + ".xml";
1665   aRunName = aTmpDir.absoluteFilePath(aRunName);
1666   DEBTRACE(aRunName.toStdString());
1667
1668   VisitorSaveGuiSchema aWriter(proc);
1669   aWriter.openFileSchema(aRunName.toStdString());
1670   aWriter.visitProc();
1671   aWriter.closeFileSchema();
1672
1673   // --- create a run context
1674
1675   YACS::ENGINE::Proc *procrun = _loader->load(aRunName.toLatin1());
1676   {
1677     end_t = clock();
1678     double passe =  (end_t -start_t);
1679     passe = passe/CLOCKS_PER_SEC;
1680     cerr <<"run schema -2- : " << passe << endl;
1681     start_t = end_t;
1682   }
1683   createContext(procrun, QtGuiContext::getQtCurrent()->getFileName(), aRunName, false);
1684
1685   // load state if required
1686
1687   GuiExecutor *executor = QtGuiContext::getQtCurrent()->getGuiExecutor();
1688   if (!executor) return;
1689   if (withState)
1690     {
1691       QString fn = QFileDialog::getOpenFileName( _parent,
1692                                                  "Choose a previous run state to load" ,
1693                                                  QString::null,
1694                                                  tr( "XML-Files (*.xml);;All Files (*)" ));
1695       if (!fn.isEmpty())
1696         {
1697           DEBTRACE("run state to load: " <<fn.toStdString());
1698           executor->setLoadStateFile(fn.toStdString());
1699         }
1700     }
1701   executor->startResumeDataflow(true); // --- initialise gui state
1702   if(_toggleStopOnErrorAct->isChecked())
1703     executor->setStopOnError(false);
1704 }
1705
1706 void GenericGui::onLoadRunStateSchema()
1707 {
1708   DEBTRACE("GenericGui::onLoadRunStateSchema");
1709   onRunLoadedSchema(true);
1710 }
1711
1712 void GenericGui::onLoadAndRunSchema()
1713 {
1714   DEBTRACE("GenericGui::onLoadAndRunSchema");
1715   QString fn = QFileDialog::getOpenFileName( _parent,
1716                                              "Choose a filename to load" ,
1717                                              QString::null,
1718                                              tr( "XML-Files (*.xml);;All Files (*)" ));
1719   if ( !fn.isEmpty() )
1720     {
1721       // add ".xml" suffix
1722       QFileInfo fi(fn);
1723       if (!fi.exists() && fi.suffix() != "xml")
1724         fn += ".xml";
1725
1726       DEBTRACE("file loaded : " <<fn.toStdString());
1727       YACS::ENGINE::Proc *proc =0;
1728       
1729       try {
1730          proc = _loader->load(fn.toLatin1());
1731       }
1732       catch (...) {
1733       }
1734       
1735       if (!proc)
1736         {
1737           QMessageBox msgBox(QMessageBox::Critical,
1738                              "Import YACS Schema, native YACS XML format",
1739                              "The file has not the native YACS XML format or is not readable.");
1740           msgBox.exec();
1741           return;
1742         }
1743       YACS::ENGINE::Logger* logger= proc->getLogger("parser");
1744       if(!logger->isEmpty())
1745         {
1746           DEBTRACE(logger->getStr());
1747         }
1748       createContext(proc, fn, "", true);
1749       onRunLoadedSchema();
1750     }
1751 }
1752
1753 void GenericGui::onChooseBatchJob() {
1754   DEBTRACE("GenericGui::onChooseBatchJob");
1755
1756   // Show the Batch Jobs list
1757   if(_BJLdialog) delete _BJLdialog;
1758   _BJLdialog = new BatchJobsListDialog(tr("Select one Batch Job to watch"),this);
1759   _BJLdialog->show();
1760   _BJLdialog->move(300,200);
1761   _BJLdialog->resize(450,200);
1762
1763 }
1764
1765 void GenericGui::onStartResume()
1766 {
1767   DEBTRACE("GenericGui::onStartResume");
1768   if (!QtGuiContext::getQtCurrent()) return;
1769   if (!QtGuiContext::getQtCurrent()->getGuiExecutor()) return;
1770   QtGuiContext::getQtCurrent()->getGuiExecutor()->startResumeDataflow();
1771 }
1772
1773 void GenericGui::onAbort()
1774 {
1775   DEBTRACE("GenericGui::onAbort");
1776   if (!QtGuiContext::getQtCurrent()) return;
1777   if (!QtGuiContext::getQtCurrent()->getGuiExecutor()) return;
1778   QtGuiContext::getQtCurrent()->getGuiExecutor()->killDataflow();
1779 }
1780
1781 void GenericGui::onPause()
1782 {
1783   DEBTRACE("GenericGui::onPause");
1784   if (!QtGuiContext::getQtCurrent()) return;
1785   if (!QtGuiContext::getQtCurrent()->getGuiExecutor()) return;
1786   QtGuiContext::getQtCurrent()->getGuiExecutor()->suspendDataflow();
1787 }
1788
1789 void GenericGui::onReset()
1790 {
1791   DEBTRACE("GenericGui::onReset");
1792   if (!QtGuiContext::getQtCurrent()) return;
1793   if (!QtGuiContext::getQtCurrent()->getGuiExecutor()) return;
1794   QtGuiContext::getQtCurrent()->getGuiExecutor()->resetDataflow();
1795 }
1796
1797 void GenericGui::onSaveRunState()
1798 {
1799   DEBTRACE("GenericGui::onSaveRunState");
1800   if (!QtGuiContext::getQtCurrent()) return;
1801   if (!QtGuiContext::getQtCurrent()->getGuiExecutor()) return;
1802   QDateTime curTime = QDateTime::currentDateTime(); 
1803   QFileInfo procName = QtGuiContext::getQtCurrent()->getFileName();
1804   QString stateName = procName.baseName();
1805   DEBTRACE(stateName.toStdString());
1806   stateName += "_state_" + curTime.toString("yyyyMMdd_hhmmss") + ".xml";
1807   DEBTRACE(stateName.toStdString());
1808   stateName = getSaveFileName(stateName);
1809   DEBTRACE(stateName.toStdString());
1810   if (!stateName.isEmpty())
1811     QtGuiContext::getQtCurrent()->getGuiExecutor()->saveState(stateName.toStdString());
1812 }
1813
1814 void GenericGui::onNewEdition()
1815 {
1816   DEBTRACE("GenericGui::onNewEdition");
1817   //   if (!QtGuiContext::getQtCurrent()) return;
1818   //   if (!QtGuiContext::getQtCurrent()->getGuiExecutor()) return;
1819   //   QtGuiContext::getQtCurrent()->getGuiExecutor()->resetDataflow();
1820 }
1821
1822 void GenericGui::onGetYacsContainerLog()
1823 {
1824   DEBTRACE("GenericGui::onGetYacsContainerLog");
1825   if (!QtGuiContext::getQtCurrent()) return;
1826   if (!QtGuiContext::getQtCurrent()->getGuiExecutor()) return;
1827   string log = QtGuiContext::getQtCurrent()->getGuiExecutor()->getContainerLog();
1828   ContainerLogViewer *lv = new ContainerLogViewer("YACS Container Log", _parent);
1829   lv->readFile(log);
1830   lv->show();
1831 }
1832
1833 void GenericGui::onGetErrorReport()
1834 {
1835   DEBTRACE("GenericGui::onGetErrorReport");
1836   if (!QtGuiContext::getQtCurrent()) return;
1837   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
1838   SubjectNode *snode = dynamic_cast<SubjectNode*>(sub);
1839   if (!snode) return;
1840   string log;
1841   if (QtGuiContext::getQtCurrent()->getGuiExecutor())
1842     {
1843       log = QtGuiContext::getQtCurrent()->getGuiExecutor()->getErrorReport(snode->getNode());
1844     }
1845   else
1846     {
1847       log = snode->getNode()->getErrorReport();
1848     }
1849
1850   LogViewer *lv = new LogViewer("Node error report", _parent);
1851   lv->setText(log);
1852   lv->show();
1853 }
1854
1855 void GenericGui::onGetErrorDetails()
1856 {
1857   DEBTRACE("GenericGui::onGetErrorDetails");
1858   if (!QtGuiContext::getQtCurrent()) return;
1859   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
1860   SubjectNode *snode = dynamic_cast<SubjectNode*>(sub);
1861   if (!snode) return;
1862   string log;
1863   if (QtGuiContext::getQtCurrent()->getGuiExecutor())
1864     {
1865       log = QtGuiContext::getQtCurrent()->getGuiExecutor()->getErrorDetails(snode->getNode());
1866     }
1867   else
1868     {
1869       log = snode->getNode()->getErrorDetails();
1870     }
1871
1872   LogViewer *lv = new LogViewer("Node Error Details", _parent);
1873   lv->setText(log);
1874   lv->show();
1875 }
1876
1877 void GenericGui::onGetContainerLog()
1878 {
1879   DEBTRACE("GenericGui::onGetContainerLog");
1880   if (!QtGuiContext::getQtCurrent()) return;
1881   if (!QtGuiContext::getQtCurrent()->getGuiExecutor()) return;
1882   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
1883   SubjectElementaryNode *snode = dynamic_cast<SubjectElementaryNode*>(sub);
1884   if (!snode) return;
1885   string log = QtGuiContext::getQtCurrent()->getGuiExecutor()->getContainerLog(snode->getNode());
1886
1887   LogViewer *lv = new LogViewer("Node Container Log", _parent);
1888   if (log.empty())
1889     {
1890       string info = "\n";
1891       if (dynamic_cast<YACS::ENGINE::ServiceNode*>(snode->getNode()))
1892         {
1893           info +="The container log of this node\n";
1894           info += "is not stored in a file and \n";
1895           info += "can't be displayed here, \n";
1896           info += "but you can have a look at \n";
1897           info += "the SALOME standard output,\n";
1898           info += "on your terminal...";
1899         }
1900       else
1901         {
1902           info += "See YACS Container log \n";
1903           info += "(on main proc menu) \n";
1904           info += "for all inline nodes";
1905         }
1906       lv->setText(info);
1907     }
1908   else
1909     lv->readFile(log);
1910   lv->show();
1911 }
1912
1913 void GenericGui::onShutdownProc()
1914 {
1915   DEBTRACE("GenericGui::onShutdownProc");
1916   if (!QtGuiContext::getQtCurrent()) return;
1917   if (!QtGuiContext::getQtCurrent()->getGuiExecutor()) return;
1918   QtGuiContext::getQtCurrent()->getGuiExecutor()->shutdownProc();
1919 }
1920
1921 void GenericGui::onEditDataTypes()
1922 {
1923   DEBTRACE("GenericGui::onEditDataTypes");
1924 }
1925
1926 void GenericGui::onCreateDataType()
1927 {
1928   DEBTRACE("GenericGui::onCreateDataType");
1929 }
1930
1931 void GenericGui::onImportDataType()
1932 {
1933   DEBTRACE("GenericGui::onImportDataType");
1934   if (_dwCatalogs) _dwCatalogs->raise();
1935 }
1936
1937 void GenericGui::onSelectComponentInstance()
1938 {
1939   DEBTRACE("GenericGui::onSelectComponentInstance");
1940   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
1941   if (!sub) return;
1942   SubjectComponent *ref = dynamic_cast<SubjectComponent*>(sub);
1943   YASSERT(ref);
1944   YACS::ENGINE::ComponentInstance* compo=ref->getComponent();
1945   QtGuiContext::getQtCurrent()->_mapOfLastComponentInstance[compo->getCompoName()]=compo;
1946 }
1947
1948 void GenericGui::onNewContainer()
1949 {
1950   DEBTRACE("GenericGui::onNewContainer");
1951   _guiEditor->CreateContainer();
1952 }
1953
1954 void GenericGui::onNewSalomeComponent()
1955 {
1956   DEBTRACE("GenericGui::onNewSalomeComponent");
1957   _guiEditor->CreateComponentInstance();
1958 }
1959
1960 void GenericGui::onNewSalomePythonComponent()
1961 {
1962   DEBTRACE("GenericGui::onNewSalomePythonComponent");
1963 }
1964
1965 void GenericGui::onNewCorbaComponent()
1966 {
1967   DEBTRACE("GenericGui::onNewCorbaComponent");
1968 }
1969
1970
1971 void GenericGui::onSalomeServiceNode()
1972 {
1973   DEBTRACE("GenericGui::onSalomeServiceNode");
1974   _guiEditor->CreateNode("SalomeNode");
1975 }
1976
1977 void GenericGui::onServiceInlineNode()
1978 {
1979   DEBTRACE("GenericGui::onServiceInlineNode");
1980   _guiEditor->CreateNode("SalomePythonNode");
1981 }
1982
1983 void GenericGui::onCORBAServiceNode()
1984 {
1985   DEBTRACE("GenericGui::onCORBAServiceNode");
1986   _guiEditor->CreateNode("CORBANode");
1987 }
1988
1989 void GenericGui::onNodeNodeServiceNode()
1990 {
1991   DEBTRACE("GenericGui::onNodeNodeServiceNode");
1992 }
1993
1994 void GenericGui::onCppNode()
1995 {
1996   DEBTRACE("GenericGui::onCppNode");
1997   _guiEditor->CreateNode("CppNode");
1998 }
1999
2000 void GenericGui::onXMLNode()
2001 {
2002   DEBTRACE("GenericGui::onXMLNode");
2003   _guiEditor->CreateNode("XmlNode");
2004 }
2005
2006 void GenericGui::onInDataNode()
2007 {
2008   DEBTRACE("GenericGui::onInDataNode");
2009   _guiEditor->CreateNode("PresetNode");
2010 }
2011
2012 void GenericGui::onOutDataNode()
2013 {
2014   DEBTRACE("GenericGui::onOutDataNode");
2015   _guiEditor->CreateNode("OutNode");
2016 }
2017
2018 void GenericGui::onInStudyNode()
2019 {
2020   DEBTRACE("GenericGui::onInStudyNode");
2021   _guiEditor->CreateNode("StudyInNode");
2022 }
2023
2024 void GenericGui::onOutStudyNode()
2025 {
2026   DEBTRACE("GenericGui::onOutStudyNode");
2027   _guiEditor->CreateNode("StudyOutNode");
2028 }
2029
2030 void GenericGui::onInlineScriptNode()
2031 {
2032   DEBTRACE("GenericGui::onInlineScriptNode");
2033   _guiEditor->CreateNode("PyScript");
2034 }
2035
2036 void GenericGui::onInlineFunctionNode()
2037 {
2038   DEBTRACE("GenericGui::onInlineFunctionNode");
2039   _guiEditor->CreateNode("PyFunction");
2040 }
2041
2042 void GenericGui::onBlockNode()
2043 {
2044   DEBTRACE("GenericGui::onBlockNode");
2045   _guiEditor->CreateBloc();
2046 }
2047
2048 void GenericGui::onFORNode()
2049 {
2050   DEBTRACE("GenericGui::onFORNode");
2051   _guiEditor->CreateForLoop();
2052 }
2053
2054 void GenericGui::onFOREACHNode()
2055 {
2056   DEBTRACE("GenericGui::onFOREACHNode");
2057   createForEachLoop("double");
2058 }
2059
2060 void GenericGui::createForEachLoop(std::string type)
2061 {
2062   DEBTRACE("GenericGui::createForEachLoop");
2063   _guiEditor->CreateForEachLoop(type);
2064 }
2065
2066 void GenericGui::onWHILENode()
2067 {
2068   DEBTRACE("GenericGui::onWHILENode");
2069   _guiEditor->CreateWhileLoop();
2070 }
2071
2072 void GenericGui::onSWITCHNode()
2073 {
2074   DEBTRACE("GenericGui::onSWITCHNode");
2075   _guiEditor->CreateSwitch();
2076 }
2077
2078 void GenericGui::onOptimizerLoop()
2079 {
2080   DEBTRACE("GenericGui::onOptimizerLoop");
2081   _guiEditor->CreateOptimizerLoop();
2082 }
2083
2084 void GenericGui::onNodeFromCatalog()
2085 {
2086   DEBTRACE("GenericGui::onNodeFromCatalog");
2087   if (_dwCatalogs) _dwCatalogs->raise();
2088 }
2089
2090 void GenericGui::onDeleteItem()
2091 {
2092   DEBTRACE("GenericGui::onDeleteItem");
2093   _guiEditor->DeleteSubject();
2094 }
2095
2096 void GenericGui::onCutItem()
2097 {
2098   DEBTRACE("GenericGui::onCutItem");
2099   _guiEditor->CutSubject();
2100 }
2101
2102 void GenericGui::onCopyItem()
2103 {
2104   DEBTRACE("GenericGui::onCopyItem");
2105   _guiEditor->CopySubject();
2106 }
2107
2108 void GenericGui::onPasteItem()
2109 {
2110   DEBTRACE("GenericGui::onPasteItem");
2111   _guiEditor->PasteSubject();
2112 }
2113
2114 void GenericGui::onPutInBloc()
2115 {
2116   _guiEditor->PutSubjectInBloc();
2117 }
2118
2119 void GenericGui::onPutGraphInBloc()
2120 {
2121   DEBTRACE("GenericGui::onPutGraphInBloc");
2122   _guiEditor->PutGraphInBloc();
2123   _guiEditor->arrangeNodes(false);
2124 }
2125
2126 void GenericGui::onPutGraphInForLoop()
2127 {
2128   DEBTRACE("GenericGui::onPutGraphInForLoop");
2129   _guiEditor->PutGraphInNode("ForLoop");
2130 }
2131
2132 void GenericGui::putGraphInForeachLoop(std::string type)
2133 {
2134   DEBTRACE("GenericGui::PutGraphInForeachLoop");
2135   _guiEditor->PutGraphInNode("ForEachLoop_"+type);
2136 }
2137
2138 void GenericGui::onPutGraphInWhileLoop()
2139 {
2140   DEBTRACE("GenericGui::onPutGraphInWhileLoop");
2141   _guiEditor->PutGraphInNode("WhileLoop");
2142 }
2143
2144 void GenericGui::onPutGraphInOptimizerLoop()
2145 {
2146   DEBTRACE("GenericGui::onPutGraphInOptimizerLoop");
2147   _guiEditor->PutGraphInNode("OptimizerLoop");
2148 }
2149
2150 void GenericGui::onArrangeLocalNodes()
2151 {
2152   DEBTRACE("GenericGui::onArrangeLocalNodes");
2153   _guiEditor->arrangeNodes(false);
2154 }
2155
2156 void GenericGui::onArrangeRecurseNodes()
2157 {
2158   DEBTRACE("GenericGui::onArrangeRecurseNodes");
2159   _guiEditor->arrangeNodes(true);
2160 }
2161
2162 void GenericGui::onRebuildLinks()
2163 {
2164   DEBTRACE("GenericGui::onRebuildLinks");
2165   _guiEditor->rebuildLinks();
2166 }
2167
2168 void GenericGui::onZoomToBloc()
2169 {
2170   DEBTRACE("GenericGui::onZoomToBloc");
2171   QtGuiContext::getQtCurrent()->getView()->onZoomToBloc();
2172 }
2173
2174 void GenericGui::onCenterOnNode()
2175 {
2176   DEBTRACE("GenericGui::onCenterOnNode");
2177   QtGuiContext::getQtCurrent()->getView()->onCenterOnNode();
2178 }
2179
2180 void GenericGui::onShrinkExpand() {
2181   DEBTRACE("GenericGui::onShrinkExpand");
2182   _guiEditor->shrinkExpand();
2183 }
2184
2185 void GenericGui::onToggleStraightLinks(bool checked)
2186 {
2187   Scene::_straightLinks = checked;
2188   DEBTRACE("Scene::_straightLinks=" << checked);
2189   if (!QtGuiContext::getQtCurrent())
2190     return;
2191   map<Subject*, SchemaItem*>::const_iterator it = QtGuiContext::getQtCurrent()->_mapOfSchemaItem.begin();
2192   for( ; it != QtGuiContext::getQtCurrent()->_mapOfSchemaItem.end(); ++it)
2193     {
2194       Subject* sub = (*it).first;
2195       sub->update(SWITCHSHAPE, 0, 0);
2196     }
2197 }
2198
2199 void GenericGui::onToggleAutomaticComputeLinks(bool checked)
2200 {
2201   Scene::_autoComputeLinks = checked;
2202   DEBTRACE("Scene::_autoComputeLinks=" << checked);
2203 }
2204
2205 void GenericGui::onToggleSimplifyLinks(bool checked)
2206 {
2207   Scene::_simplifyLinks = checked;
2208   DEBTRACE("Scene::_simplifyLinks=" << checked);
2209 }
2210
2211 void GenericGui::onToggleForce2NodesLinks(bool checked)
2212 {
2213   Scene::_force2NodesLink  = checked;
2214   DEBTRACE("Scene::_force2NodesLink=" << checked);
2215 }
2216
2217 void GenericGui::onToggleAddRowCols(bool checked)
2218 {
2219   Scene::_addRowCols  = checked;
2220   DEBTRACE("Scene::_addRowCols=" << checked);
2221 }
2222
2223 void GenericGui::onSelectReference()
2224 {
2225   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
2226   if (!sub) return;
2227   SubjectReference *ref = dynamic_cast<SubjectReference*>(sub);
2228   YASSERT(ref);
2229   SubjectServiceNode *snode = dynamic_cast<SubjectServiceNode*>(ref->getReference());
2230   snode->select(true);
2231 }
2232
2233 void GenericGui::onWhatsThis()
2234 {
2235   DEBTRACE("GenericGui::onWhatsThis");
2236   QWhatsThis::enterWhatsThisMode();
2237 }
2238
2239 void GenericGui::onWithoutStopMode(bool checked)
2240 {
2241   DEBTRACE("GenericGui::onWithoutStopMode " << checked);
2242   if (!QtGuiContext::getQtCurrent()) return;
2243   if (!QtGuiContext::getQtCurrent()->getGuiExecutor()) return;
2244   if (checked) QtGuiContext::getQtCurrent()->getGuiExecutor()->setContinueMode();
2245 }
2246
2247 void GenericGui::onBreakpointsMode(bool checked)
2248 {
2249   DEBTRACE("GenericGui::onWithoutStopMode " << checked);
2250   if (!QtGuiContext::getQtCurrent()) return;
2251   if (!QtGuiContext::getQtCurrent()->getGuiExecutor()) return;
2252   if (checked) QtGuiContext::getQtCurrent()->getGuiExecutor()->setBreakpointMode();
2253 }
2254
2255 void GenericGui::onStepByStepMode(bool checked)
2256 {
2257   DEBTRACE("GenericGui::onWithoutStopMode " << checked);
2258   if (!QtGuiContext::getQtCurrent()) return;
2259   if (!QtGuiContext::getQtCurrent()->getGuiExecutor()) return;
2260   if (checked) QtGuiContext::getQtCurrent()->getGuiExecutor()->setStepByStepMode();
2261 }
2262
2263 void GenericGui::onToggleStopOnError(bool checked)
2264 {
2265   DEBTRACE("GenericGui::onToggleStopOnError " << checked);
2266   if (!QtGuiContext::getQtCurrent()) return;
2267   if (!QtGuiContext::getQtCurrent()->getGuiExecutor()) return;
2268   if(checked)
2269     QtGuiContext::getQtCurrent()->getGuiExecutor()->setStopOnError(false);
2270   else
2271     QtGuiContext::getQtCurrent()->getGuiExecutor()->unsetStopOnError();
2272 }
2273
2274 void GenericGui::onToggleSceneItemVisible(bool checked)
2275 {
2276   DEBTRACE("GenericGui::onToggleSceneItemVisible " << checked);
2277   if (!QtGuiContext::getQtCurrent()) return;
2278   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
2279   SubjectNode *snode = dynamic_cast<SubjectNode*>(sub);
2280   if (!snode) return;
2281   DEBTRACE("---");
2282   if (!QtGuiContext::getQtCurrent()->_mapOfSceneItem.count(sub)) return;
2283   DEBTRACE("---");
2284   SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sub];
2285   item->setVisible(checked);
2286 }
2287
2288 void GenericGui::displayLinks(bool isShown)
2289 {
2290   if (!QtGuiContext::getQtCurrent()) return;
2291   map<pair<YACS::ENGINE::OutPort*, YACS::ENGINE::InPort*>,YACS::HMI::SubjectLink*>::const_iterator it;
2292   for (it = QtGuiContext::getQtCurrent()->_mapOfSubjectLink.begin();
2293        it != QtGuiContext::getQtCurrent()->_mapOfSubjectLink.end();
2294        ++it)
2295     {
2296       YACS::HMI::SubjectLink* sub = (*it).second;
2297       if (!sub) continue;
2298       SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sub];
2299       item->setVisible(isShown);
2300     }
2301 }
2302
2303 void GenericGui::displayControlLinks(bool isShown)
2304 {
2305   if (!QtGuiContext::getQtCurrent()) return;
2306   map<pair<YACS::ENGINE::Node*, YACS::ENGINE::Node*>,YACS::HMI::SubjectControlLink*>::const_iterator it;
2307   for (it = QtGuiContext::getQtCurrent()->_mapOfSubjectControlLink.begin();
2308        it != QtGuiContext::getQtCurrent()->_mapOfSubjectControlLink.end();
2309        ++it)
2310     {
2311       YACS::HMI::SubjectControlLink* sub = (*it).second;
2312       if (!sub) continue;
2313       SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sub];
2314       item->setVisible(isShown);
2315     }
2316 }
2317
2318 void GenericGui::displayPortLinks(bool isShown)
2319 {
2320   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
2321   DEBTRACE("displayPortLinks, subject : " << sub->getName());
2322   SubjectDataPort *sport = dynamic_cast<SubjectDataPort*>(sub);
2323   if (sport)
2324     {
2325       DEBTRACE("dataPort : " << sport->getName());
2326       list<SubjectLink*> linkList = sport->getListOfSubjectLink();
2327       list<SubjectLink*>::const_iterator it = linkList.begin();
2328       for( ; it != linkList.end(); ++it)
2329         {
2330           YACS::HMI::SubjectLink* sub = (*it);
2331           if (!sub) continue;
2332           SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sub];
2333           item->setVisible(isShown);
2334         }
2335       return;
2336     }
2337   SubjectNode *snode = dynamic_cast<SubjectNode*>(sub);
2338   if (snode)
2339     {
2340       DEBTRACE("Node : " << snode->getName());
2341       list<SubjectControlLink*> linkList = snode->getSubjectControlLinks();
2342       list<SubjectControlLink*>::const_iterator it = linkList.begin();
2343       for( ; it != linkList.end(); ++it)
2344         {
2345           YACS::HMI::SubjectControlLink* sub = (*it);
2346           if (!sub) continue;
2347           SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sub];
2348           item->setVisible(isShown);
2349         }
2350       return;
2351     }
2352 }
2353
2354 void GenericGui::displayALink(bool isShown)
2355 {
2356   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
2357   if (! QtGuiContext::getQtCurrent()->_mapOfSceneItem.count(sub)) return;
2358   SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sub];
2359   item->setVisible(isShown);
2360 }
2361
2362 void GenericGui::onShowAllLinks()
2363 {
2364   DEBTRACE("GenericGui::onShowAllLinks");
2365   displayLinks(true);
2366   displayControlLinks(true);
2367 }
2368
2369 void GenericGui::onHideAllLinks()
2370 {
2371   DEBTRACE("GenericGui::onHideAllLinks");
2372   displayLinks(false);
2373   displayControlLinks(false);
2374 }
2375
2376 void GenericGui::onShowOnlyPortLinks()
2377 {
2378   DEBTRACE("GenericGui::onShowOnlyPortLinks");
2379   onHideAllLinks();
2380   displayPortLinks(true);
2381 }
2382
2383 void GenericGui::onShowPortLinks()
2384 {
2385   DEBTRACE("GenericGui::onShowPortLinks");
2386   displayPortLinks(true);
2387 }
2388
2389 void GenericGui::onHidePortLinks()
2390 {
2391   DEBTRACE("GenericGui::onHidePortLinks");
2392   displayPortLinks(false);
2393 }
2394
2395 void GenericGui::onEmphasisPortLinks()
2396 {
2397   DEBTRACE("GenericGui::onEmphasisPortLinks");
2398   if (!QtGuiContext::getQtCurrent()) return;
2399   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
2400   DEBTRACE("EmphasizePortLinks, subject : " << sub->getName());
2401   if (!sub)
2402     return;
2403
2404   SubjectDataPort *sport = dynamic_cast<SubjectDataPort*>(sub);
2405   if (sport)
2406     {
2407       emphasizePortLink(sport, true);
2408       return;
2409     }
2410
2411   // --- if a Node, explore all data ports
2412
2413   SubjectNode *snode = dynamic_cast<SubjectNode*>(sub);
2414   if (snode)
2415     {
2416       DEBTRACE("Node : " << snode->getName());
2417       {
2418         list<SubjectInputPort*> linkList = snode->getSubjectInputPorts();
2419         list<SubjectInputPort*>::const_iterator it = linkList.begin();
2420         for( ; it != linkList.end(); ++it)
2421           {
2422             YACS::HMI::SubjectInputPort* sub = (*it);
2423             if (!sub) continue;
2424             emphasizePortLink(sub, true);
2425           }
2426       }
2427       {
2428         list<SubjectOutputPort*> linkList = snode->getSubjectOutputPorts();
2429         list<SubjectOutputPort*>::const_iterator it = linkList.begin();
2430         for( ; it != linkList.end(); ++it)
2431           {
2432             YACS::HMI::SubjectOutputPort* sub = (*it);
2433             if (!sub) continue;
2434             emphasizePortLink(sub, true);
2435           }
2436       }
2437       return;
2438     }
2439 }
2440
2441 void GenericGui::onShowOnlyCtrlLinks()
2442 {
2443   DEBTRACE("GenericGui::onShowOnlyCtrlLinks");
2444   onHideAllLinks();
2445   displayPortLinks(true);
2446 }
2447
2448 void GenericGui::onShowCtrlLinks()
2449 {
2450   DEBTRACE("GenericGui::onShowCtrlLinks");
2451   displayPortLinks(true);
2452 }
2453
2454 void GenericGui::onHideCtrlLinks()
2455 {
2456   DEBTRACE("GenericGui::onHideCtrlLinks");
2457   displayPortLinks(false);
2458 }
2459
2460 void GenericGui::onEmphasisCtrlLinks()
2461 {
2462   DEBTRACE("GenericGui::onEmphasisCtrlLinks");
2463   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
2464   DEBTRACE("Emphasize Ctrl Links, subject : " << sub->getName());
2465   if (!sub)
2466     return;
2467   SubjectNode *snode = dynamic_cast<SubjectNode*>(sub);
2468   if (snode)
2469     {
2470       DEBTRACE("Node : " << snode->getName());
2471       list<SubjectControlLink*> linkList = snode->getSubjectControlLinks();
2472       list<SubjectControlLink*>::const_iterator it = linkList.begin();
2473       for( ; it != linkList.end(); ++it)
2474         {
2475           YACS::HMI::SubjectControlLink* sub = (*it);
2476           if (!sub) continue;
2477           sub->update(EMPHASIZE, true, sub);
2478           Subject *sin = sub->getSubjectInNode();
2479           Subject *sout = sub->getSubjectOutNode();
2480           sin->update(EMPHASIZE, true, sub);
2481           sout->update(EMPHASIZE, true, sub);
2482         }
2483       return;
2484     }
2485 }
2486
2487 void GenericGui::onShowOnlyLink()
2488 {
2489   DEBTRACE("GenericGui::onShowOnlyLink");
2490   onHideAllLinks();
2491   displayALink(true);
2492 }
2493
2494 void GenericGui::onShowLink()
2495 {
2496   DEBTRACE("GenericGui::onShowLink");
2497   displayALink(true);
2498 }
2499
2500 void GenericGui::onHideLink()
2501 {
2502   DEBTRACE("GenericGui::onHideLink");
2503   displayALink(false);
2504 }
2505
2506 void GenericGui::onEmphasisLink()
2507 {
2508   DEBTRACE("GenericGui::onEmphasisLink");
2509   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
2510   if (!sub)
2511     return;
2512   sub->update(EMPHASIZE, true, sub);
2513 }
2514
2515 void GenericGui::onDeEmphasizeAll()
2516 {
2517   DEBTRACE("GenericGui::onDeEmphasizeAll");
2518   map<Subject*, SchemaItem*>::const_iterator it = QtGuiContext::getQtCurrent()->_mapOfSchemaItem.begin();
2519   for( ; it != QtGuiContext::getQtCurrent()->_mapOfSchemaItem.end(); ++it)
2520     {
2521       Subject* sub = (*it).first;
2522       sub->update(EMPHASIZE, false, sub);
2523     }
2524 }
2525
2526 void GenericGui::onUndo()
2527 {
2528   DEBTRACE("GenericGui::onUndo");
2529   if (QtGuiContext::getQtCurrent()->_setOfModifiedSubjects.empty())
2530     QtGuiContext::getQtCurrent()->getInvoc()->undo();
2531   else Message("undo not possible when there are local modifications not confirmed");
2532 }
2533
2534 void GenericGui::onRedo()
2535 {
2536   DEBTRACE("GenericGui::onRedo");
2537   if (QtGuiContext::getQtCurrent()->_setOfModifiedSubjects.empty())
2538     QtGuiContext::getQtCurrent()->getInvoc()->redo();
2539   else Message("redo not possible when there are local modifications not confirmed");
2540 }
2541
2542 void GenericGui::onShowUndo()
2543 {
2544   _guiEditor->showUndo(_parent);
2545 }
2546
2547 void GenericGui::onShowRedo()
2548 {
2549   _guiEditor->showRedo(_parent);
2550 }
2551
2552 void GenericGui::onCleanOnExit()
2553 {
2554   DEBTRACE("GenericGui::onCleanOnExit");
2555   int studyId = _wrapper->activeStudyId();
2556   map<QWidget*, YACS::HMI::QtGuiContext*> mapViewContextCopy = _mapViewContext;
2557   map<QWidget*, YACS::HMI::QtGuiContext*>::iterator it = mapViewContextCopy.begin();
2558   for (; it != mapViewContextCopy.end(); ++it)
2559     {
2560       closeContext((*it).first, true);
2561     }
2562 }
2563
2564 void GenericGui::emphasizePortLink(YACS::HMI::SubjectDataPort* sub, bool emphasize)
2565 {
2566   DEBTRACE("dataPort : " << sub->getName());
2567   list<SubjectLink*> linkList = sub->getListOfSubjectLink();
2568   list<SubjectLink*>::const_iterator it = linkList.begin();
2569   for( ; it != linkList.end(); ++it)
2570     {
2571       YACS::HMI::SubjectLink* subli = (*it);
2572       if (!subli) continue;
2573       subli->update(EMPHASIZE, emphasize, sub);
2574       Subject *sin = subli->getSubjectInPort();
2575       Subject *sout = subli->getSubjectOutPort();
2576       sin->update(EMPHASIZE, emphasize, sub);
2577       sout->update(EMPHASIZE, emphasize, sub);
2578     }
2579 }
2580
2581 void GenericGui::onHelpContextModule( const QString& theComponentName, const QString& theFileName, const QString& theContext)
2582 {
2583   _wrapper->onHelpContextModule(theComponentName,theFileName,theContext);
2584 }