Salome HOME
Merge branch 'BR_v14_rc' of ssh://git.salome-platform.org/modules/hydro into HEAD
[modules/hydro.git] / src / HYDROData / HYDROData_ShapeFile.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <HYDROData_ShapeFile.h>
24 #include <HYDROData_PolylineXY.h>
25 #include <HYDROData_Polyline3D.h>
26 #include <HYDROData_Bathymetry.h>
27 #include <HYDROData_LandCover.h>
28 #include <HYDROData_Profile.h>
29 #include <HYDROData_Iterator.h>
30
31 #include <QFile>
32 #include <QFileInfo>
33 #include <TopoDS.hxx>
34 #include <TopExp_Explorer.hxx>
35 #include <TopoDS_Wire.hxx>
36 #include <TopoDS_Vertex.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <BRep_Tool.hxx>
40 #include <Precision.hxx>
41 #include <Handle_Geom_Curve.hxx>
42 #include <Handle_Geom_Line.hxx>
43 #include <Handle_Geom_TrimmedCurve.hxx>
44 #include <Geom_TrimmedCurve.hxx>
45 #include <BRepBuilderAPI_MakeEdge.hxx>
46 #include <BRepBuilderAPI_MakeWire.hxx>
47 #include <BRepBuilderAPI_MakeFace.hxx>
48 #include <gp_Pln.hxx>
49 #include <BRepLib.hxx>
50 #include <ShapeFix_Shape.hxx>
51 #include <TopTools_SequenceOfShape.hxx>
52 #include <QColor>
53 #include <BRepTopAdaptor_FClass2d.hxx>
54
55 HYDROData_ShapeFile::HYDROData_ShapeFile() : myHSHP(NULL)
56
57 }
58
59 HYDROData_ShapeFile::~HYDROData_ShapeFile()
60 {
61   Free();
62 }
63
64 void HYDROData_ShapeFile::Export(const QString& aFileName, 
65   NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq,
66   NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq,
67   NCollection_Sequence<Handle_HYDROData_LandCover> aLCSeq,
68   QStringList& aNonExpList)
69 {
70   SHPHandle hSHPHandle;
71   if (!aPolyXYSeq.IsEmpty() && aPoly3DSeq.IsEmpty())
72   {
73     hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_ARC );        
74     for (int i = 1; i <= aPolyXYSeq.Size(); i++)
75       if (WriteObjectPolyXY(hSHPHandle, aPolyXYSeq(i)) != 1)
76         aNonExpList.append(aPolyXYSeq(i)->GetName());
77
78   }
79   else if (aPolyXYSeq.IsEmpty() && !aPoly3DSeq.IsEmpty())
80   {
81     hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_ARCZ );
82     for (int i = 1; i <= aPoly3DSeq.Size(); i++)
83       if (WriteObjectPoly3D(hSHPHandle, aPoly3DSeq(i)) != 1)
84         aNonExpList.append(aPoly3DSeq(i)->GetName());
85   }
86   else if (aPolyXYSeq.IsEmpty() && aPoly3DSeq.IsEmpty() && !aLCSeq.IsEmpty())
87   {
88     hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_POLYGON );
89     for (int i = 1; i <= aLCSeq.Size(); i++)
90       if (WriteObjectLC(hSHPHandle, aLCSeq(i)) != 1)
91         aNonExpList.append(aLCSeq(i)->GetName());
92   }
93   if (hSHPHandle->nRecords > 0)
94     SHPClose( hSHPHandle );
95   else
96   {
97     SHPClose( hSHPHandle );
98     remove (aFileName.toStdString().c_str());
99   }
100 }
101
102 int HYDROData_ShapeFile::WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly )
103 {
104   SHPObject     *aSHPObj;
105   std::vector<double> x, y;
106   std::vector<int> anPartStart;
107   
108   for (int i = 0; i < thePoly->NbSections(); i++)    
109     if (thePoly->GetSectionType(i) == HYDROData_IPolyline::SECTION_SPLINE)
110       return -1;
111
112   for (int i = 0; i < thePoly->NbSections(); i++)
113   {
114     anPartStart.push_back(x.size());
115     HYDROData_PolylineXY::PointsList aPointList = thePoly->GetPoints(i);
116     for (int j = 1; j <= aPointList.Size(); j++)
117     {
118       x.push_back( aPointList(j).X());
119       y.push_back( aPointList(j).Y()); 
120     }
121     if (thePoly->IsClosedSection(i))
122     {
123       x.push_back( aPointList(1).X());
124       y.push_back( aPointList(1).Y()); 
125     }
126   }
127     
128   aSHPObj = SHPCreateObject( SHPT_ARC, -1, thePoly->NbSections(), &anPartStart[0], NULL, x.size(), &x[0], &y[0], NULL, NULL );
129   SHPWriteObject( theShpHandle, -1, aSHPObj );
130   SHPDestroyObject( aSHPObj );
131   return 1;
132 }
133
134 int HYDROData_ShapeFile::WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly )
135 {
136   SHPObject     *aSHPObj;
137   std::vector<double> x, y, z;
138   std::vector<int> anPartStart;
139
140   for (int i = 0; i < thePoly->GetPolylineXY()->NbSections(); i++)    
141     if (thePoly->GetPolylineXY()->GetSectionType(i) == HYDROData_IPolyline::SECTION_SPLINE)
142       return -1;
143   
144   for (int i = 0; i < thePoly->GetPolylineXY()->NbSections(); i++)
145   {
146     anPartStart.push_back(x.size());
147     HYDROData_PolylineXY::PointsList aPointList = thePoly->GetPolylineXY()->GetPoints(i);
148     for (int j = 1; j <= aPointList.Size(); j++)
149     {
150       x.push_back( aPointList(j).X());
151       y.push_back( aPointList(j).Y()); 
152       z.push_back(thePoly->GetAltitudeObject()->GetAltitudeForPoint(gp_XY (aPointList(j).X(), aPointList(j).Y())));
153     }
154     if ( thePoly->GetPolylineXY()->IsClosedSection(i))
155     {
156       x.push_back( aPointList(1).X());
157       y.push_back( aPointList(1).Y()); 
158       z.push_back(thePoly->GetAltitudeObject()->GetAltitudeForPoint(gp_XY (aPointList(1).X(), aPointList(1).Y())));
159
160     }
161   }
162   
163   aSHPObj = SHPCreateObject( SHPT_ARCZ, -1, thePoly->GetPolylineXY()->NbSections(), &anPartStart[0], NULL, x.size(), &x[0], &y[0], &z[0], NULL );
164   SHPWriteObject( theShpHandle, -1, aSHPObj );
165   SHPDestroyObject( aSHPObj );
166   return 1;
167 }
168
169 int HYDROData_ShapeFile::WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC )
170 {
171   TopoDS_Shape aSh = theLC->GetShape();
172   if (aSh.IsNull())
173     return 0;
174   TopExp_Explorer anEdgeEx(aSh, TopAbs_EDGE);
175   for (; anEdgeEx.More(); anEdgeEx.Next()) 
176   {
177     TopoDS_Edge E = TopoDS::Edge(anEdgeEx.Current());
178     double aFP, aLP;
179     Handle_Geom_Curve aCur = BRep_Tool::Curve(E, aFP, aLP);
180     Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCur);
181     if (aLine.IsNull())
182     {
183       Handle(Geom_TrimmedCurve) aTC = Handle(Geom_TrimmedCurve)::DownCast(aCur);
184       if (!aTC.IsNull())
185       {
186         Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aTC->BasisCurve());
187         if (aLine.IsNull())
188           return -1;
189       }
190       else
191         return -1;
192     }
193
194   }
195   if (aSh.ShapeType() == TopAbs_FACE)
196   {
197     ProcessFace(TopoDS::Face(aSh), theShpHandle);
198   }
199   else if (aSh.ShapeType() == TopAbs_COMPOUND)
200   {
201     TopExp_Explorer Ex(aSh, TopAbs_FACE);
202     for (; Ex.More(); Ex.Next()) 
203     {
204       TopoDS_Face aF = TopoDS::Face(Ex.Current());   
205       if (aF.IsNull())
206         continue;
207       ProcessFace(aF, theShpHandle);
208     }
209   }
210   else
211     return 0;
212
213   return 1;
214  
215 }
216
217 void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle)
218 {
219   SHPObject     *aSHPObj;
220   std::vector<double> x, y;
221   std::vector<int> anPartStart;
222   if (theFace.ShapeType() == TopAbs_FACE)
223   {
224     TopExp_Explorer Ex(theFace, TopAbs_WIRE);
225     int NbWires = 0;
226     for (; Ex.More(); Ex.Next()) 
227     {
228       TopoDS_Wire aW = TopoDS::Wire(Ex.Current());   
229       if (aW.IsNull())
230         continue;
231       NbWires++;
232       anPartStart.push_back(x.size());
233       TopExp_Explorer aVEx(aW, TopAbs_VERTEX);
234       NCollection_Sequence<gp_Pnt2d> aPnts;
235       for (; aVEx.More(); aVEx.Next())
236       {
237         TopoDS_Vertex aV = TopoDS::Vertex(aVEx.Current()); 
238         if (aV.IsNull())
239           continue;
240         gp_Pnt P = BRep_Tool::Pnt(aV);
241         aPnts.Append(gp_Pnt2d(P.X(), P.Y()));
242       }
243       NCollection_Sequence<gp_Pnt2d> aNPnts;
244       aNPnts.Append(aPnts.First());
245       for (int j = 1; j <= aPnts.Size() - 1; j++)
246       {
247         if (!aPnts(j).IsEqual(aPnts(j + 1), Precision::Confusion())) 
248           aNPnts.Append(aPnts(j + 1));
249       }
250
251       for (int j = 1; j <= aNPnts.Size(); j++)
252       { 
253         x.push_back( aNPnts(j).X());
254         y.push_back( aNPnts(j).Y()); 
255       }
256       //x.push_back( aNPnts(1).X());
257       //y.push_back( aNPnts(1).Y()); 
258
259     }
260     
261     aSHPObj = SHPCreateObject( SHPT_POLYGON, -1, NbWires, &anPartStart[0], NULL, x.size(), &x[0], &y[0], NULL, NULL );
262     SHPWriteObject( theShpHandle, -1, aSHPObj );
263     SHPDestroyObject( aSHPObj );
264   }
265   else
266     return;
267 }
268
269 bool HYDROData_ShapeFile::Parse(SHPHandle theHandle, ShapeType theType)
270 {
271   int aShapeType;
272   mySHPObjects.clear();
273   SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL );
274   bool ToRead = (theType == ShapeType_Polyline && (aShapeType == 3 || aShapeType == 13 || aShapeType == 23)) ||
275    (theType == ShapeType_Polygon && aShapeType == 5);
276   if (ToRead) 
277   {
278     for (int i = 0; i < theHandle->nRecords; i++) 
279       mySHPObjects.push_back(SHPReadObject(theHandle, i));
280     return true;
281   }
282   else
283     return false;
284 }
285
286 void HYDROData_ShapeFile::ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F)
287 {
288   TopoDS_Wire W;
289   TopoDS_Edge E; 
290   int nParts = anObj->nParts;
291   gp_Pln pln(gp_Pnt(0,0,0), gp_Dir(0,0,1));
292
293   //Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
294   //sfs->FixFaceTool()->FixOrientationMode() = 1;
295   TopTools_SequenceOfShape aWires;
296   for ( int i = 0 ; i < nParts ; i++ )
297   { 
298     BRepBuilderAPI_MakeWire aBuilder;
299     int StartIndex = anObj->panPartStart[i];
300     int EndIndex;
301     if (i != nParts - 1)
302       EndIndex = anObj->panPartStart[i + 1];
303     else
304       EndIndex = anObj->nVertices;
305
306     for ( int k = StartIndex; k < EndIndex - 1  ; k++ )
307     {
308       gp_Pnt P1 (anObj->padfX[k], anObj->padfY[k], 0);
309       gp_Pnt P2 (anObj->padfX[k+1], anObj->padfY[k+1], 0);
310       if (P1.Distance(P2) < Precision::Confusion())
311         continue;
312       BRepBuilderAPI_MakeEdge aMakeEdge(P1, P2);
313       aBuilder.Add(TopoDS::Edge(aMakeEdge.Shape()));
314     }
315     
316     aBuilder.Build();
317     W = TopoDS::Wire(aBuilder.Shape());
318     W.Orientation(TopAbs_FORWARD);
319     BRepBuilderAPI_MakeFace aDB(pln, W);
320     TopoDS_Face aDummyFace = TopoDS::Face(aDB.Shape());
321     BRepTopAdaptor_FClass2d FClass(aDummyFace, Precision::PConfusion());
322     if ( i == 0 && FClass.PerformInfinitePoint() == TopAbs_OUT) 
323       W.Reverse();
324     if ( i > 0 && FClass.PerformInfinitePoint() != TopAbs_IN) 
325       W.Reverse();
326    
327     aWires.Append(W);
328   }
329   
330   BRepBuilderAPI_MakeFace aFBuilder(pln, TopoDS::Wire(aWires(1)));
331   for (int i = 2; i <= aWires.Length(); i++)
332     aFBuilder.Add(TopoDS::Wire(aWires(i)));
333   TopoDS_Face DF = TopoDS::Face(aFBuilder.Shape());
334
335   BRepLib::BuildCurves3d(DF);  
336   if(!DF.IsNull()) 
337   {
338     //sfs->Init ( DF );
339     //sfs->Perform();
340     F = DF; //TopoDS::Face(sfs->Shape());
341   }
342 }
343
344 bool HYDROData_ShapeFile::ImportLandCovers(const QString theFileName, QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces)
345 {
346   Free();
347   myHSHP = SHPOpen( theFileName.toAscii().data(), "rb" );
348   if (!Parse(myHSHP, HYDROData_ShapeFile::ShapeType_Polygon))
349     return false;
350   for (size_t i = 0; i < mySHPObjects.size(); i++)
351     thePolygonsList.append("polygon_" + QString::number(i + 1));
352    
353   TopoDS_Face aF;
354   if (myHSHP->nShapeType == 5)
355   {
356     for (size_t i = 0; i < mySHPObjects.size(); i++) 
357     {
358        ReadSHPPolygon(mySHPObjects[i], i, aF);
359        theFaces.Append(aF);
360     }
361     return true;
362   }
363   else
364     return false;
365 }
366
367 void HYDROData_ShapeFile::Free()
368 {  
369   for (size_t i = 0; i < mySHPObjects.size(); i++ )
370     free (mySHPObjects[i]);
371
372   mySHPObjects.clear();
373   if (myHSHP != NULL)
374   {
375     SHPClose(myHSHP);
376     myHSHP = NULL; 
377   }
378 }
379
380
381 void HYDROData_ShapeFile::ReadSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, 
382   int theInd, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
383 {
384
385   Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) );
386   
387   int nParts = anObj->nParts;
388   for ( int i = 0 ; i < nParts ; i++ )
389   {
390     int StartIndex = anObj->panPartStart[i];
391     int EndIndex;
392     if (i != nParts - 1)
393       EndIndex = anObj->panPartStart[i + 1];
394     else
395       EndIndex = anObj->nVertices;
396
397     bool IsClosed = false;
398     HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE; 
399     if (anObj->padfX[StartIndex] == anObj->padfX[EndIndex - 1] &&
400         anObj->padfY[StartIndex] == anObj->padfY[EndIndex - 1] )
401     {
402       IsClosed = true;
403       aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, true);
404     }
405     else
406       aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, false);
407     
408     if (IsClosed)
409       EndIndex--;
410     for ( int k = StartIndex; k < EndIndex ; k++ )
411     {
412       HYDROData_PolylineXY::Point aSectPoint;
413       aSectPoint.SetX( anObj->padfX[k] );
414       aSectPoint.SetY( anObj->padfY[k] );
415       aPolylineXY->AddPoint( i, aSectPoint );
416     }
417
418   }
419   
420   aPolylineXY->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
421   aPolylineXY->SetName( theFileName + "_PolyXY_" + QString::number(theInd) );
422   
423   aPolylineXY->Update();
424   theEntities.Append(aPolylineXY);
425
426 }
427
428 void HYDROData_ShapeFile::ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, 
429   int theInd, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
430 {
431   Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) );
432
433   Handle(HYDROData_Polyline3D) aPolylineObj = Handle(HYDROData_Polyline3D)::DownCast( theDocument->CreateObject( KIND_POLYLINE ) );
434
435   Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( theDocument->CreateObject( KIND_BATHYMETRY ) );
436   HYDROData_Bathymetry::AltitudePoints aAPoints;
437
438   int nParts = anObj->nParts;
439   for ( int i = 0 ; i < nParts ; i++ )
440   {
441     //bool aSectClosure = true;
442     int StartIndex = anObj->panPartStart[i];
443     int EndIndex;
444     if (i != nParts - 1)
445       EndIndex = anObj->panPartStart[i + 1];
446     else
447       EndIndex = anObj->nVertices;
448
449     bool IsClosed = false;
450     HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE; 
451     if (anObj->padfX[StartIndex] == anObj->padfX[EndIndex - 1] &&
452         anObj->padfY[StartIndex] == anObj->padfY[EndIndex - 1] &&
453         anObj->padfZ[StartIndex] == anObj->padfZ[EndIndex - 1])
454     {
455       IsClosed = true;
456       aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, true );
457     }
458     else
459       aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, false  );
460     
461     if (IsClosed)
462       EndIndex--;
463     for ( int k = StartIndex ; k < EndIndex ; k++ )
464     {
465       HYDROData_PolylineXY::Point aSectPoint;
466       aSectPoint.SetX( anObj->padfX[k] );
467       aSectPoint.SetY( anObj->padfY[k] );
468       aPolylineXY->AddPoint( i, aSectPoint );
469       aAPoints.Append(gp_XYZ (anObj->padfX[k], anObj->padfY[k], anObj->padfZ[k]));
470     }
471   }
472
473
474   QString aBathName = theFileName + "_bath_" + QString::number(theInd);
475   QString aPolyXYName = theFileName + "_polyXY_" + QString::number(theInd);
476   QString aPoly3DName = theFileName + "_poly3D_" + QString::number(theInd);
477
478   aPolylineXY->SetName( aPolyXYName );
479   aPolylineXY->SetWireColor(HYDROData_PolylineXY::DefaultWireColor());
480   aPolylineXY->Update();
481   
482   aBath->SetAltitudePoints(aAPoints);
483   aBath->SetName( aBathName );
484
485   aPolylineObj->SetPolylineXY (aPolylineXY, false);
486   aPolylineObj->SetAltitudeObject(aBath);
487
488   aPolylineObj->SetBorderColor( HYDROData_Polyline3D::DefaultBorderColor() );
489   aPolylineObj->SetName( aPoly3DName );
490   
491   aPolylineObj->Update();
492   theEntities.Append(aPolylineXY);
493   theEntities.Append(aPolylineObj);
494
495 }
496
497
498
499 bool HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
500 {
501   HYDROData_Iterator anIter( theDocument );
502   int anInd = 0;
503   QStringList anExistingNames;
504   std::vector<int> anAllowedIndexes;
505   for( ; anIter.More(); anIter.Next() )
506     anExistingNames.push_back(anIter.Current()->GetName());
507
508   SHPHandle aHSHP;
509   aHSHP = SHPOpen( theFileName.toAscii().data(), "rb" );
510   
511   QFileInfo aFileInfo(theFileName);
512   QString aBaseFileName = aFileInfo.baseName();
513
514   if (!Parse(aHSHP, HYDROData_ShapeFile::ShapeType_Polyline))
515     return false;
516   bool aStat = false;
517   if (aHSHP->nShapeType == 3 || aHSHP->nShapeType == 23)
518   {
519     anInd = 0;
520     for (;anAllowedIndexes.size() < mySHPObjects.size();)
521     {
522       if (!anExistingNames.contains(aBaseFileName + "_PolyXY_" + QString::number(anInd)))
523       {
524         anAllowedIndexes.push_back(anInd);
525         anInd++;
526       }
527       else
528         anInd++;
529     }
530     
531     for (size_t i = 0; i < mySHPObjects.size(); i++ )
532     {
533       ReadSHPPolyXY(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities);
534     }
535     aStat = true;
536   }
537   else if (aHSHP->nShapeType == 13)
538   {
539     anInd = 0;
540     for (;anAllowedIndexes.size() < mySHPObjects.size();)
541     {
542       if (!anExistingNames.contains(aBaseFileName + "_PolyXY_" + QString::number(anInd)) &&
543           !anExistingNames.contains(aBaseFileName + "_Poly3D_" + QString::number(anInd)) &&
544           !anExistingNames.contains(aBaseFileName + "_Bath_" + QString::number(anInd)))
545       {
546         anAllowedIndexes.push_back(anInd);
547         anInd++;
548       }
549       else
550         anInd++;
551     }
552     for (size_t i = 0; i < mySHPObjects.size(); i++ )
553       ReadSHPPoly3D(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities);
554     aStat = true;
555   }
556   else  
557   {
558     aStat = false;
559   }
560   
561   for (size_t i = 0; i < mySHPObjects.size(); i++ )
562     free (mySHPObjects[i]);
563
564   mySHPObjects.clear();
565   SHPClose(aHSHP);
566   return aStat;
567 }