2011-10-17 20:01:27 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
2011-10-17 20:01:27 +00:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file deltrack.cpp
|
|
|
|
*/
|
2009-07-30 11:04:07 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <pcbcommon.h>
|
2014-04-04 13:43:30 +00:00
|
|
|
#include <ratsnest_data.h>
|
2009-07-30 11:04:07 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_track.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <protos.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
TRACK* PCB_EDIT_FRAME::Delete_Segment( wxDC* DC, TRACK* aTrack )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int current_net_code;
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
if( aTrack == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
2008-03-04 21:39:46 +00:00
|
|
|
|
2011-02-21 13:54:29 +00:00
|
|
|
if( aTrack->IsNew() ) // Trace in progress, erase the last segment
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( g_CurrentTrackList.GetCount() > 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID previous_layer = GetActiveLayer();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-09-10 08:47:42 +00:00
|
|
|
DBG( g_CurrentTrackList.VerifyListIntegrity(); )
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
// Delete the current trace
|
2011-12-22 13:28:11 +00:00
|
|
|
ShowNewTrackWhenMovingCursor( m_canvas, DC, wxDefaultPosition, false );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
// delete the most recently entered
|
|
|
|
delete g_CurrentTrackList.PopBack();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( g_TwoSegmentTrackBuild )
|
2008-03-04 21:39:46 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
// if in 2 track mode, and the next most recent is a segment
|
|
|
|
// not a via, and the one previous to that is a via, then
|
|
|
|
// delete up to the via.
|
2008-12-04 04:28:11 +00:00
|
|
|
if( g_CurrentTrackList.GetCount() >= 2
|
2011-10-01 19:24:27 +00:00
|
|
|
&& g_CurrentTrackSegment->Type() != PCB_VIA_T
|
|
|
|
&& g_CurrentTrackSegment->Back()->Type() == PCB_VIA_T )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
delete g_CurrentTrackList.PopBack();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
while( g_CurrentTrackSegment && g_CurrentTrackSegment->Type() == PCB_VIA_T )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
delete g_CurrentTrackList.PopBack();
|
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( g_CurrentTrackSegment && g_CurrentTrackSegment->Type() != PCB_VIA_T )
|
2007-08-23 04:28:46 +00:00
|
|
|
previous_layer = g_CurrentTrackSegment->GetLayer();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
// Correct active layer which could change if a via
|
|
|
|
// has been erased
|
2014-03-21 10:17:47 +00:00
|
|
|
SetActiveLayer( previous_layer );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
UpdateStatusBar();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
|
|
|
if( g_TwoSegmentTrackBuild ) // We must have 2 segments or more, or 0
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
if( g_CurrentTrackList.GetCount() == 1
|
2011-10-01 19:24:27 +00:00
|
|
|
&& g_CurrentTrackSegment->Type() != PCB_VIA_T )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
delete g_CurrentTrackList.PopBack();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-04 04:28:11 +00:00
|
|
|
|
|
|
|
if( g_CurrentTrackList.GetCount() == 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( NULL, NULL );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2011-09-14 20:04:58 +00:00
|
|
|
if( GetBoard()->IsHighLightNetON() )
|
2011-10-17 20:01:27 +00:00
|
|
|
HighLight( DC );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2007-09-12 02:14:07 +00:00
|
|
|
SetCurItem( NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
if( m_canvas->IsMouseCaptured() )
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
return g_CurrentTrackSegment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2008-12-04 04:28:11 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2014-02-25 10:47:27 +00:00
|
|
|
current_net_code = aTrack->GetNetCode();
|
2008-03-04 21:39:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
DLIST<TRACK>* container = (DLIST<TRACK>*)aTrack->GetList();
|
2009-07-29 13:10:36 +00:00
|
|
|
wxASSERT( container );
|
2014-04-04 13:43:30 +00:00
|
|
|
GetBoard()->GetRatsnest()->Remove( aTrack );
|
|
|
|
aTrack->ViewRelease();
|
2009-07-29 13:10:36 +00:00
|
|
|
container->Remove( aTrack );
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2008-03-06 01:46:13 +00:00
|
|
|
// redraw the area where the track was
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->RefreshDrawingRect( aTrack->GetBoundingBox() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
SaveCopyInUndoList( aTrack, UR_DELETED );
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2011-09-15 17:58:35 +00:00
|
|
|
TestNetConnection( DC, current_net_code );
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( GetBoard() );
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::Delete_Track( wxDC* DC, TRACK* aTrack )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( aTrack != NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2014-02-25 10:47:27 +00:00
|
|
|
int current_net_code = aTrack->GetNetCode();
|
2008-12-04 04:28:11 +00:00
|
|
|
Remove_One_Track( DC, aTrack );
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2011-09-15 17:58:35 +00:00
|
|
|
TestNetConnection( DC, current_net_code );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::Delete_net( wxDC* DC, TRACK* aTrack )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( aTrack == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( !IsOK( this, _( "Delete NET?" ) ) )
|
2009-07-29 13:10:36 +00:00
|
|
|
return;
|
2008-03-10 15:51:44 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
PICKED_ITEMS_LIST itemsList;
|
|
|
|
ITEM_PICKER picker( NULL, UR_DELETED );
|
2014-02-25 10:47:27 +00:00
|
|
|
int net_code_delete = aTrack->GetNetCode();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
/* Search the first item for the given net code */
|
|
|
|
TRACK* trackList = GetBoard()->m_Track->GetStartNetCode( net_code_delete );
|
2008-03-10 15:51:44 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
/* Remove all segments having the given net code */
|
|
|
|
int ii = 0;
|
2009-11-14 22:15:22 +00:00
|
|
|
TRACK* next_track;
|
2009-07-29 13:10:36 +00:00
|
|
|
for( TRACK* segm = trackList; segm; segm = next_track, ++ii )
|
|
|
|
{
|
|
|
|
next_track = segm->Next();
|
2014-02-25 10:47:27 +00:00
|
|
|
if( segm->GetNetCode() != net_code_delete )
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
2014-04-04 13:43:30 +00:00
|
|
|
GetBoard()->GetRatsnest()->Remove( segm );
|
|
|
|
segm->ViewRelease();
|
2009-07-29 13:10:36 +00:00
|
|
|
GetBoard()->m_Track.Remove( segm );
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
// redraw the area where the track was
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->RefreshDrawingRect( segm->GetBoundingBox() );
|
2012-02-05 13:02:46 +00:00
|
|
|
picker.SetItem( segm );
|
2009-11-14 22:15:22 +00:00
|
|
|
itemsList.PushItem( picker );
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
2008-03-10 15:51:44 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
SaveCopyInUndoList( itemsList, UR_DELETED );
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2011-09-15 17:58:35 +00:00
|
|
|
TestNetConnection( DC, net_code_delete );
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( GetBoard() );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::Remove_One_Track( wxDC* DC, TRACK* pt_segm )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
int segments_to_delete_count;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( pt_segm == NULL )
|
|
|
|
return;
|
|
|
|
|
2011-09-16 15:54:50 +00:00
|
|
|
TRACK* trackList = GetBoard()->MarkTrace( pt_segm, &segments_to_delete_count,
|
|
|
|
NULL, NULL, true );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
if( segments_to_delete_count == 0 )
|
|
|
|
return;
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2014-02-25 10:47:27 +00:00
|
|
|
int net_code = pt_segm->GetNetCode();
|
2009-11-14 22:15:22 +00:00
|
|
|
PICKED_ITEMS_LIST itemsList;
|
|
|
|
ITEM_PICKER picker( NULL, UR_DELETED );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
int ii = 0;
|
|
|
|
TRACK* tracksegment = trackList;
|
|
|
|
TRACK* next_track;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
for( ; ii < segments_to_delete_count; ii++, tracksegment = next_track )
|
|
|
|
{
|
|
|
|
next_track = tracksegment->Next();
|
2013-03-28 06:40:19 +00:00
|
|
|
tracksegment->SetState( BUSY, false );
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2013-09-10 08:47:42 +00:00
|
|
|
DBG( std::cout << __func__ << ": track " << tracksegment << " status=" \
|
2013-03-31 13:27:46 +00:00
|
|
|
<< TO_UTF8( TRACK::ShowState( tracksegment->GetStatus() ) ) \
|
2011-09-07 19:41:04 +00:00
|
|
|
<< std::endl; )
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2014-04-04 13:43:30 +00:00
|
|
|
GetBoard()->GetRatsnest()->Remove( tracksegment );
|
|
|
|
tracksegment->ViewRelease();
|
2009-07-29 13:10:36 +00:00
|
|
|
GetBoard()->m_Track.Remove( tracksegment );
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
// redraw the area where the track was
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->RefreshDrawingRect( tracksegment->GetBoundingBox() );
|
2012-02-05 13:02:46 +00:00
|
|
|
picker.SetItem( tracksegment );
|
2009-11-14 22:15:22 +00:00
|
|
|
itemsList.PushItem( picker );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2009-07-29 13:10:36 +00:00
|
|
|
|
|
|
|
SaveCopyInUndoList( itemsList, UR_DELETED );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( net_code > 0 )
|
2011-09-15 17:58:35 +00:00
|
|
|
TestNetConnection( DC, net_code );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|