builder
builder
¶
The pygerber.vm.builder module provides classes for programmatic generation of
complicated RVMC.
As opposed to manual construction of RVMC by individually constructing Command objects,
builder interface is considered stable, hence it is guaranteed to not be modified
across patch and minor releases without previous deprecation warning.
To start building RVMC, create an instance of Builder class. The Builder class
provides a method layer which should be called and used as context manager.
This method will create main layer of RVMC. You can used methods on the LayerBuilder
instance returned by context manager to add shapes to the layer.
builder = Builder()
with builder.layer() as layer:
layer.circle((0, 0), 1, is_negative=False)
rvmc = builder.commands
To create a nested layer, use the layer method on the LayerBuilder instance.
Then you can proceed to add shapes to the nested layer by invoking commands
on nested layer instance. Nested layer created this way can be pasted into parent
layer using paste method. The paste method takes the nested layer instance
this explicitly disallows creation of cyclic dependencies in layers, as they will
result in exception during rendering.
builder = Builder()
with builder.layer() as layer:
with layer.layer("D10") as nested_layer:
nested_layer.circle((0, 0), 1, is_negative=False)
layer.paste(nested_layer, at=(0, 0), is_negative=False)
rvmc = builder.commands
Multiple nesting is allowed, layers defined and finalized previously can be used in any nested layers in the future. Layers and shapes are auto-magically recorded after corresponding method is called.
Adding shapes to finalized layer is not allowed and will result in exception. Layers are automatically finalized after exiting the context manager corresponding to particular layer. Before context manager is exited, eg. in nested layers, the layers can not be used.
Using parent layer in child layer will result in cyclic dependency and will raise exception during rendering. There is currently no mechanism preventing you from doing that during generation.
LayerBuilder
¶
Layer builder class.
Source code in src/pygerber/vm/builder.py
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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
finalize
¶
layer
¶
layer(
id_: str,
box: Optional[Box] = None,
origin: Optional[tuple[float, float]] = None,
) -> Generator[LayerBuilder, None, None]
Create a new layer.
Source code in src/pygerber/vm/builder.py
circle
¶
Add a command to the layer.
Source code in src/pygerber/vm/builder.py
rectangle
¶
Add a command to the layer.
Source code in src/pygerber/vm/builder.py
obround
¶
Add a command to the layer.
Source code in src/pygerber/vm/builder.py
polygon
¶
polygon(
center: tuple[float, float],
outer_diameter: float,
vertices_count: int,
base_rotation: float,
*,
is_negative: bool
) -> None
Add Shape object containing a regular polygon inscribed in bounding_circle
of diameter outer_diameter, with vertices count equal to vertices_count,
and starting rotation (counterclockwise) of base_rotation degrees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center |
tuple[float, float]
|
Center of the polygon. A tuple of two floats. |
required |
outer_diameter |
float
|
Diameter of the circle circumscribing the regular polygon, i.e. the circle through the polygon vertices. A decimal > 0. |
required |
vertices_count |
int
|
Number of vertices n, 3 ≤ n ≤ 12. An integer. |
required |
base_rotation |
float
|
The rotation angle, in degrees counterclockwise. A decimal. With rotation angle zero there is a vertex on the positive X-axis through the aperture center. |
required |
is_negative |
bool
|
Toggle switch for the negative polarity. If True, the aperture is considered solid, otherwise a hole, possibly subtracting from existing solid shapes. |
required |
Source code in src/pygerber/vm/builder.py
line
¶
line(
start: tuple[float, float],
end: tuple[float, float],
thickness: float,
*,
is_negative: bool
) -> None
Add a command to the layer.
Source code in src/pygerber/vm/builder.py
cross
¶
cross(
center: tuple[float, float],
width: float,
height: float,
thickness: float,
*,
is_negative: bool
) -> None
Add cross shape to the layer.
Source code in src/pygerber/vm/builder.py
x
¶
Add cross shape to the layer.
Source code in src/pygerber/vm/builder.py
paste
¶
Paste another layer.
Source code in src/pygerber/vm/builder.py
Builder
¶
RVMC builder class.
Source code in src/pygerber/vm/builder.py
layer
¶
layer(
box: Optional[Box] = None,
origin: Optional[tuple[float, float]] = None,
) -> Generator[LayerBuilder, None, None]
Create a new layer.