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 );
103 else if (theMode == 0)
105 DEBTRACE("non highlight mode"); // display the nodes as points with color (HYDROGUI_ShapeBathymetry::UpdateWithColorScale)
106 AIS_PointCloud::Compute( thePresentationManager, thePresentation, AIS_PointCloud::DM_Points );
108 QImage qtMark( 4, 4, QImage::Format_RGB888 ); // points marks as 4x4 rectangles
109 Handle(Image_PixMap) aMark = HYDROGUI_Tool::Pixmap( qtMark );
110 DEBTRACE("pnt dims " << aMark->SizeX() << " " << aMark->SizeY());
111 Handle(Graphic3d_MarkerImage) gMark = new Graphic3d_MarkerImage(aMark);
112 Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_USERDEFINED, Quantity_NOC_WHITE, 1.0 );
113 anAspect->SetMarkerImage(gMark);
115 DEBTRACE("nb groups " << thePresentation->NumberOfGroups()); // find the group corresponding to the points, change the aspect
116 const Graphic3d_SequenceOfGroup& grps = thePresentation->Groups();
117 Graphic3d_SequenceOfGroup::Iterator anIter( grps );
118 for ( ; anIter.More(); anIter.Next() )
120 Handle(Graphic3d_Group) aGrp = anIter.Value();
121 DEBTRACE("grp type: " << aGrp->get_type_name());
122 Handle(Graphic3d_Aspects) asp = aGrp->Aspects();
125 DEBTRACE("aspect: " << asp->get_type_name());
126 DEBTRACE("asp->LineType() " << asp->LineType());
127 if (asp->LineType() != Aspect_TOL_DASH) // find the group which does not correspond to the bounding box
128 aGrp->SetGroupPrimitivesAspect( anAspect );
132 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
133 if (!points.IsNull())
134 DEBTRACE("nb points " << points->ItemNumber());
136 if( !myTextIndices.empty() && !points.IsNull() ) // points selected ==> altitude labels
138 DEBTRACE("myTextIndices.size() " << myTextIndices.size());
140 Handle(Prs3d_TextAspect) anAspect = new Prs3d_TextAspect();
142 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
143 foreach( int index, myTextIndices )
145 gp_Pnt p = points->Vertice( index );
146 sprintf( aBuf, "%.2f", p.Z() );
147 Prs3d_Text::Draw( aGroup, anAspect, aBuf, p );
152 DEBTRACE("Do nothing");
155 void HYDROGUI_BathymetryPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
156 const Standard_Integer theMode )
158 DEBTRACE("ComputeSelection " << theMode);
163 DEBTRACE("Points selection");
164 AIS_PointCloud::ComputeSelection( theSelection, SM_Points);
169 DEBTRACE("Subset of points detection");
170 AIS_PointCloud::ComputeSelection( theSelection, SM_SubsetOfPoints );
175 DEBTRACE("Bounding box selection");
176 AIS_PointCloud::ComputeSelection( theSelection, SM_BndBox);
183 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
184 int n = points.IsNull() ? 0 : points->VertexNumber();
185 for( int i=1; i<=n; i++ )
187 gp_Pnt p = points->Vertice( i );
188 Handle(HYDROGUI_BathymetryPointOwner) anOwner = new HYDROGUI_BathymetryPointOwner( this, i );
189 Handle(Select3D_SensitivePoint) aSensitivePoint = new Select3D_SensitivePoint( anOwner, p );
190 theSelection->Add( aSensitivePoint );
195 int HYDROGUI_BathymetryPrs::NbPoints() const
197 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
198 int n = points.IsNull() ? 0 : points->VertexNumber();
202 gp_Pnt HYDROGUI_BathymetryPrs::GetPoint( int theIndex ) const
204 Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
205 if( points.IsNull() )
208 return points->Vertice( theIndex );
211 void HYDROGUI_BathymetryPrs::AddPoint( const Handle(Graphic3d_ArrayOfPoints)& thePoints,
212 const Handle(SelectMgr_EntityOwner)& theOwner )
214 DEBTRACE("AddPoint");
215 Handle(HYDROGUI_BathymetryPointOwner) anOwner = Handle(HYDROGUI_BathymetryPointOwner)::DownCast( theOwner );
216 if( anOwner.IsNull() )
218 DEBTRACE("index " << anOwner->GetIndex());
219 gp_Pnt p = GetPoint( anOwner->GetIndex() );
220 DEBTRACE("p: " << p.X() << " " << p.Y() << " " << p.Z());
221 thePoints->AddVertex( p );
224 void HYDROGUI_BathymetryPrs::HilightOwnerWithColor( const Handle(PrsMgr_PresentationManager3d)& thePM,
225 const Handle(Prs3d_Drawer)& theColor,
226 const Handle(SelectMgr_EntityOwner)& theOwner )
228 DEBTRACE("HilightOwnerWithColor"); // appel si AIS_PointCloud::ComputeSelection( theSelection, SM_Points);
229 Handle(AIS_PointCloudOwner) anOwner = Handle(AIS_PointCloudOwner)::DownCast( theOwner );
230 if (anOwner.IsNull())
232 DEBTRACE("---"); // jamais appelé : on n'a pas de AIS_PointCloudOwner
235 void HYDROGUI_BathymetryPrs::HilightSelected( const Handle(PrsMgr_PresentationManager3d)& thePM,
236 const SelectMgr_SequenceOfOwner& theOwners )
238 DEBTRACE("HilightSelected " << theOwners.Size()); // appel si AIS_PointCloud::ComputeSelection( theSelection, SM_SubsetOfPoints );
239 //AIS_PointCloud::HilightSelected(thePM, theOwners); // Non, fige la machine !
240 if (theOwners.Size() == 0)
242 Handle(SelectMgr_EntityOwner) owner = theOwners.First();
243 Handle(AIS_PointCloudOwner) anOwner = Handle(AIS_PointCloudOwner)::DownCast( owner );
244 if (!anOwner.IsNull())
246 DEBTRACE("immediateMode: " << thePM->IsImmediateModeOn()); // semble sans effet
247 const Handle(TColStd_HPackedMapOfInteger)& aSMap = anOwner->SelectedPoints();
248 DEBTRACE("selectedPoints.Extent() :" << aSMap->Map().Extent());
249 const Handle(TColStd_HPackedMapOfInteger)& aDMap = anOwner->DetectedPoints();
250 DEBTRACE("detectedPoints.Extent() :" << aDMap->Map().Extent());
253 Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( thePM );
254 aSelectPrs->SetZLayer( Graphic3d_ZLayerId_Topmost );
257 //mySelectedPoints.clear();
258 mySelectedPoints.reserve(theOwners.Size());
259 Handle(Graphic3d_ArrayOfPoints) points = new Graphic3d_ArrayOfPoints( theOwners.Size() );
260 for( int i=theOwners.Lower(); i<=theOwners.Upper(); i++ )
262 AddPoint( points, theOwners.Value( i ) );
263 Handle(HYDROGUI_BathymetryPointOwner) anOwner = Handle(HYDROGUI_BathymetryPointOwner)::DownCast( theOwners.Value( i ) );
264 if (!anOwner.IsNull())
265 mySelectedPoints.append(anOwner->GetIndex());
267 DEBTRACE("points selected " << points->ItemNumber());
268 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aSelectPrs );
269 //Handle(Graphic3d_Group) aGroup = aSelectPrs->NewGroup();
270 Handle(Graphic3d_AspectMarker3d) anAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_X, Quantity_NOC_WHITE, 1.0 );
271 aGroup->SetGroupPrimitivesAspect( anAspect );
272 aGroup->AddPrimitiveArray( points );
274 aSelectPrs->SetDisplayPriority(5);
275 aSelectPrs->Display();
279 void HYDROGUI_BathymetryPrs::ClearSelected()
281 DEBTRACE("ClearSelected");
282 Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( NULL );
283 if( !aSelectPrs.IsNull() )
285 //mySelectedPoints.clear();
288 void HYDROGUI_BathymetryPrs::SetTextLabels( const QVector<int>& theTextIndices )
290 DEBTRACE("SetTextLabels");
291 myTextIndices = theTextIndices;
295 HYDROGUI_BathymetryPointOwner::HYDROGUI_BathymetryPointOwner
296 ( const Handle(HYDROGUI_BathymetryPrs)& theBathymetry, int theIndex )
297 : SelectMgr_EntityOwner( Handle(SelectMgr_SelectableObject)::DownCast( theBathymetry ), 0 ),
302 HYDROGUI_BathymetryPointOwner::~HYDROGUI_BathymetryPointOwner()
306 Standard_Boolean HYDROGUI_BathymetryPointOwner::IsAutoHilight() const
308 return Standard_False;
311 int HYDROGUI_BathymetryPointOwner::GetIndex() const