From b8e7b28e3b3df4b29bab7b8ecdbafa8b0a138ddc Mon Sep 17 00:00:00 2001 From: adv Date: Thu, 19 Sep 2013 10:39:02 +0000 Subject: [PATCH] Drawing of zones in OCC view improved. --- src/HYDROGUI/HYDROGUI_Shape.cxx | 90 ++++++++++++++++++++++++++------- src/HYDROGUI/HYDROGUI_Shape.h | 12 +++++ 2 files changed, 83 insertions(+), 19 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index 107fb743..3fee62af 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -36,6 +36,8 @@ #include #include +#include + #include #include #include @@ -155,6 +157,43 @@ QColor HYDROGUI_Shape::getHighlightColor() const 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 @@ -163,10 +202,15 @@ void HYDROGUI_Shape::buildShape() 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 ); @@ -176,13 +220,8 @@ void HYDROGUI_Shape::buildShape() { 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: @@ -191,6 +230,24 @@ void HYDROGUI_Shape::buildShape() 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; } @@ -198,18 +255,13 @@ void HYDROGUI_Shape::buildShape() 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 ); diff --git a/src/HYDROGUI/HYDROGUI_Shape.h b/src/HYDROGUI/HYDROGUI_Shape.h index 4e1ef212..3adfec17 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.h +++ b/src/HYDROGUI/HYDROGUI_Shape.h @@ -29,6 +29,10 @@ #include #include +class BRepBuilderAPI_MakeFace; +class BRepBuilderAPI_MakeWire; +class gp_Pnt; + class HYDROGUI_Shape { public: @@ -70,6 +74,14 @@ private: static double getQuantityColorVal( const int theColorVal ); void colorShapeBorder( const QColor& theColor ); + void makeEdge( BRepBuilderAPI_MakeWire& theWireBuilder, + gp_Pnt& theFirstPoint, + gp_Pnt& theLastPoint ) const; + + void makeWire( BRepBuilderAPI_MakeFace& theFaceBuilder, + BRepBuilderAPI_MakeWire& theWireBuilder, + bool& theIsComposed ) const; + private: Handle(AIS_InteractiveContext) myContext; Handle(AIS_Shape) myShape; -- 2.39.2