KiCad PCB EDA Suite
altium_parser_sch.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 <thomas.pointhuber@gmx.at>
5  * Copyright (C) 2021 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 <iostream>
26 #include <unordered_map>
27 
28 #include <convert_to_biu.h>
29 #include <ki_exception.h>
30 
31 #include <wx/log.h>
32 
35 
36 
37 ALTIUM_SCH_RECORD ReadRecord( const std::map<wxString, wxString>& aProps )
38 {
39  int recordId = ALTIUM_PARSER::ReadInt( aProps, "RECORD", 0 );
40  return static_cast<ALTIUM_SCH_RECORD>( recordId );
41 }
42 
43 
44 constexpr int Altium2KiCadUnit( const int val, const int frac )
45 {
46  return Mils2iu( val ) * 10 + Mils2iu( frac ) / 10000; // TODO: correct, rounding issues?
47 }
48 
49 
50 int ReadKiCadUnitFrac( const std::map<wxString, wxString>& aProps, const wxString& aKey )
51 {
52  // a unit is stored using two fields, denoting the size in mils and a fraction size
53  int key = ALTIUM_PARSER::ReadInt( aProps, aKey, 0 );
54  int keyFrac = ALTIUM_PARSER::ReadInt( aProps, aKey + "_FRAC", 0 );
55  return Altium2KiCadUnit( key, keyFrac );
56 }
57 
58 
59 int ReadKiCadUnitFrac1( const std::map<wxString, wxString>& aProps, const wxString& aKey )
60 {
61  // a unit is stored using two fields, denoting the size in mils and a fraction size
62  // Dunno why Altium invents different units for the same purpose
63  int key = ALTIUM_PARSER::ReadInt( aProps, aKey, 0 );
64  int keyFrac = ALTIUM_PARSER::ReadInt( aProps, aKey + "_FRAC1", 0 );
65  return Altium2KiCadUnit( key * 10, keyFrac );
66 }
67 
68 
69 int ReadOwnerIndex( const std::map<wxString, wxString>& aProperties )
70 {
71  return ALTIUM_PARSER::ReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE );
72 }
73 
74 
75 int ReadOwnerPartId( const std::map<wxString, wxString>& aProperties )
76 {
77  return ALTIUM_PARSER::ReadInt( aProperties, "OWNERPARTID", ALTIUM_COMPONENT_NONE );
78 }
79 
80 
81 template <typename T>
82 T ReadEnum( const std::map<wxString, wxString>& aProps, const wxString& aKey, int aLower,
83  int aUpper, T aDefault )
84 {
85  int value = ALTIUM_PARSER::ReadInt( aProps, aKey, static_cast<int>( aDefault ));
86 
87  if( value < aLower || value > aUpper )
88  return aDefault;
89  else
90  return static_cast<T>( value );
91 }
92 
93 
95 {
96  aReader.Skip( 5 );
97  filename = aReader.ReadWxString();
98  uint32_t dataSize = aReader.Read<uint32_t>();
99  data = aReader.ReadVector( dataSize );
100 
101  if( aReader.HasParsingError() )
102  THROW_IO_ERROR( "Storage stream was not parsed correctly" );
103 }
104 
105 
106 ASCH_SYMBOL::ASCH_SYMBOL( const std::map<wxString, wxString>& aProps )
107 {
108  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::COMPONENT );
109 
110  currentpartid = ALTIUM_PARSER::ReadInt( aProps, "CURRENTPARTID", ALTIUM_COMPONENT_NONE );
111  libreference = ALTIUM_PARSER::ReadString( aProps, "LIBREFERENCE", "" );
112  sourcelibraryname = ALTIUM_PARSER::ReadString( aProps, "SOURCELIBRARYNAME", "" );
113  componentdescription = ALTIUM_PARSER::ReadString( aProps, "COMPONENTDESCRIPTION", "" );
114 
115  orientation = ALTIUM_PARSER::ReadInt( aProps, "ORIENTATION", 0 );
116  isMirrored = ALTIUM_PARSER::ReadBool( aProps, "ISMIRRORED", false );
117  location = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
118  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
119 
120  partcount = ALTIUM_PARSER::ReadInt( aProps, "PARTCOUNT", 0 );
121  displaymodecount = ALTIUM_PARSER::ReadInt( aProps, "DISPLAYMODECOUNT", 0 );
122  displaymode = ALTIUM_PARSER::ReadInt( aProps, "DISPLAYMODE", 0 );
123 }
124 
125 
126 ASCH_PIN::ASCH_PIN( const std::map<wxString, wxString>& aProps )
127 {
128  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PIN );
129 
130  ownerindex = ReadOwnerIndex( aProps );
131  ownerpartid = ReadOwnerPartId( aProps );
132  ownerpartdisplaymode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
133 
134  name = ALTIUM_PARSER::ReadString( aProps, "NAME", "" );
135  text = ALTIUM_PARSER::ReadString( aProps, "TEXT", "" );
136  designator = ALTIUM_PARSER::ReadString( aProps, "DESIGNATOR", "" );
137 
138  int symbolOuterInt = ALTIUM_PARSER::ReadInt( aProps, "SYMBOL_OUTER", 0 );
139  symbolOuter = static_cast<ASCH_PIN_SYMBOL_OUTER>( symbolOuterInt );
140 
141  int symbolInnerInt = ALTIUM_PARSER::ReadInt( aProps, "SYMBOL_INNER", 0 );
142  symbolInner = static_cast<ASCH_PIN_SYMBOL_INNER>( symbolInnerInt );
143 
144  int symbolOuterEdgeInt = ALTIUM_PARSER::ReadInt( aProps, "SYMBOL_OUTEREDGE", 0 );
145  symbolOuterEdge = ( symbolOuterEdgeInt == 0 || symbolOuterEdgeInt == 1
146  || symbolOuterEdgeInt == 4 || symbolOuterEdgeInt == 17 ) ?
147  static_cast<ASCH_PIN_SYMBOL_OUTEREDGE>( symbolOuterEdgeInt ) :
149 
150  int symbolInnerEdgeInt = ALTIUM_PARSER::ReadInt( aProps, "SYMBOL_INNEREDGE", 0 );
151  symbolInnerEdge = ( symbolInnerEdgeInt == 0 || symbolInnerEdgeInt == 3 ) ?
152  static_cast<ASCH_PIN_SYMBOL_INNEREDGE>( symbolInnerEdgeInt ) :
154  electrical = ReadEnum<ASCH_PIN_ELECTRICAL>( aProps, "ELECTRICAL", 0, 7,
156 
157  int pinconglomerate = ALTIUM_PARSER::ReadInt( aProps, "PINCONGLOMERATE", 0 );
158 
159  orientation = static_cast<ASCH_RECORD_ORIENTATION>( pinconglomerate & 0x03 );
160  showPinName = ( pinconglomerate & 0x08 ) != 0;
161  showDesignator = ( pinconglomerate & 0x10 ) != 0;
162 
163  int x = ALTIUM_PARSER::ReadInt( aProps, "LOCATION.X", 0 );
164  int xfrac = ALTIUM_PARSER::ReadInt( aProps, "LOCATION.X_FRAC", 0 );
165  int y = ALTIUM_PARSER::ReadInt( aProps, "LOCATION.Y", 0 );
166  int yfrac = ALTIUM_PARSER::ReadInt( aProps, "LOCATION.Y_FRAC", 0 );
167  location = wxPoint( Altium2KiCadUnit( x, xfrac ), -Altium2KiCadUnit( y, yfrac ) );
168 
169  int p = ALTIUM_PARSER::ReadInt( aProps, "PINLENGTH", 0 );
170  int pfrac = ALTIUM_PARSER::ReadInt( aProps, "PINLENGTH_FRAC", 0 );
171  pinlength = Altium2KiCadUnit( p, pfrac );
172 
173  // this code calculates the location as required by KiCad without rounding error attached
174  int kicadX = x;
175  int kicadXfrac = xfrac;
176  int kicadY = y;
177  int kicadYfrac = yfrac;
178 
179  switch( orientation )
180  {
182  kicadX += p;
183  kicadXfrac += pfrac;
184  break;
186  kicadY += p;
187  kicadYfrac += pfrac;
188  break;
190  kicadX -= p;
191  kicadXfrac -= pfrac;
192  break;
194  kicadY -= p;
195  kicadYfrac -= pfrac;
196  break;
197  default:
198  wxLogWarning( "Pin has unexpected orientation" );
199  break;
200  }
201 
202  kicadLocation = wxPoint( Altium2KiCadUnit( kicadX, kicadXfrac ),
203  -Altium2KiCadUnit( kicadY, kicadYfrac ) );
204 }
205 
206 
207 ASCH_LABEL::ASCH_LABEL( const std::map<wxString, wxString>& aProps )
208 {
209  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::LABEL );
210 
211  ownerindex = ReadOwnerIndex( aProps );
212  ownerpartid = ReadOwnerPartId( aProps );
213 
214  location = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
215  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
216 
217  text = ALTIUM_PARSER::ReadString( aProps, "TEXT", "" );
218 
219  fontId = ALTIUM_PARSER::ReadInt( aProps, "FONTID", 0 );
220  isMirrored = ALTIUM_PARSER::ReadBool( aProps, "ISMIRRORED", false );
221 
222  justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps, "JUSTIFICATION", 0, 8,
224 
225  orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps, "ORIENTATION", 0, 3,
227 }
228 
229 
230 ASCH_TEXT_FRAME::ASCH_TEXT_FRAME( const std::map<wxString, wxString>& aProps )
231 {
232  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NOTE
233  || ReadRecord( aProps ) == ALTIUM_SCH_RECORD::TEXT_FRAME );
234 
235  location = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
236  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
237  size = wxSize( ReadKiCadUnitFrac( aProps, "CORNER.X" ) - location.x,
238  -ReadKiCadUnitFrac( aProps, "CORNER.Y" ) - location.y );
239 
240  text = ALTIUM_PARSER::ReadString( aProps, "TEXT", "" );
241  text.Replace( "~1", "\n", true );
242 
243  fontId = ALTIUM_PARSER::ReadInt( aProps, "FONTID", 0 );
244  isWordWrapped = ALTIUM_PARSER::ReadBool( aProps, "WORDWRAP", false );
245  border = ALTIUM_PARSER::ReadBool( aProps, "SHOWBORDER", false );
246  textMargin = ReadKiCadUnitFrac( aProps, "TEXTMARGIN" );
247  areaColor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR", 0 );
248 
249  alignment = ReadEnum<ASCH_TEXT_FRAME_ALIGNMENT>( aProps, "ALIGNMENT", 1, 3,
251 }
252 
253 
254 ASCH_NOTE::ASCH_NOTE( const std::map<wxString, wxString>& aProperties ) :
255  ASCH_TEXT_FRAME( aProperties )
256 {
257  wxASSERT( ReadRecord( aProperties ) == ALTIUM_SCH_RECORD::NOTE );
258 
259  author = ALTIUM_PARSER::ReadString( aProperties, "AUTHOR", "" );
260 }
261 
262 
263 ASCH_BEZIER::ASCH_BEZIER( const std::map<wxString, wxString>& aProps )
264 {
265  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BEZIER );
266 
267  ownerindex = ReadOwnerIndex( aProps );
268  ownerpartid = ReadOwnerPartId( aProps );
269  ownerpartdisplaymode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
270 
271  int locationCount = ALTIUM_PARSER::ReadInt( aProps, "LOCATIONCOUNT", 0 );
272 
273  for( int i = 1; i <= locationCount; i++ )
274  {
275  const wxString si = std::to_string( i );
276  points.emplace_back( ReadKiCadUnitFrac( aProps, "X" + si ),
277  -ReadKiCadUnitFrac( aProps, "Y" + si ) );
278  }
279 
280  lineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
281 }
282 
283 
284 ASCH_POLYLINE::ASCH_POLYLINE( const std::map<wxString, wxString>& aProps )
285 {
286  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POLYLINE );
287 
288  ownerindex = ReadOwnerIndex( aProps );
289  ownerpartid = ReadOwnerPartId( aProps );
290  ownerpartdisplaymode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
291 
292  int locationCount = ALTIUM_PARSER::ReadInt( aProps, "LOCATIONCOUNT", 0 );
293 
294  for( int i = 1; i <= locationCount; i++ )
295  {
296  const wxString si = std::to_string( i );
297  points.emplace_back( ReadKiCadUnitFrac( aProps, "X" + si ),
298  -ReadKiCadUnitFrac( aProps, "Y" + si ) );
299  }
300 
301  lineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
302 
303  int linestyleVar = ALTIUM_PARSER::ReadInt( aProps, "LINESTYLEEXT", 0 );
304  linestyleVar = ALTIUM_PARSER::ReadInt( aProps, "LINESTYLE", linestyleVar ); // overwrite if present
305  linestyle = linestyleVar >= 0 && linestyleVar <= 3 ?
306  static_cast<ASCH_POLYLINE_LINESTYLE>( linestyleVar ) :
308 }
309 
310 
311 ASCH_POLYGON::ASCH_POLYGON( const std::map<wxString, wxString>& aProps )
312 {
313  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POLYGON );
314 
315  ownerindex = ReadOwnerIndex( aProps );
316  ownerpartid = ReadOwnerPartId( aProps );
317  ownerpartdisplaymode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
318 
319  int locationCount = ALTIUM_PARSER::ReadInt( aProps, "LOCATIONCOUNT", 0 );
320 
321  for( int i = 1; i <= locationCount; i++ )
322  {
323  const wxString si = std::to_string( i );
324  points.emplace_back( ReadKiCadUnitFrac( aProps, "X" + si ),
325  -ReadKiCadUnitFrac( aProps, "Y" + si ) );
326  }
327 
328  lineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
329  isSolid = ALTIUM_PARSER::ReadBool( aProps, "ISSOLID", false );
330 
331  color = ALTIUM_PARSER::ReadInt( aProps, "COLOR", 0 );
332  areacolor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR", 0 );
333 }
334 
335 
336 ASCH_ROUND_RECTANGLE::ASCH_ROUND_RECTANGLE( const std::map<wxString, wxString>& aProps )
337 {
338  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::ROUND_RECTANGLE );
339 
340  ownerindex = ReadOwnerIndex( aProps );
341  ownerpartid = ReadOwnerPartId( aProps );
342  ownerpartdisplaymode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
343 
344  bottomLeft = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
345  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
346  topRight = wxPoint( ReadKiCadUnitFrac( aProps, "CORNER.X" ),
347  -ReadKiCadUnitFrac( aProps, "CORNER.Y" ) );
348 
349  topRight = wxPoint( ReadKiCadUnitFrac( aProps, "CORNERXRADIUS" ),
350  -ReadKiCadUnitFrac( aProps, "CORNERYRADIUS" ) );
351 
352  lineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
353  isSolid = ALTIUM_PARSER::ReadBool( aProps, "ISSOLID", false );
354  isTransparent = ALTIUM_PARSER::ReadBool( aProps, "TRANSPARENT", false );
355 
356  color = ALTIUM_PARSER::ReadInt( aProps, "COLOR", 0 );
357  areacolor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR", 0 );
358 }
359 
360 
361 ASCH_ARC::ASCH_ARC( const std::map<wxString, wxString>& aProps )
362 {
363  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::ARC );
364 
365  ownerindex = ReadOwnerIndex( aProps );
366  ownerpartid = ReadOwnerPartId( aProps );
367  ownerpartdisplaymode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
368 
369  center = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
370  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
371  radius = ReadKiCadUnitFrac( aProps, "RADIUS" );
372 
373  startAngle = ALTIUM_PARSER::ReadDouble( aProps, "STARTANGLE", 0 );
374  endAngle = ALTIUM_PARSER::ReadDouble( aProps, "ENDANGLE", 0 );
375 
376  lineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
377 }
378 
379 
380 ASCH_LINE::ASCH_LINE( const std::map<wxString, wxString>& aProps )
381 {
382  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::LINE );
383 
384  ownerindex = ReadOwnerIndex( aProps );
385  ownerpartid = ReadOwnerPartId( aProps );
386  ownerpartdisplaymode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
387 
388  point1 = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
389  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
390  point2 = wxPoint( ReadKiCadUnitFrac( aProps, "CORNER.X" ),
391  -ReadKiCadUnitFrac( aProps, "CORNER.Y" ) );
392 
393  lineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
394 }
395 
396 
397 ASCH_RECTANGLE::ASCH_RECTANGLE( const std::map<wxString, wxString>& aProps )
398 {
399  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::RECTANGLE );
400 
401  ownerindex = ReadOwnerIndex( aProps );
402  ownerpartid = ReadOwnerPartId( aProps );
403  ownerpartdisplaymode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
404 
405  bottomLeft = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
406  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
407  topRight = wxPoint( ReadKiCadUnitFrac( aProps, "CORNER.X" ),
408  -ReadKiCadUnitFrac( aProps, "CORNER.Y" ) );
409 
410  lineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
411  isSolid = ALTIUM_PARSER::ReadBool( aProps, "ISSOLID", false );
412  isTransparent = ALTIUM_PARSER::ReadBool( aProps, "TRANSPARENT", false );
413 
414  color = ALTIUM_PARSER::ReadInt( aProps, "COLOR", 0 );
415  areacolor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR", 0 );
416 }
417 
418 
419 ASCH_SHEET_SYMBOL::ASCH_SHEET_SYMBOL( const std::map<wxString, wxString>& aProps )
420 {
421  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET_SYMBOL );
422 
423  location = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
424  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
425  size = wxSize( ReadKiCadUnitFrac( aProps, "XSIZE" ),
426  ReadKiCadUnitFrac( aProps, "YSIZE" ) );
427 
428  isSolid = ALTIUM_PARSER::ReadBool( aProps, "ISSOLID", false );
429 
430  color = ALTIUM_PARSER::ReadInt( aProps, "COLOR", 0 );
431  areacolor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR", 0 );
432 }
433 
434 
435 ASCH_SHEET_ENTRY::ASCH_SHEET_ENTRY( const std::map<wxString, wxString>& aProps )
436 {
437  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET_ENTRY );
438 
439  ownerindex = ReadOwnerIndex( aProps );
440  ownerpartid = ReadOwnerPartId( aProps );
441 
442  // some magic, because it stores those infos in a different unit??
443  distanceFromTop = ReadKiCadUnitFrac1( aProps, "DISTANCEFROMTOP" );
444 
445  side = ReadEnum<ASCH_SHEET_ENTRY_SIDE>( aProps, "SIDE", 0, 3, ASCH_SHEET_ENTRY_SIDE::LEFT );
446 
447  name = ALTIUM_PARSER::ReadString( aProps, "NAME", "" );
448 
449  iotype = ReadEnum<ASCH_PORT_IOTYPE>( aProps, "IOTYPE", 0, 3, ASCH_PORT_IOTYPE::UNSPECIFIED );
450  style = ReadEnum<ASCH_PORT_STYLE>( aProps, "STYLE", 0, 7, ASCH_PORT_STYLE::NONE_HORIZONTAL );
451 }
452 
453 
454 ASCH_POWER_PORT::ASCH_POWER_PORT( const std::map<wxString, wxString>& aProps )
455 {
456  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POWER_PORT );
457 
458  ownerpartid = ReadOwnerPartId( aProps );
459 
460  location = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
461  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
462 
463  orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps, "ORIENTATION", 0, 3,
465 
466  text = ALTIUM_PARSER::ReadString( aProps, "TEXT", "" );
467  showNetName = ALTIUM_PARSER::ReadBool( aProps, "SHOWNETNAME", true );
468 
469  style = ReadEnum<ASCH_POWER_PORT_STYLE>( aProps, "STYLE", 0, 10,
471 }
472 
473 ASCH_PORT::ASCH_PORT( const std::map<wxString, wxString>& aProps )
474 {
475  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PORT );
476 
477  ownerpartid = ReadOwnerPartId( aProps );
478 
479  location = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
480  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
481 
482  name = ALTIUM_PARSER::ReadString( aProps, "NAME", "" );
483  harnessType = ALTIUM_PARSER::ReadString( aProps, "HARNESSTYPE", "" );
484 
485  width = ReadKiCadUnitFrac( aProps, "WIDTH" );
486  height = ReadKiCadUnitFrac( aProps, "HEIGHT" );
487 
488  iotype = ReadEnum<ASCH_PORT_IOTYPE>( aProps, "IOTYPE", 0, 3, ASCH_PORT_IOTYPE::UNSPECIFIED );
489  style = ReadEnum<ASCH_PORT_STYLE>( aProps, "STYLE", 0, 7, ASCH_PORT_STYLE::NONE_HORIZONTAL );
490 }
491 
492 
493 ASCH_NO_ERC::ASCH_NO_ERC( const std::map<wxString, wxString>& aProps )
494 {
495  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NO_ERC );
496 
497  location = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
498  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
499 
500  isActive = ALTIUM_PARSER::ReadBool( aProps, "ISACTIVE", true );
501  supressAll = ALTIUM_PARSER::ReadInt( aProps, "SUPPRESSALL", true );
502 }
503 
504 
505 ASCH_NET_LABEL::ASCH_NET_LABEL( const std::map<wxString, wxString>& aProps )
506 {
507  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NET_LABEL );
508 
509  text = ALTIUM_PARSER::ReadString( aProps, "TEXT", "" );
510 
511  location = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
512  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
513 
514  orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps, "ORIENTATION", 0, 3,
516 }
517 
518 
519 ASCH_BUS::ASCH_BUS( const std::map<wxString, wxString>& aProps )
520 {
521  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BUS );
522 
523  indexinsheet = ALTIUM_PARSER::ReadInt( aProps, "INDEXINSHEET", 0 );
524 
525  int locationcount = ALTIUM_PARSER::ReadInt( aProps, "LOCATIONCOUNT", 0 );
526 
527  for( int i = 1; i <= locationcount; i++ )
528  {
529  const wxString si = std::to_string( i );
530  points.emplace_back( ReadKiCadUnitFrac( aProps, "X" + si ),
531  -ReadKiCadUnitFrac( aProps, "Y" + si ) );
532  }
533 
534  lineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
535 }
536 
537 
538 ASCH_WIRE::ASCH_WIRE( const std::map<wxString, wxString>& aProps )
539 {
540  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::WIRE );
541 
542  indexinsheet = ALTIUM_PARSER::ReadInt( aProps, "INDEXINSHEET", 0 );
543 
544  int locationcount = ALTIUM_PARSER::ReadInt( aProps, "LOCATIONCOUNT", 0 );
545 
546  for( int i = 1; i <= locationcount; i++ )
547  {
548  const wxString si = std::to_string( i );
549  points.emplace_back( ReadKiCadUnitFrac( aProps, "X" + si ),
550  -ReadKiCadUnitFrac( aProps, "Y" + si ) );
551  }
552 
553  lineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
554 }
555 
556 
557 ASCH_JUNCTION::ASCH_JUNCTION( const std::map<wxString, wxString>& aProps )
558 {
559  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::JUNCTION );
560 
561  ownerpartid = ReadOwnerPartId( aProps );
562 
563  location = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
564  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
565 }
566 
567 
568 ASCH_IMAGE::ASCH_IMAGE( const std::map<wxString, wxString>& aProps )
569 {
570  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMAGE );
571 
572  indexinsheet = ALTIUM_PARSER::ReadInt( aProps, "INDEXINSHEET", 0 );
573  ownerpartid = ReadOwnerPartId( aProps );
574 
575  filename = ALTIUM_PARSER::ReadString( aProps, "FILENAME", "" );
576 
577  location = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
578  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
579  corner = wxPoint( ReadKiCadUnitFrac( aProps, "CORNER.X" ),
580  -ReadKiCadUnitFrac( aProps, "CORNER.Y" ) );
581 
582  embedimage = ALTIUM_PARSER::ReadBool( aProps, "EMBEDIMAGE", false );
583  keepaspect = ALTIUM_PARSER::ReadBool( aProps, "KEEPASPECT", false );
584 }
585 
586 
587 ASCH_SHEET_FONT::ASCH_SHEET_FONT( const std::map<wxString, wxString>& aProps, int aId )
588 {
589  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET );
590 
591  const wxString sid = std::to_string( aId );
592 
593  fontname = ALTIUM_PARSER::ReadString( aProps, "FONTNAME" + sid, "" );
594 
595  size = ReadKiCadUnitFrac( aProps, "SIZE" + sid );
596  rotation = ALTIUM_PARSER::ReadInt( aProps, "ROTATION" + sid, 0 );
597 
598  italic = ALTIUM_PARSER::ReadBool( aProps, "ITALIC" + sid, false );
599  bold = ALTIUM_PARSER::ReadBool( aProps, "BOLD" + sid, false );
600  underline = ALTIUM_PARSER::ReadBool( aProps, "UNDERLINE" + sid, false );
601 }
602 
603 wxPoint ASchSheetGetSize( ASCH_SHEET_SIZE aSheetSize )
604 {
605  // From: https://github.com/vadmium/python-altium/blob/master/format.md#sheet
606  switch( aSheetSize )
607  {
608  default:
609  case ASCH_SHEET_SIZE::A4: return { 1150, 760 };
610  case ASCH_SHEET_SIZE::A3: return { 1550, 1110 };
611  case ASCH_SHEET_SIZE::A2: return { 2230, 1570 };
612  case ASCH_SHEET_SIZE::A1: return { 3150, 2230 };
613  case ASCH_SHEET_SIZE::A0: return { 4460, 3150 };
614  case ASCH_SHEET_SIZE::A: return { 950, 750 };
615  case ASCH_SHEET_SIZE::B: return { 1500, 950 };
616  case ASCH_SHEET_SIZE::C: return { 2000, 1500 };
617  case ASCH_SHEET_SIZE::D: return { 3200, 2000 };
618  case ASCH_SHEET_SIZE::E: return { 4200, 3200 };
619  case ASCH_SHEET_SIZE::LETTER: return { 1100, 850 };
620  case ASCH_SHEET_SIZE::LEGAL: return { 1400, 850 };
621  case ASCH_SHEET_SIZE::TABLOID: return { 1700, 1100 };
622  case ASCH_SHEET_SIZE::ORCAD_A: return { 990, 790 };
623  case ASCH_SHEET_SIZE::ORCAD_B: return { 1540, 990 };
624  case ASCH_SHEET_SIZE::ORCAD_C: return { 2060, 1560 };
625  case ASCH_SHEET_SIZE::ORCAD_D: return { 3260, 2060 };
626  case ASCH_SHEET_SIZE::ORCAD_E: return { 4280, 3280 };
627  }
628 }
629 
630 
631 ASCH_SHEET::ASCH_SHEET( const std::map<wxString, wxString>& aProps )
632 {
633  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET );
634 
635  int fontidcount = ALTIUM_PARSER::ReadInt( aProps, "FONTIDCOUNT", 0 );
636 
637  for( int i = 1; i <= fontidcount; i++ )
638  fonts.emplace_back( aProps, i );
639 
640  sheetSize = ReadEnum<ASCH_SHEET_SIZE>( aProps, "SHEETSTYLE", 0, 17, ASCH_SHEET_SIZE::A4 );
641  sheetOrientation = ReadEnum<ASCH_SHEET_WORKSPACEORIENTATION>(
642  aProps, "WORKSPACEORIENTATION", 0, 1, ASCH_SHEET_WORKSPACEORIENTATION::LANDSCAPE );
643 }
644 
645 
646 ASCH_SHEET_NAME::ASCH_SHEET_NAME( const std::map<wxString, wxString>& aProps )
647 {
648  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET_NAME );
649 
650  ownerindex = ReadOwnerIndex( aProps );
651  ownerpartid = ReadOwnerPartId( aProps );
652 
653  text = ALTIUM_PARSER::ReadString( aProps, "TEXT", "" );
654 
655  orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps, "ORIENTATION", 0, 3,
657 
658  location = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
659  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
660 
661  isHidden = ALTIUM_PARSER::ReadBool( aProps, "ISHIDDEN", false );
662 }
663 
664 
665 ASCH_FILE_NAME::ASCH_FILE_NAME( const std::map<wxString, wxString>& aProps )
666 {
667  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::FILE_NAME );
668 
669  ownerindex = ReadOwnerIndex( aProps );
670  ownerpartid = ReadOwnerPartId( aProps );
671 
672  text = ALTIUM_PARSER::ReadString( aProps, "TEXT", "" );
673 
674  orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps, "ORIENTATION", 0, 3,
676 
677  location = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
678  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
679 
680  isHidden = ALTIUM_PARSER::ReadBool( aProps, "ISHIDDEN", false );
681 }
682 
683 
684 ASCH_DESIGNATOR::ASCH_DESIGNATOR( const std::map<wxString, wxString>& aProps )
685 {
686  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::DESIGNATOR );
687 
688  ownerindex = ReadOwnerIndex( aProps );
689  ownerpartid = ReadOwnerPartId( aProps );
690 
691  name = ALTIUM_PARSER::ReadString( aProps, "NAME", "" );
692  text = ALTIUM_PARSER::ReadString( aProps, "TEXT", "" );
693 
694  justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps, "JUSTIFICATION", 0, 8,
696 
697  orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps, "ORIENTATION", 0, 3,
699 
700  location = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
701  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
702 }
703 
704 
705 ASCH_IMPLEMENTATION::ASCH_IMPLEMENTATION( const std::map<wxString, wxString>& aProps )
706 {
707  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMPLEMENTATION );
708 
709  ownerindex = ALTIUM_PARSER::ReadInt( aProps, "OWNERINDEX", ALTIUM_COMPONENT_NONE );
710  name = ALTIUM_PARSER::ReadString( aProps, "MODELNAME", "" );
711  type = ALTIUM_PARSER::ReadString( aProps, "MODELTYPE", "" );
712  libname = ALTIUM_PARSER::ReadString( aProps, "MODELDATAFILE0", "" );
713  isCurrent = ALTIUM_PARSER::ReadBool( aProps, "ISCURRENT", false );
714 }
715 
716 
717 ASCH_IMPLEMENTATION_LIST::ASCH_IMPLEMENTATION_LIST( const std::map<wxString, wxString>& aProps )
718 {
719  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMPLEMENTATION_LIST );
720 
721  ownerindex = ReadOwnerIndex( aProps );
722 }
723 
724 ASCH_BUS_ENTRY::ASCH_BUS_ENTRY( const std::map<wxString, wxString>& aProps )
725 {
726  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BUS_ENTRY );
727 
728  location = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
729  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
730  corner = wxPoint( ReadKiCadUnitFrac( aProps, "CORNER.X" ),
731  -ReadKiCadUnitFrac( aProps, "CORNER.Y" ) );
732 }
733 
734 
735 ASCH_PARAMETER::ASCH_PARAMETER( const std::map<wxString, wxString>& aProps )
736 {
737  wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PARAMETER );
738 
739  ownerindex = ReadOwnerIndex( aProps );
740  ownerpartid = ReadOwnerPartId( aProps );
741 
742  location = wxPoint( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
743  -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
744 
745  justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps, "JUSTIFICATION", 0, 8,
747 
748  orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps, "ORIENTATION", 0, 3,
750 
751  name = ALTIUM_PARSER::ReadString( aProps, "NAME", "" );
752  text = ALTIUM_PARSER::ReadString( aProps, "TEXT", "" );
753 
754  isHidden = ALTIUM_PARSER::ReadBool( aProps, "ISHIDDEN", false );
755  isMirrored = ALTIUM_PARSER::ReadBool( aProps, "ISMIRRORED", false );
756  isShowName = ALTIUM_PARSER::ReadBool( aProps, "SHOWNAME", false );
757 }
T ReadEnum(const std::map< wxString, wxString > &aProps, const wxString &aKey, int aLower, int aUpper, T aDefault)
wxPoint location
wxString sourcelibraryname
wxString text
ASCH_RECORD_ORIENTATION orientation
std::vector< char > data
int distanceFromTop
ASCH_IMAGE(const std::map< wxString, wxString > &aProps)
ASCH_SHEET_FONT(const std::map< wxString, wxString > &aProps, int aId)
ASCH_PARAMETER(const std::map< wxString, wxString > &aProps)
ASCH_JUNCTION(const std::map< wxString, wxString > &aProps)
ASCH_PORT_IOTYPE iotype
wxString harnessType
wxPoint ASchSheetGetSize(ASCH_SHEET_SIZE aSheetSize)
std::vector< wxPoint > points
ASCH_LABEL_JUSTIFICATION justification
int ownerpartdisplaymode
wxString filename
ASCH_POWER_PORT_STYLE style
ASCH_PORT_STYLE style
ASCH_IMPLEMENTATION(const std::map< wxString, wxString > &aProps)
wxPoint corner
ASCH_SHEET(const std::map< wxString, wxString > &aProps)
void Skip(size_t aLength)
static double ReadDouble(const std::map< wxString, wxString > &aProps, const wxString &aKey, double aDefault)
ASCH_FILE_NAME(const std::map< wxString, wxString > &aProps)
ASCH_RECTANGLE(const std::map< wxString, wxString > &aProps)
ASCH_BEZIER(const std::map< wxString, wxString > &aProps)
wxPoint kicadLocation
ASCH_RECORD_ORIENTATION orientation
ASCH_STORAGE_FILE(ALTIUM_PARSER &aReader)
ASCH_NOTE(const std::map< wxString, wxString > &aProperties)
ASCH_LABEL(const std::map< wxString, wxString > &aProps)
ASCH_POLYGON(const std::map< wxString, wxString > &aProps)
std::vector< char > ReadVector(size_t aSize)
Definition: altium_parser.h:87
wxPoint location
int ownerpartid
ASCH_RECORD_ORIENTATION orientation
ASCH_RECORD_ORIENTATION orientation
ASCH_PIN(const std::map< wxString, wxString > &aProps)
wxString libreference
static int ReadInt(const std::map< wxString, wxString > &aProps, const wxString &aKey, int aDefault)
int ownerindex
ASCH_WIRE(const std::map< wxString, wxString > &aProps)
ASCH_SHEET_NAME(const std::map< wxString, wxString > &aProps)
std::vector< wxPoint > points
constexpr int Altium2KiCadUnit(const int val, const int frac)
static bool ReadBool(const std::map< wxString, wxString > &aProps, const wxString &aKey, bool aDefault)
ASCH_SHEET_SYMBOL(const std::map< wxString, wxString > &aProps)
ASCH_LINE(const std::map< wxString, wxString > &aProps)
int ownerpartdisplaymode
ASCH_RECORD_ORIENTATION orientation
ASCH_BUS_ENTRY(const std::map< wxString, wxString > &aProps)
int ReadKiCadUnitFrac1(const std::map< wxString, wxString > &aProps, const wxString &aKey)
int ReadKiCadUnitFrac(const std::map< wxString, wxString > &aProps, const wxString &aKey)
ASCH_BUS(const std::map< wxString, wxString > &aProps)
ASCH_POWER_PORT(const std::map< wxString, wxString > &aProps)
wxString name
std::vector< wxPoint > points
ASCH_RECORD_ORIENTATION orientation
ASCH_PORT(const std::map< wxString, wxString > &aProps)
ASCH_POLYLINE(const std::map< wxString, wxString > &aProps)
ASCH_DESIGNATOR(const std::map< wxString, wxString > &aProps)
wxString designator
ASCH_TEXT_FRAME(const std::map< wxString, wxString > &aProps)
ASCH_PORT_IOTYPE iotype
ASCH_SHEET_ENTRY(const std::map< wxString, wxString > &aProps)
ASCH_ARC(const std::map< wxString, wxString > &aProps)
int ReadOwnerPartId(const std::map< wxString, wxString > &aProperties)
ALTIUM_SCH_RECORD ReadRecord(const std::map< wxString, wxString > &aProps)
ASCH_SHEET_SIZE sheetSize
ASCH_SHEET_ENTRY_SIDE side
ASCH_RECORD_ORIENTATION orientation
double startAngle
ASCH_PIN_SYMBOL_OUTEREDGE symbolOuterEdge
wxString author
wxString ReadWxString()
Definition: altium_parser.h:69
ASCH_NO_ERC(const std::map< wxString, wxString > &aProps)
ASCH_IMPLEMENTATION_LIST(const std::map< wxString, wxString > &aProps)
std::vector< ASCH_SHEET_FONT > fonts
ASCH_TEXT_FRAME_ALIGNMENT alignment
ASCH_POLYLINE_LINESTYLE linestyle
ASCH_PIN_SYMBOL_INNER symbolInner
ASCH_RECORD_ORIENTATION orientation
wxPoint location
ASCH_SYMBOL(const std::map< wxString, wxString > &aProps)
const int ALTIUM_COMPONENT_NONE
std::vector< wxPoint > points
static wxString ReadString(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
ASCH_SHEET_SIZE
int ReadOwnerIndex(const std::map< wxString, wxString > &aProperties)
int ownerpartdisplaymode
ASCH_PORT_STYLE style
ASCH_PIN_ELECTRICAL electrical
wxPoint center
ASCH_NET_LABEL(const std::map< wxString, wxString > &aProps)
ASCH_PIN_SYMBOL_OUTER symbolOuter
ASCH_PIN_SYMBOL_INNEREDGE symbolInnerEdge
ALTIUM_SCH_RECORD
ASCH_LABEL_JUSTIFICATION justification
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
ASCH_SHEET_WORKSPACEORIENTATION sheetOrientation
bool HasParsingError()
wxString componentdescription
ASCH_LABEL_JUSTIFICATION justification
std::vector< wxPoint > points
wxString name
ASCH_ROUND_RECTANGLE(const std::map< wxString, wxString > &aProps)