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
27#include <default_values.h>
28#include <eda_draw_frame.h>
29#include <sch_validators.h>
30#include <template_fieldnames.h>
31
32
33static wxString getDerivativeName( const wxString& aParentName )
34{
35 return wxString::Format( "%s_1", aParentName );
36}
37
38
40 const wxArrayString& aSymbolNames,
41 const wxString& aInheritFromSymbolName,
42 std::function<bool( wxString newName )> aValidator ) :
43 DIALOG_LIB_NEW_SYMBOL_BASE( dynamic_cast<wxWindow*>( aParent ) ),
44 m_pinTextPosition( aParent, m_staticPinTextPositionLabel, m_textPinTextPosition,
45 m_staticPinTextPositionUnits, true ),
46 m_validator( std::move( aValidator ) ),
47 m_nameIsDefaulted( true )
48{
49 if( aSymbolNames.GetCount() )
50 {
51 wxArrayString escapedNames;
52
53 for( const wxString& name : aSymbolNames )
54 escapedNames.Add( UnescapeString( name ) );
55
57
58 if( !aInheritFromSymbolName.IsEmpty() )
59 {
60 m_comboInheritanceSelect->SetSelectedSymbol( aInheritFromSymbolName );
61 }
62 }
63
64 // Trigger the event handler to show/hide the info bar message.
65 wxCommandEvent dummyEvent;
66 onParentSymbolSelect( dummyEvent );
67
68 m_textName->SetValidator( FIELD_VALIDATOR( VALUE_FIELD ) );
70
71 if( !aInheritFromSymbolName.IsEmpty() )
72 {
73 m_textName->ChangeValue( getDerivativeName( aInheritFromSymbolName ) );
74 m_nameIsDefaulted = true;
75 }
76
78
80 FILTERED_ITEM_SELECTED,
81 wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect ), nullptr, this );
82
83 m_textName->Bind( wxEVT_TEXT,
84 [this]( wxCommandEvent& aEvent )
85 {
86 m_nameIsDefaulted = false;
87 } );
88
89 // initial focus should be on first editable field.
90 m_textName->SetFocus();
91
93
94 // Now all widgets have the size fixed, call FinishDialogSettings
96}
97
98
100{
101 m_comboInheritanceSelect->Disconnect(
102 FILTERED_ITEM_SELECTED,
103 wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect ), nullptr, this );
104}
105
106
108{
109 return m_validator( GetName() );
110}
111
112
114{
115 const wxString parent = m_comboInheritanceSelect->GetValue();
116
117 if( !parent.IsEmpty() )
118 {
120 m_infoBar->ShowMessage( wxString::Format( _( "Deriving from symbol '%s'." ), parent ),
121 wxICON_INFORMATION );
122 }
123 else
124 {
126 }
127
128 if( m_textName->IsEmpty() || m_nameIsDefaulted )
129 {
130 m_textName->SetValue( getDerivativeName( parent ) );
131 m_textName->SetInsertionPointEnd();
132 m_nameIsDefaulted = true;
133 }
134
135 syncControls( !parent.IsEmpty() );
136}
137
138
139void DIALOG_LIB_NEW_SYMBOL::syncControls( bool aIsDerivedPart )
140{
141 m_staticTextDes->Enable( !aIsDerivedPart );
142 m_textReference->Enable( !aIsDerivedPart );
143 m_staticTextUnits->Enable( !aIsDerivedPart );
144 m_spinPartCount->Enable( !aIsDerivedPart );
145 m_checkUnitsInterchangeable->Enable( !aIsDerivedPart );
146 m_checkHasAlternateBodyStyle->Enable( !aIsDerivedPart );
147 m_checkIsPowerSymbol->Enable( !aIsDerivedPart );
148 m_excludeFromBomCheckBox->Enable( !aIsDerivedPart );
149 m_excludeFromBoardCheckBox->Enable( !aIsDerivedPart );
150 m_staticPinTextPositionLabel->Enable( !aIsDerivedPart );
151 m_textPinTextPosition->Enable( !aIsDerivedPart );
152 m_staticPinTextPositionUnits->Enable( !aIsDerivedPart );
153 m_checkShowPinNumber->Enable( !aIsDerivedPart );
154 m_checkShowPinName->Enable( !aIsDerivedPart );
155 m_checkShowPinNameInside->Enable( !aIsDerivedPart );
156}
157
158
159void DIALOG_LIB_NEW_SYMBOL::onPowerCheckBox( wxCommandEvent& aEvent )
160{
161 if( m_checkIsPowerSymbol->IsChecked() )
162 {
163 m_excludeFromBomCheckBox->SetValue( true );
164 m_excludeFromBoardCheckBox->SetValue( true );
165 m_excludeFromBomCheckBox->Enable( false );
166 m_excludeFromBoardCheckBox->Enable( false );
167 }
168 else
169 {
170 m_excludeFromBomCheckBox->Enable( true );
171 m_excludeFromBoardCheckBox->Enable( true );
172 }
173}
174
const char * name
Definition: DXF_plotter.cpp:59
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
Class DIALOG_LIB_NEW_SYMBOL_BASE.
SYMBOL_FILTER_COMBOBOX * m_comboInheritanceSelect
DIALOG_LIB_NEW_SYMBOL(EDA_DRAW_FRAME *aParent, const wxArrayString &aSymbolNames, const wxString &aInheritFromSymbolName, std::function< bool(wxString newName)> aValidator)
wxString GetName() const override
void syncControls(bool aIsDerivedPart)
bool TransferDataFromWindow() override
std::function< bool(wxString newName)> m_validator
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:224
void SetSelectedSymbol(const wxString &aSymbolName)
void SetSymbolList(const wxArrayString &aSymbolList)
wxString GetValue() const override
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: wx_infobar.cpp:320
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: wx_infobar.cpp:189
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: wx_infobar.cpp:153
#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)
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".