chore: set up pre-commit framework with general hooks
Add .pre-commit-config.yaml with pre-commit-hooks v5.0.0 (trailing whitespace, end-of-file fixer, yaml/json checks, large file guard, merge conflict detection). Add minimal pyproject.toml. Auto-fix trailing whitespace and missing end-of-file newlines across the codebase. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -20,57 +20,57 @@ class BoardCommands:
|
||||
def __init__(self, board: Optional[pcbnew.BOARD] = None):
|
||||
"""Initialize with optional board instance"""
|
||||
self.board = board
|
||||
|
||||
|
||||
# Initialize specialized command classes
|
||||
self.size_commands = BoardSizeCommands(board)
|
||||
self.layer_commands = BoardLayerCommands(board)
|
||||
self.outline_commands = BoardOutlineCommands(board)
|
||||
self.view_commands = BoardViewCommands(board)
|
||||
|
||||
|
||||
# Delegate board size commands
|
||||
def set_board_size(self, params: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Set the size of the PCB board"""
|
||||
self.size_commands.board = self.board
|
||||
return self.size_commands.set_board_size(params)
|
||||
|
||||
|
||||
# Delegate layer commands
|
||||
def add_layer(self, params: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Add a new layer to the PCB"""
|
||||
self.layer_commands.board = self.board
|
||||
return self.layer_commands.add_layer(params)
|
||||
|
||||
|
||||
def set_active_layer(self, params: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Set the active layer for PCB operations"""
|
||||
self.layer_commands.board = self.board
|
||||
return self.layer_commands.set_active_layer(params)
|
||||
|
||||
|
||||
def get_layer_list(self, params: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Get a list of all layers in the PCB"""
|
||||
self.layer_commands.board = self.board
|
||||
return self.layer_commands.get_layer_list(params)
|
||||
|
||||
|
||||
# Delegate board outline commands
|
||||
def add_board_outline(self, params: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Add a board outline to the PCB"""
|
||||
self.outline_commands.board = self.board
|
||||
return self.outline_commands.add_board_outline(params)
|
||||
|
||||
|
||||
def add_mounting_hole(self, params: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Add a mounting hole to the PCB"""
|
||||
self.outline_commands.board = self.board
|
||||
return self.outline_commands.add_mounting_hole(params)
|
||||
|
||||
|
||||
def add_text(self, params: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Add text annotation to the PCB"""
|
||||
self.outline_commands.board = self.board
|
||||
return self.outline_commands.add_text(params)
|
||||
|
||||
|
||||
# Delegate view commands
|
||||
def get_board_info(self, params: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Get information about the current board"""
|
||||
self.view_commands.board = self.board
|
||||
return self.view_commands.get_board_info(params)
|
||||
|
||||
|
||||
def get_board_2d_view(self, params: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Get a 2D image of the PCB"""
|
||||
self.view_commands.board = self.board
|
||||
|
||||
@@ -65,7 +65,7 @@ class BoardLayerCommands:
|
||||
# Set layer properties
|
||||
layer_stack.SetLayerName(layer_id, name)
|
||||
layer_stack.SetLayerType(layer_id, self._get_layer_type(layer_type))
|
||||
|
||||
|
||||
# Enable the layer
|
||||
self.board.SetLayerEnabled(layer_id, True)
|
||||
|
||||
@@ -168,7 +168,7 @@ class BoardLayerCommands:
|
||||
"message": "Failed to get layer list",
|
||||
"errorDetails": str(e)
|
||||
}
|
||||
|
||||
|
||||
def _get_layer_type(self, type_name: str) -> int:
|
||||
"""Convert layer type name to KiCAD layer type constant"""
|
||||
type_map = {
|
||||
|
||||
@@ -90,7 +90,7 @@ class BoardViewCommands:
|
||||
|
||||
# Create plot controller
|
||||
plotter = pcbnew.PLOT_CONTROLLER(self.board)
|
||||
|
||||
|
||||
# Set up plot options
|
||||
plot_opts = plotter.GetPlotOptions()
|
||||
plot_opts.SetOutputDirectory(os.path.dirname(self.board.GetFileName()))
|
||||
@@ -100,7 +100,7 @@ class BoardViewCommands:
|
||||
plot_opts.SetPlotFrameRef(False)
|
||||
plot_opts.SetPlotValue(True)
|
||||
plot_opts.SetPlotReference(True)
|
||||
|
||||
|
||||
# Plot to SVG first (for vector output)
|
||||
# Note: KiCAD 9.0 prepends the project name to the filename, so we use GetPlotFileName() to get the actual path
|
||||
plotter.OpenPlotfile("temp_view", pcbnew.PLOT_FORMAT_SVG, "Temporary View")
|
||||
@@ -139,7 +139,7 @@ class BoardViewCommands:
|
||||
from cairosvg import svg2png
|
||||
png_data = svg2png(url=temp_svg, output_width=width, output_height=height)
|
||||
os.remove(temp_svg)
|
||||
|
||||
|
||||
if format == "jpg":
|
||||
# Convert PNG to JPG
|
||||
img = Image.open(io.BytesIO(png_data))
|
||||
@@ -165,7 +165,7 @@ class BoardViewCommands:
|
||||
"message": "Failed to get board 2D view",
|
||||
"errorDetails": str(e)
|
||||
}
|
||||
|
||||
|
||||
def _get_layer_type_name(self, type_id: int) -> str:
|
||||
"""Convert KiCAD layer type constant to name"""
|
||||
type_map = {
|
||||
|
||||
@@ -752,14 +752,14 @@ class ComponentCommands:
|
||||
count = params.get("count")
|
||||
reference_prefix = params.get("referencePrefix", "U")
|
||||
value = params.get("value")
|
||||
|
||||
|
||||
if not component_id or not count:
|
||||
return {
|
||||
"success": False,
|
||||
"message": "Missing parameters",
|
||||
"errorDetails": "componentId and count are required"
|
||||
}
|
||||
|
||||
|
||||
if pattern == "grid":
|
||||
start_position = params.get("startPosition")
|
||||
rows = params.get("rows")
|
||||
@@ -768,21 +768,21 @@ class ComponentCommands:
|
||||
spacing_y = params.get("spacingY")
|
||||
rotation = params.get("rotation", 0)
|
||||
layer = params.get("layer", "F.Cu")
|
||||
|
||||
|
||||
if not start_position or not rows or not columns or not spacing_x or not spacing_y:
|
||||
return {
|
||||
"success": False,
|
||||
"message": "Missing grid parameters",
|
||||
"errorDetails": "For grid pattern, startPosition, rows, columns, spacingX, and spacingY are required"
|
||||
}
|
||||
|
||||
|
||||
if rows * columns != count:
|
||||
return {
|
||||
"success": False,
|
||||
"message": "Invalid grid parameters",
|
||||
"errorDetails": "rows * columns must equal count"
|
||||
}
|
||||
|
||||
|
||||
placed_components = self._place_grid_array(
|
||||
component_id,
|
||||
start_position,
|
||||
@@ -795,7 +795,7 @@ class ComponentCommands:
|
||||
rotation,
|
||||
layer
|
||||
)
|
||||
|
||||
|
||||
elif pattern == "circular":
|
||||
center = params.get("center")
|
||||
radius = params.get("radius")
|
||||
@@ -803,14 +803,14 @@ class ComponentCommands:
|
||||
angle_step = params.get("angleStep")
|
||||
rotation_offset = params.get("rotationOffset", 0)
|
||||
layer = params.get("layer", "F.Cu")
|
||||
|
||||
|
||||
if not center or not radius or not angle_step:
|
||||
return {
|
||||
"success": False,
|
||||
"message": "Missing circular parameters",
|
||||
"errorDetails": "For circular pattern, center, radius, and angleStep are required"
|
||||
}
|
||||
|
||||
|
||||
placed_components = self._place_circular_array(
|
||||
component_id,
|
||||
center,
|
||||
@@ -823,7 +823,7 @@ class ComponentCommands:
|
||||
rotation_offset,
|
||||
layer
|
||||
)
|
||||
|
||||
|
||||
else:
|
||||
return {
|
||||
"success": False,
|
||||
@@ -844,7 +844,7 @@ class ComponentCommands:
|
||||
"message": "Failed to place component array",
|
||||
"errorDetails": str(e)
|
||||
}
|
||||
|
||||
|
||||
def align_components(self, params: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Align multiple components along a line or distribute them evenly"""
|
||||
try:
|
||||
@@ -859,14 +859,14 @@ class ComponentCommands:
|
||||
alignment = params.get("alignment", "horizontal") # horizontal, vertical, or edge
|
||||
distribution = params.get("distribution", "none") # none, equal, or spacing
|
||||
spacing = params.get("spacing")
|
||||
|
||||
|
||||
if not references or len(references) < 2:
|
||||
return {
|
||||
"success": False,
|
||||
"message": "Missing references",
|
||||
"errorDetails": "At least two component references are required"
|
||||
}
|
||||
|
||||
|
||||
# Find all referenced components
|
||||
components = []
|
||||
for ref in references:
|
||||
@@ -878,7 +878,7 @@ class ComponentCommands:
|
||||
"errorDetails": f"Could not find component: {ref}"
|
||||
}
|
||||
components.append(module)
|
||||
|
||||
|
||||
# Perform alignment based on selected option
|
||||
if alignment == "horizontal":
|
||||
self._align_components_horizontally(components, distribution, spacing)
|
||||
@@ -929,7 +929,7 @@ class ComponentCommands:
|
||||
"message": "Failed to align components",
|
||||
"errorDetails": str(e)
|
||||
}
|
||||
|
||||
|
||||
def duplicate_component(self, params: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Duplicate an existing component"""
|
||||
try:
|
||||
@@ -944,14 +944,14 @@ class ComponentCommands:
|
||||
new_reference = params.get("newReference")
|
||||
position = params.get("position")
|
||||
rotation = params.get("rotation")
|
||||
|
||||
|
||||
if not reference or not new_reference:
|
||||
return {
|
||||
"success": False,
|
||||
"message": "Missing parameters",
|
||||
"errorDetails": "reference and newReference are required"
|
||||
}
|
||||
|
||||
|
||||
# Find the source component
|
||||
source = self.board.FindFootprintByReference(reference)
|
||||
if not source:
|
||||
@@ -960,7 +960,7 @@ class ComponentCommands:
|
||||
"message": "Component not found",
|
||||
"errorDetails": f"Could not find component: {reference}"
|
||||
}
|
||||
|
||||
|
||||
# Check if new reference already exists
|
||||
if self.board.FindFootprintByReference(new_reference):
|
||||
return {
|
||||
@@ -968,7 +968,7 @@ class ComponentCommands:
|
||||
"message": "Reference already exists",
|
||||
"errorDetails": f"A component with reference {new_reference} already exists"
|
||||
}
|
||||
|
||||
|
||||
# Create new footprint with the same properties
|
||||
new_module = pcbnew.FOOTPRINT(self.board)
|
||||
# For KiCAD 9.x compatibility, use SetFPID instead of SetFootprintName
|
||||
@@ -976,13 +976,13 @@ class ComponentCommands:
|
||||
new_module.SetValue(source.GetValue())
|
||||
new_module.SetReference(new_reference)
|
||||
new_module.SetLayer(source.GetLayer())
|
||||
|
||||
|
||||
# Copy pads and other items
|
||||
for pad in source.Pads():
|
||||
new_pad = pcbnew.PAD(new_module)
|
||||
new_pad.Copy(pad)
|
||||
new_module.Add(new_pad)
|
||||
|
||||
|
||||
# Set position if provided, otherwise use offset from original
|
||||
if position:
|
||||
scale = 1000000 if position.get("unit", "mm") == "mm" else 25400000
|
||||
@@ -993,17 +993,17 @@ class ComponentCommands:
|
||||
# Offset by 5mm
|
||||
source_pos = source.GetPosition()
|
||||
new_module.SetPosition(pcbnew.VECTOR2I(source_pos.x + 5000000, source_pos.y))
|
||||
|
||||
|
||||
# Set rotation if provided, otherwise use same as original
|
||||
if rotation is not None:
|
||||
rotation_angle = pcbnew.EDA_ANGLE(rotation, pcbnew.DEGREES_T)
|
||||
new_module.SetOrientation(rotation_angle)
|
||||
else:
|
||||
new_module.SetOrientation(source.GetOrientation())
|
||||
|
||||
|
||||
# Add to board
|
||||
self.board.Add(new_module)
|
||||
|
||||
|
||||
# Get final position in mm
|
||||
pos = new_module.GetPosition()
|
||||
|
||||
@@ -1031,32 +1031,32 @@ class ComponentCommands:
|
||||
"message": "Failed to duplicate component",
|
||||
"errorDetails": str(e)
|
||||
}
|
||||
|
||||
def _place_grid_array(self, component_id: str, start_position: Dict[str, Any],
|
||||
|
||||
def _place_grid_array(self, component_id: str, start_position: Dict[str, Any],
|
||||
rows: int, columns: int, spacing_x: float, spacing_y: float,
|
||||
reference_prefix: str, value: str, rotation: float, layer: str) -> List[Dict[str, Any]]:
|
||||
"""Place components in a grid pattern and return the list of placed components"""
|
||||
placed = []
|
||||
|
||||
|
||||
# Convert spacing to nm
|
||||
unit = start_position.get("unit", "mm")
|
||||
scale = 1000000 if unit == "mm" else 25400000 # mm or inch to nm
|
||||
spacing_x_nm = int(spacing_x * scale)
|
||||
spacing_y_nm = int(spacing_y * scale)
|
||||
|
||||
|
||||
# Get layer ID
|
||||
layer_id = self.board.GetLayerID(layer)
|
||||
|
||||
|
||||
for row in range(rows):
|
||||
for col in range(columns):
|
||||
# Calculate position
|
||||
x = start_position["x"] + (col * spacing_x)
|
||||
y = start_position["y"] + (row * spacing_y)
|
||||
|
||||
|
||||
# Generate reference
|
||||
index = row * columns + col + 1
|
||||
component_reference = f"{reference_prefix}{index}"
|
||||
|
||||
|
||||
# Place component
|
||||
result = self.place_component({
|
||||
"componentId": component_id,
|
||||
@@ -1066,37 +1066,37 @@ class ComponentCommands:
|
||||
"rotation": rotation,
|
||||
"layer": layer
|
||||
})
|
||||
|
||||
|
||||
if result["success"]:
|
||||
placed.append(result["component"])
|
||||
|
||||
|
||||
return placed
|
||||
|
||||
def _place_circular_array(self, component_id: str, center: Dict[str, Any],
|
||||
radius: float, count: int, angle_start: float,
|
||||
angle_step: float, reference_prefix: str,
|
||||
|
||||
def _place_circular_array(self, component_id: str, center: Dict[str, Any],
|
||||
radius: float, count: int, angle_start: float,
|
||||
angle_step: float, reference_prefix: str,
|
||||
value: str, rotation_offset: float, layer: str) -> List[Dict[str, Any]]:
|
||||
"""Place components in a circular pattern and return the list of placed components"""
|
||||
placed = []
|
||||
|
||||
|
||||
# Get unit
|
||||
unit = center.get("unit", "mm")
|
||||
|
||||
|
||||
for i in range(count):
|
||||
# Calculate angle for this component
|
||||
angle = angle_start + (i * angle_step)
|
||||
angle_rad = math.radians(angle)
|
||||
|
||||
|
||||
# Calculate position
|
||||
x = center["x"] + (radius * math.cos(angle_rad))
|
||||
y = center["y"] + (radius * math.sin(angle_rad))
|
||||
|
||||
|
||||
# Generate reference
|
||||
component_reference = f"{reference_prefix}{i+1}"
|
||||
|
||||
|
||||
# Calculate rotation (pointing outward from center)
|
||||
component_rotation = angle + rotation_offset
|
||||
|
||||
|
||||
# Place component
|
||||
result = self.place_component({
|
||||
"componentId": component_id,
|
||||
@@ -1106,114 +1106,114 @@ class ComponentCommands:
|
||||
"rotation": component_rotation,
|
||||
"layer": layer
|
||||
})
|
||||
|
||||
|
||||
if result["success"]:
|
||||
placed.append(result["component"])
|
||||
|
||||
|
||||
return placed
|
||||
|
||||
def _align_components_horizontally(self, components: List[pcbnew.FOOTPRINT],
|
||||
|
||||
def _align_components_horizontally(self, components: List[pcbnew.FOOTPRINT],
|
||||
distribution: str, spacing: Optional[float]) -> None:
|
||||
"""Align components horizontally and optionally distribute them"""
|
||||
if not components:
|
||||
return
|
||||
|
||||
|
||||
# Find the average Y coordinate
|
||||
y_sum = sum(module.GetPosition().y for module in components)
|
||||
y_avg = y_sum // len(components)
|
||||
|
||||
|
||||
# Sort components by X position
|
||||
components.sort(key=lambda m: m.GetPosition().x)
|
||||
|
||||
|
||||
# Set Y coordinate for all components
|
||||
for module in components:
|
||||
pos = module.GetPosition()
|
||||
module.SetPosition(pcbnew.VECTOR2I(pos.x, y_avg))
|
||||
|
||||
|
||||
# Handle distribution if requested
|
||||
if distribution == "equal" and len(components) > 1:
|
||||
# Get leftmost and rightmost X coordinates
|
||||
x_min = components[0].GetPosition().x
|
||||
x_max = components[-1].GetPosition().x
|
||||
|
||||
|
||||
# Calculate equal spacing
|
||||
total_space = x_max - x_min
|
||||
spacing_nm = total_space // (len(components) - 1)
|
||||
|
||||
|
||||
# Set X positions with equal spacing
|
||||
for i in range(1, len(components) - 1):
|
||||
pos = components[i].GetPosition()
|
||||
new_x = x_min + (i * spacing_nm)
|
||||
components[i].SetPosition(pcbnew.VECTOR2I(new_x, pos.y))
|
||||
|
||||
|
||||
elif distribution == "spacing" and spacing is not None:
|
||||
# Convert spacing to nanometers
|
||||
spacing_nm = int(spacing * 1000000) # assuming mm
|
||||
|
||||
|
||||
# Set X positions with the specified spacing
|
||||
x_current = components[0].GetPosition().x
|
||||
for i in range(1, len(components)):
|
||||
pos = components[i].GetPosition()
|
||||
x_current += spacing_nm
|
||||
components[i].SetPosition(pcbnew.VECTOR2I(x_current, pos.y))
|
||||
|
||||
def _align_components_vertically(self, components: List[pcbnew.FOOTPRINT],
|
||||
|
||||
def _align_components_vertically(self, components: List[pcbnew.FOOTPRINT],
|
||||
distribution: str, spacing: Optional[float]) -> None:
|
||||
"""Align components vertically and optionally distribute them"""
|
||||
if not components:
|
||||
return
|
||||
|
||||
|
||||
# Find the average X coordinate
|
||||
x_sum = sum(module.GetPosition().x for module in components)
|
||||
x_avg = x_sum // len(components)
|
||||
|
||||
|
||||
# Sort components by Y position
|
||||
components.sort(key=lambda m: m.GetPosition().y)
|
||||
|
||||
|
||||
# Set X coordinate for all components
|
||||
for module in components:
|
||||
pos = module.GetPosition()
|
||||
module.SetPosition(pcbnew.VECTOR2I(x_avg, pos.y))
|
||||
|
||||
|
||||
# Handle distribution if requested
|
||||
if distribution == "equal" and len(components) > 1:
|
||||
# Get topmost and bottommost Y coordinates
|
||||
y_min = components[0].GetPosition().y
|
||||
y_max = components[-1].GetPosition().y
|
||||
|
||||
|
||||
# Calculate equal spacing
|
||||
total_space = y_max - y_min
|
||||
spacing_nm = total_space // (len(components) - 1)
|
||||
|
||||
|
||||
# Set Y positions with equal spacing
|
||||
for i in range(1, len(components) - 1):
|
||||
pos = components[i].GetPosition()
|
||||
new_y = y_min + (i * spacing_nm)
|
||||
components[i].SetPosition(pcbnew.VECTOR2I(pos.x, new_y))
|
||||
|
||||
|
||||
elif distribution == "spacing" and spacing is not None:
|
||||
# Convert spacing to nanometers
|
||||
spacing_nm = int(spacing * 1000000) # assuming mm
|
||||
|
||||
|
||||
# Set Y positions with the specified spacing
|
||||
y_current = components[0].GetPosition().y
|
||||
for i in range(1, len(components)):
|
||||
pos = components[i].GetPosition()
|
||||
y_current += spacing_nm
|
||||
components[i].SetPosition(pcbnew.VECTOR2I(pos.x, y_current))
|
||||
|
||||
|
||||
def _align_components_to_edge(self, components: List[pcbnew.FOOTPRINT], edge: str) -> None:
|
||||
"""Align components to the specified edge of the board"""
|
||||
if not components:
|
||||
return
|
||||
|
||||
|
||||
# Get board bounds
|
||||
board_box = self.board.GetBoardEdgesBoundingBox()
|
||||
left = board_box.GetLeft()
|
||||
right = board_box.GetRight()
|
||||
top = board_box.GetTop()
|
||||
bottom = board_box.GetBottom()
|
||||
|
||||
|
||||
# Align based on specified edge
|
||||
if edge == "left":
|
||||
for module in components:
|
||||
|
||||
@@ -522,7 +522,7 @@ class LibraryCommands:
|
||||
if path == library_path:
|
||||
library_nickname = nick
|
||||
break
|
||||
|
||||
|
||||
# Minimal info — always returned even if the parser fails
|
||||
info: Dict = {
|
||||
"library": library_nickname,
|
||||
|
||||
@@ -31,7 +31,7 @@ class LibraryManager:
|
||||
# Extract library names from paths
|
||||
library_names = [os.path.splitext(os.path.basename(lib))[0] for lib in libraries]
|
||||
print(f"Found {len(library_names)} libraries: {', '.join(library_names[:10])}{'...' if len(library_names) > 10 else ''}")
|
||||
|
||||
|
||||
# Return both full paths and library names
|
||||
return {"paths": libraries, "names": library_names}
|
||||
|
||||
@@ -43,7 +43,7 @@ class LibraryManager:
|
||||
# without loading each one. We might need to implement this using KiCAD's Python API
|
||||
# directly, or by using a different approach.
|
||||
# For now, this is a placeholder implementation.
|
||||
|
||||
|
||||
# A potential approach would be to load the library file using KiCAD's Python API
|
||||
# or by parsing the library file format.
|
||||
# KiCAD symbol libraries are .kicad_sym files which are S-expression format
|
||||
@@ -73,23 +73,23 @@ class LibraryManager:
|
||||
# 1. Getting a list of all libraries using list_available_libraries
|
||||
# 2. For each library, getting a list of all symbols
|
||||
# 3. Filtering symbols based on the query
|
||||
|
||||
|
||||
# For now, this is a placeholder implementation
|
||||
libraries = LibraryManager.list_available_libraries(search_paths)
|
||||
|
||||
|
||||
results = []
|
||||
print(f"Searched for symbols matching '{query}'. This requires advanced implementation.")
|
||||
return results
|
||||
except Exception as e:
|
||||
print(f"Error searching for symbols matching '{query}': {e}")
|
||||
return []
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_default_symbol_for_component_type(component_type, search_paths=None):
|
||||
"""Get a recommended default symbol for a given component type"""
|
||||
# This method provides a simplified way to get a symbol for common component types
|
||||
# It's useful when the user doesn't specify a particular library/symbol
|
||||
|
||||
|
||||
# Define common mappings from component type to library/symbol
|
||||
common_mappings = {
|
||||
"resistor": {"library": "Device", "symbol": "R"},
|
||||
@@ -103,19 +103,19 @@ class LibraryManager:
|
||||
"microcontroller": {"library": "MCU_Module", "symbol": "Arduino_UNO_R3"},
|
||||
# Add more common components as needed
|
||||
}
|
||||
|
||||
|
||||
# Normalize input to lowercase
|
||||
component_type_lower = component_type.lower()
|
||||
|
||||
|
||||
# Try direct match first
|
||||
if component_type_lower in common_mappings:
|
||||
return common_mappings[component_type_lower]
|
||||
|
||||
|
||||
# Try partial matches
|
||||
for key, value in common_mappings.items():
|
||||
if component_type_lower in key or key in component_type_lower:
|
||||
return value
|
||||
|
||||
|
||||
# Default fallback
|
||||
return {"library": "Device", "symbol": "R"}
|
||||
|
||||
@@ -127,15 +127,15 @@ if __name__ == '__main__':
|
||||
first_lib = libraries["paths"][0]
|
||||
lib_name = libraries["names"][0]
|
||||
print(f"Testing with first library: {lib_name} ({first_lib})")
|
||||
|
||||
|
||||
# List symbols in the first library
|
||||
symbols = LibraryManager.list_library_symbols(first_lib)
|
||||
# This will report that it requires advanced implementation
|
||||
|
||||
|
||||
# Get default symbol for a component type
|
||||
resistor_sym = LibraryManager.get_default_symbol_for_component_type("resistor")
|
||||
print(f"Default symbol for resistor: {resistor_sym['library']}/{resistor_sym['symbol']}")
|
||||
|
||||
|
||||
# Try a partial match
|
||||
cap_sym = LibraryManager.get_default_symbol_for_component_type("cap")
|
||||
print(f"Default symbol for 'cap': {cap_sym['library']}/{cap_sym['symbol']}")
|
||||
|
||||
Reference in New Issue
Block a user