diff --git a/python/commands/dynamic_symbol_loader.py b/python/commands/dynamic_symbol_loader.py index 96ede68..96f0df2 100644 --- a/python/commands/dynamic_symbol_loader.py +++ b/python/commands/dynamic_symbol_loader.py @@ -41,10 +41,12 @@ class DynamicSymbolLoader: Path("C:/Program Files/KiCad/9.0/share/kicad/symbols"), Path("C:/Program Files/KiCad/8.0/share/kicad/symbols"), Path("/Applications/KiCad/KiCad.app/Contents/SharedSupport/symbols"), + Path.home() / ".local" / "share" / "kicad" / "10.0" / "symbols", Path.home() / ".local" / "share" / "kicad" / "9.0" / "symbols", + Path.home() / "Documents" / "KiCad" / "10.0" / "3rdparty" / "symbols", Path.home() / "Documents" / "KiCad" / "9.0" / "3rdparty" / "symbols", ] - for env_var in ["KICAD9_SYMBOL_DIR", "KICAD8_SYMBOL_DIR", "KICAD_SYMBOL_DIR"]: + for env_var in ["KICAD10_SYMBOL_DIR", "KICAD9_SYMBOL_DIR", "KICAD8_SYMBOL_DIR", "KICAD_SYMBOL_DIR"]: if env_var in os.environ: possible_paths.insert(0, Path(os.environ[env_var])) @@ -97,6 +99,11 @@ class DynamicSymbolLoader: def _resolve_sym_uri(self, uri: str) -> Optional[str]: """Resolve environment variables in a sym-lib-table URI.""" env_map = { + "KICAD10_SYMBOL_DIR": [ + "/usr/share/kicad/symbols", + "C:/Program Files/KiCad/10.0/share/kicad/symbols", + "/Applications/KiCad/KiCad.app/Contents/SharedSupport/symbols", + ], "KICAD9_SYMBOL_DIR": [ "C:/Program Files/KiCad/9.0/share/kicad/symbols", "/usr/share/kicad/symbols", diff --git a/python/commands/library.py b/python/commands/library.py index abf30d0..ef50aee 100644 --- a/python/commands/library.py +++ b/python/commands/library.py @@ -58,13 +58,16 @@ class LibraryManager: """Get path to global fp-lib-table file""" # Try different possible locations kicad_config_paths = [ + Path.home() / ".config" / "kicad" / "10.0" / "fp-lib-table", Path.home() / ".config" / "kicad" / "9.0" / "fp-lib-table", Path.home() / ".config" / "kicad" / "8.0" / "fp-lib-table", Path.home() / ".config" / "kicad" / "fp-lib-table", # Windows paths + Path.home() / "AppData" / "Roaming" / "kicad" / "10.0" / "fp-lib-table", Path.home() / "AppData" / "Roaming" / "kicad" / "9.0" / "fp-lib-table", Path.home() / "AppData" / "Roaming" / "kicad" / "8.0" / "fp-lib-table", # macOS paths + Path.home() / "Library" / "Preferences" / "kicad" / "10.0" / "fp-lib-table", Path.home() / "Library" / "Preferences" / "kicad" / "9.0" / "fp-lib-table", Path.home() / "Library" / "Preferences" / "kicad" / "8.0" / "fp-lib-table", ] @@ -90,11 +93,21 @@ class LibraryManager: # Simple regex-based parser for lib entries # Pattern: (lib (name "NAME")(type TYPE)(uri "URI")...) - lib_pattern = r'\(lib\s+\(name\s+"?([^")\s]+)"?\)\s*\(type\s+[^)]+\)\s*\(uri\s+"?([^")\s]+)"?' + lib_pattern = r'\(lib\s+\(name\s+"?([^")\s]+)"?\)\s*\(type\s+"?([^")\s]+)"?\)\s*\(uri\s+"?([^")\s]+)"?' for match in re.finditer(lib_pattern, content, re.IGNORECASE): nickname = match.group(1) - uri = match.group(2) + lib_type = match.group(2) + uri = match.group(3) + + if lib_type.lower() == "table": + table_uri = uri + if os.path.isabs(table_uri) and os.path.isfile(table_uri): + logger.info(f" Following Table reference: {nickname} -> {table_uri}") + self._parse_fp_lib_table(Path(table_uri)) + else: + logger.warning(f" Could not resolve Table URI: {table_uri}") + continue # Resolve environment variables in URI resolved_uri = self._resolve_uri(uri) @@ -126,10 +139,12 @@ class LibraryManager: # Common KiCAD environment variables env_vars = { + "KICAD10_FOOTPRINT_DIR": self._find_kicad_footprint_dir(), "KICAD9_FOOTPRINT_DIR": self._find_kicad_footprint_dir(), "KICAD8_FOOTPRINT_DIR": self._find_kicad_footprint_dir(), "KICAD_FOOTPRINT_DIR": self._find_kicad_footprint_dir(), "KISYSMOD": self._find_kicad_footprint_dir(), + "KICAD10_3RD_PARTY": self._find_kicad_3rdparty_dir(), "KICAD9_3RD_PARTY": self._find_kicad_3rdparty_dir(), "KICAD8_3RD_PARTY": self._find_kicad_3rdparty_dir(), } diff --git a/python/commands/library_symbol.py b/python/commands/library_symbol.py index 82a7c7e..4de88f8 100644 --- a/python/commands/library_symbol.py +++ b/python/commands/library_symbol.py @@ -77,13 +77,16 @@ class SymbolLibraryManager: """Get path to global sym-lib-table file""" # Try different possible locations (same as fp-lib-table but for symbols) kicad_config_paths = [ + Path.home() / ".config" / "kicad" / "10.0" / "sym-lib-table", Path.home() / ".config" / "kicad" / "9.0" / "sym-lib-table", Path.home() / ".config" / "kicad" / "8.0" / "sym-lib-table", Path.home() / ".config" / "kicad" / "sym-lib-table", # Windows paths + Path.home() / "AppData" / "Roaming" / "kicad" / "10.0" / "sym-lib-table", Path.home() / "AppData" / "Roaming" / "kicad" / "9.0" / "sym-lib-table", Path.home() / "AppData" / "Roaming" / "kicad" / "8.0" / "sym-lib-table", # macOS paths + Path.home() / "Library" / "Preferences" / "kicad" / "10.0" / "sym-lib-table", Path.home() / "Library" / "Preferences" / "kicad" / "9.0" / "sym-lib-table", Path.home() / "Library" / "Preferences" / "kicad" / "8.0" / "sym-lib-table", ] @@ -109,11 +112,21 @@ class SymbolLibraryManager: # Simple regex-based parser for lib entries # Pattern: (lib (name "NAME")(type TYPE)(uri "URI")...) - lib_pattern = r'\(lib\s+\(name\s+"?([^")\s]+)"?\)\s*\(type\s+[^)]+\)\s*\(uri\s+"?([^")\s]+)"?' + lib_pattern = r'\(lib\s+\(name\s+"?([^")\s]+)"?\)\s*\(type\s+"?([^")\s]+)"?\)\s*\(uri\s+"?([^")\s]+)"?' for match in re.finditer(lib_pattern, content, re.IGNORECASE): nickname = match.group(1) - uri = match.group(2) + lib_type = match.group(2) + uri = match.group(3) + + if lib_type.lower() == "table": + table_uri = uri + if os.path.isabs(table_uri) and os.path.isfile(table_uri): + logger.info(f" Following Table reference: {nickname} -> {table_uri}") + self._parse_sym_lib_table(Path(table_uri)) + else: + logger.warning(f" Could not resolve Table URI: {table_uri}") + continue # Resolve environment variables in URI resolved_uri = self._resolve_uri(uri) @@ -142,9 +155,11 @@ class SymbolLibraryManager: # Common KiCAD environment variables env_vars = { + 'KICAD10_SYMBOL_DIR': self._find_kicad_symbol_dir(), 'KICAD9_SYMBOL_DIR': self._find_kicad_symbol_dir(), 'KICAD8_SYMBOL_DIR': self._find_kicad_symbol_dir(), 'KICAD_SYMBOL_DIR': self._find_kicad_symbol_dir(), + 'KICAD10_3RD_PARTY': self._find_3rd_party_dir(), 'KICAD9_3RD_PARTY': self._find_3rd_party_dir(), 'KICAD8_3RD_PARTY': self._find_3rd_party_dir(), 'KISYSSYM': self._find_kicad_symbol_dir(), @@ -198,11 +213,14 @@ class SymbolLibraryManager: def _find_3rd_party_dir(self) -> Optional[str]: """Find KiCAD 3rd party library directory (PCM installed libs)""" possible_paths = [ + str(Path.home() / "Documents" / "KiCad" / "10.0" / "3rdparty"), str(Path.home() / "Documents" / "KiCad" / "9.0" / "3rdparty"), str(Path.home() / "Documents" / "KiCad" / "8.0" / "3rdparty"), ] # Check environment variable + if 'KICAD10_3RD_PARTY' in os.environ: + possible_paths.insert(0, os.environ['KICAD10_3RD_PARTY']) if 'KICAD9_3RD_PARTY' in os.environ: possible_paths.insert(0, os.environ['KICAD9_3RD_PARTY']) if 'KICAD8_3RD_PARTY' in os.environ: