Commit f2c03f2b authored by charras's avatar charras
Browse files

gr_basic.cpp now clips filled polygons,using the Sutherland and Hodgman algo...

gr_basic.cpp now clips filled polygons,using the Sutherland and Hodgman algo to clip the poly against a rectangle
Filled polygons are now correctly displayed under Linux(i hope)
parent e1fb4c78
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -5,6 +5,18 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with
email address.

2009-Feb-17 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
++gr_basic.cpp
    Added: Function ClipAndDrawFilledPoly()
        Used to clip a polygon and display 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 Linux (2009) because filled polygons are incorrectly drawn
        if they have too large coordinates (seems due to integer overflows in calculations)
        Could be removed in some years, if become unnecesary.


2009-Feb-17 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
++pcbnew
+84 −27
Original line number Diff line number Diff line
@@ -31,6 +31,12 @@
 * and remember users can have old versions with bugs
 */

#define USE_CLIP_FILLED_POLYGONS

#ifdef USE_CLIP_FILLED_POLYGONS
void ClipAndDrawFilledPoly( EDA_Rect * ClipBox, wxDC * DC, wxPoint Points[], int n );
#endif

/* global variables */
extern BASE_SCREEN* ActiveScreen;

@@ -74,10 +80,12 @@ static inline int USCALE( us arg, us num, us den )
}


static int inline ZoomValue( int val ) {
static int inline ZoomValue( int val )
{
    return ActiveScreen->Scale( val );
}


/****************************************/
/* External reference for the mappings. */
/****************************************/
@@ -357,9 +365,11 @@ void GRSetDrawMode( wxDC* DC, int draw_mode )
    if( draw_mode & GR_OR )
#if defined(__WXMAC__) && wxMAC_USE_CORE_GRAPHICS


        DC->SetLogicalFunction( wxCOPY );
#else


        DC->SetLogicalFunction( wxOR );
#endif
    else if( draw_mode & GR_XOR )
@@ -877,7 +887,16 @@ static void GRSPoly( EDA_Rect* ClipBox, wxDC* DC, int n, wxPoint Points[], bool
    if( Fill && ( n > 2 ) )
    {
        GRSetBrush( DC, BgColor, FILLED );
        DC->DrawPolygon( n, Points );


        /* clip before send the filled polygon to wxDC, because under linux (GTK?)
         *  polygonsl having large coordinates are incorrectly drawn
         */
#ifdef USE_CLIP_FILLED_POLYGONS
        ClipAndDrawFilledPoly( ClipBox, DC, Points, n );
#else
         DC->DrawPolygon( n, Points ); //does not work very well under linux
#endif
    }
    else
    {
@@ -1531,3 +1550,41 @@ void GRSetTextBgColor( wxDC* DC, wxFont*, int Color )
                               ColorRefs[Color].m_Blue )
                           );
}

#ifdef USE_CLIP_FILLED_POLYGONS

/** Function ClipAndDrawFilledPoly
 *  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 Linux (2009) because filled polygons are incorrectly drawn
 *  if they have too large coordinates (seems due to integer overflows in calculations)
 *  Could be removed in some years, if become unnecesary.
 */
#include "SutherlandHodgmanClipPoly.h"
void ClipAndDrawFilledPoly( EDA_Rect* aClipBox, wxDC* aDC, wxPoint aPoints[], int n )
{
    static vector<wxPoint> clippedPolygon;
    static pointVector     inputPolygon, outputPolygon;

    inputPolygon.clear();
    outputPolygon.clear();
    clippedPolygon.clear();
    for( int ii = 0; ii < n; ii++ )
        inputPolygon.push_back( PointF( (REAL)aPoints[ii].x, (REAL)aPoints[ii].y ) );

    RectF             window( (REAL) aClipBox->GetX(), (REAL) aClipBox->GetY(),
                             (REAL) aClipBox->GetWidth(), (REAL) aClipBox->GetHeight() );

    SutherlandHodgman sh( window );
    sh.Clip( inputPolygon, outputPolygon );

    for( cpointIterator cit = outputPolygon.begin(); cit != outputPolygon.end(); ++cit )
    {
        clippedPolygon.push_back( wxPoint( (int)round( cit->X ), (int)round( cit->Y ) ) );
    }

    if ( clippedPolygon.size() )
        aDC->DrawPolygon( clippedPolygon.size(), &clippedPolygon[0] );
}
#endif
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ include makefile.include
-include *.d

# specfic Compiler flags and options
CPPFLAGS += $(EXTRACPPFLAGS) -I./ -I../include -I$(BOOST)
CPPFLAGS += $(EXTRACPPFLAGS) -I./ -I../include
EDACPPFLAGS = $(CPPFLAGS)


+1 −1
Original line number Diff line number Diff line
EXTRACPPFLAGS += -I$(SYSINCLUDE) -I./ -Ibitmaps -I../include
EXTRACPPFLAGS += -I$(SYSINCLUDE) -I./ -Ibitmaps -I../include -I../polygon

COMMON = ../include/colors.h

+3 −1
Original line number Diff line number Diff line
@@ -87,6 +87,8 @@ ifdef USE_MATCH_LAYER
CPPFLAGS += -DUSE_MATCH_LAYER
endif

CPPFLAGS += -I $(BOOST_LIB)

ifdef KICAD_PYTHON
PYTHON_VERSION=2.5
PYLIBS= -L/usr/lib
@@ -100,7 +102,7 @@ endif
MESALIBSPATH = /usr/local/lib

# Boost headers     (location of boost/)
BOOST = ../
BOOST_LIB = ../

#for static link: add wx gl lib
LIBVERSION=`wx-config --release`
Loading