diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 15375470f0..e68a5e800f 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -13,6 +13,7 @@ include_directories( BEFORE ${INC_BEFORE} ) include_directories( ./dialogs ./netlist_exporters + ./widgets ../common ../common/dialogs ${INC_AFTER} @@ -72,6 +73,8 @@ set( EESCHEMA_DLGS set( EESCHEMA_WIDGETS widgets/widget_eeschema_color_config.cpp + widgets/pin_shape_combobox.cpp + widgets/pin_type_combobox.cpp ) @@ -137,6 +140,8 @@ set( EESCHEMA_SRCS operations_on_items_lists.cpp pinedit.cpp pin_number.cpp + pin_shape.cpp + pin_type.cpp plot_schematic_DXF.cpp plot_schematic_HPGL.cpp plot_schematic_PS.cpp diff --git a/eeschema/dialogs/dialog_edit_label.cpp b/eeschema/dialogs/dialog_edit_label.cpp index e861a394e5..2bdb1676c8 100644 --- a/eeschema/dialogs/dialog_edit_label.cpp +++ b/eeschema/dialogs/dialog_edit_label.cpp @@ -301,7 +301,8 @@ void DIALOG_LABEL_EDITOR::TextPropertiesAccept( wxCommandEvent& aEvent ) m_CurrentText->SetSize( wxSize( value, value ) ); if( m_TextShape ) - m_CurrentText->SetShape( m_TextShape->GetSelection() ); + /// @todo move cast to widget + m_CurrentText->SetShape( static_cast( m_TextShape->GetSelection() ) ); int style = m_TextStyle->GetSelection(); diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index 3186bf5df3..5f15760f52 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -49,8 +49,8 @@ #include #include -extern int DiagErc[PIN_NMAX][PIN_NMAX]; -extern int DefaultDiagErc[PIN_NMAX][PIN_NMAX]; +extern int DiagErc[PINTYPE_COUNT][PINTYPE_COUNT]; +extern int DefaultDiagErc[PINTYPE_COUNT][PINTYPE_COUNT]; @@ -63,7 +63,7 @@ bool DIALOG_ERC::m_tstUniqueGlobalLabels = true; // saved only for the curren #define ID_MATRIX_0 1800 BEGIN_EVENT_TABLE( DIALOG_ERC, DIALOG_ERC_BASE ) - EVT_COMMAND_RANGE( ID_MATRIX_0, ID_MATRIX_0 + ( PIN_NMAX * PIN_NMAX ) - 1, + EVT_COMMAND_RANGE( ID_MATRIX_0, ID_MATRIX_0 + ( PINTYPE_COUNT * PINTYPE_COUNT ) - 1, wxEVT_COMMAND_BUTTON_CLICKED, DIALOG_ERC::ChangeErrorLevel ) END_EVENT_TABLE() @@ -91,9 +91,9 @@ void DIALOG_ERC::Init() { m_initialized = false; - for( int ii = 0; ii < PIN_NMAX; ii++ ) + for( int ii = 0; ii < PINTYPE_COUNT; ii++ ) { - for( int jj = 0; jj < PIN_NMAX; jj++ ) + for( int jj = 0; jj < PINTYPE_COUNT; jj++ ) m_buttonList[ii][jj] = NULL; } @@ -290,7 +290,7 @@ void DIALOG_ERC::ReBuildMatrixPanel() if( m_initialized == false ) { // Print row labels - for( int ii = 0; ii < PIN_NMAX; ii++ ) + for( int ii = 0; ii < PINTYPE_COUNT; ii++ ) { int y = pos.y + (ii * bitmap_size.y); text = new wxStaticText( m_matrixPanel, -1, CommentERC_H[ii], @@ -305,7 +305,7 @@ void DIALOG_ERC::ReBuildMatrixPanel() else pos = m_buttonList[0][0]->GetPosition(); - for( int ii = 0; ii < PIN_NMAX; ii++ ) + for( int ii = 0; ii < PINTYPE_COUNT; ii++ ) { int y = pos.y + (ii * bitmap_size.y); @@ -323,7 +323,7 @@ void DIALOG_ERC::ReBuildMatrixPanel() text = new wxStaticText( m_matrixPanel, -1, CommentERC_V[ii], txtpos ); } - int event_id = ID_MATRIX_0 + ii + ( jj * PIN_NMAX ); + int event_id = ID_MATRIX_0 + ii + ( jj * PINTYPE_COUNT ); BITMAP_DEF bitmap_butt = erc_green_xpm; delete m_buttonList[ii][jj]; @@ -420,7 +420,7 @@ void DIALOG_ERC::ChangeErrorLevel( wxCommandEvent& event ) wxBitmapButton* butt = (wxBitmapButton*) event.GetEventObject(); pos = butt->GetPosition(); - x = ii / PIN_NMAX; y = ii % PIN_NMAX; + x = ii / PINTYPE_COUNT; y = ii % PINTYPE_COUNT; level = DiagErc[y][x]; diff --git a/eeschema/dialogs/dialog_erc.h b/eeschema/dialogs/dialog_erc.h index d7d9ff869f..9cce8b1a1e 100644 --- a/eeschema/dialogs/dialog_erc.h +++ b/eeschema/dialogs/dialog_erc.h @@ -27,7 +27,7 @@ #include #include -#include // For PIN_NMAX definition +#include // For PINTYPE_COUNT definition #include #include "dialog_erc_listbox.h" @@ -40,7 +40,7 @@ class DIALOG_ERC : public DIALOG_ERC_BASE private: SCH_EDIT_FRAME* m_parent; - wxBitmapButton* m_buttonList[PIN_NMAX][PIN_NMAX]; + wxBitmapButton* m_buttonList[PINTYPE_COUNT][PINTYPE_COUNT]; bool m_initialized; const SCH_MARKER* m_lastMarkerFound; static bool m_writeErcFile; diff --git a/eeschema/dialogs/dialog_lib_edit_pin.cpp b/eeschema/dialogs/dialog_lib_edit_pin.cpp index f19c125bfb..bdcf7077d1 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin.cpp +++ b/eeschema/dialogs/dialog_lib_edit_pin.cpp @@ -133,7 +133,7 @@ void DIALOG_LIB_EDIT_PIN::OnPropertiesChange( wxCommandEvent& event ) int pinNumSize = ValueFromString( g_UserUnit, GetPadNameTextSize()); int pinOrient = LIB_PIN::GetOrientationCode( GetOrientation() ); int pinLength = ValueFromString( g_UserUnit, GetLength() ); - int pinShape = LIB_PIN::GetStyleCode( GetStyle() ); + GRAPHIC_PINSHAPE pinShape = GetStyle(); ELECTRICAL_PINTYPE pinType = GetElectricalType(); m_dummyPin->SetName( GetPinName() ); @@ -161,28 +161,3 @@ void DIALOG_LIB_EDIT_PIN::SetOrientationList( const wxArrayString& list, m_choiceOrientation->Insert( list[ii], KiBitmap( aBitmaps[ii] ), ii ); } } - - -void DIALOG_LIB_EDIT_PIN::SetElectricalTypeList( const wxArrayString& list, - const BITMAP_DEF* aBitmaps ) -{ - for ( unsigned ii = 0; ii < list.GetCount(); ii++ ) - { - if( aBitmaps == NULL ) - m_choiceElectricalType->Append( list[ii] ); - else - m_choiceElectricalType->Insert( list[ii], KiBitmap( aBitmaps[ii] ), ii ); - } -} - - -void DIALOG_LIB_EDIT_PIN::SetStyleList( const wxArrayString& list, const BITMAP_DEF* aBitmaps ) -{ - for ( unsigned ii = 0; ii < list.GetCount(); ii++ ) - { - if( aBitmaps == NULL ) - m_choiceStyle->Append( list[ii] ); - else - m_choiceStyle->Insert( list[ii], KiBitmap( aBitmaps[ii] ), ii ); - } -} diff --git a/eeschema/dialogs/dialog_lib_edit_pin.h b/eeschema/dialogs/dialog_lib_edit_pin.h index 7df0792ee0..ba4063ebe4 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin.h +++ b/eeschema/dialogs/dialog_lib_edit_pin.h @@ -31,6 +31,8 @@ */ #include +#include +#include #include @@ -59,22 +61,18 @@ public: } int GetOrientation( void ) { return m_choiceOrientation->GetSelection(); } - void SetElectricalTypeList( const wxArrayString& list, const BITMAP_DEF* aBitmaps ); - void SetElectricalType( int type ) + void SetElectricalType( ELECTRICAL_PINTYPE type ) { m_choiceElectricalType->SetSelection( type ); } ELECTRICAL_PINTYPE GetElectricalType( void ) { - // m_choiceElectricalType is expected having the eletrical type names - // order indentical to the ELECTRICAL_PINTYPE enum - return (ELECTRICAL_PINTYPE)m_choiceElectricalType->GetSelection(); + return m_choiceElectricalType->GetSelection(); } - void SetStyleList( const wxArrayString& list, const BITMAP_DEF* aBitmaps ); - void SetStyle( int style ) { m_choiceStyle->SetSelection( style ); } - int GetStyle( void ) { return m_choiceStyle->GetSelection(); } + void SetStyle( GRAPHIC_PINSHAPE style ) { m_choiceStyle->SetSelection( style ); } + GRAPHIC_PINSHAPE GetStyle( void ) { return m_choiceStyle->GetSelection(); } void SetPinName( const wxString& name ) { m_textPinName->SetValue( name ); } wxString GetPinName( void ) { return m_textPinName->GetValue(); } diff --git a/eeschema/dialogs/dialog_lib_edit_pin_base.cpp b/eeschema/dialogs/dialog_lib_edit_pin_base.cpp index e0f439b045..920a586df2 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_base.cpp +++ b/eeschema/dialogs/dialog_lib_edit_pin_base.cpp @@ -5,6 +5,8 @@ // PLEASE DO "NOT" EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// +#include "pin_shape_combobox.h" +#include "pin_type_combobox.h" #include "wx/bmpcbox.h" #include "dialog_lib_edit_pin_base.h" @@ -61,14 +63,14 @@ DIALOG_LIB_EDIT_PIN_BASE::DIALOG_LIB_EDIT_PIN_BASE( wxWindow* parent, wxWindowID fgSizerPins->Add( m_staticTextEType, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 ); - m_choiceElectricalType = new wxBitmapComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); + m_choiceElectricalType = new PinTypeComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); fgSizerPins->Add( m_choiceElectricalType, 0, wxEXPAND|wxTOP|wxBOTTOM, 5 ); m_staticTextGstyle = new wxStaticText( this, wxID_ANY, _("Graphic &Style:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextGstyle->Wrap( -1 ); fgSizerPins->Add( m_staticTextGstyle, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 ); - m_choiceStyle = new wxBitmapComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); + m_choiceStyle = new PinShapeComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); fgSizerPins->Add( m_choiceStyle, 0, wxEXPAND|wxTOP|wxBOTTOM, 5 ); diff --git a/eeschema/dialogs/dialog_lib_edit_pin_base.fbp b/eeschema/dialogs/dialog_lib_edit_pin_base.fbp index 9afa0bf33f..43b1debb67 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_base.fbp +++ b/eeschema/dialogs/dialog_lib_edit_pin_base.fbp @@ -784,7 +784,7 @@ 1 wxCB_READONLY - wxBitmapComboBox; wx/bmpcbox.h + PinTypeComboBox; pin_type_combobox.h 0 @@ -958,7 +958,7 @@ 1 wxCB_READONLY - wxBitmapComboBox; wx/bmpcbox.h + PinShapeComboBox; pin_shape_combobox.h 0 diff --git a/eeschema/dialogs/dialog_lib_edit_pin_base.h b/eeschema/dialogs/dialog_lib_edit_pin_base.h index 04729809d9..e8b46e9629 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_base.h +++ b/eeschema/dialogs/dialog_lib_edit_pin_base.h @@ -12,6 +12,8 @@ #include #include class DIALOG_SHIM; +class PinShapeComboBox; +class PinTypeComboBox; class wxBitmapComboBox; #include "dialog_shim.h" @@ -64,9 +66,9 @@ class DIALOG_LIB_EDIT_PIN_BASE : public DIALOG_SHIM wxStaticText* m_staticTextOrient; wxBitmapComboBox* m_choiceOrientation; wxStaticText* m_staticTextEType; - wxBitmapComboBox* m_choiceElectricalType; + PinTypeComboBox* m_choiceElectricalType; wxStaticText* m_staticTextGstyle; - wxBitmapComboBox* m_choiceStyle; + PinShapeComboBox* m_choiceStyle; wxCheckBox* m_checkApplyToAllParts; wxCheckBox* m_checkApplyToAllConversions; wxCheckBox* m_checkShow; diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp index 369a227e54..047f737fa9 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp +++ b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp @@ -183,7 +183,7 @@ DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE( wxWindow* parent, 100, wxAlignment( wxALIGN_LEFT | wxALIGN_TOP ), wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE ); - wxDataViewTextRenderer* rend2 = new wxDataViewTextRenderer( wxT( "string" ), wxDATAVIEW_CELL_INERT ); + wxDataViewIconTextRenderer* rend2 = new wxDataViewIconTextRenderer( wxT( "wxDataViewIconText" ), wxDATAVIEW_CELL_INERT ); wxDataViewColumn* col2 = new wxDataViewColumn( _( "Type" ), rend2, DataViewModel::PIN_TYPE, @@ -255,7 +255,23 @@ unsigned int DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetColumnCount() const wxString DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetColumnType( unsigned int aCol ) const { - return wxT( "string" ); + switch( aCol ) + { + case PIN_NUMBER: + return wxT( "string" ); + + case PIN_NAME: + return wxT( "string" ); + + case PIN_TYPE: + return wxT( "wxDataViewIconText" ); + + case PIN_POSITION: + return wxT( "string" ); + } + + assert( ! "Unhandled column" ); + return wxT( "" ); } @@ -431,8 +447,20 @@ void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Group::GetValue( wxVariant& aValu if( aCol == m_GroupingColumn ) // shortcut m_Members.front()->GetValue( aValue, aCol ); - else + else if( aCol != PIN_TYPE ) aValue = GetString( aCol ); + else + { + PinNumbers values; + + for( std::list::const_iterator i = m_Members.begin(); i != m_Members.end(); ++i ) + values.insert( (*i)->GetString( aCol ) ); + + if( values.size() > 1 ) + aValue << wxDataViewIconText( boost::algorithm::join( values, "," ), wxNullIcon ); + else + m_Members.front()->GetValue( aValue, aCol ); + } } @@ -476,7 +504,22 @@ void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Group::Add( Pin* aPin ) void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Pin::GetValue( wxVariant& aValue, unsigned int aCol ) const { - aValue = GetString( aCol ); + switch( aCol ) + { + case PIN_NUMBER: + case PIN_NAME: + case PIN_POSITION: + aValue = GetString( aCol ); + break; + + case PIN_TYPE: + { + wxIcon icon; + icon.CopyFromBitmap( KiBitmap ( GetBitmap( m_Backing->GetType() ) ) ); + aValue << wxDataViewIconText( m_Backing->GetElectricalTypeName(), icon ); + } + break; + } } diff --git a/eeschema/dialogs/dialog_sch_edit_sheet_pin.h b/eeschema/dialogs/dialog_sch_edit_sheet_pin.h index fc35864d39..4d02b0145b 100644 --- a/eeschema/dialogs/dialog_sch_edit_sheet_pin.h +++ b/eeschema/dialogs/dialog_sch_edit_sheet_pin.h @@ -34,6 +34,9 @@ #include +// enum TypeSheetLabel +#include + class DIALOG_SCH_EDIT_SHEET_PIN : public DIALOG_SCH_EDIT_SHEET_PIN_BASE { @@ -49,8 +52,9 @@ public: void SetTextWidth( const wxString& aWidth ) { m_textWidth->SetValue( aWidth ); } wxString GetTextWidth() const { return m_textWidth->GetValue(); } - void SetConnectionType( int aType ) { m_choiceConnectionType->SetSelection( aType ); } - int GetConnectionType() const { return m_choiceConnectionType->GetCurrentSelection(); } + void SetConnectionType( TypeSheetLabel aType ) { m_choiceConnectionType->SetSelection( aType ); } + /// @todo move cast to widget + TypeSheetLabel GetConnectionType() const { return static_cast( m_choiceConnectionType->GetCurrentSelection() ); } void SetTextHeightUnits( const wxString& aUnit ) { m_staticHeightUnits->SetLabel( aUnit ); } void SetTextWidthUnits( const wxString& aUnit ) { m_staticWidthUnits->SetLabel( aUnit ); } diff --git a/eeschema/edit_label.cpp b/eeschema/edit_label.cpp index 2be1d87b16..2d8b2434f2 100644 --- a/eeschema/edit_label.cpp +++ b/eeschema/edit_label.cpp @@ -41,10 +41,10 @@ #include -static int lastGlobalLabelShape = (int) NET_INPUT; -static int lastTextOrientation = 0; -static bool lastTextBold = false; -static bool lastTextItalic = false; +static TypeSheetLabel lastGlobalLabelShape = NET_INPUT; +static int lastTextOrientation = 0; +static bool lastTextBold = false; +static bool lastTextItalic = false; void SCH_EDIT_FRAME::ChangeTextOrient( SCH_TEXT* aTextItem, wxDC* aDC ) diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp index 60eb82e55f..a9ef183b1a 100644 --- a/eeschema/erc.cpp +++ b/eeschema/erc.cpp @@ -121,7 +121,7 @@ const wxString CommentERC_V[] = * at start up: must be loaded by DefaultDiagErc * Can be modified in dialog ERC */ -int DiagErc[PIN_NMAX][PIN_NMAX]; +int DiagErc[PINTYPE_COUNT][PINTYPE_COUNT]; /** * Default Look up table which gives the ERC error level for a pair of connected pins @@ -130,7 +130,7 @@ int DiagErc[PIN_NMAX][PIN_NMAX]; * note also, to avoid inconsistancy: * DefaultDiagErc[i][j] = DefaultDiagErc[j][i] */ -int DefaultDiagErc[PIN_NMAX][PIN_NMAX] = +int DefaultDiagErc[PINTYPE_COUNT][PINTYPE_COUNT] = { /* I, O, Bi, 3S, Pas, UnS, PwrI, PwrO, OC, OE, NC */ /* I */ { OK, OK, OK, OK, OK, WAR, OK, OK, OK, OK, ERR }, @@ -157,7 +157,7 @@ int DefaultDiagErc[PIN_NMAX][PIN_NMAX] = * in net. Nets are OK when their final state is NET_NC or DRV. Nets with the state * NOD have no valid source signal. */ -static int MinimalReq[PIN_NMAX][PIN_NMAX] = +static int MinimalReq[PINTYPE_COUNT][PINTYPE_COUNT] = { /* In Out, Bi, 3S, Pas, UnS, PwrI,PwrO,OC, OE, NC */ /* In*/ { NOD, DRV, DRV, DRV, DRV, DRV, NOD, DRV, DRV, DRV, NPI }, @@ -228,9 +228,9 @@ int TestDuplicateSheetNames( bool aCreateMarker ) void Diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItemTst, int aMinConn, int aDiag ) { - SCH_MARKER* marker = NULL; - SCH_SCREEN* screen; - int ii, jj; + SCH_MARKER* marker = NULL; + SCH_SCREEN* screen; + ELECTRICAL_PINTYPE ii, jj; if( aDiag == OK ) return; @@ -297,7 +297,7 @@ void Diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItemTst, { msg.Printf( _( "Pin %s (%s) of component %s is unconnected." ), GetChars( string_pinnum ), - GetChars( LIB_PIN::GetElectricalTypeName( ii ) ), + GetChars( GetText( ii ) ), GetChars( cmp_ref ) ); marker->SetData( ERCE_PIN_NOT_CONNECTED, aNetItemRef->m_Start, @@ -314,7 +314,7 @@ void Diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItemTst, msg.Printf( _( "Pin %s (%s) of component %s is not driven (Net %d)." ), GetChars( string_pinnum ), - GetChars( LIB_PIN::GetElectricalTypeName( ii ) ), + GetChars( GetText( ii ) ), GetChars( cmp_ref ), aNetItemRef->GetNet() ); marker->SetData( ERCE_PIN_NOT_DRIVEN, @@ -356,12 +356,12 @@ void Diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItemTst, msg.Printf( _( "Pin %s (%s) of component %s is connected to " ), GetChars( string_pinnum ), - GetChars( LIB_PIN::GetElectricalTypeName( ii ) ), + GetChars( GetText( ii ) ), GetChars( cmp_ref ) ); marker->SetData( errortype, aNetItemRef->m_Start, msg, aNetItemRef->m_Start ); msg.Printf( _( "pin %s (%s) of component %s (net %d)." ), GetChars( alt_string_pinnum ), - GetChars( LIB_PIN::GetElectricalTypeName( jj ) ), + GetChars( GetText( jj ) ), GetChars( alt_cmp ), aNetItemRef->GetNet() ); marker->SetAuxiliaryData( msg, aNetItemTst->m_Start ); @@ -374,7 +374,7 @@ void TestOthersItems( NETLIST_OBJECT_LIST* aList, int* aMinConnexion ) { unsigned netItemTst = aNetStart; - int jj; + ELECTRICAL_PINTYPE jj; int erc = OK; /* Analysis of the table of connections. */ diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp index bbf7819f04..0ca0d878d6 100644 --- a/eeschema/lib_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -70,60 +70,10 @@ static const BITMAP_DEF iconsPinsOrientations[] = }; -// bitmaps to show pins shapes in dialog editor -// must have same order than pin_style_names -static BITMAP_DEF iconsPinsShapes[] = +const wxString LIB_PIN::GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType ) { - pinshape_normal_xpm, - pinshape_invert_xpm, - pinshape_clock_normal_xpm, - pinshape_clock_invert_xpm, - pinshape_active_low_input_xpm, - pinshape_clock_active_low_xpm, - pinshape_active_low_output_xpm, - pinshape_clock_fall_xpm, - pinshape_nonlogic_xpm -}; + assert( aType >= 0 && aType < (int) PINTYPE_COUNT ); - - -static const int pin_style_codes[] = -{ - NONE, - INVERT, - CLOCK, - CLOCK | INVERT, - LOWLEVEL_IN, - LOWLEVEL_IN | CLOCK, - LOWLEVEL_OUT, - CLOCK_FALL, - NONLOGIC -}; - -#define PIN_STYLE_CNT DIM( pin_style_codes ) - -// bitmaps to show pins electrical type in dialog editor -// must have same order than enum ELECTRICAL_PINTYPE (see lib_pin.h) -static const BITMAP_DEF iconsPinsElectricalType[] = -{ - pintype_input_xpm, - pintype_output_xpm, - pintype_bidi_xpm, - pintype_3states_xpm, - pintype_passive_xpm, - pintype_notspecif_xpm, - pintype_powerinput_xpm, - pintype_poweroutput_xpm, - pintype_opencoll_xpm, - pintype_openemit_xpm, - pintype_noconnect_xpm -}; - -#define PIN_ELECTRICAL_TYPE_CNT DIM( iconsPinsElectricalType ) - - -const wxString LIB_PIN::GetCanonicalElectricalTypeName( unsigned aType ) -{ // These strings are the canonical name of the electrictal type // Not translated, no space in name, only ASCII chars. // to use when the string name must be known and well defined @@ -140,12 +90,11 @@ const wxString LIB_PIN::GetCanonicalElectricalTypeName( unsigned aType ) wxT( "power_out" ), wxT( "openCol" ), wxT( "openEm" ), - wxT( "NotConnected" ), - wxT( "???" ) + wxT( "NotConnected" ) }; - if( aType > PIN_NMAX ) - aType = PIN_NMAX; + if( aType > (int) PINTYPE_COUNT ) + return wxT( "???" ); return msgPinElectricType[ aType ]; } @@ -176,53 +125,6 @@ static const wxString getPinOrientationName( unsigned aPinOrientationCode ) return pin_orientation_names[ aPinOrientationCode ]; } -const wxString LIB_PIN::GetElectricalTypeName( unsigned aPinsElectricalType ) -{ - const wxString pin_electrical_type_names[] = - { // Keep these translated strings not static - _( "Input" ), - _( "Output" ), - _( "Bidirectional" ), - _( "Tri-state" ), - _( "Passive" ), - _( "Unspecified" ), - _( "Power input" ), - _( "Power output" ), - _( "Open collector" ), - _( "Open emitter" ), - _( "Not connected" ), - wxT( "???" ) - }; - - if( aPinsElectricalType > PIN_ELECTRICAL_TYPE_CNT ) - aPinsElectricalType = PIN_ELECTRICAL_TYPE_CNT; - - return pin_electrical_type_names[ aPinsElectricalType ]; -} - -static const wxString getPinStyleName( unsigned aPinsStyle ) -{ - const wxString pin_style_names[] = - { // Keep these translated strings not static - _( "Line" ), - _( "Inverted" ), - _( "Clock" ), - _( "Inverted clock" ), - _( "Input low" ), - _( "Clock low" ), - _( "Output low" ), - _( "Falling edge clock" ), - _( "NonLogic" ), - wxT( "???" ) - }; - - if( aPinsStyle > PIN_STYLE_CNT ) - aPinsStyle = PIN_STYLE_CNT; - - return pin_style_names[ aPinsStyle ]; -} - - /// Utility for getting the size of the 'internal' pin decorators (as a radius) // i.e. the clock symbols (falling clock is actually external but is of // the same kind) @@ -241,11 +143,11 @@ static int ExternalPinDecoSize( const LIB_PIN &aPin ) } LIB_PIN::LIB_PIN( LIB_PART* aParent ) : - LIB_ITEM( LIB_PIN_T, aParent ) + LIB_ITEM( LIB_PIN_T, aParent ), + m_shape( PINSHAPE_LINE ) { m_length = LIB_EDIT_FRAME::GetDefaultPinLength(); m_orientation = PIN_RIGHT; // Pin orient: Up, Down, Left, Right - m_shape = NONE; // Pin shape, bitwise. m_type = PIN_UNSPECIFIED; // electrical type of pin m_attributes = 0; // bit 0 != 0: pin invisible m_number = 0; // pin number (i.e. 4 ASCII chars) @@ -378,8 +280,10 @@ void LIB_PIN::SetOrientation( int orientation ) } -void LIB_PIN::SetShape( int aShape ) +void LIB_PIN::SetShape( GRAPHIC_PINSHAPE aShape ) { + assert( aShape >= 0 && aShape < int( PINSHAPE_COUNT ) ); + if( m_shape != aShape ) { m_shape = aShape; @@ -407,10 +311,12 @@ void LIB_PIN::SetShape( int aShape ) void LIB_PIN::SetType( ELECTRICAL_PINTYPE aType ) { + assert( aType >= 0 && aType < (int) PINTYPE_COUNT ); + if( aType < PIN_INPUT ) aType = PIN_INPUT; - if( aType >= PIN_NMAX ) + if( aType >= PINTYPE_COUNT ) aType = PIN_NC; if( m_type != aType ) @@ -691,23 +597,55 @@ bool LIB_PIN::Save( OUTPUTFORMATTER& aFormatter ) if( !IsVisible() && aFormatter.Print( 0, "N" ) < 0 ) return false; - if( m_shape & INVERT && aFormatter.Print( 0, "I" ) < 0 ) - return false; + switch( m_shape ) + { + case PINSHAPE_LINE: + break; - if( m_shape & CLOCK && aFormatter.Print( 0, "C" ) < 0 ) - return false; + case PINSHAPE_INVERTED: + if( aFormatter.Print( 0, "I" ) < 0 ) + return false; + break; - if( m_shape & LOWLEVEL_IN && aFormatter.Print( 0, "L" ) < 0 ) - return false; + case PINSHAPE_CLOCK: + if( aFormatter.Print( 0, "C" ) < 0 ) + return false; + break; - if( m_shape & LOWLEVEL_OUT && aFormatter.Print( 0, "V" ) < 0 ) - return false; + case PINSHAPE_INVERTED_CLOCK: + if( aFormatter.Print( 0, "IC" ) < 0 ) + return false; + break; - if( m_shape & CLOCK_FALL && aFormatter.Print( 0, "F" ) < 0 ) - return false; + case PINSHAPE_INPUT_LOW: + if( aFormatter.Print( 0, "L" ) < 0 ) + return false; + break; - if( m_shape & NONLOGIC && aFormatter.Print( 0, "X" ) < 0 ) + case PINSHAPE_CLOCK_LOW: + if( aFormatter.Print( 0, "CL" ) < 0 ) + return false; + break; + + case PINSHAPE_OUTPUT_LOW: + if( aFormatter.Print( 0, "V" ) < 0 ) + return false; + break; + + case PINSHAPE_FALLING_EDGE_CLOCK: + if( aFormatter.Print( 0, "F" ) < 0 ) + return false; + break; + + case PINSHAPE_NONLOGIC: + if( aFormatter.Print( 0, "X" ) < 0 ) + return false; + break; + + default: + assert( !"Invalid pin shape" ); return false; + } if( aFormatter.Print( 0, "\n" ) < 0 ) return false; @@ -831,6 +769,18 @@ bool LIB_PIN::Load( LINE_READER& aLineReader, wxString& aErrorMsg ) if( prms_count >= 12 ) /* Special Symbol defined */ { + enum + { + INVERTED = 1 << 0, + CLOCK = 1 << 1, + LOWLEVEL_IN = 1 << 2, + LOWLEVEL_OUT = 1 << 3, + FALLING_EDGE = 1 << 4, + NONLOGIC = 1 << 5 + }; + + int flags = 0; + for( int j = strlen( pinAttrs ); j > 0; ) { switch( pinAttrs[--j] ) @@ -843,27 +793,27 @@ bool LIB_PIN::Load( LINE_READER& aLineReader, wxString& aErrorMsg ) break; case 'I': - m_shape |= INVERT; + flags |= INVERTED; break; case 'C': - m_shape |= CLOCK; + flags |= CLOCK; break; case 'L': - m_shape |= LOWLEVEL_IN; + flags |= LOWLEVEL_IN; break; case 'V': - m_shape |= LOWLEVEL_OUT; + flags |= LOWLEVEL_OUT; break; case 'F': - m_shape |= CLOCK_FALL; + flags |= FALLING_EDGE; break; case 'X': - m_shape |= NONLOGIC; + flags |= NONLOGIC; break; default: @@ -871,6 +821,49 @@ bool LIB_PIN::Load( LINE_READER& aLineReader, wxString& aErrorMsg ) return false; } } + + switch( flags ) + { + case 0: + m_shape = PINSHAPE_LINE; + break; + + case INVERTED: + m_shape = PINSHAPE_INVERTED; + break; + + case CLOCK: + m_shape = PINSHAPE_CLOCK; + break; + + case INVERTED | CLOCK: + m_shape = PINSHAPE_INVERTED_CLOCK; + break; + + case LOWLEVEL_IN: + m_shape = PINSHAPE_INPUT_LOW; + break; + + case LOWLEVEL_IN | CLOCK: + m_shape = PINSHAPE_CLOCK_LOW; + break; + + case LOWLEVEL_OUT: + m_shape = PINSHAPE_OUTPUT_LOW; + break; + + case FALLING_EDGE: + m_shape = PINSHAPE_FALLING_EDGE_CLOCK; + break; + + case NONLOGIC: + m_shape = PINSHAPE_NONLOGIC; + break; + + default: + aErrorMsg.Printf( wxT( "pin attributes do not give a valid pin shape [%s]" ), pinAttrs ); + return false; + } } return true; @@ -1021,7 +1014,7 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel, return; - if( m_shape & INVERT ) + if( m_shape == PINSHAPE_INVERTED || m_shape == PINSHAPE_INVERTED_CLOCK ) { const int radius = ExternalPinDecoSize( *this ); GRCircle( clipbox, aDC, MapX1 * radius + x1, @@ -1032,7 +1025,7 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel, MapY1 * radius * 2 + y1 ); GRLineTo( clipbox, aDC, posX, posY, width, color ); } - else if( m_shape & CLOCK_FALL ) /* an alternative for Inverted Clock */ + else if( m_shape == PINSHAPE_FALLING_EDGE_CLOCK ) /* an alternative for Inverted Clock */ { const int clock_size = InternalPinDecoSize( *this ); if( MapY1 == 0 ) /* MapX1 = +- 1 */ @@ -1059,7 +1052,7 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel, GRLineTo( clipbox, aDC, posX, posY, width, color ); } - if( m_shape & CLOCK ) + if( m_shape == PINSHAPE_CLOCK || m_shape == PINSHAPE_INVERTED_CLOCK || m_shape == PINSHAPE_CLOCK_LOW ) { const int clock_size = InternalPinDecoSize( *this ); if( MapY1 == 0 ) /* MapX1 = +- 1 */ @@ -1080,7 +1073,7 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel, } } - if( m_shape & LOWLEVEL_IN ) /* IEEE symbol "Active Low Input" */ + if( m_shape == PINSHAPE_INPUT_LOW || m_shape == PINSHAPE_CLOCK_LOW ) { const int symbol_size = ExternalPinDecoSize( *this ); if( MapY1 == 0 ) /* MapX1 = +- 1 */ @@ -1101,7 +1094,7 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel, } - if( m_shape & LOWLEVEL_OUT ) /* IEEE symbol "Active Low Output" */ + if( m_shape == PINSHAPE_OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */ { const int symbol_size = ExternalPinDecoSize( *this ); if( MapY1 == 0 ) /* MapX1 = +- 1 */ @@ -1121,7 +1114,7 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel, width, color ); } } - else if( m_shape & NONLOGIC ) /* NonLogic pin symbol */ + else if( m_shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */ { const int symbol_size = ExternalPinDecoSize( *this ); GRMoveTo( x1 - (MapX1 + MapY1) * symbol_size, @@ -1397,7 +1390,7 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie break; } - if( m_shape & INVERT ) + if( m_shape == PINSHAPE_INVERTED || m_shape == PINSHAPE_INVERTED_CLOCK ) { const int radius = ExternalPinDecoSize( *this ); aPlotter->Circle( wxPoint( MapX1 * radius + x1, @@ -1410,7 +1403,7 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie MapY1 * radius * 2 + y1 ) ); aPlotter->FinishTo( aPosition ); } - else if( m_shape & CLOCK_FALL ) + else if( m_shape == PINSHAPE_FALLING_EDGE_CLOCK ) { const int clock_size = InternalPinDecoSize( *this ); if( MapY1 == 0 ) /* MapX1 = +- 1 */ @@ -1436,7 +1429,8 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie aPlotter->FinishTo( aPosition ); } - if( m_shape & CLOCK ) + if( m_shape == PINSHAPE_CLOCK || m_shape == PINSHAPE_INVERTED_CLOCK || + m_shape == PINSHAPE_CLOCK_LOW ) { const int clock_size = InternalPinDecoSize( *this ); if( MapY1 == 0 ) /* MapX1 = +- 1 */ @@ -1453,7 +1447,7 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie } } - if( m_shape & LOWLEVEL_IN ) /* IEEE symbol "Active Low Input" */ + if( m_shape == PINSHAPE_INPUT_LOW || m_shape == PINSHAPE_CLOCK_LOW ) /* IEEE symbol "Active Low Input" */ { const int symbol_size = ExternalPinDecoSize( *this ); @@ -1474,7 +1468,7 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie } - if( m_shape & LOWLEVEL_OUT ) /* IEEE symbol "Active Low Output" */ + if( m_shape == PINSHAPE_OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */ { const int symbol_size = ExternalPinDecoSize( *this ); @@ -1489,7 +1483,7 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie aPlotter->FinishTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) ); } } - else if( m_shape & NONLOGIC ) /* NonLogic pin symbol */ + else if( m_shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */ { const int symbol_size = ExternalPinDecoSize( *this ); aPlotter->MoveTo( wxPoint( x1 - (MapX1 + MapY1) * symbol_size, @@ -1984,15 +1978,10 @@ void LIB_PIN::GetMsgPanelInfo( MSG_PANEL_ITEMS& aList ) aList.push_back( MSG_PANEL_ITEM( _( "Number" ), text, DARKCYAN ) ); aList.push_back( MSG_PANEL_ITEM( _( "Type" ), - LIB_PIN::GetElectricalTypeName( m_type ), + GetText( m_type ), RED ) ); - int styleCodeIndex = GetStyleCodeIndex( m_shape ); - - if( styleCodeIndex >= 0 ) - text = getPinStyleName( styleCodeIndex ); - else - text = wxT( "?" ); + text = GetText( m_shape ); aList.push_back( MSG_PANEL_ITEM( _( "Style" ), text, BLUE ) ); @@ -2042,7 +2031,7 @@ const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles ) const // Actual text height is bigger than text size int numberTextHeight = showNum ? KiROUND( m_numTextSize * 1.1 ) : 0; - if( m_shape & INVERT ) + if( m_shape == PINSHAPE_INVERTED || m_shape == PINSHAPE_INVERTED_CLOCK ) minsizeV = std::max( TARGET_PIN_RADIUS, ExternalPinDecoSize( *this ) ); // calculate top left corner position @@ -2187,72 +2176,15 @@ void LIB_PIN::Rotate() } -wxArrayString LIB_PIN::GetStyleNames( void ) -{ - wxArrayString tmp; - - for( unsigned ii = 0; ii < PIN_STYLE_CNT; ii++ ) - tmp.Add( getPinStyleName( ii ) ); - - return tmp; -} - - -int LIB_PIN::GetStyleCode( int index ) -{ - if( index >= 0 && index < (int) PIN_STYLE_CNT ) - return pin_style_codes[ index ]; - - return NONE; -} - - -int LIB_PIN::GetStyleCodeIndex( int code ) -{ - size_t i; - - for( i = 0; i < PIN_STYLE_CNT; i++ ) - { - if( pin_style_codes[i] == code ) - return (int) i; - } - - return wxNOT_FOUND; -} - - -wxArrayString LIB_PIN::GetElectricalTypeNames( void ) -{ - wxArrayString tmp; - - for( unsigned ii = 0; ii < PIN_ELECTRICAL_TYPE_CNT; ii++ ) - tmp.Add( LIB_PIN::GetElectricalTypeName( ii ) ); - - return tmp; -} - - -const BITMAP_DEF* LIB_PIN::GetElectricalTypeSymbols() -{ - return iconsPinsElectricalType; -} - - const BITMAP_DEF* LIB_PIN::GetOrientationSymbols() { return iconsPinsOrientations; } -const BITMAP_DEF* LIB_PIN::GetStyleSymbols() -{ - return iconsPinsShapes; -} - - BITMAP_DEF LIB_PIN::GetMenuImage() const { - return iconsPinsElectricalType[m_type]; + return GetBitmap( m_type ); } @@ -2261,12 +2193,7 @@ wxString LIB_PIN::GetSelectMenuText() const wxString tmp; wxString style; - int styleCode = GetStyleCodeIndex( m_shape ); - - if( styleCode >= 0 ) - style = getPinStyleName( styleCode ); - else - style = wxT( "?" ); + style = GetText( m_shape ); tmp.Printf( _( "Pin %s, %s, %s" ), GetChars( GetNumberString() ), diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h index 51f5f58783..7c0bb4bf32 100644 --- a/eeschema/lib_pin.h +++ b/eeschema/lib_pin.h @@ -32,46 +32,15 @@ #include +#include "pin_shape.h" +#include "pin_type.h" #define TARGET_PIN_RADIUS 12 // Circle diameter drawn at the active end of pins -/** - * The component library pin object electrical types used in ERC tests. - */ -enum ELECTRICAL_PINTYPE { - PIN_INPUT, - PIN_OUTPUT, - PIN_BIDI, - PIN_TRISTATE, - PIN_PASSIVE, - PIN_UNSPECIFIED, - PIN_POWER_IN, - PIN_POWER_OUT, - PIN_OPENCOLLECTOR, - PIN_OPENEMITTER, - PIN_NC, /* No connect */ - PIN_NMAX /* End of List (not used as pin type) */ -}; - - /* Pin visibility flag bit. */ #define PIN_INVISIBLE 1 /* Set makes pin invisible */ -/** - * The component library pin object drawing shapes. - */ -enum DrawPinShape { - NONE = 0, - INVERT = 1, - CLOCK = 2, - LOWLEVEL_IN = 4, - LOWLEVEL_OUT = 8, - CLOCK_FALL = 0x10, /* this is common form for inverted clock in Eastern Block */ - NONLOGIC = 0x20 -}; - - /** * The component library pin object orientations. */ @@ -94,7 +63,7 @@ class LIB_PIN : public LIB_ITEM wxPoint m_position; ///< Position of the pin. int m_length; ///< Length of the pin. int m_orientation; ///< Pin orientation (Up, Down, Left, Right) - int m_shape; ///< Bitwise ORed of pin shapes (see enum DrawPinShape) + GRAPHIC_PINSHAPE m_shape; ///< Shape drawn around pin int m_width; ///< Line width of the pin. ELECTRICAL_PINTYPE m_type; ///< Electrical type of the pin. See enum ELECTRICAL_PINTYPE. int m_attributes; ///< Set bit 0 to indicate pin is invisible. @@ -263,21 +232,21 @@ public: void Rotate(); - int GetShape() const { return m_shape; } + GRAPHIC_PINSHAPE GetShape() const { return m_shape; } /** * Set the shape of the pin to \a aShape. * * This will also update the draw style of the pins marked by EnableEditMode(). * - * @param aShape - The draw shape of the pin. See enum DrawPinShape. + * @param aShape - The draw shape of the pin. See enum GRAPHIC_PINSHAPE. */ - void SetShape( int aShape ); + void SetShape( GRAPHIC_PINSHAPE aShape ); /** * Get the electrical type of the pin. * - * @return The electrical type of the pin (see enun ELECTRICAL_PINTYPE for values). + * @return The electrical type of the pin (see enum ELECTRICAL_PINTYPE for values). */ ELECTRICAL_PINTYPE GetType() const { return m_type; } @@ -287,7 +256,7 @@ public: * @param aType is the electrical type (see enum ELECTRICAL_PINTYPE ) * @return The electrical name for a pin type (see enun MsgPinElectricType for names). */ - static const wxString GetCanonicalElectricalTypeName( unsigned aType ); + static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType ); /** * return a string giving the electrical type of the pin. @@ -299,20 +268,13 @@ public: return GetCanonicalElectricalTypeName( m_type ); } - /** - * return a translated string for messages giving the electrical type of a pin. - * @param aType is the electrical type (see enum ELECTRICAL_PINTYPE ) - * @return The electrical name of the pin (see enun MsgPinElectricType for names). - */ - static const wxString GetElectricalTypeName( unsigned aType ); - /** * return a translated string for messages giving the electrical type of the pin. * @return The electrical name of the pin. */ wxString const GetElectricalTypeName() const { - return GetElectricalTypeName( m_type ); + return GetText( m_type ); } /** @@ -478,52 +440,6 @@ public: */ static int GetOrientationCodeIndex( int aCode ); - /** - * Get a list of pin draw style names. - * - * @return List of valid pin draw style names. - */ - static wxArrayString GetStyleNames(); - - /** - * Get a list of pin styles bitmaps for menus and dialogs. - * - * @return List of valid pin electrical type bitmaps symbols in .xpm format. - */ - static const BITMAP_DEF* GetStyleSymbols(); - - /** - * Get the pin draw style code by index used to set the pin draw style. - * - * @param aIndex - The index of the pin draw style code to look up. - * @return Pin draw style code if index is valid. Returns NONE - * style on index error. - */ - static int GetStyleCode( int aIndex ); - - /** - * Get the index of the pin draw style code. - * - * @param aCode - The pin draw style code to look up. - * @return The index of the pin draw style code if found. Otherwise, - * return wxNOT_FOUND. - */ - static int GetStyleCodeIndex( int aCode ); - - /** - * Get a list of pin electrical type names. - * - * @return List of valid pin electrical type names. - */ - static wxArrayString GetElectricalTypeNames(); - - /** - * Get a list of pin electrical bitmaps for menus and dialogs. - * - * @return List of valid pin electrical type bitmaps symbols in .xpm format - */ - static const BITMAP_DEF* GetElectricalTypeSymbols(); - void SetOffset( const wxPoint& aOffset ); bool Inside( EDA_RECT& aRect ) const; diff --git a/eeschema/pin_shape.cpp b/eeschema/pin_shape.cpp new file mode 100644 index 0000000000..f59dbb4241 --- /dev/null +++ b/eeschema/pin_shape.cpp @@ -0,0 +1,104 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2004-2015 KiCad Developers, see change_log.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 + */ + +/** + * @file pin_shape.cpp + * @brief Pin shape handling + */ + +#include "pin_shape.h" + +#include + +wxString GetText( GRAPHIC_PINSHAPE shape ) +{ + switch( shape ) + { + case PINSHAPE_LINE: + return _( "Line" ); + + case PINSHAPE_INVERTED: + return _( "Inverted" ); + + case PINSHAPE_CLOCK: + return _( "Clock" ); + + case PINSHAPE_INVERTED_CLOCK: + return _( "Inverted clock" ); + + case PINSHAPE_INPUT_LOW: + return _( "Input low" ); + + case PINSHAPE_CLOCK_LOW: + return _( "Clock low" ); + + case PINSHAPE_OUTPUT_LOW: + return _( "Output low" ); + + case PINSHAPE_FALLING_EDGE_CLOCK: + return _( "Falling edge clock" ); + + case PINSHAPE_NONLOGIC: + return _( "NonLogic" ); + } + + assert( !"Invalid pin shape" ); + return wxT( "?" ); +} + + +BITMAP_DEF GetBitmap( GRAPHIC_PINSHAPE shape ) +{ + switch( shape ) + { + case PINSHAPE_LINE: + return pinshape_normal_xpm; + + case PINSHAPE_INVERTED: + return pinshape_invert_xpm; + + case PINSHAPE_CLOCK: + return pinshape_clock_normal_xpm; + + case PINSHAPE_INVERTED_CLOCK: + return pinshape_clock_invert_xpm; + + case PINSHAPE_INPUT_LOW: + return pinshape_active_low_input_xpm; + + case PINSHAPE_CLOCK_LOW: + return pinshape_clock_active_low_xpm; + + case PINSHAPE_OUTPUT_LOW: + return pinshape_active_low_output_xpm; + + case PINSHAPE_FALLING_EDGE_CLOCK: + return pinshape_clock_fall_xpm; + + case PINSHAPE_NONLOGIC: + return pinshape_nonlogic_xpm; + } + + assert( !"Invalid pin shape" ); + return 0; +}; diff --git a/eeschema/pin_shape.h b/eeschema/pin_shape.h new file mode 100644 index 0000000000..25f11b9828 --- /dev/null +++ b/eeschema/pin_shape.h @@ -0,0 +1,57 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2004-2015 KiCad Developers, see change_log.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 + */ + +/** + * @file pin_shape.h + * @brief Pin shape handling + */ + +#ifndef _PIN_SHAPE_H_ +#define _PIN_SHAPE_H_ + +#include +#include + +enum GRAPHIC_PINSHAPE +{ + PINSHAPE_LINE, + PINSHAPE_INVERTED, + PINSHAPE_CLOCK, + PINSHAPE_INVERTED_CLOCK, + PINSHAPE_INPUT_LOW, + PINSHAPE_CLOCK_LOW, + PINSHAPE_OUTPUT_LOW, + PINSHAPE_FALLING_EDGE_CLOCK, + PINSHAPE_NONLOGIC +}; + +enum +{ + PINSHAPE_COUNT = PINSHAPE_NONLOGIC + 1 +}; + +// UI +wxString GetText( GRAPHIC_PINSHAPE shape ); +BITMAP_DEF GetBitmap( GRAPHIC_PINSHAPE shape ); + +#endif diff --git a/eeschema/pin_type.cpp b/eeschema/pin_type.cpp new file mode 100644 index 0000000000..5b753a99d5 --- /dev/null +++ b/eeschema/pin_type.cpp @@ -0,0 +1,116 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2004-2015 KiCad Developers, see change_log.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 + */ + +/** + * @file pin_type.cpp + * @brief Electrical pin type handling + */ + +#include "pin_type.h" + +#include + +wxString GetText( ELECTRICAL_PINTYPE aType ) +{ + switch( aType ) + { + case PIN_INPUT: + return _( "Input" ); + + case PIN_OUTPUT: + return _( "Output" ); + + case PIN_BIDI: + return _( "Bidirectional" ); + + case PIN_TRISTATE: + return _( "Tri-state" ); + + case PIN_PASSIVE: + return _( "Passive" ); + + case PIN_UNSPECIFIED: + return _( "Unspecified" ); + + case PIN_POWER_IN: + return _( "Power input" ); + + case PIN_POWER_OUT: + return _( "Power output" ); + + case PIN_OPENCOLLECTOR: + return _( "Open collector" ); + + case PIN_OPENEMITTER: + return _( "Open emitter" ); + + case PIN_NC: + return _( "Not connected" ); + }; + + assert( !"invalid pin type" ); + return wxT( "???" ); +} + + +BITMAP_DEF GetBitmap( ELECTRICAL_PINTYPE aType ) +{ + switch( aType ) + { + case PIN_INPUT: + return pintype_input_xpm; + + case PIN_OUTPUT: + return pintype_output_xpm; + + case PIN_BIDI: + return pintype_bidi_xpm; + + case PIN_TRISTATE: + return pintype_3states_xpm; + + case PIN_PASSIVE: + return pintype_passive_xpm; + + case PIN_UNSPECIFIED: + return pintype_notspecif_xpm; + + case PIN_POWER_IN: + return pintype_powerinput_xpm; + + case PIN_POWER_OUT: + return pintype_poweroutput_xpm; + + case PIN_OPENCOLLECTOR: + return pintype_opencoll_xpm; + + case PIN_OPENEMITTER: + return pintype_openemit_xpm; + + case PIN_NC: + return pintype_noconnect_xpm; + }; + + assert( !"invalid pin type" ); + return NULL; +} diff --git a/eeschema/pin_type.h b/eeschema/pin_type.h new file mode 100644 index 0000000000..b8975c58fb --- /dev/null +++ b/eeschema/pin_type.h @@ -0,0 +1,59 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2004-2015 KiCad Developers, see change_log.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 + */ + +/** + * @file pin_type.h + * @brief Electrical pin type handling + */ +#ifndef PIN_TYPE_H_ +#define PIN_TYPE_H_ + +#include +#include + +/** + * The component library pin object electrical types used in ERC tests. + */ +enum ELECTRICAL_PINTYPE { + PIN_INPUT, + PIN_OUTPUT, + PIN_BIDI, + PIN_TRISTATE, + PIN_PASSIVE, + PIN_UNSPECIFIED, + PIN_POWER_IN, + PIN_POWER_OUT, + PIN_OPENCOLLECTOR, + PIN_OPENEMITTER, + PIN_NC /* No connect */ +}; + +enum { + PINTYPE_COUNT = PIN_NC + 1 +}; + +// UI +wxString GetText( ELECTRICAL_PINTYPE ); +BITMAP_DEF GetBitmap( ELECTRICAL_PINTYPE ); + +#endif diff --git a/eeschema/pinedit.cpp b/eeschema/pinedit.cpp index b54faf681d..30b4d99da6 100644 --- a/eeschema/pinedit.cpp +++ b/eeschema/pinedit.cpp @@ -57,7 +57,7 @@ static wxPoint OldPos; static wxPoint PinPreviousPos; static ELECTRICAL_PINTYPE LastPinType = PIN_INPUT; static int LastPinOrient = PIN_RIGHT; -static int LastPinShape = NONE; +static GRAPHIC_PINSHAPE LastPinShape = PINSHAPE_LINE; static bool LastPinCommonConvert = false; static bool LastPinCommonUnit = false; static bool LastPinVisible = true; @@ -104,10 +104,7 @@ void LIB_EDIT_FRAME::OnEditPin( wxCommandEvent& event ) wxString units = GetUnitsLabel( g_UserUnit ); dlg.SetOrientationList( LIB_PIN::GetOrientationNames(), LIB_PIN::GetOrientationSymbols() ); dlg.SetOrientation( LIB_PIN::GetOrientationCodeIndex( pin->GetOrientation() ) ); - dlg.SetStyleList( LIB_PIN::GetStyleNames(), LIB_PIN::GetStyleSymbols() ); - dlg.SetStyle( LIB_PIN::GetStyleCodeIndex( pin->GetShape() ) ); - dlg.SetElectricalTypeList( LIB_PIN::GetElectricalTypeNames(), - LIB_PIN::GetElectricalTypeSymbols() ); + dlg.SetStyle( pin->GetShape() ); dlg.SetElectricalType( pin->GetType() ); dlg.SetPinName( pin->GetName() ); dlg.SetPinNameTextSize( StringFromValue( g_UserUnit, pin->GetNameTextSize() ) ); @@ -147,7 +144,7 @@ void LIB_EDIT_FRAME::OnEditPin( wxCommandEvent& event ) LastPinNumSize = ValueFromString( g_UserUnit, dlg.GetPadNameTextSize() ); LastPinOrient = LIB_PIN::GetOrientationCode( dlg.GetOrientation() ); LastPinLength = ValueFromString( g_UserUnit, dlg.GetLength() ); - LastPinShape = LIB_PIN::GetStyleCode( dlg.GetStyle() ); + LastPinShape = dlg.GetStyle(); LastPinType = dlg.GetElectricalType(); LastPinCommonConvert = dlg.GetAddToAllBodyStyles(); LastPinCommonUnit = dlg.GetAddToAllParts(); diff --git a/eeschema/sch_sheet_pin.cpp b/eeschema/sch_sheet_pin.cpp index 048ffb1a98..52cdd5db86 100644 --- a/eeschema/sch_sheet_pin.cpp +++ b/eeschema/sch_sheet_pin.cpp @@ -466,7 +466,7 @@ void SCH_SHEET_PIN::CreateGraphicShape( std::vector & aPoints, const wx * for INPUT type the icon is the OUTPUT shape of SCH_HIERLABEL * for OUTPUT type the icon is the INPUT shape of SCH_HIERLABEL */ - int tmp = m_shape; + TypeSheetLabel tmp = m_shape; switch( m_shape ) { diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index c84852c3ce..964409a2a9 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -102,11 +102,11 @@ static int* TemplateShape[5][4] = SCH_TEXT::SCH_TEXT( const wxPoint& pos, const wxString& text, KICAD_T aType ) : SCH_ITEM( NULL, aType ), - EDA_TEXT( text ) + EDA_TEXT( text ), + m_shape( NET_INPUT ) { m_Layer = LAYER_NOTES; m_Pos = pos; - m_shape = 0; m_isDangling = false; m_MultilineAllowed = true; m_schematicOrientation = 0; diff --git a/eeschema/sch_text.h b/eeschema/sch_text.h index a570bfc57f..e80448d664 100644 --- a/eeschema/sch_text.h +++ b/eeschema/sch_text.h @@ -58,7 +58,7 @@ extern const char* SheetLabelType[]; /* names of types of labels */ class SCH_TEXT : public SCH_ITEM, public EDA_TEXT { protected: - int m_shape; + TypeSheetLabel m_shape; /// True if not connected to another object if the object derive from SCH_TEXT /// supports connections. @@ -120,9 +120,9 @@ public: int GetOrientation() { return m_schematicOrientation; } - int GetShape() const { return m_shape; } + TypeSheetLabel GetShape() const { return m_shape; } - void SetShape( int aShape ) { m_shape = aShape; } + void SetShape( TypeSheetLabel aShape ) { m_shape = aShape; } /** * Function GetSchematicTextOffset (virtual) diff --git a/eeschema/schframe.h b/eeschema/schframe.h index 95840f5bed..743eb29dd0 100644 --- a/eeschema/schframe.h +++ b/eeschema/schframe.h @@ -38,6 +38,8 @@ #include #include +// enum TypeSheetLabel +#include class LIB_EDIT_FRAME; class LIB_VIEW_FRAME; @@ -173,7 +175,7 @@ private: wxArrayString m_componentLibFiles; */ - static int m_lastSheetPinType; ///< Last sheet pin type. + static TypeSheetLabel m_lastSheetPinType; ///< Last sheet pin type. static wxSize m_lastSheetPinTextSize; ///< Last sheet pin text size. static wxPoint m_lastSheetPinPosition; ///< Last sheet pin position. diff --git a/eeschema/sheetlab.cpp b/eeschema/sheetlab.cpp index aeca4835e8..a2f4faa2f1 100644 --- a/eeschema/sheetlab.cpp +++ b/eeschema/sheetlab.cpp @@ -43,7 +43,7 @@ #include -int SCH_EDIT_FRAME::m_lastSheetPinType = NET_INPUT; +TypeSheetLabel SCH_EDIT_FRAME::m_lastSheetPinType = NET_INPUT; wxSize SCH_EDIT_FRAME::m_lastSheetPinTextSize( -1, -1 ); wxPoint SCH_EDIT_FRAME::m_lastSheetPinPosition; diff --git a/eeschema/widgets/pin_shape_combobox.cpp b/eeschema/widgets/pin_shape_combobox.cpp new file mode 100644 index 0000000000..9bab9ff8c5 --- /dev/null +++ b/eeschema/widgets/pin_shape_combobox.cpp @@ -0,0 +1,69 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2015 Simon Richter + * + * 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 + */ + +/** + * @file pin_shape_combobox.cpp + * @brief ComboBox widget for pin shape + */ + +#include "pin_shape_combobox.h" + +#include + +PinShapeComboBox::PinShapeComboBox( wxWindow* parent, + wxWindowID id, + const wxString& value, + const wxPoint& pos, + const wxSize& size, + int n, + const wxString choices[], + long style, + const wxValidator& validator, + const wxString& name ) : + wxBitmapComboBox( parent, id, value, pos, size, n, choices, style, validator, name ) +{ + for( unsigned ii = 0; ii < PINSHAPE_COUNT; ++ii ) + { + GRAPHIC_PINSHAPE shape = static_cast( ii ); + + wxString text = GetText( shape ); + BITMAP_DEF bitmap = GetBitmap( shape ); + + if( bitmap == NULL ) + Append( text ); + else + Insert( text, KiBitmap( bitmap ), ii ); + } +} + + +GRAPHIC_PINSHAPE PinShapeComboBox::GetSelection() +{ + return static_cast( wxBitmapComboBox::GetSelection() ); +} + + +void PinShapeComboBox::SetSelection( GRAPHIC_PINSHAPE aShape ) +{ + wxBitmapComboBox::SetSelection( aShape ); +} diff --git a/eeschema/widgets/pin_shape_combobox.h b/eeschema/widgets/pin_shape_combobox.h new file mode 100644 index 0000000000..659aa020b7 --- /dev/null +++ b/eeschema/widgets/pin_shape_combobox.h @@ -0,0 +1,51 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2015 Simon Richter + * + * 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 + */ + +/** + * @file pin_shape_combobox.h + * @brief ComboBox widget for pin shape + */ + +#include + +#include + +class PinShapeComboBox : public wxBitmapComboBox +{ +public: + /// @todo C++11: replace with forwarder + + PinShapeComboBox( wxWindow* parent, + wxWindowID id = wxID_ANY, + const wxString& value = wxEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + int n = 0, + const wxString choices[] = NULL, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxBitmapComboBoxNameStr ); + + GRAPHIC_PINSHAPE GetSelection(); + void SetSelection( GRAPHIC_PINSHAPE aShape ); +}; diff --git a/eeschema/widgets/pin_type_combobox.cpp b/eeschema/widgets/pin_type_combobox.cpp new file mode 100644 index 0000000000..70dd5bd1b0 --- /dev/null +++ b/eeschema/widgets/pin_type_combobox.cpp @@ -0,0 +1,69 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2015 Simon Richter + * + * 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 + */ + +/** + * @file pin_type_combobox.cpp + * @brief ComboBox widget for pin type + */ + +#include "pin_type_combobox.h" + +#include + +PinTypeComboBox::PinTypeComboBox( wxWindow* parent, + wxWindowID id, + const wxString& value, + const wxPoint& pos, + const wxSize& size, + int n, + const wxString choices[], + long style, + const wxValidator& validator, + const wxString& name ) : + wxBitmapComboBox( parent, id, value, pos, size, n, choices, style, validator, name ) +{ + for( unsigned ii = 0; ii < PINTYPE_COUNT; ++ii ) + { + ELECTRICAL_PINTYPE type = static_cast( ii ); + + wxString text = GetText( type ); + BITMAP_DEF bitmap = GetBitmap( type ); + + if( bitmap == NULL ) + Append( text ); + else + Insert( text, KiBitmap( bitmap ), ii ); + } +} + + +ELECTRICAL_PINTYPE PinTypeComboBox::GetSelection() +{ + return static_cast( wxBitmapComboBox::GetSelection() ); +} + + +void PinTypeComboBox::SetSelection( ELECTRICAL_PINTYPE aType ) +{ + wxBitmapComboBox::SetSelection( aType ); +} diff --git a/eeschema/widgets/pin_type_combobox.h b/eeschema/widgets/pin_type_combobox.h new file mode 100644 index 0000000000..c94c5d67dc --- /dev/null +++ b/eeschema/widgets/pin_type_combobox.h @@ -0,0 +1,51 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2015 Simon Richter + * + * 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 + */ + +/** + * @file pin_type_combobox.h + * @brief ComboBox widget for pin type + */ + +#include + +#include + +class PinTypeComboBox : public wxBitmapComboBox +{ +public: + /// @todo C++11: replace with forwarder + + PinTypeComboBox( wxWindow* parent, + wxWindowID id = wxID_ANY, + const wxString& value = wxEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + int n = 0, + const wxString choices[] = NULL, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxBitmapComboBoxNameStr ); + + ELECTRICAL_PINTYPE GetSelection(); + void SetSelection( ELECTRICAL_PINTYPE aType ); +};