From 721cba32d5fefd03158a0101907fb9c4cc368a9e Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Tue, 8 Sep 2020 20:51:22 +0100 Subject: [PATCH] ADDED: CADSTAR Schematic Archive Importer Initial commit to trigger the importer --- common/wildcards_and_files_ext.cpp | 6 + eeschema/CMakeLists.txt | 8 ++ eeschema/files-io.cpp | 2 + eeschema/sch_io_mgr.cpp | 8 ++ eeschema/sch_io_mgr.h | 1 + .../cadstar/cadstar_sch_archive_loader.cpp | 36 ++++++ .../cadstar/cadstar_sch_archive_loader.h | 60 ++++++++++ .../cadstar/cadstar_sch_archive_parser.cpp | 83 ++++++++++++++ .../cadstar/cadstar_sch_archive_parser.h | 55 +++++++++ .../cadstar/cadstar_sch_archive_plugin.cpp | 97 ++++++++++++++++ .../cadstar/cadstar_sch_archive_plugin.h | 106 ++++++++++++++++++ include/wildcards_and_files_ext.h | 1 + 12 files changed, 463 insertions(+) create mode 100644 eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp create mode 100644 eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h create mode 100644 eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.cpp create mode 100644 eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.h create mode 100644 eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp create mode 100644 eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h diff --git a/common/wildcards_and_files_ext.cpp b/common/wildcards_and_files_ext.cpp index f791d9a8fc..83e434d798 100644 --- a/common/wildcards_and_files_ext.cpp +++ b/common/wildcards_and_files_ext.cpp @@ -236,6 +236,12 @@ wxString AltiumSchematicFileWildcard() } +wxString CadstarSchematicArchiveFileWildcard() +{ + return _( "CADSTAR Schematic Archive files" ) + AddFileExtListToFilter( { "csa" } ); +} + + wxString EagleSchematicFileWildcard() { return _( "Eagle XML schematic files" ) + AddFileExtListToFilter( { "sch" } ); diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index f3262782f2..1069f49b2b 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -38,6 +38,13 @@ set( EESCHEMA_SCH_PLUGINS_ALTIUM sch_plugins/altium/altium_parser_sch.cpp ) + +set( EESCHEMA_SCH_PLUGINS_CADSTAR + sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp + sch_plugins/cadstar/cadstar_sch_archive_parser.cpp + sch_plugins/cadstar/cadstar_sch_archive_loader.cpp + ) + set( EESCHEMA_DLGS dialogs/dialog_annotate.cpp dialogs/dialog_annotate_base.cpp @@ -145,6 +152,7 @@ set ( EESCHEMA_LIBEDIT_SRCS ) set( EESCHEMA_SRCS ${EESCHEMA_SCH_PLUGINS_ALTIUM} + ${EESCHEMA_SCH_PLUGINS_CADSTAR} ${EESCHEMA_DLGS} ${EESCHEMA_WIDGETS} ${EESCHEMA_LIBEDIT_SRCS} diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 9747237a71..bc9ece5d31 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -611,6 +611,7 @@ void SCH_EDIT_FRAME::OnImportProject( wxCommandEvent& aEvent ) if( ADVANCED_CFG::GetCfg().m_PluginAltiumSch ) loaders.emplace_back( AltiumSchematicFileWildcard(), SCH_IO_MGR::SCH_ALTIUM ); // Import Altium schematic files + loaders.emplace_back( CadstarSchematicArchiveFileWildcard(), SCH_IO_MGR::CADSTAR_SCH_ARCHIVE ); //Import CADSTAR Schematic Archive files loaders.emplace_back( EagleSchematicFileWildcard(), SCH_IO_MGR::SCH_EAGLE ); // Import Eagle schematic files // clang-format on @@ -867,6 +868,7 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType ) switch( (SCH_IO_MGR::SCH_FILE_T) aFileType ) { case SCH_IO_MGR::SCH_ALTIUM: + case SCH_IO_MGR::CADSTAR_SCH_ARCHIVE: case SCH_IO_MGR::SCH_EAGLE: // We insist on caller sending us an absolute path, if it does not, we say it's a bug. wxASSERT_MSG( wxFileName( aFileName ).IsAbsolute(), diff --git a/eeschema/sch_io_mgr.cpp b/eeschema/sch_io_mgr.cpp index 285bf80851..e4cfa543e4 100644 --- a/eeschema/sch_io_mgr.cpp +++ b/eeschema/sch_io_mgr.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #define FMT_UNIMPLEMENTED _( "Plugin \"%s\" does not implement the \"%s\" function." ) @@ -61,6 +62,8 @@ SCH_PLUGIN* SCH_IO_MGR::FindPlugin( SCH_FILE_T aFileType ) return new SCH_SEXPR_PLUGIN(); case SCH_ALTIUM: return new SCH_ALTIUM_PLUGIN(); + case CADSTAR_SCH_ARCHIVE: + return new CADSTAR_SCH_ARCHIVE_PLUGIN(); case SCH_EAGLE: return new SCH_EAGLE_PLUGIN(); default: @@ -101,6 +104,9 @@ const wxString SCH_IO_MGR::ShowType( SCH_FILE_T aType ) case SCH_ALTIUM: return wxString( wxT( "Altium" ) ); + case CADSTAR_SCH_ARCHIVE: + return wxString( wxT( "CADSTAR Schematic Archive" ) ); + case SCH_EAGLE: return wxString( wxT( "EAGLE" ) ); } @@ -119,6 +125,8 @@ SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::EnumFromStr( const wxString& aType ) return SCH_KICAD; else if( aType == wxT( "Altium" ) ) return SCH_ALTIUM; + else if( aType == wxT( "CADSTAR Schematic Archive" ) ) + return CADSTAR_SCH_ARCHIVE; else if( aType == wxT( "EAGLE" ) ) return SCH_EAGLE; diff --git a/eeschema/sch_io_mgr.h b/eeschema/sch_io_mgr.h index 05eefca56b..ba013eaa68 100644 --- a/eeschema/sch_io_mgr.h +++ b/eeschema/sch_io_mgr.h @@ -56,6 +56,7 @@ public: SCH_LEGACY, ///< Legacy Eeschema file formats prior to s-expression. SCH_KICAD, ///< The s-expression version of the schematic file formats. SCH_ALTIUM, ///< Altium file format + CADSTAR_SCH_ARCHIVE, ///< CADSTAR Schematic Archive SCH_EAGLE, ///< Autodesk Eagle file format // Add your schematic type here. diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp new file mode 100644 index 0000000000..45451ff5be --- /dev/null +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -0,0 +1,36 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Roberto Fernandez Bautista + * 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 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +/** + * @file cadstar_sch_archive_loader.cpp + * @brief Loads a csa file into a KiCad SCHEMATIC object + */ + +#include + + +void CADSTAR_SCH_ARCHIVE_LOADER::Load( ::SCHEMATIC* aSchematic ) +{ + Parse(); + + mSchematic = aSchematic; + + // Load everything! +} diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h new file mode 100644 index 0000000000..5e9617f2f3 --- /dev/null +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h @@ -0,0 +1,60 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Roberto Fernandez Bautista + * 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 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +/** + * @file cadstar_sch_archive_loader.h + * @brief Loads a csa file into a KiCad SCHEMATIC object + */ + +#ifndef CADSTAR_SCH_ARCHIVE_LOADER_H_ +#define CADSTAR_SCH_ARCHIVE_LOADER_H_ + +#include +#include + + +class CADSTAR_SCH_ARCHIVE_LOADER : public CADSTAR_SCH_ARCHIVE_PARSER +{ +public: + explicit CADSTAR_SCH_ARCHIVE_LOADER( wxString aFilename ) + : CADSTAR_SCH_ARCHIVE_PARSER( aFilename ) + { + mSchematic = nullptr; + } + + + ~CADSTAR_SCH_ARCHIVE_LOADER() + { + } + + /** + * @brief Loads a CADSTAR PCB Archive file into the KiCad BOARD object given + * @param aBoard + */ + void Load( ::SCHEMATIC* aSchematic ); + + +private: + ::SCHEMATIC* mSchematic; + +}; // CADSTAR_SCH_ARCHIVE_LOADER + + +#endif // CADSTAR_SCH_ARCHIVE_LOADER_H_ diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.cpp new file mode 100644 index 0000000000..55010f28d3 --- /dev/null +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.cpp @@ -0,0 +1,83 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Roberto Fernandez Bautista + * 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 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +/** + * @file cadstar_sch_archive_parser.cpp + * @brief Reads in a CADSTAR Schematic Archive (*.csa) file + */ + +#include + + +void CADSTAR_SCH_ARCHIVE_PARSER::Parse() +{ + XNODE* fileRootNode = LoadArchiveFile( Filename, wxT( "CADSTARSCH" ) ); + + XNODE* cNode = fileRootNode->GetChildren(); + + if( !cNode ) + THROW_MISSING_NODE_IO_ERROR( wxT( "HEADER" ), wxT( "CADSTARSCH" ) ); + /* + for( ; cNode; cNode = cNode->GetNext() ) + { + if( cNode->GetName() == wxT( "HEADER" ) ) + { + Header.Parse( cNode ); + + switch( Header.Resolution ) + { + case RESOLUTION::HUNDREDTH_MICRON: + KiCadUnitMultiplier = 10; + break; + + default: + wxASSERT_MSG( true, wxT( "Unknown File Resolution" ) ); + break; + } + } + else if( cNode->GetName() == wxT( "ASSIGNMENTS" ) ) + Assignments.Parse( cNode ); + else if( cNode->GetName() == wxT( "LIBRARY" ) ) + Library.Parse( cNode ); + else if( cNode->GetName() == wxT( "DEFAULTS" ) ) + { + // No design information here (no need to parse) + // Only contains CADSTAR configuration data such as default shapes, text and units + // In future some of this could be converted to KiCad but limited value + } + else if( cNode->GetName() == wxT( "PARTS" ) ) + Parts.Parse( cNode ); + else if( cNode->GetName() == wxT( "LAYOUT" ) ) + Layout.Parse( cNode ); + else if( cNode->GetName() == wxT( "DISPLAY" ) ) + { + // No design information here (no need to parse) + // Contains CADSTAR Display settings such as layer/element colours and visibility. + // In the future these settings could be converted to KiCad + } + else + { + THROW_UNKNOWN_NODE_IO_ERROR( cNode->GetName(), wxT( "[root]" ) ); + } + } + */ + delete fileRootNode; +} + diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.h new file mode 100644 index 0000000000..5dd6b0f50b --- /dev/null +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.h @@ -0,0 +1,55 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Roberto Fernandez Bautista + * 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 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +/** + * @file cadstar_pcb_archive_parser.cpp + * @brief Reads in a CADSTAR Schematic Archive (*.csa) file + */ + +#ifndef CADSTAR_SCH_ARCHIVE_PARSER_H_ +#define CADSTAR_SCH_ARCHIVE_PARSER_H_ + +#include + + +/** + * @brief Represents a CADSTAR Schematic Archive (*.csa) file + */ +class CADSTAR_SCH_ARCHIVE_PARSER : public CADSTAR_ARCHIVE_PARSER +{ +public: + explicit CADSTAR_SCH_ARCHIVE_PARSER( wxString aFilename ) + : Filename( aFilename ), CADSTAR_ARCHIVE_PARSER() + { + // KiCadUnitMultiplier = 10; // assume hundredth micron + } + + /** + * @brief Parses the file + * @throw IO_ERROR if file could not be opened or there was + * an error while parsing + */ + void Parse(); + + wxString Filename; + +}; //CADSTAR_SCH_ARCHIVE_PARSER + +#endif // CADSTAR_SCH_ARCHIVE_PARSER_H_ diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp new file mode 100644 index 0000000000..6953fb246c --- /dev/null +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp @@ -0,0 +1,97 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Roberto Fernandez Bautista + * 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 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +/** + * @file cadstar_pcb_archive_plugin.cpp + * @brief Pcbnew PLUGIN for CADSTAR PCB Archive (*.cpa) format: an ASCII format + * based on S-expressions. + */ + +#include +#include + +#include +#include +#include +#include + + +const wxString CADSTAR_SCH_ARCHIVE_PLUGIN::GetName() const +{ + return wxT( "CADSTAR Schematic Archive" ); +} + + +const wxString CADSTAR_SCH_ARCHIVE_PLUGIN::GetFileExtension() const +{ + return wxT( "csa" ); +} + + +const wxString CADSTAR_SCH_ARCHIVE_PLUGIN::GetLibraryFileExtension() const +{ + return wxT( "lib" ); +} + + +int CADSTAR_SCH_ARCHIVE_PLUGIN::GetModifyHash() const +{ + return 0; +} + + +SCH_SHEET* CADSTAR_SCH_ARCHIVE_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic, + SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties ) +{ + wxASSERT( !aFileName || aSchematic != NULL ); + + mProperties = aProperties; + mSchematic = aSchematic; + + // Delete on exception, if I own m_rootSheet, according to aAppendToMe + std::unique_ptr deleter( aAppendToMe ? nullptr : mRootSheet ); + + if( aAppendToMe ) + { + wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" ); + mRootSheet = &aSchematic->Root(); + } + else + { + mRootSheet = new SCH_SHEET( aSchematic ); + mRootSheet->SetFileName( aFileName ); + } + + if( !mRootSheet->GetScreen() ) + { + SCH_SCREEN* screen = new SCH_SCREEN( mSchematic ); + screen->SetFileName( aFileName ); + mRootSheet->SetScreen( screen ); + } + + return mRootSheet; +} + + +bool CADSTAR_SCH_ARCHIVE_PLUGIN::CheckHeader( const wxString& aFileName ) +{ + //TODO + return true; +} diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h new file mode 100644 index 0000000000..866f2ca30c --- /dev/null +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h @@ -0,0 +1,106 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Roberto Fernandez Bautista + * 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 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +/** + * @file cadstar_pcb_archive_plugin.h + * @brief Pcbnew PLUGIN for CADSTAR PCB Archive (*.cpa) format: an ASCII format + * based on S-expressions. + */ + +#ifndef CADSTAR_SCH_ARCHIVE_PLUGIN_H_ +#define CADSTAR_SCH_ARCHIVE_PLUGIN_H_ + + +#include + +class SCH_SHEET; +class SCH_SCREEN; + +class CADSTAR_SCH_ARCHIVE_PLUGIN : public SCH_PLUGIN +{ +public: + + //------------------------------------------------------ + + const wxString GetName() const override; + + const wxString GetFileExtension() const override; + + const wxString GetLibraryFileExtension() const override; + + int GetModifyHash() const override; + + SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic, + SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL ) override; + + bool CheckHeader( const wxString& aFileName ) override; + + + // unimplemented functions. Will trigger a not_implemented IO error. + //void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = NULL ) override; + + //void Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway, + // const PROPERTIES* aProperties = NULL ) override; + + //void EnumerateSymbolLib( wxArrayString& aAliasNameList, const wxString& aLibraryPath, + // const PROPERTIES* aProperties = NULL ) override; + + //LIB_PART* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName, + // const PROPERTIES* aProperties = NULL ) override; + + //void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol, + // const PROPERTIES* aProperties = NULL ) override; + + //void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName, + // const PROPERTIES* aProperties = NULL ) override; + + //void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName, + // const PROPERTIES* aProperties = NULL ) override; + + //void CreateSymbolLib( const wxString& aLibraryPath, + // const PROPERTIES* aProperties = NULL ) override; + + // bool DeleteSymbolLib( const wxString& aLibraryPath, + // const PROPERTIES* aProperties = NULL ) override; + + //bool IsSymbolLibWritable( const wxString& aLibraryPath ) override; + + //void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const override; + + //----------------------------------------------------- + + + CADSTAR_SCH_ARCHIVE_PLUGIN() + { + mSchematic = nullptr; + mRootSheet = nullptr; + } + + ~CADSTAR_SCH_ARCHIVE_PLUGIN() + { + } + +private: + const PROPERTIES* mProperties; + SCHEMATIC* mSchematic; + SCH_SHEET* mRootSheet; +}; + +#endif // CADSTAR_SCH_ARCHIVE_PLUGIN_H_ diff --git a/include/wildcards_and_files_ext.h b/include/wildcards_and_files_ext.h index 666fa12f52..3be9876f7b 100644 --- a/include/wildcards_and_files_ext.h +++ b/include/wildcards_and_files_ext.h @@ -194,6 +194,7 @@ extern wxString LegacyPcbFileWildcard(); extern wxString PcbFileWildcard(); extern wxString EaglePcbFileWildcard(); extern wxString AltiumSchematicFileWildcard(); +extern wxString CadstarSchematicArchiveFileWildcard(); extern wxString EagleSchematicFileWildcard(); extern wxString EagleFilesWildcard(); extern wxString PCadPcbFileWildcard();