0024428: Implementation of LGPL license
[occt.git] / src / BRepFeat / BRepFeat_RibSlot.cxx
CommitLineData
b311480e 1// Created on: 1997-10-08
2// Created by: Olga KOULECHOVA
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//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <BRepFeat_RibSlot.ixx>
18#include <BRepFeat.hxx>
19
20#include <LocOpe.hxx>
7fd59977 21#include <LocOpe_Gluer.hxx>
22#include <LocOpe_FindEdges.hxx>
23#include <LocOpe_CSIntersector.hxx>
24#include <LocOpe_PntFace.hxx>
25
26#include <TopAbs.hxx>
27
28#include <TopExp_Explorer.hxx>
29#include <TopExp.hxx>
30
31#include <TopoDS.hxx>
32#include <TopoDS_Shape.hxx>
33#include <TopoDS_Face.hxx>
34
35#include <TopTools_ListOfShape.hxx>
36#include <TopTools_ListIteratorOfListOfShape.hxx>
37#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
38#include <TopTools_MapIteratorOfMapOfShape.hxx>
39#include <TopTools_MapOfShape.hxx>
40#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
41
42#include <TopOpeBRepBuild_HBuilder.hxx>
43
44#include <BRep_Tool.hxx>
45
46#include <BRepAlgo.hxx>
47//modified by NIZNHY-PKV Fri Mar 22 16:48:13 2002 f
48//#include <BRepAlgo_Cut.hxx>
49//#include <BRepAlgo_Fuse.hxx>
50#include <BRepAlgoAPI_Cut.hxx>
51#include <BRepAlgoAPI_Fuse.hxx>
52//modified by NIZNHY-PKV Fri Mar 22 16:48:16 2002 t
53
54#include <BRepAdaptor_Surface.hxx>
55#include <BRepBndLib.hxx>
56#include <BRepIntCurveSurface_Inter.hxx>
57#include <BRepTools_WireExplorer.hxx>
58#include <BRepTopAdaptor_FClass2d.hxx>
59#include <BRepClass3d_SolidClassifier.hxx>
60
61#include <BRepLib_MakeVertex.hxx>
62#include <BRepLib_MakeEdge.hxx>
63#include <BRepLib_MakeWire.hxx>
64#include <BRepLib_MakeFace.hxx>
65#include <BRepLib.hxx>
66
67#include <Bnd_Box.hxx>
68
69#include <Standard_ConstructionError.hxx>
70#include <Standard_NoSuchObject.hxx>
71
72#include <GeomLib.hxx>
73#include <GeomAdaptor_Curve.hxx>
74
75#include <Geom_Curve.hxx>
76#include <Geom_TrimmedCurve.hxx>
77#include <Geom_Line.hxx>
78#include <Geom_Circle.hxx>
79#include <Geom_Plane.hxx>
80#include <Geom_Ellipse.hxx>
81#include <Geom_Parabola.hxx>
82#include <Geom_Hyperbola.hxx>
83
84#include <Geom2dAPI_InterCurveCurve.hxx>
85#include <GeomAPI.hxx>
86#include <GeomAPI_ProjectPointOnCurve.hxx>
87
88#include <gp_Vec.hxx>
89#include <gp_Ax1.hxx>
90#include <gp_Pln.hxx>
91#include <gp_Pnt.hxx>
92#include <gp_Dir.hxx>
93
94
95#include <ElCLib.hxx>
96#include <ElSLib.hxx>
97#include <CSLib.hxx>
98
99#include <Precision.hxx>
100
101#include <TColGeom_SequenceOfCurve.hxx>
4e57c75e 102#include <BRepFeat_Builder.hxx>
7fd59977 103
104
105#ifdef DEB
1d0a9d4d 106extern Standard_Boolean BRepFeat_GettraceFEAT();
107extern Standard_Boolean BRepFeat_GettraceFEATRIB();
7fd59977 108#endif
109
110//=======================================================================
111//function : LFPerform
0d969553 112//purpose : topological reconstruction of ribs
7fd59977 113//=======================================================================
114
115void BRepFeat_RibSlot::LFPerform()
116{
117#ifdef DEB
118 Standard_Boolean trc = BRepFeat_GettraceFEAT();
119 if (trc) cout << "BRepFeat_RibSlot::LFPerform()" << endl;
120#endif
121 if (mySbase.IsNull() || myPbase.IsNull() || mySkface.IsNull()
122 || myGShape.IsNull() || myLFMap.IsEmpty()) {
123#ifdef DEB
124 cout << "Topological reconstruction is impossible" << endl;
125 if (trc) cout << " Fields not initialized" << endl;
126#endif
127 myStatusError = BRepFeat_NotInitialized;
128 NotDone();
129 return;
130 }
131
132 TopExp_Explorer exp,exp2;
133 Standard_Integer theOpe = 2;
134
135 if (!myGluedF.IsEmpty()) {
136 theOpe = 1;
137 }
138
139 Standard_Boolean ChangeOpe = Standard_False;
0d969553 140 // Hope that there is just a solid in the result
7fd59977 141 Standard_Boolean UntilInShape = Standard_False;
142
7fd59977 143 if (!mySUntil.IsNull()) {
144 UntilInShape = Standard_True;
145 for (exp2.Init(mySUntil,TopAbs_FACE); exp2.More(); exp2.Next()) {
146 const TopoDS_Shape& funtil = exp2.Current();
147 for (exp.Init(mySbase,TopAbs_FACE); exp.More(); exp.Next()) {
4e57c75e 148 if (exp.Current().IsSame(funtil)) {
149 break;
150 }
7fd59977 151 }
152 if (!exp.More()) {
4e57c75e 153 UntilInShape = Standard_False;
154 break;
7fd59977 155 }
156 }
157 }
158
159 TopTools_ListIteratorOfListOfShape it,it2;
160 TopTools_DataMapIteratorOfDataMapOfShapeShape itm;
161 //Standard_Integer sens = 0;
162
7fd59977 163 LocOpe_Gluer theGlue;
164
0d969553 165 //case of gluing
7fd59977 166
167 if (theOpe == 1) {
168 Standard_Boolean Collage = Standard_True;
7fd59977 169
170 LocOpe_FindEdges theFE;
171 TopTools_DataMapOfShapeListOfShape locmap;
172 theGlue.Init(mySbase,myGShape);
173 for (itm.Initialize(myGluedF); itm.More();itm.Next()) {
174 const TopoDS_Face& glface = TopoDS::Face(itm.Key());
175 const TopoDS_Face& fac = TopoDS::Face(myGluedF(glface));
176 for (exp.Init(myGShape,TopAbs_FACE); exp.More(); exp.Next()) {
4e57c75e 177 if (exp.Current().IsSame(glface)) {
178 break;
179 }
7fd59977 180 }
181 if (exp.More()) {
4e57c75e 182 Collage = BRepFeat::IsInside(glface, fac);
183 if(!Collage) {
184 theOpe = 2;
185 ChangeOpe = Standard_True;
186 break;
187 }
188 else {
189 theGlue.Bind(glface, fac);
190 theFE.Set(glface, fac);
191 for (theFE.InitIterator(); theFE.More();theFE.Next()) {
192 theGlue.Bind(theFE.EdgeFrom(),theFE.EdgeTo());
193 }
194 }
7fd59977 195 }
196 }
197
198 LocOpe_Operation ope = theGlue.OpeType();
199 if (ope == LocOpe_INVALID ||
4e57c75e 200 (myFuse && ope != LocOpe_FUSE) ||
201 (!myFuse && ope != LocOpe_CUT) ||
202 (!Collage)) {
7fd59977 203 theOpe = 2;
204 ChangeOpe = Standard_True;
205#ifdef DEB
0d969553 206 cout << "Passage to topological operations" << endl;
7fd59977 207#endif
208 }
209 }
210
0d969553 211// gluing is always applicable
7fd59977 212
213 if (theOpe == 1) {
214 theGlue.Perform();
215 if (theGlue.IsDone()) {
216 UpdateDescendants(theGlue);
217 myNewEdges = theGlue.Edges();
218 myTgtEdges = theGlue.TgtEdges();
4e57c75e 219 //
220 Done();
221 myShape = theGlue.ResultingShape();
222 BRepLib::SameParameter(myShape, 1.e-7, Standard_True);
7fd59977 223 }
224 else {
225 theOpe = 2;
226 ChangeOpe = Standard_True;
227#ifdef DEB
0d969553 228 cout << "Passage to topologic operation" << endl;
7fd59977 229#endif
230 }
231 }
232
4e57c75e 233 // case without gluing
7fd59977 234 if (theOpe == 2) {
4e57c75e 235 BRepFeat_Builder theBuilder;
236 TopTools_ListOfShape partsoftool;
237 BRepClass3d_SolidClassifier oussa;
238 Standard_Boolean bFlag;
239 TopTools_ListIteratorOfListOfShape aIt;
240
241 bFlag = (myPerfSelection == BRepFeat_NoSelection) ? 0 : 1;
242 //
243 theBuilder.Init(mySbase, myGShape);
244 theBuilder.SetOperation(myFuse, bFlag);
245 //
246 theBuilder.Perform();
247 if (bFlag) {
248 theBuilder.PartsOfTool(partsoftool);
249 aIt.Initialize(partsoftool);
250 if (aIt.More() && myPerfSelection != BRepFeat_NoSelection) {
251 Standard_Real toler = (BRep_Tool::Tolerance(myPbase))*2;
252 //
253 for(; aIt.More(); aIt.Next()) {
254 oussa.Load(aIt.Value());
255 oussa.Perform(myFirstPnt, toler);
256 TopAbs_State sp1=oussa.State();
257 oussa.Perform(myLastPnt, toler);
258 TopAbs_State sp2=oussa.State();
259 if (!(sp1 == TopAbs_OUT || sp2 == TopAbs_OUT)) {
260 const TopoDS_Shape& S = aIt.Value();
261 theBuilder.KeepPart(S);
262 }
263 }
264 }
265 //
266 theBuilder.PerformResult();
267 myShape = theBuilder.Shape();
268 } else {
269 myShape = theBuilder.Shape();
270 }
271 Done();
7fd59977 272 }
273}
274
7fd59977 275//=======================================================================
276//function : IsDeleted
277//purpose :
278//=======================================================================
279
280Standard_Boolean BRepFeat_RibSlot::IsDeleted(const TopoDS_Shape& F)
281{
282 return (myMap(F).IsEmpty());
283}
284
285
286//=======================================================================
287//function : Modified
288//purpose :
289//=======================================================================
290
291const TopTools_ListOfShape& BRepFeat_RibSlot::Modified
292 (const TopoDS_Shape& F)
293{
294#ifdef DEB
295 Standard_Boolean trc = BRepFeat_GettraceFEAT();
296 if (trc) cout << "BRepFeat_RibSlot::Modified" << endl;
297#endif
298 if (myMap.IsBound(F)) {
299 static TopTools_ListOfShape list;
300 list.Clear();
301 TopTools_ListIteratorOfListOfShape ite(myMap(F));
302 for(; ite.More(); ite.Next()) {
303 const TopoDS_Shape& sh = ite.Value();
304 if(!sh.IsSame(F))
4e57c75e 305 list.Append(sh);
7fd59977 306 }
307 return list;
308 }
309 return myGenerated; // empty list
310}
311
312//=======================================================================
313//function : Generated
314//purpose :
315//=======================================================================
316
317const TopTools_ListOfShape& BRepFeat_RibSlot::Generated
318 (const TopoDS_Shape& S)
319{
320#ifdef DEB
321 Standard_Boolean trc = BRepFeat_GettraceFEAT();
322 if (trc) cout << "BRepFeat_RibSlot::Generated" << endl;
323#endif
324 if(S.ShapeType() != TopAbs_FACE) {
325 myGenerated.Clear();
326 if(myLFMap.IsEmpty() || !myLFMap.IsBound(S)) {
0d969553 327 if (myMap.IsBound(S)) { // check if filter on face or not
4e57c75e 328 static TopTools_ListOfShape list;
329 list.Clear();
330 TopTools_ListIteratorOfListOfShape ite(myMap(S));
331 for(; ite.More(); ite.Next()) {
332 const TopoDS_Shape& sh = ite.Value();
333 if(!sh.IsSame(S))
334 list.Append(sh);
335 }
336 return list;
7fd59977 337 }
338 else return myGenerated;
339 }
340 else {
341 myGenerated.Clear();
342 TopTools_ListIteratorOfListOfShape it(myLFMap(S));
343 static TopTools_ListOfShape list;
344 list.Clear();
345 for(; it.More(); it.Next()) {
4e57c75e 346 if(myMap.IsBound(it.Value())) {
347 TopTools_ListIteratorOfListOfShape it1(myMap(it.Value()));
348 for(; it1.More(); it1.Next()) {
349 const TopoDS_Shape& sh = it1.Value();
350 if(!sh.IsSame(S))
351 list.Append(sh);
352 }
353 }
7fd59977 354 }
355 return list;
356 }
357 }
358 else return myGenerated;
359}
360
361
362//=======================================================================
363//function : UpdateDescendants
364//purpose :
365//=======================================================================
366
367void BRepFeat_RibSlot::UpdateDescendants(const LocOpe_Gluer& G)
368{
369 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itdm;
370 TopTools_ListIteratorOfListOfShape it,it2;
371 TopTools_MapIteratorOfMapOfShape itm;
372
373 for (itdm.Initialize(myMap);itdm.More();itdm.Next()) {
374 const TopoDS_Shape& orig = itdm.Key();
375 TopTools_MapOfShape newdsc;
376 for (it.Initialize(itdm.Value());it.More();it.Next()) {
377 const TopoDS_Face& fdsc = TopoDS::Face(it.Value());
378 for (it2.Initialize(G.DescendantFaces(fdsc));
4e57c75e 379 it2.More();it2.Next()) {
380 newdsc.Add(it2.Value());
7fd59977 381 }
382 }
383 myMap.ChangeFind(orig).Clear();
384 for (itm.Initialize(newdsc);itm.More();itm.Next()) {
385 myMap.ChangeFind(orig).Append(itm.Key());
386 }
387 }
388}
389
390//=======================================================================
391//function : UpdateDescendants
392//purpose :
393//=======================================================================
394 void BRepFeat_RibSlot::UpdateDescendants (const Handle(TopOpeBRepBuild_HBuilder)& B,
4e57c75e 395 const TopoDS_Shape& S,
396 const Standard_Boolean SkipFace)
7fd59977 397{
398 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itdm;
399 TopTools_ListIteratorOfListOfShape it,it2;
400 TopTools_MapIteratorOfMapOfShape itm;
401 TopExp_Explorer exp;
402
403 for (itdm.Initialize(myMap);itdm.More();itdm.Next()) {
404 const TopoDS_Shape& orig = itdm.Key();
405 if (SkipFace && orig.ShapeType() == TopAbs_FACE) {
406 continue;
407 }
408 TopTools_MapOfShape newdsc;
409 for (it.Initialize(itdm.Value());it.More();it.Next()) {
410 const TopoDS_Shape& sh = it.Value();
411 if(sh.ShapeType() != TopAbs_FACE) continue;
412 const TopoDS_Face& fdsc = TopoDS::Face(it.Value());
413 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
4e57c75e 414 if (exp.Current().IsSame(fdsc)) { // preserved
415 newdsc.Add(fdsc);
416 break;
417 }
7fd59977 418 }
419 if (!exp.More()) {
4e57c75e 420 if (B->IsSplit(fdsc, TopAbs_OUT)) {
421 for (it2.Initialize(B->Splits(fdsc,TopAbs_OUT));
422 it2.More();it2.Next()) {
423 newdsc.Add(it2.Value());
424 }
425 }
426 if (B->IsSplit(fdsc, TopAbs_IN)) {
427 for (it2.Initialize(B->Splits(fdsc,TopAbs_IN));
428 it2.More();it2.Next()) {
429 newdsc.Add(it2.Value());
430 }
431 }
432 if (B->IsSplit(fdsc, TopAbs_ON)) {
433 for (it2.Initialize(B->Splits(fdsc,TopAbs_ON));
434 it2.More();it2.Next()) {
435 newdsc.Add(it2.Value());
436 }
437 }
438 if (B->IsMerged(fdsc, TopAbs_OUT)) {
439 for (it2.Initialize(B->Merged(fdsc,TopAbs_OUT));
440 it2.More();it2.Next()) {
441 newdsc.Add(it2.Value());
442 }
443 }
444 if (B->IsMerged(fdsc, TopAbs_IN)) {
445 for (it2.Initialize(B->Merged(fdsc,TopAbs_IN));
446 it2.More();it2.Next()) {
447 newdsc.Add(it2.Value());
448 }
449 }
450 if (B->IsMerged(fdsc, TopAbs_ON)) {
451 for (it2.Initialize(B->Merged(fdsc,TopAbs_ON));
452 it2.More();it2.Next()) {
453 newdsc.Add(it2.Value());
454 }
455 }
7fd59977 456 }
457 }
458 myMap.ChangeFind(orig).Clear();
459 for (itm.Initialize(newdsc); itm.More(); itm.Next()) {
0d969553 460 // check the belonging to the shape...
7fd59977 461 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
4e57c75e 462 if (exp.Current().IsSame(itm.Key())) {
463 myMap.ChangeFind(orig).Append(itm.Key());
464 break;
465 }
7fd59977 466 }
467 }
468 }
469}
470
471
472
473//=======================================================================
474//function : FirstShape
475//purpose :
476//=======================================================================
477
478const TopTools_ListOfShape& BRepFeat_RibSlot::FirstShape() const
479{
480 if (!myFShape.IsNull()) {
481 return myMap(myFShape);
482 }
483 return myGenerated; // empty list
484}
485
486
487//=======================================================================
488//function : LastShape
489//purpose :
490//=======================================================================
491
492const TopTools_ListOfShape& BRepFeat_RibSlot::LastShape() const
493{
494 if (!myLShape.IsNull()) {
495 return myMap(myLShape);
496 }
497 return myGenerated; // empty list
498}
499
500//=======================================================================
501//function : FacesForDraft
502//purpose :
503//=======================================================================
504
505const TopTools_ListOfShape& BRepFeat_RibSlot::FacesForDraft() const
506{
507 return myFacesForDraft;
508}
509
510
511//=======================================================================
512//function : NewEdges
513//purpose :
514//=======================================================================
515
516const TopTools_ListOfShape& BRepFeat_RibSlot::NewEdges() const
517{
518 return myNewEdges;
519}
520
521//=======================================================================
522//function : TgtEdges
523//purpose :
524//=======================================================================
525
526const TopTools_ListOfShape& BRepFeat_RibSlot::TgtEdges() const
527{
528 return myTgtEdges;
529}
530
531
532//=======================================================================
533//function : CurrentStatusError
534//purpose :
535//=======================================================================
536
537BRepFeat_StatusError BRepFeat_RibSlot::CurrentStatusError() const
538{
539 return myStatusError;
540}
541
542
543//=======================================================================
544//function : CheckPoint
0d969553 545//purpose : Proofing point material side (side of extrusion)
7fd59977 546//=======================================================================
547
548gp_Pnt BRepFeat_RibSlot::CheckPoint(const TopoDS_Edge& e,
4e57c75e 549 const Standard_Real ,//bnd,
550 const Handle(Geom_Plane)& Pln)
7fd59977 551
552{
553#ifdef DEB
554 Standard_Boolean trc = BRepFeat_GettraceFEATRIB();
555 if (trc) cout << "BRepFeat_RibSlot::CheckPoint" << endl;
556#endif
0d969553
Y
557// Vector product : normal to plane X direction Wire
558// -> gives the material side
559// Proofing point somewhat inside the material side
7fd59977 560 Standard_Real f, l;
561 Handle(Geom_Curve) cc = BRep_Tool::Curve(e, f, l);
562
563 gp_Vec tgt; gp_Pnt pp;
564 Standard_Real par = ( f + l) / 2.;
565
566 cc->D1(par, pp, tgt);
567
568 if ( e.Orientation() == TopAbs_REVERSED) tgt.Reverse();
569
570 gp_Vec D = -tgt.Crossed(Pln->Pln().Position().Direction())/10.;
571 pp.Translate(D);
572
573 return pp;
574
575}
576
577
578//=======================================================================
579//function : Normal
0d969553 580//purpose : calculate the normal to a face in a point
7fd59977 581//=======================================================================
582
583gp_Dir BRepFeat_RibSlot::Normal(const TopoDS_Face& F,const gp_Pnt& P)
584
585{
586#ifdef DEB
587 Standard_Boolean trc = BRepFeat_GettraceFEATRIB();
588 if (trc) cout << "BRepFeat_RibSlot::Normal" << endl;
589#endif
590 Standard_Real U, V;
591 gp_Pnt pt;
592
593 BRepAdaptor_Surface AS(F, Standard_True);
594
595 switch ( AS.GetType()) {
596
597 case GeomAbs_Plane:
598 ElSLib::Parameters(AS.Plane(),P,U,V); break;
599
600 case GeomAbs_Cylinder:
601 ElSLib::Parameters(AS.Cylinder(),P,U,V); break;
602
603 case GeomAbs_Cone:
604 ElSLib::Parameters(AS.Cone(),P,U,V); break;
605
606 case GeomAbs_Torus:
607 ElSLib::Parameters(AS.Torus(),P,U,V); break;
608
609 default:
610 {
611 return gp_Dir(1., 0., 0.);
612 }
613 }
614
615 gp_Vec D1U, D1V;
616
4e57c75e 617 AS.D1(U, V, pt, D1U, D1V);
7fd59977 618 gp_Dir N;
619 CSLib_DerivativeStatus St;
620 CSLib::Normal(D1U, D1V, Precision::Confusion(), St, N);
621 if(F.Orientation() == TopAbs_FORWARD) N.Reverse();
622 return N;
623}
624
625//=======================================================================
626//function : IntPar
0d969553 627//purpose : calculate the parameter of a point on a curve
7fd59977 628//=======================================================================
629
630Standard_Real BRepFeat_RibSlot::IntPar(const Handle(Geom_Curve)& C,
4e57c75e 631 const gp_Pnt& P)
7fd59977 632
633{
634 if ( C.IsNull()) return 0.;
635
636 GeomAdaptor_Curve AC(C);
637 Standard_Real U;
638
639 switch ( AC.GetType()) {
640
641 case GeomAbs_Line:
642 U = ElCLib::Parameter(AC.Line(),P); break;
643
644 case GeomAbs_Circle:
645 U = ElCLib::Parameter(AC.Circle(),P); break;
646
647 case GeomAbs_Ellipse:
648 U = ElCLib::Parameter(AC.Ellipse(),P); break;
649
650 case GeomAbs_Hyperbola:
651 U = ElCLib::Parameter(AC.Hyperbola(),P); break;
652
653 case GeomAbs_Parabola:
654 U = ElCLib::Parameter(AC.Parabola(),P); break;
655
656 default:
657 U = 0.;
658 }
659
660 return U;
661}
662
663
664//=======================================================================
665//function : EdgeExtention
0d969553 666//purpose : extention of a edge by tangence
7fd59977 667//=======================================================================
668
669void BRepFeat_RibSlot::EdgeExtention(TopoDS_Edge& e,
4e57c75e 670 const Standard_Real bnd,
671 const Standard_Boolean FirstLast)
7fd59977 672{
673#ifdef DEB
674 Standard_Boolean trc = BRepFeat_GettraceFEAT();
675 if (trc) cout << "BRepFeat_RibSlot::EdgeExtention" << endl;
676#endif
677 Standard_Real f, l;
678 Handle(Geom_Curve) cu = BRep_Tool::Curve(e, f, l);
679 Handle(Geom_TrimmedCurve) C =
680 new Geom_TrimmedCurve(cu, f, l);
681
682 TopoDS_Edge E;
683
684 if(cu->DynamicType() == STANDARD_TYPE(Geom_Line) ||
685 cu->DynamicType() == STANDARD_TYPE(Geom_Circle) ||
686 cu->DynamicType() == STANDARD_TYPE(Geom_Ellipse) ||
687 cu->DynamicType() == STANDARD_TYPE(Geom_Hyperbola) ||
688 cu->DynamicType() == STANDARD_TYPE(Geom_Parabola)) {
689 if(FirstLast) {
690 BRepLib_MakeEdge Edg(cu, f-bnd/10., l);
691 E = TopoDS::Edge(Edg.Shape());
692 }
693 else {
694 BRepLib_MakeEdge Edg(cu, f, l+bnd/10.);
695 E = TopoDS::Edge(Edg.Shape());
696 }
697 }
698 else {
699 Handle(Geom_Line) ln;
700 gp_Pnt Pt;
701 gp_Pnt pnt;
702 gp_Vec vct;
703 if(FirstLast) {
704 C->D1(f, pnt, vct);
705 ln = new Geom_Line(pnt, -vct);
706 ln->D0(bnd/1000., Pt);
707 GeomLib::ExtendCurveToPoint(C, Pt, GeomAbs_G1, Standard_False);
708 BRepLib_MakeEdge Edg(C, Pt, BRep_Tool::Pnt(TopExp::LastVertex(e,Standard_True)));
709 E = TopoDS::Edge(Edg.Shape());
710 }
711 else {
712 C->D1(l, pnt, vct);
713 ln = new Geom_Line(pnt, vct);
714 ln->D0(bnd/1000., Pt);
715 GeomLib::ExtendCurveToPoint(C, Pt, GeomAbs_G1, Standard_True);
716 BRepLib_MakeEdge Edg(C, BRep_Tool::Pnt(TopExp::FirstVertex(e,Standard_True)), Pt);
717 E = TopoDS::Edge(Edg.Shape());
718 }
719 }
720 e = E;
721}
722
723
724//=======================================================================
725//function : ChoiceOfFaces
0d969553 726//purpose : choose face of support in case of support on an edge
7fd59977 727//=======================================================================
728
729TopoDS_Face BRepFeat_RibSlot::ChoiceOfFaces(TopTools_ListOfShape& faces,
4e57c75e 730 const Handle(Geom_Curve)& cc,
731 const Standard_Real par,
732 const Standard_Real ,//bnd,
733 const Handle(Geom_Plane)& Pln)
7fd59977 734
735{
736#ifdef DEB
737 Standard_Boolean trc = BRepFeat_GettraceFEATRIB();
738 if (trc) cout << "BRepFeat_RibSlot::ChoiceOfFaces" << endl;
739#endif
740 TopoDS_Face FFF;
741
742 gp_Pnt pp;
743 gp_Vec tgt;
744
745 cc->D1(par, pp, tgt);
746
747 Handle(Geom_Line) l1 = new Geom_Line(pp, tgt);
748
749 TColGeom_SequenceOfCurve scur;
750 Standard_Integer Counter = 0;
751
752
753 gp_Ax1 Axe(pp, Pln->Position().Direction());
754 for ( Standard_Integer i = 1; i <=8; i++) {
755 Handle(Geom_Curve) L =
c6541a0c 756 Handle(Geom_Curve)::DownCast(l1->Rotated(Axe, i*M_PI/9.));
7fd59977 757 scur.Append(L);
758 Counter++;
759 }
760
761 TopTools_ListIteratorOfListOfShape it;
762 it.Initialize(faces);
763 Standard_Real Par = RealLast();
764 for(; it.More(); it.Next()) {
765 const TopoDS_Face& f = TopoDS::Face(it.Value());
766 LocOpe_CSIntersector ASI(f);
767 ASI.Perform(scur);
768 if(!ASI.IsDone()) continue;
769 for(Standard_Integer jj = 1; jj<=Counter; jj++) {
770 if(ASI.NbPoints(jj) >= 1) {
4e57c75e 771 Standard_Real app = ASI.Point(jj,1).Parameter();//modified by NIZNHY-PKV Fri Mar 22 17:05:23 2002 pp
772 if(app >= 0 && app < Par) {
773 Par = app;
774 FFF = f;
775 }
7fd59977 776 }
777 }
778 }
779
780 return FFF;
781}
782
783
784//=======================================================================
785//function : HeightMax
0d969553 786//purpose : Calculate the height of the prism following the parameters of a bounding box
7fd59977 787//=======================================================================
788
789Standard_Real BRepFeat_RibSlot::HeightMax(const TopoDS_Shape& theSbase,
4e57c75e 790 const TopoDS_Shape& theSUntil,
791 gp_Pnt& p1,
7fd59977 792 gp_Pnt& p2)
793{
794#ifdef DEB
795 Standard_Boolean trc = BRepFeat_GettraceFEATRIB();
796 if (trc) cout << "BRepFeat_RibSlot::HeightMax" << endl;
797#endif
798 Bnd_Box Box;
799 BRepBndLib::Add(theSbase,Box);
800 if(!theSUntil.IsNull()) {
801 BRepBndLib::Add(theSUntil,Box);
802 }
803 Standard_Real c[6], bnd;
804 Box.Get(c[0],c[2],c[4],c[1],c[3],c[5]);
805 bnd = c[0];
806 for(Standard_Integer i = 0 ; i < 6; i++) {
807 if(c[i] > bnd) bnd = c[i];
808 }
809 p1.SetCoord(c[0]-2.*bnd, c[1]-2.*bnd, c[2]-2.*bnd);
810 p2.SetCoord(c[3]+2.*bnd, c[4]+2.*bnd, c[5]+2.*bnd);
811 return(bnd);
812}
813
814//=======================================================================
815//function : ExtremeFaces
0d969553 816//purpose : Calculate the base faces of the rib
7fd59977 817//=======================================================================
818
819Standard_Boolean BRepFeat_RibSlot::ExtremeFaces(const Standard_Boolean RevolRib,
4e57c75e 820 const Standard_Real bnd,
821 const Handle(Geom_Plane)& Pln,
822 TopoDS_Edge& FirstEdge,
823 TopoDS_Edge& LastEdge,
824 TopoDS_Face& FirstFace,
825 TopoDS_Face& LastFace,
826 TopoDS_Vertex& FirstVertex,
827 TopoDS_Vertex& LastVertex,
828 Standard_Boolean& OnFirstFace,
829 Standard_Boolean& OnLastFace,
830 Standard_Boolean& PtOnFirstEdge,
831 Standard_Boolean& PtOnLastEdge,
832 TopoDS_Edge& OnFirstEdge,
833 TopoDS_Edge& OnLastEdge)
7fd59977 834
835{
836#ifdef DEB
837 Standard_Boolean trc = BRepFeat_GettraceFEAT();
838 if (trc) cout << "BRepFeat_RibSlot::ExtremeFaces" << endl;
839#endif
840 Standard_Boolean Data = Standard_True;
841 FirstFace.Nullify();
842 LastFace.Nullify();
843 FirstEdge.Nullify();
844 LastEdge.Nullify();
845 PtOnFirstEdge = Standard_False;
846 PtOnLastEdge = Standard_False;
847 OnFirstEdge.Nullify();
848 OnLastEdge.Nullify();
849
850 BRepIntCurveSurface_Inter inter;
851 BRep_Builder B;
852 TopExp_Explorer ex1;
853
854 Standard_Boolean FirstOK = Standard_False, LastOK = Standard_False;
855
856 Standard_Integer NumberOfEdges = 0;
857 TopExp_Explorer exp(myWire, TopAbs_EDGE);
858
859 for(; exp.More(); exp.Next()) {
860 NumberOfEdges++;
861 }
862
0d969553 863// ---the wire includes only one edge
7fd59977 864 if(NumberOfEdges == 1) {
865#ifdef DEB
866 if (trc) cout << " One Edge" << endl;
867#endif
868 exp.ReInit();
869 Standard_Real f, l;//, f1, l1, temp;
870 gp_Pnt firstpoint, lastpoint;
871
0d969553 872// Points limit the unique edge
7fd59977 873 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
874 Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
875 gp_Pnt p1 = BRep_Tool::Pnt(TopExp::FirstVertex(E,Standard_True));
876 gp_Pnt p2 = BRep_Tool::Pnt(TopExp::LastVertex(E,Standard_True));
877
878 Standard_Real FirstPar = f; Standard_Real LastPar = l;
879
880
0d969553
Y
881// ---Find if 2 points limiting the unique edge of the wire
882// are on an edge or a vertex of the base shape
7fd59977 883 Standard_Boolean PtOnFirstVertex = Standard_False;
884 Standard_Boolean PtOnLastVertex = Standard_False;
885 TopoDS_Vertex OnFirstVertex, OnLastVertex;
886 PtOnEdgeVertex(RevolRib, mySbase, p1, FirstVertex, LastVertex,
4e57c75e 887 PtOnFirstEdge, OnFirstEdge, PtOnFirstVertex, OnFirstVertex);
7fd59977 888 PtOnEdgeVertex(RevolRib, mySbase, p2, FirstVertex, LastVertex,
4e57c75e 889 PtOnLastEdge, OnLastEdge, PtOnLastVertex, OnLastVertex);
7fd59977 890
891 TopTools_MapOfShape Map;
892
893 if(PtOnFirstEdge) {
894 if (!PtOnFirstVertex) {
0d969553
Y
895// Find FirstFace : face of the base shape containing OnFirstEdge
896// meeting ChoiceOfFaces
4e57c75e 897 TopExp_Explorer ex4, ex5;
898 ex4.Init(mySbase, TopAbs_FACE);
899 TopTools_ListOfShape faces;
900 faces.Clear();
901 Map.Clear();
902 for(; ex4.More(); ex4.Next()) {
903 const TopoDS_Face& fx = TopoDS::Face(ex4.Current());//modified by NIZNHY-PKV Fri Mar 22 17:06:04 2002 fx instead f
904 if ( !Map.Add(fx)) continue;
905 ex5.Init(ex4.Current(), TopAbs_EDGE);
906 for(; ex5.More(); ex5.Next()) {
907 const TopoDS_Edge& ee = TopoDS::Edge(ex5.Current());
908 if(ee.IsSame(OnFirstEdge)) {
909 faces.Append(fx);
910 }
911 }
912 }
913 if(!faces.IsEmpty()) {
914 TopoDS_Face FFF = ChoiceOfFaces(faces, cc, FirstPar+bnd/50., bnd/50., Pln);
915 if(!FFF.IsNull()) FirstFace = FFF;
916 }
7fd59977 917 }
918 else if(PtOnFirstVertex) {
0d969553
Y
919// Find FirstFace : face of the base shape containing OnFirstVertex
920// meeting ChoiceOfFaces
4e57c75e 921 TopExp_Explorer ex4, ex5;
922 ex4.Init(mySbase, TopAbs_FACE);
923 TopTools_ListOfShape faces;
924 faces.Clear();
925 Map.Clear();
926 for(; ex4.More(); ex4.Next()) {
927 const TopoDS_Face& fx = TopoDS::Face(ex4.Current());//modified by NIZNHY-PKV Fri Mar 22 17:06:36 2002 fx instead of f
928 if ( !Map.Add(fx)) continue;
929 ex5.Init(ex4.Current(), TopAbs_VERTEX);
930 for(; ex5.More(); ex5.Next()) {
931 const TopoDS_Vertex& vv = TopoDS::Vertex(ex5.Current());
932 if(vv.IsSame(OnFirstVertex)) {
933 faces.Append(fx);
934 break;
935 }
936 }
937 }
938 if(!faces.IsEmpty()) {
939 TopoDS_Face FFF = ChoiceOfFaces(faces, cc, FirstPar+bnd/50., bnd/50., Pln);
940 if(!FFF.IsNull()) FirstFace = FFF;
941 }
7fd59977 942 }
943 FirstEdge = E;
944 BRepLib_MakeVertex v(p1);
945 FirstVertex = v;
946 OnFirstFace = Standard_True;
947 }
948
949 if(PtOnLastEdge) {
950 if (!PtOnLastVertex) {
0d969553
Y
951// Find LastFace : face of the base shape containing OnLastEdge
952// meeting ChoiceOfFaces
4e57c75e 953 TopExp_Explorer ex4, ex5;
954 ex4.Init(mySbase, TopAbs_FACE);
955 TopTools_ListOfShape faces;
956 faces.Clear();
957 Map.Clear();
958 for(; ex4.More(); ex4.Next()) {
959 const TopoDS_Face& fx = TopoDS::Face(ex4.Current());//modified by NIZNHY-PKV Fri Mar 22 17:06:36 2002 fx instead of f
960 if ( !Map.Add(fx)) continue;
961 ex5.Init(ex4.Current(), TopAbs_EDGE);
962 for(; ex5.More(); ex5.Next()) {
963 const TopoDS_Edge& ee = TopoDS::Edge(ex5.Current());
964 if(ee.IsSame(OnLastEdge)) {
965 faces.Append(fx);
966 break;
967 }
968 }
969 }
970 if(!faces.IsEmpty()) {
971 TopoDS_Face FFF = ChoiceOfFaces(faces, cc, LastPar-bnd/50., bnd/50., Pln);
972 if(!FFF.IsNull()) LastFace = FFF;
973 }
7fd59977 974 }
975 else if(PtOnLastEdge && PtOnLastVertex) {
0d969553
Y
976// Find LastFace : face of the base shape containing OnLastVertex
977// meeting ChoiceOfFaces
4e57c75e 978 TopExp_Explorer ex4, ex5;
979 ex4.Init(mySbase, TopAbs_FACE);
980 TopTools_ListOfShape faces;
981 faces.Clear();
982 Map.Clear();
983 for(; ex4.More(); ex4.Next()) {
984 const TopoDS_Face& fx = TopoDS::Face(ex4.Current());//modified by NIZNHY-PKV Fri Mar 22 17:06:36 2002 fx instead of f
985 if ( !Map.Add(fx)) continue;
986 ex5.Init(ex4.Current(), TopAbs_VERTEX);
987 for(; ex5.More(); ex5.Next()) {
988 const TopoDS_Vertex& vv = TopoDS::Vertex(ex5.Current());
989 if(vv.IsSame(OnLastVertex)) {
990 faces.Append(fx);
991 break;
992 }
993 }
994 }
995 if(!faces.IsEmpty()) {
996 TopoDS_Face FFF = ChoiceOfFaces(faces, cc, LastPar-bnd/50., bnd/50., Pln);
997 if(!FFF.IsNull()) LastFace = FFF;
998 }
7fd59977 999 }
1000 LastEdge = E;
1001 BRepLib_MakeVertex v(p2);
1002 LastVertex = v;
1003 OnLastFace = Standard_True;
1004 }
1005
1006 if(!FirstFace.IsNull() && !LastFace.IsNull()) {
1007 return Standard_True;
1008 }
1009
0d969553 1010//--- FirstFace or LastFace was not found
7fd59977 1011#ifdef DEB
1012 if (trc) cout << " FirstFace or LastFace null" << endl;
1013#endif
1014 LocOpe_CSIntersector ASI(mySbase);
1015 TColGeom_SequenceOfCurve scur;
1016 scur.Clear();
1017 scur.Append(cc);
1018 ASI.Perform(scur);
1019 Standard_Real lastpar, firstpar;
1020 if(ASI.IsDone() && ASI.NbPoints(1) >= 2) {
1021 lastpar = ASI.Point(1, ASI.NbPoints(1)).Parameter();
1022 Standard_Integer lastindex = ASI.NbPoints(1);
1023 if(lastpar > l) {
4e57c75e 1024 for(Standard_Integer jj=ASI.NbPoints(1)-1; jj>=1; jj--) {
1025 Standard_Real par = ASI.Point(1,jj).Parameter();
1026 if(par <= l) {
1027 lastpar = par;
1028 lastindex = jj;
1029 break;
1030 }
1031 }
7fd59977 1032 }
1033 Standard_Integer firstindex = lastindex -1;
1034 firstpar = ASI.Point(1,firstindex).Parameter();
1035
1036 if(FirstFace.IsNull()) {
4e57c75e 1037 FirstFace = ASI.Point(1, firstindex).Face();
1038 cc->D0(firstpar, firstpoint);
1039 BRepLib_MakeVertex v1(firstpoint);
1040 FirstVertex = TopoDS::Vertex(v1.Shape());
1041 FirstEdge = E;
7fd59977 1042 }
1043
1044 if(LastFace.IsNull()) {
4e57c75e 1045 LastFace = ASI.Point(1, lastindex).Face();
1046 cc->D0(lastpar, lastpoint);
1047 BRepLib_MakeVertex v2(lastpoint);
1048 LastVertex = TopoDS::Vertex(v2.Shape());
1049 LastEdge = E;
7fd59977 1050 }
1051 }
1052 else {
1053#ifdef DEB
1054 if (trc) cout << " Less than 2 intersection points" << endl;
1055#endif
1056 Data = Standard_False;
1057 return Data;
1058 }
1059
1060 if(!OnFirstFace) {
1061 if(p1.Distance(firstpoint) <= Precision::Confusion())
4e57c75e 1062 OnFirstFace = Standard_True;
7fd59977 1063 else OnFirstFace = Standard_False;
1064 }
1065
1066 if(!OnLastFace) {
1067 if(p2.Distance(lastpoint) <= Precision::Confusion())
4e57c75e 1068 OnLastFace = Standard_True;
7fd59977 1069 else OnLastFace = Standard_False;
1070 }
1071
1072 if(FirstFace.IsNull() || LastFace.IsNull()) {
1073#ifdef DEB
1074 if (trc) cout << " First or Last Faces still null" << endl;
1075#endif
1076 Data = Standard_False;
1077 }
1078 else {
1079#ifdef DEB
1080 if (trc) cout << " FirstFace and LastFace OK" << endl;
1081#endif
1082 Data = Standard_True;
1083 }
1084
1085 return Data;
1086 }
0d969553 1087// ---The wire consists of several edges
7fd59977 1088 else {
1089#ifdef DEB
1090 if (trc) cout << " Multiple Edges" << endl;
1091#endif
1092 BRepTools_WireExplorer ex(myWire);
1093 for(; ex.More(); ex.Next()) {
1094 const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
1095 Standard_Real f, l;
1096 Handle(Geom_Curve) Cur = BRep_Tool::Curve(E, f, l);
1097 f = f - bnd/10000; l = l +bnd/10000;
1098 Handle(Geom_TrimmedCurve) curve;
1099 curve = new Geom_TrimmedCurve(Cur, f, l, Standard_True);
1100#ifdef DEB
1101 gp_Pnt P1 =
1102#endif
4e57c75e 1103 BRep_Tool::Pnt(TopExp::FirstVertex(E,Standard_True));
7fd59977 1104 gp_Pnt P2 = BRep_Tool::Pnt(TopExp::LastVertex(E,Standard_True));
1105 ex1.Init(mySbase, TopAbs_FACE);
1106 TopoDS_Vertex theVertex;
1107 TopoDS_Edge theEdge;
1108 TopoDS_Face theFace;
1109 Standard_Boolean PtOnEdge = Standard_False;
1110 Standard_Boolean PtOnVertex = Standard_False;
1111 TopoDS_Edge OnEdge;
1112 TopoDS_Vertex OnVertex;
1113 Standard_Real intpar;
1114 for(; ex1.More(); ex1.Next()) {
4e57c75e 1115 const TopoDS_Face& f = TopoDS::Face(ex1.Current());
1116 inter.Init(f,curve, BRep_Tool::Tolerance(f));
1117 if(!inter.More()) continue;
1118 for(; inter.More(); inter.Next()) {
1119 gp_Pnt thePoint = inter.Pnt();
1120 if(!FirstVertex.IsNull()) {
1121 gp_Pnt point = BRep_Tool::Pnt(FirstVertex);
1122 if(point.Distance(thePoint) <= BRep_Tool::Tolerance(f)) {
1123 continue;
1124 }
1125 }
1126 intpar = IntPar(curve, thePoint);
1127 theEdge = E;
1128 theFace = f;
1129 B.MakeVertex(theVertex, thePoint, Precision::Confusion());
1130 if(!FirstOK) {
1131 if(thePoint.Distance(P2) <= Precision::Confusion()) {
1132 continue;
1133 }
1134 }
7fd59977 1135
0d969553 1136// ---Find thepoint on an edge or a vertex of face f
4e57c75e 1137 PtOnEdgeVertex(RevolRib, f, thePoint, FirstVertex, LastVertex,
1138 PtOnEdge,OnEdge,PtOnVertex,OnVertex);
1139
1140
1141// if(!theEdge.IsNull()) break;
1142
1143 if (FirstEdge.IsNull() && !theEdge.IsNull() &&
1144 !theFace.IsNull() && !theVertex.IsNull()) {
1145 FirstEdge = theEdge;
1146 FirstFace = theFace;
1147 FirstVertex = theVertex;
1148 PtOnFirstEdge = PtOnEdge;
1149 OnFirstEdge = OnEdge;
1150 theEdge.Nullify(); theFace.Nullify(); theVertex.Nullify();
1151 if(PtOnEdge && !PtOnVertex) {
1152 TopTools_ListOfShape faces;
1153 faces.Clear();
1154 faces.Append(FirstFace);
1155 TopExp_Explorer ex2;
1156 ex2.Init(mySbase, TopAbs_FACE);
1157 for(; ex2.More(); ex2.Next()) {
1158 TopoDS_Face fx = TopoDS::Face(ex2.Current());//modified by NIZNHY-PKV Fri Mar 22 17:16:44 2002 fx/f
1159 TopExp_Explorer ex3;
1160 ex3.Init(fx, TopAbs_EDGE);
1161 for(; ex3.More(); ex3.Next()) {
1162 const TopoDS_Edge& e = TopoDS::Edge(ex3.Current());
1163 if(e.IsSame(OnEdge) && !fx.IsSame(FirstFace)) {
1164 faces.Append(fx);
1165 }
1166 }
1167 }
1168 TopoDS_Face FFF = ChoiceOfFaces(faces, curve, intpar+bnd/10., bnd/10., Pln);
1169 if(!FFF.IsNull()) FirstFace = FFF;
1170 }
1171 else if(PtOnEdge && PtOnVertex) {
1172 TopTools_ListOfShape faces;
1173 faces.Clear();
1174 faces.Append(FirstFace);
1175 TopExp_Explorer ex2;
1176 ex2.Init(mySbase, TopAbs_FACE);
1177 for(; ex2.More(); ex2.Next()) {
1178 TopoDS_Face fx = TopoDS::Face(ex2.Current());//modified by NIZNHY-PKV Fri Mar 22 17:13:08 2002 fx/f
1179 TopExp_Explorer ex3;
1180 ex3.Init(fx, TopAbs_VERTEX);
1181 for(; ex3.More(); ex3.Next()) {
1182 const TopoDS_Vertex& v = TopoDS::Vertex(ex3.Current());
1183 if(v.IsSame(OnVertex) && !fx.IsSame(FirstFace)) {
1184 faces.Append(fx);
1185 }
1186 }
1187 }
1188 TopoDS_Face FFF = ChoiceOfFaces(faces, curve, intpar+bnd/10., bnd/10., Pln);
1189 if(!FFF.IsNull()) FirstFace = FFF;
1190 }
1191 if(!FirstEdge.IsNull() && !FirstFace.IsNull()
1192 && !FirstVertex.IsNull()) {
1193 FirstOK = Standard_True;
1194 }
1195 }
1196 if(LastEdge.IsNull() && !theEdge.IsNull() &&
1197 !theFace.IsNull() && !theVertex.IsNull() &&
1198 !FirstEdge.IsNull()) {
1199 LastEdge = theEdge;
1200 LastFace = theFace;
1201 LastVertex = theVertex;
1202 PtOnLastEdge = PtOnEdge;
1203 OnLastEdge = OnEdge;
1204 if(PtOnEdge && !PtOnVertex) {
1205 TopTools_ListOfShape faces;
1206 faces.Clear();
1207 faces.Append(LastFace);
1208 TopExp_Explorer ex2;
1209 ex2.Init(mySbase, TopAbs_FACE);
1210 for(; ex2.More(); ex2.Next()) {
1211 TopoDS_Face fx = TopoDS::Face(ex2.Current());//modified by NIZNHY-PKV Fri Mar 22 17:12:06 2002 fx/f
1212 TopExp_Explorer ex3;
1213 ex3.Init(fx, TopAbs_EDGE);
1214 for(; ex3.More(); ex3.Next()) {
1215 const TopoDS_Edge& e = TopoDS::Edge(ex3.Current());
1216 if(e.IsSame(OnEdge) && !fx.IsSame(LastFace)) {
1217 faces.Append(fx);
1218 }
1219 }
1220 }
1221 TopoDS_Face FFF = ChoiceOfFaces(faces, curve, intpar-bnd/10.,bnd/10., Pln);
1222 if(!FFF.IsNull()) LastFace = FFF;
1223 }
1224 else if(PtOnEdge && PtOnVertex) {
1225 TopTools_ListOfShape faces;
1226 faces.Clear();
1227 faces.Append(LastFace);
1228 TopExp_Explorer ex2;
1229 ex2.Init(mySbase, TopAbs_FACE);
1230 for(; ex2.More(); ex2.Next()) {
1231 TopoDS_Face fx = TopoDS::Face(ex2.Current());//modified by NIZNHY-PKV Fri Mar 22 17:11:36 2002 fx/f
1232 TopExp_Explorer ex3;
1233 ex3.Init(fx, TopAbs_VERTEX);
1234 for(; ex3.More(); ex3.Next()) {
1235 const TopoDS_Vertex& v = TopoDS::Vertex(ex3.Current());
1236 if(v.IsSame(OnVertex) && !fx.IsSame(LastFace)) {
1237 faces.Append(fx);
1238 }
1239 }
1240 }
1241 TopoDS_Face FFF = ChoiceOfFaces(faces, curve, intpar-bnd/10.,bnd/10., Pln);
1242 if(!FFF.IsNull()) LastFace = FFF;
1243 }
1244 if(!LastEdge.IsNull() && !LastFace.IsNull()
1245 && !LastVertex.IsNull()) {
1246 LastOK = Standard_True;
1247 }
1248 break;
1249 }
1250 }
7fd59977 1251 }
1252 }
1253
1254 if(FirstOK && LastOK) {
1255 Data = Standard_True;
1256 gp_Pnt PP1 = BRep_Tool::Pnt(TopExp::FirstVertex(FirstEdge,Standard_True));
1257 gp_Pnt PP2 = BRep_Tool::Pnt(TopExp::LastVertex(LastEdge,Standard_True));
1258 gp_Pnt p1 = BRep_Tool::Pnt(FirstVertex);
1259 gp_Pnt p2 = BRep_Tool::Pnt(LastVertex);
1260 if(p1.Distance(PP1) <= BRep_Tool::Tolerance(FirstFace)) {
4e57c75e 1261 OnFirstFace = Standard_True;
7fd59977 1262 }
1263 if(p2.Distance(PP2) <= BRep_Tool::Tolerance(LastFace)) {
4e57c75e 1264 OnLastFace = Standard_True;
7fd59977 1265 }
1266 return Standard_True;
1267 }
1268 else {
1269#ifdef DEB
1270 if (trc) cout << " First or Last not OK" << endl;
1271#endif
1272 return Standard_False;
1273 }
1274 }
1275}
1276
1277
1278//=======================================================================
1279//function : PtOnEdgeVertex
0d969553
Y
1280//purpose : Find if 2 limit points of the unique edge of a wire
1281// are on an edge or a vertex of the base shape
7fd59977 1282//=======================================================================
1283
1284void BRepFeat_RibSlot::PtOnEdgeVertex(const Standard_Boolean RevolRib,
4e57c75e 1285 const TopoDS_Shape& shape,
1286 const gp_Pnt& point,
1287 const TopoDS_Vertex& ,//FirstVertex,
1288 const TopoDS_Vertex& ,//LastVertex,
1289 Standard_Boolean& PtOnEdge,
1290 TopoDS_Edge& OnEdge,
1291 Standard_Boolean& PtOnVertex,
1292 TopoDS_Vertex& OnVertex)
7fd59977 1293
1294{
1295#ifdef DEB
1296 Standard_Boolean trc = BRepFeat_GettraceFEATRIB();
1297 if (trc) cout << "BRepFeat_RibSlot::PtOnEdgeVertex" << endl;
1298#endif
1299 Standard_Boolean TestOK;
1300// PtOnEdge = Standard_False;
1301// OnEdge.Nullify();
1302// PtOnVertex = Standard_False;
1303// OnVertex.Nullify();
1304
1305 TopExp_Explorer EXP;
1306 EXP.Init(shape, TopAbs_EDGE);
1307 TopTools_MapOfShape Map;
1308 for(; EXP.More(); EXP.Next()) {
1309 const TopoDS_Edge& e = TopoDS::Edge(EXP.Current());
1310 if ( !Map.Add(e)) continue;
1311 if (!RevolRib) {
1312 if (BRep_Tool::Degenerated(e)) continue;
1313 }
1314 Standard_Real fff, lll;
1315 Handle(Geom_Curve) ccc = BRep_Tool::Curve(e, fff, lll);
1316 if (!RevolRib) {
1317 ccc = new Geom_TrimmedCurve(ccc, fff, lll);
1318 }
1319 GeomAPI_ProjectPointOnCurve proj(point, ccc);
1320 TestOK = Standard_False;
1321 if (!RevolRib) {
1322 if(proj.NbPoints() == 1) TestOK = Standard_True;
1323 }
1324 else {
1325 if(proj.NbPoints() >= 1) TestOK = Standard_True;
1326 }
1327 if(TestOK && proj.Distance(1) <= BRep_Tool::Tolerance(e)) {
1328 PtOnEdge = Standard_True;
4e57c75e 1329 OnEdge = e;
7fd59977 1330 TopoDS_Vertex ev1 = TopExp::FirstVertex(e,Standard_True);
1331 TopoDS_Vertex ev2 = TopExp::LastVertex(e,Standard_True);
1332 gp_Pnt ep1 = BRep_Tool::Pnt(ev1);
1333 gp_Pnt ep2 = BRep_Tool::Pnt(ev2);
1334 if(point.Distance(ep1) <= BRep_Tool::Tolerance(ev1)) {
4e57c75e 1335 PtOnVertex = Standard_True;
1336 OnVertex = ev1;
1337 break;
7fd59977 1338 }
1339 else if(point.Distance(ep2) <= BRep_Tool::Tolerance(ev1)) {
4e57c75e 1340 PtOnVertex = Standard_True;
1341 OnVertex = ev2;
1342 break;
1343 }
7fd59977 1344 break;
1345 }
1346 }
1347}
1348
1349
1350//=======================================================================
1351//function : SlidingProfile
0d969553 1352//purpose : construction of the profile face in case of sliding
7fd59977 1353//=======================================================================
1354
1355Standard_Boolean BRepFeat_RibSlot::SlidingProfile(TopoDS_Face& Prof,
4e57c75e 1356 const Standard_Boolean RevolRib,
1357 const Standard_Real myTol,
1358 Standard_Integer& Concavite,
1359 const Handle(Geom_Plane)& myPln,
1360 const TopoDS_Face& BndFace,
1361 const gp_Pnt& CheckPnt,
1362 const TopoDS_Face& FirstFace,
1363 const TopoDS_Face& LastFace,
1364 const TopoDS_Vertex& ,//FirstVertex,
1365 const TopoDS_Vertex& ,//LastVertex,
1366 const TopoDS_Edge& FirstEdge,
1367 const TopoDS_Edge& LastEdge)
7fd59977 1368
1369{
1370#ifdef DEB
1371 Standard_Boolean trc = BRepFeat_GettraceFEAT();
1372 if (trc) cout << "BRepFeat_RibSlot::SlidingProfile" << endl;
1373#endif
1374 Standard_Boolean ProfileOK = Standard_True;
0d969553
Y
1375// --case of sliding : construction of the wire of the profile
1376// --> 1 part bounding box + 1 part wire
1377// attention to the compatibility of orientations
7fd59977 1378
1379 gp_Dir FN, LN;
1380 BRepLib_MakeWire WW;
1381
1382 FN = Normal(FirstFace, myFirstPnt);
1383 LN = Normal(LastFace, myLastPnt);
1384
0d969553
Y
1385// Case of the groove (cut) <> rib (fuse)
1386// -> we are in the material
1387// -> make everything in 2d in the working plane : easier
7fd59977 1388 if(!myFuse) {
1389 FN = -FN;
1390 LN = -LN;
1391 }
1392
1393
1394 Handle(Geom_Line) ln1, ln2;
1395 gp_Pnt Pt;//,p1, p2;
1396
1397 ln2 = new Geom_Line(myFirstPnt, FN);
1398 ln1 = new Geom_Line(myLastPnt, LN);
1399
1400 Handle(Geom2d_Curve) ln2d1 = GeomAPI::To2d(ln1, myPln->Pln());
1401 Handle(Geom2d_Curve) ln2d2 = GeomAPI::To2d(ln2, myPln->Pln());
1402
1403 Geom2dAPI_InterCurveCurve inter(ln2d1, ln2d2, Precision::Confusion());
1404
1405 Standard_Boolean TestOK = Standard_True;
1406 if (RevolRib) {
1407 gp_Dir d1, d2;
1408 d1 = ln1->Position().Direction();
1409 d2 = ln2->Position().Direction();
1410 if(d1.IsOpposite(d2, myTol)) {
1411 Standard_Real par1 = ElCLib::Parameter(ln1->Lin(), myFirstPnt);
1412 Standard_Real par2 = ElCLib::Parameter(ln2->Lin(), myLastPnt);
1413 if(par1 >= myTol || par2 >= myTol) {
4e57c75e 1414 Concavite = 2; //paralel and concave
1415 BRepLib_MakeEdge e1(myLastPnt, myFirstPnt);
1416 WW.Add(e1);
7fd59977 1417 }
1418 }
1419 if(d1.IsEqual(d2, myTol)) {
1420 if(Concavite == 3) TestOK = Standard_False;
1421 }
1422 }
1423
1424 if(TestOK) {
1425 if(inter.NbPoints() > 0) {
1426 gp_Pnt2d P = inter.Point(1);
1427 myPln->D0(P.X(), P.Y(), Pt);
1428 Standard_Real par = IntPar(ln1, Pt);
1429 if(par>0) Concavite = 1; //concave
1430 }
1431 }
1432
0d969553 1433// ---Construction of the profile face
7fd59977 1434 if(Concavite == 1) {
0d969553
Y
1435// if concave : it is possible to extend first and last edges of the wire
1436// to the bounding box
7fd59977 1437 BRepLib_MakeEdge e1(myLastPnt, Pt);
1438 WW.Add(e1);
1439 BRepLib_MakeEdge e2(Pt, myFirstPnt);
1440 WW.Add(e2);
1441 }
1442 else if(Concavite == 3) {
0d969553 1443// BndEdge : edges of intersection with the bounding box
7fd59977 1444 TopoDS_Edge BndEdge1, BndEdge2;
0d969553 1445// Points of intersection with the bounding box / Find Profile
7fd59977 1446 gp_Pnt BndPnt1, BndPnt2, LastPnt;
1447 TopExp_Explorer expl;
1448 expl.Init(BndFace, TopAbs_WIRE);
1449 BRepTools_WireExplorer explo;
1450 TopoDS_Wire BndWire = TopoDS::Wire(expl.Current());
1451 explo.Init(BndWire);
1452 for(; explo.More(); explo.Next()) {
1453 const TopoDS_Edge& e = TopoDS::Edge(explo.Current());
1454 Standard_Real first, last;
1455 Handle(Geom_Curve) c = BRep_Tool::Curve(e, first, last);
1456 Handle(Geom2d_Curve) c2d = GeomAPI::To2d(c, myPln->Pln());
1457 Geom2dAPI_InterCurveCurve intcln1(ln2d1, c2d,
4e57c75e 1458 Precision::Confusion());
7fd59977 1459 if(intcln1.NbPoints() > 0) {
4e57c75e 1460 gp_Pnt2d p2d = intcln1.Point(1);
1461 gp_Pnt p;
1462 myPln->D0(p2d.X(), p2d.Y(), p);
1463 Standard_Real parl = IntPar(ln1, p);
1464 Standard_Real parc = IntPar(c, p);
1465 if(parc >= first && parc <= last && parl >= 0) {
1466 BndEdge1 = e;
1467 BndPnt1 = p;
1468 }
7fd59977 1469 }
1470
1471 Geom2dAPI_InterCurveCurve intcln2(ln2d2, c2d,
4e57c75e 1472 Precision::Confusion());
7fd59977 1473 if(intcln2.NbPoints() > 0) {
4e57c75e 1474 gp_Pnt2d p2d = intcln2.Point(1);
1475 gp_Pnt p;
1476 myPln->D0(p2d.X(), p2d.Y(), p);
1477 Standard_Real parl = IntPar(ln2, p);
1478 Standard_Real parc = IntPar(c, p);
1479 if(parc >= first && parc <= last && parl >= 0) {
1480 BndEdge2 = e;
1481 BndPnt2 = p;
1482 }
7fd59977 1483 }
1484 if(!BndEdge1.IsNull() && !BndEdge2.IsNull()) break;
1485 }
1486
1487 if(BndEdge1.IsNull() || BndEdge2.IsNull()) {
1488#ifdef DEB
1489 if (trc) cout << " Null bounding edge" << endl;
1490#endif
1491 ProfileOK = Standard_False;
1492 return ProfileOK;
1493 }
1494
1495
1496 BRepLib_MakeEdge e1(myLastPnt, BndPnt1);
1497 WW.Add(e1);
1498
1499 if(BndEdge1.IsSame(BndEdge2)) {
0d969553 1500// Particular case : same edge -> simply determined path
7fd59977 1501 BRepLib_MakeEdge e2(BndPnt1, BndPnt2);
1502 WW.Add(e2);
1503 BRepLib_MakeEdge e3(BndPnt2, myFirstPnt);
4e57c75e 1504 WW.Add(e3);
7fd59977 1505 }
1506 else {
1507 explo.Init(BndWire);
1508 for(; explo.More(); explo.Next()) {
4e57c75e 1509 const TopoDS_Edge& e = TopoDS::Edge(explo.Current());
1510 if(e.IsSame(BndEdge1)) {
1511 gp_Pnt pp;
1512 pp = BRep_Tool::Pnt(TopExp::LastVertex(e,Standard_True));
1513 if(pp.Distance(BndPnt1) >= BRep_Tool::Tolerance(e)) {
1514 LastPnt = pp;
1515 }
1516// else { //LinearForm
1517// gp_Pnt ppp = BRep_Tool::Pnt(TopExp::FirstVertex(e,Standard_True));
1518// LastPnt = ppp;
1519// }
1520 BRepLib_MakeEdge e2(BndPnt1, LastPnt);
1521 WW.Add(e2);
1522 break;
1523 }
7fd59977 1524 }
1525
1526 if(explo.More()) {
4e57c75e 1527 explo.Next();
1528 if(explo.Current().IsNull()) explo.Init(BndWire);
7fd59977 1529 }
1530 else explo.Init(BndWire);
1531
0d969553
Y
1532// Check if this is BndEdge2
1533// -> if yes : it is required to turn to join FirstPnt
1534// -> if no : add edges
7fd59977 1535 Standard_Boolean Fin = Standard_False;
1536 while(!Fin) {
4e57c75e 1537 const TopoDS_Edge& e = TopoDS::Edge(explo.Current());
1538 if(!e.IsSame(BndEdge2)) {
1539 gp_Pnt pp;
1540 pp = BRep_Tool::Pnt(TopExp::LastVertex(e,Standard_True));
1541 BRepLib_MakeEdge ee(LastPnt, pp);
1542 WW.Add(ee);
1543 LastPnt = pp;
1544 }
1545 else {
0d969553
Y
1546// the path is closed
1547// -> since met BndEdge2, end of borders on BndFace
4e57c75e 1548 Fin = Standard_True;
1549 BRepLib_MakeEdge ee(LastPnt, BndPnt2);
1550 WW.Add(ee);
1551 LastPnt = BndPnt2;
1552 }
1553 if(explo.More()) {
1554 explo.Next();
1555 if(explo.Current().IsNull()) {
1556 explo.Init(BndWire);
1557 }
1558 }
1559 else explo.Init(BndWire);
7fd59977 1560 }
1561
1562 BRepLib_MakeEdge e3(BndPnt2, myFirstPnt);
1563 WW.Add(e3);
1564 }
1565 }
1566
0d969553 1567// ---Construction of the profile
7fd59977 1568
0d969553
Y
1569// Explore the wire provided by the user
1570// BRepTools_WireExplorer : correct order - without repetition <> TopExp : non ordered
7fd59977 1571 BRepTools_WireExplorer EX(myWire);
1572
1573 Standard_Real ff, ll;
1574 Handle(Geom_Curve) FirstCurve = BRep_Tool::Curve(FirstEdge, ff, ll);
1575
1576 if(!FirstEdge.IsSame(LastEdge)) {
1577 TopoDS_Vertex FLVert = TopExp::LastVertex(FirstEdge,Standard_True);
1578 gp_Pnt FLPnt = BRep_Tool::Pnt(FLVert);
1579 BRepLib_MakeEdge ef(FirstCurve, myFirstPnt, FLPnt);
1580 WW.Add(ef);
1581 for(; EX.More(); EX.Next()) {
1582 const TopoDS_Edge& E = EX.Current();
4e57c75e 1583 if(E.IsSame(FirstEdge)) break;
7fd59977 1584 }
1585 EX.Next();
1586 for(; EX.More(); EX.Next()) {
1587 const TopoDS_Edge& E = EX.Current();
1588 if(!E.IsSame(LastEdge)) {
4e57c75e 1589 WW.Add(E);
1590 }
7fd59977 1591 else break;
1592 }
1593 Handle(Geom_Curve) LastCurve = BRep_Tool::Curve(LastEdge, ff, ll);
1594 TopoDS_Vertex LFVert = TopExp::FirstVertex(LastEdge,Standard_True);
1595 gp_Pnt LFPnt = BRep_Tool::Pnt(LFVert);
1596 BRepLib_MakeEdge el(LastCurve, LFPnt, myLastPnt);
1597 WW.Add(el);
1598 }
1599 else {
0d969553 1600// only one edge : particular processing
7fd59977 1601 Standard_Real fpar = IntPar(FirstCurve, myFirstPnt);
1602 Standard_Real lpar = IntPar(FirstCurve, myLastPnt);
1603 Handle(Geom_Curve) c;
1604 if(fpar > lpar)
1605 c = Handle(Geom_Curve)::DownCast(FirstCurve->Reversed());
1606 else
1607 c = FirstCurve;
1608
1609 BRepLib_MakeEdge ef(c, myFirstPnt, myLastPnt);
1610 WW.Add(ef);
1611 }
1612
1613 BRepLib_MakeFace f(myPln->Pln(), WW, Standard_True);
1614 TopoDS_Face fac = TopoDS::Face(f.Shape());
1615
1616 if (!BRepAlgo::IsValid(fac)) {
1617#ifdef DEB
1618 if (trc) cout << " Invalid Face" << endl;
1619#endif
1620 ProfileOK = Standard_False;
1621 return ProfileOK;
1622 }
1623
1624 if(Concavite != 3) {
0d969553 1625// if concave : face is OK
7fd59977 1626 Prof = fac;
1627 }
1628 else {
0d969553
Y
1629// if not concave
1630// CheckPnt : point slightly inside the material side
1631// Bndface : face/cut of the bounding box in the plane of the profile
7fd59977 1632 BRepTopAdaptor_FClass2d Cl(fac, BRep_Tool::Tolerance(fac));
1633 Standard_Real u, v;
1634 ElSLib::Parameters(myPln->Pln(), CheckPnt, u, v);
1635 gp_Pnt2d checkpnt2d(u, v);
1636 if(Cl.Perform(checkpnt2d, Standard_True) == TopAbs_OUT) {
0d969553 1637// If face is not the correct part of BndFace take the complementary
7fd59977 1638 //modified by NIZNHY-PKV Fri Mar 22 16:46:20 2002 f
1639 //BRepAlgo_Cut c(BndFace, fac);
1640 BRepAlgoAPI_Cut c(BndFace, fac);
1641 //modified by NIZNHY-PKV Fri Mar 22 16:46:23 2002 t
1642 TopExp_Explorer exp(c.Shape(), TopAbs_WIRE);
1643 const TopoDS_Wire& w = TopoDS::Wire(exp.Current());
1644 BRepLib_MakeFace ffx(w);//modified by NIZNHY-PKV Fri Mar 22 17:10:43 2002 ffx/ff
1645 Prof = TopoDS::Face(ffx.Shape());
1646 }
1647 else {
0d969553 1648// If face is the correct part of BndFace : face is OK
7fd59977 1649 Prof = fac;
1650 }
1651 }
1652
1653 if (!BRepAlgo::IsValid(Prof)) {
1654#ifdef DEB
1655 if (trc) cout << " Invalid Face Profile" << endl;
1656#endif
1657 ProfileOK = Standard_False;
1658 return ProfileOK;
1659 }
1660 return ProfileOK;
1661}
1662//=======================================================================
1663//function : NoSlidingProfile
0d969553 1664//purpose : construction of the face profile in case of sliding
7fd59977 1665//=======================================================================
1666
1667Standard_Boolean BRepFeat_RibSlot::NoSlidingProfile(TopoDS_Face& Prof,
4e57c75e 1668 const Standard_Boolean RevolRib,
1669 const Standard_Real myTol,
1670 Standard_Integer& Concavite,
1671 const Handle(Geom_Plane)& myPln,
1672 const Standard_Real bnd,
1673 const TopoDS_Face& BndFace,
1674 const gp_Pnt& CheckPnt,
1675 const TopoDS_Face& ,//FirstFace,
1676 const TopoDS_Face& ,//LastFace,
1677 const TopoDS_Vertex& ,//FirstVertex,
1678 const TopoDS_Vertex& ,//LastVertex,
1679 const TopoDS_Edge& FirstEdge,
1680 const TopoDS_Edge& LastEdge,
1681 const Standard_Boolean OnFirstFace,
1682 const Standard_Boolean OnLastFace)
7fd59977 1683
1684{
1685#ifdef DEB
1686 Standard_Boolean trc = BRepFeat_GettraceFEAT();
1687 if (trc) cout << "BRepFeat_RibSlot::NoSlidingProfile" << endl;
1688#endif
1689 Standard_Boolean ProfileOK = Standard_True;
1690
4e57c75e 1691 Standard_Real l1, f1, f2, l2;//, p;
7fd59977 1692 TopoDS_Vertex theFV; theFV.Nullify();
1693 gp_Pnt theFirstpoint;
1694 TopoDS_Edge theLastEdge; theLastEdge.Nullify();
1695 gp_Pnt firstpoint, lastpoint;//, pp1, pp2;
1696 gp_Vec firstvect, lastvect;
1697 TopoDS_Wire w;
1698 BRep_Builder BB;
1699 BB.MakeWire(w);
1700 //gp_Pnt p1, p3;
1701 TopoDS_Edge FalseFirstEdge, FalseLastEdge, FalseOnlyOne;
1702
1703 Handle(Geom_Curve) FirstCurve = BRep_Tool::Curve(FirstEdge, f1, l1);
1704 Handle(Geom_Curve) LastCurve = BRep_Tool::Curve(LastEdge, f2, l2);
1705
1706 Handle(Geom_Line) firstln, lastln;
1707 FirstCurve->D1(f1, firstpoint, firstvect);
1708 lastln = new Geom_Line(firstpoint, -firstvect);
1709 LastCurve->D1(l2, lastpoint, lastvect);
1710 firstln = new Geom_Line(lastpoint, lastvect);
1711
1712 gp_Pnt Pt;
1713
1714 Handle(Geom2d_Curve) ln2d1 = GeomAPI::To2d(firstln, myPln->Pln());
1715 Handle(Geom2d_Curve) ln2d2 = GeomAPI::To2d(lastln, myPln->Pln());
1716
1717 Geom2dAPI_InterCurveCurve inter(ln2d1, ln2d2, Precision::Confusion());
1718
1719 Standard_Boolean TestOK = Standard_True;
1720 if (RevolRib) {
1721 gp_Dir d1, d2;
1722 d1 = firstln->Position().Direction();
1723 d2 = lastln->Position().Direction();
1724 if(d1.IsOpposite(d2, myTol)) {
1725 Standard_Real par1 = ElCLib::Parameter(firstln->Lin(), myFirstPnt);
1726 Standard_Real par2 = ElCLib::Parameter(lastln->Lin(), myLastPnt);
1727 if(par1 >= myTol || par2 >= myTol)
4e57c75e 1728 Concavite = 2; //parallel and concave
7fd59977 1729 }
1730 if(d1.IsEqual(d2, myTol)) {
1731 if(Concavite == 3) TestOK = Standard_False;
1732 }
1733 }
1734
1735 if(TestOK) {
1736 if(inter.NbPoints() > 0) {
1737 gp_Pnt2d P = inter.Point(1);
1738 myPln->D0(P.X(), P.Y(), Pt);
1739 Standard_Real par = IntPar(firstln, Pt);
1740 if(par>0) Concavite = 1; //concave
1741 }
1742 }
1743
0d969553 1744// ---Construction of the face profile
7fd59977 1745 if(Concavite == 3) {
1746 if(OnFirstFace) {
1747 Standard_Real f, l;
1748 FalseFirstEdge = FirstEdge;
1749 EdgeExtention(FalseFirstEdge, bnd, Standard_True);
1750 const TopoDS_Vertex& vv1 = TopExp::FirstVertex(FalseFirstEdge,Standard_True);
1751 firstpoint = BRep_Tool::Pnt(vv1);
1752 Handle(Geom_Curve) cc = BRep_Tool::Curve(FalseFirstEdge, f, l);
1753 cc->D1(f, firstpoint, firstvect);
1754 lastln = new Geom_Line(firstpoint, -firstvect);
4e57c75e 1755 if(FirstEdge.IsSame(LastEdge)) FalseOnlyOne = FalseFirstEdge;
7fd59977 1756 ln2d2 = GeomAPI::To2d(lastln, myPln->Pln());
1757 }
1758 if(OnLastFace) {
1759 Standard_Real f, l;
1760 if(!FirstEdge.IsSame(LastEdge)) {
4e57c75e 1761 FalseLastEdge = LastEdge;
7fd59977 1762 }
1763 else {
4e57c75e 1764 if(FalseOnlyOne.IsNull()) FalseOnlyOne = LastEdge;
1765 FalseLastEdge = FalseOnlyOne;
7fd59977 1766 }
1767 EdgeExtention(FalseLastEdge, bnd, Standard_False);
1768 if(FirstEdge.IsSame(LastEdge)) {
4e57c75e 1769 FalseOnlyOne = FalseLastEdge;
7fd59977 1770 }
1771 const TopoDS_Vertex& vv2 = TopExp::LastVertex(FalseLastEdge,Standard_True);
1772 lastpoint = BRep_Tool::Pnt(vv2);
1773 Handle(Geom_Curve) cc = BRep_Tool::Curve(FalseLastEdge, f, l);
1774 cc->D1(l, lastpoint, lastvect);
1775 lastpoint = BRep_Tool::Pnt(vv2);
1776 firstln = new Geom_Line(lastpoint, lastvect);
1777 ln2d1 = GeomAPI::To2d(firstln, myPln->Pln());
1778 }
1779
1780 TopoDS_Edge BndEdge1, BndEdge2;
1781 gp_Pnt BndPnt1, BndPnt2, LastPnt;
1782 TopExp_Explorer expl;
1783 expl.Init(BndFace, TopAbs_WIRE);
1784 BRepTools_WireExplorer explo;
1785 TopoDS_Wire BndWire = TopoDS::Wire(expl.Current());
1786 explo.Init(BndWire);
1787 for(; explo.More(); explo.Next()) {
1788 const TopoDS_Edge& e = TopoDS::Edge(explo.Current());
1789 Standard_Real first, last;
1790 Handle(Geom_Curve) c = BRep_Tool::Curve(e, first, last);
1791 Handle(Geom2d_Curve) c2d = GeomAPI::To2d(c, myPln->Pln());
1792 Geom2dAPI_InterCurveCurve intcln1(ln2d1, c2d,
4e57c75e 1793 Precision::Confusion());
7fd59977 1794 if(intcln1.NbPoints() > 0) {
4e57c75e 1795 gp_Pnt2d p2d = intcln1.Point(1);
1796 gp_Pnt p;
1797 myPln->D0(p2d.X(), p2d.Y(), p);
1798 Standard_Real parl = IntPar(firstln, p);
1799 Standard_Real parc = IntPar(c, p);
1800 if(parc >= first && parc <= last && parl >= 0) {
1801 BndEdge1 = e;
1802 BndPnt1 = p;
1803 }
7fd59977 1804 }
1805
1806 Geom2dAPI_InterCurveCurve intcln2(ln2d2, c2d,
4e57c75e 1807 Precision::Confusion());
7fd59977 1808 if(intcln2.NbPoints() > 0) {
4e57c75e 1809 gp_Pnt2d p2d = intcln2.Point(1);
1810 gp_Pnt p;
1811 myPln->D0(p2d.X(), p2d.Y(), p);
1812 Standard_Real parl = IntPar(lastln, p);
1813 Standard_Real parc = IntPar(c, p);
1814 if(parc >= first && parc <= last && parl >= 0) {
1815 BndEdge2 = e;
1816 BndPnt2 = p;
1817 }
7fd59977 1818 }
1819 if(!BndEdge1.IsNull() && !BndEdge2.IsNull()) break;
1820 }
1821
1822 if(BndEdge1.IsNull() || BndEdge2.IsNull()) {
1823#ifdef DEB
1824 if (trc) cout << " Null bounding edge" << endl;
1825#endif
1826 ProfileOK = Standard_False;
1827 return ProfileOK;
1828 }
1829
1830 TopoDS_Edge ee1;
1831 if(theLastEdge.IsNull()) {
1832 BRepLib_MakeEdge e1(lastpoint, BndPnt1);
1833 ee1 = TopoDS::Edge(e1.Shape());
1834 }
1835 else {
1836 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
1837 BRepLib_MakeVertex v2(BndPnt1);
1838 BRepLib_MakeEdge e1(v1, v2);
1839 ee1 = TopoDS::Edge(e1.Shape());
1840 }
1841 BB.Add(w, ee1);
1842 theLastEdge = ee1;
1843 if(theFV.IsNull()) {
1844 theFV = TopExp::FirstVertex(ee1,Standard_True);
1845 theFirstpoint = BRep_Tool::Pnt(theFV);
1846 }
1847
1848 if(BndEdge1.IsSame(BndEdge2)) {
1849 TopoDS_Edge ee2, ee3;
1850 if(theLastEdge.IsNull()) {
4e57c75e 1851 BRepLib_MakeEdge e2(BndPnt1, BndPnt2);
1852 ee2 = TopoDS::Edge(e2.Shape());
7fd59977 1853 }
1854 else {
4e57c75e 1855 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
1856 BRepLib_MakeVertex v2(BndPnt2);
1857 BRepLib_MakeEdge e2(v1, v2);
1858 ee2 = TopoDS::Edge(e2.Shape());
7fd59977 1859 }
1860 BB.Add(w, ee2);
1861 theLastEdge = ee2;
1862 if(theFV.IsNull()) {
4e57c75e 1863 theFV = TopExp::FirstVertex(ee2,Standard_True);
1864 theFirstpoint = BRep_Tool::Pnt(theFV);
7fd59977 1865 }
1866 if(theLastEdge.IsNull()) {
4e57c75e 1867 BRepLib_MakeEdge e3(BndPnt2, firstpoint);
1868 ee3 = TopoDS::Edge(e3.Shape());
7fd59977 1869 }
1870 else {
4e57c75e 1871 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
1872 BRepLib_MakeVertex v2(firstpoint);
1873 BRepLib_MakeEdge e3(v1, v2);
1874 ee3 = TopoDS::Edge(e3.Shape());
7fd59977 1875 }
4e57c75e 1876 BB.Add(w, ee3);
7fd59977 1877 theLastEdge = ee3;
1878 if(theFV.IsNull()) {
4e57c75e 1879 theFV = TopExp::FirstVertex(ee3,Standard_True);
1880 theFirstpoint = BRep_Tool::Pnt(theFV);
7fd59977 1881 }
1882 }
1883 else {
1884 explo.Init(BndWire);
1885 for(; explo.More(); explo.Next()) {
4e57c75e 1886 const TopoDS_Edge& e = TopoDS::Edge(explo.Current());
1887 if(e.IsSame(BndEdge1)) {
1888 gp_Pnt pp;
1889 pp = BRep_Tool::Pnt(TopExp::LastVertex(e,Standard_True));
1890 if(pp.Distance(BndPnt1) > BRep_Tool::Tolerance(e)) {
1891 LastPnt = pp;
1892 }
1893 TopoDS_Edge eee;
1894 if(theLastEdge.IsNull()) {
1895 BRepLib_MakeEdge e2(BndPnt1, LastPnt);
1896 eee = TopoDS::Edge(e2.Shape());
1897 }
1898 else {
1899 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
1900 BRepLib_MakeVertex v2(LastPnt);
1901 BRepLib_MakeEdge e2(v1, v2);
1902 eee = TopoDS::Edge(e2.Shape());
1903 }
1904 BB.Add(w, eee);
1905 theLastEdge = eee;
1906 if(theFV.IsNull()) {
1907 theFV = TopExp::FirstVertex(eee,Standard_True);
1908 theFirstpoint = BRep_Tool::Pnt(theFV);
1909 }
1910 break;
1911 }
7fd59977 1912 }
1913
1914 if(explo.More()) {
4e57c75e 1915 explo.Next();
1916 if(explo.Current().IsNull()) explo.Init(BndWire);
7fd59977 1917 }
1918 else explo.Init(BndWire);
1919 Standard_Boolean Fin = Standard_False;
1920 while(!Fin) {
4e57c75e 1921 const TopoDS_Edge& e = TopoDS::Edge(explo.Current());
1922 if(!e.IsSame(BndEdge2)) {
1923 gp_Pnt pp;
1924 pp = BRep_Tool::Pnt(TopExp::LastVertex(e,Standard_True));
1925 TopoDS_Edge eee1;
1926 if(theLastEdge.IsNull()) {
1927 BRepLib_MakeEdge ee(LastPnt, pp);
1928 eee1 = TopoDS::Edge(ee.Shape());
1929 }
1930 else {
1931 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
1932 BRepLib_MakeVertex v2(pp);
1933 BRepLib_MakeEdge ee(v1, v2);
1934 eee1 = TopoDS::Edge(ee.Shape());
1935 }
1936 BB.Add(w, eee1);
1937 theLastEdge = eee1;
1938 if(theFV.IsNull()) {
1939 theFV = TopExp::FirstVertex(eee1,Standard_True);
1940 theFirstpoint = BRep_Tool::Pnt(theFV);
1941 }
1942 LastPnt = pp;
1943 }
1944 else {
1945 Fin = Standard_True;
1946 TopoDS_Edge eee2;
1947 if(theLastEdge.IsNull()) {
1948 BRepLib_MakeEdge ee(LastPnt, BndPnt2);
1949 eee2 = TopoDS::Edge(ee.Shape());
1950 }
1951 else {
1952 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
1953 BRepLib_MakeVertex v2(BndPnt2);
1954 BRepLib_MakeEdge ee(v1, v2);
1955 eee2 = TopoDS::Edge(ee.Shape());
1956 }
1957 BB.Add(w, eee2);
1958 theLastEdge = eee2;
1959 if(theFV.IsNull()) {
1960 theFV = TopExp::FirstVertex(eee2,Standard_True);
1961 theFirstpoint = BRep_Tool::Pnt(theFV);
1962 }
1963 LastPnt = BndPnt2;
1964 }
1965 if(explo.More()) {
1966 explo.Next();
1967 if(explo.Current().IsNull()) {
1968 explo.Init(BndWire);
1969 }
1970 }
1971 else explo.Init(BndWire);
7fd59977 1972 }
1973
1974 TopoDS_Edge eee3;
1975 if(theLastEdge.IsNull()) {
4e57c75e 1976 BRepLib_MakeEdge e3(BndPnt2, firstpoint);
1977 eee3 = TopoDS::Edge(e3.Shape());
7fd59977 1978 }
1979 else {
4e57c75e 1980 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
1981 BRepLib_MakeVertex v2(firstpoint);
1982 BRepLib_MakeEdge e3(v1, v2);
1983 eee3 = TopoDS::Edge(e3.Shape());
7fd59977 1984 }
1985 BB.Add(w, eee3);
1986 theLastEdge = eee3;
1987 if(theFV.IsNull()) {
4e57c75e 1988 theFV = TopExp::FirstVertex(eee3,Standard_True);
1989 theFirstpoint = BRep_Tool::Pnt(theFV);
7fd59977 1990 }
1991 }
1992 }
1993
1994 if(Concavite == 1) {
1995 TopoDS_Edge eee4;
1996 if(theLastEdge.IsNull()) {
1997 BRepLib_MakeEdge e(Pt, firstpoint);
1998 eee4 = TopoDS::Edge(e.Shape());
1999 }
2000 else {
2001 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
2002 BRepLib_MakeVertex v2(firstpoint);
2003 BRepLib_MakeEdge e(v1, v2);
2004 eee4 = TopoDS::Edge(e.Shape());
2005 }
2006 BB.Add(w, eee4);
2007 if(theFV.IsNull()) {
2008 theFV = TopExp::FirstVertex(eee4,Standard_True);
2009 theFirstpoint = BRep_Tool::Pnt(theFV);
2010 }
2011 theLastEdge = eee4;
2012 }
2013
2014
2015 if(FirstEdge.IsSame(LastEdge)) {
2016 if(!myLFMap.IsBound(FirstEdge)) {
2017 TopTools_ListOfShape thelist;
2018 myLFMap.Bind(FirstEdge, thelist);
2019 }
2020 if(OnFirstFace || OnLastFace) {
2021 TopoDS_Edge theEdge;
2022 Standard_Real f, l;
2023 Handle(Geom_Curve) cc = BRep_Tool::Curve(FalseOnlyOne, f, l);
2024 if(!theLastEdge.IsNull()) {
4e57c75e 2025 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
2026 TopoDS_Vertex v2;
2027 const gp_Pnt& pp = BRep_Tool::
2028 Pnt(TopExp::LastVertex(FalseOnlyOne,Standard_True));
2029 if(!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol) {
2030 v2 = theFV;
2031 }
2032 else v2 = TopExp::LastVertex(FalseOnlyOne,Standard_True);
2033 BRepLib_MakeEdge e(cc, v1, v2);
2034 theEdge = TopoDS::Edge(e.Shape());
7fd59977 2035 }
2036 else {
4e57c75e 2037 const TopoDS_Vertex& v1 = TopExp::FirstVertex(FalseOnlyOne,Standard_True);
2038 TopoDS_Vertex v2;
2039 const gp_Pnt& pp = BRep_Tool::
2040 Pnt(TopExp::LastVertex(FalseOnlyOne,Standard_True));
2041 if(!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol) {
2042 v2 = theFV;
2043 }
2044 else v2 = TopExp::LastVertex(FalseOnlyOne,Standard_True);
2045 BRepLib_MakeEdge e(cc, v1, v2);
2046 theEdge = TopoDS::Edge(e.Shape());
7fd59977 2047 }
2048 myLFMap(FirstEdge).Append(theEdge);
2049 BB.Add(w, theEdge);
2050 if(theFV.IsNull()) theFV = TopExp::FirstVertex(theEdge,Standard_True);
2051 theLastEdge = theEdge;
2052 }
2053 else {
2054 Standard_Real f, l;
2055 Handle(Geom_Curve) cc = BRep_Tool::Curve(FirstEdge, f, l);
2056 TopoDS_Edge theEdge;
2057 if(!theLastEdge.IsNull()) {
4e57c75e 2058 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
2059 TopoDS_Vertex v2;
0d969553 2060// Attention case Wire Reversed -> LastVertex without Standard_True
4e57c75e 2061 const gp_Pnt& pp = BRep_Tool::Pnt(TopExp::LastVertex(FirstEdge));
2062 if(!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol) {
2063 v2 = theFV;
2064 }
2065 else v2 = TopExp::LastVertex(FirstEdge);
2066 BRepLib_MakeEdge e(cc, v1, v2);
2067 theEdge = TopoDS::Edge(e.Shape());
7fd59977 2068 }
2069 else {
4e57c75e 2070 const TopoDS_Vertex& v1 = TopExp::FirstVertex(FirstEdge,Standard_True);
2071 TopoDS_Vertex v2;
2072 const gp_Pnt& pp = BRep_Tool::
2073 Pnt(TopExp::LastVertex(FirstEdge,Standard_True));
2074 if(!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol) {
2075 v2 = theFV;
2076 }
2077 else v2 = TopExp::LastVertex(FirstEdge,Standard_True);
2078 BRepLib_MakeEdge e(cc, v1, v2);
2079 theEdge = TopoDS::Edge(e.Shape());
7fd59977 2080 }
2081 myLFMap(FirstEdge).Append(theEdge);
2082 BB.Add(w, theEdge);
2083 if(theFV.IsNull()) theFV = TopExp::FirstVertex(theEdge,Standard_True);
2084 theLastEdge = theEdge;
2085 }
2086 }
2087 else {
2088 if(!myLFMap.IsBound(FirstEdge)) {
2089 TopTools_ListOfShape thelist1;
2090 myLFMap.Bind(FirstEdge, thelist1);
2091 }
2092 if(!OnFirstFace) {
2093 TopoDS_Edge theEdge;
2094 Standard_Real f, l;
2095 Handle(Geom_Curve) cc = BRep_Tool::Curve(FirstEdge, f, l);
2096 if(!theLastEdge.IsNull()) {
4e57c75e 2097 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
2098 const TopoDS_Vertex& v2 = TopExp::LastVertex(FirstEdge,Standard_True);
2099 BRepLib_MakeEdge e(cc, v1, v2);
2100 theEdge = TopoDS::Edge(e.Shape());
7fd59977 2101 }
2102 else {
4e57c75e 2103 theEdge = FirstEdge;
7fd59977 2104 }
2105 myLFMap(FirstEdge).Append(theEdge);
2106 BB.Add(w, theEdge);
2107 if(theFV.IsNull()) theFV = TopExp::FirstVertex(theEdge,Standard_True);
2108 theLastEdge = theEdge;
2109 }
2110 else {
2111 TopoDS_Edge theEdge;
2112 Standard_Real f, l;
2113 Handle(Geom_Curve) cc = BRep_Tool::Curve(FalseFirstEdge, f, l);
2114 if(!theLastEdge.IsNull()) {
4e57c75e 2115 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
2116 const TopoDS_Vertex& v2 = TopExp::LastVertex(FalseFirstEdge,Standard_True);
2117 BRepLib_MakeEdge e(cc, v1, v2);
2118 theEdge = TopoDS::Edge(e.Shape());
7fd59977 2119 }
2120 else {
4e57c75e 2121 theEdge = FalseFirstEdge;
7fd59977 2122 }
2123 myLFMap(FirstEdge).Append(theEdge);
2124 BB.Add(w, theEdge);
2125 if(theFV.IsNull()) theFV = TopExp::FirstVertex(theEdge,Standard_True);
2126 theLastEdge = theEdge;
2127 }
2128
2129 BRepTools_WireExplorer ex(myWire);
2130 for(; ex.More(); ex.Next()) {
2131 const TopoDS_Edge& E = ex.Current();
2132 if(E.IsSame(FirstEdge)) break;
2133 }
2134
2135 ex.Next();
2136
2137 for(; ex.More(); ex.Next()) {
2138 const TopoDS_Edge& E = ex.Current();
2139 if(!E.IsSame(LastEdge)) {
4e57c75e 2140 if(!myLFMap.IsBound(E)) {
7fd59977 2141 TopTools_ListOfShape thelist2;
4e57c75e 2142 myLFMap.Bind(E, thelist2);
2143 }
2144 TopoDS_Edge eee;
2145 Standard_Real f, l;
2146 Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
2147 if(!theLastEdge.IsNull()) {
2148 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
2149 const TopoDS_Vertex& v2 = TopExp::LastVertex(E,Standard_True);
2150 BRepLib_MakeEdge e(cc, v1, v2);
2151 eee = TopoDS::Edge(e.Shape());
2152 }
2153 else {
2154 eee = E;
2155 }
2156 myLFMap(E).Append(eee);
2157 BB.Add(w, eee);
2158 if(theFV.IsNull()) theFV = TopExp::FirstVertex(eee,Standard_True);
2159 theLastEdge = eee;
7fd59977 2160 }
2161 else break;
2162 }
2163
2164
2165 if(!OnLastFace) {
2166 if(!FirstEdge.IsSame(LastEdge)) {
4e57c75e 2167 const TopoDS_Edge& edg = TopoDS::Edge(ex.Current());
2168 if(!myLFMap.IsBound(edg)) {
7fd59977 2169 TopTools_ListOfShape thelist3;
4e57c75e 2170 myLFMap.Bind(edg, thelist3);
2171 }
2172 TopoDS_Edge eee;
2173 Standard_Real f, l;
2174 Handle(Geom_Curve) cc = BRep_Tool::Curve(edg, f, l);
2175 if(!theLastEdge.IsNull()) {
2176 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
2177 TopoDS_Vertex v2;
2178 const gp_Pnt& pp = BRep_Tool::
2179 Pnt(TopExp::LastVertex(edg,Standard_True));
2180 if(!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol) {
2181 v2 = theFV;
2182 }
2183 else v2 = TopExp::LastVertex(edg,Standard_True);
2184 BRepLib_MakeEdge e(cc, v1, v2);
2185 eee = TopoDS::Edge(e.Shape());
2186 }
2187 else {
2188 const TopoDS_Vertex& v1 = TopExp::FirstVertex(edg,Standard_True);
2189 TopoDS_Vertex v2;
2190 const gp_Pnt& pp = BRep_Tool::
2191 Pnt(TopExp::LastVertex(edg,Standard_True));
2192 if(!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol) {
2193 v2 = theFV;
2194 }
2195 else v2 = TopExp::LastVertex(edg,Standard_True);
2196 BRepLib_MakeEdge e(cc, v1, v2);
2197 eee = TopoDS::Edge(e.Shape());
2198 }
2199 myLFMap(edg).Append(eee);
2200 BB.Add(w, eee);
2201 if(theFV.IsNull()) theFV = TopExp::FirstVertex(eee,Standard_True);
2202 theLastEdge = eee;
7fd59977 2203 }
2204 else {
4e57c75e 2205 TopoDS_Edge eee;
2206 Standard_Real f, l;
2207 if(!myLFMap.IsBound(LastEdge)) {
7fd59977 2208 TopTools_ListOfShape thelist4;
4e57c75e 2209 myLFMap.Bind(LastEdge, thelist4);
2210 }
2211 Handle(Geom_Curve) cc = BRep_Tool::Curve(FalseOnlyOne, f, l);
2212 if(!theLastEdge.IsNull()) {
2213 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
2214 TopoDS_Vertex v2;
2215 const gp_Pnt& pp = BRep_Tool::
2216 Pnt(TopExp::LastVertex(FalseOnlyOne,Standard_True));
2217 if(!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol) {
2218 v2 = theFV;
2219 }
2220 else v2 = TopExp::LastVertex(FalseOnlyOne,Standard_True);
2221 BRepLib_MakeEdge e(cc, v1, v2);
2222 eee = TopoDS::Edge(e.Shape());
2223 }
2224 else {
2225 const TopoDS_Vertex& v1 = TopExp::FirstVertex(FalseOnlyOne,Standard_True);
2226 TopoDS_Vertex v2;
2227 const gp_Pnt& pp = BRep_Tool::
2228 Pnt(TopExp::LastVertex(FalseOnlyOne,Standard_True));
2229 if(!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol) {
2230 v2 = theFV;
2231 }
2232 else v2 = TopExp::LastVertex(FalseOnlyOne,Standard_True);
2233 BRepLib_MakeEdge e(cc, v1, v2);
2234 eee = TopoDS::Edge(e.Shape());
2235 }
2236 myLFMap(LastEdge).Append(eee);
2237 BB.Add(w, eee);
2238 if(theFV.IsNull()) theFV = TopExp::FirstVertex(eee,Standard_True);
2239 theLastEdge = eee;
7fd59977 2240 }
2241 }
2242 else {
2243 TopoDS_Edge eee;
2244 Standard_Real f, l;
2245 if(!myLFMap.IsBound(LastEdge)) {
2246 TopTools_ListOfShape thelist5;
4e57c75e 2247 myLFMap.Bind(LastEdge, thelist5);
7fd59977 2248 }
2249 Handle(Geom_Curve) cc = BRep_Tool::Curve(FalseLastEdge, f, l);
2250 if(!theLastEdge.IsNull()) {
4e57c75e 2251 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
2252 TopoDS_Vertex v2;
2253 const gp_Pnt& pp = BRep_Tool::
2254 Pnt(TopExp::LastVertex(FalseLastEdge,Standard_True));
2255 if(!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol) {
2256 v2 = theFV;
2257 }
2258 else v2 = TopExp::LastVertex(FalseLastEdge,Standard_True);
2259 BRepLib_MakeEdge e(cc, v1, v2);
2260 eee = TopoDS::Edge(e.Shape());
2261 }
7fd59977 2262 else {
4e57c75e 2263 const TopoDS_Vertex& v1 = TopExp::FirstVertex(FalseLastEdge,Standard_True);
2264 TopoDS_Vertex v2;
2265 const gp_Pnt& pp = BRep_Tool::
2266 Pnt(TopExp::LastVertex(FalseLastEdge,Standard_True));
2267 if(!theFV.IsNull() && theFirstpoint.Distance(pp) <= myTol) {
2268 v2 = theFV;
2269 }
2270 else v2 = TopExp::LastVertex(FalseLastEdge,Standard_True);
2271 BRepLib_MakeEdge e(cc, v1, v2);
2272 eee = TopoDS::Edge(e.Shape());
7fd59977 2273 }
2274 myLFMap(LastEdge).Append(eee);
2275 BB.Add(w, eee);
2276 if(theFV.IsNull()) theFV = TopExp::FirstVertex(eee,Standard_True);
2277 theLastEdge = eee;
2278 }
2279 }
2280
2281 if(Concavite == 1) {
2282 TopoDS_Edge eef;
4e57c75e 2283 if(theLastEdge.IsNull()) {
7fd59977 2284 BRepLib_MakeEdge ef(lastpoint, Pt);
2285 eef = TopoDS::Edge(ef.Shape());
2286 }
2287 else {
2288 const TopoDS_Vertex& v1 = TopExp::LastVertex(theLastEdge,Standard_True);
2289 BRepLib_MakeVertex vv(Pt);
2290 TopoDS_Vertex v2 = TopoDS::Vertex(vv.Shape());
2291 if(!theFV.IsNull() &&
4e57c75e 2292 Pt.Distance(theFirstpoint) <= myTol) v2 = theFV;
7fd59977 2293
2294 BRepLib_MakeEdge ef(v1, v2);
4e57c75e 2295 eef = TopoDS::Edge(ef.Shape());
7fd59977 2296 }
2297 BB.Add(w, eef);
2298 if(theFV.IsNull()) theFV = TopExp::FirstVertex(eef,Standard_True);
2299 theLastEdge = eef;
2300 }
2301
2302 if(Concavite == 2) {
2303 BRepLib_MakeEdge ee(lastpoint, firstpoint);
2304 const TopoDS_Edge& e = ee.Edge();
2305 BB.Add(w, e);
2306 }
2307
2308 BRepLib_MakeFace fa(myPln->Pln(), w, Standard_True);
2309 TopoDS_Face fac = TopoDS::Face(fa.Shape());
2310
2311 if (!BRepAlgo::IsValid(fac)) {
2312#ifdef DEB
2313 if (trc) cout << " Invalid Face" << endl;
2314#endif
2315 ProfileOK = Standard_False;
2316 return ProfileOK;
2317 }
2318
2319// if(!Concavite) {
2320 if(Concavite == 3) {
2321 BRepTopAdaptor_FClass2d Cl(fac, BRep_Tool::Tolerance(fac));
2322 Standard_Real u, v;
2323 ElSLib::Parameters(myPln->Pln(), CheckPnt, u, v);
2324 gp_Pnt2d checkpnt2d(u, v);
2325 if(Cl.Perform(checkpnt2d, Standard_True) == TopAbs_OUT) {
2326 //modified by NIZNHY-PKV Fri Mar 22 16:47:06 2002 f
2327 //BRepAlgo_Cut c(BndFace, fac);
2328 BRepAlgoAPI_Cut c(BndFace, fac);
2329 //modified by NIZNHY-PKV Fri Mar 22 16:47:09 2002 t
2330 TopExp_Explorer exp(c.Shape(), TopAbs_WIRE);
2331 //modified by NIZNHY-PKV Fri Mar 22 16:47:23 2002 f
2332 //UpdateDescendants(c.Builder(), c.Shape(), Standard_False);
2333 UpdateDescendants(c, c.Shape(), Standard_False);
2334 //modified by NIZNHY-PKV Fri Mar 22 16:47:28 2002 t
2335 const TopoDS_Wire& ww = TopoDS::Wire(exp.Current());//modified by NIZNHY-PKV Fri Mar 22 17:10:16 2002 ww/w
2336 BRepLib_MakeFace ff(ww);
2337 Prof = TopoDS::Face(ff.Shape());
2338 }
2339 else {
2340 Prof = fac;
2341 }
2342 }
2343 else {
2344 Prof = fac;
2345 }
2346
2347 if (!BRepAlgo::IsValid(Prof)) {
2348#ifdef DEB
2349 if (trc) cout << " Invalid Face Profile" << endl;
2350#endif
2351 ProfileOK = Standard_False;
2352 return ProfileOK;
2353 }
2354 return ProfileOK;
2355}
2356
2357//modified by NIZNHY-PKV Thu Mar 21 18:43:18 2002 f
2358//=======================================================================
2359//function : UpdateDescendants
2360//purpose :
2361//=======================================================================
2362 void BRepFeat_RibSlot::UpdateDescendants(const BRepAlgoAPI_BooleanOperation& aBOP,
4e57c75e 2363 const TopoDS_Shape& S,
2364 const Standard_Boolean SkipFace)
7fd59977 2365{
2366 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itdm;
2367 TopTools_ListIteratorOfListOfShape it,it2;
2368 TopTools_MapIteratorOfMapOfShape itm;
2369 TopExp_Explorer exp;
2370
2371 for (itdm.Initialize(myMap);itdm.More();itdm.Next()) {
2372 const TopoDS_Shape& orig = itdm.Key();
2373 if (SkipFace && orig.ShapeType() == TopAbs_FACE) {
2374 continue;
2375 }
2376 TopTools_MapOfShape newdsc;
2377
2378 //if (itdm.Value().IsEmpty()) {myMap.ChangeFind(orig).Append(orig);}
2379
2380 for (it.Initialize(itdm.Value());it.More();it.Next()) {
2381 const TopoDS_Shape& sh = it.Value();
2382 if(sh.ShapeType() != TopAbs_FACE) continue;
2383 const TopoDS_Face& fdsc = TopoDS::Face(it.Value());
2384 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
4e57c75e 2385 if (exp.Current().IsSame(fdsc)) { // preserved
2386 newdsc.Add(fdsc);
2387 break;
2388 }
7fd59977 2389 }
2390 if (!exp.More()) {
4e57c75e 2391 BRepAlgoAPI_BooleanOperation* pBOP=(BRepAlgoAPI_BooleanOperation*)&aBOP;
2392 const TopTools_ListOfShape& aLM=pBOP->Modified(fdsc);
2393 it2.Initialize(aLM);
2394 for (; it2.More(); it2.Next()) {
2395 const TopoDS_Shape& aS=it2.Value();
2396 newdsc.Add(aS);
2397 }
2398
7fd59977 2399 }
2400 }
2401 myMap.ChangeFind(orig).Clear();
2402 for (itm.Initialize(newdsc); itm.More(); itm.Next()) {
0d969553 2403 // check the belonging to the shape...
7fd59977 2404 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
4e57c75e 2405 if (exp.Current().IsSame(itm.Key())) {
2406// const TopoDS_Shape& sh = itm.Key();
2407 myMap.ChangeFind(orig).Append(itm.Key());
2408 break;
2409 }
7fd59977 2410 }
2411 }
2412 }
2413}
2414//modified by NIZNHY-PKV Thu Mar 21 18:43:36 2002 t