#include "HYDROData_PolylineXY.h"
+#include <BRep_Builder.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
#include <TDataStd_AsciiString.hxx>
#include <TNaming_Builder.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <NCollection_IncAllocator.hxx>
+#include <BOPAlgo_BOP.hxx>
+#include <QColor>
#include <QStringList>
IMPLEMENT_STANDARD_HANDLE( HYDROData_LandCover, HYDROData_Entity )
removeShape();
- TopoDS_Shape aResShape = buildShape();
+ TCollection_AsciiString anErrorMsg;
+ TopoDS_Shape aResShape = buildShape( GetPolylines(), anErrorMsg );
setShape( aResShape );
}
return GetReferenceObjects( DataTag_Polylines );
}
+TopoDS_Shape HYDROData_LandCover::GetShape() const
+{
+ TopoDS_Shape aShape;
+
+ TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
+ if ( !aLabel.IsNull() )
+ {
+ Handle(TNaming_NamedShape) aNamedShape;
+ if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) ) {
+ aShape = aNamedShape->Get();
+ }
+ }
+
+ return aShape;
+}
+
+void HYDROData_LandCover::SetFillingColor( const QColor& theColor )
+{
+ SetColor( theColor, DataTag_FillingColor );
+}
+
+QColor HYDROData_LandCover::GetFillingColor() const
+{
+ return GetColor( DefaultFillingColor(), DataTag_FillingColor );
+}
+
+void HYDROData_LandCover::SetBorderColor( const QColor& theColor )
+{
+ SetColor( theColor, DataTag_BorderColor );
+}
+
+QColor HYDROData_LandCover::GetBorderColor() const
+{
+ return GetColor( DefaultBorderColor(), DataTag_BorderColor );
+}
+
+QColor HYDROData_LandCover::DefaultFillingColor()
+{
+ return QColor( Qt::magenta );
+}
+
+QColor HYDROData_LandCover::DefaultBorderColor()
+{
+ return QColor( Qt::transparent );
+}
+
void HYDROData_LandCover::setShape( const TopoDS_Shape& theShape )
{
TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
}
}
-TopoDS_Shape HYDROData_LandCover::buildShape() const
+TopoDS_Shape HYDROData_LandCover::buildShape( const HYDROData_SequenceOfObjects& thePolylines,
+ TCollection_AsciiString& theErrorMsg )
{
+ theErrorMsg.Clear();
TopoDS_Shape aResShape;
+ BRepBuilderAPI_MakeWire aMakeWire;
+
+ TopTools_ListOfShape aClosedWires;
+
+ int aNbPolylines = thePolylines.Length();
+ for ( int i = 1; i <= aNbPolylines; ++i ) {
+ Handle(HYDROData_PolylineXY) aPolyline =
+ Handle(HYDROData_PolylineXY)::DownCast( thePolylines.Value( i ) );
+
+ if ( aPolyline.IsNull() ) {
+ continue;
+ }
+
+ TopoDS_Shape aPolyShape = aPolyline->GetShape();
+ if ( aPolyShape.IsNull() ) {
+ continue;
+ }
+
+ // Extract polyline wire(s)
+ TopTools_ListOfShape aPolylineWires;
+
+ if ( aPolyShape.ShapeType() == TopAbs_WIRE ) {
+ const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolyShape );
+ if ( !aPolylineWire.IsNull() ) {
+ aPolylineWires.Append( aPolylineWire );
+ }
+ } else if ( aPolyShape.ShapeType() == TopAbs_COMPOUND ) {
+ TopExp_Explorer anExp( aPolyShape, TopAbs_WIRE );
+ for (; anExp.More(); anExp.Next() ) {
+ if(!anExp.Current().IsNull()) {
+ const TopoDS_Wire& aWire = TopoDS::Wire( anExp.Current() );
+ aPolylineWires.Append( aWire );
+ }
+ }
+ }
+
+ TopTools_ListIteratorOfListOfShape anIt( aPolylineWires );
+ for ( ; anIt.More(); anIt.Next() ) {
+ TopoDS_Wire& aWire = TopoDS::Wire( anIt.Value() );
+
+ if ( aWire.Closed() ) {
+ aClosedWires.Append( aWire );
+ } else {
+ aMakeWire.Add( aWire );
+ aMakeWire.Build();
+ if ( aMakeWire.IsDone() ) {
+ if ( aMakeWire.Wire().Closed() ) {
+ aClosedWires.Append( aMakeWire.Wire() );
+ aMakeWire = BRepBuilderAPI_MakeWire();
+ }
+ }
+ }
+ }
+ }
+
+ if ( aClosedWires.Extent() == 1 ) {
+ // make face
+ BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire( aClosedWires.First() ) );
+ aMakeFace.Build();
+ if( aMakeFace.IsDone() ) {
+ aResShape = aMakeFace.Face();
+ }
+ } else if ( aClosedWires.Extent() > 1 ) {
+ // make compound
+ BRep_Builder aBuilder;
+ TopoDS_Compound aCompound;
+ aBuilder.MakeCompound( aCompound );
+
+ TopTools_ListIteratorOfListOfShape aWiresIter( aClosedWires );
+ for ( ; aWiresIter.More(); aWiresIter.Next() ) {
+ BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire( aWiresIter.Value() ) );
+ aMakeFace.Build();
+ if( aMakeFace.IsDone() ) {
+ aBuilder.Add( aCompound, aMakeFace.Face() );
+ }
+ }
+
+ aResShape = aCompound;
+ } else if ( aNbPolylines > 0 ) {
+ TCollection_AsciiString aSourceName = aNbPolylines > 1 ? "polylines" : "polyline";
+ theErrorMsg = "Can't build closed contour on the given ";
+ theErrorMsg += aSourceName;
+ }
+
///< \TODO to be reimplemented
+ /*
+ TopoDS_Shape anArgShape;
+ TopTools_ListOfShape aToolShapes;
+
HYDROData_SequenceOfObjects aRefPolylines = GetPolylines();
for ( int i = 1, n = aRefPolylines.Length(); i <= n; ++i ) {
Handle(HYDROData_PolylineXY) aPolyline =
continue;
}
- if ( aPolyline->IsClosed() ) {
- aResShape = aPolyline->GetShape();
- break;
+ if ( !aPolyline->IsClosed() ) {
+ continue;
+ }
+
+ TopoDS_Shape aPolyShape = aPolyline->GetShape();
+ if ( aPolyShape.IsNull() || aPolyShape.ShapeType() != TopAbs_WIRE ) {
+ continue;
+ }
+
+ const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolyShape );
+ if ( aPolylineWire.IsNull() ) {
+ continue;
+ }
+
+ TopoDS_Face aResultFace = TopoDS_Face();
+ BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
+ aMakeFace.Build();
+ if( aMakeFace.IsDone() ) {
+ aResultFace = aMakeFace.Face();
+ }
+
+ if( aResultFace.IsNull() ) {
+ continue;
+ }
+
+ if ( anArgShape.IsNull() ) {
+ anArgShape = aResultFace;
+ } else {
+ aToolShapes.Append( aResultFace );
+ }
+ }
+
+ aResShape = anArgShape;
+
+ if ( !anArgShape.IsNull() && aToolShapes.Extent() > 0 ) {
+ Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
+ BOPAlgo_BOP aBOP(aAL);
+
+ aBOP.AddArgument( anArgShape );
+
+ TopTools_ListIteratorOfListOfShape anIt(aToolShapes);
+ for( ; anIt.More(); anIt.Next() ) {
+ aBOP.AddTool( anIt.Value() );
+ }
+
+ aBOP.SetOperation( BOPAlgo_CUT );
+ aBOP.Perform();
+
+ if ( !aBOP.Shape().IsNull() ) {
+ aResShape = aBOP.Shape();
}
}
+ */
+
return aResShape;
}
\ No newline at end of file