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