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),
81 Trace("SUPERVGUI::SUPERVGUI")
84 MESSAGE("SUPERVGUI Info : factory build");
86 MESSAGE("SUPERVGUI Error : another call to factory constructor");
90 SUPERVGUI::~SUPERVGUI() {
91 Trace("SUPERVGUI::~SUPERVGUI")
94 //if (!engine->_is_nil()) CORBA::release(engine);
97 if (browser->isVisible())
101 MESSAGE("SUPERVGUI Info : factory destroy");
103 MESSAGE("SUPERVGUI Error : another call to factory destructor");
107 SUPERVGUI* SUPERVGUI::Supervision() {
108 CAM_Application* anApp = dynamic_cast<CAM_Application*>( SUIT_Session::session()->activeApplication() );
110 SUPERVGUI* aSupervModule = dynamic_cast<SUPERVGUI*>( anApp->activeModule() );
111 return aSupervModule;
116 void SUPERVGUI::createSupervAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle )
119 QWidget* parent = application()->desktop();
120 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
122 if ( icon_id.length() )
123 pix = resMgr->loadPixmap( "SUPERV", tr( icon_id ) );
125 pix = resMgr->loadPixmap( "SUPERV", tr( QString( "ICO_" )+po_id ) );
127 icon = QIconSet( pix );
129 QString tooltip = tr( QString( "TOP_" )+po_id ),
130 menu = tr( QString( "MEN_" )+po_id ),
131 status_bar = tr( QString( "STB_" )+po_id );
133 createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() ) );
136 void SUPERVGUI::initialize( CAM_Application* app )
138 SalomeApp_Module::initialize( app );
140 SALOME_NamingService* namingService = (( SalomeApp_Application* )application())->namingService();
141 loadEngine(namingService);
143 browser = new SUPERVGUI_Service(namingService);
144 //info = new SUPERVGUI_Information();
145 cursor = application()->desktop()->cursor();
147 fillInterfaceNameMap();
149 // ----- create actions --------------
150 createSupervAction( 301, "IMPORT" );
151 createSupervAction( 302, "EXPORT" );
153 createSupervAction( 303, "NEW" );
154 createSupervAction( 304, "MODIFY" );
156 createSupervAction( 305, "RELOAD" );
157 createSupervAction( 306, "RUN" );
158 createSupervAction( 307, "KILL" );
159 createSupervAction( 308, "SUSPEND/RESUME" );
160 createSupervAction( 309, "ADDNODE" );
161 createSupervAction( 310, "STEPBYSTEP" );
163 createSupervAction( 311, "POP_RENAME" );
164 createSupervAction( 312, "POP_DISPLAY" );
165 createSupervAction( 313, "POP_DELETE" );
167 // ----- create menu -----------------
168 int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
169 createMenu( 301, fileId, 10 );
170 createMenu( 302, fileId, 10 );
171 createMenu( separator(), fileId, 10 );
173 int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
174 createMenu( separator(), fileId, 7 );
175 createMenu( 303, editId, -1 );
176 createMenu( 304, editId, -1 );
178 int supervId = createMenu( tr( "MEN_SUPERV" ), -1, -1, 10/*, 300*/ );
179 createMenu( 305, supervId, -1 );
180 createMenu( 309, supervId, -1 );
181 createMenu( separator(), fileId, 3 );
182 createMenu( 306, supervId, -1 );
183 createMenu( 310, supervId, -1 );
184 createMenu( 307, supervId, -1 );
185 createMenu( 308, supervId, -1 );
187 // ----- create toolbars -------------
188 int supervisorId = createTool( tr( "TOOL_SUPERVISOR" ) );
189 createTool( 301, supervisorId );
190 createTool( 302, supervisorId );
191 createTool( 303, supervisorId );
192 createTool( 304, supervisorId );
193 createTool( 305, supervisorId );
194 createTool( 309, supervisorId );
196 int executionId = createTool( tr( "TOOL_EXECUTION" ) );
197 createTool( 306, executionId );
198 createTool( 310, executionId );
199 createTool( 307, executionId );
200 createTool( 308, executionId );
202 // ----- create popup for object browser items -------------
203 QtxPopupMgr* mgr = popupMgr();
204 mgr->insert( action( 311 ), -1, -1 ); // rename dataflow
205 mgr->setRule( action( 311 ), "$type in {'Dataflow'} and selcount=1", true );
206 mgr->insert( action( 312 ), -1, -1 ); // display dataflow
207 mgr->setRule( action( 312 ), "$type in {'Dataflow'} and selcount=1", true );
208 mgr->insert( separator(), -1, -1 ); // -----------
209 mgr->insert( action( 313 ), -1, -1 ); // delete object
210 mgr->setRule( action( 313 ), "$client in {'ObjectBrowser'} and $type in {'Dataflow' 'SupervisorObject'} and selcount>0", true );
213 bool SUPERVGUI::activateModule( SUIT_Study* theStudy )
215 if ( CORBA::is_nil( engine ) )
218 if ( !SalomeApp_Module::activateModule( theStudy ) )
223 //---------------------------------------
224 setMenuShown( true );
225 setToolShown( true );
227 study = application()->activeStudy();
229 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
230 this, SLOT( setMain( SUIT_ViewWindow* ) ) );
232 if ( myFirstActivation )
233 // create new empty dataflow
234 createDataflow( New, true );
239 QString SUPERVGUI::engineIOR() const
241 if ( !CORBA::is_nil( engine ) )
242 return QString( getApp()->orb()->object_to_string( engine));
243 return QString( "" );
246 bool SUPERVGUI::deactivateModule( SUIT_Study* theStudy )
248 setMenuShown( false );
249 setToolShown( false );
251 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
252 this, SLOT( setMain( SUIT_ViewWindow* ) ) );
253 //---------------------------------------
255 myFirstActivation = false;
257 return SalomeApp_Module::deactivateModule( theStudy );
260 CAM_DataModel* SUPERVGUI::createDataModel()
262 return new SUPERVGUI_DataModel( this );
265 SalomeApp_Selection* SUPERVGUI::createSelection() const
267 return new SUPERVGUI_Selection();
270 SUIT_ViewWindow* SUPERVGUI::createGraph() {
271 SUPERVGraph_ViewManager* aVM = new SUPERVGraph_ViewManager( study, application()->desktop(), new SUPERVGraph_Viewer() );
272 SUIT_ViewWindow* aVW = aVM->createViewWindow();
275 SIGNAL( deleteView( SUIT_ViewWindow* ) ),
277 SLOT( onGraphClosed( SUIT_ViewWindow* ) ) );
284 void SUPERVGUI::loadEngine(SALOME_NamingService* namingService) {
285 Trace("SUPERVGUI::loadEngine")
286 SALOME_LifeCycleCORBA LCC(namingService);
287 Engines::Component_var objComponent = LCC.FindOrLoad_Component("SuperVisionContainer", "SUPERV");
288 if (CORBA::is_nil(objComponent)) {
289 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_CANT_LOAD_SUPERV"));
293 SUPERV::SuperG_var aSuperVisionComponent;
294 aSuperVisionComponent = SUPERV::SuperG::_narrow(objComponent);
295 if (CORBA::is_nil(aSuperVisionComponent)) {
296 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_CANT_NARROW_SUPERV"));
300 // engine = new SUPERV::SuperG_var;
301 engine = aSuperVisionComponent;
305 bool SUPERVGUI::information(SUPERV_CNode node, bool isReadOnly) {
306 Trace("SUPERVGUI::information")
307 return(info->run(node, isReadOnly));
310 void SUPERVGUI::putInfo(const char* mess) {
311 Trace("SUPERVGUI::putInfo")
312 application()->putInfo(mess);
315 SUPERV_Engine SUPERVGUI::getEngine() {
316 Trace("SUPERVGUI::getEngine")
320 SUPERVGUI_Service* SUPERVGUI::getBrowser() {
321 Trace("SUPERVGUI::getBrowser")
325 QCursor SUPERVGUI::getCursor() {
326 Trace("SUPERVGUI::getCursor")
330 SUPERVGUI_Main* SUPERVGUI::getMain() {
331 Trace("SUPERVGUI::getMain")
336 void SUPERVGUI::registerGraph(QString theName, SUPERVGUI_Main* theGraph){
337 theGraph->setHashCode(theName);
338 myGraphList.append(theGraph);
342 void SUPERVGUI::unregisterGraph(SUPERVGUI_Main* theGraph) {
343 SUPERVGUI_Main* aMain;
344 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
345 if (aMain == theGraph)
346 myGraphList.remove(aMain);
351 bool SUPERVGUI::isContains(SUIT_Study* theStudy, const QString theKey) {
352 SUPERVGUI_Main* aMain;
353 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
354 if ((aMain->getStudy() == theStudy) && (aMain->getHashCode() == theKey))
361 void SUPERVGUI::onGraphClosed(SUIT_ViewWindow* theViewWindow) {
362 if( SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(theViewWindow) ) {
363 disconnect(supervFrame->getViewManager(), 0 , this, 0);
364 SUPERVGraph_View* view = supervFrame->getViewWidget();
365 SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
367 unregisterGraph(aGraph);
368 SUPERV_Graph aDataFlow = aGraph->getDataflow();
369 if ( !SUPERV_isNull( aDataFlow ) ) {
370 if ( aDataFlow->IsExecuting() ) {
371 const int aMsgResult = QMessageBox::warning(application()->desktop(),
373 tr("MSG_DF_RUNNING"),
374 tr("MSG_DF_EXECUTION"),
376 if ( aMsgResult == 1 ) {
378 if ( aDataFlow->Kill() ) {
379 // Kill() sends KillEvent and KillState to SUPERVGUI_Thread
380 // while sets myIsActive flag to false when it receives such event/state
381 // after myIsActive is false it calls QThread::exit() to terminate.
383 // why while() { qApp->processEvents() } ?
384 // because: SUPERVGUI_Thread::run() receives events, and calls myMain->execute()
385 // method using SALOME_Event paradigm, ProcessVoidEvent() function -
386 // it puts this event to the main application event loop, in which we are being now.
387 // So if we block main GUI application thread (by calling aGraph->getMyThread()->wait() here)
388 // then we will have a deadlock of 2 threads waiting for one another
389 while (aGraph->getMyThread()->running())
390 qApp->processEvents();
393 else { // BACKGROUND EXECUTION
394 emit KillMainThread(true); // set SUPERVGUI_Thread::myIsActive to false
395 while ( aGraph->getMyThread()->running() )
396 qApp->processEvents();
399 else { // EXECUTION IS FINISHED, JUST DESTROY THE SUPERVGUI_Thread object and return.
400 emit KillMainThread(true);
401 while ( aGraph->getMyThread()->running() )
402 qApp->processEvents();
409 void SUPERVGUI::setMain( SUIT_ViewWindow* w) {
413 study = w->getViewManager()->study();
417 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(w)){
418 SUPERVGraph_View* view = supervFrame->getViewWidget();
420 main = dynamic_cast<SUPERVGUI_Main*>(view);
421 connect(this, SIGNAL(KillMainThread(bool)), main->getMyThread(), SLOT(KillThread(bool)));
424 Trace("SUPERVGUI::setMain - main: "<<main);
427 void SUPERVGUI::displayDataflow() {
428 Trace("SUPERVGUI::displayDataflow");
429 OB_Browser* aBrowser = (( SalomeApp_Application* )application())->objectBrowser();
430 SUPERV_Graph aDataFlow;
433 OB_ListItem* item = (OB_ListItem*)(aBrowser->listView()->currentItem());
435 ( (( SalomeApp_Study* )(application()->activeStudy()))->studyDS()->FindObjectID(item->text(2).latin1()) );
436 _PTR(GenericAttribute) anAttr;
437 if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
438 _PTR(AttributeIOR) anIOR ( anAttr );
439 aIORName = QString(anIOR->Value().c_str());
440 if (isContains(study, aIORName)) {
441 if (QMessageBox::warning(application()->desktop(), tr("WARNING"),
442 tr("MSG_GRAPH_DISPLAYED").arg(""),
443 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
446 //aDataFlow = engine->getStreamGraph(anIOR->Value().c_str());
447 aDataFlow = engine->getGraph(anIOR->Value().c_str());
448 if (SUPERV_isNull(aDataFlow)) {
449 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
452 /* ASV: 20.10.04: fix for 6896
453 if (aDataFlow->IsStreamGraph()) {
454 SUPERV_StreamGraph aDataFlowStream = aDataFlow->ToStreamGraph();
455 if (SUPERV_isNull(aDataFlowStream)) {
456 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
459 aDataFlow = aDataFlowStream;
463 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( createGraph() );
465 main = new SUPERVGUI_Main( aViewFrame, application()->desktop(), aDataFlow );
466 registerGraph( aIORName, main );
472 void SUPERVGUI::renameDataflow() {
475 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
477 SALOME_ListIteratorOfListIO It( aList );
478 for ( ; It.More(); It.Next() ) {
479 Handle(SALOME_InteractiveObject) IObject = It.Value();
481 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
482 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
483 _PTR(GenericAttribute) anAttr;
485 if ( obj->FindAttribute(anAttr, "AttributeName") ) {
486 _PTR(AttributeName) aName ( anAttr );
487 QString nm = QString( aName->Value().c_str() );
488 nm = SalomeApp_NameDlg::getName( application()->desktop(), nm );
489 if ( !nm.isEmpty() ) {
490 // sak : 24.11.04 : fix for PAL6898 : if rename fails (study locked),
491 // a message box is displayed, and cursor is "wait cursor". We think that "wait cursor"
492 // is not neccessary here, because the rename operation is fast.
493 //QApplication::setOverrideCursor( Qt::waitCursor );
494 //study->renameIObject( IObject, nm );
497 aName->SetValue( nm.latin1() );
498 //rename Interactive object
499 IObject->setName( ( char* )nm.latin1() );
503 //QApplication::restoreOverrideCursor();
510 void SUPERVGUI::exportDataflow() {
511 Trace("SUPERVGUI::exportDataflow")
513 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
515 else if ( SUPERV_isNull( main->getDataflow() ) ) { // should not normally happen..
516 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
519 QString f = SUIT_FileDlg::getFileName(application()->desktop(),
522 tr("TTL_EXPORT_DATAFLOW"),
524 if ( !f.isEmpty() ) {
526 // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file,
527 // a backup copy of an existing file must be created (in case Export fails..)
528 QString aBackupFile = SUPERVGUI::createBackupFile( f );
530 if ( main->getDataflow()->Export(f.latin1()) ) {
531 unregisterGraph(main);
532 registerGraph(f, main);
534 // remove a backup file if export was successfull
535 if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() )
536 QFile::remove( aBackupFile );
539 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile));
546 *If a file with theOriginalFileName exists, then the function tries to create
547 * its backup copy of it (the_name + ".bakX", X = 0,1,2,..,99). Returns backup file's name
548 * If a file with theOriginalFileName does not exist, or creation fails - Return empty string.
550 QString SUPERVGUI::createBackupFile( const QString& theOriginalFileName ) {
551 QString theBackupFileName("");
552 if ( QFile::exists( theOriginalFileName ) ) {
553 // 1. construct a backup file name
556 theBackupFileName = theOriginalFileName;
557 theBackupFileName += ".bak";
558 theBackupFileName += QString::number(i++);
560 while ( QFile::exists( theBackupFileName ) && i < 100 ); // max 99 backup files
561 // if *.bak99 exists -- it will be overwritten
563 // 2. copy the original file to theBackupFileName
564 QString cmd( "cp \"");
565 cmd += theOriginalFileName;
567 cmd += theBackupFileName;
569 bool res = system( cmd.latin1() );
571 theBackupFileName = QString("");
573 return theBackupFileName;
576 void SUPERVGUI::windows( QMap<int, int>& mappa ) const
578 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
579 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
580 mappa.insert( SalomeApp_Application::WT_LogWindow, Qt::DockBottom );
583 void SUPERVGUI::newDataflow() {
584 createDataflow( New );
587 void SUPERVGUI::importDataflow() {
588 createDataflow( Import );
591 void SUPERVGUI::modifyDataflow() {
592 createDataflow( Modify );
595 bool SUPERVGUI::createDataflow( const NEW_DF_MODE mode, bool theInitialDF ) {
596 Trace("SUPERVGUI::createDataflow, mode = " << mode );
598 // asv : 27.01.05 : fix for PAL7823 : if the study is locked - warn the user and return.
599 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
600 if ( aStudy->GetProperties()->IsLocked() ) {
601 QMessageBox::warning(application()->desktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"));
605 SUPERV::Graph_var aGraph;
607 QString f; // file name. declared here because may be used below in error msg construction..
608 if ( mode == Import || mode == Modify ) { // 0. import or modify existing dataflow - select XML file
609 QString title = QString( "TLT_CREATE_DF_%1" ).arg( mode );
610 f = SUIT_FileDlg::getFileName( application()->desktop(), "", "*.xml", tr( title ), true );
611 if ( f.isEmpty() ) // pressed Cancel in file select dialog
614 // check if study already contains a graph imported from the same file
615 if ( isContains( study, f ) ) {
616 if ( QMessageBox::warning( application()->desktop(), tr("WARNING"), tr("MSG_GRAPH_DISPLAYED").arg(f),
617 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No )
622 aGraph = ( mode == Import ) ? engine->StreamGraphE( f ) : engine->StreamGraph( f );
625 aGraph = engine->StreamGraph( MAIN_NEW );
627 if ( CORBA::is_nil( aGraph ) ) {
628 QString msg( mode == New ? tr("MSG_CANT_CREATE_DF") : tr("MSG_BAD_FILE").arg(f) );
629 SUIT_MessageBox::warn1( application()->desktop(), tr("ERROR"), tr(msg), tr("BUT_OK") );
633 SUPERVGraph_ViewFrame* aViewFrame;
634 if ( theInitialDF || !myInitialViewFrame ) {
635 // 2. create a ViewFrame object
636 aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( createGraph() );
639 // 2. get empty initial view frame as new ViewFrame object
640 aViewFrame = myInitialViewFrame;
641 myInitialViewFrame = 0;
646 // 3. bind Graph and ViewFrame == create SUPERVGUI_Main object
647 main = new SUPERVGUI_Main( aViewFrame, application()->desktop(), aGraph );
652 myInitialViewFrame = aViewFrame;
655 registerGraph( f, main );
662 void SUPERVGUI::reloadDataflow() {
663 Trace("SUPERVGUI::reloadDataflow");
667 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RELOAD"));
670 void SUPERVGUI::runDataflow() {
671 Trace("SUPERVGUI::runDataflow");
673 main->run( /*andSuspend=*/false );
675 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
678 void SUPERVGUI::stepByStep() {
679 Trace("SUPERVGUI::stepByStep");
681 main->run( /*andSuspend=*/true );
683 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
686 void SUPERVGUI::killDataflow() {
687 Trace("SUPERVGUI::killDataflow");
691 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_KILL"));
694 void SUPERVGUI::suspendResumeDataflow() {
695 Trace("SUPERVGUI::suspendResumeDataflow");
697 main->suspendResume();
699 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_SUSPEND"));
702 void SUPERVGUI::showComponents() {
703 Trace("SUPERVGUI::showComponents");
705 if ( main->isEditable() )
708 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOTEDITABLE"));
711 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_ADD"));
716 /*bool SUPERVGUI::CustomPopup(QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) {
717 Trace("SUPERVGUI::customPopup");
719 if(popup->count() > 3) {
720 // Temporary code: is to be deleted soon
721 popup->removeItem(QAD_Display_Popup_ID);
722 popup->removeItem(QAD_DisplayOnly_Popup_ID);
723 popup->removeItem(QAD_Erase_Popup_ID);
724 int id = popup->idAt(popup->count() - 1);
725 if (id < 0 && id != -1) popup->removeItem(id); // separator
726 // Temporary code end
731 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
732 if ( aList.Extent() == 0 ) return false;
734 if ( aList.Extent() == 1 ) {
735 Handle(SALOME_InteractiveObject) anIObj = aList.First();
737 // insert SUPERV-specific popup items here
739 bool isDataflow, ownObj;
740 whatIsSelected(anIObj, ownObj, isDataflow);
743 popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow()));
744 popup->insertItem("Display", this, SLOT(displayDataflow()));
745 popup->insertSeparator();
748 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
751 if ( aList.Extent() > 1 ) {
753 SALOME_ListIteratorOfListIO It_forCheckOwner( aList );
754 for(;It_forCheckOwner.More();It_forCheckOwner.Next()) {
755 Handle(SALOME_InteractiveObject) anIObj = It_forCheckOwner.Value();
756 bool aIsOwner, aIsDataflow;
757 whatIsSelected(anIObj, aIsOwner, aIsDataflow);
759 if (aIsOwner) aIObjCount++;
761 if ( aIObjCount == aList.Extent() ) //all selected objects belong to Supervision
762 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
771 theIsOwner = true if Selected object belongs to Supervision.
772 theIsDataflow = true if Selected object is Dataflow
774 void SUPERVGUI::whatIsSelected(const _PTR(SObject)& theObj, bool& theIsOwner, bool& theIsDataflow) {
776 theIsDataflow = false;
779 _PTR(SComponent) comp ( theObj->GetFatherComponent() );
781 _PTR(GenericAttribute) anAttr;
782 if (comp->FindAttribute(anAttr, "AttributeName")) {
783 _PTR(AttributeName) aName ( anAttr );
784 QString compName(aName->Value().c_str());
785 if ( compName.compare( moduleName() ) == 0 ) {
786 _PTR(GenericAttribute) anAttr;
787 if (theObj->FindAttribute(anAttr, "AttributeIOR")) {
788 _PTR(AttributeIOR) anIOR ( anAttr );
789 SUPERV_Graph aDataFlow = engine->getGraph(anIOR->Value().c_str());
790 if (!SUPERV_isNull(aDataFlow)) {
791 if (aDataFlow->IsStreamGraph()) {
792 if (!SUPERV_isNull(aDataFlow->ToStreamGraph()))
793 theIsDataflow = true;
796 theIsDataflow = true;
799 CORBA::String_var anObjectID = theObj->GetID().c_str();
800 CORBA::String_var aComponentID = comp->GetID().c_str();
801 if (strcmp(anObjectID, aComponentID))
809 void SUPERVGUI::deleteObject() {
812 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
813 if ( aList.Extent() == 0 ) return;
815 // sak : 24.11.04 : fix for PAL6899 : if the study is locked - warn the user and return.
816 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
817 if ( aStudy->GetProperties()->IsLocked() ) {
818 QMessageBox::warning(application()->desktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"));
822 // sak : 24.11.04 : fix for PAL6901 : Incorrect deletion of the objects : pressing ESC button
823 // emitted "YES" button click, now it is corrected, and treated as "NO" button click.
824 if (QMessageBox::warning(application()->desktop(),
826 tr("MSG_ASK_DELETE"),
827 QMessageBox::No, QMessageBox::Yes) != QMessageBox::Yes)
830 SALOME_ListIteratorOfListIO It( aList );
831 for(;It.More();It.Next()) {
832 Handle(SALOME_InteractiveObject) anIObj = It.Value();
833 //bool aIsOwner, aIsDataflow;
834 //whatIsSelected(anIObj, aIsOwner, aIsDataflow);
836 _PTR(SObject) aObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
838 SUIT_Operation* op = new SalomeApp_ImportOperation( application() );
839 _PTR(StudyBuilder) aBuilder ( aStudy->NewBuilder() );
841 aBuilder->RemoveObjectWithChildren( aObj );
845 (( SalomeApp_Application* )application())->selectionMgr()->clearSelected();
849 void SUPERVGUI::OnGUIEvent()
851 const QObject* obj = sender();
852 if ( !obj || !obj->inherits( "QAction" ) )
854 int id = actionId((QAction*)obj);
859 bool SUPERVGUI::OnGUIEvent(int command) {
890 suspendResumeDataflow();
914 QMessageBox::warning(application()->desktop(), "Supervision Error", "Unknown Command From Salome");
919 /*bool SUPERVGUI::SetSettings() {
920 Trace("SUPERVGUI::SetSettings");
925 /*void SUPERVGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject) {
930 bool SUPERVGUI::ActiveStudyChanged() {
931 Trace("SUPERVGUI::activeStudyChanged");
932 study = application()->activeStudy();
936 /*void SUPERVGUI::SupportedViewType (int* buffer, int bufferSize)
938 if (!buffer || !bufferSize) return;
939 buffer[0] = (int)VIEW_GRAPHSUPERV;
942 void SUPERVGUI::fillInterfaceNameMap() {
943 //fill map: interface_name <-> component_name for all
944 //interfaces of all loaded components, it is necessary
945 //for correct adding factory nodes from AddComponent,
946 //SubComponent, MulComponent, etc. components.
947 myInterfaceNameMap.clear();
950 SALOME_NamingService* namingService = (( SalomeApp_Application* )application())->namingService();
952 CORBA::Object_ptr obj = namingService->Resolve("/Kernel/ModulCatalog");
953 SALOME_ModuleCatalog::ModuleCatalog_var* aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var;
954 *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
955 if (!CORBA::is_nil(*aModuleCatalog)) {
957 SALOME_ModuleCatalog::ListOfComponents_var aCompList = (*aModuleCatalog)->GetComponentList();
958 for (int ind1 = 0; ind1 < aCompList->length(); ind1++) {
960 SALOME_ModuleCatalog::Acomponent_ptr aComponent = (*aModuleCatalog)->GetComponent(aCompList[ind1]);
961 if ( aComponent != NULL ) {
963 SALOME_ModuleCatalog::ListOfInterfaces_var anIntList = aComponent->GetInterfaceList();
964 for (int ind2 = 0; ind2 < anIntList->length(); ind2++) {
965 const char* anIntName = anIntList[ind2];
966 myInterfaceNameMap.insert(QString(anIntName), QString(aComponent->componentname()));
973 QMap<QString, QString> SUPERVGUI::getInterfaceNameMap() const {
974 return myInterfaceNameMap;