Commit 5383aa2e authored by jean-pierre charras's avatar jean-pierre charras

Gerbview: fix bug 788778.

parent 09c038be
...@@ -301,8 +301,8 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component ) ...@@ -301,8 +301,8 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
if( !Component->GetFlags() ) if( !Component->GetFlags() )
{ {
ADD_MENUITEM( editmenu, ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP, _( "Edit with Libedit" ), ADD_MENUITEM( editmenu, ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP, _( "Edit with Library Editor" ),
library_xpm ); libedit_xpm );
} }
ADD_MENUITEM_WITH_SUBMENU( PopMenu, editmenu, ID_POPUP_SCH_GENERIC_EDIT_CMP, ADD_MENUITEM_WITH_SUBMENU( PopMenu, editmenu, ID_POPUP_SCH_GENERIC_EDIT_CMP,
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* @param aData = a pointer to an optional data (not used here: can be NULL) * @param aData = a pointer to an optional data (not used here: can be NULL)
*/ */
void GERBVIEW_FRAME::PrintPage( wxDC* aDC, int aPrintMasklayer, void GERBVIEW_FRAME::PrintPage( wxDC* aDC, int aPrintMasklayer,
bool aPrintMirrorMode, void* aData ) bool aPrintMirrorMode, void* aData )
{ {
// Save current draw options, because print mode has specfic options: // Save current draw options, because print mode has specfic options:
int DisplayPolygonsModeImg = g_DisplayPolygonsModeSketch; int DisplayPolygonsModeImg = g_DisplayPolygonsModeSketch;
...@@ -67,21 +67,21 @@ void GERBVIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) ...@@ -67,21 +67,21 @@ void GERBVIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
wxBusyCursor dummy; wxBusyCursor dummy;
int drawMode = -1; int drawMode = -1;
switch ( GetDisplayMode() ) switch( GetDisplayMode() )
{ {
default: default:
case 0: case 0:
break; break;
case 1: case 1:
drawMode = GR_COPY; drawMode = GR_COPY;
break; break;
case 2: case 2:
drawMode = GR_OR; drawMode = GR_OR;
break; break;
} }
// Draw according to the current setting. This needs to be GR_COPY or GR_OR. // Draw according to the current setting. This needs to be GR_COPY or GR_OR.
...@@ -115,37 +115,59 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin ...@@ -115,37 +115,59 @@ 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 // 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 // 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 ); wxColour bgColor = MakeColour( g_DrawBgColor );
wxBrush bgBrush( bgColor, wxSOLID ); wxBrush bgBrush( bgColor, wxSOLID );
int bitmapWidth, bitmapHeight; int bitmapWidth, bitmapHeight;
wxDC* plotDC = aDC; wxDC* plotDC = aDC;
aPanel->GetClientSize( &bitmapWidth, &bitmapHeight ); aPanel->GetClientSize( &bitmapWidth, &bitmapHeight );
wxBitmap* layerBitmap = NULL; wxBitmap* layerBitmap = NULL;
wxBitmap* screenBitmap = NULL; wxBitmap* screenBitmap = NULL;
wxMemoryDC layerDC; // used sequentially for each gerber layer wxMemoryDC layerDC; // used sequentially for each gerber layer
wxMemoryDC screenDC; 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 ); layerBitmap = new wxBitmap( bitmapWidth, bitmapHeight );
screenBitmap = new wxBitmap( bitmapWidth, bitmapHeight ); screenBitmap = new wxBitmap( bitmapWidth, bitmapHeight );
layerDC.SelectObject( *layerBitmap ); layerDC.SelectObject( *layerBitmap );
EDA_RECT tmpRect = aPanel->m_ClipBox;
aPanel->DoPrepareDC( layerDC ); aPanel->DoPrepareDC( layerDC );
aPanel->m_ClipBox = tmpRect; aPanel->m_ClipBox = drawBox;
layerDC.SetBackground( bgBrush ); layerDC.SetBackground( bgBrush );
layerDC.SetBackgroundMode( wxSOLID ); layerDC.SetBackgroundMode( wxSOLID );
layerDC.Clear(); layerDC.Clear();
aPanel->DrawBackGround( &layerDC );
screenDC.SelectObject( *screenBitmap ); screenDC.SelectObject( *screenBitmap );
screenDC.SetBackground( bgBrush ); screenDC.SetBackground( bgBrush );
screenDC.SetBackgroundMode( wxSOLID ); screenDC.SetBackgroundMode( wxSOLID );
screenDC.Clear(); screenDC.Clear();
plotDC = &layerDC;
} }
bool doBlit = false; // this flag requests an image transfert to actual screen when true. bool doBlit = false; // this flag requests an image transfert to actual screen when true.
...@@ -153,13 +175,13 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin ...@@ -153,13 +175,13 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
bool end = false; bool end = false;
for( int layer = 0; !end; layer++ ) for( int layer = 0; !end; layer++ )
{ {
int active_layer = ((GERBVIEW_FRAME*)m_PcbFrame)->getActiveLayer(); int active_layer = ( (GERBVIEW_FRAME*) m_PcbFrame )->getActiveLayer();
if( layer == active_layer ) // active layer will be drawn after other layers if( layer == active_layer ) // active layer will be drawn after other layers
continue; continue;
if( layer == 32 ) // last loop: draw active layer if( layer == 32 ) // last loop: draw active layer
{ {
end = true; end = true;
layer = active_layer; layer = active_layer;
} }
...@@ -171,12 +193,18 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin ...@@ -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 if( gerber == NULL ) // Graphic layer not yet used
continue; continue;
if( aDrawMode != -1 ) if( useBufferBitmap )
{ {
// Draw each layer into a bitmap first. Negative Gerber // Draw each layer into a bitmap first. Negative Gerber
// layers are drawn in background color. // layers are drawn in background color.
if( gerber->HasNegativeItems() && doBlit ) 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 ) if( aDrawMode == GR_COPY )
{ {
// Use the layer bitmap itself as a mask when blitting. The bitmap // 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 ...@@ -184,7 +212,8 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
layerDC.SelectObject( wxNullBitmap ); layerDC.SelectObject( wxNullBitmap );
layerBitmap->SetMask( new wxMask( *layerBitmap, bgColor ) ); layerBitmap->SetMask( new wxMask( *layerBitmap, bgColor ) );
layerDC.SelectObject( *layerBitmap ); 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 ) else if( aDrawMode == GR_OR )
{ {
...@@ -195,10 +224,16 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin ...@@ -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 cpu cycles needed to create the monochromatic bitmap above, and
// the extra time needed to do bit indexing into the monochromatic bitmap // the extra time needed to do bit indexing into the monochromatic bitmap
// on the blit above. // 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; doBlit = false;
layerDC.Clear(); layerDC.Clear();
} }
...@@ -209,12 +244,9 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin ...@@ -209,12 +244,9 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
int color = GetBoard()->GetLayerColor( layer ); int color = GetBoard()->GetLayerColor( layer );
GRSetDrawMode( &layerDC, GR_COPY ); GRSetDrawMode( &layerDC, GR_COPY );
GRFilledRect( &drawBox, plotDC, drawBox.GetX(), drawBox.GetY(),
EDA_RECT* cbox = &aPanel->m_ClipBox; drawBox.GetRight(), drawBox.GetBottom(),
0, color, color );
GRSFilledRect( cbox, plotDC, cbox->GetX(), cbox->GetY(),
cbox->GetRight(), cbox->GetBottom(),
0, color, color );
GRSetDrawMode( plotDC, GR_COPY ); GRSetDrawMode( plotDC, GR_COPY );
doBlit = true; doBlit = true;
...@@ -222,7 +254,7 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin ...@@ -222,7 +254,7 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
int dcode_highlight = 0; int dcode_highlight = 0;
if( layer == ((GERBVIEW_FRAME*)m_PcbFrame)->getActiveLayer() ) if( layer == ( (GERBVIEW_FRAME*) m_PcbFrame )->getActiveLayer() )
dcode_highlight = gerber->m_Selected_Tool; dcode_highlight = gerber->m_Selected_Tool;
int layerdrawMode = GR_COPY; int layerdrawMode = GR_COPY;
...@@ -230,6 +262,8 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin ...@@ -230,6 +262,8 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
if( aDrawMode == GR_OR && !gerber->HasNegativeItems() ) if( aDrawMode == GR_OR && !gerber->HasNegativeItems() )
layerdrawMode = GR_OR; 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() ) for( BOARD_ITEM* item = GetBoard()->m_Drawings; item; item = item->Next() )
{ {
GERBER_DRAW_ITEM* gerb_item = (GERBER_DRAW_ITEM*) item; 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 ...@@ -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 ) if( dcode_highlight && dcode_highlight == gerb_item->m_DCode )
drawMode |= GR_SURBRILL; drawMode |= GR_SURBRILL;
gerb_item->Draw( aPanel, plotDC, drawMode ); gerb_item->Draw( aPanel, plotDC, drawMode );
doBlit = true; 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 // this is the last transfert to screenDC. If there are no negative items, this is
// the only one // the only one
if( aDrawMode == GR_COPY ) if( aDrawMode == GR_COPY )
...@@ -256,17 +295,34 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin ...@@ -256,17 +295,34 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
layerDC.SelectObject( wxNullBitmap ); layerDC.SelectObject( wxNullBitmap );
layerBitmap->SetMask( new wxMask( *layerBitmap, bgColor ) ); layerBitmap->SetMask( new wxMask( *layerBitmap, bgColor ) );
layerDC.SelectObject( *layerBitmap ); 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 ) 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 ); layerDC.SelectObject( wxNullBitmap );
screenDC.SelectObject( wxNullBitmap ); screenDC.SelectObject( wxNullBitmap );
delete layerBitmap; delete layerBitmap;
...@@ -274,6 +330,7 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin ...@@ -274,6 +330,7 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
} }
} }
/* Function DrawItemsDCodeID /* Function DrawItemsDCodeID
* Draw the DCode value (if exists) corresponding to gerber item * Draw the DCode value (if exists) corresponding to gerber item
* Polygons do not have a DCode * Polygons do not have a DCode
...@@ -310,9 +367,9 @@ void GERBVIEW_FRAME::DrawItemsDCodeID( wxDC* aDC, int aDrawMode ) ...@@ -310,9 +367,9 @@ void GERBVIEW_FRAME::DrawItemsDCodeID( wxDC* aDC, int aDrawMode )
Line.Printf( wxT( "D%d" ), gerb_item->m_DCode ); Line.Printf( wxT( "D%d" ), gerb_item->m_DCode );
if( gerb_item->GetDcodeDescr() ) if( gerb_item->GetDcodeDescr() )
width = gerb_item->GetDcodeDescr()->GetShapeDim( gerb_item ); width = gerb_item->GetDcodeDescr()->GetShapeDim( gerb_item );
else else
width = MIN( gerb_item->m_Size.x, gerb_item->m_Size.y ); width = MIN( gerb_item->m_Size.x, gerb_item->m_Size.y );
orient = TEXT_ORIENT_HORIZ; orient = TEXT_ORIENT_HORIZ;
...@@ -327,6 +384,7 @@ void GERBVIEW_FRAME::DrawItemsDCodeID( wxDC* aDC, int aDrawMode ) ...@@ -327,6 +384,7 @@ void GERBVIEW_FRAME::DrawItemsDCodeID( wxDC* aDC, int aDrawMode )
if( abs( delta.x ) < abs( delta.y ) ) if( abs( delta.x ) < abs( delta.y ) )
orient = TEXT_ORIENT_VERT; orient = TEXT_ORIENT_VERT;
// A reasonnable size for text is width/2 because text needs margin below and above it. // A reasonnable size for text is width/2 because text needs margin below and above it.
// a margin = width/4 seems good // a margin = width/4 seems good
width /= 2; width /= 2;
...@@ -351,6 +409,7 @@ void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER&, int ) ...@@ -351,6 +409,7 @@ void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER&, int )
{ {
} }
/* dummy_functions /* dummy_functions
* *
* These functions are used in some classes. * These functions are used in some classes.
...@@ -367,4 +426,3 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, ...@@ -367,4 +426,3 @@ TRACK* Marque_Une_Piste( BOARD* aPcb,
{ {
return NULL; return NULL;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment