Made Shape.Center() more intelligent to handle switch-ups between Shape and Solid.
This commit is contained in:
parent
4a7a7963ed
commit
07acfba4b9
|
@ -685,8 +685,7 @@ class CQ(object):
|
|||
endVec = Vector(axisEndPoint)
|
||||
|
||||
def _rot(obj):
|
||||
# TODO: compute the weighted average instead of using the first solid
|
||||
startPt = obj.Solids()[0].Center()
|
||||
startPt = obj.Center()
|
||||
endPt = startPt + endVec
|
||||
return obj.rotate(startPt, endPt, angleDegrees)
|
||||
|
||||
|
|
|
@ -185,7 +185,18 @@ class Shape(object):
|
|||
return BoundBox(self.wrapped.BoundBox)
|
||||
|
||||
def Center(self):
|
||||
return Vector(self.wrapped.CenterOfMass)
|
||||
# A Part.Shape object doesn't have the CenterOfMass function, but it's wrapped Solid(s) does
|
||||
if isinstance(self.wrapped, FreeCADPart.Shape):
|
||||
# If there are no Solids, we're probably dealing with a Face or something similar
|
||||
if len(self.Solids()) == 0:
|
||||
return Vector(self.wrapped.CenterOfMass)
|
||||
else:
|
||||
# TODO: compute the weighted average instead of using the first solid
|
||||
return Vector(self.Solids()[0].wrapped.CenterOfMass)
|
||||
elif isinstance(self.wrapped, FreeCADPart.Solid):
|
||||
return Vector(self.wrapped.CenterOfMass)
|
||||
else:
|
||||
raise ValueError("Cannot find the center of %s object type" % str(type(self.Solids()[0].wrapped)))
|
||||
|
||||
def Closed(self):
|
||||
return self.wrapped.Closed
|
||||
|
@ -848,8 +859,7 @@ class Compound(Shape):
|
|||
self.wrapped = obj
|
||||
|
||||
def Center(self):
|
||||
# TODO: compute the weighted average instead of the first solid
|
||||
return self.Solids()[0].Center()
|
||||
return self.Center()
|
||||
|
||||
@classmethod
|
||||
def makeCompound(cls, listOfShapes):
|
||||
|
|
Loading…
Reference in New Issue
Block a user