X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSUPERVGUI%2FSUPERVGUI.cxx;h=d8055e4608ea2621e6ae1c350b234e550dc85484;hb=ea7f29f75031ca13b9454f5e9ac73730f1f584eb;hp=16526a35ffb178ca12eb17380af594b30f4d7507;hpb=7ce2b0744b6bfd86af6577995fc7192bd011743c;p=modules%2Fsuperv.git diff --git a/src/SUPERVGUI/SUPERVGUI.cxx b/src/SUPERVGUI/SUPERVGUI.cxx index 16526a3..d8055e4 100644 --- a/src/SUPERVGUI/SUPERVGUI.cxx +++ b/src/SUPERVGUI/SUPERVGUI.cxx @@ -1,11 +1,31 @@ -using namespace std; -// File : SUPERVGUI.cxx -// Created : 31 octobre 2001 -// Author : Francis KLOSS -// Project : SALOME -// Module : SUPERVGUI -// Copyright : CEA +// SUPERV SUPERVGUI : GUI for Supervisor component +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SUPERVGUI.cxx +// Author : Francis KLOSS +// Module : SUPERV +using namespace std; #include "SUPERVGUI.h" #include "QAD_Resource.h" @@ -17,27 +37,28 @@ using namespace std; #include "QAD_ViewFrame.h" #include "QAD_ObjectBrowser.h" #include "QAD_ObjectBrowserItem.h" +#include "QAD_MessageBox.h" + #include "SALOME_Selection.h" -#include "SALOMEGUI_NameDlg.h" -#include "Utils_ORB_INIT.hxx" #include "SALOME_ListIteratorOfListIO.hxx" #include "SALOME_InteractiveObject.hxx" -#include #include "SALOMEGUI_ImportOperation.h" +#include "SALOMEGUI_NameDlg.h" +#include "Utils_ORB_INIT.hxx" #include CORBA_SERVER_HEADER(SALOMEDS_Attributes) int SUPERVGUI::factory = 0; -SUPERVGUI Supervision; +SUPERVGUI Supervision(""); -SUPERVGUI::SUPERVGUI(): QObject(), - desktop(0), - study(0), - engine(0), - browser(0) - //info(0) +SUPERVGUI::SUPERVGUI(const QString& theName, QObject* theParent) + : SALOMEGUI( theName, theParent ), + desktop(0), + study(0), + browser(0) + //info(0) { Trace("SUPERVGUI::SUPERVGUI") if (factory==0) { @@ -52,8 +73,13 @@ SUPERVGUI::~SUPERVGUI() { Trace("SUPERVGUI::~SUPERVGUI") if (factory==1) { factory = 0; + //if (!engine->_is_nil()) CORBA::release(engine); //info->close(); - browser->close(); + if (browser) { + if (browser->isVisible()) + browser->close(); + delete browser; + } MESSAGE("SUPERVGUI Info : factory destroy"); } else { MESSAGE("SUPERVGUI Error : another call to factory destructor"); @@ -71,6 +97,10 @@ void SUPERVGUI::init(QAD_Desktop* parent) { //info = new SUPERVGUI_Information(); cursor = desktop->cursor(); connect(desktop->getMainFrame(), SIGNAL(windowActivated(QWidget*)), this, SLOT(setMain(QWidget*))); + + int anId = 300; + parent->menuBar()->changeItem(anId,parent->getComponentUserName("SUPERV")); + }; } @@ -79,10 +109,10 @@ QAD_StudyFrame* SUPERVGUI::createGraph() { QAD_StudyFrame* aStudyFrame = study->newWindow3d(study->getNextStudyFrameName(), VIEW_GRAPHSUPERV, false); if (aStudyFrame) { - connect(aStudyFrame, - SIGNAL(sfBeforeStudyFrameClosing(QAD_StudyFrame*)), + connect(study, + SIGNAL(supervStudyFrameClosing(QAD_ViewFrame*)), &Supervision, - SLOT(onGraphClosed(QAD_StudyFrame*))); + SLOT(onGraphClosed(QAD_ViewFrame*))); } return aStudyFrame; } @@ -105,8 +135,8 @@ void SUPERVGUI::loadEngine(SALOME_NamingService* namingService) { return; }; - engine = new SUPERV::SuperG_var; - *engine = aSuperVisionComponent; + // engine = new SUPERV::SuperG_var; + engine = aSuperVisionComponent; } /* bool SUPERVGUI::information(SUPERV_CNode node, bool isReadOnly) { @@ -170,14 +200,50 @@ bool SUPERVGUI::isContains(QAD_Study* theStudy, const QString theKey) { } -void SUPERVGUI::onGraphClosed(QAD_StudyFrame* theStudyFrame) { - QAD_ViewFrame* viewFrame = theStudyFrame->getRightFrame()->getViewFrame(); - if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast(viewFrame)){ - disconnect(theStudyFrame, 0 , this, 0); +void SUPERVGUI::onGraphClosed(QAD_ViewFrame* theViewFrame) { + if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast(theViewFrame)){ + disconnect(study, 0 , this, 0); SUPERVGraph_View* view = supervFrame->getViewWidget(); SUPERVGUI_Main* aGraph = dynamic_cast(view); if (aGraph) { unregisterGraph(aGraph); + SUPERV_Graph aDataFlow = aGraph->getDataflow(); + if ( !SUPERV_isNull( aDataFlow ) ) { + if ( aDataFlow->IsExecuting() ) { + const int aMsgResult = QMessageBox::warning(QAD_Application::getDesktop(), + tr("WARNING"), + tr("MSG_DF_RUNNING"), + tr("MSG_DF_EXECUTION"), + tr("MSG_DF_KILL")); + if ( aMsgResult == 1 ) { + // KILL EXECUTION + if ( aDataFlow->Kill() ) { + // Kill() sends KillEvent and KillState to SUPERVGUI_Thread + // while sets myIsActive flag to false when it receives such event/state + // after myIsActive is false it calls QThread::exit() to terminate. + + // why while() { qApp->processEvents() } ? + // because: SUPERVGUI_Thread::run() receives events, and calls myMain->execute() + // method using SALOME_Event paradigm, ProcessVoidEvent() function - + // it puts this event to the main application event loop, in which we are being now. + // So if we block main GUI application thread (by calling aGraph->getMyThread()->wait() here) + // then we will have a deadlock of 2 threads waiting for one another + while (aGraph->getMyThread()->running()) + qApp->processEvents(); + } + } + else { // BACKGROUND EXECUTION + emit KillMainThread(true); // set SUPERVGUI_Thread::myIsActive to false + while ( aGraph->getMyThread()->running() ) + qApp->processEvents(); + } + } + else { // EXECUTION IS FINISHED, JUST DESTROY THE SUPERVGUI_Thread object and return. + emit KillMainThread(true); + while ( aGraph->getMyThread()->running() ) + qApp->processEvents(); + } + } } } } @@ -193,46 +259,12 @@ void SUPERVGUI::setMain(QWidget* w) { QAD_ViewFrame* viewFrame = aStudyFrame->getRightFrame()->getViewFrame(); if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast(viewFrame)){ SUPERVGraph_View* view = supervFrame->getViewWidget(); - if (view) + if (view) { main = dynamic_cast(view); - } - Trace("SUPERVGUI::setMain - main: "<getMyThread(), SLOT(KillThread(bool))); } - - SUPERV_Graph aGraph = (*Supervision.getEngine())->GraphE(f); - //QFileInfo aFile(f); - //aGraph->SetName(aFile.baseName()); - if (SUPERV_isNull(aGraph)) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f)); - return; - } - - QAD_StudyFrame* aStudyFrame = createGraph(); - SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast - (aStudyFrame->getRightFrame()->getViewFrame()); - if(aViewFrame) { - main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph); - registerGraph(f, main); - study->showFrame(aStudyFrame); - } } + Trace("SUPERVGUI::setMain - main: "<getGraph(ior); + //aDataFlow = engine->getStreamGraph(ior); + aDataFlow = engine->getGraph(ior); if (SUPERV_isNull(aDataFlow)) { QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR")); return; } + /* ASV: 20.10.04: fix for 6896 + if (aDataFlow->IsStreamGraph()) { + SUPERV_StreamGraph aDataFlowStream = aDataFlow->ToStreamGraph(); + if (SUPERV_isNull(aDataFlowStream)) { + QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR")); + return; + } + aDataFlow = aDataFlowStream; + } + */ } QAD_StudyFrame* aStudyFrame = createGraph(); SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast (aStudyFrame->getRightFrame()->getViewFrame()); if(aViewFrame) { main = new SUPERVGUI_Main(aViewFrame, desktop, aDataFlow); - main->setAsFromStudy(true); registerGraph(aIORName, main); study->showFrame(aStudyFrame); } @@ -286,143 +328,211 @@ void SUPERVGUI::renameDataflow() { if (obj->FindAttribute(anAttr, "AttributeName")) { aName = SALOMEDS::AttributeName::_narrow(anAttr); QString nm = QString( aName->Value() ); - bool ok = FALSE; nm = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), nm ); if ( !nm.isEmpty() ) { - QApplication::setOverrideCursor( Qt::waitCursor ); + // sak : 24.11.04 : fix for PAL6898 : if rename fails (study locked), + // a message box is displayed, and cursor is "wait cursor". We think that "wait cursor" + // is not neccessary here, because the rename operation is fast. + //QApplication::setOverrideCursor( Qt::waitCursor ); study->renameIObject( IObject, nm ); - QApplication::restoreOverrideCursor(); + //QApplication::restoreOverrideCursor(); } } } } } - void SUPERVGUI::exportDataflow() { Trace("SUPERVGUI::exportDataflow") - if (main==0) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT")); - } else { + if ( main==0 ) { + QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT")); + } + else if ( SUPERV_isNull( main->getDataflow() ) ) { // should not normally happen.. + QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT")); + } + else { QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), "", "*.xml", tr("TTL_EXPORT_DATAFLOW"), false); - if (!f.isEmpty()) { - if (main->exportDataflow(f)) { + if ( !f.isEmpty() ) { + + // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file, + // a backup copy of an existing file must be created (in case Export fails..) + QString aBackupFile = SUPERVGUI::createBackupFile( f ); + + if ( main->getDataflow()->Export(f.latin1()) ) { unregisterGraph(main); registerGraph(f, main); + + // remove a backup file if export was successfull + if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() ) + QFile::remove( aBackupFile ); + } + else { + QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile)); } } } } +/** + *If a file with theOriginalFileName exists, then the function tries to create + * its backup copy of it (the_name + ".bakX", X = 0,1,2,..,99). Returns backup file's name + * If a file with theOriginalFileName does not exist, or creation fails - Return empty string. + */ +QString SUPERVGUI::createBackupFile( const QString& theOriginalFileName ) { + QString theBackupFileName(""); + if ( QFile::exists( theOriginalFileName ) ) { + // 1. construct a backup file name + int i = 0; + do { + theBackupFileName = theOriginalFileName; + theBackupFileName += ".bak"; + theBackupFileName += QString::number(i++); + } + while ( QFile::exists( theBackupFileName ) && i < 100 ); // max 99 backup files + // if *.bak99 exists -- it will be overwritten + + // 2. copy the original file to theBackupFileName + QString cmd( "cp \""); + cmd += theOriginalFileName; + cmd += "\" \""; + cmd += theBackupFileName; + cmd += "\""; + bool res = system( cmd.latin1() ); + if ( res ) + theBackupFileName = QString(""); + } + return theBackupFileName; +} + void SUPERVGUI::newDataflow() { - Trace("SUPERVGUI::editDataflow"); - QAD_StudyFrame* aStudyFrame = createGraph(); - SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast - (aStudyFrame->getRightFrame()->getViewFrame()); - if(aViewFrame){ - main = new SUPERVGUI_Main(aViewFrame, desktop, false); - main->addNode(); - study->showFrame(aStudyFrame); - } + createDataflow( New ); +} + +void SUPERVGUI::importDataflow() { + createDataflow( Import ); } void SUPERVGUI::modifyDataflow() { - Trace("SUPERVGUI::modifyDataflow") - QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), - "", - "*.xml", - tr("Modify Dataflow"), - true); - if (!f.isEmpty()){ - if (isContains(study, f)) { - if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), - tr("MSG_GRAPH_DISPLAYED").arg(f), - QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) - return; - } - - SUPERV_Graph aGraph = (*Supervision.getEngine())->Graph(f); - //QFile aFile(f); - //aGraph->SetName(aFile.name()); - if (SUPERV_isNull(aGraph)) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f)); - return; - } + createDataflow( Modify ); +} - QAD_StudyFrame* aStudyFrame = createGraph(); - SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast - (aStudyFrame->getRightFrame()->getViewFrame()); - if(aViewFrame) { - main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph); - registerGraph(f, main); - study->showFrame(aStudyFrame); - } +bool SUPERVGUI::createDataflow( const NEW_DF_MODE mode ) { + Trace("SUPERVGUI::createDataflow, mode = " << mode ); + + // asv : 27.01.05 : fix for PAL7823 : if the study is locked - warn the user and return. + SALOMEDS::Study_var aStudy = study->getStudyDocument(); + if ( aStudy->GetProperties()->IsLocked() ) { + QMessageBox::warning(QAD_Application::getDesktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED")); + return false; + } + + SUPERV::Graph_var aGraph; + + QString f; // file name. declared here because may be used below in error msg construction.. + if ( mode == Import || mode == Modify ) { // 0. import or modify existing dataflow - select XML file + QString title = QString( "TLT_CREATE_DF_%1" ).arg( mode ); + f = QAD_FileDlg::getFileName( QAD_Application::getDesktop(), "", "*.xml", tr( title ), true ); + if ( f.isEmpty() ) // pressed Cancel in file select dialog + return false; + + // check if study already contains a graph imported from the same file + if ( isContains( study, f ) ) { + if ( QMessageBox::warning( QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_GRAPH_DISPLAYED").arg(f), + QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) + return false; } + + // 1. create a graph + aGraph = ( mode == Import ) ? engine->StreamGraphE( f ) : engine->StreamGraph( f ); + } + else + aGraph = engine->StreamGraph( MAIN_NEW ); + + if ( CORBA::is_nil( aGraph ) ) { + QString msg( mode == New ? tr("MSG_CANT_CREATE_DF") : tr("MSG_BAD_FILE").arg(f) ); + QAD_MessageBox::warn1( QAD_Application::getDesktop(), tr("ERROR"), tr(msg), tr("BUT_OK") ); + return false; + } + + // 2. create a ViewFrame object + QAD_StudyFrame* aStudyFrame = createGraph(); + SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast + (aStudyFrame->getRightFrame()->getViewFrame()); + if ( aViewFrame ) { + + // 3. bind Graph and ViewFrame == create SUPERVGUI_Main object + main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph); + if ( mode == New ) + main->addNode(); + else + registerGraph( f, main ); + study->showFrame(aStudyFrame); + } + + return true; } void SUPERVGUI::reloadDataflow() { - Trace("SUPERVGUI::reloadDataflow") - if (main==0) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RELOAD")); - } else { - main->sync(); - }; + Trace("SUPERVGUI::reloadDataflow"); + if ( main ) + main->sync(); + else + QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RELOAD")); } void SUPERVGUI::runDataflow() { - Trace("SUPERVGUI::runDataflow") - if (main==0) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN")); - } else { - main->run(); - }; + Trace("SUPERVGUI::runDataflow"); + if ( main ) + main->run( /*andSuspend=*/false ); + else + QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN")); } void SUPERVGUI::stepByStep() { - Trace("SUPERVGUI::stepByStep") - if (main==0) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN")); - } else { - main->startExecute(); - } + Trace("SUPERVGUI::stepByStep"); + if ( main ) + main->run( /*andSuspend=*/true ); + else + QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN")); } void SUPERVGUI::killDataflow() { - Trace("SUPERVGUI::killDataflow") - if (main==0) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_KILL")); - } else { - main->kill(); - }; + Trace("SUPERVGUI::killDataflow"); + if ( main ) + main->kill(); + else + QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_KILL")); } void SUPERVGUI::suspendResumeDataflow() { - Trace("SUPERVGUI::suspendResumeDataflow") - if (main==0) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_SUSPEND")); - } else { - main->suspendResume(); - }; + Trace("SUPERVGUI::suspendResumeDataflow"); + if ( main ) + main->suspendResume(); + else + QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_SUSPEND")); } void SUPERVGUI::showComponents() { Trace("SUPERVGUI::showComponents"); - if (main==0) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_ADD")); - } else { - if (main->isEditable()) + if ( main ) { + if ( main->isEditable() ) main->addNode(); else QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOTEDITABLE")); } + else + QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_ADD")); + } -void SUPERVGUI::customPopup(QPopupMenu* popup) { + +bool SUPERVGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) { Trace("SUPERVGUI::customPopup"); + Supervision.init(parent); if(popup->count() > 3) { // Temporary code: is to be deleted soon popup->removeItem(QAD_Display_Popup_ID); @@ -433,22 +543,38 @@ void SUPERVGUI::customPopup(QPopupMenu* popup) { // Temporary code end } SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() ); - if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return; + if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return false; - Handle(SALOME_InteractiveObject) anIObj = Sel->firstIObject(); + if (Sel->IObjectCount() == 1) { + Handle(SALOME_InteractiveObject) anIObj = Sel->firstIObject(); - // insert SUPERV-specific popup items here + // insert SUPERV-specific popup items here - bool isDataflow, ownObj; - whatIsSelected(anIObj, ownObj, isDataflow); - - if (isDataflow) { - popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow())); - popup->insertItem("Display", this, SLOT(displayDataflow())); - popup->insertSeparator(); + bool isDataflow, ownObj; + whatIsSelected(anIObj, ownObj, isDataflow); + + if (isDataflow) { + popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow())); + popup->insertItem("Display", this, SLOT(displayDataflow())); + popup->insertSeparator(); + } + if (ownObj) + popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject())); } - if (ownObj) - popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject())); + if (Sel->IObjectCount() > 1) { + int aIObjCount = 0; + SALOME_ListIteratorOfListIO It_forCheckOwner(Sel->StoredIObjects()); + for(;It_forCheckOwner.More();It_forCheckOwner.Next()) { + Handle(SALOME_InteractiveObject) anIObj = It_forCheckOwner.Value(); + bool aIsOwner, aIsDataflow; + whatIsSelected(anIObj, aIsOwner, aIsDataflow); + + if (aIsOwner) aIObjCount++; + } + if (aIObjCount == Sel->IObjectCount()) //all selected objects belong to Supervision + popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject())); + } + return(true); } @@ -474,13 +600,21 @@ void SUPERVGUI::whatIsSelected(const Handle(SALOME_InteractiveObject)& theObj, b if (comp->FindAttribute(anAttr, "AttributeName")) { aName = SALOMEDS::AttributeName::_narrow(anAttr); QString compName(aName->Value()); - if (compName.compare(STUDY_SUPERVISION) == 0) { + //if (compName.compare(STUDY_SUPERVISION) == 0) { + if (compName.compare(QAD_Application::getDesktop()->getComponentUserName("SUPERV")) == 0) { SALOMEDS::GenericAttribute_var anAttr; if (obj->FindAttribute(anAttr, "AttributeIOR")) { SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - SUPERV_Graph aDataFlow = (*Supervision.getEngine())->getGraph(anIOR->Value()); - if (!SUPERV_isNull(aDataFlow)) - theIsDataflow = true; + //SUPERV_Graph aDataFlow = engine->getStreamGraph(anIOR->Value()); + SUPERV_Graph aDataFlow = engine->getGraph(anIOR->Value()); + if (!SUPERV_isNull(aDataFlow)) { + if (aDataFlow->IsStreamGraph()) { + if (!SUPERV_isNull(aDataFlow->ToStreamGraph())) + theIsDataflow = true; + } + else + theIsDataflow = true; + } } CORBA::String_var anObjectID = obj->GetID(); CORBA::String_var aComponentID = comp->GetID(); @@ -491,146 +625,118 @@ void SUPERVGUI::whatIsSelected(const Handle(SALOME_InteractiveObject)& theObj, b } } - void SUPERVGUI::deleteObject() { SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() ); if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return; - - Handle(SALOME_InteractiveObject) anIObj = Sel->firstIObject(); - bool aIsOwner, aIsDataflow; - whatIsSelected(anIObj, aIsOwner, aIsDataflow); - - if (!aIsOwner) return; + + // sak : 24.11.04 : fix for PAL6899 : if the study is locked - warn the user and return. + SALOMEDS::Study_var aStudy = study->getStudyDocument(); + if ( aStudy->GetProperties()->IsLocked() ) { + QMessageBox::warning(QAD_Application::getDesktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED")); + return; + } + // sak : 24.11.04 : fix for PAL6901 : Incorrect deletion of the objects : pressing ESC button + // emitted "YES" button click, now it is corrected, and treated as "NO" button click. if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_ASK_DELETE"), - QMessageBox::No, - QMessageBox::Yes) == QMessageBox::No) + QMessageBox::No, QMessageBox::Yes) != QMessageBox::Yes) return; - - SALOMEDS::Study_var aStudy = study->getStudyDocument(); - SALOMEDS::SObject_var aObj = aStudy->FindObjectID( anIObj->getEntry() ); - if (!aObj->_is_nil()) { - if (aIsDataflow) { - SALOMEDS::GenericAttribute_var anAttr; - if (aObj->FindAttribute(anAttr, "AttributeIOR")) { - SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - QString ior = anIOR->Value(); - - SUPERVGUI_Main* aMain; - for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) { - if ((aMain->getStudy() == study) && (aMain->getHashCode() == ior)) { - aMain->setAsFromStudy(false); - break; - } - } - } + + SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); + for(;It.More();It.Next()) { + Handle(SALOME_InteractiveObject) anIObj = It.Value(); + bool aIsOwner, aIsDataflow; + whatIsSelected(anIObj, aIsOwner, aIsDataflow); + + SALOMEDS::SObject_var aObj = aStudy->FindObjectID( anIObj->getEntry() ); + if (!aObj->_is_nil()) { + QAD_Operation* op = new SALOMEGUI_ImportOperation( study ); + SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder(); + op->start(); + aBuilder->RemoveObjectWithChildren(aObj); + op->finish(); } - QAD_Operation* op = new SALOMEGUI_ImportOperation( study ); - SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder(); - op->start(); - aBuilder->RemoveObjectWithChildren(aObj); - op->finish(); } Sel->ClearIObjects() ; } - - -void SUPERVGUI::activeStudyChanged() { - Trace("SUPERVGUI::activeStudyChanged"); - study = desktop->getActiveStudy(); -} - -extern "C" bool OnGUIEvent(int command, QAD_Desktop* parent) { - Supervision.init(parent); - switch (command) { - case 301: - Supervision.importDataflow(); - return(false); - - case 302: - Supervision.exportDataflow(); - return(false); - - case 303: - Supervision.newDataflow(); - return(false); - - case 304: - Supervision.modifyDataflow(); - return(false); - - case 305: - Supervision.reloadDataflow(); - return(false); - - case 306: - Supervision.runDataflow(); - return(false); - - case 307: - Supervision.killDataflow(); - return(false); - - case 308: - Supervision.suspendResumeDataflow(); - return(false); - - case 309: - Supervision.showComponents(); - return(false); - - case 310: - Supervision.stepByStep(); - return(false); - - default: - QMessageBox::warning(QAD_Application::getDesktop(), "Supervision Error", "Unknown Command From Salome"); - return(false); - - } -} - -extern "C" bool OnKeyPress(QKeyEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) { +bool SUPERVGUI::OnGUIEvent(int command, QAD_Desktop* parent) { + Supervision.init(parent); + switch (command) { + case 301: + Supervision.importDataflow(); return(false); -} - -extern "C" bool OnMousePress(QMouseEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) { + + case 302: + Supervision.exportDataflow(); return(false); -} - -extern "C" bool OnMouseMove(QMouseEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) { + + case 303: + Supervision.newDataflow(); return(false); -} - -extern "C" bool OnPopupGUIEvent(int theCommandID, QAD_Desktop* parent) { + + case 304: + Supervision.modifyDataflow(); return(false); + + case 305: + Supervision.reloadDataflow(); + return(false); + + case 306: + Supervision.runDataflow(); + return(false); + + case 307: + Supervision.killDataflow(); + return(false); + + case 308: + Supervision.suspendResumeDataflow(); + return(false); + + case 309: + Supervision.showComponents(); + return(false); + + case 310: + Supervision.stepByStep(); + return(false); + + default: + QMessageBox::warning(QAD_Application::getDesktop(), "Supervision Error", "Unknown Command From Salome"); + return(false); + } } -extern "C" bool SetSettings(QAD_Desktop* parent) { - Trace("extern SUPERVGUI::SetSettings") - Supervision.init(parent); - return(true); +bool SUPERVGUI::SetSettings(QAD_Desktop* parent) { + Trace("SUPERVGUI::SetSettings"); + Supervision.init(parent); + return(true); } -extern "C" void definePopup(QString& theContext, QString& theParent, QString& theObject) { - theObject = ""; - theContext = ""; +void SUPERVGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject) { + theObject = ""; + theContext = ""; } -extern "C" bool customPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) { - Supervision.init(parent); - Supervision.customPopup(popup); - return(true); +bool SUPERVGUI::ActiveStudyChanged(QAD_Desktop* parent) { + Trace("SUPERVGUI::activeStudyChanged"); + study = desktop->getActiveStudy(); + return true; } -extern "C" void activeStudyChanged(QAD_Desktop* parent) { - Supervision.activeStudyChanged(); +void SUPERVGUI::SupportedViewType (int* buffer, int bufferSize) +{ + if (!buffer || !bufferSize) return; + buffer[0] = (int)VIEW_GRAPHSUPERV; } -extern "C" int supportedViewType() +extern "C" { - return (int)VIEW_GRAPHSUPERV; + Standard_EXPORT SALOMEGUI* GetComponentGUI() { + return &Supervision; + } }