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
|
2018-01-09 14:20:54 +00:00
|
|
|
* Copyright (C) 2004-2018 KiCad Developers, see change_log.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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
2014-10-14 20:39:25 +00:00
|
|
|
#include <kiway.h>
|
2016-04-02 12:25:44 +00:00
|
|
|
#include <confirm.h>
|
2018-09-27 10:56:51 +00:00
|
|
|
#include <kicad_string.h>
|
2012-02-22 14:04:48 +00:00
|
|
|
#include <sch_base_frame.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <class_libentry.h>
|
|
|
|
#include <lib_field.h>
|
|
|
|
#include <template_fieldnames.h>
|
2016-04-02 12:25:44 +00:00
|
|
|
#include <class_library.h>
|
2018-09-27 16:21:06 +00:00
|
|
|
#include <sch_validators.h>
|
2012-02-22 14:04:48 +00:00
|
|
|
|
|
|
|
#include <dialog_edit_one_field.h>
|
2019-06-30 22:06:34 +00:00
|
|
|
#include <sch_text.h>
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
DIALOG_EDIT_ONE_FIELD::DIALOG_EDIT_ONE_FIELD( SCH_BASE_FRAME* aParent, const wxString& aTitle,
|
|
|
|
const EDA_TEXT* aTextItem ) :
|
2018-05-24 07:12:43 +00:00
|
|
|
DIALOG_LIB_EDIT_TEXT_BASE( aParent ),
|
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 ),
|
2018-11-29 18:59:38 +00:00
|
|
|
m_textSize( aParent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true )
|
2016-04-02 12:25:44 +00:00
|
|
|
{
|
2020-01-12 19:45:37 +00:00
|
|
|
wxASSERT( aTextItem );
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
SetTitle( aTitle );
|
|
|
|
|
|
|
|
// The field ID and power status are Initialized in the derived object's ctor.
|
|
|
|
m_fieldId = VALUE;
|
|
|
|
m_isPower = false;
|
|
|
|
|
|
|
|
m_text = aTextItem->GetText();
|
2018-07-06 17:03:57 +00:00
|
|
|
m_isItalic = aTextItem->IsItalic();
|
|
|
|
m_isBold = aTextItem->IsBold();
|
|
|
|
m_position = aTextItem->GetTextPos();
|
2017-01-23 20:30:11 +00:00
|
|
|
m_size = aTextItem->GetTextWidth();
|
2018-07-06 17:03:57 +00:00
|
|
|
m_isVertical = ( aTextItem->GetTextAngle() == TEXT_ANGLE_VERT );
|
2016-04-02 12:25:44 +00:00
|
|
|
m_verticalJustification = aTextItem->GetVertJustify() + 1;
|
|
|
|
m_horizontalJustification = aTextItem->GetHorizJustify() + 1;
|
|
|
|
m_isVisible = aTextItem->IsVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_EDIT_ONE_FIELD::init()
|
|
|
|
{
|
2018-05-24 07:12:43 +00:00
|
|
|
SetInitialFocus( m_TextValue );
|
2018-09-27 16:21:06 +00:00
|
|
|
SCH_BASE_FRAME* parent = GetParent();
|
|
|
|
bool libedit = parent->IsType( FRAME_SCH_LIB_EDITOR );
|
|
|
|
m_TextValue->SetValidator( SCH_FIELD_VALIDATOR( libedit, m_fieldId, &m_text ) );
|
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
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
// Show the footprint selection dialog if this is the footprint field.
|
2018-05-24 07:12:43 +00:00
|
|
|
m_TextValueSelectButton->Show( m_fieldId == FOOTPRINT );
|
2015-03-23 11:45:31 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
// Value fields of power components cannot be modified. This will grey out
|
|
|
|
// the text box and display an explanation.
|
|
|
|
if( m_fieldId == VALUE && m_isPower )
|
|
|
|
{
|
|
|
|
m_PowerComponentValues->Show( true );
|
|
|
|
m_TextValue->Enable( false );
|
|
|
|
}
|
2016-04-04 14:31:34 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_PowerComponentValues->Show( false );
|
|
|
|
m_TextValue->Enable( true );
|
|
|
|
}
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
m_sdbSizerButtonsOK->SetDefault();
|
2016-07-16 10:54:55 +00:00
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
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
|
|
|
|
2014-10-14 20:39:25 +00:00
|
|
|
void DIALOG_EDIT_ONE_FIELD::OnTextValueSelectButtonClick( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
// pick a footprint using the footprint picker.
|
2018-06-12 12:38:31 +00:00
|
|
|
wxString fpid = m_TextValue->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 ) )
|
|
|
|
{
|
|
|
|
m_TextValue->SetValue( fpid );
|
|
|
|
}
|
|
|
|
|
|
|
|
frame->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-19 19:20:53 +00:00
|
|
|
void DIALOG_EDIT_ONE_FIELD::OnSetFocusText( wxFocusEvent& event )
|
2012-02-22 14:04:48 +00:00
|
|
|
{
|
2019-07-28 17:28:01 +00:00
|
|
|
#ifdef __WXGTK__
|
2019-07-01 21:22:28 +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
|
2019-07-28 17:28:01 +00:00
|
|
|
//
|
|
|
|
// 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
|
2019-07-01 21:22:28 +00:00
|
|
|
m_TextValue->Update();
|
2019-07-28 17:28:01 +00:00
|
|
|
#endif
|
2019-07-01 21:22:28 +00:00
|
|
|
|
2017-01-31 18:37:00 +00:00
|
|
|
if( m_fieldId == REFERENCE )
|
2018-10-13 23:06:41 +00:00
|
|
|
SelectReferenceNumber( static_cast<wxTextEntry*>( m_TextValue ) );
|
2017-01-31 18:37:00 +00:00
|
|
|
else
|
|
|
|
m_TextValue->SetSelection( -1, -1 );
|
2018-07-26 14:41:08 +00:00
|
|
|
|
|
|
|
event.Skip();
|
2018-07-19 19:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_EDIT_ONE_FIELD::TransferDataToWindow()
|
|
|
|
{
|
2018-10-19 11:28:34 +00:00
|
|
|
m_TextValue->SetValue( m_text );
|
2017-01-31 18:37:00 +00:00
|
|
|
|
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 );
|
2018-07-06 17:03:57 +00:00
|
|
|
m_orientChoice->SetSelection( m_isVertical ? 1 : 0 );
|
|
|
|
m_hAlignChoice->SetSelection( m_horizontalJustification );
|
|
|
|
m_vAlignChoice->SetSelection( m_verticalJustification );
|
2018-05-24 07:12:43 +00:00
|
|
|
m_visible->SetValue( m_isVisible );
|
2018-07-06 17:03:57 +00:00
|
|
|
m_italic->SetValue( m_isItalic );
|
|
|
|
m_bold->SetValue( m_isBold );
|
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
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
bool DIALOG_EDIT_ONE_FIELD::TransferDataFromWindow()
|
2012-02-22 14:04:48 +00:00
|
|
|
{
|
2018-10-19 11:28:34 +00:00
|
|
|
m_text = m_TextValue->GetValue();
|
2015-06-04 15:44:56 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
if( m_fieldId == REFERENCE )
|
2015-06-04 15:44:56 +00:00
|
|
|
{
|
2016-04-02 12:25:44 +00:00
|
|
|
// Test if the reference string is valid:
|
|
|
|
if( !SCH_COMPONENT::IsReferenceStringValid( m_text ) )
|
2015-06-04 15:44:56 +00:00
|
|
|
{
|
2016-04-02 12:25:44 +00:00
|
|
|
DisplayError( this, _( "Illegal reference field value!" ) );
|
|
|
|
return false;
|
2015-06-04 15:44:56 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-27 10:56:51 +00:00
|
|
|
else if( m_fieldId == VALUE )
|
|
|
|
{
|
|
|
|
if( m_text.IsEmpty() )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "Value may not be empty." ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-06-04 15:44:56 +00:00
|
|
|
|
2018-07-06 17:03:57 +00:00
|
|
|
m_isVertical = m_orientChoice->GetSelection() == 1;
|
|
|
|
m_position = wxPoint( m_posX.GetValue(), m_posY.GetValue() );
|
2018-05-24 07:12:43 +00:00
|
|
|
m_size = m_textSize.GetValue();
|
2018-07-06 17:03:57 +00:00
|
|
|
m_horizontalJustification = m_hAlignChoice->GetSelection();
|
|
|
|
m_verticalJustification = m_vAlignChoice->GetSelection();
|
2018-05-24 07:12:43 +00:00
|
|
|
m_isVisible = m_visible->GetValue();
|
2018-07-06 17:03:57 +00:00
|
|
|
m_isItalic = m_italic->GetValue();
|
|
|
|
m_isBold = m_bold->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
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
void DIALOG_EDIT_ONE_FIELD::updateText( EDA_TEXT* aText )
|
2012-02-22 14:04:48 +00:00
|
|
|
{
|
2018-07-06 17:03:57 +00:00
|
|
|
aText->SetTextPos( m_position );
|
2017-01-23 20:30:11 +00:00
|
|
|
aText->SetTextSize( wxSize( m_size, m_size ) );
|
2016-04-02 12:25:44 +00:00
|
|
|
aText->SetVisible( m_isVisible );
|
2018-07-06 17:03:57 +00:00
|
|
|
aText->SetTextAngle( m_isVertical ? TEXT_ANGLE_VERT : TEXT_ANGLE_HORIZ );
|
|
|
|
aText->SetItalic( m_isItalic );
|
|
|
|
aText->SetBold( m_isBold );
|
2019-06-30 22:06:34 +00:00
|
|
|
aText->SetHorizJustify( EDA_TEXT::MapHorizJustify( m_horizontalJustification - 1 ) );
|
|
|
|
aText->SetVertJustify( EDA_TEXT::MapVertJustify( m_verticalJustification - 1 ) );
|
2012-02-22 14:04:48 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:39:25 +00:00
|
|
|
|
2020-01-12 19:45:37 +00:00
|
|
|
DIALOG_LIB_EDIT_ONE_FIELD::DIALOG_LIB_EDIT_ONE_FIELD(
|
|
|
|
SCH_BASE_FRAME* aParent, const wxString& aTitle, const LIB_FIELD* aField )
|
2020-01-12 20:26:07 +00:00
|
|
|
: DIALOG_EDIT_ONE_FIELD( aParent, aTitle, aField )
|
2012-02-22 14:04:48 +00:00
|
|
|
{
|
2016-04-02 12:25:44 +00:00
|
|
|
m_fieldId = aField->GetId();
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2016-04-29 16:01:09 +00:00
|
|
|
// When in the library editor, power components can be renamed.
|
|
|
|
m_isPower = false;
|
2016-04-02 12:25:44 +00:00
|
|
|
init();
|
2012-02-22 14:04:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-12 19:45:37 +00:00
|
|
|
DIALOG_SCH_EDIT_ONE_FIELD::DIALOG_SCH_EDIT_ONE_FIELD(
|
|
|
|
SCH_BASE_FRAME* aParent, const wxString& aTitle, const SCH_FIELD* aField )
|
2020-01-12 20:26:07 +00:00
|
|
|
: DIALOG_EDIT_ONE_FIELD( aParent, aTitle, aField )
|
2012-02-22 14:04:48 +00:00
|
|
|
{
|
2016-04-02 12:25:44 +00:00
|
|
|
m_fieldId = aField->GetId();
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
const SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent();
|
2014-10-14 20:39:25 +00:00
|
|
|
|
2018-05-24 07:12:43 +00:00
|
|
|
wxASSERT_MSG( component && component->Type() == SCH_COMPONENT_T,
|
2016-04-02 12:25:44 +00:00
|
|
|
wxT( "Invalid schematic field parent item." ) );
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2018-01-09 14:20:54 +00:00
|
|
|
// The library symbol may have been removed so using SCH_COMPONENT::GetPartRef() here
|
|
|
|
// 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.
|
2017-12-07 23:01:03 +00:00
|
|
|
const LIB_PART* part = GetParent()->GetLibPart( component->GetLibId(), true );
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2018-01-09 14:20:54 +00:00
|
|
|
m_isPower = ( part ) ? part->IsPower() : false;
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
init();
|
2012-02-22 14:04:48 +00:00
|
|
|
}
|
2016-04-22 13:29:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SCH_EDIT_ONE_FIELD::UpdateField( SCH_FIELD* aField, SCH_SHEET_PATH* aSheetPath )
|
|
|
|
{
|
|
|
|
if( aField->GetId() == REFERENCE )
|
|
|
|
{
|
2020-01-12 19:45:37 +00:00
|
|
|
wxASSERT( aSheetPath );
|
2016-04-22 13:29:47 +00:00
|
|
|
|
|
|
|
SCH_COMPONENT* component = dynamic_cast< SCH_COMPONENT* >( aField->GetParent() );
|
|
|
|
|
2020-01-12 19:45:37 +00:00
|
|
|
wxASSERT( component );
|
2016-04-22 13:29:47 +00:00
|
|
|
|
2018-05-24 07:12:43 +00:00
|
|
|
if( component )
|
2016-04-22 13:29:47 +00:00
|
|
|
component->SetRef( aSheetPath, m_text );
|
|
|
|
}
|
|
|
|
|
2018-07-06 17:03:57 +00:00
|
|
|
bool positioningModified = false;
|
2018-01-18 02:51:48 +00:00
|
|
|
|
2018-07-06 17:03:57 +00:00
|
|
|
if( aField->GetTextPos() != m_position )
|
|
|
|
positioningModified = true;
|
2018-01-18 02:51:48 +00:00
|
|
|
|
2018-07-06 17:03:57 +00:00
|
|
|
if( ( aField->GetTextAngle() == TEXT_ANGLE_VERT ) != m_isVertical )
|
|
|
|
positioningModified = true;
|
2018-01-18 02:51:48 +00:00
|
|
|
|
2019-06-30 22:06:34 +00:00
|
|
|
if( aField->GetHorizJustify() != EDA_TEXT::MapHorizJustify( m_horizontalJustification - 1 ) )
|
2018-07-06 17:03:57 +00:00
|
|
|
positioningModified = true;
|
|
|
|
|
2019-06-30 22:06:34 +00:00
|
|
|
if( aField->GetVertJustify() != EDA_TEXT::MapVertJustify( m_verticalJustification - 1 ) )
|
2018-07-06 17:03:57 +00:00
|
|
|
positioningModified = true;
|
2018-01-18 02:51:48 +00:00
|
|
|
|
2016-04-22 13:29:47 +00:00
|
|
|
aField->SetText( m_text );
|
|
|
|
updateText( aField );
|
2018-01-18 02:51:48 +00:00
|
|
|
|
2018-07-06 17:03:57 +00:00
|
|
|
if( positioningModified )
|
2018-01-18 02:51:48 +00:00
|
|
|
{
|
|
|
|
auto component = static_cast< SCH_COMPONENT* >( aField->GetParent() );
|
|
|
|
component->ClearFieldsAutoplaced();
|
|
|
|
}
|
2016-04-22 13:29:47 +00:00
|
|
|
}
|