2014-10-19 22:17:43 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2020-03-10 18:46:57 +00:00
|
|
|
* Copyright (C) 2014-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
|
2014-10-19 22:17:43 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
#ifndef _TEMPLATE_FIELDNAME_H_
|
|
|
|
#define _TEMPLATE_FIELDNAME_H_
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <richio.h>
|
|
|
|
#include <template_fieldnames_lexer.h>
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2010-08-09 02:03:16 +00:00
|
|
|
class TEMPLATE_FIELDNAMES_LEXER;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* The set of all field indices assuming an array like sequence that a SCH_COMPONENT or
|
|
|
|
* LIB_PART can hold.
|
|
|
|
*
|
|
|
|
* The first fields are fixed fields and are defined by #MANDATORY_FIELDS. After that come
|
|
|
|
* an unlimited number of user defined fields, only some of which have indices defined here.
|
2010-06-17 16:30:10 +00:00
|
|
|
*/
|
|
|
|
enum NumFieldType {
|
2020-11-12 21:31:41 +00:00
|
|
|
REFERENCE_FIELD = 0, ///< Field Reference of part, i.e. "IC21"
|
|
|
|
VALUE_FIELD, ///< Field Value of part, i.e. "3.3K"
|
|
|
|
FOOTPRINT_FIELD, ///< Field Name Module PCB, i.e. "16DIP300"
|
|
|
|
DATASHEET_FIELD, ///< name of datasheet
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2010-07-31 15:48:11 +00:00
|
|
|
/// The first 4 are mandatory, and must be instantiated in SCH_COMPONENT
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
/// and LIB_PART constructors
|
2010-07-31 15:48:11 +00:00
|
|
|
MANDATORY_FIELDS,
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
FIELD1 = MANDATORY_FIELDS,
|
|
|
|
FIELD2,
|
|
|
|
FIELD3,
|
|
|
|
FIELD4,
|
|
|
|
FIELD5,
|
|
|
|
FIELD6,
|
|
|
|
FIELD7,
|
2010-10-04 12:58:07 +00:00
|
|
|
FIELD8
|
2010-06-17 16:30:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Hold a name of a symbol's field, field value, and default visibility.
|
|
|
|
*
|
|
|
|
* Template fieldnames are wanted field names for use in the symbol property editors.
|
2010-06-17 16:30:10 +00:00
|
|
|
*/
|
|
|
|
struct TEMPLATE_FIELDNAME
|
|
|
|
{
|
|
|
|
TEMPLATE_FIELDNAME() :
|
2020-03-10 18:46:57 +00:00
|
|
|
m_Visible( false ),
|
|
|
|
m_URL( false )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TEMPLATE_FIELDNAME( const wxString& aName ) :
|
2020-03-10 18:46:57 +00:00
|
|
|
m_Name( aName ),
|
|
|
|
m_Visible( false ),
|
|
|
|
m_URL( false )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-09-16 19:34:52 +00:00
|
|
|
TEMPLATE_FIELDNAME( const TEMPLATE_FIELDNAME& ref )
|
|
|
|
{
|
2020-03-10 18:46:57 +00:00
|
|
|
m_Name = ref.m_Name;
|
|
|
|
m_Visible = ref.m_Visible;
|
|
|
|
m_URL = ref.m_URL;
|
2014-09-16 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Serialize this object out as text into the given #OUTPUTFORMATTER.
|
2010-06-17 16:30:10 +00:00
|
|
|
*/
|
2017-06-08 21:47:21 +00:00
|
|
|
void Format( OUTPUTFORMATTER* out, int nestLevel ) const ;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Fill this object from information in the input stream \a aSpec, which is a
|
|
|
|
* #TEMPLATE_FIELDNAMES_LEXER.
|
|
|
|
*
|
|
|
|
* The entire textual element spec is <br>(field (name _yourfieldname_)(value _yourvalue_)
|
|
|
|
* visible))</br>. The presence of value is optional, the presence of visible is optional.
|
|
|
|
* When this function is called, the input token stream given by \a aSpec is assumed to be
|
|
|
|
* positioned at the '^' in the following example, i.e. just after the identifying keyword
|
|
|
|
* and before the content specifying stuff.<br>(field ^ (....) )</br>.
|
2010-06-17 16:30:10 +00:00
|
|
|
*
|
|
|
|
* @param aSpec is the input token stream of keywords and symbols.
|
|
|
|
*/
|
2017-06-08 21:47:21 +00:00
|
|
|
void Parse( TEMPLATE_FIELDNAMES_LEXER* aSpec );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Return a default symbol field name for field \a aFieldNdx for all components.
|
|
|
|
*
|
|
|
|
* These field names are not modifiable but template field names are.
|
|
|
|
*
|
|
|
|
* @param aFieldNdx The field number index, > 0.
|
|
|
|
* @param aTranslate If true, return the translated field name, else get the canonical name.
|
2010-06-17 16:30:10 +00:00
|
|
|
*/
|
2020-10-24 02:52:43 +00:00
|
|
|
static const wxString GetDefaultFieldName( int aFieldNdx, bool aTranslate = true );
|
2020-12-21 15:17:52 +00:00
|
|
|
|
|
|
|
wxString m_Name; // The field name
|
|
|
|
bool m_Visible; // Field defaults to being visible in schematic.
|
|
|
|
bool m_URL; // If field should have a browse button
|
2010-06-17 16:30:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES;
|
|
|
|
|
|
|
|
|
|
|
|
class TEMPLATES
|
|
|
|
{
|
2020-03-10 18:46:57 +00:00
|
|
|
public:
|
2020-04-06 09:15:57 +00:00
|
|
|
TEMPLATES() :
|
|
|
|
m_resolvedDirty( true )
|
|
|
|
{ }
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Serialize this object out as text into the given #OUTPUTFORMATTER.
|
2010-06-17 16:30:10 +00:00
|
|
|
*/
|
2020-03-10 18:46:57 +00:00
|
|
|
void Format( OUTPUTFORMATTER* out, int nestLevel, bool aGlobal ) const ;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Fill this object from information in the input stream handled by
|
|
|
|
* #TEMPLATE_FIELDNAMES_LEXER.
|
2010-06-17 16:30:10 +00:00
|
|
|
*/
|
2020-03-10 18:46:57 +00:00
|
|
|
void Parse( TEMPLATE_FIELDNAMES_LEXER* in, bool aGlobal );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Insert or append a wanted symbol field name into the field names template.
|
|
|
|
*
|
|
|
|
* Should be used for any symbol property editor. If the name already exists, it
|
|
|
|
* overwrites the same name.
|
2010-06-17 16:30:10 +00:00
|
|
|
*
|
|
|
|
* @param aFieldName is a full description of the wanted field, and it must not match
|
2020-12-21 15:17:52 +00:00
|
|
|
* any of the default field names.
|
2020-03-10 18:46:57 +00:00
|
|
|
* @param aGlobal indicates whether to add to the global or project table.
|
2010-06-17 16:30:10 +00:00
|
|
|
*/
|
2020-03-10 18:46:57 +00:00
|
|
|
void AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName, bool aGlobal );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Delete the entire contents.
|
2010-06-17 16:30:10 +00:00
|
|
|
*/
|
2020-03-10 18:46:57 +00:00
|
|
|
void DeleteAllFieldNameTemplates( bool aGlobal );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Return a template field name list for read only access.
|
2010-06-17 16:30:10 +00:00
|
|
|
*/
|
2020-03-10 18:46:57 +00:00
|
|
|
const TEMPLATE_FIELDNAMES& GetTemplateFieldNames();
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Return a specific list (global or project) for read only access.
|
2020-03-10 18:46:57 +00:00
|
|
|
*/
|
|
|
|
const TEMPLATE_FIELDNAMES& GetTemplateFieldNames( bool aGlobal );
|
2011-08-30 19:24:28 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Search for \a aName in the the template field name list.
|
2011-08-30 19:24:28 +00:00
|
|
|
*
|
|
|
|
* @param aName A wxString object containing the field name to search for.
|
2020-12-21 15:17:52 +00:00
|
|
|
* @return the template field name if found; NULL otherwise.
|
2011-08-30 19:24:28 +00:00
|
|
|
*/
|
2020-03-10 18:46:57 +00:00
|
|
|
const TEMPLATE_FIELDNAME* GetFieldName( const wxString& aName );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void resolveTemplates();
|
|
|
|
|
2020-12-21 15:17:52 +00:00
|
|
|
private:
|
|
|
|
TEMPLATE_FIELDNAMES m_globals;
|
|
|
|
TEMPLATE_FIELDNAMES m_project;
|
|
|
|
|
|
|
|
// Combined list. Project templates override global ones.
|
|
|
|
TEMPLATE_FIELDNAMES m_resolved;
|
|
|
|
bool m_resolvedDirty;
|
2010-06-17 16:30:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _TEMPLATE_FIELDNAME_H_
|