Salome HOME
Feature #86: The hierarchy in the Object Browser (T 19).
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Shape.cxx
index a54e7ccd92bd03bf79e855b0bad3de3c0bd6d99c..534a57ce1135b1a831cefcebb6031ec62cf4d895 100644 (file)
 #include <TopoDS_Wire.hxx>
 #include <TopoDS_Face.hxx>
 
+#include <TopExp_Explorer.hxx>
+
+#include <BRep_Builder.hxx>
+
 #include <Precision.hxx>
 
 #include <Prs3d_ShadingAspect.hxx>
@@ -115,22 +119,45 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
       Handle(HYDROData_ImmersibleZone) aZoneObj =
         Handle(HYDROData_ImmersibleZone)::DownCast( myObject );
 
+      TopoDS_Shape aZoneShape = aZoneObj->GetTopShape();
+      if ( !aZoneShape.IsNull() ) {
+        if ( aZoneShape.ShapeType() == TopAbs_FACE ) {
+          TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
+          setFace( aZoneFace, false, false );
+        } else {
+          myTopoShape = aZoneShape;
+          myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
+
+          buildShape();
+          updateShape( false, false );
+        }
+      }
+
       QColor aFillingColor = aZoneObj->GetFillingColor();
       QColor aBorderColor = aZoneObj->GetBorderColor();
-      TopoDS_Face aZoneFace = TopoDS::Face( aZoneObj->GetTopShape() );
 
       setFillingColor( aFillingColor, false, false );
       setBorderColor( aBorderColor, false, false );
-      setFace( aZoneFace, false, false );
     }
     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Polyline) ) )
     {
       Handle(HYDROData_Polyline) aPolyline =
         Handle(HYDROData_Polyline)::DownCast( myObject );
 
-      TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolyline->GetTopShape() );
+      TopoDS_Shape aPolylineShape = aPolyline->GetTopShape();
+
+      if ( !aPolylineShape.IsNull() ) {
+        if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
+          TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
+          setWire( aPolylineWire, false, false );  
+        } else {
+          myTopoShape = aPolylineShape;
+          myDisplayMode = AIS_WireFrame;
 
-      setWire( aPolylineWire, false, false );
+          buildShape();
+          updateShape( false, false );
+        }
+      }
     }
     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) )
     {
@@ -230,8 +257,11 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
       myTopoShape = anObstacle->GetShape3D();
       myDisplayMode = AIS_Shaded;
 
-      //TODO colors should be defined in another way
-      setFillingColor( Qt::green, false, false );
+      QColor aFillingColor = anObstacle->GetFillingColor();
+      QColor aBorderColor = anObstacle->GetBorderColor();
+
+      setFillingColor( aFillingColor, false, false );
+      setBorderColor( aBorderColor, false, false );
 
       buildShape();
       updateShape( false, false );
@@ -292,6 +322,35 @@ void HYDROGUI_Shape::setWire( const TopoDS_Wire& theWire,
   updateShape( theToDisplay, theIsUpdateViewer );
 }
 
+void HYDROGUI_Shape::setFaces( const TopoDS_Compound& theWires,
+                               const bool             theToDisplay,
+                               const bool             theIsUpdateViewer )
+{
+  TopExp_Explorer anExp( theWires, TopAbs_WIRE );
+  TopoDS_Compound aCompound;
+  BRep_Builder aBuilder;
+    aBuilder.MakeCompound( aCompound );
+
+  for ( ; anExp.More(); anExp.Next() ) {
+    TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
+    if ( aWire.IsNull() ) {
+      continue;
+    }
+
+    BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
+    aMakeFace.Build();
+    if( aMakeFace.IsDone() ) {
+      aBuilder.Add( aCompound, aMakeFace.Face() );
+    }
+  }
+
+  myTopoShape = aCompound;
+  myDisplayMode = AIS_Shaded;
+
+  buildShape();
+  updateShape( theToDisplay, theIsUpdateViewer );
+}
+
 void HYDROGUI_Shape::setFace( const TopoDS_Wire& theWire,
                               const bool         theToDisplay,
                               const bool         theIsUpdateViewer )
@@ -318,6 +377,17 @@ void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace,
   updateShape( theToDisplay, theIsUpdateViewer );
 }
 
+void HYDROGUI_Shape::setShape( const TopoDS_Shape& theShape,
+                               const bool          theToDisplay,
+                               const bool          theIsUpdateViewer )
+{
+  myTopoShape = theShape;
+  myDisplayMode = AIS_Shaded;
+
+  buildShape();
+  updateShape( theToDisplay, theIsUpdateViewer );
+}
+
 void HYDROGUI_Shape::setFillingColor( const QColor& theColor,
                                       const bool    theToDisplay,
                                       const bool    theIsUpdateViewer )