OCC22138 Remove *.gxx files from Mesh algorithm Update of WOK UDLIST
[occt.git] / src / StdSelect / StdSelect_BRepSelectionTool.cxx
CommitLineData
7fd59977 1// Copyright: Matra-Datavision 1995
2// File: StdSelect_BRepSelectionTool.cxx
3// Created: Tue Mar 14 14:09:28 1995
4// Author: Robert COUBLANC
5// <rob>
6
7#define OCC232 //GG_15/03/02 Enable to compute selection also
8// for COMPSOLID shape type.
9// Origin: TELCO Smart70563 (jbz)
10
11#define OCC294 // SAV 22/10/02 catching exception from BRepAdaptor_Curve::Initialize
12#define OCC872 // SAV 23/10/02 checking if TopoDS_Wire is null or not to avoid "access violation" exception.
13
14#include <StdSelect_BRepSelectionTool.ixx>
15#include <GeomAdaptor_Curve.hxx>
16#include <BRepAdaptor_Curve.hxx>
17#include <TopTools_IndexedMapOfShape.hxx>
18#include <TopExp.hxx>
19#include <TopExp_Explorer.hxx>
20#include <BRepTools_WireExplorer.hxx>
21#include <Select3D_SensitivePoint.hxx>
22#include <StdSelect_BRepOwner.hxx>
23#include <TopoDS.hxx>
24#include <BRepAdaptor_Curve.hxx>
25#include <BRepAdaptor_Surface.hxx>
26#include <GeomAbs_SurfaceType.hxx>
27#include <BRepBndLib.hxx>
28#include <Bnd_Box.hxx>
29#include <BRep_Tool.hxx>
30#include <Geom_Circle.hxx>
31#include <Select3D_SensitiveCircle.hxx>
32#include <Select3D_SensitiveCurve.hxx>
33#include <Select3D_SensitiveSegment.hxx>
34#include <Select3D_SensitiveWire.hxx>
35#include <Select3D_SensitiveFace.hxx>
36#include <Select3D_SensitiveBox.hxx>
37#include <Select3D_SensitiveTriangulation.hxx>
38#include <Select3D_SensitiveTriangle.hxx>
39#include <Select3D_SensitiveGroup.hxx>
40
41#include <Select3D_ListIteratorOfListOfSensitive.hxx>
42#include <Select3D_ListOfSensitiveTriangle.hxx>
43#include <TColgp_HArray1OfPnt.hxx>
44#include <TColgp_SequenceOfPnt.hxx>
45#include <TColStd_Array1OfReal.hxx>
46#include <BRep_Tool.hxx>
47#include <BRepTools.hxx>
48#include <Select3D_TypeOfSensitivity.hxx>
49#include <Precision.hxx>
50#include <gp_Circ.hxx>
51#include <GCPnts_TangentialDeflection.hxx>
52#include <TopoDS_Wire.hxx>
53#include <Poly_Array1OfTriangle.hxx>
54#include <Poly_Polygon3D.hxx>
55#include <Poly_PolygonOnTriangulation.hxx>
56#include <Poly_Triangulation.hxx>
57#include <BRepMesh_IncrementalMesh.hxx>
58#include <Standard_NullObject.hxx>
59#include <Standard_ErrorHandler.hxx>
60
61//static Standard_Integer myArraySize = 2,myN=2;
62static Standard_Integer myN=2;
63static Standard_Boolean first = Standard_True;
64
65
66
67//==================================================
68// Function: Load
69// Purpose : Version debuggee....
70 //==================================================
71
72void StdSelect_BRepSelectionTool
73::Load (const Handle(SelectMgr_Selection)& aSelection,
74 const TopoDS_Shape& aShap,
75 const TopAbs_ShapeEnum aType,
76 const Standard_Real theDeflection,
77 const Standard_Real theDeviationAngle,
78 const Standard_Boolean AutoTriangulation,
79 const Standard_Integer aPriority,
80 const Standard_Integer NbPOnEdge,
81 const Standard_Real MaxParam)
82{
83
84 Standard_Integer Prior = (aPriority==-1)? GetStandardPriority(aShap,aType): aPriority;
85
86
87 switch(aType) {
88 case TopAbs_VERTEX:
89 case TopAbs_EDGE:
90 case TopAbs_WIRE:
91 case TopAbs_FACE:
92 case TopAbs_SHELL:
93 case TopAbs_SOLID:
94#ifdef OCC232
95 case TopAbs_COMPSOLID:
96#endif
97 {
98 TopTools_IndexedMapOfShape subshaps;
99 TopExp::MapShapes(aShap,aType,subshaps);
100 Standard_Boolean ComesFromDecomposition(Standard_True);
101 if(subshaps.Extent()==1)
102 if(aShap==subshaps(1))
103 ComesFromDecomposition = Standard_False;
104
105 Handle(StdSelect_BRepOwner) BOwn;
106 for (Standard_Integer I = 1;I<=subshaps.Extent();I++){
107 BOwn = new StdSelect_BRepOwner(subshaps(I),Prior,ComesFromDecomposition);
108// BOwn->SetHilightMode(1);
109 ComputeSensitive (subshaps(I),
110 BOwn,
111 aSelection,
112 theDeflection,
113 theDeviationAngle,
114 NbPOnEdge,
115 MaxParam,
116 AutoTriangulation);
117 }
118 break;
119 }
120 default:
121 {
122 Handle(StdSelect_BRepOwner) BOwn;
123 BOwn = new StdSelect_BRepOwner(aShap,Prior);
124// BOwn->SetHilightMode(1);
125
126 ComputeSensitive(aShap,
127 BOwn,
128 aSelection,
129 theDeflection,
130 theDeviationAngle,
131 NbPOnEdge,
132 MaxParam,
133 AutoTriangulation);
134 }
135
136 }
137}
138
139
140void StdSelect_BRepSelectionTool
141::Load (const Handle(SelectMgr_Selection)& aSelection,
142 const Handle(SelectMgr_SelectableObject)& aSO,
143 const TopoDS_Shape& aShap,
144 const TopAbs_ShapeEnum aType,
145 const Standard_Real theDeflection,
146 const Standard_Real theDeviationAngle,
147 const Standard_Boolean AutoTriangulation,
148 const Standard_Integer aPriority,
149 const Standard_Integer NbPOnEdge,
150 const Standard_Real MaxParam)
151
152{
153 Load (aSelection,
154 aShap,
155 aType,
156 theDeflection,
157 theDeviationAngle,
158 AutoTriangulation,
159 aPriority,
160 NbPOnEdge);
161
162 //chargement des selectables...
163 for (aSelection->Init();aSelection->More();aSelection->Next()) {
164 Handle(SelectBasics_EntityOwner) BOwn = aSelection->Sensitive()->OwnerId();
165 Handle(SelectMgr_EntityOwner) Own = *((Handle(SelectMgr_EntityOwner)*) &BOwn);
166 Own->Set(aSO);
167 }
168}
169
170
171
172
173
174/*void StdSelect_BRepSelectionTool
175::Load (const Handle(SelectMgr_Selection)& aSelection,
176 const SelectBasics_SequenceOfAddress& Users,
177 const TopoDS_Shape& aShap,
178 const TopAbs_ShapeEnum aType,
179 const Standard_Boolean AutoTriangulation,
180 const Standard_Integer aPriority,
181 const Standard_Integer NbPOnEdge,
182 const Standard_Real MaxParam)
183
184{
185 Load(aSelection,aShap,aType,AutoTriangulation,aPriority,NbPOnEdge);
186 for (aSelection->Init();aSelection->More();aSelection->Next())
187 {
188 for(Standard_Integer i=1;i<=Users.Length();i++)
189 {aSelection->Sensitive()->OwnerId()->Add(Users(i));}
190 }
191}*/
192
193
194
195
196
197void StdSelect_BRepSelectionTool
198::ComputeSensitive(const TopoDS_Shape& shap,
199 const Handle(StdSelect_BRepOwner)& Owner ,
200 const Handle(SelectMgr_Selection)& aSelection,
201 const Standard_Real theDeflection,
202 const Standard_Real theDeviationAngle,
203 const Standard_Integer NbPOnEdge,
204 const Standard_Real MaxParam,
205 const Standard_Boolean AutoTriangulation)
206{
207 TopAbs_ShapeEnum TheShapeType = shap.ShapeType();
208
209 switch (TheShapeType) {
210 case TopAbs_VERTEX:
211 {
212 aSelection->Add(new Select3D_SensitivePoint
213 (Owner , BRep_Tool::Pnt(TopoDS::Vertex(shap))));
214 break;
215 }
216 case TopAbs_EDGE:
217 {
218 Handle (Select3D_SensitiveEntity) aSensitive;
219 GetEdgeSensitive (shap, Owner, aSelection, theDeflection, theDeviationAngle, NbPOnEdge, MaxParam, aSensitive);
220 if(!aSensitive.IsNull())
221 aSelection->Add(aSensitive);
222 break;
223 }
224 case TopAbs_WIRE:
225 {
226 BRepTools_WireExplorer Exp(TopoDS::Wire(shap));
227 Handle (Select3D_SensitiveEntity) aSensitive;
228
229 Handle (Select3D_SensitiveWire) aWireSensitive = new Select3D_SensitiveWire(Owner);
230 aSelection->Add(aWireSensitive);
231 while(Exp.More()){
232 GetEdgeSensitive (Exp.Current(), Owner, aSelection, theDeflection, theDeviationAngle, NbPOnEdge, MaxParam, aSensitive);
233 aWireSensitive->Add(aSensitive);
234 Exp.Next();
235 }
236 break;
237 }
238 case TopAbs_FACE:
239 {
240 const TopoDS_Face& F = TopoDS::Face(shap);
241 Select3D_ListOfSensitive LL;
242 GetSensitiveForFace(F,Owner,LL,AutoTriangulation,NbPOnEdge,MaxParam);
243 for(Select3D_ListIteratorOfListOfSensitive It(LL);It.More();It.Next())
244 aSelection->Add(It.Value());
245 break;
246 }
247 case TopAbs_SHELL:{
248 TopTools_IndexedMapOfShape subshaps;
249 TopExp::MapShapes(shap,TopAbs_FACE,subshaps);
250 Handle(Select3D_SensitiveGroup) SG = new Select3D_SensitiveGroup(Owner);
251 Select3D_ListOfSensitive LL;
252 TopExp::MapShapes(shap,TopAbs_FACE,subshaps);
253 for (Standard_Integer I = 1;I<=subshaps.Extent();I++) {
254 GetSensitiveForFace(TopoDS::Face(subshaps(I)),
255 Owner,LL,AutoTriangulation,NbPOnEdge,MaxParam);
256 }
257
258 if(!LL.IsEmpty()){
259 SG->Add(LL);
260 aSelection->Add(SG);
261 }
262 break;
263 }
264 case TopAbs_SOLID:
265 case TopAbs_COMPSOLID:
266 {
267 TopTools_IndexedMapOfShape subshaps;
268 TopExp::MapShapes(shap,TopAbs_FACE,subshaps);
269 for (Standard_Integer I = 1;I<=subshaps.Extent();I++)
270 {
271 ComputeSensitive (subshaps(I), Owner, aSelection, theDeflection, theDeviationAngle, NbPOnEdge, MaxParam, AutoTriangulation);}
272 break;
273 }
274 case TopAbs_COMPOUND:
275 default:
276 {
277
278 TopExp_Explorer Exp;
279
280 Standard_Boolean Ilibre = 0;
281 for(Exp.Init(shap,TopAbs_VERTEX,TopAbs_EDGE);Exp.More();Exp.Next()){
282 Ilibre++;
283 ComputeSensitive (Exp.Current(), Owner, aSelection, theDeflection, theDeviationAngle, NbPOnEdge, MaxParam, AutoTriangulation);}
284
285 Ilibre = 0;
286 for(Exp.Init(shap,TopAbs_EDGE,TopAbs_FACE);Exp.More();Exp.Next()){
287 Ilibre++;
288 ComputeSensitive (Exp.Current(), Owner, aSelection, theDeflection, theDeviationAngle, NbPOnEdge, MaxParam, AutoTriangulation);}
289 Ilibre = 0;
290 for(Exp.Init(shap,TopAbs_WIRE,TopAbs_FACE);Exp.More();Exp.Next()){
291 Ilibre++;
292 ComputeSensitive (Exp.Current(), Owner, aSelection, theDeflection, theDeviationAngle, NbPOnEdge, MaxParam, AutoTriangulation);}
293
294// Standard_Integer Iface = 0;
295 TopTools_IndexedMapOfShape subshaps;
296 TopExp::MapShapes(shap,TopAbs_FACE,subshaps);
297
298 for (Standard_Integer I = 1;I<=subshaps.Extent();I++)
299 {
300 ComputeSensitive (subshaps(I), Owner, aSelection, theDeflection, theDeviationAngle, NbPOnEdge, MaxParam, AutoTriangulation);
301 }
302
303 }
304 }
305}
306
307static Handle(TColgp_HArray1OfPnt) GetPointsFromPolygon (const TopoDS_Edge& theEdge,
308 const Standard_Real theDeflection)
309{
310 Handle(TColgp_HArray1OfPnt) aResultPoints;
311
312 Standard_Real fi, la;
313 Handle(Geom_Curve) CC3d = BRep_Tool::Curve (theEdge, fi, la);
314
315 TopLoc_Location aLocation;
316 Handle(Poly_Polygon3D) aPolygon = BRep_Tool::Polygon3D (theEdge, aLocation);
317 if (!aPolygon.IsNull())
318 {
319 Standard_Boolean isOK = aPolygon->Deflection() <= theDeflection;
320 isOK = isOK || (CC3d.IsNull());
321 if (isOK)
322 {
323 const TColgp_Array1OfPnt& aNodes = aPolygon->Nodes();
324 aResultPoints = new TColgp_HArray1OfPnt (1, aNodes.Length());
325 if (aLocation.IsIdentity())
326 {
327 for (Standard_Integer aNodeId (aNodes.Lower()), aPntId (1); aNodeId <= aNodes.Upper(); ++aNodeId, ++aPntId)
328 {
329 aResultPoints->SetValue (aPntId, aNodes.Value (aNodeId));
330 }
331 }
332 else
333 {
334 for (Standard_Integer aNodeId (aNodes.Lower()), aPntId (1); aNodeId <= aNodes.Upper(); ++aNodeId, ++aPntId)
335 {
336 aResultPoints->SetValue (aPntId, aNodes.Value (aNodeId).Transformed (aLocation));
337 }
338 }
339 return aResultPoints;
340 }
341 }
342
343 Handle(Poly_Triangulation) aTriangulation;
344 Handle(Poly_PolygonOnTriangulation) anHIndices;
345 BRep_Tool::PolygonOnTriangulation (theEdge, anHIndices, aTriangulation, aLocation);
346 if (!anHIndices.IsNull())
347 {
348 Standard_Boolean isOK = anHIndices->Deflection() <= theDeflection;
349 isOK = isOK || (CC3d.IsNull());
350 if (isOK)
351 {
352 const TColStd_Array1OfInteger& anIndices = anHIndices->Nodes();
353 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
354
355 aResultPoints = new TColgp_HArray1OfPnt (1, anIndices.Length());
356
357 if (aLocation.IsIdentity())
358 {
359 for (Standard_Integer anIndex (anIndices.Lower()), aPntId (1); anIndex <= anIndices.Upper(); ++anIndex, ++aPntId)
360 {
361 aResultPoints->SetValue (aPntId, aNodes (anIndices (anIndex)));
362 }
363 }
364 else
365 {
366 for (Standard_Integer anIndex (anIndices.Lower()), aPntId (1); anIndex <= anIndices.Upper(); ++anIndex, ++aPntId)
367 {
368 aResultPoints->SetValue (aPntId, aNodes (anIndices (anIndex)).Transformed (aLocation));
369 }
370 }
371 return aResultPoints;
372 }
373 }
374 return aResultPoints;
375}
376
377static Standard_Boolean FindLimits(const Adaptor3d_Curve& aCurve,
378 const Standard_Real aLimit,
379 Standard_Real& First,
380 Standard_Real& Last)
381{
382 First = aCurve.FirstParameter();
383 Last = aCurve.LastParameter();
384 Standard_Boolean firstInf = Precision::IsNegativeInfinite(First);
385 Standard_Boolean lastInf = Precision::IsPositiveInfinite(Last);
386
387 if (firstInf || lastInf) {
388 gp_Pnt P1,P2;
389 Standard_Real delta = 1;
390 Standard_Integer count = 0;
391 if (firstInf && lastInf) {
392 do {
393 if (count++ == 100000) return Standard_False;
394 delta *= 2;
395 First = - delta;
396 Last = delta;
397 aCurve.D0(First,P1);
398 aCurve.D0(Last,P2);
399 } while (P1.Distance(P2) < aLimit);
400 }
401 else if (firstInf) {
402 aCurve.D0(Last,P2);
403 do {
404 if (count++ == 100000) return Standard_False;
405 delta *= 2;
406 First = Last - delta;
407 aCurve.D0(First,P1);
408 } while (P1.Distance(P2) < aLimit);
409 }
410 else if (lastInf) {
411 aCurve.D0(First,P1);
412 do {
413 if (count++ == 100000) return Standard_False;
414 delta *= 2;
415 Last = First + delta;
416 aCurve.D0(Last,P2);
417 } while (P1.Distance(P2) < aLimit);
418 }
419 }
420 return Standard_True;
421}
422
423//=====================================================
424// Function : GetEdgeSensitive
425// Purpose : cree un edge sensible pour pouvoir l'ajouter
426// dans computeselection a "aselection" (cas d'une selection d'un edge)
427// ou a "aSensitiveWire" (cas d'une selection d'un wire; dans ce cas la,
428// c'est le sensitive wire qui est ajoute a "aselection" )
429// odl - pour la selection par rectangle -
430//=====================================================
431void StdSelect_BRepSelectionTool
432::GetEdgeSensitive (const TopoDS_Shape& shap,
433 const Handle(StdSelect_BRepOwner)& Owner ,
434 const Handle(SelectMgr_Selection)& aSelection,
435 const Standard_Real theDeflection,
436 const Standard_Real theDeviationAngle,
437 const Standard_Integer NbPOnEdge,
438 const Standard_Real MaxParam,
439Handle(Select3D_SensitiveEntity)& aSensitive)
440{
441 BRepAdaptor_Curve cu3d;
442
443#ifdef OCC294
444 try {
445 OCC_CATCH_SIGNALS
446 cu3d.Initialize (TopoDS::Edge(shap));
447 } catch ( Standard_NullObject ) {
448 return;
449 }
450#else
451 cu3d.Initialize (TopoDS::Edge(shap));
452#endif
453
454 // try to get points from existing polygons
455 Handle(TColgp_HArray1OfPnt) aPoints = GetPointsFromPolygon (TopoDS::Edge(shap), theDeflection);
456 if (!aPoints.IsNull() && aPoints->Length() > 0)
457 {
458 aSensitive = new Select3D_SensitiveCurve (Owner, aPoints);
459 return;
460 }
461
462 Standard_Real wf,wl;
463 BRep_Tool::Range(TopoDS::Edge(shap), wf, wl);
464
465 switch(cu3d.GetType()){
466 case GeomAbs_Line:
467 {
468 aSensitive = new Select3D_SensitiveSegment
469 (Owner,
470 cu3d.Value(wf),cu3d.Value(wl));
471 break;
472 }
473 case GeomAbs_Circle:
474 {
475 Handle (Geom_Circle) TheCircle =new Geom_Circle(cu3d.Circle());
476 Standard_Real TheStart = cu3d.FirstParameter();
477 Standard_Real TheEnd = cu3d.LastParameter();
478 if(TheCircle->Radius()<=Precision::Confusion())
479 aSelection->Add(new Select3D_SensitivePoint(Owner,TheCircle->Location()));
480 else
481 aSensitive = new Select3D_SensitiveCircle(Owner,TheCircle,TheStart,TheEnd,Standard_False,16);
482 break;
483 }
484 default:
485 {
486 // modif-rob : on prend le meme deroulement que dans StdPrs_Curve
487 // nb de points...
488 //============================================
489
490 //aLimit = myDrawer->MaximalParameterValue(); ??
491 Standard_Real aLimit = 200.; // TODO (kgv) - do we need set MaxParam here?
492 Standard_Real V1 = cu3d.FirstParameter();
493 Standard_Real V2 = cu3d.LastParameter();
494 Standard_Boolean firstInf = Precision::IsNegativeInfinite(V1);
495 Standard_Boolean lastInf = Precision::IsPositiveInfinite(V2);
496
497 if (firstInf || lastInf) {
498 gp_Pnt P1,P2;
499 Standard_Real delta = 1;
500 if (firstInf && lastInf) {
501 do {
502 delta *= 2;
503 V1 = - delta;
504 V2 = delta;
505 cu3d.D0(V1,P1);
506 cu3d.D0(V2,P2);
507 } while (P1.Distance(P2) < aLimit);
508 }
509 else if (firstInf) {
510 cu3d.D0(V2,P2);
511 do {
512 delta *= 2;
513 V1 = V2 - delta;
514 cu3d.D0(V1,P1);
515 } while (P1.Distance(P2) < aLimit);
516 }
517 else if (lastInf) {
518 cu3d.D0(V1,P1);
519 do {
520 delta *= 2;
521 V2 = V1 + delta;
522 cu3d.D0(V2,P2);
523 } while (P1.Distance(P2) < aLimit);
524 }
525 }
526
527 Standard_Real aLimitV1, aLimitV2;
528 Standard_Boolean isOK = FindLimits (cu3d, aLimit, aLimitV1, aLimitV2);
529 //aLimitV1 = cu3d.FirstParameter();
530 //aLimitV2 = cu3d.LastParameter();
531
532 // reproduce drawing behavour
533 // TODO (kgv) - remove copy-paste
534 if (isOK)
535 {
536 Standard_Integer aNbIntervals = cu3d.NbIntervals (GeomAbs_C1);
537 TColStd_Array1OfReal anIntervals (1, aNbIntervals + 1);
538 cu3d.Intervals (anIntervals, GeomAbs_C1);
539 Standard_Real aV1, aV2;
540 Standard_Integer aNumberOfPoints;
541 TColgp_SequenceOfPnt aPointsSeq;
542
543 for (Standard_Integer anIntervalId = 1; anIntervalId <= aNbIntervals; ++anIntervalId)
544 {
545 aV1 = anIntervals (anIntervalId); aV2 = anIntervals (anIntervalId + 1);
546 if (aV2 > aLimitV1 && aV1 < aLimitV2)
547 {
548 aV1 = Max (aV1, aLimitV1);
549 aV2 = Min (aV2, aLimitV2);
550
551 GCPnts_TangentialDeflection anAlgo (cu3d, aV1, aV2, theDeviationAngle, theDeflection);
552 aNumberOfPoints = anAlgo.NbPoints();
553
554 if (aNumberOfPoints > 0)
555 {
556 for (Standard_Integer i = 1; i < aNumberOfPoints; ++i)
557 {
558 aPointsSeq.Append (anAlgo.Value (i));
559 }
560 if (anIntervalId == aNbIntervals)
561 {
562 aPointsSeq.Append (anAlgo.Value (aNumberOfPoints));
563 }
564 }
565 }
566 }
567
568 aPoints = new TColgp_HArray1OfPnt (1, aPointsSeq.Length());
569 for (Standard_Integer aPntId = 1; aPntId <= aPointsSeq.Length(); ++aPntId)
570 {
571 aPoints->SetValue (aPntId, aPointsSeq.Value (aPntId));
572 }
573 aSensitive = new Select3D_SensitiveCurve (Owner, aPoints);
574 break;
575 }
576
577 // simple subdivisions
578 Standard_Integer nbintervals = 1;
579
580 if (cu3d.GetType() == GeomAbs_BSplineCurve) {
581 nbintervals = cu3d.NbKnots() - 1;
582 nbintervals = Max(1, nbintervals/3);}
583
584 Standard_Real V;
585 Standard_Integer N = Max(2, NbPOnEdge*nbintervals);
586 Standard_Real DV = (V2-V1) / (N-1);
587 gp_Pnt p;
588
589 if (first) {
590 myN = N;
591 first = Standard_False;
592 }
593 if (myN == N) {
594
595 Handle(TColgp_HArray1OfPnt) points = new TColgp_HArray1OfPnt(1, N);
596
597 for (Standard_Integer i = 1; i <= N;i++)
598 {
599 V = V1 + (i-1)*DV;
600 p = cu3d.Value(V);
601 points->SetValue(i,p);
602 }
603 aSensitive = new Select3D_SensitiveCurve(Owner,points);
604
605 }
606 else {
607 Handle(TColgp_HArray1OfPnt) pointsbis = new TColgp_HArray1OfPnt(1, N);
608
609 for (Standard_Integer i = 1; i <= N;i++)
610 {
611 V = V1 + (i-1)*DV;
612 p = cu3d.Value(V);
613 pointsbis->SetValue(i,p);
614 }
615 aSensitive = new Select3D_SensitiveCurve(Owner,pointsbis);
616
617 }
618 }
619 break;
620 }
621}
622
623
624Standard_Integer StdSelect_BRepSelectionTool::GetStandardPriority (const TopoDS_Shape& SH,
625 const TopAbs_ShapeEnum aType)
626{
627 switch(aType) {
628 case TopAbs_VERTEX:
629 return 8;
630 case TopAbs_EDGE:
631 return 7;
632 case TopAbs_WIRE:
633 return 6;
634 case TopAbs_FACE:
635 return 5;
636 case TopAbs_SHAPE:
637 default:
638 switch(SH.ShapeType())
639 {
640 case TopAbs_VERTEX:
641 return 9;
642 case TopAbs_EDGE:
643 return 8;
644 case TopAbs_WIRE:
645 return 7;
646 case TopAbs_FACE:
647 return 6;
648 case TopAbs_SHELL:
649 return 5;
650 case TopAbs_COMPOUND:
651 case TopAbs_COMPSOLID:
652 case TopAbs_SOLID:
653 case TopAbs_SHAPE:
654 default:
655 return 4;
656 }
657 }
658
659 return 0;
660}
661
662//=======================================================================
663//function : GetSensitiveEntityForFace
664//purpose :
665//=======================================================================
666Standard_Boolean StdSelect_BRepSelectionTool::GetSensitiveForFace(const TopoDS_Face& F,
667 const Handle(StdSelect_BRepOwner)& Owner,
668 Select3D_ListOfSensitive& LL,
669 const Standard_Boolean AutoTriangulation,
670 const Standard_Integer NbPOnEdge,
671 const Standard_Real MaxParam,
672 const Standard_Boolean InteriorFlag)
673{
674 // voyons s y a une triangulation de la face...
675 BRepAdaptor_Curve cu3d;
676 Handle(Poly_Triangulation) T;
677 TopLoc_Location loc;
678 T = BRep_Tool::Triangulation(F,loc);
679
680 if(T.IsNull() && AutoTriangulation){
681 Standard_Real Defl=.2,Ang=30*PI/180.;
682 BRepMesh_IncrementalMesh(F,Defl,Standard_True,Ang);
683 T = BRep_Tool::Triangulation(F,loc);
684
685 }
686 if(!T.IsNull()){
687 Handle(Select3D_SensitiveTriangulation) STG =
688 new Select3D_SensitiveTriangulation(Owner,T,loc,InteriorFlag);
689 LL.Append(STG);
690 return Standard_True;
691 }
692
693 // pour les faces a bugs de triangulation ou sans autotriangulation ....
694 // tres laid et ne devrait meme plus exister ...
695 BRepAdaptor_Surface BS;
696 BS.Initialize (F);
697
698 Standard_Real FirstU = BS.FirstUParameter()<=-Precision::Infinite()? -MaxParam:BS.FirstUParameter();
699 Standard_Real LastU = BS.LastUParameter() >=Precision::Infinite()? MaxParam:BS.LastUParameter();
700 Standard_Real FirstV = BS.FirstVParameter()<=-Precision::Infinite()? -MaxParam:BS.FirstVParameter();
701 Standard_Real LastV = BS.LastVParameter()>=Precision::Infinite()? MaxParam:BS.LastVParameter();
702
703
704
705 if(BS.GetType()==GeomAbs_Plane){
706 gp_Pnt pcur;
707 Handle(TColgp_HArray1OfPnt) P = new TColgp_HArray1OfPnt(1,5);
708 BS.D0(FirstU,FirstV,pcur);
709 P->SetValue(1,pcur);
710 BS.D0(LastU,FirstV,pcur);
711 P->SetValue(2,pcur);
712 BS.D0(LastU,LastV,pcur);
713 P->SetValue(3,pcur);
714 BS.D0(FirstU,LastV,pcur);
715 P->SetValue(4,pcur);
716 P->SetValue(5,P->Value(1));
717 // si le plan est "infini", on ne le rend sensible que sur sa frontiere delimitee par MaxParam
718 if(FirstU ==-MaxParam && LastU==MaxParam && FirstV ==-MaxParam && LastV==MaxParam)
719 LL.Append(new Select3D_SensitiveFace
720 (Owner, P, Select3D_TOS_BOUNDARY));
721 else{
722 Select3D_TypeOfSensitivity TS = InteriorFlag ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY;
723 LL.Append(new Select3D_SensitiveFace
724 (Owner, P, TS));
725 }
726 return Standard_True;
727 }
728
729 // IL S'AGIT DE CONSTRUIRE UN POLYGONE "SENSIBLE" A PARTIR DU CONTOUR EXTERIEUR DE LA FACE...
730 // CA N'EST PAS BEAU DU TOUT MAIS...
731 TopoDS_Wire aWire;
732// Standard_Integer NbEdges=1;
733
734// Standard_Integer NbPoints(0);
735
736 TopExp_Explorer EW(F,TopAbs_WIRE);
737 if(EW.More())
738 aWire = TopoDS::Wire(EW.Current()); // en esperant que c'est le premier... a voir
739
740#ifdef OCC872
741 if ( aWire.IsNull() )
742 return Standard_False;
743#endif
744
745 BRepTools_WireExplorer Exp;
746 Exp.Init(aWire);
747
748 TColgp_SequenceOfPnt WirePoints;
749 Standard_Boolean FirstExp = Standard_True;
750 Standard_Real wf,wl;
751
752 for(;Exp.More();Exp.Next()){
753 cu3d.Initialize (Exp.Current());
754 BRep_Tool::Range(Exp.Current(), wf, wl);
755 if(Abs(wf-wl)<=Precision::Confusion()){
756#ifdef DEB
757 cout<<" StdSelect_BRepSelectionTool : Curve where ufirst = ulast ...."<<endl;
758#endif
759 }
760 else{
761 if(FirstExp){
762 if(Exp.Orientation()==TopAbs_FORWARD ){
763 WirePoints.Append(cu3d.Value(wf));
764 }
765 else{
766 WirePoints.Append(cu3d.Value(wl));}
767 FirstExp = Standard_False;}
768
769 switch(cu3d.GetType()){
770 case GeomAbs_Line:{
771 if(Exp.Orientation()==TopAbs_FORWARD){
772 WirePoints.Append(cu3d.Value(wl));}
773 else{
774 WirePoints.Append(cu3d.Value(wf));}
775
776 break;}
777 case GeomAbs_Circle:{
778 if (2*PI - Abs(wl-wf) <= Precision::Confusion()) {
779 if(BS.GetType()==GeomAbs_Cylinder ||
780 BS.GetType()==GeomAbs_Torus ||
781 BS.GetType()==GeomAbs_Cone ||
782 BS.GetType()==GeomAbs_BSplineSurface) // beuurkk pour l'instant...
783 {
784 Standard_Real ff= wf ,ll= wl ;
785 Standard_Real dw
786 =(Max(wf, wl)-Min(wf,wl))/(Standard_Real)Max(2, NbPOnEdge-1);
787 if (Exp.Orientation()==TopAbs_FORWARD){
788 for (Standard_Real wc=wf+dw; wc <= wl; wc+=dw){
789 WirePoints.Append(cu3d.Value(wc));
790 }
791 } else if (Exp.Orientation()==TopAbs_REVERSED){
792 for (Standard_Real wc=ll-dw; wc >= ff; wc-=dw){
793 WirePoints.Append(cu3d.Value(wc));
794 }
795 }
796 }
797
798 else {
799 if(cu3d.Circle().Radius() <= Precision::Confusion())
800 LL.Append(new Select3D_SensitivePoint(Owner,cu3d.Circle().Location()));
801 else
802 LL.Append(new Select3D_SensitiveCircle(Owner,new Geom_Circle(cu3d.Circle()),InteriorFlag,16));
803
804 }
805 }
806 else {
807 Standard_Real ff= wf ,ll= wl ;
808 Standard_Real dw
809 =(Max(wf, wl)-Min(wf,wl))/(Standard_Real)Max(2, NbPOnEdge-1);
810
811 if (Exp.Orientation()==TopAbs_FORWARD){
812 for (Standard_Real wc=wf+dw; wc <= wl; wc+=dw){
813 WirePoints.Append(cu3d.Value(wc));
814 }
815 } else if (Exp.Orientation()==TopAbs_REVERSED){
816 for (Standard_Real wc=ll-dw; wc >= ff; wc-=dw){
817 WirePoints.Append(cu3d.Value(wc));
818 }
819 }
820 }
821
822 break;
823 }
824 default:
825 {
826 Standard_Real ff= wf ,ll= wl ;
827 Standard_Real dw
828 =(Max(wf, wl)-Min(wf,wl))/(Standard_Real)Max(2, NbPOnEdge-1);
829
830
831 if (Exp.Orientation()==TopAbs_FORWARD){
832 for (Standard_Real wc=wf+dw; wc <= wl; wc+=dw){
833 WirePoints.Append(cu3d.Value(wc));
834 }
835 } else if (Exp.Orientation()==TopAbs_REVERSED) {
836 for (Standard_Real wc=ll-dw; wc >= ff; wc-=dw){
837 WirePoints.Append(cu3d.Value(wc));
838 }
839 }
840 }
841 }
842 }
843 }
844 Standard_Integer ArrayPosition = WirePoints.Length();
845
846 Handle(TColgp_HArray1OfPnt) facepoints = new TColgp_HArray1OfPnt(1,ArrayPosition);
847 // beurk beurk beurk...
848 for(Standard_Integer I=1 ;I<=ArrayPosition;I++)
849 {facepoints->SetValue (I, WirePoints.Value(I));}
850
851 if ((facepoints->Array1()).Length() > 1) { // 1 si un seul edge circulaire plein.
852 Select3D_TypeOfSensitivity TS = InteriorFlag ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY;
853 LL.Append(new Select3D_SensitiveFace
854 (Owner, facepoints, TS));
855 }
856 return Standard_True;
857}