Zones drawing optimization with WXGrapchisContext + Fix bug #612132

This commit is contained in:
Marco Serantoni 2010-10-09 10:08:29 +02:00
parent fc0864befa
commit ea812ef5c9
12 changed files with 183 additions and 105 deletions

View File

@ -24,6 +24,9 @@ option(USE_WX_ZOOM "Use wxDC to perform zooming (default OFF). Warning, this is
option(USE_WX_GRAPHICS_CONTEXT
"Use wxGraphicsContext for rendering (default OFF). Warning, this is experimental")
option(USE_WX_OVERLAY
"Use wxOverlay: Always ON for MAC (default OFF). Warning, this is experimental")
option(USE_BOOST_POLYGON_LIBRARY
"Use boost polygon library instead of Kbool to calculate filled areas in zones (default OFF). Warning, this is experimental")
@ -54,6 +57,11 @@ if(USE_WX_ZOOM)
add_definitions(-DUSE_WX_ZOOM)
endif(USE_WX_ZOOM)
if(USE_WX_OVERLAY OR APPLE)
add_definitions(-DUSE_WX_OVERLAY)
endif(USE_WX_OVERLAY OR APPLE)
if(USE_WX_GRAPHICS_CONTEXT)
set( USE_WX_ZOOM ON )
add_definitions(-DUSE_WX_ZOOM)

View File

@ -12,6 +12,7 @@
#include "class_base_screen.h"
#include "bezier_curves.h"
#include "math_for_graphics.h"
#include <wx/graphics.h>
#ifndef FILLED
@ -880,6 +881,60 @@ void GRSLine( EDA_Rect* ClipBox,
GRLastMoveToY = y2;
}
/*
* Draw an array of lines
*/
void GRLineArray(EDA_Rect* ClipBox,
wxDC* DC,
wxPoint points[],
int lines,
int width,
int Color )
{
for(int i= 0 ; i < lines; i++)
{
points[i].x = GRMapX( points[i].x );
points[i].y = GRMapY( points[i].y );
}
width = ZoomValue( width );
GRSLineArray(ClipBox,DC,points,lines,width,Color);
}
void GRSLineArray(EDA_Rect* ClipBox,
wxDC* DC,
wxPoint points[],
int lines,
int width,
int Color )
{
GRSetColorPen( DC, Color, width );
#if defined( USE_WX_GRAPHICS_CONTEXT ) || defined(__WXMAC__)
wxGraphicsContext *gc = wxGraphicsContext::Create( DC );
wxASSERT(gc);
gc->Clip( ClipBox->GetX(), ClipBox->GetY(), ClipBox->GetRight(), ClipBox->GetHeight());
wxGraphicsPath path = gc->CreatePath();
for(int i= 0 ; i < lines; i+=2)
{
path.MoveToPoint(points[i].x, points[i].y);
path.AddLineToPoint(points[i+1].x, points[i+1].y);
}
gc->StrokePath(path);
gc->ResetClip();
delete gc;
#else
for(int i= 0 ; i < lines; i+=2)
{
WinClipAndDrawLine( ClipBox, DC, points[i].x , points[i].y, points[i+1].x , points[i+1].y, Color, width );
GRLastMoveToX = points[i+1].x;
GRLastMoveToY = points[i+1].y;
}
#endif
}
/*
* Move to a new position relative to current one, in object space.

View File

@ -1,4 +1,4 @@
update=01/05/2010 14:42:54
update=Sabato, 2010 Ottobre 09 10:06:24
version=1
last_client=pcbnew
[cvpcb]

View File

@ -61,7 +61,7 @@ public:
int m_CursorLevel; // Index for cursor redraw in XOR
// mode
#ifdef __WXMAC__
#ifdef USE_WX_OVERLAY
// MAC Uses overlay to workaround the wxINVERT and wxXOR miss
wxOverlay m_overlay;
#endif

View File

@ -198,4 +198,9 @@ void GRRectPs( EDA_Rect* aClipBox, wxDC* aDC,const EDA_Rect& aRect,
void GRSFilledRect( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1,
int x2, int y2, int width, int Color, int BgColor );
void GRLineArray( EDA_Rect* ClipBox, wxDC* DC, wxPoint points[],
int lines, int width, int Color );
void GRSLineArray( EDA_Rect* ClipBox, wxDC* DC, wxPoint points[],
int lines, int width, int Color );
#endif /* define GR_BASIC */

View File

@ -186,7 +186,7 @@ void MODULE::Copy( MODULE* aModule )
void MODULE::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
int draw_mode, const wxPoint& offset )
{
if( (m_Flags & DO_NOT_DRAW) )
if( (m_Flags & DO_NOT_DRAW) || (m_Flags & IS_MOVED) )
return;
for( D_PAD* pad = m_Pads; pad; pad = pad->Next() )

View File

@ -477,6 +477,7 @@ void ZONE_CONTAINER::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int draw_mode, con
// draw the lines
int i_start_contour = 0;
wxPoint lines[( GetNumCorners()*2)+2];
for( int ic = 0; ic < GetNumCorners(); ic++ )
{
seg_start = GetCornerPosition( ic ) + offset;
@ -489,18 +490,23 @@ void ZONE_CONTAINER::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int draw_mode, con
seg_end = GetCornerPosition( i_start_contour ) + offset;
i_start_contour = ic + 1;
}
GRLine( &panel->m_ClipBox, DC, seg_start.x, seg_start.y, seg_end.x, seg_end.y, 0, color );
lines[ic*2].x = seg_start.x;
lines[ic*2].y = seg_start.y;
lines[ic*2+1].x = seg_start.x;
lines[ic*2+1].y = seg_start.y;
}
GRLineArray(&panel->m_ClipBox, DC, lines, GetNumCorners(), 0, color);
// draw hatches
wxPoint hatches[(m_Poly->m_HatchLines.size() *2)+2];
for( unsigned ic = 0; ic < m_Poly->m_HatchLines.size(); ic++ )
{
int xi = m_Poly->m_HatchLines[ic].xi + offset.x;
int yi = m_Poly->m_HatchLines[ic].yi + offset.y;
int xf = m_Poly->m_HatchLines[ic].xf + offset.x;
int yf = m_Poly->m_HatchLines[ic].yf + offset.y;
GRLine( &panel->m_ClipBox, DC, xi, yi, xf, yf, 0, color );
hatches[ic*2].x = m_Poly->m_HatchLines[ic].xi + offset.x;
hatches[ic*2].y = m_Poly->m_HatchLines[ic].yi + offset.y;
hatches[ic*2+1].x = m_Poly->m_HatchLines[ic].xf + offset.x;
hatches[ic*2+1].y = m_Poly->m_HatchLines[ic].yf + offset.y;
}
GRLineArray(&panel->m_ClipBox, DC, hatches, m_Poly->m_HatchLines.size(), 0, color );
}

View File

@ -361,7 +361,7 @@ void WinEDA_PcbFrame::GeneralControle( wxDC* DC, wxPoint Mouse )
if( DrawPanel->ManageCurseur )
{
#ifdef __WXMAC__
#ifdef USE_WX_OVERLAY
wxDCOverlay oDC( DrawPanel->m_overlay, DC );
oDC.Clear();
DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
@ -369,7 +369,7 @@ void WinEDA_PcbFrame::GeneralControle( wxDC* DC, wxPoint Mouse )
DrawPanel->ManageCurseur( DrawPanel, DC, TRUE );
#endif
}
#ifdef __WXMAC__
#ifdef USE_WX_OVERLAY
else
DrawPanel->m_overlay.Reset();
#endif

View File

@ -91,7 +91,7 @@ void WinEDA_ModuleEditFrame::ReCreateMenuBar()
fileMenu->AppendSeparator();
/* Print */
item = new wxMenuItem( fileMenu, wxID_PRINT, _( "&Print" ),
item = new wxMenuItem( fileMenu, wxID_PRINT, _( "&Print\tCtrl+P" ),
_( "Print the current module" ) );
item->SetBitmap( plot_xpm );
fileMenu->Append( item );

View File

@ -195,7 +195,7 @@ void WinEDA_PcbFrame::ReCreateMenuBar()
filesMenu->AppendSeparator();
/* Print */
item = new wxMenuItem( filesMenu, wxID_PRINT, _( "&Print" ),
item = new wxMenuItem( filesMenu, wxID_PRINT, _( "&Print\tCtrl+P" ),
_( "Print board" ) );
item->SetBitmap( print_button );
filesMenu->Append( item );

View File

@ -224,6 +224,10 @@ void Abort_MoveOrCopyModule( WinEDA_DrawPanel* Panel, wxDC* DC )
pcbframe->GetBoard()->m_Status_Pcb &= ~DO_NOT_SHOW_GENERAL_RASTNEST;
if( pcbframe->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
pcbframe->DrawGeneralRatsnest( DC );
#ifdef __WXMAC__
pcbframe->GetScreen()->SetRefreshReq();
#endif
}

View File

@ -54,7 +54,7 @@ void WinEDA_ModuleEditFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
module->Draw( DrawPanel, DC, GR_OR );
}
#ifdef __WXMAC__
#ifdef USE_WX_OVERLAY
DrawPanel->m_overlay.Reset();
wxDCOverlay overlaydc( DrawPanel->m_overlay, DC );
overlaydc.Clear();
@ -90,7 +90,7 @@ void WinEDA_PcbFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
DrawGeneralRatsnest( DC );
#ifdef __WXMAC__
#ifdef USE_WX_OVERLAY
DrawPanel->m_overlay.Reset();
wxDCOverlay overlaydc( DrawPanel->m_overlay, DC );
overlaydc.Clear();