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() );
88 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
89 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
91 if ( aCalculation->Export( aGeomEngine, aDSStudy, anEntry ) ) {
92 theUpdateFlags = UF_ObjBrowser;
100 void HYDROGUI_ExportCalculationOp::onApply()
102 QApplication::setOverrideCursor( Qt::WaitCursor );
104 int anUpdateFlags = 0;
107 bool aResult = false;
108 QStringList aBrowseObjectsEntries;
111 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
113 catch ( Standard_Failure )
115 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
116 anErrorMsg = aFailure->GetMessageString();
124 QApplication::restoreOverrideCursor();
127 module()->update( anUpdateFlags );
129 browseObjects( aBrowseObjectsEntries );
132 SUIT_MessageBox::information( module()->getApp()->desktop(),
133 tr( "EXPORT_STATUS" ),
134 tr( "EXPORT_FINISHED") );
139 if ( anErrorMsg.isEmpty() )
140 anErrorMsg = tr( "EXPORT_DATA_FAILED" );
142 anErrorMsg.prepend( tr( "EXPORT_FAILED" ) + "\n" );
144 SUIT_MessageBox::critical( module()->getApp()->desktop(),
145 tr( "EXPORT_STATUS" ),