diff --git a/common/copy_to_clipboard.cpp b/common/copy_to_clipboard.cpp index 4e2ba3f1d5..fdbba58bb3 100644 --- a/common/copy_to_clipboard.cpp +++ b/common/copy_to_clipboard.cpp @@ -37,11 +37,7 @@ void WinEDA_DrawFrame::CopyToClipboard( wxCommandEvent& event ) DrawPanel->SetCursor( wxCursor( DrawPanel->m_PanelCursor = DrawPanel->m_PanelDefaultCursor ) ); - if( DrawPanel->ManageCurseur && DrawPanel->ForceCloseManageCurseur ) - { - KicadGraphicContext dc( DrawPanel ); - DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc ); - } + DrawPanel->UnManageCursor( ); } } diff --git a/common/drawpanel.cpp b/common/drawpanel.cpp index b61d4ef99f..5fa0a8152e 100644 --- a/common/drawpanel.cpp +++ b/common/drawpanel.cpp @@ -12,6 +12,7 @@ #include "class_base_screen.h" #include "wxstruct.h" +#include "kicad_device_context.h" #define CURSOR_SIZE 12 // Cursor size in pixels @@ -69,6 +70,7 @@ WinEDA_DrawPanel::WinEDA_DrawPanel( WinEDA_DrawFrame* parent, int id, wxBORDER | wxNO_FULL_REPAINT_ON_RESIZE ) { m_Parent = parent; + wxASSERT( m_Parent ); m_ScrollButt_unit = 40; SetBackgroundColour( wxColour( ColorRefs[g_DrawBgColor].m_Red, @@ -201,7 +203,7 @@ wxPoint WinEDA_DrawPanel::CursorRealPosition( const wxPoint& ScreenPos ) { #ifdef WX_ZOOM wxCoord x, y; - KicadGraphicContext DC( this ); + INSTALL_DC( DC, this ); x = DC.DeviceToLogicalX( ScreenPos.x ); y = DC.DeviceToLogicalY( ScreenPos.y ); @@ -311,7 +313,7 @@ wxPoint WinEDA_DrawPanel::CursorScreenPosition() { #ifdef WX_ZOOM wxCoord x, y; - KicadGraphicContext DC( this ); + INSTALL_DC ( DC, this ); x = DC.LogicalToDeviceX( GetScreen()->m_Curseur.x ); y = DC.LogicalToDeviceY( GetScreen()->m_Curseur.y ); @@ -339,7 +341,7 @@ wxPoint WinEDA_DrawPanel::GetScreenCenterRealPosition( void ) GetScreen()->Unscale( realpos ); #ifdef WX_ZOOM // wxCoord x, y; -// KicadGraphicContext DC( this ); +// INSTALL_DC( DC, this ); // realpos.x = DC.DeviceToLogicalX( realpos.x ); // realpos.y = DC.DeviceToLogicalY( realpos.y ); #else @@ -567,7 +569,11 @@ void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event ) // Fix for pixel offset bug http://trac.wxwidgets.org/ticket/4187 paintDC.GetGraphicsContext()->Translate(0.5, 0.5); #else + #ifdef KICAD_USE_BUFFERED_DC + wxBufferedPaintDC paintDC( this ); + #else wxPaintDC paintDC( this ); + #endif #endif EDA_Rect tmp; wxRect PaintClipBox; @@ -1015,7 +1021,7 @@ void WinEDA_DrawPanel::OnMouseEvent( wxMouseEvent& event ) screen->m_MousePosition = CursorRealPosition( screen->m_MousePositionInPixels ); - KicadGraphicContext DC( this ); + INSTALL_DC( DC, this ); int kbstat = 0; @@ -1264,7 +1270,7 @@ void WinEDA_DrawPanel::OnKeyEvent( wxKeyEvent& event ) if( event.ShiftDown() && (key > 256) ) localkey |= GR_KB_SHIFT; - KicadGraphicContext DC( this ); + INSTALL_DC(DC, this ); BASE_SCREEN* Screen = GetScreen(); @@ -1345,18 +1351,15 @@ void WinEDA_DrawPanel::OnPan( wxCommandEvent& event ) void WinEDA_DrawPanel::UnManageCursor( int id, int cursor, const wxString& title ) { - wxClientDC dc( this ); - if( ManageCurseur && ForceCloseManageCurseur ) { + INSTALL_DC( dc, this ); ForceCloseManageCurseur( this, &dc ); m_AutoPAN_Request = false; - - if( id != -1 && cursor != -1 ) - { - wxASSERT( cursor > wxCURSOR_NONE && cursor < wxCURSOR_MAX ); - - m_Parent->SetToolID( id, cursor, title ); - } + } + if( id != -1 && cursor != -1 ) + { + wxASSERT( cursor > wxCURSOR_NONE && cursor < wxCURSOR_MAX ); + m_Parent->SetToolID( id, cursor, title ); } } diff --git a/common/zoom.cpp b/common/zoom.cpp index 418e681c1b..d5f878cced 100644 --- a/common/zoom.cpp +++ b/common/zoom.cpp @@ -15,6 +15,7 @@ #include "class_base_screen.h" #include "wxstruct.h" +#include "kicad_device_context.h" /** Compute draw offset (scroll bars and draw parameters) * in order to have the current graphic cursor position at the screen center @@ -27,7 +28,7 @@ void WinEDA_DrawFrame::Recadre_Trace( bool ToMouse ) { PutOnGrid( &(GetBaseScreen()->m_Curseur) ); AdjustScrollBars(); - KicadGraphicContext dc( DrawPanel ); + INSTALL_DC( dc, DrawPanel ) ; DrawPanel->ReDraw( &dc ); /* Move the mouse cursor to the on grid graphic cursor position */ @@ -130,7 +131,7 @@ void WinEDA_DrawFrame::OnZoom( wxCommandEvent& event ) // DrawPanel->Refresh(); usually good, // but does not work under linux, when called from here (wxGTK bug ?) { - KicadGraphicContext dc( DrawPanel ); + INSTALL_DC( dc, DrawPanel ); DrawPanel->ReDraw( &dc ); } break; diff --git a/eeschema/dialog_edit_component_in_schematic.cpp b/eeschema/dialog_edit_component_in_schematic.cpp index 2311426c5e..da4dce1c84 100644 --- a/eeschema/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialog_edit_component_in_schematic.cpp @@ -707,6 +707,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel() chipnameTextCtrl->SetValue( m_Cmp->m_ChipName ); } +#include "kicad_device_context.h" /* reinitialise components parametres to default values found in lib */ @@ -722,7 +723,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event ) if( entry == NULL ) return; - KicadGraphicContext dc( m_Parent->DrawPanel ); + INSTALL_DC( dc, m_Parent->DrawPanel ); RedrawOneStruct( m_Parent->DrawPanel, &dc, m_Cmp, g_XorMode ); diff --git a/eeschema/find.cpp b/eeschema/find.cpp index 9b7a99ff82..a684525c63 100644 --- a/eeschema/find.cpp +++ b/eeschema/find.cpp @@ -21,6 +21,8 @@ #include "protos.h" #include "class_library.h" +#include "kicad_device_context.h" + #include @@ -179,7 +181,7 @@ SCH_ITEM* WinEDA_SchematicFrame::FindComponentAndItem( Recadre_Trace( mouseWarp ); else { - KicadGraphicContext dc( DrawPanel ); + INSTALL_DC( dc, DrawPanel ); EXCHG( old_cursor_position, sheet->LastScreen()->m_Curseur ); DrawPanel->CursorOff( &dc ); @@ -354,7 +356,7 @@ SCH_ITEM* WinEDA_SchematicFrame::FindMarker( int SearchType ) Recadre_Trace( TRUE ); else { - KicadGraphicContext dc( DrawPanel ); + INSTALL_DC( dc, DrawPanel ); EXCHG( old_cursor_position, sheet->LastScreen()->m_Curseur ); DrawPanel->CursorOff( &dc ); DrawPanel->MouseTo( curpos ); @@ -577,7 +579,7 @@ SCH_ITEM* WinEDA_SchematicFrame::FindSchematicItem( const wxString& pattern, Recadre_Trace( mouseWarp ); else { - KicadGraphicContext dc( DrawPanel ); + INSTALL_DC( dc, DrawPanel ); EXCHG( old_cursor_position, Sheet->LastScreen()->m_Curseur ); DrawPanel->CursorOff( &dc ); diff --git a/eeschema/libframe.cpp b/eeschema/libframe.cpp index 20e614254f..31fd266fc5 100644 --- a/eeschema/libframe.cpp +++ b/eeschema/libframe.cpp @@ -17,6 +17,8 @@ #include "libeditfrm.h" #include "class_library.h" +#include "kicad_device_context.h" + #include @@ -604,8 +606,6 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event ) int id = event.GetId(); wxPoint pos; - KicadGraphicContext dc( DrawPanel ); - DrawPanel->m_IgnoreMouseEvents = true; wxGetMousePosition( &pos.x, &pos.y ); @@ -621,7 +621,6 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event ) case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINSIZE_ITEM: case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNAMESIZE_ITEM: case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_ITEM: - case ID_POPUP_LIBEDIT_CANCEL_EDITING: case ID_POPUP_ZOOM_BLOCK: case ID_POPUP_DELETE_BLOCK: case ID_POPUP_COPY_BLOCK: @@ -632,18 +631,23 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event ) case ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT: break; - case ID_POPUP_LIBEDIT_DELETE_ITEM: + case ID_POPUP_LIBEDIT_CANCEL_EDITING: if( DrawPanel->ManageCurseur && DrawPanel->ForceCloseManageCurseur ) - DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc ); + DrawPanel->UnManageCursor( ); + else + DrawPanel->UnManageCursor( 0, wxCURSOR_ARROW ); + break; + + case ID_POPUP_LIBEDIT_DELETE_ITEM: + DrawPanel->UnManageCursor( ); break; default: - if( DrawPanel->ManageCurseur && DrawPanel->ForceCloseManageCurseur ) - DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc ); - SetToolID( 0, wxCURSOR_ARROW, wxEmptyString ); + DrawPanel->UnManageCursor( 0, wxCURSOR_ARROW, wxEmptyString ); break; } + INSTALL_DC( dc, DrawPanel ); switch( id ) { case ID_LIBEDIT_SELECT_CURRENT_LIB: @@ -673,13 +677,6 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event ) } break; - case ID_POPUP_LIBEDIT_CANCEL_EDITING: - if( DrawPanel->ManageCurseur && DrawPanel->ForceCloseManageCurseur ) - DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc ); - else - SetToolID( 0, wxCURSOR_ARROW, wxEmptyString ); - break; - case ID_NO_SELECT_BUTT: SetToolID( 0, wxCURSOR_ARROW, wxEmptyString ); break; diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index 65fe548906..3a42beafcd 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -16,13 +16,13 @@ #include "eeschema_id.h" #include "protos.h" #include "class_library.h" +#include "kicad_device_context.h" void WinEDA_SchematicFrame::Process_Special_Functions( wxCommandEvent& event ) { int id = event.GetId(); wxPoint pos; - KicadGraphicContext dc( DrawPanel ); SCH_SCREEN* screen = GetScreen(); pos = wxGetMousePosition(); @@ -123,10 +123,8 @@ void WinEDA_SchematicFrame::Process_Special_Functions( wxCommandEvent& event ) DrawPanel-> m_PanelDefaultCursor ) ); - if( DrawPanel->ManageCurseur && DrawPanel->ForceCloseManageCurseur ) - { - DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc ); - } + // Stop the current command (if any) but keep the current tool + DrawPanel->UnManageCursor( ); /* Should not be executed, except bug. */ if( screen->m_BlockLocate.m_Command != BLOCK_IDLE ) @@ -139,25 +137,19 @@ void WinEDA_SchematicFrame::Process_Special_Functions( wxCommandEvent& event ) case ID_POPUP_SCH_DELETE_CMP: case ID_POPUP_SCH_DELETE: - // Stop the current command but keep the current tool - if( DrawPanel->ManageCurseur && DrawPanel->ForceCloseManageCurseur ) - { - DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc ); - } + // Stop the current command (if any) but keep the current tool + DrawPanel->UnManageCursor( ); break; default: // Stop the current command and deselect the current tool - if( DrawPanel->ManageCurseur && DrawPanel->ForceCloseManageCurseur ) - { - DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc ); - } DrawPanel->m_PanelCursor = DrawPanel->m_PanelDefaultCursor = wxCURSOR_ARROW; - SetToolID( 0, DrawPanel->m_PanelCursor, wxEmptyString ); + DrawPanel->UnManageCursor( 0, DrawPanel->m_PanelCursor ); break; } + INSTALL_DC( dc, DrawPanel ); switch( id ) { case ID_HIERARCHY: diff --git a/eeschema/tool_sch.cpp b/eeschema/tool_sch.cpp index 6e8064b2c2..a0d7555312 100644 --- a/eeschema/tool_sch.cpp +++ b/eeschema/tool_sch.cpp @@ -287,7 +287,6 @@ void WinEDA_SchematicFrame::OnSelectOptionToolbar( wxCommandEvent& event ) return; int id = event.GetId(); - KicadGraphicContext dc( DrawPanel ); switch( id ) { @@ -309,14 +308,13 @@ void WinEDA_SchematicFrame::OnSelectOptionToolbar( wxCommandEvent& event ) break; case ID_TB_OPTIONS_SELECT_CURSOR: - DrawPanel->CursorOff( &dc ); m_CursorShape = m_OptionsToolBar->GetToolState( id ); - DrawPanel->CursorOn( &dc ); + DrawPanel->Refresh( ); break; case ID_TB_OPTIONS_HIDDEN_PINS: m_ShowAllPins = m_OptionsToolBar->GetToolState( id ); - DrawPanel->ReDraw( &dc, TRUE ); + DrawPanel->Refresh( ); break; case ID_TB_OPTIONS_BUS_WIRES_ORIENT: diff --git a/eeschema/viewlibs.cpp b/eeschema/viewlibs.cpp index 81d1aa1571..d694d768cf 100644 --- a/eeschema/viewlibs.cpp +++ b/eeschema/viewlibs.cpp @@ -282,7 +282,16 @@ void WinEDA_ViewlibFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg ) LIB_ALIAS* alias = (LIB_ALIAS*) entry; component = alias->GetComponent(); - wxASSERT( component != NULL && component->isComponent() ); + if( component == NULL ) // Should not occur + { + wxASSERT( component != NULL ); + return; + } + if( ! component->isComponent() ) + { + wxASSERT( component->isComponent() ); + return; + } msg = alias->GetName(); diff --git a/gerbview/dcode.cpp b/gerbview/dcode.cpp index 7cded2bf40..05fb7c0e5a 100644 --- a/gerbview/dcode.cpp +++ b/gerbview/dcode.cpp @@ -464,7 +464,7 @@ void WinEDA_GerberFrame::CopyDCodesSizeToItems() } -void WinEDA_GerberFrame::Liste_D_Codes( wxDC* DC ) +void WinEDA_GerberFrame::Liste_D_Codes( ) { int ii, jj; D_CODE* pt_D_code; @@ -523,13 +523,4 @@ void WinEDA_GerberFrame::Liste_D_Codes( wxDC* DC ) List->Destroy(); if( ii < 0 ) return; - -#if 0 - - // Highlight segment corresponding to dCode selected. - if( Etat_Surbrillance ) - Hight_Light( DrawPanel, DC ); - net_code_Surbrillance = (GetScreen()->m_Active_Layer << 16) + ii; - Hight_Light( DrawPanel, DC ); -#endif } diff --git a/gerbview/edit.cpp b/gerbview/edit.cpp index 7290fe8948..461dbd596d 100644 --- a/gerbview/edit.cpp +++ b/gerbview/edit.cpp @@ -12,6 +12,7 @@ #include "gerbview.h" #include "pcbplot.h" #include "protos.h" +#include "kicad_device_context.h" /* Process the command triggered by the left button of the mouse when a tool @@ -61,7 +62,6 @@ void WinEDA_GerberFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) default: DisplayError( this, wxT( "WinEDA_GerberFrame::ProcessCommand error" ) ); - SetToolID( 0, wxCURSOR_ARROW, wxEmptyString ); break; } } @@ -75,7 +75,6 @@ void WinEDA_GerberFrame::Process_Special_Functions( wxCommandEvent& event ) int layer = GetScreen()->m_Active_Layer; GERBER* gerber_layer = g_GERBER_List[layer]; wxPoint pos; - KicadGraphicContext dc( DrawPanel ); wxGetMousePosition( &pos.x, &pos.y ); @@ -95,11 +94,7 @@ void WinEDA_GerberFrame::Process_Special_Functions( wxCommandEvent& event ) break; case ID_POPUP_CANCEL_CURRENT_COMMAND: - if( DrawPanel->ManageCurseur - && DrawPanel->ForceCloseManageCurseur ) - { - DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc ); - } + DrawPanel->UnManageCursor( ); /* Should not be executed, except bug */ if( GetScreen()->m_BlockLocate.m_Command != BLOCK_IDLE ) { @@ -114,15 +109,11 @@ void WinEDA_GerberFrame::Process_Special_Functions( wxCommandEvent& event ) break; default: - if( DrawPanel->ManageCurseur - && DrawPanel->ForceCloseManageCurseur ) - { - DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc ); - } - SetToolID( 0, wxCURSOR_ARROW, wxEmptyString ); + DrawPanel->UnManageCursor( 0, wxCURSOR_ARROW, wxEmptyString ); break; } + INSTALL_DC( dc, DrawPanel ); switch( id ) { case ID_EXIT: @@ -194,7 +185,7 @@ void WinEDA_GerberFrame::Process_Special_Functions( wxCommandEvent& event ) break; case ID_GERBVIEW_SHOW_LIST_DCODES: - Liste_D_Codes( &dc ); + Liste_D_Codes( ); break; case ID_GERBVIEW_SHOW_SOURCE: diff --git a/gerbview/initpcb.cpp b/gerbview/initpcb.cpp index ced25f38fa..8b22464b52 100644 --- a/gerbview/initpcb.cpp +++ b/gerbview/initpcb.cpp @@ -54,97 +54,6 @@ bool WinEDA_GerberFrame::Clear_Pcb( bool query ) } -void WinEDA_GerberFrame::Erase_Zones( bool query ) -{ - if( query && !IsOK( this, _( "Delete zones?" ) ) ) - return; - - GetBoard()->m_Zone.DeleteAll(); - - ScreenPcb->SetModify(); -} - - -void WinEDA_GerberFrame::Erase_Segments_Pcb( bool all_layers, bool query ) -{ - int layer = GetScreen()->m_Active_Layer; - - if( all_layers ) - layer = -1; - - BOARD_ITEM* next; - for( BOARD_ITEM* item = GetBoard()->m_Drawings; item; item = next ) - { - next = item->Next(); - - switch( item->Type() ) - { - case TYPE_DRAWSEGMENT: - case TYPE_TEXTE: - case TYPE_COTATION: - case TYPE_MIRE: - if( item->GetLayer() == layer || layer < 0 ) - GetBoard()->Delete( item ); - break; - - default: - DisplayError( this, wxT( "Draw type unknown." ) ); - break; - } - } - - ScreenPcb->SetModify(); -} - - -/* Delete track segments. - * masque_type mask options selection: - * SEGM_FIXE, SEGM_AR - * If a bit is 1, segment is not erased. - */ -void WinEDA_GerberFrame::Erase_Pistes( int masque_type, bool query ) -{ - TRACK* pt_segm; - BOARD_ITEM* PtNext; - - if( query && !IsOK( this, _( "Delete tracks?" ) ) ) - return; - - /* Mark tracks to clear. */ - for( pt_segm = GetBoard()->m_Track; - pt_segm != NULL; - pt_segm = (TRACK*) PtNext ) - { - PtNext = pt_segm->Next(); - if( pt_segm->GetState( SEGM_FIXE | SEGM_AR ) & masque_type ) - continue; - pt_segm->DeleteStructure(); - } - - ScreenPcb->SetModify(); -} - - -void WinEDA_GerberFrame::Erase_Textes_Pcb( bool query ) -{ - BOARD_ITEM* PtStruct; - BOARD_ITEM* PtNext; - - if( query && !IsOK( this, _( "Delete pcb text?" ) ) ) - return; - - PtStruct = GetBoard()->m_Drawings; - for( ; PtStruct != NULL; PtStruct = PtNext ) - { - PtNext = PtStruct->Next(); - if( PtStruct->Type() == TYPE_TEXTE ) - PtStruct->DeleteStructure(); - } - - ScreenPcb->SetModify(); -} - - void WinEDA_GerberFrame::Erase_Current_Layer( bool query ) { int layer = GetScreen()->m_Active_Layer; diff --git a/gerbview/wxGerberFrame.h b/gerbview/wxGerberFrame.h index c4944a1199..56301333e8 100644 --- a/gerbview/wxGerberFrame.h +++ b/gerbview/wxGerberFrame.h @@ -195,30 +195,15 @@ public: */ int Read_D_Code_File( const wxString& D_Code_FullFileName ); void CopyDCodesSizeToItems(); - void Liste_D_Codes( wxDC* DC ); + void Liste_D_Codes( ); void Trace_Gerber( wxDC* DC, int draw_mode, int printmasklayer ); - // Copper texts - void Rotate_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC ); - TEXTE_PCB* Create_Texte_Pcb( wxDC* DC ); - void Delete_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC ); - void StartMoveTextePcb( TEXTE_PCB* TextePcb, wxDC* DC ); - void Place_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC ); - // PCB handling bool Clear_Pcb( bool query ); void Erase_Current_Layer( bool query ); - void Erase_Zones( bool query ); - void Erase_Segments_Pcb( bool is_edges, bool query ); - void Erase_Pistes( int masque_type, bool query ); - void Erase_Textes_Pcb( bool query ); void Delete_DCode_Items( wxDC* DC, int dcode_value, int layer_number ); - - TRACK* Begin_Route( TRACK* track, wxDC* DC ); - void End_Route( TRACK* track, wxDC* DC ); - TRACK* Delete_Segment( wxDC* DC, TRACK* Track ); - int Edit_TrackSegm_Width( wxDC* DC, TRACK* segm ); + TRACK* Delete_Segment( wxDC* DC, TRACK* Track ); // Conversion function void ExportDataInPcbnewFormat( wxCommandEvent& event ); diff --git a/include/class_drawpanel.h b/include/class_drawpanel.h index aedf34b154..5d8a04a376 100644 --- a/include/class_drawpanel.h +++ b/include/class_drawpanel.h @@ -180,12 +180,4 @@ public: DECLARE_EVENT_TABLE() }; -// Helper class to handle the client Device Context -class KicadGraphicContext : public wxClientDC -{ -public: - KicadGraphicContext( WinEDA_DrawPanel * aDrawPanel ); - ~KicadGraphicContext(); -}; - #endif /* #ifndef PANEL_WXSTRUCT_H */ diff --git a/include/kicad_device_context.h b/include/kicad_device_context.h new file mode 100644 index 0000000000..0092418b80 --- /dev/null +++ b/include/kicad_device_context.h @@ -0,0 +1,37 @@ +/** + * a helper to handle the real device context used in kicad + * @file kicad_device_context.h + */ + +#ifndef __KICAD_DEVICE_CONTEXT_H__ +#define __KICAD_DEVICE_CONTEXT_H__ + +// Comment this line to use the standard wxClientDC +// and uncomment to use buffered DC +// #define KICAD_USE_BUFFERED_DC // Currently for tests + +#ifdef KICAD_USE_BUFFERED_DC +#include +#endif + +// Helper class to handle the client Device Context +class KicadGraphicContext : public wxClientDC +{ +public: + KicadGraphicContext( WinEDA_DrawPanel * aDrawPanel ); + ~KicadGraphicContext(); +}; + + +// Macro used to declare a device context in kicad: +#ifdef KICAD_USE_BUFFERED_DC + +#define INSTALL_DC(name,parent) \ +KicadGraphicContext _cDC( parent );\ +wxBufferedDC name(&_cDC, _cDC.GetSize() ); + +#else +#define INSTALL_DC(name,parent) KicadGraphicContext name( parent ); +#endif + +#endif // __KICAD_DEVICE_CONTEXT_H__ diff --git a/pcbnew/automove.cpp b/pcbnew/automove.cpp index 5c5e6a709b..9e9b87a307 100644 --- a/pcbnew/automove.cpp +++ b/pcbnew/automove.cpp @@ -15,6 +15,7 @@ #include "pcbnew_id.h" #include "protos.h" +#include "kicad_device_context.h" typedef enum { FIXE_MODULE, @@ -36,7 +37,7 @@ void WinEDA_PcbFrame::AutoPlace( wxCommandEvent& event ) { int id = event.GetId(); wxPoint pos; - KicadGraphicContext dc( DrawPanel ); + INSTALL_DC( dc, DrawPanel ); bool on_state; if( m_HToolBar == NULL ) @@ -59,12 +60,7 @@ void WinEDA_PcbFrame::AutoPlace( wxCommandEvent& event ) break; default: // Abort a current command (if any) - if( DrawPanel->ManageCurseur - && DrawPanel->ForceCloseManageCurseur ) - { - DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc ); - } - SetToolID( 0, wxCURSOR_ARROW, wxEmptyString ); + DrawPanel->UnManageCursor( 0, wxCURSOR_ARROW ); break; } diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index d55d53d31f..010635afe9 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -16,6 +16,8 @@ #include "autorout.h" #include "protos.h" +#include "kicad_device_context.h" + #include "dialog_global_edit_tracks_and_vias.h" // Uncomment following line to enable wxBell() command (which beeps speaker) @@ -32,7 +34,7 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event ) wxPoint pos; int itmp; - KicadGraphicContext dc( DrawPanel ); + INSTALL_DC( dc, DrawPanel ); BOARD_ITEM* DrawStruct = GetCurItem(); DrawPanel->CursorOff( &dc ); diff --git a/pcbnew/export_gencad.cpp b/pcbnew/export_gencad.cpp index 32abd33cd5..2d9eda86af 100644 --- a/pcbnew/export_gencad.cpp +++ b/pcbnew/export_gencad.cpp @@ -91,8 +91,7 @@ void WinEDA_PcbFrame::ExportToGenCAD( wxCommandEvent& event ) offsetX = m_Auxiliary_Axis_Position.x; offsetY = m_Auxiliary_Axis_Position.y; - KicadGraphicContext dc( DrawPanel ); - Compile_Ratsnest( &dc, TRUE ); + Compile_Ratsnest( NULL, TRUE ); /* Temporary modification of footprints that are flipped (i.e. on bottom * layer) to convert them to non flipped footprints. diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 36331dbc94..f5df47f7c4 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -17,23 +17,16 @@ void WinEDA_PcbFrame::OnFileHistory( wxCommandEvent& event ) { wxString fn; - KicadGraphicContext dc( DrawPanel ); fn = GetFileFromHistory( event.GetId(), _( "Printed circuit board" ) ); if( fn != wxEmptyString ) { - if( DrawPanel->ManageCurseur && DrawPanel->ForceCloseManageCurseur ) - { - DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc ); - } - - SetToolID( 0, wxCURSOR_ARROW, wxEmptyString ); + DrawPanel->UnManageCursor( 0, wxCURSOR_ARROW ); ::wxSetWorkingDirectory( ::wxPathOnly( fn ) ); LoadOnePcbFile( fn, false ); ReCreateAuxiliaryToolbar(); DrawPanel->MouseToCursorSchema(); - DrawPanel->CursorOn( &dc ); } } @@ -49,12 +42,7 @@ void WinEDA_PcbFrame::Files_io( wxCommandEvent& event ) // If an edition is in progress, stop it - if( DrawPanel->ManageCurseur && DrawPanel->ForceCloseManageCurseur ) - { - KicadGraphicContext dc( DrawPanel ); - DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc ); - } - SetToolID( 0, wxCURSOR_ARROW, wxEmptyString ); + DrawPanel->UnManageCursor( 0, wxCURSOR_ARROW ); switch( id ) { diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index 0e6a2bdcfc..cae9f4ec9e 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -17,6 +17,8 @@ #include "wxPcbStruct.h" #include "protos.h" +#include "kicad_device_context.h" + #include "dialog_edit_module_for_Modedit.h" #include "collectors.h" @@ -147,7 +149,7 @@ void WinEDA_ModuleEditFrame::Process_Special_Functions( wxCommandEvent& event ) wxPoint pos; bool redraw = false; - KicadGraphicContext dc( DrawPanel ); + INSTALL_DC( dc, DrawPanel ); wxGetMousePosition( &pos.x, &pos.y ); diff --git a/pcbnew/muwave_command.cpp b/pcbnew/muwave_command.cpp index aeb927fddd..7eeb425c38 100644 --- a/pcbnew/muwave_command.cpp +++ b/pcbnew/muwave_command.cpp @@ -10,6 +10,7 @@ #include "wxPcbStruct.h" #include "pcbnew_id.h" +#include "kicad_device_context.h" #include "protos.h" @@ -20,7 +21,7 @@ void WinEDA_PcbFrame::ProcessMuWaveFunctions( wxCommandEvent& event ) { int id = event.GetId(); wxPoint pos; - KicadGraphicContext dc( DrawPanel ); + INSTALL_DC( dc, DrawPanel ); wxGetMousePosition( &pos.x, &pos.y ); @@ -32,12 +33,7 @@ void WinEDA_PcbFrame::ProcessMuWaveFunctions( wxCommandEvent& event ) break; default: // End block command in progress. - if( DrawPanel->ManageCurseur - && DrawPanel->ForceCloseManageCurseur ) - { - DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc ); - } - SetToolID( 0, wxCURSOR_ARROW, wxEmptyString ); + DrawPanel->UnManageCursor( ); break; } diff --git a/pcbnew/surbrill.cpp b/pcbnew/surbrill.cpp index 987cb296c4..dcda3024ef 100644 --- a/pcbnew/surbrill.cpp +++ b/pcbnew/surbrill.cpp @@ -12,6 +12,8 @@ #include "wxPcbStruct.h" #include "collectors.h" +#include "kicad_device_context.h" + #define Pad_fill (Pad_Fill_Item.State == RUN) @@ -72,7 +74,7 @@ void WinEDA_PcbFrame::ListNetsAndSelect( wxCommandEvent& event ) if( found ) { - KicadGraphicContext dc( DrawPanel ); + INSTALL_DC( dc, DrawPanel ); if( g_HightLigt_Status ) Hight_Light( &dc );