0024752: Visualization - inherit OpenGl_Group from Graphic3d_Group
[occt.git] / src / StdSelect / StdSelect_ViewerSelector3d.cxx
CommitLineData
b311480e 1// Created on: 1995-03-15
2// Created by: Robert COUBLANC
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <StdSelect_ViewerSelector3d.ixx>
18#include <StdSelect.hxx>
19#include <SelectBasics_SensitiveEntity.hxx>
20#include <Graphic3d_AspectLine3d.hxx>
21#include <gp_Pnt.hxx>
22#include <gp_Lin.hxx>
23#include <gp_Pnt2d.hxx>
24#include <gp_Dir.hxx>
25#include <gp_Ax3.hxx>
26#include <gp_GTrsf.hxx>
4269bd1b 27#include <gp_Pln.hxx>
7fd59977 28#include <Select3D_SensitiveEntity.hxx>
b8ddfc2f 29#include <Graphic3d_ArrayOfPolylines.hxx>
51b10cd4 30#include <Graphic3d_SequenceOfHClipPlane.hxx>
4269bd1b 31#include <SelectMgr_SelectableObject.hxx>
7fd59977 32#include <SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive.hxx>
33#include <SelectBasics_ListOfBox2d.hxx>
7fd59977 34#include <TColgp_HArray1OfPnt.hxx>
35#include <TColgp_Array1OfPnt.hxx>
36#include <TColgp_HArray1OfPnt2d.hxx>
37#include <Select3D_SensitiveCurve.hxx>
38#include <Select3D_SensitiveSegment.hxx>
39#include <Select3D_SensitiveFace.hxx>
40#include <Select3D_SensitiveCircle.hxx>
41#include <Select3D_SensitivePoint.hxx>
42#include <Select3D_SensitiveTriangulation.hxx>
43#include <Select3D_SensitiveTriangle.hxx>
44#include <Select3D_SensitiveWire.hxx>
45#include <Select3D_SensitiveEntitySequence.hxx>
46#include <Select3D_ListOfSensitiveTriangle.hxx>
47#include <Select3D_SensitiveBox.hxx>
48#include <Select3D_ListIteratorOfListOfSensitiveTriangle.hxx>
49
50#include <SelectMgr_DataMapIteratorOfDataMapOfSelectionActivation.hxx>
679ecdee 51#include <Aspect_Grid.hxx>
7fd59977 52#include <Aspect_TypeOfMarker.hxx>
53#include <Graphic3d_AspectMarker3d.hxx>
a577aaab 54#include <Graphic3d_ArrayOfPoints.hxx>
7fd59977 55#include <SelectBasics_ListIteratorOfListOfBox2d.hxx>
56#include <Poly_Connect.hxx>
57#include <TColStd_HArray1OfInteger.hxx>
58
59#include <Poly_Array1OfTriangle.hxx>
60#include <Poly_Triangulation.hxx>
61#include <OSD_Environment.hxx>
62#include <V3d.hxx>
63#include <V3d_View.hxx>
679ecdee 64#include <V3d_Viewer.hxx>
b8ddfc2f 65#include <TColgp_SequenceOfPnt.hxx>
66
7fd59977 67static Standard_Integer StdSel_NumberOfFreeEdges (const Handle(Poly_Triangulation)& Trg)
68{
69 Standard_Integer nFree = 0;
70 Poly_Connect pc(Trg);
71 Standard_Integer t[3];
72 Standard_Integer i, j;
73 for (i = 1; i <= Trg->NbTriangles(); i++)
74 {
75 pc.Triangles (i, t[0], t[1], t[2]);
76 for (j = 0; j < 3; j++)
77 if (t[j] == 0) nFree++;
78 }
79 return nFree;
80}
81
197ac94e 82//=======================================================================
83// Function : Constructor
84// Purpose :
85//=======================================================================
86StdSelect_ViewerSelector3d::StdSelect_ViewerSelector3d()
87: myProjector (new Select3D_Projector()),
88 myPrevFOV (0.0),
89 myPrevScale (0.0),
90 myPrevOrthographic (Standard_True),
91 mySensMode (StdSelect_SM_WINDOW),
92 myPixelTolerance (2),
93 myToUpdateTolerance (Standard_True)
7fd59977 94{
197ac94e 95 myPrevAt[0] = 0.0;
96 myPrevAt[1] = 0.0;
97 myPrevAt[2] = 0.0;
98 myPrevUp[0] = 0.0;
99 myPrevUp[1] = 0.0;
100 myPrevUp[2] = 0.0;
101 myPrevProj[0] = 0.0;
102 myPrevProj[1] = 0.0;
103 myPrevProj[2] = 0.0;
104 myPrevAxialScale[0] = 0.0;
105 myPrevAxialScale[1] = 0.0;
106 myPrevAxialScale[2] = 0.0;
7fd59977 107}
108
197ac94e 109//=======================================================================
110// Function : Constructor
111// Purpose :
112//=======================================================================
113StdSelect_ViewerSelector3d::StdSelect_ViewerSelector3d (const Handle(Select3D_Projector)& theProj)
114: myProjector (theProj),
115 myPrevFOV (0.0),
116 myPrevScale (0.0),
117 myPrevOrthographic (Standard_True),
118 mySensMode (StdSelect_SM_WINDOW),
119 myPixelTolerance (2),
120 myToUpdateTolerance (Standard_True)
7fd59977 121{
197ac94e 122 myPrevAt[0] = 0.0;
123 myPrevAt[1] = 0.0;
124 myPrevAt[2] = 0.0;
125 myPrevUp[0] = 0.0;
126 myPrevUp[1] = 0.0;
127 myPrevUp[2] = 0.0;
128 myPrevProj[0] = 0.0;
129 myPrevProj[1] = 0.0;
130 myPrevProj[2] = 0.0;
131 myPrevAxialScale[0] = 0.0;
132 myPrevAxialScale[1] = 0.0;
133 myPrevAxialScale[2] = 0.0;
7fd59977 134}
135
197ac94e 136//=======================================================================
7fd59977 137// Function: Convert
138// Purpose :
197ac94e 139//=======================================================================
140void StdSelect_ViewerSelector3d::Convert (const Handle(SelectMgr_Selection)& theSel)
7fd59977 141{
197ac94e 142 for (theSel->Init(); theSel->More(); theSel->Next())
7fd59977 143 {
197ac94e 144 if (theSel->Sensitive()->NeedsConversion())
7fd59977 145 {
197ac94e 146 Handle(Select3D_SensitiveEntity) aSE = *((Handle(Select3D_SensitiveEntity)*) &(theSel->Sensitive()));
147 aSE->Project (myProjector);
148 if (!tosort)
149 {
150 tosort = Standard_True;
151 }
7fd59977 152 }
153 }
154}
155
197ac94e 156//=======================================================================
7fd59977 157// Function: Set
158// Purpose :
197ac94e 159//=======================================================================
160void StdSelect_ViewerSelector3d::Set (const Handle(Select3D_Projector)& theProj)
7fd59977 161{
197ac94e 162 myProjector = theProj;
163 toupdate = Standard_True;
7fd59977 164}
165
197ac94e 166//=======================================================================
3c982548 167// Function: SetSensitivityMode
7fd59977 168// Purpose :
197ac94e 169//=======================================================================
170void StdSelect_ViewerSelector3d::SetSensitivityMode (const StdSelect_SensitivityMode theMode)
7fd59977 171{
197ac94e 172 mySensMode = theMode;
3c982548 173 toupdate = Standard_True;
174}
175
197ac94e 176//=======================================================================
3c982548 177// Function: SetPixelTolerance
178// Purpose :
197ac94e 179//=======================================================================
180void StdSelect_ViewerSelector3d::SetPixelTolerance (const Standard_Integer theTolerance)
3c982548 181{
197ac94e 182 if (myPixelTolerance != theTolerance)
3c982548 183 {
197ac94e 184 myPixelTolerance = theTolerance;
185 myToUpdateTolerance = Standard_True;
3c982548 186 }
7fd59977 187}
188
197ac94e 189//=======================================================================
190// Function: Pick
7fd59977 191// Purpose :
197ac94e 192//=======================================================================
193void StdSelect_ViewerSelector3d::Pick (const Standard_Integer theXPix,
194 const Standard_Integer theYPix,
195 const Handle(V3d_View)& theView)
7fd59977 196{
197ac94e 197 SetClipping (theView->GetClipPlanes());
198 UpdateProj (theView);
679ecdee 199 Standard_Real aPnt3d[3];
200 theView->Convert (theXPix, theYPix,
201 aPnt3d[0], aPnt3d[1], aPnt3d[2]);
197ac94e 202
679ecdee 203 gp_Pnt2d aPnt2d;
204 myProjector->Project (gp_Pnt (aPnt3d[0], aPnt3d[1], aPnt3d[2]), aPnt2d);
7fd59977 205
679ecdee 206 InitSelect (aPnt2d.X(), aPnt2d.Y());
197ac94e 207}
7fd59977 208
197ac94e 209//=======================================================================
210// Function: Pick
7fd59977 211// Purpose :
197ac94e 212//=======================================================================
213void StdSelect_ViewerSelector3d::Pick (const Standard_Integer theXPMin,
214 const Standard_Integer theYPMin,
215 const Standard_Integer theXPMax,
216 const Standard_Integer theYPMax,
217 const Handle(V3d_View)& theView)
7fd59977 218{
197ac94e 219 if (myToUpdateTolerance && SensitivityMode() == StdSelect_SM_WINDOW)
7fd59977 220 {
197ac94e 221 SetSensitivity (theView->Convert (myPixelTolerance));
222 myToUpdateTolerance = Standard_False;
7fd59977 223 }
197ac94e 224
225 UpdateProj (theView);
226
227 Standard_Real aX1 = 0.0;
228 Standard_Real aY1 = 0.0;
229 Standard_Real aZ1 = 0.0;
230 Standard_Real aX2 = 0.0;
231 Standard_Real aY2 = 0.0;
232 Standard_Real aZ2 = 0.0;
233 gp_Pnt2d aP2d1;
234 gp_Pnt2d aP2d2;
235
236 theView->Convert (theXPMin, theYPMin, aX1, aY1, aZ1);
237 theView->Convert (theXPMax, theYPMax, aX2, aY2, aZ2);
238 myProjector->Project (gp_Pnt (aX1, aY1, aZ1), aP2d1);
239 myProjector->Project (gp_Pnt (aX2, aY2, aZ2), aP2d2);
240
241 InitSelect (Min (aP2d1.X(), aP2d2.X()),
242 Min (aP2d1.Y(), aP2d2.Y()),
243 Max (aP2d1.X(), aP2d2.X()),
244 Max (aP2d1.Y(), aP2d2.Y()));
7fd59977 245}
246
197ac94e 247//=======================================================================
7fd59977 248// Function: Pick
249// Purpose : Selection using a polyline
197ac94e 250//=======================================================================
251void StdSelect_ViewerSelector3d::Pick (const TColgp_Array1OfPnt2d& thePolyline,
252 const Handle(V3d_View)& theView)
7fd59977 253{
197ac94e 254 if (myToUpdateTolerance && SensitivityMode() == StdSelect_SM_WINDOW)
7fd59977 255 {
197ac94e 256 SetSensitivity (theView->Convert (myPixelTolerance));
257 myToUpdateTolerance = Standard_False;
7fd59977 258 }
259
197ac94e 260 UpdateProj (theView);
7fd59977 261
197ac94e 262 Standard_Integer aNbPix = thePolyline.Length();
7fd59977 263
264 // Convert pixel
197ac94e 265 Handle(TColgp_HArray1OfPnt2d) aP2d = new TColgp_HArray1OfPnt2d (1, aNbPix);
7fd59977 266
197ac94e 267 for (Standard_Integer aPntIt = 1; aPntIt <= aNbPix; ++aPntIt)
7fd59977 268 {
197ac94e 269 Standard_Integer aXP = (Standard_Integer)(thePolyline (aPntIt).X());
270 Standard_Integer aYP = (Standard_Integer)(thePolyline (aPntIt).Y());
7fd59977 271
197ac94e 272 Standard_Real aX = 0.0;
273 Standard_Real aY = 0.0;
274 Standard_Real aZ = 0.0;
275 gp_Pnt2d aPnt2d;
7fd59977 276
197ac94e 277 theView->Convert (aXP, aYP, aX, aY, aZ);
278 myProjector->Project (gp_Pnt (aX, aY, aZ), aPnt2d);
279
280 aP2d->SetValue (aPntIt, aPnt2d);
7fd59977 281 }
282
197ac94e 283 const TColgp_Array1OfPnt2d& aPolyConvert = aP2d->Array1();
7fd59977 284
197ac94e 285 InitSelect (aPolyConvert);
7fd59977 286}
287
197ac94e 288//=======================================================================
7fd59977 289// Function: DisplayAreas
290// Purpose : display the activated areas...
197ac94e 291//=======================================================================
292void StdSelect_ViewerSelector3d::DisplayAreas (const Handle(V3d_View)& theView)
7fd59977 293{
197ac94e 294 if (myToUpdateTolerance && SensitivityMode() == StdSelect_SM_WINDOW)
7fd59977 295 {
197ac94e 296 SetSensitivity (theView->Convert (myPixelTolerance));
297 myToUpdateTolerance = Standard_False;
7fd59977 298 }
197ac94e 299
300 UpdateProj (theView);
7fd59977 301 UpdateSort(); // Updates the activated areas
302
197ac94e 303 if (mystruct.IsNull())
304 {
305 mystruct = new Graphic3d_Structure (theView->Viewer()->Viewer());
306 }
b8ddfc2f 307
197ac94e 308 if (myareagroup.IsNull())
309 {
b64d84be 310 myareagroup = mystruct->NewGroup();
197ac94e 311 }
7fd59977 312
197ac94e 313 SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive anIt (myentities);
314 Handle(Select3D_Projector) aProjector = StdSelect::GetProjector (theView);
315 aProjector->SetView (theView);
7fd59977 316
197ac94e 317 Standard_Real aXmin = 0.0;
318 Standard_Real aYmin = 0.0;
319 Standard_Real aXmax = 0.0;
320 Standard_Real aYmax = 0.0;
321 gp_Pnt aPbid;
322 SelectBasics_ListOfBox2d aBoxList;
7fd59977 323
b8ddfc2f 324 TColgp_SequenceOfPnt aSeqLines;
197ac94e 325 for (; anIt.More(); anIt.Next())
7fd59977 326 {
197ac94e 327 anIt.Value()->Areas (aBoxList);
328
329 for (SelectBasics_ListIteratorOfListOfBox2d aBoxIt (aBoxList); aBoxIt.More(); aBoxIt.Next())
7fd59977 330 {
197ac94e 331 aBoxIt.Value().Get (aXmin, aYmin, aXmax, aYmax);
7fd59977 332
197ac94e 333 aPbid.SetCoord (aXmin - mytolerance, aYmin - mytolerance, 0.0);
334 aProjector->Transform (aPbid, aProjector->InvertedTransformation());
335 aSeqLines.Append (aPbid);
7fd59977 336
197ac94e 337 aPbid.SetCoord (aXmax + mytolerance, aYmin - mytolerance, 0.0);
338 aProjector->Transform (aPbid, aProjector->InvertedTransformation());
339 aSeqLines.Append (aPbid);
7fd59977 340
197ac94e 341 aPbid.SetCoord (aXmax + mytolerance, aYmax + mytolerance, 0.0);
342 aProjector->Transform (aPbid, aProjector->InvertedTransformation());
343 aSeqLines.Append (aPbid);
7fd59977 344
197ac94e 345 aPbid.SetCoord (aXmin - mytolerance, aYmax + mytolerance, 0.0);
346 aProjector->Transform (aPbid, aProjector->InvertedTransformation());
347 aSeqLines.Append (aPbid);
b8ddfc2f 348 }
349 }
7fd59977 350
b8ddfc2f 351 if (aSeqLines.Length())
352 {
197ac94e 353 Standard_Integer aN = 0;
354 Standard_Integer aNp = 0;
355 const Standard_Integer aNbl = aSeqLines.Length() / 4;
356
357 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines (5 * aNbl, aNbl);
358 for (aNp = 1, aN = 0; aN < aNbl; aN++)
359 {
360 aPrims->AddBound (5);
361 const gp_Pnt &aPnt1 = aSeqLines (aNp++);
362 aPrims->AddVertex (aPnt1);
363 aPrims->AddVertex (aSeqLines (aNp++));
364 aPrims->AddVertex (aSeqLines (aNp++));
365 aPrims->AddVertex (aSeqLines (aNp++));
366 aPrims->AddVertex (aPnt1);
7fd59977 367 }
197ac94e 368 myareagroup->AddPrimitiveArray (aPrims);
7fd59977 369 }
370
b8ddfc2f 371 myareagroup->SetGroupPrimitivesAspect (new Graphic3d_AspectLine3d (Quantity_NOC_AQUAMARINE1, Aspect_TOL_DASH, 1.0));
197ac94e 372 myareagroup->Structure()->SetDisplayPriority (10);
7fd59977 373 myareagroup->Structure()->Display();
374
679ecdee 375 theView->Update();
7fd59977 376}
377
197ac94e 378//=======================================================================
7fd59977 379// Function: ClearAreas
380// Purpose :
197ac94e 381//=======================================================================
382void StdSelect_ViewerSelector3d::ClearAreas (const Handle(V3d_View)& theView)
7fd59977 383{
197ac94e 384 if (myareagroup.IsNull())
385 {
386 return;
387 }
388
7fd59977 389 myareagroup->Clear();
197ac94e 390
679ecdee 391 if (!theView.IsNull())
197ac94e 392 {
393 theView->Update();
394 }
7fd59977 395}
396
197ac94e 397//=======================================================================
398// Function: UpdateProj
399// Purpose :
400//=======================================================================
401Standard_Boolean StdSelect_ViewerSelector3d::UpdateProj (const Handle(V3d_View)& theView)
7fd59977 402{
197ac94e 403 // Check common properties of camera
404 Standard_Real anUp[3];
405 Standard_Real aProj[3];
406 Standard_Real anAxialScale[3];
407 theView->Up (anUp[0], anUp[1], anUp[2]);
408 theView->Proj (aProj[0], aProj[1], aProj[2]);
409 theView->AxialScale (anAxialScale[0], anAxialScale[1], anAxialScale[2]);
410
411 Standard_Boolean isOrthographic = theView->Type() == V3d_ORTHOGRAPHIC;
412 Standard_Boolean toUpdateProjector = myPrevOrthographic != isOrthographic
413 || myPrevUp[0] != anUp[0]
414 || myPrevUp[1] != anUp[1]
415 || myPrevUp[2] != anUp[2]
416 || myPrevProj[0] != aProj[0]
417 || myPrevProj[1] != aProj[1]
418 || myPrevProj[2] != aProj[2]
419 || myPrevAxialScale[0] != anAxialScale[0]
420 || myPrevAxialScale[1] != anAxialScale[1]
421 || myPrevAxialScale[2] != anAxialScale[2];
422
423 // Check properties of perspective camera
424 Standard_Real anAt[3];
425 Standard_Real aScale = theView->Scale();
426 Standard_Real aFOV = theView->Camera()->FOVy();
427 theView->At (anAt[0], anAt[1], anAt[2]);
428 if (!isOrthographic && !toUpdateProjector)
7fd59977 429 {
197ac94e 430 toUpdateProjector = myPrevAt[0] != anAt[0]
431 || myPrevAt[1] != anAt[1]
432 || myPrevAt[2] != anAt[2]
433 || myPrevScale != aScale
434 || myPrevFOV != aFOV;
7fd59977 435 }
197ac94e 436
437 myToUpdateTolerance = aScale != myPrevScale;
438
439 // Update projector if anything changed
440 if (toUpdateProjector)
7fd59977 441 {
7fd59977 442 toupdate = Standard_True;
197ac94e 443
444 myToUpdateTolerance = Standard_True;
445
446 if (isOrthographic)
7fd59977 447 {
197ac94e 448 // For orthographic view use only direction of projection and up vector
449 // Panning, and zooming has no effect on 2D selection sensitives.
450 Handle (Graphic3d_Camera) aCamera = new Graphic3d_Camera();
451
452 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
453 aCamera->SetCenter (gp::Origin());
454 aCamera->SetDirection (gp_Dir (-aProj[0], -aProj[1], -aProj[2]));
455 aCamera->SetUp (gp_Dir (anUp[0], anUp[1], anUp[2]));
456 aCamera->SetDistance (1.0);
457 aCamera->SetAxialScale (gp_XYZ (anAxialScale[0], anAxialScale[1], anAxialScale[2]));
458
459 myProjector = new Select3D_Projector (aCamera->OrientationMatrix(), Graphic3d_Mat4d());
7fd59977 460 }
197ac94e 461 else
7fd59977 462 {
197ac94e 463 // For perspective projection panning, zooming and location of view
464 // has effect. Thus, use current view and projection matrices from
465 // view camera. Exception is that the projection transformation
466 // is scaled from NDC to size of displaying frame of view space in order
467 // to maintain consistence with pixel tolerance conversion.
468 const Graphic3d_Mat4d& aMVMatrix = theView->Camera()->OrientationMatrix();
469 const Graphic3d_Mat4d& aProjMatrix = theView->Camera()->ProjectionMatrix();
470 gp_XYZ aViewDimensions = theView->Camera()->ViewDimensions();
471
472 Graphic3d_Mat4d aScaledProj;
473 aScaledProj.ChangeValue (0, 0) = aViewDimensions.X();
474 aScaledProj.ChangeValue (1, 1) = aViewDimensions.Y();
475 aScaledProj.ChangeValue (2, 2) = aViewDimensions.Z();
476 Graphic3d_Mat4d aScaledProjMatrix = aScaledProj * aProjMatrix;
477
478 myProjector = new Select3D_Projector (aMVMatrix, aScaledProjMatrix);
7fd59977 479 }
7fd59977 480 }
481
197ac94e 482 myPrevAt[0] = anAt[0];
483 myPrevAt[1] = anAt[1];
484 myPrevAt[2] = anAt[2];
485 myPrevUp[0] = anUp[0];
486 myPrevUp[1] = anUp[1];
487 myPrevUp[2] = anUp[2];
488 myPrevProj[0] = aProj[0];
489 myPrevProj[1] = aProj[1];
490 myPrevProj[2] = aProj[2];
491 myPrevAxialScale[0] = anAxialScale[0];
492 myPrevAxialScale[1] = anAxialScale[1];
493 myPrevAxialScale[2] = anAxialScale[2];
494 myPrevFOV = aFOV;
495 myPrevScale = aScale;
496 myPrevOrthographic = isOrthographic;
497
498 if (myToUpdateTolerance && SensitivityMode() == StdSelect_SM_WINDOW)
7fd59977 499 {
197ac94e 500 SetSensitivity (theView->Convert (myPixelTolerance));
501 myToUpdateTolerance = Standard_False;
7fd59977 502 }
503
197ac94e 504 if (toupdate)
7fd59977 505 {
197ac94e 506 UpdateConversion();
7fd59977 507 }
508
197ac94e 509 if (tosort)
510 {
511 UpdateSort();
512 }
7fd59977 513
514 return Standard_True;
515}
516
517
197ac94e 518//=======================================================================
7fd59977 519// Function: DisplaySensitive.
520// Purpose : Display active primitives.
197ac94e 521//=======================================================================
522void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(V3d_View)& theView)
7fd59977 523{
197ac94e 524 if (myToUpdateTolerance && SensitivityMode() == StdSelect_SM_WINDOW)
525 {
526 SetSensitivity (theView->Convert (myPixelTolerance));
527 myToUpdateTolerance = Standard_False;
528 }
529
530 if (toupdate)
531 {
532 UpdateProj (theView);
533 }
534
535 if (tosort)
7fd59977 536 {
197ac94e 537 UpdateSort(); // Updates the activated areas
7fd59977 538 }
7fd59977 539
540 // Preparation des structures
197ac94e 541 if (mystruct.IsNull())
542 {
543 mystruct = new Graphic3d_Structure (theView->Viewer()->Viewer());
544 }
545
546 if (mysensgroup.IsNull())
547 {
b64d84be 548 mysensgroup = mystruct->NewGroup();
197ac94e 549 }
7fd59977 550
197ac94e 551 Quantity_Color aColor (Quantity_NOC_INDIANRED3);
552 Handle(Graphic3d_AspectMarker3d) aMarkerAspect =
553 new Graphic3d_AspectMarker3d (Aspect_TOM_O_PLUS, aColor, 2.0);
7fd59977 554
197ac94e 555 mysensgroup->SetPrimitivesAspect (aMarkerAspect);
7fd59977 556 mysensgroup->SetPrimitivesAspect (
557 new Graphic3d_AspectLine3d (Quantity_NOC_GRAY40, Aspect_TOL_SOLID, 2.0));
558
197ac94e 559 SelectMgr_DataMapIteratorOfDataMapOfSelectionActivation anIt (myselections);
7fd59977 560
197ac94e 561 for (; anIt.More(); anIt.Next())
7fd59977 562 {
197ac94e 563 if (anIt.Value()==0)
7fd59977 564 {
197ac94e 565 const Handle(SelectMgr_Selection)& aSel = anIt.Key();
566 ComputeSensitivePrs (aSel);
7fd59977 567 }
568 }
7fd59977 569
197ac94e 570 mysensgroup->Structure()->SetDisplayPriority (10);
7fd59977 571 mystruct->Display();
197ac94e 572
679ecdee 573 theView->Update();
7fd59977 574}
575
197ac94e 576//=======================================================================
7fd59977 577// Function: ClearSensitive
578// Purpose :
197ac94e 579//=======================================================================
580void StdSelect_ViewerSelector3d::ClearSensitive (const Handle(V3d_View)& theView)
7fd59977 581{
197ac94e 582 if (mysensgroup.IsNull())
583 {
584 return;
585 }
586
7fd59977 587 mysensgroup->Clear();
7fd59977 588
197ac94e 589 if (theView.IsNull())
590 {
591 return;
592 }
593
679ecdee 594 theView->Update();
7fd59977 595}
596
597//=======================================================================
598//function : DisplaySenstive
599//purpose :
600//=======================================================================
197ac94e 601void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(SelectMgr_Selection)& theSel,
602 const Handle(V3d_View)& theView,
603 const Standard_Boolean theToClearOthers)
7fd59977 604{
605 if (mystruct.IsNull())
197ac94e 606 {
607 mystruct = new Graphic3d_Structure (theView->Viewer()->Viewer());
608 }
609
7fd59977 610 if (mysensgroup.IsNull())
611 {
b64d84be 612 mysensgroup = mystruct->NewGroup();
197ac94e 613 Quantity_Color aColor (Quantity_NOC_INDIANRED3);
614 Handle(Graphic3d_AspectMarker3d) aMarkerAspect =
615 new Graphic3d_AspectMarker3d (Aspect_TOM_O_PLUS, aColor, 2.0);
616
617 mysensgroup-> SetPrimitivesAspect (aMarkerAspect);
7fd59977 618 mysensgroup->SetPrimitivesAspect (
619 new Graphic3d_AspectLine3d (Quantity_NOC_GRAY40, Aspect_TOL_SOLID, 2.0));
620 }
621
197ac94e 622 if (theToClearOthers)
623 {
624 mysensgroup->Clear();
625 }
7fd59977 626
197ac94e 627 ComputeSensitivePrs (theSel);
7fd59977 628
197ac94e 629 mystruct->SetDisplayPriority (10);
7fd59977 630 mystruct->Display();
679ecdee 631
632 theView->Update();
7fd59977 633}
634
635//=======================================================================
636//function : DisplayAreas
637//purpose :
638//=======================================================================
197ac94e 639void StdSelect_ViewerSelector3d::DisplayAreas (const Handle(SelectMgr_Selection)& theSel,
640 const Handle(V3d_View)& theView,
641 const Standard_Boolean theToClearOthers)
7fd59977 642{
643 if (mystruct.IsNull())
197ac94e 644 {
645 mystruct = new Graphic3d_Structure (theView->Viewer()->Viewer());
646 }
b8ddfc2f 647
7fd59977 648 if (mysensgroup.IsNull())
649 {
b64d84be 650 myareagroup = mystruct->NewGroup();
651 myareagroup->SetGroupPrimitivesAspect (new Graphic3d_AspectLine3d (Quantity_NOC_AQUAMARINE1, Aspect_TOL_DASH, 1.0));
7fd59977 652 }
653
197ac94e 654 if (theToClearOthers)
655 {
656 myareagroup->Clear();
657 }
7fd59977 658
197ac94e 659 ComputeAreasPrs (theSel);
7fd59977 660
197ac94e 661 mystruct->SetDisplayPriority (10);
7fd59977 662 mystruct->Display();
663
679ecdee 664 theView->Update();
7fd59977 665}
666
667//=======================================================================
668//function : ComputeSensitivePrs
669//purpose :
670//=======================================================================
197ac94e 671void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Selection)& theSel)
7fd59977 672{
b8ddfc2f 673 TColgp_SequenceOfPnt aSeqLines, aSeqFree;
674 TColStd_SequenceOfInteger aSeqBnds;
675
197ac94e 676 for (theSel->Init(); theSel->More(); theSel->Next())
7fd59977 677 {
197ac94e 678 Handle(Select3D_SensitiveEntity) Ent = Handle(Select3D_SensitiveEntity)::DownCast(theSel->Sensitive());
b8ddfc2f 679 const Standard_Boolean hasloc = (Ent.IsNull()? Standard_False : Ent->HasLocation());
7fd59977 680
681 TopLoc_Location theloc;
682 if(hasloc)
683 theloc = Ent->Location();
684
685 //==============
686 // Box
687 //=============
688
689 if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveBox))
690 {
691 const Bnd_Box& B = Handle(Select3D_SensitiveBox)::DownCast (Ent)->Box();
692 Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
693 B.Get (xmin, ymin, zmin, xmax, ymax, zmax);
b8ddfc2f 694 Standard_Integer i;
7fd59977 695 gp_Pnt theboxpoint[8] =
696 {
697 gp_Pnt(xmin,ymin,zmin),
698 gp_Pnt(xmax,ymin,zmin),
699 gp_Pnt(xmax,ymax,zmin),
700 gp_Pnt(xmin,ymax,zmin),
701 gp_Pnt(xmin,ymin,zmax),
702 gp_Pnt(xmax,ymin,zmax),
703 gp_Pnt(xmax,ymax,zmax),
704 gp_Pnt(xmin,ymax,zmax)
705 };
706 if(hasloc)
707 {
b8ddfc2f 708 for (i = 0; i <= 7; i++)
709 theboxpoint[i].Transform (theloc.Transformation());
7fd59977 710 }
7fd59977 711
b8ddfc2f 712 aSeqBnds.Append(5);
713 for (i = 0; i < 4; i++)
714 aSeqLines.Append(theboxpoint[i]);
715 aSeqLines.Append(theboxpoint[0]);
716
717 aSeqBnds.Append(5);
718 for (i = 4; i < 8; i++)
719 aSeqLines.Append(theboxpoint[i]);
720 aSeqLines.Append(theboxpoint[4]);
7fd59977 721
b8ddfc2f 722 for (i = 0; i < 4; i++)
7fd59977 723 {
b8ddfc2f 724 aSeqBnds.Append(2);
725 aSeqLines.Append(theboxpoint[i]);
726 aSeqLines.Append(theboxpoint[i+4]);
7fd59977 727 }
728 }
729 //==============
730 // Face
731 //=============
732 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveFace))
733 {
734 Handle(Select3D_SensitiveFace) aFace = Handle(Select3D_SensitiveFace)::DownCast(Ent);
735 Handle(TColgp_HArray1OfPnt) TheHPts;
736 aFace->Points3D(TheHPts);
737 const TColgp_Array1OfPnt& ThePts = TheHPts->Array1();
738
b8ddfc2f 739 aSeqBnds.Append(ThePts.Length());
7fd59977 740 for (Standard_Integer I = ThePts.Lower(); I <= ThePts.Upper(); I++)
741 {
742 if (hasloc)
b8ddfc2f 743 aSeqLines.Append(ThePts(I).Transformed (theloc.Transformation()));
7fd59977 744 else
b8ddfc2f 745 aSeqLines.Append(ThePts(I));
7fd59977 746 }
7fd59977 747 }
748 //==============
749 // Curve
750 //=============
751 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveCurve))
752 {
753 Handle(Select3D_SensitiveCurve) aCurve = Handle(Select3D_SensitiveCurve)::DownCast(Ent);
754 Handle(TColgp_HArray1OfPnt) TheHPts;
755 aCurve->Points3D(TheHPts);
756 const TColgp_Array1OfPnt& ThePts = TheHPts->Array1();
757
b8ddfc2f 758 aSeqBnds.Append(ThePts.Length());
7fd59977 759 for (Standard_Integer I = ThePts.Lower(); I <= ThePts.Upper(); I++)
760 {
761 if (hasloc)
b8ddfc2f 762 aSeqLines.Append(ThePts(I).Transformed (theloc.Transformation()));
7fd59977 763 else
b8ddfc2f 764 aSeqLines.Append(ThePts(I));
7fd59977 765 }
7fd59977 766 }
767 //==============
768 // Wire
769 //=============
770 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveWire))
771 {
b8ddfc2f 772 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast(Ent);
773 Select3D_SensitiveEntitySequence EntitySeq;
774 aWire->GetEdges (EntitySeq);
7fd59977 775
776 for (int i = 1; i <= EntitySeq.Length(); i++)
777 {
778 Handle(Select3D_SensitiveEntity) SubEnt = Handle(Select3D_SensitiveEntity)::DownCast(EntitySeq.Value(i));
779
780 //Segment
781 if (SubEnt->DynamicType()==STANDARD_TYPE(Select3D_SensitiveSegment))
782 {
7fd59977 783 gp_Pnt P1 (Handle(Select3D_SensitiveSegment)::DownCast(SubEnt)->StartPoint().XYZ());
784 gp_Pnt P2 (Handle(Select3D_SensitiveSegment)::DownCast(SubEnt)->EndPoint().XYZ());
785 if (hasloc)
786 {
787 P1.Transform(theloc.Transformation());
788 P2.Transform(theloc.Transformation());
789 }
b8ddfc2f 790 aSeqBnds.Append(2);
791 aSeqLines.Append(P1);
792 aSeqLines.Append(P2);
7fd59977 793 }
794
795 //circle
796 if (SubEnt->DynamicType()==STANDARD_TYPE(Select3D_SensitiveCircle))
797 {
798 Handle(Select3D_SensitiveCircle) C = Handle(Select3D_SensitiveCircle)::DownCast(SubEnt);
799 Standard_Integer Lo, Up;
800 C->ArrayBounds (Lo, Up);
801 Standard_Integer II = Lo;
802 while (II <= Up - 2)
803 {
7fd59977 804 gp_Pnt ThePts[3] =
805 {
806 gp_Pnt (C->GetPoint3d (II).XYZ()),
807 gp_Pnt (C->GetPoint3d (++II).XYZ()),
808 gp_Pnt (C->GetPoint3d (++II).XYZ())
809 };
810
811 if (hasloc)
812 {
813 for (Standard_Integer jj = 0; jj <= 2; jj++)
814 ThePts[jj].Transform (theloc.Transformation());
815 }
816
b8ddfc2f 817 aSeqBnds.Append(4);
818 aSeqLines.Append(ThePts[0]);
819 aSeqLines.Append(ThePts[1]);
820 aSeqLines.Append(ThePts[2]);
821 aSeqLines.Append(ThePts[0]);
7fd59977 822 }
823 }
824
825 //curve
826 if (SubEnt->DynamicType()==STANDARD_TYPE(Select3D_SensitiveCurve))
827 {
828 Handle(Select3D_SensitiveCurve) aCurve = Handle(Select3D_SensitiveCurve)::DownCast(SubEnt);
829 Handle(TColgp_HArray1OfPnt) TheHPts;
830 aCurve->Points3D (TheHPts);
831 const TColgp_Array1OfPnt& ThePts = TheHPts->Array1();
b8ddfc2f 832
833 aSeqBnds.Append(ThePts.Length());
7fd59977 834 for (Standard_Integer I = ThePts.Lower(); I <= ThePts.Upper(); I++)
835 {
836 if (hasloc)
b8ddfc2f 837 aSeqLines.Append(ThePts(I).Transformed (theloc.Transformation()));
7fd59977 838 else
b8ddfc2f 839 aSeqLines.Append(ThePts(I));
7fd59977 840 }
7fd59977 841 }
842 }
843 }
844 //==============
845 // Segment
846 //=============
847 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveSegment))
848 {
7fd59977 849 gp_Pnt P1 (Handle(Select3D_SensitiveSegment)::DownCast(Ent)->StartPoint().XYZ());
850 gp_Pnt P2 (Handle(Select3D_SensitiveSegment)::DownCast(Ent)->EndPoint().XYZ());
851 if (hasloc)
852 {
853 P1.Transform (theloc.Transformation());
854 P2.Transform (theloc.Transformation());
855 }
b8ddfc2f 856 aSeqBnds.Append(2);
857 aSeqLines.Append(P1);
858 aSeqLines.Append(P2);
7fd59977 859 }
860 //==============
861 // Circle
862 //=============
863 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveCircle))
864 {
865 Handle(Select3D_SensitiveCircle) C = Handle(Select3D_SensitiveCircle)::DownCast(Ent);
866 Standard_Integer Lo, Up;
867 C->ArrayBounds (Lo, Up);
868 Standard_Integer II = Lo;
869 while (II <= Up - 2)
870 {
7fd59977 871 gp_Pnt ThePts[3] =
872 {
873 gp_Pnt (C->GetPoint3d (II).XYZ()),
874 gp_Pnt (C->GetPoint3d (++II).XYZ()),
875 gp_Pnt (C->GetPoint3d (++II).XYZ())
876 };
877
878 if (hasloc)
879 {
880 for (Standard_Integer jj = 0; jj <= 2; jj++)
881 ThePts[jj].Transform (theloc.Transformation());
882 }
883
b8ddfc2f 884 aSeqBnds.Append(4);
885 aSeqLines.Append(ThePts[0]);
886 aSeqLines.Append(ThePts[1]);
887 aSeqLines.Append(ThePts[2]);
888 aSeqLines.Append(ThePts[0]);
7fd59977 889 }
890 }
891 //==============
892 // Point
893 //=============
894 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitivePoint))
895 {
896 gp_Pnt P = hasloc ?
897 Handle(Select3D_SensitivePoint)::DownCast(Ent)->Point() :
898 Handle(Select3D_SensitivePoint)::DownCast(Ent)->Point().Transformed (theloc.Transformation());
a577aaab 899 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
900 anArrayOfPoints->AddVertex (P.X(), P.Y(), P.Z());
901 mysensgroup->AddPrimitiveArray (anArrayOfPoints);
7fd59977 902 }
903 //============================================================
904 // Triangulation : On met un petit offset ves l'interieur...
905 //==========================================================
906 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveTriangulation))
907 {
908 const Handle(Poly_Triangulation)& PT =
909 (*((Handle(Select3D_SensitiveTriangulation)*) &Ent))->Triangulation();
910
911 const Poly_Array1OfTriangle& triangles = PT->Triangles();
912 const TColgp_Array1OfPnt& Nodes = PT->Nodes();
7fd59977 913 Standard_Integer n[3];
7fd59977 914
915 TopLoc_Location iloc, bidloc;
916 if ((*((Handle(Select3D_SensitiveTriangulation)*) &Ent))->HasInitLocation())
917 bidloc = (*((Handle(Select3D_SensitiveTriangulation)*) &Ent))->GetInitLocation();
918
919 if (bidloc.IsIdentity())
920 iloc = theloc;
921 else
922 iloc = theloc * bidloc;
923
924 Standard_Integer i;
925 for (i = 1; i <= PT->NbTriangles(); i++)
926 {
927 triangles (i).Get (n[0], n[1], n[2]);
928 gp_Pnt P1 (Nodes (n[0]).Transformed (iloc));
929 gp_Pnt P2 (Nodes (n[1]).Transformed (iloc));
930 gp_Pnt P3 (Nodes (n[2]).Transformed (iloc));
931 gp_XYZ V1 (P1.XYZ());
932 gp_XYZ V2 (P2.XYZ());
933 gp_XYZ V3 (P3.XYZ());
934 gp_XYZ CDG (P1.XYZ()); CDG += (P2.XYZ()); CDG += (P3.XYZ()); CDG /= 3.0;
7fd59977 935 V1 -= CDG; V2 -= CDG; V3 -= CDG;
7fd59977 936 V1 *= 0.9; V2 *= 0.9; V3 *= 0.9;
937 V1 += CDG; V2 += CDG; V3 += CDG;
b8ddfc2f 938
939 aSeqBnds.Append(4);
940 aSeqLines.Append(gp_Pnt(V1));
941 aSeqLines.Append(gp_Pnt(V2));
942 aSeqLines.Append(gp_Pnt(V3));
943 aSeqLines.Append(gp_Pnt(V1));
7fd59977 944 }
945
946 // recherche des bords libres...
947
948 Handle(TColStd_HArray1OfInteger) FreeEdges = new TColStd_HArray1OfInteger (1, 2 * StdSel_NumberOfFreeEdges (PT));
949 TColStd_Array1OfInteger& FreeE = FreeEdges->ChangeArray1();
950 Poly_Connect pc (PT);
951 Standard_Integer t[3];
952 Standard_Integer j;
953 Standard_Integer fr (1);
954 for (i = 1; i <= PT->NbTriangles(); i++)
955 {
956 pc.Triangles (i, t[0], t[1], t[2]);
957 triangles (i).Get (n[0], n[1], n[2]);
958 for (j = 0; j < 3; j++)
959 {
960 Standard_Integer k = (j + 1) % 3;
961 if (t[j] == 0)
962 {
963 FreeE (fr) = n[j];
964 FreeE (fr + 1)= n[k];
965 fr += 2;
966 }
967 }
968 }
7fd59977 969 for (Standard_Integer ifri = 1; ifri <= FreeE.Length(); ifri += 2)
970 {
b8ddfc2f 971 gp_Pnt pe1 (Nodes (FreeE (ifri)).Transformed (iloc)), pe2 (Nodes (FreeE (ifri + 1)).Transformed (iloc));
972 aSeqFree.Append(pe1);
973 aSeqFree.Append(pe2);
7fd59977 974 }
7fd59977 975 }
976 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveTriangle))
977 {
978 Handle(Select3D_SensitiveTriangle) Str = Handle(Select3D_SensitiveTriangle)::DownCast(Ent);
b8ddfc2f 979 gp_Pnt P1, P2, P3;
7fd59977 980 Str->Points3D (P1, P2, P3);
b8ddfc2f 981 gp_Pnt CDG = Str->Center3D();
7fd59977 982
983 gp_XYZ V1 (P1.XYZ()); V1 -= (CDG.XYZ());
984 gp_XYZ V2 (P2.XYZ()); V2 -= (CDG.XYZ());
985 gp_XYZ V3 (P3.XYZ()); V3 -= (CDG.XYZ());
7fd59977 986 V1 *= 0.9; V2 *= 0.9; V3 *= 0.9;
987 V1 += CDG.XYZ(); V2 += CDG.XYZ(); V3 += CDG.XYZ();
b8ddfc2f 988
989 aSeqBnds.Append(4);
990 aSeqLines.Append(gp_Pnt(V1));
991 aSeqLines.Append(gp_Pnt(V2));
992 aSeqLines.Append(gp_Pnt(V3));
993 aSeqLines.Append(gp_Pnt(V1));
7fd59977 994 }
995 }
b8ddfc2f 996
997 Standard_Integer i;
998
999 if (aSeqLines.Length())
1000 {
1001 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(aSeqLines.Length(),aSeqBnds.Length());
1002 for (i = 1; i <= aSeqLines.Length(); i++)
1003 aPrims->AddVertex(aSeqLines(i));
1004 for (i = 1; i <= aSeqBnds.Length(); i++)
1005 aPrims->AddBound(aSeqBnds(i));
1006 myareagroup->AddPrimitiveArray(aPrims);
1007 }
1008
1009 if (aSeqFree.Length())
1010 {
1011 mysensgroup->SetPrimitivesAspect (new Graphic3d_AspectLine3d (Quantity_NOC_GREEN, Aspect_TOL_SOLID, 2.0));
1012 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(aSeqFree.Length(),aSeqFree.Length()/2);
1013 for (i = 1; i <= aSeqFree.Length(); i++)
197ac94e 1014 {
b8ddfc2f 1015 aPrims->AddBound(2);
1016 aPrims->AddVertex(aSeqLines(i++));
1017 aPrims->AddVertex(aSeqLines(i));
197ac94e 1018 }
b8ddfc2f 1019 mysensgroup->AddPrimitiveArray(aPrims);
1020 mysensgroup->SetPrimitivesAspect (new Graphic3d_AspectLine3d (Quantity_NOC_GRAY40, Aspect_TOL_SOLID, 2.0));
1021 }
7fd59977 1022}
1023
1024//=======================================================================
1025//function : ComputeAreaPrs
1026//purpose :
1027//=======================================================================
197ac94e 1028void StdSelect_ViewerSelector3d::ComputeAreasPrs (const Handle(SelectMgr_Selection)& theSel)
7fd59977 1029{
197ac94e 1030 Standard_Real aXmin = 0.0;
1031 Standard_Real aYmin = 0.0;
1032 Standard_Real aXmax = 0.0;
1033 Standard_Real aYmax = 0.0;
1034
1035 gp_Pnt aPbid;
1036 SelectBasics_ListOfBox2d aBoxList;
7fd59977 1037
b8ddfc2f 1038 TColgp_SequenceOfPnt aSeqLines;
197ac94e 1039 for (theSel->Init(); theSel->More(); theSel->Next())
7fd59977 1040 {
197ac94e 1041 theSel->Sensitive()->Areas (aBoxList);
1042 for (SelectBasics_ListIteratorOfListOfBox2d aBoxIt (aBoxList); aBoxIt.More(); aBoxIt.Next())
7fd59977 1043 {
197ac94e 1044 aBoxIt.Value().Get (aXmin, aYmin, aXmax, aYmax);
7fd59977 1045
197ac94e 1046 aPbid.SetCoord (aXmin - mytolerance, aYmin - mytolerance, 0.0);
1047 myProjector->Transform (aPbid, myProjector->InvertedTransformation());
1048 aSeqLines.Append (aPbid);
7fd59977 1049
197ac94e 1050 aPbid.SetCoord (aXmax + mytolerance, aYmin - mytolerance, 0.0);
1051 myProjector->Transform (aPbid, myProjector->InvertedTransformation());
1052 aSeqLines.Append (aPbid);
7fd59977 1053
197ac94e 1054 aPbid.SetCoord (aXmax + mytolerance, aYmax + mytolerance, 0.0);
1055 myProjector->Transform (aPbid, myProjector->InvertedTransformation());
1056 aSeqLines.Append (aPbid);
7fd59977 1057
197ac94e 1058 aPbid.SetCoord (aXmin - mytolerance, aYmax + mytolerance, 0.0);
1059 myProjector->Transform (aPbid, myProjector->InvertedTransformation());
1060 aSeqLines.Append (aPbid);
b8ddfc2f 1061 }
1062 }
7fd59977 1063
b8ddfc2f 1064 if (aSeqLines.Length())
1065 {
197ac94e 1066 Standard_Integer aN = 0;
1067 Standard_Integer aNP = 0;
1068 const Standard_Integer aNBL = aSeqLines.Length() / 4;
1069 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines (5 * aNBL, aNBL);
1070 for (aNP = 1, aN = 0; aN < aNBL; aN++)
1071 {
1072 aPrims->AddBound (5);
1073 const gp_Pnt &aP1 = aSeqLines (aNP++);
1074 aPrims->AddVertex (aP1);
1075 aPrims->AddVertex (aSeqLines (aNP++));
1076 aPrims->AddVertex (aSeqLines (aNP++));
1077 aPrims->AddVertex (aSeqLines (aNP++));
1078 aPrims->AddVertex (aP1);
7fd59977 1079 }
197ac94e 1080 myareagroup->AddPrimitiveArray (aPrims);
7fd59977 1081 }
1082}
1083
1084//=======================================================================
4269bd1b 1085//function : SetClipping
7fd59977 1086//purpose :
1087//=======================================================================
51b10cd4 1088void StdSelect_ViewerSelector3d::SetClipping (const Graphic3d_SequenceOfHClipPlane& thePlanes)
7fd59977 1089{
4269bd1b 1090 myClipPlanes = thePlanes;
1091}
1092
1093//=======================================================================
1094//function : ComputeClipRange
1095//purpose :
1096//=======================================================================
51b10cd4 1097void StdSelect_ViewerSelector3d::ComputeClipRange (const Graphic3d_SequenceOfHClipPlane& thePlanes,
4269bd1b 1098 const gp_Lin& thePickLine,
1099 Standard_Real& theDepthMin,
1100 Standard_Real& theDepthMax) const
1101{
1102 theDepthMin = RealFirst();
1103 theDepthMax = RealLast();
1104 Standard_Real aPlaneA, aPlaneB, aPlaneC, aPlaneD;
1105
51b10cd4 1106 Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (thePlanes);
4269bd1b 1107 for (; aPlaneIt.More(); aPlaneIt.Next())
7fd59977 1108 {
4269bd1b 1109 const Handle(Graphic3d_ClipPlane)& aClipPlane = aPlaneIt.Value();
1110 if (!aClipPlane->IsOn())
1111 continue;
1112
1113 gp_Pln aGeomPlane = aClipPlane->ToPlane();
1114
1115 aGeomPlane.Coefficients (aPlaneA, aPlaneB, aPlaneC, aPlaneD);
1116
1117 const gp_Dir& aPlaneDir = aGeomPlane.Axis().Direction();
1118 const gp_Dir& aPickDir = thePickLine.Direction();
1119 const gp_XYZ& aPntOnLine = thePickLine.Location().XYZ();
1120 const gp_XYZ& aPlaneDirXYZ = aPlaneDir.XYZ();
1121
1122 Standard_Real aDotProduct = aPickDir.Dot (aPlaneDir);
1123 Standard_Real aDistance = -(aPntOnLine.Dot (aPlaneDirXYZ) + aPlaneD);
1124
1125 // check whether the pick line is parallel to clip plane
1126 if (Abs (aDotProduct) < Precision::Angular())
7fd59977 1127 {
4269bd1b 1128 if (aDistance > 0.0)
1129 {
1130 // line lies above the plane, thus no selection is possible
1131 theDepthMin = 0.0;
1132 theDepthMax = 0.0;
1133 return;
1134 }
1135
1136 // line lies below the plane and is not clipped, skip
1137 continue;
1138 }
1139
1140 // compute distance to point of pick line intersection with the plane
1141 Standard_Real aIntDist = aDistance / aDotProduct;
1142
1143 // change depth limits for case of opposite and directed planes
1144 if (aDotProduct < 0.0)
1145 {
1146 theDepthMax = Min (aIntDist, theDepthMax);
1147 }
1148 else if (aIntDist > theDepthMin)
1149 {
1150 theDepthMin = Max (aIntDist, theDepthMin);
7fd59977 1151 }
1152 }
1153}
4269bd1b 1154
1155//=======================================================================
1156//function : PickingLine
1157//purpose :
1158//=======================================================================
1159gp_Lin StdSelect_ViewerSelector3d::PickingLine(const Standard_Real theX, const Standard_Real theY) const
1160{
197ac94e 1161 return myProjector->Shoot (theX, theY);
4269bd1b 1162}
1163
1164//=======================================================================
1165//function : DepthClipping
1166//purpose :
1167//=======================================================================
1168void StdSelect_ViewerSelector3d::DepthClipping (const Standard_Real theX,
1169 const Standard_Real theY,
1170 Standard_Real& theDepthMin,
1171 Standard_Real& theDepthMax) const
1172{
1173 return ComputeClipRange (myClipPlanes, PickingLine (theX, theY), theDepthMin, theDepthMax);
1174}
1175
1176//=======================================================================
1177//function : DepthClipping
1178//purpose :
1179//=======================================================================
1180void StdSelect_ViewerSelector3d::DepthClipping (const Standard_Real theX,
1181 const Standard_Real theY,
1182 const Handle(SelectMgr_EntityOwner)& theOwner,
1183 Standard_Real& theDepthMin,
1184 Standard_Real& theDepthMax) const
1185{
1186 return ComputeClipRange (theOwner->Selectable()->GetClipPlanes(),
1187 PickingLine (theX, theY),
1188 theDepthMin, theDepthMax);
1189}
1190
1191//=======================================================================
1192//function : HasDepthClipping
1193//purpose :
1194//=======================================================================
1195Standard_Boolean StdSelect_ViewerSelector3d::HasDepthClipping (const Handle(SelectMgr_EntityOwner)& theOwner) const
1196{
1197 if (!theOwner->HasSelectable())
1198 {
1199 return Standard_False;
1200 }
1201
1202 const Handle(SelectMgr_SelectableObject)& aSelectable = theOwner->Selectable();
1203 return (aSelectable->GetClipPlanes().Size() > 0);
1204}