跳转到内容

Drawing Helpers

此内容尚不支持你的语言。

lc_plugin::drawing provides reader post-processing helpers for operations that need access to the drawing after parsing. LinkCAD passes Drawing to Reader::post_process().

Python exposes equivalent drawing helper methods on linkcad.v1.db.Drawing.

Key Public Items

ItemPurpose
DrawingHost-owned drawing handle for reader post-processing.
BooleanOperationLayer-level boolean operation.
MergeLayerPolarityResultResult of deferred-polarity materialization.

Enums

pub enum BooleanOperation {
Or,
AMinusB,
}
pub enum MergeLayerPolarityResult {
Success,
Cancelled,
Failure,
}

BooleanOperation::Or unions the operand layer into the result layer. BooleanOperation::AMinusB subtracts the operand layer from the result layer.

Host Construction

pub unsafe fn from_raw(ptr: *mut LcDrawing) -> Self;

This method is public for ABI glue. Format plugins should use the Drawing passed to Reader::post_process().

Post-Processing Methods

MethodDescription
boolean_layers_by_name(op, result_layer, operand_layer, resolution) -> boolRun a layer boolean operation. result_layer is operand A and receives the output.
merge_layer_polarity_group(group_name, resolution, progress, progress_from, progress_to) -> MergeLayerPolarityResultMaterialize one deferred-polarity group.
merge_all_polarity_groups(resolution, progress, progress_from, progress_to) -> MergeLayerPolarityResultMaterialize all deferred-polarity groups in one batch.
destroy_layer_by_name(layer: &str) -> boolDestroy a layer if it exists.
rename_layer(from: &str, to: &str) -> boolRename a layer.

String inputs that contain an interior NUL byte return false or MergeLayerPolarityResult::Failure instead of panicking.

Reader Post-Process Example

impl Reader for ExampleReader {
fn parse_file(
&mut self,
_path: &str,
builder: &mut DrawingBuilder,
_file_size: i64,
_current_file: i32,
_file_count: i32,
) -> bool {
builder.open_cell_by_name("TOP", true, false);
builder.select_layer_by_name("metal");
builder.create_rectangle(Point::new(0, 0), Point::new(10_000, 10_000));
builder.close_cell();
true
}
fn post_process(
&mut self,
phase: Phase,
drawing: &mut Drawing,
progress: Option<&mut DrawingBuilder>,
log: &mut EventLog,
resolution: &Resolution,
) -> bool {
if phase != Phase::ParsedAll {
return true;
}
match drawing.merge_all_polarity_groups(resolution, progress, 0, 100) {
MergeLayerPolarityResult::Success => true,
MergeLayerPolarityResult::Cancelled => false,
MergeLayerPolarityResult::Failure => {
log.error("Could not merge layer polarity groups");
false
}
}
}
}

Progress Range

progress_from and progress_to map the operation’s internal progress to a percentage interval in the host progress bar. Pass the progress builder from Reader::post_process() when available so cancellation is detected and progress updates are visible.