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