+//=======================================================================
+//function : GlueFacesByList
+//purpose :
+//=======================================================================
+TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesByList (const TopoDS_Shape& theShape,
+ const Standard_Real theTolerance,
+ const Standard_Boolean doKeepNonSolids,
+ const TopTools_MapOfShape& aFaces)
+{
+ TopoDS_Shape aRes;
+
+ GEOMAlgo_Gluer1 aGluer;
+ GEOMAlgo_ListIteratorOfListOfCoupleOfShapes aItCS;
+ GEOMAlgo_CoupleOfShapes aCS;
+ GEOMAlgo_ListOfCoupleOfShapes aLCS;
+
+ aGluer.SetShape(theShape);
+ aGluer.SetTolerance(theTolerance);
+ aGluer.SetKeepNonSolids(doKeepNonSolids);
+ aGluer.Perform();
+ Standard_Integer iErr = aGluer.ErrorStatus();
+ if (iErr) return aRes;
+
+ TopTools_ListOfShape listShape;
+ const GEOMAlgo_ListOfCoupleOfShapes& aLCSG = aGluer.GluedFaces();
+ // Access to faces
+ aItCS.Initialize(aLCSG);
+ for (; aItCS.More(); aItCS.Next()) {
+ const GEOMAlgo_CoupleOfShapes& aCSG = aItCS.Value();
+ const TopoDS_Shape& aF1 = aCSG.Shape1();
+ const TopoDS_Shape& aF2 = aCSG.Shape2();
+ if (aFaces.Contains(aF1) || aFaces.Contains(aF2))
+ continue;
+ aCS.SetShapes(aF1,aF2);
+ aLCS.Append(aCS);
+ }
+
+ //cout<<"aLCS.Extent() = "<<aLCS.Extent()<<endl;
+ if (aLCS.Extent()>0) {
+ aGluer.SetFacesToUnglue(aLCS);
+ aGluer.UnglueFaces();
+ iErr = aGluer.ErrorStatus();
+ if (iErr) return aRes;
+ }
+
+ aRes = aGluer.Result();
+
+ return aRes;
+}
+*/
+
+//=======================================================================
+//function : GlueFaces
+//purpose :
+//=======================================================================
+TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
+ const Standard_Real theTolerance,
+ const Standard_Boolean doKeepNonSolids)
+{
+ TopoDS_Shape aRes;
+
+ GEOMAlgo_Gluer2 aGA;
+
+ // 1. Initialization
+ aGA.SetArgument(theShape);
+ aGA.SetTolerance(theTolerance);
+ aGA.SetKeepNonSolids(doKeepNonSolids);
+
+ // 2. Detect interferred shapes
+ aGA.Detect();
+ Standard_Integer iErr = aGA.ErrorStatus();
+ if (iErr) {
+ switch (iErr) {
+ case 11:
+ Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
+ break;
+ case 13:
+ case 14:
+ Standard_Failure::Raise("PerformImagesToWork failed");
+ break;
+ default:
+ {
+ // description of all errors see in GEOMAlgo_Gluer2.cxx
+ TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
+ aMsg += TCollection_AsciiString(iErr);
+ Standard_Failure::Raise(aMsg.ToCString());
+ break;
+ }
+ }
+ return aRes;
+ }
+
+ // 3. Set shapes to glue. If the operator is absent, the whole gluing will be done
+ //aGA.SetShapesToGlue(aMSG);
+
+ // 4. Gluing
+ aGA.Perform();
+ iErr = aGA.ErrorStatus();
+ if (iErr) {
+ switch (iErr) {
+ case 11:
+ Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
+ break;
+ case 13:
+ case 14:
+ Standard_Failure::Raise("PerformImagesToWork failed");
+ break;
+ default:
+ {
+ // description of all errors see in GEOMAlgo_Gluer2.cxx
+ TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
+ aMsg += TCollection_AsciiString(iErr);
+ Standard_Failure::Raise(aMsg.ToCString());
+ break;
+ }
+ }
+ return aRes;
+ }
+
+ Standard_Integer iWrn = aGA.WarningStatus();
+ if (iWrn) {
+ switch (iWrn) {
+ case 1:
+ MESSAGE("No shapes to glue");
+ break;
+ default:
+ // description of all warnings see in GEOMAlgo_Gluer2.cxx
+ MESSAGE("Warning in GEOMAlgo_Gluer2 with code " << iWrn);
+ break;
+ }
+ }
+
+ // 5. Result
+ aRes = aGA.Shape();
+
+ return aRes;
+}
+
+//=======================================================================
+//function : GlueWithWarnings
+//purpose :
+//=======================================================================
+TopoDS_Shape GEOMImpl_GlueDriver::GlueWithWarnings (const TopoDS_Shape& theShape,
+ const Standard_Real theTolerance,
+ const TopAbs_ShapeEnum theShapeType,
+ const Standard_Boolean doKeepNonSolids,
+ TCollection_AsciiString& theWarning) const
+{
+ TopoDS_Shape aRes;
+
+ GEOMAlgo_Gluer2 aGA;
+
+ // 1. Initialization
+ aGA.SetArgument(theShape);
+ aGA.SetTolerance(theTolerance);
+ aGA.SetKeepNonSolids(doKeepNonSolids);
+
+ // 2. Detect interferred shapes
+ aGA.Detect();
+ Standard_Integer iErr = aGA.ErrorStatus();
+ if (iErr) {
+ switch (iErr) {
+ case 11:
+ Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
+ break;
+ case 13:
+ case 14:
+ Standard_Failure::Raise("PerformImagesToWork failed");
+ break;
+ default:
+ {
+ // description of all errors see in GEOMAlgo_Gluer2.cxx
+ TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
+ aMsg += TCollection_AsciiString(iErr);
+ Standard_Failure::Raise(aMsg.ToCString());
+ break;
+ }
+ }
+ return aRes;
+ }
+
+ if (theShapeType != TopAbs_FACE) {
+ // 3. Fill shapes to glue aMSG
+ TopTools_DataMapOfShapeListOfShape aMSG;
+ const TopTools_DataMapOfShapeListOfShape& aMSD = aGA.ShapesDetected();
+ TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItMSD;
+ aItMSD.Initialize(aMSD);
+ for (; aItMSD.More(); aItMSD.Next()) {
+ const TopoDS_Shape& aSx = aItMSD.Key();
+ const TopTools_ListOfShape& aLSD = aItMSD.Value();
+ if (aSx.ShapeType() == theShapeType) {
+ aMSG.Bind(aSx, aLSD);
+ }
+ }
+
+ // 4. Set shapes to glue. If the operator is absent, the whole gluing will be done
+ aGA.SetShapesToGlue(aMSG);
+ }
+
+ // 5. Gluing
+ aGA.Perform();
+ iErr = aGA.ErrorStatus();
+ if (iErr) {
+ switch (iErr) {
+ case 11:
+ Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
+ break;
+ case 13:
+ case 14:
+ Standard_Failure::Raise("PerformImagesToWork failed");
+ break;
+ default:
+ {
+ // description of all errors see in GEOMAlgo_Gluer2.cxx
+ TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
+ aMsg += TCollection_AsciiString(iErr);
+ Standard_Failure::Raise(aMsg.ToCString());
+ break;
+ }
+ }
+ return aRes;
+ }
+
+ Standard_Integer iWrn = aGA.WarningStatus();
+ if (iWrn) {
+ switch (iWrn) {
+ case 1:
+ theWarning = "No shapes to glue";
+ break;
+ default:
+ // description of all warnings see in GEOMAlgo_Gluer2.cxx
+ theWarning = "Warning in GEOMAlgo_Gluer2 with code ";
+ theWarning += TCollection_AsciiString(iWrn);
+ break;
+ }
+ }
+
+ // 6. Result
+ aRes = aGA.Shape();
+
+ // 7. Fill history to be used by GetInPlace functionality
+ TopTools_IndexedMapOfShape aResIndices;
+ TopExp::MapShapes(aRes, aResIndices);
+
+ Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
+
+ // history for all argument shapes
+ TDF_LabelSequence aLabelSeq;
+ aFunction->GetDependency(aLabelSeq);
+ Standard_Integer nbArg = aLabelSeq.Length();
+
+ for (Standard_Integer iarg = 1; iarg <= nbArg; iarg++) {
+
+ TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg);
+
+ Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel);
+ TopoDS_Shape anArgumentShape = anArgumentObject->GetValue();
+
+ TopTools_IndexedMapOfShape anArgumentIndices;
+ TopExp::MapShapes(anArgumentShape, anArgumentIndices);
+ Standard_Integer nbArgumentEntities = anArgumentIndices.Extent();
+
+ // Find corresponding label in history
+ TDF_Label anArgumentHistoryLabel =
+ aFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_True);
+
+ for (Standard_Integer ie = 1; ie <= nbArgumentEntities; ie++) {
+ TopoDS_Shape anEntity = anArgumentIndices.FindKey(ie);
+ const TopTools_ListOfShape& aModified = aGA.Modified(anEntity);
+ Standard_Integer nbModified = aModified.Extent();
+
+ if (nbModified > 0) {
+ TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(ie, Standard_True);
+ Handle(TDataStd_IntegerArray) anAttr =
+ TDataStd_IntegerArray::Set(aWhatHistoryLabel, 1, nbModified);
+
+ TopTools_ListIteratorOfListOfShape itM (aModified);
+ for (int im = 1; itM.More(); itM.Next(), ++im) {
+ int id = aResIndices.FindIndex(itM.Value());
+ anAttr->SetValue(im, id);
+ }
+ }
+ }
+ }
+
+ return aRes;
+}
+
+//=======================================================================
+//function : GlueByList
+//purpose :
+//=======================================================================
+TopoDS_Shape GEOMImpl_GlueDriver::GlueByList (const TopoDS_Shape& theShape,
+ const Standard_Real theTolerance,
+ const Standard_Boolean doKeepNonSolids,
+ const TopTools_MapOfShape& theShapesList,
+ const Standard_Boolean doGlueAllEdges)
+{
+ TopoDS_Shape aRes;
+
+ GEOMAlgo_Gluer2 aGA;
+
+ // 1. Initialization
+ aGA.SetArgument(theShape);
+ aGA.SetTolerance(theTolerance);
+ aGA.SetKeepNonSolids(doKeepNonSolids);
+
+ // 2. Detect interferred shapes
+ aGA.Detect();
+ Standard_Integer iErr = aGA.ErrorStatus();
+ if (iErr) {
+ switch (iErr) {
+ case 11:
+ Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
+ break;
+ case 13:
+ case 14:
+ Standard_Failure::Raise("PerformImagesToWork failed");
+ break;
+ default:
+ {
+ // description of all errors see in GEOMAlgo_Gluer2.cxx
+ TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
+ aMsg += TCollection_AsciiString(iErr);
+ Standard_Failure::Raise(aMsg.ToCString());
+ break;
+ }
+ }
+ return aRes;
+ }
+
+ // 3. Fill shapes to glue aMSG
+ TopTools_DataMapOfShapeListOfShape aMSG;
+ const TopTools_DataMapOfShapeListOfShape& aMSD = aGA.ShapesDetected();
+ TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItMSD;
+ aItMSD.Initialize(aMSD);
+ for (; aItMSD.More(); aItMSD.Next()) {
+ const TopoDS_Shape& aSx = aItMSD.Key();
+ const TopTools_ListOfShape& aLSD = aItMSD.Value();
+ TopTools_ListIteratorOfListOfShape anItLSD (aLSD);
+ bool isToGlue = false;
+ if (doGlueAllEdges && aSx.ShapeType() == TopAbs_EDGE) {
+ isToGlue = true;
+ }
+ else {
+ for (; anItLSD.More() && !isToGlue; anItLSD.Next()) {
+ if (theShapesList.Contains(anItLSD.Value())) {
+ isToGlue = true;
+ }
+ }
+ }
+ if (isToGlue) {
+ aMSG.Bind(aSx, aLSD);
+ }
+ }
+
+ // 4. Set shapes to glue. If the operator is absent, the whole gluing will be done
+ aGA.SetShapesToGlue(aMSG);
+
+ // 5. Gluing
+ aGA.Perform();
+ iErr = aGA.ErrorStatus();
+ if (iErr) {
+ switch (iErr) {
+ case 11:
+ Standard_Failure::Raise("GEOMAlgo_GlueDetector failed");
+ break;
+ case 13:
+ case 14:
+ Standard_Failure::Raise("PerformImagesToWork failed");
+ break;
+ default:
+ {
+ // description of all errors see in GEOMAlgo_Gluer2.cxx
+ TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer2 with code ");
+ aMsg += TCollection_AsciiString(iErr);
+ Standard_Failure::Raise(aMsg.ToCString());
+ break;
+ }
+ }
+ return aRes;
+ }
+
+ Standard_Integer iWrn = aGA.WarningStatus();
+ if (iWrn) {
+ switch (iWrn) {
+ case 1:
+ MESSAGE("No shapes to glue");
+ break;
+ default:
+ // description of all warnings see in GEOMAlgo_Gluer2.cxx
+ MESSAGE("Warning in GEOMAlgo_Gluer2 with code " << iWrn);
+ break;
+ }
+ }
+
+ // 6. Result
+ aRes = aGA.Shape();
+
+ return aRes;
+}
+