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