code cleaning

This commit is contained in:
charras 2009-12-19 16:10:25 +00:00
parent b808fcf4a2
commit 96849d5a11
25 changed files with 75 additions and 129 deletions

View File

@ -39,9 +39,7 @@ void WinEDA_DrawFrame::CopyToClipboard( wxCommandEvent& event )
if( DrawPanel->ManageCurseur && DrawPanel->ForceCloseManageCurseur )
{
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
KicadGraphicContext dc( DrawPanel );
DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc );
}
}

View File

@ -340,9 +340,7 @@ void WinEDA_DrawFrame::ReDrawPanel()
if( DrawPanel == NULL )
return;
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
KicadGraphicContext dc( DrawPanel );
DrawPanel->ReDraw( &dc );
}
@ -599,9 +597,8 @@ void WinEDA_DrawFrame::AdjustScrollBars()
int x, y, scroll_x, scroll_y;
double scale_x, scale_y;
wxClientDC DC( this );
DrawPanel DC( this );
DrawPanel->PrepareGraphicContext( &DC );
x = DC.LogicalToDeviceXRel( draw_size.GetWidth() );
y = DC.LogicalToDeviceYRel( draw_size.GetHeight() );

View File

@ -16,6 +16,26 @@
#define CURSOR_SIZE 12 // Cursor size in pixels
// Helper class to handle the client Device Context
KicadGraphicContext::KicadGraphicContext( WinEDA_DrawPanel * aDrawPanel )
: wxClientDC(aDrawPanel)
{
GRResetPenAndBrush( this );
SetBackgroundMode( wxTRANSPARENT );
#ifdef WX_ZOOM
double scale = aDrawPanel->GetScreen()->GetScalingFactor();
SetUserScale( scale, scale );
wxPoint origin = aDrawPanel->GetScreen()->m_DrawOrg;
SetLogicalOrigin( origin.x, origin.y );
#endif
aDrawPanel->SetBoundaryBox();
}
KicadGraphicContext::~KicadGraphicContext( )
{
}
/* Used to inhibit a response to a mouse left button release, after a
* double click (when releasing the left button at the end of the second
* click. Used in eeschema to inhibit a mouse left release command when
@ -172,19 +192,6 @@ wxRealPoint WinEDA_DrawPanel::GetGrid()
}
void WinEDA_DrawPanel::PrepareGraphicContext( wxDC* DC )
{
GRResetPenAndBrush( DC );
DC->SetBackgroundMode( wxTRANSPARENT );
#ifdef WX_ZOOM
double scale = GetScreen()->GetScalingFactor();
DC->SetUserScale( scale, scale );
wxPoint origin = GetScreen()->m_DrawOrg;
DC->SetLogicalOrigin( origin.x, origin.y );
#endif
SetBoundaryBox();
}
/** Calculate the cursor position in internal units.
* @return position (in internal units)
@ -194,8 +201,8 @@ wxPoint WinEDA_DrawPanel::CursorRealPosition( const wxPoint& ScreenPos )
{
#ifdef WX_ZOOM
wxCoord x, y;
wxClientDC DC( this );
PrepareGraphicContext( &DC );
KicadGraphicContext DC( this );
x = DC.DeviceToLogicalX( ScreenPos.x );
y = DC.DeviceToLogicalY( ScreenPos.y );
return wxPoint( x, y );
@ -304,8 +311,8 @@ wxPoint WinEDA_DrawPanel::CursorScreenPosition()
{
#ifdef WX_ZOOM
wxCoord x, y;
wxClientDC DC( this );
PrepareGraphicContext( &DC );
KicadGraphicContext DC( this );
x = DC.LogicalToDeviceX( GetScreen()->m_Curseur.x );
y = DC.LogicalToDeviceY( GetScreen()->m_Curseur.y );
return wxPoint( x, y );
@ -332,8 +339,7 @@ wxPoint WinEDA_DrawPanel::GetScreenCenterRealPosition( void )
GetScreen()->Unscale( realpos );
#ifdef WX_ZOOM
// wxCoord x, y;
// wxClientDC DC( this );
// PrepareGraphicContext( &DC );
// KicadGraphicContext DC( this );
// realpos.x = DC.DeviceToLogicalX( realpos.x );
// realpos.y = DC.DeviceToLogicalY( realpos.y );
#else
@ -567,7 +573,6 @@ void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event )
wxRect PaintClipBox;
wxPoint org;
PrepareGraphicContext( &paintDC );
tmp = m_ClipBox;
org = m_ClipBox.GetOrigin();
@ -1010,11 +1015,11 @@ void WinEDA_DrawPanel::OnMouseEvent( wxMouseEvent& event )
screen->m_MousePosition =
CursorRealPosition( screen->m_MousePositionInPixels );
wxClientDC DC( this );
KicadGraphicContext DC( this );
int kbstat = 0;
DC.SetBackground( *wxBLACK_BRUSH );
PrepareGraphicContext( &DC );
g_KeyPressed = localkey;
@ -1259,10 +1264,10 @@ void WinEDA_DrawPanel::OnKeyEvent( wxKeyEvent& event )
if( event.ShiftDown() && (key > 256) )
localkey |= GR_KB_SHIFT;
wxClientDC DC( this );
KicadGraphicContext DC( this );
BASE_SCREEN* Screen = GetScreen();
PrepareGraphicContext( &DC );
g_KeyPressed = localkey;

View File

@ -722,8 +722,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event )
if( entry == NULL )
return;
wxClientDC dc( m_Parent->DrawPanel );
m_Parent->DrawPanel->PrepareGraphicContext( &dc );
KicadGraphicContext dc( m_Parent->DrawPanel );
RedrawOneStruct( m_Parent->DrawPanel, &dc, m_Cmp, g_XorMode );

View File

@ -179,9 +179,7 @@ SCH_ITEM* WinEDA_SchematicFrame::FindComponentAndItem(
Recadre_Trace( mouseWarp );
else
{
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
KicadGraphicContext dc( DrawPanel );
EXCHG( old_cursor_position, sheet->LastScreen()->m_Curseur );
DrawPanel->CursorOff( &dc );
@ -356,9 +354,7 @@ SCH_ITEM* WinEDA_SchematicFrame::FindMarker( int SearchType )
Recadre_Trace( TRUE );
else
{
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
KicadGraphicContext dc( DrawPanel );
EXCHG( old_cursor_position, sheet->LastScreen()->m_Curseur );
DrawPanel->CursorOff( &dc );
DrawPanel->MouseTo( curpos );
@ -581,9 +577,7 @@ SCH_ITEM* WinEDA_SchematicFrame::FindSchematicItem( const wxString& pattern,
Recadre_Trace( mouseWarp );
else
{
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
KicadGraphicContext dc( DrawPanel );
EXCHG( old_cursor_position, Sheet->LastScreen()->m_Curseur );
DrawPanel->CursorOff( &dc );

View File

@ -604,12 +604,10 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event )
int id = event.GetId();
wxPoint pos;
wxClientDC dc( DrawPanel );
KicadGraphicContext dc( DrawPanel );
DrawPanel->m_IgnoreMouseEvents = true;
DrawPanel->PrepareGraphicContext( &dc );
wxGetMousePosition( &pos.x, &pos.y );
pos.y += 20;

View File

@ -22,11 +22,9 @@ void WinEDA_SchematicFrame::Process_Special_Functions( wxCommandEvent& event )
{
int id = event.GetId();
wxPoint pos;
wxClientDC dc( DrawPanel );
KicadGraphicContext dc( DrawPanel );
SCH_SCREEN* screen = GetScreen();
DrawPanel->PrepareGraphicContext( &dc );
pos = wxGetMousePosition();
pos.y += 20;

View File

@ -72,13 +72,6 @@ void WinEDA_LibeditFrame::EditGraphicSymbol( wxDC* DC, LIB_DRAW_ITEM* DrawItem )
if( !( DrawItem->m_Flags & IS_NEW ) )
SaveCopyInUndoList( DrawItem->GetParent() );
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
DrawItem->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), -1, g_XorMode,
NULL, DefaultTransformMatrix );
if( m_drawSpecificUnit )
DrawItem->m_Unit = GetUnit();
else
@ -98,9 +91,6 @@ void WinEDA_LibeditFrame::EditGraphicSymbol( wxDC* DC, LIB_DRAW_ITEM* DrawItem )
component->GetDrawItemList().sort();
GetScreen()->SetModify();
DrawItem->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), -1, g_XorMode,
NULL, DefaultTransformMatrix );
DrawItem->DisplayInfo( this );
DrawPanel->Refresh();
}

View File

@ -287,9 +287,7 @@ void WinEDA_SchematicFrame::OnSelectOptionToolbar( wxCommandEvent& event )
return;
int id = event.GetId();
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
KicadGraphicContext dc( DrawPanel );
switch( id )
{

View File

@ -189,9 +189,6 @@ void WinEDA_ViewlibFrame::ViewOneLibraryContent( CMP_LIBRARY* Lib, int Flag )
int NumOfParts = 0;
CMP_LIB_ENTRY* LibEntry;
wxString CmpName;
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
if( Lib )
NumOfParts = Lib->GetCount();
@ -234,7 +231,7 @@ void WinEDA_ViewlibFrame::ViewOneLibraryContent( CMP_LIBRARY* Lib, int Flag )
m_entryName = CmpName;
DisplayLibInfos();
Zoom_Automatique( false );
RedrawActiveWindow( &dc, true );
DrawPanel->Refresh( );
if( m_CmpList )
{

View File

@ -75,9 +75,7 @@ void WinEDA_GerberFrame::Process_Special_Functions( wxCommandEvent& event )
int layer = GetScreen()->m_Active_Layer;
GERBER* gerber_layer = g_GERBER_List[layer];
wxPoint pos;
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
KicadGraphicContext dc( DrawPanel );
wxGetMousePosition( &pos.x, &pos.y );
@ -263,9 +261,6 @@ void WinEDA_GerberFrame::Process_Special_Functions( wxCommandEvent& event )
void WinEDA_GerberFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
{
EDA_BaseStruct* DrawStruct = GetScreen()->GetCurItem();
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
switch( m_ID_current_state )
{

View File

@ -75,7 +75,6 @@ public:
BASE_SCREEN* GetScreen();
void PrepareGraphicContext( wxDC* DC );
bool IsPointOnDisplay( wxPoint ref_pos );
void OnPaint( wxPaintEvent& event );
void OnSize( wxSizeEvent& event );
@ -181,5 +180,12 @@ 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 */

View File

@ -36,14 +36,12 @@ void WinEDA_PcbFrame::AutoPlace( wxCommandEvent& event )
{
int id = event.GetId();
wxPoint pos;
wxClientDC dc( DrawPanel );
KicadGraphicContext dc( DrawPanel );
bool on_state;
if( m_HToolBar == NULL )
return;
DrawPanel->PrepareGraphicContext( &dc );
wxGetMousePosition( &pos.x, &pos.y );
switch( id )

View File

@ -169,12 +169,8 @@ void WinEDA_PcbFrame::OnSelectOptionToolbar( wxCommandEvent& event )
case ID_TB_OPTIONS_SHOW_RATSNEST:
g_Show_Ratsnest = m_OptionsToolBar->GetToolState( id );
{
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
Ratsnest_On_Off( &dc );
RedrawActiveWindow( &dc, true );
}
Ratsnest_On_Off( NULL );
DrawPanel->Refresh( );
break;
case ID_TB_OPTIONS_SHOW_MODULE_RATSNEST:

View File

@ -32,8 +32,7 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event )
wxPoint pos;
int itmp;
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
KicadGraphicContext dc( DrawPanel );
BOARD_ITEM* DrawStruct = GetCurItem();
DrawPanel->CursorOff( &dc );

View File

@ -91,9 +91,7 @@ void WinEDA_PcbFrame::ExportToGenCAD( wxCommandEvent& event )
offsetX = m_Auxiliary_Axis_Position.x;
offsetY = m_Auxiliary_Axis_Position.y;
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
KicadGraphicContext dc( DrawPanel );
Compile_Ratsnest( &dc, TRUE );
/* Temporary modification of footprints that are flipped (i.e. on bottom

View File

@ -17,7 +17,7 @@
void WinEDA_PcbFrame::OnFileHistory( wxCommandEvent& event )
{
wxString fn;
wxClientDC dc( DrawPanel );
KicadGraphicContext dc( DrawPanel );
fn = GetFileFromHistory( event.GetId(), _( "Printed circuit board" ) );
@ -25,7 +25,6 @@ void WinEDA_PcbFrame::OnFileHistory( wxCommandEvent& event )
{
if( DrawPanel->ManageCurseur && DrawPanel->ForceCloseManageCurseur )
{
DrawPanel->PrepareGraphicContext( &dc );
DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc );
}
@ -52,8 +51,7 @@ void WinEDA_PcbFrame::Files_io( wxCommandEvent& event )
// If an edition is in progress, stop it
if( DrawPanel->ManageCurseur && DrawPanel->ForceCloseManageCurseur )
{
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
KicadGraphicContext dc( DrawPanel );
DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc );
}
SetToolID( 0, wxCURSOR_ARROW, wxEmptyString );

View File

@ -80,9 +80,8 @@ void DIALOG_GLOBAL_PADS_EDITION::OnCancelClick( wxCommandEvent& event )
*/
void DIALOG_GLOBAL_PADS_EDITION::InstallPadEditor( wxCommandEvent& event )
{
wxClientDC dc( m_Parent->DrawPanel );
KicadGraphicContext dc( m_Parent->DrawPanel );
m_Parent->DrawPanel->PrepareGraphicContext( &dc );
m_Parent->DrawPanel->CursorOff( &dc );
m_Parent->InstallPadOptionsFrame( m_CurrentPad, &dc, wxDefaultPosition );
m_Parent->DrawPanel->CursorOn( &dc );

View File

@ -147,9 +147,8 @@ void WinEDA_ModuleEditFrame::Process_Special_Functions( wxCommandEvent& event )
wxPoint pos;
bool redraw = false;
wxClientDC dc( DrawPanel );
KicadGraphicContext dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
wxGetMousePosition( &pos.x, &pos.y );
pos.y += 20;

View File

@ -382,9 +382,6 @@ void WinEDA_ModuleEditFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
{
BOARD_ITEM* DrawStruct = GetCurItem();
wxPoint pos = GetPosition();
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
switch( m_ID_current_state )
{
@ -403,7 +400,7 @@ void WinEDA_ModuleEditFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
switch( DrawStruct->Type() )
{
case TYPE_PAD:
InstallPadOptionsFrame( (D_PAD*) DrawStruct, &dc, pos );
InstallPadOptionsFrame( (D_PAD*) DrawStruct, DC, pos );
DrawPanel->MouseToCursorSchema();
break;
@ -420,7 +417,7 @@ void WinEDA_ModuleEditFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
break;
case TYPE_TEXTE_MODULE:
InstallTextModOptionsFrame( (TEXTE_MODULE*) DrawStruct, &dc );
InstallTextModOptionsFrame( (TEXTE_MODULE*) DrawStruct, DC );
DrawPanel->MouseToCursorSchema();
break;

View File

@ -18,15 +18,12 @@
void WinEDA_ModuleEditFrame::OnSelectOptionToolbar( wxCommandEvent& event )
{
int id = event.GetId();
wxClientDC dc( DrawPanel );
DrawPanel->CursorOff( &dc );
DrawPanel->PrepareGraphicContext( &dc );
switch( id )
{
case ID_TB_OPTIONS_SHOW_GRID:
m_Draw_Grid = m_OptionsToolBar->GetToolState( id );
DrawPanel->ReDraw( &dc, TRUE );
DrawPanel->Refresh( );
break;
case ID_TB_OPTIONS_SELECT_UNIT_MM:
@ -51,24 +48,24 @@ void WinEDA_ModuleEditFrame::OnSelectOptionToolbar( wxCommandEvent& event )
case ID_TB_OPTIONS_SHOW_PADS_SKETCH:
m_DisplayPadFill = !m_OptionsToolBar->GetToolState( id );
DrawPanel->ReDraw( &dc, TRUE );
DrawPanel->Refresh( );
break;
case ID_TB_OPTIONS_SHOW_VIAS_SKETCH:
m_DisplayViaFill = !m_OptionsToolBar->GetToolState( id );
DrawPanel->ReDraw( &dc, TRUE );
DrawPanel->Refresh( );
break;
case ID_TB_OPTIONS_SHOW_MODULE_TEXT_SKETCH:
m_DisplayModText =
m_OptionsToolBar->GetToolState( id ) ? SKETCH : FILLED;
DrawPanel->ReDraw( &dc, TRUE );
DrawPanel->Refresh( );
break;
case ID_TB_OPTIONS_SHOW_MODULE_EDGE_SKETCH:
m_DisplayModEdge =
m_OptionsToolBar->GetToolState( id ) ? SKETCH : FILLED;
DrawPanel->ReDraw( &dc, TRUE );
DrawPanel->Refresh( );
break;
default:
@ -78,5 +75,4 @@ void WinEDA_ModuleEditFrame::OnSelectOptionToolbar( wxCommandEvent& event )
}
SetToolbars();
DrawPanel->CursorOn( &dc );
}

View File

@ -20,9 +20,7 @@ void WinEDA_PcbFrame::ProcessMuWaveFunctions( wxCommandEvent& event )
{
int id = event.GetId();
wxPoint pos;
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
KicadGraphicContext dc( DrawPanel );
wxGetMousePosition( &pos.x, &pos.y );

View File

@ -388,9 +388,6 @@ void WinEDA_PcbFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
{
BOARD_ITEM* DrawStruct = GetCurItem();
wxPoint pos = GetPosition();
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
switch( m_ID_current_state )
{
@ -429,38 +426,38 @@ void WinEDA_PcbFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
break;
case TYPE_PAD:
InstallPadOptionsFrame( (D_PAD*) DrawStruct, &dc, pos );
InstallPadOptionsFrame( (D_PAD*) DrawStruct, DC, pos );
DrawPanel->MouseToCursorSchema();
break;
case TYPE_MODULE:
InstallModuleOptionsFrame( (MODULE*) DrawStruct, &dc );
InstallModuleOptionsFrame( (MODULE*) DrawStruct, DC );
DrawPanel->MouseToCursorSchema();
break;
case TYPE_MIRE:
InstallMireOptionsFrame( (MIREPCB*) DrawStruct, &dc, pos );
InstallMireOptionsFrame( (MIREPCB*) DrawStruct, DC, pos );
DrawPanel->MouseToCursorSchema();
break;
case TYPE_COTATION:
Install_Edit_Cotation( (COTATION*) DrawStruct, &dc, pos );
Install_Edit_Cotation( (COTATION*) DrawStruct, DC, pos );
DrawPanel->MouseToCursorSchema();
break;
case TYPE_TEXTE_MODULE:
InstallTextModOptionsFrame( (TEXTE_MODULE*) DrawStruct, &dc );
InstallTextModOptionsFrame( (TEXTE_MODULE*) DrawStruct, DC );
DrawPanel->MouseToCursorSchema();
break;
case TYPE_DRAWSEGMENT:
InstallGraphicItemPropertiesDialog( (DRAWSEGMENT*) DrawStruct, &dc );
InstallGraphicItemPropertiesDialog( (DRAWSEGMENT*) DrawStruct, DC );
break;
case TYPE_ZONE_CONTAINER:
if( DrawStruct->m_Flags )
break;
Edit_Zone_Params( &dc, (ZONE_CONTAINER*) DrawStruct );
Edit_Zone_Params( DC, (ZONE_CONTAINER*) DrawStruct );
break;
default:
@ -498,7 +495,7 @@ void WinEDA_PcbFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
}
if( (DrawStruct->m_Flags & IS_NEW) )
{
End_Edge( (DRAWSEGMENT*) DrawStruct, &dc );
End_Edge( (DRAWSEGMENT*) DrawStruct, DC );
DrawPanel->m_AutoPAN_Request = false;
SetCurItem( NULL );
}

View File

@ -30,12 +30,10 @@ void WinEDA_PcbFrame::Process_Config( wxCommandEvent& event )
int id = event.GetId();
wxPoint pos;
wxClientDC dc( DrawPanel );
KicadGraphicContext dc( DrawPanel );
wxFileName fn;
DrawPanel->PrepareGraphicContext( &dc );
pos = GetPosition();
pos.x += 20;
pos.y += 20;

View File

@ -72,9 +72,7 @@ void WinEDA_PcbFrame::ListNetsAndSelect( wxCommandEvent& event )
if( found )
{
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
KicadGraphicContext dc( DrawPanel );
if( g_HightLigt_Status )
Hight_Light( &dc );