Commit 7a93d0b2 authored by Dick Hollenbeck's avatar Dick Hollenbeck

more KICAD_PLUGIN work progress

parent 8f79b146
...@@ -390,6 +390,8 @@ public: ...@@ -390,6 +390,8 @@ public:
*/ */
KICAD_T Type() const { return m_StructType; } KICAD_T Type() const { return m_StructType; }
void SetTimeStamp( unsigned long aNewTimeStamp ) { m_TimeStamp = aNewTimeStamp; }
unsigned long GetTimeStamp() const { return m_TimeStamp; }
EDA_ITEM* Next() const { return (EDA_ITEM*) Pnext; } EDA_ITEM* Next() const { return (EDA_ITEM*) Pnext; }
EDA_ITEM* Back() const { return (EDA_ITEM*) Pback; } EDA_ITEM* Back() const { return (EDA_ITEM*) Pback; }
...@@ -728,7 +730,6 @@ enum FILL_T { ...@@ -728,7 +730,6 @@ enum FILL_T {
*/ */
class EDA_TEXT class EDA_TEXT
{ {
public: public:
int m_Thickness; /* pen size used to draw this text */ int m_Thickness; /* pen size used to draw this text */
int m_Orient; /* Orient in 0.1 degrees */ int m_Orient; /* Orient in 0.1 degrees */
...@@ -770,6 +771,9 @@ public: ...@@ -770,6 +771,9 @@ public:
void SetOrientation( int aOrientation ) { m_Orient = aOrientation; } void SetOrientation( int aOrientation ) { m_Orient = aOrientation; }
int GetOrientation() const { return m_Orient; } int GetOrientation() const { return m_Orient; }
void SetItalic( bool isItalic ) { m_Italic = isItalic; }
bool GetItalic() const { return m_Italic; }
/** /**
* Function SetSize * Function SetSize
* sets text size. * sets text size.
......
...@@ -112,6 +112,8 @@ public: ...@@ -112,6 +112,8 @@ public:
return m_Name; return m_Name;
} }
void SetName( const wxString& aName ) { m_Name = aName; }
/** /**
* Function GetCount * Function GetCount
* returns the number of nets in this NETCLASS, i.e. using these rules. * returns the number of nets in this NETCLASS, i.e. using these rules.
......
...@@ -82,7 +82,6 @@ public: ...@@ -82,7 +82,6 @@ public:
*/ */
void DisplayInfo( EDA_DRAW_FRAME* frame ); void DisplayInfo( EDA_DRAW_FRAME* frame );
/** /**
* Function HitTest * Function HitTest
* tests if the given wxPoint is within the bounds of this object. * tests if the given wxPoint is within the bounds of this object.
...@@ -94,7 +93,6 @@ public: ...@@ -94,7 +93,6 @@ public:
return TextHitTest( refPos ); return TextHitTest( refPos );
} }
/** /**
* Function HitTest (overloaded) * Function HitTest (overloaded)
* tests if the given EDA_RECT intersect this object. * tests if the given EDA_RECT intersect this object.
...@@ -149,7 +147,6 @@ public: ...@@ -149,7 +147,6 @@ public:
*/ */
virtual void Show( int nestLevel, std::ostream& os ); virtual void Show( int nestLevel, std::ostream& os );
#endif #endif
}; };
#endif // #define CLASS_PCB_TEXT_H #endif // #define CLASS_PCB_TEXT_H
...@@ -117,23 +117,18 @@ public: ...@@ -117,23 +117,18 @@ public:
*/ */
virtual void Flip( const wxPoint& aCentre ); virtual void Flip( const wxPoint& aCentre );
/**
* Function GetPosition
* returns the position of this object.
* @return const wxPoint& - The position of this object.
*/
wxPoint& GetPosition()
{
return m_Start; // it had to be start or end.
}
const wxPoint GetPosition() const // overload const wxPoint GetPosition() const // overload
{ {
return m_Start; // it had to be start or end. return m_Start; // it had to be start or end.
} }
int GetWidth() const { return m_Width; }
void SetWidth( int aWidth ) { m_Width = aWidth; }
void SetPosition( const wxPoint& aPos ) { m_Start = aPos; } // overload void SetPosition( const wxPoint& aPos ) { m_Start = aPos; } // overload
void SetEnd( const wxPoint& aEnd ) { m_Start = aEnd; }
EDA_RECT GetBoundingBox() const; EDA_RECT GetBoundingBox() const;
/** /**
...@@ -177,13 +172,13 @@ public: ...@@ -177,13 +172,13 @@ public:
return hypot( dx, dy ); return hypot( dx, dy );
} }
/* Display on screen: */ /* Display on screen: */
void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int aDrawMode, void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int aDrawMode,
const wxPoint& aOffset = ZeroOffset ); const wxPoint& aOffset = ZeroOffset );
/* divers */ /* divers */
int Shape() const { return m_Shape & 0xFF; } int Shape() const { return m_Shape & 0xFF; }
void SetShape( int aShape ) { m_Shape = aShape; }
/** /**
* Function TransformShapeWithClearanceToPolygon * Function TransformShapeWithClearanceToPolygon
...@@ -489,7 +484,6 @@ public: ...@@ -489,7 +484,6 @@ public:
return wxT( "VIA" ); return wxT( "VIA" );
} }
virtual wxString GetSelectMenuText() const; virtual wxString GetSelectMenuText() const;
virtual BITMAP_DEF GetMenuImage() const { return via_sketch_xpm; } virtual BITMAP_DEF GetMenuImage() const { return via_sketch_xpm; }
......
...@@ -27,22 +27,26 @@ ...@@ -27,22 +27,26 @@
#include <kicad_plugin.h> #include <kicad_plugin.h>
// some day plugins could be in separate DLL/DSOs, until then, use the simplest method: // Some day plugins might be in separate DLL/DSOs, simply because of numbers of them
// and code size. Until then, use the simplest method:
// This implementation is one of two which could be done. // This implementation is one of two which could be done.
// the other one would cater to DLL/DSO's. But since it would be nearly // The other one would cater to DLL/DSO's. But since it would be nearly
// impossible to link a KICAD type DLL/DSO right now without pulling in all // impossible to link a KICAD type DLL/DSO right now without pulling in all
// ::Draw() functions, I forgo that option. // ::Draw() functions, I forgo that option temporarily.
// Some day it may be possible to have some built in AND some DLL/DSO, but // Some day it may be possible to have some built in AND some DLL/DSO
// only when we can keep things clean enough to link a DLL/DSO without // plugins coexisting.
// pulling in the world.
static KICAD_PLUGIN kicad_plugin;
static KICAD_PLUGIN kicad_plugin; // a secret
//static EAGLE_PLUGIN eagle_plugin; //static EAGLE_PLUGIN eagle_plugin;
PLUGIN* IO_MGR::PluginFind( PCB_FILE_T aFileType ) PLUGIN* IO_MGR::PluginFind( PCB_FILE_T aFileType )
{ {
// This implementation is subject to change, any magic is allowed here.
// The public IO_MGR API is the only pertinent public information.
switch( aFileType ) switch( aFileType )
{ {
case KICAD: return &kicad_plugin; case KICAD: return &kicad_plugin;
...@@ -104,7 +108,7 @@ BOARD* PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES* ...@@ -104,7 +108,7 @@ BOARD* PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES*
wxString msg; wxString msg;
msg.Printf( _( "Plugin %s does not implement the BOARD Load() function.\n" ), msg.Printf( _( "Plugin %s does not implement the BOARD Load() function.\n" ),
Name().GetData() ); PluginName().GetData() );
THROW_IO_ERROR( msg ); THROW_IO_ERROR( msg );
} }
...@@ -118,7 +122,7 @@ void PLUGIN::Save( const wxString* aFileName, BOARD* aBoard, PROPERTIES* aProper ...@@ -118,7 +122,7 @@ void PLUGIN::Save( const wxString* aFileName, BOARD* aBoard, PROPERTIES* aProper
wxString msg; wxString msg;
msg.Printf( _( "Plugin %s does not implement the BOARD Save() function.\n" ), msg.Printf( _( "Plugin %s does not implement the BOARD Save() function.\n" ),
Name().GetData() ); PluginName().GetData() );
THROW_IO_ERROR( msg ); THROW_IO_ERROR( msg );
} }
......
...@@ -40,7 +40,7 @@ class PLUGIN; ...@@ -40,7 +40,7 @@ class PLUGIN;
/** /**
* Class IO_MGR * Class IO_MGR
* is factory which returns an instance of a PLUGIN DSO/DLL. * is a factory which returns an instance of a PLUGIN.
*/ */
class IO_MGR class IO_MGR
{ {
...@@ -63,7 +63,8 @@ public: ...@@ -63,7 +63,8 @@ public:
* Function PluginFind * Function PluginFind
* returns a PLUGIN which the caller can use to import, export, save, or load * returns a PLUGIN which the caller can use to import, export, save, or load
* design documents. The returned PLUGIN, may be reference counted, so please * design documents. The returned PLUGIN, may be reference counted, so please
* call PluginRelease() when you are done using the returned PLUGIN. * call PluginRelease() when you are done using the returned PLUGIN. It may or
* may not be code running from a DLL/DSO.
* *
* @param aFileType is from PCB_FILE_T and tells which plugin to find. * @param aFileType is from PCB_FILE_T and tells which plugin to find.
* *
...@@ -88,21 +89,21 @@ public: ...@@ -88,21 +89,21 @@ public:
/** /**
* Function Load * Function Load
* finds the requested plugin and loads a BOARD, or throws an exception trying. * finds the requested PLUGIN and loads a BOARD, or throws an exception trying.
* *
* @param aFileType is the type of file to load. * @param aFileType is the PCB_FILE_T of file to load.
* *
* @param aFileName is the name of the file to load. * @param aFileName is the name of the file to load.
* *
* @param aAppendToMe is an existing BOARD to append to, use NULL if fresh * @param aAppendToMe is an existing BOARD to append to, use NULL if fresh
* board load wanted. * board load is wanted.
* *
* @param aProperties is an associative array that allows the caller to * @param aProperties is an associative array that allows the caller to
* pass additional tuning parameters to the plugin. * pass additional tuning parameters to the PLUGIN.
* *
* @return BOARD* - caller owns it, never NULL because exception thrown if error. * @return BOARD* - caller owns it, never NULL because exception thrown if error.
* *
* @throw IO_ERROR if the pluging cannot be found, file cannot be found, * @throw IO_ERROR if the PLUGIN cannot be found, file cannot be found,
* or file cannot be loaded. * or file cannot be loaded.
*/ */
static BOARD* Load( PCB_FILE_T aFileType, const wxString& aFileName, static BOARD* Load( PCB_FILE_T aFileType, const wxString& aFileName,
...@@ -168,7 +169,12 @@ public: ...@@ -168,7 +169,12 @@ public:
} }
}; };
virtual const wxString& Name() = 0;
/**
* Function PluginName
* returns a brief hard coded name for this PLUGIN.
*/
virtual const wxString& PluginName() = 0;
//-----<BOARD STUFF>---------------------------------------------------- //-----<BOARD STUFF>----------------------------------------------------
...@@ -192,7 +198,7 @@ public: ...@@ -192,7 +198,7 @@ public:
* @throw IO_ERROR if there is a problem loading, and its contents should * @throw IO_ERROR if there is a problem loading, and its contents should
* say what went wrong. * say what went wrong.
*/ */
virtual BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, virtual BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
PROPERTIES* aProperties = NULL ); PROPERTIES* aProperties = NULL );
/** /**
...@@ -255,4 +261,3 @@ public: ...@@ -255,4 +261,3 @@ public:
}; };
#endif // IO_MGR_H_ #endif // IO_MGR_H_
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
#include <class_mire.h> #include <class_mire.h>
#include <3d_struct.h> #include <3d_struct.h>
#include <pcb_plot_params.h> #include <pcb_plot_params.h>
#include <drawtxt.h>
/* /*
#include <pcbnew.h> #include <pcbnew.h>
...@@ -198,36 +198,18 @@ void KICAD_PLUGIN::loadAllSections( bool doAppend ) ...@@ -198,36 +198,18 @@ void KICAD_PLUGIN::loadAllSections( bool doAppend )
loadPCB_TEXTE(); loadPCB_TEXTE();
} }
#if 0
else if( TESTLINE( "$TRACK" ) ) else if( TESTLINE( "$TRACK" ) )
{ {
#if 0 && defined(PCBNEW) TRACK* insertBeforeMe = doAppend ? NULL : m_board->m_Track.GetFirst();
TRACK* insertBeforeMe = Append ? NULL : m_board->m_Track.GetFirst(); loadTrackList( insertBeforeMe, PCB_TRACE_T, NbTrack );
ReadListeSegmentDescr( aReader, insertBeforeMe, PCB_TRACE_T, NbTrack );
#endif
} }
else if( TESTLINE( BRD_NETCLASS ) ) else if( TESTLINE( "$" BRD_NETCLASS ) )
{ {
/* loadNETCLASS();
// create an empty NETCLASS without a name.
NETCLASS* netclass = new NETCLASS( m_board, wxEmptyString );
// fill it from the *.brd file, and establish its name.
netclass->ReadDescr( aReader );
if( !m_board->m_NetClasses.Add( netclass ) )
{
// Must have been a name conflict, this is a bad board file.
// User may have done a hand edit to the file.
// Delete netclass if board could not take ownership of it.
delete netclass;
// @todo: throw an exception here, this is a bad board file.
}
*/
} }
#if 0
else if( TESTLINE( "$CZONE_OUTLINE" ) ) else if( TESTLINE( "$CZONE_OUTLINE" ) )
{ {
auto_ptr<ZONE_CONTAINER> zone_descr( new ZONE_CONTAINER( m_board ) ); auto_ptr<ZONE_CONTAINER> zone_descr( new ZONE_CONTAINER( m_board ) );
...@@ -441,7 +423,7 @@ void KICAD_PLUGIN::loadSHEET() ...@@ -441,7 +423,7 @@ void KICAD_PLUGIN::loadSHEET()
char* line = aReader->Line(); char* line = aReader->Line();
if( TESTLINE( "$End" ) ) if( TESTLINE( "$End" ) )
return; return; // preferred exit
else if( TESTLINE( "Sheet" ) ) else if( TESTLINE( "Sheet" ) )
{ {
...@@ -527,8 +509,7 @@ void KICAD_PLUGIN::loadSHEET() ...@@ -527,8 +509,7 @@ void KICAD_PLUGIN::loadSHEET()
} }
} }
m_error = wxT( "Missing '$EndSHEETDESCR'" ); THROW_IO_ERROR( wxT( "Missing '$EndSHEETDESCR'" ) );
THROW_IO_ERROR( m_error );
} }
...@@ -536,7 +517,7 @@ void KICAD_PLUGIN::loadSETUP() ...@@ -536,7 +517,7 @@ void KICAD_PLUGIN::loadSETUP()
{ {
NETCLASS* netclass_default = m_board->m_NetClasses.GetDefault(); NETCLASS* netclass_default = m_board->m_NetClasses.GetDefault();
static const char delims[] = " =\n\r"; // this function only static const char delims[] = " =\n\r"; // for this function only
while( aReader->ReadLine() ) while( aReader->ReadLine() )
{ {
...@@ -924,8 +905,7 @@ void KICAD_PLUGIN::loadMODULE() ...@@ -924,8 +905,7 @@ void KICAD_PLUGIN::loadMODULE()
} }
out: out:
m_error = wxT( "Missing '$EndMODULE'" ); THROW_IO_ERROR( wxT( "Missing '$EndMODULE'" ) );
THROW_IO_ERROR( m_error );
} }
...@@ -1032,8 +1012,7 @@ void KICAD_PLUGIN::loadDRAWSEGMENT() ...@@ -1032,8 +1012,7 @@ void KICAD_PLUGIN::loadDRAWSEGMENT()
} }
} }
m_error = wxT( "Missing '$EndDRAWSEGMENT'" ); THROW_IO_ERROR( wxT( "Missing '$EndDRAWSEGMENT'" ) );
THROW_IO_ERROR( m_error );
} }
...@@ -1048,10 +1027,10 @@ void KICAD_PLUGIN::loadNETINFO_ITEM() ...@@ -1048,10 +1027,10 @@ void KICAD_PLUGIN::loadNETINFO_ITEM()
{ {
char* line = aReader->Line(); char* line = aReader->Line();
if( strnicmp( line, "$End", 4 ) == 0 ) if( TESTLINE( "$End" ) )
return; // preferred exit return; // preferred exit
if( strncmp( line, "Na", 2 ) == 0 ) else if( TESTLINE( "Na" ) )
{ {
int tmp = atoi( line + 2 ); int tmp = atoi( line + 2 );
net->SetNet( tmp ); net->SetNet( tmp );
...@@ -1062,16 +1041,15 @@ void KICAD_PLUGIN::loadNETINFO_ITEM() ...@@ -1062,16 +1041,15 @@ void KICAD_PLUGIN::loadNETINFO_ITEM()
} }
} }
m_error = wxT( "Missing '$EndEQUIPOT'" ); THROW_IO_ERROR( wxT( "Missing '$EndEQUIPOT'" ) );
THROW_IO_ERROR( m_error );
} }
void KICAD_PLUGIN::loadPCB_TEXTE() void KICAD_PLUGIN::loadPCB_TEXTE()
{ {
/* /* examples:
For a single line text: For a single line text:
----------------------
$TEXTPCB $TEXTPCB
Te "Text example" Te "Text example"
Po 66750 53450 600 800 150 0 Po 66750 53450 600 800 150 0
...@@ -1079,7 +1057,7 @@ void KICAD_PLUGIN::loadPCB_TEXTE() ...@@ -1079,7 +1057,7 @@ void KICAD_PLUGIN::loadPCB_TEXTE()
$EndTEXTPCB $EndTEXTPCB
For a multi line text: For a multi line text:
---------------------
$TEXTPCB $TEXTPCB
Te "Text example" Te "Text example"
Nl "Line 2" Nl "Line 2"
...@@ -1089,9 +1067,9 @@ void KICAD_PLUGIN::loadPCB_TEXTE() ...@@ -1089,9 +1067,9 @@ void KICAD_PLUGIN::loadPCB_TEXTE()
Nl "line nn" is a line added to the current text Nl "line nn" is a line added to the current text
*/ */
char text[1024]; char text[1024];
char style[256];
// maybe someday a constructor that takes all this data in one call?
TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board ); TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
m_board->Add( pcbtxt, ADD_APPEND ); m_board->Add( pcbtxt, ADD_APPEND );
...@@ -1100,95 +1078,327 @@ void KICAD_PLUGIN::loadPCB_TEXTE() ...@@ -1100,95 +1078,327 @@ void KICAD_PLUGIN::loadPCB_TEXTE()
char* line = aReader->Line(); char* line = aReader->Line();
if( TESTLINE( "$EndTEXTPCB" ) ) if( TESTLINE( "$EndTEXTPCB" ) )
{
return; // preferred exit return; // preferred exit
}
#if 0 // @todo else if( TESTLINE( "Te" ) ) // Text line (or first line for multi line texts)
else if( TESTLINE( "Te" ) ) // Text line (first line for multi line texts)
{ {
ReadDelimitedText( text, line + 2, sizeof(text) ); ReadDelimitedText( text, line + 2, sizeof(text) );
m_Text = FROM_UTF8( text ); pcbtxt->SetText( FROM_UTF8( text ) );
} }
else if( TESTLINE( "nl" ) ) // next line of the current text else if( TESTLINE( "nl" ) ) // next line of the current text
{ {
ReadDelimitedText( text, line + 2, sizeof(text) ); ReadDelimitedText( text, line + 2, sizeof(text) );
m_Text.Append( '\n' ); pcbtxt->SetText( pcbtxt->GetText() + '\n' + FROM_UTF8( text ) );
m_Text += FROM_UTF8( text );
} }
else if( TESTLINE( "Po" ) ) else if( TESTLINE( "Po" ) )
{ {
sscanf( line + 2, " %d %d %d %d %d %d", // sscanf( line + 2, " %d %d %d %d %d %d", &m_Pos.x, &m_Pos.y, &m_Size.x, &m_Size.y, &m_Thickness, &m_Orient );
&m_Pos.x, &m_Pos.y, const char* data = line + SZ( "Po" );
&m_Size.x, &m_Size.y,
&m_Thickness, &m_Orient ); wxSize sz;
BIU pos_x = biuParse( data, &data );
BIU pos_y = biuParse( data, &data );
sz.x = biuParse( data, &data );
sz.y = biuParse( data, &data );
BIU thickn = biuParse( data, &data );
int orient = atoi( data );
// Ensure the text has minimal size to see this text on screen: // Ensure the text has minimal size to see this text on screen:
if( m_Size.x < 5 )
m_Size.x = 5;
if( m_Size.y < 5 ) /* @todo wait until we are firmly in the nanometer world
m_Size.y = 5; if( sz.x < 5 )
sz.x = 5;
if( sz.y < 5 )
sz.y = 5;
*/
// Set a reasonable width:
if( thickn < 1 )
thickn = 1;
thickn = Clamp_Text_PenSize( thickn, sz );
pcbtxt->SetThickness( thickn );
pcbtxt->SetOrientation( orient );
pcbtxt->m_Pos = wxPoint( pos_x, pos_y );
pcbtxt->SetSize( sz );
} }
else if( TESTLINE( "De" ) ) else if( TESTLINE( "De" ) )
{ {
char style[256];
style[0] = 0; style[0] = 0;
int normal_display = 1; int normal_display = 1;
char hJustify = 'c'; char hJustify = 'c';
int layer = FIRST_COPPER_LAYER;
long timestamp = 0;
bool italic = false;
sscanf( line + 2, " %d %d %lX %s %c\n", &m_Layer, &normal_display, // sscanf( line + 2, " %d %d %lX %s %c\n", &m_Layer, &normal_display, &m_TimeStamp, style, &hJustify );
&m_TimeStamp, style, &hJustify );
m_Mirror = normal_display ? false : true; sscanf( line + 2, " %d %d %lX %s %c\n", &layer, &normal_display, &timestamp, style, &hJustify );
if( m_Layer < FIRST_COPPER_LAYER ) normal_display = normal_display ? false : true;
m_Layer = FIRST_COPPER_LAYER;
else if( m_Layer > LAST_NO_COPPER_LAYER ) if( layer < FIRST_COPPER_LAYER )
m_Layer = LAST_NO_COPPER_LAYER; layer = FIRST_COPPER_LAYER;
else if( layer > LAST_NO_COPPER_LAYER )
layer = LAST_NO_COPPER_LAYER;
if( strnicmp( style, "Italic", 6 ) == 0 ) if( strnicmp( style, "Italic", 6 ) == 0 )
m_Italic = 1; italic = true;
else
m_Italic = 0;
switch( hJustify ) switch( hJustify )
{ {
case 'l': case 'l':
case 'L': case 'L':
m_HJustify = GR_TEXT_HJUSTIFY_LEFT; hJustify = GR_TEXT_HJUSTIFY_LEFT;
break; break;
case 'c': case 'c':
case 'C': case 'C':
m_HJustify = GR_TEXT_HJUSTIFY_CENTER; hJustify = GR_TEXT_HJUSTIFY_CENTER;
break; break;
case 'r': case 'r':
case 'R': case 'R':
m_HJustify = GR_TEXT_HJUSTIFY_RIGHT; hJustify = GR_TEXT_HJUSTIFY_RIGHT;
break; break;
default: default:
m_HJustify = GR_TEXT_HJUSTIFY_CENTER; hJustify = GR_TEXT_HJUSTIFY_CENTER;
break; break;
} }
pcbtxt->SetHorizJustify( GRTextHorizJustifyType( hJustify ) );
pcbtxt->SetLayer( layer );
pcbtxt->SetItalic( italic );
pcbtxt->SetTimeStamp( timestamp );
} }
#endif
} }
/* @todo: this is unreachable code, except for when the terminator is missing THROW_IO_ERROR( wxT( "Missing '$EndTEXTPCB'" ) );
}
// Set a reasonable width:
if( m_Thickness < 1 )
m_Thickness = 1;
m_Thickness = Clamp_Text_PenSize( m_Thickness, m_Size ); void KICAD_PLUGIN::loadTrackList( TRACK* aInsertBeforeMe, int aStructType, int aSegCount )
*/ {
static const char delims[] = " \t\n\r"; // for this function only.
m_error = wxT( "Missing '$EndTEXTPCB'" ); while( aReader->ReadLine() )
THROW_IO_ERROR( m_error ); {
// read two lines per loop iteration, each loop is one TRACK or VIA
// example first line:
// "Po 0 23994 28800 24400 28800 150 -1\r\n"
char* line = aReader->Line();
BIU drill = -1; // SetDefault() if -1
TRACK* newTrack;
if( line[0] == '$' ) // $EndTRACK
return; // preferred exit
// int arg_count = sscanf( line + 2, " %d %d %d %d %d %d %d", &shape, &tempStartX, &tempStartY, &tempEndX, &tempEndY, &width, &drill );
const char* data = line + SZ( "Po" );
int shape = (int) strtol( data, (char**) &data, 10 );
BIU startX = biuParse( data, &data );
BIU startY = biuParse( data, &data );
BIU endX = biuParse( data, &data );
BIU endY = biuParse( data, &data );
BIU width = biuParse( data, &data );
// optional 7th drill parameter (must be optional in an old format?)
data = strtok( (char*) data, delims );
if( data )
{
drill = biuParse( data );
}
// Read the 2nd line to determine the exact type, one of:
// PCB_TRACE_T, PCB_VIA_T, or PCB_ZONE_T. The type field in 2nd line
// differentiates between PCB_TRACE_T and PCB_VIA_T. With virtual
// functions in use, it is critical to instantiate the PCB_VIA_T
// exactly.
if( !aReader->ReadLine() )
break;
line = aReader->Line();
// example second line:
// "De 0 0 463 0 800000\r\n"
if( line[0] == '$' )
{
// mandatory 2nd line is missing
THROW_IO_ERROR( wxT( "Missing 2nd line of a TRACK def" ) );
}
int makeType;
long timeStamp;
int layer, type, flags, net_code;
// parse the 2nd line to determine the type of object
sscanf( line + SZ( "De" ), " %d %d %d %lX %X", &layer, &type, &net_code, &timeStamp, &flags );
if( aStructType==PCB_TRACE_T && type==1 )
makeType = PCB_VIA_T;
else
makeType = aStructType;
switch( makeType )
{
default:
case PCB_TRACE_T:
newTrack = new TRACK( m_board );
m_board->m_Track.Insert( newTrack, aInsertBeforeMe );
break;
case PCB_VIA_T:
newTrack = new SEGVIA( m_board );
m_board->m_Track.Insert( newTrack, aInsertBeforeMe );
break;
case PCB_ZONE_T: // this is now deprecated, but exist in old boards
newTrack = new SEGZONE( m_board );
m_board->m_Zone.Insert( (SEGZONE*) newTrack, (SEGZONE*) aInsertBeforeMe );
break;
}
newTrack->SetTimeStamp( timeStamp );
newTrack->SetPosition( wxPoint( startX, startY ) );
newTrack->SetEnd( wxPoint( endX, endY ) );
newTrack->SetWidth( width );
newTrack->SetShape( shape );
if( drill <= 0 )
newTrack->SetDrillDefault();
else
newTrack->SetDrillValue( drill );
newTrack->SetLayer( layer );
if( makeType == PCB_VIA_T ) // Ensure layers are OK when possible:
{
if( newTrack->Shape() == VIA_THROUGH )
( (SEGVIA*) newTrack )->SetLayerPair( LAYER_N_FRONT, LAYER_N_BACK );
}
newTrack->SetNet( net_code );
newTrack->SetState( flags, ON );
}
THROW_IO_ERROR( wxT( "Missing '$EndTRACK'" ) );
}
void KICAD_PLUGIN::loadNETCLASS()
{
char buf[1024];
wxString netname;
// create an empty NETCLASS without a name, but do not add it to 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
// just before returning.
auto_ptr<NETCLASS> netclass( new NETCLASS( m_board, wxEmptyString ) );
while( aReader->ReadLine() )
{
char* line = aReader->Line();
if( TESTLINE( "AddNet" ) )
{
ReadDelimitedText( buf, line + SZ( "AddNet" ), sizeof(buf) );
netname = FROM_UTF8( buf );
netclass->Add( netname );
}
else if( TESTLINE( "$end" BRD_NETCLASS ) )
{
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; // prefered exit
}
else if( TESTLINE( "Clearance" ) )
{
BIU tmp = biuParse( line + SZ( "Clearance" ) );
netclass->SetClearance( tmp );
}
else if( TESTLINE( "TrackWidth" ) )
{
BIU tmp = biuParse( line + SZ( "TrackWidth" ) );
netclass->SetTrackWidth( tmp );
}
else if( TESTLINE( "ViaDia" ) )
{
BIU tmp = biuParse( line + SZ( "ViaDia" ) );
netclass->SetViaDiameter( tmp );
}
else if( TESTLINE( "ViaDrill" ) )
{
BIU tmp = biuParse( line + SZ( "ViaDrill" ) );
netclass->SetViaDrill( tmp );
}
else if( TESTLINE( "uViaDia" ) )
{
BIU tmp = biuParse( line + SZ( "uViaDia" ) );
netclass->SetuViaDiameter( tmp );
}
else if( TESTLINE( "uViaDrill" ) )
{
BIU tmp = biuParse( line + SZ( "uViaDrill" ) );
netclass->SetuViaDrill( tmp );
}
else if( TESTLINE( "Name" ) )
{
ReadDelimitedText( buf, line + SZ( "Name" ), sizeof(buf) );
netclass->SetName( FROM_UTF8( buf ) );
}
else if( TESTLINE( "Desc" ) )
{
ReadDelimitedText( buf, line + SZ( "Desc" ), sizeof(buf) );
netclass->SetDescription( FROM_UTF8( buf ) );
}
}
THROW_IO_ERROR( wxT( "Missing '$End" BRD_NETCLASS ) );
} }
std::string KICAD_PLUGIN::biuFmt( BIU aValue ) std::string KICAD_PLUGIN::biuFmt( BIU aValue )
{ {
double engUnits = biuToDisk * aValue; double engUnits = biuToDisk * aValue;
......
...@@ -52,7 +52,7 @@ public: ...@@ -52,7 +52,7 @@ public:
void Save( const wxString* aFileName, BOARD* aBoard, PROPERTIES* aProperties = NULL ); void Save( const wxString* aFileName, BOARD* aBoard, PROPERTIES* aProperties = NULL );
const wxString& Name() const wxString& PluginName()
{ {
static const wxString name = wxT( "KiCad" ); static const wxString name = wxT( "KiCad" );
return name; return name;
...@@ -108,12 +108,19 @@ protected: ...@@ -108,12 +108,19 @@ protected:
void loadDRAWSEGMENT(); void loadDRAWSEGMENT();
void loadNETINFO_ITEM(); void loadNETINFO_ITEM();
void loadPCB_TEXTE(); void loadPCB_TEXTE();
void loadNETCLASS();
/* /**
* Function loadTrackList
* reads a list of segments (Tracks and Vias)
*/
void loadTrackList( TRACK* aInsertBeforeMe, int aStructType, int aSegCount );
/* @todo
void load( PCB_TARGET* me ); void load( PCB_TARGET* me );
void load( NETINFO* me ); void load( NETINFO* me );
void load( TRACK* me ); void load( TRACK* me );
void load( NETCLASS* me );
void load( ZONE_CONTAINER* me ); void load( ZONE_CONTAINER* me );
void load( DIMENSION* me ); void load( DIMENSION* me );
*/ */
......
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