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 Original line 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
Please add newer entries at the top, list the date and your name with
email address.
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>
2008-Dec-28 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
================================================================================
+1 −1
Original line number Original line Diff line number Diff line
@@ -269,7 +269,7 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel, wxDC* DC,
                                     *(coordptr + 2), *(coordptr + 3), aWidth, aColor );
                                     *(coordptr + 2), *(coordptr + 3), aWidth, aColor );
                    }
                    }
                    else
                    else
                        GRPoly( &aPanel->m_ClipBox, DC, ii / 2, coord, 0,
                        GRPoly( &aPanel->m_ClipBox, DC, ii / 2, (wxPoint*)coord, 0,
                                aWidth, aColor, aColor );
                                aWidth, aColor, aColor );
                }
                }
                plume = f_cod; ii = 0;
                plume = f_cod; ii = 0;
+43 −54
Original line number Original line 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;
    int Xmin, Xmax, Ymin, Ymax;


    Xmin = Xmax = Points[0];
    Xmin = Xmax = Points[0].x;
    Ymin = Ymax = Points[1];
    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[ii].x );
        Xmin = MIN( Xmin, Points[jj] );
        Xmax = MAX( Xmax, Points[ii].x );
        Xmax = MAX( Xmax, Points[jj] );
        Ymin = MIN( Ymin, Points[ii].y );
        Ymin = MIN( Ymin, Points[jj + 1] );
        Ymax = MAX( Ymax, Points[ii].y );
        Ymax = MAX( Ymax, Points[jj + 1] );
    }
    }


    xcliplo = ClipBox->GetX();
    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. */
/* 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 )
              int width, int Color, int BgColor )
{
{
    if( !IsGRSPolyDrawable( ClipBox, n, Points ) )
    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 ) )
    if( Fill && ( n > 2 ) )
    {
    {
        GRSetBrush( DC, BgColor, FILLED );
        GRSetBrush( DC, BgColor, FILLED );
        DC->DrawPolygon( n, (wxPoint*) Points );
        DC->DrawPolygon( n, Points );
    }
    }
    else
    else
    {
    {
        int endx = Points[n * 2 - 2];
        wxPoint endPt = Points[n-1];
        int endy = Points[n * 2 - 1];


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

        // The last point is not drawn by DrawLine and DrawLines
        // The last point is not drawn by DrawLine and DrawLines
        // Add it if the polygon is not closed
        // Add it if the polygon is not closed
        if ( endx != Points[0] || endy != Points[1] )
        if( endPt != Points[0] )
            DC->DrawPoint(endx, endy);
            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 */
/* 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,
static void GRSClosedPoly( EDA_Rect* ClipBox, wxDC* DC, int aPointCount, wxPoint aPoints[],
                    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,
                    bool Fill, int width, int Color, int BgColor )
                    bool Fill, int width, int Color, int BgColor )
{
{
    int startx, starty;
    if( !IsGRSPolyDrawable( ClipBox, aPointCount, aPoints ) )

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


    GRSetColorPen( DC, Color, width );
    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 );
        GRSetBrush( DC, BgColor, FILLED );
        DC->DrawPolygon( n, (wxPoint*) Points, 0, 0, wxODDEVEN_RULE );
        DC->DrawPolygon( aPointCount, aPoints, 0, 0, wxODDEVEN_RULE );
    }
    }
    else
    else
    {
    {
        startx = Points[n * 2 - 2]; starty = Points[n * 2 - 1];
        GRSetBrush( DC, BgColor );
        GRSetBrush( DC, BgColor );
        DC->DrawLines( n, (wxPoint*) Points );
        DC->DrawLines( aPointCount, aPoints );


        /* Fermeture du polygone */
        /* 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. */
/* 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 )
             bool Fill, int width, int Color, int BgColor )
{
{
    int ii, jj;
    for( int i=0; i<n; ++i )

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


    width = ZoomValue( width );
    GRSPoly( ClipBox, DC, n, Points, Fill, width, Color, BgColor );
    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 */
/* 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 )
                   bool Fill, int Color, int BgColor )
{
{
    GRClosedPoly( ClipBox, DC, n, Points, Fill, 0, Color, 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 )
                   bool Fill, int width, int Color, int BgColor )
{
{
    int ii, jj;
    for( int i=0; i<n; ++i )

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


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


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


/*******************************************************************/
/*******************************************************************/
Hierarchical_PIN_Sheet_Struct::Hierarchical_PIN_Sheet_Struct( DrawSheetStruct* parent,
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 ),
    SCH_ITEM( parent, DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ),
    EDA_TextStruct( text )
    EDA_TextStruct( text )
/*******************************************************************/
/*******************************************************************/
@@ -76,7 +77,11 @@ void Hierarchical_PIN_Sheet_Struct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, con
    EDA_Colors             txtcolor;
    EDA_Colors             txtcolor;
    int    posx, tposx, posy, size2;
    int    posx, tposx, posy, size2;
    wxSize size;
    wxSize size;
    int    NbSegm, coord[20];
    int    NbSegm;

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

    int    LineWidth = g_DrawMinimunLineWidth;
    int    LineWidth = g_DrawMinimunLineWidth;


    if( Color >= 0 )
    if( Color >= 0 )
@@ -85,7 +90,10 @@ void Hierarchical_PIN_Sheet_Struct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, con
        txtcolor = ReturnLayerColor( m_Layer );
        txtcolor = ReturnLayerColor( m_Layer );
    GRSetDrawMode( DC, DrawMode );
    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_Text.IsEmpty() )
    {
    {
        if( m_Edge )
        if( m_Edge )
@@ -110,7 +118,10 @@ void Hierarchical_PIN_Sheet_Struct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, con
        size.y = -size.y;
        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;
    NbSegm = 0;


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


    int FillShape = FALSE;
    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;
    return true;
}
}



#if defined(DEBUG)
#if defined(DEBUG)
void Hierarchical_PIN_Sheet_Struct::Show( int nestLevel, std::ostream& os )
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;
                                 << std::flush;


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

}
}



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


    CreateGraphicShape( Poly, AnchorPos );
    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 )
    if( m_IsDangling )
        DrawDanglingSymbol( panel, DC, m_Pos + offset, color );
        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 corner_list = coordinates list fill with polygon corners ooordinates (size > 20)
 * @param Pos = Postion of the shape
 * @param Pos = Postion of the shape
 * format list is
 * format list is
@@ -414,13 +415,14 @@ void SCH_HIERLABEL::CreateGraphicShape( int* corner_list, const wxPoint& Pos )


    int  imax = *Template; Template++;
    int  imax = *Template; Template++;


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

        corner_list++; 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 );
    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 )
    if( m_IsDangling )
        DrawDanglingSymbol( panel, DC, AnchorPos, color );
        DrawDanglingSymbol( panel, DC, AnchorPos, color );
Loading