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 <HYDROGUI_Tool.h>
22 #include <Prs3d_Root.hxx>
23 #include <Prs3d_LineAspect.hxx>
24 #include <Prs3d_Text.hxx>
25 #include <Prs3d_TextAspect.hxx>
26 #include <Select3D_SensitiveBox.hxx>
27 #include <Select3D_SensitivePoint.hxx>
28 #include <Graphic3d_ArrayOfPolylines.hxx>
29 #include <Graphic3d_ArrayOfPoints.hxx>
30 #include <Image_PixMap.hxx>
31 #include <Graphic3d_MarkerImage.hxx>
35 const int BATH_HIGHLIGHT_MODE = 10;
37 HYDROGUI_BathymetryPrs::HYDROGUI_BathymetryPrs( const HYDROGUI_ShapeBathymetry* theShape )
40 SetHilightMode( BATH_HIGHLIGHT_MODE );
41 SetAutoHilight( Standard_True );
44 HYDROGUI_BathymetryPrs::~HYDROGUI_BathymetryPrs()
48 HYDROGUI_ShapeBathymetry* HYDROGUI_BathymetryPrs::GetShape() const
50 return const_cast<HYDROGUI_ShapeBathymetry*>( myShape );
53 void HYDROGUI_BathymetryPrs::UpdateBound()
55 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
57 if( !points.IsNull() )
60 int anUpper = points->VertexNumber();
62 for( int i = aLower; i <= anUpper; i++ )
64 gp_Pnt p = points->Vertice( i );
68 myBound.Update( p.X(), p.Y(), p.Z() );
73 void HYDROGUI_BathymetryPrs::SetPoints( const Handle(TColgp_HArray1OfPnt)& theCoords,
74 const Handle(Quantity_HArray1OfColor)& theColors )
76 AIS_PointCloud::SetPoints( theCoords, theColors );
80 void HYDROGUI_BathymetryPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
81 const Handle(Prs3d_Presentation)& thePresentation,
82 const Standard_Integer theMode )
84 thePresentation->Clear();
85 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
87 if( theMode==BATH_HIGHLIGHT_MODE )
89 if( myBound.IsVoid() )
93 if( myBound.IsVoid() ||
94 myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
95 myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
96 myBound.IsOpenZmin() || myBound.IsOpenZmax() )
99 Standard_Real xmin, xmax, ymin, ymax, zmin, zmax;
100 myBound.Get( xmin, ymin, zmin, xmax, ymax, zmax );
102 Handle(Prs3d_LineAspect) aWireAspect = new Prs3d_LineAspect( Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0 );
103 aGroup->SetPrimitivesAspect( aWireAspect->Aspect() );
105 Handle(Graphic3d_ArrayOfPolylines) aLines = new Graphic3d_ArrayOfPolylines( 18, 6 );
107 aLines->AddBound( 5 );
108 aLines->AddVertex( xmin, ymin, zmin );
109 aLines->AddVertex( xmax, ymin, zmin );
110 aLines->AddVertex( xmax, ymax, zmin );
111 aLines->AddVertex( xmin, ymax, zmin );
112 aLines->AddVertex( xmin, ymin, zmin );
113 aLines->AddBound( 5 );
114 aLines->AddVertex( xmin, ymin, zmax );
115 aLines->AddVertex( xmax, ymin, zmax );
116 aLines->AddVertex( xmax, ymax, zmax );
117 aLines->AddVertex( xmin, ymax, zmax );
118 aLines->AddVertex( xmin, ymin, zmax );
119 aLines->AddBound( 2 );
120 aLines->AddVertex( xmin, ymin, zmin );
121 aLines->AddVertex( xmin, ymin, zmax );
122 aLines->AddBound( 2 );
123 aLines->AddVertex( xmax, ymin, zmin );
124 aLines->AddVertex( xmax, ymin, zmax );
125 aLines->AddBound( 2 );
126 aLines->AddVertex( xmax, ymax, zmin );
127 aLines->AddVertex( xmax, ymax, zmax );
128 aLines->AddBound( 2 );
129 aLines->AddVertex( xmin, ymax, zmin );
130 aLines->AddVertex( xmin, ymax, zmax );
131 aGroup->AddPrimitiveArray( aLines );
135 Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_USERDEFINED, Quantity_NOC_WHITE, 1.0 );
136 QImage qtMark( 4, 4, QImage::Format_RGB888 );
137 Handle(Image_PixMap) aMark = HYDROGUI_Tool::Pixmap( qtMark );
138 Handle(Graphic3d_MarkerImage) gMark = new Graphic3d_MarkerImage(aMark);
139 anAspect->SetMarkerImage(gMark);
140 AIS_PointCloud::Compute( thePresentationManager, thePresentation, theMode );
141 aGroup->SetGroupPrimitivesAspect( anAspect );
143 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
144 if( !myTextIndices.empty() && !points.IsNull() )
147 Handle(Prs3d_TextAspect) anAspect = new Prs3d_TextAspect();
149 foreach( int index, myTextIndices )
151 gp_Pnt p = points->Vertice( index );
152 sprintf( aBuf, "%.2f", p.Z() );
153 Prs3d_Text::Draw( aGroup, anAspect, aBuf, p );
159 void HYDROGUI_BathymetryPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
160 const Standard_Integer theMode )
164 if( myBound.IsVoid() )
167 if( myBound.IsVoid() ||
168 myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
169 myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
170 myBound.IsOpenZmin() || myBound.IsOpenZmax() )
173 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner( this );
174 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, myBound );
175 theSelection->Add( aSensitiveBox );
179 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
180 int n = points.IsNull() ? 0 : points->VertexNumber();
181 for( int i=1; i<=n; i++ )
183 gp_Pnt p = points->Vertice( i );
184 Handle(HYDROGUI_BathymetryPointOwner) anOwner = new HYDROGUI_BathymetryPointOwner( this, i );
185 Handle(Select3D_SensitivePoint) aSensitivePoint = new Select3D_SensitivePoint( anOwner, p );
186 theSelection->Add( aSensitivePoint );
191 int HYDROGUI_BathymetryPrs::NbPoints() const
193 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
194 int n = points.IsNull() ? 0 : points->VertexNumber();
198 gp_Pnt HYDROGUI_BathymetryPrs::GetPoint( int theIndex ) const
200 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
201 if( points.IsNull() )
204 return points->Vertice( theIndex );
207 void HYDROGUI_BathymetryPrs::AddPoint( const Handle(Graphic3d_ArrayOfPoints)& thePoints,
208 const Handle(SelectMgr_EntityOwner)& theOwner )
210 Handle(HYDROGUI_BathymetryPointOwner) anOwner = Handle(HYDROGUI_BathymetryPointOwner)::DownCast( theOwner );
211 if( anOwner.IsNull() )
213 gp_Pnt p = GetPoint( anOwner->GetIndex() );
214 thePoints->AddVertex( p );
217 void HYDROGUI_BathymetryPrs::HilightOwnerWithColor( const Handle(PrsMgr_PresentationManager3d)& thePM,
218 const Handle(Graphic3d_HighlightStyle)& theColor,
219 const Handle(SelectMgr_EntityOwner)& theOwner )
221 Handle(Prs3d_Presentation) aHilightPrs = GetHilightPresentation( thePM );
222 aHilightPrs->SetZLayer( Graphic3d_ZLayerId_Topmost );
223 aHilightPrs->Clear();
224 Handle(Graphic3d_ArrayOfPoints) points = new Graphic3d_ArrayOfPoints( 1 );
225 AddPoint( points, theOwner );
227 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aHilightPrs );
228 Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_X, Quantity_NOC_WHITE, 1.0 );
229 aGroup->SetGroupPrimitivesAspect( anAspect );
230 aGroup->AddPrimitiveArray( points );
232 if( thePM->IsImmediateModeOn() )
233 thePM->AddToImmediateList( aHilightPrs );
236 void HYDROGUI_BathymetryPrs::HilightSelected( const Handle(PrsMgr_PresentationManager3d)& thePM,
237 const SelectMgr_SequenceOfOwner& theOwners )
239 Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( thePM );
240 aSelectPrs->SetZLayer( Graphic3d_ZLayerId_Topmost );
243 Handle(Graphic3d_ArrayOfPoints) points = new Graphic3d_ArrayOfPoints( theOwners.Size() );
244 for( int i=theOwners.Lower(); i<=theOwners.Upper(); i++ )
245 AddPoint( points, theOwners.Value( i ) );
247 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aSelectPrs );
248 Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_X, Quantity_NOC_WHITE, 1.0 );
249 aGroup->SetGroupPrimitivesAspect( anAspect );
250 aGroup->AddPrimitiveArray( points );
252 aSelectPrs->SetDisplayPriority(9);
253 aSelectPrs->Display();
256 void HYDROGUI_BathymetryPrs::ClearSelected()
258 Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( NULL );
259 if( !aSelectPrs.IsNull() )
263 void HYDROGUI_BathymetryPrs::SetTextLabels( const QVector<int>& theTextIndices )
265 myTextIndices = theTextIndices;
274 HYDROGUI_BathymetryPointOwner::HYDROGUI_BathymetryPointOwner
275 ( const Handle(HYDROGUI_BathymetryPrs)& theBathymetry, int theIndex )
276 : SelectMgr_EntityOwner( Handle(SelectMgr_SelectableObject)::DownCast( theBathymetry ), 0 ),
281 HYDROGUI_BathymetryPointOwner::~HYDROGUI_BathymetryPointOwner()
285 Standard_Boolean HYDROGUI_BathymetryPointOwner::IsAutoHilight() const
287 return Standard_False;
290 int HYDROGUI_BathymetryPointOwner::GetIndex() const