kicad/pcbnew/dialogs/dialog_track_via_properties...

636 lines
20 KiB
C++
Raw Normal View History

2015-07-09 11:35:51 +00:00
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* 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
*/
#include <dialogs/dialog_track_via_properties.h>
2018-01-31 08:23:20 +00:00
#include <pcb_layer_box_selector.h>
2015-07-09 11:35:51 +00:00
#include <tools/selection_tool.h>
#include <class_track.h>
2018-01-29 20:58:58 +00:00
#include <pcb_edit_frame.h>
2015-07-09 11:35:51 +00:00
#include <confirm.h>
#include <widgets/text_ctrl_eval.h>
2015-07-09 11:35:51 +00:00
#include <widgets/widget_net_selector.h>
#include <board_commit.h>
2015-07-09 11:35:51 +00:00
DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParent, const SELECTION& aItems ) :
DIALOG_TRACK_VIA_PROPERTIES_BASE( aParent ), m_items( aItems ),
m_trackStartX( aParent, m_TrackStartXCtrl, m_TrackStartXUnit ),
m_trackStartY( aParent, m_TrackStartYCtrl, m_TrackStartYUnit ),
m_trackEndX( aParent, m_TrackEndXCtrl, m_TrackEndXUnit ),
m_trackEndY( aParent, m_TrackEndYCtrl, m_TrackEndYUnit ),
m_trackWidth( aParent, m_TrackWidthCtrl, m_TrackWidthUnit ),
m_viaX( aParent, m_ViaXCtrl, m_ViaXUnit ), m_viaY( aParent, m_ViaYCtrl, m_ViaYUnit ),
m_viaDiameter( aParent, m_ViaDiameterCtrl, m_ViaDiameterUnit ),
m_viaDrill( aParent, m_ViaDrillCtrl, m_ViaDrillUnit ),
m_tracks( false ), m_vias( false )
{
wxASSERT( !m_items.Empty() );
2015-07-09 11:35:51 +00:00
// This is a way to trick gcc into considering these variables as initialized
2018-01-19 10:01:11 +00:00
OPT<int> trackStartX( []()->OPT<int> { return NULLOPT; }() );
OPT<int> trackStartY( []()->OPT<int> { return NULLOPT; }() );
OPT<int> trackEndX( []()->OPT<int> { return NULLOPT; }() );
OPT<int> trackEndY( []()->OPT<int> { return NULLOPT; }() );
OPT<int> trackWidth( []()->OPT<int> { return NULLOPT; }() );
OPT<PCB_LAYER_ID> trackLayer( []()->OPT<PCB_LAYER_ID> { return NULLOPT; }() );
OPT<int> viaX( []()->OPT<int> { return NULLOPT; }() );
OPT<int> viaY( []()->OPT<int> { return NULLOPT; }() );
OPT<int> viaDiameter( []()->OPT<int> { return NULLOPT; }() );
OPT<int> viaDrill( []()->OPT<int> { return NULLOPT; }() );
2015-07-09 11:35:51 +00:00
VIATYPE_T viaType = VIA_NOT_DEFINED;
PCB_LAYER_ID viaStartLayer = UNDEFINED_LAYER;
PCB_LAYER_ID viaEndLayer = UNDEFINED_LAYER;
m_haveUniqueNet = true;
int prevNet = -1;
m_NetComboBox->SetBoard( aParent->GetBoard() );
m_NetComboBox->Enable( true );
2016-08-15 15:16:48 +00:00
bool hasLocked = false;
bool hasUnlocked = false;
for( auto& item : m_items )
{
int net = static_cast<BOARD_CONNECTED_ITEM*>(item)->GetNetCode();
if( prevNet >= 0 && net != prevNet )
{
printf("prev %d net %d\n", net, prevNet );
m_haveUniqueNet = false;
break;
}
prevNet = net;
}
if ( m_haveUniqueNet )
{
m_NetComboBox->SetSelectedNet( prevNet );
}
else
{
m_NetComboBox->SetMultiple( true );
}
2015-07-09 11:35:51 +00:00
// Look for values that are common for every item that is selected
2016-12-09 11:04:32 +00:00
for( auto& item : m_items )
2015-07-09 11:35:51 +00:00
{
switch( item->Type() )
{
case PCB_TRACE_T:
{
const TRACK* t = static_cast<const TRACK*>( item );
if( !m_tracks ) // first track in the list
{
trackStartX = t->GetStart().x;
trackStartY = t->GetStart().y;
trackEndX = t->GetEnd().x;
trackEndY = t->GetEnd().y;
trackWidth = t->GetWidth();
trackLayer = t->GetLayer();
m_tracks = true;
}
else // check if values are the same for every selected track
{
if( trackStartX && ( *trackStartX != t->GetStart().x ) )
trackStartX = NULLOPT;
2015-07-09 11:35:51 +00:00
if( trackStartY && ( *trackStartY != t->GetStart().y ) )
trackStartY = NULLOPT;
2015-07-09 11:35:51 +00:00
if( trackEndX && ( *trackEndX != t->GetEnd().x ) )
trackEndX = NULLOPT;
2015-07-09 11:35:51 +00:00
if( trackEndY && ( *trackEndY != t->GetEnd().y ) )
trackEndY = NULLOPT;
2015-07-09 11:35:51 +00:00
if( trackWidth && ( *trackWidth != t->GetWidth() ) )
trackWidth = NULLOPT;
2015-07-09 11:35:51 +00:00
if( trackLayer && ( *trackLayer != t->GetLayer() ) )
trackLayer = NULLOPT;
2015-07-09 11:35:51 +00:00
}
2016-08-15 15:16:48 +00:00
2016-08-15 15:16:53 +00:00
if( t->IsLocked() )
2016-08-15 15:16:48 +00:00
hasLocked = true;
else
hasUnlocked = true;
2015-07-09 11:35:51 +00:00
break;
}
case PCB_VIA_T:
{
const VIA* v = static_cast<const VIA*>( item );
if( !m_vias ) // first via in the list
{
viaX = v->GetPosition().x;
viaY = v->GetPosition().y;
viaDiameter = v->GetWidth();
viaDrill = v->GetDrillValue();
m_vias = true;
viaType = v->GetViaType();
viaStartLayer = v->TopLayer();
viaEndLayer = v->BottomLayer();
2015-07-09 11:35:51 +00:00
}
else // check if values are the same for every selected via
{
if( viaX && ( *viaX != v->GetPosition().x ) )
viaX = NULLOPT;
2015-07-09 11:35:51 +00:00
if( viaY && ( *viaY != v->GetPosition().y ) )
viaY = NULLOPT;
2015-07-09 11:35:51 +00:00
if( viaDiameter && ( *viaDiameter != v->GetWidth() ) )
viaDiameter = NULLOPT;
2015-07-09 11:35:51 +00:00
if( viaDrill && ( *viaDrill != v->GetDrillValue() ) )
viaDrill = NULLOPT;
if( viaType != v->GetViaType() )
viaType = VIA_NOT_DEFINED;
if( viaStartLayer != v->TopLayer() )
viaStartLayer = UNDEFINED_LAYER;
if( viaEndLayer != v->BottomLayer() )
viaEndLayer = UNDEFINED_LAYER;
2015-07-09 11:35:51 +00:00
}
2016-08-15 15:16:48 +00:00
2016-08-15 15:16:53 +00:00
if( v->IsLocked() )
2016-08-15 15:16:48 +00:00
hasLocked = true;
else
hasUnlocked = true;
2015-07-09 11:35:51 +00:00
break;
}
default:
{
wxASSERT( false );
2015-07-09 11:35:51 +00:00
break;
}
2015-07-09 11:35:51 +00:00
}
}
wxASSERT( m_tracks || m_vias );
if( m_vias )
{
setCommonVal( viaX, m_ViaXCtrl, m_viaX );
setCommonVal( viaY, m_ViaYCtrl, m_viaY );
setCommonVal( viaDiameter, m_ViaDiameterCtrl, m_viaDiameter );
setCommonVal( viaDrill, m_ViaDrillCtrl, m_viaDrill );
m_DesignRuleViasUnit->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
int viaSelection = wxNOT_FOUND;
for( unsigned ii = 0; ii < aParent->GetDesignSettings().m_ViasDimensionsList.size(); ii++ )
{
VIA_DIMENSION* viaDimension = &aParent->GetDesignSettings().m_ViasDimensionsList[ii];
wxString msg = StringFromValue( g_UserUnit, viaDimension->m_Diameter, false )
+ " / " + StringFromValue( g_UserUnit, viaDimension->m_Drill, false );
m_DesignRuleViasCtrl->Append( msg, viaDimension );
if( viaSelection == wxNOT_FOUND && viaDiameter == viaDimension->m_Diameter
&& viaDrill == viaDimension->m_Drill )
{
viaSelection = ii;
}
}
m_DesignRuleViasCtrl->SetSelection( viaSelection );
m_DesignRuleViasCtrl->Connect( wxEVT_CHOICE, wxCommandEventHandler( DIALOG_TRACK_VIA_PROPERTIES::onViaSelect ), NULL, this );
m_ViaDiameterCtrl->Connect( wxEVT_TEXT, wxCommandEventHandler( DIALOG_TRACK_VIA_PROPERTIES::onViaEdit ), NULL, this );
m_ViaDrillCtrl->Connect( wxEVT_TEXT, wxCommandEventHandler( DIALOG_TRACK_VIA_PROPERTIES::onViaEdit ), NULL, this );
m_ViaTypeChoice->Connect( wxEVT_CHOICE, wxCommandEventHandler( DIALOG_TRACK_VIA_PROPERTIES::onViaEdit ), NULL, this );
m_ViaDiameterCtrl->SetFocus();
m_ViaTypeChoice->Enable();
if( viaType == VIA_THROUGH )
m_ViaTypeChoice->SetSelection( 0 );
else if( viaType == VIA_MICROVIA )
m_ViaTypeChoice->SetSelection( 1 );
else if ( viaType == VIA_BLIND_BURIED )
m_ViaTypeChoice->SetSelection( 2 );
else if( viaType == VIA_NOT_DEFINED )
m_ViaTypeChoice->SetSelection( 3 );
m_ViaStartLayer->SetLayersHotkeys( false );
m_ViaStartLayer->SetLayerSet( LSET::AllNonCuMask() );
m_ViaStartLayer->SetBoardFrame( aParent );
m_ViaStartLayer->Resync();
m_ViaEndLayer->SetLayersHotkeys( false );
m_ViaEndLayer->SetLayerSet( LSET::AllNonCuMask() );
m_ViaEndLayer->SetBoardFrame( aParent );
m_ViaEndLayer->Resync();
m_ViaStartLayer->SetLayerSelection( viaStartLayer );
m_ViaEndLayer->SetLayerSelection( viaEndLayer );
m_ViaStartLayer->Enable( false );
m_ViaEndLayer->Enable( false );
if( viaType != VIA_THROUGH ) // check if selected type isnt through.
{
m_ViaStartLayer->Enable();
m_ViaEndLayer->Enable();
}
}
else
{
m_MainSizer->Hide( m_sbViaSizer, true );
}
2015-07-09 11:35:51 +00:00
if( m_tracks )
{
setCommonVal( trackStartX, m_TrackStartXCtrl, m_trackStartX );
setCommonVal( trackStartY, m_TrackStartYCtrl, m_trackStartY );
setCommonVal( trackEndX, m_TrackEndXCtrl, m_trackEndX );
setCommonVal( trackEndY, m_TrackEndYCtrl, m_trackEndY );
setCommonVal( trackWidth, m_TrackWidthCtrl, m_trackWidth );
2017-08-25 14:46:49 +00:00
for( unsigned ii = 0; ii < aParent->GetDesignSettings().m_TrackWidthList.size(); ii++ )
{
int width = aParent->GetDesignSettings().m_TrackWidthList[ii];
wxString msg = StringFromValue( g_UserUnit, width, false );
m_TrackWidthCtrl->Append( msg );
}
2015-07-09 11:35:51 +00:00
m_TrackLayerCtrl->SetLayersHotkeys( false );
m_TrackLayerCtrl->SetLayerSet( LSET::AllNonCuMask() );
m_TrackLayerCtrl->SetBoardFrame( aParent );
m_TrackLayerCtrl->Resync();
if( trackLayer )
m_TrackLayerCtrl->SetLayerSelection( *trackLayer );
m_TrackWidthCtrl->SetFocus();
2015-07-09 11:35:51 +00:00
}
else
{
m_MainSizer->Hide( m_sbTrackSizer, true );
2015-07-09 11:35:51 +00:00
}
2016-08-15 15:16:53 +00:00
if( hasLocked && hasUnlocked )
2016-08-15 15:16:48 +00:00
{
m_lockedCbox->Set3StateValue( wxCHK_UNDETERMINED );
}
2016-08-15 15:16:53 +00:00
else if( hasLocked )
2016-08-15 15:16:48 +00:00
{
m_lockedCbox->Set3StateValue( wxCHK_CHECKED );
}
else
{
m_lockedCbox->Set3StateValue( wxCHK_UNCHECKED );
}
2015-07-09 11:35:51 +00:00
m_StdButtonsOK->SetDefault();
// Pressing ENTER when any of the text input fields is active applies changes
Connect( wxEVT_TEXT_ENTER, wxCommandEventHandler( DIALOG_TRACK_VIA_PROPERTIES::onOkClick ),
NULL, this );
2015-07-09 11:35:51 +00:00
}
bool DIALOG_TRACK_VIA_PROPERTIES::Apply( COMMIT& aCommit )
2015-07-09 11:35:51 +00:00
{
if( !check() )
return false;
2016-08-15 15:16:48 +00:00
bool changeLock = m_lockedCbox->Get3StateValue() != wxCHK_UNDETERMINED;
bool setLock = m_lockedCbox->Get3StateValue() == wxCHK_CHECKED;
2016-12-09 11:04:32 +00:00
for( auto item : m_items )
2015-07-09 11:35:51 +00:00
{
aCommit.Modify( item );
2015-07-09 11:35:51 +00:00
switch( item->Type() )
{
case PCB_TRACE_T:
{
wxASSERT( m_tracks );
2015-07-09 11:35:51 +00:00
TRACK* t = static_cast<TRACK*>( item );
if( m_trackStartX.Valid() || m_trackStartY.Valid() )
{
wxPoint start = t->GetStart();
if( m_trackStartX.Valid() )
start.x = m_trackStartX.GetValue();
if( m_trackStartY.Valid() )
start.y = m_trackStartY.GetValue();
t->SetStart( start );
}
if( m_trackEndX.Valid() || m_trackEndY.Valid() )
{
wxPoint end = t->GetEnd();
if( m_trackEndX.Valid() )
end.x = m_trackEndX.GetValue();
if( m_trackEndY.Valid() )
end.y = m_trackEndY.GetValue();
t->SetEnd( end );
}
if( m_trackNetclass->IsChecked() )
{
t->SetWidth( t->GetNetClass()->GetTrackWidth() );
}
else if( m_trackWidth.Valid() )
{
t->SetWidth( m_trackWidth.GetValue() );
}
LAYER_NUM layer = m_TrackLayerCtrl->GetLayerSelection();
if( layer != UNDEFINED_LAYER )
t->SetLayer( (PCB_LAYER_ID) layer );
2015-07-09 11:35:51 +00:00
2016-08-15 15:16:48 +00:00
if( changeLock )
t->SetLocked( setLock );
if ( m_NetComboBox->IsUniqueNetSelected() )
{
printf("snc %d\n", m_NetComboBox->GetSelectedNet());
t->SetNetCode( m_NetComboBox->GetSelectedNet() );
}
2015-07-09 11:35:51 +00:00
break;
}
case PCB_VIA_T:
{
wxASSERT( m_vias );
2015-07-09 11:35:51 +00:00
VIA* v = static_cast<VIA*>( item );
if( m_viaX.Valid() || m_viaY.Valid() )
{
wxPoint pos = v->GetPosition();
if( m_viaX.Valid() )
pos.x = m_viaX.GetValue();
if( m_viaY.Valid() )
pos.y = m_viaY.GetValue();
v->SetPosition( pos );
}
if( m_ViaTypeChoice->GetSelection() != 3)
{
switch( m_ViaTypeChoice->GetSelection() )
{
case 0:
v->SetViaType( VIA_THROUGH );
v->SanitizeLayers();
break;
case 1:
v->SetViaType( VIA_MICROVIA );
break;
case 2:
v->SetViaType( VIA_BLIND_BURIED );
break;
default:
break;
}
}
auto startLayer = static_cast<PCB_LAYER_ID>( m_ViaStartLayer->GetLayerSelection() );
auto endLayer = static_cast<PCB_LAYER_ID>( m_ViaEndLayer->GetLayerSelection() );
if (startLayer != UNDEFINED_LAYER )
v->SetTopLayer( startLayer );
if (endLayer != UNDEFINED_LAYER )
v->SetBottomLayer( endLayer );
v->SanitizeLayers();
2015-07-09 11:35:51 +00:00
if( m_viaNetclass->IsChecked() )
{
switch( v->GetViaType() )
{
default:
wxFAIL_MSG("Unhandled via type");
// fall through
case VIA_THROUGH:
case VIA_BLIND_BURIED:
v->SetWidth( v->GetNetClass()->GetViaDiameter() );
v->SetDrill( v->GetNetClass()->GetViaDrill() );
break;
case VIA_MICROVIA:
v->SetWidth( v->GetNetClass()->GetuViaDiameter() );
v->SetDrill( v->GetNetClass()->GetuViaDrill() );
break;
}
2015-07-09 11:35:51 +00:00
}
else
{
if( m_viaDiameter.Valid() )
v->SetWidth( m_viaDiameter.GetValue() );
if( m_viaDrill.Valid() )
v->SetDrill( m_viaDrill.GetValue() );
}
if ( m_NetComboBox->IsUniqueNetSelected() )
{
printf("snc %d\n", m_NetComboBox->GetSelectedNet());
v->SetNetCode( m_NetComboBox->GetSelectedNet() );
2015-07-09 11:35:51 +00:00
}
2016-08-15 15:16:48 +00:00
if( changeLock )
v->SetLocked( setLock );
2015-07-09 11:35:51 +00:00
break;
}
default:
wxASSERT( false );
2015-07-09 11:35:51 +00:00
break;
}
}
return true;
}
void DIALOG_TRACK_VIA_PROPERTIES::onClose( wxCloseEvent& aEvent )
{
EndModal( 0 );
}
void DIALOG_TRACK_VIA_PROPERTIES::onTrackNetclassCheck( wxCommandEvent& aEvent )
{
bool enableNC = aEvent.IsChecked();
m_TrackWidthLabel->Enable( !enableNC );
m_TrackWidthCtrl->Enable( !enableNC );
m_TrackWidthUnit->Enable( !enableNC );
}
void DIALOG_TRACK_VIA_PROPERTIES::onViaNetclassCheck( wxCommandEvent& aEvent )
{
bool enableNC = aEvent.IsChecked();
m_DesignRuleVias->Enable( !enableNC );
m_DesignRuleViasCtrl->Enable( !enableNC );
m_DesignRuleViasUnit->Enable( !enableNC );
2015-07-09 11:35:51 +00:00
m_ViaDiameterLabel->Enable( !enableNC );
m_ViaDiameterCtrl->Enable( !enableNC );
m_ViaDiameterUnit->Enable( !enableNC );
m_ViaDrillLabel->Enable( !enableNC );
m_ViaDrillCtrl->Enable( !enableNC );
m_ViaDrillUnit->Enable( !enableNC );
}
void DIALOG_TRACK_VIA_PROPERTIES::onCancelClick( wxCommandEvent& aEvent )
{
EndModal( 0 );
}
void DIALOG_TRACK_VIA_PROPERTIES::onOkClick( wxCommandEvent& aEvent )
{
if( check() )
EndModal( 1 );
}
void DIALOG_TRACK_VIA_PROPERTIES::onViaSelect( wxCommandEvent& aEvent )
{
VIA_DIMENSION* viaDimension = static_cast<VIA_DIMENSION*> ( aEvent.GetClientData() );
wxString msg = StringFromValue( g_UserUnit, viaDimension->m_Diameter, false );
m_ViaDiameterCtrl->ChangeValue( msg );
msg = StringFromValue( g_UserUnit, viaDimension->m_Drill, false );
m_ViaDrillCtrl->ChangeValue( msg );
}
void DIALOG_TRACK_VIA_PROPERTIES::onViaEdit( wxCommandEvent& aEvent )
{
m_DesignRuleViasCtrl->SetSelection( wxNOT_FOUND );
if( m_vias )
{
if( m_ViaTypeChoice->GetSelection() != 0 ) // check if selected type isnt through.
{
m_ViaStartLayer->Enable();
m_ViaEndLayer->Enable();
}
else
{
m_ViaStartLayer->SetLayerSelection( F_Cu );
m_ViaEndLayer->SetLayerSelection( B_Cu );
m_ViaStartLayer->Enable( false );
m_ViaEndLayer->Enable( false );
}
}
}
2015-07-09 11:35:51 +00:00
bool DIALOG_TRACK_VIA_PROPERTIES::check() const
{
bool trackNetclass = m_trackNetclass->IsChecked();
bool viaNetclass = m_trackNetclass->IsChecked();
if( m_tracks && !trackNetclass && m_trackWidth.Valid() && m_trackWidth.GetValue() <= 0 )
{
DisplayError( GetParent(), _( "Invalid track width" ) );
m_TrackWidthCtrl->SetFocus();
return false;
}
if( m_vias && !viaNetclass )
{
if( m_viaDiameter.Valid() && m_viaDiameter.GetValue() <= 0 )
{
DisplayError( GetParent(), _( "Invalid via diameter" ) );
m_ViaDiameterCtrl->SetFocus();
return false;
}
if( m_viaDrill.Valid() && m_viaDrill.GetValue() <= 0 )
{
DisplayError( GetParent(), _( "Invalid via drill size" ) );
m_ViaDrillCtrl->SetFocus();
return false;
}
if( m_viaDiameter.Valid() && m_viaDrill.Valid() && m_viaDiameter.GetValue() <= m_viaDrill.GetValue() )
{
DisplayError( GetParent(), _( "Via drill size has to be smaller than via diameter" ) );
m_ViaDrillCtrl->SetFocus();
return false;
}
}
if( m_vias)
{
if( m_ViaStartLayer->GetLayerSelection() == m_ViaEndLayer->GetLayerSelection() )
{
DisplayError( GetParent(), _( "Via start layer and end layer cannot be the same" ) );
return false;
}
2015-07-09 11:35:51 +00:00
}
return true;
}