33#include <fast_float/fast_float.h>
69 wxString msg =
_(
"Board may be corrupted, do not save it.\n Fix problem and try again" );
71 wxString extra = ioe.
What();
77 commit.
Push(
_(
"Import Specctra Session" ) );
79 SetStatusText( wxString(
_(
"Session file imported and merged OK." ) ) );
97 double resValue = aResolution->
GetValue();
103 case T_inch: factor = 25.4e6;
break;
104 case T_mil: factor = 25.4e3;
break;
105 case T_cm: factor = 1e7;
break;
106 case T_mm: factor = 1e6;
break;
107 case T_um: factor = 1e3;
break;
125 -
scale( aPoint.
y, aResolution ) );
187 int aNetCode,
int aViaDrillDefault )
191 int shapeCount = aPadstack->
Length();
192 int drill_diam_iu = -1;
200 if( drillStartNdx != std::string::npos )
206 if( drillEndNdx != std::string::npos )
208 std::string diam_txt( aPadstack->
m_padstack_id, drillStartNdx,
209 drillEndNdx-drillStartNdx );
212 fast_float::from_chars( diam_txt.data(), diam_txt.data() + diam_txt.size(), drill_um,
213 fast_float::chars_format::skip_white_space );
215 drill_diam_iu =
static_cast<int>( drill_um * (
pcbIUScale.IU_PER_MM / 1000.0 ) );
217 if( drill_diam_iu == aViaDrillDefault )
222 if( shapeCount == 0 )
226 else if( shapeCount == 1 )
228 shape =
static_cast<SHAPE*
>( ( *aPadstack )[0] );
231 if( type != T_circle )
232 THROW_IO_ERRORF(
_(
"Unsupported via shape: %s." ), GetTokenString( type ) );
239 via->SetDrill( drill_diam_iu );
244 else if( shapeCount == copperLayerCount )
246 shape =
static_cast<SHAPE*
>( ( *aPadstack )[0] );
249 if( type != T_circle )
250 THROW_IO_ERRORF(
_(
"Unsupported via shape: %s" ), GetTokenString( type ) );
257 via->SetDrill( drill_diam_iu );
264 int topLayerNdx = -1;
265 int botLayerNdx = INT_MAX;
269 for(
int i = 0; i < shapeCount; ++i )
271 shape =
static_cast<SHAPE*
>( ( *aPadstack )[i] );
274 if( type != T_circle )
275 THROW_IO_ERRORF(
_(
"Unsupported via shape: %s" ), GetTokenString( type ) );
284 THROW_IO_ERRORF(
_(
"Session file uses invalid layer id '%s'" ), layerName );
287 if( layerNdx > topLayerNdx )
288 topLayerNdx = layerNdx;
290 if( layerNdx < botLayerNdx )
291 botLayerNdx = layerNdx;
299 via->SetDrill( drill_diam_iu );
301 if( ( topLayerNdx == 0 && botLayerNdx == 1 )
302 || ( topLayerNdx == copperLayerCount - 2 && botLayerNdx == copperLayerCount - 1 ) )
306 else if( topLayerNdx > 0 && botLayerNdx < copperLayerCount - 1 )
315 wxCHECK2( topLayerNdx >= 0, topLayerNdx = 0 );
323 via->SetNetCode( aNetCode );
331 via->SetLocked(
true );
345 THROW_IO_ERROR(
_(
"Session file is missing the \"session\" section") );
351 THROW_IO_ERROR(
_(
"Session file is missing the \"library_out\" section") );
357 if( !track->IsLocked() )
375 boost::ptr_vector<COMPONENT>& components =
m_session->placement->m_components;
379 for(
PLACE& place : component.m_places )
394 wxASSERT( resolution );
396 aCommit.
Modify( footprint );
401 if( place.
m_side == T_front )
414 else if( place.
m_side == T_back )
429 wxFAIL_MSG( wxT(
"DSN::PARSER did not catch an illegal side := 'back|front'") );
438 boost::ptr_vector<NET_OUT>& net_outs =
m_session->route->net_outs;
442 auto skipOnError = [&skipped](
auto&& aBuild )
454 for(
NET_OUT& net_out : net_outs )
459 if( net_out.net_id.size() )
461 wxString netName =
From_UTF8( net_out.net_id.c_str() );
468 for(
WIRE& wire : net_out.wires )
474 if( shape == T_path )
478 for(
unsigned pt = 0; pt <
path->points.size() - 1; ++pt )
481 else if( shape == T_qarc )
485 aCommit.
Add(
makeARC( &wire, qarc, netoutCode ) );
487 else if( shape == T_polygon )
501 for(
WIRE_VIA& wire_via : net_out.wire_vias )
508 if( net_out.net_id.size() )
510 wxString netName =
From_UTF8( net_out.net_id.c_str() );
531 THROW_IO_ERRORF(
_(
"A wire_via refers to missing padstack '%s'." ), psid );
536 int via_drill_default = netSettings->GetDefaultNetclass()->GetViaDrill();
538 for(
unsigned v = 0; v < wire_via.
m_vertexes.size(); ++v )
539 aCommit.
Add(
makeVIA( &wire_via, padstack, wire_via.
m_vertexes[v], netCode, via_drill_default ) );
546 wxLogWarning( wxString::Format(
_(
"%d session item(s) were skipped due to unresolved "
547 "reference, layer, or padstack." ), skipped ) );
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static TOOL_ACTION selectionClear
Clear the current selection.
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
virtual void Revert() override
Revert the commit by restoring the modified items state.
virtual bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
std::shared_ptr< NET_SETTINGS > m_NetSettings
void SetLocked(bool aLocked) override
Information pertinent to a Pcbnew printed circuit board.
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
const TRACKS & Tracks() const
FOOTPRINT * FindFootprintByReference(const wxString &aReference) const
Search for a FOOTPRINT within this board with the given reference designator.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
void DeleteMARKERs()
Delete all MARKERS from the board.
Represent a set of changes (additions, deletions or modifications) of a data model (e....
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Implement a <component_descriptor> in the specctra dsn spec.
int Length() const
Return the number of ELEMs in this holder.
virtual UNIT_RES * GetUnits() const
Return the units for this section.
A <net_out_descriptor> of the specctra dsn spec.
Hold either a via or a pad definition.
std::string m_padstack_id
Support both the <path_descriptor> and the <polygon_descriptor> per the specctra dsn spec.
std::vector< POINT > points
Implement a <placement_reference> in the specctra dsn spec.
std::string m_component_id
reference designator
A "(shape ..)" element in the specctra dsn spec.
A DSN data tree, usually coming from a DSN file.
void buildLayerMaps(BOARD *aBoard)
Create a few data translation structures for layer name and number mapping between the DSN::PCB struc...
PCB_TRACK * makeTRACK(WIRE *wire, PATH *aPath, int aPointIndex, int aNetcode)
Create a TRACK form the PATH and BOARD info.
std::map< int, PCB_LAYER_ID > m_pcbLayer2kicad
maps PCB layer number to BOARD layer numbers
UNIT_RES * m_routeResolution
used during FromSESSION() only, memory for it is not owned here.
BOARD * m_sessionBoard
a copy to avoid passing as an argument, memory for it is not owned here.
void FromSESSION(BOARD *aBoard, COMMIT &aCommit)
Add the entire SESSION info to a BOARD but does not write it out.
void LoadSESSION(const wxString &aFilename)
A recursive descent parser for a SPECCTRA DSN "session" file.
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 given...
PCB_ARC * makeARC(WIRE *wire, QARC *aQarc, int aNetcode)
Create an ARC form the PATH and BOARD info.
int findLayerName(const std::string &aLayerName) const
Return the PCB layer index for a given layer name, within the specctra sessionfile.
A holder for either a T_unit or T_resolution object which are usually mutually exclusive in the dsn g...
DSN_T GetEngUnits() const
A <wire_via_descriptor> in the specctra dsn spec.
const std::string & GetPadstackId()
std::vector< POINT > m_vertexes
A <wire_shape_descriptor> in the specctra dsn spec.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Handle the data for a net.
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
void SetMid(const VECTOR2I &aMid)
bool ImportSpecctraSession(const wxString &aFullFilename)
Import a specctra *.ses file and use it to relocate footprints and to replace all vias and tracks in ...
void SetEnd(const VECTOR2I &aEnd)
void SetStart(const VECTOR2I &aStart)
const VECTOR2I & GetStart() const
const VECTOR2I & GetEnd() const
virtual void SetWidth(int aWidth)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_IO_ERRORF(msg,...)
This file contains miscellaneous commonly used macros and functions.
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
This source file implements export and import capabilities to the specctra dsn file format.
const char * GetTokenText(T aTok)
The DSN namespace and returns the C string representing a SPECCTRA_DB::keyword.
static POINT mapPt(const VECTOR2I &pt)
Convert a KiCad point into a DSN file point.
static double scale(int kicadDist)
Convert a distance from Pcbnew internal units to the reported Specctra DSN units in floating point fo...
bool ImportSpecctraSession(BOARD *aBoard, const wxString &fullFileName, COMMIT &aCommit)
Helper method to import SES file to a board.
#define UNDEFINED_DRILL_DIAMETER
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
wxString From_UTF8(const char *cstring)
A point in the SPECCTRA DSN coordinate system.
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
const VECTOR2I CalcArcMid(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aMinArcAngle=true)
Return the middle point of an arc, half-way between aStart and aEnd.
VECTOR2< int32_t > VECTOR2I