2016-02-28 17:33:29 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-03-23 17:26:32 +00:00
|
|
|
* Copyright (C) 2004-2023 KiCad Developers, see change_log.txt for contributors.
|
2016-02-28 17:33:29 +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
|
|
|
|
*/
|
|
|
|
|
2021-03-07 20:31:19 +00:00
|
|
|
#include <bitmaps.h>
|
2021-06-03 05:46:04 +00:00
|
|
|
#include <cstddef>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/arraydim.h>
|
2023-07-27 03:46:15 +00:00
|
|
|
#include <magic_enum.hpp>
|
2021-03-07 20:31:19 +00:00
|
|
|
#include <lib_pin.h>
|
2022-04-05 12:15:27 +00:00
|
|
|
#include "pgm_base.h"
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
// These are true singletons so it's OK for them to be globals.
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
static std::vector<BITMAPS> g_typeIcons;
|
|
|
|
static wxArrayString g_typeNames;
|
2016-02-28 17:33:29 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
static std::vector<BITMAPS> g_shapeIcons;
|
|
|
|
static wxArrayString g_shapeNames;
|
2016-02-28 17:33:29 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
static std::vector<BITMAPS> g_orientationIcons;
|
|
|
|
static wxArrayString g_orientationNames;
|
2016-02-28 17:33:29 +00:00
|
|
|
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
struct pinTypeStruct
|
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
wxString name;
|
|
|
|
BITMAPS bitmap;
|
2020-01-18 20:51:28 +00:00
|
|
|
};
|
2016-02-28 17:33:29 +00:00
|
|
|
|
2022-04-05 12:15:27 +00:00
|
|
|
|
|
|
|
std::map<ELECTRICAL_PINTYPE, struct pinTypeStruct> g_pinTypes = {
|
2021-03-08 02:59:07 +00:00
|
|
|
{ ELECTRICAL_PINTYPE::PT_INPUT, { _( "Input" ), BITMAPS::pintype_input } },
|
|
|
|
{ ELECTRICAL_PINTYPE::PT_OUTPUT, { _( "Output" ), BITMAPS::pintype_output } },
|
|
|
|
{ ELECTRICAL_PINTYPE::PT_BIDI, { _( "Bidirectional" ), BITMAPS::pintype_bidi } },
|
|
|
|
{ ELECTRICAL_PINTYPE::PT_TRISTATE, { _( "Tri-state" ), BITMAPS::pintype_3states } },
|
|
|
|
{ ELECTRICAL_PINTYPE::PT_PASSIVE, { _( "Passive" ), BITMAPS::pintype_passive } },
|
|
|
|
{ ELECTRICAL_PINTYPE::PT_NIC, { _( "Free" ), BITMAPS::pintype_nic } },
|
|
|
|
{ ELECTRICAL_PINTYPE::PT_UNSPECIFIED, { _( "Unspecified" ), BITMAPS::pintype_notspecif } },
|
|
|
|
{ ELECTRICAL_PINTYPE::PT_POWER_IN, { _( "Power input" ), BITMAPS::pintype_powerinput } },
|
|
|
|
{ ELECTRICAL_PINTYPE::PT_POWER_OUT, { _( "Power output" ), BITMAPS::pintype_poweroutput } },
|
|
|
|
{ ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR,{ _( "Open collector" ), BITMAPS::pintype_opencoll } },
|
|
|
|
{ ELECTRICAL_PINTYPE::PT_OPENEMITTER, { _( "Open emitter" ), BITMAPS::pintype_openemit } },
|
|
|
|
{ ELECTRICAL_PINTYPE::PT_NC, { _( "Unconnected" ), BITMAPS::pintype_noconnect } },
|
2020-01-18 20:51:28 +00:00
|
|
|
};
|
2022-04-05 12:15:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
int g_pinTypesLanguage = wxLANGUAGE_UNKNOWN;
|
2016-02-28 17:33:29 +00:00
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
struct pinShapeStruct
|
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
wxString name;
|
|
|
|
BITMAPS bitmap;
|
2020-08-21 15:54:24 +00:00
|
|
|
};
|
|
|
|
|
2021-01-22 13:04:43 +00:00
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
// clang-format off
|
|
|
|
const std::map<GRAPHIC_PINSHAPE, struct pinShapeStruct> pinShapes = {
|
2021-03-08 02:59:07 +00:00
|
|
|
{ GRAPHIC_PINSHAPE::LINE, { _( "Line" ), BITMAPS::pinshape_normal } },
|
|
|
|
{ GRAPHIC_PINSHAPE::INVERTED, { _( "Inverted" ), BITMAPS::pinshape_invert } },
|
|
|
|
{ GRAPHIC_PINSHAPE::CLOCK, { _( "Clock" ), BITMAPS::pinshape_clock_normal } },
|
|
|
|
{ GRAPHIC_PINSHAPE::INVERTED_CLOCK, { _( "Inverted clock" ), BITMAPS::pinshape_clock_invert } },
|
|
|
|
{ GRAPHIC_PINSHAPE::INPUT_LOW, { _( "Input low" ), BITMAPS::pinshape_active_low_input } },
|
|
|
|
{ GRAPHIC_PINSHAPE::CLOCK_LOW, { _( "Clock low" ), BITMAPS::pinshape_clock_active_low } },
|
|
|
|
{ GRAPHIC_PINSHAPE::OUTPUT_LOW, { _( "Output low" ), BITMAPS::pinshape_active_low_output } },
|
|
|
|
{ GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK, { _( "Falling edge clock" ), BITMAPS::pinshape_clock_fall } },
|
|
|
|
{ GRAPHIC_PINSHAPE::NONLOGIC, { _( "NonLogic" ), BITMAPS::pinshape_nonlogic } },
|
2020-08-21 15:54:24 +00:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
|
|
|
|
// bitmaps to show pins orientations in dialog editor
|
|
|
|
// must have same order than pin_orientation_names
|
2021-03-08 02:59:07 +00:00
|
|
|
static const BITMAPS iconsPinsOrientations[] =
|
2020-08-21 15:54:24 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS::pinorient_right,
|
|
|
|
BITMAPS::pinorient_left,
|
|
|
|
BITMAPS::pinorient_up,
|
|
|
|
BITMAPS::pinorient_down,
|
2020-08-21 15:54:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-07-27 03:46:15 +00:00
|
|
|
// clang-format off
|
|
|
|
std::map<PIN_ORIENTATION, struct pinShapeStruct> pinOrientations = {
|
|
|
|
{ PIN_ORIENTATION::PIN_RIGHT, { _( "Right" ), BITMAPS::pinorient_right } },
|
|
|
|
{ PIN_ORIENTATION::PIN_LEFT, { _( "Left" ), BITMAPS::pinorient_left } },
|
|
|
|
{ PIN_ORIENTATION::PIN_UP, { _( "Up" ), BITMAPS::pinorient_up } },
|
|
|
|
{ PIN_ORIENTATION::PIN_DOWN, { _( "Down" ), BITMAPS::pinorient_down } },
|
|
|
|
};
|
|
|
|
// clang-format on
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
|
2023-07-27 03:46:15 +00:00
|
|
|
PIN_ORIENTATION PinOrientationCode( size_t index )
|
2020-08-21 15:54:24 +00:00
|
|
|
{
|
2023-07-27 03:46:15 +00:00
|
|
|
wxASSERT( index < magic_enum::enum_count<PIN_ORIENTATION>() );
|
|
|
|
return magic_enum::enum_value<PIN_ORIENTATION>( index );
|
2020-08-21 15:54:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-27 03:46:15 +00:00
|
|
|
int PinOrientationIndex( PIN_ORIENTATION code )
|
2020-08-21 15:54:24 +00:00
|
|
|
{
|
2023-07-27 03:46:15 +00:00
|
|
|
auto index = magic_enum::enum_index<PIN_ORIENTATION>( code );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
2023-07-27 03:46:15 +00:00
|
|
|
if( index.has_value() )
|
|
|
|
return index.value();
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
return wxNOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InitTables()
|
|
|
|
{
|
|
|
|
for( unsigned i = 0; i < ELECTRICAL_PINTYPES_TOTAL; ++i )
|
|
|
|
{
|
|
|
|
g_typeIcons.push_back( ElectricalPinTypeGetBitmap( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
|
|
|
|
g_typeNames.push_back( ElectricalPinTypeGetText( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < GRAPHIC_PINSHAPES_TOTAL; ++i )
|
|
|
|
{
|
|
|
|
g_shapeIcons.push_back( PinShapeGetBitmap( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
|
|
|
|
g_shapeNames.push_back( PinShapeGetText( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
|
|
|
|
}
|
|
|
|
|
2023-07-27 03:46:15 +00:00
|
|
|
for( PIN_ORIENTATION orientation : magic_enum::enum_values<PIN_ORIENTATION>() )
|
2020-08-21 15:54:24 +00:00
|
|
|
{
|
2023-07-27 03:46:15 +00:00
|
|
|
g_orientationIcons.push_back( PinOrientationGetBitmap( orientation ) );
|
|
|
|
g_orientationNames.push_back( PinOrientationName( orientation ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxArrayString& PinTypeNames()
|
|
|
|
{
|
2020-11-24 22:16:41 +00:00
|
|
|
if( g_typeNames.empty() )
|
2020-08-21 15:54:24 +00:00
|
|
|
InitTables();
|
|
|
|
|
|
|
|
return g_typeNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
const std::vector<BITMAPS>& PinTypeIcons()
|
2020-08-21 15:54:24 +00:00
|
|
|
{
|
2020-11-24 22:16:41 +00:00
|
|
|
if( g_typeIcons.empty() )
|
2020-08-21 15:54:24 +00:00
|
|
|
InitTables();
|
|
|
|
|
|
|
|
return g_typeIcons;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxArrayString& PinShapeNames()
|
|
|
|
{
|
2020-11-24 22:16:41 +00:00
|
|
|
if( g_shapeNames.empty() )
|
2020-08-21 15:54:24 +00:00
|
|
|
InitTables();
|
|
|
|
|
|
|
|
return g_shapeNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
const std::vector<BITMAPS>& PinShapeIcons()
|
2020-08-21 15:54:24 +00:00
|
|
|
{
|
2020-11-24 22:16:41 +00:00
|
|
|
if( g_shapeIcons.empty() )
|
2020-08-21 15:54:24 +00:00
|
|
|
InitTables();
|
|
|
|
|
|
|
|
return g_shapeIcons;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxArrayString& PinOrientationNames()
|
|
|
|
{
|
2020-11-24 22:16:41 +00:00
|
|
|
if( g_orientationNames.empty() )
|
2020-08-21 15:54:24 +00:00
|
|
|
InitTables();
|
|
|
|
|
|
|
|
return g_orientationNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
const std::vector<BITMAPS>& PinOrientationIcons()
|
2020-08-21 15:54:24 +00:00
|
|
|
{
|
2020-11-24 22:16:41 +00:00
|
|
|
if( g_orientationIcons.empty() )
|
2020-08-21 15:54:24 +00:00
|
|
|
InitTables();
|
|
|
|
|
|
|
|
return g_orientationIcons;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-29 15:03:40 +00:00
|
|
|
wxString ElectricalPinTypeGetText( ELECTRICAL_PINTYPE aType )
|
2020-01-18 20:51:28 +00:00
|
|
|
{
|
2022-04-05 12:15:27 +00:00
|
|
|
if( g_pinTypesLanguage != Pgm().GetSelectedLanguageIdentifier() )
|
|
|
|
{
|
|
|
|
g_pinTypes[ELECTRICAL_PINTYPE::PT_INPUT].name = _( "Input" );
|
|
|
|
g_pinTypes[ELECTRICAL_PINTYPE::PT_OUTPUT].name = _( "Output" );
|
|
|
|
g_pinTypes[ELECTRICAL_PINTYPE::PT_BIDI].name = _( "Bidirectional" );
|
|
|
|
g_pinTypes[ELECTRICAL_PINTYPE::PT_TRISTATE].name = _( "Tri-state" );
|
|
|
|
g_pinTypes[ELECTRICAL_PINTYPE::PT_PASSIVE].name = _( "Passive" );
|
|
|
|
g_pinTypes[ELECTRICAL_PINTYPE::PT_NIC].name = _( "Free" );
|
|
|
|
g_pinTypes[ELECTRICAL_PINTYPE::PT_UNSPECIFIED].name = _( "Unspecified" );
|
|
|
|
g_pinTypes[ELECTRICAL_PINTYPE::PT_POWER_IN].name = _( "Power input" );
|
|
|
|
g_pinTypes[ELECTRICAL_PINTYPE::PT_POWER_OUT].name = _( "Power output" );
|
|
|
|
g_pinTypes[ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR].name = _( "Open collector" );
|
|
|
|
g_pinTypes[ELECTRICAL_PINTYPE::PT_OPENEMITTER].name = _( "Open emitter" );
|
|
|
|
g_pinTypes[ELECTRICAL_PINTYPE::PT_NC].name = _( "Unconnected" );
|
|
|
|
|
|
|
|
g_pinTypesLanguage = Pgm().GetSelectedLanguageIdentifier();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto findIt = g_pinTypes.find( aType );
|
2016-02-28 17:33:29 +00:00
|
|
|
|
2022-04-05 12:15:27 +00:00
|
|
|
wxCHECK_MSG( findIt != g_pinTypes.end(), wxT( "???" ), wxT( "Pin type not found!" ) );
|
2016-02-28 17:33:29 +00:00
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
return findIt->second.name;
|
2016-02-28 17:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS ElectricalPinTypeGetBitmap( ELECTRICAL_PINTYPE aType )
|
2016-02-28 17:33:29 +00:00
|
|
|
{
|
2022-04-05 12:15:27 +00:00
|
|
|
auto findIt = g_pinTypes.find( aType );
|
2016-02-28 17:33:29 +00:00
|
|
|
|
2022-04-05 12:15:27 +00:00
|
|
|
wxCHECK_MSG( findIt != g_pinTypes.end(), BITMAPS::INVALID_BITMAP, wxT( "Pin type not found!" ) );
|
2016-02-28 17:33:29 +00:00
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
return findIt->second.bitmap;
|
2016-02-28 17:33:29 +00:00
|
|
|
}
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
wxString PinShapeGetText( GRAPHIC_PINSHAPE aShape )
|
|
|
|
{
|
|
|
|
auto findIt = pinShapes.find( aShape );
|
|
|
|
|
2022-04-05 12:15:27 +00:00
|
|
|
wxCHECK_MSG( findIt != pinShapes.end(), wxT( "?" ), wxT( "Pin type not found!" ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
return findIt->second.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS PinShapeGetBitmap( GRAPHIC_PINSHAPE aShape )
|
2020-08-21 15:54:24 +00:00
|
|
|
{
|
|
|
|
auto findIt = pinShapes.find( aShape );
|
|
|
|
|
2022-04-05 12:15:27 +00:00
|
|
|
wxCHECK_MSG( findIt != pinShapes.end(), BITMAPS::INVALID_BITMAP, wxT( "Pin type not found!" ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
return findIt->second.bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-27 03:46:15 +00:00
|
|
|
wxString PinOrientationName( PIN_ORIENTATION aOrientation )
|
|
|
|
{
|
|
|
|
auto findIt = pinOrientations.find( aOrientation );
|
|
|
|
|
|
|
|
wxCHECK_MSG( findIt != pinOrientations.end(), wxT( "?" ), wxT( "Pin orientation not found!" ) );
|
|
|
|
|
|
|
|
return findIt->second.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BITMAPS PinOrientationGetBitmap( PIN_ORIENTATION aOrientation )
|
|
|
|
{
|
|
|
|
auto findIt = pinOrientations.find( aOrientation );
|
|
|
|
|
|
|
|
wxCHECK_MSG( findIt != pinOrientations.end(), BITMAPS::INVALID_BITMAP,
|
|
|
|
wxT( "Pin orientation not found!" ) );
|
|
|
|
|
|
|
|
return findIt->second.bitmap;
|
|
|
|
}
|