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
|
/**
* @file drag.h
* @brief Useful classes and functions used to collect tracks to drag
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004-2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2015 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef _DRAG_H_
#define _DRAG_H_
#include <class_track.h>
#include <vector>
class wxDC;
class wxPoint;
class EDA_DRAW_PANEL;
class MODULE;
class D_PAD;
class CONNECTIONS;
/** Helper classes to handle a list of track segments to drag
* and has info to undo/abort the move command
*/
/*
* a DRAG_LIST manages the list of track segments to modify
* when the pad or the module is moving in drag mode
*/
/**
* a DRAG_SEGM_PICKER manage one track segment or a via
*/
class DRAG_SEGM_PICKER
{
public:
TRACK* m_Track; // pointer to the parent track segment
D_PAD* m_Pad_Start; // pointer to the moving pad
// if the start point should follow this pad
// or NULL
D_PAD* m_Pad_End; // pointer to the moving pad
// if the end point should follow this pad
// or NULL
int m_TempFlags; // flag used in drag vias and drag track segment functions
private:
double m_RotationOffset; // initial orientation of the parent module
// Used to recalculate m_PadStartOffset and m_PadEndOffset
// after a module rotation when dragging
bool m_Flipped; // initial side of the parent module
// Used to recalculate m_PadStartOffset and m_PadEndOffset
// if the module is flipped when dragging
wxPoint m_PadStartOffset; // offset between the pad and the starting point of the track
// usually 0,0, but not always
wxPoint m_PadEndOffset; // offset between the pad and the ending point of the track
// usually 0,0, but not always
wxPoint m_startInitialValue;
wxPoint m_endInitialValue; // For abort command:
// initial m_Start and m_End values for m_Track
public:
DRAG_SEGM_PICKER( TRACK* aTrack );
~DRAG_SEGM_PICKER() {};
/**
* Set auxiliary parameters relative to calculations needed
* to find track ends positions while dragging pads
* and when modules are rotated, flipped
*/
void SetAuxParameters();
/**
* Calculate track ends position while dragging pads
* and when modules are rotated, flipped
* @param aOffset = offset of module or pad position (when moving)
*/
void SetTrackEndsCoordinates( wxPoint aOffset );
void RestoreInitialValues()
{
m_Track->SetStart( m_startInitialValue );
m_Track->SetEnd( m_endInitialValue );
}
};
class DRAG_LIST
{
public:
BOARD* m_Brd; // the main board
MODULE* m_Module; // The link to the module to move, or NULL
D_PAD* m_Pad; // The link to the pad to move, or NULL
std::vector<DRAG_SEGM_PICKER> m_DragList; // The list of DRAG_SEGM_PICKER items
public:
DRAG_LIST( BOARD* aPcb )
{
m_Brd = aPcb;
m_Module = NULL;
m_Pad = NULL;
}
/**
* Function ClearList
* clear the .m_Flags of all track segments in m_DragList
* and clear the list.
*/
void ClearList();
/** Build the list of track segments connected to pads of aModule
* in m_DragList
* For each selected track segment the EDIT flag is set
*/
void BuildDragListe( MODULE* aModule );
/** Build the list of track segments connected to aPad
* in m_DragList
* For each selected track segment the EDIT flag is set
*/
void BuildDragListe( D_PAD* aPad );
private:
/** Fills m_DragList with of track segments connected to pads in aConnections
* For each selected track segment the EDIT flag is set
*/
void fillList( CONNECTIONS& aConnections );
};
// Global variables:
// a list of DRAG_SEGM_PICKER items used to move or drag tracks.
// Each DRAG_SEGM_PICKER item points a segment to move.
extern std::vector<DRAG_SEGM_PICKER> g_DragSegmentList;
// Functions:
void DrawSegmentWhileMovingFootprint( EDA_DRAW_PANEL* panel, wxDC* DC );
/**
* Function EraseDragList
* clear the .m_Flags of all track segments stored in g_DragSegmentList
* and clear the list.
* In order to avoid useless memory reallocation, the memory is not freed
* and will be reused when creating a new list
*/
void EraseDragList();
/**
* Function Collect_TrackSegmentsToDrag.
* used to collect track segments in drag track segment
* Build the list of tracks connected to the ref point by calling
* AddSegmentToDragList for each selected track
* Net codes must be up to date, because only tracks having the right net code are tested.
*
* @param aPcb A point the the #BOARD object to collect track segment to drag.
* @param aRefPos = reference point of connection
* @param aLayerMask = layers mask to collect tracks
* @param aNetCode = the net code to consider
* @param aMaxDist = max distance from aRefPos to a track end candidate to collect the track
*/
void Collect_TrackSegmentsToDrag( BOARD* aPcb, const wxPoint& aRefPos, LSET aLayerMask,
int aNetCode, int aMaxDist );
/* Add aTrack to the drag list
* flag = STARTPOINT (if the point to drag is the start point of Track)
* or ENDPOINT (if the point to drag is the end point of Track)
*/
void AddSegmentToDragList( int flag, TRACK* aTrack );
/*
* Undraw the track segments in list, and set the EDIT flag
* Usually called after the track list is built, to prepare
* the redraw of the list when the mouse is moved
*/
void UndrawAndMarkSegmentsToDrag( EDA_DRAW_PANEL* aCanvas, wxDC* aDC );
#endif // _DRAG_H_
|