1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
/**
* @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 <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.
*/
static void Abort_Move_Pad( EDA_DRAW_PANEL* Panel, wxDC* DC )
{
D_PAD* pad = s_CurrentSelectedPad;
Panel->SetMouseCapture( NULL, NULL );
if( pad == NULL )
return;
pad->Draw( Panel, DC, GR_XOR );
pad->ClearFlags();
pad->SetPosition( Pad_OldPos );
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++ )
{
TRACK* track = g_DragSegmentList[ii].m_Track;
track->Draw( Panel, DC, GR_XOR );
track->SetState( IN_EDIT, false );
track->ClearFlags();
g_DragSegmentList[ii].RestoreInitialValues();
track->Draw( Panel, DC, GR_OR );
}
EraseDragList();
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 )
{
TRACK* Track;
D_PAD* pad = s_CurrentSelectedPad;
if( pad == NULL ) // Should not occur
return;
if( aErase )
pad->Draw( aPanel, aDC, GR_XOR );
pad->SetPosition( aPanel->GetParent()->GetCrossHairPosition() );
pad->Draw( aPanel, aDC, GR_XOR );
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{
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 );
}
}
// Function to initialize the "move pad" command
void PCB_BASE_FRAME::StartMovePad( D_PAD* aPad, wxDC* aDC, bool aDragConnectedTracks )
{
if( aPad == NULL )
return;
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 );
aPad->SetFlags( IS_MOVED );
aPad->Draw( m_canvas, aDC, GR_XOR );
EraseDragList();
// 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 );
}
}
// Routine to place a moved pad.
void PCB_BASE_FRAME::PlacePad( D_PAD* aPad, wxDC* DC )
{
int dX, dY;
TRACK* track;
if( aPad == NULL )
return;
MODULE* module = aPad->GetParent();
ITEM_PICKER picker( NULL, UR_CHANGED );
PICKED_ITEMS_LIST pickList;
// 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 );
}
// Save old module and old items values
aPad->ClearFlags();
wxPoint pad_curr_position = aPad->GetPosition();
aPad->SetPosition( Pad_OldPos );
if( g_DragSegmentList.size() == 0 )
SaveCopyInUndoList( module, UR_CHANGED );
else
{
picker.SetItem( module );
pickList.PushItem( picker );
SaveCopyInUndoList( pickList, UR_CHANGED );
}
aPad->SetPosition( pad_curr_position );
aPad->Draw( m_canvas, DC, GR_XOR );
// 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 );
}
// 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() );
aPad->SetX0( dX + aPad->GetPos0().x );
aPad->SetY0( dY + aPad->GetPos0().y );
if( DC )
aPad->Draw( m_canvas, DC, GR_OR );
module->CalculateBoundingBox();
module->SetLastEditTime();
EraseDragList();
OnModify();
m_canvas->SetMouseCapture( NULL, NULL );
m_Pcb->m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK );
}
|