KiCad PCB EDA Suite
altium_pcb.cpp File Reference
#include "altium_pcb.h"
#include "altium_parser_pcb.h"
#include "plugins/altium/altium_parser.h"
#include <plugins/altium/altium_parser_utils.h>
#include <board.h>
#include <dimension.h>
#include <pcb_shape.h>
#include <pcb_text.h>
#include <track.h>
#include <kicad_string.h>
#include <fp_shape.h>
#include <fp_text.h>
#include <board_stackup_manager/stackup_predefined_prms.h>
#include <compoundfilereader.h>
#include <convert_basic_shapes_to_polygon.h>
#include <project.h>
#include <trigo.h>
#include <utf.h>
#include <wx/docview.h>
#include <wx/mstream.h>
#include <wx/wfstream.h>
#include <wx/zstream.h>

Go to the source code of this file.

Functions

void ParseAltiumPcb (BOARD *aBoard, const wxString &aFileName, const std::map< ALTIUM_PCB_DIR, std::string > &aFileMapping)
 Helper method which opens a Altium Board File and parses it. More...
 
bool IsAltiumLayerCopper (ALTIUM_LAYER aLayer)
 
bool IsAltiumLayerAPlane (ALTIUM_LAYER aLayer)
 
void HelperShapeLineChainFromAltiumVertices (SHAPE_LINE_CHAIN &aLine, const std::vector< ALTIUM_VERTICE > &aVertices)
 

Function Documentation

◆ HelperShapeLineChainFromAltiumVertices()

void HelperShapeLineChainFromAltiumVertices ( SHAPE_LINE_CHAIN aLine,
const std::vector< ALTIUM_VERTICE > &  aVertices 
)

Definition at line 163 of file altium_pcb.cpp.

165 {
166  for( auto& vertice : aVertices )
167  {
168  if( vertice.isRound )
169  {
170  double angle = NormalizeAngleDegreesPos( vertice.endangle - vertice.startangle );
171 
172  double startradiant = DEG2RAD( vertice.startangle );
173  double endradiant = DEG2RAD( vertice.endangle );
174  wxPoint arcStartOffset = wxPoint( KiROUND( std::cos( startradiant ) * vertice.radius ),
175  -KiROUND( std::sin( startradiant ) * vertice.radius ) );
176 
177  wxPoint arcEndOffset = wxPoint( KiROUND( std::cos( endradiant ) * vertice.radius ),
178  -KiROUND( std::sin( endradiant ) * vertice.radius ) );
179 
180  wxPoint arcStart = vertice.center + arcStartOffset;
181  wxPoint arcEnd = vertice.center + arcEndOffset;
182 
183  if( GetLineLength( arcStart, vertice.position )
184  < GetLineLength( arcEnd, vertice.position ) )
185  {
186  aLine.Append( SHAPE_ARC( vertice.center, arcStart, -angle ) );
187  }
188  else
189  {
190  aLine.Append( SHAPE_ARC( vertice.center, arcEnd, angle ) );
191  }
192  }
193  else
194  {
195  aLine.Append( vertice.position );
196  }
197  }
198 
199  aLine.SetClosed( true );
200 }
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:223
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
void SetClosed(bool aClosed)
Function SetClosed()
double NormalizeAngleDegreesPos(double Angle)
Normalize angle to be in the 0.0 .
Definition: trigo.h:296
double DEG2RAD(double deg)
Definition: trigo.h:231
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68

References PNS::angle(), SHAPE_LINE_CHAIN::Append(), DEG2RAD(), GetLineLength(), KiROUND(), NormalizeAngleDegreesPos(), and SHAPE_LINE_CHAIN::SetClosed().

Referenced by ALTIUM_PCB::ParsePolygons6Data(), and ALTIUM_PCB::ParseShapeBasedRegions6Data().

◆ IsAltiumLayerAPlane()

◆ IsAltiumLayerCopper()

bool IsAltiumLayerCopper ( ALTIUM_LAYER  aLayer)

Definition at line 99 of file altium_pcb.cpp.

References BOTTOM_LAYER, and TOP_LAYER.

Referenced by ALTIUM_PCB::ParsePads6Data().

◆ ParseAltiumPcb()

void ParseAltiumPcb ( BOARD aBoard,
const wxString &  aFileName,
const std::map< ALTIUM_PCB_DIR, std::string > &  aFileMapping 
)

Helper method which opens a Altium Board File and parses it.

Parameters
aBoardboard the pcb should be appended to
aFileNamefile name of board file
aFileMappingmapping how altium stream names are mapped

Definition at line 52 of file altium_pcb.cpp.

54 {
55  // Open file
56  FILE* fp = wxFopen( aFileName, "rb" );
57 
58  if( fp == nullptr )
59  {
60  wxLogError( wxString::Format( _( "Cannot open file '%s'" ), aFileName ) );
61  return;
62  }
63 
64  fseek( fp, 0, SEEK_END );
65  long len = ftell( fp );
66 
67  if( len < 0 )
68  {
69  fclose( fp );
70  THROW_IO_ERROR( "Reading error, cannot determine length of file" );
71  }
72 
73  std::unique_ptr<unsigned char[]> buffer( new unsigned char[len] );
74  fseek( fp, 0, SEEK_SET );
75 
76  size_t bytesRead = fread( buffer.get(), sizeof( unsigned char ), len, fp );
77  fclose( fp );
78 
79  if( static_cast<size_t>( len ) != bytesRead )
80  {
81  THROW_IO_ERROR( "Reading error" );
82  }
83 
84  try
85  {
86  CFB::CompoundFileReader reader( buffer.get(), bytesRead );
87 
88  // Parse File
89  ALTIUM_PCB pcb( aBoard );
90  pcb.Parse( reader, aFileMapping );
91  }
92  catch( CFB::CFBException& exception )
93  {
94  THROW_IO_ERROR( exception.what() );
95  }
96 }
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
#define _(s)
Definition: 3d_actions.cpp:33
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), and THROW_IO_ERROR.

Referenced by ALTIUM_CIRCUIT_MAKER_PLUGIN::Load(), ALTIUM_CIRCUIT_STUDIO_PLUGIN::Load(), and ALTIUM_DESIGNER_PLUGIN::Load().