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