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