7fd59977 |
1 | // File: BRepFeat_MakeRevol.cxx |
2 | // Created: Tue Feb 13 14:42:59 1996 |
3 | // Author: Jacques GOUSSARD |
4 | // <jag@bravox> |
5 | |
6 | |
7 | #include <BRepFeat_MakeRevol.ixx> |
8 | |
9 | #include <BRepFeat.hxx> |
10 | #include <LocOpe.hxx> |
11 | #include <LocOpe_Revol.hxx> |
12 | #include <LocOpe_Builder.hxx> |
13 | #include <LocOpe_Gluer.hxx> |
14 | #include <LocOpe_FindEdges.hxx> |
15 | #include <LocOpe_SequenceOfCirc.hxx> |
16 | #include <LocOpe_BuildShape.hxx> |
17 | #include <LocOpe_CSIntersector.hxx> |
18 | #include <LocOpe_PntFace.hxx> |
19 | |
20 | #include <gp_Vec.hxx> |
21 | #include <gp_Pnt.hxx> |
22 | #include <gp_Ax1.hxx> |
23 | #include <gp_Pnt2d.hxx> |
24 | #include <TColgp_SequenceOfPnt.hxx> |
25 | #include <Geom_Surface.hxx> |
26 | #include <Geom_Curve.hxx> |
27 | #include <Geom_Circle.hxx> |
28 | #include <Geom2d_Curve.hxx> |
29 | #include <Geom_RectangularTrimmedSurface.hxx> |
30 | #include <Bnd_Box.hxx> |
31 | |
32 | #include <BRepSweep_Revol.hxx> |
33 | #include <BRep_Builder.hxx> |
34 | #include <BRep_Tool.hxx> |
35 | #include <TopExp_Explorer.hxx> |
36 | #include <TopTools_MapOfShape.hxx> |
37 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
38 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
39 | #include <TopTools_MapIteratorOfMapOfShape.hxx> |
40 | #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx> |
41 | |
42 | #include <BRepAlgoAPI_Cut.hxx> |
43 | #include <BRepAlgoAPI_Fuse.hxx> |
44 | |
45 | #include <BRepLib_MakeFace.hxx> |
46 | #include <BRepTools_Modifier.hxx> |
47 | #include <BRepTools_TrsfModification.hxx> |
48 | |
49 | #include <Standard_ConstructionError.hxx> |
50 | |
51 | #include <TopoDS_Solid.hxx> |
52 | #include <TopoDS_Compound.hxx> |
53 | #include <TopoDS_Shell.hxx> |
54 | |
55 | #include <gp_Pln.hxx> |
56 | #include <Geom_Plane.hxx> |
57 | |
58 | |
59 | #include <TopExp.hxx> |
60 | #include <Precision.hxx> |
61 | #include <BRepBndLib.hxx> |
62 | #include <BRepBuilderAPI.hxx> |
63 | #include <BRepFeat.hxx> |
64 | |
65 | #include <ElCLib.hxx> |
66 | |
67 | #ifdef DEB |
68 | Standard_IMPORT Standard_Boolean BRepFeat_GettraceFEAT(); |
69 | #endif |
70 | |
71 | static void MajMap(const TopoDS_Shape&, // base |
72 | const LocOpe_Revol&, |
73 | TopTools_DataMapOfShapeListOfShape&, // myMap |
74 | TopoDS_Shape&, // myFShape |
75 | TopoDS_Shape&); // myLShape |
76 | |
77 | |
78 | static void SetGluedFaces(const TopoDS_Face& theSkface, |
79 | const TopoDS_Shape& theSbase, |
80 | const TopoDS_Shape& thePbase, |
81 | const TopTools_DataMapOfShapeListOfShape& theSlmap, |
82 | LocOpe_Revol&, |
83 | TopTools_DataMapOfShapeShape&); |
84 | |
85 | |
86 | static void VerifGluedFaces(const TopoDS_Face& theSkface, |
87 | const TopoDS_Shape& thePbase, |
88 | Handle(Geom_Curve)& theBCurve, |
89 | TColGeom_SequenceOfCurve& theCurves, |
90 | LocOpe_Revol& theRevol, |
91 | TopTools_DataMapOfShapeShape& theMap); |
92 | |
93 | |
94 | static Standard_Boolean ToFuse(const TopoDS_Face& , |
95 | const TopoDS_Face&); |
96 | |
97 | |
98 | |
99 | |
100 | //======================================================================= |
101 | //function : Init |
102 | //purpose : |
103 | //======================================================================= |
104 | |
105 | void BRepFeat_MakeRevol::Init(const TopoDS_Shape& Sbase, |
106 | const TopoDS_Shape& Pbase, |
107 | const TopoDS_Face& Skface, |
108 | const gp_Ax1& Axis, |
109 | const Standard_Integer Mode, |
110 | const Standard_Boolean Modify) |
111 | { |
112 | #ifdef DEB |
113 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
114 | if (trc) cout << "BRepFeat_MakeRevol::Init" << endl; |
115 | #endif |
116 | myAxis = Axis; |
117 | myPbase = Pbase; |
118 | mySbase = Sbase; |
119 | BasisShapeValid(); |
120 | mySkface = Skface; |
121 | SketchFaceValid(); |
122 | myPbase = Pbase; |
123 | mySlface.Clear(); |
124 | if(Mode == 0) { |
125 | myFuse = Standard_False; |
126 | myJustFeat = Standard_False; |
127 | } |
128 | else if(Mode == 1) { |
129 | myFuse = Standard_True; |
130 | myJustFeat = Standard_False; |
131 | } |
132 | else if(Mode == 2) { |
133 | myFuse = Standard_True; |
134 | myJustFeat = Standard_True; |
135 | } |
136 | else { |
137 | } |
138 | myModify = Modify; |
139 | myJustGluer = Standard_False; |
140 | |
141 | //-------------- ifv |
142 | // mySkface.Nullify(); |
143 | //-------------- ifv |
144 | |
145 | |
146 | myShape.Nullify(); |
147 | myMap.Clear(); |
148 | myFShape.Nullify(); |
149 | myLShape.Nullify(); |
150 | TopExp_Explorer exp; |
151 | for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) { |
152 | TopTools_ListOfShape thelist; |
153 | myMap.Bind(exp.Current(), thelist); |
154 | myMap(exp.Current()).Append(exp.Current()); |
155 | } |
156 | #ifdef DEB |
157 | if (trc) { |
158 | if (myJustFeat) cout << " Just Feature" << endl; |
159 | if (myFuse) cout << " Fuse" << endl; |
160 | if (!myFuse) cout << " Cut" << endl; |
161 | if (!myModify) cout << " Modify = 0" << endl; |
162 | } |
163 | #endif |
164 | } |
165 | |
166 | |
167 | //======================================================================= |
168 | //function : Add |
169 | //purpose : add faces et edges de glissement |
170 | //======================================================================= |
171 | |
172 | void BRepFeat_MakeRevol::Add(const TopoDS_Edge& E, |
173 | const TopoDS_Face& F) |
174 | { |
175 | #ifdef DEB |
176 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
177 | if (trc) cout << "BRepFeat_MakeRevol::Add(Edge,face)" << endl; |
178 | #endif |
179 | TopExp_Explorer exp; |
180 | for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) { |
181 | if (exp.Current().IsSame(F)) { |
182 | break; |
183 | } |
184 | } |
185 | if (!exp.More()) { |
186 | Standard_ConstructionError::Raise(); |
187 | } |
188 | |
189 | for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) { |
190 | if (exp.Current().IsSame(E)) { |
191 | break; |
192 | } |
193 | } |
194 | if (!exp.More()) { |
195 | Standard_ConstructionError::Raise(); |
196 | } |
197 | |
198 | if (!mySlface.IsBound(F)) { |
199 | TopTools_ListOfShape thelist; |
200 | mySlface.Bind(F, thelist); |
201 | } |
202 | TopTools_ListIteratorOfListOfShape itl(mySlface(F)); |
203 | for (; itl.More();itl.Next()) { |
204 | if (itl.Value().IsSame(E)) { |
205 | break; |
206 | } |
207 | } |
208 | if (!itl.More()) { |
209 | mySlface(F).Append(E); |
210 | } |
211 | } |
212 | |
213 | |
214 | //======================================================================= |
215 | //function : Perform |
216 | //purpose : |
217 | //======================================================================= |
218 | |
219 | void BRepFeat_MakeRevol::Perform(const Standard_Real Angle) |
220 | { |
221 | #ifdef DEB |
222 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
223 | if (trc) cout << "BRepFeat_MakeRevol::Perform(Angle)" << endl; |
224 | #endif |
225 | mySFrom.Nullify(); |
226 | ShapeFromValid(); |
227 | mySUntil.Nullify(); |
228 | ShapeUntilValid(); |
229 | myGluedF.Clear(); |
230 | myPerfSelection = BRepFeat_NoSelection; |
231 | PerfSelectionValid(); |
232 | Standard_Boolean RevolComp = (2*PI-Abs(Angle) <= Precision::Angular()); |
233 | LocOpe_Revol theRevol; |
234 | Standard_Real angledec = 0.; |
235 | TopExp_Explorer exp; |
236 | if(RevolComp) { |
237 | /* |
238 | if (!mySkface.IsNull() || !mySlface.IsEmpty()) { |
239 | for (exp.Init(mySbase,TopAbs_FACE); exp.More(); exp.Next()) { |
240 | if (exp.Current().IsSame(mySkface)) { |
241 | angledec = PI/5; // pourquoi pas |
242 | if (myFuse) angledec = -angledec; |
243 | break; |
244 | } |
245 | } |
246 | } |
247 | */ |
248 | mySkface.Nullify(); |
249 | } |
250 | if(angledec == 0.) theRevol.Perform(myPbase, myAxis, Angle); |
251 | else theRevol.Perform(myPbase, myAxis, Angle, angledec); |
252 | |
253 | TopoDS_Shape VraiRevol = theRevol.Shape(); |
254 | |
255 | MajMap(myPbase,theRevol,myMap,myFShape,myLShape); |
256 | |
257 | myGShape = VraiRevol; |
258 | GeneratedShapeValid(); |
259 | TopoDS_Shape Base = theRevol.FirstShape(); |
260 | exp.Init(Base, TopAbs_FACE); |
261 | TopoDS_Face theBase = TopoDS::Face(exp.Current()); |
262 | exp.Next(); |
263 | if(exp.More()) { |
264 | NotDone(); |
265 | myStatusError = BRepFeat_InvFirstShape; |
266 | return; |
267 | } |
268 | |
269 | TopoDS_Face FFace; |
270 | |
271 | Standard_Boolean found = Standard_False; |
272 | |
273 | if(!mySkface.IsNull() || !mySlface.IsEmpty()) { |
274 | if(myLShape.ShapeType() == TopAbs_WIRE) { |
275 | TopExp_Explorer ex1(VraiRevol, TopAbs_FACE); |
276 | for(; ex1.More(); ex1.Next()) { |
277 | TopExp_Explorer ex2(ex1.Current(), TopAbs_WIRE); |
278 | for(; ex2.More(); ex2.Next()) { |
279 | if(ex2.Current().IsSame(myLShape)) { |
280 | FFace = TopoDS::Face(ex1.Current()); |
281 | found = Standard_True; |
282 | break; |
283 | } |
284 | } |
285 | if(found) break; |
286 | } |
287 | } |
288 | |
289 | TopExp_Explorer exp(mySbase, TopAbs_FACE); |
290 | for(; exp.More(); exp.Next()) { |
291 | const TopoDS_Face& ff = TopoDS::Face(exp.Current()); |
292 | if(ToFuse(ff, FFace)) { |
293 | TopTools_DataMapOfShapeListOfShape sl; |
294 | if(!FFace.IsSame(myPbase) && BRepFeat::IsInside(ff, FFace)) |
295 | //SetGluedFaces(ff, mySbase, FFace, sl, theRevol, myGluedF); |
296 | break; |
297 | } |
298 | } |
299 | } |
300 | |
301 | //SetGluedFaces(mySkface, mySbase, theBase, mySlface, theRevol, myGluedF); |
302 | GluedFacesValid(); |
303 | if (!mySkface.IsNull()) { |
304 | VerifGluedFaces(mySkface, theBase, myBCurve, myCurves, theRevol, myGluedF); |
305 | } |
306 | |
307 | if(myGluedF.IsEmpty()) { |
308 | if(myFuse == 1) { |
309 | //modified by NIZNHY-PKV Thu Mar 21 18:15:06 2002 f |
310 | //BRepAlgo_Fuse f(mySbase, myGShape); |
311 | //myShape = f.Shape(); |
312 | //UpdateDescendants(f.Builder(), myShape, Standard_False); |
313 | BRepAlgoAPI_Fuse f(mySbase, myGShape); |
314 | myShape = f.Shape(); |
315 | UpdateDescendants(f, myShape, Standard_False); |
316 | //modified by NIZNHY-PKV Thu Mar 21 18:15:11 2002 t |
317 | Done(); |
318 | } |
319 | else if(myFuse == 0) { |
320 | //modified by NIZNHY-PKV Thu Mar 21 18:15:37 2002 f |
321 | //BRepAlgo_Cut c(mySbase, myGShape); |
322 | //myShape = c.Shape(); |
323 | //UpdateDescendants(c.Builder(), myShape, Standard_False); |
324 | BRepAlgoAPI_Cut c(mySbase, myGShape); |
325 | myShape = c.Shape(); |
326 | UpdateDescendants(c, myShape, Standard_False); |
327 | //modified by NIZNHY-PKV Thu Mar 21 18:15:47 2002 t |
328 | Done(); |
329 | } |
330 | else { |
331 | myShape = myGShape; |
332 | Done(); |
333 | } |
334 | } |
335 | else { |
336 | theRevol.Curves(myCurves); |
337 | myBCurve = theRevol.BarycCurve(); |
338 | GlobalPerform(); |
339 | } |
340 | } |
341 | |
342 | |
343 | //======================================================================= |
344 | //function : Perform |
345 | //purpose : feature jusqu'au shape Until |
346 | //======================================================================= |
347 | |
348 | void BRepFeat_MakeRevol::Perform(const TopoDS_Shape& Until) |
349 | { |
350 | #ifdef DEB |
351 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
352 | if (trc) cout << "BRepFeat_MakeRevol::Perform(Until)" << endl; |
353 | #endif |
354 | Standard_Real Angle = 0.; |
355 | Standard_Boolean TourComplet = Standard_False; |
356 | |
357 | if (Until.IsNull()) { |
358 | Standard_ConstructionError::Raise(); |
359 | } |
360 | TopExp_Explorer exp(Until, TopAbs_FACE); |
361 | if (!exp.More()) { |
362 | Standard_ConstructionError::Raise(); |
363 | } |
364 | if (!mySkface.IsNull() && Until.IsSame(mySkface)) { |
365 | Angle = 2*PI; |
366 | TourComplet = Standard_True; |
367 | } |
368 | myGluedF.Clear(); |
369 | myPerfSelection = BRepFeat_SelectionU; |
370 | PerfSelectionValid(); |
371 | mySFrom.Nullify(); |
372 | ShapeFromValid(); |
373 | mySUntil = Until; |
374 | Standard_Boolean Trf = TransformShapeFU(1); |
375 | ShapeUntilValid(); |
376 | |
377 | // On fait systematiquement un revol quasi-complet |
378 | // BRepSweep_Revol theRevol(myPbase,myAxis,2.*PI-10.*Precision::Angular()); |
379 | LocOpe_Revol theRevol; |
380 | if(!TourComplet) { |
381 | Angle = 2.*PI- 3*PI/180.; |
382 | #ifdef DEB |
383 | if (trc) cout << " No complete Revol" << endl; |
384 | #endif |
385 | } |
386 | theRevol.Perform(myPbase, myAxis, Angle); |
387 | TopoDS_Shape VraiRevol = theRevol.Shape(); |
388 | MajMap(myPbase,theRevol,myMap,myFShape,myLShape); |
389 | |
390 | |
391 | if(!Trf) { |
392 | |
393 | myGShape = VraiRevol; |
394 | GeneratedShapeValid(); |
395 | |
396 | TopoDS_Shape Base = theRevol.FirstShape(); |
397 | exp.Init(Base, TopAbs_FACE); |
398 | TopoDS_Face theBase = TopoDS::Face(exp.Current()); |
399 | exp.Next(); |
400 | if(exp.More()) { |
401 | NotDone(); |
402 | myStatusError = BRepFeat_InvFirstShape; |
403 | return; |
404 | } |
405 | |
406 | //SetGluedFaces(mySkface, mySbase, theBase, mySlface, theRevol, myGluedF); |
407 | GluedFacesValid(); |
408 | //VerifGluedFaces(mySkface, theBase, myBCurve, myCurves, theRevol, myGluedF); |
409 | |
410 | theRevol.Curves(myCurves); |
411 | myBCurve = theRevol.BarycCurve(); |
412 | GlobalPerform(); |
413 | } |
414 | else { |
415 | TColGeom_SequenceOfCurve scur; |
416 | theRevol.Curves(myCurves); |
417 | myBCurve = theRevol.BarycCurve(); |
418 | scur.Clear(); |
419 | scur.Append(myBCurve); |
420 | LocOpe_CSIntersector ASI(mySUntil); |
421 | ASI.Perform(scur); |
422 | if (ASI.IsDone() && ASI.NbPoints(1) >=1) { |
423 | TopAbs_Orientation Or = ASI.Point(1,1).Orientation(); |
424 | TopoDS_Face FUntil = ASI.Point(1,1).Face(); |
425 | TopoDS_Shape Comp; |
426 | BRep_Builder B; |
427 | B.MakeCompound(TopoDS::Compound(Comp)); |
428 | TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or); |
429 | if (!S.IsNull()) B.Add(Comp,S); |
430 | //modified by NIZNHY-PKV Thu Mar 21 18:17:31 2002 f |
431 | //BRepAlgo_Cut trP(VraiRevol,Comp); |
432 | BRepAlgoAPI_Cut trP(VraiRevol,Comp); |
433 | //modified by NIZNHY-PKV Thu Mar 21 18:17:37 2002 t |
434 | TopoDS_Shape Cutsh = trP.Shape(); |
435 | TopExp_Explorer ex(Cutsh, TopAbs_SOLID); |
436 | for(; ex.More(); ex.Next()) { |
437 | TopExp_Explorer ex1(ex.Current(), TopAbs_FACE); |
438 | for(; ex1.More(); ex1.Next()) { |
439 | const TopoDS_Face& fac = TopoDS::Face(ex1.Current()); |
440 | if(fac.IsSame(myPbase)) { |
441 | VraiRevol = ex.Current(); |
442 | break; |
443 | } |
444 | } |
445 | } |
446 | if(myFuse == 1) { |
447 | //modified by NIZNHY-PKV Thu Mar 21 18:17:53 2002 f |
448 | //BRepAlgo_Fuse f(mySbase, VraiRevol); |
449 | //myShape = f.Shape(); |
450 | //UpdateDescendants(f.Builder(), myShape, Standard_False); |
451 | BRepAlgoAPI_Fuse f(mySbase, VraiRevol); |
452 | myShape = f.Shape(); |
453 | UpdateDescendants(f, myShape, Standard_False); |
454 | //modified by NIZNHY-PKV Thu Mar 21 18:17:57 2002 t |
455 | Done(); |
456 | } |
457 | else if(myFuse == 0) { |
458 | //modified by NIZNHY-PKV Thu Mar 21 18:18:23 2002 f |
459 | //BRepAlgo_Cut c(mySbase, VraiRevol); |
460 | //myShape = c.Shape(); |
461 | //UpdateDescendants(c.Builder(), myShape, Standard_False); |
462 | BRepAlgoAPI_Cut c(mySbase, VraiRevol); |
463 | myShape = c.Shape(); |
464 | UpdateDescendants(c, myShape, Standard_False); |
465 | //modified by NIZNHY-PKV Thu Mar 21 18:18:28 2002 t |
466 | Done(); |
467 | } |
468 | else { |
469 | myShape = VraiRevol; |
470 | Done(); |
471 | } |
472 | } |
473 | } |
474 | // boucle de controle de descendance |
475 | /* |
476 | TopExp_Explorer expr(mySbase, TopAbs_FACE); |
477 | char nom1[20], nom2[20]; |
478 | Standard_Integer ii = 0; |
479 | for(; expr.More(); expr.Next()) { |
480 | ii++; |
481 | sprintf(nom1, "faceinitial_%d", ii); |
482 | DBRep::Set(nom1, expr.Current()); |
483 | Standard_Integer jj = 0; |
484 | const TopTools_ListOfShape& list = Modified(expr.Current()); |
485 | TopTools_ListIteratorOfListOfShape ite(list); |
486 | for(; ite.More(); ite.Next()) { |
487 | jj++; |
488 | sprintf(nom2, "facemodifie_%d_%d", ii, jj); |
489 | DBRep::Set(nom2, ite.Value()); |
490 | } |
491 | } |
492 | |
493 | expr.Init(myPbase, TopAbs_EDGE); |
494 | ii=0; |
495 | for(; expr.More(); expr.Next()) { |
496 | ii++; |
497 | sprintf(nom1, "edgeinitial_%d", ii); |
498 | DBRep::Set(nom1, expr.Current()); |
499 | Standard_Integer jj = 0; |
500 | const TopTools_ListOfShape& list = Generated(expr.Current()); |
501 | TopTools_ListIteratorOfListOfShape ite(list); |
502 | for(; ite.More(); ite.Next()) { |
503 | jj++; |
504 | sprintf(nom2, "facegeneree_%d_%d", ii, jj); |
505 | DBRep::Set(nom2, ite.Value()); |
506 | } |
507 | } |
508 | */ |
509 | } |
510 | |
511 | |
512 | //======================================================================= |
513 | //function : Perform |
514 | //purpose : feature limitee par les deux shapes |
515 | //======================================================================= |
516 | |
517 | void BRepFeat_MakeRevol::Perform(const TopoDS_Shape& From, |
518 | const TopoDS_Shape& Until) |
519 | { |
520 | #ifdef DEB |
521 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
522 | if (trc) cout << "BRepFeat_MakeRevol::Perform(From,Until)" << endl; |
523 | #endif |
524 | if (From.IsNull() || Until.IsNull()) { |
525 | Standard_ConstructionError::Raise(); |
526 | } |
527 | if (!mySkface.IsNull()) { |
528 | if (From.IsSame(mySkface)) { |
529 | myJustGluer = Standard_True; |
530 | Perform(Until); |
531 | if (myJustGluer) return; |
532 | } |
533 | else if (Until.IsSame(mySkface)) { |
534 | myJustGluer = Standard_True; |
535 | myAxis.Reverse(); |
536 | Perform(From); |
537 | if (myJustGluer) return; |
538 | } |
539 | } |
540 | |
541 | myGluedF.Clear(); |
542 | myPerfSelection = BRepFeat_SelectionFU; |
543 | PerfSelectionValid(); |
544 | |
545 | TopExp_Explorer exp(From, TopAbs_FACE); |
546 | if (!exp.More()) { |
547 | Standard_ConstructionError::Raise(); |
548 | } |
549 | exp.Init(Until, TopAbs_FACE); |
550 | if (!exp.More()) { |
551 | Standard_ConstructionError::Raise(); |
552 | } |
553 | |
554 | mySFrom = From; |
555 | Standard_Boolean Trff = TransformShapeFU(0); |
556 | ShapeFromValid(); |
557 | mySUntil = Until; |
558 | Standard_Boolean Trfu = TransformShapeFU(1); |
559 | ShapeUntilValid(); |
560 | |
561 | if(Trfu != Trff) { |
562 | NotDone(); |
563 | myStatusError = BRepFeat_IncTypes; |
564 | return; |
565 | } |
566 | |
567 | LocOpe_Revol theRevol; |
568 | theRevol.Perform(myPbase, myAxis, 2*PI); |
569 | TopoDS_Shape VraiRevol = theRevol.Shape(); |
570 | |
571 | MajMap(myPbase,theRevol,myMap,myFShape,myLShape); |
572 | |
573 | if(!Trff) { |
574 | myGShape = VraiRevol; |
575 | GeneratedShapeValid(); |
576 | |
577 | //SetGluedFaces(TopoDS_Face(), mySbase, myPbase, mySlface, theRevol, myGluedF); |
578 | GluedFacesValid(); |
579 | // VerifGluedFaces(mySkface, theBase, myBCurve, myCurves, theRevol, myGluedF); |
580 | |
581 | theRevol.Curves(myCurves); |
582 | myBCurve = theRevol.BarycCurve(); |
583 | GlobalPerform(); |
584 | } |
585 | else { |
586 | theRevol.Curves(myCurves); |
587 | myBCurve = theRevol.BarycCurve(); |
588 | TColGeom_SequenceOfCurve scur; |
589 | scur.Clear(); |
590 | scur.Append(myBCurve); |
591 | LocOpe_CSIntersector ASI1(mySUntil); |
592 | LocOpe_CSIntersector ASI2(mySFrom); |
593 | ASI1.Perform(scur); |
594 | ASI2.Perform(scur); |
595 | TopAbs_Orientation OrU, OrF; |
596 | TopoDS_Face FFrom, FUntil; |
597 | Standard_Real PrF, PrU; |
598 | if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) { |
599 | OrU = ASI1.Point(1,1).Orientation(); |
600 | FUntil = ASI1.Point(1,1).Face(); |
601 | PrU = ASI1.Point(1,1).Parameter(); |
602 | } |
603 | else { |
604 | NotDone(); |
605 | myStatusError = BRepFeat_NoIntersectU; |
606 | return; |
607 | } |
608 | if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) { |
609 | Standard_Real pr1 = ASI2.Point(1,1).Parameter(); |
610 | pr1 = ElCLib::InPeriod(pr1,PrU-2*PI,PrU); |
611 | Standard_Real pr2 = ASI2.Point(1,ASI2.NbPoints(1)).Parameter(); |
612 | pr2 = ElCLib::InPeriod(pr2,PrU-2*PI,PrU); |
613 | OrF = OrU; |
614 | FFrom = ASI2.Point(1,1).Face(); |
615 | PrF = Max(pr1, pr2); |
616 | } |
617 | else { |
618 | NotDone(); |
619 | myStatusError = BRepFeat_NoIntersectF; |
620 | return; |
621 | } |
622 | if(!(PrU > PrF)) { |
623 | NotDone(); |
624 | myStatusError = BRepFeat_IncParameter; |
625 | return; |
626 | } |
627 | TopoDS_Shape Comp; |
628 | BRep_Builder B; |
629 | B.MakeCompound(TopoDS::Compound(Comp)); |
630 | TopoDS_Solid SF = BRepFeat::Tool(mySFrom, FFrom, OrF); |
631 | if (!SF.IsNull()) B.Add(Comp,SF); |
632 | TopoDS_Solid SU = BRepFeat::Tool(mySUntil, FUntil, OrU); |
633 | if (!SU.IsNull()) B.Add(Comp,SU); |
634 | //modified by NIZNHY-PKV Thu Mar 21 18:18:54 2002 f |
635 | //BRepAlgo_Cut trP(VraiRevol,Comp); |
636 | BRepAlgoAPI_Cut trP(VraiRevol,Comp); |
637 | //modified by NIZNHY-PKV Thu Mar 21 18:18:57 2002 t |
638 | TopoDS_Shape Cutsh = trP.Shape(); |
639 | TopExp_Explorer ex(Cutsh, TopAbs_SOLID); |
640 | // Standard_Real PrF = BRepFeat::ParametricBarycenter(mySFrom, myBCurve); |
641 | // Standard_Real PrU = BRepFeat::ParametricBarycenter(mySUntil, myBCurve); |
642 | VraiRevol = ex.Current(); |
643 | for(; ex.More(); ex.Next()) { |
644 | Standard_Real PrCur = BRepFeat:: |
645 | ParametricBarycenter(ex.Current(), myBCurve); |
646 | if(PrF <= PrCur && PrU >= PrCur) { |
647 | VraiRevol = ex.Current(); |
648 | break; |
649 | } |
650 | } |
651 | if(myFuse == 1) { |
652 | //modified by NIZNHY-PKV Thu Mar 21 18:19:14 2002 f |
653 | //BRepAlgo_Fuse f(mySbase, VraiRevol); |
654 | //myShape = f.Shape(); |
655 | //UpdateDescendants(f.Builder(), myShape, Standard_False); |
656 | BRepAlgoAPI_Fuse f(mySbase, VraiRevol); |
657 | myShape = f.Shape(); |
658 | UpdateDescendants(f, myShape, Standard_False); |
659 | //modified by NIZNHY-PKV Thu Mar 21 18:19:18 2002 t |
660 | Done(); |
661 | } |
662 | else if(myFuse == 0) { |
663 | //modified by NIZNHY-PKV Thu Mar 21 18:19:46 2002 f |
664 | //BRepAlgo_Cut c(mySbase, VraiRevol); |
665 | //myShape = c.Shape(); |
666 | //UpdateDescendants(c.Builder(), myShape, Standard_False); |
667 | BRepAlgoAPI_Cut c(mySbase, VraiRevol); |
668 | myShape = c.Shape(); |
669 | UpdateDescendants(c, myShape, Standard_False); |
670 | //modified by NIZNHY-PKV Thu Mar 21 18:19:50 2002 t |
671 | Done(); |
672 | } |
673 | else { |
674 | myShape = VraiRevol; |
675 | Done(); |
676 | } |
677 | } |
678 | } |
679 | |
680 | |
681 | //======================================================================= |
682 | //function : PerformThruAll |
683 | //purpose : feature a travers tout le shape initial |
684 | //======================================================================= |
685 | |
686 | void BRepFeat_MakeRevol::PerformThruAll() |
687 | { |
688 | #ifdef DEB |
689 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
690 | if (trc) cout << "BRepFeat_MakeRevol::PerformThruAll()" << endl; |
691 | #endif |
692 | Perform(2.*PI); |
693 | } |
694 | |
695 | //======================================================================= |
696 | //function : PerformUntilAngle |
697 | //purpose : feature jusqu'au shape Until definie avec l'angle |
698 | //======================================================================= |
699 | |
700 | void BRepFeat_MakeRevol::PerformUntilAngle(const TopoDS_Shape& Until, |
701 | const Standard_Real Angle) |
702 | { |
703 | #ifdef DEB |
704 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
705 | if (trc) cout << "BRepFeat_MakeRevol::PerformUntilAngle(Until,Angle)" << endl; |
706 | #endif |
707 | if (Until.IsNull()) { |
708 | Perform(Angle); |
709 | } |
710 | if(Angle == 0) { |
711 | Perform(Until); |
712 | } |
713 | TopExp_Explorer exp(Until, TopAbs_FACE); |
714 | if (!exp.More()) { |
715 | Standard_ConstructionError::Raise(); |
716 | } |
717 | if (!mySkface.IsNull() && Until.IsSame(mySkface)) { |
718 | Perform(Angle); |
719 | return; |
720 | } |
721 | myGluedF.Clear(); |
722 | myPerfSelection = BRepFeat_NoSelection; |
723 | PerfSelectionValid(); |
724 | mySFrom.Nullify(); |
725 | ShapeFromValid(); |
726 | mySUntil = Until; |
727 | Standard_Boolean Trf = TransformShapeFU(1); |
728 | ShapeUntilValid(); |
729 | |
730 | // On fait systematiquement un revol quasi-complet |
731 | // BRepSweep_Revol theRevol(myPbase,myAxis,2.*PI-10.*Precision::Angular()); |
732 | LocOpe_Revol theRevol; |
733 | theRevol.Perform(myPbase, myAxis, Angle); |
734 | TopoDS_Shape VraiRevol = theRevol.Shape(); |
735 | |
736 | MajMap(myPbase,theRevol,myMap,myFShape,myLShape); |
737 | |
738 | if(Trf) { |
739 | myGShape = VraiRevol; |
740 | GeneratedShapeValid(); |
741 | |
742 | TopoDS_Shape Base = theRevol.FirstShape(); |
743 | exp.Init(Base, TopAbs_FACE); |
744 | TopoDS_Face theBase = TopoDS::Face(exp.Current()); |
745 | exp.Next(); |
746 | if(exp.More()) { |
747 | NotDone(); |
748 | myStatusError = BRepFeat_InvFirstShape; |
749 | return; |
750 | } |
751 | |
752 | //SetGluedFaces(mySkface, mySbase, theBase, mySlface, theRevol, myGluedF); |
753 | GluedFacesValid(); |
754 | //VerifGluedFaces(mySkface, theBase, myBCurve, myCurves, theRevol, myGluedF); |
755 | |
756 | |
757 | theRevol.Curves(myCurves); |
758 | myBCurve = theRevol.BarycCurve(); |
759 | GlobalPerform(); |
760 | } |
761 | else { |
762 | TColGeom_SequenceOfCurve scur; |
763 | theRevol.Curves(myCurves); |
764 | myBCurve = theRevol.BarycCurve(); |
765 | scur.Clear(); |
766 | scur.Append(myBCurve); |
767 | LocOpe_CSIntersector ASI(mySUntil); |
768 | ASI.Perform(scur); |
769 | if (ASI.IsDone() && ASI.NbPoints(1) >=1) { |
770 | TopAbs_Orientation Or = ASI.Point(1,1).Orientation(); |
771 | TopoDS_Face FUntil = ASI.Point(1,1).Face(); |
772 | TopoDS_Shape Comp; |
773 | BRep_Builder B; |
774 | B.MakeCompound(TopoDS::Compound(Comp)); |
775 | TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or); |
776 | if (!S.IsNull()) B.Add(Comp,S); |
777 | //modified by NIZNHY-PKV Thu Mar 21 18:20:14 2002 f |
778 | //BRepAlgo_Cut trP(VraiRevol,Comp); |
779 | BRepAlgoAPI_Cut trP(VraiRevol,Comp); |
780 | //modified by NIZNHY-PKV Thu Mar 21 18:20:19 2002 t |
781 | TopoDS_Shape Cutsh = trP.Shape(); |
782 | TopExp_Explorer ex(Cutsh, TopAbs_SOLID); |
783 | for(; ex.More(); ex.Next()) { |
784 | TopExp_Explorer ex1(ex.Current(), TopAbs_FACE); |
785 | for(; ex1.More(); ex1.Next()) { |
786 | const TopoDS_Face& fac = TopoDS::Face(ex1.Current()); |
787 | if(fac.IsSame(myPbase)) { |
788 | VraiRevol = ex.Current(); |
789 | break; |
790 | } |
791 | } |
792 | } |
793 | if(myFuse == 1) { |
794 | //modified by NIZNHY-PKV Thu Mar 21 18:20:36 2002 f |
795 | //BRepAlgo_Fuse f(mySbase, VraiRevol); |
796 | //myShape = f.Shape(); |
797 | //UpdateDescendants(f.Builder(), myShape, Standard_False); |
798 | BRepAlgoAPI_Fuse f(mySbase, VraiRevol); |
799 | myShape = f.Shape(); |
800 | UpdateDescendants(f, myShape, Standard_False); |
801 | //modified by NIZNHY-PKV Thu Mar 21 18:20:40 2002 t |
802 | Done(); |
803 | } |
804 | else if(myFuse == 0) { |
805 | //modified by NIZNHY-PKV Thu Mar 21 18:21:07 2002 f |
806 | //BRepAlgo_Cut c(mySbase, VraiRevol); |
807 | //myShape = c.Shape(); |
808 | //UpdateDescendants(c.Builder(), myShape, Standard_False); |
809 | BRepAlgoAPI_Cut c(mySbase, VraiRevol); |
810 | myShape = c.Shape(); |
811 | UpdateDescendants(c, myShape, Standard_False); |
812 | //modified by NIZNHY-PKV Thu Mar 21 18:21:26 2002 t |
813 | Done(); |
814 | } |
815 | else { |
816 | myShape = VraiRevol; |
817 | Done(); |
818 | } |
819 | } |
820 | } |
821 | } |
822 | //======================================================================= |
823 | //function : Curves |
824 | //purpose : cercles parallels a la generatrice du revol |
825 | //======================================================================= |
826 | |
827 | void BRepFeat_MakeRevol::Curves(TColGeom_SequenceOfCurve& scur) |
828 | { |
829 | scur = myCurves; |
830 | } |
831 | |
832 | //======================================================================= |
833 | //function : BarycCurve |
834 | //purpose : passe par le centre des masses de la primitive |
835 | //======================================================================= |
836 | |
837 | Handle(Geom_Curve) BRepFeat_MakeRevol::BarycCurve() |
838 | { |
839 | return myBCurve; |
840 | } |
841 | |
842 | |
843 | //======================================================================= |
844 | //function : SetGluedFaces |
845 | //purpose : gestion des faces de collage |
846 | //======================================================================= |
847 | |
848 | static void SetGluedFaces(const TopoDS_Face& theSkface, |
849 | const TopoDS_Shape& theSbase, |
850 | const TopoDS_Shape& thePbase, |
851 | const TopTools_DataMapOfShapeListOfShape& theSlmap, |
852 | LocOpe_Revol& theRevol, |
853 | TopTools_DataMapOfShapeShape& theMap) |
854 | { |
855 | TopExp_Explorer exp; |
856 | if (!theSkface.IsNull() && thePbase.ShapeType() == TopAbs_FACE) { |
857 | for (exp.Init(theSbase,TopAbs_FACE); exp.More(); exp.Next()) { |
858 | if (exp.Current().IsSame(theSkface)) { |
859 | theMap.Bind(thePbase,theSkface); |
860 | break; |
861 | } |
862 | } |
863 | } |
864 | else { |
865 | TopExp_Explorer exp2; |
866 | for (exp.Init(thePbase,TopAbs_FACE);exp.More();exp.Next()) { |
867 | const TopoDS_Face& fac = TopoDS::Face(exp.Current()); |
868 | for (exp2.Init(theSbase,TopAbs_FACE);exp2.More();exp2.Next()) { |
869 | if (exp2.Current().IsSame(fac)) { |
870 | theMap.Bind(fac,fac); |
871 | break; |
872 | } |
873 | } |
874 | } |
875 | } |
876 | |
877 | // Glissements |
878 | TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(theSlmap); |
879 | if(!theSlmap.IsEmpty()) { |
880 | for (; itm.More(); itm.Next()) { |
881 | const TopoDS_Face& fac = TopoDS::Face(itm.Key()); |
882 | const TopTools_ListOfShape& ledg = itm.Value(); |
883 | TopTools_ListIteratorOfListOfShape it; |
884 | for (it.Initialize(ledg); it.More(); it.Next()) { |
885 | const TopTools_ListOfShape& gfac = theRevol.Shapes(it.Value()); |
886 | if (gfac.Extent() != 1) { |
887 | #ifdef DEB |
888 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
889 | if (trc) cout << " BRepFeat_MakeRevol : Pb SetGluedFace" << endl; |
890 | #endif |
891 | } |
892 | theMap.Bind(gfac.First(),fac); |
893 | } |
894 | } |
895 | } |
896 | } |
897 | |
898 | //======================================================================= |
899 | //function : VerifGluedFaces |
900 | //purpose : Verification intersection Outil/theSkface = thePbase |
901 | // Si oui -> OK si non -> cas sans collage |
902 | //======================================================================= |
903 | |
904 | static void VerifGluedFaces(const TopoDS_Face& theSkface, |
905 | const TopoDS_Shape& thePbase, |
906 | Handle(Geom_Curve)& theBCurve, |
907 | TColGeom_SequenceOfCurve& theCurves, |
908 | LocOpe_Revol& theRevol, |
909 | TopTools_DataMapOfShapeShape& theMap) |
910 | { |
911 | Standard_Boolean GluedFaces = Standard_True; |
912 | TopoDS_Shape VraiRevol = theRevol.Shape(); |
913 | |
914 | TColGeom_SequenceOfCurve scur; |
915 | theRevol.Curves(theCurves); |
916 | theBCurve = theRevol.BarycCurve(); |
917 | scur.Clear(); |
918 | scur.Append(theBCurve); |
919 | LocOpe_CSIntersector ASI(theSkface); |
920 | ASI.Perform(scur); |
921 | if (ASI.IsDone() && ASI.NbPoints(1) >=1) { |
922 | TopAbs_Orientation Or = ASI.Point(1,1).Orientation(); |
923 | TopoDS_Face FSk = ASI.Point(1,1).Face(); |
924 | TopoDS_Shape Comp; |
925 | BRep_Builder B; |
926 | B.MakeCompound(TopoDS::Compound(Comp)); |
927 | TopoDS_Solid S = BRepFeat::Tool(theSkface, FSk, Or); |
928 | if (!S.IsNull()) B.Add(Comp,S); |
929 | //modified by NIZNHY-PKV Thu Mar 21 18:21:54 2002 f |
930 | //BRepAlgo_Cut trP(VraiRevol,Comp); |
931 | BRepAlgoAPI_Cut trP(VraiRevol,Comp); |
932 | //modified by NIZNHY-PKV Thu Mar 21 18:21:58 2002 t |
933 | TopoDS_Shape Cutsh = trP.Shape(); |
934 | TopExp_Explorer ex(Cutsh, TopAbs_SOLID); |
935 | for(; ex.More(); ex.Next()) { |
936 | TopExp_Explorer ex1(ex.Current(), TopAbs_FACE); |
937 | for(; ex1.More(); ex1.Next()) { |
938 | const TopoDS_Face& fac1 = TopoDS::Face(ex1.Current()); |
939 | TopExp_Explorer ex2(thePbase, TopAbs_FACE); |
940 | for(; ex2.More(); ex2.Next()) { |
941 | const TopoDS_Face& fac2 = TopoDS::Face(ex2.Current()); |
942 | if(fac1.IsSame(fac2)) break; |
943 | } |
944 | if (ex2.More()) break; |
945 | } |
946 | if (ex1.More()) continue; |
947 | GluedFaces = Standard_False; |
948 | break; |
949 | } |
950 | if (!GluedFaces) { |
951 | #ifdef DEB |
952 | Standard_Boolean trc = BRepFeat_GettraceFEAT(); |
953 | if (trc) cout << " Intersection Revol/skface : pas de collage" << endl; |
954 | #endif |
955 | theMap.Clear(); |
956 | } |
957 | } |
958 | } |
959 | |
960 | //======================================================================= |
961 | //function : MajMap |
962 | //purpose : gestion de descendants |
963 | //======================================================================= |
964 | |
965 | static void MajMap(const TopoDS_Shape& theB, |
966 | const LocOpe_Revol& theP, |
967 | TopTools_DataMapOfShapeListOfShape& theMap, // myMap |
968 | TopoDS_Shape& theFShape, // myFShape |
969 | TopoDS_Shape& theLShape) // myLShape |
970 | { |
971 | TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE); |
972 | if (exp.More()) { |
973 | theFShape = exp.Current(); |
974 | TopTools_ListOfShape thelist; |
975 | theMap.Bind(theFShape, thelist); |
976 | for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) { |
977 | theMap(theFShape).Append(exp.Current()); |
978 | } |
979 | } |
980 | |
981 | exp.Init(theP.LastShape(),TopAbs_WIRE); |
982 | if (exp.More()) { |
983 | theLShape = exp.Current(); |
984 | TopTools_ListOfShape thelist1; |
985 | theMap.Bind(theLShape, thelist1); |
986 | for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) { |
987 | theMap(theLShape).Append(exp.Current()); |
988 | } |
989 | } |
990 | |
991 | for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) { |
992 | if (!theMap.IsBound(exp.Current())) { |
993 | TopTools_ListOfShape thelist2; |
994 | theMap.Bind(exp.Current(), thelist2); |
995 | theMap(exp.Current()) = theP.Shapes(exp.Current()); |
996 | } |
997 | } |
998 | } |
999 | |
1000 | |
1001 | |
1002 | //======================================================================= |
1003 | //function : ToFuse |
1004 | //purpose : deux faces samedomaine ou pas |
1005 | //======================================================================= |
1006 | |
1007 | Standard_Boolean ToFuse(const TopoDS_Face& F1, |
1008 | const TopoDS_Face& F2) |
1009 | { |
1010 | if (F1.IsNull() || F2.IsNull()) { |
1011 | return Standard_False; |
1012 | } |
1013 | |
1014 | Handle(Geom_Surface) S1,S2; |
1015 | TopLoc_Location loc1, loc2; |
1016 | Handle(Standard_Type) typS1,typS2; |
1017 | const Standard_Real tollin = Precision::Confusion(); |
1018 | const Standard_Real tolang = Precision::Angular(); |
1019 | |
1020 | S1 = BRep_Tool::Surface(F1,loc1); |
1021 | S2 = BRep_Tool::Surface(F2,loc2); |
1022 | |
1023 | typS1 = S1->DynamicType(); |
1024 | typS2 = S2->DynamicType(); |
1025 | |
1026 | if (typS1 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { |
1027 | S1 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S1))->BasisSurface(); |
1028 | typS1 = S1->DynamicType(); |
1029 | } |
1030 | |
1031 | if (typS2 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { |
1032 | S2 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S2))->BasisSurface(); |
1033 | typS2 = S2->DynamicType(); |
1034 | } |
1035 | |
1036 | if (typS1 != typS2) { |
1037 | return Standard_False; |
1038 | } |
1039 | |
1040 | |
1041 | Standard_Boolean ValRet = Standard_False; |
1042 | if (typS1 == STANDARD_TYPE(Geom_Plane)) { |
1043 | S1 = BRep_Tool::Surface(F1); // pour appliquer la location. |
1044 | S2 = BRep_Tool::Surface(F2); |
1045 | gp_Pln pl1( (*((Handle(Geom_Plane)*)&S1))->Pln()); |
1046 | gp_Pln pl2( (*((Handle(Geom_Plane)*)&S2))->Pln()); |
1047 | |
1048 | if (pl1.Position().IsCoplanar(pl2.Position(),tollin,tolang)) { |
1049 | ValRet = Standard_True; |
1050 | } |
1051 | } |
1052 | |
1053 | return ValRet; |
1054 | } |
1055 | |
1056 | |
1057 | |
1058 | |
1059 | |
1060 | |
1061 | |
1062 | |
1063 | |