#include <HYDROData_Iterator.h>
#include <HYDROData_Tool.h>
#include <AIS_DisplayMode.hxx>
-#include <BRepMesh_IncrementalMesh.hxx>
-#include <Graphic3d_ArrayOfTriangles.hxx>
-#include <Graphic3d_AspectFillArea3d.hxx>
-#include <Poly_Triangulation.hxx>
-#include <Prs3d_Root.hxx>
-#include <Select3D_SensitiveBox.hxx>
+#include <Prs3d_IsoAspect.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_InteractiveObject )
-IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_InteractiveObject )
+const Quantity_Color EDGES_COLOR = Quantity_NOC_SLATEGRAY;
+const int HILIGHT_ISO_NB = 10;
+
+IMPLEMENT_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape )
+IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape )
HYDROGUI_LandCoverMapPrs::HYDROGUI_LandCoverMapPrs( const Handle(HYDROData_LandCoverMap)& theMap )
- : AIS_InteractiveObject()
+ : AIS_ColoredShape( theMap->GetShape() )
{
SetLandCoverMap( theMap );
+ SetAutoHilight( Standard_False );
+ SetHilightAttributes( EDGES_COLOR );
}
HYDROGUI_LandCoverMapPrs::~HYDROGUI_LandCoverMapPrs()
void HYDROGUI_LandCoverMapPrs::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
{
myLCMap = theMap;
+ UpdateColors();
}
-Handle(Aspect_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const
+void HYDROGUI_LandCoverMapPrs::UpdateColors()
+{
+ SetMaterial( Graphic3d_NOM_PLASTIC );
+ 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();
+ QString aStricklerType = anIt.StricklerType();
+ Quantity_Color aColor = GetColor( aStricklerType );
+ SetCustomColor( aFace, aColor );
+ SetCustomWidth( aFace, 1.0 );
+ }
+ SetTransparency( myLCMap->GetTransparency() );
+}
+
+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;
+ if( myTable.IsNull() )
+ {
+ //TODO: go through all Strickler tables in the document to get the global range
+ }
+ else
+ myTable->GetCoefficientRange( aMin, aMax );
+
+ myColorScale->SetRange( aMin, aMax );
+ UpdateColors();
}
Handle(HYDROData_StricklerTable) HYDROGUI_LandCoverMapPrs::GetTable() const
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 = myTable->GetColor( theStricklerType );
- return HYDROData_Tool::toOccColor( aColor );
- }
- }
-
- return Quantity_Color();
-}
-
-void DrawTriangulation( const Handle(Prs3d_Presentation)& thePresentation,
- const Handle(Poly_Triangulation)& theTriangulation,
- const Quantity_Color& theColor )
-{
- const TColgp_Array1OfPnt& aNodesArray = theTriangulation->Nodes();
- int aNbNodes = aNodesArray.Length();
-
- const Poly_Array1OfTriangle& aTrianglesArray = theTriangulation->Triangles();
- int aNbTriangles = aTrianglesArray.Length();
-
- Handle( Graphic3d_ArrayOfTriangles ) anArray = new Graphic3d_ArrayOfTriangles
- ( aNbNodes, aNbTriangles * 3, Standard_True, Standard_True, Standard_False );
+ QColor aColor = HYDROData_Document::Document( myLCMap->Label())->GetAssociatedColor(theStricklerType, myTable);
- Prs3d_Root::NewGroup( thePresentation );
- Handle( Graphic3d_Group ) aGroup = Prs3d_Root::CurrentGroup( thePresentation );
- Handle( Graphic3d_AspectFillArea3d ) anAspect = new Graphic3d_AspectFillArea3d();
- Graphic3d_MaterialAspect aMaterialAspect( Graphic3d_NOM_PLASTIC );
- aMaterialAspect.SetColor( theColor );
- anAspect->SetFrontMaterial( aMaterialAspect );
- anAspect->SetBackMaterial( aMaterialAspect );
-
- Standard_Integer i;
-
- for( i = aNodesArray.Lower(); i <= aNodesArray.Upper(); i++ )
- {
- anArray->AddVertex( aNodesArray( i ), theColor );
- anArray->SetVertexNormal( i, 0, 0, 1 );
- }
-
- Standard_Integer anIndexTriangle[3] = { 0, 0, 0 };
- for( i = aTrianglesArray.Lower(); i<= aTrianglesArray.Upper(); i++ )
- {
- aTrianglesArray( i ).Get( anIndexTriangle[0], anIndexTriangle[1], anIndexTriangle[2] );
- anArray->AddEdge( anIndexTriangle[0] );
- anArray->AddEdge( anIndexTriangle[1] );
- anArray->AddEdge( anIndexTriangle[2] );
- }
- aGroup->AddPrimitiveArray( anArray );
- //aGroup->SetGroupPrimitivesAspect( anAspect );
+ if (aColor.isValid())
+ return HYDROData_Tool::toOccColor(aColor);
+ else
+ return Quantity_Color();
}
void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer theMode )
{
- if( myLCMap.IsNull() )
- return;
-
thePresentation->Clear();
- const double aLinearDeflection = 1E-2;
- BRepMesh_IncrementalMesh aMesh( myLCMap->GetShape(), aLinearDeflection );
- aMesh.Perform();
- bool isOK = aMesh.IsDone();
+
+ myDrawer->UIsoAspect()->SetNumber( 0 );
+ myDrawer->VIsoAspect()->SetNumber( 0 );
+ myDrawer->LineAspect()->SetColor( EDGES_COLOR );
+ myDrawer->FaceBoundaryAspect()->SetColor( EDGES_COLOR );
+ myDrawer->FreeBoundaryAspect()->SetColor( EDGES_COLOR );
switch( theMode )
{
+ case AIS_WireFrame:
case AIS_Shaded:
- {
- HYDROData_LandCoverMap::Iterator anIt( myLCMap );
- for( ; anIt.More(); anIt.Next() )
- {
- TopoDS_Face aFace = anIt.Face();
- QString aStricklerType = anIt.StricklerType();
- Quantity_Color aColor = GetColor( aStricklerType );
-
- TopLoc_Location aLocation;
- Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation( aFace, aLocation );
- DrawTriangulation( thePresentation, aTriangulation, aColor );
- }
- }
- break;
- default:
+ AIS_ColoredShape::Compute( thePresentationManager, thePresentation, theMode );
break;
}
+
+ if( theMode==AIS_Shaded )
+ StdPrs_WFShape::Add( thePresentation, Shape(), myDrawer );
}
-void HYDROGUI_LandCoverMapPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
- const Standard_Integer theMode )
+void HYDROGUI_LandCoverMapPrs::HilightSelected( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const SelectMgr_SequenceOfOwner& theOwners )
{
- if( myLCMap.IsNull() )
- return;
+ Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( thePresentationManager );
- if( theMode==0 )
- {
- /*theSelection->Clear();
- Bnd_Box B = BoundingBox();
- Handle(StdSelect_BRepOwner) anOwner = new StdSelect_BRepOwner( myLCMap->GetShape(), this );
- Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, B );
- theSelection->Add( aSensitiveBox );*/
- }
- else
+ SetHilightAttributes( EDGES_COLOR );
+
+ for( int i=1, n=theOwners.Length(); i<=n; i++ )
{
- //TODO
+ 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 )
+{
+ 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 );
}