Salome HOME
copyrights are updated
[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
27 //extern "C" {
28 #include <shapefil.h> 
29 //};
30
31 class gp_XYZ;
32 class Handle_HYDROData_PolylineXY;
33 class Handle_HYDROData_Polyline3D;
34 class Handle(HYDROData_Document);
35 class TopTools_SequenceOfShape;
36 class TopoDS_Face;
37 class Handle_HYDROData_Entity;
38 class Handle_HYDROData_LandCoverMap;
39
40 class HYDROData_ShapeFile 
41 {
42
43 public:
44
45 enum ShapeType
46 {
47   ShapeType_Polyline,
48   ShapeType_Polygon
49 };
50
51 enum DBF_FieldType
52 {
53   DBF_FieldType_None,
54   DBF_FieldType_String,
55   DBF_FieldType_Integer, 
56   DBF_FieldType_Double,
57   DBF_FieldType_Invalid
58 };
59
60
61 struct DBF_AttrValue
62 {
63   DBF_AttrValue() 
64   {
65     myIntVal = -1;
66     myDoubleVal = -1.0;
67     myIsNull = true;
68     myFieldType = DBF_FieldType_None;
69   }
70   QString myStrVal;
71   int myIntVal;
72   double myDoubleVal;
73   std::string myRawValue;
74   DBF_FieldType myFieldType;
75   bool myIsNull;
76 };
77
78 public:
79   HYDRODATA_EXPORT HYDROData_ShapeFile(  );
80   virtual HYDRODATA_EXPORT ~HYDROData_ShapeFile();
81
82   //Export operation
83   HYDRODATA_EXPORT void Export(const QString& aFileName, 
84                                NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq,
85                                NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq,
86                                const Handle_HYDROData_LandCoverMap& aLCSeq,
87                                QStringList& aNonExpList);
88   int WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly );
89   int WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly );
90   //TODO:int WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC );
91   //Import
92   bool Parse(SHPHandle theHandle, ShapeType theType, int& theShapeTypeOfFile);
93   //Import Landcover
94   void ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F);
95   HYDRODATA_EXPORT int ImportLandCovers(const QString theFileName, QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces, int& theShapeTypeOfFile);
96   HYDRODATA_EXPORT void Free();
97   //Import Polyline
98   void ReadSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, 
99                         int theInd, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);
100   void ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, 
101                         int theInd, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);
102   HYDRODATA_EXPORT int ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, 
103                        NCollection_Sequence<Handle_HYDROData_Entity>& theEntities, int& theShapeTypeOfFile);
104   HYDRODATA_EXPORT QString GetShapeTypeName(int theType);
105
106   //DBF I/O Methods
107   bool CheckDBFFileExisting(const QString& theSHPFilePath, QString& thePathToDBFFile);
108   bool DBF_OpenDBF(const QString& thePathToDBFFile);
109   int DBF_GetNbFields();
110   QStringList DBF_GetFieldList();
111   void DBF_GetFieldTypeList(std::vector<DBF_FieldType>& FTVect);
112   int DBF_GetNbRecords();
113   void DBF_CloseDBF();
114   void DBF_GetAttributeList(int theIndexOfField, std::vector<DBF_AttrValue>& theAttrV);
115   bool DBF_WriteFieldAndValues(const QString& theFileName, const QString& theFieldName, DBF_FieldType theType, const std::vector<DBF_AttrValue>& theAttrV, bool bUseStrValue);
116
117 private:
118   void ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle);
119   int TryOpenShapeFile(QString theFileName);
120 private:
121   std::vector<SHPObject*> mySHPObjects;
122   SHPHandle myHSHP;
123   DBFHandle     myHDBF;
124
125   friend class test_HYDROData_ShapeFile;
126 };
127
128 #endif