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" ),
79 Trace("SUPERVGUI::SUPERVGUI")
82 MESSAGE("SUPERVGUI Info : factory build");
84 MESSAGE("SUPERVGUI Error : another call to factory constructor");
88 SUPERVGUI::~SUPERVGUI() {
89 Trace("SUPERVGUI::~SUPERVGUI")
92 //if (!engine->_is_nil()) CORBA::release(engine);
95 if (browser->isVisible())
99 MESSAGE("SUPERVGUI Info : factory destroy");
101 MESSAGE("SUPERVGUI Error : another call to factory destructor");
105 SUPERVGUI* SUPERVGUI::Supervision() {
106 CAM_Application* anApp = dynamic_cast<CAM_Application*>( SUIT_Session::session()->activeApplication() );
108 SUPERVGUI* aSupervModule = dynamic_cast<SUPERVGUI*>( anApp->activeModule() );
109 return aSupervModule;
114 void SUPERVGUI::createSupervAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle )
117 QWidget* parent = application()->desktop();
118 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
120 if ( icon_id.length() )
121 pix = resMgr->loadPixmap( "SUPERV", tr( icon_id ) );
123 pix = resMgr->loadPixmap( "SUPERV", tr( QString( "ICO_" )+po_id ) );
125 icon = QIconSet( pix );
127 QString tooltip = tr( QString( "TOP_" )+po_id ),
128 menu = tr( QString( "MEN_" )+po_id ),
129 status_bar = tr( QString( "STB_" )+po_id );
131 createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() ) );
134 void SUPERVGUI::initialize( CAM_Application* app )
136 SalomeApp_Module::initialize( app );
138 SALOME_NamingService* namingService = (( SalomeApp_Application* )application())->namingService();
139 loadEngine(namingService);
141 browser = new SUPERVGUI_Service(namingService);
142 //info = new SUPERVGUI_Information();
143 cursor = application()->desktop()->cursor();
145 fillInterfaceNameMap();
147 // ----- create actions --------------
148 createSupervAction( 301, "IMPORT" );
149 createSupervAction( 302, "EXPORT" );
151 createSupervAction( 303, "NEW" );
152 createSupervAction( 304, "MODIFY" );
154 createSupervAction( 305, "RELOAD" );
155 createSupervAction( 306, "RUN" );
156 createSupervAction( 307, "KILL" );
157 createSupervAction( 308, "SUSPEND/RESUME" );
158 createSupervAction( 309, "ADDNODE" );
159 createSupervAction( 310, "STEPBYSTEP" );
161 createSupervAction( 311, "POP_RENAME" );
162 createSupervAction( 312, "POP_DISPLAY" );
163 createSupervAction( 313, "POP_DELETE" );
165 // ----- create menu -----------------
166 int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
167 createMenu( 301, fileId, 10 );
168 createMenu( 302, fileId, 10 );
169 createMenu( separator(), fileId, 10 );
171 int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
172 createMenu( separator(), fileId, 7 );
173 createMenu( 303, editId, -1 );
174 createMenu( 304, editId, -1 );
176 int supervId = createMenu( tr( "MEN_SUPERV" ), -1, -1, 10/*, 300*/ );
177 createMenu( 305, supervId, -1 );
178 createMenu( 309, supervId, -1 );
179 createMenu( separator(), fileId, 3 );
180 createMenu( 306, supervId, -1 );
181 createMenu( 310, supervId, -1 );
182 createMenu( 307, supervId, -1 );
183 createMenu( 308, supervId, -1 );
185 // ----- create toolbars -------------
186 int supervisorId = createTool( tr( "TOOL_SUPERVISOR" ) );
187 createTool( 301, supervisorId );
188 createTool( 302, supervisorId );
189 createTool( 303, supervisorId );
190 createTool( 304, supervisorId );
191 createTool( 305, supervisorId );
192 createTool( 309, supervisorId );
194 int executionId = createTool( tr( "TOOL_EXECUTION" ) );
195 createTool( 306, executionId );
196 createTool( 310, executionId );
197 createTool( 307, executionId );
198 createTool( 308, executionId );
200 // ----- create popup for object browser items -------------
201 QtxPopupMgr* mgr = popupMgr();
202 mgr->insert( action( 311 ), -1, -1 ); // rename dataflow
203 mgr->setRule( action( 311 ), "$type in {'Dataflow'} and selcount=1", true );
204 mgr->insert( action( 312 ), -1, -1 ); // display dataflow
205 mgr->setRule( action( 312 ), "$type in {'Dataflow'} and selcount=1", true );
206 mgr->insert( separator(), -1, -1 ); // -----------
207 mgr->insert( action( 313 ), -1, -1 ); // delete object
208 mgr->setRule( action( 313 ), "$client in {'ObjectBrowser'} and $type in {'Dataflow' 'SupervisorObject'} and selcount>0", true );
211 bool SUPERVGUI::activateModule( SUIT_Study* theStudy )
213 if ( CORBA::is_nil( engine ) )
216 if ( !SalomeApp_Module::activateModule( theStudy ) )
221 //---------------------------------------
222 setMenuShown( true );
223 setToolShown( true );
225 study = application()->activeStudy();
227 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
228 this, SLOT( setMain( SUIT_ViewWindow* ) ) );
233 QString SUPERVGUI::engineIOR() const
235 if ( !CORBA::is_nil( engine ) )
236 return QString( getApp()->orb()->object_to_string( engine));
237 return QString( "" );
240 bool SUPERVGUI::deactivateModule( SUIT_Study* theStudy )
242 setMenuShown( false );
243 setToolShown( false );
245 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
246 this, SLOT( setMain( SUIT_ViewWindow* ) ) );
247 //---------------------------------------
249 return SalomeApp_Module::deactivateModule( theStudy );
252 CAM_DataModel* SUPERVGUI::createDataModel()
254 return new SUPERVGUI_DataModel( this );
257 SalomeApp_Selection* SUPERVGUI::createSelection() const
259 return new SUPERVGUI_Selection();
262 SUIT_ViewWindow* SUPERVGUI::createGraph() {
263 SUPERVGraph_ViewManager* aVM = new SUPERVGraph_ViewManager( study, application()->desktop(), new SUPERVGraph_Viewer() );
264 SUIT_ViewWindow* aVW = aVM->createViewWindow();
267 SIGNAL( deleteView( SUIT_ViewWindow* ) ),
269 SLOT( onGraphClosed( SUIT_ViewWindow* ) ) );
276 void SUPERVGUI::loadEngine(SALOME_NamingService* namingService) {
277 Trace("SUPERVGUI::loadEngine")
278 SALOME_LifeCycleCORBA LCC(namingService);
279 Engines::Component_var objComponent = LCC.FindOrLoad_Component("SuperVisionContainer", "SUPERV");
280 if (CORBA::is_nil(objComponent)) {
281 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_CANT_LOAD_SUPERV"));
285 SUPERV::SuperG_var aSuperVisionComponent;
286 aSuperVisionComponent = SUPERV::SuperG::_narrow(objComponent);
287 if (CORBA::is_nil(aSuperVisionComponent)) {
288 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_CANT_NARROW_SUPERV"));
292 // engine = new SUPERV::SuperG_var;
293 engine = aSuperVisionComponent;
297 bool SUPERVGUI::information(SUPERV_CNode node, bool isReadOnly) {
298 Trace("SUPERVGUI::information")
299 return(info->run(node, isReadOnly));
302 void SUPERVGUI::putInfo(const char* mess) {
303 Trace("SUPERVGUI::putInfo")
304 application()->putInfo(mess);
307 SUPERV_Engine SUPERVGUI::getEngine() {
308 Trace("SUPERVGUI::getEngine")
312 SUPERVGUI_Service* SUPERVGUI::getBrowser() {
313 Trace("SUPERVGUI::getBrowser")
317 QCursor SUPERVGUI::getCursor() {
318 Trace("SUPERVGUI::getCursor")
322 SUPERVGUI_Main* SUPERVGUI::getMain() {
323 Trace("SUPERVGUI::getMain")
328 void SUPERVGUI::registerGraph(QString theName, SUPERVGUI_Main* theGraph){
329 theGraph->setHashCode(theName);
330 myGraphList.append(theGraph);
334 void SUPERVGUI::unregisterGraph(SUPERVGUI_Main* theGraph) {
335 SUPERVGUI_Main* aMain;
336 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
337 if (aMain == theGraph)
338 myGraphList.remove(aMain);
343 bool SUPERVGUI::isContains(SUIT_Study* theStudy, const QString theKey) {
344 SUPERVGUI_Main* aMain;
345 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
346 if ((aMain->getStudy() == theStudy) && (aMain->getHashCode() == theKey))
353 void SUPERVGUI::onGraphClosed(SUIT_ViewWindow* theViewWindow) {
354 if( SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(theViewWindow) ) {
355 disconnect(supervFrame->getViewManager(), 0 , this, 0);
356 SUPERVGraph_View* view = supervFrame->getViewWidget();
357 SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
359 unregisterGraph(aGraph);
360 SUPERV_Graph aDataFlow = aGraph->getDataflow();
361 if ( !SUPERV_isNull( aDataFlow ) ) {
362 if ( aDataFlow->IsExecuting() ) {
363 const int aMsgResult = QMessageBox::warning(application()->desktop(),
365 tr("MSG_DF_RUNNING"),
366 tr("MSG_DF_EXECUTION"),
368 if ( aMsgResult == 1 ) {
370 if ( aDataFlow->Kill() ) {
371 // Kill() sends KillEvent and KillState to SUPERVGUI_Thread
372 // while sets myIsActive flag to false when it receives such event/state
373 // after myIsActive is false it calls QThread::exit() to terminate.
375 // why while() { qApp->processEvents() } ?
376 // because: SUPERVGUI_Thread::run() receives events, and calls myMain->execute()
377 // method using SALOME_Event paradigm, ProcessVoidEvent() function -
378 // it puts this event to the main application event loop, in which we are being now.
379 // So if we block main GUI application thread (by calling aGraph->getMyThread()->wait() here)
380 // then we will have a deadlock of 2 threads waiting for one another
381 while (aGraph->getMyThread()->running())
382 qApp->processEvents();
385 else { // BACKGROUND EXECUTION
386 emit KillMainThread(true); // set SUPERVGUI_Thread::myIsActive to false
387 while ( aGraph->getMyThread()->running() )
388 qApp->processEvents();
391 else { // EXECUTION IS FINISHED, JUST DESTROY THE SUPERVGUI_Thread object and return.
392 emit KillMainThread(true);
393 while ( aGraph->getMyThread()->running() )
394 qApp->processEvents();
401 void SUPERVGUI::setMain( SUIT_ViewWindow* w) {
405 study = w->getViewManager()->study();
409 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(w)){
410 SUPERVGraph_View* view = supervFrame->getViewWidget();
412 main = dynamic_cast<SUPERVGUI_Main*>(view);
413 connect(this, SIGNAL(KillMainThread(bool)), main->getMyThread(), SLOT(KillThread(bool)));
416 Trace("SUPERVGUI::setMain - main: "<<main);
419 void SUPERVGUI::displayDataflow() {
420 Trace("SUPERVGUI::displayDataflow");
421 OB_Browser* aBrowser = (( SalomeApp_Application* )application())->objectBrowser();
422 SUPERV_Graph aDataFlow;
425 OB_ListItem* item = (OB_ListItem*)(aBrowser->listView()->currentItem());
427 ( (( SalomeApp_Study* )(application()->activeStudy()))->studyDS()->FindObjectID(item->text(2).latin1()) );
428 _PTR(GenericAttribute) anAttr;
429 if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
430 _PTR(AttributeIOR) anIOR ( anAttr );
431 aIORName = QString(anIOR->Value().c_str());
432 if (isContains(study, aIORName)) {
433 if (QMessageBox::warning(application()->desktop(), tr("WARNING"),
434 tr("MSG_GRAPH_DISPLAYED").arg(""),
435 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
438 //aDataFlow = engine->getStreamGraph(anIOR->Value().c_str());
439 aDataFlow = engine->getGraph(anIOR->Value().c_str());
440 if (SUPERV_isNull(aDataFlow)) {
441 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
444 /* ASV: 20.10.04: fix for 6896
445 if (aDataFlow->IsStreamGraph()) {
446 SUPERV_StreamGraph aDataFlowStream = aDataFlow->ToStreamGraph();
447 if (SUPERV_isNull(aDataFlowStream)) {
448 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
451 aDataFlow = aDataFlowStream;
455 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( createGraph() );
457 main = new SUPERVGUI_Main( aViewFrame, application()->desktop(), aDataFlow );
458 registerGraph( aIORName, main );
464 void SUPERVGUI::renameDataflow() {
467 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
469 SALOME_ListIteratorOfListIO It( aList );
470 for ( ; It.More(); It.Next() ) {
471 Handle(SALOME_InteractiveObject) IObject = It.Value();
473 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
474 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
475 _PTR(GenericAttribute) anAttr;
477 if ( obj->FindAttribute(anAttr, "AttributeName") ) {
478 _PTR(AttributeName) aName ( anAttr );
479 QString nm = QString( aName->Value().c_str() );
480 nm = SalomeApp_NameDlg::getName( application()->desktop(), nm );
481 if ( !nm.isEmpty() ) {
482 // sak : 24.11.04 : fix for PAL6898 : if rename fails (study locked),
483 // a message box is displayed, and cursor is "wait cursor". We think that "wait cursor"
484 // is not neccessary here, because the rename operation is fast.
485 //QApplication::setOverrideCursor( Qt::waitCursor );
486 //study->renameIObject( IObject, nm );
489 aName->SetValue( nm.latin1() );
490 //rename Interactive object
491 IObject->setName( ( char* )nm.latin1() );
495 //QApplication::restoreOverrideCursor();
502 void SUPERVGUI::exportDataflow() {
503 Trace("SUPERVGUI::exportDataflow")
505 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
507 else if ( SUPERV_isNull( main->getDataflow() ) ) { // should not normally happen..
508 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
511 QString f = SUIT_FileDlg::getFileName(application()->desktop(),
514 tr("TTL_EXPORT_DATAFLOW"),
516 if ( !f.isEmpty() ) {
518 // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file,
519 // a backup copy of an existing file must be created (in case Export fails..)
520 QString aBackupFile = SUPERVGUI::createBackupFile( f );
522 if ( main->getDataflow()->Export(f.latin1()) ) {
523 unregisterGraph(main);
524 registerGraph(f, main);
526 // remove a backup file if export was successfull
527 if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() )
528 QFile::remove( aBackupFile );
531 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile));
538 *If a file with theOriginalFileName exists, then the function tries to create
539 * its backup copy of it (the_name + ".bakX", X = 0,1,2,..,99). Returns backup file's name
540 * If a file with theOriginalFileName does not exist, or creation fails - Return empty string.
542 QString SUPERVGUI::createBackupFile( const QString& theOriginalFileName ) {
543 QString theBackupFileName("");
544 if ( QFile::exists( theOriginalFileName ) ) {
545 // 1. construct a backup file name
548 theBackupFileName = theOriginalFileName;
549 theBackupFileName += ".bak";
550 theBackupFileName += QString::number(i++);
552 while ( QFile::exists( theBackupFileName ) && i < 100 ); // max 99 backup files
553 // if *.bak99 exists -- it will be overwritten
555 // 2. copy the original file to theBackupFileName
556 QString cmd( "cp \"");
557 cmd += theOriginalFileName;
559 cmd += theBackupFileName;
561 bool res = system( cmd.latin1() );
563 theBackupFileName = QString("");
565 return theBackupFileName;
568 void SUPERVGUI::windows( QMap<int, int>& mappa ) const
570 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
571 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
572 mappa.insert( SalomeApp_Application::WT_LogWindow, Qt::DockBottom );
575 void SUPERVGUI::newDataflow() {
576 createDataflow( New );
579 void SUPERVGUI::importDataflow() {
580 createDataflow( Import );
583 void SUPERVGUI::modifyDataflow() {
584 createDataflow( Modify );
587 bool SUPERVGUI::createDataflow( const NEW_DF_MODE mode ) {
588 Trace("SUPERVGUI::createDataflow, mode = " << mode );
590 // asv : 27.01.05 : fix for PAL7823 : if the study is locked - warn the user and return.
591 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
592 if ( aStudy->GetProperties()->IsLocked() ) {
593 QMessageBox::warning(application()->desktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"));
597 SUPERV::Graph_var aGraph;
599 QString f; // file name. declared here because may be used below in error msg construction..
600 if ( mode == Import || mode == Modify ) { // 0. import or modify existing dataflow - select XML file
601 QString title = QString( "TLT_CREATE_DF_%1" ).arg( mode );
602 f = SUIT_FileDlg::getFileName( application()->desktop(), "", "*.xml", tr( title ), true );
603 if ( f.isEmpty() ) // pressed Cancel in file select dialog
606 // check if study already contains a graph imported from the same file
607 if ( isContains( study, f ) ) {
608 if ( QMessageBox::warning( application()->desktop(), tr("WARNING"), tr("MSG_GRAPH_DISPLAYED").arg(f),
609 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No )
614 aGraph = ( mode == Import ) ? engine->StreamGraphE( f ) : engine->StreamGraph( f );
617 aGraph = engine->StreamGraph( MAIN_NEW );
619 if ( CORBA::is_nil( aGraph ) ) {
620 QString msg( mode == New ? tr("MSG_CANT_CREATE_DF") : tr("MSG_BAD_FILE").arg(f) );
621 SUIT_MessageBox::warn1( application()->desktop(), tr("ERROR"), tr(msg), tr("BUT_OK") );
625 // 2. create a ViewFrame object
626 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( createGraph() );
629 // 3. bind Graph and ViewFrame == create SUPERVGUI_Main object
630 main = new SUPERVGUI_Main( aViewFrame, application()->desktop(), aGraph );
634 registerGraph( f, main );
641 void SUPERVGUI::reloadDataflow() {
642 Trace("SUPERVGUI::reloadDataflow");
646 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RELOAD"));
649 void SUPERVGUI::runDataflow() {
650 Trace("SUPERVGUI::runDataflow");
652 main->run( /*andSuspend=*/false );
654 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
657 void SUPERVGUI::stepByStep() {
658 Trace("SUPERVGUI::stepByStep");
660 main->run( /*andSuspend=*/true );
662 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
665 void SUPERVGUI::killDataflow() {
666 Trace("SUPERVGUI::killDataflow");
670 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_KILL"));
673 void SUPERVGUI::suspendResumeDataflow() {
674 Trace("SUPERVGUI::suspendResumeDataflow");
676 main->suspendResume();
678 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_SUSPEND"));
681 void SUPERVGUI::showComponents() {
682 Trace("SUPERVGUI::showComponents");
684 if ( main->isEditable() )
687 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOTEDITABLE"));
690 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_ADD"));
695 /*bool SUPERVGUI::CustomPopup(QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) {
696 Trace("SUPERVGUI::customPopup");
698 if(popup->count() > 3) {
699 // Temporary code: is to be deleted soon
700 popup->removeItem(QAD_Display_Popup_ID);
701 popup->removeItem(QAD_DisplayOnly_Popup_ID);
702 popup->removeItem(QAD_Erase_Popup_ID);
703 int id = popup->idAt(popup->count() - 1);
704 if (id < 0 && id != -1) popup->removeItem(id); // separator
705 // Temporary code end
710 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
711 if ( aList.Extent() == 0 ) return false;
713 if ( aList.Extent() == 1 ) {
714 Handle(SALOME_InteractiveObject) anIObj = aList.First();
716 // insert SUPERV-specific popup items here
718 bool isDataflow, ownObj;
719 whatIsSelected(anIObj, ownObj, isDataflow);
722 popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow()));
723 popup->insertItem("Display", this, SLOT(displayDataflow()));
724 popup->insertSeparator();
727 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
730 if ( aList.Extent() > 1 ) {
732 SALOME_ListIteratorOfListIO It_forCheckOwner( aList );
733 for(;It_forCheckOwner.More();It_forCheckOwner.Next()) {
734 Handle(SALOME_InteractiveObject) anIObj = It_forCheckOwner.Value();
735 bool aIsOwner, aIsDataflow;
736 whatIsSelected(anIObj, aIsOwner, aIsDataflow);
738 if (aIsOwner) aIObjCount++;
740 if ( aIObjCount == aList.Extent() ) //all selected objects belong to Supervision
741 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
750 theIsOwner = true if Selected object belongs to Supervision.
751 theIsDataflow = true if Selected object is Dataflow
753 void SUPERVGUI::whatIsSelected(const _PTR(SObject)& theObj, bool& theIsOwner, bool& theIsDataflow) {
755 theIsDataflow = false;
758 _PTR(SComponent) comp ( theObj->GetFatherComponent() );
760 _PTR(GenericAttribute) anAttr;
761 if (comp->FindAttribute(anAttr, "AttributeName")) {
762 _PTR(AttributeName) aName ( anAttr );
763 QString compName(aName->Value().c_str());
764 if ( compName.compare( moduleName() ) == 0 ) {
765 _PTR(GenericAttribute) anAttr;
766 if (theObj->FindAttribute(anAttr, "AttributeIOR")) {
767 _PTR(AttributeIOR) anIOR ( anAttr );
768 SUPERV_Graph aDataFlow = engine->getGraph(anIOR->Value().c_str());
769 if (!SUPERV_isNull(aDataFlow)) {
770 if (aDataFlow->IsStreamGraph()) {
771 if (!SUPERV_isNull(aDataFlow->ToStreamGraph()))
772 theIsDataflow = true;
775 theIsDataflow = true;
778 CORBA::String_var anObjectID = theObj->GetID().c_str();
779 CORBA::String_var aComponentID = comp->GetID().c_str();
780 if (strcmp(anObjectID, aComponentID))
788 void SUPERVGUI::deleteObject() {
791 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
792 if ( aList.Extent() == 0 ) return;
794 // sak : 24.11.04 : fix for PAL6899 : if the study is locked - warn the user and return.
795 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
796 if ( aStudy->GetProperties()->IsLocked() ) {
797 QMessageBox::warning(application()->desktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"));
801 // sak : 24.11.04 : fix for PAL6901 : Incorrect deletion of the objects : pressing ESC button
802 // emitted "YES" button click, now it is corrected, and treated as "NO" button click.
803 if (QMessageBox::warning(application()->desktop(),
805 tr("MSG_ASK_DELETE"),
806 QMessageBox::No, QMessageBox::Yes) != QMessageBox::Yes)
809 SALOME_ListIteratorOfListIO It( aList );
810 for(;It.More();It.Next()) {
811 Handle(SALOME_InteractiveObject) anIObj = It.Value();
812 //bool aIsOwner, aIsDataflow;
813 //whatIsSelected(anIObj, aIsOwner, aIsDataflow);
815 _PTR(SObject) aObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
817 SUIT_Operation* op = new SalomeApp_ImportOperation( application() );
818 _PTR(StudyBuilder) aBuilder ( aStudy->NewBuilder() );
820 aBuilder->RemoveObjectWithChildren( aObj );
824 (( SalomeApp_Application* )application())->selectionMgr()->clearSelected();
828 void SUPERVGUI::OnGUIEvent()
830 const QObject* obj = sender();
831 if ( !obj || !obj->inherits( "QAction" ) )
833 int id = actionId((QAction*)obj);
838 bool SUPERVGUI::OnGUIEvent(int command) {
869 suspendResumeDataflow();
893 QMessageBox::warning(application()->desktop(), "Supervision Error", "Unknown Command From Salome");
898 /*bool SUPERVGUI::SetSettings() {
899 Trace("SUPERVGUI::SetSettings");
904 /*void SUPERVGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject) {
909 bool SUPERVGUI::ActiveStudyChanged() {
910 Trace("SUPERVGUI::activeStudyChanged");
911 study = application()->activeStudy();
915 /*void SUPERVGUI::SupportedViewType (int* buffer, int bufferSize)
917 if (!buffer || !bufferSize) return;
918 buffer[0] = (int)VIEW_GRAPHSUPERV;
921 void SUPERVGUI::fillInterfaceNameMap() {
922 //fill map: interface_name <-> component_name for all
923 //interfaces of all loaded components, it is necessary
924 //for correct adding factory nodes from AddComponent,
925 //SubComponent, MulComponent, etc. components.
926 myInterfaceNameMap.clear();
929 SALOME_NamingService* namingService = (( SalomeApp_Application* )application())->namingService();
931 CORBA::Object_ptr obj = namingService->Resolve("/Kernel/ModulCatalog");
932 SALOME_ModuleCatalog::ModuleCatalog_var* aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var;
933 *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
934 if (!CORBA::is_nil(*aModuleCatalog)) {
936 SALOME_ModuleCatalog::ListOfComponents_var aCompList = (*aModuleCatalog)->GetComponentList();
937 for (int ind1 = 0; ind1 < aCompList->length(); ind1++) {
939 SALOME_ModuleCatalog::Acomponent_ptr aComponent = (*aModuleCatalog)->GetComponent(aCompList[ind1]);
940 if ( aComponent != NULL ) {
942 SALOME_ModuleCatalog::ListOfInterfaces_var anIntList = aComponent->GetInterfaceList();
943 for (int ind2 = 0; ind2 < anIntList->length(); ind2++) {
944 const char* anIntName = anIntList[ind2];
945 myInterfaceNameMap.insert(QString(anIntName), QString(aComponent->componentname()));
952 QMap<QString, QString> SUPERVGUI::getInterfaceNameMap() const {
953 return myInterfaceNameMap;