0023948: Wrong intersection between a surface of revolution and a plane.
[occt.git] / src / ChFi3d / ChFi3d_Builder_CnCrn.cxx
CommitLineData
b311480e 1// Created on: 1997-03-01
2// Created by: MPS
3// Copyright (c) 1997-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.
b311480e 16
7fd59977 17// Modified by MPS (14-04-97) traitement des cas ou il n'y a pas
18// d'intersection entre les stripes
19// Modified by MPS (16-06-97) : on tient compte du fait que GeomPlate
20// rend les courbes 2d dans meme ordre que les
21// courbes frontieres passees en entree
22// Modified by JLR (20-08-97) mise en place des nouveaux constructeurs de GeomPlate
7fd59977 23// Modified by MPS (03-11-97) on ne cree pas un batten lorsque le rapport
24// entre les deux resolutions sur la surface est trop grand (PRO10649)
7fd59977 25// Modified by MPS (05-12-97) on ne tient pas compte des aretes degenerees
26// lors du calcul du nombre d'aretes.
7fd59977 27// Modified by JCT (08-12-97) traitement des aretes vives consecutives ou non
28// (grille EDC412 sauf D2, L1, L2, L3)
7fd59977 29// Modified by JCT (11-12-97) pb osf avec indpoint + orientation de plate
30// ( --> D2, L1, L2, L3 valides mais laids)
7fd59977 31// Modified by MPS (24-02-98) traitement des aretes de regularite
7fd59977 32// Modified by MPS (01-06-98) traitement des aretes de couture
33// Modified by MPS (01-12-98) traitement des bords libres
34// Modified by MPS (01-02-99) traitement des aretes de regularite
35// consecutives
36// Traitement des coins
37
38#include <Adaptor3d_HCurveOnSurface.hxx>
39#include <Adaptor3d_CurveOnSurface.hxx>
40#include <Bnd_Box2d.hxx>
41#include <BndLib_Add2dCurve.hxx>
42#include <BRep_Tool.hxx>
43#include <BRepTools.hxx>
44#include <BRepAlgo_NormalProjection.hxx>
45#include <BRepLib_MakeEdge.hxx>
46#include <ChFi3d_Builder.jxx>
47#include <ChFi3d_Builder_0.hxx>
48#include <ChFiDS_FaceInterference.hxx>
49#include <ChFiDS_ListIteratorOfListOfStripe.hxx>
50#include <ChFiDS_SurfData.hxx>
51#include <ChFiDS_SequenceOfSurfData.hxx>
52#include <ChFiDS_Stripe.hxx>
53#include <ChFiDS_HData.hxx>
54#include <ChFiDS_CommonPoint.hxx>
55#include <ChFiDS_Regul.hxx>
56#include <ChFiDS_StripeArray1.hxx>
57#include <Extrema_ExtPC.hxx>
58#include <Extrema_ExtCC.hxx>
59#include <Extrema_POnCurv.hxx>
60#include <GeomLib.hxx>
61#include <Extrema_ExtPC.hxx>
62#include <Geom2d_BSplineCurve.hxx>
63#include <GeomAdaptor_HSurface.hxx>
64#include <Geom2d_Line.hxx>
65#include <Geom_Line.hxx>
66#include <Geom_Curve.hxx>
67#include <Geom2d_TrimmedCurve.hxx>
68#include <GeomInt_IntSS.hxx>
69#include <GeomLib.hxx>
70#include <GeomAdaptor.hxx>
71#include <Geom2dAdaptor_HCurve.hxx>
72#include <GeomPlate_BuildPlateSurface.hxx>
73#include <GeomPlate_Surface.hxx>
74#include <GeomPlate_MakeApprox.hxx>
75#include <GeomPlate_PlateG0Criterion.hxx>
76#include <GeomPlate_HArray1OfHCurveOnSurface.hxx>
77#include <Geom_Surface.hxx>
78#include <Geom_BezierCurve.hxx>
79#include <Geom2dLProp_CLProps2d.hxx>
80#include <GeomPlate_CurveConstraint.hxx>
81#include <FairCurve_Batten.hxx>
82#include <Geom2d_BSplineCurve.hxx>
83#include <gp_Pnt.hxx>
84#include <gp_Pnt2d.hxx>
85#include <gp_Dir2d.hxx>
86#include <math_Matrix.hxx>
87#include <PLib.hxx>
88#include <TColStd_HArray1OfInteger.hxx>
89#include <TColStd_ListOfInteger.hxx>
90#include <TColgp_SequenceOfXY.hxx>
91#include <TColgp_SequenceOfXYZ.hxx>
92#include <TColgp_Array1OfXYZ.hxx>
93#include <TColgp_Array1OfPnt.hxx>
94#include <TColgp_Array1OfPnt2d.hxx>
95#include <TopTools_IndexedMapOfShape.hxx>
96#include <TColStd_Array1OfInteger.hxx>
97#include <TColStd_Array1OfBoolean.hxx>
98#include <TColStd_Array2OfInteger.hxx>
99#include <TColStd_Array1OfReal.hxx>
100#include <TColStd_Array2OfReal.hxx>
101#include <TColGeom2d_Array1OfCurve.hxx>
102#include <TColGeom2d_SequenceOfCurve.hxx>
103#include <TColGeom_Array1OfCurve.hxx>
104#include <TColGeom_SequenceOfCurve.hxx>
105#include <TColGeom2d_HArray1OfCurve.hxx>
106#include <TopAbs_Orientation.hxx>
107#include <TopExp.hxx>
108#include <TopExp_Explorer.hxx>
109#include <TopOpeBRepDS_DataStructure.hxx>
110#include <TopOpeBRepDS_Curve.hxx>
111#include <TopOpeBRepDS_Point.hxx>
112#include <TopOpeBRepDS_Surface.hxx>
113#include <TopOpeBRepDS_ListOfInterference.hxx>
114#include <TopOpeBRepDS_SolidSurfaceInterference.hxx>
115#include <TopOpeBRepDS_Kind.hxx>
116#include <TopOpeBRepDS_Transition.hxx>
117#include <TopOpeBRepDS_CurvePointInterference.hxx>
118#include <TopOpeBRepDS_SurfaceCurveInterference.hxx>
119#include <TopTools_Array2OfShape.hxx>
120#include <BRepLib_MakeFace.hxx>
121#include <Precision.hxx>
122// performances
123#ifdef DEB
124#include <OSD_Chronometer.hxx>
125extern Standard_Real t_plate ,t_approxplate,t_batten;
126extern void ChFi3d_InitChron(OSD_Chronometer& ch);
127extern void ChFi3d_ResultChron(OSD_Chronometer & ch,Standard_Real& time);
128#endif
129
130// Modified by Sergey KHROMOV - Fri Dec 21 17:08:19 2001 Begin
131Standard_Boolean isTangentFaces(const TopoDS_Edge &theEdge,
132 const TopoDS_Face &theFace1,
133 const TopoDS_Face &theFace2);
134// Modified by Sergey KHROMOV - Fri Dec 21 17:08:19 2001 End
135
136//=======================================================================
137//function : Indices
138//purpose :
139//=======================================================================
140
141static void Indices ( const Standard_Integer n,
142 const Standard_Integer ic,
143 Standard_Integer & icplus,
144 Standard_Integer & icmoins)
145{
146 if (ic== (n-1)) icplus=0;
147 else icplus=ic+1;
148 if (ic==0) icmoins=n-1;
149 else icmoins=ic-1;
150}
151
152//=======================================================================
153//function : Calcul_Param
154//purpose :
155//=======================================================================
156
157static void Calcul_Param (const Handle(ChFiDS_Stripe)& stripe,
158 const Standard_Integer jfposit,
159 const Standard_Integer indice,
160 const Standard_Boolean isfirst,
161 Standard_Real & param)
162{
163 if (jfposit==2 )
164 param=stripe->SetOfSurfData()->Value(indice)->InterferenceOnS2().Parameter(isfirst);
165 else
166 param=stripe->SetOfSurfData()->Value(indice)->InterferenceOnS1().Parameter(isfirst);
167}
168
169//=======================================================================
170//function : Calcul_P2dOnSurf
171//purpose :
172//=======================================================================
173
174static void Calcul_P2dOnSurf(const Handle(ChFiDS_Stripe)& stripe,
175 const Standard_Integer jfposit,
176 const Standard_Integer indice,
177 const Standard_Real param,
178 gp_Pnt2d & p2)
179
180{
181 if (jfposit==1)
182 stripe->SetOfSurfData()->Value(indice)
183 ->InterferenceOnS1().PCurveOnSurf()->D0(param,p2);
184 else
185 stripe->SetOfSurfData()->Value(indice)
186 ->InterferenceOnS2().PCurveOnSurf()->D0(param,p2);
187}
188
189//=======================================================================
190//function : Calcul_C2dOnFace
191//purpose :
192//=======================================================================
193
194static void Calcul_C2dOnFace (const Handle(ChFiDS_Stripe)& stripe,
195 const Standard_Integer jfposit,
196 const Standard_Integer indice,
197 Handle(Geom2d_Curve) & c2d)
198
199{
200 if (jfposit==1)
201 c2d = stripe->SetOfSurfData()->Value(indice)
202 ->InterferenceOnS1().PCurveOnFace();
203 else
204 c2d = stripe->SetOfSurfData()->Value(indice)
205 ->InterferenceOnS2().PCurveOnFace();
206}
207
208//=======================================================================
209//function : Calcul_Orientation
210//purpose :
211//=======================================================================
212
213static void Calcul_Orientation(const Handle(ChFiDS_Stripe)& stripe,
214 const Standard_Integer jfposit,
215 const Standard_Integer indice,
216 TopAbs_Orientation & orient)
217{
218 if (jfposit==1)
219 orient = stripe->SetOfSurfData()->Value(indice)
220 ->InterferenceOnS1().Transition();
221 else
222 orient = stripe->SetOfSurfData()->Value(indice)
223 ->InterferenceOnS2().Transition();
224}
225
226//=======================================================================
227//function : RemoveSD
228//purpose :
229//=======================================================================
230
231static void RemoveSD(Handle(ChFiDS_Stripe)& Stripe,
232 const Standard_Integer num1,
233 const Standard_Integer num2 )
234{
235 ChFiDS_SequenceOfSurfData& Seq =
236 Stripe->ChangeSetOfSurfData()->ChangeSequence();
237 if(Seq.IsEmpty()) return;
238 if (num1==num2)
239 Seq.Remove(num1);
240 else
241 Seq.Remove(num1,num2);
242}
243
244//=======================================================================
245//function : cherche_edge1
81bba717 246//purpose : find common edge of faces F1 and F2
7fd59977 247//=======================================================================
248
249static void cherche_edge1 (const TopoDS_Face & F1,
250 const TopoDS_Face & F2,
251 TopoDS_Edge & Edge)
252{ Standard_Integer i,j;
253 TopoDS_Edge Ecur1,Ecur2;
254 Standard_Boolean trouve=Standard_False;
255 TopTools_IndexedMapOfShape MapE1,MapE2;
256 TopExp::MapShapes( F1,TopAbs_EDGE,MapE1);
257 TopExp::MapShapes( F2,TopAbs_EDGE,MapE2);
258 for ( i=1; i<= MapE1.Extent()&&!trouve; i++)
259 {
260 TopoDS_Shape aLocalShape = TopoDS_Shape (MapE1(i));
261 Ecur1=TopoDS::Edge(aLocalShape);
262 // Ecur1=TopoDS::Edge(TopoDS_Shape (MapE1(i)));
263 for ( j=1; j<= MapE2.Extent()&&!trouve; j++)
264 {
265 aLocalShape = TopoDS_Shape (MapE2(j));
266 Ecur2=TopoDS::Edge(aLocalShape);
267 // Ecur2=TopoDS::Edge(TopoDS_Shape (MapE2(j)));
268 if (Ecur2.IsSame(Ecur1))
269 {Edge=Ecur1;trouve=Standard_True;}
270 }
271 }
272}
273
274//=======================================================================
275//function : CurveHermite
81bba717 276//purpose : calculate a curve 3d using polynoms of Hermite.
277// the edge is a regular edge. Curve 3D is constructed
278// between edges icmoins and icplus.
7fd59977 279//=======================================================================
280
281static void CurveHermite (const TopOpeBRepDS_DataStructure& DStr,
282 const Handle(ChFiDS_Stripe)& CDicmoins,
283 const Standard_Integer jficmoins,
284 const Standard_Integer icmoins,
285 const Standard_Real picmoins,
286 const Standard_Integer sensicmoins,
287 const Standard_Boolean sharpicmoins,
288 const TopoDS_Edge & Eviveicmoins,
289 const Handle(ChFiDS_Stripe)& CDicplus,
290 const Standard_Integer jficplus,
291 const Standard_Integer icplus,
292 const Standard_Real picplus,
293 const Standard_Integer sensicplus,
294 const Standard_Boolean sharpicplus,
295 const TopoDS_Edge & Eviveicplus,
296 const Standard_Integer nbface,
297 TopTools_SequenceOfShape & Ecom,
298 const TopTools_SequenceOfShape & Face,
299 TColGeom2d_SequenceOfCurve & proj2d,
300 TColGeom_SequenceOfCurve & cproj,
301 TopTools_SequenceOfShape & Eproj,
302 TColStd_SequenceOfReal & param,
303 Standard_Real & error)
304{
305 gp_Pnt p01,p02;
306 gp_Vec d11,d12;
307 Standard_Integer ii,jj;
308 Standard_Real up1,up2;
309 Standard_Integer ilin,jfp;
310 Handle (Geom_Curve) c1,c2;
311 if (sharpicmoins) {
312 c1=BRep_Tool::Curve(Eviveicmoins,up1,up2);
313 }
314 else {
315 if (jficmoins==1)
316 ilin= CDicmoins->SetOfSurfData()->Value( icmoins)->InterferenceOnS1().LineIndex();
317 else ilin= CDicmoins->SetOfSurfData()->Value(icmoins)->InterferenceOnS2().LineIndex();
318 c1=DStr.Curve(ilin).Curve();
319 }
320 if (sharpicplus){
321 c2=BRep_Tool::Curve(Eviveicplus,up1,up2);
322 }
323 else {
324 jfp=3-jficplus;
325 if (jfp==1)
326 ilin= CDicplus->SetOfSurfData()->Value( icplus)->InterferenceOnS1().LineIndex();
327 else ilin=CDicplus->SetOfSurfData()->Value(icplus)->InterferenceOnS2().LineIndex();
328 c2=DStr.Curve(ilin ).Curve();
329 }
330 c1->D1(picmoins,p01,d11);
331 c2->D1(picplus,p02,d12);
332 Standard_Integer size = 4;
333 math_Matrix MatCoefs(1,size, 1,size);
334 TColgp_Array1OfXYZ Cont(1,size);
335 PLib::HermiteCoefficients(0, 1,1,1,MatCoefs);
336 Standard_Real L1=p01.Distance(p02);
337 Standard_Real lambda= ((Standard_Real)1) / Max (d11.Magnitude() / L1, 1.e-6);
338 Cont(1) = p01.XYZ();
339 if (sensicmoins==1) Cont(2) = d11.XYZ()*(-lambda) ;
340 else Cont(2) = d11.XYZ()*(lambda) ;
341 lambda= ((Standard_Real)1) / Max (d12.Magnitude() / L1, 1.e-6);
342 Cont(3) = p02.XYZ();
343 if (sensicplus==1) Cont(4) = d12.XYZ()*(lambda);
344 else Cont(4) = d12.XYZ()*(-lambda);
345 TColgp_Array1OfPnt ExtrapPoles(1, size);
346 TColgp_Array1OfPnt ExtraCoeffs(1, size);
347 gp_Pnt p0(0,0,0);
348 ExtraCoeffs.Init(p0);
349 for (ii=1; ii<=size; ii++) {
350 for (jj=1; jj<=size; jj++) {
351 ExtraCoeffs(jj).ChangeCoord() += MatCoefs(ii,jj)*Cont(ii);
352 }
353 }
354 PLib::CoefficientsPoles(ExtraCoeffs, PLib::NoWeights(),
355 ExtrapPoles, PLib::NoWeights());
356 Handle(Geom_BezierCurve) Bezier = new (Geom_BezierCurve) (ExtrapPoles);
357 BRepLib_MakeEdge Bedge (Bezier);
358 TopoDS_Edge edg =Bedge. Edge();
359 TopoDS_Face F;
360 error=1.e-30;
361 Standard_Integer nb;
362 for(nb=1;nb<=nbface;nb++){
363 F=TopoDS::Face(Face.Value(nb));
364 TopTools_IndexedMapOfShape MapE1;
365 TopoDS_Edge E1;
366 Handle(Geom2d_Curve) proj1;
367 Handle(Geom_Curve) proj1c,proj2c;
368 BRepAlgo_NormalProjection OrtProj;
369 OrtProj.Init(F);
370 OrtProj.Add(edg);
371 OrtProj.SetParams(1.e-4, 1.e-4, GeomAbs_C1, 14, 16);
372 OrtProj.Build();
373 if ( OrtProj.IsDone()){
374 TopExp::MapShapes(OrtProj.Projection() , TopAbs_EDGE, MapE1);
375 if (MapE1.Extent()!=0){
376 if (MapE1.Extent()!=1) {
1c72dff6 377 BRepLib_MakeFace Bface (BRep_Tool::Surface(F), Precision::Confusion());
7fd59977 378 F=Bface.Face();
379 OrtProj.Init(F);
380 OrtProj.Build();
381 MapE1.Clear();
382 if ( OrtProj.IsDone())
383 TopExp::MapShapes(OrtProj.Projection() ,TopAbs_EDGE, MapE1);
384 }
385 if (MapE1.Extent()!=0) {
386 Standard_Boolean trouve=Standard_False;
387 for (Standard_Integer ind=1;ind<=MapE1.Extent()&&!trouve;ind++){
388 TopoDS_Shape aLocalShape = TopoDS_Shape( MapE1(ind));
389 E1=TopoDS::Edge( aLocalShape );
390 // E1=TopoDS::Edge( TopoDS_Shape (MapE1(ind)));
391 if (!BRep_Tool::Degenerated(E1)) trouve=Standard_True;
392 }
393 Eproj.Append(E1);
394 proj1=BRep_Tool::CurveOnSurface(E1,F,up1,up2);
395 proj2d.Append(new Geom2d_TrimmedCurve(proj1,up1,up2));
396 proj1c=BRep_Tool::Curve(E1,up1,up2);
397 cproj.Append(new Geom_TrimmedCurve(proj1c,up1,up2));
398 if (error>BRep_Tool::Tolerance(E1)) error=BRep_Tool::Tolerance(E1);
399 }
400 else {
401 Eproj.Append(E1);
402 proj2d.Append(proj1);
403 cproj.Append(proj1c);
404 }
405 }
406 else {
407 Eproj.Append(E1);
408 proj2d.Append(proj1);
409 cproj.Append(proj1c);
410 }
411 }
412 }
413 for (nb=1;nb<=nbface-1;nb++) {
414 BRepAdaptor_Curve C(TopoDS::Edge(Ecom.Value(nb)));
415 C.D0(param.Value(nb),p02);
416 GeomAdaptor_Curve L (Bezier);
417 Extrema_ExtCC ext (C,L);
418 if (ext.IsDone()){
419 if (ext.NbExt()!=0){
420 Extrema_POnCurv POnC, POnL;
421 ext.Points(1, POnC, POnL);
4bbaf12b 422 if (POnC.Value().Distance(POnL.Value()) < Precision::Confusion())
423 param.ChangeValue(nb) =POnC.Parameter();
424 else
425 {
426 if (!cproj.Value(nb).IsNull()) {
427 cproj.Value(nb)->D0(cproj.Value(nb)->LastParameter(),p01);
428 }
429 else if (!cproj.Value(nb+1).IsNull()) {
430 cproj.Value(nb+1)->D0(cproj.Value(nb+1)->FirstParameter(),p01);
431 }
432 }
7fd59977 433 }
434 }
435 if (!ext.IsDone()||ext.NbExt()==0) {
436 if (!cproj.Value(nb).IsNull()) {
437 cproj.Value(nb)->D0(cproj.Value(nb)->LastParameter(),p01);
438 }
439 else if (!cproj.Value(nb+1).IsNull()) {
440 cproj.Value(nb+1)->D0(cproj.Value(nb+1)->FirstParameter(),p01);
441 }
442 if (p01.Distance(p02)>1.e-4 ){
443 Extrema_ExtPC ext1 (p01,C);
444 if (ext1.IsDone()){
445 if (ext1.NbExt()!=0){
446 Extrema_POnCurv POnC(ext1.Point(1));
447 param.ChangeValue(nb) =POnC.Parameter();
448 }
449 }
450 }
451 }
452 }
453}
454
455//=======================================================================
456//function : CalculDroite
81bba717 457//purpose : calculate a 2D straight line passing through point p2d1 and direction xdir ydir
7fd59977 458//=======================================================================
459
460static void CalculDroite(const gp_Pnt2d & p2d1,
461 const Standard_Real xdir,
462 const Standard_Real ydir,
463 Handle (Geom2d_Curve) & pcurve)
464{ gp_Dir2d dir1 (xdir, ydir);
465 Handle(Geom2d_Line) l= new Geom2d_Line (p2d1,dir1);
466 Standard_Real l0 = sqrt(xdir*xdir+ ydir*ydir );
467 pcurve = new Geom2d_TrimmedCurve(l,0,l0);
468}
469
470//=======================================================================
471//function : CalculBatten
81bba717 472//purpose : calcule a batten between curves 2d curv2d1 and curv2d2 at points p2d1 and p2d2
7fd59977 473//=======================================================================
474
475static void CalculBatten (const Handle (GeomAdaptor_HSurface) ASurf,
476 const TopoDS_Face Face ,
477 const Standard_Real xdir,
478 const Standard_Real ydir,
479 const gp_Pnt2d & p2d1,
480 const gp_Pnt2d & p2d2,
481 const Standard_Boolean contraint1,
482 const Standard_Boolean contraint2,
483 Handle (Geom2d_Curve) & curv2d1,
484 Handle (Geom2d_Curve) & curv2d2,
485 const Standard_Real picicplus,
486 const Standard_Real picplusic,
487 const Standard_Boolean inverseic,
488 const Standard_Boolean inverseicplus,
489 Handle (Geom2d_Curve)& pcurve)
490{
491 Standard_Boolean isplane;
7fd59977 492 Standard_Boolean anglebig = Standard_False;
7fd59977 493 isplane=ASurf->GetType()==GeomAbs_Plane;
494 gp_Dir2d dir1 (xdir, ydir);
495 Geom2dLProp_CLProps2d CL1(curv2d1, picicplus, 1, 1.e-4);
496 Geom2dLProp_CLProps2d CL2( curv2d2, picplusic, 1, 1.e-4);
497 gp_Dir2d dir3,dir4 ;
498 CL1.Tangent(dir3);
499 CL2.Tangent(dir4);
500 if (inverseic) dir3.Reverse();
501 if (inverseicplus) dir4.Reverse();
502 Standard_Real h = p2d2.Distance(p2d1)/20;
503 FairCurve_Batten Bat(p2d1,p2d2,h);
504 Bat.SetFreeSliding (Standard_True);
505 Standard_Real ang1,ang2;
506 ang1=dir1.Angle(dir3);
c6541a0c
D
507 if (dir1.Angle(dir4) >0 ) ang2=M_PI-dir1.Angle(dir4);
508 else ang2=-M_PI-dir1.Angle(dir4);
7fd59977 509 if (contraint1&&contraint2)
510 anglebig=(Abs(ang1)>1.2)|| (Abs(ang2)>1.2 );
511 else if (contraint1)
512 anglebig=Abs(ang1)>1.2;
513 else if (contraint2)
514 anglebig=Abs(ang2)>1.2;
c6541a0c 515 if (isplane && (Abs(ang1)>M_PI/2 || Abs(ang2)>M_PI/2))
7fd59977 516 isplane=Standard_False;
517 if (anglebig && !isplane) {
518 CalculDroite(p2d1,xdir,ydir,pcurve);
519 }
520 else {
521 if (contraint1) Bat.SetAngle1(ang1);
522 else Bat.SetConstraintOrder1(0);
523 if (contraint2) Bat.SetAngle2(ang2);
524 else Bat.SetConstraintOrder2(0);
525 FairCurve_AnalysisCode Iana;
526 Standard_Boolean Ok;
527 Ok = Bat.Compute(Iana,25,1.e-2);
528#if DEB
529 if (!Ok) {
81bba717 530 cout<<"no batten :";
7fd59977 531 Bat.Dump(cout);
532 }
533#endif
534 if (Ok) {
535 pcurve = Bat.Curve();
536 Standard_Real umin,vmin,umax,vmax;
537 BRepTools::UVBounds(Face,umin,umax,vmin,vmax);
538 Bnd_Box2d bf,bc;
539 Geom2dAdaptor_Curve acur(pcurve);
540 BndLib_Add2dCurve::Add(acur,0,bc);
541 bf.Update(umin,vmin,umax,vmax);
542 Standard_Real uminc,vminc,umaxc,vmaxc;
543 bc.Get(uminc,vminc,umaxc,vmaxc);
544 if (uminc<umin-1.e-7) Ok=Standard_False;
545 if (umaxc>umax+1.e-7) Ok=Standard_False;
546 if (vminc<vmin-1.e-7) Ok=Standard_False;
547 if (vmaxc>vmax+1.e-7) Ok=Standard_False;
548 }
549 if (!Ok) CalculDroite(p2d1, xdir,ydir, pcurve);
550 }
551}
552
553//=======================================================================
554//function : OrientationIcNonVive
81bba717 555//purpose : calculate the orientation of the curve between ic and icplus knowing that ic
556// is not a living edge.
7fd59977 557//=======================================================================
558
559static void OrientationIcNonVive (const Handle(ChFiDS_Stripe) & CDic,
560 const Standard_Integer jfic,
561 const Standard_Integer icicplus,
562 const Standard_Integer sensic,
563 TopAbs_Orientation & orien )
564{
565 TopAbs_Orientation orinterf;
566 Calcul_Orientation(CDic,jfic,icicplus,orinterf);
567 if (sensic!=1){
568 if (orinterf==TopAbs_FORWARD) orien=TopAbs_FORWARD;
569 else orien=TopAbs_REVERSED;
570 }
571 else {
572 if (orinterf==TopAbs_FORWARD) orien=TopAbs_REVERSED;
573 else orien=TopAbs_FORWARD;
574 }
575}
576
577//=======================================================================
578//function : OrientationIcplusNonVive
81bba717 579//purpose : calculate the orientation of the curve between ic and icplus knowing that icplus
580// is not a living edge;
7fd59977 581//=======================================================================
582
583static void OrientationIcplusNonVive (const Handle(ChFiDS_Stripe) & CDicplus,
584 const Standard_Integer jficplus,
585 const Standard_Integer icplusic,
586 const Standard_Integer sensicplus,
587 TopAbs_Orientation & orien )
588{
589 TopAbs_Orientation orinterf;
590 Standard_Integer jfp = 3 -jficplus;
591 Calcul_Orientation(CDicplus,jfp,icplusic,orinterf);
592 if (sensicplus==1){
593 if (orinterf==TopAbs_FORWARD) orien=TopAbs_FORWARD;
594 else orien=TopAbs_REVERSED;
595 }
596 else {
597 if (orinterf==TopAbs_FORWARD) orien=TopAbs_REVERSED;
598 else orien=TopAbs_FORWARD;
599 }
600}
601
602//=======================================================================
603//function : OrientationAreteViveConsecutive
81bba717 604//purpose : calculate the orientation of the curve between edges ic and icplus
605// where ic and icplus are consecutively living
7fd59977 606//=======================================================================
607
608static void OrientationAreteViveConsecutive (const TopoDS_Shape & Fviveicicplus,
609 const TopoDS_Shape & Eviveic,
610 const TopoDS_Vertex & V1,
611 TopAbs_Orientation & orien)
612
81bba717 613{ // orinterf is orientation of edge ic corresponding to face Fviveicicplus taken FORWARD
7fd59977 614 TopAbs_Orientation orinterf = TopAbs_FORWARD;
7fd59977 615 TopoDS_Face F=TopoDS::Face( Fviveicicplus);
616 TopoDS_Edge E=TopoDS::Edge( Eviveic);
617 TopExp_Explorer ex;
618 for(ex.Init(F.Oriented(TopAbs_FORWARD),TopAbs_EDGE);ex.More(); ex.Next()){
619 if(E.IsSame(ex.Current())) {
620 orinterf = ex.Current().Orientation();
621 break;
622 }
623 }
81bba717 624 // if V1 is vertex REVERSED of edge ic the curve
625 // has the same orientation as ic
7fd59977 626 TopoDS_Vertex vl;
627 vl=TopExp::LastVertex(E);
628 if (vl.IsSame(V1)){
629 if (orinterf==TopAbs_FORWARD) orien=TopAbs_FORWARD;
630 else orien=TopAbs_REVERSED;
631 }
632 else {
633 if (orinterf==TopAbs_FORWARD) orien=TopAbs_REVERSED;
634 else orien=TopAbs_FORWARD;
635 }
636}
637
638//=======================================================================
639//function : PerformTwoCornerSameExt
81bba717 640//purpose : calculate intersection between two stripes stripe1 and stripe2
7fd59977 641//=======================================================================
642
643static void PerformTwoCornerSameExt(TopOpeBRepDS_DataStructure& DStr,
644 const Handle(ChFiDS_Stripe)& stripe1,
645 const Standard_Integer index1,
646 const Standard_Integer sens1,
647 const Handle(ChFiDS_Stripe) &stripe2,
648 const Standard_Integer index2,
649 const Standard_Integer sens2,
650 Standard_Boolean & trouve)
651
652{ Handle (TopOpeBRepDS_CurvePointInterference) Interfp1, Interfp2;
653 Handle (TopOpeBRepDS_SurfaceCurveInterference) Interfc;
654 TopAbs_Orientation orpcurve,trafil1,orsurf1,orsurf2;
655 Standard_Boolean isfirst;
656 Standard_Integer indic1,indic2, indpoint1,indpoint2,ind,indcurve;
657 Standard_Real tol;
658 gp_Pnt P1,P2,P3,P4;
659 gp_Pnt2d p2d;
660 Handle(Geom_Curve)cint;
661 Handle(Geom2d_Curve) C2dint1,C2dint2;
662 isfirst=sens1==1;
663 ChFiDS_CommonPoint& Com11= stripe1->SetOfSurfData()->Value(index1)->ChangeVertex (isfirst,1);
664 ChFiDS_CommonPoint& Com12= stripe1->SetOfSurfData()->Value(index1)->ChangeVertex (isfirst,2);
665 isfirst=sens2==1;
666 ChFiDS_CommonPoint& Com21= stripe2->SetOfSurfData()->Value(index2)->ChangeVertex (isfirst,1);
667#ifdef DEB
668// ChFiDS_CommonPoint& Com22=
669// stripe2->SetOfSurfData()->Value(index2)->ChangeVertex (isfirst,2);
670#endif
671 indic1=stripe1->SetOfSurfData()->Value(index1)->Surf();
672 indic2=stripe2->SetOfSurfData()->Value(index2)->Surf();
673 const Handle(ChFiDS_SurfData) Fd1=stripe1->SetOfSurfData()->Value(index1);
674 const Handle(ChFiDS_SurfData) Fd2=stripe2->SetOfSurfData()->Value(index2);
675
676 TColStd_Array1OfReal Pardeb(1,4),Parfin(1,4);
677 const ChFiDS_FaceInterference& Fi11 = Fd1->InterferenceOnS1();
678 const ChFiDS_FaceInterference& Fi12 = Fd1->InterferenceOnS2();
679 const ChFiDS_FaceInterference& Fi21 = Fd2->InterferenceOnS1();
680 const ChFiDS_FaceInterference& Fi22 = Fd2->InterferenceOnS2();
681 gp_Pnt2d pfi11,pfi12,pfi21,pfi22;
682 isfirst=sens1==1;
683 pfi11 = Fi11.PCurveOnSurf()->Value(Fi11.Parameter(isfirst));
684 pfi12 = Fi12.PCurveOnSurf()->Value(Fi12.Parameter(isfirst));
685 isfirst=sens2==1;
686 if (Com11.Point().Distance(Com21.Point()) <1.e-4) {
687 pfi21 = Fi21.PCurveOnSurf()->Value(Fi21.Parameter(isfirst));
688 pfi22 = Fi22.PCurveOnSurf()->Value(Fi22.Parameter(isfirst));
689 }
690 else {
691 pfi22 = Fi21.PCurveOnSurf()->Value(Fi21.Parameter(isfirst));
692 pfi21 = Fi22.PCurveOnSurf()->Value(Fi22.Parameter(isfirst));
693 }
694
695 Pardeb(1)= pfi11.X();Pardeb(2) = pfi11.Y();
696 Pardeb(3)= pfi21.X();Pardeb(4) = pfi21.Y();
697 Parfin(1)= pfi12.X();Parfin(2) = pfi12.Y();
698 Parfin(3)= pfi22.X();Parfin(4) = pfi22.Y();
699
700 Handle(GeomAdaptor_HSurface) HS1= ChFi3d_BoundSurf(DStr,Fd1,1,2);
701 Handle(GeomAdaptor_HSurface) HS2= ChFi3d_BoundSurf(DStr,Fd2,1,2);
702 trouve=Standard_False;
703 if (ChFi3d_ComputeCurves(HS1,HS2,Pardeb,Parfin,cint,
704 C2dint1,C2dint2,1.e-4,1.e-5,tol)){
705 cint->D0(cint->FirstParameter(),P1);
706 cint->D0(cint->LastParameter(),P2);
707 trouve=((Com11.Point().Distance(P1) <1.e-4 || Com11.Point().Distance(P2)<1.e-4)&&
708 (Com12.Point().Distance(P1) <1.e-4 || Com12.Point().Distance(P2)<1.e-4));
709 }
710
711 if (trouve) {
712 isfirst=sens1==1;
713 stripe1->InDS(isfirst);
714 indpoint1=ChFi3d_IndexPointInDS(Com11,DStr);
715 indpoint2=ChFi3d_IndexPointInDS(Com12,DStr);
716 stripe1->SetIndexPoint(indpoint1,isfirst,1);
717 stripe1->SetIndexPoint(indpoint2,isfirst,2);
718 isfirst=sens2==1;
719 stripe2->InDS(isfirst);
720 if (Com11.Point().Distance(Com21.Point()) <1.e-4) {
721 stripe2->SetIndexPoint(indpoint1,isfirst,1);
722 stripe2->SetIndexPoint(indpoint2,isfirst,2);
723 }
724 else {
725 stripe2->SetIndexPoint(indpoint2,isfirst,1);
726 stripe2->SetIndexPoint(indpoint1,isfirst,2);
727 }
728
729 orsurf1=Fd1->Orientation();
730 trafil1 = DStr.Shape(Fd1->IndexOfS1()).Orientation();
731 trafil1 = TopAbs::Compose(trafil1,Fd1->Orientation());
732 trafil1 = TopAbs::Compose(TopAbs::Reverse(Fi11.Transition()),trafil1);
733 orsurf2=Fd2->Orientation();
734 TopOpeBRepDS_Curve tcurv3d(cint,tol);
735 indcurve= DStr.AddCurve(tcurv3d);
736 cint->D0(cint->FirstParameter(),P1);
737 cint->D0(cint->LastParameter(),P2);
738 Fi11.PCurveOnFace()->D0(Fi11.LastParameter(),p2d);
739 const Handle(Geom_Surface) Stemp =
740 BRep_Tool::Surface(TopoDS::Face(DStr.Shape(Fd1->IndexOfS1())));
741 Stemp ->D0(p2d.X(),p2d.Y(),P4);
742 Fi11.PCurveOnFace()->D0(Fi11.FirstParameter(),p2d);
743 Stemp ->D0(p2d.X(),p2d.Y(),P3);
744 if (P1.Distance(P4)<1.e-4 || P2.Distance(P3)<1.e-4)
745 orpcurve=trafil1;
746 else orpcurve=TopAbs::Reverse(trafil1);
747 if (Com11.Point().Distance(P1) >1.e-4) {
748 ind=indpoint1;
749 indpoint1=indpoint2;
750 indpoint2=ind;
751 }
752 Interfp1=ChFi3d_FilPointInDS(TopAbs_FORWARD,indcurve, indpoint1, cint->FirstParameter());
753 Interfp2=ChFi3d_FilPointInDS(TopAbs_REVERSED,indcurve,indpoint2, cint->LastParameter());
754 DStr.ChangeCurveInterferences(indcurve).Append(Interfp1);
755 DStr.ChangeCurveInterferences(indcurve).Append(Interfp2);
756 Interfc=ChFi3d_FilCurveInDS(indcurve,indic1,C2dint1,orpcurve);
757 DStr.ChangeSurfaceInterferences(indic1).Append(Interfc);
758 if (orsurf1==orsurf2) orpcurve=TopAbs::Reverse(orpcurve);
759 Interfc=ChFi3d_FilCurveInDS(indcurve,indic2,C2dint2,orpcurve);
760 DStr.ChangeSurfaceInterferences(indic2).Append(Interfc);
761 }
762}
763
764//=======================================================================
765//function : CpOnEdge
81bba717 766//purpose : determine if surfdata num has a common point on Eadj1 or Eadj2
7fd59977 767//=======================================================================
768
769static void CpOnEdge (const Handle(ChFiDS_Stripe) & stripe,
770 Standard_Integer num,
771 Standard_Boolean isfirst,
772 const TopoDS_Edge & Eadj1,
773 const TopoDS_Edge & Eadj2,
774 Standard_Boolean & compoint)
775
776{ ChFiDS_CommonPoint cp1,cp2;
777 compoint=Standard_False;
778 cp1 = stripe->SetOfSurfData()->Value(num)->ChangeVertex (isfirst,1);
779 cp2 = stripe->SetOfSurfData()->Value(num)->ChangeVertex (isfirst,2);
780 if(cp1.IsOnArc()){
781 if (cp1.Arc().IsSame(Eadj1)||cp1.Arc().IsSame(Eadj2))
782 compoint=Standard_True;
783 }
784 if(cp2.IsOnArc()){
785 if (cp2.Arc().IsSame(Eadj1)||cp2.Arc().IsSame(Eadj2))
786 compoint=Standard_True;
787 }
788}
789
790//=======================================================================
791//function : RemoveSurfData
81bba717 792//purpose : for each stripe removal of unused surfdatas
7fd59977 793//=======================================================================
794
795static void RemoveSurfData (const ChFiDS_StripeMap & myVDataMap,
796 const ChFiDS_Map & myEFMap,
797 const TopoDS_Edge &edgecouture,
798 const TopoDS_Face & facecouture,
799 const TopoDS_Vertex &V1)
800{ ChFiDS_ListIteratorOfListOfStripe It;
801 Standard_Boolean isfirst;
802 TopoDS_Edge Ecur,Eadj1,Eadj2;
803 TopoDS_Face Fg,Fd,F1,F2;
804 TopoDS_Vertex Vbid;
805 Standard_Integer nbsurf,nbedge,sense,num;
806 for (It.Initialize(myVDataMap(V1));It.More();It.Next()) {
807 nbsurf= It.Value()->SetOfSurfData()->Length();
808 nbedge = It.Value()->Spine()->NbEdges();
809 if (nbsurf!=1){
810 num=ChFi3d_IndexOfSurfData(V1,It.Value(),sense);
811 if (sense==1)
812 Ecur = It.Value()->Spine()->Edges(1);
813 else
814 Ecur = It.Value()->Spine()->Edges(nbedge);
815 ChFi3d_edge_common_faces(myEFMap(Ecur),F1,F2);
816 if (F1.IsSame(facecouture)) Eadj1=edgecouture;
817 else ChFi3d_cherche_element(V1,Ecur,F1,Eadj1,Vbid);
818 ChFi3d_edge_common_faces(myEFMap(Eadj1),Fg,Fd);
819 if (F2.IsSame(facecouture)) Eadj2=edgecouture;
820 else ChFi3d_cherche_element(V1,Ecur,F2,Eadj2,Vbid);
821 ChFi3d_edge_common_faces(myEFMap(Eadj2),Fg,Fd);
822 Standard_Boolean compoint=Standard_False;
823 isfirst=(sense==1);
824 Standard_Integer ind;
825 if (sense==1) {
826 ind=0;
81bba717 827 // among surfdatas find the greatest indice ind so that
828 // surfdata could have one of commonpoint on Eadj1 and Eadj2
829 // remove surfdata from 1 to ind-1
7fd59977 830 for (Standard_Integer i=1;i<=nbsurf;i++) {
831 CpOnEdge (It.Value(),i,isfirst,Eadj1,Eadj2,compoint);
832 if (compoint) ind=i;
833 }
834 if (ind>=2) RemoveSD(It.Value(),1,ind-1);
835 }
836 else {
837 ind=num;
81bba717 838 // among surfdatas find the smallest indice ind so that
839 // surfdata could have one of commonpoint on Eadj1 and Eadj2
840 // remove surfdata from ind+1 to num
7fd59977 841 for (Standard_Integer i=num;i>=1;i--) {
842 CpOnEdge (It.Value(),i,isfirst,Eadj1,Eadj2,compoint);
843 if (compoint) ind=i;
844 }
845 if (ind<num) RemoveSD(It.Value(),ind+1,num);
846 }
847 }
848 }
849}
850
851//=======================================================================
852//function : ParametrePlate
853//purpose :
854//=======================================================================
855
856static void ParametrePlate(const Standard_Integer n3d,
857 const GeomPlate_BuildPlateSurface & PSurf,
858 const Handle(Geom_Surface) & Surf,
859 const gp_Pnt & point,
860 const Standard_Real apperror,
861 gp_Pnt2d & uv)
862{ Standard_Integer ip;
863 gp_Pnt P1;
864 Standard_Real par;
865 Standard_Boolean trouve=Standard_False;
866 for (ip=1;ip<=n3d && !trouve;ip++){
867 par=PSurf.Curves2d()->Value(ip)->FirstParameter();
868 PSurf.Curves2d()->Value(ip)->D0(par,uv);
869 Surf->D0(uv.X(),uv.Y(),P1);
870 trouve=P1.IsEqual(point,apperror);
871 if (!trouve) {
872 par=PSurf.Curves2d()->Value(ip)->LastParameter();
873 PSurf.Curves2d()->Value(ip)->D0(par,uv);
874 Surf->D0(uv.X(),uv.Y(),P1);
875 trouve=P1.IsEqual(point,apperror);
876 }
877 }
878}
879
880//=======================================================================
881//function : SummarizeNormal
882//purpose :
883//=======================================================================
884
885static void SummarizeNormal(const TopoDS_Vertex& V1,
886 const TopoDS_Face& Fcur,
887 const TopoDS_Edge& Ecur,
888 gp_Vec& SumFaceNormalAtV1)
889{
890 gp_Pnt2d uv1, uv2;
891 BRep_Tool::UVPoints(Ecur,Fcur,uv1,uv2);
892 if ( ! V1.IsSame(TopExp::FirstVertex(Ecur))) uv1 = uv2;
893
894 gp_Pnt P;
895 gp_Vec d1U, d1V;
896 BRep_Tool::Surface(Fcur)->D1( uv1.X(), uv1.Y(), P, d1U, d1V);
897 gp_Vec N = d1U.Crossed(d1V);
898 if (Fcur.Orientation() == TopAbs_REVERSED) N.Reverse();
899
900 if (N.SquareMagnitude() <= Precision::PConfusion()) return;
901
902 SumFaceNormalAtV1 += N.Normalized();
903 SumFaceNormalAtV1.Normalize();
904}
905
906enum ChFi3d_SurfType { ChFiSURFACE, FACE1, FACE2 }; // for call SurfIndex(...)
907
908//=======================================================================
909//function : SurfIndex
910//purpose :
911//=======================================================================
912
913static Standard_Integer SurfIndex(const ChFiDS_StripeArray1& StripeArray1,
914 const Standard_Integer StripeIndex,
915 const Standard_Integer SurfDataIndex,
916 const ChFi3d_SurfType SurfType)
917{
918 const Handle(ChFiDS_SurfData)& aSurfData =
919 StripeArray1(StripeIndex)->SetOfSurfData()->Value(SurfDataIndex);
920 switch (SurfType) {
921 case ChFiSURFACE: return aSurfData->Surf();
922 case FACE1: return aSurfData->IndexOfS1();
923 case FACE2: return aSurfData->IndexOfS2();
924 default: return -1;
925 }
7fd59977 926}
927
928//=======================================================================
929//function : PlateOrientation
930//purpose : Define Plate orientation compared to <theRefDir> previewing
931// that Plate surface can have a sharp angle with adjacent
932// filet (bug occ266: 2 chamfs, OnSame and OnDiff) and
933// can be even twisted (grid tests cfi900 B1)
934//=======================================================================
935
936static TopAbs_Orientation PlateOrientation(const Handle(Geom_Surface)& thePlateSurf,
937 const Handle(TColGeom2d_HArray1OfCurve)& thePCArr,
938 const gp_Vec& theRefDir)
939{
940 gp_Vec du,dv;
941 gp_Pnt pp1,pp2,pp3;
942 gp_Pnt2d uv;
943 Standard_Real fpar, lpar;
944 Standard_Real SumScal1 = 0, SumScal2 = 0;
945
946 Standard_Integer i, nb = thePCArr->Upper();
947 Handle(Geom2d_Curve) aPC = thePCArr->Value(nb);
948 fpar = aPC->FirstParameter();
949 lpar = aPC->LastParameter();
950 aPC->D0( (fpar + lpar) / 2., uv);
951 thePlateSurf-> D0(uv.X(),uv.Y(),pp1);
952 aPC->D0( lpar ,uv);
953 thePlateSurf-> D0(uv.X(),uv.Y(),pp2);
954
955 for (i=1; i<=nb; i++) {
956 aPC = thePCArr->Value(i);
957 fpar = aPC->FirstParameter();
958 lpar = aPC->LastParameter();
959 aPC->D0( fpar ,uv);
960 thePlateSurf -> D1(uv.X(),uv.Y(),pp2,du,dv);
961 gp_Vec n1 = du^dv;
962 n1.Normalize();
963
964 aPC->D0( (fpar + lpar) / 2., uv);
965 thePlateSurf-> D0(uv.X(),uv.Y(),pp3);
966
967 gp_Vec vv1(pp2,pp1), vv2(pp2,pp3);
968 gp_Vec n2 = vv2^vv1;
969 n2.Normalize();
970
971 SumScal1 += n1*n2;
972 SumScal2 += n2*theRefDir;
973
974 pp1 = pp3;
975 }
976 if (SumScal2*SumScal1>0) return TopAbs_FORWARD;
977 else return TopAbs_REVERSED;
978}
979
980//=======================================================================
981//function : PerformMoreThreeCorner
81bba717 982//purpose : Process case of a top with n edges.
7fd59977 983//=======================================================================
984
985void ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
986 const Standard_Integer nconges)
987{
988// ========================================
989// Initialisations
990// ========================================
991#ifdef DEB
992 OSD_Chronometer ch;
993#endif
994 TopOpeBRepDS_DataStructure& DStr=myDS->ChangeDS();
995 const TopoDS_Vertex& V1 = myVDataMap.FindKey(Jndex);
996 Standard_Integer nedge;
997 Standard_Boolean bordlibre;
998 TopoDS_Edge edgelibre1,edgelibre2;
999// TopTools_ListIteratorOfListOfShape ItE;
1000 nedge=ChFi3d_NbNotDegeneratedEdges(V1,myVEMap);
1001 ChFi3d_ChercheBordsLibres(myVEMap,V1,bordlibre,edgelibre1,edgelibre2);
1002 Standard_Boolean droit=Standard_False;
1003 if (bordlibre) {nedge=(nedge-2)/2 +2;
1004 Standard_Real angedg=Abs(ChFi3d_AngleEdge(V1,edgelibre1,edgelibre2));
c6541a0c 1005 droit=Abs(angedg-M_PI)<0.01;
7fd59977 1006 }
1007 else nedge=nedge/2;
1008 Standard_Integer size=nedge*2;
1009 ChFiDS_StripeArray1 CD(0,size);
1010 TColStd_Array1OfInteger jf(0,size);
1011 TColStd_Array1OfInteger Index(0,size);
1012 TColStd_Array1OfInteger Indice(0,size);
1013 TColStd_Array1OfInteger sens(0,size);
1014 TColStd_Array1OfInteger indcurve3d(0,size);
1015 TColStd_Array2OfInteger numfa( 0,size,0,size);
1016 TColStd_Array1OfInteger Order( 0,size);
1017 TColStd_Array2OfInteger i(0,size,0,size);
1018 TColStd_Array2OfInteger indpoint(0,size,0,1);
1019 TColStd_Array1OfBoolean oksea(0,size);
1020 TColStd_Array1OfBoolean sharp(0,size);
1021 TColStd_Array1OfBoolean regul(0,size);
1022 TColStd_Array2OfReal p (0,size,0,size);
1023 TColStd_Array1OfReal errapp (0,size);
1024 TopTools_Array1OfShape Evive(0,size);
1025 TopTools_Array2OfShape Fvive(0,size,0,size);
1026 TColStd_Array1OfBoolean ponctuel (0,size);
1027 TColStd_Array1OfBoolean samedge (0,size);
1028 TColStd_Array1OfBoolean moresurf (0,size);
1029 TColStd_Array1OfBoolean libre(0,size);
1030 TColStd_Array1OfBoolean tangentregul (0,size);
1031 TColStd_Array1OfBoolean isG1(0,size);
1032// for(Standard_Integer ind=0;ind<=size;ind++){
1033 Standard_Integer ind;
1034 for(ind=0;ind<=size;ind++){
1035 indpoint.SetValue(ind,0,0);
1036 indpoint.SetValue(ind,1,0);
1037 Indice.SetValue(ind,0);
1038 oksea.SetValue(ind,Standard_False);
1039 sharp.SetValue(ind,Standard_False);
1040 regul.SetValue(ind,Standard_False);
1041 ponctuel.SetValue(ind,Standard_False);
1042 samedge.SetValue(ind,Standard_False);
1043 moresurf.SetValue(ind,Standard_False);
1044 libre.SetValue(ind,Standard_False);
1045 tangentregul.SetValue(ind,Standard_False);
1046 isG1.SetValue(ind,Standard_False);
1047 }
1048 ChFiDS_ListIteratorOfListOfStripe It;
1049 Handle(ChFiDS_Stripe) cd2,cdbid,cnext;
1050 TopoDS_Face face;
1d47d8d0 1051 Standard_Integer jfp = 0,ii;
7fd59977 1052 Standard_Integer ic,icplus,icmoins,icplus2,
d20d815b 1053 sense,index = 0,indice,isurf1,isurf2;
1d47d8d0 1054 Standard_Integer cbplus=0, n3d=0,IVtx = 0,nb;
7fd59977 1055 Standard_Boolean sameside,trouve,isfirst;
1056 Standard_Real pardeb ,parfin,xdir,ydir;
1d47d8d0 1057 Standard_Real tolapp=1.e-4,maxapp = 0.,maxapp1 = 0.,avedev;
7fd59977 1058 Handle (TopOpeBRepDS_CurvePointInterference) Interfp1, Interfp2;
1059 Handle (TopOpeBRepDS_SurfaceCurveInterference) Interfc;
1060 Handle(Geom_Curve) Curv3d;
1061 ChFiDS_Regul regular;
1062 TopTools_SequenceOfShape Fproj;
1063 Standard_Integer num;
1064 TopoDS_Edge Ecur;
1065 TopTools_ListIteratorOfListOfShape ItF;
1066#ifdef DEB
1067// Standard_Integer nface=ChFi3d_nbface(myVFMap(V1));
1068#endif
1069 TopoDS_Face F1,F2;
1070 gp_Vec SumFaceNormalAtV1(0,0,0); // is used to define Plate orientation
1071
81bba717 1072 // it is determined if there is a sewing edge
7fd59977 1073 Standard_Boolean couture=Standard_False;
1074 TopoDS_Face facecouture;
1075 TopoDS_Edge edgecouture;
1076 for(ItF.Initialize(myVFMap(V1));ItF.More()&&!couture;ItF.Next()) {
1077 TopoDS_Face fcur = TopoDS::Face(ItF.Value());
1078 ChFi3d_CoutureOnVertex(fcur,V1,couture,edgecouture);
1079 if (couture)
1080 facecouture=fcur;
1081 }
1082
81bba717 1083// unused surfdata are removed
7fd59977 1084 RemoveSurfData (myVDataMap, myEFMap,edgecouture,facecouture,V1);
1085
81bba717 1086 // parse edges and faces
7fd59977 1087 trouve=Standard_False;
1088 TopoDS_Edge Enext;
1089 TopoDS_Vertex VV;
1090 TopoDS_Face Fcur,Fnext;
1091 for (It.Initialize(myVDataMap(Jndex));It.More()&&!trouve;It.Next()) {
1092 cnext=It.Value();
1093 CD.SetValue(0,cnext);
1094 Index.SetValue(0,ChFi3d_IndexOfSurfData(V1,cnext,sense));
1095 sens.SetValue(0,sense);
1096 numfa.SetValue(0 ,1,SurfIndex(CD, 0, Index.Value(0), FACE2));
1097 numfa.SetValue(1 ,0, numfa.Value(0 ,1));
1098 Fcur=TopoDS::Face(DStr.Shape(numfa.Value(0,1)));
1099 Fvive.SetValue(0,1,Fcur);
1100 Fvive.SetValue(1,0,Fcur);
1101 jf.SetValue(0,2);
1102 if (sens.Value(0)==1)
1103 Ecur = CD.Value(0)->Spine()->Edges(1);
1104 else
1105 Ecur = CD.Value(0)->Spine()->Edges(CD.Value(0)->Spine()->NbEdges());
1106 Evive.SetValue(0,Ecur);
1107 ChFi3d_cherche_edge(V1,Evive,Fcur,Enext,VV);
1108 trouve= !Enext.IsNull();
1109 }
81bba717 1110 // find sum of all face normals at V1
7fd59977 1111 SummarizeNormal(V1, Fcur, Ecur, SumFaceNormalAtV1);
1112
1113 Standard_Integer nbcouture=0;
1114 for ( ii=1; ii<nedge; ii++) {
1115 if (Fcur.IsSame(facecouture)&& nbcouture==0) {
1116 Enext=edgecouture;
1117 nbcouture++;
1118 }
1119 else ChFi3d_cherche_edge(V1,Evive,Fcur,Enext,VV);
1120 if (Enext.IsNull())Standard_Failure::Raise
81bba717 1121 ("PerformMoreThreeCorner: pb in the parsing of edges and faces");
7fd59977 1122 if (Enext.IsSame(edgelibre1)|| Enext.IsSame(edgelibre2)) {
1123 CD.SetValue(ii, cdbid);
1124 Index.SetValue(ii, 0);
1125 sens.SetValue(ii, -1);
1126 TopoDS_Vertex Vref;
1127 Vref = TopExp::FirstVertex(Enext);
1128 if (Vref.IsSame(V1)) sens.SetValue(ii, 1);
1129 sharp.SetValue(ii, Standard_True);
1130 Evive.SetValue(ii, Enext);
1131 jf.SetValue(ii, 0);
1132 Indices(nedge,ii,icplus,icmoins);
1133 Fvive.SetValue(ii,icplus, Fcur);
1134 Fvive.SetValue(icplus,ii, Fcur);
1135 numfa.SetValue(ii,icplus, DStr.AddShape(Fcur));
1136 numfa.SetValue(icplus,ii,numfa.Value(ii,icplus));
1137 ii++;
1138 if (Enext.IsSame (edgelibre1)) Ecur=edgelibre2;
1139 else Ecur=edgelibre1;
1140 ChFi3d_edge_common_faces(myEFMap(Ecur),Fcur,Fcur);
1141 Indices(nedge,ii,icplus,icmoins);
1142 Fvive.SetValue(ii,icplus, Fcur);
1143 Fvive.SetValue(icplus,ii, Fcur);
1144 numfa.SetValue(ii,icplus, DStr.AddShape(Fcur));
1145 numfa.SetValue(icplus,ii,numfa.Value(ii,icplus));
1146 CD.SetValue(ii, cdbid);
1147 Index.SetValue(ii, 0);
1148 sens.SetValue(ii, -1);
1149 Vref = TopExp::FirstVertex(Ecur);
1150 if (Vref.IsSame(V1)) sens.SetValue(ii, 1);
1151 sharp.SetValue(ii, Standard_True);
1152 Evive.SetValue(ii, Ecur);
1153 jf.SetValue(ii, 0);
1154 }
1155 else {
81bba717 1156// it is found if Enext is in the map of stripes
7fd59977 1157 TopoDS_Edge EE;
1158 /*Standard_Boolean */trouve = Standard_False;
1159 for (It.Initialize(myVDataMap(Jndex));It.More()&&!trouve;It.Next()) {
1160 index = ChFi3d_IndexOfSurfData(V1,It.Value(),sense);
1161 if (sense==1)
1162 EE = It.Value()->Spine()->Edges(1);
1163 else
1164 EE = It.Value()->Spine()->Edges(It.Value()->Spine()->NbEdges());
1165 if (Enext.IsSame(EE)) {
1166 cnext=It.Value();
1167 trouve=Standard_True;
1168 }
1169 }
1170 if (trouve) {
1171 CD.SetValue(ii, cnext);
1172 Index.SetValue(ii, index);
1173 sens.SetValue(ii, sense);
1174 sharp.SetValue(ii, Standard_False);
1175 Evive.SetValue(ii, Enext);
1176 }
1177 else {
81bba717 1178 // edge ii is alive
7fd59977 1179 CD.SetValue(ii, cdbid);
1180 Index.SetValue(ii, 0);
1181 sens.SetValue(ii, -1);
1182 TopoDS_Vertex Vref;
1183 Vref = TopExp::FirstVertex(Enext);
1184 if (Vref.IsSame(V1)) sens.SetValue(ii, 1);
1185 sharp.SetValue(ii, Standard_True);
1186 Evive.SetValue(ii, Enext);
1187 jf.SetValue(ii, 0);
1188 }
81bba717 1189 // Face Fnext!=Fcur containing Enext
7fd59977 1190 Fnext=Fcur;
1191 ChFi3d_cherche_face1(myEFMap(Enext),Fcur,Fnext);
1192 Indices(nedge,ii,icplus,icmoins);
1193 Fvive.SetValue(ii,icplus, Fnext);
1194 Fvive.SetValue(icplus,ii, Fnext);
1195 numfa.SetValue(ii,icplus, DStr.AddShape(Fnext));
1196 numfa.SetValue(icplus,ii,numfa.Value(ii,icplus));
1197 Standard_Integer numface1,numface2;
1198 if (trouve) {
81bba717 1199 // it is checked if numfa corresponds to IndexOfS1 or IndexOfS2
1200 // jf is updated is consequently updated
1201 // if it is not the case among the previous faces are found
1202 // those which correspond to IndexOfs1 IndexOfS2 and
1203 // numfa and Fvive are reupdated (cts16288)
7fd59977 1204 numface2 = SurfIndex(CD, ii, Index.Value(ii), FACE2);
1205 if (numface2==numfa.Value(ii,icplus))
1206 jf.SetValue(ii, 2);
1207 else {
1208 numface1 = SurfIndex(CD, ii, Index.Value(ii), FACE1);
1209 if (numface1==numfa.Value(ii,icplus))
1210 jf.SetValue(ii, 1);
1211 else {
1212 if (numface1==numfa.Value(icmoins,ii)) {
1213 jf.SetValue(ii, 2);
1214 Fvive.SetValue(ii,icplus,TopoDS::Face(DStr.Shape(numface2)));
1215 Fvive.SetValue(icplus,ii,TopoDS::Face(DStr.Shape(numface2)));
1216 numfa.SetValue(ii,icplus, DStr.AddShape(TopoDS::Face(DStr.Shape(numface2))));
1217 numfa.SetValue(icplus,ii, numfa.Value (ii,icplus));
1218 }
1219 if (numface2==numfa.Value(icmoins,ii)) {
1220 jf.SetValue(ii, 1);
1221 Fvive.SetValue(ii,icplus,TopoDS::Face(DStr.Shape(numface1)));
1222 Fvive.SetValue(icplus,ii,TopoDS::Face(DStr.Shape(numface1)));
1223 numfa.SetValue(ii,icplus, DStr.AddShape(TopoDS::Face(DStr.Shape(numface1))));
1224 numfa.SetValue(icplus,ii, numfa.Value (ii,icplus));
1225 }
1226 }
1227 }
1228 }
1229 Ecur = Enext;
1230 Fcur = Fnext;
1231 // find sum of all face normales at V1
1232 SummarizeNormal(V1, Fcur, Ecur, SumFaceNormalAtV1);
1233 }
1234 }
1235 // mise a jour du tableau regul
1236 for (ic=0;ic<nedge;ic++) {
1237 if (sharp.Value(ic)) {
1238 Ecur=TopoDS::Edge(Evive.Value(ic));
1239 if (!Ecur.IsSame(edgecouture)) {
1240 ChFi3d_edge_common_faces(myEFMap(Ecur),F1,F2);
1241// Modified by Sergey KHROMOV - Fri Dec 21 18:11:02 2001 Begin
1242// regul.SetValue(ic,BRep_Tool::Continuity(TopoDS::Edge(Evive.Value(ic)),F1,F2)
1243// !=GeomAbs_C0);
1244 regul.SetValue(ic,isTangentFaces(TopoDS::Edge(Evive.Value(ic)),F1,F2));
1245// Modified by Sergey KHROMOV - Fri Dec 21 18:11:07 2001 End
1246 }
1247 }
1248 }
81bba717 1249 // it is checked if a regular edge is not tangent to another edge
1250 // in case if it is not considered regular (cts60072)
7fd59977 1251 for (ic=0;ic<nedge;ic++) {
1252 if (regul.Value(ic) ) {
1253 trouve=Standard_False;
1254 TopoDS_Edge ereg=TopoDS::Edge(Evive.Value(ic));
1255 for( ind=0;ind<nedge &&!trouve;ind++) {
1256 if (ind!=ic) {
1257 TopoDS_Edge ecur=TopoDS::Edge(Evive.Value(ind));
1258 Standard_Real ang=Abs(ChFi3d_AngleEdge(V1,ecur,ereg));
c6541a0c 1259 if (ang<0.01 || Abs(ang-M_PI) <0.01) {
7fd59977 1260 regul.SetValue(ic,Standard_False);
1261 tangentregul.SetValue(ic,Standard_True);
1262 trouve=Standard_True;
1263 }
1264 }
1265 }
1266 }
1267 }
1268
81bba717 1269 // variable deuxconges allows detecting cases when there is a top with
1270 // n edges and two fillets on two tangent edges that are not free borders
1271 // the connecting curves start from the fillet and end on top
7fd59977 1272
1273 Standard_Boolean deuxconges,deuxcgnontg;
1274 deuxconges=Standard_False;
1275 trouve=Standard_False;
1276 if (nconges==2) {
1277 TopoDS_Edge E1,E2;
1278 for (ic=0;ic<nedge&&!trouve;ic++) {
1279 Indices(nedge,ic,icplus,icmoins);
1280 if (!sharp.Value(ic) && !sharp.Value(icplus)){
1281 E1=TopoDS::Edge(Evive.Value(ic));
1282 E2=TopoDS::Edge(Evive.Value(icplus));
1283 deuxconges=(Abs(ChFi3d_AngleEdge(V1 ,E1,E2) )<0.01) ;
1284 trouve=deuxconges;
1285 }
1286 }
1287 }
1288
81bba717 1289 // variable deuxconges is used in the special case when there are
1290 // two fillets and if two other living edges are tangent (cts60072)
7fd59977 1291 if (nconges==2 && nedge==4) {
1292 TopoDS_Edge E1,E2;
1293 for (ic=0;ic<nedge&&!deuxconges;ic++) {
1294 Indices(nedge,ic,icplus,icmoins);
1295 if (sharp.Value(ic) && sharp.Value(icplus)){
1296 E1=TopoDS::Edge(Evive.Value(ic));
1297 E2=TopoDS::Edge(Evive.Value(icplus));
1298 if ( !E1.IsSame(edgelibre1) && !E1.IsSame(edgelibre2) &&
1299 !E2.IsSame(edgelibre1) && !E2.IsSame(edgelibre2)){
1300 Standard_Real ang=Abs(ChFi3d_AngleEdge(V1 ,E1,E2));
c6541a0c 1301 deuxconges=(ang<0.01 || Abs(ang-M_PI)<0.01);
7fd59977 1302 }
1303 }
1304 }
1305 }
1306
1307 deuxcgnontg=nconges==2&& nedge==3 && !deuxconges; // pro12305
1308
1309 if (deuxconges )
1310 for (ic=0;ic<nedge;ic++){
1311 regul.SetValue(ic,Standard_False);
1312 }
1313
1314 // Detect case of 3 edges & 2 conges: OnSame + OnDiff
1315 // (eap, Arp 9 2002, occ266)
1316 Standard_Boolean isOnSameDiff = Standard_False;
1317 if (deuxcgnontg) {
1318 Standard_Boolean isOnSame = Standard_False, isOnDiff = Standard_False;
1319 for (ic=0; ic<nedge; ic++) {
1320 if (sharp.Value(ic)) continue;
1321 ChFiDS_State stat;
1322 if ( sens(ic) == 1 )
1323 stat = CD.Value(ic)->Spine()->FirstStatus();
1324 else
1325 stat = CD.Value(ic)->Spine()->LastStatus();
1326
1327 if (stat == ChFiDS_OnSame) isOnSame = Standard_True;
1328 else if (stat == ChFiDS_OnDiff) isOnDiff = Standard_True;
1329 }
1330 isOnSameDiff = isOnSame && isOnDiff;
1331 }
1332 if ( isOnSameDiff ) {
1333#ifdef DEB
1334 cout << "OnSame + OnDiff, PerformMoreThreeCorner() calls PerformOneCorner()" << endl;
1335#endif
1336 PerformOneCorner (Jndex, Standard_True);
1337 }
1338
81bba717 1339// if the commonpoint is on an edge that does not have a
1340// vertex at the extremity, Evive is found anew
1341// Fvive is found anew if it does not correspond
1342// to two faces adjacent to Evive (cts16288)
7fd59977 1343
1344 if (!deuxconges && !isOnSameDiff)
1345 for (ic=0;ic<nedge;ic++) {
1346 if (sharp.Value(ic)) {
1347 Indices(nedge,ic,icplus,icmoins);
1348 TopoDS_Edge Arc=TopoDS::Edge(Evive.Value(ic));
1349 ChFiDS_CommonPoint cp1, cp2;
c6541a0c 1350 Standard_Real angedg=M_PI;
7fd59977 1351 TopoDS_Vertex Vcom;
1352 if (!sharp.Value(icplus)) {
1353 isfirst=(sens.Value(icplus)==1);
1354 jfp = 3 - jf.Value(icplus);
1355 cp1 = CD.Value(icplus)->SetOfSurfData()->Value(Index.Value(icplus))->
1356 ChangeVertex (isfirst,jfp);
1357 if (cp1.IsOnArc()){
1358 ChFi3d_cherche_vertex(Arc,cp1.Arc(),Vcom,trouve);
1359 if (trouve) angedg=Abs(ChFi3d_AngleEdge(Vcom,Arc,cp1.Arc()));
c6541a0c 1360 if (!cp1.Arc().IsSame(Arc) && Abs(angedg-M_PI)<0.01){
7fd59977 1361 Evive.SetValue(ic,cp1.Arc());
1362 ChFi3d_edge_common_faces(myEFMap(cp1.Arc()),F1,F2);
1363 if (!Fvive.Value(ic,icplus).IsSame(F1) && !Fvive.Value(ic,icplus).IsSame(F2)) {
1364 if (Fvive.Value(ic,icmoins).IsSame(F2)) {
1365 Fvive.SetValue(ic,icplus,F1);
1366 Fvive.SetValue(icplus,ic,F1);
1367 numfa.SetValue(ic,icplus,DStr.AddShape(F1));
1368 numfa.SetValue(icplus,ic,DStr.AddShape(F1));
1369 }
1370 else {
1371 Fvive.SetValue(ic,icplus,F2);
1372 Fvive.SetValue(icplus,ic,F2);
1373 numfa.SetValue(ic,icplus,DStr.AddShape(F2));
1374 numfa.SetValue(icplus,ic,DStr.AddShape(F2));
1375 }
1376 }
1377 samedge.SetValue(ic,Standard_True);
1378 p.SetValue(ic,icplus,cp1.ParameterOnArc());
1379 p.SetValue(ic,icmoins,cp1.ParameterOnArc());
1380 i.SetValue(ic,icplus,1);
1381 }
1382 }
1383 }
1384 if (!sharp.Value(icmoins)) {
1385 isfirst=(sens.Value(icmoins)==1);
1386 cp2 = CD.Value(icmoins)->SetOfSurfData()->Value(Index.Value(icmoins))->
1387 ChangeVertex (isfirst,jf.Value(icmoins));
1388 if (cp2.IsOnArc()) {
c6541a0c 1389 angedg=M_PI;
7fd59977 1390 ChFi3d_cherche_vertex(Arc,cp2.Arc(),Vcom,trouve);
1391 if (trouve) angedg=Abs(ChFi3d_AngleEdge(Vcom,Arc,cp2.Arc()));
c6541a0c 1392 if (!cp2.Arc().IsSame(Arc)&&Abs(angedg-M_PI)<0.01) {
7fd59977 1393 Evive.SetValue(ic,cp2.Arc());
1394 ChFi3d_edge_common_faces(myEFMap(cp2.Arc()),F1,F2);
1395 if (!Fvive.Value(ic,icmoins).IsSame(F1) && !Fvive.Value(ic,icmoins).IsSame(F2)) {
1396 if (Fvive.Value(ic,icplus).IsSame(F2)) {
1397 Fvive.SetValue(ic,icmoins,F1);
1398 numfa.SetValue(ic,icmoins,DStr.AddShape(F1));
1399 Fvive.SetValue(icmoins,ic,F1);
1400 numfa.SetValue(icmoins,ic,DStr.AddShape(F1));
1401 }
1402 else {
1403 Fvive.SetValue(ic,icmoins,F2);
1404 numfa.SetValue(ic,icmoins,DStr.AddShape(F2));
1405 Fvive.SetValue(icmoins,ic,F2);
1406 numfa.SetValue(icmoins,ic,DStr.AddShape(F2));
1407 }
1408 }
1409 samedge.SetValue(ic,Standard_True);
1410 p.SetValue(ic,icmoins,cp2.ParameterOnArc());
1411 p.SetValue(ic,icplus,cp2.ParameterOnArc());
1412 i.SetValue(ic,icmoins,1);
1413 }
1414 }
1415 }
1416 }
1417 }
1418
81bba717 1419// the first free edge is restored if it exists
7fd59977 1420 trouve=Standard_False;
1421 for (ic=0; ic<nedge&&!trouve;ic++) {
1422 TopoDS_Edge ecom;
1423 ecom=TopoDS::Edge(Evive.Value(ic));
1424 if (ecom.IsSame(edgelibre1)||ecom.IsSame(edgelibre2)){
1425 libre.SetValue(ic,Standard_True);
1426 trouve=Standard_True;
1427 }
1428 }
1429
81bba717 1430// determine the minimum recoil distance that can't be exceeded
7fd59977 1431 Standard_Boolean distmini=Standard_False;
1432 gp_Pnt som=BRep_Tool::Pnt(V1),pic;
1433 gp_Pnt2d p2;
1434 TopoDS_Edge edgemin;
1435 TopoDS_Vertex V,V2;
1436 Standard_Real dst,distmin;
1437 distmin=1.e30;
1438 for (ic=0;ic<nedge;ic++) {
1439 if (sharp.Value(ic))
1440 edgemin=TopoDS::Edge(Evive.Value(ic));
1441 else {
1442 if (sens.Value(ic)==1)
1443 edgemin= CD.Value(ic)->Spine()->Edges(1);
1444 else
1445 edgemin = CD.Value(ic)->Spine()->Edges(CD.Value(ic)->Spine()->NbEdges());
1446 }
1447 V=TopExp::FirstVertex(edgemin);
1448 V2=TopExp::LastVertex(edgemin);
1449 dst=(BRep_Tool::Pnt(V)).Distance(BRep_Tool::Pnt(V2))/1.5;
1450 if (dst<distmin) distmin=dst;
1451 }
1452
81bba717 1453// calculate intersections between stripes and determine the parameters on each pcurve
7fd59977 1454 Standard_Boolean inters=Standard_True;
1455 for (ic=0;ic<nedge;ic++) {
1456 Indices(nedge,ic,icplus,icmoins);
1457 if (sharp.Value(ic)||sharp.Value(icplus)) {
1458 oksea.SetValue(ic, Standard_False);
1459 }
1460 else {
1d47d8d0 1461 Standard_Integer jf1 = 0;
1462 Standard_Integer i1 = 0,i2 = 0;
1463 Standard_Real pa1 = 0.,pa2;
7fd59977 1464 Standard_Boolean ok;
1465 Handle(ChFiDS_Stripe) strip;
1466 Standard_Real angedg;
1467 Standard_Integer iface;
81bba717 1468 // if two edges are tangent the intersection is not attempted (cts60046)
7fd59977 1469 angedg=Abs(ChFi3d_AngleEdge(V1,TopoDS::Edge(Evive.Value(ic)),TopoDS::Edge(Evive.Value(icplus))));
c6541a0c 1470 if (Abs(angedg-M_PI)>0.01)
7fd59977 1471 ok = ChFi3d_SearchFD(DStr,CD.Value(ic),CD.Value(icplus),sens.Value(ic),sens.Value(icplus),
1472 i1,i2,pa1,pa2,
1473 Index.Value(ic),Index.Value(icplus),
1474 face,sameside,jf1,jfp);
1475 else ok=Standard_False;
81bba717 1476 // if there is an intersection it is checked if surfdata with the intersection
1477 // corresponds to the first or the last
1478 // if this is not the case, the surfdata are removed from SD
7fd59977 1479
1480 if (ok) {
1481 if (i1!=Index.Value(ic) ){
1482 Standard_Integer ideb,ifin;
1483 strip=CD.Value(ic);
1484 if (sens.Value(ic)==1) {
1485 ideb=Index.Value(ic);
1486 ifin=i1-1;
1487 }
1488 else {
1489 ifin=Index.Value(ic);
1490 ideb=i1+1;
1491 }
1492 if (i1<Index.Value(ic)) {
1493 for (nb=Index.Value(ic);nb>=i1;nb--) {
1494 if ((3-jf1)==1)
1495 iface=SurfIndex(CD, ic, nb , FACE1);
1496 else iface=SurfIndex(CD, ic, nb , FACE2);
1497 Fproj.Append(TopoDS::Face(myDS->Shape(iface)));
1498 }
1499 }
1500 if (i1>Index.Value(ic)) {
1501 for (nb=Index.Value(ic);nb<=i1;nb++) {
1502 if ((3-jf1)==1)
1503 iface=SurfIndex(CD, ic, nb , FACE1);
1504 else iface=SurfIndex(CD, ic, nb , FACE2);
1505 Fproj.Append(TopoDS::Face(myDS->Shape(iface)));
1506 }
1507 }
1508 strip=CD.Value(ic);
1509 RemoveSD(strip,ideb,ifin);
1510 num=ChFi3d_IndexOfSurfData(V1,CD.Value(ic),sense);
1511 Index.SetValue(ic,num);
1512 i1=num;
1513 }
1514 if (i2!=Index.Value(icplus) ){
1515 Standard_Integer ideb,ifin;
1516 strip=CD.Value(icplus);
1517 if (sens.Value(icplus)==1) {
1518 ideb=Index.Value(icplus);
1519 ifin=i2-1;
1520 }
1521 else {
1522 ifin=Index.Value(icplus);
1523 ideb=i2+1;
1524 }
1525
1526 if (i2<Index.Value(icplus)) {
1527 for (nb=i2;nb<=Index.Value(icplus);nb++) {
1528 if ((3-jfp)==1)
1529 iface=SurfIndex(CD, icplus, nb , FACE1);
1530 else iface=SurfIndex(CD, icplus, nb , FACE2);
1531 Fproj.Append(TopoDS::Face(myDS->Shape(iface)));
1532 }
1533 }
1534 if (i2>Index.Value(icplus)) {
1535 for (nb=i2;nb>=Index.Value(icplus);nb--) {
1536 if ((3-jfp)==1)
1537 iface=SurfIndex(CD, icplus, nb , FACE1);
1538 else iface=SurfIndex(CD, icplus, nb , FACE2);
1539 Fproj.Append(TopoDS::Face(myDS->Shape(iface)));
1540 }
1541 }
1542 RemoveSD(strip,ideb,ifin);
1543 num=ChFi3d_IndexOfSurfData(V1,CD.Value(icplus),sense);
1544 Index.SetValue(icplus,num);
1545 i2=num;
1546 }
1547 Calcul_P2dOnSurf(CD.Value(ic),jf1,i1,pa1,p2);
1548 indice=SurfIndex(CD, ic, i1, ChFiSURFACE);
1549 DStr.Surface(indice).Surface()->D0(p2.X(),p2.Y(),pic);
1550 if (pic.Distance(som)>distmin) distmini =Standard_True;
1551 jf.SetValue(ic,jf1);
1552 i.SetValue(ic,icplus,i1);
1553 i.SetValue(icplus,ic,i2);
1554 p.SetValue(ic,icplus,pa1);
1555 p.SetValue(icplus,ic,pa2);
1556 }
1557 oksea.SetValue(ic, ok);
1558 }
1559 if (!oksea.Value(ic) ) inters=Standard_False;
1560 }
1561
81bba717 1562 // case if there are only intersections
1563 // the parametres on Pcurves are the extremities of the stripe
7fd59977 1564 Standard_Real para;
1565 if (!inters) {
1566 for (ic=0;ic<nedge;ic++) {
1567 Indices(nedge,ic,icplus,icmoins);
1568 Indices(nedge,icplus,icplus2,ic);
1569 if (!oksea.Value(ic)) {
1570 cbplus++;
1571 if (sharp.Value(ic)) {
1572 if (!samedge.Value(ic)){
1573 para=BRep_Tool::Parameter(V1,TopoDS::Edge(Evive.Value(ic)));
1574 p.SetValue(ic,icplus,para);
1575 i.SetValue(ic,icplus,1);
1576 }
1577 }
1578 else {
1579 isfirst= (sens.Value(ic)==1);
1580 i.SetValue(ic,icplus,ChFi3d_IndexOfSurfData(V1,CD.Value(ic),sense));
1581 if (oksea.Value(icmoins)) {
1582 para=p.Value(ic,icmoins);
1583 p.SetValue(ic,icplus,para);
1584 }
1585 else {
1586 Calcul_Param(CD.Value(ic),jf.Value(ic),i.Value(ic,icplus),isfirst,para);
1587 p.SetValue(ic,icplus,para);
1588 }
1589 }
1590 if (sharp.Value(icplus)) {
1591 if (!samedge.Value(icplus)) {
1592 para=BRep_Tool::Parameter(V1,TopoDS::Edge(Evive.Value(icplus)));
1593 p.SetValue(icplus,ic, para);
1594 i.SetValue(icplus,ic,1);
1595 }
1596 }
1597 else {
1598 isfirst= (sens.Value(icplus)==1);
1599 i.SetValue(icplus,ic,ChFi3d_IndexOfSurfData(V1,CD.Value(icplus),sense));
1600 if (oksea.Value(icplus)){
1601 para=p.Value(icplus,icplus2);
1602 p.SetValue(icplus,ic,para);
1603 }
1604 else {
1605 jfp = 3 - jf.Value(icplus);
1606 Calcul_Param(CD.Value(icplus),jfp,i.Value(icplus,ic),isfirst,para);
1607 p.SetValue(icplus,ic,para);
1608 }
1609 }
1610 }
1611 }
1612
81bba717 1613// calculate max distance to the top at each point
7fd59977 1614 TColStd_Array1OfReal dist1(0,size);
1615 TColStd_Array1OfReal dist2(0,size);
1616 Standard_Real distance=0.;
1617 gp_Pnt sommet=BRep_Tool::Pnt(V1);
1618 if (!deuxconges)
1619 for (ic=0;ic<nedge;ic++) {
1620 Indices(nedge,ic,icplus,icmoins);
1621 if (sharp.Value(ic)) {
1622 dist1.SetValue(ic, 0);
1623 dist2.SetValue(ic, 0);
1624 }
1625 else {
1626 jfp = 3 - jf.Value(ic);
1627 Calcul_P2dOnSurf(CD.Value(ic),jfp,i.Value(ic,icmoins),p.Value(ic,icmoins),p2);
1628 indice=SurfIndex(CD, ic, i.Value(ic,icmoins), ChFiSURFACE);
1629 DStr.Surface(indice).Surface()->D0(p2.X(),p2.Y(),pic);
1630 dist1.SetValue(ic, sommet.Distance(pic));
1631 if (dist1.Value(ic) > distance ) distance= dist1.Value(ic);
1632
1633 Calcul_P2dOnSurf(CD.Value(ic),jf.Value(ic),i.Value(ic,icplus),p.Value(ic,icplus),p2);
1634 indice=SurfIndex(CD, ic, i.Value(ic,icplus), ChFiSURFACE);
1635 DStr.Surface(indice).Surface()->D0(p2.X(),p2.Y(),pic);
1636 dist2.SetValue(ic, sommet.Distance(pic));
1637 if( dist2.Value(ic) > distance )
1638 distance= dist2.Value(ic);
1639 }
1640 }
1641
81bba717 1642// offset of parameters and removal of intersection points
1643// too close to the top
7fd59977 1644
1645 Standard_Real ec, dist;
1646 if (!deuxconges && !deuxcgnontg)
1647 for (ic=0;ic<nedge;ic++) {
1648 Indices(nedge,ic,icplus,icmoins);
1649 if (sharp.Value(ic) ) {
1650 BRepAdaptor_Curve C(TopoDS::Edge(Evive.Value(ic)));
81bba717 1651 // to pass from 3D distance to a parametric distance
7fd59977 1652 if (!tangentregul(ic))
1653 ec = distance*100*C.Resolution(0.01);
1654 else ec=0.0;
1655 if (TopExp::FirstVertex(TopoDS::Edge(Evive.Value(ic))).IsSame(V1)) {
1656 para=p.Value(ic,icmoins) + ec;
1657 p.SetValue(ic,icmoins, para);
1658 }
1659 else {
1660 para=p.Value(ic,icmoins) - ec;
1661 p.SetValue(ic,icmoins,para);
1662 }
81bba717 1663// it is necessary to be on to remain on the edge
7fd59977 1664 p.SetValue(ic,icplus, p.Value(ic,icmoins));
1665 }
1666 else if (!distmini) {
1667 dist = dist1.Value(ic);
1668 if ((!oksea.Value(icmoins))||(oksea.Value(icmoins)&&(distance>1.3*dist))) {
1669 ec= distance-dist;
1670 if (oksea.Value(icmoins)) {
1671 oksea.SetValue(icmoins,Standard_False);
1672 inters=Standard_False;
1673 cbplus++;
1674 }
1675 if (sens.Value(ic)==1) {
1676 para=p.Value(ic,icmoins) + ec;
1677 p.SetValue(ic,icmoins, para);
1678 }
1679 else{
1680 para=p.Value(ic,icmoins) - ec;
1681 p.SetValue(ic,icmoins,para);
1682 }
1683 }
1684 dist = dist2.Value(ic);
1685 if ((!oksea.Value(ic))||(oksea.Value(ic)&&(distance>1.3*dist))) {
1686 if(oksea.Value(ic)) {
1687 oksea.SetValue(ic,Standard_False);
1688 inters=Standard_False;
1689 cbplus++;
1690 }
1691 if (nconges!=1) {
1692 Standard_Real parold,parnew;
1693 parold=p.Value(ic,icplus);
1694 parnew=p.Value(ic,icmoins);
1695 if (sens.Value(ic)==1) {
1696 if (parnew> parold) p.SetValue(ic,icplus, p.Value(ic,icmoins));
1697 }
1698 else {
1699 if (parnew<parold) p.SetValue(ic,icplus, p.Value(ic,icmoins));
1700 }
1701 }
1702 }
1703 }
1704 }
1705 }
1706
81bba717 1707// it is attempted to limit the edge by a commonpoint
7fd59977 1708//
1709
1710 Standard_Real tolcp=0;
1711 gp_Pnt PE, sommet=BRep_Tool::Pnt(V1);
1712 if (!deuxconges)
1713 for (ic=0;ic<nedge;ic++) {
1714 if (sharp.Value(ic)) {
1715 Indices(nedge,ic,icplus,icmoins);
1716 BRepAdaptor_Curve C(TopoDS::Edge(Evive.Value(ic)));
1717 PE = C.Value(p.Value(ic,icplus));
1718 Standard_Real d1=0., d2=0., dS = PE.Distance(sommet);
1719 ChFiDS_CommonPoint cp1, cp2;
1720 if (!sharp.Value(icplus)) {
1721 isfirst=(sens.Value(icplus)==1);
1722 jfp = 3 - jf.Value(icplus);
1723 cp1 = CD.Value(icplus)->SetOfSurfData()->Value(i.Value(icplus,ic))->
1724 ChangeVertex (isfirst,jfp);
1725 d1 = cp1.Point().Distance(sommet);
1726 }
1727 if (!sharp.Value(icmoins)) {
1728 isfirst=(sens.Value(icmoins)==1);
1729 cp2 = CD.Value(icmoins)->SetOfSurfData()->Value(i.Value(icmoins,ic))->
1730 ChangeVertex (isfirst,jf.Value(icmoins));
1731 d2 = cp2.Point().Distance(sommet);
1732 }
1733 Standard_Boolean samecompoint=Standard_False;
1734 if (!sharp.Value(icmoins) && !sharp.Value(icplus))
1735 samecompoint=cp1.Point().Distance(cp2.Point())<tolapp;
1736 if ((dS<d1 || dS<d2)&& !samecompoint) {
81bba717 1737// step back till Common Points
1738// without leaving the Edge ??
7fd59977 1739 if (d2<d1 &&cp1.IsOnArc() ) {
81bba717 1740// cp1 is chosen
7fd59977 1741 p.SetValue(ic,icmoins, cp1.ParameterOnArc());
1742 p.SetValue(ic,icplus, p.Value(ic,icmoins));
1743 isfirst=(sens.Value(icplus)==1);
1744 jfp = 3 - jf.Value(icplus);
1745 Calcul_Param(CD.Value(icplus),jfp,i.Value(icplus,ic),isfirst,para);
1746 p.SetValue(icplus,ic,para);
1747 if (cp1.Tolerance()>tolcp &&cp1.Tolerance()<1 ) tolcp=cp1.Tolerance();
1748 }
1749 else if( cp2.IsOnArc()){
81bba717 1750// cp2 is chosen
7fd59977 1751 p.SetValue(ic,icmoins, cp2.ParameterOnArc());
1752 p.SetValue(ic,icplus, p.Value(ic,icmoins));
1753 isfirst=(sens.Value(icmoins)==1);
1754 Calcul_Param(CD.Value(icmoins),jf.Value(icmoins),i.Value(icmoins,ic),isfirst, para);
1755 p.SetValue(icmoins,ic,para);
1756 if (cp2.Tolerance()>tolcp&&cp2.Tolerance()<1) tolcp=cp2.Tolerance();
1757 }
1758 }
1759 else {
81bba717 1760// step back till Common Point only if it is very close
7fd59977 1761 if (!sharp.Value(icplus)) {
1762 if ((cp1.Point().Distance(PE)<cp1.Tolerance() ||
1763 samecompoint || nconges==1) && cp1.IsOnArc()) {
81bba717 1764// it is very close to cp1
7fd59977 1765 p.SetValue(ic,icmoins, cp1.ParameterOnArc());
1766 ponctuel.SetValue(ic,Standard_True);
1767 p.SetValue(ic,icplus, p.Value(ic,icmoins));
1768 isfirst=(sens.Value(icplus)==1);
1769 jfp = 3 - jf.Value(icplus);
1770 Calcul_Param(CD.Value(icplus),jfp,i.Value(icplus,ic),isfirst,para);
1771 p.SetValue(icplus,ic,para);
1772 if (cp1.Tolerance()>tolcp &&cp1.Tolerance()<1) tolcp=cp1.Tolerance();
1773 }
1774 }
1775 if (!sharp.Value(icmoins)){
1776 if ((cp2.Point().Distance(PE)<cp2.Tolerance() ||
1777 samecompoint || nconges==1) && cp2.IsOnArc()) {
81bba717 1778// it is very close to cp2
7fd59977 1779 ponctuel.SetValue(icmoins,Standard_True);
1780 p.SetValue(ic,icmoins, cp2.ParameterOnArc());
1781 p.SetValue(ic,icplus,p.Value(ic,icmoins));
1782 isfirst=(sens.Value(icmoins)==1);
1783 Calcul_Param(CD.Value(icmoins),jf.Value(icmoins),i.Value(icmoins,ic),isfirst,para);
1784 p.SetValue(icmoins,ic,para);
1785 if (cp2.Tolerance()>tolcp&&cp2.Tolerance()<1 ) tolcp=cp2.Tolerance();
1786 }
1787 }
1788 }
1789 }
1790 }
1791
81bba717 1792// in case of a free border the parameter corresponding
1793// to the common point on the free edge is chosen.
7fd59977 1794
1795 for (ic=0;ic<nedge;ic++) {
1796 if (TopoDS::Edge(Evive.Value(ic)).IsSame(edgelibre1) ||
1797 TopoDS::Edge(Evive.Value(ic)).IsSame(edgelibre2)) {
1798 Standard_Integer indic;
1799 ChFiDS_CommonPoint CP1;
1800 Indices(nedge,ic,icplus,icmoins);
1801 if (libre.Value(ic))indic=icmoins;
1802 else indic=icplus;
1803 if (!sharp(indic)) {
1804 isfirst=sens.Value(indic)==1;
1805 CP1 = CD.Value(indic)->SetOfSurfData()->Value(Index.Value(indic))->ChangeVertex(isfirst,1);
1806 /*Standard_Boolean*/ trouve=Standard_False;
1807 if (CP1.IsOnArc()) {
1808 if(CP1.Arc().IsSame(TopoDS::Edge(Evive.Value(ic)))) {
1809 p.SetValue(ic,icmoins,CP1.ParameterOnArc());
1810 p.SetValue(ic,icplus,CP1.ParameterOnArc());
1811 trouve=Standard_True;
1812 }
1813 }
1814 if (!trouve) {
1815 CP1 = CD.Value(indic)->SetOfSurfData()->Value(Index.Value(indic))->ChangeVertex(isfirst,2);
1816 if (CP1.IsOnArc()) {
1817 if(CP1.Arc().IsSame(TopoDS::Edge(Evive.Value(ic)))) {
1818 p.SetValue(ic,icmoins,CP1.ParameterOnArc());
1819 p.SetValue(ic,icplus,CP1.ParameterOnArc());
1820 }
1821 }
1822 }
1823 }
1824 }
1825 }
1826
81bba717 1827// if ic is a regular edge, one finds edge indfin which is not
1828// a regular edge, and construtc a curve 3d
1829// between edges (or stripes ) icmoins and indfin.
1830// Then this courbe3d is projected on all faces (nbface) that
1831// separate icmoins and indfin
7fd59977 1832 Standard_Integer nbface = 0;
1d47d8d0 1833 Standard_Real error = 0.;
7fd59977 1834 TColGeom2d_Array1OfCurve proj2d1(0,size);
1835 TColGeom2d_Array1OfCurve proj2d2(0,size);
1836 TColGeom_Array1OfCurve cproj1(0,size);
1837 TColGeom_Array1OfCurve cproj2(0,size);
1838 if (!deuxconges)
1839 for (ic=0;ic<nedge;ic++) {
1840 Standard_Integer ilin;
1841 TColGeom_SequenceOfCurve cr;
1842 TColGeom2d_SequenceOfCurve pr;
1843 TopTools_SequenceOfShape Lface;
1844 TopTools_SequenceOfShape Ledge;
1845 Lface.Clear();
1846 if (regul.Value(ic)){
1847 Indices(nedge,ic,icplus,icmoins);
1848 Indices(nedge,icplus,icplus2,ic);
1849 Standard_Integer indfin,indfinmoins,indfinplus;
1850 indfin=icplus;
1851 trouve=Standard_False;
1852 ii=icplus;
1853 while (!trouve) {
1854 if (!regul.Value(ii)) {
1855 indfin=ii;
1856 trouve=Standard_True;
1857 }
1858 if (ii==nedge-1) ii=0;
1859 else ii++;
1860 }
1861 Indices(nedge,indfin,indfinplus,indfinmoins);
1862 if (!sharp.Value(icmoins)){
1863 if( jf.Value(icmoins)==1)
1864 ilin= SurfIndex(CD, icmoins, i.Value(icmoins,ic), FACE1);
1865 else
1866 ilin= SurfIndex(CD, icmoins, i.Value(icmoins,ic), FACE2);
1867 Lface.Append(TopoDS::Face(DStr.Shape(ilin)));
1868 }
1869 else Lface.Append( Fvive(ic,icmoins));
1870 if (indfin>icmoins)
1871 nbface=indfin-icmoins;
1872 else nbface =nedge-(icmoins-indfin);
1873 TopTools_SequenceOfShape Epj;
1874 TColStd_SequenceOfReal seqpr;
1875 ii=ic;
1876 for (Standard_Integer nf=1;nf<=nbface-1;nf++) {
1877 Standard_Integer iimoins,iiplus;
1878 Indices(nedge,ii,iiplus,iimoins);
1879 Ledge.Append(TopoDS::Edge(Evive.Value(ii)));
1880 seqpr.Append(p.Value(ii,iiplus));
1881 if (nf!=nbface-1) Lface.Append( Fvive(ii,iiplus));
1882 if (ii==nedge-1) ii=0;
1883 else ii++;
1884 }
1885 if (!sharp.Value(indfin) ){
1886 jfp=3-jf.Value(indfin);
1887 if (jfp==1)
1888 ilin= SurfIndex(CD, indfin, i.Value(indfin,indfinmoins), FACE1);
1889 else ilin=SurfIndex(CD, indfin, i.Value(indfin,indfinmoins), FACE2);
1890 Lface.Append(TopoDS::Face(DStr.Shape(ilin)));
1891 }
1892 else Lface.Append(Fvive(indfin,indfinmoins));
1893 CurveHermite(DStr,CD.Value(icmoins),jf.Value(icmoins),i.Value(icmoins,ic),
1894 p.Value(icmoins,ic),sens.Value(icmoins),sharp.Value(icmoins),
1895 TopoDS::Edge(Evive.Value(icmoins)),CD.Value(indfin),jf.Value(indfin),
1896 i.Value(indfin,indfinmoins),p.Value(indfin,indfinmoins),sens.Value(indfin),
1897 sharp.Value(indfin),TopoDS::Edge(Evive.Value(indfin)),nbface,Ledge,
1898 Lface,pr,cr,Epj,seqpr,error);
1899 ii=ic;
1900 for (ind=1;ind<=nbface-1;ind++) {
1901 Standard_Integer iimoins,iiplus;
1902 Indices(nedge,ii,iiplus,iimoins);
1903 p.SetValue(ii,iiplus,seqpr.Value(ind));
1904 p.SetValue(ii,iimoins,seqpr.Value(ind));
1905 proj2d1.SetValue(ii,pr.Value(ind));
1906 proj2d2.SetValue(ii,pr.Value(ind+1));
1907 cproj1.SetValue(ii,cr.Value(ind));
1908 cproj2.SetValue(ii,cr.Value(ind+1));
1909 if (ii==nedge-1) ii=0;
1910 else ii++;
1911 }
1912 if (!sharp.Value(icmoins)&&!sharp.Value(indfin)) {
1913 ii=icmoins;
1914 while (ii!=indfin) {
1915 isG1.SetValue(ii,Standard_True);
1916 if (ii==nedge-1) ii=0;
1917 else ii++;
1918 }
1919 }
1920 ic=ic+nbface-1;
1921 }
1922 }
1923
81bba717 1924 // case when the conncting curve between ic and icplus crosses many faces
7fd59977 1925
1926 TopTools_SequenceOfShape Ecom;
1927 TopTools_SequenceOfShape Eproj;
1928 TColStd_SequenceOfReal parcom;
1929 if (!deuxconges)
1930 for (ic=0;ic<nedge;ic++) {
1931 Standard_Integer iface1,iface2;
1932 TopoDS_Face face1,face2;
1933 TopoDS_Edge edge;
1934 TColGeom_SequenceOfCurve cr;
1935 TColGeom2d_SequenceOfCurve pr;
1936 Indices(nedge,ic,icplus,icmoins);
1937 if (!oksea.Value(ic)){
1938 iface1=numfa.Value(ic,icplus);
1939 iface2=numfa.Value(icplus,ic);
1940 if (!sharp.Value(ic)) {
1941 if (jf.Value(ic)==1)
1942 iface1 =SurfIndex(CD, ic, i.Value(ic,icplus), FACE1);
1943 else iface1=SurfIndex(CD, ic, i.Value(ic,icplus), FACE2);
1944 }
1945 face1=TopoDS::Face(myDS->Shape(iface1));
1946
1947 if (!sharp.Value(icplus)) {
1948 if (jf.Value(icplus)==1)
1949 iface2 =SurfIndex(CD, icplus, i.Value(icplus,ic), FACE2);
1950 else iface2=SurfIndex(CD, icplus, i.Value(icplus,ic), FACE1);
1951 }
1952 face2=TopoDS::Face(myDS->Shape(iface2));
1953 if (!face1.IsSame(face2)) {
1954 if (Fproj.Length()==0) {
1955 Fproj.Append(face1);
1956 Fproj.Append(face2);
1957 }
1958 moresurf.SetValue(ic,Standard_True);
1959 nbface=Fproj.Length();
1960 if (!TopoDS::Face(Fproj.Value(nbface)).IsSame(face2)) {
1961 Fproj.Remove(nbface);
1962 Fproj.Append(face2);
1963 }
1964 if (!TopoDS::Face(Fproj.Value(1)).IsSame(face1)) {
1965 Fproj.Remove(1);
1966 Fproj.Prepend(face1);
1967 }
1968 for (nb=1;nb<=nbface-1; nb++) {
1969 cherche_edge1 ( TopoDS::Face(Fproj.Value(nb)), TopoDS::Face(Fproj.Value(nb+1)),edge);
1970 Ecom.Append(edge);
1971 para=BRep_Tool::Parameter(TopExp::FirstVertex(edge),edge);
1972 parcom.Append(para);
1973 }
1974 CurveHermite (DStr,CD.Value(ic),jf.Value(ic),i.Value(ic,icplus),
1975 p.Value(ic,icplus),sens.Value(ic),sharp.Value(ic),
1976 TopoDS::Edge(Evive.Value(ic)),
1977 CD.Value(icplus),jf.Value(icplus),i.Value(icplus,ic),
1978 p.Value(icplus,ic),sens.Value(icplus),sharp.Value(icplus),
1979 TopoDS::Edge(Evive.Value(icplus)),nbface,Ecom,Fproj, pr,cr,Eproj,parcom,error);
1980 Ecom.Append(Ecom.Value(nbface-1));
1981 parcom.Append(parcom.Value(nbface-1));
1982 }
1983 }
1984 }
1985
81bba717 1986// case when two fillets have the same commonpoints
1987// one continues then by intersection
1988// it is checked if the extremities of the intersection coincide with commonpoints
7fd59977 1989
1990 Standard_Boolean intersection=Standard_False, introuve;
1991 if (nconges==2 && !deuxconges) {
1992 gp_Pnt P1,P2,P3,P4;
7fd59977 1993 Standard_Integer ic1 = 0,ic2 = 0;
7fd59977 1994 trouve=Standard_False;
1995 for (ic=0;ic<nedge&&!trouve;ic++) {
1996 if (!sharp.Value(ic)){
1997 ic1=ic;
1998 trouve=Standard_True;
1999 }
2000 }
2001 for (ic=0;ic<nedge;ic++) {
2002 if (!sharp.Value(ic)&& ic!=ic1) ic2=ic;
2003 }
2004 jfp = 3 - jf.Value(ic1);
2005 Indices(nedge,ic1,icplus,icmoins);
2006 Calcul_P2dOnSurf(CD.Value(ic1),jfp,i.Value(ic1,icmoins),p.Value(ic1,icmoins),p2);
2007 indice=SurfIndex(CD, ic1, i.Value(ic1,icmoins), ChFiSURFACE);
2008 DStr.Surface(indice).Surface()->D0(p2.X(),p2.Y(),P1);
2009
2010 Calcul_P2dOnSurf(CD.Value(ic1),jf.Value(ic1),i.Value(ic1,icplus),p.Value(ic1,icplus),p2);
2011 indice=SurfIndex(CD, ic1, i.Value(ic1,icplus), ChFiSURFACE);
2012 DStr.Surface(indice).Surface()->D0(p2.X(),p2.Y(),P2);
2013
2014 jfp = 3 - jf.Value(ic2);
2015 Indices(nedge,ic2,icplus,icmoins);
2016 Calcul_P2dOnSurf(CD.Value(ic2),jfp,i.Value(ic2,icmoins),p.Value(ic2,icmoins),p2);
2017 indice=SurfIndex(CD, ic2, i.Value(ic2,icmoins), ChFiSURFACE);
2018 DStr.Surface(indice).Surface()->D0(p2.X(),p2.Y(),P3);
2019
2020 Calcul_P2dOnSurf(CD.Value(ic2),jf.Value(ic2),i.Value(ic2,icplus),p.Value(ic2,icplus),p2);
2021 indice=SurfIndex(CD, ic2, i.Value(ic2,icplus), ChFiSURFACE);
2022 DStr.Surface(indice).Surface()->D0(p2.X(),p2.Y(),P4);
2023 intersection=(P1.Distance(P4)<=1.e-7 || P1.Distance(P3)<=1.e-7) &&
2024 (P2.Distance(P4)<=1.e-7 || P2.Distance(P3)<=1.e-7);
2025 if (intersection) {
2026 PerformTwoCornerSameExt(DStr,CD.Value(ic1),Index.Value(ic1),sens.Value(ic1),
2027 CD.Value(ic2),Index.Value(ic2),sens.Value(ic2),introuve);
2028 if (introuve) return;
2029 }
2030 }
2031
81bba717 2032// declaration for plate
7fd59977 2033 GeomPlate_BuildPlateSurface PSurf(3,10,3,tol2d,tolesp,angular);
2034
81bba717 2035// calculation of curves on surface for each stripe
7fd59977 2036 for (ic=0;ic<nedge;ic++) {
2037 gp_Pnt2d p2d1, p2d2;
2038 if (!sharp.Value(ic)) {
2039 n3d++;
2040 Indices(nedge,ic,icplus,icmoins);
2041 jfp = 3 - jf.Value(ic);
2042 Calcul_P2dOnSurf(CD.Value(ic),jfp,i.Value(ic,icmoins),p.Value(ic,icmoins),p2d1);
2043 Calcul_P2dOnSurf(CD.Value(ic),jf.Value(ic),i.Value(ic,icplus),p.Value(ic,icplus),p2d2);
2044// if (i[ic][icplus]!= i[ic][icmoins]) cout<<"probleme surface"<<endl;
2045 indice= SurfIndex(CD, ic, i.Value(ic,icplus), ChFiSURFACE);
2046 Handle (GeomAdaptor_HSurface) Asurf =
2047 new GeomAdaptor_HSurface(DStr.Surface(indice).Surface());
81bba717 2048 // calculation of curve 2d
7fd59977 2049 xdir= p2d2.X()-p2d1.X();
2050 ydir= p2d2.Y()-p2d1.Y();
2051 Standard_Real l0 = sqrt(xdir*xdir+ ydir*ydir );
2052 gp_Dir2d dir (xdir, ydir);
2053 Handle(Geom2d_Line) l= new Geom2d_Line (p2d1 ,dir);
2054 Handle (Geom2d_Curve) pcurve = new Geom2d_TrimmedCurve(l,0,l0);
2055 Handle (Geom2dAdaptor_HCurve) Acurv = new Geom2dAdaptor_HCurve(pcurve);
2056 Adaptor3d_CurveOnSurface CurvOnS (Acurv,Asurf);
2057 Handle(Adaptor3d_HCurveOnSurface) HCons =
2058 new Adaptor3d_HCurveOnSurface(CurvOnS);
2059 Order.SetValue(ic,1);
2060 Handle(GeomPlate_CurveConstraint) Cont =
2061 new GeomPlate_CurveConstraint(HCons,Order.Value(ic),10,tolesp,angular,0.1);
2062 PSurf.Add(Cont);
2063
81bba717 2064 // calculate indexes of points and of the curve for the DS
7fd59977 2065 isfirst=(sens.Value(ic)==1);
2066 GeomLib::BuildCurve3d(tolapp,CurvOnS,CurvOnS.FirstParameter(),
2067 CurvOnS.LastParameter(),Curv3d,maxapp,avedev);
2068 TopOpeBRepDS_Curve tcurv3d( Curv3d,maxapp);
2069 indcurve3d.SetValue(n3d,DStr.AddCurve(tcurv3d));
2070 gp_Pnt point1,point2;
2071 point1= CurvOnS.Value(CurvOnS.FirstParameter());
2072 point2 =CurvOnS.Value(CurvOnS.LastParameter());
2073
2074 TopOpeBRepDS_Point tpoint1 (point1,maxapp);
2075 TopOpeBRepDS_Point tpoint2 (point2,maxapp);
2076 errapp.SetValue(ic,maxapp);
2077 if (ic==0) {
81bba717 2078// it is necessary to create two points
7fd59977 2079 indpoint.SetValue(ic,0,DStr.AddPoint(tpoint1));
2080 indpoint.SetValue(ic,1,DStr.AddPoint(tpoint2));
2081 }
2082 else {
81bba717 2083// probably the points are already on the fillet
2084// (previous intersection...)
7fd59977 2085 trouve = Standard_False;
2086 for (ii=0;ii<ic&&(!trouve);ii++) {
2087 if (!sharp.Value(ii)) {
2088 TopOpeBRepDS_Point & tpt= DStr.ChangePoint(indpoint.Value(ii,1));
2089 if (point1.Distance(tpt.Point())<1.e-4)
2090 trouve = Standard_True;
2091 }
2092 }
2093 if (trouve)
2094 indpoint.SetValue(ic,0,indpoint.Value(ii-1,1));
2095 else
2096 indpoint.SetValue(ic,0,DStr.AddPoint(tpoint1));
2097
2098 trouve = Standard_False;
2099 for (ii=0;ii<ic&&(!trouve);ii++) {
2100 if (!sharp.Value(ii)) {
2101 TopOpeBRepDS_Point & tpt= DStr.ChangePoint(indpoint.Value(ii,0));
2102 if (point2.Distance(tpt.Point())<1.e-4)
2103 trouve = Standard_True;
2104 }
2105 }
2106 if (trouve)
2107 indpoint.SetValue(ic,1,indpoint.Value(ii-1,0));
2108 else
2109 indpoint.SetValue(ic,1,DStr.AddPoint(tpoint2));
2110 }
2111
81bba717 2112 // update of the stripe
7fd59977 2113 isurf1=3-jf.Value(ic); isurf2=jf.Value(ic);
2114 if (isurf1==2) CD.Value(ic)->SetOrientation(TopAbs_REVERSED,isfirst);
2115 CD.Value(ic)->SetCurve(indcurve3d.Value(n3d),isfirst);
2116 CD.Value(ic)->SetIndexPoint(indpoint.Value(ic,0),isfirst,isurf1);
2117 CD.Value(ic)->SetIndexPoint(indpoint.Value(ic,1),isfirst,isurf2);
2118 CD.Value(ic)->SetParameters(isfirst,pcurve->FirstParameter(),pcurve->LastParameter());
2119 ChFiDS_CommonPoint cp1;
2120 ChFiDS_CommonPoint cp2;
2121 cp1.SetPoint (point1);
2122 cp2.SetPoint( point2);
2123 CD.Value(ic)->SetOfSurfData()->Value(i.Value(ic,icmoins))->
2124 ChangeVertex (isfirst,isurf1)=cp1;
2125 CD.Value(ic)->SetOfSurfData()->Value(i.Value(ic,icmoins))->
2126 ChangeVertex (isfirst,isurf2)=cp2;
2127 CD.Value(ic)->SetOfSurfData()->Value(i.Value(ic,icmoins))->
2128 ChangeInterference(isurf1).SetParameter(p.Value(ic,icmoins),isfirst);
2129 CD.Value(ic)->SetOfSurfData()->Value(i.Value(ic,icmoins))->
2130 ChangeInterference(isurf2).SetParameter(p.Value(ic,icplus),isfirst);
2131 CD.Value(ic)-> ChangePCurve(isfirst)= pcurve;
2132 }
2133 }
2134
81bba717 2135// calculate the indices of points for living edges
7fd59977 2136 for (ic=0;ic<nedge;ic++) {
2137 if (sharp.Value(ic)) {
2138 Indices(nedge,ic,icplus,icmoins);
2139 BRepAdaptor_Curve C(TopoDS::Edge(Evive.Value(ic)));
2140 /*gp_Pnt*/ PE = C.Value(p.Value(ic,icplus));
2141 TopOpeBRepDS_Point TPE(PE,BRep_Tool::Tolerance(TopoDS::Edge(Evive.Value(ic))));
2142 ChFiDS_CommonPoint cp;
2143 if (deuxconges ) {
2144 IVtx = DStr.AddShape(V1);
2145 indpoint.SetValue(ic,0, IVtx );
2146 indpoint.SetValue(ic,1, IVtx );
2147 }
2148 if (!sharp.Value(icplus)) {
2149 isfirst=(sens.Value(icplus)==1);
2150 jfp = 3 - jf.Value(icplus);
2151 cp = CD.Value(icplus)->SetOfSurfData()->Value(i.Value(icplus,ic))->
2152 ChangeVertex (isfirst,jfp);
2153 if ( cp.Point().Distance(PE) <= Max(1.e-4,tolcp)) {
81bba717 2154// edge was limited by the 1st CommonPoint of CD[icplus]
7fd59977 2155 indpoint.SetValue(ic,0,indpoint.Value(icplus,0));
2156 indpoint.SetValue(ic,1,indpoint.Value(icplus,0));
2157 }
2158 }
2159 if (!sharp.Value(icmoins)) {
2160 isfirst=(sens.Value(icmoins)==1);
2161 cp = CD.Value(icmoins)->SetOfSurfData()->Value(i.Value(icmoins,ic))->
2162 ChangeVertex (isfirst,jf.Value(icmoins));
2163 if ( cp.Point().Distance(PE) <= Max(1.e-4,tolcp)) {
81bba717 2164// edge was limited by the 2nd CommonPoint of CD[icmoins]
7fd59977 2165 if (indpoint.Value(ic,0)==0) {
2166 indpoint.SetValue(ic,0, indpoint.Value(icmoins,1));
2167 indpoint.SetValue(ic,1, indpoint.Value(icmoins,1));
2168 }
2169 }
2170 }
2171 if (indpoint.Value(ic,0)==0) {
2172 indpoint.SetValue(ic,0,DStr.AddPoint(TPE));
2173 indpoint.SetValue(ic,1, indpoint.Value(ic,0));
2174 }
2175 }
2176 }
2177
81bba717 2178// calculation of intermediary curves connecting two stripes in case if
2179// there is no intersection. The curve is a straight line, projection or batten
7fd59977 2180
2181 Standard_Boolean raccordbatten;
2182 if (!inters) {
2183
2184 for (ic=0;ic<nedge;ic++) {
2185
2186 if (!oksea.Value(ic)&& !moresurf.Value(ic) && !libre.Value(ic) ) {
2187 Indices(nedge,ic,icplus,icmoins);
2188 raccordbatten=Standard_False;
2189 if (!regul.Value(ic)) {
2190 raccordbatten=Standard_True;
2191 if (regul.Value(icplus))
2192 raccordbatten=Standard_False;
2193 }
2194 n3d++;
2195 gp_Pnt2d p2d1, p2d2;
2196 Handle(Geom2d_Curve) curv2d1,curv2d2;
2197 Handle (Geom2d_Curve) pcurve;
2198 Handle (Geom_Curve) curveint;
2199 Handle (GeomAdaptor_HSurface) Asurf;
2200 Standard_Real u1bid,u2bid;
2201
81bba717 2202 // return the 1st curve 2d
2203 // and the 1st connection point
7fd59977 2204 if (sharp.Value(ic))
2205 curv2d1 = BRep_Tool::CurveOnSurface(TopoDS::Edge(Evive.Value(ic)),TopoDS::Face(Fvive.Value(ic,icplus)),
2206 u1bid,u2bid);
2207 else
2208 Calcul_C2dOnFace(CD.Value(ic),jf.Value(ic),i.Value(ic,icplus),curv2d1);
2209 p2d1 = curv2d1 ->Value(p.Value(ic,icplus));
2210
2211 // recuperation de la deuxieme courbe 2d
2212 // et du deuxieme point de raccordement
2213 if (sharp.Value(icplus))
2214 curv2d2 = BRep_Tool::CurveOnSurface(TopoDS::Edge(Evive.Value(icplus)),
2215 TopoDS::Face(Fvive.Value(ic,icplus)),u1bid,u2bid);
2216 else {
2217 jfp = 3 - jf.Value(icplus);
2218 Calcul_C2dOnFace(CD.Value(icplus),jfp,i.Value(icplus,ic),curv2d2);
2219 }
2220 p2d2 = curv2d2 ->Value(p.Value(icplus,ic));
2221
2222 Asurf = new GeomAdaptor_HSurface(BRep_Tool::Surface(TopoDS::Face(Fvive.Value(ic,icplus))));
2223 Standard_Real tolu,tolv,ratio;
2224 tolu=Asurf->Surface().UResolution(1.e-3);
2225 tolv=Asurf->Surface().VResolution(1.e-3);
2226 if (tolu>tolv) ratio=tolu/tolv;
2227 else ratio=tolv/tolu;
2228
81bba717 2229 // in case of a sewing edge the parameters are reframed
7fd59977 2230 if (couture) {
2231 Standard_Boolean PI1=Standard_False, PI2=Standard_False;
2232 Standard_Real xx;
c6541a0c
D
2233 PI1=0<=p2d1.X() && p2d1.X() <=M_PI;
2234 PI2=0<=p2d2.X() && p2d2.X() <=M_PI;
7fd59977 2235
2236 if (Evive.Value(ic).IsSame(edgecouture)){
2237 xx=p2d1.X();
c6541a0c
D
2238 if (PI2&&!PI1) xx=xx-2*M_PI;
2239 if (!PI2&&PI1) xx=xx+2*M_PI;
7fd59977 2240 p2d1.SetX(xx);
2241
2242 }
2243 if (Evive.Value(icplus).IsSame(edgecouture)){
2244 xx=p2d2.X();
c6541a0c
D
2245 if (PI2&&!PI1) xx=xx+2*M_PI;
2246 if (!PI2&&PI1) xx=xx-2*M_PI;
7fd59977 2247 p2d2.SetX(xx);
2248 }
2249 }
2250 xdir= p2d2.X()-p2d1.X();
2251 ydir= p2d2.Y()-p2d1.Y();
2252
2253 Standard_Real l0 = sqrt(xdir*xdir+ ydir*ydir );
2254 if (l0<1.e-7|| ponctuel.Value(ic)) {
81bba717 2255// unused connection
7fd59977 2256 n3d--;
2257 ponctuel.SetValue(ic,Standard_True);
2258 if (!deuxconges) {
2259 if ( sharp.Value(icplus) && indpoint.Value(icplus,0) == 0 ) {
2260 indpoint.SetValue(icplus,0, indpoint.Value(ic,1));
2261 indpoint.SetValue(icplus,1, indpoint.Value(ic,1));
2262 }
2263 if ( sharp.Value(ic) && indpoint.Value(ic,0) == 0 ) {
2264 indpoint.SetValue(ic,0,indpoint.Value(icmoins,1));
2265 indpoint.SetValue(ic,1,indpoint.Value(icmoins,1));
2266 }
2267 }
2268 }
81bba717 2269 else { // the connection is a straight line, projection or batten
7fd59977 2270 if (ratio>10 && nconges==1) raccordbatten=Standard_True;
2271 if (ratio>10 && raccordbatten) {
2272 CalculDroite(p2d1,xdir,ydir,pcurve);
2273 raccordbatten=Standard_False;
2274 }
81bba717 2275 else if (!raccordbatten){ // the projected curves are returned
7fd59977 2276 if (regul.Value(ic)) {
2277 if (cproj2.Value(ic).IsNull()){
2278 raccordbatten=Standard_True;
2279 }
2280 else {
2281 pcurve=proj2d2.Value(ic);
2282 curveint=cproj2.Value(ic);
2283 maxapp1=1.e-6;
2284 }
2285
2286 }
2287 else {
2288 if (cproj1.Value(ic+1).IsNull()) {
2289 raccordbatten=Standard_True;
2290 }
2291 else {
2292 pcurve=proj2d1.Value(ic+1);
2293 curveint=cproj1.Value(ic+1);
2294 maxapp1=1.e-6;
2295 }
2296 }
2297 }
2298 Standard_Boolean contraint1=Standard_True,
2299 contraint2=Standard_True;
2300 if (raccordbatten) {
2301#ifdef DEB
81bba717 2302 ChFi3d_InitChron(ch);// initial performances for battens
7fd59977 2303#endif
2304 Standard_Boolean inverseic,inverseicplus;
2305 if (sharp.Value(ic)) {
2306 inverseic=TopExp::FirstVertex(TopoDS::Edge(Evive.Value(ic))).
2307 IsSame(V1);
2308 }
2309 else {
2310 inverseic=sens.Value(ic)==1;
2311 }
2312 if (sharp.Value(icplus)){
2313 inverseicplus=TopExp::FirstVertex(TopoDS::Edge(Evive.Value(icplus))).
2314 IsSame(V1);
2315 }
2316 else {
2317 inverseicplus=sens.Value(icplus)==1;
2318 }
2319 if (TopoDS::Edge(Evive.Value(ic)).IsSame(edgelibre1) ||
2320 TopoDS::Edge(Evive.Value(ic)).IsSame(edgelibre2))
2321 contraint1=Standard_False;
2322 if (TopoDS::Edge(Evive.Value(icplus)).IsSame(edgelibre1) ||
2323 TopoDS::Edge(Evive.Value(icplus)).IsSame(edgelibre2))
2324 contraint2=Standard_False;
2325 CalculBatten(Asurf,TopoDS::Face(Fvive(ic,icplus)),xdir,ydir,p2d1,p2d2,contraint1,contraint2,curv2d1,curv2d2,p.Value(ic,icplus),
2326 p.Value(icplus,ic),inverseic,inverseicplus,pcurve);
2327#ifdef DEB
81bba717 2328 ChFi3d_ResultChron( ch,t_batten); // resulting performances for battens
7fd59977 2329#endif
2330 }
2331
81bba717 2332 // construction of borders for Plate
7fd59977 2333 Handle (Geom2dAdaptor_HCurve) Acurv=new Geom2dAdaptor_HCurve(pcurve);
2334 Adaptor3d_CurveOnSurface CurvOnS (Acurv,Asurf);
2335 Handle(Adaptor3d_HCurveOnSurface) HCons =
2336 new Adaptor3d_HCurveOnSurface(CurvOnS);
2337
81bba717 2338 // constraints G1 are set if edges ic and icplus are not both alive
7fd59977 2339
2340
2341 Order.SetValue(n3d,0);
2342 if (!sharp.Value(ic)&& !sharp.Value(icplus))
2343 Order.SetValue(n3d,1);
2344 if (!contraint1 && !sharp.Value(icplus))
2345 Order.SetValue(n3d,1);
2346 if (!contraint2 && !sharp.Value(ic))
2347 Order.SetValue(n3d,1);
2348 if (tangentregul(ic) || tangentregul(icplus) )
2349 Order.SetValue(n3d,1);
2350 if (isG1.Value(ic))
2351 Order.SetValue(n3d,1);
2352 Handle(GeomPlate_CurveConstraint) Cont =
2353 new GeomPlate_CurveConstraint(HCons,Order.Value(n3d),10,tolesp,angular,0.1);
2354 PSurf.Add(Cont);
2355
81bba717 2356 //calculation of curve 3d if it is not a projection
7fd59977 2357 if (curveint.IsNull()) {
2358 GeomLib::BuildCurve3d(tolapp,CurvOnS,CurvOnS.FirstParameter(),
2359 CurvOnS.LastParameter(),Curv3d,maxapp1,avedev);
2360 pardeb=CurvOnS.FirstParameter();
2361 parfin= CurvOnS.LastParameter();
2362 curveint= new Geom_TrimmedCurve(Curv3d,pardeb,parfin);
2363 }
2364
81bba717 2365 //storage in the DS
7fd59977 2366 TopOpeBRepDS_Curve tcurv3d( curveint,maxapp1);
2367 indcurve3d.SetValue(n3d, DStr.AddCurve(tcurv3d));
2368 pardeb=curveint->FirstParameter();
2369 parfin=curveint->LastParameter();
2370 if ( sharp.Value(icplus) && indpoint.Value(icplus,0) == 0) {
81bba717 2371 // it is necessary to initialize indpoint[icplus][0] and indpoint[icplus][1]
7fd59977 2372 gp_Pnt point2;
2373 point2 =curveint->Value(parfin);
2374 TopOpeBRepDS_Point tpoint2 (point2,maxapp);
2375 indpoint.SetValue(icplus,0,DStr.AddPoint(tpoint2));
2376 indpoint.SetValue(icplus,1,indpoint.Value(icplus,0));
2377 }
2378 Standard_Boolean IsVt1=Standard_False;
2379 Standard_Boolean IsVt2=Standard_False;
2380 if(deuxconges) {
2381 IsVt1=sharp.Value(ic);
2382 IsVt2=sharp.Value(icplus);
2383 }
2384 Interfp1=ChFi3d_FilPointInDS(TopAbs_FORWARD,indcurve3d.Value(n3d),
2385 indpoint.Value(ic,1),pardeb,IsVt1);
2386 Interfp2=ChFi3d_FilPointInDS(TopAbs_REVERSED,indcurve3d.Value(n3d),
2387 indpoint(icplus,0),parfin,IsVt2);
2388 DStr.ChangeCurveInterferences(indcurve3d.Value(n3d)).Append(Interfp1);
2389 DStr.ChangeCurveInterferences(indcurve3d.Value(n3d)).Append(Interfp2);
2390 if (!IsVt1) {
2391 TopOpeBRepDS_Point & tpt1= DStr.ChangePoint(indpoint(ic,1));
2392 tpt1.Tolerance (tpt1.Tolerance()+maxapp1);
2393 }
2394 if (!IsVt2) {
2395 TopOpeBRepDS_Point &tpt2= DStr.ChangePoint(indpoint(icplus,0));
2396 tpt2.Tolerance (tpt2.Tolerance()+maxapp1);
2397 }
2398
81bba717 2399 // calculate orientation of the curve
7fd59977 2400 TopAbs_Orientation orinterf;
2401 if (!sharp.Value(ic)) {
2402 OrientationIcNonVive(CD.Value(ic),jf.Value(ic),i.Value(ic,icplus),sens.Value(ic),orinterf);
2403 }
2404 else if (!sharp.Value(icplus)) {
2405 OrientationIcplusNonVive(CD.Value(icplus),jf.Value(icplus),i.Value(icplus,ic),sens.Value(icplus),orinterf);
2406 }
2407 else {
2408 OrientationAreteViveConsecutive (Fvive.Value(ic,icplus) ,Evive.Value(ic),V1,orinterf);
2409 }
2410 Interfc=ChFi3d_FilCurveInDS(indcurve3d.Value(n3d),numfa.Value(ic,icplus),pcurve,orinterf);
2411 DStr.ChangeShapeInterferences(numfa.Value(ic,icplus)).Append(Interfc);
2412 }
81bba717 2413 } // end of processing by edge
2414 } // end of the loop on edges
2415 } // end of processing for intermediary curves
7fd59977 2416
81bba717 2417// storage in the DS of curves projected on several faces
7fd59977 2418 for (ic=0;ic<nedge;ic++) {
2419 if (moresurf.Value(ic) ){
2420 TopoDS_Vertex Vf,Vl;
2421 gp_Pnt Pf,Pl,P1,P2,Pcom;
2422 ind = 0; //must be initialized because of possible use, see L2249
2423 Standard_Real up1,up2;
2424 TopAbs_Orientation orvt;
2425 TopAbs_Orientation oredge = TopAbs_FORWARD;
2426 Standard_Integer indpoint1,indpoint2;
2427 Indices(nedge,ic,icplus,icmoins);
2428 Handle(Geom2d_Curve) proj,proj2d;
2429 Handle(Geom_Curve) projc,cproj;
2430 TopOpeBRepDS_Point& tpt1= DStr.ChangePoint(indpoint(ic,1));
2431 TopOpeBRepDS_Point& tpt2= DStr.ChangePoint(indpoint(icplus,0));
2432 tpt1.Tolerance (tpt1.Tolerance()+error);
2433 tpt2.Tolerance (tpt1.Tolerance()+error);
2434 for(nb=1;nb<=nbface;nb++) {
2435 orvt=TopAbs_REVERSED;
2436 Vf=TopExp::FirstVertex(TopoDS::Edge(Ecom.Value(nb)));
2437 Vl=TopExp::LastVertex (TopoDS::Edge(Ecom.Value(nb)));
2438 Pf=BRep_Tool::Pnt(Vf);
2439 Pl=BRep_Tool::Pnt(Vl);
2440 para=parcom.Value(nb);
2441 Pcom=BRep_Tool::Curve(TopoDS::Edge(Ecom.Value(nb)),up1,up2)->Value(para);
2442 if (Pf.Distance(BRep_Tool::Pnt(V1))< Pl.Distance(BRep_Tool::Pnt(V1)))
2443 orvt=TopAbs_FORWARD;
2444 if (!Eproj.Value(nb).IsNull()) {
2445 n3d++;
2446 proj=BRep_Tool::CurveOnSurface(TopoDS::Edge(Eproj.Value(nb)),
2447 TopoDS::Face(Fproj.Value(nb)),up1,up2);
2448 proj2d=new Geom2d_TrimmedCurve(proj,up1,up2);
2449 projc=BRep_Tool::Curve(TopoDS::Edge(Eproj.Value(nb)),up1,up2);
2450 cproj=new Geom_TrimmedCurve(projc,up1,up2);
2451 pardeb=cproj->FirstParameter();
2452 parfin=cproj->LastParameter();
2453 P1=cproj->Value(pardeb);
2454 P2=cproj->Value(parfin);
2455 if (P1.Distance(tpt1.Point())<1.e-3)
2456 indpoint1=indpoint(ic,1);
2457 else indpoint1=ind;
2458 if (P2.Distance(tpt2.Point())<1.e-3)
2459 indpoint2=indpoint(icplus,0);
2460 else {
2461 TopOpeBRepDS_Point tpoint2 (P2,error);
2462 indpoint2= DStr.AddPoint(tpoint2);
2463 ind=indpoint2;
2464 }
2465 Handle (GeomAdaptor_HSurface) Asurf;
2466 Asurf = new GeomAdaptor_HSurface(BRep_Tool::Surface
2467 (TopoDS::Face(Fproj.Value(nb))));
2468 Handle (Geom2dAdaptor_HCurve) Acurv=new Geom2dAdaptor_HCurve(proj2d);
2469 Adaptor3d_CurveOnSurface CurvOnS (Acurv,Asurf);
2470 Handle(Adaptor3d_HCurveOnSurface) HCons =new Adaptor3d_HCurveOnSurface(CurvOnS);
2471 Order.SetValue(n3d,1);
2472 Handle(GeomPlate_CurveConstraint) Cont =
2473 new GeomPlate_CurveConstraint(HCons,Order.Value(n3d),10,tolesp,angular,0.1);
2474 PSurf.Add(Cont);
2475 TopOpeBRepDS_Curve tcurv3d( cproj,error);
2476 indcurve3d.SetValue(n3d, DStr.AddCurve(tcurv3d));
2477 Interfp1=ChFi3d_FilPointInDS(TopAbs_FORWARD,indcurve3d.Value(n3d),
2478 indpoint1,pardeb);
2479 Interfp2=ChFi3d_FilPointInDS(TopAbs_REVERSED,indcurve3d.Value(n3d),
2480 indpoint2,parfin);
2481 DStr.ChangeCurveInterferences(indcurve3d.Value(n3d)).Append(Interfp1);
2482 DStr.ChangeCurveInterferences(indcurve3d.Value(n3d)).Append(Interfp2);
2483 num=DStr.AddShape(Fproj.Value(nb));
2484 TopExp_Explorer ex;
2485 for(ex.Init(Fproj.Value(nb).Oriented(TopAbs_FORWARD),TopAbs_EDGE);
2486 ex.More(); ex.Next()){
2487 if(Ecom.Value(nb).IsSame(ex.Current())) {
2488 oredge = ex.Current().Orientation();
2489 break;
2490 }
2491 }
2492
81bba717 2493 //calculation of the orientation
7fd59977 2494 TopAbs_Orientation orinterf;
2495 if (P1.Distance(Pcom)>1.e-4) {
2496 if (orvt==TopAbs_FORWARD) {
2497 orinterf=oredge;
2498 }
2499 else {
2500 orinterf=TopAbs::Reverse(oredge);
2501 }
2502 }
2503 else {
2504 if (orvt==TopAbs_FORWARD) {
2505 orinterf=TopAbs::Reverse(oredge);
2506 }
2507 else {
2508 orinterf=oredge;
2509 }
2510 }
2511 Interfc=ChFi3d_FilCurveInDS(indcurve3d.Value(n3d),num,proj2d,orinterf);
2512 DStr.ChangeShapeInterferences(num).Append(Interfc);
2513 }
2514 indice=ind;
2515 if (nb!=nbface) {
2516 if (Eproj.Value(nb).IsNull()) indice=indpoint(ic,1);
2517 if (Eproj.Value(nb+1).IsNull()) indice=indpoint(icplus,0);
2518 Indice.SetValue(n3d,indice);
2519 Standard_Integer Iarc1=DStr.AddShape(TopoDS::Edge(Ecom.Value(nb)));
2520 Interfp1=ChFi3d_FilPointInDS(orvt,Iarc1,indice,parcom.Value(nb));
2521 DStr.ChangeShapeInterferences(Iarc1).Append(Interfp1);
2522 }
2523 }
2524 }
2525 }
2526
81bba717 2527// case when two free borders are tangent
7fd59977 2528 if (droit)
2529 for (ic=0;ic<nedge;ic++) {
2530 Handle(Geom_Curve) curve,ctrim,rcurve;
2531 Handle(Geom2d_Curve) curve2d,ctrim2d,rcurve2d;
2532 Standard_Real ufirst,ulast;
2533 Indices(nedge,ic,icplus,icmoins);
2534 Standard_Integer indpoint1,indpoint2;
2535 Standard_Boolean isvt1=Standard_False,isvt2=Standard_False;
2536 TopoDS_Edge ecur =TopoDS::Edge(Evive.Value(ic));
2537 if (ecur.IsSame(edgelibre1)|| ecur.IsSame(edgelibre2)) {
2538 n3d++;
2539 curve2d=BRep_Tool::CurveOnSurface(TopoDS::Edge(Evive.Value(ic)),
2540 TopoDS::Face(Fvive.Value(ic,icplus)),ufirst,ulast);
2541 curve=BRep_Tool::Curve(TopoDS::Edge(Evive.Value(ic)),ufirst,ulast);
2542 if (TopExp::FirstVertex((TopoDS::Edge(Evive.Value(ic)))).IsSame (V1)) {
2543 ctrim=new Geom_TrimmedCurve(curve,ufirst,p.Value(ic,icmoins));
2544 ctrim2d=new Geom2d_TrimmedCurve(curve2d,ufirst,p.Value(ic,icmoins));
2545 indpoint1=DStr.AddShape(V1);
2546 isvt1=1;
2547 indpoint2=indpoint(ic,1);
2548 }
2549 else {
2550 ctrim=new Geom_TrimmedCurve(curve, p.Value(ic,icmoins),ulast);
2551 ctrim2d=new Geom2d_TrimmedCurve(curve2d,p.Value(ic,icmoins),ulast);
2552 indpoint2=DStr.AddShape(V1);
2553 isvt2=1;
2554 indpoint1=indpoint(ic,1);
2555 }
2556 if (libre.Value(ic)){
2557 if (TopExp::FirstVertex((TopoDS::Edge(Evive.Value(ic)))).IsSame(V1)) {
2558 ctrim->Reverse();
2559 ctrim2d->Reverse();
2560 indpoint2=DStr.AddShape(V1);
2561 isvt2=1;
2562 isvt1=0;
2563 indpoint1=indpoint(ic,1);
2564 }
2565 }
2566 else {
2567 if (TopExp::LastVertex((TopoDS::Edge(Evive.Value(ic)))).IsSame(V1)) {
2568 ctrim->Reverse();
2569 ctrim2d->Reverse();
2570 indpoint1=DStr.AddShape(V1);
2571 isvt1=1;
2572 isvt2=0;
2573 indpoint2=indpoint(ic,1);
2574 }
2575 }
2576 ufirst=ctrim->FirstParameter();
2577 ulast=ctrim->LastParameter();
2578 Handle (GeomAdaptor_HSurface) Asurf;
2579 Asurf = new GeomAdaptor_HSurface(BRep_Tool::Surface
2580 (TopoDS::Face(Fvive.Value(ic,icplus))));
2581 Handle (Geom2dAdaptor_HCurve) Acurv=new Geom2dAdaptor_HCurve(ctrim2d);
2582 Adaptor3d_CurveOnSurface CurvOnS (Acurv,Asurf);
2583 Handle(Adaptor3d_HCurveOnSurface) HCons =new Adaptor3d_HCurveOnSurface(CurvOnS);
2584 Order.SetValue(n3d,0);
2585 Handle(GeomPlate_CurveConstraint) Cont =
2586 new GeomPlate_CurveConstraint(HCons,Order.Value(n3d),10,tolesp,angular,0.1);
2587 PSurf.Add(Cont);
2588 TopOpeBRepDS_Curve tcurv3d( ctrim,1.e-4);
2589 indcurve3d.SetValue(n3d, DStr.AddCurve(tcurv3d));
2590 Interfp1=ChFi3d_FilPointInDS(TopAbs_FORWARD,indcurve3d.Value(n3d),
2591 indpoint1,ufirst,isvt1);
2592 Interfp2=ChFi3d_FilPointInDS(TopAbs_REVERSED,indcurve3d.Value(n3d),
2593 indpoint2,ulast,isvt2);
2594 DStr.ChangeCurveInterferences(indcurve3d.Value(n3d)).Append(Interfp1);
2595 DStr.ChangeCurveInterferences(indcurve3d.Value(n3d)).Append(Interfp2);
2596 }
2597 }
2598
2599#ifdef DEB
81bba717 2600 ChFi3d_InitChron(ch); // init performances for plate
7fd59977 2601#endif
2602
2603 PSurf.Perform();
2604
2605#ifdef DEB
81bba717 2606 ChFi3d_ResultChron(ch, t_plate); //result performances for plate
7fd59977 2607#endif
2608
81bba717 2609 // call of approx
7fd59977 2610
2611#ifdef DEB
81bba717 2612 ChFi3d_InitChron(ch); // init performances for approxplate
7fd59977 2613#endif
2614 if (PSurf.IsDone()) {
2615 Standard_Integer nbcarreau=9;
2616 Standard_Integer degmax=8;
2617 Standard_Real seuil;
2618 Handle(GeomPlate_Surface) gpPlate = PSurf.Surface();
2619
2620 TColgp_SequenceOfXY S2d;
2621 TColgp_SequenceOfXYZ S3d;
2622 S2d.Clear();
2623 S3d.Clear();
2624 PSurf.Disc2dContour(4,S2d);
2625 PSurf.Disc3dContour(4,0,S3d);
2626 seuil = Max(tolapp,10*PSurf.G0Error());
2627 GeomPlate_PlateG0Criterion critere (S2d,S3d,seuil);
2628 GeomPlate_MakeApprox Mapp(gpPlate,critere,tolapp,nbcarreau,degmax);
2629 Handle (Geom_Surface) Surf (Mapp.Surface());
2630 Standard_Real coef = 1.1 ,apperror;
2631 apperror=Mapp.CriterionError()*coef;
2632
2633#ifdef DEB
81bba717 2634 ChFi3d_ResultChron(ch, t_approxplate); // result performances for approxplate
7fd59977 2635#endif
2636
81bba717 2637// Storage of the surface plate and corresponding curves in the DS
7fd59977 2638
2639 TopAbs_Orientation orplate,orsurfdata,orpcurve,orien;
2640#ifdef DEB
2641// Standard_Real ang1=PSurf.G1Error();
2642#endif
2643// gp_Vec n1,n2,du,dv,du1,dv1;
2644// gp_Pnt pp,pp1;
2645// Standard_Real tpar;
2646// gp_Pnt2d uv;
2647// Standard_Real scal;
2648
2649 TopOpeBRepDS_Surface Tsurf(Surf,Mapp.ApproxError());
2650 Standard_Integer Isurf=DStr.AddSurface(Tsurf);
2651 //lbo : historique QDF.
2652 if(!myEVIMap.IsBound(V1)){
2653 TColStd_ListOfInteger li;
2654 myEVIMap.Bind(V1,li);
2655 }
2656 myEVIMap.ChangeFind(V1).Append(Isurf);
2657
2658 Standard_Integer SolInd = CD.Value(0)->SolidIndex();
2659 TopOpeBRepDS_ListOfInterference& SolidInterfs =
2660 DStr.ChangeShapeInterferences(SolInd);
2661
81bba717 2662// in case when one rereads at top, it is necessary that
2663// alive edges that arrive at the top should be removed from the DS.
2664// For this they are stored in the DS with their inverted orientation
7fd59977 2665 Standard_Integer nbedge;
2666 TopExp_Explorer ex;
2667 if (deuxconges)
2668 for (ic=0;ic<nedge;ic++) {
2669 if (!sharp.Value(ic)){
2670 nbedge = CD.Value(ic)->Spine()->NbEdges();
2671 TopoDS_Edge Arcspine;
2672 if (sens.Value(ic) ==1)
2673 Arcspine=CD.Value(ic) ->Spine()->Edges(1);
2674 else
2675 Arcspine= CD.Value(ic)->Spine()->Edges(nbedge);
2676 Standard_Integer IArcspine = DStr.AddShape(Arcspine);
7fd59977 2677 TopAbs_Orientation OVtx = TopAbs_FORWARD;
7fd59977 2678 for(ex.Init(Arcspine.Oriented(TopAbs_FORWARD),TopAbs_VERTEX);
2679 ex.More(); ex.Next()){
2680 if(V1.IsSame(ex.Current())) {
2681 OVtx = ex.Current().Orientation();
2682 break;
2683 }
2684 }
2685 OVtx = TopAbs::Reverse(OVtx);
2686 Standard_Real parVtx = BRep_Tool::Parameter(V1,Arcspine);
2687 Handle(TopOpeBRepDS_CurvePointInterference)
2688 interfv = ChFi3d_FilVertexInDS(OVtx,IArcspine,IVtx,parVtx);
2689 DStr.ChangeShapeInterferences(IArcspine).Append(interfv);
2690 }
2691 }
2692
81bba717 2693 // calculate orientation of Plate orplate corresponding to surfdata
2694 // calculation corresponding to the first stripe
7fd59977 2695 Indices(nedge,0,icplus,icmoins);
2696 isfirst=(sens.Value(0)==1);
2697 const Handle(ChFiDS_SurfData)& Fd =
2698 CD.Value(0)->SetOfSurfData()->Value(i.Value(0,icmoins));
2699 indice= Fd->Surf();
2700// Handle (Geom_Surface) surfdata = DStr.Surface(indice).Surface();
2701// tpar= (CD.Value(0)->PCurve(isfirst)->FirstParameter()+
2702// CD.Value(0)->PCurve(isfirst)->LastParameter())/2 ;
2703// CD.Value(0)->PCurve(isfirst)->D0(tpar,uv);
2704// surfdata->D1(uv.X(),uv.Y(),pp,du,dv);
2705// tpar=(PSurf.Curves2d()->Value(1)->FirstParameter()+
2706// PSurf.Curves2d()->Value(1)->LastParameter())/2;
2707// (PSurf.Curves2d())->Value(1)->D0(tpar,uv);
2708// Surf-> D1(uv.X(),uv.Y(),pp1,du1,dv1);
2709// n1=du.Crossed(dv);
2710// n2=du1.Crossed(dv1);
2711// scal= n1.Dot(n2);
2712 orsurfdata=Fd->Orientation();
2713// if (scal>0) orplate=orsurfdata;
2714// else orplate=TopAbs::Reverse(orsurfdata);
2715 orplate = PlateOrientation(Surf,PSurf.Curves2d(),SumFaceNormalAtV1);
2716
81bba717 2717 // creation of solidinterderence for Plate
7fd59977 2718 Handle(TopOpeBRepDS_SolidSurfaceInterference) SSI =
2719 new TopOpeBRepDS_SolidSurfaceInterference(TopOpeBRepDS_Transition(orplate),
2720 TopOpeBRepDS_SOLID,
2721 SolInd,
2722 TopOpeBRepDS_SURFACE,
2723 Isurf);
2724 SolidInterfs.Append(SSI);
2725
81bba717 2726 // calculate orientation orien of pcurves of Plate
2727 // the curves from ic to icplus the pcurves of Plate
2728 // all have the same orientation
7fd59977 2729 Standard_Integer Ishape1,Ishape2;
7fd59977 2730 TopAbs_Orientation trafil1 = TopAbs_FORWARD, trafil2 = TopAbs_FORWARD;
7fd59977 2731 Ishape1 = Fd->IndexOfS1();
2732 Ishape2 = Fd->IndexOfS2();
2733 const ChFiDS_FaceInterference& Fi1 = Fd->InterferenceOnS1();
2734 const ChFiDS_FaceInterference& Fi2 = Fd->InterferenceOnS2();
2735 if (Ishape1 != 0) {
2736 if (Ishape1 > 0) {
2737 trafil1 = DStr.Shape(Ishape1).Orientation();
2738 }
2739 trafil1 = TopAbs::Compose(trafil1,Fd->Orientation());
2740 trafil1 = TopAbs::Compose(TopAbs::Reverse(Fi1.Transition()),trafil1);
2741 trafil2 = TopAbs::Reverse(trafil1);
2742 }
2743 else {
2744 if (Ishape2 > 0) {
2745 trafil2 = DStr.Shape(Ishape2).Orientation();
2746 }
2747 trafil2 = TopAbs::Compose(trafil2,Fd->Orientation());
2748 trafil2 = TopAbs::Compose(TopAbs::Reverse(Fi2.Transition()),trafil2);
2749 trafil1 = TopAbs::Reverse(trafil2);
2750 }
2751 if (isfirst) {
2752 orpcurve=TopAbs::Reverse(trafil1);
2753 orpcurve= TopAbs::Compose(orpcurve,CD.Value(0)->FirstPCurveOrientation ()); }
2754 else {
2755 orpcurve=trafil1;
2756 orpcurve= TopAbs::Compose(orpcurve,CD.Value(0)->LastPCurveOrientation ());
2757 }
2758 if (orsurfdata==orplate)
2759 orien =TopAbs::Reverse(orpcurve);
2760 else orien=orpcurve;
2761
2762
2763 if (!droit)
2764 for (ic=0;ic<=nedge;ic++) {
2765 if (libre.Value(ic)) {
2766 Standard_Integer icplus21;
2767 Indices(nedge,ic,icplus,icmoins);
2768 Indices(nedge,icplus,icplus21,ic);
2769 gp_Pnt2d UV1,UV2;
2770 Handle (Geom_Curve) C3d;
2771 Handle (Geom2d_Curve) C2d,curv2d;
2772 gp_Pnt ptic,pticplus;
2773 BRepAdaptor_Curve BCurv1(TopoDS::Edge(Evive.Value(ic)));
2774 BRepAdaptor_Curve BCurv2(TopoDS::Edge(Evive.Value(icplus)));
2775 Standard_Real par1=p.Value(ic,icplus);
2776 Standard_Real par2=p.Value(icplus,ic);
2777 BCurv1.D0(par1,ptic);
2778 BCurv2.D0(par2,pticplus);
2779 ParametrePlate(n3d,PSurf,Surf,ptic,apperror,UV1);
2780 ParametrePlate(n3d,PSurf,Surf,pticplus,apperror,UV2);
2781 Standard_Real to3d=1.e-3,to2d=1.e-6,tolreached;
2782 ChFiDS_CommonPoint CP1,CP2;
2783 CP1.SetArc(1.e-3, TopoDS::Edge(Evive.Value(ic)),par1,TopAbs_FORWARD);
2784 CP1.SetPoint(ptic);
2785 CP2.SetArc(1.e-3, TopoDS::Edge(Evive.Value(icplus)),par2,TopAbs_FORWARD);
2786 CP2.SetPoint(pticplus);
2787 Standard_Real param1,param2;
2788 ChFi3d_ComputeArete( CP1,UV1,CP2,UV2,Surf,C3d,C2d,param1,param2,
2789 to3d,to2d,tolreached,0);
2790 TopOpeBRepDS_Curve tcurv3d( C3d,tolreached);
2791 Standard_Integer ind1,ind2;
2792 ind1=indpoint(ic,0);
2793 ind2=indpoint(icplus,0);
2794 Standard_Integer indcurv=DStr.AddCurve(tcurv3d);
2795 Interfp1=ChFi3d_FilPointInDS(TopAbs_FORWARD,indcurv,ind1,param1);
2796 Interfp2=ChFi3d_FilPointInDS(TopAbs_REVERSED,indcurv,ind2,param2);
2797 DStr.ChangeCurveInterferences(indcurv).Append(Interfp1);
2798 DStr.ChangeCurveInterferences(indcurv).Append(Interfp2);
2799 Interfc=ChFi3d_FilCurveInDS(indcurv,Isurf,C2d,orien);
2800 DStr.ChangeSurfaceInterferences(Isurf).Append(Interfc);
2801 }
2802 }
2803
2804 // stockage des courbes relatives aux stripes
2805 n3d = 0;
2806 for (ic=0; ic<nedge ;ic++) {
2807 if (!sharp.Value(ic)) {
2808 n3d++;
2809 Indices(nedge,ic,icplus,icmoins);
2810
2811 isfirst=(sens.Value(ic)==1);
81bba717 2812 // calculate curves interference relative to stripes
7fd59977 2813
2814 apperror=Mapp.CriterionError()*coef;
2815 pardeb=CD.Value(ic)->PCurve(isfirst)->FirstParameter();
2816 parfin=CD.Value(ic)->PCurve(isfirst)->LastParameter();
2817
2818 Interfp1=ChFi3d_FilPointInDS(TopAbs_FORWARD,indcurve3d.Value(n3d),
2819 indpoint.Value(ic,0),pardeb);
2820 Interfp2=ChFi3d_FilPointInDS(TopAbs_REVERSED,indcurve3d.Value(n3d),
2821 indpoint.Value(ic,1),parfin);
2822 DStr.ChangeCurveInterferences(indcurve3d.Value(n3d)).Append( Interfp1);
2823 DStr.ChangeCurveInterferences(indcurve3d.Value(n3d)).Append( Interfp2);
2824 TopOpeBRepDS_Curve& tcourb = DStr.ChangeCurve(indcurve3d.Value(n3d));
2825
2826 tcourb.Tolerance(errapp.Value(ic)+apperror);
2827 TopOpeBRepDS_Point& tpt1= DStr.ChangePoint(indpoint(ic,0));
2828 TopOpeBRepDS_Point& tpt2= DStr.ChangePoint(indpoint(ic,1));
2829 tpt1.Tolerance (tpt1.Tolerance()+apperror);
2830 tpt2.Tolerance (tpt2.Tolerance()+apperror );
2831
81bba717 2832 // calculate surfaceinterference
7fd59977 2833 Interfc=ChFi3d_FilCurveInDS(indcurve3d.Value(n3d),Isurf,
2834 PSurf.Curves2d()->Value(n3d),orien);
2835 DStr.ChangeSurfaceInterferences(Isurf).Append(Interfc);
2836 regular.SetCurve(indcurve3d.Value(n3d));
2837 regular.SetS1(Isurf,Standard_False);
2838 indice=CD.Value(ic)->SetOfSurfData()->Value( i.Value(ic,icmoins))->Surf();
2839 regular.SetS2(indice,Standard_False);
2840 myRegul.Append(regular);
2841 }
2842 }
2843
81bba717 2844 // storage of connection curves
7fd59977 2845
2846 for (ic=0; ic<nedge;ic++) {
2847 Indices(nedge,ic,icplus,icmoins);
2848 if (!oksea.Value(ic)) {
2849 if (sharp.Value(ic) &&!deuxconges) {
81bba717 2850 // limitation of the alive edge
7fd59977 2851 TopAbs_Orientation ori;
2852 gp_Pnt Pf,Pl,sommet1;
2853 TopoDS_Vertex Vd = TopExp::FirstVertex(TopoDS::Edge(Evive.Value(ic)));
2854 TopoDS_Vertex Vf = TopExp::LastVertex(TopoDS::Edge(Evive.Value(ic)));
2855 Pf=BRep_Tool::Pnt(Vd);
2856 Pl=BRep_Tool::Pnt(Vf);
2857 sommet1=BRep_Tool::Pnt(V1);
2858 if (Pf.Distance(sommet1)<Pl.Distance(sommet1))
2859 ori = TopAbs_FORWARD;
2860 else
2861 ori = TopAbs_REVERSED;
2862 Standard_Integer Iarc1=DStr.AddShape(TopoDS::Edge(Evive.Value(ic)));
2863 Interfp1=ChFi3d_FilPointInDS(ori,Iarc1,indpoint(ic,1),p.Value(ic,icplus));
2864 DStr.ChangeShapeInterferences(TopoDS::Edge(Evive.Value(ic))).Append(Interfp1);
2865 }
2866
2867 if (!ponctuel.Value(ic) && !libre.Value(ic)) {
81bba717 2868 // actual connection
7fd59977 2869 if (!moresurf.Value(ic)){
2870 n3d++;
2871 TopOpeBRepDS_Curve& tcourb1 = DStr.ChangeCurve(indcurve3d.Value(n3d));
2872 tcourb1.Tolerance(tcourb1.Tolerance()+apperror);
2873 if (!deuxconges) {
2874 TopOpeBRepDS_Point& tpt11= DStr.ChangePoint(indpoint(ic,1));
2875 TopOpeBRepDS_Point& tpt21= DStr.ChangePoint(indpoint(icplus,0));
2876 tpt11.Tolerance (tpt11.Tolerance()+apperror);
2877 tpt21.Tolerance (tpt21.Tolerance()+apperror );
2878 }
2879 Interfc=ChFi3d_FilCurveInDS(indcurve3d.Value(n3d),Isurf,
2880 PSurf.Curves2d()->Value(n3d),orien);
2881 DStr.ChangeSurfaceInterferences(Isurf).Append(Interfc);
2882 if( Order.Value(n3d)==1) {
2883 regular.SetCurve(indcurve3d.Value(n3d));
2884 regular.SetS1(Isurf,Standard_False);
2885 regular.SetS2(numfa.Value(ic,icplus));
2886 myRegul.Append(regular);
2887 }
2888 }
2889 }
2890 }
2891 }
2892
81bba717 2893 //storage of curves projected on several faces
7fd59977 2894 for (ic=0; ic<nedge;ic++) {
2895 Indices(nedge,ic,icplus,icmoins);
2896 if (moresurf(ic))
2897 for (nb=1;nb<=nbface;nb++){
2898 if (!Eproj.Value(nb).IsNull()) {
2899 n3d++;
2900 TopOpeBRepDS_Curve& tcourb1 = DStr.ChangeCurve(indcurve3d.Value(n3d));
2901 tcourb1.Tolerance(tcourb1.Tolerance()+apperror);
2902 if(Indice.Value(n3d)!=0) {
2903 TopOpeBRepDS_Point& tpt11= DStr.ChangePoint(Indice.Value(n3d));
2904 tpt11.Tolerance (tpt11.Tolerance()+apperror);
2905 }
2906 Interfc=ChFi3d_FilCurveInDS(indcurve3d.Value(n3d),Isurf,
2907 PSurf.Curves2d()->Value(n3d),orien);
2908 DStr.ChangeSurfaceInterferences(Isurf).Append(Interfc);
2909 if( Order.Value(n3d)==1) {
2910 regular.SetCurve(indcurve3d.Value(n3d));
2911 regular.SetS1(Isurf,Standard_False);
2912 regular.SetS2(DStr.AddShape(TopoDS::Face(Fproj.Value(nb))));
2913 myRegul.Append(regular);
2914 }
2915 }
2916 }
2917 }
2918
81bba717 2919 // storage of curves in case of tangent free borders
7fd59977 2920 if (droit)
2921 for (ic=0; ic<nedge;ic++) {
2922 Indices(nedge,ic,icplus,icmoins);
2923 TopoDS_Edge ecom;
2924 ecom=TopoDS::Edge(Evive.Value(ic));
2925 if (ecom.IsSame(edgelibre1)||ecom.IsSame(edgelibre2)) {
2926 n3d++;
2927 TopOpeBRepDS_Curve& tcourb1 = DStr.ChangeCurve(indcurve3d.Value(n3d));
2928 tcourb1.Tolerance(tcourb1.Tolerance()+apperror);
2929 Interfc=ChFi3d_FilCurveInDS(indcurve3d.Value(n3d),Isurf,
2930 PSurf.Curves2d()->Value(n3d),orien);
2931 DStr.ChangeSurfaceInterferences(Isurf).Append(Interfc);
2932 }
2933 }
2934 }
81bba717 2935 else { // there is only one partial result
7fd59977 2936 done=Standard_False;
2937 hasresult=Standard_True;
2938 for (ic=0; ic<nedge;ic++) {
2939 Indices(nedge,ic,icplus,icmoins);
2940 if (!oksea.Value(ic)) {
2941 if (sharp.Value(ic) &&!deuxconges) {
81bba717 2942 // limitation of the alive edge
7fd59977 2943 TopAbs_Orientation ori;
2944 gp_Pnt Pf,Pl,sommet1;
2945 TopoDS_Vertex Vd = TopExp::FirstVertex(TopoDS::Edge(Evive.Value(ic)));
2946 TopoDS_Vertex Vf = TopExp::LastVertex(TopoDS::Edge(Evive.Value(ic)));
2947 Pf=BRep_Tool::Pnt(Vd);
2948 Pl=BRep_Tool::Pnt(Vf);
2949 sommet1=BRep_Tool::Pnt(V1);
2950 if (Pf.Distance(sommet1)<Pl.Distance(sommet1))
2951 ori = TopAbs_FORWARD;
2952 else
2953 ori = TopAbs_REVERSED;
2954 Standard_Integer Iarc1=DStr.AddShape(TopoDS::Edge(Evive.Value(ic)));
2955 Interfp1=ChFi3d_FilPointInDS(ori,Iarc1,indpoint(ic,1),p.Value(ic,icplus));
2956 DStr.ChangeShapeInterferences(TopoDS::Edge(Evive.Value(ic))).Append(Interfp1);
2957 }
2958 }
2959 }
2960 }
2961}