2014-10-21 15:48:00 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Wayne Stambaugh <stambaughw@verizon.net>
|
2019-02-07 18:03:38 +00:00
|
|
|
* Copyright (C) 2018-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-10-21 15:48:00 +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
|
|
|
|
*/
|
|
|
|
|
2018-02-02 15:56:09 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <sch_sheet.h>
|
2019-05-21 02:52:39 +00:00
|
|
|
#include <sch_validators.h>
|
2020-10-29 22:46:33 +00:00
|
|
|
#include <dialog_sheet_pin_properties.h>
|
2020-10-25 13:14:52 +00:00
|
|
|
#include <dialogs/html_messagebox.h>
|
2020-10-14 11:03:58 +00:00
|
|
|
#include <kicad_string.h>
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
static wxString sheetPinTypes[] =
|
|
|
|
{
|
|
|
|
_( "Input" ),
|
|
|
|
_( "Output" ),
|
|
|
|
_( "Bidirectional" ),
|
|
|
|
_( "Tri-state" ),
|
|
|
|
_( "Passive" )
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-10-29 22:46:33 +00:00
|
|
|
DIALOG_SHEET_PIN_PROPERTIES::DIALOG_SHEET_PIN_PROPERTIES( SCH_EDIT_FRAME* parent, SCH_SHEET_PIN* aPin ) :
|
|
|
|
DIALOG_SHEET_PIN_PROPERTIES_BASE( parent ),
|
2018-02-02 15:56:09 +00:00
|
|
|
m_frame( parent ),
|
|
|
|
m_sheetPin( aPin ),
|
2020-09-05 16:00:29 +00:00
|
|
|
m_textSize( parent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true ),
|
|
|
|
m_helpWindow( nullptr )
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
2018-02-02 15:56:09 +00:00
|
|
|
for( const wxString& sheetPinType : sheetPinTypes )
|
|
|
|
m_choiceConnectionType->Append( sheetPinType );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
m_choiceConnectionType->SetSelection( 0 );
|
2020-05-20 17:31:19 +00:00
|
|
|
SetInitialFocus( m_comboName );
|
2015-03-15 11:41:06 +00:00
|
|
|
m_sdbSizerOK->SetDefault();
|
|
|
|
|
2018-02-19 17:07:57 +00:00
|
|
|
// Set invalid label characters list:
|
2020-11-15 20:20:37 +00:00
|
|
|
SCH_NETNAME_VALIDATOR validator( true );
|
2020-05-20 17:31:19 +00:00
|
|
|
m_comboName->SetValidator( validator );
|
2018-02-19 17:07:57 +00:00
|
|
|
|
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();
|
2016-07-16 10:54:55 +00:00
|
|
|
|
2018-02-02 15:56:09 +00:00
|
|
|
/* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier versions for
|
|
|
|
* the flex grid sizer in wxGTK that prevents the last column from being sized
|
|
|
|
* correctly. It doesn't cause any problems on win32 so it doesn't need to wrapped
|
|
|
|
* in ugly #ifdef __WXGTK__ #endif.
|
|
|
|
*/
|
|
|
|
Layout();
|
|
|
|
Fit();
|
|
|
|
SetMinSize( GetSize() );
|
|
|
|
|
2015-03-15 11:41:06 +00:00
|
|
|
// On some windows manager (Unity, XFCE), this dialog is
|
|
|
|
// not always raised, depending on this dialog is run.
|
|
|
|
// Force it to be raised
|
|
|
|
Raise();
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
2018-02-19 17:07:57 +00:00
|
|
|
|
|
|
|
|
2020-10-29 22:46:33 +00:00
|
|
|
DIALOG_SHEET_PIN_PROPERTIES::~DIALOG_SHEET_PIN_PROPERTIES()
|
2020-09-05 16:00:29 +00:00
|
|
|
{
|
|
|
|
if( m_helpWindow )
|
|
|
|
m_helpWindow->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-29 22:46:33 +00:00
|
|
|
bool DIALOG_SHEET_PIN_PROPERTIES::TransferDataToWindow()
|
2018-02-02 15:56:09 +00:00
|
|
|
{
|
2020-05-20 17:31:19 +00:00
|
|
|
SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
|
|
|
|
{
|
2021-01-19 22:05:45 +00:00
|
|
|
wxString txt = static_cast<SCH_HIERLABEL*>( item )->GetText();
|
|
|
|
|
|
|
|
if( m_comboName->FindString( txt, true ) == wxNOT_FOUND )
|
|
|
|
m_comboName->Append( txt );
|
2020-05-20 17:31:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_comboName->SetValue( UnescapeString( m_sheetPin->GetText() ) );
|
|
|
|
m_comboName->SelectAll();
|
2020-04-30 08:33:02 +00:00
|
|
|
// Currently, eeschema uses only the text width as text size
|
|
|
|
// (only the text width is saved in files), and expects text width = text height
|
|
|
|
m_textSize.SetValue( m_sheetPin->GetTextWidth() );
|
2020-01-08 19:07:55 +00:00
|
|
|
m_choiceConnectionType->SetSelection( static_cast<int>( m_sheetPin->GetShape() ) );
|
2018-02-02 15:56:09 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-29 22:46:33 +00:00
|
|
|
bool DIALOG_SHEET_PIN_PROPERTIES::TransferDataFromWindow()
|
2018-02-02 15:56:09 +00:00
|
|
|
{
|
|
|
|
if( !m_sheetPin->IsNew() )
|
2020-07-13 11:21:40 +00:00
|
|
|
{
|
|
|
|
SCH_SHEET* parentSheet = m_sheetPin->GetParent();
|
2020-08-26 18:04:32 +00:00
|
|
|
m_frame->SaveCopyInUndoList( m_frame->GetScreen(), parentSheet, UNDO_REDO::CHANGED, false );
|
2020-07-13 11:21:40 +00:00
|
|
|
}
|
2018-02-02 15:56:09 +00:00
|
|
|
|
2020-05-20 17:31:19 +00:00
|
|
|
m_sheetPin->SetText( EscapeString( m_comboName->GetValue(), CTX_NETNAME ) );
|
2020-04-30 08:33:02 +00:00
|
|
|
// Currently, eeschema uses only the text width as text size,
|
|
|
|
// and expects text width = text height
|
|
|
|
m_sheetPin->SetTextSize( wxSize( m_textSize.GetValue(), m_textSize.GetValue() ) );
|
2018-02-02 15:56:09 +00:00
|
|
|
|
|
|
|
auto shape = static_cast<PINSHEETLABEL_SHAPE>( m_choiceConnectionType->GetCurrentSelection() );
|
|
|
|
m_sheetPin->SetShape( shape );
|
|
|
|
|
2020-08-10 11:40:58 +00:00
|
|
|
m_frame->UpdateItem( m_sheetPin );
|
2018-10-18 09:50:43 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
2018-02-02 15:56:09 +00:00
|
|
|
m_frame->OnModify();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-19 17:07:57 +00:00
|
|
|
|
2020-10-29 22:46:33 +00:00
|
|
|
void DIALOG_SHEET_PIN_PROPERTIES::onOKButton( wxCommandEvent& event )
|
2018-02-19 17:07:57 +00:00
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
}
|
2020-05-09 20:27:06 +00:00
|
|
|
|
|
|
|
|
2020-10-29 22:46:33 +00:00
|
|
|
void DIALOG_SHEET_PIN_PROPERTIES::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
|
2020-05-09 20:27:06 +00:00
|
|
|
{
|
2020-09-05 16:00:29 +00:00
|
|
|
m_helpWindow = SCH_TEXT::ShowSyntaxHelp( this );
|
2020-05-09 20:27:06 +00:00
|
|
|
}
|
2020-05-20 17:31:19 +00:00
|
|
|
|
|
|
|
|
2020-10-29 22:46:33 +00:00
|
|
|
void DIALOG_SHEET_PIN_PROPERTIES::onComboBox( wxCommandEvent& aEvent )
|
2020-05-20 17:31:19 +00:00
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = m_sheetPin->GetParent()->GetScreen();
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : screen->Items().OfType( SCH_HIER_LABEL_T ) )
|
|
|
|
{
|
|
|
|
auto hierLabelItem = static_cast<SCH_HIERLABEL*>( item );
|
|
|
|
|
|
|
|
if( m_comboName->GetValue().CmpNoCase( hierLabelItem->GetText() ) == 0 )
|
|
|
|
{
|
|
|
|
m_choiceConnectionType->SetSelection( static_cast<int>( hierLabelItem->GetShape() ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|