#include <HYDROGUI_DataObject.h>
#include <HYDROData_Iterator.h>
-
+#include <HYDROData_ShapeFile.h>
#include <HYDROData_Profile.h>
#include <SUIT_Desktop.h>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Wire.hxx>
-#include <BRepBuilderAPI_MakeEdge.hxx>
-#include <BRepBuilderAPI_MakeWire.hxx>
-#include <BRepBuilderAPI_MakeFace.hxx>
-#include <gp_Pln.hxx>
-#include <BRepLib.hxx>
-#include <ShapeFix_Shape.hxx>
+
HYDROGUI_ImportLandCoverOp::HYDROGUI_ImportLandCoverOp( HYDROGUI_Module* theModule )
}
-void HYDROGUI_ImportLandCoverOp::Parse(SHPHandle theHandle)
-{
- int aShapeType;
- mySHPObjects.clear();
- SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL );
- if (aShapeType == 5)
- {
- for (int i = 0; i < theHandle->nRecords; i++)
- mySHPObjects.push_back(SHPReadObject(theHandle, i));
- }
-}
-
-void HYDROGUI_ImportLandCoverOp::ProcessSHP(SHPObject* anObj, int i, TopoDS_Face& F)
-{
- TopoDS_Wire W;
- 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;
-
- for ( int i = 0 ; i < nParts ; i++ )
- {
- BRepBuilderAPI_MakeWire aBuilder;
- int StartIndex = anObj->panPartStart[i];
- int EndIndex;
- if (i != nParts - 1)
- EndIndex = anObj->panPartStart[i + 1];
- else
- EndIndex = anObj->nVertices;
-
- for ( int k = StartIndex; k < EndIndex - 1 ; k++ )
- {
- gp_Pnt P1 (anObj->padfX[k], anObj->padfY[k], 0);
- gp_Pnt P2 (anObj->padfX[k+1], anObj->padfY[k+1], 0);
- if (P1.Distance(P2) < Precision::Confusion())
- continue;
- BRepBuilderAPI_MakeEdge aMakeEdge(P1, P2);
- aBuilder.Add(TopoDS::Edge(aMakeEdge.Shape()));
- }
-
- aBuilder.Build();
- W = TopoDS::Wire(aBuilder.Shape());
- W.Reverse();
- aFBuilder.Add(W);
- }
-
- aFBuilder.Build();
- TopoDS_Face DF = aFBuilder.Face();
- BRepLib::BuildCurves3d(DF);
- bool IsInf = DF.Infinite();
- if(!DF.IsNull())
- {
- //sfs->Init ( DF );
- //sfs->Perform();
- F = DF; //TopoDS::Face(sfs->Shape());
- }
-}
-
void HYDROGUI_ImportLandCoverOp::onFileSelected()
{
HYDROGUI_ImportLandCoverDlg* aPanel = ::qobject_cast<HYDROGUI_ImportLandCoverDlg*>( inputPanel() );
QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
if (anExt == "shp")
- {
- SHPHandle aHSHP;
- aHSHP = SHPOpen( aFileName.toAscii().data(), "rb" );
- Parse(aHSHP);
+ {
+ startDocOperation();
+ QApplication::setOverrideCursor(Qt::WaitCursor);
- startDocOperation();
QStringList aPolygonsList;
- for (int i = 0; i < mySHPObjects.size(); i++)
- aPolygonsList.append("polygon_" + QString::number(i + 1));
+ TopTools_SequenceOfShape aFaces;
+ HYDROData_ShapeFile anImporter;
+
+ if (!anImporter.ImportLandCovers(aFileName, aPolygonsList, aFaces))
+ {
+ SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_LANDCOVER" ), "Cannot import land cover;\nThe shape type is not polygon" );
+ abort();
+ }
+
aPanel->setPolygonNames(aPolygonsList);
SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
}
}
- QApplication::setOverrideCursor(Qt::WaitCursor);
- TopTools_SequenceOfShape aFaces;
- TopoDS_Face aF;
- if (aHSHP->nShapeType == 5)
- {
- for (int i = 0; i < mySHPObjects.size(); i++)
- {
- ProcessSHP(mySHPObjects[i], i, aF);
- aFaces.Append(aF);
- }
- }
- else
- SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_LANDCOVER" ), "Cannot import land cover;\nThe shape type is not polygon" );
QApplication::restoreOverrideCursor();
Handle(HYDROData_LandCover) aLC = Handle(HYDROData_LandCover)::DownCast( doc()->CreateObject( KIND_LAND_COVER ) );
}
commitDocOperation();
-
- for (size_t i = 0; i < mySHPObjects.size(); i++ )
- free (mySHPObjects[i]);
- mySHPObjects.clear();
- SHPClose(aHSHP);
+ anImporter.Free();
+
}
}