2018-02-28 16:54:35 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-05-10 12:21:08 +00:00
|
|
|
* Copyright (C) 2018-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-02-28 16:54:35 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kiway.h>
|
|
|
|
#include <kiway_player.h>
|
|
|
|
#include <dialog_shim.h>
|
|
|
|
#include <fields_grid_table.h>
|
2018-08-08 20:57:53 +00:00
|
|
|
#include <sch_base_frame.h>
|
2018-03-07 12:48:08 +00:00
|
|
|
#include <sch_field.h>
|
|
|
|
#include <sch_validators.h>
|
2018-02-28 16:54:35 +00:00
|
|
|
#include <validators.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <template_fieldnames.h>
|
|
|
|
#include <widgets/grid_icon_text_helpers.h>
|
2018-07-20 15:03:43 +00:00
|
|
|
#include <widgets/grid_text_button_helpers.h>
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
#include "eda_doc.h"
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MYID_SELECT_FOOTPRINT = 991, // must be within GRID_TRICKS' enum range
|
|
|
|
MYID_SHOW_DATASHEET
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <class T>
|
2018-08-08 20:57:53 +00:00
|
|
|
FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame,
|
|
|
|
LIB_PART* aPart ) :
|
|
|
|
m_frame( aFrame ),
|
2018-07-20 15:03:43 +00:00
|
|
|
m_userUnits( aDialog->GetUserUnits() ),
|
2018-02-28 16:54:35 +00:00
|
|
|
m_part( aPart ),
|
2018-08-08 20:57:53 +00:00
|
|
|
m_fieldNameValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), FIELD_NAME ),
|
2018-09-13 15:39:14 +00:00
|
|
|
m_referenceValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), REFERENCE ),
|
2019-06-04 13:32:10 +00:00
|
|
|
m_valueValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), VALUE ),
|
|
|
|
m_libIdValidator( LIB_ID::ID_PCB ),
|
2019-06-25 23:38:28 +00:00
|
|
|
m_urlValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), FIELD_VALUE ),
|
|
|
|
m_nonUrlValidator( aFrame->IsType( FRAME_SCH_LIB_EDITOR ), FIELD_VALUE )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2018-07-21 20:23:13 +00:00
|
|
|
// Build the various grid cell attributes.
|
2019-06-04 13:32:10 +00:00
|
|
|
// NOTE: validators and cellAttrs are member variables to get the destruction order
|
|
|
|
// right. wxGrid is VERY cranky about this.
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
m_readOnlyAttr = new wxGridCellAttr;
|
|
|
|
m_readOnlyAttr->SetReadOnly( true );
|
|
|
|
|
2018-07-21 20:23:13 +00:00
|
|
|
m_fieldNameAttr = new wxGridCellAttr;
|
|
|
|
GRID_CELL_TEXT_EDITOR* nameEditor = new GRID_CELL_TEXT_EDITOR();
|
|
|
|
nameEditor->SetValidator( m_fieldNameValidator );
|
|
|
|
m_fieldNameAttr->SetEditor( nameEditor );
|
|
|
|
|
|
|
|
m_referenceAttr = new wxGridCellAttr;
|
|
|
|
GRID_CELL_TEXT_EDITOR* referenceEditor = new GRID_CELL_TEXT_EDITOR();
|
|
|
|
referenceEditor->SetValidator( m_referenceValidator );
|
|
|
|
m_referenceAttr->SetEditor( referenceEditor );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2018-09-13 15:39:14 +00:00
|
|
|
m_valueAttr = new wxGridCellAttr;
|
|
|
|
GRID_CELL_TEXT_EDITOR* valueEditor = new GRID_CELL_TEXT_EDITOR();
|
|
|
|
valueEditor->SetValidator( m_valueValidator );
|
|
|
|
m_valueAttr->SetEditor( valueEditor );
|
|
|
|
|
2018-07-20 15:03:43 +00:00
|
|
|
m_footprintAttr = new wxGridCellAttr;
|
2019-05-10 12:21:08 +00:00
|
|
|
GRID_CELL_FOOTPRINT_ID_EDITOR* fpIdEditor = new GRID_CELL_FOOTPRINT_ID_EDITOR( aDialog );
|
2019-06-04 13:32:10 +00:00
|
|
|
fpIdEditor->SetValidator( m_libIdValidator );
|
2019-05-10 12:21:08 +00:00
|
|
|
m_footprintAttr->SetEditor( fpIdEditor );
|
2018-07-20 15:03:43 +00:00
|
|
|
|
|
|
|
m_urlAttr = new wxGridCellAttr;
|
2019-05-10 12:21:08 +00:00
|
|
|
GRID_CELL_URL_EDITOR* urlEditor = new GRID_CELL_URL_EDITOR( aDialog );
|
2019-06-04 13:32:10 +00:00
|
|
|
urlEditor->SetValidator( m_urlValidator );
|
2019-05-10 12:21:08 +00:00
|
|
|
m_urlAttr->SetEditor( urlEditor );
|
|
|
|
|
|
|
|
m_nonUrlAttr = new wxGridCellAttr;
|
2019-06-04 13:32:10 +00:00
|
|
|
GRID_CELL_TEXT_EDITOR* nonUrlEditor = new GRID_CELL_TEXT_EDITOR();
|
|
|
|
nonUrlEditor->SetValidator( m_nonUrlValidator );
|
2019-05-10 12:21:08 +00:00
|
|
|
m_nonUrlAttr->SetEditor( nonUrlEditor );
|
2018-07-20 15:03:43 +00:00
|
|
|
|
2018-07-21 20:23:13 +00:00
|
|
|
m_boolAttr = new wxGridCellAttr;
|
|
|
|
m_boolAttr->SetRenderer( new wxGridCellBoolRenderer() );
|
|
|
|
m_boolAttr->SetEditor( new wxGridCellBoolEditor() );
|
|
|
|
m_boolAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
wxArrayString vAlignNames;
|
|
|
|
vAlignNames.Add( _( "Top" ) );
|
|
|
|
vAlignNames.Add( _( "Center" ) );
|
|
|
|
vAlignNames.Add( _( "Bottom" ) );
|
2018-07-21 20:23:13 +00:00
|
|
|
m_vAlignAttr = new wxGridCellAttr;
|
|
|
|
m_vAlignAttr->SetEditor( new wxGridCellChoiceEditor( vAlignNames ) );
|
|
|
|
m_vAlignAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
wxArrayString hAlignNames;
|
|
|
|
hAlignNames.Add( _( "Left" ) );
|
|
|
|
hAlignNames.Add(_( "Center" ) );
|
|
|
|
hAlignNames.Add(_( "Right" ) );
|
2018-07-21 20:23:13 +00:00
|
|
|
m_hAlignAttr = new wxGridCellAttr;
|
|
|
|
m_hAlignAttr->SetEditor( new wxGridCellChoiceEditor( hAlignNames ) );
|
|
|
|
m_hAlignAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
wxArrayString orientationNames;
|
|
|
|
orientationNames.Add( _( "Horizontal" ) );
|
|
|
|
orientationNames.Add(_( "Vertical" ) );
|
2018-07-21 20:23:13 +00:00
|
|
|
m_orientationAttr = new wxGridCellAttr;
|
|
|
|
m_orientationAttr->SetEditor( new wxGridCellChoiceEditor( orientationNames ) );
|
|
|
|
m_orientationAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
FIELDS_GRID_TABLE<T>::~FIELDS_GRID_TABLE()
|
|
|
|
{
|
|
|
|
m_readOnlyAttr->DecRef();
|
2018-07-21 20:23:13 +00:00
|
|
|
m_fieldNameAttr->DecRef();
|
|
|
|
m_boolAttr->DecRef();
|
|
|
|
m_referenceAttr->DecRef();
|
2018-09-13 15:39:14 +00:00
|
|
|
m_valueAttr->DecRef();
|
2018-07-20 15:03:43 +00:00
|
|
|
m_footprintAttr->DecRef();
|
|
|
|
m_urlAttr->DecRef();
|
2019-06-25 23:26:25 +00:00
|
|
|
m_nonUrlAttr->DecRef();
|
2018-07-21 20:23:13 +00:00
|
|
|
m_vAlignAttr->DecRef();
|
|
|
|
m_hAlignAttr->DecRef();
|
|
|
|
m_orientationAttr->DecRef();
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
wxString FIELDS_GRID_TABLE<T>::GetColLabelValue( int aCol )
|
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case FDC_NAME: return _( "Name" );
|
|
|
|
case FDC_VALUE: return _( "Value" );
|
|
|
|
case FDC_SHOWN: return _( "Show" );
|
|
|
|
case FDC_H_ALIGN: return _( "H Align" );
|
|
|
|
case FDC_V_ALIGN: return _( "V Align" );
|
|
|
|
case FDC_ITALIC: return _( "Italic" );
|
|
|
|
case FDC_BOLD: return _( "Bold" );
|
|
|
|
case FDC_TEXT_SIZE: return _( "Text Size" );
|
|
|
|
case FDC_ORIENTATION: return _( "Orientation" );
|
|
|
|
case FDC_POSX: return _( "X Position" );
|
|
|
|
case FDC_POSY: return _( "Y Position" );
|
|
|
|
default: wxFAIL; return wxEmptyString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
bool FIELDS_GRID_TABLE<T>::CanGetValueAs( int aRow, int aCol, const wxString& aTypeName )
|
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case FDC_NAME:
|
|
|
|
case FDC_VALUE:
|
|
|
|
case FDC_H_ALIGN:
|
|
|
|
case FDC_V_ALIGN:
|
|
|
|
case FDC_TEXT_SIZE:
|
|
|
|
case FDC_ORIENTATION:
|
|
|
|
case FDC_POSX:
|
|
|
|
case FDC_POSY:
|
|
|
|
return aTypeName == wxGRID_VALUE_STRING;
|
|
|
|
|
|
|
|
case FDC_SHOWN:
|
|
|
|
case FDC_ITALIC:
|
|
|
|
case FDC_BOLD:
|
|
|
|
return aTypeName == wxGRID_VALUE_BOOL;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
bool FIELDS_GRID_TABLE<T>::CanSetValueAs( int aRow, int aCol, const wxString& aTypeName )
|
|
|
|
{
|
|
|
|
return CanGetValueAs( aRow, aCol, aTypeName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
wxGridCellAttr* FIELDS_GRID_TABLE<T>::GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind )
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
wxGridCellAttr* tmp;
|
|
|
|
|
|
|
|
// Only the VALUE and DATASHEET fields can be edited for inherited symbols.
|
|
|
|
bool rowIsReadOnly = m_part && m_part->IsAlias() && ( aRow == REFERENCE || aRow == FOOTPRINT );
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case FDC_NAME:
|
2019-11-06 19:15:42 +00:00
|
|
|
if( aRow < MANDATORY_FIELDS || rowIsReadOnly )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
tmp = m_fieldNameAttr->Clone();
|
|
|
|
tmp->SetReadOnly( true );
|
|
|
|
tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
|
|
|
return tmp;
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
else
|
2018-07-21 20:23:13 +00:00
|
|
|
{
|
|
|
|
m_fieldNameAttr->IncRef();
|
|
|
|
return m_fieldNameAttr;
|
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_VALUE:
|
2018-07-21 20:23:13 +00:00
|
|
|
if( aRow == REFERENCE )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( rowIsReadOnly )
|
|
|
|
{
|
|
|
|
tmp = m_referenceAttr->Clone();
|
|
|
|
tmp->SetReadOnly( true );
|
|
|
|
tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_referenceAttr->IncRef();
|
|
|
|
return m_referenceAttr;
|
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
2018-07-21 20:23:13 +00:00
|
|
|
else if( aRow == VALUE )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2018-09-13 15:39:14 +00:00
|
|
|
// For power symbols, the value is not editable, because value and pin name must
|
|
|
|
// be the same and can be edited only in library editor.
|
2019-11-06 19:15:42 +00:00
|
|
|
if( ( m_part && m_part->IsPower() && !m_frame->IsType( FRAME_SCH_LIB_EDITOR ) )
|
|
|
|
|| rowIsReadOnly )
|
2018-07-21 20:23:13 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
tmp = m_readOnlyAttr->Clone();
|
|
|
|
tmp->SetReadOnly( true );
|
|
|
|
tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
|
|
|
return tmp;
|
2018-07-21 20:23:13 +00:00
|
|
|
}
|
2018-09-13 15:39:14 +00:00
|
|
|
else
|
2018-07-21 20:23:13 +00:00
|
|
|
{
|
2018-09-13 15:39:14 +00:00
|
|
|
m_valueAttr->IncRef();
|
|
|
|
return m_valueAttr;
|
2018-07-21 20:23:13 +00:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
2018-07-20 15:03:43 +00:00
|
|
|
else if( aRow == FOOTPRINT )
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( rowIsReadOnly )
|
|
|
|
{
|
|
|
|
tmp = m_footprintAttr->Clone();
|
|
|
|
tmp->SetReadOnly( true );
|
|
|
|
tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_footprintAttr->IncRef();
|
|
|
|
return m_footprintAttr;
|
|
|
|
}
|
2018-07-20 15:03:43 +00:00
|
|
|
}
|
|
|
|
else if( aRow == DATASHEET )
|
|
|
|
{
|
|
|
|
m_urlAttr->IncRef();
|
|
|
|
return m_urlAttr;
|
|
|
|
}
|
2018-08-08 20:57:53 +00:00
|
|
|
else
|
2018-08-08 00:41:56 +00:00
|
|
|
{
|
2018-08-08 20:57:53 +00:00
|
|
|
wxString fieldname = GetValue( aRow, FDC_NAME );
|
|
|
|
const TEMPLATE_FIELDNAME* templateFn = m_frame->GetTemplateFieldName( fieldname );
|
|
|
|
|
|
|
|
if( templateFn && templateFn->m_URL )
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( rowIsReadOnly )
|
|
|
|
{
|
|
|
|
tmp = m_urlAttr->Clone();
|
|
|
|
tmp->SetReadOnly( true );
|
|
|
|
tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_urlAttr->IncRef();
|
|
|
|
return m_urlAttr;
|
|
|
|
}
|
2018-08-08 20:57:53 +00:00
|
|
|
}
|
2019-05-10 12:21:08 +00:00
|
|
|
else
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( rowIsReadOnly )
|
|
|
|
{
|
|
|
|
tmp = m_nonUrlAttr->Clone();
|
|
|
|
tmp->SetReadOnly( true );
|
|
|
|
tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_nonUrlAttr->IncRef();
|
|
|
|
return m_nonUrlAttr;
|
|
|
|
}
|
2019-05-10 12:21:08 +00:00
|
|
|
}
|
2018-08-08 00:41:56 +00:00
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2018-07-21 20:23:13 +00:00
|
|
|
return nullptr;
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_TEXT_SIZE:
|
|
|
|
case FDC_POSX:
|
|
|
|
case FDC_POSY:
|
2019-11-06 19:15:42 +00:00
|
|
|
if( rowIsReadOnly )
|
|
|
|
{
|
|
|
|
tmp = m_readOnlyAttr->Clone();
|
|
|
|
tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_H_ALIGN:
|
2019-11-06 19:15:42 +00:00
|
|
|
if( rowIsReadOnly )
|
|
|
|
{
|
|
|
|
tmp = m_hAlignAttr->Clone();
|
|
|
|
tmp->SetReadOnly( true );
|
|
|
|
tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_hAlignAttr->IncRef();
|
|
|
|
return m_hAlignAttr;
|
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_V_ALIGN:
|
2019-11-06 19:15:42 +00:00
|
|
|
if( rowIsReadOnly )
|
|
|
|
{
|
|
|
|
tmp = m_vAlignAttr->Clone();
|
|
|
|
tmp->SetReadOnly( true );
|
|
|
|
tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_vAlignAttr->IncRef();
|
|
|
|
return m_vAlignAttr;
|
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_ORIENTATION:
|
2019-11-06 19:15:42 +00:00
|
|
|
if( rowIsReadOnly )
|
|
|
|
{
|
|
|
|
tmp = m_orientationAttr->Clone();
|
|
|
|
tmp->SetReadOnly( true );
|
|
|
|
tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_orientationAttr->IncRef();
|
|
|
|
return m_orientationAttr;
|
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_SHOWN:
|
|
|
|
case FDC_ITALIC:
|
|
|
|
case FDC_BOLD:
|
2019-11-06 19:15:42 +00:00
|
|
|
if( rowIsReadOnly )
|
|
|
|
{
|
|
|
|
tmp = m_boolAttr->Clone();
|
|
|
|
tmp->SetReadOnly( true );
|
|
|
|
tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_boolAttr->IncRef();
|
|
|
|
return m_boolAttr;
|
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
wxString FIELDS_GRID_TABLE<T>::GetValue( int aRow, int aCol )
|
|
|
|
{
|
2018-11-13 13:01:51 +00:00
|
|
|
wxCHECK( aRow < GetNumberRows(), wxEmptyString );
|
2018-02-28 16:54:35 +00:00
|
|
|
const T& field = this->at( (size_t) aRow );
|
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case FDC_NAME:
|
2019-05-10 12:21:08 +00:00
|
|
|
// Use default field name for mandatory fields, because they are translated
|
2018-02-28 16:54:35 +00:00
|
|
|
// according to the current locale
|
|
|
|
if( aRow < MANDATORY_FIELDS )
|
|
|
|
return TEMPLATE_FIELDNAME::GetDefaultFieldName( aRow );
|
|
|
|
else
|
|
|
|
return field.GetName( false );
|
|
|
|
|
|
|
|
case FDC_VALUE:
|
|
|
|
return field.GetText();
|
|
|
|
|
2019-01-16 13:16:24 +00:00
|
|
|
case FDC_SHOWN:
|
|
|
|
return StringFromBool( field.IsVisible() );
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_H_ALIGN:
|
2018-10-11 11:43:11 +00:00
|
|
|
switch ( field.GetHorizJustify() )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2019-06-04 13:32:10 +00:00
|
|
|
case GR_TEXT_HJUSTIFY_LEFT: return _( "Left" );
|
|
|
|
case GR_TEXT_HJUSTIFY_CENTER: return _( "Center" );
|
|
|
|
case GR_TEXT_HJUSTIFY_RIGHT: return _( "Right" );
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 11:43:11 +00:00
|
|
|
break;
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_V_ALIGN:
|
2018-10-11 11:43:11 +00:00
|
|
|
switch ( field.GetVertJustify() )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2019-06-04 13:32:10 +00:00
|
|
|
case GR_TEXT_VJUSTIFY_TOP: return _( "Top" );
|
|
|
|
case GR_TEXT_VJUSTIFY_CENTER: return _( "Center" );
|
|
|
|
case GR_TEXT_VJUSTIFY_BOTTOM: return _( "Bottom" );
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 11:43:11 +00:00
|
|
|
break;
|
|
|
|
|
2019-01-16 13:16:24 +00:00
|
|
|
case FDC_ITALIC:
|
|
|
|
return StringFromBool( field.IsItalic() );
|
|
|
|
|
|
|
|
case FDC_BOLD:
|
|
|
|
return StringFromBool( field.IsBold() );
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_TEXT_SIZE:
|
|
|
|
return StringFromValue( m_userUnits, field.GetTextSize().GetHeight(), true, true );
|
|
|
|
|
|
|
|
case FDC_ORIENTATION:
|
2018-10-11 11:43:11 +00:00
|
|
|
switch ( (int) field.GetTextAngle() )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2019-06-04 13:32:10 +00:00
|
|
|
case TEXT_ANGLE_HORIZ: return _( "Horizontal" );
|
|
|
|
case TEXT_ANGLE_VERT: return _( "Vertical" );
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 11:43:11 +00:00
|
|
|
break;
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_POSX:
|
|
|
|
return StringFromValue( m_userUnits, field.GetTextPos().x, true );
|
|
|
|
|
|
|
|
case FDC_POSY:
|
|
|
|
return StringFromValue( m_userUnits, field.GetTextPos().y, true );
|
|
|
|
|
|
|
|
default:
|
|
|
|
// we can't assert here because wxWidgets sometimes calls this without checking
|
|
|
|
// the column type when trying to see if there's an overflow
|
2018-10-11 14:13:12 +00:00
|
|
|
break;
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
2018-10-11 14:13:12 +00:00
|
|
|
|
|
|
|
return wxT( "bad wxWidgets!" );
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
bool FIELDS_GRID_TABLE<T>::GetValueAsBool( int aRow, int aCol )
|
|
|
|
{
|
2018-11-13 13:01:51 +00:00
|
|
|
wxCHECK( aRow < GetNumberRows(), false );
|
2018-02-28 16:54:35 +00:00
|
|
|
const T& field = this->at( (size_t) aRow );
|
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case FDC_SHOWN: return field.IsVisible();
|
|
|
|
case FDC_ITALIC: return field.IsItalic();
|
|
|
|
case FDC_BOLD: return field.IsBold();
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void FIELDS_GRID_TABLE<T>::SetValue( int aRow, int aCol, const wxString &aValue )
|
|
|
|
{
|
2018-11-13 13:01:51 +00:00
|
|
|
wxCHECK( aRow < GetNumberRows(), /*void*/ );
|
2018-02-28 16:54:35 +00:00
|
|
|
T& field = this->at( (size_t) aRow );
|
|
|
|
wxPoint pos;
|
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case FDC_NAME:
|
|
|
|
field.SetName( aValue );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FDC_VALUE:
|
|
|
|
field.SetText( aValue );
|
|
|
|
break;
|
|
|
|
|
2019-01-16 13:16:24 +00:00
|
|
|
case FDC_SHOWN:
|
|
|
|
field.SetVisible( BoolFromString( aValue ) );
|
|
|
|
break;
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_H_ALIGN:
|
|
|
|
if( aValue == _( "Left" ) )
|
|
|
|
field.SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
else if( aValue == _( "Center" ) )
|
|
|
|
field.SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
else if( aValue == _( "Right" ) )
|
|
|
|
field.SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
else
|
|
|
|
wxFAIL_MSG( wxT( "unknown horizontal alignment: " ) + aValue );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FDC_V_ALIGN:
|
|
|
|
if( aValue == _( "Top" ) )
|
|
|
|
field.SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
else if( aValue == _( "Center" ) )
|
|
|
|
field.SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
|
|
|
else if( aValue == _( "Bottom" ) )
|
|
|
|
field.SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
else
|
|
|
|
wxFAIL_MSG( wxT( "unknown vertical alignment: " ) + aValue);
|
|
|
|
break;
|
|
|
|
|
2019-01-16 13:16:24 +00:00
|
|
|
case FDC_ITALIC:
|
|
|
|
field.SetItalic( BoolFromString( aValue ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FDC_BOLD:
|
|
|
|
field.SetBold( BoolFromString( aValue ) );
|
|
|
|
break;
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
case FDC_TEXT_SIZE:
|
|
|
|
field.SetTextSize( wxSize( ValueFromString( m_userUnits, aValue ),
|
|
|
|
ValueFromString( m_userUnits, aValue ) ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FDC_ORIENTATION:
|
|
|
|
if( aValue == _( "Horizontal" ) )
|
|
|
|
field.SetTextAngle( TEXT_ANGLE_HORIZ );
|
|
|
|
else if( aValue == _( "Vertical" ) )
|
|
|
|
field.SetTextAngle( TEXT_ANGLE_VERT );
|
|
|
|
else
|
|
|
|
wxFAIL_MSG( wxT( "unknown orientation: " ) + aValue );
|
2019-03-07 16:43:21 +00:00
|
|
|
break;
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
case FDC_POSX:
|
|
|
|
case FDC_POSY:
|
|
|
|
pos = field.GetTextPos();
|
|
|
|
if( aCol == FDC_POSX )
|
|
|
|
pos.x = ValueFromString( m_userUnits, aValue );
|
|
|
|
else
|
|
|
|
pos.y = ValueFromString( m_userUnits, aValue );
|
|
|
|
field.SetTextPos( pos );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a string value" ), aCol ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetView()->Refresh();
|
|
|
|
}
|
|
|
|
|
2018-11-13 13:01:51 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
template <class T>
|
|
|
|
void FIELDS_GRID_TABLE<T>::SetValueAsBool( int aRow, int aCol, bool aValue )
|
|
|
|
{
|
2018-11-13 13:01:51 +00:00
|
|
|
wxCHECK( aRow < GetNumberRows(), /*void*/ );
|
2018-02-28 16:54:35 +00:00
|
|
|
T& field = this->at( (size_t) aRow );
|
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case FDC_SHOWN:
|
|
|
|
field.SetVisible( aValue );
|
|
|
|
break;
|
|
|
|
case FDC_ITALIC:
|
|
|
|
field.SetItalic( aValue );
|
|
|
|
break;
|
|
|
|
case FDC_BOLD:
|
|
|
|
field.SetBold( aValue );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Explicit Instantiations
|
|
|
|
|
|
|
|
template class FIELDS_GRID_TABLE<SCH_FIELD>;
|
|
|
|
template class FIELDS_GRID_TABLE<LIB_FIELD>;
|
|
|
|
|
|
|
|
|
|
|
|
void FIELDS_GRID_TRICKS::showPopupMenu( wxMenu& menu )
|
|
|
|
{
|
|
|
|
if( m_grid->GetGridCursorRow() == FOOTPRINT && m_grid->GetGridCursorCol() == FDC_VALUE )
|
|
|
|
{
|
2019-05-10 12:21:08 +00:00
|
|
|
menu.Append( MYID_SELECT_FOOTPRINT, _( "Select Footprint..." ),
|
|
|
|
_( "Browse for footprint" ) );
|
2018-02-28 16:54:35 +00:00
|
|
|
menu.AppendSeparator();
|
|
|
|
}
|
|
|
|
else if( m_grid->GetGridCursorRow() == DATASHEET && m_grid->GetGridCursorCol() == FDC_VALUE )
|
|
|
|
{
|
2019-05-10 12:21:08 +00:00
|
|
|
menu.Append( MYID_SHOW_DATASHEET, _( "Show Datasheet" ),
|
|
|
|
_( "Show datasheet in browser" ) );
|
2018-02-28 16:54:35 +00:00
|
|
|
menu.AppendSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
GRID_TRICKS::showPopupMenu( menu );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FIELDS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( event.GetId() == MYID_SELECT_FOOTPRINT )
|
|
|
|
{
|
|
|
|
// pick a footprint using the footprint picker.
|
2018-07-20 15:03:43 +00:00
|
|
|
wxString fpid = m_grid->GetCellValue( FOOTPRINT, FDC_VALUE );
|
2019-09-05 22:00:47 +00:00
|
|
|
KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_VIEWER_MODAL, true, m_dlg );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
if( frame->ShowModal( &fpid, m_dlg ) )
|
|
|
|
m_grid->SetCellValue( FOOTPRINT, FDC_VALUE, fpid );
|
|
|
|
|
|
|
|
frame->Destroy();
|
|
|
|
}
|
|
|
|
else if (event.GetId() == MYID_SHOW_DATASHEET )
|
|
|
|
{
|
|
|
|
wxString datasheet_uri = m_grid->GetCellValue( DATASHEET, FDC_VALUE );
|
|
|
|
GetAssociatedDocument( m_dlg, datasheet_uri );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GRID_TRICKS::doPopupSelection( event );
|
|
|
|
}
|
|
|
|
}
|
2019-01-16 13:16:24 +00:00
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
|
2019-01-16 13:16:24 +00:00
|
|
|
template <class T>
|
|
|
|
wxString FIELDS_GRID_TABLE<T>::StringFromBool( bool aValue )
|
|
|
|
{
|
|
|
|
if( aValue )
|
|
|
|
return wxT( "1" );
|
|
|
|
else
|
|
|
|
return wxT( "0" );
|
|
|
|
}
|
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
|
2019-01-16 13:16:24 +00:00
|
|
|
template <class T>
|
|
|
|
bool FIELDS_GRID_TABLE<T>::BoolFromString( wxString aValue )
|
|
|
|
{
|
2019-05-10 12:21:08 +00:00
|
|
|
if( aValue == "1" )
|
2019-01-16 13:16:24 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2019-05-10 12:21:08 +00:00
|
|
|
else if( aValue == "0" )
|
2019-01-16 13:16:24 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-10 12:21:08 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( "string \"%s\" can't be converted to boolean "
|
|
|
|
"correctly, it will have been perceived as FALSE", aValue ) );
|
2019-01-16 13:16:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|