2012-02-22 14:04:48 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.com
|
2016-04-02 12:25:44 +00:00
|
|
|
* Copyright (C) 2016 Wayne Stambaugh, stambaughw@gmail.com
|
2022-01-13 12:29:46 +00:00
|
|
|
* Copyright (C) 2004-2022 KiCad Developers, see AITHORS.txt for contributors.
|
2012-02-22 14:04:48 +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-10-12 20:05:37 +00:00
|
|
|
#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>
|
|
|
|
#include <settings/color_settings.h>
|
2021-03-07 20:31:19 +00:00
|
|
|
#include <bitmaps.h>
|
2014-10-14 20:39:25 +00:00
|
|
|
#include <kiway.h>
|
2016-04-02 12:25:44 +00:00
|
|
|
#include <confirm.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2012-02-22 14:04:48 +00:00
|
|
|
#include <sch_base_frame.h>
|
2020-03-30 13:14:44 +00:00
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <ee_collectors.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2012-02-22 14:04:48 +00:00
|
|
|
#include <lib_field.h>
|
|
|
|
#include <template_fieldnames.h>
|
2021-06-15 13:24:55 +00:00
|
|
|
#include <symbol_library.h>
|
2018-09-27 16:21:06 +00:00
|
|
|
#include <sch_validators.h>
|
2020-05-27 22:28:36 +00:00
|
|
|
#include <schematic.h>
|
2021-08-06 19:54:26 +00:00
|
|
|
#include <dialog_field_properties.h>
|
2019-06-30 22:06:34 +00:00
|
|
|
#include <sch_text.h>
|
2020-05-27 22:28:36 +00:00
|
|
|
#include <scintilla_tricks.h>
|
2021-07-01 13:12:18 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
DIALOG_FIELD_PROPERTIES::DIALOG_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent, const wxString& aTitle,
|
|
|
|
const EDA_TEXT* aTextItem ) :
|
2022-05-13 09:39:16 +00:00
|
|
|
DIALOG_FIELD_PROPERTIES_BASE( aParent, wxID_ANY, aTitle ),
|
2018-07-06 17:03:57 +00:00
|
|
|
m_posX( aParent, m_xPosLabel, m_xPosCtrl, m_xPosUnits, true ),
|
|
|
|
m_posY( aParent, m_yPosLabel, m_yPosCtrl, m_yPosUnits, true ),
|
2020-05-27 22:28:36 +00:00
|
|
|
m_textSize( aParent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true ),
|
2022-01-13 15:25:02 +00:00
|
|
|
m_font( nullptr ),
|
2021-01-09 19:26:07 +00:00
|
|
|
m_firstFocus( true ),
|
2020-05-27 22:28:36 +00:00
|
|
|
m_scintillaTricks( nullptr )
|
2016-04-02 12:25:44 +00:00
|
|
|
{
|
2022-03-31 18:43:08 +00:00
|
|
|
COLOR_SETTINGS* colorSettings = aParent->GetColorSettings();
|
|
|
|
COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
|
|
|
|
|
2020-01-12 19:45:37 +00:00
|
|
|
wxASSERT( aTextItem );
|
|
|
|
|
2021-09-27 12:24:53 +00:00
|
|
|
m_note->SetFont( KIUI::GetInfoFont( this ).Italic() );
|
|
|
|
m_note->Show( false );
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
// The field ID and power status are Initialized in the derived object's ctor.
|
2020-11-12 21:31:41 +00:00
|
|
|
m_fieldId = VALUE_FIELD;
|
2016-04-02 12:25:44 +00:00
|
|
|
m_isPower = false;
|
|
|
|
|
2021-06-28 10:19:12 +00:00
|
|
|
m_scintillaTricks = new SCINTILLA_TRICKS( m_StyledTextCtrl, wxT( "{}" ), true,
|
|
|
|
[this]()
|
|
|
|
{
|
|
|
|
wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
|
|
|
|
} );
|
2021-03-28 16:20:47 +00:00
|
|
|
m_StyledTextCtrl->SetEOLMode( wxSTC_EOL_LF ); // Normalize EOL across platforms
|
2020-05-27 22:28:36 +00:00
|
|
|
|
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
|
|
|
m_separator1->SetIsSeparator();
|
|
|
|
|
2022-06-12 19:09:21 +00:00
|
|
|
m_horizontal->SetIsRadioButton();
|
2021-10-12 20:05:37 +00:00
|
|
|
m_horizontal->SetBitmap( KiBitmap( BITMAPS::text_horizontal ) );
|
2022-06-12 19:09:21 +00:00
|
|
|
m_vertical->SetIsRadioButton();
|
2021-10-12 20:05:37 +00:00
|
|
|
m_vertical->SetBitmap( KiBitmap( BITMAPS::text_vertical ) );
|
|
|
|
|
|
|
|
m_separator2->SetIsSeparator();
|
|
|
|
|
|
|
|
m_bold->SetIsCheckButton();
|
|
|
|
m_bold->SetBitmap( KiBitmap( BITMAPS::text_bold ) );
|
|
|
|
m_italic->SetIsCheckButton();
|
|
|
|
m_italic->SetBitmap( KiBitmap( BITMAPS::text_italic ) );
|
|
|
|
|
|
|
|
m_separator3->SetIsSeparator();
|
|
|
|
|
2022-06-12 19:09:21 +00:00
|
|
|
m_hAlignLeft->SetIsRadioButton();
|
2021-10-12 20:05:37 +00:00
|
|
|
m_hAlignLeft->SetBitmap( KiBitmap( BITMAPS::text_align_left ) );
|
2022-06-12 19:09:21 +00:00
|
|
|
m_hAlignCenter->SetIsRadioButton();
|
2021-10-12 20:05:37 +00:00
|
|
|
m_hAlignCenter->SetBitmap( KiBitmap( BITMAPS::text_align_center ) );
|
2022-06-12 19:09:21 +00:00
|
|
|
m_hAlignRight->SetIsRadioButton();
|
2021-10-12 20:05:37 +00:00
|
|
|
m_hAlignRight->SetBitmap( KiBitmap( BITMAPS::text_align_right ) );
|
|
|
|
|
|
|
|
m_separator4->SetIsSeparator();
|
|
|
|
|
2022-06-12 19:09:21 +00:00
|
|
|
m_vAlignTop->SetIsRadioButton();
|
2021-10-12 20:05:37 +00:00
|
|
|
m_vAlignTop->SetBitmap( KiBitmap( BITMAPS::text_valign_top ) );
|
2022-06-12 19:09:21 +00:00
|
|
|
m_vAlignCenter->SetIsRadioButton();
|
2021-10-12 20:05:37 +00:00
|
|
|
m_vAlignCenter->SetBitmap( KiBitmap( BITMAPS::text_valign_center ) );
|
2022-06-12 19:09:21 +00:00
|
|
|
m_vAlignBottom->SetIsRadioButton();
|
2021-10-12 20:05:37 +00:00
|
|
|
m_vAlignBottom->SetBitmap( KiBitmap( BITMAPS::text_valign_bottom ) );
|
|
|
|
|
|
|
|
m_separator5->SetIsSeparator();
|
|
|
|
|
|
|
|
m_horizontal->Bind( wxEVT_BUTTON, &DIALOG_FIELD_PROPERTIES::onOrientButton, this );
|
|
|
|
m_vertical->Bind( wxEVT_BUTTON, &DIALOG_FIELD_PROPERTIES::onOrientButton, this );
|
|
|
|
|
|
|
|
m_hAlignLeft->Bind( wxEVT_BUTTON, &DIALOG_FIELD_PROPERTIES::onHAlignButton, this );
|
|
|
|
m_hAlignCenter->Bind( wxEVT_BUTTON, &DIALOG_FIELD_PROPERTIES::onHAlignButton, this );
|
|
|
|
m_hAlignRight->Bind( wxEVT_BUTTON, &DIALOG_FIELD_PROPERTIES::onHAlignButton, this );
|
|
|
|
|
|
|
|
m_vAlignTop->Bind( wxEVT_BUTTON, &DIALOG_FIELD_PROPERTIES::onVAlignButton, this );
|
|
|
|
m_vAlignCenter->Bind( wxEVT_BUTTON, &DIALOG_FIELD_PROPERTIES::onVAlignButton, this );
|
|
|
|
m_vAlignBottom->Bind( wxEVT_BUTTON, &DIALOG_FIELD_PROPERTIES::onVAlignButton, this );
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
m_text = aTextItem->GetText();
|
2018-07-06 17:03:57 +00:00
|
|
|
m_isItalic = aTextItem->IsItalic();
|
|
|
|
m_isBold = aTextItem->IsBold();
|
2022-03-31 18:43:08 +00:00
|
|
|
m_color = aTextItem->GetTextColor();
|
2018-07-06 17:03:57 +00:00
|
|
|
m_position = aTextItem->GetTextPos();
|
2017-01-23 20:30:11 +00:00
|
|
|
m_size = aTextItem->GetTextWidth();
|
2021-12-28 22:13:54 +00:00
|
|
|
m_isVertical = aTextItem->GetTextAngle().IsVertical();
|
2022-01-05 16:25:18 +00:00
|
|
|
m_verticalJustification = aTextItem->GetVertJustify();
|
|
|
|
m_horizontalJustification = aTextItem->GetHorizJustify();
|
2016-04-02 12:25:44 +00:00
|
|
|
m_isVisible = aTextItem->IsVisible();
|
2022-09-24 22:37:44 +00:00
|
|
|
|
|
|
|
// These should be initialized in the child classes implementing dialogs for lib and sch items.
|
|
|
|
m_isNameVisible = false;
|
|
|
|
m_allowAutoplace = true;
|
2016-04-02 12:25:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
DIALOG_FIELD_PROPERTIES::~DIALOG_FIELD_PROPERTIES()
|
2020-05-27 22:28:36 +00:00
|
|
|
{
|
|
|
|
delete m_scintillaTricks;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
void DIALOG_FIELD_PROPERTIES::init()
|
2016-04-02 12:25:44 +00:00
|
|
|
{
|
2018-09-27 16:21:06 +00:00
|
|
|
SCH_BASE_FRAME* parent = GetParent();
|
2021-05-26 11:38:23 +00:00
|
|
|
bool isSymbolEditor = parent && parent->IsType( FRAME_SCH_SYMBOL_EDITOR );
|
2016-04-02 12:25:44 +00:00
|
|
|
|
|
|
|
// Disable options for graphic text editing which are not needed for fields.
|
|
|
|
m_CommonConvert->Show( false );
|
|
|
|
m_CommonUnit->Show( false );
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2021-01-03 16:10:16 +00:00
|
|
|
// Predefined fields cannot contain some chars, or cannot be empty,
|
|
|
|
// and need a SCH_FIELD_VALIDATOR (m_StyledTextCtrl cannot use a SCH_FIELD_VALIDATOR).
|
|
|
|
bool use_validator = m_fieldId == REFERENCE_FIELD
|
|
|
|
|| m_fieldId == VALUE_FIELD
|
|
|
|
|| m_fieldId == FOOTPRINT_FIELD
|
2021-03-20 00:01:37 +00:00
|
|
|
|| m_fieldId == DATASHEET_FIELD
|
|
|
|
|| m_fieldId == SHEETNAME_V
|
|
|
|
|| m_fieldId == SHEETFILENAME_V;
|
|
|
|
|
2021-01-03 16:10:16 +00:00
|
|
|
if( use_validator )
|
2020-05-27 22:28:36 +00:00
|
|
|
{
|
2021-05-26 11:38:23 +00:00
|
|
|
m_TextCtrl->SetValidator( SCH_FIELD_VALIDATOR( isSymbolEditor, m_fieldId, &m_text ) );
|
2020-05-27 22:28:36 +00:00
|
|
|
SetInitialFocus( m_TextCtrl );
|
2021-05-26 11:38:23 +00:00
|
|
|
|
|
|
|
m_StyledTextCtrl->Show( false );
|
2020-05-27 22:28:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetInitialFocus( m_StyledTextCtrl );
|
2021-05-26 11:38:23 +00:00
|
|
|
|
|
|
|
m_TextCtrl->Show( false );
|
2020-05-27 22:28:36 +00:00
|
|
|
}
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
// Show the footprint selection dialog if this is the footprint field.
|
2021-03-08 02:59:07 +00:00
|
|
|
m_TextValueSelectButton->SetBitmap( KiBitmap( BITMAPS::small_library ) );
|
2020-11-12 21:31:41 +00:00
|
|
|
m_TextValueSelectButton->Show( m_fieldId == FOOTPRINT_FIELD );
|
2015-03-23 11:45:31 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
// Value fields of power symbols cannot be modified. This will grey out
|
2016-04-02 12:25:44 +00:00
|
|
|
// the text box and display an explanation.
|
2020-11-12 21:31:41 +00:00
|
|
|
if( m_fieldId == VALUE_FIELD && m_isPower )
|
2016-04-02 12:25:44 +00:00
|
|
|
{
|
2021-09-27 12:24:53 +00:00
|
|
|
m_note->SetLabel( wxString::Format( m_note->GetLabel(),
|
|
|
|
_( "Power symbol value field text cannot be changed." ) ) );
|
|
|
|
m_note->Show( true );
|
2020-05-27 22:28:36 +00:00
|
|
|
m_TextCtrl->Enable( false );
|
2016-04-02 12:25:44 +00:00
|
|
|
}
|
2016-04-04 14:31:34 +00:00
|
|
|
else
|
|
|
|
{
|
2020-05-27 22:28:36 +00:00
|
|
|
m_TextCtrl->Enable( true );
|
2016-04-04 14:31:34 +00:00
|
|
|
}
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2020-05-27 22:28:36 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
|
|
|
|
// Adjust the height of the scintilla text editor after the first layout
|
2021-03-28 16:20:47 +00:00
|
|
|
// To show only one line
|
|
|
|
// (multiline text are is supported in fields and will be removed)
|
2020-05-27 22:28:36 +00:00
|
|
|
if( m_StyledTextCtrl->IsShown() )
|
|
|
|
{
|
|
|
|
wxSize maxSize = m_StyledTextCtrl->GetSize();
|
2021-07-27 12:12:46 +00:00
|
|
|
maxSize.x = -1; // Do not fix the max width
|
2020-05-27 22:28:36 +00:00
|
|
|
maxSize.y = m_xPosCtrl->GetSize().y;
|
|
|
|
m_StyledTextCtrl->SetMaxSize( maxSize );
|
|
|
|
m_StyledTextCtrl->SetUseVerticalScrollBar( false );
|
|
|
|
m_StyledTextCtrl->SetUseHorizontalScrollBar( false );
|
|
|
|
}
|
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
|
|
|
|
2016-07-16 10:54:55 +00:00
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2015-03-23 11:45:31 +00:00
|
|
|
}
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
void DIALOG_FIELD_PROPERTIES::OnTextValueSelectButtonClick( wxCommandEvent& aEvent )
|
2014-10-14 20:39:25 +00:00
|
|
|
{
|
|
|
|
// pick a footprint using the footprint picker.
|
2020-06-08 19:41:09 +00:00
|
|
|
wxString fpid;
|
|
|
|
|
|
|
|
if( m_StyledTextCtrl->IsShown() )
|
|
|
|
fpid = m_StyledTextCtrl->GetValue();
|
|
|
|
else
|
|
|
|
fpid = m_TextCtrl->GetValue();
|
2014-10-14 20:39:25 +00:00
|
|
|
|
2019-09-05 22:00:47 +00:00
|
|
|
KIWAY_PLAYER* frame = Kiway().Player( FRAME_FOOTPRINT_VIEWER_MODAL, true );
|
2014-10-14 20:39:25 +00:00
|
|
|
|
|
|
|
if( frame->ShowModal( &fpid, this ) )
|
|
|
|
{
|
2020-06-04 16:47:12 +00:00
|
|
|
if( m_StyledTextCtrl->IsShown() )
|
|
|
|
m_StyledTextCtrl->SetValue( fpid );
|
|
|
|
else
|
|
|
|
m_TextCtrl->SetValue( fpid );
|
2014-10-14 20:39:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
frame->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
void DIALOG_FIELD_PROPERTIES::OnSetFocusText( wxFocusEvent& event )
|
2012-02-22 14:04:48 +00:00
|
|
|
{
|
2021-01-09 19:26:07 +00:00
|
|
|
if( m_firstFocus )
|
|
|
|
{
|
2019-07-28 17:28:01 +00:00
|
|
|
#ifdef __WXGTK__
|
2021-01-09 19:26:07 +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
|
|
|
|
if( m_fieldId == REFERENCE_FIELD || m_fieldId == VALUE_FIELD || m_fieldId == SHEETNAME_V )
|
|
|
|
m_TextCtrl->Update();
|
2019-07-28 17:28:01 +00:00
|
|
|
#endif
|
2019-07-01 21:22:28 +00:00
|
|
|
|
2021-01-09 19:26:07 +00:00
|
|
|
if( m_fieldId == REFERENCE_FIELD )
|
|
|
|
KIUI::SelectReferenceNumber( static_cast<wxTextEntry*>( m_TextCtrl ) );
|
|
|
|
else if( m_fieldId == VALUE_FIELD || m_fieldId == SHEETNAME_V )
|
|
|
|
m_TextCtrl->SetSelection( -1, -1 );
|
|
|
|
|
|
|
|
m_firstFocus = false;
|
|
|
|
}
|
2018-07-26 14:41:08 +00:00
|
|
|
|
|
|
|
event.Skip();
|
2018-07-19 19:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
void DIALOG_FIELD_PROPERTIES::onOrientButton( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
for( BITMAP_BUTTON* btn : { m_horizontal, m_vertical } )
|
|
|
|
{
|
|
|
|
if( btn->IsChecked() && btn != aEvent.GetEventObject() )
|
|
|
|
btn->Check( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_FIELD_PROPERTIES::onHAlignButton( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
for( BITMAP_BUTTON* btn : { m_hAlignLeft, m_hAlignCenter, m_hAlignRight } )
|
|
|
|
{
|
|
|
|
if( btn->IsChecked() && btn != aEvent.GetEventObject() )
|
|
|
|
btn->Check( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_FIELD_PROPERTIES::onVAlignButton( wxCommandEvent& aEvent )
|
|
|
|
{
|
2022-01-05 16:25:18 +00:00
|
|
|
for( BITMAP_BUTTON* btn : { m_vAlignTop, m_vAlignCenter, m_vAlignBottom } )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
if( btn->IsChecked() && btn != aEvent.GetEventObject() )
|
|
|
|
btn->Check( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
bool DIALOG_FIELD_PROPERTIES::TransferDataToWindow()
|
2018-07-19 19:20:53 +00:00
|
|
|
{
|
2020-05-27 22:28:36 +00:00
|
|
|
if( m_TextCtrl->IsShown() )
|
2022-10-14 21:00:54 +00:00
|
|
|
{
|
2020-05-27 22:28:36 +00:00
|
|
|
m_TextCtrl->SetValue( m_text );
|
2022-10-14 21:00:54 +00:00
|
|
|
}
|
2020-05-27 22:28:36 +00:00
|
|
|
else if( m_StyledTextCtrl->IsShown() )
|
2022-10-14 21:00:54 +00:00
|
|
|
{
|
2020-05-27 22:28:36 +00:00
|
|
|
m_StyledTextCtrl->SetValue( m_text );
|
2022-10-14 21:00:54 +00:00
|
|
|
m_StyledTextCtrl->EmptyUndoBuffer();
|
|
|
|
}
|
2017-01-31 18:37:00 +00:00
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
m_fontCtrl->SetFontSelection( m_font );
|
|
|
|
|
2018-07-06 17:03:57 +00:00
|
|
|
m_posX.SetValue( m_position.x );
|
|
|
|
m_posY.SetValue( m_position.y );
|
2018-05-24 07:12:43 +00:00
|
|
|
m_textSize.SetValue( m_size );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
m_horizontal->Check( !m_isVertical );
|
|
|
|
m_vertical->Check( m_isVertical );
|
|
|
|
|
|
|
|
m_italic->Check( m_isItalic );
|
|
|
|
m_bold->Check( m_isBold );
|
|
|
|
|
2022-03-31 18:43:08 +00:00
|
|
|
m_textColorSwatch->SetSwatchColor( m_color, false );
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
switch ( m_horizontalJustification )
|
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_H_ALIGN_LEFT: m_hAlignLeft->Check( true ); break;
|
|
|
|
case GR_TEXT_H_ALIGN_CENTER: m_hAlignCenter->Check( true ); break;
|
|
|
|
case GR_TEXT_H_ALIGN_RIGHT: m_hAlignRight->Check( true ); break;
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch ( m_verticalJustification )
|
|
|
|
{
|
2021-12-28 22:13:54 +00:00
|
|
|
case GR_TEXT_V_ALIGN_TOP: m_vAlignTop->Check( true ); break;
|
|
|
|
case GR_TEXT_V_ALIGN_CENTER: m_vAlignCenter->Check( true ); break;
|
|
|
|
case GR_TEXT_V_ALIGN_BOTTOM: m_vAlignBottom->Check( true ); break;
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
|
|
|
|
2018-05-24 07:12:43 +00:00
|
|
|
m_visible->SetValue( m_isVisible );
|
2022-09-03 20:54:05 +00:00
|
|
|
m_nameVisible->SetValue( m_isNameVisible );
|
2022-09-04 16:34:16 +00:00
|
|
|
m_cbAllowAutoPlace->SetValue( m_allowAutoplace );
|
2014-10-14 20:39:25 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
return true;
|
2012-02-22 14:04:48 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:39:25 +00:00
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
bool DIALOG_FIELD_PROPERTIES::TransferDataFromWindow()
|
2012-02-22 14:04:48 +00:00
|
|
|
{
|
2020-05-27 22:28:36 +00:00
|
|
|
if( m_TextCtrl->IsShown() )
|
|
|
|
m_text = m_TextCtrl->GetValue();
|
|
|
|
else if( m_StyledTextCtrl->IsShown() )
|
|
|
|
m_text = m_StyledTextCtrl->GetValue();
|
2015-06-04 15:44:56 +00:00
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
if( m_fieldId == REFERENCE_FIELD )
|
2015-06-04 15:44:56 +00:00
|
|
|
{
|
2016-04-02 12:25:44 +00:00
|
|
|
// Test if the reference string is valid:
|
2021-06-10 14:10:55 +00:00
|
|
|
if( !SCH_SYMBOL::IsReferenceStringValid( m_text ) )
|
2015-06-04 15:44:56 +00:00
|
|
|
{
|
2020-03-17 16:08:29 +00:00
|
|
|
DisplayError( this, _( "Illegal reference designator value!" ) );
|
2016-04-02 12:25:44 +00:00
|
|
|
return false;
|
2015-06-04 15:44:56 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-12 21:31:41 +00:00
|
|
|
else if( m_fieldId == VALUE_FIELD )
|
2018-09-27 10:56:51 +00:00
|
|
|
{
|
|
|
|
if( m_text.IsEmpty() )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "Value may not be empty." ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2021-07-01 13:12:18 +00:00
|
|
|
else if( m_fieldId == SHEETFILENAME_V )
|
|
|
|
{
|
|
|
|
wxFileName fn( m_text );
|
|
|
|
|
|
|
|
// It's annoying to throw up nag dialogs when the extension isn't right. Just
|
|
|
|
// fix it.
|
|
|
|
if( fn.GetExt().CmpNoCase( KiCadSchematicFileExtension ) != 0 )
|
|
|
|
{
|
|
|
|
fn.SetExt( KiCadSchematicFileExtension );
|
|
|
|
m_text = fn.GetFullPath();
|
|
|
|
}
|
|
|
|
}
|
2015-06-04 15:44:56 +00:00
|
|
|
|
2018-07-06 17:03:57 +00:00
|
|
|
m_position = wxPoint( m_posX.GetValue(), m_posY.GetValue() );
|
2018-05-24 07:12:43 +00:00
|
|
|
m_size = m_textSize.GetValue();
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
if( m_fontCtrl->HaveFontSelection() )
|
|
|
|
m_font = m_fontCtrl->GetFontSelection( m_bold->IsChecked(), m_italic->IsChecked() );
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
m_isVertical = m_vertical->IsChecked();
|
|
|
|
|
|
|
|
m_isBold = m_bold->IsChecked();
|
|
|
|
m_isItalic = m_italic->IsChecked();
|
2022-03-31 18:43:08 +00:00
|
|
|
m_color = m_textColorSwatch->GetSwatchColor();
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
if( m_hAlignLeft->IsChecked() )
|
2021-12-28 22:13:54 +00:00
|
|
|
m_horizontalJustification = GR_TEXT_H_ALIGN_LEFT;
|
2021-10-12 20:05:37 +00:00
|
|
|
else if( m_hAlignCenter->IsChecked() )
|
2021-12-28 22:13:54 +00:00
|
|
|
m_horizontalJustification = GR_TEXT_H_ALIGN_CENTER;
|
2021-10-12 20:05:37 +00:00
|
|
|
else
|
2021-12-28 22:13:54 +00:00
|
|
|
m_horizontalJustification = GR_TEXT_H_ALIGN_RIGHT;
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
if( m_vAlignTop->IsChecked() )
|
2021-12-28 22:13:54 +00:00
|
|
|
m_verticalJustification = GR_TEXT_V_ALIGN_TOP;
|
2021-10-12 20:05:37 +00:00
|
|
|
else if( m_vAlignCenter->IsChecked() )
|
2021-12-28 22:13:54 +00:00
|
|
|
m_verticalJustification = GR_TEXT_V_ALIGN_CENTER;
|
2021-10-12 20:05:37 +00:00
|
|
|
else
|
2021-12-28 22:13:54 +00:00
|
|
|
m_verticalJustification = GR_TEXT_V_ALIGN_BOTTOM;
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2022-09-04 16:34:16 +00:00
|
|
|
m_isVisible = m_visible->GetValue();
|
|
|
|
m_isNameVisible = m_nameVisible->GetValue();
|
|
|
|
m_allowAutoplace = m_cbAllowAutoPlace->GetValue();
|
2015-06-04 15:44:56 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
return true;
|
2014-10-14 20:39:25 +00:00
|
|
|
}
|
|
|
|
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
void DIALOG_FIELD_PROPERTIES::updateText( EDA_TEXT* aText )
|
2012-02-22 14:04:48 +00:00
|
|
|
{
|
2021-09-03 18:25:23 +00:00
|
|
|
if( aText->GetTextWidth() != m_size )
|
|
|
|
aText->SetTextSize( wxSize( m_size, m_size ) );
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
aText->SetVisible( m_isVisible );
|
2022-01-13 12:29:46 +00:00
|
|
|
aText->SetTextAngle( m_isVertical ? ANGLE_VERTICAL : ANGLE_HORIZONTAL );
|
2018-07-06 17:03:57 +00:00
|
|
|
aText->SetItalic( m_isItalic );
|
|
|
|
aText->SetBold( m_isBold );
|
2022-03-31 18:43:08 +00:00
|
|
|
aText->SetTextColor( m_color );
|
2012-02-22 14:04:48 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:39:25 +00:00
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
DIALOG_LIB_FIELD_PROPERTIES::DIALOG_LIB_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent,
|
|
|
|
const wxString& aTitle,
|
|
|
|
const LIB_FIELD* aField ) :
|
|
|
|
DIALOG_FIELD_PROPERTIES( aParent, aTitle, aField )
|
2012-02-22 14:04:48 +00:00
|
|
|
{
|
2022-09-04 16:34:16 +00:00
|
|
|
m_fieldId = aField->GetId();
|
|
|
|
m_isNameVisible = aField->IsNameShown();
|
|
|
|
m_allowAutoplace = aField->CanAutoplace();
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2021-06-30 10:53:04 +00:00
|
|
|
if( m_fieldId == VALUE_FIELD )
|
|
|
|
m_text = UnescapeString( aField->GetText() );
|
|
|
|
|
2022-09-04 16:34:16 +00:00
|
|
|
m_nameVisible->Show();
|
|
|
|
m_cbAllowAutoPlace->Show();
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
// When in the library editor, power symbols can be renamed.
|
2016-04-29 16:01:09 +00:00
|
|
|
m_isPower = false;
|
2016-04-02 12:25:44 +00:00
|
|
|
init();
|
2012-02-22 14:04:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-05 16:25:18 +00:00
|
|
|
void DIALOG_LIB_FIELD_PROPERTIES::UpdateField( LIB_FIELD* aField )
|
|
|
|
{
|
|
|
|
wxString value = m_text;
|
|
|
|
|
|
|
|
if( m_fieldId == VALUE_FIELD )
|
|
|
|
value = EscapeString( value, CTX_LIBID );
|
|
|
|
|
|
|
|
aField->SetText( value );
|
|
|
|
|
|
|
|
// VALUE === symbol name, so update the parent symbol if it changes.
|
|
|
|
if( m_fieldId == VALUE_FIELD && aField->GetParent() )
|
|
|
|
aField->GetParent()->SetName( value );
|
|
|
|
|
|
|
|
updateText( aField );
|
|
|
|
|
2022-09-03 20:54:05 +00:00
|
|
|
aField->SetNameShown( m_isNameVisible );
|
2022-09-04 16:34:16 +00:00
|
|
|
aField->SetCanAutoplace( m_allowAutoplace );
|
2022-09-03 20:54:05 +00:00
|
|
|
|
2022-01-05 16:25:18 +00:00
|
|
|
aField->SetHorizJustify( EDA_TEXT::MapHorizJustify( m_horizontalJustification ) );
|
|
|
|
aField->SetVertJustify( EDA_TEXT::MapVertJustify( m_verticalJustification ) );
|
|
|
|
aField->SetTextPos( m_position );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
DIALOG_SCH_FIELD_PROPERTIES::DIALOG_SCH_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent,
|
|
|
|
const wxString& aTitle,
|
|
|
|
const SCH_FIELD* aField ) :
|
|
|
|
DIALOG_FIELD_PROPERTIES( aParent, aTitle, aField ),
|
2020-05-27 22:28:36 +00:00
|
|
|
m_field( aField )
|
2012-02-22 14:04:48 +00:00
|
|
|
{
|
2021-09-25 16:26:48 +00:00
|
|
|
m_isSheetFilename = false;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T )
|
2020-06-30 18:15:29 +00:00
|
|
|
{
|
|
|
|
m_fieldId = aField->GetId();
|
|
|
|
}
|
|
|
|
else if( aField->GetParent() && aField->GetParent()->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
switch( aField->GetId() )
|
|
|
|
{
|
2021-09-25 16:26:48 +00:00
|
|
|
case SHEETNAME:
|
|
|
|
m_fieldId = SHEETNAME_V;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHEETFILENAME:
|
|
|
|
m_isSheetFilename = true;
|
|
|
|
m_fieldId = SHEETFILENAME_V;
|
2021-09-27 12:24:53 +00:00
|
|
|
m_note->SetLabel( wxString::Format( m_note->GetLabel(),
|
|
|
|
_( "Sheet filename can only be modified in Sheet Properties dialog." ) ) );
|
|
|
|
m_note->Show( true );
|
2021-09-25 16:26:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
m_fieldId = SHEETUSERFIELD_V;
|
|
|
|
break;
|
2020-06-30 18:15:29 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-20 09:27:35 +00:00
|
|
|
else if( aField->GetParent() && aField->GetParent()->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
|
2022-08-14 11:03:18 +00:00
|
|
|
{
|
|
|
|
m_fieldId = LABELUSERFIELD_V;
|
|
|
|
}
|
2020-06-30 18:15:29 +00:00
|
|
|
|
2020-07-29 17:02:39 +00:00
|
|
|
// show text variable cross-references in a human-readable format
|
|
|
|
m_text = aField->Schematic()->ConvertKIIDsToRefs( aField->GetText() );
|
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
m_font = m_field->GetFont();
|
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
m_isPower = false;
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_textLabel->SetLabel( aField->GetName() + ":" );
|
2020-06-30 18:15:29 +00:00
|
|
|
|
2021-11-03 18:11:08 +00:00
|
|
|
m_position = m_field->GetPosition();
|
|
|
|
|
2022-09-03 20:54:05 +00:00
|
|
|
m_isNameVisible = m_field->IsNameShown();
|
2022-09-04 16:34:16 +00:00
|
|
|
m_allowAutoplace = m_field->CanAutoplace();
|
2022-09-03 20:54:05 +00:00
|
|
|
|
2022-01-05 16:25:18 +00:00
|
|
|
m_horizontalJustification = m_field->GetEffectiveHorizJustify();
|
|
|
|
m_verticalJustification = m_field->GetEffectiveVertJustify();
|
2021-11-03 18:11:08 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
// The library symbol may have been removed so using SCH_SYMBOL::GetLibSymbolRef() here
|
2018-01-09 14:20:54 +00:00
|
|
|
// could result in a segfault. If the library symbol is no longer available, the
|
|
|
|
// schematic fields can still edit so set the power symbol flag to false. This may not
|
|
|
|
// be entirely accurate if the power library is missing but it's better then a segfault.
|
2021-06-10 14:10:55 +00:00
|
|
|
if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2021-06-17 21:22:10 +00:00
|
|
|
const SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( aField->GetParent() );
|
|
|
|
const LIB_SYMBOL* libSymbol = GetParent()->GetLibSymbol( symbol->GetLibId(), true );
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( libSymbol && libSymbol->IsPower() )
|
2020-03-06 20:02:58 +00:00
|
|
|
m_isPower = true;
|
|
|
|
}
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
m_StyledTextCtrl->Bind( wxEVT_STC_CHARADDED, &DIALOG_SCH_FIELD_PROPERTIES::onScintillaCharAdded,
|
|
|
|
this );
|
2020-05-27 22:28:36 +00:00
|
|
|
|
2022-09-04 16:34:16 +00:00
|
|
|
m_nameVisible->Show();
|
|
|
|
m_cbAllowAutoPlace->Show();
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
init();
|
2021-09-25 16:26:48 +00:00
|
|
|
|
|
|
|
if( m_isSheetFilename )
|
|
|
|
{
|
|
|
|
m_StyledTextCtrl->Enable( false );
|
|
|
|
m_TextCtrl->Enable( false );
|
|
|
|
}
|
2012-02-22 14:04:48 +00:00
|
|
|
}
|
2016-04-22 13:29:47 +00:00
|
|
|
|
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
void DIALOG_SCH_FIELD_PROPERTIES::onScintillaCharAdded( wxStyledTextEvent &aEvent )
|
2020-05-27 22:28:36 +00:00
|
|
|
{
|
2021-03-28 16:20:47 +00:00
|
|
|
int key = aEvent.GetKey();
|
|
|
|
|
2020-05-28 09:38:40 +00:00
|
|
|
SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( GetParent() );
|
2020-05-27 22:28:36 +00:00
|
|
|
wxArrayString autocompleteTokens;
|
|
|
|
int pos = m_StyledTextCtrl->GetCurrentPos();
|
|
|
|
int start = m_StyledTextCtrl->WordStartPosition( pos, true );
|
|
|
|
wxString partial;
|
|
|
|
|
2021-03-28 16:20:47 +00:00
|
|
|
// Currently, '\n' is not allowed in fields. So remove it when entered
|
|
|
|
// TODO: see if we must close the dialog. However this is not obvious, as
|
|
|
|
// if a \n is typed (and removed) when a text is selected, this text is deleted
|
|
|
|
// (in fact replaced by \n, that is removed by the filter)
|
|
|
|
if( key == '\n' )
|
|
|
|
{
|
|
|
|
wxString text = m_StyledTextCtrl->GetText();
|
|
|
|
int currpos = m_StyledTextCtrl->GetCurrentPos();
|
|
|
|
text.Replace( "\n", "" );
|
|
|
|
m_StyledTextCtrl->SetText( text );
|
|
|
|
m_StyledTextCtrl->GotoPos( currpos-1 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-27 22:28:36 +00:00
|
|
|
auto textVarRef =
|
2020-06-01 16:58:07 +00:00
|
|
|
[&]( int pt )
|
2020-05-27 22:28:36 +00:00
|
|
|
{
|
2020-06-01 16:58:07 +00:00
|
|
|
return pt >= 2
|
|
|
|
&& m_StyledTextCtrl->GetCharAt( pt - 2 ) == '$'
|
|
|
|
&& m_StyledTextCtrl->GetCharAt( pt - 1 ) == '{';
|
2020-05-27 22:28:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Check for cross-reference
|
2020-06-01 16:58:07 +00:00
|
|
|
if( start > 1 && m_StyledTextCtrl->GetCharAt( start - 1 ) == ':' )
|
2020-05-27 22:28:36 +00:00
|
|
|
{
|
2020-06-01 16:58:07 +00:00
|
|
|
int refStart = m_StyledTextCtrl->WordStartPosition( start - 1, true );
|
2020-05-27 22:28:36 +00:00
|
|
|
|
|
|
|
if( textVarRef( refStart ) )
|
|
|
|
{
|
|
|
|
partial = m_StyledTextCtrl->GetRange( start, pos );
|
|
|
|
|
2020-06-01 16:58:07 +00:00
|
|
|
wxString ref = m_StyledTextCtrl->GetRange( refStart, start - 1 );
|
2020-05-27 22:28:36 +00:00
|
|
|
SCH_SHEET_LIST sheets = editFrame->Schematic().GetSheets();
|
|
|
|
SCH_REFERENCE_LIST refs;
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* refSymbol = nullptr;
|
2020-05-27 22:28:36 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
sheets.GetSymbols( refs );
|
2020-05-27 22:28:36 +00:00
|
|
|
|
|
|
|
for( size_t jj = 0; jj < refs.GetCount(); jj++ )
|
|
|
|
{
|
2020-11-15 16:08:31 +00:00
|
|
|
if( refs[ jj ].GetSymbol()->GetRef( &refs[ jj ].GetSheetPath(), true ) == ref )
|
2020-05-27 22:28:36 +00:00
|
|
|
{
|
2020-11-15 16:08:31 +00:00
|
|
|
refSymbol = refs[ jj ].GetSymbol();
|
2020-05-27 22:28:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
if( refSymbol )
|
|
|
|
refSymbol->GetContextualTextVars( &autocompleteTokens );
|
2020-05-27 22:28:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( textVarRef( start ) )
|
|
|
|
{
|
|
|
|
partial = m_StyledTextCtrl->GetTextRange( start, pos );
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( m_field->GetParent() );
|
|
|
|
SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( m_field->GetParent() );
|
2020-05-27 22:28:36 +00:00
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
if( symbol )
|
2020-07-28 12:11:11 +00:00
|
|
|
{
|
2021-01-19 23:50:18 +00:00
|
|
|
symbol->GetContextualTextVars( &autocompleteTokens );
|
2020-07-28 12:11:11 +00:00
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
SCHEMATIC* schematic = symbol->Schematic();
|
2020-07-28 12:11:11 +00:00
|
|
|
|
|
|
|
if( schematic && schematic->CurrentSheet().Last() )
|
|
|
|
schematic->CurrentSheet().Last()->GetContextualTextVars( &autocompleteTokens );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( sheet )
|
2020-05-27 22:28:36 +00:00
|
|
|
sheet->GetContextualTextVars( &autocompleteTokens );
|
|
|
|
|
|
|
|
for( std::pair<wxString, wxString> entry : Prj().GetTextVars() )
|
|
|
|
autocompleteTokens.push_back( entry.first );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_scintillaTricks->DoAutocomplete( partial, autocompleteTokens );
|
|
|
|
m_StyledTextCtrl->SetFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-06 19:54:26 +00:00
|
|
|
void DIALOG_SCH_FIELD_PROPERTIES::UpdateField( SCH_FIELD* aField, SCH_SHEET_PATH* aSheetPath )
|
2016-04-22 13:29:47 +00:00
|
|
|
{
|
2020-03-30 13:14:44 +00:00
|
|
|
SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( GetParent() );
|
|
|
|
SCH_ITEM* parent = dynamic_cast<SCH_ITEM*>( aField->GetParent() );
|
|
|
|
int fieldType = aField->GetId();
|
2020-03-06 20:02:58 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( parent && parent->Type() == SCH_SYMBOL_T )
|
2016-04-22 13:29:47 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( parent );
|
2020-09-06 12:05:07 +00:00
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
if( fieldType == REFERENCE_FIELD )
|
2021-01-19 23:50:18 +00:00
|
|
|
symbol->SetRef( aSheetPath, m_text );
|
2020-11-12 21:31:41 +00:00
|
|
|
else if( fieldType == VALUE_FIELD )
|
2022-11-25 14:25:39 +00:00
|
|
|
symbol->SetValueFieldText( m_text );
|
2020-11-12 21:31:41 +00:00
|
|
|
else if( fieldType == FOOTPRINT_FIELD )
|
2022-11-25 14:25:39 +00:00
|
|
|
symbol->SetFootprintFieldText( m_text );
|
2016-04-22 13:29:47 +00:00
|
|
|
}
|
2022-09-26 19:25:18 +00:00
|
|
|
else if( parent && parent->Type() == SCH_GLOBAL_LABEL_T )
|
|
|
|
{
|
|
|
|
if( fieldType == 0 )
|
|
|
|
{
|
|
|
|
if( m_visible->GetValue() != parent->Schematic()->Settings().m_IntersheetRefsShow )
|
|
|
|
{
|
|
|
|
DisplayInfoMessage( this, _( "Intersheet reference visibility is "
|
|
|
|
"controlled globally from "
|
|
|
|
"Schematic Setup > General > Formatting" ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-22 13:29:47 +00:00
|
|
|
|
2018-07-06 17:03:57 +00:00
|
|
|
bool positioningModified = false;
|
2018-01-18 02:51:48 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
if( aField->GetPosition() != m_position )
|
2018-07-06 17:03:57 +00:00
|
|
|
positioningModified = true;
|
2018-01-18 02:51:48 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
if( aField->GetTextAngle().IsVertical() != m_isVertical )
|
2018-07-06 17:03:57 +00:00
|
|
|
positioningModified = true;
|
2018-01-18 02:51:48 +00:00
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
if( aField->GetEffectiveHorizJustify() != m_horizontalJustification )
|
2018-07-06 17:03:57 +00:00
|
|
|
positioningModified = true;
|
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
if( aField->GetEffectiveVertJustify() != m_verticalJustification )
|
2018-07-06 17:03:57 +00:00
|
|
|
positioningModified = true;
|
2018-01-18 02:51:48 +00:00
|
|
|
|
2020-07-29 17:02:39 +00:00
|
|
|
// convert any text variable cross-references to their UUIDs
|
|
|
|
m_text = aField->Schematic()->ConvertRefsToKIIDs( m_text );
|
|
|
|
|
2016-04-22 13:29:47 +00:00
|
|
|
aField->SetText( m_text );
|
|
|
|
updateText( aField );
|
2022-01-01 06:04:08 +00:00
|
|
|
aField->SetPosition( m_position );
|
2021-11-03 18:11:08 +00:00
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
aField->SetFont( m_font );
|
|
|
|
|
2022-09-03 20:54:05 +00:00
|
|
|
aField->SetNameShown( m_isNameVisible );
|
2022-09-04 16:34:16 +00:00
|
|
|
aField->SetCanAutoplace( m_allowAutoplace );
|
2022-09-03 20:54:05 +00:00
|
|
|
|
2021-11-03 18:11:08 +00:00
|
|
|
// Note that we must set justifications before we can ask if they're flipped. If the old
|
|
|
|
// justification is center then it won't know (whereas if the new justification is center
|
|
|
|
// the we don't care).
|
2022-01-03 01:20:25 +00:00
|
|
|
aField->SetHorizJustify( m_horizontalJustification );
|
|
|
|
aField->SetVertJustify( m_verticalJustification );
|
2021-11-03 18:11:08 +00:00
|
|
|
|
|
|
|
if( aField->IsHorizJustifyFlipped() )
|
2022-01-03 01:20:25 +00:00
|
|
|
aField->SetHorizJustify( EDA_TEXT::MapHorizJustify( -m_horizontalJustification ) );
|
2021-11-03 18:11:08 +00:00
|
|
|
|
|
|
|
if( aField->IsVertJustifyFlipped() )
|
2022-01-03 01:20:25 +00:00
|
|
|
aField->SetVertJustify( EDA_TEXT::MapVertJustify( -m_verticalJustification ) );
|
2018-01-18 02:51:48 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
// The value, footprint and datasheet fields should be kept in sync in multi-unit parts.
|
2021-06-14 18:00:08 +00:00
|
|
|
// Of course the symbol must be annotated to collect other units.
|
2021-06-10 14:10:55 +00:00
|
|
|
if( editFrame && parent && parent->Type() == SCH_SYMBOL_T )
|
2020-03-30 13:14:44 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( parent );
|
2020-03-30 13:14:44 +00:00
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
if( symbol->IsAnnotated( aSheetPath ) && ( fieldType == VALUE_FIELD
|
|
|
|
|| fieldType == FOOTPRINT_FIELD
|
|
|
|
|| fieldType == DATASHEET_FIELD ) )
|
2020-03-30 13:14:44 +00:00
|
|
|
{
|
2020-10-24 20:55:32 +00:00
|
|
|
wxString ref = symbol->GetRef( aSheetPath );
|
|
|
|
int unit = symbol->GetUnit();
|
2021-05-06 11:13:08 +00:00
|
|
|
LIB_ID libId = symbol->GetLibId();
|
2020-07-13 11:21:40 +00:00
|
|
|
|
2020-10-24 20:55:32 +00:00
|
|
|
for( SCH_SHEET_PATH& sheet : editFrame->Schematic().GetSheets() )
|
2020-07-13 11:21:40 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SCREEN* screen = sheet.LastScreen();
|
|
|
|
std::vector<SCH_SYMBOL*> otherUnits;
|
|
|
|
constexpr bool appendUndo = true;
|
2020-10-24 20:55:32 +00:00
|
|
|
|
2021-05-06 11:13:08 +00:00
|
|
|
CollectOtherUnits( ref, unit, libId, sheet, &otherUnits );
|
2020-10-24 20:55:32 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
for( SCH_SYMBOL* otherUnit : otherUnits )
|
2020-10-24 20:55:32 +00:00
|
|
|
{
|
|
|
|
editFrame->SaveCopyInUndoList( screen, otherUnit, UNDO_REDO::CHANGED,
|
|
|
|
appendUndo );
|
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
if( fieldType == VALUE_FIELD )
|
2022-11-25 14:25:39 +00:00
|
|
|
otherUnit->SetValueFieldText( m_text );
|
2020-11-12 21:31:41 +00:00
|
|
|
else if( fieldType == FOOTPRINT_FIELD )
|
2022-11-25 14:25:39 +00:00
|
|
|
otherUnit->SetFootprintFieldText( m_text );
|
2020-10-24 20:55:32 +00:00
|
|
|
else
|
2021-02-28 13:28:23 +00:00
|
|
|
otherUnit->GetField( DATASHEET_FIELD )->SetText( m_text );
|
2020-10-24 20:55:32 +00:00
|
|
|
|
2021-10-06 03:10:20 +00:00
|
|
|
editFrame->UpdateItem( otherUnit, false, true );
|
2020-10-24 20:55:32 +00:00
|
|
|
}
|
2020-07-13 11:21:40 +00:00
|
|
|
}
|
2020-03-30 13:14:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-23 15:17:22 +00:00
|
|
|
if( positioningModified && parent )
|
2020-03-30 13:14:44 +00:00
|
|
|
parent->ClearFieldsAutoplaced();
|
2016-04-22 13:29:47 +00:00
|
|
|
}
|