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