1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_ExportCalculationOp.h"
21 #include "HYDROGUI_DataModel.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_Tool.h"
25 #include <HYDROData_CalculationCase.h>
27 #include <GeometryGUI.h>
29 #include <SalomeApp_Study.h>
31 #include <LightApp_Application.h>
32 #include <LightApp_UpdateFlags.h>
34 #include <SUIT_MessageBox.h>
35 #include <SUIT_Desktop.h>
37 #include <QApplication>
39 HYDROGUI_ExportCalculationOp::HYDROGUI_ExportCalculationOp( HYDROGUI_Module* theModule )
40 : HYDROGUI_Operation( theModule )
42 setName( tr( "EXPORT_CALCULATION" ) );
45 HYDROGUI_ExportCalculationOp::~HYDROGUI_ExportCalculationOp()
49 void HYDROGUI_ExportCalculationOp::startOperation()
51 HYDROGUI_Operation::startOperation();
56 void HYDROGUI_ExportCalculationOp::abortOperation()
58 HYDROGUI_Operation::abortOperation();
61 void HYDROGUI_ExportCalculationOp::commitOperation()
63 HYDROGUI_Operation::commitOperation();
66 bool HYDROGUI_ExportCalculationOp::processApply( int& theUpdateFlags,
68 QStringList& theBrowseObjectsEntries )
70 // Get the selected calculation case
71 Handle(HYDROData_CalculationCase) aCalculation =
72 Handle(HYDROData_CalculationCase)::DownCast(
73 HYDROGUI_Tool::GetSelectedObject( module() ) );
75 if ( aCalculation.IsNull() ) {
76 theErrorMsg = tr( "NULL_DATA_OBJECT" );
83 SalomeApp_Study* aStudy =
84 dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
89 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
90 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
92 if ( aCalculation->Export( aGeomEngine, aDSStudy, anEntry, theErrorMsg ) ) {
93 theUpdateFlags = UF_ObjBrowser;
101 void HYDROGUI_ExportCalculationOp::onApply()
103 QApplication::setOverrideCursor( Qt::WaitCursor );
105 int anUpdateFlags = 0;
108 bool aResult = false;
109 QStringList aBrowseObjectsEntries;
112 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
114 catch ( Standard_Failure )
116 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
117 anErrorMsg = aFailure->GetMessageString();
125 QApplication::restoreOverrideCursor();
128 module()->update( anUpdateFlags );
130 browseObjects( aBrowseObjectsEntries );
133 SUIT_MessageBox::information( module()->getApp()->desktop(),
134 tr( "EXPORT_STATUS" ),
135 tr( "EXPORT_FINISHED") );
140 if ( anErrorMsg.isEmpty() )
141 anErrorMsg = tr( "EXPORT_DATA_FAILED" );
143 anErrorMsg.prepend( tr( "EXPORT_FAILED" ) + "\n" );
145 SUIT_MessageBox::critical( module()->getApp()->desktop(),
146 tr( "EXPORT_STATUS" ),