Commit 744dd80e authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Minor fixes. Minor code cleaning. Pcbnew: better iniatilization of members in...

Minor fixes. Minor code cleaning. Pcbnew: better iniatilization of members in DRAWSEGMENT, TRACK, EDGE_MOD (not bugs: just useful when using python scripting).
parents b1ed22f7 4a7f92fb
Loading
Loading
Loading
Loading
+34 −70
Original line number Diff line number Diff line
@@ -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,
+23 −14
Original line number Diff line number Diff line
@@ -472,23 +472,32 @@ void WORKSHEET_DATAITEM_TEXT::SetConstrainedTextSize()
    if( m_ConstrainedTextSize.y == 0 )
        m_ConstrainedTextSize.y = m_DefaultTextSize.y;

    if( m_BoundingBoxSize.x )
    if( m_BoundingBoxSize.x || m_BoundingBoxSize.y )
    {
        int linewidth = 0;
        // to know the X size of the line, we should use
        // ReturnGraphicTextWidth
        // to know the X and Y size of the line, we should use
        // EDA_TEXT::GetTextBox()
        // but this function uses integers
        // So, to avoid truncations with our unit in mm, use microns.
        int sizex_micron = KiROUND( m_ConstrainedTextSize.x * 1000.0 );
        double lenMsg = ReturnGraphicTextWidth( m_FullText, sizex_micron,
                                             IsItalic(), linewidth ) / 1000.0;
        if( lenMsg > m_BoundingBoxSize.x )
            m_ConstrainedTextSize.x *= m_BoundingBoxSize.x / lenMsg;
    }

    if( m_BoundingBoxSize.y )
    {
        if( m_ConstrainedTextSize.y > m_BoundingBoxSize.y )
            m_ConstrainedTextSize.y = m_BoundingBoxSize.y;
        wxSize size_micron;
        size_micron.x = KiROUND( m_ConstrainedTextSize.x * 1000.0 );
        size_micron.y = KiROUND( m_ConstrainedTextSize.y * 1000.0 );
        WS_DRAW_ITEM_TEXT dummy( WS_DRAW_ITEM_TEXT( this, this->m_FullText,
                                               wxPoint(0,0),
                                               size_micron,
                                               linewidth, BLACK,
                                               IsItalic(), IsBold() ) );
        dummy.SetMultilineAllowed( true );
        TransfertSetupToGraphicText( &dummy );
        EDA_RECT rect = dummy.GetTextBox();
        DSIZE size;
        size.x = rect.GetWidth() / 1000.0;
        size.y = rect.GetHeight() / 1000.0;

        if( m_BoundingBoxSize.x && size.x > m_BoundingBoxSize.x )
            m_ConstrainedTextSize.x *= m_BoundingBoxSize.x / size.x;

        if( m_BoundingBoxSize.y &&  size.y > m_BoundingBoxSize.y )
            m_ConstrainedTextSize.y *= m_BoundingBoxSize.y / size.y;
    }
}
+7 −1
Original line number Diff line number Diff line
@@ -75,7 +75,13 @@ void DIALOG_NEW_DATAITEM::OnCancelClick( wxCommandEvent& event )
void DIALOG_NEW_DATAITEM::OnOKClick( wxCommandEvent& event )
{
    if( m_item->GetType() == WORKSHEET_DATAITEM::WS_TEXT )
        ((WORKSHEET_DATAITEM_TEXT*)m_item)->m_TextBase = m_textCtrlText->GetValue();
    {
        WORKSHEET_DATAITEM_TEXT* text = ((WORKSHEET_DATAITEM_TEXT*)m_item);
        text->m_TextBase = m_textCtrlText->GetValue();
        // For multiline texts, replace the '\n' char by the "\\n" sequence",
        // in internal string
        text->m_TextBase.Replace( wxT("\n"), wxT("\\n") );
    }

    wxString msg;

+8 −6
Original line number Diff line number Diff line
@@ -110,18 +110,20 @@ DIALOG_NEW_DATAITEM_BASE::DIALOG_NEW_DATAITEM_BASE( wxWindow* parent, wxWindowID
	
	m_SizerText = new wxBoxSizer( wxVERTICAL );
	
	m_staticText10 = new wxStaticText( this, wxID_ANY, _("Text"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText10->Wrap( -1 );
	m_SizerText->Add( m_staticText10, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
	m_staticTextTitle = new wxStaticText( this, wxID_ANY, _("Text"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticTextTitle->Wrap( -1 );
	m_SizerText->Add( m_staticTextTitle, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
	
	m_textCtrlText = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
	m_SizerText->Add( m_textCtrlText, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
	m_textCtrlText = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
	m_textCtrlText->SetMinSize( wxSize( 300,-1 ) );
	
	m_SizerText->Add( m_textCtrlText, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
	
	m_staticline3 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
	m_SizerText->Add( m_staticline3, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
	
	
	bSizerUpper->Add( m_SizerText, 0, wxEXPAND, 5 );
	bSizerUpper->Add( m_SizerText, 1, wxEXPAND, 5 );
	
	
	bSizerMain->Add( bSizerUpper, 1, wxEXPAND, 5 );
+6 −6
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@
            <property name="minimum_size"></property>
            <property name="name">DIALOG_NEW_DATAITEM_BASE</property>
            <property name="pos"></property>
            <property name="size">328,290</property>
            <property name="size">328,335</property>
            <property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
            <property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
            <property name="title">New Item</property>
@@ -1369,7 +1369,7 @@
                        <object class="sizeritem" expanded="1">
                            <property name="border">5</property>
                            <property name="flag">wxEXPAND</property>
                            <property name="proportion">0</property>
                            <property name="proportion">1</property>
                            <object class="wxBoxSizer" expanded="1">
                                <property name="minimum_size"></property>
                                <property name="name">m_SizerText</property>
@@ -1415,7 +1415,7 @@
                                        <property name="minimize_button">0</property>
                                        <property name="minimum_size"></property>
                                        <property name="moveable">1</property>
                                        <property name="name">m_staticText10</property>
                                        <property name="name">m_staticTextTitle</property>
                                        <property name="pane_border">1</property>
                                        <property name="pane_position"></property>
                                        <property name="pane_size"></property>
@@ -1461,7 +1461,7 @@
                                <object class="sizeritem" expanded="1">
                                    <property name="border">5</property>
                                    <property name="flag">wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT</property>
                                    <property name="proportion">0</property>
                                    <property name="proportion">1</property>
                                    <object class="wxTextCtrl" expanded="1">
                                        <property name="BottomDockable">1</property>
                                        <property name="LeftDockable">1</property>
@@ -1496,7 +1496,7 @@
                                        <property name="maxlength"></property>
                                        <property name="min_size"></property>
                                        <property name="minimize_button">0</property>
                                        <property name="minimum_size"></property>
                                        <property name="minimum_size">300,-1</property>
                                        <property name="moveable">1</property>
                                        <property name="name">m_textCtrlText</property>
                                        <property name="pane_border">1</property>
@@ -1508,7 +1508,7 @@
                                        <property name="resize">Resizable</property>
                                        <property name="show">1</property>
                                        <property name="size"></property>
                                        <property name="style"></property>
                                        <property name="style">wxTE_MULTILINE</property>
                                        <property name="subclass"></property>
                                        <property name="toolbar_pane">0</property>
                                        <property name="tooltip"></property>
Loading