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