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