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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <HYDROGUI_BathymetryPrs.h>
20 #include <Prs3d_Root.hxx>
21 #include <Prs3d_LineAspect.hxx>
22 #include <Prs3d_Text.hxx>
23 #include <Prs3d_TextAspect.hxx>
24 #include <Select3D_SensitiveBox.hxx>
25 #include <Select3D_SensitivePoint.hxx>
26 #include <Graphic3d_ArrayOfPolylines.hxx>
27 #include <Graphic3d_ArrayOfPoints.hxx>
29 const int BATH_HIGHLIGHT_MODE = 10;
31 HYDROGUI_BathymetryPrs::HYDROGUI_BathymetryPrs( const HYDROGUI_ShapeBathymetry* theShape )
34 SetHilightMode( BATH_HIGHLIGHT_MODE );
35 SetAutoHilight( Standard_True );
38 HYDROGUI_BathymetryPrs::~HYDROGUI_BathymetryPrs()
42 HYDROGUI_ShapeBathymetry* HYDROGUI_BathymetryPrs::GetShape() const
44 return const_cast<HYDROGUI_ShapeBathymetry*>( myShape );
47 void HYDROGUI_BathymetryPrs::UpdateBound()
49 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
51 if( !points.IsNull() )
54 int anUpper = points->VertexNumber();
56 for( int i = aLower; i <= anUpper; i++ )
58 gp_Pnt p = points->Vertice( i );
62 myBound.Update( p.X(), p.Y(), p.Z() );
67 void HYDROGUI_BathymetryPrs::SetPoints( const Handle(TColgp_HArray1OfPnt)& theCoords,
68 const Handle(Quantity_HArray1OfColor)& theColors )
70 AIS_PointCloud::SetPoints( theCoords, theColors );
74 void HYDROGUI_BathymetryPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
75 const Handle(Prs3d_Presentation)& thePresentation,
76 const Standard_Integer theMode )
78 thePresentation->Clear();
79 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
81 if( theMode==BATH_HIGHLIGHT_MODE )
83 if( myBound.IsVoid() )
87 if( myBound.IsVoid() ||
88 myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
89 myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
90 myBound.IsOpenZmin() || myBound.IsOpenZmax() )
93 Standard_Real xmin, xmax, ymin, ymax, zmin, zmax;
94 myBound.Get( xmin, ymin, zmin, xmax, ymax, zmax );
96 Handle(Prs3d_LineAspect) aWireAspect = new Prs3d_LineAspect( Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0 );
97 aGroup->SetPrimitivesAspect( aWireAspect->Aspect() );
99 Handle(Graphic3d_ArrayOfPolylines) aLines = new Graphic3d_ArrayOfPolylines( 18, 6 );
101 aLines->AddBound( 5 );
102 aLines->AddVertex( xmin, ymin, zmin );
103 aLines->AddVertex( xmax, ymin, zmin );
104 aLines->AddVertex( xmax, ymax, zmin );
105 aLines->AddVertex( xmin, ymax, zmin );
106 aLines->AddVertex( xmin, ymin, zmin );
107 aLines->AddBound( 5 );
108 aLines->AddVertex( xmin, ymin, zmax );
109 aLines->AddVertex( xmax, ymin, zmax );
110 aLines->AddVertex( xmax, ymax, zmax );
111 aLines->AddVertex( xmin, ymax, zmax );
112 aLines->AddVertex( xmin, ymin, zmax );
113 aLines->AddBound( 2 );
114 aLines->AddVertex( xmin, ymin, zmin );
115 aLines->AddVertex( xmin, ymin, zmax );
116 aLines->AddBound( 2 );
117 aLines->AddVertex( xmax, ymin, zmin );
118 aLines->AddVertex( xmax, ymin, zmax );
119 aLines->AddBound( 2 );
120 aLines->AddVertex( xmax, ymax, zmin );
121 aLines->AddVertex( xmax, ymax, zmax );
122 aLines->AddBound( 2 );
123 aLines->AddVertex( xmin, ymax, zmin );
124 aLines->AddVertex( xmin, ymax, zmax );
125 aGroup->AddPrimitiveArray( aLines );
129 AIS_PointCloud::Compute( thePresentationManager, thePresentation, theMode );
131 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
132 if( !myTextIndices.empty() && !points.IsNull() )
135 Handle(Prs3d_TextAspect) anAspect = new Prs3d_TextAspect();
137 foreach( int index, myTextIndices )
139 gp_Pnt p = points->Vertice( index );
140 sprintf( aBuf, "%.2f", p.Z() );
141 Prs3d_Text::Draw( aGroup, anAspect, aBuf, p );
147 void HYDROGUI_BathymetryPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
148 const Standard_Integer theMode )
152 if( myBound.IsVoid() )
155 if( myBound.IsVoid() ||
156 myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
157 myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
158 myBound.IsOpenZmin() || myBound.IsOpenZmax() )
161 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner( this );
162 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, myBound );
163 theSelection->Add( aSensitiveBox );
167 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
168 int n = points.IsNull() ? 0 : points->VertexNumber();
169 for( int i=1; i<=n; i++ )
171 gp_Pnt p = points->Vertice( i );
172 Handle(HYDROGUI_BathymetryPointOwner) anOwner = new HYDROGUI_BathymetryPointOwner( this, i );
173 Handle(Select3D_SensitivePoint) aSensitivePoint = new Select3D_SensitivePoint( anOwner, p );
174 theSelection->Add( aSensitivePoint );
179 int HYDROGUI_BathymetryPrs::NbPoints() const
181 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
182 int n = points.IsNull() ? 0 : points->VertexNumber();
186 gp_Pnt HYDROGUI_BathymetryPrs::GetPoint( int theIndex ) const
188 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
189 if( points.IsNull() )
192 return points->Vertice( theIndex );
195 void HYDROGUI_BathymetryPrs::AddPoint( const Handle(Graphic3d_ArrayOfPoints)& thePoints,
196 const Handle(SelectMgr_EntityOwner)& theOwner )
198 Handle(HYDROGUI_BathymetryPointOwner) anOwner = Handle(HYDROGUI_BathymetryPointOwner)::DownCast( theOwner );
199 if( anOwner.IsNull() )
201 gp_Pnt p = GetPoint( anOwner->GetIndex() );
202 thePoints->AddVertex( p );
205 void HYDROGUI_BathymetryPrs::HilightOwnerWithColor( const Handle(PrsMgr_PresentationManager3d)& thePM,
206 const Handle(Graphic3d_HighlightStyle)& theColor,
207 const Handle(SelectMgr_EntityOwner)& theOwner )
209 Handle(Prs3d_Presentation) aHilightPrs = GetHilightPresentation( thePM );
210 aHilightPrs->SetZLayer( Graphic3d_ZLayerId_Topmost );
211 aHilightPrs->Clear();
212 Handle(Graphic3d_ArrayOfPoints) points = new Graphic3d_ArrayOfPoints( 1 );
213 AddPoint( points, theOwner );
215 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aHilightPrs );
216 Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_X, Quantity_NOC_WHITE, 1.0 );
217 aGroup->SetGroupPrimitivesAspect( anAspect );
218 aGroup->AddPrimitiveArray( points );
220 if( thePM->IsImmediateModeOn() )
221 thePM->AddToImmediateList( aHilightPrs );
224 void HYDROGUI_BathymetryPrs::HilightSelected( const Handle(PrsMgr_PresentationManager3d)& thePM,
225 const SelectMgr_SequenceOfOwner& theOwners )
227 Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( thePM );
228 aSelectPrs->SetZLayer( Graphic3d_ZLayerId_Topmost );
231 Handle(Graphic3d_ArrayOfPoints) points = new Graphic3d_ArrayOfPoints( theOwners.Size() );
232 for( int i=theOwners.Lower(); i<=theOwners.Upper(); i++ )
233 AddPoint( points, theOwners.Value( i ) );
235 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aSelectPrs );
236 Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_X, Quantity_NOC_WHITE, 1.0 );
237 aGroup->SetGroupPrimitivesAspect( anAspect );
238 aGroup->AddPrimitiveArray( points );
240 aSelectPrs->SetDisplayPriority(9);
241 aSelectPrs->Display();
244 void HYDROGUI_BathymetryPrs::ClearSelected()
246 Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( NULL );
247 if( !aSelectPrs.IsNull() )
251 void HYDROGUI_BathymetryPrs::SetTextLabels( const QList<int>& theTextIndices )
253 myTextIndices = theTextIndices;
262 HYDROGUI_BathymetryPointOwner::HYDROGUI_BathymetryPointOwner
263 ( const Handle(HYDROGUI_BathymetryPrs)& theBathymetry, int theIndex )
264 : SelectMgr_EntityOwner( Handle(SelectMgr_SelectableObject)::DownCast( theBathymetry ), 0 ),
269 HYDROGUI_BathymetryPointOwner::~HYDROGUI_BathymetryPointOwner()
273 Standard_Boolean HYDROGUI_BathymetryPointOwner::IsAutoHilight() const
275 return Standard_False;
278 int HYDROGUI_BathymetryPointOwner::GetIndex() const