From 18d2b12ab3662f1831e39124079a0fe90190bcdb Mon Sep 17 00:00:00 2001 From: Renaud Barate Date: Fri, 1 Mar 2013 17:32:52 +0100 Subject: [PATCH] CSV export is now done directly by the engine --- idl/PARAMETRIC_Gen.idl | 5 +++++ src/PARAMETRIC/PARAMETRIC.py | 18 ++++++++++++++++++ src/PARAMETRICGUI/PARAMETRICGUI.py | 24 +++++++++++++++++------- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/idl/PARAMETRIC_Gen.idl b/idl/PARAMETRIC_Gen.idl index 0888f83..26073a4 100644 --- a/idl/PARAMETRIC_Gen.idl +++ b/idl/PARAMETRIC_Gen.idl @@ -42,6 +42,11 @@ interface PARAMETRIC_Gen : Engines::EngineComponent, SALOMEDS::Driver void RunStudy(in long salomeStudyID, in SALOMEDS::ID entry) raises (SALOME::SALOME_Exception); + + void ExportToCSV(in long salomeStudyID, + in SALOMEDS::ID entry, + in string filePath) + raises (SALOME::SALOME_Exception); }; }; diff --git a/src/PARAMETRIC/PARAMETRIC.py b/src/PARAMETRIC/PARAMETRIC.py index a0ed4be..36ff11a 100644 --- a/src/PARAMETRIC/PARAMETRIC.py +++ b/src/PARAMETRIC/PARAMETRIC.py @@ -307,6 +307,24 @@ class PARAMETRIC(PARAMETRIC_ORB__POA.PARAMETRIC_Gen, SALOME_ComponentPy_i, SALOM except: self._raiseSalomeError() + def ExportToCSV(self, salomeStudyID, entry, filePath): + try: + self.beginService("PARAMETRIC.ExportToCSV") + + PARAMETRIC.lock.acquire() + salome.salome_init() + PARAMETRIC.lock.release() + + # Get parametric study from the case in Salome study + param_study = self._get_parametric_study(salomeStudyID, entry) + + # Export parametric study to CSV file + param_study.export_data_to_csv_file(filePath) + + self.endService("PARAMETRIC.ExportToCSV") + except: + self._raiseSalomeError() + def Save(self, theComponent, theURL, isMultiFile): try: # Select parametric studies to save diff --git a/src/PARAMETRICGUI/PARAMETRICGUI.py b/src/PARAMETRICGUI/PARAMETRICGUI.py index 934d9c0..5106f38 100644 --- a/src/PARAMETRICGUI/PARAMETRICGUI.py +++ b/src/PARAMETRICGUI/PARAMETRICGUI.py @@ -224,13 +224,23 @@ def export_to_csv(): filter = qapp.translate("export_to_csv", "CSV files (*.csv)")) if filename is not None and len(filename) > 0: try: - qapp.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) - study_id = sgPyQt.getStudyId() - entry = salome.sg.getSelected(0) - ed = ParametricStudyEditor(study_id) - param_study = ed.get_parametric_study(entry) - param_study.export_data_to_csv_file(filename) - qapp.restoreOverrideCursor() + filename = str(filename) + if not filename.endswith(".csv"): + filename += ".csv" + qapp.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) + study_id = sgPyQt.getStudyId() + entry = salome.sg.getSelected(0) + ed = ParametricStudyEditor(study_id) + engine = ed.find_or_create_engine() + engine.ExportToCSV(ed.study_id, entry, filename) + qapp.restoreOverrideCursor() + except SALOME.SALOME_Exception, exc: + qapp.restoreOverrideCursor() + logger.exception("An error happened while trying to export to CSV file.") + QtGui.QMessageBox.critical(sgPyQt.getDesktop(), + qapp.translate("export_to_csv", "Error"), + qapp.translate("export_to_csv", "An error happened while trying to " + "export parametric study to CSV file: %s" % exc.details.text)) except Exception, exc: qapp.restoreOverrideCursor() logger.exception("Export to CSV file failed") -- 2.39.2