コンテンツにスキップ

DrawingBuilder

このコンテンツはまだ日本語訳がありません。

lc_plugin::builder::DrawingBuilder is the import-side drawing construction API. LinkCAD passes it to Reader::parse_file() while a native Rust reader is importing a source file.

Use it to set drawing metadata, create cells, select layers, emit geometry, create text and references, set object properties, report progress, and write import diagnostics. Python import plugins expose the corresponding low-level API through DrawingBuilder in linkcad.v1.plugin.

Purpose

DrawingBuilder is a safe Rust wrapper around the LinkCAD plugin C ABI builder pointer. Plugin code normally receives it from the host and does not construct it directly.

pub struct DrawingBuilder { /* host-owned */ }

Host Construction

pub unsafe fn from_raw(ptr: *mut LcDrawingBuilder) -> Self;
pub fn raw(&self) -> *mut LcDrawingBuilder;

These methods are public for ABI glue and advanced integrations. Format plugins should use the DrawingBuilder passed to Reader::parse_file().

Drawing Metadata

MethodDescription
set_drawing_name(name: &str)Set the imported drawing name.
set_entity_layer_style(flags: LayerFlags)Set how entity layer information is interpreted.

Cell Management

MethodDescription
open_cell_by_number(number: i32, is_main: bool, reopen: bool)Open or create a numbered cell.
open_cell_by_name(name: &str, is_main: bool, reopen: bool)Open or create a named cell.
set_cell_name(name: &str)Rename the current cell.
close_cell()Close the current cell.
delete_cell()Delete the current cell.
find_cell(name: &str) -> boolReturn whether a cell exists.

Open a cell before creating geometry. Mark the main/top cell with is_main = true.

Layer Management

MethodDescription
select_layer_by_name(name: &str)Select or create a named layer.
select_layer_by_number(number: i32)Select or create a numbered layer.
select_layer_by_major_minor(major: i32, minor: i32)Select or create a layer by major/minor number.
set_layer_number(number: i32)Set the validated layer number for the current layer.
set_layer_comment(comment: &str)Set the current layer comment.
set_layer_color(color: Color)Set the current layer display color.
set_layer_enabled(enabled: bool)Enable or disable the current layer.
set_layer_z(z: Coord)Set the current layer Z/elevation value.
set_layer_polarity_positive(positive: bool)Set positive or negative layer polarity.
set_layer_polarity_group(group_name: &str)Assign the current layer to a deferred polarity group.
set_layer_polarity_sequence(sequence: i32)Set source-order sequence within a polarity group.

Layer polarity metadata can be materialized later with Drawing::merge_layer_polarity_group() or Drawing::merge_all_polarity_groups().

Shape Creation

All coordinates and distances use LinkCAD database units from lc_types.

MethodDescription
create_polygon(vertices: &[Point], make_simple: bool)Create a filled polygon.
create_polygon_with_bulges(vertices: &[Point], bulges: &[f64])Create a polygon with per-edge bulge values.
create_rectangle(p0: Point, p1: Point)Create a rectangle from opposite corners.
create_polyline(width: Coord, vertices: &[Point], closed: bool, end_cap: EndCap)Create a path with optional closure and end caps.
create_circle(center: Point, diameter: Coord, as_donut: bool)Create a circle or donut-style circular primitive.
create_arc(center: Point, radius: Coord, width: Coord, start_angle: Angle, end_angle: Angle, end_cap: EndCap)Create an arc.
create_donut(center: Point, mean_diameter: Coord, width: Coord)Create an annular donut primitive.
create_nurbs(width: Coord, degree: i32, knots: &[f64], ctrl_points: &[Point], periodic: bool)Create a non-rational NURBS curve.
create_nurbs_weighted(width: Coord, degree: i32, knots: &[f64], ctrl_points: &[Point], weights: &[f64], periodic: bool)Create a rational NURBS curve.
builder.open_cell_by_name("TOP", true, false);
builder.select_layer_by_name("metal1");
builder.create_polygon(
&[
Point::new(0, 0),
Point::new(10_000, 0),
Point::new(10_000, 5_000),
Point::new(0, 5_000),
],
true,
);
builder.close_cell();

Text Creation

Text creation starts with create_text(), then applies text properties to the current text object.

MethodDescription
create_text()Create a text entity in the current cell/layer.
set_text_position(pos: Point)Set the text anchor position.
set_text_height(height: f64)Set text height.
set_text_stroke_width(width: Coord)Set stroke width.
set_text_style(flags: u32, mask: u32)Set style bits selected by mask.
set_formatted_text(text: &str)Set formatted text content.
set_unformatted_text(text: &str)Set plain text content.
set_text_font(font: &str)Set font name.
set_text_width_factor(factor: f64)Set horizontal scale factor.
set_text_obliquing_angle(angle: Angle)Set oblique/slant angle.
set_text_mirrored_in_x(mirror: bool)Mirror text in X.
set_text_mirrored_in_y(mirror: bool)Mirror text in Y.
set_text_rotation(angle: Angle, absolute: bool)Set or adjust rotation.
set_text_box_width(width: f64)Set text box/wrapping width.
set_text_line_spacing(spacing: f64)Set line spacing.
builder.create_text();
builder.set_text_position(Point::new(0, 12_000));
builder.set_text_height(1_000.0);
builder.set_unformatted_text("TOP");

Current Object Properties and Fonts

MethodDescription
set_current_cell_object_real_property(name: &str, value: f64) -> boolAttach a real-valued property to the current cell object.
set_current_cell_object_bool_property(name: &str, value: bool) -> boolAttach a boolean property to the current cell object.
register_odb_fonts(fonts_dir: &Path) -> usizeRegister ODB++ fonts from a directory and return the number registered.

Cell References

MethodDescription
create_ref_by_number(cell_number: i32)Create a reference to a numbered cell.
create_ref_by_name(cell_name: &str)Create a reference to a named cell.
scale_ref(scale: f64, absolute: bool)Scale the current reference.
mirror_ref_in_x(negate: bool)Mirror the current reference in X.
mirror_ref_in_y(negate: bool)Mirror the current reference in Y.
rotate_ref(angle: Angle, absolute: bool)Rotate the current reference.
translate_ref(pt: Point)Translate the current reference.
set_ref_array_spacing(dx: Coord, dy: Coord)Set reference-array spacing.
set_ref_array_size(cols: i32, rows: i32)Set reference-array dimensions.

Query, Logging, and Progress

MethodDescription
resolution() -> ResolutionReturn the host curve tessellation settings.
log() -> EventLogReturn the import event log wrapper.
set_progress(percent: i32)Report progress, ignoring cancellation status.
try_set_progress(percent: i32) -> boolReport progress and return whether processing should continue.
is_cancelled() -> boolReturn whether the host requested cancellation.
let mut log = builder.log();
log.info("Reading geometry records");
if !builder.try_set_progress(50) {
log.warning("Import cancelled by user");
return false;
}

String Inputs

String arguments are converted to C strings by truncating at the first interior NUL byte instead of panicking. This keeps plugin callbacks safe for runtime input while preserving normal UTF-8 text.