From 81228460784c02bd37b19d554fd22740df0e56fd Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 20 Nov 2013 18:26:47 +0100 Subject: [PATCH] Pcbnew: Code cleaning and some minor fixes. --- include/class_board_item.h | 11 ++++++++ pcbnew/board_undo_redo.cpp | 53 ++++++++++++++++++----------------- pcbnew/class_drawsegment.cpp | 1 - pcbnew/class_mire.cpp | 1 - pcbnew/class_pad.cpp | 1 - pcbnew/class_zone.cpp | 1 - pcbnew/edit_pcb_text.cpp | 10 +++---- pcbnew/printout_controler.cpp | 2 +- pcbnew/protos.h | 34 +++++----------------- pcbnew/target_edit.cpp | 5 ++-- 10 files changed, 53 insertions(+), 66 deletions(-) diff --git a/include/class_board_item.h b/include/class_board_item.h index 183aad9bb3..6f6bf201d6 100644 --- a/include/class_board_item.h +++ b/include/class_board_item.h @@ -130,6 +130,17 @@ public: virtual void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode, const wxPoint& offset = ZeroOffset ) = 0; + /** + * Swap data between aItem and aImage. + * aItem and aImage should have the same type + * Used in undo redo command to swap values between an item and its copy + * Only values like layer, size .. which are modified by edition are swapped, + * not the pointers like + * Pnext and Pback because aItem is not changed in the linked list + * @param aImage = the item image which contains data to swap + */ + void SwapData( BOARD_ITEM* aImage ); + /** * Function IsOnLayer * tests to see if this object is on the given layer. Is virtual so diff --git a/pcbnew/board_undo_redo.cpp b/pcbnew/board_undo_redo.cpp index ddf3933d1d..e58e734320 100644 --- a/pcbnew/board_undo_redo.cpp +++ b/pcbnew/board_undo_redo.cpp @@ -174,32 +174,23 @@ static bool TestForExistingItem( BOARD* aPcb, BOARD_ITEM* aItem ) } -void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) +void BOARD_ITEM::SwapData( BOARD_ITEM* aImage ) { - if( aItem == NULL || aImage == NULL ) + if( aImage == NULL ) { - wxMessageBox( wxT( "SwapData error: NULL pointer" ) ); return; } - // Swap layers: - if( aItem->Type() != PCB_MODULE_T && aItem->Type() != PCB_ZONE_AREA_T ) - { - // These items have a global swap function. - LAYER_NUM layer, layerimg; - layer = aItem->GetLayer(); - layerimg = aImage->GetLayer(); - aItem->SetLayer( layerimg ); - aImage->SetLayer( layer ); - } + EDA_ITEM * pnext = Next(); + EDA_ITEM * pback = Back(); - switch( aItem->Type() ) + switch( Type() ) { case PCB_MODULE_T: { MODULE* tmp = (MODULE*) aImage->Clone(); - ( (MODULE*) aImage )->Copy( (MODULE*) aItem ); - ( (MODULE*) aItem )->Copy( tmp ); + ( (MODULE*) aImage )->Copy( (MODULE*) this ); + ( (MODULE*) this )->Copy( tmp ); delete tmp; } break; @@ -207,22 +198,24 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) case PCB_ZONE_AREA_T: { ZONE_CONTAINER* tmp = (ZONE_CONTAINER*) aImage->Clone(); - ( (ZONE_CONTAINER*) aImage )->Copy( (ZONE_CONTAINER*) aItem ); - ( (ZONE_CONTAINER*) aItem )->Copy( tmp ); + ( (ZONE_CONTAINER*) aImage )->Copy( (ZONE_CONTAINER*) this ); + ( (ZONE_CONTAINER*) this )->Copy( tmp ); delete tmp; } break; case PCB_LINE_T: - std::swap( *((DRAWSEGMENT*)aItem), *((DRAWSEGMENT*)aImage) ); + std::swap( *((DRAWSEGMENT*)this), *((DRAWSEGMENT*)aImage) ); break; case PCB_TRACE_T: case PCB_VIA_T: { - TRACK* track = (TRACK*) aItem; + TRACK* track = (TRACK*) this; TRACK* image = (TRACK*) aImage; + EXCHG(track->m_Layer, image->m_Layer ); + // swap start, end, width and shape for track and image. wxPoint exchp = track->GetStart(); track->SetStart( image->GetStart() ); @@ -263,22 +256,32 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) break; case PCB_TEXT_T: - std::swap( *((TEXTE_PCB*)aItem), *((TEXTE_PCB*)aImage) ); + std::swap( *((TEXTE_PCB*)this), *((TEXTE_PCB*)aImage) ); break; case PCB_TARGET_T: - std::swap( *((PCB_TARGET*)aItem), *((PCB_TARGET*)aImage) ); + std::swap( *((PCB_TARGET*)this), *((PCB_TARGET*)aImage) ); break; case PCB_DIMENSION_T: - std::swap( *((DIMENSION*)aItem), *((DIMENSION*)aImage) ); + std::swap( *((DIMENSION*)this), *((DIMENSION*)aImage) ); break; case PCB_ZONE_T: default: - wxMessageBox( wxT( "SwapData() error: unexpected type" ) ); + wxLogMessage( wxT( "SwapData() error: unexpected type %d" ), Type() ); break; } + + if( pnext != Next() || pback != Back() ) + { + Pnext = pnext; + Pback = pback; +#ifdef DEBUG + wxLogMessage( wxT( "SwapData Error: %s Pnext or Pback pointers modified" ), + GetClass().GetData() ); +#endif + } } @@ -481,7 +484,7 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed case UR_CHANGED: /* Exchange old and new data for each item */ { BOARD_ITEM* image = (BOARD_ITEM*) aList->GetPickedItemLink( ii ); - SwapData( item, image ); + item->SwapData( image ); } break; diff --git a/pcbnew/class_drawsegment.cpp b/pcbnew/class_drawsegment.cpp index 62126b2fca..2efafc6fac 100644 --- a/pcbnew/class_drawsegment.cpp +++ b/pcbnew/class_drawsegment.cpp @@ -44,7 +44,6 @@ #include #include -#include #include #include diff --git a/pcbnew/class_mire.cpp b/pcbnew/class_mire.cpp index d2c6845b94..e7f7fc03a1 100644 --- a/pcbnew/class_mire.cpp +++ b/pcbnew/class_mire.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include #include diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index 1f223e2335..9e9180dbad 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index 94f19b8484..6442301da4 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -41,7 +41,6 @@ #include #include -#include #include #include diff --git a/pcbnew/edit_pcb_text.cpp b/pcbnew/edit_pcb_text.cpp index 7c518322e4..e4ecfcb5a2 100644 --- a/pcbnew/edit_pcb_text.cpp +++ b/pcbnew/edit_pcb_text.cpp @@ -37,8 +37,7 @@ #include #include - -#include +#include static void Move_Texte_Pcb( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, @@ -54,7 +53,6 @@ static TEXTE_PCB s_TextCopy( (BOARD_ITEM*) NULL ); /* copy of the edited text /* * Abort current text edit progress. - * * If a text is selected, its initial coord are regenerated */ void Abort_Edit_Pcb_Text( EDA_DRAW_PANEL* Panel, wxDC* DC ) @@ -78,7 +76,7 @@ void Abort_Edit_Pcb_Text( EDA_DRAW_PANEL* Panel, wxDC* DC ) } - SwapData( TextePcb, &s_TextCopy ); + TextePcb->SwapData( &s_TextCopy ); TextePcb->ClearFlags(); #ifndef USE_WX_OVERLAY TextePcb->Draw( Panel, DC, GR_OR ); @@ -117,11 +115,11 @@ void PCB_EDIT_FRAME::Place_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC ) else { // Restore initial params - SwapData( TextePcb, &s_TextCopy ); + TextePcb->SwapData( &s_TextCopy ); // Prepare undo command SaveCopyInUndoList( TextePcb, UR_CHANGED ); - SwapData( TextePcb, &s_TextCopy ); // Restore current params + TextePcb->SwapData( &s_TextCopy ); } TextePcb->ClearFlags(); diff --git a/pcbnew/printout_controler.cpp b/pcbnew/printout_controler.cpp index 755142e107..7be6b40d3c 100644 --- a/pcbnew/printout_controler.cpp +++ b/pcbnew/printout_controler.cpp @@ -327,7 +327,7 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage() wxLogTrace( tracePrinting, wxT( "Logical origin: x=%d, y=%d" ), offset.x, offset.y ); -#if defined(wxUSE_LOG_TRACE) +#if defined(wxUSE_LOG_TRACE) && defined( DEBUG ) wxRect paperRect = GetPaperRectPixels(); wxLogTrace( tracePrinting, wxT( "Paper rectangle: left=%d, top=%d, " "right=%d, bottom=%d" ), diff --git a/pcbnew/protos.h b/pcbnew/protos.h index b469212b7b..5c4fd5e9c1 100644 --- a/pcbnew/protos.h +++ b/pcbnew/protos.h @@ -37,18 +37,6 @@ class BOARD_ITEM; class TRACK; class MODULE; -/** - * Function SwapData - * Used in undo / redo command: - * swap data between Item and a copy - * swapped data is data modified by edition, mainly sizes and texts - * so ONLY FEW values are swapped - * @param aItem = the item - * @param aImage = a copy of the item - */ -void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ); - - /***************/ /* TRPISTE.CPP */ @@ -72,19 +60,8 @@ void DrawTraces( EDA_DRAW_PANEL* panel, int nbsegment, GR_DRAWMODE mode_color ); -/*************/ -/* MODULES.C */ -/*************/ - void DrawModuleOutlines( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* module ); - -/****************/ -/* EDITRACK.C : */ -/****************/ - -TRACK* LocateIntrusion( TRACK* listStart, TRACK* aTrack, LAYER_NUM aLayer, const wxPoint& aRef ); - void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ); @@ -94,12 +71,15 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPo */ void CalculateSegmentEndPoint( const wxPoint& aPosition, int ox, int oy, int* fx, int* fy ); - -/****************/ -/* CONTROLE.CPP */ -/****************/ void RemoteCommand( const char* cmdline ); + +/** + * Finds the projection of a grid point on a track. This is the point + * from where we want to draw new orthogonal tracks when starting on a track. + */ bool Project( wxPoint* res, wxPoint on_grid, const TRACK* track ); +TRACK* LocateIntrusion( TRACK* listStart, TRACK* aTrack, LAYER_NUM aLayer, const wxPoint& aRef ); + #endif /* #define PROTO_H */ diff --git a/pcbnew/target_edit.cpp b/pcbnew/target_edit.cpp index e5e8d8e10e..dba25a86d2 100644 --- a/pcbnew/target_edit.cpp +++ b/pcbnew/target_edit.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include @@ -258,9 +257,9 @@ void PCB_EDIT_FRAME::PlaceTarget( PCB_TARGET* aTarget, wxDC* DC ) if( (aTarget->GetFlags() & IN_EDIT) ) { - SwapData( aTarget, &s_TargetCopy ); + aTarget->SwapData( &s_TargetCopy ); SaveCopyInUndoList( aTarget, UR_CHANGED ); - SwapData( aTarget, &s_TargetCopy ); + aTarget->SwapData( &s_TargetCopy ); } aTarget->ClearFlags();