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, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <initializer_list>
24
25#include <kicommon.h>
26#include <wx/string.h>
27
28class OUTPUTFORMATTER;
29class TEMPLATE_FIELDNAMES_LEXER;
30
31
55
56#define MANDATORY_FIELDS { FIELD_T::REFERENCE, \
57 FIELD_T::VALUE, \
58 FIELD_T::FOOTPRINT, \
59 FIELD_T::DATASHEET, \
60 FIELD_T::DESCRIPTION }
61
62#define GLOBALLABEL_MANDATORY_FIELDS { FIELD_T::INTERSHEET_REFS }
63
64#define SHEET_MANDATORY_FIELDS { FIELD_T::SHEET_NAME, \
65 FIELD_T::SHEET_FILENAME }
66
67// Translation should be used only to display field names in dialogs
73
74
82KICOMMON_API wxString GetDefaultFieldName( FIELD_T aFieldId, TRANSLATION aTranslation );
83KICOMMON_API wxString GetUserFieldName( int aFieldNdx, TRANSLATION aTranslation );
84
85
100KICOMMON_API bool FieldNamesAreDuplicates( const wxString& aLhs, const wxString& aRhs,
101 std::initializer_list<FIELD_T> aMandatoryFields );
102
103
107KICOMMON_API bool FieldNamesAreDuplicates( const wxString& aLhs, const wxString& aRhs );
108
109
116{
118 m_Visible( false ),
119 m_URL( false )
120 {
121 }
122
123 TEMPLATE_FIELDNAME( const wxString& aName ) :
124 m_Name( aName ),
125 m_Visible( false ),
126 m_URL( false )
127 {
128 }
129
131 {
132 m_Name = ref.m_Name;
133 m_Visible = ref.m_Visible;
134 m_URL = ref.m_URL;
135 }
136
140 void Format( OUTPUTFORMATTER* out ) const ;
141
154 void Parse( TEMPLATE_FIELDNAMES_LEXER* aSpec );
155
156 wxString m_Name; // The field name
157 bool m_Visible; // Field defaults to being visible in schematic.
158 bool m_URL; // If field should have a browse button
159};
160
161
163{
164public:
165 enum class SCOPE
166 {
169 };
170
172 m_resolvedDirty( true )
173 { }
174
178 void Format( OUTPUTFORMATTER* out, SCOPE aScope ) const;
179
190 void AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName, SCOPE aScope );
191
195 void AddTemplateFieldNames( const wxString& aSerializedFieldNames, SCOPE aScope );
196
200 void DeleteFieldNameTemplates( SCOPE aScope );
201
205 const std::vector<TEMPLATE_FIELDNAME>& GetResolvedTemplateFieldNames();
206
210 const std::vector<TEMPLATE_FIELDNAME>& GetTemplateFieldNames( SCOPE aScope );
211
218 const TEMPLATE_FIELDNAME* GetFieldName( const wxString& aName );
219
220protected:
221 void resolveTemplates();
222
223 void parse( TEMPLATE_FIELDNAMES_LEXER* in, SCOPE aScope );
224
225private:
226 std::vector<TEMPLATE_FIELDNAME> m_globals;
227 std::vector<TEMPLATE_FIELDNAME> m_project;
228
229 // Combined list. Project templates override global ones.
230 std::vector<TEMPLATE_FIELDNAME> m_resolved;
232};
An interface used to output 8 bit text in a convenient way.
Definition richio.h:294
std::vector< TEMPLATE_FIELDNAME > m_resolved
std::vector< TEMPLATE_FIELDNAME > m_project
std::vector< TEMPLATE_FIELDNAME > m_globals
LIB_FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE SCOPE
@ USER
The main config directory (e.g. ~/.config/kicad/)
#define KICOMMON_API
Definition kicommon.h:27
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition ptree.cpp:194
Hold a name of a symbol's field, field value, and default visibility.
TEMPLATE_FIELDNAME(const wxString &aName)
TEMPLATE_FIELDNAME(const TEMPLATE_FIELDNAME &ref)
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ INTERSHEET_REFS
Global label cross-reference page numbers.
@ DESCRIPTION
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
@ DATASHEET
name of datasheet
@ VALUE
Field Value of part, i.e. "3.3K".
@ UNTRANSLATED
@ TRANSLATED
KICOMMON_API wxString GetUserFieldName(int aFieldNdx, TRANSLATION aTranslation)
KICOMMON_API bool FieldNamesAreDuplicates(const wxString &aLhs, const wxString &aRhs, std::initializer_list< FIELD_T > aMandatoryFields)
Test whether two field names should be treated as duplicates for the purposes of field name uniquenes...
KICOMMON_API wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.