Deal with temporary invalid data for stock extents and ensure minimum size.

This commit is contained in:
Markus Lampert
2017-09-14 16:55:10 -07:00
committed by wmayer
parent c40e737492
commit a6fc367064
2 changed files with 38 additions and 16 deletions

View File

@@ -291,15 +291,18 @@ class StockCreateBoxEdit(StockEdit):
return self.form.stockCreateBox
def getFields(self, obj, fields = ['length', 'widht', 'height']):
if self.IsStock(obj):
if 'length' in fields:
obj.Stock.Length = FreeCAD.Units.Quantity(self.form.stockBoxLength.text())
if 'width' in fields:
obj.Stock.Width = FreeCAD.Units.Quantity(self.form.stockBoxWidth.text())
if 'height' in fields:
obj.Stock.Height = FreeCAD.Units.Quantity(self.form.stockBoxHeight.text())
else:
PathLog.error(translate('PathJob', 'Stock not a box!'))
try:
if self.IsStock(obj):
if 'length' in fields:
obj.Stock.Length = FreeCAD.Units.Quantity(self.form.stockBoxLength.text())
if 'width' in fields:
obj.Stock.Width = FreeCAD.Units.Quantity(self.form.stockBoxWidth.text())
if 'height' in fields:
obj.Stock.Height = FreeCAD.Units.Quantity(self.form.stockBoxHeight.text())
else:
PathLog.error(translate('PathJob', 'Stock not a box!'))
except:
pass
def setFields(self, obj):
if not self.IsStock(obj):
@@ -322,13 +325,16 @@ class StockCreateCylinderEdit(StockEdit):
return self.form.stockCreateCylinder
def getFields(self, obj, fields = ['radius', 'height']):
if self.IsStock(obj):
if 'radius' in fields:
obj.Stock.Radius = FreeCAD.Units.Quantity(self.form.stockCylinderRadius.text())
if 'height' in fields:
obj.Stock.Height = FreeCAD.Units.Quantity(self.form.stockCylinderHeight.text())
else:
PathLog.error(translate('PathJob', 'Stock not a cylinder!'))
try:
if self.IsStock(obj):
if 'radius' in fields:
obj.Stock.Radius = FreeCAD.Units.Quantity(self.form.stockCylinderRadius.text())
if 'height' in fields:
obj.Stock.Height = FreeCAD.Units.Quantity(self.form.stockCylinderHeight.text())
else:
PathLog.error(translate('PathJob', 'Stock not a cylinder!'))
except:
pass
def setFields(self, obj):
if not self.IsStock(obj):

View File

@@ -112,6 +112,8 @@ class StockFromBase:
class StockCreateBox:
MinExtent = 0.001
def __init__(self, obj):
obj.addProperty('App::PropertyLength', 'Length', 'Stock', QtCore.QT_TRANSLATE_NOOP("PathStock", "Length of this stock box"))
obj.addProperty('App::PropertyLength', 'Width', 'Stock', QtCore.QT_TRANSLATE_NOOP("PathStock", "Width of this stock box"))
@@ -129,6 +131,13 @@ class StockCreateBox:
return None
def execute(self, obj):
if obj.Length < self.MinExtent:
obj.Length = self.MinExtent
if obj.Width < self.MinExtent:
obj.Width = self.MinExtent
if obj.Height < self.MinExtent:
obj.Height = self.MinExtent
shape = Part.makeBox(obj.Length, obj.Width, obj.Height)
shape.Placement = obj.Placement
obj.Shape = shape
@@ -138,6 +147,8 @@ class StockCreateBox:
self.execute(obj)
class StockCreateCylinder:
MinExtent = 0.001
def __init__(self, obj):
obj.addProperty('App::PropertyLength', 'Radius', 'Stock', QtCore.QT_TRANSLATE_NOOP("PathStock", "Radius of this stock cylinder"))
obj.addProperty('App::PropertyLength', 'Height', 'Stock', QtCore.QT_TRANSLATE_NOOP("PathStock", "Height of this stock cylinder"))
@@ -153,6 +164,11 @@ class StockCreateCylinder:
return None
def execute(self, obj):
if obj.Radius < self.MinExtent:
obj.Radius = self.MinExtent
if obj.Height < self.MinExtent:
obj.Height = self.MinExtent
shape = Part.makeCylinder(obj.Radius, obj.Height)
shape.Placement = obj.Placement
obj.Shape = shape