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