From 2d1dc181b8c2d4243a11af0f7f571c0441bd8e4a Mon Sep 17 00:00:00 2001 From: mzn Date: Fri, 18 Mar 2005 12:12:59 +0000 Subject: [PATCH] Implementation of the "Dump Study" functionality in GUI. --- src/SALOMEGUI/Makefile.in | 9 +- src/SALOMEGUI/QAD_Desktop.cxx | 65 ++++++++++- src/SALOMEGUI/QAD_Desktop.h | 4 +- src/SALOMEGUI/QAD_msg_en.po | 24 ++++ src/SALOMEGUI/SALOMEGUI_AdvancedFileDlg.cxx | 121 ++++++++++++++++++++ src/SALOMEGUI/SALOMEGUI_AdvancedFileDlg.h | 61 ++++++++++ 6 files changed, 279 insertions(+), 5 deletions(-) create mode 100644 src/SALOMEGUI/SALOMEGUI_AdvancedFileDlg.cxx create mode 100644 src/SALOMEGUI/SALOMEGUI_AdvancedFileDlg.h diff --git a/src/SALOMEGUI/Makefile.in b/src/SALOMEGUI/Makefile.in index d3acbc362..e8ba535f7 100644 --- a/src/SALOMEGUI/Makefile.in +++ b/src/SALOMEGUI/Makefile.in @@ -99,7 +99,8 @@ EXPORT_HEADERS = \ SALOMEGUI_NameDlg.h \ SALOMEGUI_SetValueDlg.h \ SALOMEGUI_SetupCurveDlg.h \ - SALOMEGUI_CloseDlg.h + SALOMEGUI_CloseDlg.h \ + SALOMEGUI_AdvancedFileDlg.h # .po files to transform in .qm PO_FILES = \ @@ -182,7 +183,8 @@ LIB_SRC = \ SALOMEGUI_SetValueDlg.cxx \ SALOMEGUI_SetupCurveDlg.cxx \ SALOMEGUI_CloseDlg.cxx \ - SALOMEGUI_ActivateComponentDlg.cxx + SALOMEGUI_ActivateComponentDlg.cxx \ + SALOMEGUI_AdvancedFileDlg.cxx LIB_MOC = \ SALOMEGUI.h \ SALOMEGUI_Application.h \ @@ -213,7 +215,8 @@ LIB_MOC = \ SALOMEGUI_NameDlg.h \ SALOMEGUI_SetupCurveDlg.h \ SALOMEGUI_CloseDlg.h \ - SALOMEGUI_ActivateComponentDlg.h + SALOMEGUI_ActivateComponentDlg.h \ + SALOMEGUI_AdvancedFileDlg.h LIB_CLIENT_IDL = SALOMEDS.idl \ SALOMEDS_Attributes.idl \ SALOME_ModuleCatalog.idl \ diff --git a/src/SALOMEGUI/QAD_Desktop.cxx b/src/SALOMEGUI/QAD_Desktop.cxx index 5fa319a28..510e84786 100644 --- a/src/SALOMEGUI/QAD_Desktop.cxx +++ b/src/SALOMEGUI/QAD_Desktop.cxx @@ -68,6 +68,7 @@ #include "SALOMEGUI_AboutDlg.h" #include "SALOMEGUI_ViewChoiceDlg.h" #include "SALOMEGUI_SetValueDlg.h" +#include "SALOMEGUI_AdvancedFileDlg.h" #include "utilities.h" #include "SALOMEGUI_CloseDlg.h" @@ -600,11 +601,21 @@ void QAD_Desktop::createActions() this, SLOT( onSaveAsStudy() ))); fileSaveAsAction->addTo( &myFilePopup ); myStdActions.insert ( FileSaveAsId, fileSaveAsAction ); - /* separator */ myFilePopup.insertSeparator(); + /* dump study */ + QActionP* fileDumpStudyAction = new QActionP( "", tr("MEN_DESK_FILE_DUMP_STUDY"), 0, this ); + fileDumpStudyAction->setStatusTip ( tr("PRP_DESK_FILE_DUMP_STUDY") ); + QAD_ASSERT ( connect( fileDumpStudyAction, SIGNAL( activated() ), + this, SLOT( onDumpStudy() ))); + fileDumpStudyAction->addTo( &myFilePopup ); + myStdActions.insert ( FileDumpStudyId, fileDumpStudyAction ); + + /* separator */ + myFilePopup.insertSeparator(); + // Study properties QActionP* filePropsAction = new QActionP( "", QPixmap(), tr("MEN_DESK_FILE_PROPERTIES"), 0, this ); filePropsAction->setStatusTip ( tr("PRP_DESK_FILE_PROPERTIES") ); @@ -1933,6 +1944,57 @@ bool QAD_Desktop::onSaveAsStudy( QAD_Study* study ) return true; /* saved ok */ } +/*! + Dumps the active study to the python scripts +*/ +bool QAD_Desktop::onDumpStudy() +{ + return onDumpStudy( myActiveStudy ); +} + +/*! + Dumps the given study to the python scripts +*/ +bool QAD_Desktop::onDumpStudy( QAD_Study* study ) +{ + if ( !study ) return true; + + /* Select a path where to save the scrips and the base name of the sripts + */ + QString aDir = QAD_Tools::getDirFromPath ( myActiveStudy->getPath(), false ); + QStringList flt; + flt.append( "Python Files (*.py)" ); + QFileInfo aFileInfo = SALOMEGUI_AdvancedFileDlg::getFileName(QAD_Application::getDesktop(), + aDir,flt,tr("INF_DESK_DUMP"), tr("Publish in study"), false); + + QString aPath = aFileInfo.dirPath(true); + QString aBaseName = aFileInfo.baseName(); + + if ( aPath.isNull() || aPath.isEmpty() || aBaseName.isNull() || aBaseName.isEmpty() || !aFileInfo.dir(true).exists()) + { + putInfo( tr("INF_CANCELLED") ); + return false; + } + + bool toPublished = SALOMEGUI_AdvancedFileDlg::IsChecked; + + /* Dumping study + */ + const QString aStudyTitle = study->getTitle(); + putInfo ( tr("INF_DOC_DUMPING") + aStudyTitle ); + if ( !study->getStudyDocument()->DumpStudy( aPath, aBaseName, toPublished ) ) { + /* can't save the file */ + QAD_MessageBox::error1( this, + tr("ERR_ERROR"), + tr("ERR_DOC_CANTDUMP") + "\n" + aStudyTitle, + tr("BUT_OK") ); + putInfo(""); + return false; /* cannot dump */ + } + putInfo ( tr("INF_DOC_DUMPED").arg( aStudyTitle ) + tr(" to %1_*.py").arg(aPath + "/" + aBaseName) ); + return true; /* dumped ok */ +} + /*! Closes the active study */ @@ -2440,6 +2502,7 @@ void QAD_Desktop::updateActions() myStdActions.at( FileCloseId )->setEnabled ( myActiveStudy != NULL ); myStdActions.at( FileSaveId )->setEnabled ( myActiveStudy != NULL ); myStdActions.at( FileSaveAsId )->setEnabled ( myActiveStudy != NULL ); + myStdActions.at( FileDumpStudyId )->setEnabled ( myActiveStudy != NULL ); myStdActions.at( FilePropsId )->setEnabled( myActiveStudy != NULL ); // myStdActions.at( HelpContentsId )->setEnabled ( myActiveApp != NULL ); // myStdActions.at( HelpSearchId )->setEnabled ( myActiveApp != NULL ); diff --git a/src/SALOMEGUI/QAD_Desktop.h b/src/SALOMEGUI/QAD_Desktop.h index 35c71416e..6b32aa35e 100644 --- a/src/SALOMEGUI/QAD_Desktop.h +++ b/src/SALOMEGUI/QAD_Desktop.h @@ -71,7 +71,7 @@ class QAD_EXPORT QAD_Desktop : public QMainWindow protected: //NRI - unused - : enum ComponentType {GEOM, MESH, SOLVER, DATA, VISU, OTHER} ; - enum { FileNewId = -1000, FileOpenId, FileLoadId, FileCloseId, FileSaveId, FileSaveAsId, FilePropsId, FileExitId, + enum { FileNewId = -1000, FileOpenId, FileLoadId, FileCloseId, FileSaveId, FileSaveAsId, FileDumpStudyId, FilePropsId, FileExitId, ViewStatusBarId, SelectionPointId, SelectionEdgeId, SelectionCellId, SelectionActorId, PrefViewerOCCId, PrefViewerVTKId, PrefGraphSupervisorId, PrefViewerPlot2dId, @@ -205,6 +205,8 @@ protected slots: virtual bool onSaveStudy(QAD_Study* doc); virtual bool onSaveAsStudy(); virtual bool onSaveAsStudy(QAD_Study* doc); + virtual bool onDumpStudy(); + virtual bool onDumpStudy(QAD_Study* doc); virtual bool onCloseStudy(); virtual bool onCloseStudy(QAD_Study* doc); //ask user to remove study from study manager permanently diff --git a/src/SALOMEGUI/QAD_msg_en.po b/src/SALOMEGUI/QAD_msg_en.po index feca9f9e5..28a42b0a2 100644 --- a/src/SALOMEGUI/QAD_msg_en.po +++ b/src/SALOMEGUI/QAD_msg_en.po @@ -83,6 +83,10 @@ msgstr "Open study" msgid "INF_DESK_DOC_SAVE" msgstr "Save study" +#: QAD_Desktop.cxx:654 +msgid "INF_DESK_DUMP" +msgstr "Dump study" + #: QAD_Desktop.cxx:465 msgid "QAD_Desktop::INF_DESK_EXIT" msgstr "Exit" @@ -103,6 +107,14 @@ msgstr "Study %1 saved" msgid "QAD_Desktop::INF_DOC_SAVING" msgstr "Saving study " +#: QAD_Desktop.cxx:1987 +msgid "QAD_Desktop::INF_DOC_DUMPED" +msgstr "Study %1 dumped" + +#: QAD_Desktop.cxx:1977 +msgid "QAD_Desktop::INF_DOC_DUMPING" +msgstr "Dumping study " + #: QAD_Desktop.cxx:993 msgid "QAD_Desktop::INF_PARSE_ERROR" msgstr "Parse error" @@ -163,6 +175,10 @@ msgstr "&Save" msgid "QAD_Desktop::MEN_DESK_FILE_SAVEAS" msgstr "Save As ..." +#: QAD_Desktop.cxx:608 +msgid "QAD_Desktop::MEN_DESK_FILE_DUMP_STUDY" +msgstr "Dump Study ..." + #: QAD_Desktop.cxx:141 msgid "QAD_Desktop::MEN_DESK_HELP" msgstr "&Help" @@ -374,6 +390,10 @@ msgstr "Saves the active study" msgid "QAD_Desktop::PRP_DESK_FILE_SAVEAS" msgstr "Saves the active study with a new name" +#: QAD_Desktop.cxx:609 +msgid "QAD_Desktop::PRP_DESK_FILE_DUMP_STUDY" +msgstr "Dumps the active study to the python scripts" + #: QAD_Desktop.cxx:3759 msgid "QAD_Desktop::PRP_DESK_FILE_IMPORT" msgstr "Import file" @@ -560,6 +580,10 @@ msgstr "Cannot open study" msgid "QAD_Desktop::ERR_DOC_CANTWRITE" msgstr "Cannot save study" +#: QAD_Desktop.cxx:683 +msgid "QAD_Desktop::ERR_DOC_CANTDUMP" +msgstr "Cannot dump study" + #: QAD_Desktop.cxx:599 msgid "QAD_Desktop::ERR_DOC_UNKNOWNTYPE" msgstr "Unknown study type" diff --git a/src/SALOMEGUI/SALOMEGUI_AdvancedFileDlg.cxx b/src/SALOMEGUI/SALOMEGUI_AdvancedFileDlg.cxx new file mode 100644 index 000000000..d9e708048 --- /dev/null +++ b/src/SALOMEGUI/SALOMEGUI_AdvancedFileDlg.cxx @@ -0,0 +1,121 @@ +// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// +// 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 : SALOMEGUI_AdvancedFileDlg.cxx +// Author : Michael Zorin +// Module : SALOME +// $Header: + +#include +#include +#include +#include +#include "QAD_Config.h" +#include "SALOMEGUI_AdvancedFileDlg.h" + +using namespace std; + +bool SALOMEGUI_AdvancedFileDlg::IsChecked = false; + +/*! +Constructor +*/ +SALOMEGUI_AdvancedFileDlg::SALOMEGUI_AdvancedFileDlg( QWidget* parent, bool open, const QString& cbTitle, bool showQuickDir, bool modal ) : + QAD_FileDlg( parent, open, showQuickDir, modal ) +{ + myCheckBox = new QCheckBox( cbTitle, this ); + QLabel* label = new QLabel("", this); + label->setMaximumWidth(0); + QPushButton* pb = new QPushButton(this); + pb->setMaximumWidth(0); + addWidgets( label, myCheckBox, pb ); + myCheckBox->setChecked(false); +} + +/*! + Destructor +*/ +SALOMEGUI_AdvancedFileDlg::~SALOMEGUI_AdvancedFileDlg() +{ +} + +/*! + Processes selection : tries to set given path or filename as selection +*/ +bool SALOMEGUI_AdvancedFileDlg::processPath( const QString& path ) +{ + if ( !path.isNull() ) { + QFileInfo fi( path ); + if ( fi.exists() ) { + if ( fi.isFile() ) + setSelection( path ); + else if ( fi.isDir() ) + setDir( path ); + return true; + } + else { + if ( QFileInfo( fi.dirPath() ).exists() ) { + setDir( fi.dirPath() ); + return true; + } + } + } + return false; +} + +/*! + Returns the file name +*/ +QString SALOMEGUI_AdvancedFileDlg::getFileName( QWidget* parent, + const QString& initial, + const QStringList& filters, + const QString& caption, + const QString& cbTitle, + bool open, + bool showQuickDir, + QAD_FileValidator* validator ) +{ + SALOMEGUI_AdvancedFileDlg* fd = new SALOMEGUI_AdvancedFileDlg( parent, open, cbTitle, showQuickDir, true ); + if ( !caption.isEmpty() ) + fd->setCaption( caption ); + if ( !initial.isEmpty() ) { + fd->processPath( initial ); // VSR 24/03/03 check for existing of directory has been added to avoid QFileDialog's bug + } + fd->setFilters( filters ); + if ( validator ) + fd->setValidator( validator ); + fd->exec(); + QString filename = fd->selectedFile(); + + SALOMEGUI_AdvancedFileDlg::IsChecked = fd->IsCBChecked(); + + delete fd; + qApp->processEvents(); + + return filename; +} + +bool SALOMEGUI_AdvancedFileDlg::IsCBChecked() +{ + return myCheckBox->isChecked(); +} diff --git a/src/SALOMEGUI/SALOMEGUI_AdvancedFileDlg.h b/src/SALOMEGUI/SALOMEGUI_AdvancedFileDlg.h new file mode 100644 index 000000000..e19b81711 --- /dev/null +++ b/src/SALOMEGUI/SALOMEGUI_AdvancedFileDlg.h @@ -0,0 +1,61 @@ +// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// +// 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 : SALOMEGUI_AdvancedFileDlg.h +// Author : Michael Zorin +// Module : SALOME +// $Header: + +#ifndef SALOMEGUI_AdvancedFileDlg_H +#define SALOMEGUI_AdvancedFileDlg_H + +#include "QAD_FileDlg.h" +#include + +class SALOMEGUI_AdvancedFileDlg : public QAD_FileDlg +{ + Q_OBJECT + +public: + SALOMEGUI_AdvancedFileDlg( QWidget* parent, bool open, const QString& cbTitle, bool showQuickDir = true, bool modal = true ); + ~SALOMEGUI_AdvancedFileDlg(); + +public: + static bool IsChecked; + static QString getFileName( QWidget* parent, + const QString& initial, + const QStringList& filters, + const QString& caption, + const QString& cbTitle, + bool open, + bool showQuickDir = true, + QAD_FileValidator* validator = 0); + +private: + QCheckBox* myCheckBox; + bool IsCBChecked(); + bool processPath( const QString& path ); + +}; + +#endif // SALOMEGUI_AdvancedFileDlg_H -- 2.39.2