altium: Correctly handle symbol names containing invalid chars

Fix: https://gitlab.com/kicad/code/kicad/-/issues/6082
This commit is contained in:
Thomas Pointhuber 2020-10-23 14:29:07 +02:00
parent 51be98428d
commit 47786fa976
4 changed files with 59 additions and 14 deletions

View File

@ -0,0 +1,46 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Thomas Pointhuber <thomas.pointhuber@gmx.at>
* 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 <kicad_string.h>
#include <lib_id.h>
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

View File

@ -29,6 +29,9 @@
#include <map>
#include <vector>
#include <wx/gdicmn.h>
#include <wx/string.h>
// this constant specifies a item which is not inside an component
const int ALTIUM_COMPONENT_NONE = -1;

View File

@ -21,7 +21,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <memory>
#include "altium_parser_sch.h"
#include <plugins/altium/altium_parser.h>
#include <plugins/altium/altium_parser_utils.h>
#include <sch_plugins/altium/sch_altium_plugin.h>
#include <sch_plugins/legacy/sch_legacy_plugin.h>
#include <schematic.h>
@ -41,18 +47,14 @@
#include <sch_component.h>
#include <sch_junction.h>
#include <sch_line.h>
#include <sch_marker.h>
#include <sch_no_connect.h>
#include <sch_screen.h>
#include <sch_sheet.h>
#include <sch_text.h>
#include "altium_parser_sch.h"
#include <bezier_curves.h>
#include <compoundfilereader.h>
#include <memory>
#include <plugins/altium/altium_parser.h>
#include <sch_plugins/legacy/sch_legacy_plugin.h>
#include <kicad_string.h>
#include <wildcards_and_files_ext.h>
#include <wx/textfile.h>
@ -448,7 +450,7 @@ void SCH_ALTIUM_PLUGIN::ParseComponent( int index, const std::map<wxString, wxSt
{
ASCH_COMPONENT elem( aProperties );
LIB_ID libId( getLibName(), elem.libreference );
LIB_ID libId = AltiumToKiCadLibID( LIB_ID::ID_SCH, getLibName(), elem.libreference );
LIB_PART* kpart = new LIB_PART( wxEmptyString );
kpart->SetName( elem.libreference );

View File

@ -24,6 +24,7 @@
#include "altium_pcb.h"
#include "altium_parser_pcb.h"
#include "plugins/altium/altium_parser.h"
#include <plugins/altium/altium_parser_utils.h>
#include <class_board.h>
#include <class_dimension.h>
@ -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 );