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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_ExportFileOp.h"
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>
31 #include <HYDROData_Profile.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_FileDlg.h>
35 #include <LightApp_Application.h>
37 #include <QApplication>
40 #include <SUIT_MessageBox.h>
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>
54 HYDROGUI_ExportFileOp::HYDROGUI_ExportFileOp( HYDROGUI_Module* theModule )
55 : HYDROGUI_Operation( theModule )
57 setName( tr( "EXPORT_TO_SHAPE_FILE" ) );
60 HYDROGUI_ExportFileOp::~HYDROGUI_ExportFileOp()
64 void HYDROGUI_ExportFileOp::startOperation()
66 HYDROGUI_Operation::startOperation();
68 QString aFilter( tr("SHP_FILTER") );
70 Handle(HYDROData_PolylineXY) aPolyXY;
71 Handle(HYDROData_Polyline3D) aPoly3D;
72 NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq;
73 NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq;
75 Handle_HYDROData_LandCoverMap aLCSeq;
77 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
78 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
80 aPolyXY = Handle(HYDROData_PolylineXY)::DownCast( aSeq.Value( anIndex ));
81 if (!aPolyXY.IsNull())
82 aPolyXYSeq.Append(aPolyXY);
84 aPoly3D = Handle(HYDROData_Polyline3D)::DownCast( aSeq.Value( anIndex ));
85 if (!aPoly3D.IsNull())
86 aPoly3DSeq.Append(aPoly3D);
89 if (!aPolyXYSeq.IsEmpty() && !aPoly3DSeq.IsEmpty())
90 SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "EXPORT_TO_SHAPE_FILE" ), tr("ERROR_POLYLINES_OF_DIFF_KIND"));
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())
101 QStringList aNonExpList;
102 HYDROData_ShapeFile anExporter;
104 anExporter.Export(aFileName, aPolyXYSeq, aPoly3DSeq, aLCSeq, aNonExpList);
105 if (!aNonExpList.empty())
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);