KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_lib_new_symbol.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 (C) 2009 Wayne Stambaugh <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
22#include <widgets/wx_infobar.h>
23
24#include <default_values.h>
25#include <eda_draw_frame.h>
26#include <sch_validators.h>
27#include <template_fieldnames.h>
28
29
30static wxString getDerivativeName( const wxString& aParentName )
31{
32 return wxString::Format( "%s_1", aParentName );
33}
34
35
36
37DIALOG_LIB_NEW_SYMBOL::DIALOG_LIB_NEW_SYMBOL( EDA_DRAW_FRAME* aParent, const wxArrayString& aSymbolNames,
38 const std::function<int( const wxString& aItem )>& aDisplayStyleCallback,
39 const wxString& aInheritFromSymbolName,
40 std::function<bool( const wxString& newName )> aValidator ) :
41 DIALOG_LIB_NEW_SYMBOL_BASE( dynamic_cast<wxWindow*>( aParent ) ),
44 m_validator( std::move( aValidator ) ),
45 m_inheritFromSymbolName( aInheritFromSymbolName ),
46 m_nameIsDefaulted( true )
47{
48 m_comboInheritanceSelect->SetStringList( aSymbolNames );
49 m_comboInheritanceSelect->SetDisplayStyleCallback( aDisplayStyleCallback );
50
51 m_hint->SetFont( KIUI::GetSmallInfoFont( this ).Italic() );
52
53 m_textName->SetValidator( FIELD_VALIDATOR( FIELD_T::VALUE ) );
55
57
58 m_comboInheritanceSelect->Connect( FILTERED_ITEM_SELECTED,
59 wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect ),
60 nullptr, this );
61
62 m_textName->Bind( wxEVT_TEXT,
63 [this]( wxCommandEvent& aEvent )
64 {
65 m_nameIsDefaulted = false;
66 } );
67
68 m_checkTransferUserFields->Connect( wxEVT_CHECKBOX,
70 nullptr, this );
71
72 // initial focus should be on first editable field.
73 m_textName->SetFocus();
74
76
77 // Now all widgets have the size fixed, call FinishDialogSettings
79}
80
81
83{
84 m_comboInheritanceSelect->Disconnect( FILTERED_ITEM_SELECTED,
85 wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect ),
86 nullptr, this );
87 m_checkTransferUserFields->Disconnect( wxEVT_CHECKBOX,
89 nullptr, this );
90}
91
92
94{
95 if( !m_inheritFromSymbolName.IsEmpty() )
96 {
99 }
100
101 CallAfter(
102 [&]()
103 {
104 /* The combo box `m_comboInheritanceSelect` must first process an update event before the
105 * string can be read again. The CallAfter() method ensures that the string is available
106 * when onParentSymbolSelect() reads it again.
107 */
108 wxCommandEvent dummyEvent;
109
110 // Trigger the event handler to show/hide the info bar message.
111 onParentSymbolSelect( dummyEvent );
112 onCheckTransferUserFields( dummyEvent );
113
114 // Trigger the event handler to handle power boxes
115 onPowerCheckBox( dummyEvent );
116 } );
117
118 return true;
119}
120
121
126
127
129{
130 const wxString parent = m_comboInheritanceSelect->GetValue();
131
132 if( !parent.IsEmpty() )
133 {
134 m_infoBar->RemoveAllButtons();
135 m_infoBar->ShowMessage( wxString::Format( _( "Deriving from symbol '%s'." ), UnescapeString( parent ) ),
136 wxICON_INFORMATION );
137 }
138 else
139 {
140 m_infoBar->Dismiss();
141 }
142
143 if( m_textName->IsEmpty() || m_nameIsDefaulted )
144 {
145 m_textName->SetValue( parent.IsEmpty() ? wxString( _( "Untitled" ) )
146 : getDerivativeName( parent ) );
147 m_textName->SetInsertionPointEnd();
148 m_nameIsDefaulted = true;
149 }
150
151 syncControls();
152
153 /* The banner changes the size of the dialog box, so it needs to be adjusted. */
154 Fit();
155}
156
157
159{
160 bool isDerivedPart = !m_comboInheritanceSelect->GetValue().IsEmpty();
161
162 m_staticTextDes->Enable( !isDerivedPart );
163 m_textReference->Enable( !isDerivedPart );
164 m_staticTextUnits->Enable( !isDerivedPart );
165 m_spinPartCount->Enable( !isDerivedPart );
166 m_checkUnitsInterchangeable->Enable( !isDerivedPart );
167 m_checkHasAlternateBodyStyle->Enable( !isDerivedPart );
168 m_checkIsPowerSymbol->Enable( !isDerivedPart );
169
170 if( m_checkIsPowerSymbol->IsChecked() )
171 {
172 m_excludeFromBomCheckBox->SetValue( true );
173 m_excludeFromBoardCheckBox->SetValue( true );
174 m_excludeFromBomCheckBox->Enable( false );
175 m_excludeFromBoardCheckBox->Enable( false );
176 }
177 else
178 {
179 m_excludeFromBomCheckBox->Enable( !isDerivedPart );
180 m_excludeFromBoardCheckBox->Enable( !isDerivedPart );
181 }
182
183 m_staticPinTextPositionLabel->Enable( !isDerivedPart );
184 m_textPinTextPosition->Enable( !isDerivedPart );
185 m_staticPinTextPositionUnits->Enable( !isDerivedPart );
186
187 m_checkShowPinNumber->Enable( !isDerivedPart );
188 m_checkShowPinName->Enable( !isDerivedPart );
189 m_checkShowPinNameInside->Enable( !isDerivedPart );
190
191 m_checkKeepDatasheet->Enable( isDerivedPart );
192 m_checkKeepFootprint->Enable( isDerivedPart );
193
194 m_checkTransferUserFields->Enable( isDerivedPart );
195 m_checkKeepContentUserFields->Enable( isDerivedPart && m_checkTransferUserFields->IsChecked() );
196}
197
198
199void DIALOG_LIB_NEW_SYMBOL::onPowerCheckBox( wxCommandEvent& aEvent )
200{
201 syncControls();
202}
203
204
206{
207 syncControls();
208}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
DIALOG_LIB_NEW_SYMBOL_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("New Symbol"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
SYMBOL_FILTER_COMBOBOX * m_comboInheritanceSelect
wxString GetName() const override
std::function< bool(const wxString &newName)> m_validator
DIALOG_LIB_NEW_SYMBOL(EDA_DRAW_FRAME *aParent, const wxArrayString &aSymbolNames, const std::function< int(const wxString &aItem)> &aDisplayStyleCallback, const wxString &aInheritFromSymbolName, std::function< bool(const wxString &newName)> aValidator)
void onCheckTransferUserFields(wxCommandEvent &aEvent) override
void onPowerCheckBox(wxCommandEvent &aEvent) override
void onParentSymbolSelect(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...
The base class for create windows for drawing purpose.
A text control validator used for validating the text allowed in fields.
Definition validators.h:138
#define DEFAULT_PIN_NAME_OFFSET
The offset of the pin name string from the end of the pin in mils.
static wxString getDerivativeName(const wxString &aParentName)
#define _(s)
KICOMMON_API wxFont GetSmallInfoFont(wxWindow *aWindow)
STL namespace.
Definitions of control validators for schematic dialogs.
wxString UnescapeString(const wxString &aSource)
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".