Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/geom.git] / src / GEOMImpl / GEOMImpl_GlueDriver.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <Standard_Stream.hxx>
24
25 #include <GEOMImpl_GlueDriver.hxx>
26 #include <GEOMImpl_IGlue.hxx>
27 #include <GEOMImpl_Types.hxx>
28
29 #include <GEOM_Object.hxx>
30 #include <GEOM_Function.hxx>
31
32 //#include <GEOMAlgo_Gluer.hxx>
33 //#include "GEOMAlgo_Gluer1.hxx"
34 #include "GEOMAlgo_Gluer2.hxx"
35 #include "GEOMAlgo_ListIteratorOfListOfCoupleOfShapes.hxx"
36 #include "GEOMAlgo_CoupleOfShapes.hxx"
37 #include "GEOMAlgo_ListOfCoupleOfShapes.hxx"
38
39 #include "utilities.h"
40
41 #include <TDataStd_IntegerArray.hxx>
42
43 #include <TopExp.hxx>
44 #include <TopoDS_Shape.hxx>
45 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
46 #include <TopTools_IndexedMapOfShape.hxx>
47 #include <TopTools_ListOfShape.hxx>
48 #include <TopTools_ListIteratorOfListOfShape.hxx>
49
50 #include <ShapeFix_Shape.hxx>
51
52 #include <Standard_NullObject.hxx>
53 #include <Standard_Failure.hxx>
54
55 #define MSG_BAD_TOLERANCE "Tolerance is too big"
56 #define MSG_BAD_ARG_SHAPE "Argument shape is not a compound of hexahedral solids"
57
58 //=======================================================================
59 //function : GEOMImpl_GlueDriver
60 //purpose  :
61 //=======================================================================
62 GEOMImpl_GlueDriver::GEOMImpl_GlueDriver()
63 {
64 }
65
66 //=======================================================================
67 //function : GetID
68 //purpose  :
69 //=======================================================================
70 const Standard_GUID& GEOMImpl_GlueDriver::GetID()
71 {
72   static Standard_GUID aGlueDriver("FF1BBB63-5D14-4df2-980B-3A668264EA16");
73   return aGlueDriver;
74 }
75
76 //=======================================================================
77 //function : GlueFacesWithWarnings
78 //purpose  :
79 //=======================================================================
80 /*
81 TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesWithWarnings (const TopoDS_Shape& theShape,
82                                                          const Standard_Real theTolerance,
83                                                          const Standard_Boolean doKeepNonSolids,
84                                                          TCollection_AsciiString& theWarning) const
85 {
86   Standard_Integer iErr, iWrn;
87   TopoDS_Shape aRes;
88   GEOMAlgo_Gluer aGluer;
89
90   aGluer.SetShape(theShape);
91   aGluer.SetTolerance(theTolerance);
92   aGluer.SetCheckGeometry(Standard_True);
93   aGluer.SetKeepNonSolids(doKeepNonSolids);
94
95   aGluer.Perform();
96
97   iErr = aGluer.ErrorStatus();
98   if (iErr) {
99     switch (iErr) {
100     case 2:
101       Standard_Failure::Raise("No vertices found in source shape");
102       break;
103     case 3:
104     case 4:
105       Standard_Failure::Raise(MSG_BAD_TOLERANCE " or " MSG_BAD_ARG_SHAPE);
106       break;
107     case 5:
108       Standard_Failure::Raise("Source shape is Null");
109       break;
110     case 6:
111       Standard_Failure::Raise("Result shape is Null");
112       break;
113     case 100:
114       Standard_Failure::Raise(MSG_BAD_TOLERANCE);
115       break;
116     case 101:
117     case 102:
118       Standard_Failure::Raise(MSG_BAD_ARG_SHAPE);
119       break;
120     case 200:
121       Standard_Failure::Raise("Error occured during check of geometric coincidence");
122       break;
123     default:
124       {
125         // description of all errors see in GEOMAlgo_Gluer.cxx
126         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
127         aMsg += TCollection_AsciiString(iErr);
128         Standard_Failure::Raise(aMsg.ToCString());
129         break;
130       }
131     }
132     return aRes;
133   }
134
135   iWrn = aGluer.WarningStatus();
136   if (iWrn) {
137     switch (iWrn) {
138     case 1:
139       {
140         Standard_Integer nbAlone = aGluer.AloneShapes();
141         theWarning = TCollection_AsciiString(nbAlone);
142         theWarning += " solid(s) can not be glued by faces";
143       }
144       break;
145     default:
146       // description of all warnings see in GEOMAlgo_Gluer.cxx
147       theWarning = "Warning in GEOMAlgo_Gluer with code ";
148       theWarning += TCollection_AsciiString(iWrn);
149       break;
150     }
151   }
152
153   aRes = aGluer.Result();
154
155   // SKL 18.01.2010 - patch for 20662
156   Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aRes);
157   aSfs->SetPrecision(Precision::Confusion());
158   aSfs->Perform();
159   aRes = aSfs->Shape();
160
161   // Fill history to be used by GetInPlace functionality
162   TopTools_IndexedMapOfShape aResIndices;
163   TopExp::MapShapes(aRes, aResIndices);
164
165   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
166
167   // history for all argument shapes
168   TDF_LabelSequence aLabelSeq;
169   aFunction->GetDependency(aLabelSeq);
170   Standard_Integer nbArg = aLabelSeq.Length();
171
172   for (Standard_Integer iarg = 1; iarg <= nbArg; iarg++) {
173
174     TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg);
175
176     Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel);
177     TopoDS_Shape anArgumentShape = anArgumentObject->GetValue();
178
179     TopTools_IndexedMapOfShape anArgumentIndices;
180     TopExp::MapShapes(anArgumentShape, anArgumentIndices);
181     Standard_Integer nbArgumentEntities = anArgumentIndices.Extent();
182
183     // Find corresponding label in history
184     TDF_Label anArgumentHistoryLabel =
185       aFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_True);
186
187     for (Standard_Integer ie = 1; ie <= nbArgumentEntities; ie++) {
188       TopoDS_Shape anEntity = anArgumentIndices.FindKey(ie);
189       const TopTools_ListOfShape& aModified = aGluer.Modified(anEntity);
190       Standard_Integer nbModified = aModified.Extent();
191
192       if (nbModified > 0) {
193         TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(ie, Standard_True);
194         Handle(TDataStd_IntegerArray) anAttr =
195           TDataStd_IntegerArray::Set(aWhatHistoryLabel, 1, nbModified);
196
197         TopTools_ListIteratorOfListOfShape itM (aModified);
198         for (int im = 1; itM.More(); itM.Next(), ++im) {
199           int id = aResIndices.FindIndex(itM.Value());
200           anAttr->SetValue(im, id);
201         }
202       }
203     }
204   }
205
206   return aRes;
207 }
208
209 //=======================================================================
210 //function : GlueFaces
211 //purpose  :
212 //=======================================================================
213 TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
214                                              const Standard_Real theTolerance,
215                                              const Standard_Boolean doKeepNonSolids)
216 {
217   TopoDS_Shape aRes;
218   GEOMAlgo_Gluer aGluer;
219
220   aGluer.SetShape(theShape);
221   aGluer.SetTolerance(theTolerance);
222   aGluer.SetCheckGeometry(Standard_True);
223   aGluer.SetKeepNonSolids(doKeepNonSolids);
224
225   aGluer.Perform();
226
227   Standard_Integer iErr = aGluer.ErrorStatus();
228   if (iErr) {
229     switch (iErr) {
230     case 2:
231       Standard_Failure::Raise("No vertices found in source shape");
232       break;
233     case 5:
234       Standard_Failure::Raise("Source shape is Null");
235       break;
236     case 6:
237       Standard_Failure::Raise("Result shape is Null");
238       break;
239     case 200:
240       Standard_Failure::Raise("Error occured during check of geometric coincidence");
241       break;
242     default:
243       {
244         // description of all errors see in GEOMAlgo_Gluer.cxx
245         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
246         aMsg += TCollection_AsciiString(iErr);
247         Standard_Failure::Raise(aMsg.ToCString());
248         break;
249       }
250     }
251     return aRes;
252   }
253
254   Standard_Integer iWrn = aGluer.WarningStatus();
255   if (iWrn) {
256     switch (iWrn) {
257     case 1:
258       MESSAGE("Some shapes can not be glued by faces");
259       break;
260     default:
261       // description of all warnings see in GEOMAlgo_Gluer.cxx
262       MESSAGE("Warning in GEOMAlgo_Gluer with code " << iWrn);
263       break;
264     }
265   }
266
267   aRes = aGluer.Result();
268
269   return aRes;
270 }
271
272 //=======================================================================
273 //function : GlueFacesByList
274 //purpose  :
275 //=======================================================================
276 TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesByList (const TopoDS_Shape& theShape,
277                                                    const Standard_Real theTolerance,
278                                                    const Standard_Boolean doKeepNonSolids,
279                                                    const TopTools_MapOfShape& aFaces)
280 {
281   TopoDS_Shape aRes;
282
283   GEOMAlgo_Gluer1 aGluer;
284   GEOMAlgo_ListIteratorOfListOfCoupleOfShapes aItCS;
285   GEOMAlgo_CoupleOfShapes aCS;
286   GEOMAlgo_ListOfCoupleOfShapes aLCS;
287
288   aGluer.SetShape(theShape);
289   aGluer.SetTolerance(theTolerance);
290   aGluer.SetKeepNonSolids(doKeepNonSolids);
291   aGluer.Perform();
292   Standard_Integer iErr = aGluer.ErrorStatus();
293   if (iErr) return aRes;
294
295   TopTools_ListOfShape listShape;
296   const GEOMAlgo_ListOfCoupleOfShapes& aLCSG = aGluer.GluedFaces();
297   // Access to faces
298   aItCS.Initialize(aLCSG);
299   for (; aItCS.More(); aItCS.Next()) {
300     const GEOMAlgo_CoupleOfShapes& aCSG = aItCS.Value();
301     const TopoDS_Shape& aF1 = aCSG.Shape1();
302     const TopoDS_Shape& aF2 = aCSG.Shape2();
303     if (aFaces.Contains(aF1) || aFaces.Contains(aF2))
304       continue;
305     aCS.SetShapes(aF1,aF2);
306     aLCS.Append(aCS);
307   }
308
309   //cout<<"aLCS.Extent() = "<<aLCS.Extent()<<endl;
310   if (aLCS.Extent()>0) {
311     aGluer.SetFacesToUnglue(aLCS);
312     aGluer.UnglueFaces();
313     iErr = aGluer.ErrorStatus();
314     if (iErr) return aRes;
315   }
316
317   aRes = aGluer.Result();
318
319   return aRes;
320 }
321 */
322
323 //=======================================================================
324 //function : GlueFaces
325 //purpose  :
326 //=======================================================================
327 TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
328                                              const Standard_Real theTolerance,
329                                              const Standard_Boolean doKeepNonSolids)
330 {
331   TopoDS_Shape aRes;
332
333   GEOMAlgo_Gluer2 aGA;
334
335   // 1. Initialization
336   aGA.SetArgument(theShape);
337   aGA.SetTolerance(theTolerance);
338   aGA.SetKeepNonSolids(doKeepNonSolids);
339
340   // 2. Detect interferred shapes
341   aGA.Detect();
342   Standard_Integer iErr = aGA.ErrorStatus();
343   if (iErr) {
344     switch (iErr) {
345     case 11:
346       Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
347       break;
348     case 13:
349     case 14:
350       Standard_Failure::Raise("PerformImagesToWork failed");
351       break;
352     default:
353       {
354         // description of all errors see in GEOMAlgo_Gluer2.cxx
355         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
356         aMsg += TCollection_AsciiString(iErr);
357         Standard_Failure::Raise(aMsg.ToCString());
358         break;
359       }
360     }
361     return aRes;
362   }
363
364   // 3. Set shapes to glue. If the operator is absent, the whole gluing will be done
365   //aGA.SetShapesToGlue(aMSG);
366
367   // 4. Gluing
368   aGA.Perform();
369   iErr = aGA.ErrorStatus();
370   if (iErr) {
371     switch (iErr) {
372     case 11:
373       Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
374       break;
375     case 13:
376     case 14:
377       Standard_Failure::Raise("PerformImagesToWork failed");
378       break;
379     default:
380       {
381         // description of all errors see in GEOMAlgo_Gluer2.cxx
382         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
383         aMsg += TCollection_AsciiString(iErr);
384         Standard_Failure::Raise(aMsg.ToCString());
385         break;
386       }
387     }
388     return aRes;
389   }
390
391   Standard_Integer iWrn = aGA.WarningStatus();
392   if (iWrn) {
393     switch (iWrn) {
394     case 1:
395       MESSAGE("No shapes to glue");
396       break;
397     default:
398       // description of all warnings see in GEOMAlgo_Gluer2.cxx
399       MESSAGE("Warning in GEOMAlgo_Gluer2 with code " << iWrn);
400       break;
401     }
402   }
403
404   // 5. Result
405   aRes = aGA.Shape();
406
407   return aRes;
408 }
409
410 //=======================================================================
411 //function : GlueWithWarnings
412 //purpose  :
413 //=======================================================================
414 TopoDS_Shape GEOMImpl_GlueDriver::GlueWithWarnings (const TopoDS_Shape& theShape,
415                                                     const Standard_Real theTolerance,
416                                                     const TopAbs_ShapeEnum theShapeType,
417                                                     const Standard_Boolean doKeepNonSolids,
418                                                     TCollection_AsciiString& theWarning) const
419 {
420   TopoDS_Shape aRes;
421
422   GEOMAlgo_Gluer2 aGA;
423
424   // 1. Initialization
425   aGA.SetArgument(theShape);
426   aGA.SetTolerance(theTolerance);
427   aGA.SetKeepNonSolids(doKeepNonSolids);
428
429   // 2. Detect interferred shapes
430   aGA.Detect();
431   Standard_Integer iErr = aGA.ErrorStatus();
432   if (iErr) {
433     switch (iErr) {
434     case 11:
435       Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
436       break;
437     case 13:
438     case 14:
439       Standard_Failure::Raise("PerformImagesToWork failed");
440       break;
441     default:
442       {
443         // description of all errors see in GEOMAlgo_Gluer2.cxx
444         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
445         aMsg += TCollection_AsciiString(iErr);
446         Standard_Failure::Raise(aMsg.ToCString());
447         break;
448       }
449     }
450     return aRes;
451   }
452
453   if (theShapeType != TopAbs_FACE) {
454     // 3. Fill shapes to glue aMSG
455     TopTools_DataMapOfShapeListOfShape aMSG;
456     const TopTools_DataMapOfShapeListOfShape& aMSD = aGA.ShapesDetected();
457     TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItMSD;
458     aItMSD.Initialize(aMSD);
459     for (; aItMSD.More(); aItMSD.Next()) {
460       const TopoDS_Shape& aSx = aItMSD.Key();
461       const TopTools_ListOfShape& aLSD = aItMSD.Value();
462       if (aSx.ShapeType() == theShapeType) {
463         aMSG.Bind(aSx, aLSD);
464       }
465     }
466
467     // 4. Set shapes to glue. If the operator is absent, the whole gluing will be done
468     aGA.SetShapesToGlue(aMSG);
469   }
470
471   // 5. Gluing
472   aGA.Perform();
473   iErr = aGA.ErrorStatus();
474   if (iErr) {
475     switch (iErr) {
476     case 11:
477       Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
478       break;
479     case 13:
480     case 14:
481       Standard_Failure::Raise("PerformImagesToWork failed");
482       break;
483     default:
484       {
485         // description of all errors see in GEOMAlgo_Gluer2.cxx
486         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
487         aMsg += TCollection_AsciiString(iErr);
488         Standard_Failure::Raise(aMsg.ToCString());
489         break;
490       }
491     }
492     return aRes;
493   }
494
495   Standard_Integer iWrn = aGA.WarningStatus();
496   if (iWrn) {
497     switch (iWrn) {
498     case 1:
499       theWarning = "No shapes to glue";
500       break;
501     default:
502       // description of all warnings see in GEOMAlgo_Gluer2.cxx
503       theWarning = "Warning in GEOMAlgo_Gluer2 with code ";
504       theWarning += TCollection_AsciiString(iWrn);
505       break;
506     }
507   }
508
509   // 6. Result
510   aRes = aGA.Shape();
511
512   // 7. Fill history to be used by GetInPlace functionality
513   TopTools_IndexedMapOfShape aResIndices;
514   TopExp::MapShapes(aRes, aResIndices);
515
516   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
517
518   // history for all argument shapes
519   TDF_LabelSequence aLabelSeq;
520   aFunction->GetDependency(aLabelSeq);
521   Standard_Integer nbArg = aLabelSeq.Length();
522
523   for (Standard_Integer iarg = 1; iarg <= nbArg; iarg++) {
524
525     TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg);
526
527     Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel);
528     TopoDS_Shape anArgumentShape = anArgumentObject->GetValue();
529
530     TopTools_IndexedMapOfShape anArgumentIndices;
531     TopExp::MapShapes(anArgumentShape, anArgumentIndices);
532     Standard_Integer nbArgumentEntities = anArgumentIndices.Extent();
533
534     // Find corresponding label in history
535     TDF_Label anArgumentHistoryLabel =
536       aFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_True);
537
538     for (Standard_Integer ie = 1; ie <= nbArgumentEntities; ie++) {
539       TopoDS_Shape anEntity = anArgumentIndices.FindKey(ie);
540       const TopTools_ListOfShape& aModified = aGA.Modified(anEntity);
541       Standard_Integer nbModified = aModified.Extent();
542
543       if (nbModified > 0) {
544         TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(ie, Standard_True);
545         Handle(TDataStd_IntegerArray) anAttr =
546           TDataStd_IntegerArray::Set(aWhatHistoryLabel, 1, nbModified);
547
548         TopTools_ListIteratorOfListOfShape itM (aModified);
549         for (int im = 1; itM.More(); itM.Next(), ++im) {
550           int id = aResIndices.FindIndex(itM.Value());
551           anAttr->SetValue(im, id);
552         }
553       }
554     }
555   }
556
557   return aRes;
558 }
559
560 //=======================================================================
561 //function : GlueByList
562 //purpose  :
563 //=======================================================================
564 TopoDS_Shape GEOMImpl_GlueDriver::GlueByList (const TopoDS_Shape& theShape,
565                                               const Standard_Real theTolerance,
566                                               const Standard_Boolean doKeepNonSolids,
567                                               const TopTools_MapOfShape& theShapesList,
568                                               const Standard_Boolean doGlueAllEdges)
569 {
570   TopoDS_Shape aRes;
571
572   GEOMAlgo_Gluer2 aGA;
573
574   // 1. Initialization
575   aGA.SetArgument(theShape);
576   aGA.SetTolerance(theTolerance);
577   aGA.SetKeepNonSolids(doKeepNonSolids);
578
579   // 2. Detect interferred shapes
580   aGA.Detect();
581   Standard_Integer iErr = aGA.ErrorStatus();
582   if (iErr) {
583     switch (iErr) {
584     case 11:
585       Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
586       break;
587     case 13:
588     case 14:
589       Standard_Failure::Raise("PerformImagesToWork failed");
590       break;
591     default:
592       {
593         // description of all errors see in GEOMAlgo_Gluer2.cxx
594         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
595         aMsg += TCollection_AsciiString(iErr);
596         Standard_Failure::Raise(aMsg.ToCString());
597         break;
598       }
599     }
600     return aRes;
601   }
602
603   // 3. Fill shapes to glue aMSG
604   TopTools_DataMapOfShapeListOfShape aMSG;
605   const TopTools_DataMapOfShapeListOfShape& aMSD = aGA.ShapesDetected();
606   TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItMSD;
607   aItMSD.Initialize(aMSD);
608   for (; aItMSD.More(); aItMSD.Next()) {
609     const TopoDS_Shape& aSx = aItMSD.Key();
610     const TopTools_ListOfShape& aLSD = aItMSD.Value();
611     TopTools_ListIteratorOfListOfShape anItLSD (aLSD);
612     bool isToGlue = false;
613     if (doGlueAllEdges && aSx.ShapeType() == TopAbs_EDGE) {
614       isToGlue = true;
615     }
616     else {
617       for (; anItLSD.More() && !isToGlue; anItLSD.Next()) {
618         if (theShapesList.Contains(anItLSD.Value())) {
619           isToGlue = true;
620         }
621       }
622     }
623     if (isToGlue) {
624       aMSG.Bind(aSx, aLSD);
625     }
626   }
627
628   // 4. Set shapes to glue. If the operator is absent, the whole gluing will be done
629   aGA.SetShapesToGlue(aMSG);
630
631   // 5. Gluing
632   aGA.Perform();
633   iErr = aGA.ErrorStatus();
634   if (iErr) {
635     switch (iErr) {
636     case 11:
637       Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
638       break;
639     case 13:
640     case 14:
641       Standard_Failure::Raise("PerformImagesToWork failed");
642       break;
643     default:
644       {
645         // description of all errors see in GEOMAlgo_Gluer2.cxx
646         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
647         aMsg += TCollection_AsciiString(iErr);
648         Standard_Failure::Raise(aMsg.ToCString());
649         break;
650       }
651     }
652     return aRes;
653   }
654
655   Standard_Integer iWrn = aGA.WarningStatus();
656   if (iWrn) {
657     switch (iWrn) {
658     case 1:
659       MESSAGE("No shapes to glue");
660       break;
661     default:
662       // description of all warnings see in GEOMAlgo_Gluer2.cxx
663       MESSAGE("Warning in GEOMAlgo_Gluer2 with code " << iWrn);
664       break;
665     }
666   }
667
668   // 6. Result
669   aRes = aGA.Shape();
670
671   return aRes;
672 }
673
674 //=======================================================================
675 //function : Execute
676 //purpose  :
677 //=======================================================================
678 Standard_Integer GEOMImpl_GlueDriver::Execute(TFunction_Logbook& log) const
679 {
680   if (Label().IsNull()) return 0;
681   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
682
683   GEOMImpl_IGlue aCI (aFunction);
684   Standard_Integer aType = aFunction->GetType();
685
686   TopoDS_Shape aShape;
687   TCollection_AsciiString aWrn;
688
689   Handle(GEOM_Function) aRefBase = aCI.GetBase();
690   TopoDS_Shape aShapeBase = aRefBase->GetValue();
691   if (aShapeBase.IsNull()) {
692     Standard_NullObject::Raise("Shape for gluing is null");
693   }
694
695   Standard_Real tol3d = aCI.GetTolerance();
696
697   Standard_Boolean aKeepNonSolids = aCI.GetKeepNonSolids();
698
699   if (aType == GLUE_FACES) {
700     //aShape = GlueFacesWithWarnings(aShapeBase, tol3d, aKeepNonSolids, aWrn);
701     aShape = GlueWithWarnings(aShapeBase, tol3d, TopAbs_FACE, aKeepNonSolids, aWrn);
702   }
703   else if (aType == GLUE_EDGES) {
704     aShape = GlueWithWarnings(aShapeBase, tol3d, TopAbs_EDGE, aKeepNonSolids, aWrn);
705   }
706   else if (aType == GLUE_FACES_BY_LIST || aType == GLUE_EDGES_BY_LIST) {
707     Handle(TColStd_HSequenceOfTransient) SF = aCI.GetFaces();
708     TopTools_MapOfShape aFaces;
709     int i = 1;
710     for (; i <= SF->Length(); i++) {
711       Handle(Standard_Transient) anItem = SF->Value(i);
712       if (anItem.IsNull())
713         continue;
714       Handle(GEOM_Function) aRefSh = Handle(GEOM_Function)::DownCast(anItem);
715       if (aRefSh.IsNull())
716         continue;
717       TopoDS_Shape aFace = aRefSh->GetValue();
718       if (aFace.IsNull())
719         continue;
720       if (!aFaces.Contains(aFace))
721         aFaces.Add(aFace);
722     }
723
724     Standard_Boolean aGlueAllEdges = Standard_False;
725     if (aType == GLUE_FACES_BY_LIST)
726       aGlueAllEdges = aCI.GetGlueAllEdges();
727
728     //aShape = GlueFacesByList(aShapeBase, tol3d, aKeepNonSolids, aFaces);
729     aShape = GlueByList(aShapeBase, tol3d, aKeepNonSolids, aFaces, aGlueAllEdges);
730   }
731
732   if (aShape.IsNull()) return 0;
733
734   aFunction->SetValue(aShape);
735
736   log.SetTouched(Label());
737
738   if (!aWrn.IsEmpty()) {
739     Standard_Failure::Raise(aWrn.ToCString());
740   }
741
742   return 1;
743 }
744
745 //=======================================================================
746 //function :  GEOMImpl_GlueDriver_Type_
747 //purpose  :
748 //=======================================================================
749 Standard_EXPORT Handle_Standard_Type& GEOMImpl_GlueDriver_Type_()
750 {
751
752   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
753   if (aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
754   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
755   if (aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
756   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
757   if (aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
758
759
760   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
761   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_GlueDriver",
762                                                          sizeof(GEOMImpl_GlueDriver),
763                                                          1,
764                                                          (Standard_Address)_Ancestors,
765                                                          (Standard_Address)NULL);
766
767   return _aType;
768 }
769
770 //=======================================================================
771 //function : DownCast
772 //purpose  :
773 //=======================================================================
774 const Handle(GEOMImpl_GlueDriver) Handle(GEOMImpl_GlueDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
775 {
776   Handle(GEOMImpl_GlueDriver) _anOtherObject;
777
778   if (!AnObject.IsNull()) {
779      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_GlueDriver))) {
780        _anOtherObject = Handle(GEOMImpl_GlueDriver)((Handle(GEOMImpl_GlueDriver)&)AnObject);
781      }
782   }
783
784   return _anOtherObject;
785 }