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