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