#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>
removeShape();
- TopoDS_Shape aResShape = buildShape();
+ TCollection_AsciiString anErrorMsg;
+ TopoDS_Shape aResShape = buildShape( GetPolylines(), anErrorMsg );
setShape( aResShape );
}
}
}
-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;
- HYDROData_SequenceOfObjects aRefPolylines = GetPolylines();
- for ( int i = 1, n = aRefPolylines.Length(); i <= n; ++i ) {
+ int aNbPolylines = thePolylines.Length();
+ for ( int i = 1; i <= aNbPolylines; ++i ) {
Handle(HYDROData_PolylineXY) aPolyline =
- Handle(HYDROData_PolylineXY)::DownCast( aRefPolylines.Value( i ) );
+ Handle(HYDROData_PolylineXY)::DownCast( thePolylines.Value( i ) );
if ( aPolyline.IsNull() ) {
continue;
}
TopoDS_Shape aPolyShape = aPolyline->GetShape();
- if ( aPolyShape.IsNull() || aPolyShape.ShapeType() != TopAbs_WIRE ) {
+ if ( aPolyShape.IsNull() ) {
continue;
}
- const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolyShape );
- if ( aPolylineWire.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 );
+ }
+ }
}
-
- if ( aPolylineWire.Closed() ) {
- aClosedWires.Append( aPolylineWire );
- } else {
- aMakeWire.Add( aPolylineWire );
- aMakeWire.Build();
- if ( aMakeWire.IsDone() ) {
- if ( aMakeWire.Wire().Closed() ) {
- aClosedWires.Append( aMakeWire.Wire() );
- aMakeWire = BRepBuilderAPI_MakeWire();
+
+ 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();
+ }
}
}
}
}
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
}
}
+ if ( aZonePolylines.IsEmpty() )
+ {
+ theErrorMsg = tr( "POLYLINES_NOT_DEFINED" );
+ return false;
+ }
+
QString aSelectedStricklerType = aPanel->getSelectedAdditionalParamName();
- // TODO: Generate TopoDS_Shape based on the set of polylines, implement generateTopShape data model method
- /*
- if ( HYDROData_LandCover::generateTopShape( aZonePolylines ).IsNull() )
+ TCollection_AsciiString anError;
+ if ( HYDROData_LandCover::buildShape( aZonePolylines, anError ).IsNull() )
{
- theErrorMsg = tr( "ZONE_OBJECT_CANNOT_BE_CREATED" );
+ if ( !anError.IsEmpty() ) {
+ theErrorMsg = HYDROGUI_Tool::ToQString( anError );
+ } else {
+ theErrorMsg = tr( "LAND_COVER_OBJECT_CANNOT_BE_CREATED" );
+ }
return false;
}
- */
-
+
Handle(HYDROData_LandCover) aZoneObj = myIsEdit ? myEditedObject :
Handle(HYDROData_LandCover)::DownCast( doc()->CreateObject( KIND_LAND_COVER ) );