0024096: Eliminate compiler warning C4505 in MSVC++ with warning level 4
[occt.git] / src / BRepFeat / BRepFeat_MakeRevol.cxx
1 // Created on: 1996-02-13
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 #include <BRepFeat_MakeRevol.ixx>
24
25 #include <BRepFeat.hxx>
26 #include <LocOpe.hxx>
27 #include <LocOpe_Revol.hxx>
28 #include <LocOpe_Gluer.hxx>
29 #include <LocOpe_FindEdges.hxx>
30 #include <LocOpe_SequenceOfCirc.hxx>
31 #include <LocOpe_BuildShape.hxx>
32 #include <LocOpe_CSIntersector.hxx>
33 #include <LocOpe_PntFace.hxx>
34
35 #include <gp_Vec.hxx>
36 #include <gp_Pnt.hxx>
37 #include <gp_Ax1.hxx>
38 #include <gp_Pnt2d.hxx>
39 #include <TColgp_SequenceOfPnt.hxx>
40 #include <Geom_Surface.hxx>
41 #include <Geom_Curve.hxx>
42 #include <Geom_Circle.hxx>
43 #include <Geom2d_Curve.hxx>
44 #include <Geom_RectangularTrimmedSurface.hxx>
45 #include <Bnd_Box.hxx>
46
47 #include <BRepSweep_Revol.hxx>
48 #include <BRep_Builder.hxx>
49 #include <BRep_Tool.hxx>
50 #include <TopExp_Explorer.hxx>
51 #include <TopTools_MapOfShape.hxx>
52 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
53 #include <TopTools_ListIteratorOfListOfShape.hxx>
54 #include <TopTools_MapIteratorOfMapOfShape.hxx>
55 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
56
57 #include <BRepAlgoAPI_Cut.hxx>
58 #include <BRepAlgoAPI_Fuse.hxx>
59
60 #include <BRepLib_MakeFace.hxx>
61 #include <BRepTools_Modifier.hxx>
62 #include <BRepTools_TrsfModification.hxx>
63
64 #include <Standard_ConstructionError.hxx>
65
66 #include <TopoDS_Solid.hxx>
67 #include <TopoDS_Compound.hxx>
68 #include <TopoDS_Shell.hxx>
69
70 #include <gp_Pln.hxx>
71 #include <Geom_Plane.hxx>
72
73
74 #include <TopExp.hxx>
75 #include <Precision.hxx>
76 #include <BRepBndLib.hxx>
77 #include <BRepBuilderAPI.hxx>
78 #include <BRepFeat.hxx>
79
80 #include <ElCLib.hxx>
81
82 #ifdef DEB
83 extern Standard_Boolean BRepFeat_GettraceFEAT();
84 #endif
85
86 static void MajMap(const TopoDS_Shape&, // base
87                    const LocOpe_Revol&,
88                    TopTools_DataMapOfShapeListOfShape&, // myMap
89                    TopoDS_Shape&,  // myFShape
90                    TopoDS_Shape&); // myLShape
91
92
93 static void VerifGluedFaces(const TopoDS_Face& theSkface,
94                             const TopoDS_Shape& thePbase,
95                             Handle(Geom_Curve)& theBCurve,
96                             TColGeom_SequenceOfCurve& theCurves,
97                             LocOpe_Revol& theRevol,
98                             TopTools_DataMapOfShapeShape& theMap);
99
100
101 static Standard_Boolean ToFuse(const TopoDS_Face& ,
102                                const TopoDS_Face&);
103
104
105
106
107 //=======================================================================
108 //function : Init
109 //purpose  : 
110 //=======================================================================
111
112 void BRepFeat_MakeRevol::Init(const TopoDS_Shape& Sbase,
113                               const TopoDS_Shape& Pbase,
114                               const TopoDS_Face& Skface,
115                               const gp_Ax1& Axis,
116                               const Standard_Integer Mode,
117                               const Standard_Boolean Modify)
118 {
119 #ifdef DEB
120   Standard_Boolean trc = BRepFeat_GettraceFEAT();
121   if (trc) cout << "BRepFeat_MakeRevol::Init" << endl;
122 #endif
123   myAxis   = Axis;
124   myPbase  = Pbase;
125   mySbase  = Sbase;
126   BasisShapeValid();
127   mySkface = Skface;
128   SketchFaceValid();
129   myPbase  = Pbase;
130   mySlface.Clear();
131   if(Mode == 0) {
132     myFuse   = Standard_False;
133     myJustFeat = Standard_False;
134   }
135   else if(Mode == 1) {
136     myFuse   = Standard_True;
137     myJustFeat = Standard_False;
138   }
139   else if(Mode == 2) {
140     myFuse   = Standard_True;
141     myJustFeat = Standard_True;
142   }
143   else {    
144   }
145   myModify = Modify;
146   myJustGluer = Standard_False;
147
148   //-------------- ifv
149 //  mySkface.Nullify();
150   //-------------- ifv
151
152
153   myShape.Nullify();
154   myMap.Clear();
155   myFShape.Nullify();
156   myLShape.Nullify();
157   TopExp_Explorer exp;
158   for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
159     TopTools_ListOfShape thelist;
160     myMap.Bind(exp.Current(), thelist);
161     myMap(exp.Current()).Append(exp.Current());
162   }
163 #ifdef DEB
164   if (trc) {
165     if (myJustFeat)  cout << " Just Feature" << endl;
166     if (myFuse)  cout << " Fuse" << endl;
167     if (!myFuse)  cout << " Cut" << endl;
168     if (!myModify) cout << " Modify = 0" << endl;
169   }
170 #endif 
171 }
172
173
174 //=======================================================================
175 //function : Add
176 //purpose  : add faces add edges of sliding
177 //=======================================================================
178
179 void BRepFeat_MakeRevol::Add(const TopoDS_Edge& E,
180                              const TopoDS_Face& F)
181 {
182 #ifdef DEB
183   Standard_Boolean trc = BRepFeat_GettraceFEAT();
184   if (trc) cout << "BRepFeat_MakeRevol::Add(Edge,face)" << endl;
185 #endif
186   TopExp_Explorer exp;
187   for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
188     if (exp.Current().IsSame(F)) {
189       break;
190     }
191   }
192   if (!exp.More()) {
193     Standard_ConstructionError::Raise();
194   }
195
196   for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
197     if (exp.Current().IsSame(E)) {
198       break;
199     }
200   }
201   if (!exp.More()) {
202     Standard_ConstructionError::Raise();
203   }
204
205   if (!mySlface.IsBound(F)) {
206     TopTools_ListOfShape thelist;
207     mySlface.Bind(F, thelist);
208   }
209   TopTools_ListIteratorOfListOfShape itl(mySlface(F));
210   for (; itl.More();itl.Next()) {
211     if (itl.Value().IsSame(E)) {
212       break;
213     }
214   }
215   if (!itl.More()) {
216     mySlface(F).Append(E);
217   }
218 }
219
220
221 //=======================================================================
222 //function : Perform
223 //purpose  : 
224 //=======================================================================
225
226 void BRepFeat_MakeRevol::Perform(const Standard_Real Angle)
227 {
228 #ifdef DEB
229   Standard_Boolean trc = BRepFeat_GettraceFEAT();
230   if (trc) cout << "BRepFeat_MakeRevol::Perform(Angle)" << endl;
231 #endif
232   mySFrom.Nullify();
233   ShapeFromValid();
234   mySUntil.Nullify();
235   ShapeUntilValid();
236   myGluedF.Clear();
237   myPerfSelection = BRepFeat_NoSelection;
238   PerfSelectionValid();
239   Standard_Boolean RevolComp = (2*M_PI-Abs(Angle) <= Precision::Angular());
240   LocOpe_Revol theRevol;
241   Standard_Real angledec = 0.;
242   TopExp_Explorer exp;
243   if(RevolComp) {
244     /*
245     if (!mySkface.IsNull() || !mySlface.IsEmpty()) {
246       for (exp.Init(mySbase,TopAbs_FACE); exp.More(); exp.Next()) {
247         if (exp.Current().IsSame(mySkface)) {
248           angledec = M_PI/5; // pourquoi pas
249           if (myFuse) angledec = -angledec;
250           break;
251         }
252       }
253     }
254     */
255     mySkface.Nullify();
256   }
257   if(angledec == 0.) theRevol.Perform(myPbase, myAxis, Angle);
258   else theRevol.Perform(myPbase, myAxis, Angle, angledec);
259
260   TopoDS_Shape VraiRevol = theRevol.Shape();
261   
262   MajMap(myPbase,theRevol,myMap,myFShape,myLShape);
263
264   myGShape = VraiRevol;
265   GeneratedShapeValid();
266   TopoDS_Shape Base = theRevol.FirstShape();
267   exp.Init(Base, TopAbs_FACE);
268   TopoDS_Face theBase = TopoDS::Face(exp.Current());
269   exp.Next();
270   if(exp.More()) {
271     NotDone();
272     myStatusError = BRepFeat_InvFirstShape;
273     return;
274   }
275
276   TopoDS_Face FFace;
277   
278   Standard_Boolean found = Standard_False;
279
280   if(!mySkface.IsNull() || !mySlface.IsEmpty()) {
281     if(myLShape.ShapeType() == TopAbs_WIRE) {
282       TopExp_Explorer ex1(VraiRevol, TopAbs_FACE);
283       for(; ex1.More(); ex1.Next()) {
284         TopExp_Explorer ex2(ex1.Current(), TopAbs_WIRE);
285         for(; ex2.More(); ex2.Next()) {
286           if(ex2.Current().IsSame(myLShape)) {
287             FFace = TopoDS::Face(ex1.Current());
288             found = Standard_True;
289             break;
290           }
291         }
292         if(found) break;
293       }
294     }
295     
296     TopExp_Explorer exp(mySbase, TopAbs_FACE);
297     for(; exp.More(); exp.Next()) {
298       const TopoDS_Face& ff = TopoDS::Face(exp.Current());
299       if(ToFuse(ff, FFace)) {
300         TopTools_DataMapOfShapeListOfShape sl;
301         if(!FFace.IsSame(myPbase) && BRepFeat::IsInside(ff, FFace)) 
302         break;
303       }
304     }
305   }
306   GluedFacesValid();
307   if (!mySkface.IsNull()) {
308     VerifGluedFaces(mySkface, theBase, myBCurve, myCurves, theRevol, myGluedF);
309   }
310
311   if(myGluedF.IsEmpty()) {
312     if(myFuse == 1) {
313       //modified by NIZNHY-PKV Thu Mar 21 18:15:06 2002 f
314       //BRepAlgo_Fuse f(mySbase, myGShape);
315       //myShape = f.Shape();
316       //UpdateDescendants(f.Builder(), myShape, Standard_False);
317       BRepAlgoAPI_Fuse f(mySbase, myGShape);
318       myShape = f.Shape();
319       UpdateDescendants(f, myShape, Standard_False);
320       //modified by NIZNHY-PKV Thu Mar 21 18:15:11 2002 t
321       Done();
322     }
323     else if(myFuse == 0) {
324       //modified by NIZNHY-PKV Thu Mar 21 18:15:37 2002 f
325       //BRepAlgo_Cut c(mySbase, myGShape);
326       //myShape = c.Shape();
327       //UpdateDescendants(c.Builder(), myShape, Standard_False);
328       BRepAlgoAPI_Cut c(mySbase, myGShape);
329       myShape = c.Shape();
330       UpdateDescendants(c, myShape, Standard_False);
331       //modified by NIZNHY-PKV Thu Mar 21 18:15:47 2002 t
332       Done();
333     }
334     else {
335       myShape = myGShape;
336       Done();
337     }
338   }
339   else {
340     theRevol.Curves(myCurves);
341     myBCurve = theRevol.BarycCurve();
342     GlobalPerform();
343   }
344 }
345
346
347 //=======================================================================
348 //function : Perform
349 //purpose  : feature till shape Until
350 //=======================================================================
351
352 void BRepFeat_MakeRevol::Perform(const TopoDS_Shape& Until)
353 {
354 #ifdef DEB
355   Standard_Boolean trc = BRepFeat_GettraceFEAT();
356   if (trc) cout << "BRepFeat_MakeRevol::Perform(Until)" << endl;
357 #endif
358   Standard_Real Angle = 0.;
359   Standard_Boolean TourComplet = Standard_False;
360
361   if (Until.IsNull()) {
362     Standard_ConstructionError::Raise();
363   }
364   TopExp_Explorer exp(Until, TopAbs_FACE);
365   if (!exp.More()) {
366     Standard_ConstructionError::Raise();
367   }
368   if (!mySkface.IsNull() && Until.IsSame(mySkface)) {
369     Angle = 2*M_PI;
370     TourComplet = Standard_True;
371   }
372   myGluedF.Clear();
373   myPerfSelection = BRepFeat_SelectionU;
374   PerfSelectionValid();
375   mySFrom.Nullify();
376   ShapeFromValid();
377   mySUntil = Until;
378   Standard_Boolean Trf = TransformShapeFU(1);
379   ShapeUntilValid();
380
381 // Do systematically almost complete revolution
382 // BRepSweep_Revol theRevol(myPbase,myAxis,2.*M_PI-10.*Precision::Angular());
383   LocOpe_Revol theRevol;
384   if(!TourComplet) {
385     Angle = 2.*M_PI- 3*M_PI/180.;
386 #ifdef DEB
387     if (trc) cout << " No complete Revolution" << endl;
388 #endif
389   }
390   theRevol.Perform(myPbase, myAxis, Angle);
391   TopoDS_Shape VraiRevol = theRevol.Shape();
392   MajMap(myPbase,theRevol,myMap,myFShape,myLShape);
393
394
395   if(!Trf) {
396     
397     myGShape = VraiRevol;
398     GeneratedShapeValid();
399     
400     TopoDS_Shape Base = theRevol.FirstShape();
401     exp.Init(Base, TopAbs_FACE);
402     TopoDS_Face theBase = TopoDS::Face(exp.Current());
403     exp.Next();
404     if(exp.More()) {
405       NotDone();
406       myStatusError = BRepFeat_InvFirstShape;
407       return;
408     }
409     GluedFacesValid();
410     //VerifGluedFaces(mySkface, theBase, myBCurve, myCurves, theRevol, myGluedF);
411
412     theRevol.Curves(myCurves);
413     myBCurve = theRevol.BarycCurve();
414     GlobalPerform();
415   }
416   else {
417     TColGeom_SequenceOfCurve scur;
418     theRevol.Curves(myCurves);
419     myBCurve = theRevol.BarycCurve();    
420     scur.Clear();    
421     scur.Append(myBCurve);
422     LocOpe_CSIntersector ASI(mySUntil);
423     ASI.Perform(scur);
424     if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
425       TopAbs_Orientation Or = ASI.Point(1,1).Orientation();
426       TopoDS_Face FUntil = ASI.Point(1,1).Face();
427       TopoDS_Shape Comp;
428       BRep_Builder B;
429       B.MakeCompound(TopoDS::Compound(Comp));
430       TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
431       if (!S.IsNull()) B.Add(Comp,S);
432       //modified by NIZNHY-PKV Thu Mar 21 18:17:31 2002 f
433       //BRepAlgo_Cut trP(VraiRevol,Comp);
434       BRepAlgoAPI_Cut trP(VraiRevol,Comp);
435       //modified by NIZNHY-PKV Thu Mar 21 18:17:37 2002 t
436       TopoDS_Shape Cutsh = trP.Shape();
437       TopExp_Explorer ex(Cutsh, TopAbs_SOLID);
438       for(; ex.More(); ex.Next()) {
439         TopExp_Explorer ex1(ex.Current(), TopAbs_FACE);
440         for(; ex1.More(); ex1.Next()) {
441           const TopoDS_Face& fac = TopoDS::Face(ex1.Current());
442           if(fac.IsSame(myPbase)) {
443             VraiRevol = ex.Current();
444             break;
445           }
446         }
447       }
448       if(myFuse == 1) {
449         //modified by NIZNHY-PKV Thu Mar 21 18:17:53 2002 f
450         //BRepAlgo_Fuse f(mySbase, VraiRevol);
451         //myShape = f.Shape();
452         //UpdateDescendants(f.Builder(), myShape, Standard_False);
453         BRepAlgoAPI_Fuse f(mySbase, VraiRevol);
454         myShape = f.Shape();
455         UpdateDescendants(f, myShape, Standard_False);
456         //modified by NIZNHY-PKV Thu Mar 21 18:17:57 2002 t
457         Done();
458       }
459       else if(myFuse == 0) {
460         //modified by NIZNHY-PKV Thu Mar 21 18:18:23 2002 f
461         //BRepAlgo_Cut c(mySbase, VraiRevol);
462         //myShape = c.Shape();
463         //UpdateDescendants(c.Builder(), myShape, Standard_False);
464         BRepAlgoAPI_Cut c(mySbase, VraiRevol);
465         myShape = c.Shape();
466         UpdateDescendants(c, myShape, Standard_False);
467         //modified by NIZNHY-PKV Thu Mar 21 18:18:28 2002 t
468         Done();
469       }
470       else {
471         myShape = VraiRevol;
472         Done(); 
473       }
474     }         
475   }
476    // Loop of control of descendance
477 /*
478   TopExp_Explorer expr(mySbase, TopAbs_FACE);
479   char nom1[20], nom2[20];
480   Standard_Integer ii = 0;
481   for(; expr.More(); expr.Next()) {
482     ii++;
483     sprintf(nom1, "faceinitial_%d", ii);
484     DBRep::Set(nom1, expr.Current());
485     Standard_Integer jj = 0;
486     const TopTools_ListOfShape& list = Modified(expr.Current());
487     TopTools_ListIteratorOfListOfShape ite(list);
488     for(; ite.More(); ite.Next()) {
489       jj++;
490       sprintf(nom2, "facemodifie_%d_%d", ii, jj);
491       DBRep::Set(nom2, ite.Value());
492     }
493   }
494  
495   expr.Init(myPbase, TopAbs_EDGE); 
496   ii=0; 
497   for(; expr.More(); expr.Next()) {
498     ii++;
499     sprintf(nom1, "edgeinitial_%d", ii); 
500     DBRep::Set(nom1, expr.Current()); 
501     Standard_Integer jj = 0;
502     const TopTools_ListOfShape& list = Generated(expr.Current());
503     TopTools_ListIteratorOfListOfShape ite(list);
504     for(; ite.More(); ite.Next()) {
505       jj++;
506       sprintf(nom2, "facegeneree_%d_%d", ii, jj);
507       DBRep::Set(nom2, ite.Value());
508     }
509   }
510 */
511  }
512
513
514 //=======================================================================
515 //function : Perform
516 //purpose  : feature limited by two shapes
517 //=======================================================================
518
519 void BRepFeat_MakeRevol::Perform(const TopoDS_Shape& From,
520                                  const TopoDS_Shape& Until)
521 {
522 #ifdef DEB
523   Standard_Boolean trc = BRepFeat_GettraceFEAT();
524   if (trc) cout << "BRepFeat_MakeRevol::Perform(From,Until)" << endl;
525 #endif
526   if (From.IsNull() || Until.IsNull()) {
527     Standard_ConstructionError::Raise();
528   }
529   if (!mySkface.IsNull()) {
530     if (From.IsSame(mySkface)) {
531       myJustGluer = Standard_True;
532       Perform(Until);
533       if (myJustGluer) return;
534     }
535     else if (Until.IsSame(mySkface)) {
536       myJustGluer = Standard_True;
537       myAxis.Reverse();
538       Perform(From);
539       if (myJustGluer) return;
540     }
541   }
542
543   myGluedF.Clear();
544   myPerfSelection = BRepFeat_SelectionFU;
545   PerfSelectionValid();
546
547   TopExp_Explorer exp(From, TopAbs_FACE);
548   if (!exp.More()) {
549     Standard_ConstructionError::Raise();
550   }
551   exp.Init(Until, TopAbs_FACE);
552   if (!exp.More()) {
553     Standard_ConstructionError::Raise();
554   }
555
556   mySFrom = From;
557   Standard_Boolean Trff = TransformShapeFU(0);
558   ShapeFromValid();
559   mySUntil = Until;
560   Standard_Boolean Trfu = TransformShapeFU(1);
561   ShapeUntilValid();  
562   
563   if(Trfu != Trff) {
564     NotDone();
565     myStatusError = BRepFeat_IncTypes;
566     return;
567   }
568
569   LocOpe_Revol theRevol;
570   theRevol.Perform(myPbase, myAxis, 2*M_PI);
571   TopoDS_Shape VraiRevol = theRevol.Shape();
572
573   MajMap(myPbase,theRevol,myMap,myFShape,myLShape);
574
575   if(!Trff) {    
576     myGShape = VraiRevol;
577     GeneratedShapeValid();
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*M_PI,PrU);
611       Standard_Real pr2 = ASI2.Point(1,ASI2.NbPoints(1)).Parameter();
612       pr2 = ElCLib::InPeriod(pr2,PrU-2*M_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 throughout the initial shape
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.*M_PI);
693 }
694
695 //=======================================================================
696 //function : PerformUntilAngle
697 //purpose  : feature till shape Until defined with the 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 // Produce systematicallt an almost complete revolution
731 //  BRepSweep_Revol theRevol(myPbase,myAxis,2.*M_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     GluedFacesValid();
752     //VerifGluedFaces(mySkface, theBase, myBCurve, myCurves, theRevol, myGluedF);
753
754
755     theRevol.Curves(myCurves);
756     myBCurve = theRevol.BarycCurve();
757     GlobalPerform();
758   }
759   else {
760     TColGeom_SequenceOfCurve scur;
761     theRevol.Curves(myCurves);
762     myBCurve = theRevol.BarycCurve();    
763     scur.Clear();    
764     scur.Append(myBCurve);
765     LocOpe_CSIntersector ASI(mySUntil);
766     ASI.Perform(scur);
767     if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
768       TopAbs_Orientation Or = ASI.Point(1,1).Orientation();
769       TopoDS_Face FUntil = ASI.Point(1,1).Face();
770       TopoDS_Shape Comp;
771       BRep_Builder B;
772       B.MakeCompound(TopoDS::Compound(Comp));
773       TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
774       if (!S.IsNull()) B.Add(Comp,S);
775       //modified by NIZNHY-PKV Thu Mar 21 18:20:14 2002 f
776       //BRepAlgo_Cut trP(VraiRevol,Comp);
777       BRepAlgoAPI_Cut trP(VraiRevol,Comp);
778       //modified by NIZNHY-PKV Thu Mar 21 18:20:19 2002 t
779       TopoDS_Shape Cutsh = trP.Shape();
780       TopExp_Explorer ex(Cutsh, TopAbs_SOLID);
781       for(; ex.More(); ex.Next()) {
782         TopExp_Explorer ex1(ex.Current(), TopAbs_FACE);
783         for(; ex1.More(); ex1.Next()) {
784           const TopoDS_Face& fac = TopoDS::Face(ex1.Current());
785           if(fac.IsSame(myPbase)) {
786             VraiRevol = ex.Current();
787             break;
788           }
789         }
790       }
791       if(myFuse == 1) {
792         //modified by NIZNHY-PKV Thu Mar 21 18:20:36 2002 f
793         //BRepAlgo_Fuse f(mySbase, VraiRevol);
794         //myShape = f.Shape();
795         //UpdateDescendants(f.Builder(), myShape, Standard_False);
796         BRepAlgoAPI_Fuse f(mySbase, VraiRevol);
797         myShape = f.Shape();
798         UpdateDescendants(f, myShape, Standard_False);
799         //modified by NIZNHY-PKV Thu Mar 21 18:20:40 2002 t
800         Done();
801       }
802       else if(myFuse == 0) {
803         //modified by NIZNHY-PKV Thu Mar 21 18:21:07 2002 f
804         //BRepAlgo_Cut c(mySbase, VraiRevol);
805         //myShape = c.Shape();
806         //UpdateDescendants(c.Builder(), myShape, Standard_False);
807         BRepAlgoAPI_Cut c(mySbase, VraiRevol);
808         myShape = c.Shape();
809         UpdateDescendants(c, myShape, Standard_False);
810         //modified by NIZNHY-PKV Thu Mar 21 18:21:26 2002 t
811         Done();
812       }
813       else {
814         myShape = VraiRevol;
815         Done(); 
816       }
817     }         
818   }
819 }
820 //=======================================================================
821 //function : Curves
822 //purpose  : circles parallel to the generating edge of revolution
823 //=======================================================================
824
825 void BRepFeat_MakeRevol::Curves(TColGeom_SequenceOfCurve& scur)
826 {
827   scur = myCurves;
828 }
829
830 //=======================================================================
831 //function : BarycCurve
832 //purpose  : pass through the center of mass of the primitive
833 //=======================================================================
834
835 Handle(Geom_Curve) BRepFeat_MakeRevol::BarycCurve()
836 {
837   return myBCurve;
838 }
839
840 //=======================================================================
841 //function : VerifGluedFaces
842 //purpose  : Check intersection Tool/theSkface = thePbase
843 //           if yes -> OK otherwise -> case without gluing
844 //=======================================================================
845
846 static void VerifGluedFaces(const TopoDS_Face& theSkface,
847                             const TopoDS_Shape& thePbase,
848                             Handle(Geom_Curve)& theBCurve,
849                             TColGeom_SequenceOfCurve& theCurves,
850                             LocOpe_Revol& theRevol,
851                             TopTools_DataMapOfShapeShape& theMap)
852 {
853   Standard_Boolean GluedFaces = Standard_True;
854   TopoDS_Shape VraiRevol = theRevol.Shape();
855   
856   TColGeom_SequenceOfCurve scur;
857   theRevol.Curves(theCurves);
858   theBCurve = theRevol.BarycCurve();    
859   scur.Clear();    
860   scur.Append(theBCurve);
861   LocOpe_CSIntersector ASI(theSkface);
862   ASI.Perform(scur);
863   if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
864     TopAbs_Orientation Or = ASI.Point(1,1).Orientation();
865     TopoDS_Face FSk = ASI.Point(1,1).Face();
866     TopoDS_Shape Comp;
867     BRep_Builder B;
868     B.MakeCompound(TopoDS::Compound(Comp));
869     TopoDS_Solid S = BRepFeat::Tool(theSkface, FSk, Or);
870     if (!S.IsNull()) B.Add(Comp,S);
871     //modified by NIZNHY-PKV Thu Mar 21 18:21:54 2002 f
872     //BRepAlgo_Cut trP(VraiRevol,Comp);
873     BRepAlgoAPI_Cut trP(VraiRevol,Comp);
874     //modified by NIZNHY-PKV Thu Mar 21 18:21:58 2002 t
875     TopoDS_Shape Cutsh = trP.Shape();
876     TopExp_Explorer ex(Cutsh, TopAbs_SOLID);
877     for(; ex.More(); ex.Next()) {
878       TopExp_Explorer ex1(ex.Current(), TopAbs_FACE);
879       for(; ex1.More(); ex1.Next()) {
880         const TopoDS_Face& fac1 = TopoDS::Face(ex1.Current());
881         TopExp_Explorer ex2(thePbase, TopAbs_FACE);
882         for(; ex2.More(); ex2.Next()) {
883           const TopoDS_Face& fac2 = TopoDS::Face(ex2.Current());
884           if(fac1.IsSame(fac2)) break;
885         }
886         if (ex2.More()) break;
887       }
888       if (ex1.More()) continue;
889       GluedFaces = Standard_False;
890       break;
891     }
892     if (!GluedFaces) {
893 #ifdef DEB
894       Standard_Boolean trc = BRepFeat_GettraceFEAT();
895       if (trc) cout << " Intersection Revol/skface : no gluing" << endl;
896 #endif
897       theMap.Clear();
898     }
899   }
900 }
901
902 //=======================================================================
903 //function : MajMap
904 //purpose  : management of descendants
905 //=======================================================================
906
907 static void MajMap(const TopoDS_Shape& theB,
908                    const LocOpe_Revol& theP,
909                    TopTools_DataMapOfShapeListOfShape& theMap, // myMap
910                    TopoDS_Shape& theFShape,  // myFShape
911                    TopoDS_Shape& theLShape) // myLShape
912 {
913   TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
914   if (exp.More()) {
915     theFShape = exp.Current();
916     TopTools_ListOfShape thelist;
917     theMap.Bind(theFShape, thelist);
918     for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
919       theMap(theFShape).Append(exp.Current());
920     }
921   }
922   
923   exp.Init(theP.LastShape(),TopAbs_WIRE);
924   if (exp.More()) {
925     theLShape = exp.Current();
926     TopTools_ListOfShape thelist1;
927     theMap.Bind(theLShape, thelist1);
928     for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
929       theMap(theLShape).Append(exp.Current());
930     }
931   }
932
933   for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
934     if (!theMap.IsBound(exp.Current())) {
935       TopTools_ListOfShape thelist2;
936       theMap.Bind(exp.Current(), thelist2);
937       theMap(exp.Current()) = theP.Shapes(exp.Current());
938     }
939   }
940 }
941
942
943
944 //=======================================================================
945 //function : ToFuse
946 //purpose  : two faces samedomaine or not
947 //=======================================================================
948
949 Standard_Boolean ToFuse(const TopoDS_Face& F1,
950                         const TopoDS_Face& F2)
951 {
952   if (F1.IsNull() || F2.IsNull()) {
953     return Standard_False;
954   }
955
956   Handle(Geom_Surface) S1,S2;
957   TopLoc_Location loc1, loc2;
958   Handle(Standard_Type) typS1,typS2;
959   const Standard_Real tollin = Precision::Confusion();
960   const Standard_Real tolang = Precision::Angular();
961
962   S1 = BRep_Tool::Surface(F1,loc1);
963   S2 = BRep_Tool::Surface(F2,loc2);
964
965   typS1 = S1->DynamicType();
966   typS2 = S2->DynamicType();
967
968   if (typS1 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
969     S1 =  (*((Handle(Geom_RectangularTrimmedSurface)*)&S1))->BasisSurface();
970     typS1 = S1->DynamicType();
971   }
972
973   if (typS2 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
974     S2 =  (*((Handle(Geom_RectangularTrimmedSurface)*)&S2))->BasisSurface();
975     typS2 = S2->DynamicType();
976   }
977
978   if (typS1 != typS2) {
979     return Standard_False;
980   }
981
982
983   Standard_Boolean ValRet = Standard_False;
984   if (typS1 == STANDARD_TYPE(Geom_Plane)) {
985     S1 = BRep_Tool::Surface(F1);  // to apply the location.
986     S2 = BRep_Tool::Surface(F2);
987     gp_Pln pl1( (*((Handle(Geom_Plane)*)&S1))->Pln());
988     gp_Pln pl2( (*((Handle(Geom_Plane)*)&S2))->Pln());
989
990     if (pl1.Position().IsCoplanar(pl2.Position(),tollin,tolang)) {
991       ValRet = Standard_True;
992     }
993   }
994
995   return ValRet;
996 }
997
998
999
1000
1001
1002
1003
1004
1005