2020-08-23 19:01:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Thomas Pointhuber <thomas.pointhuber@gmx.at>
|
2021-02-24 13:48:02 +00:00
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-08-23 19:01:08 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2020-10-23 12:29:07 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "altium_parser_sch.h"
|
|
|
|
#include <plugins/altium/altium_parser.h>
|
|
|
|
#include <plugins/altium/altium_parser_utils.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <sch_plugins/altium/sch_altium_plugin.h>
|
|
|
|
|
|
|
|
#include <schematic.h>
|
|
|
|
|
|
|
|
#include <lib_arc.h>
|
2020-10-10 14:56:19 +00:00
|
|
|
#include <lib_bezier.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <lib_circle.h>
|
|
|
|
#include <lib_id.h>
|
|
|
|
#include <lib_item.h>
|
|
|
|
#include <lib_pin.h>
|
|
|
|
#include <lib_polyline.h>
|
|
|
|
#include <lib_rectangle.h>
|
|
|
|
#include <lib_text.h>
|
|
|
|
|
|
|
|
#include <bus_alias.h>
|
|
|
|
#include <sch_bitmap.h>
|
|
|
|
#include <sch_bus_entry.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_line.h>
|
|
|
|
#include <sch_no_connect.h>
|
|
|
|
#include <sch_screen.h>
|
|
|
|
#include <sch_sheet.h>
|
2021-04-06 21:15:49 +00:00
|
|
|
#include <sch_sheet_pin.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <sch_text.h>
|
|
|
|
|
2020-10-10 16:41:19 +00:00
|
|
|
#include <bezier_curves.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <compoundfilereader.h>
|
2020-10-23 12:29:07 +00:00
|
|
|
#include <kicad_string.h>
|
2020-10-24 16:40:16 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2021-04-10 19:45:36 +00:00
|
|
|
#include <wx/mstream.h>
|
|
|
|
#include <wx/zstream.h>
|
|
|
|
#include <wx/wfstream.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
|
2020-10-09 14:23:07 +00:00
|
|
|
const wxPoint GetRelativePosition( const wxPoint& aPosition, const SCH_COMPONENT* aComponent )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2020-10-09 14:23:07 +00:00
|
|
|
TRANSFORM t = aComponent->GetTransform().InverseTransform();
|
|
|
|
return t.TransformCoordinate( aPosition - aComponent->GetPosition() );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 14:51:19 +00:00
|
|
|
|
|
|
|
COLOR4D GetColorFromInt( int color )
|
|
|
|
{
|
|
|
|
int red = color & 0x0000FF;
|
|
|
|
int green = ( color & 0x00FF00 ) >> 8;
|
|
|
|
int blue = ( color & 0xFF0000 ) >> 16;
|
|
|
|
|
|
|
|
return COLOR4D().FromCSSRGBA( red, green, blue, 1.0 );
|
|
|
|
}
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
SCH_ALTIUM_PLUGIN::SCH_ALTIUM_PLUGIN()
|
|
|
|
{
|
|
|
|
m_rootSheet = nullptr;
|
|
|
|
m_currentSheet = nullptr;
|
|
|
|
m_schematic = nullptr;
|
2021-03-31 21:33:30 +00:00
|
|
|
|
|
|
|
m_reporter = &WXLOG_REPORTER::GetInstance();
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_ALTIUM_PLUGIN::~SCH_ALTIUM_PLUGIN()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxString SCH_ALTIUM_PLUGIN::GetName() const
|
|
|
|
{
|
|
|
|
return "Altium";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxString SCH_ALTIUM_PLUGIN::GetFileExtension() const
|
|
|
|
{
|
|
|
|
return "SchDoc";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxString SCH_ALTIUM_PLUGIN::GetLibraryFileExtension() const
|
|
|
|
{
|
|
|
|
return "SchLib";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_ALTIUM_PLUGIN::GetModifyHash() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_ALTIUM_PLUGIN::CheckHeader( const wxString& aFileName )
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString SCH_ALTIUM_PLUGIN::getLibName()
|
|
|
|
{
|
|
|
|
if( m_libName.IsEmpty() )
|
|
|
|
{
|
|
|
|
// Try to come up with a meaningful name
|
|
|
|
m_libName = m_schematic->Prj().GetProjectName();
|
|
|
|
|
|
|
|
if( m_libName.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxFileName fn( m_rootSheet->GetFileName() );
|
|
|
|
m_libName = fn.GetName();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_libName.IsEmpty() )
|
|
|
|
m_libName = "noname";
|
|
|
|
|
|
|
|
m_libName += "-altium-import";
|
2020-12-17 23:32:23 +00:00
|
|
|
m_libName = LIB_ID::FixIllegalChars( m_libName, true );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_libName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxFileName SCH_ALTIUM_PLUGIN::getLibFileName()
|
|
|
|
{
|
|
|
|
wxFileName fn( m_schematic->Prj().GetProjectPath(), getLibName(), KiCadSymbolLibFileExtension );
|
|
|
|
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
SCH_SHEET* SCH_ALTIUM_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic,
|
2020-11-05 23:19:47 +00:00
|
|
|
SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
|
|
|
wxASSERT( !aFileName || aSchematic != NULL );
|
|
|
|
|
2020-11-05 23:24:29 +00:00
|
|
|
wxFileName fileName( aFileName );
|
2021-03-03 01:06:25 +00:00
|
|
|
fileName.SetExt( KiCadSchematicFileExtension );
|
2020-08-23 19:01:08 +00:00
|
|
|
m_schematic = aSchematic;
|
|
|
|
|
|
|
|
// Delete on exception, if I own m_rootSheet, according to aAppendToMe
|
|
|
|
std::unique_ptr<SCH_SHEET> deleter( aAppendToMe ? nullptr : m_rootSheet );
|
|
|
|
|
|
|
|
if( aAppendToMe )
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
|
|
|
|
m_rootSheet = &aSchematic->Root();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_rootSheet = new SCH_SHEET( aSchematic );
|
2020-11-06 01:32:40 +00:00
|
|
|
m_rootSheet->SetFileName( fileName.GetFullPath() );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_rootSheet->GetScreen() )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
|
|
|
|
screen->SetFileName( aFileName );
|
|
|
|
m_rootSheet->SetScreen( screen );
|
|
|
|
}
|
|
|
|
|
|
|
|
SYMBOL_LIB_TABLE* libTable = m_schematic->Prj().SchSymbolLibTable();
|
|
|
|
|
|
|
|
wxCHECK_MSG( libTable, NULL, "Could not load symbol lib table." );
|
|
|
|
|
|
|
|
m_pi.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
|
|
|
|
|
|
|
|
/// @note No check is being done here to see if the existing symbol library exists so this
|
|
|
|
/// will overwrite the existing one.
|
|
|
|
if( !libTable->HasLibrary( getLibName() ) )
|
|
|
|
{
|
|
|
|
// Create a new empty symbol library.
|
|
|
|
m_pi->CreateSymbolLib( getLibFileName().GetFullPath() );
|
|
|
|
wxString libTableUri = "${KIPRJMOD}/" + getLibFileName().GetFullName();
|
|
|
|
|
|
|
|
// Add the new library to the project symbol library table.
|
2020-11-05 23:19:47 +00:00
|
|
|
libTable->InsertRow( new SYMBOL_LIB_TABLE_ROW( getLibName(), libTableUri,
|
|
|
|
wxString( "KiCad" ) ) );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
// Save project symbol library table.
|
|
|
|
wxFileName fn( m_schematic->Prj().GetProjectPath(),
|
2020-11-05 23:19:47 +00:00
|
|
|
SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
// So output formatter goes out of scope and closes the file before reloading.
|
|
|
|
{
|
|
|
|
FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
|
|
|
|
libTable->Format( &formatter, 0 );
|
|
|
|
}
|
|
|
|
|
2020-10-23 14:22:56 +00:00
|
|
|
// Reload the symbol library table.
|
2020-08-23 19:01:08 +00:00
|
|
|
m_schematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL );
|
|
|
|
m_schematic->Prj().SchSymbolLibTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_currentSheet = m_rootSheet;
|
|
|
|
ParseAltiumSch( aFileName );
|
|
|
|
|
|
|
|
m_pi->SaveLibrary( getLibFileName().GetFullPath() );
|
|
|
|
|
2021-03-16 19:51:31 +00:00
|
|
|
SCH_SCREENS allSheets( m_rootSheet );
|
|
|
|
allSheets.UpdateSymbolLinks(); // Update all symbol library links for all sheets.
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
return m_rootSheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*wxString SCH_EAGLE_PLUGIN::fixSymbolName( const wxString& aName )
|
|
|
|
{
|
|
|
|
wxString ret = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_SCH );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
void SCH_ALTIUM_PLUGIN::ParseAltiumSch( const wxString& aFileName )
|
|
|
|
{
|
|
|
|
// Open file
|
|
|
|
FILE* fp = wxFopen( aFileName, "rb" );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
if( fp == nullptr )
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Cannot open file '%s'." ), aFileName ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2020-08-23 19:01:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fseek( fp, 0, SEEK_END );
|
|
|
|
long len = ftell( fp );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
if( len < 0 )
|
|
|
|
{
|
|
|
|
fclose( fp );
|
|
|
|
THROW_IO_ERROR( "Reading error, cannot determine length of file" );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<unsigned char[]> buffer( new unsigned char[len] );
|
|
|
|
fseek( fp, 0, SEEK_SET );
|
|
|
|
|
|
|
|
size_t bytesRead = fread( buffer.get(), sizeof( unsigned char ), len, fp );
|
|
|
|
fclose( fp );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
if( static_cast<size_t>( len ) != bytesRead )
|
|
|
|
THROW_IO_ERROR( "Reading error" );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
CFB::CompoundFileReader reader( buffer.get(), bytesRead );
|
2021-04-10 19:45:36 +00:00
|
|
|
ParseStorage( reader ); // we need this before parsing the FileHeader
|
|
|
|
ParseFileHeader( reader );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
catch( CFB::CFBException& exception )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( exception.what() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-10 19:45:36 +00:00
|
|
|
void SCH_ALTIUM_PLUGIN::ParseStorage( const CFB::CompoundFileReader& aReader )
|
|
|
|
{
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* file = FindStream( aReader, "Storage" );
|
|
|
|
|
|
|
|
if( file == nullptr )
|
|
|
|
return;
|
|
|
|
|
|
|
|
ALTIUM_PARSER reader( aReader, file );
|
|
|
|
|
|
|
|
std::map<wxString, wxString> properties = reader.ReadProperties();
|
|
|
|
wxString header = ALTIUM_PARSER::PropertiesReadString( properties, "HEADER", "" );
|
|
|
|
int weight = ALTIUM_PARSER::PropertiesReadInt( properties, "WEIGHT", 0 );
|
|
|
|
|
|
|
|
if( weight < 0 )
|
|
|
|
THROW_IO_ERROR( "Storage weight is negative!" );
|
|
|
|
|
|
|
|
for( int i = 0; i < weight; i++ )
|
|
|
|
{
|
|
|
|
m_altiumStorage.emplace_back( reader );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.HasParsingError() )
|
|
|
|
THROW_IO_ERROR( "stream was not parsed correctly!" );
|
|
|
|
|
|
|
|
// TODO pointhi: is it possible to have multiple headers in one Storage file? Otherwise throw IO Error.
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
wxLogError(
|
|
|
|
wxString::Format( "Storage file was not fully parsed as %d bytes are remaining.",
|
|
|
|
reader.GetRemainingBytes() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_ALTIUM_PLUGIN::ParseFileHeader( const CFB::CompoundFileReader& aReader )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* file = FindStream( aReader, "FileHeader" );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
if( file == nullptr )
|
|
|
|
THROW_IO_ERROR( "FileHeader not found" );
|
|
|
|
|
|
|
|
ALTIUM_PARSER reader( aReader, file );
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() <= 0 )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "FileHeader does not contain any data" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::map<wxString, wxString> properties = reader.ReadProperties();
|
|
|
|
|
|
|
|
int recordId = ALTIUM_PARSER::PropertiesReadInt( properties, "RECORD", 0 );
|
|
|
|
ALTIUM_SCH_RECORD record = static_cast<ALTIUM_SCH_RECORD>( recordId );
|
|
|
|
|
|
|
|
if( record != ALTIUM_SCH_RECORD::HEADER )
|
|
|
|
THROW_IO_ERROR( "Header expected" );
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:07:42 +00:00
|
|
|
// Prepare some local variables
|
|
|
|
wxASSERT( m_altiumPortsCurrentSheet.empty() );
|
|
|
|
wxASSERT( !m_currentTitleBlock );
|
|
|
|
|
|
|
|
m_currentTitleBlock = std::make_unique<TITLE_BLOCK>();
|
|
|
|
|
2021-03-02 12:18:05 +00:00
|
|
|
// index is required required to resolve OWNERINDEX
|
2020-08-23 19:01:08 +00:00
|
|
|
for( int index = 0; reader.GetRemainingBytes() > 0; index++ )
|
|
|
|
{
|
|
|
|
std::map<wxString, wxString> properties = reader.ReadProperties();
|
|
|
|
|
|
|
|
int recordId = ALTIUM_PARSER::PropertiesReadInt( properties, "RECORD", 0 );
|
|
|
|
ALTIUM_SCH_RECORD record = static_cast<ALTIUM_SCH_RECORD>( recordId );
|
|
|
|
|
|
|
|
// see: https://github.com/vadmium/python-altium/blob/master/format.md
|
|
|
|
switch( record )
|
|
|
|
{
|
|
|
|
case ALTIUM_SCH_RECORD::HEADER:
|
|
|
|
THROW_IO_ERROR( "Header already parsed" );
|
|
|
|
case ALTIUM_SCH_RECORD::COMPONENT:
|
|
|
|
ParseComponent( index, properties );
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::PIN:
|
|
|
|
ParsePin( properties );
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::IEEE_SYMBOL:
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::LABEL:
|
2020-10-17 11:52:47 +00:00
|
|
|
ParseLabel( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::BEZIER:
|
2020-10-10 14:56:19 +00:00
|
|
|
ParseBezier( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::POLYLINE:
|
2020-10-10 14:56:19 +00:00
|
|
|
ParsePolyline( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::POLYGON:
|
2020-10-10 14:22:53 +00:00
|
|
|
ParsePolygon( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::ELLIPSE:
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::PIECHART:
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::ROUND_RECTANGLE:
|
2020-10-14 19:15:09 +00:00
|
|
|
ParseRoundRectangle( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::ELLIPTICAL_ARC:
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::ARC:
|
2020-10-10 16:41:19 +00:00
|
|
|
ParseArc( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::LINE:
|
2020-10-10 16:41:19 +00:00
|
|
|
ParseLine( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::RECTANGLE:
|
|
|
|
ParseRectangle( properties );
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::SHEET_SYMBOL:
|
2020-10-27 14:51:19 +00:00
|
|
|
ParseSheetSymbol( index, properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::SHEET_ENTRY:
|
2020-10-27 14:51:19 +00:00
|
|
|
ParseSheetEntry( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::POWER_PORT:
|
2020-10-24 16:40:16 +00:00
|
|
|
ParsePowerPort( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::PORT:
|
2020-10-27 13:07:42 +00:00
|
|
|
// Ports are parsed after the sheet was parsed
|
|
|
|
// This is required because we need all electrical connection points before placing.
|
|
|
|
m_altiumPortsCurrentSheet.emplace_back( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::NO_ERC:
|
2020-10-14 19:23:36 +00:00
|
|
|
ParseNoERC( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::NET_LABEL:
|
|
|
|
ParseNetLabel( properties );
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::BUS:
|
|
|
|
ParseBus( properties );
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::WIRE:
|
|
|
|
ParseWire( properties );
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::TEXT_FRAME:
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::JUNCTION:
|
2020-10-09 15:21:27 +00:00
|
|
|
ParseJunction( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
2021-04-10 19:45:36 +00:00
|
|
|
case ALTIUM_SCH_RECORD::IMAGE: ParseImage( properties ); break;
|
2020-08-23 19:01:08 +00:00
|
|
|
case ALTIUM_SCH_RECORD::SHEET:
|
2020-10-17 12:33:30 +00:00
|
|
|
ParseSheet( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::SHEET_NAME:
|
2020-10-27 14:51:19 +00:00
|
|
|
ParseSheetName( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::FILE_NAME:
|
2020-10-27 14:51:19 +00:00
|
|
|
ParseFileName( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::DESIGNATOR:
|
|
|
|
ParseDesignator( properties );
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::BUS_ENTRY:
|
2020-10-17 14:03:46 +00:00
|
|
|
ParseBusEntry( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::TEMPLATE:
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::PARAMETER:
|
2020-10-26 17:26:49 +00:00
|
|
|
ParseParameter( properties );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::WARNING_SIGN:
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::IMPLEMENTATION_LIST:
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::IMPLEMENTATION:
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::RECORD_46:
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::RECORD_47:
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::RECORD_48:
|
|
|
|
break;
|
2020-10-10 16:41:19 +00:00
|
|
|
case ALTIUM_SCH_RECORD::RECORD_209:
|
|
|
|
break;
|
2020-08-23 19:01:08 +00:00
|
|
|
case ALTIUM_SCH_RECORD::RECORD_215:
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::RECORD_216:
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::RECORD_217:
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::RECORD_218:
|
|
|
|
break;
|
|
|
|
case ALTIUM_SCH_RECORD::RECORD_226:
|
|
|
|
break;
|
|
|
|
default:
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Unknown Record id: %d." ), recordId ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.HasParsingError() )
|
|
|
|
THROW_IO_ERROR( "stream was not parsed correctly!" );
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
THROW_IO_ERROR( "stream is not fully parsed" );
|
|
|
|
|
|
|
|
// assign LIB_PART -> COMPONENT
|
|
|
|
for( auto component : m_components )
|
|
|
|
{
|
|
|
|
auto kpart = m_symbols.find( component.first );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
if( kpart == m_symbols.end() )
|
|
|
|
THROW_IO_ERROR( "every component should have a symbol attached" );
|
|
|
|
|
|
|
|
m_pi->SaveSymbol( getLibFileName().GetFullPath(), new LIB_PART( *( kpart->second ) ),
|
2020-11-05 23:19:47 +00:00
|
|
|
m_properties.get() );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
component.second->SetLibSymbol( kpart->second );
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:07:42 +00:00
|
|
|
// Handle title blocks
|
|
|
|
m_currentSheet->GetScreen()->SetTitleBlock( *m_currentTitleBlock );
|
|
|
|
m_currentTitleBlock.reset();
|
|
|
|
|
|
|
|
// Handle Ports
|
|
|
|
for( const ASCH_PORT& port : m_altiumPortsCurrentSheet )
|
|
|
|
ParsePort( port );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-10-27 13:07:42 +00:00
|
|
|
m_altiumPortsCurrentSheet.clear();
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
m_components.clear();
|
|
|
|
m_symbols.clear();
|
|
|
|
|
|
|
|
// Otherwise we cannot save the imported sheet?
|
|
|
|
m_currentSheet->SetModified();
|
|
|
|
}
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
|
|
|
|
bool SCH_ALTIUM_PLUGIN::IsComponentPartVisible( int aOwnerindex, int aOwnerpartdisplaymode ) const
|
2020-10-23 15:02:56 +00:00
|
|
|
{
|
|
|
|
const auto& component = m_altiumComponents.find( aOwnerindex );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-10-23 15:02:56 +00:00
|
|
|
if( component == m_altiumComponents.end() )
|
|
|
|
return false;
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
return component->second.displaymode == aOwnerpartdisplaymode;
|
2020-10-23 15:02:56 +00:00
|
|
|
}
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2021-04-10 19:45:36 +00:00
|
|
|
const ASCH_STORAGE_FILE* SCH_ALTIUM_PLUGIN::GetFileFromStorage( const wxString& aFilename ) const
|
|
|
|
{
|
|
|
|
const ASCH_STORAGE_FILE* nonExactMatch = nullptr;
|
|
|
|
|
|
|
|
for( const ASCH_STORAGE_FILE& file : m_altiumStorage )
|
|
|
|
{
|
|
|
|
if( file.filename.IsSameAs( aFilename ) )
|
|
|
|
{
|
|
|
|
return &file;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( file.filename.EndsWith( aFilename ) )
|
|
|
|
{
|
|
|
|
nonExactMatch = &file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nonExactMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-05 23:19:47 +00:00
|
|
|
void SCH_ALTIUM_PLUGIN::ParseComponent( int aIndex,
|
|
|
|
const std::map<wxString, wxString>& aProperties )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2020-10-27 14:51:19 +00:00
|
|
|
auto pair = m_altiumComponents.insert( { aIndex, ASCH_COMPONENT( aProperties ) } );
|
2020-10-23 15:02:56 +00:00
|
|
|
const ASCH_COMPONENT& elem = pair.first->second;
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2020-10-27 13:16:17 +00:00
|
|
|
// TODO: this is a hack until we correctly apply all transformations to every element
|
2020-11-05 23:19:47 +00:00
|
|
|
wxString name = wxString::Format( "%d%s_%s",
|
|
|
|
elem.orientation,
|
|
|
|
elem.isMirrored ? "_mirrored" : "",
|
|
|
|
elem.libreference );
|
2020-12-17 23:32:23 +00:00
|
|
|
LIB_ID libId = AltiumToKiCadLibID( getLibName(), name );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
LIB_PART* kpart = new LIB_PART( wxEmptyString );
|
2020-10-27 13:16:17 +00:00
|
|
|
kpart->SetName( name );
|
2020-10-23 14:22:56 +00:00
|
|
|
kpart->SetDescription( elem.componentdescription );
|
2020-08-23 19:01:08 +00:00
|
|
|
kpart->SetLibId( libId );
|
2020-10-27 14:51:19 +00:00
|
|
|
m_symbols.insert( { aIndex, kpart } );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
// each component has its own symbol for now
|
|
|
|
SCH_COMPONENT* component = new SCH_COMPONENT();
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
component->SetPosition( elem.location + m_sheetOffset );
|
2020-10-09 14:23:07 +00:00
|
|
|
//component->SetOrientation( elem.orientation ); // TODO: keep it simple for now, and only set position
|
2020-08-23 19:01:08 +00:00
|
|
|
component->SetLibId( libId );
|
|
|
|
//component->SetLibSymbol( kpart ); // this has to be done after parsing the LIB_PART!
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
component->SetUnit( elem.currentpartid );
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
m_currentSheet->GetScreen()->Append( component );
|
|
|
|
|
2020-10-27 14:51:19 +00:00
|
|
|
m_components.insert( { aIndex, component } );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_ALTIUM_PLUGIN::ParsePin( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_PIN elem( aProperties );
|
|
|
|
|
|
|
|
const auto& symbol = m_symbols.find( elem.ownerindex );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
if( symbol == m_symbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Pin has non-existent ownerindex %d." ),
|
|
|
|
elem.ownerindex ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
2020-08-23 19:01:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
|
2020-10-23 15:02:56 +00:00
|
|
|
return;
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
const auto& component = m_components.at( symbol->first );
|
|
|
|
|
|
|
|
LIB_PIN* pin = new LIB_PIN( symbol->second );
|
|
|
|
symbol->second->AddDrawItem( pin );
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
pin->SetUnit( elem.ownerpartid );
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
pin->SetName( elem.name );
|
|
|
|
pin->SetNumber( elem.designator );
|
2020-10-09 14:23:07 +00:00
|
|
|
pin->SetLength( elem.pinlength );
|
|
|
|
|
|
|
|
wxPoint pinLocation = elem.location; // the location given is not the connection point!
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-10-09 14:23:07 +00:00
|
|
|
switch( elem.orientation )
|
|
|
|
{
|
2020-10-14 19:38:12 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::RIGHTWARDS:
|
2020-10-09 14:23:07 +00:00
|
|
|
pin->SetOrientation( DrawPinOrient::PIN_LEFT );
|
|
|
|
pinLocation.x += elem.pinlength;
|
|
|
|
break;
|
2020-10-14 19:38:12 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::UPWARDS:
|
2020-10-09 14:23:07 +00:00
|
|
|
pin->SetOrientation( DrawPinOrient::PIN_DOWN );
|
|
|
|
pinLocation.y -= elem.pinlength;
|
|
|
|
break;
|
2020-10-14 19:38:12 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::LEFTWARDS:
|
2020-10-09 14:23:07 +00:00
|
|
|
pin->SetOrientation( DrawPinOrient::PIN_RIGHT );
|
|
|
|
pinLocation.x -= elem.pinlength;
|
|
|
|
break;
|
2020-10-14 19:38:12 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::DOWNWARDS:
|
2020-10-09 14:23:07 +00:00
|
|
|
pin->SetOrientation( DrawPinOrient::PIN_UP );
|
|
|
|
pinLocation.y += elem.pinlength;
|
|
|
|
break;
|
|
|
|
default:
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( _( "Pin has unexpected orientation." ), RPT_SEVERITY_WARNING );
|
2020-10-09 14:23:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-10 14:43:33 +00:00
|
|
|
// TODO: position can be sometimes off a little bit!
|
2020-10-17 13:35:22 +00:00
|
|
|
pin->SetPosition( GetRelativePosition( pinLocation + m_sheetOffset, component ) );
|
2020-10-10 14:43:33 +00:00
|
|
|
// TODO: the following fix is even worse for now?
|
|
|
|
// pin->SetPosition( GetRelativePosition( elem.kicadLocation, component ) );
|
2020-10-09 14:23:07 +00:00
|
|
|
|
|
|
|
switch( elem.electrical )
|
|
|
|
{
|
|
|
|
case ASCH_PIN_ELECTRICAL::INPUT:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_INPUT );
|
|
|
|
break;
|
|
|
|
case ASCH_PIN_ELECTRICAL::BIDI:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_BIDI );
|
|
|
|
break;
|
|
|
|
case ASCH_PIN_ELECTRICAL::OUTPUT:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_OUTPUT );
|
|
|
|
break;
|
|
|
|
case ASCH_PIN_ELECTRICAL::OPEN_COLLECTOR:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR );
|
|
|
|
break;
|
|
|
|
case ASCH_PIN_ELECTRICAL::PASSIVE:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_PASSIVE );
|
|
|
|
break;
|
|
|
|
case ASCH_PIN_ELECTRICAL::TRISTATE:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_TRISTATE );
|
|
|
|
break;
|
|
|
|
case ASCH_PIN_ELECTRICAL::OPEN_EMITTER:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_OPENEMITTER );
|
|
|
|
break;
|
|
|
|
case ASCH_PIN_ELECTRICAL::POWER:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
|
|
|
|
break;
|
|
|
|
case ASCH_PIN_ELECTRICAL::UNKNOWN:
|
|
|
|
default:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_UNSPECIFIED );
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( _( "Pin has unexpected electrical type." ), RPT_SEVERITY_WARNING );
|
2020-10-09 14:23:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( elem.symbolOuterEdge == ASCH_PIN_SYMBOL_OUTEREDGE::UNKNOWN )
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( _( "Pin has unexpected outer edge type." ), RPT_SEVERITY_WARNING );
|
2020-10-09 14:23:07 +00:00
|
|
|
|
|
|
|
if( elem.symbolInnerEdge == ASCH_PIN_SYMBOL_INNEREDGE::UNKNOWN )
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( _( "Pin has unexpected inner edge type." ), RPT_SEVERITY_WARNING );
|
2020-10-09 14:23:07 +00:00
|
|
|
|
|
|
|
if( elem.symbolOuterEdge == ASCH_PIN_SYMBOL_OUTEREDGE::NEGATED )
|
|
|
|
{
|
|
|
|
switch( elem.symbolInnerEdge )
|
|
|
|
{
|
|
|
|
case ASCH_PIN_SYMBOL_INNEREDGE::CLOCK:
|
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::INVERTED_CLOCK );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::INVERTED );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-10-09 15:13:18 +00:00
|
|
|
else if( elem.symbolOuterEdge == ASCH_PIN_SYMBOL_OUTEREDGE::LOW_INPUT )
|
|
|
|
{
|
|
|
|
switch( elem.symbolInnerEdge )
|
|
|
|
{
|
|
|
|
case ASCH_PIN_SYMBOL_INNEREDGE::CLOCK:
|
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::CLOCK_LOW );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::INPUT_LOW );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( elem.symbolOuterEdge == ASCH_PIN_SYMBOL_OUTEREDGE::LOW_OUTPUT )
|
|
|
|
{
|
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::OUTPUT_LOW );
|
|
|
|
}
|
2020-10-09 14:23:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
switch( elem.symbolInnerEdge )
|
|
|
|
{
|
|
|
|
case ASCH_PIN_SYMBOL_INNEREDGE::CLOCK:
|
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::CLOCK );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::LINE ); // nothing to do
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 11:52:47 +00:00
|
|
|
void SetEdaTextJustification( EDA_TEXT* text, ASCH_LABEL_JUSTIFICATION justification )
|
|
|
|
{
|
|
|
|
switch( justification )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::UNKNOWN:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::BOTTOM_CENTER:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::BOTTOM_RIGHT:
|
|
|
|
text->SetVertJustify( EDA_TEXT_VJUSTIFY_T::GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
break;
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::CENTER_LEFT:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::CENTER_CENTER:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::CENTER_RIGHT:
|
|
|
|
text->SetVertJustify( EDA_TEXT_VJUSTIFY_T::GR_TEXT_VJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::TOP_LEFT:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::TOP_CENTER:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::TOP_RIGHT:
|
|
|
|
text->SetVertJustify( EDA_TEXT_VJUSTIFY_T::GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( justification )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::UNKNOWN:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::CENTER_LEFT:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::TOP_LEFT:
|
|
|
|
text->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::BOTTOM_CENTER:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::CENTER_CENTER:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::TOP_CENTER:
|
|
|
|
text->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::BOTTOM_RIGHT:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::CENTER_RIGHT:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::TOP_RIGHT:
|
|
|
|
text->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_LABEL elem( aProperties );
|
|
|
|
|
2020-10-17 12:33:30 +00:00
|
|
|
// TODO: text variable support
|
2020-10-17 11:52:47 +00:00
|
|
|
if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_TEXT* text = new SCH_TEXT( elem.location + m_sheetOffset, elem.text );
|
2020-10-17 11:52:47 +00:00
|
|
|
|
|
|
|
SetEdaTextJustification( text, elem.justification );
|
|
|
|
|
2020-10-17 12:33:30 +00:00
|
|
|
size_t fontId = static_cast<int>( elem.fontId );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-10-17 12:33:30 +00:00
|
|
|
if( m_altiumSheet && fontId > 0 && fontId <= m_altiumSheet->fonts.size() )
|
|
|
|
{
|
|
|
|
const ASCH_SHEET_FONT& font = m_altiumSheet->fonts.at( fontId - 1 );
|
|
|
|
text->SetItalic( font.italic );
|
|
|
|
text->SetBold( font.bold );
|
|
|
|
text->SetTextSize( { font.size / 2, font.size / 2 } );
|
|
|
|
}
|
|
|
|
|
2020-10-17 11:52:47 +00:00
|
|
|
text->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( text );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto& symbol = m_symbols.find( elem.ownerindex );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-10-17 11:52:47 +00:00
|
|
|
if( symbol == m_symbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Label has non-existent ownerindex %d." ),
|
|
|
|
elem.ownerindex ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
2020-10-17 11:52:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& component = m_components.at( symbol->first );
|
|
|
|
|
|
|
|
LIB_TEXT* text = new LIB_TEXT( symbol->second );
|
|
|
|
symbol->second->AddDrawItem( text );
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
text->SetUnit( elem.ownerpartid );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
text->SetPosition( GetRelativePosition( elem.location + m_sheetOffset, component ) );
|
2020-10-17 11:52:47 +00:00
|
|
|
text->SetText( elem.text );
|
|
|
|
SetEdaTextJustification( text, elem.justification );
|
2020-10-17 12:33:30 +00:00
|
|
|
|
|
|
|
size_t fontId = static_cast<int>( elem.fontId );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-10-17 12:33:30 +00:00
|
|
|
if( m_altiumSheet && fontId > 0 && fontId <= m_altiumSheet->fonts.size() )
|
|
|
|
{
|
|
|
|
const ASCH_SHEET_FONT& font = m_altiumSheet->fonts.at( fontId - 1 );
|
|
|
|
text->SetItalic( font.italic );
|
|
|
|
text->SetBold( font.bold );
|
|
|
|
text->SetTextSize( { font.size / 2, font.size / 2 } );
|
|
|
|
}
|
2020-10-17 11:52:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-10 14:56:19 +00:00
|
|
|
void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_BEZIER elem( aProperties );
|
|
|
|
|
2020-10-10 16:41:19 +00:00
|
|
|
if( elem.points.size() < 2 )
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Bezier has %d control points. At least 2 are "
|
|
|
|
"expected." ),
|
|
|
|
static_cast<int>( elem.points.size() ) ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
2020-10-10 16:41:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-10 14:56:19 +00:00
|
|
|
if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
2020-10-10 16:41:19 +00:00
|
|
|
for( size_t i = 0; i + 1 < elem.points.size(); i += 3 )
|
|
|
|
{
|
|
|
|
if( i + 2 == elem.points.size() )
|
|
|
|
{
|
|
|
|
// special case: single line
|
2020-11-05 23:19:47 +00:00
|
|
|
SCH_LINE* line = new SCH_LINE( elem.points.at( i ) + m_sheetOffset,
|
|
|
|
SCH_LAYER_ID::LAYER_NOTES );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
line->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset );
|
2020-10-10 16:41:19 +00:00
|
|
|
line->SetLineWidth( elem.lineWidth );
|
2020-10-14 19:04:53 +00:00
|
|
|
line->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
2020-10-10 16:41:19 +00:00
|
|
|
|
|
|
|
line->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( line );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// simulate bezier using line segments
|
|
|
|
std::vector<wxPoint> bezierPoints;
|
|
|
|
std::vector<wxPoint> polyPoints;
|
|
|
|
for( size_t j = i; j < elem.points.size() && j < i + 4; j++ )
|
|
|
|
{
|
2020-10-17 13:35:22 +00:00
|
|
|
bezierPoints.push_back( elem.points.at( j ) + m_sheetOffset );
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BEZIER_POLY converter( bezierPoints );
|
|
|
|
converter.GetPoly( polyPoints );
|
|
|
|
|
2020-10-18 13:11:12 +00:00
|
|
|
for( size_t k = 0; k + 1 < polyPoints.size(); k++ )
|
2020-10-10 16:41:19 +00:00
|
|
|
{
|
2020-11-05 23:19:47 +00:00
|
|
|
SCH_LINE* line = new SCH_LINE( polyPoints.at( k ) + m_sheetOffset,
|
|
|
|
SCH_LAYER_ID::LAYER_NOTES );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
line->SetEndPoint( polyPoints.at( k + 1 ) + m_sheetOffset );
|
2020-10-10 16:41:19 +00:00
|
|
|
line->SetLineWidth( elem.lineWidth );
|
|
|
|
|
|
|
|
line->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( line );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-10 14:56:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto& symbol = m_symbols.find( elem.ownerindex );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-10-10 14:56:19 +00:00
|
|
|
if( symbol == m_symbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Bezier has non-existent ownerindex %d." ),
|
|
|
|
elem.ownerindex ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
2020-10-10 14:56:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
|
2020-10-23 15:02:56 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-10 14:56:19 +00:00
|
|
|
const auto& component = m_components.at( symbol->first );
|
|
|
|
|
2020-10-10 16:41:19 +00:00
|
|
|
for( size_t i = 0; i + 1 < elem.points.size(); i += 3 )
|
2020-10-10 14:56:19 +00:00
|
|
|
{
|
2020-10-10 16:41:19 +00:00
|
|
|
if( i + 2 == elem.points.size() )
|
|
|
|
{
|
|
|
|
// special case: single line
|
|
|
|
LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second );
|
|
|
|
symbol->second->AddDrawItem( line );
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
line->SetUnit( elem.ownerpartid );
|
|
|
|
|
2020-10-10 16:41:19 +00:00
|
|
|
for( size_t j = i; j < elem.points.size() && j < i + 2; j++ )
|
|
|
|
{
|
2020-11-05 23:19:47 +00:00
|
|
|
line->AddPoint( GetRelativePosition( elem.points.at( j ) + m_sheetOffset,
|
|
|
|
component ) );
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
line->SetWidth( elem.lineWidth );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// bezier always has maximum of 4 control points
|
|
|
|
LIB_BEZIER* bezier = new LIB_BEZIER( symbol->second );
|
|
|
|
symbol->second->AddDrawItem( bezier );
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
bezier->SetUnit( elem.ownerpartid );
|
|
|
|
|
2020-10-10 16:41:19 +00:00
|
|
|
for( size_t j = i; j < elem.points.size() && j < i + 4; j++ )
|
|
|
|
{
|
2020-11-05 23:19:47 +00:00
|
|
|
bezier->AddPoint( GetRelativePosition( elem.points.at( j ) + m_sheetOffset,
|
|
|
|
component ) );
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bezier->SetWidth( elem.lineWidth );
|
|
|
|
}
|
2020-10-10 14:56:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_ALTIUM_PLUGIN::ParsePolyline( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_POLYLINE elem( aProperties );
|
|
|
|
|
|
|
|
if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
2020-10-14 19:04:53 +00:00
|
|
|
PLOT_DASH_TYPE dashType = PLOT_DASH_TYPE::DEFAULT;
|
|
|
|
switch( elem.linestyle )
|
|
|
|
{
|
|
|
|
default:
|
2020-11-05 23:19:47 +00:00
|
|
|
case ASCH_POLYLINE_LINESTYLE::SOLID: dashType = PLOT_DASH_TYPE::SOLID; break;
|
|
|
|
case ASCH_POLYLINE_LINESTYLE::DASHED: dashType = PLOT_DASH_TYPE::DASH; break;
|
|
|
|
case ASCH_POLYLINE_LINESTYLE::DOTTED: dashType = PLOT_DASH_TYPE::DOT; break;
|
|
|
|
case ASCH_POLYLINE_LINESTYLE::DASH_DOTTED: dashType = PLOT_DASH_TYPE::DASHDOT; break;
|
2020-10-14 19:04:53 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 13:11:12 +00:00
|
|
|
for( size_t i = 0; i + 1 < elem.points.size(); i++ )
|
2020-10-10 14:56:19 +00:00
|
|
|
{
|
2020-11-05 23:19:47 +00:00
|
|
|
SCH_LINE* line = new SCH_LINE( elem.points.at( i ) + m_sheetOffset,
|
|
|
|
SCH_LAYER_ID::LAYER_NOTES );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
line->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset );
|
2020-10-10 16:41:19 +00:00
|
|
|
line->SetLineWidth( elem.lineWidth );
|
2020-10-14 19:04:53 +00:00
|
|
|
line->SetLineStyle( dashType );
|
2020-10-10 14:56:19 +00:00
|
|
|
|
|
|
|
line->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( line );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto& symbol = m_symbols.find( elem.ownerindex );
|
|
|
|
if( symbol == m_symbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Polyline has non-existent ownerindex %d." ),
|
|
|
|
elem.ownerindex ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
2020-10-10 14:56:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
|
2020-10-23 15:02:56 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-10 14:56:19 +00:00
|
|
|
const auto& component = m_components.at( symbol->first );
|
|
|
|
|
|
|
|
LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second );
|
|
|
|
symbol->second->AddDrawItem( line );
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
line->SetUnit( elem.ownerpartid );
|
|
|
|
|
2020-10-10 14:56:19 +00:00
|
|
|
for( wxPoint& point : elem.points )
|
|
|
|
{
|
2020-10-17 13:35:22 +00:00
|
|
|
line->AddPoint( GetRelativePosition( point + m_sheetOffset, component ) );
|
2020-10-10 14:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
line->SetWidth( elem.lineWidth );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-10 14:22:53 +00:00
|
|
|
void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map<wxString, wxString>& aProperties )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2020-10-10 14:22:53 +00:00
|
|
|
ASCH_POLYGON elem( aProperties );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2020-10-10 14:22:53 +00:00
|
|
|
if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2020-10-10 14:22:53 +00:00
|
|
|
// TODO: we cannot fill this polygon, only draw it for now
|
2020-10-18 13:11:12 +00:00
|
|
|
for( size_t i = 0; i + 1 < elem.points.size(); i++ )
|
2020-10-10 14:22:53 +00:00
|
|
|
{
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_LINE* line =
|
|
|
|
new SCH_LINE( elem.points.at( i ) + m_sheetOffset, SCH_LAYER_ID::LAYER_NOTES );
|
|
|
|
line->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset );
|
2020-10-10 16:41:19 +00:00
|
|
|
line->SetLineWidth( elem.lineWidth );
|
2020-10-14 19:04:53 +00:00
|
|
|
line->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2020-10-10 14:22:53 +00:00
|
|
|
line->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( line );
|
|
|
|
}
|
|
|
|
|
|
|
|
// close polygon
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_LINE* line =
|
|
|
|
new SCH_LINE( elem.points.front() + m_sheetOffset, SCH_LAYER_ID::LAYER_NOTES );
|
|
|
|
line->SetEndPoint( elem.points.back() + m_sheetOffset );
|
2020-10-10 16:41:19 +00:00
|
|
|
line->SetLineWidth( elem.lineWidth );
|
2020-10-14 19:04:53 +00:00
|
|
|
line->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2020-10-10 14:22:53 +00:00
|
|
|
line->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( line );
|
|
|
|
}
|
|
|
|
else
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2020-10-10 14:22:53 +00:00
|
|
|
const auto& symbol = m_symbols.find( elem.ownerindex );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-10-10 14:22:53 +00:00
|
|
|
if( symbol == m_symbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Polygon has non-existent ownerindex %d." ),
|
|
|
|
elem.ownerindex ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
2020-10-10 14:22:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
|
2020-10-23 15:02:56 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-10 14:22:53 +00:00
|
|
|
const auto& component = m_components.at( symbol->first );
|
|
|
|
|
|
|
|
LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second );
|
|
|
|
symbol->second->AddDrawItem( line );
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
line->SetUnit( elem.ownerpartid );
|
|
|
|
|
2020-10-10 14:22:53 +00:00
|
|
|
for( wxPoint& point : elem.points )
|
2020-10-17 13:35:22 +00:00
|
|
|
line->AddPoint( GetRelativePosition( point + m_sheetOffset, component ) );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
line->AddPoint( GetRelativePosition( elem.points.front() + m_sheetOffset, component ) );
|
2020-10-10 14:22:53 +00:00
|
|
|
|
|
|
|
line->SetWidth( elem.lineWidth );
|
2020-10-14 19:04:53 +00:00
|
|
|
|
|
|
|
if( !elem.isSolid )
|
|
|
|
line->SetFillMode( FILL_TYPE::NO_FILL );
|
|
|
|
else if( elem.color == elem.areacolor )
|
2020-10-10 14:22:53 +00:00
|
|
|
line->SetFillMode( FILL_TYPE::FILLED_SHAPE );
|
2020-10-14 19:04:53 +00:00
|
|
|
else
|
|
|
|
line->SetFillMode( FILL_TYPE::FILLED_WITH_BG_BODYCOLOR );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
2020-10-10 14:22:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-14 19:15:09 +00:00
|
|
|
void SCH_ALTIUM_PLUGIN::ParseRoundRectangle( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_ROUND_RECTANGLE elem( aProperties );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
wxPoint sheetTopRight = elem.topRight + m_sheetOffset;
|
|
|
|
wxPoint sheetBottomLeft = elem.bottomLeft + m_sheetOffset;
|
|
|
|
|
2020-10-14 19:15:09 +00:00
|
|
|
if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
2020-10-17 13:35:22 +00:00
|
|
|
const wxPoint topLeft = { sheetBottomLeft.x, sheetTopRight.y };
|
|
|
|
const wxPoint bottomRight = { sheetTopRight.x, sheetBottomLeft.y };
|
2020-10-14 19:15:09 +00:00
|
|
|
|
|
|
|
// TODO: we cannot fill this rectangle, only draw it for now
|
|
|
|
// TODO: misses rounded edges
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_LINE* lineTop = new SCH_LINE( sheetTopRight, SCH_LAYER_ID::LAYER_NOTES );
|
2020-10-14 19:15:09 +00:00
|
|
|
lineTop->SetEndPoint( topLeft );
|
|
|
|
lineTop->SetLineWidth( elem.lineWidth );
|
|
|
|
lineTop->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
|
|
|
lineTop->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( lineTop );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_LINE* lineBottom = new SCH_LINE( sheetBottomLeft, SCH_LAYER_ID::LAYER_NOTES );
|
2020-10-14 19:15:09 +00:00
|
|
|
lineBottom->SetEndPoint( bottomRight );
|
|
|
|
lineBottom->SetLineWidth( elem.lineWidth );
|
|
|
|
lineBottom->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
|
|
|
lineBottom->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( lineBottom );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_LINE* lineRight = new SCH_LINE( sheetTopRight, SCH_LAYER_ID::LAYER_NOTES );
|
2020-10-14 19:15:09 +00:00
|
|
|
lineRight->SetEndPoint( bottomRight );
|
|
|
|
lineRight->SetLineWidth( elem.lineWidth );
|
|
|
|
lineRight->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
|
|
|
lineRight->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( lineRight );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_LINE* lineLeft = new SCH_LINE( sheetBottomLeft, SCH_LAYER_ID::LAYER_NOTES );
|
2020-10-14 19:15:09 +00:00
|
|
|
lineLeft->SetEndPoint( topLeft );
|
|
|
|
lineLeft->SetLineWidth( elem.lineWidth );
|
|
|
|
lineLeft->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
|
|
|
lineLeft->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( lineLeft );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto& symbol = m_symbols.find( elem.ownerindex );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-10-14 19:15:09 +00:00
|
|
|
if( symbol == m_symbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Rounded rectangle has non-existent "
|
|
|
|
"ownerindex %d." ),
|
|
|
|
elem.ownerindex ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
2020-10-14 19:15:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
|
2020-10-23 15:02:56 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-14 19:15:09 +00:00
|
|
|
const auto& component = m_components.at( symbol->first );
|
|
|
|
|
|
|
|
// TODO: misses rounded edges
|
|
|
|
LIB_RECTANGLE* rect = new LIB_RECTANGLE( symbol->second );
|
|
|
|
symbol->second->AddDrawItem( rect );
|
2020-10-23 15:20:07 +00:00
|
|
|
|
|
|
|
rect->SetUnit( elem.ownerpartid );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
rect->SetPosition( GetRelativePosition( elem.topRight + m_sheetOffset, component ) );
|
|
|
|
rect->SetEnd( GetRelativePosition( elem.bottomLeft + m_sheetOffset, component ) );
|
2020-10-14 19:15:09 +00:00
|
|
|
rect->SetWidth( elem.lineWidth );
|
|
|
|
|
2020-10-15 07:51:53 +00:00
|
|
|
if( !elem.isSolid )
|
|
|
|
rect->SetFillMode( FILL_TYPE::NO_FILL );
|
|
|
|
else if( elem.color == elem.areacolor )
|
|
|
|
rect->SetFillMode( FILL_TYPE::FILLED_SHAPE );
|
2020-10-14 19:15:09 +00:00
|
|
|
else
|
2020-10-15 07:51:53 +00:00
|
|
|
rect->SetFillMode( FILL_TYPE::FILLED_WITH_BG_BODYCOLOR );
|
2020-10-14 19:15:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-10 16:41:19 +00:00
|
|
|
void SCH_ALTIUM_PLUGIN::ParseArc( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_ARC elem( aProperties );
|
|
|
|
|
|
|
|
if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( _( "Arc drawing is not possible for now on schematic." ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto& symbol = m_symbols.find( elem.ownerindex );
|
|
|
|
if( symbol == m_symbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Arc has non-existent ownerindex %d." ),
|
|
|
|
elem.ownerindex ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
2020-10-10 16:41:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
|
2020-10-23 15:02:56 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-10 16:41:19 +00:00
|
|
|
const auto& component = m_components.at( symbol->first );
|
|
|
|
|
|
|
|
if( elem.startAngle == 0 && ( elem.endAngle == 0 || elem.endAngle == 360 ) )
|
|
|
|
{
|
|
|
|
LIB_CIRCLE* circle = new LIB_CIRCLE( symbol->second );
|
|
|
|
symbol->second->AddDrawItem( circle );
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
circle->SetUnit( elem.ownerpartid );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
circle->SetPosition( GetRelativePosition( elem.center + m_sheetOffset, component ) );
|
2020-10-10 16:41:19 +00:00
|
|
|
circle->SetRadius( elem.radius );
|
|
|
|
circle->SetWidth( elem.lineWidth );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LIB_ARC* arc = new LIB_ARC( symbol->second );
|
|
|
|
symbol->second->AddDrawItem( arc );
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
arc->SetUnit( elem.ownerpartid );
|
|
|
|
|
2020-10-10 16:41:19 +00:00
|
|
|
// TODO: correct?
|
2020-10-17 13:35:22 +00:00
|
|
|
arc->SetPosition( GetRelativePosition( elem.center + m_sheetOffset, component ) );
|
2020-10-10 16:41:19 +00:00
|
|
|
arc->SetRadius( elem.radius );
|
|
|
|
arc->SetFirstRadiusAngle( elem.startAngle * 10. );
|
|
|
|
arc->SetSecondRadiusAngle( elem.endAngle * 10. );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_ALTIUM_PLUGIN::ParseLine( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_LINE elem( aProperties );
|
|
|
|
|
|
|
|
if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
|
|
|
// close polygon
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_LINE* line = new SCH_LINE( elem.point1 + m_sheetOffset, SCH_LAYER_ID::LAYER_NOTES );
|
|
|
|
line->SetEndPoint( elem.point2 + m_sheetOffset );
|
2020-10-10 16:41:19 +00:00
|
|
|
line->SetLineWidth( elem.lineWidth );
|
2020-10-14 19:04:53 +00:00
|
|
|
line->SetLineStyle( PLOT_DASH_TYPE::SOLID ); // TODO?
|
2020-10-10 16:41:19 +00:00
|
|
|
|
|
|
|
line->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( line );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto& symbol = m_symbols.find( elem.ownerindex );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-10-10 16:41:19 +00:00
|
|
|
if( symbol == m_symbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Line has non-existent ownerindex %d." ),
|
|
|
|
elem.ownerindex ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
2020-10-10 16:41:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
|
2020-10-23 15:02:56 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-10 16:41:19 +00:00
|
|
|
const auto& component = m_components.at( symbol->first );
|
|
|
|
|
|
|
|
LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second );
|
|
|
|
symbol->second->AddDrawItem( line );
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
line->SetUnit( elem.ownerpartid );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
line->AddPoint( GetRelativePosition( elem.point1 + m_sheetOffset, component ) );
|
|
|
|
line->AddPoint( GetRelativePosition( elem.point2 + m_sheetOffset, component ) );
|
2020-10-10 16:41:19 +00:00
|
|
|
|
|
|
|
line->SetWidth( elem.lineWidth );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-10 14:22:53 +00:00
|
|
|
void SCH_ALTIUM_PLUGIN::ParseRectangle( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_RECTANGLE elem( aProperties );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
wxPoint sheetTopRight = elem.topRight + m_sheetOffset;
|
|
|
|
wxPoint sheetBottomLeft = elem.bottomLeft + m_sheetOffset;
|
|
|
|
|
2020-10-10 14:22:53 +00:00
|
|
|
if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2020-10-17 13:35:22 +00:00
|
|
|
const wxPoint topLeft = { sheetBottomLeft.x, sheetTopRight.y };
|
|
|
|
const wxPoint bottomRight = { sheetTopRight.x, sheetBottomLeft.y };
|
2020-10-10 14:22:53 +00:00
|
|
|
|
|
|
|
// TODO: we cannot fill this rectangle, only draw it for now
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_LINE* lineTop = new SCH_LINE( sheetTopRight, SCH_LAYER_ID::LAYER_NOTES );
|
2020-10-10 14:22:53 +00:00
|
|
|
lineTop->SetEndPoint( topLeft );
|
2020-10-10 16:41:19 +00:00
|
|
|
lineTop->SetLineWidth( elem.lineWidth );
|
2020-10-14 19:04:53 +00:00
|
|
|
lineTop->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
2020-10-10 14:22:53 +00:00
|
|
|
lineTop->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( lineTop );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_LINE* lineBottom = new SCH_LINE( sheetBottomLeft, SCH_LAYER_ID::LAYER_NOTES );
|
2020-10-10 14:22:53 +00:00
|
|
|
lineBottom->SetEndPoint( bottomRight );
|
2020-10-10 16:41:19 +00:00
|
|
|
lineBottom->SetLineWidth( elem.lineWidth );
|
2020-10-14 19:04:53 +00:00
|
|
|
lineBottom->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
2020-10-10 14:22:53 +00:00
|
|
|
lineBottom->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( lineBottom );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_LINE* lineRight = new SCH_LINE( sheetTopRight, SCH_LAYER_ID::LAYER_NOTES );
|
2020-10-10 14:22:53 +00:00
|
|
|
lineRight->SetEndPoint( bottomRight );
|
2020-10-10 16:41:19 +00:00
|
|
|
lineRight->SetLineWidth( elem.lineWidth );
|
2020-10-14 19:04:53 +00:00
|
|
|
lineRight->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
2020-10-10 14:22:53 +00:00
|
|
|
lineRight->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( lineRight );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_LINE* lineLeft = new SCH_LINE( sheetBottomLeft, SCH_LAYER_ID::LAYER_NOTES );
|
2020-10-10 14:22:53 +00:00
|
|
|
lineLeft->SetEndPoint( topLeft );
|
2020-10-10 16:41:19 +00:00
|
|
|
lineLeft->SetLineWidth( elem.lineWidth );
|
2020-10-14 19:04:53 +00:00
|
|
|
lineLeft->SetLineStyle( PLOT_DASH_TYPE::SOLID );
|
2020-10-10 14:22:53 +00:00
|
|
|
lineLeft->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( lineLeft );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-10 14:22:53 +00:00
|
|
|
const auto& symbol = m_symbols.find( elem.ownerindex );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2020-10-10 14:22:53 +00:00
|
|
|
if( symbol == m_symbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Rectangle has non-existent ownerindex %d." ),
|
|
|
|
elem.ownerindex ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
2020-10-10 14:22:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
|
2020-10-23 15:02:56 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-10 14:22:53 +00:00
|
|
|
const auto& component = m_components.at( symbol->first );
|
|
|
|
|
|
|
|
LIB_RECTANGLE* rect = new LIB_RECTANGLE( symbol->second );
|
|
|
|
symbol->second->AddDrawItem( rect );
|
2020-10-23 15:20:07 +00:00
|
|
|
|
|
|
|
rect->SetUnit( elem.ownerpartid );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
rect->SetPosition( GetRelativePosition( sheetTopRight, component ) );
|
|
|
|
rect->SetEnd( GetRelativePosition( sheetBottomLeft, component ) );
|
2020-10-10 14:22:53 +00:00
|
|
|
rect->SetWidth( elem.lineWidth );
|
2020-10-14 19:04:53 +00:00
|
|
|
|
|
|
|
if( !elem.isSolid )
|
2020-10-10 14:22:53 +00:00
|
|
|
rect->SetFillMode( FILL_TYPE::NO_FILL );
|
2020-10-14 19:04:53 +00:00
|
|
|
else if( elem.color == elem.areacolor )
|
2020-10-10 14:22:53 +00:00
|
|
|
rect->SetFillMode( FILL_TYPE::FILLED_SHAPE );
|
|
|
|
else
|
|
|
|
rect->SetFillMode( FILL_TYPE::FILLED_WITH_BG_BODYCOLOR );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-27 14:51:19 +00:00
|
|
|
void SCH_ALTIUM_PLUGIN::ParseSheetSymbol(
|
|
|
|
int aIndex, const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_SHEET_SYMBOL elem( aProperties );
|
|
|
|
|
|
|
|
SCH_SHEET* sheet = new SCH_SHEET( m_currentSheet, elem.location + m_sheetOffset );
|
|
|
|
SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
|
|
|
|
|
|
|
|
sheet->SetSize( elem.size );
|
|
|
|
|
|
|
|
sheet->SetBorderColor( GetColorFromInt( elem.color ) );
|
|
|
|
if( elem.isSolid )
|
|
|
|
sheet->SetBackgroundColor( GetColorFromInt( elem.areacolor ) );
|
|
|
|
|
|
|
|
sheet->SetScreen( screen );
|
|
|
|
|
|
|
|
sheet->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( sheet );
|
|
|
|
|
|
|
|
m_sheets.insert( { aIndex, sheet } );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_ALTIUM_PLUGIN::ParseSheetEntry( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_SHEET_ENTRY elem( aProperties );
|
|
|
|
|
|
|
|
const auto& sheet = m_sheets.find( elem.ownerindex );
|
|
|
|
if( sheet == m_sheets.end() )
|
|
|
|
{
|
2020-11-05 23:19:47 +00:00
|
|
|
wxLogError( wxString::Format( "Sheet Entry has non-existent ownerindex %d",
|
|
|
|
elem.ownerindex ) );
|
2020-10-27 14:51:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_SHEET_PIN* sheetPin = new SCH_SHEET_PIN( sheet->second );
|
|
|
|
sheet->second->AddPin( sheetPin );
|
|
|
|
|
|
|
|
sheetPin->SetText( elem.name );
|
|
|
|
sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_UNSPECIFIED );
|
|
|
|
//sheetPin->SetLabelSpinStyle( getSpinStyle( term.OrientAngle, false ) );
|
|
|
|
//sheetPin->SetPosition( getKiCadPoint( term.Position ) );
|
|
|
|
|
|
|
|
wxPoint pos = sheet->second->GetPosition();
|
|
|
|
wxSize size = sheet->second->GetSize();
|
|
|
|
|
|
|
|
switch( elem.side )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case ASCH_SHEET_ENTRY_SIDE::LEFT:
|
|
|
|
sheetPin->SetPosition( { pos.x, pos.y + elem.distanceFromTop } );
|
|
|
|
sheetPin->SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT );
|
|
|
|
sheetPin->SetEdge( SHEET_SIDE::SHEET_LEFT_SIDE );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_ENTRY_SIDE::RIGHT:
|
|
|
|
sheetPin->SetPosition( { pos.x + size.x, pos.y + elem.distanceFromTop } );
|
|
|
|
sheetPin->SetLabelSpinStyle( LABEL_SPIN_STYLE::RIGHT );
|
|
|
|
sheetPin->SetEdge( SHEET_SIDE::SHEET_RIGHT_SIDE );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_ENTRY_SIDE::TOP:
|
|
|
|
sheetPin->SetPosition( { pos.x + elem.distanceFromTop, pos.y } );
|
|
|
|
sheetPin->SetLabelSpinStyle( LABEL_SPIN_STYLE::UP );
|
|
|
|
sheetPin->SetEdge( SHEET_SIDE::SHEET_TOP_SIDE );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_ENTRY_SIDE::BOTTOM:
|
|
|
|
sheetPin->SetPosition( { pos.x + elem.distanceFromTop, pos.y + size.y } );
|
|
|
|
sheetPin->SetLabelSpinStyle( LABEL_SPIN_STYLE::BOTTOM );
|
|
|
|
sheetPin->SetEdge( SHEET_SIDE::SHEET_BOTTOM_SIDE );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( elem.iotype )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case ASCH_PORT_IOTYPE::UNSPECIFIED:
|
|
|
|
sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_UNSPECIFIED );
|
|
|
|
break;
|
|
|
|
case ASCH_PORT_IOTYPE::OUTPUT:
|
|
|
|
sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_OUTPUT );
|
|
|
|
break;
|
|
|
|
case ASCH_PORT_IOTYPE::INPUT:
|
|
|
|
sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_INPUT );
|
|
|
|
break;
|
|
|
|
case ASCH_PORT_IOTYPE::BIDI:
|
|
|
|
sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_BIDI );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-31 21:33:30 +00:00
|
|
|
wxPoint HelperGeneratePowerPortGraphics( LIB_PART* aKPart, ASCH_POWER_PORT_STYLE aStyle,
|
|
|
|
REPORTER* aReporter )
|
2020-10-24 16:40:16 +00:00
|
|
|
{
|
|
|
|
if( aStyle == ASCH_POWER_PORT_STYLE::CIRCLE || aStyle == ASCH_POWER_PORT_STYLE::ARROW )
|
|
|
|
{
|
|
|
|
LIB_POLYLINE* line1 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line1 );
|
|
|
|
line1->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line1->AddPoint( { 0, 0 } );
|
|
|
|
line1->AddPoint( { 0, Mils2iu( -50 ) } );
|
|
|
|
|
|
|
|
if( aStyle == ASCH_POWER_PORT_STYLE::CIRCLE )
|
|
|
|
{
|
|
|
|
LIB_CIRCLE* circle = new LIB_CIRCLE( aKPart );
|
|
|
|
aKPart->AddDrawItem( circle );
|
|
|
|
circle->SetWidth( Mils2iu( 5 ) );
|
|
|
|
circle->SetRadius( Mils2iu( 25 ) );
|
|
|
|
circle->SetPosition( { Mils2iu( 0 ), Mils2iu( -75 ) } );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line2 );
|
|
|
|
line2->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line2->AddPoint( { Mils2iu( -25 ), Mils2iu( -50 ) } );
|
|
|
|
line2->AddPoint( { Mils2iu( 25 ), Mils2iu( -50 ) } );
|
|
|
|
line2->AddPoint( { Mils2iu( 0 ), Mils2iu( -100 ) } );
|
|
|
|
line2->AddPoint( { Mils2iu( -25 ), Mils2iu( -50 ) } );
|
|
|
|
}
|
|
|
|
|
|
|
|
return { 0, Mils2iu( 150 ) };
|
|
|
|
}
|
|
|
|
else if( aStyle == ASCH_POWER_PORT_STYLE::WAVE )
|
|
|
|
{
|
|
|
|
LIB_POLYLINE* line = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line );
|
|
|
|
line->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line->AddPoint( { 0, 0 } );
|
|
|
|
line->AddPoint( { 0, Mils2iu( -72 ) } );
|
|
|
|
|
|
|
|
LIB_BEZIER* bezier = new LIB_BEZIER( aKPart );
|
|
|
|
aKPart->AddDrawItem( bezier );
|
|
|
|
bezier->SetWidth( Mils2iu( 5 ) );
|
|
|
|
bezier->AddPoint( { Mils2iu( 30 ), Mils2iu( -50 ) } );
|
|
|
|
bezier->AddPoint( { Mils2iu( 30 ), Mils2iu( -87 ) } );
|
|
|
|
bezier->AddPoint( { Mils2iu( -30 ), Mils2iu( -63 ) } );
|
|
|
|
bezier->AddPoint( { Mils2iu( -30 ), Mils2iu( -100 ) } );
|
|
|
|
|
|
|
|
return { 0, Mils2iu( 150 ) };
|
|
|
|
}
|
|
|
|
else if( aStyle == ASCH_POWER_PORT_STYLE::POWER_GROUND
|
|
|
|
|| aStyle == ASCH_POWER_PORT_STYLE::SIGNAL_GROUND
|
|
|
|
|| aStyle == ASCH_POWER_PORT_STYLE::EARTH
|
|
|
|
|| aStyle == ASCH_POWER_PORT_STYLE::GOST_ARROW )
|
|
|
|
{
|
|
|
|
LIB_POLYLINE* line1 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line1 );
|
|
|
|
line1->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line1->AddPoint( { 0, 0 } );
|
|
|
|
line1->AddPoint( { 0, Mils2iu( -100 ) } );
|
|
|
|
|
|
|
|
if( aStyle == ASCH_POWER_PORT_STYLE::POWER_GROUND )
|
|
|
|
{
|
|
|
|
LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line2 );
|
|
|
|
line2->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -100 ) } );
|
|
|
|
line2->AddPoint( { Mils2iu( 100 ), Mils2iu( -100 ) } );
|
|
|
|
|
|
|
|
LIB_POLYLINE* line3 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line3 );
|
|
|
|
line3->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line3->AddPoint( { Mils2iu( -70 ), Mils2iu( -130 ) } );
|
|
|
|
line3->AddPoint( { Mils2iu( 70 ), Mils2iu( -130 ) } );
|
|
|
|
|
|
|
|
LIB_POLYLINE* line4 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line4 );
|
|
|
|
line4->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line4->AddPoint( { Mils2iu( -40 ), Mils2iu( -160 ) } );
|
|
|
|
line4->AddPoint( { Mils2iu( 40 ), Mils2iu( -160 ) } );
|
|
|
|
|
|
|
|
LIB_POLYLINE* line5 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line5 );
|
|
|
|
line5->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line5->AddPoint( { Mils2iu( -10 ), Mils2iu( -190 ) } );
|
|
|
|
line5->AddPoint( { Mils2iu( 10 ), Mils2iu( -190 ) } );
|
|
|
|
}
|
|
|
|
else if( aStyle == ASCH_POWER_PORT_STYLE::SIGNAL_GROUND )
|
|
|
|
{
|
|
|
|
LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line2 );
|
|
|
|
line2->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -100 ) } );
|
|
|
|
line2->AddPoint( { Mils2iu( 100 ), Mils2iu( -100 ) } );
|
|
|
|
line2->AddPoint( { Mils2iu( 0 ), Mils2iu( -200 ) } );
|
|
|
|
line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -100 ) } );
|
|
|
|
}
|
|
|
|
else if( aStyle == ASCH_POWER_PORT_STYLE::EARTH )
|
|
|
|
{
|
|
|
|
LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line2 );
|
|
|
|
line2->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line2->AddPoint( { Mils2iu( -150 ), Mils2iu( -200 ) } );
|
|
|
|
line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -100 ) } );
|
|
|
|
line2->AddPoint( { Mils2iu( 100 ), Mils2iu( -100 ) } );
|
|
|
|
line2->AddPoint( { Mils2iu( 50 ), Mils2iu( -200 ) } );
|
|
|
|
|
|
|
|
LIB_POLYLINE* line3 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line3 );
|
|
|
|
line3->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line3->AddPoint( { Mils2iu( 0 ), Mils2iu( -100 ) } );
|
|
|
|
line3->AddPoint( { Mils2iu( -50 ), Mils2iu( -200 ) } );
|
|
|
|
}
|
|
|
|
else // ASCH_POWER_PORT_STYLE::GOST_ARROW
|
|
|
|
{
|
|
|
|
LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line2 );
|
|
|
|
line2->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line2->AddPoint( { Mils2iu( -25 ), Mils2iu( -50 ) } );
|
|
|
|
line2->AddPoint( { Mils2iu( 0 ), Mils2iu( -100 ) } );
|
|
|
|
line2->AddPoint( { Mils2iu( 25 ), Mils2iu( -50 ) } );
|
|
|
|
|
|
|
|
return { 0, Mils2iu( 150 ) }; // special case
|
|
|
|
}
|
|
|
|
|
|
|
|
return { 0, Mils2iu( 250 ) };
|
|
|
|
}
|
|
|
|
else if( aStyle == ASCH_POWER_PORT_STYLE::GOST_POWER_GROUND
|
|
|
|
|| aStyle == ASCH_POWER_PORT_STYLE::GOST_EARTH )
|
|
|
|
{
|
|
|
|
LIB_POLYLINE* line1 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line1 );
|
|
|
|
line1->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line1->AddPoint( { 0, 0 } );
|
|
|
|
line1->AddPoint( { 0, Mils2iu( -160 ) } );
|
|
|
|
|
|
|
|
LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line2 );
|
|
|
|
line2->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -160 ) } );
|
|
|
|
line2->AddPoint( { Mils2iu( 100 ), Mils2iu( -160 ) } );
|
|
|
|
|
|
|
|
LIB_POLYLINE* line3 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line3 );
|
|
|
|
line3->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line3->AddPoint( { Mils2iu( -60 ), Mils2iu( -200 ) } );
|
|
|
|
line3->AddPoint( { Mils2iu( 60 ), Mils2iu( -200 ) } );
|
|
|
|
|
|
|
|
LIB_POLYLINE* line4 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line4 );
|
|
|
|
line4->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line4->AddPoint( { Mils2iu( -20 ), Mils2iu( -240 ) } );
|
|
|
|
line4->AddPoint( { Mils2iu( 20 ), Mils2iu( -240 ) } );
|
|
|
|
|
|
|
|
if( aStyle == ASCH_POWER_PORT_STYLE::GOST_POWER_GROUND )
|
|
|
|
return { 0, Mils2iu( 300 ) };
|
|
|
|
|
|
|
|
LIB_CIRCLE* circle = new LIB_CIRCLE( aKPart );
|
|
|
|
aKPart->AddDrawItem( circle );
|
|
|
|
circle->SetWidth( Mils2iu( 10 ) );
|
|
|
|
circle->SetRadius( Mils2iu( 120 ) );
|
|
|
|
circle->SetPosition( { Mils2iu( 0 ), Mils2iu( -160 ) } );
|
|
|
|
|
|
|
|
return { 0, Mils2iu( 350 ) };
|
|
|
|
}
|
|
|
|
else if( aStyle == ASCH_POWER_PORT_STYLE::GOST_BAR )
|
|
|
|
{
|
|
|
|
LIB_POLYLINE* line1 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line1 );
|
|
|
|
line1->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line1->AddPoint( { 0, 0 } );
|
|
|
|
line1->AddPoint( { 0, Mils2iu( -200 ) } );
|
|
|
|
|
|
|
|
LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line2 );
|
|
|
|
line2->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line2->AddPoint( { Mils2iu( -100 ), Mils2iu( -200 ) } );
|
|
|
|
line2->AddPoint( { Mils2iu( 100 ), Mils2iu( -200 ) } );
|
|
|
|
|
|
|
|
return { 0, Mils2iu( 250 ) };
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aStyle != ASCH_POWER_PORT_STYLE::BAR )
|
2021-03-31 21:33:30 +00:00
|
|
|
{
|
|
|
|
aReporter->Report( _( "Power Port has unknown style, use bar instead." ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
|
|
|
}
|
2020-10-24 16:40:16 +00:00
|
|
|
|
|
|
|
LIB_POLYLINE* line1 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line1 );
|
|
|
|
line1->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line1->AddPoint( { 0, 0 } );
|
|
|
|
line1->AddPoint( { 0, Mils2iu( -100 ) } );
|
|
|
|
|
|
|
|
LIB_POLYLINE* line2 = new LIB_POLYLINE( aKPart );
|
|
|
|
aKPart->AddDrawItem( line2 );
|
|
|
|
line2->SetWidth( Mils2iu( 10 ) );
|
|
|
|
line2->AddPoint( { Mils2iu( -50 ), Mils2iu( -100 ) } );
|
|
|
|
line2->AddPoint( { Mils2iu( 50 ), Mils2iu( -100 ) } );
|
|
|
|
|
|
|
|
return { 0, Mils2iu( 150 ) };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_ALTIUM_PLUGIN::ParsePowerPort( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_POWER_PORT elem( aProperties );
|
|
|
|
|
2020-12-17 23:32:23 +00:00
|
|
|
LIB_ID libId = AltiumToKiCadLibID( getLibName(), elem.text );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
|
|
|
LIB_PART* kpart = nullptr;
|
|
|
|
|
|
|
|
const auto& symbol = m_powerSymbols.find( elem.text );
|
|
|
|
if( symbol != m_powerSymbols.end() )
|
|
|
|
{
|
|
|
|
kpart = symbol->second; // cache hit
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kpart = new LIB_PART( wxEmptyString );
|
|
|
|
kpart->SetPower();
|
|
|
|
kpart->SetName( elem.text );
|
|
|
|
kpart->GetReferenceField().SetText( "#PWR" );
|
|
|
|
kpart->GetValueField().SetText( elem.text );
|
|
|
|
kpart->GetValueField().SetVisible( true ); // TODO: why does this not work?
|
2020-11-05 23:19:47 +00:00
|
|
|
kpart->SetDescription( wxString::Format( _( "Power symbol creates a global label with name '%s'" ),
|
|
|
|
elem.text ) );
|
2020-10-24 16:40:16 +00:00
|
|
|
kpart->SetKeyWords( "power-flag" );
|
|
|
|
kpart->SetLibId( libId );
|
|
|
|
|
|
|
|
// generate graphic
|
|
|
|
LIB_PIN* pin = new LIB_PIN( kpart );
|
|
|
|
kpart->AddDrawItem( pin );
|
|
|
|
|
|
|
|
pin->SetName( elem.text );
|
|
|
|
pin->SetPosition( { 0, 0 } );
|
|
|
|
pin->SetLength( 0 );
|
|
|
|
|
|
|
|
// marks the pin as a global label
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
|
|
|
|
pin->SetVisible( false );
|
|
|
|
|
2021-03-31 21:33:30 +00:00
|
|
|
wxPoint valueFieldPos = HelperGeneratePowerPortGraphics( kpart, elem.style, m_reporter );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
|
|
|
kpart->GetValueField().SetPosition( valueFieldPos );
|
|
|
|
|
|
|
|
// this has to be done after parsing the LIB_PART!
|
|
|
|
m_pi->SaveSymbol( getLibFileName().GetFullPath(), kpart, m_properties.get() );
|
|
|
|
m_powerSymbols.insert( { elem.text, kpart } );
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_SHEET_PATH sheetpath;
|
|
|
|
m_rootSheet->LocatePathOfScreen( m_currentSheet->GetScreen(), &sheetpath );
|
|
|
|
|
|
|
|
// each component has its own symbol for now
|
|
|
|
SCH_COMPONENT* component = new SCH_COMPONENT();
|
|
|
|
component->SetRef( &sheetpath, "#PWR?" );
|
|
|
|
component->SetValue( elem.text );
|
|
|
|
component->SetLibId( libId );
|
|
|
|
component->SetLibSymbol( new LIB_PART( *kpart ) );
|
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
SCH_FIELD* valueField = component->GetField( VALUE_FIELD );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
|
|
|
// TODO: Why do I need to set those a second time?
|
|
|
|
valueField->SetVisible( true );
|
|
|
|
valueField->SetPosition( kpart->GetValueField().GetPosition() );
|
|
|
|
|
|
|
|
component->SetPosition( elem.location + m_sheetOffset );
|
|
|
|
|
|
|
|
switch( elem.orientation )
|
|
|
|
{
|
|
|
|
case ASCH_RECORD_ORIENTATION::RIGHTWARDS:
|
|
|
|
component->SetOrientation( COMPONENT_ORIENTATION_T::CMP_ORIENT_90 );
|
|
|
|
valueField->SetTextAngle( -900. );
|
|
|
|
valueField->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
case ASCH_RECORD_ORIENTATION::UPWARDS:
|
|
|
|
component->SetOrientation( COMPONENT_ORIENTATION_T::CMP_ORIENT_180 );
|
|
|
|
valueField->SetTextAngle( -1800. );
|
|
|
|
valueField->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
case ASCH_RECORD_ORIENTATION::LEFTWARDS:
|
|
|
|
component->SetOrientation( COMPONENT_ORIENTATION_T::CMP_ORIENT_270 );
|
|
|
|
valueField->SetTextAngle( -2700. );
|
|
|
|
valueField->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
case ASCH_RECORD_ORIENTATION::DOWNWARDS:
|
|
|
|
component->SetOrientation( COMPONENT_ORIENTATION_T::CMP_ORIENT_0 );
|
|
|
|
valueField->SetTextAngle( 0. );
|
|
|
|
valueField->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
default:
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( _( "Pin has unexpected orientation." ), RPT_SEVERITY_WARNING );
|
2020-10-24 16:40:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_currentSheet->GetScreen()->Append( component );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-27 13:07:42 +00:00
|
|
|
void SCH_ALTIUM_PLUGIN::ParsePort( const ASCH_PORT& aElem )
|
2020-10-26 15:54:49 +00:00
|
|
|
{
|
2020-10-27 13:07:42 +00:00
|
|
|
// Get both connection points where we could connect to
|
|
|
|
wxPoint start = aElem.location + m_sheetOffset;
|
|
|
|
wxPoint end = start;
|
|
|
|
|
|
|
|
switch( aElem.style )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case ASCH_PORT_STYLE::NONE_HORIZONTAL:
|
|
|
|
case ASCH_PORT_STYLE::LEFT:
|
|
|
|
case ASCH_PORT_STYLE::RIGHT:
|
|
|
|
case ASCH_PORT_STYLE::LEFT_RIGHT:
|
|
|
|
end.x += aElem.width;
|
|
|
|
break;
|
|
|
|
case ASCH_PORT_STYLE::NONE_VERTICAL:
|
|
|
|
case ASCH_PORT_STYLE::TOP:
|
|
|
|
case ASCH_PORT_STYLE::BOTTOM:
|
|
|
|
case ASCH_PORT_STYLE::TOP_BOTTOM:
|
|
|
|
end.y -= aElem.width;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check which connection points exists in the schematic
|
|
|
|
SCH_SCREEN* screen = m_currentSheet->GetScreen();
|
|
|
|
|
|
|
|
bool startIsWireTerminal = screen->IsTerminalPoint( start, LAYER_WIRE );
|
|
|
|
bool startIsBusTerminal = screen->IsTerminalPoint( start, LAYER_BUS );
|
|
|
|
|
|
|
|
bool endIsWireTerminal = screen->IsTerminalPoint( end, LAYER_WIRE );
|
|
|
|
bool endIsBusTerminal = screen->IsTerminalPoint( end, LAYER_BUS );
|
|
|
|
|
|
|
|
// check if any of the points is a terminal point
|
|
|
|
// TODO: there seems a problem to detect approximated connections towards component pins?
|
2020-11-05 23:19:47 +00:00
|
|
|
bool connectionFound = startIsWireTerminal
|
|
|
|
|| startIsBusTerminal
|
|
|
|
|| endIsWireTerminal
|
|
|
|
|| endIsBusTerminal;
|
|
|
|
|
2020-10-27 13:07:42 +00:00
|
|
|
if( !connectionFound )
|
2020-11-05 23:19:47 +00:00
|
|
|
{
|
|
|
|
wxLogError( wxString::Format( "There is a Port for \"%s\", but no connections towards it?",
|
|
|
|
aElem.name ) );
|
|
|
|
}
|
2020-10-27 13:07:42 +00:00
|
|
|
|
|
|
|
// Select label position. In case both match, we will add a line later.
|
|
|
|
wxPoint position = ( startIsWireTerminal || startIsBusTerminal ) ? start : end;
|
2020-10-26 15:54:49 +00:00
|
|
|
|
2020-10-27 13:07:42 +00:00
|
|
|
SCH_TEXT* const label = new SCH_GLOBALLABEL( position, aElem.name );
|
2020-10-26 15:54:49 +00:00
|
|
|
// TODO: detect correct label type depending on sheet settings, etc.
|
|
|
|
// label = new SCH_HIERLABEL( elem.location + m_sheetOffset, elem.name );
|
|
|
|
|
2020-10-27 13:07:42 +00:00
|
|
|
switch( aElem.iotype )
|
2020-10-26 15:54:49 +00:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case ASCH_PORT_IOTYPE::UNSPECIFIED:
|
|
|
|
label->SetShape( PINSHEETLABEL_SHAPE::PS_UNSPECIFIED );
|
|
|
|
break;
|
|
|
|
case ASCH_PORT_IOTYPE::OUTPUT:
|
|
|
|
label->SetShape( PINSHEETLABEL_SHAPE::PS_OUTPUT );
|
|
|
|
break;
|
|
|
|
case ASCH_PORT_IOTYPE::INPUT:
|
|
|
|
label->SetShape( PINSHEETLABEL_SHAPE::PS_INPUT );
|
|
|
|
break;
|
|
|
|
case ASCH_PORT_IOTYPE::BIDI:
|
|
|
|
label->SetShape( PINSHEETLABEL_SHAPE::PS_BIDI );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:07:42 +00:00
|
|
|
switch( aElem.style )
|
2020-10-26 15:54:49 +00:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case ASCH_PORT_STYLE::NONE_HORIZONTAL:
|
|
|
|
case ASCH_PORT_STYLE::LEFT:
|
|
|
|
case ASCH_PORT_STYLE::RIGHT:
|
|
|
|
case ASCH_PORT_STYLE::LEFT_RIGHT:
|
2020-10-27 13:07:42 +00:00
|
|
|
if( ( startIsWireTerminal || startIsBusTerminal ) )
|
|
|
|
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::RIGHT );
|
|
|
|
else
|
|
|
|
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT );
|
2020-10-26 15:54:49 +00:00
|
|
|
break;
|
|
|
|
case ASCH_PORT_STYLE::NONE_VERTICAL:
|
|
|
|
case ASCH_PORT_STYLE::TOP:
|
|
|
|
case ASCH_PORT_STYLE::BOTTOM:
|
|
|
|
case ASCH_PORT_STYLE::TOP_BOTTOM:
|
2020-10-27 13:07:42 +00:00
|
|
|
if( ( startIsWireTerminal || startIsBusTerminal ) )
|
|
|
|
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::UP );
|
|
|
|
else
|
|
|
|
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::BOTTOM );
|
2020-10-26 15:54:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
label->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( label );
|
|
|
|
|
2020-10-27 13:07:42 +00:00
|
|
|
// This is a hack, for the case both connection points are valid: add a small wire
|
|
|
|
if( ( startIsWireTerminal && endIsWireTerminal ) || !connectionFound )
|
2020-10-26 15:54:49 +00:00
|
|
|
{
|
|
|
|
SCH_LINE* wire = new SCH_LINE( start, SCH_LAYER_ID::LAYER_WIRE );
|
2020-10-27 13:07:42 +00:00
|
|
|
wire->SetEndPoint( end );
|
2020-10-26 15:54:49 +00:00
|
|
|
wire->SetLineWidth( Mils2iu( 2 ) );
|
|
|
|
wire->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( wire );
|
|
|
|
}
|
2020-10-27 13:07:42 +00:00
|
|
|
else if( startIsBusTerminal && endIsBusTerminal )
|
2020-10-26 15:54:49 +00:00
|
|
|
{
|
2020-10-27 13:07:42 +00:00
|
|
|
SCH_LINE* wire = new SCH_LINE( start, SCH_LAYER_ID::LAYER_BUS );
|
|
|
|
wire->SetEndPoint( end );
|
2020-10-26 15:54:49 +00:00
|
|
|
wire->SetLineWidth( Mils2iu( 2 ) );
|
|
|
|
wire->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( wire );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-14 19:23:36 +00:00
|
|
|
void SCH_ALTIUM_PLUGIN::ParseNoERC( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_NO_ERC elem( aProperties );
|
|
|
|
|
|
|
|
if( elem.isActive )
|
|
|
|
{
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_NO_CONNECT* noConnect = new SCH_NO_CONNECT( elem.location + m_sheetOffset );
|
2020-10-14 19:23:36 +00:00
|
|
|
|
|
|
|
noConnect->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( noConnect );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
void SCH_ALTIUM_PLUGIN::ParseNetLabel( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_NET_LABEL elem( aProperties );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_LABEL* label = new SCH_LABEL( elem.location + m_sheetOffset, elem.text );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
switch( elem.orientation )
|
|
|
|
{
|
2020-10-14 19:38:12 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::RIGHTWARDS:
|
|
|
|
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::RIGHT );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
2020-10-14 19:38:12 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::UPWARDS:
|
2020-08-23 19:01:08 +00:00
|
|
|
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::UP );
|
|
|
|
break;
|
2020-10-14 19:38:12 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::LEFTWARDS:
|
|
|
|
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT );
|
2020-08-23 19:01:08 +00:00
|
|
|
break;
|
2020-10-14 19:38:12 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::DOWNWARDS:
|
2020-08-23 19:01:08 +00:00
|
|
|
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::BOTTOM );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
label->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( label );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_ALTIUM_PLUGIN::ParseBus( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_BUS elem( aProperties );
|
|
|
|
|
2020-10-18 13:11:12 +00:00
|
|
|
for( size_t i = 0; i + 1 < elem.points.size(); i++ )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_LINE* bus =
|
|
|
|
new SCH_LINE( elem.points.at( i ) + m_sheetOffset, SCH_LAYER_ID::LAYER_BUS );
|
|
|
|
bus->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset );
|
2020-10-10 16:41:19 +00:00
|
|
|
bus->SetLineWidth( elem.lineWidth );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
bus->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( bus );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_ALTIUM_PLUGIN::ParseWire( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_WIRE elem( aProperties );
|
|
|
|
|
2020-10-18 13:11:12 +00:00
|
|
|
for( size_t i = 0; i + 1 < elem.points.size(); i++ )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_LINE* wire =
|
|
|
|
new SCH_LINE( elem.points.at( i ) + m_sheetOffset, SCH_LAYER_ID::LAYER_WIRE );
|
|
|
|
wire->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset );
|
2020-10-10 16:41:19 +00:00
|
|
|
wire->SetLineWidth( elem.lineWidth );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
wire->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( wire );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-09 15:21:27 +00:00
|
|
|
void SCH_ALTIUM_PLUGIN::ParseJunction( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_JUNCTION elem( aProperties );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
SCH_JUNCTION* junction = new SCH_JUNCTION( elem.location + m_sheetOffset );
|
2020-10-09 15:21:27 +00:00
|
|
|
|
|
|
|
junction->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( junction );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-10 19:45:36 +00:00
|
|
|
void SCH_ALTIUM_PLUGIN::ParseImage( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_IMAGE elem( aProperties );
|
|
|
|
|
|
|
|
wxPoint center = ( elem.location + elem.corner ) / 2 + m_sheetOffset;
|
|
|
|
std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>( center );
|
|
|
|
|
|
|
|
if( elem.embedimage )
|
|
|
|
{
|
|
|
|
const ASCH_STORAGE_FILE* storageFile = GetFileFromStorage( elem.filename );
|
|
|
|
|
|
|
|
if( !storageFile )
|
|
|
|
{
|
|
|
|
wxLogError(
|
|
|
|
wxString::Format( "Embedded file not found in storage: %s", elem.filename ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString storagePath = wxFileName::CreateTempFileName( "kicad_import_" );
|
|
|
|
|
|
|
|
// As wxZlibInputStream is not seekable, we need to write a temporary file
|
|
|
|
wxMemoryInputStream fileStream( storageFile->data.data(), storageFile->data.size() );
|
|
|
|
wxZlibInputStream zlibInputStream( fileStream );
|
|
|
|
wxFFileOutputStream outputStream( storagePath );
|
|
|
|
outputStream.Write( zlibInputStream );
|
|
|
|
outputStream.Close();
|
|
|
|
|
|
|
|
if( !bitmap->ReadImageFile( storagePath ) )
|
|
|
|
{
|
|
|
|
wxLogError( wxString::Format( "Error while reading image: %s", storagePath ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove temporary file
|
|
|
|
wxRemoveFile( storagePath );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !wxFileExists( elem.filename ) )
|
|
|
|
{
|
|
|
|
wxLogError( wxString::Format( "File not found on disk: %s", elem.filename ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !bitmap->ReadImageFile( elem.filename ) )
|
|
|
|
{
|
|
|
|
wxLogError( wxString::Format( "Error while reading image: %s", elem.filename ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// we only support one scale, thus we need to select one in case it does not keep aspect ratio
|
|
|
|
wxSize currentImageSize = bitmap->GetSize();
|
|
|
|
wxPoint expectedImageSize = elem.location - elem.corner;
|
|
|
|
double scaleX = std::abs( static_cast<double>( expectedImageSize.x ) / currentImageSize.x );
|
|
|
|
double scaleY = std::abs( static_cast<double>( expectedImageSize.y ) / currentImageSize.y );
|
|
|
|
bitmap->SetImageScale( std::min( scaleX, scaleY ) );
|
|
|
|
|
|
|
|
bitmap->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( bitmap.release() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 12:33:30 +00:00
|
|
|
void SCH_ALTIUM_PLUGIN::ParseSheet( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
m_altiumSheet = std::make_unique<ASCH_SHEET>( aProperties );
|
2020-10-17 13:35:22 +00:00
|
|
|
|
|
|
|
PAGE_INFO pageInfo;
|
|
|
|
|
|
|
|
bool isPortrait = m_altiumSheet->sheetOrientation == ASCH_SHEET_WORKSPACEORIENTATION::PORTRAIT;
|
|
|
|
switch( m_altiumSheet->sheetSize )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case ASCH_SHEET_SIZE::A4:
|
|
|
|
pageInfo.SetType( "A4", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::A3:
|
|
|
|
pageInfo.SetType( "A3", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::A2:
|
|
|
|
pageInfo.SetType( "A2", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::A1:
|
|
|
|
pageInfo.SetType( "A1", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::A0:
|
|
|
|
pageInfo.SetType( "A0", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::A:
|
|
|
|
pageInfo.SetType( "A", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::B:
|
|
|
|
pageInfo.SetType( "B", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::C:
|
|
|
|
pageInfo.SetType( "C", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::D:
|
|
|
|
pageInfo.SetType( "D", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::E:
|
|
|
|
pageInfo.SetType( "E", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::LETTER:
|
|
|
|
pageInfo.SetType( "USLetter", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::LEGAL:
|
|
|
|
pageInfo.SetType( "USLegal", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::TABLOID:
|
|
|
|
pageInfo.SetType( "A3", isPortrait ); // TODO: use User
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::ORCAD_A:
|
|
|
|
pageInfo.SetType( "A", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::ORCAD_B:
|
|
|
|
pageInfo.SetType( "B", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::ORCAD_C:
|
|
|
|
pageInfo.SetType( "C", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::ORCAD_D:
|
|
|
|
pageInfo.SetType( "D", isPortrait );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_SIZE::ORCAD_E:
|
|
|
|
pageInfo.SetType( "E", isPortrait );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_currentSheet->GetScreen()->SetPageSettings( pageInfo );
|
|
|
|
|
|
|
|
m_sheetOffset = { 0, pageInfo.GetHeightIU() };
|
2020-10-17 12:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-27 14:51:19 +00:00
|
|
|
void SetFieldOrientation( SCH_FIELD& aField, ASCH_RECORD_ORIENTATION aOrientation )
|
|
|
|
{
|
|
|
|
switch( aOrientation )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case ASCH_RECORD_ORIENTATION::RIGHTWARDS:
|
|
|
|
aField.SetTextAngle( 0 );
|
|
|
|
break;
|
|
|
|
case ASCH_RECORD_ORIENTATION::UPWARDS:
|
|
|
|
aField.SetTextAngle( 900 );
|
|
|
|
break;
|
|
|
|
case ASCH_RECORD_ORIENTATION::LEFTWARDS:
|
|
|
|
aField.SetTextAngle( 1800 );
|
|
|
|
break;
|
|
|
|
case ASCH_RECORD_ORIENTATION::DOWNWARDS:
|
|
|
|
aField.SetTextAngle( 2700 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_ALTIUM_PLUGIN::ParseSheetName( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_SHEET_NAME elem( aProperties );
|
|
|
|
|
|
|
|
const auto& sheet = m_sheets.find( elem.ownerindex );
|
|
|
|
if( sheet == m_sheets.end() )
|
|
|
|
{
|
2020-11-05 23:19:47 +00:00
|
|
|
wxLogError( wxString::Format( "Sheet Name has non-existent ownerindex %d",
|
|
|
|
elem.ownerindex ) );
|
2020-10-27 14:51:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_FIELD& sheetNameField = sheet->second->GetFields()[SHEETNAME];
|
|
|
|
|
|
|
|
sheetNameField.SetPosition( elem.location + m_sheetOffset );
|
|
|
|
sheetNameField.SetText( elem.text );
|
|
|
|
sheetNameField.SetVisible( !elem.isHidden );
|
|
|
|
|
|
|
|
sheetNameField.SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
sheetNameField.SetVertJustify( EDA_TEXT_VJUSTIFY_T::GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
|
|
|
|
SetFieldOrientation( sheetNameField, elem.orientation );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_ALTIUM_PLUGIN::ParseFileName( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_FILE_NAME elem( aProperties );
|
|
|
|
|
|
|
|
const auto& sheet = m_sheets.find( elem.ownerindex );
|
|
|
|
if( sheet == m_sheets.end() )
|
|
|
|
{
|
2020-11-05 23:19:47 +00:00
|
|
|
wxLogError( wxString::Format( "File Name has non-existent ownerindex %d",
|
|
|
|
elem.ownerindex ) );
|
2020-10-27 14:51:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_FIELD& filenameField = sheet->second->GetFields()[SHEETFILENAME];
|
|
|
|
|
|
|
|
filenameField.SetPosition( elem.location + m_sheetOffset );
|
2021-03-02 21:39:47 +00:00
|
|
|
|
|
|
|
// If last symbols are ".sChDoC", change them to ".kicad_sch"
|
|
|
|
if( ( elem.text.Right( GetFileExtension().length() + 1 ).Lower() ) == ( "." + GetFileExtension().Lower() ))
|
|
|
|
{
|
2021-03-04 07:47:25 +00:00
|
|
|
elem.text.RemoveLast( GetFileExtension().length() );
|
2021-03-03 01:06:25 +00:00
|
|
|
elem.text += KiCadSchematicFileExtension;
|
2021-03-02 21:39:47 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 12:22:57 +00:00
|
|
|
filenameField.SetText( elem.text );
|
2021-03-02 21:39:47 +00:00
|
|
|
|
2020-10-27 14:51:19 +00:00
|
|
|
filenameField.SetVisible( !elem.isHidden );
|
|
|
|
|
|
|
|
filenameField.SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
filenameField.SetVertJustify( EDA_TEXT_VJUSTIFY_T::GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
|
|
|
|
SetFieldOrientation( filenameField, elem.orientation );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
void SCH_ALTIUM_PLUGIN::ParseDesignator( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_DESIGNATOR elem( aProperties );
|
|
|
|
|
2020-10-26 17:26:49 +00:00
|
|
|
const auto& symbol = m_symbols.find( elem.ownerindex );
|
|
|
|
if( symbol == m_symbols.end() )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Designator has non-existent ownerindex %d." ),
|
|
|
|
elem.ownerindex ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
2020-10-26 17:26:49 +00:00
|
|
|
return;
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 17:26:49 +00:00
|
|
|
const auto& component = m_components.at( symbol->first );
|
|
|
|
|
|
|
|
SCH_SHEET_PATH sheetpath;
|
|
|
|
m_rootSheet->LocatePathOfScreen( m_currentSheet->GetScreen(), &sheetpath );
|
|
|
|
|
|
|
|
component->SetRef( &sheetpath, elem.text );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
SCH_FIELD* refField = component->GetField( REFERENCE_FIELD );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2020-10-26 17:26:49 +00:00
|
|
|
refField->SetPosition( elem.location + m_sheetOffset );
|
|
|
|
refField->SetVisible( true );
|
|
|
|
|
|
|
|
refField->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
refField->SetVertJustify( EDA_TEXT_VJUSTIFY_T::GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
|
2020-10-27 14:51:19 +00:00
|
|
|
SetFieldOrientation( *refField, elem.orientation );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
2020-10-17 14:03:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_ALTIUM_PLUGIN::ParseBusEntry( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_BUS_ENTRY elem( aProperties );
|
|
|
|
|
|
|
|
SCH_BUS_WIRE_ENTRY* busWireEntry = new SCH_BUS_WIRE_ENTRY( elem.location + m_sheetOffset );
|
|
|
|
|
|
|
|
wxPoint vector = elem.corner - elem.location;
|
|
|
|
busWireEntry->SetSize( { vector.x, vector.y } );
|
|
|
|
|
|
|
|
busWireEntry->SetFlags( IS_NEW );
|
|
|
|
m_currentSheet->GetScreen()->Append( busWireEntry );
|
|
|
|
}
|
2020-10-26 17:26:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_ALTIUM_PLUGIN::ParseParameter( const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
ASCH_PARAMETER elem( aProperties );
|
|
|
|
|
2021-03-14 15:40:36 +00:00
|
|
|
// TODO: fill in replacements from variant, sheet and project
|
2021-03-20 19:41:51 +00:00
|
|
|
altium_override_map_t stringReplacement = {
|
2021-03-14 15:40:36 +00:00
|
|
|
{ "Comment", "${VALUE}" },
|
|
|
|
{ "Value", "${Altium_Value}" },
|
|
|
|
};
|
|
|
|
|
2020-10-26 17:26:49 +00:00
|
|
|
if( elem.ownerindex <= 0 && elem.ownerpartid == ALTIUM_COMPONENT_NONE )
|
|
|
|
{
|
|
|
|
// This is some sheet parameter
|
|
|
|
if( elem.text == "*" )
|
|
|
|
return; // indicates parameter not set?
|
|
|
|
|
|
|
|
SCH_SHEET_PATH sheetpath;
|
|
|
|
m_rootSheet->LocatePathOfScreen( m_currentSheet->GetScreen(), &sheetpath );
|
|
|
|
|
|
|
|
if( elem.name == "SheetNumber" )
|
|
|
|
m_rootSheet->SetPageNumber( sheetpath, elem.text );
|
|
|
|
else if( elem.name == "Title" )
|
|
|
|
m_currentTitleBlock->SetTitle( elem.text );
|
|
|
|
else if( elem.name == "Revision" )
|
|
|
|
m_currentTitleBlock->SetRevision( elem.text );
|
|
|
|
else if( elem.name == "Date" )
|
|
|
|
m_currentTitleBlock->SetDate( elem.text );
|
|
|
|
else if( elem.name == "CompanyName" )
|
|
|
|
m_currentTitleBlock->SetCompany( elem.text );
|
|
|
|
// TODO: parse other parameters
|
|
|
|
// TODO: handle parameters in labels
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto& symbol = m_symbols.find( elem.ownerindex );
|
|
|
|
if( symbol == m_symbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& component = m_components.at( symbol->first );
|
|
|
|
|
|
|
|
// TODO: location not correct?
|
2021-01-30 14:44:32 +00:00
|
|
|
const wxPoint position = elem.location + m_sheetOffset;
|
|
|
|
|
|
|
|
SCH_FIELD* field = nullptr;
|
2021-03-14 15:40:36 +00:00
|
|
|
if( elem.name == "Comment" )
|
2021-01-30 14:44:32 +00:00
|
|
|
{
|
|
|
|
field = component->GetField( VALUE_FIELD );
|
|
|
|
field->SetPosition( position );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int fieldIdx = component->GetFieldCount();
|
2021-03-20 19:41:51 +00:00
|
|
|
wxString fieldName = elem.name.IsSameAs( "Value", false ) ? "Altium_Value" : elem.name;
|
2021-03-14 15:40:36 +00:00
|
|
|
field = component->AddField( { position, fieldIdx, component, fieldName } );
|
2021-01-30 14:44:32 +00:00
|
|
|
}
|
|
|
|
|
2021-03-14 15:40:36 +00:00
|
|
|
wxString kicadText = AltiumSpecialStringsToKiCadVariables( elem.text, stringReplacement );
|
|
|
|
field->SetText( kicadText );
|
2021-01-30 14:44:32 +00:00
|
|
|
|
|
|
|
field->SetVisible( !elem.isHidden );
|
|
|
|
field->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_LEFT );
|
2020-10-26 17:26:49 +00:00
|
|
|
|
|
|
|
switch( elem.orientation )
|
|
|
|
{
|
2021-01-30 14:44:32 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::RIGHTWARDS: field->SetTextAngle( 0 ); break;
|
|
|
|
case ASCH_RECORD_ORIENTATION::UPWARDS: field->SetTextAngle( 90 ); break;
|
|
|
|
case ASCH_RECORD_ORIENTATION::LEFTWARDS: field->SetTextAngle( 180 ); break;
|
|
|
|
case ASCH_RECORD_ORIENTATION::DOWNWARDS: field->SetTextAngle( 270 ); break;
|
2020-10-26 17:26:49 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-02-24 13:48:02 +00:00
|
|
|
}
|