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