2011-10-17 20:01:27 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-06-18 13:19:30 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
2015-06-18 13:19:30 +00:00
|
|
|
* Copyright (C) 1992-2015 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 editrack-part2.cpp
|
|
|
|
*/
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_marker_pcb.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
2018-01-28 21:02:31 +00:00
|
|
|
#include <drc.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2018-01-31 16:09:26 +00:00
|
|
|
#include <connectivity_data.h>
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
unsigned itmp;
|
2007-08-04 04:40:07 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
if( aTrack == NULL )
|
2007-08-04 04:40:07 +00:00
|
|
|
{
|
2015-09-03 07:44:30 +00:00
|
|
|
if( GetActiveLayer() != GetScreen()->m_Route_Layer_TOP )
|
|
|
|
SetActiveLayer( GetScreen()->m_Route_Layer_TOP );
|
2007-08-04 04:40:07 +00:00
|
|
|
else
|
2015-09-03 07:44:30 +00:00
|
|
|
SetActiveLayer( GetScreen()->m_Route_Layer_BOTTOM );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
UpdateStatusBar();
|
2007-12-14 22:31:45 +00:00
|
|
|
return true;
|
2007-08-04 04:40:07 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 17:45:37 +00:00
|
|
|
// Avoid more than one via on the current location:
|
2013-01-13 00:04:00 +00:00
|
|
|
if( GetBoard()->GetViaByPosition( g_CurrentTrackSegment->GetEnd(),
|
2011-09-14 20:04:58 +00:00
|
|
|
g_CurrentTrackSegment->GetLayer() ) )
|
2007-12-14 22:31:45 +00:00
|
|
|
return false;
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
for( TRACK* segm = g_FirstTrackSegment; segm; segm = segm->Next() )
|
2007-08-04 04:40:07 +00:00
|
|
|
{
|
2013-01-13 00:04:00 +00:00
|
|
|
if( segm->Type() == PCB_VIA_T && g_CurrentTrackSegment->GetEnd() == segm->GetStart() )
|
2007-12-14 22:31:45 +00:00
|
|
|
return false;
|
2007-08-04 04:40:07 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 17:45:37 +00:00
|
|
|
// Is the current segment Ok (no DRC error) ?
|
2017-08-04 12:43:02 +00:00
|
|
|
if( Settings().m_legacyDrcOn )
|
2007-09-20 06:45:17 +00:00
|
|
|
{
|
2018-06-04 08:44:25 +00:00
|
|
|
if( BAD_DRC==m_drc->DrcOnCreatingTrack( g_CurrentTrackSegment, GetBoard()->m_Track ) )
|
2012-02-02 17:45:37 +00:00
|
|
|
// DRC error, the change layer is not made
|
2007-12-14 22:31:45 +00:00
|
|
|
return false;
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
// Handle 2 segments.
|
2017-08-04 12:43:02 +00:00
|
|
|
if( Settings().m_legacyUseTwoSegmentTracks && g_CurrentTrackSegment->Back() )
|
2007-09-20 06:45:17 +00:00
|
|
|
{
|
2018-06-04 08:44:25 +00:00
|
|
|
if( BAD_DRC == m_drc->DrcOnCreatingTrack( g_CurrentTrackSegment->Back(),
|
|
|
|
GetBoard()->m_Track ) )
|
2007-12-14 22:31:45 +00:00
|
|
|
return false;
|
2007-09-20 06:45:17 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-04 04:40:07 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
/* Save current state before placing a via.
|
2009-11-14 22:15:22 +00:00
|
|
|
* If the via cannot be placed this current state will be reused
|
2008-12-04 04:28:11 +00:00
|
|
|
*/
|
|
|
|
itmp = g_CurrentTrackList.GetCount();
|
2007-08-04 04:40:07 +00:00
|
|
|
Begin_Route( g_CurrentTrackSegment, DC );
|
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2007-08-04 04:40:07 +00:00
|
|
|
|
2012-02-02 17:45:37 +00:00
|
|
|
// create the via
|
2014-04-25 06:00:04 +00:00
|
|
|
VIA* via = new VIA( GetBoard() );
|
2011-12-21 13:42:02 +00:00
|
|
|
via->SetFlags( IS_NEW );
|
2014-04-25 06:00:04 +00:00
|
|
|
via->SetViaType( GetDesignSettings().m_CurrentViaType );
|
2014-02-25 10:47:27 +00:00
|
|
|
via->SetNetCode( GetBoard()->GetHighLightNetCode() );
|
2015-06-18 13:19:30 +00:00
|
|
|
via->SetPosition( g_CurrentTrackSegment->GetEnd() );
|
|
|
|
|
|
|
|
// for microvias, the size and hole will be changed later.
|
|
|
|
via->SetWidth( GetDesignSettings().GetCurrentViaSize());
|
|
|
|
via->SetDrill( GetDesignSettings().GetCurrentViaDrill() );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-01-25 20:06:56 +00:00
|
|
|
// Usual via is from copper to component.
|
2014-06-24 16:17:18 +00:00
|
|
|
// layer pair is B_Cu and F_Cu.
|
|
|
|
via->SetLayerPair( B_Cu, F_Cu );
|
2010-01-25 20:06:56 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID first_layer = GetActiveLayer();
|
|
|
|
PCB_LAYER_ID last_layer;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-01-25 20:06:56 +00:00
|
|
|
// prepare switch to new active layer:
|
|
|
|
if( first_layer != GetScreen()->m_Route_Layer_TOP )
|
|
|
|
last_layer = GetScreen()->m_Route_Layer_TOP;
|
2007-08-04 04:40:07 +00:00
|
|
|
else
|
2010-01-25 20:06:56 +00:00
|
|
|
last_layer = GetScreen()->m_Route_Layer_BOTTOM;
|
2007-08-04 04:40:07 +00:00
|
|
|
|
2012-02-02 17:45:37 +00:00
|
|
|
// Adjust the actual via layer pair
|
2014-06-24 16:17:18 +00:00
|
|
|
switch( via->GetViaType() )
|
2008-04-01 05:21:50 +00:00
|
|
|
{
|
2014-06-29 20:33:29 +00:00
|
|
|
case VIA_BLIND_BURIED:
|
|
|
|
via->SetLayerPair( first_layer, last_layer );
|
|
|
|
break;
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2014-06-29 20:33:29 +00:00
|
|
|
case VIA_MICROVIA: // from external to the near neighbor inner layer
|
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID last_inner_layer = ToLAYER_ID( ( GetBoard()->GetCopperLayerCount() - 2 ) );
|
2014-06-29 20:33:29 +00:00
|
|
|
|
|
|
|
if( first_layer == B_Cu )
|
|
|
|
last_layer = last_inner_layer;
|
|
|
|
else if( first_layer == F_Cu )
|
|
|
|
last_layer = In1_Cu;
|
|
|
|
else if( first_layer == last_inner_layer )
|
|
|
|
last_layer = B_Cu;
|
|
|
|
else if( first_layer == In1_Cu )
|
|
|
|
last_layer = F_Cu;
|
|
|
|
// else error: will be removed later
|
|
|
|
via->SetLayerPair( first_layer, last_layer );
|
2015-06-18 13:19:30 +00:00
|
|
|
|
|
|
|
// Update diameter and hole size, which where set previously
|
|
|
|
// for normal vias
|
|
|
|
NETINFO_ITEM* net = via->GetNet();
|
|
|
|
via->SetWidth( net->GetMicroViaSize() );
|
|
|
|
via->SetDrill( net->GetMicroViaDrillSize() );
|
2014-06-29 20:33:29 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2014-06-29 20:33:29 +00:00
|
|
|
default:
|
|
|
|
break;
|
2007-10-01 04:34:11 +00:00
|
|
|
}
|
2007-10-15 07:50:59 +00:00
|
|
|
|
2018-06-04 08:44:25 +00:00
|
|
|
if( Settings().m_legacyDrcOn &&
|
|
|
|
BAD_DRC == m_drc->DrcOnCreatingTrack( via, GetBoard()->m_Track ) )
|
2007-09-20 06:45:17 +00:00
|
|
|
{
|
2012-02-02 17:45:37 +00:00
|
|
|
// DRC fault: the Via cannot be placed here ...
|
2008-12-04 04:28:11 +00:00
|
|
|
delete via;
|
2007-12-18 00:04:08 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2007-12-18 02:34:54 +00:00
|
|
|
|
2008-04-01 05:21:50 +00:00
|
|
|
// delete the track(s) added in Begin_Route()
|
2008-12-04 04:28:11 +00:00
|
|
|
while( g_CurrentTrackList.GetCount() > itmp )
|
2007-12-18 00:04:08 +00:00
|
|
|
{
|
|
|
|
Delete_Segment( DC, g_CurrentTrackSegment );
|
|
|
|
}
|
2007-12-18 02:34:54 +00:00
|
|
|
|
2011-06-09 13:30:46 +00:00
|
|
|
SetCurItem( g_CurrentTrackSegment, false );
|
|
|
|
|
|
|
|
// Refresh DRC diag, erased by previous calls
|
|
|
|
if( m_drc->GetCurrentMarker() )
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( m_drc->GetCurrentMarker() );
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2007-12-14 22:31:45 +00:00
|
|
|
return false;
|
2007-08-04 04:40:07 +00:00
|
|
|
}
|
|
|
|
|
2014-03-21 10:17:47 +00:00
|
|
|
SetActiveLayer( last_layer );
|
2010-01-25 20:06:56 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
TRACK* lastNonVia = g_CurrentTrackSegment;
|
|
|
|
|
2007-09-04 14:28:20 +00:00
|
|
|
/* A new via was created. It was Ok.
|
2007-09-20 06:45:17 +00:00
|
|
|
*/
|
2008-12-04 04:28:11 +00:00
|
|
|
g_CurrentTrackList.PushBack( via );
|
2007-09-20 06:45:17 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
/* The via is now in linked list and we need a new track segment
|
|
|
|
* after the via, starting at via location.
|
|
|
|
* it will become the new current segment (from via to the mouse cursor)
|
|
|
|
*/
|
2007-09-20 06:45:17 +00:00
|
|
|
|
2012-01-14 19:50:32 +00:00
|
|
|
TRACK* track = (TRACK*)lastNonVia->Clone();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
|
|
|
/* the above creates a new segment from the last entered segment, with the
|
|
|
|
* current width, flags, netcode, etc... values.
|
|
|
|
* layer, start and end point are not correct,
|
|
|
|
* and will be modified next
|
2007-09-20 06:45:17 +00:00
|
|
|
*/
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
// set the layer to the new value
|
2014-03-21 10:17:47 +00:00
|
|
|
track->SetLayer( GetActiveLayer() );
|
2007-09-20 06:45:17 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* the start point is the via position and the end point is the cursor
|
|
|
|
* which also is on the via (will change when moving mouse)
|
2008-12-04 04:28:11 +00:00
|
|
|
*/
|
2013-01-13 00:04:00 +00:00
|
|
|
track->SetEnd( via->GetStart() );
|
2014-01-08 14:18:51 +00:00
|
|
|
track->SetStart( via->GetStart() );
|
2007-09-20 06:45:17 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
g_CurrentTrackList.PushBack( track );
|
2007-09-20 06:45:17 +00:00
|
|
|
|
2017-08-04 12:43:02 +00:00
|
|
|
if( Settings().m_legacyUseTwoSegmentTracks )
|
2007-09-20 06:45:17 +00:00
|
|
|
{
|
2007-08-30 22:20:52 +00:00
|
|
|
// Create a second segment (we must have 2 track segments to adjust)
|
2012-01-14 19:50:32 +00:00
|
|
|
g_CurrentTrackList.PushBack( (TRACK*)g_CurrentTrackSegment->Clone() );
|
2007-08-04 04:40:07 +00:00
|
|
|
}
|
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( via );
|
2009-04-05 20:49:15 +00:00
|
|
|
UpdateStatusBar();
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2007-12-14 22:31:45 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2018-01-31 16:09:26 +00:00
|
|
|
|
|
|
|
static void ListSetState( EDA_ITEM* Start, int NbItem, STATUS_FLAGS State,
|
|
|
|
bool onoff );
|
|
|
|
|
|
|
|
|
|
|
|
void DrawTraces( EDA_DRAW_PANEL* panel, wxDC* DC, TRACK* aTrackList, int nbsegment,
|
|
|
|
GR_DRAWMODE draw_mode )
|
|
|
|
{
|
|
|
|
// preserve the start of the list for debugging.
|
|
|
|
for( TRACK* track = aTrackList; nbsegment > 0 && track; nbsegment--, track = track->Next() )
|
|
|
|
{
|
|
|
|
track->Draw( panel, DC, draw_mode );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function try to remove an old track, when a new track is created,
|
|
|
|
* and the old track is no more needed
|
|
|
|
*/
|
|
|
|
int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC,
|
|
|
|
TRACK* aNewTrack,
|
|
|
|
int aNewTrackSegmentsCount,
|
|
|
|
PICKED_ITEMS_LIST* aItemsListPicker )
|
|
|
|
{
|
|
|
|
TRACK* StartTrack, * EndTrack;
|
|
|
|
TRACK* pt_segm;
|
|
|
|
TRACK* pt_del;
|
2018-06-12 08:05:12 +00:00
|
|
|
int nb_segm, nbconnect;
|
2018-01-31 16:09:26 +00:00
|
|
|
wxPoint start;
|
|
|
|
wxPoint end;
|
|
|
|
LSET startmasklayer, endmasklayer;
|
|
|
|
int netcode = aNewTrack->GetNetCode();
|
|
|
|
|
2018-06-12 08:05:12 +00:00
|
|
|
// Reconstruct the complete track (the new track has to start on a segment of track).
|
|
|
|
// Note: aNewTrackSegmentsCount conatins the number of new track segments
|
2018-01-31 16:09:26 +00:00
|
|
|
ListSetState( aNewTrack, aNewTrackSegmentsCount, BUSY, false );
|
|
|
|
|
|
|
|
/* If the new track begins with a via, complete the track segment using
|
|
|
|
* the following segment as a reference because a via is often a hub of
|
|
|
|
* segments, and does not characterize track.
|
|
|
|
*/
|
|
|
|
if( aNewTrack->Type() == PCB_VIA_T && ( aNewTrackSegmentsCount > 1 ) )
|
|
|
|
aNewTrack = aNewTrack->Next();
|
|
|
|
|
2018-06-12 08:05:12 +00:00
|
|
|
// When MarkTrace try to find the entire track, if the starting segment
|
|
|
|
// is fully inside a pad, MarkTrace does not find correctly the full trace,
|
|
|
|
// because the entire track is the set of segments between 2 nodes
|
|
|
|
// (pads or point connecting more than 2 items)
|
2018-07-08 12:12:40 +00:00
|
|
|
// so use another (better) starting segment in this case
|
2018-06-12 08:05:12 +00:00
|
|
|
TRACK* track_segment = aNewTrack;
|
2018-01-31 16:09:26 +00:00
|
|
|
|
2018-06-12 08:05:12 +00:00
|
|
|
for( int ii = 0; ii < aNewTrackSegmentsCount; ii++ )
|
2018-01-31 16:09:26 +00:00
|
|
|
{
|
2018-06-12 08:05:12 +00:00
|
|
|
D_PAD* pad_st = m_Pcb->GetPad( aNewTrack->GetStart() );
|
|
|
|
D_PAD* pad_end = m_Pcb->GetPad( aNewTrack->GetEnd() );
|
2018-01-31 16:09:26 +00:00
|
|
|
|
2018-06-12 08:05:12 +00:00
|
|
|
if( pad_st && pad_st == pad_end )
|
|
|
|
track_segment = aNewTrack->Next();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2018-01-31 16:09:26 +00:00
|
|
|
|
2018-06-12 08:05:12 +00:00
|
|
|
// Mark the full trace containing track_segment, and recalculate the
|
|
|
|
// beginning of the trace, and the number of segments, as the new trace
|
|
|
|
// can contain also already existing track segments
|
2018-06-12 14:50:18 +00:00
|
|
|
aNewTrack = GetBoard()->MarkTrace( GetBoard()->m_Track, track_segment,
|
|
|
|
&aNewTrackSegmentsCount,
|
2018-06-12 08:05:12 +00:00
|
|
|
nullptr, nullptr, true );
|
|
|
|
wxASSERT( aNewTrack );
|
2018-01-31 16:09:26 +00:00
|
|
|
|
|
|
|
TRACK* bufStart = m_Pcb->m_Track->GetStartNetCode( netcode ); // Beginning of tracks of the net
|
|
|
|
TRACK* bufEnd = bufStart->GetEndNetCode( netcode ); // End of tracks of the net
|
|
|
|
|
|
|
|
// Flags for cleaning the net.
|
|
|
|
for( pt_del = bufStart; pt_del; pt_del = pt_del->Next() )
|
|
|
|
{
|
2018-06-12 08:05:12 +00:00
|
|
|
// printf( "track %p turning off BUSY | IN_EDIT | IS_LINKED\n", pt_del );
|
2018-01-31 16:09:26 +00:00
|
|
|
pt_del->SetState( BUSY | IN_EDIT | IS_LINKED, false );
|
|
|
|
|
|
|
|
if( pt_del == bufEnd ) // Last segment reached
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aNewTrack->GetEndSegments( aNewTrackSegmentsCount, &StartTrack, &EndTrack ) == 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( ( StartTrack == NULL ) || ( EndTrack == NULL ) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
start = StartTrack->GetStart();
|
|
|
|
end = EndTrack->GetEnd();
|
|
|
|
|
|
|
|
// The start and end points cannot be the same.
|
|
|
|
if( start == end )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Determine layers interconnected these points.
|
|
|
|
startmasklayer = StartTrack->GetLayerSet();
|
|
|
|
endmasklayer = EndTrack->GetLayerSet();
|
|
|
|
|
|
|
|
// There may be a via or a pad on the end points.
|
|
|
|
pt_segm = m_Pcb->m_Track->GetVia( NULL, start, startmasklayer );
|
|
|
|
|
|
|
|
if( pt_segm )
|
|
|
|
startmasklayer |= pt_segm->GetLayerSet();
|
|
|
|
|
|
|
|
if( StartTrack->start && ( StartTrack->start->Type() == PCB_PAD_T ) )
|
|
|
|
{
|
|
|
|
// Start on pad.
|
|
|
|
D_PAD* pad = (D_PAD*) StartTrack->start;
|
|
|
|
startmasklayer |= pad->GetLayerSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
pt_segm = m_Pcb->m_Track->GetVia( NULL, end, endmasklayer );
|
|
|
|
|
|
|
|
if( pt_segm )
|
|
|
|
endmasklayer |= pt_segm->GetLayerSet();
|
|
|
|
|
|
|
|
if( EndTrack->end && ( EndTrack->end->Type() == PCB_PAD_T ) )
|
|
|
|
{
|
|
|
|
D_PAD* pad = (D_PAD*) EndTrack->end;
|
|
|
|
endmasklayer |= pad->GetLayerSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark as deleted a new track (which is not involved in the search for other connections)
|
|
|
|
ListSetState( aNewTrack, aNewTrackSegmentsCount, IS_DELETED, true );
|
|
|
|
|
|
|
|
/* A segment must be connected to the starting point, otherwise
|
|
|
|
* it is unnecessary to analyze the other point
|
|
|
|
*/
|
|
|
|
pt_segm = GetTrack( bufStart, bufEnd, start, startmasklayer );
|
|
|
|
|
|
|
|
if( pt_segm == NULL ) // Not connected to the track starting point.
|
|
|
|
{
|
|
|
|
// Clear the delete flag.
|
|
|
|
ListSetState( aNewTrack, aNewTrackSegmentsCount, IS_DELETED, false );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Marking a list of candidate segmented connect to endpoint
|
|
|
|
* Note: the vias are not taken into account because they do
|
|
|
|
* not define a track, since they are on an intersection.
|
|
|
|
*/
|
|
|
|
for( pt_del = bufStart, nbconnect = 0; ; )
|
|
|
|
{
|
|
|
|
pt_segm = GetTrack( pt_del, bufEnd, end, endmasklayer );
|
|
|
|
|
|
|
|
if( pt_segm == NULL )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( pt_segm->Type() != PCB_VIA_T )
|
|
|
|
{
|
|
|
|
if( pt_segm->GetState( IS_LINKED ) == 0 )
|
|
|
|
{
|
|
|
|
pt_segm->SetState( IS_LINKED, true );
|
|
|
|
nbconnect++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pt_del == bufEnd )
|
|
|
|
break;
|
|
|
|
|
|
|
|
pt_del = pt_segm->Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nbconnect == 0 )
|
|
|
|
{
|
|
|
|
// Clear used flags
|
|
|
|
for( pt_del = bufStart; pt_del; pt_del = pt_del->Next() )
|
|
|
|
{
|
|
|
|
pt_del->SetState( BUSY | IS_DELETED | IN_EDIT | IS_LINKED, false );
|
|
|
|
|
|
|
|
if( pt_del == bufEnd ) // Last segment reached
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark trace as edited (which does not involve searching for other tracks)
|
|
|
|
ListSetState( aNewTrack, aNewTrackSegmentsCount, IS_DELETED, false );
|
|
|
|
ListSetState( aNewTrack, aNewTrackSegmentsCount, IN_EDIT, true );
|
|
|
|
|
|
|
|
// Test all marked segments.
|
|
|
|
while( nbconnect )
|
|
|
|
{
|
|
|
|
for( pt_del = bufStart; pt_del; pt_del = pt_del->Next() )
|
|
|
|
{
|
|
|
|
if( pt_del->GetState( IS_LINKED ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( pt_del == bufEnd ) // Last segment reached
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nbconnect--;
|
|
|
|
|
|
|
|
if( pt_del )
|
|
|
|
pt_del->SetState( IS_LINKED, false );
|
|
|
|
|
2018-06-12 14:50:18 +00:00
|
|
|
pt_del = GetBoard()->MarkTrace( GetBoard()->m_Track, pt_del, &nb_segm,
|
|
|
|
NULL, NULL, true );
|
2018-01-31 16:09:26 +00:00
|
|
|
|
|
|
|
/* Test if the marked track is redundant, i.e. if one of marked segments
|
|
|
|
* is connected to the starting point of the new track.
|
|
|
|
*/
|
2018-06-12 08:05:12 +00:00
|
|
|
|
2018-01-31 16:09:26 +00:00
|
|
|
pt_segm = pt_del;
|
|
|
|
|
2018-06-12 08:05:12 +00:00
|
|
|
for( int ii = 0; pt_segm && (ii < nb_segm); pt_segm = pt_segm->Next(), ii++ )
|
2018-01-31 16:09:26 +00:00
|
|
|
{
|
|
|
|
if( pt_segm->GetState( BUSY ) == 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( pt_segm->GetStart() == start || pt_segm->GetEnd() == start )
|
|
|
|
{
|
|
|
|
// Marked track can be erased.
|
|
|
|
TRACK* NextS;
|
|
|
|
|
|
|
|
DrawTraces( m_canvas, aDC, pt_del, nb_segm, GR_XOR | GR_HIGHLIGHT );
|
|
|
|
|
2018-06-12 08:05:12 +00:00
|
|
|
for( int jj = 0; jj < nb_segm; jj++, pt_del = NextS )
|
2018-01-31 16:09:26 +00:00
|
|
|
{
|
|
|
|
NextS = pt_del->Next();
|
|
|
|
|
|
|
|
if( aItemsListPicker )
|
|
|
|
{
|
|
|
|
pt_del->UnLink();
|
|
|
|
pt_del->SetStatus( 0 );
|
|
|
|
pt_del->ClearFlags();
|
|
|
|
GetBoard()->GetConnectivity()->Remove( pt_del );
|
|
|
|
ITEM_PICKER picker( pt_del, UR_DELETED );
|
|
|
|
aItemsListPicker->PushItem( picker );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GetBoard()->GetConnectivity()->Remove( pt_del );
|
|
|
|
pt_del->DeleteStructure();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up flags.
|
|
|
|
for( pt_del = m_Pcb->m_Track; pt_del != NULL; pt_del = pt_del->Next() )
|
|
|
|
{
|
|
|
|
if( pt_del->GetState( IN_EDIT ) )
|
|
|
|
{
|
|
|
|
pt_del->SetState( IN_EDIT, false );
|
|
|
|
|
|
|
|
if( aDC )
|
|
|
|
pt_del->Draw( m_canvas, aDC, GR_OR );
|
|
|
|
}
|
|
|
|
|
|
|
|
pt_del->SetState( IN_EDIT | IS_LINKED, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear BUSY flag here because the track did not get marked.
|
|
|
|
ListSetState( pt_del, nb_segm, BUSY, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear used flags
|
|
|
|
for( pt_del = m_Pcb->m_Track; pt_del; pt_del = pt_del->Next() )
|
|
|
|
{
|
|
|
|
pt_del->SetState( BUSY | IS_DELETED | IN_EDIT | IS_LINKED, false );
|
|
|
|
|
|
|
|
if( pt_del == bufEnd ) // Last segment reached
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Set the bits of .m_State member to on/off value, using bit mask State
|
|
|
|
* of a list of EDA_ITEM
|
|
|
|
*/
|
|
|
|
static void ListSetState( EDA_ITEM* Start, int NbItem, STATUS_FLAGS State,
|
|
|
|
bool onoff )
|
|
|
|
{
|
|
|
|
for( ; (Start != NULL ) && ( NbItem > 0 ); NbItem--, Start = Start->Next() )
|
|
|
|
{
|
|
|
|
Start->SetState( State, onoff );
|
|
|
|
}
|
|
|
|
}
|