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
|
2023-01-04 20:39:50 +00:00
|
|
|
* Copyright (C) 2016-2023 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>
|
2021-04-18 17:39:46 +00:00
|
|
|
#include <mutex>
|
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>
|
2021-06-01 05:17:57 +00:00
|
|
|
#include <wx/log.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <wx/textfile.h>
|
2016-07-11 19:48:46 +00:00
|
|
|
#include <wx/tokenzr.h>
|
2021-07-25 12:10:36 +00:00
|
|
|
#include <wx_filename.h> // For ::ResolvePossibleSymlinks()
|
2020-01-28 15:42:42 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
#include <kiway.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2016-07-06 09:22:56 +00:00
|
|
|
#include <richio.h>
|
2018-04-13 13:58:25 +00:00
|
|
|
#include <trace_helpers.h>
|
2021-06-08 14:09:24 +00:00
|
|
|
#include <trigo.h>
|
2021-08-14 20:05:21 +00:00
|
|
|
#include <progress_reporter.h>
|
2021-03-22 12:19:47 +00:00
|
|
|
#include <general.h>
|
2021-07-17 19:56:18 +00:00
|
|
|
#include <gr_text.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>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.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>
|
2021-04-06 21:15:49 +00:00
|
|
|
#include <sch_sheet_pin.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <bus_alias.h>
|
2022-02-01 23:43:37 +00:00
|
|
|
#include <sch_plugins/legacy/sch_legacy_lib_plugin_cache.h>
|
2020-10-05 18:38:40 +00:00
|
|
|
#include <sch_plugins/legacy/sch_legacy_plugin.h>
|
2022-02-01 21:29:54 +00:00
|
|
|
#include <sch_plugins/legacy/sch_legacy_plugin_helpers.h>
|
2018-01-30 08:56:43 +00:00
|
|
|
#include <sch_screen.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2021-06-15 13:24:55 +00:00
|
|
|
#include <symbol_library.h>
|
2017-09-02 18:12:50 +00:00
|
|
|
#include <eeschema_id.h> // for MAX_UNIT_COUNT_PER_PACKAGE definition
|
2019-04-28 16:36:31 +00:00
|
|
|
#include <tool/selection.h>
|
2022-01-29 19:07:07 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
|
2017-11-15 13:08:27 +00:00
|
|
|
// Tokens to read/save graphic lines style
|
|
|
|
#define T_STYLE "style"
|
2021-06-09 19:32:58 +00:00
|
|
|
#define T_COLOR "rgb" // cannot be modified (used by wxWidgets)
|
|
|
|
#define T_COLORA "rgba" // cannot be modified (used by wxWidgets)
|
2017-11-15 13:08:27 +00:00
|
|
|
#define T_WIDTH "width"
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
SCH_LEGACY_PLUGIN::SCH_LEGACY_PLUGIN() :
|
2022-10-01 12:44:21 +00:00
|
|
|
m_appending( false ),
|
2021-06-23 22:53:08 +00:00
|
|
|
m_progressReporter( nullptr ),
|
|
|
|
m_lineReader( nullptr ),
|
|
|
|
m_lastProgressLine( 0 ),
|
|
|
|
m_lineCount( 0 )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
init( nullptr );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-28 04:30:13 +00:00
|
|
|
SCH_LEGACY_PLUGIN::~SCH_LEGACY_PLUGIN()
|
|
|
|
{
|
|
|
|
delete m_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-06 16:51:52 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::init( SCHEMATIC* aSchematic, const STRING_UTF8_MAP* aProperties )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2020-05-19 02:58:28 +00:00
|
|
|
m_version = 0;
|
|
|
|
m_rootSheet = nullptr;
|
2022-10-17 13:19:39 +00:00
|
|
|
m_currentSheet = nullptr;
|
2020-05-21 03:00:23 +00:00
|
|
|
m_schematic = aSchematic;
|
2020-05-19 02:58:28 +00:00
|
|
|
m_cache = nullptr;
|
|
|
|
m_out = nullptr;
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::checkpoint()
|
|
|
|
{
|
|
|
|
const unsigned PROGRESS_DELTA = 250;
|
|
|
|
|
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
unsigned curLine = m_lineReader->LineNumber();
|
|
|
|
|
|
|
|
if( curLine > m_lastProgressLine + PROGRESS_DELTA )
|
|
|
|
{
|
2021-06-24 10:09:03 +00:00
|
|
|
m_progressReporter->SetCurrentProgress( ( (double) curLine )
|
|
|
|
/ std::max( 1U, m_lineCount ) );
|
2021-06-23 22:53:08 +00:00
|
|
|
|
|
|
|
if( !m_progressReporter->KeepRefreshing() )
|
|
|
|
THROW_IO_ERROR( ( "Open cancelled by user." ) );
|
|
|
|
|
|
|
|
m_lastProgressLine = curLine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-21 03:00:23 +00:00
|
|
|
SCH_SHEET* SCH_LEGACY_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
2022-11-06 16:51:52 +00:00
|
|
|
SCH_SHEET* aAppendToMe, const STRING_UTF8_MAP* aProperties )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxASSERT( !aFileName || aSchematic != nullptr );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
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() )
|
2020-05-21 03:00:23 +00:00
|
|
|
m_path = aSchematic->Prj().GetProjectPath();
|
2018-04-22 13:47:54 +00:00
|
|
|
|
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
|
|
|
|
{
|
2020-05-21 03:00:23 +00:00
|
|
|
m_path = aSchematic->Prj().GetProjectPath();
|
2018-02-05 14:01:55 +00:00
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2018-05-09 09:15:00 +00:00
|
|
|
m_currentPath.push( m_path );
|
2020-05-21 03:00:23 +00:00
|
|
|
init( aSchematic, aProperties );
|
2020-05-19 13:08:49 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( aAppendToMe == nullptr )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
// Clean up any allocated memory if an exception occurs loading the schematic.
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic );
|
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();
|
2020-05-19 02:58:28 +00:00
|
|
|
m_rootSheet = nullptr; // Quiet Coverity warning.
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-01 12:44:21 +00:00
|
|
|
m_appending = true;
|
2020-05-13 02:00:37 +00:00
|
|
|
wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
|
|
|
|
m_rootSheet = &aSchematic->Root();
|
2016-07-06 09:22:56 +00:00
|
|
|
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 )
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
SCH_SCREEN* screen = nullptr;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2022-10-15 18:15:51 +00:00
|
|
|
m_currentSheet = aSheet;
|
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
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();
|
2020-04-22 20:00:48 +00:00
|
|
|
fileName.SetExt( "sch" );
|
2016-07-25 00:52:40 +00:00
|
|
|
|
|
|
|
if( !fileName.IsAbsolute() )
|
2018-05-09 09:15:00 +00:00
|
|
|
fileName.MakeAbsolute( m_currentPath.top() );
|
2016-07-25 00:52:40 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// Save the current path so that it gets restored when descending and ascending the
|
2018-02-05 14:01:55 +00:00
|
|
|
// sheet hierarchy which allows for sheet schematic files to be nested in folders
|
|
|
|
// relative to the last path a schematic was loaded from.
|
2021-06-26 11:33:37 +00:00
|
|
|
wxLogTrace( traceSchLegacyPlugin, "Saving path '%s'", m_currentPath.top() );
|
2018-05-09 09:15:00 +00:00
|
|
|
m_currentPath.push( fileName.GetPath() );
|
2021-06-26 11:33:37 +00:00
|
|
|
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 );
|
2020-05-13 02:00:37 +00:00
|
|
|
screen->SetParent( m_schematic );
|
2016-07-06 09:22:56 +00:00
|
|
|
// Do not need to load the sub-sheets - this has already been done.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-21 02:27:48 +00:00
|
|
|
aSheet->SetScreen( new SCH_SCREEN( m_schematic ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
|
|
|
|
|
2022-10-15 18:15:51 +00:00
|
|
|
if( aSheet == m_rootSheet )
|
|
|
|
const_cast<KIID&>( aSheet->m_Uuid ) = aSheet->GetScreen()->GetUuid();
|
|
|
|
|
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() );
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2020-04-26 19:46:53 +00:00
|
|
|
|
2021-10-14 13:12:40 +00:00
|
|
|
aSheet->GetScreen()->SetFileReadOnly( !fileName.IsFileWritable() );
|
|
|
|
aSheet->GetScreen()->SetFileExists( true );
|
|
|
|
|
2022-08-15 17:47:23 +00:00
|
|
|
for( SCH_ITEM* aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
|
2020-04-26 19:46:53 +00:00
|
|
|
{
|
|
|
|
wxCHECK2( aItem->Type() == SCH_SHEET_T, continue );
|
|
|
|
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
|
|
|
}
|
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 );
|
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
|
|
|
|
|
|
|
|
if( !m_progressReporter->KeepRefreshing() )
|
|
|
|
THROW_IO_ERROR( ( "Open cancelled by user." ) );
|
|
|
|
|
|
|
|
m_lineReader = &reader;
|
|
|
|
m_lineCount = 0;
|
|
|
|
|
|
|
|
while( reader.ReadLine() )
|
|
|
|
m_lineCount++;
|
|
|
|
|
|
|
|
reader.Rewind();
|
|
|
|
}
|
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
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
|
Fix source comment/doc typos (follow-up)
Found via `codespell -q 3 -S *.po,./thirdparty -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,dout,einstance,modul,ot,overide,serie,te,,tesselate,tesselator,tht`
2021-07-03 22:37:31 +00:00
|
|
|
// so checking for its existance will fail so just exit here and take our chances. :(
|
2019-04-28 16:36:31 +00:00
|
|
|
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-05-13 02:00:37 +00:00
|
|
|
// We cannot safely load content without a set root level.
|
|
|
|
wxCHECK_RET( m_rootSheet,
|
|
|
|
"Cannot call SCH_LEGACY_PLUGIN::LoadContent() without setting root sheet." );
|
2020-02-28 19:08:48 +00:00
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
while( aReader.ReadLine() )
|
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
checkpoint();
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
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 ) )
|
2021-05-05 21:41:51 +00:00
|
|
|
aScreen->Append( loadSymbol( 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
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
m_error.Printf( _( "'%s' does not appear to be an Eeschema file." ),
|
|
|
|
aScreen->GetFileName() );
|
2016-07-06 09:22:56 +00:00
|
|
|
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() )
|
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
checkpoint();
|
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
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
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxASSERT( aScreen != nullptr );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
while( line != nullptr )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
buf.clear();
|
|
|
|
|
|
|
|
if( !aReader.ReadLine() )
|
|
|
|
SCH_PARSE_ERROR( _( "unexpected end of file" ), aReader, line );
|
|
|
|
|
|
|
|
line = aReader.Line();
|
|
|
|
|
|
|
|
if( strCompare( "Sheet", line, &line ) )
|
|
|
|
{
|
2020-10-18 20:30:37 +00:00
|
|
|
aScreen->SetVirtualPageNumber( parseInt( aReader, line, &line ) );
|
|
|
|
aScreen->SetPageCount( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<SCH_SHEET> sheet = std::make_unique<SCH_SHEET>();
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
const char* line = aReader.ReadLine();
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
while( line != nullptr )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
if( strCompare( "S", line, &line ) ) // Sheet dimensions.
|
|
|
|
{
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I position;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
|
|
|
position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
sheet->SetPosition( position );
|
|
|
|
|
|
|
|
wxSize size;
|
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
size.SetWidth( schIUScale.MilsToIU( parseInt( aReader, line, &line ) ) );
|
|
|
|
size.SetHeight( schIUScale.MilsToIU( 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 );
|
2022-09-16 23:42:20 +00:00
|
|
|
size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2020-03-13 09:53:44 +00:00
|
|
|
SCH_FIELD& field = sheet->GetFields()[ fieldId ];
|
|
|
|
field.SetText( text );
|
|
|
|
field.SetTextSize( wxSize( size, size ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
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
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<SCH_SHEET_PIN> sheetPin = std::make_unique<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 );
|
|
|
|
|
2021-08-17 17:51:13 +00:00
|
|
|
sheetPin->SetText( ConvertToNewOverbarNotation( text ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( line == nullptr )
|
2016-07-06 09:22:56 +00:00
|
|
|
THROW_IO_ERROR( _( "unexpected end of line" ) );
|
|
|
|
|
|
|
|
switch( parseChar( aReader, line, &line ) )
|
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
case 'I': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_INPUT ); break;
|
|
|
|
case 'O': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT ); break;
|
|
|
|
case 'B': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_BIDI ); break;
|
|
|
|
case 'T': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE ); break;
|
|
|
|
case 'U': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED ); break;
|
2020-02-20 21:29:21 +00:00
|
|
|
default: SCH_PARSE_ERROR( "invalid sheet pin type", aReader, line );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( parseChar( aReader, line, &line ) )
|
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
case 'R': sheetPin->SetSide( SHEET_SIDE::RIGHT ); break;
|
|
|
|
case 'T': sheetPin->SetSide( SHEET_SIDE::TOP ); break;
|
2021-11-28 19:06:08 +00:00
|
|
|
case 'B': sheetPin->SetSide( SHEET_SIDE::BOTTOM ); break;
|
2021-10-12 20:05:37 +00:00
|
|
|
case 'L': sheetPin->SetSide( SHEET_SIDE::LEFT ); 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
|
|
|
}
|
|
|
|
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I position;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
|
|
|
position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
sheetPin->SetPosition( position );
|
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
size = schIUScale.MilsToIU( 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
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
sheet->AutoplaceFields( /* aScreen */ nullptr, /* 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
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return nullptr; // Prevents compiler warning. Should never get here.
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>();
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK( strCompare( "$Bitmap", line, &line ), nullptr );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
while( line != nullptr )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
if( strCompare( "Pos", line, &line ) )
|
|
|
|
{
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I position;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
|
|
|
position.y = schIUScale.MilsToIU( 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 );
|
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
|
2021-12-01 10:05:16 +00:00
|
|
|
// Note:
|
|
|
|
// Some old files created bu the V4 schematic versions have a extra
|
|
|
|
// "$EndBitmap" at the end of the hexadecimal data. (Probably due to
|
|
|
|
// a bug). So discard it
|
2016-07-06 09:22:56 +00:00
|
|
|
int len = strlen( line );
|
|
|
|
|
2021-12-01 09:54:48 +00:00
|
|
|
for( ; len > 0 && !isspace( *line ) && '$' != *line; len -= 3, line += 3 )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
int value = 0;
|
|
|
|
|
|
|
|
if( sscanf( line, "%X", &value ) == 1 )
|
|
|
|
stream.PutC( (char) value );
|
|
|
|
else
|
|
|
|
THROW_IO_ERROR( "invalid PNG data" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( line == nullptr )
|
2016-07-06 09:22:56 +00:00
|
|
|
THROW_IO_ERROR( _( "unexpected end of file" ) );
|
|
|
|
}
|
|
|
|
else if( strCompare( "$EndBitmap", line ) )
|
2022-09-26 18:37:45 +00:00
|
|
|
{
|
2016-07-06 09:22:56 +00:00
|
|
|
return bitmap.release();
|
2022-09-26 18:37:45 +00:00
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>();
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK( strCompare( "Connection", line, &line ), nullptr );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
wxString name;
|
|
|
|
|
|
|
|
parseUnquotedString( name, aReader, line, &line );
|
|
|
|
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I position;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
|
|
|
position.y = schIUScale.MilsToIU( 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
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<SCH_NO_CONNECT> no_connect = std::make_unique<SCH_NO_CONNECT>();
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK( strCompare( "NoConn", line, &line ), nullptr );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
wxString name;
|
|
|
|
|
|
|
|
parseUnquotedString( name, aReader, line, &line );
|
|
|
|
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I position;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
|
|
|
position.y = schIUScale.MilsToIU( 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
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>();
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK( strCompare( "Wire", line, &line ), nullptr );
|
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 )
|
|
|
|
{
|
2022-09-16 23:42:20 +00:00
|
|
|
int size = schIUScale.MilsToIU( 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 );
|
2022-03-20 15:57:18 +00:00
|
|
|
|
|
|
|
if( buf == wxT( "solid" ) )
|
|
|
|
wire->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
|
|
|
else if( buf == wxT( "dashed" ) )
|
|
|
|
wire->SetLineStyle( PLOT_DASH_TYPE::DASH );
|
|
|
|
else if( buf == wxT( "dash_dot" ) )
|
|
|
|
wire->SetLineStyle( PLOT_DASH_TYPE::DASHDOT );
|
|
|
|
else if( buf == wxT( "dotted" ) )
|
|
|
|
wire->SetLineStyle( PLOT_DASH_TYPE::DOT );
|
2017-11-15 13:08:27 +00:00
|
|
|
}
|
|
|
|
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;
|
2022-10-17 13:19:39 +00:00
|
|
|
|
2017-11-15 13:08:27 +00:00
|
|
|
// 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();
|
|
|
|
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I begin, end;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
begin.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
|
|
|
begin.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
|
|
|
end.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
|
|
|
end.y = schIUScale.MilsToIU( 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();
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK( strCompare( "Entry", line, &line ), nullptr );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<SCH_BUS_ENTRY_BASE> busEntry;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
if( strCompare( "Wire", line, &line ) )
|
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
busEntry = std::make_unique<SCH_BUS_WIRE_ENTRY>();
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
if( !strCompare( "Line", line, &line ) )
|
|
|
|
SCH_PARSE_ERROR( "invalid bus entry definition expected 'Line'", aReader, line );
|
|
|
|
}
|
|
|
|
else if( strCompare( "Bus", line, &line ) )
|
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
busEntry = std::make_unique<SCH_BUS_BUS_ENTRY>();
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
if( !strCompare( "Bus", line, &line ) )
|
|
|
|
SCH_PARSE_ERROR( "invalid bus entry definition expected 'Bus'", aReader, line );
|
|
|
|
}
|
|
|
|
else
|
2022-09-26 18:37:45 +00:00
|
|
|
{
|
2016-07-06 09:22:56 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid bus entry type", aReader, line );
|
2022-09-26 18:37:45 +00:00
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I pos;
|
2016-07-06 09:22:56 +00:00
|
|
|
wxSize size;
|
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
pos.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
|
|
|
pos.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
|
|
|
size.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
|
|
|
size.y = schIUScale.MilsToIU( 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();
|
|
|
|
}
|
|
|
|
|
2022-10-17 13:19:39 +00:00
|
|
|
|
2020-01-08 19:07:55 +00:00
|
|
|
// clang-format off
|
2021-10-12 20:05:37 +00:00
|
|
|
const std::map<LABEL_FLAG_SHAPE, const char*> sheetLabelNames
|
2020-01-08 19:07:55 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
{ LABEL_FLAG_SHAPE::L_INPUT, "Input" },
|
|
|
|
{ LABEL_FLAG_SHAPE::L_OUTPUT, "Output" },
|
|
|
|
{ LABEL_FLAG_SHAPE::L_BIDI, "BiDi" },
|
|
|
|
{ LABEL_FLAG_SHAPE::L_TRISTATE, "3State" },
|
|
|
|
{ LABEL_FLAG_SHAPE::L_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
|
|
|
{
|
2022-09-26 18:37:45 +00:00
|
|
|
const char* line = aReader.Line();
|
|
|
|
KICAD_T textType = TYPE_NOT_INIT;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK( strCompare( "Text", line, &line ), nullptr );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
if( strCompare( "Notes", line, &line ) )
|
2022-09-26 18:37:45 +00:00
|
|
|
{
|
|
|
|
textType = SCH_TEXT_T;
|
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
else if( strCompare( "Label", line, &line ) )
|
2022-09-26 18:37:45 +00:00
|
|
|
{
|
|
|
|
textType = SCH_LABEL_T;
|
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
else if( strCompare( "HLabel", line, &line ) )
|
2022-09-26 18:37:45 +00:00
|
|
|
{
|
|
|
|
textType = SCH_HIER_LABEL_T;
|
|
|
|
}
|
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 )
|
2022-09-26 18:37:45 +00:00
|
|
|
textType = SCH_HIER_LABEL_T;
|
2016-07-07 13:09:32 +00:00
|
|
|
else
|
2022-09-26 18:37:45 +00:00
|
|
|
textType = SCH_GLOBAL_LABEL_T;
|
2016-07-07 13:09:32 +00:00
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
else
|
2022-09-26 18:37:45 +00:00
|
|
|
{
|
2016-07-06 09:22:56 +00:00
|
|
|
SCH_PARSE_ERROR( "unknown Text type", aReader, line );
|
2022-09-26 18:37:45 +00:00
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I position;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
|
|
|
position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
2022-09-26 18:37:45 +00:00
|
|
|
|
|
|
|
std::unique_ptr<SCH_TEXT> text;
|
|
|
|
|
|
|
|
switch( textType )
|
|
|
|
{
|
|
|
|
case SCH_TEXT_T: text.reset( new SCH_TEXT( position ) ); break;
|
|
|
|
case SCH_LABEL_T: text.reset( new SCH_LABEL( position ) ); break;
|
|
|
|
case SCH_HIER_LABEL_T: text.reset( new SCH_HIERLABEL( position ) ); break;
|
|
|
|
case SCH_GLOBAL_LABEL_T: text.reset( new SCH_GLOBALLABEL( position ) ); break;
|
|
|
|
default: break;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2022-01-24 13:40:39 +00:00
|
|
|
text->SetTextSpinStyle( static_cast<TEXT_SPIN_STYLE::SPIN>( spinStyle ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
int size = schIUScale.MilsToIU( 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
|
|
|
}
|
|
|
|
|
2020-04-13 19:55:27 +00:00
|
|
|
int penWidth = 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
|
|
|
|
2020-04-13 19:55:27 +00:00
|
|
|
// The penWidth 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 >= ' ' )
|
2020-04-13 19:55:27 +00:00
|
|
|
penWidth = parseInt( aReader, line, &line );
|
2016-07-07 13:09:32 +00:00
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2020-04-13 19:55:27 +00:00
|
|
|
text->SetBold( penWidth != 0 );
|
2020-04-14 12:25:00 +00:00
|
|
|
text->SetTextThickness( penWidth != 0 ? GetPenSizeForBold( size ) : 0 );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
// 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" ) );
|
|
|
|
}
|
|
|
|
|
2021-07-25 12:10:36 +00:00
|
|
|
text->SetText( ConvertToNewOverbarNotation( val ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
return text.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* SCH_LEGACY_PLUGIN::loadSymbol( LINE_READER& aReader )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK( strCompare( "$Comp", line, &line ), nullptr );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
std::unique_ptr<SCH_SYMBOL> symbol = std::make_unique<SCH_SYMBOL>();
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
while( line != nullptr )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
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 )
|
2020-12-17 23:32:23 +00:00
|
|
|
libId.Parse( libName, true );
|
2017-11-23 15:52:28 +00:00
|
|
|
else
|
2021-06-30 11:00:06 +00:00
|
|
|
libId.SetLibItemName( libName );
|
2017-01-31 01:31:19 +00:00
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
symbol->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() )
|
2021-05-05 21:41:51 +00:00
|
|
|
symbol->SetPrefix( wxString( "U" ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
else
|
2021-05-05 21:41:51 +00:00
|
|
|
symbol->SetPrefix( prefix );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
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.
|
2020-04-06 09:15:57 +00:00
|
|
|
if( m_rootSheet->GetScreen() )
|
2021-05-28 19:07:04 +00:00
|
|
|
m_rootSheet->GetScreen()->SetContentModified();
|
2017-03-30 19:44:47 +00:00
|
|
|
}
|
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
symbol->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.
|
2020-04-06 09:15:57 +00:00
|
|
|
if( m_rootSheet->GetScreen() )
|
2021-05-28 19:07:04 +00:00
|
|
|
m_rootSheet->GetScreen()->SetContentModified();
|
2019-03-23 22:51:13 +00:00
|
|
|
}
|
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
symbol->SetConvert( convert );
|
2019-03-23 22:51:13 +00:00
|
|
|
|
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" )
|
2021-05-05 21:41:51 +00:00
|
|
|
const_cast<KIID&>( symbol->m_Uuid ) = KIID( text );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
else if( strCompare( "P", line, &line ) )
|
|
|
|
{
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I pos;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
pos.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
|
|
|
pos.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
2021-05-05 21:41:51 +00:00
|
|
|
symbol->SetPosition( pos );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
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 );
|
|
|
|
|
2022-10-01 12:44:21 +00:00
|
|
|
// Note: AR path excludes root sheet, but includes symbol. Drop the symbol ID
|
|
|
|
// since it's already defined in the symbol itself.
|
2020-02-22 21:39:59 +00:00
|
|
|
KIID_PATH path( pathStr );
|
|
|
|
|
|
|
|
if( path.size() > 0 )
|
2022-10-01 12:44:21 +00:00
|
|
|
path.pop_back();
|
2020-02-22 21:39:59 +00:00
|
|
|
|
2022-10-01 12:44:21 +00:00
|
|
|
// In the new file format, the root schematic UUID is used as the virtual SCH_SHEET
|
|
|
|
// UUID so we need to prefix it to the symbol path so the symbol instance paths
|
|
|
|
// get saved with the root schematic UUID.
|
|
|
|
if( !m_appending )
|
2022-10-15 18:50:06 +00:00
|
|
|
path.insert( path.begin(), m_rootSheet->GetScreen()->GetUuid() );
|
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 );
|
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
symbol->AddHierarchicalReference( path, reference, (int)tmp );
|
|
|
|
symbol->GetField( REFERENCE_FIELD )->SetText( reference );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
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 );
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I pos;
|
2022-09-16 23:42:20 +00:00
|
|
|
pos.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
|
|
|
pos.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
|
|
|
int size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
int attributes = parseHex( aReader, line, &line );
|
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
if( index >= symbol->GetFieldCount() )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
// The first MANDATOR_FIELDS _must_ be constructed within the SCH_SYMBOL
|
2021-05-05 21:41:51 +00:00
|
|
|
// constructor. This assert is simply here to guard against a change in that
|
|
|
|
// constructor.
|
|
|
|
wxASSERT( symbol->GetFieldCount() >= MANDATORY_FIELDS );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
// Ignore the _supplied_ fieldNdx. It is not important anymore if within the
|
|
|
|
// user defined fields region (i.e. >= MANDATORY_FIELDS).
|
2016-07-06 09:22:56 +00:00
|
|
|
// We freely renumber the index to fit the next available field slot.
|
2021-05-05 21:41:51 +00:00
|
|
|
index = symbol->GetFieldCount(); // new has this index after insertion
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2022-01-01 18:08:03 +00:00
|
|
|
SCH_FIELD field( VECTOR2I( 0, 0 ), index, symbol.get(), name );
|
2021-05-05 21:41:51 +00:00
|
|
|
symbol->AddField( field );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
2016-07-07 13:09:32 +00:00
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
SCH_FIELD& field = symbol->GetFields()[index];
|
2021-02-28 13:28:23 +00:00
|
|
|
|
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' )
|
2021-12-28 22:13:54 +00:00
|
|
|
field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2016-07-07 13:09:32 +00:00
|
|
|
else if( hjustify == 'R' )
|
2021-12-28 22:13:54 +00:00
|
|
|
field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2016-07-07 13:09:32 +00:00
|
|
|
else if( hjustify != 'C' )
|
2021-05-05 21:41:51 +00:00
|
|
|
SCH_PARSE_ERROR( "symbol field text horizontal justification must be "
|
2017-08-04 18:43:31 +00:00
|
|
|
"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' )
|
2021-12-28 22:13:54 +00:00
|
|
|
field.SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
2016-07-07 13:09:32 +00:00
|
|
|
else if( textAttrs[0] == 'B' )
|
2021-12-28 22:13:54 +00:00
|
|
|
field.SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2016-07-07 13:09:32 +00:00
|
|
|
else if( textAttrs[0] != 'C' )
|
2021-05-05 21:41:51 +00:00
|
|
|
SCH_PARSE_ERROR( "symbol field text vertical justification must be "
|
2017-08-04 18:43:31 +00:00
|
|
|
"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 )
|
2022-09-26 18:37:45 +00:00
|
|
|
{
|
2021-05-05 21:41:51 +00:00
|
|
|
SCH_PARSE_ERROR( _( "symbol field text attributes must be 3 characters wide" ),
|
2016-12-29 18:38:31 +00:00
|
|
|
aReader, line );
|
2022-09-26 18:37:45 +00:00
|
|
|
}
|
2016-12-29 18:38:31 +00:00
|
|
|
|
|
|
|
if( textAttrs[1] == 'I' )
|
2022-09-26 18:37:45 +00:00
|
|
|
{
|
2021-02-28 13:28:23 +00:00
|
|
|
field.SetItalic( true );
|
2022-09-26 18:37:45 +00:00
|
|
|
}
|
2016-12-29 18:38:31 +00:00
|
|
|
else if( textAttrs[1] != 'N' )
|
2022-09-26 18:37:45 +00:00
|
|
|
{
|
2021-05-05 21:41:51 +00:00
|
|
|
SCH_PARSE_ERROR( "symbol field text italics indicator must be I or N",
|
2016-12-29 18:38:31 +00:00
|
|
|
aReader, line );
|
2022-09-26 18:37:45 +00:00
|
|
|
}
|
2016-12-29 18:38:31 +00:00
|
|
|
|
|
|
|
if( textAttrs[2] == 'B' )
|
2022-09-26 18:37:45 +00:00
|
|
|
{
|
2021-02-28 13:28:23 +00:00
|
|
|
field.SetBold( true );
|
2022-09-26 18:37:45 +00:00
|
|
|
}
|
2016-12-29 18:38:31 +00:00
|
|
|
else if( textAttrs[2] != 'N' )
|
2022-09-26 18:37:45 +00:00
|
|
|
{
|
2021-05-05 21:41:51 +00:00
|
|
|
SCH_PARSE_ERROR( "symbol field text bold indicator must be B or N",
|
2016-12-29 18:38:31 +00:00
|
|
|
aReader, line );
|
2022-09-26 18:37:45 +00:00
|
|
|
}
|
2016-12-29 18:38:31 +00:00
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
2021-02-28 13:28:23 +00:00
|
|
|
field.SetText( text );
|
|
|
|
field.SetTextPos( pos );
|
|
|
|
field.SetVisible( !attributes );
|
|
|
|
field.SetTextSize( wxSize( size, size ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
if( orientation == 'H' )
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_HORIZONTAL );
|
2016-07-06 09:22:56 +00:00
|
|
|
else if( orientation == 'V' )
|
2022-01-13 12:29:46 +00:00
|
|
|
field.SetTextAngle( ANGLE_VERTICAL );
|
2016-07-06 09:22:56 +00:00
|
|
|
else
|
2021-05-05 21:41:51 +00:00
|
|
|
SCH_PARSE_ERROR( "symbol field orientation must be H or V", aReader, line );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2016-07-07 13:09:32 +00:00
|
|
|
if( name.IsEmpty() )
|
|
|
|
name = TEMPLATE_FIELDNAME::GetDefaultFieldName( index );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2021-02-28 13:28:23 +00:00
|
|
|
field.SetName( name );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
else if( strCompare( "$EndComp", line ) )
|
2016-08-01 07:11:31 +00:00
|
|
|
{
|
2022-10-19 16:22:55 +00:00
|
|
|
if( !m_appending )
|
2022-10-15 18:15:51 +00:00
|
|
|
{
|
2022-10-19 16:22:55 +00:00
|
|
|
if( m_currentSheet == m_rootSheet )
|
|
|
|
{
|
|
|
|
KIID_PATH path;
|
|
|
|
path.push_back( m_rootSheet->GetScreen()->GetUuid() );
|
2022-11-20 17:04:44 +00:00
|
|
|
|
2023-01-04 20:39:50 +00:00
|
|
|
SCH_SYMBOL_INSTANCE instance;
|
2022-11-20 17:04:44 +00:00
|
|
|
instance.m_Path = path;
|
|
|
|
instance.m_Reference = symbol->GetField( REFERENCE_FIELD )->GetText();
|
|
|
|
instance.m_Unit = symbol->GetUnit();
|
|
|
|
symbol->AddHierarchicalReference( instance );
|
2022-10-19 16:22:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-04 20:39:50 +00:00
|
|
|
for( const SCH_SYMBOL_INSTANCE& instance : symbol->GetInstanceReferences() )
|
2022-10-19 16:22:55 +00:00
|
|
|
{
|
2023-01-04 20:39:50 +00:00
|
|
|
SCH_SYMBOL_INSTANCE tmpInstance = instance;
|
2022-11-20 17:04:44 +00:00
|
|
|
symbol->AddHierarchicalReference( tmpInstance );
|
2022-10-19 16:22:55 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-15 18:15:51 +00:00
|
|
|
}
|
|
|
|
|
2016-08-01 07:11:31 +00:00
|
|
|
// Ensure all flags (some are set by previous initializations) are reset:
|
2021-05-05 21:41:51 +00:00
|
|
|
symbol->ClearFlags();
|
|
|
|
return symbol.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 )
|
2021-05-05 21:41:51 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid symbol 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 )
|
2021-05-05 21:41:51 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid symbol 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 )
|
2021-05-05 21:41:51 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid symbol 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 )
|
2021-05-05 21:41:51 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid symbol Y2 transform value", aReader, line );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
symbol->SetTransform( transform );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
line = aReader.ReadLine();
|
|
|
|
}
|
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
SCH_PARSE_ERROR( "invalid symbol line", aReader, line );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return nullptr; // Prevents compiler warning. Should never get here.
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
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
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
auto busAlias = std::make_shared<BUS_ALIAS>( aScreen );
|
2019-03-11 21:32:05 +00:00
|
|
|
const char* line = aReader.Line();
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK( strCompare( "BusAlias", line, &line ), nullptr );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
wxString buf;
|
|
|
|
parseUnquotedString( buf, aReader, line, &line );
|
|
|
|
busAlias->SetName( buf );
|
|
|
|
|
|
|
|
while( *line != '\0' )
|
|
|
|
{
|
|
|
|
buf.clear();
|
|
|
|
parseUnquotedString( buf, aReader, line, &line, true );
|
2021-10-14 13:12:40 +00:00
|
|
|
|
2022-08-22 16:52:42 +00:00
|
|
|
if( !buf.IsEmpty() )
|
|
|
|
busAlias->Members().emplace_back( buf );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return busAlias;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-22 12:19:47 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2021-03-22 12:19:47 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET object." );
|
2021-03-22 12:19:47 +00:00
|
|
|
wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
|
|
|
|
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
|
|
|
|
|
|
|
|
init( aSchematic, 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( aSheet );
|
2021-10-14 13:12:40 +00:00
|
|
|
|
|
|
|
aSheet->GetScreen()->SetFileExists( true );
|
2021-03-22 12:19:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::Format( SCH_SHEET* aSheet )
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET* object." );
|
|
|
|
wxCHECK_RET( m_schematic != nullptr, "NULL SCHEMATIC* object." );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
SCH_SCREEN* screen = aSheet->GetScreen();
|
|
|
|
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
|
|
|
// 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
|
|
|
|
m_out->Print( 0, "EELAYER %d %d\n", SCH_LAYER_ID_COUNT, 0 );
|
|
|
|
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 = screen->GetTitleBlock();
|
|
|
|
const PAGE_INFO& page = screen->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", screen->GetVirtualPageNumber(), screen->GetPageCount() );
|
|
|
|
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() );
|
|
|
|
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() );
|
|
|
|
m_out->Print( 0, "$EndDescr\n" );
|
|
|
|
|
2022-09-11 17:41:54 +00:00
|
|
|
for( const std::shared_ptr<BUS_ALIAS>& alias : screen->GetBusAliases() )
|
2021-03-22 12:19:47 +00:00
|
|
|
saveBusAlias( alias );
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
|
2022-08-15 17:47:23 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items() )
|
2021-03-22 12:19:47 +00:00
|
|
|
save_map.insert( item );
|
|
|
|
|
|
|
|
|
|
|
|
for( auto& item : save_map )
|
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
case SCH_SYMBOL_T:
|
|
|
|
saveSymbol( static_cast<SCH_SYMBOL*>( item ) );
|
2021-03-22 12:19:47 +00:00
|
|
|
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()" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "$EndSCHEMATC\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::Format( SELECTION* aSelection, OUTPUTFORMATTER* aFormatter )
|
|
|
|
{
|
|
|
|
m_out = aFormatter;
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < aSelection->GetSize(); ++i )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item = (SCH_ITEM*) aSelection->GetItem( i );
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
case SCH_SYMBOL_T:
|
|
|
|
saveSymbol( static_cast< SCH_SYMBOL* >( item ) );
|
2021-03-22 12:19:47 +00:00
|
|
|
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()" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol )
|
2021-03-22 12:19:47 +00:00
|
|
|
{
|
|
|
|
std::string name1;
|
|
|
|
std::string name2;
|
|
|
|
|
|
|
|
static wxString delimiters( wxT( " " ) );
|
|
|
|
|
|
|
|
// This is redundant with the AR entries below, but it makes the files backwards-compatible.
|
2021-06-10 14:10:55 +00:00
|
|
|
if( aSymbol->GetInstanceReferences().size() > 0 )
|
2021-03-22 12:19:47 +00:00
|
|
|
{
|
2023-01-04 20:39:50 +00:00
|
|
|
const SCH_SYMBOL_INSTANCE& instance = aSymbol->GetInstanceReferences()[0];
|
2021-03-22 12:19:47 +00:00
|
|
|
name1 = toUTFTildaText( instance.m_Reference );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
if( aSymbol->GetField( REFERENCE_FIELD )->GetText().IsEmpty() )
|
|
|
|
name1 = toUTFTildaText( aSymbol->GetPrefix() );
|
2021-03-22 12:19:47 +00:00
|
|
|
else
|
2021-06-10 14:10:55 +00:00
|
|
|
name1 = toUTFTildaText( aSymbol->GetField( REFERENCE_FIELD )->GetText() );
|
2021-03-22 12:19:47 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
wxString symbol_name = aSymbol->GetLibId().Format();
|
2021-03-22 12:19:47 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( symbol_name.size() )
|
2021-03-22 12:19:47 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
name2 = toUTFTildaText( symbol_name );
|
2021-03-22 12:19:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name2 = "_NONAME_";
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "$Comp\n" );
|
|
|
|
m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() );
|
|
|
|
|
|
|
|
// Generate unit number, conversion and timestamp
|
|
|
|
m_out->Print( 0, "U %d %d %8.8X\n",
|
2021-06-10 14:10:55 +00:00
|
|
|
aSymbol->GetUnit(),
|
|
|
|
aSymbol->GetConvert(),
|
|
|
|
aSymbol->m_Uuid.AsLegacyTimestamp() );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
// Save the position
|
|
|
|
m_out->Print( 0, "P %d %d\n",
|
2022-09-16 23:53:06 +00:00
|
|
|
schIUScale.IUToMils( aSymbol->GetPosition().x ),
|
|
|
|
schIUScale.IUToMils( aSymbol->GetPosition().y ) );
|
2021-03-22 12:19:47 +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
|
|
|
|
*/
|
2021-06-10 14:10:55 +00:00
|
|
|
if( aSymbol->GetInstanceReferences().size() > 1 )
|
2021-03-22 12:19:47 +00:00
|
|
|
{
|
2023-01-04 20:39:50 +00:00
|
|
|
for( const SCH_SYMBOL_INSTANCE& instance : aSymbol->GetInstanceReferences() )
|
2021-03-22 12:19:47 +00:00
|
|
|
{
|
|
|
|
/*format:
|
|
|
|
* AR Path="/140/2" Ref="C99" Part="1"
|
2021-05-05 21:41:51 +00:00
|
|
|
* where 140 is the uid of the containing sheet and 2 is the timestamp of this symbol.
|
2021-03-22 12:19:47 +00:00
|
|
|
* (timestamps are actually 8 hex chars)
|
2021-05-05 21:41:51 +00:00
|
|
|
* Ref is the conventional symbol reference designator for this 'path'
|
|
|
|
* Part is the conventional symbol unit selection for this 'path'
|
2021-03-22 12:19:47 +00:00
|
|
|
*/
|
|
|
|
wxString path = "/";
|
|
|
|
|
|
|
|
// Skip root sheet
|
|
|
|
for( int i = 1; i < (int) instance.m_Path.size(); ++i )
|
|
|
|
path += instance.m_Path[i].AsLegacyTimestampString() + "/";
|
|
|
|
|
|
|
|
m_out->Print( 0, "AR Path=\"%s\" Ref=\"%s\" Part=\"%d\" \n",
|
2021-06-10 14:10:55 +00:00
|
|
|
TO_UTF8( path + aSymbol->m_Uuid.AsLegacyTimestampString() ),
|
2021-03-22 12:19:47 +00:00
|
|
|
TO_UTF8( instance.m_Reference ),
|
|
|
|
instance.m_Unit );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the ugly field id, which I would like to see go away someday soon.
|
2021-06-10 14:10:55 +00:00
|
|
|
for( int i = 0; i < aSymbol->GetFieldCount(); ++i )
|
|
|
|
aSymbol->GetFields()[i].SetId( i );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
// Fixed fields:
|
|
|
|
// Save mandatory fields even if they are blank,
|
|
|
|
// because the visibility, size and orientation are set from library editor.
|
|
|
|
for( unsigned i = 0; i < MANDATORY_FIELDS; ++i )
|
2021-06-10 14:10:55 +00:00
|
|
|
saveField( &aSymbol->GetFields()[i] );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
// User defined fields:
|
2021-06-10 18:51:46 +00:00
|
|
|
// The *policy* about which user defined fields are symbol of a symbol is now
|
2021-03-22 12:19:47 +00:00
|
|
|
// 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.
|
2021-06-10 14:10:55 +00:00
|
|
|
for( int i = MANDATORY_FIELDS; i < aSymbol->GetFieldCount(); ++i )
|
|
|
|
saveField( &aSymbol->GetFields()[i] );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
// Unit number, position, box ( old standard )
|
2021-06-10 14:10:55 +00:00
|
|
|
m_out->Print( 0, "\t%-4d %-4d %-4d\n", aSymbol->GetUnit(),
|
2022-09-16 23:53:06 +00:00
|
|
|
schIUScale.IUToMils( aSymbol->GetPosition().x ),
|
|
|
|
schIUScale.IUToMils( aSymbol->GetPosition().y ) );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
TRANSFORM transform = aSymbol->GetTransform();
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
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';
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
if( aField->GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT )
|
2021-03-22 12:19:47 +00:00
|
|
|
hjustify = 'L';
|
2021-12-28 22:13:54 +00:00
|
|
|
else if( aField->GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
|
2021-03-22 12:19:47 +00:00
|
|
|
hjustify = 'R';
|
|
|
|
|
|
|
|
char vjustify = 'C';
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
if( aField->GetVertJustify() == GR_TEXT_V_ALIGN_BOTTOM )
|
2021-03-22 12:19:47 +00:00
|
|
|
vjustify = 'B';
|
2021-12-28 22:13:54 +00:00
|
|
|
else if( aField->GetVertJustify() == GR_TEXT_V_ALIGN_TOP )
|
2021-03-22 12:19:47 +00:00
|
|
|
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
|
2021-12-28 22:13:54 +00:00
|
|
|
aField->GetTextAngle().IsHorizontal() ? 'H' : 'V',
|
2022-09-16 23:53:06 +00:00
|
|
|
schIUScale.IUToMils( aField->GetLibPosition().x ),
|
|
|
|
schIUScale.IUToMils( aField->GetLibPosition().y ),
|
|
|
|
schIUScale.IUToMils( aField->GetTextWidth() ),
|
2021-03-22 12:19:47 +00:00
|
|
|
!aField->IsVisible(),
|
|
|
|
hjustify, vjustify,
|
|
|
|
aField->IsItalic() ? 'I' : 'N',
|
|
|
|
aField->IsBold() ? 'B' : 'N' );
|
|
|
|
|
|
|
|
// Save field name, if the name is user definable
|
|
|
|
if( aField->GetId() >= MANDATORY_FIELDS )
|
|
|
|
m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
|
|
|
|
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::saveBitmap( SCH_BITMAP* aBitmap )
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_RET( aBitmap != nullptr, "SCH_BITMAP* is NULL" );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
const wxImage* image = aBitmap->GetImage()->GetImageData();
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_RET( image != nullptr, "wxImage* is NULL" );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, "$Bitmap\n" );
|
|
|
|
m_out->Print( 0, "Pos %-4d %-4d\n",
|
2022-09-16 23:53:06 +00:00
|
|
|
schIUScale.IUToMils( aBitmap->GetPosition().x ),
|
|
|
|
schIUScale.IUToMils( aBitmap->GetPosition().y ) );
|
2021-03-22 12:19:47 +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();
|
|
|
|
|
|
|
|
for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_RET( aSheet != nullptr, "SCH_SHEET* is NULL" );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, "$Sheet\n" );
|
|
|
|
m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n",
|
2022-09-16 23:53:06 +00:00
|
|
|
schIUScale.IUToMils( aSheet->GetPosition().x ),
|
|
|
|
schIUScale.IUToMils( aSheet->GetPosition().y ),
|
|
|
|
schIUScale.IUToMils( aSheet->GetSize().x ),
|
|
|
|
schIUScale.IUToMils( aSheet->GetSize().y ) );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, "U %8.8X\n", aSheet->m_Uuid.AsLegacyTimestamp() );
|
|
|
|
|
|
|
|
SCH_FIELD& sheetName = aSheet->GetFields()[SHEETNAME];
|
|
|
|
SCH_FIELD& fileName = aSheet->GetFields()[SHEETFILENAME];
|
|
|
|
|
|
|
|
if( !sheetName.GetText().IsEmpty() )
|
2022-09-26 18:37:45 +00:00
|
|
|
{
|
2021-03-22 12:19:47 +00:00
|
|
|
m_out->Print( 0, "F0 %s %d\n",
|
|
|
|
EscapedUTF8( sheetName.GetText() ).c_str(),
|
2022-09-16 23:53:06 +00:00
|
|
|
schIUScale.IUToMils( sheetName.GetTextSize().x ) );
|
2022-09-26 18:37:45 +00:00
|
|
|
}
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
if( !fileName.GetText().IsEmpty() )
|
2022-09-26 18:37:45 +00:00
|
|
|
{
|
2021-03-22 12:19:47 +00:00
|
|
|
m_out->Print( 0, "F1 %s %d\n",
|
|
|
|
EscapedUTF8( fileName.GetText() ).c_str(),
|
2022-09-16 23:53:06 +00:00
|
|
|
schIUScale.IUToMils( fileName.GetTextSize().x ) );
|
2022-09-26 18:37:45 +00:00
|
|
|
}
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
|
|
|
|
{
|
|
|
|
int type, side;
|
|
|
|
|
|
|
|
if( pin->GetText().IsEmpty() )
|
|
|
|
break;
|
|
|
|
|
2021-11-28 19:06:08 +00:00
|
|
|
switch( pin->GetSide() )
|
2021-03-22 12:19:47 +00:00
|
|
|
{
|
|
|
|
default:
|
2021-05-31 01:20:43 +00:00
|
|
|
case SHEET_SIDE::LEFT: side = 'L'; break;
|
|
|
|
case SHEET_SIDE::RIGHT: side = 'R'; break;
|
|
|
|
case SHEET_SIDE::TOP: side = 'T'; break;
|
|
|
|
case SHEET_SIDE::BOTTOM: side = 'B'; break;
|
2021-03-22 12:19:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( pin->GetShape() )
|
|
|
|
{
|
|
|
|
default:
|
2021-10-12 20:05:37 +00:00
|
|
|
case LABEL_FLAG_SHAPE::L_UNSPECIFIED: type = 'U'; break;
|
|
|
|
case LABEL_FLAG_SHAPE::L_INPUT: type = 'I'; break;
|
|
|
|
case LABEL_FLAG_SHAPE::L_OUTPUT: type = 'O'; break;
|
|
|
|
case LABEL_FLAG_SHAPE::L_BIDI: type = 'B'; break;
|
|
|
|
case LABEL_FLAG_SHAPE::L_TRISTATE: type = 'T'; break;
|
2021-03-22 12:19:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n",
|
|
|
|
pin->GetNumber(),
|
|
|
|
EscapedUTF8( pin->GetText() ).c_str(), // supplies wrapping quotes
|
2022-09-16 23:53:06 +00:00
|
|
|
type, side, schIUScale.IUToMils( pin->GetPosition().x ),
|
|
|
|
schIUScale.IUToMils( pin->GetPosition().y ),
|
|
|
|
schIUScale.IUToMils( pin->GetTextWidth() ) );
|
2021-03-22 12:19:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "$EndSheet\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::saveJunction( SCH_JUNCTION* aJunction )
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_RET( aJunction != nullptr, "SCH_JUNCTION* is NULL" );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, "Connection ~ %-4d %-4d\n",
|
2022-09-16 23:53:06 +00:00
|
|
|
schIUScale.IUToMils( aJunction->GetPosition().x ),
|
|
|
|
schIUScale.IUToMils( aJunction->GetPosition().y ) );
|
2021-03-22 12:19:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::saveNoConnect( SCH_NO_CONNECT* aNoConnect )
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_RET( aNoConnect != nullptr, "SCH_NOCONNECT* is NULL" );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, "NoConn ~ %-4d %-4d\n",
|
2022-09-16 23:53:06 +00:00
|
|
|
schIUScale.IUToMils( aNoConnect->GetPosition().x ),
|
|
|
|
schIUScale.IUToMils( aNoConnect->GetPosition().y ) );
|
2021-03-22 12:19:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry )
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_RET( aBusEntry != nullptr, "SCH_BUS_ENTRY_BASE* is NULL" );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
if( aBusEntry->GetLayer() == LAYER_WIRE )
|
2022-09-26 18:37:45 +00:00
|
|
|
{
|
2021-03-22 12:19:47 +00:00
|
|
|
m_out->Print( 0, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
|
2022-09-16 23:53:06 +00:00
|
|
|
schIUScale.IUToMils( aBusEntry->GetPosition().x ),
|
|
|
|
schIUScale.IUToMils( aBusEntry->GetPosition().y ),
|
2022-10-17 13:19:39 +00:00
|
|
|
schIUScale.IUToMils( aBusEntry->GetEnd().x ),
|
|
|
|
schIUScale.IUToMils( aBusEntry->GetEnd().y ) );
|
2022-09-26 18:37:45 +00:00
|
|
|
}
|
2021-03-22 12:19:47 +00:00
|
|
|
else
|
2022-09-26 18:37:45 +00:00
|
|
|
{
|
2021-03-22 12:19:47 +00:00
|
|
|
m_out->Print( 0, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
|
2022-09-16 23:53:06 +00:00
|
|
|
schIUScale.IUToMils( aBusEntry->GetPosition().x ),
|
|
|
|
schIUScale.IUToMils( aBusEntry->GetPosition().y ),
|
2022-10-17 13:19:39 +00:00
|
|
|
schIUScale.IUToMils( aBusEntry->GetEnd().x ),
|
|
|
|
schIUScale.IUToMils( aBusEntry->GetEnd().y ) );
|
2022-09-26 18:37:45 +00:00
|
|
|
}
|
2021-03-22 12:19:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::saveLine( SCH_LINE* aLine )
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_RET( aLine != nullptr, "SCH_LINE* is NULL" );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
const char* layer = "Notes";
|
|
|
|
const char* width = "Line";
|
|
|
|
|
|
|
|
if( aLine->GetLayer() == LAYER_WIRE )
|
|
|
|
layer = "Wire";
|
|
|
|
else if( aLine->GetLayer() == LAYER_BUS )
|
|
|
|
layer = "Bus";
|
|
|
|
|
|
|
|
m_out->Print( 0, "Wire %s %s", layer, width );
|
|
|
|
|
|
|
|
// Write line style (width, type, color) only for non default values
|
|
|
|
if( aLine->IsGraphicLine() )
|
|
|
|
{
|
|
|
|
if( aLine->GetLineSize() != 0 )
|
2022-09-16 23:53:06 +00:00
|
|
|
m_out->Print( 0, " %s %d", T_WIDTH, schIUScale.IUToMils( aLine->GetLineSize() ) );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
2022-06-28 01:12:13 +00:00
|
|
|
m_out->Print( 0, " %s %s", T_STYLE,
|
|
|
|
TO_UTF8( STROKE_PARAMS::GetLineStyleToken( aLine->GetLineStyle() ) ) );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
if( aLine->GetLineColor() != COLOR4D::UNSPECIFIED )
|
2022-06-28 01:12:13 +00:00
|
|
|
{
|
2021-03-22 12:19:47 +00:00
|
|
|
m_out->Print( 0, " %s",
|
2022-09-30 19:18:37 +00:00
|
|
|
TO_UTF8( aLine->GetLineColor().ToCSSString() ) );
|
2022-06-28 01:12:13 +00:00
|
|
|
}
|
2021-03-22 12:19:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
|
|
|
|
m_out->Print( 0, "\t%-4d %-4d %-4d %-4d",
|
2022-10-17 13:19:39 +00:00
|
|
|
schIUScale.IUToMils( aLine->GetStartPoint().x ),
|
|
|
|
schIUScale.IUToMils( aLine->GetStartPoint().y ),
|
|
|
|
schIUScale.IUToMils( aLine->GetEndPoint().x ),
|
|
|
|
schIUScale.IUToMils( aLine->GetEndPoint().y ) );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::saveText( SCH_TEXT* aText )
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_RET( aText != nullptr, "SCH_TEXT* is NULL" );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
const char* italics = "~";
|
|
|
|
const char* textType = "Notes";
|
|
|
|
|
|
|
|
if( aText->IsItalic() )
|
|
|
|
italics = "Italic";
|
|
|
|
|
|
|
|
wxString text = aText->GetText();
|
|
|
|
|
|
|
|
SCH_LAYER_ID layer = aText->GetLayer();
|
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Local labels must have their spin style inverted for left and right
|
2022-01-24 13:40:39 +00:00
|
|
|
int spinStyle = static_cast<int>( aText->GetTextSpinStyle() );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
if( spinStyle == 0 )
|
|
|
|
spinStyle = 2;
|
|
|
|
else if( spinStyle == 2 )
|
|
|
|
spinStyle = 0;
|
|
|
|
|
|
|
|
m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
|
2022-10-17 13:19:39 +00:00
|
|
|
schIUScale.IUToMils( aText->GetPosition().x ),
|
|
|
|
schIUScale.IUToMils( aText->GetPosition().y ),
|
2021-03-22 12:19:47 +00:00
|
|
|
spinStyle,
|
2022-09-16 23:53:06 +00:00
|
|
|
schIUScale.IUToMils( aText->GetTextWidth() ),
|
|
|
|
italics, schIUScale.IUToMils( aText->GetTextThickness() ), TO_UTF8( text ) );
|
2021-03-22 12:19:47 +00:00
|
|
|
}
|
|
|
|
else if( layer == LAYER_GLOBLABEL || layer == LAYER_HIERLABEL )
|
|
|
|
{
|
|
|
|
textType = ( layer == LAYER_GLOBLABEL ) ? "GLabel" : "HLabel";
|
|
|
|
|
|
|
|
auto shapeLabelIt = sheetLabelNames.find( aText->GetShape() );
|
|
|
|
wxCHECK_RET( shapeLabelIt != sheetLabelNames.end(), "Shape not found in names list" );
|
|
|
|
|
|
|
|
m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
|
2022-10-17 13:19:39 +00:00
|
|
|
schIUScale.IUToMils( aText->GetPosition().x ),
|
|
|
|
schIUScale.IUToMils( aText->GetPosition().y ),
|
2022-01-24 13:40:39 +00:00
|
|
|
static_cast<int>( aText->GetTextSpinStyle() ),
|
2022-09-16 23:53:06 +00:00
|
|
|
schIUScale.IUToMils( aText->GetTextWidth() ),
|
2021-03-22 12:19:47 +00:00
|
|
|
shapeLabelIt->second,
|
|
|
|
italics,
|
2022-09-16 23:53:06 +00:00
|
|
|
schIUScale.IUToMils( aText->GetTextThickness() ), TO_UTF8( text ) );
|
2021-03-22 12:19:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias )
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_RET( aAlias != nullptr, "BUS_ALIAS* is NULL" );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
wxString members = boost::algorithm::join( aAlias->Members(), " " );
|
|
|
|
|
|
|
|
m_out->Print( 0, "BusAlias %s %s\n",
|
|
|
|
TO_UTF8( aAlias->GetName() ), TO_UTF8( members ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-06 16:51:52 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::cacheLib( const wxString& aLibraryFileName, const STRING_UTF8_MAP* aProperties )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2021-03-26 17:30:47 +00:00
|
|
|
if( !isBuffering( aProperties ) )
|
2017-01-27 15:56:36 +00:00
|
|
|
m_cache->Load();
|
2016-08-18 23:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-06 16:51:52 +00:00
|
|
|
bool SCH_LEGACY_PLUGIN::writeDocFile( const STRING_UTF8_MAP* aProperties )
|
2021-03-22 12:19:47 +00:00
|
|
|
{
|
|
|
|
std::string propName( SCH_LEGACY_PLUGIN::PropNoDocFile );
|
|
|
|
|
|
|
|
if( aProperties && aProperties->find( propName ) != aProperties->end() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-06 16:51:52 +00:00
|
|
|
bool SCH_LEGACY_PLUGIN::isBuffering( const STRING_UTF8_MAP* aProperties )
|
2017-01-27 15:56:36 +00:00
|
|
|
{
|
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 )
|
2022-02-07 20:40:21 +00:00
|
|
|
return m_cache->GetModifyHash();
|
2016-10-24 23:18:50 +00:00
|
|
|
|
|
|
|
// 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,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2016-08-18 23:23:10 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
2017-09-02 18:12:50 +00:00
|
|
|
bool powerSymbolsOnly = ( aProperties &&
|
|
|
|
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
|
2021-03-26 17:30:47 +00:00
|
|
|
|
|
|
|
cacheLib( aLibraryPath, aProperties );
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
|
2016-08-18 23:23:10 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
for( LIB_SYMBOL_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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
|
2017-02-24 16:09:27 +00:00
|
|
|
const wxString& aLibraryPath,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2017-02-24 16:09:27 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
2017-09-02 18:12:50 +00:00
|
|
|
bool powerSymbolsOnly = ( aProperties &&
|
|
|
|
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
|
2021-03-26 17:30:47 +00:00
|
|
|
|
|
|
|
cacheLib( aLibraryPath, aProperties );
|
2017-02-24 16:09:27 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
|
2017-02-24 16:09:27 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
for( LIB_SYMBOL_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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* SCH_LEGACY_PLUGIN::LoadSymbol( const wxString& aLibraryPath,
|
|
|
|
const wxString& aSymbolName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2016-09-03 18:28:17 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
2021-03-26 17:30:47 +00:00
|
|
|
cacheLib( aLibraryPath, aProperties );
|
2016-09-03 18:28:17 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL_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
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2021-03-22 12:19:47 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
2021-03-26 17:30:47 +00:00
|
|
|
cacheLib( aLibraryPath, aProperties );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
m_cache->AddSymbol( aSymbol );
|
|
|
|
|
|
|
|
if( !isBuffering( aProperties ) )
|
|
|
|
m_cache->Save( writeDocFile( aProperties ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2021-03-22 12:19:47 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
2021-03-26 17:30:47 +00:00
|
|
|
cacheLib( aLibraryPath, aProperties );
|
2021-03-22 12:19:47 +00:00
|
|
|
|
|
|
|
m_cache->DeleteSymbol( aSymbolName );
|
|
|
|
|
|
|
|
if( !isBuffering( aProperties ) )
|
|
|
|
m_cache->Save( writeDocFile( aProperties ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LEGACY_PLUGIN::CreateSymbolLib( const wxString& aLibraryPath,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2021-03-22 12:19:47 +00:00
|
|
|
{
|
|
|
|
if( wxFileExists( aLibraryPath ) )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Symbol library '%s' already exists." ),
|
|
|
|
aLibraryPath.GetData() ) );
|
2021-03-22 12:19:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LOCALE_IO toggle;
|
|
|
|
|
|
|
|
delete m_cache;
|
|
|
|
m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
|
|
|
|
m_cache->SetModified();
|
|
|
|
m_cache->Save( writeDocFile( aProperties ) );
|
|
|
|
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,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2016-10-09 12:29:44 +00:00
|
|
|
{
|
|
|
|
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 ) )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Symbol 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;
|
2021-04-22 21:20:34 +00:00
|
|
|
m_cache = nullptr;
|
2016-10-09 12:29:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-27 15:56:36 +00:00
|
|
|
|
|
|
|
|
2022-11-06 16:51:52 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::SaveLibrary( const wxString& aLibraryPath, const STRING_UTF8_MAP* aProperties )
|
2021-03-22 12:19:47 +00:00
|
|
|
{
|
|
|
|
if( !m_cache )
|
|
|
|
m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
|
|
|
|
|
|
|
|
wxString oldFileName = m_cache->GetFileName();
|
|
|
|
|
|
|
|
if( !m_cache->IsFile( aLibraryPath ) )
|
|
|
|
{
|
|
|
|
m_cache->SetFileName( aLibraryPath );
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a forced save.
|
|
|
|
m_cache->SetModified();
|
|
|
|
m_cache->Save( writeDocFile( aProperties ) );
|
|
|
|
m_cache->SetFileName( oldFileName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2020-05-22 14:12:44 +00:00
|
|
|
// Writing legacy symbol libraries is deprecated.
|
|
|
|
return false;
|
2017-10-06 18:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void SCH_LEGACY_PLUGIN::FormatPart( LIB_SYMBOL* symbol, OUTPUTFORMATTER & formatter )
|
2021-03-22 12:19:47 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( symbol, formatter );
|
2021-03-22 12:19:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
const char* SCH_LEGACY_PLUGIN::PropBuffering = "buffering";
|
|
|
|
const char* SCH_LEGACY_PLUGIN::PropNoDocFile = "no_doc_file";
|