Added stock creation.

This commit is contained in:
Markus Lampert
2017-09-02 14:50:29 -07:00
committed by wmayer
parent f4ee27458f
commit b778882f76
5 changed files with 633 additions and 94 deletions

View File

@@ -24,23 +24,36 @@
import FreeCAD
import FreeCADGui
from FreeCAD import Vector
from PySide import QtCore, QtGui
import Part
import PathIconViewProvider
from PySide import QtCore
# Qt tanslation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
class Stock:
class StockFromBase:
def __init__(self, obj):
def __init__(self, obj, base):
"Make stock"
obj.addProperty("App::PropertyFloat","Length_Allowance","Stock",QtCore.QT_TRANSLATE_NOOP("App::Property","extra allowance from part width")).Length_Allowance = 1.0
obj.addProperty("App::PropertyFloat","Width_Allowance","Stock",QtCore.QT_TRANSLATE_NOOP("App::Property","extra allowance from part width")).Width_Allowance = 1.0
obj.addProperty("App::PropertyFloat","Height_Allowance","Stock",QtCore.QT_TRANSLATE_NOOP("App::Property","extra allowance from part width")).Height_Allowance = 1.0
obj.addProperty("App::PropertyLink","Base","Base",QtCore.QT_TRANSLATE_NOOP("App::Property","The base object this represents"))
obj.addProperty("App::PropertyLink", "Base", "Base", QtCore.QT_TRANSLATE_NOOP("PathStock", "The base object this stock is derived from"))
obj.addProperty("App::PropertyLength", "ExtXneg", "Stock", QtCore.QT_TRANSLATE_NOOP("PathStock", "Extra allowance from part bound box in negative X direction"))
obj.addProperty("App::PropertyLength", "ExtXpos", "Stock", QtCore.QT_TRANSLATE_NOOP("PathStock", "Extra allowance from part bound box in positive X direction"))
obj.addProperty("App::PropertyLength", "ExtYneg", "Stock", QtCore.QT_TRANSLATE_NOOP("PathStock", "Extra allowance from part bound box in negative Y direction"))
obj.addProperty("App::PropertyLength", "ExtYpos", "Stock", QtCore.QT_TRANSLATE_NOOP("PathStock", "Extra allowance from part bound box in positive Y direction"))
obj.addProperty("App::PropertyLength", "ExtZneg", "Stock", QtCore.QT_TRANSLATE_NOOP("PathStock", "Extra allowance from part bound box in negative Z direction"))
obj.addProperty("App::PropertyLength", "ExtZpos", "Stock", QtCore.QT_TRANSLATE_NOOP("PathStock", "Extra allowance from part bound box in positive Z direction"))
obj.Base = base
obj.ExtXneg= 1.0
obj.ExtXpos= 1.0
obj.ExtYneg= 1.0
obj.ExtYpos= 1.0
obj.ExtZneg= 1.0
obj.ExtZpos= 1.0
obj.Proxy = self
def __getstate__(self):
@@ -50,23 +63,70 @@ class Stock:
return None
def execute(self, obj):
self.Xmin = obj.Base.Shape.BoundBox.XMin
self.Xmax = obj.Base.Shape.BoundBox.XMax
bb = obj.Base.Shape.BoundBox
self.Ymin = obj.Base.Shape.BoundBox.YMin
self.Ymax = obj.Base.Shape.BoundBox.YMax
origin = FreeCAD.Vector(bb.XMin, bb.YMin, bb.ZMin)
self.origin = origin - FreeCAD.Vector(obj.ExtXneg.Value, obj.ExtYneg.Value, obj.ExtZneg.Value)
self.Zmin = obj.Base.Shape.BoundBox.ZMin
self.Zmax = obj.Base.Shape.BoundBox.ZMax
self.length = bb.XLength + obj.ExtXneg.Value + obj.ExtXpos.Value
self.width = bb.YLength + obj.ExtYneg.Value + obj.ExtYpos.Value
self.height = bb.ZLength + obj.ExtZneg.Value + obj.ExtZpos.Value
self.length = self.Xmax - self.Xmin + obj.Length_Allowance * 2.0
self.width = self.Ymax - self.Ymin + obj.Width_Allowance * 2.0
self.height = self.Zmax - self.Zmin + obj.Height_Allowance * 2.0
self.pnt = Vector(self.Xmin - obj.Length_Allowance, self.Ymin -
obj.Width_Allowance, self.Zmin - obj.Height_Allowance)
obj.Shape = Part.makeBox(self.length, self.width, self.height, self.origin)
obj.Shape = Part.makeBox(
self.length, self.width, self.height, self.pnt)
def SetupStockObject(obj, addVPProxy):
if FreeCAD.GuiUp and obj.ViewObject:
if addVPProxy:
PathIconViewProvider.ViewProvider(obj.ViewObject, 'Stock')
obj.ViewObject.Transparency = 90
obj.ViewObject.DisplayMode = 'Wireframe'
def CreateFromBase(job):
obj = FreeCAD.ActiveDocument.addObject('Part::FeaturePython', 'Stock')
proxy = StockFromBase(obj, job.Base)
SetupStockObject(obj, True)
proxy.execute(obj)
obj.purgeTouched()
return obj
def CreateBox(job, extent=None, at=None):
obj = FreeCAD.ActiveDocument.addObject('Part::Box', 'Stock')
if extent:
obj.Length = extent.x
obj.Width = extent.y
obj.Height = extent.z
elif job.Base:
bb = job.Base.Shape.BoundBox
obj.Length = bb.XLength
obj.Width = bb.YLength
obj.Height = bb.ZLength
if at:
obj.Placement = FreeCAD.Placement(at, FreeCAD.Vector(), 0)
else:
bb = job.Base.Shape.BoundBox
origin = FreeCAD.Vector(bb.XMin, bb.YMin, bb.ZMin)
obj.Placement = FreeCAD.Placement(origin, FreeCAD.Vector(), 0)
SetupStockObject(obj, False)
return obj
def CreateCylinder(job, radius=None, height=None, at=None):
obj = FreeCAD.ActiveDocument.addObject('Part::Cylinder', 'Stock')
if radius:
obj.Radius = radius
if height:
obj.Height = height
elif job.Base:
bb = job.Base.Shape.BoundBox
obj.Radius = max(bb.XLength, bb.YLength) * 0.7072 # 1/sqrt(2)
obj.Height = bb.ZLength
if at:
obj.Placement = FreeCAD.Placement(at, FreeCAD.Vector(), 0)
else:
bb = job.Base.Shape.BoundBox
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, False)
return obj
class _ViewProviderStock: