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