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"
32 #include "SALOMEDSClient.hxx"
33 #include <boost/shared_ptr.hpp>
34 using namespace boost;
36 #include "CAM_Application.h"
37 #include "OB_Browser.h"
38 #include "OB_ListItem.h"
39 #include "SalomeApp_Application.h"
40 #include "SalomeApp_ImportOperation.h"
41 #include "SalomeApp_NameDlg.h"
42 #include "SalomeApp_SelectionMgr.h"
43 #include "SalomeApp_Study.h"
44 #include "SUIT_Desktop.h"
45 #include "SUIT_FileDlg.h"
46 #include "SUIT_MessageBox.h"
47 #include "SUIT_Operation.h"
48 #include "SUIT_ResourceMgr.h"
49 #include "SUIT_Session.h"
50 #include "SUIT_Study.h"
52 #include "SUPERVGraph_ViewManager.h"
54 #include "SALOME_ListIO.hxx"
55 #include "SALOME_ListIteratorOfListIO.hxx"
56 #include "SALOME_InteractiveObject.hxx"
57 #include "Utils_ORB_INIT.hxx"
59 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
63 int SUPERVGUI::factory = 0;
66 Standard_EXPORT CAM_Module* createModule() {
67 return new SUPERVGUI();
72 SUPERVGUI::SUPERVGUI()
73 : SalomeApp_Module( "SUPERV" ),
78 Trace("SUPERVGUI::SUPERVGUI")
81 MESSAGE("SUPERVGUI Info : factory build");
83 MESSAGE("SUPERVGUI Error : another call to factory constructor");
87 SUPERVGUI::~SUPERVGUI() {
88 Trace("SUPERVGUI::~SUPERVGUI")
91 //if (!engine->_is_nil()) CORBA::release(engine);
94 if (browser->isVisible())
98 MESSAGE("SUPERVGUI Info : factory destroy");
100 MESSAGE("SUPERVGUI Error : another call to factory destructor");
104 SUPERVGUI* SUPERVGUI::Supervision() {
105 CAM_Application* anApp = dynamic_cast<CAM_Application*>( SUIT_Session::session()->activeApplication() );
107 SUPERVGUI* aSupervModule = dynamic_cast<SUPERVGUI*>( anApp->activeModule() );
108 return aSupervModule;
113 void SUPERVGUI::createSupervAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle )
116 QWidget* parent = application()->desktop();
117 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
119 if ( icon_id.length() )
120 pix = resMgr->loadPixmap( "SUPERV", tr( icon_id ) );
122 pix = resMgr->loadPixmap( "SUPERV", tr( QString( "ICO_" )+po_id ) );
124 icon = QIconSet( pix );
126 QString tooltip = tr( QString( "TOP_" )+po_id ),
127 menu = tr( QString( "MEN_" )+po_id ),
128 status_bar = tr( QString( "STB_" )+po_id );
130 createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() ) );
133 void SUPERVGUI::initialize( CAM_Application* app )
135 SalomeApp_Module::initialize( app );
137 SALOME_NamingService* namingService = (( SalomeApp_Application* )application())->namingService();
138 loadEngine(namingService);
140 browser = new SUPERVGUI_Service(namingService);
141 //info = new SUPERVGUI_Information();
142 cursor = application()->desktop()->cursor();
144 // ----- create actions --------------
145 createSupervAction( 301, "IMPORT" );
146 createSupervAction( 302, "EXPORT" );
148 createSupervAction( 303, "NEW" );
149 createSupervAction( 304, "MODIFY" );
151 createSupervAction( 305, "RELOAD" );
152 createSupervAction( 306, "RUN" );
153 createSupervAction( 307, "KILL" );
154 createSupervAction( 308, "SUSPEND/RESUME" );
155 createSupervAction( 309, "ADDNODE" );
156 createSupervAction( 310, "STEPBYSTEP" );
158 // ----- create menu -----------------
159 int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
160 createMenu( 301, fileId, 10 );
161 createMenu( 302, fileId, 10 );
162 createMenu( separator(), fileId, 10 );
164 int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
165 createMenu( separator(), fileId, 7 );
166 createMenu( 303, editId, -1 );
167 createMenu( 304, editId, -1 );
169 int supervId = createMenu( tr( "MEN_SUPERV" ), -1, -1, 10/*, 300*/ );
170 createMenu( 305, supervId, -1 );
171 createMenu( 309, supervId, -1 );
172 createMenu( separator(), fileId, 3 );
173 createMenu( 306, supervId, -1 );
174 createMenu( 310, supervId, -1 );
175 createMenu( 307, supervId, -1 );
176 createMenu( 308, supervId, -1 );
178 // ----- create toolbars -------------
179 int supervisorId = createTool( tr( "TOOL_SUPERVISOR" ) );
180 createTool( 301, supervisorId );
181 createTool( 302, supervisorId );
182 createTool( 303, supervisorId );
183 createTool( 304, supervisorId );
184 createTool( 305, supervisorId );
185 createTool( 309, supervisorId );
187 int executionId = createTool( tr( "TOOL_EXECUTION" ) );
188 createTool( 306, executionId );
189 createTool( 310, executionId );
190 createTool( 307, executionId );
191 createTool( 308, executionId );
195 void SUPERVGUI::activateModule( SUIT_Study* theStudy )
197 SalomeApp_Module::activateModule( theStudy );
199 //---------------------------------------
200 setMenuShown( true );
201 setToolShown( true );
203 study = application()->activeStudy();
205 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
206 this, SLOT( setMain( SUIT_ViewWindow* ) ) );
210 QString SUPERVGUI::engineIOR() const
212 if ( !CORBA::is_nil( engine ) )
213 return QString( getApp()->orb()->object_to_string( engine));
214 return QString( "" );
217 void SUPERVGUI::deactivateModule( SUIT_Study* theStudy )
219 setMenuShown( false );
220 setToolShown( false );
222 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
223 this, SLOT( setMain( SUIT_ViewWindow* ) ) );
224 //---------------------------------------
226 SalomeApp_Module::deactivateModule( theStudy );
229 CAM_DataModel* SUPERVGUI::createDataModel()
231 return new SUPERVGUI_DataModel( this );
234 SUIT_ViewWindow* SUPERVGUI::createGraph() {
235 SUPERVGraph_ViewManager* aVM = new SUPERVGraph_ViewManager( study, application()->desktop(), new SUPERVGraph_Viewer() );
236 SUIT_ViewWindow* aVW = aVM->createViewWindow();
239 SIGNAL( deleteView( SUIT_ViewWindow* ) ),
241 SLOT( onGraphClosed( SUIT_ViewWindow* ) ) );
248 void SUPERVGUI::loadEngine(SALOME_NamingService* namingService) {
249 Trace("SUPERVGUI::loadEngine")
250 SALOME_LifeCycleCORBA LCC(namingService);
251 Engines::Component_var objComponent = LCC.FindOrLoad_Component("SuperVisionContainer", "SUPERV");
252 if (CORBA::is_nil(objComponent)) {
253 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_CANT_LOAD_SUPERV"));
257 SUPERV::SuperG_var aSuperVisionComponent;
258 aSuperVisionComponent = SUPERV::SuperG::_narrow(objComponent);
259 if (CORBA::is_nil(aSuperVisionComponent)) {
260 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_CANT_NARROW_SUPERV"));
264 // engine = new SUPERV::SuperG_var;
265 engine = aSuperVisionComponent;
269 bool SUPERVGUI::information(SUPERV_CNode node, bool isReadOnly) {
270 Trace("SUPERVGUI::information")
271 return(info->run(node, isReadOnly));
274 void SUPERVGUI::putInfo(const char* mess) {
275 Trace("SUPERVGUI::putInfo")
276 application()->putInfo(mess);
279 SUPERV_Engine SUPERVGUI::getEngine() {
280 Trace("SUPERVGUI::getEngine")
284 SUPERVGUI_Service* SUPERVGUI::getBrowser() {
285 Trace("SUPERVGUI::getBrowser")
289 QCursor SUPERVGUI::getCursor() {
290 Trace("SUPERVGUI::getCursor")
294 SUPERVGUI_Main* SUPERVGUI::getMain() {
295 Trace("SUPERVGUI::getMain")
300 void SUPERVGUI::registerGraph(QString theName, SUPERVGUI_Main* theGraph){
301 theGraph->setHashCode(theName);
302 myGraphList.append(theGraph);
306 void SUPERVGUI::unregisterGraph(SUPERVGUI_Main* theGraph) {
307 SUPERVGUI_Main* aMain;
308 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
309 if (aMain == theGraph)
310 myGraphList.remove(aMain);
315 bool SUPERVGUI::isContains(SUIT_Study* theStudy, const QString theKey) {
316 SUPERVGUI_Main* aMain;
317 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
318 if ((aMain->getStudy() == theStudy) && (aMain->getHashCode() == theKey))
325 void SUPERVGUI::onGraphClosed(SUIT_ViewWindow* theViewWindow) {
326 if( SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(theViewWindow) ) {
327 disconnect(supervFrame->getViewManager(), 0 , this, 0);
328 SUPERVGraph_View* view = supervFrame->getViewWidget();
329 SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
331 unregisterGraph(aGraph);
332 SUPERV_Graph aDataFlow = aGraph->getDataflow();
333 if ( !SUPERV_isNull( aDataFlow ) ) {
334 if ( aDataFlow->IsExecuting() ) {
335 const int aMsgResult = QMessageBox::warning(application()->desktop(),
337 tr("MSG_DF_RUNNING"),
338 tr("MSG_DF_EXECUTION"),
340 if ( aMsgResult == 1 ) {
342 if ( aDataFlow->Kill() ) {
343 // Kill() sends KillEvent and KillState to SUPERVGUI_Thread
344 // while sets myIsActive flag to false when it receives such event/state
345 // after myIsActive is false it calls QThread::exit() to terminate.
347 // why while() { qApp->processEvents() } ?
348 // because: SUPERVGUI_Thread::run() receives events, and calls myMain->execute()
349 // method using SALOME_Event paradigm, ProcessVoidEvent() function -
350 // it puts this event to the main application event loop, in which we are being now.
351 // So if we block main GUI application thread (by calling aGraph->getMyThread()->wait() here)
352 // then we will have a deadlock of 2 threads waiting for one another
353 while (aGraph->getMyThread()->running())
354 qApp->processEvents();
357 else { // BACKGROUND EXECUTION
358 emit KillMainThread(true); // set SUPERVGUI_Thread::myIsActive to false
359 while ( aGraph->getMyThread()->running() )
360 qApp->processEvents();
363 else { // EXECUTION IS FINISHED, JUST DESTROY THE SUPERVGUI_Thread object and return.
364 emit KillMainThread(true);
365 while ( aGraph->getMyThread()->running() )
366 qApp->processEvents();
373 void SUPERVGUI::setMain( SUIT_ViewWindow* w) {
377 study = w->getViewManager()->study();
379 cout<<" setMain(...) : NULL study!";
383 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(w)){
384 SUPERVGraph_View* view = supervFrame->getViewWidget();
386 main = dynamic_cast<SUPERVGUI_Main*>(view);
387 connect(this, SIGNAL(KillMainThread(bool)), main->getMyThread(), SLOT(KillThread(bool)));
390 Trace("SUPERVGUI::setMain - main: "<<main);
393 void SUPERVGUI::displayDataflow() {
394 Trace("SUPERVGUI::displayDataflow");
395 OB_Browser* aBrowser = (( SalomeApp_Application* )application())->objectBrowser();
396 SUPERV_Graph aDataFlow;
399 OB_ListItem* item = (OB_ListItem*)(aBrowser->getListView()->currentItem());
401 ( (( SalomeApp_Study* )(application()->activeStudy()))->studyDS()->FindObjectID(item->text(2).latin1()) );
402 _PTR(GenericAttribute) anAttr;
403 if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
404 _PTR(AttributeIOR) anIOR ( anAttr );
405 aIORName = QString(anIOR->Value().c_str());
406 if (isContains(study, aIORName)) {
407 if (QMessageBox::warning(application()->desktop(), tr("WARNING"),
408 tr("MSG_GRAPH_DISPLAYED").arg(""),
409 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
412 //aDataFlow = engine->getStreamGraph(anIOR->Value().c_str());
413 aDataFlow = engine->getGraph(anIOR->Value().c_str());
414 if (SUPERV_isNull(aDataFlow)) {
415 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
418 /* ASV: 20.10.04: fix for 6896
419 if (aDataFlow->IsStreamGraph()) {
420 SUPERV_StreamGraph aDataFlowStream = aDataFlow->ToStreamGraph();
421 if (SUPERV_isNull(aDataFlowStream)) {
422 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
425 aDataFlow = aDataFlowStream;
429 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( createGraph() );
431 main = new SUPERVGUI_Main( aViewFrame, application()->desktop(), aDataFlow );
432 registerGraph( aIORName, main );
438 void SUPERVGUI::renameDataflow() {
441 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
443 SALOME_ListIteratorOfListIO It( aList );
444 for ( ; It.More(); It.Next() ) {
445 Handle(SALOME_InteractiveObject) IObject = It.Value();
447 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
448 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
449 _PTR(GenericAttribute) anAttr;
451 if ( obj->FindAttribute(anAttr, "AttributeName") ) {
452 _PTR(AttributeName) aName ( anAttr );
453 QString nm = QString( aName->Value().c_str() );
454 nm = SalomeApp_NameDlg::getName( application()->desktop(), nm );
455 if ( !nm.isEmpty() ) {
456 // sak : 24.11.04 : fix for PAL6898 : if rename fails (study locked),
457 // a message box is displayed, and cursor is "wait cursor". We think that "wait cursor"
458 // is not neccessary here, because the rename operation is fast.
459 //QApplication::setOverrideCursor( Qt::waitCursor );
460 //study->renameIObject( IObject, nm );
463 aName->SetValue( nm.latin1() );
464 //rename Interactive object
465 IObject->setName( ( char* )nm.latin1() );
469 //QApplication::restoreOverrideCursor();
476 void SUPERVGUI::exportDataflow() {
477 Trace("SUPERVGUI::exportDataflow")
479 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
481 else if ( SUPERV_isNull( main->getDataflow() ) ) { // should not normally happen..
482 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
485 QString f = SUIT_FileDlg::getFileName(application()->desktop(),
488 tr("TTL_EXPORT_DATAFLOW"),
490 if ( !f.isEmpty() ) {
492 // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file,
493 // a backup copy of an existing file must be created (in case Export fails..)
494 QString aBackupFile = SUPERVGUI::createBackupFile( f );
496 if ( main->getDataflow()->Export(f.latin1()) ) {
497 unregisterGraph(main);
498 registerGraph(f, main);
500 // remove a backup file if export was successfull
501 if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() )
502 QFile::remove( aBackupFile );
505 QMessageBox::warning(application()->desktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile));
512 *If a file with theOriginalFileName exists, then the function tries to create
513 * its backup copy of it (the_name + ".bakX", X = 0,1,2,..,99). Returns backup file's name
514 * If a file with theOriginalFileName does not exist, or creation fails - Return empty string.
516 QString SUPERVGUI::createBackupFile( const QString& theOriginalFileName ) {
517 QString theBackupFileName("");
518 if ( QFile::exists( theOriginalFileName ) ) {
519 // 1. construct a backup file name
522 theBackupFileName = theOriginalFileName;
523 theBackupFileName += ".bak";
524 theBackupFileName += QString::number(i++);
526 while ( QFile::exists( theBackupFileName ) && i < 100 ); // max 99 backup files
527 // if *.bak99 exists -- it will be overwritten
529 // 2. copy the original file to theBackupFileName
530 QString cmd( "cp \"");
531 cmd += theOriginalFileName;
533 cmd += theBackupFileName;
535 bool res = system( cmd.latin1() );
537 theBackupFileName = QString("");
539 return theBackupFileName;
542 void SUPERVGUI::windows( QMap<int, int>& mappa ) const
544 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
545 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
546 mappa.insert( SalomeApp_Application::WT_LogWindow, Qt::DockBottom );
549 void SUPERVGUI::newDataflow() {
550 createDataflow( New );
553 void SUPERVGUI::importDataflow() {
554 createDataflow( Import );
557 void SUPERVGUI::modifyDataflow() {
558 createDataflow( Modify );
561 bool SUPERVGUI::createDataflow( const NEW_DF_MODE mode ) {
562 Trace("SUPERVGUI::createDataflow, mode = " << mode );
564 // asv : 27.01.05 : fix for PAL7823 : if the study is locked - warn the user and return.
565 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
566 if ( aStudy->GetProperties()->IsLocked() ) {
567 QMessageBox::warning(application()->desktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"));
571 SUPERV::Graph_var aGraph;
573 QString f; // file name. declared here because may be used below in error msg construction..
574 if ( mode == Import || mode == Modify ) { // 0. import or modify existing dataflow - select XML file
575 QString title = QString( "TLT_CREATE_DF_%1" ).arg( mode );
576 f = SUIT_FileDlg::getFileName( application()->desktop(), "", "*.xml", tr( title ), true );
577 if ( f.isEmpty() ) // pressed Cancel in file select dialog
580 // check if study already contains a graph imported from the same file
581 if ( isContains( study, f ) ) {
582 if ( QMessageBox::warning( application()->desktop(), tr("WARNING"), tr("MSG_GRAPH_DISPLAYED").arg(f),
583 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No )
588 aGraph = ( mode == Import ) ? engine->StreamGraphE( f ) : engine->StreamGraph( f );
591 aGraph = engine->StreamGraph( MAIN_NEW );
593 if ( CORBA::is_nil( aGraph ) ) {
594 QString msg( mode == New ? tr("MSG_CANT_CREATE_DF") : tr("MSG_BAD_FILE").arg(f) );
595 SUIT_MessageBox::warn1( application()->desktop(), tr("ERROR"), tr(msg), tr("BUT_OK") );
599 // 2. create a ViewFrame object
600 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( createGraph() );
603 // 3. bind Graph and ViewFrame == create SUPERVGUI_Main object
604 main = new SUPERVGUI_Main( aViewFrame, application()->desktop(), aGraph );
608 registerGraph( f, main );
615 void SUPERVGUI::reloadDataflow() {
616 Trace("SUPERVGUI::reloadDataflow");
620 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RELOAD"));
623 void SUPERVGUI::runDataflow() {
624 Trace("SUPERVGUI::runDataflow");
626 main->run( /*andSuspend=*/false );
628 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
631 void SUPERVGUI::stepByStep() {
632 Trace("SUPERVGUI::stepByStep");
634 main->run( /*andSuspend=*/true );
636 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
639 void SUPERVGUI::killDataflow() {
640 Trace("SUPERVGUI::killDataflow");
644 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_KILL"));
647 void SUPERVGUI::suspendResumeDataflow() {
648 Trace("SUPERVGUI::suspendResumeDataflow");
650 main->suspendResume();
652 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_SUSPEND"));
655 void SUPERVGUI::showComponents() {
656 Trace("SUPERVGUI::showComponents");
658 if ( main->isEditable() )
661 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOTEDITABLE"));
664 QMessageBox::warning(application()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_ADD"));
669 /*bool SUPERVGUI::CustomPopup(QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) {
670 Trace("SUPERVGUI::customPopup");
672 if(popup->count() > 3) {
673 // Temporary code: is to be deleted soon
674 popup->removeItem(QAD_Display_Popup_ID);
675 popup->removeItem(QAD_DisplayOnly_Popup_ID);
676 popup->removeItem(QAD_Erase_Popup_ID);
677 int id = popup->idAt(popup->count() - 1);
678 if (id < 0 && id != -1) popup->removeItem(id); // separator
679 // Temporary code end
684 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
685 if ( aList.Extent() == 0 ) return false;
687 if ( aList.Extent() == 1 ) {
688 Handle(SALOME_InteractiveObject) anIObj = aList.First();
690 // insert SUPERV-specific popup items here
692 bool isDataflow, ownObj;
693 whatIsSelected(anIObj, ownObj, isDataflow);
696 popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow()));
697 popup->insertItem("Display", this, SLOT(displayDataflow()));
698 popup->insertSeparator();
701 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
704 if ( aList.Extent() > 1 ) {
706 SALOME_ListIteratorOfListIO It_forCheckOwner( aList );
707 for(;It_forCheckOwner.More();It_forCheckOwner.Next()) {
708 Handle(SALOME_InteractiveObject) anIObj = It_forCheckOwner.Value();
709 bool aIsOwner, aIsDataflow;
710 whatIsSelected(anIObj, aIsOwner, aIsDataflow);
712 if (aIsOwner) aIObjCount++;
714 if ( aIObjCount == aList.Extent() ) //all selected objects belong to Supervision
715 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
724 theIsOwner = true if Selected object belongs to Suipervision.
725 theIsDataflow = true if Selected object is Dataflow
727 void SUPERVGUI::whatIsSelected(const Handle(SALOME_InteractiveObject)& theObj, bool& theIsOwner, bool& theIsDataflow) {
729 theIsDataflow = false;
731 if (theObj.IsNull()) return;
733 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
734 _PTR(SObject) obj ( aStudy->FindObjectID( theObj->getEntry() ) );
737 _PTR(SComponent) comp ( obj->GetFatherComponent() );
739 _PTR(GenericAttribute) anAttr;
740 if (comp->FindAttribute(anAttr, "AttributeName")) {
741 _PTR(AttributeName) aName ( anAttr );
742 QString compName(aName->Value().c_str());
743 if ( compName.compare( (( CAM_Application* )application())->moduleTitle( moduleName() ) ) == 0 ) {
744 _PTR(GenericAttribute) anAttr;
745 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
746 _PTR(AttributeIOR) anIOR ( anAttr );
747 SUPERV_Graph aDataFlow = engine->getGraph(anIOR->Value().c_str());
748 if (!SUPERV_isNull(aDataFlow)) {
749 if (aDataFlow->IsStreamGraph()) {
750 if (!SUPERV_isNull(aDataFlow->ToStreamGraph()))
751 theIsDataflow = true;
754 theIsDataflow = true;
757 CORBA::String_var anObjectID = obj->GetID().c_str();
758 CORBA::String_var aComponentID = comp->GetID().c_str();
759 if (strcmp(anObjectID, aComponentID)) theIsOwner = true;
766 void SUPERVGUI::deleteObject() {
769 (( SalomeApp_Application* )application())->selectionMgr()->selectedObjects( aList );
770 if ( aList.Extent() == 0 ) return;
772 // sak : 24.11.04 : fix for PAL6899 : if the study is locked - warn the user and return.
773 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
774 if ( aStudy->GetProperties()->IsLocked() ) {
775 QMessageBox::warning(application()->desktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"));
779 // sak : 24.11.04 : fix for PAL6901 : Incorrect deletion of the objects : pressing ESC button
780 // emitted "YES" button click, now it is corrected, and treated as "NO" button click.
781 if (QMessageBox::warning(application()->desktop(),
783 tr("MSG_ASK_DELETE"),
784 QMessageBox::No, QMessageBox::Yes) != QMessageBox::Yes)
787 SALOME_ListIteratorOfListIO It( aList );
788 for(;It.More();It.Next()) {
789 Handle(SALOME_InteractiveObject) anIObj = It.Value();
790 bool aIsOwner, aIsDataflow;
791 whatIsSelected(anIObj, aIsOwner, aIsDataflow);
793 _PTR(SObject) aObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
795 SUIT_Operation* op = new SalomeApp_ImportOperation( application() );
796 _PTR(StudyBuilder) aBuilder ( aStudy->NewBuilder() );
798 aBuilder->RemoveObjectWithChildren( aObj );
802 (( SalomeApp_Application* )application())->selectionMgr()->clearSelected();
805 void SUPERVGUI::OnGUIEvent()
807 const QObject* obj = sender();
808 if ( !obj || !obj->inherits( "QAction" ) )
810 int id = actionId((QAction*)obj);
815 bool SUPERVGUI::OnGUIEvent(int command) {
846 suspendResumeDataflow();
858 QMessageBox::warning(application()->desktop(), "Supervision Error", "Unknown Command From Salome");
863 /*bool SUPERVGUI::SetSettings() {
864 Trace("SUPERVGUI::SetSettings");
869 /*void SUPERVGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject) {
874 bool SUPERVGUI::ActiveStudyChanged() {
875 Trace("SUPERVGUI::activeStudyChanged");
876 study = application()->activeStudy();
880 /*void SUPERVGUI::SupportedViewType (int* buffer, int bufferSize)
882 if (!buffer || !bufferSize) return;
883 buffer[0] = (int)VIEW_GRAPHSUPERV;