2012-02-19 04:02:19 +00:00
|
|
|
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file move-drag_pads.cpp
|
|
|
|
* @brief Edit footprint pads.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <block_commande.h>
|
2018-01-29 15:39:40 +00:00
|
|
|
#include <pcb_base_frame.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <drag.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
static D_PAD* s_CurrentSelectedPad;
|
2011-11-24 17:32:51 +00:00
|
|
|
static wxPoint Pad_OldPos;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Cancel move pad command.
|
2008-02-23 01:27:21 +00:00
|
|
|
*/
|
2011-02-12 19:38:55 +00:00
|
|
|
static void Abort_Move_Pad( EDA_DRAW_PANEL* Panel, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-02-23 01:27:21 +00:00
|
|
|
D_PAD* pad = s_CurrentSelectedPad;
|
|
|
|
|
2011-02-13 09:07:30 +00:00
|
|
|
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 );
|
2011-12-21 13:42:02 +00:00
|
|
|
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 );
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
// 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
|
|
|
{
|
2013-07-05 17:48:01 +00:00
|
|
|
TRACK* track = g_DragSegmentList[ii].m_Track;
|
|
|
|
track->Draw( Panel, DC, GR_XOR );
|
|
|
|
track->SetState( IN_EDIT, false );
|
|
|
|
track->ClearFlags();
|
2012-09-11 07:33:17 +00:00
|
|
|
g_DragSegmentList[ii].RestoreInitialValues();
|
2013-07-05 17:48:01 +00:00
|
|
|
track->Draw( Panel, DC, GR_OR );
|
2008-02-23 01:27:21 +00:00
|
|
|
}
|
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
EraseDragList();
|
2008-02-23 01:27:21 +00:00
|
|
|
s_CurrentSelectedPad = NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Draw in drag mode when moving a pad.
|
|
|
|
*/
|
2011-02-03 19:27:28 +00:00
|
|
|
static void Show_Pad_Move( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-02-23 01:27:21 +00:00
|
|
|
TRACK* Track;
|
|
|
|
D_PAD* pad = s_CurrentSelectedPad;
|
|
|
|
|
2011-02-12 19:38:55 +00:00
|
|
|
if( pad == NULL ) // Should not occur
|
|
|
|
return;
|
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
if( aErase )
|
|
|
|
pad->Draw( aPanel, aDC, GR_XOR );
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
pad->SetPosition( aPanel->GetParent()->GetCrossHairPosition() );
|
2011-02-03 19:27:28 +00:00
|
|
|
pad->Draw( aPanel, aDC, GR_XOR );
|
2008-02-23 01:27:21 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
|
2008-02-23 01:27:21 +00:00
|
|
|
{
|
2012-09-11 07:33:17 +00:00
|
|
|
Track = g_DragSegmentList[ii].m_Track;
|
2011-02-03 19:27:28 +00:00
|
|
|
|
|
|
|
if( aErase )
|
|
|
|
Track->Draw( aPanel, aDC, GR_XOR );
|
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
g_DragSegmentList[ii].SetTrackEndsCoordinates( wxPoint(0, 0) );
|
2011-02-03 19:27:28 +00:00
|
|
|
|
|
|
|
Track->Draw( aPanel, aDC, GR_XOR );
|
2008-02-23 01:27:21 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Function to initialize the "move pad" command
|
2012-09-11 07:33:17 +00:00
|
|
|
void PCB_BASE_FRAME::StartMovePad( D_PAD* aPad, wxDC* aDC, bool aDragConnectedTracks )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
if( aPad == NULL )
|
2008-02-23 01:27:21 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
s_CurrentSelectedPad = aPad;
|
|
|
|
|
|
|
|
Pad_OldPos = aPad->GetPosition();
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( aPad );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( Show_Pad_Move, Abort_Move_Pad );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
// 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 );
|
2012-09-11 07:33:17 +00:00
|
|
|
aPad->Draw( m_canvas, aDC, GR_XOR );
|
|
|
|
|
|
|
|
EraseDragList();
|
2007-10-07 18:24:15 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Build the list of track segments to drag if the command is a drag pad
|
2012-09-11 07:33:17 +00:00
|
|
|
if( aDragConnectedTracks )
|
|
|
|
{
|
|
|
|
DRAG_LIST drglist( GetBoard() );
|
|
|
|
drglist.BuildDragListe( aPad );
|
|
|
|
UndrawAndMarkSegmentsToDrag( m_canvas, aDC );
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Routine to place a moved pad.
|
|
|
|
void PCB_BASE_FRAME::PlacePad( D_PAD* aPad, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-10-14 18:14:58 +00:00
|
|
|
int dX, dY;
|
2013-07-05 17:48:01 +00:00
|
|
|
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;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
MODULE* module = aPad->GetParent();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-10-14 18:14:58 +00:00
|
|
|
ITEM_PICKER picker( NULL, UR_CHANGED );
|
2009-08-03 18:54:48 +00:00
|
|
|
PICKED_ITEMS_LIST pickList;
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Save dragged track segments in undo list
|
2010-08-31 15:54:05 +00:00
|
|
|
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
|
2009-08-03 18:54:48 +00:00
|
|
|
{
|
2013-07-05 17:48:01 +00:00
|
|
|
track = g_DragSegmentList[ii].m_Track;
|
2009-10-14 18:14:58 +00:00
|
|
|
|
2009-08-03 18:54:48 +00:00
|
|
|
// Set the old state
|
2010-08-31 15:54:05 +00:00
|
|
|
if( g_DragSegmentList[ii].m_Pad_Start )
|
2013-07-05 17:48:01 +00:00
|
|
|
track->SetStart( Pad_OldPos );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
if( g_DragSegmentList[ii].m_Pad_End )
|
2013-07-05 17:48:01 +00:00
|
|
|
track->SetEnd( Pad_OldPos );
|
2009-08-03 18:54:48 +00:00
|
|
|
|
2013-07-05 17:48:01 +00:00
|
|
|
picker.SetItem( track );
|
2009-10-14 18:14:58 +00:00
|
|
|
pickList.PushItem( picker );
|
2009-08-03 18:54:48 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Save old module and old items values
|
2013-03-28 09:40:29 +00:00
|
|
|
aPad->ClearFlags();
|
2012-02-19 04:02:19 +00:00
|
|
|
wxPoint pad_curr_position = aPad->GetPosition();
|
2009-08-03 18:54:48 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
aPad->SetPosition( Pad_OldPos );
|
2011-05-13 13:15:28 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
if( g_DragSegmentList.size() == 0 )
|
2012-02-19 04:02:19 +00:00
|
|
|
SaveCopyInUndoList( module, UR_CHANGED );
|
2009-08-03 18:54:48 +00:00
|
|
|
else
|
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
picker.SetItem( module );
|
2009-10-14 18:14:58 +00:00
|
|
|
pickList.PushItem( picker );
|
2009-08-03 18:54:48 +00:00
|
|
|
SaveCopyInUndoList( pickList, UR_CHANGED );
|
2010-08-31 15:54:05 +00:00
|
|
|
}
|
2009-08-03 18:54:48 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
aPad->SetPosition( pad_curr_position );
|
|
|
|
aPad->Draw( m_canvas, DC, GR_XOR );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Redraw dragged track segments
|
2010-08-31 15:54:05 +00:00
|
|
|
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
|
2009-08-03 18:54:48 +00:00
|
|
|
{
|
2013-07-05 17:48:01 +00:00
|
|
|
track = g_DragSegmentList[ii].m_Track;
|
2009-10-14 18:14:58 +00:00
|
|
|
|
2009-08-03 18:54:48 +00:00
|
|
|
// Set the new state
|
2010-08-31 15:54:05 +00:00
|
|
|
if( g_DragSegmentList[ii].m_Pad_Start )
|
2013-07-05 17:48:01 +00:00
|
|
|
track->SetStart( aPad->GetPosition() );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
if( g_DragSegmentList[ii].m_Pad_End )
|
2013-07-05 17:48:01 +00:00
|
|
|
track->SetEnd( aPad->GetPosition() );
|
|
|
|
|
|
|
|
if( DC )
|
|
|
|
track->Draw( m_canvas, DC, GR_XOR );
|
2009-08-03 18:54:48 +00:00
|
|
|
|
2013-07-05 17:48:01 +00:00
|
|
|
track->SetState( IN_EDIT, false );
|
|
|
|
track->ClearFlags();
|
2011-05-13 13:15:28 +00:00
|
|
|
|
2009-10-14 18:14:58 +00:00
|
|
|
if( DC )
|
2013-07-05 17:48:01 +00:00
|
|
|
track->Draw( m_canvas, DC, GR_OR );
|
2009-08-03 18:54:48 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
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() );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
aPad->SetX0( dX + aPad->GetPos0().x );
|
2012-09-11 07:33:17 +00:00
|
|
|
aPad->SetY0( dY + aPad->GetPos0().y );
|
2012-02-19 04:02:19 +00:00
|
|
|
|
2009-10-14 18:14:58 +00:00
|
|
|
if( DC )
|
2012-02-19 04:02:19 +00:00
|
|
|
aPad->Draw( m_canvas, DC, GR_OR );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
module->CalculateBoundingBox();
|
2012-09-05 12:13:33 +00:00
|
|
|
module->SetLastEditTime();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-08-31 15:54:05 +00:00
|
|
|
EraseDragList();
|
2008-02-23 01:27:21 +00:00
|
|
|
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( NULL, NULL );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|