65 GetCanvas()->GetView()->Remove( track );
78 wxString msg =
_(
"Board may be corrupted, do not save it.\n Fix problem and try again" );
80 wxString extra = ioe.
What();
94 GetCanvas()->GetView()->RecacheAllItems();
97 for(
auto track :
GetBoard()->Tracks() )
98 GetCanvas()->GetView()->Add( track );
101 SetStatusText( wxString(
_(
"Session file imported and merged OK." ) ) );
122 double resValue = aResolution->
GetValue();
161 wxPoint ret(
scale( aPoint.
x, aResolution ),
162 -
scale( aPoint.
y, aResolution ) );
199 int aViaDrillDefault )
203 int shapeCount = aPadstack->
Length();
204 int drill_diam_iu = -1;
210 int drillStartNdx = aPadstack->
padstack_id.find(
':' );
212 if( drillStartNdx != -1 )
216 int drillEndNdx = aPadstack->
padstack_id.rfind(
'_' );
217 if( drillEndNdx != -1 )
220 drillStartNdx, drillEndNdx-drillStartNdx );
222 double drill_um = strtod( diam_txt.c_str(), 0 );
224 drill_diam_iu = int( drill_um * (
IU_PER_MM / 1000.0) );
226 if( drill_diam_iu == aViaDrillDefault )
231 if( shapeCount == 0 )
235 else if( shapeCount == 1 )
237 shape = (
SHAPE*) (*aPadstack)[0];
240 if( type != T_circle )
243 GetTokenString( type ) ) );
251 via->SetDrill( drill_diam_iu );
253 via->SetWidth( viaDiam );
256 else if( shapeCount == copperLayerCount )
258 shape = (
SHAPE*) (*aPadstack)[0];
260 if( type != T_circle )
269 via->SetDrill( drill_diam_iu );
271 via->SetWidth( viaDiam );
276 int topLayerNdx = -1;
277 int botLayerNdx = INT_MAX;
281 for(
int i=0; i<shapeCount; ++i )
283 shape = (
SHAPE*) (*aPadstack)[i];
285 if( type != T_circle )
287 _(
"Unsupported via shape: %s" ), GetTokenString( type ) ) );
296 _(
"Session file uses invalid layer id \"%s\"" ), layerName ) );
299 if( layerNdx > topLayerNdx )
300 topLayerNdx = layerNdx;
302 if( layerNdx < botLayerNdx )
303 botLayerNdx = layerNdx;
311 via->SetDrill( drill_diam_iu );
313 if( (topLayerNdx==0 && botLayerNdx==1)
314 || (topLayerNdx==copperLayerCount-2 && botLayerNdx==copperLayerCount-1))
319 via->SetWidth( viaDiam );
324 via->SetLayerPair( topLayer, botLayer );
329 via->SetNetCode( aNetCode );
337 via->SetLocked(
true );
351 THROW_IO_ERROR(
_(
"Session file is missing the \"session\" section") );
357 THROW_IO_ERROR(
_(
"Session file is missing the \"library_out\" section") );
361 std::vector<PCB_TRACK*>
locked;
363 while( !aBoard->
Tracks().empty() )
366 aBoard->
Tracks().pop_back();
369 locked.push_back( track );
382 aBoard->
Add( track );
391 for( COMPONENTS::iterator comp=components.begin(); comp!=components.end(); ++comp )
393 PLACES& places = comp->places;
394 for(
unsigned i=0; i<places.size(); ++i )
396 PLACE* place = &places[i];
411 wxASSERT( resolution );
413 wxPoint newPos =
mapPt( place->
vertex, resolution );
414 footprint->SetPosition( newPos );
416 if( place->
side == T_front )
421 if( footprint->GetLayer() !=
F_Cu )
424 footprint->Flip( footprint->GetPosition(), false );
427 footprint->SetOrientation( orientation );
429 else if( place->
side == T_back )
433 if( footprint->GetLayer() !=
B_Cu )
436 footprint->Flip( footprint->GetPosition(), false );
439 footprint->SetOrientation( orientation );
444 wxFAIL_MSG( wxT(
"DSN::PARSER did not catch an illegal side := 'back|front'") );
454 for( NET_OUTS::iterator net = net_outs.begin(); net!=net_outs.end(); ++net )
459 if( net->net_id.size() )
461 wxString netName =
FROM_UTF8( net->net_id.c_str() );
474 WIRES& wires = net->wires;
475 for(
unsigned i = 0; i<wires.size(); ++i )
477 WIRE* wire = &wires[i];
480 if( shape != T_path )
499 for(
unsigned pt=0; pt < path->points.size()-1; ++pt )
502 aBoard->
Add( track );
509 for(
unsigned i=0; i<wire_vias.size(); ++i )
514 if( net->net_id.size() )
516 wxString netName =
FROM_UTF8( net->net_id.c_str() );
551 int via_drill_default = netclass->GetViaDrill();
553 for(
unsigned v = 0; v < wire_via->
vertexes.size(); ++v )
void LoadSESSION(const wxString &aFilename)
A recursive descent parser for a SPECCTRA DSN "session" file.
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
void buildLayerMaps(BOARD *aBoard)
Create a few data translation structures for layer name and number mapping between the DSN::PCB struc...
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.
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.
boost::ptr_vector< WIRE_VIA > WIRE_VIAS
void SetEnd(const wxPoint &aEnd)
static constexpr double IU_PER_MM
Mock up a conversion function.
static POINT mapPt(const wxPoint &pt)
Convert a KiCad point into a DSN file point.
A holder for either a T_unit or T_resolution object which are usually mutually exclusive in the dsn g...
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
virtual void SetLocked(bool aLocked)
Modify the 'lock' status for of the item.
boost::ptr_vector< NET_OUT > NET_OUTS
DSN_T GetEngUnits() const
virtual bool IsLocked() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
This file contains miscellaneous commonly used macros and functions.
int findLayerName(const std::string &aLayerName) const
Return the PCB layer index for a given layer name, within the specctra sessionfile.
Support both the <path_descriptor> and the <polygon_descriptor> per the specctra dsn spec.
UNIT_RES * GetUnits() const override
Return the units for this section.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
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
Implement a <placement_reference> in the specctra dsn spec.
#define UNDEFINED_DRILL_DIAMETER
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
void SetStart(const wxPoint &aStart)
std::string component_id
reference designator
Hold either a via or a pad definition.
NETCLASSES & GetNetClasses() const
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.
A "(shape ..)" element in the specctra dsn spec.
const std::string & GetPadstackId()
void SetWidth(int aWidth)
PCB_TRACK * makeTRACK(WIRE *wire, PATH *aPath, int aPointIndex, int aNetcode)
Create a #TRACK form the #PATH and BOARD info.
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 ...
A <library_descriptor> in the specctra dsn specification.
std::vector< PCB_LAYER_ID > m_pcbLayer2kicad
maps PCB layer number to BOARD layer numbers
A point in the SPECCTRA DSN coordinate system.
A <wire_shape_descriptor> in the specctra dsn spec.
boost::ptr_vector< PLACE > PLACES
Information pertinent to a Pcbnew printed circuit board.
PCB_LAYER_ID
A quick note on layer IDs:
int GetCopperLayerCount() const
static double scale(int kicadDist)
Convert a distance from Pcbnew internal units to the reported Specctra DSN units in floating point fo...
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
PCB_VIA * makeVIA(WIRE_VIA *aVia, PADSTACK *aPadstack, const POINT &aPoint, int aNetCode, int aViaDrillDefault)
Instantiate a KiCad #VIA on the heap and initializes it with internal values consistent with the give...
virtual UNIT_RES * GetUnits() const
Return the units for this section.
NETCLASSPTR GetDefault() const
boost::ptr_vector< WIRE > WIRES
A <wire_via_descriptor> in the specctra dsn spec.
void FromSESSION(BOARD *aBoard)
Add the entire #SESSION info to a BOARD but does not write it out.
int Length() const
Return the number of ELEMs in this holder.
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.