Note
Go to the end to download the full example code.
Padding
This example demonstrates the qtcad.builder.Builder.pad_volume operation.
Initialization
from qtcad.builder import Builder
from qtcad.builder import Mask, Polygon
from pathlib import Path
from util import is_interactive
Setting up the shapes
Here we define the device substrateprint shape (a simple box)…
substrateprint = Polygon.box(10, 10, name="substrate").centered()
… and the two “gates”
gate_1 = Polygon.box(10, 1, name="gate_1").centered().translated(0, -2)
gate_2 = gate_1.translated(0, 4).named("gate_2")
Finally we assemble them into masks
box_mask = Mask("substrateprint")
box_mask.add_shape(substrateprint)
gate_mask = Mask("gates")
gate_mask.add_shape(gate_1)
gate_mask.add_shape(gate_2)
Polygon(name='gate_2', id=1, hull=[(-5, 1.5), (-5, 2.5), (5, 2.5), (5, 1.5)], holes=[])
Generating the geometry
builder = Builder(name="padding demo")
(
builder.set_mesh_size(10)
.add_mask(box_mask)
.add_mask(gate_mask)
.group_from_shape()
.use_mask("substrateprint")
.use_shape("substrate")
.extrude(3)
.use_mask("gates")
.extrude(0.4)
)
[01:52:45 PM] INFO Using mask 'substrateprint' builder.py:750
INFO Extruding shape 0 from mask 'substrateprint' with name 'substrate' by 3 at z=0 builder.py:2695
[01:52:46 PM] INFO Creating new physical group with name 'substrate_bottom' builder.py:2482
INFO Creating new physical group with name 'substrate_side' builder.py:2482
INFO Creating new physical group with name 'substrate_top' builder.py:2482
INFO Creating new physical group with name 'substrate' builder.py:2482
INFO Setting z-coordinate to 3 builder.py:849
INFO Using mask 'gates' builder.py:750
INFO Extruding shape 0 from mask 'gates' with name 'gate_1' by 0.4 at z=3 builder.py:2695
INFO Creating new physical group with name 'gate_1_bottom' builder.py:2482
INFO Creating new physical group with name 'gate_1_side' builder.py:2482
INFO Creating new physical group with name 'gate_1_top' builder.py:2482
INFO Fragmenting... fragmenter.py:234
INFO Creating new physical group with name 'gate_1' builder.py:2482
INFO Extruding shape 1 from mask 'gates' with name 'gate_2' by 0.4 at z=3 builder.py:2695
INFO Creating new physical group with name 'gate_2_bottom' builder.py:2482
INFO Creating new physical group with name 'gate_2_side' builder.py:2482
INFO Creating new physical group with name 'gate_2_top' builder.py:2482
INFO Fragmenting... fragmenter.py:234
INFO Creating new physical group with name 'gate_2' builder.py:2482
INFO Setting z-coordinate to 3.4 builder.py:849
<qtcad.builder.builder.Builder object at 0x7f026d9ab9d0>
At this point we have two “gates” on top of a “substrate”
builder.view(
surfaces=False,
volume_labels=True,
angles=(-45, 0, 45),
save="figs/before_padding.svg",
)
INFO Saving /home/hiro/Documents/org/roam/code/qtcad_flake/qtcad/packages/builder/examples/operations/figs/before_padding.svg builder.py:1863
<qtcad.builder.builder.Builder object at 0x7f026d9ab9d0>
Now we add padding around those gates. The first padding will not
be clipped, whereas the padding around the second gate will be
clipped by the substrateprint shape we selected beforehand.
We also set polygonize=False for the first gate to create a curved
padding volume.
(
builder.use_mask("substrateprint")
.use_shape("substrate")
.pad_volume("gate_1", 0.6, noclip=False, polygonize=False)
.pad_volume("gate_2", 0.6, noclip=True)
)
[01:52:47 PM] INFO Using mask 'substrateprint' builder.py:750
INFO Padding Physical Group 'gate_1' of dimension 3 with a layer of 0.6 (clipping with shapes with shapes: [('substrate', 0)]) builder.py:442
[01:52:48 PM] INFO Creating new physical group with name 'gate_1_padding_bottom' builder.py:2482
INFO Creating new physical group with name 'gate_1_padding_side' builder.py:2482
INFO Creating new physical group with name 'gate_1_padding_top' builder.py:2482
INFO Fragmenting... fragmenter.py:234
[01:52:50 PM] INFO Creating new physical group with name 'gate_1_padding' builder.py:2482
[01:52:51 PM] INFO Padding Physical Group 'gate_2' of dimension 3 with a layer of 0.6 builder.py:442
[01:52:52 PM] INFO Creating new physical group with name 'gate_2_padding_bottom' builder.py:2482
INFO Creating new physical group with name 'gate_2_padding_side' builder.py:2482
INFO Creating new physical group with name 'gate_2_padding_top' builder.py:2482
INFO Fragmenting... fragmenter.py:234
[01:52:57 PM] INFO Creating new physical group with name 'gate_2_padding' builder.py:2482
<qtcad.builder.builder.Builder object at 0x7f026d9ab9d0>
Viewing the result
builder.view(
surfaces=False, angles=(-45, 0, 45), save="figs/final.svg", show=is_interactive
)
[01:53:01 PM] INFO Saving /home/hiro/Documents/org/roam/code/qtcad_flake/qtcad/packages/builder/examples/operations/figs/final.svg builder.py:1863
<qtcad.builder.builder.Builder object at 0x7f026d9ab9d0>
Hiding the padding volume
builder.view(
True,
groups=["gate_1", "gate_2", "substrate"],
surfaces=True,
volume_labels=True,
angles=(-90, 0, 90),
orthographic=True,
save="figs/padding_removed.svg",
show=is_interactive,
)
[01:53:02 PM] INFO Saving /home/hiro/Documents/org/roam/code/qtcad_flake/qtcad/packages/builder/examples/operations/figs/padding_removed.svg builder.py:1863
<qtcad.builder.builder.Builder object at 0x7f026d9ab9d0>
Total running time of the script: (0 minutes 19.370 seconds)