2014-10-23 17:53:38 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-10-14 19:07:04 +00:00
|
|
|
* Copyright (C) 2007-2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-10-23 17:53:38 +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
|
|
|
|
*/
|
|
|
|
|
2011-09-16 15:54:50 +00:00
|
|
|
/**
|
|
|
|
* @file edit_track_width.cpp
|
2011-09-20 13:57:40 +00:00
|
|
|
* @brief Functions to modify sizes of segment, track, net, all vias and/or all tracks.
|
2011-09-16 15:54:50 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <wxPcbStruct.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_track.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <drc_stuff.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
bool PCB_EDIT_FRAME::SetTrackSegmentWidth( TRACK* aTrackItem,
|
|
|
|
PICKED_ITEMS_LIST* aItemsListPicker,
|
|
|
|
bool aUseNetclassValue )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2016-10-14 19:07:04 +00:00
|
|
|
/* Modify one track segment width or one via diameter and drill (using DRC control).
|
|
|
|
* Basic function used by other routines when editing tracks or vias
|
|
|
|
* aTrackItem = the track segment or via to modify
|
|
|
|
* aItemsListPicker = the list picker to use for an undo command (can be NULL)
|
|
|
|
* aUseNetclassValue = true to use NetClass value, false to use BOARD::m_designSettings value
|
|
|
|
* return true if done, false if no not change (due to DRC error)
|
|
|
|
*/
|
2010-12-05 16:24:08 +00:00
|
|
|
int initial_width, new_width;
|
|
|
|
int initial_drill = -1,new_drill = -1;
|
2009-10-10 17:27:53 +00:00
|
|
|
bool change_ok = false;
|
|
|
|
NETINFO_ITEM* net = NULL;
|
|
|
|
|
|
|
|
if( aUseNetclassValue )
|
2014-02-25 10:40:34 +00:00
|
|
|
net = aTrackItem->GetNet();
|
2007-12-01 03:42:52 +00:00
|
|
|
|
2013-01-13 00:04:00 +00:00
|
|
|
initial_width = aTrackItem->GetWidth();
|
2010-12-05 16:24:08 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
if( net )
|
|
|
|
new_width = net->GetTrackWidth();
|
|
|
|
else
|
2014-05-13 09:22:51 +00:00
|
|
|
new_width = GetDesignSettings().GetCurrentTrackWidth();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( aTrackItem->Type() == PCB_VIA_T )
|
2007-12-01 03:42:52 +00:00
|
|
|
{
|
2014-04-25 06:00:04 +00:00
|
|
|
const VIA *via = static_cast<const VIA *>( aTrackItem );
|
|
|
|
|
2015-06-19 08:55:37 +00:00
|
|
|
// Micro vias have a size only defined in their netclass
|
|
|
|
// (no specific values defined by a table of specific value)
|
2015-06-19 09:06:52 +00:00
|
|
|
// Ensure the netclass is accessible:
|
2015-06-19 08:55:37 +00:00
|
|
|
if( via->GetViaType() == VIA_MICROVIA && net == NULL )
|
|
|
|
net = aTrackItem->GetNet();
|
|
|
|
|
2015-06-18 13:19:30 +00:00
|
|
|
// Get the draill value, regardless it is default or specific
|
|
|
|
initial_drill = via->GetDrillValue();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
if( net )
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2009-10-10 17:27:53 +00:00
|
|
|
new_width = net->GetViaSize();
|
2015-06-18 13:19:30 +00:00
|
|
|
new_drill = net->GetViaDrillSize();
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2009-10-10 17:27:53 +00:00
|
|
|
else
|
2009-10-30 17:58:15 +00:00
|
|
|
{
|
2014-05-13 09:22:51 +00:00
|
|
|
new_width = GetDesignSettings().GetCurrentViaSize();
|
|
|
|
new_drill = GetDesignSettings().GetCurrentViaDrill();
|
2009-10-30 17:58:15 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
if( via->GetViaType() == VIA_MICROVIA )
|
2009-10-10 17:27:53 +00:00
|
|
|
{
|
|
|
|
if( net )
|
2015-06-18 13:19:30 +00:00
|
|
|
{
|
2009-10-30 17:58:15 +00:00
|
|
|
new_width = net->GetMicroViaSize();
|
2015-06-18 13:19:30 +00:00
|
|
|
new_drill = net->GetMicroViaDrillSize();
|
|
|
|
}
|
2013-12-29 10:15:06 +00:00
|
|
|
else
|
2015-06-19 08:55:37 +00:00
|
|
|
{
|
|
|
|
// Should not occur
|
|
|
|
}
|
2009-10-10 17:27:53 +00:00
|
|
|
}
|
2015-06-18 13:19:30 +00:00
|
|
|
|
|
|
|
// Old versions set a drill value <= 0, when the default netclass it used
|
|
|
|
// but it could be better to set the drill value to the actual value
|
|
|
|
// to avoid issues for existing vias, if the default drill value is modified
|
|
|
|
// in the netclass, and not in current vias.
|
2015-06-19 08:55:37 +00:00
|
|
|
if( via->GetDrill() <= 0 ) // means default netclass drill value used
|
2015-06-18 13:19:30 +00:00
|
|
|
{
|
|
|
|
initial_drill = -1; // Force drill vias re-initialization
|
|
|
|
}
|
2007-12-01 03:42:52 +00:00
|
|
|
}
|
|
|
|
|
2013-01-13 00:04:00 +00:00
|
|
|
aTrackItem->SetWidth( new_width );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-02-06 05:44:19 +00:00
|
|
|
// make a DRC test because the new size is bigger than the old size
|
2011-09-16 15:54:50 +00:00
|
|
|
if( initial_width < new_width )
|
2007-12-01 03:42:52 +00:00
|
|
|
{
|
2009-08-08 06:07:08 +00:00
|
|
|
int diagdrc = OK_DRC;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-03-27 18:32:12 +00:00
|
|
|
if( g_Drc_On )
|
2009-08-08 06:07:08 +00:00
|
|
|
diagdrc = m_drc->Drc( aTrackItem, GetBoard()->m_Track );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
if( diagdrc == OK_DRC )
|
|
|
|
change_ok = true;
|
|
|
|
}
|
|
|
|
else if( initial_width > new_width )
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2009-08-08 06:07:08 +00:00
|
|
|
change_ok = true;
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2015-06-18 13:19:30 +00:00
|
|
|
else if( (aTrackItem->Type() == PCB_VIA_T) )
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2015-06-18 13:19:30 +00:00
|
|
|
// if a via has its drill value changed, force change
|
|
|
|
if( initial_drill != new_drill )
|
|
|
|
change_ok = true;
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2009-08-08 06:07:08 +00:00
|
|
|
|
|
|
|
if( change_ok )
|
|
|
|
{
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
if( aItemsListPicker )
|
|
|
|
{
|
2013-01-13 00:04:00 +00:00
|
|
|
aTrackItem->SetWidth( initial_width );
|
2009-08-08 06:07:08 +00:00
|
|
|
ITEM_PICKER picker( aTrackItem, UR_CHANGED );
|
2012-02-05 13:02:46 +00:00
|
|
|
picker.SetLink( aTrackItem->Clone() );
|
2009-08-08 06:07:08 +00:00
|
|
|
aItemsListPicker->PushItem( picker );
|
2013-01-13 00:04:00 +00:00
|
|
|
aTrackItem->SetWidth( new_width );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( aTrackItem->Type() == PCB_VIA_T )
|
2010-12-05 16:24:08 +00:00
|
|
|
{
|
|
|
|
// Set new drill value. Note: currently microvias have only a default drill value
|
2014-04-25 06:00:04 +00:00
|
|
|
VIA *via = static_cast<VIA *>( aTrackItem );
|
2010-12-05 16:24:08 +00:00
|
|
|
if( new_drill > 0 )
|
2014-04-25 06:00:04 +00:00
|
|
|
via->SetDrill( new_drill );
|
2010-12-05 16:24:08 +00:00
|
|
|
else
|
2014-04-25 06:00:04 +00:00
|
|
|
via->SetDrillDefault();
|
2010-12-05 16:24:08 +00:00
|
|
|
}
|
2009-08-08 06:07:08 +00:00
|
|
|
}
|
2007-12-01 03:42:52 +00:00
|
|
|
}
|
|
|
|
else
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2013-01-13 00:04:00 +00:00
|
|
|
aTrackItem->SetWidth( initial_width );
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2007-12-01 03:42:52 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
return change_ok;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-01 03:42:52 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Edit_TrackSegm_Width
|
2009-08-08 06:07:08 +00:00
|
|
|
* Modify one track segment width or one via diameter (using DRC control).
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aDC = the curred device context (can be NULL)
|
2009-08-08 06:07:08 +00:00
|
|
|
* @param aTrackItem = the track segment or via to modify
|
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::Edit_TrackSegm_Width( wxDC* aDC, TRACK* aTrackItem )
|
2009-08-08 06:07:08 +00:00
|
|
|
{
|
|
|
|
PICKED_ITEMS_LIST itemsListPicker;
|
2009-10-10 17:27:53 +00:00
|
|
|
bool change = SetTrackSegmentWidth( aTrackItem, &itemsListPicker, false );
|
2009-08-08 06:07:08 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( change == 0 || aTrackItem->GetFlags() )
|
2009-08-08 06:07:08 +00:00
|
|
|
return; // No change
|
|
|
|
|
|
|
|
// The segment has changed: redraw it and save it in undo list
|
2010-12-29 17:47:32 +00:00
|
|
|
if( aDC )
|
2009-08-08 06:07:08 +00:00
|
|
|
{
|
2009-10-07 17:10:37 +00:00
|
|
|
TRACK* oldsegm = (TRACK*) itemsListPicker.GetPickedItemLink( 0 );
|
2009-10-10 17:27:53 +00:00
|
|
|
wxASSERT( oldsegm );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOff( aDC ); // Erase cursor shape
|
|
|
|
oldsegm->Draw( m_canvas, aDC, GR_XOR ); // Erase old track shape
|
|
|
|
aTrackItem->Draw( m_canvas, aDC, GR_OR ); // Display new track shape
|
|
|
|
m_canvas->CrossHairOn( aDC ); // Display cursor shape
|
2009-08-08 06:07:08 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
SaveCopyInUndoList( itemsListPicker, UR_CHANGED );
|
|
|
|
}
|
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::Edit_Track_Width( wxDC* aDC, TRACK* aTrackSegment )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2016-10-14 19:07:04 +00:00
|
|
|
/* Modify a full track (a trace) width (using DRC control).
|
|
|
|
* a full track is the set of track segments between 2 nodes: pads or a node that has
|
|
|
|
* more than 2 segments connected
|
|
|
|
* aDC = the curred device context (can be NULL)
|
|
|
|
* aTrackSegment = a via or a track belonging to the trace to change
|
|
|
|
*/
|
2007-12-01 03:42:52 +00:00
|
|
|
TRACK* pt_track;
|
2009-08-08 06:07:08 +00:00
|
|
|
int nb_segm;
|
2007-12-01 03:42:52 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
if( aTrackSegment == NULL )
|
2007-12-01 03:42:52 +00:00
|
|
|
return;
|
|
|
|
|
2011-09-16 15:54:50 +00:00
|
|
|
pt_track = GetBoard()->MarkTrace( aTrackSegment, &nb_segm, NULL, NULL, true );
|
2009-08-08 06:07:08 +00:00
|
|
|
|
|
|
|
PICKED_ITEMS_LIST itemsListPicker;
|
|
|
|
bool change = false;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
for( int ii = 0; ii < nb_segm; ii++, pt_track = pt_track->Next() )
|
2007-12-01 03:42:52 +00:00
|
|
|
{
|
2013-03-27 18:32:12 +00:00
|
|
|
pt_track->SetState( BUSY, false );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
if( SetTrackSegmentWidth( pt_track, &itemsListPicker, false ) )
|
2009-08-08 06:07:08 +00:00
|
|
|
change = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !change )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Some segment have changed: redraw them and save in undo list
|
2010-12-29 17:47:32 +00:00
|
|
|
if( aDC )
|
2009-08-08 06:07:08 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOff( aDC ); // Erase cursor shape
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
for( unsigned ii = 0; ii < itemsListPicker.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
TRACK* segm = (TRACK*) itemsListPicker.GetPickedItemLink( ii );
|
2011-12-22 13:28:11 +00:00
|
|
|
segm->Draw( m_canvas, aDC, GR_XOR ); // Erase old track shape
|
2009-08-08 06:07:08 +00:00
|
|
|
segm = (TRACK*) itemsListPicker.GetPickedItem( ii );
|
2011-12-22 13:28:11 +00:00
|
|
|
segm->Draw( m_canvas, aDC, GR_OR ); // Display new track shape
|
2016-10-14 19:07:04 +00:00
|
|
|
|
2016-12-05 22:54:41 +00:00
|
|
|
// fixme: commit!
|
|
|
|
// segm->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
2009-08-08 06:07:08 +00:00
|
|
|
}
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOn( aDC ); // Display cursor shape
|
2007-12-01 03:42:52 +00:00
|
|
|
}
|
2009-08-08 06:07:08 +00:00
|
|
|
|
|
|
|
SaveCopyInUndoList( itemsListPicker, UR_CHANGED );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
bool PCB_EDIT_FRAME::Change_Net_Tracks_And_Vias_Sizes( int aNetcode, bool aUseNetclassValue )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2016-10-14 19:07:04 +00:00
|
|
|
/* Reset all tracks width and vias diameters and drill
|
|
|
|
* to their default Netclass value or current values
|
|
|
|
* aNetcode : the netcode of the net to edit
|
|
|
|
* aUseNetclassValue = true to use netclass values, false to use current values
|
|
|
|
*/
|
2007-12-01 03:42:52 +00:00
|
|
|
TRACK* pt_segm;
|
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
if( aNetcode <= 0 )
|
2009-10-30 17:58:15 +00:00
|
|
|
return false;
|
2007-12-01 03:42:52 +00:00
|
|
|
|
2012-02-06 05:44:19 +00:00
|
|
|
// Examine segments
|
2009-08-08 06:07:08 +00:00
|
|
|
PICKED_ITEMS_LIST itemsListPicker;
|
|
|
|
bool change = false;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
for( pt_segm = GetBoard()->m_Track; pt_segm != NULL; pt_segm = pt_segm->Next() )
|
2007-12-01 03:42:52 +00:00
|
|
|
{
|
2014-02-25 10:40:34 +00:00
|
|
|
if( aNetcode != pt_segm->GetNetCode() ) // not in net
|
2007-12-01 03:42:52 +00:00
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-02-06 05:44:19 +00:00
|
|
|
// we have found a item member of the net
|
2009-10-30 17:58:15 +00:00
|
|
|
if( SetTrackSegmentWidth( pt_segm, &itemsListPicker, aUseNetclassValue ) )
|
2009-08-08 06:07:08 +00:00
|
|
|
change = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !change )
|
2009-10-30 17:58:15 +00:00
|
|
|
return false;
|
2009-08-08 06:07:08 +00:00
|
|
|
|
2009-10-30 17:58:15 +00:00
|
|
|
// Some segment have changed: save them in undo list
|
2009-08-08 06:07:08 +00:00
|
|
|
SaveCopyInUndoList( itemsListPicker, UR_CHANGED );
|
2009-10-30 17:58:15 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
bool PCB_EDIT_FRAME::Reset_All_Tracks_And_Vias_To_Netclass_Values( bool aTrack, bool aVia )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-12-01 03:42:52 +00:00
|
|
|
TRACK* pt_segm;
|
|
|
|
|
2012-02-06 05:44:19 +00:00
|
|
|
// read and edit tracks and vias if required
|
2009-08-08 06:07:08 +00:00
|
|
|
PICKED_ITEMS_LIST itemsListPicker;
|
|
|
|
bool change = false;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
for( pt_segm = GetBoard()->m_Track; pt_segm != NULL; pt_segm = pt_segm->Next() )
|
2007-12-01 03:42:52 +00:00
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
if( (pt_segm->Type() == PCB_VIA_T ) && aVia )
|
2007-12-01 03:42:52 +00:00
|
|
|
{
|
2009-10-10 17:27:53 +00:00
|
|
|
if( SetTrackSegmentWidth( pt_segm, &itemsListPicker, true ) )
|
2009-08-08 06:07:08 +00:00
|
|
|
change = true;
|
2007-12-01 03:42:52 +00:00
|
|
|
}
|
2009-08-08 06:07:08 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( (pt_segm->Type() == PCB_TRACE_T ) && aTrack )
|
2009-10-10 17:27:53 +00:00
|
|
|
{
|
|
|
|
if( SetTrackSegmentWidth( pt_segm, &itemsListPicker, true ) )
|
2011-03-03 19:08:13 +00:00
|
|
|
change = true;
|
2009-10-10 17:27:53 +00:00
|
|
|
}
|
2009-08-08 06:07:08 +00:00
|
|
|
}
|
2009-10-10 17:27:53 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
if( !change )
|
|
|
|
return false;
|
|
|
|
|
2009-10-30 17:58:15 +00:00
|
|
|
// Some segment have changed: save them in undo list
|
2009-08-08 06:07:08 +00:00
|
|
|
SaveCopyInUndoList( itemsListPicker, UR_CHANGED );
|
|
|
|
|
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|