-// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+#include <Basics_OCCTVersion.hxx>
+
#include <GEOMImpl_IMeasureOperations.hxx>
#include <GEOMImpl_IMeasure.hxx>
#include <GEOMImpl_MeasureDriver.hxx>
#include <GEOMAlgo_AlgoTools.hxx>
#include <GEOMAlgo_KindOfName.hxx>
#include <GEOMAlgo_ShapeInfoFiller.hxx>
-#include <OCC2VTK_Tools.h>
#include <GEOM_PythonDump.hxx>
#include <BOPCol_ListOfShape.hxx>
#include <BOPDS_DS.hxx>
#include <BOPDS_MapOfPassKey.hxx>
+#if OCC_VERSION_LARGE > 0x07010000
+#include <BOPDS_MapOfPair.hxx>
+#include <BOPDS_Pair.hxx>
+#endif
#include <BRepBndLib.hxx>
#include <BRepBuilderAPI_Copy.hxx>
#include <BRepCheck_ListIteratorOfListOfStatus.hxx>
#include <BRepClass_FaceClassifier.hxx>
#include <BRepExtrema_DistShapeShape.hxx>
#include <BRepExtrema_ShapeProximity.hxx>
+#if OCC_VERSION_LARGE > 0x06090000
+#include <BRepExtrema_SelfIntersection.hxx>
+#include <BRepExtrema_MapOfIntegerPackedMapOfInteger.hxx>
+#endif
#include <BRepGProp.hxx>
#include <BRepTools.hxx>
#include <BRep_Tool.hxx>
#include <GeomAPI_ProjectPointOnSurf.hxx>
#include <GeomLProp_CLProps.hxx>
#include <GeomLProp_SLProps.hxx>
+#include <Geom_Plane.hxx>
#include <GProp_GProps.hxx>
#include <GProp_PrincipalProps.hxx>
#include <ShapeAnalysis.hxx>
#include <TopoDS_Edge.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape.hxx>
+#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
+#include <set>
+
//=============================================================================
/*!
* Constructor
}
const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
+ // specific processing for some "advandced" objects
+ switch ( geom_type ) {
+ case GEOM_MARKER:
+ // local coordinate systen
+ // (+) geompy.kind.LCS xc yc zc xx xy xz yx yy yz zx zy zz
+
+ TopoDS_Face aFace = TopoDS::Face( aShape );
+ Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
+ gp_Pnt aC = aPlane->Pln().Location();
+ gp_Ax3 anAx3 = aPlane->Pln().Position();
+
+ theDoubles->Append(aC.X());
+ theDoubles->Append(aC.Y());
+ theDoubles->Append(aC.Z());
+
+ gp_Dir aD = anAx3.XDirection();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+ aD = anAx3.YDirection();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+ aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ SetErrorCode(OK);
+ return SK_LCS;
+ }
+
// Interprete results
TopAbs_ShapeEnum aType = anInfo.Type();
switch (aType)
theDoubles->Append(aD.X());
theDoubles->Append(aD.Y());
theDoubles->Append(aD.Z());
+
+ if (anInfo.KindOfBounds() != GEOMAlgo_KB_INFINITE)
+ {
+ // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
+ aKind = SK_PLANAR;
+
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
+ }
}
break;
default:
- if (anInfo.KindOfShape() == GEOMAlgo_KS_PLANE) {
- // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
-
- aKind = SK_PLANAR;
-
- gp_Pnt aC = anInfo.Location();
- theDoubles->Append(aC.X());
- theDoubles->Append(aC.Y());
- theDoubles->Append(aC.Z());
-
- gp_Ax3 anAx3 = anInfo.Position();
- gp_Dir aD = anAx3.Direction();
- theDoubles->Append(aD.X());
- theDoubles->Append(aD.Y());
- theDoubles->Append(aD.Z());
-
- theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
- theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
- }
- else {
- // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
- // (+) geompy.kind.FACE nb_edges nb_vertices
-
- theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
- theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
- }
+ // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
+ // (+) geompy.kind.FACE nb_edges nb_vertices
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
}
}
break;
*/
//=============================================================================
void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
+ const Standard_Real theTolerance,
Standard_Real& theLength,
Standard_Real& theSurfArea,
Standard_Real& theVolume)
//Compute the parameters
GProp_GProps LProps, SProps;
+ Standard_Real anEps = theTolerance >= 0 ? theTolerance : 1.e-6;
try {
OCC_CATCH_SIGNALS;
- BRepGProp::LinearProperties(aShape, LProps);
+ BRepGProp::LinearProperties(aShape, LProps, Standard_True);
theLength = LProps.Mass();
- BRepGProp::SurfaceProperties(aShape, SProps);
+ BRepGProp::SurfaceProperties(aShape, SProps, anEps, Standard_True);
theSurfArea = SProps.Mass();
theVolume = 0.0;
if (aShape.ShapeType() < TopAbs_SHELL) {
for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
GProp_GProps VProps;
- BRepGProp::VolumeProperties(Exp.Current(), VProps);
+ BRepGProp::VolumeProperties(Exp.Current(), VProps, anEps, Standard_True);
theVolume += VProps.Mass();
}
}
if (aShape.ShapeType() == TopAbs_VERTEX ||
aShape.ShapeType() == TopAbs_EDGE ||
aShape.ShapeType() == TopAbs_WIRE) {
- BRepGProp::LinearProperties(aShape, System);
+ BRepGProp::LinearProperties(aShape, System, Standard_True);
} else if (aShape.ShapeType() == TopAbs_FACE ||
aShape.ShapeType() == TopAbs_SHELL) {
- BRepGProp::SurfaceProperties(aShape, System);
+ BRepGProp::SurfaceProperties(aShape, System, Standard_True);
} else {
- BRepGProp::VolumeProperties(aShape, System);
+ BRepGProp::VolumeProperties(aShape, System, Standard_True);
}
gp_Mat I = System.MatrixOfInertia();
Handle(TColStd_HSequenceOfInteger)& theIntersections)
{
SetErrorCode(KO);
- bool isGood = false;
if (theIntersections.IsNull())
theIntersections = new TColStd_HSequenceOfInteger;
theIntersections->Clear();
if (theShape.IsNull())
- return isGood;
+ return false;
Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
- if (aRefShape.IsNull()) return isGood;
+ if (aRefShape.IsNull()) return false;
TopoDS_Shape aShape = aRefShape->GetValue();
- if (aShape.IsNull()) return isGood;
+ if (aShape.IsNull()) return false;
// 0. Prepare data
TopoDS_Shape aScopy;
aCSI.Perform();
Standard_Integer iErr = aCSI.ErrorStatus();
- isGood = true;
//
Standard_Integer aNbS, n1, n2;
+#if OCC_VERSION_LARGE > 0x07010000
+ BOPDS_MapIteratorOfMapOfPair aItMPK;
+#else
BOPDS_MapIteratorMapOfPassKey aItMPK;
+#endif
//
// 2. Take the shapes from DS
const BOPDS_DS& aDS = aCSI.DS();
aNbS=aDS.NbShapes();
//
// 3. Get the pairs of interfered shapes
+#if OCC_VERSION_LARGE > 0x07010000
+ const BOPDS_MapOfPair& aMPK=aDS.Interferences();
+#else
const BOPDS_MapOfPassKey& aMPK=aDS.Interferences();
+#endif
aItMPK.Initialize(aMPK);
for (; aItMPK.More(); aItMPK.Next()) {
+#if OCC_VERSION_LARGE > 0x07010000
+ const BOPDS_Pair& aPK=aItMPK.Value();
+ aPK.Indices(n1, n2);
+#else
const BOPDS_PassKey& aPK=aItMPK.Value();
aPK.Ids(n1, n2);
+#endif
//
if (n1 > aNbS || n2 > aNbS){
return false; // Error
theIntersections->Append(anIndices.FindIndex(aS1));
theIntersections->Append(anIndices.FindIndex(aS2));
- isGood = false;
}
if (!iErr) {
SetErrorCode(OK);
}
- return isGood;
+ return theIntersections->IsEmpty();
+}
+
+//=============================================================================
+/*!
+ * CheckSelfIntersectionsFast
+ */
+//=============================================================================
+bool GEOMImpl_IMeasureOperations::CheckSelfIntersectionsFast
+ (Handle(GEOM_Object) theShape,
+ float theDeflection, double theTolerance,
+ Handle(TColStd_HSequenceOfInteger)& theIntersections)
+{
+ SetErrorCode(KO);
+
+ if (theIntersections.IsNull())
+ theIntersections = new TColStd_HSequenceOfInteger;
+ else
+ theIntersections->Clear();
+
+ if (theShape.IsNull())
+ return false;
+
+ Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
+ if (aRefShape.IsNull()) return false;
+
+ TopoDS_Shape aShape = aRefShape->GetValue();
+ if (aShape.IsNull()) return false;
+
+ // Prepare data
+ TopoDS_Shape aScopy;
+
+ GEOMAlgo_AlgoTools::CopyShape(aShape, aScopy);
+ GEOMUtils::MeshShape(aScopy, theDeflection);
+
+ // Map sub-shapes and their indices
+ TopTools_IndexedMapOfShape anIndices;
+ TopExp::MapShapes(aScopy, anIndices);
+
+#if OCC_VERSION_LARGE > 0x06090000
+ // Checker of fast interferences
+ BRepExtrema_SelfIntersection aTool(aScopy, (theTolerance <= 0.) ? 0.0 : theTolerance);
+
+ // Launch the checker
+ aTool.Perform();
+
+ const BRepExtrema_MapOfIntegerPackedMapOfInteger& intersections = aTool.OverlapElements();
+
+ std::set<Standard_Integer> processed;
+
+ for (BRepExtrema_MapOfIntegerPackedMapOfInteger::Iterator it(intersections); it.More(); it.Next()) {
+ Standard_Integer idxLeft = it.Key();
+ if (processed.count(idxLeft) > 0) continue; // already added
+ processed.insert(idxLeft);
+ const TColStd_PackedMapOfInteger& overlaps = it.Value();
+ for (TColStd_MapIteratorOfPackedMapOfInteger subit(overlaps); subit.More(); subit.Next()) {
+ Standard_Integer idxRight = subit.Key();
+ if (processed.count(idxRight) > 0) continue; // already added
+ const TopoDS_Shape& aS1 = aTool.GetSubShape(idxLeft);
+ const TopoDS_Shape& aS2 = aTool.GetSubShape(idxRight);
+ theIntersections->Append(anIndices.FindIndex(aS1));
+ theIntersections->Append(anIndices.FindIndex(aS2));
+ }
+ }
+
+ if (aTool.IsDone())
+ SetErrorCode(OK);
+#endif
+
+ return theIntersections->IsEmpty();
+}
+
+//=============================================================================
+/*!
+ * CheckBOPArguments
+ */
+//=============================================================================
+bool GEOMImpl_IMeasureOperations::CheckBOPArguments
+ (const Handle(GEOM_Object) &theShape)
+{
+ SetErrorCode(KO);
+
+ if (theShape.IsNull()) {
+ return false;
+ }
+
+ Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
+
+ if (aRefShape.IsNull()) {
+ return false;
+ }
+
+ TopoDS_Shape aShape = aRefShape->GetValue();
+
+ if (aShape.IsNull()) {
+ return false;
+ }
+
+ //Compute the parameters
+ bool isValid = GEOMUtils::CheckBOPArguments(aShape);
+
+ SetErrorCode(OK);
+
+ return isValid;
}
//=============================================================================
GEOMAlgo_AlgoTools::CopyShape(aShape1, aScopy1);
GEOMAlgo_AlgoTools::CopyShape(aShape2, aScopy2);
- float aDeflection = (theDeflection <= 0.) ? 0.001 : theDeflection;
- GEOM::MeshShape(aScopy1, aDeflection);
- GEOM::MeshShape(aScopy2, aDeflection);
+ GEOMUtils::MeshShape(aScopy1, theDeflection);
+ GEOMUtils::MeshShape(aScopy2, theDeflection);
//
// Map sub-shapes and their indices
TopTools_IndexedMapOfShape anIndices1, anIndices2;
aBSP.Perform();
// 2. Get sets of IDs of overlapped faces
- for (BRepExtrema_OverlappedSubShapes::Iterator anIt1 (aBSP.OverlapSubShapes1()); anIt1.More(); anIt1.Next()) {
+#if OCC_VERSION_LARGE > 0x06090000
+ for (BRepExtrema_MapOfIntegerPackedMapOfInteger::Iterator anIt1 (aBSP.OverlapSubShapes1()); anIt1.More(); anIt1.Next())
+#else
+ for (BRepExtrema_OverlappedSubShapes::Iterator anIt1 (aBSP.OverlapSubShapes1()); anIt1.More(); anIt1.Next())
+#endif
+ {
const TopoDS_Shape& aS1 = aBSP.GetSubShape1(anIt1.Key());
theIntersections1->Append(anIndices1.FindIndex(aS1));
}
- for (BRepExtrema_OverlappedSubShapes::Iterator anIt2 (aBSP.OverlapSubShapes2()); anIt2.More(); anIt2.Next()) {
+#if OCC_VERSION_LARGE > 0x06090000
+ for (BRepExtrema_MapOfIntegerPackedMapOfInteger::Iterator anIt2 (aBSP.OverlapSubShapes2()); anIt2.More(); anIt2.Next())
+#else
+ for (BRepExtrema_OverlappedSubShapes::Iterator anIt2 (aBSP.OverlapSubShapes2()); anIt2.More(); anIt2.Next())
+#endif
+ {
const TopoDS_Shape& aS2 = aBSP.GetSubShape2(anIt2.Key());
theIntersections2->Append(anIndices2.FindIndex(aS2));
}
return isGood;
}
+
//=============================================================================
/*!
* IsGoodForSolid