KiCad PCB EDA Suite
deltrack.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
7  * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
8 *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
31 #include <fctsys.h>
32 #include <class_drawpanel.h>
33 #include <confirm.h>
34 #include <wxPcbStruct.h>
35 #include <macros.h>
36 #include <ratsnest_data.h>
37 
38 #include <class_board.h>
39 #include <class_track.h>
40 
41 #include <pcbnew.h>
42 #include <protos.h>
43 
44 
46 {
47  if( aTrack == NULL )
48  return NULL;
49 
50  if( aTrack->IsNew() ) // Trace in progress, erase the last segment
51  {
52  if( g_CurrentTrackList.GetCount() > 0 )
53  {
54  LAYER_ID previous_layer = GetActiveLayer();
55 
56  DBG( g_CurrentTrackList.VerifyListIntegrity(); )
57 
58  // Delete the current trace
59  ShowNewTrackWhenMovingCursor( m_canvas, DC, wxDefaultPosition, false );
60 
61  // delete the most recently entered
62  delete g_CurrentTrackList.PopBack();
63 
65  {
66  // if in 2 track mode, and the next most recent is a segment
67  // not a via, and the one previous to that is a via, then
68  // delete up to the via.
69  if( g_CurrentTrackList.GetCount() >= 2
70  && g_CurrentTrackSegment->Type() != PCB_VIA_T
71  && g_CurrentTrackSegment->Back()->Type() == PCB_VIA_T )
72  {
73  delete g_CurrentTrackList.PopBack();
74  }
75  }
76 
78  {
79  delete g_CurrentTrackList.PopBack();
80 
82  previous_layer = g_CurrentTrackSegment->GetLayer();
83  }
84 
85  // Correct active layer which could change if a via
86  // has been erased
87  SetActiveLayer( previous_layer );
88 
90 
91  if( g_TwoSegmentTrackBuild ) // We must have 2 segments or more, or 0
92  {
93  if( g_CurrentTrackList.GetCount() == 1
94  && g_CurrentTrackSegment->Type() != PCB_VIA_T )
95  {
96  delete g_CurrentTrackList.PopBack();
97  }
98  }
99 
100  if( g_CurrentTrackList.GetCount() == 0 )
101  {
102  m_canvas->SetMouseCapture( NULL, NULL );
103 
104  if( GetBoard()->IsHighLightNetON() )
105  HighLight( DC );
106 
107  SetCurItem( NULL );
108  return NULL;
109  }
110  else
111  {
112  if( m_canvas->IsMouseCaptured() )
113  m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
114 
115  return g_CurrentTrackSegment;
116  }
117  }
118  return NULL;
119  }
120 
121  int netcode = aTrack->GetNetCode();
122 
123  // Remove the segment from list, but do not delete it (it will be stored i n undo list)
124  GetBoard()->Remove( aTrack );
125 
126  GetBoard()->GetRatsnest()->Remove( aTrack );
127 
128  // redraw the area where the track was
130 
131  SaveCopyInUndoList( aTrack, UR_DELETED );
132  OnModify();
133  TestNetConnection( DC, netcode );
134  SetMsgPanel( GetBoard() );
135 
136  return NULL;
137 }
138 
139 
140 void PCB_EDIT_FRAME::Delete_Track( wxDC* DC, TRACK* aTrack )
141 {
142  if( aTrack != NULL )
143  {
144  int netcode = aTrack->GetNetCode();
145  Remove_One_Track( DC, aTrack );
146  OnModify();
147  TestNetConnection( DC, netcode );
148  }
149 }
150 
151 
152 void PCB_EDIT_FRAME::Delete_net( wxDC* DC, TRACK* aTrack )
153 {
154  if( aTrack == NULL )
155  return;
156 
157  if( !IsOK( this, _( "Delete NET?" ) ) )
158  return;
159 
160  PICKED_ITEMS_LIST itemsList;
161  ITEM_PICKER picker( NULL, UR_DELETED );
162  int netcode = aTrack->GetNetCode();
163 
164  /* Search the first item for the given net code */
165  TRACK* trackList = GetBoard()->m_Track->GetStartNetCode( netcode );
166 
167  /* Remove all segments having the given net code */
168  int ii = 0;
169  TRACK* next_track;
170  for( TRACK* segm = trackList; segm; segm = next_track, ++ii )
171  {
172  next_track = segm->Next();
173  if( segm->GetNetCode() != netcode )
174  break;
175 
176  GetBoard()->GetRatsnest()->Remove( segm );
177  GetBoard()->m_Track.Remove( segm );
178 
179  // redraw the area where the track was
180  m_canvas->RefreshDrawingRect( segm->GetBoundingBox() );
181  picker.SetItem( segm );
182  itemsList.PushItem( picker );
183  }
184 
185  SaveCopyInUndoList( itemsList, UR_DELETED );
186  OnModify();
187  TestNetConnection( DC, netcode );
188  SetMsgPanel( GetBoard() );
189 }
190 
191 
192 void PCB_EDIT_FRAME::Remove_One_Track( wxDC* DC, TRACK* pt_segm )
193 {
194  int segments_to_delete_count;
195 
196  if( pt_segm == NULL )
197  return;
198 
199  TRACK* trackList = GetBoard()->MarkTrace( pt_segm, &segments_to_delete_count,
200  NULL, NULL, true );
201 
202  if( segments_to_delete_count == 0 )
203  return;
204 
205  int net_code = pt_segm->GetNetCode();
206  PICKED_ITEMS_LIST itemsList;
207  ITEM_PICKER picker( NULL, UR_DELETED );
208 
209  int ii = 0;
210  TRACK* tracksegment = trackList;
211  TRACK* next_track;
212 
213  for( ; ii < segments_to_delete_count; ii++, tracksegment = next_track )
214  {
215  next_track = tracksegment->Next();
216  tracksegment->SetState( BUSY, false );
217 
218  DBG( std::cout << __func__ << ": track " << tracksegment << " status=" \
219  << TO_UTF8( TRACK::ShowState( tracksegment->GetStatus() ) ) \
220  << std::endl; )
221 
222  GetBoard()->GetRatsnest()->Remove( tracksegment );
223  GetBoard()->m_Track.Remove( tracksegment );
224 
225  // redraw the area where the track was
226  m_canvas->RefreshDrawingRect( tracksegment->GetBoundingBox() );
227  picker.SetItem( tracksegment );
228  itemsList.PushItem( picker );
229  }
230 
231  SaveCopyInUndoList( itemsList, UR_DELETED );
232 
233  if( net_code > 0 )
234  TestNetConnection( DC, net_code );
235 }
#define g_CurrentTrackSegment
most recently created segment
Definition: pcbnew.h:101
virtual void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
Definition: pcbframe.cpp:1004
TRACK * Delete_Segment(wxDC *DC, TRACK *Track)
Function Delete_Segment removes a track segment.
Definition: deltrack.cpp:45
T * Remove(T *aElement)
Function Remove removes aElement from the list, but does not delete it.
Definition: dlist.h:211
virtual LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
virtual void SetActiveLayer(LAYER_ID aLayer) override
Function SetActiveLayer will change the currently active layer to aLayer and also update the PCB_LAYE...
Definition: pcbframe.cpp:893
This file is part of the common library.
bool IsNew() const
Definition: base_struct.h:216
DLIST< TRACK > g_CurrentTrackList
Definition: pcbnew.cpp:98
void TestNetConnection(wxDC *aDC, int aNetCode)
Function TestNetConnection tests the connections relative to aNetCode.
Definition: connect.cpp:786
Class BOARD to handle a board.
Class that computes missing connections on a PCB.
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
BOARD * GetBoard() const
void RefreshDrawingRect(const EDA_RECT &aRect, bool aEraseBackground=true)
Function RefreshDrawingRect redraws the contents of aRect in drawing units.
Definition: draw_panel.cpp:306
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
#define BUSY
Pcbnew: flag indicating that the structure has.
Definition: base_struct.h:134
Functions relatives to tracks, vias and segments used to fill zones.
This file contains miscellaneous commonly used macros and functions.
bool Remove(const BOARD_ITEM *aItem)
Function Remove() Removes an item from the ratsnest data.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
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:751
bool IsMouseCaptured() const
void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
void HighLight(wxDC *DC)
Function HighLight.
Definition: highlight.cpp:101
TRACK * MarkTrace(TRACK *aTrace, int *aCount, double *aTraceLength, double *aInPackageLength, bool aReorder)
Function MarkTrace marks a chain of trace segments, connected to aTrace.
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
void SaveCopyInUndoList(BOARD_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0)) override
Function SaveCopyInUndoList Creates a new entry in undo list of commands.
Definition: undo_redo.cpp:172
void SetItem(EDA_ITEM *aItem)
RN_DATA * GetRatsnest() const
Function GetRatsnest() returns list of missing connections between components/tracks.
Definition: class_board.h:287
int GetNetCode() const
Function GetNetCode.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
void Delete_Track(wxDC *DC, TRACK *Track)
Definition: deltrack.cpp:140
virtual void UpdateStatusBar() override
Function UpdateStatusBar updates the status bar information.
T * PopBack()
Definition: dlist.h:228
TRACK * Next() const
Definition: class_track.h:97
void SetState(int type, int state)
Definition: base_struct.h:242
TRACK * GetStartNetCode(int NetCode)
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
void ShowNewTrackWhenMovingCursor(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
Definition: editrack.cpp:673
unsigned GetCount() const
Function GetCount returns the number of elements in the list.
Definition: dlist.h:126
void Delete_net(wxDC *DC, TRACK *Track)
Definition: deltrack.cpp:152
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108
#define DBG(x)
Definition: fctsys.h:33
DLIST< TRACK > m_Track
Definition: class_board.h:244
void SetMouseCapture(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback, END_MOUSE_CAPTURE_CALLBACK aEndMouseCaptureCallback)
Function SetMouseCapture sets the mouse capture and end mouse capture callbacks to aMouseCaptureCallb...
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:111
bool g_TwoSegmentTrackBuild
Definition: pcbnew.cpp:76
void Remove(BOARD_ITEM *aBoardItem) override
>
void Remove_One_Track(wxDC *DC, TRACK *pt_segm)
Function Remove_One_Track removes 1 track/ The leading segment is removed and all adjacent segments u...
Definition: deltrack.cpp:192