1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <RuntimeSALOME.hxx>
25 #include <YACSGui_Module.h>
26 #include <YACSGui_Graph.h>
27 #include <YACSGui_DataModel.h>
28 #include <YACSGui_DataObject.h>
29 #include <YACSGui_Executor.h>
30 #include <YACSGui_XMLDriver.h>
31 #include <YACSGui_Observer.h>
32 #include "YACSGui_RunMode.h"
34 #include <YACSPrs_ElementaryNode.h>
35 #include <YACSPrs_BlocNode.h>
36 #include <YACSPrs_Link.h>
38 #include <SUIT_Session.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_FileDlg.h>
41 #include <SUIT_MessageBox.h>
42 #include <CAM_Application.h>
43 #include <SalomeApp_Application.h>
44 #include <QxGraph_ViewModel.h>
45 #include <QxGraph_ViewWindow.h>
46 #include <QxGraph_ViewManager.h>
47 #include <QxGraph_Canvas.h> // for test presentations
48 #include <QxGraph_Prs.h> // for test presentations
51 #include <SALOME_LifeCycleCORBA.hxx>
53 #include <qapplication.h>
55 #include <iostream> // for debug only
56 #include "utilities.h"
59 using namespace YACS::ENGINE;
64 CAM_Module* createModule()
66 return new YACSGui_Module();
73 YACSGui_Module::YACSGui_Module() : SalomeApp_Module( "YACS" )
75 MESSAGE("YACSGui_Module::YACSGui_Module()");
82 YACSGui_Module::~YACSGui_Module()
84 MESSAGE("YACSGui_Module::~YACSGui_Module()");
87 //! Initialize module.
90 void YACSGui_Module::initialize( CAM_Application* theApp )
92 MESSAGE("YACSGui_Module::initialize");
93 SalomeApp_Module::initialize(theApp);
94 InitYACSGuiGen( dynamic_cast<SalomeApp_Application*>( theApp ) );
100 //! Creates module actions.
103 void YACSGui_Module::createActions()
105 MESSAGE("YACSGui_Module::createActions()");
107 QWidget* aDesktop = application()->desktop();
108 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
110 if (!aDesktop || !aResourceMgr)
114 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_NEW_DATAFLOW"));
115 createAction( NewDataflowId, tr("TOP_NEW_DATAFLOW"), QIconSet(aPixmap),
116 tr("MEN_NEW_DATAFLOW"), tr("STB_NEW_DATAFLOW"),
117 0, aDesktop, false, this, SLOT(onNewDataflow()));
119 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_MODIFY_DATAFLOW"));
120 createAction( ModifyDataflowId, tr("TOP_MODIFY_DATAFLOW"), QIconSet(aPixmap),
121 tr("MEN_MODIFY_DATAFLOW"), tr("STB_MODIFY_DATAFLOW"),
122 0, aDesktop, false, this, SLOT(onModifyDataflow()));
124 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_MODIFY_SUPERV_DATAFLOW"));
125 createAction( ModifySupervDataflowId, tr("TOP_MODIFY_SUPERV_DATAFLOW"), QIconSet(aPixmap),
126 tr("MEN_MODIFY_SUPERV_DATAFLOW"), tr("STB_MODIFY_SUPERV_DATAFLOW"),
127 0, aDesktop, false, this, SLOT(onModifySupervDataflow()));
129 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_IMPORT_DATAFLOW"));
130 createAction( ImportDataflowId, tr("TOP_IMPORT_DATAFLOW"), QIconSet(aPixmap),
131 tr("MEN_IMPORT_DATAFLOW"), tr("STB_IMPORT_DATAFLOW"),
132 0, aDesktop, false, this, SLOT(onImportDataflow()));
134 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_IMPORT_SUPERV_DATAFLOW"));
135 createAction( ImportSupervDataflowId, tr("TOP_IMPORT_SUPERV_DATAFLOW"), QIconSet(aPixmap),
136 tr("MEN_IMPORT_SUPERV_DATAFLOW"), tr("STB_IMPORT_SUPERV_DATAFLOW"),
137 0, aDesktop, false, this, SLOT(onImportSupervDataflow()));
139 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_EXPORT_DATAFLOW"));
140 createAction( ExportDataflowId, tr("TOP_EXPORT_DATAFLOW"), QIconSet(aPixmap),
141 tr("MEN_EXPORT_DATAFLOW"), tr("STB_EXPORT_DATAFLOW"),
142 0, aDesktop, false, this, SLOT(onExportDataflow()));
145 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_ADD_NODE"));
146 createAction( AddNodeId, tr("TOP_ADD_NODE"), QIconSet(aPixmap),
147 tr("MEN_ADD_NODE"), tr("STB_ADD_NODE"),
148 0, aDesktop, false, this, SLOT(onAddNode()));
150 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_SUSPEND_RESUME_DATAFLOW"));
151 createAction( SuspendResumeDataflowId, tr("TOP_SUSPEND_RESUME_DATAFLOW"), QIconSet(aPixmap),
152 tr("MEN_SUSPEND_RESUME_DATAFLOW"), tr("STB_SUSPEND_RESUME_DATAFLOW"),
153 0, aDesktop, false, this, SLOT(onSuspendResumeDataflow()));
155 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_RUN_DATAFLOW"));
156 createAction( RunDataflowId, tr("TOP_RUN_DATAFLOW"), QIconSet(aPixmap),
157 tr("MEN_RUN_DATAFLOW"), tr("STB_RUN_DATAFLOW"),
158 0, aDesktop, false, this, SLOT(onRunDataflow()));
160 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_REMOTE_RUN_DATAFLOW"));
161 createAction( RemoteRunDataflowId, tr("TOP_REMOTE_RUN_DATAFLOW"), QIconSet(aPixmap),
162 tr("MEN_REMOTE_RUN_DATAFLOW"), tr("STB_REMOTE_RUN_DATAFLOW"),
163 0, aDesktop, false, this, SLOT(onRemoteRunDataflow()));
165 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_KILL_DATAFLOW"));
166 createAction( KillDataflowId, tr("TOP_KILL_DATAFLOW"), QIconSet(aPixmap),
167 tr("MEN_KILL_DATAFLOW"), tr("STB_KILL_DATAFLOW"),
168 0, aDesktop, false, this, SLOT(onKillDataflow()));
170 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_TOGGLESTOPONERROR"));
171 createAction( ToggleStopOnErrorId, tr("TOP_TOGGLESTOPONERROR"), QIconSet(aPixmap),
172 tr("MEN_TOGGLESTOPONERROR"), tr("STB_TOGGLESTOPONERROR"),
173 0, aDesktop, false, this, SLOT(onToggleStopOnError()));
175 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_FILTERNEXTSTEPS"));
176 createAction( FilterNextStepsId, tr("TOP_FILTERNEXTSTEPS"), QIconSet(aPixmap),
177 tr("MEN_FILTERNEXTSTEPS"), tr("STB_FILTERNEXTSTEPS"),
178 0, aDesktop, false, this, SLOT(onFilterNextSteps()));
180 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_ADD_DATAFLOW_IN_STUDY"));
181 createAction( AddDataflowInStudyId, tr("TOP_ADD_DATAFLOW_IN_STUDY"), QIconSet(aPixmap),
182 tr("MEN_ADD_DATAFLOW_IN_STUDY"), tr("STB_ADD_DATAFLOW_IN_STUDY"),
183 0, aDesktop, false, this, SLOT(onAddDataflowInStudy()));
185 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_CHANGE_INFORMATIONS"));
186 createAction( ChangeInformationsId, tr("TOP_CHANGE_INFORMATIONS"), QIconSet(aPixmap),
187 tr("MEN_CHANGE_INFORMATIONS"), tr("STB_CHANGE_INFORMATIONS"),
188 0, aDesktop, false, this, SLOT(onChangeInformations()));
190 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_SAVEDATAFLOWSTATE"));
191 createAction( SaveDataflowStateId, tr("TOP_SAVEDATAFLOWSTATE"), QIconSet(aPixmap),
192 tr("MEN_SAVEDATAFLOWSTATE"), tr("STB_SAVEDATAFLOWSTATE"),
193 0, aDesktop, false, this, SLOT(onSaveDataflowState()));
195 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_RELOAD_DATAFLOW"));
196 createAction( ReloadDataflowId, tr("TOP_RELOAD_DATAFLOW"), QIconSet(aPixmap),
197 tr("MEN_RELOAD_DATAFLOW"), tr("STB_RELOAD_DATAFLOW"),
198 0, aDesktop, false, this, SLOT(onReloadDataflow()));
200 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_REBUILD_LINKS"));
201 createAction( RebuildLinksId, tr("TOP_REBUILD_LINKS"), QIconSet(aPixmap),
202 tr("MEN_REBUILD_LINKS"), tr("STB_REBUILD_LINKS"),
203 0, aDesktop, false, this, SLOT(onRebuildLinks()));
205 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_FULL_VIEW"));
206 createAction( FullViewId, tr("TOP_FULL_VIEW"), QIconSet(aPixmap),
207 tr("MEN_FULL_VIEW"), tr("STB_FULL_VIEW"),
208 0, aDesktop, false, this, SLOT(onFullView()));
210 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_CONTROL_VIEW"));
211 createAction( ControlViewId, tr("TOP_CONTROL_VIEW"), QIconSet(aPixmap),
212 tr("MEN_CONTROL_VIEW"), tr("STB_CONTROL_VIEW"),
213 0, aDesktop, false, this, SLOT(onControlView()));
215 aPixmap = aResourceMgr->loadPixmap("YACSGui", tr("ICON_TABLE_VIEW"));
216 createAction( TableViewId, tr("TOP_TABLE_VIEW"), QIconSet(aPixmap),
217 tr("MEN_TABLE_VIEW"), tr("STB_TABLE_VIEW"),
218 0, aDesktop, false, this, SLOT(onTableView()));
222 //! Creates module menus.
225 void YACSGui_Module::createMenus()
227 MESSAGE("YACSGui_Module::createMenus");
228 int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
229 createMenu( NewDataflowId, fileId, 10 );
230 createMenu( ModifyDataflowId, fileId, 10 );
231 createMenu( ModifySupervDataflowId, fileId, 10 );
232 createMenu( ImportDataflowId, fileId, 10 );
233 createMenu( ImportSupervDataflowId, fileId, 10 );
234 createMenu( ExportDataflowId, fileId, 10 );
236 int supervisorId = createMenu( tr( "MEN_SUPERVISOR" ), -1, -1, 10 );
237 createMenu( AddNodeId, supervisorId, -1 );
238 createMenu( separator(), supervisorId, -1 );
239 createMenu( SuspendResumeDataflowId, supervisorId, -1 );
240 createMenu( RemoteRunDataflowId, supervisorId, -1 );
241 createMenu( RunDataflowId, supervisorId, -1 );
242 createMenu( KillDataflowId, supervisorId, -1 );
243 createMenu( separator(), supervisorId, -1 );
244 createMenu( ToggleStopOnErrorId, supervisorId, -1 );
245 createMenu( separator(), supervisorId, -1 );
246 createMenu( AddDataflowInStudyId, supervisorId, -1 );
247 createMenu( ChangeInformationsId, supervisorId, -1 );
248 createMenu( separator(), supervisorId, -1 );
249 createMenu( SaveDataflowStateId, supervisorId, -1 );
250 createMenu( ReloadDataflowId, supervisorId, -1 );
251 createMenu( RebuildLinksId, supervisorId, -1 );
253 int dataflowTbId = createTool( tr("TOOLBAR_DATAFLOW") );
254 createTool( NewDataflowId, dataflowTbId );
255 createTool( ModifyDataflowId, dataflowTbId );
256 createTool( ModifySupervDataflowId, dataflowTbId );
257 createTool( ImportDataflowId, dataflowTbId );
258 createTool( ImportSupervDataflowId, dataflowTbId );
259 createTool( ExportDataflowId, dataflowTbId );
260 createTool( separator(), dataflowTbId );
261 createTool( AddDataflowInStudyId, dataflowTbId );
262 createTool( separator(), dataflowTbId );
263 createTool( ReloadDataflowId, dataflowTbId );
264 createTool( RebuildLinksId, dataflowTbId );
265 createTool( separator(), dataflowTbId );
266 createTool( FullViewId, dataflowTbId );
267 createTool( ControlViewId, dataflowTbId );
268 createTool( TableViewId, dataflowTbId );
269 createTool( separator(), dataflowTbId );
270 createTool( SaveDataflowStateId, dataflowTbId );
272 int executionTbId = createTool( tr("TOOLBAR_EXECUTION") );
273 createTool( SuspendResumeDataflowId, executionTbId );
274 createTool( RemoteRunDataflowId, executionTbId );
275 createTool( RunDataflowId, executionTbId );
276 createTool( separator(), executionTbId );
277 createTool( KillDataflowId, executionTbId );
278 createTool( ToggleStopOnErrorId, executionTbId );
281 //! Defines which windows should be created.
284 void YACSGui_Module::windows( QMap<int, int>& mappa ) const
286 MESSAGE("YACSGui_Module::windows");
287 mappa.insert( LightApp_Application::WT_ObjectBrowser, Qt::DockLeft );
288 mappa.insert( LightApp_Application::WT_PyConsole, Qt::DockBottom );
291 //! Defines viewer type.
294 void YACSGui_Module::viewManagers( QStringList& lst ) const
296 MESSAGE("YACSGui_Module::viewManagers");
297 lst.append( QxGraph_Viewer::Type() );
301 //! Inherited public slot. Called on a module activating.
304 bool YACSGui_Module::activateModule( SUIT_Study* theStudy )
306 MESSAGE("YACSGui_Module::activateModule");
307 bool bOk = SalomeApp_Module::activateModule( theStudy );
308 setMenuShown( true );
309 setToolShown( true );
311 RuntimeSALOME::setRuntime();
315 //! Inherited public slot. Called on a module deactivating.
318 bool YACSGui_Module::deactivateModule( SUIT_Study* theStudy )
320 MESSAGE("YACSGui_Module::deactivateModule");
321 setMenuShown( false );
322 setToolShown( false );
323 return SalomeApp_Module::deactivateModule( theStudy );
326 //! Module's engine IOR
329 QString YACSGui_Module::engineIOR() const
331 MESSAGE("YACSGui_Module::engineIOR");
332 CORBA::String_var anIOR = getApp()->orb()->object_to_string( InitYACSGuiGen( getApp() ) );
333 return QString( anIOR.in() );
336 //! Gets a reference to the module's engine
339 YACSGui_ORB::YACSGui_Gen_ptr YACSGui_Module::InitYACSGuiGen( SalomeApp_Application* app )
341 MESSAGE("YACSGui_Module::InitYACSGuiGen");
342 Engines::Component_var comp = app->lcc()->FindOrLoad_Component( "YACSContainer","YACSGui" );
343 YACSGui_ORB::YACSGui_Gen_ptr clr = YACSGui_ORB::YACSGui_Gen::_narrow(comp);
344 ASSERT(!CORBA::is_nil(clr));
349 void YACSGui_Module::createGraph( SUIT_ViewManager* theVM )
351 MESSAGE("YACSGui_Module::createGraph");
352 QxGraph_ViewWindow* aVW = dynamic_cast<QxGraph_ViewWindow*>( theVM->getActiveView() );
355 // create graph with null Proc : waiting for import operation!
356 YACS::ENGINE::Proc* aProc = 0;
357 YACSGui_Loader::PrsDataMap aPrsData;
358 YACSGui_Loader::PortLinkDataMap aPortLinkData;
359 YACSGui_Loader::LabelLinkDataMap aLabelLinkData;
360 displayGraph( aProc, aPrsData, aPortLinkData, aLabelLinkData );
364 //! Private slot. Creates a new empty dataflow.
367 void YACSGui_Module::onNewDataflow()
369 MESSAGE("YACSGui_Module::onNewDataflow");
370 printf("YACSGui_Module::newDataflow\n");
371 SUIT_ViewManager* aVM = getApp()->createViewManager( QxGraph_Viewer::Type() );
375 //! Private slot. Imports uneditable dataflow from the XML file(choosing via a file dialog)
378 void YACSGui_Module::onImportDataflow()
380 MESSAGE("YACSGui_Module::onImportDataflow");
381 ImportDataflowFromFile(false);
384 //! Private slot. Imports editable dataflow from the XML file(choosing via a file dialog)
387 void YACSGui_Module::onModifyDataflow()
389 MESSAGE("YACSGui_Module::onModifyDataflow");
390 ImportDataflowFromFile(true);
393 //! Private slot. Imports uneditable SUPERV dataflow from the XML file(choosing via a file dialog)
396 void YACSGui_Module::onImportSupervDataflow()
398 MESSAGE("YACSGui_Module::onImportSupervDataflow");
399 ImportDataflowFromFile(false, true);
402 //! Private slot. Imports editable SUPERV dataflow from the XML file(choosing via a file dialog)
405 void YACSGui_Module::onModifySupervDataflow()
407 MESSAGE("YACSGui_Module::onModifySupervDataflow");
408 ImportDataflowFromFile(true, true);
411 //! Private slot. Exports current dataflow to XML file.
414 void YACSGui_Module::onExportDataflow()
416 MESSAGE("YACSGui_Module::onExportDataflow");
417 if ( !activeGraph() )
419 Proc* aProc = activeGraph()->getProc();
423 QString aFileName = SUIT_FileDlg::getFileName( application()->desktop(), aProc->getName(), "*.xml", tr("TLT_EXPORT_DATAFLOW"), false );
424 if (aFileName.isEmpty())
427 YACSGui_VisitorSaveSchema aWriter( this, aProc );
428 aWriter.openFileSchema( aFileName );
429 aWriter.visitProc( aProc );
430 aWriter.closeFileSchema();
433 //! Private slot. Reloads current dataflow.
436 void YACSGui_Module::onReloadDataflow()
438 MESSAGE("YACSGui_Module::onReloadDataflow");
439 YACSGui_Graph* aGraph = activeGraph();
442 aGraph->setToUpdate(true);
447 //! Private slot. Rebuilds dataflow links.
450 void YACSGui_Module::onRebuildLinks()
452 MESSAGE("YACSGui_Module::onRebuildLinks");
453 YACSGui_Graph* aGraph = activeGraph();
454 if (aGraph) aGraph->rebuildLinks();
457 //! Private slot. Open dialog for add node to current dataflow.
460 void YACSGui_Module::onAddNode()
462 MESSAGE("YACSGui_Module::onAddNode");
463 YACSGui_Graph* aGraph = activeGraph();
466 SUIT_MessageBox::warn1(getApp()->desktop(),
468 tr("MSG_NO_DATAFLOW_SELECTED"),
473 YACSGui_DataModel* aModel = getDataModel();
474 if ( aModel && !aModel->isEditable(activeGraph()->getProc()) )
476 SUIT_MessageBox::warn1(getApp()->desktop(),
478 tr("MSG_DATAFLOW_NOT_EDITABLE"),
484 //! Private slot. Starts dataflow execution.
487 void YACSGui_Module::onRunDataflow()
489 MESSAGE("YACSGui_Module::onRunDataflow");
490 YACSGui_Executor* anExecutor = findExecutor();
492 anExecutor->runDataflow();
495 //! Private slot. Starts remote dataflow execution.
498 void YACSGui_Module::onRemoteRunDataflow()
500 MESSAGE("YACSGui_Module::onRemoteRunDataflow");
501 YACSGui_Executor* anExecutor = findExecutor();
503 anExecutor->runDataflow(true);
506 //! Private slot. Kills dataflow execution.
509 void YACSGui_Module::onKillDataflow()
511 MESSAGE("YACSGui_Module::onKillDataflow");
512 YACSGui_Executor* anExecutor = findExecutor();
515 if (!anExecutor->isRunning())
517 SUIT_MessageBox::warn1(getApp()->desktop(),
519 tr("MSG_DATAFLOW_IS_NOT_RUNNING"),
524 anExecutor->stopDataflow();
525 //myExecutors[aProc] = 0; //@
528 //! Private slot. Suspends or resumes dataflow execution.
531 void YACSGui_Module::onSuspendResumeDataflow()
533 MESSAGE("YACSGui_Module::onSuspendResumeDataflow");
534 YACSGui_Executor* anExecutor = findExecutor();
537 RunModeMap::iterator anIterator = _runModeMap.find(anExecutor);
538 YACSGui_RunMode* aRunMode = 0;
539 if (anIterator != _runModeMap.end())
540 aRunMode = (*anIterator).second;
543 aRunMode = new YACSGui_RunMode(anExecutor, application()->desktop());
544 _runModeMap[anExecutor] = aRunMode;
546 if (!aRunMode->isShown())
551 void YACSGui_Module::onFilterNextSteps()
553 MESSAGE("YACSGui_Module::onFilterNextSteps --- NOT YET IMPLEMENTED!");
554 YACSGui_Executor* anExecutor = findExecutor();
560 void YACSGui_Module::onSaveDataflowState()
562 MESSAGE("YACSGui_Module::onSaveDataflowState --- NOT YET IMPLEMENTED!");
563 YACSGui_Executor* anExecutor = findExecutor();
569 void YACSGui_Module::onToggleStopOnError()
571 MESSAGE("YACSGui_Module::onToggleStopOnError");
572 YACSGui_Executor* anExecutor = findExecutor();
575 anExecutor->setStopOnError(true);
579 //! Private slot. Add current dataflow to study.
582 void YACSGui_Module::onAddDataflowInStudy()
584 MESSAGE("YACSGui_Module::onAddDataflowInStudy");
585 YACSGui_Graph* aGraph = activeGraph();
588 Proc* aProc = aGraph->getProc();
590 aProc = new Proc("NewDataflow");
591 YACSGui_DataModel* aModel = getDataModel();
593 aModel->addData(aProc);
597 //! Private slot. TD: what's this ?
600 void YACSGui_Module::onChangeInformations()
602 MESSAGE("YACSGui_Module::onChangeInformations --- NOT YET IMPLEMENTED!");
605 //! Private slot. Switch current dataflow to full view mode.
608 void YACSGui_Module::onFullView()
610 MESSAGE("YACSGui_Module::onFullView --- NOT YET IMPLEMENTED!");
613 //! Private slot. Switch current dataflow to control view mode.
616 void YACSGui_Module::onControlView()
618 MESSAGE("YACSGui_Module::onControlView --- NOT YET IMPLEMENTED!");
621 //! Private slot. Switch current dataflow to table view mode.
624 void YACSGui_Module::onTableView()
626 MESSAGE("YACSGui_Module::onTableView --- NOT YET IMPLEMENTED!");
629 //! Creates and displays presentation of a calculation graph.
631 * \param theGraph - graph to be displayed
632 * \param thePrsData - map of node coordinates and dimensions
634 YACSGui_Graph* YACSGui_Module::displayGraph( YACS::ENGINE::Proc* theGraph,
635 const YACSGui_Loader::PrsDataMap& thePrsData,
636 const YACSGui_Loader::PortLinkDataMap& thePortLinkData,
637 const YACSGui_Loader::LabelLinkDataMap& theLabelLinkData)
639 MESSAGE("YACSGui_Module::displayGraph");
640 YACSGui_Graph* aGraph = 0;
642 QxGraph_Canvas* aCanvas = getCanvas();
646 aGraph = new YACSGui_Graph( this, aCanvas, theGraph );
649 // Update node geometry
650 // TODO: not optimal, graph is redrawn twice -
651 // before and after node geometry is applied - to be improved...
652 bool needToUpdate = false;
653 if ( thePrsData.size() )
655 for ( YACSGui_Loader::PrsDataMap::const_iterator it = thePrsData.begin(); it != thePrsData.end(); it++ )
657 YACSPrs_ElementaryNode* anItem = aGraph->getItem( (*it).first );
658 YACSGui_Loader::PrsData aData = (*it).second;
663 YACSPrs_BlocNode* aBloc = dynamic_cast<YACSPrs_BlocNode*>(anItem);
666 aBloc->resize( (int)aData.width, (int)aData.height );
669 anItem->setIsCheckAreaNeeded(false);
670 anItem->move( aData.x, aData.y );
671 anItem->setIsCheckAreaNeeded(true);
672 anItem->setZ( aData.z );
677 // Update port links presentations
678 if ( thePortLinkData.size() )
680 for ( YACSGui_Loader::PortLinkDataMap::const_iterator it = thePortLinkData.begin(); it != thePortLinkData.end(); it++ )
682 // (*it).first.first is an output port engine
683 // (*it).first.second is an input port engine
684 YACSPrs_ElementaryNode* aFromNodePrs = aGraph->getItem( (*it).first.first->getNode() );
685 if ( !aFromNodePrs ) continue;
687 std::list<YACSPrs_Link*> aLinksPrs = aFromNodePrs->getPortPrs( (*it).first.first )->getLinks();
688 for ( std::list<YACSPrs_Link*>::iterator itL = aLinksPrs.begin(); itL != aLinksPrs.end(); itL++ )
690 if ( YACSPrs_PortLink* aPortLink = dynamic_cast<YACSPrs_PortLink*>( *itL ) )
692 if ( aPortLink->getInputPort()->getEngine() == (*it).first.second )
694 aPortLink->setPoints((*it).second);
703 // Update label links presentations
704 if ( theLabelLinkData.size() )
706 for ( YACSGui_Loader::LabelLinkDataMap::const_iterator it = theLabelLinkData.begin(); it != theLabelLinkData.end(); it++ )
708 YACSPrs_ElementaryNode* aSlaveNodePrs = aGraph->getItem( (*it).first );
709 if ( !aSlaveNodePrs ) continue;
711 if ( YACSPrs_LabelLink* aLinkPrs = aSlaveNodePrs->getLabelLink() )
713 aLinkPrs->setPoints((*it).second);
720 if ( needToUpdate ) aCanvas->update();
723 //! Returns the presentation of a given calculation graph.
726 YACSGui_Graph* YACSGui_Module::getGraph( YACS::ENGINE::Proc* theGraph )
728 MESSAGE("YACSGui_Module::getGraph");
729 YACSGui_Graph* aGraph = 0;
730 // TODO - find a graph in all viewers
732 // TEMPORARY solution:
733 if ( activeGraph() && activeGraph()->getProc() == theGraph )
735 aGraph = activeGraph();
741 //! Returns the presentation of a the calculation graph corresponding to the active view.
744 YACSGui_Graph* YACSGui_Module::activeGraph()
746 MESSAGE("YACSGui_Module::activeGraph");
747 YACSGui_Graph* aGraph = 0;
748 QxGraph_Canvas* aCanvas = getCanvas();
750 // Assume that there's the one and only prs per a canvas
751 aGraph = dynamic_cast<YACSGui_Graph*>( aCanvas->getPrs() );
755 //! Returns the graph viewer instance
758 QxGraph_Viewer* YACSGui_Module::getViewer()
760 MESSAGE("YACSGui_Module::getViewer");
761 QxGraph_Viewer* aViewer = 0;
762 QxGraph_ViewManager* aVM =
763 dynamic_cast<QxGraph_ViewManager*>( getApp()->getViewManager( QxGraph_Viewer::Type(), true ) );
765 aViewer = dynamic_cast<QxGraph_Viewer*>( aVM->getViewModel() );
769 //! Returns the canvas for graph drawing
772 QxGraph_Canvas* YACSGui_Module::getCanvas()
774 MESSAGE("YACSGui_Module::getCanvas");
775 QxGraph_Canvas* aCanvas = 0;
776 QxGraph_Viewer* aViewer = getViewer();
778 aCanvas = aViewer->getCanvas();
782 void YACSGui_Module::createElementaryNodePrs()
784 MESSAGE("YACSGui_Module::createElementaryNodePrs --- NOT YET IMPLEMENTED!");
787 YACS::ENGINE::Node* aNode = 0; // temporary solution for test
788 YACSPrs_ElementaryNode* anElemNode =
789 new YACSPrs_ElementaryNode(SUIT_Session::session()->resourceMgr(), myGraph->getCanvas(), aNode);
790 myGraph->getCanvas()->getPrs()->addItem(anElemNode); // add item for the current display mode
792 myGraph->getCanvas()->update();
796 //! Create new instance of data model and return it.
799 CAM_DataModel* YACSGui_Module::createDataModel()
801 MESSAGE("YACSGui_Module::createDataModel");
802 return new YACSGui_DataModel( this );
805 //! Retuns data model.
808 YACSGui_DataModel* YACSGui_Module::getDataModel() const
810 MESSAGE("YACSGui_Module::getDataModel");
811 YACSGui_DataModel* aModel = dynamic_cast<YACSGui_DataModel*>( dataModel() );
815 //! Load dataflow from file.
817 * \param setEditable - define if the dataflow wiil be editable.
819 void YACSGui_Module::ImportDataflowFromFile(const bool setEditable, bool fromSuperv)
821 MESSAGE("YACSGui_Module::ImportDataflowFromFile");
826 caption = QString(tr("TLT_MODIFY_SUPERV_DATAFLOW"));
828 caption = QString(tr("TLT_IMPORT_SUPERV_DATAFLOW"));
833 caption = QString(tr("TLT_MODIFY_DATAFLOW"));
835 caption = QString(tr("TLT_IMPORT_DATAFLOW"));
837 QString aFileName = SUIT_FileDlg::getFileName( application()->desktop(), "", "*.xml", caption, true );
839 if (aFileName.isEmpty())
841 QString tmpFileName = aFileName;
845 YACSGui_ORB::YACSGui_Gen_ptr engineRef = InitYACSGuiGen(getApp());
848 tmpFileName = engineRef->convertSupervFile(aFileName);
852 std::cerr<<"Unexpected exception in convertSupervFile " <<std::endl;
853 SUIT_MessageBox::warn1(getApp()->desktop(),
855 tr("Unexpected exception in convertSupervFile"),
861 //TD: Here check if the study already contains a graph imported from the same file
863 YACSGui_Loader aLoader;
868 if (!tmpFileName.isEmpty())
869 aProc = aLoader.load(tmpFileName);
871 //TD: Check the result of file loading
874 SUIT_MessageBox::error1(getApp()->desktop(),
876 tr("MSG_IMPORT_FILE_ERROR"),
881 aProc->setName(QFileInfo(aFileName).fileName ());
883 SUIT_ViewManager* aVM = getApp()->createViewManager( QxGraph_Viewer::Type() );
885 // set caption for graph's view window
886 QxGraph_ViewWindow* aVW = dynamic_cast<QxGraph_ViewWindow*>( aVM->getActiveView() );
887 if ( aVW ) aVW->setCaption(QFileInfo(aFileName).fileName ());
889 YACSGui_DataModel* aModel = getDataModel();
891 aModel->add(aProc, setEditable);
892 // TD: add graph to study.
895 const YACSGui_Loader::PrsDataMap& aPrsData = aLoader.getPrsData( aProc, w, h );
896 const YACSGui_Loader::PortLinkDataMap& aPortLinkData = aLoader.getPortLinkData( aProc );
897 const YACSGui_Loader::LabelLinkDataMap& aLabelLinkData = aLoader.getLabelLinkData( aProc );
900 if ( w > 0 && h > 0 )
901 aVW->getViewModel()->getCanvas()->resize( w, h );
902 displayGraph( aProc, aPrsData, aPortLinkData, aLabelLinkData );
905 catch (YACS::Exception& ex)
907 std::cerr<<"YACSGui_Module::importDataflow: " <<ex.what()<<std::endl;
911 //! Returns or create executor for a given graph.
914 YACSGui_Executor* YACSGui_Module::getExecutor( YACS::ENGINE::Proc* theProc )
916 MESSAGE("YACSGui_Module::getExecutor");
917 YACSGui_Executor* anExecutor = 0;
919 ExecutorMap::iterator anIterator = myExecutors.find(theProc);
920 if (anIterator != myExecutors.end())
921 anExecutor = (*anIterator).second;
925 anExecutor = new YACSGui_Executor(this, theProc);
926 anExecutor->setGraph(activeGraph());
927 myExecutors[theProc] = anExecutor;
933 //! Returns executor for active graph or nul if no active graph
936 YACSGui_Executor* YACSGui_Module::findExecutor()
938 MESSAGE("YACSGui_Module::findExecutor");
939 YACSGui_Graph* aGraph = activeGraph();
940 YACSGui_Executor* anExecutor = 0;
943 aProc = aGraph->getProc();
945 if (!aGraph || !aProc)
947 SUIT_MessageBox::warn1(getApp()->desktop(),
949 tr("MSG_NO_DATAFLOW_LOADED"),
954 anExecutor = getExecutor(aProc);
958 YACSGui_RunMode* YACSGui_Module::getRunMode(YACSGui_Executor* executor)
960 RunModeMap::iterator anIterator = _runModeMap.find(executor);
961 YACSGui_RunMode* aRunMode = 0;
962 if (anIterator != _runModeMap.end())
963 aRunMode = _runModeMap[executor];