0022800: OSD::SetSignal(Standard_True) is not called in the standard samples
[occt.git] / src / BRep / BRep_Tool.cxx
CommitLineData
703a6abd
O
1// File: BRep_Tool.cxx
2// Created: Wed Jul 7 15:35:57 1993
3// Author: Remi LEQUETTE
7fd59977 4
5#include <BRep_Tool.ixx>
6#include <BRep_TFace.hxx>
7#include <BRep_TEdge.hxx>
8#include <BRep_TVertex.hxx>
9#include <BRep_CurveRepresentation.hxx>
10#include <BRep_CurveOnSurface.hxx>
11#include <BRep_CurveOnClosedSurface.hxx>
12#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
13#include <BRep_PointRepresentation.hxx>
14#include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
15#include <BRep_Curve3D.hxx>
16#include <BRep_Polygon3D.hxx>
17#include <BRep_PolygonOnSurface.hxx>
18#include <BRep_PolygonOnClosedSurface.hxx>
19#include <BRep_PolygonOnTriangulation.hxx>
20#include <BRep_PolygonOnClosedTriangulation.hxx>
21#include <TopoDS.hxx>
22#include <TopoDS_Iterator.hxx>
23#include <TopExp_Explorer.hxx>
24#include <TopExp.hxx>
25#include <TopTools_MapOfShape.hxx>
26#include <ElSLib.hxx>
27#include <Geom_Plane.hxx>
28#include <Geom_RectangularTrimmedSurface.hxx>
29#include <Geom_OffsetSurface.hxx>
30#include <Geom_TrimmedCurve.hxx>
31#include <Geom2d_TrimmedCurve.hxx>
32#include <ProjLib_ProjectedCurve.hxx>
33#include <GeomProjLib.hxx>
34#include <Geom2dAdaptor.hxx>
35#include <GeomAdaptor_HCurve.hxx>
36#include <GeomAdaptor_HSurface.hxx>
37#include <Precision.hxx>
38#include <Poly_Triangulation.hxx>
39#include <Poly_Polygon3D.hxx>
40#include <Poly_Polygon2D.hxx>
41#include <Poly_PolygonOnTriangulation.hxx>
42
43//modified by NIZNHY-PKV Fri Oct 17 14:13:29 2008f
44static
45 Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS);
46//modified by NIZNHY-PKV Fri Oct 17 14:13:33 2008t
47//
48//=======================================================================
49//function : Surface
50//purpose : Returns the geometric surface of the face. Returns
51// in <L> the location for the surface.
52//=======================================================================
53
54const Handle(Geom_Surface)& BRep_Tool::Surface(const TopoDS_Face& F,
703a6abd 55 TopLoc_Location& L)
7fd59977 56{
57 Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
58 L = F.Location() * TF->Location();
59 return TF->Surface();
60}
61
62//=======================================================================
63//function : Surface
64//purpose : Returns the geometric surface of the face. It can
65// be a copy if there is a Location.
66//=======================================================================
67
68Handle(Geom_Surface) BRep_Tool::Surface(const TopoDS_Face& F)
69{
70 Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
71 TopLoc_Location L = F.Location() * TF->Location();
72 Handle(Geom_Surface) S = TF->Surface();
73
74 if(S.IsNull()) return S;
75
76 Handle(Geom_Geometry) S1;
77 if (!L.IsIdentity()) {
78 S1 = S->Copy();
79 S = *((Handle(Geom_Surface)*)&S1);
80 S->Transform(L.Transformation());
81 }
82 return S;
83}
84
85//=======================================================================
86//function : Triangulation
87//purpose : Returns the Triangulation of the face. It is a
88// null handle if there is no triangulation.
89//=======================================================================
90
91const Handle(Poly_Triangulation)&
92BRep_Tool::Triangulation(const TopoDS_Face& F,
703a6abd 93 TopLoc_Location& L)
7fd59977 94{
95 L = F.Location();
96 return (*((Handle(BRep_TFace)*)&F.TShape()))->Triangulation();
97}
98
99//=======================================================================
100//function : Tolerance
101//purpose : Returns the tolerance of the face.
102//=======================================================================
103
104Standard_Real BRep_Tool::Tolerance(const TopoDS_Face& F)
105{
106 Standard_Real p = (*((Handle(BRep_TFace)*)&F.TShape()))->Tolerance();
107 Standard_Real pMin = Precision::Confusion();
108 if (p > pMin) return p;
109 else return pMin;
110}
111
112//=======================================================================
113//function : NaturalRestriction
114//purpose : Returns the NaturalRestriction flag of the face.
115//=======================================================================
116
117Standard_Boolean BRep_Tool::NaturalRestriction(const TopoDS_Face& F)
118{
119 return (*((Handle(BRep_TFace)*) &F.TShape()))->NaturalRestriction();
120}
121
122//=======================================================================
123//function : Curve
124//purpose : Returns the 3D curve of the edge. May be a Null
125// handle. Returns in <L> the location for the curve.
126// In <First> and <Last> the parameter range.
127//=======================================================================
128
2b442de5 129static const Handle(Geom_Curve) nullCurve;
7fd59977 130
131const Handle(Geom_Curve)& BRep_Tool::Curve(const TopoDS_Edge& E,
703a6abd
O
132 TopLoc_Location& L,
133 Standard_Real& First,
134 Standard_Real& Last)
7fd59977 135{
136 // find the representation
137 BRep_ListIteratorOfListOfCurveRepresentation itcr
138 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
139
140 while (itcr.More()) {
141 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
142 if (cr->IsCurve3D()) {
143 const Handle(BRep_Curve3D)& GC = *((Handle(BRep_Curve3D)*)&cr);
144 L = E.Location() * GC->Location();
145 GC->Range(First,Last);
146 return GC->Curve3D();
147 }
148 itcr.Next();
149 }
150 L.Identity();
151 return nullCurve;
152}
153
154//=======================================================================
155//function : Curve
156//purpose : Returns the 3D curve of the edge. May be a Null handle.
157// In <First> and <Last> the parameter range.
158// It can be a copy if there is a Location.
159//=======================================================================
160
161Handle(Geom_Curve) BRep_Tool::Curve(const TopoDS_Edge& E,
703a6abd
O
162 Standard_Real& First,
163 Standard_Real& Last)
7fd59977 164{
165 TopLoc_Location L;
166 Handle(Geom_Curve) C = Curve(E,L,First,Last);
167 if ( !C.IsNull() ) {
168 Handle(Geom_Geometry) C1;
169 if ( !L.IsIdentity() ) {
170 C1 = C->Copy();
171 C = *((Handle(Geom_Curve)*)&C1);
172 C->Transform(L.Transformation());
173 }
174 }
175 return C;
176}
177
178//=======================================================================
179//function : IsGeometric
180//purpose : Returns True if <E> is a 3d curve or a curve on
181// surface.
182//=======================================================================
183
184Standard_Boolean BRep_Tool::IsGeometric(const TopoDS_Edge& E)
185{
186 // find the representation
187 BRep_ListIteratorOfListOfCurveRepresentation itcr
188 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
189
190 while (itcr.More()) {
191 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
192 if (cr->IsCurve3D()) {
193 Standard_Real first, last;
194 TopLoc_Location L;
195 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E, L, first, last);
196 if (!C.IsNull()) return Standard_True;
197 }
198 else if (cr->IsCurveOnSurface()) return Standard_True;
199 itcr.Next();
200 }
201 return Standard_False;
202}
203
204//=======================================================================
205//function : Polygon3D
206//purpose : Returns the 3D polygon of the edge. May be a Null
207// handle. Returns in <L> the location for the polygon.
208//=======================================================================
209
2b442de5
S
210static const Handle(Poly_Polygon3D) nullPolygon3D;
211
7fd59977 212const Handle(Poly_Polygon3D)& BRep_Tool::Polygon3D(const TopoDS_Edge& E,
703a6abd 213 TopLoc_Location& L)
7fd59977 214{
215 // find the representation
216 BRep_ListIteratorOfListOfCurveRepresentation itcr
217 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
218
219 while (itcr.More()) {
220 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
221 if (cr->IsPolygon3D()) {
222 const Handle(BRep_Polygon3D)& GC = *((Handle(BRep_Polygon3D)*)&cr);
223 L = E.Location() * GC->Location();
224 return GC->Polygon3D();
225 }
226 itcr.Next();
227 }
228 L.Identity();
229 return nullPolygon3D;
230}
231
232//=======================================================================
233//function : CurveOnSurface
234//purpose : Returns the curve associated to the edge in the
235// parametric space of the face. Returns a NULL
236// handle if this curve does not exist. Returns in
237// <First> and <Last> the parameter range.
238//=======================================================================
239
240Handle(Geom2d_Curve) BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
703a6abd
O
241 const TopoDS_Face& F,
242 Standard_Real& First,
243 Standard_Real& Last)
7fd59977 244{
245 TopLoc_Location l;
246 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
247 TopoDS_Edge aLocalEdge = E;
248 if (F.Orientation() == TopAbs_REVERSED) {
249 aLocalEdge.Reverse();
250// return CurveOnSurface(E,S,l,First,Last);
251 }
252// return CurveOnSurface(TopoDS::Edge(E.Reversed()),S,l,First,Last);
253// else
254// return CurveOnSurface(E,S,l,First,Last);
255 return CurveOnSurface(aLocalEdge,S,l,First,Last);
256}
257
258//=======================================================================
259//function : CurveOnSurface
260//purpose : Returns the curve associated to the edge in the
261// parametric space of the surface. Returns a NULL
262// handle if this curve does not exist. Returns in
263// <First> and <Last> the parameter range.
264//=======================================================================
265
2b442de5 266static const Handle(Geom2d_Curve) nullPCurve;
7fd59977 267
268Handle(Geom2d_Curve) BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
703a6abd
O
269 const Handle(Geom_Surface)& S,
270 const TopLoc_Location& L,
271 Standard_Real& First,
272 Standard_Real& Last)
7fd59977 273{
274 TopLoc_Location loc = L.Predivided(E.Location());
275 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
276
277 // find the representation
278 BRep_ListIteratorOfListOfCurveRepresentation itcr
279 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
280
281 while (itcr.More()) {
282 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
283 if (cr->IsCurveOnSurface(S,loc)) {
284 const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
285 GC->Range(First,Last);
286 if (GC->IsCurveOnClosedSurface() && Eisreversed)
703a6abd 287 return GC->PCurve2();
7fd59977 288 else
703a6abd 289 return GC->PCurve();
7fd59977 290 }
291 itcr.Next();
292 }
7fd59977 293
294 // for planar surface and 3d curve try a projection
295 // modif 21-05-97 : for RectangularTrimmedSurface, try a projection
296 Handle(Geom_Plane) GP;
297 Handle(Geom_RectangularTrimmedSurface) GRTS;
298 GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
299 if(!GRTS.IsNull())
300 GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface());
301 else
302 GP = Handle(Geom_Plane)::DownCast(S);
303 //fin modif du 21-05-97
304
305 if (!GP.IsNull()) {
306
703a6abd
O
307 Handle(GeomAdaptor_HCurve) HC;
308 Handle(GeomAdaptor_HSurface) HS;
309
310 HC = new GeomAdaptor_HCurve();
311 HS = new GeomAdaptor_HSurface();
7fd59977 312
313 TopLoc_Location LC;
314
0d969553 315 Standard_Real f, l;// for those who call with (u,u).
7fd59977 316 Handle(Geom_Curve) C3d =
317 BRep_Tool::Curve(E,/*LC,*/f,l); // transforming plane instead of curve
318 // we can loose scale factor of Curve transformation (eap 13 May 2002)
319
320 LC = L/*.Predivided(LC)*/;
321
322 if (C3d.IsNull()) return nullPCurve;
323
324 Handle(Geom_Plane) Plane = GP;
325 if (!LC.IsIdentity()) {
326 const gp_Trsf& T = LC.Transformation();
327 Handle(Geom_Geometry) GPT = GP->Transformed(T);
328 Plane = *((Handle(Geom_Plane)*)&GPT);
329 }
330 GeomAdaptor_Surface& GAS = HS->ChangeSurface();
331 GAS.Load(Plane);
332
333 Handle(Geom_Curve) ProjOnPlane =
334 GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d,f,l),
703a6abd
O
335 Plane,
336 Plane->Position().Direction(),
337 Standard_True);
7fd59977 338
339 GeomAdaptor_Curve& GAC = HC->ChangeCurve();
340 GAC.Load(ProjOnPlane);
341
342 ProjLib_ProjectedCurve Proj(HS,HC);
343 Handle(Geom2d_Curve) pc = Geom2dAdaptor::MakeCurve(Proj);
344
345 if (pc->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
346 Handle(Geom2d_TrimmedCurve) TC =
703a6abd 347 (*((Handle(Geom2d_TrimmedCurve)*)&pc));
7fd59977 348 pc = TC->BasisCurve();
349 }
350 First = f; Last = l;
351 return pc;
352 }
353
354 return nullPCurve;
355}
356
357//=======================================================================
358//function : CurveOnSurface
359//purpose :
360//=======================================================================
361
362void BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
703a6abd
O
363 Handle(Geom2d_Curve)& C,
364 Handle(Geom_Surface)& S,
365 TopLoc_Location& L,
366 Standard_Real& First,
367 Standard_Real& Last)
7fd59977 368{
369 // find the representation
370 BRep_ListIteratorOfListOfCurveRepresentation itcr
371 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
372
373 while (itcr.More()) {
374 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
375 if (cr->IsCurveOnSurface()) {
376 const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
377 C = GC->PCurve();
378 S = GC->Surface();
379 L = E.Location() * GC->Location();
380 GC->Range(First,Last);
381 return;
382 }
383 itcr.Next();
384 }
385
386 C = Handle(Geom2d_Curve)();
387 S = Handle(Geom_Surface)();
388 L = TopLoc_Location();
389}
390
391//=======================================================================
392//function : CurveOnSurface
393//purpose :
394//=======================================================================
395
396void BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
703a6abd
O
397 Handle(Geom2d_Curve)& C,
398 Handle(Geom_Surface)& S,
399 TopLoc_Location& L,
400 Standard_Real& First,
401 Standard_Real& Last,
402 const Standard_Integer Index)
7fd59977 403{
404 Standard_Integer i = 0;
405 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
406
407 // find the representation
408 BRep_ListIteratorOfListOfCurveRepresentation itcr
409 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
410
411 while (itcr.More()) {
412 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
413 if (cr->IsCurveOnSurface()) {
414 const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
415 i++;
416 if (i > Index) break;
417 if (i == Index) {
703a6abd 418 // JMB le 21 Mai 1999
0d969553
Y
419 // it is done as in the other CurveOnSurface methods, ie. take into account
420 // the orientation in case of cut edges (return PCurve2)
421 // otherwise there is a risk to loop curves or to not get the prover one.
703a6abd
O
422 if (GC->IsCurveOnClosedSurface() && Eisreversed)
423 C = GC->PCurve2();
424 else
425 C = GC->PCurve();
426 S = GC->Surface();
427 L = E.Location() * GC->Location();
428 GC->Range(First,Last);
429 return;
7fd59977 430 }
431 }
432 itcr.Next();
433 }
434
435 C = Handle(Geom2d_Curve)();
436 S = Handle(Geom_Surface)();
437 L = TopLoc_Location();
438}
439
440//=======================================================================
441//function : PolygonOnSurface
442//purpose : Returns the polygon associated to the edge in the
443// parametric space of the face. Returns a NULL
444// handle if this polygon does not exist.
445//=======================================================================
446
447Handle(Poly_Polygon2D) BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
703a6abd 448 const TopoDS_Face& F)
7fd59977 449{
450 TopLoc_Location l;
451 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
452 TopoDS_Edge aLocalEdge = E;
453 if (F.Orientation() == TopAbs_REVERSED) {
454 aLocalEdge.Reverse();
455// return PolygonOnSurface(E,S,l);
456 }
457 // return PolygonOnSurface(TopoDS::Edge(E.Reversed()),S,l);
458// else
459// return PolygonOnSurface(E,S,l);
460 return PolygonOnSurface(aLocalEdge,S,l);
461}
462
463//=======================================================================
464//function : PolygonOnSurface
465//purpose : Returns the polygon associated to the edge in the
466// parametric space of the surface. Returns a NULL
467// handle if this polygon does not exist.
468//=======================================================================
469
2b442de5 470static const Handle(Poly_Polygon2D) nullPolygon2D;
7fd59977 471
472Handle(Poly_Polygon2D)
473 BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
703a6abd
O
474 const Handle(Geom_Surface)& S,
475 const TopLoc_Location& L)
7fd59977 476{
477 TopLoc_Location l = L.Predivided(E.Location());
478 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
479
480 // find the representation
481 BRep_ListIteratorOfListOfCurveRepresentation itcr
482 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
483
484 while (itcr.More()) {
485 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
486 if (cr->IsPolygonOnSurface(S,l)) {
487 if (cr->IsPolygonOnClosedSurface() && Eisreversed )
703a6abd 488 return cr->Polygon2();
7fd59977 489 else
703a6abd 490 return cr->Polygon();
7fd59977 491 }
492 itcr.Next();
493 }
494
495 return nullPolygon2D;
496}
497
498//=======================================================================
499//function : PolygonOnSurface
500//purpose :
501//=======================================================================
502
503void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
703a6abd
O
504 Handle(Poly_Polygon2D)& P,
505 Handle(Geom_Surface)& S,
506 TopLoc_Location& L)
7fd59977 507{
508 // find the representation
509 BRep_ListIteratorOfListOfCurveRepresentation itcr
510 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
511
512 while (itcr.More()) {
513 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
514 if (cr->IsPolygonOnSurface()) {
515 const Handle(BRep_PolygonOnSurface)& PS =
703a6abd 516 *((Handle(BRep_PolygonOnSurface)*)&cr);
7fd59977 517 P = PS->Polygon();
518 S = PS->Surface();
519 L = E.Location() * PS->Location();
520 return;
521 }
522 itcr.Next();
523 }
524
525 L = TopLoc_Location();
526 P = Handle(Poly_Polygon2D)();
527 S = Handle(Geom_Surface)();
528}
529
530//=======================================================================
531//function : PolygonOnSurface
532//purpose :
533//=======================================================================
534
535void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
703a6abd
O
536 Handle(Poly_Polygon2D)& P,
537 Handle(Geom_Surface)& S,
538 TopLoc_Location& L,
539 const Standard_Integer Index)
7fd59977 540{
541 Standard_Integer i = 0;
542
543 // find the representation
544 BRep_ListIteratorOfListOfCurveRepresentation itcr
545 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
546
547 while (itcr.More()) {
548 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
549 if (cr->IsPolygonOnSurface()) {
550 const Handle(BRep_PolygonOnSurface)& PS =
703a6abd 551 *((Handle(BRep_PolygonOnSurface)*)&cr);
7fd59977 552 i++;
553 if (i > Index) break;
554 if (i == Index) {
703a6abd
O
555 P = PS->Polygon();
556 S = PS->Surface();
557 L = E.Location() * PS->Location();
558 return;
7fd59977 559 }
560 }
561 itcr.Next();
562 }
563
564 L = TopLoc_Location();
565 P = Handle(Poly_Polygon2D)();
566 S = Handle(Geom_Surface)();
567}
568
569//=======================================================================
570//function : PolygonOnTriangulation
571//purpose : Returns the polygon associated to the edge in the
572// parametric space of the face. Returns a NULL
573// handle if this polygon does not exist.
574//=======================================================================
575
2b442de5 576static const Handle(Poly_PolygonOnTriangulation) nullArray;
7fd59977 577
578const Handle(Poly_PolygonOnTriangulation)&
579BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
703a6abd
O
580 const Handle(Poly_Triangulation)& T,
581 const TopLoc_Location& L)
7fd59977 582{
583 TopLoc_Location l = L.Predivided(E.Location());
584 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
585
586 // find the representation
587 BRep_ListIteratorOfListOfCurveRepresentation itcr
588 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
589
590 while (itcr.More()) {
591 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
592 if ( cr->IsPolygonOnTriangulation(T,l)) {
593 if ( cr->IsPolygonOnClosedTriangulation() && Eisreversed )
703a6abd 594 return cr->PolygonOnTriangulation2();
7fd59977 595 else
703a6abd 596 return cr->PolygonOnTriangulation();
7fd59977 597 }
598 itcr.Next();
599 }
600
601 return nullArray;
602}
603
604//=======================================================================
605//function : PolygonOnTriangulation
606//purpose :
607//=======================================================================
608
609void
610BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
703a6abd
O
611 Handle(Poly_PolygonOnTriangulation)& P,
612 Handle(Poly_Triangulation)& T,
613 TopLoc_Location& L)
7fd59977 614{
615 // find the representation
616 BRep_ListIteratorOfListOfCurveRepresentation itcr
617 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
618
619 while (itcr.More()) {
620 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
621 if (cr->IsPolygonOnTriangulation()) {
622 const Handle(BRep_PolygonOnTriangulation)& PT =
703a6abd 623 *((Handle(BRep_PolygonOnTriangulation)*)&cr);
7fd59977 624 P = PT->PolygonOnTriangulation();
625 T = PT->Triangulation();
626 L = E.Location() * PT->Location();
627 return;
628 }
629 itcr.Next();
630 }
631
632 L = TopLoc_Location();
633 P = Handle(Poly_PolygonOnTriangulation)();
634 T = Handle(Poly_Triangulation)();
635}
636
637//=======================================================================
638//function : PolygonOnTriangulation
639//purpose :
640//=======================================================================
641
642void
643BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
703a6abd
O
644 Handle(Poly_PolygonOnTriangulation)& P,
645 Handle(Poly_Triangulation)& T,
646 TopLoc_Location& L,
647 const Standard_Integer Index)
7fd59977 648{
649 Standard_Integer i = 0;
650
651 // find the representation
652 BRep_ListIteratorOfListOfCurveRepresentation itcr
653 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
654
655 while (itcr.More()) {
656 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
657 if (cr->IsPolygonOnTriangulation()) {
658 const Handle(BRep_PolygonOnTriangulation)& PT =
703a6abd 659 *((Handle(BRep_PolygonOnTriangulation)*)&cr);
7fd59977 660 i++;
661 if (i > Index) break;
662 if (i == Index) {
703a6abd
O
663 T = PT->Triangulation();
664 P = PT->PolygonOnTriangulation();
665 L = E.Location() * PT->Location();
666 return;
7fd59977 667 }
668 }
669 itcr.Next();
670 }
671
672 L = TopLoc_Location();
673 P = Handle(Poly_PolygonOnTriangulation)();
674 T = Handle(Poly_Triangulation)();
675}
676
677//=======================================================================
678//function : IsClosed
679//purpose : Returns True if <E> has two PCurves in the
680// parametric space of <F>. i.e. <F> is on a closed
681// surface and <E> is on the closing curve.
682//=======================================================================
683
684Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
703a6abd 685 const TopoDS_Face& F)
7fd59977 686{
687 TopLoc_Location l;
688 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
689 if (IsClosed(E,S,l)) return Standard_True;
690 return IsClosed(E, BRep_Tool::Triangulation(F,l));
691}
692
693//=======================================================================
694//function : IsClosed
695//purpose : Returns True if <E> has two PCurves in the
696// parametric space of <S>. i.e. <S> is a closed
697// surface and <E> is on the closing curve.
698//=======================================================================
699
700Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
703a6abd
O
701 const Handle(Geom_Surface)& S,
702 const TopLoc_Location& L)
7fd59977 703{
704 //modified by NIZNHY-PKV Fri Oct 17 12:16:58 2008f
705 if (IsPlane(S)) {
706 return Standard_False;
707 }
708 //modified by NIZNHY-PKV Fri Oct 17 12:16:54 2008t
709 //
710 TopLoc_Location l = L.Predivided(E.Location());
711
712 // find the representation
713 BRep_ListIteratorOfListOfCurveRepresentation itcr
714 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
715
716 while (itcr.More()) {
717 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
718 if (cr->IsCurveOnSurface(S,l) &&
703a6abd 719 cr->IsCurveOnClosedSurface())
7fd59977 720 return Standard_True;
721 itcr.Next();
722 }
723 return Standard_False;
724}
725
726//=======================================================================
727//function : IsClosed
728//purpose : Returns True if <E> has two arrays of indices in
729// the triangulation <T>.
730//=======================================================================
731
732Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
703a6abd 733 const Handle(Poly_Triangulation)& T)
7fd59977 734{
735 TopLoc_Location l = E.Location();
736
737 // find the representation
738 BRep_ListIteratorOfListOfCurveRepresentation itcr
739 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
740
741 while (itcr.More()) {
742 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
743 if (cr->IsPolygonOnTriangulation(T,l) &&
703a6abd 744 cr->IsPolygonOnClosedTriangulation())
7fd59977 745 return Standard_True;
746 itcr.Next();
747 }
748 return Standard_False;
749}
750
751//=======================================================================
752//function : Tolerance
753//purpose : Returns the tolerance for <E>.
754//=======================================================================
755
756Standard_Real BRep_Tool::Tolerance(const TopoDS_Edge& E)
757{
758 Standard_Real p = (*((Handle(BRep_TEdge)*)&E.TShape()))->Tolerance();
759 Standard_Real pMin = Precision::Confusion();
760 if (p > pMin) return p;
761 else return pMin;
762}
763
764//=======================================================================
765//function : SameParameter
766//purpose : Returns the SameParameter flag for the edge.
767//=======================================================================
768
769Standard_Boolean BRep_Tool::SameParameter(const TopoDS_Edge& E)
770{
771 return (*((Handle(BRep_TEdge)*)&E.TShape()))->SameParameter();
772}
773
774//=======================================================================
775//function : SameRange
776//purpose : Returns the SameRange flag for the edge.
777//=======================================================================
778
779Standard_Boolean BRep_Tool::SameRange(const TopoDS_Edge& E)
780{
781 return (*((Handle(BRep_TEdge)*)&E.TShape()))->SameRange();
782}
783
784//=======================================================================
785//function : Degenerated
786//purpose : Returns True if the edge is degenerated.
787//=======================================================================
788
789Standard_Boolean BRep_Tool::Degenerated(const TopoDS_Edge& E)
790{
791 return (*((Handle(BRep_TEdge)*)&E.TShape()))->Degenerated();
792}
793
794//=======================================================================
795//function : Range
796//purpose :
797//=======================================================================
798
799void BRep_Tool::Range(const TopoDS_Edge& E,
703a6abd
O
800 Standard_Real& First,
801 Standard_Real& Last)
7fd59977 802{
803 // set the range to all the representations
804 BRep_ListIteratorOfListOfCurveRepresentation itcr
805 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
806
807 while (itcr.More()) {
808 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
809 if (cr->IsCurve3D()) {
810 const Handle(BRep_Curve3D)& CR = *((Handle(BRep_Curve3D)*)&cr);
811 if (!CR->Curve3D().IsNull()) {
703a6abd
O
812 First = CR->First();
813 Last = CR->Last();
814 break;
7fd59977 815 }
816 }
817 else if (cr->IsCurveOnSurface()) {
818 const Handle(BRep_GCurve)& CR = *((Handle(BRep_GCurve)*)&cr);
819 First = CR->First();
820 Last = CR->Last();
821 break;
822 }
823 itcr.Next();
824 }
825}
826
827//=======================================================================
828//function : Range
829//purpose :
830//=======================================================================
831
832void BRep_Tool::Range(const TopoDS_Edge& E,
703a6abd
O
833 const Handle(Geom_Surface)& S,
834 const TopLoc_Location& L,
835 Standard_Real& First,
836 Standard_Real& Last)
7fd59977 837{
838 TopLoc_Location l = L.Predivided(E.Location());
839
840 // find the representation
841 BRep_ListIteratorOfListOfCurveRepresentation itcr
842 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
843
844 while (itcr.More()) {
845 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
846 if (cr->IsCurveOnSurface(S,l)) {
847 (*((Handle(BRep_GCurve)*)&cr))->Range(First,Last);
848 break;
849 }
850 itcr.Next();
851 }
852 if (!itcr.More()) {
853 Range(E,First,Last);
854 }
855 (*((Handle(BRep_TEdge)*)&E.TShape()))->Modified(Standard_True);
856 }
857
858//=======================================================================
859//function : Range
860//purpose :
861//=======================================================================
862
863void BRep_Tool::Range(const TopoDS_Edge& E,
703a6abd
O
864 const TopoDS_Face& F,
865 Standard_Real& First,
866 Standard_Real& Last)
7fd59977 867{
868 TopLoc_Location L;
869 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
870 Range(E,S,L,First,Last);
871}
872
873//=======================================================================
874//function : UVPoints
875//purpose :
876//=======================================================================
877
878void BRep_Tool::UVPoints(const TopoDS_Edge& E,
703a6abd
O
879 const Handle(Geom_Surface)& S,
880 const TopLoc_Location& L,
881 gp_Pnt2d& PFirst,
882 gp_Pnt2d& PLast)
7fd59977 883{
884 TopLoc_Location l = L.Predivided(E.Location());
885 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
886
887 // find the representation
888 BRep_ListIteratorOfListOfCurveRepresentation itcr
889 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
890
891 while (itcr.More()) {
892 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
893 if (cr->IsCurveOnSurface(S,l)) {
894 if (cr->IsCurveOnClosedSurface() && Eisreversed)
703a6abd 895 (*((Handle(BRep_CurveOnClosedSurface)*)&cr))->UVPoints2(PFirst,PLast);
7fd59977 896 else
703a6abd 897 (*((Handle(BRep_CurveOnSurface)*)&cr))->UVPoints(PFirst,PLast);
7fd59977 898 return;
899 }
900 itcr.Next();
901 }
902
903 // for planar surface project the vertices
904 // modif 21-05-97 : for RectangularTrimmedSurface, project the vertices
905 Handle(Geom_Plane) GP;
906 Handle(Geom_RectangularTrimmedSurface) GRTS;
907 GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
908 if(!GRTS.IsNull())
909 GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface());
910 else
911 GP = Handle(Geom_Plane)::DownCast(S);
912 //fin modif du 21-05-97
913 if (!GP.IsNull()) {
914 // get the two vertices
915 TopoDS_Vertex Vf,Vl;
916 TopExp::Vertices(E,Vf,Vl);
917
918 TopLoc_Location Linverted = L.Inverted();
919 Vf.Move(Linverted);
920 Vl.Move(Linverted);
921 Standard_Real u,v;
922 gp_Pln pln = GP->Pln();
923
924 u=v=0.;
925 if (!Vf.IsNull()) {
926 gp_Pnt PF = BRep_Tool::Pnt(Vf);
927 ElSLib::Parameters(pln,PF,u,v);
928 }
929 PFirst.SetCoord(u,v);
930
931 u=v=0.;
932 if (!Vl.IsNull()) {
933 gp_Pnt PL = BRep_Tool::Pnt(Vl);
934 ElSLib::Parameters(pln,PL,u,v);
935 }
936 PLast.SetCoord(u,v);
937 }
938}
939
940//=======================================================================
941//function : UVPoints
942//purpose :
943//=======================================================================
944
945void BRep_Tool::UVPoints(const TopoDS_Edge& E,
703a6abd
O
946 const TopoDS_Face& F,
947 gp_Pnt2d& PFirst,
948 gp_Pnt2d& PLast)
7fd59977 949{
950 TopLoc_Location L;
951 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
952 TopoDS_Edge aLocalEdge = E;
953 if (F.Orientation() == TopAbs_REVERSED) {
954 aLocalEdge.Reverse();
955// UVPoints(E,S,L,PFirst,PLast);
956 }
957// UVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast);
958// else
959// UVPoints(E,S,L,PFirst,PLast);
960 UVPoints(aLocalEdge,S,L,PFirst,PLast);
961}
962
963//=======================================================================
964//function : SetUVPoints
965//purpose :
966//=======================================================================
967
968void BRep_Tool::SetUVPoints(const TopoDS_Edge& E,
703a6abd
O
969 const Handle(Geom_Surface)& S,
970 const TopLoc_Location& L,
971 const gp_Pnt2d& PFirst,
972 const gp_Pnt2d& PLast)
7fd59977 973{
974 TopLoc_Location l = L.Predivided(E.Location());
975 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
976
977 // find the representation
978 BRep_ListIteratorOfListOfCurveRepresentation itcr
979 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
980
981 while (itcr.More()) {
982 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
983 if (cr->IsCurveOnSurface(S,l)) {
984 if (cr->IsCurveOnClosedSurface() && Eisreversed)
703a6abd
O
985 (*((Handle(BRep_CurveOnClosedSurface)*) &cr))->
986 SetUVPoints2(PFirst,PLast);
7fd59977 987 else
703a6abd
O
988 (*((Handle(BRep_CurveOnSurface)*) &cr))->
989 SetUVPoints(PFirst,PLast);
7fd59977 990 }
991 itcr.Next();
992 }
993}
994
995//=======================================================================
996//function : SetUVPoints
997//purpose :
998//=======================================================================
999
1000void BRep_Tool::SetUVPoints(const TopoDS_Edge& E,
703a6abd
O
1001 const TopoDS_Face& F,
1002 const gp_Pnt2d& PFirst,
1003 const gp_Pnt2d& PLast)
7fd59977 1004{
1005 TopLoc_Location L;
1006 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1007 TopoDS_Edge aLocalEdge = E;
1008 if (F.Orientation() == TopAbs_REVERSED) {
1009 aLocalEdge.Reverse();
1010// SetUVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast);
1011 }
1012// else
1013// SetUVPoints(E,S,L,PFirst,PLast);
1014 SetUVPoints(aLocalEdge,S,L,PFirst,PLast);
1015}
1016
1017//=======================================================================
1018//function : HasContinuity
1019//purpose : Returns True if the edge is on the surfaces of the
1020// two faces.
1021//=======================================================================
1022
1023Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E,
703a6abd
O
1024 const TopoDS_Face& F1,
1025 const TopoDS_Face& F2)
7fd59977 1026{
1027 TopLoc_Location l1,l2;
1028 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1029 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1030 return HasContinuity(E,S1,S2,l1,l2);
1031}
1032
1033//=======================================================================
1034//function : Continuity
1035//purpose : Returns the continuity.
1036//=======================================================================
1037
1038GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E,
703a6abd
O
1039 const TopoDS_Face& F1,
1040 const TopoDS_Face& F2)
7fd59977 1041{
1042 TopLoc_Location l1,l2;
1043 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1044 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1045 return Continuity(E,S1,S2,l1,l2);
1046}
1047
1048//=======================================================================
1049//function : HasContinuity
1050//purpose : Returns True if the edge is on the surfaces.
1051//=======================================================================
1052
1053Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E,
703a6abd
O
1054 const Handle(Geom_Surface)& S1,
1055 const Handle(Geom_Surface)& S2,
1056 const TopLoc_Location& L1,
1057 const TopLoc_Location& L2)
7fd59977 1058{
1059 const TopLoc_Location& Eloc = E.Location();
1060 TopLoc_Location l1 = L1.Predivided(Eloc);
1061 TopLoc_Location l2 = L2.Predivided(Eloc);
1062
1063 // find the representation
1064 BRep_ListIteratorOfListOfCurveRepresentation itcr
1065 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
1066
1067 while (itcr.More()) {
1068 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1069 if (cr->IsRegularity(S1,S2,l1,l2))
1070 return Standard_True;
1071 itcr.Next();
1072 }
1073 return Standard_False;
1074}
1075
1076//=======================================================================
1077//function : Continuity
1078//purpose : Returns the continuity.
1079//=======================================================================
1080
1081GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E,
703a6abd
O
1082 const Handle(Geom_Surface)& S1,
1083 const Handle(Geom_Surface)& S2,
1084 const TopLoc_Location& L1,
1085 const TopLoc_Location& L2)
7fd59977 1086{
1087 TopLoc_Location l1 = L1.Predivided(E.Location());
1088 TopLoc_Location l2 = L2.Predivided(E.Location());
1089
1090 // find the representation
1091 BRep_ListIteratorOfListOfCurveRepresentation itcr
1092 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
1093
1094 while (itcr.More()) {
1095 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1096 if (cr->IsRegularity(S1,S2,l1,l2))
1097 return cr->Continuity();
1098 itcr.Next();
1099 }
1100 return GeomAbs_C0;
1101}
1102
1103//=======================================================================
1104//function : Pnt
1105//purpose : Returns the 3d point.
1106//=======================================================================
1107
1108gp_Pnt BRep_Tool::Pnt(const TopoDS_Vertex& V)
1109{
1110 Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1111 gp_Pnt P = TV->Pnt();
1112 P.Transform(V.Location().Transformation());
1113 return P;
1114}
1115
1116//=======================================================================
1117//function : Tolerance
1118//purpose : Returns the tolerance.
1119//=======================================================================
1120
1121Standard_Real BRep_Tool::Tolerance(const TopoDS_Vertex& V)
1122{
1123 Standard_Real p = (*((Handle(BRep_TVertex)*)&V.TShape()))->Tolerance();
1124 Standard_Real pMin = Precision::Confusion();
1125 if (p > pMin) return p;
1126 else return pMin;
1127}
1128
1129//=======================================================================
1130//function : Parameter
1131//purpose : Returns the parameter of <V> on <E>.
1132//=======================================================================
1133
1134Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
703a6abd 1135 const TopoDS_Edge& E)
7fd59977 1136{
1137
1138 // Search the vertex in the edge
1139
1140 Standard_Boolean rev = Standard_False;
1141 TopoDS_Shape VF;
1142 TopAbs_Orientation orient = TopAbs_INTERNAL;
1143
1144 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1145
1146 // if the edge has no vertices
1147 // and is degenerated use the vertex orientation
1148 // RLE, june 94
1149
1150 if (!itv.More() && Degenerated(E)) {
1151 orient = V.Orientation();
1152 }
1153
1154 while (itv.More()) {
1155 const TopoDS_Shape& Vcur = itv.Value();
1156 if (V.IsSame(Vcur)) {
1157 if (VF.IsNull()) {
703a6abd 1158 VF = Vcur;
7fd59977 1159 }
1160 else {
703a6abd
O
1161 rev = E.Orientation() == TopAbs_REVERSED;
1162 if (Vcur.Orientation() == V.Orientation()) {
1163 VF = Vcur;
1164 }
7fd59977 1165 }
1166 }
1167 itv.Next();
1168 }
1169
1170 if (!VF.IsNull()) orient = VF.Orientation();
1171
1172 Standard_Real f,l;
1173
1174 if (orient == TopAbs_FORWARD) {
1175 BRep_Tool::Range(E,f,l);
1176 return (rev) ? l : f;
1177 }
1178
1179 else if (orient == TopAbs_REVERSED) {
1180 BRep_Tool::Range(E,f,l);
1181 return (rev) ? f : l;
1182 }
1183
1184 else {
1185 TopLoc_Location L;
1186 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L,f,l);
1187 L = L.Predivided(V.Location());
1188 if (!C.IsNull() || Degenerated(E)) {
1189 BRep_ListIteratorOfListOfPointRepresentation itpr
703a6abd 1190 ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points());
7fd59977 1191
1192 while (itpr.More()) {
703a6abd
O
1193 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1194 if (pr->IsPointOnCurve(C,L)) {
1195 Standard_Real p = pr->Parameter();
1196 Standard_Real res = p;// SVV 4 nov 99 - to avoid warnings on Linux
1197 if (!C.IsNull()) {
1198 // Closed curves RLE 16 june 94
1199 if (Precision::IsNegativeInfinite(f)) return pr->Parameter();//p;
1200 if (Precision::IsPositiveInfinite(l)) return pr->Parameter();//p;
1201 gp_Pnt Pf = C->Value(f).Transformed(L.Transformation());
1202 gp_Pnt Pl = C->Value(l).Transformed(L.Transformation());
1203 Standard_Real tol = BRep_Tool::Tolerance(V);
1204 if (Pf.Distance(Pl) < tol) {
1205 if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) {
1206 if (V.Orientation() == TopAbs_FORWARD) res = f;//p = f;
1207 else res = l;//p = l;
1208 }
1209 }
1210 }
1211 return res;//p;
1212 }
1213 itpr.Next();
7fd59977 1214 }
1215 }
1216 else {
1217 // no 3d curve !!
1218 // let us try with the first pcurve
1219 Handle(Geom2d_Curve) PC;
1220 Handle(Geom_Surface) S;
1221 BRep_Tool::CurveOnSurface(E,PC,S,L,f,l);
1222 L = L.Predivided(V.Location());
1223 BRep_ListIteratorOfListOfPointRepresentation itpr
703a6abd 1224 ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points());
7fd59977 1225
1226 while (itpr.More()) {
703a6abd
O
1227 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1228 if (pr->IsPointOnCurveOnSurface(PC,S,L)) {
1229 Standard_Real p = pr->Parameter();
1230 // Closed curves RLE 16 june 94
1231 if (PC->IsClosed()) {
1232 if ((p == PC->FirstParameter()) ||
1233 (p == PC->LastParameter())) {
1234 if (V.Orientation() == TopAbs_FORWARD) p = PC->FirstParameter();
1235 else p = PC->LastParameter();
1236 }
1237 }
1238 return p;
1239 }
1240 itpr.Next();
7fd59977 1241 }
1242 }
1243 }
1244
1245 Standard_NoSuchObject::Raise("BRep_Tool:: no parameter on edge");
1246 return 0;
1247}
1248
1249//=======================================================================
1250//function : Parameter
1251//purpose : Returns the parameters of the vertex on the
1252// pcurve of the edge on the face.
1253//=======================================================================
1254
1255Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
703a6abd
O
1256 const TopoDS_Edge& E,
1257 const TopoDS_Face& F)
7fd59977 1258{
1259 TopLoc_Location L;
1260 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1261 return BRep_Tool::Parameter(V,E,S,L);
1262}
1263
1264//=======================================================================
1265//function : Parameter
1266//purpose : Returns the parameters of the vertex on the
1267// pcurve of the edge on the surface.
1268//=======================================================================
1269
1270Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
703a6abd
O
1271 const TopoDS_Edge& E,
1272 const Handle(Geom_Surface)& S,
1273 const TopLoc_Location& L)
7fd59977 1274{
1275 // Search the vertex in the edge
1276
1277 Standard_Boolean rev = Standard_False;
1278 TopoDS_Shape VF;
1279 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1280
1281 while (itv.More()) {
1282 if (V.IsSame(itv.Value())) {
1283 if (VF.IsNull()) VF = itv.Value();
1284 else {
703a6abd
O
1285 rev = E.Orientation() == TopAbs_REVERSED;
1286 if (itv.Value().Orientation() == V.Orientation())
1287 VF = itv.Value();
7fd59977 1288 }
1289 }
1290 itv.Next();
1291 }
1292
1293 TopAbs_Orientation orient = TopAbs_INTERNAL;
1294 if (!VF.IsNull()) orient = VF.Orientation();
1295
1296 Standard_Real f,l;
1297
1298 if (orient == TopAbs_FORWARD) {
1299 BRep_Tool::Range(E,S,L,f,l);
1300 return (rev) ? l : f;
1301 }
1302
1303 else if (orient == TopAbs_REVERSED) {
1304 BRep_Tool::Range(E,S,L,f,l);
1305 return (rev) ? f : l;
1306 }
1307
1308 else {
1309 Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(E,S,L,f,l);
1310 BRep_ListIteratorOfListOfPointRepresentation itpr
1311 ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points());
1312
1313 while (itpr.More()) {
1314 if (itpr.Value()->IsPointOnCurveOnSurface(PC,S,L))
1315 return itpr.Value()->Parameter();
1316 itpr.Next();
1317 }
1318 }
1319
1320 //----------------------------------------------------------
1321
1322 TopLoc_Location L1;
1323 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L1,f,l);
1324 L1 = L1.Predivided(V.Location());
1325 if (!C.IsNull() || Degenerated(E)) {
1326 BRep_ListIteratorOfListOfPointRepresentation itpr
1327 ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points());
1328
1329 while (itpr.More()) {
1330 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1331 if (pr->IsPointOnCurve(C,L1)) {
703a6abd
O
1332 Standard_Real p = pr->Parameter();
1333 Standard_Real res = p;
1334 if (!C.IsNull()) {
1335 // Closed curves RLE 16 june 94
1336 if (Precision::IsNegativeInfinite(f)) return res;
1337 if (Precision::IsPositiveInfinite(l)) return res;
1338 gp_Pnt Pf = C->Value(f).Transformed(L1.Transformation());
1339 gp_Pnt Pl = C->Value(l).Transformed(L1.Transformation());
1340 Standard_Real tol = BRep_Tool::Tolerance(V);
1341 if (Pf.Distance(Pl) < tol) {
1342 if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) {
1343 if (V.Orientation() == TopAbs_FORWARD) res = f;
1344 else res = l;
1345 }
1346 }
1347 }
1348 return res;
7fd59977 1349 }
1350 itpr.Next();
1351 }
1352 }
1353
1354//----------------------------------------------------------
1355
1356 Standard_NoSuchObject::Raise("BRep_Tool:: no parameter on edge");
1357 return 0;
1358}
1359
1360//=======================================================================
1361//function : Parameters
1362//purpose : Returns the parameters of the vertex on the face.
1363//=======================================================================
1364
1365gp_Pnt2d BRep_Tool::Parameters(const TopoDS_Vertex& V,
703a6abd 1366 const TopoDS_Face& F)
7fd59977 1367{
1368 TopLoc_Location L;
1369 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1370 L = L.Predivided(V.Location());
1371 BRep_ListIteratorOfListOfPointRepresentation itpr
1372 ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points());
0d969553 1373 // It is checked if there is PointRepresentation (case non Manifold)
7fd59977 1374
1375 while (itpr.More()) {
1376 if (itpr.Value()->IsPointOnSurface(S,L)) {
1377 return gp_Pnt2d(itpr.Value()->Parameter(),
703a6abd 1378 itpr.Value()->Parameter2());
7fd59977 1379 }
1380 itpr.Next();
1381 }
1382
1383 TopoDS_Vertex Vf,Vl;
1384 TopoDS_Edge E;
0d969553
Y
1385 // Otherwise the edges are searched (PMN 4/06/97) It is not possible to succeed 999/1000!
1386 // even if often there is a way to make more economically than above...
7fd59977 1387 TopExp_Explorer exp;
1388 for (exp.Init(F, TopAbs_EDGE); exp.More(); exp.Next()) {
1389 E = TopoDS::Edge(exp.Current());
1390 TopExp::Vertices(E, Vf, Vl);
1391 if ((V.IsSame(Vf)) || (V.IsSame(Vl))) {
1392 gp_Pnt2d Pf, Pl;
1393 UVPoints(E, F, Pf, Pl);
1394 if (V.IsSame(Vf)) return Pf;
0d969553 1395 else return Pl;//Ambiguity (natural) for degenerated edges.
7fd59977 1396 }
1397 }
1398 Standard_NoSuchObject::Raise("BRep_Tool:: no parameters on surface");
1399 return gp_Pnt2d(0,0);
1400}
1401//=======================================================================
1402//function : IsClosed
1403//purpose : Returns <True> if S if flaged Closed, if S is a
1404// Solid,Shell or Compound returns <True> is S has no free boundaries.
1405//=======================================================================
1406Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Shape& S)
1407{
1408 if (S.ShapeType() == TopAbs_SHELL || S.ShapeType() == TopAbs_SOLID ||
1409 S.ShapeType() == TopAbs_COMPOUND) {
1410 TopTools_MapOfShape M;
1411 TopExp_Explorer exp;
1412 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
1413// for (TopExp_Explorer exp(S,TopAbs_EDGE); exp.More(); exp.Next()) {
1414 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1415 if (BRep_Tool::Degenerated(E)) continue;
1416 if (!M.Add(E)) M.Remove(E);
1417 }
1418 if ( M.IsEmpty()) return 1;
1419 }
1420 return (S.Closed());
1421}
1422
1423//modified by NIZNHY-PKV Fri Oct 17 14:09:58 2008 f
1424//=======================================================================
1425//function : IsPlane
1426//purpose :
1427//=======================================================================
1428Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS)
1429{
1430 Standard_Boolean bRet;
1431 Handle(Geom_Plane) aGP;
1432 Handle(Geom_RectangularTrimmedSurface) aGRTS;
1433 Handle(Geom_OffsetSurface) aGOFS;
1434 //
1435 aGRTS=Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
1436 aGOFS=Handle(Geom_OffsetSurface)::DownCast(aS);
1437 //
1438 if(!aGOFS.IsNull()) {
1439 aGP=Handle(Geom_Plane)::DownCast(aGOFS->BasisSurface());
1440 }
1441 else if(!aGRTS.IsNull()) {
1442 aGP=Handle(Geom_Plane)::DownCast(aGRTS->BasisSurface());
1443 }
1444 else {
1445 aGP=Handle(Geom_Plane)::DownCast(aS);
1446 }
1447 //
1448 bRet=!aGP.IsNull();
1449 //
1450 return bRet;
1451}