0024624: Lost word in license statement in source files
[occt.git] / src / TopOpeBRepDS / TopOpeBRepDS_BuildTool.cxx
CommitLineData
b311480e 1// Created on: 1993-06-17
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <TopOpeBRepDS_BuildTool.ixx>
18
19#include <TopoDS.hxx>
20#include <TopExp_Explorer.hxx>
21#include <TopAbs.hxx>
22#include <BRep_Tool.hxx>
23#include <TopOpeBRepTool_GeomTool.hxx>
24#include <TopOpeBRepTool_ShapeTool.hxx>
25#include <TopOpeBRepTool_OutCurveType.hxx>
26#include <TopOpeBRepDS_SurfaceCurveInterference.hxx>
27#include <Precision.hxx>
28#include <Geom_Surface.hxx>
29#include <GeomAdaptor_Curve.hxx>
30#include <Geom_BSplineCurve.hxx>
31#include <Geom_Plane.hxx>
32#include <Geom_TrimmedCurve.hxx>
33#include <GeomAPI_ProjectPointOnCurve.hxx>
34#include <GeomAPI_ProjectPointOnSurf.hxx>
35#include <TopoDS_Edge.hxx>
36#include <TopoDS_Vertex.hxx>
37#include <ElCLib.hxx>
38#include <gp.hxx>
39#include <gp_Vec2d.hxx>
40#include <TopExp.hxx>
41#include <TopLoc_Location.hxx>
42#include <TopOpeBRepTool_ShapeTool.hxx>
43#include <Geom_SphericalSurface.hxx>
44#include <Standard_ProgramError.hxx>
45#include <Standard_NotImplemented.hxx>
46#include <gp_Pnt.hxx>
47#include <gp_Pnt2d.hxx>
48#include <TopOpeBRepDS_Dumper.hxx>
49#include <BRepAdaptor_Surface.hxx>
50#include <Geom2d_Conic.hxx>
51#include <Geom2d_Circle.hxx>
52#include <Geom2d_Line.hxx>
53#include <Geom2d_Ellipse.hxx>
54#include <Geom2d_Parabola.hxx>
55#include <Geom2d_Hyperbola.hxx>
56#include <Geom2d_BezierCurve.hxx>
57#include <Geom2d_BSplineCurve.hxx>
58#include <Geom2d_TrimmedCurve.hxx>
59#include <Geom2d_OffsetCurve.hxx>
60#include <Geom_Conic.hxx>
61#include <Geom_Circle.hxx>
62#include <Geom_Line.hxx>
63#include <Geom_Ellipse.hxx>
64#include <Geom_Parabola.hxx>
65#include <Geom_Hyperbola.hxx>
66#include <Geom_BezierCurve.hxx>
67#include <Geom_BSplineCurve.hxx>
68#include <Geom_TrimmedCurve.hxx>
69#include <Geom_OffsetCurve.hxx>
70// includes especially needed by the static Project function
71#include <BRep_Tool.hxx>
72#include <GeomAdaptor_Curve.hxx>
73#include <Extrema_ExtPC.hxx>
74#include <gp_Pnt.hxx>
75#include <Extrema_POnCurv.hxx>
76#include <Geom_Curve.hxx>
77#include <Geom_BSplineCurve.hxx>
78#include <TCollection_AsciiString.hxx>
79#include <Geom2d_TrimmedCurve.hxx>
80
81#ifdef DEB
1d0a9d4d 82extern Standard_Boolean TopOpeBRepDS_GettraceDSNC();
83extern Standard_Boolean TopOpeBRepDS_GettraceBUTO();
84extern Standard_Boolean TopOpeBRepDS_GettraceTRPE();
85extern Standard_Boolean TopOpeBRepDS_GettraceSANTRAN();
7fd59977 86static void DUMPCURVES(const Handle(Geom_Curve)& C3D,const TopOpeBRepDS_Curve& C)
87{
88 if ( !C3D.IsNull() ) {
89 Standard_Real dp1 = C3D->FirstParameter();
90 Standard_Real dp2 = C3D->LastParameter();
91 cout<<"TopOpeBRepDS_BuildTool : C3D = "<<dp1<<","<<dp2<<endl;
92 }
93 if ( !C.Curve1().IsNull() ) {
94 Standard_Real dp1 = C.Curve1()->FirstParameter();
95 Standard_Real dp2 = C.Curve1()->LastParameter();
96 cout<<"TopOpeBRepDS_BuildTool : PC1 = "<<dp1<<","<<dp2<<endl;
97 }
98 if ( !C.Curve2().IsNull() ) {
99 Standard_Real dp1 = C.Curve2()->FirstParameter();
100 Standard_Real dp2 = C.Curve2()->LastParameter();
101 cout<<"TopOpeBRepDS_BuildTool : PC2 = "<<dp1<<","<<dp2<<endl;
102 }
103}
104#endif
105
106#ifdef DRAW
107#include <TopOpeBRepDS_DRAW.hxx>
108#endif
109
110//-----------------------------------------------------------------------
111//function : PrintSurface
112//purpose : print the name of a surface on a stream
113// a mettre dans TopOpeBRepDS_Dumper.cxx NYI
114//-----------------------------------------------------------------------
115
116#ifdef DEB
117static Standard_OStream& PrintSurface(const TopoDS_Face& F, Standard_OStream& s)
118{
119 BRepAdaptor_Surface STA_Surface(F);
120 GeomAbs_SurfaceType t = STA_Surface.GetType();
121 switch(t) {
122 case GeomAbs_Plane : s<<"PLANE"; break;
123 case GeomAbs_Cylinder : s<<"CYLINDER"; break;
124 case GeomAbs_Cone : s<<"CONE"; break;
125 case GeomAbs_Sphere : s<<"SPHERE"; break;
126 case GeomAbs_Torus : s<<"TORUS"; break;
127 case GeomAbs_BezierSurface : s<<"BEZIERSURFACE"; break;
128 case GeomAbs_BSplineSurface : s<<"BSPLINESURFACE"; break;
129 case GeomAbs_SurfaceOfRevolution : s<<"SURFACEOFREVOLUTION"; break;
130 case GeomAbs_SurfaceOfExtrusion : s<<"SURFACEOFEXTRUSION"; break;
131 case GeomAbs_OtherSurface : default : s<<"OTHERSURFACE"; break;
132 }
133 return s;
134}
135#endif
136
137Standard_EXPORT Handle(Geom2d_Curve) BASISCURVE2D(const Handle(Geom2d_Curve)& C);
138
139//-----------------------------------------------------------------------
140//function : GetOrigin
141//purpose : a mettre dans TopOpeBRepDS_Dumper.cxx NYI
142//-----------------------------------------------------------------------
143
144#ifdef DEB
145static Standard_Boolean GetOrigin(const Handle(Geom2d_Curve)& PCIN, gp_Pnt2d& o)
146{
147 if (PCIN.IsNull()) return Standard_False;
148 Handle(Geom2d_Curve) PC = ::BASISCURVE2D(PCIN);
149 if (PC.IsNull()) return Standard_False;
150
151 Handle(Standard_Type) T = PC->DynamicType();
152 if ((T==STANDARD_TYPE(Geom2d_Circle)) ||
153 (T==STANDARD_TYPE(Geom2d_Ellipse)) ||
154 (T==STANDARD_TYPE(Geom2d_Parabola)) ||
155 (T==STANDARD_TYPE(Geom2d_Hyperbola))) {
156 o = Handle(Geom2d_Conic)::DownCast(PC)->Location();
157 return Standard_True;
158 }
159 else if (T==STANDARD_TYPE(Geom2d_Line)) {
160 o = Handle(Geom2d_Line)::DownCast(PC)->Location();
161 return Standard_True;
162 }
163 else {
164 return Standard_False;
165 }
d3f26155 166// return Standard_False;
7fd59977 167}
168#endif
169
170//-----------------------------------------------------------------------
171//function : GetOrigin
172//purpose : a mettre dans TopOpeBRepDS_Dumper.cxx NYI
173//-----------------------------------------------------------------------
174
175#ifdef DEB
176static Standard_Boolean GetOrigin(const Handle(Geom_Curve)& CIN, gp_Pnt& o)
177{
178 if (CIN.IsNull()) return Standard_False;
179 Handle(Geom_Curve) C = TopOpeBRepTool_ShapeTool::BASISCURVE(CIN);
180 if (C.IsNull()) return Standard_False;
181
182 Handle(Standard_Type) T = C->DynamicType();
183 if ((T==STANDARD_TYPE(Geom_Circle)) ||
184 (T==STANDARD_TYPE(Geom_Ellipse)) ||
185 (T==STANDARD_TYPE(Geom_Parabola)) ||
186 (T==STANDARD_TYPE(Geom_Hyperbola))) {
187 o = Handle(Geom_Conic)::DownCast(C)->Location();
188 return Standard_True;
189 }
190 else if (T==STANDARD_TYPE(Geom_Line)) {
191 o = Handle(Geom_Line)::DownCast(C)->Position().Location();
192 return Standard_True;
193 }
194 else {
195 return Standard_False;
196 }
7fd59977 197}
198#endif
199
200Standard_Boolean FUN_UisoLineOnSphe
201(const TopoDS_Shape& F,
202 const Handle(Geom2d_Curve)& PC)
203{
204 if (PC.IsNull()) return Standard_False;
205
206 Handle(Geom_Surface) SSS = TopOpeBRepTool_ShapeTool::BASISSURFACE(TopoDS::Face(F));
207 Handle(Geom2d_Curve) LLL = ::BASISCURVE2D(PC);
208 Handle(Standard_Type) TS = SSS->DynamicType();
209 Handle(Standard_Type) T2 = LLL->DynamicType();
210 Standard_Boolean issphere = (TS == STANDARD_TYPE(Geom_SphericalSurface));
211 Standard_Boolean isline2d = (T2 == STANDARD_TYPE(Geom2d_Line));
212 Standard_Boolean isisoU = Standard_False;
213 if (issphere && isline2d) {
214 Handle(Geom2d_Line) L = Handle(Geom2d_Line)::DownCast(LLL);
215 const gp_Dir2d& d = L->Direction();
216 isisoU = (Abs(d.X()) < Precision::Parametric(Precision::Confusion()));
217 }
218 return isisoU;
219}
220
221//=======================================================================
222//function : TopOpeBRepDS_BuildTool
223//purpose :
224//=======================================================================
225
226TopOpeBRepDS_BuildTool::TopOpeBRepDS_BuildTool():
227myCurveTool(TopOpeBRepTool_APPROX),
228myOverWrite(Standard_True),
229myTranslate(Standard_True)
230{
231}
232
233//=======================================================================
234//function : TopOpeBRepDS_BuildTool
235//purpose :
236//=======================================================================
237
238TopOpeBRepDS_BuildTool::TopOpeBRepDS_BuildTool
239 (const TopOpeBRepTool_OutCurveType O) :
240myCurveTool(O),
241myOverWrite(Standard_True),
242myTranslate(Standard_True)
243{
244}
245
246//=======================================================================
247//function : TopOpeBRepDS_BuildTool
248//purpose :
249//=======================================================================
250
251TopOpeBRepDS_BuildTool::TopOpeBRepDS_BuildTool
252 (const TopOpeBRepTool_GeomTool& GT) :
253myCurveTool(GT),
254myOverWrite(Standard_True),
255myTranslate(Standard_True)
256{
257}
258
259Standard_Boolean TopOpeBRepDS_BuildTool::OverWrite()const
260{
261 return myOverWrite;
262}
263
264void TopOpeBRepDS_BuildTool::OverWrite(const Standard_Boolean O)
265{
266 myOverWrite = O;
267}
268
269Standard_Boolean TopOpeBRepDS_BuildTool::Translate()const
270{
271 return myTranslate;
272}
273
274void TopOpeBRepDS_BuildTool::Translate(const Standard_Boolean T)
275{
276 myTranslate = T;
277}
278
279//=======================================================================
280//function : GetGeomTool
281//purpose :
282//=======================================================================
283
284const TopOpeBRepTool_GeomTool& TopOpeBRepDS_BuildTool::GetGeomTool() const
285{
286 const TopOpeBRepTool_GeomTool& GT = myCurveTool.GetGeomTool();
287 return GT;
288}
289
290//=======================================================================
291//function : ChangeGeomTool
292//purpose :
293//=======================================================================
294
295TopOpeBRepTool_GeomTool& TopOpeBRepDS_BuildTool::ChangeGeomTool()
296{
297 TopOpeBRepTool_GeomTool& GT = myCurveTool.ChangeGeomTool();
298 return GT;
299}
300
301//=======================================================================
302//function : MakeVertex
303//purpose :
304//=======================================================================
305
306void TopOpeBRepDS_BuildTool::MakeVertex(TopoDS_Shape& V,
307 const TopOpeBRepDS_Point& P)const
308{
309 myBuilder.MakeVertex(TopoDS::Vertex(V),P.Point(),P.Tolerance());
310}
311
312#ifdef DEB
313//-----------------------------------------------------------------------
314static Standard_OStream& DUMPPNT(const gp_Pnt& P, Standard_OStream& OS)
315//-----------------------------------------------------------------------
316{ OS<<P.X()<<" "<<P.Y()<<" "<<P.Z(); return OS; }
317#endif
318
319//=======================================================================
320//function : MakeEdge
321//purpose :
322//=======================================================================
323
324void TopOpeBRepDS_BuildTool::MakeEdge(TopoDS_Shape& E,
325 const TopOpeBRepDS_Curve& C)const
326{
327 // Gestion des courbes nulles pour carreaux pointus
328 // RLE 28-6-94
329
330 if (C.Curve().IsNull()) {
331 myBuilder.MakeEdge(TopoDS::Edge(E));
332 myBuilder.Degenerated(TopoDS::Edge(E),Standard_True);
333 return;
334 }
335
336 const Handle(Geom_Curve)& GC = C.Curve();
337 myBuilder.MakeEdge(TopoDS::Edge(E),GC,C.Tolerance());
338
339 Standard_Boolean addorigin = Standard_False;
340 Standard_Boolean setrange = Standard_False;
341
342 if (addorigin) {
343 if ( GC->IsClosed() ) {
344 // in case of a closed curve, insert in E a vertex located at the origin
345 // of the curve C.
346 TopoDS_Vertex V;
347 Standard_Real first = GC->FirstParameter();
348 gp_Pnt P = GC->Value(first);
349 myBuilder.MakeVertex(V,P,C.Tolerance());
350 myBuilder.Add(E,V);
351 V.Reverse();
352 myBuilder.Add(E,V);
353
354 // If the curve is a degree 1 bspline set the range to 1 .. NbPoles
355 Handle(Geom_BSplineCurve) BSC = Handle(Geom_BSplineCurve)::DownCast(GC);
356 if (!BSC.IsNull()) {
357 if (BSC->Degree() == 1) {
358 myBuilder.Range(TopoDS::Edge(E),1,BSC->NbPoles());
359#ifdef DEB
360 if (TopOpeBRepDS_GettraceBUTO()) {
361 cout<<endl<<"TopOpeBRepDS_BuildTool : ";
362 cout<<"new range of "<< 1 <<" "<<BSC->NbPoles()<<endl;
363 }
364#endif
365 }
366 }
367
368#ifdef DEB
369 if (TopOpeBRepDS_GettraceBUTO()) {
370 cout<<"TopOpeBRepDS_BuildTool : ";
371 cout<<"vertices on parameter "<<first<<endl;
372 cout<<" point is "; DUMPPNT(P,cout); cout<<endl;
373 }
374#endif
375 }
376 }
377
378 if (setrange) {
379 Standard_Real first,last;
380 Standard_Boolean rangedef = C.Range(first,last);
381 if (rangedef) {
382 Range(E,first,last);
383#ifdef DEB
384 if (TopOpeBRepDS_GettraceBUTO()) {
385 cout<<"TopOpeBRepDS_BuildTool : ";
386 cout<<"set edge range : "<<first<<" "<<last<<endl;
387 }
388#endif
389 }
390 }
391}
392
393//=======================================================================
394//function : MakeEdge
395//purpose :
396//=======================================================================
397
398void TopOpeBRepDS_BuildTool::MakeEdge
399(TopoDS_Shape& E,
400 const TopOpeBRepDS_Curve& C,
401 const TopOpeBRepDS_DataStructure& BDS) const
402{
403 // Gestion des courbes nulles pour carreaux pointus
404 // RLE 28-6-94
405
406 TopoDS_Edge& EE = TopoDS::Edge(E);
407
408 if (C.Curve().IsNull()) {
409 myBuilder.MakeEdge(EE);
410 myBuilder.Degenerated(EE,Standard_True);
411
412 // Creation d'une arete avec PCurve connectee a la BDS Curve
413 // JYL 22-09-94
414 Handle(TopOpeBRepDS_Interference) I = C.GetSCI1();
415 Handle(TopOpeBRepDS_SurfaceCurveInterference) SCI;
416 SCI=Handle(TopOpeBRepDS_SurfaceCurveInterference)::DownCast(I);
417 Standard_Integer iS = SCI->Support();
418 const TopOpeBRepDS_Surface& DSS = BDS.Surface(iS);
419 const Handle(Geom_Surface)& GS = DSS.Surface();
420 const Handle(Geom2d_Curve)& PC = SCI->PCurve();
421 myBuilder.UpdateEdge(EE,PC,GS,TopLoc_Location(),DSS.Tolerance());
422 return;
423 }
424 else {
425 const Handle(Geom_Curve)& GC = C.Curve();
426 myBuilder.MakeEdge(EE,GC,C.Tolerance());
427 }
428
429}
430
431//=======================================================================
432//function : MakeEdge
433//purpose :
434//=======================================================================
435
436void TopOpeBRepDS_BuildTool::MakeEdge
437(TopoDS_Shape& E,
438 const Handle(Geom_Curve)& C,
439 const Standard_Real Tol)const
440{
441 myBuilder.MakeEdge(TopoDS::Edge(E),C,Tol);
442}
443
444
445//=======================================================================
446//function : MakeEdge
447//purpose :
448//=======================================================================
449
450void TopOpeBRepDS_BuildTool::MakeEdge(TopoDS_Shape& E) const
451{
452 myBuilder.MakeEdge(TopoDS::Edge(E));
453}
454
455
456//=======================================================================
457//function : MakeWire
458//purpose :
459//=======================================================================
460
461void TopOpeBRepDS_BuildTool::MakeWire(TopoDS_Shape& W)const
462{
463 myBuilder.MakeWire(TopoDS::Wire(W));
464}
465
466
467//=======================================================================
468//function : MakeFace
469//purpose :
470//=======================================================================
471
472void TopOpeBRepDS_BuildTool::MakeFace(TopoDS_Shape& F,
473 const TopOpeBRepDS_Surface& S)const
474{
475 myBuilder.MakeFace(TopoDS::Face(F),S.Surface(),S.Tolerance());
476}
477
478
479//=======================================================================
480//function : MakeShell
481//purpose :
482//=======================================================================
483
484void TopOpeBRepDS_BuildTool::MakeShell(TopoDS_Shape& Sh)const
485{
486 myBuilder.MakeShell(TopoDS::Shell(Sh));
487}
488
489
490//=======================================================================
491//function : MakeSolid
492//purpose :
493//=======================================================================
494
495void TopOpeBRepDS_BuildTool::MakeSolid(TopoDS_Shape& S)const
496{
497 myBuilder.MakeSolid(TopoDS::Solid(S));
498}
499
500
501//=======================================================================
502//function : CopyEdge
503//purpose :
504//=======================================================================
505
506void TopOpeBRepDS_BuildTool::CopyEdge(const TopoDS_Shape& Ein,
507 TopoDS_Shape& Eou)const
508{
509
510 // Splendide evolution de BRep_Curve3D::BRep_Curve3D(Geom_Curve,Location)
511 // apres modification de la primitive Sphere pour parametrisation de
512 // l'arete meridienne en -pi/2,+pi/2.
513 // Ein est l'arete de couture complete d'une sphere complete
514 // BRep_Tool::Range(Ein) --> -pi/2,+pi/2
515 // BRep_Tool::Range(Ein.EmptyCopied()) --> 0,2pi
516 // NYI reflexion sur la notion de Range d'une arete et de la geometrie
517 // NYI sous jacente dans le cas ou, par construction, les vertex d'une
518 // NYI arete on des valeurs de parametre HORS des bornes [first,last] de la
519 // NYI courbe 3D support de l'arete (cas de l'arete de couture d'une sphere)
520 // On redefinit desormais le range de l'arete Eou, a la place de se
521 // contenter du simplissime Eou = Ein.EmptyCopied();
522 // merci les amis : correction bug PRO2586
523
524 Standard_Real f,l;
525 TopoDS_Edge E1 = TopoDS::Edge(Ein);
526 BRep_Tool::Range(E1,f,l);
527 Eou = Ein.EmptyCopied();
528 TopoDS_Edge E2 = TopoDS::Edge(Eou);
529 myBuilder.Range(E2,f,l);
530}
531
532
533//=======================================================================
534//function : GetOrientedEdgeVertices
535//purpose :
536//=======================================================================
537
538void TopOpeBRepDS_BuildTool::GetOrientedEdgeVertices
539(TopoDS_Edge& E,
540 TopoDS_Vertex& Vmin, TopoDS_Vertex& Vmax,
541 Standard_Real& Parmin, Standard_Real& Parmax) const
542{
543 if ( E.Orientation() == TopAbs_FORWARD)
544 TopExp::Vertices(E,Vmin,Vmax);
545 else
546 TopExp::Vertices(E,Vmax,Vmin);
547 if ( !Vmin.IsNull() && !Vmax.IsNull()) {
548 Parmin = BRep_Tool::Parameter(Vmin,E);
549 Parmax = BRep_Tool::Parameter(Vmax,E);
550 }
551}
552
553//=======================================================================
554//function : UpdateEdgeCurveTol
555//purpose :
556//=======================================================================
557
558void TopOpeBRepDS_BuildTool::UpdateEdgeCurveTol
559//(const TopoDS_Face& F1,const TopoDS_Face& F2,
560(const TopoDS_Face& ,const TopoDS_Face& ,
561 TopoDS_Edge& E, const Handle(Geom_Curve)& C3Dnew,
562// const Standard_Real tol3d,
563 const Standard_Real ,
564// const Standard_Real tol2d1,
565 const Standard_Real ,
566// const Standard_Real tol2d2,
567 const Standard_Real ,
568 Standard_Real& newtol,
569 Standard_Real& newparmin,
570 Standard_Real& newparmax) const
571
572{
573 if (C3Dnew.IsNull()) return;
574 BRep_Builder BB;
575
576 // newtol = max des tolerances atteintes en 3d
577// JMB le 06 Juillet 1999
578// les valeurs tol3d et tol2d1,tol2d2 proviennent des approx. Dans la version 2.0 de CasCade,
579// elles n'etaient pas calculees et on renvoyait systematiquement les valeurs initiales (a savoir)
580// 1.E-7. Dans la version 2.1 de CasCade, ces valeurs sont desormais calculees selon un calcul
581// d'erreur dans les Approx. Malheureusement, il apparait que ce calcul d'erreur renvoit dans la
582// plupart des cas de tres grosses valeurs (parfois de l'ordre de 1.E-1). Ce qui amenait la topologie
583// a coder des tolerances enormes dans les pieces resultats rendant celles-ci inexpoitables.
584// De plus on essayait de rafiner la tolerance en appelant les UResolution sur les surfaces support.
585// sur des surfaces tres particulieres, ce UREsolution n'a plus aucun sens et peut amener a des valeurs
586// abberantes.
587// On decide donc de laisser la tolerance de l'edge telle qu'elle est afin d'avoir un comportement similaire
588// a 2.0. Jusqu'a present on a constate que des problemes avec la methode de calcul d'erreur des approx.
589
590
591 newtol = 1.E-7;
592// Standard_Real r1,r2;
593// r1 = TopOpeBRepTool_ShapeTool::Resolution3d(F1,tol2d1);
594// r2 = TopOpeBRepTool_ShapeTool::Resolution3d(F2,tol2d2);
595// newtol=tol3d;
596// if (r1>newtol) newtol=r1;
597// if (r2>newtol) newtol=r2;
598//#ifdef DEB
599// if (TopOpeBRepDS_GettraceDSNC()) cout<<"newtol = "<<newtol<<endl;
600//#endif
601
602// newtol *= 1.5;
603
604 TopoDS_Vertex Vmin,Vmax; Standard_Real parmin,parmax;
605 GetOrientedEdgeVertices(E,Vmin,Vmax,parmin,parmax);
606
607 Standard_Real tolmin=BRep_Tool::Tolerance(Vmin);
608 if(newtol>tolmin) tolmin=newtol;
609 Standard_Real tolmax=BRep_Tool::Tolerance(Vmax);
610 if(newtol>tolmax) tolmax=newtol;
611
612
613// newparmin=C3Dnew->FirstParameter(); // -merge 04-07-97
614// newparmax=C3Dnew->LastParameter(); // -merge 04-07-97
615
616 // +merge 04-07-97
617 Handle(Geom_TrimmedCurve) GTC = Handle(Geom_TrimmedCurve)::DownCast(C3Dnew);
618 if(GTC.IsNull()) {
619 Handle(Geom_BSplineCurve) GBSC = Handle(Geom_BSplineCurve)::DownCast(C3Dnew);
620 if(GBSC.IsNull()) {
621 newparmin = parmin;
622 newparmax = parmax;
623 } else {
624 newparmin=C3Dnew->FirstParameter();
625 newparmax=C3Dnew->LastParameter();
626 }
627 } else {
628 newparmin=C3Dnew->FirstParameter();
629 newparmax=C3Dnew->LastParameter();
630 } // +merge 04-07-97
631
632 if (Vmin.Orientation() == TopAbs_FORWARD) {
633 BB.UpdateVertex(Vmin,newparmin,E,tolmin);
634 BB.UpdateVertex(Vmax,newparmax,E,tolmax);
635 }
636 else {
637 BB.UpdateVertex(Vmin,newparmax,E,tolmin);
638 BB.UpdateVertex(Vmax,newparmin,E,tolmax);
639 }
640
641// DSBT.Curve3D(E,C3Dnew,newtol); // -merge 04-07-97
642 Curve3D(E,C3Dnew,newtol);
643
644 // projection des vertex INTERNAL de E pour parametrage
645 // sur la nouvelle courbe C3Dnew de l'arete E
646 TopExp_Explorer exi(E,TopAbs_VERTEX);
647 for (;exi.More(); exi.Next() ) {
648 const TopoDS_Vertex& vi = TopoDS::Vertex(exi.Current());
649 if ( vi.Orientation() != TopAbs_INTERNAL ) continue;
650 gp_Pnt P = BRep_Tool::Pnt(vi);
651 Standard_Real tolvi=TopOpeBRepTool_ShapeTool::Tolerance(vi);
652 GeomAPI_ProjectPointOnCurve dm(P,C3Dnew,newparmin,newparmax);
653 Standard_Boolean dmdone = dm.Extrema().IsDone();
654 if ( dmdone ) {
655 if ( dm.NbPoints() ) {
656 Standard_Real newpar = dm.LowerDistanceParameter();
657 BB.UpdateVertex(vi,newpar,E,tolvi);
658 }
659 }
660 } // INTERNAL vertex
661}
662
663//=======================================================================
664//function : ApproxCurves
665//purpose :
666//=======================================================================
667
668void TopOpeBRepDS_BuildTool::ApproxCurves
669(const TopOpeBRepDS_Curve& C,
670 TopoDS_Edge& E,
671 Standard_Integer& inewC,
672 const Handle(TopOpeBRepDS_HDataStructure)& HDS) const
673{
674 TopOpeBRepDS_Curve newC1;
675 inewC = HDS->MakeCurve(C,newC1);
676 TopOpeBRepDS_Curve& newC = HDS->ChangeCurve(inewC);
677
678#ifdef DEB
679// Standard_Boolean tDSNC = TopOpeBRepDS_GettraceDSNC();
680 Standard_Boolean tBUTO = TopOpeBRepDS_GettraceBUTO();
681#endif
682
683 // C1 curves have been approximated by BSplines of degree 1 :
684 // compute new geometry on curves.
685
686 const TopoDS_Face& F1 = TopoDS::Face(newC.Shape1());
687 const TopoDS_Face& F2 = TopoDS::Face(newC.Shape2());
688
689 const Handle(Geom_Curve)& C3D = C.Curve();
690 const Handle(Geom2d_Curve)& PC1 = C.Curve1();
691 const Handle(Geom2d_Curve)& PC2 = C.Curve2();
692
693 // Vmin,Vmax = bounding vertices of edge <E>
694 // and their parameters parmin,parmax .
695
696 TopoDS_Vertex Vmin,Vmax;Standard_Real parmin,parmax;
697 GetOrientedEdgeVertices(E,Vmin,Vmax,parmin,parmax);
698
699#ifdef DEB
700 if (tBUTO) cout<<"Recompute1 min,max = "<<parmin<<","<<parmax<<endl;
701 if (tBUTO) DUMPCURVES(C3D,C);
702#endif
703
704 Handle(Geom_Curve) C3Dnew;
705 Handle(Geom2d_Curve) PC1new;
706 Handle(Geom2d_Curve) PC2new;
707 Standard_Real tolreached3d,tolreached2d;
708
709 Standard_Boolean approxMade = myCurveTool.MakeCurves(parmin,parmax,
710 C3D,PC1,PC2,F1,F2,
711 C3Dnew,PC1new,PC2new,
712 tolreached3d,tolreached2d);
713
714 Standard_Real newtol,newparmin,newparmax;
715 // MSV Nov 12, 2001: if approx failed than leave old curves of degree 1
716 if (!approxMade) {
717#ifdef DEB
718 cout<<"TopOpeBRepDS_BuildTool::ApproxCurves : approx failed, leave curves of degree 1"
719 <<endl;
720#endif
721 newtol = BRep_Tool::Tolerance(E);
722 newparmin = parmin;
723 newparmax = parmax;
724 C3Dnew = C3D;
725 PC1new = PC1;
726 PC2new = PC2;
727 }
728 else {
729 UpdateEdgeCurveTol
730 (F1,F2,E,C3Dnew,tolreached3d,tolreached2d,tolreached2d,
731 newtol,newparmin,newparmax);
732 }
733
734 if (!C3Dnew.IsNull()) {
735 newC.DefineCurve(C3Dnew,newtol,Standard_False);
736 newC.SetRange(newparmin,newparmax);
737 }
738
739 if (!PC1new.IsNull()) newC.Curve1(PC1new);
740 if (!PC2new.IsNull()) newC.Curve2(PC2new);
741}
742
743
744//=======================================================================
745//function : ComputePCurves
746//purpose :
747//=======================================================================
748Standard_Boolean FUN_getUV
749(const Handle(Geom_Surface) surf,
750 const Handle(Geom_Curve) C3D,
751 const Standard_Real par3d,
752 Standard_Real& u0,
753 Standard_Real& v0)
754{
755 gp_Pnt P3d; C3D->D0(par3d,P3d);
756 GeomAPI_ProjectPointOnSurf pons(P3d,surf);
757 if (pons.NbPoints() < 1) return Standard_False;
758 pons.LowerDistanceParameters(u0,v0);
759 return Standard_True;
760}
761
762Standard_Boolean FUN_reversePC
763(Handle(Geom2d_Curve) PCnew,
764 const TopoDS_Face& F,
765 const gp_Pnt& P3DC3D,
766 const Standard_Real par2d,
767 const Standard_Real tol)
768{
769 gp_Pnt2d P2D; PCnew->D0(par2d,P2D);
770 BRepAdaptor_Surface BAS(F,Standard_False);
771 gp_Pnt P3D = BAS.Value(P2D.X(),P2D.Y());
772 Standard_Boolean PCreversed = Standard_False;
773 Standard_Boolean sam = P3D.IsEqual(P3DC3D,tol);
774 PCreversed = !sam;
775
776#ifdef DEB
777#ifdef DRAW
778 Standard_Boolean tBUTO = TopOpeBRepDS_GettraceBUTO();
779 if (tBUTO) {FUN_draw(P3DC3D); FUN_draw(P3D);}
780#endif
781#endif
782
783 if ( PCreversed ) {
784 Handle(Geom2d_Curve) PC = ::BASISCURVE2D(PCnew);
785 if (!PC.IsNull()) {
786 Handle(Geom2d_Line) L = Handle(Geom2d_Line)::DownCast(PC);
787 gp_Dir2d d = L->Direction();
788 d.Reverse();
789 L->SetDirection(d);
790 }
791 }
792 return PCreversed;
793}
794Standard_Boolean FUN_makeUisoLineOnSphe
795(const TopoDS_Face& F, // with geometry the spherical surface
796 const Handle(Geom_Curve) C3D,
797 Handle(Geom2d_Curve) PCnew,
798 const Standard_Real tol3d)
799{
800 // p3df,p3dl : C3d first and last parameters
801 Standard_Real p3df = C3D->FirstParameter();
802 Standard_Real p3dl = C3D->LastParameter();
803
804 // u0,v0 : C3d(par3d) UV parameters
805 Standard_Real deltainf = 0.243234, deltasup = 0.543345;
806 Standard_Real par3dinf = (1-deltainf)*p3df + deltainf*p3dl;
807 Standard_Real par3dsup = (1-deltasup)*p3df + deltasup*p3dl;
808 Standard_Real uinf,vinf,usup,vsup;
809 Handle(Geom_Surface) surf = BRep_Tool::Surface(F);
810 if (!FUN_getUV(surf,C3D,par3dinf,uinf,vinf)) return Standard_False;
811 if (!FUN_getUV(surf,C3D,par3dsup,usup,vsup)) return Standard_False;
812 Standard_Real tol = Precision::Parametric(tol3d);
813 if (Abs(uinf-usup) > tol) return Standard_False;
814#ifdef DEB
815// Standard_Real deltav = vsup-vinf;
816#endif
817
818 Standard_Boolean isvgrowing = (vsup - vinf > -tol);
819 gp_Dir2d vdir;
820 if (isvgrowing) vdir = gp_Dir2d(0,1);
821 else vdir = gp_Dir2d(0,-1);
822
823 gp_Pnt2d origin(uinf,vinf);
824 origin.Translate(gp_Vec2d(vdir).Scaled(p3df-par3dinf));
825 Handle(Geom2d_Curve) PC = ::BASISCURVE2D(PCnew);
826 if (!PC.IsNull()) {
827 Handle(Geom2d_Line) L = Handle(Geom2d_Line)::DownCast(PC);
828 L->SetLin2d(gp_Lin2d(origin,vdir));
829#ifdef DEB
830#ifdef DRAW
831 Standard_Boolean trc = TopOpeBRepDS_GettraceBUTO();
832 if (trc) {
833 FUN_draw(gp_Pnt2d(uinf,vinf));
834 FUN_draw(gp_Pnt2d(usup,vsup));
835 FUN_draw(L,p3dl-p3df);
836 }
837#endif
838#endif
839 } // (!PC.IsNull())
840
841 return Standard_True;
842}
843
844void TopOpeBRepDS_BuildTool::ComputePCurves
845(const TopOpeBRepDS_Curve& C,
846 TopoDS_Edge& E,
847 TopOpeBRepDS_Curve& newC,
848 const Standard_Boolean comppc1,
849 const Standard_Boolean comppc2,
850 const Standard_Boolean compc3d) const
851{
852#ifdef DEB
853// Standard_Boolean tDSNC = TopOpeBRepDS_GettraceDSNC();
854 Standard_Boolean tBUTO = TopOpeBRepDS_GettraceBUTO();
855 Standard_Boolean tTRPE = TopOpeBRepDS_GettraceTRPE();
856#endif
857
858 const TopoDS_Face& F1 = TopoDS::Face(newC.Shape1());
859 const TopoDS_Face& F2 = TopoDS::Face(newC.Shape2());
860
861 const Handle(Geom_Curve)& C3D = C.Curve();
862#ifdef DEB
863// const Handle(Geom2d_Curve)& PC1 = C.Curve1();
864// const Handle(Geom2d_Curve)& PC2 = C.Curve2();
865#endif
866
867 // get bounding vertices Vmin,Vmax supported by the new edge <E>
868 // and their corresponding parameters parmin,parmax .
869
870 TopoDS_Vertex Vmin,Vmax;Standard_Real parmin,parmax;
871 GetOrientedEdgeVertices(E,Vmin,Vmax,parmin,parmax);
872
873#ifdef DEB
874 if (tBUTO) cout<<"Recompute2 min,max = "<<parmin<<","<<parmax<<endl;
875 if (tBUTO) DUMPCURVES(C3D,C);
876#endif
877
878 Handle(Geom2d_Curve) PC1new;
879 Handle(Geom2d_Curve) PC2new;
880
881 if(C3D.IsNull()) {
1d47d8d0 882 Standard_Real tolreached2d1 = Precision::Confusion(), tolreached2d2 = Precision::Confusion(), r1, r2, tol=Precision::Confusion();
7fd59977 883 if (comppc1) PC1new = myCurveTool.MakePCurveOnFace(F1,C3D,tolreached2d1);
884 if (comppc2) PC2new = myCurveTool.MakePCurveOnFace(F2,C3D,tolreached2d2);
885
886 r1 = TopOpeBRepTool_ShapeTool::Resolution3d(F1,tolreached2d1);
887 r2 = TopOpeBRepTool_ShapeTool::Resolution3d(F2,tolreached2d2);
888 tol = Max(tol,r1);
889 tol = Max(tol,r2);
890 newC.Tolerance(tol);
891
892 if (!PC1new.IsNull()) newC.Curve1(PC1new);
893 if (!PC2new.IsNull()) newC.Curve2(PC2new);
894
895 return;
896 }
897
898 Handle(Geom_Curve) C3Dnew = C3D;
899
900 if ( C3D->IsPeriodic() ) {
901 // ellipse on cone : periodize parmin,parmax
902 Standard_Real period = C3D->LastParameter() - C3D->FirstParameter();
903 Standard_Real f,l;
904 if (Vmin.Orientation() == TopAbs_FORWARD) { f = parmin; l = parmax; }
905 else { f = parmax; l = parmin; }
906 parmin = f; parmax = l;
907 ElCLib::AdjustPeriodic(f,f+period,Precision::PConfusion(),parmin,parmax);
908 if (compc3d) C3Dnew = new Geom_TrimmedCurve(C3D,parmin,parmax);
909
910#ifdef DEB
911 if (tBUTO||tTRPE) cout<<"Recompute2 : parmin,parmax "<<f<<","<<l<<endl;
912 if (tBUTO||tTRPE) cout<<" --> parmin,parmax "<<parmin<<","<<parmax<<endl;
913#endif
914 }
915
916 Standard_Real tolreached3d = C.Tolerance();
917 Standard_Real tolreached2d1 = C.Tolerance();
918 Standard_Real tolreached2d2 = C.Tolerance();
919
920 if (comppc1) PC1new = myCurveTool.MakePCurveOnFace(F1,C3Dnew,tolreached2d1);
921 if (comppc2) PC2new = myCurveTool.MakePCurveOnFace(F2,C3Dnew,tolreached2d2);
922
923 Standard_Real newtol,newparmin,newparmax;
924 UpdateEdgeCurveTol(F1,F2,E,C3Dnew,tolreached3d,tolreached2d1,tolreached2d2,
925 newtol,newparmin,newparmax);
926
927 // xpu : suite merge : 07-07-97
928 // xpu : 17-06-97
929 // Rmq : C1.Curve<i>() ne sert plus qu'a determiner si la courbe
930 // est une isos de la sphere
931 // NYI : enlever FUN_reversePC
932 Standard_Boolean UisoLineOnSphe1 = Standard_False;
933 UisoLineOnSphe1 = ::FUN_UisoLineOnSphe(F1,PC1new);
934 if (UisoLineOnSphe1) ::FUN_makeUisoLineOnSphe(F1,C3Dnew,PC1new,newtol);
935
936 Standard_Boolean UisoLineOnSphe2 = Standard_False;
937 UisoLineOnSphe2 = ::FUN_UisoLineOnSphe(F2,PC2new);
938 if (UisoLineOnSphe2) ::FUN_makeUisoLineOnSphe(F2,C3Dnew,PC2new,newtol);
939 // xpu : 17-06-97
940 // xpu : suite merge : 07-07-97
941
942 if (!C3Dnew.IsNull()) {
943 newC.Curve(C3Dnew,newtol);
944 newC.SetRange(newparmin, newparmax);
945 }
946 if (!PC1new.IsNull()) newC.Curve1(PC1new);
947 if (!PC2new.IsNull()) newC.Curve2(PC2new);
948
949#ifdef DEB
950 if (tBUTO) DUMPCURVES(C3Dnew,newC);
951#endif
952}
953
954//=======================================================================
955//function : PutPCurves
956//purpose :
957//=======================================================================
958
959void TopOpeBRepDS_BuildTool::PutPCurves
960(const TopOpeBRepDS_Curve& newC,
961 TopoDS_Edge& E,
962 const Standard_Boolean comppc1,
963 const Standard_Boolean comppc2) const
964{
965
966 TopoDS_Face& F1 = *((TopoDS_Face*)(void*)&(TopoDS::Face(newC.Shape1())));
967 Handle(Geom2d_Curve) PC1 = newC.Curve1();
968 if (!PC1.IsNull() && comppc1) {
969 PCurve(F1,E,PC1);
970 }
971
972 TopoDS_Face& F2 = *((TopoDS_Face*)(void*)&(TopoDS::Face(newC.Shape2())));
973 Handle(Geom2d_Curve) PC2 = newC.Curve2();
974 if (!PC2.IsNull() && comppc2) {
975 PCurve(F2,E,PC2);
976 }
977
978}
979
980//=======================================================================
981//function : RecomputeCurves
982//purpose :
983//=======================================================================
984
985void TopOpeBRepDS_BuildTool::RecomputeCurves
986(const TopOpeBRepDS_Curve& C,
987// const TopoDS_Edge& oldE,
988 const TopoDS_Edge& ,
989 TopoDS_Edge& E,
990 Standard_Integer& inewC,
991 const Handle(TopOpeBRepDS_HDataStructure)& HDS) const
992{
993 const TopOpeBRepTool_GeomTool& GT = myCurveTool.GetGeomTool();
994 const Standard_Boolean compc3d = GT.CompC3D();
995 const Standard_Boolean comppc1 = GT.CompPC1();
996 const Standard_Boolean comppc2 = GT.CompPC2();
997 const Standard_Boolean comppc = comppc1 || comppc2;
998 const Standard_Boolean iswalk = C.IsWalk();
999 const Standard_Boolean approx = Approximation();
1000
1001 const Handle(Geom_Curve)& C3D = C.Curve();
1002 if (comppc1 && C.Shape1().IsNull()) Standard_ProgramError::Raise
1003 ("TopOpeBRepDS_BuildTool::RecomputeCurve 2");
1004 if (comppc2 && C.Shape2().IsNull()) Standard_ProgramError::Raise
1005 ("TopOpeBRepDS_BuildTool::RecomputeCurve 3");
1006 TopoDS_Vertex Vmin,Vmax; TopExp::Vertices(E,Vmin,Vmax);
1007 if ( Vmin.IsNull() ) Standard_ProgramError::Raise
1008 ("TopOpeBRepDS_BuildTool::RecomputeCurve 4");
1009 if ( Vmax.IsNull() ) Standard_ProgramError::Raise
1010 ("TopOpeBRepDS_BuildTool::RecomputeCurve 5");
1011
1012 if (iswalk && approx) {
1013 if (compc3d && C3D.IsNull()) Standard_ProgramError::Raise
1014 ("TopOpeBRepDS_BuildTool::RecomputeCurve 1");
1015 ApproxCurves(C, E, inewC, HDS);
1016 TopOpeBRepDS_Curve& newC = HDS->ChangeCurve(inewC);
1017 PutPCurves(newC, E, comppc1, comppc2);
1018 }
1019// else if (iswalk && interpol) {
1020// InterpolCurves(C, E, inewC, comppc1, comppc2, HDS);
1021// TopOpeBRepDS_Curve& newC = HDS->ChangeCurve(inewC);
1022// PutPCurves(newC, E, comppc1, comppc2);
1023// }
1024
1025 else {
1026 if (comppc) {
1027 TopOpeBRepDS_Curve newC1;
1028 inewC = HDS->MakeCurve(C,newC1);
1029 TopOpeBRepDS_Curve& newC = HDS->ChangeCurve(inewC);
1030 if(iswalk && !approx) {
1031 if (compc3d && C3D.IsNull()) Standard_ProgramError::Raise
1032 ("TopOpeBRepDS_BuildTool::RecomputeCurve 1");
1033 newC.Curve1(C.Curve1());
1034 newC.Curve2(C.Curve2());
1035 }
1036 else
1037 ComputePCurves(C, E, newC, comppc1, comppc2, compc3d);
1038 PutPCurves(newC, E, comppc1, comppc2);
1039 }
1040 }
1041}
1042
1043//=======================================================================
1044//function : CopyFace
1045//purpose :
1046//=======================================================================
1047
1048void TopOpeBRepDS_BuildTool::CopyFace(const TopoDS_Shape& Fin,
1049 TopoDS_Shape& Fou)const
1050{
1051 Fou = Fin.EmptyCopied();
1052}
1053
1054
1055//=======================================================================
1056//function : AddEdgeVertex
1057//purpose :
1058//=======================================================================
1059
1060void TopOpeBRepDS_BuildTool::AddEdgeVertex(const TopoDS_Shape& Ein,
1061 TopoDS_Shape& Eou,
1062 const TopoDS_Shape& V)const
1063{
1064 myBuilder.Add(Eou,V);
1065 TopoDS_Edge e1 = TopoDS::Edge(Ein);
1066 TopoDS_Edge e2 = TopoDS::Edge(Eou);
1067 TopoDS_Vertex v1 = TopoDS::Vertex(V);
1068 myBuilder.Transfert(e1,e2,v1,v1);
1069}
1070
1071
1072//=======================================================================
1073//function : AddEdgeVertex
1074//purpose :
1075//=======================================================================
1076
1077void TopOpeBRepDS_BuildTool::AddEdgeVertex(TopoDS_Shape& E,
1078 const TopoDS_Shape& V)const
1079{
1080 myBuilder.Add(E,V);
1081}
1082
1083
1084//=======================================================================
1085//function : AddWireEdge
1086//purpose :
1087//=======================================================================
1088
1089void TopOpeBRepDS_BuildTool::AddWireEdge(TopoDS_Shape& W,
1090 const TopoDS_Shape& E)const
1091{
1092 myBuilder.Add(W,E);
1093}
1094
1095
1096//=======================================================================
1097//function : AddFaceWire
1098//purpose :
1099//=======================================================================
1100
1101void TopOpeBRepDS_BuildTool::AddFaceWire(TopoDS_Shape& F,
1102 const TopoDS_Shape& W)const
1103{
1104 myBuilder.Add(F,W);
1105}
1106
1107
1108//=======================================================================
1109//function : AddShellFace
1110//purpose :
1111//=======================================================================
1112
1113void TopOpeBRepDS_BuildTool::AddShellFace(TopoDS_Shape& Sh,
1114 const TopoDS_Shape& F)const
1115{
1116 myBuilder.Add(Sh,F);
1117}
1118
1119
1120//=======================================================================
1121//function : AddSolidShell
1122//purpose :
1123//=======================================================================
1124
1125void TopOpeBRepDS_BuildTool::AddSolidShell(TopoDS_Shape& S,
1126 const TopoDS_Shape& Sh)const
1127{
1128 myBuilder.Add(S,Sh);
1129}
1130
1131
1132//=======================================================================
1133//function : Parameter
1134//purpose :
1135//=======================================================================
1136
1137void TopOpeBRepDS_BuildTool::Parameter(const TopoDS_Shape& E,
1138 const TopoDS_Shape& V,
1139 const Standard_Real P)const
1140{
1141 const TopoDS_Edge& e = TopoDS::Edge(E);
1142 const TopoDS_Vertex& v = TopoDS::Vertex(V);
1143 Standard_Real p = P;
1144
1145 // 13/07/95 :
1146 TopLoc_Location loc; Standard_Real f,l;
1147 Handle(Geom_Curve) C = BRep_Tool::Curve(e,loc,f,l);
1148 if ( !C.IsNull() && C->IsPeriodic()) {
1149 Standard_Real per = C->Period();
1d47d8d0 1150
7fd59977 1151 TopAbs_Orientation oV=TopAbs_FORWARD;
1d47d8d0 1152
7fd59977 1153 TopExp_Explorer exV(e,TopAbs_VERTEX);
1154 for (; exV.More(); exV.Next()) {
1155 const TopoDS_Vertex& vofe = TopoDS::Vertex(exV.Current());
1156 if ( vofe.IsSame(v) ) {
1157 oV = vofe.Orientation();
1158 break;
1159 }
1160 }
1161 if ( exV.More() ) {
1162 if ( oV == TopAbs_REVERSED ) {
1163 if ( p < f ) {
1164 Standard_Real pp = ElCLib::InPeriod(p,f,f+per);
1165#ifdef DEB
1166 if (TopOpeBRepDS_GettraceBUTO() ) {
1167 cout<<"BuildTool Parameter : "<<p<<" --> "<<pp<<endl;
1168 }
1169#endif
1170 p = pp;
1171 }
1172 }
1173 }
1174 }
1175
1176 myBuilder.UpdateVertex(v,p,e,
1177 0); // NYI : Tol on new vertex ??
1178}
1179
1180//=======================================================================
1181//function : Range
1182//purpose :
1183//=======================================================================
1184
1185void TopOpeBRepDS_BuildTool::Range(const TopoDS_Shape& E,
1186 const Standard_Real first,
1187 const Standard_Real last)const
1188{
1189 myBuilder.Range(TopoDS::Edge(E),first,last);
1190}
1191
1192
1193//=======================================================================
1194//function : UpdateEdge
1195//purpose :
1196//=======================================================================
1197
1198void TopOpeBRepDS_BuildTool::UpdateEdge(const TopoDS_Shape& Ein,
1199 TopoDS_Shape& Eou)const
1200{
1201 TopLoc_Location loc;
1202 Standard_Real f1,l1;
1203 Standard_Real f2,l2;
1204 Handle(Geom_Curve) Cin = BRep_Tool::Curve(TopoDS::Edge(Ein),loc,f1,l1);
1205 Handle(Geom_Curve) Cou = BRep_Tool::Curve(TopoDS::Edge(Eou),loc,f2,l2);
1206 if (Cin.IsNull() || Cou.IsNull()) return;
1207
1208 if ( Cou->IsPeriodic() ) {
1209 Standard_Real f2n = f2, l2n = l2;
1210 if ( l2n <= f2n ) {
1211 ElCLib::AdjustPeriodic(f1,l1,Precision::PConfusion(),f2n,l2n);
1212 Range(Eou,f2n,l2n);
1213#ifdef DEB
1214 if (TopOpeBRepDS_GettraceBUTO() || TopOpeBRepDS_GettraceTRPE()) {
1215 cout<<endl;
1216 cout<<"UpdateEdge f1,l1 "<<f1<<" "<<l1<<endl;
1217 cout<<"UpdateEdge f2,l2 "<<f2<<" "<<l2<<" "<<endl;
1218 cout<<"UpdateEdge f2n,l2n "<<f2n<<" "<<l2n<<endl;
1219 TopExp_Explorer ex;
1220 for (ex.Init(Eou,TopAbs_VERTEX); ex.More(); ex.Next()) {
1221 TopoDS_Vertex v = TopoDS::Vertex(ex.Current());
1222 Standard_Real par = BRep_Tool::Parameter(v,TopoDS::Edge(Eou));
1223 TopAbs_Orientation o = v.Orientation();
1224 cout<<"BuildTool vertex ";TopAbs::Print(o,cout); cout<<" "<<par<<endl;
1225 }
1226 }
1227#endif
1228 }
1229 }
1230}
1231
1232//=======================================================================
1233//function : Project
1234//purpose : project a vertex on a curve
1235//=======================================================================
1236
1237static Standard_Boolean Project(const Handle(Geom_Curve)& C,
1238 const TopoDS_Vertex& V,
1239 Standard_Real& p)
1240{
1241 gp_Pnt P = BRep_Tool::Pnt(V);
1242 Standard_Real tol = BRep_Tool::Tolerance(V);
1243 GeomAdaptor_Curve GAC(C);
1244 Extrema_ExtPC extrema(P,GAC);
1245 if (extrema.IsDone()) {
1246 Standard_Integer i,n = extrema.NbExt();
1247 for (i = 1; i <= n; i++) {
1248 if (extrema.IsMin(i)) {
1249 Extrema_POnCurv EPOC = extrema.Point(i);
1250 if (P.Distance(EPOC.Value()) <= tol) {
1251 p = EPOC.Parameter();
1252 return Standard_True;
1253 }
1254 }
1255 }
1256 }
1257 return Standard_False;
1258}
1259
1260
1261//=======================================================================
1262//function : Parameter
1263//purpose :
1264//=======================================================================
1265
1266void TopOpeBRepDS_BuildTool::Parameter(const TopOpeBRepDS_Curve& C,
1267 TopoDS_Shape& E,
1268 TopoDS_Shape& V)const
1269{
1270 Standard_Real newparam;
1271 Project(C.Curve(),TopoDS::Vertex(V),newparam);
1272 Parameter(E,V,newparam);
1273}
1274
1275
1276//=======================================================================
1277//function : Curve3D
1278//purpose :
1279//=======================================================================
1280
1281void TopOpeBRepDS_BuildTool::Curve3D
1282(TopoDS_Shape& E,
1283 const Handle(Geom_Curve)& C,
1284 const Standard_Real Tol)const
1285{
1286 myBuilder.UpdateEdge(TopoDS::Edge(E),
1287 C,
1288 Tol);
1289}
1290
1291
1292//=======================================================================
1293//function : TranslateOnPeriodic
1294//purpose :
1295//=======================================================================
1296
1297void TopOpeBRepDS_BuildTool::TranslateOnPeriodic
1298 (TopoDS_Shape& F,
1299 TopoDS_Shape& E,
1300 Handle(Geom2d_Curve)& PC) const
1301{
1302 // get range C3Df,C3Dl of 3d curve C3D of E
1303 TopLoc_Location L;
1304 Standard_Real C3Df,C3Dl;
1305// Handle(Geom_Curve) C3D = BRep_Tool::Curve(TopoDS::Edge(E),L,C3Df,C3Dl);
1306 Handle(Geom_Curve) C3D = BRep_Tool::Curve(TopoDS::Edge(E),C3Df,C3Dl); // 13-07-97: xpu
1307
1308 Standard_Real first = C3Df, last = C3Dl;
1309 if (C3D->IsPeriodic()) {
1310 if ( last < first ) last += Abs(first - last);
1311 }
1312
1313 // jyl-xpu : 13-06-97 :
1314 // if <PC> is U isoline on sphere, a special parametrization
1315 // is to provide, we compute <PC> (which is a line) bounds
1316 // with C3D bounds.
1317 Standard_Boolean UisoLineOnSphe = FUN_UisoLineOnSphe(F,PC);
1318 Standard_Boolean newv = Standard_True;
1319
1320 Standard_Real du,dv;
1321
1322 gp_Pnt2d ptest;
1323 Standard_Real t =(first+last)*.5;
1324 PC->D0(t,ptest);
1325 Standard_Real u1 = ptest.X(), u2 = u1;
1326 Standard_Real v1 = ptest.Y(), v2 = v1;
1327
1328 if (newv) {
1329 if (UisoLineOnSphe) {
1330 Handle(Geom_Curve) c3d = BRep_Tool::Curve(TopoDS::Edge(E),C3Df,C3Dl);
1331 GeomAdaptor_Curve GC(c3d); gp_Pnt p3dtest = GC.Value(t);
1332 Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(F));
1333 GeomAPI_ProjectPointOnSurf pons(p3dtest,surf);
1334 if (!(pons.NbPoints() < 1))
1335 pons.LowerDistanceParameters(u2,v2);
1336 } else TopOpeBRepTool_ShapeTool::AdjustOnPeriodic(F,u2,v2);
1337 }
1338 if (!newv) TopOpeBRepTool_ShapeTool::AdjustOnPeriodic(F,u2,v2);
1339 du = u2 - u1, dv = v2 - v1;
1340
1341 if ( du != 0. || dv != 0.) {
1342#ifdef DEB
1343 if (TopOpeBRepDS_GettraceBUTO() || TopOpeBRepDS_GettraceTRPE()) {
1344 cout<<endl;
1345 cout<<"TranslateOnPeriodic : Curve range "<<C3Df<<" "<<C3Dl<<endl;
1346 Standard_Real PCf,PCl;
1347 BRep_Tool::Range(TopoDS::Edge(E),TopoDS::Face(F),PCf,PCl);
1348 cout<<"TranslateOnPeriodic : PCurve range "<<PCf<<" "<<PCl<<endl;
1349 cout<<"TranslateOnPeriodic : translation "<<du<<" "<<dv<<endl;
1350 }
1351#endif
1352 // translate curve PC of du,dv
1353 Handle(Geom2d_Curve) PCT = Handle(Geom2d_Curve)::DownCast(PC->Copy());
1354 PCT->Translate(gp_Vec2d(du,dv));
1355 PC = PCT;
1356 }
1357}
1358
1359
1360// RLE - IAB 16 june 94
1361// should be provided by the BRep_Builder
1362
1363Standard_EXPORT void TopOpeBRepDS_SetThePCurve(const BRep_Builder& B,
1364 TopoDS_Edge& E,
1365 const TopoDS_Face& F,
1366 const TopAbs_Orientation O,
1367 const Handle(Geom2d_Curve)& C)
1368{
1369 // check if there is already a pcurve on non planar faces
1370 Standard_Real f,l;
1371 Handle(Geom2d_Curve) OC;
1372 TopLoc_Location SL;
1373 Handle(Geom_Plane) GP = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(F,SL));
1374 if (GP.IsNull())
1375 OC = BRep_Tool::CurveOnSurface(E,F,f,l);
1376
1377 if (OC.IsNull())
1378 B.UpdateEdge(E,C,F,Precision::Confusion());
1379 else {
1380 Standard_Boolean degen = BRep_Tool::Degenerated(E);
1381 if(!degen){
1382 if (O == TopAbs_REVERSED)
1383 B.UpdateEdge(E,OC,C,F,Precision::Confusion());
1384 else
1385 B.UpdateEdge(E,C,OC,F,Precision::Confusion());
1386 }
1387 }
1388}
1389
1390#ifdef DEB
1391//------------------------------------------------------------------------
1392static void DUMPPCURVE(const TopoDS_Edge& EE,
1393 const TopoDS_Face& FF,
1394 const Handle(Geom2d_Curve)& PC)
1395//------------------------------------------------------------------------
1396{
1397 TopLoc_Location L; Standard_Real Cf,Cl;
1398 Handle(Geom_Curve) C = BRep_Tool::Curve(EE,L,Cf,Cl);
1399 if (C->IsPeriodic()) {
1400 cout<<endl;
1401 cout<<"DUMPPCURVE : ";cout<<" face "; ::PrintSurface(FF,cout); cout<<endl;
1402 cout<<"PCurve type : ";TopOpeBRepDS_Dumper::PrintType(PC,cout); cout<<endl;
1403 gp_Pnt oC;
1404 if (::GetOrigin(C,oC))
1405 cout<<"(E)Curve origin : "<<oC.X()<<" "<<oC.Y()<<" "<<oC.Z()<<endl;
1406 cout<<"(E)Curve range : Cf,Cl = "<<Cf<<" "<<Cl<<endl;
1407
1408 Standard_Real PCf,PCl;
1409 PCf = PC->FirstParameter(); PCl = PC->LastParameter();
1410 gp_Pnt2d oPC;
1411 if (::GetOrigin(PC,oPC))
1412 cout<<"(PC)PCurve origin : "<<oPC.X()<<" "<<oPC.Y()<<endl;
1413 cout<<"(PC)PCurve range : PCf,PCl = "<<PCf<<" "<<PCl<<endl;
1414 }
1415}
1416#endif
1417
1418//=======================================================================
1419//function : PCurve
1420//purpose :
1421//=======================================================================
1422
1423void TopOpeBRepDS_BuildTool::PCurve(TopoDS_Shape& F,
1424 TopoDS_Shape& E,
1425 const Handle(Geom2d_Curve)& PC)const
1426{
1427 if ( ! PC.IsNull() ) {
1428 TopoDS_Face FF = TopoDS::Face(F);
1429 TopoDS_Edge EE = TopoDS::Edge(E);
1430 Handle(Geom2d_Curve) PCT = PC;
1431
1432#ifdef DEB
1433#ifdef DRAW
1434 Standard_Boolean trc = Standard_False;
1435 if (trc) FUN_draw(FF);
1436 if (trc) FUN_draw(EE);
1437 if (trc) FUN_draw(PC,0.);
1438#endif
1439 if (TopOpeBRepDS_GettraceTRPE()) DUMPPCURVE(EE,FF,PCT);
1440#endif
1441
1442 // pour iab, ajout de Translate
1443 Standard_Boolean tran = myTranslate;
1444#ifdef DEB
1445 if ( TopOpeBRepDS_GettraceSANTRAN()) {
1446 tran = Standard_False;
1447 cout<<"SANS translation de pcurve"<<endl;
1448 }
1449#endif
1450
1451 // xpu : 13-06-97 :
1452 // recompute twice the pcurve boundaries if OverWrite
1453 // if the pcurve <PC> is U isoline on sphere -> to avoid.
1454 Standard_Boolean UisoLineOnSphe = FUN_UisoLineOnSphe(F,PC);
1455 Standard_Boolean overwrite = UisoLineOnSphe? Standard_False:myOverWrite;
1456 // xpu : 13-06-97
1457
1458 if (tran)
1459 TranslateOnPeriodic(F,E,PCT);
1460
1461 if (overwrite)
1462 myBuilder.UpdateEdge(EE,PCT,FF,0);
1463 else
1464 TopOpeBRepDS_SetThePCurve(myBuilder,EE,FF,E.Orientation(),PCT);
1465
1466 // parametrage sur la nouvelle courbe 2d
1467 TopExp_Explorer exi(E,TopAbs_VERTEX);
1468 for (;exi.More(); exi.Next() ) {
1469 const TopoDS_Vertex& vi = TopoDS::Vertex(exi.Current());
1470 if ( vi.Orientation() != TopAbs_INTERNAL ) continue;
1471 Standard_Real tolvi = TopOpeBRepTool_ShapeTool::Tolerance(vi);
1472 // NYI tester l'existence d'au moins
1473 // NYI un parametrage de vi sur EE (en 3d ou en 2d)
1474 // NYI --> a faire dans BRep_Tool
1475 Standard_Real newpar = BRep_Tool::Parameter(vi,EE);
1476 myBuilder.UpdateVertex(vi,newpar,EE,FF,tolvi);
1477 } // INTERNAL vertex
1478
1479#ifdef DEB
1480 if (TopOpeBRepDS_GettraceTRPE()) DUMPPCURVE(EE,FF,PCT);
1481#endif
1482 }
1483}
1484
1485//=======================================================================
1486//function : PCurve
1487//purpose :
1488//=======================================================================
1489
1490void TopOpeBRepDS_BuildTool::PCurve(TopoDS_Shape& F,
1491 TopoDS_Shape& E,
1492 const TopOpeBRepDS_Curve& CDS,
1493 const Handle(Geom2d_Curve)& PC)const
1494{
1495 if ( ! PC.IsNull() ) {
1496 TopoDS_Face FF = TopoDS::Face(F);
1497 TopoDS_Edge EE = TopoDS::Edge(E);
1498
1499 Handle(Geom2d_Curve) PCT = PC;
1500 Standard_Real CDSmin,CDSmax;
1501 Standard_Boolean rangedef = CDS.Range(CDSmin,CDSmax);
1502
1503
1504 TopLoc_Location L; Standard_Real Cf,Cl;
1505 Handle(Geom_Curve) C = BRep_Tool::Curve(EE,L,Cf,Cl);
1506
1507#ifdef DEB
1508 if (TopOpeBRepDS_GettraceTRPE()) DUMPPCURVE(EE,FF,PCT);
1509#endif
1510
1511 if (!C.IsNull()){
1512 Standard_Boolean deca = (Abs(Cf - CDSmin) > Precision::PConfusion());
1513 Handle(Geom2d_Line) line2d = Handle(Geom2d_Line)::DownCast(PCT);
1514 Standard_Boolean isline2d = !line2d.IsNull();
1515 Standard_Boolean tran=(rangedef && deca && C->IsPeriodic() && isline2d);
1516 if (tran) {
1517 TopLoc_Location Loc;
1518 const Handle(Geom_Surface) Surf = BRep_Tool::Surface(FF,Loc);
1519 Standard_Boolean isUperio = Surf->IsUPeriodic();
1520 Standard_Boolean isVperio = Surf->IsVPeriodic();
1521 gp_Dir2d dir2d = line2d->Direction();
1522 Standard_Real delta;
1523 if (isUperio && dir2d.IsParallel(gp::DX2d(),Precision::Angular())) {
1524 delta = (CDSmin - Cf) * dir2d.X();
1525 PCT->Translate(gp_Vec2d(delta,0.));
1526 }
1527 else if(isVperio && dir2d.IsParallel(gp::DY2d(),Precision::Angular())){
1528 delta = (CDSmin - Cf) * dir2d.Y();
1529 PCT->Translate(gp_Vec2d(0.,delta));
1530 }
1531 }
1532 }
1533
1534 TopOpeBRepDS_SetThePCurve(myBuilder,EE,FF,E.Orientation(),PCT);
1535
1536#ifdef DEB
1537 if (TopOpeBRepDS_GettraceTRPE()) DUMPPCURVE(EE,FF,PCT);
1538#endif
1539 }
1540}
1541
1542
1543//=======================================================================
1544//function : Orientation
1545//purpose :
1546//=======================================================================
1547
1548void TopOpeBRepDS_BuildTool::Orientation(TopoDS_Shape& S,
1549 const TopAbs_Orientation O)const
1550{
1551 S.Orientation(O);
1552}
1553
1554
1555//=======================================================================
1556//function : Orientation
1557//purpose :
1558//=======================================================================
1559
1560TopAbs_Orientation TopOpeBRepDS_BuildTool::Orientation
1561 (const TopoDS_Shape& S) const
1562{
1563 return S.Orientation();
1564}
1565
1566//=======================================================================
1567//function : Closed
1568//purpose :
1569//=======================================================================
1570
1571void TopOpeBRepDS_BuildTool::Closed(TopoDS_Shape& S,
1572 const Standard_Boolean B)const
1573{
1574 S.Closed(B);
1575}
1576
1577
1578//=======================================================================
1579//function : Approximation
1580//purpose :
1581//=======================================================================
1582
1583Standard_Boolean TopOpeBRepDS_BuildTool::Approximation() const
1584{
1585 return myCurveTool.GetGeomTool().TypeC3D() != TopOpeBRepTool_BSPLINE1;
1586}
1587
1588void TopOpeBRepDS_BuildTool::UpdateSurface(const TopoDS_Shape& F,const Handle(Geom_Surface)& SU) const
1589{
1590 BRep_Builder BB;
1591 TopLoc_Location L;
1592 Standard_Real tol = BRep_Tool::Tolerance(TopoDS::Face(F));
1593 BB.UpdateFace(TopoDS::Face(F),SU,L,tol);
1594}
1595
1596void TopOpeBRepDS_BuildTool::UpdateSurface(const TopoDS_Shape& E,const TopoDS_Shape& oldF,
1597 const TopoDS_Shape& newF) const
1598{
1599 BRep_Builder BB;
1600 Standard_Real f,l;
1601 const Handle(Geom2d_Curve)& PC = BRep_Tool::CurveOnSurface(TopoDS::Edge(E),TopoDS::Face(oldF),f,l);
1602 Standard_Real tol = BRep_Tool::Tolerance(TopoDS::Face(oldF));
1603 BB.UpdateEdge(TopoDS::Edge(E),PC,TopoDS::Face(newF),tol);
1604}
1605
1606
1607/* // - merge 04-07-97
1608//=======================================================================
1609//function : RecomputeCurve
1610//purpose :
1611//=======================================================================
1612
1613void TopOpeBRepDS_BuildTool::RecomputeCurve
1614(const TopOpeBRepDS_Curve& C1,
1615 TopoDS_Shape& E,
1616 TopOpeBRepDS_Curve& C2 ) const
1617{
1618 // - C1 curves have been approximated by BSplines of degree 1 :
1619 // or
1620 // - C1.Curve() is non projectable on at least one of the original
1621 // intersecting faces.
1622
1623 const TopOpeBRepTool_GeomTool& GT = myCurveTool.GetGeomTool();
1624 Standard_Boolean compc3d = GT.CompC3D();
1625 Standard_Boolean comppc1 = GT.CompPC1();
1626 Standard_Boolean comppc2 = GT.CompPC2();
1627
1628 const Handle(Geom_Curve)& C3D = C1.Curve();
1629 if (compc3d && C3D.IsNull()) Standard_ProgramError::Raise
1630 ("TopOpeBRepDS_BuildTool::RecomputeCurve 1");
1631 if (comppc1 && C2.Shape1().IsNull()) Standard_ProgramError::Raise
1632 ("TopOpeBRepDS_BuildTool::RecomputeCurve 2");
1633 if (comppc2 && C2.Shape2().IsNull()) Standard_ProgramError::Raise
1634 ("TopOpeBRepDS_BuildTool::RecomputeCurve 3");
1635 TopoDS_Vertex Vmin,Vmax; TopExp::Vertices(TopoDS::Edge(E),Vmin,Vmax);
1636 if ( Vmin.IsNull() ) Standard_ProgramError::Raise
1637 ("TopOpeBRepDS_BuildTool::RecomputeCurve 4");
1638 if ( Vmax.IsNull() ) Standard_ProgramError::Raise
1639 ("TopOpeBRepDS_BuildTool::RecomputeCurve 5");
1640
1641 Standard_Boolean kbspl1 = Standard_False;
1642 Handle(Geom_BSplineCurve) BS = Handle(Geom_BSplineCurve)::DownCast(C3D);
1643 if (!BS.IsNull()) kbspl1 = (BS->Degree() == 1);
1644 if (kbspl1) RecomputeBSpline1Curve(C1,E,C2);
1645 else RecomputeCurveOnCone(C1,E,C2);
1646}
1647
1648//=======================================================================
1649//function : RecomputeBSpline1Curve
1650//purpose :
1651//=======================================================================
1652
1653void TopOpeBRepDS_BuildTool::RecomputeBSpline1Curve
1654(const TopOpeBRepDS_Curve& C1,
1655 TopoDS_Shape& EE,
1656 TopOpeBRepDS_Curve& C2) const
1657{
1658#ifdef DEB
1659 Standard_Boolean tDSNC = TopOpeBRepDS_GettraceDSNC();
1660 Standard_Boolean tBUTO = TopOpeBRepDS_GettraceBUTO();
1661#endif
1662
1663 // C1 curves have been approximated by BSplines of degree 1 :
1664 // compute new geometry on curves.
1665
1666 TopoDS_Edge& E = TopoDS::Edge(EE);
1667
1668 const TopOpeBRepTool_GeomTool& GT = myCurveTool.GetGeomTool();
1669 TopOpeBRepTool_OutCurveType typec3d = GT.TypeC3D();
1670 Standard_Boolean compc3d = GT.CompC3D();
1671 Standard_Boolean comppc1 = GT.CompPC1();
1672 Standard_Boolean comppc2 = GT.CompPC2();
1673
1674 const TopoDS_Face& F1 = TopoDS::Face(C2.Shape1());
1675 const TopoDS_Face& F2 = TopoDS::Face(C2.Shape2());
1676
1677 const Handle(Geom_Curve)& C3D = C1.Curve();
1678 const Handle(Geom2d_Curve)& PC1 = C1.Curve1();
1679 const Handle(Geom2d_Curve)& PC2 = C1.Curve2();
1680
1681 // Vmin,Vmax = bounding vertices of edge <E>
1682 // and their parameters parmin,parmax .
1683
1684 TopoDS_Vertex Vmin,Vmax; Standard_Real parmin,parmax;
1685 ::GetOrientedEdgeVertices(E,Vmin,Vmax,parmin,parmax);
1686
1687#ifdef DEB
1688 if (tBUTO) cout<<"Recompute1 min,max = "<<parmin<<","<<parmax<<endl;
1689 if (tBUTO) DUMPCURVES(C3D,C1);
1690#endif
1691
1692 Handle(Geom_Curve) C3Dnew;
1693 Handle(Geom2d_Curve) PC1new;
1694 Handle(Geom2d_Curve) PC2new;
1695 Standard_Real tolreached3d,tolreached2d;
1696
1697 if ( typec3d == TopOpeBRepTool_BSPLINE1 ) {
1698 if ( compc3d ) {
1699 C3Dnew = Handle(Geom_BSplineCurve)::DownCast(C3D->Copy());
1700 (Handle(Geom_BSplineCurve)::DownCast(C3Dnew))->Segment(parmin,parmax);
1701 }
1702 if ( comppc1 && (!PC1.IsNull()) ) {
1703 PC1new = Handle(Geom2d_BSplineCurve)::DownCast(PC1->Copy());
1704 (Handle(Geom2d_BSplineCurve)::DownCast(PC1new))->Segment(parmin,parmax);
1705 }
1706 if ( comppc2 && (!PC2.IsNull()) ) {
1707 PC2new = Handle(Geom2d_BSplineCurve)::DownCast(PC2->Copy());
1708 (Handle(Geom2d_BSplineCurve)::DownCast(PC2new))->Segment(parmin,parmax);
1709 }
1710 }
1711
1712 else if ( typec3d == TopOpeBRepTool_APPROX ) {
1713 if (!comppc1 || !comppc2) Standard_NotImplemented::Raise("DSBuildToolAPPROX");
1714 myCurveTool.MakeCurves(parmin,parmax,
1715 C3D,PC1,PC2,F1,F2,
1716 C3Dnew,PC1new,PC2new,
1717 tolreached3d,tolreached2d);
1718 }
1719
1720 else if ( typec3d == TopOpeBRepTool_INTERPOL ) {
1721 Standard_NotImplemented::Raise("DSBuildToolINTERPOL");
1722 }
1723
1724 Standard_Real newtol,newparmin,newparmax;
1725 ::FUN_updateEDGECURVETOL
1726 (*this,F1,F2,E,C3Dnew,tolreached3d,tolreached2d,tolreached2d,
1727 newtol,newparmin,newparmax);
1728
1729 if (!C3Dnew.IsNull()) {
1730 C2.DefineCurve(C3Dnew,newtol,Standard_False);
1731 C2.SetRange(newparmin,newparmax);
1732 }
1733 if (!PC1new.IsNull()) C2.Curve1(PC1new);
1734 if (!PC2new.IsNull()) C2.Curve2(PC2new);
1735}
1736
1737
1738//=======================================================================
1739//function : RecomputeCurveOnCone
1740//purpose :
1741//=======================================================================
1742
1743void TopOpeBRepDS_BuildTool::RecomputeCurveOnCone
1744 (const TopOpeBRepDS_Curve& C1,
1745 TopoDS_Shape& EE,
1746 TopOpeBRepDS_Curve& C2 ) const
1747{
1748#ifdef DEB
1749 Standard_Boolean tDSNC = TopOpeBRepDS_GettraceDSNC();
1750 Standard_Boolean tBUTO = TopOpeBRepDS_GettraceBUTO();
1751 Standard_Boolean tTRPE = TopOpeBRepDS_GettraceTRPE();
1752#endif
1753
1754 // C1 Pcurves have not been computed because C1 Curve is not projectable
1755 // on one at least of the intersecting faces giving C1 Curve.
1756 // (see TopOpeBRepTool_CurveTool::IsProjectable())
1757
1758 TopoDS_Edge& E = TopoDS::Edge(EE);
1759
1760 const TopOpeBRepTool_GeomTool& GT = myCurveTool.GetGeomTool();
1761 TopOpeBRepTool_OutCurveType typec3d = GT.TypeC3D();
1762 Standard_Boolean compc3d = GT.CompC3D();
1763 Standard_Boolean comppc1 = GT.CompPC1();
1764 Standard_Boolean comppc2 = GT.CompPC2();
1765
1766 const TopoDS_Face& F1 = TopoDS::Face(C2.Shape1());
1767 const TopoDS_Face& F2 = TopoDS::Face(C2.Shape2());
1768
1769 const Handle(Geom_Curve)& C3D = C1.Curve();
1770 const Handle(Geom2d_Curve)& PC1 = C1.Curve1();
1771 const Handle(Geom2d_Curve)& PC2 = C1.Curve2();
1772
1773 // get bounding vertices Vmin,Vmax supported by the new edge <E>
1774 // and their corresponding parameters parmin,parmax .
1775
1776 TopoDS_Vertex Vmin,Vmax; Standard_Real parmin,parmax;
1777 ::GetOrientedEdgeVertices(E,Vmin,Vmax,parmin,parmax);
1778
1779#ifdef DEB
1780 if (tBUTO) {cout<<"Recompute2 min,max = "<<parmin<<","<<parmax<<endl;
1781 DUMPCURVES(C3D,C1);}
1782#endif
1783
1784 if ( C3D->IsPeriodic() ) {
1785 // ellipse on cone : periodize parmin,parmax
1786 Standard_Real period = C3D->LastParameter() - C3D->FirstParameter();
1787 Standard_Real f,l;
1788 if (Vmin.Orientation() == TopAbs_FORWARD) { f = parmin; l = parmax; }
1789 else { f = parmax; l = parmin; }
1790 parmin = f; parmax = l;
1791 ElCLib::AdjustPeriodic(f,f+period,Precision::PConfusion(),parmin,parmax);
1792#ifdef DEB
1793 if (tBUTO||tTRPE) cout<<"Recompute2 : parmin,parmax "<<f<<","<<l<<endl;
1794 if (tBUTO||tTRPE) cout<<" --> parmin,parmax "<<parmin<<","<<parmax<<endl;
1795#endif
1796 }
1797
1798 Handle(Geom_TrimmedCurve) C3Dnew;
1799 Handle(Geom2d_Curve) PC1new;
1800 Handle(Geom2d_Curve) PC2new;
1801 Standard_Real tolreached3d = C1.Tolerance();
1802 Standard_Real tolreached2d1 = C1.Tolerance();
1803 Standard_Real tolreached2d2 = C1.Tolerance();
1804 if (compc3d) C3Dnew = new Geom_TrimmedCurve(C3D,parmin,parmax);
1805 if (comppc1) PC1new = myCurveTool.MakePCurveOnFace(F1,C3Dnew,tolreached2d1);
1806 if (comppc2) PC2new = myCurveTool.MakePCurveOnFace(F2,C3Dnew,tolreached2d2);
1807
1808#ifdef DRAW
1809 if (tBUTO) {FUN_draw(F1); FUN_draw(F2); FUN_draw(E);}
1810#endif
1811
1812 Standard_Real newtol,newparmin,newparmax;
1813 FUN_updateEDGECURVETOL
1814 (*this,F1,F2,E,C3Dnew,tolreached3d,tolreached2d1,tolreached2d2,
1815 newtol,newparmin,newparmax);
1816
1817// jyl : 16-06-97
1818// Standard_Real fac = 0.3798123578771;
1819// Standard_Real tol = newtol;
1820// Standard_Real par3d = (1-fac)*newparmin + (fac)*newparmax;
1821// Standard_Real par2d = par3d - newparmin;
1822//
1823// gp_Pnt P3DC3D; C3D->D0(par3d,P3DC3D);
1824//
1825// Standard_Boolean UisoLineOnSphe1 = Standard_False;
1826// UisoLineOnSphe1 = ::FUN_UisoLineOnSphe(F1,PC1new);
1827// if (UisoLineOnSphe1) {
1828// Standard_Real isrev1 =
1829// ::FUN_reversePC(PC1new,F1,P3DC3D,par2d,tol);
1830//
1831//#ifdef DEB
1832// if (tBUTO && isrev1) cout<<"on retourne PC1"<<endl;
1833//#endif
1834//
1835// }
1836//
1837// Standard_Boolean UisoLineOnSphe2 = Standard_False;
1838// UisoLineOnSphe2 = ::FUN_UisoLineOnSphe(F2,PC2new);
1839// if (UisoLineOnSphe2) {
1840// Standard_Real isrev2 =
1841// ::FUN_reversePC(PC2new,F2,P3DC3D,par2d,tol);
1842//
1843//#ifdef DEB
1844// if (tBUTO && isrev2) cout<<"on retourne PC2"<<endl;
1845//#endif
1846// }
1847
1848 // xpu : 17-06-97
1849 // Rmq : C1.Curve<i>() ne sert plus qu'a determiner si la courbe
1850 // est une isos de la sphere
1851 // NYI : enlever FUN_reversePC
1852 Standard_Boolean UisoLineOnSphe1 = Standard_False;
1853 UisoLineOnSphe1 = ::FUN_UisoLineOnSphe(F1,PC1new);
1854 if (UisoLineOnSphe1) {
1855 ::FUN_makeUisoLineOnSphe(F1,C3Dnew,PC1new,newtol);
1856 }
1857 Standard_Boolean UisoLineOnSphe2 = Standard_False;
1858 UisoLineOnSphe2 = ::FUN_UisoLineOnSphe(F2,PC2new);
1859 if (UisoLineOnSphe2) {
1860 ::FUN_makeUisoLineOnSphe(F2,C3Dnew,PC2new,newtol);
1861 } // xpu : 17-06-97
1862
1863 if (!C3Dnew.IsNull()) C2.Curve(C3Dnew,newtol);
1864 if (!PC1new.IsNull()) C2.Curve1(PC1new);
1865 if (!PC2new.IsNull()) C2.Curve2(PC2new);
1866
1867#ifdef DEB
1868 if (tBUTO) DUMPCURVES(C3Dnew,C2);
1869#endif
1870}*/ // - merge 04-07-97
1871
1872