Salome HOME
Feature #86: The hierarchy in the Object Browser (T 19).
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Shape.cxx
index 361a420cc42f5e1fb5e8b14256476b42e262708b..534a57ce1135b1a831cefcebb6031ec62cf4d895 100644 (file)
 #include <HYDROData_Polyline.h>
 #include <HYDROData_Region.h>
 #include <HYDROData_Zone.h>
+#include <HYDROData_Obstacle.h>
 
 #include <TopoDS.hxx>
 #include <TopoDS_Wire.hxx>
 #include <TopoDS_Face.hxx>
 
+#include <TopExp_Explorer.hxx>
+
+#include <BRep_Builder.hxx>
+
 #include <Precision.hxx>
 
 #include <Prs3d_ShadingAspect.hxx>
@@ -114,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();
 
-      setWire( aPolylineWire, false, false );
+      if ( !aPolylineShape.IsNull() ) {
+        if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
+          TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
+          setWire( aPolylineWire, false, false );  
+        } else {
+          myTopoShape = aPolylineShape;
+          myDisplayMode = AIS_WireFrame;
+
+          buildShape();
+          updateShape( false, false );
+        }
+      }
     }
     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) )
     {
@@ -219,8 +247,28 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
       setTextureFileName( aTextureFileName, false, false );
       setFace( aWire, false, false );
     }
-  }
+    else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Obstacle) ) )
+    {
+      Handle(HYDROData_Obstacle) anObstacle =
+        Handle(HYDROData_Obstacle)::DownCast( myObject );
 
+      //TODO BEGIN of the block of code to be reimplemented
+      //TODO GetTopShape() to be used in future
+      myTopoShape = anObstacle->GetShape3D();
+      myDisplayMode = AIS_Shaded;
+
+      QColor aFillingColor = anObstacle->GetFillingColor();
+      QColor aBorderColor = anObstacle->GetBorderColor();
+
+      setFillingColor( aFillingColor, false, false );
+      setBorderColor( aBorderColor, false, false );
+
+      buildShape();
+      updateShape( false, false );
+      //TODO END of the block of code to be reimplemented
+    }
+  }
   if ( myShape.IsNull() || !isVisible() )
     return;
 
@@ -274,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 )
@@ -292,7 +369,20 @@ void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace,
                               const bool         theIsUpdateViewer )
 {
   myTopoShape = theFace;
-  myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_ExactHLR;
+  myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
+  //Note: AIS_Shaded+2 is the same as AIS_ExactHLR
+  //TODO: it would be more suitable to use TexturedShape mode from GEOM_AISShape
+
+  buildShape();
+  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 );