Back to index

salome-geom  6.5.0
GEOMImpl_GlueDriver.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include <Standard_Stream.hxx>
00024 
00025 #include <GEOMImpl_GlueDriver.hxx>
00026 #include <GEOMImpl_IGlue.hxx>
00027 #include <GEOMImpl_Types.hxx>
00028 
00029 #include <GEOM_Object.hxx>
00030 #include <GEOM_Function.hxx>
00031 
00032 #include "GEOMAlgo_Gluer2.hxx"
00033 #include "GEOMAlgo_ListIteratorOfListOfCoupleOfShapes.hxx"
00034 #include "GEOMAlgo_CoupleOfShapes.hxx"
00035 #include "GEOMAlgo_ListOfCoupleOfShapes.hxx"
00036 
00037 #include <Basics_OCCTVersion.hxx>
00038 
00039 #include "utilities.h"
00040 
00041 #include <TDataStd_IntegerArray.hxx>
00042 
00043 #include <TopExp.hxx>
00044 #include <TopoDS_Shape.hxx>
00045 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
00046 #include <TopTools_IndexedMapOfShape.hxx>
00047 #include <TopTools_ListOfShape.hxx>
00048 #include <TopTools_ListIteratorOfListOfShape.hxx>
00049 
00050 #include <ShapeFix_Shape.hxx>
00051 
00052 #include <Standard_NullObject.hxx>
00053 #include <Standard_Failure.hxx>
00054 
00055 #define MSG_BAD_TOLERANCE "Tolerance is too big"
00056 #define MSG_BAD_ARG_SHAPE "Argument shape is not a compound of hexahedral solids"
00057 
00058 //=======================================================================
00059 //function : GEOMImpl_GlueDriver
00060 //purpose  :
00061 //=======================================================================
00062 GEOMImpl_GlueDriver::GEOMImpl_GlueDriver()
00063 {
00064 }
00065 
00066 //=======================================================================
00067 //function : GetID
00068 //purpose  :
00069 //=======================================================================
00070 const Standard_GUID& GEOMImpl_GlueDriver::GetID()
00071 {
00072   static Standard_GUID aGlueDriver("FF1BBB63-5D14-4df2-980B-3A668264EA16");
00073   return aGlueDriver;
00074 }
00075 
00076 //=======================================================================
00077 //function : GlueFacesWithWarnings
00078 //purpose  :
00079 //=======================================================================
00080 /*
00081 TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesWithWarnings (const TopoDS_Shape& theShape,
00082                                                          const Standard_Real theTolerance,
00083                                                          const Standard_Boolean doKeepNonSolids,
00084                                                          TCollection_AsciiString& theWarning) const
00085 {
00086   Standard_Integer iErr, iWrn;
00087   TopoDS_Shape aRes;
00088   GEOMAlgo_Gluer aGluer;
00089 
00090   aGluer.SetShape(theShape);
00091   aGluer.SetTolerance(theTolerance);
00092   aGluer.SetCheckGeometry(Standard_True);
00093   aGluer.SetKeepNonSolids(doKeepNonSolids);
00094 
00095   aGluer.Perform();
00096 
00097   iErr = aGluer.ErrorStatus();
00098   if (iErr) {
00099     switch (iErr) {
00100     case 2:
00101       Standard_Failure::Raise("No vertices found in source shape");
00102       break;
00103     case 3:
00104     case 4:
00105       Standard_Failure::Raise(MSG_BAD_TOLERANCE " or " MSG_BAD_ARG_SHAPE);
00106       break;
00107     case 5:
00108       Standard_Failure::Raise("Source shape is Null");
00109       break;
00110     case 6:
00111       Standard_Failure::Raise("Result shape is Null");
00112       break;
00113     case 100:
00114       Standard_Failure::Raise(MSG_BAD_TOLERANCE);
00115       break;
00116     case 101:
00117     case 102:
00118       Standard_Failure::Raise(MSG_BAD_ARG_SHAPE);
00119       break;
00120     case 200:
00121       Standard_Failure::Raise("Error occured during check of geometric coincidence");
00122       break;
00123     default:
00124       {
00125         // description of all errors see in GEOMAlgo_Gluer.cxx
00126         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
00127         aMsg += TCollection_AsciiString(iErr);
00128         Standard_Failure::Raise(aMsg.ToCString());
00129         break;
00130       }
00131     }
00132     return aRes;
00133   }
00134 
00135   iWrn = aGluer.WarningStatus();
00136   if (iWrn) {
00137     switch (iWrn) {
00138     case 1:
00139       {
00140         Standard_Integer nbAlone = aGluer.AloneShapes();
00141         theWarning = TCollection_AsciiString(nbAlone);
00142         theWarning += " solid(s) can not be glued by faces";
00143       }
00144       break;
00145     default:
00146       // description of all warnings see in GEOMAlgo_Gluer.cxx
00147       theWarning = "Warning in GEOMAlgo_Gluer with code ";
00148       theWarning += TCollection_AsciiString(iWrn);
00149       break;
00150     }
00151   }
00152 
00153   aRes = aGluer.Result();
00154 
00155   // SKL 18.01.2010 - patch for 20662
00156   Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aRes);
00157   aSfs->SetPrecision(Precision::Confusion());
00158   aSfs->Perform();
00159   aRes = aSfs->Shape();
00160 
00161   // Fill history to be used by GetInPlace functionality
00162   TopTools_IndexedMapOfShape aResIndices;
00163   TopExp::MapShapes(aRes, aResIndices);
00164 
00165   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00166 
00167   // history for all argument shapes
00168   TDF_LabelSequence aLabelSeq;
00169   aFunction->GetDependency(aLabelSeq);
00170   Standard_Integer nbArg = aLabelSeq.Length();
00171 
00172   for (Standard_Integer iarg = 1; iarg <= nbArg; iarg++) {
00173 
00174     TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg);
00175 
00176     Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel);
00177     TopoDS_Shape anArgumentShape = anArgumentObject->GetValue();
00178 
00179     TopTools_IndexedMapOfShape anArgumentIndices;
00180     TopExp::MapShapes(anArgumentShape, anArgumentIndices);
00181     Standard_Integer nbArgumentEntities = anArgumentIndices.Extent();
00182 
00183     // Find corresponding label in history
00184     TDF_Label anArgumentHistoryLabel =
00185       aFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_True);
00186 
00187     for (Standard_Integer ie = 1; ie <= nbArgumentEntities; ie++) {
00188       TopoDS_Shape anEntity = anArgumentIndices.FindKey(ie);
00189       const TopTools_ListOfShape& aModified = aGluer.Modified(anEntity);
00190       Standard_Integer nbModified = aModified.Extent();
00191 
00192       if (nbModified > 0) {
00193         TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(ie, Standard_True);
00194         Handle(TDataStd_IntegerArray) anAttr =
00195           TDataStd_IntegerArray::Set(aWhatHistoryLabel, 1, nbModified);
00196 
00197         TopTools_ListIteratorOfListOfShape itM (aModified);
00198         for (int im = 1; itM.More(); itM.Next(), ++im) {
00199           int id = aResIndices.FindIndex(itM.Value());
00200           anAttr->SetValue(im, id);
00201         }
00202       }
00203     }
00204   }
00205 
00206   return aRes;
00207 }
00208 
00209 //=======================================================================
00210 //function : GlueFaces
00211 //purpose  :
00212 //=======================================================================
00213 TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
00214                                              const Standard_Real theTolerance,
00215                                              const Standard_Boolean doKeepNonSolids)
00216 {
00217   TopoDS_Shape aRes;
00218   GEOMAlgo_Gluer aGluer;
00219 
00220   aGluer.SetShape(theShape);
00221   aGluer.SetTolerance(theTolerance);
00222   aGluer.SetCheckGeometry(Standard_True);
00223   aGluer.SetKeepNonSolids(doKeepNonSolids);
00224 
00225   aGluer.Perform();
00226 
00227   Standard_Integer iErr = aGluer.ErrorStatus();
00228   if (iErr) {
00229     switch (iErr) {
00230     case 2:
00231       Standard_Failure::Raise("No vertices found in source shape");
00232       break;
00233     case 5:
00234       Standard_Failure::Raise("Source shape is Null");
00235       break;
00236     case 6:
00237       Standard_Failure::Raise("Result shape is Null");
00238       break;
00239     case 200:
00240       Standard_Failure::Raise("Error occured during check of geometric coincidence");
00241       break;
00242     default:
00243       {
00244         // description of all errors see in GEOMAlgo_Gluer.cxx
00245         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
00246         aMsg += TCollection_AsciiString(iErr);
00247         Standard_Failure::Raise(aMsg.ToCString());
00248         break;
00249       }
00250     }
00251     return aRes;
00252   }
00253 
00254   Standard_Integer iWrn = aGluer.WarningStatus();
00255   if (iWrn) {
00256     switch (iWrn) {
00257     case 1:
00258       MESSAGE("Some shapes can not be glued by faces");
00259       break;
00260     default:
00261       // description of all warnings see in GEOMAlgo_Gluer.cxx
00262       MESSAGE("Warning in GEOMAlgo_Gluer with code " << iWrn);
00263       break;
00264     }
00265   }
00266 
00267   aRes = aGluer.Result();
00268 
00269   return aRes;
00270 }
00271 
00272 //=======================================================================
00273 //function : GlueFacesByList
00274 //purpose  :
00275 //=======================================================================
00276 TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesByList (const TopoDS_Shape& theShape,
00277                                                    const Standard_Real theTolerance,
00278                                                    const Standard_Boolean doKeepNonSolids,
00279                                                    const TopTools_MapOfShape& aFaces)
00280 {
00281   TopoDS_Shape aRes;
00282 
00283   GEOMAlgo_Gluer1 aGluer;
00284   GEOMAlgo_ListIteratorOfListOfCoupleOfShapes aItCS;
00285   GEOMAlgo_CoupleOfShapes aCS;
00286   GEOMAlgo_ListOfCoupleOfShapes aLCS;
00287 
00288   aGluer.SetShape(theShape);
00289   aGluer.SetTolerance(theTolerance);
00290   aGluer.SetKeepNonSolids(doKeepNonSolids);
00291   aGluer.Perform();
00292   Standard_Integer iErr = aGluer.ErrorStatus();
00293   if (iErr) return aRes;
00294 
00295   TopTools_ListOfShape listShape;
00296   const GEOMAlgo_ListOfCoupleOfShapes& aLCSG = aGluer.GluedFaces();
00297   // Access to faces
00298   aItCS.Initialize(aLCSG);
00299   for (; aItCS.More(); aItCS.Next()) {
00300     const GEOMAlgo_CoupleOfShapes& aCSG = aItCS.Value();
00301     const TopoDS_Shape& aF1 = aCSG.Shape1();
00302     const TopoDS_Shape& aF2 = aCSG.Shape2();
00303     if (aFaces.Contains(aF1) || aFaces.Contains(aF2))
00304       continue;
00305     aCS.SetShapes(aF1,aF2);
00306     aLCS.Append(aCS);
00307   }
00308 
00309   //cout<<"aLCS.Extent() = "<<aLCS.Extent()<<endl;
00310   if (aLCS.Extent()>0) {
00311     aGluer.SetFacesToUnglue(aLCS);
00312     aGluer.UnglueFaces();
00313     iErr = aGluer.ErrorStatus();
00314     if (iErr) return aRes;
00315   }
00316 
00317   aRes = aGluer.Result();
00318 
00319   return aRes;
00320 }
00321 */
00322 
00323 //=======================================================================
00324 //function : GlueFaces
00325 //purpose  :
00326 //=======================================================================
00327 TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
00328                                              const Standard_Real theTolerance,
00329                                              const Standard_Boolean doKeepNonSolids)
00330 {
00331   TopoDS_Shape aRes;
00332 
00333   GEOMAlgo_Gluer2 aGA;
00334 
00335   // 1. Initialization
00336   aGA.SetArgument(theShape);
00337   aGA.SetTolerance(theTolerance);
00338   aGA.SetKeepNonSolids(doKeepNonSolids);
00339 
00340   // 2. Detect interferred shapes
00341   aGA.Detect();
00342 
00343   //Standard_Integer iWrnDetect = aGA.WarningStatus();
00344   //if (iWrnDetect == 2) {
00345   //  Standard_Failure::Raise("GLUE_ERROR_STICKED_SHAPES");
00346   //}
00347 
00348   Standard_Integer iErr = aGA.ErrorStatus();
00349   if (iErr) {
00350     switch (iErr) {
00351     case 11:
00352       Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
00353       break;
00354     case 13:
00355     case 14:
00356       Standard_Failure::Raise("PerformImagesToWork failed");
00357       break;
00358     default:
00359       {
00360         // description of all errors see in GEOMAlgo_Gluer2.cxx
00361         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
00362         aMsg += TCollection_AsciiString(iErr);
00363         Standard_Failure::Raise(aMsg.ToCString());
00364         break;
00365       }
00366     }
00367     return aRes;
00368   }
00369 
00370   // 3. Set shapes to glue. If the operator is absent, the whole gluing will be done
00371   //aGA.SetShapesToGlue(aMSG);
00372 
00373   // 4. Gluing
00374   aGA.Perform();
00375   iErr = aGA.ErrorStatus();
00376   if (iErr) {
00377     switch (iErr) {
00378     case 11:
00379       Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
00380       break;
00381     case 13:
00382     case 14:
00383       Standard_Failure::Raise("PerformImagesToWork failed");
00384       break;
00385     default:
00386       {
00387         // description of all errors see in GEOMAlgo_Gluer2.cxx
00388         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
00389         aMsg += TCollection_AsciiString(iErr);
00390         Standard_Failure::Raise(aMsg.ToCString());
00391         break;
00392       }
00393     }
00394     return aRes;
00395   }
00396 
00397   Standard_Integer iWrn = aGA.WarningStatus();
00398   if (iWrn) {
00399     switch (iWrn) {
00400     case 1:
00401       MESSAGE("No shapes to glue");
00402       break;
00403     default:
00404       // description of all warnings see in GEOMAlgo_Gluer2.cxx
00405       MESSAGE("Warning in GEOMAlgo_Gluer2 with code " << iWrn);
00406       break;
00407     }
00408   }
00409 
00410   // 5. Result
00411   aRes = aGA.Shape();
00412 
00413   return aRes;
00414 }
00415 
00416 //=======================================================================
00417 //function : GlueWithWarnings
00418 //purpose  :
00419 //=======================================================================
00420 TopoDS_Shape GEOMImpl_GlueDriver::GlueWithWarnings (const TopoDS_Shape& theShape,
00421                                                     const Standard_Real theTolerance,
00422                                                     const TopAbs_ShapeEnum theShapeType,
00423                                                     const Standard_Boolean doKeepNonSolids,
00424                                                     TCollection_AsciiString& theWarning) const
00425 {
00426   TopoDS_Shape aRes;
00427 
00428   GEOMAlgo_Gluer2 aGA;
00429 
00430   // 1. Initialization
00431   aGA.SetArgument(theShape);
00432   aGA.SetTolerance(theTolerance);
00433   aGA.SetKeepNonSolids(doKeepNonSolids);
00434 
00435   // 2. Detect interferred shapes
00436   aGA.Detect();
00437 
00438   //modified by NIZNHY-PKV Tue Mar 13 14:07:12 2012f
00439 #if OCC_VERSION_LARGE > 0x06050200
00440   Standard_Integer iWrnDetect = aGA.WarningStatus();
00441   if (iWrnDetect == 2) {
00442     /*
00443     TopTools_ListIteratorOfListOfShape aItLS;
00444 
00445     // Sticked shapes are detected
00446     const TopTools_IndexedDataMapOfShapeListOfShape& aIDMSS = pGluer2->StickedShapes();
00447 
00448     Standard_Integer i, aNb = aIDMSS.Extent();
00449     for (i = 1; i <= aNb; ++i) {
00450       // ancestor aSa (edge, wire face,..)  
00451       const TopoDS_Shape& aSa = aIDMSS.FindKey(i); 
00452 
00453       // successors aSs (vertex, edge, ...)
00454       // of the ancestor that are sticked 
00455       // for given value of the tolerance
00456       const TopTools_ListOfShape& aLSS = aIDMSS.FindFromIndex(i);
00457       aItLS.Initialize(aLSS);
00458       for (; aItLS.More(); aItLS.Next()) {
00459        const TopoDS_Shape& aSs = aItLS.Value();
00460       }
00461     }
00462     */
00463     Standard_Failure::Raise("GLUE_ERROR_STICKED_SHAPES");
00464     //Standard_Failure::Raise("Sticked shapes are detected. The tolerance value is too big.");
00465     //theWarning = "Sticked shapes are detected. The tolerance value is too big.";
00466   }
00467 #endif
00468   //modified by NIZNHY-PKV Tue Mar 13 14:07:14 2012t
00469 
00470   Standard_Integer iErr = aGA.ErrorStatus();
00471   if (iErr) {
00472     switch (iErr) {
00473     case 11:
00474       Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
00475       break;
00476     case 13:
00477     case 14:
00478       Standard_Failure::Raise("PerformImagesToWork failed");
00479       break;
00480     default:
00481       {
00482         // description of all errors see in GEOMAlgo_Gluer2.cxx
00483         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
00484         aMsg += TCollection_AsciiString(iErr);
00485         Standard_Failure::Raise(aMsg.ToCString());
00486         break;
00487       }
00488     }
00489     return aRes;
00490   }
00491 
00492   if (theShapeType != TopAbs_FACE) {
00493     // 3. Fill shapes to glue aMSG
00494     TopTools_DataMapOfShapeListOfShape aMSG;
00495     const TopTools_DataMapOfShapeListOfShape& aMSD = aGA.ShapesDetected();
00496     TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItMSD;
00497     aItMSD.Initialize(aMSD);
00498     for (; aItMSD.More(); aItMSD.Next()) {
00499       const TopoDS_Shape& aSx = aItMSD.Key();
00500       const TopTools_ListOfShape& aLSD = aItMSD.Value();
00501       if (aSx.ShapeType() == theShapeType) {
00502         aMSG.Bind(aSx, aLSD);
00503       }
00504     }
00505 
00506     // 4. Set shapes to glue. If the operator is absent, the whole gluing will be done
00507     aGA.SetShapesToGlue(aMSG);
00508   }
00509 
00510   // 5. Gluing
00511   aGA.Perform();
00512   iErr = aGA.ErrorStatus();
00513   if (iErr) {
00514     switch (iErr) {
00515     case 11:
00516       Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
00517       break;
00518     case 13:
00519     case 14:
00520       Standard_Failure::Raise("PerformImagesToWork failed");
00521       break;
00522     default:
00523       {
00524         // description of all errors see in GEOMAlgo_Gluer2.cxx
00525         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
00526         aMsg += TCollection_AsciiString(iErr);
00527         Standard_Failure::Raise(aMsg.ToCString());
00528         break;
00529       }
00530     }
00531     return aRes;
00532   }
00533 
00534   Standard_Integer iWrn = aGA.WarningStatus();
00535   if (iWrn) {
00536     switch (iWrn) {
00537     case 1:
00538       theWarning = "No shapes to glue";
00539       break;
00540     default:
00541       // description of all warnings see in GEOMAlgo_Gluer2.cxx
00542       theWarning = "Warning in GEOMAlgo_Gluer2 with code ";
00543       theWarning += TCollection_AsciiString(iWrn);
00544       break;
00545     }
00546   }
00547 
00548   // 6. Result
00549   aRes = aGA.Shape();
00550 
00551   // 7. Fill history to be used by GetInPlace functionality
00552   TopTools_IndexedMapOfShape aResIndices;
00553   TopExp::MapShapes(aRes, aResIndices);
00554 
00555   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00556 
00557   // history for all argument shapes
00558   TDF_LabelSequence aLabelSeq;
00559   aFunction->GetDependency(aLabelSeq);
00560   Standard_Integer nbArg = aLabelSeq.Length();
00561 
00562   for (Standard_Integer iarg = 1; iarg <= nbArg; iarg++) {
00563 
00564     TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg);
00565 
00566     Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel);
00567     TopoDS_Shape anArgumentShape = anArgumentObject->GetValue();
00568 
00569     TopTools_IndexedMapOfShape anArgumentIndices;
00570     TopExp::MapShapes(anArgumentShape, anArgumentIndices);
00571     Standard_Integer nbArgumentEntities = anArgumentIndices.Extent();
00572 
00573     // Find corresponding label in history
00574     TDF_Label anArgumentHistoryLabel =
00575       aFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_True);
00576 
00577     for (Standard_Integer ie = 1; ie <= nbArgumentEntities; ie++) {
00578       TopoDS_Shape anEntity = anArgumentIndices.FindKey(ie);
00579       const TopTools_ListOfShape& aModified = aGA.Modified(anEntity);
00580       Standard_Integer nbModified = aModified.Extent();
00581 
00582       if (nbModified > 0) {
00583         TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(ie, Standard_True);
00584         Handle(TDataStd_IntegerArray) anAttr =
00585           TDataStd_IntegerArray::Set(aWhatHistoryLabel, 1, nbModified);
00586 
00587         TopTools_ListIteratorOfListOfShape itM (aModified);
00588         for (int im = 1; itM.More(); itM.Next(), ++im) {
00589           int id = aResIndices.FindIndex(itM.Value());
00590           anAttr->SetValue(im, id);
00591         }
00592       }
00593     }
00594   }
00595 
00596   return aRes;
00597 }
00598 
00599 //=======================================================================
00600 //function : GlueByList
00601 //purpose  :
00602 //=======================================================================
00603 TopoDS_Shape GEOMImpl_GlueDriver::GlueByList (const TopoDS_Shape& theShape,
00604                                               const Standard_Real theTolerance,
00605                                               const Standard_Boolean doKeepNonSolids,
00606                                               const TopTools_MapOfShape& theShapesList,
00607                                               const Standard_Boolean doGlueAllEdges)
00608 {
00609   TopoDS_Shape aRes;
00610 
00611   GEOMAlgo_Gluer2 aGA;
00612 
00613   // 1. Initialization
00614   aGA.SetArgument(theShape);
00615   aGA.SetTolerance(theTolerance);
00616   aGA.SetKeepNonSolids(doKeepNonSolids);
00617 
00618   // 2. Detect interferred shapes
00619   aGA.Detect();
00620   Standard_Integer iErr = aGA.ErrorStatus();
00621   if (iErr) {
00622     switch (iErr) {
00623     case 11:
00624       Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
00625       break;
00626     case 13:
00627     case 14:
00628       Standard_Failure::Raise("PerformImagesToWork failed");
00629       break;
00630     default:
00631       {
00632         // description of all errors see in GEOMAlgo_Gluer2.cxx
00633         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
00634         aMsg += TCollection_AsciiString(iErr);
00635         Standard_Failure::Raise(aMsg.ToCString());
00636         break;
00637       }
00638     }
00639     return aRes;
00640   }
00641 
00642   // 3. Fill shapes to glue aMSG
00643   TopTools_DataMapOfShapeListOfShape aMSG;
00644   const TopTools_DataMapOfShapeListOfShape& aMSD = aGA.ShapesDetected();
00645   TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItMSD;
00646   aItMSD.Initialize(aMSD);
00647   for (; aItMSD.More(); aItMSD.Next()) {
00648     const TopoDS_Shape& aSx = aItMSD.Key();
00649     const TopTools_ListOfShape& aLSD = aItMSD.Value();
00650     TopTools_ListIteratorOfListOfShape anItLSD (aLSD);
00651     bool isToGlue = false;
00652     if (doGlueAllEdges && aSx.ShapeType() == TopAbs_EDGE) {
00653       isToGlue = true;
00654     }
00655     else {
00656       for (; anItLSD.More() && !isToGlue; anItLSD.Next()) {
00657         if (theShapesList.Contains(anItLSD.Value())) {
00658           isToGlue = true;
00659         }
00660       }
00661     }
00662     if (isToGlue) {
00663       aMSG.Bind(aSx, aLSD);
00664     }
00665   }
00666 
00667   // 4. Set shapes to glue. If the operator is absent, the whole gluing will be done
00668   aGA.SetShapesToGlue(aMSG);
00669 
00670   // 5. Gluing
00671   aGA.Perform();
00672   iErr = aGA.ErrorStatus();
00673   if (iErr) {
00674     switch (iErr) {
00675     case 11:
00676       Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
00677       break;
00678     case 13:
00679     case 14:
00680       Standard_Failure::Raise("PerformImagesToWork failed");
00681       break;
00682     default:
00683       {
00684         // description of all errors see in GEOMAlgo_Gluer2.cxx
00685         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
00686         aMsg += TCollection_AsciiString(iErr);
00687         Standard_Failure::Raise(aMsg.ToCString());
00688         break;
00689       }
00690     }
00691     return aRes;
00692   }
00693 
00694   Standard_Integer iWrn = aGA.WarningStatus();
00695   if (iWrn) {
00696     switch (iWrn) {
00697     case 1:
00698       MESSAGE("No shapes to glue");
00699       break;
00700     default:
00701       // description of all warnings see in GEOMAlgo_Gluer2.cxx
00702       MESSAGE("Warning in GEOMAlgo_Gluer2 with code " << iWrn);
00703       break;
00704     }
00705   }
00706 
00707   // 6. Result
00708   aRes = aGA.Shape();
00709 
00710   return aRes;
00711 }
00712 
00713 //=======================================================================
00714 //function : Execute
00715 //purpose  :
00716 //=======================================================================
00717 Standard_Integer GEOMImpl_GlueDriver::Execute(TFunction_Logbook& log) const
00718 {
00719   if (Label().IsNull()) return 0;
00720   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00721 
00722   GEOMImpl_IGlue aCI (aFunction);
00723   Standard_Integer aType = aFunction->GetType();
00724 
00725   TopoDS_Shape aShape;
00726   TCollection_AsciiString aWrn;
00727 
00728   Handle(GEOM_Function) aRefBase = aCI.GetBase();
00729   TopoDS_Shape aShapeBase = aRefBase->GetValue();
00730   if (aShapeBase.IsNull()) {
00731     Standard_NullObject::Raise("Shape for gluing is null");
00732   }
00733 
00734   Standard_Real tol3d = aCI.GetTolerance();
00735 
00736   Standard_Boolean aKeepNonSolids = aCI.GetKeepNonSolids();
00737 
00738   if (aType == GLUE_FACES) {
00739     //aShape = GlueFacesWithWarnings(aShapeBase, tol3d, aKeepNonSolids, aWrn);
00740     aShape = GlueWithWarnings(aShapeBase, tol3d, TopAbs_FACE, aKeepNonSolids, aWrn);
00741   }
00742   else if (aType == GLUE_EDGES) {
00743     aShape = GlueWithWarnings(aShapeBase, tol3d, TopAbs_EDGE, aKeepNonSolids, aWrn);
00744   }
00745   else if (aType == GLUE_FACES_BY_LIST || aType == GLUE_EDGES_BY_LIST) {
00746     Handle(TColStd_HSequenceOfTransient) SF = aCI.GetFaces();
00747     TopTools_MapOfShape aFaces;
00748     int i = 1;
00749     for (; i <= SF->Length(); i++) {
00750       Handle(Standard_Transient) anItem = SF->Value(i);
00751       if (anItem.IsNull())
00752         continue;
00753       Handle(GEOM_Function) aRefSh = Handle(GEOM_Function)::DownCast(anItem);
00754       if (aRefSh.IsNull())
00755         continue;
00756       TopoDS_Shape aFace = aRefSh->GetValue();
00757       if (aFace.IsNull())
00758         continue;
00759       if (!aFaces.Contains(aFace))
00760         aFaces.Add(aFace);
00761     }
00762 
00763     Standard_Boolean aGlueAllEdges = Standard_False;
00764     if (aType == GLUE_FACES_BY_LIST)
00765       aGlueAllEdges = aCI.GetGlueAllEdges();
00766 
00767     //aShape = GlueFacesByList(aShapeBase, tol3d, aKeepNonSolids, aFaces);
00768     aShape = GlueByList(aShapeBase, tol3d, aKeepNonSolids, aFaces, aGlueAllEdges);
00769   }
00770 
00771   if (aShape.IsNull()) return 0;
00772 
00773   aFunction->SetValue(aShape);
00774 
00775   log.SetTouched(Label());
00776 
00777   if (!aWrn.IsEmpty()) {
00778     Standard_Failure::Raise(aWrn.ToCString());
00779   }
00780 
00781   return 1;
00782 }
00783 
00784 //=======================================================================
00785 //function :  GEOMImpl_GlueDriver_Type_
00786 //purpose  :
00787 //=======================================================================
00788 Standard_EXPORT Handle_Standard_Type& GEOMImpl_GlueDriver_Type_()
00789 {
00790 
00791   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00792   if (aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00793   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00794   if (aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
00795   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00796   if (aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00797 
00798 
00799   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00800   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_GlueDriver",
00801                                                          sizeof(GEOMImpl_GlueDriver),
00802                                                          1,
00803                                                          (Standard_Address)_Ancestors,
00804                                                          (Standard_Address)NULL);
00805 
00806   return _aType;
00807 }
00808 
00809 //=======================================================================
00810 //function : DownCast
00811 //purpose  :
00812 //=======================================================================
00813 const Handle(GEOMImpl_GlueDriver) Handle(GEOMImpl_GlueDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00814 {
00815   Handle(GEOMImpl_GlueDriver) _anOtherObject;
00816 
00817   if (!AnObject.IsNull()) {
00818      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_GlueDriver))) {
00819        _anOtherObject = Handle(GEOMImpl_GlueDriver)((Handle(GEOMImpl_GlueDriver)&)AnObject);
00820      }
00821   }
00822 
00823   return _anOtherObject;
00824 }