Salome HOME
Merge remote-tracking branch 'origin/BR_SINUSX_FORMAT' into BR_v14_rc
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportSinusXOp.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_ImportSinusXOp.h"
24
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_UpdateFlags.h"
28 #include "HYDROGUI_Tool.h"
29 #include <HYDROData_PolylineXY.h>
30 #include <HYDROData_Polyline3D.h>
31 #include <HYDROGUI_DataObject.h>
32 #include <HYDROData_Bathymetry.h>
33 #include <HYDROData_Iterator.h>
34
35 #include <HYDROData_Profile.h>
36
37 #include <SUIT_Desktop.h>
38 #include <SUIT_FileDlg.h>
39 #include <LightApp_Application.h>
40
41 #include <QApplication>
42 #include <QFile>
43 #include <QFileInfo>
44 #include <QMessageBox>
45
46 #include <HYDROData_SinusX.h>
47
48
49 HYDROGUI_ImportSinusXOp::HYDROGUI_ImportSinusXOp( HYDROGUI_Module* theModule )
50 : HYDROGUI_Operation( theModule )
51 {
52   setName( tr( "IMPORT_SINUSX" ) );
53 }
54
55 HYDROGUI_ImportSinusXOp::~HYDROGUI_ImportSinusXOp()
56 {
57 }
58
59 void HYDROGUI_ImportSinusXOp::startOperation()
60 {
61   HYDROGUI_Operation::startOperation();
62
63   myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
64   myFileDlg->setWindowTitle( getName() );
65   myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles );
66   myFileDlg->setFilter( tr("SINUSX_FILTER") );
67
68   connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
69   connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
70
71   myFileDlg->exec();
72 }
73
74 void HYDROGUI_ImportSinusXOp::onApply()
75 {
76   if ( !myFileDlg )
77   {
78     abort();
79     return;
80   }
81
82   QString aFileName = myFileDlg->selectedFile();
83   if ( aFileName.isEmpty() )
84   {
85     abort();
86     return;
87   }
88
89   QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
90
91   if (anExt == "sx")
92   {
93     QApplication::setOverrideCursor( Qt::WaitCursor );
94
95     startDocOperation();
96
97     HYDROData_SinusX aSinusXImporter;
98     NCollection_Sequence<Handle_HYDROData_Entity> anEntities;
99     if (aSinusXImporter.Import(aFileName, doc(), anEntities)) 
100     {
101       UpdateView(anEntities);
102       commitDocOperation();
103       commit();
104     }
105     else
106     {
107       abort();
108     }
109   }
110
111   module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
112   
113   QApplication::restoreOverrideCursor();
114 }
115
116 void HYDROGUI_ImportSinusXOp::UpdateView( NCollection_Sequence<Handle_HYDROData_Entity>& anEntities)
117 {
118   size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
119   if ( anActiveViewId == 0 )
120     anActiveViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() );
121
122   for (int i = 1; i <= anEntities.Size() ; i++)
123   {
124     anEntities(i)->Update();
125     module()->setObjectVisible( anActiveViewId, anEntities(i), true );
126     module()->setIsToUpdate( anEntities(i) );
127   }
128 }
129