X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSUPERVGUI%2FSUPERVGUI.cxx;h=d8055e4608ea2621e6ae1c350b234e550dc85484;hb=ea7f29f75031ca13b9454f5e9ac73730f1f584eb;hp=e4c6bf35945c240f6361288c63da5275e45b132e;hpb=e4b2f8f88a294e451364a8b84d170a59dcbb5d3f;p=modules%2Fsuperv.git diff --git a/src/SUPERVGUI/SUPERVGUI.cxx b/src/SUPERVGUI/SUPERVGUI.cxx index e4c6bf3..d8055e4 100644 --- a/src/SUPERVGUI/SUPERVGUI.cxx +++ b/src/SUPERVGUI/SUPERVGUI.cxx @@ -37,13 +37,14 @@ 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) @@ -266,42 +267,6 @@ void SUPERVGUI::setMain(QWidget* w) { Trace("SUPERVGUI::setMain - main: "<StreamGraphE(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); - } - } -} - void SUPERVGUI::displayDataflow() { Trace("SUPERVGUI::displayDataflow"); QAD_ObjectBrowser* aBrowser = ((QAD_StudyFrame*)(desktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser(); @@ -343,7 +308,6 @@ void SUPERVGUI::displayDataflow() { (aStudyFrame->getRightFrame()->getViewFrame()); if(aViewFrame) { main = new SUPERVGUI_Main(aViewFrame, desktop, aDataFlow); - main->setAsFromStudy(true); registerGraph(aIORName, main); study->showFrame(aStudyFrame); } @@ -366,147 +330,203 @@ void SUPERVGUI::renameDataflow() { QString nm = QString( aName->Value() ); 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"); - - //asv 20.10.04: removed 2 SUPERVGUI_Main constructors. there is only ONE way - //to create a Main object now: with a non-null DataFlow as a 3d parameter - //1. create a Graph object - SUPERV_Graph aNewDataFlow = engine->StreamGraph( MAIN_NEW ); - if (SUPERV_isNull( aNewDataFlow )) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_DF")); - return; - } - //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 Main - main = new SUPERVGUI_Main(aViewFrame, desktop, aNewDataFlow ); - 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 = engine->StreamGraph(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")); + } @@ -605,16 +625,23 @@ 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; + // 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; SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); @@ -623,24 +650,8 @@ void SUPERVGUI::deleteObject() { bool aIsOwner, aIsDataflow; whatIsSelected(anIObj, aIsOwner, aIsDataflow); - 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; - } - } - } - } QAD_Operation* op = new SALOMEGUI_ImportOperation( study ); SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder(); op->start();