c89defa29dafbbcf442b5ba1506ccf82fab5eddd
[occt.git] / src / BRepFeat / BRepFeat_MakeLinearForm.cxx
1 // Created on: 1997-04-14
2 // Created by: Olga KOULECHOVA
3 // Copyright (c) 1997-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 <BRep_Builder.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepAlgoAPI_Common.hxx>
21 #include <BRepAlgoAPI_Section.hxx>
22 #include <BRepBuilderAPI.hxx>
23 #include <BRepBuilderAPI_MakeFace.hxx>
24 #include <BRepBuilderAPI_Transform.hxx>
25 #include <BRepExtrema_ExtCF.hxx>
26 #include <BRepExtrema_ExtPC.hxx>
27 #include <BRepExtrema_ExtPF.hxx>
28 #include <BRepFeat.hxx>
29 #include <BRepFeat_MakeLinearForm.hxx>
30 #include <BRepLib_MakeEdge.hxx>
31 #include <BRepLib_MakeFace.hxx>
32 #include <BRepLib_MakeVertex.hxx>
33 #include <BRepLib_MakeWire.hxx>
34 #include <BRepPrimAPI_MakeBox.hxx>
35 #include <BRepTools.hxx>
36 #include <BRepTools_Modifier.hxx>
37 #include <BRepTools_TrsfModification.hxx>
38 #include <BRepTools_WireExplorer.hxx>
39 #include <Geom2d_Curve.hxx>
40 #include <Geom2d_Line.hxx>
41 #include <Geom_Curve.hxx>
42 #include <Geom_CylindricalSurface.hxx>
43 #include <Geom_Plane.hxx>
44 #include <Geom_RectangularTrimmedSurface.hxx>
45 #include <Geom_Surface.hxx>
46 #include <Geom_TrimmedCurve.hxx>
47 #include <GeomLProp_CLProps.hxx>
48 #include <GeomProjLib.hxx>
49 #include <gp_Dir.hxx>
50 #include <gp_Lin.hxx>
51 #include <gp_Pln.hxx>
52 #include <gp_Pnt.hxx>
53 #include <gp_Pnt2d.hxx>
54 #include <gp_Vec.hxx>
55 #include <gp_Vec2d.hxx>
56 #include <IntRes2d_IntersectionPoint.hxx>
57 #include <LocOpe.hxx>
58 #include <LocOpe_FindEdges.hxx>
59 #include <LocOpe_Gluer.hxx>
60 #include <LocOpe_LinearForm.hxx>
61 #include <Precision.hxx>
62 #include <Standard_ConstructionError.hxx>
63 #include <TColGeom_Array1OfCurve.hxx>
64 #include <TColgp_Array1OfPnt.hxx>
65 #include <TColgp_SequenceOfPnt.hxx>
66 #include <TColStd_Array1OfReal.hxx>
67 #include <TopExp.hxx>
68 #include <TopExp_Explorer.hxx>
69 #include <TopoDS.hxx>
70 #include <TopoDS_Edge.hxx>
71 #include <TopoDS_Face.hxx>
72 #include <TopoDS_Shape.hxx>
73 #include <TopoDS_Wire.hxx>
74 #include <TopOpeBRepBuild_HBuilder.hxx>
75 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
76 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
77 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
78 #include <TopTools_ListIteratorOfListOfShape.hxx>
79 #include <TopTools_ListOfShape.hxx>
80 #include <TopTools_MapIteratorOfMapOfShape.hxx>
81 #include <TopTools_MapOfShape.hxx>
82
83 //modified by NIZNHY-PKV Fri Mar 22 16:51:33 2002 f
84 //#include <BRepAlgo_Section.hxx>
85 //#include <BRepAlgo_Common.hxx>
86 //modified by NIZNHY-PKV Fri Mar 22 16:51:35 2002 t
87 //#include <DbgTools.hxx>
88 #ifdef OCCT_DEBUG
89 extern Standard_Boolean BRepFeat_GettraceFEAT();
90 extern Standard_Boolean BRepFeat_GettraceFEATRIB();
91 #endif
92
93 static void MajMap(const TopoDS_Shape&, // base
94                    const LocOpe_LinearForm&,
95                    TopTools_DataMapOfShapeListOfShape&, // myMap
96                    TopoDS_Shape&,  // myFShape
97                    TopoDS_Shape&); // myLShape
98
99 static void SetGluedFaces(const TopTools_DataMapOfShapeListOfShape& theSlmap,
100                           LocOpe_LinearForm&,
101                           TopTools_DataMapOfShapeShape&);
102
103 //=======================================================================
104 //function : Init
105 //purpose  : 
106 //=======================================================================
107
108 void BRepFeat_MakeLinearForm::Init(const TopoDS_Shape& Sbase,
109                                    const TopoDS_Wire& W,
110                                    const Handle(Geom_Plane)& Plane,
111                                    const gp_Vec& Direc,
112                                    const gp_Vec& Direc1,
113                                    const Standard_Integer Mode,
114                                    const Standard_Boolean Modify)
115 {
116 #ifdef OCCT_DEBUG
117   Standard_Boolean trc = BRepFeat_GettraceFEAT();
118   if (trc) cout << "BRepFeat_MakeLinearForm::Init" << endl;
119 #endif
120   Standard_Boolean RevolRib = Standard_False;
121   Done();
122   myGenerated.Clear();
123   
124 // modify = 0 if there is no intention to make sliding
125 //        = 1 if one tries to make sliding
126   Standard_Boolean Sliding = Modify;
127   myLFMap.Clear();
128
129   myShape.Nullify();
130   myMap.Clear();
131   myFShape.Nullify();
132   myLShape.Nullify();
133   mySbase  = Sbase;
134   mySkface.Nullify();
135   myPbase.Nullify();
136
137   myGShape.Nullify();
138   mySUntil.Nullify();
139   myListOfEdges.Clear();
140   mySlface.Clear();
141
142   TopoDS_Shape aLocalShapeW = W.Oriented(TopAbs_FORWARD);
143   myWire = TopoDS::Wire(aLocalShapeW);
144 //  myWire = TopoDS::Wire(W.Oriented(TopAbs_FORWARD));
145   myDir  = Direc;
146   myDir1 = Direc1;
147   myPln  = Plane;
148
149   if(Mode == 0) 
150     myFuse   = Standard_False;
151   else // if(Mode == 1) 
152     myFuse   = Standard_True;
153 #ifdef OCCT_DEBUG
154   if (trc) {
155     if (myFuse)  cout << " Fuse" << endl;
156     if (!myFuse)  cout << " Cut" << endl;
157   }
158 #endif
159
160   
161 // ---Determine Tolerance : max tolerance on parameters
162   myTol = Precision::Confusion();
163
164   TopExp_Explorer exx;  
165   exx.Init(myWire, TopAbs_VERTEX);
166   for(; exx.More(); exx.Next()) {
167     const Standard_Real& tol = BRep_Tool::
168       Tolerance(TopoDS::Vertex(exx.Current()));
169     if(tol > myTol) myTol = tol;
170   }
171
172   exx.Init(Sbase, TopAbs_VERTEX);
173   for(; exx.More(); exx.Next()) {
174     const Standard_Real& tol = BRep_Tool::
175       Tolerance(TopoDS::Vertex(exx.Current()));
176     if(tol > myTol) myTol = tol;
177   }
178
179 // ---Control of directions
180 //    the wire should be in the rib
181   gp_Vec nulldir(0, 0, 0);
182   if(!myDir1.IsEqual(nulldir, myTol, myTol)) {
183     Standard_Real ang = myDir1.Angle(myDir);
184     if(ang != M_PI) {
185 #ifdef OCCT_DEBUG
186       if (trc) cout << " Directions must be opposite" << endl;
187 #endif
188       myStatusError = BRepFeat_BadDirect;
189       NotDone();
190       return;
191     }
192   }
193   else {
194
195 // Rib is centre in the middle of translation
196 #ifdef OCCT_DEBUG
197     if (trc)  cout << " Rib is centre" << endl;
198 #endif
199     const gp_Vec& DirTranslation = (Direc + Direc1) * 0.5;
200     gp_Trsf T;
201     T.SetTranslation(DirTranslation);
202     BRepBuilderAPI_Transform trf(T);
203     trf.Perform(myWire);
204     myWire = TopoDS::Wire(trf.Shape());
205     myDir  = Direc  - DirTranslation;
206     myDir1 = Direc1 - DirTranslation;
207     myPln->Transform(T);
208   }
209
210 // ---Calculate bounding box
211   BRep_Builder BB;
212
213   TopTools_ListOfShape theList;  
214   
215   TopoDS_Shape U;
216   U.Nullify();
217   gp_Pnt FirstCorner, LastCorner;
218   Standard_Real bnd = HeightMax(mySbase, U, FirstCorner, LastCorner);
219   myBnd = bnd;
220
221   BRepPrimAPI_MakeBox Bndbox(FirstCorner, LastCorner);
222   TopoDS_Solid BndBox = Bndbox.Solid();
223
224
225 // ---Construction of the face workplane (section bounding box)
226   BRepLib_MakeFace PlaneF(myPln->Pln(), -6.*myBnd, 
227                           6.*myBnd, -6.*myBnd, 6.*myBnd);
228   TopoDS_Face PlaneFace = TopoDS::Face(PlaneF.Shape());
229
230   //modified by NIZNHY-PKV Fri Mar 22 16:49:28 2002 f
231   //BRepAlgo_Common PlaneS(BndBox, PlaneFace);
232   BRepAlgoAPI_Common PlaneS(BndBox, PlaneFace);
233   //modified by NIZNHY-PKV Fri Mar 22 16:49:39 2002 t  
234   TopExp_Explorer EXP;
235   TopoDS_Shape PlaneSect = PlaneS.Shape();
236   EXP.Init(PlaneSect, TopAbs_WIRE);
237   TopoDS_Wire www = TopoDS::Wire(EXP.Current());
238   BRepLib_MakeFace Bndface(myPln->Pln(), www, Standard_True);
239   TopoDS_Face BndFace = TopoDS::Face(Bndface.Shape());
240
241
242 // ---Find support faces of the rib
243   TopoDS_Edge FirstEdge, LastEdge;
244   TopoDS_Face FirstFace, LastFace;
245   TopoDS_Vertex FirstVertex, LastVertex;
246
247   Standard_Boolean OnFirstFace = Standard_False;
248   Standard_Boolean OnLastFace = Standard_False;
249   Standard_Boolean PtOnFirstEdge = Standard_False;
250   Standard_Boolean PtOnLastEdge = Standard_False;
251   TopoDS_Edge OnFirstEdge, OnLastEdge;
252   OnFirstEdge.Nullify();
253   OnLastEdge.Nullify();
254
255   Standard_Boolean Data = ExtremeFaces(RevolRib, myBnd, myPln, FirstEdge, LastEdge, 
256                                        FirstFace, LastFace, FirstVertex, 
257                                        LastVertex, OnFirstFace, OnLastFace,
258                                        PtOnFirstEdge, PtOnLastEdge,
259                                        OnFirstEdge, OnLastEdge);
260  
261   if(!Data) {
262 #ifdef OCCT_DEBUG
263     if (trc) cout << " No Extreme faces" << endl;
264 #endif
265     myStatusError = BRepFeat_NoExtFace;
266     NotDone();
267     return;
268   }
269
270
271 // ---Proofing Point for the side of the wire to be filled - side material
272   gp_Pnt CheckPnt = CheckPoint(FirstEdge, bnd/10., myPln);
273
274 //  Standard_Real f, l;
275
276 // ---Control sliding valuable
277 // Many cases when the sliding is abandoned
278   Standard_Integer Concavite = 3;  // a priori the profile is not concave
279
280   myFirstPnt = BRep_Tool::Pnt(FirstVertex);
281   myLastPnt  = BRep_Tool::Pnt(LastVertex);
282
283 // SliList : list of faces concerned by the rib
284   TopTools_ListOfShape SliList;
285   SliList.Append(FirstFace);
286
287   if(Sliding) {    // sliding
288 #ifdef OCCT_DEBUG
289     if (trc) cout << " Sliding" << endl;
290 #endif
291     Sliding = Standard_False;
292     Handle(Geom_Surface) s = BRep_Tool::Surface(FirstFace);
293     if (s->DynamicType() == 
294         STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
295       s = Handle(Geom_RectangularTrimmedSurface)::
296         DownCast(s)->BasisSurface();
297     }
298     if(s->DynamicType() == STANDARD_TYPE(Geom_Plane) ||
299        s->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
300 // if plane or cylinder : sliding is possible
301       Sliding = Standard_True;
302     }
303   }
304
305 // Control only start and end points
306 // -> no control at the middle - improve
307 // Controle between Surface and segment between 2 limit points
308 // is too expensive - improve
309   if(Sliding) {
310     gp_Pnt p1(myFirstPnt.X()+myDir.X(),myFirstPnt.Y()+myDir.Y(),
311               myFirstPnt.Z()+myDir.Z());
312     BRepLib_MakeEdge ee1(myFirstPnt, p1);
313     BRepExtrema_ExtCF ext1(ee1, FirstFace);
314     if(ext1.NbExt() == 1 && ext1.SquareDistance(1)<=BRep_Tool::Tolerance(FirstFace) * BRep_Tool::Tolerance(FirstFace)) {
315       gp_Pnt p2(myLastPnt.X()+myDir.X(),myLastPnt.Y()+myDir.Y(),
316                 myLastPnt.Z()+myDir.Z());
317       BRepLib_MakeEdge ee2(myLastPnt, p2);
318       BRepExtrema_ExtCF ext2(ee2, LastFace); // ExtCF : curves and surfaces
319       if(ext2.NbExt() == 1 && ext2.SquareDistance(1)<=BRep_Tool::Tolerance(LastFace) * BRep_Tool::Tolerance(LastFace)) {
320         Sliding = Standard_True;
321       }
322       else {
323         Sliding = Standard_False;
324       }      
325     }
326     else {
327       Sliding = Standard_False;
328     }   
329   }
330
331   if(!myDir1.IsEqual(nulldir, Precision::Confusion(), Precision::Confusion())) {
332     if(Sliding) {
333       gp_Pnt p1(myFirstPnt.X()+myDir1.X(),myFirstPnt.Y()+myDir1.Y(),
334                 myFirstPnt.Z()+myDir1.Z());
335       BRepLib_MakeEdge ee1(myFirstPnt, p1);
336       BRepExtrema_ExtCF ext1(ee1, FirstFace);
337       if(ext1.NbExt() == 1 && ext1.SquareDistance(1)<=BRep_Tool::Tolerance(FirstFace) * BRep_Tool::Tolerance(FirstFace)) {
338         gp_Pnt p2(myLastPnt.X()+myDir1.X(),myLastPnt.Y()+myDir1.Y(),
339                   myLastPnt.Z()+myDir1.Z());
340         BRepLib_MakeEdge ee2(myLastPnt, p2);
341         BRepExtrema_ExtCF ext2(ee2, LastFace);
342         if(ext2.NbExt() == 1 && ext2.SquareDistance(1)<=BRep_Tool::Tolerance(LastFace) * BRep_Tool::Tolerance(LastFace)) {
343           Sliding = Standard_True;
344         }
345         else {
346           Sliding = Standard_False;
347         }      
348       }
349       else {
350         Sliding = Standard_False;
351       }   
352     }
353   }
354
355
356 // Construct a great profile that goes till the bounding box
357 // -> by tangency with the first and the last edge of the Wire
358 // -> by normals to the support faces : statistically better
359 // Intersect everything to find the final profile
360
361
362 // ---case of sliding : construction of the profile face 
363   if(Sliding) {
364 #ifdef OCCT_DEBUG
365     if (trc) cout << " still Sliding" << endl;
366 #endif
367     TopoDS_Face Prof;
368     Standard_Boolean ProfileOK;
369     ProfileOK = SlidingProfile(Prof,RevolRib,myTol,Concavite,myPln,BndFace,CheckPnt,
370                                FirstFace,LastFace,FirstVertex,LastVertex,
371                                FirstEdge,LastEdge);
372     
373     if (!ProfileOK) {
374 #ifdef OCCT_DEBUG
375       if (trc)
376       {
377         cout << "Not computable" << endl;
378         cout << "Face profile not computable" << endl;
379       }
380 #endif
381       myStatusError = BRepFeat_NoFaceProf;
382       NotDone();
383       return;
384     }
385
386
387 // ---Propagation on faces of the initial shape 
388 // to find the faces concerned by the rib
389     Standard_Boolean falseside = Standard_True;
390     Sliding = Propagate(SliList, Prof, myFirstPnt, myLastPnt, falseside);
391 // Control if there is everything required to have the material at the proper side
392     if(falseside == Standard_False) {
393 #ifdef OCCT_DEBUG
394       cout << "Verify plane and wire orientation" << endl;
395 #endif
396       myStatusError = BRepFeat_FalseSide;
397       NotDone();
398       return;
399     }
400   }
401
402
403 // ---Generation of the base of the rib profile 
404
405   TopoDS_Wire w;
406   BB.MakeWire(w);
407   TopoDS_Edge thePreviousEdge;
408   TopoDS_Vertex theFV;
409   thePreviousEdge.Nullify();
410
411 // calculate the number of edges to fill the map
412   Standard_Integer counter = 1;
413
414 // ---case of sliding
415   if(Sliding && !myListOfEdges.IsEmpty()) {
416     BRepTools_WireExplorer EX1(myWire);
417     for(; EX1.More(); EX1.Next()) {
418       const TopoDS_Edge& E = EX1.Current();
419       if(!myLFMap.IsBound(E)) {
420         TopTools_ListOfShape theTmpList;
421         myLFMap.Bind(E, theTmpList );
422       }      
423       if(E.IsSame(FirstEdge)) {
424         Standard_Real f, l;
425         Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
426         cc = new Geom_TrimmedCurve(cc, f, l);
427         gp_Pnt pt;
428         if(!FirstEdge.IsSame(LastEdge)) {
429           pt = BRep_Tool::Pnt(TopExp::LastVertex(E,Standard_True)); 
430         }
431         else {
432           pt = myLastPnt;
433           Standard_Real fpar = IntPar(cc, myFirstPnt);
434           Standard_Real lpar = IntPar(cc, pt);
435           Handle(Geom_Curve) ccc;
436           if(fpar > lpar) {
437             ccc = Handle(Geom_Curve)::DownCast(cc->Reversed());
438             cc = ccc;
439           }
440         }
441         TopoDS_Edge ee1;
442         if(thePreviousEdge.IsNull()) {
443           BRepLib_MakeVertex v1(myFirstPnt);
444           BRepLib_MakeVertex v2(pt);      
445           BRepLib_MakeEdge e(cc, v1, v2);
446           ee1 = TopoDS::Edge(e.Shape());
447         } 
448         else {
449           const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
450           BRepLib_MakeVertex v2(pt);
451           
452           BRepLib_MakeEdge e(cc, v1, v2);
453           ee1 = TopoDS::Edge(e.Shape());
454         }
455         TopoDS_Shape aLocalShape = ee1.Oriented(E.Orientation());
456         ee1 = TopoDS::Edge(aLocalShape);
457 //      ee1 = TopoDS::Edge(ee1.Oriented(E.Orientation()));
458         if(counter == 1) theFV = TopExp::FirstVertex(ee1,Standard_True);
459         myLFMap(E).Append(ee1);
460         BB.Add(w, ee1);
461         thePreviousEdge = ee1;
462         counter++;
463         EX1.Next();
464         break;
465       }
466     }
467  
468 // Case of several edges
469     if(!FirstEdge.IsSame(LastEdge)) {
470       for(; EX1.More(); EX1.Next()) {
471         const TopoDS_Edge& E = EX1.Current();
472         if(!myLFMap.IsBound(E)) {
473           TopTools_ListOfShape thelist1;
474           myLFMap.Bind(E, thelist1);
475         }      
476         theList.Append(E);
477         Standard_Real f, l;
478         if(!E.IsSame(LastEdge)) {
479           Handle(Geom_Curve) ccc = BRep_Tool::Curve(E, f, l);
480           TopoDS_Vertex v1, v2;
481           if(!thePreviousEdge.IsNull()) {
482             v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
483             v2 = TopExp::LastVertex(E,Standard_True);
484           }
485           else {
486 //          v1 = TopExp::LastVertex(E,Standard_True);
487             v1 = TopExp::FirstVertex(E,Standard_True);
488             v2 = TopExp::LastVertex(E,Standard_True);
489           }
490           BRepLib_MakeEdge E1(ccc, v1, v2);
491           TopoDS_Edge E11 = TopoDS::Edge(E1.Shape());
492           TopoDS_Shape aLocalShape = E11.Oriented(E.Orientation());
493           E11 = TopoDS::Edge(aLocalShape);
494 //        E11 = TopoDS::Edge(E11.Oriented(E.Orientation()));
495           thePreviousEdge = E11;
496           myLFMap(E).Append(E11);
497           BB.Add(w, E11);
498           if(counter == 1) theFV = TopExp::FirstVertex(E11,Standard_True);
499           counter++;
500         }
501         else {
502           Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
503           gp_Pnt pf = BRep_Tool::Pnt(TopExp::FirstVertex(E,Standard_True));
504           gp_Pnt pl = myLastPnt;
505           TopoDS_Edge ee;
506           if(thePreviousEdge.IsNull()) {
507             BRepLib_MakeEdge e(cc, pf , pl); 
508             ee = TopoDS::Edge(e.Shape());
509           }
510           else {
511             const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
512             BRepLib_MakeVertex v2(pl);
513             BRepLib_MakeEdge e(cc, v1, v2);
514             ee = TopoDS::Edge(e.Shape());
515           }
516           TopoDS_Shape aLocalShape = ee.Oriented(E.Orientation());
517           ee = TopoDS::Edge(aLocalShape);
518 //        ee = TopoDS::Edge(ee.Oriented(E.Orientation()));
519           BB.Add(w, ee);
520           myLFMap(E).Append(ee);
521           if(counter == 1) theFV = TopExp::FirstVertex(ee,Standard_True);
522           thePreviousEdge = ee;
523           counter++;
524           break;
525         }
526       }
527     }
528     
529     TopTools_ListIteratorOfListOfShape it(myListOfEdges);
530     Standard_Boolean FirstOK = Standard_False;
531     Standard_Boolean LastOK = Standard_False;
532     
533     gp_Pnt theLastPnt = myLastPnt;
534     Standard_Integer sens = 0;
535     TopoDS_Edge theEdge, theLEdge, theFEdge;
536     Standard_Integer counter1 = counter;
537     TopTools_ListOfShape NewListOfEdges;
538     NewListOfEdges.Clear();
539     while (!FirstOK) {
540       const TopoDS_Edge& edg = TopoDS::Edge(it.Value());
541       gp_Pnt fp, lp;
542       Standard_Real f, l;
543       Handle(Geom_Curve) ccc = BRep_Tool::Curve(edg, f, l);
544       Handle(Geom_TrimmedCurve) cc = new Geom_TrimmedCurve(ccc, f, l);
545       if ( edg.Orientation() == TopAbs_REVERSED) cc->Reverse();
546
547       fp = cc->Value(cc->FirstParameter());
548       lp = cc->Value(cc->LastParameter());
549       Standard_Real dist = fp.Distance(theLastPnt);
550       if(dist <= myTol) {
551         sens = 1;
552         LastOK = Standard_True;
553       }
554       else {
555         dist = lp.Distance(theLastPnt);
556         if(dist <= myTol) {
557           sens = 2;
558           LastOK = Standard_True;
559           cc->Reverse();
560         }
561       }
562       Standard_Integer FirstFlag = 0;
563       if(sens==1 && lp.Distance(myFirstPnt) <= myTol) {
564         FirstOK = Standard_True;
565         FirstFlag = 1;
566       }
567       else if(sens==2 && fp.Distance(myFirstPnt) <= myTol) {
568         FirstOK = Standard_True;
569         FirstFlag = 2;
570       }
571       
572       if (LastOK) {
573         TopoDS_Edge eeee;
574         Standard_Real fpar = cc->FirstParameter();
575         Standard_Real lpar = cc->LastParameter();
576         if(!FirstOK) {
577           if(thePreviousEdge.IsNull()) {
578             BRepLib_MakeEdge e(cc, fpar, lpar);
579             eeee = TopoDS::Edge(e.Shape());
580           }
581           else {
582             const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
583             BB.UpdateVertex(v1, dist);
584             BRepLib_MakeVertex v2(cc->Value(lpar));
585             TopoDS_Vertex nv=v2.Vertex();
586             BRepLib_MakeEdge e(cc, v1, nv);
587             eeee = TopoDS::Edge(e.Shape());
588           }
589         }
590         else {
591           if(thePreviousEdge.IsNull()) {
592             BRepLib_MakeVertex v1(cc->Value(fpar)); 
593             BRepLib_MakeEdge e(cc, v1, theFV);
594             eeee = TopoDS::Edge(e.Shape());
595           }
596           else {
597             const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
598             BRepLib_MakeEdge e(cc, v1, theFV);
599             eeee = TopoDS::Edge(e.Shape());
600           }
601         }
602
603         thePreviousEdge = eeee;
604         BB.Add(w, eeee);
605         if(counter == 1) theFV = TopExp::FirstVertex(eeee,Standard_True);
606         counter1++;
607         NewListOfEdges.Append(edg);
608         theEdge = eeee;
609
610         if(dist <= myTol) 
611           theFEdge = edg;
612         theLastPnt = BRep_Tool::Pnt(TopExp::LastVertex(theEdge,Standard_True));
613       }
614
615       if(FirstFlag == 1) {
616         theLEdge = edg;
617       }
618       else if(FirstFlag == 2) {
619         theLEdge = theEdge;
620       }
621
622       if(LastOK) {
623         myListOfEdges.Remove(it);
624         it.Initialize(myListOfEdges);
625         LastOK = Standard_False;
626       }
627       else if(it.More()) it.Next();
628       else {
629         Sliding = Standard_False;
630         break;
631       } 
632       sens = 0;
633     }
634
635
636     TopTools_DataMapOfShapeListOfShape SlidMap;
637     SlidMap.Clear();
638     
639     if(Sliding && counter1 > counter) {
640       TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm;
641       TopExp_Explorer EX2(w, TopAbs_EDGE);
642       Standard_Integer ii = 0;
643       for(; EX2.More(); EX2.Next()) {
644         const TopoDS_Edge& E = TopoDS::Edge(EX2.Current());
645         ii++;   
646         if(ii >= counter && ii <= counter1) {
647           it.Initialize(NewListOfEdges);
648           Standard_Integer jj = 0;
649           for(; it.More(); it.Next()) {
650             const TopoDS_Edge& e2 = TopoDS::Edge(it.Value());
651             jj++;
652             if(jj== (ii - counter +1)) {          
653               itm.Initialize(mySlface);
654               for(; itm.More(); itm.Next()) {
655                 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
656                 const TopTools_ListOfShape& ledg = itm.Value();
657                 TopTools_ListIteratorOfListOfShape itedg(ledg);
658                 //Standard_Integer iiii = 0;
659                 for(; itedg.More(); itedg.Next()) {
660                   const TopoDS_Edge& e1 = TopoDS::Edge(itedg.Value());
661                   if(e1.IsSame(e2)){
662                     if(!SlidMap.IsBound(fac)) {
663                       TopTools_ListOfShape thelist2;
664                       SlidMap.Bind(fac, thelist2);
665                     }
666                     SlidMap(fac).Append(E);
667                   }
668                 }               
669               }
670             }
671           } 
672         }
673       }
674     }
675
676     mySlface.Clear();
677     mySlface = SlidMap;
678   }
679
680 // ---Arguments of LocOpe_LinearForm : arguments of the prism sliding
681   if(Sliding) {
682     TopoDS_Face F;
683     BB.MakeFace(F, myPln, myTol);
684     w.Closed (BRep_Tool::IsClosed (w));
685     BB.Add(F, w);
686 //    BRepLib_MakeFace F(myPln->Pln(),w, Standard_True);
687     mySkface = F;
688     myPbase  = mySkface;
689     mySUntil.Nullify();
690   }
691   
692
693 // ---Case without sliding : construction of the profile face   
694   if(!Sliding) {
695 #ifdef OCCT_DEBUG
696     if (trc) {
697       if (Modify) cout << " Sliding failure" << endl;
698       cout << " no Sliding" << endl;
699     }
700 #endif
701     TopoDS_Face Prof;
702     Standard_Boolean ProfileOK;
703     ProfileOK = NoSlidingProfile(Prof,RevolRib,myTol,Concavite,myPln,
704                                  bnd,BndFace,CheckPnt,
705                                  FirstFace,LastFace,FirstVertex,LastVertex,
706                                  FirstEdge,LastEdge,OnFirstFace,OnLastFace);
707     
708     if (!ProfileOK) {
709 #ifdef OCCT_DEBUG
710       if (trc)
711       {
712         cout << "Not computable" << endl;
713         cout << " Face profile not computable" << endl;
714       }
715 #endif
716       myStatusError = BRepFeat_NoFaceProf;
717       NotDone();
718       return;
719     }
720
721
722 // ---Propagation on faces of the initial shape
723 // to find the faces concerned by the rib
724     Standard_Boolean falseside = Standard_True;
725     Propagate(SliList, Prof, myFirstPnt, myLastPnt, falseside);
726 // Control if there is everything required to have the material at the proper side
727     if(falseside == Standard_False) {
728 #ifdef OCCT_DEBUG
729       cout << "Verify plane and wire orientation" << endl;
730 #endif
731       myStatusError = BRepFeat_FalseSide;
732       NotDone();
733       return;
734     }
735
736     mySlface.Clear();
737
738     TopTools_ListIteratorOfListOfShape it;
739     it.Initialize(SliList);
740     
741     TopoDS_Shape comp;
742     
743     BB.MakeShell(TopoDS::Shell(comp));
744     
745     for(; it.More(); it.Next()) {
746       BB.Add(comp, it.Value());
747     }
748     comp.Closed (BRep_Tool::IsClosed (comp));
749     
750     mySUntil = comp;
751
752     mySkface = Prof;
753     myPbase  = Prof;
754   }
755
756   mySliding = Sliding;
757
758   TopExp_Explorer exp;
759   for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
760     TopTools_ListOfShape thelist3;
761     myMap.Bind(exp.Current(), thelist3);
762     myMap(exp.Current()).Append(exp.Current());
763   }
764 }
765
766
767 //=======================================================================
768 //function : Add
769 //purpose  : add des element de collage
770 //=======================================================================
771
772 void BRepFeat_MakeLinearForm::Add(const TopoDS_Edge& E,
773                                   const TopoDS_Face& F)
774 {
775 #ifdef OCCT_DEBUG
776   Standard_Boolean trc = BRepFeat_GettraceFEAT();
777   if (trc) cout << "BRepFeat_MakeLinearForm::Add" << endl;
778 #endif
779   if(mySlface.IsEmpty()) {
780     TopExp_Explorer exp;
781     for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
782       if (exp.Current().IsSame(F)) {
783         break;
784       }
785     }
786     if (!exp.More()) {
787       Standard_ConstructionError::Raise();
788     }
789   
790     if (!mySlface.IsBound(F)) {
791       TopTools_ListOfShape thelist;
792       mySlface.Bind(F, thelist);
793     }
794     TopTools_ListIteratorOfListOfShape itl(mySlface(F));
795     for (; itl.More();itl.Next()) {
796       if (itl.Value().IsSame(E)) {
797         break;
798       }
799     }
800     if (!itl.More()) {
801       mySlface(F).Append(E);
802     }
803   } 
804 }
805
806   
807
808 //=======================================================================
809 //function : Perform
810 //purpose  : construction of rib from a profile and the initial shape
811 //=======================================================================
812
813 void BRepFeat_MakeLinearForm::Perform()
814 {
815 #ifdef OCCT_DEBUG
816   Standard_Boolean trc = BRepFeat_GettraceFEAT();
817   if (trc) cout << "BRepFeat_MakeLinearForm::Perform()" << endl;
818 #endif
819   if(mySbase.IsNull() || mySkface.IsNull() || myPbase.IsNull()) {
820 #ifdef OCCT_DEBUG
821     if (trc) cout << " Fields not initialized" << endl;
822 #endif
823     myStatusError = BRepFeat_NotInitialized;
824     NotDone();
825     return;
826   }
827
828   gp_Vec nulldir(0, 0, 0);
829
830   Standard_Real Length = myDir.Magnitude() +  myDir1.Magnitude();
831
832   myGluedF.Clear();
833  
834   if(!mySUntil.IsNull()) 
835     myPerfSelection = BRepFeat_SelectionU;
836   else 
837     myPerfSelection = BRepFeat_NoSelection;
838
839   gp_Dir dir(myDir);
840   gp_Vec V = Length*dir;
841
842   LocOpe_LinearForm theForm;
843
844   if(myDir1.IsEqual(nulldir, Precision::Confusion(), Precision::Confusion())) 
845     theForm.Perform(myPbase, V, myFirstPnt, myLastPnt);
846   else 
847     theForm.Perform(myPbase, V, myDir1, myFirstPnt, myLastPnt);
848
849   TopoDS_Shape VraiForm = theForm.Shape();   // primitive of the rib
850
851   myFacesForDraft.Append(theForm.FirstShape());
852   myFacesForDraft.Append(theForm.LastShape());
853   MajMap(myPbase,theForm,myMap,myFShape,myLShape);   // management of descendants
854
855   TopExp_Explorer exx(myPbase, TopAbs_EDGE);
856   for(; exx.More(); exx.Next()) {
857     const TopoDS_Edge& e = TopoDS::Edge(exx.Current());
858     if(!myMap.IsBound(e)) {
859 #ifdef OCCT_DEBUG
860       if (trc) cout << " Sliding face not in Base shape" << endl;
861 #endif
862       myStatusError = BRepFeat_IncSlidFace;
863       NotDone();
864       return;
865     }
866   }
867
868   myGShape = VraiForm;
869   SetGluedFaces(mySlface, theForm, myGluedF);  // management of sliding faces  
870
871   if(!myGluedF.IsEmpty() && !mySUntil.IsNull()) {
872 #ifdef OCCT_DEBUG
873     if (trc)
874     {
875       cout << "The case is not computable" << endl;
876       cout << " Glued faces not empty and Until shape not null" << endl;
877     }
878 #endif
879     myStatusError = BRepFeat_InvShape;
880     NotDone();
881     return;
882   }
883
884   LFPerform();
885
886 /*
887
888   TopExp_Explorer expr(mySbase, TopAbs_FACE);
889   char nom1[20], nom2[20];
890   Standard_Integer ii = 0;
891   for(; expr.More(); expr.Next()) {
892     ii++;
893     sprintf(nom1, "faceinitial_%d", ii);
894     DBRep::Set(nom1, expr.Current());
895     Standard_Integer jj = 0;
896     const TopTools_ListOfShape& list = Modified(expr.Current());
897     TopTools_ListIteratorOfListOfShape ite(list);
898     for(; ite.More(); ite.Next()) {
899       jj++;
900       sprintf(nom2, "facemodifie_%d_%d", ii, jj);
901       DBRep::Set(nom2, ite.Value());
902     }
903   }
904
905   expr.Init(myWire, TopAbs_EDGE);
906   ii=0;
907   for(; expr.More(); expr.Next()) {
908     ii++;
909     sprintf(nom1, "edgeinitial_%d", ii);
910     DBRep::Set(nom1, expr.Current());
911     Standard_Integer jj = 0;
912     const TopTools_ListOfShape& genf = Generated(expr.Current());
913     TopTools_ListIteratorOfListOfShape ite(genf);
914     for(; ite.More(); ite.Next()) {
915       jj++;
916       sprintf(nom2, "egdegeneree_%d_%d", ii, jj);
917       DBRep::Set(nom2, ite.Value());
918     }
919   }
920 */
921 }
922
923 //=======================================================================
924 //function : Propagate
925 //purpose  : propagation on faces of the initial shape, find 
926 // faces concerned by the rib
927 //=======================================================================
928   Standard_Boolean BRepFeat_MakeLinearForm::Propagate(TopTools_ListOfShape& SliList,
929                                                       const TopoDS_Face& fac,
930                                                       const gp_Pnt& Firstpnt, 
931                                                       const gp_Pnt& Lastpnt, 
932                                                       Standard_Boolean& falseside)
933 {
934 #ifdef OCCT_DEBUG
935   Standard_Boolean trc = BRepFeat_GettraceFEATRIB();
936   if (trc) cout << "BRepFeat_MakeLinearForm::Propagate" << endl;
937 #endif
938   gp_Pnt Firstpoint = Firstpnt;
939   gp_Pnt Lastpoint = Lastpnt;
940
941   Standard_Boolean result = Standard_True;
942   TopoDS_Face CurrentFace, saveFace;
943   CurrentFace = TopoDS::Face(SliList.First());
944   saveFace = CurrentFace;
945
946   Standard_Boolean LastOK = Standard_False, FirstOK= Standard_False;
947   Standard_Boolean v1OK = Standard_False, v2OK= Standard_False;
948   TopoDS_Vertex v1, v2, v3, v4, ve1, ve2;
949
950   //modified by NIZNHY-PKV Fri Mar 22 16:50:24 2002 f
951   //BRepAlgo_Section sect (fac, CurrentFace, Standard_False);
952   BRepAlgoAPI_Section sect (fac, CurrentFace, Standard_False);
953   //modified by NIZNHY-PKV Fri Mar 22 16:50:32 2002 t
954
955   sect.Approximation(Standard_True);
956   sect.Build();
957
958   TopExp_Explorer Ex;
959   TopoDS_Edge eb, ec;
960   gp_Pnt p1, p2;
961   Standard_Real t1 = 0., t2 = 0.;
962   Standard_Boolean c1f, c2f, c1l, c2l;
963
964   for (Ex.Init(sect.Shape(), TopAbs_EDGE); Ex.More(); Ex.Next()) {
965     ec = TopoDS::Edge(Ex.Current());
966     v1 = TopExp::FirstVertex(ec,Standard_True); 
967     v2 = TopExp::LastVertex(ec,Standard_True); 
968     p1 = BRep_Tool::Pnt(v1);
969     p2 = BRep_Tool::Pnt(v2);
970     t1 = BRep_Tool::Tolerance(v1);
971     t2 = BRep_Tool::Tolerance(v2);
972     c1f = p1.Distance(Firstpoint)<=t1;
973     c2f = p2.Distance(Firstpoint)<=t2;
974     c1l = p1.Distance(Lastpoint)<=t1;
975     c2l = p2.Distance(Lastpoint)<=t2;
976     if (c1f || c2f || c1l|| c2l) {
977       eb = ec;
978       if (c1f || c1l) v1OK=Standard_True;
979       if (c2f || c2l) v2OK=Standard_True;
980       if (c1f || c2f) FirstOK=Standard_True;
981       if (c1l || c2l) LastOK=Standard_True;
982       break;
983     }
984   }
985
986   if(eb.IsNull()) {
987     falseside = Standard_False;
988     return Standard_False;
989   }
990   TopTools_ListOfShape thelist;
991   mySlface.Bind(CurrentFace, thelist);
992   mySlface(CurrentFace).Append(eb);
993     
994   myListOfEdges.Clear();
995   myListOfEdges.Append(eb);
996     
997   // two points are on the same face.
998   if(LastOK && FirstOK) {
999     return result;
1000   }
1001   
1002   TopTools_IndexedDataMapOfShapeListOfShape mapedges;
1003   TopExp::MapShapesAndAncestors(mySbase, TopAbs_EDGE, TopAbs_FACE, mapedges);
1004   TopExp_Explorer ex;
1005   TopoDS_Edge FirstEdge;
1006   BRep_Builder BB;
1007
1008   TopoDS_Vertex Vprevious;
1009   gp_Pnt ptprev;
1010   Standard_Real dp;
1011
1012   while (!(LastOK && FirstOK)) {
1013     if (v1OK) {
1014       Vprevious=v2;
1015       ptprev=p2;
1016     }
1017     else {
1018       Vprevious=v1;
1019       ptprev=p1;
1020     }
1021     
1022     // find edge connected to v1 or v2:
1023     for (ex.Init(CurrentFace, TopAbs_EDGE); ex.More(); ex.Next()) {
1024       const TopoDS_Edge& rfe = TopoDS::Edge(ex.Current());
1025
1026       BRepExtrema_ExtPC projF(Vprevious, rfe);
1027
1028       if(projF.IsDone() && projF.NbExt() >=1) {
1029         Standard_Real dist2min = RealLast();
1030         Standard_Integer index = 0;
1031         for (Standard_Integer sol =1 ; sol <= projF.NbExt(); sol++) {
1032           if (projF.SquareDistance(sol) <= dist2min) {
1033             index = sol;
1034             dist2min = projF.SquareDistance(sol);
1035           }
1036         }
1037         if (index != 0) {
1038           if (dist2min <= BRep_Tool::Tolerance(rfe) * BRep_Tool::Tolerance(rfe)) {
1039             FirstEdge = rfe;
1040             // If the edge is not perpendicular to the plane of the rib
1041             // it is required to set Sliding(result) to false.
1042             if (result) {
1043               result=Standard_False;
1044               ve1 = TopExp::FirstVertex(rfe,Standard_True);
1045               ve2 = TopExp::LastVertex(rfe,Standard_True);
1046               BRepExtrema_ExtPF perp(ve1, fac);
1047               if (perp.IsDone()) {
1048                 gp_Pnt pe1=perp.Point(1);
1049                 perp.Perform(ve2, fac);
1050                 if (perp.IsDone()) {
1051                   gp_Pnt pe2=perp.Point(1);
1052                   if (pe1.Distance(pe2)<=BRep_Tool::Tolerance(rfe)) 
1053                     result=Standard_True;
1054                 }
1055               }
1056             }
1057             break;
1058           }
1059         }
1060       }
1061     }
1062     
1063     const TopTools_ListOfShape& L = mapedges.FindFromKey(FirstEdge);
1064     TopTools_ListIteratorOfListOfShape It(L);
1065
1066     for (; It.More(); It.Next()) {
1067       const TopoDS_Face& FF = TopoDS::Face(It.Value());
1068       if (!FF.IsSame(CurrentFace)) {
1069         CurrentFace = FF;
1070         break;
1071       }
1072     }
1073
1074     //modified by NIZNHY-PKV Fri Mar 22 16:50:53 2002 f
1075     //BRepAlgo_Section sectf (fac, CurrentFace, Standard_False);
1076     BRepAlgoAPI_Section sectf (fac, CurrentFace, Standard_False);
1077     //modified by NIZNHY-PKV Fri Mar 22 16:51:03 2002 t
1078     sectf.Approximation(Standard_True);
1079     sectf.Build();
1080
1081     TopoDS_Edge edg1;
1082     for (Ex.Init(sectf.Shape(), TopAbs_EDGE); Ex.More(); Ex.Next()) {
1083       edg1 = TopoDS::Edge(Ex.Current());
1084       v1=TopExp::FirstVertex(edg1,Standard_True);
1085       v2=TopExp::LastVertex(edg1,Standard_True);
1086       t1 = BRep_Tool::Tolerance(v1);
1087       t2 = BRep_Tool::Tolerance(v2);
1088       p1 = BRep_Tool::Pnt(v1);
1089       p2 = BRep_Tool::Pnt(v2);
1090       v1OK = p1.Distance(ptprev)<=t1;
1091       v2OK = p2.Distance(ptprev)<=t2;
1092       if (v1OK || v2OK) break;
1093     }    
1094     
1095     if (v1OK) {
1096       if (!FirstOK) {
1097         dp = p2.Distance(Firstpoint);
1098         if(dp <= 2*t2) {
1099           FirstOK = Standard_True;
1100           BB.UpdateVertex(v2, dp);
1101         }
1102       }
1103       if (!LastOK) {
1104         dp = p2.Distance(Lastpoint);
1105         if(dp <= 2*t2) {
1106           LastOK = Standard_True;
1107           BB.UpdateVertex(v2, dp);
1108         }
1109       }
1110     }
1111     else if (v2OK) {
1112       if (!FirstOK) {
1113         dp = p1.Distance(Firstpoint);
1114         if(dp <= 2*t1) {
1115           FirstOK = Standard_True;
1116           BB.UpdateVertex(v1, dp);
1117         }
1118       }
1119       if (!LastOK) {
1120         dp = p1.Distance(Lastpoint);
1121         if(dp <= 2*t1) {
1122           LastOK = Standard_True;
1123           BB.UpdateVertex(v1, dp);
1124         }
1125       }
1126     }
1127     else {
1128       // end by chaining the section
1129       return Standard_False;
1130     }
1131     TopTools_ListOfShape thelist1;
1132     mySlface.Bind(CurrentFace, thelist1);
1133     mySlface(CurrentFace).Append(edg1);
1134     myListOfEdges.Append(edg1);
1135   }
1136
1137   return result;
1138   
1139 }
1140
1141 //=======================================================================
1142 //function : MajMap
1143 //purpose  : management of descendants
1144 //=======================================================================
1145
1146 static void MajMap(const TopoDS_Shape& theB,
1147                    const LocOpe_LinearForm& theP,
1148                    TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1149                    TopoDS_Shape& theFShape,  // myFShape
1150                    TopoDS_Shape& theLShape) // myLShape
1151 {
1152   TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
1153   if (exp.More()) {
1154     theFShape = exp.Current();
1155     TopTools_ListOfShape thelist;
1156     theMap.Bind(theFShape, thelist);
1157     for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
1158       theMap(theFShape).Append(exp.Current());
1159     }
1160   }
1161   
1162   exp.Init(theP.LastShape(),TopAbs_WIRE);
1163   if (exp.More()) {
1164     theLShape = exp.Current();
1165     TopTools_ListOfShape thelist1;
1166     theMap.Bind(theLShape, thelist1);
1167     for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1168       theMap(theLShape).Append(exp.Current());
1169     }
1170   }
1171   
1172   for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1173     if (!theMap.IsBound(exp.Current())) {
1174       TopTools_ListOfShape thelist2; 
1175       theMap.Bind(exp.Current(), thelist2);
1176       theMap(exp.Current()) = theP.Shapes(exp.Current());
1177     }
1178   }
1179 }
1180
1181 //=======================================================================
1182 //function : SetGluedFaces
1183 //purpose  : management of faces of gluing
1184 //=======================================================================
1185
1186 static void SetGluedFaces(const TopTools_DataMapOfShapeListOfShape& theSlmap,
1187                           LocOpe_LinearForm& thePrism,
1188                           TopTools_DataMapOfShapeShape& theMap)
1189 {
1190   // Slidings
1191   TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(theSlmap);
1192   if(!theSlmap.IsEmpty()) {
1193     for (; itm.More(); itm.Next()) {
1194       const TopoDS_Face& fac = TopoDS::Face(itm.Key());
1195       const TopTools_ListOfShape& ledg = itm.Value();
1196       TopTools_ListIteratorOfListOfShape it;
1197       for (it.Initialize(ledg); it.More(); it.Next()) {
1198         const TopTools_ListOfShape& gfac = thePrism.Shapes(it.Value());
1199         if (gfac.Extent() != 1) {
1200 #ifdef OCCT_DEBUG
1201           cout << "Pb SetGluedFace" << endl;
1202 #endif
1203         }
1204         theMap.Bind(gfac.First(),fac);
1205       }
1206     }
1207   }
1208 }
1209