2021-10-12 20:05:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
|
2024-01-28 12:58:09 +00:00
|
|
|
* Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-10-12 20:05:37 +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 <sch_edit_frame.h>
|
|
|
|
#include <widgets/bitmap_button.h>
|
2022-01-03 01:20:25 +00:00
|
|
|
#include <widgets/font_choice.h>
|
2022-03-31 18:43:08 +00:00
|
|
|
#include <widgets/color_swatch.h>
|
2022-08-28 22:25:01 +00:00
|
|
|
#include <widgets/wx_combobox.h>
|
2022-03-29 19:41:03 +00:00
|
|
|
#include <settings/color_settings.h>
|
2022-01-25 22:33:37 +00:00
|
|
|
#include <sch_textbox.h>
|
2021-10-12 20:05:37 +00:00
|
|
|
#include <confirm.h>
|
|
|
|
#include <schematic.h>
|
2023-06-09 21:41:33 +00:00
|
|
|
#include <sch_commit.h>
|
2021-10-12 20:05:37 +00:00
|
|
|
#include <dialogs/html_message_box.h>
|
|
|
|
#include <scintilla_tricks.h>
|
|
|
|
#include <dialog_text_properties.h>
|
2022-09-20 18:41:16 +00:00
|
|
|
#include <gr_text.h>
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_ITEM* aTextItem ) :
|
2021-10-12 20:05:37 +00:00
|
|
|
DIALOG_TEXT_PROPERTIES_BASE( aParent ),
|
2022-01-25 22:33:37 +00:00
|
|
|
m_frame( aParent ),
|
|
|
|
m_currentItem( aTextItem ),
|
|
|
|
m_currentText( dynamic_cast<EDA_TEXT*>( aTextItem ) ),
|
|
|
|
m_textSize( aParent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits ),
|
|
|
|
m_borderWidth( aParent, m_borderWidthLabel, m_borderWidthCtrl, m_borderWidthUnits ),
|
2021-10-12 20:05:37 +00:00
|
|
|
m_scintillaTricks( nullptr ),
|
|
|
|
m_helpWindow( nullptr )
|
|
|
|
{
|
2022-03-31 18:43:08 +00:00
|
|
|
COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
|
|
|
|
COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
if( aTextItem->Type() == SCH_TEXTBOX_T )
|
|
|
|
{
|
|
|
|
SetTitle( _( "Text Box Properties" ) );
|
|
|
|
|
|
|
|
m_borderColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
|
2022-03-31 18:43:08 +00:00
|
|
|
m_borderColorSwatch->SetSwatchBackground( schematicBackground );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
for( const auto& [ lineStyle, lineStyleDesc ] : lineTypeNames )
|
2024-01-22 03:55:13 +00:00
|
|
|
m_borderStyleCombo->Append( lineStyleDesc.name,
|
|
|
|
KiBitmapBundle( lineStyleDesc.bitmap ) );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
m_borderStyleCombo->Append( DEFAULT_STYLE );
|
2022-03-11 23:13:05 +00:00
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
|
2022-03-31 18:43:08 +00:00
|
|
|
m_fillColorSwatch->SetSwatchBackground( schematicBackground );
|
2022-03-29 19:41:03 +00:00
|
|
|
|
|
|
|
if( m_frame->GetColorSettings()->GetOverrideSchItemColors() )
|
|
|
|
m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
|
2022-05-14 13:52:53 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
else
|
|
|
|
{
|
2022-01-31 19:11:21 +00:00
|
|
|
m_borderCheckbox->Show( false );
|
2022-01-25 22:33:37 +00:00
|
|
|
m_borderWidth.Show( false );
|
|
|
|
m_borderColorLabel->Show( false );
|
|
|
|
m_panelBorderColor->Show( false );
|
|
|
|
m_borderStyleLabel->Show( false );
|
|
|
|
m_borderStyleCombo->Show( false );
|
|
|
|
m_fillColorLabel->Show( false );
|
|
|
|
m_panelFillColor->Show( false );
|
2022-02-08 08:37:50 +00:00
|
|
|
m_filledCtrl->Show( false );
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
m_textCtrl->SetEOLMode( wxSTC_EOL_LF );
|
|
|
|
|
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
|
2024-01-28 12:58:09 +00:00
|
|
|
m_textCtrl->SetTechnology( wxSTC_TECHNOLOGY_DIRECTWRITE );
|
2023-08-03 16:28:37 +00:00
|
|
|
#endif
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
m_scintillaTricks = new SCINTILLA_TRICKS( m_textCtrl, wxT( "{}" ), false,
|
2023-05-24 22:46:48 +00:00
|
|
|
// onAccept handler
|
2023-08-02 19:11:59 +00:00
|
|
|
[this]( wxKeyEvent& aEvent )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
|
2023-05-24 22:46:48 +00:00
|
|
|
},
|
2024-01-28 12:58:09 +00:00
|
|
|
|
2023-05-24 22:46:48 +00:00
|
|
|
// onCharAdded handler
|
|
|
|
[this]( wxStyledTextEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_scintillaTricks->DoTextVarAutocomplete(
|
|
|
|
[this]( const wxString& crossRef, wxArrayString* tokens )
|
|
|
|
{
|
|
|
|
getContextualTextVars( crossRef, tokens );
|
|
|
|
} );
|
2021-10-12 20:05:37 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
m_textEntrySizer->AddGrowableRow( 0 );
|
|
|
|
|
2022-03-31 18:43:08 +00:00
|
|
|
m_textColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
|
|
|
|
m_textColorSwatch->SetSwatchBackground( schematicBackground );
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
SetInitialFocus( m_textCtrl );
|
|
|
|
|
|
|
|
m_separator1->SetIsSeparator();
|
|
|
|
|
|
|
|
m_bold->SetIsCheckButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_bold->SetBitmap( KiBitmapBundle( BITMAPS::text_bold ) );
|
2021-10-12 20:05:37 +00:00
|
|
|
m_italic->SetIsCheckButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_italic->SetBitmap( KiBitmapBundle( BITMAPS::text_italic ) );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
m_separator2->SetIsSeparator();
|
|
|
|
|
2022-09-02 18:15:40 +00:00
|
|
|
m_hAlignLeft->SetIsRadioButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_hAlignLeft->SetBitmap( KiBitmapBundle( BITMAPS::text_align_left ) );
|
2022-09-02 18:15:40 +00:00
|
|
|
m_hAlignCenter->SetIsRadioButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_hAlignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_align_center ) );
|
2022-09-02 18:15:40 +00:00
|
|
|
m_hAlignRight->SetIsRadioButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_hAlignRight->SetBitmap( KiBitmapBundle( BITMAPS::text_align_right ) );
|
2023-11-25 12:38:24 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
m_separator3->SetIsSeparator();
|
|
|
|
|
2022-09-02 18:15:40 +00:00
|
|
|
m_vAlignTop->SetIsRadioButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_vAlignTop->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_top ) );
|
2022-09-02 18:15:40 +00:00
|
|
|
m_vAlignCenter->SetIsRadioButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_vAlignCenter->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_center ) );
|
2022-09-02 18:15:40 +00:00
|
|
|
m_vAlignBottom->SetIsRadioButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_vAlignBottom->SetBitmap( KiBitmapBundle( BITMAPS::text_valign_bottom ) );
|
2022-09-02 18:15:40 +00:00
|
|
|
|
|
|
|
m_separator4->SetIsSeparator();
|
|
|
|
|
|
|
|
m_horizontal->SetIsRadioButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_horizontal->SetBitmap( KiBitmapBundle( BITMAPS::text_horizontal ) );
|
2022-09-02 18:15:40 +00:00
|
|
|
m_vertical->SetIsRadioButton();
|
2023-10-21 18:56:19 +00:00
|
|
|
m_vertical->SetBitmap( KiBitmapBundle( BITMAPS::text_vertical ) );
|
2022-09-02 18:15:40 +00:00
|
|
|
|
|
|
|
m_separator5->SetIsSeparator();
|
|
|
|
|
2022-08-27 18:14:57 +00:00
|
|
|
SCH_SHEET_LIST sheetList = m_frame->Schematic().GetSheets();
|
|
|
|
sheetList.SortByPageNumbers( false );
|
|
|
|
|
|
|
|
for( const SCH_SHEET_PATH& sheet : sheetList )
|
|
|
|
{
|
|
|
|
wxString sheetPageNum = sheet.GetPageNumber();
|
|
|
|
wxString sheetName = sheet.size() == 1 ? _( "<root sheet>" ) : sheet.Last()->GetName();
|
|
|
|
|
2022-08-28 22:25:01 +00:00
|
|
|
m_hyperlinkCombo->Append( wxT( "#" ) + sheetPageNum,
|
|
|
|
wxString::Format( _( "Page %s (%s)" ), sheetPageNum, sheetName ) );
|
2022-08-27 18:14:57 +00:00
|
|
|
m_pageNumbers.push_back( sheetPageNum );
|
|
|
|
}
|
|
|
|
|
2022-08-28 11:04:23 +00:00
|
|
|
m_hyperlinkCombo->Append( wxT( "---" ) );
|
2022-08-28 22:25:01 +00:00
|
|
|
m_hyperlinkCombo->Append( wxT( "file://" ), wxT( "file://..." ) );
|
|
|
|
m_hyperlinkCombo->Append( wxT( "http://" ), wxT( "http://..." ) );
|
|
|
|
m_hyperlinkCombo->Append( wxT( "https://" ), wxT( "https://..." ) );
|
2022-08-27 18:14:57 +00:00
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
2021-10-12 20:05:37 +00:00
|
|
|
Layout();
|
|
|
|
|
2022-09-02 18:15:40 +00:00
|
|
|
m_hAlignLeft->Bind( wxEVT_BUTTON, &DIALOG_TEXT_PROPERTIES::onHAlignButton, this );
|
|
|
|
m_hAlignCenter->Bind( wxEVT_BUTTON, &DIALOG_TEXT_PROPERTIES::onHAlignButton, this );
|
|
|
|
m_hAlignRight->Bind( wxEVT_BUTTON, &DIALOG_TEXT_PROPERTIES::onHAlignButton, this );
|
|
|
|
m_vAlignTop->Bind( wxEVT_BUTTON, &DIALOG_TEXT_PROPERTIES::onVAlignButton, this );
|
|
|
|
m_vAlignCenter->Bind( wxEVT_BUTTON, &DIALOG_TEXT_PROPERTIES::onVAlignButton, this );
|
|
|
|
m_vAlignBottom->Bind( wxEVT_BUTTON, &DIALOG_TEXT_PROPERTIES::onVAlignButton, this );
|
|
|
|
m_horizontal->Bind( wxEVT_BUTTON, &DIALOG_TEXT_PROPERTIES::onTextAngleButton, this );
|
|
|
|
m_vertical->Bind( wxEVT_BUTTON, &DIALOG_TEXT_PROPERTIES::onTextAngleButton, this );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
finishDialogSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_TEXT_PROPERTIES::~DIALOG_TEXT_PROPERTIES()
|
|
|
|
{
|
|
|
|
delete m_scintillaTricks;
|
|
|
|
|
|
|
|
if( m_helpWindow )
|
|
|
|
m_helpWindow->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-24 22:46:48 +00:00
|
|
|
void DIALOG_TEXT_PROPERTIES::getContextualTextVars( const wxString& aCrossRef,
|
|
|
|
wxArrayString* aTokens )
|
|
|
|
{
|
|
|
|
if( !aCrossRef.IsEmpty() )
|
|
|
|
{
|
|
|
|
SCH_SHEET_LIST sheets = m_frame->Schematic().GetSheets();
|
|
|
|
SCH_REFERENCE_LIST refs;
|
|
|
|
SCH_SYMBOL* refSymbol = nullptr;
|
|
|
|
|
|
|
|
sheets.GetSymbols( refs );
|
|
|
|
|
|
|
|
for( int jj = 0; jj < (int) refs.GetCount(); jj++ )
|
|
|
|
{
|
|
|
|
SCH_REFERENCE& ref = refs[jj];
|
|
|
|
|
|
|
|
if( ref.GetSymbol()->GetRef( &ref.GetSheetPath(), true ) == aCrossRef )
|
|
|
|
{
|
|
|
|
refSymbol = ref.GetSymbol();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( refSymbol )
|
|
|
|
refSymbol->GetContextualTextVars( aTokens );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCHEMATIC* schematic = m_currentItem->Schematic();
|
|
|
|
|
|
|
|
if( schematic && schematic->CurrentSheet().Last() )
|
2023-07-10 11:33:38 +00:00
|
|
|
{
|
2023-05-24 22:46:48 +00:00
|
|
|
schematic->CurrentSheet().Last()->GetContextualTextVars( aTokens );
|
2023-07-10 11:33:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( std::pair<wxString, wxString> entry : Prj().GetTextVars() )
|
|
|
|
aTokens->push_back( entry.first );
|
|
|
|
}
|
2023-05-24 22:46:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
bool DIALOG_TEXT_PROPERTIES::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataToWindow() )
|
|
|
|
return false;
|
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
SCHEMATIC& schematic = m_frame->Schematic();
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2022-05-23 09:09:48 +00:00
|
|
|
m_hyperlinkCb->SetValue( m_currentText->HasHyperlink() );
|
2022-08-28 11:04:23 +00:00
|
|
|
m_hyperlinkCombo->SetValue( m_currentText->GetHyperlink() );
|
2022-05-14 13:52:53 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
// show text variable cross-references in a human-readable format
|
|
|
|
m_textCtrl->SetValue( schematic.ConvertKIIDsToRefs( m_currentText->GetText() ) );
|
2022-10-14 21:00:54 +00:00
|
|
|
m_textCtrl->EmptyUndoBuffer();
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2023-08-08 16:32:08 +00:00
|
|
|
m_excludeFromSim->SetValue( m_currentItem->GetExcludedFromSim() );
|
2023-04-09 11:14:21 +00:00
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
m_fontCtrl->SetFontSelection( m_currentText->GetFont() );
|
2021-10-12 20:05:37 +00:00
|
|
|
m_textSize.SetValue( m_currentText->GetTextWidth() );
|
2022-03-31 18:43:08 +00:00
|
|
|
m_textColorSwatch->SetSwatchColor( m_currentText->GetTextColor(), false );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
m_bold->Check( m_currentText->IsBold() );
|
|
|
|
m_italic->Check( m_currentText->IsItalic() );
|
|
|
|
|
2023-09-07 16:09:53 +00:00
|
|
|
switch( m_currentText->GetHorizJustify() )
|
|
|
|
{
|
2024-02-03 13:43:41 +00:00
|
|
|
case GR_TEXT_H_ALIGN_LEFT: m_hAlignLeft->Check(); break;
|
|
|
|
case GR_TEXT_H_ALIGN_CENTER: m_hAlignCenter->Check(); break;
|
|
|
|
case GR_TEXT_H_ALIGN_RIGHT: m_hAlignRight->Check(); break;
|
|
|
|
case GR_TEXT_H_ALIGN_INDETERMINATE: break;
|
2023-09-07 16:09:53 +00:00
|
|
|
}
|
|
|
|
|
2023-10-30 12:33:15 +00:00
|
|
|
switch( m_currentText->GetVertJustify() )
|
|
|
|
{
|
2024-02-03 13:43:41 +00:00
|
|
|
case GR_TEXT_V_ALIGN_TOP: m_vAlignTop->Check(); break;
|
|
|
|
case GR_TEXT_V_ALIGN_CENTER: m_vAlignCenter->Check(); break;
|
|
|
|
case GR_TEXT_V_ALIGN_BOTTOM: m_vAlignBottom->Check(); break;
|
|
|
|
case GR_TEXT_V_ALIGN_INDETERMINATE: break;
|
2023-10-30 12:33:15 +00:00
|
|
|
}
|
|
|
|
|
2023-09-07 16:09:53 +00:00
|
|
|
if( m_currentText->GetTextAngle() == ANGLE_VERTICAL )
|
|
|
|
m_vertical->Check();
|
|
|
|
else
|
|
|
|
m_horizontal->Check();
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
if( m_currentItem->Type() == SCH_TEXTBOX_T )
|
|
|
|
{
|
|
|
|
SCH_TEXTBOX* textBox = static_cast<SCH_TEXTBOX*>( m_currentItem );
|
|
|
|
|
2022-01-31 19:11:21 +00:00
|
|
|
m_borderCheckbox->SetValue( textBox->GetWidth() >= 0 );
|
2022-02-01 15:30:15 +00:00
|
|
|
|
|
|
|
if( textBox->GetWidth() >= 0 )
|
|
|
|
m_borderWidth.SetValue( textBox->GetWidth() );
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
m_borderColorSwatch->SetSwatchColor( textBox->GetStroke().GetColor(), false );
|
|
|
|
|
2023-11-25 13:05:45 +00:00
|
|
|
int style = static_cast<int>( textBox->GetStroke().GetLineStyle() );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
if( style == -1 )
|
|
|
|
m_borderStyleCombo->SetStringSelection( DEFAULT_STYLE );
|
|
|
|
else if( style < (int) lineTypeNames.size() )
|
|
|
|
m_borderStyleCombo->SetSelection( style );
|
|
|
|
else
|
|
|
|
wxFAIL_MSG( "Line type not found in the type lookup map" );
|
|
|
|
|
2022-01-31 19:11:21 +00:00
|
|
|
m_borderWidth.Enable( textBox->GetWidth() >= 0 );
|
|
|
|
m_borderColorLabel->Enable( textBox->GetWidth() >= 0 );
|
|
|
|
m_borderColorSwatch->Enable( textBox->GetWidth() >= 0 );
|
|
|
|
m_borderStyleLabel->Enable( textBox->GetWidth() >= 0 );
|
|
|
|
m_borderStyleCombo->Enable( textBox->GetWidth() >= 0 );
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
m_filledCtrl->SetValue( textBox->IsFilled() );
|
|
|
|
m_fillColorSwatch->SetSwatchColor( textBox->GetFillColor(), false );
|
|
|
|
|
2022-01-31 19:11:21 +00:00
|
|
|
m_fillColorLabel->Enable( textBox->IsFilled() );
|
|
|
|
m_fillColorSwatch->Enable( textBox->IsFilled() );
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-27 18:14:57 +00:00
|
|
|
void DIALOG_TEXT_PROPERTIES::onBorderChecked( wxCommandEvent& aEvent )
|
2022-01-31 19:11:21 +00:00
|
|
|
{
|
|
|
|
bool border = m_borderCheckbox->GetValue();
|
|
|
|
|
|
|
|
if( border && m_borderWidth.GetValue() < 0 )
|
|
|
|
m_borderWidth.SetValue( m_frame->eeconfig()->m_Drawing.default_line_thickness );
|
|
|
|
|
|
|
|
m_borderWidth.Enable( border );
|
|
|
|
m_borderColorLabel->Enable( border );
|
|
|
|
m_borderColorSwatch->Enable( border );
|
|
|
|
m_borderStyleLabel->Enable( border );
|
|
|
|
m_borderStyleCombo->Enable( border );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-27 18:14:57 +00:00
|
|
|
void DIALOG_TEXT_PROPERTIES::onFillChecked( wxCommandEvent& aEvent )
|
2022-01-31 19:11:21 +00:00
|
|
|
{
|
|
|
|
bool fill = m_filledCtrl->GetValue();
|
|
|
|
|
|
|
|
m_fillColorLabel->Enable( fill );
|
|
|
|
m_fillColorSwatch->Enable( fill );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-14 13:52:53 +00:00
|
|
|
void DIALOG_TEXT_PROPERTIES::onHyperlinkChecked( wxCommandEvent& aEvent )
|
|
|
|
{
|
2022-08-28 11:04:23 +00:00
|
|
|
if( aEvent.IsChecked() && m_hyperlinkCombo->GetValue().IsEmpty() )
|
2022-05-14 13:52:53 +00:00
|
|
|
{
|
2022-08-28 11:04:23 +00:00
|
|
|
m_hyperlinkCombo->ChangeValue( m_lastLink );
|
2022-05-14 13:52:53 +00:00
|
|
|
}
|
2022-08-28 11:04:23 +00:00
|
|
|
else if( !aEvent.IsChecked() && !m_hyperlinkCombo->GetValue().IsEmpty() )
|
2022-05-14 13:52:53 +00:00
|
|
|
{
|
2022-08-28 11:04:23 +00:00
|
|
|
m_lastLink = m_hyperlinkCombo->GetValue();
|
|
|
|
m_hyperlinkCombo->SetValue( wxEmptyString );
|
2022-05-14 13:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-28 11:04:23 +00:00
|
|
|
void DIALOG_TEXT_PROPERTIES::onHyperlinkText( wxCommandEvent& event )
|
2022-08-27 18:14:57 +00:00
|
|
|
{
|
2022-08-28 11:04:23 +00:00
|
|
|
if( !m_hyperlinkCombo->GetValue().IsEmpty() )
|
|
|
|
m_hyperlinkCb->SetValue( true );
|
2022-08-27 18:14:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_TEXT_PROPERTIES::onHyperlinkCombo( wxCommandEvent& aEvent )
|
|
|
|
{
|
2022-08-28 22:25:01 +00:00
|
|
|
if( aEvent.GetSelection() >= 0 )
|
2022-08-27 21:56:29 +00:00
|
|
|
{
|
2022-08-28 22:25:01 +00:00
|
|
|
m_hyperlinkCb->SetValue( true );
|
2022-08-28 11:04:23 +00:00
|
|
|
m_hyperlinkCombo->SetInsertionPointEnd();
|
2022-08-27 18:14:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-02 18:15:40 +00:00
|
|
|
void DIALOG_TEXT_PROPERTIES::onHAlignButton( wxCommandEvent& aEvent )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
2022-09-02 18:15:40 +00:00
|
|
|
for( BITMAP_BUTTON* btn : { m_hAlignLeft, m_hAlignCenter, m_hAlignRight } )
|
|
|
|
{
|
|
|
|
if( btn->IsChecked() && btn != aEvent.GetEventObject() )
|
|
|
|
btn->Check( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_TEXT_PROPERTIES::onVAlignButton( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
for( BITMAP_BUTTON* btn : { m_vAlignTop, m_vAlignCenter, m_vAlignBottom } )
|
|
|
|
{
|
|
|
|
if( btn->IsChecked() && btn != aEvent.GetEventObject() )
|
|
|
|
btn->Check( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_TEXT_PROPERTIES::onTextAngleButton( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
for( BITMAP_BUTTON* btn : { m_horizontal, m_vertical } )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
if( btn->IsChecked() && btn != aEvent.GetEventObject() )
|
|
|
|
btn->Check( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_TEXT_PROPERTIES::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Don't allow text to disappear; it can be difficult to correct if you can't select it
|
|
|
|
if( !m_textSize.Validate( 0.01, 1000.0, EDA_UNITS::MILLIMETRES ) )
|
|
|
|
return false;
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( m_frame );
|
|
|
|
wxString text;
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
/* save old text in undo list if not already in edit */
|
2022-01-25 22:33:37 +00:00
|
|
|
if( m_currentItem->GetEditFlags() == 0 )
|
2023-06-07 22:45:06 +00:00
|
|
|
commit.Modify( m_currentItem, m_frame->GetScreen() );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
// convert any text variable cross-references to their UUIDs
|
2022-01-03 01:20:25 +00:00
|
|
|
text = m_frame->Schematic().ConvertRefsToKIIDs( m_textCtrl->GetValue() );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
2022-04-05 15:25:03 +00:00
|
|
|
// On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting
|
|
|
|
text.Replace( "\r", "\n" );
|
|
|
|
#elif defined( __WINDOWS__ )
|
|
|
|
// 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.
|
|
|
|
text.Replace( "\r", "" );
|
2021-10-12 20:05:37 +00:00
|
|
|
#endif
|
|
|
|
|
2022-04-05 15:25:03 +00:00
|
|
|
if( m_currentItem->Type() == SCH_TEXTBOX_T )
|
|
|
|
{
|
|
|
|
// Textboxes have a defined extent and so are allowed to be empty
|
2022-04-05 19:10:25 +00:00
|
|
|
m_currentText->SetText( text );
|
2022-04-05 15:25:03 +00:00
|
|
|
}
|
|
|
|
else if( !text.IsEmpty() )
|
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
m_currentText->SetText( text );
|
|
|
|
}
|
2022-04-05 15:25:03 +00:00
|
|
|
else
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
2022-04-05 15:25:03 +00:00
|
|
|
// Other text items do not have defined extents, and so will disappear if empty
|
2021-10-12 20:05:37 +00:00
|
|
|
DisplayError( this, _( "Text can not be empty." ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-08 16:32:08 +00:00
|
|
|
m_currentItem->SetExcludedFromSim( m_excludeFromSim->GetValue() );
|
2023-04-09 11:14:21 +00:00
|
|
|
|
2022-08-28 11:04:23 +00:00
|
|
|
if( !m_currentText->ValidateHyperlink( m_hyperlinkCombo->GetValue() ) )
|
2022-05-14 13:52:53 +00:00
|
|
|
{
|
2022-07-23 02:34:52 +00:00
|
|
|
DisplayError( this, _( "Invalid hyperlink destination. Please enter either a valid URL "
|
2022-08-27 18:14:57 +00:00
|
|
|
"(e.g. file:// or http(s)://) or \"#<page number>\" to create "
|
2022-07-23 02:34:52 +00:00
|
|
|
"a hyperlink to a page in this schematic." ) );
|
2022-05-14 13:52:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-28 11:04:23 +00:00
|
|
|
m_currentText->SetHyperlink( m_hyperlinkCombo->GetValue() );
|
2022-05-14 13:52:53 +00:00
|
|
|
}
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
if( m_currentText->GetTextWidth() != m_textSize.GetValue() )
|
2023-02-19 03:40:07 +00:00
|
|
|
m_currentText->SetTextSize( VECTOR2I( m_textSize.GetValue(), m_textSize.GetValue() ) );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
if( m_fontCtrl->HaveFontSelection() )
|
|
|
|
{
|
|
|
|
m_currentText->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(),
|
|
|
|
m_italic->IsChecked() ) );
|
|
|
|
}
|
|
|
|
|
2024-02-25 17:28:05 +00:00
|
|
|
// Must come after SetTextSize()
|
|
|
|
m_currentText->SetBold( m_bold->IsChecked() );
|
2021-10-12 20:05:37 +00:00
|
|
|
m_currentText->SetItalic( m_italic->IsChecked() );
|
2024-02-25 17:28:05 +00:00
|
|
|
|
2022-03-31 18:43:08 +00:00
|
|
|
m_currentText->SetTextColor( m_textColorSwatch->GetSwatchColor() );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2023-09-07 16:09:53 +00:00
|
|
|
if( m_hAlignRight->IsChecked() )
|
|
|
|
m_currentText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
else if( m_hAlignCenter->IsChecked() )
|
|
|
|
m_currentText->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
else
|
|
|
|
m_currentText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2023-10-30 12:33:15 +00:00
|
|
|
if( m_vAlignBottom->IsChecked() )
|
|
|
|
m_currentText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
|
|
|
else if( m_vAlignCenter->IsChecked() )
|
|
|
|
m_currentText->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
|
|
|
else
|
|
|
|
m_currentText->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
|
|
|
|
2023-09-07 16:09:53 +00:00
|
|
|
if( m_vertical->IsChecked() )
|
|
|
|
m_currentText->SetTextAngle( ANGLE_VERTICAL );
|
2022-09-02 18:15:40 +00:00
|
|
|
else
|
2023-09-07 16:09:53 +00:00
|
|
|
m_currentText->SetTextAngle( ANGLE_HORIZONTAL );
|
|
|
|
|
|
|
|
if( m_currentItem->Type() == SCH_TEXTBOX_T )
|
2022-09-02 18:15:40 +00:00
|
|
|
{
|
|
|
|
SCH_TEXTBOX* textBox = static_cast<SCH_TEXTBOX*>( m_currentItem );
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
STROKE_PARAMS stroke = textBox->GetStroke();
|
|
|
|
|
2022-01-31 19:11:21 +00:00
|
|
|
if( m_borderCheckbox->GetValue() )
|
2023-06-07 22:45:06 +00:00
|
|
|
stroke.SetWidth( std::max( 0, m_borderWidth.GetIntValue() ) );
|
2022-01-31 19:11:21 +00:00
|
|
|
else
|
|
|
|
stroke.SetWidth( -1 );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
auto it = lineTypeNames.begin();
|
|
|
|
std::advance( it, m_borderStyleCombo->GetSelection() );
|
|
|
|
|
|
|
|
if( it == lineTypeNames.end() )
|
2023-11-25 13:05:45 +00:00
|
|
|
stroke.SetLineStyle( LINE_STYLE::DEFAULT );
|
2022-01-25 22:33:37 +00:00
|
|
|
else
|
2023-11-25 13:05:45 +00:00
|
|
|
stroke.SetLineStyle( it->first );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
stroke.SetColor( m_borderColorSwatch->GetSwatchColor() );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
textBox->SetStroke( stroke );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2022-03-31 18:43:08 +00:00
|
|
|
textBox->SetFillMode( m_filledCtrl->GetValue() ? FILL_T::FILLED_WITH_COLOR
|
|
|
|
: FILL_T::NO_FILL );
|
2022-01-25 22:33:37 +00:00
|
|
|
textBox->SetFillColor( m_fillColorSwatch->GetSwatchColor() );
|
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2023-06-07 22:45:06 +00:00
|
|
|
if( !commit.Empty() )
|
2024-02-03 13:43:41 +00:00
|
|
|
commit.Push( _( "Edit Text Properties" ), SKIP_CONNECTIVITY );
|
2023-06-07 22:45:06 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_TEXT_PROPERTIES::OnFormattingHelp( wxHyperlinkEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_helpWindow = SCH_TEXT::ShowSyntaxHelp( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_TEXT_PROPERTIES::onMultiLineTCLostFocus( wxFocusEvent& event )
|
|
|
|
{
|
|
|
|
if( m_scintillaTricks )
|
|
|
|
m_scintillaTricks->CancelAutocomplete();
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|