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