Skip to content

linkcad.controller

High-level conversion workflow controller. Use this when you need the full conversion wizard state machine (select formats, set options, read, apply tools, write) rather than driving linkcad.conv directly.

from linkcad.v1.controller import (
ConversionController, ConversionState,
ControllerEvent, IControllerListener, ProgressInfo,
)

Classes

ConversionController

Orchestrates the multi-step conversion workflow used by the LinkCAD conversion wizard.

from linkcad.v1.controller import ConversionController
ctrl = ConversionController()
ConversionController.import_format = "GDSII"
ConversionController.export_format = "DXF"
ctrl.selected_input_files = ["/data/design.gds"]
ConversionController.output_file = "/data/design.dxf"
ctrl.start_read()
dwg = ctrl.current_drawing
if dwg is None:
raise RuntimeError("Import produced no drawing")
ctrl.start_write()
print(ctrl.current_state)

Format selection and the output path are process-wide state in the engine, so import_format, export_format and output_file are static properties: assign them on the class. Reading them from an instance works too, and gives the same value.

Property / MethodDescription
ConversionController()Create a new controller instance
ConversionController.import_format / .export_formatFormat names (e.g. "GDSII"); static, assignable
ConversionController.output_fileOutput file path; static, assignable
ctrl.selected_input_filesList of input file paths; assignable
ctrl.set_import_options(options_json) / ctrl.set_export_options(options_json)Apply options as a JSON string
ctrl.tools_enabledWhether tools run between reading and writing; assignable
ctrl.configure_tools(tools_config)Configure the tool stage from JSON
ctrl.batch_modeBatch conversion mode; assignable
ctrl.start_read()Start reading the input file(s)
ctrl.start_write()Start writing the output file
ctrl.start_batch()Start a batch conversion
ctrl.finish_operation(success)Mark the current operation as finished
ctrl.cancel_current_operation()Cancel the operation in flight
ctrl.operation_in_progressTrue while an operation is running
ctrl.next() / ctrl.back() / ctrl.reset()Move through the workflow states
ctrl.can_go_next / ctrl.can_go_backWhether navigation is possible
ctrl.current_stateCurrent ConversionState
ctrl.current_drawingThe loaded Drawing, or None
ctrl.current_progressCurrent ProgressInfo
ctrl.import_logImport log, as an IEventLogReader
ctrl.export_logExport log, as an IEventLog
ctrl.conversionsThe underlying Conversions collection — see linkcad.conv
ctrl.add_listener(listener) / ctrl.remove_listener(listener)Attach or detach an IControllerListener

set_import_options() and set_export_options() stay methods: the controller hands the JSON straight to the plugin and keeps nothing to read back, and a property with no getter is not a property.

ConversionState

Enum naming each page of the conversion wizard.

ValueDescription
ConversionState.BeginInitial state
ConversionState.SelectFormatImport and export format selection
ConversionState.ImportOptionsImport options page
ConversionState.ExportOptionsPreExport options shown before reading
ConversionState.ReadFileReading the input file(s)
ConversionState.ApplyToolsApplying geometry tools
ConversionState.ReadLogImport log review
ConversionState.OpenPolysOpen-polyline handling
ConversionState.BatchToolsTool configuration for batch runs
ConversionState.StructureCell/layer structure page
ConversionState.ExportOptionsPostExport options shown after reading
ConversionState.SelectBatchFilesBatch file selection
ConversionState.ConvertBatchFilesBatch conversion in progress
ConversionState.WriteFileWriting the output file
ConversionState.WriteLogExport log review
ConversionState.SummarySummary page
ConversionState.EndWorkflow complete

ControllerEvent

Enum of the notifications a controller emits.

ValueDescription
ControllerEvent.StateChangedThe workflow moved to a different state
ControllerEvent.PageActivatedA wizard page became active
ControllerEvent.ProgressUpdatedProgress information changed
ControllerEvent.LogUpdatedA log gained entries
ControllerEvent.DrawingChangedThe current drawing was replaced
ControllerEvent.OperationFinishedAn operation completed
ControllerEvent.OperationCancelledAn operation was cancelled
ControllerEvent.ErrorOccurredAn error was reported

ProgressInfo

Progress snapshot returned by ctrl.current_progress.

PropertyDescription
percentageProgress percentage (0-100)
current_operationDescription of the current step
current_fileFile being processed
current_file_indexIndex of the current file
total_filesNumber of files in the job

IControllerListener

Subclass this to receive controller notifications. Every method must be overridden.

from linkcad.v1.controller import ConversionController, IControllerListener
class Watcher(IControllerListener):
def on_state_changed(self, new_state): print(f"state: {new_state}")
def on_page_activated(self, page): pass
def on_progress_updated(self, progress): print(f"{progress.percentage}%")
def on_log_updated(self): pass
def on_drawing_about_to_be_cleared(self, drawing): pass
def on_drawing_changed(self, drawing): pass
def on_operation_finished(self, success): print(f"finished: {success}")
def on_operation_cancelled(self): pass
def on_error_occurred(self, message): print(f"error: {message}")
ctrl = ConversionController()
watcher = Watcher()
ctrl.add_listener(watcher)
MethodCalled when
on_state_changed(new_state)The workflow state changes
on_page_activated(page)A wizard page is activated
on_progress_updated(progress)Progress is updated
on_log_updated()A log is updated
on_drawing_about_to_be_cleared(drawing)Right before the current drawing is discarded
on_drawing_changed(drawing)The drawing changes
on_operation_finished(success)An operation finishes
on_operation_cancelled()An operation is cancelled
on_error_occurred(message)An error occurs