kicad-sch-api 0.3.0__py3-none-any.whl → 0.5.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. kicad_sch_api/__init__.py +68 -3
  2. kicad_sch_api/cli/__init__.py +45 -0
  3. kicad_sch_api/cli/base.py +302 -0
  4. kicad_sch_api/cli/bom.py +164 -0
  5. kicad_sch_api/cli/erc.py +229 -0
  6. kicad_sch_api/cli/export_docs.py +289 -0
  7. kicad_sch_api/cli/kicad_to_python.py +169 -0
  8. kicad_sch_api/cli/netlist.py +94 -0
  9. kicad_sch_api/cli/types.py +43 -0
  10. kicad_sch_api/collections/__init__.py +36 -0
  11. kicad_sch_api/collections/base.py +604 -0
  12. kicad_sch_api/collections/components.py +1623 -0
  13. kicad_sch_api/collections/junctions.py +206 -0
  14. kicad_sch_api/collections/labels.py +508 -0
  15. kicad_sch_api/collections/wires.py +292 -0
  16. kicad_sch_api/core/__init__.py +37 -2
  17. kicad_sch_api/core/collections/__init__.py +5 -0
  18. kicad_sch_api/core/collections/base.py +248 -0
  19. kicad_sch_api/core/component_bounds.py +34 -7
  20. kicad_sch_api/core/components.py +213 -52
  21. kicad_sch_api/core/config.py +110 -15
  22. kicad_sch_api/core/connectivity.py +692 -0
  23. kicad_sch_api/core/exceptions.py +175 -0
  24. kicad_sch_api/core/factories/__init__.py +5 -0
  25. kicad_sch_api/core/factories/element_factory.py +278 -0
  26. kicad_sch_api/core/formatter.py +60 -9
  27. kicad_sch_api/core/geometry.py +94 -5
  28. kicad_sch_api/core/junctions.py +26 -75
  29. kicad_sch_api/core/labels.py +324 -0
  30. kicad_sch_api/core/managers/__init__.py +30 -0
  31. kicad_sch_api/core/managers/base.py +76 -0
  32. kicad_sch_api/core/managers/file_io.py +246 -0
  33. kicad_sch_api/core/managers/format_sync.py +502 -0
  34. kicad_sch_api/core/managers/graphics.py +580 -0
  35. kicad_sch_api/core/managers/hierarchy.py +661 -0
  36. kicad_sch_api/core/managers/metadata.py +271 -0
  37. kicad_sch_api/core/managers/sheet.py +492 -0
  38. kicad_sch_api/core/managers/text_elements.py +537 -0
  39. kicad_sch_api/core/managers/validation.py +476 -0
  40. kicad_sch_api/core/managers/wire.py +410 -0
  41. kicad_sch_api/core/nets.py +305 -0
  42. kicad_sch_api/core/no_connects.py +252 -0
  43. kicad_sch_api/core/parser.py +194 -970
  44. kicad_sch_api/core/parsing_utils.py +63 -0
  45. kicad_sch_api/core/pin_utils.py +103 -9
  46. kicad_sch_api/core/schematic.py +1328 -1079
  47. kicad_sch_api/core/texts.py +316 -0
  48. kicad_sch_api/core/types.py +159 -23
  49. kicad_sch_api/core/wires.py +27 -75
  50. kicad_sch_api/exporters/__init__.py +10 -0
  51. kicad_sch_api/exporters/python_generator.py +610 -0
  52. kicad_sch_api/exporters/templates/default.py.jinja2 +65 -0
  53. kicad_sch_api/geometry/__init__.py +38 -0
  54. kicad_sch_api/geometry/font_metrics.py +22 -0
  55. kicad_sch_api/geometry/routing.py +211 -0
  56. kicad_sch_api/geometry/symbol_bbox.py +608 -0
  57. kicad_sch_api/interfaces/__init__.py +17 -0
  58. kicad_sch_api/interfaces/parser.py +76 -0
  59. kicad_sch_api/interfaces/repository.py +70 -0
  60. kicad_sch_api/interfaces/resolver.py +117 -0
  61. kicad_sch_api/parsers/__init__.py +14 -0
  62. kicad_sch_api/parsers/base.py +145 -0
  63. kicad_sch_api/parsers/elements/__init__.py +22 -0
  64. kicad_sch_api/parsers/elements/graphics_parser.py +564 -0
  65. kicad_sch_api/parsers/elements/label_parser.py +216 -0
  66. kicad_sch_api/parsers/elements/library_parser.py +165 -0
  67. kicad_sch_api/parsers/elements/metadata_parser.py +58 -0
  68. kicad_sch_api/parsers/elements/sheet_parser.py +352 -0
  69. kicad_sch_api/parsers/elements/symbol_parser.py +485 -0
  70. kicad_sch_api/parsers/elements/text_parser.py +250 -0
  71. kicad_sch_api/parsers/elements/wire_parser.py +242 -0
  72. kicad_sch_api/parsers/registry.py +155 -0
  73. kicad_sch_api/parsers/utils.py +80 -0
  74. kicad_sch_api/symbols/__init__.py +18 -0
  75. kicad_sch_api/symbols/cache.py +467 -0
  76. kicad_sch_api/symbols/resolver.py +361 -0
  77. kicad_sch_api/symbols/validators.py +504 -0
  78. kicad_sch_api/utils/logging.py +555 -0
  79. kicad_sch_api/utils/logging_decorators.py +587 -0
  80. kicad_sch_api/utils/validation.py +16 -22
  81. kicad_sch_api/validation/__init__.py +25 -0
  82. kicad_sch_api/validation/erc.py +171 -0
  83. kicad_sch_api/validation/erc_models.py +203 -0
  84. kicad_sch_api/validation/pin_matrix.py +243 -0
  85. kicad_sch_api/validation/validators.py +391 -0
  86. kicad_sch_api/wrappers/__init__.py +14 -0
  87. kicad_sch_api/wrappers/base.py +89 -0
  88. kicad_sch_api/wrappers/wire.py +198 -0
  89. kicad_sch_api-0.5.1.dist-info/METADATA +540 -0
  90. kicad_sch_api-0.5.1.dist-info/RECORD +114 -0
  91. kicad_sch_api-0.5.1.dist-info/entry_points.txt +4 -0
  92. {kicad_sch_api-0.3.0.dist-info → kicad_sch_api-0.5.1.dist-info}/top_level.txt +1 -0
  93. mcp_server/__init__.py +34 -0
  94. mcp_server/example_logging_integration.py +506 -0
  95. mcp_server/models.py +252 -0
  96. mcp_server/server.py +357 -0
  97. mcp_server/tools/__init__.py +32 -0
  98. mcp_server/tools/component_tools.py +516 -0
  99. mcp_server/tools/connectivity_tools.py +532 -0
  100. mcp_server/tools/consolidated_tools.py +1216 -0
  101. mcp_server/tools/pin_discovery.py +333 -0
  102. mcp_server/utils/__init__.py +38 -0
  103. mcp_server/utils/logging.py +127 -0
  104. mcp_server/utils.py +36 -0
  105. kicad_sch_api/core/manhattan_routing.py +0 -430
  106. kicad_sch_api/core/simple_manhattan.py +0 -228
  107. kicad_sch_api/core/wire_routing.py +0 -380
  108. kicad_sch_api-0.3.0.dist-info/METADATA +0 -483
  109. kicad_sch_api-0.3.0.dist-info/RECORD +0 -31
  110. kicad_sch_api-0.3.0.dist-info/entry_points.txt +0 -2
  111. {kicad_sch_api-0.3.0.dist-info → kicad_sch_api-0.5.1.dist-info}/WHEEL +0 -0
  112. {kicad_sch_api-0.3.0.dist-info → kicad_sch_api-0.5.1.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,271 @@
1
+ """
2
+ Metadata Manager for KiCAD schematic configuration.
3
+
4
+ Handles schematic-level settings, properties, and configuration including
5
+ paper size, title block, version information, and instance sections.
6
+ """
7
+
8
+ import logging
9
+ from typing import Any, Dict, List, Optional
10
+
11
+ from .base import BaseManager
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ class MetadataManager(BaseManager):
17
+ """
18
+ Manages schematic metadata and configuration settings.
19
+
20
+ Responsible for:
21
+ - Title block management
22
+ - Paper size and page setup
23
+ - Version and generator information
24
+ - Library and instance sections
25
+ - Schema-level properties
26
+ """
27
+
28
+ def __init__(self, schematic_data: Dict[str, Any]):
29
+ """
30
+ Initialize MetadataManager with schematic data.
31
+
32
+ Args:
33
+ schematic_data: Reference to schematic data dictionary
34
+ """
35
+ super().__init__(schematic_data)
36
+
37
+ def set_paper_size(self, paper: str) -> None:
38
+ """
39
+ Set paper size for the schematic.
40
+
41
+ Args:
42
+ paper: Paper size (e.g., "A4", "A3", "Letter", "Legal")
43
+ """
44
+ from ..config import config
45
+
46
+ if paper not in config.paper.valid_sizes:
47
+ logger.warning(f"Unusual paper size: {paper}. Valid sizes: {config.paper.valid_sizes}")
48
+
49
+ self._data["paper"] = paper
50
+ logger.debug(f"Set paper size: {paper}")
51
+
52
+ def set_version_info(
53
+ self, version: Optional[int] = None, generator: Optional[str] = None
54
+ ) -> None:
55
+ """
56
+ Set KiCAD version and generator information.
57
+
58
+ Args:
59
+ version: KiCAD schema version number
60
+ generator: Generator application string
61
+ """
62
+ if version is not None:
63
+ self._data["version"] = version
64
+ logger.debug(f"Set version: {version}")
65
+
66
+ if generator is not None:
67
+ self._data["generator"] = generator
68
+ logger.debug(f"Set generator: {generator}")
69
+
70
+ def set_title_block(
71
+ self,
72
+ title: str = "",
73
+ date: str = "",
74
+ rev: str = "",
75
+ company: str = "",
76
+ comments: Optional[Dict[int, str]] = None,
77
+ ) -> None:
78
+ """
79
+ Set title block information.
80
+
81
+ Args:
82
+ title: Schematic title
83
+ date: Creation/revision date
84
+ rev: Revision number
85
+ company: Company name
86
+ comments: Numbered comments (1, 2, 3, etc.)
87
+ """
88
+ if comments is None:
89
+ comments = {}
90
+
91
+ self._data["title_block"] = {
92
+ "title": title,
93
+ "date": date,
94
+ "rev": rev,
95
+ "company": company,
96
+ "comments": comments,
97
+ }
98
+
99
+ logger.debug(f"Set title block: {title} rev {rev}")
100
+
101
+ def copy_metadata_from(self, source_data: Dict[str, Any]) -> None:
102
+ """
103
+ Copy metadata from another schematic.
104
+
105
+ Args:
106
+ source_data: Source schematic data to copy from
107
+ """
108
+ # Copy basic metadata
109
+ for key in ["paper", "version", "generator"]:
110
+ if key in source_data:
111
+ self._data[key] = source_data[key]
112
+
113
+ # Copy title block if present
114
+ if "title_block" in source_data:
115
+ self._data["title_block"] = source_data["title_block"].copy()
116
+
117
+ # Copy lib_symbols if present
118
+ if "lib_symbols" in source_data:
119
+ self._data["lib_symbols"] = source_data["lib_symbols"].copy()
120
+
121
+ logger.info("Copied metadata from source schematic")
122
+
123
+ def add_lib_symbols_section(self, lib_symbols: Dict[str, Any]) -> None:
124
+ """
125
+ Add or update lib_symbols section.
126
+
127
+ Args:
128
+ lib_symbols: Library symbols data
129
+ """
130
+ self._data["lib_symbols"] = lib_symbols
131
+ logger.debug(f"Updated lib_symbols section with {len(lib_symbols)} symbols")
132
+
133
+ def add_instances_section(self, instances: Dict[str, Any]) -> None:
134
+ """
135
+ Add or update symbol instances section.
136
+
137
+ Args:
138
+ instances: Symbol instances data
139
+ """
140
+ self._data["symbol_instances"] = instances
141
+ logger.debug("Updated symbol_instances section")
142
+
143
+ def add_sheet_instances_section(self, sheet_instances: List[Dict]) -> None:
144
+ """
145
+ Add or update sheet instances section.
146
+
147
+ Args:
148
+ sheet_instances: List of sheet instance data
149
+ """
150
+ self._data["sheet_instances"] = sheet_instances
151
+ logger.debug(f"Updated sheet_instances section with {len(sheet_instances)} instances")
152
+
153
+ def set_uuid(self, uuid_str: str) -> None:
154
+ """
155
+ Set schematic UUID.
156
+
157
+ Args:
158
+ uuid_str: UUID string for the schematic
159
+ """
160
+ self._data["uuid"] = uuid_str
161
+ logger.debug(f"Set schematic UUID: {uuid_str}")
162
+
163
+ def get_version(self) -> Optional[int]:
164
+ """Get KiCAD schema version."""
165
+ return self._data.get("version")
166
+
167
+ def get_generator(self) -> Optional[str]:
168
+ """Get generator application string."""
169
+ return self._data.get("generator")
170
+
171
+ def get_uuid(self) -> Optional[str]:
172
+ """Get schematic UUID."""
173
+ return self._data.get("uuid")
174
+
175
+ def get_paper_size(self) -> Optional[str]:
176
+ """Get paper size."""
177
+ return self._data.get("paper")
178
+
179
+ def get_title_block(self) -> Dict[str, Any]:
180
+ """
181
+ Get title block information.
182
+
183
+ Returns:
184
+ Title block data dictionary
185
+ """
186
+ return self._data.get("title_block", {})
187
+
188
+ def get_lib_symbols(self) -> Dict[str, Any]:
189
+ """
190
+ Get lib_symbols section.
191
+
192
+ Returns:
193
+ Library symbols data
194
+ """
195
+ return self._data.get("lib_symbols", {})
196
+
197
+ def get_symbol_instances(self) -> Dict[str, Any]:
198
+ """
199
+ Get symbol instances section.
200
+
201
+ Returns:
202
+ Symbol instances data
203
+ """
204
+ return self._data.get("symbol_instances", {})
205
+
206
+ def get_sheet_instances(self) -> List[Dict]:
207
+ """
208
+ Get sheet instances section.
209
+
210
+ Returns:
211
+ List of sheet instances
212
+ """
213
+ return self._data.get("sheet_instances", [])
214
+
215
+ def get_metadata_summary(self) -> Dict[str, Any]:
216
+ """
217
+ Get comprehensive metadata summary.
218
+
219
+ Returns:
220
+ Dictionary with all metadata information
221
+ """
222
+ title_block = self.get_title_block()
223
+
224
+ return {
225
+ "version": self.get_version(),
226
+ "generator": self.get_generator(),
227
+ "uuid": self.get_uuid(),
228
+ "paper": self.get_paper_size(),
229
+ "title": title_block.get("title", ""),
230
+ "revision": title_block.get("rev", ""),
231
+ "company": title_block.get("company", ""),
232
+ "date": title_block.get("date", ""),
233
+ "comments": title_block.get("comments", {}),
234
+ "lib_symbols_count": len(self.get_lib_symbols()),
235
+ "symbol_instances_count": (
236
+ len(self.get_symbol_instances())
237
+ if isinstance(self.get_symbol_instances(), list)
238
+ else 1 if self.get_symbol_instances() else 0
239
+ ),
240
+ "sheet_instances_count": len(self.get_sheet_instances()),
241
+ }
242
+
243
+ def validate_metadata(self) -> List[str]:
244
+ """
245
+ Validate metadata consistency and completeness.
246
+
247
+ Returns:
248
+ List of validation warnings/issues
249
+ """
250
+ issues = []
251
+
252
+ # Check required fields
253
+ if not self.get_version():
254
+ issues.append("Missing KiCAD version")
255
+
256
+ if not self.get_generator():
257
+ issues.append("Missing generator information")
258
+
259
+ # Check title block
260
+ title_block = self.get_title_block()
261
+ if not title_block.get("title"):
262
+ issues.append("Title block missing title")
263
+
264
+ # Check paper size
265
+ from ..config import config
266
+
267
+ paper = self.get_paper_size()
268
+ if paper and paper not in config.paper.valid_sizes:
269
+ issues.append(f"Non-standard paper size: {paper}")
270
+
271
+ return issues