69 wxString msg =
_(
"Board may be corrupted, do not save it.\n Fix problem and try again" );
71 wxString extra = ioe.
What();
85 GetCanvas()->GetView()->RecacheAllItems();
88 for(
auto track :
GetBoard()->Tracks() )
89 GetCanvas()->GetView()->Add( track );
92 SetStatusText( wxString(
_(
"Session file imported and merged OK." ) ) );
113 double resValue = aResolution->
GetValue();
152 wxPoint ret(
scale( aPoint.
x, aResolution ),
153 -
scale( aPoint.
y, aResolution ) );
167 wxString::Format(
_(
"Session file uses invalid layer id \"%s\"" ), layerName ) );
183 int aNetCode,
int aViaDrillDefault )
188 int shapeCount = aPadstack->
Length();
189 int drill_diam_iu = -1;
195 int drillStartNdx = aPadstack->
padstack_id.find(
':' );
197 if( drillStartNdx != -1 )
201 int drillEndNdx = aPadstack->
padstack_id.rfind(
'_' );
202 if( drillEndNdx != -1 )
205 drillStartNdx, drillEndNdx-drillStartNdx );
207 double drill_um = strtod( diam_txt.c_str(), 0 );
209 drill_diam_iu = int( drill_um * (
IU_PER_MM / 1000.0) );
211 if( drill_diam_iu == aViaDrillDefault )
216 if( shapeCount == 0 )
220 else if( shapeCount == 1 )
222 shape = (
SHAPE*) (*aPadstack)[0];
224 if( type != T_circle )
233 via->SetDrill( drill_diam_iu );
235 via->SetWidth( viaDiam );
238 else if( shapeCount == copperLayerCount )
240 shape = (
SHAPE*) (*aPadstack)[0];
242 if( type != T_circle )
251 via->SetDrill( drill_diam_iu );
253 via->SetWidth( viaDiam );
258 int topLayerNdx = -1;
259 int botLayerNdx = INT_MAX;
263 for(
int i=0; i<shapeCount; ++i )
265 shape = (
SHAPE*) (*aPadstack)[i];
267 if( type != T_circle )
269 _(
"Unsupported via shape: %s" ), GetTokenString( type ) ) );
278 _(
"Session file uses invalid layer id \"%s\"" ), layerName ) );
281 if( layerNdx > topLayerNdx )
282 topLayerNdx = layerNdx;
284 if( layerNdx < botLayerNdx )
285 botLayerNdx = layerNdx;
293 via->SetDrill( drill_diam_iu );
295 if( (topLayerNdx==0 && botLayerNdx==1)
296 || (topLayerNdx==copperLayerCount-2 && botLayerNdx==copperLayerCount-1))
301 via->SetWidth( viaDiam );
306 via->SetLayerPair( topLayer, botLayer );
311 via->SetNetCode( aNetCode );
324 THROW_IO_ERROR(
_(
"Session file is missing the \"session\" section") );
330 THROW_IO_ERROR(
_(
"Session file is missing the \"library_out\" section") );
345 for( COMPONENTS::iterator comp=components.begin(); comp!=components.end(); ++comp )
347 PLACES& places = comp->places;
348 for(
unsigned i=0; i<places.size(); ++i )
350 PLACE* place = &places[i];
365 wxASSERT( resolution );
367 wxPoint newPos =
mapPt( place->
vertex, resolution );
368 footprint->SetPosition( newPos );
370 if( place->
side == T_front )
375 if( footprint->GetLayer() !=
F_Cu )
378 footprint->Flip( footprint->GetPosition(), false );
381 footprint->SetOrientation( orientation );
383 else if( place->
side == T_back )
387 if( footprint->GetLayer() !=
B_Cu )
390 footprint->Flip( footprint->GetPosition(), false );
393 footprint->SetOrientation( orientation );
398 wxFAIL_MSG( wxT(
"DSN::PARSER did not catch an illegal side := 'back|front'") );
408 for( NET_OUTS::iterator net = net_outs.begin(); net!=net_outs.end(); ++net )
413 if( net->net_id.size() )
415 wxString netName =
FROM_UTF8( net->net_id.c_str() );
428 WIRES& wires = net->wires;
429 for(
unsigned i = 0; i<wires.size(); ++i )
431 WIRE* wire = &wires[i];
434 if( shape != T_path )
452 for(
unsigned pt=0; pt<path->points.size()-1; ++pt )
455 aBoard->
Add( track );
462 for(
unsigned i=0; i<wire_vias.size(); ++i )
467 if( net->net_id.size() )
469 wxString netName =
FROM_UTF8( net->net_id.c_str() );
499 _(
"A wire_via references a missing padstack \"%s\"" ), psid ) );
504 int via_drill_default = netclass->GetViaDrill();
506 for(
unsigned v=0; v<wire_via->
vertexes.size(); ++v )
void LoadSESSION(const wxString &aFilename)
Function LoadSESSION is a recursive descent parser for a SPECCTRA DSN "session" file.
VIA corresponds to the <via_descriptor> in the specctra dsn spec.
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
TRACK * makeTRACK(PATH *aPath, int aPointIndex, int aNetcode)
Function makeTRACK creates a TRACK form the PATH and BOARD info.
void buildLayerMaps(BOARD *aBoard)
Function buildLayerMaps creates a few data translation structures for layer name and number mapping b...
BOARD * m_sessionBoard
a copy to avoid passing as an argument, memory for it is not owned here.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
This source file implements export and import capabilities to the specctra dsn file format.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library TODO brief description.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
This file is part of the common library.
void SetEnd(const wxPoint &aEnd)
boost::ptr_vector< WIRE_VIA > WIRE_VIAS
static constexpr double IU_PER_MM
Mock up a conversion function.
static POINT mapPt(const wxPoint &pt)
Function mapPt converts a KiCad point into a DSN file point.
UNIT_RES is a holder for either a T_unit or T_resolution object which are usually mutually exclusive ...
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
boost::ptr_vector< NET_OUT > NET_OUTS
DSN_T GetEngUnits() const
This file contains miscellaneous commonly used macros and functions.
void SetWidth(int aWidth)
int findLayerName(const std::string &aLayerName) const
Function findLayerName returns the PCB layer index for a given layer name, within the specctra sessio...
#define UNDEFINED_DRILL_DIAMETER
PATH supports both the <path_descriptor> and the <polygon_descriptor> per the specctra dsn spec.
UNIT_RES * GetUnits() const override
Function GetUnits returns the units for this section.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
PCB_LAYER_ID
A quick note on layer IDs:
PADSTACK * FindPADSTACK(const std::string &aPadstackId)
Function FindPADSTACK searches the padstack container by name.
virtual const wxString What() const
A composite of Problem() and Where()
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void DeleteMARKERs()
Delete all MARKERS from the board.
boost::ptr_vector< COMPONENT > COMPONENTS
PLACE implements the <placement_reference> in the specctra dsn spec.
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
::VIA * makeVIA(PADSTACK *aPadstack, const POINT &aPoint, int aNetCode, int aViaDrillDefault)
Function makeVIA instantiates a KiCad VIA on the heap and initializes it with internal values consist...
std::string component_id
reference designator
PADSTACK holds either a via or a pad definition.
NETCLASSES & GetNetClasses() const
SPECCTRA_DB holds a DSN data tree, usually coming from a DSN file.
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
UNIT_RES * m_routeResolution
used during FromSESSION() only, memory for it is not owned here.
SHAPE corresponds to the "(shape ..)" element in the specctra dsn spec.
const std::string & GetPadstackId()
Handle the data for a net.
bool ImportSpecctraSession(const wxString &aFullFilename)
Import a specctra *.ses file and use it to relocate MODULEs and to replace all vias and tracks in an ...
LIBRARY corresponds to the <library_descriptor> in the specctra dsn specification.
std::vector< PCB_LAYER_ID > m_pcbLayer2kicad
maps PCB layer number to BOARD layer numbers
Struct POINT is a holder for a point in the SPECCTRA DSN coordinate system.
WIRE corresponds to <wire_shape_descriptor> in the specctra dsn spec.
boost::ptr_vector< PLACE > PLACES
Information pertinent to a Pcbnew printed circuit board.
int GetCopperLayerCount() const
static double scale(int kicadDist)
Function scale converts a distance from PCBNEW internal units to the reported specctra dsn units in f...
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
virtual UNIT_RES * GetUnits() const
Function GetUnits returns the units for this section.
NETCLASSPTR GetDefault() const
boost::ptr_vector< WIRE > WIRES
void SetStart(const wxPoint &aStart)
WIRE_VIA corresponds to <wire_via_descriptor> in the specctra dsn spec.
void FromSESSION(BOARD *aBoard)
Function FromSESSION adds the entire SESSION info to a BOARD but does not write it out.
int Length() const
Function Length returns the number of ELEMs in this ELEM.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
#define THROW_IO_ERROR(msg)
FOOTPRINT * FindFootprintByReference(const wxString &aReference) const
Search for a FOOTPRINT within this board with the given reference designator.