0020744: EDF 1272 GEOM : Get(Real?)type of an object

Additional point: add EnumToLong() function to convert enumerator values to the long values
This commit is contained in:
inv 2010-12-27 11:50:29 +00:00
parent aab55c4f10
commit e9605e4e5b
2 changed files with 22 additions and 13 deletions

View File

@ -39,5 +39,5 @@ for k in dir(geom):
if k[0] == '_':continue if k[0] == '_':continue
globals()[k]=getattr(geom,k) globals()[k]=getattr(geom,k)
del k del k
from geompyDC import ShapeType,GEOM,kind, info, PackData, ReadTexture from geompyDC import ShapeType, GEOM, kind, info, PackData, ReadTexture, EnumToLong

View File

@ -259,6 +259,14 @@ def ReadTexture(fname):
pass pass
return 0, 0, "" return 0, 0, ""
## Returns a long value from enumeration type
# Can be used for CORBA enumerator types like GEOM.shape_type
# @ingroup l1_geompy_auxiliary
def EnumToLong(theItem):
ret = theItem
if hasattr(theItem, "_v"): ret = theItem._v
return ret
## Kinds of shape enumeration ## Kinds of shape enumeration
# @ingroup l1_geompy_auxiliary # @ingroup l1_geompy_auxiliary
kind = GEOM.GEOM_IKindOfShape kind = GEOM.GEOM_IKindOfShape
@ -2256,8 +2264,8 @@ class geompyDC(GEOM._objref_GEOM_Gen):
# @param aType shape type # @param aType shape type
def ExtractShapes(self, aShape, aType, sorted = False): def ExtractShapes(self, aShape, aType, sorted = False):
ret = [] ret = []
t = aShape.GetShapeType()._v t = EnumToLong(aShape.GetShapeType())
if hasattr(aType, "_v"): aType = aType._v aType = EnumToLong(aType)
if t == aType: if t == aType:
ret.append(aShape ) ret.append(aShape )
elif sorted: elif sorted:
@ -2583,7 +2591,7 @@ class geompyDC(GEOM._objref_GEOM_Gen):
# automatic detection of the most appropriate shape limit type # automatic detection of the most appropriate shape limit type
lim = GEOM.SHAPE lim = GEOM.SHAPE
for s in ListShapes: lim = min( lim, s.GetMaxShapeType() ) for s in ListShapes: lim = min( lim, s.GetMaxShapeType() )
Limit = lim._v Limit = EnumToLong(lim)
pass pass
anObj = self.BoolOp.MakePartition(ListShapes, ListTools, anObj = self.BoolOp.MakePartition(ListShapes, ListTools,
ListKeepInside, ListRemoveInside, ListKeepInside, ListRemoveInside,
@ -2613,7 +2621,7 @@ class geompyDC(GEOM._objref_GEOM_Gen):
# automatic detection of the most appropriate shape limit type # automatic detection of the most appropriate shape limit type
lim = GEOM.SHAPE lim = GEOM.SHAPE
for s in ListShapes: lim = min( lim, s.GetMaxShapeType() ) for s in ListShapes: lim = min( lim, s.GetMaxShapeType() )
Limit = lim._v Limit = EnumToLong(lim)
pass pass
anObj = self.BoolOp.MakePartitionNonSelfIntersectedShape(ListShapes, ListTools, anObj = self.BoolOp.MakePartitionNonSelfIntersectedShape(ListShapes, ListTools,
ListKeepInside, ListRemoveInside, ListKeepInside, ListRemoveInside,
@ -3450,7 +3458,9 @@ class geompyDC(GEOM._objref_GEOM_Gen):
# Example: see GEOM_TestMeasures.py # Example: see GEOM_TestMeasures.py
listSh = self.SubShapeAllIDs(theShape, theType) listSh = self.SubShapeAllIDs(theShape, theType)
Nb = len(listSh) Nb = len(listSh)
if theShape.GetShapeType()._v == theType: t = EnumToLong(theShape.GetShapeType())
theType = EnumToLong(theType)
if t == theType:
Nb = Nb + 1 Nb = Nb + 1
pass pass
return Nb return Nb
@ -3465,15 +3475,14 @@ class geompyDC(GEOM._objref_GEOM_Gen):
# Example: see GEOM_TestMeasures.py # Example: see GEOM_TestMeasures.py
aDict = {} aDict = {}
for typeSh in ShapeType: for typeSh in ShapeType:
if typeSh != "AUTO" and typeSh != "SHAPE": if typeSh in ( "AUTO", "SHAPE" ): continue
listSh = self.SubShapeAllIDs(theShape, ShapeType[typeSh]) listSh = self.SubShapeAllIDs(theShape, ShapeType[typeSh])
Nb = len(listSh) Nb = len(listSh)
if theShape.GetShapeType()._v == ShapeType[typeSh]: if EnumToLon(theShape.GetShapeType()) == ShapeType[typeSh]:
Nb = Nb + 1 Nb = Nb + 1
pass pass
aDict[typeSh] = Nb aDict[typeSh] = Nb
pass pass
pass
return aDict return aDict
## Get a point, situated at the centre of mass of theShape. ## Get a point, situated at the centre of mass of theShape.