Added support for Part as base object.

This commit is contained in:
Markus Lampert
2017-09-20 21:54:06 -07:00
parent 87533cbb16
commit 992b2589b2
2 changed files with 26 additions and 5 deletions

View File

@@ -63,6 +63,18 @@ class StockType:
return cls.CreateCylinder
return cls.Unknown
def shapeBoundBox(obj):
if hasattr(obj, 'Shape'):
return obj.Shape.BoundBox
if 'App::Part' == obj.TypeId:
bounds = [shapeBoundBox(o) for o in obj.Group]
if bounds:
bb = bounds[0]
for b in bounds[1:]:
bb = bb.united(b)
return bb
PathLog.error(translate('PathStock', 'Invalid base object - no shape found'))
return None
class StockFromBase:
@@ -93,7 +105,7 @@ class StockFromBase:
return None
def execute(self, obj):
bb = obj.Base.Shape.BoundBox
bb = shapeBoundBox(obj.Base)
origin = FreeCAD.Vector(bb.XMin, bb.YMin, bb.ZMin)
self.origin = origin - FreeCAD.Vector(obj.ExtXneg.Value, obj.ExtYneg.Value, obj.ExtZneg.Value)
@@ -216,14 +228,14 @@ def CreateBox(job, extent=None, placement=None):
obj.Width = extent.y
obj.Height = extent.z
elif base:
bb = base.Shape.BoundBox
bb = shapeBoundBox(base)
obj.Length = max(bb.XLength, 1)
obj.Width = max(bb.YLength, 1)
obj.Height = max(bb.ZLength, 1)
if placement:
obj.Placement = placement
elif base:
bb = base.Shape.BoundBox
bb = shapeBoundBox(base)
origin = FreeCAD.Vector(bb.XMin, bb.YMin, bb.ZMin)
obj.Placement = FreeCAD.Placement(origin, FreeCAD.Vector(), 0)
SetupStockObject(obj, StockType.CreateBox)
@@ -238,13 +250,13 @@ def CreateCylinder(job, radius=None, height=None, placement=None):
if height:
obj.Height = height
elif base:
bb = base.Shape.BoundBox
bb = shapeBoundBox(base)
obj.Radius = math.sqrt(bb.XLength ** 2 + bb.YLength ** 2) / 2.0
obj.Height = max(bb.ZLength, 1)
if placement:
obj.Placement = placement
elif base:
bb = base.Shape.BoundBox
bb = shapeBoundBox(base)
origin = FreeCAD.Vector((bb.XMin + bb.XMax)/2, (bb.YMin + bb.YMax)/2, bb.ZMin)
obj.Placement = FreeCAD.Placement(origin, FreeCAD.Vector(), 0)
SetupStockObject(obj, StockType.CreateCylinder)

View File

@@ -40,6 +40,11 @@ NotValidBaseTypeIds = ['Sketcher::SketchObject']
def isValidBaseObject(obj):
'''isValidBaseObject(obj) ... returns true if the object can be used as a base for a job.'''
if hasattr(obj, 'getParentGeoFeatureGroup') and obj.getParentGeoFeatureGroup():
# Can't link to anything inside a geo feature group anymore
return False
if hasattr(obj, 'TypeId') and 'App::Part' == obj.TypeId:
return obj.Group and any(hasattr(o, 'Shape') for o in obj.Group)
if not hasattr(obj, 'Shape'):
return False
if obj.TypeId in NotValidBaseTypeIds:
@@ -58,6 +63,10 @@ def isSolid(obj):
if obj.Shape.ShapeType == 'Compound':
if hasattr(obj, 'Base') and hasattr(obj, 'Tool'):
return isSolid(obj.Base) and isSolid(obj.Tool)
if hasattr(obj, 'TypeId') and 'App::Part' == obj.TypeId:
if not obj.Group or any(hasattr(o, 'Shape') and not isSolid(o) for o in obj.Group):
return False
return True
return False
def toolControllerForOp(op):