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