Salome HOME
Porting on OCCT 7.0 and Qt 5. Make compilable version.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportSinusXOp.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_ImportSinusXOp.h"
20
21 #include "HYDROGUI_DataModel.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_UpdateFlags.h"
24 #include "HYDROGUI_Tool2.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>
30
31 #include <HYDROData_Profile.h>
32
33 #include <SUIT_Desktop.h>
34 #include <SUIT_FileDlg.h>
35 #include <LightApp_Application.h>
36
37 #include <QApplication>
38 #include <QFile>
39 #include <QFileInfo>
40 #include <QMessageBox>
41
42 #include <HYDROData_SinusX.h>
43
44
45 HYDROGUI_ImportSinusXOp::HYDROGUI_ImportSinusXOp( HYDROGUI_Module* theModule )
46 : HYDROGUI_Operation( theModule )
47 {
48   setName( tr( "IMPORT_SINUSX" ) );
49 }
50
51 HYDROGUI_ImportSinusXOp::~HYDROGUI_ImportSinusXOp()
52 {
53 }
54
55 void HYDROGUI_ImportSinusXOp::startOperation()
56 {
57   HYDROGUI_Operation::startOperation();
58
59   myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
60   myFileDlg->setWindowTitle( getName() );
61   myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles );
62   myFileDlg->setNameFilter( tr("SINUSX_FILTER") );
63
64   connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
65   connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
66
67   myFileDlg->exec();
68 }
69
70 void HYDROGUI_ImportSinusXOp::onApply()
71 {
72   if ( !myFileDlg )
73   {
74     abort();
75     return;
76   }
77
78   QStringList aFileNames = myFileDlg->selectedFiles();
79   bool IsImported = false;
80   
81   QApplication::setOverrideCursor( Qt::WaitCursor );  
82   startDocOperation();
83
84   foreach (QString aFileName, aFileNames) 
85   {
86     if ( aFileName.isEmpty() )
87       continue;
88
89     QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
90
91     if (anExt == "sx")
92     {
93       HYDROData_SinusX aSinusXImporter;
94       NCollection_Sequence<Handle(HYDROData_Entity)> anEntities;
95       if (aSinusXImporter.Import(aFileName, doc(), anEntities)) 
96       {
97         UpdateView(anEntities);
98         IsImported = true;
99       }
100     }
101   }
102
103   if (IsImported)
104   {
105     commitDocOperation();
106     commit();
107   }
108   else
109     abort();
110
111   module()->update( UF_Model | UF_VTKViewer | UF_OCCViewer );  
112   QApplication::restoreOverrideCursor();
113 }
114
115 void HYDROGUI_ImportSinusXOp::UpdateView( NCollection_Sequence<Handle(HYDROData_Entity)>& anEntities)
116 {
117   size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
118   if ( anActiveViewId == 0 )
119     anActiveViewId = HYDROGUI_Tool::GetActiveViewId( module() );
120
121   for (int i = 1; i <= anEntities.Size() ; i++)
122   {
123     anEntities(i)->Update();
124     module()->setObjectVisible( anActiveViewId, anEntities(i), true );
125     module()->setIsToUpdate( anEntities(i) );
126   }
127 }
128