X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_ShapeFile.cxx;h=15ef87394f1eb4423c036b465894a75ed2f2af45;hb=e744ba34fd38d6744d11b54cd15b6f86350695b2;hp=70e657ba7e77c642431242945e9a7db096fbd300;hpb=26ee8dae14d0d419190ec577932eeaebff0fa12a;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_ShapeFile.cxx b/src/HYDROData/HYDROData_ShapeFile.cxx index 70e657ba..15ef8739 100644 --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@ -50,7 +50,7 @@ #include #include #include - +#include HYDROData_ShapeFile::HYDROData_ShapeFile() : myHSHP(NULL) { @@ -95,7 +95,9 @@ void HYDROData_ShapeFile::Export(const QString& aFileName, else { SHPClose( hSHPHandle ); - remove (aFileName.toStdString().c_str()); + QString aFN = aFileName.simplified(); + remove (aFN.toStdString().c_str()); + remove (aFN.replace( ".shp", ".shx", Qt::CaseInsensitive).toStdString().c_str()); } } @@ -266,11 +268,12 @@ void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandl return; } -bool HYDROData_ShapeFile::Parse(SHPHandle theHandle, ShapeType theType) +bool HYDROData_ShapeFile::Parse(SHPHandle theHandle, ShapeType theType, int& theShapeTypeOfFile) { int aShapeType; mySHPObjects.clear(); SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL ); + theShapeTypeOfFile = aShapeType; bool ToRead = (theType == ShapeType_Polyline && (aShapeType == 3 || aShapeType == 13 || aShapeType == 23)) || (theType == ShapeType_Polygon && aShapeType == 5); if (ToRead) @@ -289,11 +292,10 @@ void HYDROData_ShapeFile::ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F TopoDS_Edge E; int nParts = anObj->nParts; gp_Pln pln(gp_Pnt(0,0,0), gp_Dir(0,0,1)); - BRepBuilderAPI_MakeFace aFBuilder(pln); //Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape; //sfs->FixFaceTool()->FixOrientationMode() = 1; - + TopTools_SequenceOfShape aWires; for ( int i = 0 ; i < nParts ; i++ ) { BRepBuilderAPI_MakeWire aBuilder; @@ -316,14 +318,24 @@ void HYDROData_ShapeFile::ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F aBuilder.Build(); W = TopoDS::Wire(aBuilder.Shape()); - W.Reverse(); - aFBuilder.Add(W); + W.Orientation(TopAbs_FORWARD); + BRepBuilderAPI_MakeFace aDB(pln, W); + TopoDS_Face aDummyFace = TopoDS::Face(aDB.Shape()); + BRepTopAdaptor_FClass2d FClass(aDummyFace, Precision::PConfusion()); + if ( i == 0 && FClass.PerformInfinitePoint() == TopAbs_OUT) + W.Reverse(); + if ( i > 0 && FClass.PerformInfinitePoint() != TopAbs_IN) + W.Reverse(); + + aWires.Append(W); } + + BRepBuilderAPI_MakeFace aFBuilder(pln, TopoDS::Wire(aWires(1))); + for (int i = 2; i <= aWires.Length(); i++) + aFBuilder.Add(TopoDS::Wire(aWires(i))); + TopoDS_Face DF = TopoDS::Face(aFBuilder.Shape()); - aFBuilder.Build(); - TopoDS_Face DF = aFBuilder.Face(); BRepLib::BuildCurves3d(DF); - bool IsInf = DF.Infinite(); if(!DF.IsNull()) { //sfs->Init ( DF ); @@ -332,12 +344,15 @@ void HYDROData_ShapeFile::ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F } } -bool HYDROData_ShapeFile::ImportLandCovers(const QString theFileName, QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces) +int HYDROData_ShapeFile::ImportLandCovers(const QString theFileName, QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces, int& theShapeTypeOfFile) { Free(); + int Stat = TryOpenShapeFile(theFileName); + if (Stat != 0) + return Stat; myHSHP = SHPOpen( theFileName.toAscii().data(), "rb" ); - if (!Parse(myHSHP, HYDROData_ShapeFile::ShapeType_Polygon)) - return false; + if (!Parse(myHSHP, HYDROData_ShapeFile::ShapeType_Polygon, theShapeTypeOfFile)) + return 0; for (size_t i = 0; i < mySHPObjects.size(); i++) thePolygonsList.append("polygon_" + QString::number(i + 1)); @@ -349,10 +364,10 @@ bool HYDROData_ShapeFile::ImportLandCovers(const QString theFileName, QStringLis ReadSHPPolygon(mySHPObjects[i], i, aF); theFaces.Append(aF); } - return true; + return 1; } else - return false; + return 0; } void HYDROData_ShapeFile::Free() @@ -476,7 +491,7 @@ void HYDROData_ShapeFile::ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, aPolylineObj->SetPolylineXY (aPolylineXY, false); aPolylineObj->SetAltitudeObject(aBath); - aPolylineObj->SetBorderColor( HYDROData_Polyline3D::DefaultBorderColor() ); + aPolylineObj->SetBorderColor( aPolylineObj->DefaultBorderColor() ); aPolylineObj->SetName( aPoly3DName ); aPolylineObj->Update(); @@ -487,8 +502,14 @@ void HYDROData_ShapeFile::ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, -bool HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, NCollection_Sequence& theEntities) +int HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, + NCollection_Sequence& theEntities, int& theShapeTypeOfFile) { + //Free(); + int aStat = TryOpenShapeFile(theFileName); + if (aStat != 0) + return aStat; + HYDROData_Iterator anIter( theDocument ); int anInd = 0; QStringList anExistingNames; @@ -502,9 +523,8 @@ bool HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument QFileInfo aFileInfo(theFileName); QString aBaseFileName = aFileInfo.baseName(); - if (!Parse(aHSHP, HYDROData_ShapeFile::ShapeType_Polyline)) - return false; - bool aStat = false; + if (!Parse(aHSHP, HYDROData_ShapeFile::ShapeType_Polyline, theShapeTypeOfFile)) + return 0; if (aHSHP->nShapeType == 3 || aHSHP->nShapeType == 23) { anInd = 0; @@ -523,7 +543,7 @@ bool HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument { ReadSHPPolyXY(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities); } - aStat = true; + aStat = 1; } else if (aHSHP->nShapeType == 13) { @@ -542,11 +562,11 @@ bool HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument } for (size_t i = 0; i < mySHPObjects.size(); i++ ) ReadSHPPoly3D(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities); - aStat = true; + aStat = 1; } else { - aStat = false; + aStat = 0; } for (size_t i = 0; i < mySHPObjects.size(); i++ ) @@ -555,4 +575,63 @@ bool HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument mySHPObjects.clear(); SHPClose(aHSHP); return aStat; +} + +QString HYDROData_ShapeFile::GetShapeTypeName(int theType) +{ + switch (theType) + { + case 0: + return "null shape"; + case 1: + return "point (unsupported by HYDRO)"; + case 3: + return "arc/polyline (supported by HYDRO)"; + case 5: + return "polygon (supported by HYDRO)"; + case 8: + return "multipoint (unsupported by HYDRO)"; + case 11: + return "pointZ (unsupported by HYDRO)"; + case 13: + return "arcZ/polyline (supported by HYDRO)"; + case 15: + return "polygonZ (unsupported by HYDRO)"; + case 18: + return "multipointZ (unsupported by HYDRO)"; + case 21: + return "pointM (unsupported by HYDRO)"; + case 23: + return "arcM/polyline (supported by HYDRO)"; + case 25: + return "polygonM (unsupported by HYDRO)"; + case 28: + return "multipointM (unsupported by HYDRO)"; + case 31: + return "multipatch (unsupported by HYDRO)"; + default: + return "unknown"; + } +} + +int HYDROData_ShapeFile::TryOpenShapeFile(QString theFileName) +{ + QString aSHPfile = theFileName.simplified(); + QString aSHXfile = theFileName.simplified().replace( ".shp", ".shx", Qt::CaseInsensitive); + FILE* pFileSHP = NULL; + pFileSHP = fopen (aSHPfile.toAscii().data(), "r"); + FILE* pFileSHX = NULL; + pFileSHX = fopen (aSHXfile.toAscii().data(), "r"); + + if (pFileSHP == NULL || pFileSHX == NULL) + { + if (pFileSHP == NULL) + return -1; + if (pFileSHX == NULL) + return -2; + } + + fclose (pFileSHP); + fclose (pFileSHX); + return 0; } \ No newline at end of file