kicad/pcbnew/move-drag_pads.cpp

208 lines
5.0 KiB
C++
Raw Normal View History

2012-02-19 04:02:19 +00:00
/**
* @file move-drag_pads.cpp
* @brief Edit footprint pads.
*/
#include <fctsys.h>
#include <gr_basic.h>
#include <common.h>
#include <class_drawpanel.h>
#include <trigo.h>
#include <block_commande.h>
#include <wxBasePcbFrame.h>
#include <pcbcommon.h>
#include <class_board.h>
#include <class_module.h>
#include <pcbnew.h>
#include <drag.h>
static D_PAD* s_CurrentSelectedPad;
static wxPoint Pad_OldPos;
/* Cancel move pad command.
2008-02-23 01:27:21 +00:00
*/
static void Abort_Move_Pad( EDA_DRAW_PANEL* Panel, wxDC* DC )
{
2008-02-23 01:27:21 +00:00
D_PAD* pad = s_CurrentSelectedPad;
Panel->SetMouseCapture( NULL, NULL );
2008-02-23 01:27:21 +00:00
if( pad == NULL )
return;
2008-04-01 05:21:50 +00:00
pad->Draw( Panel, DC, GR_XOR );
pad->ClearFlags();
2012-02-19 04:02:19 +00:00
pad->SetPosition( Pad_OldPos );
2008-04-01 05:21:50 +00:00
pad->Draw( Panel, DC, GR_XOR );
// Pad move in progress: restore origin of dragged tracks, if any.
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
2008-02-23 01:27:21 +00:00
{
TRACK* Track = g_DragSegmentList[ii].m_Track;
Track->Draw( Panel, DC, GR_XOR );
Track->SetState( IN_EDIT, false );
g_DragSegmentList[ii].RestoreInitialValues();
Track->Draw( Panel, DC, GR_OR );
2008-02-23 01:27:21 +00:00
}
EraseDragList();
2008-02-23 01:27:21 +00:00
s_CurrentSelectedPad = NULL;
}
/* Draw in drag mode when moving a pad.
*/
static void Show_Pad_Move( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool aErase )
{
2008-02-23 01:27:21 +00:00
TRACK* Track;
BASE_SCREEN* screen = aPanel->GetScreen();
2008-02-23 01:27:21 +00:00
D_PAD* pad = s_CurrentSelectedPad;
if( pad == NULL ) // Should not occur
return;
if( aErase )
pad->Draw( aPanel, aDC, GR_XOR );
2008-04-01 05:21:50 +00:00
2012-02-19 04:02:19 +00:00
pad->SetPosition( screen->GetCrossHairPosition() );
pad->Draw( aPanel, aDC, GR_XOR );
2008-02-23 01:27:21 +00:00
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
2008-02-23 01:27:21 +00:00
{
Track = g_DragSegmentList[ii].m_Track;
if( aErase )
Track->Draw( aPanel, aDC, GR_XOR );
g_DragSegmentList[ii].SetTrackEndsCoordinates( wxPoint(0, 0) );
Track->Draw( aPanel, aDC, GR_XOR );
2008-02-23 01:27:21 +00:00
}
}
2012-02-19 04:02:19 +00:00
// Function to initialize the "move pad" command
void PCB_BASE_FRAME::StartMovePad( D_PAD* aPad, wxDC* aDC, bool aDragConnectedTracks )
{
2012-02-19 04:02:19 +00:00
if( aPad == NULL )
2008-02-23 01:27:21 +00:00
return;
2012-02-19 04:02:19 +00:00
s_CurrentSelectedPad = aPad;
Pad_OldPos = aPad->GetPosition();
SetMsgPanel( aPad );
m_canvas->SetMouseCapture( Show_Pad_Move, Abort_Move_Pad );
// Draw the pad, in SKETCH mode
aPad->Draw( m_canvas, aDC, GR_XOR );
2012-02-19 04:02:19 +00:00
aPad->SetFlags( IS_MOVED );
aPad->Draw( m_canvas, aDC, GR_XOR );
EraseDragList();
2012-02-19 04:02:19 +00:00
// Build the list of track segments to drag if the command is a drag pad
if( aDragConnectedTracks )
{
DRAG_LIST drglist( GetBoard() );
drglist.BuildDragListe( aPad );
UndrawAndMarkSegmentsToDrag( m_canvas, aDC );
}
}
2012-02-19 04:02:19 +00:00
// Routine to place a moved pad.
void PCB_BASE_FRAME::PlacePad( D_PAD* aPad, wxDC* DC )
{
int dX, dY;
TRACK* Track;
2008-02-23 01:27:21 +00:00
2012-02-19 04:02:19 +00:00
if( aPad == NULL )
2008-02-23 01:27:21 +00:00
return;
2012-02-19 04:02:19 +00:00
MODULE* module = aPad->GetParent();
ITEM_PICKER picker( NULL, UR_CHANGED );
PICKED_ITEMS_LIST pickList;
2012-02-19 04:02:19 +00:00
// Save dragged track segments in undo list
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{
Track = g_DragSegmentList[ii].m_Track;
// Set the old state
if( g_DragSegmentList[ii].m_Pad_Start )
Track->SetStart( Pad_OldPos );
if( g_DragSegmentList[ii].m_Pad_End )
Track->SetEnd( Pad_OldPos );
2012-02-05 13:02:46 +00:00
picker.SetItem( Track );
pickList.PushItem( picker );
}
2012-02-19 04:02:19 +00:00
// Save old module and old items values
aPad->ClearFlags();
2012-02-19 04:02:19 +00:00
wxPoint pad_curr_position = aPad->GetPosition();
2012-02-19 04:02:19 +00:00
aPad->SetPosition( Pad_OldPos );
if( g_DragSegmentList.size() == 0 )
2012-02-19 04:02:19 +00:00
SaveCopyInUndoList( module, UR_CHANGED );
else
{
2012-02-19 04:02:19 +00:00
picker.SetItem( module );
pickList.PushItem( picker );
SaveCopyInUndoList( pickList, UR_CHANGED );
}
2012-02-19 04:02:19 +00:00
aPad->SetPosition( pad_curr_position );
aPad->Draw( m_canvas, DC, GR_XOR );
2012-02-19 04:02:19 +00:00
// Redraw dragged track segments
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{
Track = g_DragSegmentList[ii].m_Track;
// Set the new state
if( g_DragSegmentList[ii].m_Pad_Start )
Track->SetStart( aPad->GetPosition() );
if( g_DragSegmentList[ii].m_Pad_End )
Track->SetEnd( aPad->GetPosition() );
Track->SetState( IN_EDIT, false );
if( DC )
Track->Draw( m_canvas, DC, GR_OR );
}
2012-02-19 04:02:19 +00:00
// Compute local coordinates (i.e refer to module position and for module orient = 0)
dX = aPad->GetPosition().x - Pad_OldPos.x;
dY = aPad->GetPosition().y - Pad_OldPos.y;
RotatePoint( &dX, &dY, -module->GetOrientation() );
2012-02-19 04:02:19 +00:00
aPad->SetX0( dX + aPad->GetPos0().x );
aPad->SetY0( dY + aPad->GetPos0().y );
2012-02-19 04:02:19 +00:00
if( DC )
2012-02-19 04:02:19 +00:00
aPad->Draw( m_canvas, DC, GR_OR );
2012-02-19 04:02:19 +00:00
module->CalculateBoundingBox();
module->SetLastEditTime();
EraseDragList();
2008-02-23 01:27:21 +00:00
OnModify();
m_canvas->SetMouseCapture( NULL, NULL );
m_Pcb->m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK );
}