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,
118 const int key, const bool toggle)
121 QWidget* parent = application()->desktop();
122 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
124 if (!icon_id.isEmpty())
125 pix = resMgr->loadPixmap("SUPERV", tr(icon_id));
127 // pix = resMgr->loadPixmap("SUPERV", tr(QString("ICO_") + po_id));
130 icon = QIconSet(pix);
132 QString tooltip = tr(QString("TOP_") + po_id),
133 menu = tr(QString("MEN_") + po_id),
134 status_bar = tr(QString("STB_") + po_id);
136 createAction(id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT(OnGUIEvent()));
139 void SUPERVGUI::initialize( CAM_Application* app )
141 SalomeApp_Module::initialize( app );
143 SALOME_NamingService* namingService = (( SalomeApp_Application* )application())->namingService();
144 loadEngine(namingService);
146 browser = new SUPERVGUI_Service(namingService);
147 //info = new SUPERVGUI_Information();
148 cursor = application()->desktop()->cursor();
150 fillInterfaceNameMap();
152 // ----- create actions --------------
153 createSupervAction( 301, "IMPORT" , "ICO_IMPORT" );
154 createSupervAction( 302, "EXPORT" , "ICO_EXPORT" );
156 createSupervAction( 303, "NEW" , "ICO_NEW" );
157 createSupervAction( 304, "MODIFY" , "ICO_MODIFY" );
159 createSupervAction( 305, "RELOAD" , "ICO_RELOAD" );
160 createSupervAction( 306, "RUN" , "ICO_RUN" );
161 createSupervAction( 307, "KILL" , "ICO_KILL" );
162 createSupervAction( 308, "SUSPEND/RESUME", "ICO_SUSPEND/RESUME" );
163 createSupervAction( 309, "ADDNODE" , "ICO_ADDNODE" );
164 createSupervAction( 310, "STEPBYSTEP" , "ICO_STEPBYSTEP" );
166 createSupervAction( 311, "POP_RENAME" );
167 createSupervAction( 312, "POP_DISPLAY" );
168 createSupervAction( 313, "POP_DELETE" );
170 // ----- create menu -----------------
171 int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
172 createMenu( 301, fileId, 10 );
173 createMenu( 302, fileId, 10 );
174 createMenu( separator(), fileId, 10 );
176 int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
177 createMenu( separator(), fileId, 7 );
178 createMenu( 303, editId, -1 );
179 createMenu( 304, editId, -1 );
181 int supervId = createMenu( tr( "MEN_SUPERV" ), -1, -1, 10/*, 300*/ );
182 createMenu( 305, supervId, -1 );
183 createMenu( 309, supervId, -1 );
184 createMenu( separator(), fileId, 3 );
185 createMenu( 306, supervId, -1 );
186 createMenu( 310, supervId, -1 );
187 createMenu( 307, supervId, -1 );
188 createMenu( 308, supervId, -1 );
190 // ----- create toolbars -------------
191 int supervisorId = createTool( tr( "TOOL_SUPERVISOR" ) );
192 createTool( 301, supervisorId );
193 createTool( 302, supervisorId );
194 createTool( 303, supervisorId );
195 createTool( 304, supervisorId );
196 createTool( 305, supervisorId );
197 createTool( 309, supervisorId );
199 int executionId = createTool( tr( "TOOL_EXECUTION" ) );
200 createTool( 306, executionId );
201 createTool( 310, executionId );
202 createTool( 307, executionId );
203 createTool( 308, executionId );
205 // ----- create popup for object browser items -------------
206 QtxPopupMgr* mgr = popupMgr();
207 mgr->insert( action( 311 ), -1, -1 ); // rename dataflow
208 mgr->setRule( action( 311 ), "$type in {'Dataflow'} and selcount=1", true );
209 mgr->insert( action( 312 ), -1, -1 ); // display dataflow
210 mgr->setRule( action( 312 ), "$type in {'Dataflow'} and selcount=1", true );
211 mgr->insert( separator(), -1, -1 ); // -----------
212 mgr->insert( action( 313 ), -1, -1 ); // delete object
213 mgr->setRule( action( 313 ), "$client in {'ObjectBrowser'} and $type in {'Dataflow' 'SupervisorObject'} and selcount>0", true );
216 bool SUPERVGUI::activateModule( SUIT_Study* theStudy )
218 if ( CORBA::is_nil( engine ) )
221 if ( !SalomeApp_Module::activateModule( theStudy ) )
226 //---------------------------------------
227 setMenuShown( true );
228 setToolShown( true );
230 study = application()->activeStudy();
232 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
233 this, SLOT( setMain( SUIT_ViewWindow* ) ) );
235 if ( myFirstActivation ) {
236 myAllGraphsClosed = false;
237 // create new empty dataflow
238 createDataflow( New, true );
244 QString SUPERVGUI::engineIOR() const
246 if ( !CORBA::is_nil( engine ) )
247 return QString( getApp()->orb()->object_to_string( engine));
248 return QString( "" );
251 bool SUPERVGUI::deactivateModule( SUIT_Study* theStudy )
253 setMenuShown( false );
254 setToolShown( false );
256 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
257 this, SLOT( setMain( SUIT_ViewWindow* ) ) );
258 //---------------------------------------
260 if ( !myAllGraphsClosed )
261 myFirstActivation = false;
263 return SalomeApp_Module::deactivateModule( theStudy );
266 CAM_DataModel* SUPERVGUI::createDataModel()
268 return new SUPERVGUI_DataModel( this );
271 SalomeApp_Selection* SUPERVGUI::createSelection() const
273 return new SUPERVGUI_Selection();
276 SUIT_ViewWindow* SUPERVGUI::createGraph() {
277 SUPERVGraph_ViewManager* aVM = new SUPERVGraph_ViewManager( study, application()->desktop(), new SUPERVGraph_Viewer() );
278 (( SalomeApp_Application* )application())->addViewManager( aVM );
279 SUIT_ViewWindow* aVW = aVM->createViewWindow();
282 SIGNAL( deleteView( SUIT_ViewWindow* ) ),
284 SLOT( onGraphClosed( SUIT_ViewWindow* ) ) );
291 void SUPERVGUI::loadEngine(SALOME_NamingService* namingService) {
292 Trace("SUPERVGUI::loadEngine")
293 SALOME_LifeCycleCORBA LCC(namingService);
294 Engines::Component_var objComponent = LCC.FindOrLoad_Component("SuperVisionContainer", "SUPERV");
295 if (CORBA::is_nil(objComponent)) {
296 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_CANT_LOAD_SUPERV"));
300 SUPERV::SuperG_var aSuperVisionComponent;
301 aSuperVisionComponent = SUPERV::SuperG::_narrow(objComponent);
302 if (CORBA::is_nil(aSuperVisionComponent)) {
303 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_CANT_NARROW_SUPERV"));
307 // engine = new SUPERV::SuperG_var;
308 engine = aSuperVisionComponent;
312 bool SUPERVGUI::information(SUPERV_CNode node, bool isReadOnly) {
313 Trace("SUPERVGUI::information")
314 return(info->run(node, isReadOnly));
317 void SUPERVGUI::putInfo(const char* mess) {
318 Trace("SUPERVGUI::putInfo")
319 application()->putInfo(mess);
322 SUPERV_Engine SUPERVGUI::getEngine() {
323 Trace("SUPERVGUI::getEngine")
327 SUPERVGUI_Service* SUPERVGUI::getBrowser() {
328 Trace("SUPERVGUI::getBrowser")
332 QCursor SUPERVGUI::getCursor() {
333 Trace("SUPERVGUI::getCursor")
337 SUPERVGUI_Main* SUPERVGUI::getMain() {
338 Trace("SUPERVGUI::getMain")
343 void SUPERVGUI::registerGraph(QString theName, SUPERVGUI_Main* theGraph){
344 theGraph->setHashCode(theName);
345 myGraphList.append(theGraph);
349 void SUPERVGUI::unregisterGraph(SUPERVGUI_Main* theGraph) {
350 SUPERVGUI_Main* aMain;
351 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
352 if (aMain == theGraph)
353 myGraphList.remove(aMain);
358 bool SUPERVGUI::isContains(SUIT_Study* theStudy, const QString theKey) {
359 SUPERVGUI_Main* aMain;
360 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
361 if ((aMain->getStudy() == theStudy) && (aMain->getHashCode() == theKey))
368 void SUPERVGUI::onGraphClosed(SUIT_ViewWindow* theViewWindow) {
369 if( SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(theViewWindow) ) {
370 disconnect(supervFrame->getViewManager(), 0 , this, 0);
371 SUPERVGraph_View* view = supervFrame->getViewWidget();
372 SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
374 unregisterGraph(aGraph);
375 SUPERV_Graph aDataFlow = aGraph->getDataflow();
376 if ( !SUPERV_isNull( aDataFlow ) ) {
377 if ( aDataFlow->IsExecuting() ) {
378 const int aMsgResult = QMessageBox::warning(application()->desktop(),
380 tr("MSG_DF_RUNNING"),
381 tr("MSG_DF_EXECUTION"),
383 if ( aMsgResult == 1 ) {
385 if ( aDataFlow->Kill() ) {
386 // Kill() sends KillEvent and KillState to SUPERVGUI_Thread
387 // while sets myIsActive flag to false when it receives such event/state
388 // after myIsActive is false it calls QThread::exit() to terminate.
390 // why while() { qApp->processEvents() } ?
391 // because: SUPERVGUI_Thread::run() receives events, and calls myMain->execute()
392 // method using SALOME_Event paradigm, ProcessVoidEvent() function -
393 // it puts this event to the main application event loop, in which we are being now.
394 // So if we block main GUI application thread (by calling aGraph->getMyThread()->wait() here)
395 // then we will have a deadlock of 2 threads waiting for one another
396 while (aGraph->getMyThread()->running())
397 qApp->processEvents();
400 else { // BACKGROUND EXECUTION
401 emit KillMainThread(true); // set SUPERVGUI_Thread::myIsActive to false
402 while ( aGraph->getMyThread()->running() )
403 qApp->processEvents();
406 else { // EXECUTION IS FINISHED, JUST DESTROY THE SUPERVGUI_Thread object and return.
407 emit KillMainThread(true);
408 while ( aGraph->getMyThread()->running() )
409 qApp->processEvents();
414 if ( myGraphList.isEmpty() ) {
415 myAllGraphsClosed = true;
416 myFirstActivation = true;
417 myInitialViewFrame = 0;
422 void SUPERVGUI::setMain( SUIT_ViewWindow* w) {
426 study = w->getViewManager()->study();
430 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(w)){
431 SUPERVGraph_View* view = supervFrame->getViewWidget();
433 main = dynamic_cast<SUPERVGUI_Main*>(view);
434 connect(this, SIGNAL(KillMainThread(bool)), main->getMyThread(), SLOT(KillThread(bool)));
437 Trace("SUPERVGUI::setMain - main: "<<main);
440 void SUPERVGUI::displayDataflow() {
441 Trace("SUPERVGUI::displayDataflow");
442 OB_Browser* aBrowser = (( SalomeApp_Application* )application())->objectBrowser();
443 SUPERV_Graph aDataFlow;
446 OB_ListItem* item = (OB_ListItem*)(aBrowser->listView()->currentItem());
448 ( (( SalomeApp_Study* )(application()->activeStudy()))->studyDS()->FindObjectID(item->text(2).latin1()) );
449 _PTR(GenericAttribute) anAttr;
450 if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
451 _PTR(AttributeIOR) anIOR ( anAttr );
452 aIORName = QString(anIOR->Value().c_str());
453 if (isContains(study, aIORName)) {
454 if (QMessageBox::warning(application()->desktop(), tr("WARNING"),
455 tr("MSG_GRAPH_DISPLAYED").arg(""),
456 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
459 //aDataFlow = engine->getStreamGraph(anIOR->Value().c_str());
460 aDataFlow = engine->getGraph(anIOR->Value().c_str());
461 if (SUPERV_isNull(aDataFlow)) {
462 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
465 /* ASV: 20.10.04: fix for 6896
466 if (aDataFlow->IsStreamGraph()) {
467 SUPERV_StreamGraph aDataFlowStream = aDataFlow->ToStreamGraph();
468 if (SUPERV_isNull(aDataFlowStream)) {
469 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
472 aDataFlow = aDataFlowStream;
477 SUPERVGraph_ViewFrame* aViewFrame;
478 if ( !myInitialViewFrame ) {
479 // first case : create a ViewFrame object
480 aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( createGraph() );
483 // second case : get empty initial view frame as new ViewFrame object
484 aViewFrame = myInitialViewFrame;
485 myInitialViewFrame = 0;
489 main = new SUPERVGUI_Main( aViewFrame, application()->desktop(), aDataFlow );
490 registerGraph( aIORName, main );
496 void SUPERVGUI::renameDataflow() {
499 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
501 SALOME_ListIteratorOfListIO It( aList );
502 for ( ; It.More(); It.Next() ) {
503 Handle(SALOME_InteractiveObject) IObject = It.Value();
505 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
506 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
507 _PTR(GenericAttribute) anAttr;
509 if ( obj->FindAttribute(anAttr, "AttributeName") ) {
510 _PTR(AttributeName) aName ( anAttr );
511 QString nm = QString( aName->Value().c_str() );
512 nm = SalomeApp_NameDlg::getName( application()->desktop(), nm );
513 if ( !nm.isEmpty() ) {
514 // sak : 24.11.04 : fix for PAL6898 : if rename fails (study locked),
515 // a message box is displayed, and cursor is "wait cursor". We think that "wait cursor"
516 // is not neccessary here, because the rename operation is fast.
517 //QApplication::setOverrideCursor( Qt::waitCursor );
518 //study->renameIObject( IObject, nm );
521 aName->SetValue( nm.latin1() );
522 //rename Interactive object
523 IObject->setName( ( char* )nm.latin1() );
527 //QApplication::restoreOverrideCursor();
534 void SUPERVGUI::exportDataflow() {
535 Trace("SUPERVGUI::exportDataflow")
537 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
539 else if ( SUPERV_isNull( main->getDataflow() ) ) { // should not normally happen..
540 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
543 QString f = SUIT_FileDlg::getFileName(application()->desktop(),
546 tr("TTL_EXPORT_DATAFLOW"),
548 if ( !f.isEmpty() ) {
550 // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file,
551 // a backup copy of an existing file must be created (in case Export fails..)
552 QString aBackupFile = SUPERVGUI::createBackupFile( f );
554 if ( main->getDataflow()->Export(f.latin1()) ) {
555 unregisterGraph(main);
556 registerGraph(f, main);
558 // remove a backup file if export was successfull
559 if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() )
560 QFile::remove( aBackupFile );
563 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile));
570 *If a file with theOriginalFileName exists, then the function tries to create
571 * its backup copy of it (the_name + ".bakX", X = 0,1,2,..,99). Returns backup file's name
572 * If a file with theOriginalFileName does not exist, or creation fails - Return empty string.
574 QString SUPERVGUI::createBackupFile( const QString& theOriginalFileName ) {
575 QString theBackupFileName("");
576 if ( QFile::exists( theOriginalFileName ) ) {
577 // 1. construct a backup file name
580 theBackupFileName = theOriginalFileName;
581 theBackupFileName += ".bak";
582 theBackupFileName += QString::number(i++);
584 while ( QFile::exists( theBackupFileName ) && i < 100 ); // max 99 backup files
585 // if *.bak99 exists -- it will be overwritten
587 // 2. copy the original file to theBackupFileName
588 QString cmd( "cp \"");
589 cmd += theOriginalFileName;
591 cmd += theBackupFileName;
593 bool res = system( cmd.latin1() );
595 theBackupFileName = QString("");
597 return theBackupFileName;
600 void SUPERVGUI::windows( QMap<int, int>& mappa ) const
602 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
603 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
604 mappa.insert( SalomeApp_Application::WT_LogWindow, Qt::DockBottom );
607 void SUPERVGUI::newDataflow() {
608 createDataflow( New );
611 void SUPERVGUI::importDataflow() {
612 createDataflow( Import );
615 void SUPERVGUI::modifyDataflow() {
616 createDataflow( Modify );
619 bool SUPERVGUI::createDataflow( const NEW_DF_MODE mode, bool theInitialDF ) {
620 Trace("SUPERVGUI::createDataflow, mode = " << mode );
622 // asv : 27.01.05 : fix for PAL7823 : if the study is locked - warn the user and return.
623 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
624 if ( aStudy->GetProperties()->IsLocked() ) {
625 QMessageBox::warning(application()->desktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"));
629 SUPERV::Graph_var aGraph;
631 QString f; // file name. declared here because may be used below in error msg construction..
632 if ( mode == Import || mode == Modify ) { // 0. import or modify existing dataflow - select XML file
633 QString title = QString( "TLT_CREATE_DF_%1" ).arg( mode );
634 f = SUIT_FileDlg::getFileName( application()->desktop(), "", "*.xml", tr( title ), true );
635 if ( f.isEmpty() ) // pressed Cancel in file select dialog
638 // check if study already contains a graph imported from the same file
639 if ( isContains( study, f ) ) {
640 if ( QMessageBox::warning( application()->desktop(), tr("WARNING"), tr("MSG_GRAPH_DISPLAYED").arg(f),
641 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No )
646 aGraph = ( mode == Import ) ? engine->StreamGraphE( f ) : engine->StreamGraph( f );
649 aGraph = engine->StreamGraph( MAIN_NEW );
651 if ( CORBA::is_nil( aGraph ) ) {
652 QString msg( mode == New ? tr("MSG_CANT_CREATE_DF") : tr("MSG_BAD_FILE").arg(f) );
653 SUIT_MessageBox::warn1( application()->desktop(), tr("ERROR"), tr(msg), tr("BUT_OK") );
657 SUPERVGraph_ViewFrame* aViewFrame;
658 if ( theInitialDF || !myInitialViewFrame ) {
659 // 2. create a ViewFrame object
660 aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( createGraph() );
663 // 2. get empty initial view frame as new ViewFrame object
664 aViewFrame = myInitialViewFrame;
665 myInitialViewFrame = 0;
670 // 3. bind Graph and ViewFrame == create SUPERVGUI_Main object
671 main = new SUPERVGUI_Main( aViewFrame, application()->desktop(), aGraph );
676 myInitialViewFrame = aViewFrame;
679 registerGraph( f, main );
686 void SUPERVGUI::reloadDataflow() {
687 Trace("SUPERVGUI::reloadDataflow");
691 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RELOAD"));
694 void SUPERVGUI::runDataflow() {
695 Trace("SUPERVGUI::runDataflow");
697 main->run( /*andSuspend=*/false );
699 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
702 void SUPERVGUI::stepByStep() {
703 Trace("SUPERVGUI::stepByStep");
705 main->run( /*andSuspend=*/true );
707 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
710 void SUPERVGUI::killDataflow() {
711 Trace("SUPERVGUI::killDataflow");
715 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_KILL"));
718 void SUPERVGUI::suspendResumeDataflow() {
719 Trace("SUPERVGUI::suspendResumeDataflow");
721 main->suspendResume();
723 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_SUSPEND"));
726 void SUPERVGUI::showComponents() {
727 Trace("SUPERVGUI::showComponents");
729 if ( main->isEditable() )
732 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOTEDITABLE"));
735 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_ADD"));
740 /*bool SUPERVGUI::CustomPopup(QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) {
741 Trace("SUPERVGUI::customPopup");
743 if(popup->count() > 3) {
744 // Temporary code: is to be deleted soon
745 popup->removeItem(QAD_Display_Popup_ID);
746 popup->removeItem(QAD_DisplayOnly_Popup_ID);
747 popup->removeItem(QAD_Erase_Popup_ID);
748 int id = popup->idAt(popup->count() - 1);
749 if (id < 0 && id != -1) popup->removeItem(id); // separator
750 // Temporary code end
755 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
756 if ( aList.Extent() == 0 ) return false;
758 if ( aList.Extent() == 1 ) {
759 Handle(SALOME_InteractiveObject) anIObj = aList.First();
761 // insert SUPERV-specific popup items here
763 bool isDataflow, ownObj;
764 whatIsSelected(anIObj, ownObj, isDataflow);
767 popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow()));
768 popup->insertItem("Display", this, SLOT(displayDataflow()));
769 popup->insertSeparator();
772 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
775 if ( aList.Extent() > 1 ) {
777 SALOME_ListIteratorOfListIO It_forCheckOwner( aList );
778 for(;It_forCheckOwner.More();It_forCheckOwner.Next()) {
779 Handle(SALOME_InteractiveObject) anIObj = It_forCheckOwner.Value();
780 bool aIsOwner, aIsDataflow;
781 whatIsSelected(anIObj, aIsOwner, aIsDataflow);
783 if (aIsOwner) aIObjCount++;
785 if ( aIObjCount == aList.Extent() ) //all selected objects belong to Supervision
786 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
795 theIsOwner = true if Selected object belongs to Supervision.
796 theIsDataflow = true if Selected object is Dataflow
798 void SUPERVGUI::whatIsSelected(const _PTR(SObject)& theObj, bool& theIsOwner, bool& theIsDataflow) {
800 theIsDataflow = false;
803 _PTR(SComponent) comp ( theObj->GetFatherComponent() );
805 _PTR(GenericAttribute) anAttr;
806 if (comp->FindAttribute(anAttr, "AttributeName")) {
807 _PTR(AttributeName) aName ( anAttr );
808 QString compName(aName->Value().c_str());
809 if ( compName.compare( moduleName() ) == 0 ) {
810 _PTR(GenericAttribute) anAttr;
811 if (theObj->FindAttribute(anAttr, "AttributeIOR")) {
812 _PTR(AttributeIOR) anIOR ( anAttr );
813 SUPERV_Graph aDataFlow = engine->getGraph(anIOR->Value().c_str());
814 if (!SUPERV_isNull(aDataFlow)) {
815 if (aDataFlow->IsStreamGraph()) {
816 if (!SUPERV_isNull(aDataFlow->ToStreamGraph()))
817 theIsDataflow = true;
820 theIsDataflow = true;
823 CORBA::String_var anObjectID = theObj->GetID().c_str();
824 CORBA::String_var aComponentID = comp->GetID().c_str();
825 if (strcmp(anObjectID, aComponentID))
833 void SUPERVGUI::deleteObject() {
836 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
837 if ( aList.Extent() == 0 ) return;
839 // sak : 24.11.04 : fix for PAL6899 : if the study is locked - warn the user and return.
840 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
841 if ( aStudy->GetProperties()->IsLocked() ) {
842 QMessageBox::warning(application()->desktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"));
846 // sak : 24.11.04 : fix for PAL6901 : Incorrect deletion of the objects : pressing ESC button
847 // emitted "YES" button click, now it is corrected, and treated as "NO" button click.
848 if (QMessageBox::warning(application()->desktop(),
850 tr("MSG_ASK_DELETE"),
851 QMessageBox::No, QMessageBox::Yes) != QMessageBox::Yes)
854 SALOME_ListIteratorOfListIO It( aList );
855 for(;It.More();It.Next()) {
856 Handle(SALOME_InteractiveObject) anIObj = It.Value();
857 //bool aIsOwner, aIsDataflow;
858 //whatIsSelected(anIObj, aIsOwner, aIsDataflow);
860 _PTR(SObject) aObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
862 SUIT_Operation* op = new SalomeApp_ImportOperation( application() );
863 _PTR(StudyBuilder) aBuilder ( aStudy->NewBuilder() );
865 aBuilder->RemoveObjectWithChildren( aObj );
869 (( SalomeApp_Application* )application())->selectionMgr()->clearSelected();
873 void SUPERVGUI::OnGUIEvent()
875 const QObject* obj = sender();
876 if ( !obj || !obj->inherits( "QAction" ) )
878 int id = actionId((QAction*)obj);
883 bool SUPERVGUI::OnGUIEvent(int command) {
914 suspendResumeDataflow();
938 QMessageBox::warning(application()->desktop(), "Supervision Error", "Unknown Command From Salome");
943 /*bool SUPERVGUI::SetSettings() {
944 Trace("SUPERVGUI::SetSettings");
949 /*void SUPERVGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject) {
954 bool SUPERVGUI::ActiveStudyChanged() {
955 Trace("SUPERVGUI::activeStudyChanged");
956 study = application()->activeStudy();
960 /*void SUPERVGUI::SupportedViewType (int* buffer, int bufferSize)
962 if (!buffer || !bufferSize) return;
963 buffer[0] = (int)VIEW_GRAPHSUPERV;
966 void SUPERVGUI::fillInterfaceNameMap() {
967 //fill map: interface_name <-> component_name for all
968 //interfaces of all loaded components, it is necessary
969 //for correct adding factory nodes from AddComponent,
970 //SubComponent, MulComponent, etc. components.
971 myInterfaceNameMap.clear();
974 SALOME_NamingService* namingService = (( SalomeApp_Application* )application())->namingService();
976 CORBA::Object_ptr obj = namingService->Resolve("/Kernel/ModulCatalog");
977 SALOME_ModuleCatalog::ModuleCatalog_var* aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var;
978 *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
979 if (!CORBA::is_nil(*aModuleCatalog)) {
981 SALOME_ModuleCatalog::ListOfComponents_var aCompList = (*aModuleCatalog)->GetComponentList();
982 for (int ind1 = 0; ind1 < aCompList->length(); ind1++) {
984 SALOME_ModuleCatalog::Acomponent_ptr aComponent = (*aModuleCatalog)->GetComponent(aCompList[ind1]);
985 if ( aComponent != NULL ) {
987 SALOME_ModuleCatalog::ListOfInterfaces_var anIntList = aComponent->GetInterfaceList();
988 for (int ind2 = 0; ind2 < anIntList->length(); ind2++) {
989 const char* anIntName = anIntList[ind2];
990 myInterfaceNameMap.insert(QString(anIntName), QString(aComponent->componentname()));
997 QMap<QString, QString> SUPERVGUI::getInterfaceNameMap() const {
998 return myInterfaceNameMap;