From e2a4d58e8f2fa8438c9e7f3c3d7349485edcf6d8 Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Wed, 22 Feb 2023 22:00:37 +0100 Subject: [PATCH] Extract CADSTAR PIN_TYPE and PIN::POSITION into a separate header --- .../plugins/cadstar/cadstar_archive_objects.h | 57 +++++++++++++++++++ .../cadstar/cadstar_archive_parser.cpp | 22 +++---- .../plugins/cadstar/cadstar_archive_parser.h | 51 +++++------------ .../cadstar/cadstar_sch_archive_loader.cpp | 22 +++---- .../cadstar/cadstar_sch_archive_loader.h | 2 +- 5 files changed, 95 insertions(+), 59 deletions(-) create mode 100644 common/plugins/cadstar/cadstar_archive_objects.h diff --git a/common/plugins/cadstar/cadstar_archive_objects.h b/common/plugins/cadstar/cadstar_archive_objects.h new file mode 100644 index 0000000000..f40bdce948 --- /dev/null +++ b/common/plugins/cadstar/cadstar_archive_objects.h @@ -0,0 +1,57 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2023 Roberto Fernandez Bautista + * Copyright (C) 2023 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_archive_objects.h + * Contains common object definitions + */ + +#ifndef CADSTAR_ARCHIVE_OBJECTS_H_ +#define CADSTAR_ARCHIVE_OBJECTS_H_ + + +enum class CADSTAR_PIN_TYPE +{ + UNCOMMITTED, ///< Uncommitted pin (default) + INPUT, ///< Input pin + OUTPUT_OR, ///< Output pin OR tieable + OUTPUT_NOT_OR, ///< Output pin not OR tieable + OUTPUT_NOT_NORM_OR, ///< Output pin not normally OR tieable + POWER, ///< Power pin + GROUND, ///< Ground pin + TRISTATE_BIDIR, ///< Tristate bi-directional driver pin + TRISTATE_INPUT, ///< Tristate input pin + TRISTATE_DRIVER ///< Tristate output pin +}; + + +/** + * @brief Positioning of pin names can be in one of four quadrants + */ +enum class CADSTAR_PIN_POSITION +{ + TOP_RIGHT = 0, ///< Default + TOP_LEFT = 1, + BOTTOM_LEFT = 2, + BOTTOM_RIGHT = 3 +}; + + +#endif // CADSTAR_ARCHIVE_OBJECTS_H_ diff --git a/common/plugins/cadstar/cadstar_archive_parser.cpp b/common/plugins/cadstar/cadstar_archive_parser.cpp index 32012423da..362154e368 100644 --- a/common/plugins/cadstar/cadstar_archive_parser.cpp +++ b/common/plugins/cadstar/cadstar_archive_parser.cpp @@ -1768,20 +1768,22 @@ void CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::GATE::Parse( XNODE* aNode, PARSER } -CADSTAR_ARCHIVE_PARSER::PART::PIN_TYPE CADSTAR_ARCHIVE_PARSER::PART::GetPinType( XNODE* aNode ) +CADSTAR_PIN_TYPE CADSTAR_ARCHIVE_PARSER::PART::GetPinType( XNODE* aNode ) { wxASSERT( aNode->GetName() == wxT( "PINTYPE" ) ); wxString pinTypeStr = GetXmlAttributeIDString( aNode, 0 ); - std::map pinTypeMap = { { wxT( "INPUT" ), PIN_TYPE::INPUT }, - { wxT( "OUTPUT_OR" ), PIN_TYPE::OUTPUT_OR }, - { wxT( "OUTPUT_NOT_OR" ), PIN_TYPE::OUTPUT_NOT_OR }, - { wxT( "OUTPUT_NOT_NORM_OR" ), PIN_TYPE::OUTPUT_NOT_NORM_OR }, - { wxT( "POWER" ), PIN_TYPE::POWER }, { wxT( "GROUND" ), PIN_TYPE::GROUND }, - { wxT( "TRISTATE_BIDIR" ), PIN_TYPE::TRISTATE_BIDIR }, - { wxT( "TRISTATE_INPUT" ), PIN_TYPE::TRISTATE_INPUT }, - { wxT( "TRISTATE_DRIVER" ), PIN_TYPE::TRISTATE_DRIVER } }; + std::map pinTypeMap = { + { wxT( "INPUT" ), CADSTAR_PIN_TYPE::INPUT }, + { wxT( "OUTPUT_OR" ), CADSTAR_PIN_TYPE::OUTPUT_OR }, + { wxT( "OUTPUT_NOT_OR" ), CADSTAR_PIN_TYPE::OUTPUT_NOT_OR }, + { wxT( "OUTPUT_NOT_NORM_OR" ), CADSTAR_PIN_TYPE::OUTPUT_NOT_NORM_OR }, + { wxT( "POWER" ), CADSTAR_PIN_TYPE::POWER }, + { wxT( "GROUND" ), CADSTAR_PIN_TYPE::GROUND }, + { wxT( "TRISTATE_BIDIR" ), CADSTAR_PIN_TYPE::TRISTATE_BIDIR }, + { wxT( "TRISTATE_INPUT" ), CADSTAR_PIN_TYPE::TRISTATE_INPUT }, + { wxT( "TRISTATE_DRIVER" ), CADSTAR_PIN_TYPE::TRISTATE_DRIVER } }; if( pinTypeMap.find( pinTypeStr ) == pinTypeMap.end() ) THROW_UNKNOWN_PARAMETER_IO_ERROR( pinTypeStr, aNode->GetName() ); @@ -1829,7 +1831,7 @@ void CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::PIN::Parse( XNODE* aNode, PARSER_ } else if( cNodeName == wxT( "PINPOSITION" ) ) { - Position = (POSITION) GetXmlAttributeIDLong( cNode, 0 ); + Position = CADSTAR_PIN_POSITION( GetXmlAttributeIDLong( cNode, 0 ) ); } else if( cNodeName == wxT( "PINIDENTIFIER" ) ) { diff --git a/common/plugins/cadstar/cadstar_archive_parser.h b/common/plugins/cadstar/cadstar_archive_parser.h index efb17f6156..8760a0ca02 100644 --- a/common/plugins/cadstar/cadstar_archive_parser.h +++ b/common/plugins/cadstar/cadstar_archive_parser.h @@ -35,6 +35,7 @@ #include #include +#include // THROW_IO_ERROR definitions to ensure consistent wording is used in the error messages @@ -968,23 +969,7 @@ public: struct PART : PARSER { - enum class PIN_TYPE - { - UNCOMMITTED, ///< Uncommitted pin (default) - INPUT, ///< Input pin - OUTPUT_OR, ///< Output pin OR tieable - OUTPUT_NOT_OR, ///< Output pin not OR tieable - OUTPUT_NOT_NORM_OR, ///< Output pin not normally OR tieable - POWER, ///< Power pin - GROUND, ///< Ground pin - TRISTATE_BIDIR, ///< Tristate bi-directional driver pin - TRISTATE_INPUT, ///< Tristate input pin - TRISTATE_DRIVER ///< Tristate output pin - }; - - - static PIN_TYPE GetPinType( XNODE* aNode ); - + static CADSTAR_PIN_TYPE GetPinType( XNODE* aNode ); struct DEFINITION : PARSER ///< "PARTDEFINITION" node name { @@ -1001,17 +986,6 @@ public: struct PIN : PARSER ///< "PARTDEFINITIONPIN" node name { - /** - * @brief Positioning of pin names can be in one of four quadrants - */ - enum class POSITION - { - TOP_RIGHT = 0, ///< Default - TOP_LEFT = 1, - BOTTOM_LEFT = 2, - BOTTOM_RIGHT = 3 - }; - PART_DEFINITION_PIN_ID ID = UNDEFINED_VALUE; wxString Identifier = wxEmptyString; ///< This should match a pad identifier @@ -1043,15 +1017,18 @@ public: ///< (subnode="PINSIGNAL") GATE_ID TerminalGate; ///< (subnode="PINTERM", param0) TERMINAL_ID TerminalPin; ///< (subnode="PINTERM", param1) - PIN_TYPE Type = PIN_TYPE::UNCOMMITTED; ///< subnode="PINTYPE" - long Load = UNDEFINED_VALUE; ///< The electrical current expected on + + CADSTAR_PIN_TYPE Type = CADSTAR_PIN_TYPE::UNCOMMITTED; ///< subnode="PINTYPE" + + long Load = UNDEFINED_VALUE; ///< The electrical current expected on ///< the pin (It is unclear what the units ///< are, but only accepted values are ///< integers) subnode ="PINLOAD" - POSITION Position = - POSITION::TOP_RIGHT; ///< The pin names will use these positions when - ///< the symbol is added to a schematic design - ///< subnode="PINPOSITION" + /// + CADSTAR_PIN_POSITION Position = + CADSTAR_PIN_POSITION::TOP_RIGHT; ///< The pin names will use these positions + ///< when the symbol is added to a design + ///< subnode="PINPOSITION" void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override; }; @@ -1131,9 +1108,9 @@ public: struct PART_PIN : PARSER ///< "PARTPIN" node name { PART_PIN_ID ID; - wxString Name = wxEmptyString; - PIN_TYPE Type = PIN_TYPE::UNCOMMITTED; - wxString Identifier = wxEmptyString; + wxString Name = wxEmptyString; + CADSTAR_PIN_TYPE Type = CADSTAR_PIN_TYPE::UNCOMMITTED; + wxString Identifier = wxEmptyString; void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override; }; diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index a71309c34f..6969633f08 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -2491,20 +2491,20 @@ CADSTAR_SCH_ARCHIVE_LOADER::getPartDefinitionPin( const PART& aCadstarPart, cons } -ELECTRICAL_PINTYPE CADSTAR_SCH_ARCHIVE_LOADER::getKiCadPinType( const PART::PIN_TYPE& aPinType ) +ELECTRICAL_PINTYPE CADSTAR_SCH_ARCHIVE_LOADER::getKiCadPinType( const CADSTAR_PIN_TYPE& aPinType ) { switch( aPinType ) { - case PART::PIN_TYPE::UNCOMMITTED: return ELECTRICAL_PINTYPE::PT_PASSIVE; - case PART::PIN_TYPE::INPUT: return ELECTRICAL_PINTYPE::PT_INPUT; - case PART::PIN_TYPE::OUTPUT_OR: return ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR; - case PART::PIN_TYPE::OUTPUT_NOT_OR: return ELECTRICAL_PINTYPE::PT_OUTPUT; - case PART::PIN_TYPE::OUTPUT_NOT_NORM_OR: return ELECTRICAL_PINTYPE::PT_OUTPUT; - case PART::PIN_TYPE::POWER: return ELECTRICAL_PINTYPE::PT_POWER_IN; - case PART::PIN_TYPE::GROUND: return ELECTRICAL_PINTYPE::PT_POWER_IN; - case PART::PIN_TYPE::TRISTATE_BIDIR: return ELECTRICAL_PINTYPE::PT_BIDI; - case PART::PIN_TYPE::TRISTATE_INPUT: return ELECTRICAL_PINTYPE::PT_INPUT; - case PART::PIN_TYPE::TRISTATE_DRIVER: return ELECTRICAL_PINTYPE::PT_OUTPUT; + case CADSTAR_PIN_TYPE::UNCOMMITTED: return ELECTRICAL_PINTYPE::PT_PASSIVE; + case CADSTAR_PIN_TYPE::INPUT: return ELECTRICAL_PINTYPE::PT_INPUT; + case CADSTAR_PIN_TYPE::OUTPUT_OR: return ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR; + case CADSTAR_PIN_TYPE::OUTPUT_NOT_OR: return ELECTRICAL_PINTYPE::PT_OUTPUT; + case CADSTAR_PIN_TYPE::OUTPUT_NOT_NORM_OR: return ELECTRICAL_PINTYPE::PT_OUTPUT; + case CADSTAR_PIN_TYPE::POWER: return ELECTRICAL_PINTYPE::PT_POWER_IN; + case CADSTAR_PIN_TYPE::GROUND: return ELECTRICAL_PINTYPE::PT_POWER_IN; + case CADSTAR_PIN_TYPE::TRISTATE_BIDIR: return ELECTRICAL_PINTYPE::PT_BIDI; + case CADSTAR_PIN_TYPE::TRISTATE_INPUT: return ELECTRICAL_PINTYPE::PT_INPUT; + case CADSTAR_PIN_TYPE::TRISTATE_DRIVER: return ELECTRICAL_PINTYPE::PT_OUTPUT; } return ELECTRICAL_PINTYPE::PT_UNSPECIFIED; diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h index f6a2db3133..17d9b7e6b9 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h @@ -206,7 +206,7 @@ private: const TERMINAL_ID& aTerminalID ); //Helper Functions for obtaining individual elements as KiCad elements: - ELECTRICAL_PINTYPE getKiCadPinType( const PART::PIN_TYPE& aPinType ); + ELECTRICAL_PINTYPE getKiCadPinType( const CADSTAR_PIN_TYPE& aPinType ); int getKiCadUnitNumberFromGate( const GATE_ID& aCadstarGateID ); TEXT_SPIN_STYLE getSpinStyle( const long long& aCadstarOrientation, bool aMirror );