- // prendre un premier shell dans la liste des shells
- // initialiser un compshell avec ce shell
- // tant qu'il reste des shells dans la liste
- // chercher un shell qui a des faces en commun avec le compshell
- // creer un BRepTools_Quilt
- // recenser les faces communes issues du compshell, les ajouter au quilt
- // recenser les faces restantes du shell a inclure, les ajouter au quilt
- // recenser les edges en double, a remplacer
- // pour chaque paire d'edge
- // tester l'orientation relative des aretes
- // bind dans le quilt de Eold.Forward et Enew.Forward (ou reverse)
- // recuperer le nouveau shell
- // l'incorporer dans le compshell
- // appliquer BRepTools_SameParameter au compshell
- // (rendre parametres 2D des edges identiques aux parametres 3D)
-
- TopoDS_Shape aShape;
-
- TopoDS_Compound C;
- BRep_Builder bu;
- bu.MakeCompound(C); // empty compound;
- TopTools_ListOfShape shellList;
- for (TopExp_Explorer exp (theShape, TopAbs_SHELL); exp.More(); exp.Next()) {
- const TopoDS_Shell& S = TopoDS::Shell(exp.Current());
- shellList.Append(S);
- }
- TopTools_ListIteratorOfListOfShape its (shellList);
- if (!its.More()) {
- Standard_ConstructionError::Raise("Glue aborted : no shell in shape");
- }
-
- TopoDS_Shell S = TopoDS::Shell(its.Value());
- bu.Add(C, S); // add first shell to compound
- shellList.Remove(its);
- bool shellAdded = true;
- bool bigTolerance = false;
-
- while ((shellList.Extent() > 0) && shellAdded) {
- shellAdded = false;
- its.Initialize(shellList);
- for (; its.More(); its.Next()) {
- S = TopoDS::Shell(its.Value());
-
- // compare tolerance with shape's size
- Bnd_Box aBox;
- BRepBndLib::Add(S, aBox);
- Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
- aBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
- Standard_Real aTolerance = theTolerance;
- if (aBox.IsXThin(100. * aTolerance))
- aTolerance = 0.01 * (Xmax - Xmin);
- if (aBox.IsYThin(100. * aTolerance))
- aTolerance = 0.01 * (Ymax - Ymin);
- if (aBox.IsZThin(100. * aTolerance))
- aTolerance = 0.01 * (Zmax - Zmin);
- if (theTolerance > aTolerance)
- bigTolerance = true;
-
- bool isConnected = false;
- TopTools_ListOfShape newEdges; // common edges from new compound
- TopTools_ListOfShape oldEdges; // common edges from face to add
- TopoDS_Compound CFN;
- TopoDS_Compound CFO;
- bu.MakeCompound(CFN); // empty compound for new faces
- bu.MakeCompound(CFO); // empty compound for old faces
-
- for (TopExp_Explorer exp (S, TopAbs_FACE); exp.More(); exp.Next()) {
- // try to find corresponding face in new compound
- TopoDS_Face F = TopoDS::Face(exp.Current());
- TopoDS_Face newFace = FindSameFace(C,F,aTolerance);
- if (! newFace.IsNull())
- {
- // face found
- isConnected = true;
- bu.Add(CFN, newFace); // common faces from new compound
- for (TopExp_Explorer ee (F, TopAbs_EDGE); ee.More(); ee.Next()) {
- // find edge pair
- TopoDS_Edge Eold = TopoDS::Edge(ee.Current());
- TopoDS_Edge Enew = FindSameEdge(newFace, Eold, aTolerance);
- if (Enew.IsNull()) {
- Standard_ConstructionError::Raise("Glue aborted : no same edge in same face");
- }
- oldEdges.Append(Eold);
- newEdges.Append(Enew);
- }
- } else {
- bu.Add(CFO, F); // not common faces from shell to add
- }
- }
- if (isConnected) {
- // some faces found
- shellAdded = true;
- BRepTools_Quilt glue;
- glue.Add(CFN);
- TopTools_ListIteratorOfListOfShape ito (oldEdges);
- TopTools_ListIteratorOfListOfShape itn (newEdges);
- for (; ito.More(); ito.Next()) {
- // bind
- glue.Bind(TopoDS::Edge(ito.Value()), TopoDS::Edge(itn.Value()));
- itn.Next();
- }
- glue.Add(CFO);
- TopoDS_Compound newc = TopoDS::Compound(glue.Shells());
- for (TopExp_Explorer exs (newc, TopAbs_SHELL); exs.More(); exs.Next()) {
- TopoDS_Shell NS = TopoDS::Shell(exs.Current());
- bu.Add(C, NS);
- }
- shellList.Remove(its);
- // remove shell from list
+ Standard_Integer iErr, iWrn;
+ TopoDS_Shape aRes;
+ GEOMAlgo_Gluer aGluer;
+
+ aGluer.SetShape(theShape);
+ aGluer.SetTolerance(theTolerance);
+ aGluer.SetCheckGeometry(Standard_True);
+ aGluer.SetKeepNonSolids(doKeepNonSolids);
+
+ aGluer.Perform();
+
+ iErr = aGluer.ErrorStatus();
+ if (iErr) {
+ switch (iErr) {
+ case 2:
+ Standard_Failure::Raise("No vertices found in source shape");
+ break;
+ case 5:
+ Standard_Failure::Raise("Source shape is Null");
+ break;
+ case 6:
+ Standard_Failure::Raise("Result shape is Null");
+ break;
+ case 200:
+ Standard_Failure::Raise("Error occured during check of geometric coincidence");
+ break;
+ default:
+ {
+ // description of all errors see in GEOMAlgo_Gluer.cxx
+ TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
+ aMsg += TCollection_AsciiString(iErr);
+ Standard_Failure::Raise(aMsg.ToCString());