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