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>
32 #include <TColStd_HPackedMapOfInteger.hxx>
33 #include <TColStd_PackedMapOfInteger.hxx>
38 #include "HYDRO_trace.hxx"
40 const int BATH_HIGHLIGHT_MODE = 10;
42 HYDROGUI_BathymetryPrs::HYDROGUI_BathymetryPrs( const HYDROGUI_ShapeBathymetry* theShape )
45 DEBTRACE("HYDROGUI_BathymetryPrs");
46 SetHilightMode( BATH_HIGHLIGHT_MODE );
47 SetAutoHilight( Standard_True );
50 HYDROGUI_BathymetryPrs::~HYDROGUI_BathymetryPrs()
54 HYDROGUI_ShapeBathymetry* HYDROGUI_BathymetryPrs::GetShape() const
56 return const_cast<HYDROGUI_ShapeBathymetry*>( myShape );
59 void HYDROGUI_BathymetryPrs::UpdateBound()
61 DEBTRACE("UpdateBound");
62 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
64 if( !points.IsNull() )
67 int anUpper = points->VertexNumber();
69 for( int i = aLower; i <= anUpper; i++ )
71 gp_Pnt p = points->Vertice( i );
75 myBound.Update( p.X(), p.Y(), p.Z() );
80 void HYDROGUI_BathymetryPrs::SetPoints( const Handle(TColgp_HArray1OfPnt)& theCoords,
81 const Handle(Quantity_HArray1OfColor)& theColors,
82 const Handle(TColgp_HArray1OfDir)& theNormals )
84 AIS_PointCloud::SetPoints( theCoords, theColors, theNormals );
88 void HYDROGUI_BathymetryPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
89 const Handle(Prs3d_Presentation)& thePresentation,
90 const Standard_Integer theMode )
92 DEBTRACE("Compute " << theMode);
93 // thePresentation->Clear();
94 // Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
96 if( theMode== BATH_HIGHLIGHT_MODE ) // highlight ==> draw bounding box
98 AIS_PointCloud::Compute( thePresentationManager, thePresentation, AIS_PointCloud::DM_BndBox );
99 // if( myBound.IsVoid() )
102 // if( myBound.IsVoid() ||
103 // myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
104 // myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
105 // myBound.IsOpenZmin() || myBound.IsOpenZmax() )
108 // Standard_Real xmin, xmax, ymin, ymax, zmin, zmax;
109 // myBound.Get( xmin, ymin, zmin, xmax, ymax, zmax );
111 // Handle(Prs3d_LineAspect) aWireAspect = new Prs3d_LineAspect( Quantity_NOC_RED, Aspect_TOL_DASH, 4.0 );
112 // aGroup->SetPrimitivesAspect( aWireAspect->Aspect() ); // use Aspect_TOL_DASH to find the group by the aspect style
114 // Handle(Graphic3d_ArrayOfPolylines) aLines = new Graphic3d_ArrayOfPolylines( 18, 6 );
116 // aLines->AddBound( 5 );
117 // aLines->AddVertex( xmin, ymin, zmin );
118 // aLines->AddVertex( xmax, ymin, zmin );
119 // aLines->AddVertex( xmax, ymax, zmin );
120 // aLines->AddVertex( xmin, ymax, zmin );
121 // aLines->AddVertex( xmin, ymin, zmin );
122 // aLines->AddBound( 5 );
123 // aLines->AddVertex( xmin, ymin, zmax );
124 // aLines->AddVertex( xmax, ymin, zmax );
125 // aLines->AddVertex( xmax, ymax, zmax );
126 // aLines->AddVertex( xmin, ymax, zmax );
127 // aLines->AddVertex( xmin, ymin, zmax );
128 // aLines->AddBound( 2 );
129 // aLines->AddVertex( xmin, ymin, zmin );
130 // aLines->AddVertex( xmin, ymin, zmax );
131 // aLines->AddBound( 2 );
132 // aLines->AddVertex( xmax, ymin, zmin );
133 // aLines->AddVertex( xmax, ymin, zmax );
134 // aLines->AddBound( 2 );
135 // aLines->AddVertex( xmax, ymax, zmin );
136 // aLines->AddVertex( xmax, ymax, zmax );
137 // aLines->AddBound( 2 );
138 // aLines->AddVertex( xmin, ymax, zmin );
139 // aLines->AddVertex( xmin, ymax, zmax );
140 // aGroup->AddPrimitiveArray( aLines );
142 else if (theMode == 0)
144 DEBTRACE("non highlight mode"); // display the nodes as points with color (HYDROGUI_ShapeBathymetry::UpdateWithColorScale)
145 AIS_PointCloud::Compute( thePresentationManager, thePresentation, AIS_PointCloud::DM_Points );
147 QImage qtMark( 4, 4, QImage::Format_RGB888 ); // points marks as 4x4 rectangles
148 Handle(Image_PixMap) aMark = HYDROGUI_Tool::Pixmap( qtMark );
149 DEBTRACE("pnt dims " << aMark->SizeX() << " " << aMark->SizeY());
150 Handle(Graphic3d_MarkerImage) gMark = new Graphic3d_MarkerImage(aMark);
151 Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_USERDEFINED, Quantity_NOC_WHITE, 1.0 );
152 anAspect->SetMarkerImage(gMark);
154 DEBTRACE("nb groups " << thePresentation->NumberOfGroups()); // find the group corresponding to the points, change the aspect
155 const Graphic3d_SequenceOfGroup& grps = thePresentation->Groups();
156 Graphic3d_SequenceOfGroup::Iterator anIter( grps );
157 for ( ; anIter.More(); anIter.Next() )
159 Handle(Graphic3d_Group) aGrp = anIter.Value();
160 DEBTRACE("grp type: " << aGrp->get_type_name());
161 Handle(Graphic3d_Aspects) asp = aGrp->Aspects();
164 DEBTRACE("aspect: " << asp->get_type_name());
165 DEBTRACE("asp->LineType() " << asp->LineType());
166 if (asp->LineType() != Aspect_TOL_DASH) // find the group which does not correspond to the bounding box
167 aGrp->SetGroupPrimitivesAspect( anAspect );
171 // Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
172 // if (!points.IsNull())
173 // DEBTRACE("nb points " << points->ItemNumber());
175 // if( !myTextIndices.empty() && !points.IsNull() ) // points selected ==> altitude labels
177 // DEBTRACE("myTextIndices.size() " << myTextIndices.size());
179 // Handle(Prs3d_TextAspect) anAspect = new Prs3d_TextAspect();
181 // foreach( int index, myTextIndices )
183 // gp_Pnt p = points->Vertice( index );
184 // sprintf( aBuf, "%.2f", p.Z() );
185 // Prs3d_Text::Draw( aGroup, anAspect, aBuf, p );
190 DEBTRACE("Do nothing");
193 void HYDROGUI_BathymetryPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
194 const Standard_Integer theMode )
196 DEBTRACE("ComputeSelection " << theMode);
201 DEBTRACE("Bounding box selection");
202 AIS_PointCloud::ComputeSelection( theSelection, SM_BndBox);
207 DEBTRACE("Subset of points detection");
208 AIS_PointCloud::ComputeSelection( theSelection, SM_SubsetOfPoints ); // SM_Points ?
213 DEBTRACE("Do Nothing");
218 // if( theMode == 0 )
220 // if( myBound.IsVoid() )
223 // if( myBound.IsVoid() ||
224 // myBound.IsOpenXmin() || myBound.IsOpenXmax() ||
225 // myBound.IsOpenYmin() || myBound.IsOpenYmax() ||
226 // myBound.IsOpenZmin() || myBound.IsOpenZmax() )
229 // Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner( this );
230 // Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, myBound );
231 // theSelection->Add( aSensitiveBox );
233 // if( theMode == 1 )
235 // AIS_PointCloud::ComputeSelection(theSelection, theMode);
236 //// Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
237 //// int n = points.IsNull() ? 0 : points->VertexNumber();
238 //// for( int i=1; i<=n; i++ )
240 //// gp_Pnt p = points->Vertice( i );
241 //// Handle(HYDROGUI_BathymetryPointOwner) anOwner = new HYDROGUI_BathymetryPointOwner( this, i );
242 //// Handle(Select3D_SensitivePoint) aSensitivePoint = new Select3D_SensitivePoint( anOwner, p );
243 //// theSelection->Add( aSensitivePoint );
248 int HYDROGUI_BathymetryPrs::NbPoints() const
250 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
251 int n = points.IsNull() ? 0 : points->VertexNumber();
255 gp_Pnt HYDROGUI_BathymetryPrs::GetPoint( int theIndex ) const
257 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
258 if( points.IsNull() )
261 return points->Vertice( theIndex );
264 void HYDROGUI_BathymetryPrs::AddPoint( const Handle(Graphic3d_ArrayOfPoints)& thePoints,
265 const Handle(SelectMgr_EntityOwner)& theOwner )
267 DEBTRACE("AddPoint");
268 Handle(AIS_PointCloudOwner) anOwner = Handle(AIS_PointCloudOwner)::DownCast( theOwner );
269 if( anOwner.IsNull() )
271 // gp_Pnt p = GetPoint( anOwner->GetIndex() );
272 // thePoints->AddVertex( p );
275 void HYDROGUI_BathymetryPrs::HilightOwnerWithColor( const Handle(PrsMgr_PresentationManager3d)& thePM,
276 const Handle(Prs3d_Drawer)& theColor,
277 const Handle(SelectMgr_EntityOwner)& theOwner )
279 DEBTRACE("HilightOwnerWithColor"); // appel si AIS_PointCloud::ComputeSelection( theSelection, SM_Points);
280 Handle(AIS_PointCloudOwner) anOwner = Handle(AIS_PointCloudOwner)::DownCast( theOwner );
281 if (anOwner.IsNull())
283 DEBTRACE("---"); // jamais appelé : on n'a pas de AIS_PointCloudOwner
285 // Handle(Prs3d_Presentation) aHilightPrs = GetHilightPresentation( thePM );
286 // aHilightPrs->SetZLayer( Graphic3d_ZLayerId_Topmost );
287 // aHilightPrs->Clear();
288 // Handle(Graphic3d_ArrayOfPoints) points = new Graphic3d_ArrayOfPoints( 1 );
289 // AddPoint( points, theOwner );
291 // Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aHilightPrs );
292 // Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_X, Quantity_NOC_WHITE, 1.0 );
293 // aGroup->SetGroupPrimitivesAspect( anAspect );
294 // aGroup->AddPrimitiveArray( points );
296 // if( thePM->IsImmediateModeOn() )
297 // thePM->AddToImmediateList( aHilightPrs );
300 void HYDROGUI_BathymetryPrs::HilightSelected( const Handle(PrsMgr_PresentationManager3d)& thePM,
301 const SelectMgr_SequenceOfOwner& theOwners )
303 DEBTRACE("HilightSelected " << theOwners.Size()); // appel si AIS_PointCloud::ComputeSelection( theSelection, SM_SubsetOfPoints );
304 //AIS_PointCloud::HilightSelected(thePM, theOwners); // Non, fige la machine !
305 if (theOwners.Size() == 0)
307 Handle(SelectMgr_EntityOwner) owner = theOwners.First();
308 Handle(AIS_PointCloudOwner) anOwner = Handle(AIS_PointCloudOwner)::DownCast( owner );
309 if (anOwner.IsNull())
311 DEBTRACE("immediateMode: " << thePM->IsImmediateModeOn()); // semble sans effet
312 const Handle(TColStd_HPackedMapOfInteger)& aSMap = anOwner->SelectedPoints();
313 DEBTRACE("selectedPoints.Extent() :" << aSMap->Map().Extent());
314 const Handle(TColStd_HPackedMapOfInteger)& aDMap = anOwner->DetectedPoints();
315 DEBTRACE("detectedPoints.Extent() :" << aDMap->Map().Extent());
318 // Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( thePM );
319 // aSelectPrs->SetZLayer( Graphic3d_ZLayerId_Topmost );
320 // aSelectPrs->Clear();
322 // Handle(Graphic3d_ArrayOfPoints) points = new Graphic3d_ArrayOfPoints( theOwners.Size() );
323 // for( int i=theOwners.Lower(); i<=theOwners.Upper(); i++ )
324 // AddPoint( points, theOwners.Value( i ) );
326 // Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aSelectPrs );
327 // Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_X, Quantity_NOC_WHITE, 1.0 );
328 // aGroup->SetGroupPrimitivesAspect( anAspect );
329 // aGroup->AddPrimitiveArray( points );
331 // aSelectPrs->SetDisplayPriority(9);
332 // aSelectPrs->Display();
335 void HYDROGUI_BathymetryPrs::ClearSelected()
337 DEBTRACE("ClearSelected");
338 Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( NULL );
339 if( !aSelectPrs.IsNull() )
343 void HYDROGUI_BathymetryPrs::SetTextLabels( const QVector<int>& theTextIndices )
345 DEBTRACE("SetTextLabels");
346 myTextIndices = theTextIndices;
355 HYDROGUI_BathymetryPointOwner::HYDROGUI_BathymetryPointOwner
356 ( const Handle(HYDROGUI_BathymetryPrs)& theBathymetry, int theIndex )
357 : SelectMgr_EntityOwner( Handle(SelectMgr_SelectableObject)::DownCast( theBathymetry ), 0 ),
362 HYDROGUI_BathymetryPointOwner::~HYDROGUI_BathymetryPointOwner()
366 Standard_Boolean HYDROGUI_BathymetryPointOwner::IsAutoHilight() const
368 return Standard_False;
371 int HYDROGUI_BathymetryPointOwner::GetIndex() const