Commit 343e55b0 authored by Dick Hollenbeck's avatar Dick Hollenbeck

First working copy of KICAD_PLUGIN::Load()

parent 0fb4954f
...@@ -46,8 +46,8 @@ ...@@ -46,8 +46,8 @@
*/ */
#define IO_FORMAT _( "IO_ERROR: %s\n from %s : %s" ) #define IO_FORMAT _( "IO_ERROR: %s\nfrom %s : %s" )
#define PARSE_FORMAT _( "PARSE_ERROR: %s in input/source \"%s\", line %d, offset %d\n from %s : %s" ) #define PARSE_FORMAT _( "PARSE_ERROR: %s in input/source \"%s\", line %d, offset %d\nfrom %s : %s" )
// references: // references:
// http://stackoverflow.com/questions/2670816/how-can-i-use-the-compile-time-constant-line-in-a-string // http://stackoverflow.com/questions/2670816/how-can-i-use-the-compile-time-constant-line-in-a-string
......
...@@ -221,6 +221,14 @@ wxPoint DRAWSEGMENT::GetEnd() const ...@@ -221,6 +221,14 @@ wxPoint DRAWSEGMENT::GetEnd() const
} }
void DRAWSEGMENT::SetAngle( double aAngle )
{
NORMALIZE_ANGLE_360( aAngle );
m_Angle = (int) aAngle;
}
MODULE* DRAWSEGMENT::GetParentModule() const MODULE* DRAWSEGMENT::GetParentModule() const
{ {
if( m_Parent->Type() != PCB_MODULE_T ) if( m_Parent->Type() != PCB_MODULE_T )
......
...@@ -46,7 +46,12 @@ public: ...@@ -46,7 +46,12 @@ public:
void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; } void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; }
void SetAngle( double aAngle ) { m_Angle = (int) aAngle; } /**
* Function SetAngle
* sets the angle for arcs, and normalizes it within the range 0 - 360 degrees.
* @param aAngle is tenths of degrees, but will soon be degrees.
*/
void SetAngle( double aAngle ); // encapsulates the transition to degrees
void SetType( int aType ) { m_Type = aType; } void SetType( int aType ) { m_Type = aType; }
......
...@@ -58,7 +58,6 @@ public: ...@@ -58,7 +58,6 @@ public:
*/ */
void DisplayInfo( EDA_DRAW_FRAME* frame ); void DisplayInfo( EDA_DRAW_FRAME* frame );
/** /**
* Function GetClass * Function GetClass
* returns the class name. * returns the class name.
......
...@@ -185,6 +185,17 @@ void D_PAD::SetPadName( const wxString& name ) ...@@ -185,6 +185,17 @@ void D_PAD::SetPadName( const wxString& name )
m_Padname[ii] = 0; m_Padname[ii] = 0;
} }
void D_PAD::SetPadName( const char* aName )
{
unsigned i;
for( i=0; i<sizeof(m_Padname) && *aName; ++i )
m_Padname[i] = *aName++;
while( i < sizeof(m_Padname) )
m_Padname[i++] = 0;
}
/** /**
* Function SetNetname * Function SetNetname
......
...@@ -183,7 +183,20 @@ public: ...@@ -183,7 +183,20 @@ public:
void SetDelta( const wxSize& aSize ) { m_DeltaSize = aSize; } void SetDelta( const wxSize& aSize ) { m_DeltaSize = aSize; }
void SetDrillSize( const wxSize& aSize ) { m_Drill = aSize; } void SetDrillSize( const wxSize& aSize ) { m_Drill = aSize; }
void SetOffset( const wxSize& aOffset ) { m_Offset = aOffset; } void SetOffset( const wxSize& aOffset ) { m_Offset = aOffset; }
void SetOrientation( int aAngle ) { m_Orient = aAngle; }
/**
* Function SetOrientation
* sets the rotation angle of the pad.
* @param aAngle is tenths of degrees, but will soon be degrees.
*/
void SetOrientation( double aAngle ) { m_Orient = (int) aAngle; } // manage migration to degrees
/**
* Function GetOrientation
* returns the rotation angle of the pad in tenths of degress, but soon degress.
*/
double GetOrientation() const { return m_Orient; }
void SetDrillShape( int aDrillShape ) { m_DrillShape = aDrillShape; } void SetDrillShape( int aDrillShape ) { m_DrillShape = aDrillShape; }
void SetLayerMask( int aLayerMask ) { m_layerMask = aLayerMask; } void SetLayerMask( int aLayerMask ) { m_layerMask = aLayerMask; }
void SetAttribute( int aAttribute ) { m_Attribut = aAttribute; } void SetAttribute( int aAttribute ) { m_Attribut = aAttribute; }
...@@ -313,6 +326,7 @@ public: ...@@ -313,6 +326,7 @@ public:
// others // others
void SetPadName( const wxString& name ); // Change pad name void SetPadName( const wxString& name ); // Change pad name
void SetPadName( const char* aName );
wxString ReturnStringPadName() const; // Return pad name as string in a wxString wxString ReturnStringPadName() const; // Return pad name as string in a wxString
......
...@@ -50,11 +50,19 @@ public: ...@@ -50,11 +50,19 @@ public:
return m_Pos; // from EDA_TEXT return m_Pos; // from EDA_TEXT
} }
/// @deprecated it seems
void SetType( int aType ) { m_Type = aType; }
void SetPosition( const wxPoint& aPos ) // overload a base void SetPosition( const wxPoint& aPos ) // overload a base
{ {
m_Pos = aPos; // in EDA_TEXT m_Pos = aPos; // in EDA_TEXT
} }
void SetVisible( bool isVisible ) { m_NoShow = !isVisible; }
void SetInvisible( bool isHidden ) { m_NoShow = isHidden; }
void SetPos0( const wxPoint& aPos ) { m_Pos0 = aPos; }
void Copy( TEXTE_MODULE* source ); // copy structure void Copy( TEXTE_MODULE* source ); // copy structure
int GetLength() const; /* text length */ int GetLength() const; /* text length */
......
...@@ -280,10 +280,12 @@ this file again." ) ); ...@@ -280,10 +280,12 @@ this file again." ) );
if( !aAppend ) if( !aAppend )
SetBoard( board ); SetBoard( board );
} }
catch ( IO_ERROR ioe ) catch( IO_ERROR ioe )
{ {
// @todo wxString msg = wxString::Format( _( "Error loading board.\n%s" ),
printf( "Error loading board: %s\n", TO_UTF8( ioe.errorText ) ); ioe.errorText.GetData() );
wxMessageBox( msg, _( "Open Board File" ), wxICON_ERROR );
} }
if( !aAppend ) if( !aAppend )
......
...@@ -66,17 +66,15 @@ void IO_MGR::PluginRelease( PLUGIN* aPlugin ) ...@@ -66,17 +66,15 @@ void IO_MGR::PluginRelease( PLUGIN* aPlugin )
} }
const wxString& IO_MGR::ShowType( PCB_FILE_T aFileType ) const wxString IO_MGR::ShowType( PCB_FILE_T aFileType )
{ {
static const wxString kicad = wxT( "KiCad" );
static const wxString unknown = _( "Unknown" );
switch( aFileType ) switch( aFileType )
{ {
case KICAD:
return kicad;
default: default:
return unknown; // could Printf() the numeric value of aFileType return wxString::Format( _( "Unknown PCB_FILE_T value: %d" ), aFileType );
case KICAD:
return wxString( wxT( "KiCad" ) );
} }
} }
...@@ -92,11 +90,7 @@ BOARD* IO_MGR::Load( PCB_FILE_T aFileType, const wxString& aFileName, ...@@ -92,11 +90,7 @@ BOARD* IO_MGR::Load( PCB_FILE_T aFileType, const wxString& aFileName,
return pi->Load( aFileName, aAppendToMe, aProperties ); // virtual return pi->Load( aFileName, aAppendToMe, aProperties ); // virtual
} }
wxString msg; THROW_IO_ERROR( wxString::Format( _( "Plugin type '%s' is not found." ), ShowType( aFileType ).GetData() ) );
msg.Printf( _( "Plugin type '%s' is not found.\n" ), ShowType( aFileType ).GetData() );
THROW_IO_ERROR( msg );
} }
...@@ -111,11 +105,7 @@ void IO_MGR::Save( PCB_FILE_T aFileType, const wxString& aFileName, BOARD* aBoar ...@@ -111,11 +105,7 @@ void IO_MGR::Save( PCB_FILE_T aFileType, const wxString& aFileName, BOARD* aBoar
return; return;
} }
wxString msg; THROW_IO_ERROR( wxString::Format( _( "Plugin type '%s' is not found." ), ShowType( aFileType ).GetData() ) );
msg.Printf( _( "Plugin type '%s' is not found." ), ShowType( aFileType ).GetData() );
THROW_IO_ERROR( msg );
} }
...@@ -124,12 +114,8 @@ BOARD* PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES* ...@@ -124,12 +114,8 @@ BOARD* PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES*
// not pure virtual so that plugins only have to implement subset of the PLUGIN interface, // not pure virtual so that plugins only have to implement subset of the PLUGIN interface,
// e.g. Load() or Save() but not both. // e.g. Load() or Save() but not both.
wxString msg; THROW_IO_ERROR( wxString::Format(
_( "Plugin %s does not implement the BOARD Load() function." ), PluginName().GetData() ) );
msg.Printf( _( "Plugin %s does not implement the BOARD Load() function." ),
PluginName().GetData() );
THROW_IO_ERROR( msg );
} }
...@@ -138,11 +124,6 @@ void PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, PROPERTIES* aProper ...@@ -138,11 +124,6 @@ void PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, PROPERTIES* aProper
// not pure virtual so that plugins only have to implement subset of the PLUGIN interface, // not pure virtual so that plugins only have to implement subset of the PLUGIN interface,
// e.g. Load() or Save() but not both. // e.g. Load() or Save() but not both.
wxString msg; THROW_IO_ERROR( wxString::Format(
_( "Plugin %s does not implement the BOARD Save() function." ), PluginName().GetData() ) );
msg.Printf( _( "Plugin %s does not implement the BOARD Save() function." ),
PluginName().GetData() );
THROW_IO_ERROR( msg );
} }
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
WX_DECLARE_STRING_HASH_MAP( wxString, PROPERTIES ); WX_DECLARE_STRING_HASH_MAP( wxString, PROPERTIES );
class BOARD; class BOARD;
class SCHEMATIC;
class PLUGIN; class PLUGIN;
...@@ -88,7 +87,7 @@ public: ...@@ -88,7 +87,7 @@ public:
* Function ShowType * Function ShowType
* returns a brief name for a plugin, given aFileType enum. * returns a brief name for a plugin, given aFileType enum.
*/ */
static const wxString& ShowType( PCB_FILE_T aFileType ); static const wxString ShowType( PCB_FILE_T aFileType );
/** /**
* Function Load * Function Load
...@@ -268,6 +267,8 @@ public: ...@@ -268,6 +267,8 @@ public:
//-----<SCHEMATIC STUFF>------------------------------------------------ //-----<SCHEMATIC STUFF>------------------------------------------------
// Should split into schematic specific PLUGIN base type // Should split into schematic specific PLUGIN base type
class SCHEMATIC;
/** /**
* Function Load * Function Load
* loads a file from some special input file format that * loads a file from some special input file format that
......
...@@ -228,9 +228,10 @@ BOARD* KICAD_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, PROPER ...@@ -228,9 +228,10 @@ BOARD* KICAD_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, PROPER
THROW_IO_ERROR( m_error ); THROW_IO_ERROR( m_error );
} }
// reader now owns fp, will close on exception or return
FILE_LINE_READER reader( fp, aFileName ); FILE_LINE_READER reader( fp, aFileName );
aReader = &reader; aReader = &reader; // member function accessibility
init( aProperties ); init( aProperties );
...@@ -331,7 +332,7 @@ void KICAD_PLUGIN::loadAllSections( bool doAppend ) ...@@ -331,7 +332,7 @@ void KICAD_PLUGIN::loadAllSections( bool doAppend )
{ {
while( READLINE() ) while( READLINE() )
{ {
line = aReader->Line(); // gobble til $EndSetup line = aReader->Line(); // gobble until $EndSetup
if( TESTLINE( "$EndSETUP" ) ) if( TESTLINE( "$EndSETUP" ) )
break; break;
...@@ -579,23 +580,8 @@ void KICAD_PLUGIN::loadSETUP() ...@@ -579,23 +580,8 @@ void KICAD_PLUGIN::loadSETUP()
if( TESTLINE( "PcbPlotParams" ) ) if( TESTLINE( "PcbPlotParams" ) )
{ {
PCB_PLOT_PARAMS_PARSER parser( line + SZ( "PcbPlotParams" ), aReader->GetSource() ); PCB_PLOT_PARAMS_PARSER parser( line + SZ( "PcbPlotParams" ), aReader->GetSource() );
// try
{
g_PcbPlotOptions.Parse( &parser ); g_PcbPlotOptions.Parse( &parser );
} }
/* move this higher up
catch( IO_ERROR& e )
{
wxString msg;
msg.Printf( _( "Error reading PcbPlotParams from %s:\n%s" ),
aReader->GetSource().GetData(),
e.errorText.GetData() );
wxMessageBox( msg, _( "Open Board File" ), wxICON_ERROR );
}
*/
}
else if( TESTLINE( "AuxiliaryAxisOrg" ) ) else if( TESTLINE( "AuxiliaryAxisOrg" ) )
{ {
...@@ -892,7 +878,7 @@ void KICAD_PLUGIN::loadMODULE() ...@@ -892,7 +878,7 @@ void KICAD_PLUGIN::loadMODULE()
// most frequently encountered ones at the top // most frequently encountered ones at the top
if( TESTLINE( "D" ) ) // read a drawing item if( TESTLINE( "D" ) ) // read a drawing item, e.g. "DS"
{ {
loadEDGE_MODULE( module.get() ); loadEDGE_MODULE( module.get() );
/* /*
...@@ -1054,13 +1040,13 @@ void KICAD_PLUGIN::loadPAD( MODULE* aModule ) ...@@ -1054,13 +1040,13 @@ void KICAD_PLUGIN::loadPAD( MODULE* aModule )
if( TESTLINE( "Sh" ) ) // (Sh)ape and padname if( TESTLINE( "Sh" ) ) // (Sh)ape and padname
{ {
// e.g. "Sh "A2" C 520 520 0 0 900" // e.g. "Sh "A2" C 520 520 0 0 900"
// "Sh "1" R 157 1378 0 0 900" // or "Sh "1" R 157 1378 0 0 900"
char padname[sizeof(pad->m_Padname)+1]; char padname[sizeof(pad->m_Padname)+1];
data = line + SZ( "Sh" ); data = line + SZ( "Sh" ) + 1; // +1 skips trailing whitespace
data = data + ReadDelimitedText( padname, data, sizeof(padname) ) + 1; data = data + ReadDelimitedText( padname, data, sizeof(padname) ) + 1; // +1 trailing whitespace
// sscanf( PtLine, " %s %d %d %d %d %d", BufCar, &m_Size.x, &m_Size.y, &m_DeltaSize.x, &m_DeltaSize.y, &m_Orient ); // sscanf( PtLine, " %s %d %d %d %d %d", BufCar, &m_Size.x, &m_Size.y, &m_DeltaSize.x, &m_DeltaSize.y, &m_Orient );
...@@ -1069,17 +1055,22 @@ void KICAD_PLUGIN::loadPAD( MODULE* aModule ) ...@@ -1069,17 +1055,22 @@ void KICAD_PLUGIN::loadPAD( MODULE* aModule )
BIU size_y = biuParse( data, &data ); BIU size_y = biuParse( data, &data );
BIU delta_x = biuParse( data, &data ); BIU delta_x = biuParse( data, &data );
BIU delta_y = biuParse( data, &data ); BIU delta_y = biuParse( data, &data );
int orient = intParse( data ); double orient = degParse( data );
switch( padshape ) switch( padshape )
{ {
default:
case 'C': padshape = PAD_CIRCLE; break; case 'C': padshape = PAD_CIRCLE; break;
case 'R': padshape = PAD_RECT; break; case 'R': padshape = PAD_RECT; break;
case 'O': padshape = PAD_OVAL; break; case 'O': padshape = PAD_OVAL; break;
case 'T': padshape = PAD_TRAPEZOID; break; case 'T': padshape = PAD_TRAPEZOID; break;
default:
m_error.Printf( _( "Unknown padshape '%s' on line:%d" ),
FROM_UTF8( line ).GetData(), aReader->LineNumber() );
THROW_IO_ERROR( m_error );
} }
pad->SetPadName( padname );
pad->SetShape( padshape );
pad->SetSize( wxSize( size_x, size_y ) ); pad->SetSize( wxSize( size_x, size_y ) );
pad->SetDelta( wxSize( delta_x, delta_y ) ); pad->SetDelta( wxSize( delta_x, delta_y ) );
pad->SetOrientation( orient ); pad->SetOrientation( orient );
...@@ -1249,14 +1240,12 @@ void KICAD_PLUGIN::loadEDGE_MODULE( MODULE* aModule ) ...@@ -1249,14 +1240,12 @@ void KICAD_PLUGIN::loadEDGE_MODULE( MODULE* aModule )
BIU start0_y = biuParse( data, &data ); BIU start0_y = biuParse( data, &data );
BIU end0_x = biuParse( data, &data ); BIU end0_x = biuParse( data, &data );
BIU end0_y = biuParse( data, &data ); BIU end0_y = biuParse( data, &data );
double angle = dblParse( data, &data ); double angle = degParse( data, &data );
width = biuParse( data, &data ); width = biuParse( data, &data );
layer = intParse( data ); layer = intParse( data );
// @todo put in accessor dwg->SetAngle( angle );
NORMALIZE_ANGLE_360( angle );
dwg->m_Start0 = wxPoint( start0_x, start0_y ); dwg->m_Start0 = wxPoint( start0_x, start0_y );
dwg->m_End0 = wxPoint( end0_x, end0_y ); dwg->m_End0 = wxPoint( end0_x, end0_y );
} }
...@@ -1282,40 +1271,47 @@ void KICAD_PLUGIN::loadEDGE_MODULE( MODULE* aModule ) ...@@ -1282,40 +1271,47 @@ void KICAD_PLUGIN::loadEDGE_MODULE( MODULE* aModule )
break; break;
case S_POLYGON: case S_POLYGON:
#if 0 // @todo
{ {
int pointCount; // e.g. "DP %d %d %d %d %d %d %d\n"
sscanf( Line + 3, "%d %d %d %d %d %d %d", &m_Start0.x, &m_Start0.y, &m_End0.x, &m_End0.y, &pointCount, &m_Width, &m_Layer ); // sscanf( Line + 3, "%d %d %d %d %d %d %d", &m_Start0.x, &m_Start0.y, &m_End0.x, &m_End0.y, &pointCount, &m_Width, &m_Layer );
m_PolyPoints.clear(); BIU start0_x = biuParse( line + SZ( "DP" ), &data );
m_PolyPoints.reserve( pointCount ); BIU start0_y = biuParse( data, &data );
BIU end0_x = biuParse( data, &data );
BIU end0_y = biuParse( data, &data );
int ptCount = intParse( data, &data );
for( ii = 0; ii<pointCount; ii++ ) width = biuParse( data, &data );
{ layer = intParse( data );
if( READLINE() )
{ dwg->m_Start0 = wxPoint( start0_x, start0_y );
Buf = aReader->Line(); dwg->m_End0 = wxPoint( end0_x, end0_y );
std::vector<wxPoint>& pts = dwg->GetPolyPoints();
pts.reserve( ptCount );
if( strncmp( Buf, "Dl", 2 ) != 0 ) for( int ii = 0; ii<ptCount; ++ii )
{ {
error = 1; if( !READLINE() )
break; {
THROW_IO_ERROR( wxT( "S_POLGON point count mismatch." ) );
} }
int x; line = aReader->Line();
int y;
sscanf( Buf + 3, "%d %d\n", &x, &y );
m_PolyPoints.push_back( wxPoint( x, y ) ); // e.g. "Dl 23 44\n"
}
else if( !TESTLINE( "Dl" ) )
{ {
error = 1; THROW_IO_ERROR( wxT( "Missing Dl point def" ) );
break;
} }
BIU x = biuParse( line + SZ( "Dl" ), &data );
BIU y = biuParse( data );
pts.push_back( wxPoint( x, y ) );
} }
} }
#endif
break; break;
default: default:
...@@ -1345,7 +1341,7 @@ void KICAD_PLUGIN::loadEDGE_MODULE( MODULE* aModule ) ...@@ -1345,7 +1341,7 @@ void KICAD_PLUGIN::loadEDGE_MODULE( MODULE* aModule )
EDGE_MODULE* em = dwg.release(); EDGE_MODULE* em = dwg.release();
m_board->m_Drawings.PushBack( em ); aModule->m_Drawings.PushBack( em );
// this had been done at the MODULE level before, presumably because it needs // this had been done at the MODULE level before, presumably because it needs
// to be already added to a module before this function will work. // to be already added to a module before this function will work.
...@@ -1355,7 +1351,92 @@ void KICAD_PLUGIN::loadEDGE_MODULE( MODULE* aModule ) ...@@ -1355,7 +1351,92 @@ void KICAD_PLUGIN::loadEDGE_MODULE( MODULE* aModule )
void KICAD_PLUGIN::loadTEXTE_MODULE( TEXTE_MODULE* aText ) void KICAD_PLUGIN::loadTEXTE_MODULE( TEXTE_MODULE* aText )
{ {
// @todo const char* data;
char* line = aReader->Line(); // current (old) line
// sscanf( line + 1, "%d %d %d %d %d %d %d %s %s %d %s", &type, &m_Pos0.x, &m_Pos0.y, &m_Size.y, &m_Size.x,
// &m_Orient, &m_Thickness, BufCar1, BufCar2, &layer, BufCar3 ) >= 10 )
// e.g. "T1 6940 -16220 350 300 900 60 M I 20 N "CFCARD"\r\n"
int type = intParse( line+1, &data );
BIU pos0_x = biuParse( data, &data );
BIU pos0_y = biuParse( data, &data );
BIU size0_x = biuParse( data, &data );
BIU size0_y = biuParse( data, &data );
double orient = degParse( data, &data );
BIU thickn = biuParse( data, &data );
// after switching to strtok, there's no easy coming back because of the
// embedded nul(s?) placed to the right of the current field.
char* mirror = strtok( (char*) data, delims );
char* hide = strtok( NULL, delims );
char* tmp = strtok( NULL, delims );
int layer = tmp ? intParse( tmp ) : SILKSCREEN_N_FRONT;
char* italic = strtok( NULL, delims );
char* text = strtok( NULL, delims );
if( type != TEXT_is_REFERENCE && type != TEXT_is_VALUE )
type = TEXT_is_DIVERS;
aText->SetType( type );
aText->SetPos0( wxPoint( pos0_x, pos0_y ) );
/* @todo move to accessor? cannot reach these defines from here
pcbnew.h off limit because of globals in there
// Test for a reasonable size:
if( size0_x < TEXTS_MIN_SIZE )
size0_x = TEXTS_MIN_SIZE;
if( size0_y < TEXTS_MIN_SIZE )
size0_y = TEXTS_MIN_SIZE;
*/
aText->SetSize( wxSize( size0_x, size0_y ) );
// Due to the Pcbnew history, .m_Orient is saved in screen value
// but it is handled as relative to its parent footprint
// @todo is there now an opportunity for a better way as we move to degrees and
// a new file format?
orient -= ( (MODULE*) aText->GetParent() )->GetOrientation();
aText->SetOrientation( orient );
// @todo put in accessors?
// Set a reasonable width:
if( thickn < 1 )
thickn = 1;
aText->SetThickness( Clamp_Text_PenSize( thickn, aText->GetSize() ) );
aText->SetMirrored( mirror && *mirror == 'M' );
aText->SetInvisible( hide && *hide == 'I' );
aText->SetItalic( italic && *italic == 'I' );
// @todo put in accessor?
// Test for a reasonable layer:
if( layer < 0 )
layer = 0;
if( layer > LAST_NO_COPPER_LAYER )
layer = LAST_NO_COPPER_LAYER;
if( layer == LAYER_N_BACK )
layer = SILKSCREEN_N_BACK;
else if( layer == LAYER_N_FRONT )
layer = SILKSCREEN_N_FRONT;
aText->SetLayer( layer );
// Calculate the actual position.
aText->SetDrawCoord();
// convert the "quoted, escaped, UTF8, text" to a wxString
wxString wtext;
ReadDelimitedText( &wtext, text ? text : "" );
aText->SetText( wtext );
} }
...@@ -1424,9 +1505,7 @@ void KICAD_PLUGIN::loadDRAWSEGMENT() ...@@ -1424,9 +1505,7 @@ void KICAD_PLUGIN::loadDRAWSEGMENT()
$EndDRAWSEGMENT $EndDRAWSEGMENT
*/ */
// immediately save object in tree, so if exception, no memory leak auto_ptr<DRAWSEGMENT> dseg( new DRAWSEGMENT( m_board ) );
DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
m_board->Add( dseg, ADD_APPEND );
while( READLINE() ) while( READLINE() )
{ {
...@@ -1483,7 +1562,7 @@ void KICAD_PLUGIN::loadDRAWSEGMENT() ...@@ -1483,7 +1562,7 @@ void KICAD_PLUGIN::loadDRAWSEGMENT()
break; break;
case 2: case 2:
double angle; double angle;
angle = dblParse( data ); angle = degParse( data );
dseg->SetAngle( angle ); // m_Angle dseg->SetAngle( angle ); // m_Angle
break; break;
case 3: case 3:
...@@ -1521,8 +1600,11 @@ void KICAD_PLUGIN::loadDRAWSEGMENT() ...@@ -1521,8 +1600,11 @@ void KICAD_PLUGIN::loadDRAWSEGMENT()
} }
else if( TESTLINE( "$EndDRAWSEGMENT" ) ) else if( TESTLINE( "$EndDRAWSEGMENT" ) )
{
m_board->Add( dseg.release(), ADD_APPEND );
return; // preferred exit return; // preferred exit
} }
}
THROW_IO_ERROR( wxT( "Missing '$EndDRAWSEGMENT'" ) ); THROW_IO_ERROR( wxT( "Missing '$EndDRAWSEGMENT'" ) );
} }
...@@ -1808,7 +1890,7 @@ void KICAD_PLUGIN::loadNETCLASS() ...@@ -1808,7 +1890,7 @@ void KICAD_PLUGIN::loadNETCLASS()
// yet since that would bypass duplicate netclass name checking within the BOARD. // yet since that would bypass duplicate netclass name checking within the BOARD.
// store it temporarily in an auto_ptr until successfully inserted into the BOARD // store it temporarily in an auto_ptr until successfully inserted into the BOARD
// just before returning. // just before returning.
auto_ptr<NETCLASS> netclass( new NETCLASS( m_board, wxEmptyString ) ); auto_ptr<NETCLASS> nc( new NETCLASS( m_board, wxEmptyString ) );
while( READLINE() ) while( READLINE() )
{ {
...@@ -1816,77 +1898,78 @@ void KICAD_PLUGIN::loadNETCLASS() ...@@ -1816,77 +1898,78 @@ void KICAD_PLUGIN::loadNETCLASS()
if( TESTLINE( "AddNet" ) ) // most frequent type of line if( TESTLINE( "AddNet" ) ) // most frequent type of line
{ {
// e.g. "AddNet "V3.3D"\n"
ReadDelimitedText( buf, line + SZ( "AddNet" ), sizeof(buf) ); ReadDelimitedText( buf, line + SZ( "AddNet" ), sizeof(buf) );
netname = FROM_UTF8( buf ); netname = FROM_UTF8( buf );
netclass->Add( netname ); nc->Add( netname );
}
else if( TESTLINE( "$EndNCLASS" ) )
{
if( m_board->m_NetClasses.Add( netclass.get() ) )
{
netclass.release();
}
else
{
// Must have been a name conflict, this is a bad board file.
// User may have done a hand edit to the file.
// auto_ptr will delete netclass on this code path
m_error.Printf( _( "duplicate NETCLASS name '%s'" ), netclass->GetName().GetData() );
THROW_IO_ERROR( m_error );
}
return; // preferred exit
} }
else if( TESTLINE( "Clearance" ) ) else if( TESTLINE( "Clearance" ) )
{ {
BIU tmp = biuParse( line + SZ( "Clearance" ) ); BIU tmp = biuParse( line + SZ( "Clearance" ) );
netclass->SetClearance( tmp ); nc->SetClearance( tmp );
} }
else if( TESTLINE( "TrackWidth" ) ) else if( TESTLINE( "TrackWidth" ) )
{ {
BIU tmp = biuParse( line + SZ( "TrackWidth" ) ); BIU tmp = biuParse( line + SZ( "TrackWidth" ) );
netclass->SetTrackWidth( tmp ); nc->SetTrackWidth( tmp );
} }
else if( TESTLINE( "ViaDia" ) ) else if( TESTLINE( "ViaDia" ) )
{ {
BIU tmp = biuParse( line + SZ( "ViaDia" ) ); BIU tmp = biuParse( line + SZ( "ViaDia" ) );
netclass->SetViaDiameter( tmp ); nc->SetViaDiameter( tmp );
} }
else if( TESTLINE( "ViaDrill" ) ) else if( TESTLINE( "ViaDrill" ) )
{ {
BIU tmp = biuParse( line + SZ( "ViaDrill" ) ); BIU tmp = biuParse( line + SZ( "ViaDrill" ) );
netclass->SetViaDrill( tmp ); nc->SetViaDrill( tmp );
} }
else if( TESTLINE( "uViaDia" ) ) else if( TESTLINE( "uViaDia" ) )
{ {
BIU tmp = biuParse( line + SZ( "uViaDia" ) ); BIU tmp = biuParse( line + SZ( "uViaDia" ) );
netclass->SetuViaDiameter( tmp ); nc->SetuViaDiameter( tmp );
} }
else if( TESTLINE( "uViaDrill" ) ) else if( TESTLINE( "uViaDrill" ) )
{ {
BIU tmp = biuParse( line + SZ( "uViaDrill" ) ); BIU tmp = biuParse( line + SZ( "uViaDrill" ) );
netclass->SetuViaDrill( tmp ); nc->SetuViaDrill( tmp );
} }
else if( TESTLINE( "Name" ) ) else if( TESTLINE( "Name" ) )
{ {
ReadDelimitedText( buf, line + SZ( "Name" ), sizeof(buf) ); ReadDelimitedText( buf, line + SZ( "Name" ), sizeof(buf) );
netclass->SetName( FROM_UTF8( buf ) ); nc->SetName( FROM_UTF8( buf ) );
} }
else if( TESTLINE( "Desc" ) ) else if( TESTLINE( "Desc" ) )
{ {
ReadDelimitedText( buf, line + SZ( "Desc" ), sizeof(buf) ); ReadDelimitedText( buf, line + SZ( "Desc" ), sizeof(buf) );
netclass->SetDescription( FROM_UTF8( buf ) ); nc->SetDescription( FROM_UTF8( buf ) );
}
else if( TESTLINE( "$EndNCLASS" ) )
{
if( m_board->m_NetClasses.Add( nc.get() ) )
{
nc.release();
}
else
{
// Must have been a name conflict, this is a bad board file.
// User may have done a hand edit to the file.
// auto_ptr will delete nc on this code path
m_error.Printf( _( "duplicate NETCLASS name '%s'" ), nc->GetName().GetData() );
THROW_IO_ERROR( m_error );
}
return; // preferred exit
} }
} }
...@@ -1900,24 +1983,22 @@ void KICAD_PLUGIN::loadZONE_CONTAINER() ...@@ -1900,24 +1983,22 @@ void KICAD_PLUGIN::loadZONE_CONTAINER()
int outline_hatch = CPolyLine::NO_HATCH; int outline_hatch = CPolyLine::NO_HATCH;
bool sawCorner = false; bool sawCorner = false;
int layer = 0; char buf[1024];
while( READLINE() ) while( READLINE() )
{ {
const char* data;
char* line = aReader->Line(); char* line = aReader->Line();
if( TESTLINE( "ZCorner" ) ) // new corner found if( TESTLINE( "ZCorner" ) ) // new corner found
{ {
// e.g. "ZCorner 25650 49500 0" // e.g. "ZCorner 25650 49500 0"
BIU x = biuParse( line + SZ( "ZCorner" ), &data );
const char* data = line + SZ( "ZCorner" );
BIU x = biuParse( data, &data );
BIU y = biuParse( data, &data ); BIU y = biuParse( data, &data );
int flag = atoi( data ); int flag = atoi( data );
if( !sawCorner ) if( !sawCorner )
zc->m_Poly->Start( layer, x, y, outline_hatch ); zc->m_Poly->Start( zc->GetLayer(), x, y, outline_hatch );
else else
zc->AppendCorner( wxPoint( x, y ) ); zc->AppendCorner( wxPoint( x, y ) );
...@@ -1930,11 +2011,7 @@ void KICAD_PLUGIN::loadZONE_CONTAINER() ...@@ -1930,11 +2011,7 @@ void KICAD_PLUGIN::loadZONE_CONTAINER()
else if( TESTLINE( "ZInfo" ) ) // general info found else if( TESTLINE( "ZInfo" ) ) // general info found
{ {
// e.g. 'ZInfo 479194B1 310 "COMMON"' // e.g. 'ZInfo 479194B1 310 "COMMON"'
long timestamp = hexParse( line + SZ( "ZInfo" ), &data );
const char* data = line + SZ( "ZInfo" );
char buf[1024];
long timestamp = hexParse( data, &data );
int netcode = intParse( data, &data ); int netcode = intParse( data, &data );
if( ReadDelimitedText( buf, data, sizeof(buf) ) > (int) sizeof(buf) ) if( ReadDelimitedText( buf, data, sizeof(buf) ) > (int) sizeof(buf) )
...@@ -1949,55 +2026,42 @@ void KICAD_PLUGIN::loadZONE_CONTAINER() ...@@ -1949,55 +2026,42 @@ void KICAD_PLUGIN::loadZONE_CONTAINER()
else if( TESTLINE( "ZLayer" ) ) // layer found else if( TESTLINE( "ZLayer" ) ) // layer found
{ {
char* data = line + SZ( "ZLayer" ); int layer = intParse( line + SZ( "ZLayer" ) );
zc->SetLayer( layer );
layer = atoi( data );
} }
else if( TESTLINE( "ZAux" ) ) // aux info found else if( TESTLINE( "ZAux" ) ) // aux info found
{ {
// e.g. "ZAux 7 E" // e.g. "ZAux 7 E"
int ignore = intParse( line + SZ( "ZAux" ), &data );
char* hopt = strtok( (char*) data, delims );
char* data = line + SZ( "ZAux" ); if( !hopt )
int x;
char hopt[10];
int ret = sscanf( data, "%d %c", &x, hopt );
if( ret < 2 )
{ {
m_error.Printf( wxT( "Bad ZAux for CZONE_CONTAINER '%s'" ), zc->GetNetName().GetData() ); m_error.Printf( wxT( "Bad ZAux for CZONE_CONTAINER '%s'" ), zc->GetNetName().GetData() );
THROW_IO_ERROR( m_error ); THROW_IO_ERROR( m_error );
} }
switch( hopt[0] ) // upper case required switch( *hopt ) // upper case required
{ {
case 'N': case 'N': outline_hatch = CPolyLine::NO_HATCH; break;
outline_hatch = CPolyLine::NO_HATCH; case 'E': outline_hatch = CPolyLine::DIAGONAL_EDGE; break;
break; case 'F': outline_hatch = CPolyLine::DIAGONAL_FULL; break;
case 'E':
outline_hatch = CPolyLine::DIAGONAL_EDGE;
break;
case 'F':
outline_hatch = CPolyLine::DIAGONAL_FULL;
break;
default: default:
m_error.Printf( wxT( "Bad ZAux for CZONE_CONTAINER '%s'" ), zc->GetNetName().GetData() ); m_error.Printf( wxT( "Bad ZAux for CZONE_CONTAINER '%s'" ), zc->GetNetName().GetData() );
THROW_IO_ERROR( m_error ); THROW_IO_ERROR( m_error );
} }
(void) ignore;
// Set hatch mode later, after reading corner outline data // Set hatch mode later, after reading corner outline data
} }
else if( TESTLINE( "ZSmoothing" ) ) else if( TESTLINE( "ZSmoothing" ) )
{ {
// e.g. "ZSmoothing 0 0" // e.g. "ZSmoothing 0 0"
int smoothing = intParse( line + SZ( "ZSmoothing" ), &data );
const char* data = line + SZ( "ZSmoothing" );
int smoothing = intParse( data, &data );
BIU cornerRadius = biuParse( data ); BIU cornerRadius = biuParse( data );
if( smoothing >= ZONE_SETTING::SMOOTHING_LAST || smoothing < 0 ) if( smoothing >= ZONE_SETTING::SMOOTHING_LAST || smoothing < 0 )
...@@ -2013,10 +2077,7 @@ void KICAD_PLUGIN::loadZONE_CONTAINER() ...@@ -2013,10 +2077,7 @@ void KICAD_PLUGIN::loadZONE_CONTAINER()
else if( TESTLINE( "ZOptions" ) ) else if( TESTLINE( "ZOptions" ) )
{ {
// e.g. "ZOptions 0 32 F 200 200" // e.g. "ZOptions 0 32 F 200 200"
int fillmode = intParse( line + SZ( "ZOptions" ), &data );
const char* data = line + SZ( "ZOptions" );
int fillmode = intParse( data, &data );
int arcsegcount = intParse( data, &data ); int arcsegcount = intParse( data, &data );
char fillstate = data[1]; // here e.g. " F" char fillstate = data[1]; // here e.g. " F"
BIU thermalReliefGap = biuParse( data += 2 , &data ); // +=2 for " F" BIU thermalReliefGap = biuParse( data += 2 , &data ); // +=2 for " F"
...@@ -2036,41 +2097,29 @@ void KICAD_PLUGIN::loadZONE_CONTAINER() ...@@ -2036,41 +2097,29 @@ void KICAD_PLUGIN::loadZONE_CONTAINER()
else if( TESTLINE( "ZClearance" ) ) // Clearance and pad options info found else if( TESTLINE( "ZClearance" ) ) // Clearance and pad options info found
{ {
// e.g. "ZClearance 40 I" // e.g. "ZClearance 40 I"
BIU clearance = biuParse( line + SZ( "ZClearance" ), &data );
char* padoption = strtok( (char*) data, delims ); // data: " I"
const char* data = line + SZ( "ZClearance" ); int popt;
switch( *padoption )
BIU clearance = biuParse( data, &data );
int padoption = data[1]; // e.g. " I"
zc->SetZoneClearance( clearance );
switch( padoption )
{ {
case 'I': case 'I': popt = PAD_IN_ZONE; break;
padoption = PAD_IN_ZONE; case 'T': popt = THERMAL_PAD; break;
break; case 'X': popt = PAD_NOT_IN_ZONE; break;
case 'T':
padoption = THERMAL_PAD;
break;
case 'X':
padoption = PAD_NOT_IN_ZONE;
break;
default: default:
m_error.Printf( wxT( "Bad ZClearance padoption for CZONE_CONTAINER '%s'" ), zc->GetNetName().GetData() ); m_error.Printf( wxT( "Bad ZClearance padoption for CZONE_CONTAINER '%s'" ),
zc->GetNetName().GetData() );
THROW_IO_ERROR( m_error ); THROW_IO_ERROR( m_error );
} }
zc->SetPadOption( padoption ); zc->SetZoneClearance( clearance );
zc->SetPadOption( popt );
} }
else if( TESTLINE( "ZMinThickness" ) ) else if( TESTLINE( "ZMinThickness" ) )
{ {
char* data = line + SZ( "ZMinThickness" ); BIU thickness = biuParse( line + SZ( "ZMinThickness" ) );
BIU thickness = biuParse( data );
zc->SetMinThickness( thickness ); zc->SetMinThickness( thickness );
} }
...@@ -2086,14 +2135,11 @@ void KICAD_PLUGIN::loadZONE_CONTAINER() ...@@ -2086,14 +2135,11 @@ void KICAD_PLUGIN::loadZONE_CONTAINER()
break; break;
// e.g. "39610 43440 0 0" // e.g. "39610 43440 0 0"
BIU x = biuParse( line, &data );
const char* data = line;
BIU x = biuParse( data, &data );
BIU y = biuParse( data, &data ); BIU y = biuParse( data, &data );
bool end_contour = (data[1] == '1'); // end_countour was a bool when file saved, so '0' or '1' here bool end_contour = intParse( data, &data ); // end_countour was a bool when file saved, so '0' or '1' here
int utility = atoi( data + 3 ); int utility = intParse( data );
zc->m_FilledPolysList.push_back( CPolyPt( x, y, end_contour, utility ) ); zc->m_FilledPolysList.push_back( CPolyPt( x, y, end_contour, utility ) );
} }
...@@ -2108,9 +2154,8 @@ void KICAD_PLUGIN::loadZONE_CONTAINER() ...@@ -2108,9 +2154,8 @@ void KICAD_PLUGIN::loadZONE_CONTAINER()
if( TESTLINE( "$endFILLSEGMENTS" ) ) if( TESTLINE( "$endFILLSEGMENTS" ) )
break; break;
const char* data = line; // e.g. ""%d %d %d %d\n"
BIU sx = biuParse( line, &data );
BIU sx = biuParse( data, &data );
BIU sy = biuParse( data, &data ); BIU sy = biuParse( data, &data );
BIU ex = biuParse( data, &data ); BIU ex = biuParse( data, &data );
BIU ey = biuParse( data ); BIU ey = biuParse( data );
...@@ -2134,7 +2179,7 @@ void KICAD_PLUGIN::loadZONE_CONTAINER() ...@@ -2134,7 +2179,7 @@ void KICAD_PLUGIN::loadZONE_CONTAINER()
zc->SetNet( 0 ); zc->SetNet( 0 );
} }
// Set hatch here, when outlines corners are read // Set hatch here, after outlines corners are read
zc->m_Poly->SetHatch( outline_hatch ); zc->m_Poly->SetHatch( outline_hatch );
m_board->Add( zc.release() ); m_board->Add( zc.release() );
...@@ -2424,7 +2469,7 @@ BIU KICAD_PLUGIN::biuParse( const char* aValue, const char** nptrptr ) ...@@ -2424,7 +2469,7 @@ BIU KICAD_PLUGIN::biuParse( const char* aValue, const char** nptrptr )
if( errno ) if( errno )
{ {
m_error.Printf( _( "invalid float number in file:'%s', line:%d, offset:%d" ), m_error.Printf( _( "invalid float number in\nfile: '%s'\nline: %d\noffset: %d" ),
aReader->GetSource().GetData(), aReader->LineNumber(), aValue - aReader->Line() + 1 ); aReader->GetSource().GetData(), aReader->LineNumber(), aValue - aReader->Line() + 1 );
THROW_IO_ERROR( m_error ); THROW_IO_ERROR( m_error );
...@@ -2432,7 +2477,7 @@ BIU KICAD_PLUGIN::biuParse( const char* aValue, const char** nptrptr ) ...@@ -2432,7 +2477,7 @@ BIU KICAD_PLUGIN::biuParse( const char* aValue, const char** nptrptr )
if( aValue == nptr ) if( aValue == nptr )
{ {
m_error.Printf( _( "missing float number in file:'%s', line:%d, offset:%d" ), m_error.Printf( _( "missing float number in\nfile: '%s'\nline: %d\noffset: %d" ),
aReader->GetSource().GetData(), aReader->LineNumber(), aValue - aReader->Line() + 1 ); aReader->GetSource().GetData(), aReader->LineNumber(), aValue - aReader->Line() + 1 );
THROW_IO_ERROR( m_error ); THROW_IO_ERROR( m_error );
...@@ -2447,7 +2492,7 @@ BIU KICAD_PLUGIN::biuParse( const char* aValue, const char** nptrptr ) ...@@ -2447,7 +2492,7 @@ BIU KICAD_PLUGIN::biuParse( const char* aValue, const char** nptrptr )
} }
double KICAD_PLUGIN::dblParse( const char* aValue, const char** nptrptr ) double KICAD_PLUGIN::degParse( const char* aValue, const char** nptrptr )
{ {
char* nptr; char* nptr;
...@@ -2457,7 +2502,7 @@ double KICAD_PLUGIN::dblParse( const char* aValue, const char** nptrptr ) ...@@ -2457,7 +2502,7 @@ double KICAD_PLUGIN::dblParse( const char* aValue, const char** nptrptr )
if( errno ) if( errno )
{ {
m_error.Printf( _( "invalid float number in file:'%s', line:%d, offset:%d" ), m_error.Printf( _( "invalid float number in\nfile: '%s'\nline: %d\noffset: %d" ),
aReader->GetSource().GetData(), aReader->LineNumber(), aValue - aReader->Line() + 1 ); aReader->GetSource().GetData(), aReader->LineNumber(), aValue - aReader->Line() + 1 );
THROW_IO_ERROR( m_error ); THROW_IO_ERROR( m_error );
...@@ -2465,7 +2510,7 @@ double KICAD_PLUGIN::dblParse( const char* aValue, const char** nptrptr ) ...@@ -2465,7 +2510,7 @@ double KICAD_PLUGIN::dblParse( const char* aValue, const char** nptrptr )
if( aValue == nptr ) if( aValue == nptr )
{ {
m_error.Printf( _( "missing float number in file:'%s', line:%d, offset:%d" ), m_error.Printf( _( "missing float number in\nfile: '%s'\nline: %d\noffset: %d" ),
aReader->GetSource().GetData(), aReader->LineNumber(), aValue - aReader->Line() + 1 ); aReader->GetSource().GetData(), aReader->LineNumber(), aValue - aReader->Line() + 1 );
THROW_IO_ERROR( m_error ); THROW_IO_ERROR( m_error );
...@@ -2502,7 +2547,7 @@ void KICAD_PLUGIN::init( PROPERTIES* aProperties ) ...@@ -2502,7 +2547,7 @@ void KICAD_PLUGIN::init( PROPERTIES* aProperties )
} }
void KICAD_PLUGIN::Save( const wxString* aFileName, BOARD* aBoard, PROPERTIES* aProperties ) void KICAD_PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, PROPERTIES* aProperties )
{ {
LOCALE_IO toggle; // toggles on then off the C locale. LOCALE_IO toggle; // toggles on then off the C locale.
} }
......
...@@ -56,7 +56,7 @@ public: ...@@ -56,7 +56,7 @@ public:
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES* aProperties = NULL ); // overload BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES* aProperties = NULL ); // overload
void Save( const wxString* aFileName, BOARD* aBoard, PROPERTIES* aProperties = NULL ); // overload void Save( const wxString& aFileName, BOARD* aBoard, PROPERTIES* aProperties = NULL ); // overload
const wxString& PluginName() const wxString& PluginName()
{ {
...@@ -103,8 +103,10 @@ protected: ...@@ -103,8 +103,10 @@ protected:
BIU biuParse( const char* aValue, const char** nptrptr = NULL ); BIU biuParse( const char* aValue, const char** nptrptr = NULL );
/** /**
* Function dblParse * Function degParse
* parses an ASCII decimal floating point value without scaling into a double. * parses an ASCII decimal floating point value which is certainy an angle. This
* is a dedicated function for encapsulating support for the migration from
* tenths of degrees to degrees in floating point.
* *
* @param aValue is the ASCII value in C locale form with possible leading whitespace * @param aValue is the ASCII value in C locale form with possible leading whitespace
* *
...@@ -113,7 +115,7 @@ protected: ...@@ -113,7 +115,7 @@ protected:
* *
* @return double - the string converted to a primitive double type * @return double - the string converted to a primitive double type
*/ */
double dblParse( const char* aValue, const char** nptrptr = NULL ); double degParse( const char* aValue, const char** nptrptr = NULL );
// load / parse functions // load / parse functions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment