KiCad PCB EDA Suite
Loading...
Searching...
No Matches
template_fieldnames.h
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) 2010 SoftPLC Corporation, Dick Hollenbeck <[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
25#pragma once
26
27#include <wx/string.h>
28
29class OUTPUTFORMATTER;
30class TEMPLATE_FIELDNAMES_LEXER;
31
32
47
51};
52
53#define MANDATORY_FIELDS { REFERENCE_FIELD, VALUE_FIELD, FOOTPRINT_FIELD, DATASHEET_FIELD, DESCRIPTION_FIELD }
54
55// A helper to call GetDefaultFieldName with or without translation.
56// Translation should be used only to display field names in dialogs
57#define DO_TRANSLATE true
58
59
69wxString GetDefaultFieldName( int aFieldNdx, bool aTranslateForHI );
70wxString GetUserFieldName( int aFieldNdx, bool aTranslateForHI );
71
72
73inline wxString GetCanonicalFieldName( int idx )
74{
75 // While TEMPLATE_FIELDNAME::GetDefaultFieldName() still works for non-mandatory fields,
76 // it's confusing to call it through this function.
77 wxASSERT( idx < MANDATORY_FIELD_COUNT );
78
79 return GetDefaultFieldName( idx, !DO_TRANSLATE );
80}
81
82
89{
91 m_Visible( false ),
92 m_URL( false )
93 {
94 }
95
96 TEMPLATE_FIELDNAME( const wxString& aName ) :
97 m_Name( aName ),
98 m_Visible( false ),
99 m_URL( false )
100 {
101 }
102
104 {
105 m_Name = ref.m_Name;
106 m_Visible = ref.m_Visible;
107 m_URL = ref.m_URL;
108 }
109
113 void Format( OUTPUTFORMATTER* out ) const ;
114
127 void Parse( TEMPLATE_FIELDNAMES_LEXER* aSpec );
128
129 wxString m_Name; // The field name
130 bool m_Visible; // Field defaults to being visible in schematic.
131 bool m_URL; // If field should have a browse button
132};
133
134typedef std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES;
135
136
138{
139public:
141 m_resolvedDirty( true )
142 { }
143
147 void Format( OUTPUTFORMATTER* out, bool aGlobal ) const ;
148
159 void AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName, bool aGlobal );
160
164 void AddTemplateFieldNames( const wxString& aSerializedFieldNames );
165
169 void DeleteAllFieldNameTemplates( bool aGlobal );
170
175
179 const TEMPLATE_FIELDNAMES& GetTemplateFieldNames( bool aGlobal );
180
187 const TEMPLATE_FIELDNAME* GetFieldName( const wxString& aName );
188
189protected:
190 void resolveTemplates();
191
192 void parse( TEMPLATE_FIELDNAMES_LEXER* in, bool aGlobal );
193
194private:
197
198 // Combined list. Project templates override global ones.
201};
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:322
TEMPLATE_FIELDNAMES m_globals
void AddTemplateFieldName(const TEMPLATE_FIELDNAME &aFieldName, bool aGlobal)
Insert or append a wanted symbol field name into the field names template.
void AddTemplateFieldNames(const wxString &aSerializedFieldNames)
Add a serialized list of template field names.
TEMPLATE_FIELDNAMES m_project
TEMPLATE_FIELDNAMES m_resolved
void resolveTemplates()
Flatten project and global templates into a single list.
const TEMPLATE_FIELDNAME * GetFieldName(const wxString &aName)
Search for aName in the template field name list.
void DeleteAllFieldNameTemplates(bool aGlobal)
Delete the entire contents.
const TEMPLATE_FIELDNAMES & GetTemplateFieldNames()
Return a template field name list for read only access.
void parse(TEMPLATE_FIELDNAMES_LEXER *in, bool aGlobal)
void Format(OUTPUTFORMATTER *out, bool aGlobal) const
Serialize this object out as text into the given OUTPUTFORMATTER.
Hold a name of a symbol's field, field value, and default visibility.
void Format(OUTPUTFORMATTER *out) const
Serialize this object out as text into the given OUTPUTFORMATTER.
void Parse(TEMPLATE_FIELDNAMES_LEXER *aSpec)
Fill this object from information in the input stream aSpec, which is a #TEMPLATE_FIELDNAMES_LEXER.
TEMPLATE_FIELDNAME(const wxString &aName)
TEMPLATE_FIELDNAME(const TEMPLATE_FIELDNAME &ref)
#define DO_TRANSLATE
wxString GetCanonicalFieldName(int idx)
MANDATORY_FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ INVALID_FIELD
The field ID hasn't been set yet; field is invalid.
@ MANDATORY_FIELD_COUNT
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT, LIB_PART, and FOOTPRINT constru...
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
@ DESCRIPTION_FIELD
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
wxString GetDefaultFieldName(int aFieldNdx, bool aTranslateForHI)
Return a default symbol field name for field aFieldNdx for all components.
wxString GetUserFieldName(int aFieldNdx, bool aTranslateForHI)
std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES