Commit 0d790e57 authored by dickelbeck's avatar dickelbeck
Browse files

polygon work, EDGE_MODULE::m_PolyPoints is now std::vector

parent fadacffc
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -5,6 +5,17 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with
email address.

2008-Dec-29 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
++all
  * gr_basic.h DOXYGEN comments.  made a couple functions static and removed
    those from gr_basic.h since they are private to gr_basic.c.  changed the
    polygon code to use wxPoints since that is what the underlying wxWidgets
    API uses.
++gerbview
    More work on drawing polygons, erasure still work in progress.  Will
    probably switch to ZONEs from SEG_ZONEs for polygons.


2008-Dec-28 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
+1 −1
Original line number Diff line number Diff line
@@ -269,7 +269,7 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel, wxDC* DC,
                                     *(coordptr + 2), *(coordptr + 3), aWidth, aColor );
                    }
                    else
                        GRPoly( &aPanel->m_ClipBox, DC, ii / 2, coord, 0,
                        GRPoly( &aPanel->m_ClipBox, DC, ii / 2, (wxPoint*)coord, 0,
                                aWidth, aColor, aColor );
                }
                plume = f_cod; ii = 0;
+43 −54
Original line number Diff line number Diff line
@@ -828,21 +828,19 @@ void GRSCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int
}


static bool IsGRSPolyDrawable( EDA_Rect* ClipBox, int n, int* Points )
static bool IsGRSPolyDrawable( EDA_Rect* ClipBox, int n, wxPoint Points[] )
{
    int ii;
    int Xmin, Xmax, Ymin, Ymax;

    Xmin = Xmax = Points[0];
    Ymin = Ymax = Points[1];
    Xmin = Xmax = Points[0].x;
    Ymin = Ymax = Points[0].y;

    for( ii = 1; ii < n; ii++ )     // calcul du rectangle d'encadrement
    for( int ii = 1; ii < n; ii++ )     // calcul du rectangle d'encadrement
    {
        int jj = ii * 2;
        Xmin = MIN( Xmin, Points[jj] );
        Xmax = MAX( Xmax, Points[jj] );
        Ymin = MIN( Ymin, Points[jj + 1] );
        Ymax = MAX( Ymax, Points[jj + 1] );
        Xmin = MIN( Xmin, Points[ii].x );
        Xmax = MAX( Xmax, Points[ii].x );
        Ymin = MIN( Ymin, Points[ii].y );
        Ymax = MAX( Ymax, Points[ii].y );
    }

    xcliplo = ClipBox->GetX();
@@ -866,7 +864,7 @@ static bool IsGRSPolyDrawable( EDA_Rect* ClipBox, int n, int* Points )
/************************************************************************/
/* Routine to draw a new polyline and fill it if Fill, in screen space. */
/************************************************************************/
void GRSPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points, bool Fill,
static void GRSPoly( EDA_Rect* ClipBox, wxDC* DC, int n, wxPoint Points[], bool Fill,
              int width, int Color, int BgColor )
{
    if( !IsGRSPolyDrawable( ClipBox, n, Points ) )
@@ -877,19 +875,19 @@ void GRSPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points, bool Fill,
    if( Fill && ( n > 2 ) )
    {
        GRSetBrush( DC, BgColor, FILLED );
        DC->DrawPolygon( n, (wxPoint*) Points );
        DC->DrawPolygon( n, Points );
    }
    else
    {
        int endx = Points[n * 2 - 2];
        int endy = Points[n * 2 - 1];
        wxPoint endPt = Points[n-1];

        GRSetBrush( DC, Color );
        DC->DrawLines( n, (wxPoint*) Points );
        DC->DrawLines( n, Points );

        // The last point is not drawn by DrawLine and DrawLines
        // Add it if the polygon is not closed
        if ( endx != Points[0] || endy != Points[1] )
            DC->DrawPoint(endx, endy);
        if( endPt != Points[0] )
            DC->DrawPoint(endPt.x, endPt.y);
    }
}

@@ -897,61 +895,56 @@ void GRSPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points, bool Fill,
/******************************************************************************/
/* Routine to draw a new closed polyline and fill it if Fill, in screen space */
/******************************************************************************/
void GRSClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points,
                    bool Fill, int Color, int BgColor )
{
    GRSClosedPoly( ClipBox, DC, n, Points, Fill, 0, Color, BgColor );
}


void GRSClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points,
static void GRSClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int aPointCount, wxPoint aPoints[],
                    bool Fill, int width, int Color, int BgColor )
{
    int startx, starty;

    if( !IsGRSPolyDrawable( ClipBox, n, Points ) )
    if( !IsGRSPolyDrawable( ClipBox, aPointCount, aPoints ) )
        return;

    GRSetColorPen( DC, Color, width );

    if( Fill && ( n > 2 ) )
    if( Fill && ( aPointCount > 2 ) )
    {
        GRSMoveTo( Points[n * 2 - 2], Points[n * 2 - 1] );
        GRSMoveTo( aPoints[aPointCount-1].x, aPoints[aPointCount-1].y );
        GRSetBrush( DC, BgColor, FILLED );
        DC->DrawPolygon( n, (wxPoint*) Points, 0, 0, wxODDEVEN_RULE );
        DC->DrawPolygon( aPointCount, aPoints, 0, 0, wxODDEVEN_RULE );
    }
    else
    {
        startx = Points[n * 2 - 2]; starty = Points[n * 2 - 1];
        GRSetBrush( DC, BgColor );
        DC->DrawLines( n, (wxPoint*) Points );
        DC->DrawLines( aPointCount, aPoints );

        /* Fermeture du polygone */
        if( (startx != Points[0]) || (starty != Points[1]) )
        if( aPoints[aPointCount-1] != aPoints[0] )
        {
            GRSLine( ClipBox, DC, Points[0], Points[1], startx, starty, width, Color );
            GRSLine( ClipBox, DC, aPoints[0].x, aPoints[0].y,
                aPoints[aPointCount-1].x, aPoints[aPointCount-1].y, width, Color );
        }
    }
}

/* not used
static void GRSClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int n, wxPoint Points[],
                    bool Fill, int Color, int BgColor )
{
    GRSClosedPoly( ClipBox, DC, n, Points, Fill, 0, Color, BgColor );
}
*/


/************************************************************************/
/* Routine to draw a new polyline and fill it if Fill, in drawing space. */
/************************************************************************/
void GRPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points,
void GRPoly( EDA_Rect* ClipBox, wxDC* DC, int n, wxPoint Points[],
             bool Fill, int width, int Color, int BgColor )
{
    int ii, jj;

    width = ZoomValue( width );
    for( ii = 0; ii < n; ii++ )
    for( int i=0; i<n; ++i )
    {
        jj = ii << 1;
        Points[jj] = GRMapX( Points[jj] );
        jj++;
        Points[jj] = GRMapY( Points[jj] );
        Points[i].x = GRMapX( Points[i].x );
        Points[i].y = GRMapY( Points[i].y );
    }

    width = ZoomValue( width );
    GRSPoly( ClipBox, DC, n, Points, Fill, width, Color, BgColor );
}

@@ -959,27 +952,23 @@ void GRPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points,
/**************************************************************************/
/* Routine to draw a closed polyline and fill it if Fill, in object space */
/**************************************************************************/
void GRClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points,
void GRClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int n, wxPoint Points[],
                   bool Fill, int Color, int BgColor )
{
    GRClosedPoly( ClipBox, DC, n, Points, Fill, 0, Color, BgColor );
}


void GRClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points,
void GRClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int n, wxPoint Points[],
                   bool Fill, int width, int Color, int BgColor )
{
    int ii, jj;

    width = ZoomValue( width );
    for( ii = 0; ii < n; ii++ )
    for( int i=0; i<n; ++i )
    {
        jj = ii << 1;
        Points[jj] = GRMapX( Points[jj] );
        jj++;
        Points[jj] = GRMapY( Points[jj] );
        Points[i].x = GRMapX( Points[i].x );
        Points[i].y = GRMapY( Points[i].y );
    }

    width = ZoomValue( width );
    GRSClosedPoly( ClipBox, DC, n, Points, Fill, width, Color, BgColor );
}

+39 −26
Original line number Diff line number Diff line
@@ -35,7 +35,8 @@

/*******************************************************************/
Hierarchical_PIN_Sheet_Struct::Hierarchical_PIN_Sheet_Struct( DrawSheetStruct* parent,
                                            const wxPoint& pos, const wxString& text ) :
                                                              const wxPoint&   pos,
                                                              const wxString&  text ) :
    SCH_ITEM( parent, DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ),
    EDA_TextStruct( text )
/*******************************************************************/
@@ -76,7 +77,11 @@ void Hierarchical_PIN_Sheet_Struct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, con
    EDA_Colors             txtcolor;
    int    posx, tposx, posy, size2;
    wxSize size;
    int    NbSegm, coord[20];
    int    NbSegm;

    // @todo use wxPoints here
    int    coord[20];

    int    LineWidth = g_DrawMinimunLineWidth;

    if( Color >= 0 )
@@ -85,7 +90,10 @@ void Hierarchical_PIN_Sheet_Struct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, con
        txtcolor = ReturnLayerColor( m_Layer );
    GRSetDrawMode( DC, DrawMode );

    posx = m_Pos.x + offset.x; posy = m_Pos.y + offset.y; size = m_Size;
    posx = m_Pos.x + offset.x;
    posy = m_Pos.y + offset.y;
    size = m_Size;

    if( !m_Text.IsEmpty() )
    {
        if( m_Edge )
@@ -110,7 +118,10 @@ void Hierarchical_PIN_Sheet_Struct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, con
        size.y = -size.y;
    }

    coord[0] = posx; coord[1] = posy; size2 = size.x / 2;
    coord[0] = posx;
    coord[1] = posy;

    size2  = size.x / 2;
    NbSegm = 0;

    switch( m_Shape )
@@ -154,7 +165,8 @@ void Hierarchical_PIN_Sheet_Struct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, con
    }

    int FillShape = FALSE;
    GRPoly( &panel->m_ClipBox, DC, NbSegm, coord, FillShape, LineWidth, txtcolor, txtcolor ); /* Poly Non rempli */
    GRPoly( &panel->m_ClipBox, DC, NbSegm, (wxPoint*) coord,
            FillShape, LineWidth, txtcolor, txtcolor );     /* Poly Non rempli */
}


@@ -202,6 +214,7 @@ bool Hierarchical_PIN_Sheet_Struct::Save( FILE* aFile ) const
    return true;
}


#if defined(DEBUG)
void Hierarchical_PIN_Sheet_Struct::Show( int nestLevel, std::ostream& os )
{
@@ -214,7 +227,7 @@ void Hierarchical_PIN_Sheet_Struct::Show( int nestLevel, std::ostream& os )
                                 << std::flush;

//    NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n";

}


#endif
+11 −9
Original line number Diff line number Diff line
@@ -393,15 +393,16 @@ void SCH_HIERLABEL::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offs
    }

    CreateGraphicShape( Poly, AnchorPos );
    GRPoly( &panel->m_ClipBox, DC, Poly[0], Poly + 1, 0, width, color, color );
    GRPoly( &panel->m_ClipBox, DC, Poly[0], (wxPoint*)(Poly + 1), 0, width, color, color );

    if( m_IsDangling )
        DrawDanglingSymbol( panel, DC, m_Pos + offset, color );
}


/** function CreateGraphicShape
 * Calculates the graphic shape (a polygon) associated to the text
/**
 * Function CreateGraphicShape
 * calculates the graphic shape (a polygon) associated to the text
 * @param corner_list = coordinates list fill with polygon corners ooordinates (size > 20)
 * @param Pos = Postion of the shape
 * format list is
@@ -414,13 +415,14 @@ void SCH_HIERLABEL::CreateGraphicShape( int* corner_list, const wxPoint& Pos )

    int  imax = *Template; Template++;

    *corner_list = imax; corner_list++;
    *corner_list++ = imax;
    for( int ii = 0; ii < imax; ii++ )
    {
        *corner_list = ( HalfSize * (*Template) ) + Pos.x;
        corner_list++; Template++;
        *corner_list = ( HalfSize * (*Template) ) + Pos.y;
        corner_list++; Template++;
        *corner_list++ = ( HalfSize * (*Template) ) + Pos.x;
        Template++;

        *corner_list++ = ( HalfSize * (*Template) ) + Pos.y;
        Template++;
    }
}

@@ -546,7 +548,7 @@ void SCH_GLOBALLABEL::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& dr
    }

    CreateGraphicShape( Poly, AnchorPos );
    GRPoly( &panel->m_ClipBox, DC, Poly[0], Poly + 1, 0, width, color, color );
    GRPoly( &panel->m_ClipBox, DC, Poly[0], (wxPoint*) (Poly + 1), 0, width, color, color );

    if( m_IsDangling )
        DrawDanglingSymbol( panel, DC, AnchorPos, color );
Loading