]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Implementation of the "Dump Study" functionality in GUI.
authormzn <mzn@opencascade.com>
Fri, 18 Mar 2005 12:12:59 +0000 (12:12 +0000)
committermzn <mzn@opencascade.com>
Fri, 18 Mar 2005 12:12:59 +0000 (12:12 +0000)
src/SALOMEGUI/Makefile.in
src/SALOMEGUI/QAD_Desktop.cxx
src/SALOMEGUI/QAD_Desktop.h
src/SALOMEGUI/QAD_msg_en.po
src/SALOMEGUI/SALOMEGUI_AdvancedFileDlg.cxx [new file with mode: 0644]
src/SALOMEGUI/SALOMEGUI_AdvancedFileDlg.h [new file with mode: 0644]

index d3acbc362e7ce15c251fab2e8f125528c97e74ca..e8ba535f7d5374c1af6b24c4729a66a1f77885f6 100644 (file)
@@ -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 \
index 5fa319a2803321ef960b8d416aa81a6b1e6d52ab..510e8478657c7678b00ffb4e4ab7d7ac61198397 100644 (file)
@@ -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 );
index 35c71416e8726c46d93ec3ed892c600cc6bb0473..6b32aa35e7c222447ef810ef9f4cc6c73428b98e 100644 (file)
@@ -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
index feca9f9e5cc569ceaf3deb8a3772691fc2a877b0..28a42b0a2f639cefa20a0f742c35aad7d24ab58f 100644 (file)
@@ -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 (file)
index 0000000..d9e7080
--- /dev/null
@@ -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 <qapplication.h>
+#include <qlabel.h>
+#include <qpushbutton.h>
+#include <qstring.h>
+#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 (file)
index 0000000..e19b817
--- /dev/null
@@ -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 <qcheckbox.h>
+
+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