From 79e2a4146987927a0abae6fc2f0dc68c894f87bc Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 19 Jan 2015 09:23:10 +0100 Subject: [PATCH] Pcbnew: Fix potential bug in DRAG_SEGM_PICKER (a variable type bool was used as int. type is now int). Minor code cleanup. --- pcbnew/autorouter/auto_place_footprints.cpp | 3 +- pcbnew/block.cpp | 2 +- pcbnew/class_module.cpp | 1 - pcbnew/class_module.h | 12 +++++++ pcbnew/drag.h | 6 ++-- pcbnew/dragsegm.cpp | 10 +++--- pcbnew/modules.cpp | 37 +++++++++------------ pcbnew/protos.h | 2 -- 8 files changed, 38 insertions(+), 35 deletions(-) diff --git a/pcbnew/autorouter/auto_place_footprints.cpp b/pcbnew/autorouter/auto_place_footprints.cpp index d3bd65ca3a..db39ee93ba 100644 --- a/pcbnew/autorouter/auto_place_footprints.cpp +++ b/pcbnew/autorouter/auto_place_footprints.cpp @@ -652,8 +652,7 @@ int getOptimalModulePlacement( PCB_EDIT_FRAME* aFrame, MODULE* aModule, wxDC* aD CurrPosition = initialPos; // Undraw the current footprint - g_Offset_Module = wxPoint( 0, 0 ); - DrawModuleOutlines( aFrame->GetCanvas(), aDC, aModule ); + aModule->DrawOutlinesWhenMoving( aFrame->GetCanvas(), aDC, wxPoint( 0, 0 ) ); g_Offset_Module = mod_pos - CurrPosition; diff --git a/pcbnew/block.cpp b/pcbnew/block.cpp index 71d6370056..cc4e9eaa4b 100644 --- a/pcbnew/block.cpp +++ b/pcbnew/block.cpp @@ -532,7 +532,7 @@ static void drawPickedItems( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint aOffset { case PCB_MODULE_T: frame->GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK; - DrawModuleOutlines( aPanel, aDC, (MODULE*) item ); + ((MODULE*) item)->DrawOutlinesWhenMoving( aPanel, aDC, g_Offset_Module ); break; case PCB_LINE_T: diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 523b019e56..ecf7c45caa 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -45,7 +45,6 @@ #include <3d_struct.h> #include -#include #include #include #include diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index 5b5ea39248..266b033e3f 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -280,6 +280,18 @@ public: GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset ); + /** + * Function DrawOutlinesWhenMoving + * draws in XOR mode the footprint when moving it to the \a aDC. + * To speed up the drawing, only a simplified shape is drawn + * @param aPanel = draw panel, Used to know the clip box + * @param aDC = Current Device Context + * @param aMoveVector = the offset between the curr position and + * the draw position. + */ + void DrawOutlinesWhenMoving( EDA_DRAW_PANEL* aPanel, + wxDC* aDC, const wxPoint& aMoveVector ); + /** * function ReadandInsert3DComponentShape * read the 3D component shape(s) of the footprint (physical shape) diff --git a/pcbnew/drag.h b/pcbnew/drag.h index 72a27ac34a..aac3c60862 100644 --- a/pcbnew/drag.h +++ b/pcbnew/drag.h @@ -49,10 +49,10 @@ class CONNECTIONS; /* * a DRAG_LIST manages the list of track segments to modify - * when the pad or the module is moving + * when the pad or the module is moving in drag mode */ -/* +/** * a DRAG_SEGM_PICKER manage one track segment or a via */ class DRAG_SEGM_PICKER @@ -65,7 +65,7 @@ public: D_PAD* m_Pad_End; // pointer to the moving pad // if the end point should follow this pad // or NULL - bool m_Flag; // flag used in drag vias and drag track segment functions + int m_TempFlags; // flag used in drag vias and drag track segment functions private: double m_RotationOffset; // initial orientation of the parent module diff --git a/pcbnew/dragsegm.cpp b/pcbnew/dragsegm.cpp index 82764600aa..fd1c718d8f 100644 --- a/pcbnew/dragsegm.cpp +++ b/pcbnew/dragsegm.cpp @@ -56,7 +56,7 @@ DRAG_SEGM_PICKER::DRAG_SEGM_PICKER( TRACK* aTrack ) m_endInitialValue = m_Track->GetEnd(); m_Pad_Start = m_Track->GetState( START_ON_PAD ) ? (D_PAD*)m_Track->start : NULL; m_Pad_End = m_Track->GetState( END_ON_PAD ) ? (D_PAD*)m_Track->end : NULL; - m_Flag = 0; + m_TempFlags = 0; m_RotationOffset = 0.0; m_Flipped = false; } @@ -320,10 +320,10 @@ void AddSegmentToDragList( int flag, TRACK* aTrack ) DRAG_SEGM_PICKER wrapper( aTrack ); if( flag & STARTPOINT ) - wrapper.m_Flag |= 1; + wrapper.m_TempFlags |= 1; if( flag & ENDPOINT ) - wrapper.m_Flag |= 2; + wrapper.m_TempFlags |= 2; if( flag & STARTPOINT ) aTrack->SetFlags( STARTPOINT ); @@ -411,10 +411,10 @@ void UndrawAndMarkSegmentsToDrag( EDA_DRAW_PANEL* aCanvas, wxDC* aDC ) track->SetState( IN_EDIT, false ); track->SetFlags( IS_DRAGGED ); - if( g_DragSegmentList[ii].m_Flag & STARTPOINT ) + if( g_DragSegmentList[ii].m_TempFlags & STARTPOINT ) track->SetFlags( STARTPOINT ); - if( g_DragSegmentList[ii].m_Flag & ENDPOINT ) + if( g_DragSegmentList[ii].m_TempFlags & ENDPOINT ) track->SetFlags( ENDPOINT ); track->Draw( aCanvas, aDC, GR_XOR ); diff --git a/pcbnew/modules.cpp b/pcbnew/modules.cpp index 0f7393cfa4..370ca3c9ae 100644 --- a/pcbnew/modules.cpp +++ b/pcbnew/modules.cpp @@ -24,7 +24,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/* +/** * @file modules.cpp */ @@ -40,7 +40,6 @@ #include #include -#include #include @@ -166,7 +165,7 @@ void Abort_MoveOrCopyModule( EDA_DRAW_PANEL* Panel, wxDC* DC ) if( module ) { // Erase the current footprint on screen - DrawModuleOutlines( Panel, DC, module ); + module->DrawOutlinesWhenMoving( Panel, DC, g_Offset_Module ); /* If a move command: return to old position * If a copy command, delete the new footprint @@ -239,12 +238,12 @@ void MoveFootprint( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, /* Erase current footprint. */ if( aErase ) { - DrawModuleOutlines( aPanel, aDC, module ); + module->DrawOutlinesWhenMoving( aPanel, aDC, g_Offset_Module ); } /* Redraw the module at the new position. */ g_Offset_Module = module->GetPosition() - aPanel->GetParent()->GetCrossHairPosition(); - DrawModuleOutlines( aPanel, aDC, module ); + module->DrawOutlinesWhenMoving( aPanel, aDC, g_Offset_Module ); DrawSegmentWhileMovingFootprint( aPanel, aDC ); } @@ -323,7 +322,7 @@ void PCB_EDIT_FRAME::Change_Side_Module( MODULE* Module, wxDC* DC ) /* Erase footprint and draw outline if it has been already drawn. */ if( DC ) { - DrawModuleOutlines( m_canvas, DC, Module ); + Module->DrawOutlinesWhenMoving( m_canvas, DC, g_Offset_Module ); DrawSegmentWhileMovingFootprint( m_canvas, DC ); } } @@ -347,7 +346,7 @@ void PCB_EDIT_FRAME::Change_Side_Module( MODULE* Module, wxDC* DC ) { if( DC ) { - DrawModuleOutlines( m_canvas, DC, Module ); + Module->DrawOutlinesWhenMoving( m_canvas, DC, g_Offset_Module ); DrawSegmentWhileMovingFootprint( m_canvas, DC ); } @@ -459,7 +458,7 @@ void PCB_BASE_FRAME::Rotate_Module( wxDC* DC, MODULE* module, double angle, bool { if( DC ) { - DrawModuleOutlines( m_canvas, DC, module ); + module->DrawOutlinesWhenMoving( m_canvas, DC, g_Offset_Module ); DrawSegmentWhileMovingFootprint( m_canvas, DC ); } } @@ -486,7 +485,7 @@ void PCB_BASE_FRAME::Rotate_Module( wxDC* DC, MODULE* module, double angle, bool else { // Beiing moved: just redraw it - DrawModuleOutlines( m_canvas, DC, module ); + module->DrawOutlinesWhenMoving( m_canvas, DC, g_Offset_Module ); DrawSegmentWhileMovingFootprint( m_canvas, DC ); } @@ -496,35 +495,31 @@ void PCB_BASE_FRAME::Rotate_Module( wxDC* DC, MODULE* module, double angle, bool } -/*************************************************/ -/* Redraw in XOR mode the outlines of a module. */ -/*************************************************/ -void DrawModuleOutlines( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* module ) +// Redraw in XOR mode the outlines of the module. +void MODULE::DrawOutlinesWhenMoving( EDA_DRAW_PANEL* panel, wxDC* DC, + const wxPoint& aMoveVector ) { int pad_fill_tmp; D_PAD* pt_pad; - if( module == NULL ) - return; - - module->DrawEdgesOnly( panel, DC, g_Offset_Module, GR_XOR ); + DrawEdgesOnly( panel, DC, aMoveVector, GR_XOR ); DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)panel->GetDisplayOptions(); // Show pads in sketch mode to speedu up drawings pad_fill_tmp = displ_opts->m_DisplayPadFill; displ_opts->m_DisplayPadFill = true; - pt_pad = module->Pads(); + pt_pad = Pads(); for( ; pt_pad != NULL; pt_pad = pt_pad->Next() ) - pt_pad->Draw( panel, DC, GR_XOR, g_Offset_Module ); + pt_pad->Draw( panel, DC, GR_XOR, aMoveVector ); displ_opts->m_DisplayPadFill = pad_fill_tmp; - if( displ_opts->m_Show_Module_Ratsnest && panel ) + if( displ_opts->m_Show_Module_Ratsnest ) { PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) panel->GetParent(); - frame->build_ratsnest_module( module ); + frame->build_ratsnest_module( this ); frame->TraceModuleRatsNest( DC ); } } diff --git a/pcbnew/protos.h b/pcbnew/protos.h index 3e981ad7f0..0dfb258e01 100644 --- a/pcbnew/protos.h +++ b/pcbnew/protos.h @@ -61,8 +61,6 @@ void DrawTraces( EDA_DRAW_PANEL* panel, int nbsegment, GR_DRAWMODE mode_color ); -void DrawModuleOutlines( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* module ); - void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase );