0024947: Redesign OCCT legacy type system -- automatic
[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
f751596e 17#include <StdSelect_ViewerSelector3d.hxx>
7fd59977 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>
f751596e 30#include <Graphic3d_Group.hxx>
51b10cd4 31#include <Graphic3d_SequenceOfHClipPlane.hxx>
f751596e 32#include <Graphic3d_Structure.hxx>
4269bd1b 33#include <SelectMgr_SelectableObject.hxx>
7fd59977 34#include <TColgp_HArray1OfPnt.hxx>
35#include <TColgp_Array1OfPnt.hxx>
f751596e 36#include <TColgp_Array1OfPnt2d.hxx>
7fd59977 37#include <TColgp_HArray1OfPnt2d.hxx>
38#include <Select3D_SensitiveCurve.hxx>
39#include <Select3D_SensitiveSegment.hxx>
40#include <Select3D_SensitiveFace.hxx>
41#include <Select3D_SensitiveCircle.hxx>
42#include <Select3D_SensitivePoint.hxx>
43#include <Select3D_SensitiveTriangulation.hxx>
44#include <Select3D_SensitiveTriangle.hxx>
45#include <Select3D_SensitiveWire.hxx>
7fd59977 46#include <Select3D_SensitiveBox.hxx>
f751596e 47#include <SelectMgr_Selection.hxx>
48#include <SelectMgr_EntityOwner.hxx>
7fd59977 49
679ecdee 50#include <Aspect_Grid.hxx>
7fd59977 51#include <Aspect_TypeOfMarker.hxx>
f751596e 52#include <Aspect_Window.hxx>
7fd59977 53#include <Graphic3d_AspectMarker3d.hxx>
a577aaab 54#include <Graphic3d_ArrayOfPoints.hxx>
7fd59977 55#include <Poly_Connect.hxx>
56#include <TColStd_HArray1OfInteger.hxx>
57
58#include <Poly_Array1OfTriangle.hxx>
59#include <Poly_Triangulation.hxx>
60#include <OSD_Environment.hxx>
61#include <V3d.hxx>
62#include <V3d_View.hxx>
679ecdee 63#include <V3d_Viewer.hxx>
b8ddfc2f 64#include <TColgp_SequenceOfPnt.hxx>
65
f751596e 66#include <OSD_Timer.hxx>
67
f751596e 68
7fd59977 69static Standard_Integer StdSel_NumberOfFreeEdges (const Handle(Poly_Triangulation)& Trg)
70{
71 Standard_Integer nFree = 0;
72 Poly_Connect pc(Trg);
73 Standard_Integer t[3];
74 Standard_Integer i, j;
75 for (i = 1; i <= Trg->NbTriangles(); i++)
76 {
77 pc.Triangles (i, t[0], t[1], t[2]);
78 for (j = 0; j < 3; j++)
79 if (t[j] == 0) nFree++;
80 }
81 return nFree;
82}
83
197ac94e 84//=======================================================================
85// Function : Constructor
86// Purpose :
87//=======================================================================
f751596e 88StdSelect_ViewerSelector3d::StdSelect_ViewerSelector3d() {}
3c982548 89
197ac94e 90//=======================================================================
3c982548 91// Function: SetPixelTolerance
92// Purpose :
197ac94e 93//=======================================================================
f751596e 94void StdSelect_ViewerSelector3d::SetPixelTolerance (const Standard_Real theTolerance)
3c982548 95{
f751596e 96 if (mytolerance != theTolerance)
3c982548 97 {
28ee613b 98 if (theTolerance < 0.0)
99 myTolerances.ResetDefaults();
100 else
101 myTolerances.SetCustomTolerance (theTolerance);
102 mytolerance = myTolerances.Tolerance();
197ac94e 103 myToUpdateTolerance = Standard_True;
3c982548 104 }
7fd59977 105}
106
197ac94e 107//=======================================================================
108// Function: Pick
7fd59977 109// Purpose :
197ac94e 110//=======================================================================
111void StdSelect_ViewerSelector3d::Pick (const Standard_Integer theXPix,
112 const Standard_Integer theYPix,
113 const Handle(V3d_View)& theView)
7fd59977 114{
197ac94e 115 SetClipping (theView->GetClipPlanes());
197ac94e 116
f751596e 117 if(myToUpdateTolerance)
118 {
119 mySelectingVolumeMgr.SetPixelTolerance (mytolerance);
120 myToUpdateTolerance = Standard_False;
121 }
122
123 mySelectingVolumeMgr.SetCamera (theView->Camera());
124 mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Point);
125 Standard_Integer aWidth = 0, aHeight = 0;
126 theView->Window()->Size (aWidth, aHeight);
127 mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight);
128 gp_Pnt2d aMousePos (static_cast<Standard_Real> (theXPix),
129 static_cast<Standard_Real> (theYPix));
130 mySelectingVolumeMgr.BuildSelectingVolume (aMousePos);
7fd59977 131
f751596e 132 TraverseSensitives();
197ac94e 133}
7fd59977 134
197ac94e 135//=======================================================================
136// Function: Pick
7fd59977 137// Purpose :
197ac94e 138//=======================================================================
139void StdSelect_ViewerSelector3d::Pick (const Standard_Integer theXPMin,
140 const Standard_Integer theYPMin,
141 const Standard_Integer theXPMax,
142 const Standard_Integer theYPMax,
143 const Handle(V3d_View)& theView)
7fd59977 144{
f751596e 145 mySelectingVolumeMgr.SetCamera (theView->Camera());
146 mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Box);
147 Standard_Integer aWidth = 0, aHeight = 0;
148 theView->Window()->Size (aWidth, aHeight);
149 mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight);
150 gp_Pnt2d aMinMousePos (static_cast<Standard_Real> (theXPMin),
151 static_cast<Standard_Real> (theYPMin));
152 gp_Pnt2d aMaxMousePos (static_cast<Standard_Real> (theXPMax),
153 static_cast<Standard_Real> (theYPMax));
154 mySelectingVolumeMgr.BuildSelectingVolume (aMinMousePos,
155 aMaxMousePos);
156
157 TraverseSensitives();
7fd59977 158}
159
197ac94e 160//=======================================================================
7fd59977 161// Function: Pick
162// Purpose : Selection using a polyline
197ac94e 163//=======================================================================
164void StdSelect_ViewerSelector3d::Pick (const TColgp_Array1OfPnt2d& thePolyline,
165 const Handle(V3d_View)& theView)
7fd59977 166{
f751596e 167 mySelectingVolumeMgr.SetCamera (theView->Camera());
168 mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Polyline);
169 Standard_Integer aWidth = 0, aHeight = 0;
170 theView->Window()->Size (aWidth, aHeight);
171 mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight);
172 mySelectingVolumeMgr.BuildSelectingVolume (thePolyline);
173
174 TraverseSensitives();
7fd59977 175}
176
197ac94e 177//=======================================================================
7fd59977 178// Function: DisplaySensitive.
179// Purpose : Display active primitives.
197ac94e 180//=======================================================================
181void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(V3d_View)& theView)
7fd59977 182{
7fd59977 183 // Preparation des structures
197ac94e 184 if (mystruct.IsNull())
185 {
186 mystruct = new Graphic3d_Structure (theView->Viewer()->Viewer());
187 }
188
189 if (mysensgroup.IsNull())
190 {
b64d84be 191 mysensgroup = mystruct->NewGroup();
197ac94e 192 }
7fd59977 193
197ac94e 194 Quantity_Color aColor (Quantity_NOC_INDIANRED3);
195 Handle(Graphic3d_AspectMarker3d) aMarkerAspect =
196 new Graphic3d_AspectMarker3d (Aspect_TOM_O_PLUS, aColor, 2.0);
7fd59977 197
197ac94e 198 mysensgroup->SetPrimitivesAspect (aMarkerAspect);
7fd59977 199 mysensgroup->SetPrimitivesAspect (
200 new Graphic3d_AspectLine3d (Quantity_NOC_GRAY40, Aspect_TOL_SOLID, 2.0));
201
f751596e 202 for (Standard_Integer anObjectIdx = 0; anObjectIdx <= mySelectableObjects->Size(); ++anObjectIdx)
7fd59977 203 {
f751596e 204 const Handle (SelectMgr_SelectableObject)& anObject = mySelectableObjects->GetObjectById (anObjectIdx);
205 for (anObject->Init(); anObject->More(); anObject->Next())
7fd59977 206 {
f751596e 207 if (anObject->CurrentSelection()->GetSelectionState() == SelectMgr_SOS_Activated)
208 {
209 ComputeSensitivePrs (anObject->CurrentSelection(), anObject->Transformation());
210 }
7fd59977 211 }
212 }
7fd59977 213
197ac94e 214 mysensgroup->Structure()->SetDisplayPriority (10);
7fd59977 215 mystruct->Display();
197ac94e 216
679ecdee 217 theView->Update();
7fd59977 218}
219
197ac94e 220//=======================================================================
7fd59977 221// Function: ClearSensitive
222// Purpose :
197ac94e 223//=======================================================================
224void StdSelect_ViewerSelector3d::ClearSensitive (const Handle(V3d_View)& theView)
7fd59977 225{
197ac94e 226 if (mysensgroup.IsNull())
227 {
228 return;
229 }
230
7fd59977 231 mysensgroup->Clear();
7fd59977 232
197ac94e 233 if (theView.IsNull())
234 {
235 return;
236 }
237
679ecdee 238 theView->Update();
7fd59977 239}
240
241//=======================================================================
242//function : DisplaySenstive
243//purpose :
244//=======================================================================
197ac94e 245void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(SelectMgr_Selection)& theSel,
f751596e 246 const gp_Trsf& theTrsf,
197ac94e 247 const Handle(V3d_View)& theView,
248 const Standard_Boolean theToClearOthers)
7fd59977 249{
250 if (mystruct.IsNull())
197ac94e 251 {
252 mystruct = new Graphic3d_Structure (theView->Viewer()->Viewer());
253 }
254
7fd59977 255 if (mysensgroup.IsNull())
256 {
b64d84be 257 mysensgroup = mystruct->NewGroup();
197ac94e 258 Quantity_Color aColor (Quantity_NOC_INDIANRED3);
259 Handle(Graphic3d_AspectMarker3d) aMarkerAspect =
260 new Graphic3d_AspectMarker3d (Aspect_TOM_O_PLUS, aColor, 2.0);
261
262 mysensgroup-> SetPrimitivesAspect (aMarkerAspect);
7fd59977 263 mysensgroup->SetPrimitivesAspect (
264 new Graphic3d_AspectLine3d (Quantity_NOC_GRAY40, Aspect_TOL_SOLID, 2.0));
265 }
266
197ac94e 267 if (theToClearOthers)
268 {
269 mysensgroup->Clear();
270 }
7fd59977 271
f751596e 272 ComputeSensitivePrs (theSel, theTrsf);
7fd59977 273
197ac94e 274 mystruct->SetDisplayPriority (10);
7fd59977 275 mystruct->Display();
276
679ecdee 277 theView->Update();
7fd59977 278}
279
280//=======================================================================
281//function : ComputeSensitivePrs
282//purpose :
283//=======================================================================
f751596e 284void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Selection)& theSel,
285 const gp_Trsf& theLoc)
7fd59977 286{
b8ddfc2f 287 TColgp_SequenceOfPnt aSeqLines, aSeqFree;
288 TColStd_SequenceOfInteger aSeqBnds;
289
197ac94e 290 for (theSel->Init(); theSel->More(); theSel->Next())
7fd59977 291 {
f751596e 292 Handle(Select3D_SensitiveEntity) Ent =
293 Handle(Select3D_SensitiveEntity)::DownCast(theSel->Sensitive()->BaseSensitive());
294 const Standard_Boolean hasloc = theLoc.Form() != gp_Identity;
7fd59977 295
296 //==============
297 // Box
298 //=============
299
300 if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveBox))
301 {
302 const Bnd_Box& B = Handle(Select3D_SensitiveBox)::DownCast (Ent)->Box();
303 Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
304 B.Get (xmin, ymin, zmin, xmax, ymax, zmax);
b8ddfc2f 305 Standard_Integer i;
7fd59977 306 gp_Pnt theboxpoint[8] =
307 {
308 gp_Pnt(xmin,ymin,zmin),
309 gp_Pnt(xmax,ymin,zmin),
310 gp_Pnt(xmax,ymax,zmin),
311 gp_Pnt(xmin,ymax,zmin),
312 gp_Pnt(xmin,ymin,zmax),
313 gp_Pnt(xmax,ymin,zmax),
314 gp_Pnt(xmax,ymax,zmax),
315 gp_Pnt(xmin,ymax,zmax)
316 };
317 if(hasloc)
318 {
b8ddfc2f 319 for (i = 0; i <= 7; i++)
f751596e 320 theboxpoint[i].Transform (theLoc);
7fd59977 321 }
7fd59977 322
b8ddfc2f 323 aSeqBnds.Append(5);
324 for (i = 0; i < 4; i++)
325 aSeqLines.Append(theboxpoint[i]);
326 aSeqLines.Append(theboxpoint[0]);
327
328 aSeqBnds.Append(5);
329 for (i = 4; i < 8; i++)
330 aSeqLines.Append(theboxpoint[i]);
331 aSeqLines.Append(theboxpoint[4]);
7fd59977 332
b8ddfc2f 333 for (i = 0; i < 4; i++)
7fd59977 334 {
b8ddfc2f 335 aSeqBnds.Append(2);
336 aSeqLines.Append(theboxpoint[i]);
337 aSeqLines.Append(theboxpoint[i+4]);
7fd59977 338 }
339 }
340 //==============
341 // Face
342 //=============
343 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveFace))
344 {
345 Handle(Select3D_SensitiveFace) aFace = Handle(Select3D_SensitiveFace)::DownCast(Ent);
346 Handle(TColgp_HArray1OfPnt) TheHPts;
f751596e 347 aFace->GetPoints(TheHPts);
7fd59977 348 const TColgp_Array1OfPnt& ThePts = TheHPts->Array1();
349
b8ddfc2f 350 aSeqBnds.Append(ThePts.Length());
7fd59977 351 for (Standard_Integer I = ThePts.Lower(); I <= ThePts.Upper(); I++)
352 {
353 if (hasloc)
f751596e 354 aSeqLines.Append(ThePts(I).Transformed (theLoc));
7fd59977 355 else
b8ddfc2f 356 aSeqLines.Append(ThePts(I));
7fd59977 357 }
7fd59977 358 }
359 //==============
360 // Curve
361 //=============
362 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveCurve))
363 {
364 Handle(Select3D_SensitiveCurve) aCurve = Handle(Select3D_SensitiveCurve)::DownCast(Ent);
365 Handle(TColgp_HArray1OfPnt) TheHPts;
366 aCurve->Points3D(TheHPts);
367 const TColgp_Array1OfPnt& ThePts = TheHPts->Array1();
368
b8ddfc2f 369 aSeqBnds.Append(ThePts.Length());
7fd59977 370 for (Standard_Integer I = ThePts.Lower(); I <= ThePts.Upper(); I++)
371 {
372 if (hasloc)
f751596e 373 aSeqLines.Append(ThePts(I).Transformed (theLoc));
7fd59977 374 else
b8ddfc2f 375 aSeqLines.Append(ThePts(I));
7fd59977 376 }
7fd59977 377 }
378 //==============
379 // Wire
380 //=============
381 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveWire))
382 {
b8ddfc2f 383 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast(Ent);
f751596e 384 const NCollection_Vector<Handle(Select3D_SensitiveEntity)>& anEntities = aWire->GetEdges();
7fd59977 385
f751596e 386 for (int i = 0; i < anEntities.Length(); i++)
7fd59977 387 {
f751596e 388 Handle(Select3D_SensitiveEntity) SubEnt = Handle(Select3D_SensitiveEntity)::DownCast(anEntities.Value(i));
7fd59977 389
390 //Segment
391 if (SubEnt->DynamicType()==STANDARD_TYPE(Select3D_SensitiveSegment))
392 {
7fd59977 393 gp_Pnt P1 (Handle(Select3D_SensitiveSegment)::DownCast(SubEnt)->StartPoint().XYZ());
394 gp_Pnt P2 (Handle(Select3D_SensitiveSegment)::DownCast(SubEnt)->EndPoint().XYZ());
395 if (hasloc)
396 {
f751596e 397 P1.Transform(theLoc);
398 P2.Transform(theLoc);
7fd59977 399 }
b8ddfc2f 400 aSeqBnds.Append(2);
401 aSeqLines.Append(P1);
402 aSeqLines.Append(P2);
7fd59977 403 }
404
405 //circle
406 if (SubEnt->DynamicType()==STANDARD_TYPE(Select3D_SensitiveCircle))
407 {
d7515f9a 408 Handle(Select3D_SensitiveCircle) aCircle = Handle(Select3D_SensitiveCircle)::DownCast(SubEnt);
409 Standard_Integer aFrom, aTo;
410 aCircle->ArrayBounds (aFrom, aTo);
411 aTo -= 2;
412 for (Standard_Integer aPntIter = aFrom; aPntIter <= aTo; aPntIter += 2)
7fd59977 413 {
d7515f9a 414 gp_Pnt aPnts[3] =
7fd59977 415 {
d7515f9a 416 gp_Pnt (aCircle->GetPoint3d (aPntIter + 0).XYZ()),
417 gp_Pnt (aCircle->GetPoint3d (aPntIter + 1).XYZ()),
418 gp_Pnt (aCircle->GetPoint3d (aPntIter + 2).XYZ())
7fd59977 419 };
420
421 if (hasloc)
422 {
f751596e 423 aPnts[0].Transform (theLoc);
424 aPnts[1].Transform (theLoc);
425 aPnts[2].Transform (theLoc);
7fd59977 426 }
427
d7515f9a 428 aSeqBnds.Append (4);
429 aSeqLines.Append (aPnts[0]);
430 aSeqLines.Append (aPnts[1]);
431 aSeqLines.Append (aPnts[2]);
432 aSeqLines.Append (aPnts[0]);
7fd59977 433 }
434 }
435
436 //curve
437 if (SubEnt->DynamicType()==STANDARD_TYPE(Select3D_SensitiveCurve))
438 {
439 Handle(Select3D_SensitiveCurve) aCurve = Handle(Select3D_SensitiveCurve)::DownCast(SubEnt);
440 Handle(TColgp_HArray1OfPnt) TheHPts;
441 aCurve->Points3D (TheHPts);
442 const TColgp_Array1OfPnt& ThePts = TheHPts->Array1();
b8ddfc2f 443
444 aSeqBnds.Append(ThePts.Length());
7fd59977 445 for (Standard_Integer I = ThePts.Lower(); I <= ThePts.Upper(); I++)
446 {
447 if (hasloc)
f751596e 448 aSeqLines.Append(ThePts(I).Transformed (theLoc));
7fd59977 449 else
b8ddfc2f 450 aSeqLines.Append(ThePts(I));
7fd59977 451 }
7fd59977 452 }
453 }
454 }
455 //==============
456 // Segment
457 //=============
458 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveSegment))
459 {
7fd59977 460 gp_Pnt P1 (Handle(Select3D_SensitiveSegment)::DownCast(Ent)->StartPoint().XYZ());
461 gp_Pnt P2 (Handle(Select3D_SensitiveSegment)::DownCast(Ent)->EndPoint().XYZ());
462 if (hasloc)
463 {
f751596e 464 P1.Transform (theLoc);
465 P2.Transform (theLoc);
7fd59977 466 }
b8ddfc2f 467 aSeqBnds.Append(2);
468 aSeqLines.Append(P1);
469 aSeqLines.Append(P2);
7fd59977 470 }
471 //==============
472 // Circle
473 //=============
474 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveCircle))
475 {
d7515f9a 476 Handle(Select3D_SensitiveCircle) aCircle = Handle(Select3D_SensitiveCircle)::DownCast(Ent);
477 Standard_Integer aFrom, aTo;
478 aCircle->ArrayBounds (aFrom, aTo);
479 aTo -= 2;
480 for (Standard_Integer aPntIter = aFrom; aPntIter <= aTo; aPntIter += 2)
7fd59977 481 {
d7515f9a 482 gp_Pnt aPnts[3] =
7fd59977 483 {
d7515f9a 484 gp_Pnt (aCircle->GetPoint3d (aPntIter + 0).XYZ()),
485 gp_Pnt (aCircle->GetPoint3d (aPntIter + 1).XYZ()),
486 gp_Pnt (aCircle->GetPoint3d (aPntIter + 2).XYZ())
7fd59977 487 };
488
489 if (hasloc)
490 {
f751596e 491 aPnts[0].Transform (theLoc);
492 aPnts[1].Transform (theLoc);
493 aPnts[2].Transform (theLoc);
7fd59977 494 }
495
d7515f9a 496 aSeqBnds.Append (4);
497 aSeqLines.Append (aPnts[0]);
498 aSeqLines.Append (aPnts[1]);
499 aSeqLines.Append (aPnts[2]);
500 aSeqLines.Append (aPnts[0]);
7fd59977 501 }
502 }
503 //==============
504 // Point
505 //=============
506 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitivePoint))
507 {
508 gp_Pnt P = hasloc ?
509 Handle(Select3D_SensitivePoint)::DownCast(Ent)->Point() :
f751596e 510 Handle(Select3D_SensitivePoint)::DownCast(Ent)->Point().Transformed (theLoc);
a577aaab 511 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
512 anArrayOfPoints->AddVertex (P.X(), P.Y(), P.Z());
513 mysensgroup->AddPrimitiveArray (anArrayOfPoints);
7fd59977 514 }
515 //============================================================
516 // Triangulation : On met un petit offset ves l'interieur...
517 //==========================================================
518 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveTriangulation))
519 {
520 const Handle(Poly_Triangulation)& PT =
521 (*((Handle(Select3D_SensitiveTriangulation)*) &Ent))->Triangulation();
522
523 const Poly_Array1OfTriangle& triangles = PT->Triangles();
524 const TColgp_Array1OfPnt& Nodes = PT->Nodes();
7fd59977 525 Standard_Integer n[3];
7fd59977 526
527 TopLoc_Location iloc, bidloc;
528 if ((*((Handle(Select3D_SensitiveTriangulation)*) &Ent))->HasInitLocation())
529 bidloc = (*((Handle(Select3D_SensitiveTriangulation)*) &Ent))->GetInitLocation();
530
531 if (bidloc.IsIdentity())
f751596e 532 iloc = theLoc;
7fd59977 533 else
f751596e 534 iloc = theLoc * bidloc;
7fd59977 535
536 Standard_Integer i;
537 for (i = 1; i <= PT->NbTriangles(); i++)
538 {
539 triangles (i).Get (n[0], n[1], n[2]);
540 gp_Pnt P1 (Nodes (n[0]).Transformed (iloc));
541 gp_Pnt P2 (Nodes (n[1]).Transformed (iloc));
542 gp_Pnt P3 (Nodes (n[2]).Transformed (iloc));
543 gp_XYZ V1 (P1.XYZ());
544 gp_XYZ V2 (P2.XYZ());
545 gp_XYZ V3 (P3.XYZ());
546 gp_XYZ CDG (P1.XYZ()); CDG += (P2.XYZ()); CDG += (P3.XYZ()); CDG /= 3.0;
7fd59977 547 V1 -= CDG; V2 -= CDG; V3 -= CDG;
7fd59977 548 V1 *= 0.9; V2 *= 0.9; V3 *= 0.9;
549 V1 += CDG; V2 += CDG; V3 += CDG;
b8ddfc2f 550
551 aSeqBnds.Append(4);
552 aSeqLines.Append(gp_Pnt(V1));
553 aSeqLines.Append(gp_Pnt(V2));
554 aSeqLines.Append(gp_Pnt(V3));
555 aSeqLines.Append(gp_Pnt(V1));
7fd59977 556 }
557
558 // recherche des bords libres...
559
560 Handle(TColStd_HArray1OfInteger) FreeEdges = new TColStd_HArray1OfInteger (1, 2 * StdSel_NumberOfFreeEdges (PT));
561 TColStd_Array1OfInteger& FreeE = FreeEdges->ChangeArray1();
562 Poly_Connect pc (PT);
563 Standard_Integer t[3];
564 Standard_Integer j;
565 Standard_Integer fr (1);
566 for (i = 1; i <= PT->NbTriangles(); i++)
567 {
568 pc.Triangles (i, t[0], t[1], t[2]);
569 triangles (i).Get (n[0], n[1], n[2]);
570 for (j = 0; j < 3; j++)
571 {
572 Standard_Integer k = (j + 1) % 3;
573 if (t[j] == 0)
574 {
575 FreeE (fr) = n[j];
576 FreeE (fr + 1)= n[k];
577 fr += 2;
578 }
579 }
580 }
7fd59977 581 for (Standard_Integer ifri = 1; ifri <= FreeE.Length(); ifri += 2)
582 {
b8ddfc2f 583 gp_Pnt pe1 (Nodes (FreeE (ifri)).Transformed (iloc)), pe2 (Nodes (FreeE (ifri + 1)).Transformed (iloc));
584 aSeqFree.Append(pe1);
585 aSeqFree.Append(pe2);
7fd59977 586 }
7fd59977 587 }
588 else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveTriangle))
589 {
590 Handle(Select3D_SensitiveTriangle) Str = Handle(Select3D_SensitiveTriangle)::DownCast(Ent);
b8ddfc2f 591 gp_Pnt P1, P2, P3;
7fd59977 592 Str->Points3D (P1, P2, P3);
b8ddfc2f 593 gp_Pnt CDG = Str->Center3D();
7fd59977 594
595 gp_XYZ V1 (P1.XYZ()); V1 -= (CDG.XYZ());
596 gp_XYZ V2 (P2.XYZ()); V2 -= (CDG.XYZ());
597 gp_XYZ V3 (P3.XYZ()); V3 -= (CDG.XYZ());
7fd59977 598 V1 *= 0.9; V2 *= 0.9; V3 *= 0.9;
599 V1 += CDG.XYZ(); V2 += CDG.XYZ(); V3 += CDG.XYZ();
b8ddfc2f 600
601 aSeqBnds.Append(4);
602 aSeqLines.Append(gp_Pnt(V1));
603 aSeqLines.Append(gp_Pnt(V2));
604 aSeqLines.Append(gp_Pnt(V3));
605 aSeqLines.Append(gp_Pnt(V1));
7fd59977 606 }
607 }
b8ddfc2f 608
609 Standard_Integer i;
610
611 if (aSeqLines.Length())
612 {
613 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(aSeqLines.Length(),aSeqBnds.Length());
614 for (i = 1; i <= aSeqLines.Length(); i++)
615 aPrims->AddVertex(aSeqLines(i));
616 for (i = 1; i <= aSeqBnds.Length(); i++)
617 aPrims->AddBound(aSeqBnds(i));
618 myareagroup->AddPrimitiveArray(aPrims);
619 }
620
621 if (aSeqFree.Length())
622 {
623 mysensgroup->SetPrimitivesAspect (new Graphic3d_AspectLine3d (Quantity_NOC_GREEN, Aspect_TOL_SOLID, 2.0));
624 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(aSeqFree.Length(),aSeqFree.Length()/2);
625 for (i = 1; i <= aSeqFree.Length(); i++)
197ac94e 626 {
b8ddfc2f 627 aPrims->AddBound(2);
628 aPrims->AddVertex(aSeqLines(i++));
629 aPrims->AddVertex(aSeqLines(i));
197ac94e 630 }
b8ddfc2f 631 mysensgroup->AddPrimitiveArray(aPrims);
632 mysensgroup->SetPrimitivesAspect (new Graphic3d_AspectLine3d (Quantity_NOC_GRAY40, Aspect_TOL_SOLID, 2.0));
633 }
7fd59977 634}
635
7fd59977 636//=======================================================================
4269bd1b 637//function : SetClipping
7fd59977 638//purpose :
639//=======================================================================
51b10cd4 640void StdSelect_ViewerSelector3d::SetClipping (const Graphic3d_SequenceOfHClipPlane& thePlanes)
7fd59977 641{
4269bd1b 642 myClipPlanes = thePlanes;
643}
644
4269bd1b 645//=======================================================================
646//function : HasDepthClipping
647//purpose :
648//=======================================================================
649Standard_Boolean StdSelect_ViewerSelector3d::HasDepthClipping (const Handle(SelectMgr_EntityOwner)& theOwner) const
650{
651 if (!theOwner->HasSelectable())
652 {
653 return Standard_False;
654 }
655
656 const Handle(SelectMgr_SelectableObject)& aSelectable = theOwner->Selectable();
657 return (aSelectable->GetClipPlanes().Size() > 0);
658}
f751596e 659
660//=======================================================================
661//function : ResetSelectionActivationStatus
662//purpose : Marks all sensitive entities, stored in viewer selector,
663// as inactive for selection
664//=======================================================================
665void StdSelect_ViewerSelector3d::ResetSelectionActivationStatus()
666{
667 resetSelectionActivationStatus();
668}
2157d6ac 669
670//=======================================================================
671//function : AllowOverlapDetection
672//purpose : Sets the detection type: if theIsToAllow is false,
673// only fully included sensitives will be detected, otherwise
674// the algorithm will mark both included and overlapped entities
675// as matched
676//=======================================================================
677void StdSelect_ViewerSelector3d::AllowOverlapDetection (const Standard_Boolean theIsToAllow)
678{
679 mySelectingVolumeMgr.AllowOverlapDetection (theIsToAllow);
680}