2018-03-28 17:14:04 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-12-05 21:56:55 +00:00
|
|
|
* Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-03-28 17:14:04 +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_player.h>
|
2021-02-02 23:16:37 +00:00
|
|
|
#include <fp_text_grid_table.h>
|
2018-03-28 17:14:04 +00:00
|
|
|
#include <widgets/grid_icon_text_helpers.h>
|
|
|
|
#include <widgets/grid_combobox.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2021-12-22 21:43:41 +00:00
|
|
|
#include <pcb_base_frame.h>
|
2018-03-28 17:14:04 +00:00
|
|
|
#include "grid_layer_box_helpers.h"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MYID_SELECT_FOOTPRINT = 991, // must be within GRID_TRICKS' enum range
|
|
|
|
MYID_SHOW_DATASHEET
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
wxArrayString g_menuOrientations;
|
|
|
|
|
|
|
|
|
2021-12-22 21:43:41 +00:00
|
|
|
FP_TEXT_GRID_TABLE::FP_TEXT_GRID_TABLE( PCB_BASE_FRAME* aFrame ) :
|
|
|
|
m_frame( aFrame )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
|
|
|
// Build the column attributes.
|
|
|
|
|
|
|
|
m_readOnlyAttr = new wxGridCellAttr;
|
|
|
|
m_readOnlyAttr->SetReadOnly( true );
|
|
|
|
|
|
|
|
m_boolColAttr = new wxGridCellAttr;
|
|
|
|
m_boolColAttr->SetRenderer( new wxGridCellBoolRenderer() );
|
|
|
|
m_boolColAttr->SetEditor( new wxGridCellBoolEditor() );
|
2020-09-04 13:41:36 +00:00
|
|
|
m_boolColAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
if( g_menuOrientations.IsEmpty() )
|
|
|
|
{
|
2021-08-07 23:02:07 +00:00
|
|
|
g_menuOrientations.push_back( "0" + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
|
|
|
|
g_menuOrientations.push_back( "90" + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
|
|
|
|
g_menuOrientations.push_back( "-90" + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
|
|
|
|
g_menuOrientations.push_back( "180" + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
|
2018-03-28 17:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_orientationColAttr = new wxGridCellAttr;
|
|
|
|
m_orientationColAttr->SetEditor( new GRID_CELL_COMBOBOX( g_menuOrientations ) );
|
|
|
|
|
|
|
|
m_layerColAttr = new wxGridCellAttr;
|
|
|
|
m_layerColAttr->SetRenderer( new GRID_CELL_LAYER_RENDERER( m_frame ) );
|
2020-10-13 17:46:48 +00:00
|
|
|
m_layerColAttr->SetEditor( new GRID_CELL_LAYER_SELECTOR( m_frame, {} ) );
|
2021-12-22 21:43:41 +00:00
|
|
|
|
|
|
|
m_frame->Bind( UNITS_CHANGED, &FP_TEXT_GRID_TABLE::onUnitsChanged, this );
|
2018-03-28 17:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
FP_TEXT_GRID_TABLE::~FP_TEXT_GRID_TABLE()
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
|
|
|
m_readOnlyAttr->DecRef();
|
|
|
|
m_boolColAttr->DecRef();
|
|
|
|
m_orientationColAttr->DecRef();
|
|
|
|
m_layerColAttr->DecRef();
|
2021-12-22 21:43:41 +00:00
|
|
|
|
|
|
|
m_frame->Unbind( UNITS_CHANGED, &FP_TEXT_GRID_TABLE::onUnitsChanged, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FP_TEXT_GRID_TABLE::onUnitsChanged( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( GetView() )
|
|
|
|
GetView()->ForceRefresh();
|
|
|
|
|
|
|
|
aEvent.Skip();
|
2018-03-28 17:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
wxString FP_TEXT_GRID_TABLE::GetColLabelValue( int aCol )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_TEXT: return _( "Text Items" );
|
|
|
|
case FPT_SHOWN: return _( "Show" );
|
|
|
|
case FPT_WIDTH: return _( "Width" );
|
|
|
|
case FPT_HEIGHT: return _( "Height" );
|
|
|
|
case FPT_THICKNESS: return _( "Thickness" );
|
|
|
|
case FPT_ITALIC: return _( "Italic" );
|
|
|
|
case FPT_LAYER: return _( "Layer" );
|
|
|
|
case FPT_ORIENTATION: return _( "Orientation" );
|
|
|
|
case FPT_UPRIGHT: return _( "Keep Upright" );
|
|
|
|
case FPT_XOFFSET: return _( "X Offset" );
|
|
|
|
case FPT_YOFFSET: return _( "Y Offset" );
|
2018-03-28 17:14:04 +00:00
|
|
|
default: wxFAIL; return wxEmptyString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
wxString FP_TEXT_GRID_TABLE::GetRowLabelValue( int aRow )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
|
|
|
switch( aRow )
|
|
|
|
{
|
2020-05-08 18:10:47 +00:00
|
|
|
case 0: return _( "Reference designator" );
|
2018-03-28 17:14:04 +00:00
|
|
|
case 1: return _( "Value" );
|
|
|
|
default: return wxEmptyString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
bool FP_TEXT_GRID_TABLE::CanGetValueAs( int aRow, int aCol, const wxString& aTypeName )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_TEXT:
|
|
|
|
case FPT_WIDTH:
|
|
|
|
case FPT_HEIGHT:
|
|
|
|
case FPT_THICKNESS:
|
|
|
|
case FPT_ORIENTATION:
|
|
|
|
case FPT_XOFFSET:
|
|
|
|
case FPT_YOFFSET:
|
2018-03-28 17:14:04 +00:00
|
|
|
return aTypeName == wxGRID_VALUE_STRING;
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_SHOWN:
|
|
|
|
case FPT_ITALIC:
|
|
|
|
case FPT_UPRIGHT:
|
2018-03-28 17:14:04 +00:00
|
|
|
return aTypeName == wxGRID_VALUE_BOOL;
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_LAYER:
|
2018-03-28 17:14:04 +00:00
|
|
|
return aTypeName == wxGRID_VALUE_NUMBER;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
bool FP_TEXT_GRID_TABLE::CanSetValueAs( int aRow, int aCol, const wxString& aTypeName )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
|
|
|
return CanGetValueAs( aRow, aCol, aTypeName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
wxGridCellAttr* FP_TEXT_GRID_TABLE::GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_TEXT:
|
|
|
|
case FPT_WIDTH:
|
|
|
|
case FPT_HEIGHT:
|
|
|
|
case FPT_THICKNESS:
|
|
|
|
case FPT_XOFFSET:
|
|
|
|
case FPT_YOFFSET:
|
2018-03-28 17:14:04 +00:00
|
|
|
return nullptr;
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_SHOWN:
|
|
|
|
case FPT_ITALIC:
|
|
|
|
case FPT_UPRIGHT:
|
2018-03-28 17:14:04 +00:00
|
|
|
m_boolColAttr->IncRef();
|
|
|
|
return m_boolColAttr;
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_LAYER:
|
2018-03-28 17:14:04 +00:00
|
|
|
m_layerColAttr->IncRef();
|
|
|
|
return m_layerColAttr;
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_ORIENTATION:
|
2018-03-28 17:14:04 +00:00
|
|
|
m_orientationColAttr->IncRef();
|
|
|
|
return m_orientationColAttr;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
wxString FP_TEXT_GRID_TABLE::GetValue( int aRow, int aCol )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
2021-12-05 21:56:55 +00:00
|
|
|
const FP_TEXT& text = this->at( (size_t) aRow );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_TEXT:
|
2018-03-28 17:14:04 +00:00
|
|
|
return text.GetText();
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_WIDTH:
|
2021-12-22 21:43:41 +00:00
|
|
|
return StringFromValue( m_frame->GetUserUnits(), text.GetTextWidth(), true );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_HEIGHT:
|
2021-12-22 21:43:41 +00:00
|
|
|
return StringFromValue( m_frame->GetUserUnits(), text.GetTextHeight(), true );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_THICKNESS:
|
2021-12-22 21:43:41 +00:00
|
|
|
return StringFromValue( m_frame->GetUserUnits(), text.GetTextThickness(), true );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_LAYER:
|
2018-03-28 17:14:04 +00:00
|
|
|
return text.GetLayerName();
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_ORIENTATION:
|
2022-01-18 23:20:48 +00:00
|
|
|
return StringFromValue( EDA_UNITS::DEGREES, text.GetTextAngle().AsDegrees(), true );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_XOFFSET:
|
2021-12-22 21:43:41 +00:00
|
|
|
return StringFromValue( m_frame->GetUserUnits(), text.GetPos0().x, true );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_YOFFSET:
|
2021-12-22 21:43:41 +00:00
|
|
|
return StringFromValue( m_frame->GetUserUnits(), text.GetPos0().y, true );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
return wxT( "bad wxWidgets!" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
bool FP_TEXT_GRID_TABLE::GetValueAsBool( int aRow, int aCol )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
2021-12-05 21:56:55 +00:00
|
|
|
FP_TEXT& text = this->at( (size_t) aRow );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_SHOWN: return text.IsVisible();
|
|
|
|
case FPT_ITALIC: return text.IsItalic();
|
|
|
|
case FPT_UPRIGHT: return text.IsKeepUpright();
|
2021-12-05 21:56:55 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
long FP_TEXT_GRID_TABLE::GetValueAsLong( int aRow, int aCol )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
2021-12-05 21:56:55 +00:00
|
|
|
FP_TEXT& text = this->at( (size_t) aRow );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_LAYER: return text.GetLayer();
|
2021-12-05 21:56:55 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a long value" ), aCol ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
void FP_TEXT_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
2021-12-05 21:56:55 +00:00
|
|
|
FP_TEXT& text = this->at( (size_t) aRow );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos;
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_TEXT:
|
2018-03-28 17:14:04 +00:00
|
|
|
text.SetText( aValue );
|
|
|
|
break;
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_WIDTH:
|
2021-12-22 21:43:41 +00:00
|
|
|
text.SetTextWidth( ValueFromString( m_frame->GetUserUnits(), aValue ) );
|
2018-03-28 17:14:04 +00:00
|
|
|
break;
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_HEIGHT:
|
2021-12-22 21:43:41 +00:00
|
|
|
text.SetTextHeight( ValueFromString( m_frame->GetUserUnits(), aValue ) );
|
2018-03-28 17:14:04 +00:00
|
|
|
break;
|
|
|
|
|
2021-12-22 21:43:41 +00:00
|
|
|
case FPT_THICKNESS:text.SetTextThickness( ValueFromString( m_frame->GetUserUnits(), aValue ) );
|
2018-03-28 17:14:04 +00:00
|
|
|
break;
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_ORIENTATION:
|
2022-01-13 23:30:52 +00:00
|
|
|
text.SetTextAngle( EDA_ANGLE( DoubleValueFromString( EDA_UNITS::UNSCALED, aValue ),
|
|
|
|
DEGREES_T ) );
|
2018-03-28 17:14:04 +00:00
|
|
|
text.SetDrawCoord();
|
|
|
|
break;
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_XOFFSET:
|
|
|
|
case FPT_YOFFSET:
|
2018-03-28 17:14:04 +00:00
|
|
|
pos = text.GetPos0();
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
if( aCol == FPT_XOFFSET )
|
2021-12-22 21:43:41 +00:00
|
|
|
pos.x = ValueFromString( m_frame->GetUserUnits(), aValue );
|
2018-03-28 17:14:04 +00:00
|
|
|
else
|
2021-12-22 21:43:41 +00:00
|
|
|
pos.y = ValueFromString( m_frame->GetUserUnits(), aValue );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
text.SetPos0( pos );
|
|
|
|
text.SetDrawCoord();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a string value" ), aCol ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetView()->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
void FP_TEXT_GRID_TABLE::SetValueAsBool( int aRow, int aCol, bool aValue )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
2021-12-05 21:56:55 +00:00
|
|
|
FP_TEXT& text = this->at( (size_t) aRow );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_SHOWN:
|
2018-03-28 17:14:04 +00:00
|
|
|
text.SetVisible( aValue );
|
|
|
|
break;
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_ITALIC:
|
2018-03-28 17:14:04 +00:00
|
|
|
text.SetItalic( aValue );
|
|
|
|
break;
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_UPRIGHT:text.SetKeepUpright( aValue );
|
2018-03-28 17:14:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-02 23:16:37 +00:00
|
|
|
void FP_TEXT_GRID_TABLE::SetValueAsLong( int aRow, int aCol, long aValue )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
2021-12-05 21:56:55 +00:00
|
|
|
FP_TEXT& text = this->at( (size_t) aRow );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2021-02-02 23:16:37 +00:00
|
|
|
case FPT_LAYER:
|
2018-03-28 17:14:04 +00:00
|
|
|
text.SetLayer( ToLAYER_ID( (int) aValue ) );
|
|
|
|
text.SetMirrored( IsBackLayer( text.GetLayer() ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a long value" ), aCol ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|