1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SUPERVGUI.cxx
25 // Author : Francis KLOSS
29 #include "SUPERVGUI.h"
30 #include "SUPERVGUI_DataModel.h"
31 #include "SUPERVGUI_Selection.h"
33 #include "SALOMEDSClient.hxx"
34 #include <boost/shared_ptr.hpp>
35 using namespace boost;
37 #include "CAM_Application.h"
38 #include "OB_Browser.h"
39 #include "OB_ListItem.h"
40 #include "SalomeApp_Application.h"
41 #include "SalomeApp_ImportOperation.h"
42 #include "SalomeApp_NameDlg.h"
43 #include "SalomeApp_SelectionMgr.h"
44 #include "SalomeApp_Study.h"
45 #include "SUIT_Desktop.h"
46 #include "SUIT_FileDlg.h"
47 #include "SUIT_MessageBox.h"
48 #include "SUIT_Operation.h"
49 #include "SUIT_ResourceMgr.h"
50 #include "SUIT_Session.h"
51 #include "SUIT_Study.h"
53 #include "SUPERVGraph_ViewManager.h"
55 #include "SALOME_ListIO.hxx"
56 #include "SALOME_ListIteratorOfListIO.hxx"
57 #include "SALOME_InteractiveObject.hxx"
58 #include "Utils_ORB_INIT.hxx"
60 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
64 int SUPERVGUI::factory = 0;
67 Standard_EXPORT CAM_Module* createModule() {
68 return new SUPERVGUI();
73 SUPERVGUI::SUPERVGUI()
74 : SalomeApp_Module( "SUPERV" ),
77 myFirstActivation(true),
78 myAllGraphsClosed(false),
82 Trace("SUPERVGUI::SUPERVGUI")
85 MESSAGE("SUPERVGUI Info : factory build");
87 MESSAGE("SUPERVGUI Error : another call to factory constructor");
91 SUPERVGUI::~SUPERVGUI() {
92 Trace("SUPERVGUI::~SUPERVGUI")
95 //if (!engine->_is_nil()) CORBA::release(engine);
98 if (browser->isVisible())
102 MESSAGE("SUPERVGUI Info : factory destroy");
104 MESSAGE("SUPERVGUI Error : another call to factory destructor");
108 SUPERVGUI* SUPERVGUI::Supervision() {
109 CAM_Application* anApp = dynamic_cast<CAM_Application*>( SUIT_Session::session()->activeApplication() );
111 SUPERVGUI* aSupervModule = dynamic_cast<SUPERVGUI*>( anApp->activeModule() );
112 return aSupervModule;
117 void SUPERVGUI::createSupervAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle )
120 QWidget* parent = application()->desktop();
121 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
123 if ( icon_id.length() )
124 pix = resMgr->loadPixmap( "SUPERV", tr( icon_id ) );
126 pix = resMgr->loadPixmap( "SUPERV", tr( QString( "ICO_" )+po_id ) );
128 icon = QIconSet( pix );
130 QString tooltip = tr( QString( "TOP_" )+po_id ),
131 menu = tr( QString( "MEN_" )+po_id ),
132 status_bar = tr( QString( "STB_" )+po_id );
134 createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() ) );
137 void SUPERVGUI::initialize( CAM_Application* app )
139 SalomeApp_Module::initialize( app );
141 SALOME_NamingService* namingService = (( SalomeApp_Application* )application())->namingService();
142 loadEngine(namingService);
144 browser = new SUPERVGUI_Service(namingService);
145 //info = new SUPERVGUI_Information();
146 cursor = application()->desktop()->cursor();
148 fillInterfaceNameMap();
150 // ----- create actions --------------
151 createSupervAction( 301, "IMPORT" );
152 createSupervAction( 302, "EXPORT" );
154 createSupervAction( 303, "NEW" );
155 createSupervAction( 304, "MODIFY" );
157 createSupervAction( 305, "RELOAD" );
158 createSupervAction( 306, "RUN" );
159 createSupervAction( 307, "KILL" );
160 createSupervAction( 308, "SUSPEND/RESUME" );
161 createSupervAction( 309, "ADDNODE" );
162 createSupervAction( 310, "STEPBYSTEP" );
164 createSupervAction( 311, "POP_RENAME" );
165 createSupervAction( 312, "POP_DISPLAY" );
166 createSupervAction( 313, "POP_DELETE" );
168 // ----- create menu -----------------
169 int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
170 createMenu( 301, fileId, 10 );
171 createMenu( 302, fileId, 10 );
172 createMenu( separator(), fileId, 10 );
174 int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
175 createMenu( separator(), fileId, 7 );
176 createMenu( 303, editId, -1 );
177 createMenu( 304, editId, -1 );
179 int supervId = createMenu( tr( "MEN_SUPERV" ), -1, -1, 10/*, 300*/ );
180 createMenu( 305, supervId, -1 );
181 createMenu( 309, supervId, -1 );
182 createMenu( separator(), fileId, 3 );
183 createMenu( 306, supervId, -1 );
184 createMenu( 310, supervId, -1 );
185 createMenu( 307, supervId, -1 );
186 createMenu( 308, supervId, -1 );
188 // ----- create toolbars -------------
189 int supervisorId = createTool( tr( "TOOL_SUPERVISOR" ) );
190 createTool( 301, supervisorId );
191 createTool( 302, supervisorId );
192 createTool( 303, supervisorId );
193 createTool( 304, supervisorId );
194 createTool( 305, supervisorId );
195 createTool( 309, supervisorId );
197 int executionId = createTool( tr( "TOOL_EXECUTION" ) );
198 createTool( 306, executionId );
199 createTool( 310, executionId );
200 createTool( 307, executionId );
201 createTool( 308, executionId );
203 // ----- create popup for object browser items -------------
204 QtxPopupMgr* mgr = popupMgr();
205 mgr->insert( action( 311 ), -1, -1 ); // rename dataflow
206 mgr->setRule( action( 311 ), "$type in {'Dataflow'} and selcount=1", true );
207 mgr->insert( action( 312 ), -1, -1 ); // display dataflow
208 mgr->setRule( action( 312 ), "$type in {'Dataflow'} and selcount=1", true );
209 mgr->insert( separator(), -1, -1 ); // -----------
210 mgr->insert( action( 313 ), -1, -1 ); // delete object
211 mgr->setRule( action( 313 ), "$client in {'ObjectBrowser'} and $type in {'Dataflow' 'SupervisorObject'} and selcount>0", true );
214 bool SUPERVGUI::activateModule( SUIT_Study* theStudy )
216 if ( CORBA::is_nil( engine ) )
219 if ( !SalomeApp_Module::activateModule( theStudy ) )
224 //---------------------------------------
225 setMenuShown( true );
226 setToolShown( true );
228 study = application()->activeStudy();
230 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
231 this, SLOT( setMain( SUIT_ViewWindow* ) ) );
233 if ( myFirstActivation ) {
234 myAllGraphsClosed = false;
235 // create new empty dataflow
236 createDataflow( New, true );
242 QString SUPERVGUI::engineIOR() const
244 if ( !CORBA::is_nil( engine ) )
245 return QString( getApp()->orb()->object_to_string( engine));
246 return QString( "" );
249 bool SUPERVGUI::deactivateModule( SUIT_Study* theStudy )
251 setMenuShown( false );
252 setToolShown( false );
254 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
255 this, SLOT( setMain( SUIT_ViewWindow* ) ) );
256 //---------------------------------------
258 if ( !myAllGraphsClosed )
259 myFirstActivation = false;
261 return SalomeApp_Module::deactivateModule( theStudy );
264 CAM_DataModel* SUPERVGUI::createDataModel()
266 return new SUPERVGUI_DataModel( this );
269 SalomeApp_Selection* SUPERVGUI::createSelection() const
271 return new SUPERVGUI_Selection();
274 SUIT_ViewWindow* SUPERVGUI::createGraph() {
275 SUPERVGraph_ViewManager* aVM = new SUPERVGraph_ViewManager( study, application()->desktop(), new SUPERVGraph_Viewer() );
276 (( SalomeApp_Application* )application())->addViewManager( aVM );
277 SUIT_ViewWindow* aVW = aVM->createViewWindow();
280 SIGNAL( deleteView( SUIT_ViewWindow* ) ),
282 SLOT( onGraphClosed( SUIT_ViewWindow* ) ) );
289 void SUPERVGUI::loadEngine(SALOME_NamingService* namingService) {
290 Trace("SUPERVGUI::loadEngine")
291 SALOME_LifeCycleCORBA LCC(namingService);
292 Engines::Component_var objComponent = LCC.FindOrLoad_Component("SuperVisionContainer", "SUPERV");
293 if (CORBA::is_nil(objComponent)) {
294 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_CANT_LOAD_SUPERV"));
298 SUPERV::SuperG_var aSuperVisionComponent;
299 aSuperVisionComponent = SUPERV::SuperG::_narrow(objComponent);
300 if (CORBA::is_nil(aSuperVisionComponent)) {
301 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_CANT_NARROW_SUPERV"));
305 // engine = new SUPERV::SuperG_var;
306 engine = aSuperVisionComponent;
310 bool SUPERVGUI::information(SUPERV_CNode node, bool isReadOnly) {
311 Trace("SUPERVGUI::information")
312 return(info->run(node, isReadOnly));
315 void SUPERVGUI::putInfo(const char* mess) {
316 Trace("SUPERVGUI::putInfo")
317 application()->putInfo(mess);
320 SUPERV_Engine SUPERVGUI::getEngine() {
321 Trace("SUPERVGUI::getEngine")
325 SUPERVGUI_Service* SUPERVGUI::getBrowser() {
326 Trace("SUPERVGUI::getBrowser")
330 QCursor SUPERVGUI::getCursor() {
331 Trace("SUPERVGUI::getCursor")
335 SUPERVGUI_Main* SUPERVGUI::getMain() {
336 Trace("SUPERVGUI::getMain")
341 void SUPERVGUI::registerGraph(QString theName, SUPERVGUI_Main* theGraph){
342 theGraph->setHashCode(theName);
343 myGraphList.append(theGraph);
347 void SUPERVGUI::unregisterGraph(SUPERVGUI_Main* theGraph) {
348 SUPERVGUI_Main* aMain;
349 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
350 if (aMain == theGraph)
351 myGraphList.remove(aMain);
356 bool SUPERVGUI::isContains(SUIT_Study* theStudy, const QString theKey) {
357 SUPERVGUI_Main* aMain;
358 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
359 if ((aMain->getStudy() == theStudy) && (aMain->getHashCode() == theKey))
366 void SUPERVGUI::onGraphClosed(SUIT_ViewWindow* theViewWindow) {
367 if( SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(theViewWindow) ) {
368 disconnect(supervFrame->getViewManager(), 0 , this, 0);
369 SUPERVGraph_View* view = supervFrame->getViewWidget();
370 SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
372 unregisterGraph(aGraph);
373 SUPERV_Graph aDataFlow = aGraph->getDataflow();
374 if ( !SUPERV_isNull( aDataFlow ) ) {
375 if ( aDataFlow->IsExecuting() ) {
376 const int aMsgResult = QMessageBox::warning(application()->desktop(),
378 tr("MSG_DF_RUNNING"),
379 tr("MSG_DF_EXECUTION"),
381 if ( aMsgResult == 1 ) {
383 if ( aDataFlow->Kill() ) {
384 // Kill() sends KillEvent and KillState to SUPERVGUI_Thread
385 // while sets myIsActive flag to false when it receives such event/state
386 // after myIsActive is false it calls QThread::exit() to terminate.
388 // why while() { qApp->processEvents() } ?
389 // because: SUPERVGUI_Thread::run() receives events, and calls myMain->execute()
390 // method using SALOME_Event paradigm, ProcessVoidEvent() function -
391 // it puts this event to the main application event loop, in which we are being now.
392 // So if we block main GUI application thread (by calling aGraph->getMyThread()->wait() here)
393 // then we will have a deadlock of 2 threads waiting for one another
394 while (aGraph->getMyThread()->running())
395 qApp->processEvents();
398 else { // BACKGROUND EXECUTION
399 emit KillMainThread(true); // set SUPERVGUI_Thread::myIsActive to false
400 while ( aGraph->getMyThread()->running() )
401 qApp->processEvents();
404 else { // EXECUTION IS FINISHED, JUST DESTROY THE SUPERVGUI_Thread object and return.
405 emit KillMainThread(true);
406 while ( aGraph->getMyThread()->running() )
407 qApp->processEvents();
412 if ( myGraphList.isEmpty() ) {
413 myAllGraphsClosed = true;
414 myFirstActivation = true;
415 myInitialViewFrame = 0;
420 void SUPERVGUI::setMain( SUIT_ViewWindow* w) {
424 study = w->getViewManager()->study();
428 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(w)){
429 SUPERVGraph_View* view = supervFrame->getViewWidget();
431 main = dynamic_cast<SUPERVGUI_Main*>(view);
432 connect(this, SIGNAL(KillMainThread(bool)), main->getMyThread(), SLOT(KillThread(bool)));
435 Trace("SUPERVGUI::setMain - main: "<<main);
438 void SUPERVGUI::displayDataflow() {
439 Trace("SUPERVGUI::displayDataflow");
440 OB_Browser* aBrowser = (( SalomeApp_Application* )application())->objectBrowser();
441 SUPERV_Graph aDataFlow;
444 OB_ListItem* item = (OB_ListItem*)(aBrowser->listView()->currentItem());
446 ( (( SalomeApp_Study* )(application()->activeStudy()))->studyDS()->FindObjectID(item->text(2).latin1()) );
447 _PTR(GenericAttribute) anAttr;
448 if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
449 _PTR(AttributeIOR) anIOR ( anAttr );
450 aIORName = QString(anIOR->Value().c_str());
451 if (isContains(study, aIORName)) {
452 if (QMessageBox::warning(application()->desktop(), tr("WARNING"),
453 tr("MSG_GRAPH_DISPLAYED").arg(""),
454 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
457 //aDataFlow = engine->getStreamGraph(anIOR->Value().c_str());
458 aDataFlow = engine->getGraph(anIOR->Value().c_str());
459 if (SUPERV_isNull(aDataFlow)) {
460 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
463 /* ASV: 20.10.04: fix for 6896
464 if (aDataFlow->IsStreamGraph()) {
465 SUPERV_StreamGraph aDataFlowStream = aDataFlow->ToStreamGraph();
466 if (SUPERV_isNull(aDataFlowStream)) {
467 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
470 aDataFlow = aDataFlowStream;
475 SUPERVGraph_ViewFrame* aViewFrame;
476 if ( !myInitialViewFrame ) {
477 // first case : create a ViewFrame object
478 aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( createGraph() );
481 // second case : get empty initial view frame as new ViewFrame object
482 aViewFrame = myInitialViewFrame;
483 myInitialViewFrame = 0;
487 main = new SUPERVGUI_Main( aViewFrame, application()->desktop(), aDataFlow );
488 registerGraph( aIORName, main );
494 void SUPERVGUI::renameDataflow() {
497 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
499 SALOME_ListIteratorOfListIO It( aList );
500 for ( ; It.More(); It.Next() ) {
501 Handle(SALOME_InteractiveObject) IObject = It.Value();
503 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
504 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
505 _PTR(GenericAttribute) anAttr;
507 if ( obj->FindAttribute(anAttr, "AttributeName") ) {
508 _PTR(AttributeName) aName ( anAttr );
509 QString nm = QString( aName->Value().c_str() );
510 nm = SalomeApp_NameDlg::getName( application()->desktop(), nm );
511 if ( !nm.isEmpty() ) {
512 // sak : 24.11.04 : fix for PAL6898 : if rename fails (study locked),
513 // a message box is displayed, and cursor is "wait cursor". We think that "wait cursor"
514 // is not neccessary here, because the rename operation is fast.
515 //QApplication::setOverrideCursor( Qt::waitCursor );
516 //study->renameIObject( IObject, nm );
519 aName->SetValue( nm.latin1() );
520 //rename Interactive object
521 IObject->setName( ( char* )nm.latin1() );
525 //QApplication::restoreOverrideCursor();
532 void SUPERVGUI::exportDataflow() {
533 Trace("SUPERVGUI::exportDataflow")
535 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
537 else if ( SUPERV_isNull( main->getDataflow() ) ) { // should not normally happen..
538 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
541 QString f = SUIT_FileDlg::getFileName(application()->desktop(),
544 tr("TTL_EXPORT_DATAFLOW"),
546 if ( !f.isEmpty() ) {
548 // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file,
549 // a backup copy of an existing file must be created (in case Export fails..)
550 QString aBackupFile = SUPERVGUI::createBackupFile( f );
552 if ( main->getDataflow()->Export(f.latin1()) ) {
553 unregisterGraph(main);
554 registerGraph(f, main);
556 // remove a backup file if export was successfull
557 if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() )
558 QFile::remove( aBackupFile );
561 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile));
568 *If a file with theOriginalFileName exists, then the function tries to create
569 * its backup copy of it (the_name + ".bakX", X = 0,1,2,..,99). Returns backup file's name
570 * If a file with theOriginalFileName does not exist, or creation fails - Return empty string.
572 QString SUPERVGUI::createBackupFile( const QString& theOriginalFileName ) {
573 QString theBackupFileName("");
574 if ( QFile::exists( theOriginalFileName ) ) {
575 // 1. construct a backup file name
578 theBackupFileName = theOriginalFileName;
579 theBackupFileName += ".bak";
580 theBackupFileName += QString::number(i++);
582 while ( QFile::exists( theBackupFileName ) && i < 100 ); // max 99 backup files
583 // if *.bak99 exists -- it will be overwritten
585 // 2. copy the original file to theBackupFileName
586 QString cmd( "cp \"");
587 cmd += theOriginalFileName;
589 cmd += theBackupFileName;
591 bool res = system( cmd.latin1() );
593 theBackupFileName = QString("");
595 return theBackupFileName;
598 void SUPERVGUI::windows( QMap<int, int>& mappa ) const
600 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
601 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
602 mappa.insert( SalomeApp_Application::WT_LogWindow, Qt::DockBottom );
605 void SUPERVGUI::newDataflow() {
606 createDataflow( New );
609 void SUPERVGUI::importDataflow() {
610 createDataflow( Import );
613 void SUPERVGUI::modifyDataflow() {
614 createDataflow( Modify );
617 bool SUPERVGUI::createDataflow( const NEW_DF_MODE mode, bool theInitialDF ) {
618 Trace("SUPERVGUI::createDataflow, mode = " << mode );
620 // asv : 27.01.05 : fix for PAL7823 : if the study is locked - warn the user and return.
621 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
622 if ( aStudy->GetProperties()->IsLocked() ) {
623 QMessageBox::warning(application()->desktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"));
627 SUPERV::Graph_var aGraph;
629 QString f; // file name. declared here because may be used below in error msg construction..
630 if ( mode == Import || mode == Modify ) { // 0. import or modify existing dataflow - select XML file
631 QString title = QString( "TLT_CREATE_DF_%1" ).arg( mode );
632 f = SUIT_FileDlg::getFileName( application()->desktop(), "", "*.xml", tr( title ), true );
633 if ( f.isEmpty() ) // pressed Cancel in file select dialog
636 // check if study already contains a graph imported from the same file
637 if ( isContains( study, f ) ) {
638 if ( QMessageBox::warning( application()->desktop(), tr("WARNING"), tr("MSG_GRAPH_DISPLAYED").arg(f),
639 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No )
644 aGraph = ( mode == Import ) ? engine->StreamGraphE( f ) : engine->StreamGraph( f );
647 aGraph = engine->StreamGraph( MAIN_NEW );
649 if ( CORBA::is_nil( aGraph ) ) {
650 QString msg( mode == New ? tr("MSG_CANT_CREATE_DF") : tr("MSG_BAD_FILE").arg(f) );
651 SUIT_MessageBox::warn1( application()->desktop(), tr("ERROR"), tr(msg), tr("BUT_OK") );
655 SUPERVGraph_ViewFrame* aViewFrame;
656 if ( theInitialDF || !myInitialViewFrame ) {
657 // 2. create a ViewFrame object
658 aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( createGraph() );
661 // 2. get empty initial view frame as new ViewFrame object
662 aViewFrame = myInitialViewFrame;
663 myInitialViewFrame = 0;
668 // 3. bind Graph and ViewFrame == create SUPERVGUI_Main object
669 main = new SUPERVGUI_Main( aViewFrame, application()->desktop(), aGraph );
674 myInitialViewFrame = aViewFrame;
677 registerGraph( f, main );
684 void SUPERVGUI::reloadDataflow() {
685 Trace("SUPERVGUI::reloadDataflow");
689 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RELOAD"));
692 void SUPERVGUI::runDataflow() {
693 Trace("SUPERVGUI::runDataflow");
695 main->run( /*andSuspend=*/false );
697 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
700 void SUPERVGUI::stepByStep() {
701 Trace("SUPERVGUI::stepByStep");
703 main->run( /*andSuspend=*/true );
705 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
708 void SUPERVGUI::killDataflow() {
709 Trace("SUPERVGUI::killDataflow");
713 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_KILL"));
716 void SUPERVGUI::suspendResumeDataflow() {
717 Trace("SUPERVGUI::suspendResumeDataflow");
719 main->suspendResume();
721 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_SUSPEND"));
724 void SUPERVGUI::showComponents() {
725 Trace("SUPERVGUI::showComponents");
727 if ( main->isEditable() )
730 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOTEDITABLE"));
733 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_ADD"));
738 /*bool SUPERVGUI::CustomPopup(QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) {
739 Trace("SUPERVGUI::customPopup");
741 if(popup->count() > 3) {
742 // Temporary code: is to be deleted soon
743 popup->removeItem(QAD_Display_Popup_ID);
744 popup->removeItem(QAD_DisplayOnly_Popup_ID);
745 popup->removeItem(QAD_Erase_Popup_ID);
746 int id = popup->idAt(popup->count() - 1);
747 if (id < 0 && id != -1) popup->removeItem(id); // separator
748 // Temporary code end
753 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
754 if ( aList.Extent() == 0 ) return false;
756 if ( aList.Extent() == 1 ) {
757 Handle(SALOME_InteractiveObject) anIObj = aList.First();
759 // insert SUPERV-specific popup items here
761 bool isDataflow, ownObj;
762 whatIsSelected(anIObj, ownObj, isDataflow);
765 popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow()));
766 popup->insertItem("Display", this, SLOT(displayDataflow()));
767 popup->insertSeparator();
770 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
773 if ( aList.Extent() > 1 ) {
775 SALOME_ListIteratorOfListIO It_forCheckOwner( aList );
776 for(;It_forCheckOwner.More();It_forCheckOwner.Next()) {
777 Handle(SALOME_InteractiveObject) anIObj = It_forCheckOwner.Value();
778 bool aIsOwner, aIsDataflow;
779 whatIsSelected(anIObj, aIsOwner, aIsDataflow);
781 if (aIsOwner) aIObjCount++;
783 if ( aIObjCount == aList.Extent() ) //all selected objects belong to Supervision
784 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
793 theIsOwner = true if Selected object belongs to Supervision.
794 theIsDataflow = true if Selected object is Dataflow
796 void SUPERVGUI::whatIsSelected(const _PTR(SObject)& theObj, bool& theIsOwner, bool& theIsDataflow) {
798 theIsDataflow = false;
801 _PTR(SComponent) comp ( theObj->GetFatherComponent() );
803 _PTR(GenericAttribute) anAttr;
804 if (comp->FindAttribute(anAttr, "AttributeName")) {
805 _PTR(AttributeName) aName ( anAttr );
806 QString compName(aName->Value().c_str());
807 if ( compName.compare( moduleName() ) == 0 ) {
808 _PTR(GenericAttribute) anAttr;
809 if (theObj->FindAttribute(anAttr, "AttributeIOR")) {
810 _PTR(AttributeIOR) anIOR ( anAttr );
811 SUPERV_Graph aDataFlow = engine->getGraph(anIOR->Value().c_str());
812 if (!SUPERV_isNull(aDataFlow)) {
813 if (aDataFlow->IsStreamGraph()) {
814 if (!SUPERV_isNull(aDataFlow->ToStreamGraph()))
815 theIsDataflow = true;
818 theIsDataflow = true;
821 CORBA::String_var anObjectID = theObj->GetID().c_str();
822 CORBA::String_var aComponentID = comp->GetID().c_str();
823 if (strcmp(anObjectID, aComponentID))
831 void SUPERVGUI::deleteObject() {
834 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
835 if ( aList.Extent() == 0 ) return;
837 // sak : 24.11.04 : fix for PAL6899 : if the study is locked - warn the user and return.
838 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
839 if ( aStudy->GetProperties()->IsLocked() ) {
840 QMessageBox::warning(application()->desktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"));
844 // sak : 24.11.04 : fix for PAL6901 : Incorrect deletion of the objects : pressing ESC button
845 // emitted "YES" button click, now it is corrected, and treated as "NO" button click.
846 if (QMessageBox::warning(application()->desktop(),
848 tr("MSG_ASK_DELETE"),
849 QMessageBox::No, QMessageBox::Yes) != QMessageBox::Yes)
852 SALOME_ListIteratorOfListIO It( aList );
853 for(;It.More();It.Next()) {
854 Handle(SALOME_InteractiveObject) anIObj = It.Value();
855 //bool aIsOwner, aIsDataflow;
856 //whatIsSelected(anIObj, aIsOwner, aIsDataflow);
858 _PTR(SObject) aObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
860 SUIT_Operation* op = new SalomeApp_ImportOperation( application() );
861 _PTR(StudyBuilder) aBuilder ( aStudy->NewBuilder() );
863 aBuilder->RemoveObjectWithChildren( aObj );
867 (( SalomeApp_Application* )application())->selectionMgr()->clearSelected();
871 void SUPERVGUI::OnGUIEvent()
873 const QObject* obj = sender();
874 if ( !obj || !obj->inherits( "QAction" ) )
876 int id = actionId((QAction*)obj);
881 bool SUPERVGUI::OnGUIEvent(int command) {
912 suspendResumeDataflow();
936 QMessageBox::warning(application()->desktop(), "Supervision Error", "Unknown Command From Salome");
941 /*bool SUPERVGUI::SetSettings() {
942 Trace("SUPERVGUI::SetSettings");
947 /*void SUPERVGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject) {
952 bool SUPERVGUI::ActiveStudyChanged() {
953 Trace("SUPERVGUI::activeStudyChanged");
954 study = application()->activeStudy();
958 /*void SUPERVGUI::SupportedViewType (int* buffer, int bufferSize)
960 if (!buffer || !bufferSize) return;
961 buffer[0] = (int)VIEW_GRAPHSUPERV;
964 void SUPERVGUI::fillInterfaceNameMap() {
965 //fill map: interface_name <-> component_name for all
966 //interfaces of all loaded components, it is necessary
967 //for correct adding factory nodes from AddComponent,
968 //SubComponent, MulComponent, etc. components.
969 myInterfaceNameMap.clear();
972 SALOME_NamingService* namingService = (( SalomeApp_Application* )application())->namingService();
974 CORBA::Object_ptr obj = namingService->Resolve("/Kernel/ModulCatalog");
975 SALOME_ModuleCatalog::ModuleCatalog_var* aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var;
976 *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
977 if (!CORBA::is_nil(*aModuleCatalog)) {
979 SALOME_ModuleCatalog::ListOfComponents_var aCompList = (*aModuleCatalog)->GetComponentList();
980 for (int ind1 = 0; ind1 < aCompList->length(); ind1++) {
982 SALOME_ModuleCatalog::Acomponent_ptr aComponent = (*aModuleCatalog)->GetComponent(aCompList[ind1]);
983 if ( aComponent != NULL ) {
985 SALOME_ModuleCatalog::ListOfInterfaces_var anIntList = aComponent->GetInterfaceList();
986 for (int ind2 = 0; ind2 < anIntList->length(); ind2++) {
987 const char* anIntName = anIntList[ind2];
988 myInterfaceNameMap.insert(QString(anIntName), QString(aComponent->componentname()));
995 QMap<QString, QString> SUPERVGUI::getInterfaceNameMap() const {
996 return myInterfaceNameMap;