ADDED: Altium SchLib Support

This commit is contained in:
Seth Hillbrand 2023-08-28 14:50:56 -07:00
parent cb3c712a9c
commit 24d3df5416
8 changed files with 1457 additions and 496 deletions

View File

@ -277,6 +277,41 @@ ALTIUM_COMPOUND_FILE::FindStreamSingleLevel( const CFB::COMPOUND_FILE_ENTRY* aEn
}
std::map<wxString, const CFB::COMPOUND_FILE_ENTRY*>
ALTIUM_COMPOUND_FILE::GetLibSymbols( const CFB::COMPOUND_FILE_ENTRY* aStart ) const
{
const CFB::COMPOUND_FILE_ENTRY* root = aStart ? aStart : m_reader->GetRootEntry();
if( !root )
return {};
std::map<wxString, const CFB::COMPOUND_FILE_ENTRY*> folders;
m_reader->EnumFiles( root, 1, [&]( const CFB::COMPOUND_FILE_ENTRY* tentry, const CFB::utf16string&, int ) -> int
{
wxString dirName = UTF16ToWstring( tentry->name, tentry->nameLen );
if( m_reader->IsStream( tentry ) )
return 0;
m_reader->EnumFiles( tentry, 1,
[&]( const CFB::COMPOUND_FILE_ENTRY* entry, const CFB::utf16string&, int ) -> int
{
std::wstring fileName = UTF16ToWstring( entry->name, entry->nameLen );
if( m_reader->IsStream( entry ) && fileName == L"Data" )
folders[dirName] = entry;
return 0;
} );
return 0;
} );
return folders;
}
const CFB::COMPOUND_FILE_ENTRY*
ALTIUM_COMPOUND_FILE::FindStream( const CFB::COMPOUND_FILE_ENTRY* aStart,
const std::vector<std::string>& aStreamPath ) const
@ -340,11 +375,16 @@ ALTIUM_PARSER::ALTIUM_PARSER( std::unique_ptr<char[]>& aContent, size_t aSize )
}
std::map<wxString, wxString> ALTIUM_PARSER::ReadProperties()
std::map<wxString, wxString> ALTIUM_PARSER::ReadProperties(
std::function<std::map<wxString, wxString>( const std::string& )> handleBinaryData )
{
std::map<wxString, wxString> kv;
uint32_t length = Read<uint32_t>();
bool isBinary = ( length & 0xff000000 ) != 0;
length &= 0x00ffffff;
if( length > GetRemainingBytes() )
{
@ -372,6 +412,11 @@ std::map<wxString, wxString> ALTIUM_PARSER::ReadProperties()
std::string str = std::string( m_pos, length - ( hasNullByte ? 1 : 0 ) );
m_pos += length;
if( isBinary )
{
return handleBinaryData( str );
}
std::size_t token_end = 0;
while( token_end < str.size() && token_end != std::string::npos )
@ -542,4 +587,4 @@ wxString ALTIUM_PARSER::ReadUnicodeString( const std::map<wxString, wxString>& a
}
return ReadString( aProps, aKey, aDefault );
}
}

View File

@ -30,9 +30,13 @@
#include <numeric>
#include <wx/gdicmn.h>
#include <wx/mstream.h>
#include <wx/zstream.h>
#include <math/vector2d.h>
#include <vector>
#include <string>
#include <stdexcept>
namespace CFB
{
@ -75,6 +79,8 @@ public:
const std::string aName,
const bool aIsStream ) const;
std::map<wxString, const CFB::COMPOUND_FILE_ENTRY*> GetLibSymbols( const CFB::COMPOUND_FILE_ENTRY* aStart ) const;
private:
std::unique_ptr<CFB::CompoundFileReader> m_reader;
std::vector<char> m_buffer;
@ -238,7 +244,12 @@ public:
return length;
}
std::map<wxString, wxString> ReadProperties();
std::map<wxString, wxString> ReadProperties(
std::function<std::map<wxString, wxString>( const std::string& )> handleBinaryData =
[]( const std::string& )
{
return std::map<wxString, wxString>();
} );
static int32_t ConvertToKicadUnit( const double aValue );
@ -311,4 +322,110 @@ private:
};
class ALTIUM_BINARY_READER
{
public:
ALTIUM_BINARY_READER( const std::string& binaryData ) : m_data( binaryData ), m_position( 0 ) {}
int32_t ReadInt32()
{
if( m_position + sizeof( int32_t ) > m_data.size() )
throw std::out_of_range( "ALTIUM_BINARY_READER: out of range" );
int32_t value = *reinterpret_cast<const int32_t*>( &m_data[m_position] );
m_position += sizeof( int32_t );
return value;
}
int16_t ReadInt16()
{
if( m_position + sizeof( int16_t ) > m_data.size() )
throw std::out_of_range( "ALTIUM_BINARY_READER: out of range" );
int16_t value = *reinterpret_cast<const int16_t*>( &m_data[m_position] );
m_position += sizeof( int16_t );
return value;
}
uint8_t ReadByte()
{
if( m_position + sizeof( uint8_t ) > m_data.size() )
throw std::out_of_range( "ALTIUM_BINARY_READER: out of range" );
uint8_t value = *reinterpret_cast<const uint8_t*>( &m_data[m_position] );
m_position += sizeof( uint8_t );
return value;
}
std::string ReadPascalString()
{
uint8_t length = ReadByte();
if( m_position + length > m_data.size() )
throw std::out_of_range( "ALTIUM_BINARY_READER: out of range" );
std::string pascalString( &m_data[m_position], &m_data[m_position + length] );
m_position += length;
return pascalString;
}
private:
const std::string& m_data;
size_t m_position;
};
class ALTIUM_COMPRESSED_READER : public ALTIUM_BINARY_READER
{
public:
ALTIUM_COMPRESSED_READER( const std::string& aData ) : ALTIUM_BINARY_READER( aData )
{}
std::pair<int, std::string> ReadCompressedString()
{
std::string result;
int id = -1;
while( true )
{
uint8_t byte = ReadByte();
if( byte != 0xD0 )
throw std::runtime_error( "ALTIUM_COMPRESSED_READER: invalid compressed string" );
std::string str = ReadPascalString();
id = std::stoi( str );
std::string data = ReadPascalString();
result = decompressData( data );
}
return std::make_pair( id, result );
}
private:
std::string decompressData( std::string& aData )
{
// Create a memory input stream with the buffer
wxMemoryInputStream memStream( (void*) aData.data(), aData.length() );
// Create a zlib input stream with the memory input stream
wxZlibInputStream zStream( memStream );
// Prepare a string to hold decompressed data
std::string decompressedData;
// Read decompressed data from the zlib input stream
while( !zStream.Eof() )
{
char buffer[1024];
zStream.Read( buffer, sizeof( buffer ) );
size_t bytesRead = zStream.LastRead();
decompressedData.append( buffer, bytesRead );
}
return decompressedData;
}
};
#endif //ALTIUM_PARSER_H

View File

@ -310,7 +310,7 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, P
fileFiltersStr = _( "All supported formats" ) + wxT( "|" ) + allWildcardsStr + wxT( "|" )
+ fileFiltersStr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, aGrid,
&cfg->m_lastSymbolLibDir, fileFiltersStr,
true, m_project->GetProjectPath() ) );
@ -831,7 +831,7 @@ void PANEL_SYM_LIB_TABLE::onConvertLegacyLibraries( wxCommandEvent& event )
for( int row : selectedRows )
{
if( m_cur_grid->GetCellValue( row, COL_TYPE ) != databaseType &&
if( m_cur_grid->GetCellValue( row, COL_TYPE ) != databaseType &&
m_cur_grid->GetCellValue( row, COL_TYPE ) != kicadType )
{
legacyRows.push_back( row );

View File

@ -0,0 +1,45 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
*
*
* 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 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _ALTIUM_LIB_PLUGIN_CACHE_
#define _ALTIUM_LIB_PLUGIN_CACHE_
#include "../sch_lib_plugin_cache.h"
class FILE_LINE_READER;
class SCH_SEXPR_PLUGIN;
/**
* A cache assistant for Altium symbol libraries.
*/
class ALTIUM_LIB_PLUGIN_CACHE : public SCH_LIB_PLUGIN_CACHE
{
public:
ALTIUM_LIB_PLUGIN_CACHE( const wxString& aLibraryPath );
virtual ~ALTIUM_LIB_PLUGIN_CACHE();
void Load() override;
private:
friend SCH_SEXPR_PLUGIN;
};
#endif // _ALTIUM_LIB_PLUGIN_CACHE_

View File

@ -145,6 +145,8 @@ ASCH_PIN::ASCH_PIN( const std::map<wxString, wxString>& aProps )
{
wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PIN );
isKiCadLibPin = ALTIUM_PARSER::ReadBool( aProps, "ISKICADLIBPIN", false );
ownerindex = ReadOwnerIndex( aProps );
ownerpartid = ReadOwnerPartId( aProps );
ownerpartdisplaymode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
@ -154,29 +156,27 @@ ASCH_PIN::ASCH_PIN( const std::map<wxString, wxString>& aProps )
designator = ALTIUM_PARSER::ReadString( aProps, "DESIGNATOR", "" );
int symbolOuterInt = ALTIUM_PARSER::ReadInt( aProps, "SYMBOL_OUTER", 0 );
symbolOuter = static_cast<ASCH_PIN_SYMBOL_OUTER>( symbolOuterInt );
symbolOuter = ASCH_PIN_SYMBOL::FromInt( symbolOuterInt );
int symbolInnerInt = ALTIUM_PARSER::ReadInt( aProps, "SYMBOL_INNER", 0 );
symbolInner = static_cast<ASCH_PIN_SYMBOL_INNER>( symbolInnerInt );
symbolInner = ASCH_PIN_SYMBOL::FromInt( symbolInnerInt );
int symbolOuterEdgeInt = ALTIUM_PARSER::ReadInt( aProps, "SYMBOL_OUTEREDGE", 0 );
symbolOuterEdge = ( symbolOuterEdgeInt == 0 || symbolOuterEdgeInt == 1
|| symbolOuterEdgeInt == 4 || symbolOuterEdgeInt == 17 ) ?
static_cast<ASCH_PIN_SYMBOL_OUTEREDGE>( symbolOuterEdgeInt ) :
ASCH_PIN_SYMBOL_OUTEREDGE::NO_SYMBOL;
symbolOuterEdge = ASCH_PIN_SYMBOL::FromInt( symbolOuterEdgeInt );
int symbolInnerEdgeInt = ALTIUM_PARSER::ReadInt( aProps, "SYMBOL_INNEREDGE", 0 );
symbolInnerEdge = ( symbolInnerEdgeInt == 0 || symbolInnerEdgeInt == 3 ) ?
static_cast<ASCH_PIN_SYMBOL_INNEREDGE>( symbolInnerEdgeInt ) :
ASCH_PIN_SYMBOL_INNEREDGE::NO_SYMBOL;
symbolInnerEdge = ASCH_PIN_SYMBOL::FromInt( symbolInnerEdgeInt );
electrical = ReadEnum<ASCH_PIN_ELECTRICAL>( aProps, "ELECTRICAL", 0, 7,
ASCH_PIN_ELECTRICAL::INPUT );
int pinconglomerate = ALTIUM_PARSER::ReadInt( aProps, "PINCONGLOMERATE", 0 );
orientation = static_cast<ASCH_RECORD_ORIENTATION>( pinconglomerate & 0x03 );
hidden = ( pinconglomerate & 0x04 ) != 0;
showPinName = ( pinconglomerate & 0x08 ) != 0;
showDesignator = ( pinconglomerate & 0x10 ) != 0;
// graphically locked pins are in bit 0x40, but we don't care about that
int x = ALTIUM_PARSER::ReadInt( aProps, "LOCATION.X", 0 );
int xfrac = ALTIUM_PARSER::ReadInt( aProps, "LOCATION.X_FRAC", 0 );
@ -194,26 +194,35 @@ ASCH_PIN::ASCH_PIN( const std::map<wxString, wxString>& aProps )
int kicadY = y;
int kicadYfrac = yfrac;
int offsetY = p;
int offsetYfrac = pfrac;
if( isKiCadLibPin )
{
offsetY = -offsetY;
offsetYfrac = -offsetYfrac;
}
switch( orientation )
{
case ASCH_RECORD_ORIENTATION::RIGHTWARDS:
kicadX += p;
kicadXfrac += pfrac;
kicadX += offsetY;
kicadXfrac += offsetYfrac;
break;
case ASCH_RECORD_ORIENTATION::UPWARDS:
kicadY += p;
kicadYfrac += pfrac;
kicadY += offsetY;
kicadYfrac += offsetYfrac;
break;
case ASCH_RECORD_ORIENTATION::LEFTWARDS:
kicadX -= p;
kicadXfrac -= pfrac;
kicadX -= offsetY;
kicadXfrac -= offsetYfrac;
break;
case ASCH_RECORD_ORIENTATION::DOWNWARDS:
kicadY -= p;
kicadYfrac -= pfrac;
kicadY -= offsetY;
kicadYfrac -= offsetYfrac;
break;
default:
@ -226,6 +235,35 @@ ASCH_PIN::ASCH_PIN( const std::map<wxString, wxString>& aProps )
}
ASCH_FILL_INTERFACE::ASCH_FILL_INTERFACE( const std::map<wxString, wxString>& aProps )
{
AreaColor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR", 0 );
IsSolid = ALTIUM_PARSER::ReadBool( aProps, "ISSOLID", false );
IsTransparent = ALTIUM_PARSER::ReadBool( aProps, "TRANSPARENT", false );
}
ASCH_BORDER_INTERFACE::ASCH_BORDER_INTERFACE( const std::map<wxString, wxString>& aProps )
{
LineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
// Altium line width 0 means hairline. Since KiCad doesn't have a hairline, we
// represent it as a 1 mil line.
if( LineWidth == 0 )
LineWidth = 1;
Color = ALTIUM_PARSER::ReadInt( aProps, "COLOR", 0 );
}
ASCH_SHAPE_INTERFACE::ASCH_SHAPE_INTERFACE( const std::map<wxString, wxString>& aProps )
{
OwnerIndex = ReadOwnerIndex( aProps );
OwnerPartID = ReadOwnerPartId( aProps );
IndexInSheet = ALTIUM_PARSER::ReadInt( aProps, "INDEXINSHEET", 0 );
OwnerPartDisplayMode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
}
ASCH_LABEL::ASCH_LABEL( const std::map<wxString, wxString>& aProps )
{
wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::LABEL );
@ -271,10 +309,15 @@ ASCH_TEXT_FRAME::ASCH_TEXT_FRAME( const std::map<wxString, wxString>& aProps )
IsWordWrapped = ALTIUM_PARSER::ReadBool( aProps, "WORDWRAP", false );
ShowBorder = ALTIUM_PARSER::ReadBool( aProps, "SHOWBORDER", false );
TextMargin = ReadKiCadUnitFrac( aProps, "TEXTMARGIN" );
AreaColor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR", 0 );
BorderColor = ALTIUM_PARSER::ReadInt( aProps, "COLOR", 0 );
TextColor = ALTIUM_PARSER::ReadInt( aProps, "TEXTCOLOR", 0 );
IsSolid = ALTIUM_PARSER::ReadBool( aProps, "WORDWRAP", true );
BorderWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
isSolid = ALTIUM_PARSER::ReadBool( aProps, "ISSOLID", false );
IsWordWrapped = ALTIUM_PARSER::ReadBool( aProps, "WORDWRAP", true );
Alignment = ReadEnum<ASCH_TEXT_FRAME_ALIGNMENT>( aProps, "ALIGNMENT", 1, 3,
ASCH_TEXT_FRAME_ALIGNMENT::LEFT );
@ -290,14 +333,12 @@ ASCH_NOTE::ASCH_NOTE( const std::map<wxString, wxString>& aProperties ) :
}
ASCH_BEZIER::ASCH_BEZIER( const std::map<wxString, wxString>& aProps )
ASCH_BEZIER::ASCH_BEZIER( const std::map<wxString, wxString>& aProps ) :
ASCH_SHAPE_INTERFACE( aProps ),
ASCH_BORDER_INTERFACE( aProps )
{
wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BEZIER );
ownerindex = ReadOwnerIndex( aProps );
ownerpartid = ReadOwnerPartId( aProps );
ownerpartdisplaymode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
int locationCount = ALTIUM_PARSER::ReadInt( aProps, "LOCATIONCOUNT", 0 );
for( int i = 1; i <= locationCount; i++ )
@ -306,19 +347,15 @@ ASCH_BEZIER::ASCH_BEZIER( const std::map<wxString, wxString>& aProps )
points.emplace_back( ReadKiCadUnitFrac( aProps, "X" + si ),
-ReadKiCadUnitFrac( aProps, "Y" + si ) );
}
lineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
}
ASCH_POLYLINE::ASCH_POLYLINE( const std::map<wxString, wxString>& aProps )
ASCH_POLYLINE::ASCH_POLYLINE( const std::map<wxString, wxString>& aProps ) :
ASCH_SHAPE_INTERFACE( aProps ),
ASCH_BORDER_INTERFACE( aProps )
{
wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POLYLINE );
OwnerIndex = ReadOwnerIndex( aProps );
OwnerPartID = ReadOwnerPartId( aProps );
OwnerPartDisplayMode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
int locationCount = ALTIUM_PARSER::ReadInt( aProps, "LOCATIONCOUNT", 0 );
for( int i = 1; i <= locationCount; i++ )
@ -328,9 +365,6 @@ ASCH_POLYLINE::ASCH_POLYLINE( const std::map<wxString, wxString>& aProps )
-ReadKiCadUnitFrac( aProps, "Y" + si ) );
}
LineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
Color = ALTIUM_PARSER::ReadInt( aProps, "COLOR", 0 );
int linestyleVar = ALTIUM_PARSER::ReadInt( aProps, "LINESTYLEEXT", 0 );
// overwrite if present.
@ -341,14 +375,13 @@ ASCH_POLYLINE::ASCH_POLYLINE( const std::map<wxString, wxString>& aProps )
}
ASCH_POLYGON::ASCH_POLYGON( const std::map<wxString, wxString>& aProps )
ASCH_POLYGON::ASCH_POLYGON( const std::map<wxString, wxString>& aProps ) :
ASCH_SHAPE_INTERFACE( aProps ),
ASCH_FILL_INTERFACE( aProps ),
ASCH_BORDER_INTERFACE( aProps )
{
wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POLYGON );
OwnerIndex = ReadOwnerIndex( aProps );
OwnerPartID = ReadOwnerPartId( aProps );
OwnerPartDisplayMode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
int locationCount = ALTIUM_PARSER::ReadInt( aProps, "LOCATIONCOUNT", 0 );
for( int i = 1; i <= locationCount; i++ )
@ -357,23 +390,16 @@ ASCH_POLYGON::ASCH_POLYGON( const std::map<wxString, wxString>& aProps )
points.emplace_back( ReadKiCadUnitFrac( aProps, "X" + si ),
-ReadKiCadUnitFrac( aProps, "Y" + si ) );
}
LineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
IsSolid = ALTIUM_PARSER::ReadBool( aProps, "ISSOLID", false );
Color = ALTIUM_PARSER::ReadInt( aProps, "COLOR", 0 );
AreaColor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR", 0 );
}
ASCH_ROUND_RECTANGLE::ASCH_ROUND_RECTANGLE( const std::map<wxString, wxString>& aProps )
ASCH_ROUND_RECTANGLE::ASCH_ROUND_RECTANGLE( const std::map<wxString, wxString>& aProps ) :
ASCH_SHAPE_INTERFACE( aProps ),
ASCH_FILL_INTERFACE( aProps ),
ASCH_BORDER_INTERFACE( aProps )
{
wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::ROUND_RECTANGLE );
OwnerIndex = ReadOwnerIndex( aProps );
OwnerPartID = ReadOwnerPartId( aProps );
OwnerPartDisplayMode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
BottomLeft = VECTOR2I( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
-ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
TopRight = VECTOR2I( ReadKiCadUnitFrac( aProps, "CORNER.X" ),
@ -381,25 +407,16 @@ ASCH_ROUND_RECTANGLE::ASCH_ROUND_RECTANGLE( const std::map<wxString, wxString>&
CornerRadius = wxSize( ReadKiCadUnitFrac( aProps, "CORNERXRADIUS" ),
-ReadKiCadUnitFrac( aProps, "CORNERYRADIUS" ) );
LineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
IsSolid = ALTIUM_PARSER::ReadBool( aProps, "ISSOLID", false );
IsTransparent = ALTIUM_PARSER::ReadBool( aProps, "TRANSPARENT", false );
Color = ALTIUM_PARSER::ReadInt( aProps, "COLOR", 0 );
AreaColor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR", 0 );
}
ASCH_ARC::ASCH_ARC( const std::map<wxString, wxString>& aProps )
ASCH_ARC::ASCH_ARC( const std::map<wxString, wxString>& aProps ) :
ASCH_SHAPE_INTERFACE( aProps ),
ASCH_BORDER_INTERFACE( aProps )
{
m_IsElliptical = ReadRecord( aProps ) == ALTIUM_SCH_RECORD::ELLIPTICAL_ARC;
wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::ARC || m_IsElliptical );
ownerindex = ReadOwnerIndex( aProps );
ownerpartid = ReadOwnerPartId( aProps );
ownerpartdisplaymode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
m_Center = VECTOR2I( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
-ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
m_Radius = ReadKiCadUnitFrac( aProps, "RADIUS" );
@ -410,44 +427,36 @@ ASCH_ARC::ASCH_ARC( const std::map<wxString, wxString>& aProps )
m_StartAngle = ALTIUM_PARSER::ReadDouble( aProps, "STARTANGLE", 0 );
m_EndAngle = ALTIUM_PARSER::ReadDouble( aProps, "ENDANGLE", 0 );
m_LineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
}
ASCH_ELLIPSE::ASCH_ELLIPSE( const std::map<wxString, wxString>& aProps )
ASCH_ELLIPSE::ASCH_ELLIPSE( const std::map<wxString, wxString>& aProps ) :
ASCH_SHAPE_INTERFACE( aProps ),
ASCH_FILL_INTERFACE( aProps ),
ASCH_BORDER_INTERFACE( aProps )
{
wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::ELLIPSE );
OwnerIndex = ReadOwnerIndex( aProps );
OwnerPartID = ReadOwnerPartId( aProps );
Center = VECTOR2I( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
-ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
Radius = ReadKiCadUnitFrac( aProps, "RADIUS" );
SecondaryRadius = ReadKiCadUnitFrac( aProps, "SECONDARYRADIUS" );
AreaColor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR", 0 );
IsNotAccesible = ALTIUM_PARSER::ReadBool( aProps, "ISNOTACCESIBLE", false );
IsSolid = ALTIUM_PARSER::ReadBool( aProps, "ISSOLID", false );
}
ASCH_LINE::ASCH_LINE( const std::map<wxString, wxString>& aProps )
ASCH_LINE::ASCH_LINE( const std::map<wxString, wxString>& aProps ) :
ASCH_SHAPE_INTERFACE( aProps ),
ASCH_BORDER_INTERFACE( aProps )
{
wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::LINE );
ownerindex = ReadOwnerIndex( aProps );
ownerpartid = ReadOwnerPartId( aProps );
ownerpartdisplaymode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
point1 = VECTOR2I( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
-ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
point2 = VECTOR2I( ReadKiCadUnitFrac( aProps, "CORNER.X" ),
-ReadKiCadUnitFrac( aProps, "CORNER.Y" ) );
lineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
}
@ -541,25 +550,18 @@ ASCH_HARNESS_TYPE::ASCH_HARNESS_TYPE( const std::map<wxString, wxString>& aProps
}
ASCH_RECTANGLE::ASCH_RECTANGLE( const std::map<wxString, wxString>& aProps )
ASCH_RECTANGLE::ASCH_RECTANGLE( const std::map<wxString, wxString>& aProps ) :
ASCH_SHAPE_INTERFACE( aProps ),
ASCH_FILL_INTERFACE( aProps ),
ASCH_BORDER_INTERFACE( aProps )
{
wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::RECTANGLE );
OwnerIndex = ReadOwnerIndex( aProps );
OwnerPartID = ReadOwnerPartId( aProps );
OwnerPartDisplayMode = ALTIUM_PARSER::ReadInt( aProps, "OWNERPARTDISPLAYMODE", 0 );
BottomLeft = VECTOR2I( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
-ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
TopRight = VECTOR2I( ReadKiCadUnitFrac( aProps, "CORNER.X" ),
-ReadKiCadUnitFrac( aProps, "CORNER.Y" ) );
LineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
IsSolid = ALTIUM_PARSER::ReadBool( aProps, "ISSOLID", false );
IsTransparent = ALTIUM_PARSER::ReadBool( aProps, "TRANSPARENT", false );
Color = ALTIUM_PARSER::ReadInt( aProps, "COLOR", 0 );
AreaColor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR", 0 );
}
@ -724,14 +726,12 @@ ASCH_JUNCTION::ASCH_JUNCTION( const std::map<wxString, wxString>& aProps )
}
ASCH_IMAGE::ASCH_IMAGE( const std::map<wxString, wxString>& aProps )
ASCH_IMAGE::ASCH_IMAGE( const std::map<wxString, wxString>& aProps ) :
ASCH_SHAPE_INTERFACE( aProps ),
ASCH_BORDER_INTERFACE( aProps )
{
wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMAGE );
indexinsheet = ALTIUM_PARSER::ReadInt( aProps, "INDEXINSHEET", 0 );
ownerindex = ReadOwnerIndex( aProps );
ownerpartid = ReadOwnerPartId( aProps );
filename = ALTIUM_PARSER::ReadString( aProps, "FILENAME", "" );
location = VECTOR2I( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
@ -919,3 +919,12 @@ ASCH_PARAMETER::ASCH_PARAMETER( const std::map<wxString, wxString>& aProps )
isMirrored = ALTIUM_PARSER::ReadBool( aProps, "ISMIRRORED", false );
isShowName = ALTIUM_PARSER::ReadBool( aProps, "SHOWNAME", false );
}
ASCH_HYPERLINK::ASCH_HYPERLINK( const std::map<wxString, wxString>& aProps ) :
ASCH_LABEL( aProps )
{
wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::HYPERLINK );
url = ALTIUM_PARSER::ReadString( aProps, "URL", "" );
}

View File

@ -104,7 +104,7 @@ enum class ALTIUM_SCH_RECORD
HARNESS_TYPE = 217,
SIGNAL_HARNESS = 218,
BLANKET = 225,
RECORD_226 = 226,
HYPERLINK = 226,
};
@ -122,12 +122,26 @@ struct ASCH_SHAPE_INTERFACE
int OwnerIndex;
int OwnerPartID;
int OwnerPartDisplayMode;
int IndexInSheet;
int LineWidth;
bool IsSolid;
explicit ASCH_SHAPE_INTERFACE( const std::map<wxString, wxString>& aProps );
};
int Color;
struct ASCH_FILL_INTERFACE
{
int AreaColor;
bool IsSolid;
bool IsTransparent;
explicit ASCH_FILL_INTERFACE( const std::map<wxString, wxString>& aProps );
};
struct ASCH_BORDER_INTERFACE
{
int LineWidth;
int Color;
explicit ASCH_BORDER_INTERFACE( const std::map<wxString, wxString>& aProps );
};
@ -151,52 +165,125 @@ struct ASCH_SYMBOL
};
enum class ASCH_PIN_SYMBOL_OUTER
enum class ASCH_PIN_SYMBOL_EDGE
{
UNKNOWN = -1,
NO_SYMBOL = 0,
RIGHT_LEFT_SIGNAL_FLOW = 2,
ANALOG_SIGNAL_IN = 5,
NOT_LOGIC_CONNECTION = 6,
DIGITAL_SIGNAL_IN = 25,
LEFT_RIGHT_SIGNAL_FLOW = 33,
BIDI_SIGNAL_FLOW = 34
};
enum class ASCH_PIN_SYMBOL_INNER
{
UNKNOWN = -1,
NO_SYMBOL = 0,
POSPONED_OUTPUT = 8,
NEGATED = 1,
RIGHTLEFT = 2,
CLOCK = 3,
LOW_INPUT = 4,
ANALOG_IN = 5,
NOLOGICCONNECT = 6,
// 7 is missing
POSTPONE_OUTPUT = 8,
OPEN_COLLECTOR = 9,
HIZ = 10,
HIGH_CURRENT = 11,
PULSE = 12,
SCHMITT = 13,
// 14-16 missing
LOW_OUTPUT = 17,
// 18-21 missing
OPEN_COLLECTOR_PULL_UP = 22,
OPEN_EMITTER = 23,
OPEN_EMITTER_PULL_UP = 24,
DIGITAL_IN = 25,
// 26-29 missing
SHIFT_LEFT = 30,
OPEN_OUTPUT = 32
// 31 is missing
OPEN_OUTPUT = 32,
LEFTRIGHT = 33,
BIDI = 34
};
enum class ASCH_PIN_SYMBOL_OUTEREDGE
class ASCH_PIN_SYMBOL
{
UNKNOWN = -1,
NO_SYMBOL = 0,
NEGATED = 1,
LOW_INPUT = 4,
LOW_OUTPUT = 17
};
public:
enum PTYPE
{
UNKNOWN = -1,
NO_SYMBOL = 0,
NEGATED = 1,
RIGHTLEFT = 2,
CLOCK = 3,
LOW_INPUT = 4,
ANALOG_IN = 5,
NOLOGICCONNECT = 6,
// 7 is missing
POSTPONE_OUTPUT = 8,
OPEN_COLLECTOR = 9,
HIZ = 10,
HIGH_CURRENT = 11,
PULSE = 12,
SCHMITT = 13,
// 14-16 missing
LOW_OUTPUT = 17,
// 18-21 missing
OPEN_COLLECTOR_PULL_UP = 22,
OPEN_EMITTER = 23,
OPEN_EMITTER_PULL_UP = 24,
DIGITAL_IN = 25,
// 26-29 missing
SHIFT_LEFT = 30,
// 31 is missing
OPEN_OUTPUT = 32,
LEFTRIGHT = 33,
BIDI = 34
};
enum class ASCH_PIN_SYMBOL_INNEREDGE
{
UNKNOWN = -1,
NO_SYMBOL = 0,
CLOCK = 3,
static PTYPE FromInt( int aInt )
{
switch( aInt )
{
case 0:
return NO_SYMBOL;
case 1:
return NEGATED;
case 2:
return RIGHTLEFT;
case 3:
return CLOCK;
case 4:
return LOW_INPUT;
case 5:
return ANALOG_IN;
case 6:
return NOLOGICCONNECT;
case 8:
return POSTPONE_OUTPUT;
case 9:
return OPEN_COLLECTOR;
case 10:
return HIZ;
case 11:
return HIGH_CURRENT;
case 12:
return PULSE;
case 13:
return SCHMITT;
case 17:
return LOW_OUTPUT;
case 22:
return OPEN_COLLECTOR_PULL_UP;
case 23:
return OPEN_EMITTER;
case 24:
return OPEN_EMITTER_PULL_UP;
case 25:
return DIGITAL_IN;
case 30:
return SHIFT_LEFT;
case 32:
return OPEN_OUTPUT;
case 33:
return LEFTRIGHT;
case 34:
return BIDI;
default:
return UNKNOWN;
}
}
};
@ -225,11 +312,11 @@ struct ASCH_PIN
wxString text;
wxString designator;
ASCH_PIN_SYMBOL_OUTER symbolOuter;
ASCH_PIN_SYMBOL_INNER symbolInner;
ASCH_PIN_SYMBOL::PTYPE symbolOuter;
ASCH_PIN_SYMBOL::PTYPE symbolInner;
ASCH_PIN_SYMBOL_OUTEREDGE symbolOuterEdge;
ASCH_PIN_SYMBOL_INNEREDGE symbolInnerEdge;
ASCH_PIN_SYMBOL::PTYPE symbolOuterEdge;
ASCH_PIN_SYMBOL::PTYPE symbolInnerEdge;
ASCH_PIN_ELECTRICAL electrical;
ASCH_RECORD_ORIENTATION orientation;
@ -241,6 +328,9 @@ struct ASCH_PIN
bool showPinName;
bool showDesignator;
bool hidden;
bool isKiCadLibPin; // Tracking variable to handle LibEdit nuance
explicit ASCH_PIN( const std::map<wxString, wxString>& aProps );
};
@ -278,6 +368,7 @@ struct ASCH_LABEL
VECTOR2I location;
wxString text;
int textColor;
int fontId;
bool isMirrored;
@ -288,6 +379,13 @@ struct ASCH_LABEL
explicit ASCH_LABEL( const std::map<wxString, wxString>& aProps );
};
struct ASCH_HYPERLINK : ASCH_LABEL
{
wxString url;
explicit ASCH_HYPERLINK( const std::map<wxString, wxString>& aProps );
};
struct ASCH_TEXT_FRAME
{
@ -302,12 +400,14 @@ struct ASCH_TEXT_FRAME
bool IsWordWrapped; // to do when kicad supports this
bool ShowBorder;
bool IsSolid;
int FontID;
int TextMargin; // to do when kicad supports this
int AreaColor;
int TextColor;
int BorderColor;
int BorderWidth;
bool isSolid;
ASCH_TEXT_FRAME_ALIGNMENT Alignment;
@ -323,16 +423,10 @@ struct ASCH_NOTE : ASCH_TEXT_FRAME
};
struct ASCH_BEZIER
struct ASCH_BEZIER : ASCH_SHAPE_INTERFACE, ASCH_BORDER_INTERFACE
{
int ownerindex;
int ownerpartid;
int ownerpartdisplaymode;
std::vector<VECTOR2I> points;
int lineWidth;
explicit ASCH_BEZIER( const std::map<wxString, wxString>& aProps );
};
@ -355,24 +449,17 @@ enum class ASCH_SHEET_ENTRY_SIDE
};
struct ASCH_POLYLINE
struct ASCH_POLYLINE : ASCH_SHAPE_INTERFACE, ASCH_BORDER_INTERFACE
{
int OwnerIndex;
int OwnerPartID;
int OwnerPartDisplayMode;
std::vector<VECTOR2I> Points;
int LineWidth;
int Color;
ASCH_POLYLINE_LINESTYLE LineStyle;
explicit ASCH_POLYLINE( const std::map<wxString, wxString>& aProps );
};
struct ASCH_POLYGON : ASCH_SHAPE_INTERFACE
struct ASCH_POLYGON : ASCH_SHAPE_INTERFACE, ASCH_FILL_INTERFACE, ASCH_BORDER_INTERFACE
{
std::vector<VECTOR2I> points;
@ -380,7 +467,7 @@ struct ASCH_POLYGON : ASCH_SHAPE_INTERFACE
};
struct ASCH_ROUND_RECTANGLE : ASCH_SHAPE_INTERFACE
struct ASCH_ROUND_RECTANGLE : ASCH_SHAPE_INTERFACE, ASCH_FILL_INTERFACE, ASCH_BORDER_INTERFACE
{
VECTOR2I BottomLeft;
VECTOR2I TopRight;
@ -393,12 +480,8 @@ struct ASCH_ROUND_RECTANGLE : ASCH_SHAPE_INTERFACE
};
struct ASCH_ARC
struct ASCH_ARC : ASCH_SHAPE_INTERFACE, ASCH_BORDER_INTERFACE
{
int ownerindex;
int ownerpartid;
int ownerpartdisplaymode;
bool m_IsElliptical;
VECTOR2I m_Center;
int m_Radius;
@ -406,40 +489,27 @@ struct ASCH_ARC
double m_StartAngle;
double m_EndAngle;
int m_LineWidth;
explicit ASCH_ARC( const std::map<wxString, wxString>& aProps );
};
struct ASCH_ELLIPSE
struct ASCH_ELLIPSE : ASCH_SHAPE_INTERFACE, ASCH_FILL_INTERFACE, ASCH_BORDER_INTERFACE
{
int OwnerIndex;
int OwnerPartID;
VECTOR2I Center;
int Radius;
double SecondaryRadius;
int AreaColor;
bool IsSolid;
bool IsNotAccesible;
explicit ASCH_ELLIPSE( const std::map<wxString, wxString>& aProps );
};
struct ASCH_LINE
struct ASCH_LINE : ASCH_SHAPE_INTERFACE, ASCH_BORDER_INTERFACE
{
int ownerindex;
int ownerpartid;
int ownerpartdisplaymode;
VECTOR2I point1;
VECTOR2I point2;
int lineWidth;
explicit ASCH_LINE( const std::map<wxString, wxString>& aProps );
};
@ -526,7 +596,7 @@ struct ASCH_HARNESS_TYPE
};
struct ASCH_RECTANGLE : ASCH_SHAPE_INTERFACE
struct ASCH_RECTANGLE : ASCH_SHAPE_INTERFACE, ASCH_FILL_INTERFACE, ASCH_BORDER_INTERFACE
{
VECTOR2I BottomLeft;
VECTOR2I TopRight;
@ -703,12 +773,8 @@ struct ASCH_JUNCTION
};
struct ASCH_IMAGE
struct ASCH_IMAGE : ASCH_SHAPE_INTERFACE, ASCH_BORDER_INTERFACE
{
int indexinsheet;
int ownerindex;
int ownerpartid;
wxString filename;
VECTOR2I location;
VECTOR2I corner;

File diff suppressed because it is too large Load Diff

View File

@ -60,10 +60,10 @@ public:
return PLUGIN_FILE_DESC( _HKI( "Altium schematic files" ), { "SchDoc" } );
}
/*const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
{
return PLUGIN_FILE_DESC( _HKI( "Altium schematic library files" ), { "SchLib" } );
}*/
}
int GetModifyHash() const override;
@ -77,11 +77,17 @@ public:
//void Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway,
// const PROPERTIES* aProperties = NULL ) override;
//void EnumerateSymbolLib( wxArrayString& aAliasNameList, const wxString& aLibraryPath,
// const PROPERTIES* aProperties = NULL ) override;
//LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
// const PROPERTIES* aProperties = NULL ) override;
void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
const wxString& aLibraryPath,
const STRING_UTF8_MAP* aProperties = nullptr ) override;
void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
const wxString& aLibraryPath,
const STRING_UTF8_MAP* aProperties = nullptr ) override;
LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
const STRING_UTF8_MAP* aProperties = nullptr ) override;
//void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
// const PROPERTIES* aProperties = NULL ) override;
@ -98,7 +104,10 @@ public:
// bool DeleteSymbolLib( const wxString& aLibraryPath,
// const PROPERTIES* aProperties = NULL ) override;
//bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
bool IsSymbolLibWritable( const wxString& aLibraryPath ) override
{
return false;
}
//void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const override;
@ -117,25 +126,27 @@ private:
bool IsComponentPartVisible( int aOwnerindex, int aOwnerpartdisplaymode ) const;
const ASCH_STORAGE_FILE* GetFileFromStorage( const wxString& aFilename ) const;
void AddTextBox( const ASCH_TEXT_FRAME* aElem );
void AddLibTextBox( const ASCH_TEXT_FRAME* aElem, LIB_SYMBOL* aLibSymbol = nullptr );
void ParseComponent( int aIndex, const std::map<wxString, wxString>& aProperties );
void ParsePin( const std::map<wxString, wxString>& aProperties );
void ParseLabel( const std::map<wxString, wxString>& aProperties );
void ParseTextFrame( const std::map<wxString, wxString>& aProperties );
void ParsePin( const std::map<wxString, wxString>& aProperties, LIB_SYMBOL* aLibSymbol = nullptr );
void ParseLabel( const std::map<wxString, wxString>& aProperties, LIB_SYMBOL* aLibSymbol = nullptr );
void ParseTextFrame( const std::map<wxString, wxString>& aProperties, LIB_SYMBOL* aLibSymbol = nullptr );
void ParseNote( const std::map<wxString, wxString>& aProperties );
void ParseBezier( const std::map<wxString, wxString>& aProperties );
void ParsePolyline( const std::map<wxString, wxString>& aProperties );
void ParsePolygon( const std::map<wxString, wxString>& aProperties );
void ParseRoundRectangle( const std::map<wxString, wxString>& aProperties );
void ParseArc( const std::map<wxString, wxString>& aProperties );
void ParseEllipse( const std::map<wxString, wxString>& aProperties );
void ParseLine( const std::map<wxString, wxString>& aProperties );
void ParseBezier( const std::map<wxString, wxString>& aProperties, LIB_SYMBOL* aLibSymbol = nullptr );
void ParsePolyline( const std::map<wxString, wxString>& aProperties, LIB_SYMBOL* aLibSymbol = nullptr );
void ParsePolygon( const std::map<wxString, wxString>& aProperties, LIB_SYMBOL* aLibSymbol = nullptr );
void ParseRoundRectangle( const std::map<wxString, wxString>& aProperties, LIB_SYMBOL* aLibSymbol = nullptr );
void ParseArc( const std::map<wxString, wxString>& aProperties, LIB_SYMBOL* aLibSymbol = nullptr );
void ParseEllipse( const std::map<wxString, wxString>& aProperties, LIB_SYMBOL* aLibSymbol = nullptr );
void ParseLine( const std::map<wxString, wxString>& aProperties, LIB_SYMBOL* aLibSymbol = nullptr );
void ParseSignalHarness( const std::map<wxString, wxString>& aProperties );
void ParseHarnessConnector( int aIndex, const std::map<wxString, wxString>& aProperties );
void ParseHarnessEntry( const std::map<wxString, wxString>& aProperties );
void ParseHarnessType( const std::map<wxString, wxString>& aProperties );
void ParseHarnessPort( const ASCH_PORT& aElem );
void ParseRectangle( const std::map<wxString, wxString>& aProperties );
void ParseHyperlink( const std::map<wxString, wxString>& aProperties, LIB_SYMBOL* aLibSymbol = nullptr );
void ParseRectangle( const std::map<wxString, wxString>& aProperties, LIB_SYMBOL* aLibSymbol = nullptr );
void ParseSheetSymbol( int aIndex, const std::map<wxString, wxString>& aProperties );
void ParseSheetEntry( const std::map<wxString, wxString>& aProperties );
void ParsePowerPort( const std::map<wxString, wxString>& aProperties );
@ -149,12 +160,16 @@ private:
void ParseSheet( const std::map<wxString, wxString>& aProperties );
void ParseSheetName( const std::map<wxString, wxString>& aProperties );
void ParseFileName( const std::map<wxString, wxString>& aProperties );
void ParseDesignator( const std::map<wxString, wxString>& aProperties );
void ParseDesignator( const std::map<wxString, wxString>& aProperties, LIB_SYMBOL* aLibSymbol = nullptr );
void ParseBusEntry( const std::map<wxString, wxString>& aProperties );
void ParseParameter( const std::map<wxString, wxString>& aProperties );
void ParseParameter( const std::map<wxString, wxString>& aProperties, LIB_SYMBOL* aLibSymbol = nullptr );
void ParseImplementationList( int aIndex, const std::map<wxString, wxString>& aProperties );
void ParseImplementation( const std::map<wxString, wxString>& aProperties );
void ParseLibHeader( const ALTIUM_COMPOUND_FILE& aAltiumSchFile, wxArrayString& aLibNames );
std::map<wxString,LIB_SYMBOL*> ParseLibFile( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
LIB_SYMBOL* ParseLibComponent( const std::map<wxString, wxString>& aProperties );
private:
REPORTER* m_reporter; // current reporter for warnings/errors
@ -189,6 +204,13 @@ private:
// Add offset to all harness ownerIndex'es after parsing FileHeader.
int m_harnessOwnerIndexOffset;
int m_harnessEntryParent; // used to identify harness connector for harness entry element
// Symbol caching
void ensureLoadedLibrary( const wxString& aLibraryPath, const STRING_UTF8_MAP* aProperties );
long long getLibraryTimestamp( const wxString& aLibraryPath ) const;
std::map<wxString, long long> m_timestamps;
std::map<wxString, std::map<wxString, LIB_SYMBOL*>> m_libCache;
};
#endif // _SCH_ALTIUM_PLUGIN_H_