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