29#include <wx/translation.h>
39 constexpr FIELD_ROW LEGACY_COLOURS[] = { { 0, INT_MAX,
"i2 b i6" },
40 { 9000, INT_MAX,
"i" },
41 { 0, INT_MAX,
"b i b i b i5 b i b8" },
43 { 0x838, INT_MAX,
"b2" },
44 { 2001, INT_MAX,
"i b" },
45 { 3000, INT_MAX,
"i b" },
46 { 6000, INT_MAX,
"b2 i3" },
47 { 7000, INT_MAX,
"o a b i b17" },
48 { 7001, INT_MAX,
"b" },
49 { 8000, INT_MAX,
"b4" },
50 { 8000, 0x1f42,
"b2" },
51 { 8000, INT_MAX,
"b s" },
52 { 0x1f43, INT_MAX,
"b8 i4" },
53 { 9000, INT_MAX,
"b i" },
54 { 9001, INT_MAX,
"b i" },
55 { 0x2712, INT_MAX,
"b6 f" },
56 { 0x2716, INT_MAX,
"b" },
57 { 0x2717, INT_MAX,
"i2 b i2 b i2 b i b i b i b" },
58 { 12001, INT_MAX,
"i b" },
59 { 0x2ee6, INT_MAX,
"i b" },
60 { 0x3e81, INT_MAX,
"i b" },
61 { 13000, INT_MAX,
"b2 i b3 i i b2 i b2" },
62 { 0x32c9, INT_MAX,
"i b" },
63 { 14000, INT_MAX,
"i b i b b21" },
64 { 14001, INT_MAX,
"b" },
65 { 0x36b3, INT_MAX,
"b2" },
66 { 15000, INT_MAX,
"i b2 i b4" },
67 { 16001, INT_MAX,
"b2" },
68 { 17000, INT_MAX,
"b i b i" } };
72 constexpr FIELD_ROW DEFAULTS_TAIL[] = { { 7000, INT_MAX,
"o4 s i3 b i2" }, { 8001, INT_MAX,
"b s o b s o3" },
73 { 0x1f43, INT_MAX,
"s" }, { 9000, INT_MAX,
"o" },
74 { 0x2716, INT_MAX,
"s" }, { 0x2717, INT_MAX,
"o2 s i3 o2 s 1 i3" },
75 { 12001, INT_MAX,
"o2 s" }, { 0x2ee4, INT_MAX,
"s 12" },
76 { 0x2ee6, INT_MAX,
"o4 s" }, { 14000, INT_MAX,
"o6 s3 i3 1 i2 13" },
77 { 0x36b2, INT_MAX,
"s" }, { 0x36b3, INT_MAX,
"1 s i2" },
78 { 16001, INT_MAX,
"i s" }, { 18000, INT_MAX,
"1 i2 1 s i2 13" } };
82 constexpr FIELD_ROW DESIGN_TAIL[] = { { 12000, INT_MAX,
"o" }, { 16000, INT_MAX,
"o2" }, { 17000, INT_MAX,
"o" },
83 { 22000, INT_MAX,
"o" }, { 0x6d62, INT_MAX,
"s" }, { 29001, INT_MAX,
"o" },
84 { 30000, INT_MAX,
"o" }, { 0x7531, INT_MAX,
"o" }, { 0x36b1, INT_MAX,
"o" } };
89 constexpr FIELD_ROW DESIGN_VIEW[] = { { 0, INT_MAX,
"i3" } };
90 constexpr FIELD_ROW ONE_LIST[] = { { 0, INT_MAX,
"o" } };
91 constexpr FIELD_ROW GRID[] = { { 0, INT_MAX,
"s b i2 b i2 b i b2 i5 b" },
92 { 17000, INT_MAX,
"b" },
93 { 20000, INT_MAX,
"b" } };
94 constexpr FIELD_ROW SCREEN_GRID[] = { { 0, INT_MAX,
"i" }, { 9000, INT_MAX,
"i b3" }, { 13000, INT_MAX,
"b" } };
98 void setGrow( std::vector<int32_t>& aArray,
size_t aIndex, int32_t aValue )
100 if( ( aIndex < aArray.size() ? aArray[aIndex] : 0 ) == aValue )
103 if( aArray.size() <= aIndex )
104 aArray.resize( aIndex + 1, 0 );
106 aArray[aIndex] = aValue;
110 void clearIfSet( std::vector<int32_t>& aArray,
size_t aIndex )
112 if( aIndex < aArray.size() )
120 member->DesignOwned = aDesignOwned;
122 co_await aAr.Embedded( aMember, aClass );
129 LOAD_TASK
Load( ARCHIVE& aAr )
override
132 if( !DesignOwned || ItemFormat( aAr ) >= 0x835 )
135 aAr.Skip( ItemFormat( aAr ) >= 9000 ? 12 : 8 );
142 LOAD_TASK
Load( ARCHIVE& aAr )
override
145 const int v = ItemFormat( aAr );
151 aAr.Skip( 8 *
size_t( aAr.Count() ) );
153 co_await SkipFields( aAr, v >= 0x839 ?
"i6 b6 i4" :
"i6" );
160 LOAD_TASK
Load( ARCHIVE& aAr )
override
164 if( ItemFormat( aAr ) > 0x1f41 )
165 aAr.Skip( 4 *
size_t( std::max( 0, aAr.I32() ) ) );
174 LOAD_TASK
Load( ARCHIVE& aAr )
override
178 if( ItemFormat( aAr ) < 10000 )
181 for( uint32_t i = aAr.Count(); i > 0; --i )
184 aAr.Skip( 4 *
size_t( aAr.Count() ) );
191 LOAD_TASK
Load( ARCHIVE& aAr )
override
195 const int v = ItemFormat( aAr );
199 co_await SkipRows( aAr, v, LEGACY_COLOURS );
204 aAr.Skip( 8 *
size_t( std::max( 0, aAr.I32() ) ) );
206 for(
int i = 0; i < 3; ++i )
207 aAr.Skip( 5 *
size_t( std::max( 0, aAr.I32() ) ) );
215 void assignDefaultNetClass(
OBJECT* aNets,
OBJECT* aNetClasses )
217 const std::vector<OBJECT*>& classes =
ListItems( aNetClasses );
221 if( !net->NetClass && !classes.empty() )
222 net->NetClass = classes.front();
241 co_await loadMember( aAr, *member, aClass, aDesignOwned );
270 for( uint32_t i = aAr.
Count(); i > 0; --i )
272 int32_t key = aAr.
I32();
281 { 13000, INT_MAX,
"1" }, { 14000, INT_MAX,
"s" }, { 0x36b2, INT_MAX,
"s" }, { 17000, INT_MAX,
"s" }
288 aAr.
Skip( 4 *
size_t( std::max( 0, aAr.
I32() ) ) );
294 for( uint32_t i = aAr.
Count(); i > 0; --i )
309 setGrow(
Params, 24, 0x6338 );
310 setGrow(
Params, 25, 0xf80c );
318 setGrow(
Params, 37, 0xfe );
331 co_await SkipFields( aAr, v > 12000 ?
"o4" :
"o3" );
341 co_await SkipRows( aAr, v, DEFAULTS_TAIL );
348 for( uint32_t i = aAr.
U32(); i > 0; --i )
351 size_t versionPos = aAr.
Pos();
357 wxString::Format(
_(
"Easy-PC design format %d at offset %zu is too new." ),
Version, versionPos ) );
366 co_await SkipFields( aAr, v < 0x834 ?
"i4 b i" :
"i4" );
399 co_await SkipFields( aAr, v < 0x835 ?
"i3 o2" :
"i o2" );
433 co_await SkipRows( aAr, v, DESIGN_TAIL );
437 co_await SkipMember( aAr,
"CScreenGrid",
true );
438 co_await SkipMember( aAr,
"COldWorkingGrid",
true );
441 co_await SkipMember( aAr,
"CDesignColours",
true );
442 co_await SkipMember( aAr,
"CDesignView",
true );
448 co_await SkipMember( aAr,
"CRoutingParameters",
true );
451 co_await SkipMember( aAr,
"CPlacementParameters",
true );
466 co_await SkipMember( aAr,
"CManufactureData",
true );
470 co_await loadMember( aAr,
DrcParameters,
"CCheckParameters",
true );
471 co_await SkipMember( aAr,
"CCheckParameters",
true );
476 co_await SkipMember( aAr,
"CComponentRules" );
479 co_await SkipMember( aAr,
"CComponentColours" );
KICAD_PLUGIN_EXPORT SCENEGRAPH * Load(char const *aFileName)
Read a model file and creates a generic display structure.
One archive load stream; it owns every object it creates.
int CurrentReadFormat() const
static std::unique_ptr< OBJECT > Create(const char *aClass)
An object of a registered class, not yet loaded.
wxString ReadString()
ANSI (windows-1252) or the 0xFF 0xFFFE UTF-16 form.
void SetProduct(int32_t aProduct)
TYPED_AWAITER< T > ObjectAs()
bool InBool()
one or four bytes, depending on the active format
int DocumentVersion() const
void SetDocumentVersion(int aVersion)
void SetBooleanIsByte(bool aByte)
uint32_t Count()
a 16-bit count, 0xFFFF escaping to 32 bits
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.
The project file (.prj), a bare archive stream.
The design document and the design parameter tables the importers use.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
std::map< std::string, std::function< std::unique_ptr< OBJECT >()>, std::less<> > REGISTRY
LOAD_TASK SkipRows(ARCHIVE &aAr, int aVersion, std::span< const FIELD_ROW > aRows)
SkipFields for every row aVersion falls in, in order.
LOAD_TASK SkipMember(ARCHIVE &aAr, const char *aClass, bool aDesignOwned)
Load and drop an embedded member of a registered class; aDesignOwned marks its design as owner.
constexpr int NEWEST_ITEM_FORMAT
The newest item format a file can carry (30001)
LOAD_TASK SkipFields(ARCHIVE &aAr, std::string_view aOps)
Read and drop a run of fields described by aOps, each letter optionally followed by a repeat count: b...
constexpr char THERMAL_RULE_SET[]
A thermal rule set as SkipFields ops: owner, four thermal rules (owner and an int array),...
std::vector< T * > TypedItems(const OBJECT *aList)
The items of ListItems that are a T, in order.
void RegisterRootClasses(REGISTRY &aReg)
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)
A member stored inside the design.
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.
A run of fields present from version since to until inclusive.
Root of every deserialized object.
A point read as two int32 values.
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
std::map< int32_t, int32_t > Values
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
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.
int ItemFormat(const ARCHIVE &aAr) const override
The version this object gates on; the base is the archive's current read format.
int32_t Param(int aIndex, int32_t aDefault=0) const
The value at aIndex, or aDefault where the stored array is shorter, as the accessors do.
std::vector< int32_t > Params
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
LOAD_TASK Load(ARCHIVE &aAr) override
Read this object's fields.
OBJECT * Spacings
legacy or current design spacings, depending on format
SOURCE_CHECK_PARAMETERS DrcParameters
from 13000
SOURCE_DESIGN_PARAMETERS DesignParameters
after 8000
SOURCE_DEFAULTS * Defaults
OBJECT * ComponentInstances
Common grid settings, available to every frame.