Salome HOME
refs #1278: by default objects in study are not expanded
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_BathymetryPrs.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <HYDROGUI_BathymetryPrs.h>
20 #include <Prs3d_Presentation.hxx>
21 #include <Prs3d_Root.hxx>
22 #include <Prs3d_LineAspect.hxx>
23 #include <SelectMgr_EntityOwner.hxx>
24 #include <SelectMgr_Selection.hxx>
25 #include <Select3D_SensitiveBox.hxx>
26 #include <Graphic3d_Group.hxx>
27 #include <Graphic3d_ArrayOfPolylines.hxx>
28 #include <Graphic3d_ArrayOfPoints.hxx>
29
30 const int BATH_HIGHLIGHT_MODE = 10;
31
32 HYDROGUI_BathymetryPrs::HYDROGUI_BathymetryPrs()
33 {
34   SetHilightMode( BATH_HIGHLIGHT_MODE );
35   SetAutoHilight( Standard_True );
36 }
37
38 HYDROGUI_BathymetryPrs::~HYDROGUI_BathymetryPrs()
39 {
40 }
41
42 void HYDROGUI_BathymetryPrs::UpdateBound()
43 {
44   Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
45   myBound.SetVoid();
46   if( !points.IsNull() )
47   {
48     int aLower = 1;
49     int anUpper = points->VertexNumber();
50
51     for( int i = aLower; i <= anUpper; i++ )
52     {
53       gp_Pnt p = points->Vertice( i );
54       if( i==aLower )
55         myBound.Set( p );
56       else
57         myBound.Update( p.X(), p.Y(), p.Z() );
58     }
59   }
60 }
61
62 void HYDROGUI_BathymetryPrs::SetPoints( const Handle(TColgp_HArray1OfPnt)&     theCoords,
63                                         const Handle(Quantity_HArray1OfColor)& theColors )
64 {
65   AIS_PointCloud::SetPoints( theCoords, theColors );
66   UpdateBound();
67 }
68
69 void HYDROGUI_BathymetryPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
70                                       const Handle(Prs3d_Presentation)& thePresentation,
71                                       const Standard_Integer theMode )
72 {
73   if( theMode==BATH_HIGHLIGHT_MODE )
74   {
75     thePresentation->Clear();
76     if( myBound.IsVoid() )
77       UpdateBound();
78
79     if( myBound.IsVoid() || 
80         myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
81         myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
82         myBound.IsOpenZmin() || myBound.IsOpenZmax() )
83       return;
84
85     Standard_Real xmin, xmax, ymin, ymax, zmin, zmax;
86     myBound.Get( xmin, ymin, zmin, xmax, ymax, zmax );
87
88     Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
89     Handle(Prs3d_LineAspect) aWireAspect = new Prs3d_LineAspect( Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0 );
90     aGroup->SetPrimitivesAspect( aWireAspect->Aspect() );
91
92     Handle(Graphic3d_ArrayOfPolylines) aLines = new Graphic3d_ArrayOfPolylines( 18, 6 );
93     
94     aLines->AddBound( 5 );
95     aLines->AddVertex( xmin, ymin, zmin );
96     aLines->AddVertex( xmax, ymin, zmin );
97     aLines->AddVertex( xmax, ymax, zmin );
98     aLines->AddVertex( xmin, ymax, zmin );
99     aLines->AddVertex( xmin, ymin, zmin );
100     aLines->AddBound( 5 );
101     aLines->AddVertex( xmin, ymin, zmax );
102     aLines->AddVertex( xmax, ymin, zmax );
103     aLines->AddVertex( xmax, ymax, zmax );
104     aLines->AddVertex( xmin, ymax, zmax );
105     aLines->AddVertex( xmin, ymin, zmax );
106     aLines->AddBound( 2 );
107     aLines->AddVertex( xmin, ymin, zmin );
108     aLines->AddVertex( xmin, ymin, zmax );
109     aLines->AddBound( 2 );
110     aLines->AddVertex( xmax, ymin, zmin );
111     aLines->AddVertex( xmax, ymin, zmax );
112     aLines->AddBound( 2 );
113     aLines->AddVertex( xmax, ymax, zmin );
114     aLines->AddVertex( xmax, ymax, zmax );
115     aLines->AddBound( 2 );
116     aLines->AddVertex( xmin, ymax, zmin );
117     aLines->AddVertex( xmin, ymax, zmax );
118     aGroup->AddPrimitiveArray( aLines );
119   }
120   else
121     AIS_PointCloud::Compute( thePresentationManager, thePresentation, theMode );
122 }
123
124 void HYDROGUI_BathymetryPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
125                                                const Standard_Integer theMode )
126 {
127   if( theMode == 0 )
128   {
129     if( myBound.IsVoid() )
130       UpdateBound();
131
132     if( myBound.IsVoid() || 
133         myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
134         myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
135         myBound.IsOpenZmin() || myBound.IsOpenZmax() )
136       return;
137
138     Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner( this );
139     Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, myBound );
140     theSelection->Add( aSensitiveBox );
141   }
142 }