Salome HOME
refs #568: Land Cover: a draft of data model and implementation of dialog box and...
[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
29 const int BATH_HIGHLIGHT_MODE = 10;
30
31 HYDROGUI_BathymetryPrs::HYDROGUI_BathymetryPrs()
32 {
33   SetHilightMode( BATH_HIGHLIGHT_MODE );
34 }
35
36 HYDROGUI_BathymetryPrs::~HYDROGUI_BathymetryPrs()
37 {
38 }
39
40 void HYDROGUI_BathymetryPrs::SetPoints( const Handle(TColgp_HArray1OfPnt)&     theCoords,
41                                         const Handle(Quantity_HArray1OfColor)& theColors )
42 {
43   myBound.SetVoid();
44   if( !theCoords.IsNull() )
45   {
46     int aLower = theCoords->Lower();
47     int anUpper = theCoords->Upper();
48
49     for( int i = aLower; i <= anUpper; i++ )
50     {
51       if( i==aLower )
52         myBound.Set( theCoords->Value( i ) );
53       else
54       {
55         gp_Pnt aPnt = theCoords->Value( i );
56         myBound.Update( aPnt.X(), aPnt.Y(), aPnt.Z() );
57       }
58     }
59   }
60   AIS_PointCloud::SetPoints( theCoords, theColors );
61 }
62
63 void HYDROGUI_BathymetryPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
64                                       const Handle(Prs3d_Presentation)& thePresentation,
65                                       const Standard_Integer theMode )
66 {
67   if( theMode==BATH_HIGHLIGHT_MODE )
68   {
69     thePresentation->Clear();
70     if( myBound.IsVoid() || 
71         myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
72         myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
73         myBound.IsOpenZmin() || myBound.IsOpenZmax() )
74       return;
75
76     Standard_Real xmin, xmax, ymin, ymax, zmin, zmax;
77     myBound.Get( xmin, ymin, zmin, xmax, ymax, zmax );
78
79     Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
80     Handle(Prs3d_LineAspect) aWireAspect = new Prs3d_LineAspect( Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0 );
81     aGroup->SetPrimitivesAspect( aWireAspect->Aspect() );
82
83     Handle(Graphic3d_ArrayOfPolylines) aLines = new Graphic3d_ArrayOfPolylines( 18, 6 );
84     
85     aLines->AddBound( 5 );
86     aLines->AddVertex( xmin, ymin, zmin );
87     aLines->AddVertex( xmax, ymin, zmin );
88     aLines->AddVertex( xmax, ymax, zmin );
89     aLines->AddVertex( xmin, ymax, zmin );
90     aLines->AddVertex( xmin, ymin, zmin );
91     aLines->AddBound( 5 );
92     aLines->AddVertex( xmin, ymin, zmax );
93     aLines->AddVertex( xmax, ymin, zmax );
94     aLines->AddVertex( xmax, ymax, zmax );
95     aLines->AddVertex( xmin, ymax, zmax );
96     aLines->AddVertex( xmin, ymin, zmax );
97     aLines->AddBound( 2 );
98     aLines->AddVertex( xmin, ymin, zmin );
99     aLines->AddVertex( xmin, ymin, zmax );
100     aLines->AddBound( 2 );
101     aLines->AddVertex( xmax, ymin, zmin );
102     aLines->AddVertex( xmax, ymin, zmax );
103     aLines->AddBound( 2 );
104     aLines->AddVertex( xmax, ymax, zmin );
105     aLines->AddVertex( xmax, ymax, zmax );
106     aLines->AddBound( 2 );
107     aLines->AddVertex( xmin, ymax, zmin );
108     aLines->AddVertex( xmin, ymax, zmax );
109     aGroup->AddPrimitiveArray( aLines );
110   }
111   else
112     AIS_PointCloud::Compute( thePresentationManager, thePresentation, theMode );
113 }
114
115 void HYDROGUI_BathymetryPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
116                                                const Standard_Integer theMode )
117 {
118   if( theMode == 0 )
119   {
120     if( myBound.IsVoid() || 
121         myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
122         myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
123         myBound.IsOpenZmin() || myBound.IsOpenZmax() )
124       return;
125
126     Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner( this );
127     Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, myBound );
128     theSelection->Add( aSensitiveBox );
129   }
130 }