File size: 9,091 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | # SPDX-License-Identifier: LGPL-2.1-or-later
# ***************************************************************************
# * 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 Path.Main.Stock as PathStock
from CAMTests.PathTestUtils import PathTestBase
class FakeJobProxy:
def baseObject(self, obj):
return obj.Base
R = 223.606798 / 2
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", "Model")
model = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", "Model")
model.addObject(self.base)
self.job.Model = model
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)
|