0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / BRepFeat / BRepFeat_MakeLinearForm.cxx
CommitLineData
7fd59977 1// File: BRepFeat_MakeLinearForm.cxx
2// Created: Mon Apr 14 13:34:46 1997
3// Author: Olga KOULECHOVA
4// <opt@langdox.paris1.matra-dtv.fr>
5
6
7#include <BRepFeat_MakeLinearForm.ixx>
8
9#include <BRepFeat.hxx>
10
11#include <LocOpe.hxx>
12#include <LocOpe_Builder.hxx>
13#include <LocOpe_LinearForm.hxx>
14#include <LocOpe_Gluer.hxx>
15#include <LocOpe_FindEdges.hxx>
16
17#include <gp_Vec.hxx>
18#include <gp_Pln.hxx>
19#include <gp_Lin.hxx>
20#include <gp_Dir.hxx>
21#include <gp_Pnt.hxx>
22
23#include <gp_Vec2d.hxx>
24#include <gp_Pnt2d.hxx>
25
26#include <Geom_Curve.hxx>
27
28#include <Geom2d_Curve.hxx>
29#include <Geom2d_Line.hxx>
30
31#include <Geom_Plane.hxx>
32#include <Geom_Surface.hxx>
33#include <Geom_CylindricalSurface.hxx>
34#include <Geom_RectangularTrimmedSurface.hxx>
35
36#include <Geom_TrimmedCurve.hxx>
37#include <GeomProjLib.hxx>
38
39#include <Geom2d_Curve.hxx>
40#include <Geom2d_Curve.hxx>
41
42#include <TColgp_SequenceOfPnt.hxx>
43
44#include <TColStd_Array1OfReal.hxx>
45#include <IntRes2d_IntersectionPoint.hxx>
46
47#include <BRepTools_WireExplorer.hxx>
48
49#include <BRep_Tool.hxx>
50#include <BRep_Builder.hxx>
51
52#include <TopExp_Explorer.hxx>
53#include <TopExp.hxx>
54
55#include <TopTools_MapOfShape.hxx>
56#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
57#include <TopTools_ListOfShape.hxx>
58#include <TopTools_ListIteratorOfListOfShape.hxx>
59#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
60#include <TopTools_MapIteratorOfMapOfShape.hxx>
61#include <TopOpeBRepBuild_HBuilder.hxx>
62#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
63
64#include <TColgp_Array1OfPnt.hxx>
65
66#include <TColGeom_Array1OfCurve.hxx>
67
68#include <TopoDS.hxx>
69#include <TopoDS_Shape.hxx>
70#include <TopoDS_Face.hxx>
71
72#include <BRepLib_MakeVertex.hxx>
73#include <BRepLib_MakeEdge.hxx>
74#include <BRepLib_MakeFace.hxx>
75
76#include <BRepTools.hxx>
77
78#include <BRepBuilderAPI.hxx>
79#include <BRepPrimAPI_MakeBox.hxx>
80#include <BRepBuilderAPI_MakeFace.hxx>
81
82//modified by NIZNHY-PKV Fri Mar 22 16:51:33 2002 f
83//#include <BRepAlgo_Section.hxx>
84//#include <BRepAlgo_Common.hxx>
85#include <BRepAlgoAPI_Section.hxx>
86#include <BRepAlgoAPI_Common.hxx>
87//modified by NIZNHY-PKV Fri Mar 22 16:51:35 2002 t
88
89#include <BRepExtrema_ExtPC.hxx>
90#include <BRepExtrema_ExtPF.hxx>
91#include <BRepExtrema_ExtCF.hxx>
92
93#include <BRepTools_Modifier.hxx>
94#include <BRepTools_TrsfModification.hxx>
95
96#include <Standard_ConstructionError.hxx>
97
98#include <Precision.hxx>
99
100#include <GeomLProp_CLProps.hxx>
101
102#include <BRepBuilderAPI_Transform.hxx>
103#include <BRepLib_MakeWire.hxx>
104//#include <DbgTools.hxx>
105
106#ifdef DEB
107Standard_IMPORT Standard_Boolean BRepFeat_GettraceFEAT();
108Standard_IMPORT Standard_Boolean BRepFeat_GettraceFEATRIB();
109#endif
110
111static void MajMap(const TopoDS_Shape&, // base
112 const LocOpe_LinearForm&,
113 TopTools_DataMapOfShapeListOfShape&, // myMap
114 TopoDS_Shape&, // myFShape
115 TopoDS_Shape&); // myLShape
116
117static void SetGluedFaces(const TopTools_DataMapOfShapeListOfShape& theSlmap,
118 LocOpe_LinearForm&,
119 TopTools_DataMapOfShapeShape&);
120
121//=======================================================================
122//function : Init
123//purpose :
124//=======================================================================
125
126void BRepFeat_MakeLinearForm::Init(const TopoDS_Shape& Sbase,
127 const TopoDS_Wire& W,
128 const Handle(Geom_Plane)& Plane,
129 const gp_Vec& Direc,
130 const gp_Vec& Direc1,
131 const Standard_Integer Mode,
132 const Standard_Boolean Modify)
133{
134#ifdef DEB
135 Standard_Boolean trc = BRepFeat_GettraceFEAT();
136 if (trc) cout << "BRepFeat_MakeLinearForm::Init" << endl;
137#endif
138 Standard_Boolean RevolRib = Standard_False;
139 Done();
140 myGenerated.Clear();
141
0d969553
Y
142// modify = 0 if there is no intention to make sliding
143// = 1 if one tries to make sliding
7fd59977 144 Standard_Boolean Sliding = Modify;
145 myLFMap.Clear();
146
147 myShape.Nullify();
148 myMap.Clear();
149 myFShape.Nullify();
150 myLShape.Nullify();
151 mySbase = Sbase;
152 mySkface.Nullify();
153 myPbase.Nullify();
154
155 myGShape.Nullify();
156 mySUntil.Nullify();
157 myListOfEdges.Clear();
158 mySlface.Clear();
159
160 TopoDS_Shape aLocalShape = W.Oriented(TopAbs_FORWARD);
161 myWire = TopoDS::Wire(aLocalShape);
162// myWire = TopoDS::Wire(W.Oriented(TopAbs_FORWARD));
163 myDir = Direc;
164 myDir1 = Direc1;
165 myPln = Plane;
166
167 if(Mode == 0)
168 myFuse = Standard_False;
169 else // if(Mode == 1)
170 myFuse = Standard_True;
171#ifdef DEB
172 if (trc) {
173 if (myFuse) cout << " Fuse" << endl;
174 if (!myFuse) cout << " Cut" << endl;
175 }
176#endif
177
178
0d969553 179// ---Determine Tolerance : max tolerance on parameters
7fd59977 180 myTol = Precision::Confusion();
181
182 TopExp_Explorer exx;
183 exx.Init(myWire, TopAbs_VERTEX);
184 for(; exx.More(); exx.Next()) {
185 const Standard_Real& tol = BRep_Tool::
186 Tolerance(TopoDS::Vertex(exx.Current()));
187 if(tol > myTol) myTol = tol;
188 }
189
190 exx.Init(Sbase, TopAbs_VERTEX);
191 for(; exx.More(); exx.Next()) {
192 const Standard_Real& tol = BRep_Tool::
193 Tolerance(TopoDS::Vertex(exx.Current()));
194 if(tol > myTol) myTol = tol;
195 }
196
0d969553
Y
197// ---Control of directions
198// the wire should be in the rib
7fd59977 199 gp_Vec nulldir(0, 0, 0);
200 if(!myDir1.IsEqual(nulldir, myTol, myTol)) {
201 Standard_Real ang = myDir1.Angle(myDir);
c6541a0c 202 if(ang != M_PI) {
7fd59977 203#ifdef DEB
204 if (trc) cout << " Directions must be opposite" << endl;
205#endif
206 myStatusError = BRepFeat_BadDirect;
207 NotDone();
208 return;
209 }
210 }
211 else {
212
213// Rib is centre in the middle of translation
214#ifdef DEB
215 if (trc) cout << " Rib is centre" << endl;
216#endif
217 const gp_Vec& DirTranslation = (Direc + Direc1) * 0.5;
218 gp_Trsf T;
219 T.SetTranslation(DirTranslation);
220 BRepBuilderAPI_Transform trf(T);
221 trf.Perform(myWire);
222 myWire = TopoDS::Wire(trf.Shape());
223 myDir = Direc - DirTranslation;
224 myDir1 = Direc1 - DirTranslation;
225 myPln->Transform(T);
226 }
227
0d969553 228// ---Calculate bounding box
7fd59977 229 BRep_Builder BB;
230
231 TopTools_ListOfShape theList;
232
233 TopoDS_Shape U;
234 U.Nullify();
235 gp_Pnt FirstCorner, LastCorner;
236 Standard_Real bnd = HeightMax(mySbase, U, FirstCorner, LastCorner);
237 myBnd = bnd;
238
239 BRepPrimAPI_MakeBox Bndbox(FirstCorner, LastCorner);
240 TopoDS_Solid BndBox = Bndbox.Solid();
241
242
0d969553 243// ---Construction of the face workplane (section bounding box)
7fd59977 244 BRepLib_MakeFace PlaneF(myPln->Pln(), -6.*myBnd,
245 6.*myBnd, -6.*myBnd, 6.*myBnd);
246 TopoDS_Face PlaneFace = TopoDS::Face(PlaneF.Shape());
247
248 //modified by NIZNHY-PKV Fri Mar 22 16:49:28 2002 f
249 //BRepAlgo_Common PlaneS(BndBox, PlaneFace);
250 BRepAlgoAPI_Common PlaneS(BndBox, PlaneFace);
251 //modified by NIZNHY-PKV Fri Mar 22 16:49:39 2002 t
252 TopExp_Explorer EXP;
253 TopoDS_Shape PlaneSect = PlaneS.Shape();
254 EXP.Init(PlaneSect, TopAbs_WIRE);
255 TopoDS_Wire www = TopoDS::Wire(EXP.Current());
256 BRepLib_MakeFace Bndface(myPln->Pln(), www, Standard_True);
257 TopoDS_Face BndFace = TopoDS::Face(Bndface.Shape());
258
259
0d969553 260// ---Find support faces of the rib
7fd59977 261 TopoDS_Edge FirstEdge, LastEdge;
262 TopoDS_Face FirstFace, LastFace;
263 TopoDS_Vertex FirstVertex, LastVertex;
264
265 Standard_Boolean OnFirstFace = Standard_False;
266 Standard_Boolean OnLastFace = Standard_False;
267 Standard_Boolean PtOnFirstEdge = Standard_False;
268 Standard_Boolean PtOnLastEdge = Standard_False;
269 TopoDS_Edge OnFirstEdge, OnLastEdge;
270 OnFirstEdge.Nullify();
271 OnLastEdge.Nullify();
272
273 Standard_Boolean Data = ExtremeFaces(RevolRib, myBnd, myPln, FirstEdge, LastEdge,
274 FirstFace, LastFace, FirstVertex,
275 LastVertex, OnFirstFace, OnLastFace,
276 PtOnFirstEdge, PtOnLastEdge,
277 OnFirstEdge, OnLastEdge);
278
279 if(!Data) {
280#ifdef DEB
281 if (trc) cout << " No Extreme faces" << endl;
282#endif
283 myStatusError = BRepFeat_NoExtFace;
284 NotDone();
285 return;
286 }
287
288
0d969553 289// ---Proofing Point for the side of the wire to be filled - side material
7fd59977 290 gp_Pnt CheckPnt = CheckPoint(FirstEdge, bnd/10., myPln);
291
292// Standard_Real f, l;
293
0d969553
Y
294// ---Control sliding valuable
295// Many cases when the sliding is abandoned
296 Standard_Integer Concavite = 3; // a priori the profile is not concave
7fd59977 297
298 myFirstPnt = BRep_Tool::Pnt(FirstVertex);
299 myLastPnt = BRep_Tool::Pnt(LastVertex);
300
0d969553 301// SliList : list of faces concerned by the rib
7fd59977 302 TopTools_ListOfShape SliList;
303 SliList.Append(FirstFace);
304
0d969553 305 if(Sliding) { // sliding
7fd59977 306#ifdef DEB
307 if (trc) cout << " Sliding" << endl;
308#endif
309 Standard_Boolean Sliding = Standard_False;
310 Handle(Geom_Surface) s = BRep_Tool::Surface(FirstFace);
311 if (s->DynamicType() ==
312 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
313 s = Handle(Geom_RectangularTrimmedSurface)::
314 DownCast(s)->BasisSurface();
315 }
316 if(s->DynamicType() == STANDARD_TYPE(Geom_Plane) ||
317 s->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
0d969553 318// if plane or cylinder : sliding is possible
7fd59977 319 Sliding = Standard_True;
320 }
321 }
322
0d969553
Y
323// Control only start and end points
324// -> no control at the middle - improve
325// Controle between Surface and segment between 2 limit points
326// is too expensive - improve
7fd59977 327 if(Sliding) {
328 gp_Pnt p1(myFirstPnt.X()+myDir.X(),myFirstPnt.Y()+myDir.Y(),
329 myFirstPnt.Z()+myDir.Z());
330 BRepLib_MakeEdge ee1(myFirstPnt, p1);
331 BRepExtrema_ExtCF ext1(ee1, FirstFace);
332 if(ext1.NbExt() == 1 && ext1.SquareDistance(1)<=BRep_Tool::Tolerance(FirstFace) * BRep_Tool::Tolerance(FirstFace)) {
333 gp_Pnt p2(myLastPnt.X()+myDir.X(),myLastPnt.Y()+myDir.Y(),
334 myLastPnt.Z()+myDir.Z());
335 BRepLib_MakeEdge ee2(myLastPnt, p2);
0d969553 336 BRepExtrema_ExtCF ext2(ee2, LastFace); // ExtCF : curves and surfaces
7fd59977 337 if(ext2.NbExt() == 1 && ext2.SquareDistance(1)<=BRep_Tool::Tolerance(LastFace) * BRep_Tool::Tolerance(LastFace)) {
338 Sliding = Standard_True;
339 }
340 else {
341 Sliding = Standard_False;
342 }
343 }
344 else {
345 Sliding = Standard_False;
346 }
347 }
348
349 if(!myDir1.IsEqual(nulldir, Precision::Confusion(), Precision::Confusion())) {
350 if(Sliding) {
351 gp_Pnt p1(myFirstPnt.X()+myDir1.X(),myFirstPnt.Y()+myDir1.Y(),
352 myFirstPnt.Z()+myDir1.Z());
353 BRepLib_MakeEdge ee1(myFirstPnt, p1);
354 BRepExtrema_ExtCF ext1(ee1, FirstFace);
355 if(ext1.NbExt() == 1 && ext1.SquareDistance(1)<=BRep_Tool::Tolerance(FirstFace) * BRep_Tool::Tolerance(FirstFace)) {
356 gp_Pnt p2(myLastPnt.X()+myDir1.X(),myLastPnt.Y()+myDir1.Y(),
357 myLastPnt.Z()+myDir1.Z());
358 BRepLib_MakeEdge ee2(myLastPnt, p2);
359 BRepExtrema_ExtCF ext2(ee2, LastFace);
360 if(ext2.NbExt() == 1 && ext2.SquareDistance(1)<=BRep_Tool::Tolerance(LastFace) * BRep_Tool::Tolerance(LastFace)) {
361 Sliding = Standard_True;
362 }
363 else {
364 Sliding = Standard_False;
365 }
366 }
367 else {
368 Sliding = Standard_False;
369 }
370 }
371 }
372
373
0d969553
Y
374// Construct a great profile that goes till the bounding box
375// -> by tangency with the first and the last edge of the Wire
376// -> by normals to the support faces : statistically better
377// Intersect everything to find the final profile
7fd59977 378
379
0d969553 380// ---case of sliding : construction of the profile face
7fd59977 381 if(Sliding) {
382#ifdef DEB
383 if (trc) cout << " still Sliding" << endl;
384#endif
385 TopoDS_Face Prof;
386 Standard_Boolean ProfileOK;
387 ProfileOK = SlidingProfile(Prof,RevolRib,myTol,Concavite,myPln,BndFace,CheckPnt,
388 FirstFace,LastFace,FirstVertex,LastVertex,
389 FirstEdge,LastEdge);
390
391 if (!ProfileOK) {
392#ifdef DEB
393 cout << "Not computable" << endl;
394 if (trc) cout << "Face profile not computable" << endl;
395#endif
396 myStatusError = BRepFeat_NoFaceProf;
397 NotDone();
398 return;
399 }
400
401
0d969553
Y
402// ---Propagation on faces of the initial shape
403// to find the faces concerned by the rib
7fd59977 404 Standard_Boolean falseside = Standard_True;
405 Sliding = Propagate(SliList, Prof, myFirstPnt, myLastPnt, falseside);
0d969553 406// Control if there is everything required to have the material at the proper side
7fd59977 407 if(falseside == Standard_False) {
408#ifdef DEB
409 cout << "Verify plane and wire orientation" << endl;
410#endif
411 myStatusError = BRepFeat_FalseSide;
412 NotDone();
413 return;
414 }
415 }
416
417
0d969553 418// ---Generation of the base of the rib profile
7fd59977 419
420 TopoDS_Wire w;
421 BB.MakeWire(w);
422 TopoDS_Edge thePreviousEdge;
423 TopoDS_Vertex theFV;
424 thePreviousEdge.Nullify();
425
0d969553 426// calculate the number of edges to fill the map
7fd59977 427 Standard_Integer counter = 1;
428
0d969553 429// ---case of sliding
7fd59977 430 if(Sliding && !myListOfEdges.IsEmpty()) {
431 BRepTools_WireExplorer EX1(myWire);
432 for(; EX1.More(); EX1.Next()) {
433 const TopoDS_Edge& E = EX1.Current();
434 if(!myLFMap.IsBound(E)) {
435 TopTools_ListOfShape theTmpList;
436 myLFMap.Bind(E, theTmpList );
437 }
438 if(E.IsSame(FirstEdge)) {
439 Standard_Real f, l;
440 Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
441 cc = new Geom_TrimmedCurve(cc, f, l);
442 gp_Pnt pt;
443 if(!FirstEdge.IsSame(LastEdge)) {
444 pt = BRep_Tool::Pnt(TopExp::LastVertex(E,Standard_True));
445 }
446 else {
447 pt = myLastPnt;
448 Standard_Real fpar = IntPar(cc, myFirstPnt);
449 Standard_Real lpar = IntPar(cc, pt);
450 Handle(Geom_Curve) ccc;
451 if(fpar > lpar) {
452 ccc = Handle(Geom_Curve)::DownCast(cc->Reversed());
453 cc = ccc;
454 }
455 }
456 TopoDS_Edge ee1;
457 if(thePreviousEdge.IsNull()) {
458 BRepLib_MakeVertex v1(myFirstPnt);
459 BRepLib_MakeVertex v2(pt);
460 BRepLib_MakeEdge e(cc, v1, v2);
461 ee1 = TopoDS::Edge(e.Shape());
462 }
463 else {
464 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
465 BRepLib_MakeVertex v2(pt);
466
467 BRepLib_MakeEdge e(cc, v1, v2);
468 ee1 = TopoDS::Edge(e.Shape());
469 }
470 TopoDS_Shape aLocalShape = ee1.Oriented(E.Orientation());
471 ee1 = TopoDS::Edge(aLocalShape);
472// ee1 = TopoDS::Edge(ee1.Oriented(E.Orientation()));
473 if(counter == 1) theFV = TopExp::FirstVertex(ee1,Standard_True);
474 myLFMap(E).Append(ee1);
475 BB.Add(w, ee1);
476 thePreviousEdge = ee1;
477 counter++;
478 EX1.Next();
479 break;
480 }
481 }
482
0d969553 483// Case of several edges
7fd59977 484 if(!FirstEdge.IsSame(LastEdge)) {
485 for(; EX1.More(); EX1.Next()) {
486 const TopoDS_Edge& E = EX1.Current();
487 if(!myLFMap.IsBound(E)) {
488 TopTools_ListOfShape thelist1;
489 myLFMap.Bind(E, thelist1);
490 }
491 theList.Append(E);
492 Standard_Real f, l;
493 if(!E.IsSame(LastEdge)) {
494 Handle(Geom_Curve) ccc = BRep_Tool::Curve(E, f, l);
495 TopoDS_Vertex v1, v2;
496 if(!thePreviousEdge.IsNull()) {
497 v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
498 v2 = TopExp::LastVertex(E,Standard_True);
499 }
500 else {
501// v1 = TopExp::LastVertex(E,Standard_True);
502 v1 = TopExp::FirstVertex(E,Standard_True);
503 v2 = TopExp::LastVertex(E,Standard_True);
504 }
505 BRepLib_MakeEdge E1(ccc, v1, v2);
506 TopoDS_Edge E11 = TopoDS::Edge(E1.Shape());
507 TopoDS_Shape aLocalShape = E11.Oriented(E.Orientation());
508 E11 = TopoDS::Edge(aLocalShape);
509// E11 = TopoDS::Edge(E11.Oriented(E.Orientation()));
510 thePreviousEdge = E11;
511 myLFMap(E).Append(E11);
512 BB.Add(w, E11);
513 if(counter == 1) theFV = TopExp::FirstVertex(E11,Standard_True);
514 counter++;
515 }
516 else {
517 Standard_Real f, l;
518 Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
519 gp_Pnt pf = BRep_Tool::Pnt(TopExp::FirstVertex(E,Standard_True));
520 gp_Pnt pl = myLastPnt;
521 TopoDS_Edge ee;
522 if(thePreviousEdge.IsNull()) {
523 BRepLib_MakeEdge e(cc, pf , pl);
524 ee = TopoDS::Edge(e.Shape());
525 }
526 else {
527 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
528 BRepLib_MakeVertex v2(pl);
529 BRepLib_MakeEdge e(cc, v1, v2);
530 ee = TopoDS::Edge(e.Shape());
531 }
532 TopoDS_Shape aLocalShape = ee.Oriented(E.Orientation());
533 ee = TopoDS::Edge(aLocalShape);
534// ee = TopoDS::Edge(ee.Oriented(E.Orientation()));
535 BB.Add(w, ee);
536 myLFMap(E).Append(ee);
537 if(counter == 1) theFV = TopExp::FirstVertex(ee,Standard_True);
538 thePreviousEdge = ee;
539 counter++;
540 break;
541 }
542 }
543 }
544
545 TopTools_ListIteratorOfListOfShape it(myListOfEdges);
546 Standard_Boolean FirstOK = Standard_False;
547 Standard_Boolean LastOK = Standard_False;
548
549 gp_Pnt theLastPnt = myLastPnt;
550 Standard_Integer sens = 0;
551 TopoDS_Edge theEdge, theLEdge, theFEdge;
552 Standard_Integer counter1 = counter;
553 TopTools_ListOfShape NewListOfEdges;
554 NewListOfEdges.Clear();
555 while (!FirstOK) {
556 const TopoDS_Edge& edg = TopoDS::Edge(it.Value());
557 gp_Pnt fp, lp;
558 Standard_Real f, l;
559 Handle(Geom_Curve) ccc = BRep_Tool::Curve(edg, f, l);
560 Handle(Geom_TrimmedCurve) cc = new Geom_TrimmedCurve(ccc, f, l);
561 if ( edg.Orientation() == TopAbs_REVERSED) cc->Reverse();
562
563 fp = cc->Value(cc->FirstParameter());
564 lp = cc->Value(cc->LastParameter());
565 Standard_Real dist = fp.Distance(theLastPnt);
566 if(dist <= myTol) {
567 sens = 1;
568 LastOK = Standard_True;
569 }
570 else {
571 dist = lp.Distance(theLastPnt);
572 if(dist <= myTol) {
573 sens = 2;
574 LastOK = Standard_True;
575 cc->Reverse();
576 }
577 }
578 Standard_Integer FirstFlag = 0;
579 if(sens==1 && lp.Distance(myFirstPnt) <= myTol) {
580 FirstOK = Standard_True;
581 FirstFlag = 1;
582 }
583 else if(sens==2 && fp.Distance(myFirstPnt) <= myTol) {
584 FirstOK = Standard_True;
585 FirstFlag = 2;
586 }
587
588 if (LastOK) {
589 TopoDS_Edge eeee;
590 Standard_Real fpar = cc->FirstParameter();
591 Standard_Real lpar = cc->LastParameter();
592 if(!FirstOK) {
593 if(thePreviousEdge.IsNull()) {
594 BRepLib_MakeEdge e(cc, fpar, lpar);
595 eeee = TopoDS::Edge(e.Shape());
596 }
597 else {
598 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
599 BB.UpdateVertex(v1, dist);
600 BRepLib_MakeVertex v2(cc->Value(lpar));
601 TopoDS_Vertex nv=v2.Vertex();
602 BRepLib_MakeEdge e(cc, v1, nv);
603 eeee = TopoDS::Edge(e.Shape());
604 }
605 }
606 else {
607 if(thePreviousEdge.IsNull()) {
608 BRepLib_MakeVertex v1(cc->Value(fpar));
609 BRepLib_MakeEdge e(cc, v1, theFV);
610 eeee = TopoDS::Edge(e.Shape());
611 }
612 else {
613 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
614 BRepLib_MakeEdge e(cc, v1, theFV);
615 eeee = TopoDS::Edge(e.Shape());
616 }
617 }
618
619 thePreviousEdge = eeee;
620 BB.Add(w, eeee);
621 if(counter == 1) theFV = TopExp::FirstVertex(eeee,Standard_True);
622 counter1++;
623 NewListOfEdges.Append(edg);
624 theEdge = eeee;
7fd59977 625
626 if(dist <= myTol)
627 theFEdge = edg;
628 theLastPnt = BRep_Tool::Pnt(TopExp::LastVertex(theEdge,Standard_True));
629 }
630
631 if(FirstFlag == 1) {
632 theLEdge = edg;
633 }
634 else if(FirstFlag == 2) {
635 theLEdge = theEdge;
636 }
637
638 if(LastOK) {
639 myListOfEdges.Remove(it);
640 it.Initialize(myListOfEdges);
641 LastOK = Standard_False;
642 }
643 else if(it.More()) it.Next();
644 else {
645 Sliding = Standard_False;
646 break;
647 }
648 sens = 0;
649 }
650
651
652 TopTools_DataMapOfShapeListOfShape SlidMap;
653 SlidMap.Clear();
654
655 if(Sliding && counter1 > counter) {
656 TopTools_ListIteratorOfListOfShape it;
657 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm;
658 TopExp_Explorer EX2(w, TopAbs_EDGE);
659 Standard_Integer ii = 0;
660 for(; EX2.More(); EX2.Next()) {
661 const TopoDS_Edge& E = TopoDS::Edge(EX2.Current());
662 ii++;
663 if(ii >= counter && ii <= counter1) {
664 it.Initialize(NewListOfEdges);
665 Standard_Integer jj = 0;
666 for(; it.More(); it.Next()) {
667 const TopoDS_Edge& e2 = TopoDS::Edge(it.Value());
668 jj++;
669 if(jj== (ii - counter +1)) {
670 itm.Initialize(mySlface);
671 for(; itm.More(); itm.Next()) {
672 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
673 const TopTools_ListOfShape& ledg = itm.Value();
674 TopTools_ListIteratorOfListOfShape itedg(ledg);
675 //Standard_Integer iiii = 0;
676 for(; itedg.More(); itedg.Next()) {
677 const TopoDS_Edge& e1 = TopoDS::Edge(itedg.Value());
678 if(e1.IsSame(e2)){
679 if(!SlidMap.IsBound(fac)) {
680 TopTools_ListOfShape thelist2;
681 SlidMap.Bind(fac, thelist2);
682 }
683 SlidMap(fac).Append(E);
684 }
685 }
686 }
687 }
688 }
689 }
690 }
691 }
692
693 mySlface.Clear();
694 mySlface = SlidMap;
695 }
696
0d969553 697// ---Arguments of LocOpe_LinearForm : arguments of the prism sliding
7fd59977 698 if(Sliding) {
699 TopoDS_Face F;
700 BB.MakeFace(F, myPln, myTol);
701 BB.Add(F, w);
702// BRepLib_MakeFace F(myPln->Pln(),w, Standard_True);
703 mySkface = F;
704 myPbase = mySkface;
705 mySUntil.Nullify();
706 }
707
708
0d969553 709// ---Case without sliding : construction of the profile face
7fd59977 710 if(!Sliding) {
711#ifdef DEB
712 if (trc) {
713 if (Modify) cout << " Sliding failure" << endl;
714 cout << " no Sliding" << endl;
715 }
716#endif
717 TopoDS_Face Prof;
718 Standard_Boolean ProfileOK;
719 ProfileOK = NoSlidingProfile(Prof,RevolRib,myTol,Concavite,myPln,
720 bnd,BndFace,CheckPnt,
721 FirstFace,LastFace,FirstVertex,LastVertex,
722 FirstEdge,LastEdge,OnFirstFace,OnLastFace);
723
724 if (!ProfileOK) {
725#ifdef DEB
726 cout << "Not computable" << endl;
727 if (trc) cout << " Face profile not computable" << endl;
728#endif
729 myStatusError = BRepFeat_NoFaceProf;
730 NotDone();
731 return;
732 }
733
734
0d969553
Y
735// ---Propagation on faces of the initial shape
736// to find the faces concerned by the rib
7fd59977 737 Standard_Boolean falseside = Standard_True;
738 Propagate(SliList, Prof, myFirstPnt, myLastPnt, falseside);
0d969553 739// Control if there is everything required to have the material at the proper side
7fd59977 740 if(falseside == Standard_False) {
741#ifdef DEB
742 cout << "Verify plane and wire orientation" << endl;
743#endif
744 myStatusError = BRepFeat_FalseSide;
745 NotDone();
746 return;
747 }
748
749 mySlface.Clear();
750
751 TopTools_ListIteratorOfListOfShape it;
752 it.Initialize(SliList);
753
754 TopoDS_Shape comp;
755
756 BRep_Builder BB;
757 BB.MakeShell(TopoDS::Shell(comp));
758
759 for(; it.More(); it.Next()) {
760 BB.Add(comp, it.Value());
761 }
762
763 mySUntil = comp;
764
765 mySkface = Prof;
766 myPbase = Prof;
767 }
768
769 mySliding = Sliding;
770
771 TopExp_Explorer exp;
772 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
773 TopTools_ListOfShape thelist3;
774 myMap.Bind(exp.Current(), thelist3);
775 myMap(exp.Current()).Append(exp.Current());
776 }
777}
778
779
780//=======================================================================
781//function : Add
782//purpose : add des element de collage
783//=======================================================================
784
785void BRepFeat_MakeLinearForm::Add(const TopoDS_Edge& E,
786 const TopoDS_Face& F)
787{
788#ifdef DEB
789 Standard_Boolean trc = BRepFeat_GettraceFEAT();
790 if (trc) cout << "BRepFeat_MakeLinearForm::Add" << endl;
791#endif
792 if(mySlface.IsEmpty()) {
793 TopExp_Explorer exp;
794 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
795 if (exp.Current().IsSame(F)) {
796 break;
797 }
798 }
799 if (!exp.More()) {
800 Standard_ConstructionError::Raise();
801 }
802
803 if (!mySlface.IsBound(F)) {
804 TopTools_ListOfShape thelist;
805 mySlface.Bind(F, thelist);
806 }
807 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
808 for (; itl.More();itl.Next()) {
809 if (itl.Value().IsSame(E)) {
810 break;
811 }
812 }
813 if (!itl.More()) {
814 mySlface(F).Append(E);
815 }
816 }
817}
818
819
820
821//=======================================================================
822//function : Perform
0d969553 823//purpose : construction of rib from a profile and the initial shape
7fd59977 824//=======================================================================
825
826void BRepFeat_MakeLinearForm::Perform()
827{
828#ifdef DEB
829 Standard_Boolean trc = BRepFeat_GettraceFEAT();
830 if (trc) cout << "BRepFeat_MakeLinearForm::Perform()" << endl;
831#endif
832 if(mySbase.IsNull() || mySkface.IsNull() || myPbase.IsNull()) {
833#ifdef DEB
834 if (trc) cout << " Fields not initialized" << endl;
835#endif
836 myStatusError = BRepFeat_NotInitialized;
837 NotDone();
838 return;
839 }
840
841 gp_Vec nulldir(0, 0, 0);
842
843 Standard_Real Length = myDir.Magnitude() + myDir1.Magnitude();
844
845 myGluedF.Clear();
846
847 if(!mySUntil.IsNull())
848 myPerfSelection = BRepFeat_SelectionU;
849 else
850 myPerfSelection = BRepFeat_NoSelection;
851
852 gp_Dir dir(myDir);
853 gp_Vec V = Length*dir;
854
855 LocOpe_LinearForm theForm;
856
857 if(myDir1.IsEqual(nulldir, Precision::Confusion(), Precision::Confusion()))
858 theForm.Perform(myPbase, V, myFirstPnt, myLastPnt);
859 else
860 theForm.Perform(myPbase, V, myDir1, myFirstPnt, myLastPnt);
861
0d969553 862 TopoDS_Shape VraiForm = theForm.Shape(); // primitive of the rib
7fd59977 863
864 myFacesForDraft.Append(theForm.FirstShape());
865 myFacesForDraft.Append(theForm.LastShape());
0d969553 866 MajMap(myPbase,theForm,myMap,myFShape,myLShape); // management of descendants
7fd59977 867
868 TopExp_Explorer exx(myPbase, TopAbs_EDGE);
869 for(; exx.More(); exx.Next()) {
870 const TopoDS_Edge& e = TopoDS::Edge(exx.Current());
871 if(!myMap.IsBound(e)) {
872#ifdef DEB
873 if (trc) cout << " Sliding face not in Base shape" << endl;
874#endif
875 myStatusError = BRepFeat_IncSlidFace;
876 NotDone();
877 return;
878 }
879 }
880
881 myGShape = VraiForm;
0d969553 882 SetGluedFaces(mySlface, theForm, myGluedF); // management of sliding faces
7fd59977 883
884 if(!myGluedF.IsEmpty() && !mySUntil.IsNull()) {
885#ifdef DEB
886 cout << "The case is not computable" << endl;
887 if (trc) cout << " Glued faces not empty and Until shape not null" << endl;
888#endif
889 myStatusError = BRepFeat_InvShape;
890 NotDone();
891 return;
892 }
893
894 LFPerform();
895
896/*
897
898 TopExp_Explorer expr(mySbase, TopAbs_FACE);
899 char nom1[20], nom2[20];
900 Standard_Integer ii = 0;
901 for(; expr.More(); expr.Next()) {
902 ii++;
903 sprintf(nom1, "faceinitial_%d", ii);
904 DBRep::Set(nom1, expr.Current());
905 Standard_Integer jj = 0;
906 const TopTools_ListOfShape& list = Modified(expr.Current());
907 TopTools_ListIteratorOfListOfShape ite(list);
908 for(; ite.More(); ite.Next()) {
909 jj++;
910 sprintf(nom2, "facemodifie_%d_%d", ii, jj);
911 DBRep::Set(nom2, ite.Value());
912 }
913 }
914
915 expr.Init(myWire, TopAbs_EDGE);
916 ii=0;
917 for(; expr.More(); expr.Next()) {
918 ii++;
919 sprintf(nom1, "edgeinitial_%d", ii);
920 DBRep::Set(nom1, expr.Current());
921 Standard_Integer jj = 0;
922 const TopTools_ListOfShape& genf = Generated(expr.Current());
923 TopTools_ListIteratorOfListOfShape ite(genf);
924 for(; ite.More(); ite.Next()) {
925 jj++;
926 sprintf(nom2, "egdegeneree_%d_%d", ii, jj);
927 DBRep::Set(nom2, ite.Value());
928 }
929 }
930*/
931}
932
933//=======================================================================
934//function : Propagate
0d969553
Y
935//purpose : propagation on faces of the initial shape, find
936// faces concerned by the rib
7fd59977 937//=======================================================================
938 Standard_Boolean BRepFeat_MakeLinearForm::Propagate(TopTools_ListOfShape& SliList,
939 const TopoDS_Face& fac,
940 const gp_Pnt& Firstpnt,
941 const gp_Pnt& Lastpnt,
942 Standard_Boolean& falseside)
943{
944#ifdef DEB
945 Standard_Boolean trc = BRepFeat_GettraceFEATRIB();
946 if (trc) cout << "BRepFeat_MakeLinearForm::Propagate" << endl;
947#endif
948 gp_Pnt Firstpoint = Firstpnt;
949 gp_Pnt Lastpoint = Lastpnt;
950
951 Standard_Boolean result = Standard_True;
952 TopoDS_Face CurrentFace, saveFace;
953 CurrentFace = TopoDS::Face(SliList.First());
954 saveFace = CurrentFace;
955
956 Standard_Boolean LastOK = Standard_False, FirstOK= Standard_False;
957 Standard_Boolean v1OK = Standard_False, v2OK= Standard_False;
958 TopoDS_Vertex v1, v2, v3, v4, ve1, ve2;
959
960 //modified by NIZNHY-PKV Fri Mar 22 16:50:24 2002 f
961 //BRepAlgo_Section sect (fac, CurrentFace, Standard_False);
962 BRepAlgoAPI_Section sect (fac, CurrentFace, Standard_False);
963 //modified by NIZNHY-PKV Fri Mar 22 16:50:32 2002 t
964
965 sect.Approximation(Standard_True);
966 sect.Build();
967
968 TopExp_Explorer Ex;
969 TopoDS_Edge eb, ec;
970 gp_Pnt p1, p2;
971#ifndef DEB
972 Standard_Real t1 = 0., t2 = 0.;
973#else
974 Standard_Real t1, t2;
975#endif
976 Standard_Boolean c1f, c2f, c1l, c2l;
977
978 for (Ex.Init(sect.Shape(), TopAbs_EDGE); Ex.More(); Ex.Next()) {
979 ec = TopoDS::Edge(Ex.Current());
980 v1 = TopExp::FirstVertex(ec,Standard_True);
981 v2 = TopExp::LastVertex(ec,Standard_True);
982 p1 = BRep_Tool::Pnt(v1);
983 p2 = BRep_Tool::Pnt(v2);
984 t1 = BRep_Tool::Tolerance(v1);
985 t2 = BRep_Tool::Tolerance(v2);
986 c1f = p1.Distance(Firstpoint)<=t1;
987 c2f = p2.Distance(Firstpoint)<=t2;
988 c1l = p1.Distance(Lastpoint)<=t1;
989 c2l = p2.Distance(Lastpoint)<=t2;
990 if (c1f || c2f || c1l|| c2l) {
991 eb = ec;
992 if (c1f || c1l) v1OK=Standard_True;
993 if (c2f || c2l) v2OK=Standard_True;
994 if (c1f || c2f) FirstOK=Standard_True;
995 if (c1l || c2l) LastOK=Standard_True;
996 break;
997 }
998 }
999
1000 if(eb.IsNull()) {
1001 falseside = Standard_False;
1002 return Standard_False;
1003 }
1004 TopTools_ListOfShape thelist;
1005 mySlface.Bind(CurrentFace, thelist);
1006 mySlface(CurrentFace).Append(eb);
1007
1008 myListOfEdges.Clear();
1009 myListOfEdges.Append(eb);
1010
0d969553 1011 // two points are on the same face.
7fd59977 1012 if(LastOK && FirstOK) {
1013 return result;
1014 }
1015
1016 TopTools_IndexedDataMapOfShapeListOfShape mapedges;
1017 TopExp::MapShapesAndAncestors(mySbase, TopAbs_EDGE, TopAbs_FACE, mapedges);
1018 TopExp_Explorer ex;
1019 TopoDS_Edge FirstEdge;
1020 BRep_Builder BB;
1021
1022 TopoDS_Vertex Vprevious;
1023 gp_Pnt ptprev;
1024 Standard_Real tvp, dp;
1025
1026 while (!(LastOK && FirstOK)) {
1027 if (v1OK) {
1028 Vprevious=v2;
1029 ptprev=p2;
1030 tvp=t2;
1031 }
1032 else {
1033 Vprevious=v1;
1034 ptprev=p1;
1035 tvp=t1;
1036 }
1037
0d969553 1038 // find edge connected to v1 or v2:
7fd59977 1039 for (ex.Init(CurrentFace, TopAbs_EDGE); ex.More(); ex.Next()) {
1040 const TopoDS_Edge& rfe = TopoDS::Edge(ex.Current());
1041
1042 BRepExtrema_ExtPC projF(Vprevious, rfe);
1043
1044 if(projF.IsDone() && projF.NbExt() >=1) {
1045 Standard_Real dist2min = RealLast();
1046 Standard_Integer index = 0;
1047 for (Standard_Integer sol =1 ; sol <= projF.NbExt(); sol++) {
1048 if (projF.SquareDistance(sol) <= dist2min) {
1049 index = sol;
1050 dist2min = projF.SquareDistance(sol);
1051 }
1052 }
1053 if (index != 0) {
1054 if (dist2min <= BRep_Tool::Tolerance(rfe) * BRep_Tool::Tolerance(rfe)) {
1055 FirstEdge = rfe;
0d969553
Y
1056 // If the edge is not perpendicular to the plane of the rib
1057 // it is required to set Sliding(result) to false.
7fd59977 1058 if (result) {
1059 result=Standard_False;
1060 ve1 = TopExp::FirstVertex(rfe,Standard_True);
1061 ve2 = TopExp::LastVertex(rfe,Standard_True);
1062 BRepExtrema_ExtPF perp(ve1, fac);
1063 if (perp.IsDone()) {
1064 gp_Pnt pe1=perp.Point(1);
1065 perp.Perform(ve2, fac);
1066 if (perp.IsDone()) {
1067 gp_Pnt pe2=perp.Point(1);
1068 if (pe1.Distance(pe2)<=BRep_Tool::Tolerance(rfe))
1069 result=Standard_True;
1070 }
1071 }
1072 }
1073 break;
1074 }
1075 }
1076 }
1077 }
1078
1079 const TopTools_ListOfShape& L = mapedges.FindFromKey(FirstEdge);
1080 TopTools_ListIteratorOfListOfShape It(L);
1081
1082 for (; It.More(); It.Next()) {
1083 const TopoDS_Face& FF = TopoDS::Face(It.Value());
1084 if (!FF.IsSame(CurrentFace)) {
1085 CurrentFace = FF;
1086 break;
1087 }
1088 }
1089
1090 //modified by NIZNHY-PKV Fri Mar 22 16:50:53 2002 f
1091 //BRepAlgo_Section sectf (fac, CurrentFace, Standard_False);
1092 BRepAlgoAPI_Section sectf (fac, CurrentFace, Standard_False);
1093 //modified by NIZNHY-PKV Fri Mar 22 16:51:03 2002 t
1094 sectf.Approximation(Standard_True);
1095 sectf.Build();
1096
1097 TopoDS_Edge edg1;
1098 for (Ex.Init(sectf.Shape(), TopAbs_EDGE); Ex.More(); Ex.Next()) {
1099 edg1 = TopoDS::Edge(Ex.Current());
1100 v1=TopExp::FirstVertex(edg1,Standard_True);
1101 v2=TopExp::LastVertex(edg1,Standard_True);
1102 t1 = BRep_Tool::Tolerance(v1);
1103 t2 = BRep_Tool::Tolerance(v2);
1104 p1 = BRep_Tool::Pnt(v1);
1105 p2 = BRep_Tool::Pnt(v2);
1106 v1OK = p1.Distance(ptprev)<=t1;
1107 v2OK = p2.Distance(ptprev)<=t2;
1108 if (v1OK || v2OK) break;
1109 }
1110
1111 if (v1OK) {
1112 if (!FirstOK) {
1113 dp = p2.Distance(Firstpoint);
1114 if(dp <= 2*t2) {
1115 FirstOK = Standard_True;
1116 BB.UpdateVertex(v2, dp);
1117 }
1118 }
1119 if (!LastOK) {
1120 dp = p2.Distance(Lastpoint);
1121 if(dp <= 2*t2) {
1122 LastOK = Standard_True;
1123 BB.UpdateVertex(v2, dp);
1124 }
1125 }
1126 }
1127 else if (v2OK) {
1128 if (!FirstOK) {
1129 dp = p1.Distance(Firstpoint);
1130 if(dp <= 2*t1) {
1131 FirstOK = Standard_True;
1132 BB.UpdateVertex(v1, dp);
1133 }
1134 }
1135 if (!LastOK) {
1136 dp = p1.Distance(Lastpoint);
1137 if(dp <= 2*t1) {
1138 LastOK = Standard_True;
1139 BB.UpdateVertex(v1, dp);
1140 }
1141 }
1142 }
1143 else {
0d969553 1144 // end by chaining the section
7fd59977 1145 return Standard_False;
1146 }
7fd59977 1147 TopTools_ListOfShape thelist1;
7fd59977 1148 mySlface.Bind(CurrentFace, thelist1);
1149 mySlface(CurrentFace).Append(edg1);
1150 myListOfEdges.Append(edg1);
1151 }
1152
1153 return result;
1154
1155}
1156
1157//=======================================================================
1158//function : MajMap
0d969553 1159//purpose : management of descendants
7fd59977 1160//=======================================================================
1161
1162static void MajMap(const TopoDS_Shape& theB,
1163 const LocOpe_LinearForm& theP,
1164 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1165 TopoDS_Shape& theFShape, // myFShape
1166 TopoDS_Shape& theLShape) // myLShape
1167{
1168 TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
1169 if (exp.More()) {
1170 theFShape = exp.Current();
1171 TopTools_ListOfShape thelist;
1172 theMap.Bind(theFShape, thelist);
1173 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
1174 theMap(theFShape).Append(exp.Current());
1175 }
1176 }
1177
1178 exp.Init(theP.LastShape(),TopAbs_WIRE);
1179 if (exp.More()) {
1180 theLShape = exp.Current();
1181 TopTools_ListOfShape thelist1;
1182 theMap.Bind(theLShape, thelist1);
1183 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1184 theMap(theLShape).Append(exp.Current());
1185 }
1186 }
1187
1188 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1189 if (!theMap.IsBound(exp.Current())) {
1190#ifdef DEB
1191 const TopoDS_Edge& e =
1192#endif
1193 TopoDS::Edge(exp.Current());
1194 TopTools_ListOfShape thelist2;
1195 theMap.Bind(exp.Current(), thelist2);
1196 theMap(exp.Current()) = theP.Shapes(exp.Current());
1197 }
1198 }
1199}
1200
1201//=======================================================================
1202//function : SetGluedFaces
0d969553 1203//purpose : management of faces of gluing
7fd59977 1204//=======================================================================
1205
1206static void SetGluedFaces(const TopTools_DataMapOfShapeListOfShape& theSlmap,
1207 LocOpe_LinearForm& thePrism,
1208 TopTools_DataMapOfShapeShape& theMap)
1209{
0d969553 1210 // Slidings
7fd59977 1211 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(theSlmap);
1212 if(!theSlmap.IsEmpty()) {
1213 for (; itm.More(); itm.Next()) {
1214 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
1215 const TopTools_ListOfShape& ledg = itm.Value();
1216 TopTools_ListIteratorOfListOfShape it;
1217 for (it.Initialize(ledg); it.More(); it.Next()) {
1218 const TopTools_ListOfShape& gfac = thePrism.Shapes(it.Value());
1219 if (gfac.Extent() != 1) {
1220#ifdef DEB
1221 cout << "Pb SetGluedFace" << endl;
1222#endif
1223 }
1224 theMap.Bind(gfac.First(),fac);
1225 }
1226 }
1227 }
1228}
1229