2016-07-06 09:22:56 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 CERN
|
2020-02-20 12:11:04 +00:00
|
|
|
* Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-07-06 09:22:56 +00:00
|
|
|
*
|
|
|
|
* @author Wayne Stambaugh <stambaughw@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
#include <algorithm>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <boost/algorithm/string/join.hpp>
|
2019-12-05 14:03:15 +00:00
|
|
|
#include <cctype>
|
2020-01-28 15:42:42 +00:00
|
|
|
#include <set>
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
#include <wx/mstream.h>
|
|
|
|
#include <wx/filename.h>
|
2016-07-11 19:48:46 +00:00
|
|
|
#include <wx/tokenzr.h>
|
2020-01-28 15:42:42 +00:00
|
|
|
|
2018-09-17 17:00:19 +00:00
|
|
|
#include <pgm_base.h>
|
2019-05-31 12:15:25 +00:00
|
|
|
#include <gr_text.h>
|
2016-07-11 19:48:46 +00:00
|
|
|
#include <kiway.h>
|
|
|
|
#include <kicad_string.h>
|
2016-07-06 09:22:56 +00:00
|
|
|
#include <richio.h>
|
|
|
|
#include <core/typeinfo.h>
|
2017-01-27 15:56:36 +00:00
|
|
|
#include <properties.h>
|
2018-04-13 13:58:25 +00:00
|
|
|
#include <trace_helpers.h>
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
#include <general.h>
|
2017-12-01 16:49:19 +00:00
|
|
|
#include <sch_bitmap.h>
|
2016-07-06 09:22:56 +00:00
|
|
|
#include <sch_bus_entry.h>
|
2017-12-01 16:49:19 +00:00
|
|
|
#include <sch_component.h>
|
2016-07-06 09:22:56 +00:00
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_line.h>
|
2017-12-01 16:49:19 +00:00
|
|
|
#include <sch_marker.h>
|
2016-07-06 09:22:56 +00:00
|
|
|
#include <sch_no_connect.h>
|
|
|
|
#include <sch_text.h>
|
|
|
|
#include <sch_sheet.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <sch_bitmap.h>
|
|
|
|
#include <bus_alias.h>
|
2016-07-06 09:22:56 +00:00
|
|
|
#include <sch_legacy_plugin.h>
|
|
|
|
#include <template_fieldnames.h>
|
2018-01-30 08:56:43 +00:00
|
|
|
#include <sch_screen.h>
|
2016-08-18 23:23:10 +00:00
|
|
|
#include <class_libentry.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <lib_arc.h>
|
|
|
|
#include <lib_bezier.h>
|
|
|
|
#include <lib_circle.h>
|
2017-12-01 16:49:19 +00:00
|
|
|
#include <lib_field.h>
|
2016-08-18 23:23:10 +00:00
|
|
|
#include <lib_pin.h>
|
|
|
|
#include <lib_polyline.h>
|
|
|
|
#include <lib_rectangle.h>
|
|
|
|
#include <lib_text.h>
|
2017-09-02 18:12:50 +00:00
|
|
|
#include <eeschema_id.h> // for MAX_UNIT_COUNT_PER_PACKAGE definition
|
|
|
|
#include <symbol_lib_table.h> // for PropPowerSymsOnly definintion.
|
2018-09-17 17:00:19 +00:00
|
|
|
#include <confirm.h>
|
2019-04-28 16:36:31 +00:00
|
|
|
#include <tool/selection.h>
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
#define Mils2Iu( x ) Mils2iu( x )
|
|
|
|
|
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
// Must be the first line of part library document (.dcm) files.
|
|
|
|
#define DOCFILE_IDENT "EESchema-DOCLIB Version 2.0"
|
|
|
|
|
2016-07-07 13:09:32 +00:00
|
|
|
#define SCH_PARSE_ERROR( text, reader, pos ) \
|
|
|
|
THROW_PARSE_ERROR( text, reader.GetSource(), reader.Line(), \
|
2016-07-06 09:22:56 +00:00
|
|
|
reader.LineNumber(), pos - reader.Line() )
|
|
|
|
|
|
|
|
|
|
|
|
// Token delimiters.
|
|
|
|
const char* delims = " \t\r\n";
|
|
|
|
|
2017-11-15 13:08:27 +00:00
|
|
|
// Tokens to read/save graphic lines style
|
|
|
|
#define T_STYLE "style"
|
|
|
|
#define T_COLOR "rgb" // cannot be modifed (used by wxWidgets)
|
|
|
|
#define T_COLORA "rgba" // cannot be modifed (used by wxWidgets)
|
|
|
|
#define T_WIDTH "width"
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2016-09-30 14:01:05 +00:00
|
|
|
static bool is_eol( char c )
|
|
|
|
{
|
|
|
|
// The default file eol character used internally by KiCad.
|
|
|
|
// |
|
|
|
|
// | Possible eol if someone edited the file by hand on certain platforms.
|
|
|
|
// | |
|
|
|
|
// | | May have gone past eol with strtok().
|
|
|
|
// | | |
|
|
|
|
if( c == '\n' || c == '\r' || c == 0 )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
/**
|
2017-12-01 16:49:19 +00:00
|
|
|
* Compare \a aString to the string starting at \a aLine and advances the character point to
|
2016-07-06 09:22:56 +00:00
|
|
|
* the end of \a String and returns the new pointer position in \a aOutput if it is not NULL.
|
|
|
|
*
|
|
|
|
* @param aString - A pointer to the string to compare.
|
|
|
|
* @param aLine - A pointer to string to begin the comparison.
|
|
|
|
* @param aOutput - A pointer to a string pointer to the end of the comparison if not NULL.
|
2017-11-15 13:08:27 +00:00
|
|
|
* @return true if \a aString was found starting at \a aLine. Otherwise false.
|
2016-07-06 09:22:56 +00:00
|
|
|
*/
|
|
|
|
static bool strCompare( const char* aString, const char* aLine, const char** aOutput = NULL )
|
|
|
|
{
|
|
|
|
size_t len = strlen( aString );
|
2016-11-02 18:47:38 +00:00
|
|
|
bool retv = ( strncasecmp( aLine, aString, len ) == 0 ) &&
|
|
|
|
( isspace( aLine[ len ] ) || aLine[ len ] == 0 );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
if( retv && aOutput )
|
|
|
|
{
|
|
|
|
const char* tmp = aLine;
|
|
|
|
|
|
|
|
// Move past the end of the token.
|
|
|
|
tmp += len;
|
|
|
|
|
|
|
|
// Move to the beginning of the next token.
|
|
|
|
while( *tmp && isspace( *tmp ) )
|
|
|
|
tmp++;
|
|
|
|
|
|
|
|
*aOutput = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-01 16:49:19 +00:00
|
|
|
* Parse an ASCII integer string with possible leading whitespace into
|
2016-07-06 09:22:56 +00:00
|
|
|
* an integer and updates the pointer at \a aOutput if it is not NULL, just
|
|
|
|
* like "man strtol()".
|
|
|
|
*
|
|
|
|
* @param aReader - The line reader used to generate exception throw information.
|
|
|
|
* @param aLine - A pointer the current position in a string.
|
|
|
|
* @param aOutput - The pointer to a string pointer to copy the string pointer position when
|
|
|
|
* the parsing is complete.
|
|
|
|
* @return A valid integer value.
|
2017-12-01 16:49:19 +00:00
|
|
|
* @throw An #IO_ERROR on an unexpected end of line.
|
|
|
|
* @throw A #PARSE_ERROR if the parsed token is not a valid integer.
|
2016-07-06 09:22:56 +00:00
|
|
|
*/
|
2019-03-14 18:57:16 +00:00
|
|
|
static int parseInt( LINE_READER& aReader, const char* aLine, const char** aOutput = NULL )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
if( !*aLine )
|
2016-08-18 23:23:10 +00:00
|
|
|
SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, aLine );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
// Clear errno before calling strtol() in case some other crt call set it.
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
long retv = strtol( aLine, (char**) aOutput, 10 );
|
|
|
|
|
|
|
|
// Make sure no error occurred when calling strtol().
|
|
|
|
if( errno == ERANGE )
|
|
|
|
SCH_PARSE_ERROR( "invalid integer value", aReader, aLine );
|
|
|
|
|
|
|
|
// strtol does not strip off whitespace before the next token.
|
|
|
|
if( aOutput )
|
|
|
|
{
|
|
|
|
const char* next = *aOutput;
|
|
|
|
|
|
|
|
while( *next && isspace( *next ) )
|
|
|
|
next++;
|
|
|
|
|
|
|
|
*aOutput = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (int) retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-01 16:49:19 +00:00
|
|
|
* Parse an ASCII hex integer string with possible leading whitespace into
|
2016-07-06 09:22:56 +00:00
|
|
|
* a long integer and updates the pointer at \a aOutput if it is not NULL, just
|
2019-03-25 13:03:23 +00:00
|
|
|
* like "man strtoll".
|
2016-07-06 09:22:56 +00:00
|
|
|
*
|
|
|
|
* @param aReader - The line reader used to generate exception throw information.
|
|
|
|
* @param aLine - A pointer the current position in a string.
|
|
|
|
* @param aOutput - The pointer to a string pointer to copy the string pointer position when
|
|
|
|
* the parsing is complete.
|
2019-03-25 13:03:23 +00:00
|
|
|
* @return A valid uint32_t value.
|
2017-12-01 16:49:19 +00:00
|
|
|
* @throw IO_ERROR on an unexpected end of line.
|
|
|
|
* @throw PARSE_ERROR if the parsed token is not a valid integer.
|
2016-07-06 09:22:56 +00:00
|
|
|
*/
|
2020-02-20 12:11:04 +00:00
|
|
|
static uint32_t parseHex( LINE_READER& aReader, const char* aLine, const char** aOutput = NULL )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
if( !*aLine )
|
2016-08-18 23:23:10 +00:00
|
|
|
SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, aLine );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2019-03-25 13:03:23 +00:00
|
|
|
// Due to some issues between some files created by a 64 bits version and those
|
|
|
|
// created by a 32 bits version, we use here a temporary at least 64 bits storage:
|
|
|
|
unsigned long long retv;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2019-03-25 13:03:23 +00:00
|
|
|
// Clear errno before calling strtoull() in case some other crt call set it.
|
2016-07-06 09:22:56 +00:00
|
|
|
errno = 0;
|
2019-03-25 13:03:23 +00:00
|
|
|
retv = strtoull( aLine, (char**) aOutput, 16 );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2019-03-25 13:03:23 +00:00
|
|
|
// Make sure no error occurred when calling strtoull().
|
2016-07-06 09:22:56 +00:00
|
|
|
if( errno == ERANGE )
|
|
|
|
SCH_PARSE_ERROR( "invalid hexadecimal number", aReader, aLine );
|
|
|
|
|
|
|
|
// Strip off whitespace before the next token.
|
|
|
|
if( aOutput )
|
|
|
|
{
|
|
|
|
const char* next = *aOutput;
|
|
|
|
|
|
|
|
while( *next && isspace( *next ) )
|
|
|
|
next++;
|
|
|
|
|
|
|
|
*aOutput = next;
|
|
|
|
}
|
|
|
|
|
2019-03-25 13:03:23 +00:00
|
|
|
return (uint32_t)retv;
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-01 16:49:19 +00:00
|
|
|
* Parses an ASCII point string with possible leading whitespace into a double precision
|
2016-07-06 09:22:56 +00:00
|
|
|
* floating point number and updates the pointer at \a aOutput if it is not NULL, just
|
|
|
|
* like "man strtod".
|
|
|
|
*
|
|
|
|
* @param aReader - The line reader used to generate exception throw information.
|
|
|
|
* @param aLine - A pointer the current position in a string.
|
|
|
|
* @param aOutput - The pointer to a string pointer to copy the string pointer position when
|
|
|
|
* the parsing is complete.
|
|
|
|
* @return A valid double value.
|
2017-12-01 16:49:19 +00:00
|
|
|
* @throw IO_ERROR on an unexpected end of line.
|
|
|
|
* @throw PARSE_ERROR if the parsed token is not a valid integer.
|
2016-07-06 09:22:56 +00:00
|
|
|
*/
|
2019-03-14 18:57:16 +00:00
|
|
|
static double parseDouble( LINE_READER& aReader, const char* aLine,
|
2016-07-06 09:22:56 +00:00
|
|
|
const char** aOutput = NULL )
|
|
|
|
{
|
|
|
|
if( !*aLine )
|
2016-08-18 23:23:10 +00:00
|
|
|
SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, aLine );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
// Clear errno before calling strtod() in case some other crt call set it.
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
double retv = strtod( aLine, (char**) aOutput );
|
|
|
|
|
|
|
|
// Make sure no error occurred when calling strtod().
|
|
|
|
if( errno == ERANGE )
|
|
|
|
SCH_PARSE_ERROR( "invalid floating point number", aReader, aLine );
|
|
|
|
|
|
|
|
// strtod does not strip off whitespace before the next token.
|
|
|
|
if( aOutput )
|
|
|
|
{
|
|
|
|
const char* next = *aOutput;
|
|
|
|
|
|
|
|
while( *next && isspace( *next ) )
|
|
|
|
next++;
|
|
|
|
|
|
|
|
*aOutput = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-01 16:49:19 +00:00
|
|
|
* Parse a single ASCII character and updates the pointer at \a aOutput if it is not NULL.
|
2016-07-06 09:22:56 +00:00
|
|
|
*
|
|
|
|
* @param aReader - The line reader used to generate exception throw information.
|
|
|
|
* @param aCurrentToken - A pointer the current position in a string.
|
|
|
|
* @param aNextToken - The pointer to a string pointer to copy the string pointer position when
|
|
|
|
* the parsing is complete.
|
|
|
|
* @return A valid ASCII character.
|
2017-12-01 16:49:19 +00:00
|
|
|
* @throw IO_ERROR on an unexpected end of line.
|
|
|
|
* @throw PARSE_ERROR if the parsed token is not a a single character token.
|
2016-07-06 09:22:56 +00:00
|
|
|
*/
|
2019-03-14 18:57:16 +00:00
|
|
|
static char parseChar( LINE_READER& aReader, const char* aCurrentToken,
|
2016-07-06 09:22:56 +00:00
|
|
|
const char** aNextToken = NULL )
|
|
|
|
{
|
|
|
|
while( *aCurrentToken && isspace( *aCurrentToken ) )
|
|
|
|
aCurrentToken++;
|
|
|
|
|
|
|
|
if( !*aCurrentToken )
|
|
|
|
SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, aCurrentToken );
|
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
if( !isspace( *( aCurrentToken + 1 ) ) )
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "expected single character token", aReader, aCurrentToken );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
if( aNextToken )
|
|
|
|
{
|
|
|
|
const char* next = aCurrentToken + 2;
|
|
|
|
|
|
|
|
while( *next && isspace( *next ) )
|
|
|
|
next++;
|
|
|
|
|
|
|
|
*aNextToken = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *aCurrentToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-01 16:49:19 +00:00
|
|
|
* Parse an unquoted utf8 string and updates the pointer at \a aOutput if it is not NULL.
|
2016-07-06 09:22:56 +00:00
|
|
|
*
|
|
|
|
* The parsed string must be a continuous string with no white space.
|
|
|
|
*
|
|
|
|
* @param aString - A reference to the parsed string.
|
|
|
|
* @param aReader - The line reader used to generate exception throw information.
|
|
|
|
* @param aCurrentToken - A pointer the current position in a string.
|
|
|
|
* @param aNextToken - The pointer to a string pointer to copy the string pointer position when
|
|
|
|
* the parsing is complete.
|
|
|
|
* @param aCanBeEmpty - True if the parsed string is optional. False if it is mandatory.
|
2017-12-01 16:49:19 +00:00
|
|
|
* @throw IO_ERROR on an unexpected end of line.
|
|
|
|
* @throw PARSE_ERROR if the \a aCanBeEmpty is false and no string was parsed.
|
2016-07-06 09:22:56 +00:00
|
|
|
*/
|
2019-03-14 18:57:16 +00:00
|
|
|
static void parseUnquotedString( wxString& aString, LINE_READER& aReader,
|
2016-07-06 09:22:56 +00:00
|
|
|
const char* aCurrentToken, const char** aNextToken = NULL,
|
|
|
|
bool aCanBeEmpty = false )
|
|
|
|
{
|
|
|
|
if( !*aCurrentToken )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
if( aCanBeEmpty )
|
|
|
|
return;
|
|
|
|
else
|
|
|
|
SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, aCurrentToken );
|
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
const char* tmp = aCurrentToken;
|
|
|
|
|
|
|
|
while( *tmp && isspace( *tmp ) )
|
|
|
|
tmp++;
|
|
|
|
|
|
|
|
if( !*tmp )
|
|
|
|
{
|
|
|
|
if( aCanBeEmpty )
|
|
|
|
return;
|
|
|
|
else
|
2016-08-18 23:23:10 +00:00
|
|
|
SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, aCurrentToken );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string utf8;
|
|
|
|
|
|
|
|
while( *tmp && !isspace( *tmp ) )
|
|
|
|
utf8 += *tmp++;
|
|
|
|
|
|
|
|
aString = FROM_UTF8( utf8.c_str() );
|
|
|
|
|
|
|
|
if( aString.IsEmpty() && !aCanBeEmpty )
|
|
|
|
SCH_PARSE_ERROR( _( "expected unquoted string" ), aReader, aCurrentToken );
|
|
|
|
|
|
|
|
if( aNextToken )
|
|
|
|
{
|
|
|
|
const char* next = tmp;
|
|
|
|
|
|
|
|
while( *next && isspace( *next ) )
|
|
|
|
next++;
|
|
|
|
|
|
|
|
*aNextToken = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-01 16:49:19 +00:00
|
|
|
* Parse an quoted ASCII utf8 and updates the pointer at \a aOutput if it is not NULL.
|
2016-07-06 09:22:56 +00:00
|
|
|
*
|
|
|
|
* The parsed string must be contained within a single line. There are no multi-line
|
|
|
|
* quoted strings in the legacy schematic file format.
|
|
|
|
*
|
|
|
|
* @param aString - A reference to the parsed string.
|
|
|
|
* @param aReader - The line reader used to generate exception throw information.
|
|
|
|
* @param aCurrentToken - A pointer the current position in a string.
|
|
|
|
* @param aNextToken - The pointer to a string pointer to copy the string pointer position when
|
|
|
|
* the parsing is complete.
|
|
|
|
* @param aCanBeEmpty - True if the parsed string is optional. False if it is mandatory.
|
2017-12-01 16:49:19 +00:00
|
|
|
* @throw IO_ERROR on an unexpected end of line.
|
|
|
|
* @throw PARSE_ERROR if the \a aCanBeEmpty is false and no string was parsed.
|
2016-07-06 09:22:56 +00:00
|
|
|
*/
|
2019-03-14 18:57:16 +00:00
|
|
|
static void parseQuotedString( wxString& aString, LINE_READER& aReader,
|
2016-07-06 09:22:56 +00:00
|
|
|
const char* aCurrentToken, const char** aNextToken = NULL,
|
|
|
|
bool aCanBeEmpty = false )
|
|
|
|
{
|
|
|
|
if( !*aCurrentToken )
|
|
|
|
{
|
|
|
|
if( aCanBeEmpty )
|
|
|
|
return;
|
|
|
|
else
|
2016-08-18 23:23:10 +00:00
|
|
|
SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, aCurrentToken );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* tmp = aCurrentToken;
|
|
|
|
|
|
|
|
while( *tmp && isspace( *tmp ) )
|
|
|
|
tmp++;
|
|
|
|
|
|
|
|
if( !*tmp )
|
|
|
|
{
|
|
|
|
if( aCanBeEmpty )
|
|
|
|
return;
|
|
|
|
else
|
2016-08-18 23:23:10 +00:00
|
|
|
SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, aCurrentToken );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify opening quote.
|
|
|
|
if( *tmp != '"' )
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "expecting opening quote", aReader, aCurrentToken );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
tmp++;
|
|
|
|
|
|
|
|
std::string utf8; // utf8 without escapes and quotes.
|
|
|
|
|
|
|
|
// Fetch everything up to closing quote.
|
|
|
|
while( *tmp )
|
|
|
|
{
|
|
|
|
if( *tmp == '\\' )
|
|
|
|
{
|
|
|
|
tmp++;
|
|
|
|
|
|
|
|
if( !*tmp )
|
2016-08-18 23:23:10 +00:00
|
|
|
SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, aCurrentToken );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
// Do not copy the escape byte if it is followed by \ or "
|
|
|
|
if( *tmp != '"' && *tmp != '\\' )
|
|
|
|
utf8 += '\\';
|
|
|
|
|
|
|
|
utf8 += *tmp;
|
|
|
|
}
|
|
|
|
else if( *tmp == '"' ) // Closing double quote.
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
utf8 += *tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
aString = FROM_UTF8( utf8.c_str() );
|
|
|
|
|
|
|
|
if( aString.IsEmpty() && !aCanBeEmpty )
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "expected quoted string", aReader, aCurrentToken );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
if( *tmp && *tmp != '"' )
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "no closing quote for string found", aReader, tmp );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
// Move past the closing quote.
|
|
|
|
tmp++;
|
|
|
|
|
|
|
|
if( aNextToken )
|
|
|
|
{
|
|
|
|
const char* next = tmp;
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
while( *next == ' ' )
|
2016-07-06 09:22:56 +00:00
|
|
|
next++;
|
|
|
|
|
|
|
|
*aNextToken = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-31 01:31:19 +00:00
|
|
|
/**
|
2017-12-01 16:49:19 +00:00
|
|
|
* A cache assistant for the part library portion of the #SCH_PLUGIN API, and only for the
|
2017-01-31 01:31:19 +00:00
|
|
|
* #SCH_LEGACY_PLUGIN, so therefore is private to this implementation file, i.e. not placed
|
|
|
|
* into a header.
|
|
|
|
*/
|
|
|
|
class SCH_LEGACY_PLUGIN_CACHE
|
|
|
|
{
|
2017-10-22 00:48:25 +00:00
|
|
|
static int m_modHash; // Keep track of the modification status of the library.
|
|
|
|
|
2018-01-25 00:37:07 +00:00
|
|
|
wxString m_fileName; // Absolute path and file name.
|
2017-01-31 01:31:19 +00:00
|
|
|
wxFileName m_libFileName; // Absolute path and file name is required here.
|
|
|
|
wxDateTime m_fileModTime;
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART_MAP m_symbols; // Map of names of #LIB_PART pointers.
|
2017-01-31 01:31:19 +00:00
|
|
|
bool m_isWritable;
|
|
|
|
bool m_isModified;
|
|
|
|
int m_versionMajor;
|
|
|
|
int m_versionMinor;
|
|
|
|
int m_libType; // Is this cache a component or symbol library.
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
void loadHeader( FILE_LINE_READER& aReader );
|
2019-11-06 19:15:42 +00:00
|
|
|
static void loadAliases( std::unique_ptr<LIB_PART>& aPart, LINE_READER& aReader,
|
|
|
|
LIB_PART_MAP* aMap = nullptr );
|
2019-04-28 16:36:31 +00:00
|
|
|
static void loadField( std::unique_ptr<LIB_PART>& aPart, LINE_READER& aReader );
|
|
|
|
static void loadDrawEntries( std::unique_ptr<LIB_PART>& aPart, LINE_READER& aReader,
|
|
|
|
int aMajorVersion, int aMinorVersion );
|
|
|
|
static void loadFootprintFilters( std::unique_ptr<LIB_PART>& aPart,
|
|
|
|
LINE_READER& aReader );
|
|
|
|
void loadDocs();
|
|
|
|
static LIB_ARC* loadArc( std::unique_ptr<LIB_PART>& aPart, LINE_READER& aReader );
|
|
|
|
static LIB_CIRCLE* loadCircle( std::unique_ptr<LIB_PART>& aPart, LINE_READER& aReader );
|
|
|
|
static LIB_TEXT* loadText( std::unique_ptr<LIB_PART>& aPart, LINE_READER& aReader,
|
|
|
|
int aMajorVersion, int aMinorVersion );
|
|
|
|
static LIB_RECTANGLE* loadRectangle( std::unique_ptr<LIB_PART>& aPart,
|
|
|
|
LINE_READER& aReader );
|
|
|
|
static LIB_PIN* loadPin( std::unique_ptr<LIB_PART>& aPart, LINE_READER& aReader );
|
|
|
|
static LIB_POLYLINE* loadPolyLine( std::unique_ptr<LIB_PART>& aPart, LINE_READER& aReader );
|
|
|
|
static LIB_BEZIER* loadBezier( std::unique_ptr<LIB_PART>& aPart, LINE_READER& aReader );
|
|
|
|
|
|
|
|
static FILL_T parseFillMode( LINE_READER& aReader, const char* aLine,
|
2019-11-06 19:15:42 +00:00
|
|
|
const char** aOutput );
|
|
|
|
LIB_PART* removeSymbol( LIB_PART* aAlias );
|
2017-01-31 01:31:19 +00:00
|
|
|
|
|
|
|
void saveDocFile();
|
2019-03-14 18:57:16 +00:00
|
|
|
static void saveArc( LIB_ARC* aArc, OUTPUTFORMATTER& aFormatter );
|
|
|
|
static void saveBezier( LIB_BEZIER* aBezier, OUTPUTFORMATTER& aFormatter );
|
|
|
|
static void saveCircle( LIB_CIRCLE* aCircle, OUTPUTFORMATTER& aFormatter );
|
|
|
|
static void saveField( LIB_FIELD* aField, OUTPUTFORMATTER& aFormatter );
|
|
|
|
static void savePin( LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter );
|
|
|
|
static void savePolyLine( LIB_POLYLINE* aPolyLine, OUTPUTFORMATTER& aFormatter );
|
|
|
|
static void saveRectangle( LIB_RECTANGLE* aRectangle, OUTPUTFORMATTER& aFormatter );
|
|
|
|
static void saveText( LIB_TEXT* aText, OUTPUTFORMATTER& aFormatter );
|
2017-01-31 01:31:19 +00:00
|
|
|
|
|
|
|
friend SCH_LEGACY_PLUGIN;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SCH_LEGACY_PLUGIN_CACHE( const wxString& aLibraryPath );
|
|
|
|
~SCH_LEGACY_PLUGIN_CACHE();
|
|
|
|
|
|
|
|
int GetModifyHash() const { return m_modHash; }
|
|
|
|
|
|
|
|
// Most all functions in this class throw IO_ERROR exceptions. There are no
|
|
|
|
// error codes nor user interface calls from here, nor in any SCH_PLUGIN objects.
|
|
|
|
// Catch these exceptions higher up please.
|
|
|
|
|
|
|
|
/// Save the entire library to file m_libFileName;
|
|
|
|
void Save( bool aSaveDocFile = true );
|
|
|
|
|
|
|
|
void Load();
|
|
|
|
|
|
|
|
void AddSymbol( const LIB_PART* aPart );
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
void DeleteSymbol( const wxString& aName );
|
2017-01-31 01:31:19 +00:00
|
|
|
|
2018-07-23 22:49:07 +00:00
|
|
|
// If m_libFileName is a symlink follow it to the real source file
|
|
|
|
wxFileName GetRealFile() const;
|
|
|
|
|
2017-01-31 01:31:19 +00:00
|
|
|
wxDateTime GetLibModificationTime();
|
|
|
|
|
|
|
|
bool IsFile( const wxString& aFullPathAndFileName ) const;
|
|
|
|
|
|
|
|
bool IsFileChanged() const;
|
|
|
|
|
|
|
|
void SetModified( bool aModified = true ) { m_isModified = aModified; }
|
|
|
|
|
|
|
|
wxString GetLogicalName() const { return m_libFileName.GetName(); }
|
|
|
|
|
|
|
|
void SetFileName( const wxString& aFileName ) { m_libFileName = aFileName; }
|
|
|
|
|
|
|
|
wxString GetFileName() const { return m_libFileName.GetFullPath(); }
|
2019-03-15 13:09:42 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
static LIB_PART* LoadPart( LINE_READER& aReader, int aMajorVersion, int aMinorVersion,
|
|
|
|
LIB_PART_MAP* aMap = nullptr );
|
|
|
|
static void SaveSymbol( LIB_PART* aSymbol, OUTPUTFORMATTER& aFormatter,
|
|
|
|
LIB_PART_MAP* aMap = nullptr );
|
2017-01-31 01:31:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
SCH_LEGACY_PLUGIN::SCH_LEGACY_PLUGIN()
|
|
|
|
{
|
|
|
|
init( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-28 04:30:13 +00:00
|
|
|
SCH_LEGACY_PLUGIN::~SCH_LEGACY_PLUGIN()
|
|
|
|
{
|
|
|
|
delete m_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::init( KIWAY* aKiway, const PROPERTIES* aProperties )
|
|
|
|
{
|
|
|
|
m_version = 0;
|
|
|
|
m_rootSheet = NULL;
|
|
|
|
m_props = aProperties;
|
|
|
|
m_kiway = aKiway;
|
2016-08-18 23:23:10 +00:00
|
|
|
m_cache = NULL;
|
|
|
|
m_out = NULL;
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_SHEET* SCH_LEGACY_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway,
|
|
|
|
SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties )
|
|
|
|
{
|
|
|
|
wxASSERT( !aFileName || aKiway != NULL );
|
|
|
|
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
SCH_SHEET* sheet;
|
|
|
|
|
|
|
|
wxFileName fn = aFileName;
|
|
|
|
|
|
|
|
// Unfortunately child sheet file names the legacy schematic file format are not fully
|
|
|
|
// qualified and are always appended to the project path. The aFileName attribute must
|
|
|
|
// always be an absolute path so the project path can be used for load child sheet files.
|
|
|
|
wxASSERT( fn.IsAbsolute() );
|
|
|
|
|
2018-02-05 14:01:55 +00:00
|
|
|
if( aAppendToMe )
|
|
|
|
{
|
2018-02-14 16:55:06 +00:00
|
|
|
wxLogTrace( traceSchLegacyPlugin, "Append \"%s\" to sheet \"%s\".",
|
|
|
|
aFileName, aAppendToMe->GetFileName() );
|
2018-02-05 14:01:55 +00:00
|
|
|
|
|
|
|
wxFileName normedFn = aAppendToMe->GetFileName();
|
|
|
|
|
|
|
|
if( !normedFn.IsAbsolute() )
|
|
|
|
{
|
|
|
|
if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
|
|
|
|
m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
|
|
|
|
}
|
2018-02-14 16:55:06 +00:00
|
|
|
|
2018-04-22 13:47:54 +00:00
|
|
|
if( m_path.IsEmpty() )
|
|
|
|
m_path = aKiway->Prj().GetProjectPath();
|
|
|
|
|
2020-02-07 17:06:24 +00:00
|
|
|
wxLogTrace( traceSchLegacyPlugin, "m_Normalized append path \"%s\".", m_path );
|
2018-02-05 14:01:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_path = aKiway->Prj().GetProjectPath();
|
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2018-05-09 09:15:00 +00:00
|
|
|
m_currentPath.push( m_path );
|
2016-07-06 09:22:56 +00:00
|
|
|
init( aKiway, aProperties );
|
|
|
|
|
|
|
|
if( aAppendToMe == NULL )
|
|
|
|
{
|
|
|
|
// Clean up any allocated memory if an exception occurs loading the schematic.
|
2016-07-11 19:48:46 +00:00
|
|
|
std::unique_ptr< SCH_SHEET > newSheet( new SCH_SHEET );
|
2016-07-06 09:22:56 +00:00
|
|
|
newSheet->SetFileName( aFileName );
|
|
|
|
m_rootSheet = newSheet.get();
|
|
|
|
loadHierarchy( newSheet.get() );
|
|
|
|
|
|
|
|
// If we got here, the schematic loaded successfully.
|
|
|
|
sheet = newSheet.release();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_rootSheet = aAppendToMe->GetRootSheet();
|
|
|
|
wxASSERT( m_rootSheet != NULL );
|
|
|
|
sheet = aAppendToMe;
|
|
|
|
loadHierarchy( sheet );
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:15:00 +00:00
|
|
|
wxASSERT( m_currentPath.size() == 1 ); // only the project path should remain
|
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
return sheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Everything below this comment is recursive. Modify with care.
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::loadHierarchy( SCH_SHEET* aSheet )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = NULL;
|
|
|
|
|
|
|
|
if( !aSheet->GetScreen() )
|
|
|
|
{
|
2016-07-25 00:52:40 +00:00
|
|
|
// SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
|
|
|
|
// stores the file name and extension. Add the project path to the file name and
|
|
|
|
// extension to compare when calling SCH_SHEET::SearchHierarchy().
|
|
|
|
wxFileName fileName = aSheet->GetFileName();
|
|
|
|
|
|
|
|
if( !fileName.IsAbsolute() )
|
2018-05-09 09:15:00 +00:00
|
|
|
fileName.MakeAbsolute( m_currentPath.top() );
|
2016-07-25 00:52:40 +00:00
|
|
|
|
2018-02-05 14:01:55 +00:00
|
|
|
// Save the current path so that it gets restored when decending and ascending the
|
|
|
|
// sheet hierarchy which allows for sheet schematic files to be nested in folders
|
|
|
|
// relative to the last path a schematic was loaded from.
|
2018-05-09 09:15:00 +00:00
|
|
|
wxLogTrace( traceSchLegacyPlugin, "Saving path \"%s\"", m_currentPath.top() );
|
|
|
|
m_currentPath.push( fileName.GetPath() );
|
|
|
|
wxLogTrace( traceSchLegacyPlugin, "Current path \"%s\"", m_currentPath.top() );
|
|
|
|
wxLogTrace( traceSchLegacyPlugin, "Loading \"%s\"", fileName.GetFullPath() );
|
2018-02-05 14:01:55 +00:00
|
|
|
|
2019-07-09 15:09:03 +00:00
|
|
|
m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
if( screen )
|
|
|
|
{
|
|
|
|
aSheet->SetScreen( screen );
|
|
|
|
|
|
|
|
// Do not need to load the sub-sheets - this has already been done.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aSheet->SetScreen( new SCH_SCREEN( m_kiway ) );
|
|
|
|
aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
|
|
|
|
|
2017-12-07 00:10:45 +00:00
|
|
|
try
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2017-12-07 00:10:45 +00:00
|
|
|
loadFile( fileName.GetFullPath(), aSheet->GetScreen() );
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
|
2017-12-07 00:10:45 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
assert( aItem->Type() == SCH_SHEET_T );
|
|
|
|
auto sheet = static_cast<SCH_SHEET*>( aItem );
|
|
|
|
|
|
|
|
// Set the parent to aSheet. This effectively creates a method to find
|
|
|
|
// the root sheet from any sheet so a pointer to the root sheet does not
|
|
|
|
// need to be stored globally. Note: this is not the same as a hierarchy.
|
|
|
|
// Complex hierarchies can have multiple copies of a sheet. This only
|
|
|
|
// provides a simple tree to find the root sheet.
|
|
|
|
sheet->SetParent( aSheet );
|
|
|
|
|
|
|
|
// Recursion starts here.
|
|
|
|
loadHierarchy( sheet );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
2017-12-07 00:10:45 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
// If there is a problem loading the root sheet, there is no recovery.
|
|
|
|
if( aSheet == m_rootSheet )
|
|
|
|
throw( ioe );
|
|
|
|
|
|
|
|
// For all subsheets, queue up the error message for the caller.
|
|
|
|
if( !m_error.IsEmpty() )
|
|
|
|
m_error += "\n";
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2017-12-07 00:10:45 +00:00
|
|
|
m_error += ioe.What();
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-05 14:01:55 +00:00
|
|
|
|
2018-05-09 09:15:00 +00:00
|
|
|
m_currentPath.pop();
|
|
|
|
wxLogTrace( traceSchLegacyPlugin, "Restoring path \"%s\"", m_currentPath.top() );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::loadFile( const wxString& aFileName, SCH_SCREEN* aScreen )
|
|
|
|
{
|
|
|
|
FILE_LINE_READER reader( aFileName );
|
|
|
|
|
|
|
|
loadHeader( reader, aScreen );
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
LoadContent( reader, aScreen, m_version );
|
|
|
|
|
|
|
|
// Unfortunately schematic files prior to version 2 are not terminated with $EndSCHEMATC
|
|
|
|
// so checking for it's existance will fail so just exit here and take our chances. :(
|
|
|
|
if( m_version > 1 )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
char* line = reader.Line();
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
while( *line == ' ' )
|
|
|
|
line++;
|
|
|
|
|
|
|
|
if( !strCompare( "$EndSCHEMATC", line ) )
|
|
|
|
THROW_IO_ERROR( "'$EndSCHEMATC' not found" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::LoadContent( LINE_READER& aReader, SCH_SCREEN* aScreen, int version )
|
|
|
|
{
|
|
|
|
m_version = version;
|
|
|
|
|
2020-02-28 19:08:48 +00:00
|
|
|
// We cannot safely load content without a set root level. If we haven't been given one,
|
|
|
|
// pick the default
|
|
|
|
if( m_rootSheet == nullptr )
|
|
|
|
m_rootSheet = g_RootSheet;
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
while( aReader.ReadLine() )
|
|
|
|
{
|
|
|
|
char* line = aReader.Line();
|
|
|
|
|
|
|
|
while( *line == ' ' )
|
2016-07-06 09:22:56 +00:00
|
|
|
line++;
|
|
|
|
|
|
|
|
// Either an object will be loaded properly or the file load will fail and raise
|
|
|
|
// an exception.
|
|
|
|
if( strCompare( "$Descr", line ) )
|
2019-04-28 16:36:31 +00:00
|
|
|
loadPageSettings( aReader, aScreen );
|
2016-07-06 09:22:56 +00:00
|
|
|
else if( strCompare( "$Comp", line ) )
|
2019-04-28 16:36:31 +00:00
|
|
|
aScreen->Append( loadComponent( aReader ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
else if( strCompare( "$Sheet", line ) )
|
2019-04-28 16:36:31 +00:00
|
|
|
aScreen->Append( loadSheet( aReader ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
else if( strCompare( "$Bitmap", line ) )
|
2019-04-28 16:36:31 +00:00
|
|
|
aScreen->Append( loadBitmap( aReader ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
else if( strCompare( "Connection", line ) )
|
2019-04-28 16:36:31 +00:00
|
|
|
aScreen->Append( loadJunction( aReader ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
else if( strCompare( "NoConn", line ) )
|
2019-04-28 16:36:31 +00:00
|
|
|
aScreen->Append( loadNoConnect( aReader ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
else if( strCompare( "Wire", line ) )
|
2019-04-28 16:36:31 +00:00
|
|
|
aScreen->Append( loadWire( aReader ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
else if( strCompare( "Entry", line ) )
|
2019-04-28 16:36:31 +00:00
|
|
|
aScreen->Append( loadBusEntry( aReader ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
else if( strCompare( "Text", line ) )
|
2019-04-28 16:36:31 +00:00
|
|
|
aScreen->Append( loadText( aReader ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
else if( strCompare( "BusAlias", line ) )
|
2019-04-28 16:36:31 +00:00
|
|
|
aScreen->AddBusAlias( loadBusAlias( aReader, aScreen ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
else if( strCompare( "$EndSCHEMATC", line ) )
|
|
|
|
return;
|
2019-08-15 07:19:15 +00:00
|
|
|
else
|
|
|
|
SCH_PARSE_ERROR( "unrecognized token", aReader, line );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::loadHeader( LINE_READER& aReader, SCH_SCREEN* aScreen )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.ReadLine();
|
|
|
|
|
2018-03-01 22:13:50 +00:00
|
|
|
if( !line || !strCompare( "Eeschema Schematic File Version", line, &line ) )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
m_error.Printf( _( "\"%s\" does not appear to be an Eeschema file" ),
|
2016-07-06 09:22:56 +00:00
|
|
|
GetChars( aScreen->GetFileName() ) );
|
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the file version here.
|
|
|
|
m_version = parseInt( aReader, line, &line );
|
|
|
|
|
|
|
|
// The next lines are the lib list section, and are mainly comments, like:
|
|
|
|
// LIBS:power
|
|
|
|
// the lib list is not used, but is in schematic file just in case.
|
|
|
|
// It is usually not empty, but we accept empty list.
|
|
|
|
// If empty, there is a legacy section, not used
|
|
|
|
// EELAYER i j
|
|
|
|
// and the last line is
|
|
|
|
// EELAYER END
|
|
|
|
// Skip all lines until the end of header "EELAYER END" is found
|
|
|
|
while( aReader.ReadLine() )
|
|
|
|
{
|
|
|
|
line = aReader.Line();
|
|
|
|
|
|
|
|
while( *line == ' ' )
|
|
|
|
line++;
|
|
|
|
|
|
|
|
if( strCompare( "EELAYER END", line ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( _( "Missing 'EELAYER END'" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::loadPageSettings( LINE_READER& aReader, SCH_SCREEN* aScreen )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
wxASSERT( aScreen != NULL );
|
|
|
|
|
|
|
|
wxString buf;
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
|
|
|
PAGE_INFO pageInfo;
|
|
|
|
TITLE_BLOCK tb;
|
|
|
|
|
|
|
|
wxCHECK_RET( strCompare( "$Descr", line, &line ), "Invalid sheet description" );
|
|
|
|
|
|
|
|
parseUnquotedString( buf, aReader, line, &line );
|
|
|
|
|
|
|
|
if( !pageInfo.SetType( buf ) )
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid page size", aReader, line );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2016-09-13 17:47:20 +00:00
|
|
|
int pagew = parseInt( aReader, line, &line );
|
|
|
|
int pageh = parseInt( aReader, line, &line );
|
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
if( buf == PAGE_INFO::Custom )
|
|
|
|
{
|
2016-09-13 17:47:20 +00:00
|
|
|
pageInfo.SetWidthMils( pagew );
|
|
|
|
pageInfo.SetHeightMils( pageh );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString orientation;
|
|
|
|
|
|
|
|
// Non custom size, set portrait if its present. Can be empty string which defaults
|
|
|
|
// to landscape.
|
|
|
|
parseUnquotedString( orientation, aReader, line, &line, true );
|
|
|
|
|
|
|
|
if( orientation == "portrait" )
|
|
|
|
pageInfo.SetPortrait( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
aScreen->SetPageSettings( pageInfo );
|
|
|
|
|
|
|
|
while( line != NULL )
|
|
|
|
{
|
|
|
|
buf.clear();
|
|
|
|
|
|
|
|
if( !aReader.ReadLine() )
|
|
|
|
SCH_PARSE_ERROR( _( "unexpected end of file" ), aReader, line );
|
|
|
|
|
|
|
|
line = aReader.Line();
|
|
|
|
|
|
|
|
if( strCompare( "Sheet", line, &line ) )
|
|
|
|
{
|
|
|
|
aScreen->m_ScreenNumber = parseInt( aReader, line, &line );
|
|
|
|
aScreen->m_NumberOfScreens = parseInt( aReader, line, &line );
|
|
|
|
}
|
|
|
|
else if( strCompare( "Title", line, &line ) )
|
|
|
|
{
|
|
|
|
parseQuotedString( buf, aReader, line, &line, true );
|
|
|
|
tb.SetTitle( buf );
|
|
|
|
}
|
|
|
|
else if( strCompare( "Date", line, &line ) )
|
|
|
|
{
|
|
|
|
parseQuotedString( buf, aReader, line, &line, true );
|
|
|
|
tb.SetDate( buf );
|
|
|
|
}
|
|
|
|
else if( strCompare( "Rev", line, &line ) )
|
|
|
|
{
|
|
|
|
parseQuotedString( buf, aReader, line, &line, true );
|
|
|
|
tb.SetRevision( buf );
|
|
|
|
}
|
|
|
|
else if( strCompare( "Comp", line, &line ) )
|
|
|
|
{
|
|
|
|
parseQuotedString( buf, aReader, line, &line, true );
|
|
|
|
tb.SetCompany( buf );
|
|
|
|
}
|
|
|
|
else if( strCompare( "Comment1", line, &line ) )
|
|
|
|
{
|
|
|
|
parseQuotedString( buf, aReader, line, &line, true );
|
2019-08-21 16:58:29 +00:00
|
|
|
tb.SetComment( 0, buf );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
else if( strCompare( "Comment2", line, &line ) )
|
|
|
|
{
|
|
|
|
parseQuotedString( buf, aReader, line, &line, true );
|
2019-08-21 16:58:29 +00:00
|
|
|
tb.SetComment( 1, buf );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
else if( strCompare( "Comment3", line, &line ) )
|
|
|
|
{
|
|
|
|
parseQuotedString( buf, aReader, line, &line, true );
|
2019-08-21 16:58:29 +00:00
|
|
|
tb.SetComment( 2, buf );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
else if( strCompare( "Comment4", line, &line ) )
|
|
|
|
{
|
|
|
|
parseQuotedString( buf, aReader, line, &line, true );
|
2019-08-21 16:58:29 +00:00
|
|
|
tb.SetComment( 3, buf );
|
|
|
|
}
|
|
|
|
else if( strCompare( "Comment5", line, &line ) )
|
|
|
|
{
|
|
|
|
parseQuotedString( buf, aReader, line, &line, true );
|
|
|
|
tb.SetComment( 4, buf );
|
|
|
|
}
|
|
|
|
else if( strCompare( "Comment6", line, &line ) )
|
|
|
|
{
|
|
|
|
parseQuotedString( buf, aReader, line, &line, true );
|
|
|
|
tb.SetComment( 5, buf );
|
|
|
|
}
|
|
|
|
else if( strCompare( "Comment7", line, &line ) )
|
|
|
|
{
|
|
|
|
parseQuotedString( buf, aReader, line, &line, true );
|
|
|
|
tb.SetComment( 6, buf );
|
|
|
|
}
|
|
|
|
else if( strCompare( "Comment8", line, &line ) )
|
|
|
|
{
|
|
|
|
parseQuotedString( buf, aReader, line, &line, true );
|
|
|
|
tb.SetComment( 7, buf );
|
|
|
|
}
|
|
|
|
else if( strCompare( "Comment9", line, &line ) )
|
|
|
|
{
|
|
|
|
parseQuotedString( buf, aReader, line, &line, true );
|
|
|
|
tb.SetComment( 8, buf );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
else if( strCompare( "$EndDescr", line ) )
|
|
|
|
{
|
|
|
|
aScreen->SetTitleBlock( tb );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "missing 'EndDescr'", aReader, line );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
SCH_SHEET* SCH_LEGACY_PLUGIN::loadSheet( LINE_READER& aReader )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2016-07-11 19:48:46 +00:00
|
|
|
std::unique_ptr< SCH_SHEET > sheet( new SCH_SHEET() );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
const char* line = aReader.ReadLine();
|
|
|
|
|
|
|
|
while( line != NULL )
|
|
|
|
{
|
|
|
|
if( strCompare( "S", line, &line ) ) // Sheet dimensions.
|
|
|
|
{
|
|
|
|
wxPoint position;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
position.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
position.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
sheet->SetPosition( position );
|
|
|
|
|
|
|
|
wxSize size;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
size.SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
|
|
|
|
size.SetHeight( Mils2Iu( parseInt( aReader, line, &line ) ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
sheet->SetSize( size );
|
|
|
|
}
|
2020-02-20 12:11:04 +00:00
|
|
|
else if( strCompare( "U", line, &line ) ) // Sheet UUID.
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
wxString text;
|
|
|
|
parseUnquotedString( text, aReader, line );
|
2020-03-04 02:02:22 +00:00
|
|
|
|
|
|
|
if( text != "00000000" )
|
|
|
|
const_cast<KIID&>( sheet->m_Uuid ) = KIID( text );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
else if( *line == 'F' ) // Sheet field.
|
|
|
|
{
|
|
|
|
line++;
|
|
|
|
|
|
|
|
wxString text;
|
|
|
|
int size;
|
|
|
|
int fieldId = parseInt( aReader, line, &line );
|
|
|
|
|
|
|
|
if( fieldId == 0 || fieldId == 1 ) // Sheet name and file name.
|
|
|
|
{
|
|
|
|
parseQuotedString( text, aReader, line, &line );
|
2019-12-30 18:28:00 +00:00
|
|
|
size = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
if( fieldId == 0 )
|
|
|
|
{
|
|
|
|
sheet->SetName( text );
|
|
|
|
sheet->SetSheetNameSize( size );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sheet->SetFileName( text );
|
|
|
|
sheet->SetFileNameSize( size );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Sheet pin.
|
|
|
|
{
|
2020-01-12 18:40:50 +00:00
|
|
|
// Use a unique_ptr so that we clean up in the case of a throw
|
2016-07-11 19:48:46 +00:00
|
|
|
std::unique_ptr< SCH_SHEET_PIN > sheetPin( new SCH_SHEET_PIN( sheet.get() ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
sheetPin->SetNumber( fieldId );
|
|
|
|
|
|
|
|
// Can be empty fields.
|
|
|
|
parseQuotedString( text, aReader, line, &line, true );
|
|
|
|
|
|
|
|
sheetPin->SetText( text );
|
|
|
|
|
|
|
|
if( line == NULL )
|
|
|
|
THROW_IO_ERROR( _( "unexpected end of line" ) );
|
|
|
|
|
|
|
|
switch( parseChar( aReader, line, &line ) )
|
|
|
|
{
|
2020-02-20 21:29:21 +00:00
|
|
|
case 'I': sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_INPUT ); break;
|
|
|
|
case 'O': sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_OUTPUT ); break;
|
|
|
|
case 'B': sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_BIDI ); break;
|
|
|
|
case 'T': sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_TRISTATE ); break;
|
|
|
|
case 'U': sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_UNSPECIFIED ); break;
|
|
|
|
default: SCH_PARSE_ERROR( "invalid sheet pin type", aReader, line );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( parseChar( aReader, line, &line ) )
|
|
|
|
{
|
2019-05-17 16:45:27 +00:00
|
|
|
case 'R': sheetPin->SetEdge( SHEET_RIGHT_SIDE ); break;
|
|
|
|
case 'T': sheetPin->SetEdge( SHEET_TOP_SIDE ); break;
|
|
|
|
case 'B': sheetPin->SetEdge( SHEET_BOTTOM_SIDE ); break;
|
|
|
|
case 'L': sheetPin->SetEdge( SHEET_LEFT_SIDE ); break;
|
2016-07-06 09:22:56 +00:00
|
|
|
default:
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid sheet pin side", aReader, line );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxPoint position;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
position.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
position.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
sheetPin->SetPosition( position );
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
size = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
sheetPin->SetTextSize( wxSize( size, size ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
sheet->AddPin( sheetPin.release() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( strCompare( "$EndSheet", line ) )
|
2020-03-06 12:05:21 +00:00
|
|
|
{
|
|
|
|
sheet->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
|
2016-07-06 09:22:56 +00:00
|
|
|
return sheet.release();
|
2020-03-06 12:05:21 +00:00
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
}
|
|
|
|
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "missing '$EndSheet`", aReader, line );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
return NULL; // Prevents compiler warning. Should never get here.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
SCH_BITMAP* SCH_LEGACY_PLUGIN::loadBitmap( LINE_READER& aReader )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2016-07-11 19:48:46 +00:00
|
|
|
std::unique_ptr< SCH_BITMAP > bitmap( new SCH_BITMAP );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-07-06 13:52:47 +00:00
|
|
|
wxCHECK( strCompare( "$Bitmap", line, &line ), NULL );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
|
|
|
|
while( line != NULL )
|
|
|
|
{
|
|
|
|
if( strCompare( "Pos", line, &line ) )
|
|
|
|
{
|
|
|
|
wxPoint position;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
position.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
position.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
bitmap->SetPosition( position );
|
|
|
|
}
|
|
|
|
else if( strCompare( "Scale", line, &line ) )
|
|
|
|
{
|
2019-01-15 15:40:09 +00:00
|
|
|
auto scalefactor = parseDouble( aReader, line, &line );
|
|
|
|
|
|
|
|
// Prevent scalefactor values that cannot be displayed.
|
|
|
|
// In the case of a bad value, we accept that the image might be mis-scaled
|
|
|
|
// rather than removing the full image. Users can then edit the scale factor in
|
|
|
|
// Eeschema to the appropriate value
|
|
|
|
if( !std::isnormal( scalefactor ) )
|
|
|
|
scalefactor = 1.0;
|
|
|
|
|
|
|
|
bitmap->GetImage()->SetScale( scalefactor );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
else if( strCompare( "Data", line, &line ) )
|
|
|
|
{
|
|
|
|
wxMemoryOutputStream stream;
|
|
|
|
|
|
|
|
while( line )
|
|
|
|
{
|
|
|
|
if( !aReader.ReadLine() )
|
|
|
|
SCH_PARSE_ERROR( _( "Unexpected end of file" ), aReader, line );
|
|
|
|
|
|
|
|
line = aReader.Line();
|
|
|
|
|
|
|
|
if( strCompare( "EndData", line ) )
|
|
|
|
{
|
|
|
|
// all the PNG date is read.
|
|
|
|
// We expect here m_image and m_bitmap are void
|
|
|
|
wxImage* image = new wxImage();
|
|
|
|
wxMemoryInputStream istream( stream );
|
|
|
|
image->LoadFile( istream, wxBITMAP_TYPE_PNG );
|
2016-07-11 19:48:46 +00:00
|
|
|
bitmap->GetImage()->SetImage( image );
|
|
|
|
bitmap->GetImage()->SetBitmap( new wxBitmap( *image ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read PNG data, stored in hexadecimal,
|
|
|
|
// each byte = 2 hexadecimal digits and a space between 2 bytes
|
|
|
|
// and put it in memory stream buffer
|
|
|
|
int len = strlen( line );
|
|
|
|
|
|
|
|
for( ; len > 0 && !isspace( *line ); len -= 3, line += 3 )
|
|
|
|
{
|
|
|
|
int value = 0;
|
|
|
|
|
|
|
|
if( sscanf( line, "%X", &value ) == 1 )
|
|
|
|
stream.PutC( (char) value );
|
|
|
|
else
|
|
|
|
THROW_IO_ERROR( "invalid PNG data" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( line == NULL )
|
|
|
|
THROW_IO_ERROR( _( "unexpected end of file" ) );
|
|
|
|
}
|
|
|
|
else if( strCompare( "$EndBitmap", line ) )
|
|
|
|
return bitmap.release();
|
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( _( "unexpected end of file" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
SCH_JUNCTION* SCH_LEGACY_PLUGIN::loadJunction( LINE_READER& aReader )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2016-07-11 19:48:46 +00:00
|
|
|
std::unique_ptr< SCH_JUNCTION > junction( new SCH_JUNCTION );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-07-06 13:52:47 +00:00
|
|
|
wxCHECK( strCompare( "Connection", line, &line ), NULL );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
wxString name;
|
|
|
|
|
|
|
|
parseUnquotedString( name, aReader, line, &line );
|
|
|
|
|
|
|
|
wxPoint position;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
position.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
position.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
junction->SetPosition( position );
|
|
|
|
|
|
|
|
return junction.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
SCH_NO_CONNECT* SCH_LEGACY_PLUGIN::loadNoConnect( LINE_READER& aReader )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2016-07-11 19:48:46 +00:00
|
|
|
std::unique_ptr< SCH_NO_CONNECT > no_connect( new SCH_NO_CONNECT );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-07-06 13:52:47 +00:00
|
|
|
wxCHECK( strCompare( "NoConn", line, &line ), NULL );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
wxString name;
|
|
|
|
|
|
|
|
parseUnquotedString( name, aReader, line, &line );
|
|
|
|
|
|
|
|
wxPoint position;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
position.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
position.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
no_connect->SetPosition( position );
|
|
|
|
|
|
|
|
return no_connect.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
SCH_LINE* SCH_LEGACY_PLUGIN::loadWire( LINE_READER& aReader )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2016-07-11 19:48:46 +00:00
|
|
|
std::unique_ptr< SCH_LINE > wire( new SCH_LINE );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-07-06 13:52:47 +00:00
|
|
|
wxCHECK( strCompare( "Wire", line, &line ), NULL );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
if( strCompare( "Wire", line, &line ) )
|
|
|
|
wire->SetLayer( LAYER_WIRE );
|
|
|
|
else if( strCompare( "Bus", line, &line ) )
|
|
|
|
wire->SetLayer( LAYER_BUS );
|
|
|
|
else if( strCompare( "Notes", line, &line ) )
|
|
|
|
wire->SetLayer( LAYER_NOTES );
|
|
|
|
else
|
|
|
|
SCH_PARSE_ERROR( "invalid line type", aReader, line );
|
|
|
|
|
|
|
|
if( !strCompare( "Line", line, &line ) )
|
|
|
|
SCH_PARSE_ERROR( "invalid wire definition", aReader, line );
|
|
|
|
|
2017-11-15 13:08:27 +00:00
|
|
|
// Since Sept 15, 2017, a line style is alloved (width, style, color)
|
|
|
|
// Only non default values are stored
|
|
|
|
while( !is_eol( *line ) )
|
|
|
|
{
|
|
|
|
wxString buf;
|
|
|
|
|
|
|
|
parseUnquotedString( buf, aReader, line, &line );
|
|
|
|
|
|
|
|
if( buf == ")" )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
else if( buf == T_WIDTH )
|
|
|
|
{
|
2019-12-30 18:28:00 +00:00
|
|
|
int size = Mils2Iu( parseInt( aReader, line, &line ) );
|
2017-11-15 13:08:27 +00:00
|
|
|
wire->SetLineWidth( size );
|
|
|
|
}
|
|
|
|
else if( buf == T_STYLE )
|
|
|
|
{
|
|
|
|
parseUnquotedString( buf, aReader, line, &line );
|
2019-12-28 00:55:11 +00:00
|
|
|
PLOT_DASH_TYPE style = SCH_LINE::GetLineStyleByName( buf );
|
2017-11-15 13:08:27 +00:00
|
|
|
wire->SetLineStyle( style );
|
|
|
|
}
|
|
|
|
else // should be the color parameter.
|
|
|
|
{
|
|
|
|
// The color param is something like rgb(150, 40, 191)
|
|
|
|
// and because there is no space between ( and 150
|
|
|
|
// the first param is inside buf.
|
|
|
|
// So break keyword and the first param into 2 separate strings.
|
|
|
|
wxString prm, keyword;
|
|
|
|
keyword = buf.BeforeLast( '(', &prm );
|
|
|
|
|
|
|
|
if( ( keyword == T_COLOR ) || ( keyword == T_COLORA ) )
|
|
|
|
{
|
|
|
|
long color[4] = { 0 };
|
|
|
|
|
|
|
|
int ii = 0;
|
|
|
|
|
|
|
|
if( !prm.IsEmpty() )
|
|
|
|
{
|
|
|
|
prm.ToLong( &color[ii] );
|
|
|
|
ii++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int prm_count = ( keyword == T_COLORA ) ? 4 : 3;
|
|
|
|
// fix opacity to 1.0 or 255, when not exists in file
|
|
|
|
color[3] = 255;
|
|
|
|
|
|
|
|
for(; ii < prm_count && !is_eol( *line ); ii++ )
|
2018-12-09 16:59:00 +00:00
|
|
|
{
|
2017-11-15 13:08:27 +00:00
|
|
|
color[ii] = parseInt( aReader, line, &line );
|
|
|
|
|
2018-12-09 16:59:00 +00:00
|
|
|
// Skip the separator between values
|
|
|
|
if( *line == ',' || *line == ' ')
|
|
|
|
line++;
|
|
|
|
}
|
|
|
|
|
2017-11-15 13:08:27 +00:00
|
|
|
wire->SetLineColor( color[0]/255.0, color[1]/255.0, color[2]/255.0,color[3]/255.0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the segment en points coordinates:
|
2016-07-06 09:22:56 +00:00
|
|
|
line = aReader.ReadLine();
|
|
|
|
|
|
|
|
wxPoint begin, end;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
begin.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
begin.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
end.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
end.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
wire->SetStartPoint( begin );
|
|
|
|
wire->SetEndPoint( end );
|
|
|
|
|
|
|
|
return wire.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
SCH_BUS_ENTRY_BASE* SCH_LEGACY_PLUGIN::loadBusEntry( LINE_READER& aReader )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-07-06 13:52:47 +00:00
|
|
|
wxCHECK( strCompare( "Entry", line, &line ), NULL );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
std::unique_ptr< SCH_BUS_ENTRY_BASE > busEntry;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
if( strCompare( "Wire", line, &line ) )
|
|
|
|
{
|
|
|
|
busEntry.reset( new SCH_BUS_WIRE_ENTRY );
|
|
|
|
|
|
|
|
if( !strCompare( "Line", line, &line ) )
|
|
|
|
SCH_PARSE_ERROR( "invalid bus entry definition expected 'Line'", aReader, line );
|
|
|
|
}
|
|
|
|
else if( strCompare( "Bus", line, &line ) )
|
|
|
|
{
|
|
|
|
busEntry.reset( new SCH_BUS_BUS_ENTRY );
|
|
|
|
|
|
|
|
if( !strCompare( "Bus", line, &line ) )
|
|
|
|
SCH_PARSE_ERROR( "invalid bus entry definition expected 'Bus'", aReader, line );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SCH_PARSE_ERROR( "invalid bus entry type", aReader, line );
|
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
|
|
|
|
wxPoint pos;
|
|
|
|
wxSize size;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
size.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
size.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
size.x -= pos.x;
|
|
|
|
size.y -= pos.y;
|
|
|
|
|
|
|
|
busEntry->SetPosition( pos );
|
|
|
|
busEntry->SetSize( size );
|
|
|
|
|
|
|
|
return busEntry.release();
|
|
|
|
}
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
// clang-format off
|
|
|
|
const std::map<PINSHEETLABEL_SHAPE, const char*> sheetLabelNames
|
|
|
|
{
|
2020-01-09 07:52:30 +00:00
|
|
|
{ PINSHEETLABEL_SHAPE::PS_INPUT, "Input" },
|
|
|
|
{ PINSHEETLABEL_SHAPE::PS_OUTPUT, "Output" },
|
|
|
|
{ PINSHEETLABEL_SHAPE::PS_BIDI, "BiDi" },
|
|
|
|
{ PINSHEETLABEL_SHAPE::PS_TRISTATE, "3State" },
|
|
|
|
{ PINSHEETLABEL_SHAPE::PS_UNSPECIFIED, "UnSpc" },
|
2020-01-08 19:07:55 +00:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
SCH_TEXT* SCH_LEGACY_PLUGIN::loadText( LINE_READER& aReader )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-07-06 13:52:47 +00:00
|
|
|
wxCHECK( strCompare( "Text", line, &line ), NULL );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
std::unique_ptr< SCH_TEXT> text;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
if( strCompare( "Notes", line, &line ) )
|
|
|
|
text.reset( new SCH_TEXT );
|
|
|
|
else if( strCompare( "Label", line, &line ) )
|
|
|
|
text.reset( new SCH_LABEL );
|
|
|
|
else if( strCompare( "HLabel", line, &line ) )
|
|
|
|
text.reset( new SCH_HIERLABEL );
|
2016-07-07 13:09:32 +00:00
|
|
|
else if( strCompare( "GLabel", line, &line ) )
|
|
|
|
{
|
|
|
|
// Prior to version 2, the SCH_GLOBALLABEL object did not exist.
|
|
|
|
if( m_version == 1 )
|
|
|
|
text.reset( new SCH_HIERLABEL );
|
|
|
|
else
|
|
|
|
text.reset( new SCH_GLOBALLABEL );
|
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
else
|
|
|
|
SCH_PARSE_ERROR( "unknown Text type", aReader, line );
|
|
|
|
|
|
|
|
// Parse the parameters common to all text objects.
|
|
|
|
wxPoint position;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
position.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
position.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
text->SetPosition( position );
|
2020-01-08 19:07:55 +00:00
|
|
|
|
|
|
|
int spinStyle = parseInt( aReader, line, &line );
|
|
|
|
|
|
|
|
// Sadly we store the orientation of hierarchical and global labels using a different
|
|
|
|
// int encoding than that for local labels:
|
|
|
|
// Global Local
|
|
|
|
// Left justified 0 2
|
|
|
|
// Up 1 3
|
|
|
|
// Right justified 2 0
|
|
|
|
// Down 3 1
|
|
|
|
// So we must flip it as the enum is setup with the "global" numbering
|
|
|
|
if( text->Type() != SCH_GLOBAL_LABEL_T && text->Type() != SCH_HIER_LABEL_T )
|
|
|
|
{
|
|
|
|
if( spinStyle == 0 )
|
|
|
|
spinStyle = 2;
|
|
|
|
else if( spinStyle == 2 )
|
|
|
|
spinStyle = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
text->SetLabelSpinStyle( spinStyle );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
int size = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
text->SetTextSize( wxSize( size, size ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
// Parse the global and hierarchical label type.
|
2019-04-15 23:56:41 +00:00
|
|
|
if( text->Type() == SCH_HIER_LABEL_T || text->Type() == SCH_GLOBAL_LABEL_T )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2020-01-08 19:07:55 +00:00
|
|
|
auto resultIt = std::find_if( sheetLabelNames.begin(), sheetLabelNames.end(),
|
|
|
|
[ &line ]( const auto& it )
|
2020-01-09 07:52:30 +00:00
|
|
|
{
|
|
|
|
return strCompare( it.second, line, &line );
|
2020-01-08 19:07:55 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
if( resultIt != sheetLabelNames.end() )
|
|
|
|
text->SetShape( resultIt->first );
|
2016-07-06 09:22:56 +00:00
|
|
|
else
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid label type", aReader, line );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 13:09:32 +00:00
|
|
|
int thickness = 0;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2018-09-03 17:51:17 +00:00
|
|
|
// The following tokens do not exist in version 1 schematic files,
|
|
|
|
// and not always in version 2 for HLabels and GLabels
|
2016-07-07 13:09:32 +00:00
|
|
|
if( m_version > 1 )
|
|
|
|
{
|
2018-09-03 17:51:17 +00:00
|
|
|
if( m_version > 2 || *line >= ' ' )
|
|
|
|
{
|
|
|
|
if( strCompare( "Italic", line, &line ) )
|
|
|
|
text->SetItalic( true );
|
|
|
|
else if( !strCompare( "~", line, &line ) )
|
|
|
|
SCH_PARSE_ERROR( _( "expected 'Italics' or '~'" ), aReader, line );
|
|
|
|
}
|
2016-07-07 13:09:32 +00:00
|
|
|
|
|
|
|
// The thickness token does not exist in older versions of the schematic file format
|
2016-11-02 18:47:38 +00:00
|
|
|
// so calling parseInt will be made only if the EOL is not reached.
|
|
|
|
if( *line >= ' ' )
|
|
|
|
thickness = parseInt( aReader, line, &line );
|
2016-07-07 13:09:32 +00:00
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
text->SetBold( thickness != 0 );
|
|
|
|
text->SetThickness( thickness != 0 ? GetPenSizeForBold( size ) : 0 );
|
|
|
|
|
|
|
|
// Read the text string for the text.
|
|
|
|
char* tmp = aReader.ReadLine();
|
|
|
|
|
|
|
|
tmp = strtok( tmp, "\r\n" );
|
|
|
|
wxString val = FROM_UTF8( tmp );
|
|
|
|
|
|
|
|
for( ; ; )
|
|
|
|
{
|
|
|
|
int i = val.find( wxT( "\\n" ) );
|
|
|
|
|
|
|
|
if( i == wxNOT_FOUND )
|
|
|
|
break;
|
|
|
|
|
|
|
|
val.erase( i, 2 );
|
|
|
|
val.insert( i, wxT( "\n" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
text->SetText( val );
|
|
|
|
|
|
|
|
return text.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( LINE_READER& aReader )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-07-06 13:52:47 +00:00
|
|
|
wxCHECK( strCompare( "$Comp", line, &line ), NULL );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
std::unique_ptr< SCH_COMPONENT > component( new SCH_COMPONENT() );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
|
|
|
|
while( line != NULL )
|
|
|
|
{
|
|
|
|
if( strCompare( "L", line, &line ) )
|
|
|
|
{
|
|
|
|
wxString libName;
|
2018-12-06 17:44:13 +00:00
|
|
|
size_t pos = 2; // "X" plus ' ' space character.
|
|
|
|
wxString utf8Line = wxString::FromUTF8( line );
|
|
|
|
wxStringTokenizer tokens( utf8Line, " \r\n\t" );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2018-12-06 17:44:13 +00:00
|
|
|
if( tokens.CountTokens() < 2 )
|
|
|
|
THROW_PARSE_ERROR( "invalid symbol library definition", aReader.GetSource(),
|
|
|
|
aReader.Line(), aReader.LineNumber(), pos );
|
|
|
|
|
|
|
|
libName = tokens.GetNextToken();
|
2016-07-06 09:22:56 +00:00
|
|
|
libName.Replace( "~", " " );
|
2017-01-31 01:31:19 +00:00
|
|
|
|
2017-09-01 20:42:20 +00:00
|
|
|
LIB_ID libId;
|
|
|
|
|
2017-11-23 15:52:28 +00:00
|
|
|
// Prior to schematic version 4, library IDs did not have a library nickname so
|
|
|
|
// parsing the symbol name with LIB_ID::Parse() would break symbol library links
|
|
|
|
// that contained '/' and ':' characters.
|
|
|
|
if( m_version > 3 )
|
2018-07-26 14:38:30 +00:00
|
|
|
libId.Parse( libName, LIB_ID::ID_SCH, true );
|
2017-11-23 15:52:28 +00:00
|
|
|
else
|
|
|
|
libId.SetLibItemName( libName, false );
|
2017-01-31 01:31:19 +00:00
|
|
|
|
|
|
|
component->SetLibId( libId );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2018-12-06 17:44:13 +00:00
|
|
|
wxString refDesignator = tokens.GetNextToken();
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
refDesignator.Replace( "~", " " );
|
|
|
|
|
|
|
|
wxString prefix = refDesignator;
|
|
|
|
|
|
|
|
while( prefix.Length() )
|
|
|
|
{
|
|
|
|
if( ( prefix.Last() < '0' || prefix.Last() > '9') && prefix.Last() != '?' )
|
|
|
|
break;
|
|
|
|
|
|
|
|
prefix.RemoveLast();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid a prefix containing trailing/leading spaces
|
|
|
|
prefix.Trim( true );
|
|
|
|
prefix.Trim( false );
|
|
|
|
|
|
|
|
if( prefix.IsEmpty() )
|
|
|
|
component->SetPrefix( wxString( "U" ) );
|
|
|
|
else
|
|
|
|
component->SetPrefix( prefix );
|
|
|
|
}
|
|
|
|
else if( strCompare( "U", line, &line ) )
|
|
|
|
{
|
2017-03-30 19:44:47 +00:00
|
|
|
// This fixes a potentially buggy files caused by unit being set to zero which
|
|
|
|
// causes netlist issues. See https://bugs.launchpad.net/kicad/+bug/1677282.
|
|
|
|
int unit = parseInt( aReader, line, &line );
|
|
|
|
|
|
|
|
if( unit == 0 )
|
|
|
|
{
|
|
|
|
unit = 1;
|
|
|
|
|
|
|
|
// Set the file as modified so the user can be warned.
|
|
|
|
if( m_rootSheet && m_rootSheet->GetScreen() )
|
|
|
|
m_rootSheet->GetScreen()->SetModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
component->SetUnit( unit );
|
2019-03-23 22:51:13 +00:00
|
|
|
|
|
|
|
// Same can also happen with the convert parameter
|
|
|
|
int convert = parseInt( aReader, line, &line );
|
|
|
|
|
|
|
|
if( convert == 0 )
|
|
|
|
{
|
|
|
|
convert = 1;
|
|
|
|
|
|
|
|
// Set the file as modified so the user can be warned.
|
|
|
|
if( m_rootSheet && m_rootSheet->GetScreen() )
|
|
|
|
m_rootSheet->GetScreen()->SetModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
component->SetConvert( convert );
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
wxString text;
|
|
|
|
parseUnquotedString( text, aReader, line, &line );
|
2020-03-04 02:02:22 +00:00
|
|
|
|
|
|
|
if( text != "00000000" )
|
|
|
|
const_cast<KIID&>( component->m_Uuid ) = KIID( text );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
else if( strCompare( "P", line, &line ) )
|
|
|
|
{
|
|
|
|
wxPoint pos;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
component->SetPosition( pos );
|
|
|
|
}
|
|
|
|
else if( strCompare( "AR", line, &line ) )
|
|
|
|
{
|
|
|
|
const char* strCompare = "Path=";
|
|
|
|
int len = strlen( strCompare );
|
|
|
|
|
2016-08-16 08:27:09 +00:00
|
|
|
if( strncasecmp( strCompare, line, len ) != 0 )
|
2016-07-06 09:22:56 +00:00
|
|
|
SCH_PARSE_ERROR( "missing 'Path=' token", aReader, line );
|
|
|
|
|
|
|
|
line += len;
|
2020-02-22 21:39:59 +00:00
|
|
|
wxString pathStr, reference, unit;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2020-02-22 21:39:59 +00:00
|
|
|
parseQuotedString( pathStr, aReader, line, &line );
|
|
|
|
|
|
|
|
// Note: AR path excludes root sheet, but includes component. Normalize to
|
|
|
|
// internal format by shifting everything down one and adding the root sheet.
|
|
|
|
KIID_PATH path( pathStr );
|
|
|
|
|
|
|
|
if( path.size() > 0 )
|
|
|
|
{
|
|
|
|
for( size_t i = path.size() - 1; i > 0; --i )
|
|
|
|
path[i] = path[i-1];
|
|
|
|
|
|
|
|
path[0] = m_rootSheet->m_Uuid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
path.push_back( m_rootSheet->m_Uuid );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
strCompare = "Ref=";
|
|
|
|
len = strlen( strCompare );
|
|
|
|
|
2016-08-16 08:27:09 +00:00
|
|
|
if( strncasecmp( strCompare, line, len ) != 0 )
|
2016-07-06 09:22:56 +00:00
|
|
|
SCH_PARSE_ERROR( "missing 'Ref=' token", aReader, line );
|
|
|
|
|
|
|
|
line+= len;
|
|
|
|
parseQuotedString( reference, aReader, line, &line );
|
|
|
|
|
|
|
|
strCompare = "Part=";
|
|
|
|
len = strlen( strCompare );
|
|
|
|
|
2016-08-16 08:27:09 +00:00
|
|
|
if( strncasecmp( strCompare, line, len ) != 0 )
|
2016-07-06 09:22:56 +00:00
|
|
|
SCH_PARSE_ERROR( "missing 'Part=' token", aReader, line );
|
|
|
|
|
|
|
|
line+= len;
|
|
|
|
parseQuotedString( unit, aReader, line, &line );
|
|
|
|
|
|
|
|
long tmp;
|
|
|
|
|
|
|
|
if( !unit.ToLong( &tmp, 10 ) )
|
|
|
|
SCH_PARSE_ERROR( "expected integer value", aReader, line );
|
|
|
|
|
2017-05-31 08:20:49 +00:00
|
|
|
if( tmp < 0 || tmp > MAX_UNIT_COUNT_PER_PACKAGE )
|
2016-07-06 09:22:56 +00:00
|
|
|
SCH_PARSE_ERROR( "unit value out of range", aReader, line );
|
|
|
|
|
|
|
|
component->AddHierarchicalReference( path, reference, (int)tmp );
|
|
|
|
component->GetField( REFERENCE )->SetText( reference );
|
|
|
|
|
|
|
|
}
|
|
|
|
else if( strCompare( "F", line, &line ) )
|
|
|
|
{
|
|
|
|
int index = parseInt( aReader, line, &line );
|
|
|
|
|
2016-07-07 13:09:32 +00:00
|
|
|
wxString text, name;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
parseQuotedString( text, aReader, line, &line, true );
|
|
|
|
|
|
|
|
char orientation = parseChar( aReader, line, &line );
|
|
|
|
wxPoint pos;
|
2019-12-30 18:28:00 +00:00
|
|
|
pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
int size = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
int attributes = parseHex( aReader, line, &line );
|
|
|
|
|
|
|
|
if( index >= component->GetFieldCount() )
|
|
|
|
{
|
|
|
|
// The first MANDATOR_FIELDS _must_ be constructed within
|
|
|
|
// the SCH_COMPONENT constructor. This assert is simply here
|
|
|
|
// to guard against a change in that constructor.
|
|
|
|
wxASSERT( component->GetFieldCount() >= MANDATORY_FIELDS );
|
|
|
|
|
|
|
|
// Ignore the _supplied_ fieldNdx. It is not important anymore
|
|
|
|
// if within the user defined fields region (i.e. >= MANDATORY_FIELDS).
|
|
|
|
// We freely renumber the index to fit the next available field slot.
|
|
|
|
index = component->GetFieldCount(); // new has this index after insertion
|
|
|
|
|
|
|
|
SCH_FIELD field( wxPoint( 0, 0 ), -1, component.get(), name );
|
|
|
|
component->AddField( field );
|
|
|
|
}
|
2016-07-07 13:09:32 +00:00
|
|
|
|
|
|
|
// Prior to version 2 of the schematic file format, none of the following existed.
|
|
|
|
if( m_version > 1 )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2016-07-07 13:09:32 +00:00
|
|
|
wxString textAttrs;
|
|
|
|
char hjustify = parseChar( aReader, line, &line );
|
|
|
|
|
|
|
|
parseUnquotedString( textAttrs, aReader, line, &line );
|
|
|
|
|
|
|
|
// The name of the field is optional.
|
|
|
|
parseQuotedString( name, aReader, line, &line, true );
|
|
|
|
|
|
|
|
if( hjustify == 'L' )
|
|
|
|
component->GetField( index )->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
else if( hjustify == 'R' )
|
|
|
|
component->GetField( index )->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
else if( hjustify != 'C' )
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "component field text horizontal justification must be "
|
|
|
|
"L, R, or C", aReader, line );
|
2016-07-07 13:09:32 +00:00
|
|
|
|
|
|
|
// We are guaranteed to have a least one character here for older file formats
|
|
|
|
// otherwise an exception would have been raised..
|
|
|
|
if( textAttrs[0] == 'T' )
|
|
|
|
component->GetField( index )->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
else if( textAttrs[0] == 'B' )
|
|
|
|
component->GetField( index )->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
else if( textAttrs[0] != 'C' )
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "component field text vertical justification must be "
|
|
|
|
"B, T, or C", aReader, line );
|
2016-07-07 13:09:32 +00:00
|
|
|
|
|
|
|
// Newer file formats include the bold and italics text attribute.
|
2016-12-29 18:38:31 +00:00
|
|
|
if( textAttrs.Length() > 1 )
|
|
|
|
{
|
|
|
|
if( textAttrs.Length() != 3 )
|
|
|
|
SCH_PARSE_ERROR( _( "component field text attributes must be 3 characters wide" ),
|
|
|
|
aReader, line );
|
|
|
|
|
|
|
|
if( textAttrs[1] == 'I' )
|
|
|
|
component->GetField( index )->SetItalic( true );
|
|
|
|
else if( textAttrs[1] != 'N' )
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "component field text italics indicator must be I or N",
|
2016-12-29 18:38:31 +00:00
|
|
|
aReader, line );
|
|
|
|
|
|
|
|
if( textAttrs[2] == 'B' )
|
|
|
|
component->GetField( index )->SetBold( true );
|
|
|
|
else if( textAttrs[2] != 'N' )
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "component field text bold indicator must be B or N",
|
2016-12-29 18:38:31 +00:00
|
|
|
aReader, line );
|
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
component->GetField( index )->SetText( text );
|
2017-01-23 20:30:11 +00:00
|
|
|
component->GetField( index )->SetTextPos( pos );
|
|
|
|
component->GetField( index )->SetVisible( !attributes );
|
|
|
|
component->GetField( index )->SetTextSize( wxSize( size, size ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
if( orientation == 'H' )
|
2017-01-23 20:30:11 +00:00
|
|
|
component->GetField( index )->SetTextAngle( TEXT_ANGLE_HORIZ );
|
2016-07-06 09:22:56 +00:00
|
|
|
else if( orientation == 'V' )
|
2017-01-23 20:30:11 +00:00
|
|
|
component->GetField( index )->SetTextAngle( TEXT_ANGLE_VERT );
|
2016-07-06 09:22:56 +00:00
|
|
|
else
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "component field orientation must be H or V",
|
2016-07-06 09:22:56 +00:00
|
|
|
aReader, line );
|
|
|
|
|
2016-07-07 13:09:32 +00:00
|
|
|
if( name.IsEmpty() )
|
|
|
|
name = TEMPLATE_FIELDNAME::GetDefaultFieldName( index );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2016-07-07 13:09:32 +00:00
|
|
|
component->GetField( index )->SetName( name );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
else if( strCompare( "$EndComp", line ) )
|
2016-08-01 07:11:31 +00:00
|
|
|
{
|
|
|
|
// Ensure all flags (some are set by previous initializations) are reset:
|
|
|
|
component->ClearFlags();
|
2016-07-06 09:22:56 +00:00
|
|
|
return component.release();
|
2016-08-01 07:11:31 +00:00
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// There are two lines that begin with a tab or spaces that includes a line with the
|
|
|
|
// redundant position information and the transform matrix settings.
|
|
|
|
|
|
|
|
// Parse the redundant position information just the same to check for formatting
|
|
|
|
// errors.
|
|
|
|
parseInt( aReader, line, &line ); // Always 1.
|
|
|
|
parseInt( aReader, line, &line ); // The X coordinate.
|
|
|
|
parseInt( aReader, line, &line ); // The Y coordinate.
|
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
|
|
|
|
TRANSFORM transform;
|
|
|
|
|
|
|
|
transform.x1 = parseInt( aReader, line, &line );
|
|
|
|
|
|
|
|
if( transform.x1 < -1 || transform.x1 > 1 )
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid component X1 transform value", aReader, line );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
transform.y1 = parseInt( aReader, line, &line );
|
|
|
|
|
|
|
|
if( transform.y1 < -1 || transform.y1 > 1 )
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid component Y1 transform value", aReader, line );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
transform.x2 = parseInt( aReader, line, &line );
|
|
|
|
|
|
|
|
if( transform.x2 < -1 || transform.x2 > 1 )
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid component X2 transform value", aReader, line );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
transform.y2 = parseInt( aReader, line, &line );
|
|
|
|
|
|
|
|
if( transform.y2 < -1 || transform.y2 > 1 )
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid component Y2 transform value", aReader, line );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
component->SetTransform( transform );
|
|
|
|
}
|
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_PARSE_ERROR( "invalid component line", aReader, line );
|
|
|
|
|
|
|
|
return NULL; // Prevents compiler warning. Should never get here.
|
|
|
|
}
|
2016-07-11 19:48:46 +00:00
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
std::shared_ptr<BUS_ALIAS> SCH_LEGACY_PLUGIN::loadBusAlias( LINE_READER& aReader,
|
|
|
|
SCH_SCREEN* aScreen )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
auto busAlias = std::make_shared< BUS_ALIAS >( aScreen );
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
|
|
|
wxCHECK( strCompare( "BusAlias", line, &line ), NULL );
|
|
|
|
|
|
|
|
wxString buf;
|
|
|
|
parseUnquotedString( buf, aReader, line, &line );
|
|
|
|
busAlias->SetName( buf );
|
|
|
|
|
|
|
|
while( *line != '\0' )
|
|
|
|
{
|
|
|
|
buf.clear();
|
|
|
|
parseUnquotedString( buf, aReader, line, &line, true );
|
|
|
|
if( buf.Len() > 0 )
|
|
|
|
{
|
|
|
|
busAlias->AddMember( buf );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return busAlias;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::Save( const wxString& aFileName, SCH_SCREEN* aScreen, KIWAY* aKiway,
|
|
|
|
const PROPERTIES* aProperties )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN object." );
|
|
|
|
wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
|
|
|
|
|
2018-04-14 14:51:58 +00:00
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
init( aKiway, aProperties );
|
|
|
|
|
|
|
|
wxFileName fn = aFileName;
|
|
|
|
|
|
|
|
// File names should be absolute. Don't assume everything relative to the project path
|
|
|
|
// works properly.
|
|
|
|
wxASSERT( fn.IsAbsolute() );
|
|
|
|
|
|
|
|
FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
|
|
|
|
|
|
|
|
m_out = &formatter; // no ownership
|
|
|
|
|
|
|
|
Format( aScreen );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::Format( SCH_SCREEN* aScreen )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN* object." );
|
|
|
|
wxCHECK_RET( m_kiway != NULL, "NULL KIWAY* object." );
|
|
|
|
|
|
|
|
// Write the header
|
|
|
|
m_out->Print( 0, "%s %s %d\n", "EESchema", SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION );
|
|
|
|
|
|
|
|
// This section is not used, but written for file compatibility
|
2017-03-13 03:19:33 +00:00
|
|
|
m_out->Print( 0, "EELAYER %d %d\n", SCH_LAYER_ID_COUNT, 0 );
|
2016-07-11 19:48:46 +00:00
|
|
|
m_out->Print( 0, "EELAYER END\n" );
|
|
|
|
|
|
|
|
/* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
|
|
|
|
* SheetNumber and Sheet Count in a complex hierarchy, but useful in
|
|
|
|
* simple hierarchy and flat hierarchy. Used also to search the root
|
|
|
|
* sheet ( ScreenNumber = 1 ) within the files
|
|
|
|
*/
|
|
|
|
const TITLE_BLOCK& tb = aScreen->GetTitleBlock();
|
|
|
|
const PAGE_INFO& page = aScreen->GetPageSettings();
|
|
|
|
|
|
|
|
m_out->Print( 0, "$Descr %s %d %d%s\n", TO_UTF8( page.GetType() ),
|
|
|
|
page.GetWidthMils(),
|
|
|
|
page.GetHeightMils(),
|
|
|
|
!page.IsCustom() && page.IsPortrait() ? " portrait" : "" );
|
|
|
|
m_out->Print( 0, "encoding utf-8\n" );
|
|
|
|
m_out->Print( 0, "Sheet %d %d\n", aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens );
|
|
|
|
m_out->Print( 0, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() );
|
|
|
|
m_out->Print( 0, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() );
|
|
|
|
m_out->Print( 0, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() );
|
|
|
|
m_out->Print( 0, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() );
|
2019-08-21 16:58:29 +00:00
|
|
|
m_out->Print( 0, "Comment1 %s\n", EscapedUTF8( tb.GetComment( 0 ) ).c_str() );
|
|
|
|
m_out->Print( 0, "Comment2 %s\n", EscapedUTF8( tb.GetComment( 1 ) ).c_str() );
|
|
|
|
m_out->Print( 0, "Comment3 %s\n", EscapedUTF8( tb.GetComment( 2 ) ).c_str() );
|
|
|
|
m_out->Print( 0, "Comment4 %s\n", EscapedUTF8( tb.GetComment( 3 ) ).c_str() );
|
|
|
|
m_out->Print( 0, "Comment5 %s\n", EscapedUTF8( tb.GetComment( 4 ) ).c_str() );
|
|
|
|
m_out->Print( 0, "Comment6 %s\n", EscapedUTF8( tb.GetComment( 5 ) ).c_str() );
|
|
|
|
m_out->Print( 0, "Comment7 %s\n", EscapedUTF8( tb.GetComment( 6 ) ).c_str() );
|
|
|
|
m_out->Print( 0, "Comment8 %s\n", EscapedUTF8( tb.GetComment( 7 ) ).c_str() );
|
|
|
|
m_out->Print( 0, "Comment9 %s\n", EscapedUTF8( tb.GetComment( 8 ) ).c_str() );
|
2016-07-11 19:48:46 +00:00
|
|
|
m_out->Print( 0, "$EndDescr\n" );
|
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& alias : aScreen->GetBusAliases() )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
saveBusAlias( alias );
|
|
|
|
}
|
|
|
|
|
2020-01-28 15:42:42 +00:00
|
|
|
// Enforce item ordering
|
|
|
|
auto cmp = []( const SCH_ITEM* a, const SCH_ITEM* b ) { return *a < *b; };
|
|
|
|
std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto item : aScreen->Items() )
|
2020-01-28 15:42:42 +00:00
|
|
|
save_map.insert( item );
|
|
|
|
|
|
|
|
|
|
|
|
for( auto& item : save_map )
|
2016-07-11 19:48:46 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_COMPONENT_T:
|
2019-06-25 23:39:58 +00:00
|
|
|
saveComponent( static_cast<SCH_COMPONENT*>( item ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
|
|
|
case SCH_BITMAP_T:
|
2019-06-25 23:39:58 +00:00
|
|
|
saveBitmap( static_cast<SCH_BITMAP*>( item ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
|
|
|
case SCH_SHEET_T:
|
2019-06-25 23:39:58 +00:00
|
|
|
saveSheet( static_cast<SCH_SHEET*>( item ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
|
|
|
case SCH_JUNCTION_T:
|
2019-06-25 23:39:58 +00:00
|
|
|
saveJunction( static_cast<SCH_JUNCTION*>( item ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
|
|
|
case SCH_NO_CONNECT_T:
|
2019-06-25 23:39:58 +00:00
|
|
|
saveNoConnect( static_cast<SCH_NO_CONNECT*>( item ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
|
|
|
case SCH_BUS_BUS_ENTRY_T:
|
2019-06-25 23:39:58 +00:00
|
|
|
saveBusEntry( static_cast<SCH_BUS_ENTRY_BASE*>( item ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
|
|
|
case SCH_LINE_T:
|
2019-06-25 23:39:58 +00:00
|
|
|
saveLine( static_cast<SCH_LINE*>( item ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
|
|
|
case SCH_TEXT_T:
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
2019-04-15 23:56:41 +00:00
|
|
|
case SCH_HIER_LABEL_T:
|
2019-06-25 23:39:58 +00:00
|
|
|
saveText( static_cast<SCH_TEXT*>( item ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "$EndSCHEMATC\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::Format( SELECTION* aSelection, OUTPUTFORMATTER* aFormatter )
|
|
|
|
{
|
|
|
|
m_out = aFormatter;
|
|
|
|
|
2019-05-11 09:12:39 +00:00
|
|
|
for( unsigned i = 0; i < aSelection->GetSize(); ++i )
|
2019-04-28 16:36:31 +00:00
|
|
|
{
|
|
|
|
SCH_ITEM* item = (SCH_ITEM*) aSelection->GetItem( i );
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_COMPONENT_T:
|
|
|
|
saveComponent( static_cast< SCH_COMPONENT* >( item ) );
|
|
|
|
break;
|
|
|
|
case SCH_BITMAP_T:
|
|
|
|
saveBitmap( static_cast< SCH_BITMAP* >( item ) );
|
|
|
|
break;
|
|
|
|
case SCH_SHEET_T:
|
|
|
|
saveSheet( static_cast< SCH_SHEET* >( item ) );
|
|
|
|
break;
|
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
saveJunction( static_cast< SCH_JUNCTION* >( item ) );
|
|
|
|
break;
|
|
|
|
case SCH_NO_CONNECT_T:
|
|
|
|
saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ) );
|
|
|
|
break;
|
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
|
|
|
case SCH_BUS_BUS_ENTRY_T:
|
|
|
|
saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ) );
|
|
|
|
break;
|
|
|
|
case SCH_LINE_T:
|
|
|
|
saveLine( static_cast< SCH_LINE* >( item ) );
|
|
|
|
break;
|
|
|
|
case SCH_TEXT_T:
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
|
|
|
saveText( static_cast< SCH_TEXT* >( item ) );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::saveComponent( SCH_COMPONENT* aComponent )
|
|
|
|
{
|
|
|
|
std::string name1;
|
|
|
|
std::string name2;
|
|
|
|
wxArrayString reference_fields;
|
|
|
|
|
|
|
|
static wxString delimiters( wxT( " " ) );
|
|
|
|
|
|
|
|
// This is redundant with the AR entries below, but it makes the files backwards-compatible.
|
2020-02-22 21:39:59 +00:00
|
|
|
if( aComponent->GetInstanceReferences().size() > 0 )
|
2016-07-11 19:48:46 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
const COMPONENT_INSTANCE_REFERENCE& instance = aComponent->GetInstanceReferences()[0];
|
|
|
|
name1 = toUTFTildaText( instance.m_Reference );
|
2016-07-11 19:48:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aComponent->GetField( REFERENCE )->GetText().IsEmpty() )
|
|
|
|
name1 = toUTFTildaText( aComponent->GetPrefix() );
|
|
|
|
else
|
|
|
|
name1 = toUTFTildaText( aComponent->GetField( REFERENCE )->GetText() );
|
|
|
|
}
|
|
|
|
|
2017-09-01 20:42:20 +00:00
|
|
|
wxString part_name = aComponent->GetLibId().Format();
|
2016-07-11 19:48:46 +00:00
|
|
|
|
|
|
|
if( part_name.size() )
|
|
|
|
{
|
|
|
|
name2 = toUTFTildaText( part_name );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name2 = "_NONAME_";
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "$Comp\n" );
|
|
|
|
m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() );
|
|
|
|
|
2020-02-20 23:40:30 +00:00
|
|
|
// Generate unit number, conversion and timestamp
|
|
|
|
m_out->Print( 0, "U %d %d %8.8X\n",
|
2020-02-20 12:11:04 +00:00
|
|
|
aComponent->GetUnit(),
|
|
|
|
aComponent->GetConvert(),
|
2020-02-20 23:40:30 +00:00
|
|
|
aComponent->m_Uuid.AsLegacyTimestamp() );
|
2016-07-11 19:48:46 +00:00
|
|
|
|
|
|
|
// Save the position
|
2019-12-30 18:28:00 +00:00
|
|
|
m_out->Print( 0, "P %d %d\n",
|
|
|
|
Iu2Mils( aComponent->GetPosition().x ),
|
|
|
|
Iu2Mils( aComponent->GetPosition().y ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
|
|
|
|
/* If this is a complex hierarchy; save hierarchical references.
|
|
|
|
* but for simple hierarchies it is not necessary.
|
|
|
|
* the reference inf is already saved
|
|
|
|
* this is useful for old Eeschema version compatibility
|
|
|
|
*/
|
2020-02-22 21:39:59 +00:00
|
|
|
if( aComponent->GetInstanceReferences().size() > 1 )
|
2016-07-11 19:48:46 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
for( const COMPONENT_INSTANCE_REFERENCE& instance : aComponent->GetInstanceReferences() )
|
2016-07-11 19:48:46 +00:00
|
|
|
{
|
|
|
|
/*format:
|
|
|
|
* AR Path="/140/2" Ref="C99" Part="1"
|
|
|
|
* where 140 is the uid of the containing sheet
|
|
|
|
* and 2 is the timestamp of this component.
|
|
|
|
* (timestamps are actually 8 hex chars)
|
|
|
|
* Ref is the conventional component reference for this 'path'
|
|
|
|
* Part is the conventional component part selection for this 'path'
|
|
|
|
*/
|
2020-02-22 21:39:59 +00:00
|
|
|
wxString path = "/";
|
2020-02-21 23:18:43 +00:00
|
|
|
|
2020-02-22 21:39:59 +00:00
|
|
|
// Skip root sheet
|
2020-02-25 15:21:50 +00:00
|
|
|
for( int i = 1; i < (int) instance.m_Path.size(); ++i )
|
2020-02-22 21:39:59 +00:00
|
|
|
path += instance.m_Path[i].AsLegacyTimestampString() + "/";
|
2020-02-21 23:18:43 +00:00
|
|
|
|
2020-02-22 21:39:59 +00:00
|
|
|
m_out->Print( 0, "AR Path=\"%s\" Ref=\"%s\" Part=\"%d\" \n",
|
|
|
|
TO_UTF8( path + aComponent->m_Uuid.AsLegacyTimestampString() ),
|
|
|
|
TO_UTF8( instance.m_Reference ),
|
|
|
|
instance.m_Unit );
|
2016-07-11 19:48:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the ugly field index, which I would like to see go away someday soon.
|
|
|
|
for( int i = 0; i < aComponent->GetFieldCount(); ++i )
|
|
|
|
aComponent->GetField( i )->SetId( i );
|
|
|
|
|
|
|
|
// Fixed fields:
|
|
|
|
// Save mandatory fields even if they are blank,
|
2019-08-20 17:22:30 +00:00
|
|
|
// because the visibility, size and orientation are set from library editor.
|
2016-07-11 19:48:46 +00:00
|
|
|
for( unsigned i = 0; i < MANDATORY_FIELDS; ++i )
|
|
|
|
saveField( aComponent->GetField( i ) );
|
|
|
|
|
|
|
|
// 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( int i = MANDATORY_FIELDS; i < aComponent->GetFieldCount(); ++i )
|
|
|
|
saveField( aComponent->GetField( i ) );
|
|
|
|
|
|
|
|
// Unit number, position, box ( old standard )
|
2019-12-30 18:28:00 +00:00
|
|
|
m_out->Print( 0, "\t%-4d %-4d %-4d\n", aComponent->GetUnit(),
|
|
|
|
Iu2Mils( aComponent->GetPosition().x ),
|
|
|
|
Iu2Mils( aComponent->GetPosition().y ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
|
|
|
|
TRANSFORM transform = aComponent->GetTransform();
|
|
|
|
|
|
|
|
m_out->Print( 0, "\t%-4d %-4d %-4d %-4d\n",
|
|
|
|
transform.x1, transform.y1, transform.x2, transform.y2 );
|
|
|
|
m_out->Print( 0, "$EndComp\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::saveField( SCH_FIELD* aField )
|
|
|
|
{
|
|
|
|
char hjustify = 'C';
|
|
|
|
|
|
|
|
if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
|
|
|
|
hjustify = 'L';
|
|
|
|
else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
|
|
|
|
hjustify = 'R';
|
|
|
|
|
|
|
|
char vjustify = 'C';
|
|
|
|
|
|
|
|
if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
|
|
|
|
vjustify = 'B';
|
|
|
|
else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
|
|
|
|
vjustify = 'T';
|
|
|
|
|
|
|
|
m_out->Print( 0, "F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
|
|
|
|
aField->GetId(),
|
|
|
|
EscapedUTF8( aField->GetText() ).c_str(), // wraps in quotes too
|
2017-01-23 20:30:11 +00:00
|
|
|
aField->GetTextAngle() == TEXT_ANGLE_HORIZ ? 'H' : 'V',
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aField->GetLibPosition().x ),
|
|
|
|
Iu2Mils( aField->GetLibPosition().y ),
|
|
|
|
Iu2Mils( aField->GetTextWidth() ),
|
2017-01-23 20:30:11 +00:00
|
|
|
!aField->IsVisible(),
|
2016-07-11 19:48:46 +00:00
|
|
|
hjustify, vjustify,
|
|
|
|
aField->IsItalic() ? 'I' : 'N',
|
|
|
|
aField->IsBold() ? 'B' : 'N' );
|
|
|
|
|
|
|
|
// Save field name, if the name is user definable
|
|
|
|
if( aField->GetId() >= FIELD1 )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::saveBitmap( SCH_BITMAP* aBitmap )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aBitmap != NULL, "SCH_BITMAP* is NULL" );
|
|
|
|
|
2019-04-24 09:50:18 +00:00
|
|
|
const wxImage* image = aBitmap->GetImage()->GetImageData();
|
2016-07-11 19:48:46 +00:00
|
|
|
|
|
|
|
wxCHECK_RET( image != NULL, "wxImage* is NULL" );
|
|
|
|
|
|
|
|
m_out->Print( 0, "$Bitmap\n" );
|
2019-12-30 18:28:00 +00:00
|
|
|
m_out->Print( 0, "Pos %-4d %-4d\n",
|
|
|
|
Iu2Mils( aBitmap->GetPosition().x ),
|
|
|
|
Iu2Mils( aBitmap->GetPosition().y ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
m_out->Print( 0, "Scale %f\n", aBitmap->GetImage()->GetScale() );
|
|
|
|
m_out->Print( 0, "Data\n" );
|
|
|
|
|
|
|
|
wxMemoryOutputStream stream;
|
|
|
|
|
|
|
|
image->SaveFile( stream, wxBITMAP_TYPE_PNG );
|
|
|
|
|
|
|
|
// Write binary data in hexadecimal form (ASCII)
|
|
|
|
wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
|
|
|
|
char* begin = (char*) buffer->GetBufferStart();
|
|
|
|
|
2016-11-09 08:46:35 +00:00
|
|
|
for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
|
2016-07-11 19:48:46 +00:00
|
|
|
{
|
|
|
|
if( ii >= 32 )
|
|
|
|
{
|
|
|
|
ii = 0;
|
|
|
|
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "%2.2X ", *begin & 0xFF );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "\nEndData\n" );
|
|
|
|
m_out->Print( 0, "$EndBitmap\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::saveSheet( SCH_SHEET* aSheet )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aSheet != NULL, "SCH_SHEET* is NULL" );
|
|
|
|
|
|
|
|
m_out->Print( 0, "$Sheet\n" );
|
2017-01-23 20:30:11 +00:00
|
|
|
m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n",
|
2020-02-20 12:11:04 +00:00
|
|
|
Iu2Mils( aSheet->GetPosition().x ),
|
|
|
|
Iu2Mils( aSheet->GetPosition().y ),
|
|
|
|
Iu2Mils( aSheet->GetSize().x ),
|
|
|
|
Iu2Mils( aSheet->GetSize().y ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2020-02-20 23:40:30 +00:00
|
|
|
m_out->Print( 0, "U %8.8X\n", aSheet->m_Uuid.AsLegacyTimestamp() );
|
2016-07-11 19:48:46 +00:00
|
|
|
|
|
|
|
if( !aSheet->GetName().IsEmpty() )
|
2020-02-20 23:40:30 +00:00
|
|
|
m_out->Print( 0, "F0 %s %d\n",
|
2020-02-20 12:11:04 +00:00
|
|
|
EscapedUTF8( aSheet->GetName() ).c_str(),
|
2020-02-20 23:40:30 +00:00
|
|
|
Iu2Mils( aSheet->GetSheetNameSize() ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
|
|
|
|
if( !aSheet->GetFileName().IsEmpty() )
|
2020-02-20 23:40:30 +00:00
|
|
|
m_out->Print( 0, "F1 %s %d\n",
|
2020-02-20 12:11:04 +00:00
|
|
|
EscapedUTF8( aSheet->GetFileName() ).c_str(),
|
2020-02-20 23:40:30 +00:00
|
|
|
Iu2Mils( aSheet->GetFileNameSize() ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2020-01-12 18:40:50 +00:00
|
|
|
for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
|
2016-07-11 19:48:46 +00:00
|
|
|
{
|
|
|
|
int type, side;
|
|
|
|
|
2020-01-12 18:40:50 +00:00
|
|
|
if( pin->GetText().IsEmpty() )
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-12 18:40:50 +00:00
|
|
|
switch( pin->GetEdge() )
|
2016-07-11 19:48:46 +00:00
|
|
|
{
|
|
|
|
default:
|
2019-05-17 16:45:27 +00:00
|
|
|
case SHEET_LEFT_SIDE: side = 'L'; break;
|
|
|
|
case SHEET_RIGHT_SIDE: side = 'R'; break;
|
|
|
|
case SHEET_TOP_SIDE: side = 'T'; break;
|
|
|
|
case SHEET_BOTTOM_SIDE: side = 'B'; break;
|
2016-07-11 19:48:46 +00:00
|
|
|
}
|
|
|
|
|
2020-01-12 18:40:50 +00:00
|
|
|
switch( pin->GetShape() )
|
2016-07-11 19:48:46 +00:00
|
|
|
{
|
|
|
|
default:
|
2020-02-20 12:11:04 +00:00
|
|
|
case PINSHEETLABEL_SHAPE::PS_UNSPECIFIED: type = 'U'; break;
|
|
|
|
case PINSHEETLABEL_SHAPE::PS_INPUT: type = 'I'; break;
|
|
|
|
case PINSHEETLABEL_SHAPE::PS_OUTPUT: type = 'O'; break;
|
|
|
|
case PINSHEETLABEL_SHAPE::PS_BIDI: type = 'B'; break;
|
|
|
|
case PINSHEETLABEL_SHAPE::PS_TRISTATE: type = 'T'; break;
|
2016-07-11 19:48:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n",
|
|
|
|
pin->GetNumber(),
|
2020-01-12 18:40:50 +00:00
|
|
|
EscapedUTF8( pin->GetText() ).c_str(), // supplies wrapping quotes
|
|
|
|
type, side, Iu2Mils( pin->GetPosition().x ),
|
|
|
|
Iu2Mils( pin->GetPosition().y ),
|
|
|
|
Iu2Mils( pin->GetTextWidth() ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "$EndSheet\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::saveJunction( SCH_JUNCTION* aJunction )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aJunction != NULL, "SCH_JUNCTION* is NULL" );
|
|
|
|
|
|
|
|
m_out->Print( 0, "Connection ~ %-4d %-4d\n",
|
2020-02-20 12:11:04 +00:00
|
|
|
Iu2Mils( aJunction->GetPosition().x ),
|
|
|
|
Iu2Mils( aJunction->GetPosition().y ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::saveNoConnect( SCH_NO_CONNECT* aNoConnect )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aNoConnect != NULL, "SCH_NOCONNECT* is NULL" );
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
m_out->Print( 0, "NoConn ~ %-4d %-4d\n",
|
|
|
|
Iu2Mils( aNoConnect->GetPosition().x ),
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aNoConnect->GetPosition().y ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aBusEntry != NULL, "SCH_BUS_ENTRY_BASE* is NULL" );
|
|
|
|
|
|
|
|
if( aBusEntry->GetLayer() == LAYER_WIRE )
|
|
|
|
m_out->Print( 0, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aBusEntry->GetPosition().x ),
|
|
|
|
Iu2Mils( aBusEntry->GetPosition().y ),
|
|
|
|
Iu2Mils( aBusEntry->m_End().x ), Iu2Mils( aBusEntry->m_End().y ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
else
|
|
|
|
m_out->Print( 0, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aBusEntry->GetPosition().x ),
|
|
|
|
Iu2Mils( aBusEntry->GetPosition().y ),
|
|
|
|
Iu2Mils( aBusEntry->m_End().x ), Iu2Mils( aBusEntry->m_End().y ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::saveLine( SCH_LINE* aLine )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aLine != NULL, "SCH_LINE* is NULL" );
|
|
|
|
|
|
|
|
const char* layer = "Notes";
|
|
|
|
const char* width = "Line";
|
|
|
|
|
|
|
|
if( aLine->GetLayer() == LAYER_WIRE )
|
|
|
|
layer = "Wire";
|
|
|
|
else if( aLine->GetLayer() == LAYER_BUS )
|
|
|
|
layer = "Bus";
|
|
|
|
|
2017-11-15 13:08:27 +00:00
|
|
|
m_out->Print( 0, "Wire %s %s", layer, width );
|
|
|
|
|
|
|
|
// Write line style (width, type, color) only for non default values
|
2019-12-26 15:15:34 +00:00
|
|
|
if( aLine->IsGraphicLine() )
|
2017-11-15 13:08:27 +00:00
|
|
|
{
|
|
|
|
if( aLine->GetPenSize() != aLine->GetDefaultWidth() )
|
2019-12-30 18:28:00 +00:00
|
|
|
m_out->Print( 0, " %s %d", T_WIDTH, Iu2Mils( aLine->GetLineSize() ) );
|
2017-11-15 13:08:27 +00:00
|
|
|
|
|
|
|
if( aLine->GetLineStyle() != aLine->GetDefaultStyle() )
|
2019-12-30 18:28:00 +00:00
|
|
|
m_out->Print( 0, " %s %s", T_STYLE,
|
|
|
|
SCH_LINE::GetLineStyleName( aLine->GetLineStyle() ) );
|
2017-11-15 13:08:27 +00:00
|
|
|
|
2020-02-03 16:46:58 +00:00
|
|
|
if( aLine->GetLineColor() != COLOR4D::UNSPECIFIED )
|
2017-11-15 13:08:27 +00:00
|
|
|
m_out->Print( 0, " %s",
|
|
|
|
TO_UTF8( aLine->GetLineColor().ToColour().GetAsString( wxC2S_CSS_SYNTAX ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
|
|
|
|
m_out->Print( 0, "\t%-4d %-4d %-4d %-4d",
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aLine->GetStartPoint().x ), Iu2Mils( aLine->GetStartPoint().y ),
|
|
|
|
Iu2Mils( aLine->GetEndPoint().x ), Iu2Mils( aLine->GetEndPoint().y ) );
|
2017-10-31 16:33:37 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, "\n");
|
2016-07-11 19:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::saveText( SCH_TEXT* aText )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aText != NULL, "SCH_TEXT* is NULL" );
|
|
|
|
|
|
|
|
const char* italics = "~";
|
|
|
|
const char* textType = "Notes";
|
|
|
|
|
|
|
|
if( aText->IsItalic() )
|
|
|
|
italics = "Italic";
|
|
|
|
|
|
|
|
wxString text = aText->GetText();
|
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
SCH_LAYER_ID layer = aText->GetLayer();
|
2016-07-11 19:48:46 +00:00
|
|
|
|
|
|
|
if( layer == LAYER_NOTES || layer == LAYER_LOCLABEL )
|
|
|
|
{
|
|
|
|
if( layer == LAYER_NOTES )
|
|
|
|
{
|
|
|
|
// For compatibility reasons, the text must be saved in only one text line
|
|
|
|
// so replace all EOLs with \\n
|
|
|
|
text.Replace( wxT( "\n" ), wxT( "\\n" ) );
|
|
|
|
|
|
|
|
// Here we should have no CR or LF character in line
|
|
|
|
// This is not always the case if a multiline text was copied (using a copy/paste
|
|
|
|
// function) from a text that uses E.O.L characters that differs from the current
|
|
|
|
// EOL format. This is mainly the case under Linux using LF symbol when copying
|
|
|
|
// a text from Windows (using CRLF symbol) so we must just remove the extra CR left
|
|
|
|
// (or LF left under MacOSX)
|
|
|
|
for( unsigned ii = 0; ii < text.Len(); )
|
|
|
|
{
|
|
|
|
if( text[ii] == 0x0A || text[ii] == 0x0D )
|
|
|
|
text.erase( ii, 1 );
|
|
|
|
else
|
|
|
|
ii++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
textType = "Label";
|
|
|
|
}
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
// Local labels must have their spin style inverted for left and right
|
|
|
|
int spinStyle = static_cast<int>( aText->GetLabelSpinStyle() );
|
|
|
|
|
|
|
|
if( spinStyle == 0 )
|
|
|
|
spinStyle = 2;
|
|
|
|
else if( spinStyle == 2 )
|
|
|
|
spinStyle = 0;
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aText->GetPosition().x ), Iu2Mils( aText->GetPosition().y ),
|
2020-01-08 19:07:55 +00:00
|
|
|
spinStyle,
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aText->GetTextWidth() ),
|
|
|
|
italics, Iu2Mils( aText->GetThickness() ), TO_UTF8( text ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
}
|
|
|
|
else if( layer == LAYER_GLOBLABEL || layer == LAYER_HIERLABEL )
|
|
|
|
{
|
|
|
|
textType = ( layer == LAYER_GLOBLABEL ) ? "GLabel" : "HLabel";
|
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
auto shapeLabelIt = sheetLabelNames.find( aText->GetShape() );
|
|
|
|
wxCHECK_RET( shapeLabelIt != sheetLabelNames.end(), "Shape not found in names list" );
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aText->GetPosition().x ), Iu2Mils( aText->GetPosition().y ),
|
2020-01-08 19:07:55 +00:00
|
|
|
static_cast<int>( aText->GetLabelSpinStyle() ),
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aText->GetTextWidth() ),
|
2020-01-08 19:07:55 +00:00
|
|
|
shapeLabelIt->second,
|
2017-01-23 20:30:11 +00:00
|
|
|
italics,
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aText->GetThickness() ), TO_UTF8( text ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( aAlias != NULL, "BUS_ALIAS* is NULL" );
|
|
|
|
|
|
|
|
wxString members = boost::algorithm::join( aAlias->Members(), " " );
|
|
|
|
|
|
|
|
m_out->Print( 0, "BusAlias %s %s\n",
|
|
|
|
TO_UTF8( aAlias->GetName() ), TO_UTF8( members ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-22 00:48:25 +00:00
|
|
|
int SCH_LEGACY_PLUGIN_CACHE::m_modHash = 1; // starts at 1 and goes up
|
|
|
|
|
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN_CACHE( const wxString& aFullPathAndFileName ) :
|
2018-01-25 00:37:07 +00:00
|
|
|
m_fileName( aFullPathAndFileName ),
|
2016-08-18 23:23:10 +00:00
|
|
|
m_libFileName( aFullPathAndFileName ),
|
2016-09-17 17:31:58 +00:00
|
|
|
m_isWritable( true ),
|
2017-10-22 00:48:25 +00:00
|
|
|
m_isModified( false )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
m_versionMajor = -1;
|
|
|
|
m_versionMinor = -1;
|
2016-12-30 11:39:41 +00:00
|
|
|
m_libType = LIBRARY_TYPE_EESCHEMA;
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_LEGACY_PLUGIN_CACHE::~SCH_LEGACY_PLUGIN_CACHE()
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
std::vector< LIB_PART* > rootParts;
|
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
// When the cache is destroyed, all of the alias objects on the heap should be deleted.
|
2019-11-06 19:15:42 +00:00
|
|
|
for( LIB_PART_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); ++it )
|
|
|
|
delete it->second;
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
m_symbols.clear();
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-23 22:49:07 +00:00
|
|
|
// If m_libFileName is a symlink follow it to the real source file
|
|
|
|
wxFileName SCH_LEGACY_PLUGIN_CACHE::GetRealFile() const
|
|
|
|
{
|
|
|
|
wxFileName fn( m_libFileName );
|
|
|
|
|
2018-07-24 07:52:33 +00:00
|
|
|
#ifndef __WINDOWS__
|
2018-07-23 22:49:07 +00:00
|
|
|
if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
|
|
|
|
{
|
|
|
|
char buffer[ PATH_MAX + 1 ];
|
|
|
|
ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
|
|
|
|
|
|
|
|
if( pathLen > 0 )
|
|
|
|
{
|
|
|
|
buffer[ pathLen ] = '\0';
|
|
|
|
fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
|
|
|
|
fn.Normalize();
|
|
|
|
}
|
|
|
|
}
|
2018-07-24 07:52:33 +00:00
|
|
|
#endif
|
2018-07-23 22:49:07 +00:00
|
|
|
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
wxDateTime SCH_LEGACY_PLUGIN_CACHE::GetLibModificationTime()
|
|
|
|
{
|
2018-07-23 22:49:07 +00:00
|
|
|
wxFileName fn = GetRealFile();
|
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
// update the writable flag while we have a wxFileName, in a network this
|
|
|
|
// is possibly quite dynamic anyway.
|
2018-07-23 22:49:07 +00:00
|
|
|
m_isWritable = fn.IsFileWritable();
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-07-23 22:49:07 +00:00
|
|
|
return fn.GetModificationTime();
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_LEGACY_PLUGIN_CACHE::IsFile( const wxString& aFullPathAndFileName ) const
|
|
|
|
{
|
2018-01-25 00:37:07 +00:00
|
|
|
return m_fileName == aFullPathAndFileName;
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_LEGACY_PLUGIN_CACHE::IsFileChanged() const
|
|
|
|
{
|
2018-07-23 22:49:07 +00:00
|
|
|
wxFileName fn = GetRealFile();
|
|
|
|
|
|
|
|
if( m_fileModTime.IsValid() && fn.IsOk() && fn.FileExists() )
|
|
|
|
return fn.GetModificationTime() != m_fileModTime;
|
2017-02-13 18:47:18 +00:00
|
|
|
|
|
|
|
return false;
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART* SCH_LEGACY_PLUGIN_CACHE::removeSymbol( LIB_PART* aPart )
|
2016-09-17 17:31:58 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
wxCHECK_MSG( aPart != NULL, NULL, "NULL pointer cannot be removed from library." );
|
2016-09-17 17:31:58 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART* firstChild = NULL;
|
|
|
|
LIB_PART_MAP::iterator it = m_symbols.find( aPart->GetName() );
|
2016-09-17 17:31:58 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( it == m_symbols.end() )
|
2016-09-17 17:31:58 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// If the entry pointer doesn't match the name it is mapped to in the library, we
|
|
|
|
// have done something terribly wrong.
|
2019-11-06 19:15:42 +00:00
|
|
|
wxCHECK_MSG( *it->second == aPart, NULL,
|
|
|
|
"Pointer mismatch while attempting to remove alias entry <" + aPart->GetName() +
|
2016-09-17 17:31:58 +00:00
|
|
|
"> from library cache <" + m_libFileName.GetName() + ">." );
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
// If the symbol is a root symbol used by other symbols find the first alias that uses
|
|
|
|
// the root part and make it the new root.
|
|
|
|
if( aPart->IsRoot() )
|
2016-09-17 17:31:58 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
for( auto entry : m_symbols )
|
|
|
|
{
|
|
|
|
if( entry.second->IsAlias()
|
|
|
|
&& entry.second->GetParent().lock() == aPart->SharedPtr() )
|
|
|
|
{
|
|
|
|
firstChild = entry.second;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-17 17:31:58 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( firstChild )
|
2016-09-17 17:31:58 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
for( LIB_ITEM& drawItem : aPart->GetDrawItems() )
|
|
|
|
{
|
|
|
|
if( drawItem.Type() == LIB_FIELD_T )
|
|
|
|
{
|
|
|
|
LIB_FIELD& field = static_cast<LIB_FIELD&>( drawItem );
|
2016-09-17 17:31:58 +00:00
|
|
|
|
2020-02-16 12:51:44 +00:00
|
|
|
if( firstChild->FindField( field.GetName( NATIVE_FIELD_NAME ) ) )
|
2019-11-06 19:15:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
LIB_ITEM* newItem = (LIB_ITEM*) drawItem.Clone();
|
|
|
|
drawItem.SetParent( firstChild );
|
|
|
|
firstChild->AddDrawItem( newItem );
|
|
|
|
}
|
2016-09-17 17:31:58 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
// Reparent the remaining aliases.
|
|
|
|
for( auto entry : m_symbols )
|
|
|
|
{
|
|
|
|
if( entry.second->IsAlias()
|
|
|
|
&& entry.second->GetParent().lock() == aPart->SharedPtr() )
|
|
|
|
entry.second->SetParent( firstChild );
|
|
|
|
}
|
2016-09-17 17:31:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
m_symbols.erase( it );
|
|
|
|
delete aPart;
|
2016-09-17 17:31:58 +00:00
|
|
|
m_isModified = true;
|
|
|
|
++m_modHash;
|
2019-11-06 19:15:42 +00:00
|
|
|
return firstChild;
|
2016-09-17 17:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::AddSymbol( const LIB_PART* aPart )
|
|
|
|
{
|
2017-01-27 15:56:36 +00:00
|
|
|
// aPart is cloned in PART_LIB::AddPart(). The cache takes ownership of aPart.
|
2019-11-06 19:15:42 +00:00
|
|
|
wxString name = aPart->GetName();
|
|
|
|
LIB_PART_MAP::iterator it = m_symbols.find( name );
|
2016-09-17 17:31:58 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( it != m_symbols.end() )
|
2016-09-17 17:31:58 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
removeSymbol( it->second );
|
2016-09-17 17:31:58 +00:00
|
|
|
}
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
m_symbols[ name ] = const_cast< LIB_PART* >( aPart );
|
2016-09-17 17:31:58 +00:00
|
|
|
m_isModified = true;
|
|
|
|
++m_modHash;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::Load()
|
|
|
|
{
|
2018-09-17 17:00:19 +00:00
|
|
|
if( !m_libFileName.FileExists() )
|
|
|
|
{
|
2019-07-10 17:59:39 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Library file \"%s\" not found." ),
|
|
|
|
m_libFileName.GetFullPath() ) );
|
2018-09-17 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
wxCHECK_RET( m_libFileName.IsAbsolute(),
|
|
|
|
wxString::Format( "Cannot use relative file paths in legacy plugin to "
|
2017-12-15 11:37:46 +00:00
|
|
|
"open library \"%s\".", m_libFileName.GetFullPath() ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2017-12-15 11:37:46 +00:00
|
|
|
wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file \"%s\"",
|
2017-02-16 01:28:36 +00:00
|
|
|
m_libFileName.GetFullPath() );
|
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
FILE_LINE_READER reader( m_libFileName.GetFullPath() );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
if( !reader.ReadLine() )
|
|
|
|
THROW_IO_ERROR( _( "unexpected end of file" ) );
|
|
|
|
|
|
|
|
const char* line = reader.Line();
|
|
|
|
|
|
|
|
if( !strCompare( "EESchema-LIBRARY Version", line, &line ) )
|
2016-11-21 08:56:44 +00:00
|
|
|
{
|
|
|
|
// Old .sym files (which are libraries with only one symbol, used to store and reuse shapes)
|
|
|
|
// EESchema-LIB Version x.x SYMBOL. They are valid files.
|
|
|
|
if( !strCompare( "EESchema-LIB Version", line, &line ) )
|
|
|
|
SCH_PARSE_ERROR( "file is not a valid component or symbol library file", reader, line );
|
|
|
|
}
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
m_versionMajor = parseInt( reader, line, &line );
|
|
|
|
|
|
|
|
if( *line != '.' )
|
|
|
|
SCH_PARSE_ERROR( "invalid file version formatting in header", reader, line );
|
|
|
|
|
|
|
|
line++;
|
|
|
|
|
|
|
|
m_versionMinor = parseInt( reader, line, &line );
|
|
|
|
|
|
|
|
if( m_versionMajor < 1 || m_versionMinor < 0 || m_versionMinor > 99 )
|
|
|
|
SCH_PARSE_ERROR( "invalid file version in header", reader, line );
|
|
|
|
|
|
|
|
// Check if this is a symbol library which is the same as a component library but without
|
|
|
|
// any alias, documentation, footprint filters, etc.
|
|
|
|
if( strCompare( "SYMBOL", line, &line ) )
|
|
|
|
{
|
|
|
|
// Symbol files add date and time stamp info to the header.
|
|
|
|
m_libType = LIBRARY_TYPE_SYMBOL;
|
|
|
|
|
|
|
|
/// @todo Probably should check for a valid date and time stamp even though it's not used.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_libType = LIBRARY_TYPE_EESCHEMA;
|
|
|
|
}
|
|
|
|
|
|
|
|
while( reader.ReadLine() )
|
|
|
|
{
|
|
|
|
line = reader.Line();
|
|
|
|
|
|
|
|
if( *line == '#' || isspace( *line ) ) // Skip comments and blank lines.
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Headers where only supported in older library file formats.
|
|
|
|
if( m_libType == LIBRARY_TYPE_EESCHEMA && strCompare( "$HEADER", line ) )
|
|
|
|
loadHeader( reader );
|
|
|
|
|
|
|
|
if( strCompare( "DEF", line ) )
|
|
|
|
{
|
|
|
|
// Read one DEF/ENDDEF part entry from library:
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART* part = LoadPart( reader, m_versionMajor, m_versionMinor, &m_symbols );
|
2019-03-15 13:09:42 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
m_symbols[ part->GetName() ] = part;
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
++m_modHash;
|
|
|
|
|
|
|
|
// Remember the file modification time of library file when the
|
|
|
|
// cache snapshot was made, so that in a networked environment we will
|
|
|
|
// reload the cache as needed.
|
|
|
|
m_fileModTime = GetLibModificationTime();
|
|
|
|
|
|
|
|
if( USE_OLD_DOC_FILE_FORMAT( m_versionMajor, m_versionMinor ) )
|
|
|
|
loadDocs();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::loadDocs()
|
|
|
|
{
|
|
|
|
const char* line;
|
|
|
|
wxString text;
|
|
|
|
wxString aliasName;
|
|
|
|
wxFileName fn = m_libFileName;
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART* symbol = NULL;;
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
fn.SetExt( DOC_EXT );
|
|
|
|
|
|
|
|
// Not all libraries will have a document file.
|
|
|
|
if( !fn.FileExists() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( !fn.IsFileReadable() )
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "user does not have permission to read library "
|
2017-12-15 11:37:46 +00:00
|
|
|
"document file \"%s\"" ), fn.GetFullPath() ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
FILE_LINE_READER reader( fn.GetFullPath() );
|
|
|
|
|
|
|
|
line = reader.ReadLine();
|
|
|
|
|
|
|
|
if( !line )
|
|
|
|
THROW_IO_ERROR( _( "symbol document library file is empty" ) );
|
|
|
|
|
|
|
|
if( !strCompare( DOCFILE_IDENT, line, &line ) )
|
|
|
|
SCH_PARSE_ERROR( "invalid document library file version formatting in header",
|
|
|
|
reader, line );
|
|
|
|
|
|
|
|
while( reader.ReadLine() )
|
|
|
|
{
|
|
|
|
line = reader.Line();
|
|
|
|
|
|
|
|
if( *line == '#' ) // Comment line.
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !strCompare( "$CMP", line, &line ) != 0 )
|
|
|
|
SCH_PARSE_ERROR( "$CMP command expected", reader, line );
|
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
aliasName = wxString::FromUTF8( line );
|
|
|
|
aliasName.Trim();
|
2018-10-07 13:08:30 +00:00
|
|
|
aliasName = LIB_ID::FixIllegalChars( aliasName, LIB_ID::ID_SCH );
|
2018-12-05 18:54:51 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART_MAP::iterator it = m_symbols.find( aliasName );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( it == m_symbols.end() )
|
|
|
|
wxLogWarning( "Symbol '%s' not found in library:\n\n"
|
2016-08-18 23:23:10 +00:00
|
|
|
"'%s'\n\nat line %d offset %d", aliasName, fn.GetFullPath(),
|
|
|
|
reader.LineNumber(), (int) (line - reader.Line() ) );
|
|
|
|
else
|
2019-11-06 19:15:42 +00:00
|
|
|
symbol = it->second;
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2017-02-28 09:00:18 +00:00
|
|
|
// Read the curent alias associated doc.
|
|
|
|
// if the alias does not exist, just skip the description
|
|
|
|
// (Can happen if a .dcm is not synchronized with the corresponding .lib file)
|
|
|
|
while( reader.ReadLine() )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
2017-02-28 09:00:18 +00:00
|
|
|
line = reader.Line();
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2017-02-28 09:00:18 +00:00
|
|
|
if( !line )
|
|
|
|
SCH_PARSE_ERROR( "unexpected end of file", reader, line );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2017-02-28 09:00:18 +00:00
|
|
|
if( strCompare( "$ENDCMP", line, &line ) )
|
|
|
|
break;
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2017-02-28 09:00:18 +00:00
|
|
|
text = FROM_UTF8( line + 2 );
|
2018-08-09 06:44:10 +00:00
|
|
|
// Remove spaces at eol, and eol chars:
|
|
|
|
text = text.Trim();
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2017-02-28 09:00:18 +00:00
|
|
|
switch( line[0] )
|
|
|
|
{
|
|
|
|
case 'D':
|
2019-11-06 19:15:42 +00:00
|
|
|
if( symbol )
|
|
|
|
symbol->SetDescription( text );
|
2017-02-28 09:00:18 +00:00
|
|
|
break;
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2017-02-28 09:00:18 +00:00
|
|
|
case 'K':
|
2019-11-06 19:15:42 +00:00
|
|
|
if( symbol )
|
|
|
|
symbol->SetKeyWords( text );
|
2017-02-28 09:00:18 +00:00
|
|
|
break;
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2017-02-28 09:00:18 +00:00
|
|
|
case 'F':
|
2019-11-06 19:15:42 +00:00
|
|
|
if( symbol )
|
|
|
|
{
|
|
|
|
symbol->SetDocFileName( text );
|
|
|
|
symbol->GetField( DATASHEET )->SetText( text );
|
|
|
|
}
|
2017-02-28 09:00:18 +00:00
|
|
|
break;
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-08-09 06:44:10 +00:00
|
|
|
case 0:
|
|
|
|
case '\n':
|
|
|
|
case '\r':
|
2017-02-28 09:00:18 +00:00
|
|
|
case '#':
|
2018-08-09 06:44:10 +00:00
|
|
|
// Empty line or commment
|
2017-02-28 09:00:18 +00:00
|
|
|
break;
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2017-02-28 09:00:18 +00:00
|
|
|
default:
|
|
|
|
SCH_PARSE_ERROR( "expected token in symbol definition", reader, line );
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::loadHeader( FILE_LINE_READER& aReader )
|
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-08-19 12:53:06 +00:00
|
|
|
wxASSERT( strCompare( "$HEADER", line, &line ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
while( aReader.ReadLine() )
|
|
|
|
{
|
|
|
|
line = (char*) aReader;
|
|
|
|
|
|
|
|
// The time stamp saved in old library files is not used or saved in the latest
|
|
|
|
// library file version.
|
|
|
|
if( strCompare( "TimeStamp", line, &line ) )
|
|
|
|
continue;
|
|
|
|
else if( strCompare( "$ENDHEADER", line, &line ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-15 13:09:42 +00:00
|
|
|
LIB_PART* SCH_LEGACY_PLUGIN_CACHE::LoadPart( LINE_READER& aReader, int aMajorVersion,
|
2019-11-06 19:15:42 +00:00
|
|
|
int aMinorVersion, LIB_PART_MAP* aMap )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2019-04-08 00:11:06 +00:00
|
|
|
while( *line == '#' )
|
|
|
|
aReader.ReadLine();
|
|
|
|
|
2019-08-15 07:19:15 +00:00
|
|
|
if( !strCompare( "DEF", line, &line ) )
|
|
|
|
SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
long num;
|
|
|
|
size_t pos = 4; // "DEF" plus the first space.
|
|
|
|
wxString utf8Line = wxString::FromUTF8( line );
|
|
|
|
wxStringTokenizer tokens( utf8Line, " \r\n\t" );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
if( tokens.CountTokens() < 8 )
|
|
|
|
SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
|
|
|
|
|
|
|
|
// Read DEF line:
|
2016-08-18 23:23:10 +00:00
|
|
|
std::unique_ptr< LIB_PART > part( new LIB_PART( wxEmptyString ) );
|
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
wxString name, prefix, tmp;
|
|
|
|
|
|
|
|
name = tokens.GetNextToken();
|
|
|
|
pos += name.size() + 1;
|
|
|
|
|
|
|
|
prefix = tokens.GetNextToken();
|
|
|
|
pos += prefix.size() + 1;
|
|
|
|
|
|
|
|
tmp = tokens.GetNextToken();
|
|
|
|
pos += tmp.size() + 1; // NumOfPins, unused.
|
|
|
|
|
|
|
|
tmp = tokens.GetNextToken(); // Pin name offset.
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
if( !tmp.ToLong( &num ) )
|
|
|
|
THROW_PARSE_ERROR( "invalid pin offset", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
pos += tmp.size() + 1;
|
2019-12-30 18:28:00 +00:00
|
|
|
part->SetPinNameOffset( Mils2Iu( (int)num ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
tmp = tokens.GetNextToken(); // Show pin numbers.
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
if( !( tmp == "Y" || tmp == "N") )
|
|
|
|
THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
pos += tmp.size() + 1;
|
|
|
|
part->SetShowPinNumbers( ( tmp == "N" ) ? false : true );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
tmp = tokens.GetNextToken(); // Show pin names.
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
if( !( tmp == "Y" || tmp == "N") )
|
|
|
|
THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
|
|
|
|
|
|
|
pos += tmp.size() + 1;
|
|
|
|
part->SetShowPinNames( ( tmp == "N" ) ? false : true );
|
|
|
|
|
|
|
|
tmp = tokens.GetNextToken(); // Number of units.
|
|
|
|
|
|
|
|
if( !tmp.ToLong( &num ) )
|
|
|
|
THROW_PARSE_ERROR( "invalid unit count", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
|
|
|
|
|
|
|
pos += tmp.size() + 1;
|
|
|
|
part->SetUnitCount( (int)num );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
// Ensure m_unitCount is >= 1. Could be read as 0 in old libraries.
|
|
|
|
if( part->GetUnitCount() < 1 )
|
|
|
|
part->SetUnitCount( 1 );
|
|
|
|
|
|
|
|
// Copy part name and prefix.
|
|
|
|
|
|
|
|
// The root alias is added to the alias list by SetName() which is called by SetText().
|
|
|
|
if( name.IsEmpty() )
|
|
|
|
{
|
2017-11-12 20:49:38 +00:00
|
|
|
part->SetName( "~" );
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
else if( name[0] != '~' )
|
|
|
|
{
|
2017-11-12 20:49:38 +00:00
|
|
|
part->SetName( name );
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-12 20:49:38 +00:00
|
|
|
part->SetName( name.Right( name.Length() - 1 ) );
|
|
|
|
part->GetValueField().SetVisible( false );
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 12:26:31 +00:00
|
|
|
// Don't set the library alias, this is determined by the symbol library table.
|
|
|
|
part->SetLibId( LIB_ID( wxEmptyString, part->GetName() ) );
|
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
LIB_FIELD& reference = part->GetReferenceField();
|
|
|
|
|
|
|
|
if( prefix == "~" )
|
|
|
|
{
|
|
|
|
reference.Empty();
|
|
|
|
reference.SetVisible( false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reference.SetText( prefix );
|
|
|
|
}
|
|
|
|
|
2016-11-20 14:19:06 +00:00
|
|
|
// In version 2.2 and earlier, this parameter was a '0' which was just a place holder.
|
2016-08-18 23:23:10 +00:00
|
|
|
// The was no concept of interchangeable multiple unit symbols.
|
2019-03-15 13:09:42 +00:00
|
|
|
if( LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
|
|
|
|
&& LIB_VERSION( aMajorVersion, aMinorVersion ) <= LIB_VERSION( 2, 2 ) )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
// Nothing needs to be set since the default setting for symbols with multiple
|
|
|
|
// units were never interchangeable. Just parse the 0 an move on.
|
2018-12-05 18:54:51 +00:00
|
|
|
tmp = tokens.GetNextToken();
|
|
|
|
pos += tmp.size() + 1;
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-05 18:54:51 +00:00
|
|
|
tmp = tokens.GetNextToken();
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
if( tmp == "L" )
|
2016-08-18 23:23:10 +00:00
|
|
|
part->LockUnits( true );
|
2018-12-05 18:54:51 +00:00
|
|
|
else if( tmp == "F" || tmp == "0" )
|
2016-08-18 23:23:10 +00:00
|
|
|
part->LockUnits( false );
|
|
|
|
else
|
2018-12-05 18:54:51 +00:00
|
|
|
THROW_PARSE_ERROR( "expected L, F, or 0", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
pos += tmp.size() + 1;
|
|
|
|
}
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
// There is the optional power component flag.
|
2018-12-05 18:54:51 +00:00
|
|
|
if( tokens.HasMoreTokens() )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
2018-12-05 18:54:51 +00:00
|
|
|
tmp = tokens.GetNextToken();
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
if( tmp == "P" )
|
2016-08-18 23:23:10 +00:00
|
|
|
part->SetPower();
|
2018-12-05 18:54:51 +00:00
|
|
|
else if( tmp == "N" )
|
2016-08-18 23:23:10 +00:00
|
|
|
part->SetNormal();
|
|
|
|
else
|
2018-12-05 18:54:51 +00:00
|
|
|
THROW_PARSE_ERROR( "expected P or N", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
|
|
|
|
// Read lines until "ENDDEF" is found.
|
|
|
|
while( line )
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( *line == '#' ) // Comment
|
2017-02-19 22:44:53 +00:00
|
|
|
;
|
2019-11-06 19:15:42 +00:00
|
|
|
else if( strCompare( "Ti", line, &line ) ) // Modification date is ignored.
|
2016-08-18 23:23:10 +00:00
|
|
|
continue;
|
2019-11-06 19:15:42 +00:00
|
|
|
else if( strCompare( "ALIAS", line, &line ) ) // Aliases
|
|
|
|
loadAliases( part, aReader, aMap );
|
|
|
|
else if( *line == 'F' ) // Fields
|
2016-08-18 23:23:10 +00:00
|
|
|
loadField( part, aReader );
|
2019-11-06 19:15:42 +00:00
|
|
|
else if( strCompare( "DRAW", line, &line ) ) // Drawing objects.
|
2019-03-15 13:09:42 +00:00
|
|
|
loadDrawEntries( part, aReader, aMajorVersion, aMinorVersion );
|
2019-11-06 19:15:42 +00:00
|
|
|
else if( strCompare( "$FPLIST", line, &line ) ) // Footprint filter list
|
2016-08-18 23:23:10 +00:00
|
|
|
loadFootprintFilters( part, aReader );
|
2019-11-06 19:15:42 +00:00
|
|
|
else if( strCompare( "ENDDEF", line, &line ) ) // End of part description
|
2017-02-12 01:14:45 +00:00
|
|
|
{
|
2016-08-18 23:23:10 +00:00
|
|
|
return part.release();
|
2017-02-12 01:14:45 +00:00
|
|
|
}
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_PARSE_ERROR( "missing ENDDEF", aReader, line );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::loadAliases( std::unique_ptr<LIB_PART>& aPart,
|
2019-11-06 19:15:42 +00:00
|
|
|
LINE_READER& aReader,
|
|
|
|
LIB_PART_MAP* aMap )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
wxString newAliasName;
|
2016-08-18 23:23:10 +00:00
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
|
|
|
wxCHECK_RET( strCompare( "ALIAS", line, &line ), "Invalid ALIAS section" );
|
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
wxString utf8Line = wxString::FromUTF8( line );
|
|
|
|
wxStringTokenizer tokens( utf8Line, " \r\n\t" );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-05 18:54:51 +00:00
|
|
|
// Parse the ALIAS list.
|
|
|
|
while( tokens.HasMoreTokens() )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
newAliasName = tokens.GetNextToken();
|
|
|
|
|
|
|
|
if( aMap )
|
|
|
|
{
|
|
|
|
LIB_PART* newPart = new LIB_PART( newAliasName );
|
|
|
|
|
|
|
|
newPart->SetParent( aPart.get() );
|
|
|
|
|
|
|
|
// This will prevent duplicate aliases.
|
|
|
|
(*aMap)[ newPart->GetName() ] = newPart;
|
|
|
|
}
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::loadField( std::unique_ptr<LIB_PART>& aPart,
|
2019-11-06 19:15:42 +00:00
|
|
|
LINE_READER& aReader )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
|
|
|
wxCHECK_RET( *line == 'F', "Invalid field line" );
|
|
|
|
|
2019-08-02 00:10:25 +00:00
|
|
|
wxString text;
|
2016-08-18 23:23:10 +00:00
|
|
|
int id;
|
|
|
|
|
|
|
|
if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid field ID", aReader, line + 1 );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
LIB_FIELD* field;
|
|
|
|
|
|
|
|
if( (unsigned) id < MANDATORY_FIELDS )
|
|
|
|
{
|
|
|
|
field = aPart->GetField( id );
|
|
|
|
|
|
|
|
// this will fire only if somebody broke a constructor or editor.
|
|
|
|
// MANDATORY_FIELDS are always present in ram resident components, no
|
|
|
|
// exceptions, and they always have their names set, even fixed fields.
|
|
|
|
wxASSERT( field );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
field = new LIB_FIELD( aPart.get(), id );
|
|
|
|
aPart->AddDrawItem( field );
|
|
|
|
}
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
// Skip to the first double quote.
|
|
|
|
while( *line != '"' && *line != 0 )
|
|
|
|
line++;
|
|
|
|
|
|
|
|
if( *line == 0 )
|
|
|
|
SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
|
|
|
|
|
2019-08-02 00:10:25 +00:00
|
|
|
parseQuotedString( text, aReader, line, &line, true );
|
|
|
|
|
|
|
|
field->SetText( text );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
// Doctor the *.lib file field which has a "~" in blank fields. New saves will
|
|
|
|
// not save like this.
|
2019-08-02 00:10:25 +00:00
|
|
|
if( text.size() == 1 && text[0] == '~' )
|
|
|
|
field->SetText( wxEmptyString );
|
|
|
|
else
|
|
|
|
field->SetText( text );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
wxPoint pos;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
field->SetPosition( pos );
|
|
|
|
|
|
|
|
wxSize textSize;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
textSize.x = textSize.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2017-01-23 20:30:11 +00:00
|
|
|
field->SetTextSize( textSize );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
char textOrient = parseChar( aReader, line, &line );
|
|
|
|
|
|
|
|
if( textOrient == 'H' )
|
2017-01-23 20:30:11 +00:00
|
|
|
field->SetTextAngle( TEXT_ANGLE_HORIZ );
|
2016-08-18 23:23:10 +00:00
|
|
|
else if( textOrient == 'V' )
|
2017-01-23 20:30:11 +00:00
|
|
|
field->SetTextAngle( TEXT_ANGLE_VERT );
|
2016-08-18 23:23:10 +00:00
|
|
|
else
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid field text orientation parameter", aReader, line );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
char textVisible = parseChar( aReader, line, &line );
|
|
|
|
|
|
|
|
if( textVisible == 'V' )
|
|
|
|
field->SetVisible( true );
|
|
|
|
else if ( textVisible == 'I' )
|
|
|
|
field->SetVisible( false );
|
|
|
|
else
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid field text visibility parameter", aReader, line );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
// It may be technically correct to use the library version to determine if the field text
|
|
|
|
// attributes are present. If anyone knows if that is valid and what version that would be,
|
|
|
|
// please change this to test the library version rather than an EOL or the quoted string
|
|
|
|
// of the field name.
|
|
|
|
if( *line != 0 && *line != '"' )
|
|
|
|
{
|
|
|
|
char textHJustify = parseChar( aReader, line, &line );
|
|
|
|
|
|
|
|
if( textHJustify == 'C' )
|
|
|
|
field->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
else if( textHJustify == 'L' )
|
|
|
|
field->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
else if( textHJustify == 'R' )
|
|
|
|
field->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
else
|
2018-08-07 01:17:00 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid field text horizontal justification", aReader, line );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
wxString attributes;
|
|
|
|
|
|
|
|
parseUnquotedString( attributes, aReader, line, &line );
|
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
size_t attrSize = attributes.size();
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
if( !(attrSize == 3 || attrSize == 1 ) )
|
|
|
|
SCH_PARSE_ERROR( "invalid field text attributes size", aReader, line );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
switch( (wxChar) attributes[0] )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
2018-08-07 01:17:00 +00:00
|
|
|
case 'C': field->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
|
|
|
|
case 'B': field->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
|
|
|
|
case 'T': field->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
|
|
|
|
default: SCH_PARSE_ERROR( "invalid field text vertical justification", aReader, line );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( attrSize == 3 )
|
|
|
|
{
|
|
|
|
wxChar attr_1 = attributes[1];
|
|
|
|
wxChar attr_2 = attributes[2];
|
|
|
|
|
|
|
|
if( attr_1 == 'I' ) // Italic
|
2016-08-18 23:23:10 +00:00
|
|
|
field->SetItalic( true );
|
2018-08-07 01:17:00 +00:00
|
|
|
else if( attr_1 != 'N' ) // No italics is default, check for error.
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
if ( attr_2 == 'B' ) // Bold
|
2016-08-18 23:23:10 +00:00
|
|
|
field->SetBold( true );
|
2018-08-07 01:17:00 +00:00
|
|
|
else if( attr_2 != 'N' ) // No bold is default, check for error.
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid field text bold parameter", aReader, line );
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fields in RAM must always have names.
|
2017-11-07 09:18:08 +00:00
|
|
|
if( (unsigned) id < MANDATORY_FIELDS )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
field->m_name = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
|
|
|
|
|
2017-02-28 09:00:18 +00:00
|
|
|
// Ensure the VALUE field = the part name (can be not the case
|
|
|
|
// with malformed libraries: edited by hand, or converted from other tools)
|
2018-08-07 01:17:00 +00:00
|
|
|
if( id == VALUE )
|
2019-08-02 00:10:25 +00:00
|
|
|
field->SetText( aPart->GetName() );
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-07 01:17:00 +00:00
|
|
|
parseQuotedString( field->m_name, aReader, line, &line, true ); // Optional.
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::loadDrawEntries( std::unique_ptr<LIB_PART>& aPart,
|
2019-11-06 19:15:42 +00:00
|
|
|
LINE_READER& aReader,
|
|
|
|
int aMajorVersion,
|
|
|
|
int aMinorVersion )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
|
|
|
wxCHECK_RET( strCompare( "DRAW", line, &line ), "Invalid DRAW section" );
|
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
|
|
|
|
while( line )
|
|
|
|
{
|
|
|
|
if( strCompare( "ENDDRAW", line, &line ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch( line[0] )
|
|
|
|
{
|
|
|
|
case 'A': // Arc
|
|
|
|
aPart->AddDrawItem( loadArc( aPart, aReader ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C': // Circle
|
|
|
|
aPart->AddDrawItem( loadCircle( aPart, aReader ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'T': // Text
|
2019-03-15 13:09:42 +00:00
|
|
|
aPart->AddDrawItem( loadText( aPart, aReader, aMajorVersion, aMinorVersion ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'S': // Square
|
|
|
|
aPart->AddDrawItem( loadRectangle( aPart, aReader ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'X': // Pin Description
|
|
|
|
aPart->AddDrawItem( loadPin( aPart, aReader ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P': // Polyline
|
|
|
|
aPart->AddDrawItem( loadPolyLine( aPart, aReader ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'B': // Bezier Curves
|
|
|
|
aPart->AddDrawItem( loadBezier( aPart, aReader ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '#': // Comment
|
|
|
|
case '\n': // Empty line
|
|
|
|
case '\r':
|
|
|
|
case 0:
|
2016-10-17 02:58:02 +00:00
|
|
|
break;
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
default:
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "undefined DRAW entry", aReader, line );
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
}
|
|
|
|
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "file ended prematurely loading component draw element", aReader, line );
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
FILL_T SCH_LEGACY_PLUGIN_CACHE::parseFillMode( LINE_READER& aReader, const char* aLine,
|
2016-08-18 23:23:10 +00:00
|
|
|
const char** aOutput )
|
|
|
|
{
|
2020-03-03 22:01:51 +00:00
|
|
|
switch ( parseChar( aReader, aLine, aOutput ) )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
2020-03-03 22:01:51 +00:00
|
|
|
case 'F':
|
|
|
|
return FILLED_SHAPE;
|
|
|
|
case 'f':
|
|
|
|
return FILLED_WITH_BG_BODYCOLOR;
|
|
|
|
case 'N':
|
|
|
|
return NO_FILL;
|
|
|
|
default:
|
|
|
|
SCH_PARSE_ERROR( "invalid fill type, expected f, F, or N", aReader, aLine );
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
2020-03-03 22:01:51 +00:00
|
|
|
|
|
|
|
// This will never be reached but quiets the compiler warnings
|
|
|
|
return NO_FILL;
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
LIB_ARC* SCH_LEGACY_PLUGIN_CACHE::loadArc( std::unique_ptr<LIB_PART>& aPart,
|
2019-11-06 19:15:42 +00:00
|
|
|
LINE_READER& aReader )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-08-19 15:31:46 +00:00
|
|
|
wxCHECK_MSG( strCompare( "A", line, &line ), NULL, "Invalid LIB_ARC definition" );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
LIB_ARC* arc = new LIB_ARC( aPart.get() );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
wxPoint center;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
center.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
center.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
arc->SetPosition( center );
|
2019-12-30 18:28:00 +00:00
|
|
|
arc->SetRadius( Mils2Iu( parseInt( aReader, line, &line ) ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
int angle1 = parseInt( aReader, line, &line );
|
|
|
|
int angle2 = parseInt( aReader, line, &line );
|
|
|
|
|
|
|
|
NORMALIZE_ANGLE_POS( angle1 );
|
|
|
|
NORMALIZE_ANGLE_POS( angle2 );
|
|
|
|
arc->SetFirstRadiusAngle( angle1 );
|
|
|
|
arc->SetSecondRadiusAngle( angle2 );
|
|
|
|
|
|
|
|
arc->SetUnit( parseInt( aReader, line, &line ) );
|
|
|
|
arc->SetConvert( parseInt( aReader, line, &line ) );
|
2019-12-30 18:28:00 +00:00
|
|
|
arc->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
|
2016-11-21 08:56:44 +00:00
|
|
|
|
|
|
|
// Old libraries (version <= 2.2) do not have always this FILL MODE param
|
|
|
|
// when fill mode is no fill (default mode).
|
|
|
|
if( *line != 0 )
|
|
|
|
arc->SetFillMode( parseFillMode( aReader, line, &line ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
// Actual Coordinates of arc ends are read from file
|
|
|
|
if( *line != 0 )
|
|
|
|
{
|
|
|
|
wxPoint arcStart, arcEnd;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
arcStart.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
arcStart.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
arcEnd.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
arcEnd.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
arc->SetStart( arcStart );
|
|
|
|
arc->SetEnd( arcEnd );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Actual Coordinates of arc ends are not read from file
|
|
|
|
// (old library), calculate them
|
|
|
|
wxPoint arcStart( arc->GetRadius(), 0 );
|
|
|
|
wxPoint arcEnd( arc->GetRadius(), 0 );
|
|
|
|
|
|
|
|
RotatePoint( &arcStart.x, &arcStart.y, -angle1 );
|
|
|
|
arcStart += arc->GetPosition();
|
|
|
|
arc->SetStart( arcStart );
|
|
|
|
RotatePoint( &arcEnd.x, &arcEnd.y, -angle2 );
|
|
|
|
arcEnd += arc->GetPosition();
|
|
|
|
arc->SetEnd( arcEnd );
|
|
|
|
}
|
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
return arc;
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
LIB_CIRCLE* SCH_LEGACY_PLUGIN_CACHE::loadCircle( std::unique_ptr<LIB_PART>& aPart,
|
2019-11-06 19:15:42 +00:00
|
|
|
LINE_READER& aReader )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-08-19 15:31:46 +00:00
|
|
|
wxCHECK_MSG( strCompare( "C", line, &line ), NULL, "Invalid LIB_CIRCLE definition" );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
LIB_CIRCLE* circle = new LIB_CIRCLE( aPart.get() );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
wxPoint center;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
center.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
center.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
circle->SetPosition( center );
|
2019-12-30 18:28:00 +00:00
|
|
|
circle->SetRadius( Mils2Iu( parseInt( aReader, line, &line ) ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
circle->SetUnit( parseInt( aReader, line, &line ) );
|
|
|
|
circle->SetConvert( parseInt( aReader, line, &line ) );
|
2019-12-30 18:28:00 +00:00
|
|
|
circle->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
if( *line != 0 )
|
|
|
|
circle->SetFillMode( parseFillMode( aReader, line, &line ) );
|
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
return circle;
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
LIB_TEXT* SCH_LEGACY_PLUGIN_CACHE::loadText( std::unique_ptr<LIB_PART>& aPart,
|
2019-11-06 19:15:42 +00:00
|
|
|
LINE_READER& aReader,
|
|
|
|
int aMajorVersion,
|
|
|
|
int aMinorVersion )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-08-19 15:31:46 +00:00
|
|
|
wxCHECK_MSG( strCompare( "T", line, &line ), NULL, "Invalid LIB_TEXT definition" );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
LIB_TEXT* text = new LIB_TEXT( aPart.get() );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
text->SetTextAngle( (double) parseInt( aReader, line, &line ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
wxPoint center;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
center.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
center.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
text->SetPosition( center );
|
|
|
|
|
|
|
|
wxSize size;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
size.x = size.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2017-01-23 20:30:11 +00:00
|
|
|
text->SetTextSize( size );
|
|
|
|
text->SetVisible( !parseInt( aReader, line, &line ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
text->SetUnit( parseInt( aReader, line, &line ) );
|
|
|
|
text->SetConvert( parseInt( aReader, line, &line ) );
|
|
|
|
|
|
|
|
wxString str;
|
|
|
|
|
|
|
|
// If quoted string loading fails, load as not quoted string.
|
|
|
|
if( *line == '"' )
|
|
|
|
parseQuotedString( str, aReader, line, &line );
|
|
|
|
else
|
2018-05-14 15:49:30 +00:00
|
|
|
{
|
2016-08-18 23:23:10 +00:00
|
|
|
parseUnquotedString( str, aReader, line, &line );
|
|
|
|
|
2018-05-14 15:49:30 +00:00
|
|
|
// In old libs, "spaces" are replaced by '~' in unquoted strings:
|
|
|
|
str.Replace( "~", " " );
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
if( !str.IsEmpty() )
|
|
|
|
{
|
|
|
|
// convert two apostrophes back to double quote
|
|
|
|
str.Replace( "''", "\"" );
|
|
|
|
}
|
|
|
|
|
|
|
|
text->SetText( str );
|
|
|
|
|
|
|
|
// Here things are murky and not well defined. At some point it appears the format
|
|
|
|
// was changed to add text properties. However rather than add the token to the end of
|
|
|
|
// the text definition, it was added after the string and no mention if the file
|
|
|
|
// verion was bumped or not so this code make break on very old component libraries.
|
2016-09-30 14:01:05 +00:00
|
|
|
//
|
|
|
|
// Update: apparently even in the latest version this can be different so added a test
|
|
|
|
// for end of line before checking for the text properties.
|
2019-03-15 13:09:42 +00:00
|
|
|
if( LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
|
|
|
|
&& LIB_VERSION( aMajorVersion, aMinorVersion ) > LIB_VERSION( 2, 0 ) && !is_eol( *line ) )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
if( strCompare( "Italic", line, &line ) )
|
|
|
|
text->SetItalic( true );
|
|
|
|
else if( !strCompare( "Normal", line, &line ) )
|
2018-08-07 01:17:00 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'", aReader, line );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
if( parseInt( aReader, line, &line ) > 0 )
|
|
|
|
text->SetBold( true );
|
|
|
|
|
2017-02-27 16:22:06 +00:00
|
|
|
// Some old libaries version > 2.0 do not have these options for text justification:
|
|
|
|
if( !is_eol( *line ) )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
2017-02-27 16:22:06 +00:00
|
|
|
switch( parseChar( aReader, line, &line ) )
|
|
|
|
{
|
2018-08-07 01:17:00 +00:00
|
|
|
case 'L': text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break;
|
|
|
|
case 'C': text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break;
|
|
|
|
case 'R': text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); break;
|
|
|
|
default: SCH_PARSE_ERROR( "invalid horizontal text justication; expected L, C, or R",
|
|
|
|
aReader, line );
|
2017-02-27 16:22:06 +00:00
|
|
|
}
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2017-02-27 16:22:06 +00:00
|
|
|
switch( parseChar( aReader, line, &line ) )
|
|
|
|
{
|
2018-08-07 01:17:00 +00:00
|
|
|
case 'T': text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
|
|
|
|
case 'C': text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
|
|
|
|
case 'B': text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
|
|
|
|
default: SCH_PARSE_ERROR( "invalid vertical text justication; expected T, C, or B",
|
|
|
|
aReader, line );
|
2017-02-27 16:22:06 +00:00
|
|
|
}
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
return text;
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
LIB_RECTANGLE* SCH_LEGACY_PLUGIN_CACHE::loadRectangle( std::unique_ptr<LIB_PART>& aPart,
|
2019-11-06 19:15:42 +00:00
|
|
|
LINE_READER& aReader )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-08-19 15:31:46 +00:00
|
|
|
wxCHECK_MSG( strCompare( "S", line, &line ), NULL, "Invalid LIB_RECTANGLE definition" );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
LIB_RECTANGLE* rectangle = new LIB_RECTANGLE( aPart.get() );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
wxPoint pos;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
rectangle->SetPosition( pos );
|
|
|
|
|
|
|
|
wxPoint end;
|
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
end.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
end.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
rectangle->SetEnd( end );
|
|
|
|
|
|
|
|
rectangle->SetUnit( parseInt( aReader, line, &line ) );
|
|
|
|
rectangle->SetConvert( parseInt( aReader, line, &line ) );
|
2019-12-30 18:28:00 +00:00
|
|
|
rectangle->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
if( *line != 0 )
|
|
|
|
rectangle->SetFillMode( parseFillMode( aReader, line, &line ) );
|
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
return rectangle;
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
LIB_PIN* SCH_LEGACY_PLUGIN_CACHE::loadPin( std::unique_ptr<LIB_PART>& aPart,
|
2019-11-06 19:15:42 +00:00
|
|
|
LINE_READER& aReader )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-08-19 15:31:46 +00:00
|
|
|
wxCHECK_MSG( strCompare( "X", line, &line ), NULL, "Invalid LIB_PIN definition" );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
LIB_PIN* pin = new LIB_PIN( aPart.get() );
|
2018-01-29 00:51:07 +00:00
|
|
|
|
2018-12-06 16:47:20 +00:00
|
|
|
size_t pos = 2; // "X" plus ' ' space character.
|
|
|
|
wxString tmp;
|
|
|
|
wxString utf8Line = wxString::FromUTF8( line );
|
|
|
|
wxStringTokenizer tokens( utf8Line, " \r\n\t" );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-06 16:47:20 +00:00
|
|
|
if( tokens.CountTokens() < 11 )
|
|
|
|
SCH_PARSE_ERROR( "invalid pin definition", aReader, line );
|
2018-08-08 08:15:44 +00:00
|
|
|
|
2018-12-06 16:47:20 +00:00
|
|
|
pin->m_name = tokens.GetNextToken();
|
|
|
|
pos += pin->m_name.size() + 1;
|
|
|
|
pin->m_number = tokens.GetNextToken();
|
|
|
|
pos += pin->m_number.size() + 1;
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-06 16:47:20 +00:00
|
|
|
long num;
|
|
|
|
wxPoint position;
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-06 16:47:20 +00:00
|
|
|
tmp = tokens.GetNextToken();
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-12-06 16:47:20 +00:00
|
|
|
if( !tmp.ToLong( &num ) )
|
|
|
|
THROW_PARSE_ERROR( "invalid pin X coordinate", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
|
|
|
|
|
|
|
pos += tmp.size() + 1;
|
2019-12-30 18:28:00 +00:00
|
|
|
position.x = Mils2Iu( (int) num );
|
2018-12-06 16:47:20 +00:00
|
|
|
|
|
|
|
tmp = tokens.GetNextToken();
|
|
|
|
|
|
|
|
if( !tmp.ToLong( &num ) )
|
|
|
|
THROW_PARSE_ERROR( "invalid pin Y coordinate", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
|
|
|
|
|
|
|
pos += tmp.size() + 1;
|
2019-12-30 18:28:00 +00:00
|
|
|
position.y = Mils2Iu( (int) num );
|
2018-12-06 16:47:20 +00:00
|
|
|
pin->m_position = position;
|
|
|
|
|
|
|
|
tmp = tokens.GetNextToken();
|
|
|
|
|
|
|
|
if( !tmp.ToLong( &num ) )
|
|
|
|
THROW_PARSE_ERROR( "invalid pin length", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
|
|
|
|
|
|
|
pos += tmp.size() + 1;
|
2019-12-30 18:28:00 +00:00
|
|
|
pin->m_length = Mils2Iu( (int) num );
|
2018-12-06 16:47:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
tmp = tokens.GetNextToken();
|
|
|
|
|
|
|
|
if( tmp.size() > 1 )
|
|
|
|
THROW_PARSE_ERROR( "invalid pin orientation", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
|
|
|
|
|
|
|
pos += tmp.size() + 1;
|
|
|
|
pin->m_orientation = tmp[0];
|
|
|
|
|
|
|
|
tmp = tokens.GetNextToken();
|
|
|
|
|
|
|
|
if( !tmp.ToLong( &num ) )
|
|
|
|
THROW_PARSE_ERROR( "invalid pin number text size", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
|
|
|
|
|
|
|
pos += tmp.size() + 1;
|
2019-12-30 18:28:00 +00:00
|
|
|
pin->m_numTextSize = Mils2Iu( (int) num );
|
2018-12-06 16:47:20 +00:00
|
|
|
|
|
|
|
tmp = tokens.GetNextToken();
|
|
|
|
|
|
|
|
if( !tmp.ToLong( &num ) )
|
|
|
|
THROW_PARSE_ERROR( "invalid pin name text size", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
|
|
|
|
|
|
|
pos += tmp.size() + 1;
|
2019-12-30 18:28:00 +00:00
|
|
|
pin->m_nameTextSize = Mils2Iu( (int) num );
|
2018-12-06 16:47:20 +00:00
|
|
|
|
|
|
|
tmp = tokens.GetNextToken();
|
|
|
|
|
|
|
|
if( !tmp.ToLong( &num ) )
|
|
|
|
THROW_PARSE_ERROR( "invalid pin unit", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
|
|
|
|
|
|
|
pos += tmp.size() + 1;
|
|
|
|
pin->m_Unit = (int) num;
|
|
|
|
|
|
|
|
tmp = tokens.GetNextToken();
|
|
|
|
|
|
|
|
if( !tmp.ToLong( &num ) )
|
|
|
|
THROW_PARSE_ERROR( "invalid pin alternate body type", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
|
|
|
|
|
|
|
pos += tmp.size() + 1;
|
|
|
|
pin->m_Convert = (int) num;
|
|
|
|
|
|
|
|
tmp = tokens.GetNextToken();
|
|
|
|
|
|
|
|
if( tmp.size() != 1 )
|
|
|
|
THROW_PARSE_ERROR( "invalid pin type", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
|
|
|
|
|
|
|
pos += tmp.size() + 1;
|
|
|
|
char type = tmp[0];
|
|
|
|
|
|
|
|
wxString attributes;
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
switch( type )
|
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
case 'I':
|
|
|
|
pin->m_type = ELECTRICAL_PINTYPE::PT_INPUT;
|
|
|
|
break;
|
|
|
|
case 'O':
|
|
|
|
pin->m_type = ELECTRICAL_PINTYPE::PT_OUTPUT;
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
pin->m_type = ELECTRICAL_PINTYPE::PT_BIDI;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
pin->m_type = ELECTRICAL_PINTYPE::PT_TRISTATE;
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
pin->m_type = ELECTRICAL_PINTYPE::PT_PASSIVE;
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
pin->m_type = ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
pin->m_type = ELECTRICAL_PINTYPE::PT_POWER_IN;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
pin->m_type = ELECTRICAL_PINTYPE::PT_POWER_OUT;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
pin->m_type = ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR;
|
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
pin->m_type = ELECTRICAL_PINTYPE::PT_OPENEMITTER;
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
pin->m_type = ELECTRICAL_PINTYPE::PT_NC;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
THROW_PARSE_ERROR( "unknown pin type", aReader.GetSource(), aReader.Line(),
|
|
|
|
aReader.LineNumber(), pos );
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 16:47:20 +00:00
|
|
|
// Optional
|
|
|
|
if( tokens.HasMoreTokens() ) /* Special Symbol defined */
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
2018-12-06 16:47:20 +00:00
|
|
|
tmp = tokens.GetNextToken();
|
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
INVERTED = 1 << 0,
|
|
|
|
CLOCK = 1 << 1,
|
|
|
|
LOWLEVEL_IN = 1 << 2,
|
|
|
|
LOWLEVEL_OUT = 1 << 3,
|
|
|
|
FALLING_EDGE = 1 << 4,
|
|
|
|
NONLOGIC = 1 << 5
|
|
|
|
};
|
|
|
|
|
|
|
|
int flags = 0;
|
|
|
|
|
2018-12-06 16:47:20 +00:00
|
|
|
for( int j = tmp.size(); j > 0; )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
2018-12-06 16:47:20 +00:00
|
|
|
switch( tmp[--j].GetValue() )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
2018-08-07 01:17:00 +00:00
|
|
|
case '~': break;
|
|
|
|
case 'N': pin->m_attributes |= PIN_INVISIBLE; break;
|
|
|
|
case 'I': flags |= INVERTED; break;
|
|
|
|
case 'C': flags |= CLOCK; break;
|
|
|
|
case 'L': flags |= LOWLEVEL_IN; break;
|
|
|
|
case 'V': flags |= LOWLEVEL_OUT; break;
|
|
|
|
case 'F': flags |= FALLING_EDGE; break;
|
|
|
|
case 'X': flags |= NONLOGIC; break;
|
2018-12-06 16:47:20 +00:00
|
|
|
default: THROW_PARSE_ERROR( "invalid pin attribut", aReader.GetSource(),
|
|
|
|
aReader.Line(), aReader.LineNumber(), pos );
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
2018-12-06 16:47:20 +00:00
|
|
|
|
|
|
|
pos += 1;
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( flags )
|
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
case 0:
|
|
|
|
pin->m_shape = GRAPHIC_PINSHAPE::LINE;
|
|
|
|
break;
|
|
|
|
case INVERTED:
|
|
|
|
pin->m_shape = GRAPHIC_PINSHAPE::INVERTED;
|
|
|
|
break;
|
|
|
|
case CLOCK:
|
|
|
|
pin->m_shape = GRAPHIC_PINSHAPE::CLOCK;
|
|
|
|
break;
|
|
|
|
case INVERTED | CLOCK:
|
|
|
|
pin->m_shape = GRAPHIC_PINSHAPE::INVERTED_CLOCK;
|
|
|
|
break;
|
|
|
|
case LOWLEVEL_IN:
|
|
|
|
pin->m_shape = GRAPHIC_PINSHAPE::INPUT_LOW;
|
|
|
|
break;
|
|
|
|
case LOWLEVEL_IN | CLOCK:
|
|
|
|
pin->m_shape = GRAPHIC_PINSHAPE::CLOCK_LOW;
|
|
|
|
break;
|
|
|
|
case LOWLEVEL_OUT:
|
|
|
|
pin->m_shape = GRAPHIC_PINSHAPE::OUTPUT_LOW;
|
|
|
|
break;
|
|
|
|
case FALLING_EDGE:
|
|
|
|
pin->m_shape = GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK;
|
|
|
|
break;
|
|
|
|
case NONLOGIC:
|
|
|
|
pin->m_shape = GRAPHIC_PINSHAPE::NONLOGIC;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SCH_PARSE_ERROR( "pin attributes do not define a valid pin shape", aReader, line );
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
return pin;
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
LIB_POLYLINE* SCH_LEGACY_PLUGIN_CACHE::loadPolyLine( std::unique_ptr<LIB_PART>& aPart,
|
2019-11-06 19:15:42 +00:00
|
|
|
LINE_READER& aReader )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-08-19 15:31:46 +00:00
|
|
|
wxCHECK_MSG( strCompare( "P", line, &line ), NULL, "Invalid LIB_POLYLINE definition" );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
LIB_POLYLINE* polyLine = new LIB_POLYLINE( aPart.get() );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
int points = parseInt( aReader, line, &line );
|
|
|
|
polyLine->SetUnit( parseInt( aReader, line, &line ) );
|
|
|
|
polyLine->SetConvert( parseInt( aReader, line, &line ) );
|
2019-12-30 18:28:00 +00:00
|
|
|
polyLine->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
|
2018-08-07 01:17:00 +00:00
|
|
|
polyLine->Reserve( points );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
wxPoint pt;
|
|
|
|
|
|
|
|
for( int i = 0; i < points; i++ )
|
|
|
|
{
|
2019-12-30 18:28:00 +00:00
|
|
|
pt.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
pt.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
polyLine->AddPoint( pt );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( *line != 0 )
|
|
|
|
polyLine->SetFillMode( parseFillMode( aReader, line, &line ) );
|
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
return polyLine;
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
LIB_BEZIER* SCH_LEGACY_PLUGIN_CACHE::loadBezier( std::unique_ptr<LIB_PART>& aPart,
|
2019-11-06 19:15:42 +00:00
|
|
|
LINE_READER& aReader )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-08-19 15:31:46 +00:00
|
|
|
wxCHECK_MSG( strCompare( "B", line, &line ), NULL, "Invalid LIB_BEZIER definition" );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
LIB_BEZIER* bezier = new LIB_BEZIER( aPart.get() );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
int points = parseInt( aReader, line, &line );
|
|
|
|
bezier->SetUnit( parseInt( aReader, line, &line ) );
|
|
|
|
bezier->SetConvert( parseInt( aReader, line, &line ) );
|
2019-12-30 18:28:00 +00:00
|
|
|
bezier->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
wxPoint pt;
|
2018-08-07 01:17:00 +00:00
|
|
|
bezier->Reserve( points );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < points; i++ )
|
|
|
|
{
|
2019-12-30 18:28:00 +00:00
|
|
|
pt.x = Mils2Iu( parseInt( aReader, line, &line ) );
|
|
|
|
pt.y = Mils2Iu( parseInt( aReader, line, &line ) );
|
2016-08-18 23:23:10 +00:00
|
|
|
bezier->AddPoint( pt );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( *line != 0 )
|
|
|
|
bezier->SetFillMode( parseFillMode( aReader, line, &line ) );
|
|
|
|
|
2018-08-07 01:17:00 +00:00
|
|
|
return bezier;
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::loadFootprintFilters( std::unique_ptr<LIB_PART>& aPart,
|
2019-11-06 19:15:42 +00:00
|
|
|
LINE_READER& aReader )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2016-08-19 15:31:46 +00:00
|
|
|
wxCHECK_RET( strCompare( "$FPLIST", line, &line ), "Invalid footprint filter list" );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
wxArrayString footprintFilters;
|
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
while( line )
|
|
|
|
{
|
|
|
|
if( strCompare( "$ENDFPLIST", line, &line ) )
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
|
|
|
aPart->SetFootprintFilters( footprintFilters );
|
2016-08-18 23:23:10 +00:00
|
|
|
return;
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
2016-08-18 23:23:10 +00:00
|
|
|
|
|
|
|
wxString footprint;
|
|
|
|
|
|
|
|
parseUnquotedString( footprint, aReader, line, &line );
|
2019-11-06 19:15:42 +00:00
|
|
|
footprintFilters.Add( footprint );
|
2016-08-18 23:23:10 +00:00
|
|
|
line = aReader.ReadLine();
|
|
|
|
}
|
|
|
|
|
2017-08-04 18:43:31 +00:00
|
|
|
SCH_PARSE_ERROR( "file ended prematurely while loading footprint filters", aReader, line );
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::Save( bool aSaveDocFile )
|
2016-09-17 17:31:58 +00:00
|
|
|
{
|
|
|
|
if( !m_isModified )
|
|
|
|
return;
|
|
|
|
|
2018-07-23 22:49:07 +00:00
|
|
|
// Write through symlinks, don't replace them
|
|
|
|
wxFileName fn = GetRealFile();
|
|
|
|
|
|
|
|
std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( fn.GetFullPath() ) );
|
2017-02-16 01:28:36 +00:00
|
|
|
formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
|
|
|
|
formatter->Print( 0, "#encoding utf-8\n");
|
2016-09-17 17:31:58 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
for( LIB_PART_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); it++ )
|
2016-09-17 17:31:58 +00:00
|
|
|
{
|
|
|
|
if( !it->second->IsRoot() )
|
|
|
|
continue;
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
SaveSymbol( it->second, *formatter.get(), &m_symbols );
|
2016-09-17 17:31:58 +00:00
|
|
|
}
|
|
|
|
|
2017-02-16 01:28:36 +00:00
|
|
|
formatter->Print( 0, "#\n#End Library\n" );
|
|
|
|
formatter.reset();
|
|
|
|
|
2018-07-23 22:49:07 +00:00
|
|
|
m_fileModTime = fn.GetModificationTime();
|
2016-09-17 17:31:58 +00:00
|
|
|
m_isModified = false;
|
2017-01-27 15:56:36 +00:00
|
|
|
|
|
|
|
if( aSaveDocFile )
|
|
|
|
saveDocFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( LIB_PART* aSymbol, OUTPUTFORMATTER& aFormatter,
|
|
|
|
LIB_PART_MAP* aMap )
|
2017-12-01 16:49:19 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
wxCHECK_RET( aSymbol && aSymbol->IsRoot(), "Invalid LIB_PART pointer." );
|
|
|
|
|
|
|
|
// LIB_ALIAS objects are deprecated but we still need to gather up the derived symbols
|
|
|
|
// and save their names for the old file format.
|
|
|
|
wxArrayString aliasNames;
|
|
|
|
|
|
|
|
if( aMap )
|
|
|
|
{
|
|
|
|
for( auto entry : *aMap )
|
|
|
|
{
|
|
|
|
LIB_PART* part = entry.second;
|
|
|
|
|
|
|
|
if( part->IsAlias() && part->GetParent().lock() == aSymbol->SharedPtr() )
|
|
|
|
aliasNames.Add( part->GetName() );
|
|
|
|
}
|
|
|
|
}
|
2017-12-01 16:49:19 +00:00
|
|
|
|
|
|
|
LIB_FIELD& value = aSymbol->GetValueField();
|
|
|
|
|
|
|
|
// First line: it s a comment (component name for readers)
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "#\n# %s\n#\n", TO_UTF8( value.GetText() ) );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
|
|
|
// Save data
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "DEF" );
|
2019-04-04 13:48:57 +00:00
|
|
|
aFormatter.Print( 0, " %s", TO_UTF8( value.GetText() ) );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
|
|
|
LIB_FIELD& reference = aSymbol->GetReferenceField();
|
|
|
|
|
|
|
|
if( !reference.GetText().IsEmpty() )
|
|
|
|
{
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, " %s", TO_UTF8( reference.GetText() ) );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, " ~" );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, " %d %d %c %c %d %c %c\n",
|
2019-12-30 18:28:00 +00:00
|
|
|
0, Iu2Mils( aSymbol->GetPinNameOffset() ),
|
2019-04-04 13:48:57 +00:00
|
|
|
aSymbol->ShowPinNumbers() ? 'Y' : 'N',
|
|
|
|
aSymbol->ShowPinNames() ? 'Y' : 'N',
|
|
|
|
aSymbol->GetUnitCount(), aSymbol->UnitsLocked() ? 'L' : 'F',
|
|
|
|
aSymbol->IsPower() ? 'P' : 'N' );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
2017-12-14 16:24:29 +00:00
|
|
|
timestamp_t dateModified = aSymbol->GetDateLastEdition();
|
2017-12-01 16:49:19 +00:00
|
|
|
|
|
|
|
if( dateModified != 0 )
|
|
|
|
{
|
2017-12-14 16:24:29 +00:00
|
|
|
int sec = dateModified & 63;
|
|
|
|
int min = ( dateModified >> 6 ) & 63;
|
|
|
|
int hour = ( dateModified >> 12 ) & 31;
|
|
|
|
int day = ( dateModified >> 17 ) & 31;
|
|
|
|
int mon = ( dateModified >> 22 ) & 15;
|
|
|
|
int year = ( dateModified >> 26 ) + 1990;
|
2017-12-01 16:49:19 +00:00
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LIB_FIELDS fields;
|
|
|
|
aSymbol->GetFields( fields );
|
|
|
|
|
|
|
|
// Mandatory fields:
|
|
|
|
// may have their own save policy so there is a separate loop for them.
|
|
|
|
// Empty fields are saved, because the user may have set visibility,
|
|
|
|
// size and orientation
|
|
|
|
for( int i = 0; i < MANDATORY_FIELDS; ++i )
|
|
|
|
{
|
|
|
|
saveField( &fields[i], aFormatter );
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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( unsigned 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].GetText().IsEmpty() )
|
|
|
|
{
|
|
|
|
fields[i].SetId( fieldId++ );
|
|
|
|
saveField( &fields[i], aFormatter );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
// Save the alias list: a line starting by "ALIAS".
|
|
|
|
if( !aliasNames.IsEmpty() )
|
2017-12-01 16:49:19 +00:00
|
|
|
{
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "ALIAS" );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
for( unsigned i = 0; i < aliasNames.GetCount(); i++ )
|
2017-12-01 16:49:19 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
aFormatter.Print( 0, " %s", TO_UTF8( aliasNames[i] ) );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "\n" );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxArrayString footprints = aSymbol->GetFootprints();
|
|
|
|
|
|
|
|
// Write the footprint filter list
|
|
|
|
if( footprints.GetCount() != 0 )
|
|
|
|
{
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "$FPLIST\n" );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
|
|
|
for( unsigned i = 0; i < footprints.GetCount(); i++ )
|
|
|
|
{
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, " %s\n", TO_UTF8( footprints[i] ) );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "$ENDFPLIST\n" );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save graphics items (including pins)
|
|
|
|
if( !aSymbol->GetDrawItems().empty() )
|
|
|
|
{
|
|
|
|
// Sort the draw items in order to editing a file editing by hand.
|
|
|
|
aSymbol->GetDrawItems().sort();
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "DRAW\n" );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
|
|
|
for( LIB_ITEM& item : aSymbol->GetDrawItems() )
|
|
|
|
{
|
|
|
|
switch( item.Type() )
|
|
|
|
{
|
|
|
|
case LIB_FIELD_T: // Fields have already been saved above.
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case LIB_ARC_T:
|
|
|
|
saveArc( (LIB_ARC*) &item, aFormatter );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LIB_BEZIER_T:
|
|
|
|
saveBezier( (LIB_BEZIER*) &item, aFormatter );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LIB_CIRCLE_T:
|
|
|
|
saveCircle( ( LIB_CIRCLE* ) &item, aFormatter );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LIB_PIN_T:
|
|
|
|
savePin( (LIB_PIN* ) &item, aFormatter );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LIB_POLYLINE_T:
|
|
|
|
savePolyLine( ( LIB_POLYLINE* ) &item, aFormatter );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LIB_RECTANGLE_T:
|
|
|
|
saveRectangle( ( LIB_RECTANGLE* ) &item, aFormatter );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LIB_TEXT_T:
|
|
|
|
saveText( ( LIB_TEXT* ) &item, aFormatter );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "ENDDRAW\n" );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "ENDDEF\n" );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::saveArc( LIB_ARC* aArc,
|
2019-03-14 18:57:16 +00:00
|
|
|
OUTPUTFORMATTER& aFormatter )
|
2017-12-01 16:49:19 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( aArc && aArc->Type() == LIB_ARC_T, "Invalid LIB_ARC object." );
|
|
|
|
|
|
|
|
int x1 = aArc->GetFirstRadiusAngle();
|
|
|
|
|
|
|
|
if( x1 > 1800 )
|
|
|
|
x1 -= 3600;
|
|
|
|
|
|
|
|
int x2 = aArc->GetSecondRadiusAngle();
|
|
|
|
|
|
|
|
if( x2 > 1800 )
|
|
|
|
x2 -= 3600;
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aArc->GetPosition().x ), Iu2Mils( aArc->GetPosition().y ),
|
|
|
|
Iu2Mils( aArc->GetRadius() ), x1, x2, aArc->GetUnit(), aArc->GetConvert(),
|
|
|
|
Iu2Mils( aArc->GetWidth() ), fill_tab[aArc->GetFillMode()],
|
|
|
|
Iu2Mils( aArc->GetStart().x ), Iu2Mils( aArc->GetStart().y ),
|
|
|
|
Iu2Mils( aArc->GetEnd().x ), Iu2Mils( aArc->GetEnd().y ) );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::saveBezier( LIB_BEZIER* aBezier,
|
2019-03-14 18:57:16 +00:00
|
|
|
OUTPUTFORMATTER& aFormatter )
|
2017-12-01 16:49:19 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( aBezier && aBezier->Type() == LIB_BEZIER_T, "Invalid LIB_BEZIER object." );
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "B %u %d %d %d", (unsigned)aBezier->GetPoints().size(),
|
2019-12-30 18:28:00 +00:00
|
|
|
aBezier->GetUnit(), aBezier->GetConvert(), Iu2Mils( aBezier->GetWidth() ) );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
|
|
|
for( const auto& pt : aBezier->GetPoints() )
|
2019-12-30 18:28:00 +00:00
|
|
|
aFormatter.Print( 0, " %d %d", Iu2Mils( pt.x ), Iu2Mils( pt.y ) );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, " %c\n", fill_tab[aBezier->GetFillMode()] );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::saveCircle( LIB_CIRCLE* aCircle,
|
2019-03-14 18:57:16 +00:00
|
|
|
OUTPUTFORMATTER& aFormatter )
|
2017-12-01 16:49:19 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( aCircle && aCircle->Type() == LIB_CIRCLE_T, "Invalid LIB_CIRCLE object." );
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "C %d %d %d %d %d %d %c\n",
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aCircle->GetPosition().x ), Iu2Mils( aCircle->GetPosition().y ),
|
|
|
|
Iu2Mils( aCircle->GetRadius() ), aCircle->GetUnit(), aCircle->GetConvert(),
|
|
|
|
Iu2Mils( aCircle->GetWidth() ), fill_tab[aCircle->GetFillMode()] );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::saveField( LIB_FIELD* aField,
|
2019-03-14 18:57:16 +00:00
|
|
|
OUTPUTFORMATTER& aFormatter )
|
2017-12-01 16:49:19 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
|
|
|
|
|
|
|
|
int hjustify, vjustify;
|
|
|
|
int id = aField->GetId();
|
2019-08-02 00:10:25 +00:00
|
|
|
wxString text = aField->GetText();
|
2017-12-01 16:49:19 +00:00
|
|
|
|
|
|
|
hjustify = 'C';
|
|
|
|
|
|
|
|
if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
|
|
|
|
hjustify = 'L';
|
|
|
|
else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
|
|
|
|
hjustify = 'R';
|
|
|
|
|
|
|
|
vjustify = 'C';
|
|
|
|
|
|
|
|
if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
|
|
|
|
vjustify = 'B';
|
|
|
|
else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
|
|
|
|
vjustify = 'T';
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
|
2019-03-15 13:09:42 +00:00
|
|
|
id,
|
|
|
|
EscapedUTF8( text ).c_str(), // wraps in quotes
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aField->GetTextPos().x ), Iu2Mils( aField->GetTextPos().y ),
|
|
|
|
Iu2Mils( aField->GetTextWidth() ),
|
2019-03-15 13:09:42 +00:00
|
|
|
aField->GetTextAngle() == 0 ? 'H' : 'V',
|
|
|
|
aField->IsVisible() ? 'V' : 'I',
|
|
|
|
hjustify, vjustify,
|
|
|
|
aField->IsItalic() ? 'I' : 'N',
|
|
|
|
aField->IsBold() ? 'B' : 'N' );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
|
|
|
/* Save field name, if necessary
|
|
|
|
* Field name is saved only if it is not the default name.
|
|
|
|
* Just because default name depends on the language and can change from
|
2018-04-08 10:28:59 +00:00
|
|
|
* a country to another
|
2017-12-01 16:49:19 +00:00
|
|
|
*/
|
|
|
|
wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
|
|
|
|
|
|
|
|
if( id >= FIELD1 && !aField->m_name.IsEmpty() && aField->m_name != defName )
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, " %s", EscapedUTF8( aField->m_name ).c_str() );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "\n" );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::savePin( LIB_PIN* aPin,
|
2019-03-14 18:57:16 +00:00
|
|
|
OUTPUTFORMATTER& aFormatter )
|
2017-12-01 16:49:19 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
|
|
|
|
|
|
|
|
int Etype;
|
|
|
|
|
|
|
|
switch( aPin->GetType() )
|
|
|
|
{
|
|
|
|
default:
|
2020-01-18 20:51:28 +00:00
|
|
|
case ELECTRICAL_PINTYPE::PT_INPUT:
|
2017-12-01 16:49:19 +00:00
|
|
|
Etype = 'I';
|
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case ELECTRICAL_PINTYPE::PT_OUTPUT:
|
2017-12-01 16:49:19 +00:00
|
|
|
Etype = 'O';
|
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case ELECTRICAL_PINTYPE::PT_BIDI:
|
2017-12-01 16:49:19 +00:00
|
|
|
Etype = 'B';
|
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case ELECTRICAL_PINTYPE::PT_TRISTATE:
|
2017-12-01 16:49:19 +00:00
|
|
|
Etype = 'T';
|
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case ELECTRICAL_PINTYPE::PT_PASSIVE:
|
2017-12-01 16:49:19 +00:00
|
|
|
Etype = 'P';
|
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case ELECTRICAL_PINTYPE::PT_UNSPECIFIED:
|
2017-12-01 16:49:19 +00:00
|
|
|
Etype = 'U';
|
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case ELECTRICAL_PINTYPE::PT_POWER_IN:
|
2017-12-01 16:49:19 +00:00
|
|
|
Etype = 'W';
|
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case ELECTRICAL_PINTYPE::PT_POWER_OUT:
|
2017-12-01 16:49:19 +00:00
|
|
|
Etype = 'w';
|
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR:
|
2017-12-01 16:49:19 +00:00
|
|
|
Etype = 'C';
|
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case ELECTRICAL_PINTYPE::PT_OPENEMITTER:
|
2017-12-01 16:49:19 +00:00
|
|
|
Etype = 'E';
|
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case ELECTRICAL_PINTYPE::PT_NC:
|
2017-12-01 16:49:19 +00:00
|
|
|
Etype = 'N';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aPin->GetName().IsEmpty() )
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "X %s", TO_UTF8( aPin->GetName() ) );
|
2017-12-01 16:49:19 +00:00
|
|
|
else
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "X ~" );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, " %s %d %d %d %c %d %d %d %d %c",
|
2019-03-15 13:09:42 +00:00
|
|
|
aPin->GetNumber().IsEmpty() ? "~" : TO_UTF8( aPin->GetNumber() ),
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aPin->GetPosition().x ), Iu2Mils( aPin->GetPosition().y ),
|
|
|
|
Iu2Mils( (int) aPin->GetLength() ), (int) aPin->GetOrientation(),
|
|
|
|
Iu2Mils( aPin->GetNumberTextSize() ), Iu2Mils( aPin->GetNameTextSize() ),
|
2019-03-15 13:09:42 +00:00
|
|
|
aPin->GetUnit(), aPin->GetConvert(), Etype );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
if( aPin->GetShape() != GRAPHIC_PINSHAPE::LINE || !aPin->IsVisible() )
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, " " );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
|
|
|
if( !aPin->IsVisible() )
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "N" );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
|
|
|
switch( aPin->GetShape() )
|
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
case GRAPHIC_PINSHAPE::LINE:
|
2017-12-01 16:49:19 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case GRAPHIC_PINSHAPE::INVERTED:
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "I" );
|
2017-12-01 16:49:19 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case GRAPHIC_PINSHAPE::CLOCK:
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "C" );
|
2017-12-01 16:49:19 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case GRAPHIC_PINSHAPE::INVERTED_CLOCK:
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "IC" );
|
2017-12-01 16:49:19 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case GRAPHIC_PINSHAPE::INPUT_LOW:
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "L" );
|
2017-12-01 16:49:19 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case GRAPHIC_PINSHAPE::CLOCK_LOW:
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "CL" );
|
2017-12-01 16:49:19 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case GRAPHIC_PINSHAPE::OUTPUT_LOW:
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "V" );
|
2017-12-01 16:49:19 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK:
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "F" );
|
2017-12-01 16:49:19 +00:00
|
|
|
break;
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
case GRAPHIC_PINSHAPE::NONLOGIC:
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "X" );
|
2017-12-01 16:49:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert( !"Invalid pin shape" );
|
|
|
|
}
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "\n" );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
|
|
|
aPin->ClearFlags( IS_CHANGED );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::savePolyLine( LIB_POLYLINE* aPolyLine,
|
2019-03-14 18:57:16 +00:00
|
|
|
OUTPUTFORMATTER& aFormatter )
|
2017-12-01 16:49:19 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( aPolyLine && aPolyLine->Type() == LIB_POLYLINE_T, "Invalid LIB_POLYLINE object." );
|
|
|
|
|
|
|
|
int ccount = aPolyLine->GetCornerCount();
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "P %d %d %d %d", ccount, aPolyLine->GetUnit(), aPolyLine->GetConvert(),
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aPolyLine->GetWidth() ) );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
|
|
|
for( const auto& pt : aPolyLine->GetPolyPoints() )
|
|
|
|
{
|
2019-12-30 18:28:00 +00:00
|
|
|
aFormatter.Print( 0, " %d %d", Iu2Mils( pt.x ), Iu2Mils( pt.y ) );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, " %c\n", fill_tab[aPolyLine->GetFillMode()] );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::saveRectangle( LIB_RECTANGLE* aRectangle,
|
2019-03-14 18:57:16 +00:00
|
|
|
OUTPUTFORMATTER& aFormatter )
|
2017-12-01 16:49:19 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( aRectangle && aRectangle->Type() == LIB_RECTANGLE_T,
|
|
|
|
"Invalid LIB_RECTANGLE object." );
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "S %d %d %d %d %d %d %d %c\n",
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aRectangle->GetPosition().x ),
|
|
|
|
Iu2Mils( aRectangle->GetPosition().y ),
|
|
|
|
Iu2Mils( aRectangle->GetEnd().x ), Iu2Mils( aRectangle->GetEnd().y ),
|
2019-03-15 13:09:42 +00:00
|
|
|
aRectangle->GetUnit(), aRectangle->GetConvert(),
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aRectangle->GetWidth() ), fill_tab[aRectangle->GetFillMode()] );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::saveText( LIB_TEXT* aText,
|
2019-03-14 18:57:16 +00:00
|
|
|
OUTPUTFORMATTER& aFormatter )
|
2017-12-01 16:49:19 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
|
|
|
|
|
|
|
|
wxString text = aText->GetText();
|
|
|
|
|
2018-05-14 15:49:30 +00:00
|
|
|
if( text.Contains( wxT( " " ) ) || text.Contains( wxT( "~" ) ) || text.Contains( wxT( "\"" ) ) )
|
2017-12-01 16:49:19 +00:00
|
|
|
{
|
|
|
|
// convert double quote to similar-looking two apostrophes
|
|
|
|
text.Replace( wxT( "\"" ), wxT( "''" ) );
|
|
|
|
text = wxT( "\"" ) + text + wxT( "\"" );
|
|
|
|
}
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, "T %g %d %d %d %d %d %d %s", aText->GetTextAngle(),
|
2019-12-30 18:28:00 +00:00
|
|
|
Iu2Mils( aText->GetTextPos().x ), Iu2Mils( aText->GetTextPos().y ),
|
|
|
|
Iu2Mils( aText->GetTextWidth() ), !aText->IsVisible(),
|
2019-03-15 13:09:42 +00:00
|
|
|
aText->GetUnit(), aText->GetConvert(), TO_UTF8( text ) );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, " %s %d", aText->IsItalic() ? "Italic" : "Normal", aText->IsBold() );
|
2017-12-01 16:49:19 +00:00
|
|
|
|
|
|
|
char hjustify = 'C';
|
|
|
|
|
|
|
|
if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
|
|
|
|
hjustify = 'L';
|
|
|
|
else if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
|
|
|
|
hjustify = 'R';
|
|
|
|
|
|
|
|
char vjustify = 'C';
|
|
|
|
|
|
|
|
if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
|
|
|
|
vjustify = 'B';
|
|
|
|
else if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
|
|
|
|
vjustify = 'T';
|
|
|
|
|
2019-03-14 18:57:16 +00:00
|
|
|
aFormatter.Print( 0, " %c %c\n", hjustify, vjustify );
|
2017-12-01 16:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::saveDocFile()
|
|
|
|
{
|
2017-12-01 16:49:19 +00:00
|
|
|
wxFileName fileName = m_libFileName;
|
2017-01-27 15:56:36 +00:00
|
|
|
|
2017-12-01 16:49:19 +00:00
|
|
|
fileName.SetExt( DOC_EXT );
|
|
|
|
FILE_OUTPUTFORMATTER formatter( fileName.GetFullPath() );
|
2017-01-27 15:56:36 +00:00
|
|
|
|
|
|
|
formatter.Print( 0, "%s\n", DOCFILE_IDENT );
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
for( LIB_PART_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); ++it )
|
2017-01-27 15:56:36 +00:00
|
|
|
{
|
2017-12-01 16:49:19 +00:00
|
|
|
wxString description = it->second->GetDescription();
|
|
|
|
wxString keyWords = it->second->GetKeyWords();
|
|
|
|
wxString docFileName = it->second->GetDocFileName();
|
|
|
|
|
|
|
|
if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
formatter.Print( 0, "#\n$CMP %s\n", TO_UTF8( it->second->GetName() ) );
|
|
|
|
|
|
|
|
if( !description.IsEmpty() )
|
|
|
|
formatter.Print( 0, "D %s\n", TO_UTF8( description ) );
|
|
|
|
|
|
|
|
if( !keyWords.IsEmpty() )
|
|
|
|
formatter.Print( 0, "K %s\n", TO_UTF8( keyWords ) );
|
|
|
|
|
|
|
|
if( !docFileName.IsEmpty() )
|
|
|
|
formatter.Print( 0, "F %s\n", TO_UTF8( docFileName ) );
|
|
|
|
|
|
|
|
formatter.Print( 0, "$ENDCMP\n" );
|
2017-01-27 15:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
formatter.Print( 0, "#\n#End Doc Library\n" );
|
2016-09-17 17:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
void SCH_LEGACY_PLUGIN_CACHE::DeleteSymbol( const wxString& aSymbolName )
|
2016-09-23 17:28:38 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART_MAP::iterator it = m_symbols.find( aSymbolName );
|
2016-09-23 17:28:38 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( it == m_symbols.end() )
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "library %s does not contain a symbol named %s" ),
|
|
|
|
m_libFileName.GetFullName(), aSymbolName ) );
|
2016-09-23 17:28:38 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART* part = it->second;
|
2016-09-23 17:28:38 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( part->IsRoot() )
|
2016-09-23 17:28:38 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART* rootPart = part;
|
2016-09-23 17:28:38 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
// Remove the root symbol and all it's children.
|
|
|
|
m_symbols.erase( it );
|
2016-09-23 17:28:38 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART_MAP::iterator it1 = m_symbols.begin();
|
2016-09-23 17:28:38 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
while( it1 != m_symbols.end() )
|
|
|
|
{
|
|
|
|
if( it1->second->IsAlias() && it1->second->GetParent().lock() == rootPart->SharedPtr() )
|
|
|
|
{
|
2019-11-08 20:50:04 +00:00
|
|
|
delete it1->second;
|
|
|
|
it1 = m_symbols.erase( it1 );
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-08 20:50:04 +00:00
|
|
|
it1++;
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
2016-09-23 17:28:38 +00:00
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
delete rootPart;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Just remove the alias.
|
|
|
|
m_symbols.erase( it );
|
|
|
|
delete part;
|
2016-09-23 17:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
++m_modHash;
|
|
|
|
m_isModified = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::cacheLib( const wxString& aLibraryFileName )
|
|
|
|
{
|
|
|
|
if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
|
|
|
|
{
|
|
|
|
// a spectacular episode in memory management:
|
|
|
|
delete m_cache;
|
|
|
|
m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryFileName );
|
2017-01-27 15:56:36 +00:00
|
|
|
|
2017-07-12 09:55:51 +00:00
|
|
|
// Because m_cache is rebuilt, increment PART_LIBS::s_modify_generation
|
|
|
|
// to modify the hash value that indicate component to symbol links
|
|
|
|
// must be updated.
|
|
|
|
PART_LIBS::s_modify_generation++;
|
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
if( !isBuffering( m_props ) )
|
|
|
|
m_cache->Load();
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
bool SCH_LEGACY_PLUGIN::writeDocFile( const PROPERTIES* aProperties )
|
|
|
|
{
|
|
|
|
std::string propName( SCH_LEGACY_PLUGIN::PropNoDocFile );
|
|
|
|
|
|
|
|
if( aProperties && aProperties->find( propName ) != aProperties->end() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_LEGACY_PLUGIN::isBuffering( const PROPERTIES* aProperties )
|
|
|
|
{
|
2017-02-28 09:17:11 +00:00
|
|
|
return ( aProperties && aProperties->Exists( SCH_LEGACY_PLUGIN::PropBuffering ) );
|
2017-01-27 15:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-24 23:18:50 +00:00
|
|
|
int SCH_LEGACY_PLUGIN::GetModifyHash() const
|
|
|
|
{
|
|
|
|
if( m_cache )
|
|
|
|
return m_cache->GetModifyHash();
|
|
|
|
|
|
|
|
// If the cache hasn't been loaded, it hasn't been modified.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
|
2016-08-18 23:23:10 +00:00
|
|
|
const wxString& aLibraryPath,
|
|
|
|
const PROPERTIES* aProperties )
|
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
2017-01-28 04:30:13 +00:00
|
|
|
m_props = aProperties;
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2017-09-02 18:12:50 +00:00
|
|
|
bool powerSymbolsOnly = ( aProperties &&
|
|
|
|
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
|
2016-08-18 23:23:10 +00:00
|
|
|
cacheLib( aLibraryPath );
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
const LIB_PART_MAP& symbols = m_cache->m_symbols;
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
for( LIB_PART_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
|
2017-09-02 18:12:50 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( !powerSymbolsOnly || it->second->IsPower() )
|
|
|
|
aSymbolNameList.Add( it->first );
|
2017-09-02 18:12:50 +00:00
|
|
|
}
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::EnumerateSymbolLib( std::vector<LIB_PART*>& aSymbolList,
|
2017-02-24 16:09:27 +00:00
|
|
|
const wxString& aLibraryPath,
|
|
|
|
const PROPERTIES* aProperties )
|
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
|
|
|
m_props = aProperties;
|
|
|
|
|
2017-09-02 18:12:50 +00:00
|
|
|
bool powerSymbolsOnly = ( aProperties &&
|
|
|
|
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
|
2017-02-24 16:09:27 +00:00
|
|
|
cacheLib( aLibraryPath );
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
const LIB_PART_MAP& symbols = m_cache->m_symbols;
|
2017-02-24 16:09:27 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
for( LIB_PART_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
|
2017-09-02 18:12:50 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( !powerSymbolsOnly || it->second->IsPower() )
|
|
|
|
aSymbolList.push_back( it->second );
|
2017-09-02 18:12:50 +00:00
|
|
|
}
|
2017-02-24 16:09:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART* SCH_LEGACY_PLUGIN::LoadSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
|
|
|
|
const PROPERTIES* aProperties )
|
2016-09-03 18:28:17 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
|
|
|
m_props = aProperties;
|
|
|
|
|
|
|
|
cacheLib( aLibraryPath );
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
|
2016-09-03 18:28:17 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( it == m_cache->m_symbols.end() )
|
|
|
|
return nullptr;
|
2016-09-03 18:28:17 +00:00
|
|
|
|
|
|
|
return it->second;
|
|
|
|
}
|
2016-09-17 17:31:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
|
|
|
|
const PROPERTIES* aProperties )
|
|
|
|
{
|
|
|
|
m_props = aProperties;
|
|
|
|
|
|
|
|
cacheLib( aLibraryPath );
|
|
|
|
|
|
|
|
m_cache->AddSymbol( aSymbol );
|
2017-01-27 15:56:36 +00:00
|
|
|
|
|
|
|
if( !isBuffering( aProperties ) )
|
|
|
|
m_cache->Save( writeDocFile( aProperties ) );
|
2016-09-17 17:31:58 +00:00
|
|
|
}
|
2016-09-23 17:28:38 +00:00
|
|
|
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
|
2016-09-29 22:31:43 +00:00
|
|
|
const PROPERTIES* aProperties )
|
|
|
|
{
|
|
|
|
m_props = aProperties;
|
|
|
|
|
|
|
|
cacheLib( aLibraryPath );
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
m_cache->DeleteSymbol( aSymbolName );
|
2017-01-27 15:56:36 +00:00
|
|
|
|
|
|
|
if( !isBuffering( aProperties ) )
|
|
|
|
m_cache->Save( writeDocFile( aProperties ) );
|
2016-09-29 22:31:43 +00:00
|
|
|
}
|
2016-10-05 23:28:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::CreateSymbolLib( const wxString& aLibraryPath,
|
|
|
|
const PROPERTIES* aProperties )
|
|
|
|
{
|
|
|
|
if( wxFileExists( aLibraryPath ) )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format(
|
2017-12-15 11:37:46 +00:00
|
|
|
_( "symbol library \"%s\" already exists, cannot create a new library" ),
|
2016-10-05 23:28:56 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
LOCALE_IO toggle;
|
|
|
|
|
|
|
|
m_props = aProperties;
|
|
|
|
|
|
|
|
delete m_cache;
|
|
|
|
m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
|
2017-01-27 15:56:36 +00:00
|
|
|
m_cache->SetModified();
|
|
|
|
m_cache->Save( writeDocFile( aProperties ) );
|
2016-10-05 23:28:56 +00:00
|
|
|
m_cache->Load(); // update m_writable and m_mod_time
|
|
|
|
}
|
2016-10-09 12:29:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool SCH_LEGACY_PLUGIN::DeleteSymbolLib( const wxString& aLibraryPath,
|
|
|
|
const PROPERTIES* aProperties )
|
|
|
|
{
|
|
|
|
wxFileName fn = aLibraryPath;
|
|
|
|
|
|
|
|
if( !fn.FileExists() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
|
|
|
|
// we don't want that. we want bare metal portability with no UI here.
|
|
|
|
if( wxRemove( aLibraryPath ) )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "library \"%s\" cannot be deleted" ),
|
2016-10-09 12:29:44 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_cache && m_cache->IsFile( aLibraryPath ) )
|
|
|
|
{
|
|
|
|
delete m_cache;
|
|
|
|
m_cache = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-27 15:56:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::SaveLibrary( const wxString& aLibraryPath, const PROPERTIES* aProperties )
|
|
|
|
{
|
2017-02-12 23:40:53 +00:00
|
|
|
if( !m_cache )
|
|
|
|
m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
|
2017-01-27 15:56:36 +00:00
|
|
|
|
2017-02-12 23:40:53 +00:00
|
|
|
wxString oldFileName = m_cache->GetFileName();
|
2017-01-27 15:56:36 +00:00
|
|
|
|
2017-02-12 23:40:53 +00:00
|
|
|
if( !m_cache->IsFile( aLibraryPath ) )
|
|
|
|
{
|
|
|
|
m_cache->SetFileName( aLibraryPath );
|
2017-01-27 15:56:36 +00:00
|
|
|
}
|
2017-02-12 23:40:53 +00:00
|
|
|
|
|
|
|
// This is a forced save.
|
|
|
|
m_cache->SetModified();
|
|
|
|
m_cache->Save( writeDocFile( aProperties ) );
|
|
|
|
m_cache->SetFileName( oldFileName );
|
2017-01-27 15:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-21 12:41:00 +00:00
|
|
|
bool SCH_LEGACY_PLUGIN::CheckHeader( const wxString& aFileName )
|
|
|
|
{
|
|
|
|
// Open file and check first line
|
|
|
|
wxTextFile tempFile;
|
|
|
|
|
|
|
|
tempFile.Open( aFileName );
|
|
|
|
wxString firstline;
|
|
|
|
// read the first line
|
|
|
|
firstline = tempFile.GetFirstLine();
|
|
|
|
tempFile.Close();
|
|
|
|
|
|
|
|
return firstline.StartsWith( "EESchema" );
|
|
|
|
}
|
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
|
|
|
|
bool SCH_LEGACY_PLUGIN::IsSymbolLibWritable( const wxString& aLibraryPath )
|
|
|
|
{
|
|
|
|
return wxFileName::IsFileWritable( aLibraryPath );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-15 13:09:42 +00:00
|
|
|
LIB_PART* SCH_LEGACY_PLUGIN::ParsePart( LINE_READER& reader, int aMajorVersion,
|
|
|
|
int aMinorVersion )
|
2019-03-14 18:57:16 +00:00
|
|
|
{
|
2019-03-15 13:09:42 +00:00
|
|
|
return SCH_LEGACY_PLUGIN_CACHE::LoadPart( reader, aMajorVersion, aMinorVersion );
|
2019-03-14 18:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-15 13:09:42 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::FormatPart( LIB_PART* part, OUTPUTFORMATTER & formatter )
|
2019-03-14 18:57:16 +00:00
|
|
|
{
|
|
|
|
SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( part, formatter );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
const char* SCH_LEGACY_PLUGIN::PropBuffering = "buffering";
|
|
|
|
const char* SCH_LEGACY_PLUGIN::PropNoDocFile = "no_doc_file";
|