]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Drawing of zones in OCC view improved.
authoradv <adv@opencascade.com>
Thu, 19 Sep 2013 10:39:02 +0000 (10:39 +0000)
committeradv <adv@opencascade.com>
Thu, 19 Sep 2013 10:39:02 +0000 (10:39 +0000)
src/HYDROGUI/HYDROGUI_Shape.cxx
src/HYDROGUI/HYDROGUI_Shape.h

index 107fb7436f3a48553a6b1ca92dec05dc3a79a26e..3fee62afb9282293e4902859d6e7de30e1d05375 100644 (file)
@@ -36,6 +36,8 @@
 #include <TopoDS_Wire.hxx>
 #include <TopoDS_Face.hxx>
 
+#include <Precision.hxx>
+
 #include <Prs3d_ShadingAspect.hxx>
 #include <Prs3d_LineAspect.hxx>
 #include <Prs3d_IsoAspect.hxx>
@@ -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 );
 
index 4e1ef2120d42f68be7990590ee1f51702d41ff29..3adfec17df49b01a888de7a93587132c78d68461 100644 (file)
 #include <QColor>
 #include <QPainterPath>
 
+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;