#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <BRep_Tool.hxx>
+#include <BRepTools.hxx>
#include <Precision.hxx>
#include <Handle_Geom_Curve.hxx>
#include <Handle_Geom_Line.hxx>
#include <TopTools_SequenceOfShape.hxx>
#include <QColor>
#include <BRepTopAdaptor_FClass2d.hxx>
+#include <TopExp.hxx>
#ifdef WIN32
#pragma warning( disable: 4996 )
if ( !aLCM.IsNull() && !aLCM->IsEmpty())
{
hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_POLYGON );
- HYDROData_LandCoverMap::Iterator It( aLCM );
- for( ; It.More(); It.Next() )
+ HYDROData_LandCoverMap::Explorer It( aLCM );
+ for( ; It.More(); It.Next())
{
TopoDS_Face aFace = It.Face();
if (WriteObjectPolygon(hSHPHandle, aFace) != 1)
void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle)
{
+ if (theFace.ShapeType() != TopAbs_FACE)
+ return;
SHPObject *aSHPObj;
std::vector<double> x, y;
std::vector<int> anPartStart;
- if (theFace.ShapeType() == TopAbs_FACE)
+ TopoDS_Wire OuterW = BRepTools::OuterWire(theFace);
+ NCollection_Sequence<TopoDS_Wire> aWires;
+
+ //write an outer wire first
+ aWires.Append(OuterW);
+ TopExp_Explorer Ex(theFace, TopAbs_WIRE);
+ for (; Ex.More(); Ex.Next())
{
- TopExp_Explorer Ex(theFace, TopAbs_WIRE);
- int NbWires = 0;
- for (; Ex.More(); Ex.Next())
+ TopoDS_Wire aW = TopoDS::Wire(Ex.Current());
+ if (aW.IsEqual(OuterW))
+ continue;
+ aWires.Append(aW);
+ }
+
+ //TopExp_Explorer Ex(theFace, TopAbs_WIRE);
+ int NbWires = 0;
+ for (int k = 1; k <= aWires.Length(); k++)
+ {
+ TopoDS_Wire aW = aWires(k);
+ if (aW.IsNull())
+ continue;
+ NbWires++;
+ if (aW.Orientation() == TopAbs_INTERNAL)
+ //cant write internal wires/edges
+ continue;
+ // Try to reorder edges
+ Handle(ShapeFix_Wire) aSFW = new ShapeFix_Wire( aW, theFace, Precision::Confusion() );
+ aSFW->ModifyTopologyMode() = Standard_False;
+ aSFW->ModifyGeometryMode() = Standard_False;
+ aSFW->FixReorder();
+ Handle(ShapeExtend_WireData) aSEWD = aSFW->WireData();
+ Standard_Integer nbE = aSEWD->NbEdges();
+ if (nbE == 0)
+ continue;
+ //
+ anPartStart.push_back(x.size());
+ NCollection_Sequence<gp_Pnt2d> aPnts;
+ for (Standard_Integer i = 1; i <= nbE; i++)
{
- TopoDS_Wire aW = TopoDS::Wire(Ex.Current());
- if (aW.IsNull())
+ TopoDS_Edge E = aSEWD->Edge(i);
+ TopoDS_Vertex aV = TopExp::LastVertex(E, 1);
+ if (aV.IsNull())
continue;
- NbWires++;
- anPartStart.push_back(x.size());
- TopExp_Explorer aVEx(aW, TopAbs_VERTEX);
- NCollection_Sequence<gp_Pnt2d> aPnts;
- for (; aVEx.More(); aVEx.Next())
- {
- TopoDS_Vertex aV = TopoDS::Vertex(aVEx.Current());
- if (aV.IsNull())
- continue;
- gp_Pnt P = BRep_Tool::Pnt(aV);
- aPnts.Append(gp_Pnt2d(P.X(), P.Y()));
- }
- NCollection_Sequence<gp_Pnt2d> aNPnts;
- aNPnts.Append(aPnts.First());
- for (int j = 1; j <= aPnts.Size() - 1; j++)
- {
- if (!aPnts(j).IsEqual(aPnts(j + 1), Precision::Confusion()))
- aNPnts.Append(aPnts(j + 1));
- }
+ gp_Pnt P = BRep_Tool::Pnt(aV);
+ aPnts.Append(gp_Pnt2d(P.X(), P.Y()));
+ }
+ NCollection_Sequence<gp_Pnt2d> aNPnts;
+ aNPnts.Append(aPnts.First());
+ for (int j = 1; j <= aPnts.Size() - 1; j++)
+ {
+ if (!aPnts(j).IsEqual(aPnts(j + 1), Precision::Confusion()))
+ aNPnts.Append(aPnts(j + 1));
+ }
- for (int j = 1; j <= aNPnts.Size(); j++)
- {
- x.push_back( aNPnts(j).X());
- y.push_back( aNPnts(j).Y());
- }
- //x.push_back( aNPnts(1).X());
- //y.push_back( aNPnts(1).Y());
+ //assume that the orientation of extrenal wire & internal wires is correct
+ //so just write all points "as-is"
+ //External wire will be written in clockwise direction
+ //any other wires (holes) - in anticlockwise direction
+ for (int j = 1; j <= aNPnts.Size(); j++)
+ {
+ x.push_back( aNPnts(j).X());
+ y.push_back( aNPnts(j).Y());
}
-
- aSHPObj = SHPCreateObject( SHPT_POLYGON, -1, NbWires, &anPartStart[0], NULL, x.size(), &x[0], &y[0], NULL, NULL );
- SHPWriteObject( theShpHandle, -1, aSHPObj );
- SHPDestroyObject( aSHPObj );
+ x.push_back( aNPnts(1).X());
+ y.push_back( aNPnts(1).Y());
}
- else
- return;
+
+ aSHPObj = SHPCreateObject( SHPT_POLYGON, -1, NbWires, &anPartStart[0], NULL, x.size(), &x[0], &y[0], NULL, NULL );
+ SHPWriteObject( theShpHandle, -1, aSHPObj );
+ SHPDestroyObject( aSHPObj );
+
}
bool HYDROData_ShapeFile::Parse(SHPHandle theHandle, ShapeType theType, int& theShapeTypeOfFile)
void HYDROData_ShapeFile::ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F)
{
+ if (!anObj)
+ return;
TopoDS_Wire W;
TopoDS_Edge E;
int nParts = anObj->nParts;