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