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;
418 void SUPERVGUI::setMain( SUIT_ViewWindow* w) {
422 study = w->getViewManager()->study();
426 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(w)){
427 SUPERVGraph_View* view = supervFrame->getViewWidget();
429 main = dynamic_cast<SUPERVGUI_Main*>(view);
430 connect(this, SIGNAL(KillMainThread(bool)), main->getMyThread(), SLOT(KillThread(bool)));
433 Trace("SUPERVGUI::setMain - main: "<<main);
436 void SUPERVGUI::displayDataflow() {
437 Trace("SUPERVGUI::displayDataflow");
438 OB_Browser* aBrowser = (( SalomeApp_Application* )application())->objectBrowser();
439 SUPERV_Graph aDataFlow;
442 OB_ListItem* item = (OB_ListItem*)(aBrowser->listView()->currentItem());
444 ( (( SalomeApp_Study* )(application()->activeStudy()))->studyDS()->FindObjectID(item->text(2).latin1()) );
445 _PTR(GenericAttribute) anAttr;
446 if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
447 _PTR(AttributeIOR) anIOR ( anAttr );
448 aIORName = QString(anIOR->Value().c_str());
449 if (isContains(study, aIORName)) {
450 if (QMessageBox::warning(application()->desktop(), tr("WARNING"),
451 tr("MSG_GRAPH_DISPLAYED").arg(""),
452 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
455 //aDataFlow = engine->getStreamGraph(anIOR->Value().c_str());
456 aDataFlow = engine->getGraph(anIOR->Value().c_str());
457 if (SUPERV_isNull(aDataFlow)) {
458 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
461 /* ASV: 20.10.04: fix for 6896
462 if (aDataFlow->IsStreamGraph()) {
463 SUPERV_StreamGraph aDataFlowStream = aDataFlow->ToStreamGraph();
464 if (SUPERV_isNull(aDataFlowStream)) {
465 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
468 aDataFlow = aDataFlowStream;
472 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( createGraph() );
474 main = new SUPERVGUI_Main( aViewFrame, application()->desktop(), aDataFlow );
475 registerGraph( aIORName, main );
481 void SUPERVGUI::renameDataflow() {
484 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
486 SALOME_ListIteratorOfListIO It( aList );
487 for ( ; It.More(); It.Next() ) {
488 Handle(SALOME_InteractiveObject) IObject = It.Value();
490 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
491 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
492 _PTR(GenericAttribute) anAttr;
494 if ( obj->FindAttribute(anAttr, "AttributeName") ) {
495 _PTR(AttributeName) aName ( anAttr );
496 QString nm = QString( aName->Value().c_str() );
497 nm = SalomeApp_NameDlg::getName( application()->desktop(), nm );
498 if ( !nm.isEmpty() ) {
499 // sak : 24.11.04 : fix for PAL6898 : if rename fails (study locked),
500 // a message box is displayed, and cursor is "wait cursor". We think that "wait cursor"
501 // is not neccessary here, because the rename operation is fast.
502 //QApplication::setOverrideCursor( Qt::waitCursor );
503 //study->renameIObject( IObject, nm );
506 aName->SetValue( nm.latin1() );
507 //rename Interactive object
508 IObject->setName( ( char* )nm.latin1() );
512 //QApplication::restoreOverrideCursor();
519 void SUPERVGUI::exportDataflow() {
520 Trace("SUPERVGUI::exportDataflow")
522 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
524 else if ( SUPERV_isNull( main->getDataflow() ) ) { // should not normally happen..
525 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
528 QString f = SUIT_FileDlg::getFileName(application()->desktop(),
531 tr("TTL_EXPORT_DATAFLOW"),
533 if ( !f.isEmpty() ) {
535 // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file,
536 // a backup copy of an existing file must be created (in case Export fails..)
537 QString aBackupFile = SUPERVGUI::createBackupFile( f );
539 if ( main->getDataflow()->Export(f.latin1()) ) {
540 unregisterGraph(main);
541 registerGraph(f, main);
543 // remove a backup file if export was successfull
544 if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() )
545 QFile::remove( aBackupFile );
548 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile));
555 *If a file with theOriginalFileName exists, then the function tries to create
556 * its backup copy of it (the_name + ".bakX", X = 0,1,2,..,99). Returns backup file's name
557 * If a file with theOriginalFileName does not exist, or creation fails - Return empty string.
559 QString SUPERVGUI::createBackupFile( const QString& theOriginalFileName ) {
560 QString theBackupFileName("");
561 if ( QFile::exists( theOriginalFileName ) ) {
562 // 1. construct a backup file name
565 theBackupFileName = theOriginalFileName;
566 theBackupFileName += ".bak";
567 theBackupFileName += QString::number(i++);
569 while ( QFile::exists( theBackupFileName ) && i < 100 ); // max 99 backup files
570 // if *.bak99 exists -- it will be overwritten
572 // 2. copy the original file to theBackupFileName
573 QString cmd( "cp \"");
574 cmd += theOriginalFileName;
576 cmd += theBackupFileName;
578 bool res = system( cmd.latin1() );
580 theBackupFileName = QString("");
582 return theBackupFileName;
585 void SUPERVGUI::windows( QMap<int, int>& mappa ) const
587 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
588 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
589 mappa.insert( SalomeApp_Application::WT_LogWindow, Qt::DockBottom );
592 void SUPERVGUI::newDataflow() {
593 createDataflow( New );
596 void SUPERVGUI::importDataflow() {
597 createDataflow( Import );
600 void SUPERVGUI::modifyDataflow() {
601 createDataflow( Modify );
604 bool SUPERVGUI::createDataflow( const NEW_DF_MODE mode, bool theInitialDF ) {
605 Trace("SUPERVGUI::createDataflow, mode = " << mode );
607 // asv : 27.01.05 : fix for PAL7823 : if the study is locked - warn the user and return.
608 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
609 if ( aStudy->GetProperties()->IsLocked() ) {
610 QMessageBox::warning(application()->desktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"));
614 SUPERV::Graph_var aGraph;
616 QString f; // file name. declared here because may be used below in error msg construction..
617 if ( mode == Import || mode == Modify ) { // 0. import or modify existing dataflow - select XML file
618 QString title = QString( "TLT_CREATE_DF_%1" ).arg( mode );
619 f = SUIT_FileDlg::getFileName( application()->desktop(), "", "*.xml", tr( title ), true );
620 if ( f.isEmpty() ) // pressed Cancel in file select dialog
623 // check if study already contains a graph imported from the same file
624 if ( isContains( study, f ) ) {
625 if ( QMessageBox::warning( application()->desktop(), tr("WARNING"), tr("MSG_GRAPH_DISPLAYED").arg(f),
626 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No )
631 aGraph = ( mode == Import ) ? engine->StreamGraphE( f ) : engine->StreamGraph( f );
634 aGraph = engine->StreamGraph( MAIN_NEW );
636 if ( CORBA::is_nil( aGraph ) ) {
637 QString msg( mode == New ? tr("MSG_CANT_CREATE_DF") : tr("MSG_BAD_FILE").arg(f) );
638 SUIT_MessageBox::warn1( application()->desktop(), tr("ERROR"), tr(msg), tr("BUT_OK") );
642 SUPERVGraph_ViewFrame* aViewFrame;
643 if ( theInitialDF || !myInitialViewFrame ) {
644 // 2. create a ViewFrame object
645 aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( createGraph() );
648 // 2. get empty initial view frame as new ViewFrame object
649 aViewFrame = myInitialViewFrame;
650 myInitialViewFrame = 0;
655 // 3. bind Graph and ViewFrame == create SUPERVGUI_Main object
656 main = new SUPERVGUI_Main( aViewFrame, application()->desktop(), aGraph );
661 myInitialViewFrame = aViewFrame;
664 registerGraph( f, main );
671 void SUPERVGUI::reloadDataflow() {
672 Trace("SUPERVGUI::reloadDataflow");
676 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RELOAD"));
679 void SUPERVGUI::runDataflow() {
680 Trace("SUPERVGUI::runDataflow");
682 main->run( /*andSuspend=*/false );
684 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
687 void SUPERVGUI::stepByStep() {
688 Trace("SUPERVGUI::stepByStep");
690 main->run( /*andSuspend=*/true );
692 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
695 void SUPERVGUI::killDataflow() {
696 Trace("SUPERVGUI::killDataflow");
700 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_KILL"));
703 void SUPERVGUI::suspendResumeDataflow() {
704 Trace("SUPERVGUI::suspendResumeDataflow");
706 main->suspendResume();
708 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_SUSPEND"));
711 void SUPERVGUI::showComponents() {
712 Trace("SUPERVGUI::showComponents");
714 if ( main->isEditable() )
717 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOTEDITABLE"));
720 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_ADD"));
725 /*bool SUPERVGUI::CustomPopup(QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) {
726 Trace("SUPERVGUI::customPopup");
728 if(popup->count() > 3) {
729 // Temporary code: is to be deleted soon
730 popup->removeItem(QAD_Display_Popup_ID);
731 popup->removeItem(QAD_DisplayOnly_Popup_ID);
732 popup->removeItem(QAD_Erase_Popup_ID);
733 int id = popup->idAt(popup->count() - 1);
734 if (id < 0 && id != -1) popup->removeItem(id); // separator
735 // Temporary code end
740 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
741 if ( aList.Extent() == 0 ) return false;
743 if ( aList.Extent() == 1 ) {
744 Handle(SALOME_InteractiveObject) anIObj = aList.First();
746 // insert SUPERV-specific popup items here
748 bool isDataflow, ownObj;
749 whatIsSelected(anIObj, ownObj, isDataflow);
752 popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow()));
753 popup->insertItem("Display", this, SLOT(displayDataflow()));
754 popup->insertSeparator();
757 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
760 if ( aList.Extent() > 1 ) {
762 SALOME_ListIteratorOfListIO It_forCheckOwner( aList );
763 for(;It_forCheckOwner.More();It_forCheckOwner.Next()) {
764 Handle(SALOME_InteractiveObject) anIObj = It_forCheckOwner.Value();
765 bool aIsOwner, aIsDataflow;
766 whatIsSelected(anIObj, aIsOwner, aIsDataflow);
768 if (aIsOwner) aIObjCount++;
770 if ( aIObjCount == aList.Extent() ) //all selected objects belong to Supervision
771 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
780 theIsOwner = true if Selected object belongs to Supervision.
781 theIsDataflow = true if Selected object is Dataflow
783 void SUPERVGUI::whatIsSelected(const _PTR(SObject)& theObj, bool& theIsOwner, bool& theIsDataflow) {
785 theIsDataflow = false;
788 _PTR(SComponent) comp ( theObj->GetFatherComponent() );
790 _PTR(GenericAttribute) anAttr;
791 if (comp->FindAttribute(anAttr, "AttributeName")) {
792 _PTR(AttributeName) aName ( anAttr );
793 QString compName(aName->Value().c_str());
794 if ( compName.compare( moduleName() ) == 0 ) {
795 _PTR(GenericAttribute) anAttr;
796 if (theObj->FindAttribute(anAttr, "AttributeIOR")) {
797 _PTR(AttributeIOR) anIOR ( anAttr );
798 SUPERV_Graph aDataFlow = engine->getGraph(anIOR->Value().c_str());
799 if (!SUPERV_isNull(aDataFlow)) {
800 if (aDataFlow->IsStreamGraph()) {
801 if (!SUPERV_isNull(aDataFlow->ToStreamGraph()))
802 theIsDataflow = true;
805 theIsDataflow = true;
808 CORBA::String_var anObjectID = theObj->GetID().c_str();
809 CORBA::String_var aComponentID = comp->GetID().c_str();
810 if (strcmp(anObjectID, aComponentID))
818 void SUPERVGUI::deleteObject() {
821 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
822 if ( aList.Extent() == 0 ) return;
824 // sak : 24.11.04 : fix for PAL6899 : if the study is locked - warn the user and return.
825 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
826 if ( aStudy->GetProperties()->IsLocked() ) {
827 QMessageBox::warning(application()->desktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"));
831 // sak : 24.11.04 : fix for PAL6901 : Incorrect deletion of the objects : pressing ESC button
832 // emitted "YES" button click, now it is corrected, and treated as "NO" button click.
833 if (QMessageBox::warning(application()->desktop(),
835 tr("MSG_ASK_DELETE"),
836 QMessageBox::No, QMessageBox::Yes) != QMessageBox::Yes)
839 SALOME_ListIteratorOfListIO It( aList );
840 for(;It.More();It.Next()) {
841 Handle(SALOME_InteractiveObject) anIObj = It.Value();
842 //bool aIsOwner, aIsDataflow;
843 //whatIsSelected(anIObj, aIsOwner, aIsDataflow);
845 _PTR(SObject) aObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
847 SUIT_Operation* op = new SalomeApp_ImportOperation( application() );
848 _PTR(StudyBuilder) aBuilder ( aStudy->NewBuilder() );
850 aBuilder->RemoveObjectWithChildren( aObj );
854 (( SalomeApp_Application* )application())->selectionMgr()->clearSelected();
858 void SUPERVGUI::OnGUIEvent()
860 const QObject* obj = sender();
861 if ( !obj || !obj->inherits( "QAction" ) )
863 int id = actionId((QAction*)obj);
868 bool SUPERVGUI::OnGUIEvent(int command) {
899 suspendResumeDataflow();
923 QMessageBox::warning(application()->desktop(), "Supervision Error", "Unknown Command From Salome");
928 /*bool SUPERVGUI::SetSettings() {
929 Trace("SUPERVGUI::SetSettings");
934 /*void SUPERVGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject) {
939 bool SUPERVGUI::ActiveStudyChanged() {
940 Trace("SUPERVGUI::activeStudyChanged");
941 study = application()->activeStudy();
945 /*void SUPERVGUI::SupportedViewType (int* buffer, int bufferSize)
947 if (!buffer || !bufferSize) return;
948 buffer[0] = (int)VIEW_GRAPHSUPERV;
951 void SUPERVGUI::fillInterfaceNameMap() {
952 //fill map: interface_name <-> component_name for all
953 //interfaces of all loaded components, it is necessary
954 //for correct adding factory nodes from AddComponent,
955 //SubComponent, MulComponent, etc. components.
956 myInterfaceNameMap.clear();
959 SALOME_NamingService* namingService = (( SalomeApp_Application* )application())->namingService();
961 CORBA::Object_ptr obj = namingService->Resolve("/Kernel/ModulCatalog");
962 SALOME_ModuleCatalog::ModuleCatalog_var* aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var;
963 *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
964 if (!CORBA::is_nil(*aModuleCatalog)) {
966 SALOME_ModuleCatalog::ListOfComponents_var aCompList = (*aModuleCatalog)->GetComponentList();
967 for (int ind1 = 0; ind1 < aCompList->length(); ind1++) {
969 SALOME_ModuleCatalog::Acomponent_ptr aComponent = (*aModuleCatalog)->GetComponent(aCompList[ind1]);
970 if ( aComponent != NULL ) {
972 SALOME_ModuleCatalog::ListOfInterfaces_var anIntList = aComponent->GetInterfaceList();
973 for (int ind2 = 0; ind2 < anIntList->length(); ind2++) {
974 const char* anIntName = anIntList[ind2];
975 myInterfaceNameMap.insert(QString(anIntName), QString(aComponent->componentname()));
982 QMap<QString, QString> SUPERVGUI::getInterfaceNameMap() const {
983 return myInterfaceNameMap;