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