Salome HOME
Feature #86: The hierarchy in the Object Browser (T 19).
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Shape.cxx
index 4eaecc5163153195a3025225e1ae463682acbad9..534a57ce1135b1a831cefcebb6031ec62cf4d895 100644 (file)
@@ -26,6 +26,7 @@
 #include "HYDROGUI_Tool.h"
 
 #include <AIS_Drawer.hxx>
+#include <AIS_TexturedShape.hxx>
 
 #include <BRepBuilderAPI_MakeEdge.hxx>
 #include <BRepBuilderAPI_MakeWire.hxx>
 #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>
@@ -106,34 +112,52 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
   // Try to retrieve information from object
   if ( !myObject.IsNull() )
   {
-    Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myObject );
+    Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myObject->Label() );
   
     if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ImmersibleZone) ) )
     {
       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 );
-    }
-    else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Region) ) )
-    {
-      Handle(HYDROData_Region) aRegion =
-        Handle(HYDROData_Region)::DownCast( myObject );
+      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) ) )
     {
@@ -162,7 +186,15 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
       }
        
       setFace( aZoneFace, false, false );
-      setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) );
+      if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
+      {
+        // Red color for a zone with bathymetry conflict
+        setFillingColor( Qt::red );
+      }
+      else
+      {
+        setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) );
+      }
     }
     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) )
     {
@@ -215,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;
 
@@ -270,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 )
@@ -288,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 );
@@ -351,7 +445,17 @@ void HYDROGUI_Shape::buildShape()
   if ( myTopoShape.IsNull() )
     return;
 
-  myShape = new AIS_TexturedShape( myTopoShape );
+  QString aTextureFileName = getTextureFileName();
+  bool anIsTexture = !aTextureFileName.isEmpty();
+
+  if ( anIsTexture )
+  {
+    myShape = new AIS_TexturedShape( myTopoShape );
+  }
+  else
+  {
+    myShape = new AIS_Shape( myTopoShape );
+  }
 
   if ( !myObject.IsNull() )
     myShape->SetOwner( myObject );
@@ -359,12 +463,14 @@ void HYDROGUI_Shape::buildShape()
   myShape->SetTransparency( 0 );
   myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode );
 
-  QString aTextureFileName = getTextureFileName();
-  if( !aTextureFileName.isEmpty() )
+  if( anIsTexture )
   {
-    myShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) );
-    myShape->SetTextureMapOn();
-    myShape->DisableTextureModulate();
+    Handle(AIS_TexturedShape) aTexturedShape = 
+      Handle(AIS_TexturedShape)::DownCast( myShape );
+
+    aTexturedShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) );
+    aTexturedShape->SetTextureMapOn();
+    aTexturedShape->DisableTextureModulate();
   }
 
     // Init default params for shape