KiCad PCB EDA Suite
move-drag_pads.cpp
Go to the documentation of this file.
1 
2 
8 #include <fctsys.h>
9 #include <gr_basic.h>
10 #include <common.h>
11 #include <class_drawpanel.h>
12 #include <trigo.h>
13 #include <block_commande.h>
14 #include <wxBasePcbFrame.h>
15 
16 #include <class_board.h>
17 #include <class_module.h>
18 
19 #include <pcbnew.h>
20 #include <drag.h>
21 
22 
25 
26 
27 /* Cancel move pad command.
28  */
29 static void Abort_Move_Pad( EDA_DRAW_PANEL* Panel, wxDC* DC )
30 {
32 
33  Panel->SetMouseCapture( NULL, NULL );
34 
35  if( pad == NULL )
36  return;
37 
38  pad->Draw( Panel, DC, GR_XOR );
39  pad->ClearFlags();
40  pad->SetPosition( Pad_OldPos );
41  pad->Draw( Panel, DC, GR_XOR );
42 
43  // Pad move in progress: restore origin of dragged tracks, if any.
44  for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
45  {
46  TRACK* track = g_DragSegmentList[ii].m_Track;
47  track->Draw( Panel, DC, GR_XOR );
48  track->SetState( IN_EDIT, false );
49  track->ClearFlags();
50  g_DragSegmentList[ii].RestoreInitialValues();
51  track->Draw( Panel, DC, GR_OR );
52  }
53 
54  EraseDragList();
55  s_CurrentSelectedPad = NULL;
56 }
57 
58 
59 /* Draw in drag mode when moving a pad.
60  */
61 static void Show_Pad_Move( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
62  bool aErase )
63 {
64  TRACK* Track;
66 
67  if( pad == NULL ) // Should not occur
68  return;
69 
70  if( aErase )
71  pad->Draw( aPanel, aDC, GR_XOR );
72 
73  pad->SetPosition( aPanel->GetParent()->GetCrossHairPosition() );
74  pad->Draw( aPanel, aDC, GR_XOR );
75 
76  for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
77  {
78  Track = g_DragSegmentList[ii].m_Track;
79 
80  if( aErase )
81  Track->Draw( aPanel, aDC, GR_XOR );
82 
83  g_DragSegmentList[ii].SetTrackEndsCoordinates( wxPoint(0, 0) );
84 
85  Track->Draw( aPanel, aDC, GR_XOR );
86  }
87 }
88 
89 
90 // Function to initialize the "move pad" command
91 void PCB_BASE_FRAME::StartMovePad( D_PAD* aPad, wxDC* aDC, bool aDragConnectedTracks )
92 {
93  if( aPad == NULL )
94  return;
95 
96  s_CurrentSelectedPad = aPad;
97 
98  Pad_OldPos = aPad->GetPosition();
99 
100  SetMsgPanel( aPad );
102 
103  // Draw the pad, in SKETCH mode
104  aPad->Draw( m_canvas, aDC, GR_XOR );
105  aPad->SetFlags( IS_MOVED );
106  aPad->Draw( m_canvas, aDC, GR_XOR );
107 
108  EraseDragList();
109 
110  // Build the list of track segments to drag if the command is a drag pad
111  if( aDragConnectedTracks )
112  {
113  DRAG_LIST drglist( GetBoard() );
114  drglist.BuildDragListe( aPad );
116  }
117 }
118 
119 
120 // Routine to place a moved pad.
121 void PCB_BASE_FRAME::PlacePad( D_PAD* aPad, wxDC* DC )
122 {
123  int dX, dY;
124  TRACK* track;
125 
126  if( aPad == NULL )
127  return;
128 
129  MODULE* module = aPad->GetParent();
130 
131  ITEM_PICKER picker( NULL, UR_CHANGED );
132  PICKED_ITEMS_LIST pickList;
133 
134  // Save dragged track segments in undo list
135  for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
136  {
137  track = g_DragSegmentList[ii].m_Track;
138 
139  // Set the old state
140  if( g_DragSegmentList[ii].m_Pad_Start )
141  track->SetStart( Pad_OldPos );
142 
143  if( g_DragSegmentList[ii].m_Pad_End )
144  track->SetEnd( Pad_OldPos );
145 
146  picker.SetItem( track );
147  pickList.PushItem( picker );
148  }
149 
150  // Save old module and old items values
151  aPad->ClearFlags();
152  wxPoint pad_curr_position = aPad->GetPosition();
153 
154  aPad->SetPosition( Pad_OldPos );
155 
156  if( g_DragSegmentList.size() == 0 )
157  SaveCopyInUndoList( module, UR_CHANGED );
158  else
159  {
160  picker.SetItem( module );
161  pickList.PushItem( picker );
162  SaveCopyInUndoList( pickList, UR_CHANGED );
163  }
164 
165  aPad->SetPosition( pad_curr_position );
166  aPad->Draw( m_canvas, DC, GR_XOR );
167 
168  // Redraw dragged track segments
169  for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
170  {
171  track = g_DragSegmentList[ii].m_Track;
172 
173  // Set the new state
174  if( g_DragSegmentList[ii].m_Pad_Start )
175  track->SetStart( aPad->GetPosition() );
176 
177  if( g_DragSegmentList[ii].m_Pad_End )
178  track->SetEnd( aPad->GetPosition() );
179 
180  if( DC )
181  track->Draw( m_canvas, DC, GR_XOR );
182 
183  track->SetState( IN_EDIT, false );
184  track->ClearFlags();
185 
186  if( DC )
187  track->Draw( m_canvas, DC, GR_OR );
188  }
189 
190  // Compute local coordinates (i.e refer to module position and for module orient = 0)
191  dX = aPad->GetPosition().x - Pad_OldPos.x;
192  dY = aPad->GetPosition().y - Pad_OldPos.y;
193 
194  RotatePoint( &dX, &dY, -module->GetOrientation() );
195 
196  aPad->SetX0( dX + aPad->GetPos0().x );
197  aPad->SetY0( dY + aPad->GetPos0().y );
198 
199  if( DC )
200  aPad->Draw( m_canvas, DC, GR_OR );
201 
202  module->CalculateBoundingBox();
203  module->SetLastEditTime();
204 
205  EraseDragList();
206 
207  OnModify();
208  m_canvas->SetMouseCapture( NULL, NULL );
210 }
#define IN_EDIT
Item currently edited.
Definition: base_struct.h:111
static void Abort_Move_Pad(EDA_DRAW_PANEL *Panel, wxDC *DC)
static wxPoint Pad_OldPos
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:117
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
void CalculateBoundingBox()
Function CalculateBoundingBox calculates the bounding box in board coordinates.
Class BOARD to handle a board.
MODULE * GetParent() const
Definition: class_pad.h:108
void EraseDragList()
Function EraseDragList clear the .m_Flags of all track segments stored in g_DragSegmentList and clear...
Definition: dragsegm.cpp:309
BOARD * GetBoard() const
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:169
const wxPoint & GetPos0() const
Definition: class_pad.h:176
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
void SetLastEditTime(time_t aTime)
Definition: class_module.h:270
void SetY0(int y)
Definition: class_pad.h:178
void PlacePad(D_PAD *Pad, wxDC *DC)
void StartMovePad(D_PAD *aPad, wxDC *aDC, bool aDragConnectedTracks)
Function StartMovePad Initialize a drag or move pad command.
std::vector< DRAG_SEGM_PICKER > g_DragSegmentList
Definition: dragsegm.cpp:48
Classes used in Pcbnew, CvPcb and GerbView.
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:253
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:754
double GetOrientation() const
Definition: class_module.h:148
Useful classes and functions used to collect tracks to drag.
const wxPoint & GetPosition() const override
Definition: class_pad.h:170
void UndrawAndMarkSegmentsToDrag(EDA_DRAW_PANEL *aCanvas, wxDC *aDC)
Definition: dragsegm.cpp:404
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
void SetItem(EDA_ITEM *aItem)
Definition: gr_basic.h:42
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
This file is part of the common library.
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
void SetState(int type, int state)
Definition: base_struct.h:242
void BuildDragListe(MODULE *aModule)
Build the list of track segments connected to pads of aModule in m_DragList For each selected track s...
Definition: dragsegm.cpp:153
virtual void SaveCopyInUndoList(BOARD_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0))=0
Function SaveCopyInUndoList (virtual pure) Creates a new entry in undo list of commands.
The common library.
static D_PAD * s_CurrentSelectedPad
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
void SetStart(const wxPoint &aStart)
Definition: class_track.h:120
void SetX0(int x)
Definition: class_pad.h:179
Module description (excepted pads)
void SetMouseCapture(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback, END_MOUSE_CAPTURE_CALLBACK aEndMouseCaptureCallback)
Function SetMouseCapture sets the mouse capture and end mouse capture callbacks to aMouseCaptureCallb...
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
int m_Status_Pcb
Flags used in ratsnest calculation and update.
Definition: class_board.h:240
static void Show_Pad_Move(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
#define IS_MOVED
Item being moved.
Definition: base_struct.h:112