2014-10-21 11:48:00 -04:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-01-23 15:45:51 -05:00
|
|
|
* Copyright (C) 2009 Wayne Stambaugh <stambaughw@gmail.com>
|
2023-09-05 22:07:51 +01:00
|
|
|
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-10-21 11:48:00 -04: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
|
|
|
|
*/
|
|
|
|
|
2024-10-27 04:09:21 +08:00
|
|
|
#include "dialog_lib_new_symbol.h"
|
|
|
|
|
2020-10-06 14:25:37 -07:00
|
|
|
#include <default_values.h>
|
|
|
|
#include <eda_draw_frame.h>
|
2024-12-18 22:43:55 +08:00
|
|
|
#include <lib_symbol_library_manager.h>
|
2016-08-19 18:42:39 +02:00
|
|
|
#include <sch_validators.h>
|
|
|
|
#include <template_fieldnames.h>
|
2013-05-25 23:36:44 -05:00
|
|
|
|
2024-10-27 04:09:21 +08:00
|
|
|
|
2024-12-18 22:43:55 +08:00
|
|
|
DIALOG_LIB_NEW_SYMBOL::DIALOG_LIB_NEW_SYMBOL( EDA_DRAW_FRAME* aParent,
|
|
|
|
const wxString& aLibName,
|
|
|
|
LIB_SYMBOL_LIBRARY_MANAGER& aLibManager,
|
2023-09-05 22:07:51 +01:00
|
|
|
const wxString& aInheritFromSymbolName,
|
|
|
|
std::function<bool( wxString newName )> aValidator ) :
|
2024-12-18 22:43:55 +08:00
|
|
|
DIALOG_LIB_NEW_SYMBOL_BASE( dynamic_cast<wxWindow*>( aParent ) ), m_libManager( aLibManager ),
|
2023-09-05 22:07:51 +01:00
|
|
|
m_pinTextPosition( aParent, m_staticPinTextPositionLabel, m_textPinTextPosition,
|
|
|
|
m_staticPinTextPositionUnits, true ),
|
|
|
|
m_validator( std::move( aValidator ) )
|
2013-05-25 23:36:44 -05:00
|
|
|
{
|
2024-12-18 22:43:55 +08:00
|
|
|
wxArrayString symbolNames;
|
|
|
|
m_libManager.GetSymbolNames( aLibName, symbolNames );
|
|
|
|
|
|
|
|
if( symbolNames.GetCount() )
|
2021-07-28 18:36:13 +01:00
|
|
|
{
|
|
|
|
wxArrayString escapedNames;
|
|
|
|
|
2024-12-18 22:43:55 +08:00
|
|
|
for( const wxString& name : symbolNames )
|
2021-07-28 18:36:13 +01:00
|
|
|
escapedNames.Add( UnescapeString( name ) );
|
|
|
|
|
2024-10-27 04:09:21 +08:00
|
|
|
m_comboInheritanceSelect->SetSymbolList( escapedNames );
|
2023-02-22 01:49:46 +00:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
if( !aInheritFromSymbolName.IsEmpty() )
|
2023-02-22 01:49:46 +00:00
|
|
|
{
|
2024-10-27 04:09:21 +08:00
|
|
|
m_comboInheritanceSelect->SetSelectedSymbol( aInheritFromSymbolName );
|
2023-02-22 01:49:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-18 22:43:55 +08:00
|
|
|
// Trigger the event handler to show/hide the info bar message.
|
|
|
|
wxCommandEvent dummyEvent;
|
|
|
|
onParentSymbolSelect( dummyEvent );
|
2019-11-06 14:15:42 -05:00
|
|
|
|
2023-06-13 11:06:30 -04:00
|
|
|
m_textName->SetValidator( FIELD_VALIDATOR( VALUE_FIELD ) );
|
|
|
|
m_textReference->SetValidator( FIELD_VALIDATOR( REFERENCE_FIELD ) );
|
2016-08-19 18:42:39 +02:00
|
|
|
|
2022-09-16 19:42:20 -04:00
|
|
|
m_pinTextPosition.SetValue( schIUScale.MilsToIU( DEFAULT_PIN_NAME_OFFSET ) );
|
2020-01-23 15:45:51 -05:00
|
|
|
|
2024-10-27 04:09:21 +08:00
|
|
|
m_comboInheritanceSelect->Connect(
|
|
|
|
FILTERED_ITEM_SELECTED,
|
|
|
|
wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect ), nullptr, this );
|
|
|
|
|
2013-12-07 22:46:25 -06:00
|
|
|
// initial focus should be on first editable field.
|
|
|
|
m_textName->SetFocus();
|
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
2016-07-18 09:04:13 +02:00
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2013-05-25 23:36:44 -05:00
|
|
|
}
|
2019-11-06 14:15:42 -05:00
|
|
|
|
|
|
|
|
2024-10-27 04:09:21 +08:00
|
|
|
DIALOG_LIB_NEW_SYMBOL::~DIALOG_LIB_NEW_SYMBOL()
|
|
|
|
{
|
|
|
|
m_comboInheritanceSelect->Disconnect(
|
|
|
|
FILTERED_ITEM_SELECTED,
|
|
|
|
wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect ), nullptr, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
bool DIALOG_LIB_NEW_SYMBOL::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
return m_validator( GetName() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-10-27 04:09:21 +08:00
|
|
|
void DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect( wxCommandEvent& aEvent )
|
2019-11-06 14:15:42 -05:00
|
|
|
{
|
2024-12-18 22:43:55 +08:00
|
|
|
const wxString parent = m_comboInheritanceSelect->GetValue();
|
|
|
|
|
|
|
|
if( !parent.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_infoBar->RemoveAllButtons();
|
|
|
|
m_infoBar->ShowMessage( wxString::Format( _( "Deriving from symbol '%s'." ), parent ),
|
|
|
|
wxICON_INFORMATION );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_infoBar->Dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
syncControls( !parent.IsEmpty() );
|
2019-11-06 14:15:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-14 14:00:08 -04:00
|
|
|
void DIALOG_LIB_NEW_SYMBOL::syncControls( bool aIsDerivedPart )
|
2019-11-06 14:15:42 -05:00
|
|
|
{
|
|
|
|
m_staticTextDes->Enable( !aIsDerivedPart );
|
|
|
|
m_textReference->Enable( !aIsDerivedPart );
|
|
|
|
m_staticTextUnits->Enable( !aIsDerivedPart );
|
|
|
|
m_spinPartCount->Enable( !aIsDerivedPart );
|
2022-02-06 13:23:08 +00:00
|
|
|
m_checkUnitsInterchangeable->Enable( !aIsDerivedPart );
|
2024-01-26 17:29:26 +00:00
|
|
|
m_checkHasAlternateBodyStyle->Enable( !aIsDerivedPart );
|
2019-11-06 14:15:42 -05:00
|
|
|
m_checkIsPowerSymbol->Enable( !aIsDerivedPart );
|
2020-09-09 09:03:37 -04:00
|
|
|
m_excludeFromBomCheckBox->Enable( !aIsDerivedPart );
|
|
|
|
m_excludeFromBoardCheckBox->Enable( !aIsDerivedPart );
|
2020-01-23 15:45:51 -05:00
|
|
|
m_staticPinTextPositionLabel->Enable( !aIsDerivedPart );
|
|
|
|
m_textPinTextPosition->Enable( !aIsDerivedPart );
|
|
|
|
m_staticPinTextPositionUnits->Enable( !aIsDerivedPart );
|
2019-11-06 14:15:42 -05:00
|
|
|
m_checkShowPinNumber->Enable( !aIsDerivedPart );
|
|
|
|
m_checkShowPinName->Enable( !aIsDerivedPart );
|
|
|
|
m_checkShowPinNameInside->Enable( !aIsDerivedPart );
|
|
|
|
}
|
2020-09-09 09:03:37 -04:00
|
|
|
|
|
|
|
|
2021-06-14 14:00:08 -04:00
|
|
|
void DIALOG_LIB_NEW_SYMBOL::onPowerCheckBox( wxCommandEvent& aEvent )
|
2020-09-09 09:03:37 -04:00
|
|
|
{
|
|
|
|
if( m_checkIsPowerSymbol->IsChecked() )
|
|
|
|
{
|
|
|
|
m_excludeFromBomCheckBox->SetValue( true );
|
|
|
|
m_excludeFromBoardCheckBox->SetValue( true );
|
|
|
|
m_excludeFromBomCheckBox->Enable( false );
|
|
|
|
m_excludeFromBoardCheckBox->Enable( false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_excludeFromBomCheckBox->Enable( true );
|
|
|
|
m_excludeFromBoardCheckBox->Enable( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|