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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
26#include <widgets/wx_infobar.h>
27
28#include <default_values.h>
29#include <eda_draw_frame.h>
30#include <sch_validators.h>
31#include <template_fieldnames.h>
32
33
34static wxString getDerivativeName( const wxString& aParentName )
35{
36 return wxString::Format( "%s_1", aParentName );
37}
38
39
41 const wxArrayString& aSymbolNames,
42 const wxString& aInheritFromSymbolName,
43 std::function<bool( const wxString& newName )> aValidator ) :
44 DIALOG_LIB_NEW_SYMBOL_BASE( dynamic_cast<wxWindow*>( aParent ) ),
47 m_validator( std::move( aValidator ) ),
48 m_inheritFromSymbolName( aInheritFromSymbolName ),
49 m_nameIsDefaulted( true )
50{
51 if( aSymbolNames.GetCount() )
52 {
53 wxArrayString unescapedNames;
54
55 for( const wxString& name : aSymbolNames )
56 unescapedNames.Add( UnescapeString( name ) );
57
58 m_comboInheritanceSelect->SetStringList( unescapedNames );
59 }
60
61 m_textName->SetValidator( FIELD_VALIDATOR( FIELD_T::VALUE ) );
63
65
66 m_comboInheritanceSelect->Connect( FILTERED_ITEM_SELECTED,
67 wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect ),
68 nullptr, this );
69
70 m_textName->Bind( wxEVT_TEXT,
71 [this]( wxCommandEvent& aEvent )
72 {
73 m_nameIsDefaulted = false;
74 } );
75
76 m_checkTransferUserFields->Connect( wxEVT_CHECKBOX,
78 nullptr, this );
79
80 // initial focus should be on first editable field.
81 m_textName->SetFocus();
82
84
85 // Now all widgets have the size fixed, call FinishDialogSettings
87}
88
89
91{
92 m_comboInheritanceSelect->Disconnect( FILTERED_ITEM_SELECTED,
93 wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect ),
94 nullptr, this );
95 m_checkTransferUserFields->Disconnect( wxEVT_CHECKBOX,
97 nullptr, this );
98}
99
100
102{
103 if( !m_inheritFromSymbolName.IsEmpty() )
104 {
107 }
108
109 CallAfter(
110 [&]()
111 {
112 /* The combo box `m_comboInheritanceSelect` must first process an update event before the string can be read again.
113 * The CallAfter() method ensures that the string is available when onParentSymbolSelect() reads it again.
114 */
115 wxCommandEvent dummyEvent;
116
117 // Trigger the event handler to show/hide the info bar message.
118 onParentSymbolSelect( dummyEvent );
119 onCheckTransferUserFields( dummyEvent );
120
121 // Trigger the event handler to handle power boxes
122 onPowerCheckBox( dummyEvent );
123 } );
124
125 return true;
126}
127
128
133
134
136{
137 const wxString parent = m_comboInheritanceSelect->GetValue();
138
139 if( !parent.IsEmpty() )
140 {
141 m_infoBar->RemoveAllButtons();
142 m_infoBar->ShowMessage( wxString::Format( _( "Deriving from symbol '%s'." ), UnescapeString( parent ) ),
143 wxICON_INFORMATION );
144 }
145 else
146 {
147 m_infoBar->Dismiss();
148 }
149
150 if( m_textName->IsEmpty() || m_nameIsDefaulted )
151 {
152 m_textName->SetValue( getDerivativeName( parent ) );
153 m_textName->SetInsertionPointEnd();
154 m_nameIsDefaulted = true;
155 }
156
157 syncControls( !parent.IsEmpty() );
158
159 /* The banner changes the size of the dialog box, so it needs to be adjusted. */
160 Fit();
161}
162
163
164void DIALOG_LIB_NEW_SYMBOL::syncControls( bool aIsDerivedPart )
165{
166 m_staticTextDes->Enable( !aIsDerivedPart );
167 m_textReference->Enable( !aIsDerivedPart );
168 m_staticTextUnits->Enable( !aIsDerivedPart );
169 m_spinPartCount->Enable( !aIsDerivedPart );
170 m_checkUnitsInterchangeable->Enable( !aIsDerivedPart );
171 m_checkHasAlternateBodyStyle->Enable( !aIsDerivedPart );
172 m_checkIsPowerSymbol->Enable( !aIsDerivedPart );
173 m_excludeFromBomCheckBox->Enable( !aIsDerivedPart );
174 m_excludeFromBoardCheckBox->Enable( !aIsDerivedPart );
175 m_staticPinTextPositionLabel->Enable( !aIsDerivedPart );
176 m_textPinTextPosition->Enable( !aIsDerivedPart );
177 m_staticPinTextPositionUnits->Enable( !aIsDerivedPart );
178
179 m_checkShowPinNumber->Enable( !aIsDerivedPart );
180 m_checkShowPinName->Enable( !aIsDerivedPart );
181 m_checkShowPinNameInside->Enable( !aIsDerivedPart );
182
183 m_checkKeepDatasheet->Enable( aIsDerivedPart );
184 m_checkKeepFootprint->Enable( aIsDerivedPart );
185 m_checkTransferUserFields->Enable( aIsDerivedPart );
186 m_checkKeepContentUserFields->Enable( aIsDerivedPart );
187}
188
189
190void DIALOG_LIB_NEW_SYMBOL::onPowerCheckBox( wxCommandEvent& aEvent )
191{
192 if( m_checkIsPowerSymbol->IsChecked() )
193 {
194 m_excludeFromBomCheckBox->SetValue( true );
195 m_excludeFromBoardCheckBox->SetValue( true );
196 m_excludeFromBomCheckBox->Enable( false );
197 m_excludeFromBoardCheckBox->Enable( false );
198 }
199 else
200 {
201 m_excludeFromBomCheckBox->Enable( true );
202 m_excludeFromBoardCheckBox->Enable( true );
203 }
204}
205
206
208{
209 bool checked = m_checkTransferUserFields->IsChecked();
210 m_checkKeepContentUserFields->Enable( checked );
211}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:127
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
DIALOG_LIB_NEW_SYMBOL(EDA_DRAW_FRAME *aParent, const wxArrayString &aSymbolNames, const wxString &aInheritFromSymbolName, std::function< bool(const wxString &newName)> aValidator)
wxString GetName() const override
std::function< bool(const wxString &newName)> m_validator
void syncControls(bool aIsDerivedPart)
virtual void onCheckTransferUserFields(wxCommandEvent &aEvent) override
virtual 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:142
#define DEFAULT_PIN_NAME_OFFSET
The intersheets references prefix string.
static wxString getDerivativeName(const wxString &aParentName)
#define _(s)
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".