Salome HOME
refs #603
[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   QStringList aFileNames = myFileDlg->selectedFiles();
83   bool IsImported = false;
84   
85   QApplication::setOverrideCursor( Qt::WaitCursor );  
86   startDocOperation();
87
88   foreach (QString aFileName, aFileNames) 
89   {
90     if ( aFileName.isEmpty() )
91       continue;
92
93     QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
94
95     if (anExt == "sx")
96     {
97       HYDROData_SinusX aSinusXImporter;
98       NCollection_Sequence<Handle_HYDROData_Entity> anEntities;
99       if (aSinusXImporter.Import(aFileName, doc(), anEntities)) 
100       {
101         UpdateView(anEntities);
102         IsImported = true;
103       }
104     }
105   }
106
107   if (IsImported)
108   {
109     commitDocOperation();
110     commit();
111   }
112   else
113     abort();
114
115   module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
116   
117   QApplication::restoreOverrideCursor();
118 }
119
120 void HYDROGUI_ImportSinusXOp::UpdateView( NCollection_Sequence<Handle_HYDROData_Entity>& anEntities)
121 {
122   size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
123   if ( anActiveViewId == 0 )
124     anActiveViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() );
125
126   for (int i = 1; i <= anEntities.Size() ; i++)
127   {
128     anEntities(i)->Update();
129     module()->setObjectVisible( anActiveViewId, anEntities(i), true );
130     module()->setIsToUpdate( anEntities(i) );
131   }
132 }
133