From 76001ce57825e79174062959beb06bfa6ae81a02 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Dec 2025 20:10:08 +0000 Subject: [PATCH 1/4] Initial plan From c695a78a51f954661fa49a192538e690a39d42c0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Dec 2025 20:17:52 +0000 Subject: [PATCH 2/4] Fix CGI server to use machine-specific variable patterns and add prefix field Co-authored-by: d-creations <99477364+d-creations@users.noreply.github.com> --- scripts/cgiserver.cgi | 65 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/scripts/cgiserver.cgi b/scripts/cgiserver.cgi index 4bcd528..123567d 100644 --- a/scripts/cgiserver.cgi +++ b/scripts/cgiserver.cgi @@ -9,6 +9,20 @@ import json import os from typing import Dict, List, Any, Optional +# Add src to path to import domain module +sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src')) + +try: + from ncplot7py.domain.machines import ( + get_machine_regex_patterns as domain_get_machine_regex_patterns, + get_machine_config, + FANUC_STAR_CONFIG, + SIEMENS_840D_CONFIG, + ) + USE_DOMAIN_MODULE = True +except ImportError: + USE_DOMAIN_MODULE = False + # Set content type for CGI print("Content-Type: application/json") print() @@ -19,12 +33,32 @@ def get_machine_regex_patterns(control_type: str) -> Dict[str, Any]: Each machine has specific patterns for: - tools: Regular tool calls (e.g., T1-T99) - - variables: Variable references (e.g., #1 - #999) + - variables: Variable references (e.g., #1 - #999 for Fanuc, R1 - R999 for Siemens) - keywords: Special codes like M-codes and extended T-codes Returns a dictionary with pattern strings and descriptions. """ - # Base patterns common to most machines + # Use domain module if available for machine-specific patterns + if USE_DOMAIN_MODULE: + patterns = domain_get_machine_regex_patterns(control_type) + # Add variable_prefix for frontend to parse user input (e.g., "R5 = 5" or "#5 = 5") + if "SIEMENS" in control_type.upper() or "MILL" in control_type.upper(): + patterns["variables"]["prefix"] = SIEMENS_840D_CONFIG.variable_prefix + else: + patterns["variables"]["prefix"] = FANUC_STAR_CONFIG.variable_prefix + return patterns + + # Fallback patterns if domain module is not available + # Determine variable pattern based on control type + if "SIEMENS" in control_type.upper() or "MILL" in control_type.upper(): + var_pattern = r"R(\d+)" + var_prefix = "R" + var_description = "Variables R1 - R999" + else: + var_pattern = r"#(\d+)" + var_prefix = "#" + var_description = "Variables #1 - #999" + base_patterns = { "tools": { "pattern": r"T([1-9]|[1-9][0-9])(?!\d)", @@ -32,8 +66,9 @@ def get_machine_regex_patterns(control_type: str) -> Dict[str, Any]: "range": {"min": 1, "max": 99} }, "variables": { - "pattern": r"#([1-9]|[1-9][0-9]{1,2})(?!\d)", - "description": "Variables #1 - #999", + "pattern": var_pattern, + "description": var_description, + "prefix": var_prefix, "range": {"min": 1, "max": 999} }, "keywords": { @@ -49,20 +84,24 @@ def get_machine_regex_patterns(control_type: str) -> Dict[str, Any]: } } - # Patterns are currently the same for all control types - # This structure allows future customization per control type if needed return base_patterns def get_mock_machines() -> List[Dict[str, Any]]: - """Return list of available machines with their regex patterns""" + """Return list of available machines with their regex patterns. + + Control types: + - SIEMENS/MILL: Uses R-parameters (R1, R2, etc.) + - TURN/FANUC: Uses #-parameters (#1, #2, etc.) + """ machines = [ - {"machineName": "ISO_MILL", "controlType": "MILL"}, + {"machineName": "ISO_MILL", "controlType": "SIEMENS"}, + {"machineName": "SIEMENS_MILL", "controlType": "SIEMENS"}, {"machineName": "FANUC_T", "controlType": "TURN"}, - {"machineName": "SB12RG_F", "controlType": "MILL"}, - {"machineName": "SB12RG_B", "controlType": "MILL"}, - {"machineName": "SR20JII_F", "controlType": "MILL"}, - {"machineName": "SR20JII_B", "controlType": "MILL"}, + {"machineName": "SB12RG_F", "controlType": "TURN"}, + {"machineName": "SB12RG_B", "controlType": "TURN"}, + {"machineName": "SR20JII_F", "controlType": "TURN"}, + {"machineName": "SR20JII_B", "controlType": "TURN"}, ] # Add regex patterns to each machine @@ -147,7 +186,7 @@ def handle_execute_programs(programs: List[Dict[str, Any]]) -> Dict[str, Any]: canal_nr = program_entry.get("canalNr", "1") # Validate machine name - valid_machines = ["SB12RG_F", "FANUC_T", "SR20JII_F", "SB12RG_B", "SR20JII_B", "ISO_MILL"] + valid_machines = ["SB12RG_F", "FANUC_T", "SR20JII_F", "SB12RG_B", "SR20JII_B", "ISO_MILL", "SIEMENS_MILL"] if machine_name not in valid_machines: messages.append(f"Invalid machine name: {machine_name}") continue From 00380a6b38d42a4caed93c6b705074103098b983 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Dec 2025 20:20:25 +0000 Subject: [PATCH 3/4] Update CGI server with more specific control types and improved docstrings Co-authored-by: d-creations <99477364+d-creations@users.noreply.github.com> --- scripts/cgiserver.cgi | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/scripts/cgiserver.cgi b/scripts/cgiserver.cgi index 123567d..c1e2834 100644 --- a/scripts/cgiserver.cgi +++ b/scripts/cgiserver.cgi @@ -37,12 +37,18 @@ def get_machine_regex_patterns(control_type: str) -> Dict[str, Any]: - keywords: Special codes like M-codes and extended T-codes Returns a dictionary with pattern strings and descriptions. + + Control type mapping: + - SIEMENS, SIEMENS_840D, MILL -> Siemens (R-parameters) + - TURN, FANUC, FANUC_STAR -> Fanuc (Hash-parameters) """ # Use domain module if available for machine-specific patterns if USE_DOMAIN_MODULE: patterns = domain_get_machine_regex_patterns(control_type) # Add variable_prefix for frontend to parse user input (e.g., "R5 = 5" or "#5 = 5") - if "SIEMENS" in control_type.upper() or "MILL" in control_type.upper(): + # The domain module uses control_type heuristics: SIEMENS/MILL -> Siemens, STAR/TURN -> Fanuc + control_upper = control_type.upper() + if "SIEMENS" in control_upper or ("MILL" in control_upper and "FANUC" not in control_upper): patterns["variables"]["prefix"] = SIEMENS_840D_CONFIG.variable_prefix else: patterns["variables"]["prefix"] = FANUC_STAR_CONFIG.variable_prefix @@ -50,7 +56,8 @@ def get_machine_regex_patterns(control_type: str) -> Dict[str, Any]: # Fallback patterns if domain module is not available # Determine variable pattern based on control type - if "SIEMENS" in control_type.upper() or "MILL" in control_type.upper(): + control_upper = control_type.upper() + if "SIEMENS" in control_upper or ("MILL" in control_upper and "FANUC" not in control_upper): var_pattern = r"R(\d+)" var_prefix = "R" var_description = "Variables R1 - R999" @@ -91,17 +98,17 @@ def get_mock_machines() -> List[Dict[str, Any]]: """Return list of available machines with their regex patterns. Control types: - - SIEMENS/MILL: Uses R-parameters (R1, R2, etc.) - - TURN/FANUC: Uses #-parameters (#1, #2, etc.) + - SIEMENS_840D: Uses R-parameters (R1, R2, etc.) for Siemens controls + - FANUC_STAR: Uses #-parameters (#1, #2, etc.) for Fanuc/Star turning machines """ machines = [ - {"machineName": "ISO_MILL", "controlType": "SIEMENS"}, - {"machineName": "SIEMENS_MILL", "controlType": "SIEMENS"}, - {"machineName": "FANUC_T", "controlType": "TURN"}, - {"machineName": "SB12RG_F", "controlType": "TURN"}, - {"machineName": "SB12RG_B", "controlType": "TURN"}, - {"machineName": "SR20JII_F", "controlType": "TURN"}, - {"machineName": "SR20JII_B", "controlType": "TURN"}, + {"machineName": "ISO_MILL", "controlType": "SIEMENS_840D"}, + {"machineName": "SIEMENS_MILL", "controlType": "SIEMENS_840D"}, + {"machineName": "FANUC_T", "controlType": "FANUC_STAR"}, + {"machineName": "SB12RG_F", "controlType": "FANUC_STAR"}, + {"machineName": "SB12RG_B", "controlType": "FANUC_STAR"}, + {"machineName": "SR20JII_F", "controlType": "FANUC_STAR"}, + {"machineName": "SR20JII_B", "controlType": "FANUC_STAR"}, ] # Add regex patterns to each machine From 6f65e57ee2f580857820d39a6e6d0802b953fcbd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Dec 2025 20:22:23 +0000 Subject: [PATCH 4/4] Align CGI server control type logic with domain module Co-authored-by: d-creations <99477364+d-creations@users.noreply.github.com> --- scripts/cgiserver.cgi | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/scripts/cgiserver.cgi b/scripts/cgiserver.cgi index c1e2834..a6798a0 100644 --- a/scripts/cgiserver.cgi +++ b/scripts/cgiserver.cgi @@ -38,30 +38,39 @@ def get_machine_regex_patterns(control_type: str) -> Dict[str, Any]: Returns a dictionary with pattern strings and descriptions. - Control type mapping: - - SIEMENS, SIEMENS_840D, MILL -> Siemens (R-parameters) - - TURN, FANUC, FANUC_STAR -> Fanuc (Hash-parameters) + Control type mapping (matching domain module): + - STAR, TURN -> Fanuc (Hash-parameters: #1, #2, etc.) + - SIEMENS, MILL -> Siemens (R-parameters: R1, R2, etc.) + - Default -> Fanuc Generic (Hash-parameters) """ + control_upper = control_type.upper() + is_fanuc = "STAR" in control_upper or "TURN" in control_upper + is_siemens = "SIEMENS" in control_upper or "MILL" in control_upper + # Use domain module if available for machine-specific patterns if USE_DOMAIN_MODULE: patterns = domain_get_machine_regex_patterns(control_type) # Add variable_prefix for frontend to parse user input (e.g., "R5 = 5" or "#5 = 5") - # The domain module uses control_type heuristics: SIEMENS/MILL -> Siemens, STAR/TURN -> Fanuc - control_upper = control_type.upper() - if "SIEMENS" in control_upper or ("MILL" in control_upper and "FANUC" not in control_upper): + if is_fanuc: + patterns["variables"]["prefix"] = FANUC_STAR_CONFIG.variable_prefix + elif is_siemens: patterns["variables"]["prefix"] = SIEMENS_840D_CONFIG.variable_prefix else: patterns["variables"]["prefix"] = FANUC_STAR_CONFIG.variable_prefix return patterns # Fallback patterns if domain module is not available - # Determine variable pattern based on control type - control_upper = control_type.upper() - if "SIEMENS" in control_upper or ("MILL" in control_upper and "FANUC" not in control_upper): + # Determine variable pattern based on control type (matching domain module logic) + if is_fanuc: + var_pattern = r"#(\d+)" + var_prefix = "#" + var_description = "Variables #1 - #999" + elif is_siemens: var_pattern = r"R(\d+)" var_prefix = "R" var_description = "Variables R1 - R999" else: + # Default to Fanuc var_pattern = r"#(\d+)" var_prefix = "#" var_description = "Variables #1 - #999"