Salome HOME
LCM // Import/Export of SHP p.1
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ExportFileOp.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_ExportFileOp.h"
20
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_LandCoverMap.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 <SUIT_MessageBox.h>
41 #include <TopoDS.hxx>
42 #include <TopExp_Explorer.hxx>
43 #include <TopoDS_Wire.hxx>
44 #include <TopoDS_Vertex.hxx>
45 #include <TopoDS_Edge.hxx>
46 #include <BRep_Tool.hxx>
47 #include <Precision.hxx>
48 #include <Handle_Geom_Curve.hxx>
49 #include <Handle_Geom_Line.hxx>
50 #include <Handle_Geom_TrimmedCurve.hxx>
51 #include <Geom_TrimmedCurve.hxx>
52 #include <HYDROData_ShapeFile.h>
53
54 HYDROGUI_ExportFileOp::HYDROGUI_ExportFileOp( HYDROGUI_Module* theModule )
55 : HYDROGUI_Operation( theModule )
56 {
57   setName( tr( "EXPORT_TO_SHAPE_FILE" ) );
58 }
59
60 HYDROGUI_ExportFileOp::~HYDROGUI_ExportFileOp()
61 {
62 }
63
64 void HYDROGUI_ExportFileOp::startOperation()
65 {
66   HYDROGUI_Operation::startOperation();
67   
68   QString aFilter( tr("SHP_FILTER") ); 
69   
70   Handle(HYDROData_PolylineXY) aPolyXY;
71   Handle(HYDROData_Polyline3D) aPoly3D;
72   NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq;
73   NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq;
74   // TODO
75   Handle_HYDROData_LandCoverMap aLCSeq;
76   
77   HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
78   for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
79   {
80     aPolyXY = Handle(HYDROData_PolylineXY)::DownCast( aSeq.Value( anIndex ));
81     if (!aPolyXY.IsNull())
82       aPolyXYSeq.Append(aPolyXY);
83
84     aPoly3D = Handle(HYDROData_Polyline3D)::DownCast( aSeq.Value( anIndex ));
85     if (!aPoly3D.IsNull())
86       aPoly3DSeq.Append(aPoly3D);
87   }
88
89   if (!aPolyXYSeq.IsEmpty() && !aPoly3DSeq.IsEmpty())
90     SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "EXPORT_TO_SHAPE_FILE" ), tr("ERROR_POLYLINES_OF_DIFF_KIND"));
91   else
92   {
93     QString aName = "";
94     if (aPolyXYSeq.Size() == 1 && aPoly3DSeq.IsEmpty())
95       aName = aPolyXYSeq(1)->GetName();
96     if (aPoly3DSeq.Size() == 1 && aPolyXYSeq.IsEmpty())
97       aName = aPoly3DSeq(1)->GetName();
98     QString aFileName = SUIT_FileDlg::getFileName( module()->getApp()->desktop(), aName, aFilter, tr( "EXPORT_TO_SHAPE_FILE" ), false );
99     if (!aFileName.isEmpty())
100     {
101       QStringList aNonExpList;
102       HYDROData_ShapeFile anExporter;
103       // TODO
104       anExporter.Export(aFileName,  aPolyXYSeq, aPoly3DSeq, aLCSeq, aNonExpList);
105       if (!aNonExpList.empty())
106       {
107         QString aMessage = tr("CANNOT_BE_EXPORTED") + "\n";
108         foreach (QString anNonExpEntName, aNonExpList)
109           aMessage += anNonExpEntName + "\n"; 
110         SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "EXPORT_TO_SHAPE_FILE" ), aMessage);
111       }
112       commit();
113     }
114     else
115       abort();
116   }
117
118 }
119