KiCad PCB EDA Suite
Loading...
Searching...
No Matches
altium_parser_pcb.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 (C) 2020 Thomas Pointhuber <[email protected]>
5 * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <map>
26#include <unordered_map>
27
28#include <ki_exception.h>
29#include <math/util.h>
30
31#include <wx/log.h>
32
33#include "altium_parser_pcb.h"
36
37
38ALTIUM_LAYER altium_layer_from_name( const wxString& aName )
39{
40 static const std::unordered_map<std::string, ALTIUM_LAYER> hash_map = {
41 { "TOP", ALTIUM_LAYER::TOP_LAYER },
42 { "MID1", ALTIUM_LAYER::MID_LAYER_1 },
43 { "MID2", ALTIUM_LAYER::MID_LAYER_2 },
44 { "MID3", ALTIUM_LAYER::MID_LAYER_3 },
45 { "MID4", ALTIUM_LAYER::MID_LAYER_4 },
46 { "MID5", ALTIUM_LAYER::MID_LAYER_5 },
47 { "MID6", ALTIUM_LAYER::MID_LAYER_6 },
48 { "MID7", ALTIUM_LAYER::MID_LAYER_7 },
49 { "MID8", ALTIUM_LAYER::MID_LAYER_8 },
50 { "MID9", ALTIUM_LAYER::MID_LAYER_9 },
51 { "MID10", ALTIUM_LAYER::MID_LAYER_10 },
52 { "MID11", ALTIUM_LAYER::MID_LAYER_11 },
53 { "MID12", ALTIUM_LAYER::MID_LAYER_12 },
54 { "MID13", ALTIUM_LAYER::MID_LAYER_13 },
55 { "MID14", ALTIUM_LAYER::MID_LAYER_14 },
56 { "MID15", ALTIUM_LAYER::MID_LAYER_15 },
57 { "MID16", ALTIUM_LAYER::MID_LAYER_16 },
58 { "MID17", ALTIUM_LAYER::MID_LAYER_17 },
59 { "MID18", ALTIUM_LAYER::MID_LAYER_18 },
60 { "MID19", ALTIUM_LAYER::MID_LAYER_19 },
61 { "MID20", ALTIUM_LAYER::MID_LAYER_20 },
62 { "MID21", ALTIUM_LAYER::MID_LAYER_21 },
63 { "MID22", ALTIUM_LAYER::MID_LAYER_22 },
64 { "MID23", ALTIUM_LAYER::MID_LAYER_23 },
65 { "MID24", ALTIUM_LAYER::MID_LAYER_24 },
66 { "MID25", ALTIUM_LAYER::MID_LAYER_25 },
67 { "MID26", ALTIUM_LAYER::MID_LAYER_26 },
68 { "MID27", ALTIUM_LAYER::MID_LAYER_27 },
69 { "MID28", ALTIUM_LAYER::MID_LAYER_28 },
70 { "MID29", ALTIUM_LAYER::MID_LAYER_29 },
71 { "MID30", ALTIUM_LAYER::MID_LAYER_30 },
72 { "BOTTOM", ALTIUM_LAYER::BOTTOM_LAYER },
73
74 { "TOPOVERLAY", ALTIUM_LAYER::TOP_OVERLAY },
75 { "BOTTOMOVERLAY", ALTIUM_LAYER::BOTTOM_OVERLAY },
76 { "TOPPASTE", ALTIUM_LAYER::TOP_PASTE },
77 { "BOTTOMPASTE", ALTIUM_LAYER::BOTTOM_PASTE },
78 { "TOPSOLDER", ALTIUM_LAYER::TOP_SOLDER },
79 { "BOTTOMSOLDER", ALTIUM_LAYER::BOTTOM_SOLDER },
80
97
98 { "DRILLGUIDE", ALTIUM_LAYER::DRILL_GUIDE },
99 { "KEEPOUT", ALTIUM_LAYER::KEEP_OUT_LAYER },
100
101 { "MECHANICAL1", ALTIUM_LAYER::MECHANICAL_1 },
102 { "MECHANICAL2", ALTIUM_LAYER::MECHANICAL_2 },
103 { "MECHANICAL3", ALTIUM_LAYER::MECHANICAL_3 },
104 { "MECHANICAL4", ALTIUM_LAYER::MECHANICAL_4 },
105 { "MECHANICAL5", ALTIUM_LAYER::MECHANICAL_5 },
106 { "MECHANICAL6", ALTIUM_LAYER::MECHANICAL_6 },
107 { "MECHANICAL7", ALTIUM_LAYER::MECHANICAL_7 },
108 { "MECHANICAL8", ALTIUM_LAYER::MECHANICAL_8 },
109 { "MECHANICAL9", ALTIUM_LAYER::MECHANICAL_9 },
110 { "MECHANICAL10", ALTIUM_LAYER::MECHANICAL_10 },
111 { "MECHANICAL11", ALTIUM_LAYER::MECHANICAL_11 },
112 { "MECHANICAL12", ALTIUM_LAYER::MECHANICAL_12 },
113 { "MECHANICAL13", ALTIUM_LAYER::MECHANICAL_13 },
114 { "MECHANICAL14", ALTIUM_LAYER::MECHANICAL_14 },
115 { "MECHANICAL15", ALTIUM_LAYER::MECHANICAL_15 },
116 { "MECHANICAL16", ALTIUM_LAYER::MECHANICAL_16 },
117
118 { "DRILLDRAWING", ALTIUM_LAYER::DRILL_DRAWING },
119 { "MULTILAYER", ALTIUM_LAYER::MULTI_LAYER },
120
121 // FIXME: the following mapping is just a guess
122 { "CONNECTIONS", ALTIUM_LAYER::CONNECTIONS },
123 { "BACKGROUND", ALTIUM_LAYER::BACKGROUND },
124 { "DRCERRORMARKERS", ALTIUM_LAYER::DRC_ERROR_MARKERS },
125 { "SELECTIONS", ALTIUM_LAYER::SELECTIONS },
126 { "VISIBLEGRID1", ALTIUM_LAYER::VISIBLE_GRID_1 },
127 { "VISIBLEGRID2", ALTIUM_LAYER::VISIBLE_GRID_2 },
128 { "PADHOLES", ALTIUM_LAYER::PAD_HOLES },
129 { "VIAHOLES", ALTIUM_LAYER::VIA_HOLES },
130 };
131
132 auto it = hash_map.find( std::string( aName.c_str() ) );
133
134 if( it == hash_map.end() )
135 {
136 wxLogError( _( "Unknown mapping of the Altium layer '%s'." ), aName );
138 }
139 else
140 {
141 return it->second;
142 }
143}
144
145void altium_parse_polygons( std::map<wxString, wxString>& aProps,
146 std::vector<ALTIUM_VERTICE>& aVertices )
147{
148 for( size_t i = 0; i < std::numeric_limits<size_t>::max(); i++ )
149 {
150 const wxString si = std::to_string( i );
151
152 const wxString vxi = wxT( "VX" ) + si;
153 const wxString vyi = wxT( "VY" ) + si;
154
155 if( aProps.find( vxi ) == aProps.end() || aProps.find( vyi ) == aProps.end() )
156 break; // it doesn't seem like we know beforehand how many vertices are inside a polygon
157
158 const bool isRound = ALTIUM_PROPS_UTILS::ReadInt( aProps, wxT( "KIND" ) + si, 0 ) != 0;
159 const int32_t radius = ALTIUM_PROPS_UTILS::ReadKicadUnit( aProps, wxT( "R" ) + si, wxT( "0mil" ) );
160 const double sa = ALTIUM_PROPS_UTILS::ReadDouble( aProps, wxT( "SA" ) + si, 0. );
161 const double ea = ALTIUM_PROPS_UTILS::ReadDouble( aProps, wxT( "EA" ) + si, 0. );
162 const VECTOR2I vp = VECTOR2I( ALTIUM_PROPS_UTILS::ReadKicadUnit( aProps, vxi, wxT( "0mil" ) ),
163 -ALTIUM_PROPS_UTILS::ReadKicadUnit( aProps, vyi, wxT( "0mil" ) ) );
164 const VECTOR2I cp = VECTOR2I( ALTIUM_PROPS_UTILS::ReadKicadUnit( aProps, wxT( "CX" ) + si, wxT( "0mil" ) ),
165 -ALTIUM_PROPS_UTILS::ReadKicadUnit( aProps, wxT( "CY" ) + si, wxT( "0mil" ) ) );
166
167 aVertices.emplace_back( isRound, radius, sa, ea, vp, cp );
168 }
169}
170
171
172static ALTIUM_MODE ReadAltiumModeFromProperties( const std::map<wxString, wxString>& aProps,
173 wxString aKey )
174{
175 wxString mode = ALTIUM_PROPS_UTILS::ReadString( aProps, aKey, wxT( "" ) );
176
177 if( mode == wxT( "None" ) )
178 return ALTIUM_MODE::NONE;
179 else if( mode == wxT( "Rule" ) )
180 return ALTIUM_MODE::RULE;
181 else if( mode == wxT( "Manual" ) )
182 return ALTIUM_MODE::MANUAL;
183
184 wxLogError( _( "Unknown Mode string: '%s'." ), mode );
186}
187
188
189static ALTIUM_RECORD ReadAltiumRecordFromProperties( const std::map<wxString, wxString>& aProps,
190 wxString aKey )
191{
192 wxString record = ALTIUM_PROPS_UTILS::ReadString( aProps, aKey, wxT( "" ) );
193
194 if( record == wxT( "Arc" ) )
195 return ALTIUM_RECORD::ARC;
196 else if( record == wxT( "Pad" ) )
197 return ALTIUM_RECORD::PAD;
198 else if( record == wxT( "Via" ) )
199 return ALTIUM_RECORD::VIA;
200 else if( record == wxT( "Track" ) )
202 else if( record == wxT( "Text" ) )
203 return ALTIUM_RECORD::TEXT;
204 else if( record == wxT( "Fill" ) )
205 return ALTIUM_RECORD::FILL;
206 else if( record == wxT( "Region" ) ) // correct?
208 else if( record == wxT( "Model" ) )
210
211 wxLogError( _( "Unknown Record name string: '%s'." ), record );
213}
214
215
218 const std::map<wxString, wxString>& aProps, wxString aKey )
219{
220 wxString parsedType = ALTIUM_PROPS_UTILS::ReadString( aProps, aKey, wxT( "" ) );
221
222 if( parsedType == wxT( "Mask" ) )
224
225 wxLogError( _( "Unknown Extended Primitive Information type: '%s'." ), parsedType );
227}
228
229
238static void ExpectSubrecordLengthAtLeast( const std::string& aStreamType,
239 const std::string& aSubrecordName, size_t aExpectedLength,
240 size_t aActualLength )
241{
242 if( aActualLength < aExpectedLength )
243 {
244 THROW_IO_ERROR( wxString::Format( "%s stream %s has length %d, "
245 "which is unexpected (expected at least %d)",
246 aStreamType, aSubrecordName, aActualLength,
247 aExpectedLength ) );
248 }
249}
250
251
253{
254 const std::map<wxString, wxString> props = aReader.ReadProperties();
255
256 if( props.empty() )
257 THROW_IO_ERROR( wxT( "ExtendedPrimitiveInformation stream has no properties!" ) );
258
259 primitiveIndex = ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "PRIMITIVEINDEX" ), -1 );
260 primitiveObjectId = ReadAltiumRecordFromProperties( props, wxT( "PRIMITIVEOBJECTID" ) );
262
263 pastemaskexpansionmode = ReadAltiumModeFromProperties( props, wxT( "PASTEMASKEXPANSIONMODE" ) );
265 props, wxT( "PASTEMASKEXPANSION_MANUAL" ), wxT( "0mil" ) );
267 ReadAltiumModeFromProperties( props, wxT( "SOLDERMASKEXPANSIONMODE" ) );
269 props, wxT( "SOLDERMASKEXPANSION_MANUAL" ), wxT( "0mil" ) );
270}
271
272
274{
275 std::map<wxString, wxString> props = aReader.ReadProperties();
276
277 if( props.empty() )
278 THROW_IO_ERROR( wxT( "Board6 stream has no properties!" ) );
279
280 sheetpos = VECTOR2I( ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "SHEETX" ), wxT( "0mil" ) ),
281 -ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "SHEETY" ), wxT( "0mil" ) ) );
282 sheetsize = wxSize( ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "SHEETWIDTH" ), wxT( "0mil" ) ),
283 ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "SHEETHEIGHT" ), wxT( "0mil" ) ) );
284
285 layercount = ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "LAYERSETSCOUNT" ), 1 ) + 1;
286
287 for( size_t i = 1; i < std::numeric_limits<size_t>::max(); i++ )
288 {
289 const wxString layeri = wxT( "LAYER" ) + wxString( std::to_string( i ) );
290 const wxString layername = layeri + wxT( "NAME" );
291
292 auto layernameit = props.find( layername );
293
294 if( layernameit == props.end() )
295 break; // it doesn't seem like we know beforehand how many vertices are inside a polygon
296
298
299 l.name = ALTIUM_PROPS_UTILS::ReadString( props, layername, wxT( "" ) );
300 wxString originalName = l.name;
301 int ii = 2;
302
303 // Ensure that layer names are unique in KiCad
304 while( !layerNames.insert( l.name ).second )
305 l.name = wxString::Format( wxT( "%s %d" ), originalName, ii++ );
306
307 l.nextId = ALTIUM_PROPS_UTILS::ReadInt( props, layeri + wxT( "NEXT" ), 0 );
308 l.prevId = ALTIUM_PROPS_UTILS::ReadInt( props, layeri + wxT( "PREV" ), 0 );
309 l.copperthick = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, layeri + wxT( "COPTHICK" ), wxT( "1.4mil" ) );
310
311 l.dielectricconst = ALTIUM_PROPS_UTILS::ReadDouble( props, layeri + wxT( "DIELCONST" ), 0. );
312 l.dielectricthick = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, layeri + wxT( "DIELHEIGHT" ), wxT( "60mil" ) );
313 l.dielectricmaterial = ALTIUM_PROPS_UTILS::ReadString( props, layeri + wxT( "DIELMATERIAL" ), wxT( "FR-4" ) );
314
315 stackup.push_back( l );
316 }
317
319
320 if( aReader.HasParsingError() )
321 THROW_IO_ERROR( wxT( "Board6 stream was not parsed correctly!" ) );
322}
323
325{
326 std::map<wxString, wxString> properties = aReader.ReadProperties();
327
328 if( properties.empty() )
329 THROW_IO_ERROR( wxT( "Classes6 stream has no properties!" ) );
330
331 name = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "NAME" ), wxT( "" ) );
332 uniqueid = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "UNIQUEID" ), wxT( "" ) );
333 kind = static_cast<ALTIUM_CLASS_KIND>( ALTIUM_PROPS_UTILS::ReadInt( properties, wxT( "KIND" ), -1 ) );
334
335 for( size_t i = 0; i < std::numeric_limits<size_t>::max(); i++ )
336 {
337 auto mit = properties.find( wxT( "M" ) + wxString( std::to_string( i ) ) );
338
339 if( mit == properties.end() )
340 break; // it doesn't seem like we know beforehand how many components are in the netclass
341
342 names.push_back( mit->second );
343 }
344
345 if( aReader.HasParsingError() )
346 THROW_IO_ERROR( wxT( "Classes6 stream was not parsed correctly" ) );
347}
348
350{
351 std::map<wxString, wxString> props = aReader.ReadProperties();
352
353 if( props.empty() )
354 THROW_IO_ERROR( wxT( "Components6 stream has no props" ) );
355
356 layer = altium_layer_from_name( ALTIUM_PROPS_UTILS::ReadString( props, wxT( "LAYER" ), wxT( "" ) ) );
357 position = VECTOR2I( ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "X" ), wxT( "0mil" ) ),
358 -ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "Y" ), wxT( "0mil" ) ) );
359 rotation = ALTIUM_PROPS_UTILS::ReadDouble( props, wxT( "ROTATION" ), 0. );
360 locked = ALTIUM_PROPS_UTILS::ReadBool( props, wxT( "LOCKED" ), false );
361 nameon = ALTIUM_PROPS_UTILS::ReadBool( props, wxT( "NAMEON" ), true );
362 commenton = ALTIUM_PROPS_UTILS::ReadBool( props, wxT( "COMMENTON" ), false );
363 sourcedesignator = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "SOURCEDESIGNATOR" ), wxT( "" ) );
364
366 ALTIUM_PROPS_UTILS::ReadUnicodeString( props, wxT( "SOURCEFOOTPRINTLIBRARY" ), wxT( "" ) );
367 pattern = ALTIUM_PROPS_UTILS::ReadUnicodeString( props, wxT( "PATTERN" ), wxT( "" ) );
368
369 sourcecomponentlibrary = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "SOURCECOMPONENTLIBRARY" ), wxT( "" ) );
370 sourcelibreference = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "SOURCELIBREFERENCE" ), wxT( "" ) );
371
373 ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "NAMEAUTOPOSITION" ), 0 ) );
375 ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "COMMENTAUTOPOSITION" ), 0 ) );
376
377 if( aReader.HasParsingError() )
378 THROW_IO_ERROR( wxT( "Components6 stream was not parsed correctly" ) );
379}
380
382{
383 aReader.Skip( 2 );
384
385 std::map<wxString, wxString> props = aReader.ReadProperties();
386
387 if( props.empty() )
388 THROW_IO_ERROR( wxT( "Dimensions6 stream has no props" ) );
389
390 layer = altium_layer_from_name( ALTIUM_PROPS_UTILS::ReadString( props, wxT( "LAYER" ), wxT( "" ) ) );
391 kind = static_cast<ALTIUM_DIMENSION_KIND>( ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "DIMENSIONKIND" ), 0 ) );
392
393 textformat = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "TEXTFORMAT" ), wxT( "" ) );
394 textprefix = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "TEXTPREFIX" ), wxT( "" ) );
395 textsuffix = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "TEXTSUFFIX" ), wxT( "" ) );
396
397 height = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "HEIGHT" ), wxT( "0mil" ) );
398 angle = ALTIUM_PROPS_UTILS::ReadDouble( props, wxT( "ANGLE" ), 0. );
399
400 linewidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "LINEWIDTH" ), wxT( "10mil" ) );
401 textheight = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "TEXTHEIGHT" ), wxT( "10mil" ) );
402 textlinewidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "TEXTLINEWIDTH" ), wxT( "6mil" ) );
403 textprecision = ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "TEXTPRECISION" ), 2 );
404 textbold = ALTIUM_PROPS_UTILS::ReadBool( props, wxT( "TEXTLINEWIDTH" ), false );
405 textitalic = ALTIUM_PROPS_UTILS::ReadBool( props, wxT( "ITALIC" ), false );
406 textgap = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "TEXTGAP" ), wxT( "10mil" ) );
407
408 arrowsize = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "ARROWSIZE" ), wxT( "60mil" ) );
409
410 wxString text_position_raw = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "TEXTPOSITION" ), wxT( "" ) );
411
412 xy1 = VECTOR2I( ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "X1" ), wxT( "0mil" ) ),
413 -ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "Y1" ), wxT( "0mil" ) ) );
414
415 int refcount = ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "REFERENCES_COUNT" ), 0 );
416
417 for( int i = 0; i < refcount; i++ )
418 {
419 const std::string refi = "REFERENCE" + std::to_string( i ) + "POINT";
420 const wxString ref( refi );
421 referencePoint.emplace_back( ALTIUM_PROPS_UTILS::ReadKicadUnit( props, ref + wxT( "X" ), wxT( "0mil" ) ),
422 -ALTIUM_PROPS_UTILS::ReadKicadUnit( props, ref + wxT( "Y" ), wxT( "0mil" ) ) );
423 }
424
425 for( size_t i = 1; i < std::numeric_limits<size_t>::max(); i++ )
426 {
427 const std::string texti = "TEXT" + std::to_string( i );
428 const std::string textix = texti + "X";
429 const std::string textiy = texti + "Y";
430
431 if( props.find( textix ) == props.end() || props.find( textiy ) == props.end() )
432 break; // it doesn't seem like we know beforehand how many vertices are inside a polygon
433
434 textPoint.emplace_back( ALTIUM_PROPS_UTILS::ReadKicadUnit( props, textix, wxT( "0mil" ) ),
435 -ALTIUM_PROPS_UTILS::ReadKicadUnit( props, textiy, wxT( "0mil" ) ) );
436 }
437
438 wxString dimensionunit = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "TEXTDIMENSIONUNIT" ), wxT( "Millimeters" ) );
439
440 if( dimensionunit == wxT( "Inches" ) ) textunit = ALTIUM_UNIT::INCHES;
441 else if( dimensionunit == wxT( "Mils" ) ) textunit = ALTIUM_UNIT::MILS;
442 else if( dimensionunit == wxT( "Millimeters" ) ) textunit = ALTIUM_UNIT::MILLIMETERS;
443 else if( dimensionunit == wxT( "Centimeters" ) ) textunit = ALTIUM_UNIT::CENTIMETER;
444 else textunit = ALTIUM_UNIT::UNKNOWN;
445
446 if( aReader.HasParsingError() )
447 THROW_IO_ERROR( wxT( "Dimensions6 stream was not parsed correctly" ) );
448}
449
451{
452 std::map<wxString, wxString> properties = aReader.ReadProperties();
453
454 if( properties.empty() )
455 THROW_IO_ERROR( wxT( "Model stream has no properties!" ) );
456
457 name = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "NAME" ), wxT( "" ) );
458 id = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "ID" ), wxT( "" ) );
459 isEmbedded = ALTIUM_PROPS_UTILS::ReadBool( properties, wxT( "EMBED" ), false );
460
461 rotation.x = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "ROTX" ), 0. );
462 rotation.y = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "ROTY" ), 0. );
463 rotation.z = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "ROTZ" ), 0. );
464
465 if( aReader.HasParsingError() )
466 THROW_IO_ERROR( wxT( "Model stream was not parsed correctly" ) );
467}
468
470{
471 std::map<wxString, wxString> properties = aReader.ReadProperties();
472
473 if( properties.empty() )
474 THROW_IO_ERROR( wxT( "Nets6 stream has no properties" ) );
475
476 name = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "NAME" ), wxT( "" ) );
477
478 if( aReader.HasParsingError() )
479 THROW_IO_ERROR( wxT( "Nets6 stream was not parsed correctly" ) );
480}
481
483{
484 std::map<wxString, wxString> properties = aReader.ReadProperties();
485
486 if( properties.empty() )
487 THROW_IO_ERROR( wxT( "Polygons6 stream has no properties" ) );
488
489 layer = altium_layer_from_name( ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "LAYER" ), wxT( "" ) ) );
490 net = ALTIUM_PROPS_UTILS::ReadInt( properties, wxT( "NET" ), ALTIUM_NET_UNCONNECTED );
491 locked = ALTIUM_PROPS_UTILS::ReadBool( properties, wxT( "LOCKED" ), false );
492
493 // TODO: kind
494
495 gridsize = ALTIUM_PROPS_UTILS::ReadKicadUnit( properties, wxT( "GRIDSIZE" ), wxT( "0mil" ) );
496 trackwidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( properties, wxT( "TRACKWIDTH" ), wxT( "0mil" ) );
497 minprimlength = ALTIUM_PROPS_UTILS::ReadKicadUnit( properties, wxT( "MINPRIMLENGTH" ), wxT( "0mil" ) );
498 useoctagons = ALTIUM_PROPS_UTILS::ReadBool( properties, wxT( "USEOCTAGONS" ), false );
499
500 pourindex = ALTIUM_PROPS_UTILS::ReadInt( properties, wxT( "POURINDEX" ), 0 );
501
502 wxString hatchstyleraw = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "HATCHSTYLE" ), wxT( "" ) );
503
504 if( hatchstyleraw == wxT( "Solid" ) ) hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::SOLID;
505 else if( hatchstyleraw == wxT( "45Degree" ) ) hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::DEGREE_45;
506 else if( hatchstyleraw == wxT( "90Degree" ) ) hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::DEGREE_90;
507 else if( hatchstyleraw == wxT( "Horizontal" ) ) hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::HORIZONTAL;
508 else if( hatchstyleraw == wxT( "Vertical" ) ) hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::VERTICAL;
509 else if( hatchstyleraw == wxT( "None" ) ) hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::NONE;
510 else hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::UNKNOWN;
511
512 altium_parse_polygons( properties, vertices );
513
514 if( aReader.HasParsingError() )
515 THROW_IO_ERROR( wxT( "Polygons6 stream was not parsed correctly" ) );
516}
517
519{
520 // Initialize all variables and make Coverity happy
521 minLimit = 0;
522 maxLimit = 0;
523 preferredWidth = 0;
526 clearanceGap = 0;
531 polygonconnectStyle = ALTIUM_CONNECT_STYLE::UNKNOWN;
532
533 aReader.Skip( 2 );
534
535 std::map<wxString, wxString> props = aReader.ReadProperties();
536
537 if( props.empty() )
538 THROW_IO_ERROR( wxT( "Rules6 stream has no props" ) );
539
540 name = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "NAME" ), wxT( "" ) );
541 priority = ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "PRIORITY" ), 1 );
542
543 scope1expr = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "SCOPE1EXPRESSION" ), wxT( "" ) );
544 scope2expr = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "SCOPE2EXPRESSION" ), wxT( "" ) );
545
546 wxString rulekind = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "RULEKIND" ), wxT( "" ) );
547 if( rulekind == wxT( "Clearance" ) )
548 {
549 kind = ALTIUM_RULE_KIND::CLEARANCE;
550 clearanceGap = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "GAP" ), wxT( "10mil" ) );
551 }
552 else if( rulekind == wxT( "DiffPairsRouting" ) )
553 {
554 kind = ALTIUM_RULE_KIND::DIFF_PAIR_ROUTINGS;
555 }
556 else if( rulekind == wxT( "Height" ) )
557 {
558 kind = ALTIUM_RULE_KIND::HEIGHT;
559 }
560 else if( rulekind == wxT( "HoleSize" ) )
561 {
562 kind = ALTIUM_RULE_KIND::HOLE_SIZE;
563 minLimit = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MINLIMIT" ), wxT( "1mil" ) );
564 maxLimit = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MAXLIMIT" ), wxT( "150mil" ) );
565 }
566 else if( rulekind == wxT( "HoleToHoleClearance" ) )
567 {
568 kind = ALTIUM_RULE_KIND::HOLE_TO_HOLE_CLEARANCE;
569 clearanceGap = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "GAP" ), wxT( "10mil" ) );
570 }
571 else if( rulekind == wxT( "RoutingVias" ) )
572 {
573 kind = ALTIUM_RULE_KIND::ROUTING_VIAS;
574 width = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "WIDTH" ), wxT( "20mil" ) );
575 minWidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MINWIDTH" ), wxT( "20mil" ) );
576 maxWidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MAXWIDTH" ), wxT( "50mil" ) );
577 holeWidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "HOLEWIDTH" ), wxT( "10mil" ) );
578 minHoleWidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MINHOLEWIDTH" ), wxT( "10mil" ) );
579 maxHoleWidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MAXHOLEWIDTH" ), wxT( "28mil" ) );
580 }
581 else if( rulekind == wxT( "Width" ) )
582 {
583 kind = ALTIUM_RULE_KIND::WIDTH;
584 minLimit = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MINLIMIT" ), wxT( "6mil" ) );
585 maxLimit = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MAXLIMIT" ), wxT( "40mil" ) );
586 preferredWidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "PREFERREDWIDTH" ), wxT( "6mil" ) );
587}
588 else if( rulekind == wxT( "PasteMaskExpansion" ) )
589 {
590 kind = ALTIUM_RULE_KIND::PASTE_MASK_EXPANSION;
591 pastemaskExpansion = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "EXPANSION" ), wxT( "0" ) );
592 }
593 else if( rulekind == wxT( "SolderMaskExpansion" ) )
594 {
595 kind = ALTIUM_RULE_KIND::SOLDER_MASK_EXPANSION;
596 soldermaskExpansion = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "EXPANSION" ), wxT( "4mil" ) );
597 }
598 else if( rulekind == wxT( "PlaneClearance" ) )
599 {
600 kind = ALTIUM_RULE_KIND::PLANE_CLEARANCE;
601 planeclearanceClearance = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "CLEARANCE" ), wxT( "10mil" ) );
602 }
603 else if( rulekind == wxT( "PolygonConnect" ) )
604 {
605 kind = ALTIUM_RULE_KIND::POLYGON_CONNECT;
606 polygonconnectAirgapwidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "AIRGAPWIDTH" ), wxT( "10mil" ) );
607 polygonconnectReliefconductorwidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "RELIEFCONDUCTORWIDTH" ), wxT( "10mil" ) );
608 polygonconnectReliefentries = ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "RELIEFENTRIES" ), 4 );
609
610 wxString style = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "CONNECTSTYLE" ), wxT( "" ) );
611
612 if( style == wxT( "Direct" ) ) polygonconnectStyle = ALTIUM_CONNECT_STYLE::DIRECT;
613 else if( style == wxT( "Relief" ) ) polygonconnectStyle = ALTIUM_CONNECT_STYLE::RELIEF;
614 else if( style == wxT( "NoConnect" ) ) polygonconnectStyle = ALTIUM_CONNECT_STYLE::NONE;
615 else polygonconnectStyle = ALTIUM_CONNECT_STYLE::UNKNOWN;
616 }
617 else
618 {
619 kind = ALTIUM_RULE_KIND::UNKNOWN;
620 }
621
622 if( aReader.HasParsingError() )
623 THROW_IO_ERROR( wxT( "Rules6 stream was not parsed correctly" ) );
624}
625
627{
628 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
629 if( recordtype != ALTIUM_RECORD::ARC )
630 {
631 THROW_IO_ERROR( wxT( "Arcs6 stream has invalid recordtype" ) );
632 }
633
634 // Subrecord 1
636
637 layer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
638
639 uint8_t flags1 = aReader.Read<uint8_t>();
640 is_locked = ( flags1 & 0x04 ) == 0;
641 is_polygonoutline = ( flags1 & 0x02 ) != 0;
642
643 uint8_t flags2 = aReader.Read<uint8_t>();
644 is_keepout = flags2 == 2;
645
646 net = aReader.Read<uint16_t>();
647 polygon = aReader.Read<uint16_t>();
648 component = aReader.Read<uint16_t>();
649 aReader.Skip( 4 );
650 center = aReader.ReadVector2IPos();
651 radius = aReader.ReadKicadUnit();
652 startangle = aReader.Read<double>();
653 endangle = aReader.Read<double>();
654 width = aReader.ReadKicadUnit();
655 subpolyindex = aReader.Read<uint16_t>();
656
657 if( aReader.GetRemainingSubrecordBytes() >= 10 )
658 {
659 aReader.Skip( 9 );
660 keepoutrestrictions = aReader.Read<uint8_t>();
661 }
662 else
663 {
664 keepoutrestrictions = is_keepout ? 0x1F : 0;
665 }
666
667 aReader.SkipSubrecord();
668
669 if( aReader.HasParsingError() )
670 {
671 THROW_IO_ERROR( wxT( "Arcs6 stream was not parsed correctly" ) );
672 }
673}
674
676{
677 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
678
679 if( recordtype != ALTIUM_RECORD::MODEL )
680 THROW_IO_ERROR( wxT( "ComponentsBodies6 stream has invalid recordtype" ) );
681
683
684 aReader.Skip( 7 );
685 component = aReader.Read<uint16_t>();
686 aReader.Skip( 9 );
687
688 std::map<wxString, wxString> properties = aReader.ReadProperties();
689
690 if( properties.empty() )
691 THROW_IO_ERROR( wxT( "ComponentsBodies6 stream has no properties" ) );
692
693 modelName = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "MODEL.NAME" ), wxT( "" ) );
694 modelId = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "MODELID" ), wxT( "" ) );
695 modelIsEmbedded = ALTIUM_PROPS_UTILS::ReadBool( properties, wxT( "MODEL.EMBED" ), false );
696
697 modelPosition.x = ALTIUM_PROPS_UTILS::ReadKicadUnit( properties, wxT( "MODEL.2D.X" ), wxT( "0mil" ) );
698 modelPosition.y = -ALTIUM_PROPS_UTILS::ReadKicadUnit( properties, wxT( "MODEL.2D.Y" ), wxT( "0mil" ) );
699 modelPosition.z = ALTIUM_PROPS_UTILS::ReadKicadUnit( properties, wxT( "MODEL.3D.DZ" ), wxT( "0mil" ) );
700
701 modelRotation.x = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "MODEL.3D.ROTX" ), 0. );
702 modelRotation.y = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "MODEL.3D.ROTY" ), 0. );
703 modelRotation.z = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "MODEL.3D.ROTZ" ), 0. );
704
705 rotation = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "MODEL.2D.ROTATION" ), 0. );
706
707 bodyOpacity = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "BODYOPACITY3D" ), 1. );
708
709 aReader.SkipSubrecord();
710
711 if( aReader.HasParsingError() )
712 THROW_IO_ERROR( wxT( "Components6 stream was not parsed correctly" ) );
713}
714
716{
717 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
718
719 if( recordtype != ALTIUM_RECORD::PAD )
720 THROW_IO_ERROR( wxT( "Pads6 stream has invalid recordtype" ) );
721
722 // Subrecord 1
723 size_t subrecord1 = aReader.ReadAndSetSubrecordLength();
724
725 if( subrecord1 == 0 )
726 THROW_IO_ERROR( wxT( "Pads6 stream has no subrecord1 data" ) );
727
728 name = aReader.ReadWxString();
729
730 if( aReader.GetRemainingSubrecordBytes() != 0 )
731 THROW_IO_ERROR( wxT( "Pads6 stream has invalid subrecord1 length" ) );
732
733 aReader.SkipSubrecord();
734
735 // Subrecord 2
737 aReader.SkipSubrecord();
738
739 // Subrecord 3
741 aReader.SkipSubrecord();
742
743 // Subrecord 4
745 aReader.SkipSubrecord();
746
747 // Subrecord 5
748 size_t subrecord5 = aReader.ReadAndSetSubrecordLength();
749
750 ExpectSubrecordLengthAtLeast( "Pads6", "subrecord5", 110, subrecord5 );
751
752 layer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
753 tolayer = ALTIUM_LAYER::UNKNOWN;
754 fromlayer = ALTIUM_LAYER::UNKNOWN;
755
756 uint8_t flags1 = aReader.Read<uint8_t>();
757 is_test_fab_top = ( flags1 & 0x80 ) != 0;
758 is_tent_bottom = ( flags1 & 0x40 ) != 0;
759 is_tent_top = ( flags1 & 0x20 ) != 0;
760 is_locked = ( flags1 & 0x04 ) == 0;
761
762 uint8_t flags2 = aReader.Read<uint8_t>();
763 is_test_fab_bottom = ( flags2 & 0x01 ) != 0;
764
765 net = aReader.Read<uint16_t>();
766 aReader.Skip( 2 );
767 component = aReader.Read<uint16_t>();
768 aReader.Skip( 4 ); // to 13
769
770 position = aReader.ReadVector2IPos();
771 topsize = aReader.ReadVector2ISize();
772 midsize = aReader.ReadVector2ISize();
773 botsize = aReader.ReadVector2ISize();
774 holesize = aReader.ReadKicadUnit(); // to 49
775
776 topshape = static_cast<ALTIUM_PAD_SHAPE>( aReader.Read<uint8_t>() );
777 midshape = static_cast<ALTIUM_PAD_SHAPE>( aReader.Read<uint8_t>() );
778 botshape = static_cast<ALTIUM_PAD_SHAPE>( aReader.Read<uint8_t>() );
779
780 direction = aReader.Read<double>();
781 plated = aReader.Read<uint8_t>() != 0;
782 aReader.Skip( 1 );
783 padmode = static_cast<ALTIUM_PAD_MODE>( aReader.Read<uint8_t>() );
784 aReader.Skip( 23 );
787 aReader.Skip( 7 );
788 pastemaskexpansionmode = static_cast<ALTIUM_MODE>( aReader.Read<uint8_t>() );
789 soldermaskexpansionmode = static_cast<ALTIUM_MODE>( aReader.Read<uint8_t>() );
790 aReader.Skip( 3 ); // to 106
791
792 if( subrecord5 == 110 )
793 {
794 // Don't know exactly what this is, but it's always been 0 in the files with
795 // 110-byte subrecord5.
796 // e.g. https://gitlab.com/kicad/code/kicad/-/issues/16514
797 const uint32_t unknown = aReader.ReadKicadUnit(); // to 110
798
799 if( unknown != 0 )
800 {
801 THROW_IO_ERROR( wxString::Format( "Pads6 stream subrecord5 + 106 has value %d, "
802 "which is unexpected",
803 unknown ) );
804 }
805 holerotation = 0;
806 }
807 else
808 {
809 // More than 110, need at least 114
810 ExpectSubrecordLengthAtLeast( "Pads6", "subrecord5", 114, subrecord5 );
811 holerotation = aReader.Read<double>(); // to 114
812 }
813
814 if( subrecord5 >= 120 )
815 {
816 tolayer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
817 aReader.Skip( 2 );
818 fromlayer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
819 //aReader.skip( 2 );
820 }
821 else if( subrecord5 == 171 )
822 {
823 }
824
825 aReader.SkipSubrecord();
826
827 // Subrecord 6
828 size_t subrecord6 = aReader.ReadAndSetSubrecordLength();
829 // Known lengths: 596, 628, 651
830 // 596 is the number of bytes read in this code-block
831 if( subrecord6 >= 596 )
832 { // TODO: detect type from something else than the size?
833 sizeAndShape = std::make_unique<APAD6_SIZE_AND_SHAPE>();
834
835 for( wxSize& size : sizeAndShape->inner_size )
836 size.x = aReader.ReadKicadUnitX();
837
838 for( wxSize& size : sizeAndShape->inner_size )
839 size.y = aReader.ReadKicadUnitY();
840
841 for( ALTIUM_PAD_SHAPE& shape : sizeAndShape->inner_shape )
842 shape = static_cast<ALTIUM_PAD_SHAPE>( aReader.Read<uint8_t>() );
843
844 aReader.Skip( 1 );
845
846 sizeAndShape->holeshape = static_cast<ALTIUM_PAD_HOLE_SHAPE>( aReader.Read<uint8_t>() );
847 sizeAndShape->slotsize = aReader.ReadKicadUnit();
848 sizeAndShape->slotrotation = aReader.Read<double>();
849
850 for( VECTOR2I& pt : sizeAndShape->holeoffset )
851 pt.x = aReader.ReadKicadUnitX();
852
853 for( VECTOR2I& pt : sizeAndShape->holeoffset )
854 pt.y = aReader.ReadKicadUnitY();
855
856 aReader.Skip( 1 );
857
858 for( ALTIUM_PAD_SHAPE_ALT& shape : sizeAndShape->alt_shape )
859 shape = static_cast<ALTIUM_PAD_SHAPE_ALT>( aReader.Read<uint8_t>() );
860
861 for( uint8_t& radius : sizeAndShape->cornerradius )
862 radius = aReader.Read<uint8_t>();
863 }
864 else if( subrecord6 != 0 )
865 {
866 wxLogError( _( "Pads6 stream has unexpected length for subrecord 6: %d." ), subrecord6 );
867 }
868
869 aReader.SkipSubrecord();
870
871 if( aReader.HasParsingError() )
872 THROW_IO_ERROR( wxT( "Pads6 stream was not parsed correctly" ) );
873}
874
876{
877 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
878
879 if( recordtype != ALTIUM_RECORD::VIA )
880 THROW_IO_ERROR( wxT( "Vias6 stream has invalid recordtype" ) );
881
882 // Subrecord 1
883 size_t subrecord1 = aReader.ReadAndSetSubrecordLength();
884
885 aReader.Skip( 1 );
886
887 uint8_t flags1 = aReader.Read<uint8_t>();
888 is_test_fab_top = ( flags1 & 0x80 ) != 0;
889 is_tent_bottom = ( flags1 & 0x40 ) != 0;
890 is_tent_top = ( flags1 & 0x20 ) != 0;
891 is_locked = ( flags1 & 0x04 ) == 0;
892
893 uint8_t flags2 = aReader.Read<uint8_t>();
894 is_test_fab_bottom = ( flags2 & 0x01 ) != 0;
895
896 net = aReader.Read<uint16_t>();
897 aReader.Skip( 8 );
898 position = aReader.ReadVector2IPos();
899 diameter = aReader.ReadKicadUnit();
900 holesize = aReader.ReadKicadUnit();
901
902 layer_start = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
903 layer_end = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
904
905 if( subrecord1 <= 74 )
906 {
907 viamode = ALTIUM_PAD_MODE::SIMPLE;
908 }
909 else
910 {
911 aReader.Skip( 43 );
912 viamode = static_cast<ALTIUM_PAD_MODE>( aReader.Read<uint8_t>() );
913 }
914
915 aReader.SkipSubrecord();
916
917 if( aReader.HasParsingError() )
918 THROW_IO_ERROR( wxT( "Vias6 stream was not parsed correctly" ) );
919}
920
922{
923 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
924
925 if( recordtype != ALTIUM_RECORD::TRACK )
926 THROW_IO_ERROR( wxT( "Tracks6 stream has invalid recordtype" ) );
927
928 // Subrecord 1
930
931 layer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
932
933 uint8_t flags1 = aReader.Read<uint8_t>();
934 is_locked = ( flags1 & 0x04 ) == 0;
935 is_polygonoutline = ( flags1 & 0x02 ) != 0;
936
937 uint8_t flags2 = aReader.Read<uint8_t>();
938 is_keepout = flags2 == 2;
939
940 net = aReader.Read<uint16_t>();
941 polygon = aReader.Read<uint16_t>();
942 component = aReader.Read<uint16_t>();
943 aReader.Skip( 4 );
944 start = aReader.ReadVector2IPos();
945 end = aReader.ReadVector2IPos();
946 width = aReader.ReadKicadUnit();
947 subpolyindex = aReader.Read<uint16_t>();
948
949 if( aReader.GetRemainingSubrecordBytes() >= 11 )
950 {
951 aReader.Skip( 10 );
952 keepoutrestrictions = aReader.Read<uint8_t>();
953 }
954 else
955 {
956 keepoutrestrictions = is_keepout ? 0x1F : 0;
957 }
958
959 aReader.SkipSubrecord();
960
961 if( aReader.HasParsingError() )
962 THROW_IO_ERROR( wxT( "Tracks6 stream was not parsed correctly" ) );
963}
964
965ATEXT6::ATEXT6( ALTIUM_BINARY_PARSER& aReader, std::map<uint32_t, wxString>& aStringTable )
966{
967 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
968
969 if( recordtype != ALTIUM_RECORD::TEXT )
970 THROW_IO_ERROR( wxT( "Texts6 stream has invalid recordtype" ) );
971
972 // Subrecord 1 - Properties
973 size_t subrecord1 = aReader.ReadAndSetSubrecordLength();
974
975 layer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
976 aReader.Skip( 6 );
977 component = aReader.Read<uint16_t>();
978 aReader.Skip( 4 );
979 position = aReader.ReadVector2IPos();
980 height = aReader.ReadKicadUnit();
981 aReader.Skip( 2 );
982 rotation = aReader.Read<double>();
983 isMirrored = aReader.Read<uint8_t>() != 0;
984 strokewidth = aReader.ReadKicadUnit();
985 isComment = aReader.Read<uint8_t>() != 0;
986 isDesignator = aReader.Read<uint8_t>() != 0;
987 aReader.Skip( 2 );
988 isBold = aReader.Read<uint8_t>() != 0;
989 isItalic = aReader.Read<uint8_t>() != 0;
990
991 char fontData[64] = { 0 };
992 aReader.ReadBytes( fontData, sizeof( fontData ) );
993 fontname = wxString( fontData, wxMBConvUTF16LE(), sizeof( fontData ) ).BeforeFirst( '\0' );
994
995 isInverted = aReader.Read<uint8_t>() != 0;
996 aReader.Skip( 4 );
997 uint32_t stringIndex = aReader.Read<uint32_t>();
998 aReader.Skip( 13 );
999 textposition = static_cast<ALTIUM_TEXT_POSITION>( aReader.Read<uint8_t>() );
1004 if( subrecord1 <= 230 )
1005 textposition = ALTIUM_TEXT_POSITION::LEFT_BOTTOM;
1006
1007 aReader.Skip( 27 );
1008 fonttype = static_cast<ALTIUM_TEXT_TYPE>( aReader.Read<uint8_t>() );
1009
1010 aReader.SkipSubrecord();
1011
1012 // Subrecord 2 - Legacy 8bit string, max 255 chars, unknown codepage
1013 aReader.ReadAndSetSubrecordLength();
1014
1015 auto entry = aStringTable.find( stringIndex );
1016
1017 if( entry != aStringTable.end() )
1018 text = entry->second;
1019 else
1020 text = aReader.ReadWxString();
1021
1022 // Normalize Windows line endings
1023 text.Replace( wxT( "\r\n" ), wxT( "\n" ) );
1024
1025 aReader.SkipSubrecord();
1026
1027 if( aReader.HasParsingError() )
1028 THROW_IO_ERROR( wxT( "Texts6 stream was not parsed correctly" ) );
1029}
1030
1032{
1033 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
1034
1035 if( recordtype != ALTIUM_RECORD::FILL )
1036 THROW_IO_ERROR( wxT( "Fills6 stream has invalid recordtype" ) );
1037
1038 // Subrecord 1
1039 aReader.ReadAndSetSubrecordLength();
1040
1041 layer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
1042
1043 uint8_t flags1 = aReader.Read<uint8_t>();
1044 is_locked = ( flags1 & 0x04 ) == 0;
1045
1046 uint8_t flags2 = aReader.Read<uint8_t>();
1047 is_keepout = flags2 == 2;
1048
1049 net = aReader.Read<uint16_t>();
1050 aReader.Skip( 2 );
1051 component = aReader.Read<uint16_t>();
1052 aReader.Skip( 4 );
1053 pos1 = aReader.ReadVector2IPos();
1054 pos2 = aReader.ReadVector2IPos();
1055 rotation = aReader.Read<double>();
1056
1057 if( aReader.GetRemainingSubrecordBytes() >= 10 )
1058 {
1059 aReader.Skip( 9 );
1060 keepoutrestrictions = aReader.Read<uint8_t>();
1061 }
1062 else
1063 {
1064 keepoutrestrictions = is_keepout ? 0x1F : 0;
1065 }
1066
1067 aReader.SkipSubrecord();
1068
1069 if( aReader.HasParsingError() )
1070 THROW_IO_ERROR( wxT( "Fills6 stream was not parsed correctly" ) );
1071}
1072
1073AREGION6::AREGION6( ALTIUM_BINARY_PARSER& aReader, bool aExtendedVertices )
1074{
1075 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
1076
1077 if( recordtype != ALTIUM_RECORD::REGION )
1078 THROW_IO_ERROR( wxT( "Regions6 stream has invalid recordtype" ) );
1079
1080 // Subrecord 1
1081 aReader.ReadAndSetSubrecordLength();
1082
1083 layer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
1084
1085 uint8_t flags1 = aReader.Read<uint8_t>();
1086 is_locked = ( flags1 & 0x04 ) == 0;
1087
1088 uint8_t flags2 = aReader.Read<uint8_t>();
1089 is_keepout = flags2 == 2;
1090
1091 net = aReader.Read<uint16_t>();
1092 polygon = aReader.Read<uint16_t>();
1093 component = aReader.Read<uint16_t>();
1094 aReader.Skip( 5 );
1095 holecount = aReader.Read<uint16_t>();
1096 aReader.Skip( 2 );
1097
1098 std::map<wxString, wxString> properties = aReader.ReadProperties();
1099
1100 if( properties.empty() )
1101 THROW_IO_ERROR( wxT( "Regions6 stream has empty properties" ) );
1102
1103 int pkind = ALTIUM_PROPS_UTILS::ReadInt( properties, wxT( "KIND" ), 0 );
1104 bool is_cutout = ALTIUM_PROPS_UTILS::ReadBool( properties, wxT( "ISBOARDCUTOUT" ), false );
1105
1106 is_shapebased = ALTIUM_PROPS_UTILS::ReadBool( properties, wxT( "ISSHAPEBASED" ), false );
1107 keepoutrestrictions = static_cast<uint8_t>(
1108 ALTIUM_PROPS_UTILS::ReadInt( properties, wxT( "KEEPOUTRESTRIC" ), 0x1F ) );
1109
1110 // TODO: this can differ from the other subpolyindex?!
1111 // Note: "the other subpolyindex" is "polygon"
1112 subpolyindex = static_cast<uint16_t>(
1113 ALTIUM_PROPS_UTILS::ReadInt( properties, "SUBPOLYINDEX", ALTIUM_POLYGON_NONE ) );
1114
1115 switch( pkind )
1116 {
1117 case 0:
1118 if( is_cutout )
1119 {
1120 kind = ALTIUM_REGION_KIND::BOARD_CUTOUT;
1121 }
1122 else
1123 {
1124 kind = ALTIUM_REGION_KIND::COPPER;
1125 }
1126 break;
1127 case 1:
1128 kind = ALTIUM_REGION_KIND::POLYGON_CUTOUT;
1129 break;
1130 case 2:
1131 kind = ALTIUM_REGION_KIND::DASHED_OUTLINE;
1132 break;
1133 case 3:
1134 kind = ALTIUM_REGION_KIND::UNKNOWN_3; // TODO: what kind is this?
1135 break;
1136 case 4:
1137 kind = ALTIUM_REGION_KIND::CAVITY_DEFINITION;
1138 break;
1139 default:
1140 kind = ALTIUM_REGION_KIND::UNKNOWN;
1141 break;
1142 }
1143
1144 uint32_t num_outline_vertices = aReader.Read<uint32_t>();
1145
1146 if( aExtendedVertices )
1147 num_outline_vertices++; // Has a closing vertex
1148
1149 for( uint32_t i = 0; i < num_outline_vertices; i++ )
1150 {
1151 if( aExtendedVertices )
1152 {
1153 bool isRound = aReader.Read<uint8_t>() != 0;
1154 VECTOR2I position = aReader.ReadVector2IPos();
1155 VECTOR2I center = aReader.ReadVector2IPos();
1156 int32_t radius = aReader.ReadKicadUnit();
1157 double angle1 = aReader.Read<double>();
1158 double angle2 = aReader.Read<double>();
1159 outline.emplace_back( isRound, radius, angle1, angle2, position, center );
1160 }
1161 else
1162 {
1163 // For some regions the coordinates are stored as double and not as int32_t
1164 int32_t x = ALTIUM_PROPS_UTILS::ConvertToKicadUnit( aReader.Read<double>() );
1165 int32_t y = ALTIUM_PROPS_UTILS::ConvertToKicadUnit( -aReader.Read<double>() );
1166 outline.emplace_back( VECTOR2I( x, y ) );
1167 }
1168 }
1169
1170 holes.resize( holecount );
1171 for( uint16_t k = 0; k < holecount; k++ )
1172 {
1173 uint32_t num_hole_vertices = aReader.Read<uint32_t>();
1174 holes.at( k ).reserve( num_hole_vertices );
1175
1176 for( uint32_t i = 0; i < num_hole_vertices; i++ )
1177 {
1178 int32_t x = ALTIUM_PROPS_UTILS::ConvertToKicadUnit( aReader.Read<double>() );
1179 int32_t y = ALTIUM_PROPS_UTILS::ConvertToKicadUnit( -aReader.Read<double>() );
1180 holes.at( k ).emplace_back( VECTOR2I( x, y ) );
1181 }
1182 }
1183
1184 aReader.SkipSubrecord();
1185
1186 if( aReader.HasParsingError() )
1187 THROW_IO_ERROR( wxT( "Regions6 stream was not parsed correctly" ) );
1188}
void altium_parse_polygons(std::map< wxString, wxString > &aProps, std::vector< ALTIUM_VERTICE > &aVertices)
static void ExpectSubrecordLengthAtLeast(const std::string &aStreamType, const std::string &aSubrecordName, size_t aExpectedLength, size_t aActualLength)
Throw an IO_ERROR if the actual length is less than the expected length.
ALTIUM_LAYER altium_layer_from_name(const wxString &aName)
static AEXTENDED_PRIMITIVE_INFORMATION_TYPE ReadAltiumExtendedPrimitiveInformationTypeFromProperties(const std::map< wxString, wxString > &aProps, wxString aKey)
static ALTIUM_MODE ReadAltiumModeFromProperties(const std::map< wxString, wxString > &aProps, wxString aKey)
static ALTIUM_RECORD ReadAltiumRecordFromProperties(const std::map< wxString, wxString > &aProps, wxString aKey)
ALTIUM_PAD_SHAPE_ALT
ALTIUM_TEXT_POSITION
ALTIUM_PAD_MODE
ALTIUM_TEXT_TYPE
ALTIUM_PAD_SHAPE
ALTIUM_DIMENSION_KIND
ALTIUM_PAD_HOLE_SHAPE
const uint16_t ALTIUM_NET_UNCONNECTED
ALTIUM_CLASS_KIND
ALTIUM_MODE
const uint16_t ALTIUM_POLYGON_NONE
ALTIUM_LAYER
AEXTENDED_PRIMITIVE_INFORMATION_TYPE
ALTIUM_RECORD
void Skip(size_t aLength)
size_t GetRemainingSubrecordBytes() const
std::map< wxString, wxString > ReadProperties(std::function< std::map< wxString, wxString >(const std::string &)> handleBinaryData=[](const std::string &) { return std::map< wxString, wxString >();})
int ReadBytes(char *aOut, size_t aSize)
static int ReadInt(const std::map< wxString, wxString > &aProps, const wxString &aKey, int aDefault)
static int32_t ReadKicadUnit(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
static bool ReadBool(const std::map< wxString, wxString > &aProps, const wxString &aKey, bool aDefault)
static wxString ReadUnicodeString(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
static wxString ReadString(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
static double ReadDouble(const std::map< wxString, wxString > &aProps, const wxString &aKey, double aDefault)
static int32_t ConvertToKicadUnit(const double aValue)
T y
Definition: vector3.h:63
T z
Definition: vector3.h:64
T x
Definition: vector3.h:62
#define _(s)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:39
double startangle
uint16_t component
bool is_keepout
uint32_t width
ALTIUM_LAYER layer
AARC6(ALTIUM_BINARY_PARSER &aReader)
uint8_t keepoutrestrictions
uint16_t polygon
VECTOR2I center
uint32_t radius
uint16_t net
bool is_locked
bool is_polygonoutline
double endangle
uint16_t subpolyindex
VECTOR2I sheetpos
std::set< wxString > layerNames
wxSize sheetsize
ABOARD6(ALTIUM_BINARY_PARSER &aReader)
std::vector< ABOARD6_LAYER_STACKUP > stackup
std::vector< ALTIUM_VERTICE > board_vertices
wxString uniqueid
std::vector< wxString > names
ALTIUM_CLASS_KIND kind
wxString name
ACLASS6(ALTIUM_BINARY_PARSER &aReader)
ALTIUM_TEXT_POSITION commentautoposition
ALTIUM_TEXT_POSITION nameautoposition
ACOMPONENT6(ALTIUM_BINARY_PARSER &aReader)
wxString sourcefootprintlibrary
ALTIUM_LAYER layer
wxString sourcelibreference
wxString sourcedesignator
wxString sourcecomponentlibrary
ACOMPONENTBODY6(ALTIUM_BINARY_PARSER &aReader)
int32_t textprecision
ALTIUM_UNIT textunit
wxString textsuffix
uint32_t textlinewidth
wxString textformat
ALTIUM_LAYER layer
std::vector< VECTOR2I > textPoint
wxString textprefix
uint32_t linewidth
ALTIUM_DIMENSION_KIND kind
uint32_t textheight
ADIMENSION6(ALTIUM_BINARY_PARSER &aReader)
std::vector< VECTOR2I > referencePoint
AEXTENDED_PRIMITIVE_INFORMATION_TYPE type
AEXTENDED_PRIMITIVE_INFORMATION(ALTIUM_BINARY_PARSER &aReader)
VECTOR2I pos2
ALTIUM_LAYER layer
uint16_t net
VECTOR2I pos1
double rotation
uint8_t keepoutrestrictions
AFILL6(ALTIUM_BINARY_PARSER &aReader)
uint16_t component
wxString name
VECTOR3D rotation
AMODEL(ALTIUM_BINARY_PARSER &aReader)
ANET6(ALTIUM_BINARY_PARSER &aReader)
wxString name
double holerotation
int32_t soldermaskexpansionmanual
uint16_t net
ALTIUM_LAYER layer
APAD6(ALTIUM_BINARY_PARSER &aReader)
std::unique_ptr< APAD6_SIZE_AND_SHAPE > sizeAndShape
ALTIUM_LAYER tolayer
ALTIUM_PAD_SHAPE topshape
ALTIUM_PAD_MODE padmode
ALTIUM_MODE pastemaskexpansionmode
uint32_t holesize
double direction
ALTIUM_MODE soldermaskexpansionmode
wxString name
bool is_test_fab_bottom
bool is_tent_bottom
VECTOR2I botsize
ALTIUM_PAD_SHAPE botshape
uint16_t component
VECTOR2I midsize
ALTIUM_PAD_SHAPE midshape
int32_t pastemaskexpansionmanual
bool is_tent_top
ALTIUM_LAYER fromlayer
VECTOR2I position
bool is_locked
VECTOR2I topsize
bool is_test_fab_top
int32_t minprimlength
std::vector< ALTIUM_VERTICE > vertices
APOLYGON6(ALTIUM_BINARY_PARSER &aReader)
ALTIUM_POLYGON_HATCHSTYLE hatchstyle
int32_t pourindex
int32_t trackwidth
ALTIUM_LAYER layer
int32_t gridsize
uint8_t keepoutrestrictions
ALTIUM_LAYER layer
AREGION6(ALTIUM_BINARY_PARSER &aReader, bool aExtendedVertices)
uint16_t holecount
std::vector< ALTIUM_VERTICE > outline
uint16_t subpolyindex
std::vector< std::vector< ALTIUM_VERTICE > > holes
uint16_t component
uint16_t net
uint16_t polygon
ALTIUM_REGION_KIND kind
ALTIUM_RULE_KIND kind
ALTIUM_CONNECT_STYLE polygonconnectStyle
wxString scope1expr
int preferredWidth
wxString name
int planeclearanceClearance
int32_t polygonconnectReliefconductorwidth
int pastemaskExpansion
wxString scope2expr
int soldermaskExpansion
ARULE6(ALTIUM_BINARY_PARSER &aReader)
int32_t polygonconnectAirgapwidth
int polygonconnectReliefentries
ALTIUM_TEXT_POSITION textposition
uint16_t component
wxString text
double rotation
uint32_t height
wxString fontname
ALTIUM_LAYER layer
VECTOR2I position
ALTIUM_TEXT_TYPE fonttype
bool isDesignator
ATEXT6(ALTIUM_BINARY_PARSER &aReader, std::map< uint32_t, wxString > &aStringTable)
uint32_t strokewidth
VECTOR2I end
ATRACK6(ALTIUM_BINARY_PARSER &aReader)
uint32_t width
bool is_polygonoutline
uint16_t net
uint16_t polygon
uint16_t subpolyindex
uint8_t keepoutrestrictions
VECTOR2I start
ALTIUM_LAYER layer
uint16_t component
uint32_t diameter
uint16_t net
VECTOR2I position
bool is_locked
bool is_tent_top
bool is_test_fab_top
bool is_tent_bottom
bool is_test_fab_bottom
ALTIUM_PAD_MODE viamode
AVIA6(ALTIUM_BINARY_PARSER &aReader)
ALTIUM_LAYER layer_start
ALTIUM_LAYER layer_end
uint32_t holesize
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588