Commit b6508af0 authored by Dick Hollenbeck's avatar Dick Hollenbeck

KICAD_PLUGIN and nanometer intermediate checkin, work in progress...

parent 3a887850
......@@ -97,7 +97,7 @@ void EDA_GRAPHIC_TEXT_CTRL::SetValue( int textSize )
}
wxString EDA_GRAPHIC_TEXT_CTRL::GetText()
const wxString EDA_GRAPHIC_TEXT_CTRL::GetText() const
{
wxString text = m_FrameText->GetValue();
return text;
......
......@@ -87,7 +87,7 @@ EDA_ITEM* SCH_FIELD::doClone() const
}
wxString SCH_FIELD::GetText() const
const wxString SCH_FIELD::GetText() const
{
wxString text = m_Text;
......
......@@ -88,9 +88,9 @@ public:
* overrides the default implementation to allow for the part suffix to be added
* to the reference designator field if the component has multiple parts.
*
* @return a wxString object containing the field's string.
* @return a const wxString object containing the field's string.
*/
virtual wxString GetText() const;
virtual const wxString GetText() const;
void Place( SCH_EDIT_FRAME* frame, wxDC* DC );
......
......@@ -3,8 +3,8 @@
* @brief Basic classes for most KiCad items.
*/
#ifndef BASE_STRUCT_H
#define BASE_STRUCT_H
#ifndef BASE_STRUCT_H_
#define BASE_STRUCT_H_
#include "colors.h"
#include "bitmaps.h"
......@@ -725,8 +725,8 @@ enum FILL_T {
/**
* Class EDA_TEXT
* is a basic class to handle texts (labels, texts on components or footprints
* ..) not used directly.
* The text classes are derived from EDA_ITEM and EDA_TEXT
* ..) not used directly. The "used" text classes are derived from EDA_ITEM and
* EDA_TEXT using multiple inheritance.
*/
class EDA_TEXT
{
......@@ -772,24 +772,25 @@ public:
int GetOrientation() const { return m_Orient; }
void SetItalic( bool isItalic ) { m_Italic = isItalic; }
bool GetItalic() const { return m_Italic; }
bool IsItalic() const { return m_Italic; }
/**
* Function SetSize
* sets text size.
* @param aNewSize is the new text size.
*/
void SetSize( wxSize aNewSize ) { m_Size = aNewSize; };
void SetSize( const wxSize& aNewSize ) { m_Size = aNewSize; };
/**
* Function GetSize
* returns text size.
* @return wxSize - text size.
*/
wxSize GetSize() const { return m_Size; };
const wxSize GetSize() const { return m_Size; };
//void SetPosition( const wxPoint& aPoint ) { m_Pos = aPoint; }
//wxPoint GetPosition() const { return m_Pos; }
/// named differently than the ones using multiple inheritance and including this class
void SetPos( const wxPoint& aPoint ) { m_Pos = aPoint; }
const wxPoint GetPos() const { return m_Pos; }
int GetLength() const { return m_Text.Length(); };
......@@ -904,9 +905,9 @@ public:
* string to provide a way for modifying the base string by adding a suffix or
* prefix to the base string.
* </p>
* @return a wxString object containing the string of the item.
* @return a const wxString object containing the string of the item.
*/
virtual wxString GetText() const { return m_Text; }
virtual const wxString GetText() const { return m_Text; }
GRTextHorizJustifyType GetHorizJustify() const { return m_HJustify; };
GRTextVertJustifyType GetVertJustify() const { return m_VJustify; };
......@@ -914,4 +915,4 @@ public:
void SetVertJustify( GRTextVertJustifyType aType ) { m_VJustify = aType; };
};
#endif /* BASE_STRUCT_H */
#endif // BASE_STRUCT_H_
......@@ -81,7 +81,7 @@ public:
~EDA_GRAPHIC_TEXT_CTRL();
wxString GetText();
const wxString GetText() const;
int GetTextSize();
void Enable( bool state );
void SetTitle( const wxString& title );
......
......@@ -37,15 +37,22 @@ DIMENSION::~DIMENSION()
}
void DIMENSION::SetText( const wxString& NewText )
void DIMENSION::SetPosition( const wxPoint& aPos )
{
m_Text->m_Text = NewText;
m_Pos = aPos;
m_Text->SetPos( aPos );
}
wxString DIMENSION::GetText( void ) const
void DIMENSION::SetText( const wxString& aNewText )
{
return m_Text->m_Text;
m_Text->SetText( aNewText );
}
const wxString DIMENSION::GetText() const
{
return m_Text->GetText();
}
......
......@@ -37,13 +37,15 @@ public:
DIMENSION( BOARD_ITEM* aParent );
~DIMENSION();
const wxPoint GetPosition() const
const wxPoint GetPosition() const { return m_Pos; }
void SetPosition( const wxPoint& aPos ); // override, sets m_Text's position too
void SetTextSize( const wxSize& aTextSize )
{
return m_Pos;
m_Text->SetSize( aTextSize );
}
void SetPosition( const wxPoint& aPos ) { m_Pos = aPos; }
/**
* Function SetLayer
* sets the layer this item is on.
......@@ -69,7 +71,7 @@ public:
bool Save( FILE* aFile ) const;
void SetText( const wxString& NewText );
wxString GetText( void ) const;
const wxString GetText() const;
void Copy( DIMENSION* source );
......@@ -80,7 +82,7 @@ public:
* Function Move
* @param offset : moving vector
*/
void Move(const wxPoint& offset);
void Move( const wxPoint& offset );
/**
* Function Rotate
......@@ -132,7 +134,6 @@ public:
*/
bool HitTest( EDA_RECT& refArea );
/**
* Function GetClass
* returns the class name.
......
......@@ -288,7 +288,7 @@ bool NETCLASS::Save( FILE* aFile ) const
{
bool result = true;
fprintf( aFile, "$" BRD_NETCLASS "\n" );
fprintf( aFile, "$NCLASS\n" );
fprintf( aFile, "Name %s\n", EscapedUTF8( m_Name ).c_str() );
fprintf( aFile, "Desc %s\n", EscapedUTF8( GetDescription() ).c_str() );
......@@ -307,7 +307,7 @@ bool NETCLASS::Save( FILE* aFile ) const
for( const_iterator i = begin(); i!=end(); ++i )
fprintf( aFile, "AddNet %s\n", EscapedUTF8( *i ).c_str() );
fprintf( aFile, "$End" BRD_NETCLASS "\n" );
fprintf( aFile, "$EndNCLASS\n" );
return result;
}
......@@ -334,74 +334,72 @@ void NETCLASS::Show( int nestLevel, std::ostream& os )
#endif
bool NETCLASS::ReadDescr( LINE_READER* aReader )
{
bool result = false;
char* Line;
char Buffer[1024];
char* line;
char buf[1024];
wxString netname;
while( aReader->ReadLine() )
{
Line = aReader->Line();
if( strnicmp( Line, "AddNet", 6 ) == 0 )
line = aReader->Line();
if( strnicmp( line, "AddNet", 6 ) == 0 )
{
ReadDelimitedText( Buffer, Line + 6, sizeof(Buffer) );
netname = FROM_UTF8( Buffer );
ReadDelimitedText( buf, line + 6, sizeof(buf) );
netname = FROM_UTF8( buf );
Add( netname );
continue;
}
if( strnicmp( Line, "$end" BRD_NETCLASS, sizeof( "$end" BRD_NETCLASS)-1) == 0 )
if( strnicmp( line, "$endNCLASS", sizeof( "$endNCLASS" ) - 1 ) == 0 )
{
result = true;
break;
}
if( strnicmp( Line, "Clearance", 9 ) == 0 )
if( strnicmp( line, "Clearance", 9 ) == 0 )
{
SetClearance( atoi( Line + 9 ) );
SetClearance( atoi( line + 9 ) );
continue;
}
if( strnicmp( Line, "TrackWidth", 10 ) == 0 )
if( strnicmp( line, "TrackWidth", 10 ) == 0 )
{
SetTrackWidth( atoi( Line + 10 ) );
SetTrackWidth( atoi( line + 10 ) );
continue;
}
if( strnicmp( Line, "ViaDia", 6 ) == 0 )
if( strnicmp( line, "ViaDia", 6 ) == 0 )
{
SetViaDiameter( atoi( Line + 6 ) );
SetViaDiameter( atoi( line + 6 ) );
continue;
}
if( strnicmp( Line, "ViaDrill", 8 ) == 0 )
if( strnicmp( line, "ViaDrill", 8 ) == 0 )
{
SetViaDrill( atoi( Line + 8 ) );
SetViaDrill( atoi( line + 8 ) );
continue;
}
if( strnicmp( Line, "uViaDia", 7 ) == 0 )
if( strnicmp( line, "uViaDia", 7 ) == 0 )
{
SetuViaDiameter( atoi( Line + 7 ) );
SetuViaDiameter( atoi( line + 7 ) );
continue;
}
if( strnicmp( Line, "uViaDrill", 9 ) == 0 )
if( strnicmp( line, "uViaDrill", 9 ) == 0 )
{
SetuViaDrill( atoi( Line + 9 ) );
SetuViaDrill( atoi( line + 9 ) );
continue;
}
if( strnicmp( Line, "Name", 4 ) == 0 )
if( strnicmp( line, "Name", 4 ) == 0 )
{
ReadDelimitedText( Buffer, Line + 4, sizeof(Buffer) );
m_Name = FROM_UTF8( Buffer );
ReadDelimitedText( buf, line + 4, sizeof(buf) );
m_Name = FROM_UTF8( buf );
continue;
}
if( strnicmp( Line, "Desc", 4 ) == 0 )
if( strnicmp( line, "Desc", 4 ) == 0 )
{
ReadDelimitedText( Buffer, Line + 4, sizeof(Buffer) );
SetDescription( FROM_UTF8( Buffer ) );
ReadDelimitedText( buf, line + 4, sizeof(buf) );
SetDescription( FROM_UTF8( buf ) );
continue;
}
}
......
......@@ -80,16 +80,6 @@ public:
static const wxString Default; ///< the name of the default NETCLASS
/**
* Name of identifier within BOARD file.
* 08-Sept-2009: changed the name from "NETCLASS" to this so we can
* toss any previous NETCLASSes in migratory BOARD files which will not have
* the proper parameters in the default netclass
* (from m_Parent->m_designSettings) in them.
* Spare the user from having to enter those defaults manually.
*/
#define BRD_NETCLASS "NCLASS"
/**
* Constructor
* stuffs a NETCLASS instance with aParent, aName, and optionally the initialParameters
......
......@@ -196,8 +196,8 @@ bool ZONE_CONTAINER::Save( FILE* aFile ) const
m_FillMode,
m_ArcToSegmentsCount,
m_IsFilled ? 'S' : 'F',
m_ThermalReliefGapValue,
m_ThermalReliefCopperBridgeValue );
m_ThermalReliefGap,
m_ThermalReliefCopperBridge );
if( ret < 3 )
return false;
......@@ -398,7 +398,7 @@ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader )
char fillstate = 'F';
text = Line + 8;
ret = sscanf( text, "%d %d %c %d %d", &fillmode, &arcsegmentcount, &fillstate,
&m_ThermalReliefGapValue, &m_ThermalReliefCopperBridgeValue );
&m_ThermalReliefGap, &m_ThermalReliefCopperBridge );
if( ret < 1 ) // Must find 1 or more args.
return false;
......@@ -1213,8 +1213,8 @@ void ZONE_CONTAINER::Copy( ZONE_CONTAINER* src )
m_FillMode = src->m_FillMode; // Filling mode (segments/polygons)
m_ArcToSegmentsCount = src->m_ArcToSegmentsCount;
m_PadOption = src->m_PadOption;
m_ThermalReliefGapValue = src->m_ThermalReliefGapValue;
m_ThermalReliefCopperBridgeValue = src->m_ThermalReliefCopperBridgeValue;
m_ThermalReliefGap = src->m_ThermalReliefGap;
m_ThermalReliefCopperBridge = src->m_ThermalReliefCopperBridge;
m_Poly->m_HatchStyle = src->m_Poly->GetHatchStyle();
m_Poly->m_HatchLines = src->m_Poly->m_HatchLines; // Copy vector <CSegment>
m_FilledPolysList.clear();
......
......@@ -24,17 +24,18 @@ class BOARD;
class ZONE_CONTAINER;
/* a small class used when filling areas with segments */
class SEGMENT
/**
* Struct SEGMENT
* is a simple container used when filling areas with segments
*/
struct SEGMENT
{
public:
wxPoint m_Start; // starting point of a segment
wxPoint m_End; // ending point of a segment
public:
SEGMENT() {}
SEGMENT( const wxPoint& aStart, const wxPoint& aEnd)
SEGMENT( const wxPoint& aStart, const wxPoint& aEnd )
{
m_Start = aStart;
m_End = aEnd;
......@@ -69,10 +70,10 @@ public:
int m_PadOption;
// thickness of the gap in thermal reliefs.
int m_ThermalReliefGapValue;
int m_ThermalReliefGap;
// thickness of the copper bridge in thermal reliefs
int m_ThermalReliefCopperBridgeValue;
int m_ThermalReliefCopperBridge;
int utility, utility2; // flags used in polygon calculations
// true when a zone was filled, false after deleting the filled areas
......@@ -167,7 +168,6 @@ public:
*/
void DrawWhileCreateOutline( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode = GR_OR );
/* Function GetBoundingBox
* @return an EDA_RECT that is the bounding box of the zone outline
*/
......@@ -204,8 +204,8 @@ public:
}
/**
* Functio SetNet
* set the netcode and the netname.
* Function SetNet
* sets the netcode and the netname.
*
* @param aNetCode The net code of the zone container if greater than or equal to
* zero. Otherwise the current net code is kept and set the net
......@@ -226,6 +226,31 @@ public:
* @return wxString - The net name.
*/
wxString GetNetName() const { return m_Netname; };
void SetNetName( const wxString& aName ) { m_Netname = aName; }
void SetFillMode( int aFillMode ) { m_FillMode = aFillMode; }
int GetFillMode() const { return m_FillMode; }
void SetThermalReliefGap( int aThermalReliefGap ) { m_ThermalReliefGap = aThermalReliefGap; }
int GetThermalReliefGap() const { return m_ThermalReliefGap; }
void SetThermalReliefCopperBridge( int aThermalReliefCopperBridge ) { m_ThermalReliefCopperBridge = aThermalReliefCopperBridge; }
int GetThermalReliefCopperBridge() const { return m_ThermalReliefCopperBridge; }
void SetArcSegCount( int aArcSegCount ) { m_ArcToSegmentsCount = aArcSegCount; }
int GetArcSegCount() const { return m_ArcToSegmentsCount; }
bool IsFilled() const { return m_IsFilled; }
void SetIsFilled( bool isFilled ) { m_IsFilled = isFilled; }
int GetZoneClearance() const { return m_ZoneClearance; }
void SetZoneClearance( int aZoneClearance ) { m_ZoneClearance = aZoneClearance; }
int GetPadOption() const { return m_PadOption; }
void SetPadOption( int aPadOption ) { m_PadOption = aPadOption; }
int GetMinThickness() const { return m_ZoneMinThickness; }
void SetMinThickness( int aMinThickness ) { m_ZoneMinThickness = aMinThickness; }
/**
* Function HitTest
......@@ -403,32 +428,27 @@ public:
return m_Poly->GetNumCorners();
}
void RemoveAllContours( void )
{
m_Poly->RemoveAllContours();
}
wxPoint GetCornerPosition( int aCornerIndex ) const
{
return wxPoint( m_Poly->GetX( aCornerIndex ), m_Poly->GetY( aCornerIndex ) );
}
void SetCornerPosition( int aCornerIndex, wxPoint new_pos )
{
m_Poly->SetX( aCornerIndex, new_pos.x );
m_Poly->SetY( aCornerIndex, new_pos.y );
}
void AppendCorner( wxPoint position )
{
m_Poly->AppendCorner( position.x, position.y );
}
int GetHatchStyle() const
{
return m_Poly->GetHatchStyle();
......@@ -436,12 +456,12 @@ public:
/**
* Function IsSame
* test is 2 zones are equivalent:
* tests if 2 zones are equivalent:
* 2 zones are equivalent if they have same parameters and same outlines
* info relative to filling is not take in account
* info, filling is not taken into account
* @param aZoneToCompare = zone to compare with "this"
*/
bool IsSame( const ZONE_CONTAINER &aZoneToCompare);
bool IsSame( const ZONE_CONTAINER &aZoneToCompare );
/**
* Function GetSmoothedPoly
......
......@@ -33,8 +33,8 @@ ZONE_SETTING::ZONE_SETTING( void )
m_ArcToSegmentsCount = ARC_APPROX_SEGMENTS_COUNT_LOW_DEF; /* Option to select number of segments to approximate a circle
* ARC_APPROX_SEGMENTS_COUNT_LOW_DEF
* or ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF segments */
m_ThermalReliefGapValue = 200; // tickness of the gap in thermal reliefs
m_ThermalReliefCopperBridgeValue = 200; // tickness of the copper bridge in thermal reliefs
m_ThermalReliefGap = 200; // tickness of the gap in thermal reliefs
m_ThermalReliefCopperBridge = 200; // tickness of the copper bridge in thermal reliefs
m_Zone_Pad_Options = THERMAL_PAD; // How pads are covered by copper in zone
......@@ -57,8 +57,8 @@ void ZONE_SETTING::ImportSetting( const ZONE_CONTAINER& aSource )
m_CurrentZone_Layer = aSource.GetLayer();
m_Zone_HatchingStyle = aSource.GetHatchStyle();
m_ArcToSegmentsCount = aSource.m_ArcToSegmentsCount;
m_ThermalReliefGapValue = aSource.m_ThermalReliefGapValue;
m_ThermalReliefCopperBridgeValue = aSource.m_ThermalReliefCopperBridgeValue;
m_ThermalReliefGap = aSource.m_ThermalReliefGap;
m_ThermalReliefCopperBridge = aSource.m_ThermalReliefCopperBridge;
m_Zone_Pad_Options = aSource.m_PadOption;
cornerSmoothingType = aSource.GetCornerSmoothingType();
cornerRadius = aSource.GetCornerRadius();
......@@ -81,8 +81,8 @@ void ZONE_SETTING::ExportSetting( ZONE_CONTAINER& aTarget, bool aFullExport )
aTarget.m_ZoneMinThickness = m_ZoneMinThickness;
aTarget.m_Poly->SetHatch( m_Zone_HatchingStyle );
aTarget.m_ArcToSegmentsCount = m_ArcToSegmentsCount;
aTarget.m_ThermalReliefGapValue = m_ThermalReliefGapValue;
aTarget.m_ThermalReliefCopperBridgeValue = m_ThermalReliefCopperBridgeValue;
aTarget.m_ThermalReliefGap = m_ThermalReliefGap;
aTarget.m_ThermalReliefCopperBridge = m_ThermalReliefCopperBridge;
aTarget.m_PadOption = m_Zone_Pad_Options;
aTarget.SetCornerSmoothingType( cornerSmoothingType );
aTarget.SetCornerRadius( cornerRadius );
......
......@@ -41,8 +41,8 @@ public:
// Option to select number of segments to approximate a circle 16 or 32 segments.
int m_ArcToSegmentsCount;
long m_ThermalReliefGapValue; // thickness of the gap in thermal reliefs
long m_ThermalReliefCopperBridgeValue; // thickness of the copper bridge in thermal reliefs
long m_ThermalReliefGap; // thickness of the gap in thermal reliefs
long m_ThermalReliefCopperBridge; // thickness of the copper bridge in thermal reliefs
int m_Zone_Pad_Options; // How pads are covered by copper in zone
private:
......
......@@ -122,10 +122,10 @@ void DIALOG_COPPER_ZONE::initDialog()
AddUnitSymbol( *m_AntipadSizeText, g_UserUnit );
AddUnitSymbol( *m_CopperBridgeWidthText, g_UserUnit );
PutValueInLocalUnits( *m_AntipadSizeValue,
m_Zone_Setting->m_ThermalReliefGapValue,
m_Zone_Setting->m_ThermalReliefGap,
PCB_INTERNAL_UNIT );
PutValueInLocalUnits( *m_CopperWidthValue,
m_Zone_Setting->m_ThermalReliefCopperBridgeValue,
m_Zone_Setting->m_ThermalReliefCopperBridge,
PCB_INTERNAL_UNIT );
m_cornerSmoothingChoice->SetSelection( m_Zone_Setting->GetCornerSmoothingType() );
......@@ -328,19 +328,19 @@ bool DIALOG_COPPER_ZONE::AcceptOptions( bool aPromptForErrors, bool aUseExportab
else
g_Zone_45_Only = TRUE;
m_Zone_Setting->m_ThermalReliefGapValue = ReturnValueFromTextCtrl( *m_AntipadSizeValue,
m_Zone_Setting->m_ThermalReliefGap = ReturnValueFromTextCtrl( *m_AntipadSizeValue,
PCB_INTERNAL_UNIT );
m_Zone_Setting->m_ThermalReliefCopperBridgeValue = ReturnValueFromTextCtrl(
m_Zone_Setting->m_ThermalReliefCopperBridge = ReturnValueFromTextCtrl(
*m_CopperWidthValue,
PCB_INTERNAL_UNIT );
m_Config->Write( ZONE_THERMAL_RELIEF_GAP_STRING_KEY,
(long) m_Zone_Setting->m_ThermalReliefGapValue );
(long) m_Zone_Setting->m_ThermalReliefGap );
m_Config->Write(
ZONE_THERMAL_RELIEF_COPPER_WIDTH_STRING_KEY,
(long) m_Zone_Setting->m_ThermalReliefCopperBridgeValue );
(long) m_Zone_Setting->m_ThermalReliefCopperBridge );
if( m_Zone_Setting->m_ThermalReliefCopperBridgeValue <= m_Zone_Setting->m_ZoneMinThickness )
if( m_Zone_Setting->m_ThermalReliefCopperBridge <= m_Zone_Setting->m_ZoneMinThickness )
{
DisplayError( this,
_( "Thermal relief spoke width is larger than the minimum width." ) );
......
......@@ -1030,7 +1030,7 @@ int PCB_EDIT_FRAME::ReadPcbFile( LINE_READER* aReader, bool Append )
continue;
}
if( TESTLINE( BRD_NETCLASS ) )
if( TESTLINE( "NCLASS" ) )
{
// create an empty NETCLASS without a name.
NETCLASS* netclass = new NETCLASS( board, wxEmptyString );
......
......@@ -22,16 +22,27 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* This implements loading and saving a BOARD, behind the PLUGIN interface.
/*
This implements loading and saving a BOARD, behind the PLUGIN interface.
The philosophy on loading:
*) BIUs should be typed as such to distinguish them from ints.
*) Do not assume that BIUs will always be int, doing a sscanf() into a BIU
does not make sense in case the size of the BUI changes.
*) variable are put onto the stack in an automatic, even when it might look
more efficient to do otherwise. This is so we can seem them with a debugger.
*) Global variable should not be touched from within a PLUGIN, since it will eventuall
be in a DLL/DSO. This includes window information too. The PLUGIN API knows
nothing of wxFrame.
*/
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <kicad_plugin.h> // I implement this
#include <kicad_plugin.h> // implement this here
#include <auto_ptr.h>
#include <kicad_string.h>
......@@ -121,21 +132,49 @@
#define MM_PER_BIU 1e-6
#define UM_PER_BIU 1e-3
/// Test for a specific length of characters.
/// C string compare test for a specific length of characters.
/// The -1 is to omit the trailing \0 which is included in sizeof() on a
/// string.
/// string constant.
#define TESTLINE( x ) (strncmp( line, x, sizeof(x) - 1 ) == 0)
/// Get the length of a constant string, at compile time
/// Get the length of a string constant, at compile time
#define SZ( x ) (sizeof(x)-1)
using namespace std; // auto_ptr
/**
* Function intParse
* parses an ASCII integer string with possible leading whitespace into
* an integers and updates the pointer at \a out if it is not NULL, just
* like "man strtol()". I can use this without casting, and its name says
* what I am doing.
*/
static inline int intParse( const char* next, const char** out = NULL )
{
// please just compile this and be quiet, hide casting ugliness:
return (int) strtol( next, (char**) out, 10 );
}
/**
* Function hexParse
* parses an ASCII hex integer string with possible leading whitespace into
* a long integer and updates the pointer at \a out if it is not NULL, just
* like "man strtol()". I can use this without casting, and its name says
* what I am doing.
*/
static inline long hexParse( const char* next, const char** out = NULL )
{
// please just compile this and be quiet, hide casting ugliness:
return strtol( next, (char**) out, 16 );
}
BOARD* KICAD_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES* aProperties )
{
LOCALE_IO toggle; // toggles on then off the C locale.
wxString msg;
LOCALE_IO toggle; // toggles on, then off, the C locale.
m_board = aAppendToMe ? aAppendToMe : new BOARD( NULL );
......@@ -201,35 +240,25 @@ void KICAD_PLUGIN::loadAllSections( bool doAppend )
else if( TESTLINE( "$TRACK" ) )
{
TRACK* insertBeforeMe = doAppend ? NULL : m_board->m_Track.GetFirst();
loadTrackList( insertBeforeMe, PCB_TRACE_T, NbTrack );
loadTrackList( insertBeforeMe, PCB_TRACE_T );
}
else if( TESTLINE( "$" BRD_NETCLASS ) )
else if( TESTLINE( "$NCLASS" ) )
{
loadNETCLASS();
}
#if 0
else if( TESTLINE( "$CZONE_OUTLINE" ) )
{
auto_ptr<ZONE_CONTAINER> zone_descr( new ZONE_CONTAINER( m_board ) );
load( zone_descr.get() );
if( zone_descr->GetNumCorners() > 2 ) // should always occur
m_board->Add( zone_descr.release() );
// else delete zone_descr; done by auto_ptr
loadZONE_CONTAINER();
}
else if( TESTLINE( "$COTATION" ) )
{
DIMENSION* dim = new DIMENSION( m_board );
m_board->Add( dim, ADD_APPEND );
load( dim );
loadDIMENSION();
}
#if 0
else if( TESTLINE( "$PCB_TARGET" ) )
{
PCB_TARGET* t = new PCB_TARGET( m_board );
......@@ -299,23 +328,19 @@ void KICAD_PLUGIN::loadGENERAL()
// what are the engineering units of the dimensions in the BOARD?
data = strtok( line + SZ("Units"), delims );
if( strcmp( data, "mm" ) == 0 )
if( !strcmp( data, "mm" ) )
{
#if defined(KICAD_NANOMETRE)
diskToBiu = 1000000.0;
#else
m_error = wxT( "May not load new *.brd file into 'PCBNew compiled for deci-mils'" );
THROW_IO_ERROR( m_error );
THROW_IO_ERROR( _( "May not load new *.brd file into 'PCBNew compiled for deci-mils'" ) );
#endif
}
}
else if( TESTLINE( "EnabledLayers" ) )
{
int enabledLayers = 0;
data = strtok( line + SZ( "EnabledLayers" ), delims );
sscanf( data, "%X", &enabledLayers );
int enabledLayers = hexParse( line + SZ( "EnabledLayers" ) );
// Setup layer visibility
m_board->SetEnabledLayers( enabledLayers );
......@@ -323,10 +348,7 @@ void KICAD_PLUGIN::loadGENERAL()
else if( TESTLINE( "Ly" ) ) // Old format for Layer count
{
int layer_mask = 1;
data = strtok( line + SZ( "Ly" ), delims );
sscanf( data, "%X", &layer_mask );
int layer_mask = hexParse( line + SZ( "Ly" ) );
int layer_count = 0;
......@@ -341,24 +363,25 @@ void KICAD_PLUGIN::loadGENERAL()
else if( TESTLINE( "BoardThickness" ) )
{
data = strtok( line + SZ( "BoardThickness" ), delims );
data = line + SZ( "BoardThickness" );
m_board->GetBoardDesignSettings()->m_BoardThickness = atoi( data );
}
/*
else if( TESTLINE( "Links" ) )
{
// Info only, do nothing, but only for a short while.
}
*/
else if( TESTLINE( "NoConn" ) )
{
data = strtok( line + SZ( "NoConn" ), delims );
data = line + SZ( "NoConn" );
m_board->m_NbNoconnect = atoi( data );
}
else if( TESTLINE( "Di" ) )
{
// skip the first token "Di".
// no use of strtok() in this one, don't want the nuls
data = line + SZ( "Di" );
......@@ -377,31 +400,31 @@ void KICAD_PLUGIN::loadGENERAL()
// Read the number of segments of type DRAW, TRACK, ZONE
else if( TESTLINE( "Ndraw" ) )
{
data = strtok( line + SZ( "Ndraw" ), delims );
data = line + SZ( "Ndraw" );
NbDraw = atoi( data );
}
else if( TESTLINE( "Ntrack" ) )
{
data = strtok( line + SZ( "Ntrack" ), delims );
data = line + SZ( "Ntrack" );
NbTrack = atoi( data );
}
else if( TESTLINE( "Nzone" ) )
{
data = strtok( line + SZ( "Nzone" ), delims );
data = line + SZ( "Nzone" );
NbZone = atoi( data );
}
else if( TESTLINE( "Nmodule" ) )
{
data = strtok( line + SZ( "Nmodule" ), delims );
data = line + SZ( "Nmodule" );
NbMod = atoi( data );
}
else if( TESTLINE( "Nnets" ) )
{
data = strtok( line + SZ( "Nnets" ), delims );
data = line + SZ( "Nnets" );
NbNets = atoi( data );
}
}
......@@ -437,7 +460,7 @@ void KICAD_PLUGIN::loadSHEET()
{
if( stricmp( TO_UTF8( sheet->m_Name ), text ) == 0 )
{
// screen->m_CurrentSheetDesc = sheet;
// @todo screen->m_CurrentSheetDesc = sheet;
if( sheet == &g_Sheet_user )
{
......@@ -521,17 +544,19 @@ void KICAD_PLUGIN::loadSETUP()
while( aReader->ReadLine() )
{
char* line = aReader->Line();
const char* data;
char* line = aReader->Line();
if( TESTLINE( "PcbPlotParams" ) )
{
PCB_PLOT_PARAMS_PARSER parser( &line[13], aReader->GetSource() );
PCB_PLOT_PARAMS_PARSER parser( line + SZ( "PcbPlotParams" ), aReader->GetSource() );
try
// try
{
g_PcbPlotOptions.Parse( &parser );
}
/* move this higher up
catch( IO_ERROR& e )
{
wxString msg;
......@@ -541,13 +566,10 @@ void KICAD_PLUGIN::loadSETUP()
e.errorText.GetData() );
wxMessageBox( msg, _( "Open Board File" ), wxICON_ERROR );
}
continue;
*/
}
strtok( line, delims );
data = strtok( NULL, delims );
if( TESTLINE( "$EndSETUP" ) )
else if( TESTLINE( "$EndSETUP" ) )
{
// Until such time as the *.brd file does not have the
// global parameters:
......@@ -571,7 +593,7 @@ void KICAD_PLUGIN::loadSETUP()
else if( TESTLINE( "AuxiliaryAxisOrg" ) )
{
BIU gx = biuParse( data, &data );
BIU gx = biuParse( line + SZ( "AuxiliaryAxisOrg" ), &data );
BIU gy = biuParse( data );
/* @todo
......@@ -584,20 +606,17 @@ void KICAD_PLUGIN::loadSETUP()
else if( TESTLINE( "Layers" ) == 0 )
{
int tmp = atoi( data );
int tmp = atoi( line + SZ( "Layers" ) );
m_board->SetCopperLayerCount( tmp );
}
else if( TESTLINE( "Layer[" ) )
{
const int LAYERKEYZ = sizeof("Layer[") - 1;
// parse:
// Layer[n] <a_Layer_name_with_no_spaces> <LAYER_T>
// eg: "Layer[n] <a_Layer_name_with_no_spaces> <LAYER_T>"
char* cp = line + LAYERKEYZ;
int layer = atoi( cp );
int layer = intParse( line + SZ( "Layer[" ), &data );
data = strtok( (char*) data+1, delims ); // +1 for ']'
if( data )
{
wxString layerName = FROM_UTF8( data );
......@@ -626,49 +645,49 @@ void KICAD_PLUGIN::loadSETUP()
else if( TESTLINE( "TrackWidthList" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "TrackWidthList" ) );
m_board->m_TrackWidthList.push_back( tmp );
}
else if( TESTLINE( "TrackClearence" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "TrackClearence" ) );
netclass_default->SetClearance( tmp );
}
else if( TESTLINE( "TrackMinWidth" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "TrackMinWidth" ) );
m_board->GetBoardDesignSettings()->m_TrackMinWidth = tmp;
}
else if( TESTLINE( "ZoneClearence" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "ZoneClearence" ) );
g_Zone_Default_Setting.m_ZoneClearance = tmp;
}
else if( TESTLINE( "DrawSegmWidth" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "DrawSegmWidth" ) );
m_board->GetBoardDesignSettings()->m_DrawSegmentWidth = tmp;
}
else if( TESTLINE( "EdgeSegmWidth" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "EdgeSegmWidth" ) );
m_board->GetBoardDesignSettings()->m_EdgeSegmentWidth = tmp;
}
else if( TESTLINE( "ViaMinSize" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "ViaMinSize" ) );
m_board->GetBoardDesignSettings()->m_ViasMinSize = tmp;
}
else if( TESTLINE( "MicroViaMinSize" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "MicroViaMinSize" ) );
m_board->GetBoardDesignSettings()->m_MicroViasMinSize = tmp;
}
......@@ -677,11 +696,10 @@ void KICAD_PLUGIN::loadSETUP()
// e.g. "ViaSizeList DIAMETER [DRILL]"
BIU drill = 0;
BIU diameter = biuParse( data );
BIU diameter = biuParse( line + SZ( "ViaSizeList" ), &data );
data = strtok( NULL, delims );
if( data ) // DRILL may not be present
data = strtok( (char*) data, delims );
if( data ) // DRILL may not be present ?
drill = biuParse( data );
m_board->m_ViasDimensionsList.push_back( VIA_DIMENSION( diameter, drill ) );
......@@ -689,42 +707,43 @@ void KICAD_PLUGIN::loadSETUP()
else if( TESTLINE( "ViaDrill" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "ViaDrill" ) );
netclass_default->SetViaDrill( tmp );
}
else if( TESTLINE( "ViaMinDrill" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "ViaMinDrill" ) );
m_board->GetBoardDesignSettings()->m_ViasMinDrill = tmp;
}
else if( TESTLINE( "MicroViaDrill" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "MicroViaDrill" ) );
netclass_default->SetuViaDrill( tmp );
}
else if( TESTLINE( "MicroViaMinDrill" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "MicroViaMinDrill" ) );
m_board->GetBoardDesignSettings()->m_MicroViasMinDrill = tmp;
}
else if( TESTLINE( "MicroViasAllowed" ) )
{
m_board->GetBoardDesignSettings()->m_MicroViasAllowed = atoi( data );
int tmp = atoi( line + SZ( "MicroViasAllowed" ) );
m_board->GetBoardDesignSettings()->m_MicroViasAllowed = tmp;
}
else if( TESTLINE( "TextPcbWidth" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "TextPcbWidth" ) );
m_board->GetBoardDesignSettings()->m_PcbTextWidth = tmp;
}
else if( TESTLINE( "TextPcbSize" ) )
{
BIU x = biuParse( data, &data );
BIU x = biuParse( line + SZ( "TextPcbSize" ), &data );
BIU y = biuParse( data );
m_board->GetBoardDesignSettings()->m_PcbTextSize = wxSize( x, y );
......@@ -732,7 +751,7 @@ void KICAD_PLUGIN::loadSETUP()
else if( TESTLINE( "EdgeModWidth" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "EdgeModWidth" ) );
/* @todo
g_ModuleSegmentWidth = tmp;
*/
......@@ -740,7 +759,7 @@ void KICAD_PLUGIN::loadSETUP()
else if( TESTLINE( "TextModWidth" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "TextModWidth" ) );
/* @todo
g_ModuleTextWidth = tmp;
*/
......@@ -748,7 +767,7 @@ void KICAD_PLUGIN::loadSETUP()
else if( TESTLINE( "TextModSize" ) )
{
BIU x = biuParse( data, &data );
BIU x = biuParse( line + SZ( "TextModSize" ), &data );
BIU y = biuParse( data );
/* @todo
g_ModuleTextSize = wxSize( x, y );
......@@ -757,7 +776,7 @@ void KICAD_PLUGIN::loadSETUP()
else if( TESTLINE( "PadSize" ) )
{
BIU x = biuParse( data, &data );
BIU x = biuParse( line + SZ( "PadSize" ), &data );
BIU y = biuParse( data );
/* @todo
g_Pad_Master.m_Size = wxSize( x, y );
......@@ -766,7 +785,7 @@ void KICAD_PLUGIN::loadSETUP()
else if( TESTLINE( "PadDrill" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "PadDrill" ) );
/* @todo
g_Pad_Master.m_Drill.x( tmp );
g_Pad_Master.m_Drill.y( tmp );
......@@ -775,25 +794,25 @@ void KICAD_PLUGIN::loadSETUP()
else if( TESTLINE( "Pad2MaskClearance" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "Pad2MaskClearance" ) );
m_board->GetBoardDesignSettings()->m_SolderMaskMargin = tmp;
}
else if( TESTLINE( "Pad2PasteClearance" ) )
{
BIU tmp = biuParse( data );
BIU tmp = biuParse( line + SZ( "Pad2PasteClearance" ) );
m_board->GetBoardDesignSettings()->m_SolderPasteMargin = tmp;
}
else if( TESTLINE( "Pad2PasteClearanceRatio" ) )
{
double ratio = atof( data );
double ratio = atof( line + SZ( "Pad2PasteClearanceRatio" ) );
m_board->GetBoardDesignSettings()->m_SolderPasteMarginRatio = ratio;
}
else if( TESTLINE( "GridOrigin" ) )
{
BIU gx = biuParse( data, &data );
BIU gx = biuParse( line + SZ( "GridOrigin" ), &data );
BIU gy = biuParse( data );
/* @todo
......@@ -872,8 +891,7 @@ void KICAD_PLUGIN::loadMODULE()
case 'N': // Shape File Name
{
char buf[512];
ReadDelimitedText( buf, text, 512 );
ReadDelimitedText( buf, text, sizeof(buf) );
t3D->m_Shape3DName = FROM_UTF8( buf );
}
break;
......@@ -926,20 +944,20 @@ void KICAD_PLUGIN::loadDRAWSEGMENT()
{
char* line = aReader->Line();
if( strnicmp( line, "$End", 4 ) == 0 )
return; // Normal end matches here, because it's: $EndDRAWSEGMENT
if( TESTLINE( "$EndDRAWSEGMENT" ) )
return; // preferred exit
if( line[0] == 'P' )
else if( TESTLINE( "Po" ) )
{
// sscanf( line + 2, " %d %d %d %d %d %d", &m_Shape, &m_Start.x, &m_Start.y, &m_End.x, &m_End.y, &m_Width );
const char* next = line + 2;
const char* data = line + SZ( "Po" );
BIU shape = biuParse( next, &next );
BIU start_x = biuParse( next, &next );
BIU start_y = biuParse( next, &next );
BIU end_x = biuParse( next, &next );
BIU end_y = biuParse( next, &next );
BIU width = biuParse( next );
BIU shape = biuParse( data, &data );
BIU start_x = biuParse( data, &data );
BIU start_y = biuParse( data, &data );
BIU end_x = biuParse( data, &data );
BIU end_y = biuParse( data, &data );
BIU width = biuParse( data );
if( width < 0 )
width = 0;
......@@ -950,19 +968,20 @@ void KICAD_PLUGIN::loadDRAWSEGMENT()
dseg->SetEnd( wxPoint( end_x, end_y ) );
}
else if( line[0] == 'D' )
else if( TESTLINE( "De" ) )
{
const char* data = strtok( line, " " ); // "De", skip it
BIU x = 0;
BIU y = 0;
BIU y;
int val;
char* token = strtok( line, " " ); // "De", skip it
for( int i = 0; (token = strtok( NULL," " )) != NULL; ++i )
for( int i = 0; (data = strtok( NULL, " " )) != NULL; ++i )
{
switch( i )
{
case 0:
sscanf( token, "%d", &val );
val = atoi( data );
if( val < FIRST_NO_COPPER_LAYER )
val = FIRST_NO_COPPER_LAYER;
......@@ -973,35 +992,37 @@ void KICAD_PLUGIN::loadDRAWSEGMENT()
dseg->SetLayer( val );
break;
case 1:
sscanf( token, "%d", &val );
val = atoi( data );
dseg->SetType( val ); // m_Type
break;
case 2:
sscanf( token, "%d", &val );
val = atoi( data );
dseg->SetAngle( val ); // m_Angle
break;
case 3:
sscanf( token, "%lX", &dseg->m_TimeStamp );
long timestamp;
timestamp = hexParse( data );
dseg->SetTimeStamp( timestamp );
break;
case 4:
sscanf( token, "%X", &val );
val = hexParse( data );
dseg->SetState( val, ON );
break;
// Bezier Control Points
case 5:
x = biuParse( token );
x = biuParse( data );
break;
case 6:
y = biuParse( token );
y = biuParse( data );
dseg->SetBezControl1( wxPoint( x, y ) );
break;
case 7:
x = biuParse( token );
x = biuParse( data );
break;
case 8:
y = biuParse( token );
y = biuParse( data );
dseg->SetBezControl2( wxPoint( x, y ) );
break;
......@@ -1190,7 +1211,7 @@ void KICAD_PLUGIN::loadPCB_TEXTE()
}
void KICAD_PLUGIN::loadTrackList( TRACK* aInsertBeforeMe, int aStructType, int aSegCount )
void KICAD_PLUGIN::loadTrackList( TRACK* aInsertBeforeMe, int aStructType )
{
static const char delims[] = " \t\n\r"; // for this function only.
......@@ -1202,16 +1223,17 @@ void KICAD_PLUGIN::loadTrackList( TRACK* aInsertBeforeMe, int aStructType, int a
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 );
assert( TESTLINE( "Po" ) );
const char* data = line + SZ( "Po" );
int shape = (int) strtol( data, (char**) &data, 10 );
int shape = intParse( data, &data );
BIU startX = biuParse( data, &data );
BIU startY = biuParse( data, &data );
BIU endX = biuParse( data, &data );
......@@ -1238,7 +1260,7 @@ void KICAD_PLUGIN::loadTrackList( TRACK* aInsertBeforeMe, int aStructType, int a
// example second line:
// "De 0 0 463 0 800000\r\n"
if( line[0] == '$' )
if( !TESTLINE( "De" ) )
{
// mandatory 2nd line is missing
THROW_IO_ERROR( wxT( "Missing 2nd line of a TRACK def" ) );
......@@ -1256,6 +1278,8 @@ void KICAD_PLUGIN::loadTrackList( TRACK* aInsertBeforeMe, int aStructType, int a
else
makeType = aStructType;
TRACK* newTrack; // BOARD insert this new one immediately after instantiation
switch( makeType )
{
default:
......@@ -1326,7 +1350,7 @@ void KICAD_PLUGIN::loadNETCLASS()
netclass->Add( netname );
}
else if( TESTLINE( "$end" BRD_NETCLASS ) )
else if( TESTLINE( "$endNCLASS" ) )
{
if( m_board->m_NetClasses.Add( netclass.get() ) )
{
......@@ -1343,7 +1367,7 @@ void KICAD_PLUGIN::loadNETCLASS()
THROW_IO_ERROR( m_error );
}
return; // prefered exit
return; // preferred exit
}
else if( TESTLINE( "Clearance" ) )
......@@ -1395,7 +1419,462 @@ void KICAD_PLUGIN::loadNETCLASS()
}
}
THROW_IO_ERROR( wxT( "Missing '$End" BRD_NETCLASS ) );
THROW_IO_ERROR( wxT( "Missing '$EndNCLASS'" ) );
}
void KICAD_PLUGIN::loadZONE_CONTAINER()
{
auto_ptr<ZONE_CONTAINER> zc( new ZONE_CONTAINER( m_board ) );
int outline_hatch = CPolyLine::NO_HATCH;
bool sawCorner = false;
int layer = 0;
while( aReader->ReadLine() )
{
char* line = aReader->Line();
if( TESTLINE( "ZCorner" ) ) // new corner found
{
// e.g. "ZCorner 25650 49500 0"
const char* data = line + SZ( "ZCorner" );
BIU x = biuParse( data, &data );
BIU y = biuParse( data, &data );
int flag = atoi( data );
if( !sawCorner )
zc->m_Poly->Start( layer, x, y, outline_hatch );
else
zc->AppendCorner( wxPoint( x, y ) );
sawCorner = true;
if( flag )
zc->m_Poly->Close();
}
else if( TESTLINE( "ZInfo" ) ) // general info found
{
// e.g. 'ZInfo 479194B1 310 "COMMON"'
const char* data = line + SZ( "ZInfo" );
char buf[1024];
long timestamp = hexParse( data, &data );
int netcode = intParse( data, &data );
if( ReadDelimitedText( buf, data, sizeof(buf) ) > (int) sizeof(buf) )
{
THROW_IO_ERROR( wxT( "ZInfo netname too long" ) );
}
zc->SetTimeStamp( timestamp );
zc->SetNet( netcode );
zc->SetNetName( FROM_UTF8( buf ) );
}
else if( TESTLINE( "ZLayer" ) ) // layer found
{
char* data = line + SZ( "ZLayer" );
layer = atoi( data );
}
else if( TESTLINE( "ZAux" ) ) // aux info found
{
// e.g. "ZAux 7 E"
char* data = line + SZ( "ZAux" );
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() );
THROW_IO_ERROR( m_error );
}
switch( hopt[0] ) // upper case required
{
case 'N':
outline_hatch = CPolyLine::NO_HATCH;
break;
case 'E':
outline_hatch = CPolyLine::DIAGONAL_EDGE;
break;
case 'F':
outline_hatch = CPolyLine::DIAGONAL_FULL;
break;
default:
m_error.Printf( wxT( "Bad ZAux for CZONE_CONTAINER '%s'" ), zc->GetNetName().GetData() );
THROW_IO_ERROR( m_error );
}
// Set hatch mode later, after reading corner outline data
}
else if( TESTLINE( "ZSmoothing" ) )
{
// e.g. "ZSmoothing 0 0"
const char* data = line + SZ( "ZSmoothing" );
int smoothing = intParse( data, &data );
BIU cornerRadius = biuParse( data );
if( smoothing >= ZONE_SETTING::SMOOTHING_LAST || smoothing < 0 )
{
m_error.Printf( wxT( "Bad ZSmoothing for CZONE_CONTAINER '%s'" ), zc->GetNetName().GetData() );
THROW_IO_ERROR( m_error );
}
zc->SetCornerSmoothingType( smoothing );
zc->SetCornerRadius( cornerRadius );
}
else if( TESTLINE( "ZOptions" ) )
{
// e.g. "ZOptions 0 32 F 200 200"
const char* data = line + SZ( "ZOptions" );
int fillmode = intParse( data, &data );
int arcsegcount = intParse( data, &data );
char fillstate = data[1]; // here e.g. " F"
BIU thermalReliefGap = biuParse( data += 2 , &data ); // +=2 for " F"
BIU thermalReliefCopperBridge = biuParse( data );
zc->SetFillMode( fillmode ? 1 : 0 );
if( arcsegcount >= 32 /* ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF: don't really want pcbnew.h in here, after all, its a PLUGIN and global data is evil. */ )
arcsegcount = 32;
zc->SetArcSegCount( arcsegcount );
zc->SetIsFilled( fillstate == 'S' ? true : false );
zc->SetThermalReliefGap( thermalReliefGap );
zc->SetThermalReliefCopperBridge( thermalReliefCopperBridge );
}
else if( TESTLINE( "ZClearance" ) ) // Clearance and pad options info found
{
// e.g. "ZClearance 40 I"
const char* data = line + SZ( "ZClearance" );
BIU clearance = biuParse( data, &data );
int padoption = data[1]; // e.g. " I"
zc->SetZoneClearance( clearance );
switch( padoption )
{
case 'I':
padoption = PAD_IN_ZONE;
break;
case 'T':
padoption = THERMAL_PAD;
break;
case 'X':
padoption = PAD_NOT_IN_ZONE;
break;
default:
m_error.Printf( wxT( "Bad ZClearance padoption for CZONE_CONTAINER '%s'" ), zc->GetNetName().GetData() );
THROW_IO_ERROR( m_error );
}
zc->SetPadOption( padoption );
}
else if( TESTLINE( "ZMinThickness" ) )
{
char* data = line + SZ( "ZMinThickness" );
BIU thickness = biuParse( data );
zc->SetMinThickness( thickness );
}
else if( TESTLINE( "$POLYSCORNERS" ) )
{
// Read the PolysList (polygons used for fill areas in the zone)
while( aReader->ReadLine() )
{
line = aReader->Line();
if( TESTLINE( "$endPOLYSCORNERS" ) )
break;
// e.g. "39610 43440 0 0"
const char* data = line;
BIU x = 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
int utility = atoi( data + 3 );
zc->m_FilledPolysList.push_back( CPolyPt( x, y, end_contour, utility ) );
}
}
else if( TESTLINE( "$FILLSEGMENTS" ) )
{
while( aReader->ReadLine() )
{
line = aReader->Line();
if( TESTLINE( "$endFILLSEGMENTS" ) )
break;
const char* data = line;
BIU sx = biuParse( data, &data );
BIU sy = biuParse( data, &data );
BIU ex = biuParse( data, &data );
BIU ey = biuParse( data );
zc->m_FillSegmList.push_back( SEGMENT(
wxPoint( sx, sy ),
wxPoint( ex, ey ) ) );
}
}
else if( TESTLINE( "$endCZONE_OUTLINE" ) )
{
// should always occur, but who knows, a zone without two corners
// is no zone at all, it's a spot?
if( zc->GetNumCorners() > 2 )
{
if( !zc->IsOnCopperLayer() )
{
zc->SetFillMode( 0 );
zc->SetNet( 0 );
}
// Set hatch here, when outlines corners are read
zc->m_Poly->SetHatch( outline_hatch );
m_board->Add( zc.release() );
}
return; // preferred exit
}
}
THROW_IO_ERROR( wxT( "Missing '$endCZONE_OUTLINE'" ) );
}
void KICAD_PLUGIN::loadDIMENSION()
{
auto_ptr<DIMENSION> dim( new DIMENSION( m_board ) );
while( aReader->ReadLine() )
{
const char* data;
char* line = aReader->Line();
if( TESTLINE( "$EndDIMENSION" ) )
{
m_board->Add( dim.release(), ADD_APPEND );
return; // preferred exit
}
else if( TESTLINE( "Va" ) )
{
BIU value = biuParse( line + SZ( "Va" ) );
dim->m_Value = value;
}
else if( TESTLINE( "Ge" ) )
{
int layer;
long timestamp;
int shape;
sscanf( line + SZ( "Ge" ), " %d %d %lX", &shape, &layer, &timestamp );
if( layer < FIRST_NO_COPPER_LAYER )
layer = FIRST_NO_COPPER_LAYER;
else if( layer > LAST_NO_COPPER_LAYER )
layer = LAST_NO_COPPER_LAYER;
dim->SetLayer( layer );
dim->SetTimeStamp( timestamp );
dim->m_Shape = shape;
}
else if( TESTLINE( "Te" ) )
{
char buf[2048];
ReadDelimitedText( buf, line + SZ( "Te" ), sizeof(buf) );
dim->m_Text->SetText( FROM_UTF8( buf ) );
}
else if( TESTLINE( "Po" ) )
{
// sscanf( Line + 2, " %d %d %d %d %d %d %d", &m_Text->m_Pos.x, &m_Text->m_Pos.y,
// &m_Text->m_Size.x, &m_Text->m_Size.y, &thickness, &orientation, &normal_display );
int normal_display = 1;
BIU pos_x = biuParse( line + SZ( "Po" ), &data );
BIU pos_y = biuParse( data, &data );
BIU width = biuParse( data, &data );
BIU height = biuParse( data, &data );
BIU thickn = biuParse( data, &data );
int orient = intParse( data, &data );
data = strtok( (char*) data, " \t\r\n" );
if( data ) // optional from old days?
normal_display = intParse( data );
// This sets both DIMENSION's position and internal m_Text's.
// @todo: But why do we even know about internal m_Text?
dim->SetPosition( wxPoint( pos_x, pos_y ) );
dim->SetTextSize( wxSize( width, height ) );
dim->m_Text->m_Mirror = normal_display ? false : true;
dim->m_Text->SetThickness( thickn );
dim->m_Text->SetOrientation( orient );
}
else if( TESTLINE( "Sb" ) )
{
// sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_crossBarOx, &m_crossBarOy, &m_crossBarFx, &m_crossBarFy, &m_Width );
int ignore = biuParse( line + SZ( "Sb" ), &data );
BIU crossBarOx = biuParse( data, &data );
BIU crossBarOy = biuParse( data, &data );
BIU crossBarFx = biuParse( data, &data );
BIU crossBarFy = biuParse( data, &data );
BIU width = biuParse( data );
dim->m_crossBarOx = crossBarOx;
dim->m_crossBarOy = crossBarOy;
dim->m_crossBarFx = crossBarFx;
dim->m_crossBarFy = crossBarFy;
dim->m_Width = width;
(void) ignore;
}
else if( TESTLINE( "Sd" ) )
{
// sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_featureLineDOx, &m_featureLineDOy, &m_featureLineDFx, &m_featureLineDFy, &Dummy );
int ignore = intParse( line + SZ( "Sd" ), &data );
BIU featureLineDOx = biuParse( data, &data );
BIU featureLineDOy = biuParse( data, &data );
BIU featureLineDFx = biuParse( data, &data );
BIU featureLineDFy = biuParse( data );
dim->m_featureLineDOx = featureLineDOx;
dim->m_featureLineDOy = featureLineDOy;
dim->m_featureLineDFx = featureLineDFx;
dim->m_featureLineDFy = featureLineDFy;
(void) ignore;
}
else if( TESTLINE( "Sg" ) )
{
// sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_featureLineGOx, &m_featureLineGOy, &m_featureLineGFx, &m_featureLineGFy, &Dummy );
int ignore = intParse( line + SZ( "Sg" ), &data );
BIU featureLineGOx = biuParse( data, &data );
BIU featureLineGOy = biuParse( data, &data );
BIU featureLineGFx = biuParse( data, &data );
BIU featureLineGFy = biuParse( data );
dim->m_featureLineGOx = featureLineGOx;
dim->m_featureLineGOy = featureLineGOy;
dim->m_featureLineGFx = featureLineGFx;
dim->m_featureLineGFy = featureLineGFy;
(void) ignore;
}
else if( TESTLINE( "S1" ) )
{
// sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_arrowD1Ox, &m_arrowD1Oy, &m_arrowD1Fx, &m_arrowD1Fy, &Dummy );
int ignore = intParse( line + SZ( "S1" ), &data );
BIU arrowD10x = biuParse( data, &data );
BIU arrowD10y = biuParse( data, &data );
BIU arrowD1Fx = biuParse( data, &data );
BIU arrowD1Fy = biuParse( data );
dim->m_arrowD1Ox = arrowD10x;
dim->m_arrowD1Oy = arrowD10y;
dim->m_arrowD1Fx = arrowD1Fx;
dim->m_arrowD1Fy = arrowD1Fy;
(void) ignore;
}
else if( TESTLINE( "S2" ) )
{
// sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_arrowD2Ox, &m_arrowD2Oy, &m_arrowD2Fx, &m_arrowD2Fy, &Dummy );
int ignore = intParse( line + SZ( "S2" ), &data );
BIU arrowD2Ox = biuParse( data, &data );
BIU arrowD2Oy = biuParse( data, &data );
BIU arrowD2Fx = biuParse( data, &data );
BIU arrowD2Fy = biuParse( data, &data );
dim->m_arrowD2Ox = arrowD2Ox;
dim->m_arrowD2Oy = arrowD2Oy;
dim->m_arrowD2Fx = arrowD2Fx;
dim->m_arrowD2Fy = arrowD2Fy;
(void) ignore;
}
else if( TESTLINE( "S3" ) )
{
// sscanf( Line + 2, " %d %d %d %d %d %d\n", &Dummy, &m_arrowG1Ox, &m_arrowG1Oy, &m_arrowG1Fx, &m_arrowG1Fy, &Dummy );
int ignore = intParse( line + SZ( "S3" ), &data );
BIU arrowG1Ox = biuParse( data, &data );
BIU arrowG1Oy = biuParse( data, &data );
BIU arrowG1Fx = biuParse( data, &data );
BIU arrowG1Fy = biuParse( data, &data );
dim->m_arrowG1Ox = arrowG1Ox;
dim->m_arrowG1Oy = arrowG1Oy;
dim->m_arrowG1Fx = arrowG1Fx;
dim->m_arrowG1Fy = arrowG1Fy;
(void) ignore;
}
else if( TESTLINE( "S4" ) )
{
// sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_arrowG2Ox, &m_arrowG2Oy, &m_arrowG2Fx, &m_arrowG2Fy, &Dummy );
int ignore = intParse( line + SZ( "S4" ), &data );
BIU arrowG2Ox = biuParse( data, &data );
BIU arrowG2Oy = biuParse( data, &data );
BIU arrowG2Fx = biuParse( data, &data );
BIU arrowG2Fy = biuParse( data, &data );
dim->m_arrowG2Ox = arrowG2Ox;
dim->m_arrowG2Oy = arrowG2Oy;
dim->m_arrowG2Fx = arrowG2Fx;
dim->m_arrowG2Fy = arrowG2Fy;
(void) ignore;
}
}
THROW_IO_ERROR( wxT( "Missing '$EndDIMENSION'" ) );
}
......@@ -1430,9 +1909,17 @@ BIU KICAD_PLUGIN::biuParse( const char* aValue, const char** nptrptr )
double fval = strtod( aValue, &nptr );
if( errno || aValue == nptr )
if( errno )
{
m_error.Printf( _( "invalid float number in file: '%s' on line: %d" ),
aReader->GetSource().GetData(), aReader->LineNumber() );
THROW_IO_ERROR( m_error );
}
if( aValue == nptr )
{
m_error.Printf( _( "invalid float number in file: '%s' line: %d" ),
m_error.Printf( _( "missing float number in file: '%s' on line: %d" ),
aReader->GetSource().GetData(), aReader->LineNumber() );
THROW_IO_ERROR( m_error );
......
......@@ -112,17 +112,25 @@ protected:
/**
* Function loadTrackList
* reads a list of segments (Tracks and Vias)
* reads a list of segments (Tracks and Vias, or Segzones)
*
* @param aInsertBeforeMe may be either NULL indicating append, or it may
* be an insertion point before which all the segments are inserted.
*
* @param aStructType is either PCB_TRACE_T to indicate tracks and vias, or
* PCB_ZONE_T to indicate oldschool zone segments (before polygons came to be).
*/
void loadTrackList( TRACK* aInsertBeforeMe, int aStructType, int aSegCount );
void loadTrackList( TRACK* aInsertBeforeMe, int aStructType );
void loadZONE_CONTAINER(); // "$CZONE_OUTLINE"
void loadDIMENSION(); // "$COTATION"
/* @todo
void load( PCB_TARGET* me );
void load( NETINFO* me );
void load( TRACK* me );
void load( ZONE_CONTAINER* me );
void load( DIMENSION* me );
*/
// void load( SEGZONE* me );
......
......@@ -480,9 +480,9 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC )
}
wxGetApp().m_EDA_Config->Read( ZONE_THERMAL_RELIEF_GAP_STRING_KEY,
&g_Zone_Default_Setting.m_ThermalReliefGapValue );
&g_Zone_Default_Setting.m_ThermalReliefGap );
wxGetApp().m_EDA_Config->Read( ZONE_THERMAL_RELIEF_COPPER_WIDTH_STRING_KEY,
&g_Zone_Default_Setting.m_ThermalReliefCopperBridgeValue );
&g_Zone_Default_Setting.m_ThermalReliefCopperBridge );
g_Zone_Default_Setting.m_CurrentZone_Layer = zone->GetLayer();
DIALOG_COPPER_ZONE* frame = new DIALOG_COPPER_ZONE( this, &g_Zone_Default_Setting );
......
......@@ -342,13 +342,13 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
if( pad->GetNet() != GetNet() )
continue;
item_boundingbox = pad->GetBoundingBox();
item_boundingbox.Inflate( m_ThermalReliefGapValue, m_ThermalReliefGapValue );
item_boundingbox.Inflate( m_ThermalReliefGap, m_ThermalReliefGap );
if( item_boundingbox.Intersects( zone_boundingbox ) )
{
CreateThermalReliefPadPolygon( cornerBufferPolysToSubstract,
*pad, m_ThermalReliefGapValue,
m_ThermalReliefCopperBridgeValue,
*pad, m_ThermalReliefGap,
m_ThermalReliefCopperBridge,
m_ZoneMinThickness,
s_CircleToSegmentsCount,
s_Correction, s_thermalRot );
......
......@@ -49,7 +49,7 @@ void BuildUnconnectedThermalStubsPolygonList( std::vector<CPolyPt>& aCornerBuffe
int pen_radius = aZone->m_ZoneMinThickness / 2;
// Calculate thermal bridge half width
int thermbridgeWidth = aZone->m_ThermalReliefCopperBridgeValue / 2;
int thermbridgeWidth = aZone->m_ThermalReliefCopperBridge / 2;
for( MODULE* module = aPcb->m_Modules; module; module = module->Next() )
{
for( D_PAD* pad = module->m_Pads; pad != NULL; pad = pad->Next() )
......@@ -61,17 +61,17 @@ void BuildUnconnectedThermalStubsPolygonList( std::vector<CPolyPt>& aCornerBuffe
continue;
item_boundingbox = pad->GetBoundingBox();
item_boundingbox.Inflate( aZone->m_ThermalReliefGapValue );
item_boundingbox.Inflate( aZone->m_ThermalReliefGap );
if( !( item_boundingbox.Intersects( zone_boundingbox ) ) )
continue;
// Thermal bridges are like a segment from a starting point inside the pad
// to an ending point outside the pad
wxPoint startpoint, endpoint;
endpoint.x = ( pad->m_Size.x / 2 ) + aZone->m_ThermalReliefGapValue;
endpoint.y = ( pad->m_Size.y / 2 ) + aZone->m_ThermalReliefGapValue;
endpoint.x = ( pad->m_Size.x / 2 ) + aZone->m_ThermalReliefGap;
endpoint.y = ( pad->m_Size.y / 2 ) + aZone->m_ThermalReliefGap;
int copperThickness = aZone->m_ThermalReliefCopperBridgeValue - aZone->m_ZoneMinThickness;
int copperThickness = aZone->m_ThermalReliefCopperBridge - aZone->m_ZoneMinThickness;
if( copperThickness < 0 )
copperThickness = 0;
......
......@@ -86,10 +86,10 @@ bool ZONE_CONTAINER::IsSame( const ZONE_CONTAINER& aZoneToCompare )
if( m_PadOption != aZoneToCompare.m_PadOption )
return false;
if( m_ThermalReliefGapValue != aZoneToCompare.m_ThermalReliefGapValue )
if( m_ThermalReliefGap != aZoneToCompare.m_ThermalReliefGap )
return false;
if( m_ThermalReliefCopperBridgeValue != aZoneToCompare.m_ThermalReliefCopperBridgeValue )
if( m_ThermalReliefCopperBridge != aZoneToCompare.m_ThermalReliefCopperBridge )
return false;
// Compare outlines
......
......@@ -97,8 +97,9 @@ public:
class CPolyPt
{
public:
CPolyPt( int qx = 0, int qy = 0, bool qf = false )
{ x = qx; y = qy; end_contour = qf; utility = 0; };
CPolyPt( int qx = 0, int qy = 0, bool qf = false, int aUtility = 0 )
{ x = qx; y = qy; end_contour = qf; utility = aUtility; };
int x;
int y;
bool end_contour;
......
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