Salome HOME
refs #1832
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_LandCoverMapPrs.cxx
index 7a005c24d78239fa2239ed0aa267268c984cffd7..7888166a154e4fa55f84f2b97dc2b4e50d9edbe9 100644 (file)
 #include <HYDROData_Tool.h>
 #include <AIS_DisplayMode.hxx>
 #include <Prs3d_IsoAspect.hxx>
-#include <StdPrs_WFDeflectionShape.hxx>
+#include <SelectMgr_SequenceOfOwner.hxx>
+#include <StdPrs_WFShape.hxx>
+#include <StdSelect_BRepOwner.hxx>
 #include <TopoDS_Face.hxx>
 #include <QColor>
 #include <QString>
 
-IMPLEMENT_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape )
+const Quantity_Color EDGES_COLOR = Quantity_NOC_SLATEGRAY;
+const int HILIGHT_ISO_NB = 10;
+
 IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape )
 
 HYDROGUI_LandCoverMapPrs::HYDROGUI_LandCoverMapPrs( const Handle(HYDROData_LandCoverMap)& theMap )
   : AIS_ColoredShape( theMap->GetShape() )
 {
   SetLandCoverMap( theMap );
+  SetAutoHilight( Standard_False );
+  SetHilightAttributes( EDGES_COLOR );
 }
 
 HYDROGUI_LandCoverMapPrs::~HYDROGUI_LandCoverMapPrs()
@@ -52,9 +58,15 @@ void HYDROGUI_LandCoverMapPrs::SetLandCoverMap( const Handle(HYDROData_LandCover
 
 void HYDROGUI_LandCoverMapPrs::UpdateColors()
 {
-  Set( myLCMap->GetShape() );
   SetMaterial( Graphic3d_NOM_PLASTIC );
-  HYDROData_LandCoverMap::Iterator anIt( myLCMap );
+  if( myLCMap.IsNull() )
+  {
+    Set( TopoDS_Shape() );
+    return;
+  }
+  
+  Set( myLCMap->GetShape() );
+  HYDROData_LandCoverMap::Explorer anIt( myLCMap );
   for( ; anIt.More(); anIt.Next() )
   {
     TopoDS_Face aFace = anIt.Face();
@@ -62,15 +74,16 @@ void HYDROGUI_LandCoverMapPrs::UpdateColors()
     Quantity_Color aColor = GetColor( aStricklerType );
     SetCustomColor( aFace, aColor );
     SetCustomWidth( aFace, 1.0 );
-  }
+  } 
+  SetTransparency( myLCMap->GetTransparency() );
 }
 
-Handle(Aspect_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const
+Handle(AIS_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const
 {
   return myColorScale;
 }
 
-void HYDROGUI_LandCoverMapPrs::SetColorScale( const Handle(Aspect_ColorScale)& theColorScale )
+void HYDROGUI_LandCoverMapPrs::SetColorScale( const Handle(AIS_ColorScale)& theColorScale )
 {
   myColorScale = theColorScale;
   double aMin = 0, aMax = 0;
@@ -109,24 +122,12 @@ Quantity_Color HYDROGUI_LandCoverMapPrs::GetColor( const QString& theStricklerTy
       return Quantity_Color();
   }
 
-  if( !myTable.IsNull() && myTable->HasType( theStricklerType ) )
-  {
-    QColor aColor = myTable->GetColor( theStricklerType );
-    return HYDROData_Tool::toOccColor( aColor );
-  }
-
-  HYDROData_Iterator anIt( HYDROData_Document::Document( myLCMap->Label() ), KIND_STRICKLER_TABLE );
-  for( ; anIt.More(); anIt.Next() )
-  {
-    Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
-    if( aTable->HasType( theStricklerType ) )
-    {
-      QColor aColor = aTable->GetColor( theStricklerType );
-      return HYDROData_Tool::toOccColor( aColor );
-    }
-  }
+  QColor aColor = HYDROData_Document::Document( myLCMap->Label())->GetAssociatedColor(theStricklerType, myTable);
 
-  return Quantity_Color();
+  if (aColor.isValid())
+    return HYDROData_Tool::toOccColor(aColor);
+  else
+    return Quantity_Color();
 }
 
 void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
@@ -135,13 +136,11 @@ void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3
 {
   thePresentation->Clear();
 
-  Quantity_Color anEdgeColor = Quantity_NOC_WHITE;
-
   myDrawer->UIsoAspect()->SetNumber( 0 );
   myDrawer->VIsoAspect()->SetNumber( 0 );
-  myDrawer->LineAspect()->SetColor( anEdgeColor );
-  myDrawer->FaceBoundaryAspect()->SetColor( anEdgeColor );
-  myDrawer->FreeBoundaryAspect()->SetColor( anEdgeColor );
+  myDrawer->LineAspect()->SetColor( EDGES_COLOR );
+  myDrawer->FaceBoundaryAspect()->SetColor( EDGES_COLOR );
+  myDrawer->FreeBoundaryAspect()->SetColor( EDGES_COLOR );
 
   switch( theMode )
   {
@@ -152,6 +151,39 @@ void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3
   }
 
   if( theMode==AIS_Shaded )
-    StdPrs_WFDeflectionShape::Add( thePresentation, Shape(), myDrawer );
+    StdPrs_WFShape::Add( thePresentation, Shape(), myDrawer );
+}
+
+void HYDROGUI_LandCoverMapPrs::HilightSelected( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+                                                const SelectMgr_SequenceOfOwner& theOwners )
+{
+  Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( thePresentationManager );
+
+  SetHilightAttributes( EDGES_COLOR );
+
+  for( int i=1, n=theOwners.Length(); i<=n; i++ )
+  {
+    Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast( theOwners.Value( i ) );
+    if( !anOwner.IsNull() )
+      StdPrs_WFShape::Add( aSelectPrs, anOwner->Shape(), HilightAttributes() );
+  }
+
+  HilightAttributes()->UIsoAspect()->SetNumber( 0 );
+  HilightAttributes()->VIsoAspect()->SetNumber( 0 );
+
+  aSelectPrs->SetDisplayPriority( 9 );
+  aSelectPrs->Display();
 }
 
+void HYDROGUI_LandCoverMapPrs::SetHilightAttributes( const Quantity_Color& theEdgesColor )
+{
+  if (HilightAttributes().IsNull())
+    AIS_ColoredShape::SetHilightAttributes(new Prs3d_Drawer());
+  HilightAttributes()->UIsoAspect()->SetNumber( HILIGHT_ISO_NB );
+  HilightAttributes()->UIsoAspect()->SetColor( theEdgesColor );
+  HilightAttributes()->VIsoAspect()->SetNumber( HILIGHT_ISO_NB );
+  HilightAttributes()->VIsoAspect()->SetColor( theEdgesColor );
+  HilightAttributes()->LineAspect()->SetColor( theEdgesColor );
+  HilightAttributes()->FaceBoundaryAspect()->SetColor( theEdgesColor );
+  HilightAttributes()->FreeBoundaryAspect()->SetColor( theEdgesColor );
+}