KiCad PCB EDA Suite
Loading...
Searching...
No Matches
easypc_classes_connectivity.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
22
23#include <climits>
24
25
26namespace EASYPC
27{
28
29namespace
30{
31
32 // Classes whose fields no importer reads
33 constexpr FIELD_ROW NET_ARRAY[] = { { 0, INT_MAX, "i" } };
34 constexpr FIELD_ROW SHEET[] = { { 0, INT_MAX, "s" } };
35 constexpr FIELD_ROW NAME_CHANGE[] = { { 0, INT_MAX, "i s2" } };
36
37} // namespace
38
39
41{
42 co_await SOURCE_DESIGN_ITEM::Load( aAr );
43
44 const int v = ItemFormat( aAr );
45
46 Position = ReadPoint( aAr );
47 Symbol = co_await aAr.Object();
48 Coppers = co_await aAr.Object();
49 Pads = co_await aAr.Object();
50 Texts = co_await aAr.Object();
51
52 if( v < 10003 )
53 {
54 OBJECT* symbolName = co_await aAr.Object();
55
56 // Before format 10003 the symbol name stands for the value positions; the component instance sets the types
57 ConvertedValuePositions = std::make_unique<SOURCE_DESIGN_LIST>();
58 ConvertedSymbolName = std::make_unique<SOURCE_VALUE_POSITION>();
59 ConvertedSymbolName->Types = 0x1f;
60
61 if( const SOURCE_TEXT_POSITION* name = dynamic_cast<const SOURCE_TEXT_POSITION*>( symbolName ) )
62 {
64 vp.TextStyle = name->TextStyle;
65 vp.Mirrored = name->Mirrored;
66 vp.Position = name->Position;
67 vp.Rotation = name->Rotation;
68 vp.Layer = name->Layer;
69 vp.Alignment = name->Alignment;
70 }
71
72 ConvertedValuePositions->Items.push_back( ConvertedSymbolName.get() );
74 }
75 else
76 {
77 ValuePositions = co_await aAr.Object();
78 }
79
80 Angle = aAr.I32();
81 Gate = aAr.I32();
82 Mirrored = aAr.InBool();
83
84 if( v < 3000 )
85 {
86 Placed = true;
87 co_return;
88 }
89
90 Placed = aAr.InBool();
91 aAr.InBool(); // fixed
92
93 if( v > 17999 )
94 aAr.Skip( 8 ); // scale
95
96 if( v > 23999 )
97 aAr.Skip( 4 );
98}
99
100
102{
103 co_await SOURCE_DESIGN_ITEM::Load( aAr );
104
105 Component = co_await aAr.Object();
106 Name = aAr.ReadString();
107 SymbolInstances = co_await aAr.Object();
108
109 const int v = ItemFormat( aAr );
110
111 if( v < 10003 )
112 {
114
115 // Four display flags in stream order
117 {
118 if( aAr.InBool() )
119 ValueTypes |= bit;
120 }
121
122 // They become the types of each gate's first value position
124 {
125 const std::vector<OBJECT*>& vps = ListItems( inst->ValuePositions );
126
127 if( SOURCE_VALUE_POSITION* first =
128 vps.empty() ? nullptr : dynamic_cast<SOURCE_VALUE_POSITION*>( vps.front() ) )
129 first->Types = ValueTypes;
130 }
131 }
132 else if( v >= 10005 )
133 {
134 ValueTypes = v < 19000 ? aAr.U32() : aAr.U64();
135 }
136
137 if( v >= 12000 )
138 Suppress = aAr.I32();
139
140 if( v > 12999 )
141 co_await aAr.Object(); // sheet
142
143 // Variants and associated parts are null tags in every known file
144 if( v > 16999 )
145 co_await aAr.Object();
146
147 if( v > 21999 )
148 co_await aAr.Object();
149}
150
151
153{
154 co_await SOURCE_DESIGN_ITEM::Load( aAr );
155
156 const int v = ItemFormat( aAr );
157
158 Node = co_await aAr.Object();
159 Pad = co_await aAr.Object();
160
161 if( v < 10003 )
162 {
163 PinName = co_await aAr.Object();
164 PinNumber = co_await aAr.Object();
165
166 if( v < 2103 )
167 co_return;
168
169 StyleException = co_await aAr.Object();
170
171 if( v < 9000 )
172 co_return;
173 }
174 else
175 {
176 ValuePositions = co_await aAr.Object();
177 StyleException = co_await aAr.Object();
178 }
179
180 aAr.Skip( 8 ); // teardrop, testland
181
182 if( v > 15000 )
183 aAr.Skip( 4 );
184
185 if( v > 22999 )
186 aAr.Skip( 4 );
187
188 if( v > 23999 )
189 aAr.Skip( 12 );
190}
191
192
194{
195 co_await SOURCE_DESIGN_ITEM::Load( aAr );
196 Copper = co_await aAr.Object();
197}
198
199
201{
202 co_await SOURCE_DESIGN_ITEM::Load( aAr );
203
204 Name = aAr.ReadString();
205 Connections = co_await aAr.Object();
206 Nodes = co_await aAr.Object();
207 NetClass = co_await aAr.Object();
208 aAr.InBool();
209 GuardSpacing = aAr.I32();
210
211 const int v = ItemFormat( aAr );
212
213 if( v > 5999 )
214 {
215 aAr.InBool();
216 aAr.Skip( 4 );
217 }
218
219 // Connection display, a BOOL before 15003
220 if( v > 8999 && v < 15003 )
221 aAr.InBool();
222 else if( v > 8999 )
223 aAr.Skip( 4 );
224}
225
226
228{
229 // The item fields, then the text position fields without their item fields
230 co_await SOURCE_DESIGN_ITEM::Load( aAr );
231 co_await LoadRemainder( aAr );
232 Displayed = aAr.InBool();
233}
234
235
237{
238 co_await SOURCE_DESIGN_ITEM::Load( aAr );
239
240 Item = co_await aAr.Object();
241 NetName = co_await aAr.Object();
242 Position = ReadPoint( aAr );
243}
244
245
247{
248 co_await SOURCE_DESIGN_ITEM::Load( aAr );
249
250 Node1 = co_await aAr.Object();
251 Node2 = co_await aAr.Object();
252 Track = co_await aAr.Object();
253}
254
255
257{
258 co_await SOURCE_DESIGN_ITEM::Load( aAr );
259
260 const int v = ItemFormat( aAr );
261
262 Position = ReadPoint( aAr );
263 Style = co_await aAr.Object();
264 Node = co_await aAr.Object();
265 Angle = aAr.I32();
266
267 if( v > 8002 )
268 aAr.InBool(); // fixed
269
270 if( v > 8999 )
271 aAr.Skip( v > 15000 ? 12 : 8 ); // teardrop, testland, connect type
272}
273
274
276{
277 co_await SOURCE_CONNECT_POINT::Load( aAr );
278
279 const int v = ItemFormat( aAr );
280
281 if( v <= 8999 )
282 co_return;
283
284 aAr.InBool(); // locked
285
286 if( v > 10000 )
287 LayerSpan = co_await aAr.Object();
288
289 if( v > 17000 )
290 aAr.Skip( 1 );
291
292 if( v >= 25000 )
293 Tented = aAr.Bool();
294}
295
296
302
303
305{
306 co_await SOURCE_COMMON_SHAPE::Load( aAr );
307
308 co_await aAr.Object(); // default style
309 Layer = co_await aAr.Object();
310
311 // Both flags gate on the format of the shape's parent, and only when it exists
312 if( !dynamic_cast<const SOURCE_DESIGN_ITEM*>( Parent ) )
313 co_return;
314
315 const int v = Parent->ItemFormat( aAr );
316
317 if( v > 8002 )
318 aAr.InBool();
319
320 if( v > 8999 )
321 aAr.Skip( 1 );
322}
323
324
326{
327 co_await SOURCE_COMMON_SEGMENT::LoadTail( aAr );
328
329 Style = co_await aAr.Object();
330 aAr.InBool();
331}
332
333
335{
336 co_await SOURCE_SHAPE_ITEM::Load( aAr );
337
338 const int v = ItemFormat( aAr );
339
340 if( v > 16000 )
341 Name = aAr.ReadString();
342
343 for( int32_t i = aAr.I32(); i > 0; --i )
344 Nets.push_back( co_await aAr.Object() );
345
346 Terminals = co_await aAr.Object();
347
348 if( v > 16001 )
349 ValuePositions = co_await aAr.Object();
350}
351
352
354{
355 co_await SOURCE_SHAPE_ITEM::Load( aAr );
356
357 if( ItemFormat( aAr ) > 5999 )
358 aAr.InBool();
359
360 if( ItemFormat( aAr ) > 11000 )
361 Plated = aAr.I32();
362}
363
364
366{
367 Register<SOURCE_SYMBOL_INSTANCE>( aReg, { "CSymbolInstance" } );
368 Register<SOURCE_COMPONENT_INSTANCE>( aReg, { "CComponentInstance" } );
369 Register<SOURCE_PAD_INSTANCE>( aReg, { "CPadInstance" } );
370 Register<SOURCE_COPPER_INSTANCE>( aReg, { "CCopperInstance" } );
371 Register<SOURCE_NET>( aReg, { "CNet" } );
372 RegisterSkipped<SOURCE_DESIGN_LIST>( aReg, "CNetArray", NET_ARRAY );
373 Register<SOURCE_NET_NAME>( aReg, { "CNetName" } );
374 Register<SOURCE_NODE>( aReg, { "CNode" } );
375 Register<SOURCE_CONNECTION>( aReg, { "CConnection" } );
376 Register<SOURCE_CONNECT_POINT>( aReg, { "CConnectPoint" } );
377 Register<SOURCE_JUNCTION>( aReg, { "CJunction" } );
378 Register<SOURCE_COPPER_TERMINAL>( aReg, { "CCopperTerminal" } );
379 Register<SOURCE_VIA>( aReg, { "CVia" } );
380 Register<SOURCE_BUS_TERMINAL>( aReg, { "CBusTerminal" } );
381 Register<SOURCE_TRACK>( aReg, { "CTrack" } );
382 Register<SOURCE_TRACK_SEGMENT>( aReg, { "CTrackSegment" } );
383 Register<SOURCE_BUS>( aReg, { "CBus" } );
384 Register<SOURCE_BOARD>( aReg, { "CBoard" } );
386 RegisterSkipped<SOURCE_DESIGN_ITEM>( aReg, "CNameChange", NAME_CHANGE );
388 { "CSymbolInstanceArray", "CComponentInstanceArray", "CPadInstanceArray",
389 "CCopperInstanceArray", "CCopperTerminalArray", "CNodeArray", "CConnectionArray",
390 "CBusArray", "CBusTerminalArray", "CBoardArray", "CSheetArray",
391 "CComponentColoursArray", "CComponentRulesArray", "CNameChangeList" } );
392}
393
394} // namespace EASYPC
const char * name
One archive load stream; it owns every object it creates.
void Skip(size_t aLen)
wxString ReadString()
ANSI (windows-1252) or the 0xFF 0xFFFE UTF-16 form.
bool InBool()
one or four bytes, depending on the active format
OBJECT_AWAITER Object()
A loader coroutine. Awaiting one queues it on its archive's frame stack instead of nesting the call.
Placed instances and connectivity: component, symbol and pad instances, nets, nodes,...
Symbols, components and gates, embedded in designs or the single object of a library item stream.
std::map< std::string, std::function< std::unique_ptr< OBJECT >()>, std::less<> > REGISTRY
std::vector< T * > TypedItems(const OBJECT *aList)
The items of ListItems that are a T, in order.
void RegisterSkipped(REGISTRY &aReg, const char *aName, std::span< const FIELD_ROW > aRows)
const std::vector< OBJECT * > & ListItems(const OBJECT *aList)
The items of a design list or array, empty for anything else.
void Register(REGISTRY &aReg, std::initializer_list< const char * > aNames)
Register the class names whose objects load as a T.
POINT32 ReadPoint(ARCHIVE &aAr)
void RegisterConnectivityClasses(REGISTRY &aReg)
A run of fields present from version since to until inclusive.
Root of every deserialized object.
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
std::vector< OBJECT * > Nets
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
LOAD_TASK LoadTail(ARCHIVE &aAr) override
The fields a subclass reads after the next vertex.
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
OBJECT * Track
null for an unrouted connection
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
OBJECT * Copper
the definition's free copper
The base of nearly every class.
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
int ItemFormat(const ARCHIVE &aAr) const override
The version this object gates on; the base is the archive's current read format.
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
OBJECT * NetClass
the design's first class when the file stores none
OBJECT * Item
pad instance, via, junction, copper or bus terminal, or free pad
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
OBJECT * PinNumber
placed pin number, below 10003
OBJECT * PinName
placed pin name, below 10003
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
OBJECT * Node
null when unconnected
OBJECT * StyleException
pad style overriding the pad's own
OBJECT * Pad
the definition's free pad
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
A placed footprint (gate -1) or a placed schematic gate.
std::unique_ptr< SOURCE_VALUE_POSITION > ConvertedSymbolName
std::unique_ptr< SOURCE_DESIGN_LIST > ConvertedValuePositions
Below 10003 the stored symbol name becomes the first value position of a new list.
OBJECT * ValuePositions
below 10003 built from the stored symbol name
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
LOAD_TASK LoadRemainder(ARCHIVE &aAr)
The text position fields that follow the item fields.
OBJECT * Style
track style of the span leaving this vertex
LOAD_TASK LoadTail(ARCHIVE &aAr) override
The fields a subclass reads after the next vertex.
OBJECT * Layer
null in a schematic
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.