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