kicad/pcbnew/move-drag_pads.cpp

115 lines
2.6 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>
2018-01-29 15:39:40 +00:00
#include <pcb_base_frame.h>
#include <class_board.h>
#include <class_module.h>
#include <pcbnew.h>
#include <drag.h>
static wxPoint Pad_OldPos;
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 );
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() );
if( DC )
track->Draw( m_canvas, DC, GR_XOR );
track->SetState( IN_EDIT, false );
track->ClearFlags();
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 );
}