0022312: Translation of french commentaries in OCCT files
[occt.git] / src / BRepFeat / BRepFeat_MakePrism.cxx
1 // File:        BRepFeat_MakePrism.cxx
2 // Created:     Tue Feb 13 14:42:59 1996
3 // Author:      Jacques GOUSSARD
4 //              <jag@bravox>
5
6
7 #include <BRepFeat_MakePrism.ixx>
8
9 #include <BRepFeat.hxx>
10 #include <LocOpe.hxx>
11 #include <LocOpe_Prism.hxx>
12 #include <LocOpe_CSIntersector.hxx>
13 #include <LocOpe_PntFace.hxx>
14
15 #include <gp_Vec.hxx>
16 #include <gp_Pnt.hxx>
17 #include <gp_Ax1.hxx>
18 #include <gp_Pnt2d.hxx>
19 #include <Geom_Curve.hxx>
20 #include <Geom_Line.hxx>
21 #include <Geom_RectangularTrimmedSurface.hxx>
22 #include <Geom_Surface.hxx>
23
24 #include <BRepLib_MakeFace.hxx>
25
26 #include <TColgp_SequenceOfPnt.hxx>
27 #include <TColGeom_SequenceOfCurve.hxx>
28 #include <Bnd_Box.hxx>
29
30 #include <BRep_Tool.hxx>
31
32 #include <BRepTools.hxx>
33
34
35 #include <TopExp_Explorer.hxx>
36 #include <TopTools_MapOfShape.hxx>
37 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
38 #include <TopTools_ListIteratorOfListOfShape.hxx>
39 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
40 #include <TopTools_ListIteratorOfListOfShape.hxx>
41 #include <TopTools_ListOfShape.hxx>
42
43 #include <BRepBuilderAPI.hxx>
44 #include <BRepPrimAPI_MakeBox.hxx>
45
46 //modified by NIZNHY-PKV Thu Mar 21 18:14:23 2002 f
47 //#include <BRepAlgo_Cut.hxx>
48 //#include <BRepAlgo_Fuse.hxx>
49 #include <BRepAlgoAPI_Cut.hxx>
50 #include <BRepAlgoAPI_Fuse.hxx>
51 //modified by NIZNHY-PKV Thu Mar 21 18:14:26 2002 t
52
53 #include <Standard_ConstructionError.hxx>
54 #include <TopoDS.hxx>
55
56
57 #include <TopoDS_Face.hxx>
58 #include <TopoDS_Solid.hxx>
59 #include <TopoDS_Compound.hxx>
60
61 #include <TopExp.hxx>
62 #include <BRepBndLib.hxx>
63
64 #include <Precision.hxx>
65 #include <gp_Pln.hxx>
66 #include <Geom_Plane.hxx>
67
68 #ifdef DEB
69 Standard_IMPORT Standard_Boolean BRepFeat_GettraceFEAT();
70 #endif
71
72 static void MajMap(const TopoDS_Shape&, // base
73                    const LocOpe_Prism&,
74                    TopTools_DataMapOfShapeListOfShape&, // myMap
75                    TopoDS_Shape&,  // myFShape
76                    TopoDS_Shape&); // myLShape
77
78 static Standard_Boolean ToFuse(const TopoDS_Face& ,
79                                const TopoDS_Face&);
80
81
82 static void SetGluedFaces(const TopoDS_Face& theSkface,
83                           const TopoDS_Shape& theSbase,
84                           const TopoDS_Shape& thePbase,
85                           const TopTools_DataMapOfShapeListOfShape& theSlmap,
86                           LocOpe_Prism&,
87                           TopTools_DataMapOfShapeShape&);
88
89 #ifdef DEB
90 static void VerifGluedFaces(const TopoDS_Face& theSkface,
91                             const TopoDS_Shape& thePbase,
92                             Handle(Geom_Curve)& theBCurve,
93                             TColGeom_SequenceOfCurve& theCurves,
94                             LocOpe_Prism& thePrism,
95                             TopTools_DataMapOfShapeShape& theMap);
96 #endif
97
98 static Standard_Real HeightMax(const TopoDS_Shape& theSbase,
99                                const TopoDS_Face& theSkface,
100                                const TopoDS_Shape& theSFrom,
101                                const TopoDS_Shape& theSUntil);
102
103 static Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
104                                     const TopoDS_Shape& Until);
105
106 static Handle(Geom_Curve) TestCurve(const TopoDS_Shape&,
107                                     const gp_Vec&);
108
109
110 //=======================================================================
111 //function : Init
112 //purpose  : 
113 //=======================================================================
114
115 void BRepFeat_MakePrism::Init(const TopoDS_Shape& Sbase,
116                               const TopoDS_Shape& Pbase,
117                               const TopoDS_Face& Skface,
118                               const gp_Dir& Direc,
119                               const Standard_Integer Mode,
120                               const Standard_Boolean Modify)
121 {
122 #ifdef DEB
123   Standard_Boolean trc = BRepFeat_GettraceFEAT();
124   if (trc) cout << "BRepFeat_MakePrism::Init" << endl;
125 #endif
126   mySkface = Skface;
127   SketchFaceValid();
128   mySbase  = Sbase;
129   BasisShapeValid();
130   myPbase  = Pbase;
131   mySlface.Clear();
132   myDir    = Direc;
133   if(Mode == 0) {
134     myFuse   = Standard_False;
135     myJustFeat = Standard_False;
136   }
137   else if(Mode == 1) {
138     myFuse   = Standard_True;
139     myJustFeat = Standard_False;
140   }
141   else if(Mode == 2) {
142     myFuse   = Standard_True;
143     myJustFeat = Standard_True;
144   }
145   else {    
146   }
147   myModify = Modify;
148   myJustGluer = Standard_False;
149
150
151   //-------------- ifv
152   //mySkface.Nullify();
153   //-------------- ifv
154
155
156   myShape.Nullify();
157   myNewEdges.Clear();
158   myTgtEdges.Clear();
159   myMap.Clear();
160   myFShape.Nullify();
161   myLShape.Nullify();
162   TopExp_Explorer exp;
163   for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
164     TopTools_ListOfShape thelist;
165     myMap.Bind(exp.Current(), thelist);
166     myMap(exp.Current()).Append(exp.Current());
167   }
168 #ifdef DEB
169   if (trc) {
170     if (myJustFeat)  cout << " Just Feature" << endl;
171     if (myFuse)  cout << " Fuse" << endl;
172     if (!myFuse)  cout << " Cut" << endl;
173     if (!myModify) cout << " Modify = 0" << endl;
174   }
175 #endif 
176 }
177
178
179 //=======================================================================
180 //function : Add
181 //purpose  : add elements of sliding (edge on face)
182 //=======================================================================
183
184 void BRepFeat_MakePrism::Add(const TopoDS_Edge& E,
185                              const TopoDS_Face& F)
186 {
187 #ifdef DEB
188   Standard_Boolean trc = BRepFeat_GettraceFEAT();
189   if (trc) cout << "BRepFeat_MakePrism::Add(Edge,face)" << endl;
190 #endif
191   TopExp_Explorer exp;
192   for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
193     if (exp.Current().IsSame(F)) {
194       break;
195     }
196   }
197   if (!exp.More()) {
198     Standard_ConstructionError::Raise();
199   }
200   
201   for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
202     if (exp.Current().IsSame(E)) {
203       break;
204     }
205   }
206   if (!exp.More()) {
207     Standard_ConstructionError::Raise();
208   }
209   
210   if (!mySlface.IsBound(F)) {
211     TopTools_ListOfShape thelist1;
212     mySlface.Bind(F, thelist1);
213   }
214   TopTools_ListIteratorOfListOfShape itl(mySlface(F));
215   for (; itl.More();itl.Next()) {
216     if (itl.Value().IsSame(E)) {
217       break;
218     }
219   }
220   if (!itl.More()) {
221     mySlface(F).Append(E);
222   }
223 }
224
225
226 //=======================================================================
227 //function : Perform
228 //purpose  : construction of prism of length Length and 
229 //           call of reconstruction topo
230 //=======================================================================
231
232 void BRepFeat_MakePrism::Perform(const Standard_Real Length)
233 {
234 #ifdef DEB
235   Standard_Boolean trc = BRepFeat_GettraceFEAT();
236   if (trc) cout << "BRepFeat_MakePrism::Perform(Length)" << endl;
237 #endif
238   mySFrom.Nullify();
239   ShapeFromValid();
240   mySUntil.Nullify();
241   ShapeUntilValid();
242   myGluedF.Clear();
243   myPerfSelection = BRepFeat_NoSelection;
244   PerfSelectionValid();
245   gp_Vec V(Length*myDir);
246   
247 //construction of prism of height Length
248
249   LocOpe_Prism thePrism(myPbase,V);
250   TopoDS_Shape VraiPrism = thePrism.Shape();
251   
252 // management of descendants
253   MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
254   
255
256   myGShape = VraiPrism;    // the primitive
257   GeneratedShapeValid();
258   
259   TopoDS_Face FFace;
260   
261   Standard_Boolean found = Standard_False;
262
263 // try to detect the faces of gluing 
264 // in case if the top of the prism is tangent to the initial shape
265
266   if(!mySkface.IsNull() || !mySlface.IsEmpty()) {
267     if(myLShape.ShapeType() == TopAbs_WIRE) {
268       TopExp_Explorer ex1(VraiPrism, TopAbs_FACE);
269       for(; ex1.More(); ex1.Next()) {
270         TopExp_Explorer ex2(ex1.Current(), TopAbs_WIRE);
271         for(; ex2.More(); ex2.Next()) {
272           if(ex2.Current().IsSame(myLShape)) {
273             FFace = TopoDS::Face(ex1.Current());
274             found = Standard_True;
275             break;
276           }
277         }
278         if(found) break;
279       }
280     }
281     
282     TopExp_Explorer exp(mySbase, TopAbs_FACE);
283     for(; exp.More(); exp.Next()) {
284       const TopoDS_Face& ff = TopoDS::Face(exp.Current());
285       if(ToFuse(ff, FFace)) {
286         TopTools_DataMapOfShapeListOfShape sl;
287         if(!FFace.IsSame(myPbase) && BRepFeat::IsInside(ff, FFace)) 
288 //        SetGluedFaces(ff, mySbase, FFace, sl, thePrism, myGluedF);
289         break;
290       }
291     }
292   }
293
294 // management of faces of gluing given by the user
295
296 //  SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePrism, myGluedF);
297   GluedFacesValid();
298 //  VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
299
300   if(!myGluedF.IsEmpty()) {   // case gluing
301     myJustGluer = Standard_True;
302     thePrism.Curves(myCurves);
303     myBCurve = thePrism.BarycCurve();    
304     GlobalPerform();  // topological reconstruction 
305   }
306
307 // if there is no gluing  -> call of ope topo
308   if(!myJustGluer) {
309     if(myFuse == 1 && !myJustFeat) {
310       //modified by NIZNHY-PKV Thu Mar 21 17:55:30 2002 f
311       //BRepAlgo_Fuse f(mySbase, myGShape);
312       //myShape = f.Shape();
313       //UpdateDescendants(f.Builder(), myShape, Standard_False);
314       BRepAlgoAPI_Fuse f(mySbase, myGShape);
315       myShape = f.Shape();
316       UpdateDescendants(f, myShape, Standard_False);
317       //modified by NIZNHY-PKV Thu Mar 21 17:55:34 2002 t
318       Done();
319     }
320     else if(myFuse == 0) {
321       //modified by NIZNHY-PKV Thu Mar 21 17:55:59 2002 f
322       //BRepAlgo_Cut c(mySbase, myGShape);
323       //myShape = c.Shape();
324       //UpdateDescendants(c.Builder(), myShape, Standard_False);
325       BRepAlgoAPI_Cut c(mySbase, myGShape);
326       myShape = c.Shape();
327       UpdateDescendants(c, myShape, Standard_False);
328       //modified by NIZNHY-PKV Thu Mar 21 17:56:02 2002 t
329       Done();
330     }
331     else {
332       myShape = myGShape;
333       Done();
334     }
335   }
336 }
337
338
339 //=======================================================================
340 //function : Perform
341 //purpose  : construction of prism oriented at the face Until, sufficiently 
342 //           long; call of topological reconstruction          
343 //=======================================================================
344
345 void BRepFeat_MakePrism::Perform(const TopoDS_Shape& Until)
346 {
347 #ifdef DEB
348   Standard_Boolean trc = BRepFeat_GettraceFEAT();
349   if (trc) cout << "BRepFeat_MakePrism::Perform(Until)" << endl;
350 #endif
351   if (Until.IsNull()) {
352     Standard_ConstructionError::Raise();
353   }
354   TopExp_Explorer exp(Until, TopAbs_FACE);
355   if (!exp.More()) {
356     Standard_ConstructionError::Raise();
357   }
358   myGluedF.Clear();
359   myPerfSelection = BRepFeat_SelectionU;
360   PerfSelectionValid();
361   mySFrom.Nullify();
362   ShapeFromValid();
363   mySUntil = Until;
364   Standard_Boolean Trf = TransformShapeFU(1);  
365   ShapeUntilValid();
366   Handle(Geom_Curve) C = TestCurve(myPbase,myDir);  
367   Standard_Integer sens = SensOfPrism(C, mySUntil);
368   Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
369   gp_Vec V(2*sens*Height*myDir);
370
371 // construction of long prism
372   LocOpe_Prism thePrism(myPbase,V);
373   TopoDS_Shape VraiPrism = thePrism.Shape();
374
375 // in case of support of face Until
376   if(!Trf) {    
377     MajMap(myPbase,thePrism,myMap,myFShape,myLShape);    
378     myGShape = VraiPrism;
379     GeneratedShapeValid();
380
381     //SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePrism, myGluedF);
382     GluedFacesValid();
383 //    VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
384
385     thePrism.Curves(myCurves);
386     myBCurve = thePrism.BarycCurve();
387     GlobalPerform();
388   }
389   else {    // until support -> passage to topological operations
390     MajMap(myPbase,thePrism,myMap,myFShape,myLShape);    
391     TColGeom_SequenceOfCurve scur;
392     scur.Clear();    
393     scur.Append(C);
394
395 // direction of the prism depending on Until
396
397     LocOpe_CSIntersector ASI(mySUntil);
398     ASI.Perform(scur);
399     TopAbs_Orientation Or;
400     if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
401       if (myFuse == 1) {
402         Or = ASI.Point(1,1).Orientation();
403       }
404       else {
405         Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
406       }
407       if(sens==-1) Or=TopAbs::Reverse(Or);
408       TopoDS_Face FUntil = ASI.Point(1,1).Face();
409       TopoDS_Shape Comp;
410       BRep_Builder B;
411       B.MakeCompound(TopoDS::Compound(Comp));
412       TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
413       if (!S.IsNull()) B.Add(Comp,S);
414       //modified by NIZNHY-PKV Thu Mar 21 17:56:31 2002 f
415       //BRepAlgo_Cut trP(VraiPrism,Comp);
416       //UpdateDescendants(trP.Builder(),trP.Shape(), Standard_False);
417       BRepAlgoAPI_Cut trP(VraiPrism,Comp);
418       UpdateDescendants(trP, trP.Shape(), Standard_False);
419       //modified by NIZNHY-PKV Thu Mar 21 17:56:38 2002 t
420       TopExp_Explorer ex(trP.Shape(), TopAbs_SOLID);
421       TopoDS_Shape Cutsh = ex.Current();
422       if(myFuse == 1 && !myJustFeat) {
423         //modified by NIZNHY-PKV Thu Mar 21 17:57:49 2002 f
424         //BRepAlgo_Fuse f(mySbase, Cutsh);
425         //myShape = f.Shape();
426         //UpdateDescendants(f.Builder(), myShape, Standard_False);
427         BRepAlgoAPI_Fuse f(mySbase, Cutsh);
428         myShape = f.Shape();
429         UpdateDescendants(f, myShape, Standard_False);
430         //modified by NIZNHY-PKV Thu Mar 21 17:57:53 2002 t
431         Done();
432       }
433       else if(myFuse == 0) {
434         //modified by NIZNHY-PKV Thu Mar 21 17:59:33 2002 f
435         //BRepAlgo_Cut c(mySbase, Cutsh);
436         //myShape = c.Shape();
437         //UpdateDescendants(c.Builder(), myShape, Standard_False);
438         BRepAlgoAPI_Cut c(mySbase, Cutsh);
439         myShape = c.Shape();
440         UpdateDescendants(c, myShape, Standard_False);
441         //modified by NIZNHY-PKV Thu Mar 21 17:59:43 2002 t
442         Done();
443       }
444       else {
445         myShape = Cutsh;
446         Done(); 
447       }
448     }         
449   }
450 /*   // loop of control of descendance
451
452   TopExp_Explorer expr(mySbase, TopAbs_FACE);
453   char nom1[20], nom2[20];
454   Standard_Integer ii = 0;
455   for(; expr.More(); expr.Next()) {
456     ii++;
457     sprintf(nom1, "faceinitial_%d", ii);
458     DBRep::Set(nom1, expr.Current());
459     Standard_Integer jj = 0;
460     const TopTools_ListOfShape& list = Modified(expr.Current());
461     TopTools_ListIteratorOfListOfShape ite(list);
462     for(; ite.More(); ite.Next()) {
463       jj++;
464       sprintf(nom2, "facemodifie_%d_%d", ii, jj);
465       DBRep::Set(nom2, ite.Value());
466     }
467   }
468
469   expr.Init(myPbase, TopAbs_EDGE);
470   ii=0;
471   for(; expr.More(); expr.Next()) {
472     ii++;
473     sprintf(nom1, "edgeinitial_%d", ii);
474     DBRep::Set(nom1, expr.Current());
475     Standard_Integer jj = 0;
476     const TopTools_ListOfShape& list = Generated(expr.Current());
477     TopTools_ListIteratorOfListOfShape ite(list);
478     for(; ite.More(); ite.Next()) {
479       jj++;
480       sprintf(nom2, "facegeneree_%d_%d", ii, jj);
481       DBRep::Set(nom2, ite.Value());
482     }
483   }
484 */
485 }
486
487
488 //=======================================================================
489 //function : Perform
490 //purpose  : construction of a sufficiently long and properly oriented prism
491 //           call of topological reconstruction
492 //=======================================================================
493
494 void BRepFeat_MakePrism::Perform(const TopoDS_Shape& From,
495                                  const TopoDS_Shape& Until)
496 {
497 #ifdef DEB
498   Standard_Boolean trc = BRepFeat_GettraceFEAT();
499   if (trc) cout << "BRepFeat_MakePrism::Perform(From,Until)" << endl;
500 #endif
501   if (From.IsNull() || Until.IsNull()) {
502     Standard_ConstructionError::Raise();
503   }
504
505   if (!mySkface.IsNull()) {
506     if (From.IsSame(mySkface)) {
507       myJustGluer = Standard_True;
508       Perform(Until);
509       if (myJustGluer) return;
510     }
511     else if (Until.IsSame(mySkface)) {
512       myJustGluer = Standard_True;
513       Perform(From);
514       if (myJustGluer) return;
515     } 
516   }
517   
518   myGluedF.Clear();
519   myPerfSelection = BRepFeat_SelectionFU;
520   PerfSelectionValid();
521   
522   TopExp_Explorer exp(From, TopAbs_FACE);
523   if (!exp.More()) {
524     Standard_ConstructionError::Raise();
525   }
526   exp.Init(Until, TopAbs_FACE);
527   if (!exp.More()) {
528     Standard_ConstructionError::Raise();
529   }
530   mySFrom = From;
531   Standard_Boolean Trff = TransformShapeFU(0);
532   ShapeFromValid();
533   mySUntil = Until;
534   Standard_Boolean Trfu = TransformShapeFU(1);
535   ShapeUntilValid();  
536   if(Trfu != Trff) {
537     NotDone();
538     myStatusError = BRepFeat_IncTypes;
539     return;
540   }
541
542 // length depending on bounding boxes
543
544   Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
545   Handle(Geom_Curve) C = TestCurve(myPbase,myDir);  
546   Standard_Integer sens;  // direction of prism
547   Standard_Integer tran;  // transfer of prism
548   if(From.IsSame(Until)) {
549     sens = 1;
550     tran = -1;
551   }
552   else {
553     sens = SensOfPrism(C, mySUntil);
554     tran = sens*SensOfPrism(C, mySFrom);
555   }
556   LocOpe_Prism thePrism;   
557   if(tran < 0) {
558     gp_Vec Vtra(-3*Height*sens/2.*myDir);
559     thePrism.Perform(myPbase,3*sens*Height*myDir,Vtra);
560   }
561   else {
562     thePrism.Perform(myPbase,2*sens*Height*myDir);
563   }
564   TopoDS_Shape VraiPrism = thePrism.Shape();
565   
566   if(!Trff) {
567     MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
568     
569     myGShape = VraiPrism;
570     GeneratedShapeValid();
571
572     //SetGluedFaces(TopoDS_Face(), // on ne veut pas binder mySkface
573         //        mySbase, myPbase, mySlface, thePrism, myGluedF);
574     GluedFacesValid();
575 ////    VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
576
577     thePrism.Curves(myCurves);
578     myBCurve = thePrism.BarycCurve();
579     GlobalPerform();
580   }
581   else {    // case until support -> topological operation
582     MajMap(myPbase,thePrism,myMap,myFShape,myLShape);    
583     TColGeom_SequenceOfCurve scur;
584     scur.Clear();    
585     scur.Append(C);
586     LocOpe_CSIntersector ASI1(mySUntil);
587     LocOpe_CSIntersector ASI2(mySFrom);
588     ASI1.Perform(scur);
589     ASI2.Perform(scur);
590     TopAbs_Orientation OrU, OrF;
591     TopoDS_Face FFrom, FUntil;
592     if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
593       if (myFuse == 1) {
594         OrU = ASI1.Point(1,1).Orientation();
595       }
596       else {
597         OrU = ASI1.Point(1,ASI1.NbPoints(1)).Orientation();
598       }
599       if(sens==-1) OrU = TopAbs::Reverse(OrU);
600       FUntil = ASI1.Point(1,1).Face();
601     }
602     else {
603       NotDone();
604       myStatusError = BRepFeat_NoIntersectU;
605       return;
606     }
607     if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
608       OrF = ASI2.Point(1,1).Orientation();
609       if(sens==1) OrF = TopAbs::Reverse(OrF);
610       FFrom = ASI2.Point(1,1).Face();
611     }
612     else {
613       NotDone();
614       myStatusError = BRepFeat_NoIntersectF;
615       return;
616     }
617     TopoDS_Shape Comp;
618     BRep_Builder B;
619     B.MakeCompound(TopoDS::Compound(Comp));
620     TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, OrU);
621     if (!S.IsNull()) {
622       B.Add(Comp,S);
623     }
624     else {
625       NotDone();
626       myStatusError = BRepFeat_NullToolU;
627       return;
628     }
629     TopoDS_Solid SS = BRepFeat::Tool(mySFrom, FFrom, OrF);
630     if (!SS.IsNull()) {
631       B.Add(Comp,SS);
632     }
633     else {
634       NotDone();
635       myStatusError = BRepFeat_NullToolF;
636       return;
637     }
638     //modified by NIZNHY-PKV Thu Mar 21 18:00:10 2002 f
639     //BRepAlgo_Cut trP(VraiPrism,Comp);
640     //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
641     BRepAlgoAPI_Cut trP(VraiPrism,Comp);
642     UpdateDescendants(trP, trP.Shape(), Standard_False);
643     //modified by NIZNHY-PKV Thu Mar 21 18:00:16 2002 t
644     if(myFuse == 1 && !myJustFeat) {
645       //modified by NIZNHY-PKV Thu Mar 21 18:00:35 2002 f
646       //BRepAlgo_Fuse f(mySbase, trP.Shape());
647       //myShape = f.Shape();
648       //UpdateDescendants(f.Builder(), myShape, Standard_False);
649       BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
650       myShape = f.Shape();
651       UpdateDescendants(f, myShape, Standard_False);
652       //modified by NIZNHY-PKV Thu Mar 21 18:00:40 2002 t
653       Done();
654     }
655     else if(myFuse == 0) {
656       //modified by NIZNHY-PKV Thu Mar 21 18:01:01 2002 f
657       //BRepAlgo_Cut c(mySbase, trP.Shape());
658       //myShape = c.Shape();
659       //UpdateDescendants(c.Builder(), myShape, Standard_False);
660       BRepAlgoAPI_Cut c(mySbase, trP.Shape());
661       myShape = c.Shape();
662       UpdateDescendants(c, myShape, Standard_False);
663       //modified by NIZNHY-PKV Thu Mar 21 18:01:13 2002 t
664       Done();
665     }
666     else {
667       myShape = trP.Shape();
668       Done();   
669     }
670   }         
671 // control history
672 /*
673   TopExp_Explorer expr(mySbase, TopAbs_FACE);
674   char nom1[20], nom2[20];
675   Standard_Integer ii = 0;
676   for(; expr.More(); expr.Next()) {
677     ii++;
678     sprintf(nom1, "faceinitial_%d", ii);
679     DBRep::Set(nom1, expr.Current());
680     Standard_Integer jj = 0;
681     const TopTools_ListOfShape& list = Modified(expr.Current());
682     TopTools_ListIteratorOfListOfShape ite(list);
683     for(; ite.More(); ite.Next()) {
684       jj++;
685       sprintf(nom2, "facemodifie_%d_%d", ii, jj);
686       DBRep::Set(nom2, ite.Value());
687     }
688   }
689
690   expr.Init(myPbase, TopAbs_EDGE);
691   ii=0;
692   for(; expr.More(); expr.Next()) {
693     ii++;
694     sprintf(nom1, "edgeinitial_%d", ii);
695     DBRep::Set(nom1, expr.Current());
696     Standard_Integer jj = 0;
697     const TopTools_ListOfShape& list = Generated(expr.Current());
698     TopTools_ListIteratorOfListOfShape ite(list);
699     for(; ite.More(); ite.Next()) {
700       jj++;
701       sprintf(nom2, "egdegeneree_%d_%d", ii, jj);
702       DBRep::Set(nom2, ite.Value());
703     }
704   }
705 */
706 }
707
708
709
710 //=======================================================================
711 //function : PerformUntilEnd
712 //purpose  : construction of a prism and reconstruction
713 //=======================================================================
714
715 void BRepFeat_MakePrism::PerformUntilEnd()
716 {
717 #ifdef DEB
718   Standard_Boolean trc = BRepFeat_GettraceFEAT();
719   if (trc) cout << "BRepFeat_MakePrism::PerformUntilEnd()" << endl;
720 #endif
721   myPerfSelection = BRepFeat_SelectionSh;
722   PerfSelectionValid();
723   myGluedF.Clear();
724   mySUntil.Nullify();
725   ShapeUntilValid();
726   mySFrom.Nullify();
727   ShapeFromValid();
728   Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
729   gp_Vec V(2*Height*myDir);
730   
731   LocOpe_Prism thePrism(myPbase,V);
732   TopoDS_Shape VraiPrism = thePrism.Shape();
733   
734   MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
735   
736   myGShape = VraiPrism;
737   GeneratedShapeValid();
738   GluedFacesValid();
739
740   if(myFuse == 0) {
741     //modified by NIZNHY-PKV Thu Mar 21 18:02:46 2002 f
742     //BRepAlgo_Cut c(mySbase, myGShape);
743     BRepAlgoAPI_Cut c(mySbase, myGShape);
744     //modified by NIZNHY-PKV Thu Mar 21 18:03:15 2002 t
745     if (c.IsDone()) {
746       myShape = c.Shape();
747       //modified by NIZNHY-PKV Thu Mar 21 18:03:38 2002 f
748       //UpdateDescendants(c.Builder(), myShape, Standard_False);
749       UpdateDescendants(c, myShape, Standard_False);
750       //modified by NIZNHY-PKV Thu Mar 21 18:03:42 2002 t
751       Done();
752     }
753   }
754   else {
755     thePrism.Curves(myCurves);
756     myBCurve = thePrism.BarycCurve();
757     GlobalPerform();
758   }
759 }
760
761 //=======================================================================
762 //function : PerformFromEnd
763 //purpose  : 
764 //=======================================================================
765
766 void BRepFeat_MakePrism::PerformFromEnd(const TopoDS_Shape& Until)
767 {
768 #ifdef DEB
769   Standard_Boolean trc = BRepFeat_GettraceFEAT();
770   if (trc) cout << "BRepFeat_MakePrism::PerformFromEnd(From,Until)" << endl;
771 #endif
772   if (Until.IsNull()) {
773     Standard_ConstructionError::Raise();
774   }
775   if (!mySkface.IsNull() && Until.IsSame(mySkface)) {
776     myDir.Reverse();
777     PerformUntilEnd();
778     return;
779   }
780   TopExp_Explorer exp;
781   exp.Init(Until, TopAbs_FACE);
782   if (!exp.More()) {
783     Standard_ConstructionError::Raise();
784   }
785   myPerfSelection = BRepFeat_SelectionShU;
786   PerfSelectionValid();
787   mySFrom.Nullify();
788   ShapeFromValid();
789   mySUntil = Until;
790   Standard_Boolean Trf = TransformShapeFU(1);
791   ShapeUntilValid();
792   Handle(Geom_Curve) C = TestCurve(myPbase,myDir);  
793   Standard_Integer sens = SensOfPrism(C, mySUntil);
794   Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
795   gp_Vec Vtra(-3*Height*sens/2.*myDir);
796   gp_Vec Vect(3*sens*Height*myDir);
797   LocOpe_Prism thePrism(myPbase,Vect,Vtra);
798   TopoDS_Shape VraiPrism = thePrism.Shape();
799   
800   if(!Trf) {  // case face until 
801     MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
802     myGShape = VraiPrism;
803     GeneratedShapeValid();
804     myGluedF.Clear();
805     GluedFacesValid();
806     thePrism.Curves(myCurves);
807     myBCurve = thePrism.BarycCurve();
808     GlobalPerform();
809   }
810   else {   // case support
811     MajMap(myPbase,thePrism,myMap,myFShape,myLShape);    
812     TColGeom_SequenceOfCurve scur;
813     scur.Clear();    
814     scur.Append(C);
815     LocOpe_CSIntersector ASI1(mySUntil);
816     LocOpe_CSIntersector ASI2(mySbase);
817     ASI1.Perform(scur);
818     ASI2.Perform(scur);
819 #ifndef DEB
820     TopAbs_Orientation OrU = TopAbs_FORWARD, OrF = TopAbs_FORWARD;
821 #else
822     TopAbs_Orientation OrU, OrF;
823 #endif
824     TopoDS_Face FUntil, FFrom;
825     if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
826       OrU = ASI1.Point(1,1).Orientation();
827       if(sens==-1) {
828         OrU = TopAbs::Reverse(OrU);
829       }
830       FUntil = ASI1.Point(1,1).Face();
831     }
832     if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
833       OrF = ASI2.Point(1,1).Orientation();
834 //      if(sens==1) OrF = TopAbs::Reverse(OrF);
835       FFrom = ASI2.Point(1 ,1).Face();
836       Handle(Geom_Surface) S = BRep_Tool::Surface(FFrom);
837       if (S->DynamicType() == 
838           STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
839         S = Handle(Geom_RectangularTrimmedSurface)::
840           DownCast(S)->BasisSurface();
841       }
842       BRepLib_MakeFace fac(S, Precision::Confusion());
843       mySFrom = fac.Face();  
844       Trf = TransformShapeFU(0);
845       FFrom = TopoDS::Face(mySFrom);
846     }
847 //    else {
848 //      NotDone();
849 //      return;
850 //    }
851     TopoDS_Shape Comp;
852     BRep_Builder B;
853     B.MakeCompound(TopoDS::Compound(Comp));
854     TopoDS_Solid Sol = BRepFeat::Tool(mySUntil, FUntil, OrU);
855     if (!Sol.IsNull()) {
856       B.Add(Comp,Sol);
857     }
858     else {
859       NotDone();
860       myStatusError = BRepFeat_NullToolU;
861       return;
862     }
863
864     TopoDS_Solid Sol1 = BRepFeat::Tool(mySFrom, FFrom, OrF);
865     if (!Sol1.IsNull()) {
866       B.Add(Comp,Sol1);
867     }
868     else {
869       NotDone();
870       myStatusError = BRepFeat_NullToolF;
871       return;
872     }
873     //modified by NIZNHY-PKV Thu Mar 21 18:03:57 2002 f
874     //BRepAlgo_Cut trP(VraiPrism,Comp);
875     //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
876     BRepAlgoAPI_Cut trP(VraiPrism,Comp);
877     UpdateDescendants(trP, trP.Shape(), Standard_False);
878     //modified by NIZNHY-PKV Thu Mar 21 18:04:08 2002 t
879     if(myFuse == 1 && !myJustFeat) {
880       //modified by NIZNHY-PKV Thu Mar 21 18:04:33 2002 f
881       //BRepAlgo_Fuse f(mySbase, trP.Shape());
882       //myShape = f.Shape();
883       //UpdateDescendants(f.Builder(), myShape, Standard_False);
884       BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
885       myShape = f.Shape();
886       UpdateDescendants(f, myShape, Standard_False);
887       //modified by NIZNHY-PKV Thu Mar 21 18:04:41 2002 t
888       Done();
889     }
890     else if(myFuse == 0) {
891       //modified by NIZNHY-PKV Thu Mar 21 18:04:54 2002 f
892       //BRepAlgo_Cut c(mySbase, trP.Shape());
893       //myShape = c.Shape();
894       //UpdateDescendants(c.Builder(), myShape, Standard_False);
895       BRepAlgoAPI_Cut c(mySbase, trP.Shape());
896       myShape = c.Shape();
897       UpdateDescendants(c, myShape, Standard_False);
898       //modified by NIZNHY-PKV Thu Mar 21 18:05:00 2002 t
899       Done();
900     }
901     else {
902       myShape = trP.Shape();
903       Done();   
904     }
905   }         
906 }
907
908
909
910 //=======================================================================
911 //function : PerformThruAll
912 //purpose  : 
913 //=======================================================================
914
915 void BRepFeat_MakePrism::PerformThruAll()
916 {
917 #ifdef DEB
918   Standard_Boolean trc = BRepFeat_GettraceFEAT();
919   if (trc) cout << "BRepFeat_MakePrism::PerformThruAll()" << endl;
920 #endif
921   mySUntil.Nullify();
922   ShapeUntilValid();
923   mySFrom.Nullify();
924   ShapeFromValid();
925   if(myFuse == 0) {
926     myPerfSelection = BRepFeat_NoSelection;
927   }
928   else {
929     myPerfSelection = BRepFeat_SelectionSh;
930   }
931   PerfSelectionValid();
932   myGluedF.Clear();
933   GluedFacesValid();
934
935   Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
936   gp_Vec V(3*Height*myDir);
937   gp_Vec Vtra(-3*Height/2.*myDir);
938   LocOpe_Prism thePrism(myPbase,V,Vtra);
939   TopoDS_Shape VraiPrism = thePrism.Shape();
940   MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
941
942   myGShape = VraiPrism;
943   GeneratedShapeValid();  
944
945   if(myFuse == 0) {
946     //modified by NIZNHY-PKV Thu Mar 21 18:05:31 2002 f
947     //BRepAlgo_Cut c(mySbase, myGShape);
948     BRepAlgoAPI_Cut c(mySbase, myGShape);
949     //modified by NIZNHY-PKV Thu Mar 21 18:05:33 2002 t
950     if (c.IsDone()) {
951       myShape = c.Shape();
952       //modified by NIZNHY-PKV Thu Mar 21 18:05:46 2002 f
953       //UpdateDescendants(c.Builder(), myShape, Standard_False);
954       UpdateDescendants(c, myShape, Standard_False);
955       //modified by NIZNHY-PKV Thu Mar 21 18:05:50 2002 t
956       Done();
957     }
958   }
959   else {
960     thePrism.Curves(myCurves);
961     myBCurve = thePrism.BarycCurve();
962     GlobalPerform();
963   }
964 }
965
966
967 //=======================================================================
968 //function : PerformUntilHauteur
969 //purpose  : 
970 //=======================================================================
971
972 void BRepFeat_MakePrism::PerformUntilHeight(const TopoDS_Shape& Until,
973                                              const Standard_Real Length)
974 {
975 #ifdef DEB
976   Standard_Boolean trc = BRepFeat_GettraceFEAT();
977   if (trc) cout << "BRepFeat_MakePrism::PerformUntilHeight(Until,Length)" << endl;
978 #endif
979   if (Until.IsNull()) {
980     Perform(Length);
981   }
982   if(Length == 0) {
983     Perform(Until);
984   }
985   TopExp_Explorer exp(Until, TopAbs_FACE);
986   if (!exp.More()) {
987     Standard_ConstructionError::Raise();
988   }
989   myGluedF.Clear();
990   myPerfSelection = BRepFeat_NoSelection;
991   PerfSelectionValid();
992   mySFrom.Nullify();
993   ShapeFromValid();
994   mySUntil = Until;
995   Standard_Boolean Trf = TransformShapeFU(1);
996   ShapeUntilValid();
997   Handle(Geom_Curve) C = TestCurve(myPbase,myDir);  
998   Standard_Integer sens = SensOfPrism(C, mySUntil);
999   gp_Vec V(sens*Length*myDir);
1000   LocOpe_Prism thePrism(myPbase,V);
1001   TopoDS_Shape VraiPrism = thePrism.Shape();
1002
1003   if(!Trf) {
1004     MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
1005     
1006     myGShape = VraiPrism;
1007     GeneratedShapeValid();
1008
1009     //SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePrism, myGluedF);
1010     GluedFacesValid();
1011 //    VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
1012
1013     thePrism.Curves(myCurves);
1014     myBCurve = thePrism.BarycCurve();
1015     GlobalPerform();
1016   }
1017   else {
1018     MajMap(myPbase,thePrism,myMap,myFShape,myLShape);    
1019     TColGeom_SequenceOfCurve scur;
1020     scur.Clear();    
1021     scur.Append(C);
1022     LocOpe_CSIntersector ASI(mySUntil);
1023     ASI.Perform(scur);
1024     TopAbs_Orientation Or;
1025     if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
1026       if (myFuse == 1) {
1027         Or = ASI.Point(1,1).Orientation();
1028       }
1029       else {
1030         Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
1031       }
1032       if(sens==-1) Or=TopAbs::Reverse(Or);
1033       TopoDS_Face FUntil = ASI.Point(1,1).Face();
1034       TopoDS_Shape Comp;
1035       BRep_Builder B;
1036       B.MakeCompound(TopoDS::Compound(Comp));
1037       TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
1038       if (!S.IsNull()) B.Add(Comp,S);
1039
1040       //modified by NIZNHY-PKV Thu Mar 21 18:06:09 2002 f
1041       //BRepAlgo_Cut trP(VraiPrism,Comp);
1042       //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
1043       BRepAlgoAPI_Cut trP(VraiPrism,Comp);
1044       UpdateDescendants(trP, trP.Shape(), Standard_False);
1045       //modified by NIZNHY-PKV Thu Mar 21 18:06:15 2002 t
1046       if(myFuse == 1 && !myJustFeat) {
1047         //modified by NIZNHY-PKV Thu Mar 21 18:06:36 2002 f
1048         //BRepAlgo_Fuse f(mySbase, trP.Shape());
1049         //myShape = f.Shape();
1050         //UpdateDescendants(f.Builder(), myShape, Standard_False);
1051         BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
1052         myShape = f.Shape();
1053         UpdateDescendants(f, myShape, Standard_False);
1054         //modified by NIZNHY-PKV Thu Mar 21 18:06:41 2002 t
1055         Done();
1056       }
1057       else if(myFuse == 0) {
1058         //modified by NIZNHY-PKV Thu Mar 21 18:07:06 2002 f
1059         //BRepAlgo_Cut c(mySbase, trP.Shape());
1060         //myShape = c.Shape();
1061         //UpdateDescendants(c.Builder(), myShape, Standard_False);
1062         BRepAlgoAPI_Cut c(mySbase, trP.Shape());
1063         myShape = c.Shape();
1064         UpdateDescendants(c, myShape, Standard_False);
1065         //modified by NIZNHY-PKV Thu Mar 21 18:07:12 2002 t
1066         Done();
1067       }
1068       else {
1069         myShape = trP.Shape();
1070         Done(); 
1071       }
1072     }         
1073   }
1074 }
1075
1076 //=======================================================================
1077 //function : Curves
1078 //purpose  : sequence of curves parallel to the axis of prism 
1079 //=======================================================================
1080
1081 void BRepFeat_MakePrism::Curves(TColGeom_SequenceOfCurve& scur)
1082 {
1083   scur = myCurves;
1084 }
1085
1086 //=======================================================================
1087 //function : BarycCurve
1088 //purpose  : curve parallel to the axis of the prism passing through the center  
1089 //           of masses
1090 //=======================================================================
1091
1092 Handle(Geom_Curve) BRepFeat_MakePrism::BarycCurve()
1093 {
1094   return myBCurve;
1095 }
1096
1097
1098 //=======================================================================
1099 //function : HeightMax
1100 //purpose  : Calculate the height of the prism following the parameters of
1101 //           bounding box
1102 //=======================================================================
1103
1104 static Standard_Real HeightMax(const TopoDS_Shape& theSbase,
1105                                const TopoDS_Face&  theSkface,
1106                                const TopoDS_Shape& theSFrom,
1107                                const TopoDS_Shape& theSUntil)
1108 {
1109   Bnd_Box Box;
1110   BRepBndLib::Add(theSbase,Box);
1111   BRepBndLib::Add(theSkface,Box);
1112   if(!theSFrom.IsNull()) {
1113 #ifndef DEB
1114     Standard_Boolean FacRevolInfini = Standard_False;
1115 #else
1116     Standard_Boolean FacRevolInfini;
1117 #endif
1118     TopExp_Explorer exp;
1119     exp.Init(theSFrom, TopAbs_EDGE);
1120     for(; exp.More(); exp.Next()) {
1121       TopExp_Explorer exp1;
1122       exp1.Init(exp.Current(), TopAbs_VERTEX);
1123       if(!exp1.More()) {
1124         FacRevolInfini = Standard_True;
1125         break;
1126       }
1127     }
1128     if(!FacRevolInfini)
1129       BRepBndLib::Add(theSFrom,Box);
1130   }
1131   if(!theSUntil.IsNull()) {
1132 #ifndef DEB
1133     Standard_Boolean FacRevolInfini = Standard_False;
1134 #else
1135     Standard_Boolean FacRevolInfini;
1136 #endif
1137     TopExp_Explorer exp;
1138     exp.Init(theSUntil, TopAbs_EDGE);
1139     for(; exp.More(); exp.Next()) {
1140       TopExp_Explorer exp1;
1141       exp1.Init(exp.Current(), TopAbs_VERTEX);
1142       if(!exp1.More()) {
1143         FacRevolInfini = Standard_True;
1144         break;
1145       }
1146     }
1147     if(!FacRevolInfini)
1148       BRepBndLib::Add(theSUntil,Box);
1149   }
1150
1151   Standard_Real c[6];
1152
1153   Box.Get(c[0],c[2],c[4],c[1],c[3],c[5]);
1154   Standard_Real parmin=c[0], parmax = c[0];
1155   for(Standard_Integer i = 0 ; i < 6; i++) {
1156     if(c[i] > parmax) parmax = c[i];
1157     if(c[i] < parmin ) parmin = c[i];    
1158   }
1159 //#ifndef DEB
1160   Standard_Real Height = fabs(2.*(parmax - parmin));
1161 //#else
1162 //  Standard_Real Height = abs(2.*(parmax - parmin));
1163 //#endif
1164   return(Height);
1165 }
1166
1167
1168 //=======================================================================
1169 //function : SensOfPrism
1170 //purpose  : Direction of the prism depending on the shape Until
1171 //=======================================================================
1172 Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
1173                              const TopoDS_Shape& Until)
1174 {
1175   LocOpe_CSIntersector ASI1(Until);
1176   TColGeom_SequenceOfCurve scur;
1177   scur.Append(C);
1178   ASI1.Perform(scur);
1179   Standard_Integer sens = 1;
1180   if(ASI1.IsDone() && ASI1.NbPoints(1) >= 1) {
1181     if(ASI1.Point(1, 1).Parameter() < 0. && 
1182        ASI1.Point(1, ASI1.NbPoints(1)).Parameter() < 0.) {
1183       sens = -1;
1184     }
1185   }
1186   else if(BRepFeat::ParametricBarycenter(Until,C) < 0) {
1187       sens = -1;
1188   }
1189   else {}
1190   return sens;
1191 }
1192
1193
1194 //=======================================================================
1195 //function : SetGluedFaces
1196 //purpose  : management of gluing faces
1197 //=======================================================================
1198
1199 static void SetGluedFaces(const TopoDS_Face& theSkface,
1200                           const TopoDS_Shape& theSbase,
1201                           const TopoDS_Shape& thePbase,
1202                           const TopTools_DataMapOfShapeListOfShape& theSlmap,
1203                           LocOpe_Prism& thePrism,
1204                           TopTools_DataMapOfShapeShape& theMap)
1205 {
1206   TopExp_Explorer exp;
1207   if (!theSkface.IsNull() && thePbase.ShapeType() == TopAbs_FACE) {
1208     for (exp.Init(theSbase,TopAbs_FACE); exp.More(); exp.Next()) {
1209       if (exp.Current().IsSame(theSkface)) {
1210         theMap.Bind(thePbase,theSkface);
1211         break;
1212       }
1213     }
1214   }
1215   else {
1216     for (exp.Init(theSbase,TopAbs_FACE); exp.More(); exp.Next()) {
1217       if (exp.Current().IsSame(theSkface)) {
1218         TopExp_Explorer exp2;
1219         for (exp2.Init(thePbase,TopAbs_FACE);exp2.More();exp2.Next()) {
1220           theMap.Bind(exp2.Current(),theSkface);
1221         }
1222         break;
1223       }
1224     }
1225   }
1226
1227   // Sliding
1228   TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(theSlmap);
1229   if(!theSlmap.IsEmpty()) {
1230     for (; itm.More(); itm.Next()) {
1231       const TopoDS_Face& fac = TopoDS::Face(itm.Key());
1232       const TopTools_ListOfShape& ledg = itm.Value();
1233       TopTools_ListIteratorOfListOfShape it;
1234       for (it.Initialize(ledg); it.More(); it.Next()) {
1235         const TopTools_ListOfShape& gfac = thePrism.Shapes(it.Value());
1236         if (gfac.Extent() != 1) {
1237 #ifdef DEB
1238           Standard_Boolean trc = BRepFeat_GettraceFEAT();
1239           if (trc)  cout << " BRepFeat_MakePrism : Pb SetGluedFace" << endl;
1240 #endif
1241         }
1242         theMap.Bind(gfac.First(),fac);
1243       }
1244     }
1245   }
1246 }
1247
1248
1249 //=======================================================================
1250 //function : VerifGluedFaces
1251 //purpose  : Verification  intersection Tool/theSkface = thePbase
1252 //           If yes -> OK otherwise -> case without gluing
1253 //=======================================================================
1254 #ifdef DEB
1255 static void VerifGluedFaces(const TopoDS_Face& theSkface,
1256                             const TopoDS_Shape& thePbase,
1257                             Handle(Geom_Curve)& theBCurve,
1258                             TColGeom_SequenceOfCurve& theCurves,
1259                             LocOpe_Prism& thePrism,
1260                             TopTools_DataMapOfShapeShape& theMap)
1261 {
1262   Standard_Boolean GluedFaces = Standard_True;
1263   TopoDS_Shape VraiPrism = thePrism.Shape();
1264   
1265   TColGeom_SequenceOfCurve scur;
1266   thePrism.Curves(theCurves);
1267   theBCurve = thePrism.BarycCurve();    
1268   scur.Clear();    
1269   scur.Append(theBCurve);
1270   LocOpe_CSIntersector ASI(theSkface);
1271   ASI.Perform(scur);
1272   if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
1273     TopAbs_Orientation Or = ASI.Point(1,1).Orientation();
1274     TopoDS_Face FSk = ASI.Point(1,1).Face();
1275     TopoDS_Shape Comp;
1276     BRep_Builder B;
1277     B.MakeCompound(TopoDS::Compound(Comp));
1278     TopoDS_Solid S = BRepFeat::Tool(theSkface, FSk, Or);
1279     if (!S.IsNull()) B.Add(Comp,S);
1280     //modified by NIZNHY-PKV Thu Mar 21 18:07:35 2002 f
1281     //BRepAlgo_Cut trP(VraiPrism,Comp);
1282     BRepAlgoAPI_Cut trP(VraiPrism,Comp);
1283     //modified by NIZNHY-PKV Thu Mar 21 18:07:39 2002 t
1284     TopoDS_Shape Cutsh = trP.Shape();
1285     TopExp_Explorer ex(Cutsh, TopAbs_SOLID);
1286     for(; ex.More(); ex.Next()) {
1287       TopExp_Explorer ex1(ex.Current(), TopAbs_FACE);
1288       for(; ex1.More(); ex1.Next()) {
1289         const TopoDS_Face& fac1 = TopoDS::Face(ex1.Current());
1290         TopExp_Explorer ex2(thePbase, TopAbs_FACE);
1291         for(; ex2.More(); ex2.Next()) {
1292           const TopoDS_Face& fac2 = TopoDS::Face(ex2.Current());
1293           if(fac1.IsSame(fac2)) break;
1294         }
1295         if (ex2.More()) break;
1296       }
1297       if (ex1.More()) continue;
1298       GluedFaces = Standard_False;
1299       break;
1300     }
1301     if (!GluedFaces) {
1302 #ifdef DEB
1303       Standard_Boolean trc = BRepFeat_GettraceFEAT();
1304       if (trc) cout << " Intersection Prism/skface : no gluing" << endl;
1305 #endif
1306       theMap.Clear();
1307     }
1308   }
1309 }
1310 #endif
1311
1312 //=======================================================================
1313 //function : MajMap
1314 //purpose  : management of descendants
1315 //=======================================================================
1316
1317 static void MajMap(const TopoDS_Shape& theB,
1318                    const LocOpe_Prism& theP,
1319                    TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1320                    TopoDS_Shape& theFShape,  // myFShape
1321                    TopoDS_Shape& theLShape) // myLShape
1322 {
1323   TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
1324   if (exp.More()) {
1325     theFShape = exp.Current();
1326     TopTools_ListOfShape thelist2;
1327     theMap.Bind(theFShape, thelist2);
1328     for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
1329       theMap(theFShape).Append(exp.Current());
1330     }
1331   }
1332   
1333   exp.Init(theP.LastShape(),TopAbs_WIRE);
1334   if (exp.More()) {
1335     theLShape = exp.Current();
1336     TopTools_ListOfShape thelist3;
1337     theMap.Bind(theLShape, thelist3);
1338     for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1339       theMap(theLShape).Append(exp.Current());
1340     }
1341   }
1342
1343   for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1344     if (!theMap.IsBound(exp.Current())) {
1345       TopTools_ListOfShape thelist4;
1346       theMap.Bind(exp.Current(), thelist4);
1347       theMap(exp.Current()) = theP.Shapes(exp.Current());
1348     }
1349   }
1350 }
1351
1352
1353 //=======================================================================
1354 //function : MajMap
1355 //purpose  : management of descendants
1356 //=======================================================================
1357
1358 static Handle(Geom_Curve) TestCurve(const TopoDS_Shape& Base,
1359                                     const gp_Vec& V)
1360 {
1361   gp_Pnt bar(0., 0., 0.);
1362   TColgp_SequenceOfPnt spt;
1363   LocOpe::SampleEdges(Base,spt);
1364   for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
1365     const gp_Pnt& pvt = spt(jj);
1366     bar.ChangeCoord() += pvt.XYZ();
1367   }
1368   bar.ChangeCoord().Divide(spt.Length());
1369   gp_Ax1 newAx(bar,V);
1370   Handle(Geom_Line) theLin = new Geom_Line(newAx);
1371   return theLin;
1372 }
1373
1374
1375
1376
1377 //=======================================================================
1378 //function : ToFuse
1379 //purpose  : face SameDomaine or not
1380 //=======================================================================
1381
1382 Standard_Boolean ToFuse(const TopoDS_Face& F1,
1383                         const TopoDS_Face& F2)
1384 {
1385   if (F1.IsNull() || F2.IsNull()) {
1386     return Standard_False;
1387   }
1388
1389   Handle(Geom_Surface) S1,S2;
1390   TopLoc_Location loc1, loc2;
1391   Handle(Standard_Type) typS1,typS2;
1392   const Standard_Real tollin = Precision::Confusion();
1393   const Standard_Real tolang = Precision::Angular();
1394
1395   S1 = BRep_Tool::Surface(F1,loc1);
1396   S2 = BRep_Tool::Surface(F2,loc2);
1397
1398   typS1 = S1->DynamicType();
1399   typS2 = S2->DynamicType();
1400
1401   if (typS1 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1402     S1 =  (*((Handle(Geom_RectangularTrimmedSurface)*)&S1))->BasisSurface();
1403     typS1 = S1->DynamicType();
1404   }
1405
1406   if (typS2 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1407     S2 =  (*((Handle(Geom_RectangularTrimmedSurface)*)&S2))->BasisSurface();
1408     typS2 = S2->DynamicType();
1409   }
1410
1411   if (typS1 != typS2) {
1412     return Standard_False;
1413   }
1414
1415
1416   Standard_Boolean ValRet = Standard_False;
1417   if (typS1 == STANDARD_TYPE(Geom_Plane)) {
1418     S1 = BRep_Tool::Surface(F1);  // to apply the location.
1419     S2 = BRep_Tool::Surface(F2);
1420     gp_Pln pl1( (*((Handle(Geom_Plane)*)&S1))->Pln());
1421     gp_Pln pl2( (*((Handle(Geom_Plane)*)&S2))->Pln());
1422
1423     if (pl1.Position().IsCoplanar(pl2.Position(),tollin,tolang)) {
1424       ValRet = Standard_True;
1425     }
1426   }
1427
1428   return ValRet;
1429 }
1430
1431
1432
1433
1434
1435