Altium: Refactor and add initial structure for schematic importer

altium: move pcbnew/altium2kicadpcb_plugin -> pcbnew/plugins/altium

See: https://gitlab.com/kicad/code/kicad/-/issues/4412
This commit is contained in:
Thomas Pointhuber 2020-08-23 19:01:08 +00:00 committed by Jon Evans
parent eb0d3d653f
commit a03fb7a9a8
39 changed files with 1285 additions and 107 deletions

View File

@ -14,6 +14,7 @@ Licensed under BOOSTv1:
Licensed under ISC:
- portions of code in include/geometry/polygon_triangulation.h
Licensed under MIT:
- compoundfilereader in thirdparty/compoundfilereader
- delaunator in thirdparty/delaunator
- tinyspline_lib in thirdparty/tinyspline_lib
- nlohmann/json in thirdparty/nlohmann_json

View File

@ -269,6 +269,10 @@ set( PLOTTERS_CONTROL_SRCS
plotters/common_plot_functions.cpp
)
set( PLUGINS_ALTIUM_SRCS
plugins/altium/altium_parser.cpp
)
set( COMMON_SRCS
${LIB_KICAD_SRCS}
${COMMON_ABOUT_DLG_SRCS}
@ -277,6 +281,7 @@ set( COMMON_SRCS
${COMMON_PAGE_LAYOUT_SRCS}
${COMMON_PREVIEW_ITEMS_SRCS}
${PLOTTERS_CONTROL_SRCS}
${PLUGINS_ALTIUM_SRCS}
advanced_config.cpp
array_axis.cpp
array_options.cpp
@ -437,6 +442,7 @@ target_include_directories( common PRIVATE
add_dependencies( common libcontext )
add_dependencies( common version_header )
add_dependencies( common compoundfilereader ) # used by altium_parser.cpp
target_link_libraries( common
kimath
@ -454,6 +460,9 @@ target_include_directories( common PUBLIC
$<TARGET_PROPERTY:nlohmann_json,INTERFACE_INCLUDE_DIRECTORIES>
)
target_include_directories( common PUBLIC
$<TARGET_PROPERTY:compoundfilereader,INTERFACE_INCLUDE_DIRECTORIES>
) # used by altium_parser.cpp
set( PCB_COMMON_SRCS
base_screen.cpp

View File

@ -113,6 +113,11 @@ static const wxChar DrawArcCenterStartEndMaxAngle[] = wxT( "DrawArcCenterStartEn
*/
static const wxChar StrokeTriangulation[] = wxT( "StrokeTriangulation" );
/**
* When true, enable Altium Schematic import (*.SchDoc)
*/
static const wxChar PluginAltiumSch[] = wxT( "PluginAltiumSch" );
} // namespace KEYS
@ -196,6 +201,7 @@ ADVANCED_CFG::ADVANCED_CFG()
m_drawArcAccuracy = 10.0;
m_drawArcCenterMaxAngle = 50.0;
m_DrawTriangulationOutlines = false;
m_PluginAltiumSch = false;
loadFromConfigFile();
}
@ -254,6 +260,9 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::StrokeTriangulation,
&m_DrawTriangulationOutlines, false ) );
configParams.push_back(
new PARAM_CFG_BOOL( true, AC_KEYS::PluginAltiumSch, &m_PluginAltiumSch, false ) );
wxConfigLoadSetups( &aCfg, configParams );
for( auto param : configParams )

View File

@ -68,8 +68,8 @@ ALTIUM_PARSER::ALTIUM_PARSER(
const CFB::CompoundFileReader& aReader, const CFB::COMPOUND_FILE_ENTRY* aEntry )
{
m_subrecord_end = nullptr;
m_size = static_cast<size_t>( aEntry->size );
m_error = false;
m_size = static_cast<size_t>( aEntry->size );
m_error = false;
m_content.reset( new char[m_size] );
m_pos = m_content.get();
@ -155,10 +155,10 @@ int32_t ALTIUM_PARSER::PropertiesReadKicadUnit( const std::map<wxString, wxStrin
size_t decimal_point = value.find( '.' );
size_t value_end = value.find_first_not_of( "+-0123456789." );
wxString before_decimal_str = value.Left( decimal_point );
int before_decimal = wxAtoi( before_decimal_str );
int after_decimal = 0;
size_t after_decimal_digits = 0;
wxString before_decimal_str = value.Left( decimal_point );
int before_decimal = wxAtoi( before_decimal_str );
int after_decimal = 0;
size_t after_decimal_digits = 0;
if( decimal_point != wxString::npos )
{
if( value_end != wxString::npos )

View File

@ -229,6 +229,12 @@ wxString KiCadSchematicFileWildcard()
}
wxString AltiumSchematicFileWildcard()
{
return _( "Altium schematic files" ) + AddFileExtListToFilter( { "SchDoc" } );
}
wxString EagleSchematicFileWildcard()
{
return _( "Eagle XML schematic files" ) + AddFileExtListToFilter( { "sch" } );

View File

@ -67,12 +67,11 @@ set_target_properties( cvpcb_kiface PROPERTIES
)
target_link_libraries( cvpcb_kiface
pcbcommon
pcad2kicadpcb
altium2kicadpcb
3d-viewer
gal
common
kimath
${PCBNEW_IO_LIBRARIES}
${wxWidgets_LIBRARIES}
${GDI_PLUS_LIBRARIES}
)

View File

@ -33,6 +33,11 @@ include_directories(
${INC_AFTER}
)
set( EESCHEMA_SCH_PLUGINS_ALTIUM
sch_plugins/altium/sch_altium_plugin.cpp
sch_plugins/altium/altium_parser_sch.cpp
)
set( EESCHEMA_DLGS
dialogs/dialog_annotate.cpp
dialogs/dialog_annotate_base.cpp
@ -143,6 +148,7 @@ set ( EESCHEMA_LIBEDIT_SRCS
)
set( EESCHEMA_SRCS
${EESCHEMA_SCH_PLUGINS_ALTIUM}
${EESCHEMA_DLGS}
${EESCHEMA_WIDGETS}
${EESCHEMA_LIBEDIT_SRCS}

View File

@ -24,45 +24,40 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <fctsys.h>
#include <sch_draw_panel.h>
#include <confirm.h>
#include <env_paths.h>
#include <gestfich.h>
#include <sch_edit_frame.h>
#include <pgm_base.h>
#include <kiface_i.h>
#include <richio.h>
#include <trace_helpers.h>
#include <tool/tool_manager.h>
#include <id.h>
#include <advanced_config.h>
#include <class_library.h>
#include <lib_edit_frame.h>
#include <sch_sheet.h>
#include <sch_sheet_path.h>
#include <sch_component.h>
#include <schematic.h>
#include <wildcards_and_files_ext.h>
#include <confirm.h>
#include <connection_graph.h>
#include <dialog_migrate_buses.h>
#include <dialog_symbol_remap.h>
#include <eeschema_settings.h>
#include <gestfich.h>
#include <id.h>
#include <kiface_i.h>
#include <kiplatform/app.h>
#include <pgm_base.h>
#include <profile.h>
#include <project/project_file.h>
#include <project_rescue.h>
#include <reporter.h>
#include <eeschema_config.h>
#include <eeschema_settings.h>
#include <sch_legacy_plugin.h>
#include <richio.h>
#include <sch_component.h>
#include <sch_eagle_plugin.h>
#include <symbol_lib_table.h>
#include <dialog_symbol_remap.h>
#include <dialog_migrate_buses.h>
#include <ws_data_model.h>
#include <connection_graph.h>
#include <tool/actions.h>
#include <tools/sch_editor_control.h>
#include <project/project_file.h>
#include <sch_edit_frame.h>
#include <sch_legacy_plugin.h>
#include <sch_sheet.h>
#include <sch_sheet_path.h>
#include <schematic.h>
#include <settings/common_settings.h>
#include <settings/settings_manager.h>
#include <netlist.h>
#include <symbol_lib_table.h>
#include <tool/actions.h>
#include <tool/tool_manager.h>
#include <tools/sch_editor_control.h>
#include <trace_helpers.h>
#include <widgets/infobar.h>
#include <kiplatform/app.h>
#include <wildcards_and_files_ext.h>
#include <ws_data_model.h>
bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName )
@ -596,8 +591,27 @@ void SCH_EDIT_FRAME::OnImportProject( wxCommandEvent& aEvent )
bool setProject = Prj().GetProjectFullName().IsEmpty();
wxString path = wxPathOnly( Prj().GetProjectFullName() );
wxFileDialog dlg( this, _( "Import Schematic" ), path, wxEmptyString,
EagleSchematicFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
// clang-format off
std::list<std::pair<const wxString, const SCH_IO_MGR::SCH_FILE_T>> loaders;
if( ADVANCED_CFG::GetCfg().m_PluginAltiumSch )
loaders.emplace_back( AltiumSchematicFileWildcard(), SCH_IO_MGR::SCH_ALTIUM ); // Import Altium schematic files
loaders.emplace_back( EagleSchematicFileWildcard(), SCH_IO_MGR::SCH_EAGLE ); // Import Eagle schematic files
// clang-format on
wxString fileFilters;
for( auto& loader : loaders )
{
if( !fileFilters.IsEmpty() )
fileFilters += wxChar( '|' );
fileFilters += wxGetTranslation( loader.first );
}
wxFileDialog dlg( this, _( "Import Schematic" ), path, wxEmptyString, fileFilters,
wxFD_OPEN | wxFD_FILE_MUST_EXIST ); // TODO
if( dlg.ShowModal() == wxID_CANCEL )
return;
@ -617,8 +631,26 @@ void SCH_EDIT_FRAME::OnImportProject( wxCommandEvent& aEvent )
Schematic().SetProject( &Prj() );
}
// For now there is only one import plugin
importFile( dlg.GetPath(), SCH_IO_MGR::SCH_EAGLE );
wxFileName fn = dlg.GetPath();
SCH_IO_MGR::SCH_FILE_T pluginType = SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN;
for( auto& loader : loaders )
{
if( fn.GetExt().CmpNoCase( SCH_IO_MGR::GetFileExtension( loader.second ) ) == 0 )
{
pluginType = loader.second;
break;
}
}
if( pluginType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
{
wxLogError( wxString::Format( "unexpected file extension: %s", fn.GetExt() ) );
return;
}
importFile( dlg.GetPath(), pluginType );
}
@ -817,6 +849,7 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType )
switch( (SCH_IO_MGR::SCH_FILE_T) aFileType )
{
case SCH_IO_MGR::SCH_ALTIUM:
case SCH_IO_MGR::SCH_EAGLE:
// We insist on caller sending us an absolute path, if it does not, we say it's a bug.
wxASSERT_MSG( wxFileName( aFileName ).IsAbsolute(),
@ -832,7 +865,8 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType )
try
{
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ) );
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi(
SCH_IO_MGR::FindPlugin( (SCH_IO_MGR::SCH_FILE_T) aFileType ) );
Schematic().SetRoot( pi->Load( aFileName, &Schematic() ) );
// Eagle sheets do not use a worksheet frame by default, so set it to an empty one

View File

@ -27,6 +27,7 @@
#include <lib_item.h>
#include <math/util.h> // for KiROUND
#include <trigo.h> // for GetLineLength
class LIB_CIRCLE : public LIB_ITEM

View File

@ -28,6 +28,7 @@
#include <sch_eagle_plugin.h>
#include <sch_sexpr_plugin.h>
#include <sch_plugins/altium/sch_altium_plugin.h>
#include <wildcards_and_files_ext.h>
#define FMT_UNIMPLEMENTED _( "Plugin \"%s\" does not implement the \"%s\" function." )
@ -58,6 +59,8 @@ SCH_PLUGIN* SCH_IO_MGR::FindPlugin( SCH_FILE_T aFileType )
return new SCH_LEGACY_PLUGIN();
case SCH_KICAD:
return new SCH_SEXPR_PLUGIN();
case SCH_ALTIUM:
return new SCH_ALTIUM_PLUGIN();
case SCH_EAGLE:
return new SCH_EAGLE_PLUGIN();
default:
@ -95,8 +98,11 @@ const wxString SCH_IO_MGR::ShowType( SCH_FILE_T aType )
case SCH_KICAD:
return wxString( wxT( "KiCad" ) );
case SCH_ALTIUM:
return wxString( wxT( "Altium" ) );
case SCH_EAGLE:
return wxString( wxT( "EAGLE" ) );
return wxString( wxT( "EAGLE" ) );
}
}
@ -111,6 +117,8 @@ SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::EnumFromStr( const wxString& aType )
return SCH_LEGACY;
else if( aType == wxT( "KiCad" ) )
return SCH_KICAD;
else if( aType == wxT( "Altium" ) )
return SCH_ALTIUM;
else if( aType == wxT( "EAGLE" ) )
return SCH_EAGLE;

View File

@ -55,6 +55,7 @@ public:
{
SCH_LEGACY, ///< Legacy Eeschema file formats prior to s-expression.
SCH_KICAD, ///< The s-expression version of the schematic file formats.
SCH_ALTIUM, ///< Altium file format
SCH_EAGLE, ///< Autodesk Eagle file format
// Add your schematic type here.

View File

@ -0,0 +1,197 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Thomas Pointhuber <thomas.pointhuber@gmx.at>
*
* 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
*/
#include <iostream>
#include <unordered_map>
#include <convert_to_biu.h>
#include <ki_exception.h>
#include "plugins/altium/altium_parser.h"
#include "sch_plugins/altium/altium_parser_sch.h"
ALTIUM_SCH_RECORD PropertiesReadRecord( const std::map<wxString, wxString>& aProperties )
{
int recordId = ALTIUM_PARSER::PropertiesReadInt( aProperties, "RECORD", 0 );
return static_cast<ALTIUM_SCH_RECORD>( recordId );
}
constexpr int Altium2KiCadUnit( const int val, const int frac )
{
return Mils2iu( val ) * 10 + Mils2iu( frac ) / 10000; // TODO: correct, rounding issues?
}
ASCH_COMPONENT::ASCH_COMPONENT( const std::map<wxString, wxString>& aProperties )
{
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::COMPONENT );
currentpartid =
ALTIUM_PARSER::PropertiesReadInt( aProperties, "CURRENTPARTID", ALTIUM_COMPONENT_NONE );
libreference = ALTIUM_PARSER::PropertiesReadString( aProperties, "LIBREFERENCE", "" );
orientation = ALTIUM_PARSER::PropertiesReadInt( aProperties, "ORIENTATION", 0 );
int x = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.X", 0 );
int xfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.X_FRAC", 0 );
int y = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.Y", 0 );
int yfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.Y_FRAC", 0 );
location = wxPoint( Altium2KiCadUnit( x, xfrac ), -Altium2KiCadUnit( y, yfrac ) );
}
ASCH_PIN::ASCH_PIN( const std::map<wxString, wxString>& aProperties )
{
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::PIN );
ownerindex =
ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE );
ownerpartid = ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", 0 );
name = ALTIUM_PARSER::PropertiesReadString( aProperties, "NAME", "" );
text = ALTIUM_PARSER::PropertiesReadString( aProperties, "TEXT", "" );
designator = ALTIUM_PARSER::PropertiesReadString( aProperties, "DESIGNATOR", "" );
int pinconglomerate = ALTIUM_PARSER::PropertiesReadInt( aProperties, "PINCONGLOMERATE", 0 );
orientation = pinconglomerate & 0x03;
int x = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.X", 0 );
int xfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.X_FRAC", 0 );
int y = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.Y", 0 );
int yfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.Y_FRAC", 0 );
location = wxPoint( Altium2KiCadUnit( x, xfrac ), -Altium2KiCadUnit( y, yfrac ) );
}
ASCH_RECTANGLE::ASCH_RECTANGLE( const std::map<wxString, wxString>& aProperties )
{
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::RECTANGLE );
ownerindex =
ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE );
ownerpartid = ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", 0 );
int x = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.X", 0 );
int xfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.X_FRAC", 0 );
int y = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.Y", 0 );
int yfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.Y_FRAC", 0 );
bottomLeft = wxPoint( Altium2KiCadUnit( x, xfrac ), -Altium2KiCadUnit( y, yfrac ) );
x = ALTIUM_PARSER::PropertiesReadInt( aProperties, "CORNER.X", 0 );
xfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "CORNER.X_FRAC", 0 );
y = ALTIUM_PARSER::PropertiesReadInt( aProperties, "CORNER.Y", 0 );
yfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "CORNER.Y_FRAC", 0 );
topRight = wxPoint( Altium2KiCadUnit( x, xfrac ), -Altium2KiCadUnit( y, yfrac ) );
lineWidth = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LINEWIDTH", 0 );
isSolid = ALTIUM_PARSER::PropertiesReadBool( aProperties, "ISSOLID", false );
isTransparent = ALTIUM_PARSER::PropertiesReadBool( aProperties, "TRANSPARENT", false );
}
ASCH_NET_LABEL::ASCH_NET_LABEL( const std::map<wxString, wxString>& aProperties )
{
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::NET_LABEL );
text = ALTIUM_PARSER::PropertiesReadString( aProperties, "TEXT", "" );
orientation = ALTIUM_PARSER::PropertiesReadInt( aProperties, "ORIENTATION", 0 );
int x = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.X", 0 );
int xfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.X_FRAC", 0 );
int y = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.Y", 0 );
int yfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.Y_FRAC", 0 );
location = wxPoint( Altium2KiCadUnit( x, xfrac ), -Altium2KiCadUnit( y, yfrac ) );
}
ASCH_BUS::ASCH_BUS( const std::map<wxString, wxString>& aProperties )
{
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::BUS );
indexinsheet = ALTIUM_PARSER::PropertiesReadInt( aProperties, "INDEXINSHEET", 0 );
linewidth = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LINEWIDTH", 0 );
int locationcount = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATIONCOUNT", 0 );
for( int i = 0; i < locationcount; i++ )
{
const wxString si = std::to_string( i + 1 );
int x = ALTIUM_PARSER::PropertiesReadInt( aProperties, "X" + si, 0 );
int xfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "X" + si + "_FRAC", 0 );
int y = ALTIUM_PARSER::PropertiesReadInt( aProperties, "Y" + si, 0 );
int yfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "Y" + si + "_FRAC", 0 );
points.emplace_back( Altium2KiCadUnit( x, xfrac ), -Altium2KiCadUnit( y, yfrac ) );
}
}
ASCH_WIRE::ASCH_WIRE( const std::map<wxString, wxString>& aProperties )
{
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::WIRE );
/*std::cout << "-----------------------------------" << std::endl;
// debug
for( auto& property : aProperties )
{
std::cout << " * '" << property.first << "' = '" << property.second << "'"
<< std::endl;
}*/
indexinsheet = ALTIUM_PARSER::PropertiesReadInt( aProperties, "INDEXINSHEET", 0 );
linewidth = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LINEWIDTH", 0 );
int locationcount = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATIONCOUNT", 0 );
for( int i = 0; i < locationcount; i++ )
{
const wxString si = std::to_string( i + 1 );
int x = ALTIUM_PARSER::PropertiesReadInt( aProperties, "X" + si, 0 );
int xfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "X" + si + "_FRAC", 0 );
int y = ALTIUM_PARSER::PropertiesReadInt( aProperties, "Y" + si, 0 );
int yfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "Y" + si + "_FRAC", 0 );
points.emplace_back( Altium2KiCadUnit( x, xfrac ), -Altium2KiCadUnit( y, yfrac ) );
}
}
ASCH_DESIGNATOR::ASCH_DESIGNATOR( const std::map<wxString, wxString>& aProperties )
{
wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::DESIGNATOR );
ownerindex =
ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE );
ownerpartid = ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", 0 );
name = ALTIUM_PARSER::PropertiesReadString( aProperties, "NAME", "" );
text = ALTIUM_PARSER::PropertiesReadString( aProperties, "TEXT", "" );
orientation = ALTIUM_PARSER::PropertiesReadInt( aProperties, "ORIENTATION", 0 );
int x = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.X", 0 );
int xfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.X_FRAC", 0 );
int y = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.Y", 0 );
int yfrac = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATION.Y_FRAC", 0 );
location = wxPoint( Altium2KiCadUnit( x, xfrac ), -Altium2KiCadUnit( y, yfrac ) );
}

View File

@ -0,0 +1,175 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Thomas Pointhuber <thomas.pointhuber@gmx.at>
*
* 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
*/
#ifndef ALTIUM_PARSER_SCH_H
#define ALTIUM_PARSER_SCH_H
#include <cstdint>
#include <cstring>
#include <map>
#include <vector>
// this constant specifies a item which is not inside an component
const int ALTIUM_COMPONENT_NONE = -1;
enum class ALTIUM_SCH_RECORD
{
HEADER = 0,
COMPONENT = 1,
PIN = 2,
IEEE_SYMBOL = 3,
LABEL = 4,
BEZIER = 5,
POLYLINE = 6,
POLYGON = 7,
ELLIPSE = 8,
PIECHART = 9,
ROUND_RECTANGLE = 10,
ELLIPTICAL_ARC = 11,
ARC = 12,
LINE = 13,
RECTANGLE = 14,
SHEET_SYMBOL = 15,
SHEET_ENTRY = 16,
POWER_PORT = 17,
PORT = 18,
NO_ERC = 22,
NET_LABEL = 25,
BUS = 26,
WIRE = 27,
TEXT_FRAME = 28,
JUNCTION = 29,
IMAGE = 30,
SHEET = 31,
SHEET_NAME = 32,
FILE_NAME = 33,
DESIGNATOR = 34,
BUS_ENTRY = 37,
TEMPLATE = 39,
PARAMETER = 41,
WARNING_SIGN = 43,
IMPLEMENTATION_LIST = 44,
IMPLEMENTATION = 45,
RECORD_46 = 46,
RECORD_47 = 47,
RECORD_48 = 48,
RECORD_215 = 215,
RECORD_216 = 216,
RECORD_217 = 217,
RECORD_218 = 218,
RECORD_226 = 226,
};
struct ASCH_COMPONENT
{
int currentpartid;
wxString libreference;
int orientation;
wxPoint location;
explicit ASCH_COMPONENT( const std::map<wxString, wxString>& aProperties );
};
struct ASCH_PIN
{
int ownerindex;
int ownerpartid;
wxString name;
wxString text;
wxString designator;
int orientation;
wxPoint location;
explicit ASCH_PIN( const std::map<wxString, wxString>& aProperties );
};
struct ASCH_RECTANGLE
{
int ownerindex;
int ownerpartid;
wxPoint bottomLeft;
wxPoint topRight;
int lineWidth;
bool isSolid;
bool isTransparent;
explicit ASCH_RECTANGLE( const std::map<wxString, wxString>& aProperties );
};
struct ASCH_NET_LABEL
{
wxString text;
int orientation;
wxPoint location;
explicit ASCH_NET_LABEL( const std::map<wxString, wxString>& aProperties );
};
struct ASCH_BUS
{
int indexinsheet;
int linewidth;
std::vector<wxPoint> points;
explicit ASCH_BUS( const std::map<wxString, wxString>& aProperties );
};
struct ASCH_WIRE
{
int indexinsheet;
int linewidth;
std::vector<wxPoint> points;
explicit ASCH_WIRE( const std::map<wxString, wxString>& aProperties );
};
struct ASCH_DESIGNATOR
{
int ownerindex;
int ownerpartid;
wxString name;
wxString text;
int orientation;
wxPoint location;
explicit ASCH_DESIGNATOR( const std::map<wxString, wxString>& aProperties );
};
#endif //ALTIUM_PARSER_SCH_H

View File

@ -0,0 +1,609 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Thomas Pointhuber <thomas.pointhuber@gmx.at>
*
* 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
*/
#include <sch_plugins/altium/sch_altium_plugin.h>
#include <schematic.h>
#include <lib_arc.h>
#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>
#include <sch_component.h>
#include <sch_junction.h>
#include <sch_line.h>
#include <sch_marker.h>
#include <sch_no_connect.h>
#include <sch_screen.h>
#include <sch_sheet.h>
#include <sch_text.h>
#include "altium_parser_sch.h"
#include <bits/unique_ptr.h>
#include <compoundfilereader.h>
#include <plugins/altium/altium_parser.h>
#include <sch_legacy_plugin.h>
#include <wildcards_and_files_ext.h>
#include <wx/textfile.h>
const wxPoint calculateComponentPoint( const wxPoint& aPosition, const SCH_COMPONENT* aComponent )
{
const wxPoint newPos = aPosition - aComponent->GetPosition();
return { newPos.x, -newPos.y };
}
SCH_ALTIUM_PLUGIN::SCH_ALTIUM_PLUGIN()
{
m_rootSheet = nullptr;
m_currentSheet = nullptr;
m_schematic = nullptr;
}
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";
m_libName = LIB_ID::FixIllegalChars( m_libName, LIB_ID::ID_SCH, true );
}
return m_libName;
}
wxFileName SCH_ALTIUM_PLUGIN::getLibFileName()
{
wxFileName fn( m_schematic->Prj().GetProjectPath(), getLibName(), KiCadSymbolLibFileExtension );
return fn;
}
SCH_SHEET* SCH_ALTIUM_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic,
SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties )
{
wxASSERT( !aFileName || aSchematic != NULL );
m_filename = aFileName;
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 );
m_rootSheet->SetFileName( aFileName );
}
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 ) );
m_properties = std::make_unique<PROPERTIES>();
( *m_properties )[SCH_LEGACY_PLUGIN::PropBuffering] = "";
/// @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.
libTable->InsertRow(
new SYMBOL_LIB_TABLE_ROW( getLibName(), libTableUri, wxString( "KiCad" ) ) );
// Save project symbol library table.
wxFileName fn( m_schematic->Prj().GetProjectPath(),
SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
// So output formatter goes out of scope and closes the file before reloading.
{
FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
libTable->Format( &formatter, 0 );
}
// Relaod the symbol library table.
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() );
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" );
if( fp == nullptr )
{
wxLogError( wxString::Format( _( "Cannot open file '%s'" ), aFileName ) );
return;
}
fseek( fp, 0, SEEK_END );
long len = ftell( fp );
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 );
if( static_cast<size_t>( len ) != bytesRead )
{
THROW_IO_ERROR( "Reading error" );
}
try
{
CFB::CompoundFileReader reader( buffer.get(), bytesRead );
Parse( reader );
}
catch( CFB::CFBException& exception )
{
THROW_IO_ERROR( exception.what() );
}
}
void SCH_ALTIUM_PLUGIN::Parse( const CFB::CompoundFileReader& aReader )
{
const CFB::COMPOUND_FILE_ENTRY* file = FindStream( aReader, "FileHeader" );
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" );
}
}
// index is required required to resolve OWNERINDEX
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:
break;
case ALTIUM_SCH_RECORD::BEZIER:
break;
case ALTIUM_SCH_RECORD::POLYLINE:
break;
case ALTIUM_SCH_RECORD::POLYGON:
break;
case ALTIUM_SCH_RECORD::ELLIPSE:
break;
case ALTIUM_SCH_RECORD::PIECHART:
break;
case ALTIUM_SCH_RECORD::ROUND_RECTANGLE:
break;
case ALTIUM_SCH_RECORD::ELLIPTICAL_ARC:
break;
case ALTIUM_SCH_RECORD::ARC:
break;
case ALTIUM_SCH_RECORD::LINE:
break;
case ALTIUM_SCH_RECORD::RECTANGLE:
ParseRectangle( properties );
break;
case ALTIUM_SCH_RECORD::SHEET_SYMBOL:
break;
case ALTIUM_SCH_RECORD::SHEET_ENTRY:
break;
case ALTIUM_SCH_RECORD::POWER_PORT:
break;
case ALTIUM_SCH_RECORD::PORT:
break;
case ALTIUM_SCH_RECORD::NO_ERC:
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:
break;
case ALTIUM_SCH_RECORD::IMAGE:
break;
case ALTIUM_SCH_RECORD::SHEET:
break;
case ALTIUM_SCH_RECORD::SHEET_NAME:
break;
case ALTIUM_SCH_RECORD::FILE_NAME:
break;
case ALTIUM_SCH_RECORD::DESIGNATOR:
ParseDesignator( properties );
break;
case ALTIUM_SCH_RECORD::BUS_ENTRY:
break;
case ALTIUM_SCH_RECORD::TEMPLATE:
break;
case ALTIUM_SCH_RECORD::PARAMETER:
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;
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:
wxLogError( wxString::Format( "Unknown Record id: %d", recordId ) );
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 );
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 ) ),
m_properties.get() );
component.second->SetLibSymbol( kpart->second );
}
m_components.clear();
m_symbols.clear();
// Otherwise we cannot save the imported sheet?
m_currentSheet->SetModified();
}
void SCH_ALTIUM_PLUGIN::ParseComponent( int index, const std::map<wxString, wxString>& aProperties )
{
ASCH_COMPONENT elem( aProperties );
LIB_ID libId( getLibName(), elem.libreference );
LIB_PART* kpart = new LIB_PART( wxEmptyString );
kpart->SetName( elem.libreference );
kpart->SetLibId( libId );
m_symbols.insert( { index, kpart } );
// each component has its own symbol for now
SCH_COMPONENT* component = new SCH_COMPONENT();
component->SetPosition( elem.location );
component->SetOrientation( elem.orientation );
component->SetLibId( libId );
//component->SetLibSymbol( kpart ); // this has to be done after parsing the LIB_PART!
m_currentSheet->GetScreen()->Append( component );
m_components.insert( { index, component } );
std::cout << "component index: " << index << " partid: " << elem.currentpartid << std::endl;
}
void SCH_ALTIUM_PLUGIN::ParsePin( const std::map<wxString, wxString>& aProperties )
{
ASCH_PIN elem( aProperties );
const auto& symbol = m_symbols.find( elem.ownerindex );
if( symbol == m_symbols.end() )
{
// TODO: e.g. can depend on Template (RECORD=39
wxLogWarning( wxString::Format(
"Pin tries to access symbol with ownerindex %d which does not exist",
elem.ownerindex ) );
return;
}
const auto& component = m_components.at( symbol->first );
LIB_PIN* pin = new LIB_PIN( symbol->second );
symbol->second->AddDrawItem( pin );
pin->SetPosition( calculateComponentPoint( elem.location, component ) );
pin->SetOrientation( elem.orientation );
pin->SetName( elem.name );
pin->SetNumber( elem.designator );
}
void SCH_ALTIUM_PLUGIN::ParseRectangle( const std::map<wxString, wxString>& aProperties )
{
ASCH_RECTANGLE elem( aProperties );
const auto& symbol = m_symbols.find( elem.ownerindex );
if( symbol == m_symbols.end() )
{
// TODO: e.g. can depend on Template (RECORD=39
wxLogWarning( wxString::Format(
"Pin tries to access symbol with ownerindex %d which does not exist",
elem.ownerindex ) );
return;
}
const auto& component = m_components.at( symbol->first );
LIB_RECTANGLE* rect = new LIB_RECTANGLE( symbol->second );
symbol->second->AddDrawItem( rect );
rect->SetPosition( calculateComponentPoint( elem.topRight, component ) );
rect->SetEnd( calculateComponentPoint( elem.bottomLeft, component ) );
rect->SetWidth( elem.lineWidth );
if( elem.isTransparent )
{
rect->SetFillMode( NO_FILL );
}
else if( elem.isSolid )
{
rect->SetFillMode( FILLED_SHAPE );
}
else
{
rect->SetFillMode( FILLED_WITH_BG_BODYCOLOR );
}
}
void SCH_ALTIUM_PLUGIN::ParseNetLabel( const std::map<wxString, wxString>& aProperties )
{
ASCH_NET_LABEL elem( aProperties );
SCH_LABEL* label = new SCH_LABEL( elem.location, elem.text );
switch( elem.orientation )
{
case 0:
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT );
break;
case 1:
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::UP );
break;
case 2:
label->SetLabelSpinStyle( LABEL_SPIN_STYLE::RIGHT );
break;
case 3:
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 );
for( int i = 0; i < (int) elem.points.size() - 1; i++ )
{
SCH_LINE* bus = new SCH_LINE( elem.points.at( i ), SCH_LAYER_ID::LAYER_BUS );
bus->SetEndPoint( elem.points.at( i + 1 ) );
bus->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( bus );
}
}
void SCH_ALTIUM_PLUGIN::ParseWire( const std::map<wxString, wxString>& aProperties )
{
ASCH_WIRE elem( aProperties );
for( int i = 0; i < (int) elem.points.size() - 1; i++ )
{
SCH_LINE* wire = new SCH_LINE( elem.points.at( i ), SCH_LAYER_ID::LAYER_WIRE );
wire->SetEndPoint( elem.points.at( i + 1 ) );
wire->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( wire );
}
}
void SCH_ALTIUM_PLUGIN::ParseDesignator( const std::map<wxString, wxString>& aProperties )
{
ASCH_DESIGNATOR elem( aProperties );
if( elem.ownerpartid == ALTIUM_COMPONENT_NONE )
{
return; // TODO: what to do?
}
const auto& component = m_components.find( elem.ownerpartid );
if( component == m_components.end() )
{
// TODO: e.g. can depend on Template (RECORD=39
THROW_IO_ERROR( wxString::Format(
"Designator tries to access component with ownerpartid %d which does not exist",
elem.ownerpartid ) );
}
LIB_PART* symbol = m_symbols.at( elem.ownerpartid );
// TODO: component->second->SetRef(m_sheet, elem.name);
LIB_TEXT* text = new LIB_TEXT( symbol );
symbol->AddDrawItem( text );
text->SetPosition( elem.location );
text->SetTextAngle( elem.orientation * 90. );
text->SetText( elem.name ); // TODO: use variable
}

View File

@ -0,0 +1,123 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Thomas Pointhuber <thomas.pointhuber@gmx.at>
*
* 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
*/
#ifndef _SCH_ALTIUM_PLUGIN_H_
#define _SCH_ALTIUM_PLUGIN_H_
#include <memory>
#include <sch_io_mgr.h>
#include <wx/filename.h>
class SCH_COMPONENT;
namespace CFB
{
class CompoundFileReader;
}
/**
* SCH_ALTIUM_PLUGIN
* is a #SCH_PLUGIN derivation for loading Altium .SchDoc schematic files.
*
* As with all SCH_PLUGINs there is no UI dependencies i.e. windowing calls allowed.
*/
class SCH_ALTIUM_PLUGIN : public SCH_PLUGIN
{
public:
SCH_ALTIUM_PLUGIN();
~SCH_ALTIUM_PLUGIN();
const wxString GetName() const override;
const wxString GetFileExtension() const override;
const wxString GetLibraryFileExtension() const override;
int GetModifyHash() const override;
SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL ) override;
bool CheckHeader( const wxString& aFileName ) override;
// unimplemented functions. Will trigger a not_implemented IO error.
//void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = NULL ) override;
//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_PART* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
// const PROPERTIES* aProperties = NULL ) override;
//void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
// const PROPERTIES* aProperties = NULL ) override;
//void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
// const PROPERTIES* aProperties = NULL ) override;
//void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
// const PROPERTIES* aProperties = NULL ) override;
//void CreateSymbolLib( const wxString& aLibraryPath,
// const PROPERTIES* aProperties = NULL ) override;
// bool DeleteSymbolLib( const wxString& aLibraryPath,
// const PROPERTIES* aProperties = NULL ) override;
//bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
//void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const override;
wxString getLibName();
wxFileName getLibFileName();
void ParseAltiumSch( const wxString& aFileName );
void Parse( const CFB::CompoundFileReader& aReader );
private:
void ParseComponent( int index, const std::map<wxString, wxString>& aProperties );
void ParsePin( const std::map<wxString, wxString>& aProperties );
void ParseRectangle( const std::map<wxString, wxString>& aProperties );
void ParseNetLabel( const std::map<wxString, wxString>& aProperties );
void ParseBus( const std::map<wxString, wxString>& aProperties );
void ParseWire( const std::map<wxString, wxString>& aProperties );
void ParseDesignator( const std::map<wxString, wxString>& aProperties );
private:
SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded..
SCH_SHEET* m_currentSheet; ///< The current sheet of the schematic being loaded..
wxFileName m_filename;
SCHEMATIC* m_schematic; ///< Passed to Load(), the schematic object being loaded
wxString m_libName; ///< Library name to save symbols
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi; ///< Plugin to create the KiCad symbol library.
std::unique_ptr<PROPERTIES> m_properties; ///< Library plugin properties.
std::map<int, SCH_COMPONENT*> m_components;
std::map<int, LIB_PART*> m_symbols; // for the start, every component has its unique symbol
};
#endif // _SCH_ALTIUM_PLUGIN_H_

View File

@ -113,6 +113,12 @@ public:
*/
bool m_DrawTriangulationOutlines;
/**
* When true, enable Altium Schematic import (*.SchDoc)
* the current implementation is highly incomplete
*/
bool m_PluginAltiumSch;
private:
ADVANCED_CFG();

View File

@ -192,6 +192,7 @@ extern wxString CsvFileWildcard();
extern wxString LegacyPcbFileWildcard();
extern wxString PcbFileWildcard();
extern wxString EaglePcbFileWildcard();
extern wxString AltiumSchematicFileWildcard();
extern wxString EagleSchematicFileWildcard();
extern wxString EagleFilesWildcard();
extern wxString PCadPcbFileWildcard();

View File

@ -574,7 +574,9 @@ endif()
add_subdirectory( pcad2kicadpcb_plugin )
add_subdirectory( altium2kicadpcb_plugin )
add_subdirectory( plugins/altium )
set( PCBNEW_IO_LIBRARIES pcad2kicadpcb altium2pcbnew CACHE INTERNAL "")
if( BUILD_GITHUB_PLUGIN )
add_subdirectory( github )
@ -669,8 +671,6 @@ set( PCBNEW_KIFACE_LIBRARIES
connectivity
pcbcommon
pnsrouter
pcad2kicadpcb
altium2kicadpcb
kiplatform
common
gal
@ -678,6 +678,7 @@ set( PCBNEW_KIFACE_LIBRARIES
tinyspline_lib
idf3
nanosvg
${PCBNEW_IO_LIBRARIES}
${wxWidgets_LIBRARIES}
${GITHUB_PLUGIN_LIBRARIES}
${GDI_PLUS_LIBRARIES}

View File

@ -25,9 +25,6 @@
#include <wx/filename.h>
#include <wx/uri.h>
#include <altium2kicadpcb_plugin/altium_circuit_maker_plugin.h>
#include <altium2kicadpcb_plugin/altium_circuit_studio_plugin.h>
#include <altium2kicadpcb_plugin/altium_designer_plugin.h>
#include <config.h>
#include <eagle_plugin.h>
#include <gpcb_plugin.h>
@ -35,6 +32,9 @@
#include <kicad_plugin.h>
#include <legacy_plugin.h>
#include <pcad2kicadpcb_plugin/pcad_plugin.h>
#include <plugins/altium/altium_circuit_maker_plugin.h>
#include <plugins/altium/altium_circuit_studio_plugin.h>
#include <plugins/altium/altium_designer_plugin.h>
#if defined(BUILD_GITHUB_PLUGIN)
#include <github/github_plugin.h>

View File

@ -6,17 +6,16 @@ set( ALTIUM2PCBNEW_SRCS
altium_circuit_studio_plugin.cpp
altium_designer_plugin.cpp
altium_pcb.cpp
altium_parser.cpp
altium_parser_pcb.cpp
)
add_library( altium2kicadpcb STATIC ${ALTIUM2PCBNEW_SRCS} )
add_library( altium2pcbnew STATIC ${ALTIUM2PCBNEW_SRCS} )
add_dependencies( altium2kicadpcb compoundfilereader )
add_dependencies( altium2pcbnew compoundfilereader )
target_link_libraries( altium2kicadpcb pcbcommon )
target_link_libraries( altium2pcbnew pcbcommon )
target_include_directories( altium2kicadpcb PUBLIC
target_include_directories( altium2pcbnew PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
$<TARGET_PROPERTY:compoundfilereader,INTERFACE_INCLUDE_DIRECTORIES>
)

View File

@ -27,8 +27,8 @@
#include <ki_exception.h>
#include <math/util.h>
#include "altium_parser.h"
#include "altium_parser_pcb.h"
#include "plugins/altium/altium_parser.h"
ALTIUM_LAYER altium_layer_from_name( const wxString& aName )
@ -129,7 +129,7 @@ ALTIUM_LAYER altium_layer_from_name( const wxString& aName )
if( it == hash_map.end() )
{
wxLogError( wxString::Format(
"Unknown mapping of the Altium layer '%s'. Please report as issue.", aName ) );
"Unknown mapping of the Altium layer '%s'. Please report as issue.", aName ) );
return ALTIUM_LAYER::UNKNOWN;
}
else
@ -435,7 +435,7 @@ APOLYGON6::APOLYGON6( ALTIUM_PARSER& aReader )
minprimlength = ALTIUM_PARSER::PropertiesReadKicadUnit( properties, "MINPRIMLENGTH", "0mil" );
useoctagons = ALTIUM_PARSER::PropertiesReadBool( properties, "USEOCTAGONS", false );
pourindex = ALTIUM_PARSER::PropertiesReadInt( properties, "POURINDEX", 0 );
pourindex = ALTIUM_PARSER::PropertiesReadInt( properties, "POURINDEX", 0 );
wxString hatchstyleraw = ALTIUM_PARSER::PropertiesReadString( properties, "HATCHSTYLE", "" );
@ -479,12 +479,12 @@ APOLYGON6::APOLYGON6( ALTIUM_PARSER& aReader )
ARULE6::ARULE6( ALTIUM_PARSER& aReader )
{
// Initalize all variables and make Coverity happy
clearanceGap = 0;
planeclearanceClearance = 0;
polygonconnectAirgapwidth = 0;
clearanceGap = 0;
planeclearanceClearance = 0;
polygonconnectAirgapwidth = 0;
polygonconnectReliefconductorwidth = 0;
polygonconnectReliefentries = 0;
polygonconnectStyle = ALTIUM_CONNECT_STYLE::UNKNOWN;
polygonconnectReliefentries = 0;
polygonconnectStyle = ALTIUM_CONNECT_STYLE::UNKNOWN;
aReader.Skip( 2 );
@ -532,7 +532,7 @@ ARULE6::ARULE6( ALTIUM_PARSER& aReader )
}
else if( rulekind == "PlaneClearance" )
{
kind = ALTIUM_RULE_KIND::PLANE_CLEARANCE;
kind = ALTIUM_RULE_KIND::PLANE_CLEARANCE;
planeclearanceClearance =
ALTIUM_PARSER::PropertiesReadKicadUnit( properties, "CLEARANCE", "10mil" );
}
@ -581,16 +581,16 @@ AARC6::AARC6( ALTIUM_PARSER& aReader )
layer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
uint8_t flags1 = aReader.Read<uint8_t>();
is_locked = ( flags1 & 0x04 ) == 0;
uint8_t flags1 = aReader.Read<uint8_t>();
is_locked = ( flags1 & 0x04 ) == 0;
is_polygonoutline = ( flags1 & 0x02 ) != 0;
uint8_t flags2 = aReader.Read<uint8_t>();
is_keepout = flags2 == 2;
net = aReader.Read<uint16_t>();
net = aReader.Read<uint16_t>();
subpolyindex = aReader.Read<uint16_t>();
component = aReader.Read<uint16_t>();
component = aReader.Read<uint16_t>();
aReader.Skip( 4 );
center = aReader.ReadWxPoint();
radius = aReader.ReadKicadUnit();
@ -688,8 +688,8 @@ APAD6::APAD6( ALTIUM_PARSER& aReader )
if( subrecord5 < 114 )
THROW_IO_ERROR( "Pads6 stream subrecord has length < 114, which is unexpected" );
layer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
tolayer = ALTIUM_LAYER::UNKNOWN;
layer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
tolayer = ALTIUM_LAYER::UNKNOWN;
fromlayer = ALTIUM_LAYER::UNKNOWN;
uint8_t flags1 = aReader.Read<uint8_t>();
@ -747,7 +747,7 @@ APAD6::APAD6( ALTIUM_PARSER& aReader )
// Known lengths: 596, 628, 651
// 596 is the number of bytes read in this code-block
if( subrecord6 >= 596 )
{ // TODO: detect type from something else than the size?
{ // TODO: detect type from something else than the size?
sizeAndShape = std::make_unique<APAD6_SIZE_AND_SHAPE>();
for( wxSize& size : sizeAndShape->inner_size )
@ -845,16 +845,16 @@ ATRACK6::ATRACK6( ALTIUM_PARSER& aReader )
layer = static_cast<ALTIUM_LAYER>( aReader.Read<uint8_t>() );
uint8_t flags1 = aReader.Read<uint8_t>();
is_locked = ( flags1 & 0x04 ) == 0;
uint8_t flags1 = aReader.Read<uint8_t>();
is_locked = ( flags1 & 0x04 ) == 0;
is_polygonoutline = ( flags1 & 0x02 ) != 0;
uint8_t flags2 = aReader.Read<uint8_t>();
is_keepout = flags2 == 2;
net = aReader.Read<uint16_t>();
net = aReader.Read<uint16_t>();
subpolyindex = aReader.Read<uint16_t>();
component = aReader.Read<uint16_t>();
component = aReader.Read<uint16_t>();
aReader.Skip( 4 );
start = aReader.ReadWxPoint();
end = aReader.ReadWxPoint();

View File

@ -538,8 +538,8 @@ struct ACOMPONENTBODY6
struct APAD6_SIZE_AND_SHAPE
{
ALTIUM_PAD_HOLE_SHAPE holeshape;
uint32_t slotsize;
double slotrotation;
uint32_t slotsize;
double slotrotation;
wxSize inner_size[29];
ALTIUM_PAD_SHAPE inner_shape[29];

View File

@ -22,8 +22,8 @@
*/
#include "altium_pcb.h"
#include "altium_parser.h"
#include "altium_parser_pcb.h"
#include "plugins/altium/altium_parser.h"
#include <class_board.h>
#include <class_dimension.h>
@ -499,9 +499,8 @@ int ALTIUM_PCB::GetNetCode( uint16_t aId ) const
}
else if( m_num_nets < aId )
{
THROW_IO_ERROR(
wxString::Format( "Netcode with id %d does not exist. Only %d nets are known",
aId, m_num_nets ) );
THROW_IO_ERROR( wxString::Format(
"Netcode with id %d does not exist. Only %d nets are known", aId, m_num_nets ) );
}
else
{
@ -653,8 +652,7 @@ void ALTIUM_PCB::ParseBoard6Data(
{
if( layer.nextId != 0 )
{
THROW_IO_ERROR(
"Board6 stream, unexpected id while parsing last stackup layer" );
THROW_IO_ERROR( "Board6 stream, unexpected id while parsing last stackup layer" );
}
// overwrite entry from internal -> bottom
m_layermap[alayer] = B_Cu;
@ -930,7 +928,7 @@ void ALTIUM_PCB::HelperParseDimensions6Linear( const ADIMENSION6& aElem )
* REFERENCE1POINT pointing the same direction as REFERENCE0POINT -> XY1. This should give us a valid
* measurement point where we can place the drawsegment.
*/
wxPoint direction = aElem.xy1 - referencePoint0;
wxPoint direction = aElem.xy1 - referencePoint0;
wxPoint directionNormalVector = wxPoint( -direction.y, direction.x );
SEG segm1( referencePoint0, referencePoint0 + directionNormalVector );
SEG segm2( referencePoint1, referencePoint1 + direction );
@ -1333,8 +1331,8 @@ void ALTIUM_PCB::ParsePolygons6Data(
}
}
if( elem.hatchstyle != ALTIUM_POLYGON_HATCHSTYLE::SOLID &&
elem.hatchstyle != ALTIUM_POLYGON_HATCHSTYLE::UNKNOWN )
if( elem.hatchstyle != ALTIUM_POLYGON_HATCHSTYLE::SOLID
&& elem.hatchstyle != ALTIUM_POLYGON_HATCHSTYLE::UNKNOWN )
{
zone->SetFillMode( ZONE_FILL_MODE::HATCH_PATTERN );
zone->SetHatchThickness( elem.trackwidth );
@ -1712,7 +1710,7 @@ void ALTIUM_PCB::ParsePads6Data(
module = m_components.at( elem.component );
}
D_PAD* pad = new D_PAD( module );
D_PAD* pad = new D_PAD( module );
module->Add( pad, ADD_MODE::APPEND );
pad->SetName( elem.name );
@ -1788,8 +1786,8 @@ void ALTIUM_PCB::ParsePads6Data(
default:
case ALTIUM_PAD_HOLE_SHAPE::UNKNOWN:
wxLogError( wxString::Format(
"Pad '%s' of Footprint %s uses a hole of unknown kind %d",
elem.name, module->GetReference(), elem.sizeAndShape->holeshape ) );
"Pad '%s' of Footprint %s uses a hole of unknown kind %d", elem.name,
module->GetReference(), elem.sizeAndShape->holeshape ) );
pad->SetDrillShape( PAD_DRILL_SHAPE_T::PAD_DRILL_SHAPE_CIRCLE );
pad->SetDrillSize( wxSize( elem.holesize, elem.holesize ) ); // Workaround
break;

View File

@ -53,7 +53,7 @@ add_executable( drc_proto
../../3d-viewer/3d_viewer/3d_viewer_settings.cpp
)
add_dependencies( drc_proto pnsrouter pcbcommon pcad2kicadpcb ${GITHUB_PLUGIN_LIBRARIES} )
add_dependencies( drc_proto pnsrouter pcbcommon ${PCBNEW_IO_LIBRARIES} ${GITHUB_PLUGIN_LIBRARIES} )
include_directories( BEFORE ${INC_BEFORE} )
include_directories(
@ -95,10 +95,9 @@ target_link_libraries( drc_proto
pcbcommon
bitmaps
gal
pcad2kicadpcb
altium2kicadpcb
common
pcbcommon
${PCBNEW_IO_LIBRARIES}
${GITHUB_PLUGIN_LIBRARIES}
common
pcbcommon
@ -115,4 +114,4 @@ make_lexer(
drc_rules_proto_lexer.h
drc_rules_proto_keywords.cpp
DRCRULEPROTO_T
)
)

View File

@ -31,7 +31,7 @@ if( BUILD_GITHUB_PLUGIN )
set( GITHUB_PLUGIN_LIBRARIES github_plugin )
endif()
add_dependencies( pnsrouter pcbcommon pcad2kicadpcb altium2kicadpcb ${GITHUB_PLUGIN_LIBRARIES} )
add_dependencies( pnsrouter pcbcommon ${PCBNEW_IO_LIBRARIES} ${GITHUB_PLUGIN_LIBRARIES} )
add_executable(test_gal_pixel_alignment WIN32
test_gal_pixel_alignment.cpp
@ -71,12 +71,11 @@ target_link_libraries( test_gal_pixel_alignment
kimath
pnsrouter
pcbcommon
pcad2kicadpcb
altium2kicadpcb
bitmaps
3d-viewer
gal
common
${PCBNEW_IO_LIBRARIES}
${GITHUB_PLUGIN_LIBRARIES}
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}

View File

@ -30,7 +30,7 @@ if( BUILD_GITHUB_PLUGIN )
set( GITHUB_PLUGIN_LIBRARIES github_plugin )
endif()
add_dependencies( pnsrouter pcbcommon pcad2kicadpcb ${GITHUB_PLUGIN_LIBRARIES} )
add_dependencies( pnsrouter pcbcommon ${PCBNEW_IO_LIBRARIES} ${GITHUB_PLUGIN_LIBRARIES} )
add_executable( libeval_compiler_test
libeval_compiler_test.cpp
@ -75,10 +75,9 @@ target_link_libraries( libeval_compiler_test
pcbcommon
bitmaps
gal
pcad2kicadpcb
altium2kicadpcb
common
pcbcommon
${PCBNEW_IO_LIBRARIES}
${GITHUB_PLUGIN_LIBRARIES}
common
pcbcommon

View File

@ -31,7 +31,7 @@ if( BUILD_GITHUB_PLUGIN )
set( GITHUB_PLUGIN_LIBRARIES github_plugin )
endif()
add_dependencies( pnsrouter pcbcommon pcad2kicadpcb ${GITHUB_PLUGIN_LIBRARIES} )
add_dependencies( pnsrouter pcbcommon ${PCBNEW_IO_LIBRARIES} ${GITHUB_PLUGIN_LIBRARIES} )
add_executable(test_window WIN32
test.cpp
@ -62,12 +62,12 @@ include_directories(
)
target_link_libraries( test_window
pcad2kicadpcb
pnsrouter
pcbcommon
3d-viewer
gal
common
${PCBNEW_IO_LIBRARIES}
${GITHUB_PLUGIN_LIBRARIES}
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}

View File

@ -73,8 +73,6 @@ target_link_libraries( qa_pcbnew
connectivity
pcbcommon
pnsrouter
pcad2kicadpcb
altium2kicadpcb
gal
common
gal
@ -84,6 +82,7 @@ target_link_libraries( qa_pcbnew
nanosvg
idf3
unit_test_utils
${PCBNEW_IO_LIBRARIES}
${wxWidgets_LIBRARIES}
${GITHUB_PLUGIN_LIBRARIES}
${GDI_PLUS_LIBRARIES}

View File

@ -53,8 +53,6 @@ target_link_libraries( qa_pcbnew_tools
connectivity
pcbcommon
pnsrouter
pcad2kicadpcb
altium2kicadpcb
gal
dxflib_qcad
tinyspline_lib
@ -63,6 +61,7 @@ target_link_libraries( qa_pcbnew_tools
common
qa_utils
unit_test_utils
${PCBNEW_IO_LIBRARIES}
${wxWidgets_LIBRARIES}
${GITHUB_PLUGIN_LIBRARIES}
${GDI_PLUS_LIBRARIES}

View File

@ -64,7 +64,6 @@ target_link_libraries( qa_pcbnew_utils PUBLIC
# connectivity
# pcbcommon
# pnsrouter
# pcad2kicadpcb
# common
# pcbcommon
# gal
@ -72,6 +71,7 @@ target_link_libraries( qa_pcbnew_utils PUBLIC
# lib_dxf
# idf3
# unit_test_utils
# ${PCBNEW_IO_LIBRARIES}
# ${wxWidgets_LIBRARIES}
# ${GITHUB_PLUGIN_LIBRARIES}
# ${GDI_PLUS_LIBRARIES}