Salome HOME
Fix for the bug #42: point C is not activated, but point C is shown in preview in...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Shape.cxx
index 4b78aae4c5b7f3b550be93306509c71440716011..9a6c0ca700144bd562ff588259b0508e277063a9 100644 (file)
 #include <Graphic3d_AspectFillArea3d.hxx>
 #include <Graphic3d_MaterialAspect.hxx>
 
-#include <HYDROData_Domain.h>
+#include <HYDROData_Document.h>
 #include <HYDROData_Image.h>
+#include <HYDROData_ImmersibleZone.h>
 #include <HYDROData_Polyline.h>
+#include <HYDROData_Region.h>
+#include <HYDROData_Zone.h>
 
+#include <TopoDS.hxx>
 #include <TopoDS_Wire.hxx>
 #include <TopoDS_Face.hxx>
 
@@ -53,7 +57,7 @@
 #include <QFile>
 
 HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext,
-                                const Handle(HYDROData_Object)&       theObject )
+                                const Handle(HYDROData_Entity)&       theObject )
 : myContext( theContext ),
   myObject( theObject ),
   myIsHighlight( false ),
@@ -102,28 +106,72 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
   // Try to retrieve information from object
   if ( !myObject.IsNull() )
   {
-    if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Domain) ) )
+    Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myObject->Label() );
+  
+    if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ImmersibleZone) ) )
     {
-      Handle(HYDROData_Domain) aDomainObj =
-        Handle(HYDROData_Domain)::DownCast( myObject );
+      Handle(HYDROData_ImmersibleZone) aZoneObj =
+        Handle(HYDROData_ImmersibleZone)::DownCast( myObject );
 
-      QColor aFillingColor = aDomainObj->GetFillingColor();
-      QColor aBorderColor = aDomainObj->GetBorderColor();
-      TopoDS_Face aDomainFace = aDomainObj->Face();
+      QColor aFillingColor = aZoneObj->GetFillingColor();
+      QColor aBorderColor = aZoneObj->GetBorderColor();
+      TopoDS_Face aZoneFace = TopoDS::Face( aZoneObj->GetTopShape() );
 
       setFillingColor( aFillingColor, false, false );
       setBorderColor( aBorderColor, false, false );
-      setFace( aDomainFace, 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 = aPolyline->Wire();
+      TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolyline->GetTopShape() );
 
       setWire( aPolylineWire, false, false );
     }
+    else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Region) ) )
+    {
+      Handle(HYDROData_Region) aRegion =
+        Handle(HYDROData_Region)::DownCast( myObject );
+    }
+    else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) )
+    {
+      Handle(HYDROData_Zone) aZone =
+        Handle(HYDROData_Zone)::DownCast( myObject );
+
+      TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() );
+
+      // Generate the filling color for zone
+      QStringList aGeomObjectsNames;
+
+      HYDROData_SequenceOfObjects aRefObjects = aZone->GetGeometryObjects();
+      HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
+      for ( ; anIter.More(); anIter.Next() )
+      {
+        Handle(HYDROData_Object) aRefbject = 
+          Handle(HYDROData_Object)::DownCast( anIter.Value() );
+        if ( aRefbject.IsNull() )
+          continue;
+
+        QString aRefObjectName = aRefbject->GetName();
+        if ( aRefObjectName.isEmpty() )
+          continue;
+
+        aGeomObjectsNames.append( aRefObjectName );
+      }
+       
+      setFace( aZoneFace, false, false );
+      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) ) )
     {
       Handle(HYDROData_Image) anImageObj =
@@ -140,7 +188,8 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
       int aWidth = anImage.width();
       int aHeight = anImage.height();
 
-      anImage = anImage.transformed( aTrsf, Qt::SmoothTransformation );
+      QTransform anInversion = QTransform::fromScale( -1, -1 );
+      anImage = anImage.transformed( anInversion * aTrsf, Qt::SmoothTransformation );
 
       // temporary optimization, to reduce the saved image size (and the texture quality)
       QImage anImageToSave = reduceTexture( anImage, 500 );
@@ -440,7 +489,7 @@ void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor )
   }
 }
 
-QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Object)& theImageObj )
+QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj )
 {
   QString aResult;
   if( !theImageObj.IsNull() )