]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_ImportSinusXOp.cxx
Salome HOME
write dbf with Hydro shapefiles, attribute string "PartName" with polyline name
[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 #include <HYDROGUI_ImportSinusXDlg.h>
44
45
46 HYDROGUI_ImportSinusXOp::HYDROGUI_ImportSinusXOp( HYDROGUI_Module* theModule )
47 : HYDROGUI_Operation( theModule )
48 {
49   setName( tr( "IMPORT_SINUSX" ) );
50 }
51
52 HYDROGUI_ImportSinusXOp::~HYDROGUI_ImportSinusXOp()
53 {
54 }
55
56 void HYDROGUI_ImportSinusXOp::startOperation()
57 {
58   HYDROGUI_Operation::startOperation();
59
60   myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
61   myFileDlg->setWindowTitle( getName() );
62   myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles );
63   myFileDlg->setNameFilter( tr("SINUSX_FILTER") );
64
65   connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
66   connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
67
68   myFileDlg->exec();
69 }
70
71 void HYDROGUI_ImportSinusXOp::onApply()
72 {
73   if ( !myFileDlg )
74   {
75     abort();
76     return;
77   }
78
79   QStringList aFileNames = myFileDlg->selectedFiles();
80   bool IsImported = false;
81
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       QApplication::setOverrideCursor( Qt::WaitCursor );  
96       bool ParseStat = aSinusXImporter.OpenAndParse(aFileName);
97       QApplication::restoreOverrideCursor();
98       if (ParseStat)
99       {
100         std::vector<HYDROGUI_CurveBlock> aCurveBlocks = aSinusXImporter.GetCurveBlocks();
101         QStringList names;
102         std::vector<int> types;
103         for (int i=0;i<aCurveBlocks.size();i++)
104         {
105           HYDROGUI_CurveBlock CurveBlock = aCurveBlocks[i];
106           types.push_back(CurveBlock.myType);
107           names << CurveBlock.myName;
108         }
109         HYDROGUI_ImportSinusXDlg* aDLG = new HYDROGUI_ImportSinusXDlg( module()->getApp()->desktop(), names, types );
110         aDLG->setModal( true );
111         aDLG->setWindowTitle(tr("ENTITIES_TO_IMPORT_FROM_SX"));
112         //QApplication::restoreOverrideCursor();
113         if( aDLG->exec()==QDialog::Accepted ) //??
114         {
115           QApplication::setOverrideCursor( Qt::WaitCursor );
116           std::vector<HYDROData_SinusX::ImportOptions> options = aDLG->GetImportOptions();
117           aSinusXImporter.Import(doc(), anEntities, &options);
118           UpdateView(anEntities);
119           QApplication::restoreOverrideCursor();
120           IsImported = true;
121         }
122       }
123     }
124   }
125
126   if (IsImported)
127   {
128     commitDocOperation();
129     commit();
130   }
131   else
132     abort();
133
134   module()->update( UF_Model | UF_VTKViewer | UF_OCCViewer );  
135   QApplication::restoreOverrideCursor();
136 }
137
138 void HYDROGUI_ImportSinusXOp::UpdateView( NCollection_Sequence<Handle(HYDROData_Entity)>& anEntities)
139 {
140   size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
141   if ( anActiveViewId == 0 )
142     anActiveViewId = HYDROGUI_Tool::GetActiveViewId( module() );
143
144   for (int i = 1; i <= anEntities.Size() ; i++)
145   {
146     anEntities(i)->Update();
147     module()->setObjectVisible( anActiveViewId, anEntities(i), true );
148     module()->setIsToUpdate( anEntities(i) );
149   }
150 }
151