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:
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
......
......@@ -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;
......
......@@ -44,7 +44,6 @@
#include <msgpanel.h>
#include <pcbnew.h>
#include <protos.h>
#include <math_for_graphics.h>
#include <class_board.h>
......
......@@ -38,7 +38,6 @@
#include <colors_selection.h>
#include <trigo.h>
#include <macros.h>
#include <protos.h>
#include <richio.h>
#include <class_board.h>
......
......@@ -34,7 +34,6 @@
#include <confirm.h>
#include <kicad_string.h>
#include <trigo.h>
#include <protos.h>
#include <richio.h>
#include <wxstruct.h>
#include <macros.h>
......
......@@ -41,7 +41,6 @@
#include <wxBasePcbFrame.h>
#include <msgpanel.h>
#include <protos.h>
#include <class_board.h>
#include <class_zone.h>
......
......@@ -37,8 +37,7 @@
#include <class_board.h>
#include <class_pcb_text.h>
#include <protos.h>
#include <class_board_item.h>
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();
......
......@@ -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" ),
......
......@@ -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 */
......@@ -34,7 +34,6 @@
#include <dialog_helpers.h>
#include <base_units.h>
#include <gr_basic.h>
#include <protos.h>
#include <class_board.h>
#include <class_mire.h>
......@@ -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();
......
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