Fixed stock creation with odd initial extent - tessellate to the rescue.
This commit is contained in:
@@ -212,30 +212,37 @@ def SetupStockObject(obj, stockType):
|
||||
obj.ViewObject.DisplayMode = 'Wireframe'
|
||||
|
||||
def CreateFromBase(job, neg=None, pos=None, placement=None):
|
||||
PathLog.track(job.Label if job else "-", neg, pos, placement)
|
||||
base = job.Base if job and hasattr(job, 'Base') else None
|
||||
if base:
|
||||
base.Shape.tessellate(0.1)
|
||||
obj = FreeCAD.ActiveDocument.addObject('Part::FeaturePython', 'Stock')
|
||||
proxy = StockFromBase(obj, base)
|
||||
|
||||
if neg:
|
||||
obj.ExtXneg = neg.x
|
||||
obj.ExtYneg = neg.y
|
||||
obj.ExtZneg = neg.z
|
||||
|
||||
if pos:
|
||||
obj.ExtXpos = pos.x
|
||||
obj.ExtYpos = pos.y
|
||||
obj.ExtZpos = pos.z
|
||||
|
||||
if placement:
|
||||
obj.Placement = placement
|
||||
|
||||
SetupStockObject(obj, StockType.FromBase)
|
||||
proxy.execute(obj)
|
||||
obj.purgeTouched()
|
||||
return obj
|
||||
|
||||
def CreateBox(job, extent=None, placement=None):
|
||||
PathLog.track(job.Label if job else "-", extent, placement)
|
||||
base = job.Base if job and hasattr(job, 'Base') else None
|
||||
if base:
|
||||
base.Shape.tessellate(0.1)
|
||||
obj = FreeCAD.ActiveDocument.addObject('Part::FeaturePython', 'Stock')
|
||||
proxy = StockCreateBox(obj)
|
||||
|
||||
if extent:
|
||||
obj.Length = extent.x
|
||||
obj.Width = extent.y
|
||||
@@ -255,24 +262,29 @@ def CreateBox(job, extent=None, placement=None):
|
||||
return obj
|
||||
|
||||
def CreateCylinder(job, radius=None, height=None, placement=None):
|
||||
PathLog.track(job.Label if job else "-", radius, height, placement)
|
||||
base = job.Base if job and hasattr(job, 'Base') else None
|
||||
if base:
|
||||
base.Shape.tessellate(0.1)
|
||||
obj = FreeCAD.ActiveDocument.addObject('Part::FeaturePython', 'Stock')
|
||||
proxy = StockCreateCylinder(obj)
|
||||
|
||||
if radius:
|
||||
obj.Radius = radius
|
||||
|
||||
if height:
|
||||
obj.Height = height
|
||||
elif base:
|
||||
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 = 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)
|
||||
return obj
|
||||
|
||||
@@ -348,14 +360,18 @@ def CreateFromTemplate(job, template):
|
||||
return CreateFromBase(job, neg, pos, placement)
|
||||
|
||||
if stockType == StockType.CreateBox:
|
||||
PathLog.track(' create box')
|
||||
length = template.get('length')
|
||||
width = template.get('width')
|
||||
height = template.get('height')
|
||||
extent = None
|
||||
if length is not None and width is not None and height is not None:
|
||||
PathLog.track(' have extent')
|
||||
extent = FreeCAD.Vector(FreeCAD.Units.Quantity(length).Value, FreeCAD.Units.Quantity(width).Value, FreeCAD.Units.Quantity(height).Value)
|
||||
elif length is not None or width is not None or height is not None:
|
||||
PathLog.error(translate('PathStock', 'Corrupted or incomplete size for creating a stock box - ignoring size'))
|
||||
else:
|
||||
PathLog.track(" take placement (%s) and extent (%s) from model" % (placement, extent))
|
||||
return CreateBox(job, extent, placement)
|
||||
|
||||
if stockType == StockType.CreateCylinder:
|
||||
|
||||
Reference in New Issue
Block a user