Fix KiCAD 9.0 API compatibility for board, export, and view commands
This commit resolves critical KiCAD 9.0 API compatibility issues identified through comprehensive testing and code audit. ## Major Fixes ### board/size.py - Board Outline Creation - **Issue:** Stub implementation didn't create actual board edges - **Fix:** Delegate to BoardOutlineCommands for proper Edge.Cuts geometry creation - **Impact:** set_board_size() now creates actual rectangular board outlines - **Tested:** 100x80mm and 4x3 inch board creation validated ### board/view.py - Board Extents Query - **Issue:** get_board_extents() command not implemented - **Fix:** New implementation returns complete bounding box data - **Returns:** left, top, right, bottom, width, height, center coordinates - **Tested:** Successfully returns 93.55mm × 212.05mm for test board ### board/__init__.py - Delegation Wiring - **Fix:** Added get_board_extents() delegation to BoardViewCommands - **Impact:** Completes board query API surface ### export.py - 3D Model Export - **Issue:** Get3DViewer() doesn't work in headless KiCAD 9.0 - **Fix:** Replace with kicad-cli subprocess calls for STEP/VRML export - **New:** _find_kicad_cli() helper for cross-platform CLI detection - **Features:** - STEP export with component/copper/silkscreen/soldermask options - VRML export with configurable units - 5-minute timeout for large boards - Proper error handling and validation - **Tested:** - STEP export: 144.65 MB (full), 114.61 MB (board-only) - VRML export: 60.69 MB - All exports successful on 415-component board ## Test Results All changes validated with test_kicad_9_fixes.py: - ✅ Board outline creation (mm and inch units) - ✅ Board extents query - ✅ STEP 3D export (full and board-only) - ✅ VRML 3D export - ✅ Error handling and validation ## Compatibility - **KiCAD Version:** 9.0.6 (tested) - **Backward Compatible:** Yes (kicad-cli available in KiCAD 8.0+) - **Platform:** Windows, macOS, Linux ## Breaking Changes None - all changes are additions or fixes to broken functionality. ## Related - Complements previous fixes: design_rules.py, component.py, layers.py - Part of comprehensive KiCAD 9.0 compatibility effort - Documentation: PYTHON_AUDIT_REPORT_FINAL.md, TEST_RESULTS.md Fixes #<issue-number-if-applicable>
This commit is contained in:
@@ -176,3 +176,57 @@ class BoardViewCommands:
|
||||
}
|
||||
# Note: LT_USER was removed in KiCAD 9.0
|
||||
return type_map.get(type_id, "unknown")
|
||||
|
||||
def get_board_extents(self, params: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Get the bounding box extents of the board"""
|
||||
try:
|
||||
if not self.board:
|
||||
return {
|
||||
"success": False,
|
||||
"message": "No board is loaded",
|
||||
"errorDetails": "Load or create a board first"
|
||||
}
|
||||
|
||||
# Get unit preference (default to mm)
|
||||
unit = params.get("unit", "mm")
|
||||
scale = 1000000 if unit == "mm" else 25400000 # nm to mm or inch
|
||||
|
||||
# Get board bounding box
|
||||
board_box = self.board.GetBoardEdgesBoundingBox()
|
||||
|
||||
# Extract bounds in nanometers, then convert
|
||||
left = board_box.GetLeft() / scale
|
||||
top = board_box.GetTop() / scale
|
||||
right = board_box.GetRight() / scale
|
||||
bottom = board_box.GetBottom() / scale
|
||||
width = board_box.GetWidth() / scale
|
||||
height = board_box.GetHeight() / scale
|
||||
|
||||
# Get center point
|
||||
center_x = board_box.GetCenter().x / scale
|
||||
center_y = board_box.GetCenter().y / scale
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"extents": {
|
||||
"left": left,
|
||||
"top": top,
|
||||
"right": right,
|
||||
"bottom": bottom,
|
||||
"width": width,
|
||||
"height": height,
|
||||
"center": {
|
||||
"x": center_x,
|
||||
"y": center_y
|
||||
},
|
||||
"unit": unit
|
||||
}
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting board extents: {str(e)}")
|
||||
return {
|
||||
"success": False,
|
||||
"message": "Failed to get board extents",
|
||||
"errorDetails": str(e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user