0026586: Eliminate compile warnings obtained by building occt with vc14: declaration...
[occt.git] / src / LocOpe / LocOpe_Generator.cxx
CommitLineData
b311480e 1// Created on: 1996-01-09
2// Created by: Jacques GOUSSARD
3// Copyright (c) 1996-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// Modifed: Portage NT 7-5-97 DPF (return NewParameter)
18
7fd59977 19#include <BRep_Builder.hxx>
20#include <BRep_Tool.hxx>
21#include <BRepAlgo_Loop.hxx>
42cf5bc1 22#include <BRepTools.hxx>
23#include <ElCLib.hxx>
24#include <Geom2d_Curve.hxx>
25#include <Geom_Circle.hxx>
7fd59977 26#include <Geom_Curve.hxx>
42cf5bc1 27#include <Geom_CylindricalSurface.hxx>
7fd59977 28#include <Geom_Line.hxx>
42cf5bc1 29#include <Geom_Plane.hxx>
30#include <Geom_RectangularTrimmedSurface.hxx>
31#include <Geom_Surface.hxx>
32#include <Geom_TrimmedCurve.hxx>
7fd59977 33#include <GeomProjLib.hxx>
42cf5bc1 34#include <gp_Cylinder.hxx>
35#include <gp_Pln.hxx>
36#include <LocOpe_BuildShape.hxx>
37#include <LocOpe_GeneratedShape.hxx>
38#include <LocOpe_Generator.hxx>
7fd59977 39#include <Precision.hxx>
42cf5bc1 40#include <Standard_NoSuchObject.hxx>
41#include <Standard_NullObject.hxx>
42#include <StdFail_NotDone.hxx>
43#include <TopExp.hxx>
44#include <TopExp_Explorer.hxx>
45#include <TopoDS.hxx>
46#include <TopoDS_Edge.hxx>
47#include <TopoDS_Face.hxx>
48#include <TopoDS_Iterator.hxx>
49#include <TopoDS_Shape.hxx>
50#include <TopoDS_Solid.hxx>
51#include <TopoDS_Vertex.hxx>
52#include <TopoDS_Wire.hxx>
53#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
54#include <TopTools_DataMapOfShapeListOfShape.hxx>
55#include <TopTools_DataMapOfShapeShape.hxx>
56#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
57#include <TopTools_ListIteratorOfListOfShape.hxx>
58#include <TopTools_MapIteratorOfMapOfShape.hxx>
59#include <TopTools_MapOfShape.hxx>
7fd59977 60
61static Standard_Boolean ToFuse(const TopoDS_Face& ,
62 const TopoDS_Face&);
63
64
65static Standard_Boolean ToFuse(const TopoDS_Edge& ,
66 const TopoDS_Edge&);
67
68
69static Standard_Boolean ToFuse(const TopoDS_Edge&,
70 const TopoDS_Face&,
71 const TopoDS_Vertex&,
72 const TopTools_MapOfShape&);
73
74static Standard_Real NewParameter(const TopoDS_Edge&,
75 const TopoDS_Vertex&,
76 const TopoDS_Edge&,
77 const TopoDS_Vertex&);
78
7fd59977 79
80//=======================================================================
81//function : Perform
82//purpose :
83//=======================================================================
84
85void LocOpe_Generator::Perform(const Handle(LocOpe_GeneratedShape)& G)
86{
87 if (myShape.IsNull()) {
88 Standard_NullObject::Raise();
89 }
90 myDone = Standard_False;
91 myRes.Nullify();
92// myDescFaces.Clear();
93 myModShapes.Clear();
94// myFFromE.Clear();
95
96 const TopTools_ListOfShape& ledges = G->GeneratingEdges();
97
98 // On genere une liste des faces a gauche du wire. Equivalent du LeftOf.
99 // Attention : il faudra bien propager pour ne pas oublier des faces
100 // a l`interieur
101
102 TopExp_Explorer exp, exp2, exp3;
103 TopTools_MapOfShape theLeft; // Faces a gauche
104
105 TopTools_MapOfShape GEdg,GVtx; // Edges et vertex generateurs
106
107 TopTools_ListIteratorOfListOfShape itl,itl2;
108
109
110 for (itl.Initialize(ledges); itl.More(); itl.Next()) {
111 const TopoDS_Edge& edg = TopoDS::Edge(itl.Value());
112
113 GEdg.Add(edg);
114 for (exp2.Init(edg,TopAbs_VERTEX); exp2.More(); exp2.Next()) {
115 const TopoDS_Vertex& vtx = TopoDS::Vertex(exp2.Current());
116 if (!GVtx.Contains(vtx)) {
117 GVtx.Add(vtx);
118 }
119 }
120 for (exp2.Init(myShape, TopAbs_FACE); exp2.More(); exp2.Next()) {
121 const TopoDS_Face& fac = TopoDS::Face(exp2.Current());
122 for (exp3.Init(fac,TopAbs_EDGE); exp3.More(); exp3.Next()) {
123 if (exp3.Current().IsSame(edg) &&
124 exp3.Current().Orientation() == edg.Orientation()) {
125 theLeft.Add(fac);
126 TopTools_ListOfShape emptylist;
127 if(!myModShapes.IsBound(fac)) {
128 myModShapes.Bind(fac,emptylist);
129 }
130 break;
131 }
132 }
133 if (exp3.More()) {
134 break;
135 }
136 }
137 }
138
139 TopTools_IndexedDataMapOfShapeListOfShape theEFMap;
140 TopExp::MapShapesAndAncestors(myShape,TopAbs_EDGE,TopAbs_FACE,theEFMap);
141
142 TopTools_DataMapOfShapeListOfShape theEEMap;
143 TopTools_DataMapOfShapeListOfShape theFFMap;
144 TopTools_MapOfShape toRemove;
145 TopTools_MapIteratorOfMapOfShape itm;
146 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itf;
147
148 // recherche des fusions de faces
149 for (itm.Initialize(GEdg); itm.More(); itm.Next()) {
150 const TopoDS_Edge& edg = TopoDS::Edge(itm.Key());
151 if (!theEFMap.Contains(edg)) {
152 continue;
153 }
154 for (itl2.Initialize(theEFMap.FindFromKey(edg));itl2.More();itl2.Next()){
155 if (!theLeft.Contains(itl2.Value())) {
156 break;
157 }
158 }
159 if (!itl2.More()) { // edge "interne" au shell, ou bord libre
160 }
161 else {
162 const TopoDS_Face& fac = TopoDS::Face(itl2.Value());
163 TopoDS_Face facbis = G->Generated(edg);
164 if (ToFuse(fac,facbis)) {
165 // On recherche si une face a deja fusionne avec facbis
166 Standard_Boolean facbisfound = Standard_False;
167 for (itf.Initialize(theFFMap); itf.More(); itf.Next()) {
168 if (itf.Key().IsSame(fac)) {
169 continue;
170 }
171 for (itl.Initialize(itf.Value()); itl.More(); itl.Next()) {
172 if (itl.Value().IsSame(facbis)) {
173 facbisfound = Standard_True;
174 break;
175 }
176 }
177 if (facbisfound) {
178 theFFMap(itf.Key()).Append(fac);
179 toRemove.Add(fac);
180 toRemove.Add(edg);
181 break;
182 }
183 }
184
185 if (!facbisfound) {
186 if (!theFFMap.IsBound(fac)) {
187 TopTools_ListOfShape thelist;
188 theFFMap.Bind(fac, thelist);
189 }
190 for (itl.Initialize(theFFMap(fac)); itl.More(); itl.Next()) {
191 if (itl.Value().IsSame(facbis)) {
192 break;
193 }
194 }
195 if (!itl.More()) {
196 theFFMap(fac).Append(facbis);
197 }
198 toRemove.Add(edg);
199 toRemove.Add(facbis);
200 }
201 }
202 else { // face generee par edg : on la marque.
203// myFFromE.Bind(edg,facbis);
204 }
205 }
206 }
207
208
209 // Il faut ici ajouter dans toRemove les edges de connexites entre faces
210 // a fusionner avec une meme face de base
211
212// TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itf(theFFMap);
213 itf.Initialize(theFFMap);
214 for (; itf.More(); itf.Next()) {
215 for (itl.Initialize(itf.Value()); itl.More(); itl.Next()) {
216 for (exp.Init(itl.Value(),TopAbs_EDGE); exp.More(); exp.Next()) {
217 const TopoDS_Edge& ed = TopoDS::Edge(exp.Current());
218 if (toRemove.Contains(ed)) {
219 continue;
220 }
221 for (itl2.Initialize(itf.Value()); itl2.More(); itl2.Next()) {
222 if (!itl2.Value().IsSame(itl.Value())) {
223 for (exp2.Init(itl2.Value(),TopAbs_EDGE);exp2.More();exp2.Next()) {
224 if (ed.IsSame(exp2.Current())) {
225 toRemove.Add(ed);
226 break;
227 }
228 }
229 if (exp2.More()) {
230 break;
231 }
232 }
233 }
234 }
235 }
236 }
237
238 TopTools_ListOfShape RebuildFace;
239 TopTools_MapOfShape mapTreated;
240 TopTools_DataMapOfShapeShape DontFuse;
96a95605 241 TopAbs_Orientation orient,orface;
7fd59977 242
243 for (itf.Reset(); itf.More(); itf.Next()) {
244 const TopoDS_Face& fac = TopoDS::Face(itf.Key());
245 for (exp.Init(fac,TopAbs_EDGE); exp.More(); exp.Next()) {
246 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
247 if (mapTreated.Contains(edg)) {
248 continue; // on saute l`edge
249 }
250
251 mapTreated.Add(edg);
252 for (exp2.Init(edg,TopAbs_VERTEX); exp2.More(); exp2.Next()) {
253 const TopoDS_Vertex& vtx = TopoDS::Vertex(exp2.Current());
254 if (GVtx.Contains(vtx)) {
255 TopoDS_Edge edgbis = G->Generated(vtx);
256
257 if ((edgbis.IsNull() || BRep_Tool::Degenerated(edgbis)) ||
258// toRemove.Contains(edgbis) ||
259 !ToFuse(edg,edgbis)) {
260 continue;
261 }
262// a voir
263 if (BRepTools::IsReallyClosed(edg,fac)) {
264 if (!theEEMap.IsBound(edg)) {
265 TopTools_ListOfShape thelist1;
266 theEEMap.Bind(edg, thelist1);
267 theEEMap(edg).Append(edgbis);
268 toRemove.Add(edgbis); // toujours vrai pour edge double
269 Standard_Boolean FuseEdge = Standard_True;
270 TopoDS_Vertex Vf,Vl;
271 TopExp::Vertices(edg,Vf,Vl);
272 Standard_Boolean ConnectLast = (Vl.IsSame(vtx));
273 for (exp3.Init(fac.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
274 exp3.More(); exp3.Next()) {
275 const TopoDS_Edge& eee = TopoDS::Edge(exp3.Current());
276 orient = eee.Orientation();
277 if (!eee.IsSame(edg)) {
278 TopExp::Vertices(eee,Vf,Vl);
279 if ((Vf.IsSame(vtx) || Vl.IsSame(vtx)) &&
280 !toRemove.Contains(eee)) {
281 FuseEdge = Standard_False;
282 // On recherche celui qu`il ne faut pas fusionner
283
284 if ((Vf.IsSame(vtx) && orient == TopAbs_FORWARD) ||
285 (Vl.IsSame(vtx) && orient == TopAbs_REVERSED)) {
286 if (ConnectLast) {
287 DontFuse.Bind(edg,fac.Oriented(TopAbs_FORWARD));
288 }
289 else {
290 DontFuse.Bind(edg,fac.Oriented(TopAbs_REVERSED));
291 }
292 }
293 else {
294 if (ConnectLast) {
295 DontFuse.Bind(edg,fac.Oriented(TopAbs_REVERSED));
296 }
297 else {
298 DontFuse.Bind(edg,fac.Oriented(TopAbs_FORWARD));
299 }
300 }
301 break;
302 }
303 }
304 }
305 if (FuseEdge) {
306 toRemove.Add(vtx);
307 }
308 }
309 }
310
311
312 else {
313/* A VOIR
314 if (!BRep_Tool::IsClosed(edg,fac)) {
315*/
316 if (!theEEMap.IsBound(edg)) {
317 TopTools_ListOfShape thelist2;
318 theEEMap.Bind(edg, thelist2);
319 }
320 theEEMap(edg).Append(edgbis);
321 const TopTools_ListOfShape& L = theEEMap(edg);
322 TopTools_ListIteratorOfListOfShape Lit(L);
323 Standard_Boolean OK = Standard_True;
324 for (; Lit.More(); Lit.Next()) {
325 if (Lit.Value().IsSame(edgbis)) {
326 OK = Standard_False;
327 break;
328 }
329 }
330 if (OK) theEEMap(edg).Append(edgbis);
331
332 itl.Initialize(theEFMap.FindFromKey(edg));
333 Standard_Boolean FuseEdge = ToFuse(edg,fac,vtx,toRemove);
334 if (!FuseEdge) {
335 DontFuse.Bind(edg,fac);
336 }
337 else {
338 for (; itl.More(); itl.Next()) {
339 if (!itl.Value().IsSame(fac)) {
340 if (theFFMap.IsBound(itl.Value())) {
341 FuseEdge = ToFuse(edg,TopoDS::Face(itl.Value()),
342 vtx,toRemove);
343 // edge a fusionner
344 if (FuseEdge) {
345 toRemove.Add(vtx);
346 }
347 else {
348 if (toRemove.Contains(vtx)) {
349 toRemove.Remove(vtx);
350 }
351 DontFuse.Bind(edg,itl.Value());
352 }
353 }
354 else { // on marque comme face a reconstruire
355 RebuildFace.Append(itl.Value());
356 if (toRemove.Contains(vtx)) {
357 toRemove.Remove(vtx);
358 }
359 DontFuse.Bind(edg,itl.Value());
360 }
361
362 break;
363 }
364 }
365 }
366 }
367 }
368 }
369 }
370 }
371
372
373
374 for (itl.Initialize(RebuildFace); itl.More(); itl.Next()) {
375 TopTools_ListOfShape thelist3;
376 theFFMap.Bind(itl.Value(), thelist3);
377 }
378
379 BRep_Builder B;
380 TopoDS_Face newface;
381 TopoDS_Wire outw,newwire;
382 TopoDS_Edge newedg;
383 TopoDS_Vertex newvtx;
384 TopLoc_Location loc;
1d47d8d0 385 Standard_Real tol,prm,f,l, Uminc = 0.,Umaxc = 0.;
7fd59977 386 gp_Pnt2d pf,pl;
387
388 Handle(Geom_Surface) S;
389 Handle(Geom_Plane) P;
390 Handle(Geom_Curve) C;
391
392 // Fusion des edges
393 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape ite(theEEMap);
394 for (; ite.More(); ite.Next()) {
395 Standard_Boolean KeepNewEdge = Standard_False;
396 const TopoDS_Edge& edg = TopoDS::Edge(ite.Key());
397 BRep_Tool::Range(edg,f,l);
398 TopoDS_Shape aLocalEdge = edg.EmptyCopied();
399 newedg = TopoDS::Edge(aLocalEdge);
400// newedg = TopoDS::Edge(edg.EmptyCopied());
401 newedg.Orientation(TopAbs_FORWARD);
402 for (exp.Init(edg.Oriented(TopAbs_FORWARD),TopAbs_VERTEX);
403 exp.More(); exp.Next()) {
404 const TopoDS_Vertex& vtx = TopoDS::Vertex(exp.Current());
405 prm = BRep_Tool::Parameter(vtx,edg);
406
407 newvtx.Nullify();
408 for (itl.Initialize(theEEMap(edg)); itl.More(); itl.Next()) {
409 const TopoDS_Edge& edgbis = TopoDS::Edge(itl.Value());
410 for (exp2.Init(edgbis,TopAbs_VERTEX); exp2.More(); exp2.Next()) {
411 if (exp2.Current().IsSame(vtx)) {
412 break;
413 }
414 }
415 if (exp2.More()) {
416 for (exp2.ReInit(); exp2.More(); exp2.Next()) {
417 if (!exp2.Current().IsSame(vtx)) {
418 newvtx = TopoDS::Vertex(exp2.Current());
419 prm = NewParameter(edg,vtx,newedg,newvtx);
420 break;
421 }
422 }
423 break;
424 }
425 }
426
427 if (toRemove.Contains(vtx) ||
428 (prm <l && prm > f)) {
429 B.Add(newedg,newvtx.Oriented(vtx.Orientation()));
430 tol = BRep_Tool::Tolerance(newvtx);
431 B.UpdateVertex(newvtx,prm,newedg,tol);
432 toRemove.Add(itl.Value()); // i-e edgbis
433 KeepNewEdge = Standard_True;
434 }
435 else {
436 B.Add(newedg,vtx.Oriented(vtx.Orientation()));
437 tol = BRep_Tool::Tolerance(vtx);
438 B.UpdateVertex(vtx,prm,newedg,tol);
439 }
440 }
441 if (KeepNewEdge) {
442 TopTools_ListOfShape emptylist;
443 if(!myModShapes.IsBound(edg)) {
444 myModShapes.Bind(edg,emptylist);
445 }
446 myModShapes(edg).Append(newedg);
447 toRemove.Add(edg);
448 }
449 }
450
451 TopTools_MapOfShape EdgAdded;
452
453 // Fusion des faces, ou reconstruction
454 for (itf.Reset();itf.More(); itf.Next()) {
455 const TopoDS_Face& fac = TopoDS::Face(itf.Key());
456 Standard_Boolean ModFace = Standard_False;
7fd59977 457 TopTools_ListOfShape listofedg;
458
459 EdgAdded.Clear();
460
461 for(exp.Init(myShape,TopAbs_FACE); exp.More(); exp.Next()) {
462 if (exp.Current().IsSame(fac)) {
463 break;
464 }
465 }
466 orface = exp.Current().Orientation();
51740958 467 TopoDS_Shape aLocalFaceEmptyCopied = fac.EmptyCopied();
468 newface = TopoDS::Face(aLocalFaceEmptyCopied);
7fd59977 469// newface = TopoDS::Face(fac.EmptyCopied());
470 newface.Orientation(TopAbs_FORWARD);
471 S = BRep_Tool::Surface(fac);
472 if (S->DynamicType()== STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
c5f3a425 473 S = Handle(Geom_RectangularTrimmedSurface)::DownCast (S)->BasisSurface();
7fd59977 474 }
475 P = Handle(Geom_Plane)::DownCast(S);
476 TopoDS_Wire wir;
477 for (exp.Init(fac.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
478 exp.More(); exp.Next()) {
479 wir = TopoDS::Wire(exp.Current());
480 for (exp2.Init(wir,TopAbs_EDGE); exp2.More(); exp2.Next()) {
481 const TopoDS_Edge& edg = TopoDS::Edge(exp2.Current());
482 if (toRemove.Contains(edg) || myModShapes.IsBound(edg) ) {
483 break;
484 }
485 }
486 if (!exp2.More()) { // wire non modifie
487// B.Add(newface,wir.Oriented(wir.Orientation()));
488 for (exp2.Init(wir,TopAbs_EDGE); exp2.More(); exp2.Next()) {
489 listofedg.Append(exp2.Current());
490 }
7fd59977 491 }
492 else {
493 if (!ModFace) {
494
495 // Petit truc crad pour les p-curves sur les cylindres...
496 if (P.IsNull()) {
497 Standard_Real Vminc,Vmaxc;
498 BRepTools::UVBounds(fac,Uminc,Umaxc,Vminc,Vmaxc);
499 }
500
501
502 // premier passage : on met les wires non touches des faces
503 // en vis a vis
504
505 for (itl.Initialize(itf.Value()); itl.More(); itl.Next()) {
506 TopoDS_Face facbis = TopoDS::Face(itl.Value());
507 for (itl2.Initialize(G->OrientedFaces());itl2.More();itl2.Next()) {
508 if (itl2.Value().IsSame(facbis)) {
509 break;
510 }
511 }
512 if (itl2.More()) {
513 orient = itl2.Value().Orientation();
514 facbis.Orientation(orient);
515 }
516 else { // on fusionne avec une autre face du shape...
517 for (exp2.Init(myShape, TopAbs_FACE); exp2.More(); exp2.Next()) {
518 if (exp2.Current().IsSame(facbis)) {
519 facbis.Orientation(exp2.Current().Orientation());
520 break;
521 }
522 }
523 }
524
525 for (exp3.Init(facbis,TopAbs_WIRE); exp3.More(); exp3.Next()) {
526 for (exp2.Init(exp3.Current(),TopAbs_EDGE);
527 exp2.More(); exp2.Next()) {
528 if (toRemove.Contains(exp2.Current())) {
529 break;
530 }
531 }
532 if (!exp2.More()) {
533 TopoDS_Wire theNew;
534 B.MakeWire(theNew); // FORWARD
535 for (exp2.ReInit(); exp2.More(); exp2.Next()) {
536 const TopoDS_Edge& edg = TopoDS::Edge(exp2.Current());
537
538 orient = TopAbs::Compose(orface,edg.Orientation());
539// B.Add(theNew,edg.Oriented(or));
540 listofedg.Append(edg.Oriented(orient));
541 EdgAdded.Add(edg);
542 if (P.IsNull()) {
543 // on met les courbes 2d si on n`est pas sur un plan
544 // on ne devrait pas avoir de pb d`edge de couture.
545 tol = BRep_Tool::Tolerance(edg);
546 C = BRep_Tool::Curve(edg,loc,f,l);
547 if (!loc.IsIdentity()) {
548 Handle(Geom_Geometry) GG = C->Transformed(loc.Transformation());
c5f3a425 549 C = Handle(Geom_Curve)::DownCast (GG);
7fd59977 550 }
551 if (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
c5f3a425 552 C = Handle(Geom_TrimmedCurve)::DownCast (C)->BasisCurve();
7fd59977 553 }
554
555 Handle(Geom2d_Curve) C2d = GeomProjLib::Curve2d(C,f,l,S,tol);
556
557 // Tentative de recalage dans la facette
558 pf = C2d->Value(f);
559 pl = C2d->Value(l);
560 Standard_Real tttol = Precision::Angular();
561 while (Min(pf.X(),pl.X()) >= Umaxc-tttol) {
c6541a0c 562 C2d->Translate(gp_Vec2d(-2.*M_PI,0));
7fd59977 563 pf = C2d->Value(f);
564 pl = C2d->Value(l);
565 }
566
567 while (Max(pf.X(),pl.X()) <= Uminc+tttol) {
c6541a0c 568 C2d->Translate(gp_Vec2d(2.*M_PI,0));
7fd59977 569 pf = C2d->Value(f);
570 pl = C2d->Value(l);
571 }
572
573 if (!BRepTools::IsReallyClosed(edg,facbis)) {
574 B.UpdateEdge(edg,C2d,newface,tol);
575 }
576 // else {
577 // cout << "Edge double bizarre... " << endl;
578 // }
579 }
580 }
581// B.Add(newface,theNew);
7fd59977 582 }
583 }
584 }
585 ModFace = Standard_True;
586 }
587
7fd59977 588 // reconstruction du wire
589 //B.MakeWire(newwire);
590
591 Handle(Geom2d_Curve) C2d,C2d1;
7fd59977 592
593// for (exp2.Init(wir.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
594 for (exp2.Init(wir,TopAbs_EDGE); exp2.More(); exp2.Next()) {
595 const TopoDS_Edge& edg = TopoDS::Edge(exp2.Current());
596 orient = edg.Orientation();
597 if (!toRemove.Contains(edg) && !theEEMap.IsBound(edg)) {
598// B.Add(newwire,edg.Oriented(or));
599// listofedg.Append(edg.Oriented(or));
600 listofedg.Append(edg);
7fd59977 601 }
602 else if (myModShapes.IsBound(edg) || theEEMap.IsBound(edg)) {
603 if (myModShapes.IsBound(edg)) {
604 newedg = TopoDS::Edge(myModShapes(edg).First());
605 }
606 else {
607 newedg = edg;
608 }
609// B.Add(newwire,newedg.Oriented(or));
610 listofedg.Append(newedg.Oriented(orient));
7fd59977 611 C = BRep_Tool::Curve(newedg,loc,f,l);
612 if (!loc.IsIdentity()) {
613 Handle(Geom_Geometry) GG = C->Transformed(loc.Transformation());
c5f3a425 614 C = Handle(Geom_Curve)::DownCast (GG);
7fd59977 615 }
616 if (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
c5f3a425 617 C = Handle(Geom_TrimmedCurve)::DownCast (C)->BasisCurve();
7fd59977 618 }
619 if (P.IsNull()) { // on met les courbes 2d si on n`est pas
620 // sur un plan
621// TopAbs_Orientation oredonfafw = TopAbs::Compose(or,orsav);
622 TopAbs_Orientation oredonfafw = orient;
623 tol = BRep_Tool::Tolerance(newedg);
624 TopoDS_Shape aLocalEdge = edg.Oriented(oredonfafw);
625 TopoDS_Shape aLocalFace = fac.Oriented(TopAbs_FORWARD);
626 C2d = BRep_Tool::CurveOnSurface
627 (TopoDS::Edge(aLocalEdge),TopoDS::Face(aLocalFace),f,l);
628// C2d = BRep_Tool::CurveOnSurface
629// (TopoDS::Edge(edg.Oriented(oredonfafw)),
630// TopoDS::Face(fac.Oriented(TopAbs_FORWARD)),
631// f,l);
632
633 if (!BRepTools::IsReallyClosed(edg,fac)) {
634 B.UpdateEdge(newedg,C2d,newface,tol);
635 }
636 else if (C2d1.IsNull()){
637 C2d1 = C2d;
638 }
639 else {
640// if (TopAbs::Compose(orsav,or) == TopAbs_FORWARD) {
641 if (orient == TopAbs_FORWARD) {
642 B.UpdateEdge(newedg,C2d,C2d1,newface,tol);
643 }
644 else {
645 B.UpdateEdge(newedg,C2d1,C2d,newface,tol);
646 }
647 }
648 }
649 Standard_Boolean AddPart = Standard_False;
650 if (DontFuse.IsBound(edg)) {
651 if (!BRepTools::IsReallyClosed(edg,fac)) {
652 if (DontFuse(edg).IsSame(fac)) {
653 if (myModShapes.IsBound(edg)) {
654 AddPart = Standard_True;
655 }
656 }
657 else if (!toRemove.Contains(edg)) {
658 AddPart = Standard_True;
659 }
660
661 }
662 else {
663 if (myModShapes.IsBound(edg)) { // edg raccourci
664// if (TopAbs::Compose(orsav,or)==DontFuse(edg).Orientation()){
665 if (orient == DontFuse(edg).Orientation()){
666 AddPart = Standard_True;
667 }
668 }
669 else {
670// if (TopAbs::Compose(orsav,or) ==
671 if (orient ==
672 TopAbs::Reverse(DontFuse(edg).Orientation())) {
673 AddPart = Standard_True;
674 }
675 }
676 }
677 }
678 if (AddPart) {
679 itl2.Initialize(theEEMap(edg));
680 gp_Vec dir1,dir2;
681 for (; itl2.More(); itl2.Next()) {
682 if (EdgAdded.Contains(itl2.Value())) {
683 continue;
684 }
685 const TopoDS_Edge& edgbis = TopoDS::Edge(itl2.Value());
686 TopoDS_Iterator it1(newedg),it2;
687 for (; it1.More(); it1.Next()) {
688 for (it2.Initialize(edgbis); it2.More(); it2.Next()) {
689 if (it1.Value().IsSame(it2.Value())) {
690 break;
691 }
692 }
693 if (it2.More()) {
694 break;
695 }
696 }
697
698 if (it1.More()) {
699 gp_Pnt ptbid;
700 Standard_Real prmvt =
701 BRep_Tool::Parameter(TopoDS::Vertex(it1.Value()),newedg);
702 C->D1(prmvt,ptbid,dir1);
703
704
705 C = BRep_Tool::Curve(edgbis,loc,f,l);
706 if (!loc.IsIdentity()) {
707 Handle(Geom_Geometry) GG = C->Transformed(loc.Transformation());
c5f3a425 708 C = Handle(Geom_Curve)::DownCast (GG);
7fd59977 709 }
710 if (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
c5f3a425 711 C = Handle(Geom_TrimmedCurve)::DownCast (C)->BasisCurve();
7fd59977 712 }
713 prmvt =
714 BRep_Tool::Parameter(TopoDS::Vertex(it1.Value()),edgbis);
715 C->D1(prmvt,ptbid,dir2);
716 }
717 else {
718 dir1 = dir2 = gp_Vec(1,0,0);
719 }
720 EdgAdded.Add(edgbis);
721 if (dir1.Dot(dir2) <0.) {
722// B.Add(newwire,edgbis.Oriented(TopAbs::Reverse(or)));
723 listofedg.Append(edgbis.Oriented(TopAbs::Reverse(orient)));
724 }
725 else {
726// B.Add(newwire,edgbis.Oriented(or));
727 listofedg.Append(edgbis.Oriented(orient));
728 }
729
730
731 if (P.IsNull()) {
732 // on met les courbes 2d si on n`est pas sur un plan
733 // C est la courbe de edgbis, f et l s`y rapportent
734 Handle(Geom2d_Curve) PTC = GeomProjLib::Curve2d(C,f,l,S,tol);
735 if (S->IsUPeriodic()) {
736 Standard_Real Uref;
737 if (DontFuse.IsBound(edg)) {
738 TopAbs_Orientation oredge = DontFuse(edg).Orientation();
739 if (myModShapes.IsBound(edg)) { // edge raccourci...
740 TopoDS_Shape aLocalShape = edg.Oriented(oredge);
741 TopoDS_Shape aLocalFace = fac.Oriented(TopAbs_FORWARD);
742 BRep_Tool::
743 UVPoints(TopoDS::Edge(aLocalShape),TopoDS::Face(aLocalFace),pf,pl);
744// BRep_Tool::
745// UVPoints(TopoDS::Edge(edg.Oriented(oredge)),
746// TopoDS::Face(fac.Oriented(TopAbs_FORWARD)),
747// pf,pl);
748 }
749 else {
750 TopoDS_Shape aLocalShape = edg.Oriented(TopAbs::Reverse(oredge));
751 TopoDS_Shape aLocalFace = fac.Oriented(TopAbs_FORWARD);
752 BRep_Tool::
753 UVPoints(TopoDS::Edge(aLocalShape),TopoDS::Face(aLocalFace),pf,pl);
754// BRep_Tool::
755// UVPoints(TopoDS::Edge(edg.Oriented(TopAbs::Reverse(oredge))),
756// TopoDS::Face(fac.Oriented(TopAbs_FORWARD)),
757// pf,pl);
758 }
759 Uref = pf.X();
760 }
761 else {
762 BRep_Tool::UVPoints(edg,fac,pf,pl);
763 Uref = pf.X();
764 }
765
766 Standard_Real NewU = (PTC->Value(f)).X();
767
768// if(abs(NewU - Uref) > Epsilon(S->UPeriod())) {
769 if(fabs(NewU - Uref) > Epsilon(S->UPeriod())) {
770 PTC -> Translate(gp_Vec2d((Uref - NewU), 0.));
771 }
772 }
773
774 B.UpdateEdge(edgbis,PTC,newface,tol);
775 }
776 }
777 }
778 }
779 }
780
781 // Recuperation des edges sur les faces a fusionner.
782
783// ICICICICI
784
785// orface = TopAbs::Compose(orsav,orface);
786
787 Standard_Boolean includeinw = Standard_False;
788 for (itl.Initialize(itf.Value()); itl.More(); itl.Next()) {
789 TopoDS_Face facbis = TopoDS::Face(itl.Value());
790 Standard_Boolean genface = Standard_True;
791 for (itl2.Initialize(G->OrientedFaces()); itl2.More(); itl2.Next()) {
792 if (itl2.Value().IsSame(facbis)) {
793 break;
794 }
795 }
796 if (itl2.More()) {
797 orient = itl2.Value().Orientation();
798 facbis.Orientation(orient);
799 }
800 else { // on fusionne avec une autre face du shape...
801 genface = Standard_False;
802 for (exp2.Init(myShape, TopAbs_FACE); exp2.More(); exp2.Next()) {
803 if (exp2.Current().IsSame(facbis)) {
804 facbis.Orientation(exp2.Current().Orientation());
805 break;
806 }
807 }
808 }
809
810 for (exp3.Init(facbis,TopAbs_WIRE); exp3.More(); exp3.Next()) {
811 for (exp2.Init(exp3.Current(),TopAbs_EDGE);
812 exp2.More(); exp2.Next()) {
813 if (toRemove.Contains(exp2.Current())) {
814 break;
815 }
816 }
817 if (genface) {
818 includeinw = Standard_True;
819 }
820 else {
51740958 821 Standard_Boolean isIncludedInW = Standard_False;
7fd59977 822 if (exp2.More()) {
823 for (exp2.ReInit(); exp2.More(); exp2.Next()) {
824 if (!toRemove.Contains(exp2.Current())) {
825 continue;
826 }
827 TopoDS_Vertex VF,VL;
828 TopExp::Vertices(TopoDS::Edge(exp2.Current()),VF,VL);
829 TopExp_Explorer exp4;
830 for (exp4.Init(wir,TopAbs_VERTEX);
831// for (TopExp_Explorer exp4(wir,TopAbs_VERTEX);
832 exp4.More(); exp4.Next()) {
833 if (exp4.Current().IsSame(VF) ||
834 exp4.Current().IsSame(VL)) {
51740958 835 isIncludedInW = Standard_True;
7fd59977 836 break;
837 }
838 }
51740958 839 if (isIncludedInW) {
7fd59977 840 break;
841 }
842 }
843 }
844 }
845
846 if (!includeinw) {
847 continue;
848 }
849
850 for (exp2.ReInit(); exp2.More(); exp2.Next()) {
851 const TopoDS_Edge& edg = TopoDS::Edge(exp2.Current());
852 if (!toRemove.Contains(edg) && !EdgAdded.Contains(edg)) {
853
854 orient = TopAbs::Compose(orface,edg.Orientation());
855 // B.Add(newwire,edg.Oriented(or));
856 listofedg.Append(edg.Oriented(orient));
7fd59977 857 EdgAdded.Add(edg);
858 if (P.IsNull()) {
859 // on met les courbes 2d si on n`est pas sur un plan
860 // on ne devrait pas avoir de pb d`edge de couture.
861 tol = BRep_Tool::Tolerance(edg);
862 C = BRep_Tool::Curve(edg,loc,f,l);
863 if (!loc.IsIdentity()) {
864 Handle(Geom_Geometry) GG = C->Transformed(loc.Transformation());
c5f3a425 865 C = Handle(Geom_Curve)::DownCast (GG);
7fd59977 866 }
867 if (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
c5f3a425 868 C = Handle(Geom_TrimmedCurve)::DownCast (C)->BasisCurve();
7fd59977 869 }
870
871 C2d = GeomProjLib::Curve2d(C,f,l,S,tol);
872
873 // Tentative de recalage dans la facette
874 pf = C2d->Value(f);
875 pl = C2d->Value(l);
876 Standard_Real tttol = Precision::Angular();
877 while (Min(pf.X(),pl.X()) >= Umaxc - tttol) {
c6541a0c 878 C2d->Translate(gp_Vec2d(-2.*M_PI,0));
7fd59977 879 pf = C2d->Value(f);
880 pl = C2d->Value(l);
881 }
882
883 while (Max(pf.X(),pl.X()) <= Uminc + tttol) {
c6541a0c 884 C2d->Translate(gp_Vec2d(2.*M_PI,0));
7fd59977 885 pf = C2d->Value(f);
886 pl = C2d->Value(l);
887 }
888
889 if (!BRepTools::IsReallyClosed(edg,facbis)) {
890 B.UpdateEdge(edg,C2d,newface,tol);
891 }
892 // else {
893 // cout << "Edge double bizarre... " << endl;
894 // }
895 }
896 }
897 }
898 }
899 }
900 }
901 }
902 if (!listofedg.IsEmpty()) {
903 BRepAlgo_Loop L;
904 L.Init(newface);
905 L.AddConstEdges(listofedg);
906 L.Perform();
907 L.WiresToFaces();
7fd59977 908 const TopTools_ListOfShape& listoffaces = L.NewFaces();
909 toRemove.Add(fac);
910 // if (!HasWire) {
911 // newface.Nullify();
912 // }
913 myModShapes.Bind(fac,listoffaces);
914 for (itl.Initialize(itf.Value()); itl.More(); itl.Next()) {
915 myModShapes.Bind(itl.Value(),listoffaces);
916 }
917 }
918 }
919
920/* JAG 16.09.96 : on utilise LocOpe_BuildShape
921 TopoDS_Shell theShell;
922 B.MakeShell(theShell);
923 for (exp.Init(myShape,TopAbs_FACE); exp.More(); exp.Next()) {
924 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
925 if (!theLeft.Contains(fac)) {
926 if (!toRemove.Contains(exp.Current())) {
927 B.Add(theShell,fac);
928 myModShapes.Bind(fac,fac);
929 }
930 else if (!myModShapes(fac).IsNull()) {
931 B.Add(theShell, myModShapes(fac).Oriented(fac.Orientation()));
932 }
933 }
934 }
935
936
937 TopAbs_Orientation orsolid = myShape.Orientation();
938 for (itl.Initialize(G->OrientedFaces()); itl.More(); itl.Next()) {
939 const TopoDS_Face& fac = TopoDS::Face(itl.Value());
940 if (toRemove.Contains(fac)) {
941 continue;
942 }
943
944 if (orsolid == TopAbs_FORWARD) {
945 B.Add(theShell,fac);
946 }
947 else {
948 B.Add(theShell,fac.Reversed());
949 }
950 myModShapes.Bind(fac,fac);
951
952 }
953
954 B.MakeSolid(TopoDS::Solid(myRes));
955 B.Add(myRes,theShell);
956 myRes.Orientation(orsolid);
957
958*/
959
960 // 06.11.96
961 // Debug temporaire. Il faudra prevoir un syntaxe de BuildShape
962 // qui impose une ori de certaines faces.
963
964 TopoDS_Face FaceRefOri;
965
966 TopTools_ListOfShape lfres;
967 for (exp.Init(myShape,TopAbs_FACE); exp.More(); exp.Next()) {
968 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
969 if (!theLeft.Contains(fac)) {
970 if (!toRemove.Contains(exp.Current())) {
971 lfres.Append(fac);
972 if(!myModShapes.IsBound(fac)) {
973 TopTools_ListOfShape emptylist;
974 myModShapes.Bind(fac, emptylist);
975 }
976 myModShapes(fac).Append(fac);
977 if (FaceRefOri.IsNull()) {
978 FaceRefOri = fac;
979 }
980 }
981 else if (myModShapes.IsBound(fac)) {
982 lfres.Append(myModShapes(fac).First().Oriented(fac.Orientation()));
983 }
984 }
985 }
986
987
988 TopAbs_Orientation orsolid = myShape.Orientation();
989 for (itl.Initialize(G->OrientedFaces()); itl.More(); itl.Next()) {
990 const TopoDS_Face& fac = TopoDS::Face(itl.Value());
991 if (toRemove.Contains(fac)) {
992 continue;
993 }
994
995 if (orsolid == TopAbs_FORWARD) {
996 lfres.Append(fac);
997 }
998 else {
999 lfres.Append(fac.Reversed());
1000 }
1001 if(!myModShapes.IsBound(fac)) {
1002 TopTools_ListOfShape emptylist;
1003 myModShapes.Bind(fac, emptylist);
1004 }
1005 myModShapes(fac).Append(fac);
1006 }
1007
1008 LocOpe_BuildShape BS(lfres);
1009 myRes = BS.Shape();
1010 // Suite debug du 06.11.96
1011 if (myRes.ShapeType() == TopAbs_SOLID) {
1012 for (exp.Init(myRes,TopAbs_FACE); exp.More(); exp.Next()) {
1013 if (exp.Current().IsSame(FaceRefOri)) {
1014 break;
1015 }
1016 }
1017 if (exp.More() &&
1018 exp.Current().Orientation() != FaceRefOri.Orientation()) {
1019 // ---C++: return const& ---C++: return const& ---C++: return const&Si un seul Shell , on change son orientation
1020 TopoDS_Solid NewSol;
1021 B.MakeSolid(NewSol);
1022 exp.Init(myRes,TopAbs_SHELL);
1023 B.Add(NewSol,exp.Current().Reversed());
1024 myRes.Nullify();
1025 myRes = NewSol;
1026 }
1027 }
1028
1029
1030 // recodage des regularites qui existaient sur le shape colle
1031
1032
1033
1034 myDone = Standard_True;
1035}
1036
1037//=======================================================================
1038//function : DescendantFace
1039//purpose :
1040//=======================================================================
1041
1042 const TopTools_ListOfShape& LocOpe_Generator::DescendantFace(const TopoDS_Face& F)
1043{
1044 // TopTools_ListOfShape list;
1045
1046 if (!myDone) {StdFail_NotDone::Raise();}
1047 return myModShapes(F);
1048}
1049
1050//=======================================================================
1051//function : ToFuse
1052//purpose :
1053//=======================================================================
1054
1055Standard_Boolean ToFuse(const TopoDS_Face& F1,
1056 const TopoDS_Face& F2)
1057{
1058 if (F1.IsNull() || F2.IsNull()) {
1059 return Standard_False;
1060 }
1061
1062 Handle(Geom_Surface) S1,S2;
1063 TopLoc_Location loc1, loc2;
1064 Handle(Standard_Type) typS1,typS2;
1065 const Standard_Real tollin = Precision::Confusion();
1066 const Standard_Real tolang = Precision::Angular();
1067
1068 S1 = BRep_Tool::Surface(F1,loc1);
1069 S2 = BRep_Tool::Surface(F2,loc2);
1070
1071 typS1 = S1->DynamicType();
1072 typS2 = S2->DynamicType();
1073
1074 if (typS1 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
c5f3a425 1075 S1 = Handle(Geom_RectangularTrimmedSurface)::DownCast (S1)->BasisSurface();
7fd59977 1076 typS1 = S1->DynamicType();
1077 }
1078
1079 if (typS2 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
c5f3a425 1080 S2 = Handle(Geom_RectangularTrimmedSurface)::DownCast (S2)->BasisSurface();
7fd59977 1081 typS2 = S2->DynamicType();
1082 }
1083
1084 if (typS1 != typS2) {
1085 return Standard_False;
1086 }
1087
1088
1089 Standard_Boolean ValRet = Standard_False;
1090 if (typS1 == STANDARD_TYPE(Geom_Plane)) {
1091
c5f3a425 1092 gp_Pln pl1( Handle(Geom_Plane)::DownCast (S1)->Pln());
1093 gp_Pln pl2( Handle(Geom_Plane)::DownCast (S2)->Pln());
7fd59977 1094
1095 pl1.Transform(loc1.Transformation());
1096 pl2.Transform(loc2.Transformation());
1097
1098 if (pl1.Position().IsCoplanar(pl2.Position(),tollin,tolang)) {
1099 ValRet = Standard_True;
1100 }
1101 }
1102
1103 return ValRet;
1104}
1105
1106
1107//=======================================================================
1108//function : ToFuse
1109//purpose :
1110//=======================================================================
1111
1112Standard_Boolean ToFuse(const TopoDS_Edge& E1,
1113 const TopoDS_Edge& E2)
1114{
1115
1116 if (E1.IsNull() || E2.IsNull()) {
1117 return Standard_False;
1118 }
1119
1120 Handle(Geom_Curve) C1,C2;
1121 TopLoc_Location loc1, loc2;
1122 Handle(Standard_Type) typC1,typC2;
1123 const Standard_Real tollin = Precision::Confusion();
1124 const Standard_Real tolang = Precision::Angular();
1125 Standard_Real f,l;
1126
1127 C1 = BRep_Tool::Curve(E1,loc1,f,l);
1128 if (!loc1.IsIdentity()) {
1129 Handle(Geom_Geometry) CC1 = C1->Transformed(loc1.Transformation());
c5f3a425 1130 C1 = Handle(Geom_Curve)::DownCast (CC1);
7fd59977 1131 }
1132
1133 C2 = BRep_Tool::Curve(E2,loc2,f,l);
1134 if (!loc2.IsIdentity()) {
1135 Handle(Geom_Geometry) CC2 = C2->Transformed(loc2.Transformation());
c5f3a425 1136 C2 = Handle(Geom_Curve)::DownCast (CC2);
7fd59977 1137 }
1138
1139 typC1 = C1->DynamicType();
1140 typC2 = C2->DynamicType();
1141
1142 if (typC1 == STANDARD_TYPE(Geom_TrimmedCurve)) {
c5f3a425 1143 C1 = Handle(Geom_TrimmedCurve)::DownCast (C1)->BasisCurve();
7fd59977 1144 typC1 = C1->DynamicType();
1145 }
1146 if (typC2 == STANDARD_TYPE(Geom_TrimmedCurve)) {
c5f3a425 1147 C2 = Handle(Geom_TrimmedCurve)::DownCast (C2)->BasisCurve();
7fd59977 1148 typC2 = C2->DynamicType();
1149 }
1150
1151 if (typC1 != typC2) {
1152 return Standard_False;
1153 }
1154
1155 Standard_Boolean ValRet = Standard_False;
1156 if (typC1 == STANDARD_TYPE(Geom_Line)) {
c5f3a425 1157 gp_Lin li1( Handle(Geom_Line)::DownCast (C1)->Lin());
1158 gp_Lin li2( Handle(Geom_Line)::DownCast (C2)->Lin());
7fd59977 1159
1160 if (li1.Position().IsCoaxial(li2.Position(),tolang,tollin)) {
1161 ValRet = Standard_True;
1162 }
1163 }
1164
1165 return ValRet;
1166}
1167
1168
1169//=======================================================================
1170//function : ToFuse
1171//purpose :
1172//=======================================================================
1173
1174Standard_Boolean ToFuse(const TopoDS_Edge& E,
1175 const TopoDS_Face& F,
1176 const TopoDS_Vertex& V,
1177 const TopTools_MapOfShape& toRemove)
1178{
1179 TopoDS_Vertex Vf,Vl;
1180 TopExp_Explorer exp;
1181 for (exp.Init(F,TopAbs_EDGE); exp.More(); exp.Next()) {
1182// for (TopExp_Explorer exp(F,TopAbs_EDGE); exp.More(); exp.Next()) {
1183 const TopoDS_Edge& eee = TopoDS::Edge(exp.Current());
1184 if (!eee.IsSame(E)) {
1185 TopExp::Vertices(eee,Vf,Vl);
1186 if ((Vf.IsSame(V) || Vl.IsSame(V)) &&
1187 !toRemove.Contains(eee)) {
1188 return Standard_False;
1189 }
1190 }
1191 }
1192 return Standard_True;
1193}
1194
1195
1196//=======================================================================
1197//function : NewParameter
1198//purpose :
1199//=======================================================================
1200
1201Standard_Real NewParameter(const TopoDS_Edge& Edg,
1202 const TopoDS_Vertex& Vtx,
1203 const TopoDS_Edge& NewEdg,
1204 const TopoDS_Vertex& NewVtx)
1205{
1206
1207 Handle(Geom_Curve) C;
1208 TopLoc_Location loc;
1209 Handle(Standard_Type) typC;
1210 Standard_Real f,l;
1211
1212 gp_Pnt P = BRep_Tool::Pnt(NewVtx);
1213
1214 C = BRep_Tool::Curve(Edg,loc,f,l);
1215 if (!loc.IsIdentity()) {
1216 Handle(Geom_Geometry) GG = C->Transformed(loc.Transformation());
c5f3a425 1217 C = Handle(Geom_Curve)::DownCast (GG);
7fd59977 1218 }
1219 typC = C->DynamicType();
1220 if (typC == STANDARD_TYPE(Geom_TrimmedCurve)) {
c5f3a425 1221 C = Handle(Geom_TrimmedCurve)::DownCast (C)->BasisCurve();
7fd59977 1222 typC = C->DynamicType();
1223 }
1224
1225 if (typC == STANDARD_TYPE(Geom_Line)) {
c5f3a425 1226 return ElCLib::Parameter( Handle(Geom_Line)::DownCast (C)->Lin(),P);
7fd59977 1227 }
1228 else if (typC == STANDARD_TYPE(Geom_Circle)) {
1229 Standard_Real prm = ElCLib::Parameter
c5f3a425 1230 ( Handle(Geom_Circle)::DownCast (C)->Circ(),P);
7fd59977 1231 // Vtx vient d`une exploration de Edg orientee FORWARD
1232
1233 TopAbs_Orientation orient = TopAbs::Reverse(Vtx.Orientation());
1234 if (orient == TopAbs_FORWARD || orient == TopAbs_REVERSED) {
1235// for (TopExp_Explorer exp(NewEdg.Oriented(TopAbs_FORWARD),TopAbs_VERTEX);
1236 TopExp_Explorer exp(NewEdg.Oriented(TopAbs_FORWARD),TopAbs_VERTEX) ;
1237 for ( ; exp.More(); exp.Next()) {
1238 if (exp.Current().Orientation() == orient) {
1239 break;
1240 }
1241 }
1242 if (exp.More()) {
1243 Standard_Real prmmax = BRep_Tool::Parameter
1244 (TopoDS::Vertex(exp.Current()),NewEdg);
c6541a0c 1245 if (Abs(prmmax - prm) <= Epsilon(2.*M_PI)) {
7fd59977 1246 if (orient == TopAbs_REVERSED) {
c6541a0c 1247 prm -= 2.*M_PI;
7fd59977 1248 }
1249 else {
c6541a0c 1250 prm += 2.*M_PI;
7fd59977 1251 }
1252 }
1253 }
1254 }
1255 return prm;
1256 }
1257 return 0;
1258}