#include <TopoDS_Wire.hxx>
#include <TopoDS_Face.hxx>
+#include <Precision.hxx>
+
#include <Prs3d_ShadingAspect.hxx>
#include <Prs3d_LineAspect.hxx>
#include <Prs3d_IsoAspect.hxx>
return myHighlightColor;
}
+void HYDROGUI_Shape::makeEdge( BRepBuilderAPI_MakeWire& theWireBuilder,
+ gp_Pnt& theFirstPoint,
+ gp_Pnt& theLastPoint ) const
+{
+ BRepBuilderAPI_MakeEdge anEdgeBuilder( theFirstPoint, theLastPoint );
+ anEdgeBuilder.Build();
+ if ( anEdgeBuilder.IsDone() )
+ {
+ TopoDS_Edge anEdge = anEdgeBuilder;
+ theWireBuilder.Add( anEdge );
+ }
+}
+
+void HYDROGUI_Shape::makeWire( BRepBuilderAPI_MakeFace& theFaceBuilder,
+ BRepBuilderAPI_MakeWire& theWireBuilder,
+ bool& theIsComposed ) const
+{
+ theWireBuilder.Build();
+ if ( theWireBuilder.IsDone() )
+ {
+ TopoDS_Wire aBuildedWire = theWireBuilder;
+ if ( theIsComposed )
+ {
+ theFaceBuilder.Add( aBuildedWire );
+ }
+ else
+ {
+ theFaceBuilder = BRepBuilderAPI_MakeFace( aBuildedWire, true );
+
+ theFaceBuilder.Build();
+ theIsComposed = theFaceBuilder.IsDone();
+ }
+ }
+
+ theWireBuilder = BRepBuilderAPI_MakeWire();
+}
+
void HYDROGUI_Shape::buildShape()
{
// Erase previously created shape
if ( myPath.isEmpty() )
return;
- BRepBuilderAPI_MakeWire aMakeWire;
+ BRepBuilderAPI_MakeFace aFaceBuilder;
+ BRepBuilderAPI_MakeWire aWireBuilder;
// Build new shape from path
- gp_Pnt aPrevPoint( 0, 0, myZIndex );
+ bool anIsComposed = false;
+ bool anIsStarted = false;
+ gp_Pnt aStartPoint( 0, 0, myZIndex );
+ gp_Pnt aPrevPoint( 0, 0, myZIndex );
+
for ( int i = 0; i < myPath.elementCount(); ++i )
{
const QPainterPath::Element& aPathElem = myPath.elementAt( i );
{
case QPainterPath::LineToElement:
{
- BRepBuilderAPI_MakeEdge aMakeEdge( aPrevPoint, aCurPoint );
- aMakeEdge.Build();
- if ( aMakeEdge.IsDone() )
- {
- TopoDS_Edge anEdge = aMakeEdge;
- aMakeWire.Add( anEdge );
- }
+ // Just build the edge
+ makeEdge( aWireBuilder, aPrevPoint, aCurPoint );
break;
}
case QPainterPath::CurveToElement:
break;
}
case QPainterPath::MoveToElement:
+ {
+ if ( anIsStarted )
+ {
+ // Compose face
+ if ( !aStartPoint.IsEqual( aPrevPoint, Precision::Confusion() ) )
+ {
+ //Close wire
+ makeEdge( aWireBuilder, aPrevPoint, aStartPoint );
+ }
+
+ // Make face wiyth edge
+ makeWire( aFaceBuilder, aWireBuilder, anIsComposed );
+ }
+
+ anIsStarted = true;
+ aStartPoint = aCurPoint;
+ break;
+ }
default:
break;
}
aPrevPoint = aCurPoint;
}
- TopoDS_Face aResShape;
+ makeWire( aFaceBuilder, aWireBuilder, anIsComposed );
- aMakeWire.Build();
- if ( aMakeWire.IsDone() )
- {
- TopoDS_Wire aCommonWire = aMakeWire;
+ TopoDS_Face aResShape;
- BRepBuilderAPI_MakeFace aMakeFace( aCommonWire, true );
- aMakeFace.Build();
- if ( aMakeFace.IsDone() )
- aResShape = aMakeFace;
- }
+ aFaceBuilder.Build();
+ if ( aFaceBuilder.IsDone() )
+ aResShape = aFaceBuilder;
myShape = new AIS_Shape( aResShape );