Added stock support to templates.

This commit is contained in:
Markus Lampert
2017-09-03 22:35:12 -07:00
committed by wmayer
parent af4bac8abf
commit 4a735b372e
9 changed files with 662 additions and 49 deletions

View File

@@ -53,6 +53,7 @@
<file>icons/preferences-path.svg</file>
<file>panels/DlgJobChooser.ui</file>
<file>panels/DlgJobCreate.ui</file>
<file>panels/DlgJobTemplateExport.ui</file>
<file>panels/DlgSelectPostProcessor.ui</file>
<file>panels/DlgToolControllerEdit.ui</file>
<file>panels/DlgToolCopy.ui</file>

File diff suppressed because one or more lines are too long

View File

@@ -58,6 +58,7 @@ class JobTemplate:
GeometryTolerance = 'tol'
Description = 'desc'
ToolController = 'ToolController'
Stock = 'Stock'
def isResourceClone(obj, propName, resourceName):
'''isResourceClone(obj, propName, resourceName) ... Return True if the given property of obj is a clone of type resourceName.'''
@@ -174,6 +175,8 @@ class ObjectJob:
obj.Description = job.get(JobTemplate.Description)
for tc in tree.getroot().iter(JobTemplate.ToolController):
tcs.append(PathToolController.FromTemplate(tc))
for stock in tree.getroot().iter(JobTemplate.Stock):
obj.Stock = PathStock.CreateFromTemplate(self, stock)
else:
tcs.append(PathToolController.Create(obj.Name))
PathLog.debug("setting tool controllers (%d)" % len(tcs))

View File

@@ -26,6 +26,7 @@ import FreeCAD
import FreeCADGui
import PathScripts.PathJob as PathJob
import PathScripts.PathLog as PathLog
import PathScripts.PathStock as PathStock
import glob
import os
import xml.etree.ElementTree as xml
@@ -126,7 +127,73 @@ class CommandJobCreate:
template = 'None'
FreeCADGui.doCommand('PathScripts.PathJobGui.Create(App.ActiveDocument.%s, %s)' % (base.Name, template))
class CommandJobExportTemplate:
class DlgJobTemplateExport:
DataObject = QtCore.Qt.ItemDataRole.UserRole
def __init__(self, job, parent=None):
self.job = job
self.dialog = FreeCADGui.PySideUic.loadUi(":/panels/DlgJobTemplateExport.ui")
if job.PostProcessor:
ppHint = "%s %s %s" % (job.PostProcessor, job.PostProcessorArgs, job.PostProcessorOutputFile)
self.dialog.postProcessingHint.setText(ppHint)
else:
self.dialog.postProcessingGroup.setEnabled(False)
self.dialog.postProcessingGroup.setChecked(False)
if job.Stock and not PathJob.isResourceClone(job, 'Stock', 'Stock'):
if hasattr(job.Stock, 'ExtXNeg'):
seHint = translate('PathJob', "Base -/+ %.2f/%.2f %.2f/%.2f %.2f/%.2f") % (job.Stock.ExtXneg, job.Stock.ExtXpos, job.Stock.ExtYneg, job.Stock.ExtYpos, job.Stock.ExtZneg, job.Stock.ExtZpos)
self.dialog.stockPlacement.setChecked(False)
elif hasattr(job.Stock, 'Length') and hasattr(job.Stock, 'Width'):
seHint = translate('PathJob', "Box: %.2f x %.2f x %.2f") % (job.Stock.Length, job.Stock.Width, job.Stock.Height)
elif hasattr(job.Stock, 'Radius'):
seHint = translate('PathJob', "Cylinder: %.2f x %.2f") % (job.Stock.Radius, job.Stock.Height)
else:
seHint = '-'
PathLog.error(translate('PathJob', 'Unsupported stock type'))
self.dialog.stockExtentHint.setText(seHint)
spHint = "%s" % job.Stock.Placement
self.dialog.stockPlacementHint.setText(spHint)
for tc in sorted(job.ToolController, key=lambda o: o.Label):
item = QtGui.QListWidgetItem(tc.Label)
item.setData(self.DataObject, tc)
item.setCheckState(QtCore.Qt.CheckState.Checked)
self.dialog.toolsList.addItem(item)
self.dialog.toolsGroup.clicked.connect(self.checkUncheckTools)
def checkUncheckTools(self):
state = QtCore.Qt.CheckState.Checked if self.dialog.toolsGroup.isChecked() else QtCore.Qt.CheckState.Unchecked
for i in range(self.dialog.toolsList.count()):
self.dialog.toolsList.item(i).setCheckState(state)
def includePostProcessing(self):
return self.dialog.postProcessingGroup.isChecked()
def includeToolControllers(self):
tcs = []
for i in range(self.dialog.toolsList.count()):
item = self.dialog.toolsList.item(i)
if item.checkState() == QtCore.Qt.CheckState.Checked:
tcs.append(item.data(self.DataObject))
return tcs
def includeStock(self):
return self.dialog.stockGroup.isChecked()
def includeStockExtent(self):
return self.dialog.stockExtent.isChecked()
def includeStockPlacement(self):
return self.dialog.stockPlacement.isChecked()
def exec_(self):
return self.dialog.exec_()
class CommandJobTemplateExport:
'''
Command to export a template of a given job.
Opens a dialog to select the file to store the template in. If the template is stored in Path's
@@ -144,27 +211,39 @@ class CommandJobExportTemplate:
def Activated(self):
job = FreeCADGui.Selection.getSelection()[0]
foo = QtGui.QFileDialog.getSaveFileName(QtGui.qApp.activeWindow(),
"Path - Job Template",
PathPreferences.filePath(),
"job_*.xml")[0]
if foo:
self.Execute(job, foo)
dialog = DlgJobTemplateExport(job)
if dialog.exec_() == 1:
foo = QtGui.QFileDialog.getSaveFileName(QtGui.qApp.activeWindow(),
"Path - Job Template",
PathPreferences.filePath(),
"job_*.xml")[0]
if foo:
self.Execute(job, foo, dialog)
@classmethod
def Execute(cls, job, path):
def Execute(cls, job, path, dialog=None):
root = xml.Element('PathJobTemplate')
xml.SubElement(root, JobTemplate.Job, job.Proxy.templateAttrs(job))
for obj in job.Group:
if hasattr(obj, 'Tool') and hasattr(obj, 'SpindleDir'):
tc = xml.SubElement(root, JobTemplate.ToolController, obj.Proxy.templateAttrs(obj))
tc.append(xml.fromstring(obj.Tool.Content))
jobAttributes = job.Proxy.templateAttrs(job)
if dialog and not dialog.includePostProcessing():
jobAttributes.pop(PathJob.JobTemplate.PostProcessor, None)
jobAttributes.pob(PathJob.JobTemplate.PostProcessorArgs, None)
jobAttributes.pob(PathJob.JobTemplate.PostProcessorOutputFile, None)
xml.SubElement(root, PathJob.JobTemplate.Job, jobAttributes)
tcs = dialog.includeToolControllers() if dialog else job.ToolController
for tc in tcs:
element = xml.SubElement(root, PathJob.JobTemplate.ToolController, tc.Proxy.templateAttrs(tc))
element.append(xml.fromstring(tc.Tool.Content))
if dialog:
if dialog.includeStock():
xml.SubElement(root, PathJob.JobTemplate.Stock, PathStock.TemplateAttributes(job.Stock, dialog.includeStockExtent(), dialog.includeStockPlacement()))
else:
xml.SubElement(root, PathJob.JobTemplate.Stock, PathStock.TemplateAttributes(job.Stock))
xml.ElementTree(root).write(path)
if FreeCAD.GuiUp:
# register the FreeCAD command
FreeCADGui.addCommand('Path_Job', CommandJobCreate())
FreeCADGui.addCommand('Path_ExportTemplate', CommandJobExportTemplate())
FreeCADGui.addCommand('Path_ExportTemplate', CommandJobTemplateExport())
FreeCAD.Console.PrintLog("Loading PathJobGui... done\n")

View File

@@ -113,6 +113,10 @@ class StockEdit(object):
self.form = form
self.setupUi(obj)
@classmethod
def IsStock(cls, obj):
return PathStock.StockType.FromStock(obj.Stock) == cls.StockType
def activate(self, obj, select = False):
PathLog.track(obj.Label, select)
def showHide(widget, activeWidget):
@@ -139,11 +143,7 @@ class StockEdit(object):
class StockFromBaseBoundBoxEdit(StockEdit):
Index = 2
StockType = 'FromBase'
@classmethod
def IsStock(cls, obj):
return hasattr(obj.Stock, 'ExtXneg') and hasattr(obj.Stock, 'ExtZpos')
StockType = PathStock.StockType.FromBase
def editorFrame(self):
return self.form.stockFromBase
@@ -219,11 +219,7 @@ class StockFromBaseBoundBoxEdit(StockEdit):
class StockCreateBoxEdit(StockEdit):
Index = 0
StockType = 'CreateBox'
@classmethod
def IsStock(cls, obj):
return hasattr(obj.Stock, 'Length') and hasattr(obj.Stock, 'Width') and hasattr(obj.Stock, 'Height') and not StockFromBaseBoundBoxEdit.IsStock(obj)
StockType = PathStock.StockType.CreateBox
def editorFrame(self):
return self.form.stockCreateBox
@@ -254,10 +250,7 @@ class StockCreateBoxEdit(StockEdit):
class StockCreateCylinderEdit(StockEdit):
Index = 1
@classmethod
def IsStock(cls, obj):
return hasattr(obj.Stock, 'Radius') and hasattr(obj.Stock, 'Height')
StockType = PathStock.StockType.CreateCylinder
def editorFrame(self):
return self.form.stockCreateCylinder
@@ -284,9 +277,7 @@ class StockCreateCylinderEdit(StockEdit):
class StockFromExistingEdit(StockEdit):
Index = 3
def IsStock(cls, obj):
return PathJob.isResourceClone(obj, 'Stock', 'Stock')
StockType = PathStock.StockType.Unknown
def editorFrame(self):
return self.form.stockFromExisting

View File

@@ -24,10 +24,17 @@
import FreeCAD
import Part
import PathIconViewProvider
import PathScripts.PathIconViewProvider as PathIconViewProvider
import PathScripts.PathLog as PathLog
import math
from PySide import QtCore
if True:
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
# Qt tanslation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
@@ -80,53 +87,180 @@ def SetupStockObject(obj, addVPProxy):
obj.ViewObject.Transparency = 90
obj.ViewObject.DisplayMode = 'Wireframe'
def CreateFromBase(job):
def CreateFromBase(job, neg=None, pos=None, placement=None):
obj = FreeCAD.ActiveDocument.addObject('Part::FeaturePython', 'Stock')
# don't want to use the resrouce clone - we want the real object so
# Base and Stock can be placed independently
proxy = StockFromBase(obj, job.Proxy.baseObject(job))
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, True)
proxy.execute(obj)
obj.purgeTouched()
return obj
def CreateBox(job, extent=None, at=None):
def CreateBox(job, extent=None, placement=None):
base = job.Base if job and hasattr(job, 'Base') else 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
elif base:
bb = base.Shape.BoundBox
obj.Length = max(bb.XLength, 1)
obj.Width = max(bb.YLength, 1)
obj.Height = max(bb.ZLength, 1)
if at:
obj.Placement = FreeCAD.Placement(at, FreeCAD.Vector(), 0)
else:
bb = job.Base.Shape.BoundBox
if placement:
obj.Placement = placement
elif base:
bb = 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):
def CreateCylinder(job, radius=None, height=None, placement=None):
base = job.Base if job and hasattr(job, 'Base') else 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)
elif base:
bb = base.Shape.BoundBox
obj.Radius = math.sqrt(bb.XLength ** 2 + bb.YLength ** 2) / 2.0
obj.Height = max(bb.ZLength, 1)
if at:
obj.Placement = FreeCAD.Placement(at, FreeCAD.Vector(), 0)
else:
bb = job.Base.Shape.BoundBox
if placement:
obj.Placement = placement
elif base:
bb = 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 StockType:
NoStock = 'None'
FromBase = 'FromBase'
CreateBox = 'CreateBox'
CreateCylinder = 'CreateCylinder'
Unknown = 'Unknown'
@classmethod
def FromStock(cls, stock):
'''FromStock(stock) ... Answer a string representing the type of stock.'''
if not stock:
return cls.NoStock
if hasattr(stock, 'ExtXneg') and hasattr(stock, 'ExtZpos'):
return cls.FromBase
if hasattr(stock, 'Length') and hasattr(stock, 'Width'):
return cls.CreateBox
if hasattr(stock, 'Radius') and hasattr(stock, 'Height'):
return cls.CreateCylinder
return cls.Unknown
def TemplateAttributes(stock, includeExtent=True, includePlacement=True):
attrs = {}
if stock:
stockType = StockType.FromStock(stock)
attrs['create'] = stockType
if includeExtent:
if stockType == StockType.FromBase:
attrs['xneg'] = ("%s" % stock.ExtXneg)
attrs['xpos'] = ("%s" % stock.ExtXpos)
attrs['yneg'] = ("%s" % stock.ExtYneg)
attrs['ypos'] = ("%s" % stock.ExtYpos)
attrs['zneg'] = ("%s" % stock.ExtZneg)
attrs['zpos'] = ("%s" % stock.ExtZpos)
if stockType == StockType.CreateBox:
attrs['length'] = ("%s" % stock.Length)
attrs['width'] = ("%s" % stock.Width)
attrs['height'] = ("%s" % stock.Height)
if stockType == StockType.CreateCylinder:
attrs['radius'] = ("%s" % stock.Radius)
attrs['height'] = ("%s" % stock.Height)
if includePlacement:
pos = stock.Placement.Base
attrs['posX'] = ("%f" % pos.x)
attrs['posY'] = ("%f" % pos.y)
attrs['posZ'] = ("%f" % pos.z)
rot = stock.Placement.Rotation
attrs['rotX'] = ("%f" % rot.Q[0])
attrs['rotY'] = ("%f" % rot.Q[1])
attrs['rotZ'] = ("%f" % rot.Q[2])
attrs['rotW'] = ("%f" % rot.Q[3])
return attrs
def CreateFromTemplate(job, template):
stockType = template.get('create')
if stockType:
placement = None
posX = template.get('posX')
posY = template.get('posY')
posZ = template.get('posZ')
rotX = template.get('rotX')
rotY = template.get('rotY')
rotZ = template.get('rotZ')
rotW = template.get('rotW')
if posX is not None and posY is not None and posZ is not None and rotX is not None and rotY is not None and rotZ is not None and rotW is not None:
pos = FreeCAD.Vector(float(posX), float(posY), float(posZ))
rot = FreeCAD.Rotation(float(rotX), float(rotY), float(rotZ), float(rotW))
placement = FreeCAD.Placement(pos, rot)
elif posX is not None or posY is not None or posZ is not None or rotX is not None or rotY is not None or rotZ is not None or rotW is not None:
PathLog.warning(translate('PathStock', 'Corrupted or incomplete placement information in template - ignoring'))
if stockType == StockType.FromBase:
xneg = template.get('xneg')
xpos = template.get('xpos')
yneg = template.get('yneg')
ypos = template.get('ypos')
zneg = template.get('zneg')
zpos = template.get('zpos')
neg = None
pos = None
if xneg is not None and xpos is not None and yneg is not None and ypos is not None and zneg is not None and zpos is not None:
neg = FreeCAD.Vector(FreeCAD.Units.Quantity(xneg).Value, FreeCAD.Units.Quantity(yneg).Value, FreeCAD.Units.Quantity(zneg).Value)
pos = FreeCAD.Vector(FreeCAD.Units.Quantity(xpos).Value, FreeCAD.Units.Quantity(ypos).Value, FreeCAD.Units.Quantity(zpos).Value)
elif xneg is not None or xpos is not None or yneg is not None or ypos is not None or zneg is not None or zpos is not None:
PathLog.error(translate('PathStock', 'Corrupted or incomplete specification for creating stock from base - ignoring extent'))
return CreateFromBase(job, neg, pos, placement)
if stockType == StockType.CreateBox:
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:
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'))
return CreateBox(job, extent, placement)
if stockType == StockType.CreateCylinder:
radius = template.get('radius')
height = template.get('height')
if radius is not None and height is not None:
pass
elif radius is not None or height is not None:
radius = None
height = None
PathLog.error(translate('PathStock', 'Corrupted or incomplete size for creating a stock cylinder - ignoring size'))
return CreateCylinder(job, radius, height, placement)
PathLog.error(translate('PathStock', 'Unsupported stock type named %s'), stockType)
return None
FreeCAD.Console.PrintLog("Loading PathStock... done\n")

View File

@@ -43,6 +43,12 @@ class PathTestBase(unittest.TestCase):
self.assertRoughly(pt1.y, pt2.y)
self.assertRoughly(pt1.z, pt2.z)
def assertPlacement(self, p1, p2):
"""Verify that two placements are roughly identical."""
self.assertCoincide(p1.Base, p2.Base)
self.assertCoincide(p1.Rotation.Axis, p2.Rotation.Axis)
self.assertRoughly(p1.Rotation.Angle, p2.Rotation.Angle)
def assertLine(self, edge, pt1, pt2):
"""Verify that edge is a line from pt1 to pt2."""
# Depending on the setting of LineOld ....

View File

@@ -0,0 +1,206 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2017 sliptonic <shopinthewoods@gmail.com> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
import FreeCAD
import Part
import Path
import PathScripts.PathStock as PathStock
from PathTests.PathTestUtils import PathTestBase
class FakeJobProxy:
def baseObject(self, obj):
return obj.Base
R = 223.606798
class TestPathStock(PathTestBase):
def setUp(self):
self.doc = FreeCAD.newDocument("TestPathStock")
self.base = self.doc.addObject('Part::Box', 'Box')
self.base.Length = 100
self.base.Width = 200
self.base.Height = 300
self.job = self.doc.addObject('App::FeaturePython', 'Job')
self.job.addProperty('App::PropertyLink', 'Base')
self.job.Base = self.base
self.job.addProperty('App::PropertyLink', 'Proxy')
self.job.Proxy = FakeJobProxy()
def tearDown(self):
FreeCAD.closeDocument("TestPathStock")
def test00(self):
'''Test CreateBox'''
stock = PathStock.CreateBox(self.job)
self.assertTrue(hasattr(stock, 'Length'))
self.assertTrue(hasattr(stock, 'Width'))
self.assertTrue(hasattr(stock, 'Height'))
self.assertEqual(100, stock.Length)
self.assertEqual(200, stock.Width)
self.assertEqual(300, stock.Height)
extent = FreeCAD.Vector(17, 13, 77)
stock = PathStock.CreateBox(self.job, extent)
self.assertEqual(17, stock.Length)
self.assertEqual(13, stock.Width)
self.assertEqual(77, stock.Height)
placement = FreeCAD.Placement(FreeCAD.Vector(-3, 88, 4), FreeCAD.Vector(0, 0, 1), 180)
stock = PathStock.CreateBox(self.job, extent, placement)
self.assertEqual(17, stock.Length)
self.assertEqual(13, stock.Width)
self.assertEqual(77, stock.Height)
self.assertPlacement(placement, stock.Placement)
def test01(self):
'''Test CreateCylinder'''
stock = PathStock.CreateCylinder(self.job)
self.assertTrue(hasattr(stock, 'Radius'))
self.assertTrue(hasattr(stock, 'Height'))
self.assertRoughly(R, stock.Radius.Value)
self.assertEqual(300, stock.Height)
stock = PathStock.CreateCylinder(self.job, 37, 24)
self.assertEqual(37, stock.Radius)
self.assertEqual(24, stock.Height)
placement = FreeCAD.Placement(FreeCAD.Vector(3, 8, -4), FreeCAD.Vector(0, 0, 1), -90)
stock = PathStock.CreateCylinder(self.job, 1, 88, placement)
self.assertEqual(1, stock.Radius)
self.assertEqual(88, stock.Height)
self.assertPlacement(placement, stock.Placement)
def test10(self):
'''Verify FromTemplate box creation.'''
extent = FreeCAD.Vector(17, 13, 77)
placement = FreeCAD.Placement(FreeCAD.Vector(3, 8, -4), FreeCAD.Vector(0, 0, 1), -90)
orig = PathStock.CreateBox(self.job, extent, placement)
# collect full template
template = PathStock.TemplateAttributes(orig)
stock = PathStock.CreateFromTemplate(self.job, template)
self.assertEqual(PathStock.StockType.CreateBox, PathStock.StockType.FromStock(stock))
self.assertEqual(orig.Length, stock.Length)
self.assertEqual(orig.Width, stock.Width)
self.assertEqual(orig.Height, stock.Height)
self.assertPlacement(orig.Placement, stock.Placement)
# don't store extent in template
template = PathStock.TemplateAttributes(orig, False, True)
stock = PathStock.CreateFromTemplate(self.job, template)
self.assertEqual(PathStock.StockType.CreateBox, PathStock.StockType.FromStock(stock))
self.assertEqual(100, stock.Length)
self.assertEqual(200, stock.Width)
self.assertEqual(300, stock.Height)
self.assertPlacement(orig.Placement, stock.Placement)
# don't store placement in template
template = PathStock.TemplateAttributes(orig, True, False)
stock = PathStock.CreateFromTemplate(self.job, template)
self.assertEqual(PathStock.StockType.CreateBox, PathStock.StockType.FromStock(stock))
self.assertEqual(orig.Length, stock.Length)
self.assertEqual(orig.Width, stock.Width)
self.assertEqual(orig.Height, stock.Height)
self.assertPlacement(FreeCAD.Placement(), stock.Placement)
def test11(self):
'''Verify FromTemplate cylinder creation.'''
radius = 7
height = 12
placement = FreeCAD.Placement(FreeCAD.Vector(99, 88, 77), FreeCAD.Vector(1, 1, 1), 123)
orig = PathStock.CreateCylinder(self.job, radius, height, placement)
# full template
template = PathStock.TemplateAttributes(orig)
stock = PathStock.CreateFromTemplate(self.job, template)
self.assertEqual(PathStock.StockType.CreateCylinder, PathStock.StockType.FromStock(stock))
self.assertEqual(orig.Radius, stock.Radius)
self.assertEqual(orig.Height, stock.Height)
self.assertPlacement(orig.Placement, stock.Placement)
# no extent in template
template = PathStock.TemplateAttributes(orig, False, True)
stock = PathStock.CreateFromTemplate(self.job, template)
self.assertEqual(PathStock.StockType.CreateCylinder, PathStock.StockType.FromStock(stock))
self.assertRoughly(R, stock.Radius.Value)
self.assertEqual(300, stock.Height)
self.assertPlacement(orig.Placement, stock.Placement)
# no placement template - and no base
template = PathStock.TemplateAttributes(orig, True, False)
stock = PathStock.CreateFromTemplate(None, template)
self.assertEqual(PathStock.StockType.CreateCylinder, PathStock.StockType.FromStock(stock))
self.assertEqual(orig.Radius, stock.Radius)
self.assertEqual(orig.Height, stock.Height)
self.assertPlacement(FreeCAD.Placement(), stock.Placement)
# no placement template - but base
template = PathStock.TemplateAttributes(orig, True, False)
stock = PathStock.CreateFromTemplate(self.job, template)
self.assertEqual(PathStock.StockType.CreateCylinder, PathStock.StockType.FromStock(stock))
self.assertEqual(orig.Radius, stock.Radius)
self.assertEqual(orig.Height, stock.Height)
self.assertPlacement(FreeCAD.Placement(FreeCAD.Vector(50, 100, 0), FreeCAD.Rotation()), stock.Placement)
def test12(self):
'''Verify FromTemplate from Base creation.'''
neg = FreeCAD.Vector(1,2,3)
pos = FreeCAD.Vector(9,8,7)
orig = PathStock.CreateFromBase(self.job, neg, pos)
# Make sure we have a different base object for the creation
self.base.Length = 11
self.base.Width = 12
self.base.Height = 13
# full template
template = PathStock.TemplateAttributes(orig)
stock = PathStock.CreateFromTemplate(self.job, template)
self.assertEqual(PathStock.StockType.FromBase, PathStock.StockType.FromStock(stock))
self.assertEqual(orig.ExtXneg, stock.ExtXneg)
self.assertEqual(orig.ExtXpos, stock.ExtXpos)
self.assertEqual(orig.ExtYneg, stock.ExtYneg)
self.assertEqual(orig.ExtYpos, stock.ExtYpos)
self.assertEqual(orig.ExtZneg, stock.ExtZneg)
self.assertEqual(orig.ExtZpos, stock.ExtZpos)
bb = stock.Shape.BoundBox
self.assertEqual(neg.x + pos.x + 11, bb.XLength)
self.assertEqual(neg.y + pos.y + 12, bb.YLength)
self.assertEqual(neg.z + pos.z + 13, bb.ZLength)

View File

@@ -32,4 +32,4 @@ from PathTests.TestPathUtil import TestPathUtil
from PathTests.TestPathDepthParams import depthTestCases
from PathTests.TestPathDressupHoldingTags import TestHoldingTags
from PathTests.TestPathDressupDogbone import TestDressupDogbone
from PathTests.TestPathStock import TestPathStock