Salome HOME
First implementation of automatic mode of regions creation in the calculation case...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_BathymetryPrs.cxx
1
2 #include <HYDROGUI_BathymetryPrs.h>
3 #include <Prs3d_Presentation.hxx>
4 #include <Prs3d_Root.hxx>
5 #include <Prs3d_LineAspect.hxx>
6 #include <SelectMgr_EntityOwner.hxx>
7 #include <SelectMgr_Selection.hxx>
8 #include <Select3D_SensitiveBox.hxx>
9 #include <Graphic3d_Group.hxx>
10 #include <Graphic3d_ArrayOfPolylines.hxx>
11
12 const int BATH_HIGHLIGHT_MODE = 10;
13
14 HYDROGUI_BathymetryPrs::HYDROGUI_BathymetryPrs()
15 {
16   SetHilightMode( BATH_HIGHLIGHT_MODE );
17 }
18
19 HYDROGUI_BathymetryPrs::~HYDROGUI_BathymetryPrs()
20 {
21 }
22
23 void HYDROGUI_BathymetryPrs::SetPoints( const Handle(TColgp_HArray1OfPnt)&     theCoords,
24                                         const Handle(Quantity_HArray1OfColor)& theColors )
25 {
26   myBound.SetVoid();
27   if( !theCoords.IsNull() )
28   {
29     int aLower = theCoords->Lower();
30     int anUpper = theCoords->Upper();
31
32     for( int i = aLower; i <= anUpper; i++ )
33     {
34       if( i==aLower )
35         myBound.Set( theCoords->Value( i ) );
36       else
37       {
38         gp_Pnt aPnt = theCoords->Value( i );
39         myBound.Update( aPnt.X(), aPnt.Y(), aPnt.Z() );
40       }
41     }
42   }
43   AIS_PointCloud::SetPoints( theCoords, theColors );
44 }
45
46 void HYDROGUI_BathymetryPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
47                                       const Handle(Prs3d_Presentation)& thePresentation,
48                                       const Standard_Integer theMode )
49 {
50   if( theMode==BATH_HIGHLIGHT_MODE )
51   {
52     thePresentation->Clear();
53     if( myBound.IsVoid() || 
54         myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
55         myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
56         myBound.IsOpenZmin() || myBound.IsOpenZmax() )
57       return;
58
59     Standard_Real xmin, xmax, ymin, ymax, zmin, zmax;
60     myBound.Get( xmin, ymin, zmin, xmax, ymax, zmax );
61
62     Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
63     Handle(Prs3d_LineAspect) aWireAspect = new Prs3d_LineAspect( Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0 );
64     aGroup->SetPrimitivesAspect( aWireAspect->Aspect() );
65
66     Handle(Graphic3d_ArrayOfPolylines) aLines = new Graphic3d_ArrayOfPolylines( 18, 6 );
67     
68     aLines->AddBound( 5 );
69     aLines->AddVertex( xmin, ymin, zmin );
70     aLines->AddVertex( xmax, ymin, zmin );
71     aLines->AddVertex( xmax, ymax, zmin );
72     aLines->AddVertex( xmin, ymax, zmin );
73     aLines->AddVertex( xmin, ymin, zmin );
74     aLines->AddBound( 5 );
75     aLines->AddVertex( xmin, ymin, zmax );
76     aLines->AddVertex( xmax, ymin, zmax );
77     aLines->AddVertex( xmax, ymax, zmax );
78     aLines->AddVertex( xmin, ymax, zmax );
79     aLines->AddVertex( xmin, ymin, zmax );
80     aLines->AddBound( 2 );
81     aLines->AddVertex( xmin, ymin, zmin );
82     aLines->AddVertex( xmin, ymin, zmax );
83     aLines->AddBound( 2 );
84     aLines->AddVertex( xmax, ymin, zmin );
85     aLines->AddVertex( xmax, ymin, zmax );
86     aLines->AddBound( 2 );
87     aLines->AddVertex( xmax, ymax, zmin );
88     aLines->AddVertex( xmax, ymax, zmax );
89     aLines->AddBound( 2 );
90     aLines->AddVertex( xmin, ymax, zmin );
91     aLines->AddVertex( xmin, ymax, zmax );
92     aGroup->AddPrimitiveArray( aLines );
93   }
94   else
95     AIS_PointCloud::Compute( thePresentationManager, thePresentation, theMode );
96 }
97
98 void HYDROGUI_BathymetryPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
99                                                const Standard_Integer theMode )
100 {
101   if( theMode == 0 )
102   {
103     if( myBound.IsVoid() || 
104         myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
105         myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
106         myBound.IsOpenZmin() || myBound.IsOpenZmax() )
107       return;
108
109     Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner( this );
110     Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, myBound );
111     theSelection->Add( aSensitiveBox );
112   }
113 }