KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_microvia_stack.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <confirm.h>
22#include <lset.h>
23#include <pcb_base_edit_frame.h>
25#include <pcb_track.h>
26
29
30
33 m_stack( aStack ),
37{
38 for( PCB_LAYER_BOX_SELECTOR* selector : { m_startLayer, m_endLayer } )
39 {
40 selector->SetLayersHotkeys( false );
41 selector->SetNotAllowedLayerSet( LSET::AllNonCuMask() );
42 selector->SetBoardFrame( aParent );
43 selector->Resync();
44 }
45
46 m_typeChoice->Bind( wxEVT_CHOICE, &DIALOG_MICROVIA_STACK::onTypeChanged, this );
47 m_useNetclass->Bind( wxEVT_CHECKBOX, &DIALOG_MICROVIA_STACK::onUseNetclass, this );
48
51}
52
53
55{
56 m_startLayer->SetLayerSelection( m_stack->GetStartLayer() );
57 m_endLayer->SetLayerSelection( m_stack->GetEndLayer() );
58 m_typeChoice->SetSelection( m_stack->GetStyle() == VIA_STACK_STYLE::STAGGERED ? 1 : 0 );
59
60 m_useNetclass->SetValue( m_stack->GetUseNetclass() );
61 m_filled->SetValue( m_stack->IsFilled() );
62 m_capped->SetValue( m_stack->IsCapped() );
63
64 m_viaSize.SetValue( m_stack->GetViaSize() );
65 m_viaDrill.SetValue( m_stack->GetViaDrill() );
66 m_pitch.SetValue( m_stack->GetPitch() );
67
69 return true;
70}
71
72
74{
75 PCB_LAYER_ID startLayer = ToLAYER_ID( m_startLayer->GetLayerSelection() );
76 PCB_LAYER_ID endLayer = ToLAYER_ID( m_endLayer->GetLayerSelection() );
77 bool staggered = m_typeChoice->GetSelection() == 1;
78
79 if( startLayer == endLayer )
80 {
81 DisplayErrorMessage( this, _( "The start and end layers must be different." ) );
82 return false;
83 }
84
85 if( !PCB_VIA_STACK::IsSpanValid( m_stack->GetBoard(), startLayer, endLayer ) )
86 {
87 DisplayErrorMessage( this, _( "Select a start and an end layer present on this board." ) );
88 return false;
89 }
90
91 if( staggered && m_pitch.GetIntValue() <= 0 )
92 {
93 DisplayErrorMessage( this, _( "Staggered stacks need a pitch greater than zero." ) );
94 return false;
95 }
96
97 if( m_pitch.GetIntValue() > pcbIUScale.mmToIU( MAX_MICROVIA_STACK_PITCH_MM ) )
98 {
101
102 DisplayErrorMessage( this, wxString::Format( _( "The pitch must be %s or less." ), limit ) );
103 return false;
104 }
105
106 m_stack->SetStartLayer( startLayer );
107 m_stack->SetEndLayer( endLayer );
109
110 m_stack->SetUseNetclass( m_useNetclass->GetValue() );
111
112 // Stacked stacks land on filled copper, so fill is forced on.
113 m_stack->SetFilled( staggered ? m_filled->GetValue() : true );
114 m_stack->SetCapped( m_capped->GetValue() );
115
116 if( m_useNetclass->GetValue() )
117 {
118 m_stack->SetViaSize( 0 );
119 m_stack->SetViaDrill( 0 );
120 }
121 else
122 {
123 if( std::optional<PCB_VIA::VIA_PARAMETER_ERROR> error = PCB_VIA::ValidateViaParameters(
124 m_viaSize.GetIntValue(), m_viaDrill.GetIntValue(), startLayer, endLayer ) )
125 {
126 DisplayErrorMessage( this, error->m_Message );
127 return false;
128 }
129
130 m_stack->SetViaSize( m_viaSize.GetIntValue() );
131 m_stack->SetViaDrill( m_viaDrill.GetIntValue() );
132 }
133
134 m_stack->SetPitch( m_pitch.GetIntValue() );
135 return true;
136}
137
138
140{
141 bool staggered = m_typeChoice->GetSelection() == 1;
142 bool useNetclass = m_useNetclass->GetValue();
143
144 // Pitch only applies to staggered stacks.
145 m_pitch.Enable( staggered );
146
147 // Size and drill come from the netclass when requested.
148 m_viaSize.Enable( !useNetclass );
149 m_viaDrill.Enable( !useNetclass );
150
151 // Stacked stacks are always copper filled.
152 m_filled->Enable( staggered );
153
154 if( !staggered )
155 m_filled->SetValue( true );
156}
157
158
159void DIALOG_MICROVIA_STACK::onTypeChanged( wxCommandEvent& aEvent )
160{
162}
163
164
165void DIALOG_MICROVIA_STACK::onUseNetclass( wxCommandEvent& aEvent )
166{
168}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
#define MAX_MICROVIA_STACK_PITCH_MM
PCB_LAYER_BOX_SELECTOR * m_startLayer
PCB_LAYER_BOX_SELECTOR * m_endLayer
DIALOG_MICROVIA_STACK_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Microvia Stack"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE)
DIALOG_MICROVIA_STACK(PCB_BASE_EDIT_FRAME *aParent, PCB_VIA_STACK *aStack)
void onUseNetclass(wxCommandEvent &aEvent)
bool TransferDataFromWindow() override
void onTypeChanged(wxCommandEvent &aEvent)
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
EDA_UNITS GetUserUnits() const
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition lset.cpp:623
Common, abstract interface for edit frames.
Class to display a pcb layer list in a wxBitmapComboBox.
A microvia stack: several single hop microvias, plus connecting traces for staggered stacks,...
static bool IsSpanValid(BOARD *aBoard, PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd)
True when both span ends are copper layers within the board's copper layer count.
static std::optional< VIA_PARAMETER_ERROR > ValidateViaParameters(std::optional< int > aDiameter, std::optional< int > aPrimaryDrill, std::optional< PCB_LAYER_ID > aPrimaryStartLayer=std::nullopt, std::optional< PCB_LAYER_ID > aPrimaryEndLayer=std::nullopt, std::optional< int > aSecondaryDrill=std::nullopt, std::optional< PCB_LAYER_ID > aSecondaryStartLayer=std::nullopt, std::optional< PCB_LAYER_ID > aSecondaryEndLayer=std::nullopt, std::optional< int > aTertiaryDrill=std::nullopt, std::optional< PCB_LAYER_ID > aTertiaryStartLayer=std::nullopt, std::optional< PCB_LAYER_ID > aTertiaryEndLayer=std::nullopt, int aCopperLayerCount=0)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
This file is part of the common library.
#define _(s)
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:750
KICOMMON_API wxString MessageTextFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
A helper to convert the double length aValue to a string in inches, millimeters, or unscaled units.