Salome HOME
Modify creation of curves: 1) using QDockWidget instead of QDialog; 2) selection...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Shape.cxx
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 );