Commit 44bb2e6d authored by jean-pierre charras's avatar jean-pierre charras

Pcbnew: Code cleaning and some minor fixes.

parent d0c50d56
...@@ -130,6 +130,17 @@ public: ...@@ -130,6 +130,17 @@ public:
virtual void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, virtual void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
GR_DRAWMODE aDrawMode, const wxPoint& offset = ZeroOffset ) = 0; 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 * Function IsOnLayer
* tests to see if this object is on the given layer. Is virtual so * tests to see if this object is on the given layer. Is virtual so
......
...@@ -174,32 +174,23 @@ static bool TestForExistingItem( BOARD* aPcb, BOARD_ITEM* aItem ) ...@@ -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; return;
} }
// Swap layers: EDA_ITEM * pnext = Next();
if( aItem->Type() != PCB_MODULE_T && aItem->Type() != PCB_ZONE_AREA_T ) EDA_ITEM * pback = Back();
{
// These items have a global swap function.
LAYER_NUM layer, layerimg;
layer = aItem->GetLayer();
layerimg = aImage->GetLayer();
aItem->SetLayer( layerimg );
aImage->SetLayer( layer );
}
switch( aItem->Type() ) switch( Type() )
{ {
case PCB_MODULE_T: case PCB_MODULE_T:
{ {
MODULE* tmp = (MODULE*) aImage->Clone(); MODULE* tmp = (MODULE*) aImage->Clone();
( (MODULE*) aImage )->Copy( (MODULE*) aItem ); ( (MODULE*) aImage )->Copy( (MODULE*) this );
( (MODULE*) aItem )->Copy( tmp ); ( (MODULE*) this )->Copy( tmp );
delete tmp; delete tmp;
} }
break; break;
...@@ -207,22 +198,24 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) ...@@ -207,22 +198,24 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage )
case PCB_ZONE_AREA_T: case PCB_ZONE_AREA_T:
{ {
ZONE_CONTAINER* tmp = (ZONE_CONTAINER*) aImage->Clone(); ZONE_CONTAINER* tmp = (ZONE_CONTAINER*) aImage->Clone();
( (ZONE_CONTAINER*) aImage )->Copy( (ZONE_CONTAINER*) aItem ); ( (ZONE_CONTAINER*) aImage )->Copy( (ZONE_CONTAINER*) this );
( (ZONE_CONTAINER*) aItem )->Copy( tmp ); ( (ZONE_CONTAINER*) this )->Copy( tmp );
delete tmp; delete tmp;
} }
break; break;
case PCB_LINE_T: case PCB_LINE_T:
std::swap( *((DRAWSEGMENT*)aItem), *((DRAWSEGMENT*)aImage) ); std::swap( *((DRAWSEGMENT*)this), *((DRAWSEGMENT*)aImage) );
break; break;
case PCB_TRACE_T: case PCB_TRACE_T:
case PCB_VIA_T: case PCB_VIA_T:
{ {
TRACK* track = (TRACK*) aItem; TRACK* track = (TRACK*) this;
TRACK* image = (TRACK*) aImage; TRACK* image = (TRACK*) aImage;
EXCHG(track->m_Layer, image->m_Layer );
// swap start, end, width and shape for track and image. // swap start, end, width and shape for track and image.
wxPoint exchp = track->GetStart(); wxPoint exchp = track->GetStart();
track->SetStart( image->GetStart() ); track->SetStart( image->GetStart() );
...@@ -263,22 +256,32 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) ...@@ -263,22 +256,32 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage )
break; break;
case PCB_TEXT_T: case PCB_TEXT_T:
std::swap( *((TEXTE_PCB*)aItem), *((TEXTE_PCB*)aImage) ); std::swap( *((TEXTE_PCB*)this), *((TEXTE_PCB*)aImage) );
break; break;
case PCB_TARGET_T: case PCB_TARGET_T:
std::swap( *((PCB_TARGET*)aItem), *((PCB_TARGET*)aImage) ); std::swap( *((PCB_TARGET*)this), *((PCB_TARGET*)aImage) );
break; break;
case PCB_DIMENSION_T: case PCB_DIMENSION_T:
std::swap( *((DIMENSION*)aItem), *((DIMENSION*)aImage) ); std::swap( *((DIMENSION*)this), *((DIMENSION*)aImage) );
break; break;
case PCB_ZONE_T: case PCB_ZONE_T:
default: default:
wxMessageBox( wxT( "SwapData() error: unexpected type" ) ); wxLogMessage( wxT( "SwapData() error: unexpected type %d" ), Type() );
break; 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 ...@@ -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 */ case UR_CHANGED: /* Exchange old and new data for each item */
{ {
BOARD_ITEM* image = (BOARD_ITEM*) aList->GetPickedItemLink( ii ); BOARD_ITEM* image = (BOARD_ITEM*) aList->GetPickedItemLink( ii );
SwapData( item, image ); item->SwapData( image );
} }
break; break;
......
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
#include <msgpanel.h> #include <msgpanel.h>
#include <pcbnew.h> #include <pcbnew.h>
#include <protos.h>
#include <math_for_graphics.h> #include <math_for_graphics.h>
#include <class_board.h> #include <class_board.h>
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include <colors_selection.h> #include <colors_selection.h>
#include <trigo.h> #include <trigo.h>
#include <macros.h> #include <macros.h>
#include <protos.h>
#include <richio.h> #include <richio.h>
#include <class_board.h> #include <class_board.h>
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include <confirm.h> #include <confirm.h>
#include <kicad_string.h> #include <kicad_string.h>
#include <trigo.h> #include <trigo.h>
#include <protos.h>
#include <richio.h> #include <richio.h>
#include <wxstruct.h> #include <wxstruct.h>
#include <macros.h> #include <macros.h>
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
#include <wxBasePcbFrame.h> #include <wxBasePcbFrame.h>
#include <msgpanel.h> #include <msgpanel.h>
#include <protos.h>
#include <class_board.h> #include <class_board.h>
#include <class_zone.h> #include <class_zone.h>
......
...@@ -37,8 +37,7 @@ ...@@ -37,8 +37,7 @@
#include <class_board.h> #include <class_board.h>
#include <class_pcb_text.h> #include <class_pcb_text.h>
#include <class_board_item.h>
#include <protos.h>
static void Move_Texte_Pcb( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, 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 ...@@ -54,7 +53,6 @@ static TEXTE_PCB s_TextCopy( (BOARD_ITEM*) NULL ); /* copy of the edited text
/* /*
* Abort current text edit progress. * Abort current text edit progress.
*
* If a text is selected, its initial coord are regenerated * If a text is selected, its initial coord are regenerated
*/ */
void Abort_Edit_Pcb_Text( EDA_DRAW_PANEL* Panel, wxDC* DC ) 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 ) ...@@ -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(); TextePcb->ClearFlags();
#ifndef USE_WX_OVERLAY #ifndef USE_WX_OVERLAY
TextePcb->Draw( Panel, DC, GR_OR ); TextePcb->Draw( Panel, DC, GR_OR );
...@@ -117,11 +115,11 @@ void PCB_EDIT_FRAME::Place_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC ) ...@@ -117,11 +115,11 @@ void PCB_EDIT_FRAME::Place_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC )
else else
{ {
// Restore initial params // Restore initial params
SwapData( TextePcb, &s_TextCopy ); TextePcb->SwapData( &s_TextCopy );
// Prepare undo command // Prepare undo command
SaveCopyInUndoList( TextePcb, UR_CHANGED ); SaveCopyInUndoList( TextePcb, UR_CHANGED );
SwapData( TextePcb, &s_TextCopy );
// Restore current params // Restore current params
TextePcb->SwapData( &s_TextCopy );
} }
TextePcb->ClearFlags(); TextePcb->ClearFlags();
......
...@@ -327,7 +327,7 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage() ...@@ -327,7 +327,7 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage()
wxLogTrace( tracePrinting, wxT( "Logical origin: x=%d, y=%d" ), wxLogTrace( tracePrinting, wxT( "Logical origin: x=%d, y=%d" ),
offset.x, offset.y ); offset.x, offset.y );
#if defined(wxUSE_LOG_TRACE) #if defined(wxUSE_LOG_TRACE) && defined( DEBUG )
wxRect paperRect = GetPaperRectPixels(); wxRect paperRect = GetPaperRectPixels();
wxLogTrace( tracePrinting, wxT( "Paper rectangle: left=%d, top=%d, " wxLogTrace( tracePrinting, wxT( "Paper rectangle: left=%d, top=%d, "
"right=%d, bottom=%d" ), "right=%d, bottom=%d" ),
......
...@@ -37,18 +37,6 @@ class BOARD_ITEM; ...@@ -37,18 +37,6 @@ class BOARD_ITEM;
class TRACK; class TRACK;
class MODULE; 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 */ /* TRPISTE.CPP */
...@@ -72,19 +60,8 @@ void DrawTraces( EDA_DRAW_PANEL* panel, ...@@ -72,19 +60,8 @@ void DrawTraces( EDA_DRAW_PANEL* panel,
int nbsegment, int nbsegment,
GR_DRAWMODE mode_color ); GR_DRAWMODE mode_color );
/*************/
/* MODULES.C */
/*************/
void DrawModuleOutlines( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* module ); 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, void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool aErase ); bool aErase );
...@@ -94,12 +71,15 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPo ...@@ -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 ); void CalculateSegmentEndPoint( const wxPoint& aPosition, int ox, int oy, int* fx, int* fy );
/****************/
/* CONTROLE.CPP */
/****************/
void RemoteCommand( const char* cmdline ); 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 ); 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 */ #endif /* #define PROTO_H */
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include <dialog_helpers.h> #include <dialog_helpers.h>
#include <base_units.h> #include <base_units.h>
#include <gr_basic.h> #include <gr_basic.h>
#include <protos.h>
#include <class_board.h> #include <class_board.h>
#include <class_mire.h> #include <class_mire.h>
...@@ -258,9 +257,9 @@ void PCB_EDIT_FRAME::PlaceTarget( PCB_TARGET* aTarget, wxDC* DC ) ...@@ -258,9 +257,9 @@ void PCB_EDIT_FRAME::PlaceTarget( PCB_TARGET* aTarget, wxDC* DC )
if( (aTarget->GetFlags() & IN_EDIT) ) if( (aTarget->GetFlags() & IN_EDIT) )
{ {
SwapData( aTarget, &s_TargetCopy ); aTarget->SwapData( &s_TargetCopy );
SaveCopyInUndoList( aTarget, UR_CHANGED ); SaveCopyInUndoList( aTarget, UR_CHANGED );
SwapData( aTarget, &s_TargetCopy ); aTarget->SwapData( &s_TargetCopy );
} }
aTarget->ClearFlags(); aTarget->ClearFlags();
......
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