2013-03-30 00:06:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-06-08 00:04:11 +00:00
|
|
|
* Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-03-30 00:06:08 +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
|
|
|
|
*/
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
#include "dialog_symbol_properties.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2022-01-27 00:04:45 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2021-03-07 20:31:19 +00:00
|
|
|
#include <bitmaps.h>
|
2008-11-24 06:53:43 +00:00
|
|
|
#include <wx/tooltip.h>
|
2020-09-02 11:50:07 +00:00
|
|
|
#include <grid_tricks.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2021-07-28 18:50:17 +00:00
|
|
|
#include <pin_numbers.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2021-12-16 14:39:58 +00:00
|
|
|
#include <kiplatform/ui.h>
|
2020-09-02 11:50:07 +00:00
|
|
|
#include <widgets/grid_icon_text_helpers.h>
|
2021-01-28 11:15:47 +00:00
|
|
|
#include <widgets/grid_combobox.h>
|
2022-12-13 20:47:28 +00:00
|
|
|
#include <widgets/std_bitmap_button.h>
|
2020-05-23 15:50:08 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2020-03-30 13:14:44 +00:00
|
|
|
#include <ee_collectors.h>
|
2021-06-15 13:24:55 +00:00
|
|
|
#include <symbol_library.h>
|
2018-02-28 16:54:35 +00:00
|
|
|
#include <fields_grid_table.h>
|
2019-02-20 23:20:06 +00:00
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <sch_reference_list.h>
|
2020-05-24 14:55:37 +00:00
|
|
|
#include <schematic.h>
|
2023-06-09 21:41:33 +00:00
|
|
|
#include <sch_commit.h>
|
2020-08-13 21:30:30 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tool/actions.h>
|
2017-10-06 18:07:43 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
#include <dialog_sim_model.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2022-01-27 00:04:45 +00:00
|
|
|
wxDEFINE_EVENT( SYMBOL_DELAY_FOCUS, wxCommandEvent );
|
|
|
|
wxDEFINE_EVENT( SYMBOL_DELAY_SELECTION, wxCommandEvent );
|
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
enum PIN_TABLE_COL_ORDER
|
|
|
|
{
|
|
|
|
COL_NUMBER,
|
|
|
|
COL_BASE_NAME,
|
|
|
|
COL_ALT_NAME,
|
|
|
|
COL_TYPE,
|
|
|
|
COL_SHAPE,
|
|
|
|
|
|
|
|
COL_COUNT // keep as last
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SCH_PIN_TABLE_DATA_MODEL : public wxGridTableBase, public std::vector<SCH_PIN>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SCH_PIN_TABLE_DATA_MODEL() :
|
|
|
|
m_readOnlyAttr( nullptr ),
|
|
|
|
m_typeAttr( nullptr ),
|
|
|
|
m_shapeAttr( nullptr )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~SCH_PIN_TABLE_DATA_MODEL()
|
|
|
|
{
|
|
|
|
for( wxGridCellAttr* attr : m_nameAttrs )
|
|
|
|
attr->DecRef();
|
|
|
|
|
|
|
|
m_readOnlyAttr->DecRef();
|
|
|
|
m_typeAttr->DecRef();
|
|
|
|
m_shapeAttr->DecRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BuildAttrs()
|
|
|
|
{
|
2022-06-08 12:48:19 +00:00
|
|
|
for( wxGridCellAttr* attr : m_nameAttrs )
|
|
|
|
attr->DecRef();
|
|
|
|
|
|
|
|
m_nameAttrs.clear();
|
|
|
|
|
|
|
|
if( m_readOnlyAttr )
|
|
|
|
m_readOnlyAttr->DecRef();
|
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
m_readOnlyAttr = new wxGridCellAttr;
|
|
|
|
m_readOnlyAttr->SetReadOnly( true );
|
|
|
|
|
|
|
|
for( const SCH_PIN& pin : *this )
|
|
|
|
{
|
|
|
|
LIB_PIN* lib_pin = pin.GetLibPin();
|
|
|
|
wxGridCellAttr* attr = nullptr;
|
|
|
|
|
|
|
|
if( lib_pin->GetAlternates().empty() )
|
|
|
|
{
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetReadOnly( true );
|
2023-09-03 14:33:55 +00:00
|
|
|
attr->SetBackgroundColour( KIPLATFORM::UI::GetDialogBGColour() );
|
2020-09-02 11:50:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxArrayString choices;
|
|
|
|
choices.push_back( lib_pin->GetName() );
|
|
|
|
|
|
|
|
for( const std::pair<const wxString, LIB_PIN::ALT>& alt : lib_pin->GetAlternates() )
|
|
|
|
choices.push_back( alt.first );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr();
|
2021-01-28 11:15:47 +00:00
|
|
|
attr->SetEditor( new GRID_CELL_COMBOBOX( choices ) );
|
2020-09-02 11:50:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_nameAttrs.push_back( attr );
|
|
|
|
}
|
|
|
|
|
2022-06-08 12:48:19 +00:00
|
|
|
if( m_typeAttr )
|
|
|
|
m_typeAttr->DecRef();
|
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
m_typeAttr = new wxGridCellAttr;
|
2021-05-06 11:13:08 +00:00
|
|
|
m_typeAttr->SetRenderer( new GRID_CELL_ICON_TEXT_RENDERER( PinTypeIcons(),
|
|
|
|
PinTypeNames() ) );
|
2020-09-02 11:50:07 +00:00
|
|
|
m_typeAttr->SetReadOnly( true );
|
|
|
|
|
2022-06-08 12:48:19 +00:00
|
|
|
if( m_shapeAttr )
|
|
|
|
m_shapeAttr->DecRef();
|
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
m_shapeAttr = new wxGridCellAttr;
|
2021-05-06 11:13:08 +00:00
|
|
|
m_shapeAttr->SetRenderer( new GRID_CELL_ICON_TEXT_RENDERER( PinShapeIcons(),
|
|
|
|
PinShapeNames() ) );
|
2020-09-02 11:50:07 +00:00
|
|
|
m_shapeAttr->SetReadOnly( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetNumberRows() override { return (int) size(); }
|
|
|
|
int GetNumberCols() override { return COL_COUNT; }
|
|
|
|
|
|
|
|
wxString GetColLabelValue( int aCol ) override
|
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case COL_NUMBER: return _( "Number" );
|
|
|
|
case COL_BASE_NAME: return _( "Base Name" );
|
|
|
|
case COL_ALT_NAME: return _( "Alternate Assignment" );
|
|
|
|
case COL_TYPE: return _( "Electrical Type" );
|
|
|
|
case COL_SHAPE: return _( "Graphic Style" );
|
|
|
|
default: wxFAIL; return wxEmptyString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsEmptyCell( int row, int col ) override
|
|
|
|
{
|
|
|
|
return false; // don't allow adjacent cell overflow, even if we are actually empty
|
|
|
|
}
|
|
|
|
|
2023-11-03 18:48:19 +00:00
|
|
|
bool CanSetValueAs( int aRow, int aCol, const wxString& aTypeName ) override
|
|
|
|
{
|
|
|
|
// Don't accept random values; must use the popup to change to a known alternate
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
wxString GetValue( int aRow, int aCol ) override
|
|
|
|
{
|
|
|
|
return GetValue( at( aRow ), aCol );
|
|
|
|
}
|
|
|
|
|
|
|
|
static wxString GetValue( const SCH_PIN& aPin, int aCol )
|
|
|
|
{
|
2023-09-03 14:33:55 +00:00
|
|
|
if( aCol == COL_ALT_NAME )
|
|
|
|
{
|
|
|
|
if( aPin.GetLibPin()->GetAlternates().empty() )
|
|
|
|
return wxEmptyString;
|
|
|
|
else if( aPin.GetAlt().IsEmpty() )
|
|
|
|
return aPin.GetName();
|
|
|
|
else
|
|
|
|
return aPin.GetAlt();
|
|
|
|
}
|
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case COL_NUMBER: return aPin.GetNumber();
|
|
|
|
case COL_BASE_NAME: return aPin.GetLibPin()->GetName();
|
|
|
|
case COL_TYPE: return PinTypeNames()[static_cast<int>( aPin.GetType() )];
|
|
|
|
case COL_SHAPE: return PinShapeNames()[static_cast<int>( aPin.GetShape() )];
|
|
|
|
default: wxFAIL; return wxEmptyString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-11 16:37:25 +00:00
|
|
|
wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind ) override
|
2020-09-02 11:50:07 +00:00
|
|
|
{
|
2024-04-11 16:37:25 +00:00
|
|
|
// This is needed to support alternating row colors
|
|
|
|
auto enhanceAttr = [this, &aRow, &aCol,
|
|
|
|
&aKind]( wxGridCellAttr* aInputAttr ) -> wxGridCellAttr*
|
|
|
|
{
|
|
|
|
if( aInputAttr == nullptr )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
wxGridCellAttr* attr = aInputAttr;
|
|
|
|
|
|
|
|
if( wxGridCellAttrProvider* provider = GetAttrProvider() )
|
|
|
|
{
|
|
|
|
wxGridCellAttr* providerAttr = provider->GetAttr( aRow, aCol, aKind );
|
|
|
|
|
|
|
|
if( providerAttr )
|
|
|
|
{
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetKind( wxGridCellAttr::Merged );
|
|
|
|
|
|
|
|
attr->MergeWith( aInputAttr );
|
|
|
|
aInputAttr->DecRef();
|
|
|
|
|
|
|
|
attr->MergeWith( providerAttr );
|
|
|
|
providerAttr->DecRef();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return attr;
|
|
|
|
};
|
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case COL_NUMBER:
|
|
|
|
case COL_BASE_NAME:
|
|
|
|
m_readOnlyAttr->IncRef();
|
2024-04-11 16:37:25 +00:00
|
|
|
return enhanceAttr( m_readOnlyAttr );
|
2020-09-02 11:50:07 +00:00
|
|
|
|
|
|
|
case COL_ALT_NAME:
|
|
|
|
m_nameAttrs[ aRow ]->IncRef();
|
2024-04-11 16:37:25 +00:00
|
|
|
return enhanceAttr( m_nameAttrs[ aRow ] );
|
2020-09-02 11:50:07 +00:00
|
|
|
|
|
|
|
case COL_TYPE:
|
|
|
|
m_typeAttr->IncRef();
|
2024-04-11 16:37:25 +00:00
|
|
|
return enhanceAttr( m_typeAttr );
|
2020-09-02 11:50:07 +00:00
|
|
|
|
|
|
|
case COL_SHAPE:
|
|
|
|
m_shapeAttr->IncRef();
|
2024-04-11 16:37:25 +00:00
|
|
|
return enhanceAttr( m_shapeAttr );
|
2020-09-02 11:50:07 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetValue( int aRow, int aCol, const wxString &aValue ) override
|
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case COL_ALT_NAME:
|
2021-01-28 11:15:47 +00:00
|
|
|
if( aValue == at( aRow ).GetLibPin()->GetName() )
|
2020-09-02 11:50:07 +00:00
|
|
|
at( aRow ).SetAlt( wxEmptyString );
|
|
|
|
else
|
|
|
|
at( aRow ).SetAlt( aValue );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_NUMBER:
|
|
|
|
case COL_BASE_NAME:
|
|
|
|
case COL_TYPE:
|
|
|
|
case COL_SHAPE:
|
|
|
|
// Read-only.
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool compare( const SCH_PIN& lhs, const SCH_PIN& rhs, int sortCol, bool ascending )
|
|
|
|
{
|
|
|
|
wxString lhStr = GetValue( lhs, sortCol );
|
|
|
|
wxString rhStr = GetValue( rhs, sortCol );
|
|
|
|
|
|
|
|
if( lhStr == rhStr )
|
|
|
|
{
|
|
|
|
// Secondary sort key is always COL_NUMBER
|
|
|
|
sortCol = COL_NUMBER;
|
|
|
|
lhStr = GetValue( lhs, sortCol );
|
|
|
|
rhStr = GetValue( rhs, sortCol );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool res;
|
|
|
|
|
|
|
|
// N.B. To meet the iterator sort conditions, we cannot simply invert the truth
|
|
|
|
// to get the opposite sort. i.e. ~(a<b) != (a>b)
|
|
|
|
auto cmp = [ ascending ]( const auto a, const auto b )
|
|
|
|
{
|
|
|
|
if( ascending )
|
|
|
|
return a < b;
|
|
|
|
else
|
|
|
|
return b < a;
|
|
|
|
};
|
|
|
|
|
|
|
|
switch( sortCol )
|
|
|
|
{
|
|
|
|
case COL_NUMBER:
|
|
|
|
case COL_BASE_NAME:
|
|
|
|
case COL_ALT_NAME:
|
2021-07-28 18:50:17 +00:00
|
|
|
res = cmp( PIN_NUMBERS::Compare( lhStr, rhStr ), 0 );
|
2020-09-02 11:50:07 +00:00
|
|
|
break;
|
|
|
|
case COL_TYPE:
|
|
|
|
case COL_SHAPE:
|
|
|
|
res = cmp( lhStr.CmpNoCase( rhStr ), 0 );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = cmp( StrNumCmp( lhStr, rhStr ), 0 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SortRows( int aSortCol, bool ascending )
|
|
|
|
{
|
|
|
|
std::sort( begin(), end(),
|
|
|
|
[ aSortCol, ascending ]( const SCH_PIN& lhs, const SCH_PIN& rhs ) -> bool
|
|
|
|
{
|
|
|
|
return compare( lhs, rhs, aSortCol, ascending );
|
|
|
|
} );
|
|
|
|
}
|
2023-10-17 12:07:15 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<wxGridCellAttr*> m_nameAttrs;
|
|
|
|
wxGridCellAttr* m_readOnlyAttr;
|
|
|
|
wxGridCellAttr* m_typeAttr;
|
|
|
|
wxGridCellAttr* m_shapeAttr;
|
2020-09-02 11:50:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES( SCH_EDIT_FRAME* aParent,
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* aSymbol ) :
|
2020-10-20 21:26:00 +00:00
|
|
|
DIALOG_SYMBOL_PROPERTIES_BASE( aParent ),
|
2021-06-10 14:10:55 +00:00
|
|
|
m_symbol( nullptr ),
|
2020-10-20 21:26:00 +00:00
|
|
|
m_part( nullptr ),
|
2022-10-11 23:38:01 +00:00
|
|
|
m_fieldsSize( 0, 0 ),
|
2023-12-14 12:23:50 +00:00
|
|
|
m_lastRequestedFieldsSize( 0, 0 ),
|
|
|
|
m_lastRequestedPinsSize( 0, 0 ),
|
2022-10-11 23:38:01 +00:00
|
|
|
m_editorShown( false ),
|
2020-10-20 21:26:00 +00:00
|
|
|
m_fields( nullptr ),
|
|
|
|
m_dataModel( nullptr )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
m_symbol = aSymbol;
|
2021-06-15 12:31:28 +00:00
|
|
|
m_part = m_symbol->GetLibSymbolRef().get();
|
2020-09-03 11:47:51 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
// GetLibSymbolRef() now points to the cached part in the schematic, which should always be
|
2020-12-03 09:42:31 +00:00
|
|
|
// there for usual cases, but can be null when opening old schematics not storing the part
|
|
|
|
// so we need to handle m_part == nullptr
|
2021-07-28 15:39:40 +00:00
|
|
|
// wxASSERT( m_part );
|
2020-09-03 11:47:51 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
m_fields = new FIELDS_GRID_TABLE( this, aParent, m_fieldsGrid, m_symbol );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
// Give a bit more room for combobox editors
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->SetDefaultRowSize( m_fieldsGrid->GetDefaultRowSize() + 4 );
|
|
|
|
m_pinGrid->SetDefaultRowSize( m_pinGrid->GetDefaultRowSize() + 4 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->SetTable( m_fields );
|
2023-03-02 17:50:39 +00:00
|
|
|
m_fieldsGrid->PushEventHandler( new FIELDS_GRID_TRICKS( m_fieldsGrid, this,
|
|
|
|
[&]( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
OnAddField( aEvent );
|
|
|
|
} ) );
|
2021-12-12 17:27:40 +00:00
|
|
|
m_fieldsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Show/hide columns according to user's preference
|
2023-04-13 12:45:22 +00:00
|
|
|
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
|
2020-05-04 12:01:35 +00:00
|
|
|
{
|
2023-04-13 12:45:22 +00:00
|
|
|
m_fieldsGrid->ShowHideColumns( cfg->m_Appearance.edit_symbol_visible_columns );
|
|
|
|
m_shownColumns = m_fieldsGrid->GetShownColumns();
|
2020-05-04 12:01:35 +00:00
|
|
|
}
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
if( m_part && m_part->HasAlternateBodyStyle() )
|
2020-10-20 21:26:00 +00:00
|
|
|
{
|
|
|
|
// DeMorgan conversions are a subclass of alternate pin assignments, so don't allow
|
|
|
|
// free-form alternate assignments as well. (We won't know how to map the alternates
|
|
|
|
// back and forth when the conversion is changed.)
|
2021-01-04 23:56:50 +00:00
|
|
|
m_pinTablePage->Disable();
|
2021-10-29 19:27:24 +00:00
|
|
|
m_pinTablePage->SetToolTip( _( "Alternate pin assignments are not available for De Morgan "
|
2021-07-28 15:39:40 +00:00
|
|
|
"symbols." ) );
|
2020-10-20 21:26:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_dataModel = new SCH_PIN_TABLE_DATA_MODEL();
|
|
|
|
|
|
|
|
// Make a copy of the pins for editing
|
2021-06-10 14:10:55 +00:00
|
|
|
for( const std::unique_ptr<SCH_PIN>& pin : m_symbol->GetRawPins() )
|
2020-10-20 21:26:00 +00:00
|
|
|
m_dataModel->push_back( *pin );
|
2020-09-02 11:50:07 +00:00
|
|
|
|
2020-10-20 21:26:00 +00:00
|
|
|
m_dataModel->SortRows( COL_NUMBER, true );
|
|
|
|
m_dataModel->BuildAttrs();
|
2020-09-02 11:50:07 +00:00
|
|
|
|
2020-10-20 21:26:00 +00:00
|
|
|
m_pinGrid->SetTable( m_dataModel );
|
|
|
|
}
|
2020-09-02 11:50:07 +00:00
|
|
|
|
2023-04-14 18:40:41 +00:00
|
|
|
if( m_part && m_part->IsPower() )
|
|
|
|
m_spiceFieldsButton->Hide();
|
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
m_pinGrid->PushEventHandler( new GRID_TRICKS( m_pinGrid ) );
|
2021-12-12 17:27:40 +00:00
|
|
|
m_pinGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
|
2023-07-09 11:19:43 +00:00
|
|
|
|
|
|
|
m_tcLibraryID->SetBackgroundColour( KIPLATFORM::UI::GetDialogBGColour() );
|
2020-09-02 11:50:07 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
wxToolTip::Enable( true );
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
2009-07-26 17:16:42 +00:00
|
|
|
|
2017-09-12 07:43:51 +00:00
|
|
|
// Configure button logos
|
2023-10-21 18:56:19 +00:00
|
|
|
m_bpAdd->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
|
|
|
|
m_bpDelete->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
|
|
|
|
m_bpMoveUp->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
|
|
|
|
m_bpMoveDown->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
|
2017-09-12 07:43:51 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// wxFormBuilder doesn't include this event...
|
2022-12-07 17:01:36 +00:00
|
|
|
m_fieldsGrid->Bind( wxEVT_GRID_CELL_CHANGING, &DIALOG_SYMBOL_PROPERTIES::OnGridCellChanging,
|
|
|
|
this );
|
|
|
|
m_pinGrid->Bind( wxEVT_GRID_COL_SORT, &DIALOG_SYMBOL_PROPERTIES::OnPinTableColSort, this );
|
|
|
|
Bind( SYMBOL_DELAY_FOCUS, &DIALOG_SYMBOL_PROPERTIES::HandleDelayedFocus, this );
|
|
|
|
Bind( SYMBOL_DELAY_SELECTION, &DIALOG_SYMBOL_PROPERTIES::HandleDelayedSelection, this );
|
2022-01-27 00:04:45 +00:00
|
|
|
|
|
|
|
QueueEvent( new wxCommandEvent( SYMBOL_DELAY_SELECTION ) );
|
|
|
|
wxCommandEvent *evt = new wxCommandEvent( SYMBOL_DELAY_FOCUS );
|
|
|
|
evt->SetClientData( new VECTOR2I( REFERENCE_FIELD, FDC_VALUE ) );
|
|
|
|
QueueEvent( evt );
|
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2008-12-31 15:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
DIALOG_SYMBOL_PROPERTIES::~DIALOG_SYMBOL_PROPERTIES()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2023-04-13 12:45:22 +00:00
|
|
|
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
|
2022-12-24 22:18:05 +00:00
|
|
|
{
|
2023-04-13 12:45:22 +00:00
|
|
|
cfg->m_Appearance.edit_symbol_visible_columns = m_fieldsGrid->GetShownColumnsAsString();
|
2022-12-24 22:18:05 +00:00
|
|
|
cfg->m_Appearance.edit_symbol_width = GetSize().x;
|
|
|
|
cfg->m_Appearance.edit_symbol_height = GetSize().y;
|
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
// Prevents crash bug in wxGrid's d'tor
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->DestroyTable( m_fields );
|
2020-10-20 21:26:00 +00:00
|
|
|
|
|
|
|
if( m_dataModel )
|
|
|
|
m_pinGrid->DestroyTable( m_dataModel );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2022-12-07 17:01:36 +00:00
|
|
|
m_fieldsGrid->Unbind( wxEVT_GRID_CELL_CHANGING, &DIALOG_SYMBOL_PROPERTIES::OnGridCellChanging,
|
|
|
|
this );
|
|
|
|
m_pinGrid->Unbind( wxEVT_GRID_COL_SORT, &DIALOG_SYMBOL_PROPERTIES::OnPinTableColSort, this );
|
|
|
|
Unbind( SYMBOL_DELAY_FOCUS, &DIALOG_SYMBOL_PROPERTIES::HandleDelayedFocus, this );
|
|
|
|
Unbind( SYMBOL_DELAY_SELECTION, &DIALOG_SYMBOL_PROPERTIES::HandleDelayedSelection, this );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
// Delete the GRID_TRICKS.
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->PopEventHandler( true );
|
|
|
|
m_pinGrid->PopEventHandler( true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
SCH_EDIT_FRAME* DIALOG_SYMBOL_PROPERTIES::GetParent()
|
2019-02-20 23:20:06 +00:00
|
|
|
{
|
|
|
|
return dynamic_cast<SCH_EDIT_FRAME*>( wxDialog::GetParent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
bool DIALOG_SYMBOL_PROPERTIES::TransferDataToWindow()
|
2014-09-17 16:04:04 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
if( !wxDialog::TransferDataToWindow() )
|
|
|
|
return false;
|
2014-09-17 16:04:04 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
std::set<wxString> defined;
|
|
|
|
|
2020-04-01 14:00:40 +00:00
|
|
|
// Push a copy of each field into m_updateFields
|
2021-06-10 14:10:55 +00:00
|
|
|
for( int i = 0; i < m_symbol->GetFieldCount(); ++i )
|
2014-09-17 16:04:04 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_FIELD field( m_symbol->GetFields()[i] );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
// change offset to be symbol-relative
|
2021-06-10 14:10:55 +00:00
|
|
|
field.Offset( -m_symbol->GetPosition() );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2024-01-24 11:00:45 +00:00
|
|
|
field.SetText( m_symbol->Schematic()->ConvertKIIDsToRefs( field.GetText() ) );
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
defined.insert( field.GetName() );
|
|
|
|
m_fields->push_back( field );
|
2014-09-17 16:04:04 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Add in any template fieldnames not yet defined:
|
2020-08-30 17:57:10 +00:00
|
|
|
for( const TEMPLATE_FIELDNAME& templateFieldname :
|
|
|
|
GetParent()->Schematic().Settings().m_TemplateFieldNames.GetTemplateFieldNames() )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
|
|
|
if( defined.count( templateFieldname.m_Name ) <= 0 )
|
|
|
|
{
|
2023-02-19 03:40:07 +00:00
|
|
|
SCH_FIELD field( VECTOR2I( 0, 0 ), -1, m_symbol, templateFieldname.m_Name );
|
2018-02-28 16:54:35 +00:00
|
|
|
field.SetVisible( templateFieldname.m_Visible );
|
|
|
|
m_fields->push_back( field );
|
|
|
|
}
|
|
|
|
}
|
2014-09-17 16:04:04 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// notify the grid
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->size() );
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->ProcessTableMessage( msg );
|
2021-12-16 14:39:58 +00:00
|
|
|
AdjustFieldsGridColumns();
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// If a multi-unit symbol, set up the unit selector and interchangeable checkbox.
|
|
|
|
if( m_symbol->GetUnitCount() > 1 )
|
2017-10-06 18:07:43 +00:00
|
|
|
{
|
2022-09-04 16:22:02 +00:00
|
|
|
// Ensure symbol unit is the currently selected unit (mandatory in complex hierarchies)
|
|
|
|
// from the current sheet path, because it can be modified by previous calculations
|
2024-04-02 17:28:17 +00:00
|
|
|
m_symbol->SetUnit( m_symbol->GetUnitSelection( &GetParent()->GetCurrentSheet() ) );
|
2022-09-04 16:22:02 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
for( int ii = 1; ii <= m_symbol->GetUnitCount(); ii++ )
|
2022-09-14 22:11:37 +00:00
|
|
|
{
|
|
|
|
if( m_symbol->HasUnitDisplayName( ii ) )
|
|
|
|
m_unitChoice->Append( m_symbol->GetUnitDisplayName( ii ) );
|
|
|
|
else
|
2023-11-12 23:42:36 +00:00
|
|
|
m_unitChoice->Append( m_symbol->SubReference( ii, false ) );
|
2022-09-14 22:11:37 +00:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_symbol->GetUnit() <= ( int )m_unitChoice->GetCount() )
|
|
|
|
m_unitChoice->SetSelection( m_symbol->GetUnit() - 1 );
|
2017-10-06 18:07:43 +00:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
else
|
2014-09-17 16:04:04 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
m_unitLabel->Enable( false );
|
|
|
|
m_unitChoice->Enable( false );
|
2014-09-17 16:04:04 +00:00
|
|
|
}
|
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
if( m_part && m_part->HasAlternateBodyStyle() )
|
2014-09-17 16:04:04 +00:00
|
|
|
{
|
2024-04-06 13:14:44 +00:00
|
|
|
if( m_symbol->GetBodyStyle() > BODY_STYLE::BASE )
|
2018-02-28 16:54:35 +00:00
|
|
|
m_cbAlternateSymbol->SetValue( true );
|
2014-09-17 16:04:04 +00:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
else
|
2020-09-03 11:47:51 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
m_cbAlternateSymbol->Enable( false );
|
2020-09-03 11:47:51 +00:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
// Set the symbol orientation and mirroring.
|
2021-06-10 14:10:55 +00:00
|
|
|
int orientation = m_symbol->GetOrientation() & ~( SYM_MIRROR_X | SYM_MIRROR_Y );
|
2014-09-18 10:29:52 +00:00
|
|
|
|
2020-09-02 00:37:28 +00:00
|
|
|
switch( orientation )
|
|
|
|
{
|
|
|
|
default:
|
2021-06-10 14:10:55 +00:00
|
|
|
case SYM_ORIENT_0: m_orientationCtrl->SetSelection( 0 ); break;
|
|
|
|
case SYM_ORIENT_90: m_orientationCtrl->SetSelection( 1 ); break;
|
|
|
|
case SYM_ORIENT_270: m_orientationCtrl->SetSelection( 2 ); break;
|
|
|
|
case SYM_ORIENT_180: m_orientationCtrl->SetSelection( 3 ); break;
|
2020-09-02 00:37:28 +00:00
|
|
|
}
|
2017-10-06 18:07:43 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
int mirror = m_symbol->GetOrientation() & ( SYM_MIRROR_X | SYM_MIRROR_Y );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2020-09-02 00:37:28 +00:00
|
|
|
switch( mirror )
|
|
|
|
{
|
|
|
|
default: m_mirrorCtrl->SetSelection( 0 ) ; break;
|
2021-06-10 14:10:55 +00:00
|
|
|
case SYM_MIRROR_X: m_mirrorCtrl->SetSelection( 1 ); break;
|
|
|
|
case SYM_MIRROR_Y: m_mirrorCtrl->SetSelection( 2 ); break;
|
2020-09-02 00:37:28 +00:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2023-08-08 16:32:08 +00:00
|
|
|
m_cbExcludeFromSim->SetValue( m_symbol->GetExcludedFromSim() );
|
2023-06-25 02:03:06 +00:00
|
|
|
m_cbExcludeFromBom->SetValue( m_symbol->GetExcludedFromBOM() );
|
|
|
|
m_cbExcludeFromBoard->SetValue( m_symbol->GetExcludedFromBoard() );
|
2022-09-16 16:20:36 +00:00
|
|
|
m_cbDNP->SetValue( m_symbol->GetDNP() );
|
2020-06-03 12:30:57 +00:00
|
|
|
|
2020-12-03 09:42:31 +00:00
|
|
|
if( m_part )
|
|
|
|
{
|
2024-04-02 17:28:17 +00:00
|
|
|
m_ShowPinNumButt->SetValue( m_part->GetShowPinNumbers() );
|
|
|
|
m_ShowPinNameButt->SetValue( m_part->GetShowPinNames() );
|
2020-12-03 09:42:31 +00:00
|
|
|
}
|
2014-09-17 16:04:04 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Set the symbol's library name.
|
2021-07-28 17:40:35 +00:00
|
|
|
m_tcLibraryID->SetValue( UnescapeString( m_symbol->GetLibId().Format() ) );
|
2014-09-17 16:04:04 +00:00
|
|
|
|
2020-09-02 00:37:28 +00:00
|
|
|
Layout();
|
2022-01-28 20:57:51 +00:00
|
|
|
m_fieldsGrid->Layout();
|
|
|
|
wxSafeYield();
|
2019-04-09 15:58:23 +00:00
|
|
|
|
2020-09-02 00:37:28 +00:00
|
|
|
return true;
|
2014-09-17 16:04:04 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnEditSpiceModel( wxCommandEvent& event )
|
2016-08-11 12:41:10 +00:00
|
|
|
{
|
2022-10-26 13:03:20 +00:00
|
|
|
if( !m_fieldsGrid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2022-12-11 22:59:27 +00:00
|
|
|
std::vector<SCH_FIELD> fields;
|
2016-08-11 12:41:10 +00:00
|
|
|
|
2022-12-11 22:59:27 +00:00
|
|
|
for( const SCH_FIELD& field : *m_fields )
|
|
|
|
fields.emplace_back( field );
|
|
|
|
|
2024-01-25 15:29:29 +00:00
|
|
|
DIALOG_SIM_MODEL dialog( this, m_parentFrame, *m_symbol, fields );
|
2016-08-11 12:41:10 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( dialog.ShowModal() != wxID_OK )
|
|
|
|
return;
|
2016-08-11 12:41:10 +00:00
|
|
|
|
2022-12-11 22:59:27 +00:00
|
|
|
// Add in any new fields
|
|
|
|
for( const SCH_FIELD& editedField : fields )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2022-12-11 22:59:27 +00:00
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for( SCH_FIELD& existingField : *m_fields )
|
|
|
|
{
|
|
|
|
if( existingField.GetName() == editedField.GetName() )
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
existingField.SetText( editedField.GetText() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !found )
|
|
|
|
{
|
|
|
|
m_fields->emplace_back( editedField );
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
|
|
|
|
m_fieldsGrid->ProcessTableMessage( msg );
|
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
2022-12-11 22:59:27 +00:00
|
|
|
|
|
|
|
// Remove any deleted fields
|
2022-12-15 14:21:38 +00:00
|
|
|
for( int ii = (int) m_fields->size() - 1; ii >= 0; --ii )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2022-12-11 22:59:27 +00:00
|
|
|
SCH_FIELD& existingField = m_fields->at( ii );
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for( SCH_FIELD& editedField : fields )
|
|
|
|
{
|
|
|
|
if( editedField.GetName() == existingField.GetName() )
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-15 14:21:38 +00:00
|
|
|
if( !found )
|
2022-12-11 22:59:27 +00:00
|
|
|
{
|
|
|
|
m_fields->erase( m_fields->begin() + ii );
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
|
2022-12-15 14:40:57 +00:00
|
|
|
m_fieldsGrid->ClearSelection();
|
2022-12-11 22:59:27 +00:00
|
|
|
m_fieldsGrid->ProcessTableMessage( msg );
|
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
|
2021-10-25 11:34:30 +00:00
|
|
|
OnModify();
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->ForceRefresh();
|
2008-11-24 21:06:50 +00:00
|
|
|
}
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnCancelButtonClick( wxCommandEvent& event )
|
2019-01-31 19:05:11 +00:00
|
|
|
{
|
|
|
|
// Running the Footprint Browser gums up the works and causes the automatic cancel
|
|
|
|
// stuff to no longer work. So we do it here ourselves.
|
|
|
|
EndQuasiModal( wxID_CANCEL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
bool DIALOG_SYMBOL_PROPERTIES::Validate()
|
2014-09-15 12:06:00 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
LIB_ID id;
|
2014-09-15 11:59:40 +00:00
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
if( !m_fieldsGrid->CommitPendingChanges() || !m_fieldsGrid->Validate() )
|
2018-08-13 17:00:08 +00:00
|
|
|
return false;
|
2014-09-15 11:59:40 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( !SCH_SYMBOL::IsReferenceStringValid( m_fields->at( REFERENCE_FIELD ).GetText() ) )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2018-07-21 20:23:13 +00:00
|
|
|
DisplayErrorMessage( this, _( "References must start with a letter." ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2022-01-27 00:04:45 +00:00
|
|
|
wxCommandEvent *evt = new wxCommandEvent( SYMBOL_DELAY_FOCUS );
|
|
|
|
evt->SetClientData( new VECTOR2I( REFERENCE_FIELD, FDC_VALUE ) );
|
|
|
|
QueueEvent( evt );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-31 01:31:19 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Check for missing field names.
|
2018-08-15 11:19:41 +00:00
|
|
|
for( size_t i = MANDATORY_FIELDS; i < m_fields->size(); ++i )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
|
|
|
SCH_FIELD& field = m_fields->at( i );
|
|
|
|
wxString fieldName = field.GetName( false );
|
|
|
|
|
|
|
|
if( fieldName.IsEmpty() )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
DisplayErrorMessage( this, _( "Fields must have a name." ) );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2022-01-27 00:04:45 +00:00
|
|
|
wxCommandEvent *evt = new wxCommandEvent( SYMBOL_DELAY_FOCUS );
|
|
|
|
evt->SetClientData( new VECTOR2I( i, FDC_VALUE ) );
|
|
|
|
QueueEvent( evt );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
return false;
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
bool DIALOG_SYMBOL_PROPERTIES::TransferDataFromWindow()
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2019-05-10 12:21:08 +00:00
|
|
|
if( !wxDialog::TransferDataFromWindow() ) // Calls our Validate() method.
|
2018-08-13 17:00:08 +00:00
|
|
|
return false;
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
if( !m_fieldsGrid->CommitPendingChanges() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( !m_pinGrid->CommitPendingChanges() )
|
|
|
|
return false;
|
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
SCH_COMMIT commit( GetParent() );
|
|
|
|
SCH_SCREEN* currentScreen = GetParent()->GetScreen();
|
2023-11-28 18:19:15 +00:00
|
|
|
bool replaceOnCurrentScreen;
|
2020-05-05 14:55:54 +00:00
|
|
|
wxCHECK( currentScreen, false );
|
|
|
|
|
|
|
|
// This needs to be done before the LIB_ID is changed to prevent stale library symbols in
|
|
|
|
// the schematic file.
|
2023-11-28 18:19:15 +00:00
|
|
|
replaceOnCurrentScreen = currentScreen->Remove( m_symbol );
|
2020-05-05 14:55:54 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// save old cmp in undo list if not already in edit, or moving ...
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_symbol->GetEditFlags() == 0 )
|
2023-06-08 00:04:11 +00:00
|
|
|
commit.Modify( m_symbol, currentScreen );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
// Save current flags which could be modified by next change settings
|
2021-06-10 14:10:55 +00:00
|
|
|
EDA_ITEM_FLAGS flags = m_symbol->GetFlags();
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
// For symbols with multiple shapes (De Morgan representation) Set the selected shape:
|
2019-04-15 13:59:36 +00:00
|
|
|
if( m_cbAlternateSymbol->IsEnabled() && m_cbAlternateSymbol->GetValue() )
|
2024-04-06 13:14:44 +00:00
|
|
|
m_symbol->SetBodyStyle( BODY_STYLE::DEMORGAN );
|
2019-04-15 13:59:36 +00:00
|
|
|
else
|
2024-04-06 13:14:44 +00:00
|
|
|
m_symbol->SetBodyStyle( BODY_STYLE::BASE );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
//Set the part selection in multiple part per package
|
2020-09-02 00:37:28 +00:00
|
|
|
int unit_selection = m_unitChoice->IsEnabled() ? m_unitChoice->GetSelection() + 1 : 1;
|
2021-06-10 14:10:55 +00:00
|
|
|
m_symbol->SetUnitSelection( &GetParent()->GetCurrentSheet(), unit_selection );
|
|
|
|
m_symbol->SetUnit( unit_selection );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-09-02 00:37:28 +00:00
|
|
|
switch( m_orientationCtrl->GetSelection() )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
case 0: m_symbol->SetOrientation( SYM_ORIENT_0 ); break;
|
|
|
|
case 1: m_symbol->SetOrientation( SYM_ORIENT_90 ); break;
|
|
|
|
case 2: m_symbol->SetOrientation( SYM_ORIENT_270 ); break;
|
|
|
|
case 3: m_symbol->SetOrientation( SYM_ORIENT_180 ); break;
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2020-09-02 00:37:28 +00:00
|
|
|
switch( m_mirrorCtrl->GetSelection() )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2022-04-19 20:11:43 +00:00
|
|
|
case 0: break;
|
2021-06-10 14:10:55 +00:00
|
|
|
case 1: m_symbol->SetOrientation( SYM_MIRROR_X ); break;
|
|
|
|
case 2: m_symbol->SetOrientation( SYM_MIRROR_Y ); break;
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
2014-12-16 18:58:26 +00:00
|
|
|
|
2020-12-03 09:42:31 +00:00
|
|
|
if( m_part )
|
|
|
|
{
|
|
|
|
m_part->SetShowPinNames( m_ShowPinNameButt->GetValue() );
|
|
|
|
m_part->SetShowPinNumbers( m_ShowPinNumButt->GetValue() );
|
|
|
|
}
|
2020-09-02 00:37:28 +00:00
|
|
|
|
2022-09-05 10:57:07 +00:00
|
|
|
// Restore m_Flag modified by SetUnit() and other change settings from the dialog
|
2021-06-10 14:10:55 +00:00
|
|
|
m_symbol->ClearFlags();
|
|
|
|
m_symbol->SetFlags( flags );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// change all field positions from relative to absolute
|
|
|
|
for( unsigned i = 0; i < m_fields->size(); ++i )
|
2024-01-24 11:00:45 +00:00
|
|
|
{
|
|
|
|
SCH_FIELD& field = m_fields->at( i );
|
|
|
|
|
|
|
|
field.Offset( m_symbol->GetPosition() );
|
|
|
|
field.SetText( m_symbol->Schematic()->ConvertRefsToKIIDs( field.GetText() ) );
|
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_FIELDS& fields = m_symbol->GetFields();
|
2011-01-18 10:42:49 +00:00
|
|
|
|
2020-05-10 18:41:29 +00:00
|
|
|
fields.clear();
|
|
|
|
|
2023-03-19 19:15:02 +00:00
|
|
|
for( size_t ii = 0; ii < m_fields->size(); ++ii )
|
|
|
|
{
|
|
|
|
SCH_FIELD& field = m_fields->at( ii );
|
|
|
|
const wxString& fieldName = field.GetCanonicalName();
|
|
|
|
|
|
|
|
if( fieldName.IsEmpty() && field.GetText().IsEmpty() )
|
|
|
|
continue;
|
|
|
|
else if( fieldName.IsEmpty() )
|
|
|
|
field.SetName( _( "untitled" ) );
|
|
|
|
|
|
|
|
fields.push_back( field );
|
|
|
|
}
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
// Reference has a specific initialization, depending on the current active sheet
|
2021-06-10 14:10:55 +00:00
|
|
|
// because for a given symbol, in a complex hierarchy, there are more than one
|
2010-01-13 13:43:36 +00:00
|
|
|
// reference.
|
2021-06-10 14:10:55 +00:00
|
|
|
m_symbol->SetRef( &GetParent()->GetCurrentSheet(), m_fields->at( REFERENCE_FIELD ).GetText() );
|
2010-01-13 13:43:36 +00:00
|
|
|
|
2023-10-17 12:07:15 +00:00
|
|
|
// Similar for Value and Footprint, except that the GUI behavior is that they are kept
|
2020-09-06 12:05:07 +00:00
|
|
|
// in sync between multiple instances.
|
2022-11-25 14:25:39 +00:00
|
|
|
m_symbol->SetValueFieldText( m_fields->at( VALUE_FIELD ).GetText() );
|
|
|
|
m_symbol->SetFootprintFieldText( m_fields->at( FOOTPRINT_FIELD ).GetText() );
|
2020-09-06 12:05:07 +00:00
|
|
|
|
2023-08-08 16:32:08 +00:00
|
|
|
m_symbol->SetExcludedFromSim( m_cbExcludeFromSim->IsChecked() );
|
2023-06-25 02:03:06 +00:00
|
|
|
m_symbol->SetExcludedFromBOM( m_cbExcludeFromBom->IsChecked() );
|
|
|
|
m_symbol->SetExcludedFromBoard( m_cbExcludeFromBoard->IsChecked() );
|
2022-09-16 16:20:36 +00:00
|
|
|
m_symbol->SetDNP( m_cbDNP->IsChecked() );
|
2020-06-03 12:30:57 +00:00
|
|
|
|
2022-02-16 18:26:46 +00:00
|
|
|
// Update any assignments
|
|
|
|
if( m_dataModel )
|
|
|
|
{
|
|
|
|
for( const SCH_PIN& model_pin : *m_dataModel )
|
|
|
|
{
|
|
|
|
// map from the edited copy back to the "real" pin in the symbol.
|
2022-08-13 01:24:07 +00:00
|
|
|
SCH_PIN* src_pin = m_symbol->GetPin( model_pin.GetNumber() );
|
|
|
|
|
|
|
|
if( src_pin )
|
|
|
|
src_pin->SetAlt( model_pin.GetAlt() );
|
2022-02-16 18:26:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-17 12:01:12 +00:00
|
|
|
// Keep fields other than the reference, include/exclude flags, and alternate pin assignements
|
|
|
|
// in sync in multi-unit parts.
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_symbol->GetUnitCount() > 1 && m_symbol->IsAnnotated( &GetParent()->GetCurrentSheet() ) )
|
2018-01-06 12:36:08 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
wxString ref = m_symbol->GetRef( &GetParent()->GetCurrentSheet() );
|
|
|
|
int unit = m_symbol->GetUnit();
|
|
|
|
LIB_ID libId = m_symbol->GetLibId();
|
2020-10-24 20:55:32 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
for( SCH_SHEET_PATH& sheet : GetParent()->Schematic().GetSheets() )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SCREEN* screen = sheet.LastScreen();
|
|
|
|
std::vector<SCH_SYMBOL*> otherUnits;
|
2018-01-06 12:36:08 +00:00
|
|
|
|
2021-05-06 11:13:08 +00:00
|
|
|
CollectOtherUnits( ref, unit, libId, sheet, &otherUnits );
|
2019-05-10 12:21:08 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
for( SCH_SYMBOL* otherUnit : otherUnits )
|
2020-07-13 11:21:40 +00:00
|
|
|
{
|
2023-06-09 16:24:49 +00:00
|
|
|
commit.Modify( otherUnit, screen );
|
2022-11-25 14:25:39 +00:00
|
|
|
otherUnit->SetValueFieldText( m_fields->at( VALUE_FIELD ).GetText() );
|
|
|
|
otherUnit->SetFootprintFieldText( m_fields->at( FOOTPRINT_FIELD ).GetText() );
|
2022-02-17 12:01:12 +00:00
|
|
|
|
|
|
|
for( size_t ii = DATASHEET_FIELD; ii < m_fields->size(); ++ii )
|
|
|
|
{
|
|
|
|
SCH_FIELD* otherField = otherUnit->FindField( m_fields->at( ii ).GetName() );
|
|
|
|
|
|
|
|
if( otherField )
|
|
|
|
{
|
|
|
|
otherField->SetText( m_fields->at( ii ).GetText() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-11 22:15:54 +00:00
|
|
|
SCH_FIELD newField( m_fields->at( ii ) );
|
|
|
|
const_cast<KIID&>( newField.m_Uuid ) = KIID();
|
|
|
|
|
|
|
|
newField.Offset( -m_symbol->GetPosition() );
|
|
|
|
newField.Offset( otherUnit->GetPosition() );
|
|
|
|
|
|
|
|
newField.SetParent( otherUnit );
|
|
|
|
otherUnit->AddField( newField );
|
2022-02-17 12:01:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( size_t ii = otherUnit->GetFields().size() - 1; ii > DATASHEET_FIELD; ii-- )
|
|
|
|
{
|
|
|
|
SCH_FIELD& otherField = otherUnit->GetFields().at( ii );
|
|
|
|
|
|
|
|
if( !m_symbol->FindField( otherField.GetName() ) )
|
|
|
|
otherUnit->GetFields().erase( otherUnit->GetFields().begin() + ii );
|
|
|
|
}
|
|
|
|
|
2023-08-08 16:32:08 +00:00
|
|
|
otherUnit->SetExcludedFromSim( m_cbExcludeFromSim->IsChecked() );
|
2023-06-25 02:03:06 +00:00
|
|
|
otherUnit->SetExcludedFromBOM( m_cbExcludeFromBom->IsChecked() );
|
|
|
|
otherUnit->SetExcludedFromBoard( m_cbExcludeFromBoard->IsChecked() );
|
2022-09-16 16:20:36 +00:00
|
|
|
otherUnit->SetDNP( m_cbDNP->IsChecked() );
|
2022-02-16 18:26:46 +00:00
|
|
|
|
|
|
|
if( m_dataModel )
|
|
|
|
{
|
|
|
|
for( const SCH_PIN& model_pin : *m_dataModel )
|
|
|
|
{
|
|
|
|
SCH_PIN* src_pin = otherUnit->GetPin( model_pin.GetNumber() );
|
|
|
|
|
|
|
|
if( src_pin )
|
|
|
|
src_pin->SetAlt( model_pin.GetAlt() );
|
|
|
|
}
|
|
|
|
}
|
2020-07-13 11:21:40 +00:00
|
|
|
}
|
2018-01-06 12:36:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-28 18:19:15 +00:00
|
|
|
if( replaceOnCurrentScreen )
|
|
|
|
currentScreen->Append( m_symbol );
|
2023-06-08 00:04:11 +00:00
|
|
|
|
|
|
|
if( !commit.Empty() )
|
|
|
|
commit.Push( _( "Edit Symbol Properties" ) );
|
2020-08-13 21:30:30 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
return true;
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnGridCellChanging( wxGridEvent& event )
|
2008-11-26 06:25:20 +00:00
|
|
|
{
|
2020-09-02 11:50:07 +00:00
|
|
|
wxGridCellEditor* editor = m_fieldsGrid->GetCellEditor( event.GetRow(), event.GetCol() );
|
2018-07-21 20:23:13 +00:00
|
|
|
wxControl* control = editor->GetControl();
|
|
|
|
|
|
|
|
if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
|
2008-11-26 06:25:20 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
event.Veto();
|
2022-01-27 00:04:45 +00:00
|
|
|
wxCommandEvent *evt = new wxCommandEvent( SYMBOL_DELAY_FOCUS );
|
|
|
|
evt->SetClientData( new VECTOR2I( event.GetRow(), event.GetCol() ) );
|
|
|
|
QueueEvent( evt );
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
2020-06-02 20:42:17 +00:00
|
|
|
else if( event.GetCol() == FDC_NAME )
|
|
|
|
{
|
|
|
|
wxString newName = event.GetString();
|
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
for( int i = 0; i < m_fieldsGrid->GetNumberRows(); ++i )
|
2020-06-02 20:42:17 +00:00
|
|
|
{
|
|
|
|
if( i == event.GetRow() )
|
|
|
|
continue;
|
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
if( newName.CmpNoCase( m_fieldsGrid->GetCellValue( i, FDC_NAME ) ) == 0 )
|
2020-06-02 20:42:17 +00:00
|
|
|
{
|
2021-06-30 10:53:04 +00:00
|
|
|
DisplayError( this, wxString::Format( _( "Field name '%s' already in use." ),
|
2020-06-02 20:42:17 +00:00
|
|
|
newName ) );
|
|
|
|
event.Veto();
|
2022-01-27 00:04:45 +00:00
|
|
|
wxCommandEvent *evt = new wxCommandEvent( SYMBOL_DELAY_FOCUS );
|
|
|
|
evt->SetClientData( new VECTOR2I( event.GetRow(), event.GetCol() ) );
|
|
|
|
QueueEvent( evt );
|
2020-06-02 20:42:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-21 20:23:13 +00:00
|
|
|
|
|
|
|
editor->DecRef();
|
2008-11-26 06:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnGridEditorShown( wxGridEvent& aEvent )
|
2020-10-17 23:14:17 +00:00
|
|
|
{
|
2020-11-12 21:31:41 +00:00
|
|
|
if( aEvent.GetRow() == REFERENCE_FIELD && aEvent.GetCol() == FDC_VALUE )
|
2022-01-27 00:04:45 +00:00
|
|
|
QueueEvent( new wxCommandEvent( SYMBOL_DELAY_SELECTION ) );
|
2022-01-24 17:54:05 +00:00
|
|
|
|
2022-01-26 01:57:42 +00:00
|
|
|
m_editorShown = true;
|
|
|
|
}
|
|
|
|
|
2022-01-24 23:30:25 +00:00
|
|
|
|
2022-01-26 01:57:42 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnGridEditorHidden( wxGridEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_editorShown = false;
|
2020-10-17 23:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnAddField( wxCommandEvent& event )
|
2013-08-08 16:12:41 +00:00
|
|
|
{
|
2020-09-02 11:50:07 +00:00
|
|
|
if( !m_fieldsGrid->CommitPendingChanges() )
|
2018-08-13 17:00:08 +00:00
|
|
|
return;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCHEMATIC_SETTINGS& settings = m_symbol->Schematic()->Settings();
|
2022-12-28 13:43:14 +00:00
|
|
|
int fieldID = (int) m_fields->size();
|
2023-02-19 03:40:07 +00:00
|
|
|
SCH_FIELD newField( VECTOR2I( 0, 0 ), fieldID, m_symbol,
|
2023-10-17 12:07:15 +00:00
|
|
|
TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldID,
|
|
|
|
DO_TRANSLATE ) );
|
2014-05-05 17:28:40 +00:00
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
newField.SetTextAngle( m_fields->at( REFERENCE_FIELD ).GetTextAngle() );
|
2023-02-19 03:40:07 +00:00
|
|
|
newField.SetTextSize( VECTOR2I( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
|
2020-04-04 20:32:14 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_fields->push_back( newField );
|
2014-05-04 00:44:57 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// notify the grid
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->ProcessTableMessage( msg );
|
2016-05-17 18:02:49 +00:00
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->MakeCellVisible( (int) m_fields->size() - 1, 0 );
|
|
|
|
m_fieldsGrid->SetGridCursor( (int) m_fields->size() - 1, 0 );
|
2014-05-04 00:44:57 +00:00
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->EnableCellEditControl();
|
|
|
|
m_fieldsGrid->ShowCellEditControl();
|
2021-10-25 11:34:30 +00:00
|
|
|
|
|
|
|
OnModify();
|
2013-08-08 16:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnDeleteField( wxCommandEvent& event )
|
2008-11-26 06:25:20 +00:00
|
|
|
{
|
2021-12-12 17:27:40 +00:00
|
|
|
wxArrayInt selectedRows = m_fieldsGrid->GetSelectedRows();
|
2008-11-26 06:25:20 +00:00
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
if( selectedRows.empty() && m_fieldsGrid->GetGridCursorRow() >= 0 )
|
|
|
|
selectedRows.push_back( m_fieldsGrid->GetGridCursorRow() );
|
|
|
|
|
|
|
|
if( selectedRows.empty() )
|
2008-11-26 06:25:20 +00:00
|
|
|
return;
|
2021-12-12 17:27:40 +00:00
|
|
|
|
|
|
|
for( int row : selectedRows )
|
2008-11-26 06:25:20 +00:00
|
|
|
{
|
2021-12-12 17:27:40 +00:00
|
|
|
if( row < MANDATORY_FIELDS )
|
|
|
|
{
|
|
|
|
DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
|
|
|
|
MANDATORY_FIELDS ) );
|
|
|
|
return;
|
|
|
|
}
|
2008-11-26 06:25:20 +00:00
|
|
|
}
|
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->CommitPendingChanges( true /* quiet mode */ );
|
2022-12-12 14:43:37 +00:00
|
|
|
m_fieldsGrid->ClearSelection();
|
2018-08-13 17:00:08 +00:00
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
// Reverse sort so deleting a row doesn't change the indexes of the other rows.
|
|
|
|
selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } );
|
2008-11-26 06:25:20 +00:00
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
for( int row : selectedRows )
|
2017-09-12 07:43:51 +00:00
|
|
|
{
|
2021-12-12 17:27:40 +00:00
|
|
|
m_fields->erase( m_fields->begin() + row );
|
|
|
|
|
|
|
|
// notify the grid
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
|
|
|
|
m_fieldsGrid->ProcessTableMessage( msg );
|
|
|
|
|
|
|
|
if( m_fieldsGrid->GetNumberRows() > 0 )
|
|
|
|
{
|
|
|
|
m_fieldsGrid->MakeCellVisible( std::max( 0, row-1 ), m_fieldsGrid->GetGridCursorCol() );
|
|
|
|
m_fieldsGrid->SetGridCursor( std::max( 0, row-1 ), m_fieldsGrid->GetGridCursorCol() );
|
|
|
|
}
|
2017-09-12 07:43:51 +00:00
|
|
|
}
|
2021-10-25 11:34:30 +00:00
|
|
|
|
|
|
|
OnModify();
|
2017-09-12 07:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnMoveUp( wxCommandEvent& event )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2020-09-02 11:50:07 +00:00
|
|
|
if( !m_fieldsGrid->CommitPendingChanges() )
|
2018-08-13 17:00:08 +00:00
|
|
|
return;
|
2008-11-26 00:20:16 +00:00
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
int i = m_fieldsGrid->GetGridCursorRow();
|
2008-11-26 00:20:16 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
if( i > MANDATORY_FIELDS )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
SCH_FIELD tmp = m_fields->at( (unsigned) i );
|
2018-02-28 16:54:35 +00:00
|
|
|
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
|
|
|
|
m_fields->insert( m_fields->begin() + i - 1, tmp );
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->ForceRefresh();
|
2008-11-26 00:20:16 +00:00
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->SetGridCursor( i - 1, m_fieldsGrid->GetGridCursorCol() );
|
2021-05-06 11:13:08 +00:00
|
|
|
m_fieldsGrid->MakeCellVisible( m_fieldsGrid->GetGridCursorRow(),
|
|
|
|
m_fieldsGrid->GetGridCursorCol() );
|
2021-10-25 11:34:30 +00:00
|
|
|
|
|
|
|
OnModify();
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
else
|
2020-05-05 14:55:54 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
wxBell();
|
2020-05-05 14:55:54 +00:00
|
|
|
}
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnMoveDown( wxCommandEvent& event )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2020-09-02 11:50:07 +00:00
|
|
|
if( !m_fieldsGrid->CommitPendingChanges() )
|
2018-08-13 17:00:08 +00:00
|
|
|
return;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
int i = m_fieldsGrid->GetGridCursorRow();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
if( i >= MANDATORY_FIELDS && i < m_fieldsGrid->GetNumberRows() - 1 )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
SCH_FIELD tmp = m_fields->at( (unsigned) i );
|
2018-02-28 16:54:35 +00:00
|
|
|
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
|
|
|
|
m_fields->insert( m_fields->begin() + i + 1, tmp );
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->ForceRefresh();
|
2011-08-30 19:24:28 +00:00
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->SetGridCursor( i + 1, m_fieldsGrid->GetGridCursorCol() );
|
2021-05-06 11:13:08 +00:00
|
|
|
m_fieldsGrid->MakeCellVisible( m_fieldsGrid->GetGridCursorRow(),
|
|
|
|
m_fieldsGrid->GetGridCursorCol() );
|
2021-10-25 11:34:30 +00:00
|
|
|
|
|
|
|
OnModify();
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
else
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
wxBell();
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
2008-12-31 16:49:45 +00:00
|
|
|
}
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnEditSymbol( wxCommandEvent& )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2021-03-01 20:36:18 +00:00
|
|
|
if( TransferDataFromWindow() )
|
|
|
|
EndQuasiModal( SYMBOL_PROPS_EDIT_SCHEMATIC_SYMBOL );
|
2020-09-02 00:37:28 +00:00
|
|
|
}
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2019-04-04 11:26:07 +00:00
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnEditLibrarySymbol( wxCommandEvent& )
|
2020-09-02 00:37:28 +00:00
|
|
|
{
|
2021-03-01 20:36:18 +00:00
|
|
|
if( TransferDataFromWindow() )
|
|
|
|
EndQuasiModal( SYMBOL_PROPS_EDIT_LIBRARY_SYMBOL );
|
2020-09-02 00:37:28 +00:00
|
|
|
}
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnUpdateSymbol( wxCommandEvent& )
|
2020-09-02 00:37:28 +00:00
|
|
|
{
|
2021-03-01 20:36:18 +00:00
|
|
|
if( TransferDataFromWindow() )
|
|
|
|
EndQuasiModal( SYMBOL_PROPS_WANT_UPDATE_SYMBOL );
|
2020-09-02 00:37:28 +00:00
|
|
|
}
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnExchangeSymbol( wxCommandEvent& )
|
2020-09-02 00:37:28 +00:00
|
|
|
{
|
2021-03-01 20:36:18 +00:00
|
|
|
if( TransferDataFromWindow() )
|
|
|
|
EndQuasiModal( SYMBOL_PROPS_WANT_EXCHANGE_SYMBOL );
|
2008-11-24 21:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnPinTableCellEdited( wxGridEvent& aEvent )
|
2020-09-02 11:50:07 +00:00
|
|
|
{
|
|
|
|
int row = aEvent.GetRow();
|
|
|
|
|
2022-05-04 00:08:11 +00:00
|
|
|
if( m_pinGrid->GetCellValue( row, COL_ALT_NAME )
|
|
|
|
== m_dataModel->GetValue( row, COL_BASE_NAME ) )
|
|
|
|
{
|
2020-09-02 11:50:07 +00:00
|
|
|
m_dataModel->SetValue( row, COL_ALT_NAME, wxEmptyString );
|
2022-05-04 00:08:11 +00:00
|
|
|
}
|
2020-09-02 11:50:07 +00:00
|
|
|
|
|
|
|
// These are just to get the cells refreshed
|
|
|
|
m_dataModel->SetValue( row, COL_TYPE, m_dataModel->GetValue( row, COL_TYPE ) );
|
|
|
|
m_dataModel->SetValue( row, COL_SHAPE, m_dataModel->GetValue( row, COL_SHAPE ) );
|
|
|
|
|
2021-10-25 11:34:30 +00:00
|
|
|
OnModify();
|
2020-09-02 11:50:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnPinTableColSort( wxGridEvent& aEvent )
|
2020-09-02 11:50:07 +00:00
|
|
|
{
|
|
|
|
int sortCol = aEvent.GetCol();
|
|
|
|
bool ascending;
|
|
|
|
|
|
|
|
// This is bonkers, but wxWidgets doesn't tell us ascending/descending in the
|
|
|
|
// event, and if we ask it will give us pre-event info.
|
|
|
|
if( m_pinGrid->IsSortingBy( sortCol ) )
|
|
|
|
// same column; invert ascending
|
|
|
|
ascending = !m_pinGrid->IsSortOrderAscending();
|
|
|
|
else
|
|
|
|
// different column; start with ascending
|
|
|
|
ascending = true;
|
|
|
|
|
|
|
|
m_dataModel->SortRows( sortCol, ascending );
|
2022-06-08 12:48:19 +00:00
|
|
|
m_dataModel->BuildAttrs();
|
2020-09-02 11:50:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-16 14:39:58 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::AdjustFieldsGridColumns()
|
2008-11-24 21:06:50 +00:00
|
|
|
{
|
2021-12-16 14:39:58 +00:00
|
|
|
wxGridUpdateLocker deferRepaintsTillLeavingScope( m_fieldsGrid );
|
2020-09-02 11:50:07 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Account for scroll bars
|
2021-12-16 14:39:58 +00:00
|
|
|
int fieldsWidth = KIPLATFORM::UI::GetUnobscuredSize( m_fieldsGrid ).x;
|
2020-09-02 11:50:07 +00:00
|
|
|
|
|
|
|
m_fieldsGrid->AutoSizeColumn( 0 );
|
2022-11-16 12:35:21 +00:00
|
|
|
m_fieldsGrid->SetColSize( 0, std::max( 72, m_fieldsGrid->GetColSize( 0 ) ) );
|
2020-09-02 11:50:07 +00:00
|
|
|
|
|
|
|
int fixedColsWidth = m_fieldsGrid->GetColSize( 0 );
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
for( int i = 2; i < m_fieldsGrid->GetNumberCols(); i++ )
|
|
|
|
fixedColsWidth += m_fieldsGrid->GetColSize( i );
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2022-11-16 12:35:21 +00:00
|
|
|
m_fieldsGrid->SetColSize( 1, std::max( 120, fieldsWidth - fixedColsWidth ) );
|
2021-12-16 14:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_PROPERTIES::AdjustPinsGridColumns()
|
|
|
|
{
|
|
|
|
wxGridUpdateLocker deferRepaintsTillLeavingScope( m_pinGrid );
|
|
|
|
|
|
|
|
// Account for scroll bars
|
|
|
|
int pinTblWidth = KIPLATFORM::UI::GetUnobscuredSize( m_pinGrid ).x;
|
2020-09-02 11:50:07 +00:00
|
|
|
|
|
|
|
// Stretch the Base Name and Alternate Assignment columns to fit.
|
|
|
|
for( int i = 0; i < COL_COUNT; ++i )
|
|
|
|
{
|
|
|
|
if( i != COL_BASE_NAME && i != COL_ALT_NAME )
|
|
|
|
pinTblWidth -= m_pinGrid->GetColSize( i );
|
|
|
|
}
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
m_pinGrid->SetColSize( COL_BASE_NAME, pinTblWidth / 2 );
|
|
|
|
m_pinGrid->SetColSize( COL_ALT_NAME, pinTblWidth / 2 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2023-04-13 12:45:22 +00:00
|
|
|
std::bitset<64> shownColumns = m_fieldsGrid->GetShownColumns();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( shownColumns != m_shownColumns )
|
2016-04-17 15:15:26 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
m_shownColumns = shownColumns;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
if( !m_fieldsGrid->IsCellEditControlShown() )
|
2021-12-16 14:39:58 +00:00
|
|
|
AdjustFieldsGridColumns();
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
2022-01-27 00:04:45 +00:00
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
|
|
|
|
2022-01-27 00:04:45 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::HandleDelayedFocus( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
VECTOR2I *loc = static_cast<VECTOR2I*>( event.GetClientData() );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2022-01-27 00:04:45 +00:00
|
|
|
wxCHECK_RET( loc, wxT( "Missing focus cell location" ) );
|
2020-10-17 23:14:17 +00:00
|
|
|
|
2022-01-27 00:04:45 +00:00
|
|
|
// Handle a delayed focus
|
2020-10-17 23:14:17 +00:00
|
|
|
|
2022-01-27 00:04:45 +00:00
|
|
|
m_fieldsGrid->SetFocus();
|
|
|
|
m_fieldsGrid->MakeCellVisible( loc->x, loc->y );
|
|
|
|
m_fieldsGrid->SetGridCursor( loc->x, loc->y );
|
2020-10-17 23:14:17 +00:00
|
|
|
|
2022-01-27 00:04:45 +00:00
|
|
|
m_fieldsGrid->EnableCellEditControl( true );
|
|
|
|
m_fieldsGrid->ShowCellEditControl();
|
2020-10-17 23:14:17 +00:00
|
|
|
|
2022-01-27 00:04:45 +00:00
|
|
|
delete loc;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2017-08-25 11:37:21 +00:00
|
|
|
|
|
|
|
|
2022-01-27 00:04:45 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::HandleDelayedSelection( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
// Handle a delayed selection
|
|
|
|
wxGridCellEditor* cellEditor = m_fieldsGrid->GetCellEditor( REFERENCE_FIELD, FDC_VALUE );
|
|
|
|
|
|
|
|
if( wxTextEntry* txt = dynamic_cast<wxTextEntry*>( cellEditor->GetControl() ) )
|
|
|
|
KIUI::SelectReferenceNumber( txt );
|
|
|
|
|
|
|
|
cellEditor->DecRef(); // we're done; must release
|
|
|
|
}
|
|
|
|
|
2021-12-16 14:39:58 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnSizeFieldsGrid( wxSizeEvent& event )
|
2017-08-25 11:37:21 +00:00
|
|
|
{
|
2021-12-17 04:00:24 +00:00
|
|
|
wxSize new_size = event.GetSize();
|
2017-08-25 11:37:21 +00:00
|
|
|
|
2023-12-14 12:23:50 +00:00
|
|
|
if( ( !m_editorShown || m_lastRequestedFieldsSize != new_size ) && m_fieldsSize != new_size )
|
2019-02-27 07:07:32 +00:00
|
|
|
{
|
2021-12-17 04:00:24 +00:00
|
|
|
m_fieldsSize = new_size;
|
2021-12-16 14:39:58 +00:00
|
|
|
|
|
|
|
AdjustFieldsGridColumns();
|
|
|
|
}
|
|
|
|
|
2022-01-26 01:57:42 +00:00
|
|
|
// We store this value to check whether the dialog is changing size. This might indicate
|
2023-12-14 12:23:50 +00:00
|
|
|
// that the user is scaling the dialog with a grid-cell-editor shown. Some editors do not
|
|
|
|
// close (at least on GTK) when the user drags a dialog corner
|
|
|
|
m_lastRequestedFieldsSize = new_size;
|
2022-01-26 01:57:42 +00:00
|
|
|
|
2021-12-16 14:39:58 +00:00
|
|
|
// Always propagate for a grid repaint (needed if the height changes, as well as width)
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnSizePinsGrid( wxSizeEvent& event )
|
|
|
|
{
|
2021-12-17 04:00:24 +00:00
|
|
|
wxSize new_size = event.GetSize();
|
2021-12-16 14:39:58 +00:00
|
|
|
|
2023-12-14 12:23:50 +00:00
|
|
|
if( ( !m_editorShown || m_lastRequestedPinsSize != new_size ) && m_pinsSize != new_size )
|
2021-12-16 14:39:58 +00:00
|
|
|
{
|
2021-12-17 04:00:24 +00:00
|
|
|
m_pinsSize = new_size;
|
2021-12-16 14:39:58 +00:00
|
|
|
|
|
|
|
AdjustPinsGridColumns();
|
2019-02-27 07:07:32 +00:00
|
|
|
}
|
2019-04-27 12:50:21 +00:00
|
|
|
|
2023-12-14 12:23:50 +00:00
|
|
|
// We store this value to check whether the dialog is changing size. This might indicate
|
|
|
|
// that the user is scaling the dialog with a grid-cell-editor shown. Some editors do not
|
|
|
|
// close (at least on GTK) when the user drags a dialog corner
|
|
|
|
m_lastRequestedPinsSize = new_size;
|
|
|
|
|
2019-04-27 12:50:21 +00:00
|
|
|
// Always propagate for a grid repaint (needed if the height changes, as well as width)
|
|
|
|
event.Skip();
|
2018-03-05 00:06:12 +00:00
|
|
|
}
|
2019-02-20 23:20:06 +00:00
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnInitDlg( wxInitDialogEvent& event )
|
2019-02-20 23:20:06 +00:00
|
|
|
{
|
|
|
|
TransferDataToWindow();
|
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2022-12-24 22:18:05 +00:00
|
|
|
|
|
|
|
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
|
|
|
|
|
|
|
if( cfg && cfg->m_Appearance.edit_symbol_width > 0 && cfg->m_Appearance.edit_symbol_height > 0 )
|
|
|
|
SetSize( cfg->m_Appearance.edit_symbol_width, cfg->m_Appearance.edit_symbol_height );
|
2019-02-27 07:07:32 +00:00
|
|
|
}
|
2021-10-25 11:34:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnCheckBox( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-13 09:00:00 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnUnitChoice( wxCommandEvent& event )
|
2021-10-25 11:34:30 +00:00
|
|
|
{
|
2022-08-13 09:00:00 +00:00
|
|
|
if( m_dataModel )
|
|
|
|
{
|
2022-09-05 10:57:07 +00:00
|
|
|
EDA_ITEM_FLAGS flags = m_symbol->GetFlags();
|
|
|
|
|
2022-08-13 09:00:00 +00:00
|
|
|
int unit_selection = m_unitChoice->GetSelection() + 1;
|
|
|
|
|
|
|
|
// We need to select a new unit to build the new unit pin list
|
|
|
|
// but we should not change the symbol, so the initial unit will be selected
|
|
|
|
// after rebuilding the pin list
|
|
|
|
int old_unit = m_symbol->GetUnit();
|
|
|
|
m_symbol->SetUnit( unit_selection );
|
|
|
|
|
|
|
|
// Rebuild a copy of the pins of the new unit for editing
|
|
|
|
m_dataModel->clear();
|
|
|
|
|
|
|
|
for( const std::unique_ptr<SCH_PIN>& pin : m_symbol->GetRawPins() )
|
|
|
|
m_dataModel->push_back( *pin );
|
|
|
|
|
|
|
|
m_dataModel->SortRows( COL_NUMBER, true );
|
|
|
|
m_dataModel->BuildAttrs();
|
|
|
|
|
2022-12-16 13:42:49 +00:00
|
|
|
m_symbol->SetUnit( old_unit );
|
2022-09-05 10:57:07 +00:00
|
|
|
|
|
|
|
// Restore m_Flag modified by SetUnit()
|
|
|
|
m_symbol->ClearFlags();
|
|
|
|
m_symbol->SetFlags( flags );
|
2022-08-13 09:00:00 +00:00
|
|
|
}
|
|
|
|
|
2021-10-25 11:34:30 +00:00
|
|
|
OnModify();
|
2022-01-24 17:54:05 +00:00
|
|
|
}
|
2022-09-02 19:48:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_PROPERTIES::onUpdateEditSymbol( wxUpdateUIEvent& event )
|
|
|
|
{
|
|
|
|
event.Enable( m_symbol && m_symbol->GetLibSymbolRef() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_PROPERTIES::onUpdateEditLibrarySymbol( wxUpdateUIEvent& event )
|
|
|
|
{
|
|
|
|
event.Enable( m_symbol && m_symbol->GetLibSymbolRef() );
|
|
|
|
}
|
|
|
|
|