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 <pcb_edit_frame.h>
35 #include <macros.h>
36 #include <connectivity_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  PCB_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 
64  if( Settings().m_legacyUseTwoSegmentTracks )
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( Settings().m_legacyUseTwoSegmentTracks ) // 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 in undo list)
124  GetBoard()->Remove( aTrack );
125  GetBoard()->GetConnectivity()->Remove( aTrack );
126 
127  SaveCopyInUndoList( aTrack, UR_DELETED );
128  OnModify();
129 
130  if( GetBoard()->IsElementVisible( LAYER_RATSNEST ) && DC )
131  {
132  GRSetDrawMode( DC, GR_XOR );
133  DrawGeneralRatsnest( DC, 0 );
134  }
135  // compute and display the new ratsnest
136  TestNetConnection( DC, netcode );
137  SetMsgPanel( GetBoard() );
138 
139  // redraw the area where the track was
141 
142  return NULL;
143 }
144 
145 
146 void PCB_EDIT_FRAME::Delete_Track( wxDC* DC, TRACK* aTrack )
147 {
148  if( aTrack != NULL )
149  {
150  Remove_One_Track( DC, aTrack );
151  OnModify();
152  }
153 }
154 
155 
156 void PCB_EDIT_FRAME::Delete_net( wxDC* DC, TRACK* aTrack )
157 {
158  if( aTrack == NULL )
159  return;
160 
161  if( !IsOK( this, _( "Delete NET?" ) ) )
162  return;
163 
164  PICKED_ITEMS_LIST itemsList;
165  ITEM_PICKER picker( NULL, UR_DELETED );
166  int netcode = aTrack->GetNetCode();
167 
168  /* Search the first item for the given net code */
169  TRACK* trackList = GetBoard()->m_Track->GetStartNetCode( netcode );
170 
171  /* Remove all segments having the given net code */
172  int ii = 0;
173  TRACK* next_track;
174  for( TRACK* segm = trackList; segm; segm = next_track, ++ii )
175  {
176  next_track = segm->Next();
177  if( segm->GetNetCode() != netcode )
178  break;
179 
180  GetBoard()->GetConnectivity()->Remove( segm );
181  GetBoard()->m_Track.Remove( segm );
182 
183  // redraw the area where the track was
184  m_canvas->RefreshDrawingRect( segm->GetBoundingBox() );
185  picker.SetItem( segm );
186  itemsList.PushItem( picker );
187  }
188 
189  SaveCopyInUndoList( itemsList, UR_DELETED );
190  OnModify();
191 
192  // Erase old ratsnest
194  {
195  GRSetDrawMode( DC, GR_XOR );
196  DrawGeneralRatsnest( DC, 0 );
197  }
198 
199  TestNetConnection( DC, netcode );
200  SetMsgPanel( GetBoard() );
201 }
202 
203 
204 void PCB_EDIT_FRAME::Remove_One_Track( wxDC* DC, TRACK* pt_segm )
205 {
206  int segments_to_delete_count;
207 
208  if( pt_segm == NULL )
209  return;
210 
211  TRACK* trackList = GetBoard()->MarkTrace( GetBoard()->m_Track, pt_segm,
212  &segments_to_delete_count,
213  NULL, NULL, true );
214 
215  if( segments_to_delete_count == 0 )
216  return;
217 
218  int net_code = pt_segm->GetNetCode();
219  PICKED_ITEMS_LIST itemsList;
220  ITEM_PICKER picker( NULL, UR_DELETED );
221 
222  int ii = 0;
223  TRACK* tracksegment = trackList;
224  TRACK* next_track;
225 
226  for( ; ii < segments_to_delete_count; ii++, tracksegment = next_track )
227  {
228  next_track = tracksegment->Next();
229  tracksegment->SetState( BUSY, false );
230 
231  DBG( std::cout << __func__ << ": track " << tracksegment << " status=" \
232  << TO_UTF8( TRACK::ShowState( tracksegment->GetStatus() ) ) \
233  << std::endl; )
234 
235  GetBoard()->GetConnectivity()->Remove( tracksegment );
236  GetBoard()->m_Track.Remove( tracksegment );
237 
238  // redraw the area where the track was
239  m_canvas->RefreshDrawingRect( tracksegment->GetBoundingBox() );
240  picker.SetItem( tracksegment );
241  itemsList.PushItem( picker );
242  }
243 
244  SaveCopyInUndoList( itemsList, UR_DELETED );
245 
246  if( net_code > 0 )
247  {
248  // Erase old ratsnest
250  {
251  GRSetDrawMode( DC, GR_XOR );
252  DrawGeneralRatsnest( DC, 0 );
253  }
254 
255  // Build and draw the new ratsnest
256  TestNetConnection( DC, net_code );
257  }
258 }
#define g_CurrentTrackSegment
most recently created segment
Definition: pcbnew.h:94
virtual void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
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
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:318
This file is part of the common library.
bool IsNew() const
Definition: base_struct.h:216
DLIST< TRACK > g_CurrentTrackList
Definition: pcbnew.cpp:90
void TestNetConnection(wxDC *aDC, int aNetCode)
Function TestNetConnection tests the connections relative to aNetCode.
Definition: connect.cpp:40
Class BOARD to handle a board.
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:301
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:132
Functions relatives to tracks, vias and segments used to fill zones.
This file contains miscellaneous commonly used macros and functions.
#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
bool IsElementVisible(GAL_LAYER_ID aElement) const
Function IsElementVisible tests whether a given element category is visible.
PCB_LAYER_ID
A quick note on layer IDs:
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:862
bool IsMouseCaptured() const
PCB_GENERAL_SETTINGS & Settings()
void DrawGeneralRatsnest(wxDC *aDC, int aNetcode=0)
function Displays the general ratsnest Only ratsnest with the status bit CH_VISIBLE is set are displa...
Definition: ratsnest.cpp:85
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
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:202
void SetItem(EDA_ITEM *aItem)
int GetNetCode() const
Function GetNetCode.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:107
void Delete_Track(wxDC *DC, TRACK *Track)
Definition: deltrack.cpp:146
virtual void UpdateStatusBar() override
Function UpdateStatusBar updates the status bar information.
T * PopBack()
Definition: dlist.h:228
TRACK * Next() const
Definition: class_track.h:99
void SetState(int type, int state)
Definition: base_struct.h:242
TRACK * GetStartNetCode(int NetCode)
void ShowNewTrackWhenMovingCursor(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
Definition: editrack.cpp:665
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:156
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
#define DBG(x)
Definition: fctsys.h:33
DLIST< TRACK > m_Track
Definition: class_board.h:249
void SetMouseCapture(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback, END_MOUSE_CAPTURE_CALLBACK aEndMouseCaptureCallback)
Function SetMouseCapture sets the mouse capture and end mouse capture callbacks to aMouseCaptureCallb...
TRACK * MarkTrace(TRACK *aTrackList, TRACK *aTrace, int *aCount, double *aTraceLength, double *aInPackageLength, bool aReorder)
Function MarkTrace marks a chain of trace segments, connected to aTrace.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:282
virtual void SetActiveLayer(PCB_LAYER_ID aLayer) override
Function SetActiveLayer will change the currently active layer to aLayer and also update the PCB_LAYE...
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:296
void Remove(BOARD_ITEM *aBoardItem) override
Removes an item from the container.
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:204