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
|
2019-05-28 23:23:58 +00:00
|
|
|
* Copyright (C) 2010-2019 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
|
|
|
|
*/
|
|
|
|
|
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-05-31 12:15:25 +00:00
|
|
|
#include <gr_text.h>
|
2019-03-27 12:36:28 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <widgets/tab_traversal.h>
|
2018-06-06 10:05:56 +00:00
|
|
|
#include <widgets/unit_binder.h>
|
2019-03-27 12:36:28 +00:00
|
|
|
#include <board_commit.h>
|
2018-06-06 10:05:56 +00:00
|
|
|
#include <class_board.h>
|
2019-03-27 12:36:28 +00:00
|
|
|
#include <class_dimension.h>
|
|
|
|
#include <class_module.h>
|
2018-06-06 10:05:56 +00:00
|
|
|
#include <class_pcb_text.h>
|
|
|
|
#include <class_text_mod.h>
|
2019-03-27 12:36:28 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
|
|
|
#include <pcb_layer_box_selector.h>
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <wx/valnum.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2018-06-06 10:05:56 +00:00
|
|
|
|
|
|
|
|
2019-05-28 23:23:58 +00:00
|
|
|
DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BOARD_ITEM* aItem ) :
|
2018-06-06 10:05:56 +00:00
|
|
|
DIALOG_TEXT_PROPERTIES_BASE( aParent ),
|
2019-08-04 16:30:18 +00:00
|
|
|
m_Parent( aParent ),
|
|
|
|
m_item( aItem ),
|
|
|
|
m_edaText( nullptr ),
|
|
|
|
m_modText( nullptr ),
|
|
|
|
m_pcbText( nullptr ),
|
2018-11-29 18:59:38 +00:00
|
|
|
m_textWidth( aParent, m_SizeXLabel, m_SizeXCtrl, m_SizeXUnits, true ),
|
|
|
|
m_textHeight( aParent, m_SizeYLabel, m_SizeYCtrl, m_SizeYUnits, true ),
|
|
|
|
m_thickness( aParent, m_ThicknessLabel, m_ThicknessCtrl, m_ThicknessUnits, true ),
|
2018-06-06 10:05:56 +00:00
|
|
|
m_posX( aParent, m_PositionXLabel, m_PositionXCtrl, m_PositionXUnits ),
|
|
|
|
m_posY( aParent, m_PositionYLabel, m_PositionYCtrl, m_PositionYUnits ),
|
2019-09-02 10:07:05 +00:00
|
|
|
m_linesThickness( aParent, m_LineThicknessLabel, m_LineThicknessCtrl,
|
|
|
|
m_LineThicknessUnits, true ),
|
2018-06-06 10:05:56 +00:00
|
|
|
m_OrientValidator( 1, &m_OrientValue )
|
|
|
|
{
|
2018-07-21 12:49:19 +00:00
|
|
|
wxString title;
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2020-04-18 20:40:54 +00:00
|
|
|
m_MultiLineText->SetEOLMode( wxSTC_EOL_LF );
|
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
|
|
|
|
2019-09-02 10:07:05 +00:00
|
|
|
m_linesThickness.Show( m_item->Type() == PCB_DIMENSION_T );
|
2019-09-02 07:11:59 +00:00
|
|
|
|
2018-06-06 10:05:56 +00:00
|
|
|
if( m_item->Type() == PCB_DIMENSION_T )
|
|
|
|
{
|
2019-09-02 10:07:05 +00:00
|
|
|
title = _( "Dimension Properties" );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
|
|
|
DIMENSION* dimension = (DIMENSION*) m_item;
|
|
|
|
m_edaText = &dimension->Text();
|
|
|
|
m_pcbText = &dimension->Text();
|
|
|
|
|
2019-09-02 10:07:05 +00:00
|
|
|
// Since this is really the object properties for a dimension (rather than just the
|
|
|
|
// text properties), make some of the propertie labels more explicit.
|
|
|
|
for( wxStaticText* label : { m_SizeXLabel, m_SizeYLabel, m_ThicknessLabel,
|
|
|
|
m_PositionXLabel, m_PositionYLabel, m_OrientLabel } )
|
|
|
|
{
|
|
|
|
label->SetLabel( label->GetToolTipText() + wxT( ":" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Mirrored->SetLabel( m_Mirrored->GetToolTipText() );
|
|
|
|
|
2018-07-21 12:49:19 +00:00
|
|
|
SetInitialFocus( m_DimensionText );
|
|
|
|
m_SingleLineSizer->Show( false );
|
|
|
|
m_MultiLineSizer->Show( false );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
|
|
|
m_KeepUpright->Show( false );
|
2018-07-21 12:49:19 +00:00
|
|
|
m_statusLine->Show( false );
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
|
|
|
else if( m_item->Type() == PCB_MODULE_TEXT_T )
|
|
|
|
{
|
|
|
|
title = _( "Footprint Text Properties" );
|
|
|
|
|
|
|
|
m_modText = (TEXTE_MODULE*) m_item;
|
|
|
|
m_edaText = static_cast<EDA_TEXT*>( m_modText );
|
|
|
|
|
|
|
|
switch( m_modText->GetType() )
|
|
|
|
{
|
2018-07-21 12:49:19 +00:00
|
|
|
case TEXTE_MODULE::TEXT_is_REFERENCE: m_TextLabel->SetLabel( _( "Reference:" ) ); break;
|
|
|
|
case TEXTE_MODULE::TEXT_is_VALUE: m_TextLabel->SetLabel( _( "Value:" ) ); break;
|
|
|
|
case TEXTE_MODULE::TEXT_is_DIVERS: m_TextLabel->SetLabel( _( "Text:" ) ); break;
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
2018-07-21 12:49:19 +00:00
|
|
|
|
|
|
|
SetInitialFocus( m_SingleLineText );
|
|
|
|
m_MultiLineSizer->Show( false );
|
|
|
|
m_DimensionTextSizer->Show( false );
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
title = _( "Text Properties" );
|
|
|
|
|
|
|
|
m_pcbText = (TEXTE_PCB*) aItem;
|
|
|
|
m_edaText = static_cast<EDA_TEXT*>( m_pcbText );
|
2018-07-21 12:49:19 +00:00
|
|
|
|
|
|
|
SetInitialFocus( m_MultiLineText );
|
|
|
|
m_SingleLineSizer->Show( false );
|
|
|
|
m_DimensionTextSizer->Show( false );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2018-12-02 09:30:48 +00:00
|
|
|
// This option make sense only for footprint texts,
|
|
|
|
// Texts on board are always visible:
|
|
|
|
m_Visible->SetValue( true );
|
|
|
|
m_Visible->Show( false );
|
|
|
|
|
2018-06-06 10:05:56 +00:00
|
|
|
m_KeepUpright->Show( false );
|
2018-07-21 12:49:19 +00:00
|
|
|
m_statusLine->Show( false );
|
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.
|
|
|
|
if( !m_Parent->GetBoard()->IsLayerEnabled( m_item->GetLayer() ) )
|
|
|
|
m_LayerSelectionCtrl->ShowNonActivatedLayers( true );
|
|
|
|
|
|
|
|
m_LayerSelectionCtrl->SetLayersHotkeys( false );
|
2018-08-24 02:29:05 +00:00
|
|
|
m_LayerSelectionCtrl->SetNotAllowedLayerSet( LSET::ForbiddenTextLayers() );
|
2018-06-06 10:05:56 +00:00
|
|
|
m_LayerSelectionCtrl->SetBoardFrame( m_Parent );
|
|
|
|
m_LayerSelectionCtrl->Resync();
|
|
|
|
|
|
|
|
m_OrientValue = 0.0;
|
|
|
|
m_OrientValidator.SetRange( -360.0, 360.0 );
|
|
|
|
m_OrientCtrl->SetValidator( m_OrientValidator );
|
|
|
|
m_OrientValidator.SetWindow( m_OrientCtrl );
|
|
|
|
|
2018-12-05 18:08:06 +00:00
|
|
|
// Handle decimal separators in combo dropdown
|
|
|
|
for( size_t i = 0; i < m_OrientCtrl->GetCount(); ++i )
|
|
|
|
{
|
|
|
|
wxString item = m_OrientCtrl->GetString( i );
|
|
|
|
item.Replace( '.', localeconv()->decimal_point[0] );
|
|
|
|
m_OrientCtrl->SetString( i, item );
|
|
|
|
}
|
|
|
|
|
2018-07-17 21:14:02 +00:00
|
|
|
// Set font sizes
|
|
|
|
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
|
2018-07-18 16:59:05 +00:00
|
|
|
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
|
|
|
|
m_statusLine->SetFont( infoFont );
|
2018-07-17 21:14:02 +00:00
|
|
|
|
2018-06-06 10:05:56 +00:00
|
|
|
m_sdbSizerOK->SetDefault();
|
|
|
|
|
2019-08-26 17:36:35 +00:00
|
|
|
// We can't set the tab order through wxWidgets due to shortcomings in their mnemonics
|
|
|
|
// implementation on MSW
|
|
|
|
m_tabOrder = {
|
2019-03-27 12:36:28 +00:00
|
|
|
m_LayerLabel,
|
|
|
|
m_LayerSelectionCtrl,
|
|
|
|
m_SizeXCtrl,
|
|
|
|
m_SizeYCtrl,
|
|
|
|
m_ThicknessCtrl,
|
|
|
|
m_PositionXCtrl,
|
|
|
|
m_PositionYCtrl,
|
2019-09-02 10:07:05 +00:00
|
|
|
m_LineThicknessCtrl,
|
2019-03-27 12:36:28 +00:00
|
|
|
m_Visible,
|
|
|
|
m_Italic,
|
|
|
|
m_JustifyChoice,
|
|
|
|
m_OrientCtrl,
|
|
|
|
m_Mirrored,
|
|
|
|
m_KeepUpright,
|
2019-08-26 17:36:35 +00:00
|
|
|
m_sdbSizerOK,
|
|
|
|
m_sdbSizerCancel
|
|
|
|
};
|
2019-03-27 12:36:28 +00:00
|
|
|
|
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.
|
2018-12-01 11:56:59 +00:00
|
|
|
Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( DIALOG_TEXT_PROPERTIES::OnCharHook ), NULL, this );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
|
|
|
FinishDialogSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_TEXT_PROPERTIES::~DIALOG_TEXT_PROPERTIES()
|
|
|
|
{
|
2018-12-01 11:56:59 +00:00
|
|
|
Disconnect( wxEVT_CHAR_HOOK, wxKeyEventHandler( DIALOG_TEXT_PROPERTIES::OnCharHook ), NULL, this );
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Routine for main window class to launch text properties dialog.
|
|
|
|
*/
|
2019-05-28 23:23:58 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::InstallTextOptionsFrame( BOARD_ITEM* aText )
|
2018-06-06 10:05:56 +00:00
|
|
|
{
|
2019-05-28 23:23:58 +00:00
|
|
|
DIALOG_TEXT_PROPERTIES dlg( this, aText );
|
2018-06-06 10:05:56 +00:00
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_TEXT_PROPERTIES::OnCharHook( wxKeyEvent& aEvent )
|
|
|
|
{
|
2019-09-10 11:06:08 +00:00
|
|
|
if( aEvent.GetKeyCode() == WXK_RETURN && aEvent.ShiftDown() )
|
2018-06-06 10:05:56 +00:00
|
|
|
{
|
2019-09-10 11:06:08 +00:00
|
|
|
if( TransferDataFromWindow() )
|
|
|
|
EndModal( wxID_OK );
|
|
|
|
}
|
|
|
|
else if( m_MultiLineText->IsShown() && m_MultiLineText->HasFocus() )
|
|
|
|
{
|
|
|
|
if( aEvent.GetKeyCode() == WXK_TAB && !aEvent.ControlDown() )
|
2019-09-05 07:42:01 +00:00
|
|
|
{
|
2019-09-10 11:06:08 +00:00
|
|
|
m_MultiLineText->Tab();
|
2019-09-05 07:42:01 +00:00
|
|
|
}
|
2019-09-10 11:06:08 +00:00
|
|
|
else if( IsCtrl( 'Z', aEvent ) )
|
2019-09-05 07:42:01 +00:00
|
|
|
{
|
2019-09-10 11:06:08 +00:00
|
|
|
m_MultiLineText->Undo();
|
|
|
|
}
|
|
|
|
else if( IsShiftCtrl( 'Z', aEvent ) || IsCtrl( 'Y', aEvent ) )
|
|
|
|
{
|
|
|
|
m_MultiLineText->Redo();
|
|
|
|
}
|
|
|
|
else if( IsCtrl( 'X', aEvent ) )
|
|
|
|
{
|
|
|
|
m_MultiLineText->Cut();
|
|
|
|
}
|
|
|
|
else if( IsCtrl( 'C', aEvent ) )
|
|
|
|
{
|
|
|
|
m_MultiLineText->Copy();
|
|
|
|
}
|
|
|
|
else if( IsCtrl( 'V', aEvent ) )
|
|
|
|
{
|
|
|
|
m_MultiLineText->Paste();
|
2019-09-05 07:42:01 +00:00
|
|
|
}
|
2018-12-01 11:56:59 +00:00
|
|
|
else
|
|
|
|
{
|
2019-09-10 11:06:08 +00:00
|
|
|
aEvent.Skip();
|
2018-12-01 11:56:59 +00:00
|
|
|
}
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-21 12:49:19 +00:00
|
|
|
void DIALOG_TEXT_PROPERTIES::OnDimensionTextChange( wxCommandEvent& event )
|
2018-06-06 10:05:56 +00:00
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
EDA_UNITS units = EDA_UNITS::UNSCALED;
|
2018-07-21 12:49:19 +00:00
|
|
|
bool useMils;
|
|
|
|
|
|
|
|
FetchUnitsFromString( m_DimensionText->GetValue(), units, useMils );
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
if( units != EDA_UNITS::UNSCALED )
|
|
|
|
m_DimensionUnitsOpt->SetSelection( units == EDA_UNITS::MILLIMETRES ? 2 : useMils ? 1 : 0 );
|
2018-07-21 12:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_TEXT_PROPERTIES::OnDimensionUnitsChange( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
DIMENSION* dimension = (DIMENSION*) m_item;
|
2019-12-20 14:11:39 +00:00
|
|
|
EDA_UNITS units;
|
2018-07-21 12:49:19 +00:00
|
|
|
bool useMils;
|
|
|
|
|
|
|
|
// Get default units in case dimension text doesn't contain units.
|
|
|
|
dimension->GetUnits( units, useMils );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2018-07-21 12:49:19 +00:00
|
|
|
double value = ValueFromString( units, m_DimensionText->GetValue(), useMils );
|
|
|
|
|
|
|
|
switch( event.GetSelection() )
|
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
case 0:
|
|
|
|
units = EDA_UNITS::INCHES;
|
|
|
|
useMils = false;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
units = EDA_UNITS::INCHES;
|
|
|
|
useMils = true;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
units = EDA_UNITS::MILLIMETRES;
|
|
|
|
useMils = false;
|
|
|
|
break;
|
2018-07-21 12:49:19 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_DimensionText->SetValue( StringFromValue( units, value, true, useMils ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
wxString DIALOG_TEXT_PROPERTIES::convertKIIDsToReferences( const wxString& aSource )
|
|
|
|
{
|
|
|
|
wxString newbuf;
|
|
|
|
size_t sourceLen = aSource.length();
|
|
|
|
|
|
|
|
for( size_t i = 0; i < sourceLen; ++i )
|
|
|
|
{
|
|
|
|
if( aSource[i] == '$' && i + 1 < sourceLen && aSource[i+1] == '{' )
|
|
|
|
{
|
|
|
|
wxString token;
|
|
|
|
bool isCrossRef = false;
|
|
|
|
|
|
|
|
for( i = i + 2; i < sourceLen; ++i )
|
|
|
|
{
|
|
|
|
if( aSource[i] == '}' )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( aSource[i] == ':' )
|
|
|
|
isCrossRef = true;
|
|
|
|
|
|
|
|
token.append( aSource[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( isCrossRef )
|
|
|
|
{
|
2020-04-11 19:12:49 +00:00
|
|
|
wxString remainder;
|
|
|
|
wxString ref = token.BeforeFirst( ':', &remainder );
|
|
|
|
BOARD_ITEM* refItem = m_Parent->GetBoard()->GetItem( KIID( ref ) );
|
2020-04-06 13:06:57 +00:00
|
|
|
|
|
|
|
if( refItem && refItem->Type() == PCB_MODULE_T )
|
2020-04-11 19:12:49 +00:00
|
|
|
token = static_cast<MODULE*>( refItem )->GetReference() + ":" + remainder;
|
2020-04-06 13:06:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
newbuf.append( "${" + token + "}" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newbuf.append( aSource[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString DIALOG_TEXT_PROPERTIES::convertReferencesToKIIDs( const wxString& aSource )
|
|
|
|
{
|
|
|
|
wxString newbuf;
|
|
|
|
size_t sourceLen = aSource.length();
|
|
|
|
|
|
|
|
for( size_t i = 0; i < sourceLen; ++i )
|
|
|
|
{
|
|
|
|
if( aSource[i] == '$' && i + 1 < sourceLen && aSource[i+1] == '{' )
|
|
|
|
{
|
|
|
|
wxString token;
|
|
|
|
bool isCrossRef = false;
|
|
|
|
|
|
|
|
for( i = i + 2; i < sourceLen; ++i )
|
|
|
|
{
|
|
|
|
if( aSource[i] == '}' )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( aSource[i] == ':' )
|
|
|
|
isCrossRef = true;
|
|
|
|
|
|
|
|
token.append( aSource[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( isCrossRef )
|
|
|
|
{
|
2020-04-11 19:12:49 +00:00
|
|
|
wxString remainder;
|
|
|
|
wxString ref = token.BeforeFirst( ':', &remainder );
|
2020-04-06 13:06:57 +00:00
|
|
|
|
|
|
|
for( MODULE* mod : m_Parent->GetBoard()->Modules() )
|
|
|
|
{
|
2020-04-11 19:12:49 +00:00
|
|
|
if( mod->GetReference().CmpNoCase( ref ) == 0 )
|
2020-04-06 13:06:57 +00:00
|
|
|
{
|
2020-04-11 19:37:06 +00:00
|
|
|
wxString test( remainder );
|
|
|
|
|
|
|
|
if( mod->ResolveTextVar( &test ) )
|
|
|
|
token = mod->m_Uuid.AsString() + ":" + remainder;
|
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newbuf.append( "${" + token + "}" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newbuf.append( aSource[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-21 12:49:19 +00:00
|
|
|
bool DIALOG_TEXT_PROPERTIES::TransferDataToWindow()
|
|
|
|
{
|
2018-06-06 10:05:56 +00:00
|
|
|
if( m_SingleLineText->IsShown() )
|
|
|
|
{
|
|
|
|
m_SingleLineText->SetValue( m_edaText->GetText() );
|
2018-10-13 23:06:41 +00:00
|
|
|
|
|
|
|
if( m_modText && m_modText->GetType() == TEXTE_MODULE::TEXT_is_REFERENCE )
|
|
|
|
SelectReferenceNumber( static_cast<wxTextEntry*>( m_SingleLineText ) );
|
|
|
|
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
|
|
|
{
|
2020-04-06 13:06:57 +00:00
|
|
|
m_MultiLineText->SetValue( convertKIIDsToReferences( m_edaText->GetText() ) );
|
2018-06-06 10:05:56 +00:00
|
|
|
m_MultiLineText->SetSelection( -1, -1 );
|
|
|
|
}
|
2018-07-21 12:49:19 +00:00
|
|
|
else if (m_DimensionText->IsShown() )
|
|
|
|
{
|
|
|
|
m_DimensionText->SetValue( m_edaText->GetText() );
|
|
|
|
m_DimensionText->SetSelection( -1, -1 );
|
|
|
|
|
|
|
|
DIMENSION* dimension = (DIMENSION*) m_item;
|
2019-12-20 14:11:39 +00:00
|
|
|
EDA_UNITS units;
|
|
|
|
bool useMils;
|
2018-07-21 12:49:19 +00:00
|
|
|
dimension->GetUnits( units, useMils );
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
m_DimensionUnitsOpt->SetSelection( units == EDA_UNITS::MILLIMETRES ? 2 : useMils ? 1 : 0 );
|
2019-09-02 07:11:59 +00:00
|
|
|
|
|
|
|
m_linesThickness.SetValue( dimension->GetWidth() );
|
2018-07-21 12:49:19 +00:00
|
|
|
}
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2019-01-03 03:40:29 +00:00
|
|
|
if( m_item->Type() == PCB_MODULE_TEXT_T && m_modText )
|
2018-06-06 10:05:56 +00:00
|
|
|
{
|
2018-07-21 12:49:19 +00:00
|
|
|
MODULE* module = dynamic_cast<MODULE*>( m_modText->GetParent() );
|
|
|
|
wxString msg;
|
2018-06-06 10:05:56 +00:00
|
|
|
|
|
|
|
if( module )
|
|
|
|
{
|
2018-07-18 16:59:05 +00:00
|
|
|
msg.Printf( _("Footprint %s (%s), %s, rotated %.1f deg"),
|
|
|
|
module->GetReference(),
|
|
|
|
module->GetValue(),
|
|
|
|
module->IsFlipped() ? _( "back side (mirrored)" ) : _( "front side" ),
|
|
|
|
module->GetOrientation() / 10.0 );
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2018-07-21 12:49:19 +00:00
|
|
|
m_statusLine->SetLabel( msg );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_statusLine->Show( false );
|
|
|
|
}
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2018-12-05 18:08:06 +00:00
|
|
|
if( m_LayerSelectionCtrl->SetLayerSelection( m_item->GetLayer() ) < 0 )
|
|
|
|
{
|
|
|
|
wxMessageBox( _( "This item was on a non-existing or forbidden layer.\n"
|
|
|
|
"It has been moved to the first allowed layer." ) );
|
|
|
|
m_LayerSelectionCtrl->SetSelection( 0 );
|
|
|
|
}
|
2018-06-06 10:05:56 +00:00
|
|
|
|
|
|
|
m_textWidth.SetValue( m_edaText->GetTextSize().x );
|
|
|
|
m_textHeight.SetValue( m_edaText->GetTextSize().y );
|
2020-04-14 12:25:00 +00:00
|
|
|
m_thickness.SetValue( m_edaText->GetTextThickness() );
|
2018-06-06 10:05:56 +00:00
|
|
|
m_posX.SetValue( m_edaText->GetTextPos().x );
|
|
|
|
m_posY.SetValue( m_edaText->GetTextPos().y );
|
|
|
|
|
|
|
|
m_Visible->SetValue( m_edaText->IsVisible() );
|
|
|
|
m_Italic->SetValue( m_edaText->IsItalic() );
|
|
|
|
EDA_TEXT_HJUSTIFY_T hJustify = m_edaText->GetHorizJustify();
|
|
|
|
m_JustifyChoice->SetSelection( (int) hJustify + 1 );
|
|
|
|
m_OrientValue = m_edaText->GetTextAngleDegrees();
|
|
|
|
m_Mirrored->SetValue( m_edaText->IsMirrored() );
|
|
|
|
|
|
|
|
if( m_modText )
|
2018-04-28 15:22:25 +00:00
|
|
|
m_KeepUpright->SetValue( m_modText->IsKeepUpright() );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
|
|
|
return DIALOG_TEXT_PROPERTIES_BASE::TransferDataToWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_TEXT_PROPERTIES::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
if( !DIALOG_TEXT_PROPERTIES_BASE::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
2018-11-29 18:59:38 +00:00
|
|
|
if( !m_textWidth.Validate( TEXTS_MIN_SIZE, TEXTS_MAX_SIZE )
|
|
|
|
|| !m_textHeight.Validate( TEXTS_MIN_SIZE, TEXTS_MAX_SIZE ) )
|
2018-06-06 10:05:56 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
BOARD_COMMIT commit( m_Parent );
|
|
|
|
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
|
|
|
|
|
|
|
/* set flag in edit to force undo/redo/abort proper operation,
|
|
|
|
* and avoid new calls to SaveCopyInUndoList for the same text
|
|
|
|
* this can occurs when a text is moved, and then rotated, edited ..
|
|
|
|
*/
|
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() )
|
|
|
|
m_edaText->SetText( m_SingleLineText->GetValue() );
|
|
|
|
}
|
|
|
|
else if( m_MultiLineText->IsShown() )
|
|
|
|
{
|
|
|
|
if( !m_MultiLineText->GetValue().IsEmpty() )
|
2019-09-10 08:57:04 +00:00
|
|
|
{
|
2020-04-06 13:06:57 +00:00
|
|
|
wxString txt = convertReferencesToKIIDs( m_MultiLineText->GetValue() );
|
|
|
|
|
2019-09-10 08:57:04 +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
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
txt.Replace( "\r", "" );
|
|
|
|
#endif
|
|
|
|
m_edaText->SetText( txt );
|
|
|
|
}
|
2018-07-21 12:49:19 +00:00
|
|
|
}
|
|
|
|
else if( m_DimensionText->IsShown() )
|
|
|
|
{
|
|
|
|
if( !m_DimensionText->GetValue().IsEmpty() )
|
|
|
|
m_edaText->SetText( m_DimensionText->GetValue() );
|
|
|
|
|
|
|
|
DIMENSION* dimension = (DIMENSION*) m_item;
|
|
|
|
|
|
|
|
switch( m_DimensionUnitsOpt->GetSelection() )
|
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
case 0:
|
|
|
|
dimension->SetUnits( EDA_UNITS::INCHES, false );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
dimension->SetUnits( EDA_UNITS::INCHES, true );
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
dimension->SetUnits( EDA_UNITS::MILLIMETRES, false );
|
|
|
|
break;
|
2018-07-21 12:49:19 +00:00
|
|
|
default: break;
|
|
|
|
}
|
2019-09-02 07:11:59 +00:00
|
|
|
|
|
|
|
dimension->SetWidth( m_linesThickness.GetValue() );
|
2019-11-27 16:38:40 +00:00
|
|
|
dimension->AdjustDimensionDetails(
|
|
|
|
m_Parent->GetBoard()->GetDesignSettings().m_DimensionPrecision );
|
2018-07-21 12:49:19 +00:00
|
|
|
}
|
2018-06-06 10:05:56 +00:00
|
|
|
|
|
|
|
m_item->SetLayer( ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() ) );
|
|
|
|
|
|
|
|
m_edaText->SetTextSize( wxSize( m_textWidth.GetValue(), m_textHeight.GetValue() ) );
|
2020-04-14 12:25:00 +00:00
|
|
|
m_edaText->SetTextThickness( m_thickness.GetValue() );
|
2018-06-06 10:05:56 +00:00
|
|
|
m_edaText->SetTextPos( wxPoint( m_posX.GetValue(), m_posY.GetValue() ) );
|
|
|
|
|
2018-07-19 22:25:58 +00:00
|
|
|
if( m_modText )
|
|
|
|
m_modText->SetLocalCoord();
|
|
|
|
|
2018-06-06 10:05:56 +00:00
|
|
|
// Test for acceptable values for thickness and size and clamp if fails
|
2020-04-14 12:25:00 +00:00
|
|
|
int maxPenWidth = Clamp_Text_PenSize( m_edaText->GetTextThickness(), m_edaText->GetTextSize() );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
if( m_edaText->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." ) );
|
2020-04-14 12:25:00 +00:00
|
|
|
m_edaText->SetTextThickness( maxPenWidth );
|
2018-06-06 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_edaText->SetVisible( m_Visible->GetValue() );
|
|
|
|
m_edaText->SetItalic( m_Italic->GetValue() );
|
|
|
|
m_edaText->SetTextAngle( KiROUND( m_OrientValue * 10.0 ) );
|
|
|
|
m_edaText->SetMirrored( m_Mirrored->GetValue() );
|
|
|
|
|
|
|
|
if( m_modText )
|
2018-04-28 15:22:25 +00:00
|
|
|
m_modText->SetKeepUpright( m_KeepUpright->GetValue() );
|
2018-06-06 10:05:56 +00:00
|
|
|
|
|
|
|
switch( m_JustifyChoice->GetSelection() )
|
|
|
|
{
|
|
|
|
case 0: m_edaText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break;
|
|
|
|
case 1: m_edaText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break;
|
|
|
|
case 2: m_edaText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Parent->Refresh();
|
|
|
|
|
|
|
|
if( pushCommit )
|
|
|
|
commit.Push( _( "Change text properties" ) );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|