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_ShapeBathymetry.h>
21 #include <HYDROGUI_Tool.h>
23 #include <Prs3d_Root.hxx>
24 #include <Prs3d_LineAspect.hxx>
25 #include <Prs3d_Text.hxx>
26 #include <Prs3d_TextAspect.hxx>
27 #include <Select3D_SensitiveBox.hxx>
28 #include <Select3D_SensitivePoint.hxx>
29 #include <Graphic3d_ArrayOfPolylines.hxx>
30 #include <Graphic3d_ArrayOfPoints.hxx>
31 #include <Image_PixMap.hxx>
32 #include <Graphic3d_MarkerImage.hxx>
33 #include <TColStd_HPackedMapOfInteger.hxx>
34 #include <TColStd_PackedMapOfInteger.hxx>
41 #include "HYDRO_trace.hxx"
43 const int BATH_HIGHLIGHT_MODE = 10;
45 HYDROGUI_BathymetryPrs::HYDROGUI_BathymetryPrs( const HYDROGUI_ShapeBathymetry* theShape )
48 DEBTRACE("HYDROGUI_BathymetryPrs");
49 SetHilightMode( BATH_HIGHLIGHT_MODE );
50 SetAutoHilight( Standard_True );
53 HYDROGUI_BathymetryPrs::~HYDROGUI_BathymetryPrs()
57 HYDROGUI_ShapeBathymetry* HYDROGUI_BathymetryPrs::GetShape() const
59 return const_cast<HYDROGUI_ShapeBathymetry*>( myShape );
62 void HYDROGUI_BathymetryPrs::UpdateBound()
64 DEBTRACE("UpdateBound");
65 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
67 if( !points.IsNull() )
70 int anUpper = points->VertexNumber();
72 for( int i = aLower; i <= anUpper; i++ )
74 gp_Pnt p = points->Vertice( i );
78 myBound.Update( p.X(), p.Y(), p.Z() );
83 void HYDROGUI_BathymetryPrs::SetPoints( const Handle(TColgp_HArray1OfPnt)& theCoords,
84 const Handle(Quantity_HArray1OfColor)& theColors,
85 const Handle(TColgp_HArray1OfDir)& theNormals )
87 AIS_PointCloud::SetPoints( theCoords, theColors, theNormals );
91 void HYDROGUI_BathymetryPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
92 const Handle(Prs3d_Presentation)& thePresentation,
93 const Standard_Integer theMode )
95 DEBTRACE("Compute " << theMode);
96 // thePresentation->Clear();
97 // Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
99 if( theMode== BATH_HIGHLIGHT_MODE ) // highlight ==> draw bounding box
101 AIS_PointCloud::Compute( thePresentationManager, thePresentation, AIS_PointCloud::DM_BndBox );
102 // if( myBound.IsVoid() )
105 // if( myBound.IsVoid() ||
106 // myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
107 // myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
108 // myBound.IsOpenZmin() || myBound.IsOpenZmax() )
111 // Standard_Real xmin, xmax, ymin, ymax, zmin, zmax;
112 // myBound.Get( xmin, ymin, zmin, xmax, ymax, zmax );
114 // Handle(Prs3d_LineAspect) aWireAspect = new Prs3d_LineAspect( Quantity_NOC_RED, Aspect_TOL_DASH, 4.0 );
115 // aGroup->SetPrimitivesAspect( aWireAspect->Aspect() ); // use Aspect_TOL_DASH to find the group by the aspect style
117 // Handle(Graphic3d_ArrayOfPolylines) aLines = new Graphic3d_ArrayOfPolylines( 18, 6 );
119 // aLines->AddBound( 5 );
120 // aLines->AddVertex( xmin, ymin, zmin );
121 // aLines->AddVertex( xmax, ymin, zmin );
122 // aLines->AddVertex( xmax, ymax, zmin );
123 // aLines->AddVertex( xmin, ymax, zmin );
124 // aLines->AddVertex( xmin, ymin, zmin );
125 // aLines->AddBound( 5 );
126 // aLines->AddVertex( xmin, ymin, zmax );
127 // aLines->AddVertex( xmax, ymin, zmax );
128 // aLines->AddVertex( xmax, ymax, zmax );
129 // aLines->AddVertex( xmin, ymax, zmax );
130 // aLines->AddVertex( xmin, ymin, zmax );
131 // aLines->AddBound( 2 );
132 // aLines->AddVertex( xmin, ymin, zmin );
133 // aLines->AddVertex( xmin, ymin, zmax );
134 // aLines->AddBound( 2 );
135 // aLines->AddVertex( xmax, ymin, zmin );
136 // aLines->AddVertex( xmax, ymin, zmax );
137 // aLines->AddBound( 2 );
138 // aLines->AddVertex( xmax, ymax, zmin );
139 // aLines->AddVertex( xmax, ymax, zmax );
140 // aLines->AddBound( 2 );
141 // aLines->AddVertex( xmin, ymax, zmin );
142 // aLines->AddVertex( xmin, ymax, zmax );
143 // aGroup->AddPrimitiveArray( aLines );
145 else if (theMode == 0)
147 DEBTRACE("non highlight mode"); // display the nodes as points with color (HYDROGUI_ShapeBathymetry::UpdateWithColorScale)
148 AIS_PointCloud::Compute( thePresentationManager, thePresentation, AIS_PointCloud::DM_Points );
150 QImage qtMark( 4, 4, QImage::Format_RGB888 ); // points marks as 4x4 rectangles
151 Handle(Image_PixMap) aMark = HYDROGUI_Tool::Pixmap( qtMark );
152 DEBTRACE("pnt dims " << aMark->SizeX() << " " << aMark->SizeY());
153 Handle(Graphic3d_MarkerImage) gMark = new Graphic3d_MarkerImage(aMark);
154 Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_USERDEFINED, Quantity_NOC_WHITE, 1.0 );
155 anAspect->SetMarkerImage(gMark);
157 DEBTRACE("nb groups " << thePresentation->NumberOfGroups()); // find the group corresponding to the points, change the aspect
158 const Graphic3d_SequenceOfGroup& grps = thePresentation->Groups();
159 Graphic3d_SequenceOfGroup::Iterator anIter( grps );
160 for ( ; anIter.More(); anIter.Next() )
162 Handle(Graphic3d_Group) aGrp = anIter.Value();
163 DEBTRACE("grp type: " << aGrp->get_type_name());
164 Handle(Graphic3d_Aspects) asp = aGrp->Aspects();
167 DEBTRACE("aspect: " << asp->get_type_name());
168 DEBTRACE("asp->LineType() " << asp->LineType());
169 if (asp->LineType() != Aspect_TOL_DASH) // find the group which does not correspond to the bounding box
170 aGrp->SetGroupPrimitivesAspect( anAspect );
174 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
175 if (!points.IsNull())
176 DEBTRACE("nb points " << points->ItemNumber());
178 if( !myTextIndices.empty() && !points.IsNull() ) // points selected ==> altitude labels
180 DEBTRACE("myTextIndices.size() " << myTextIndices.size());
182 Handle(Prs3d_TextAspect) anAspect = new Prs3d_TextAspect();
184 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
185 foreach( int index, myTextIndices )
187 gp_Pnt p = points->Vertice( index );
188 sprintf( aBuf, "%.2f", p.Z() );
189 Prs3d_Text::Draw( aGroup, anAspect, aBuf, p );
194 DEBTRACE("Do nothing");
197 void HYDROGUI_BathymetryPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
198 const Standard_Integer theMode )
200 DEBTRACE("ComputeSelection " << theMode);
205 DEBTRACE("Points selection");
206 AIS_PointCloud::ComputeSelection( theSelection, SM_Points);
211 DEBTRACE("Subset of points detection");
212 AIS_PointCloud::ComputeSelection( theSelection, SM_SubsetOfPoints );
217 DEBTRACE("Bounding box selection");
218 AIS_PointCloud::ComputeSelection( theSelection, SM_BndBox);
223 // if( theMode == 0 )
225 // if( myBound.IsVoid() )
228 // if( myBound.IsVoid() ||
229 // myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
230 // myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
231 // myBound.IsOpenZmin() || myBound.IsOpenZmax() )
234 // Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner( this );
235 // Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, myBound );
236 // theSelection->Add( aSensitiveBox );
240 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
241 int n = points.IsNull() ? 0 : points->VertexNumber();
242 for( int i=1; i<=n; i++ )
244 gp_Pnt p = points->Vertice( i );
245 Handle(HYDROGUI_BathymetryPointOwner) anOwner = new HYDROGUI_BathymetryPointOwner( this, i );
246 Handle(Select3D_SensitivePoint) aSensitivePoint = new Select3D_SensitivePoint( anOwner, p );
247 theSelection->Add( aSensitivePoint );
252 int HYDROGUI_BathymetryPrs::NbPoints() const
254 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
255 int n = points.IsNull() ? 0 : points->VertexNumber();
259 gp_Pnt HYDROGUI_BathymetryPrs::GetPoint( int theIndex ) const
261 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
262 if( points.IsNull() )
265 return points->Vertice( theIndex );
268 void HYDROGUI_BathymetryPrs::AddPoint( const Handle(Graphic3d_ArrayOfPoints)& thePoints,
269 const Handle(SelectMgr_EntityOwner)& theOwner )
271 DEBTRACE("AddPoint");
272 Handle(HYDROGUI_BathymetryPointOwner) anOwner = Handle(HYDROGUI_BathymetryPointOwner)::DownCast( theOwner );
273 if( anOwner.IsNull() )
275 DEBTRACE("index " << anOwner->GetIndex());
276 gp_Pnt p = GetPoint( anOwner->GetIndex() );
277 DEBTRACE("p: " << p.X() << " " << p.Y() << " " << p.Z());
278 thePoints->AddVertex( p );
281 void HYDROGUI_BathymetryPrs::HilightOwnerWithColor( const Handle(PrsMgr_PresentationManager3d)& thePM,
282 const Handle(Prs3d_Drawer)& theColor,
283 const Handle(SelectMgr_EntityOwner)& theOwner )
285 DEBTRACE("HilightOwnerWithColor"); // appel si AIS_PointCloud::ComputeSelection( theSelection, SM_Points);
286 Handle(AIS_PointCloudOwner) anOwner = Handle(AIS_PointCloudOwner)::DownCast( theOwner );
287 if (anOwner.IsNull())
289 DEBTRACE("---"); // jamais appelé : on n'a pas de AIS_PointCloudOwner
291 // Handle(Prs3d_Presentation) aHilightPrs = GetHilightPresentation( thePM );
292 // aHilightPrs->SetZLayer( Graphic3d_ZLayerId_Topmost );
293 // aHilightPrs->Clear();
294 // Handle(Graphic3d_ArrayOfPoints) points = new Graphic3d_ArrayOfPoints( 1 );
295 // AddPoint( points, theOwner );
297 // Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aHilightPrs );
298 // Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_X, Quantity_NOC_WHITE, 1.0 );
299 // aGroup->SetGroupPrimitivesAspect( anAspect );
300 // aGroup->AddPrimitiveArray( points );
302 // if( thePM->IsImmediateModeOn() )
303 // thePM->AddToImmediateList( aHilightPrs );
306 void HYDROGUI_BathymetryPrs::HilightSelected( const Handle(PrsMgr_PresentationManager3d)& thePM,
307 const SelectMgr_SequenceOfOwner& theOwners )
309 DEBTRACE("HilightSelected " << theOwners.Size()); // appel si AIS_PointCloud::ComputeSelection( theSelection, SM_SubsetOfPoints );
310 //AIS_PointCloud::HilightSelected(thePM, theOwners); // Non, fige la machine !
311 if (theOwners.Size() == 0)
313 Handle(SelectMgr_EntityOwner) owner = theOwners.First();
314 Handle(AIS_PointCloudOwner) anOwner = Handle(AIS_PointCloudOwner)::DownCast( owner );
315 if (!anOwner.IsNull())
317 DEBTRACE("immediateMode: " << thePM->IsImmediateModeOn()); // semble sans effet
318 const Handle(TColStd_HPackedMapOfInteger)& aSMap = anOwner->SelectedPoints();
319 DEBTRACE("selectedPoints.Extent() :" << aSMap->Map().Extent());
320 const Handle(TColStd_HPackedMapOfInteger)& aDMap = anOwner->DetectedPoints();
321 DEBTRACE("detectedPoints.Extent() :" << aDMap->Map().Extent());
324 Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( thePM );
325 aSelectPrs->SetZLayer( Graphic3d_ZLayerId_Topmost );
328 //mySelectedPoints.clear();
329 mySelectedPoints.reserve(theOwners.Size());
330 Handle(Graphic3d_ArrayOfPoints) points = new Graphic3d_ArrayOfPoints( theOwners.Size() );
331 for( int i=theOwners.Lower(); i<=theOwners.Upper(); i++ )
333 AddPoint( points, theOwners.Value( i ) );
334 Handle(HYDROGUI_BathymetryPointOwner) anOwner = Handle(HYDROGUI_BathymetryPointOwner)::DownCast( theOwners.Value( i ) );
335 if (!anOwner.IsNull())
336 mySelectedPoints.append(anOwner->GetIndex());
338 DEBTRACE("points selected " << points->ItemNumber());
339 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aSelectPrs );
340 //Handle(Graphic3d_Group) aGroup = aSelectPrs->NewGroup();
341 Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_X, Quantity_NOC_WHITE, 1.0 );
342 aGroup->SetGroupPrimitivesAspect( anAspect );
343 aGroup->AddPrimitiveArray( points );
345 aSelectPrs->SetDisplayPriority(5);
346 aSelectPrs->Display();
350 void HYDROGUI_BathymetryPrs::ClearSelected()
352 DEBTRACE("ClearSelected");
353 Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( NULL );
354 if( !aSelectPrs.IsNull() )
356 //mySelectedPoints.clear();
359 void HYDROGUI_BathymetryPrs::SetTextLabels( const QVector<int>& theTextIndices )
361 DEBTRACE("SetTextLabels");
362 myTextIndices = theTextIndices;
371 HYDROGUI_BathymetryPointOwner::HYDROGUI_BathymetryPointOwner
372 ( const Handle(HYDROGUI_BathymetryPrs)& theBathymetry, int theIndex )
373 : SelectMgr_EntityOwner( Handle(SelectMgr_SelectableObject)::DownCast( theBathymetry ), 0 ),
378 HYDROGUI_BathymetryPointOwner::~HYDROGUI_BathymetryPointOwner()
382 Standard_Boolean HYDROGUI_BathymetryPointOwner::IsAutoHilight() const
384 return Standard_False;
387 int HYDROGUI_BathymetryPointOwner::GetIndex() const