From 47786fa9762912de8958bd491afadb6238bd372d Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Fri, 23 Oct 2020 14:29:07 +0200 Subject: [PATCH] altium: Correctly handle symbol names containing invalid chars Fix: https://gitlab.com/kicad/code/kicad/-/issues/6082 --- common/plugins/altium/altium_parser_utils.h | 46 +++++++++++++++++++ .../sch_plugins/altium/altium_parser_sch.h | 3 ++ .../sch_plugins/altium/sch_altium_plugin.cpp | 14 +++--- pcbnew/plugins/altium/altium_pcb.cpp | 10 +--- 4 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 common/plugins/altium/altium_parser_utils.h diff --git a/common/plugins/altium/altium_parser_utils.h b/common/plugins/altium/altium_parser_utils.h new file mode 100644 index 0000000000..51ac5ae4ad --- /dev/null +++ b/common/plugins/altium/altium_parser_utils.h @@ -0,0 +1,46 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Thomas Pointhuber + * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef ALTIUM_PARSER_UTILS_H +#define ALTIUM_PARSER_UTILS_H + +#include +#include + + +LIB_ID AltiumToKiCadLibID( LIB_ID::LIB_ID_TYPE aType, wxString aLibName, wxString aLibReference ) +{ + ReplaceIllegalFileNameChars( aLibName, '_' ); + ReplaceIllegalFileNameChars( aLibReference, '_' ); + + wxString key = !aLibName.empty() ? ( aLibName + ":" + aLibReference ) : aLibReference; + + LIB_ID libId; + libId.Parse( key, aType, true ); + + return libId; +} + + +#endif //ALTIUM_PARSER_UTILS_H diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.h b/eeschema/sch_plugins/altium/altium_parser_sch.h index 8c8c112596..c50881a29e 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.h +++ b/eeschema/sch_plugins/altium/altium_parser_sch.h @@ -29,6 +29,9 @@ #include #include +#include +#include + // this constant specifies a item which is not inside an component const int ALTIUM_COMPONENT_NONE = -1; diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index 380e9f4ec8..a6b8181417 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -21,7 +21,13 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include + +#include "altium_parser_sch.h" +#include +#include #include +#include #include @@ -41,18 +47,14 @@ #include #include #include -#include #include #include #include #include -#include "altium_parser_sch.h" #include #include -#include -#include -#include +#include #include #include @@ -448,7 +450,7 @@ void SCH_ALTIUM_PLUGIN::ParseComponent( int index, const std::mapSetName( elem.libreference ); diff --git a/pcbnew/plugins/altium/altium_pcb.cpp b/pcbnew/plugins/altium/altium_pcb.cpp index a6e320d966..75f0bb3f8c 100644 --- a/pcbnew/plugins/altium/altium_pcb.cpp +++ b/pcbnew/plugins/altium/altium_pcb.cpp @@ -24,6 +24,7 @@ #include "altium_pcb.h" #include "altium_parser_pcb.h" #include "plugins/altium/altium_parser.h" +#include #include #include @@ -753,15 +754,8 @@ void ALTIUM_PCB::ParseComponents6Data( m_board->Add( module, ADD_MODE::APPEND ); m_components.emplace_back( module ); - wxString pack_ref = elem.sourcelibreference; - wxString lib_ref = elem.sourcefootprintlibrary; // TODO: remove ".PcbLib" part - ReplaceIllegalFileNameChars( lib_ref, '_' ); - ReplaceIllegalFileNameChars( pack_ref, '_' ); + LIB_ID fpID = AltiumToKiCadLibID(LIB_ID::ID_PCB, elem.sourcefootprintlibrary, elem.sourcelibreference ); - wxString key = !lib_ref.empty() ? lib_ref + ":" + pack_ref : pack_ref; - - LIB_ID fpID; - fpID.Parse( key, LIB_ID::ID_PCB, true ); module->SetFPID( fpID ); module->SetPosition( elem.position );