From 20d473776aa1d01d181cc3ee564462aeb8edff6e Mon Sep 17 00:00:00 2001 From: skv Date: Fri, 12 Dec 2014 12:04:55 +0300 Subject: [PATCH] GetInPlace method refactoring --- src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.cxx | 62 ++++++ src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.hxx | 14 +- src/GEOMImpl/GEOMImpl_CopyDriver.cxx | 73 ++------ src/GEOMImpl/GEOMImpl_CopyDriver.hxx | 33 +--- src/GEOMImpl/GEOMImpl_IShapesOperations.cxx | 198 +------------------- src/GEOMImpl/GEOMImpl_IShapesOperations.hxx | 9 +- 6 files changed, 95 insertions(+), 294 deletions(-) diff --git a/src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.cxx b/src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.cxx index bc5c709af..f531ba16e 100644 --- a/src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.cxx +++ b/src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.cxx @@ -25,6 +25,7 @@ #include +#include #include #include #include @@ -48,6 +49,67 @@ #include +//======================================================================= +//function : GetInPlace +//purpose : +//======================================================================= +Standard_Boolean GEOMAlgo_GetInPlaceAPI::GetInPlace + (const TopoDS_Shape &theWhere, + const TopoDS_Shape &theWhat, + GEOMAlgo_GetInPlace &theGIP) +{ + if (theWhere.IsNull() || theWhat.IsNull()) { + return Standard_False; + } + + // Compute confusion tolerance. + Standard_Real aTolConf = Precision::Confusion(); + Standard_Integer i; + + for (i = 0; i < 2; ++i) { + TopExp_Explorer anExp(i == 0 ? theWhere : theWhat, TopAbs_VERTEX); + + for (; anExp.More(); anExp.Next()) { + const TopoDS_Vertex aVtx = TopoDS::Vertex(anExp.Current()); + const Standard_Real aTolVtx = BRep_Tool::Tolerance(aVtx); + + if (aTolVtx > aTolConf) { + aTolConf = aTolVtx; + } + } + } + + // Compute mass tolerance. + Bnd_Box aBoundingBox; + Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; + Standard_Real aMassTol; + + BRepBndLib::Add(theWhere, aBoundingBox); + BRepBndLib::Add(theWhat, aBoundingBox); + aBoundingBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); + aMassTol = Max(aXmax - aXmin, aYmax - aYmin); + aMassTol = Max(aMassTol, aZmax - aZmin); + aMassTol *= aTolConf; + + // Searching for the sub-shapes inside the ShapeWhere shape + theGIP.SetTolerance(aTolConf); + theGIP.SetTolMass(aMassTol); + theGIP.SetTolCG(aTolConf); + + theGIP.SetArgument(theWhat); + theGIP.SetShapeWhere(theWhere); + + theGIP.Perform(); + + int iErr = theGIP.ErrorStatus(); + + if (iErr) { + return Standard_False; + } + + return Standard_True; +} + //======================================================================= //function : GetInPlaceOld //purpose : diff --git a/src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.hxx b/src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.hxx index 43a8d6e90..36ed52d46 100644 --- a/src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.hxx +++ b/src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.hxx @@ -29,6 +29,7 @@ #include +class GEOMAlgo_GetInPlace; class Handle_GEOM_Function; class BRepExtrema_DistShapeShape; class TopoDS_Face; @@ -48,6 +49,17 @@ class GEOMAlgo_GetInPlaceAPI public: + /** + * \brief New GetInPlace method implementation. + * Initializes the GEOMAlgo_GetInPlace object with correct parameters and + * performs computation (calls theGIP's method Perform. Returns + * Standard_True in face of success; Standard_False otherwise. + */ + Standard_EXPORT static Standard_Boolean GetInPlace + (const TopoDS_Shape &theWhere, + const TopoDS_Shape &theWhat, + GEOMAlgo_GetInPlace &theGIP); + /*! * \brief Old implementation of GetInPlace algoritm. * This method searches among sub shapes of the shape theWhere parts that are @@ -66,7 +78,7 @@ public: /** - * \brief GetInPlaceBy history method implementation. + * \brief GetInPlaceByHistory method implementation. * Returns Standard_True if something is found. Warning: theShapesInPlace * list is not cleared at first. */ diff --git a/src/GEOMImpl/GEOMImpl_CopyDriver.cxx b/src/GEOMImpl/GEOMImpl_CopyDriver.cxx index 09ea9bba5..427451f5e 100644 --- a/src/GEOMImpl/GEOMImpl_CopyDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_CopyDriver.cxx @@ -29,19 +29,11 @@ #include "GEOMAlgo_GetInPlace.hxx" #include "GEOMAlgo_GetInPlaceAPI.hxx" -#include -#include -#include -#include -#include -#include #include -#include -#include #include -#include #include #include +#include #include #include #include @@ -208,6 +200,7 @@ Standard_Integer GEOMImpl_CopyDriver::transferData(TFunction_Logbook& log) const GEOMImpl_ITransferData aTD2(aRef2); Standard_Integer i; Standard_Integer aNbShapes = anIndices1.Extent(); + TopTools_MapOfShape aMapFence; aDatumName->SetValue(DATUM_NAME_INDEX, "GEOM_TRANSFER_DATA_NAMES"); aDatumName->SetValue(DATUM_MATERIAL_INDEX, "GEOM_TRANSFER_DATA_MATERIALS"); @@ -232,7 +225,9 @@ Standard_Integer GEOMImpl_CopyDriver::transferData(TFunction_Logbook& log) const for (; anIt.More(); anIt.Next()) { const TopoDS_Shape &aShapeDest = anIt.Value(); - aTD2.SetName(aShapeDest, aName); + if (aMapFence.Add(aShapeDest)) { + aTD2.SetName(aShapeDest, aName); + } } } } @@ -252,7 +247,9 @@ Standard_Integer GEOMImpl_CopyDriver::transferData(TFunction_Logbook& log) const for (; anIt.More(); anIt.Next()) { const TopoDS_Shape &aShapeDest = anIt.Value(); - aTD2.SetMaterial(aShapeDest, aMaterial); + if (aMapFence.Add(aShapeDest)) { + aTD2.SetMaterial(aShapeDest, aMaterial); + } } } } @@ -279,66 +276,28 @@ Standard_Boolean GEOMImpl_CopyDriver::getInPlace const TopoDS_Shape &theDestinationShape, TopTools_IndexedDataMapOfShapeListOfShape &theMapSourceDest) const { - // Compute confusion tolerance. - Standard_Real aTolConf = Precision::Confusion(); - Standard_Integer i; - - for (i = 0; i < 2; ++i) { - TopExp_Explorer anExp - (i == 0 ? theSourceShape : theDestinationShape, TopAbs_VERTEX); - - for (; anExp.More(); anExp.Next()) { - const TopoDS_Vertex aVtx = TopoDS::Vertex(anExp.Current()); - const Standard_Real aTolVtx = BRep_Tool::Tolerance(aVtx); - - if (aTolVtx > aTolConf) { - aTolConf = aTolVtx; - } - } - } - - // Compute mass tolerance. - Bnd_Box aBoundingBox; - Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; - Standard_Real aMassTol; - - BRepBndLib::Add(theSourceShape, aBoundingBox); - BRepBndLib::Add(theDestinationShape, aBoundingBox); - aBoundingBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); - aMassTol = Max(aXmax - aXmin, aYmax - aYmin); - aMassTol = Max(aMassTol, aZmax - aZmin); - aMassTol *= aTolConf; - - // Searching for the sub-shapes inside the ShapeWhere shape + // Searching for the sub-shapes inside theDestinationShape shape GEOMAlgo_GetInPlace aGIP; - aGIP.SetTolerance(aTolConf); - aGIP.SetTolMass(aMassTol); - aGIP.SetTolCG(aTolConf); - - aGIP.SetArgument(theSourceShape); - aGIP.SetShapeWhere(theDestinationShape); - aGIP.Perform(); - - int iErr = aGIP.ErrorStatus(); - - if (iErr) { + if (!GEOMAlgo_GetInPlaceAPI::GetInPlace + (theDestinationShape, theSourceShape, aGIP)) { return Standard_False; } const GEOMAlgo_DataMapOfShapeMapOfShape &aShapesIn = aGIP.ShapesIn(); const GEOMAlgo_DataMapOfShapeMapOfShape &aShapesOn = aGIP.ShapesOn(); + Standard_Integer i; Standard_Integer j; Standard_Integer aNbShapes = theSourceIndices.Extent(); - for (j = 1; j <= aNbShapes; ++j) { - const TopoDS_Shape &aSource = theSourceIndices.FindKey(j); + for (i = 1; i <= aNbShapes; ++i) { + const TopoDS_Shape &aSource = theSourceIndices.FindKey(i); TopTools_ListOfShape aListShapes2; TopTools_MapOfShape aMapShapes2; - for (i = 0; i < 2; ++i) { + for (j = 0; j < 2; ++j) { const GEOMAlgo_DataMapOfShapeMapOfShape &aShapes2 = - i == 0 ? aShapesIn : aShapesOn; + j == 0 ? aShapesIn : aShapesOn; if (aShapes2.IsBound(aSource)) { const TopTools_MapOfShape &aMapShapesDest = diff --git a/src/GEOMImpl/GEOMImpl_CopyDriver.hxx b/src/GEOMImpl/GEOMImpl_CopyDriver.hxx index 4541b6ffa..602bc2ddc 100644 --- a/src/GEOMImpl/GEOMImpl_CopyDriver.hxx +++ b/src/GEOMImpl/GEOMImpl_CopyDriver.hxx @@ -26,41 +26,10 @@ #ifndef _GEOMImpl_CopyDriver_HeaderFile #define _GEOMImpl_CopyDriver_HeaderFile -#ifndef _TColStd_SequenceOfExtendedString_HeaderFile -#include -#endif -#ifndef _Standard_TypeMismatch_HeaderFile -#include -#endif - -#ifndef _Standard_HeaderFile -#include -#endif - -#ifndef _Standard_Macro_HeaderFile -#include -#endif -#ifndef _Standard_HeaderFile -#include -#endif -#ifndef _Standard_GUID_HeaderFile -#include -#endif - -#ifndef _TFunction_Driver_HeaderFile -#include -#endif -#ifndef _TFunction_Logbook_HeaderFile -#include -#endif -#ifndef _Standard_CString_HeaderFile -#include -#endif - -class TColStd_SequenceOfExtendedString; class TopoDS_Shape; class TopTools_IndexedDataMapOfShapeListOfShape; class TopTools_IndexedMapOfShape; +class Standard_GUID; #include "GEOM_BaseDriver.hxx" diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx index ac43bf39b..96ec73c87 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx @@ -53,63 +53,32 @@ #include "GEOMAlgo_ClsfBox.hxx" #include "GEOMAlgo_ClsfSolid.hxx" -//#include "GEOMAlgo_CoupleOfShapes.hxx" #include "GEOMAlgo_FinderShapeOn1.hxx" #include "GEOMAlgo_FinderShapeOnQuad.hxx" #include "GEOMAlgo_FinderShapeOn2.hxx" #include "GEOMAlgo_GetInPlace.hxx" #include "GEOMAlgo_GetInPlaceAPI.hxx" #include "GEOMAlgo_GlueDetector.hxx" -//#include "GEOMAlgo_ListIteratorOfListOfCoupleOfShapes.hxx" -//#include "GEOMAlgo_ListOfCoupleOfShapes.hxx" - -//#include #include -//#include -//#include #include #include -#include -//#include -//#include -//#include -#include -#include -#include -#include #include #include #include -#include -#include -#include -#include -#include -#include #include #include #include #include #include #include -#include #include -#include -#include #include #include -#include #include -#include -#include -#include -#include #include #include -#include -#include #include #include #include @@ -125,14 +94,10 @@ #include #include #include -#include #include #include -#include -#include -#include #include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC @@ -3791,130 +3756,6 @@ Handle(TColStd_HSequenceOfInteger) return aSeqOfIDs; } -//============================================================================= -/*! - * GetInPlaceOfShape - */ -//============================================================================= -static bool GetInPlaceOfShape (const Handle(GEOM_Function)& theWhereFunction, - const TopTools_IndexedMapOfShape& theWhereIndices, - const TopoDS_Shape& theWhat, - TColStd_ListOfInteger& theModifiedList) -{ - if (theWhereFunction.IsNull() || theWhat.IsNull()) return false; - - if (theWhereIndices.Contains(theWhat)) { - // entity was not changed by the operation - Standard_Integer aWhatIndex = theWhereIndices.FindIndex(theWhat); - theModifiedList.Append(aWhatIndex); - return true; - } - - // try to find in history - TDF_Label aHistoryLabel = theWhereFunction->GetHistoryEntry(Standard_False); - - // search in history for all argument shapes - Standard_Boolean isFound = Standard_False; - Standard_Boolean isGood = Standard_False; - - TDF_LabelSequence aLabelSeq; - theWhereFunction->GetDependency(aLabelSeq); - Standard_Integer nbArg = aLabelSeq.Length(); - - for (Standard_Integer iarg = 1; iarg <= nbArg && !isFound; 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); - - if (anArgumentIndices.Contains(theWhat)) { - isFound = Standard_True; - Standard_Integer aWhatIndex = anArgumentIndices.FindIndex(theWhat); - - // Find corresponding label in history - TDF_Label anArgumentHistoryLabel = - theWhereFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_False); - if (anArgumentHistoryLabel.IsNull()) { - // Lost History of operation argument. Possibly, all its entities was removed. - isGood = Standard_True; - } - else { - TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(aWhatIndex, Standard_False); - - if (aWhatHistoryLabel.IsNull()) { - // Removed entity ? Compound ? Compsolid ? Shell ? Wire - isGood = Standard_False; - } else { - Handle(TDataStd_IntegerArray) anIntegerArray; - if (!aWhatHistoryLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anIntegerArray)) { - //Error: Empty modifications history for the sought shape. - isGood = Standard_False; - } - else { - isGood = Standard_True; - Standard_Integer imod, aModifLen = anIntegerArray->Array()->Length(); - for (imod = 1; imod <= aModifLen; imod++) { - theModifiedList.Append(anIntegerArray->Array()->Value(imod)); - } - } - } - } - } - } - - isFound = isGood; - - if (!isFound) { - // try compound/compsolid/shell/wire element by element - bool isFoundAny = false; - TopTools_MapOfShape mapShape; - - if (theWhat.ShapeType() == TopAbs_COMPOUND || - theWhat.ShapeType() == TopAbs_COMPSOLID) { - // recursive processing of compound/compsolid - TopoDS_Iterator anIt (theWhat, Standard_True, Standard_True); - for (; anIt.More(); anIt.Next()) { - if (mapShape.Add(anIt.Value())) { - TopoDS_Shape curWhat = anIt.Value(); - isFoundAny = GetInPlaceOfShape(theWhereFunction, theWhereIndices, curWhat, theModifiedList); - if (isFoundAny) isFound = Standard_True; - } - } - } - else if (theWhat.ShapeType() == TopAbs_SHELL) { - // try to replace a shell by its faces images - TopExp_Explorer anExp (theWhat, TopAbs_FACE); - for (; anExp.More(); anExp.Next()) { - if (mapShape.Add(anExp.Current())) { - TopoDS_Shape curWhat = anExp.Current(); - isFoundAny = GetInPlaceOfShape(theWhereFunction, theWhereIndices, curWhat, theModifiedList); - if (isFoundAny) isFound = Standard_True; - } - } - } - else if (theWhat.ShapeType() == TopAbs_WIRE) { - // try to replace a wire by its edges images - TopExp_Explorer anExp (theWhat, TopAbs_EDGE); - for (; anExp.More(); anExp.Next()) { - if (mapShape.Add(anExp.Current())) { - TopoDS_Shape curWhat = anExp.Current(); - isFoundAny = GetInPlaceOfShape(theWhereFunction, theWhereIndices, curWhat, theModifiedList); - if (isFoundAny) isFound = Standard_True; - } - } - } - else { - // Removed entity - } - } - - return isFound; -} - //============================================================================= /*! * case GetInPlace: @@ -3936,47 +3777,10 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlace (Handle(GEOM_Object) return NULL; } - // Compute confusion tolerance. - Standard_Real aTolConf = Precision::Confusion(); - Standard_Integer i; - - for (i = 0; i < 2; ++i) { - TopExp_Explorer anExp(i == 0 ? aWhere : aWhat, TopAbs_VERTEX); - - for (; anExp.More(); anExp.Next()) { - const TopoDS_Vertex aVtx = TopoDS::Vertex(anExp.Current()); - const Standard_Real aTolVtx = BRep_Tool::Tolerance(aVtx); - - if (aTolVtx > aTolConf) { - aTolConf = aTolVtx; - } - } - } - - // Compute mass tolerance. - Bnd_Box aBoundingBox; - Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; - Standard_Real aMassTol; - - BRepBndLib::Add(aWhere, aBoundingBox); - BRepBndLib::Add(aWhat, aBoundingBox); - aBoundingBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); - aMassTol = Max(aXmax - aXmin, aYmax - aYmin); - aMassTol = Max(aMassTol, aZmax - aZmin); - aMassTol *= aTolConf; - // Searching for the sub-shapes inside the ShapeWhere shape GEOMAlgo_GetInPlace aGIP; - aGIP.SetTolerance(aTolConf); - aGIP.SetTolMass(aMassTol); - aGIP.SetTolCG(aTolConf); - - aGIP.SetArgument(aWhat); - aGIP.SetShapeWhere(aWhere); - aGIP.Perform(); - int iErr = aGIP.ErrorStatus(); - if (iErr) { + if (!GEOMAlgo_GetInPlaceAPI::GetInPlace(aWhere, aWhat, aGIP)) { SetErrorCode("Error in GEOMAlgo_GetInPlace"); return NULL; } diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx index 68543ebec..e536ca3c0 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx @@ -34,22 +34,17 @@ #include "GEOMAlgo_State.hxx" -#include -#include -#include #include #include -#include - -#include +#include #include -#include class GEOM_Engine; class Handle(GEOM_Object); class Handle(TColStd_HArray1OfInteger); +class TopoDS_Shape; class GEOMImpl_IShapesOperations : public GEOM_IOperations { -- 2.39.2