mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-06 02:30:55 -08:00
Formatting change
This commit is contained in:
parent
cbb827d271
commit
fa79240f1f
1 changed files with 40 additions and 19 deletions
|
|
@ -1,27 +1,40 @@
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import math
|
import math
|
||||||
from typing import Union, Iterable
|
from typing import Union, Iterable
|
||||||
from build123d import (
|
from build123d import (
|
||||||
Mode, Shape, Plane, Locations,
|
Mode,
|
||||||
BuildLine, Line, Bezier, RadiusArc,
|
Shape,
|
||||||
BuildSketch, Sketch, make_face, RegularPolygon, Circle, PolarLocations,
|
Plane,
|
||||||
BuildPart, Part, Cone, extrude, add, mirror,
|
Locations,
|
||||||
section
|
BuildLine,
|
||||||
)
|
Line,
|
||||||
from build123d.exporters import (
|
Bezier,
|
||||||
ExportSVG, ExportDXF, Drawing, LineType
|
RadiusArc,
|
||||||
|
BuildSketch,
|
||||||
|
Sketch,
|
||||||
|
make_face,
|
||||||
|
RegularPolygon,
|
||||||
|
Circle,
|
||||||
|
PolarLocations,
|
||||||
|
BuildPart,
|
||||||
|
Part,
|
||||||
|
Cone,
|
||||||
|
extrude,
|
||||||
|
add,
|
||||||
|
mirror,
|
||||||
|
section,
|
||||||
)
|
)
|
||||||
|
from build123d.exporters import ExportSVG, ExportDXF, Drawing, LineType
|
||||||
|
|
||||||
|
|
||||||
class ExportersTestCase(unittest.TestCase):
|
class ExportersTestCase(unittest.TestCase):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_test_sketch() -> Sketch:
|
def create_test_sketch() -> Sketch:
|
||||||
with BuildSketch() as sketchy:
|
with BuildSketch() as sketchy:
|
||||||
with BuildLine():
|
with BuildLine():
|
||||||
Line((0, 0), (16, 0))
|
Line((0, 0), (16, 0))
|
||||||
Bezier((16,0), (16,8), (16,8), (8,8))
|
Bezier((16, 0), (16, 8), (16, 8), (8, 8))
|
||||||
RadiusArc((8,8), (0,0), -8, short_sagitta=True)
|
RadiusArc((8, 8), (0, 0), -8, short_sagitta=True)
|
||||||
make_face()
|
make_face()
|
||||||
with Locations((5, 4)):
|
with Locations((5, 4)):
|
||||||
RegularPolygon(2, 4, mode=Mode.SUBTRACT)
|
RegularPolygon(2, 4, mode=Mode.SUBTRACT)
|
||||||
|
|
@ -37,7 +50,9 @@ class ExportersTestCase(unittest.TestCase):
|
||||||
return party.part
|
return party.part
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def basic_svg_export(shape: Union[Shape, Iterable[Shape]], filename: str, reverse: bool = False):
|
def basic_svg_export(
|
||||||
|
shape: Union[Shape, Iterable[Shape]], filename: str, reverse: bool = False
|
||||||
|
):
|
||||||
svg = ExportSVG()
|
svg = ExportSVG()
|
||||||
svg.add_shape(shape, reverse_wires=reverse)
|
svg.add_shape(shape, reverse_wires=reverse)
|
||||||
svg.write(filename)
|
svg.write(filename)
|
||||||
|
|
@ -58,12 +73,12 @@ class ExportersTestCase(unittest.TestCase):
|
||||||
svg = ExportSVG(line_weight=0.13)
|
svg = ExportSVG(line_weight=0.13)
|
||||||
svg.add_layer("hidden", line_weight=0.09, line_type=LineType.HIDDEN)
|
svg.add_layer("hidden", line_weight=0.09, line_type=LineType.HIDDEN)
|
||||||
svg.add_shape(dwg.visible_lines)
|
svg.add_shape(dwg.visible_lines)
|
||||||
svg.add_shape(dwg.hidden_lines, layer='hidden')
|
svg.add_shape(dwg.hidden_lines, layer="hidden")
|
||||||
svg.write(filebase + ".svg")
|
svg.write(filebase + ".svg")
|
||||||
dxf = ExportDXF(line_weight=0.13)
|
dxf = ExportDXF(line_weight=0.13)
|
||||||
dxf.add_layer("hidden", line_weight=0.09, line_type=LineType.HIDDEN)
|
dxf.add_layer("hidden", line_weight=0.09, line_type=LineType.HIDDEN)
|
||||||
dxf.add_shape(dwg.visible_lines)
|
dxf.add_shape(dwg.visible_lines)
|
||||||
dxf.add_shape(dwg.hidden_lines, layer='hidden')
|
dxf.add_shape(dwg.hidden_lines, layer="hidden")
|
||||||
dxf.write(filebase + ".dxf")
|
dxf.write(filebase + ".dxf")
|
||||||
|
|
||||||
def test_sketch(self):
|
def test_sketch(self):
|
||||||
|
|
@ -81,7 +96,9 @@ class ExportersTestCase(unittest.TestCase):
|
||||||
winding order."""
|
winding order."""
|
||||||
part = ExportersTestCase.create_test_part()
|
part = ExportersTestCase.create_test_part()
|
||||||
test_section = section(part, Plane.XY, height=0)
|
test_section = section(part, Plane.XY, height=0)
|
||||||
ExportersTestCase.basic_svg_export(test_section, "test-back-section.svg", reverse=True)
|
ExportersTestCase.basic_svg_export(
|
||||||
|
test_section, "test-back-section.svg", reverse=True
|
||||||
|
)
|
||||||
|
|
||||||
def test_angled_section(self):
|
def test_angled_section(self):
|
||||||
"""Export an angled section.
|
"""Export an angled section.
|
||||||
|
|
@ -93,14 +110,14 @@ class ExportersTestCase(unittest.TestCase):
|
||||||
ExportersTestCase.basic_combo_export(angled_section, "test-angled-section")
|
ExportersTestCase.basic_combo_export(angled_section, "test-angled-section")
|
||||||
|
|
||||||
def test_cam_section_svg(self):
|
def test_cam_section_svg(self):
|
||||||
""" Export a section through the top face, with a simple
|
"""Export a section through the top face, with a simple
|
||||||
CAM oriented layer setup."""
|
CAM oriented layer setup."""
|
||||||
part = ExportersTestCase.create_test_part()
|
part = ExportersTestCase.create_test_part()
|
||||||
section_plane = Plane.XY.offset(4)
|
section_plane = Plane.XY.offset(4)
|
||||||
cam_section = section_plane.to_local_coords(section(part, section_plane))
|
cam_section = section_plane.to_local_coords(section(part, section_plane))
|
||||||
svg = ExportSVG()
|
svg = ExportSVG()
|
||||||
white = (255,255,255)
|
white = (255, 255, 255)
|
||||||
black = (0,0,0)
|
black = (0, 0, 0)
|
||||||
svg.add_layer("exterior", line_color=black, fill_color=black)
|
svg.add_layer("exterior", line_color=black, fill_color=black)
|
||||||
svg.add_layer("interior", line_color=black, fill_color=white)
|
svg.add_layer("interior", line_color=black, fill_color=white)
|
||||||
for f in cam_section.faces():
|
for f in cam_section.faces():
|
||||||
|
|
@ -138,3 +155,7 @@ class ExportersTestCase(unittest.TestCase):
|
||||||
mirror(about=Plane.YZ.offset(25))
|
mirror(about=Plane.YZ.offset(25))
|
||||||
drawing = Drawing(part.part)
|
drawing = Drawing(part.part)
|
||||||
ExportersTestCase.drawing_combo_export(drawing, "test-ellipse-rotation")
|
ExportersTestCase.drawing_combo_export(drawing, "test-ellipse-rotation")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue