Revise machine

This commit is contained in:
sliptonic
2026-01-03 13:19:10 -06:00
committed by Billy Huddleston
parent 4bba7364f5
commit e53b2e311a
2 changed files with 122 additions and 102 deletions

View File

@@ -395,7 +395,7 @@ class TestMachineFactory(PathTestUtils.PathTestBase):
)
# Configure post-processor settings
machine.output.comments = False
machine.output.output_comments = False
machine.output.axis_precision = 4
machine.output.line_increment = 5
@@ -409,6 +409,6 @@ class TestMachineFactory(PathTestUtils.PathTestBase):
self.assertEqual(loaded.name, machine.name)
self.assertEqual(loaded.manufacturer, machine.manufacturer)
self.assertEqual(len(loaded.spindles), 1)
self.assertFalse(loaded.output.comments)
self.assertFalse(loaded.output.output_comments)
self.assertEqual(loaded.output.axis_precision, 4)
self.assertEqual(loaded.output.line_increment, 5)

View File

@@ -91,31 +91,43 @@ class OutputOptions:
# These options control conversion of Path Objects to actual gcode.
output_units: OutputUnits = OutputUnits.METRIC # G-code output units
comments: bool = True
blank_lines: bool = True
header: bool = True
line_numbers: bool = False
path_labels: bool = False
machine_name: bool = False
output_double_parameters: bool = False # Controls whether to output duplicate axis values
output_bcnc_comments: bool = True
# Line formatting options
command_space: str = " "
comment_symbol: str = "("
end_of_line_chars: str = "\n"
line_increment: int = 10
line_number_start: int = 100
end_of_line_chars: str = "\n"
line_numbers: bool = False
line_number_prefix: str = "N"
# Output content options
output_comments: bool = True # Renamed from 'comments'
output_blank_lines: bool = True # Renamed from 'blank_lines'
output_bcnc_comments: bool = True
output_header: bool = True # Renamed from 'header'
output_labels: bool = False # Renamed from 'path_labels'
output_operation_labels: bool = True # Renamed from 'show_operation_labels'
# Header content options
list_tools_in_header: bool = False # Renamed from 'list_tools_in_preamble'
list_fixtures_in_header: bool = True
machine_name_in_header: bool = False # Renamed from 'machine_name'
description_in_header: bool = True
date_in_header: bool = True
document_name_in_header: bool = True
# Filter options
filter_double_parameters: bool = False # Renamed from 'output_double_parameters'
filter_double_commands: bool = False # Renamed from 'modal' (moved from ProcessingOptions)
# UI and display options
show_editor: bool = True # Show editor after G-code generation
list_tools_in_preamble: bool = False # List tools in preamble
show_operation_labels: bool = True # Show operation labels in output
# Numeric precision settings
axis_precision: int = 3 # Decimal places for axis coordinates
feed_precision: int = 3 # Decimal places for feed rates
spindle_decimals: int = 0 # Decimal places for spindle speed
spindle_precision: int = 0 # Renamed from 'spindle_decimals'
@dataclass
@@ -160,26 +172,21 @@ class GCodeBlocks:
class ProcessingOptions:
"""Processing and transformation options."""
# connversion and expansion of Path Objects. Does not affect final gcode generation
# Conversion and expansion of Path Objects. Does not affect final gcode generation
modal: bool = False # Suppress repeated commands
translate_drill_cycles: bool = False
split_arcs: bool = False
show_machine_units: bool = True
tool_before_change: bool = False # Output T before M6 (e.g., T1 M6 instead of M6 T1)
# Lists of commands
adaptive: bool = False # Enable adaptive toolpath optimization
drill_cycles_to_translate: List[str] = field(
default_factory=lambda: ["G73", "G81", "G82", "G83"]
)
suppress_commands: List[str] = field(default_factory=list)
# Output processing options
tool_change: bool = True # Enable tool change commands
adaptive: bool = False # Enable adaptive toolpath optimization
# Numeric settings
show_machine_units: bool = True
spindle_wait: float = 0.0 # seconds
split_arcs: bool = False
suppress_commands: List[str] = field(default_factory=list)
tool_before_change: bool = False # Output T before M6 (e.g., T1 M6 instead of M6 T1)
tool_change: bool = True # Enable tool change commands
translate_drill_cycles: bool = False
return_to: Optional[Tuple[float, float, float]] = None # (x, y, z) or None
@@ -450,11 +457,12 @@ class Machine:
f"configuration_units must be 'metric' or 'imperial', got '{self.configuration_units}'"
)
# Backward compatibility for doubles
if not hasattr(self.output, "output_double_parameters"):
self.output.output_double_parameters = getattr(self.output, "doubles", False)
# Set deprecated doubles for backward compatibility
self.output.doubles = self.output.output_double_parameters
# Backward compatibility for renamed fields
# Support old field names by creating aliases
if not hasattr(self.output, "filter_double_parameters"):
self.output.filter_double_parameters = getattr(self.output, "output_double_parameters", False)
if not hasattr(self.output, "filter_double_commands"):
self.output.filter_double_commands = getattr(self.processing, "modal", False)
# ========================================================================
# PROPERTIES - Bridge between physical machine and post-processor
@@ -792,26 +800,32 @@ class Machine:
# Output options
data["output"] = {
"comments": self.output.comments,
"blank_lines": self.output.blank_lines,
"header": self.output.header,
"line_numbers": self.output.line_numbers,
"path_labels": self.output.path_labels,
"machine_name": self.output.machine_name,
"output_double_parameters": self.output.output_double_parameters,
"output_bcnc_comments": self.output.output_bcnc_comments,
"output_units": self.output.output_units.value,
"show_editor": self.output.show_editor,
"list_tools_in_preamble": self.output.list_tools_in_preamble,
"show_operation_labels": self.output.show_operation_labels,
"axis_precision": self.output.axis_precision,
"feed_precision": self.output.feed_precision,
"spindle_decimals": self.output.spindle_decimals,
"command_space": self.output.command_space,
"comment_symbol": self.output.comment_symbol,
"output_comments": self.output.output_comments,
"end_of_line_chars": self.output.end_of_line_chars,
"line_increment": self.output.line_increment,
"line_number_start": self.output.line_number_start,
"end_of_line_chars": self.output.end_of_line_chars,
"line_numbers": self.output.line_numbers,
"line_number_prefix": self.output.line_number_prefix,
"list_tools_in_header": self.output.list_tools_in_header,
"list_fixtures_in_header": self.output.list_fixtures_in_header,
"machine_name_in_header": self.output.machine_name_in_header,
"description_in_header": self.output.description_in_header,
"date_in_header": self.output.date_in_header,
"document_name_in_header": self.output.document_name_in_header,
"filter_double_parameters": self.output.filter_double_parameters,
"filter_double_commands": self.output.filter_double_commands,
"output_blank_lines": self.output.output_blank_lines,
"output_bcnc_comments": self.output.output_bcnc_comments,
"output_header": self.output.output_header,
"output_labels": self.output.output_labels,
"output_operation_labels": self.output.output_operation_labels,
"output_units": self.output.output_units.value,
"show_editor": self.output.show_editor,
"axis_precision": self.output.axis_precision,
"feed_precision": self.output.feed_precision,
"spindle_precision": self.output.spindle_precision,
}
# G-code blocks (only non-empty ones)
@@ -850,16 +864,15 @@ class Machine:
# Processing options
data["processing"] = {
"modal": self.processing.modal,
"translate_drill_cycles": self.processing.translate_drill_cycles,
"split_arcs": self.processing.split_arcs,
"show_machine_units": self.processing.show_machine_units,
"tool_before_change": self.processing.tool_before_change,
"drill_cycles_to_translate": self.processing.drill_cycles_to_translate,
"suppress_commands": self.processing.suppress_commands,
"tool_change": self.processing.tool_change,
"adaptive": self.processing.adaptive,
"drill_cycles_to_translate": self.processing.drill_cycles_to_translate,
"show_machine_units": self.processing.show_machine_units,
"spindle_wait": self.processing.spindle_wait,
"split_arcs": self.processing.split_arcs,
"suppress_commands": self.processing.suppress_commands,
"tool_before_change": self.processing.tool_before_change,
"tool_change": self.processing.tool_change,
"translate_drill_cycles": self.processing.translate_drill_cycles,
}
if self.processing.return_to:
data["processing"]["return_to"] = list(self.processing.return_to)
@@ -1011,16 +1024,43 @@ class Machine:
# Load output options
output_data = data.get("output", {})
if output_data:
config.output.comments = output_data.get("comments", True)
config.output.blank_lines = output_data.get("blank_lines", True)
config.output.header = output_data.get("header", True)
# Line formatting options
config.output.command_space = output_data.get("command_space", " ")
config.output.comment_symbol = output_data.get("comment_symbol", "(")
config.output.end_of_line_chars = output_data.get("end_of_line_chars", "\n")
config.output.line_increment = output_data.get("line_increment", 10)
config.output.line_number_start = output_data.get("line_number_start", 100)
config.output.line_numbers = output_data.get("line_numbers", False)
config.output.path_labels = output_data.get("path_labels", False)
config.output.machine_name = output_data.get("machine_name", False)
config.output.output_double_parameters = output_data.get(
"output_double_parameters", False
)
config.output.line_number_prefix = output_data.get("line_number_prefix", "N")
# Output content options (with backward compatibility)
config.output.output_comments = output_data.get("output_comments", output_data.get("comments", True))
config.output.output_blank_lines = output_data.get("output_blank_lines", output_data.get("blank_lines", True))
config.output.output_bcnc_comments = output_data.get("output_bcnc_comments", True)
config.output.output_header = output_data.get("output_header", output_data.get("header", True))
config.output.output_labels = output_data.get("output_labels", output_data.get("path_labels", False))
config.output.output_operation_labels = output_data.get("output_operation_labels", output_data.get("show_operation_labels", True))
# Header content options (with backward compatibility)
config.output.list_tools_in_header = output_data.get("list_tools_in_header", output_data.get("list_tools_in_preamble", False))
config.output.list_fixtures_in_header = output_data.get("list_fixtures_in_header", True)
config.output.machine_name_in_header = output_data.get("machine_name_in_header", output_data.get("machine_name", False))
config.output.description_in_header = output_data.get("description_in_header", True)
config.output.date_in_header = output_data.get("date_in_header", True)
config.output.document_name_in_header = output_data.get("document_name_in_header", True)
# Filter options (with backward compatibility)
config.output.filter_double_parameters = output_data.get("filter_double_parameters", output_data.get("output_double_parameters", False))
# filter_double_commands comes from processing.modal in old format
config.output.filter_double_commands = output_data.get("filter_double_commands", False)
# UI and display options
config.output.show_editor = output_data.get("show_editor", True)
# Numeric precision settings (with backward compatibility)
config.output.axis_precision = output_data.get("axis_precision", 3)
config.output.feed_precision = output_data.get("feed_precision", 3)
config.output.spindle_precision = output_data.get("spindle_precision", output_data.get("spindle_decimals", 0))
# Handle output_units conversion from string to enum
output_units_str = output_data.get("output_units", "metric")
@@ -1028,54 +1068,34 @@ class Machine:
OutputUnits.METRIC if output_units_str == "metric" else OutputUnits.IMPERIAL
)
# These fields are now in ProcessingOptions
# These fields are now in ProcessingOptions (backward compatibility)
if "tool_change" in output_data:
config.processing.tool_change = output_data["tool_change"]
if "adaptive" in output_data:
config.processing.adaptive = output_data["adaptive"]
# Migrate fields from ProcessingOptions to OutputOptions if needed
if "show_editor" in output_data:
config.output.show_editor = output_data["show_editor"]
if "list_tools_in_preamble" in output_data:
config.output.list_tools_in_preamble = output_data["list_tools_in_preamble"]
if "show_operation_labels" in output_data:
config.output.show_operation_labels = output_data["show_operation_labels"]
# Set precision values from output_data
if "axis_precision" in output_data:
config.output.axis_precision = output_data["axis_precision"]
if "feed_precision" in output_data:
config.output.feed_precision = output_data["feed_precision"]
if "spindle_decimals" in output_data:
config.output.spindle_decimals = output_data["spindle_decimals"]
# Load formatting fields from output_data
config.output.command_space = output_data.get("command_space", " ")
config.output.comment_symbol = output_data.get("comment_symbol", "(")
config.output.line_increment = output_data.get("line_increment", 10)
config.output.line_number_start = output_data.get("line_number_start", 100)
config.output.end_of_line_chars = output_data.get("end_of_line_chars", "\n")
# Load processing options
processing_data = data.get("processing", {})
if processing_data:
config.processing.modal = processing_data.get("modal", False)
config.processing.translate_drill_cycles = processing_data.get(
"translate_drill_cycles", False
)
config.processing.split_arcs = processing_data.get("split_arcs", False)
config.processing.show_machine_units = processing_data.get("show_machine_units", True)
config.processing.tool_before_change = processing_data.get("tool_before_change", False)
config.processing.adaptive = processing_data.get("adaptive", False)
config.processing.drill_cycles_to_translate = processing_data.get(
"drill_cycles_to_translate", ["G73", "G81", "G82", "G83"]
)
config.processing.suppress_commands = processing_data.get("suppress_commands", [])
config.processing.tool_change = processing_data.get("tool_change", True)
config.processing.adaptive = processing_data.get("adaptive", False)
config.processing.show_machine_units = processing_data.get("show_machine_units", True)
config.processing.spindle_wait = processing_data.get("spindle_wait", 0.0)
config.processing.split_arcs = processing_data.get("split_arcs", False)
config.processing.suppress_commands = processing_data.get("suppress_commands", [])
config.processing.tool_before_change = processing_data.get("tool_before_change", False)
config.processing.tool_change = processing_data.get("tool_change", True)
config.processing.translate_drill_cycles = processing_data.get(
"translate_drill_cycles", False
)
return_to = processing_data.get("return_to", None)
config.processing.return_to = tuple(return_to) if return_to is not None else None
# Backward compatibility: modal moved to output.filter_double_commands
if "modal" in processing_data:
config.output.filter_double_commands = processing_data["modal"]
# Load G-code blocks
blocks_data = data.get("blocks", {})