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