2012-02-22 14:04:48 +00:00
|
|
|
/**
|
2012-02-27 23:02:08 +00:00
|
|
|
* @file dialog_edit_one_field.cpp
|
2012-02-22 14:04:48 +00:00
|
|
|
* @brief dialog to editing a field ( not a graphic text) in current component.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2017-10-06 18:07:43 +00:00
|
|
|
* Copyright (C) 2004-2017 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>
|
2012-04-13 18:51:24 +00:00
|
|
|
#include <base_units.h>
|
2014-10-14 20:39:25 +00:00
|
|
|
#include <kiway.h>
|
2016-04-02 12:25:44 +00:00
|
|
|
#include <confirm.h>
|
2012-02-22 14:04:48 +00:00
|
|
|
|
|
|
|
#include <general.h>
|
|
|
|
#include <sch_base_frame.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <class_libentry.h>
|
|
|
|
#include <lib_field.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <template_fieldnames.h>
|
2016-04-02 12:25:44 +00:00
|
|
|
#include <class_library.h>
|
|
|
|
#include <sch_validators.h>
|
2012-02-22 14:04:48 +00:00
|
|
|
|
|
|
|
#include <dialog_edit_one_field.h>
|
|
|
|
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
// These should probably moved into some other file as helpers.
|
|
|
|
EDA_TEXT_HJUSTIFY_T IntToEdaTextHorizJustify( int aHorizJustify )
|
2012-02-22 14:04:48 +00:00
|
|
|
{
|
2016-04-02 12:25:44 +00:00
|
|
|
wxASSERT( aHorizJustify >= GR_TEXT_HJUSTIFY_LEFT && aHorizJustify <= GR_TEXT_HJUSTIFY_RIGHT );
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
if( aHorizJustify > GR_TEXT_HJUSTIFY_RIGHT )
|
|
|
|
return GR_TEXT_HJUSTIFY_RIGHT;
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
if( aHorizJustify < GR_TEXT_HJUSTIFY_LEFT )
|
|
|
|
return GR_TEXT_HJUSTIFY_LEFT;
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
return (EDA_TEXT_HJUSTIFY_T) aHorizJustify;
|
|
|
|
}
|
2012-02-22 14:04:48 +00:00
|
|
|
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
EDA_TEXT_VJUSTIFY_T IntToEdaTextVertJustify( int aVertJustify )
|
|
|
|
{
|
|
|
|
wxASSERT( aVertJustify >= GR_TEXT_VJUSTIFY_TOP && aVertJustify <= GR_TEXT_VJUSTIFY_BOTTOM );
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
if( aVertJustify > GR_TEXT_VJUSTIFY_BOTTOM )
|
|
|
|
return GR_TEXT_VJUSTIFY_BOTTOM;
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
if( aVertJustify < GR_TEXT_VJUSTIFY_TOP )
|
|
|
|
return GR_TEXT_VJUSTIFY_TOP;
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
return (EDA_TEXT_VJUSTIFY_T) aVertJustify;
|
|
|
|
}
|
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 ) :
|
|
|
|
DIALOG_LIB_EDIT_TEXT_BASE( aParent )
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
m_style = aTextItem->IsItalic() ? 1 : 0;
|
|
|
|
m_style += aTextItem->IsBold() ? 2 : 0;
|
2017-01-23 20:30:11 +00:00
|
|
|
m_size = aTextItem->GetTextWidth();
|
|
|
|
m_orientation = ( 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()
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
m_TextValue->SetFocus();
|
2016-08-19 16:42:39 +00:00
|
|
|
SCH_BASE_FRAME* parent = static_cast<SCH_BASE_FRAME*>( GetParent() );
|
|
|
|
m_TextValue->SetValidator( SCH_FIELD_VALIDATOR(
|
|
|
|
parent->IsType( FRAME_SCH_LIB_EDITOR ),
|
|
|
|
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.
|
|
|
|
if( m_fieldId == FOOTPRINT )
|
|
|
|
{
|
|
|
|
m_TextValueSelectButton->Show();
|
|
|
|
m_TextValueSelectButton->Enable();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_TextValueSelectButton->Hide();
|
|
|
|
m_TextValueSelectButton->Disable();
|
2012-02-22 14:04:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msg = m_TextSizeText->GetLabel() + ReturnUnitSymbol();
|
|
|
|
m_TextSizeText->SetLabel( msg );
|
|
|
|
|
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.
|
|
|
|
wxString fpid;
|
|
|
|
|
|
|
|
KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_MODULE_VIEWER_MODAL, true );
|
|
|
|
|
|
|
|
if( frame->ShowModal( &fpid, this ) )
|
|
|
|
{
|
|
|
|
m_TextValue->SetValue( fpid );
|
|
|
|
}
|
|
|
|
|
|
|
|
frame->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
bool DIALOG_EDIT_ONE_FIELD::TransferDataToWindow()
|
2012-02-22 14:04:48 +00:00
|
|
|
{
|
2016-04-02 12:25:44 +00:00
|
|
|
wxLogDebug( "In DIALOG_EDIT_ONE_FIELD::TransferDataToWindow()" );
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
m_TextValue->SetValue( m_text );
|
2017-01-31 18:37:00 +00:00
|
|
|
|
|
|
|
if( m_fieldId == REFERENCE )
|
|
|
|
{
|
|
|
|
if( m_text.find_first_of( '?' ) != m_text.npos )
|
|
|
|
{
|
|
|
|
m_TextValue->SetSelection( m_text.find_first_of( '?' ),
|
|
|
|
m_text.find_last_of( '?' ) + 1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString num = m_text;
|
|
|
|
|
|
|
|
while( !num.IsEmpty() && ( !isdigit( num.Last() ) ||
|
|
|
|
!isdigit( num.GetChar( 0 ) ) ) )
|
|
|
|
{
|
|
|
|
if( !isdigit( num.Last() ) )
|
|
|
|
num.RemoveLast();
|
|
|
|
if( !isdigit( num.GetChar ( 0 ) ) )
|
|
|
|
num = num.Right( num.Length() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_TextValue->SetSelection( m_text.Find( num ),
|
|
|
|
m_text.Find( num ) + num.Length() );
|
|
|
|
|
|
|
|
if( num.IsEmpty() )
|
|
|
|
m_TextValue->SetSelection( -1, -1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_TextValue->SetSelection( -1, -1 );
|
|
|
|
}
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
m_Orient->SetValue( m_orientation );
|
|
|
|
m_TextSize->SetValue( StringFromValue( g_UserUnit, m_size ) );
|
|
|
|
m_TextHJustificationOpt->SetSelection( m_horizontalJustification );
|
|
|
|
m_TextVJustificationOpt->SetSelection( m_verticalJustification );
|
|
|
|
m_Invisible->SetValue( !m_isVisible );
|
|
|
|
m_TextShapeOpt->SetSelection( m_style );
|
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
|
|
|
{
|
2016-04-02 12:25:44 +00:00
|
|
|
wxLogDebug( "In DIALOG_EDIT_ONE_FIELD::TransferDataFromWindow()" );
|
|
|
|
|
|
|
|
m_text = m_TextValue->GetValue();
|
2015-06-04 15:44:56 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
// There are lots of specific tests required to validate field text.
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
m_orientation = m_Orient->GetValue();
|
|
|
|
m_size = ValueFromString( g_UserUnit, m_TextSize->GetValue() );
|
|
|
|
m_horizontalJustification = m_TextHJustificationOpt->GetSelection();
|
|
|
|
m_verticalJustification = m_TextVJustificationOpt->GetSelection();
|
|
|
|
m_isVisible = !m_Invisible->GetValue();
|
|
|
|
m_style = m_TextShapeOpt->GetSelection();
|
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
|
|
|
{
|
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 );
|
2017-01-23 20:30:11 +00:00
|
|
|
aText->SetTextAngle( m_orientation ? TEXT_ANGLE_VERT : TEXT_ANGLE_HORIZ );
|
2016-04-02 12:25:44 +00:00
|
|
|
aText->SetItalic( (m_style & 1) != 0 );
|
|
|
|
aText->SetBold( (m_style & 2) != 0 );
|
|
|
|
aText->SetHorizJustify( IntToEdaTextHorizJustify( m_horizontalJustification - 1 ) );
|
|
|
|
aText->SetVertJustify( IntToEdaTextVertJustify( m_verticalJustification - 1 ) );
|
2012-02-22 14:04:48 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:39:25 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
DIALOG_LIB_EDIT_ONE_FIELD::DIALOG_LIB_EDIT_ONE_FIELD( SCH_BASE_FRAME* aParent,
|
|
|
|
const wxString& aTitle,
|
|
|
|
const LIB_FIELD* aField ) :
|
|
|
|
DIALOG_EDIT_ONE_FIELD( aParent, aTitle, dynamic_cast< const EDA_TEXT* >( 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
DIALOG_SCH_EDIT_ONE_FIELD::DIALOG_SCH_EDIT_ONE_FIELD( SCH_BASE_FRAME* aParent,
|
|
|
|
const wxString& aTitle,
|
|
|
|
const SCH_FIELD* aField ) :
|
|
|
|
DIALOG_EDIT_ONE_FIELD( aParent, aTitle, dynamic_cast< const EDA_TEXT* >( 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
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
wxASSERT_MSG( component != NULL && component->Type() == SCH_COMPONENT_T,
|
|
|
|
wxT( "Invalid schematic field parent item." ) );
|
2012-02-22 14:04:48 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
const LIB_PART* part = GetParent()->GetLibPart( component->GetLibId() );
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
wxASSERT_MSG( part, wxT( "Library part for component <" ) +
|
2017-07-24 19:02:59 +00:00
|
|
|
component->GetLibId().Format() + wxT( "> could not be found." ) );
|
2015-12-13 16:56:47 +00:00
|
|
|
|
2016-04-02 12:25:44 +00:00
|
|
|
m_isPower = part->IsPower();
|
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 )
|
|
|
|
{
|
|
|
|
wxASSERT( aField != NULL || aField->Type() != SCH_FIELD_T );
|
|
|
|
|
|
|
|
if( aField->GetId() == REFERENCE )
|
|
|
|
{
|
|
|
|
wxASSERT( aSheetPath != NULL );
|
|
|
|
|
|
|
|
SCH_COMPONENT* component = dynamic_cast< SCH_COMPONENT* >( aField->GetParent() );
|
|
|
|
|
|
|
|
wxASSERT( component != NULL );
|
|
|
|
|
|
|
|
if( component != NULL )
|
|
|
|
component->SetRef( aSheetPath, m_text );
|
|
|
|
}
|
|
|
|
|
|
|
|
aField->SetText( m_text );
|
|
|
|
updateText( aField );
|
|
|
|
}
|