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