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_ImportSinusXOp.h"
21 #include "HYDROGUI_DataModel.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_UpdateFlags.h"
24 #include "HYDROGUI_Tool.h"
25 #include <HYDROData_PolylineXY.h>
26 #include <HYDROData_Polyline3D.h>
27 #include <HYDROGUI_DataObject.h>
28 #include <HYDROData_Bathymetry.h>
29 #include <HYDROData_Iterator.h>
31 #include <HYDROData_Profile.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_FileDlg.h>
35 #include <LightApp_Application.h>
37 #include <QApplication>
40 #include <QMessageBox>
42 #include <HYDROData_SinusX.h>
45 HYDROGUI_ImportSinusXOp::HYDROGUI_ImportSinusXOp( HYDROGUI_Module* theModule )
46 : HYDROGUI_Operation( theModule )
48 setName( tr( "IMPORT_SINUSX" ) );
51 HYDROGUI_ImportSinusXOp::~HYDROGUI_ImportSinusXOp()
55 void HYDROGUI_ImportSinusXOp::startOperation()
57 HYDROGUI_Operation::startOperation();
59 myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
60 myFileDlg->setWindowTitle( getName() );
61 myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles );
62 myFileDlg->setFilter( tr("SINUSX_FILTER") );
64 connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
65 connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
70 void HYDROGUI_ImportSinusXOp::onApply()
78 QStringList aFileNames = myFileDlg->selectedFiles();
79 bool IsImported = false;
81 QApplication::setOverrideCursor( Qt::WaitCursor );
84 foreach (QString aFileName, aFileNames)
86 if ( aFileName.isEmpty() )
89 QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
93 HYDROData_SinusX aSinusXImporter;
94 NCollection_Sequence<Handle_HYDROData_Entity> anEntities;
95 if (aSinusXImporter.Import(aFileName, doc(), anEntities))
97 UpdateView(anEntities);
105 commitDocOperation();
111 module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
113 QApplication::restoreOverrideCursor();
116 void HYDROGUI_ImportSinusXOp::UpdateView( NCollection_Sequence<Handle_HYDROData_Entity>& anEntities)
118 size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
119 if ( anActiveViewId == 0 )
120 anActiveViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() );
122 for (int i = 1; i <= anEntities.Size() ; i++)
124 anEntities(i)->Update();
125 module()->setObjectVisible( anActiveViewId, anEntities(i), true );
126 module()->setIsToUpdate( anEntities(i) );