]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_ShapeFile.h
Salome HOME
Merge branch 'BR_H2018_2' of https://codev-tuleap.cea.fr/plugins/git/salome/hydro...
[modules/hydro.git] / src / HYDROData / HYDROData_ShapeFile.h
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 #ifndef HYDRODATA_SHAPEFILE_H
20 #define HYDRODATA_SHAPEFILE_H
21
22 #include "HYDROData.h"
23
24 #include <NCollection_Sequence.hxx>
25
26 #include <TopTools_SequenceOfShape.hxx>
27
28 #include <QStringList>
29
30 #include <vector>
31
32
33 //extern "C" {
34 #include <shapefil.h> 
35 //};
36
37 class gp_XYZ;
38 class HYDROData_PolylineXY;
39 class HYDROData_Polyline3D;
40 class HYDROData_Document;
41 class TopoDS_Face;
42 class TopoDS_Shape;
43 class HYDROData_Entity;
44 class HYDROData_LandCoverMap;
45
46 class HYDROData_ShapeFile 
47 {
48
49 public:
50
51 enum ShapeType
52 {
53   ShapeType_Polyline,
54   ShapeType_Polygon
55 };
56
57 enum DBF_FieldType
58 {
59   DBF_FieldType_None,
60   DBF_FieldType_String,
61   DBF_FieldType_Integer, 
62   DBF_FieldType_Double,
63   DBF_FieldType_Invalid
64 };
65
66 enum ImportShapeType
67 {
68   ImportShapeType_Polyline,
69   ImportShapeType_Polyline3D,
70   ImportShapeType_Polygon,
71   ImportShapeType_All
72 };
73
74 struct DBF_AttrValue
75 {
76   DBF_AttrValue() 
77   {
78     myIntVal = -1;
79     myDoubleVal = -1.0;
80     myIsNull = true;
81     myFieldType = DBF_FieldType_None;
82   }
83   QString myStrVal;
84   int myIntVal;
85   double myDoubleVal;
86   std::string myRawValue;
87   DBF_FieldType myFieldType;
88   bool myIsNull;
89 };
90
91 public:
92   HYDRODATA_EXPORT HYDROData_ShapeFile(  );
93   virtual HYDRODATA_EXPORT ~HYDROData_ShapeFile();
94
95   //Export operation
96   HYDRODATA_EXPORT void Export(Handle(HYDROData_Document) theDocument,
97                                const QString& aFileName,
98                                NCollection_Sequence<Handle(HYDROData_PolylineXY)> aPolyXYSeq,
99                                NCollection_Sequence<Handle(HYDROData_Polyline3D)> aPoly3DSeq,
100                                QStringList& aNonExpList);
101
102   HYDRODATA_EXPORT void Export(Handle(HYDROData_Document) theDocument,
103                                const QString& aFileName,
104                                const Handle(HYDROData_LandCoverMap)& aLCM,
105                                QStringList& aNonExpList,
106                                bool bCheckLinear = true,
107                                bool bUseDiscr = false, 
108                                double theDefl = 0.1);
109
110   int WriteObjectPolyXY(Handle(HYDROData_Document) theDocument, SHPHandle theShpHandle,
111                         Handle(HYDROData_PolylineXY) thePoly );
112
113   int WriteObjectPoly3D(Handle(HYDROData_Document) theDocument, SHPHandle theShpHandle,
114                         Handle(HYDROData_Polyline3D) thePoly );
115
116   int WriteObjectPolygon(Handle(HYDROData_Document) theDocument, SHPHandle theShpHandle,
117                          const TopoDS_Shape& theInputShape, bool bUseDiscr, double theDefl );
118   //Import
119   bool Parse(SHPHandle theHandle, ShapeType theType, int& theShapeTypeOfFile);
120   //Import Landcover
121   void ReadSHPPolygon(Handle(HYDROData_Document) theDocument, SHPObject* anObj, int i, TopoDS_Face& F);
122
123   HYDRODATA_EXPORT int ImportPolygons(Handle(HYDROData_Document) theDocument,
124                                       const QString theFileName,
125                                       QStringList& thePolygonsList, 
126                                       TopTools_SequenceOfShape& theFaces, 
127                                       int& theShapeTypeOfFile);
128
129   HYDRODATA_EXPORT void Free();
130
131   //Import Polyline
132   void ReadSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, 
133                      int theInd, NCollection_Sequence<Handle(HYDROData_Entity)>& theEntities,
134                      bool bReadAsPolylin = false);
135
136   void ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, 
137                      int theInd, NCollection_Sequence<Handle(HYDROData_Entity)>& theEntities);
138
139   HYDRODATA_EXPORT int ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, 
140                                        NCollection_Sequence<Handle(HYDROData_Entity)>& theEntities, int& theShapeTypeOfFile,
141                                        ImportShapeType theShapeTypesToImport);
142
143   HYDRODATA_EXPORT QString GetShapeTypeName(int theType);
144
145   //DBF I/O Methods
146   HYDRODATA_EXPORT bool CheckDBFFileExisting(const QString& theSHPFilePath, QString& thePathToDBFFile);
147   HYDRODATA_EXPORT bool DBF_OpenDBF(const QString& thePathToDBFFile);
148   HYDRODATA_EXPORT int DBF_GetNbFields();
149   HYDRODATA_EXPORT QStringList DBF_GetFieldList();
150   HYDRODATA_EXPORT void DBF_GetFieldTypeList(std::vector<DBF_FieldType>& FTVect);
151   HYDRODATA_EXPORT int DBF_GetNbRecords();
152   HYDRODATA_EXPORT void DBF_CloseDBF();
153   HYDRODATA_EXPORT void DBF_GetAttributeList(int theIndexOfField, std::vector<DBF_AttrValue>& theAttrV);
154   HYDRODATA_EXPORT bool DBF_WriteFieldAndValues(const QString& theFileName, const QString& theFieldName, DBF_FieldType theType, const std::vector<DBF_AttrValue>& theAttrV, bool bUseStrValue);
155
156 private:
157   
158   void ProcessFace(Handle(HYDROData_Document) theDocument,
159                    const TopoDS_Face& theFace, SHPHandle theShpHandle,
160                    bool bUseDiscr, double theDefl);
161
162   bool CheckLinear(const TopoDS_Shape& theInpShape);
163
164   int TryOpenShapeFile(QString theFileName);
165
166   void GetFreeIndices(std::vector<int>& theAllowedIndexes, QString strName, size_t theObjsSize,
167                       QStringList theExistingNames, QString theBaseFileName);
168
169 private:
170   std::vector<SHPObject*> mySHPObjects;
171   SHPHandle myHSHP;
172   DBFHandle     myHDBF;
173
174   friend class test_HYDROData_ShapeFile;
175 };
176
177 #endif