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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <cmath>
22#include <map>
23#include <set>
24#include <unordered_map>
25
26#include <ki_exception.h>
27#include <math/util.h>
28
29#include <wx/log.h>
30#include <wx/translation.h>
31
32#include "altium_parser_pcb.h"
35
36
44static const wxChar* traceAltiumImport = wxT( "KICAD_ALTIUM_IMPORT" );
45
46
47/*
48 * Returns an Altium layer id from V6 and V7 file format data, compatible with the rest of the parser.
49 */
51{
53 return aV7Layer;
54
55 return aV6Layer;
56}
57
58
59bool altiumScopeExprMatchesPolygon( const wxString& aExpr )
60{
61 // INPOLY/ISPOLY are prefixes of INPOLYGON/ISPOLYGON, so two checks cover all four tokens.
62 wxString upper = aExpr.Upper();
63 return upper.Contains( wxT( "INPOLY" ) ) || upper.Contains( wxT( "ISPOLY" ) );
64}
65
66
67const ARULE6* selectAltiumPolygonRule( const std::vector<ARULE6>& aRulesByPriorityAsc )
68{
69 for( const ARULE6& rule : aRulesByPriorityAsc )
70 {
71 if( altiumScopeExprMatchesPolygon( rule.scope1expr )
72 || altiumScopeExprMatchesPolygon( rule.scope2expr ) )
73 {
74 return &rule;
75 }
76 }
77
78 return nullptr;
79}
80
81
82bool altiumViaSideIsTented( bool aTentFlag, bool aManual, bool aFromHole, uint32_t aHoleSize,
83 int32_t aMaskExpansion, int aLandDiameter )
84{
85 if( aTentFlag )
86 return true;
87
88 if( aManual && aFromHole )
89 {
90 int64_t opening = static_cast<int64_t>( aHoleSize ) + 2LL * aMaskExpansion;
91
92 return opening <= static_cast<int64_t>( aLandDiameter );
93 }
94
95 return false;
96}
97
98
99/*
100 * Returns V7 layer ids for Mechanical 17 and above. Otherwise, V6 layer ids.
101 */
102ALTIUM_LAYER altium_layer_from_name( const wxString& aName )
103{
104 if( aName.IsEmpty() )
106
107 static const std::unordered_map<std::string, ALTIUM_LAYER> hash_map = {
108 { "TOP", ALTIUM_LAYER::TOP_LAYER },
109 { "MID1", ALTIUM_LAYER::MID_LAYER_1 },
110 { "MID2", ALTIUM_LAYER::MID_LAYER_2 },
111 { "MID3", ALTIUM_LAYER::MID_LAYER_3 },
112 { "MID4", ALTIUM_LAYER::MID_LAYER_4 },
113 { "MID5", ALTIUM_LAYER::MID_LAYER_5 },
114 { "MID6", ALTIUM_LAYER::MID_LAYER_6 },
115 { "MID7", ALTIUM_LAYER::MID_LAYER_7 },
116 { "MID8", ALTIUM_LAYER::MID_LAYER_8 },
117 { "MID9", ALTIUM_LAYER::MID_LAYER_9 },
118 { "MID10", ALTIUM_LAYER::MID_LAYER_10 },
119 { "MID11", ALTIUM_LAYER::MID_LAYER_11 },
120 { "MID12", ALTIUM_LAYER::MID_LAYER_12 },
121 { "MID13", ALTIUM_LAYER::MID_LAYER_13 },
122 { "MID14", ALTIUM_LAYER::MID_LAYER_14 },
123 { "MID15", ALTIUM_LAYER::MID_LAYER_15 },
124 { "MID16", ALTIUM_LAYER::MID_LAYER_16 },
125 { "MID17", ALTIUM_LAYER::MID_LAYER_17 },
126 { "MID18", ALTIUM_LAYER::MID_LAYER_18 },
127 { "MID19", ALTIUM_LAYER::MID_LAYER_19 },
128 { "MID20", ALTIUM_LAYER::MID_LAYER_20 },
129 { "MID21", ALTIUM_LAYER::MID_LAYER_21 },
130 { "MID22", ALTIUM_LAYER::MID_LAYER_22 },
131 { "MID23", ALTIUM_LAYER::MID_LAYER_23 },
132 { "MID24", ALTIUM_LAYER::MID_LAYER_24 },
133 { "MID25", ALTIUM_LAYER::MID_LAYER_25 },
134 { "MID26", ALTIUM_LAYER::MID_LAYER_26 },
135 { "MID27", ALTIUM_LAYER::MID_LAYER_27 },
136 { "MID28", ALTIUM_LAYER::MID_LAYER_28 },
137 { "MID29", ALTIUM_LAYER::MID_LAYER_29 },
138 { "MID30", ALTIUM_LAYER::MID_LAYER_30 },
139 { "BOTTOM", ALTIUM_LAYER::BOTTOM_LAYER },
140
141 { "TOPOVERLAY", ALTIUM_LAYER::TOP_OVERLAY },
142 { "BOTTOMOVERLAY", ALTIUM_LAYER::BOTTOM_OVERLAY },
143 { "TOPPASTE", ALTIUM_LAYER::TOP_PASTE },
144 { "BOTTOMPASTE", ALTIUM_LAYER::BOTTOM_PASTE },
145 { "TOPSOLDER", ALTIUM_LAYER::TOP_SOLDER },
146 { "BOTTOMSOLDER", ALTIUM_LAYER::BOTTOM_SOLDER },
147
148 { "PLANE1", ALTIUM_LAYER::INTERNAL_PLANE_1 },
149 { "PLANE2", ALTIUM_LAYER::INTERNAL_PLANE_2 },
150 { "PLANE3", ALTIUM_LAYER::INTERNAL_PLANE_3 },
151 { "PLANE4", ALTIUM_LAYER::INTERNAL_PLANE_4 },
152 { "PLANE5", ALTIUM_LAYER::INTERNAL_PLANE_5 },
153 { "PLANE6", ALTIUM_LAYER::INTERNAL_PLANE_6 },
154 { "PLANE7", ALTIUM_LAYER::INTERNAL_PLANE_7 },
155 { "PLANE8", ALTIUM_LAYER::INTERNAL_PLANE_8 },
156 { "PLANE9", ALTIUM_LAYER::INTERNAL_PLANE_9 },
157 { "PLANE10", ALTIUM_LAYER::INTERNAL_PLANE_10 },
158 { "PLANE11", ALTIUM_LAYER::INTERNAL_PLANE_11 },
159 { "PLANE12", ALTIUM_LAYER::INTERNAL_PLANE_12 },
160 { "PLANE13", ALTIUM_LAYER::INTERNAL_PLANE_13 },
161 { "PLANE14", ALTIUM_LAYER::INTERNAL_PLANE_14 },
162 { "PLANE15", ALTIUM_LAYER::INTERNAL_PLANE_15 },
163 { "PLANE16", ALTIUM_LAYER::INTERNAL_PLANE_16 },
164
165 { "DRILLGUIDE", ALTIUM_LAYER::DRILL_GUIDE },
166 { "KEEPOUT", ALTIUM_LAYER::KEEP_OUT_LAYER },
167
168 { "MECHANICAL1", ALTIUM_LAYER::MECHANICAL_1 },
169 { "MECHANICAL2", ALTIUM_LAYER::MECHANICAL_2 },
170 { "MECHANICAL3", ALTIUM_LAYER::MECHANICAL_3 },
171 { "MECHANICAL4", ALTIUM_LAYER::MECHANICAL_4 },
172 { "MECHANICAL5", ALTIUM_LAYER::MECHANICAL_5 },
173 { "MECHANICAL6", ALTIUM_LAYER::MECHANICAL_6 },
174 { "MECHANICAL7", ALTIUM_LAYER::MECHANICAL_7 },
175 { "MECHANICAL8", ALTIUM_LAYER::MECHANICAL_8 },
176 { "MECHANICAL9", ALTIUM_LAYER::MECHANICAL_9 },
177 { "MECHANICAL10", ALTIUM_LAYER::MECHANICAL_10 },
178 { "MECHANICAL11", ALTIUM_LAYER::MECHANICAL_11 },
179 { "MECHANICAL12", ALTIUM_LAYER::MECHANICAL_12 },
180 { "MECHANICAL13", ALTIUM_LAYER::MECHANICAL_13 },
181 { "MECHANICAL14", ALTIUM_LAYER::MECHANICAL_14 },
182 { "MECHANICAL15", ALTIUM_LAYER::MECHANICAL_15 },
183 { "MECHANICAL16", ALTIUM_LAYER::MECHANICAL_16 },
184
185 { "DRILLDRAWING", ALTIUM_LAYER::DRILL_DRAWING },
186 { "MULTILAYER", ALTIUM_LAYER::MULTI_LAYER },
187
188 // FIXME: the following mapping is just a guess
189 { "CONNECTIONS", ALTIUM_LAYER::CONNECTIONS },
190 { "BACKGROUND", ALTIUM_LAYER::BACKGROUND },
191 { "DRCERRORMARKERS", ALTIUM_LAYER::DRC_ERROR_MARKERS },
192 { "SELECTIONS", ALTIUM_LAYER::SELECTIONS },
193 { "VISIBLEGRID1", ALTIUM_LAYER::VISIBLE_GRID_1 },
194 { "VISIBLEGRID2", ALTIUM_LAYER::VISIBLE_GRID_2 },
195 { "PADHOLES", ALTIUM_LAYER::PAD_HOLES },
196 { "VIAHOLES", ALTIUM_LAYER::VIA_HOLES },
197 };
198
199 auto it = hash_map.find( std::string( aName.c_str() ) );
200
201 if( it != hash_map.end() )
202 return it->second;
203
204 // Try V7 format mechanical layers
205 const wxString mechanicalStr( "MECHANICAL" );
206
207 if( aName.StartsWith( mechanicalStr ) )
208 {
209 unsigned long val = 0;
210
211 if( aName.Mid( mechanicalStr.length() ).ToULong( &val ) )
212 return static_cast<ALTIUM_LAYER>( static_cast<int>( ALTIUM_LAYER::V7_MECHANICAL_BASE ) + val );
213 }
214
215 wxLogError( _( "Unknown mapping of the Altium layer '%s'." ), aName );
217}
218
219
221{
222 static const std::unordered_map<std::string, ALTIUM_MECHKIND> hash_map = {
223 { "AssemblyTop", ALTIUM_MECHKIND::ASSEMBLY_TOP },
224 { "AssemblyBottom", ALTIUM_MECHKIND::ASSEMBLY_BOT },
225
226 { "AssemblyNotes", ALTIUM_MECHKIND::ASSEMBLY_NOTES },
227 { "Board", ALTIUM_MECHKIND::BOARD },
228
229 { "CoatingTop", ALTIUM_MECHKIND::COATING_TOP },
230 { "CoatingBottom", ALTIUM_MECHKIND::COATING_BOT },
231
232 { "ComponentCenterTop", ALTIUM_MECHKIND::COMPONENT_CENTER_TOP },
233 { "ComponentCenterBottom", ALTIUM_MECHKIND::COMPONENT_CENTER_BOT },
234
235 { "ComponentOutlineTop", ALTIUM_MECHKIND::COMPONENT_OUTLINE_TOP },
236 { "ComponentOutlineBottom", ALTIUM_MECHKIND::COMPONENT_OUTLINE_BOT },
237
238 { "CourtyardTop", ALTIUM_MECHKIND::COURTYARD_TOP },
239 { "CourtyardBottom", ALTIUM_MECHKIND::COURTYARD_BOT },
240
241 { "DesignatorTop", ALTIUM_MECHKIND::DESIGNATOR_TOP },
242 { "DesignatorBottom", ALTIUM_MECHKIND::DESIGNATOR_BOT },
243
244 { "Dimensions", ALTIUM_MECHKIND::DIMENSIONS },
245 { "DimensionsTop", ALTIUM_MECHKIND::DIMENSIONS_TOP },
246 { "DimensionsBottom", ALTIUM_MECHKIND::DIMENSIONS_BOT },
247
248 { "FabNotes", ALTIUM_MECHKIND::FAB_NOTES },
249
250 { "GluePointsTop", ALTIUM_MECHKIND::GLUE_POINTS_TOP },
251 { "GluePointsBottom", ALTIUM_MECHKIND::GLUE_POINTS_BOT },
252
253 { "GoldPlatingTop", ALTIUM_MECHKIND::GOLD_PLATING_TOP },
254 { "GoldPlatingBottom", ALTIUM_MECHKIND::GOLD_PLATING_BOT },
255
256 { "ValueTop", ALTIUM_MECHKIND::VALUE_TOP },
257 { "ValueBottom", ALTIUM_MECHKIND::VALUE_BOT },
258
259 { "VCut", ALTIUM_MECHKIND::V_CUT },
260
261 { "3DBodyTop", ALTIUM_MECHKIND::BODY_3D_TOP },
262 { "3DBodyBottom", ALTIUM_MECHKIND::BODY_3D_BOT },
263
264 { "RouteToolPath", ALTIUM_MECHKIND::ROUTE_TOOL_PATH },
265 { "Sheet", ALTIUM_MECHKIND::SHEET },
266 { "BoardShape", ALTIUM_MECHKIND::BOARD_SHAPE },
267 };
268
269 auto it = hash_map.find( std::string( aName.c_str() ) );
270
271 if( it != hash_map.end() )
272 {
273 return it->second;
274 }
275 else
276 {
277 wxLogError( _( "Unknown mapping of the Altium layer kind '%s'." ), aName );
279 }
280}
281
282
283void altium_parse_polygons( std::map<wxString, wxString>& aProps,
284 std::vector<ALTIUM_VERTICE>& aVertices )
285{
286 for( size_t i = 0; i < std::numeric_limits<size_t>::max(); i++ )
287 {
288 const wxString si = std::to_string( i );
289
290 const wxString vxi = wxT( "VX" ) + si;
291 const wxString vyi = wxT( "VY" ) + si;
292
293 if( aProps.find( vxi ) == aProps.end() || aProps.find( vyi ) == aProps.end() )
294 break; // it doesn't seem like we know beforehand how many vertices are inside a polygon
295
296 const bool isRound = ALTIUM_PROPS_UTILS::ReadInt( aProps, wxT( "KIND" ) + si, 0 ) != 0;
297 const int32_t radius = ALTIUM_PROPS_UTILS::ReadKicadUnit( aProps, wxT( "R" ) + si, wxT( "0mil" ) );
298 const double sa = ALTIUM_PROPS_UTILS::ReadDouble( aProps, wxT( "SA" ) + si, 0. );
299 const double ea = ALTIUM_PROPS_UTILS::ReadDouble( aProps, wxT( "EA" ) + si, 0. );
300 const VECTOR2I vp = VECTOR2I( ALTIUM_PROPS_UTILS::ReadKicadUnit( aProps, vxi, wxT( "0mil" ) ),
301 -ALTIUM_PROPS_UTILS::ReadKicadUnit( aProps, vyi, wxT( "0mil" ) ) );
302 const VECTOR2I cp = VECTOR2I( ALTIUM_PROPS_UTILS::ReadKicadUnit( aProps, wxT( "CX" ) + si, wxT( "0mil" ) ),
303 -ALTIUM_PROPS_UTILS::ReadKicadUnit( aProps, wxT( "CY" ) + si, wxT( "0mil" ) ) );
304
305 aVertices.emplace_back( isRound, radius, sa, ea, vp, cp );
306 }
307}
308
309
310static ALTIUM_MODE ReadAltiumModeFromProperties( const std::map<wxString, wxString>& aProps,
311 wxString aKey )
312{
313 wxString mode = ALTIUM_PROPS_UTILS::ReadString( aProps, aKey, wxT( "" ) );
314
315 if( mode == wxT( "None" ) )
316 return ALTIUM_MODE::NONE;
317 else if( mode == wxT( "Rule" ) )
318 return ALTIUM_MODE::RULE;
319 else if( mode == wxT( "Manual" ) )
320 return ALTIUM_MODE::MANUAL;
321
322 wxLogError( _( "Unknown Mode string: '%s'." ), mode );
324}
325
326
327static ALTIUM_RECORD ReadAltiumRecordFromProperties( const std::map<wxString, wxString>& aProps,
328 wxString aKey )
329{
330 wxString record = ALTIUM_PROPS_UTILS::ReadString( aProps, aKey, wxT( "" ) );
331
332 if( record == wxT( "Arc" ) )
333 return ALTIUM_RECORD::ARC;
334 else if( record == wxT( "Pad" ) )
335 return ALTIUM_RECORD::PAD;
336 else if( record == wxT( "Via" ) )
337 return ALTIUM_RECORD::VIA;
338 else if( record == wxT( "Track" ) )
340 else if( record == wxT( "Text" ) )
341 return ALTIUM_RECORD::TEXT;
342 else if( record == wxT( "Fill" ) )
343 return ALTIUM_RECORD::FILL;
344 else if( record == wxT( "Region" ) ) // correct?
346 else if( record == wxT( "Model" ) )
348
349 wxLogError( _( "Unknown Record name string: '%s'." ), record );
351}
352
353
356 const std::map<wxString, wxString>& aProps, wxString aKey )
357{
358 wxString parsedType = ALTIUM_PROPS_UTILS::ReadString( aProps, aKey, wxT( "" ) );
359
360 if( parsedType == wxT( "Mask" ) )
362
363 wxLogError( _( "Unknown Extended Primitive Information type: '%s'." ), parsedType );
365}
366
367
376static void ExpectSubrecordLengthAtLeast( const std::string& aStreamType,
377 const std::string& aSubrecordName, size_t aExpectedLength,
378 size_t aActualLength )
379{
380 if( aActualLength < aExpectedLength )
381 {
382 THROW_IO_ERROR( wxString::Format( "%s stream %s has length %d, "
383 "which is unexpected (expected at least %d)",
384 aStreamType, aSubrecordName, aActualLength,
385 aExpectedLength ) );
386 }
387}
388
389
391{
392 const std::map<wxString, wxString> props = aReader.ReadProperties();
393
394 if( props.empty() )
395 THROW_IO_ERROR( wxT( "ExtendedPrimitiveInformation stream has no properties!" ) );
396
397 primitiveIndex = ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "PRIMITIVEINDEX" ), -1 );
398 primitiveObjectId = ReadAltiumRecordFromProperties( props, wxT( "PRIMITIVEOBJECTID" ) );
400
401 pastemaskexpansionmode = ReadAltiumModeFromProperties( props, wxT( "PASTEMASKEXPANSIONMODE" ) );
403 props, wxT( "PASTEMASKEXPANSION_MANUAL" ), wxT( "0mil" ) );
405 ReadAltiumModeFromProperties( props, wxT( "SOLDERMASKEXPANSIONMODE" ) );
407 props, wxT( "SOLDERMASKEXPANSION_MANUAL" ), wxT( "0mil" ) );
408}
409
410
411ABOARD6_LAYER_STACKUP::ABOARD6_LAYER_STACKUP( const std::map<wxString, wxString>& aProps, const wxString& aPrefix,
412 uint32_t aLayerIdFallback )
413{
414 // LAYERID is specific to V7 format
415 layerId = ALTIUM_PROPS_UTILS::ReadInt( aProps, aPrefix + wxT( "LAYERID" ), aLayerIdFallback );
416
417 name = ALTIUM_PROPS_UTILS::ReadString( aProps, aPrefix + wxT( "NAME" ), wxT( "" ) );
418 nextId = ALTIUM_PROPS_UTILS::ReadInt( aProps, aPrefix + wxT( "NEXT" ), 0 );
419 prevId = ALTIUM_PROPS_UTILS::ReadInt( aProps, aPrefix + wxT( "PREV" ), 0 );
420 copperthick = ALTIUM_PROPS_UTILS::ReadKicadUnit( aProps, aPrefix + wxT( "COPTHICK" ), wxT( "1.4mil" ) );
421
422 dielectricconst = ALTIUM_PROPS_UTILS::ReadDouble( aProps, aPrefix + wxT( "DIELCONST" ), 0. );
423 dielectricthick = ALTIUM_PROPS_UTILS::ReadKicadUnit( aProps, aPrefix + wxT( "DIELHEIGHT" ), wxT( "60mil" ) );
424 dielectricmaterial = ALTIUM_PROPS_UTILS::ReadString( aProps, aPrefix + wxT( "DIELMATERIAL" ), wxT( "FR-4" ) );
425
426 // TODO: In some component libraries MECHENABLED may be FALSE but the layers show up as used.
427 // (we should check if any objects exists on these layers?)
428 wxString mechEnabled = ALTIUM_PROPS_UTILS::ReadString( aProps, aPrefix + wxT( "MECHENABLED" ), wxT( "" ) );
429
430 mechenabled = !mechEnabled.Contains( wxS( "FALSE" ) );
431
432 if( mechenabled )
433 {
434 wxString mechKind = ALTIUM_PROPS_UTILS::ReadString( aProps, aPrefix + wxT( "MECHKIND" ), wxT( "" ) );
435
436 if( !mechKind.IsEmpty() )
438 }
439}
440
441
442static wxString MakeAltiumDielectricKey( const wxString& aMaterial, int32_t aHeight, double aConst )
443{
444 return wxString::Format( wxT( "%s|%d|%d" ), aMaterial, aHeight,
445 static_cast<int>( std::lround( aConst * 1000.0 ) ) );
446}
447
448
449// Build a lookup from the modern physical stackup keys (LAYER_V8_<n> / V9_STACK_LAYER<n>) so we
450// can recover dielectric properties that the legacy LAYER<n> keys do not carry. Currently only the
451// loss tangent is missing from the legacy records, so we key the lookup on the dielectric material,
452// height and permittivity that both formats share. If two distinct dielectrics share the same key
453// but report different loss tangents the mapping is ambiguous, so we flag it and skip the backfill
454// for that key rather than guess.
455static std::map<wxString, double> ReadAltiumDielectricLossTangents( const std::map<wxString, wxString>& aProps )
456{
457 std::map<wxString, double> tangents;
458 std::set<wxString> ambiguous;
459
460 auto scan = [&]( const wxString& aFamily )
461 {
462 for( size_t i = 0; i < std::numeric_limits<size_t>::max(); i++ )
463 {
464 const wxString prefix = aFamily + std::to_string( i );
465
466 if( aProps.find( prefix + wxT( "NAME" ) ) == aProps.end() )
467 break;
468
469 if( aProps.find( prefix + wxT( "DIELLOSSTANGENT" ) ) == aProps.end() )
470 continue;
471
472 wxString material = ALTIUM_PROPS_UTILS::ReadString( aProps, prefix + wxT( "DIELMATERIAL" ),
473 wxT( "" ) );
474 int32_t height = ALTIUM_PROPS_UTILS::ReadKicadUnit( aProps, prefix + wxT( "DIELHEIGHT" ),
475 wxT( "0mil" ) );
476 double diconst = ALTIUM_PROPS_UTILS::ReadDouble( aProps, prefix + wxT( "DIELCONST" ), 0. );
477 double tangent = ALTIUM_PROPS_UTILS::ReadDouble( aProps, prefix + wxT( "DIELLOSSTANGENT" ),
478 0. );
479
480 wxString key = MakeAltiumDielectricKey( material, height, diconst );
481
482 auto [it, inserted] = tangents.insert( { key, tangent } );
483
484 if( !inserted && std::abs( it->second - tangent ) > 1e-9 )
485 ambiguous.insert( key );
486 }
487 };
488
489 // Prefer V9 keys (most recent); fall back to the V8 physical stackup keys only for dielectrics
490 // the V9 scan did not already provide.
491 scan( wxT( "V9_STACK_LAYER" ) );
492 scan( wxT( "LAYER_V8_" ) );
493
494 for( const wxString& key : ambiguous )
495 tangents.erase( key );
496
497 return tangents;
498}
499
500
501static std::vector<ABOARD6_LAYER_STACKUP> ReadAltiumStackupFromProperties( const std::map<wxString, wxString>& aProps )
502{
503 std::vector<ABOARD6_LAYER_STACKUP> stackup;
504
505 for( size_t i = 1; i < std::numeric_limits<size_t>::max(); i++ )
506 {
507 const wxString layeri = wxString( wxT( "LAYER" ) ) << std::to_string( i );
508 const wxString layername = layeri + wxT( "NAME" );
509
510 auto layernameit = aProps.find( layername );
511
512 if( layernameit == aProps.end() )
513 break;
514
515 ABOARD6_LAYER_STACKUP l( aProps, layeri, i );
516 stackup.push_back( l );
517 }
518
519 // V7 format layers
520 for( size_t i = 0; i < std::numeric_limits<size_t>::max(); i++ )
521 {
522 const wxString layeri = wxString( wxT( "LAYERV7_" ) ) << std::to_string( i );
523 const wxString layername = layeri + wxT( "NAME" );
524
525 auto layernameit = aProps.find( layername );
526
527 if( layernameit == aProps.end() )
528 break;
529
530 ABOARD6_LAYER_STACKUP l( aProps, layeri, 0 );
531 stackup.push_back( l );
532 }
533
534 // The legacy LAYER<n> records do not store the dielectric loss tangent, but the modern V8/V9
535 // physical stackup keys do. Backfill it onto the matching dielectric records.
536 std::map<wxString, double> tangents = ReadAltiumDielectricLossTangents( aProps );
537
538 if( !tangents.empty() )
539 {
540 for( ABOARD6_LAYER_STACKUP& l : stackup )
541 {
542 wxString key = MakeAltiumDielectricKey( l.dielectricmaterial, l.dielectricthick,
543 l.dielectricconst );
544
545 auto it = tangents.find( key );
546
547 if( it != tangents.end() )
548 l.dielectriclosstangent = it->second;
549 }
550 }
551
552 return stackup;
553}
554
555
557{
558 std::map<wxString, wxString> props = aReader.ReadProperties();
559
560 if( props.empty() )
561 THROW_IO_ERROR( wxT( "Library stream has no properties!" ) );
562
563 layercount = ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "LAYERSETSCOUNT" ), 1 ) + 1;
564
566
568 {
569 wxString originalName = l.name;
570
571 // Ensure that layer names are unique in KiCad
572 for( int ii = 2; !layerNames.insert( l.name ).second; ii++ )
573 l.name = wxString::Format( wxT( "%s %d" ), originalName, ii );
574 }
575
576 if( aReader.HasParsingError() )
577 THROW_IO_ERROR( wxT( "Library stream was not parsed correctly!" ) );
578}
579
580
582{
583 std::map<wxString, wxString> props = aReader.ReadProperties();
584
585 if( props.empty() )
586 THROW_IO_ERROR( wxT( "Board6 stream has no properties!" ) );
587
588 sheetpos = VECTOR2I( ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "SHEETX" ), wxT( "0mil" ) ),
589 -ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "SHEETY" ), wxT( "0mil" ) ) );
590 sheetsize = wxSize( ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "SHEETWIDTH" ), wxT( "0mil" ) ),
591 ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "SHEETHEIGHT" ), wxT( "0mil" ) ) );
592
593 layercount = ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "LAYERSETSCOUNT" ), 1 ) + 1;
594
596
598 {
599 wxString originalName = l.name;
600
601 // Ensure that layer names are unique in KiCad
602 for( int ii = 2; !layerNames.insert( l.name ).second; ii++ )
603 l.name = wxString::Format( wxT( "%s %d" ), originalName, ii );
604 }
605
607
608 if( aReader.HasParsingError() )
609 THROW_IO_ERROR( wxT( "Board6 stream was not parsed correctly!" ) );
610}
611
613{
614 std::map<wxString, wxString> properties = aReader.ReadProperties();
615
616 if( properties.empty() )
617 THROW_IO_ERROR( wxT( "Classes6 stream has no properties!" ) );
618
619 name = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "NAME" ), wxT( "" ) );
620 uniqueid = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "UNIQUEID" ), wxT( "" ) );
621 kind = static_cast<ALTIUM_CLASS_KIND>( ALTIUM_PROPS_UTILS::ReadInt( properties, wxT( "KIND" ), -1 ) );
622
623 for( size_t i = 0; i < std::numeric_limits<size_t>::max(); i++ )
624 {
625 auto mit = properties.find( wxT( "M" ) + wxString( std::to_string( i ) ) );
626
627 if( mit == properties.end() )
628 break; // it doesn't seem like we know beforehand how many components are in the netclass
629
630 names.push_back( mit->second );
631 }
632
633 if( aReader.HasParsingError() )
634 THROW_IO_ERROR( wxT( "Classes6 stream was not parsed correctly" ) );
635}
636
638{
639 std::map<wxString, wxString> props = aReader.ReadProperties();
640
641 if( props.empty() )
642 THROW_IO_ERROR( wxT( "Components6 stream has no props" ) );
643
644 layer = altium_layer_from_name( ALTIUM_PROPS_UTILS::ReadString( props, wxT( "LAYER" ), wxT( "" ) ) );
645 position = VECTOR2I( ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "X" ), wxT( "0mil" ) ),
646 -ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "Y" ), wxT( "0mil" ) ) );
647 rotation = ALTIUM_PROPS_UTILS::ReadDouble( props, wxT( "ROTATION" ), 0. );
648 locked = ALTIUM_PROPS_UTILS::ReadBool( props, wxT( "LOCKED" ), false );
649 nameon = ALTIUM_PROPS_UTILS::ReadBool( props, wxT( "NAMEON" ), true );
650 commenton = ALTIUM_PROPS_UTILS::ReadBool( props, wxT( "COMMENTON" ), false );
651 sourcedesignator = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "SOURCEDESIGNATOR" ), wxT( "" ) );
652
653 sourceUniqueID = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "SOURCEUNIQUEID" ), wxT( "" ) );
654
655 // Remove leading backslash from sourceUniqueID to match schematic component unique IDs
656 if( sourceUniqueID.starts_with( wxT( "\\" ) ) )
658
659 sourceHierachicalPath = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "SOURCEHIERARCHICALPATH" ), wxT( "" ) );
661 ALTIUM_PROPS_UTILS::ReadUnicodeString( props, wxT( "SOURCEFOOTPRINTLIBRARY" ), wxT( "" ) );
662 pattern = ALTIUM_PROPS_UTILS::ReadUnicodeString( props, wxT( "PATTERN" ), wxT( "" ) );
663
664 sourcecomponentlibrary = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "SOURCECOMPONENTLIBRARY" ), wxT( "" ) );
665 sourcelibreference = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "SOURCELIBREFERENCE" ), wxT( "" ) );
666
668 ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "NAMEAUTOPOSITION" ), 0 ) );
670 ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "COMMENTAUTOPOSITION" ), 0 ) );
671
672 if( aReader.HasParsingError() )
673 THROW_IO_ERROR( wxT( "Components6 stream was not parsed correctly" ) );
674}
675
677{
678 aReader.Skip( 2 );
679
680 std::map<wxString, wxString> props = aReader.ReadProperties();
681
682 if( props.empty() )
683 THROW_IO_ERROR( wxT( "Dimensions6 stream has no props" ) );
684
685 layer_v6 = altium_layer_from_name( ALTIUM_PROPS_UTILS::ReadString( props, wxT( "LAYER" ), wxT( "" ) ) );
686 layer_v7 = altium_layer_from_name( ALTIUM_PROPS_UTILS::ReadString( props, wxT( "LAYER_V7" ), wxT( "" ) ) );
687 kind = static_cast<ALTIUM_DIMENSION_KIND>( ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "DIMENSIONKIND" ), 0 ) );
688
689 textformat = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "TEXTFORMAT" ), wxT( "" ) );
690 textprefix = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "TEXTPREFIX" ), wxT( "" ) );
691 textsuffix = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "TEXTSUFFIX" ), wxT( "" ) );
692
693 height = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "HEIGHT" ), wxT( "0mil" ) );
694 angle = ALTIUM_PROPS_UTILS::ReadDouble( props, wxT( "ANGLE" ), 0. );
695
696 linewidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "LINEWIDTH" ), wxT( "10mil" ) );
697 textheight = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "TEXTHEIGHT" ), wxT( "10mil" ) );
698 textlinewidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "TEXTLINEWIDTH" ), wxT( "6mil" ) );
699 textprecision = ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "TEXTPRECISION" ), 2 );
700 textbold = ALTIUM_PROPS_UTILS::ReadBool( props, wxT( "TEXTLINEWIDTH" ), false );
701 textitalic = ALTIUM_PROPS_UTILS::ReadBool( props, wxT( "ITALIC" ), false );
702 textgap = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "TEXTGAP" ), wxT( "10mil" ) );
703
704 arrowsize = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "ARROWSIZE" ), wxT( "60mil" ) );
705
706 wxString text_position_raw = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "TEXTPOSITION" ), wxT( "" ) );
707
708 xy1 = VECTOR2I( ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "X1" ), wxT( "0mil" ) ),
709 -ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "Y1" ), wxT( "0mil" ) ) );
710
711 int refcount = ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "REFERENCES_COUNT" ), 0 );
712
713 for( int i = 0; i < refcount; i++ )
714 {
715 const std::string refi = "REFERENCE" + std::to_string( i ) + "POINT";
716 const wxString ref( refi );
717 referencePoint.emplace_back( ALTIUM_PROPS_UTILS::ReadKicadUnit( props, ref + wxT( "X" ), wxT( "0mil" ) ),
718 -ALTIUM_PROPS_UTILS::ReadKicadUnit( props, ref + wxT( "Y" ), wxT( "0mil" ) ) );
719 }
720
721 for( size_t i = 1; i < std::numeric_limits<size_t>::max(); i++ )
722 {
723 const std::string texti = "TEXT" + std::to_string( i );
724 const std::string textix = texti + "X";
725 const std::string textiy = texti + "Y";
726
727 if( props.find( textix ) == props.end() || props.find( textiy ) == props.end() )
728 break; // it doesn't seem like we know beforehand how many vertices are inside a polygon
729
730 textPoint.emplace_back( ALTIUM_PROPS_UTILS::ReadKicadUnit( props, textix, wxT( "0mil" ) ),
731 -ALTIUM_PROPS_UTILS::ReadKicadUnit( props, textiy, wxT( "0mil" ) ) );
732 }
733
734 wxString dimensionunit = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "TEXTDIMENSIONUNIT" ), wxT( "Millimeters" ) );
735
736 if( dimensionunit == wxT( "Inches" ) ) textunit = ALTIUM_UNIT::INCH;
737 else if( dimensionunit == wxT( "Mils" ) ) textunit = ALTIUM_UNIT::MILS;
738 else if( dimensionunit == wxT( "Millimeters" ) ) textunit = ALTIUM_UNIT::MM;
739 else if( dimensionunit == wxT( "Centimeters" ) ) textunit = ALTIUM_UNIT::CM;
741
743
744 if( aReader.HasParsingError() )
745 THROW_IO_ERROR( wxT( "Dimensions6 stream was not parsed correctly" ) );
746}
747
749{
750 std::map<wxString, wxString> properties = aReader.ReadProperties();
751
752 if( properties.empty() )
753 THROW_IO_ERROR( wxT( "Model stream has no properties!" ) );
754
755 name = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "NAME" ), wxT( "" ) );
756 id = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "ID" ), wxT( "" ) );
757 isEmbedded = ALTIUM_PROPS_UTILS::ReadBool( properties, wxT( "EMBED" ), false );
758
759 rotation.x = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "ROTX" ), 0. );
760 rotation.y = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "ROTY" ), 0. );
761 rotation.z = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "ROTZ" ), 0. );
762
763 z_offset = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "DZ" ), 0. );
764 checksum = ALTIUM_PROPS_UTILS::ReadInt( properties, wxT( "CHECKSUM" ), 0 );
765
766 if( aReader.HasParsingError() )
767 THROW_IO_ERROR( wxT( "Model stream was not parsed correctly" ) );
768}
769
771{
772 std::map<wxString, wxString> properties = aReader.ReadProperties();
773
774 if( properties.empty() )
775 THROW_IO_ERROR( wxT( "Nets6 stream has no properties" ) );
776
777 name = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "NAME" ), wxT( "" ) );
778
779 if( aReader.HasParsingError() )
780 THROW_IO_ERROR( wxT( "Nets6 stream was not parsed correctly" ) );
781}
782
784{
785 std::map<wxString, wxString> properties = aReader.ReadProperties();
786
787 if( properties.empty() )
788 THROW_IO_ERROR( wxT( "Polygons6 stream has no properties" ) );
789
790 layer_v6 = altium_layer_from_name( ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "LAYER" ), wxT( "" ) ) );
791 layer_v7 = altium_layer_from_name( ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "LAYER_V7" ), wxT( "" ) ) );
792 net = ALTIUM_PROPS_UTILS::ReadInt( properties, wxT( "NET" ), ALTIUM_NET_UNCONNECTED );
793 locked = ALTIUM_PROPS_UTILS::ReadBool( properties, wxT( "LOCKED" ), false );
794
795 // TODO: kind
796
797 gridsize = ALTIUM_PROPS_UTILS::ReadKicadUnit( properties, wxT( "GRIDSIZE" ), wxT( "0mil" ) );
798 trackwidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( properties, wxT( "TRACKWIDTH" ), wxT( "0mil" ) );
799 minprimlength = ALTIUM_PROPS_UTILS::ReadKicadUnit( properties, wxT( "MINPRIMLENGTH" ), wxT( "0mil" ) );
800 useoctagons = ALTIUM_PROPS_UTILS::ReadBool( properties, wxT( "USEOCTAGONS" ), false );
801
802 pourindex = ALTIUM_PROPS_UTILS::ReadInt( properties, wxT( "POURINDEX" ), 0 );
803
804 wxString hatchstyleraw = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "HATCHSTYLE" ), wxT( "" ) );
805
806 if( hatchstyleraw == wxT( "Solid" ) ) hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::SOLID;
807 else if( hatchstyleraw == wxT( "45Degree" ) ) hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::DEGREE_45;
808 else if( hatchstyleraw == wxT( "90Degree" ) ) hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::DEGREE_90;
809 else if( hatchstyleraw == wxT( "Horizontal" ) ) hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::HORIZONTAL;
810 else if( hatchstyleraw == wxT( "Vertical" ) ) hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::VERTICAL;
811 else if( hatchstyleraw == wxT( "None" ) ) hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::NONE;
813
814 altium_parse_polygons( properties, vertices );
815
817
818 if( aReader.HasParsingError() )
819 THROW_IO_ERROR( wxT( "Polygons6 stream was not parsed correctly" ) );
820}
821
823{
824 aReader.Skip( 2 );
825
826 std::map<wxString, wxString> props = aReader.ReadProperties();
827
828 if( props.empty() )
829 THROW_IO_ERROR( wxT( "Rules6 stream has no props" ) );
830
831 name = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "NAME" ), wxT( "" ) );
832 priority = ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "PRIORITY" ), 1 );
833
834 scope1expr = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "SCOPE1EXPRESSION" ), wxT( "" ) );
835 scope2expr = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "SCOPE2EXPRESSION" ), wxT( "" ) );
836
837 wxString rulekind = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "RULEKIND" ), wxT( "" ) );
838 if( rulekind == wxT( "Clearance" ) )
839 {
841 clearanceGap = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "GAP" ), wxT( "10mil" ) );
842 }
843 else if( rulekind == wxT( "DiffPairsRouting" ) )
844 {
846 }
847 else if( rulekind == wxT( "Height" ) )
848 {
850 }
851 else if( rulekind == wxT( "HoleSize" ) )
852 {
854 minLimit = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MINLIMIT" ), wxT( "1mil" ) );
855 maxLimit = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MAXLIMIT" ), wxT( "150mil" ) );
856 }
857 else if( rulekind == wxT( "HoleToHoleClearance" ) )
858 {
860 clearanceGap = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "GAP" ), wxT( "10mil" ) );
861 }
862 else if( rulekind == wxT( "RoutingVias" ) )
863 {
865 width = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "WIDTH" ), wxT( "20mil" ) );
866 minWidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MINWIDTH" ), wxT( "20mil" ) );
867 maxWidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MAXWIDTH" ), wxT( "50mil" ) );
868 holeWidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "HOLEWIDTH" ), wxT( "10mil" ) );
869 minHoleWidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MINHOLEWIDTH" ), wxT( "10mil" ) );
870 maxHoleWidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MAXHOLEWIDTH" ), wxT( "28mil" ) );
871 }
872 else if( rulekind == wxT( "Width" ) )
873 {
875 minLimit = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MINLIMIT" ), wxT( "6mil" ) );
876 maxLimit = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MAXLIMIT" ), wxT( "40mil" ) );
877 preferredWidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "PREFERREDWIDTH" ), wxT( "6mil" ) );
878}
879 else if( rulekind == wxT( "PasteMaskExpansion" ) )
880 {
882 pastemaskExpansion = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "EXPANSION" ), wxT( "0" ) );
883 }
884 else if( rulekind == wxT( "SolderMaskExpansion" ) )
885 {
887 soldermaskExpansion = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "EXPANSION" ), wxT( "4mil" ) );
888 }
889 else if( rulekind == wxT( "PlaneClearance" ) )
890 {
892 planeclearanceClearance = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "CLEARANCE" ), wxT( "10mil" ) );
893 }
894 else if( rulekind == wxT( "PolygonConnect" ) )
895 {
897 polygonconnectAirgapwidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "AIRGAPWIDTH" ), wxT( "10mil" ) );
898 polygonconnectReliefconductorwidth = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "RELIEFCONDUCTORWIDTH" ), wxT( "10mil" ) );
899 polygonconnectReliefentries = ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "RELIEFENTRIES" ), 4 );
900
901 wxString style = ALTIUM_PROPS_UTILS::ReadString( props, wxT( "CONNECTSTYLE" ), wxT( "" ) );
902
903 if( style == wxT( "Direct" ) ) polygonconnectStyle = ALTIUM_CONNECT_STYLE::DIRECT;
904 else if( style == wxT( "Relief" ) ) polygonconnectStyle = ALTIUM_CONNECT_STYLE::RELIEF;
905 else if( style == wxT( "NoConnect" ) ) polygonconnectStyle = ALTIUM_CONNECT_STYLE::NONE;
907 }
908 else
909 {
911 }
912
913 if( aReader.HasParsingError() )
914 THROW_IO_ERROR( wxT( "Rules6 stream was not parsed correctly" ) );
915}
916
918{
919 std::map<wxString, wxString> props = aReader.ReadProperties();
920
921 if( props.empty() )
922 THROW_IO_ERROR( wxT( "SmartUnions stream has no props" ) );
923
924 unionindex = ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "UNIONINDEX" ), 0 );
925 is_tuning = ALTIUM_PROPS_UTILS::ReadBool( props, wxT( "TRACETUNINGVALID" ), false );
926
927 // A tuned differential pair names its pair here; single-track tuning leaves it empty.
928 is_diffpair = !ALTIUM_PROPS_UTILS::ReadString( props, wxT( "TUNEDOBJECTDIFFPAIR" ),
929 wxT( "" ) ).IsEmpty();
930
931 style = ALTIUM_PROPS_UTILS::ReadInt( props, wxT( "STYLE" ), 0 );
932 gap = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "GAP" ), wxT( "0mil" ) );
933 amplitude = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "AMPLITUDE" ), wxT( "0mil" ) );
934 minamplitude = ALTIUM_PROPS_UTILS::ReadKicadUnit( props, wxT( "MINAMPLITUDE" ), wxT( "0mil" ) );
935 mitterradiusratio = ALTIUM_PROPS_UTILS::ReadDouble( props, wxT( "MITTERRADIUSRATIO" ), 0.0 );
936 singleside = ALTIUM_PROPS_UTILS::ReadBool( props, wxT( "SINGLESIDE" ), false );
937
938 if( aReader.HasParsingError() )
939 THROW_IO_ERROR( wxT( "SmartUnions stream was not parsed correctly" ) );
940}
941
943{
944 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
945 if( recordtype != ALTIUM_RECORD::ARC )
946 {
947 THROW_IO_ERROR( wxT( "Arcs6 stream has invalid recordtype" ) );
948 }
949
950 // Subrecord 1
952
953 layer_v6 = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
954
955 uint8_t flags1 = aReader.Read<uint8_t>();
956 is_locked = ( flags1 & 0x04 ) == 0;
957 is_polygonoutline = ( flags1 & 0x02 ) != 0;
958
959 uint8_t flags2 = aReader.Read<uint8_t>();
960 is_keepout = flags2 == 2;
961
962 net = aReader.Read<uint16_t>();
963 polygon = aReader.Read<uint16_t>();
964 component = aReader.Read<uint16_t>();
965 aReader.Skip( 4 );
966 center = aReader.ReadVector2IPos();
967 radius = aReader.ReadKicadUnit();
968 startangle = aReader.Read<double>();
969 endangle = aReader.Read<double>();
970 width = aReader.ReadKicadUnit();
971 subpolyindex = aReader.Read<uint16_t>();
972
973 int remaining = aReader.GetRemainingSubrecordBytes();
974
975 if( remaining >= 9 )
976 {
977 aReader.Skip( 1 );
978 unionindex = aReader.Read<uint32_t>();
979 layer_v7 = static_cast<ALTIUM_LAYER>( aReader.Read<uint32_t>() );
980 }
981
982 if( remaining >= 10 )
983 keepoutrestrictions = aReader.Read<uint8_t>();
984 else
985 keepoutrestrictions = is_keepout ? 0x1F : 0;
986
988
989 aReader.SkipSubrecord();
990
991 if( aReader.HasParsingError() )
992 {
993 THROW_IO_ERROR( wxT( "Arcs6 stream was not parsed correctly" ) );
994 }
995}
996
998{
999 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
1000
1001 if( recordtype != ALTIUM_RECORD::MODEL )
1002 THROW_IO_ERROR( wxT( "ComponentsBodies6 stream has invalid recordtype" ) );
1003
1004 aReader.ReadAndSetSubrecordLength();
1005
1006 aReader.Skip( 7 );
1007 component = aReader.Read<uint16_t>();
1008 aReader.Skip( 9 );
1009
1010 std::map<wxString, wxString> properties = aReader.ReadProperties();
1011
1012 if( properties.empty() )
1013 THROW_IO_ERROR( wxT( "ComponentsBodies6 stream has no properties" ) );
1014
1015 modelName = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "MODEL.NAME" ), wxT( "" ) );
1016 modelId = ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "MODELID" ), wxT( "" ) );
1017 modelIsEmbedded = ALTIUM_PROPS_UTILS::ReadBool( properties, wxT( "MODEL.EMBED" ), false );
1018
1019 modelPosition.x = ALTIUM_PROPS_UTILS::ReadKicadUnit( properties, wxT( "MODEL.2D.X" ), wxT( "0mil" ) );
1020 modelPosition.y = -ALTIUM_PROPS_UTILS::ReadKicadUnit( properties, wxT( "MODEL.2D.Y" ), wxT( "0mil" ) );
1021 modelPosition.z = ALTIUM_PROPS_UTILS::ReadKicadUnit( properties, wxT( "MODEL.3D.DZ" ), wxT( "0mil" ) );
1022
1023 modelRotation.x = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "MODEL.3D.ROTX" ), 0. );
1024 modelRotation.y = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "MODEL.3D.ROTY" ), 0. );
1025 modelRotation.z = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "MODEL.3D.ROTZ" ), 0. );
1026
1027 rotation = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "MODEL.2D.ROTATION" ), 0. );
1028
1029 body_opacity_3d = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "BODYOPACITY3D" ), 1. );
1030 body_projection = ALTIUM_PROPS_UTILS::ReadInt( properties, wxT( "BODYPROJECTION" ), 0 );
1031
1032 aReader.SkipSubrecord();
1033
1034 if( aReader.HasParsingError() )
1035 THROW_IO_ERROR( wxT( "Components6 stream was not parsed correctly" ) );
1036}
1037
1039{
1040 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
1041
1042 if( recordtype != ALTIUM_RECORD::PAD )
1043 THROW_IO_ERROR( wxT( "Pads6 stream has invalid recordtype" ) );
1044
1045 // Subrecord 1
1046 size_t subrecord1 = aReader.ReadAndSetSubrecordLength();
1047
1048 if( subrecord1 == 0 )
1049 THROW_IO_ERROR( wxT( "Pads6 stream has no subrecord1 data" ) );
1050
1051 name = aReader.ReadWxString();
1052
1053 if( aReader.GetRemainingSubrecordBytes() != 0 )
1054 THROW_IO_ERROR( wxT( "Pads6 stream has invalid subrecord1 length" ) );
1055
1056 aReader.SkipSubrecord();
1057
1058 // Subrecord 2
1059 aReader.ReadAndSetSubrecordLength();
1060 aReader.SkipSubrecord();
1061
1062 // Subrecord 3
1063 aReader.ReadAndSetSubrecordLength();
1064 aReader.SkipSubrecord();
1065
1066 // Subrecord 4
1067 aReader.ReadAndSetSubrecordLength();
1068 aReader.SkipSubrecord();
1069
1070 // Subrecord 5
1071 size_t subrecord5 = aReader.ReadAndSetSubrecordLength();
1072
1073 ExpectSubrecordLengthAtLeast( "Pads6", "subrecord5", 110, subrecord5 );
1074
1075 layer_v6 = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
1078
1079 uint8_t flags1 = aReader.Read<uint8_t>();
1080 is_test_fab_top = ( flags1 & 0x80 ) != 0;
1081 is_tent_bottom = ( flags1 & 0x40 ) != 0;
1082 is_tent_top = ( flags1 & 0x20 ) != 0;
1083 is_locked = ( flags1 & 0x04 ) == 0;
1084
1085 uint8_t flags2 = aReader.Read<uint8_t>();
1086 is_test_fab_bottom = ( flags2 & 0x01 ) != 0;
1087
1088 net = aReader.Read<uint16_t>();
1089 aReader.Skip( 2 );
1090 component = aReader.Read<uint16_t>();
1091 aReader.Skip( 4 ); // to 13
1092
1093 position = aReader.ReadVector2IPos();
1094 topsize = aReader.ReadVector2ISize();
1095 midsize = aReader.ReadVector2ISize();
1096 botsize = aReader.ReadVector2ISize();
1097 holesize = aReader.ReadKicadUnit(); // to 49
1098
1099 topshape = static_cast<ALTIUM_PAD_SHAPE>( aReader.Read<uint8_t>() );
1100 midshape = static_cast<ALTIUM_PAD_SHAPE>( aReader.Read<uint8_t>() );
1101 botshape = static_cast<ALTIUM_PAD_SHAPE>( aReader.Read<uint8_t>() );
1102
1103 direction = aReader.Read<double>();
1104 plated = aReader.Read<uint8_t>() != 0;
1105 aReader.Skip( 1 );
1106 padmode = static_cast<ALTIUM_PAD_MODE>( aReader.Read<uint8_t>() );
1107 aReader.Skip( 23 );
1110 aReader.Skip( 7 );
1111 pastemaskexpansionmode = static_cast<ALTIUM_MODE>( aReader.Read<uint8_t>() );
1112 soldermaskexpansionmode = static_cast<ALTIUM_MODE>( aReader.Read<uint8_t>() );
1113 aReader.Skip( 3 ); // to 106
1114
1116 pad_to_die_delay = 0;
1117
1118 if( subrecord5 == 110 )
1119 {
1120 // Don't know exactly what this is, but it's always been 0 in the files with 110-byte subrecord5.
1121 // e.g. https://gitlab.com/kicad/code/kicad/-/issues/16514
1122 const uint32_t unknown = aReader.ReadKicadUnit(); // to 110
1123
1124 if( unknown != 0 )
1125 {
1126 THROW_IO_ERROR( wxString::Format( "Pads6 stream subrecord5 + 106 has value %d, which is unexpected",
1127 unknown ) );
1128 }
1129 holerotation = 0;
1130 }
1131 else
1132 {
1133 // More than 110, need at least 114
1134 ExpectSubrecordLengthAtLeast( "Pads6", "subrecord5", 114, subrecord5 );
1135 holerotation = aReader.Read<double>(); // to 114
1136 }
1137
1138 if( subrecord5 >= 120 )
1139 {
1140 tolayer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
1141 aReader.Skip( 2 );
1142 fromlayer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
1143 //aReader.skip( 2 );
1144 }
1145 else if( subrecord5 == 171 )
1146 {
1147 }
1148
1149 if( subrecord5 >= 202 )
1150 {
1151 aReader.Skip( 40 );
1152 pad_to_die_length = aReader.ReadKicadUnit();
1153 aReader.Skip( 32 );
1154 pad_to_die_delay = KiROUND( aReader.Read<double>() * 1e18 );
1155 }
1156
1157 aReader.SkipSubrecord();
1158
1159 // Subrecord 6
1160 size_t subrecord6 = aReader.ReadAndSetSubrecordLength();
1161 // Known lengths: 596, 628, 651
1162 // 596 is the number of bytes read in this code-block
1163 if( subrecord6 >= 596 )
1164 {
1165 sizeAndShape = std::make_unique<APAD6_SIZE_AND_SHAPE>();
1166
1167 for( wxSize& size : sizeAndShape->inner_size )
1168 size.x = aReader.ReadKicadUnitX();
1169
1170 for( wxSize& size : sizeAndShape->inner_size )
1171 size.y = aReader.ReadKicadUnitY();
1172
1173 for( ALTIUM_PAD_SHAPE& shape : sizeAndShape->inner_shape )
1174 shape = static_cast<ALTIUM_PAD_SHAPE>( aReader.Read<uint8_t>() );
1175
1176 aReader.Skip( 1 );
1177
1178 sizeAndShape->holeshape = static_cast<ALTIUM_PAD_HOLE_SHAPE>( aReader.Read<uint8_t>() );
1179 sizeAndShape->slotsize = aReader.ReadKicadUnit();
1180 sizeAndShape->slotrotation = aReader.Read<double>();
1181
1182 for( VECTOR2I& pt : sizeAndShape->holeoffset )
1183 pt.x = aReader.ReadKicadUnitX();
1184
1185 for( VECTOR2I& pt : sizeAndShape->holeoffset )
1186 pt.y = aReader.ReadKicadUnitY();
1187
1188 aReader.Skip( 1 );
1189
1190 for( ALTIUM_PAD_SHAPE_ALT& shape : sizeAndShape->alt_shape )
1191 shape = static_cast<ALTIUM_PAD_SHAPE_ALT>( aReader.Read<uint8_t>() );
1192
1193 for( uint8_t& radius : sizeAndShape->cornerradius )
1194 radius = aReader.Read<uint8_t>();
1195 }
1196 else if( subrecord6 != 0 )
1197 {
1198 wxLogError( _( "Pads6 stream has unexpected length for subrecord 6: %d." ), subrecord6 );
1199 }
1200
1202
1203 aReader.SkipSubrecord();
1204
1205 if( aReader.HasParsingError() )
1206 THROW_IO_ERROR( wxT( "Pads6 stream was not parsed correctly" ) );
1207}
1208
1210{
1211 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
1212
1213 if( recordtype != ALTIUM_RECORD::VIA )
1214 THROW_IO_ERROR( wxT( "Vias6 stream has invalid recordtype" ) );
1215
1216 // Subrecord 1
1217 size_t subrecord1 = aReader.ReadAndSetSubrecordLength();
1218
1219 aReader.Skip( 1 );
1220 uint8_t flags1 = aReader.Read<uint8_t>();
1221 is_test_fab_top = ( flags1 & 0x80 ) != 0;
1222 is_tent_bottom = ( flags1 & 0x40 ) != 0;
1223 is_tent_top = ( flags1 & 0x20 ) != 0;
1224 is_locked = ( flags1 & 0x04 ) == 0;
1225
1226 uint8_t flags2 = aReader.Read<uint8_t>();
1227 is_test_fab_bottom = ( flags2 & 0x01 ) != 0;
1228
1229 net = aReader.Read<uint16_t>();
1230 aReader.Skip( 8 );
1231 position = aReader.ReadVector2IPos();
1232 diameter = aReader.ReadKicadUnit();
1233 holesize = aReader.ReadKicadUnit();
1234
1235 layer_start = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
1236 layer_end = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
1237
1238 if( subrecord1 <= 74 )
1239 {
1241 }
1242 else
1243 {
1244 uint8_t temp_byte = aReader.Read<uint8_t>(); // Unknown.
1245
1247 thermal_relief_conductorcount = aReader.Read<uint8_t>();
1248 aReader.Skip( 1 ); // Unknown.
1249
1251
1252 aReader.ReadKicadUnit(); // Unknown. 20mil?
1253 aReader.ReadKicadUnit(); // Unknown. 20mil?
1254
1255 aReader.Skip( 4 );
1257
1258 // Records that don't carry an explicit back expansion mirror the front value.
1260
1261 aReader.Skip( 8 );
1262
1263 temp_byte = aReader.Read<uint8_t>();
1264 soldermask_expansion_manual = temp_byte & 0x02;
1265
1266 soldermask_expansion_from_hole = aReader.Read<uint8_t>() & 0x01;
1267
1268 aReader.Skip( 6 );
1269
1270 viamode = static_cast<ALTIUM_PAD_MODE>( aReader.Read<uint8_t>() );
1271
1272 for( int ii = 0; ii < 32; ++ii )
1273 {
1274 diameter_by_layer[ii] = aReader.ReadKicadUnit();
1275 }
1276 }
1277
1278 if( subrecord1 >= 246 )
1279 {
1280 aReader.Skip( 38 );
1281 soldermask_expansion_linked = aReader.Read<uint8_t>() & 0x01;
1283
1286 }
1287
1288 if( subrecord1 >= 307 )
1289 {
1290 aReader.Skip( 45 );
1291
1292 pos_tolerance = aReader.ReadKicadUnit();
1293 neg_tolerance = aReader.ReadKicadUnit();
1294 }
1295
1296 aReader.SkipSubrecord();
1297
1298 if( aReader.HasParsingError() )
1299 THROW_IO_ERROR( wxT( "Vias6 stream was not parsed correctly" ) );
1300}
1301
1303{
1304 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
1305
1306 if( recordtype != ALTIUM_RECORD::TRACK )
1307 THROW_IO_ERROR( wxT( "Tracks6 stream has invalid recordtype" ) );
1308
1309 // Subrecord 1
1310 aReader.ReadAndSetSubrecordLength();
1311
1312 layer_v6 = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
1313
1314 uint8_t flags1 = aReader.Read<uint8_t>();
1315 is_locked = ( flags1 & 0x04 ) == 0;
1316 is_polygonoutline = ( flags1 & 0x02 ) != 0;
1317
1318 uint8_t flags2 = aReader.Read<uint8_t>();
1319 is_keepout = flags2 == 2;
1320
1321 net = aReader.Read<uint16_t>();
1322 polygon = aReader.Read<uint16_t>();
1323 component = aReader.Read<uint16_t>();
1324 aReader.Skip( 4 );
1325 start = aReader.ReadVector2IPos();
1326 end = aReader.ReadVector2IPos();
1327 width = aReader.ReadKicadUnit();
1328 subpolyindex = aReader.Read<uint16_t>();
1329 aReader.Skip( 1 );
1330
1331 int remaining = aReader.GetRemainingSubrecordBytes();
1332
1333 if( remaining >= 9 )
1334 {
1335 unionindex = aReader.Read<uint32_t>();
1336 aReader.Skip( 1 );
1337 layer_v7 = static_cast<ALTIUM_LAYER>( aReader.Read<uint32_t>() );
1338 }
1339
1340 if( remaining >= 10 )
1341 keepoutrestrictions = aReader.Read<uint8_t>();
1342 else
1343 keepoutrestrictions = is_keepout ? 0x1F : 0;
1344
1346
1347 aReader.SkipSubrecord();
1348
1349 if( aReader.HasParsingError() )
1350 THROW_IO_ERROR( wxT( "Tracks6 stream was not parsed correctly" ) );
1351}
1352
1353ATEXT6::ATEXT6( ALTIUM_BINARY_PARSER& aReader, std::map<uint32_t, wxString>& aStringTable )
1354{
1355 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
1356
1357 if( recordtype != ALTIUM_RECORD::TEXT )
1358 THROW_IO_ERROR( wxT( "Texts6 stream has invalid recordtype" ) );
1359
1360 // Subrecord 1 - Properties
1361 size_t subrecord1 = aReader.ReadAndSetSubrecordLength();
1362
1363 layer_v6 = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
1364 aReader.Skip( 6 );
1365 component = aReader.Read<uint16_t>();
1366 aReader.Skip( 4 );
1367 position = aReader.ReadVector2IPos();
1368 height = aReader.ReadKicadUnit();
1369 strokefonttype = static_cast<STROKE_FONT_TYPE>( aReader.Read<uint16_t>() );
1370 // TODO: The Serif font type doesn't match well with KiCad, we should replace it with a better match
1371
1372 rotation = aReader.Read<double>();
1373 isMirrored = aReader.Read<uint8_t>() != 0;
1374 strokewidth = aReader.ReadKicadUnit();
1375
1376 if( subrecord1 < 123 )
1377 {
1379 aReader.SkipSubrecord();
1380 return;
1381 }
1382
1383 isComment = aReader.Read<uint8_t>() != 0;
1384 isDesignator = aReader.Read<uint8_t>() != 0;
1385 aReader.Skip( 1 );
1386 fonttype = static_cast<ALTIUM_TEXT_TYPE>( aReader.Read<uint8_t>() );
1387 isBold = aReader.Read<uint8_t>() != 0;
1388 isItalic = aReader.Read<uint8_t>() != 0;
1389
1390 char fontData[64] = { 0 };
1391 aReader.ReadBytes( fontData, sizeof( fontData ) );
1392 fontname = wxString( fontData, wxMBConvUTF16LE(), sizeof( fontData ) ).BeforeFirst( '\0' );
1393
1394 char tmpbyte = aReader.Read<uint8_t>();
1395 isInverted = !!tmpbyte;
1396 margin_border_width = aReader.ReadKicadUnit(); // "Margin Border"
1397 widestring_index = aReader.Read<uint32_t>();
1398 aReader.Skip( 4 );
1399
1400 // An inverted rect in Altium is like a text box with the text inverted.
1401 isInvertedRect = aReader.Read<uint8_t>() != 0;
1402
1405 textbox_rect_justification = static_cast<ALTIUM_TEXT_POSITION>( aReader.Read<uint8_t>() );
1406 text_offset_width = aReader.ReadKicadUnit(); // "Text Offset"
1407
1408 int remaining = aReader.GetRemainingSubrecordBytes();
1409
1410 if( remaining >= 93 )
1411 {
1412 VECTOR2I unk_vec = aReader.ReadVector2ISize();
1413 wxLogTrace( traceAltiumImport, " Unk vec: %d, %d\n", unk_vec.x, unk_vec.y );
1414
1415 barcode_margin = aReader.ReadVector2ISize();
1416
1417 int32_t unk32 = aReader.ReadKicadUnit();
1418 wxLogTrace( traceAltiumImport, " Unk32: %d\n", unk32 );
1419
1420 barcode_type = static_cast<ALTIUM_BARCODE_TYPE>( aReader.Read<uint8_t>() );
1421 uint8_t unk8 = aReader.Read<uint8_t>();
1422 wxLogTrace( traceAltiumImport, " Unk8: %u\n", unk8 );
1423
1424 barcode_inverted = aReader.Read<uint8_t>() != 0;
1425 fonttype = static_cast<ALTIUM_TEXT_TYPE>( aReader.Read<uint8_t>() );
1426
1427 aReader.ReadBytes( fontData, sizeof( fontData ) );
1428 barcode_fontname = wxString( fontData, wxMBConvUTF16LE(), sizeof( fontData ) ).BeforeFirst( '\0' );
1429
1430 aReader.Read<uint8_t>();
1431 wxLogTrace( traceAltiumImport, " Unk8_2: %u\n", unk8 );
1432
1433 layer_v7 = static_cast<ALTIUM_LAYER>( aReader.Read<uint32_t>() );
1434 }
1435
1436 if( remaining >= 103 )
1437 {
1438 // "Frame" text type flag
1439 isFrame = aReader.Read<uint8_t>() != 0;
1440
1441 // Use "Offset" border value instead of "Margin"
1442 isOffsetBorder = aReader.Read<uint8_t>() != 0;
1443
1444 for( size_t ii = 0; ii < 8; ++ii )
1445 {
1446 uint8_t temp = aReader.Peek<uint8_t>();
1447 uint32_t temp32 = ii < 3 ? ALTIUM_PROPS_UTILS::ConvertToKicadUnit( aReader.Peek<uint32_t>() ) : 0;
1448 wxLogTrace( traceAltiumImport, "3ATEXT6 %zu:\t Byte:%u, Kicad:%u\n", ii, temp, temp32 );
1449 aReader.Skip( 1 );
1450 }
1451 }
1452 else
1453 {
1455 isOffsetBorder = false;
1456 }
1457
1458 if( remaining >= 115 )
1459 {
1460 // textbox_rect_justification will be wrong (5) when this flag is unset,
1461 // in that case, we should always use the left bottom justification.
1462 isJustificationValid = aReader.Read<uint8_t>() != 0;
1463 }
1464 else
1465 {
1466 isJustificationValid = false;
1467 }
1468
1469 aReader.SkipSubrecord();
1470
1471 // Subrecord 2 - Legacy 8bit string, max 255 chars, unknown codepage
1472 aReader.ReadAndSetSubrecordLength();
1473
1474 auto entry = aStringTable.find( widestring_index );
1475
1476 if( entry != aStringTable.end() )
1477 text = entry->second;
1478 else
1479 text = aReader.ReadWxString();
1480
1481 // Normalize Windows line endings
1482 text.Replace( wxT( "\r\n" ), wxT( "\n" ) );
1483
1484 aReader.SkipSubrecord();
1485
1486 // Altium only supports inverting truetype fonts
1488 {
1489 isInverted = false;
1490 isInvertedRect = false;
1491 }
1492
1494
1495 if( aReader.HasParsingError() )
1496 THROW_IO_ERROR( wxT( "Texts6 stream was not parsed correctly" ) );
1497}
1498
1500{
1501 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
1502
1503 if( recordtype != ALTIUM_RECORD::FILL )
1504 THROW_IO_ERROR( wxT( "Fills6 stream has invalid recordtype" ) );
1505
1506 // Subrecord 1
1507 aReader.ReadAndSetSubrecordLength();
1508
1509 layer_v6 = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
1510
1511 uint8_t flags1 = aReader.Read<uint8_t>();
1512 is_locked = ( flags1 & 0x04 ) == 0;
1513
1514 uint8_t flags2 = aReader.Read<uint8_t>();
1515 is_keepout = flags2 == 2;
1516
1517 net = aReader.Read<uint16_t>();
1518 aReader.Skip( 2 );
1519 component = aReader.Read<uint16_t>();
1520 aReader.Skip( 4 );
1521 pos1 = aReader.ReadVector2IPos();
1522 pos2 = aReader.ReadVector2IPos();
1523 rotation = aReader.Read<double>();
1524
1525 int remaining = aReader.GetRemainingSubrecordBytes();
1526
1527 if( remaining >= 9 )
1528 {
1529 aReader.Skip( 5 );
1530 layer_v7 = static_cast<ALTIUM_LAYER>( aReader.Read<uint32_t>() );
1531 }
1532
1533 if( remaining >= 10 )
1534 keepoutrestrictions = aReader.Read<uint8_t>();
1535 else
1536 keepoutrestrictions = is_keepout ? 0x1F : 0;
1537
1539
1540 aReader.SkipSubrecord();
1541
1542 if( aReader.HasParsingError() )
1543 THROW_IO_ERROR( wxT( "Fills6 stream was not parsed correctly" ) );
1544}
1545
1546AREGION6::AREGION6( ALTIUM_BINARY_PARSER& aReader, bool aExtendedVertices )
1547{
1548 ALTIUM_RECORD recordtype = static_cast<ALTIUM_RECORD>( aReader.Read<uint8_t>() );
1549
1550 if( recordtype != ALTIUM_RECORD::REGION )
1551 THROW_IO_ERROR( wxT( "Regions6 stream has invalid recordtype" ) );
1552
1553 // Subrecord 1
1554 aReader.ReadAndSetSubrecordLength();
1555
1556 layer_v6 = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
1557
1558 uint8_t flags1 = aReader.Read<uint8_t>();
1559 is_locked = ( flags1 & 0x04 ) == 0;
1560 is_teardrop = ( flags1 & 0x10 ) != 0;
1561
1562 uint8_t flags2 = aReader.Read<uint8_t>();
1563 is_keepout = flags2 == 2;
1564
1565 net = aReader.Read<uint16_t>();
1566 polygon = aReader.Read<uint16_t>();
1567 component = aReader.Read<uint16_t>();
1568 aReader.Skip( 5 );
1569 holecount = aReader.Read<uint16_t>();
1570 aReader.Skip( 2 );
1571
1572 std::map<wxString, wxString> properties = aReader.ReadProperties();
1573
1574 if( properties.empty() )
1575 THROW_IO_ERROR( wxT( "Regions6 stream has empty properties" ) );
1576
1577 layer_v7 = altium_layer_from_name( ALTIUM_PROPS_UTILS::ReadString( properties, wxT( "V7_LAYER" ), "" ) );
1578
1579 int pkind = ALTIUM_PROPS_UTILS::ReadInt( properties, wxT( "KIND" ), 0 );
1580 bool is_cutout = ALTIUM_PROPS_UTILS::ReadBool( properties, wxT( "ISBOARDCUTOUT" ), false );
1581
1582 is_shapebased = ALTIUM_PROPS_UTILS::ReadBool( properties, wxT( "ISSHAPEBASED" ), false );
1583 keepoutrestrictions = static_cast<uint8_t>(
1584 ALTIUM_PROPS_UTILS::ReadInt( properties, wxT( "KEEPOUTRESTRIC" ), 0x1F ) );
1585
1586 // TODO: this can differ from the other subpolyindex?!
1587 // Note: "the other subpolyindex" is "polygon"
1588 subpolyindex = static_cast<uint16_t>(
1589 ALTIUM_PROPS_UTILS::ReadInt( properties, "SUBPOLYINDEX", ALTIUM_POLYGON_NONE ) );
1590
1591 switch( pkind )
1592 {
1593 case 0:
1594 if( is_cutout )
1595 {
1597 }
1598 else
1599 {
1601 }
1602
1603 break;
1604
1605 case 1:
1607 break;
1608
1609 case 2:
1611 break;
1612
1613 case 3:
1614 kind = ALTIUM_REGION_KIND::UNKNOWN_3; // TODO: what kind is this?
1615 break;
1616
1617 case 4:
1619 break;
1620
1621 default:
1623 break;
1624 }
1625
1626 uint32_t num_outline_vertices = aReader.Read<uint32_t>();
1627
1628 if( aExtendedVertices )
1629 num_outline_vertices++; // Has a closing vertex
1630
1631 for( uint32_t i = 0; i < num_outline_vertices; i++ )
1632 {
1633 if( aExtendedVertices )
1634 {
1635 bool isRound = aReader.Read<uint8_t>() != 0;
1636 VECTOR2I position = aReader.ReadVector2IPos();
1637 VECTOR2I center = aReader.ReadVector2IPos();
1638 int32_t radius = aReader.ReadKicadUnit();
1639 double angle1 = aReader.Read<double>();
1640 double angle2 = aReader.Read<double>();
1641 outline.emplace_back( isRound, radius, angle1, angle2, position, center );
1642 }
1643 else
1644 {
1645 // For some regions the coordinates are stored as double and not as int32_t
1646 int32_t x = ALTIUM_PROPS_UTILS::ConvertToKicadUnit( aReader.Read<double>() );
1647 int32_t y = ALTIUM_PROPS_UTILS::ConvertToKicadUnit( -aReader.Read<double>() );
1648 outline.emplace_back( VECTOR2I( x, y ) );
1649 }
1650 }
1651
1652 holes.resize( holecount );
1653 for( uint16_t k = 0; k < holecount; k++ )
1654 {
1655 uint32_t num_hole_vertices = aReader.Read<uint32_t>();
1656 holes.at( k ).reserve( num_hole_vertices );
1657
1658 for( uint32_t i = 0; i < num_hole_vertices; i++ )
1659 {
1660 int32_t x = ALTIUM_PROPS_UTILS::ConvertToKicadUnit( aReader.Read<double>() );
1661 int32_t y = ALTIUM_PROPS_UTILS::ConvertToKicadUnit( -aReader.Read<double>() );
1662 holes.at( k ).emplace_back( VECTOR2I( x, y ) );
1663 }
1664 }
1665
1667
1668 aReader.SkipSubrecord();
1669
1670 if( aReader.HasParsingError() )
1671 THROW_IO_ERROR( wxT( "Regions6 stream was not parsed correctly" ) );
1672}
bool altiumScopeExprMatchesPolygon(const wxString &aExpr)
Return true if an Altium rule scope expression targets polygon pour primitives (matches InPolygon,...
void altium_parse_polygons(std::map< wxString, wxString > &aProps, std::vector< ALTIUM_VERTICE > &aVertices)
ALTIUM_MECHKIND altium_mechkind_from_name(const wxString &aName)
static std::map< wxString, double > ReadAltiumDielectricLossTangents(const std::map< wxString, wxString > &aProps)
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 wxString MakeAltiumDielectricKey(const wxString &aMaterial, int32_t aHeight, double aConst)
static AEXTENDED_PRIMITIVE_INFORMATION_TYPE ReadAltiumExtendedPrimitiveInformationTypeFromProperties(const std::map< wxString, wxString > &aProps, wxString aKey)
ALTIUM_LAYER altium_versioned_layer(ALTIUM_LAYER aV6Layer, ALTIUM_LAYER aV7Layer)
const ARULE6 * selectAltiumPolygonRule(const std::vector< ARULE6 > &aRulesByPriorityAsc)
Select the highest Altium-priority rule whose scope references polygons.
static ALTIUM_MODE ReadAltiumModeFromProperties(const std::map< wxString, wxString > &aProps, wxString aKey)
static std::vector< ABOARD6_LAYER_STACKUP > ReadAltiumStackupFromProperties(const std::map< wxString, wxString > &aProps)
static ALTIUM_RECORD ReadAltiumRecordFromProperties(const std::map< wxString, wxString > &aProps, wxString aKey)
bool altiumViaSideIsTented(bool aTentFlag, bool aManual, bool aFromHole, uint32_t aHoleSize, int32_t aMaskExpansion, int aLandDiameter)
Decide whether one side of an Altium via should be tented when imported into KiCad.
ALTIUM_PAD_SHAPE_ALT
ALTIUM_TEXT_POSITION
ALTIUM_MECHKIND
ALTIUM_PAD_MODE
ALTIUM_TEXT_TYPE
ALTIUM_PAD_SHAPE
ALTIUM_BARCODE_TYPE
ALTIUM_DIMENSION_KIND
ALTIUM_PAD_HOLE_SHAPE
const uint16_t ALTIUM_NET_UNCONNECTED
ALTIUM_CLASS_KIND
const uint16_t ALTIUM_POLYGON_NONE
AEXTENDED_PRIMITIVE_INFORMATION_TYPE
ALTIUM_RECORD
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:986
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)
#define _(s)
static const wxChar * traceAltiumImport
Flag to enable Altium importer logging.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
double startangle
uint16_t component
uint32_t unionindex
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
ALTIUM_LAYER layer_v6
ALTIUM_LAYER layer_v7
bool is_polygonoutline
double endangle
uint16_t subpolyindex
ABOARD6_LAYER_STACKUP(const std::map< wxString, wxString > &aProps, const wxString &aPrefix, uint32_t aLayerIdFallback)
VECTOR2I sheetpos
std::set< wxString > layerNames
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)
wxString sourceHierachicalPath
ALTIUM_TEXT_POSITION commentautoposition
ALTIUM_TEXT_POSITION nameautoposition
ACOMPONENT6(ALTIUM_BINARY_PARSER &aReader)
wxString sourcefootprintlibrary
ALTIUM_LAYER layer
wxString sourcelibreference
wxString sourcedesignator
wxString sourceUniqueID
wxString sourcecomponentlibrary
ACOMPONENTBODY6(ALTIUM_BINARY_PARSER &aReader)
ALTIUM_UNIT textunit
uint32_t textlinewidth
ALTIUM_LAYER layer
ALTIUM_LAYER layer_v6
std::vector< VECTOR2I > textPoint
ALTIUM_DIMENSION_KIND kind
ALTIUM_LAYER layer_v7
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)
ALTIUM_LAYER layer_v6
uint16_t component
ALTIUM_LAYER layer_v7
std::set< wxString > layerNames
std::vector< ABOARD6_LAYER_STACKUP > stackup
ALIBRARY(ALTIUM_BINARY_PARSER &aReader)
double z_offset
int32_t checksum
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 layer_v7
ALTIUM_LAYER tolayer
ALTIUM_PAD_SHAPE topshape
ALTIUM_LAYER layer_v6
ALTIUM_PAD_MODE padmode
ALTIUM_MODE pastemaskexpansionmode
uint32_t holesize
double direction
ALTIUM_MODE soldermaskexpansionmode
wxString name
bool is_test_fab_bottom
int32_t pad_to_die_delay
bool is_tent_bottom
VECTOR2I botsize
ALTIUM_PAD_SHAPE botshape
uint16_t component
VECTOR2I midsize
ALTIUM_PAD_SHAPE midshape
int32_t pastemaskexpansionmanual
ALTIUM_LAYER fromlayer
VECTOR2I position
VECTOR2I topsize
bool is_test_fab_top
int32_t pad_to_die_length
ALTIUM_LAYER layer_v6
int32_t minprimlength
std::vector< ALTIUM_VERTICE > vertices
APOLYGON6(ALTIUM_BINARY_PARSER &aReader)
ALTIUM_LAYER layer_v7
ALTIUM_POLYGON_HATCHSTYLE hatchstyle
ALTIUM_LAYER layer
uint8_t keepoutrestrictions
ALTIUM_LAYER layer
AREGION6(ALTIUM_BINARY_PARSER &aReader, bool aExtendedVertices)
ALTIUM_LAYER layer_v7
uint16_t holecount
ALTIUM_LAYER layer_v6
std::vector< ALTIUM_VERTICE > outline
uint16_t subpolyindex
std::vector< std::vector< ALTIUM_VERTICE > > holes
uint16_t component
uint16_t polygon
ALTIUM_REGION_KIND kind
ALTIUM_RULE_KIND kind
ALTIUM_CONNECT_STYLE polygonconnectStyle
wxString scope1expr
wxString name
int planeclearanceClearance
int32_t polygonconnectReliefconductorwidth
int pastemaskExpansion
ARULE6()=default
wxString scope2expr
int soldermaskExpansion
int32_t polygonconnectAirgapwidth
int polygonconnectReliefentries
ASMARTUNION6(ALTIUM_BINARY_PARSER &aReader)
uint32_t text_offset_width
VECTOR2I barcode_margin
uint32_t textbox_rect_height
uint16_t component
ALTIUM_LAYER layer_v6
ALTIUM_TEXT_POSITION textbox_rect_justification
bool isInvertedRect
wxString text
uint32_t widestring_index
uint32_t textbox_rect_width
double rotation
uint32_t margin_border_width
uint32_t height
wxString fontname
bool isJustificationValid
ALTIUM_BARCODE_TYPE barcode_type
ALTIUM_LAYER layer
VECTOR2I position
ALTIUM_LAYER layer_v7
ALTIUM_TEXT_TYPE fonttype
STROKE_FONT_TYPE strokefonttype
wxString barcode_fontname
bool isOffsetBorder
ATEXT6(ALTIUM_BINARY_PARSER &aReader, std::map< uint32_t, wxString > &aStringTable)
bool barcode_inverted
uint32_t strokewidth
ALTIUM_LAYER layer_v6
uint32_t unionindex
ATRACK6(ALTIUM_BINARY_PARSER &aReader)
uint32_t width
bool is_polygonoutline
ALTIUM_LAYER layer_v7
uint16_t polygon
uint16_t subpolyindex
uint8_t keepoutrestrictions
VECTOR2I start
ALTIUM_LAYER layer
uint16_t component
bool soldermask_expansion_linked
uint32_t thermal_relief_conductorcount
uint32_t diameter
uint32_t neg_tolerance
uint16_t net
VECTOR2I position
int32_t thermal_relief_airgap
bool is_test_fab_top
bool soldermask_expansion_from_hole
int32_t soldermask_expansion_front
uint32_t pos_tolerance
bool is_tent_bottom
bool is_test_fab_bottom
bool soldermask_expansion_manual
ALTIUM_PAD_MODE viamode
AVIA6(ALTIUM_BINARY_PARSER &aReader)
uint32_t thermal_relief_conductorwidth
int32_t soldermask_expansion_back
uint32_t diameter_by_layer[32]
ALTIUM_LAYER layer_start
ALTIUM_LAYER layer_end
uint32_t holesize
VECTOR2I center
int radius
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683