- Implement 3D model analysis and mechanical constraints checking - Add advanced DRC rule customization for HDI, RF, and automotive applications - Create symbol library management with analysis and validation tools - Implement PCB layer stack-up analysis with impedance calculations - Fix Context parameter validation errors causing client failures - Add enhanced tool annotations with examples for better LLM compatibility - Include comprehensive test coverage improvements (22.21% coverage) - Add CLAUDE.md documentation for development guidance New Advanced Tools: • 3D model analysis: analyze_3d_models, check_mechanical_constraints • Advanced DRC: create_drc_rule_set, analyze_pcb_drc_violations • Symbol management: analyze_symbol_library, validate_symbol_library • Layer analysis: analyze_pcb_stackup, calculate_trace_impedance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
73 lines
2.3 KiB
Python
73 lines
2.3 KiB
Python
"""
|
|
Utility functions for detecting and selecting available KiCad API approaches.
|
|
"""
|
|
|
|
import os
|
|
import subprocess
|
|
import shutil
|
|
from typing import Tuple, Optional, Literal
|
|
|
|
from kicad_mcp.config import system
|
|
|
|
|
|
def check_for_cli_api() -> bool:
|
|
"""Check if KiCad CLI API is available.
|
|
|
|
Returns:
|
|
True if KiCad CLI is available, False otherwise
|
|
"""
|
|
try:
|
|
# Check if kicad-cli is in PATH
|
|
if system == "Windows":
|
|
# On Windows, check for kicad-cli.exe
|
|
kicad_cli = shutil.which("kicad-cli.exe")
|
|
else:
|
|
# On Unix-like systems
|
|
kicad_cli = shutil.which("kicad-cli")
|
|
|
|
if kicad_cli:
|
|
# Verify it's a working kicad-cli
|
|
if system == "Windows":
|
|
cmd = [kicad_cli, "--version"]
|
|
else:
|
|
cmd = [kicad_cli, "--version"]
|
|
|
|
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
if result.returncode == 0:
|
|
print(f"Found working kicad-cli: {kicad_cli}")
|
|
return True
|
|
|
|
# Check common installation locations if not found in PATH
|
|
if system == "Windows":
|
|
# Common Windows installation paths
|
|
potential_paths = [
|
|
r"C:\Program Files\KiCad\bin\kicad-cli.exe",
|
|
r"C:\Program Files (x86)\KiCad\bin\kicad-cli.exe",
|
|
]
|
|
elif system == "Darwin": # macOS
|
|
# Common macOS installation paths
|
|
potential_paths = [
|
|
"/Applications/KiCad/KiCad.app/Contents/MacOS/kicad-cli",
|
|
"/Applications/KiCad/kicad-cli",
|
|
]
|
|
else: # Linux
|
|
# Common Linux installation paths
|
|
potential_paths = [
|
|
"/usr/bin/kicad-cli",
|
|
"/usr/local/bin/kicad-cli",
|
|
"/opt/kicad/bin/kicad-cli",
|
|
]
|
|
|
|
# Check each potential path
|
|
for path in potential_paths:
|
|
if os.path.exists(path) and os.access(path, os.X_OK):
|
|
print(f"Found kicad-cli at common location: {path}")
|
|
return True
|
|
|
|
print("KiCad CLI API is not available")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"Error checking for KiCad CLI API: {str(e)}")
|
|
return False
|