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>
|
2024-01-26 13:59:07 +00:00
|
|
|
* Copyright (C) 2021-2024 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"
|
2023-12-19 17:39:26 +00:00
|
|
|
#include <io/io_utils.h>
|
2024-02-04 17:14:19 +00:00
|
|
|
#include <io/altium/altium_binary_parser.h>
|
|
|
|
#include <io/altium/altium_ascii_parser.h>
|
2023-12-19 17:39:26 +00:00
|
|
|
#include <io/altium/altium_parser_utils.h>
|
2023-12-24 00:31:24 +00:00
|
|
|
#include <sch_io/altium/sch_io_altium.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
#include <schematic.h>
|
2023-09-28 03:04:53 +00:00
|
|
|
#include <project_sch.h>
|
2024-02-21 13:45:27 +00:00
|
|
|
#include <project/project_file.h>
|
|
|
|
#include <project/net_settings.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
#include <lib_id.h>
|
2024-04-20 09:44:34 +00:00
|
|
|
#include <sch_pin.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#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>
|
2024-04-15 20:18:54 +00:00
|
|
|
#include <sch_shape.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <sch_no_connect.h>
|
|
|
|
#include <sch_screen.h>
|
2022-01-24 13:40:39 +00:00
|
|
|
#include <sch_label.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <sch_sheet.h>
|
2021-04-06 21:15:49 +00:00
|
|
|
#include <sch_sheet_pin.h>
|
2022-08-09 19:21:36 +00:00
|
|
|
#include <sch_textbox.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2020-10-10 16:41:19 +00:00
|
|
|
#include <bezier_curves.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <compoundfilereader.h>
|
2023-09-05 21:01:27 +00:00
|
|
|
#include <geometry/ellipse.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.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>
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2021-04-10 19:45:36 +00:00
|
|
|
#include <wx/zstream.h>
|
|
|
|
#include <wx/wfstream.h>
|
2024-01-31 05:22:20 +00:00
|
|
|
#include <magic_enum.hpp>
|
2024-02-04 17:14:19 +00:00
|
|
|
#include "sch_io_altium.h"
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2022-09-03 21:15:54 +00:00
|
|
|
// Harness port object itself does not contain color information about itself
|
|
|
|
// It seems altium is drawing harness ports using these colors
|
2022-10-31 14:03:35 +00:00
|
|
|
#define HARNESS_PORT_COLOR_DEFAULT_BACKGROUND COLOR4D( 0.92941176470588238, \
|
|
|
|
0.94901960784313721, \
|
|
|
|
0.98431372549019602, 1.0 )
|
|
|
|
|
|
|
|
#define HARNESS_PORT_COLOR_DEFAULT_OUTLINE COLOR4D( 0.56078431372549020, \
|
|
|
|
0.61960784313725492, \
|
|
|
|
0.78823529411764703, 1.0 )
|
|
|
|
|
2022-09-03 21:15:54 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
static const VECTOR2I GetRelativePosition( const VECTOR2I& aPosition, const SCH_SYMBOL* aSymbol )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
TRANSFORM t = aSymbol->GetTransform().InverseTransform();
|
|
|
|
return t.TransformCoordinate( aPosition - aSymbol->GetPosition() );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 14:51:19 +00:00
|
|
|
|
2021-12-27 15:50:30 +00:00
|
|
|
static COLOR4D GetColorFromInt( int color )
|
2020-10-27 14:51:19 +00:00
|
|
|
{
|
|
|
|
int red = color & 0x0000FF;
|
|
|
|
int green = ( color & 0x00FF00 ) >> 8;
|
|
|
|
int blue = ( color & 0xFF0000 ) >> 16;
|
|
|
|
|
|
|
|
return COLOR4D().FromCSSRGBA( red, green, blue, 1.0 );
|
|
|
|
}
|
|
|
|
|
2021-12-27 15:50:30 +00:00
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
static LINE_STYLE GetPlotDashType( const ASCH_POLYLINE_LINESTYLE linestyle )
|
2021-12-27 15:50:30 +00:00
|
|
|
{
|
|
|
|
switch( linestyle )
|
|
|
|
{
|
2023-11-25 13:05:45 +00:00
|
|
|
case ASCH_POLYLINE_LINESTYLE::SOLID: return LINE_STYLE::SOLID;
|
|
|
|
case ASCH_POLYLINE_LINESTYLE::DASHED: return LINE_STYLE::DASH;
|
|
|
|
case ASCH_POLYLINE_LINESTYLE::DOTTED: return LINE_STYLE::DOT;
|
|
|
|
case ASCH_POLYLINE_LINESTYLE::DASH_DOTTED: return LINE_STYLE::DASHDOT;
|
|
|
|
default: return LINE_STYLE::DEFAULT;
|
2021-12-27 15:50:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
static void SetSchShapeLine( const ASCH_BORDER_INTERFACE& elem, SCH_SHAPE* shape )
|
2021-12-27 15:50:30 +00:00
|
|
|
{
|
2023-11-25 13:05:45 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID,
|
2022-10-31 14:03:35 +00:00
|
|
|
GetColorFromInt( elem.Color ) ) );
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SetSchShapeFillAndColor( const ASCH_FILL_INTERFACE& elem, SCH_SHAPE* shape )
|
|
|
|
{
|
2021-12-27 15:50:30 +00:00
|
|
|
|
2022-09-03 22:38:41 +00:00
|
|
|
if( !elem.IsSolid )
|
2021-12-27 15:50:30 +00:00
|
|
|
{
|
|
|
|
shape->SetFillMode( FILL_T::NO_FILL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shape->SetFillMode( FILL_T::FILLED_WITH_COLOR );
|
2022-09-03 22:38:41 +00:00
|
|
|
shape->SetFillColor( GetColorFromInt( elem.AreaColor ) );
|
2021-12-27 15:50:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
static void SetLibShapeLine( const ASCH_BORDER_INTERFACE& elem, SCH_SHAPE* shape,
|
2024-02-21 13:05:18 +00:00
|
|
|
ALTIUM_SCH_RECORD aType )
|
2021-12-27 15:50:30 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
COLOR4D color = GetColorFromInt( elem.Color );
|
|
|
|
COLOR4D default_color;
|
2024-02-21 13:05:18 +00:00
|
|
|
COLOR4D alt_default_color = COLOR4D( PUREBLUE ); // PUREBLUE is used for many objects, so if
|
|
|
|
// it is used, we will assume that it should
|
|
|
|
// blend with the others
|
2023-08-28 21:50:56 +00:00
|
|
|
STROKE_PARAMS stroke;
|
2021-12-27 15:50:30 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
switch( aType )
|
2021-12-27 15:50:30 +00:00
|
|
|
{
|
2024-02-21 13:05:18 +00:00
|
|
|
case ALTIUM_SCH_RECORD::ARC: default_color = COLOR4D( PUREBLUE ); break;
|
|
|
|
case ALTIUM_SCH_RECORD::BEZIER: default_color = COLOR4D( PURERED ); break;
|
|
|
|
case ALTIUM_SCH_RECORD::ELLIPSE: default_color = COLOR4D( PUREBLUE ); break;
|
|
|
|
case ALTIUM_SCH_RECORD::ELLIPTICAL_ARC: default_color = COLOR4D( PUREBLUE ); break;
|
|
|
|
case ALTIUM_SCH_RECORD::LINE: default_color = COLOR4D( PUREBLUE ); break;
|
|
|
|
case ALTIUM_SCH_RECORD::POLYGON: default_color = COLOR4D( PUREBLUE ); break;
|
|
|
|
case ALTIUM_SCH_RECORD::POLYLINE: default_color = COLOR4D( BLACK ); break;
|
|
|
|
case ALTIUM_SCH_RECORD::RECTANGLE: default_color = COLOR4D( 0.5, 0, 0, 1.0 ); break;
|
|
|
|
case ALTIUM_SCH_RECORD::ROUND_RECTANGLE: default_color = COLOR4D( PUREBLUE ); break;
|
|
|
|
default: default_color = COLOR4D( PUREBLUE ); break;
|
2021-12-27 15:50:30 +00:00
|
|
|
}
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
if( color == default_color || color == alt_default_color )
|
2023-08-28 21:50:56 +00:00
|
|
|
color = COLOR4D::UNSPECIFIED;
|
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID, color ) );
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
static void SetLibShapeFillAndColor( const ASCH_FILL_INTERFACE& elem, SCH_SHAPE* shape,
|
2024-01-26 13:59:07 +00:00
|
|
|
ALTIUM_SCH_RECORD aType, int aStrokeColor )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
|
|
|
COLOR4D bgcolor = GetColorFromInt( elem.AreaColor );
|
|
|
|
COLOR4D default_bgcolor;
|
|
|
|
|
|
|
|
switch (aType)
|
2021-12-27 15:50:30 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
case ALTIUM_SCH_RECORD::RECTANGLE:
|
|
|
|
default_bgcolor = GetColorFromInt( 11599871 ); // Light Yellow
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default_bgcolor = GetColorFromInt( 12632256 ); // Grey
|
|
|
|
break;
|
2021-12-27 15:50:30 +00:00
|
|
|
}
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
if( elem.IsTransparent )
|
|
|
|
bgcolor = bgcolor.WithAlpha( 0.5 );
|
|
|
|
|
|
|
|
if( !elem.IsSolid )
|
2024-02-21 13:05:18 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
shape->SetFillMode( FILL_T::NO_FILL );
|
2024-02-21 13:05:18 +00:00
|
|
|
}
|
2023-08-28 21:50:56 +00:00
|
|
|
else if( elem.AreaColor == aStrokeColor )
|
2023-09-05 21:01:27 +00:00
|
|
|
{
|
|
|
|
bgcolor = shape->GetStroke().GetColor();
|
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
shape->SetFillMode( FILL_T::FILLED_SHAPE );
|
2023-09-05 21:01:27 +00:00
|
|
|
}
|
2023-09-09 16:59:57 +00:00
|
|
|
else if( bgcolor.WithAlpha( 1.0 ) == default_bgcolor )
|
2024-02-21 13:05:18 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
shape->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
|
2024-02-21 13:05:18 +00:00
|
|
|
}
|
2021-12-27 15:50:30 +00:00
|
|
|
else
|
2024-02-21 13:05:18 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
shape->SetFillMode( FILL_T::FILLED_WITH_COLOR );
|
2024-02-21 13:05:18 +00:00
|
|
|
}
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
shape->SetFillColor( bgcolor );
|
|
|
|
|
2024-01-26 13:59:07 +00:00
|
|
|
if( elem.AreaColor == aStrokeColor
|
2024-02-21 13:05:18 +00:00
|
|
|
&& shape->GetStroke().GetWidth() == schIUScale.MilsToIU( 1 ) )
|
2021-12-27 15:50:30 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
STROKE_PARAMS stroke = shape->GetStroke();
|
|
|
|
stroke.SetWidth( -1 );
|
|
|
|
shape->SetStroke( stroke );
|
2021-12-27 15:50:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_IO_ALTIUM::SCH_IO_ALTIUM() :
|
|
|
|
SCH_IO( wxS( "Altium" ) )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2023-12-19 14:32:31 +00:00
|
|
|
m_isIntLib = false;
|
2020-08-23 19:01:08 +00:00
|
|
|
m_rootSheet = nullptr;
|
|
|
|
m_schematic = nullptr;
|
2022-08-16 16:54:20 +00:00
|
|
|
m_harnessOwnerIndexOffset = 0;
|
|
|
|
m_harnessEntryParent = 0;
|
2021-03-31 21:33:30 +00:00
|
|
|
|
|
|
|
m_reporter = &WXLOG_REPORTER::GetInstance();
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
SCH_IO_ALTIUM::~SCH_IO_ALTIUM()
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
for( auto& [libName, lib] : m_libCache )
|
|
|
|
{
|
|
|
|
for( auto& [name, symbol] : lib )
|
|
|
|
delete symbol;
|
|
|
|
}
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
int SCH_IO_ALTIUM::GetModifyHash() const
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
bool SCH_IO_ALTIUM::isBinaryFile( const wxString& aFileName )
|
2023-10-01 11:58:38 +00:00
|
|
|
{
|
|
|
|
// Compound File Binary Format header
|
2023-12-19 17:39:26 +00:00
|
|
|
return IO_UTILS::fileStartsWithBinaryHeader( aFileName, IO_UTILS::COMPOUND_FILE_HEADER );
|
2023-10-01 11:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
bool SCH_IO_ALTIUM::isASCIIFile( const wxString& aFileName )
|
|
|
|
{
|
|
|
|
// ASCII file format
|
|
|
|
return IO_UTILS::fileStartsWithPrefix( aFileName, wxS( "|HEADER=" ), false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_IO_ALTIUM::checkFileHeader( const wxString& aFileName )
|
|
|
|
{
|
|
|
|
return isBinaryFile( aFileName ) || isASCIIFile( aFileName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
bool SCH_IO_ALTIUM::CanReadSchematicFile( const wxString& aFileName ) const
|
2023-10-01 11:58:38 +00:00
|
|
|
{
|
2023-12-19 17:39:26 +00:00
|
|
|
if( !SCH_IO::CanReadSchematicFile( aFileName ) )
|
2023-10-01 11:58:38 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return checkFileHeader( aFileName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
bool SCH_IO_ALTIUM::CanReadLibrary( const wxString& aFileName ) const
|
2023-10-01 11:58:38 +00:00
|
|
|
{
|
2023-12-19 17:39:26 +00:00
|
|
|
if( !SCH_IO::CanReadLibrary( aFileName ) )
|
2023-10-01 11:58:38 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return checkFileHeader( aFileName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
wxString SCH_IO_ALTIUM::getLibName()
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
|
|
|
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";
|
2023-09-14 15:35:19 +00:00
|
|
|
m_libName = LIB_ID::FixIllegalChars( m_libName, true ).wx_str();
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_libName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
wxFileName SCH_IO_ALTIUM::getLibFileName()
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2023-12-28 02:10:01 +00:00
|
|
|
wxFileName fn( m_schematic->Prj().GetProjectPath(), getLibName(),
|
|
|
|
FILEEXT::KiCadSymbolLibFileExtension );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
SCH_SHEET* SCH_IO_ALTIUM::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
2024-02-21 13:05:18 +00:00
|
|
|
SCH_SHEET* aAppendToMe,
|
2024-01-26 13:59:07 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2022-10-31 14:03:35 +00:00
|
|
|
wxCHECK( !aFileName.IsEmpty() && aSchematic, nullptr );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2020-11-05 23:24:29 +00:00
|
|
|
wxFileName fileName( aFileName );
|
2023-12-28 02:10:01 +00:00
|
|
|
fileName.SetExt( FILEEXT::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() );
|
2021-07-07 17:30:59 +00:00
|
|
|
|
2021-12-09 00:14:04 +00:00
|
|
|
aSchematic->SetRoot( m_rootSheet );
|
|
|
|
|
2021-07-07 17:30:59 +00:00
|
|
|
SCH_SHEET_PATH sheetpath;
|
|
|
|
sheetpath.push_back( m_rootSheet );
|
|
|
|
|
2022-11-22 19:35:27 +00:00
|
|
|
// We'll update later if we find a pageNumber record for it.
|
|
|
|
sheetpath.SetPageNumber( "#" );
|
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 );
|
2022-10-31 14:03:35 +00:00
|
|
|
const_cast<KIID&>( m_rootSheet->m_Uuid ) = screen->GetUuid();
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
2023-09-28 03:04:53 +00:00
|
|
|
SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &m_schematic->Prj() );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2023-12-27 20:39:29 +00:00
|
|
|
m_pi.reset( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
/// @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.
|
2023-12-27 00:25:41 +00:00
|
|
|
m_pi->CreateLibrary( getLibFileName().GetFullPath() );
|
2020-08-23 19:01:08 +00:00
|
|
|
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.
|
2021-07-16 20:13:26 +00:00
|
|
|
m_schematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr );
|
2023-09-28 03:04:53 +00:00
|
|
|
PROJECT_SCH::SchSymbolLibTable( &m_schematic->Prj() );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
m_sheetPath.push_back( m_rootSheet );
|
|
|
|
|
|
|
|
SCH_SCREEN* rootScreen = m_rootSheet->GetScreen();
|
|
|
|
wxCHECK( rootScreen, nullptr );
|
|
|
|
|
|
|
|
SCH_SHEET_INSTANCE sheetInstance;
|
|
|
|
|
|
|
|
sheetInstance.m_Path = m_sheetPath.Path();
|
|
|
|
sheetInstance.m_PageNumber = wxT( "#" );
|
|
|
|
|
|
|
|
rootScreen->m_sheetInstances.emplace_back( sheetInstance );
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
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.
|
2021-07-07 19:04:10 +00:00
|
|
|
allSheets.ClearEditFlags();
|
2021-03-16 19:51:31 +00:00
|
|
|
|
2024-02-21 13:45:27 +00:00
|
|
|
// Set up the default netclass wire & bus width based on imported wires & buses.
|
|
|
|
//
|
|
|
|
|
|
|
|
int minWireWidth = std::numeric_limits<int>::max();
|
|
|
|
int minBusWidth = std::numeric_limits<int>::max();
|
|
|
|
|
|
|
|
for( SCH_SCREEN* screen = allSheets.GetFirst(); screen != nullptr; screen = allSheets.GetNext() )
|
|
|
|
{
|
|
|
|
std::vector<SCH_MARKER*> markers;
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : screen->Items().OfType( SCH_LINE_T ) )
|
|
|
|
{
|
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( item );
|
|
|
|
|
|
|
|
if( line->IsWire() && line->GetLineWidth() > 0 )
|
|
|
|
minWireWidth = std::min( minWireWidth, line->GetLineWidth() );
|
|
|
|
|
|
|
|
if( line->IsBus() && line->GetLineWidth() > 0 )
|
|
|
|
minBusWidth = std::min( minBusWidth, line->GetLineWidth() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<NET_SETTINGS>& netSettings = m_schematic->Prj().GetProjectFile().NetSettings();
|
|
|
|
|
|
|
|
if( minWireWidth < std::numeric_limits<int>::max() )
|
|
|
|
netSettings->m_DefaultNetClass->SetWireWidth( minWireWidth );
|
|
|
|
|
|
|
|
if( minBusWidth < std::numeric_limits<int>::max() )
|
|
|
|
netSettings->m_DefaultNetClass->SetBusWidth( minBusWidth );
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
return m_rootSheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
SCH_SCREEN* SCH_IO_ALTIUM::getCurrentScreen()
|
2022-10-31 14:03:35 +00:00
|
|
|
{
|
|
|
|
return m_sheetPath.LastScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
SCH_SHEET* SCH_IO_ALTIUM::getCurrentSheet()
|
2022-10-31 14:03:35 +00:00
|
|
|
{
|
|
|
|
return m_sheetPath.Last();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseAltiumSch( const wxString& aFileName )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2022-10-31 14:03:35 +00:00
|
|
|
// Load path may be different from the project path.
|
|
|
|
wxFileName parentFileName = aFileName;
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
if( isBinaryFile( aFileName ) )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_COMPOUND_FILE altiumSchFile( aFileName );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
ParseStorage( altiumSchFile ); // we need this before parsing the FileHeader
|
|
|
|
ParseFileHeader( altiumSchFile );
|
|
|
|
|
|
|
|
// Parse "Additional" because sheet is set up during "FileHeader" parsing.
|
|
|
|
ParseAdditional( altiumSchFile );
|
|
|
|
}
|
|
|
|
catch( const CFB::CFBException& exception )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( exception.what() );
|
|
|
|
}
|
|
|
|
catch( const std::exception& exc )
|
|
|
|
{
|
|
|
|
wxLogDebug( wxT( "Unhandled exception in Altium schematic parsers: %s." ), exc.what() );
|
|
|
|
throw;
|
|
|
|
}
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
2024-02-04 17:14:19 +00:00
|
|
|
else // ASCII
|
2022-12-06 01:18:05 +00:00
|
|
|
{
|
2024-02-04 17:14:19 +00:00
|
|
|
ParseASCIISchematic( aFileName );
|
2022-12-06 01:18:05 +00:00
|
|
|
}
|
2022-10-31 14:03:35 +00:00
|
|
|
|
|
|
|
SCH_SCREEN* currentScreen = getCurrentScreen();
|
|
|
|
wxCHECK( currentScreen, /* void */ );
|
|
|
|
|
|
|
|
// Descend the sheet hierarchy.
|
|
|
|
for( SCH_ITEM* item : currentScreen->Items().OfType( SCH_SHEET_T ) )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* loadedScreen = nullptr;
|
|
|
|
SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( item );
|
|
|
|
|
|
|
|
wxCHECK2( sheet, continue );
|
|
|
|
|
|
|
|
// The assumption is that all of the Altium schematic files will be in the same
|
|
|
|
// path as the parent sheet path.
|
|
|
|
wxFileName loadAltiumFileName( parentFileName.GetPath(), sheet->GetFileName() );
|
|
|
|
|
2024-01-31 14:57:05 +00:00
|
|
|
if( !loadAltiumFileName.IsFileReadable() )
|
|
|
|
{
|
|
|
|
// Try case-insensitive search
|
|
|
|
wxArrayString files;
|
2024-02-21 13:05:18 +00:00
|
|
|
wxDir::GetAllFiles( parentFileName.GetPath(), &files, wxEmptyString,
|
|
|
|
wxDIR_FILES | wxDIR_HIDDEN );
|
2024-01-31 14:57:05 +00:00
|
|
|
|
|
|
|
for( const wxString& candidate : files )
|
|
|
|
{
|
|
|
|
wxFileName candidateFname( candidate );
|
|
|
|
|
|
|
|
if( candidateFname.GetFullName().IsSameAs( sheet->GetFileName(), false ) )
|
|
|
|
{
|
|
|
|
loadAltiumFileName = candidateFname;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-06 01:18:05 +00:00
|
|
|
if( loadAltiumFileName.GetFullName().IsEmpty() || !loadAltiumFileName.IsFileReadable() )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
msg.Printf( _( "The file name for sheet %s is undefined, this is probably an"
|
2022-12-08 07:36:59 +00:00
|
|
|
" Altium signal harness that got converted to a sheet." ),
|
2022-12-06 01:18:05 +00:00
|
|
|
sheet->GetName() );
|
|
|
|
m_reporter->Report( msg );
|
2022-12-10 19:32:24 +00:00
|
|
|
sheet->SetScreen( new SCH_SCREEN( m_schematic ) );
|
2022-12-06 01:18:05 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
m_rootSheet->SearchHierarchy( loadAltiumFileName.GetFullPath(), &loadedScreen );
|
|
|
|
|
|
|
|
if( loadedScreen )
|
|
|
|
{
|
|
|
|
sheet->SetScreen( loadedScreen );
|
|
|
|
// Do not need to load the sub-sheets - this has already been done.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sheet->SetScreen( new SCH_SCREEN( m_schematic ) );
|
|
|
|
SCH_SCREEN* screen = sheet->GetScreen();
|
2024-02-07 02:03:47 +00:00
|
|
|
|
|
|
|
if( sheet->GetName().Trim().empty() )
|
|
|
|
sheet->SetName( loadAltiumFileName.GetName() );
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
wxCHECK2( screen, continue );
|
|
|
|
|
|
|
|
m_sheetPath.push_back( sheet );
|
|
|
|
ParseAltiumSch( loadAltiumFileName.GetFullPath() );
|
|
|
|
|
|
|
|
// Map the loaded Altium file to the project file.
|
|
|
|
wxFileName projectFileName = loadAltiumFileName;
|
|
|
|
projectFileName.SetPath( m_schematic->Prj().GetProjectPath() );
|
2023-12-28 02:10:01 +00:00
|
|
|
projectFileName.SetExt( FILEEXT::KiCadSchematicFileExtension );
|
2022-10-31 14:03:35 +00:00
|
|
|
sheet->SetFileName( projectFileName.GetFullName() );
|
|
|
|
screen->SetFileName( projectFileName.GetFullPath() );
|
|
|
|
|
|
|
|
m_sheetPath.pop_back();
|
|
|
|
}
|
|
|
|
}
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseStorage( const ALTIUM_COMPOUND_FILE& aAltiumSchFile )
|
2021-04-10 19:45:36 +00:00
|
|
|
{
|
2022-02-19 15:45:55 +00:00
|
|
|
const CFB::COMPOUND_FILE_ENTRY* file = aAltiumSchFile.FindStream( { "Storage" } );
|
2021-04-10 19:45:36 +00:00
|
|
|
|
|
|
|
if( file == nullptr )
|
|
|
|
return;
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumSchFile, file );
|
2021-04-10 19:45:36 +00:00
|
|
|
|
|
|
|
std::map<wxString, wxString> properties = reader.ReadProperties();
|
2024-02-04 17:14:19 +00:00
|
|
|
wxString header = ALTIUM_PROPS_UTILS::ReadString( properties, "HEADER", "" );
|
|
|
|
int weight = ALTIUM_PROPS_UTILS::ReadInt( properties, "WEIGHT", 0 );
|
2021-04-10 19:45:36 +00:00
|
|
|
|
|
|
|
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!" );
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// TODO pointhi: is it possible to have multiple headers in one Storage file? Otherwise
|
|
|
|
// throw IO Error.
|
2021-04-10 19:45:36 +00:00
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
2021-06-26 19:21:30 +00:00
|
|
|
{
|
2021-07-07 11:25:01 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Storage file not fully parsed "
|
|
|
|
"(%d bytes remaining)." ),
|
|
|
|
reader.GetRemainingBytes() ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2021-06-26 19:21:30 +00:00
|
|
|
}
|
2021-04-10 19:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseAdditional( const ALTIUM_COMPOUND_FILE& aAltiumSchFile )
|
2022-08-09 11:39:13 +00:00
|
|
|
{
|
2024-02-04 17:14:19 +00:00
|
|
|
wxString streamName = wxS( "Additional" );
|
|
|
|
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* file =
|
|
|
|
aAltiumSchFile.FindStream( { streamName.ToStdString() } );
|
2022-08-09 11:39:13 +00:00
|
|
|
|
|
|
|
if( file == nullptr )
|
|
|
|
return;
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumSchFile, file );
|
2022-08-09 11:39:13 +00:00
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() <= 0 )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "Additional section does not contain any data" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::map<wxString, wxString> properties = reader.ReadProperties();
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
int recordId = ALTIUM_PROPS_UTILS::ReadInt( properties, "RECORD", 0 );
|
2022-08-09 11:39:13 +00:00
|
|
|
ALTIUM_SCH_RECORD record = static_cast<ALTIUM_SCH_RECORD>( recordId );
|
|
|
|
|
|
|
|
if( record != ALTIUM_SCH_RECORD::HEADER )
|
|
|
|
THROW_IO_ERROR( "Header expected" );
|
|
|
|
}
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
for( int index = 0; reader.GetRemainingBytes() > 0; index++ )
|
2022-08-09 11:39:13 +00:00
|
|
|
{
|
|
|
|
std::map<wxString, wxString> properties = reader.ReadProperties();
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ParseRecord( index, properties, streamName );
|
2022-08-09 11:39:13 +00:00
|
|
|
}
|
|
|
|
|
2022-08-09 19:21:36 +00:00
|
|
|
// Handle harness Ports
|
|
|
|
for( const ASCH_PORT& port : m_altiumHarnessPortsCurrentSheet )
|
|
|
|
ParseHarnessPort( port );
|
|
|
|
|
2022-08-09 11:39:13 +00:00
|
|
|
if( reader.HasParsingError() )
|
|
|
|
THROW_IO_ERROR( "stream was not parsed correctly!" );
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
THROW_IO_ERROR( "stream is not fully parsed" );
|
2024-02-07 01:57:39 +00:00
|
|
|
|
|
|
|
m_altiumHarnessPortsCurrentSheet.clear();
|
2022-08-09 11:39:13 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 19:45:36 +00:00
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseFileHeader( const ALTIUM_COMPOUND_FILE& aAltiumSchFile )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2024-02-04 17:14:19 +00:00
|
|
|
wxString streamName = wxS( "FileHeader" );
|
|
|
|
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* file =
|
|
|
|
aAltiumSchFile.FindStream( { streamName.ToStdString() } );
|
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" );
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumSchFile, file );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() <= 0 )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "FileHeader does not contain any data" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::map<wxString, wxString> properties = reader.ReadProperties();
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
wxString libtype = ALTIUM_PROPS_UTILS::ReadString( properties, "HEADER", "" );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2024-01-14 10:12:47 +00:00
|
|
|
if( libtype.CmpNoCase( "Protel for Windows - Schematic Capture Binary File Version 5.0" ) )
|
|
|
|
THROW_IO_ERROR( _( "Expected Altium Schematic file version 5.0" ) );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 13:07:42 +00:00
|
|
|
// Prepare some local variables
|
2022-10-31 14:03:35 +00:00
|
|
|
wxCHECK( m_altiumPortsCurrentSheet.empty(), /* void */ );
|
|
|
|
wxCHECK( !m_currentTitleBlock, /* void */ );
|
2020-10-27 13:07:42 +00:00
|
|
|
|
|
|
|
m_currentTitleBlock = std::make_unique<TITLE_BLOCK>();
|
|
|
|
|
2021-07-06 13:39:56 +00:00
|
|
|
// index is 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();
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ParseRecord( index, properties, streamName );
|
|
|
|
}
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
if( reader.HasParsingError() )
|
|
|
|
THROW_IO_ERROR( "stream was not parsed correctly!" );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
THROW_IO_ERROR( "stream is not fully parsed" );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
// assign LIB_SYMBOL -> COMPONENT
|
|
|
|
for( std::pair<const int, SCH_SYMBOL*>& symbol : m_symbols )
|
|
|
|
{
|
|
|
|
auto libSymbolIt = m_libSymbols.find( symbol.first );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
THROW_IO_ERROR( "every symbol should have a symbol attached" );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
m_pi->SaveSymbol( getLibFileName().GetFullPath(),
|
|
|
|
new LIB_SYMBOL( *( libSymbolIt->second ) ), m_properties.get() );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
symbol.second->SetLibSymbol( libSymbolIt->second );
|
|
|
|
}
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
// Handle title blocks
|
|
|
|
screen->SetTitleBlock( *m_currentTitleBlock );
|
|
|
|
m_currentTitleBlock.reset();
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
// Handle Ports
|
|
|
|
for( const ASCH_PORT& port : m_altiumPortsCurrentSheet )
|
|
|
|
ParsePort( port );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
m_altiumPortsCurrentSheet.clear();
|
|
|
|
m_altiumComponents.clear();
|
|
|
|
m_altiumTemplates.clear();
|
|
|
|
m_altiumImplementationList.clear();
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
m_symbols.clear();
|
|
|
|
m_libSymbols.clear();
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
// Otherwise we cannot save the imported sheet?
|
|
|
|
SCH_SHEET* sheet = getCurrentSheet();
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
wxCHECK( sheet, /* void */ );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
sheet->SetModified();
|
|
|
|
}
|
2022-10-31 14:03:35 +00:00
|
|
|
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseASCIISchematic( const wxString& aFileName )
|
|
|
|
{
|
|
|
|
// Read storage content first
|
|
|
|
{
|
|
|
|
ALTIUM_ASCII_PARSER storageReader( aFileName );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
while( storageReader.CanRead() )
|
|
|
|
{
|
|
|
|
std::map<wxString, wxString> properties = storageReader.ReadProperties();
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
// Binary data
|
|
|
|
if( properties.find( wxS( "BINARY" ) ) != properties.end() )
|
|
|
|
m_altiumStorage.emplace_back( properties );
|
|
|
|
}
|
|
|
|
}
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
// Read other data
|
|
|
|
ALTIUM_ASCII_PARSER reader( aFileName );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
if( !reader.CanRead() )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "FileHeader does not contain any data" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::map<wxString, wxString> properties = reader.ReadProperties();
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
wxString libtype = ALTIUM_PROPS_UTILS::ReadString( properties, "HEADER", "" );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
if( libtype.CmpNoCase( "Protel for Windows - Schematic Capture Ascii File Version 5.0" ) )
|
|
|
|
THROW_IO_ERROR( _( "Expected Altium Schematic file version 5.0" ) );
|
|
|
|
}
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
// Prepare some local variables
|
|
|
|
wxCHECK( m_altiumPortsCurrentSheet.empty(), /* void */ );
|
|
|
|
wxCHECK( !m_currentTitleBlock, /* void */ );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
m_currentTitleBlock = std::make_unique<TITLE_BLOCK>();
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
// index is required to resolve OWNERINDEX
|
|
|
|
int index = 0;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
while( reader.CanRead() )
|
|
|
|
{
|
|
|
|
std::map<wxString, wxString> properties = reader.ReadProperties();
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
// Reset index at headers
|
|
|
|
if( properties.find( wxS( "HEADER" ) ) != properties.end() )
|
|
|
|
{
|
|
|
|
index = 0;
|
|
|
|
continue;
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
if( properties.find( wxS( "RECORD" ) ) != properties.end() )
|
|
|
|
ParseRecord( index, properties, aFileName );
|
|
|
|
|
|
|
|
index++;
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.HasParsingError() )
|
|
|
|
THROW_IO_ERROR( "stream was not parsed correctly!" );
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
if( reader.CanRead() )
|
2020-08-23 19:01:08 +00:00
|
|
|
THROW_IO_ERROR( "stream is not fully parsed" );
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// assign LIB_SYMBOL -> COMPONENT
|
2021-07-05 09:51:15 +00:00
|
|
|
for( std::pair<const int, SCH_SYMBOL*>& symbol : m_symbols )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2021-07-05 09:51:15 +00:00
|
|
|
auto libSymbolIt = m_libSymbols.find( symbol.first );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2021-07-05 09:51:15 +00:00
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
THROW_IO_ERROR( "every symbol should have a symbol attached" );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2021-07-05 09:51:15 +00:00
|
|
|
m_pi->SaveSymbol( getLibFileName().GetFullPath(),
|
|
|
|
new LIB_SYMBOL( *( libSymbolIt->second ) ), m_properties.get() );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2021-07-05 09:51:15 +00:00
|
|
|
symbol.second->SetLibSymbol( libSymbolIt->second );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
2020-10-27 13:07:42 +00:00
|
|
|
// Handle title blocks
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->SetTitleBlock( *m_currentTitleBlock );
|
2020-10-27 13:07:42 +00:00
|
|
|
m_currentTitleBlock.reset();
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
// Handle harness Ports
|
|
|
|
for( const ASCH_PORT& port : m_altiumHarnessPortsCurrentSheet )
|
|
|
|
ParseHarnessPort( port );
|
|
|
|
|
2020-10-27 13:07:42 +00:00
|
|
|
// 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();
|
2022-11-28 00:34:33 +00:00
|
|
|
m_altiumComponents.clear();
|
2024-01-30 23:06:58 +00:00
|
|
|
m_altiumTemplates.clear();
|
2024-02-04 17:14:19 +00:00
|
|
|
m_altiumImplementationList.clear();
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
m_symbols.clear();
|
2021-07-05 09:51:15 +00:00
|
|
|
m_libSymbols.clear();
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
// Otherwise we cannot save the imported sheet?
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SHEET* sheet = getCurrentSheet();
|
|
|
|
|
|
|
|
wxCHECK( sheet, /* void */ );
|
|
|
|
|
|
|
|
sheet->SetModified();
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-23 15:20:07 +00:00
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseRecord( int index, std::map<wxString, wxString>& properties,
|
|
|
|
const wxString& aSectionName )
|
|
|
|
{
|
|
|
|
int recordId = ALTIUM_PROPS_UTILS::ReadInt( properties, "RECORD", -1 );
|
|
|
|
ALTIUM_SCH_RECORD record = static_cast<ALTIUM_SCH_RECORD>( recordId );
|
|
|
|
|
|
|
|
// see: https://github.com/vadmium/python-altium/blob/master/format.md
|
|
|
|
switch( record )
|
|
|
|
{
|
|
|
|
// FileHeader section
|
|
|
|
|
|
|
|
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:
|
|
|
|
m_reporter->Report( _( "Record 'IEEE_SYMBOL' not handled." ), RPT_SEVERITY_INFO );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::LABEL:
|
|
|
|
ParseLabel( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::BEZIER:
|
|
|
|
ParseBezier( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::POLYLINE:
|
|
|
|
ParsePolyline( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::POLYGON:
|
|
|
|
ParsePolygon( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::ELLIPSE:
|
|
|
|
ParseEllipse( properties );
|
|
|
|
break;
|
|
|
|
|
2024-04-30 03:07:14 +00:00
|
|
|
case ALTIUM_SCH_RECORD::PIECHART:
|
|
|
|
m_reporter->Report( _( "Record 'PIECHART' not handled." ), RPT_SEVERITY_INFO );
|
|
|
|
break;
|
2024-02-04 17:14:19 +00:00
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::ROUND_RECTANGLE:
|
|
|
|
ParseRoundRectangle( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::ELLIPTICAL_ARC:
|
|
|
|
case ALTIUM_SCH_RECORD::ARC:
|
|
|
|
ParseArc( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::LINE:
|
|
|
|
ParseLine( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::RECTANGLE:
|
|
|
|
ParseRectangle( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::SHEET_SYMBOL:
|
|
|
|
ParseSheetSymbol( index, properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::SHEET_ENTRY:
|
|
|
|
ParseSheetEntry( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::POWER_PORT:
|
|
|
|
ParsePowerPort( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::PORT:
|
|
|
|
// 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 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::NO_ERC:
|
|
|
|
ParseNoERC( properties );
|
|
|
|
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:
|
|
|
|
ParseTextFrame( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::JUNCTION:
|
|
|
|
ParseJunction( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::IMAGE:
|
|
|
|
ParseImage( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::SHEET:
|
|
|
|
ParseSheet( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::SHEET_NAME:
|
|
|
|
ParseSheetName( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::FILE_NAME:
|
|
|
|
ParseFileName( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::DESIGNATOR:
|
|
|
|
ParseDesignator( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::BUS_ENTRY:
|
|
|
|
ParseBusEntry( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::TEMPLATE:
|
|
|
|
ParseTemplate( index, properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::PARAMETER:
|
|
|
|
ParseParameter( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::PARAMETER_SET:
|
|
|
|
m_reporter->Report( _( "Parameter Set not currently supported." ), RPT_SEVERITY_ERROR );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::IMPLEMENTATION_LIST:
|
|
|
|
ParseImplementationList( index, properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::IMPLEMENTATION:
|
|
|
|
ParseImplementation( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::MAP_DEFINER_LIST:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::MAP_DEFINER:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::IMPL_PARAMS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::NOTE:
|
|
|
|
ParseNote( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::COMPILE_MASK:
|
|
|
|
m_reporter->Report( _( "Compile mask not currently supported." ), RPT_SEVERITY_ERROR );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::HYPERLINK:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Additional section
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::HARNESS_CONNECTOR:
|
|
|
|
ParseHarnessConnector( index, properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::HARNESS_ENTRY:
|
|
|
|
ParseHarnessEntry( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::HARNESS_TYPE:
|
|
|
|
ParseHarnessType( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::SIGNAL_HARNESS:
|
|
|
|
ParseSignalHarness( properties );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::BLANKET:
|
|
|
|
m_reporter->Report( _( "Blanket not currently supported." ), RPT_SEVERITY_ERROR );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
m_reporter->Report(
|
|
|
|
wxString::Format( _( "Unknown or unexpected record id %d found in %s." ), recordId,
|
|
|
|
aSectionName ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_IO_ALTIUM::m_harnessOwnerIndexOffset = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-05 19:10:26 +00:00
|
|
|
bool SCH_IO_ALTIUM::IsComponentPartVisible( const ASCH_OWNER_INTERFACE& aElem ) const
|
2020-10-23 15:02:56 +00:00
|
|
|
{
|
2024-02-05 19:10:26 +00:00
|
|
|
const auto& component = m_altiumComponents.find( aElem.ownerindex );
|
|
|
|
const auto& templ = m_altiumTemplates.find( aElem.ownerindex );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2024-01-30 23:06:58 +00:00
|
|
|
if( component != m_altiumComponents.end() )
|
2024-02-05 19:10:26 +00:00
|
|
|
return component->second.displaymode == aElem.ownerpartdisplaymode;
|
2024-01-30 23:06:58 +00:00
|
|
|
|
|
|
|
if( templ != m_altiumTemplates.end() )
|
|
|
|
return true;
|
2020-10-23 15:02:56 +00:00
|
|
|
|
2024-01-30 23:06:58 +00:00
|
|
|
return false;
|
2020-10-23 15:02:56 +00:00
|
|
|
}
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
const ASCH_STORAGE_FILE* SCH_IO_ALTIUM::GetFileFromStorage( const wxString& aFilename ) const
|
2021-04-10 19:45:36 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-21 13:05:18 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseComponent( int aIndex, const std::map<wxString, wxString>& aProperties )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2022-11-26 00:10:27 +00:00
|
|
|
SCH_SHEET* currentSheet = m_sheetPath.Last();
|
|
|
|
wxCHECK( currentSheet, /* void */ );
|
|
|
|
|
|
|
|
wxString sheetName = currentSheet->GetName();
|
|
|
|
|
|
|
|
if( sheetName.IsEmpty() )
|
|
|
|
sheetName = wxT( "root" );
|
|
|
|
|
2022-11-28 00:34:33 +00:00
|
|
|
ASCH_SYMBOL altiumSymbol( aProperties );
|
|
|
|
|
|
|
|
if( m_altiumComponents.count( aIndex ) )
|
|
|
|
{
|
|
|
|
const ASCH_SYMBOL& currentSymbol = m_altiumComponents.at( aIndex );
|
|
|
|
|
|
|
|
m_reporter->Report( wxString::Format( _( "Symbol \"%s\" in sheet \"%s\" at index %d "
|
|
|
|
"replaced with symbol \"%s\"." ),
|
|
|
|
currentSymbol.libreference,
|
|
|
|
sheetName,
|
|
|
|
aIndex,
|
|
|
|
altiumSymbol.libreference ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pair = m_altiumComponents.insert( { aIndex, altiumSymbol } );
|
|
|
|
const ASCH_SYMBOL& elem = pair.first->second;
|
|
|
|
|
2020-10-27 13:16:17 +00:00
|
|
|
// TODO: this is a hack until we correctly apply all transformations to every element
|
2024-02-05 21:38:21 +00:00
|
|
|
wxString name = wxString::Format( "%s_%d%s_%s",
|
2022-11-26 00:10:27 +00:00
|
|
|
sheetName,
|
2020-11-05 23:19:47 +00:00
|
|
|
elem.orientation,
|
|
|
|
elem.isMirrored ? "_mirrored" : "",
|
2024-02-05 21:38:21 +00:00
|
|
|
elem.libreference );
|
|
|
|
|
|
|
|
if( elem.displaymodecount > 1 )
|
|
|
|
name << '_' << elem.displaymode;
|
|
|
|
|
2020-12-17 23:32:23 +00:00
|
|
|
LIB_ID libId = AltiumToKiCadLibID( getLibName(), name );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* ksymbol = new LIB_SYMBOL( wxEmptyString );
|
|
|
|
ksymbol->SetName( name );
|
|
|
|
ksymbol->SetDescription( elem.componentdescription );
|
|
|
|
ksymbol->SetLibId( libId );
|
2021-07-05 09:51:15 +00:00
|
|
|
m_libSymbols.insert( { aIndex, ksymbol } );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
// each component has its own symbol for now
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = new SCH_SYMBOL();
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->SetPosition( elem.location + m_sheetOffset );
|
2021-07-16 20:13:26 +00:00
|
|
|
|
|
|
|
// TODO: keep it simple for now, and only set position.
|
2022-11-24 18:42:41 +00:00
|
|
|
// component->SetOrientation( elem.orientation );
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->SetLibId( libId );
|
2022-11-23 13:46:03 +00:00
|
|
|
symbol->SetUnit( std::max( 0, elem.currentpartid ) );
|
2024-03-06 04:08:11 +00:00
|
|
|
symbol->GetField( DESCRIPTION_FIELD )->SetText( elem.componentdescription );
|
2020-10-23 15:20:07 +00:00
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
2022-01-28 15:52:30 +00:00
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( symbol );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2021-07-05 09:51:15 +00:00
|
|
|
m_symbols.insert( { aIndex, symbol } );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-30 23:06:58 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseTemplate( int aIndex, const std::map<wxString, wxString>& aProperties )
|
|
|
|
{
|
|
|
|
SCH_SHEET* currentSheet = m_sheetPath.Last();
|
|
|
|
wxCHECK( currentSheet, /* void */ );
|
|
|
|
|
|
|
|
wxString sheetName = currentSheet->GetName();
|
|
|
|
|
|
|
|
if( sheetName.IsEmpty() )
|
|
|
|
sheetName = wxT( "root" );
|
|
|
|
|
|
|
|
ASCH_TEMPLATE altiumTemplate( aProperties );
|
|
|
|
|
|
|
|
// Extract base name from path
|
|
|
|
wxString baseName = altiumTemplate.filename.AfterLast( '\\' ).BeforeLast( '.' );
|
|
|
|
|
|
|
|
if( baseName.IsEmpty() )
|
|
|
|
baseName = wxS( "Template" );
|
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
m_altiumTemplates.insert( { aIndex, altiumTemplate } );
|
|
|
|
// No need to create a symbol - graphics is put on the sheet
|
2024-01-30 23:06:58 +00:00
|
|
|
}
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
|
2024-01-26 13:59:07 +00:00
|
|
|
void SCH_IO_ALTIUM::ParsePin( const std::map<wxString, wxString>& aProperties,
|
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
|
|
|
ASCH_PIN elem( aProperties );
|
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
LIB_SYMBOL* symbol = (int) aSymbol.size() <= elem.ownerpartdisplaymode
|
|
|
|
? nullptr
|
|
|
|
: aSymbol[elem.ownerpartdisplaymode];
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SYMBOL* schSymbol = nullptr;
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
if( !symbol )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
|
|
|
m_reporter->Report( wxString::Format( wxT( "Pin's owner (%d) not found." ),
|
2024-05-04 13:18:56 +00:00
|
|
|
elem.ownerindex ),
|
2023-08-28 21:50:56 +00:00
|
|
|
RPT_SEVERITY_DEBUG );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-02-05 19:10:26 +00:00
|
|
|
if( !IsComponentPartVisible( elem ) )
|
2023-08-28 21:50:56 +00:00
|
|
|
return;
|
2020-10-23 15:02:56 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
schSymbol = m_symbols.at( libSymbolIt->first );
|
|
|
|
symbol = libSymbolIt->second;
|
|
|
|
}
|
|
|
|
|
2024-04-20 09:44:34 +00:00
|
|
|
SCH_PIN* pin = new SCH_PIN( symbol );
|
2023-09-04 21:46:25 +00:00
|
|
|
|
|
|
|
// Make sure that these are visible when initializing the symbol
|
|
|
|
// This may be overriden by the file data but not by the pin defaults
|
|
|
|
pin->SetNameTextSize( schIUScale.MilsToIU( DEFAULT_PINNAME_SIZE ) );
|
|
|
|
pin->SetNumberTextSize( schIUScale.MilsToIU( DEFAULT_PINNUM_SIZE ) );
|
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
symbol->AddDrawItem( pin, false );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2022-11-23 13:46:03 +00:00
|
|
|
pin->SetUnit( std::max( 0, elem.ownerpartid ) );
|
2020-10-23 15:20:07 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
pin->SetName( AltiumPinNamesToKiCad( elem.name ) );
|
2020-08-23 19:01:08 +00:00
|
|
|
pin->SetNumber( elem.designator );
|
2020-10-09 14:23:07 +00:00
|
|
|
pin->SetLength( elem.pinlength );
|
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
if( elem.hidden )
|
|
|
|
pin->SetVisible( false );
|
|
|
|
|
2021-07-03 23:17:23 +00:00
|
|
|
if( !elem.showDesignator )
|
|
|
|
pin->SetNumberTextSize( 0 );
|
|
|
|
|
|
|
|
if( !elem.showPinName )
|
|
|
|
pin->SetNameTextSize( 0 );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I 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:
|
2023-07-27 03:46:15 +00:00
|
|
|
pin->SetOrientation( PIN_ORIENTATION::PIN_LEFT );
|
2020-10-09 14:23:07 +00:00
|
|
|
pinLocation.x += elem.pinlength;
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-14 19:38:12 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::UPWARDS:
|
2023-07-27 03:46:15 +00:00
|
|
|
pin->SetOrientation( PIN_ORIENTATION::PIN_DOWN );
|
2020-10-09 14:23:07 +00:00
|
|
|
pinLocation.y -= elem.pinlength;
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-14 19:38:12 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::LEFTWARDS:
|
2023-07-27 03:46:15 +00:00
|
|
|
pin->SetOrientation( PIN_ORIENTATION::PIN_RIGHT );
|
2020-10-09 14:23:07 +00:00
|
|
|
pinLocation.x -= elem.pinlength;
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-14 19:38:12 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::DOWNWARDS:
|
2023-07-27 03:46:15 +00:00
|
|
|
pin->SetOrientation( PIN_ORIENTATION::PIN_UP );
|
2020-10-09 14:23:07 +00:00
|
|
|
pinLocation.y += elem.pinlength;
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-09 14:23:07 +00:00
|
|
|
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!
|
2024-05-04 13:18:56 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
if( schSymbol )
|
2024-05-04 13:18:56 +00:00
|
|
|
pinLocation = GetRelativePosition( pinLocation + m_sheetOffset, schSymbol );
|
|
|
|
|
|
|
|
pin->SetPosition( pinLocation );
|
2020-10-09 14:23:07 +00:00
|
|
|
|
|
|
|
switch( elem.electrical )
|
|
|
|
{
|
|
|
|
case ASCH_PIN_ELECTRICAL::INPUT:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_INPUT );
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-09 14:23:07 +00:00
|
|
|
case ASCH_PIN_ELECTRICAL::BIDI:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_BIDI );
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-09 14:23:07 +00:00
|
|
|
case ASCH_PIN_ELECTRICAL::OUTPUT:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_OUTPUT );
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-09 14:23:07 +00:00
|
|
|
case ASCH_PIN_ELECTRICAL::OPEN_COLLECTOR:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR );
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-09 14:23:07 +00:00
|
|
|
case ASCH_PIN_ELECTRICAL::PASSIVE:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_PASSIVE );
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-09 14:23:07 +00:00
|
|
|
case ASCH_PIN_ELECTRICAL::TRISTATE:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_TRISTATE );
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-09 14:23:07 +00:00
|
|
|
case ASCH_PIN_ELECTRICAL::OPEN_EMITTER:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_OPENEMITTER );
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-09 14:23:07 +00:00
|
|
|
case ASCH_PIN_ELECTRICAL::POWER:
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-09 14:23:07 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
if( elem.symbolOuterEdge == ASCH_PIN_SYMBOL::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
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
if( elem.symbolInnerEdge == ASCH_PIN_SYMBOL::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
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
if( elem.symbolOuterEdge == ASCH_PIN_SYMBOL::NEGATED )
|
2020-10-09 14:23:07 +00:00
|
|
|
{
|
|
|
|
switch( elem.symbolInnerEdge )
|
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
case ASCH_PIN_SYMBOL::CLOCK:
|
2020-10-09 14:23:07 +00:00
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::INVERTED_CLOCK );
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-09 14:23:07 +00:00
|
|
|
default:
|
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::INVERTED );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-08-28 21:50:56 +00:00
|
|
|
else if( elem.symbolOuterEdge == ASCH_PIN_SYMBOL::LOW_INPUT )
|
2020-10-09 15:13:18 +00:00
|
|
|
{
|
|
|
|
switch( elem.symbolInnerEdge )
|
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
case ASCH_PIN_SYMBOL::CLOCK:
|
2020-10-09 15:13:18 +00:00
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::CLOCK_LOW );
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-09 15:13:18 +00:00
|
|
|
default:
|
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::INPUT_LOW );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-08-28 21:50:56 +00:00
|
|
|
else if( elem.symbolOuterEdge == ASCH_PIN_SYMBOL::LOW_OUTPUT )
|
2020-10-09 15:13:18 +00:00
|
|
|
{
|
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::OUTPUT_LOW );
|
|
|
|
}
|
2020-10-09 14:23:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
switch( elem.symbolInnerEdge )
|
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
case ASCH_PIN_SYMBOL::CLOCK:
|
2020-10-09 14:23:07 +00:00
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::CLOCK );
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-09 14:23:07 +00:00
|
|
|
default:
|
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::LINE ); // nothing to do
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-14 11:11:47 +00:00
|
|
|
void SetTextPositioning( EDA_TEXT* text, ASCH_LABEL_JUSTIFICATION justification,
|
2024-05-04 13:18:56 +00:00
|
|
|
ASCH_RECORD_ORIENTATION orientation, bool for_lib_item = false )
|
2020-10-17 11:52:47 +00:00
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
int vjustify, hjustify;
|
2022-01-13 12:29:46 +00:00
|
|
|
EDA_ANGLE angle = ANGLE_HORIZONTAL;
|
2021-07-24 20:28:24 +00:00
|
|
|
|
2020-10-17 11:52:47 +00:00
|
|
|
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:
|
2021-12-28 22:13:54 +00:00
|
|
|
vjustify = GR_TEXT_V_ALIGN_BOTTOM;
|
2020-10-17 11:52:47 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-17 11:52:47 +00:00
|
|
|
case ASCH_LABEL_JUSTIFICATION::CENTER_LEFT:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::CENTER_CENTER:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::CENTER_RIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
vjustify = GR_TEXT_V_ALIGN_CENTER;
|
2020-10-17 11:52:47 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-17 11:52:47 +00:00
|
|
|
case ASCH_LABEL_JUSTIFICATION::TOP_LEFT:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::TOP_CENTER:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::TOP_RIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
vjustify = GR_TEXT_V_ALIGN_TOP;
|
2020-10-17 11:52:47 +00:00
|
|
|
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:
|
2021-12-28 22:13:54 +00:00
|
|
|
hjustify = GR_TEXT_H_ALIGN_LEFT;
|
2020-10-17 11:52:47 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-17 11:52:47 +00:00
|
|
|
case ASCH_LABEL_JUSTIFICATION::BOTTOM_CENTER:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::CENTER_CENTER:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::TOP_CENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
hjustify = GR_TEXT_H_ALIGN_CENTER;
|
2020-10-17 11:52:47 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-17 11:52:47 +00:00
|
|
|
case ASCH_LABEL_JUSTIFICATION::BOTTOM_RIGHT:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::CENTER_RIGHT:
|
|
|
|
case ASCH_LABEL_JUSTIFICATION::TOP_RIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
hjustify = GR_TEXT_H_ALIGN_RIGHT;
|
2021-07-24 20:28:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( orientation )
|
|
|
|
{
|
|
|
|
case ASCH_RECORD_ORIENTATION::RIGHTWARDS:
|
2024-05-04 13:18:56 +00:00
|
|
|
if( for_lib_item )
|
|
|
|
vjustify *= -1;
|
|
|
|
|
2022-01-13 12:29:46 +00:00
|
|
|
angle = ANGLE_HORIZONTAL;
|
2021-07-24 20:28:24 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2021-07-24 20:28:24 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::LEFTWARDS:
|
2024-05-04 13:18:56 +00:00
|
|
|
if( !for_lib_item )
|
|
|
|
vjustify *= -1;
|
|
|
|
|
2021-07-24 20:28:24 +00:00
|
|
|
hjustify *= -1;
|
2022-01-13 12:29:46 +00:00
|
|
|
angle = ANGLE_HORIZONTAL;
|
2021-07-24 20:28:24 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2021-07-24 20:28:24 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::UPWARDS:
|
2024-05-04 13:18:56 +00:00
|
|
|
if( for_lib_item )
|
|
|
|
vjustify *= -1;
|
|
|
|
|
2022-01-13 12:29:46 +00:00
|
|
|
angle = ANGLE_VERTICAL;
|
2021-07-24 20:28:24 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2021-07-24 20:28:24 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::DOWNWARDS:
|
2024-05-04 13:18:56 +00:00
|
|
|
if( !for_lib_item )
|
|
|
|
vjustify *= -1;
|
|
|
|
|
2021-07-24 20:28:24 +00:00
|
|
|
hjustify *= -1;
|
2022-01-13 12:29:46 +00:00
|
|
|
angle = ANGLE_VERTICAL;
|
2020-10-17 11:52:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-07-24 20:28:24 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
text->SetVertJustify( static_cast<GR_TEXT_V_ALIGN_T>( vjustify ) );
|
|
|
|
text->SetHorizJustify( static_cast<GR_TEXT_H_ALIGN_T>( hjustify ) );
|
2021-07-24 20:28:24 +00:00
|
|
|
text->SetTextAngle( angle );
|
2020-10-17 11:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
bool SCH_IO_ALTIUM::ShouldPutItemOnSheet( int aOwnerindex )
|
|
|
|
{
|
|
|
|
// No component assigned -> Put on sheet
|
|
|
|
if( aOwnerindex == ALTIUM_COMPONENT_NONE )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// For a template -> Put on sheet so we can resolve variables
|
|
|
|
if( m_altiumTemplates.find( aOwnerindex ) != m_altiumTemplates.end() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 13:59:07 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseLabel( const std::map<wxString, wxString>& aProperties,
|
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol, std::vector<int>& aFontSizes )
|
2020-10-17 11:52:47 +00:00
|
|
|
{
|
|
|
|
ASCH_LABEL elem( aProperties );
|
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
if( aSymbol.empty() && ShouldPutItemOnSheet( elem.ownerindex ) )
|
2020-10-17 11:52:47 +00:00
|
|
|
{
|
2023-10-01 13:10:09 +00:00
|
|
|
static const std::map<wxString, wxString> variableMap = {
|
2021-07-08 13:14:27 +00:00
|
|
|
{ "APPLICATION_BUILDNUMBER", "KICAD_VERSION" },
|
2024-05-04 13:18:56 +00:00
|
|
|
{ "SHEETNUMBER", "#" },
|
|
|
|
{ "SHEETTOTAL", "##" },
|
|
|
|
{ "TITLE", "TITLE" }, // including 1:1 maps makes it easier
|
|
|
|
{ "REVISION", "REVISION" }, // to see that the list is complete
|
|
|
|
{ "DATE", "ISSUE_DATE" },
|
|
|
|
{ "CURRENTDATE", "CURRENT_DATE" },
|
|
|
|
{ "COMPANYNAME", "COMPANY" },
|
|
|
|
{ "DOCUMENTNAME", "FILENAME" },
|
|
|
|
{ "DOCUMENTFULLPATHANDNAME", "FILEPATH" },
|
|
|
|
{ "PROJECTNAME", "PROJECTNAME" },
|
2021-07-08 13:14:27 +00:00
|
|
|
};
|
2021-07-06 12:27:36 +00:00
|
|
|
|
2023-10-01 13:10:09 +00:00
|
|
|
wxString kicadText = AltiumSchSpecialStringsToKiCadVariables( elem.text, variableMap );
|
2021-07-08 13:14:27 +00:00
|
|
|
SCH_TEXT* textItem = new SCH_TEXT( elem.location + m_sheetOffset, kicadText );
|
2020-10-17 11:52:47 +00:00
|
|
|
|
2021-07-24 20:28:24 +00:00
|
|
|
SetTextPositioning( textItem, elem.justification, elem.orientation );
|
2020-10-17 11:52:47 +00:00
|
|
|
|
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 );
|
2022-08-10 08:00:41 +00:00
|
|
|
textItem->SetTextSize( { font.Size / 2, font.Size / 2 } );
|
2024-02-25 17:28:05 +00:00
|
|
|
|
|
|
|
// Must come after SetTextSize()
|
|
|
|
textItem->SetBold( font.Bold );
|
|
|
|
textItem->SetItalic( font.Italic );
|
2020-10-17 12:33:30 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 13:14:27 +00:00
|
|
|
textItem->SetFlags(IS_NEW );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
|
|
|
screen->Append( textItem );
|
2020-10-17 11:52:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
LIB_SYMBOL* symbol = (int) aSymbol.size() <= elem.ownerpartdisplaymode
|
|
|
|
? nullptr
|
|
|
|
: aSymbol[elem.ownerpartdisplaymode];
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SYMBOL* schsym = nullptr;
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
if( !symbol )
|
2020-10-17 11:52:47 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
|
|
|
|
|
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
|
|
|
m_reporter->Report( wxString::Format( wxT( "Label's owner (%d) not found." ),
|
2024-01-26 13:59:07 +00:00
|
|
|
elem.ownerindex ),
|
2023-08-28 21:50:56 +00:00
|
|
|
RPT_SEVERITY_DEBUG );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol = libSymbolIt->second;
|
|
|
|
schsym = m_symbols.at( libSymbolIt->first );
|
2020-10-17 11:52:47 +00:00
|
|
|
}
|
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
VECTOR2I pos = elem.location;
|
|
|
|
SCH_TEXT* textItem = new SCH_TEXT( { 0, 0 }, elem.text, LAYER_DEVICE );
|
2023-08-28 21:50:56 +00:00
|
|
|
symbol->AddDrawItem( textItem, false );
|
2020-10-17 11:52:47 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
/// Handle labels that are in a library symbol, not on schematic
|
2024-05-04 13:18:56 +00:00
|
|
|
if( schsym )
|
|
|
|
pos = GetRelativePosition( elem.location + m_sheetOffset, schsym );
|
2020-10-23 15:20:07 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
textItem->SetPosition( pos );
|
2023-08-28 21:50:56 +00:00
|
|
|
textItem->SetUnit( std::max( 0, elem.ownerpartid ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
SetTextPositioning( textItem, elem.justification, elem.orientation, true );
|
2020-10-17 12:33:30 +00:00
|
|
|
|
2024-04-14 18:04:53 +00:00
|
|
|
size_t fontId = 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 );
|
2022-08-10 08:00:41 +00:00
|
|
|
textItem->SetTextSize( { font.Size / 2, font.Size / 2 } );
|
2024-02-25 17:28:05 +00:00
|
|
|
|
|
|
|
// Must come after SetTextSize()
|
|
|
|
textItem->SetBold( font.Bold );
|
|
|
|
textItem->SetItalic( font.Italic );
|
2020-10-17 12:33:30 +00:00
|
|
|
}
|
2023-09-06 17:10:54 +00:00
|
|
|
else if( fontId > 0 && fontId <= aFontSizes.size() )
|
|
|
|
{
|
|
|
|
int size = aFontSizes[fontId - 1];
|
|
|
|
textItem->SetTextSize( { size, size } );
|
|
|
|
}
|
2020-10-17 11:52:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 13:59:07 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseTextFrame( const std::map<wxString, wxString>& aProperties,
|
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol,
|
|
|
|
std::vector<int>& aFontSizes )
|
2021-07-06 19:26:22 +00:00
|
|
|
{
|
|
|
|
ASCH_TEXT_FRAME elem( aProperties );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
if( aSymbol.empty() && ShouldPutItemOnSheet( elem.ownerindex ) )
|
2023-08-28 21:50:56 +00:00
|
|
|
AddTextBox( &elem );
|
2023-09-04 21:46:25 +00:00
|
|
|
else
|
2023-09-06 17:10:54 +00:00
|
|
|
AddLibTextBox( &elem, aSymbol, aFontSizes );
|
2022-08-16 14:45:11 +00:00
|
|
|
}
|
2021-07-06 19:26:22 +00:00
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseNote( const std::map<wxString, wxString>& aProperties )
|
2024-01-26 13:59:07 +00:00
|
|
|
{
|
2022-08-16 14:45:11 +00:00
|
|
|
ASCH_NOTE elem( aProperties );
|
|
|
|
AddTextBox( static_cast<ASCH_TEXT_FRAME*>( &elem ) );
|
2021-07-06 19:26:22 +00:00
|
|
|
|
2022-08-16 14:45:11 +00:00
|
|
|
// TODO: need some sort of property system for storing author....
|
|
|
|
}
|
2021-07-06 19:26:22 +00:00
|
|
|
|
|
|
|
|
2024-01-26 13:59:07 +00:00
|
|
|
void SCH_IO_ALTIUM::AddTextBox( const ASCH_TEXT_FRAME *aElem )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
2022-08-16 14:45:11 +00:00
|
|
|
SCH_TEXTBOX* textBox = new SCH_TEXTBOX();
|
2021-07-06 19:26:22 +00:00
|
|
|
|
2022-08-16 14:45:11 +00:00
|
|
|
VECTOR2I sheetTopRight = aElem->TopRight + m_sheetOffset;
|
2023-08-28 21:50:56 +00:00
|
|
|
VECTOR2I sheetBottomLeft = aElem->BottomLeft +m_sheetOffset;
|
|
|
|
|
2022-08-16 14:45:11 +00:00
|
|
|
textBox->SetStart( sheetTopRight );
|
|
|
|
textBox->SetEnd( sheetBottomLeft );
|
2021-07-06 19:26:22 +00:00
|
|
|
|
2022-08-16 14:45:11 +00:00
|
|
|
textBox->SetText( aElem->Text );
|
2021-07-06 19:26:22 +00:00
|
|
|
|
2022-08-16 14:45:11 +00:00
|
|
|
textBox->SetFillColor( GetColorFromInt( aElem->AreaColor ) );
|
2022-08-19 16:47:22 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
if( aElem->isSolid)
|
2022-08-19 16:47:22 +00:00
|
|
|
textBox->SetFillMode( FILL_T::FILLED_WITH_COLOR );
|
|
|
|
else
|
|
|
|
textBox->SetFilled( false );
|
2021-07-05 22:57:58 +00:00
|
|
|
|
2022-08-16 14:45:11 +00:00
|
|
|
if( aElem->ShowBorder )
|
2023-11-25 13:05:45 +00:00
|
|
|
textBox->SetStroke( STROKE_PARAMS( 0, LINE_STYLE::DEFAULT,
|
2022-10-31 14:03:35 +00:00
|
|
|
GetColorFromInt( aElem->BorderColor ) ) );
|
2022-08-16 14:45:11 +00:00
|
|
|
else
|
2023-11-25 13:05:45 +00:00
|
|
|
textBox->SetStroke( STROKE_PARAMS( -1, LINE_STYLE::DEFAULT,
|
2022-10-31 14:03:35 +00:00
|
|
|
GetColorFromInt( aElem->BorderColor ) ) );
|
2021-07-05 22:57:58 +00:00
|
|
|
|
2022-08-16 14:45:11 +00:00
|
|
|
switch( aElem->Alignment )
|
2021-07-05 22:57:58 +00:00
|
|
|
{
|
|
|
|
default:
|
2021-07-06 19:26:22 +00:00
|
|
|
case ASCH_TEXT_FRAME_ALIGNMENT::LEFT:
|
2022-08-16 14:45:11 +00:00
|
|
|
textBox->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2021-07-05 22:57:58 +00:00
|
|
|
break;
|
2021-07-06 19:26:22 +00:00
|
|
|
case ASCH_TEXT_FRAME_ALIGNMENT::CENTER:
|
2022-08-16 14:45:11 +00:00
|
|
|
textBox->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
2021-07-05 22:57:58 +00:00
|
|
|
break;
|
2021-07-06 19:26:22 +00:00
|
|
|
case ASCH_TEXT_FRAME_ALIGNMENT::RIGHT:
|
2022-08-16 14:45:11 +00:00
|
|
|
textBox->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2021-07-05 22:57:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-08-16 14:45:11 +00:00
|
|
|
size_t fontId = static_cast<int>( aElem->FontID );
|
2021-07-05 22:57:58 +00:00
|
|
|
|
|
|
|
if( m_altiumSheet && fontId > 0 && fontId <= m_altiumSheet->fonts.size() )
|
|
|
|
{
|
|
|
|
const ASCH_SHEET_FONT& font = m_altiumSheet->fonts.at( fontId - 1 );
|
2022-08-16 14:45:11 +00:00
|
|
|
textBox->SetTextSize( { font.Size / 2, font.Size / 2 } );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2024-02-25 17:28:05 +00:00
|
|
|
// Must come after SetTextSize()
|
|
|
|
textBox->SetBold( font.Bold );
|
|
|
|
textBox->SetItalic( font.Italic );
|
|
|
|
//textBox->SetFont( //how to set font, we have a font name here: ( font.fontname );
|
2021-07-05 22:57:58 +00:00
|
|
|
}
|
|
|
|
|
2022-08-16 14:45:11 +00:00
|
|
|
textBox->SetFlags( IS_NEW );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
|
|
|
screen->Append( textBox );
|
2021-07-05 22:57:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 13:59:07 +00:00
|
|
|
void SCH_IO_ALTIUM::AddLibTextBox( const ASCH_TEXT_FRAME *aElem, std::vector<LIB_SYMBOL*>& aSymbol,
|
|
|
|
std::vector<int>& aFontSizes )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
2023-09-09 17:27:51 +00:00
|
|
|
LIB_SYMBOL* symbol = static_cast<int>( aSymbol.size() ) <= aElem->ownerpartdisplaymode
|
|
|
|
? nullptr
|
|
|
|
: aSymbol[aElem->ownerpartdisplaymode];
|
|
|
|
SCH_SYMBOL* schsym = nullptr;
|
|
|
|
|
|
|
|
if( !symbol )
|
|
|
|
{
|
|
|
|
const auto& libSymbolIt = m_libSymbols.find( aElem->ownerindex );
|
|
|
|
|
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
|
|
|
m_reporter->Report(
|
|
|
|
wxString::Format( wxT( "Label's owner (%d) not found." ), aElem->ownerindex ),
|
|
|
|
RPT_SEVERITY_DEBUG );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol = libSymbolIt->second;
|
|
|
|
schsym = m_symbols.at( libSymbolIt->first );
|
|
|
|
}
|
2023-09-04 21:46:25 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_TEXTBOX* textBox = new SCH_TEXTBOX( LAYER_DEVICE );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-09 17:27:51 +00:00
|
|
|
textBox->SetUnit( std::max( 0, aElem->ownerpartid ) );
|
|
|
|
symbol->AddDrawItem( textBox, false );
|
|
|
|
|
|
|
|
/// Handle text frames that are in a library symbol, not on schematic
|
|
|
|
if( !schsym )
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
textBox->SetStart( aElem->TopRight );
|
|
|
|
textBox->SetEnd( aElem->BottomLeft );
|
2023-09-09 17:27:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
textBox->SetStart( GetRelativePosition( aElem->TopRight + m_sheetOffset, schsym ) );
|
|
|
|
textBox->SetEnd( GetRelativePosition( aElem->BottomLeft + m_sheetOffset, schsym ) );
|
|
|
|
}
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
textBox->SetText( aElem->Text );
|
|
|
|
|
|
|
|
textBox->SetFillColor( GetColorFromInt( aElem->AreaColor ) );
|
|
|
|
|
|
|
|
if( aElem->isSolid)
|
|
|
|
textBox->SetFillMode( FILL_T::FILLED_WITH_COLOR );
|
|
|
|
else
|
|
|
|
textBox->SetFilled( false );
|
|
|
|
|
|
|
|
if( aElem->ShowBorder )
|
2023-11-25 13:05:45 +00:00
|
|
|
textBox->SetStroke( STROKE_PARAMS( 0, LINE_STYLE::DEFAULT,
|
2023-08-28 21:50:56 +00:00
|
|
|
GetColorFromInt( aElem->BorderColor ) ) );
|
|
|
|
else
|
|
|
|
textBox->SetStroke( STROKE_PARAMS( -1 ) );
|
|
|
|
|
|
|
|
switch( aElem->Alignment )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case ASCH_TEXT_FRAME_ALIGNMENT::LEFT:
|
|
|
|
textBox->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
break;
|
|
|
|
case ASCH_TEXT_FRAME_ALIGNMENT::CENTER:
|
|
|
|
textBox->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
break;
|
|
|
|
case ASCH_TEXT_FRAME_ALIGNMENT::RIGHT:
|
|
|
|
textBox->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-09-06 17:10:54 +00:00
|
|
|
if( aElem->FontID > 0 && aElem->FontID <= static_cast<int>( aFontSizes.size() ) )
|
|
|
|
{
|
|
|
|
int size = aFontSizes[aElem->FontID - 1];
|
|
|
|
textBox->SetTextSize( { size, size } );
|
|
|
|
}
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseBezier( const std::map<wxString, wxString>& aProperties,
|
2024-01-26 13:59:07 +00:00
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol )
|
2020-10-10 14:56:19 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
if( aSymbol.empty() && ShouldPutItemOnSheet( elem.ownerindex ) )
|
2020-10-10 14:56:19 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SCREEN* currentScreen = getCurrentScreen();
|
|
|
|
wxCHECK( currentScreen, /* void */ );
|
|
|
|
|
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 );
|
2023-11-25 13:05:45 +00:00
|
|
|
line->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID ) );
|
2020-10-10 16:41:19 +00:00
|
|
|
|
|
|
|
line->SetFlags( IS_NEW );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
currentScreen->Append( line );
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
// simulate Bezier using line segments
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> bezierPoints;
|
|
|
|
std::vector<VECTOR2I> polyPoints;
|
2021-07-05 09:51:15 +00:00
|
|
|
|
2020-10-10 16:41:19 +00:00
|
|
|
for( size_t j = i; j < elem.points.size() && j < i + 4; j++ )
|
2021-12-27 15:50:30 +00:00
|
|
|
bezierPoints.push_back( elem.points.at( j ) );
|
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 );
|
2023-11-25 13:05:45 +00:00
|
|
|
line->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID ) );
|
2020-10-10 16:41:19 +00:00
|
|
|
|
|
|
|
line->SetFlags( IS_NEW );
|
2023-08-28 21:50:56 +00:00
|
|
|
currentScreen->Append( line );
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-10 14:56:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
LIB_SYMBOL* symbol = (int) aSymbol.size() <= elem.ownerpartdisplaymode
|
|
|
|
? nullptr
|
|
|
|
: aSymbol[elem.ownerpartdisplaymode];
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SYMBOL* schsym = nullptr;
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
if( !symbol )
|
2020-10-10 14:56:19 +00:00
|
|
|
{
|
2023-09-04 21:46:25 +00:00
|
|
|
const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
|
|
|
m_reporter->Report( wxString::Format( wxT( "Bezier's owner (%d) not found." ),
|
2024-01-26 13:59:07 +00:00
|
|
|
elem.ownerindex ),
|
|
|
|
RPT_SEVERITY_DEBUG );
|
2023-08-28 21:50:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol = libSymbolIt->second;
|
|
|
|
schsym = m_symbols.at( libSymbolIt->first );
|
2020-10-10 14:56:19 +00:00
|
|
|
}
|
|
|
|
|
2024-02-05 19:10:26 +00:00
|
|
|
if( aSymbol.empty() && !IsComponentPartVisible( elem ) )
|
2020-10-23 15:02:56 +00:00
|
|
|
return;
|
|
|
|
|
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
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-08-28 21:50:56 +00:00
|
|
|
symbol->AddDrawItem( line, false );
|
2020-10-10 16:41:19 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
line->SetUnit( std::max( 0, elem.ownerpartid ) );
|
2020-10-23 15:20:07 +00:00
|
|
|
|
2020-10-10 16:41:19 +00:00
|
|
|
for( size_t j = i; j < elem.points.size() && j < i + 2; j++ )
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
VECTOR2I pos = elem.points.at( j );
|
|
|
|
|
|
|
|
if( schsym )
|
|
|
|
pos = GetRelativePosition( pos + m_sheetOffset, schsym );
|
|
|
|
|
|
|
|
line->AddPoint( pos );
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
line->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID ) );
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
2021-09-11 12:38:59 +00:00
|
|
|
else if( i + 3 == elem.points.size() )
|
|
|
|
{
|
|
|
|
// TODO: special case of a single line with an extra point?
|
|
|
|
// I haven't a clue what this is all about, but the sample document we have in
|
|
|
|
// https://gitlab.com/kicad/code/kicad/-/issues/8974 responds best by treating it
|
|
|
|
// as another single line special case.
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-08-28 21:50:56 +00:00
|
|
|
symbol->AddDrawItem( line, false );
|
2021-09-11 12:38:59 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
line->SetUnit( std::max( 0, elem.ownerpartid ) );
|
2021-09-11 12:38:59 +00:00
|
|
|
|
|
|
|
for( size_t j = i; j < elem.points.size() && j < i + 2; j++ )
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
VECTOR2I pos = elem.points.at( j );
|
|
|
|
|
|
|
|
if( schsym )
|
|
|
|
pos = GetRelativePosition( pos + m_sheetOffset, schsym );
|
|
|
|
|
|
|
|
line->AddPoint( pos );
|
2021-09-11 12:38:59 +00:00
|
|
|
}
|
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
line->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID ) );
|
2021-09-11 12:38:59 +00:00
|
|
|
}
|
2020-10-10 16:41:19 +00:00
|
|
|
else
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
// Bezier always has exactly 4 control points
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* bezier = new SCH_SHAPE( SHAPE_T::BEZIER, LAYER_DEVICE );
|
2023-08-28 21:50:56 +00:00
|
|
|
symbol->AddDrawItem( bezier, false );
|
2020-10-10 16:41:19 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
bezier->SetUnit( std::max( 0, elem.ownerpartid ) );
|
2020-10-23 15:20:07 +00:00
|
|
|
|
2020-10-10 16:41:19 +00:00
|
|
|
for( size_t j = i; j < elem.points.size() && j < i + 4; j++ )
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
VECTOR2I pos = elem.points.at( j );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
if( schsym )
|
|
|
|
pos = GetRelativePosition( pos + m_sheetOffset, schsym );
|
2021-11-02 22:45:25 +00:00
|
|
|
|
|
|
|
switch( j - i )
|
|
|
|
{
|
2022-03-22 10:04:24 +00:00
|
|
|
case 0: bezier->SetStart( pos ); break;
|
2021-11-02 22:45:25 +00:00
|
|
|
case 1: bezier->SetBezierC1( pos ); break;
|
|
|
|
case 2: bezier->SetBezierC2( pos ); break;
|
2022-03-22 10:04:24 +00:00
|
|
|
case 3: bezier->SetEnd( pos ); break;
|
2021-11-02 22:45:25 +00:00
|
|
|
default: break; // Can't get here but silence warnings
|
|
|
|
}
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
bezier->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID ) );
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
2020-10-10 14:56:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParsePolyline( const std::map<wxString, wxString>& aProperties,
|
2024-01-26 13:59:07 +00:00
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol )
|
2020-10-10 14:56:19 +00:00
|
|
|
{
|
|
|
|
ASCH_POLYLINE elem( aProperties );
|
|
|
|
|
2024-01-31 14:57:05 +00:00
|
|
|
if( elem.Points.size() < 2 )
|
|
|
|
return;
|
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
if( aSymbol.empty() && ShouldPutItemOnSheet( elem.ownerindex ) )
|
2020-10-10 14:56:19 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
2024-01-31 14:57:05 +00:00
|
|
|
for( size_t i = 1; i < elem.Points.size(); i++ )
|
|
|
|
{
|
|
|
|
SCH_LINE* line = new SCH_LINE;
|
|
|
|
|
|
|
|
line->SetStartPoint( elem.Points[i - 1] + m_sheetOffset );
|
|
|
|
line->SetEndPoint( elem.Points[i] + m_sheetOffset );
|
2021-12-27 16:22:28 +00:00
|
|
|
|
2024-01-31 14:57:05 +00:00
|
|
|
line->SetStroke( STROKE_PARAMS( elem.LineWidth, GetPlotDashType( elem.LineStyle ),
|
|
|
|
GetColorFromInt( elem.Color ) ) );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2024-01-31 14:57:05 +00:00
|
|
|
line->SetFlags( IS_NEW );
|
2020-10-10 14:56:19 +00:00
|
|
|
|
2024-01-31 14:57:05 +00:00
|
|
|
screen->Append( line );
|
|
|
|
}
|
2020-10-10 14:56:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
LIB_SYMBOL* symbol = (int) aSymbol.size() <= elem.ownerpartdisplaymode
|
|
|
|
? nullptr
|
|
|
|
: aSymbol[elem.ownerpartdisplaymode];
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SYMBOL* schsym = nullptr;
|
2021-07-05 09:51:15 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
if( !symbol )
|
2020-10-10 14:56:19 +00:00
|
|
|
{
|
2023-09-04 21:46:25 +00:00
|
|
|
const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
|
|
|
m_reporter->Report( wxString::Format( wxT( "Polyline's owner (%d) not found." ),
|
2024-01-26 13:59:07 +00:00
|
|
|
elem.ownerindex ),
|
2023-08-28 21:50:56 +00:00
|
|
|
RPT_SEVERITY_DEBUG );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol = libSymbolIt->second;
|
|
|
|
schsym = m_symbols.at( libSymbolIt->first );
|
2020-10-10 14:56:19 +00:00
|
|
|
}
|
|
|
|
|
2024-02-05 19:10:26 +00:00
|
|
|
if( aSymbol.empty() && !IsComponentPartVisible( elem ) )
|
2020-10-23 15:02:56 +00:00
|
|
|
return;
|
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-08-28 21:50:56 +00:00
|
|
|
symbol->AddDrawItem( line, false );
|
2020-10-10 14:56:19 +00:00
|
|
|
|
2024-01-30 23:06:58 +00:00
|
|
|
line->SetUnit( std::max( 0, elem.ownerpartid ) );
|
2020-10-23 15:20:07 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
for( VECTOR2I point : elem.Points )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
if( schsym )
|
|
|
|
point = GetRelativePosition( point + m_sheetOffset, schsym );
|
|
|
|
|
|
|
|
line->AddPoint( point );
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
2020-10-10 14:56:19 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
SetLibShapeLine( elem, line, ALTIUM_SCH_RECORD::POLYLINE );
|
|
|
|
STROKE_PARAMS stroke = line->GetStroke();
|
2023-11-25 13:05:45 +00:00
|
|
|
stroke.SetLineStyle( GetPlotDashType( elem.LineStyle ) );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
line->SetStroke( stroke );
|
2020-10-10 14:56:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParsePolygon( const std::map<wxString, wxString>& aProperties,
|
2024-01-26 13:59:07 +00:00
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol )
|
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
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
if( aSymbol.empty() && ShouldPutItemOnSheet( elem.ownerindex ) )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
SCH_SHAPE* poly = new SCH_SHAPE( SHAPE_T::POLY );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
for( VECTOR2I& point : elem.points )
|
2021-12-27 16:22:28 +00:00
|
|
|
poly->AddPoint( point + m_sheetOffset );
|
|
|
|
poly->AddPoint( elem.points.front() + m_sheetOffset );
|
2020-10-10 14:22:53 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
SetSchShapeLine( elem, poly );
|
2021-12-27 16:22:28 +00:00
|
|
|
SetSchShapeFillAndColor( elem, poly );
|
|
|
|
poly->SetFlags( IS_NEW );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( poly );
|
2020-10-10 14:22:53 +00:00
|
|
|
}
|
|
|
|
else
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
LIB_SYMBOL* symbol = (int) aSymbol.size() <= elem.ownerpartdisplaymode
|
|
|
|
? nullptr
|
|
|
|
: aSymbol[elem.ownerpartdisplaymode];
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SYMBOL* schsym = nullptr;
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
if( !symbol )
|
2020-10-10 14:22:53 +00:00
|
|
|
{
|
2023-09-04 21:46:25 +00:00
|
|
|
const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
|
|
|
m_reporter->Report( wxString::Format( wxT( "Polygon's owner (%d) not found." ),
|
2024-05-04 13:18:56 +00:00
|
|
|
elem.ownerindex ),
|
|
|
|
RPT_SEVERITY_DEBUG );
|
2023-08-28 21:50:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol = libSymbolIt->second;
|
|
|
|
schsym = m_symbols.at( libSymbolIt->first );
|
2020-10-10 14:22:53 +00:00
|
|
|
}
|
|
|
|
|
2024-02-05 19:10:26 +00:00
|
|
|
if( aSymbol.empty() && !IsComponentPartVisible( elem ) )
|
2020-10-23 15:02:56 +00:00
|
|
|
return;
|
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2020-10-10 14:22:53 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
symbol->AddDrawItem( line, false );
|
2024-01-30 23:06:58 +00:00
|
|
|
line->SetUnit( std::max( 0, elem.ownerpartid ) );
|
2020-10-23 15:20:07 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
for( VECTOR2I point : elem.points )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
if( schsym )
|
|
|
|
point = GetRelativePosition( point + m_sheetOffset, schsym );
|
|
|
|
|
|
|
|
line->AddPoint( point );
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
VECTOR2I point = elem.points.front();
|
|
|
|
|
|
|
|
if( schsym )
|
|
|
|
point = GetRelativePosition( elem.points.front() + m_sheetOffset, schsym );
|
|
|
|
|
|
|
|
line->AddPoint( point );
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
SetLibShapeLine( elem, line, ALTIUM_SCH_RECORD::POLYGON );
|
|
|
|
SetLibShapeFillAndColor( elem, line, ALTIUM_SCH_RECORD::POLYGON, elem.Color );
|
|
|
|
|
2024-01-26 13:59:07 +00:00
|
|
|
if( line->GetFillColor() == line->GetStroke().GetColor()
|
|
|
|
&& line->GetFillMode() != FILL_T::NO_FILL )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
|
|
|
STROKE_PARAMS stroke = line->GetStroke();
|
|
|
|
stroke.SetWidth( -1 );
|
|
|
|
line->SetStroke( stroke );
|
|
|
|
}
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
2020-10-10 14:22:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseRoundRectangle( const std::map<wxString, wxString>& aProperties,
|
2024-01-26 13:59:07 +00:00
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol )
|
2020-10-14 19:15:09 +00:00
|
|
|
{
|
|
|
|
ASCH_ROUND_RECTANGLE elem( aProperties );
|
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
if( aSymbol.empty() && ShouldPutItemOnSheet( elem.ownerindex ) )
|
2020-10-14 19:15:09 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
2020-10-14 19:15:09 +00:00
|
|
|
// TODO: misses rounded edges
|
2023-07-24 16:07:56 +00:00
|
|
|
SCH_SHAPE* rect = new SCH_SHAPE( SHAPE_T::RECTANGLE );
|
2021-12-27 15:50:30 +00:00
|
|
|
|
2024-01-30 23:06:58 +00:00
|
|
|
rect->SetPosition( elem.TopRight + m_sheetOffset );
|
|
|
|
rect->SetEnd( elem.BottomLeft + m_sheetOffset );
|
2023-08-28 21:50:56 +00:00
|
|
|
SetSchShapeLine( elem, rect );
|
2021-12-27 15:50:30 +00:00
|
|
|
SetSchShapeFillAndColor( elem, rect );
|
|
|
|
rect->SetFlags( IS_NEW );
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( rect );
|
2020-10-14 19:15:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
LIB_SYMBOL* symbol = (int) aSymbol.size() <= elem.ownerpartdisplaymode
|
|
|
|
? nullptr
|
|
|
|
: aSymbol[elem.ownerpartdisplaymode];
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SYMBOL* schsym = nullptr;
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
if( !symbol )
|
2020-10-14 19:15:09 +00:00
|
|
|
{
|
2023-09-04 21:46:25 +00:00
|
|
|
const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
|
|
|
m_reporter->Report( wxString::Format( wxT( "Rounded rectangle's owner (%d) not "
|
2024-01-26 13:59:07 +00:00
|
|
|
"found." ),
|
|
|
|
elem.ownerindex ),
|
2023-08-28 21:50:56 +00:00
|
|
|
RPT_SEVERITY_DEBUG );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol = libSymbolIt->second;
|
|
|
|
schsym = m_symbols.at( libSymbolIt->first );
|
2020-10-14 19:15:09 +00:00
|
|
|
}
|
|
|
|
|
2024-02-05 19:10:26 +00:00
|
|
|
if( aSymbol.empty() && !IsComponentPartVisible( elem ) )
|
2020-10-23 15:02:56 +00:00
|
|
|
return;
|
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* rect = nullptr;
|
2020-10-23 15:20:07 +00:00
|
|
|
|
2024-01-30 23:06:58 +00:00
|
|
|
int width = std::abs( elem.TopRight.x - elem.BottomLeft.x );
|
|
|
|
int height = std::abs( elem.TopRight.y - elem.BottomLeft.y );
|
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
// If it is a circle, make it a circle
|
2024-01-30 23:06:58 +00:00
|
|
|
if( std::abs( elem.CornerRadius.x ) >= width / 2
|
|
|
|
&& std::abs( elem.CornerRadius.y ) >= height / 2 )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
rect = new SCH_SHAPE( SHAPE_T::CIRCLE, LAYER_DEVICE );
|
2023-09-04 21:46:25 +00:00
|
|
|
|
2024-01-30 23:06:58 +00:00
|
|
|
VECTOR2I center = ( elem.TopRight + elem.BottomLeft ) / 2;
|
|
|
|
int radius = std::min( width / 2, height / 2 );
|
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
if( schsym )
|
|
|
|
center = GetRelativePosition( center + m_sheetOffset, schsym );
|
2024-01-30 23:06:58 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
rect->SetPosition( center );
|
2024-01-30 23:06:58 +00:00
|
|
|
rect->SetEnd( VECTOR2I( rect->GetPosition().x + radius, rect->GetPosition().y ) );
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
rect = new SCH_SHAPE( SHAPE_T::RECTANGLE, LAYER_DEVICE );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
if( !schsym )
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
rect->SetPosition( elem.TopRight );
|
|
|
|
rect->SetEnd( elem.BottomLeft );
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rect->SetPosition( GetRelativePosition( elem.TopRight + m_sheetOffset, schsym ) );
|
|
|
|
rect->SetEnd( GetRelativePosition( elem.BottomLeft + m_sheetOffset, schsym ) );
|
|
|
|
}
|
2020-10-23 15:20:07 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
rect->Normalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLibShapeLine( elem, rect, ALTIUM_SCH_RECORD::ROUND_RECTANGLE );
|
|
|
|
SetLibShapeFillAndColor( elem, rect, ALTIUM_SCH_RECORD::ROUND_RECTANGLE, elem.Color );
|
|
|
|
|
|
|
|
symbol->AddDrawItem( rect, false );
|
2024-01-30 23:06:58 +00:00
|
|
|
rect->SetUnit( std::max( 0, elem.ownerpartid ) );
|
2020-10-14 19:15:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 13:59:07 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseArc( const std::map<wxString, wxString>& aProperties,
|
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol )
|
2020-10-10 16:41:19 +00:00
|
|
|
{
|
|
|
|
ASCH_ARC elem( aProperties );
|
|
|
|
|
2024-05-04 14:09:52 +00:00
|
|
|
int arc_radius = elem.m_Radius;
|
|
|
|
VECTOR2I center = elem.m_Center;
|
|
|
|
EDA_ANGLE startAngle( elem.m_EndAngle, DEGREES_T );
|
|
|
|
EDA_ANGLE endAngle( elem.m_StartAngle, DEGREES_T );
|
|
|
|
VECTOR2I startOffset( KiROUND( arc_radius * startAngle.Cos() ),
|
|
|
|
-KiROUND( arc_radius * startAngle.Sin() ) );
|
|
|
|
VECTOR2I endOffset( KiROUND( arc_radius * endAngle.Cos() ),
|
|
|
|
-KiROUND( arc_radius * endAngle.Sin() ) );
|
2022-11-24 18:42:41 +00:00
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
if( aSymbol.empty() && ShouldPutItemOnSheet( elem.ownerindex ) )
|
2020-10-10 16:41:19 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SCREEN* currentScreen = getCurrentScreen();
|
|
|
|
wxCHECK( currentScreen, /* void */ );
|
|
|
|
|
2022-11-24 18:42:41 +00:00
|
|
|
if( elem.m_StartAngle == 0 && ( elem.m_EndAngle == 0 || elem.m_EndAngle == 360 ) )
|
2021-12-27 15:02:12 +00:00
|
|
|
{
|
2022-01-25 22:33:37 +00:00
|
|
|
SCH_SHAPE* circle = new SCH_SHAPE( SHAPE_T::CIRCLE );
|
2021-12-27 15:02:12 +00:00
|
|
|
|
2022-11-24 18:42:41 +00:00
|
|
|
circle->SetPosition( elem.m_Center + m_sheetOffset );
|
|
|
|
circle->SetEnd( circle->GetPosition() + VECTOR2I( arc_radius, 0 ) );
|
2023-11-25 13:05:45 +00:00
|
|
|
circle->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID ) );
|
2021-12-27 15:02:12 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
currentScreen->Append( circle );
|
2021-12-27 15:02:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-25 22:33:37 +00:00
|
|
|
SCH_SHAPE* arc = new SCH_SHAPE( SHAPE_T::ARC );
|
2021-12-27 15:02:12 +00:00
|
|
|
|
2022-11-24 18:42:41 +00:00
|
|
|
arc->SetCenter( elem.m_Center + m_sheetOffset );
|
|
|
|
arc->SetStart( elem.m_Center + startOffset + m_sheetOffset );
|
2024-05-04 14:09:52 +00:00
|
|
|
arc->SetEnd( elem.m_Center + endOffset + m_sheetOffset );
|
2021-12-27 15:02:12 +00:00
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
arc->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID ) );
|
2021-12-27 15:02:12 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
currentScreen->Append( arc );
|
2021-12-27 15:02:12 +00:00
|
|
|
}
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
LIB_SYMBOL* symbol = (int) aSymbol.size() <= elem.ownerpartdisplaymode
|
|
|
|
? nullptr
|
|
|
|
: aSymbol[elem.ownerpartdisplaymode];
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SYMBOL* schsym = nullptr;
|
2021-07-06 13:39:56 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
if( !symbol )
|
2020-10-10 16:41:19 +00:00
|
|
|
{
|
2023-09-04 21:46:25 +00:00
|
|
|
const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
|
|
|
m_reporter->Report( wxString::Format( wxT( "Arc's owner (%d) not found." ),
|
2024-05-04 13:18:56 +00:00
|
|
|
elem.ownerindex ),
|
|
|
|
RPT_SEVERITY_DEBUG );
|
2023-08-28 21:50:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol = libSymbolIt->second;
|
|
|
|
schsym = m_symbols.at( libSymbolIt->first );
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
|
|
|
|
2024-02-05 19:10:26 +00:00
|
|
|
if( aSymbol.empty() && !IsComponentPartVisible( elem ) )
|
2020-10-23 15:02:56 +00:00
|
|
|
return;
|
|
|
|
|
2022-11-24 18:42:41 +00:00
|
|
|
if( elem.m_StartAngle == 0 && ( elem.m_EndAngle == 0 || elem.m_EndAngle == 360 ) )
|
2020-10-10 16:41:19 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* circle = new SCH_SHAPE( SHAPE_T::CIRCLE, LAYER_DEVICE );
|
2023-08-28 21:50:56 +00:00
|
|
|
symbol->AddDrawItem( circle, false );
|
2020-10-10 16:41:19 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
circle->SetUnit( std::max( 0, elem.ownerpartid ) );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
if( schsym )
|
|
|
|
center = GetRelativePosition( center + m_sheetOffset, schsym );
|
|
|
|
|
|
|
|
circle->SetPosition( center );
|
2020-10-23 15:20:07 +00:00
|
|
|
|
2022-11-24 18:42:41 +00:00
|
|
|
circle->SetEnd( circle->GetPosition() + VECTOR2I( arc_radius, 0 ) );
|
2023-08-28 21:50:56 +00:00
|
|
|
SetLibShapeLine( elem, circle, ALTIUM_SCH_RECORD::ARC );
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* arc = new SCH_SHAPE( SHAPE_T::ARC, LAYER_DEVICE );
|
2023-08-28 21:50:56 +00:00
|
|
|
symbol->AddDrawItem( arc, false );
|
2023-09-04 21:46:25 +00:00
|
|
|
arc->SetUnit( std::max( 0, elem.ownerpartid ) );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
if( schsym )
|
2024-05-04 13:18:56 +00:00
|
|
|
center = GetRelativePosition( elem.m_Center + m_sheetOffset, schsym );
|
|
|
|
|
|
|
|
arc->SetCenter( center );
|
|
|
|
arc->SetStart( center + startOffset );
|
2024-05-04 14:09:52 +00:00
|
|
|
arc->SetEnd( center + endOffset );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
SetLibShapeLine( elem, arc, ALTIUM_SCH_RECORD::ARC );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-04 21:46:25 +00:00
|
|
|
|
|
|
|
|
2024-01-26 13:59:07 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseEllipticalArc( const std::map<wxString, wxString>& aProperties,
|
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol )
|
2023-09-05 21:01:27 +00:00
|
|
|
{
|
|
|
|
ASCH_ARC elem( aProperties );
|
2023-09-04 21:46:25 +00:00
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
if( aSymbol.empty() && ShouldPutItemOnSheet( elem.ownerindex ) )
|
2023-09-05 21:01:27 +00:00
|
|
|
{
|
|
|
|
SCH_SCREEN* currentScreen = getCurrentScreen();
|
|
|
|
wxCHECK( currentScreen, /* void */ );
|
2023-09-04 21:46:25 +00:00
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
ELLIPSE<int> ellipse( elem.m_Center + m_sheetOffset, elem.m_Radius,
|
2024-01-06 22:03:41 +00:00
|
|
|
KiROUND( elem.m_SecondaryRadius ), ANGLE_0,
|
2023-09-05 21:01:27 +00:00
|
|
|
EDA_ANGLE( elem.m_StartAngle, DEGREES_T ),
|
|
|
|
EDA_ANGLE( elem.m_EndAngle, DEGREES_T ) );
|
|
|
|
std::vector<BEZIER<int>> beziers;
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
TransformEllipseToBeziers( ellipse, beziers );
|
|
|
|
|
|
|
|
for( const BEZIER<int>& bezier : beziers )
|
|
|
|
{
|
|
|
|
SCH_SHAPE* schbezier = new SCH_SHAPE( SHAPE_T::BEZIER );
|
|
|
|
schbezier->SetStart( bezier.Start );
|
|
|
|
schbezier->SetBezierC1( bezier.C1 );
|
|
|
|
schbezier->SetBezierC2( bezier.C2 );
|
|
|
|
schbezier->SetEnd( bezier.End );
|
2023-11-25 13:05:45 +00:00
|
|
|
schbezier->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID ) );
|
2023-09-05 21:01:27 +00:00
|
|
|
schbezier->RebuildBezierToSegmentsPointsList( elem.LineWidth );
|
|
|
|
|
|
|
|
currentScreen->Append( schbezier );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
LIB_SYMBOL* symbol = (int) aSymbol.size() <= elem.ownerpartdisplaymode
|
|
|
|
? nullptr
|
|
|
|
: aSymbol[elem.ownerpartdisplaymode];
|
2023-09-05 21:01:27 +00:00
|
|
|
SCH_SYMBOL* schsym = nullptr;
|
|
|
|
|
|
|
|
if( !symbol )
|
|
|
|
{
|
|
|
|
const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
|
|
|
|
|
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
|
|
|
m_reporter->Report( wxString::Format( wxT( "Elliptical Arc's owner (%d) not found." ),
|
2024-05-04 13:18:56 +00:00
|
|
|
elem.ownerindex ),
|
2024-02-21 13:05:18 +00:00
|
|
|
RPT_SEVERITY_DEBUG );
|
2023-09-05 21:01:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol = libSymbolIt->second;
|
|
|
|
schsym = m_symbols.at( libSymbolIt->first );
|
|
|
|
}
|
|
|
|
|
2024-02-05 19:10:26 +00:00
|
|
|
if( aSymbol.empty() && !IsComponentPartVisible( elem ) )
|
2023-09-05 21:01:27 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
ELLIPSE<int> ellipse( elem.m_Center, elem.m_Radius,
|
2024-01-06 22:03:41 +00:00
|
|
|
KiROUND( elem.m_SecondaryRadius ), ANGLE_0,
|
2023-09-05 21:01:27 +00:00
|
|
|
EDA_ANGLE( elem.m_StartAngle, DEGREES_T ),
|
|
|
|
EDA_ANGLE( elem.m_EndAngle, DEGREES_T ) );
|
|
|
|
std::vector<BEZIER<int>> beziers;
|
|
|
|
|
|
|
|
TransformEllipseToBeziers( ellipse, beziers );
|
|
|
|
|
|
|
|
for( const BEZIER<int>& bezier : beziers )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* schbezier = new SCH_SHAPE( SHAPE_T::BEZIER, LAYER_DEVICE );
|
2023-09-05 21:01:27 +00:00
|
|
|
symbol->AddDrawItem( schbezier, false );
|
|
|
|
|
|
|
|
schbezier->SetUnit( std::max( 0, elem.ownerpartid ) );
|
|
|
|
|
|
|
|
if( schsym )
|
|
|
|
{
|
|
|
|
schbezier->SetStart( GetRelativePosition( bezier.Start + m_sheetOffset, schsym ) );
|
|
|
|
schbezier->SetBezierC1( GetRelativePosition( bezier.C1 + m_sheetOffset, schsym ) );
|
|
|
|
schbezier->SetBezierC2( GetRelativePosition( bezier.C2 + m_sheetOffset, schsym ) );
|
|
|
|
schbezier->SetEnd( GetRelativePosition( bezier.End + m_sheetOffset, schsym ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
schbezier->SetStart( bezier.Start );
|
|
|
|
schbezier->SetBezierC1( bezier.C1 );
|
|
|
|
schbezier->SetBezierC2( bezier.C2 );
|
|
|
|
schbezier->SetEnd( bezier.End );
|
2023-09-05 21:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetLibShapeLine( elem, schbezier, ALTIUM_SCH_RECORD::ELLIPTICAL_ARC );
|
|
|
|
schbezier->RebuildBezierToSegmentsPointsList( elem.LineWidth );
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 13:59:07 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseEllipse( const std::map<wxString, wxString>& aProperties,
|
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol )
|
2022-09-04 00:58:03 +00:00
|
|
|
{
|
|
|
|
ASCH_ELLIPSE elem( aProperties );
|
|
|
|
|
2023-08-31 22:13:43 +00:00
|
|
|
if( elem.Radius == elem.SecondaryRadius )
|
2022-09-04 00:58:03 +00:00
|
|
|
{
|
2023-08-31 22:13:43 +00:00
|
|
|
ParseCircle( aProperties, aSymbol );
|
2022-09-04 00:58:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
if( aSymbol.empty() && ShouldPutItemOnSheet( elem.ownerindex ) )
|
2023-08-31 22:13:43 +00:00
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
2024-01-31 06:34:36 +00:00
|
|
|
COLOR4D fillColor = GetColorFromInt( elem.AreaColor );
|
|
|
|
|
|
|
|
if( elem.IsTransparent )
|
|
|
|
fillColor = fillColor.WithAlpha( 0.5 );
|
|
|
|
|
|
|
|
FILL_T fillMode = elem.IsSolid ? FILL_T::FILLED_WITH_COLOR : FILL_T::NO_FILL;
|
|
|
|
|
2024-01-26 13:59:07 +00:00
|
|
|
ELLIPSE<int> ellipse( elem.Center + m_sheetOffset, elem.Radius,
|
2024-01-06 22:03:41 +00:00
|
|
|
KiROUND( elem.SecondaryRadius ), ANGLE_0 );
|
2024-01-31 06:34:36 +00:00
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
std::vector<BEZIER<int>> beziers;
|
2024-01-31 06:34:36 +00:00
|
|
|
std::vector<VECTOR2I> polyPoints;
|
2023-08-31 22:13:43 +00:00
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
TransformEllipseToBeziers( ellipse, beziers );
|
2023-08-31 22:13:43 +00:00
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
for( const BEZIER<int>& bezier : beziers )
|
|
|
|
{
|
|
|
|
SCH_SHAPE* schbezier = new SCH_SHAPE( SHAPE_T::BEZIER );
|
|
|
|
schbezier->SetStart( bezier.Start );
|
|
|
|
schbezier->SetBezierC1( bezier.C1 );
|
|
|
|
schbezier->SetBezierC2( bezier.C2 );
|
|
|
|
schbezier->SetEnd( bezier.End );
|
2023-11-25 13:05:45 +00:00
|
|
|
schbezier->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID ) );
|
2024-01-31 06:34:36 +00:00
|
|
|
schbezier->SetFillColor( fillColor );
|
|
|
|
schbezier->SetFillMode( fillMode );
|
2023-08-31 22:13:43 +00:00
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
schbezier->RebuildBezierToSegmentsPointsList( schbezier->GetWidth() / 2 );
|
|
|
|
screen->Append( schbezier );
|
2024-01-31 06:34:36 +00:00
|
|
|
|
|
|
|
polyPoints.push_back( bezier.Start );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( fillMode != FILL_T::NO_FILL )
|
|
|
|
{
|
|
|
|
SCH_SHAPE* schpoly = new SCH_SHAPE( SHAPE_T::POLY );
|
|
|
|
schpoly->SetFillColor( fillColor );
|
|
|
|
schpoly->SetFillMode( fillMode );
|
|
|
|
schpoly->SetWidth( -1 );
|
|
|
|
|
|
|
|
for( const VECTOR2I& point : polyPoints )
|
|
|
|
schpoly->AddPoint( point );
|
|
|
|
|
|
|
|
schpoly->AddPoint( polyPoints[0] );
|
|
|
|
|
|
|
|
screen->Append( schpoly );
|
2023-08-31 22:13:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
LIB_SYMBOL* symbol = (int) aSymbol.size() <= elem.ownerpartdisplaymode
|
|
|
|
? nullptr
|
|
|
|
: aSymbol[elem.ownerpartdisplaymode];
|
2023-08-31 22:13:43 +00:00
|
|
|
SCH_SYMBOL* schsym = nullptr;
|
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
if( !symbol )
|
2023-08-31 22:13:43 +00:00
|
|
|
{
|
2023-09-04 21:46:25 +00:00
|
|
|
const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
|
2023-08-31 22:13:43 +00:00
|
|
|
|
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
|
|
|
m_reporter->Report( wxString::Format( wxT( "Ellipse's owner (%d) not found." ),
|
2023-09-04 21:46:25 +00:00
|
|
|
elem.ownerindex ),
|
2023-08-31 22:13:43 +00:00
|
|
|
RPT_SEVERITY_DEBUG );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol = libSymbolIt->second;
|
|
|
|
schsym = m_symbols.at( libSymbolIt->first );
|
|
|
|
}
|
|
|
|
|
2024-01-31 16:08:25 +00:00
|
|
|
ELLIPSE<int> ellipse( elem.Center, elem.Radius, KiROUND( elem.SecondaryRadius ),
|
2024-01-06 22:03:41 +00:00
|
|
|
ANGLE_0 );
|
2024-01-31 16:08:25 +00:00
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
std::vector<BEZIER<int>> beziers;
|
2024-01-31 16:08:25 +00:00
|
|
|
std::vector<VECTOR2I> polyPoints;
|
2023-08-31 22:13:43 +00:00
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
TransformEllipseToBeziers( ellipse, beziers );
|
2023-08-31 22:13:43 +00:00
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
for( const BEZIER<int>& bezier : beziers )
|
2023-08-31 22:13:43 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* libbezier = new SCH_SHAPE( SHAPE_T::BEZIER, LAYER_DEVICE );
|
2023-09-05 21:01:27 +00:00
|
|
|
symbol->AddDrawItem( libbezier, false );
|
2024-01-30 23:06:58 +00:00
|
|
|
libbezier->SetUnit( std::max( 0, elem.ownerpartid ) );
|
2023-09-05 21:01:27 +00:00
|
|
|
|
|
|
|
if( !schsym )
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
libbezier->SetStart( bezier.Start );
|
|
|
|
libbezier->SetBezierC1( bezier.C1 );
|
|
|
|
libbezier->SetBezierC2( bezier.C2 );
|
|
|
|
libbezier->SetEnd( bezier.End );
|
2023-09-05 21:01:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
libbezier->SetStart( GetRelativePosition( bezier.Start + m_sheetOffset, schsym ) );
|
|
|
|
libbezier->SetBezierC1( GetRelativePosition( bezier.C1 + m_sheetOffset, schsym ) );
|
|
|
|
libbezier->SetBezierC2( GetRelativePosition( bezier.C2 + m_sheetOffset, schsym ) );
|
|
|
|
libbezier->SetEnd( GetRelativePosition( bezier.End + m_sheetOffset, schsym ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLibShapeLine( elem, libbezier, ALTIUM_SCH_RECORD::ELLIPSE );
|
|
|
|
SetLibShapeFillAndColor( elem, libbezier, ALTIUM_SCH_RECORD::ELLIPSE, elem.Color );
|
|
|
|
libbezier->RebuildBezierToSegmentsPointsList( libbezier->GetWidth() / 2 );
|
2024-01-31 16:08:25 +00:00
|
|
|
|
|
|
|
polyPoints.push_back( libbezier->GetStart() );
|
2023-08-31 22:13:43 +00:00
|
|
|
}
|
2023-09-05 21:01:27 +00:00
|
|
|
|
|
|
|
// A series of beziers won't fill the center, so if this is meant to be fully filled,
|
|
|
|
// Add a polygon to fill the center
|
2024-01-31 16:08:25 +00:00
|
|
|
if( elem.IsSolid )
|
2023-08-31 22:13:43 +00:00
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* libline = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-09-05 21:01:27 +00:00
|
|
|
symbol->AddDrawItem( libline, false );
|
2024-01-30 23:06:58 +00:00
|
|
|
libline->SetUnit( std::max( 0, elem.ownerpartid ) );
|
2023-08-31 22:13:43 +00:00
|
|
|
|
2024-01-31 16:08:25 +00:00
|
|
|
for( const VECTOR2I& point : polyPoints )
|
|
|
|
libline->AddPoint( point );
|
|
|
|
|
|
|
|
libline->AddPoint( polyPoints[0] );
|
2023-08-31 22:13:43 +00:00
|
|
|
|
2024-01-31 16:08:25 +00:00
|
|
|
libline->SetWidth( -1 );
|
2023-09-05 21:01:27 +00:00
|
|
|
SetLibShapeFillAndColor( elem, libline, ALTIUM_SCH_RECORD::ELLIPSE, elem.Color );
|
|
|
|
}
|
2023-08-31 22:13:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 13:59:07 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseCircle( const std::map<wxString, wxString>& aProperties,
|
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol )
|
2023-08-31 22:13:43 +00:00
|
|
|
{
|
|
|
|
ASCH_ELLIPSE elem( aProperties );
|
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
if( aSymbol.empty() && ShouldPutItemOnSheet( elem.ownerindex ) )
|
2022-09-04 00:58:03 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
SCH_SHAPE* circle = new SCH_SHAPE( SHAPE_T::CIRCLE );
|
2022-09-04 00:58:03 +00:00
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
circle->SetPosition( elem.Center + m_sheetOffset );
|
|
|
|
circle->SetEnd( circle->GetPosition() + VECTOR2I( elem.Radius, 0 ) );
|
2023-11-25 13:05:45 +00:00
|
|
|
circle->SetStroke( STROKE_PARAMS( 1, LINE_STYLE::SOLID ) );
|
2022-09-04 00:58:03 +00:00
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
circle->SetFillColor( GetColorFromInt( elem.AreaColor ) );
|
2022-09-04 00:58:03 +00:00
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
if( elem.IsSolid )
|
|
|
|
circle->SetFillMode( FILL_T::FILLED_WITH_COLOR );
|
|
|
|
else
|
|
|
|
circle->SetFilled( false );
|
2022-09-04 00:58:03 +00:00
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( circle );
|
2022-09-04 00:58:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
LIB_SYMBOL* symbol = (int) aSymbol.size() <= elem.ownerpartdisplaymode
|
|
|
|
? nullptr
|
|
|
|
: aSymbol[elem.ownerpartdisplaymode];
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SYMBOL* schsym = nullptr;
|
2022-09-04 00:58:03 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
if( !symbol )
|
2022-09-04 00:58:03 +00:00
|
|
|
{
|
2023-09-04 21:46:25 +00:00
|
|
|
const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
|
2022-09-04 00:58:03 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
|
|
|
m_reporter->Report( wxString::Format( wxT( "Ellipse's owner (%d) not found." ),
|
2023-09-04 21:46:25 +00:00
|
|
|
elem.ownerindex ),
|
2023-08-28 21:50:56 +00:00
|
|
|
RPT_SEVERITY_DEBUG );
|
|
|
|
return;
|
|
|
|
}
|
2022-09-04 00:58:03 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
symbol = libSymbolIt->second;
|
|
|
|
schsym = m_symbols.at( libSymbolIt->first );
|
|
|
|
}
|
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
VECTOR2I center = elem.Center;
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* circle = new SCH_SHAPE( SHAPE_T::CIRCLE, LAYER_DEVICE );
|
2023-08-28 21:50:56 +00:00
|
|
|
symbol->AddDrawItem( circle, false );
|
2022-09-04 00:58:03 +00:00
|
|
|
|
2024-01-30 23:06:58 +00:00
|
|
|
circle->SetUnit( std::max( 0, elem.ownerpartid ) );
|
2022-09-04 00:58:03 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
if( schsym )
|
|
|
|
center = GetRelativePosition( center + m_sheetOffset, schsym );
|
2022-09-04 00:58:03 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
circle->SetPosition( center );
|
2023-08-28 21:50:56 +00:00
|
|
|
circle->SetEnd( circle->GetPosition() + VECTOR2I( elem.Radius, 0 ) );
|
2022-09-04 00:58:03 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
SetLibShapeLine( elem, circle, ALTIUM_SCH_RECORD::ELLIPSE );
|
|
|
|
SetLibShapeFillAndColor( elem, circle, ALTIUM_SCH_RECORD::ELLIPSE, elem.Color );
|
2022-09-04 00:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 13:59:07 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseLine( const std::map<wxString, wxString>& aProperties,
|
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol )
|
2020-10-10 16:41:19 +00:00
|
|
|
{
|
|
|
|
ASCH_LINE elem( aProperties );
|
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
if( aSymbol.empty() && ShouldPutItemOnSheet( elem.ownerindex ) )
|
2020-10-10 16:41:19 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
2020-10-10 16:41:19 +00:00
|
|
|
// 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 );
|
2023-09-11 14:52:13 +00:00
|
|
|
line->SetStroke( STROKE_PARAMS( elem.LineWidth, GetPlotDashType( elem.LineStyle ),
|
|
|
|
GetColorFromInt( elem.Color ) ) );
|
2020-10-10 16:41:19 +00:00
|
|
|
|
|
|
|
line->SetFlags( IS_NEW );
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( line );
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
LIB_SYMBOL* symbol = (int) aSymbol.size() <= elem.ownerpartdisplaymode
|
|
|
|
? nullptr
|
|
|
|
: aSymbol[elem.ownerpartdisplaymode];
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SYMBOL* schsym = nullptr;
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
if( !symbol )
|
2020-10-10 16:41:19 +00:00
|
|
|
{
|
2023-09-04 21:46:25 +00:00
|
|
|
const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
|
|
|
m_reporter->Report( wxString::Format( wxT( "Line's owner (%d) not found." ),
|
2024-05-04 13:18:56 +00:00
|
|
|
elem.ownerindex ),
|
2023-08-28 21:50:56 +00:00
|
|
|
RPT_SEVERITY_DEBUG );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol = libSymbolIt->second;
|
|
|
|
schsym = m_symbols.at( libSymbolIt->first );
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
|
|
|
|
2024-02-05 19:10:26 +00:00
|
|
|
if( aSymbol.empty() && !IsComponentPartVisible( elem ) )
|
2020-10-23 15:02:56 +00:00
|
|
|
return;
|
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-08-28 21:50:56 +00:00
|
|
|
symbol->AddDrawItem( line, false );
|
2020-10-10 16:41:19 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
line->SetUnit( std::max( 0, elem.ownerpartid ) );
|
2020-10-23 15:20:07 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
if( !schsym )
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
line->AddPoint( elem.point1 );
|
|
|
|
line->AddPoint( elem.point2 );
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line->AddPoint( GetRelativePosition( elem.point1 + m_sheetOffset, schsym ) );
|
|
|
|
line->AddPoint( GetRelativePosition( elem.point2 + m_sheetOffset, schsym ) );
|
|
|
|
}
|
2020-10-10 16:41:19 +00:00
|
|
|
|
2023-09-11 14:52:13 +00:00
|
|
|
SetLibShapeLine( elem, line, ALTIUM_SCH_RECORD::LINE );
|
|
|
|
line->SetLineStyle( GetPlotDashType( elem.LineStyle ) );
|
2020-10-10 16:41:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseSignalHarness( const std::map<wxString, wxString>& aProperties )
|
2022-08-09 11:39:13 +00:00
|
|
|
{
|
|
|
|
ASCH_SIGNAL_HARNESS elem( aProperties );
|
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
if( ShouldPutItemOnSheet( elem.ownerindex ) )
|
2022-08-09 11:39:13 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
2022-08-09 11:39:13 +00:00
|
|
|
SCH_SHAPE* poly = new SCH_SHAPE( SHAPE_T::POLY );
|
|
|
|
|
2022-08-10 08:00:41 +00:00
|
|
|
for( VECTOR2I& point : elem.Points )
|
2022-08-09 11:39:13 +00:00
|
|
|
poly->AddPoint( point + m_sheetOffset );
|
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
poly->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID,
|
2022-08-10 08:00:41 +00:00
|
|
|
GetColorFromInt( elem.Color ) ) );
|
2022-08-09 11:39:13 +00:00
|
|
|
poly->SetFlags( IS_NEW );
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( poly );
|
2022-08-09 11:39:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No clue if this situation can ever exist
|
2022-10-31 14:03:35 +00:00
|
|
|
m_reporter->Report( wxT( "Signal harness, belonging to the part is not currently "
|
|
|
|
"supported." ), RPT_SEVERITY_DEBUG );
|
2022-08-09 11:39:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseHarnessConnector( int aIndex, const std::map<wxString,
|
2024-01-26 13:59:07 +00:00
|
|
|
wxString>& aProperties )
|
2022-08-09 12:00:45 +00:00
|
|
|
{
|
|
|
|
ASCH_HARNESS_CONNECTOR elem( aProperties );
|
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
if( ShouldPutItemOnSheet( elem.ownerindex ) )
|
2022-08-09 12:00:45 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SCREEN* currentScreen = getCurrentScreen();
|
|
|
|
wxCHECK( currentScreen, /* void */ );
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SHEET* sheet = new SCH_SHEET( getCurrentSheet(), elem.Location + m_sheetOffset,
|
|
|
|
elem.Size );
|
2022-08-09 12:00:45 +00:00
|
|
|
|
2022-12-06 01:18:05 +00:00
|
|
|
sheet->SetScreen( new SCH_SCREEN( m_schematic ) );
|
2022-10-31 14:03:35 +00:00
|
|
|
sheet->SetBackgroundColor( GetColorFromInt( elem.AreaColor ) );
|
|
|
|
sheet->SetBorderColor( GetColorFromInt( elem.Color ) );
|
2022-08-09 12:00:45 +00:00
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
currentScreen->Append( sheet );
|
2022-08-09 12:00:45 +00:00
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SHEET_PATH sheetpath = m_sheetPath;
|
|
|
|
sheetpath.push_back( sheet );
|
2022-08-09 12:00:45 +00:00
|
|
|
|
2022-11-22 19:35:27 +00:00
|
|
|
sheetpath.SetPageNumber( "Harness #" );
|
2022-08-09 12:00:45 +00:00
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
m_harnessEntryParent = aIndex + m_harnessOwnerIndexOffset;
|
|
|
|
m_sheets.insert( { m_harnessEntryParent, sheet } );
|
2022-08-09 12:00:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// I have no clue if this situation can ever exist
|
2022-10-31 14:03:35 +00:00
|
|
|
m_reporter->Report( wxT( "Harness connector, belonging to the part is not currently "
|
|
|
|
"supported." ),
|
|
|
|
RPT_SEVERITY_DEBUG );
|
2022-08-09 12:00:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseHarnessEntry( const std::map<wxString, wxString>& aProperties )
|
2022-08-09 12:15:42 +00:00
|
|
|
{
|
|
|
|
ASCH_HARNESS_ENTRY elem( aProperties );
|
|
|
|
|
|
|
|
const auto& sheetIt = m_sheets.find( m_harnessEntryParent );
|
|
|
|
|
|
|
|
if( sheetIt == m_sheets.end() )
|
|
|
|
{
|
2022-09-08 17:11:52 +00:00
|
|
|
m_reporter->Report( wxString::Format( wxT( "Harness entry's parent (%d) not found." ),
|
2023-12-24 00:31:24 +00:00
|
|
|
SCH_IO_ALTIUM::m_harnessEntryParent ),
|
2022-10-31 14:03:35 +00:00
|
|
|
RPT_SEVERITY_DEBUG );
|
2022-08-09 12:15:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_SHEET_PIN* sheetPin = new SCH_SHEET_PIN( sheetIt->second );
|
|
|
|
sheetIt->second->AddPin( sheetPin );
|
|
|
|
|
2022-08-10 08:00:41 +00:00
|
|
|
sheetPin->SetText( elem.Name );
|
2022-08-09 12:15:42 +00:00
|
|
|
sheetPin->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
|
|
|
|
|
|
|
|
VECTOR2I pos = sheetIt->second->GetPosition();
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I size = sheetIt->second->GetSize();
|
2022-08-09 12:15:42 +00:00
|
|
|
|
2022-08-10 08:00:41 +00:00
|
|
|
switch( elem.Side )
|
2022-08-09 12:15:42 +00:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case ASCH_SHEET_ENTRY_SIDE::LEFT:
|
2022-08-10 08:00:41 +00:00
|
|
|
sheetPin->SetPosition( { pos.x, pos.y + elem.DistanceFromTop } );
|
2023-09-07 16:09:53 +00:00
|
|
|
sheetPin->SetSpinStyle( SPIN_STYLE::LEFT );
|
2022-08-09 12:15:42 +00:00
|
|
|
sheetPin->SetSide( SHEET_SIDE::LEFT );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_ENTRY_SIDE::RIGHT:
|
2022-08-10 08:00:41 +00:00
|
|
|
sheetPin->SetPosition( { pos.x + size.x, pos.y + elem.DistanceFromTop } );
|
2023-09-07 16:09:53 +00:00
|
|
|
sheetPin->SetSpinStyle( SPIN_STYLE::RIGHT );
|
2022-08-09 12:15:42 +00:00
|
|
|
sheetPin->SetSide( SHEET_SIDE::RIGHT );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_ENTRY_SIDE::TOP:
|
2022-08-10 08:00:41 +00:00
|
|
|
sheetPin->SetPosition( { pos.x + elem.DistanceFromTop, pos.y } );
|
2023-09-07 16:09:53 +00:00
|
|
|
sheetPin->SetSpinStyle( SPIN_STYLE::UP );
|
2022-08-09 12:15:42 +00:00
|
|
|
sheetPin->SetSide( SHEET_SIDE::TOP );
|
|
|
|
break;
|
|
|
|
case ASCH_SHEET_ENTRY_SIDE::BOTTOM:
|
2022-08-10 08:00:41 +00:00
|
|
|
sheetPin->SetPosition( { pos.x + elem.DistanceFromTop, pos.y + size.y } );
|
2023-09-07 16:09:53 +00:00
|
|
|
sheetPin->SetSpinStyle( SPIN_STYLE::BOTTOM );
|
2022-08-09 12:15:42 +00:00
|
|
|
sheetPin->SetSide( SHEET_SIDE::BOTTOM );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseHarnessType( const std::map<wxString, wxString>& aProperties )
|
2022-08-09 12:32:41 +00:00
|
|
|
{
|
|
|
|
ASCH_HARNESS_TYPE elem( aProperties );
|
|
|
|
|
|
|
|
const auto& sheetIt = m_sheets.find( m_harnessEntryParent );
|
|
|
|
|
|
|
|
if( sheetIt == m_sheets.end() )
|
|
|
|
{
|
2022-09-08 17:11:52 +00:00
|
|
|
m_reporter->Report( wxString::Format( wxT( "Harness type's parent (%d) not found." ),
|
2022-08-09 12:32:41 +00:00
|
|
|
m_harnessEntryParent ),
|
2022-10-31 14:03:35 +00:00
|
|
|
RPT_SEVERITY_DEBUG );
|
2022-08-09 12:32:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_FIELD& sheetNameField = sheetIt->second->GetFields()[SHEETNAME];
|
|
|
|
|
2022-08-10 08:00:41 +00:00
|
|
|
sheetNameField.SetPosition( elem.Location + m_sheetOffset );
|
|
|
|
sheetNameField.SetText( elem.Text );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
|
|
|
// Always set as visible so user is aware about ( !elem.isHidden );
|
|
|
|
sheetNameField.SetVisible( true );
|
|
|
|
SetTextPositioning( &sheetNameField, ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT,
|
|
|
|
ASCH_RECORD_ORIENTATION::RIGHTWARDS );
|
2022-08-10 08:00:41 +00:00
|
|
|
sheetNameField.SetTextColor( GetColorFromInt( elem.Color ) );
|
2022-08-09 12:32:41 +00:00
|
|
|
|
2022-12-06 01:18:05 +00:00
|
|
|
SCH_FIELD& sheetFileName = sheetIt->second->GetFields()[SHEETFILENAME];
|
2023-12-28 02:10:01 +00:00
|
|
|
sheetFileName.SetText( elem.Text + wxT( "." ) + FILEEXT::KiCadSchematicFileExtension );
|
2022-12-06 01:18:05 +00:00
|
|
|
|
2023-12-28 02:10:01 +00:00
|
|
|
wxFileName fn( m_schematic->Prj().GetProjectPath(), elem.Text,
|
|
|
|
FILEEXT::KiCadSchematicFileExtension );
|
2022-12-06 01:18:05 +00:00
|
|
|
wxString fullPath = fn.GetFullPath();
|
|
|
|
|
|
|
|
fullPath.Replace( wxT( "\\" ), wxT( "/" ) );
|
|
|
|
|
|
|
|
SCH_SCREEN* screen = sheetIt->second->GetScreen();
|
|
|
|
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
screen->SetFileName( fullPath );
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Altium's harness connector (%s) was imported as a "
|
|
|
|
"hierarchical sheet. Please review the imported "
|
|
|
|
"schematic." ),
|
|
|
|
elem.Text ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
2022-08-09 12:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseRectangle( const std::map<wxString, wxString>& aProperties,
|
2024-01-26 13:59:07 +00:00
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol )
|
2020-10-10 14:22:53 +00:00
|
|
|
{
|
|
|
|
ASCH_RECTANGLE elem( aProperties );
|
|
|
|
|
2022-09-03 22:38:41 +00:00
|
|
|
VECTOR2I sheetTopRight = elem.TopRight + m_sheetOffset;
|
|
|
|
VECTOR2I sheetBottomLeft = elem.BottomLeft + m_sheetOffset;
|
2020-10-17 13:35:22 +00:00
|
|
|
|
2024-01-31 03:59:57 +00:00
|
|
|
if( aSymbol.empty() && ShouldPutItemOnSheet( elem.ownerindex ) )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
SCH_SHAPE* rect = new SCH_SHAPE( SHAPE_T::RECTANGLE );
|
2021-12-27 15:50:30 +00:00
|
|
|
|
|
|
|
rect->SetPosition( sheetTopRight );
|
|
|
|
rect->SetEnd( sheetBottomLeft );
|
2023-08-28 21:50:56 +00:00
|
|
|
SetSchShapeLine( elem, rect );
|
2021-12-27 15:50:30 +00:00
|
|
|
SetSchShapeFillAndColor( elem, rect );
|
|
|
|
rect->SetFlags( IS_NEW );
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( rect );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
LIB_SYMBOL* symbol = (int) aSymbol.size() <= elem.ownerpartdisplaymode
|
|
|
|
? nullptr
|
|
|
|
: aSymbol[elem.ownerpartdisplaymode];
|
2023-08-28 21:50:56 +00:00
|
|
|
SCH_SYMBOL* schsym = nullptr;
|
2020-11-05 23:19:47 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
if( !symbol )
|
2020-10-10 14:22:53 +00:00
|
|
|
{
|
2023-09-04 21:46:25 +00:00
|
|
|
const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
|
|
|
m_reporter->Report( wxString::Format( wxT( "Rectangle's owner (%d) not found." ),
|
2023-09-04 21:46:25 +00:00
|
|
|
elem.ownerindex ),
|
2023-08-28 21:50:56 +00:00
|
|
|
RPT_SEVERITY_DEBUG );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol = libSymbolIt->second;
|
|
|
|
schsym = m_symbols.at( libSymbolIt->first );
|
2020-10-10 14:22:53 +00:00
|
|
|
}
|
|
|
|
|
2024-02-05 19:10:26 +00:00
|
|
|
if( aSymbol.empty() && !IsComponentPartVisible( elem ) )
|
2020-10-23 15:02:56 +00:00
|
|
|
return;
|
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* rect = new SCH_SHAPE( SHAPE_T::RECTANGLE, LAYER_DEVICE );
|
2023-08-28 21:50:56 +00:00
|
|
|
symbol->AddDrawItem( rect, false );
|
2020-10-23 15:20:07 +00:00
|
|
|
|
2024-01-30 23:06:58 +00:00
|
|
|
rect->SetUnit( std::max( 0, elem.ownerpartid ) );
|
2020-10-23 15:20:07 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
if( !schsym )
|
|
|
|
{
|
2024-05-04 13:18:56 +00:00
|
|
|
rect->SetPosition( sheetTopRight );
|
|
|
|
rect->SetEnd( sheetBottomLeft );
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rect->SetPosition( GetRelativePosition( sheetTopRight, schsym ) );
|
|
|
|
rect->SetEnd( GetRelativePosition( sheetBottomLeft, schsym ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLibShapeLine( elem, rect, ALTIUM_SCH_RECORD::RECTANGLE );
|
|
|
|
SetLibShapeFillAndColor( elem, rect, ALTIUM_SCH_RECORD::RECTANGLE, elem.Color );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseSheetSymbol( int aIndex, const std::map<wxString, wxString>& aProperties )
|
2020-10-27 14:51:19 +00:00
|
|
|
{
|
|
|
|
ASCH_SHEET_SYMBOL elem( aProperties );
|
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
SCH_SHEET* sheet = new SCH_SHEET( getCurrentSheet(), elem.location + m_sheetOffset, elem.size );
|
2020-10-27 14:51:19 +00:00
|
|
|
|
|
|
|
sheet->SetBorderColor( GetColorFromInt( elem.color ) );
|
2021-07-07 17:30:36 +00:00
|
|
|
|
2020-10-27 14:51:19 +00:00
|
|
|
if( elem.isSolid )
|
|
|
|
sheet->SetBackgroundColor( GetColorFromInt( elem.areacolor ) );
|
|
|
|
|
|
|
|
sheet->SetFlags( IS_NEW );
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SCREEN* currentScreen = getCurrentScreen();
|
|
|
|
wxCHECK( currentScreen, /* void */ );
|
|
|
|
currentScreen->Append( sheet );
|
|
|
|
|
|
|
|
SCH_SHEET_PATH sheetpath = m_sheetPath;
|
2021-07-07 17:30:59 +00:00
|
|
|
sheetpath.push_back( sheet );
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
// We'll update later if we find a pageNumber record for it.
|
|
|
|
sheetpath.SetPageNumber( "#" );
|
|
|
|
|
|
|
|
SCH_SCREEN* rootScreen = m_rootSheet->GetScreen();
|
|
|
|
wxCHECK( rootScreen, /* void */ );
|
|
|
|
|
|
|
|
SCH_SHEET_INSTANCE sheetInstance;
|
|
|
|
|
|
|
|
sheetInstance.m_Path = sheetpath.Path();
|
|
|
|
sheetInstance.m_PageNumber = wxT( "#" );
|
|
|
|
|
|
|
|
rootScreen->m_sheetInstances.emplace_back( sheetInstance );
|
2020-10-27 14:51:19 +00:00
|
|
|
m_sheets.insert( { aIndex, sheet } );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseSheetEntry( const std::map<wxString, wxString>& aProperties )
|
2020-10-27 14:51:19 +00:00
|
|
|
{
|
|
|
|
ASCH_SHEET_ENTRY elem( aProperties );
|
|
|
|
|
2021-07-07 17:30:36 +00:00
|
|
|
const auto& sheetIt = m_sheets.find( elem.ownerindex );
|
2021-06-26 19:21:30 +00:00
|
|
|
|
2021-07-07 17:30:36 +00:00
|
|
|
if( sheetIt == m_sheets.end() )
|
2020-10-27 14:51:19 +00:00
|
|
|
{
|
2022-09-08 17:11:52 +00:00
|
|
|
m_reporter->Report( wxString::Format( wxT( "Sheet entry's owner (%d) not found." ),
|
2021-07-07 11:25:01 +00:00
|
|
|
elem.ownerindex ),
|
2022-10-31 14:03:35 +00:00
|
|
|
RPT_SEVERITY_DEBUG );
|
2020-10-27 14:51:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-07 17:30:36 +00:00
|
|
|
SCH_SHEET_PIN* sheetPin = new SCH_SHEET_PIN( sheetIt->second );
|
|
|
|
sheetIt->second->AddPin( sheetPin );
|
2020-10-27 14:51:19 +00:00
|
|
|
|
|
|
|
sheetPin->SetText( elem.name );
|
2021-10-12 20:05:37 +00:00
|
|
|
sheetPin->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
|
2023-09-07 16:09:53 +00:00
|
|
|
//sheetPin->SetSpinStyle( getSpinStyle( term.OrientAngle, false ) );
|
2020-10-27 14:51:19 +00:00
|
|
|
//sheetPin->SetPosition( getKiCadPoint( term.Position ) );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos = sheetIt->second->GetPosition();
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I size = sheetIt->second->GetSize();
|
2020-10-27 14:51:19 +00:00
|
|
|
|
|
|
|
switch( elem.side )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case ASCH_SHEET_ENTRY_SIDE::LEFT:
|
|
|
|
sheetPin->SetPosition( { pos.x, pos.y + elem.distanceFromTop } );
|
2023-09-07 16:09:53 +00:00
|
|
|
sheetPin->SetSpinStyle( SPIN_STYLE::LEFT );
|
2021-11-28 19:06:08 +00:00
|
|
|
sheetPin->SetSide( SHEET_SIDE::LEFT );
|
2020-10-27 14:51:19 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-27 14:51:19 +00:00
|
|
|
case ASCH_SHEET_ENTRY_SIDE::RIGHT:
|
|
|
|
sheetPin->SetPosition( { pos.x + size.x, pos.y + elem.distanceFromTop } );
|
2023-09-07 16:09:53 +00:00
|
|
|
sheetPin->SetSpinStyle( SPIN_STYLE::RIGHT );
|
2021-11-28 19:06:08 +00:00
|
|
|
sheetPin->SetSide( SHEET_SIDE::RIGHT );
|
2020-10-27 14:51:19 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-27 14:51:19 +00:00
|
|
|
case ASCH_SHEET_ENTRY_SIDE::TOP:
|
|
|
|
sheetPin->SetPosition( { pos.x + elem.distanceFromTop, pos.y } );
|
2023-09-07 16:09:53 +00:00
|
|
|
sheetPin->SetSpinStyle( SPIN_STYLE::UP );
|
2021-11-28 19:06:08 +00:00
|
|
|
sheetPin->SetSide( SHEET_SIDE::TOP );
|
2020-10-27 14:51:19 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-27 14:51:19 +00:00
|
|
|
case ASCH_SHEET_ENTRY_SIDE::BOTTOM:
|
|
|
|
sheetPin->SetPosition( { pos.x + elem.distanceFromTop, pos.y + size.y } );
|
2023-09-07 16:09:53 +00:00
|
|
|
sheetPin->SetSpinStyle( SPIN_STYLE::BOTTOM );
|
2021-11-28 19:06:08 +00:00
|
|
|
sheetPin->SetSide( SHEET_SIDE::BOTTOM );
|
2020-10-27 14:51:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( elem.iotype )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case ASCH_PORT_IOTYPE::UNSPECIFIED:
|
2021-10-12 20:05:37 +00:00
|
|
|
sheetPin->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
|
2020-10-27 14:51:19 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-27 14:51:19 +00:00
|
|
|
case ASCH_PORT_IOTYPE::OUTPUT:
|
2021-10-12 20:05:37 +00:00
|
|
|
sheetPin->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
|
2020-10-27 14:51:19 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-27 14:51:19 +00:00
|
|
|
case ASCH_PORT_IOTYPE::INPUT:
|
2021-10-12 20:05:37 +00:00
|
|
|
sheetPin->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
|
2020-10-27 14:51:19 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-27 14:51:19 +00:00
|
|
|
case ASCH_PORT_IOTYPE::BIDI:
|
2021-10-12 20:05:37 +00:00
|
|
|
sheetPin->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
|
2020-10-27 14:51:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I HelperGeneratePowerPortGraphics( LIB_SYMBOL* aKsymbol, ASCH_POWER_PORT_STYLE aStyle,
|
2022-10-31 14:03:35 +00:00
|
|
|
REPORTER* aReporter )
|
2020-10-24 16:40:16 +00:00
|
|
|
{
|
|
|
|
if( aStyle == ASCH_POWER_PORT_STYLE::CIRCLE || aStyle == ASCH_POWER_PORT_STYLE::ARROW )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line1 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line1->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2020-10-24 16:40:16 +00:00
|
|
|
line1->AddPoint( { 0, 0 } );
|
2024-05-04 13:18:56 +00:00
|
|
|
line1->AddPoint( { 0, schIUScale.MilsToIU( 50 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line1, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
|
|
|
if( aStyle == ASCH_POWER_PORT_STYLE::CIRCLE )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* circle = new SCH_SHAPE( SHAPE_T::CIRCLE, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
circle->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 5 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
circle->SetPosition( { schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 75 ) } );
|
2022-09-16 23:42:20 +00:00
|
|
|
circle->SetEnd( circle->GetPosition() + VECTOR2I( schIUScale.MilsToIU( 25 ), 0 ) );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( circle, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line2 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( -25 ), schIUScale.MilsToIU( 50 ) } );
|
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( 25 ), schIUScale.MilsToIU( 50 ) } );
|
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 100 ) } );
|
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( -25 ), schIUScale.MilsToIU( 50 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line2, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
}
|
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
return { 0, schIUScale.MilsToIU( 150 ) };
|
2020-10-24 16:40:16 +00:00
|
|
|
}
|
|
|
|
else if( aStyle == ASCH_POWER_PORT_STYLE::WAVE )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2020-10-24 16:40:16 +00:00
|
|
|
line->AddPoint( { 0, 0 } );
|
2024-05-04 13:18:56 +00:00
|
|
|
line->AddPoint( { 0, schIUScale.MilsToIU( 72 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* bezier = new SCH_SHAPE( SHAPE_T::BEZIER, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
bezier->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 5 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
bezier->SetStart( { schIUScale.MilsToIU( 30 ), schIUScale.MilsToIU( 50 ) } );
|
|
|
|
bezier->SetBezierC1( { schIUScale.MilsToIU( 30 ), schIUScale.MilsToIU( 87 ) } );
|
|
|
|
bezier->SetBezierC2( { schIUScale.MilsToIU( -30 ), schIUScale.MilsToIU( 63 ) } );
|
|
|
|
bezier->SetEnd( { schIUScale.MilsToIU( -30 ), schIUScale.MilsToIU( 100 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( bezier, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
return { 0, schIUScale.MilsToIU( 150 ) };
|
2020-10-24 16:40:16 +00:00
|
|
|
}
|
|
|
|
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 )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line1 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line1->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2020-10-24 16:40:16 +00:00
|
|
|
line1->AddPoint( { 0, 0 } );
|
2024-05-04 13:18:56 +00:00
|
|
|
line1->AddPoint( { 0, schIUScale.MilsToIU( 100 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line1, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
|
|
|
if( aStyle == ASCH_POWER_PORT_STYLE::POWER_GROUND )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line2 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( -100 ), schIUScale.MilsToIU( 100 ) } );
|
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( 100 ), schIUScale.MilsToIU( 100 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line2, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line3 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line3->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
line3->AddPoint( { schIUScale.MilsToIU( -70 ), schIUScale.MilsToIU( 130 ) } );
|
|
|
|
line3->AddPoint( { schIUScale.MilsToIU( 70 ), schIUScale.MilsToIU( 130 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line3, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line4 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line4->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
line4->AddPoint( { schIUScale.MilsToIU( -40 ), schIUScale.MilsToIU( 160 ) } );
|
|
|
|
line4->AddPoint( { schIUScale.MilsToIU( 40 ), schIUScale.MilsToIU( 160 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line4, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line5 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line5->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
line5->AddPoint( { schIUScale.MilsToIU( -10 ), schIUScale.MilsToIU( 190 ) } );
|
|
|
|
line5->AddPoint( { schIUScale.MilsToIU( 10 ), schIUScale.MilsToIU( 190 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line5, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
}
|
|
|
|
else if( aStyle == ASCH_POWER_PORT_STYLE::SIGNAL_GROUND )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line2 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( -100 ), schIUScale.MilsToIU( 100 ) } );
|
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( 100 ), schIUScale.MilsToIU( 100 ) } );
|
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 200 ) } );
|
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( -100 ), schIUScale.MilsToIU( 100 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line2, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
}
|
|
|
|
else if( aStyle == ASCH_POWER_PORT_STYLE::EARTH )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line2 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( -150 ), schIUScale.MilsToIU( 200 ) } );
|
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( -100 ), schIUScale.MilsToIU( 100 ) } );
|
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( 100 ), schIUScale.MilsToIU( 100 ) } );
|
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( 50 ), schIUScale.MilsToIU( 200 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line2, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line3 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line3->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
line3->AddPoint( { schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 100 ) } );
|
|
|
|
line3->AddPoint( { schIUScale.MilsToIU( -50 ), schIUScale.MilsToIU( 200 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line3, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
}
|
|
|
|
else // ASCH_POWER_PORT_STYLE::GOST_ARROW
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line2 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( -25 ), schIUScale.MilsToIU( 50 ) } );
|
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 100 ) } );
|
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( 25 ), schIUScale.MilsToIU( 50 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line2, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
return { 0, schIUScale.MilsToIU( 150 ) }; // special case
|
2020-10-24 16:40:16 +00:00
|
|
|
}
|
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
return { 0, schIUScale.MilsToIU( 250 ) };
|
2020-10-24 16:40:16 +00:00
|
|
|
}
|
|
|
|
else if( aStyle == ASCH_POWER_PORT_STYLE::GOST_POWER_GROUND
|
|
|
|
|| aStyle == ASCH_POWER_PORT_STYLE::GOST_EARTH )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line1 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line1->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2020-10-24 16:40:16 +00:00
|
|
|
line1->AddPoint( { 0, 0 } );
|
2024-05-04 13:18:56 +00:00
|
|
|
line1->AddPoint( { 0, schIUScale.MilsToIU( 160 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line1, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line2 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( -100 ), schIUScale.MilsToIU( 160 ) } );
|
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( 100 ), schIUScale.MilsToIU( 160 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line2, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line3 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line3->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
line3->AddPoint( { schIUScale.MilsToIU( -60 ), schIUScale.MilsToIU( 200 ) } );
|
|
|
|
line3->AddPoint( { schIUScale.MilsToIU( 60 ), schIUScale.MilsToIU( 200 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line3, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line4 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line4->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
line4->AddPoint( { schIUScale.MilsToIU( -20 ), schIUScale.MilsToIU( 240 ) } );
|
|
|
|
line4->AddPoint( { schIUScale.MilsToIU( 20 ), schIUScale.MilsToIU( 240 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line4, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
|
|
|
if( aStyle == ASCH_POWER_PORT_STYLE::GOST_POWER_GROUND )
|
2024-05-04 13:18:56 +00:00
|
|
|
return { 0, schIUScale.MilsToIU( -300 ) };
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* circle = new SCH_SHAPE( SHAPE_T::CIRCLE, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
circle->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
circle->SetPosition( { schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 160 ) } );
|
2022-09-16 23:42:20 +00:00
|
|
|
circle->SetEnd( circle->GetPosition() + VECTOR2I( schIUScale.MilsToIU( 120 ), 0 ) );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( circle, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
return { 0, schIUScale.MilsToIU( 350 ) };
|
2020-10-24 16:40:16 +00:00
|
|
|
}
|
|
|
|
else if( aStyle == ASCH_POWER_PORT_STYLE::GOST_BAR )
|
|
|
|
{
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line1 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line1->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2020-10-24 16:40:16 +00:00
|
|
|
line1->AddPoint( { 0, 0 } );
|
2024-05-04 13:18:56 +00:00
|
|
|
line1->AddPoint( { 0, schIUScale.MilsToIU( 200 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line1, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line2 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( -100 ), schIUScale.MilsToIU( 200 ) } );
|
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( 100 ), schIUScale.MilsToIU( 200 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line2, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
return { 0, schIUScale.MilsToIU( 250 ) };
|
2020-10-24 16:40:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aStyle != ASCH_POWER_PORT_STYLE::BAR )
|
2021-03-31 21:33:30 +00:00
|
|
|
{
|
2022-09-08 17:11:52 +00:00
|
|
|
aReporter->Report( _( "Power Port with unknown style imported as 'Bar' type." ),
|
2021-03-31 21:33:30 +00:00
|
|
|
RPT_SEVERITY_WARNING );
|
|
|
|
}
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line1 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line1->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2020-10-24 16:40:16 +00:00
|
|
|
line1->AddPoint( { 0, 0 } );
|
2024-05-04 13:18:56 +00:00
|
|
|
line1->AddPoint( { 0, schIUScale.MilsToIU( 100 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line1, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* line2 = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
|
2023-11-25 13:05:45 +00:00
|
|
|
line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
|
2024-05-04 13:18:56 +00:00
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( -50 ), schIUScale.MilsToIU( 100 ) } );
|
|
|
|
line2->AddPoint( { schIUScale.MilsToIU( 50 ), schIUScale.MilsToIU( 100 ) } );
|
2024-05-02 22:44:48 +00:00
|
|
|
aKsymbol->AddDrawItem( line2, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
return { 0, schIUScale.MilsToIU( 150 ) };
|
2020-10-24 16:40:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParsePowerPort( const std::map<wxString, wxString>& aProperties )
|
2020-10-24 16:40:16 +00:00
|
|
|
{
|
|
|
|
ASCH_POWER_PORT elem( aProperties );
|
|
|
|
|
2024-01-31 05:22:20 +00:00
|
|
|
wxString symName( elem.text );
|
|
|
|
std::string styleName( magic_enum::enum_name<ASCH_POWER_PORT_STYLE>( elem.style ) );
|
|
|
|
|
|
|
|
if( !styleName.empty() )
|
|
|
|
symName << '_' << styleName;
|
|
|
|
|
|
|
|
LIB_ID libId = AltiumToKiCadLibID( getLibName(), symName );
|
|
|
|
LIB_SYMBOL* libSymbol = nullptr;
|
|
|
|
|
|
|
|
const auto& powerSymbolIt = m_powerSymbols.find( symName );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2021-07-05 09:51:15 +00:00
|
|
|
if( powerSymbolIt != m_powerSymbols.end() )
|
2020-10-24 16:40:16 +00:00
|
|
|
{
|
2021-07-05 09:51:15 +00:00
|
|
|
libSymbol = powerSymbolIt->second; // cache hit
|
2020-10-24 16:40:16 +00:00
|
|
|
}
|
2024-05-04 13:18:56 +00:00
|
|
|
else if( LIB_SYMBOL* alreadyLoaded = m_pi->LoadSymbol( getLibFileName().GetFullPath(),
|
|
|
|
elem.text, m_properties.get() ) )
|
2024-02-25 13:46:45 +00:00
|
|
|
{
|
|
|
|
libSymbol = alreadyLoaded;
|
|
|
|
}
|
2020-10-24 16:40:16 +00:00
|
|
|
else
|
|
|
|
{
|
2021-07-05 09:51:15 +00:00
|
|
|
libSymbol = new LIB_SYMBOL( wxEmptyString );
|
|
|
|
libSymbol->SetPower();
|
|
|
|
libSymbol->SetName( elem.text );
|
|
|
|
libSymbol->GetReferenceField().SetText( "#PWR" );
|
|
|
|
libSymbol->GetValueField().SetText( elem.text );
|
2021-07-24 20:28:24 +00:00
|
|
|
libSymbol->GetValueField().SetVisible( true );
|
2021-07-07 16:53:30 +00:00
|
|
|
libSymbol->SetDescription( wxString::Format( _( "Power symbol creates a global "
|
2021-07-05 09:51:15 +00:00
|
|
|
"label with name '%s'" ), elem.text ) );
|
|
|
|
libSymbol->SetKeyWords( "power-flag" );
|
|
|
|
libSymbol->SetLibId( libId );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
|
|
|
// generate graphic
|
2024-04-20 09:44:34 +00:00
|
|
|
SCH_PIN* pin = new SCH_PIN( libSymbol );
|
2023-08-28 21:50:56 +00:00
|
|
|
libSymbol->AddDrawItem( pin, false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
|
|
|
pin->SetName( elem.text );
|
|
|
|
pin->SetPosition( { 0, 0 } );
|
|
|
|
pin->SetLength( 0 );
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
|
2023-09-11 07:02:43 +00:00
|
|
|
pin->SetVisible( false );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2024-02-21 13:05:18 +00:00
|
|
|
VECTOR2I valueFieldPos = HelperGeneratePowerPortGraphics( libSymbol, elem.style,
|
|
|
|
m_reporter );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2021-07-05 09:51:15 +00:00
|
|
|
libSymbol->GetValueField().SetPosition( valueFieldPos );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// this has to be done after parsing the LIB_SYMBOL!
|
2021-07-05 09:51:15 +00:00
|
|
|
m_pi->SaveSymbol( getLibFileName().GetFullPath(), libSymbol, m_properties.get() );
|
2024-01-31 05:22:20 +00:00
|
|
|
m_powerSymbols.insert( { symName, libSymbol } );
|
2020-10-24 16:40:16 +00:00
|
|
|
}
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2021-07-05 09:51:15 +00:00
|
|
|
// each symbol has its own powerSymbolIt for now
|
|
|
|
SCH_SYMBOL* symbol = new SCH_SYMBOL();
|
2022-10-31 14:03:35 +00:00
|
|
|
symbol->SetRef( &m_sheetPath, "#PWR?" );
|
2022-11-25 14:25:39 +00:00
|
|
|
symbol->SetValueFieldText( elem.text );
|
2021-07-05 09:51:15 +00:00
|
|
|
symbol->SetLibId( libId );
|
|
|
|
symbol->SetLibSymbol( new LIB_SYMBOL( *libSymbol ) );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2021-07-05 09:51:15 +00:00
|
|
|
SCH_FIELD* valueField = symbol->GetField( VALUE_FIELD );
|
2021-07-24 20:28:24 +00:00
|
|
|
valueField->SetVisible( elem.showNetName );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2021-07-24 20:28:24 +00:00
|
|
|
// TODO: Why do I need to set this a second time?
|
2021-07-05 09:51:15 +00:00
|
|
|
valueField->SetPosition( libSymbol->GetValueField().GetPosition() );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
2021-07-05 09:51:15 +00:00
|
|
|
symbol->SetPosition( elem.location + m_sheetOffset );
|
2020-10-24 16:40:16 +00:00
|
|
|
|
|
|
|
switch( elem.orientation )
|
|
|
|
{
|
|
|
|
case ASCH_RECORD_ORIENTATION::RIGHTWARDS:
|
2021-07-05 09:51:15 +00:00
|
|
|
symbol->SetOrientation( SYMBOL_ORIENTATION_T::SYM_ORIENT_90 );
|
2022-01-13 12:29:46 +00:00
|
|
|
valueField->SetTextAngle( ANGLE_VERTICAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
valueField->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2020-10-24 16:40:16 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-24 16:40:16 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::UPWARDS:
|
2021-07-05 09:51:15 +00:00
|
|
|
symbol->SetOrientation( SYMBOL_ORIENTATION_T::SYM_ORIENT_180 );
|
2022-01-13 12:29:46 +00:00
|
|
|
valueField->SetTextAngle( ANGLE_HORIZONTAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
valueField->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
2020-10-24 16:40:16 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-24 16:40:16 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::LEFTWARDS:
|
2021-07-05 09:51:15 +00:00
|
|
|
symbol->SetOrientation( SYMBOL_ORIENTATION_T::SYM_ORIENT_270 );
|
2022-01-13 12:29:46 +00:00
|
|
|
valueField->SetTextAngle( ANGLE_VERTICAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
valueField->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2020-10-24 16:40:16 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-24 16:40:16 +00:00
|
|
|
case ASCH_RECORD_ORIENTATION::DOWNWARDS:
|
2021-07-05 09:51:15 +00:00
|
|
|
symbol->SetOrientation( SYMBOL_ORIENTATION_T::SYM_ORIENT_0 );
|
2022-01-13 12:29:46 +00:00
|
|
|
valueField->SetTextAngle( ANGLE_HORIZONTAL );
|
2021-12-28 22:13:54 +00:00
|
|
|
valueField->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
2020-10-24 16:40:16 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-24 16:40:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( symbol );
|
2020-10-24 16:40:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseHarnessPort( const ASCH_PORT& aElem )
|
2022-08-09 19:21:36 +00:00
|
|
|
{
|
|
|
|
SCH_TEXTBOX* textBox = new SCH_TEXTBOX();
|
|
|
|
|
2022-08-10 08:00:41 +00:00
|
|
|
textBox->SetText( aElem.Name );
|
|
|
|
textBox->SetTextColor( GetColorFromInt( aElem.TextColor ) );
|
2022-08-09 19:21:36 +00:00
|
|
|
|
2022-08-10 08:00:41 +00:00
|
|
|
int height = aElem.Height;
|
2022-08-09 19:21:36 +00:00
|
|
|
if( height <= 0 )
|
2022-09-16 23:42:20 +00:00
|
|
|
height = schIUScale.MilsToIU( 100 ); // chose default 50 grid
|
2022-08-09 19:21:36 +00:00
|
|
|
|
2022-08-10 08:00:41 +00:00
|
|
|
textBox->SetStartX( ( aElem.Location + m_sheetOffset ).x );
|
|
|
|
textBox->SetStartY( ( aElem.Location + m_sheetOffset ).y - ( height / 2 ) );
|
|
|
|
textBox->SetEndX( ( aElem.Location + m_sheetOffset ).x + ( aElem.Width ) );
|
|
|
|
textBox->SetEndY( ( aElem.Location + m_sheetOffset ).y + ( height / 2 ) );
|
2022-08-09 19:21:36 +00:00
|
|
|
|
2022-09-03 21:15:54 +00:00
|
|
|
textBox->SetFillColor( HARNESS_PORT_COLOR_DEFAULT_BACKGROUND );
|
2022-08-19 16:47:22 +00:00
|
|
|
textBox->SetFillMode( FILL_T::FILLED_WITH_COLOR );
|
2022-08-09 19:21:36 +00:00
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
textBox->SetStroke( STROKE_PARAMS( 2, LINE_STYLE::DEFAULT,
|
2022-10-31 14:03:35 +00:00
|
|
|
HARNESS_PORT_COLOR_DEFAULT_OUTLINE ) );
|
2022-08-09 19:21:36 +00:00
|
|
|
|
2022-08-10 08:00:41 +00:00
|
|
|
switch( aElem.Alignment )
|
2022-08-09 19:21:36 +00:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case ASCH_TEXT_FRAME_ALIGNMENT::LEFT:
|
|
|
|
textBox->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2022-08-09 19:21:36 +00:00
|
|
|
case ASCH_TEXT_FRAME_ALIGNMENT::CENTER:
|
|
|
|
textBox->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2022-08-09 19:21:36 +00:00
|
|
|
case ASCH_TEXT_FRAME_ALIGNMENT::RIGHT:
|
|
|
|
textBox->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-08-10 08:00:41 +00:00
|
|
|
size_t fontId = static_cast<int>( aElem.FontID );
|
2022-08-09 19:21:36 +00:00
|
|
|
|
|
|
|
if( m_altiumSheet && fontId > 0 && fontId <= m_altiumSheet->fonts.size() )
|
|
|
|
{
|
|
|
|
const ASCH_SHEET_FONT& font = m_altiumSheet->fonts.at( fontId - 1 );
|
2022-08-10 08:00:41 +00:00
|
|
|
textBox->SetTextSize( { font.Size / 2, font.Size / 2 } );
|
2024-02-25 17:28:05 +00:00
|
|
|
|
|
|
|
// Must come after SetTextSize()
|
|
|
|
textBox->SetBold( font.Bold );
|
|
|
|
textBox->SetItalic( font.Italic );
|
|
|
|
//textBox->SetFont( //how to set font, we have a font name here: ( font.fontname );
|
2022-08-09 19:21:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
textBox->SetFlags( IS_NEW );
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
|
|
|
screen->Append( textBox );
|
2022-08-09 19:21:36 +00:00
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Altium's harness port (%s) was imported as "
|
|
|
|
"a text box. Please review the imported "
|
|
|
|
"schematic." ),
|
|
|
|
aElem.Name ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
2022-08-09 19:21:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParsePort( const ASCH_PORT& aElem )
|
2020-10-26 15:54:49 +00:00
|
|
|
{
|
2022-08-10 08:00:41 +00:00
|
|
|
if( !aElem.HarnessType.IsEmpty() )
|
2022-08-09 19:21:36 +00:00
|
|
|
{
|
|
|
|
// Parse harness ports after "Additional" compound section is parsed
|
|
|
|
m_altiumHarnessPortsCurrentSheet.emplace_back( aElem );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-10 08:00:41 +00:00
|
|
|
VECTOR2I start = aElem.Location + m_sheetOffset;
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I end = start;
|
2020-10-27 13:07:42 +00:00
|
|
|
|
2022-08-10 08:00:41 +00:00
|
|
|
switch( aElem.Style )
|
2020-10-27 13:07:42 +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:
|
2022-08-10 08:00:41 +00:00
|
|
|
end.x += aElem.Width;
|
2020-10-27 13:07:42 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-27 13:07:42 +00:00
|
|
|
case ASCH_PORT_STYLE::NONE_VERTICAL:
|
|
|
|
case ASCH_PORT_STYLE::TOP:
|
|
|
|
case ASCH_PORT_STYLE::BOTTOM:
|
|
|
|
case ASCH_PORT_STYLE::TOP_BOTTOM:
|
2022-08-10 08:00:41 +00:00
|
|
|
end.y -= aElem.Width;
|
2020-10-27 13:07:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check which connection points exists in the schematic
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
2020-10-27 13:07:42 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-08-09 19:21:36 +00:00
|
|
|
if( !connectionFound )
|
2021-07-07 11:25:01 +00:00
|
|
|
{
|
2022-08-10 08:00:41 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Port %s has no connections." ), aElem.Name ),
|
2021-07-07 16:53:30 +00:00
|
|
|
RPT_SEVERITY_WARNING );
|
2021-07-07 11:25:01 +00:00
|
|
|
}
|
2020-10-27 13:07:42 +00:00
|
|
|
|
|
|
|
// Select label position. In case both match, we will add a line later.
|
2022-01-24 13:40:39 +00:00
|
|
|
VECTOR2I position = ( startIsWireTerminal || startIsBusTerminal ) ? start : end;
|
|
|
|
SCH_LABEL_BASE* label;
|
2021-07-07 16:53:30 +00:00
|
|
|
|
2020-10-26 15:54:49 +00:00
|
|
|
// TODO: detect correct label type depending on sheet settings, etc.
|
2024-02-21 13:05:18 +00:00
|
|
|
#if 1 // Set to 1 to use SCH_HIERLABEL label, 0 to use SCH_GLOBALLABEL
|
2022-11-24 18:42:41 +00:00
|
|
|
{
|
2022-11-28 16:56:46 +00:00
|
|
|
label = new SCH_HIERLABEL( position, aElem.Name );
|
2022-11-24 18:42:41 +00:00
|
|
|
}
|
2024-02-21 13:05:18 +00:00
|
|
|
#else
|
2022-08-10 08:00:41 +00:00
|
|
|
label = new SCH_GLOBALLABEL( position, aElem.Name );
|
2024-02-21 13:05:18 +00:00
|
|
|
#endif
|
2022-08-16 16:54:20 +00:00
|
|
|
|
2022-08-10 08:00:41 +00:00
|
|
|
switch( aElem.IOtype )
|
2020-10-26 15:54:49 +00:00
|
|
|
{
|
|
|
|
default:
|
2024-02-21 13:05:18 +00:00
|
|
|
case ASCH_PORT_IOTYPE::UNSPECIFIED: label->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED ); break;
|
|
|
|
case ASCH_PORT_IOTYPE::OUTPUT: label->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT ); break;
|
|
|
|
case ASCH_PORT_IOTYPE::INPUT: label->SetShape( LABEL_FLAG_SHAPE::L_INPUT ); break;
|
|
|
|
case ASCH_PORT_IOTYPE::BIDI: label->SetShape( LABEL_FLAG_SHAPE::L_BIDI ); break;
|
2020-10-26 15:54:49 +00:00
|
|
|
}
|
|
|
|
|
2022-08-10 08:00:41 +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 ) )
|
2023-09-07 16:09:53 +00:00
|
|
|
label->SetSpinStyle( SPIN_STYLE::RIGHT );
|
2020-10-27 13:07:42 +00:00
|
|
|
else
|
2023-09-07 16:09:53 +00:00
|
|
|
label->SetSpinStyle( SPIN_STYLE::LEFT );
|
2024-02-21 13:05:18 +00:00
|
|
|
|
2020-10-26 15:54:49 +00:00
|
|
|
break;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2020-10-26 15:54:49 +00:00
|
|
|
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 ) )
|
2023-09-07 16:09:53 +00:00
|
|
|
label->SetSpinStyle( SPIN_STYLE::UP );
|
2020-10-27 13:07:42 +00:00
|
|
|
else
|
2023-09-07 16:09:53 +00:00
|
|
|
label->SetSpinStyle( SPIN_STYLE::BOTTOM );
|
2024-02-21 13:05:18 +00:00
|
|
|
|
2020-10-26 15:54:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-08-09 19:25:55 +00:00
|
|
|
label->AutoplaceFields( screen, false );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2022-08-09 19:25:55 +00:00
|
|
|
// Default "Sheet References" field should be hidden, at least for now
|
2022-11-24 18:42:41 +00:00
|
|
|
if( label->GetFields().size() > 0 )
|
|
|
|
label->GetFields()[0].SetVisible( false );
|
|
|
|
|
2020-10-26 15:54:49 +00:00
|
|
|
label->SetFlags( IS_NEW );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
|
|
|
screen->Append( label );
|
2020-10-26 15:54:49 +00:00
|
|
|
|
2020-10-27 13:07:42 +00:00
|
|
|
// This is a hack, for the case both connection points are valid: add a small wire
|
2021-07-07 16:53:30 +00:00
|
|
|
if( ( startIsWireTerminal && endIsWireTerminal ) )
|
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 );
|
2022-09-16 23:42:20 +00:00
|
|
|
wire->SetLineWidth( schIUScale.MilsToIU( 2 ) );
|
2020-10-26 15:54:49 +00:00
|
|
|
wire->SetFlags( IS_NEW );
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( wire );
|
2020-10-26 15:54:49 +00:00
|
|
|
}
|
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 );
|
2022-09-16 23:42:20 +00:00
|
|
|
wire->SetLineWidth( schIUScale.MilsToIU( 2 ) );
|
2020-10-26 15:54:49 +00:00
|
|
|
wire->SetFlags( IS_NEW );
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( wire );
|
2020-10-26 15:54:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseNoERC( const std::map<wxString, wxString>& aProperties )
|
2020-10-14 19:23:36 +00:00
|
|
|
{
|
|
|
|
ASCH_NO_ERC elem( aProperties );
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
2020-10-14 19:23:36 +00:00
|
|
|
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 );
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( noConnect );
|
2020-10-14 19:23:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseNetLabel( const std::map<wxString, wxString>& aProperties )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
2023-07-04 07:27:43 +00:00
|
|
|
SetTextPositioning( label, elem.justification, elem.orientation );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
label->SetFlags( IS_NEW );
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( label );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseBus( const std::map<wxString, wxString>& aProperties )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
|
|
|
ASCH_BUS elem( aProperties );
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
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
|
|
|
{
|
2021-07-07 11:25:01 +00:00
|
|
|
SCH_LINE* bus = new SCH_LINE( elem.points.at( i ) + m_sheetOffset,
|
|
|
|
SCH_LAYER_ID::LAYER_BUS );
|
2020-10-17 13:35:22 +00:00
|
|
|
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 );
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( bus );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseWire( const std::map<wxString, wxString>& aProperties )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
|
|
|
ASCH_WIRE elem( aProperties );
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
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
|
|
|
{
|
2024-02-21 13:05:18 +00:00
|
|
|
SCH_LINE* wire = new SCH_LINE( elem.points.at( i ) + m_sheetOffset,
|
|
|
|
SCH_LAYER_ID::LAYER_WIRE );
|
2020-10-17 13:35:22 +00:00
|
|
|
wire->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset );
|
2024-02-04 17:14:19 +00:00
|
|
|
// wire->SetLineWidth( elem.lineWidth );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
wire->SetFlags( IS_NEW );
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( wire );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseJunction( const std::map<wxString, wxString>& aProperties )
|
2020-10-09 15:21:27 +00:00
|
|
|
{
|
2023-01-22 08:40:09 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
2020-10-09 15:21:27 +00:00
|
|
|
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 );
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( junction );
|
2020-10-09 15:21:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseImage( const std::map<wxString, wxString>& aProperties )
|
2021-04-10 19:45:36 +00:00
|
|
|
{
|
|
|
|
ASCH_IMAGE elem( aProperties );
|
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
const auto& component = m_altiumComponents.find( elem.ownerindex );
|
2023-01-27 16:28:38 +00:00
|
|
|
|
|
|
|
//Hide the image if it is owned by a component but the part id do not match
|
|
|
|
if( component != m_altiumComponents.end()
|
2023-09-04 21:46:25 +00:00
|
|
|
&& component->second.currentpartid != elem.ownerpartid )
|
2023-01-27 16:28:38 +00:00
|
|
|
return;
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I center = ( elem.location + elem.corner ) / 2 + m_sheetOffset;
|
2021-04-10 19:45:36 +00:00
|
|
|
std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>( center );
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
2021-04-10 19:45:36 +00:00
|
|
|
if( elem.embedimage )
|
|
|
|
{
|
|
|
|
const ASCH_STORAGE_FILE* storageFile = GetFileFromStorage( elem.filename );
|
|
|
|
|
|
|
|
if( !storageFile )
|
|
|
|
{
|
2021-07-07 11:25:01 +00:00
|
|
|
wxString msg = wxString::Format( _( "Embedded file %s not found in storage." ),
|
|
|
|
elem.filename );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
2021-04-10 19:45:36 +00:00
|
|
|
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 ) )
|
|
|
|
{
|
2021-07-07 11:25:01 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Error reading image %s." ), storagePath ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2021-04-10 19:45:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove temporary file
|
|
|
|
wxRemoveFile( storagePath );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !wxFileExists( elem.filename ) )
|
|
|
|
{
|
2021-07-07 11:25:01 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "File not found %s." ), elem.filename ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2021-04-10 19:45:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !bitmap->ReadImageFile( elem.filename ) )
|
|
|
|
{
|
2021-07-07 11:25:01 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Error reading image %s." ), elem.filename ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2021-04-10 19:45:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// we only support one scale, thus we need to select one in case it does not keep aspect ratio
|
2022-08-31 09:15:42 +00:00
|
|
|
VECTOR2I currentImageSize = bitmap->GetSize();
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I expectedImageSize = elem.location - elem.corner;
|
2022-08-31 09:15:42 +00:00
|
|
|
double scaleX = std::abs( static_cast<double>( expectedImageSize.x ) / currentImageSize.x );
|
|
|
|
double scaleY = std::abs( static_cast<double>( expectedImageSize.y ) / currentImageSize.y );
|
2021-04-10 19:45:36 +00:00
|
|
|
bitmap->SetImageScale( std::min( scaleX, scaleY ) );
|
|
|
|
|
|
|
|
bitmap->SetFlags( IS_NEW );
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( bitmap.release() );
|
2021-04-10 19:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseSheet( const std::map<wxString, wxString>& aProperties )
|
2020-10-17 12:33:30 +00:00
|
|
|
{
|
|
|
|
m_altiumSheet = std::make_unique<ASCH_SHEET>( aProperties );
|
2020-10-17 13:35:22 +00:00
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
2020-10-17 13:35:22 +00:00
|
|
|
PAGE_INFO pageInfo;
|
|
|
|
|
|
|
|
bool isPortrait = m_altiumSheet->sheetOrientation == ASCH_SHEET_WORKSPACEORIENTATION::PORTRAIT;
|
2021-07-07 17:30:36 +00:00
|
|
|
|
2023-09-11 07:02:59 +00:00
|
|
|
if( m_altiumSheet->useCustomSheet )
|
2020-10-17 13:35:22 +00:00
|
|
|
{
|
2023-09-11 07:02:59 +00:00
|
|
|
PAGE_INFO::SetCustomWidthMils( schIUScale.IUToMils( m_altiumSheet->customSize.x ) );
|
|
|
|
PAGE_INFO::SetCustomHeightMils( schIUScale.IUToMils( m_altiumSheet->customSize.y ) );
|
|
|
|
pageInfo.SetType( PAGE_INFO::Custom, isPortrait );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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 ); 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;
|
|
|
|
}
|
2020-10-17 13:35:22 +00:00
|
|
|
}
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->SetPageSettings( pageInfo );
|
2020-10-17 13:35:22 +00:00
|
|
|
|
2022-09-16 23:25:07 +00:00
|
|
|
m_sheetOffset = { 0, pageInfo.GetHeightIU( schIUScale.IU_PER_MILS ) };
|
2020-10-17 12:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseSheetName( const std::map<wxString, wxString>& aProperties )
|
2020-10-27 14:51:19 +00:00
|
|
|
{
|
|
|
|
ASCH_SHEET_NAME elem( aProperties );
|
|
|
|
|
2021-07-07 17:30:36 +00:00
|
|
|
const auto& sheetIt = m_sheets.find( elem.ownerindex );
|
|
|
|
|
|
|
|
if( sheetIt == m_sheets.end() )
|
2020-10-27 14:51:19 +00:00
|
|
|
{
|
2022-09-08 17:11:52 +00:00
|
|
|
m_reporter->Report( wxString::Format( wxT( "Sheetname's owner (%d) not found." ),
|
2021-07-07 11:25:01 +00:00
|
|
|
elem.ownerindex ),
|
2022-10-31 14:03:35 +00:00
|
|
|
RPT_SEVERITY_DEBUG );
|
2020-10-27 14:51:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-07 17:30:36 +00:00
|
|
|
SCH_FIELD& sheetNameField = sheetIt->second->GetFields()[SHEETNAME];
|
2020-10-27 14:51:19 +00:00
|
|
|
|
|
|
|
sheetNameField.SetPosition( elem.location + m_sheetOffset );
|
|
|
|
sheetNameField.SetText( elem.text );
|
|
|
|
sheetNameField.SetVisible( !elem.isHidden );
|
2021-07-24 20:28:24 +00:00
|
|
|
SetTextPositioning( &sheetNameField, ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT, elem.orientation );
|
2020-10-27 14:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseFileName( const std::map<wxString, wxString>& aProperties )
|
2020-10-27 14:51:19 +00:00
|
|
|
{
|
|
|
|
ASCH_FILE_NAME elem( aProperties );
|
|
|
|
|
2021-07-07 11:25:01 +00:00
|
|
|
const auto& sheetIt = m_sheets.find( elem.ownerindex );
|
|
|
|
|
|
|
|
if( sheetIt == m_sheets.end() )
|
2020-10-27 14:51:19 +00:00
|
|
|
{
|
2022-09-08 17:11:52 +00:00
|
|
|
m_reporter->Report( wxString::Format( wxT( "Filename's owner (%d) not found." ),
|
2021-07-07 11:25:01 +00:00
|
|
|
elem.ownerindex ),
|
2022-10-31 14:03:35 +00:00
|
|
|
RPT_SEVERITY_DEBUG );
|
2020-10-27 14:51:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-07 11:25:01 +00:00
|
|
|
SCH_FIELD& filenameField = sheetIt->second->GetFields()[SHEETFILENAME];
|
2020-10-27 14:51:19 +00:00
|
|
|
|
|
|
|
filenameField.SetPosition( elem.location + m_sheetOffset );
|
2021-03-02 21:39:47 +00:00
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
// Keep the filename of the Altium file until after the file is actually loaded.
|
2021-03-02 12:22:57 +00:00
|
|
|
filenameField.SetText( elem.text );
|
2020-10-27 14:51:19 +00:00
|
|
|
filenameField.SetVisible( !elem.isHidden );
|
2021-07-24 20:28:24 +00:00
|
|
|
SetTextPositioning( &filenameField, ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT, elem.orientation );
|
2020-10-27 14:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseDesignator( const std::map<wxString, wxString>& aProperties )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
|
|
|
ASCH_DESIGNATOR elem( aProperties );
|
|
|
|
|
2021-07-05 09:51:15 +00:00
|
|
|
const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
|
|
|
|
|
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
2020-08-23 19:01:08 +00:00
|
|
|
{
|
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
2022-09-08 17:11:52 +00:00
|
|
|
m_reporter->Report( wxString::Format( wxT( "Designator's owner (%d) not found." ),
|
2023-08-28 21:50:56 +00:00
|
|
|
elem.ownerindex ),
|
2022-10-31 14:03:35 +00:00
|
|
|
RPT_SEVERITY_DEBUG );
|
2020-10-26 17:26:49 +00:00
|
|
|
return;
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
2021-07-05 09:51:15 +00:00
|
|
|
SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
|
2020-10-26 17:26:49 +00:00
|
|
|
SCH_SHEET_PATH sheetpath;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
2020-10-26 17:26:49 +00:00
|
|
|
|
2022-01-28 15:52:30 +00:00
|
|
|
// Graphics symbols have no reference. '#GRAPHIC' allows them to not have footprint associated.
|
2022-10-31 14:03:35 +00:00
|
|
|
// Note: not all unnamed imported symbols are necessarily graphics.
|
2022-01-28 15:52:30 +00:00
|
|
|
bool emptyRef = elem.text.IsEmpty();
|
2023-01-16 01:22:17 +00:00
|
|
|
symbol->SetRef( &m_sheetPath, emptyRef ? wxString( wxS( "#GRAPHIC" ) ) : elem.text );
|
2020-08-23 19:01:08 +00:00
|
|
|
|
2022-11-23 13:46:03 +00:00
|
|
|
// I am not sure value and ref should be invisible just because emptyRef is true
|
|
|
|
// I have examples with this criteria fully incorrect.
|
2022-11-24 18:42:41 +00:00
|
|
|
bool visible = !emptyRef;
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2022-11-24 18:42:41 +00:00
|
|
|
symbol->GetField( VALUE_FIELD )->SetVisible( visible );
|
|
|
|
symbol->GetField( REFERENCE_FIELD )->SetVisible( visible );
|
2022-10-31 14:03:35 +00:00
|
|
|
|
2022-11-24 18:42:41 +00:00
|
|
|
SCH_FIELD* field = symbol->GetField( REFERENCE_FIELD );
|
2022-01-28 15:52:30 +00:00
|
|
|
field->SetPosition( elem.location + m_sheetOffset );
|
2024-05-04 13:18:56 +00:00
|
|
|
SetTextPositioning( field, elem.justification, elem.orientation, true );
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
2020-10-17 14:03:46 +00:00
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseLibDesignator( const std::map<wxString, wxString>& aProperties,
|
2024-01-26 13:59:07 +00:00
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol,
|
|
|
|
std::vector<int>& aFontSizes )
|
2023-09-06 18:36:27 +00:00
|
|
|
{
|
|
|
|
ASCH_DESIGNATOR elem( aProperties );
|
|
|
|
|
|
|
|
// Designators are shared by everyone
|
|
|
|
for( LIB_SYMBOL* symbol : aSymbol )
|
|
|
|
{
|
|
|
|
bool emptyRef = elem.text.IsEmpty();
|
2024-04-12 21:00:41 +00:00
|
|
|
SCH_FIELD& refField = symbol->GetReferenceField();
|
2023-09-06 18:36:27 +00:00
|
|
|
|
|
|
|
if( emptyRef )
|
|
|
|
refField.SetText( wxT( "X" ) );
|
|
|
|
else
|
|
|
|
refField.SetText( elem.text.BeforeLast( '?' ) ); // remove the '?' at the end for KiCad-style
|
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
refField.SetPosition( elem.location );
|
2023-09-06 18:36:27 +00:00
|
|
|
|
|
|
|
if( elem.fontId > 0 && elem.fontId <= static_cast<int>( aFontSizes.size() ) )
|
|
|
|
{
|
|
|
|
int size = aFontSizes[elem.fontId - 1];
|
|
|
|
refField.SetTextSize( { size, size } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseBusEntry( const std::map<wxString, wxString>& aProperties )
|
2020-10-17 14:03:46 +00:00
|
|
|
{
|
|
|
|
ASCH_BUS_ENTRY elem( aProperties );
|
|
|
|
|
2022-10-31 14:03:35 +00:00
|
|
|
SCH_SCREEN* screen = getCurrentScreen();
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
2020-10-17 14:03:46 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busWireEntry = new SCH_BUS_WIRE_ENTRY( elem.location + m_sheetOffset );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I vector = elem.corner - elem.location;
|
2020-10-17 14:03:46 +00:00
|
|
|
busWireEntry->SetSize( { vector.x, vector.y } );
|
|
|
|
|
|
|
|
busWireEntry->SetFlags( IS_NEW );
|
2022-10-31 14:03:35 +00:00
|
|
|
screen->Append( busWireEntry );
|
2020-10-17 14:03:46 +00:00
|
|
|
}
|
2020-10-26 17:26:49 +00:00
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseParameter( const std::map<wxString, wxString>& aProperties )
|
2020-10-26 17:26:49 +00:00
|
|
|
{
|
|
|
|
ASCH_PARAMETER elem( aProperties );
|
|
|
|
|
2021-03-14 15:40:36 +00:00
|
|
|
// TODO: fill in replacements from variant, sheet and project
|
2023-10-01 13:10:09 +00:00
|
|
|
static const std::map<wxString, wxString> variableMap = {
|
2021-07-08 13:14:27 +00:00
|
|
|
{ "COMMENT", "VALUE" },
|
|
|
|
{ "VALUE", "ALTIUM_VALUE" },
|
2021-03-14 15:40:36 +00:00
|
|
|
};
|
|
|
|
|
2024-01-30 23:06:58 +00:00
|
|
|
if( elem.ownerindex <= 0 )
|
2020-10-26 17:26:49 +00:00
|
|
|
{
|
|
|
|
// This is some sheet parameter
|
|
|
|
if( elem.text == "*" )
|
|
|
|
return; // indicates parameter not set?
|
|
|
|
|
2021-07-07 23:19:31 +00:00
|
|
|
wxString paramName = elem.name.Upper();
|
|
|
|
|
|
|
|
if( paramName == "SHEETNUMBER" )
|
|
|
|
{
|
2022-11-22 19:35:27 +00:00
|
|
|
m_sheetPath.SetPageNumber( elem.text );
|
2021-07-07 23:19:31 +00:00
|
|
|
}
|
|
|
|
else if( paramName == "TITLE" )
|
|
|
|
{
|
2020-10-26 17:26:49 +00:00
|
|
|
m_currentTitleBlock->SetTitle( elem.text );
|
2021-07-07 23:19:31 +00:00
|
|
|
}
|
|
|
|
else if( paramName == "REVISION" )
|
|
|
|
{
|
2020-10-26 17:26:49 +00:00
|
|
|
m_currentTitleBlock->SetRevision( elem.text );
|
2021-07-07 23:19:31 +00:00
|
|
|
}
|
|
|
|
else if( paramName == "DATE" )
|
|
|
|
{
|
2020-10-26 17:26:49 +00:00
|
|
|
m_currentTitleBlock->SetDate( elem.text );
|
2021-07-07 23:19:31 +00:00
|
|
|
}
|
|
|
|
else if( paramName == "COMPANYNAME" )
|
|
|
|
{
|
2020-10-26 17:26:49 +00:00
|
|
|
m_currentTitleBlock->SetCompany( elem.text );
|
2021-07-07 23:19:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_schematic->Prj().GetTextVars()[ paramName ] = elem.text;
|
|
|
|
}
|
2020-10-26 17:26:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-06 18:36:27 +00:00
|
|
|
const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
|
2021-07-05 09:51:15 +00:00
|
|
|
|
2023-09-06 18:36:27 +00:00
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
2020-10-26 17:26:49 +00:00
|
|
|
{
|
2023-09-06 18:36:27 +00:00
|
|
|
// TODO: e.g. can depend on Template (RECORD=39
|
|
|
|
return;
|
2020-10-26 17:26:49 +00:00
|
|
|
}
|
|
|
|
|
2023-09-06 18:36:27 +00:00
|
|
|
SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
|
|
|
|
SCH_FIELD* field = nullptr;
|
2022-03-22 10:04:24 +00:00
|
|
|
wxString upperName = elem.name.Upper();
|
2021-07-05 09:51:15 +00:00
|
|
|
|
2022-03-22 10:04:24 +00:00
|
|
|
if( upperName == "COMMENT" )
|
|
|
|
{
|
2023-09-06 18:36:27 +00:00
|
|
|
field = symbol->GetField( VALUE_FIELD );
|
2022-03-22 10:04:24 +00:00
|
|
|
}
|
2021-01-30 14:44:32 +00:00
|
|
|
else
|
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
int fieldIdx = 0;
|
2021-07-08 13:14:27 +00:00
|
|
|
wxString fieldName = elem.name.Upper();
|
|
|
|
|
2023-09-06 18:36:27 +00:00
|
|
|
fieldIdx = symbol->GetFieldCount();
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2022-03-22 10:04:24 +00:00
|
|
|
if( fieldName.IsEmpty() )
|
|
|
|
{
|
|
|
|
int disambiguate = 1;
|
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
while( 1 )
|
2022-03-22 10:04:24 +00:00
|
|
|
{
|
|
|
|
fieldName = wxString::Format( "ALTIUM_UNNAMED_%d", disambiguate++ );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-06 18:36:27 +00:00
|
|
|
if( !symbol->FindField( fieldName ) )
|
|
|
|
break;
|
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
2022-03-22 10:04:24 +00:00
|
|
|
}
|
|
|
|
else if( fieldName == "VALUE" )
|
|
|
|
{
|
2021-07-08 13:14:27 +00:00
|
|
|
fieldName = "ALTIUM_VALUE";
|
2022-03-22 10:04:24 +00:00
|
|
|
}
|
2021-07-08 13:14:27 +00:00
|
|
|
|
2023-09-06 18:36:27 +00:00
|
|
|
field = symbol->AddField( SCH_FIELD( VECTOR2I(), fieldIdx, symbol, fieldName ) );
|
2021-01-30 14:44:32 +00:00
|
|
|
}
|
|
|
|
|
2023-10-01 13:10:09 +00:00
|
|
|
wxString kicadText = AltiumSchSpecialStringsToKiCadVariables( elem.text, variableMap );
|
2021-03-14 15:40:36 +00:00
|
|
|
field->SetText( kicadText );
|
2023-09-06 18:36:27 +00:00
|
|
|
field->SetPosition( elem.location + m_sheetOffset );
|
|
|
|
field->SetVisible( !elem.isHidden );
|
2024-05-04 13:18:56 +00:00
|
|
|
SetTextPositioning( field, elem.justification, elem.orientation, true );
|
2023-09-06 18:36:27 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-06 18:36:27 +00:00
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseLibParameter( const std::map<wxString, wxString>& aProperties,
|
2024-01-26 13:59:07 +00:00
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol,
|
|
|
|
std::vector<int>& aFontSizes )
|
2023-09-06 18:36:27 +00:00
|
|
|
{
|
|
|
|
ASCH_PARAMETER elem( aProperties );
|
|
|
|
|
2024-02-22 18:23:39 +00:00
|
|
|
// Part ID 1 is the current library part.
|
|
|
|
// Part ID ALTIUM_COMPONENT_NONE(-1) means all parts
|
2023-09-06 18:49:21 +00:00
|
|
|
// If a parameter is assigned to a specific element such as a pin,
|
|
|
|
// we will need to handle it here.
|
|
|
|
// TODO: Handle HIDDENNETNAME property (others?)
|
2024-02-22 18:23:39 +00:00
|
|
|
if( elem.ownerpartid != 1 && elem.ownerpartid != ALTIUM_COMPONENT_NONE )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If ownerindex is populated, this is parameter belongs to a subelement (e.g. pin).
|
|
|
|
// Ignore for now.
|
|
|
|
// TODO: Update this when KiCad supports parameters for any object
|
|
|
|
if( elem.ownerindex != ALTIUM_COMPONENT_NONE )
|
2023-09-06 18:49:21 +00:00
|
|
|
return;
|
|
|
|
|
2023-09-06 18:36:27 +00:00
|
|
|
// TODO: fill in replacements from variant, sheet and project
|
|
|
|
// N.B. We do not keep the Altium "VALUE" variable here because
|
|
|
|
// we don't have a way to assign variables to specific symbols
|
|
|
|
std::map<wxString, wxString> variableMap = {
|
|
|
|
{ "COMMENT", "VALUE" },
|
|
|
|
};
|
|
|
|
|
|
|
|
for( LIB_SYMBOL* libSymbol : aSymbol )
|
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
SCH_FIELD* field = nullptr;
|
2023-09-06 18:36:27 +00:00
|
|
|
wxString upperName = elem.name.Upper();
|
|
|
|
|
|
|
|
if( upperName == "COMMENT" )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
2023-09-06 18:36:27 +00:00
|
|
|
field = &libSymbol->GetValueField();
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-06 18:36:27 +00:00
|
|
|
int fieldIdx = libSymbol->GetFieldCount();
|
2024-02-22 18:24:34 +00:00
|
|
|
wxString fieldNameStem = elem.name;
|
|
|
|
wxString fieldName = fieldNameStem;
|
|
|
|
int disambiguate = 1;
|
2023-09-06 18:36:27 +00:00
|
|
|
|
|
|
|
if( fieldName.IsEmpty() )
|
|
|
|
{
|
2024-02-22 18:24:34 +00:00
|
|
|
fieldNameStem = "ALTIUM_UNNAMED";
|
|
|
|
fieldName = "ALTIUM_UNNAMED_1";
|
|
|
|
disambiguate = 2;
|
2023-09-06 18:36:27 +00:00
|
|
|
}
|
2024-02-22 18:24:34 +00:00
|
|
|
else if( upperName == "VALUE" )
|
2023-09-06 18:36:27 +00:00
|
|
|
{
|
2024-02-22 18:24:34 +00:00
|
|
|
fieldNameStem = "ALTIUM_VALUE";
|
2023-09-06 18:36:27 +00:00
|
|
|
fieldName = "ALTIUM_VALUE";
|
|
|
|
}
|
|
|
|
|
2024-02-22 18:24:34 +00:00
|
|
|
// Avoid adding duplicate fields
|
|
|
|
while( libSymbol->FindField( fieldName ) )
|
|
|
|
fieldName = wxString::Format( "%s_%d", fieldNameStem, disambiguate++ );
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
SCH_FIELD* new_field = new SCH_FIELD( libSymbol, fieldIdx, fieldName );
|
2023-09-06 18:36:27 +00:00
|
|
|
libSymbol->AddField( new_field );
|
|
|
|
field = new_field;
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
|
2023-10-01 13:10:09 +00:00
|
|
|
wxString kicadText = AltiumSchSpecialStringsToKiCadVariables( elem.text, variableMap );
|
2023-09-06 18:36:27 +00:00
|
|
|
field->SetText( kicadText );
|
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
field->SetTextPos( elem.location );
|
|
|
|
SetTextPositioning( field, elem.justification, elem.orientation, true );
|
2021-01-30 14:44:32 +00:00
|
|
|
field->SetVisible( !elem.isHidden );
|
2023-09-06 17:10:54 +00:00
|
|
|
|
|
|
|
if( elem.fontId > 0 && elem.fontId <= static_cast<int>( aFontSizes.size() ) )
|
|
|
|
{
|
|
|
|
int size = aFontSizes[elem.fontId - 1];
|
|
|
|
field->SetTextSize( { size, size } );
|
|
|
|
}
|
2020-10-26 17:26:49 +00:00
|
|
|
}
|
2021-02-24 13:48:02 +00:00
|
|
|
}
|
2021-07-06 13:39:56 +00:00
|
|
|
|
2021-07-07 19:01:49 +00:00
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseImplementationList( int aIndex,
|
2024-01-26 13:59:07 +00:00
|
|
|
const std::map<wxString, wxString>& aProperties )
|
2021-07-07 19:01:49 +00:00
|
|
|
{
|
|
|
|
ASCH_IMPLEMENTATION_LIST elem( aProperties );
|
|
|
|
|
|
|
|
m_altiumImplementationList.emplace( aIndex, elem.ownerindex );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseImplementation( const std::map<wxString, wxString>& aProperties,
|
2024-01-26 13:59:07 +00:00
|
|
|
std::vector<LIB_SYMBOL*>& aSymbol )
|
2021-07-06 13:39:56 +00:00
|
|
|
{
|
|
|
|
ASCH_IMPLEMENTATION elem( aProperties );
|
|
|
|
|
2023-11-17 04:20:15 +00:00
|
|
|
if( elem.type != wxS( "PCBLIB" ) )
|
|
|
|
return;
|
2023-09-05 21:01:27 +00:00
|
|
|
|
2023-11-17 04:20:15 +00:00
|
|
|
// For schematic files, we need to check if the model is current.
|
|
|
|
if( aSymbol.size() == 0 && !elem.isCurrent )
|
|
|
|
return;
|
2023-09-07 06:53:30 +00:00
|
|
|
|
2023-11-17 04:20:15 +00:00
|
|
|
// For IntLibs we want to use the same lib name for footprints
|
|
|
|
wxString libName = m_isIntLib ? m_libName : elem.libname;
|
2023-09-05 21:01:27 +00:00
|
|
|
|
2023-11-17 04:20:15 +00:00
|
|
|
wxArrayString fpFilters;
|
|
|
|
fpFilters.Add( wxString::Format( wxS( "*%s*" ), elem.name ) );
|
2021-07-08 13:14:27 +00:00
|
|
|
|
2023-11-17 04:20:15 +00:00
|
|
|
// Parse the footprint fields for the library symbol
|
|
|
|
if( !aSymbol.empty() )
|
|
|
|
{
|
|
|
|
for( LIB_SYMBOL* symbol : aSymbol )
|
2021-07-08 13:14:27 +00:00
|
|
|
{
|
2023-11-17 04:20:15 +00:00
|
|
|
LIB_ID fpLibId = AltiumToKiCadLibID( libName, elem.name );
|
2021-07-07 19:01:49 +00:00
|
|
|
|
2023-11-17 04:20:15 +00:00
|
|
|
symbol->SetFPFilters( fpFilters );
|
2024-04-12 21:00:41 +00:00
|
|
|
SCH_FIELD& footprintField = symbol->GetFootprintField();
|
2023-11-17 04:20:15 +00:00
|
|
|
footprintField.SetText( fpLibId.Format() );
|
2021-07-06 13:39:56 +00:00
|
|
|
}
|
|
|
|
|
2023-11-17 04:20:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-07-07 19:01:49 +00:00
|
|
|
|
2023-11-17 04:20:15 +00:00
|
|
|
const auto& implementationOwnerIt = m_altiumImplementationList.find( elem.ownerindex );
|
2021-07-07 19:01:49 +00:00
|
|
|
|
2023-11-17 04:20:15 +00:00
|
|
|
if( implementationOwnerIt == m_altiumImplementationList.end() )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxString::Format( wxT( "Implementation's owner (%d) not found." ),
|
|
|
|
elem.ownerindex ),
|
|
|
|
RPT_SEVERITY_DEBUG );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& libSymbolIt = m_libSymbols.find( implementationOwnerIt->second );
|
2021-07-06 13:39:56 +00:00
|
|
|
|
2023-11-17 04:20:15 +00:00
|
|
|
if( libSymbolIt == m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxString::Format( wxT( "Footprint's owner (%d) not found." ),
|
|
|
|
implementationOwnerIt->second ),
|
|
|
|
RPT_SEVERITY_DEBUG );
|
|
|
|
return;
|
2021-07-06 13:39:56 +00:00
|
|
|
}
|
2023-11-17 04:20:15 +00:00
|
|
|
|
|
|
|
LIB_ID fpLibId = AltiumToKiCadLibID( libName, elem.name );
|
|
|
|
|
|
|
|
libSymbolIt->second->SetFPFilters( fpFilters ); // TODO: not ideal as we overwrite it
|
|
|
|
|
|
|
|
SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
|
|
|
|
|
|
|
|
symbol->SetFootprintFieldText( fpLibId.Format() );
|
2021-07-06 13:39:56 +00:00
|
|
|
}
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2024-01-26 13:59:07 +00:00
|
|
|
std::vector<LIB_SYMBOL*> SCH_IO_ALTIUM::ParseLibComponent( const std::map<wxString,
|
|
|
|
wxString>& aProperties )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
|
|
|
ASCH_SYMBOL elem( aProperties );
|
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
std::vector<LIB_SYMBOL*> symbols;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
symbols.reserve( elem.displaymodecount );
|
|
|
|
|
|
|
|
for( int i = 0; i < elem.displaymodecount; i++ )
|
|
|
|
{
|
|
|
|
LIB_SYMBOL* symbol = new LIB_SYMBOL( wxEmptyString );
|
|
|
|
|
|
|
|
if( elem.displaymodecount > 1 )
|
2024-01-26 13:59:07 +00:00
|
|
|
symbol->SetName( wxString::Format( "%s (Altium Display %d)", elem.libreference,
|
|
|
|
i + 1 ) );
|
2023-09-04 21:46:25 +00:00
|
|
|
else
|
|
|
|
symbol->SetName( elem.libreference );
|
|
|
|
|
|
|
|
LIB_ID libId = AltiumToKiCadLibID( getLibName(), symbol->GetName() );
|
|
|
|
symbol->SetDescription( elem.componentdescription );
|
|
|
|
symbol->SetLibId( libId );
|
|
|
|
symbol->SetUnitCount( elem.partcount - 1 );
|
|
|
|
symbols.push_back( symbol );
|
|
|
|
}
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
return symbols;
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
std::map<wxString,LIB_SYMBOL*> SCH_IO_ALTIUM::ParseLibFile( const ALTIUM_COMPOUND_FILE& aAltiumLibFile )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
|
|
|
std::map<wxString,LIB_SYMBOL*> ret;
|
2023-09-06 17:10:54 +00:00
|
|
|
std::vector<int> fontSizes;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-06 17:10:54 +00:00
|
|
|
ParseLibHeader( aAltiumLibFile, fontSizes );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
std::map<wxString, const CFB::COMPOUND_FILE_ENTRY*> syms = aAltiumLibFile.GetLibSymbols( nullptr );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
for( auto& [name, entry] : syms )
|
|
|
|
{
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumLibFile, entry );
|
2023-09-04 21:46:25 +00:00
|
|
|
std::vector<LIB_SYMBOL*> symbols;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() <= 0 )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "LibSymbol does not contain any data" );
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
std::map<wxString, wxString> properties = reader.ReadProperties();
|
2024-02-04 17:14:19 +00:00
|
|
|
int recordId = ALTIUM_PROPS_UTILS::ReadInt( properties, "RECORD", 0 );
|
2023-08-28 21:50:56 +00:00
|
|
|
ALTIUM_SCH_RECORD record = static_cast<ALTIUM_SCH_RECORD>( recordId );
|
|
|
|
|
|
|
|
if( record != ALTIUM_SCH_RECORD::COMPONENT )
|
|
|
|
THROW_IO_ERROR( "LibSymbol does not start with COMPONENT record" );
|
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
symbols = ParseLibComponent( properties );
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto handleBinaryDataLambda =
|
|
|
|
[]( const std::string& binaryData ) -> std::map<wxString, wxString>
|
2024-05-04 13:18:56 +00:00
|
|
|
{
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
std::map<wxString, wxString> result;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
ALTIUM_BINARY_READER binreader( binaryData );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
int32_t recordId = binreader.ReadInt32();
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
if( recordId != static_cast<int32_t>( ALTIUM_SCH_RECORD::PIN ) )
|
|
|
|
THROW_IO_ERROR( "Binary record missing PIN record" );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
result["RECORD"] = wxString::Format( "%d", recordId );
|
|
|
|
binreader.ReadByte(); // unknown
|
|
|
|
result["OWNERPARTID"] = wxString::Format( "%d", binreader.ReadInt16() );
|
|
|
|
result["OWNERPARTDISPLAYMODE"] = wxString::Format( "%d", binreader.ReadByte() );
|
|
|
|
result["SYMBOL_INNEREDGE"] = wxString::Format( "%d", binreader.ReadByte() );
|
|
|
|
result["SYMBOL_OUTEREDGE"] = wxString::Format( "%d", binreader.ReadByte() );
|
|
|
|
result["SYMBOL_INNER"] = wxString::Format( "%d", binreader.ReadByte() );
|
|
|
|
result["SYMBOL_OUTER"] = wxString::Format( "%d", binreader.ReadByte() );
|
|
|
|
result["TEXT"] = binreader.ReadPascalString();
|
|
|
|
binreader.ReadByte(); // unknown
|
|
|
|
result["ELECTRICAL"] = wxString::Format( "%d", binreader.ReadByte() );
|
|
|
|
result["PINCONGLOMERATE"] = wxString::Format( "%d", binreader.ReadByte() );
|
|
|
|
result["PINLENGTH"] = wxString::Format( "%d", binreader.ReadInt16() );
|
|
|
|
result["LOCATION.X"] = wxString::Format( "%d", binreader.ReadInt16() );
|
|
|
|
result["LOCATION.Y"] = wxString::Format( "%d", binreader.ReadInt16() );
|
|
|
|
result["COLOR"] = wxString::Format( "%d", binreader.ReadInt32() );
|
|
|
|
result["NAME"] = binreader.ReadPascalString();
|
|
|
|
result["DESIGNATOR"] = binreader.ReadPascalString();
|
|
|
|
result["SWAPIDGROUP"] = binreader.ReadPascalString();
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
std::string partSeq = binreader.ReadPascalString(); // This is 'part|&|seq'
|
|
|
|
std::vector<std::string> partSeqSplit = split( partSeq, "|" );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
if( partSeqSplit.size() == 3 )
|
|
|
|
{
|
|
|
|
result["PART"] = partSeqSplit[0];
|
|
|
|
result["SEQ"] = partSeqSplit[2];
|
|
|
|
}
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2024-05-04 13:18:56 +00:00
|
|
|
return result;
|
|
|
|
};
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
while( reader.GetRemainingBytes() > 0 )
|
|
|
|
{
|
|
|
|
std::map<wxString, wxString> properties = reader.ReadProperties( handleBinaryDataLambda );
|
|
|
|
|
|
|
|
if( properties.empty() )
|
|
|
|
continue;
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
int recordId = ALTIUM_PROPS_UTILS::ReadInt( properties, "RECORD", 0 );
|
2023-08-28 21:50:56 +00:00
|
|
|
ALTIUM_SCH_RECORD record = static_cast<ALTIUM_SCH_RECORD>( recordId );
|
|
|
|
|
|
|
|
switch( record )
|
|
|
|
{
|
2023-09-04 21:46:25 +00:00
|
|
|
case ALTIUM_SCH_RECORD::PIN: ParsePin( properties, symbols ); break;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-06 17:10:54 +00:00
|
|
|
case ALTIUM_SCH_RECORD::LABEL: ParseLabel( properties, symbols, fontSizes ); break;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
case ALTIUM_SCH_RECORD::BEZIER: ParseBezier( properties, symbols ); break;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
case ALTIUM_SCH_RECORD::POLYLINE: ParsePolyline( properties, symbols ); break;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
case ALTIUM_SCH_RECORD::POLYGON: ParsePolygon( properties, symbols ); break;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
case ALTIUM_SCH_RECORD::ELLIPSE: ParseEllipse( properties, symbols ); break;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2024-04-30 03:07:14 +00:00
|
|
|
case ALTIUM_SCH_RECORD::PIECHART:
|
|
|
|
m_reporter->Report( wxString::Format( _( "Record 'PIECHART' not handled, found "
|
|
|
|
"in %s." ),
|
|
|
|
symbols[0]->GetName() ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
break;
|
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
case ALTIUM_SCH_RECORD::ROUND_RECTANGLE: ParseRoundRectangle( properties, symbols ); break;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
case ALTIUM_SCH_RECORD::ELLIPTICAL_ARC: ParseEllipticalArc( properties, symbols ); break;
|
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
case ALTIUM_SCH_RECORD::ARC: ParseArc( properties, symbols ); break;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
case ALTIUM_SCH_RECORD::LINE: ParseLine( properties, symbols ); break;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
case ALTIUM_SCH_RECORD::RECTANGLE: ParseRectangle( properties, symbols ); break;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-06 18:36:27 +00:00
|
|
|
case ALTIUM_SCH_RECORD::DESIGNATOR: ParseLibDesignator( properties, symbols, fontSizes ); break;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-06 18:36:27 +00:00
|
|
|
case ALTIUM_SCH_RECORD::PARAMETER: ParseLibParameter( properties, symbols, fontSizes ); break;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-06 17:10:54 +00:00
|
|
|
case ALTIUM_SCH_RECORD::TEXT_FRAME: ParseTextFrame( properties, symbols, fontSizes ); break;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
// Nothing for now. TODO: Figure out how implementation lists are generted in libs
|
|
|
|
case ALTIUM_SCH_RECORD::IMPLEMENTATION_LIST: break;
|
2023-09-05 21:01:27 +00:00
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::IMPLEMENTATION: ParseImplementation( properties, symbols ); break;
|
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
case ALTIUM_SCH_RECORD::IMPL_PARAMS: break;
|
|
|
|
|
|
|
|
case ALTIUM_SCH_RECORD::MAP_DEFINER_LIST: break;
|
|
|
|
case ALTIUM_SCH_RECORD::MAP_DEFINER: break;
|
|
|
|
|
|
|
|
// TODO: add support for these. They are just drawn symbols, so we can probably hardcode
|
|
|
|
case ALTIUM_SCH_RECORD::IEEE_SYMBOL: break;
|
|
|
|
|
|
|
|
// TODO: Hanlde images once libedit supports them
|
|
|
|
case ALTIUM_SCH_RECORD::IMAGE: break;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
m_reporter->Report( wxString::Format( _( "Unknown or unexpected record id %d found "
|
2023-09-04 21:46:25 +00:00
|
|
|
"in %s." ),
|
|
|
|
recordId, symbols[0]->GetName() ),
|
2023-08-28 21:50:56 +00:00
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.HasParsingError() )
|
|
|
|
THROW_IO_ERROR( "stream was not parsed correctly!" );
|
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() != 0 )
|
|
|
|
THROW_IO_ERROR( "stream is not fully parsed" );
|
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
for( size_t ii = 0; ii < symbols.size(); ii++ )
|
|
|
|
{
|
|
|
|
LIB_SYMBOL* symbol = symbols[ii];
|
2023-09-05 21:01:27 +00:00
|
|
|
symbol->FixupDrawItems();
|
2023-09-04 21:46:25 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
SCH_FIELD& valField = symbol->GetValueField();
|
2023-09-06 17:10:54 +00:00
|
|
|
|
|
|
|
if( valField.GetText().IsEmpty() )
|
|
|
|
valField.SetText( name );
|
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
if( symbols.size() == 1 )
|
|
|
|
ret[name] = symbol;
|
|
|
|
else
|
|
|
|
ret[wxString::Format( "%s (Altium Display %zd)", name, ii + 1 )] = symbol;
|
|
|
|
}
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
long long SCH_IO_ALTIUM::getLibraryTimestamp( const wxString& aLibraryPath ) const
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
|
|
|
wxFileName fn( aLibraryPath );
|
|
|
|
|
2023-10-01 13:42:41 +00:00
|
|
|
if( fn.IsFileReadable() && fn.GetModificationTime().IsValid() )
|
2023-08-28 21:50:56 +00:00
|
|
|
return fn.GetModificationTime().GetValue().GetValue();
|
|
|
|
else
|
|
|
|
return wxDateTime( 0.0 ).GetValue().GetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::ensureLoadedLibrary( const wxString& aLibraryPath,
|
2024-01-26 13:59:07 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
|
|
|
if( m_libCache.count( aLibraryPath ) )
|
|
|
|
{
|
|
|
|
wxCHECK( m_timestamps.count( aLibraryPath ), /*void*/ );
|
|
|
|
|
|
|
|
if( m_timestamps.at( aLibraryPath ) == getLibraryTimestamp( aLibraryPath ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-17 04:20:15 +00:00
|
|
|
std::vector<std::unique_ptr<ALTIUM_COMPOUND_FILE>> compoundFiles;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
wxFileName fileName( aLibraryPath );
|
|
|
|
m_libName = fileName.GetName();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2023-11-17 04:20:15 +00:00
|
|
|
if( aLibraryPath.Lower().EndsWith( wxS( ".schlib" ) ) )
|
|
|
|
{
|
|
|
|
m_isIntLib = false;
|
|
|
|
|
|
|
|
compoundFiles.push_back( std::make_unique<ALTIUM_COMPOUND_FILE>( aLibraryPath ) );
|
|
|
|
}
|
|
|
|
else if( aLibraryPath.Lower().EndsWith( wxS( ".intlib" ) ) )
|
|
|
|
{
|
|
|
|
m_isIntLib = true;
|
|
|
|
|
|
|
|
std::unique_ptr<ALTIUM_COMPOUND_FILE> intCom =
|
|
|
|
std::make_unique<ALTIUM_COMPOUND_FILE>( aLibraryPath );
|
|
|
|
|
|
|
|
std::map<wxString, const CFB::COMPOUND_FILE_ENTRY*> schLibFiles =
|
|
|
|
intCom->EnumDir( L"SchLib" );
|
|
|
|
|
|
|
|
for( const auto& [schLibName, cfe] : schLibFiles )
|
|
|
|
compoundFiles.push_back( intCom->DecodeIntLibStream( *cfe ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map<wxString, LIB_SYMBOL*>& cacheMapRef = m_libCache[aLibraryPath];
|
|
|
|
|
|
|
|
for( auto& altiumSchFilePtr : compoundFiles )
|
|
|
|
{
|
|
|
|
std::map<wxString, LIB_SYMBOL*> parsed = ParseLibFile( *altiumSchFilePtr );
|
|
|
|
cacheMapRef.insert( parsed.begin(), parsed.end() );
|
|
|
|
}
|
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
m_timestamps[aLibraryPath] = getLibraryTimestamp( aLibraryPath );
|
|
|
|
}
|
|
|
|
catch( const CFB::CFBException& exception )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( exception.what() );
|
|
|
|
}
|
|
|
|
catch( const std::exception& exc )
|
|
|
|
{
|
2023-11-17 04:20:15 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Unhandled exception in Altium schematic parsers: %s." ),
|
|
|
|
exc.what() ) );
|
2023-08-28 21:50:56 +00:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 13:59:07 +00:00
|
|
|
void SCH_IO_ALTIUM::ParseLibHeader( const ALTIUM_COMPOUND_FILE& aAltiumSchFile,
|
|
|
|
std::vector<int>& aFontSizes )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
|
|
|
const CFB::COMPOUND_FILE_ENTRY* file = aAltiumSchFile.FindStream( { "FileHeader" } );
|
|
|
|
|
|
|
|
if( file == nullptr )
|
|
|
|
THROW_IO_ERROR( "FileHeader not found" );
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
ALTIUM_BINARY_PARSER reader( aAltiumSchFile, file );
|
2023-08-28 21:50:56 +00:00
|
|
|
|
|
|
|
if( reader.GetRemainingBytes() <= 0 )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "FileHeader does not contain any data" );
|
|
|
|
}
|
2023-09-04 21:46:25 +00:00
|
|
|
|
|
|
|
std::map<wxString, wxString> properties = reader.ReadProperties();
|
|
|
|
|
2024-02-04 17:14:19 +00:00
|
|
|
wxString libtype = ALTIUM_PROPS_UTILS::ReadString( properties, "HEADER", "" );
|
2023-09-04 21:46:25 +00:00
|
|
|
|
|
|
|
if( libtype.CmpNoCase( "Protel for Windows - Schematic Library Editor Binary File Version 5.0" ) )
|
|
|
|
THROW_IO_ERROR( _( "Expected Altium Schematic Library file version 5.0" ) );
|
|
|
|
|
|
|
|
for( auto& [key, value] : properties )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
2023-09-04 21:46:25 +00:00
|
|
|
wxString upperKey = key.Upper();
|
2023-09-06 17:10:54 +00:00
|
|
|
wxString remaining;
|
2023-08-28 21:50:56 +00:00
|
|
|
|
2023-09-06 17:10:54 +00:00
|
|
|
if( upperKey.StartsWith( "SIZE", &remaining ) )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
2023-09-06 17:10:54 +00:00
|
|
|
if( !remaining.empty() )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
2023-09-06 17:10:54 +00:00
|
|
|
int ind = wxAtoi( remaining );
|
2023-09-04 21:46:25 +00:00
|
|
|
|
2023-09-06 17:10:54 +00:00
|
|
|
if( static_cast<int>( aFontSizes.size() ) < ind )
|
|
|
|
aFontSizes.resize( ind );
|
2023-09-04 21:46:25 +00:00
|
|
|
|
2023-09-06 17:10:54 +00:00
|
|
|
// Altium stores in pt. 1 pt = 1/72 inch. 1 mil = 1/1000 inch.
|
|
|
|
int scaled = schIUScale.MilsToIU( wxAtoi( value ) * 72.0 / 10.0 );
|
|
|
|
aFontSizes[ind - 1] = scaled;
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-04 21:46:25 +00:00
|
|
|
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-02 02:47:19 +00:00
|
|
|
void SCH_IO_ALTIUM::doEnumerateSymbolLib( const wxString& aLibraryPath,
|
|
|
|
const STRING_UTF8_MAP* aProperties,
|
|
|
|
std::function<void(const wxString&, LIB_SYMBOL*)> aInserter )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
2023-09-04 21:46:25 +00:00
|
|
|
ensureLoadedLibrary( aLibraryPath, aProperties );
|
|
|
|
|
2024-05-02 02:47:19 +00:00
|
|
|
bool powerSymbolsOnly = ( aProperties &&
|
|
|
|
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly )
|
|
|
|
!= aProperties->end() );
|
|
|
|
|
2023-09-04 21:46:25 +00:00
|
|
|
auto it = m_libCache.find( aLibraryPath );
|
|
|
|
|
|
|
|
if( it != m_libCache.end() )
|
|
|
|
{
|
|
|
|
for( auto& [libnameStr, libSymbol] : it->second )
|
2024-05-02 02:47:19 +00:00
|
|
|
{
|
|
|
|
if( powerSymbolsOnly && !libSymbol->IsPower() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
aInserter( libnameStr, libSymbol );
|
|
|
|
}
|
2023-09-04 21:46:25 +00:00
|
|
|
}
|
2024-05-02 02:47:19 +00:00
|
|
|
}
|
2023-09-04 21:46:25 +00:00
|
|
|
|
2024-05-02 02:47:19 +00:00
|
|
|
|
|
|
|
void SCH_IO_ALTIUM::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
|
|
|
|
const wxString& aLibraryPath,
|
|
|
|
const STRING_UTF8_MAP* aProperties )
|
|
|
|
{
|
|
|
|
doEnumerateSymbolLib( aLibraryPath, aProperties,
|
|
|
|
[&]( const wxString& aStr, LIB_SYMBOL* )
|
|
|
|
{
|
|
|
|
aSymbolNameList.Add( aStr );
|
|
|
|
} );
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
void SCH_IO_ALTIUM::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
|
2024-01-26 13:59:07 +00:00
|
|
|
const wxString& aLibraryPath,
|
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
2024-05-02 02:47:19 +00:00
|
|
|
doEnumerateSymbolLib( aLibraryPath, aProperties,
|
|
|
|
[&]( const wxString&, LIB_SYMBOL* aSymbol )
|
|
|
|
{
|
|
|
|
aSymbolList.emplace_back( aSymbol );
|
|
|
|
} );
|
2023-08-28 21:50:56 +00:00
|
|
|
}
|
|
|
|
|
2024-05-02 02:47:19 +00:00
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
LIB_SYMBOL* SCH_IO_ALTIUM::LoadSymbol( const wxString& aLibraryPath,
|
2024-01-26 13:59:07 +00:00
|
|
|
const wxString& aAliasName,
|
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2023-08-28 21:50:56 +00:00
|
|
|
{
|
|
|
|
ensureLoadedLibrary( aLibraryPath, aProperties );
|
|
|
|
|
|
|
|
auto it = m_libCache.find( aLibraryPath );
|
|
|
|
|
|
|
|
if( it != m_libCache.end() )
|
|
|
|
{
|
|
|
|
auto it2 = it->second.find( aAliasName );
|
|
|
|
|
|
|
|
if( it2 != it->second.end() )
|
|
|
|
return it2->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
2023-11-29 14:55:17 +00:00
|
|
|
}
|