Commit 4a7f92fb authored by jean-pierre charras's avatar jean-pierre charras

Minor code cleaning. Pcbnew: better iniatilization of members in DRAWSEGMENT,...

Minor code cleaning. Pcbnew: better iniatilization of members in DRAWSEGMENT, TRACK, EDGE_MOD (useful when using  python scripting).
parent b1ed22f7
......@@ -15,6 +15,7 @@
#include <wx/graphics.h>
static const bool FILLED = true;
static const bool NOT_FILLED = false;
/* Important Note:
* These drawing functions clip draw item before send these items to wxDC draw
......@@ -50,11 +51,8 @@ GR_DRAWMODE g_XorMode = GR_NXOR;
EDA_COLOR_T g_DrawBgColor = WHITE;
#define USE_CLIP_FILLED_POLYGONS
#ifdef USE_CLIP_FILLED_POLYGONS
static void ClipAndDrawFilledPoly( EDA_RECT * ClipBox, wxDC * DC, wxPoint Points[], int n );
#endif
static void ClipAndDrawPoly( EDA_RECT * ClipBox, wxDC * DC, wxPoint Points[],
int n );
/* These functions are used by corresponding functions
* ( GRSCircle is called by GRCircle for instance) after mapping coordinates
......@@ -857,14 +855,9 @@ static bool IsGRSPolyDrawable( EDA_RECT* ClipBox, int n, wxPoint Points[] )
/*
* Draw a new polyline and fill it if Fill, in screen space.
*/
static void GRSPoly( EDA_RECT* ClipBox,
wxDC* DC,
int n,
wxPoint Points[],
bool Fill,
int width,
EDA_COLOR_T Color,
EDA_COLOR_T BgColor )
static void GRSPoly( EDA_RECT* ClipBox, wxDC* DC, int n, wxPoint Points[],
bool Fill, int width,
EDA_COLOR_T Color, EDA_COLOR_T BgColor )
{
if( !IsGRSPolyDrawable( ClipBox, n, Points ) )
return;
......@@ -878,12 +871,9 @@ static void GRSPoly( EDA_RECT* ClipBox,
/* clip before send the filled polygon to wxDC, because under linux
* (GTK?) polygons having large coordinates are incorrectly drawn
* (integer overflow in coordinates, I am guessing)
*/
#ifdef USE_CLIP_FILLED_POLYGONS
ClipAndDrawFilledPoly( ClipBox, DC, Points, n );
#else
DC->DrawPolygon( n, Points ); // does not work very well under linux
#endif
ClipAndDrawPoly( ClipBox, DC, Points, n );
}
else
{
......@@ -903,47 +893,36 @@ static void GRSPoly( EDA_RECT* ClipBox,
/*
* Draw a new closed polyline and fill it if Fill, in screen space.
*/
static void GRSClosedPoly( EDA_RECT* ClipBox,
wxDC* DC,
int aPointCount,
wxPoint aPoints[],
bool Fill,
int width,
EDA_COLOR_T Color,
EDA_COLOR_T BgColor )
static void GRSClosedPoly( EDA_RECT* aClipBox, wxDC* aDC,
int aPointCount, wxPoint aPoints[],
bool aFill, int aWidth,
EDA_COLOR_T aColor,
EDA_COLOR_T aBgColor )
{
if( !IsGRSPolyDrawable( ClipBox, aPointCount, aPoints ) )
if( !IsGRSPolyDrawable( aClipBox, aPointCount, aPoints ) )
return;
GRSetColorPen( DC, Color, width );
GRSetColorPen( aDC, aColor, aWidth );
if( Fill && ( aPointCount > 2 ) )
if( aFill && ( aPointCount > 2 ) )
{
GRLastMoveToX = aPoints[aPointCount - 1].x;
GRLastMoveToY = aPoints[aPointCount - 1].y;
GRSetBrush( DC, BgColor, FILLED );
#ifdef USE_CLIP_FILLED_POLYGONS
ClipAndDrawFilledPoly( ClipBox, DC, aPoints, aPointCount );
#else
DC->DrawPolygon( aPointCount, aPoints ); // does not work very well under linux
#endif
GRSetBrush( aDC, aBgColor, FILLED );
ClipAndDrawPoly( aClipBox, aDC, aPoints, aPointCount );
}
else
{
GRSetBrush( DC, BgColor );
DC->DrawLines( aPointCount, aPoints );
GRSetBrush( aDC, aBgColor );
aDC->DrawLines( aPointCount, aPoints );
int lastpt = aPointCount - 1;
/* Close the polygon. */
if( aPoints[aPointCount - 1] != aPoints[0] )
if( aPoints[lastpt] != aPoints[0] )
{
GRLine( ClipBox,
DC,
aPoints[0].x,
aPoints[0].y,
aPoints[aPointCount - 1].x,
aPoints[aPointCount - 1].y,
width,
Color );
GRLine( aClipBox, aDC, aPoints[0].x, aPoints[0].y,
aPoints[lastpt].x, aPoints[lastpt].y,
aWidth, aColor );
}
}
}
......@@ -1322,30 +1301,20 @@ void GRFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
void GRSRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2,
int aWidth, EDA_COLOR_T aColor, wxPenStyle aStyle )
{
wxPoint points[5];
points[0] = wxPoint(x1, y1);
points[1] = wxPoint(x1, y2);
points[2] = wxPoint(x2, y2);
points[3] = wxPoint(x2, y1);
points[4] = points[0];
GRSetColorPen( aDC, aColor, aWidth, aStyle );
GRSetBrush( aDC, BLACK );
if( aClipBox )
{
EDA_RECT clipbox(*aClipBox);
clipbox.Inflate(aWidth);
ClipAndDrawFilledPoly(&clipbox, aDC, points, 5); // polygon approach is more accurate
}
else
ClipAndDrawFilledPoly(aClipBox, aDC, points, 5);
GRSClosedPoly( aClipBox, aDC, 5, points, NOT_FILLED, aWidth,
aColor, aColor );
}
void GRSFilledRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2,
int aWidth, EDA_COLOR_T aColor, EDA_COLOR_T aBgColor )
{
wxPoint points[5];
points[0] = wxPoint(x1, y1);
points[1] = wxPoint(x1, y2);
......@@ -1354,21 +1323,19 @@ void GRSFilledRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y
points[4] = points[0];
GRSetBrush( aDC, aBgColor, FILLED );
GRSetColorPen( aDC, aBgColor, aWidth );
if( aClipBox && (aWidth > 0) )
{
EDA_RECT clipbox(*aClipBox);
clipbox.Inflate(aWidth);
ClipAndDrawFilledPoly(&clipbox, aDC, points, 5); // polygon approach is more accurate
ClipAndDrawPoly(&clipbox, aDC, points, 5); // polygon approach is more accurate
}
else
ClipAndDrawFilledPoly(aClipBox, aDC, points, 5);
ClipAndDrawPoly(aClipBox, aDC, points, 5 );
}
#ifdef USE_CLIP_FILLED_POLYGONS
/**
* Function ClipAndDrawFilledPoly
* Function ClipAndDrawPoly
* Used to clip a polygon and draw it as Filled Polygon
* uses the Sutherland and Hodgman algo to clip the given poly against a
* rectangle. This rectangle is the drawing area this is useful under
......@@ -1382,7 +1349,7 @@ void GRSFilledRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y
*/
#include <SutherlandHodgmanClipPoly.h>
void ClipAndDrawFilledPoly( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPoints[], int n )
void ClipAndDrawPoly( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPoints[], int n )
{
if( aClipBox == NULL )
{
......@@ -1417,9 +1384,6 @@ void ClipAndDrawFilledPoly( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPoints[], in
}
#endif
void GRBezier( EDA_RECT* ClipBox,
wxDC* DC,
int x1,
......
......@@ -56,9 +56,11 @@
DRAWSEGMENT::DRAWSEGMENT( BOARD_ITEM* aParent, KICAD_T idtype ) :
BOARD_ITEM( aParent, idtype )
{
m_Width = m_Type = m_Angle = 0;
m_Type = 0;
m_Angle = 0;
m_Flags = 0;
m_Shape = S_SEGMENT;
m_Width = Millimeter2iu( 0.15 ); // Gives a decent width
}
......
......@@ -57,7 +57,7 @@ EDGE_MODULE::EDGE_MODULE( MODULE* parent, STROKE_T aShape ) :
{
m_Shape = aShape;
m_Angle = 0;
m_Width = 120;
m_Layer = SILKSCREEN_N_FRONT;
}
......
......@@ -50,7 +50,9 @@ PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent ) :
BOARD_ITEM( aParent, PCB_TARGET_T )
{
m_Shape = 0;
m_Size = 5000;
m_Size = Millimeter2iu( 5 ); // Gives a decent size
m_Width = Millimeter2iu( 0.15 ); // Gives a decent width
m_Layer = EDGE_N; // a target is on all layers
}
PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent, int aShape, LAYER_NUM aLayer,
......
......@@ -124,7 +124,7 @@ TRACK* GetTrace( TRACK* aStartTrace, TRACK* aEndTrace, const wxPoint& aPosition,
TRACK::TRACK( BOARD_ITEM* aParent, KICAD_T idtype ) :
BOARD_CONNECTED_ITEM( aParent, idtype )
{
m_Width = 0;
m_Width = Millimeter2iu( 0.2 );
m_Shape = S_SEGMENT;
start = end = NULL;
SetDrillDefault();
......@@ -187,6 +187,7 @@ SEGVIA::SEGVIA( BOARD_ITEM* aParent ) :
TRACK( aParent, PCB_VIA_T )
{
SetShape( VIA_THROUGH );
m_Width = Millimeter2iu( 0.5 );
}
......
#!/usr/bin/python
# This python script wizard creates a FPC connector
# for Surface Mounted Technology
from pcbnew import *
......@@ -6,7 +8,7 @@ class FPCFootprintWizard(FootprintWizardPlugin):
def __init__(self):
FootprintWizardPlugin.__init__(self)
self.name = "FPC"
self.description = "FPC Footprint Wizard"
self.description = "FPC (SMTechnology) Footprint Wizard"
self.parameters = {
"Pads":
{"*n":40, # not internal units preceded by "*"
......@@ -17,9 +19,9 @@ class FPCFootprintWizard(FootprintWizardPlugin):
{"shield_to_pad": FromMM(1.6),
"from_top": FromMM(1.3),
"width": FromMM(1.5),
"height": FromMM(2)},
"height": FromMM(2)}
}
self.ClearErrors()
# build a rectangular pad
......@@ -75,48 +77,61 @@ class FPCFootprintWizard(FootprintWizardPlugin):
shl_to_pad = p["Shield"]["shield_to_pad"]
shl_from_top = p["Shield"]["from_top"]
offsetX = pad_pitch*(pads-1)/2
size_pad = wxSize(pad_width,pad_height)
size_shld = wxSize(shl_width,shl_height)
size_text = wxSize( FromMM( 0.8), FromMM( 0.7) )
textposy = pad_height/2 + FromMM(1)
module.SetReference("FPC"+str(pads)) # give it a reference name
module.Reference().SetPos0(wxPointMM(-1,-2))
module.Reference().SetPosition(wxPointMM(-1,-2))
module.Reference().SetPos0(wxPoint(0, textposy))
module.Reference().SetTextPosition(module.Reference().GetPos0())
module.Reference().SetSize( size_text )
textposy = textposy + FromMM(1)
module.SetValue("Val***") # give it a default value
module.Value().SetPos0( wxPoint(0, textposy) )
module.Value().SetTextPosition(module.Value().GetPos0())
module.Value().SetSize( size_text )
module.SetLibRef("FPC"+str(pads)) #the name in library
# create a pad array and add it to the module
for n in range (0,pads):
pad = self.smdRectPad(module,size_pad,wxPoint(pad_pitch*n,0),str(n+1))
xpos = pad_pitch*n - offsetX
pad = self.smdRectPad(module,size_pad,wxPoint(xpos,0),str(n+1))
module.Add(pad)
pad_s0 = self.smdRectPad(module,
size_shld,
wxPoint(-shl_to_pad,shl_from_top),
"0")
pad_s1 = self.smdRectPad(module,
size_shld,
wxPoint((pads-1)*pad_pitch+shl_to_pad,shl_from_top),
"0")
xpos = -shl_to_pad-offsetX
pad_s0 = self.smdRectPad(module, size_shld, wxPoint(xpos,shl_from_top), "0")
xpos = (pads-1)*pad_pitch+shl_to_pad-offsetX
pad_s1 = self.smdRectPad(module, size_shld, wxPoint(xpos,shl_from_top), "0")
module.Add(pad_s0)
module.Add(pad_s1)
e = EDGE_MODULE(module)
e.SetStartEnd(wxPointMM(-1,0),wxPointMM(0,0))
e.SetWidth(FromMM(0.2))
e.SetLayer(EDGE_LAYER)
e.SetShape(S_SEGMENT)
module.Add(e)
module.SetLibRef("FPC"+str(pads))
def register():
# create our footprint wizard
fpc_wizard = FPCFootprintWizard()
# register it into pcbnew
fpc_wizard.register()
return fpc_wizard
#add outline
outline = EDGE_MODULE(module)
width = FromMM(0.2)
posy = -pad_height/2 - width/2 -FromMM(0.2)
outline.SetStartEnd(wxPoint(pad_pitch * pads - pad_pitch*0.5-offsetX, posy),
wxPoint( - pad_pitch*0.5-offsetX, posy))
outline.SetWidth(width)
outline.SetLayer(SILKSCREEN_N_FRONT) #default: not needed
outline.SetShape(S_SEGMENT)
module.Add(outline)
outline1 = EDGE_MODULE(module)
outline1.Copy(outline) #copy all settings from outline
posy = pad_height/2 + width/2 +FromMM(0.2)
outline1.SetStartEnd(wxPoint(pad_pitch * pads - pad_pitch*0.5-offsetX, posy),
wxPoint( - pad_pitch*0.5-offsetX, posy))
module.Add(outline1)
# create our footprint wizard
fpc_wizard = FPCFootprintWizard()
# register it into pcbnew
fpc_wizard.register()
......@@ -164,12 +164,18 @@ class TouchSliderWizard(FootprintWizardPlugin):
step_length = float(touch_length) / float(steps)
size_text = wxSize( FromMM( 1), FromMM( 1) );
module.SetReference("TS"+str(steps)) # give it a reference name
module.Reference().SetPos0(wxPointMM(-1,-2))
module.Reference().SetPosition(wxPointMM(-1,-2))
module.Reference().SetPos0(wxPointMM(0,-2))
module.Reference().SetTextPosition(module.Reference().GetPos0())
module.Reference().SetSize( size_text );
# starting pad
module.SetValue("Val**") # give it a value
module.Value().SetPos0(wxPointMM(0,-3.2))
module.Value().SetTextPosition(module.Value().GetPos0())
module.Value().SetSize( size_text );
# starting pad
pos = wxPointMM(0,0)
band_width = touch_width/bands
......
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