Commit f3d5c494 authored by Dick Hollenbeck's avatar Dick Hollenbeck

meet Ralph, a big harry template fieldnames patch

parent 39476ccd
eeschema/cmp_library_base.cpp
eeschema/cmp_library_base.h
eeschema/cmp_library_keywords.cpp
eeschema/cmp_library_keywords.h
eeschema/template_fieldnames_keywords.cpp
eeschema/template_fieldnames_keywords.h
pcbnew/dialog_freeroute_exchange_help_html.h
Makefile
CMakeFiles
......@@ -9,4 +11,5 @@ Testing
version.h
config.h
install_manifest.txt
Documentation/doxygen
*.cmake
......@@ -4,6 +4,32 @@ KiCad ChangeLog 2010
Please add newer entries at the top, list the date and your name with
email address.
2010-Jun-17 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
++eeschema:
Added "template fieldnames" to eeschema. This is a list of template elements
consisting of {name, value, visibility} which you want shown in the eeschema
component fieldname (property) editors (both schematic and library versions
of the editors). Template fieldnames are forced into the editors'
presentation of the fields even though those fields may not exist in the
component. Entering a non-blank value while in a field editor will cause the
field & value to be retained in the component. Therefore it is unusual to
provide a non-blank '.value' in a template, because a trip through the field
editor will invariably add that field to the component since the template
being applied has initially a non blank 'value'. The current template editor
is only going to last about a week and it does not support adding non-blank
template values yet, nor visibility control, only field '.name'. But the
template fieldnames configuration storage and component field editors do
know how to handle template.visible and template.value already, in addition
to template.name. See the file .eeschema in your home directory for the
configuration storage, keyword: FieldNames. e.g. only field Manufacturer has
a '.value':
FieldNames=(templatefields (field (name "Manufacturer")(value "IBM 12")) (field (name "Vendor")) (field (name "Installed")) (field (name "Ralphy") visible))
DSNLEXER is used to parse the FieldNames record, & OUTPUTFORMATTER to generate it.
2010-jun-15, UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
================================================================================
bitmap2component:
......
......@@ -39,23 +39,29 @@
# Usage:
#
# add_custom_command(
# OUTPUT ${CMAKE_BINARY_DIR}/cmp_library_base.h
# OUTPUT ${CMAKE_BINARY_DIR}/cmp_library_keywords.h
# ${CMAKE_BINARY_DIR}/cmp_library_keywords.cpp
# COMMAND ${CMAKE_COMMAND}
# -DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/token_list_file
# -Denum=YOURTOK_T
# -DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.lst
# -P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake
# DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.lst
# )
#
# Input parameters:
#
# inputFile - The name of the token list file.
# enum - The name of the enum to generate, defaults to DSN_T, but
# you'll get collisions if you don't override it.
# inputFile - The name of the token list file.
# outputPath - Optional output path to save the generated files. If not defined,
# the output path is the same path as the token list file path.
#
set( tokens "" )
set( lineCount 0 )
set( dsnErrorMsg "DSN token file generator failure:" )
if( NOT EXISTS ${inputFile} )
message( FATAL_ERROR "${dsnErrorMsg} file ${inputFile} cannot be found." )
endif( NOT EXISTS ${inputFile} )
......@@ -64,14 +70,20 @@ if( NOT EXISTS ${outputPath} )
get_filename_component( outputPath "${inputFile}" PATH )
endif( NOT EXISTS ${outputPath} )
if( NOT DEFINED enum )
set( enum DSN_T )
endif()
#message( STATUS "enum: ${enum}" )
# Separate the file name without extension from the full file path.
get_filename_component( result "${inputFile}" NAME_WE )
message( STATUS "Extracted file name ${result} from path ${inputFile}" )
# Create include and source file name from the list file name.
set( includeFileName "${outputPath}/${result}_base.h" )
set( sourceFileName "${outputPath}/${result}_base.cpp" )
set( includeFileName "${outputPath}/${result}_keywords.h" )
set( sourceFileName "${outputPath}/${result}_keywords.cpp" )
# Create tag for generating header file.
string( TOUPPER "${result}" fileNameTag )
......@@ -91,7 +103,7 @@ set( includeFileHeader
namespace DSN {
enum DSN_T {
enum ${enum} {
// these first few are negative special ones for syntax, and are
// inherited from DSNLEXER.
......@@ -122,7 +134,7 @@ set( sourceFileHeader
#include \"fctsys.h\"
#include \"macros.h\"
#include \"${result}_base.h\"
#include \"${result}_keywords.h\"
namespace DSN {
......@@ -130,7 +142,6 @@ namespace DSN {
#define TOKDEF(x) { #x, T_##x }
const KEYWORD ${result}_keywords[] = {
"
)
......@@ -193,8 +204,10 @@ endforeach( token ${tokens} )
file( APPEND "${includeFileName}"
"};
extern const KEYWORD ${result}_keywords[];
extern const unsigned ${result}_keyword_count;
} // End namespace DSN
} // End namespace DSN
#endif // End ${headerTag}
......@@ -208,6 +221,6 @@ file( APPEND "${sourceFileName}"
const unsigned ${result}_keyword_count = DIM( ${result}_keywords );
} // End namespace DSN
} // End namespace DSN
"
)
......@@ -182,6 +182,16 @@ const char* DSNLEXER::GetTokenText( int aTok )
}
wxString DSNLEXER::GetTokenString( int aTok )
{
wxString ret;
ret << wxT("'") << CONV_FROM_UTF8( GetTokenText(aTok) ) << wxT("'");
return ret;
}
void DSNLEXER::ThrowIOError( wxString aText, int charOffset ) throw (IOError)
{
// append to aText, do not overwrite
......@@ -193,6 +203,38 @@ void DSNLEXER::ThrowIOError( wxString aText, int charOffset ) throw (IOError)
}
void DSNLEXER::Expecting( int aTok ) throw( IOError )
{
wxString errText( _("Expecting") );
errText << wxT(" ") << GetTokenString( aTok );
ThrowIOError( errText, CurOffset() );
}
void DSNLEXER::Expecting( const wxString& text ) throw( IOError )
{
wxString errText( _("Expecting") );
errText << wxT(" '") << text << wxT("'");
ThrowIOError( errText, CurOffset() );
}
void DSNLEXER::Unexpected( int aTok ) throw( IOError )
{
wxString errText( _("Unexpected") );
errText << wxT(" ") << GetTokenString( aTok );
ThrowIOError( errText, CurOffset() );
}
void DSNLEXER::Unexpected( const wxString& text ) throw( IOError )
{
wxString errText( _("Unexpected") );
errText << wxT(" '") << text << wxT("'");
ThrowIOError( errText, CurOffset() );
}
/**
* Function isspace
* strips the upper bits of the int to ensure the value passed to ::isspace() is
......
......@@ -124,6 +124,8 @@ set(EESCHEMA_SRCS
symbdraw.cpp
symbedit.cpp
edit_graphic_bodyitem_text.cpp
template_fieldnames_keywords.cpp
template_fieldnames.cpp
tool_lib.cpp
tool_sch.cpp
tool_viewlib.cpp
......@@ -155,20 +157,34 @@ endif(APPLE)
# Generate DSN lexer header and source files for the component library file
# format.
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_base.h
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_keywords.h
${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_keywords.cpp
COMMAND ${CMAKE_COMMAND}
-DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.lst
-P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.lst
COMMENT "creating ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_base.h(.cpp)
COMMENT "creating ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_keywords.h(.cpp)
from ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.lst"
)
set_source_files_properties( cmp_library_lexer.cpp
PROPERTIES
OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_base.h
OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_keywords.h
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames_keywords.h
${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames_keywords.cpp
COMMAND ${CMAKE_COMMAND}
-Denum=TFIELD_T
-DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.lst
-P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.lst
COMMENT "creating ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames_keywords.h(.cpp)
from ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.lst"
)
add_executable(eeschema WIN32 MACOSX_BUNDLE ${EESCHEMA_SRCS} ${EESCHEMA_EXTRA_SRCS}
${EESCHEMA_RESOURCES})
......
......@@ -188,13 +188,15 @@ LIB_COMPONENT::LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary ) :
m_DrawPinNum = 1;
m_DrawPinName = 1;
/* The minimum requirements for a component are a value and a reference
* designator field.
*/
// Add the MANDATORY_FIELDS in RAM only. These are assumed to be present
// when the field editors are invoked.
LIB_FIELD* value = new LIB_FIELD( this, VALUE );
value->m_Text = aName;
drawings.push_back( value );
drawings.push_back( new LIB_FIELD( this, REFERENCE ) );
drawings.push_back( new LIB_FIELD( this, FOOTPRINT ) );
drawings.push_back( new LIB_FIELD( this, DATASHEET ) );
}
......@@ -388,19 +390,17 @@ void LIB_COMPONENT::RemoveDrawItem( LIB_DRAW_ITEM* aItem,
{
wxASSERT( aItem != NULL );
/* Value and reference fields cannot be removed. */
// none of the MANDATOR_FIELDS may be removed in RAM, but they may be
// omitted when saving to disk.
if( aItem->Type() == COMPONENT_FIELD_DRAW_TYPE )
{
LIB_FIELD* field = (LIB_FIELD*)aItem;
LIB_FIELD* field = (LIB_FIELD*) aItem;
if( field->m_FieldId == VALUE || field->m_FieldId == REFERENCE )
if( field->m_FieldId < MANDATORY_FIELDS )
{
wxString fieldType = ( field->m_FieldId == VALUE ) ?
_( "value" ) : _( "reference" );
wxLogWarning( _( "An attempt was made to remove the %s field \
from component %s in library %s." ),
GetChars( fieldType ), GetChars( GetName() ),
wxLogWarning( _( "An attempt was made to remove the %s field "
"from component %s in library %s." ),
GetChars( field->m_Name ), GetChars( GetName() ),
GetChars( GetLibraryName() ) );
return;
}
......@@ -518,8 +518,8 @@ LIB_PIN* LIB_COMPONENT::GetPin( const wxString& aNumber, int aUnit, int aConvert
bool LIB_COMPONENT::Save( FILE* aFile )
{
size_t i;
LIB_FIELD& value = GetValueField();
size_t i;
LIB_FIELD& value = GetValueField();
/* First line: it s a comment (component name for readers) */
if( fprintf( aFile, "#\n# %s\n#\n", CONV_TO_UTF8( value.m_Text ) ) < 0 )
......@@ -567,13 +567,33 @@ bool LIB_COMPONENT::Save( FILE* aFile )
LIB_FIELD_LIST fields;
GetFields( fields );
for( i = 0; i < fields.size(); i++ )
// Fixed fields:
// may have their own save policy so there is a separate loop for them.
for( i = 0; i < MANDATORY_FIELDS; ++i )
{
if( fields[i].m_Text.IsEmpty() && fields[i].m_Name.IsEmpty() )
continue;
if( !fields[i].m_Text.IsEmpty() )
{
if( !fields[i].Save( aFile ) )
return false;
}
}
if( !fields[i].Save( aFile ) )
return false;
// User defined fields:
// may have their own save policy so there is a separate loop for them.
int fieldId = MANDATORY_FIELDS; // really wish this would go away.
for( i = MANDATORY_FIELDS; i < fields.size(); ++i )
{
// There is no need to save empty fields, i.e. no reason to preserve field
// names now that fields names come in dynamically through the template
// fieldnames.
if( !fields[i].m_Text.IsEmpty() )
{
fields[i].m_FieldId = fieldId++;
if( !fields[i].Save( aFile ) )
return false;
}
}
/* Save the alias list: a line starting by "ALIAS" */
......@@ -623,6 +643,7 @@ bool LIB_COMPONENT::Save( FILE* aFile )
{
if( item.Type() == COMPONENT_FIELD_DRAW_TYPE )
continue;
if( !item.Save( aFile ) )
return false;
}
......@@ -637,6 +658,7 @@ bool LIB_COMPONENT::Save( FILE* aFile )
return true;
}
bool LIB_COMPONENT::Load( FILE* aFile, char* aLine, int* aLineNum,
wxString& aErrorMsg )
{
......@@ -832,8 +854,8 @@ bool LIB_COMPONENT::LoadDrawEntries( FILE* aFile, char* aLine,
{
if( GetLine( aFile, aLine, aLineNum, LINE_BUFFER_LEN_LARGE ) == NULL )
{
aErrorMsg = wxT( "file ended prematurely while attempting \
to flush to end of drawing section." );
aErrorMsg = wxT( "file ended prematurely while attempting "
"to flush to end of drawing section." );
return false;
}
} while( strncmp( aLine, "ENDDRAW", 7 ) != 0 );
......@@ -868,21 +890,26 @@ bool LIB_COMPONENT::LoadField( char* aLine, wxString& aErrorMsg )
{
LIB_FIELD* field = new LIB_FIELD( this );
if ( !field->Load( aLine, aErrorMsg ) )
if( !field->Load( aLine, aErrorMsg ) )
{
SAFE_DELETE( field );
return false;
}
if( field->m_FieldId == REFERENCE )
{
GetReferenceField() = *field;
SAFE_DELETE( field );
}
else if ( field->m_FieldId == VALUE )
if( field->m_FieldId < MANDATORY_FIELDS )
{
GetValueField() = *field;
name = field->m_Text;
LIB_FIELD* fixedField = GetField( field->m_FieldId );
// this will fire only if somebody broke a constructor or editor.
// MANDATORY_FIELDS are alway present in ram resident components, no
// exceptions, and they always have their names set, even fixed fields.
wxASSERT( fixedField );
*fixedField = *field;
if( field->m_FieldId == VALUE )
name = field->m_Text;
SAFE_DELETE( field );
}
else
......@@ -932,6 +959,7 @@ EDA_Rect LIB_COMPONENT::GetBoundaryBox( int aUnit, int aConvert )
if( ( item.m_Unit > 0 ) && ( ( unitCount > 1 ) && ( aUnit > 0 )
&& ( aUnit != item.m_Unit ) ) )
continue;
if( item.m_Convert > 0
&& ( ( aConvert > 0 ) && ( aConvert != item.m_Convert ) ) )
continue;
......@@ -947,48 +975,69 @@ EDA_Rect LIB_COMPONENT::GetBoundaryBox( int aUnit, int aConvert )
}
/** Function SetFields
* initialize fields from a vector of fields
* @param aFields a std::vector <LIB_FIELD> to import.
*/
void LIB_COMPONENT::SetFields( const std::vector <LIB_FIELD> aFields )
void LIB_COMPONENT::deleteAllFields()
{
LIB_FIELD* field;
LIB_DRAW_ITEM_LIST::iterator it;
for( size_t i = 0; i < aFields.size(); i++ )
for( it = drawings.begin(); it!=drawings.end(); /* deleting */ )
{
field = GetField( aFields[i].m_FieldId );
if( field )
if( it->Type() != COMPONENT_FIELD_DRAW_TYPE )
{
*field = aFields[i];
if( (int) i == VALUE )
name = field->m_Text;
++it;
continue;
}
/* If the field isn't set, don't add it to the component. */
if( aFields[i].m_Text.IsEmpty() )
continue;
// 'it' is not advanced, but should point to next in list after erase()
drawings.erase( it );
}
}
void LIB_COMPONENT::SetFields( const std::vector <LIB_FIELD>& aFields )
{
deleteAllFields();
for( unsigned i=0; i<aFields.size(); ++i )
{
// drawings is a ptr_vector, new and copy an object on the heap.
LIB_FIELD* field = new LIB_FIELD( aFields[i] );
field = new LIB_FIELD( aFields[i] );
drawings.push_back( field );
}
drawings.sort();
drawings.sort(); // would be nice to know why...
}
void LIB_COMPONENT::GetFields( LIB_FIELD_LIST& aList )
{
LIB_FIELD* field;
// The only caller of this function is the library field editor, so it
// establishes policy here.
// Grab the MANDATORY_FIELDS first, in expected order given by
// enum NumFieldType
for( int id=0; id<MANDATORY_FIELDS; ++id )
{
field = GetField( id );
// the MANDATORY_FIELDS are exactly that in RAM.
wxASSERT( field );
aList.push_back( *field );
}
// Now grab all the rest of fields.
BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings )
{
if( item.Type() != COMPONENT_FIELD_DRAW_TYPE )
continue;
LIB_FIELD* field = ( LIB_FIELD* ) &item;
field = ( LIB_FIELD* ) &item;
if( (unsigned) field->m_FieldId < MANDATORY_FIELDS )
continue; // was added above
aList.push_back( *field );
}
}
......@@ -1011,6 +1060,23 @@ LIB_FIELD* LIB_COMPONENT::GetField( int aId )
}
LIB_FIELD* LIB_COMPONENT::FindField( const wxString& aFieldName )
{
BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings )
{
if( item.Type() != COMPONENT_FIELD_DRAW_TYPE )
continue;
LIB_FIELD* field = ( LIB_FIELD* ) &item;
if( field->m_Name == aFieldName )
return field;
}
return NULL;
}
LIB_FIELD& LIB_COMPONENT::GetValueField()
{
LIB_FIELD* field = GetField( VALUE );
......
......@@ -118,9 +118,9 @@ public:
}
};
typedef boost::ptr_vector< CMP_LIB_ENTRY > LIB_ENTRY_LIST;
extern bool operator<( const CMP_LIB_ENTRY& aItem1, const CMP_LIB_ENTRY& aItem2 );
extern int LibraryEntryCompare( const CMP_LIB_ENTRY* aItem1, const CMP_LIB_ENTRY* aItem2 );
......@@ -183,6 +183,9 @@ private:
* Used only by the component editor LibEdit
* to store aliases info during edition
* usually void outside the component editor */
void deleteAllFields();
public:
LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary = NULL );
LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary = NULL );
......@@ -301,19 +304,32 @@ public:
void SetNormal() { m_options = ENTRY_NORMAL; }
/**
* Initialize fields from a vector of fields.
* Function SetFields
* overwrites all the existing in this component with fields supplied
* in \a aFieldsList. The only known caller of this function is the
* library component field editor, and it establishes needed behavior.
*
* @param aFields - a std::vector <LIB_FIELD> to import.
* @param aFieldsList is a set of fields to import, removing all previous fields.
*/
void SetFields( const std::vector <LIB_FIELD> aFields );
void SetFields( const std::vector <LIB_FIELD>& aFieldsList );
/**
* Return list of field references of component.
* Function GetFields
* returns a list of fields withing this component. The only known caller of
* this function is the library component field editor, and it establishes
* needed behavior.
*
* @param aList - List to add field references to.
* @param aList - List to add fields to
*/
void GetFields( LIB_FIELD_LIST& aList );
/**
* Function FindField
* finds a field within this component matching \a aFieldName and returns
* it or NULL if not found.
*/
LIB_FIELD* FindField( const wxString& aFieldName );
/**
* Return pointer to the requested field.
*
......
......@@ -3,6 +3,7 @@
/**********************************************************/
#include "fctsys.h"
#include "appl_wxstruct.h"
#include "gr_basic.h"
#include "common.h"
#include "base_struct.h"
......@@ -35,8 +36,8 @@
*
* 0 = REFERENCE
* 1 = VALUE
* 3 = FOOTPRINT (default Footprint)
* 4 = DOCUMENTATION (user doc link)
* 2 = FOOTPRINT (default Footprint)
* 3 = DOCUMENTATION (user doc link)
*
* others = free fields
*/
......@@ -81,6 +82,11 @@ void LIB_FIELD::Init( int id )
m_FieldId = id;
m_Size.x = m_Size.y = DEFAULT_SIZE_TEXT;
m_typeName = _( "Field" );
// fields in RAM must always have names, because we are trying to get
// less dependent on field ids and more dependent on names.
// Plus assumptions are made in the field editors.
m_Name = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
}
......@@ -94,13 +100,16 @@ bool LIB_FIELD::Save( FILE* ExportFile )
hjustify = 'L';
else if( m_HJustify == GR_TEXT_HJUSTIFY_RIGHT )
hjustify = 'R';
vjustify = 'C';
if( m_VJustify == GR_TEXT_VJUSTIFY_BOTTOM )
vjustify = 'B';
else if( m_VJustify == GR_TEXT_VJUSTIFY_TOP )
vjustify = 'T';
if( text.IsEmpty() )
text = wxT( "~" );
if( fprintf( ExportFile, "F%d \"%s\" %d %d %d %c %c %c %c%c%c",
m_FieldId, CONV_TO_UTF8( text ), m_Pos.x, m_Pos.y, m_Size.x,
m_Orient == 0 ? 'H' : 'V',
......@@ -115,8 +124,10 @@ bool LIB_FIELD::Save( FILE* ExportFile )
* Just because default name depends on the language and can change from
* a country to an other
*/
wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( m_FieldId );
if( m_FieldId >= FIELD1 && !m_Name.IsEmpty()
&& m_Name != ReturnDefaultFieldName( m_FieldId )
&& m_Name != defName
&& fprintf( ExportFile, " \"%s\"", CONV_TO_UTF8( m_Name ) ) < 0 )
return false;
......@@ -177,8 +188,7 @@ bool LIB_FIELD::Load( char* line, wxString& errorMsg )
if( cnt < 5 )
{
errorMsg.Printf( wxT( "field %d does not have the correct number of \
parameters" ),
errorMsg.Printf( wxT( "field %d does not have the correct number of parameters" ),
m_FieldId );
return false;
}
......@@ -192,8 +202,7 @@ parameters" ),
m_Orient = TEXT_ORIENT_VERT;
else
{
errorMsg.Printf( wxT( "field %d text orientation parameter <%c> is \
not valid" ),
errorMsg.Printf( wxT( "field %d text orientation parameter <%c> is not valid" ),
textOrient );
return false;
}
......@@ -204,8 +213,7 @@ not valid" ),
m_Attributs |= TEXT_NO_VISIBLE;
else
{
errorMsg.Printf( wxT( "field %d text visible parameter <%c> is not \
valid" ),
errorMsg.Printf( wxT( "field %d text visible parameter <%c> is not valid" ),
textVisible );
return false;
}
......@@ -223,9 +231,9 @@ valid" ),
m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
else
{
errorMsg.Printf( wxT( "field %d text horizontal justification \
parameter <%c> is not valid" ),
textHJustify );
errorMsg.Printf(
wxT( "field %d text horizontal justification parameter <%c> is not valid" ),
textHJustify );
return false;
}
......@@ -237,9 +245,9 @@ parameter <%c> is not valid" ),
m_VJustify = GR_TEXT_VJUSTIFY_TOP;
else
{
errorMsg.Printf( wxT( "field %d text vertical justification \
parameter <%c> is not valid" ),
textVJustify[0] );
errorMsg.Printf(
wxT( "field %d text vertical justification parameter <%c> is not valid" ),
textVJustify[0] );
return false;
}
......@@ -249,7 +257,15 @@ parameter <%c> is not valid" ),
m_Bold = true;
}
if( m_FieldId >= FIELD1 )
// fields in RAM must always have names.
if( m_FieldId < MANDATORY_FIELDS )
{
// Fields in RAM must always have names, because we are trying to get
// less dependent on field ids and more dependent on names.
// Plus assumptions are made in the field editors.
m_Name = TEMPLATE_FIELDNAME::GetDefaultFieldName( m_FieldId );
}
else
{
ReadDelimitedText( fieldUserName, line, sizeof( fieldUserName ) );
m_Name = CONV_FROM_UTF8( fieldUserName );
......@@ -259,7 +275,6 @@ parameter <%c> is not valid" ),
}
/** Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
......@@ -346,7 +361,9 @@ bool LIB_FIELD::HitTest( const wxPoint& refPos )
return HitTest( refPos, 0, DefaultTransformMatrix );
}
/** Function HitTest
/**
* Function HitTest
* @return true if the point aPosRef is near this object
* @param aPosRef = a wxPoint to test
* @param aThreshold = unused here (TextHitTest calculates its threshold )
......@@ -527,34 +544,3 @@ EDA_Rect LIB_FIELD::GetBoundingBox()
return rect;
}
/**
* Function ReturnDefaultFieldName
* Return the default field name from its index (REFERENCE, VALUE ..)
* FieldDefaultNameList is not static, because we want the text translation
* for I18n
* @param aFieldNdx = Filed number (>= 0)
*/
wxString ReturnDefaultFieldName( int aFieldNdx )
{
// avoid unnecessarily copying wxStrings at runtime.
static const wxString defaults[] = {
_( "Reference" ), // Reference of part, i.e. "IC21"
_( "Value" ), // Value of part, i.e. "3.3K" and name in lib
// for lib entries
_( "Footprint" ), // Footprint, used by cvpcb or pcbnew, i.e.
// "16DIP300"
_( "Datasheet" ), // A link to an user document, if wanted
};
if( (unsigned) aFieldNdx <= DATASHEET )
return defaults[ aFieldNdx ];
else
{
wxString ret = _( "Field" );
ret << ( aFieldNdx - FIELD1 + 1);
return ret;
}
}
......@@ -9,32 +9,19 @@
#include "classes_body_items.h"
class LIB_FIELD;
typedef std::vector< LIB_FIELD > LIB_FIELD_LIST;
/* Fields , same as component fields.
* can be defined in libraries (mandatory for ref and value, ca be useful for
* footprints)
* 2 Fields are always defined :
* Prefix (U, IC..) with gives the reference in schematic)
* Name (74LS00..) used to find the component in libraries, and give the
* default value in schematic
/**
* Class LIB_FIELD
* is used in symbol libraries. At least MANDATORY_FIELDS are always present
* in a ram resident library symbol. All constructors must ensure this because
* the component property editor assumes it.
* @see enum NumFieldType
*/
class LIB_FIELD : public LIB_DRAW_ITEM, public EDA_TextStruct
{
public:
int m_FieldId; /* 0 = REFERENCE
* 1 = VALUE
* 3 = FOOTPRINT (default Footprint)
* 4 = DOCUMENTATION (user doc link)
* others = free fields
*/
wxString m_Name; /* Field Name (not the field text itself, that is
* .m_Text) */
int m_FieldId; ///< @see enum NumFieldType
wxString m_Name; ///< Name (not the field text value itself, that is .m_Text)
public:
......@@ -84,7 +71,8 @@ public:
int aColor, int aDrawMode, void* aData,
const int aTransformMatrix[2][2] );
/** Function IsVisible
/**
* Function IsVisible
* @return true is this field is visible, false if flagged invisible
*/
bool IsVisible()
......@@ -174,4 +162,6 @@ protected:
virtual void DoSetWidth( int width ) { m_Width = width; }
};
typedef std::vector< LIB_FIELD > LIB_FIELD_LIST;
#endif // CLASS_LIBENTRY_FIELDS_H
......@@ -28,19 +28,18 @@ class LIB_FIELD;
class SCH_FIELD : public SCH_ITEM, public EDA_TextStruct
{
public:
int m_FieldId; /* Field indicator type (REFERENCE, VALUE or
* other id) */
int m_FieldId; ///< Field index, @see enum NumFieldType
wxString m_Name; /* Field name (ref, value,pcb, sheet, filed 1..
* and for fields 1 to 8 the name is editable
*/
bool m_AddExtraText; /* Mainly for REFERENCE, add extra info
wxString m_Name;
bool m_AddExtraText; /**< for REFERENCE, add extra info
* (for REFERENCE: add part selection text */
public:
SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_COMPONENT* aParent,
wxString aName = wxEmptyString );
~SCH_FIELD();
virtual wxString GetClass() const
......
......@@ -3,6 +3,7 @@
/**************************************************************/
#include "fctsys.h"
#include "appl_wxstruct.h"
#include "class_drawpanel.h"
#include "gr_basic.h"
#include "common.h"
......@@ -63,7 +64,6 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_COMPONENT& libComponent,
const wxPoint& pos, bool setNewItemFlag ) :
SCH_ITEM( NULL, TYPE_SCH_COMPONENT )
{
Init( pos );
m_Multi = unit;
......@@ -74,42 +74,39 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_COMPONENT& libComponent,
if( setNewItemFlag )
m_Flags = IS_NEW | IS_MOVED;
// Import predefined fields from the library component:
// Import user defined fields from the library component:
LIB_FIELD_LIST libFields;
libComponent.GetFields( libFields );
for( size_t i = 0; i < libFields.size(); i++ )
for( LIB_FIELD_LIST::iterator it = libFields.begin(); it!=libFields.end(); ++it )
{
if( libFields[i].m_Text.IsEmpty() && libFields[i].m_Name.IsEmpty() )
// Can no longer insert an empty name, since names are now keys. The
// field index is not used beyond the first MANDATORY_FIELDS
if( it->m_Name.IsEmpty() )
continue;
int field_idx = libFields[i].m_FieldId;
/* Add extra fields if library component has more than the default
* number of fields.
*/
if( field_idx >= GetFieldCount() )
// See if field by same name already exists.
SCH_FIELD* schField = FindField( it->m_Name );
if( !schField )
{
while( field_idx >= GetFieldCount() )
{
SCH_FIELD field( wxPoint( 0, 0 ), GetFieldCount(), this,
ReturnDefaultFieldName( field_idx ) );
AddField( field );
}
SCH_FIELD fld( wxPoint( 0, 0 ), GetFieldCount(), this, it->m_Name );
schField = AddField( fld );
}
SCH_FIELD* schField = GetField( field_idx );
schField->m_Pos = m_Pos + libFields[i].m_Pos;
schField->ImportValues( libFields[i] );
schField->m_Text = libFields[i].m_Text;
schField->m_Name = ( field_idx < FIELD1 ) ? ReturnDefaultFieldName( field_idx ) :
libFields[i].m_Name;
}
schField->m_Pos = m_Pos + it->m_Pos;
schField->ImportValues( *it );
schField->m_Text = it->m_Text;
}
wxString msg = libComponent.GetReferenceField().m_Text;
if( msg.IsEmpty() )
msg = wxT( "U" );
m_PrefixString = msg;
// update the reference -- just the prefix for now.
......@@ -147,20 +144,19 @@ SCH_COMPONENT::SCH_COMPONENT( const SCH_COMPONENT& aTemplate ) :
void SCH_COMPONENT::Init( const wxPoint& pos )
{
m_Pos = pos;
m_Multi = 0; /* In multi unit chip - which unit to draw. */
m_Convert = 0; /* De Morgan Handling */
m_Multi = 0; // In multi unit chip - which unit to draw.
m_Convert = 0; // De Morgan Handling
/* The rotation/mirror transformation matrix. pos normal */
// The rotation/mirror transformation matrix. pos normal
m_Transform[0][0] = 1;
m_Transform[0][1] = 0;
m_Transform[1][0] = 0;
m_Transform[1][1] = -1;
m_Fields.reserve( DEFAULT_NUMBER_OF_FIELDS );
for( int i = 0; i < DEFAULT_NUMBER_OF_FIELDS; ++i )
// construct only the mandatory fields, which are the first 4 only.
for( int i = 0; i < MANDATORY_FIELDS; ++i )
{
SCH_FIELD field( pos, i, this, ReturnDefaultFieldName( i ) );
SCH_FIELD field( pos, i, this, TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) );
if( i==REFERENCE )
field.SetLayer( LAYER_REFERENCEPART );
......@@ -300,7 +296,7 @@ wxString SCH_COMPONENT::ReturnFieldName( int aFieldNdx ) const
if( !field->m_Name.IsEmpty() )
return field->m_Name;
else
return ReturnDefaultFieldName( aFieldNdx );
return TEMPLATE_FIELDNAME::GetDefaultFieldName( aFieldNdx );
}
return wxEmptyString;
......@@ -504,14 +500,27 @@ SCH_FIELD* SCH_COMPONENT::GetField( int aFieldNdx ) const
wxASSERT( field );
// use case to remove const-ness
// use cast to remove const-ness
return (SCH_FIELD*) field;
}
void SCH_COMPONENT::AddField( const SCH_FIELD& aField )
SCH_FIELD* SCH_COMPONENT::AddField( const SCH_FIELD& aField )
{
int newNdx = m_Fields.size();
m_Fields.push_back( aField );
return &m_Fields[newNdx];
}
SCH_FIELD* SCH_COMPONENT::FindField( const wxString& aFieldName )
{
for( unsigned i=0; i<m_Fields.size(); ++i )
{
if( aFieldName == m_Fields[i].m_Name )
return &m_Fields[i];
}
return NULL;
}
......@@ -607,7 +616,7 @@ void SCH_COMPONENT::SwapData( SCH_COMPONENT* copyitem )
{
GetField(ii)->SetParent( this );
}
EXCHG( m_PathsAndReferences, copyitem->m_PathsAndReferences);
}
......@@ -1038,17 +1047,34 @@ bool SCH_COMPONENT::Save( FILE* f ) const
}
}
for( int fieldNdx = 0; fieldNdx < GetFieldCount(); ++fieldNdx )
// update the ugly field index, which I would like to see go away someday soon.
for( unsigned i=0; i<m_Fields.size(); ++i )
{
SCH_FIELD* field = GetField( fieldNdx );
wxString defaultName = ReturnDefaultFieldName( fieldNdx );
SCH_FIELD* fld = GetField( i );
fld->m_FieldId = i; // we don't need field Ids, please be gone.
}
// only save the field if there is a value in the field or if field name
// is different than the default field name
if( field->m_Text.IsEmpty() && defaultName == field->m_Name )
continue;
// Fixed fields:
// Save fixed fields which are non blank.
for( unsigned i=0; i<MANDATORY_FIELDS; ++i )
{
SCH_FIELD* fld = GetField( i );
if( !fld->m_Text.IsEmpty() )
{
if( !fld->Save( f ) )
return false;
}
}
if( !field->Save( f ) )
// User defined fields:
// The *policy* about which user defined fields are part of a symbol is now
// only in the dialog editors. No policy should be enforced here, simply
// save all the user defined fields, they are present because a dialog editor
// thought they should be. If you disagree, go fix the dialog editors.
for( unsigned i=MANDATORY_FIELDS; i<m_Fields.size(); ++i )
{
SCH_FIELD* fld = GetField( i );
if( !fld->Save( f ) )
return false;
}
......
......@@ -31,32 +31,6 @@ struct Error
}
};
/**
* Enum NumFieldType
* is the numbered set of all fields a SCH_COMPONENT can hold
* Note more than 8 user fields are allowed, but for efficiency reasons
* the defualt number of users fields is 8
*/
enum NumFieldType {
REFERENCE = 0, ///< Field Reference of part, i.e. "IC21"
VALUE, ///< Field Value of part, i.e. "3.3K"
FOOTPRINT, ///< Field Name Module PCB, i.e. "16DIP300"
DATASHEET, ///< name of datasheet
FIELD1,
FIELD2,
FIELD3,
FIELD4,
FIELD5,
FIELD6,
FIELD7,
FIELD8,
DEFAULT_NUMBER_OF_FIELDS
};
/// A container for several SCH_FIELD items
typedef std::vector<SCH_FIELD> SCH_FIELDS;
......@@ -230,6 +204,8 @@ public:
*/
EDA_Rect GetBoundingBox();
//-----<Fields>-----------------------------------------------------------
/**
* Function ReturnFieldName
* returns the Field name given a field index like (REFERENCE, VALUE ..)
......@@ -241,7 +217,7 @@ public:
/**
* Function GetField
* returns a field.
* @param aFieldNdx An index into the array of fields
* @param aFieldNdx An index into the array of fields, not a field id.
* @return SCH_FIELD* - the field value or NULL if does not exist
*/
SCH_FIELD* GetField( int aFieldNdx ) const;
......@@ -251,14 +227,22 @@ public:
* adds a field to the component. The field is copied as it is put into
* the component.
* @param aField A const reference to the SCH_FIELD to add.
* @return SCH_FIELD* - the newly inserted field.
*/
SCH_FIELD* AddField( const SCH_FIELD& aField );
/**
* Function FindField
* searches for SCH_FIELD with \a aFieldName and returns it if found, else NULL.
*/
void AddField( const SCH_FIELD& aField );
SCH_FIELD* FindField( const wxString& aFieldName );
void SetFields( const SCH_FIELDS& aFields )
{
m_Fields = aFields; // vector copying, length is changed possibly
}
//-----</Fields>----------------------------------------------------------
/**
* Function GetFieldCount
......
......@@ -3,4 +3,4 @@
* library file DSN lexer which will replace the current library and library
* document file formats.
*/
#include "cmp_library_base.cpp"
#include "cmp_library_keywords.cpp"
......@@ -3,6 +3,7 @@
#include <algorithm>
#include "fctsys.h"
#include "appl_wxstruct.h"
#include "gr_basic.h"
#include "common.h"
#include "class_drawpanel.h"
......@@ -111,22 +112,6 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( wxWindow
{
GetSizer()->SetSizeHints( this );
}
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::reinitializeFieldsIdAndDefaultNames( )
{
for( unsigned new_id = FIELD1; new_id < m_FieldsBuf.size(); new_id++ )
{
unsigned old_id = m_FieldsBuf[new_id].m_FieldId;
if ( old_id != new_id )
{
if ( m_FieldsBuf[new_id].m_Name == ReturnDefaultFieldName( old_id ) )
m_FieldsBuf[new_id].m_Name = ReturnDefaultFieldName( new_id );
m_FieldsBuf[new_id].m_FieldId = new_id;
}
}
}
......@@ -242,7 +227,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event
copyPanelToOptions();
/* save old cmp in undo list if not already in edit, or moving ... */
// save old cmp in undo list if not already in edit, or moving ...
if( m_Cmp->m_Flags == 0 )
m_Parent->SaveCopyInUndoList( m_Cmp, UR_CHANGED );
......@@ -252,10 +237,11 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event
m_FieldsBuf[i].m_Pos += m_Cmp->m_Pos;
}
// delete any fields with no name
for( unsigned i = FIELD1; i<m_FieldsBuf.size(); )
// delete any fields with no name or no value before we copy all of m_FieldsBuf
// back into the component
for( unsigned i = MANDATORY_FIELDS; i<m_FieldsBuf.size(); )
{
if( m_FieldsBuf[i].m_Name.IsEmpty() )
if( m_FieldsBuf[i].m_Name.IsEmpty() || m_FieldsBuf[i].m_Text.IsEmpty() )
{
m_FieldsBuf.erase( m_FieldsBuf.begin() + i );
continue;
......@@ -272,13 +258,12 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event
// copy all the fields back, and change the length of m_Fields.
m_Cmp->SetFields( m_FieldsBuf );
// Reference has a specific initialisation, depending on the current active sheet
// because for a given component, in a complexe hierarchy, there are more than one
// reference.
m_Cmp->SetRef( m_Parent->GetSheet(), m_FieldsBuf[REFERENCE].m_Text );
m_Parent->OnModify( );
m_Parent->TestDanglingEnds( m_Parent->GetScreen()->EEDrawList, NULL );
......@@ -303,7 +288,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::addFieldButtonHandler( wxCommandEvent&
blank.m_Orient = m_FieldsBuf[REFERENCE].m_Orient;
m_FieldsBuf.push_back( blank );
m_FieldsBuf[fieldNdx].m_Name = ReturnDefaultFieldName(fieldNdx);
m_FieldsBuf[fieldNdx].m_Name = TEMPLATE_FIELDNAME::GetDefaultFieldName(fieldNdx);
m_skipCopyFromPanel = true;
setRowItem( fieldNdx, m_FieldsBuf[fieldNdx] );
......@@ -320,7 +305,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::deleteFieldButtonHandler( wxCommandEven
if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
return;
if( fieldNdx < FIELD1 )
if( fieldNdx < MANDATORY_FIELDS )
{
wxBell();
return;
......@@ -333,8 +318,6 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::deleteFieldButtonHandler( wxCommandEven
if( fieldNdx >= m_FieldsBuf.size() )
--fieldNdx;
// Reinitialize fields IDs and default names:
reinitializeFieldsIdAndDefaultNames();
updateDisplay( );
setSelectedFieldNdx( fieldNdx );
......@@ -342,14 +325,14 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::deleteFieldButtonHandler( wxCommandEven
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC:: moveUpButtonHandler( wxCommandEvent& event )
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::moveUpButtonHandler( wxCommandEvent& event )
{
unsigned fieldNdx = getSelectedFieldNdx();
if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
return;
if( fieldNdx <= FIELD1 )
if( fieldNdx <= MANDATORY_FIELDS )
{
wxBell();
return;
......@@ -371,8 +354,6 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC:: moveUpButtonHandler( wxCommandEvent& e
m_FieldsBuf[fieldNdx] = tmp;
setRowItem( fieldNdx, tmp );
// Reinitialize fields IDs and default names:
reinitializeFieldsIdAndDefaultNames();
updateDisplay( );
m_skipCopyFromPanel = true;
......@@ -408,10 +389,14 @@ int DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::getSelectedFieldNdx()
}
static bool SortFieldsById(const SCH_FIELD& item1, const SCH_FIELD& item2)
SCH_FIELD* DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::findField( const wxString& aFieldName )
{
return item1.m_FieldId < item2.m_FieldId;
for( unsigned i=0; i<m_FieldsBuf.size(); ++i )
{
if( aFieldName == m_FieldsBuf[i].m_Name )
return &m_FieldsBuf[i];
}
return NULL;
}
......@@ -419,6 +404,18 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::InitBuffers( SCH_COMPONENT* aComponent
{
m_Cmp = aComponent;
/* We have 3 component related field lists to be aware of: 1) UI
presentation, 2) fields in component ram copy, and 3) fields recorded
with component on disk. m_FieldsBuf is the list of UI fields, and this
list is not the same as the list which is in the component, which is
also not the same as the list on disk. All 3 lists are potentially
different. In the UI we choose to preserve the order of the first
MANDATORY_FIELDS which are sometimes called fixed fields. Then we append
the template fieldnames in the exact same order as the template
fieldname editor shows them. Then we append any user defined fieldnames
which came from the component.
*/
m_LibEntry = CMP_LIBRARY::FindLibraryComponent( m_Cmp->m_ChipName );
#if 0 && defined(DEBUG)
......@@ -430,28 +427,85 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::InitBuffers( SCH_COMPONENT* aComponent
#endif
// copy all the fields to a work area
m_FieldsBuf = aComponent->m_Fields;
// When this code was written, all field constructors ensure that the fixed fields
// are all present within a component. So we can knowingly copy them over
// in the normal order. Copy only the fixed fields at first.
// Please do not break the field constructors.
m_FieldsBuf.clear();
for( int i=0; i<MANDATORY_FIELDS; ++i )
{
m_FieldsBuf.push_back( aComponent->m_Fields[i] );
// make the editable field position relative to the component
m_FieldsBuf[i].m_Pos -= m_Cmp->m_Pos;
}
// Add template fieldnames:
// Now copy in the template fields, in the order that they are present in the
// template field editor UI.
const TEMPLATE_FIELDNAMES& tfnames = m_Parent->GetTemplateFieldNames();
for( TEMPLATE_FIELDNAMES::const_iterator it = tfnames.begin(); it!=tfnames.end(); ++it )
{
// add a new field unconditionally to the UI only
SCH_FIELD fld( wxPoint(0,0), -1 /* id is a relic */, NULL, it->m_Name );
// See if field by same name already exists in component.
SCH_FIELD* schField = aComponent->FindField( it->m_Name );
// If the field does not already exist in the component, then we
// use defaults from the template fieldname, otherwise the original
// values from the component will be set.
if( !schField )
{
if( !it->m_Visible )
fld.m_Attributs |= TEXT_NO_VISIBLE;
else
fld.m_Attributs &= ~TEXT_NO_VISIBLE;
fld.m_Text = it->m_Value; // empty? ok too.
}
else
{
fld = *schField;
// make the editable field position relative to the component
fld.m_Pos -= m_Cmp->m_Pos;
}
m_FieldsBuf.push_back( fld );
}
// Lastly, append any original fields from the component which were not added
// from the set of fixed fields nor from the set of template fields.
for( unsigned i=MANDATORY_FIELDS; i<aComponent->m_Fields.size(); ++i )
{
SCH_FIELD* cmp = &aComponent->m_Fields[i];
SCH_FIELD* buf = findField( cmp->m_Name );
if( !buf )
{
int newNdx = m_FieldsBuf.size();
m_FieldsBuf.push_back( *cmp );
// make the editable field position relative to the component
m_FieldsBuf[newNdx].m_Pos -= m_Cmp->m_Pos;
}
}
// Sort files by field id,if they are not entered by id
sort(m_FieldsBuf.begin(), m_FieldsBuf.end(), SortFieldsById);
#if 0 && defined(DEBUG)
for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
{
printf( "m_FieldsBuf[%d] (x=%d, y=%d)\n", i, m_FieldsBuf[i].m_Pos.x,
m_FieldsBuf[i].m_Pos.y );
printf( "m_FieldsBuf[%d] (x=%-3d, y=%-3d) name:%s\n", i, m_FieldsBuf[i].m_Pos.x,
m_FieldsBuf[i].m_Pos.y, CONV_TO_UTF8(m_FieldsBuf[i].m_Name) );
}
#endif
m_FieldsBuf[REFERENCE].m_Text = m_Cmp->GetRef( m_Parent->GetSheet() );
for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
{
// make the editable field position relative to the component
m_FieldsBuf[i].m_Pos -= m_Cmp->m_Pos;
setRowItem( i, m_FieldsBuf[i] );
}
......@@ -512,22 +566,27 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copySelectedFieldToPanel()
rotateCheckBox->SetValue( field.m_Orient == TEXT_ORIENT_VERT );
int style = 0;
if( field.m_Italic )
style = 1;
if( field.m_Bold )
style |= 2;
m_StyleRadioBox->SetSelection( style );
fieldNameTextCtrl->SetValue( field.m_Name );
// if fieldNdx == REFERENCE, VALUE, FOOTPRINT, or DATASHEET, then
//disable editing
fieldNameTextCtrl->Enable( fieldNdx >= FIELD1 );
fieldNameTextCtrl->SetEditable( fieldNdx >= FIELD1 );
moveUpButton->Enable( fieldNdx >= FIELD1 ); /* disable move up button
* for non moveable fields */
// if fieldNdx == REFERENCE, VALUE, then disable delete button
deleteFieldButton->Enable( fieldNdx > VALUE );
// the names of the fixed fields are not editable, others are.
fieldNameTextCtrl->Enable( fieldNdx >= MANDATORY_FIELDS );
fieldNameTextCtrl->SetEditable( fieldNdx >= MANDATORY_FIELDS );
// only user defined fields may be moved, and not the top most user defined
// field since it would be moving up into the fixed fields, > not >=
moveUpButton->Enable( fieldNdx > MANDATORY_FIELDS );
// may only delete user defined fields
deleteFieldButton->Enable( fieldNdx >= MANDATORY_FIELDS );
fieldValueTextCtrl->SetValue( field.m_Text );
......@@ -554,11 +613,12 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copySelectedFieldToPanel()
rotateCheckBox->SetValue( m_FieldsBuf[REFERENCE].m_Orient == TEXT_ORIENT_VERT );
coord.x = m_FieldsBuf[REFERENCE].m_Pos.x
+ ( fieldNdx - FIELD1 + 1 ) * 100;
+ ( fieldNdx - MANDATORY_FIELDS + 1 ) * 100;
coord.y = m_FieldsBuf[REFERENCE].m_Pos.y
+ ( fieldNdx - FIELD1 + 1 ) * 100;
+ ( fieldNdx - MANDATORY_FIELDS + 1 ) * 100;
// coord can compute negative if field is < FIELD1, e.g. FOOTPRINT.
// coord can compute negative if field is < MANDATORY_FIELDS, e.g. FOOTPRINT.
// That is ok, we basically don't want all the new empty fields on
// top of each other.
}
......
......@@ -67,6 +67,8 @@ class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC : public DIALOG_EDIT_COMPONENT_IN_SCHEM
void deleteFieldButtonHandler( wxCommandEvent& event );
void moveUpButtonHandler( wxCommandEvent& event );
SCH_FIELD* findField( const wxString& aFieldName );
protected:
......@@ -92,12 +94,6 @@ private:
for( unsigned ii = FIELD1; ii<m_FieldsBuf.size(); ii++ )
setRowItem( ii, m_FieldsBuf[ii] );
}
/** Function reinitializeFieldsIdAndDefaultNames
* Calculates the field id and default name, after deleting a field
* or moving a field
*/
void reinitializeFieldsIdAndDefaultNames();
};
#endif // __dialog_edit_component_in_schematic__
......@@ -5,6 +5,7 @@
#include <algorithm>
#include "fctsys.h"
#include "appl_wxstruct.h"
#include "common.h"
#include "confirm.h"
#include "class_drawpanel.h"
......@@ -20,8 +21,8 @@
// Local variables:
static int s_SelectedRow;
#define COLUMN_FIELD_NAME 0
#define COLUMN_TEXT 1
#define COLUMN_FIELD_NAME 0
#define COLUMN_TEXT 1
/*****************************************************************************************/
class DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB : public DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE
......@@ -29,8 +30,8 @@ class DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB : public DIALOG_EDIT_LIBENTRY_FIELDS_IN
{
private:
WinEDA_LibeditFrame* m_Parent;
LIB_COMPONENT* m_LibEntry;
bool m_skipCopyFromPanel;
LIB_COMPONENT* m_LibEntry;
bool m_skipCopyFromPanel;
/// a copy of the edited component's LIB_FIELDs
std::vector <LIB_FIELD> m_FieldsBuf;
......@@ -63,7 +64,14 @@ private:
* sets up to edit the given component.
* @param aComponent The component to edit.
*/
void InitBuffers( void );
void InitBuffers();
/**
* Function findField
* searches m_FieldsBuf and returns a LIB_FIELD with \a aFieldName or NULL if
* not found.
*/
LIB_FIELD* findField( const wxString& aFieldName );
/**
* Function copySelectedFieldToPanel
......@@ -81,21 +89,16 @@ private:
bool copyPanelToSelectedField();
void setRowItem( int aFieldNdx, const LIB_FIELD& aField );
/** Function updateDisplay
/**
* Function updateDisplay
* update the listbox showing fields, according to the fields texts
* must be called after a text change in fields, if this change is not an edition
*/
void updateDisplay( )
{
for( unsigned ii = FIELD1; ii<m_FieldsBuf.size(); ii++ )
for( unsigned ii = MANDATORY_FIELDS; ii<m_FieldsBuf.size(); ii++ )
setRowItem( ii, m_FieldsBuf[ii] );
}
/** Function reinitializeFieldsIdAndDefaultNames
* Calculates the field id and default name, after deleting a field
* or moving a field
*/
void reinitializeFieldsIdAndDefaultNames();
};
......@@ -223,8 +226,8 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnOKButtonClick( wxCommandEvent& event
if( newvalue->CmpNoCase( m_LibEntry->m_AliasList[i] ) == 0 )
{
wxString msg;
msg.Printf( _( "A new name is entered for this component\nAn \
alias %s already exists!\nCannot update this component" ),
msg.Printf( _( "A new name is entered for this component\n"
"An alias %s already exists!\nCannot update this component" ),
newvalue->GetData() );
DisplayError( this, msg );
return;
......@@ -234,10 +237,11 @@ alias %s already exists!\nCannot update this component" ),
/* save old cmp in undo list */
m_Parent->SaveCopyInUndoList( m_LibEntry, IS_CHANGED );
// delete any fields with no name
for( unsigned i = FIELD1; i < m_FieldsBuf.size(); )
// delete any fields with no name or no value before we copy all of m_FieldsBuf
// back into the component
for( unsigned i = MANDATORY_FIELDS; i < m_FieldsBuf.size(); )
{
if( m_FieldsBuf[i].m_Name.IsEmpty() )
if( m_FieldsBuf[i].m_Name.IsEmpty() || m_FieldsBuf[i].m_Text.IsEmpty() )
{
m_FieldsBuf.erase( m_FieldsBuf.begin() + i );
continue;
......@@ -246,7 +250,17 @@ alias %s already exists!\nCannot update this component" ),
++i;
}
// copy all the fields back, and change the length of m_Fields.
#if defined(DEBUG)
for( unsigned i=0; i<m_FieldsBuf.size(); ++i )
{
printf( "save[%d].name:'%s' value:'%s'\n", i,
CONV_TO_UTF8( m_FieldsBuf[i].m_Name ),
CONV_TO_UTF8( m_FieldsBuf[i].m_Text )
);
}
#endif
// copy all the fields back, fully replacing any previous fields
m_LibEntry->SetFields( m_FieldsBuf );
m_Parent->OnModify( );
......@@ -255,27 +269,13 @@ alias %s already exists!\nCannot update this component" ),
}
/******************************************************************************/
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::reinitializeFieldsIdAndDefaultNames( )
/*****************************************************************************/
{
for( unsigned new_id = FIELD1; new_id < m_FieldsBuf.size(); new_id++ )
{
unsigned old_id = m_FieldsBuf[new_id].m_FieldId;
if ( old_id != new_id )
{
if ( m_FieldsBuf[new_id].m_Name == ReturnDefaultFieldName( old_id ) )
m_FieldsBuf[new_id].m_Name = ReturnDefaultFieldName( new_id );
m_FieldsBuf[new_id].m_FieldId = new_id;
}
}
}
/**************************************************************************************/
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::addFieldButtonHandler( wxCommandEvent& event )
/**************************************************************************************/
{
WinEDA_SchematicFrame* frame;
frame = (WinEDA_SchematicFrame*) wxGetApp().GetTopWindow();
// in case m_FieldsBuf[REFERENCE].m_Orient has changed on screen only, grab
// screen contents.
if( !copyPanelToSelectedField() )
......@@ -286,7 +286,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::addFieldButtonHandler( wxCommandEvent&
LIB_FIELD blank( fieldNdx );
m_FieldsBuf.push_back( blank );
m_FieldsBuf[fieldNdx].m_Name = ReturnDefaultFieldName(fieldNdx);
m_FieldsBuf[fieldNdx].m_Name = TEMPLATE_FIELDNAME::GetDefaultFieldName(fieldNdx);
setRowItem( fieldNdx, m_FieldsBuf[fieldNdx] );
......@@ -300,7 +300,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::addFieldButtonHandler( wxCommandEvent&
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::deleteFieldButtonHandler( wxCommandEvent& event )
/*****************************************************************************************/
/* Delete a field.
* Fields REFERENCE and VALUE are mandatory, and cannot be deleted.
* MANDATORY_FIELDS cannot be deleted.
* If a field is empty, it is removed.
* if not empty, the text is removed.
*/
......@@ -317,6 +317,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::deleteFieldButtonHandler( wxCommandEven
}
m_skipCopyFromPanel = true;
if( m_FieldsBuf[fieldNdx].m_Text.IsEmpty() )
{
m_FieldsBuf.erase( m_FieldsBuf.begin() + fieldNdx );
......@@ -324,9 +325,6 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::deleteFieldButtonHandler( wxCommandEven
if( fieldNdx >= m_FieldsBuf.size() )
--fieldNdx;
// Reinitialize fields IDs and default names:
reinitializeFieldsIdAndDefaultNames();
}
else
{
......@@ -351,7 +349,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB:: moveUpButtonHandler( wxCommandEvent& e
if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
return;
if( fieldNdx <= FIELD1 )
if( fieldNdx <= MANDATORY_FIELDS )
{
wxBell();
return;
......@@ -370,8 +368,6 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB:: moveUpButtonHandler( wxCommandEvent& e
m_FieldsBuf[fieldNdx] = tmp;
setRowItem( fieldNdx, tmp );
// Reinitialize fields IDs and default names:
reinitializeFieldsIdAndDefaultNames();
updateDisplay( );
m_skipCopyFromPanel = true;
......@@ -407,54 +403,139 @@ int DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::getSelectedFieldNdx()
}
static bool SortFieldsById(const LIB_FIELD& item1, const LIB_FIELD& item2)
/**
* Function findfield
* searches a LIB_FIELD_LIST for aFieldName.
*/
static LIB_FIELD* findfield( const LIB_FIELD_LIST& aList, const wxString& aFieldName )
{
return item1.m_FieldId < item2.m_FieldId;
const LIB_FIELD* field = NULL;
for( unsigned i=0; i<aList.size(); ++i )
{
if( aFieldName == aList[i].m_Name )
{
field = &aList[i]; // best to avoid casting here.
break;
}
}
return (LIB_FIELD*) field; // remove const-ness last
}
LIB_FIELD* DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::findField( const wxString& aFieldName )
{
for( unsigned i=0; i<m_FieldsBuf.size(); ++i )
{
if( aFieldName == m_FieldsBuf[i].m_Name )
return &m_FieldsBuf[i];
}
return NULL;
}
/***********************************************************/
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::InitBuffers( void )
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::InitBuffers()
/***********************************************************/
{
LIB_FIELD_LIST fields;
LIB_FIELD_LIST cmpFields;
m_LibEntry->GetFields( cmpFields );
m_LibEntry->GetFields( fields );
#if defined(DEBUG)
for( unsigned i=0; i<cmpFields.size(); ++i )
{
printf( "cmpFields[%d].name:%s\n", i, CONV_TO_UTF8( cmpFields[i].m_Name ) );
}
#endif
/* We have 3 component related field lists to be aware of: 1) UI
presentation (m_FieldsBuf), 2) fields in component ram copy, and 3)
fields recorded with component on disk. m_FieldsBuf is the list of UI
fields, and this list is not the same as the list which is in the
component, which is also not the same as the list on disk. All 3 lists
are potentially different. In the UI we choose to preserve the order of
the first MANDATORY_FIELDS which are sometimes called fixed fields. Then
we append the template fieldnames in the exact same order as the
template fieldname editor shows them. Then we append any user defined
fieldnames which came from the component, and user can modify it during
editing, but cannot delete or move a fixed field.
*/
// copy all the fields to a work area
m_FieldsBuf.reserve(DEFAULT_NUMBER_OF_FIELDS);
m_FieldsBuf.clear();
// Creates a working copy of fields
for( size_t i = 0; i < fields.size(); i++ )
m_FieldsBuf.push_back( fields[i] );
/* When this code was written, all field constructors ensured that the
MANDATORY_FIELDS are all present within a component (in ram only). So we can
knowingly copy them over in the normal order. Copy only the fixed fields
at first. Please do not break the field constructors.
*/
// Display 12 fields (or more), and add missing fields
LIB_FIELD blank( 2 );
unsigned fcount = m_FieldsBuf.size();
for( unsigned ii = 2; ii < DEFAULT_NUMBER_OF_FIELDS; ii++ )
// fixed fields:
for( int i=0; i<MANDATORY_FIELDS; ++i )
{
unsigned jj;
for ( jj = 2; jj < fcount; jj ++ )
if ( m_FieldsBuf[jj].m_FieldId == (int)ii ) // Field id already exists, ok.
break;
if ( jj < fcount ) continue;
// Field id not found: add this field
blank.m_FieldId = ii;
m_FieldsBuf.push_back( blank );
D( printf( "add fixed:%s\n", CONV_TO_UTF8( cmpFields[i].m_Name ) ); )
m_FieldsBuf.push_back( cmpFields[i] );
}
m_FieldsBuf[VALUE].m_Name << wxT( "/" ) << _( "Chip Name" );
// Add template fieldnames:
// Now copy in the template fields, in the order that they are present in the
// template field editor UI.
const TEMPLATE_FIELDNAMES& tfnames =
((WinEDA_SchematicFrame*)m_Parent->GetParent())->GetTemplateFieldNames();
for( TEMPLATE_FIELDNAMES::const_iterator it = tfnames.begin(); it!=tfnames.end(); ++it )
{
// add a new field unconditionally to the UI only for this template fieldname
// field id must not be in range 0 - MANDATORY_FIELDS, set before saving to disk
LIB_FIELD fld(-1);
// See if field by same name already exists in component.
LIB_FIELD* libField = findfield( cmpFields, it->m_Name );
// Sort files by field id, because they are not entered by id
sort(m_FieldsBuf.begin(), m_FieldsBuf.end(), SortFieldsById);
// If the field does not already exist in the component, then we
// use defaults from the template fieldname, otherwise the original
// values from the component will be set.
if( !libField )
{
D( printf( "add template:%s\n", CONV_TO_UTF8( it->m_Name ) ); )
fld.m_Name = it->m_Name;
fld.m_Text = it->m_Value; // empty? ok too.
if( !it->m_Visible )
fld.m_Attributs |= TEXT_NO_VISIBLE;
else
fld.m_Attributs &= ~TEXT_NO_VISIBLE;
}
else
{
D( printf( "match template:%s\n", CONV_TO_UTF8( libField->m_Name )); )
fld = *libField; // copy values from component, m_Name too
}
m_FieldsBuf.push_back( fld );
}
// Now, all fields with Id 0 to NUMBER_OF_FIELDS-1 exist
// init default fields names
for( unsigned ii = 0; ii < m_FieldsBuf.size(); ii++ )
// Lastly, append any original fields from the component which were not added
// from the set of fixed fields nor from the set of template fields.
for( unsigned i=MANDATORY_FIELDS; i<cmpFields.size(); ++i )
{
if( m_FieldsBuf[ii].m_Name.IsEmpty() || ii < FIELD1 )
m_FieldsBuf[ii].m_Name = ReturnDefaultFieldName( ii );
LIB_FIELD* cmp = &cmpFields[i];
LIB_FIELD* buf = findField( cmp->m_Name );
if( !buf )
{
D( printf( "add cmp:%s\n", CONV_TO_UTF8( cmp->m_Name )); )
m_FieldsBuf.push_back( *cmp );
}
}
/* field names have become more important than field ids, so we cannot
mangle the names in the buffer, but can do so in the panel, see elsewhere.
m_FieldsBuf[VALUE].m_Name << wxT( "/" ) << _( "Chip Name" );
*/
for( unsigned ii = 0; ii < m_FieldsBuf.size(); ++ii )
{
setRowItem( ii, m_FieldsBuf[ii] );
......@@ -466,6 +547,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::InitBuffers( void )
// resume editing at the last row edited, last time dialog was up.
if ( s_SelectedRow < (int) m_FieldsBuf.size() )
s_SelectedRow = 0;
setSelectedFieldNdx( s_SelectedRow );
}
......@@ -513,8 +595,10 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copySelectedFieldToPanel()
int style = 0;
if( field.m_Italic )
style = 1;
if( field.m_Bold )
style |= 2;
m_StyleRadioBox->SetSelection( style );
// Copy the text justification
......@@ -532,12 +616,22 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copySelectedFieldToPanel()
else
m_FieldVJustifyCtrl->SetSelection(1);
fieldNameTextCtrl->SetValue( field.m_Name );
// Field names have become more important than field ids, so we cannot
// mangle the names in the buffer but we can do so in the panel.
if( field.m_FieldId == VALUE )
fieldNameTextCtrl->SetValue( field.m_Name + wxT( " / " ) + _( "Chip Name" ) );
else
fieldNameTextCtrl->SetValue( field.m_Name );
// if fieldNdx == REFERENCE, VALUE, FOOTPRINT, or DATASHEET, then disable field name editing
fieldNameTextCtrl->Enable( fieldNdx >= FIELD1 );
fieldNameTextCtrl->SetEditable( fieldNdx >= FIELD1 );
moveUpButton->Enable( fieldNdx >= FIELD1 ); // disable move up button for non moveable fields
fieldNameTextCtrl->Enable( fieldNdx >= MANDATORY_FIELDS );
fieldNameTextCtrl->SetEditable( fieldNdx >= MANDATORY_FIELDS );
// only user defined fields may be moved, and not the top most user defined
// field since it would be moving up into the fixed fields, > not >=
moveUpButton->Enable( fieldNdx > MANDATORY_FIELDS );
// if fieldNdx == REFERENCE, VALUE, then disable delete button
deleteFieldButton->Enable( fieldNdx > VALUE );
......@@ -557,10 +651,10 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copySelectedFieldToPanel()
{
rotateCheckBox->SetValue( m_FieldsBuf[REFERENCE].m_Orient == TEXT_ORIENT_VERT );
coord.x = m_FieldsBuf[REFERENCE].m_Pos.x + (fieldNdx - FIELD1 + 1) * 100;
coord.y = m_FieldsBuf[REFERENCE].m_Pos.y + (fieldNdx - FIELD1 + 1) * 100;
coord.x = m_FieldsBuf[REFERENCE].m_Pos.x + (fieldNdx - MANDATORY_FIELDS + 1) * 100;
coord.y = m_FieldsBuf[REFERENCE].m_Pos.y + (fieldNdx - MANDATORY_FIELDS + 1) * 100;
// coord can compute negative if field is < FIELD1, e.g. FOOTPRINT.
// coord can compute negative if field is < MANDATORY_FIELDS, e.g. FOOTPRINT.
// That is ok, we basically don't want all the new empty fields on
// top of each other.
}
......@@ -602,25 +696,31 @@ bool DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copyPanelToSelectedField()
GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_HJUSTIFY_RIGHT
};
GRTextVertJustifyType vjustify[3] = {
GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_TOP
};
field.m_HJustify = hjustify[m_FieldHJustifyCtrl->GetSelection()];
field.m_VJustify = vjustify[m_FieldVJustifyCtrl->GetSelection()];
/* Void fields texts for REFERENCE and VALUE (value is the name of the component in lib ! ) are not allowed
* change them only for a new non void value
*/
// Blank/empty field texts for REFERENCE and VALUE are not allowed.
// (Value is the name of the component in lib!)
// Change them only if user provided a non blank value
if( !fieldValueTextCtrl->GetValue().IsEmpty() || fieldNdx > VALUE )
field.m_Text = fieldValueTextCtrl->GetValue();
field.m_Name = fieldNameTextCtrl->GetValue();
// FieldNameTextCtrl has a tricked value in it for VALUE index, do not copy it back.
// It has the "Chip Name" appended.
if( field.m_FieldId >= MANDATORY_FIELDS )
field.m_Name = fieldNameTextCtrl->GetValue();
setRowItem( fieldNdx, field ); // update fieldListCtrl
field.m_Size.x = WinEDA_GraphicTextCtrl::ParseSize(
textSizeTextCtrl->GetValue(), EESCHEMA_INTERNAL_UNIT, g_UnitMetric );
field.m_Size.y = field.m_Size.x;
int style = m_StyleRadioBox->GetSelection();
......@@ -632,7 +732,7 @@ bool DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copyPanelToSelectedField()
if( (style & 2 ) != 0 )
field.m_Bold = true;
else
field.m_Bold = false;
field.m_Bold = false;
double value;
......
......@@ -40,3 +40,89 @@ void DIALOG_EESCHEMA_OPTIONS::SetGridSizes( const GridArray& grid_sizes,
m_choiceGridSize->SetSelection( select );
}
void DIALOG_EESCHEMA_OPTIONS::SetFieldName( int aNdx, wxString aName )
{
switch( aNdx )
{
case 0:
m_fieldName1->SetValue( aName );
break;
case 1:
m_fieldName2->SetValue( aName );
break;
case 2:
m_fieldName3->SetValue( aName );
break;
case 3:
m_fieldName4->SetValue( aName );
break;
case 4:
m_fieldName5->SetValue( aName );
break;
case 5:
m_fieldName6->SetValue( aName );
break;
case 6:
m_fieldName7->SetValue( aName );
break;
case 7:
m_fieldName8->SetValue( aName );
break;
default:
break;
}
}
wxString DIALOG_EESCHEMA_OPTIONS::GetFieldName( int aNdx )
{
wxString nme;
switch ( aNdx )
{
case 0:
nme = m_fieldName1->GetValue();
break;
case 1:
nme = m_fieldName2->GetValue();
break;
case 2:
nme = m_fieldName3->GetValue();
break;
case 3:
nme = m_fieldName4->GetValue();
break;
case 4:
nme = m_fieldName5->GetValue();
break;
case 5:
nme = m_fieldName6->GetValue();
break;
case 6:
nme = m_fieldName7->GetValue();
break;
case 7:
nme = m_fieldName8->GetValue();
break;
default:
break;
}
return nme;
}
......@@ -11,7 +11,7 @@
class DIALOG_EESCHEMA_OPTIONS : public DIALOG_EESCHEMA_OPTIONS_BASE
{
public:
DIALOG_EESCHEMA_OPTIONS( wxWindow* parent );
DIALOG_EESCHEMA_OPTIONS( wxWindow* parent );
void SetUnits( const wxArrayString& units, int select = 0 );
int GetUnitsSelection( void ) { return m_choiceUnits->GetSelection(); }
......@@ -91,6 +91,13 @@ public:
{
return m_checkPageLimits->GetValue();
}
/** Set the field \a aNdx textctrl to \a aName */
void SetFieldName( int aNdx, wxString aName);
/** Get the field \a aNdx name from the fields textctrl */
wxString GetFieldName( int aNdx );
};
#endif // __dialog_eeschema_options__
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Apr 16 2008)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "dialog_eeschema_options_base.h"
///////////////////////////////////////////////////////////////////////////
BEGIN_EVENT_TABLE( DIALOG_EESCHEMA_OPTIONS_BASE, wxDialog )
EVT_CHOICE( wxID_ANY, DIALOG_EESCHEMA_OPTIONS_BASE::_wxFB_OnChooseUnits )
END_EVENT_TABLE()
DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
wxBoxSizer* mainSizer;
mainSizer = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* bSizer3;
bSizer3 = new wxBoxSizer( wxVERTICAL );
wxFlexGridSizer* fgSizer1;
fgSizer1 = new wxFlexGridSizer( 7, 3, 0, 0 );
fgSizer1->AddGrowableCol( 0 );
fgSizer1->AddGrowableCol( 1 );
fgSizer1->AddGrowableCol( 2 );
fgSizer1->SetFlexibleDirection( wxHORIZONTAL );
fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_staticText2 = new wxStaticText( this, wxID_ANY, _("Mesurement &units:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText2->Wrap( -1 );
fgSizer1->Add( m_staticText2, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
wxArrayString m_choiceUnitsChoices;
m_choiceUnits = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceUnitsChoices, 0 );
m_choiceUnits->SetSelection( 0 );
fgSizer1->Add( m_choiceUnits, 1, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
fgSizer1->Add( 0, 0, 1, wxALIGN_CENTER_VERTICAL|wxEXPAND, 3 );
m_staticText3 = new wxStaticText( this, wxID_ANY, _("&Grid size:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText3->Wrap( -1 );
fgSizer1->Add( m_staticText3, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
wxArrayString m_choiceGridSizeChoices;
m_choiceGridSize = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceGridSizeChoices, 0 );
m_choiceGridSize->SetSelection( 0 );
fgSizer1->Add( m_choiceGridSize, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticGridUnits = new wxStaticText( this, wxID_ANY, _("mils"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticGridUnits->Wrap( -1 );
fgSizer1->Add( m_staticGridUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_staticText5 = new wxStaticText( this, wxID_ANY, _("Default &line width:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText5->Wrap( -1 );
fgSizer1->Add( m_staticText5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_spinLineWidth = new wxSpinCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_WRAP, 0, 100, 0 );
fgSizer1->Add( m_spinLineWidth, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticLineWidthUnits = new wxStaticText( this, wxID_ANY, _("mils"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticLineWidthUnits->Wrap( -1 );
fgSizer1->Add( m_staticLineWidthUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_staticText7 = new wxStaticText( this, wxID_ANY, _("Default text &size:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText7->Wrap( -1 );
fgSizer1->Add( m_staticText7, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_spinTextSize = new wxSpinCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_WRAP, 0, 1000, 0 );
fgSizer1->Add( m_spinTextSize, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticTextSizeUnits = new wxStaticText( this, wxID_ANY, _("mils"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextSizeUnits->Wrap( -1 );
fgSizer1->Add( m_staticTextSizeUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_staticText9 = new wxStaticText( this, wxID_ANY, _("Repeat draw item &horizontal displacement:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText9->Wrap( -1 );
fgSizer1->Add( m_staticText9, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_spinRepeatHorizontal = new wxSpinCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_WRAP, 0, 500, 0 );
fgSizer1->Add( m_spinRepeatHorizontal, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticRepeatXUnits = new wxStaticText( this, wxID_ANY, _("mils"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticRepeatXUnits->Wrap( -1 );
fgSizer1->Add( m_staticRepeatXUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_staticText12 = new wxStaticText( this, wxID_ANY, _("Repeat draw item &vertical displacement:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText12->Wrap( -1 );
fgSizer1->Add( m_staticText12, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_spinRepeatVertical = new wxSpinCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_WRAP, 0, 500, 100 );
fgSizer1->Add( m_spinRepeatVertical, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticRepeatYUnits = new wxStaticText( this, wxID_ANY, _("mils"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticRepeatYUnits->Wrap( -1 );
fgSizer1->Add( m_staticRepeatYUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_staticText16 = new wxStaticText( this, wxID_ANY, _("&Repeat label increment:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText16->Wrap( -1 );
fgSizer1->Add( m_staticText16, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_spinRepeatLabel = new wxSpinCtrl( this, wxID_ANY, wxT("1"), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_WRAP, 0, 10, 1 );
fgSizer1->Add( m_spinRepeatLabel, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
fgSizer1->Add( 0, 0, 1, wxALIGN_CENTER_VERTICAL|wxEXPAND, 3 );
bSizer3->Add( fgSizer1, 0, wxALIGN_CENTER|wxEXPAND, 0 );
wxBoxSizer* bSizer2;
bSizer2 = new wxBoxSizer( wxVERTICAL );
m_checkShowGrid = new wxCheckBox( this, wxID_ANY, _("Show g&rid"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer2->Add( m_checkShowGrid, 0, wxALL|wxEXPAND, 3 );
m_checkShowHiddenPins = new wxCheckBox( this, wxID_ANY, _("Show hi&dden pins"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer2->Add( m_checkShowHiddenPins, 0, wxALL|wxEXPAND, 3 );
m_checkAutoPan = new wxCheckBox( this, wxID_ANY, _("Enable automatic &panning"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer2->Add( m_checkAutoPan, 0, wxALL|wxEXPAND, 3 );
m_checkHVOrientation = new wxCheckBox( this, wxID_ANY, _("Allow buses and wires to be placed in H or V &orientation only"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer2->Add( m_checkHVOrientation, 0, wxALL|wxEXPAND, 3 );
m_checkPageLimits = new wxCheckBox( this, wxID_ANY, _("Show p&age limits"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer2->Add( m_checkPageLimits, 0, wxALL|wxEXPAND, 3 );
bSizer3->Add( bSizer2, 0, wxEXPAND, 0 );
bSizer3->Add( 0, 0, 1, wxALL|wxEXPAND, 10 );
m_sdbSizer1 = new wxStdDialogButtonSizer();
m_sdbSizer1OK = new wxButton( this, wxID_OK );
m_sdbSizer1->AddButton( m_sdbSizer1OK );
m_sdbSizer1Cancel = new wxButton( this, wxID_CANCEL );
m_sdbSizer1->AddButton( m_sdbSizer1Cancel );
m_sdbSizer1->Realize();
bSizer3->Add( m_sdbSizer1, 0, wxALL|wxEXPAND, 0 );
mainSizer->Add( bSizer3, 1, wxALL|wxEXPAND, 12 );
this->SetSizer( mainSizer );
this->Layout();
mainSizer->Fit( this );
this->Centre( wxBOTH );
}
DIALOG_EESCHEMA_OPTIONS_BASE::~DIALOG_EESCHEMA_OPTIONS_BASE()
{
}
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 21 2009)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "dialog_eeschema_options_base.h"
///////////////////////////////////////////////////////////////////////////
BEGIN_EVENT_TABLE( DIALOG_EESCHEMA_OPTIONS_BASE, wxDialog )
EVT_CHOICE( wxID_ANY, DIALOG_EESCHEMA_OPTIONS_BASE::_wxFB_OnChooseUnits )
END_EVENT_TABLE()
DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
wxBoxSizer* mainSizer;
mainSizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bSizer5;
bSizer5 = new wxBoxSizer( wxVERTICAL );
m_notebook1 = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
m_panel1 = new wxPanel( m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
wxBoxSizer* p1mainSizer;
p1mainSizer = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* bSizer3;
bSizer3 = new wxBoxSizer( wxVERTICAL );
wxFlexGridSizer* fgSizer1;
fgSizer1 = new wxFlexGridSizer( 7, 3, 0, 0 );
fgSizer1->AddGrowableCol( 0 );
fgSizer1->AddGrowableCol( 1 );
fgSizer1->AddGrowableCol( 2 );
fgSizer1->SetFlexibleDirection( wxHORIZONTAL );
fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_staticText2 = new wxStaticText( m_panel1, wxID_ANY, _("Measurement &units:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText2->Wrap( -1 );
fgSizer1->Add( m_staticText2, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
wxArrayString m_choiceUnitsChoices;
m_choiceUnits = new wxChoice( m_panel1, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceUnitsChoices, 0 );
m_choiceUnits->SetSelection( 0 );
fgSizer1->Add( m_choiceUnits, 1, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
fgSizer1->Add( 0, 0, 1, wxALIGN_CENTER_VERTICAL|wxEXPAND, 3 );
m_staticText3 = new wxStaticText( m_panel1, wxID_ANY, _("&Grid size:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText3->Wrap( -1 );
fgSizer1->Add( m_staticText3, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
wxArrayString m_choiceGridSizeChoices;
m_choiceGridSize = new wxChoice( m_panel1, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceGridSizeChoices, 0 );
m_choiceGridSize->SetSelection( 0 );
fgSizer1->Add( m_choiceGridSize, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticGridUnits = new wxStaticText( m_panel1, wxID_ANY, _("mils"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticGridUnits->Wrap( -1 );
fgSizer1->Add( m_staticGridUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_staticText5 = new wxStaticText( m_panel1, wxID_ANY, _("Default &line width:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText5->Wrap( -1 );
fgSizer1->Add( m_staticText5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_spinLineWidth = new wxSpinCtrl( m_panel1, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_WRAP, 0, 100, 0 );
fgSizer1->Add( m_spinLineWidth, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticLineWidthUnits = new wxStaticText( m_panel1, wxID_ANY, _("mils"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticLineWidthUnits->Wrap( -1 );
fgSizer1->Add( m_staticLineWidthUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_staticText7 = new wxStaticText( m_panel1, wxID_ANY, _("Default text &size:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText7->Wrap( -1 );
fgSizer1->Add( m_staticText7, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_spinTextSize = new wxSpinCtrl( m_panel1, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_WRAP, 0, 1000, 0 );
fgSizer1->Add( m_spinTextSize, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticTextSizeUnits = new wxStaticText( m_panel1, wxID_ANY, _("mils"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextSizeUnits->Wrap( -1 );
fgSizer1->Add( m_staticTextSizeUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_staticText9 = new wxStaticText( m_panel1, wxID_ANY, _("Repeat draw item &horizontal displacement:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText9->Wrap( -1 );
fgSizer1->Add( m_staticText9, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_spinRepeatHorizontal = new wxSpinCtrl( m_panel1, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_WRAP, 0, 500, 0 );
fgSizer1->Add( m_spinRepeatHorizontal, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticRepeatXUnits = new wxStaticText( m_panel1, wxID_ANY, _("mils"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticRepeatXUnits->Wrap( -1 );
fgSizer1->Add( m_staticRepeatXUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_staticText12 = new wxStaticText( m_panel1, wxID_ANY, _("Repeat draw item &vertical displacement:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText12->Wrap( -1 );
fgSizer1->Add( m_staticText12, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_spinRepeatVertical = new wxSpinCtrl( m_panel1, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_WRAP, 0, 500, 100 );
fgSizer1->Add( m_spinRepeatVertical, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticRepeatYUnits = new wxStaticText( m_panel1, wxID_ANY, _("mils"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticRepeatYUnits->Wrap( -1 );
fgSizer1->Add( m_staticRepeatYUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_staticText16 = new wxStaticText( m_panel1, wxID_ANY, _("&Repeat label increment:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText16->Wrap( -1 );
fgSizer1->Add( m_staticText16, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_spinRepeatLabel = new wxSpinCtrl( m_panel1, wxID_ANY, wxT("1"), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_WRAP, 0, 10, 1 );
fgSizer1->Add( m_spinRepeatLabel, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
fgSizer1->Add( 0, 0, 1, wxALIGN_CENTER_VERTICAL|wxEXPAND, 3 );
bSizer3->Add( fgSizer1, 0, wxALIGN_CENTER|wxEXPAND, 0 );
wxBoxSizer* bSizer2;
bSizer2 = new wxBoxSizer( wxVERTICAL );
m_checkShowGrid = new wxCheckBox( m_panel1, wxID_ANY, _("Show g&rid"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer2->Add( m_checkShowGrid, 0, wxALL|wxEXPAND, 3 );
m_checkShowHiddenPins = new wxCheckBox( m_panel1, wxID_ANY, _("Show hi&dden pins"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer2->Add( m_checkShowHiddenPins, 0, wxALL|wxEXPAND, 3 );
m_checkAutoPan = new wxCheckBox( m_panel1, wxID_ANY, _("Enable automatic &panning"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer2->Add( m_checkAutoPan, 0, wxALL|wxEXPAND, 3 );
m_checkHVOrientation = new wxCheckBox( m_panel1, wxID_ANY, _("Allow buses and wires to be placed in H or V &orientation only"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer2->Add( m_checkHVOrientation, 0, wxALL|wxEXPAND, 3 );
m_checkPageLimits = new wxCheckBox( m_panel1, wxID_ANY, _("Show p&age limits"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer2->Add( m_checkPageLimits, 0, wxALL|wxEXPAND, 3 );
bSizer3->Add( bSizer2, 0, wxEXPAND, 0 );
bSizer3->Add( 0, 0, 1, wxALL|wxEXPAND, 10 );
p1mainSizer->Add( bSizer3, 1, wxALL|wxEXPAND, 12 );
m_panel1->SetSizer( p1mainSizer );
m_panel1->Layout();
p1mainSizer->Fit( m_panel1 );
m_notebook1->AddPage( m_panel1, _("General Options"), true );
m_panel2 = new wxPanel( m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
m_panel2->SetToolTip( _("User defined field names for schematic components. ") );
wxBoxSizer* bSizer6;
bSizer6 = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bSizer8;
bSizer8 = new wxBoxSizer( wxVERTICAL );
m_staticText211 = new wxStaticText( m_panel2, wxID_ANY, _("Please enter fieldnames which you want presented in the component fieldname (property) editors. Names may not include (, ), or \" characters."), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText211->Wrap( 400 );
bSizer8->Add( m_staticText211, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5 );
bSizer6->Add( bSizer8, 0, wxEXPAND, 5 );
wxBoxSizer* bSizer7;
bSizer7 = new wxBoxSizer( wxVERTICAL );
wxFlexGridSizer* fgSizer2;
fgSizer2 = new wxFlexGridSizer( 2, 2, 0, 0 );
fgSizer2->AddGrowableCol( 1 );
fgSizer2->SetFlexibleDirection( wxHORIZONTAL );
fgSizer2->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_staticText15 = new wxStaticText( m_panel2, wxID_ANY, _("Custom field 1"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText15->Wrap( -1 );
fgSizer2->Add( m_staticText15, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 3 );
m_fieldName1 = new wxTextCtrl( m_panel2, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_fieldName1, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticText161 = new wxStaticText( m_panel2, wxID_ANY, _("Custom field 2"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText161->Wrap( -1 );
fgSizer2->Add( m_staticText161, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 3 );
m_fieldName2 = new wxTextCtrl( m_panel2, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_fieldName2, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticText17 = new wxStaticText( m_panel2, wxID_ANY, _("Custom field 3"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText17->Wrap( -1 );
fgSizer2->Add( m_staticText17, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 3 );
m_fieldName3 = new wxTextCtrl( m_panel2, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_fieldName3, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticText18 = new wxStaticText( m_panel2, wxID_ANY, _("Custom field 4"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText18->Wrap( -1 );
fgSizer2->Add( m_staticText18, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 3 );
m_fieldName4 = new wxTextCtrl( m_panel2, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_fieldName4, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticText19 = new wxStaticText( m_panel2, wxID_ANY, _("Custom field 5"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText19->Wrap( -1 );
fgSizer2->Add( m_staticText19, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 3 );
m_fieldName5 = new wxTextCtrl( m_panel2, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_fieldName5, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticText20 = new wxStaticText( m_panel2, wxID_ANY, _("Custom field 6"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText20->Wrap( -1 );
fgSizer2->Add( m_staticText20, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 3 );
m_fieldName6 = new wxTextCtrl( m_panel2, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_fieldName6, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticText21 = new wxStaticText( m_panel2, wxID_ANY, _("Custom field 7"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText21->Wrap( -1 );
fgSizer2->Add( m_staticText21, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 3 );
m_fieldName7 = new wxTextCtrl( m_panel2, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_fieldName7, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticText22 = new wxStaticText( m_panel2, wxID_ANY, _("Custom field 8"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText22->Wrap( -1 );
fgSizer2->Add( m_staticText22, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 3 );
m_fieldName8 = new wxTextCtrl( m_panel2, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_fieldName8, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
bSizer7->Add( fgSizer2, 1, wxALIGN_CENTER|wxEXPAND, 5 );
bSizer6->Add( bSizer7, 1, wxALL|wxEXPAND, 12 );
m_panel2->SetSizer( bSizer6 );
m_panel2->Layout();
bSizer6->Fit( m_panel2 );
m_notebook1->AddPage( m_panel2, _("Template Field Names"), false );
bSizer5->Add( m_notebook1, 1, wxEXPAND, 0 );
m_sdbSizer1 = new wxStdDialogButtonSizer();
m_sdbSizer1OK = new wxButton( this, wxID_OK );
m_sdbSizer1->AddButton( m_sdbSizer1OK );
m_sdbSizer1Cancel = new wxButton( this, wxID_CANCEL );
m_sdbSizer1->AddButton( m_sdbSizer1Cancel );
m_sdbSizer1->Realize();
bSizer5->Add( m_sdbSizer1, 0, wxALL|wxEXPAND, 12 );
mainSizer->Add( bSizer5, 1, 0, 12 );
this->SetSizer( mainSizer );
this->Layout();
mainSizer->Fit( this );
this->Centre( wxBOTH );
}
DIALOG_EESCHEMA_OPTIONS_BASE::~DIALOG_EESCHEMA_OPTIONS_BASE()
{
}
This source diff could not be displayed because it is too large. You can view the blob instead.
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Apr 16 2008)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __dialog_eeschema_options_base__
#define __dialog_eeschema_options_base__
#include <wx/intl.h>
#include <wx/string.h>
#include <wx/stattext.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/choice.h>
#include <wx/spinctrl.h>
#include <wx/sizer.h>
#include <wx/checkbox.h>
#include <wx/button.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class DIALOG_EESCHEMA_OPTIONS_BASE
///////////////////////////////////////////////////////////////////////////////
class DIALOG_EESCHEMA_OPTIONS_BASE : public wxDialog
{
DECLARE_EVENT_TABLE()
private:
// Private event handlers
void _wxFB_OnChooseUnits( wxCommandEvent& event ){ OnChooseUnits( event ); }
protected:
wxStaticText* m_staticText2;
wxChoice* m_choiceUnits;
wxStaticText* m_staticText3;
wxChoice* m_choiceGridSize;
wxStaticText* m_staticGridUnits;
wxStaticText* m_staticText5;
wxSpinCtrl* m_spinLineWidth;
wxStaticText* m_staticLineWidthUnits;
wxStaticText* m_staticText7;
wxSpinCtrl* m_spinTextSize;
wxStaticText* m_staticTextSizeUnits;
wxStaticText* m_staticText9;
wxSpinCtrl* m_spinRepeatHorizontal;
wxStaticText* m_staticRepeatXUnits;
wxStaticText* m_staticText12;
wxSpinCtrl* m_spinRepeatVertical;
wxStaticText* m_staticRepeatYUnits;
wxStaticText* m_staticText16;
wxSpinCtrl* m_spinRepeatLabel;
wxCheckBox* m_checkShowGrid;
wxCheckBox* m_checkShowHiddenPins;
wxCheckBox* m_checkAutoPan;
wxCheckBox* m_checkHVOrientation;
wxCheckBox* m_checkPageLimits;
wxStdDialogButtonSizer* m_sdbSizer1;
wxButton* m_sdbSizer1OK;
wxButton* m_sdbSizer1Cancel;
// Virtual event handlers, overide them in your derived class
virtual void OnChooseUnits( wxCommandEvent& event ){ event.Skip(); }
public:
DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Schematic Editor Options"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_EESCHEMA_OPTIONS_BASE();
};
#endif //__dialog_eeschema_options_base__
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 21 2009)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __dialog_eeschema_options_base__
#define __dialog_eeschema_options_base__
#include <wx/intl.h>
#include <wx/string.h>
#include <wx/stattext.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/choice.h>
#include <wx/spinctrl.h>
#include <wx/sizer.h>
#include <wx/checkbox.h>
#include <wx/panel.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/textctrl.h>
#include <wx/notebook.h>
#include <wx/button.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class DIALOG_EESCHEMA_OPTIONS_BASE
///////////////////////////////////////////////////////////////////////////////
class DIALOG_EESCHEMA_OPTIONS_BASE : public wxDialog
{
DECLARE_EVENT_TABLE()
private:
// Private event handlers
void _wxFB_OnChooseUnits( wxCommandEvent& event ){ OnChooseUnits( event ); }
protected:
wxNotebook* m_notebook1;
wxPanel* m_panel1;
wxStaticText* m_staticText2;
wxChoice* m_choiceUnits;
wxStaticText* m_staticText3;
wxChoice* m_choiceGridSize;
wxStaticText* m_staticGridUnits;
wxStaticText* m_staticText5;
wxSpinCtrl* m_spinLineWidth;
wxStaticText* m_staticLineWidthUnits;
wxStaticText* m_staticText7;
wxSpinCtrl* m_spinTextSize;
wxStaticText* m_staticTextSizeUnits;
wxStaticText* m_staticText9;
wxSpinCtrl* m_spinRepeatHorizontal;
wxStaticText* m_staticRepeatXUnits;
wxStaticText* m_staticText12;
wxSpinCtrl* m_spinRepeatVertical;
wxStaticText* m_staticRepeatYUnits;
wxStaticText* m_staticText16;
wxSpinCtrl* m_spinRepeatLabel;
wxCheckBox* m_checkShowGrid;
wxCheckBox* m_checkShowHiddenPins;
wxCheckBox* m_checkAutoPan;
wxCheckBox* m_checkHVOrientation;
wxCheckBox* m_checkPageLimits;
wxPanel* m_panel2;
wxStaticText* m_staticText211;
wxStaticText* m_staticText15;
wxTextCtrl* m_fieldName1;
wxStaticText* m_staticText161;
wxTextCtrl* m_fieldName2;
wxStaticText* m_staticText17;
wxTextCtrl* m_fieldName3;
wxStaticText* m_staticText18;
wxTextCtrl* m_fieldName4;
wxStaticText* m_staticText19;
wxTextCtrl* m_fieldName5;
wxStaticText* m_staticText20;
wxTextCtrl* m_fieldName6;
wxStaticText* m_staticText21;
wxTextCtrl* m_fieldName7;
wxStaticText* m_staticText22;
wxTextCtrl* m_fieldName8;
wxStdDialogButtonSizer* m_sdbSizer1;
wxButton* m_sdbSizer1OK;
wxButton* m_sdbSizer1Cancel;
// Virtual event handlers, overide them in your derived class
virtual void OnChooseUnits( wxCommandEvent& event ) { event.Skip(); }
public:
DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Schematic Editor Options"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_EESCHEMA_OPTIONS_BASE();
};
#endif //__dialog_eeschema_options_base__
......@@ -22,16 +22,16 @@
#include <wx/fdrepdlg.h>
#define HOTKEY_FILENAME wxT( "eeschema" )
#define HOTKEY_FILENAME wxT( "eeschema" )
#define FR_HISTORY_LIST_CNT 10 ///< Maximum number of find and replace strings.
#define FR_HISTORY_LIST_CNT 10 ///< Maximum number of find and replace strings.
void WinEDA_LibeditFrame::Process_Config( wxCommandEvent& event )
{
int id = event.GetId();
wxPoint pos;
wxFileName fn;
WinEDA_SchematicFrame * schFrame = (WinEDA_SchematicFrame *) GetParent();
WinEDA_SchematicFrame * schFrame = ( WinEDA_SchematicFrame * ) GetParent();
wxGetMousePosition( &pos.x, &pos.y );
......@@ -187,6 +187,7 @@ void WinEDA_SchematicFrame::OnSetOptions( wxCommandEvent& event )
wxLogDebug( wxT( "Current grid array index %d." ),
grid_list.Index( GetBaseScreen()->GetGrid() ) );
units.Add( GetUnitsLabel( INCHES ) );
units.Add( GetUnitsLabel( MILLIMETRE ) );
......@@ -206,12 +207,24 @@ void WinEDA_SchematicFrame::OnSetOptions( wxCommandEvent& event )
dlg.Fit();
dlg.SetMinSize( dlg.GetSize() );
const TEMPLATE_FIELDNAMES& tfnames = m_TemplateFieldNames.GetTemplateFieldNames();
for( unsigned i=0; i<tfnames.size(); ++i )
{
D(printf("dlg.SetFieldName(%d, '%s')\n",
i, CONV_TO_UTF8( tfnames[i].m_Name) );)
dlg.SetFieldName( i, tfnames[i].m_Name );
}
if( dlg.ShowModal() == wxID_CANCEL )
return;
g_UnitMetric = dlg.GetUnitsSelection();
GetBaseScreen()->SetGrid(
grid_list[ (size_t) dlg.GetGridSelection() ].m_Size );
g_DrawDefaultLineThickness = dlg.GetLineWidth();
g_DefaultTextLabelSize = dlg.GetTextSize();
g_RepeatStep.x = dlg.GetRepeatHorizontal();
......@@ -222,6 +235,27 @@ void WinEDA_SchematicFrame::OnSetOptions( wxCommandEvent& event )
DrawPanel->m_AutoPAN_Enable = dlg.GetEnableAutoPan();
g_HVLines = dlg.GetEnableHVBusOrientation();
g_ShowPageLimits = dlg.GetShowPageLimits();
wxString templateFieldName;
// @todo this will change when the template field editor is redone to
// look like the component field property editor, showing visibility and value also
DeleteAllTemplateFieldNames();
for( int i=0; i<8; ++i ) // no. fields in this dialog window
{
templateFieldName = dlg.GetFieldName( i );
if( !templateFieldName.IsEmpty() )
{
TEMPLATE_FIELDNAME fld( dlg.GetFieldName( i ) );
// @todo set visibility and value also from a better editor
AddTemplateFieldName( fld );
}
}
DrawPanel->Refresh( true );
}
......@@ -438,7 +472,7 @@ static const wxString FindStringEntry( wxT( "LastFindString" ) );
static const wxString ReplaceStringEntry( wxT( "LastReplaceString" ) );
static const wxString FindStringHistoryEntry( wxT( "FindStringHistoryList%d" ) );
static const wxString ReplaceStringHistoryEntry( wxT( "ReplaceStringHistoryList%d" ) );
static const wxString FieldNamesEntry( wxT( "FieldNames" ) );
/*
* Return the EESchema applications settings list.
......@@ -614,6 +648,26 @@ void WinEDA_SchematicFrame::LoadSettings()
if( !tmpHistory.IsEmpty() )
m_replaceStringHistoryList.Add( tmpHistory );
}
wxString templateFieldNames = cfg->Read( FieldNamesEntry, wxEmptyString );
if( !templateFieldNames.IsEmpty() )
{
std::string dsnTxt = CONV_TO_UTF8( templateFieldNames );
DSNLEXER lexer( dsnTxt, DSN::template_fieldnames_keywords,
DSN::template_fieldnames_keyword_count );
try
{
m_TemplateFieldNames.Parse( &lexer );
}
catch( IOError e )
{
// @todo show error msg
D(printf("templatefieldnames parsing error: '%s'\n",
CONV_TO_UTF8(e.errorText) );)
}
}
}
......@@ -660,7 +714,7 @@ void WinEDA_SchematicFrame::SaveSettings()
/* Save the find and replace string history list. */
size_t i;
wxString tmpHistory;
wxString entry;
wxString entry; // invoke constructor outside of any loops
for ( i = 0; i < m_findStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
{
......@@ -673,4 +727,17 @@ void WinEDA_SchematicFrame::SaveSettings()
entry.Printf( ReplaceStringHistoryEntry, i );
cfg->Write( entry, m_replaceStringHistoryList[ i ] );
}
// Save template fieldnames
STRINGFORMATTER sf;
m_TemplateFieldNames.Format( &sf, 0 );
wxString record = CONV_FROM_UTF8( sf.GetString().c_str() );
record.Replace( wxT("\n"), wxT(""), true ); // strip all newlines
record.Replace( wxT(" "), wxT(" "), true ); // double space to single
cfg->Write( FieldNamesEntry, record );
}
......@@ -506,7 +506,6 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
char* ptcar;
wxString fieldName;
component = new SCH_COMPONENT();
component->m_Convert = 1;
......@@ -703,7 +702,7 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
ReadDelimitedText( FieldUserName, ptcar, sizeof(FieldUserName) );
if( !FieldUserName[0] )
fieldName = ReturnDefaultFieldName( fieldNdx );
fieldName = TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldNdx );
else
fieldName = CONV_FROM_UTF8( FieldUserName );
......
#include "template_fieldnames.h"
//#include "class_sch_component.h"
#include "dsnlexer.h"
#include "macros.h"
using namespace DSN; // enum TFIELD_T is in this namespace
wxString TEMPLATE_FIELDNAME::GetDefaultFieldName( int aFieldNdx )
{
// Fixed values for the first few default fields used by EESCHEMA
static const wxString fixedNames[] = {
_( "Reference" ), // The component reference, R1, C1, etc.
_( "Value" ), // The component value + name
_( "Footprint" ), // The footprint for use with PCBNEW
_( "Datasheet" ), // Link to a datasheet for component
};
if ( (unsigned) aFieldNdx < DIM(fixedNames) )
return fixedNames[aFieldNdx];
else
{
wxString fieldName = _("Field");
fieldName << aFieldNdx;
return fieldName;
}
}
void TEMPLATE_FIELDNAME::Format( OUTPUTFORMATTER* out, int nestLevel ) const throw( IOError )
{
// user may want spaces in his field name, ug, so quote them for the parser.
out->Print( nestLevel, "(field (name \"%s\")", CONV_TO_UTF8(m_Name) );
if( !m_Value.IsEmpty() )
out->Print( 0, "(value \"%s\")", CONV_TO_UTF8(m_Value) );
if( m_Visible )
out->Print( 0, " visible" );
out->Print( 0, ")\n" );
}
void TEMPLATE_FIELDNAME::Parse( DSNLEXER* in ) throw( IOError )
{
TFIELD_T tok;
if( (tok = (TFIELD_T) in->NextTok()) != T_LEFT )
in->Expecting( T_LEFT );
if( (tok = (TFIELD_T) in->NextTok()) != T_name )
in->Expecting( T_name );
if( (tok = (TFIELD_T) in->NextTok()) != T_SYMBOL && tok!=T_STRING )
in->Expecting( _("field's name") );
m_Name = CONV_FROM_UTF8( in->CurText() );
if( (tok = (TFIELD_T) in->NextTok()) != T_RIGHT )
in->Expecting( T_RIGHT );
while( (tok = (TFIELD_T) in->NextTok() ) != T_RIGHT && tok != T_EOF )
{
if( tok == T_LEFT )
tok = (TFIELD_T) in->NextTok();
switch( tok )
{
case T_value:
if( (tok = (TFIELD_T) in->NextTok()) != T_SYMBOL && tok!=T_STRING )
in->Expecting( _("field's value") );
m_Value = CONV_FROM_UTF8( in->CurText() );
if( (tok = (TFIELD_T) in->NextTok()) != T_RIGHT )
in->Expecting( T_RIGHT );
break;
case T_visible:
m_Visible = true;
break;
default:
in->Unexpected( CONV_FROM_UTF8( in->CurText() ) );
break;
}
}
}
void TEMPLATES::Format( OUTPUTFORMATTER* out, int nestLevel ) const throw( IOError )
{
// We'll keep this general even though the only know use at this time
// will not want the newlines or the indentation.
out->Print( nestLevel, "(templatefields" );
for( unsigned i=0; i<m_Fields.size(); ++i )
m_Fields[i].Format( out, nestLevel+1 );
out->Print( 0, ")\n" );
}
void TEMPLATES::Parse( DSNLEXER* in ) throw( IOError )
{
TFIELD_T tok;
while( (tok = (TFIELD_T) in->NextTok() ) != T_RIGHT && tok != T_EOF )
{
if( tok == T_LEFT )
tok = (TFIELD_T) in->NextTok();
switch( tok )
{
case T_templatefields: // a token indicating class TEMPLATES.
// Be flexible regarding the starting point of the DSNLEXER
// stream. Caller may not have read the first two tokens out of the
// stream: T_LEFT and T_templatefields, so ignore them if seen here.
break;
case T_field:
{
// instantiate on stack, so if exception is thrown,
// destructor runs
TEMPLATE_FIELDNAME field;
field.Parse( in );
// add the field
AddTemplateFieldName( field );
}
break;
default:
in->Unexpected( CONV_FROM_UTF8( in->CurText() ) );
break;
}
}
D(printf("tok:%d\n", tok);)
}
int TEMPLATES::AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName )
{
// Ensure that the template fieldname does not match a fixed fieldname.
for( int i=0; i<MANDATORY_FIELDS; ++i )
{
if( TEMPLATE_FIELDNAME::GetDefaultFieldName(i) == aFieldName.m_Name )
{
return -1;
}
}
// ensure uniqueness, overwrite any template fieldname by the same name.
for( unsigned i=0; i<m_Fields.size(); ++i )
{
if( m_Fields[i].m_Name == aFieldName.m_Name )
{
D(printf("inserting template fieldname:'%s' at %d\n",
CONV_TO_UTF8(aFieldName.m_Name), i );)
m_Fields[i] = aFieldName;
return i; // return the container index
}
}
// D(printf("appending template fieldname:'%s'\n", CONV_TO_UTF8(aFieldName.m_Name) );)
// the name is legal and not previously added to the config container, append
// it and return its index within the container.
m_Fields.push_back( aFieldName );
return m_Fields.size() - 1; // return the index of insertion.
}
#ifndef _TEMPLATE_FIELDNAME_H_
#define _TEMPLATE_FIELDNAME_H_
#include "richio.h"
#include "wxstruct.h"
#include "macros.h"
#include "template_fieldnames_keywords.h"
class DSNLEXER;
/**
* Enum NumFieldType
* is the set of all field indices assuming an array like sequence that a
* SCH_COMPONENT or LIB_COMPONENT can hold.
* The first fields are called fixed fields and the quantity of them is
* given by MANDATORY_FIELDS. After that come an unlimited number of
* user defined fields, only some of which have indices defined here.
*/
enum NumFieldType {
REFERENCE = 0, ///< Field Reference of part, i.e. "IC21"
VALUE, ///< Field Value of part, i.e. "3.3K"
FOOTPRINT, ///< Field Name Module PCB, i.e. "16DIP300"
DATASHEET, ///< name of datasheet
MANDATORY_FIELDS, ///< the first 4 are mandatory or fixed, and instantiated in FIELD constructors
FIELD1 = MANDATORY_FIELDS,
FIELD2,
FIELD3,
FIELD4,
FIELD5,
FIELD6,
FIELD7,
FIELD8,
};
/**
* Struct TEMPLATE_FIELDNAME
* holds a name of a component's field, field value, and default visibility.
* Template fieldnames are wanted fieldnames for use in the symbol/component
* property editors.
*/
struct TEMPLATE_FIELDNAME
{
wxString m_Name; ///< The field name
wxString m_Value; ///< The default value or empty
bool m_Visible; ///< If first appearance of the field's editor has as visible.
TEMPLATE_FIELDNAME() :
m_Visible( false )
{
}
TEMPLATE_FIELDNAME( const wxString& aName ) :
m_Name( aName ),
m_Visible( false )
{
}
/**
* Function Format
* serializes this object out as text into the given OUTPUTFORMATTER.
*/
void Format( OUTPUTFORMATTER* out, int nestLevel ) const throw( IOError );
/**
* Function Parse
* fills this object from information in the input stream \a aSpec, which
* is a DSNLEXER. 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 ^ (....) )
*
* @param aSpec is the input token stream of keywords and symbols.
*/
void Parse( DSNLEXER* aSpec ) throw( IOError );
/**
* Function GetDefaultFieldName
* returns a default symbol field name for field \a aFieldNdx for all components.
* These fieldnames are not modifiable, but template fieldnames are.
* @param aFieldNdx The field number index, > 0
*/
static wxString GetDefaultFieldName( int aFieldNdx );
};
typedef std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES;
class TEMPLATES
{
private:
TEMPLATE_FIELDNAMES m_Fields;
public:
/**
* Function Format
* serializes this object out as text into the given OUTPUTFORMATTER.
*/
void Format( OUTPUTFORMATTER* out, int nestLevel ) const throw( IOError );
/**
* Function Parse
* fills this object from information in the input stream handled by DSNLEXER
*/
void Parse( DSNLEXER* in ) throw( IOError );
/**
* Function AddTemplateFieldName
* inserts or appends a wanted symbol field name into the fieldnames
* template. Should be used for any symbol property editor. If the name
* already exists, it overwrites the same name.
*
* @param aFieldName is a full description of the wanted field, and it must not match
* any of the default fieldnames.
* @return int - the index within the config container at which aFieldName was
* added, or -1 if the name is illegal because it matches a default fieldname.
*/
int AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName );
/**
* Function DeleteAllTemplateFieldNames
* deletes the entire contents.
*/
void DeleteAllTemplateFieldNames()
{
m_Fields.clear();
}
/**
* Function GetTemplateFieldName
* returns a template fieldnames list for read only access.
*/
const TEMPLATE_FIELDNAMES& GetTemplateFieldNames()
{
return m_Fields;
}
};
#endif // _TEMPLATE_FIELDNAME_H_
field
name
templatefields
value
visible
......@@ -230,13 +230,53 @@ public:
void ThrowIOError( wxString aText, int charOffset ) throw (IOError);
/**
* Function GetTokenString
* Function Expecting
* throws an IOError exception with an input file specific error message.
* @param aTok is the token/keyword type which was expected at the current input location.
* @throw IOError with the location within the input file of the problem.
*/
void Expecting( int aTok ) throw( IOError );
/**
* Function Expecting
* throws an IOError exception with an input file specific error message.
* @param aErrorMsg is the token/keyword type which was expected at the
* current input location.
* @throw IOError with the location within the input file of the problem.
*/
void Expecting( const wxString& aErrorMsg ) throw( IOError );
/**
* Function Unexpected
* throws an IOError exception with an input file specific error message.
* @param aTok is the token/keyword type which was not expected at the
* current input location.
* @throw IOError with the location within the input file of the problem.
*/
void Unexpected( int aTok ) throw( IOError );
/**
* Function Unexpected
* throws an IOError exception with an input file specific error message.
* @param aErrorMsg is the token/keyword type which was not expected at the
* current input location.
* @throw IOError with the location within the input file of the problem.
*/
void Unexpected( const wxString& aErrorMsg ) throw( IOError );
/**
* Function GetTokenText
* returns the C string representation of a DSN_T value.
*/
const char* GetTokenText( int aTok );
static const char* Syntax( int aTok );
/**
* Function GetTokenString
* returns a quote wrapped wxString representation of a token value.
*/
wxString GetTokenString( int aTok );
static const char* Syntax( int aTok );
/**
* Function CurText
......
......@@ -11,8 +11,8 @@
#include <boost/ptr_container/ptr_vector.hpp>
/* definifition des types de parametre des files de configuration */
enum paramcfg_id /* type du parametre dans la structure ParamConfig */
/** Type of parameter in the configuration file */
enum paramcfg_id
{
PARAM_INT,
PARAM_SETCOLOR,
......@@ -20,7 +20,8 @@ enum paramcfg_id /* type du parametre dans la structure ParamConfig */
PARAM_BOOL,
PARAM_LIBNAME_LIST,
PARAM_WXSTRING,
PARAM_COMMAND_ERASE
PARAM_COMMAND_ERASE,
PARAM_FIELDNAME_LIST,
};
#define MAX_COLOR 0x8001F
......@@ -29,36 +30,50 @@ enum paramcfg_id /* type du parametre dans la structure ParamConfig */
#define INT_MINVAL 0x80000000
#define INT_MAXVAL 0x7FFFFFFF
/**
* Class PARAM_CFG_BASE
* is a base class which establishes the virtual functions ReadParam and SaveParam,
* which are re-implemented by a number of base classes, and these function's
* doxygen comments are inherited also.
*/
class PARAM_CFG_BASE
{
public:
const wxChar* m_Ident; /* Keyword in config data */
paramcfg_id m_Type; /* Type of parameter */
const wxChar* m_Group; /* Group name (tjis is like a path in the config data) */
bool m_Setup; /* TRUE -> setup parameter (used for all projects), FALSE = parameter relative to a project */
const wxChar* m_Ident; ///< Keyword in config data
paramcfg_id m_Type; ///< Type of parameter
const wxChar* m_Group; ///< Group name (this is like a path in the config data)
bool m_Setup; ///< Install or Project based parameter, true == install
public:
PARAM_CFG_BASE( const wxChar* ident, const paramcfg_id type, const wxChar* group = NULL );
/** ReadParam
* read the value of parameter thi stored in aConfig
* @param aConfig = the wxConfigBase that store the parameter
/**
* Function ReadParam
* reads the value of the parameter stored in aConfig
* @param aConfig = the wxConfigBase that holds the parameter
*/
virtual void ReadParam( wxConfigBase* aConfig ) {};
/** SaveParam
* the the value of parameter thi stored in aConfig
/**
* Function SaveParam
* saves the value of the parameter stored in aConfig
* @param aConfig = the wxConfigBase that can store the parameter
*/
virtual void SaveParam( wxConfigBase* aConfig ) {};
};
/**
* Configuration parameter - Integer Class
*
*/
class PARAM_CFG_INT : public PARAM_CFG_BASE
{
public:
int* m_Pt_param; /* pointeur sur le parametre a configurer */
int m_Min, m_Max; /* valeurs extremes du parametre */
int m_Default; /* valeur par defaut */
int* m_Pt_param; ///< Pointer to the parameter value
int m_Min, m_Max; ///< Minimum and maximum values of the param type
int m_Default; ///< The default value of the parameter
public:
PARAM_CFG_INT( const wxChar* ident, int* ptparam,
......@@ -68,24 +83,20 @@ public:
int default_val = 0, int min = INT_MINVAL, int max = INT_MAXVAL,
const wxChar* group = NULL );
/** ReadParam
* read the value of parameter thi stored in aConfig
* @param aConfig = the wxConfigBase that store the parameter
*/
virtual void ReadParam( wxConfigBase* aConfig );
/** SaveParam
* the the value of parameter thi stored in aConfig
* @param aConfig = the wxConfigBase that can store the parameter
*/
virtual void SaveParam( wxConfigBase* aConfig );
};
/**
* Configuration parameter - SetColor Class
*
*/
class PARAM_CFG_SETCOLOR : public PARAM_CFG_BASE
{
public:
int* m_Pt_param; /* pointeur sur le parametre a configurer */
int m_Default; /* valeur par defaut */
int* m_Pt_param; ///< Pointer to the parameter value
int m_Default; ///< The default value of the parameter
public:
PARAM_CFG_SETCOLOR( const wxChar* ident, int* ptparam,
......@@ -93,25 +104,21 @@ public:
PARAM_CFG_SETCOLOR( bool Insetup, const wxChar* ident, int* ptparam,
int default_val, const wxChar* group = NULL );
/** ReadParam
* read the value of parameter thi stored in aConfig
* @param aConfig = the wxConfigBase that store the parameter
*/
virtual void ReadParam( wxConfigBase* aConfig );
/** SaveParam
* the the value of parameter thi stored in aConfig
* @param aConfig = the wxConfigBase that can store the parameter
*/
virtual void SaveParam( wxConfigBase* aConfig );
};
/**
* Configuration parameter - Double Precision Class
*
*/
class PARAM_CFG_DOUBLE : public PARAM_CFG_BASE
{
public:
double* m_Pt_param; /* pointeur sur le parametre a configurer */
double m_Default; /* valeur par defaut */
double m_Min, m_Max; /* valeurs extremes du parametre */
double* m_Pt_param; ///< Pointer to the parameter value
double m_Default; ///< The default value of the parameter
double m_Min, m_Max; ///< Minimum and maximum values of the param type
public:
PARAM_CFG_DOUBLE( const wxChar* ident, double* ptparam,
......@@ -121,24 +128,20 @@ public:
double default_val = 0.0, double min = 0.0, double max = 10000.0,
const wxChar* group = NULL );
/** ReadParam
* read the value of parameter thi stored in aConfig
* @param aConfig = the wxConfigBase that store the parameter
*/
virtual void ReadParam( wxConfigBase* aConfig );
/** SaveParam
* the the value of parameter thi stored in aConfig
* @param aConfig = the wxConfigBase that can store the parameter
*/
virtual void SaveParam( wxConfigBase* aConfig );
};
/**
* Configuration parameter - Boolean Class
*
*/
class PARAM_CFG_BOOL : public PARAM_CFG_BASE
{
public:
bool* m_Pt_param; /* pointeur sur le parametre a configurer */
int m_Default; /* valeur par defaut */
bool* m_Pt_param; ///< Pointer to the parameter value
int m_Default; ///< The default value of the parameter
public:
PARAM_CFG_BOOL( const wxChar* ident, bool* ptparam,
......@@ -146,24 +149,19 @@ public:
PARAM_CFG_BOOL( bool Insetup, const wxChar* ident, bool* ptparam,
int default_val = FALSE, const wxChar* group = NULL );
/** ReadParam
* read the value of parameter thi stored in aConfig
* @param aConfig = the wxConfigBase that store the parameter
*/
virtual void ReadParam( wxConfigBase* aConfig );
/** SaveParam
* the the value of parameter thi stored in aConfig
* @param aConfig = the wxConfigBase that can store the parameter
*/
virtual void SaveParam( wxConfigBase* aConfig );
};
/**
* Configuration parameter - wxString Class
*
*/
class PARAM_CFG_WXSTRING : public PARAM_CFG_BASE
{
public:
wxString* m_Pt_param; /* pointeur sur le parametre a configurer */
wxString* m_Pt_param; ///< Pointer to the parameter value
public:
PARAM_CFG_WXSTRING( const wxChar* ident, wxString* ptparam, const wxChar* group = NULL );
......@@ -171,42 +169,28 @@ public:
const wxChar* ident,
wxString* ptparam,
const wxChar* group = NULL );
/** ReadParam
* read the value of parameter thi stored in aConfig
* @param aConfig = the wxConfigBase that store the parameter
*/
virtual void ReadParam( wxConfigBase* aConfig );
/** SaveParam
* the the value of parameter thi stored in aConfig
* @param aConfig = the wxConfigBase that can store the parameter
*/
virtual void ReadParam( wxConfigBase* aConfig );
virtual void SaveParam( wxConfigBase* aConfig );
};
class PARAM_CFG_LIBNAME_LIST : public PARAM_CFG_BASE
{
public:
wxArrayString* m_Pt_param; /* pointeur sur le parametre a configurer */
wxArrayString* m_Pt_param; ///< Pointer to the parameter value
public:
PARAM_CFG_LIBNAME_LIST( const wxChar* ident,
wxArrayString* ptparam,
const wxChar* group = NULL );
/** ReadParam
* read the value of parameter thi stored in aConfig
* @param aConfig = the wxConfigBase that store the parameter
*/
virtual void ReadParam( wxConfigBase* aConfig );
/** SaveParam
* the the value of parameter thi stored in aConfig
* @param aConfig = the wxConfigBase that can store the parameter
*/
virtual void SaveParam( wxConfigBase* aConfig );
};
/** A list of parameters type */
typedef boost::ptr_vector< PARAM_CFG_BASE > PARAM_CFG_ARRAY;
#endif /* __PARAM_CONFIG_H__ */
......@@ -8,6 +8,7 @@
#include "wxstruct.h"
#include "param_config.h"
#include "class_undoredo_container.h"
#include "template_fieldnames.h"
class WinEDA_LibeditFrame;
......@@ -51,6 +52,7 @@ enum fl_rot_cmp
CMP_MIRROR_Y = 0x200 // Mirror around Y axis
};
/**
* Schematic editor (EESchema) main window.
*/
......@@ -68,6 +70,8 @@ public:
wxString m_UserLibraryPath;
wxArrayString m_ComponentLibFiles;
protected:
TEMPLATES m_TemplateFieldNames;
private:
wxString m_DefaultSchematicFileName;
......@@ -108,6 +112,49 @@ public:
void SaveProjectFile( wxWindow* displayframe, bool askoverwrite = true );
bool LoadProjectFile( const wxString& CfgFileName, bool ForceRereadConfig );
/**
* Function GetDefaultFieldName
* returns a default symbol field name for field \a aFieldNdx for all components.
* These fieldnames are not modifiable, but template fieldnames are.
* @param aFieldNdx The field number index
*/
static wxString GetDefaultFieldName( int aFieldNdx );
/**
* Function AddTemplateFieldName
* inserts or appends a wanted symbol field name into the fieldnames
* template. Should be used for any symbol property editor. If the name
* already exists, it overwrites the same name.
*
* @param aFieldName is a full description of the wanted field, and it must not match
* any of the default fieldnames.
* @return int - the index within the config container at which aFieldName was
* added, or -1 if the name is illegal because it matches a default fieldname.
*/
int AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName )
{
return m_TemplateFieldNames.AddTemplateFieldName( aFieldName );
}
/**
* Function GetTemplateFieldName
* returns a template fieldnames list for read only access.
*/
const TEMPLATE_FIELDNAMES& GetTemplateFieldNames()
{
return m_TemplateFieldNames.GetTemplateFieldNames();
}
/**
* Function DeleteAllTemplateFieldNames
* removes all template fieldnames.
*/
void DeleteAllTemplateFieldNames()
{
m_TemplateFieldNames.DeleteAllTemplateFieldNames();
}
PARAM_CFG_ARRAY& GetConfigurationSettings( void );
void LoadSettings();
void SaveSettings();
......
......@@ -549,30 +549,24 @@ void SPECCTRA_DB::ThrowIOError( const wxChar* fmt, ... ) throw( IOError )
void SPECCTRA_DB::expecting( DSN_T aTok ) throw( IOError )
{
wxString errText( _("Expecting") );
errText << wxT(" ") << GetTokenString( aTok );
lexer->ThrowIOError( errText, lexer->CurOffset() );
lexer->Expecting( aTok );
}
void SPECCTRA_DB::expecting( const char* text ) throw( IOError )
{
wxString errText( _("Expecting") );
errText << wxT(" '") << CONV_FROM_UTF8(text) << wxT("'");
lexer->ThrowIOError( errText, lexer->CurOffset() );
wxString errText = CONV_FROM_UTF8( text );
lexer->Expecting( errText );
}
void SPECCTRA_DB::unexpected( DSN_T aTok ) throw( IOError )
{
wxString errText( _("Unexpected") );
errText << wxT(" ") << GetTokenString( aTok );
lexer->ThrowIOError( errText, lexer->CurOffset() );
lexer->Expecting( aTok );
}
void SPECCTRA_DB::unexpected( const char* text ) throw( IOError )
{
wxString errText( _("Unexpected") );
errText << wxT(" '") << CONV_FROM_UTF8(text) << wxT("'");
lexer->ThrowIOError( errText, lexer->CurOffset() );
wxString errText = CONV_FROM_UTF8( text );
lexer->Unexpected( errText );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment