Gerbview: fix bug 788778.

This commit is contained in:
jean-pierre charras 2011-05-30 15:55:37 +02:00
parent 09c038be5c
commit 5383aa2e56
2 changed files with 106 additions and 48 deletions

View File

@ -301,8 +301,8 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
if( !Component->GetFlags() )
{
ADD_MENUITEM( editmenu, ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP, _( "Edit with Libedit" ),
library_xpm );
ADD_MENUITEM( editmenu, ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP, _( "Edit with Library Editor" ),
libedit_xpm );
}
ADD_MENUITEM_WITH_SUBMENU( PopMenu, editmenu, ID_POPUP_SCH_GENERIC_EDIT_CMP,

View File

@ -115,6 +115,10 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
{
// Because Images can be negative (i.e with background filled in color) items are drawn
// graphic layer per graphic layer, after the background is filled
// to a temporary biumap
// at least when aDrawMode = GR_COPY or aDrawMode = GR_OR
// If aDrawMode = -1, items are drawn to the main screen, and therefore
// arfefacts can happen with negative items or negative images
wxColour bgColor = MakeColour( g_DrawBgColor );
wxBrush bgBrush( bgColor, wxSOLID );
@ -129,23 +133,41 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
wxMemoryDC layerDC; // used sequentially for each gerber layer
wxMemoryDC screenDC;
if( aDrawMode != -1 )
// When each image must be drawn using GR_OR (transparency mode)
// or GR_COPY (stacked mode) we must use a temporary bitmap
// to draw gerber images.
// this is due to negative objects (drawn using background color) that create artefacct
// on other images when drawn on screen
bool useBufferBitmap = false;
if( (aDrawMode == GR_COPY) || ( aDrawMode == GR_OR ) )
useBufferBitmap = true;
// these parameters are saved here, because they are modified
// and restored later
EDA_RECT drawBox = aPanel->m_ClipBox;
double scale;
aDC->GetUserScale(&scale, &scale);
wxPoint dev_org = aDC->GetDeviceOrigin();
wxPoint logical_org = aDC->GetLogicalOrigin( );
if( useBufferBitmap )
{
layerBitmap = new wxBitmap( bitmapWidth, bitmapHeight );
screenBitmap = new wxBitmap( bitmapWidth, bitmapHeight );
layerDC.SelectObject( *layerBitmap );
EDA_RECT tmpRect = aPanel->m_ClipBox;
aPanel->DoPrepareDC( layerDC );
aPanel->m_ClipBox = tmpRect;
aPanel->m_ClipBox = drawBox;
layerDC.SetBackground( bgBrush );
layerDC.SetBackgroundMode( wxSOLID );
layerDC.Clear();
aPanel->DrawBackGround( &layerDC );
screenDC.SelectObject( *screenBitmap );
screenDC.SetBackground( bgBrush );
screenDC.SetBackgroundMode( wxSOLID );
screenDC.Clear();
plotDC = &layerDC;
}
bool doBlit = false; // this flag requests an image transfert to actual screen when true.
@ -171,12 +193,18 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
if( gerber == NULL ) // Graphic layer not yet used
continue;
if( aDrawMode != -1 )
if( useBufferBitmap )
{
// Draw each layer into a bitmap first. Negative Gerber
// layers are drawn in background color.
if( gerber->HasNegativeItems() && doBlit )
{
// Set Device orgin, logical origin and scale to default values
// This is needed by Blit function when using a mask.
// Beside, for Blit call, both layerDC and screenDc must have the same settings
layerDC.SetDeviceOrigin(0,0);
layerDC.SetLogicalOrigin( 0, 0 );
layerDC.SetUserScale( 1, 1 );
if( aDrawMode == GR_COPY )
{
// Use the layer bitmap itself as a mask when blitting. The bitmap
@ -184,7 +212,8 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
layerDC.SelectObject( wxNullBitmap );
layerBitmap->SetMask( new wxMask( *layerBitmap, bgColor ) );
layerDC.SelectObject( *layerBitmap );
screenDC.Blit( 0, 0, bitmapWidth, bitmapHeight, &layerDC, 0, 0, wxCOPY, true );
screenDC.Blit( 0, 0, bitmapWidth, bitmapHeight,
&layerDC, 0, 0, wxCOPY, true );
}
else if( aDrawMode == GR_OR )
{
@ -195,10 +224,16 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
// the cpu cycles needed to create the monochromatic bitmap above, and
// the extra time needed to do bit indexing into the monochromatic bitmap
// on the blit above.
screenDC.Blit( 0, 0, bitmapWidth, bitmapHeight, &layerDC, 0, 0, wxOR );
screenDC.Blit( 0, 0, bitmapWidth, bitmapHeight,
&layerDC, 0, 0, wxOR );
}
}
// Restore actual values for drawing
layerDC.SetDeviceOrigin( dev_org.x, dev_org.y );
layerDC.SetLogicalOrigin( logical_org.x, logical_org.y );
layerDC.SetUserScale( scale, scale );
doBlit = false;
layerDC.Clear();
}
@ -209,11 +244,8 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
int color = GetBoard()->GetLayerColor( layer );
GRSetDrawMode( &layerDC, GR_COPY );
EDA_RECT* cbox = &aPanel->m_ClipBox;
GRSFilledRect( cbox, plotDC, cbox->GetX(), cbox->GetY(),
cbox->GetRight(), cbox->GetBottom(),
GRFilledRect( &drawBox, plotDC, drawBox.GetX(), drawBox.GetY(),
drawBox.GetRight(), drawBox.GetBottom(),
0, color, color );
GRSetDrawMode( plotDC, GR_COPY );
@ -230,6 +262,8 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
if( aDrawMode == GR_OR && !gerber->HasNegativeItems() )
layerdrawMode = GR_OR;
// Now we can draw the current layer to the bitmap buffer
// When needed, the previous bitmap is already copied to the screen buffer.
for( BOARD_ITEM* item = GetBoard()->m_Drawings; item; item = item->Next() )
{
GERBER_DRAW_ITEM* gerb_item = (GERBER_DRAW_ITEM*) item;
@ -241,14 +275,19 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
if( dcode_highlight && dcode_highlight == gerb_item->m_DCode )
drawMode |= GR_SURBRILL;
gerb_item->Draw( aPanel, plotDC, drawMode );
doBlit = true;
}
}
if( doBlit && aDrawMode != -1 ) // Blit is used only if aDrawMode >= 0
if( doBlit && useBufferBitmap ) // Blit is used only if aDrawMode >= 0
{
// For this Blit call, layerDC and screenDC must have the same settings
// So we set device orgin, logical origin and scale to default values
// in layerDC
layerDC.SetDeviceOrigin(0,0);
layerDC.SetLogicalOrigin( 0, 0 );
layerDC.SetUserScale( 1, 1 );
// this is the last transfert to screenDC. If there are no negative items, this is
// the only one
if( aDrawMode == GR_COPY )
@ -256,17 +295,34 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
layerDC.SelectObject( wxNullBitmap );
layerBitmap->SetMask( new wxMask( *layerBitmap, bgColor ) );
layerDC.SelectObject( *layerBitmap );
screenDC.Blit( 0, 0, bitmapWidth, bitmapHeight, &layerDC, 0, 0, wxCOPY, true );
screenDC.Blit( 0, 0, bitmapWidth, bitmapHeight,
&layerDC, 0, 0, wxCOPY, true );
}
else if( aDrawMode == GR_OR )
{
screenDC.Blit( 0, 0, bitmapWidth, bitmapHeight, &layerDC, 0, 0, wxOR, false );
screenDC.Blit( 0, 0, bitmapWidth, bitmapHeight,
&layerDC, 0, 0, wxOR );
}
}
if( aDrawMode != -1 )
if( useBufferBitmap )
{
aDC->Blit( 0, 0, bitmapWidth, bitmapHeight, &screenDC, 0, 0, wxCOPY );
// For this Blit call, aDC and screenDC must have the same settings
// So we set device orgin, logical origin and scale to default values
// in aDC
aDC->SetDeviceOrigin( 0, 0);
aDC->SetLogicalOrigin( 0, 0 );
aDC->SetUserScale( 1, 1 );
aDC->Blit( 0, 0, bitmapWidth, bitmapHeight,
&screenDC, 0, 0, wxCOPY );
// Restore aDC values
aDC->SetDeviceOrigin(dev_org.x, dev_org.y);
aDC->SetLogicalOrigin( logical_org.x, logical_org.y );
aDC->SetUserScale( scale, scale );
layerDC.SelectObject( wxNullBitmap );
screenDC.SelectObject( wxNullBitmap );
delete layerBitmap;
@ -274,6 +330,7 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
}
}
/* Function DrawItemsDCodeID
* Draw the DCode value (if exists) corresponding to gerber item
* Polygons do not have a DCode
@ -327,6 +384,7 @@ void GERBVIEW_FRAME::DrawItemsDCodeID( wxDC* aDC, int aDrawMode )
if( abs( delta.x ) < abs( delta.y ) )
orient = TEXT_ORIENT_VERT;
// A reasonnable size for text is width/2 because text needs margin below and above it.
// a margin = width/4 seems good
width /= 2;
@ -351,6 +409,7 @@ void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER&, int )
{
}
/* dummy_functions
*
* These functions are used in some classes.
@ -367,4 +426,3 @@ TRACK* Marque_Une_Piste( BOARD* aPcb,
{
return NULL;
}