2018-06-06 10:05:56 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2018 Jean-Pierre Charras jp.charras at wanadoo.fr
|
2023-03-30 11:49:23 +00:00
|
|
|
* Copyright (C) 2010-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-06-06 10:05:56 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-11-07 22:41:03 +00:00
|
|
|
#include <widgets/bitmap_button.h>
|
2022-01-03 01:20:25 +00:00
|
|
|
#include <widgets/font_choice.h>
|
2019-03-27 12:36:28 +00:00
|
|
|
#include <dialog_text_properties.h>
|
2018-06-06 10:05:56 +00:00
|
|
|
#include <confirm.h>
|
2019-03-27 12:36:28 +00:00
|
|
|
#include <board_commit.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_text.h>
|
2023-05-24 11:08:52 +00:00
|
|
|
#include <project.h>
|
2019-03-27 12:36:28 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
|
|
|
#include <pcb_layer_box_selector.h>
|
|
|
|
#include <wx/valnum.h>
|
2021-06-24 22:50:57 +00:00
|
|
|
#include <scintilla_tricks.h>
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, PCB_TEXT* aText ) :
|
2022-01-03 01:20:25 +00:00
|
|
|
DIALOG_TEXT_PROPERTIES_BASE( aParent ),
|
|
|
|
m_frame( aParent ),
|
2023-03-30 11:49:23 +00:00
|
|
|
m_item( aText ),
|
2022-01-03 01:20:25 +00:00
|
|
|
m_textWidth( aParent, m_SizeXLabel, m_SizeXCtrl, m_SizeXUnits ),
|
|
|
|
m_textHeight( aParent, m_SizeYLabel, m_SizeYCtrl, m_SizeYUnits ),
|
|
|
|
m_thickness( aParent, m_ThicknessLabel, m_ThicknessCtrl, m_ThicknessUnits ),
|
|
|
|
m_posX( aParent, m_PositionXLabel, m_PositionXCtrl, m_PositionXUnits ),
|
|
|
|
m_posY( aParent, m_PositionYLabel, m_PositionYCtrl, m_PositionYUnits ),
|
|
|
|
m_orientation( aParent, m_OrientLabel, m_OrientCtrl, nullptr )
|
2018-06-06 10:05:56 +00:00
|
|
|
{
|
2018-07-21 12:49:19 +00:00
|
|
|
wxString title;
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2020-07-06 14:41:29 +00:00
|
|
|
// Configure display origin transforms
|
2023-09-21 13:28:11 +00:00
|
|
|
if( m_item->GetParentFootprint() )
|
|
|
|
{
|
|
|
|
m_posX.SetCoordType( ORIGIN_TRANSFORMS::REL_X_COORD );
|
|
|
|
m_posY.SetCoordType( ORIGIN_TRANSFORMS::REL_Y_COORD );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_posX.SetCoordType( ORIGIN_TRANSFORMS::ABS_X_COORD );
|
|
|
|
m_posY.SetCoordType( ORIGIN_TRANSFORMS::ABS_Y_COORD );
|
|
|
|
}
|
2020-07-06 14:41:29 +00:00
|
|
|
|
2020-04-18 20:40:54 +00:00
|
|
|
m_MultiLineText->SetEOLMode( wxSTC_EOL_LF );
|
2020-04-19 19:09:26 +00:00
|
|
|
|
2023-08-03 16:28:37 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
// Without this setting, on Windows, some esoteric unicode chars create display issue
|
|
|
|
// in a wxStyledTextCtrl.
|
|
|
|
// for SetTechnology() info, see https://www.scintilla.org/ScintillaDoc.html#SCI_SETTECHNOLOGY
|
|
|
|
m_MultiLineText->SetTechnology(wxSTC_TECHNOLOGY_DIRECTWRITE);
|
|
|
|
#endif
|
|
|
|
|
2021-06-28 10:19:12 +00:00
|
|
|
m_scintillaTricks = new SCINTILLA_TRICKS( m_MultiLineText, wxT( "{}" ), false,
|
2024-03-10 10:46:26 +00:00
|
|
|
// onAcceptFn
|
2023-08-02 19:11:59 +00:00
|
|
|
[this]( wxKeyEvent& aEvent )
|
2021-06-28 10:19:12 +00:00
|
|
|
{
|
|
|
|
wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
|
2023-05-24 22:46:48 +00:00
|
|
|
},
|
2024-03-10 10:46:26 +00:00
|
|
|
// onCharFn
|
2023-05-24 22:46:48 +00:00
|
|
|
[this]( wxStyledTextEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_scintillaTricks->DoTextVarAutocomplete(
|
2024-03-10 10:46:26 +00:00
|
|
|
// getTokensFn
|
|
|
|
[this]( const wxString& xRef, wxArrayString* tokens )
|
2023-05-24 22:46:48 +00:00
|
|
|
{
|
2024-03-10 10:46:26 +00:00
|
|
|
m_frame->GetContextualTextVars( m_item, xRef, tokens );
|
2023-05-24 22:46:48 +00:00
|
|
|
} );
|
2021-06-28 10:19:12 +00:00
|
|
|
} );
|
2021-06-24 22:50:57 +00:00
|
|
|
|
2020-04-19 19:09:26 +00:00
|
|
|
// A hack which causes Scintilla to auto-size the text editor canvas
|
|
|
|
// See: https://github.com/jacobslusser/ScintillaNET/issues/216
|
|
|
|
m_MultiLineText->SetScrollWidth( 1 );
|
|
|
|
m_MultiLineText->SetScrollWidthTracking( true );
|
2020-04-18 20:40:54 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( m_item->GetParentFootprint() )
|
2018-06-06 10:05:56 +00:00
|
|
|
{
|
2023-06-13 12:49:07 +00:00
|
|
|
m_PositionXLabel->SetLabel( _( "Offset X:" ) );
|
|
|
|
m_PositionYLabel->SetLabel( _( "Offset Y:" ) );
|
|
|
|
|
2023-06-06 17:30:03 +00:00
|
|
|
if( m_item->Type() == PCB_FIELD_T )
|
2021-10-31 16:32:24 +00:00
|
|
|
{
|
2023-06-06 17:30:03 +00:00
|
|
|
PCB_FIELD* field = static_cast<PCB_FIELD*>( m_item );
|
2021-10-31 16:32:24 +00:00
|
|
|
|
2023-06-06 17:30:03 +00:00
|
|
|
if( field->IsReference() )
|
|
|
|
{
|
|
|
|
title = _( "Footprint Reference Properties" );
|
|
|
|
m_TextLabel->SetLabel( _( "Reference:" ) );
|
|
|
|
}
|
|
|
|
else if( field->IsValue() )
|
|
|
|
{
|
|
|
|
title = _( "Footprint Value Properties" );
|
|
|
|
m_TextLabel->SetLabel( _( "Value:" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-23 10:53:25 +00:00
|
|
|
// Don't let users modify the library link, in the board editor
|
|
|
|
if( field->IsFootprint() && !m_frame->IsType( FRAME_FOOTPRINT_EDITOR ) )
|
2023-06-13 16:56:24 +00:00
|
|
|
m_SingleLineText->SetEditable( false );
|
|
|
|
|
2023-06-06 17:30:03 +00:00
|
|
|
title = _( "Footprint Field Properties" );
|
|
|
|
m_TextLabel->SetLabel( _( "Text:" ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2018-06-06 10:05:56 +00:00
|
|
|
{
|
2023-06-06 17:30:03 +00:00
|
|
|
title = _( "Footprint Text Properties" );
|
|
|
|
m_TextLabel->SetLabel( _( "Text:" ) );
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
2018-07-21 12:49:19 +00:00
|
|
|
|
|
|
|
SetInitialFocus( m_SingleLineText );
|
|
|
|
m_MultiLineSizer->Show( false );
|
2021-10-31 16:32:24 +00:00
|
|
|
|
|
|
|
// Do not allow locking items in the footprint editor
|
|
|
|
m_cbLocked->Show( false );
|
2023-06-17 17:34:37 +00:00
|
|
|
|
|
|
|
m_tabOrder = {
|
|
|
|
m_SingleLineText,
|
|
|
|
m_LayerSelectionCtrl,
|
|
|
|
m_SizeXCtrl,
|
|
|
|
m_SizeYCtrl,
|
|
|
|
m_ThicknessCtrl,
|
|
|
|
m_Visible,
|
|
|
|
m_cbKnockout,
|
|
|
|
m_KeepUpright,
|
|
|
|
m_PositionXCtrl,
|
|
|
|
m_PositionYCtrl,
|
|
|
|
m_OrientCtrl,
|
|
|
|
m_sdbSizerOK,
|
|
|
|
m_sdbSizerCancel
|
|
|
|
};
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
title = _( "Text Properties" );
|
|
|
|
|
2018-07-21 12:49:19 +00:00
|
|
|
SetInitialFocus( m_MultiLineText );
|
|
|
|
m_SingleLineSizer->Show( false );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2021-01-18 14:31:56 +00:00
|
|
|
// This option makes sense only for footprint texts; texts on board are always visible.
|
2018-12-02 09:30:48 +00:00
|
|
|
m_Visible->SetValue( true );
|
2021-10-31 16:32:24 +00:00
|
|
|
m_Visible->Show( false );
|
2018-12-02 09:30:48 +00:00
|
|
|
|
2018-06-06 10:05:56 +00:00
|
|
|
m_KeepUpright->Show( false );
|
2018-07-21 12:49:19 +00:00
|
|
|
m_statusLine->Show( false );
|
2023-06-17 17:34:37 +00:00
|
|
|
|
|
|
|
m_tabOrder = {
|
|
|
|
m_MultiLineText,
|
|
|
|
m_cbLocked,
|
|
|
|
m_LayerSelectionCtrl,
|
|
|
|
m_SizeXCtrl,
|
|
|
|
m_SizeYCtrl,
|
|
|
|
m_ThicknessCtrl,
|
|
|
|
m_cbKnockout,
|
|
|
|
m_PositionXCtrl,
|
|
|
|
m_PositionYCtrl,
|
|
|
|
m_OrientCtrl,
|
|
|
|
m_sdbSizerOK,
|
|
|
|
m_sdbSizerCancel
|
|
|
|
};
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
m_bold->SetIsCheckButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_bold->SetBitmap( KiBitmapBundle( BITMAPS::text_bold ) );
|
2021-11-07 22:41:03 +00:00
|
|
|
m_italic->SetIsCheckButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_italic->SetBitmap( KiBitmapBundle( BITMAPS::text_italic ) );
|
2021-11-07 22:41:03 +00:00
|
|
|
|
|
|
|
m_separator1->SetIsSeparator();
|
|
|
|
|
2022-06-12 19:09:21 +00:00
|
|
|
m_alignLeft->SetIsRadioButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_alignLeft->SetBitmap( KiBitmapBundle( BITMAPS::text_align_left ) );
|
2022-06-12 19:09:21 +00:00
|
|
|
m_alignCenter->SetIsRadioButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_alignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_align_center ) );
|
2022-06-12 19:09:21 +00:00
|
|
|
m_alignRight->SetIsRadioButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_alignRight->SetBitmap( KiBitmapBundle( BITMAPS::text_align_right ) );
|
2021-11-07 22:41:03 +00:00
|
|
|
|
|
|
|
m_separator2->SetIsSeparator();
|
|
|
|
|
2023-01-08 12:13:06 +00:00
|
|
|
m_valignBottom->SetIsRadioButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_valignBottom->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_bottom ) );
|
2023-01-08 12:13:06 +00:00
|
|
|
m_valignCenter->SetIsRadioButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_valignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_center ) );
|
2023-01-08 12:13:06 +00:00
|
|
|
m_valignTop->SetIsRadioButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_valignTop->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_top ) );
|
2021-11-07 22:41:03 +00:00
|
|
|
|
|
|
|
m_separator3->SetIsSeparator();
|
|
|
|
|
2023-01-08 12:13:06 +00:00
|
|
|
m_mirrored->SetIsCheckButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_mirrored->SetBitmap( KiBitmapBundle( BITMAPS::text_mirrored ) );
|
2023-01-08 12:13:06 +00:00
|
|
|
|
2018-06-06 10:05:56 +00:00
|
|
|
SetTitle( title );
|
|
|
|
m_hash_key = title;
|
|
|
|
|
|
|
|
// Configure the layers list selector. Note that footprints are built outside the current
|
|
|
|
// board and so we may need to show all layers if the text is on an unactivated layer.
|
2022-01-03 01:20:25 +00:00
|
|
|
if( !m_frame->GetBoard()->IsLayerEnabled( m_item->GetLayer() ) )
|
2018-06-06 10:05:56 +00:00
|
|
|
m_LayerSelectionCtrl->ShowNonActivatedLayers( true );
|
|
|
|
|
|
|
|
m_LayerSelectionCtrl->SetLayersHotkeys( false );
|
2022-01-03 01:20:25 +00:00
|
|
|
m_LayerSelectionCtrl->SetBoardFrame( m_frame );
|
2018-06-06 10:05:56 +00:00
|
|
|
m_LayerSelectionCtrl->Resync();
|
|
|
|
|
2020-12-11 15:23:40 +00:00
|
|
|
m_orientation.SetUnits( EDA_UNITS::DEGREES );
|
|
|
|
m_orientation.SetPrecision( 3 );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2021-01-01 23:42:44 +00:00
|
|
|
// Set predefined rotations in combo dropdown, according to the locale floating point
|
|
|
|
// separator notation
|
2020-12-11 15:23:40 +00:00
|
|
|
double rot_list[] = { 0.0, 90.0, -90.0, 180.0 };
|
|
|
|
|
|
|
|
for( size_t ii = 0; ii < m_OrientCtrl->GetCount() && ii < 4; ++ii )
|
2022-02-04 22:44:59 +00:00
|
|
|
m_OrientCtrl->SetString( ii, wxString::Format( wxT( "%.1f" ), rot_list[ii] ) );
|
2018-12-05 18:08:06 +00:00
|
|
|
|
2018-07-17 21:14:02 +00:00
|
|
|
// Set font sizes
|
2021-09-11 19:07:33 +00:00
|
|
|
m_statusLine->SetFont( KIUI::GetInfoFont( this ) );
|
2018-07-17 21:14:02 +00:00
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
2018-06-06 10:05:56 +00:00
|
|
|
|
|
|
|
// wxTextCtrls fail to generate wxEVT_CHAR events when the wxTE_MULTILINE flag is set,
|
|
|
|
// so we have to listen to wxEVT_CHAR_HOOK events instead.
|
2021-07-19 23:56:05 +00:00
|
|
|
Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( DIALOG_TEXT_PROPERTIES::OnCharHook ),
|
|
|
|
nullptr, this );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_TEXT_PROPERTIES::~DIALOG_TEXT_PROPERTIES()
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
Disconnect( wxEVT_CHAR_HOOK, wxKeyEventHandler( DIALOG_TEXT_PROPERTIES::OnCharHook ),
|
|
|
|
nullptr, this );
|
2021-06-24 22:50:57 +00:00
|
|
|
|
|
|
|
delete m_scintillaTricks;
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::ShowTextPropertiesDialog( PCB_TEXT* aText )
|
2018-06-06 10:05:56 +00:00
|
|
|
{
|
2019-05-28 23:23:58 +00:00
|
|
|
DIALOG_TEXT_PROPERTIES dlg( this, aText );
|
2024-03-10 12:18:27 +00:00
|
|
|
|
|
|
|
// QuasiModal required for Scintilla auto-complete
|
2021-02-20 13:06:12 +00:00
|
|
|
dlg.ShowQuasiModal();
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-25 16:25:26 +00:00
|
|
|
void DIALOG_TEXT_PROPERTIES::OnSetFocusText( wxFocusEvent& event )
|
|
|
|
{
|
2023-06-06 17:30:03 +00:00
|
|
|
if( m_item->Type() == PCB_FIELD_T && static_cast<PCB_FIELD*>( m_item )->IsReference() )
|
|
|
|
{
|
2020-11-25 16:25:26 +00:00
|
|
|
#ifdef __WXGTK__
|
2023-06-06 17:30:03 +00:00
|
|
|
// Force an update of the text control before setting the text selection
|
|
|
|
// This is needed because GTK seems to ignore the selection on first update
|
|
|
|
//
|
|
|
|
// Note that we can't do this on OSX as it tends to provoke Apple's
|
|
|
|
// "[NSAlert runModal] may not be invoked inside of transaction begin/commit pair"
|
|
|
|
// bug. See: https://bugs.launchpad.net/kicad/+bug/1837225
|
2020-11-26 00:05:57 +00:00
|
|
|
m_SingleLineText->Update();
|
2020-11-25 16:25:26 +00:00
|
|
|
#endif
|
|
|
|
KIUI::SelectReferenceNumber( static_cast<wxTextEntry*>( m_SingleLineText ) );
|
2023-06-06 17:30:03 +00:00
|
|
|
}
|
2020-11-25 16:25:26 +00:00
|
|
|
else
|
|
|
|
m_SingleLineText->SetSelection( -1, -1 );
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-21 12:49:19 +00:00
|
|
|
bool DIALOG_TEXT_PROPERTIES::TransferDataToWindow()
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
BOARD* board = m_frame->GetBoard();
|
|
|
|
FOOTPRINT* parentFP = m_item->GetParentFootprint();
|
2024-01-24 13:34:04 +00:00
|
|
|
wxString msg = board->ConvertKIIDsToCrossReferences( UnescapeString( m_item->GetText() ) );
|
2023-03-30 11:49:23 +00:00
|
|
|
|
2018-06-06 10:05:56 +00:00
|
|
|
if( m_SingleLineText->IsShown() )
|
|
|
|
{
|
2024-01-24 13:34:04 +00:00
|
|
|
m_SingleLineText->SetValue( msg );
|
2018-10-13 23:06:41 +00:00
|
|
|
|
2023-06-06 17:30:03 +00:00
|
|
|
if( m_item->Type() == PCB_FIELD_T && static_cast<PCB_FIELD*>( m_item )->IsReference() )
|
2020-10-25 16:41:38 +00:00
|
|
|
KIUI::SelectReferenceNumber( static_cast<wxTextEntry*>( m_SingleLineText ) );
|
2018-10-13 23:06:41 +00:00
|
|
|
else
|
|
|
|
m_SingleLineText->SetSelection( -1, -1 );
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
2018-07-21 12:49:19 +00:00
|
|
|
else if( m_MultiLineText->IsShown() )
|
2018-06-06 10:05:56 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
m_MultiLineText->SetValue( msg );
|
2018-06-06 10:05:56 +00:00
|
|
|
m_MultiLineText->SetSelection( -1, -1 );
|
2022-10-14 21:00:54 +00:00
|
|
|
m_MultiLineText->EmptyUndoBuffer();
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( parentFP )
|
2018-06-06 10:05:56 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
m_statusLine->SetLabel( wxString::Format( _( "Footprint %s (%s), %s, rotated %.1f deg"),
|
|
|
|
parentFP->GetReference(),
|
|
|
|
parentFP->GetValue(),
|
|
|
|
parentFP->IsFlipped() ? _( "back side (mirrored)" )
|
|
|
|
: _( "front side" ),
|
|
|
|
parentFP->GetOrientation().AsDegrees() ) );
|
2018-07-21 12:49:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_statusLine->Show( false );
|
|
|
|
}
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2021-01-12 09:00:21 +00:00
|
|
|
m_cbLocked->SetValue( m_item->IsLocked() );
|
|
|
|
|
2020-10-13 17:46:48 +00:00
|
|
|
m_LayerSelectionCtrl->SetLayerSelection( m_item->GetLayer() );
|
2022-03-08 13:16:39 +00:00
|
|
|
m_cbKnockout->SetValue( m_item->IsKnockout() );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
m_fontCtrl->SetFontSelection( m_item->GetFont() );
|
2022-01-03 01:20:25 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
m_textWidth.SetValue( m_item->GetTextSize().x );
|
|
|
|
m_textHeight.SetValue( m_item->GetTextSize().y );
|
|
|
|
m_thickness.SetValue( m_item->GetTextThickness() );
|
|
|
|
m_posX.SetValue( m_item->GetFPRelativePosition().x );
|
|
|
|
m_posY.SetValue( m_item->GetFPRelativePosition().y );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
m_Visible->SetValue( m_item->IsVisible() );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( parentFP )
|
|
|
|
m_KeepUpright->SetValue( m_item->IsKeepUpright() );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
m_bold->Check( m_item->IsBold() );
|
|
|
|
m_italic->Check( m_item->IsItalic() );
|
2021-11-07 22:41:03 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
switch ( m_item->GetHorizJustify() )
|
2021-11-07 22:41:03 +00:00
|
|
|
{
|
2024-02-03 13:43:41 +00:00
|
|
|
case GR_TEXT_H_ALIGN_LEFT: m_alignLeft->Check( true ); break;
|
|
|
|
case GR_TEXT_H_ALIGN_CENTER: m_alignCenter->Check( true ); break;
|
|
|
|
case GR_TEXT_H_ALIGN_RIGHT: m_alignRight->Check( true ); break;
|
|
|
|
case GR_TEXT_H_ALIGN_INDETERMINATE: break;
|
2021-11-07 22:41:03 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
switch ( m_item->GetVertJustify() )
|
2023-01-08 12:13:06 +00:00
|
|
|
{
|
2024-02-03 13:43:41 +00:00
|
|
|
case GR_TEXT_V_ALIGN_BOTTOM: m_valignBottom->Check( true ); break;
|
|
|
|
case GR_TEXT_V_ALIGN_CENTER: m_valignCenter->Check( true ); break;
|
|
|
|
case GR_TEXT_V_ALIGN_TOP: m_valignTop->Check( true ); break;
|
|
|
|
case GR_TEXT_V_ALIGN_INDETERMINATE: break;
|
2023-01-08 12:13:06 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
m_mirrored->Check( m_item->IsMirrored() );
|
2021-11-07 22:41:03 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
EDA_ANGLE orientation = m_item->GetTextAngle();
|
2022-04-10 21:43:09 +00:00
|
|
|
m_orientation.SetAngleValue( orientation.Normalize180() );
|
2021-11-07 22:41:03 +00:00
|
|
|
|
2018-06-06 10:05:56 +00:00
|
|
|
return DIALOG_TEXT_PROPERTIES_BASE::TransferDataToWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
void DIALOG_TEXT_PROPERTIES::onFontSelected( wxCommandEvent & aEvent )
|
|
|
|
{
|
|
|
|
if( KIFONT::FONT::IsStroke( aEvent.GetString() ) )
|
|
|
|
{
|
|
|
|
m_thickness.Show( true );
|
|
|
|
|
|
|
|
int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() );
|
|
|
|
int thickness = m_thickness.GetValue();
|
|
|
|
|
|
|
|
m_bold->Check( abs( thickness - GetPenSizeForBold( textSize ) )
|
|
|
|
< abs( thickness - GetPenSizeForNormal( textSize ) ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_thickness.Show( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_TEXT_PROPERTIES::onBoldToggle( wxCommandEvent & aEvent )
|
|
|
|
{
|
|
|
|
int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() );
|
|
|
|
|
|
|
|
if( aEvent.IsChecked() )
|
|
|
|
m_thickness.ChangeValue( GetPenSizeForBold( textSize ) );
|
|
|
|
else
|
|
|
|
m_thickness.ChangeValue( GetPenSizeForNormal( textSize ) );
|
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-07 22:41:03 +00:00
|
|
|
void DIALOG_TEXT_PROPERTIES::onAlignButton( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
for( BITMAP_BUTTON* btn : { m_alignLeft, m_alignCenter, m_alignRight } )
|
|
|
|
{
|
|
|
|
if( btn->IsChecked() && btn != aEvent.GetEventObject() )
|
|
|
|
btn->Check( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-08 12:13:06 +00:00
|
|
|
void DIALOG_TEXT_PROPERTIES::onValignButton( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
for( BITMAP_BUTTON* btn : { m_valignBottom, m_valignCenter, m_valignTop } )
|
|
|
|
{
|
|
|
|
if( btn->IsChecked() && btn != aEvent.GetEventObject() )
|
|
|
|
btn->Check( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
void DIALOG_TEXT_PROPERTIES::onThickness( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
int textSize = std::min( m_textWidth.GetValue(), m_textHeight.GetValue() );
|
|
|
|
int thickness = m_thickness.GetValue();
|
|
|
|
|
|
|
|
m_bold->Check( abs( thickness - GetPenSizeForBold( textSize ) )
|
|
|
|
< abs( thickness - GetPenSizeForNormal( textSize ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-06 10:05:56 +00:00
|
|
|
bool DIALOG_TEXT_PROPERTIES::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
if( !DIALOG_TEXT_PROPERTIES_BASE::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
2024-03-23 13:15:31 +00:00
|
|
|
int minSize = pcbIUScale.mmToIU( TEXT_MIN_SIZE_MM );
|
|
|
|
int maxSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
|
2023-06-03 15:59:00 +00:00
|
|
|
|
|
|
|
if( !m_textWidth.Validate( minSize, maxSize ) || !m_textHeight.Validate( minSize, maxSize ) )
|
2018-06-06 10:05:56 +00:00
|
|
|
return false;
|
|
|
|
|
2024-01-24 13:34:04 +00:00
|
|
|
BOARD* board = m_frame->GetBoard();
|
2022-01-03 01:20:25 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2018-06-06 10:05:56 +00:00
|
|
|
commit.Modify( m_item );
|
|
|
|
|
|
|
|
// If no other command in progress, prepare undo command
|
|
|
|
// (for a command in progress, will be made later, at the completion of command)
|
2019-04-22 08:58:06 +00:00
|
|
|
bool pushCommit = ( m_item->GetEditFlags() == 0 );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2021-01-01 23:42:44 +00:00
|
|
|
// Set IN_EDIT flag to force undo/redo/abort proper operation and avoid new calls to
|
|
|
|
// SaveCopyInUndoList for the same text if is moved, and then rotated, edited, etc....
|
2018-09-18 10:52:15 +00:00
|
|
|
if( !pushCommit )
|
2018-06-06 10:05:56 +00:00
|
|
|
m_item->SetFlags( IN_EDIT );
|
|
|
|
|
|
|
|
// Set the new text content
|
2018-07-21 12:49:19 +00:00
|
|
|
if( m_SingleLineText->IsShown() )
|
|
|
|
{
|
|
|
|
if( !m_SingleLineText->GetValue().IsEmpty() )
|
2024-01-24 13:34:04 +00:00
|
|
|
{
|
|
|
|
wxString txt = board->ConvertCrossReferencesToKIIDs( m_SingleLineText->GetValue() );
|
|
|
|
|
|
|
|
m_item->SetText( txt );
|
|
|
|
}
|
2018-07-21 12:49:19 +00:00
|
|
|
}
|
|
|
|
else if( m_MultiLineText->IsShown() )
|
|
|
|
{
|
|
|
|
if( !m_MultiLineText->GetValue().IsEmpty() )
|
2019-09-10 08:57:04 +00:00
|
|
|
{
|
2021-01-01 23:42:44 +00:00
|
|
|
wxString txt = board->ConvertCrossReferencesToKIIDs( m_MultiLineText->GetValue() );
|
2020-04-06 13:06:57 +00:00
|
|
|
|
2021-06-15 12:20:52 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
// On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting.
|
|
|
|
// Replace it now.
|
2022-02-04 22:44:59 +00:00
|
|
|
txt.Replace( wxT( "\r" ), wxT( "\n" ) );
|
2021-06-15 14:21:01 +00:00
|
|
|
#elif defined( __WINDOWS__ )
|
2021-01-01 23:42:44 +00:00
|
|
|
// On Windows, a new line is coded as \r\n. We use only \n in kicad files and in
|
|
|
|
// drawing routines so strip the \r char.
|
2022-02-04 22:44:59 +00:00
|
|
|
txt.Replace( wxT( "\r" ), wxT( "" ) );
|
2019-09-10 08:57:04 +00:00
|
|
|
#endif
|
2023-03-30 11:49:23 +00:00
|
|
|
m_item->SetText( EscapeString( txt, CTX_QUOTED_STR ) );
|
2019-09-10 08:57:04 +00:00
|
|
|
}
|
2018-07-21 12:49:19 +00:00
|
|
|
}
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2021-01-12 09:00:21 +00:00
|
|
|
m_item->SetLocked( m_cbLocked->GetValue() );
|
|
|
|
|
2018-06-06 10:05:56 +00:00
|
|
|
m_item->SetLayer( ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() ) );
|
2022-03-08 13:16:39 +00:00
|
|
|
m_item->SetIsKnockout( m_cbKnockout->GetValue() );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
if( m_fontCtrl->HaveFontSelection() )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
m_item->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(),
|
|
|
|
m_italic->IsChecked() ) );
|
2022-01-03 01:20:25 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
m_item->SetTextSize( VECTOR2I( m_textWidth.GetValue(), m_textHeight.GetValue() ) );
|
|
|
|
m_item->SetTextThickness( m_thickness.GetValue() );
|
|
|
|
m_item->SetFPRelativePosition( VECTOR2I( m_posX.GetValue(), m_posY.GetValue() ) );
|
2018-07-19 22:25:58 +00:00
|
|
|
|
2018-06-06 10:05:56 +00:00
|
|
|
// Test for acceptable values for thickness and size and clamp if fails
|
2023-03-30 11:49:23 +00:00
|
|
|
int maxPenWidth = Clamp_Text_PenSize( m_item->GetTextThickness(), m_item->GetTextSize() );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( m_item->GetTextThickness() > maxPenWidth )
|
2018-06-06 10:05:56 +00:00
|
|
|
{
|
2018-07-21 12:49:19 +00:00
|
|
|
DisplayError( this, _( "The text thickness is too large for the text size.\n"
|
2018-06-06 10:05:56 +00:00
|
|
|
"It will be clamped." ) );
|
2023-03-30 11:49:23 +00:00
|
|
|
m_item->SetTextThickness( maxPenWidth );
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
m_item->SetTextAngle( m_orientation.GetAngleValue().Normalize() );
|
2021-11-07 22:41:03 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
m_item->SetVisible( m_Visible->GetValue() );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( m_KeepUpright->IsShown() )
|
|
|
|
m_item->SetKeepUpright( m_KeepUpright->GetValue() );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2024-02-25 17:28:05 +00:00
|
|
|
m_item->SetBoldFlag( m_bold->IsChecked() );
|
2023-03-30 11:49:23 +00:00
|
|
|
m_item->SetItalic( m_italic->IsChecked() );
|
2022-01-03 01:20:25 +00:00
|
|
|
|
2021-11-07 22:41:03 +00:00
|
|
|
if( m_alignLeft->IsChecked() )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_item->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2021-11-07 22:41:03 +00:00
|
|
|
else if( m_alignCenter->IsChecked() )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_item->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
2021-11-07 22:41:03 +00:00
|
|
|
else
|
2023-03-30 11:49:23 +00:00
|
|
|
m_item->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
2021-11-07 22:41:03 +00:00
|
|
|
|
2023-01-08 12:13:06 +00:00
|
|
|
if( m_valignBottom->IsChecked() )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_item->SetVertJustify ( GR_TEXT_V_ALIGN_BOTTOM );
|
2023-01-08 12:13:06 +00:00
|
|
|
else if( m_valignCenter->IsChecked() )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_item->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2023-01-08 12:13:06 +00:00
|
|
|
else
|
2023-03-30 11:49:23 +00:00
|
|
|
m_item->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
2023-01-08 12:13:06 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
m_item->SetMirrored( m_mirrored->IsChecked() );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
|
|
|
if( pushCommit )
|
2024-02-03 13:43:41 +00:00
|
|
|
commit.Push( _( "Edit Text Properties" ) );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-11-20 01:23:43 +00:00
|
|
|
|
|
|
|
|
2021-11-27 09:08:30 +00:00
|
|
|
void DIALOG_TEXT_PROPERTIES::onMultiLineTCLostFocus( wxFocusEvent& event )
|
2021-11-20 01:23:43 +00:00
|
|
|
{
|
|
|
|
if( m_scintillaTricks )
|
|
|
|
m_scintillaTricks->CancelAutocomplete();
|
2021-11-27 09:08:30 +00:00
|
|
|
|
|
|
|
event.Skip();
|
2021-11-20 01:23:43 +00:00
|
|
|
}
|