2013-03-30 00:06:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-01-28 11:15:47 +00:00
|
|
|
* Copyright (C) 2004-2021 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
|
|
|
|
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>
|
2018-02-28 16:54:35 +00:00
|
|
|
#include <menus_helpers.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>
|
2018-05-30 10:52:19 +00:00
|
|
|
#include <widgets/wx_grid.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>
|
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
|
|
|
|
2016-08-11 12:42:13 +00:00
|
|
|
#ifdef KICAD_SPICE
|
2016-08-11 12:41:40 +00:00
|
|
|
#include <dialog_spice_model.h>
|
2016-08-11 12:42:13 +00:00
|
|
|
#endif /* KICAD_SPICE */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
|
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>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
std::vector<wxGridCellAttr*> m_nameAttrs;
|
|
|
|
wxGridCellAttr* m_readOnlyAttr;
|
|
|
|
wxGridCellAttr* m_typeAttr;
|
|
|
|
wxGridCellAttr* m_shapeAttr;
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetValue( int aRow, int aCol ) override
|
|
|
|
{
|
|
|
|
return GetValue( at( aRow ), aCol );
|
|
|
|
}
|
|
|
|
|
|
|
|
static wxString GetValue( const SCH_PIN& aPin, int aCol )
|
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case COL_NUMBER: return aPin.GetNumber();
|
|
|
|
case COL_BASE_NAME: return aPin.GetLibPin()->GetName();
|
|
|
|
case COL_ALT_NAME: return aPin.GetAlt();
|
|
|
|
case COL_TYPE: return PinTypeNames()[static_cast<int>( aPin.GetType() )];
|
|
|
|
case COL_SHAPE: return PinShapeNames()[static_cast<int>( aPin.GetShape() )];
|
|
|
|
default: wxFAIL; return wxEmptyString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind ) override
|
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case COL_NUMBER:
|
|
|
|
case COL_BASE_NAME:
|
|
|
|
m_readOnlyAttr->IncRef();
|
|
|
|
return m_readOnlyAttr;
|
|
|
|
|
|
|
|
case COL_ALT_NAME:
|
|
|
|
m_nameAttrs[ aRow ]->IncRef();
|
|
|
|
return m_nameAttrs[ aRow ];
|
|
|
|
|
|
|
|
case COL_TYPE:
|
|
|
|
m_typeAttr->IncRef();
|
|
|
|
return m_typeAttr;
|
|
|
|
|
|
|
|
case COL_SHAPE:
|
|
|
|
m_shapeAttr->IncRef();
|
|
|
|
return m_shapeAttr;
|
|
|
|
|
|
|
|
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 );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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 ),
|
|
|
|
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
|
|
|
|
2021-02-17 14:06:19 +00:00
|
|
|
m_fields = new FIELDS_GRID_TABLE<SCH_FIELD>( this, aParent, m_fieldsGrid, m_part );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2019-02-27 07:07:32 +00:00
|
|
|
m_width = 0;
|
2020-11-12 21:31:41 +00:00
|
|
|
m_delayedFocusRow = REFERENCE_FIELD;
|
2018-02-28 16:54:35 +00:00
|
|
|
m_delayedFocusColumn = FDC_VALUE;
|
2020-10-17 23:14:17 +00:00
|
|
|
m_delayedSelection = true;
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2016-08-11 12:42:13 +00:00
|
|
|
#ifndef KICAD_SPICE
|
2018-02-28 16:54:35 +00:00
|
|
|
m_spiceFieldsButton->Hide();
|
2016-08-11 12:42:13 +00:00
|
|
|
#endif /* not KICAD_SPICE */
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// disable some options inside the edit dialog which can cause problems while dragging
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_symbol->IsDragging() )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2020-09-02 00:37:28 +00:00
|
|
|
m_orientationLabel->Disable();
|
|
|
|
m_orientationCtrl->Disable();
|
|
|
|
m_mirrorLabel->Disable();
|
|
|
|
m_mirrorCtrl->Disable();
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
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 );
|
|
|
|
m_fieldsGrid->PushEventHandler( new FIELDS_GRID_TRICKS( m_fieldsGrid, this ) );
|
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
|
2021-07-28 15:39:40 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
2020-03-29 16:42:24 +00:00
|
|
|
|
|
|
|
if( cfg )
|
2020-05-04 12:01:35 +00:00
|
|
|
{
|
2020-03-29 16:42:24 +00:00
|
|
|
m_shownColumns = cfg->m_Appearance.edit_component_visible_columns;
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->ShowHideColumns( m_shownColumns );
|
2020-05-04 12:01:35 +00:00
|
|
|
}
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2020-12-03 09:42:31 +00:00
|
|
|
if( m_part && m_part->HasConversion() )
|
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
|
|
|
|
|
|
|
m_pinGrid->PushEventHandler( new GRID_TRICKS( m_pinGrid ) );
|
2021-12-12 17:27:40 +00:00
|
|
|
m_pinGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
|
2020-09-02 11:50:07 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
wxToolTip::Enable( true );
|
2018-02-28 16:54:35 +00:00
|
|
|
m_stdDialogButtonSizerOK->SetDefault();
|
2009-07-26 17:16:42 +00:00
|
|
|
|
2017-09-12 07:43:51 +00:00
|
|
|
// Configure button logos
|
2021-03-08 02:59:07 +00:00
|
|
|
m_bpAdd->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
|
|
|
|
m_bpDelete->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
|
|
|
|
m_bpMoveUp->SetBitmap( KiBitmap( BITMAPS::small_up ) );
|
|
|
|
m_bpMoveDown->SetBitmap( KiBitmap( 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...
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->Connect( wxEVT_GRID_CELL_CHANGING,
|
2020-10-20 21:26:00 +00:00
|
|
|
wxGridEventHandler( DIALOG_SYMBOL_PROPERTIES::OnGridCellChanging ),
|
|
|
|
nullptr, this );
|
2020-09-02 11:50:07 +00:00
|
|
|
|
|
|
|
m_pinGrid->Connect( wxEVT_GRID_COL_SORT,
|
2020-10-20 21:26:00 +00:00
|
|
|
wxGridEventHandler( DIALOG_SYMBOL_PROPERTIES::OnPinTableColSort ),
|
|
|
|
nullptr, this );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
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
|
|
|
{
|
2021-07-28 15:39:40 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
2020-03-29 16:42:24 +00:00
|
|
|
|
|
|
|
if( cfg )
|
2020-09-02 11:50:07 +00:00
|
|
|
cfg->m_Appearance.edit_component_visible_columns = m_fieldsGrid->GetShownColumns();
|
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
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->Disconnect( wxEVT_GRID_CELL_CHANGING,
|
2020-10-20 21:26:00 +00:00
|
|
|
wxGridEventHandler( DIALOG_SYMBOL_PROPERTIES::OnGridCellChanging ),
|
|
|
|
nullptr, this );
|
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
m_pinGrid->Disconnect( wxEVT_GRID_COL_SORT,
|
2020-10-17 23:25:39 +00:00
|
|
|
wxGridEventHandler( DIALOG_SYMBOL_PROPERTIES::OnPinTableColSort ),
|
2020-09-02 11:50:07 +00:00
|
|
|
nullptr, 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
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_FIELD field( wxPoint( 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 );
|
|
|
|
AdjustGridColumns( m_fieldsGrid->GetRect().GetWidth() );
|
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
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
for( int ii = 1; ii <= m_symbol->GetUnitCount(); ii++ )
|
2021-06-10 18:51:46 +00:00
|
|
|
m_unitChoice->Append( LIB_SYMBOL::SubReference( ii, false ) );
|
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
|
|
|
}
|
|
|
|
|
2020-12-03 09:42:31 +00:00
|
|
|
if( m_part && m_part->HasConversion() )
|
2014-09-17 16:04:04 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_symbol->GetConvert() > LIB_ITEM::LIB_CONVERT::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
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
m_cbExcludeFromBom->SetValue( !m_symbol->GetIncludeInBom() );
|
|
|
|
m_cbExcludeFromBoard->SetValue( !m_symbol->GetIncludeOnBoard() );
|
2020-06-03 12:30:57 +00:00
|
|
|
|
2020-12-03 09:42:31 +00:00
|
|
|
if( m_part )
|
|
|
|
{
|
|
|
|
m_ShowPinNumButt->SetValue( m_part->ShowPinNumbers() );
|
|
|
|
m_ShowPinNameButt->SetValue( m_part->ShowPinNames() );
|
|
|
|
}
|
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();
|
2019-04-09 15:58:23 +00:00
|
|
|
|
2021-02-10 11:48:58 +00:00
|
|
|
// Workaround to fix an annoying issue on wxGTK: in some cases selecting a field
|
|
|
|
// to change its value make this value invisible. It happens until the dialog is resized.
|
|
|
|
// So I am guessing there is a problem when initializing sizers settings
|
|
|
|
// Do not create issues on other OS
|
|
|
|
wxSafeYield(); // slice of time to handle events generated when creating the
|
|
|
|
// dialog, especially size events
|
|
|
|
m_fieldsGrid->Layout(); // Force recalculating all sizers in m_fieldsGrid
|
|
|
|
|
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
|
|
|
{
|
2016-08-11 12:42:13 +00:00
|
|
|
#ifdef KICAD_SPICE
|
2018-02-28 16:54:35 +00:00
|
|
|
int diff = m_fields->size();
|
2016-08-11 12:41:10 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
DIALOG_SPICE_MODEL dialog( this, *m_symbol, m_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
|
|
|
|
2020-03-25 18:06:18 +00:00
|
|
|
diff = (int) m_fields->size() - diff;
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( diff > 0 )
|
|
|
|
{
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, diff );
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->ProcessTableMessage( msg );
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
|
|
|
else if( diff < 0 )
|
|
|
|
{
|
2020-02-14 07:36:25 +00:00
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, -diff );
|
2020-09-02 11:50:07 +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();
|
2018-02-28 16:54:35 +00:00
|
|
|
#endif /* KICAD_SPICE */
|
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
|
|
|
wxString msg;
|
|
|
|
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
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_delayedFocusColumn = FDC_VALUE;
|
2020-11-12 21:31:41 +00:00
|
|
|
m_delayedFocusRow = REFERENCE_FIELD;
|
2020-10-17 23:14:17 +00:00
|
|
|
m_delayedSelection = false;
|
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
|
|
|
|
|
|
|
m_delayedFocusColumn = FDC_NAME;
|
|
|
|
m_delayedFocusRow = i;
|
2020-10-17 23:14:17 +00:00
|
|
|
m_delayedSelection = false;
|
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;
|
|
|
|
|
2020-05-05 14:55:54 +00:00
|
|
|
SCH_SCREEN* currentScreen = GetParent()->GetScreen();
|
2020-08-30 17:57:10 +00:00
|
|
|
SCHEMATIC& schematic = GetParent()->Schematic();
|
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.
|
2021-06-10 14:10:55 +00:00
|
|
|
currentScreen->Remove( m_symbol );
|
2020-05-05 14:55:54 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
wxString msg;
|
|
|
|
|
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 )
|
|
|
|
GetParent()->SaveCopyInUndoList( currentScreen, m_symbol, UNDO_REDO::CHANGED, false );
|
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() )
|
2021-06-10 14:10:55 +00:00
|
|
|
m_symbol->SetConvert( LIB_ITEM::LIB_CONVERT::DEMORGAN );
|
2019-04-15 13:59:36 +00:00
|
|
|
else
|
2021-06-10 14:10:55 +00:00
|
|
|
m_symbol->SetConvert( LIB_ITEM::LIB_CONVERT::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
|
|
|
{
|
2021-05-06 11:13:08 +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
|
|
|
|
2014-12-16 18:58:26 +00:00
|
|
|
// Restore m_Flag modified by SetUnit() and other change settings
|
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 )
|
2021-06-10 14:10:55 +00:00
|
|
|
m_fields->at( i ).Offset( m_symbol->GetPosition() );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2021-06-17 21:22:10 +00:00
|
|
|
LIB_SYMBOL* entry = GetParent()->GetLibSymbol( m_symbol->GetLibId() );
|
2011-05-31 16:29:14 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( entry && entry->IsPower() )
|
2021-06-10 14:10:55 +00:00
|
|
|
m_fields->at( VALUE_FIELD ).SetText( m_symbol->GetLibId().GetLibItemName() );
|
2008-11-26 00:20:16 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Push all fields to the symbol -except- for those which are TEMPLATE_FIELDNAMES
|
2020-05-10 18:41:29 +00:00
|
|
|
// with empty values.
|
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();
|
|
|
|
|
|
|
|
for( size_t i = 0; i < m_fields->size(); ++i )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
SCH_FIELD& field = m_fields->at( i );
|
2020-05-10 18:41:29 +00:00
|
|
|
bool emptyTemplateField = false;
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2020-05-10 18:41:29 +00:00
|
|
|
if( i >= MANDATORY_FIELDS )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2020-08-30 17:57:10 +00:00
|
|
|
for( const TEMPLATE_FIELDNAME& fieldname :
|
|
|
|
schematic.Settings().m_TemplateFieldNames.GetTemplateFieldNames() )
|
2011-08-30 19:24:28 +00:00
|
|
|
{
|
2020-05-10 18:41:29 +00:00
|
|
|
if( field.GetName() == fieldname.m_Name && field.GetText().IsEmpty() )
|
|
|
|
{
|
|
|
|
emptyTemplateField = true;
|
|
|
|
break;
|
|
|
|
}
|
2011-08-30 19:24:28 +00:00
|
|
|
}
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-10 18:41:29 +00:00
|
|
|
if( !emptyTemplateField )
|
|
|
|
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
|
|
|
|
2020-09-06 12:05:07 +00:00
|
|
|
// Similar for Value and Footprint, except that the GUI behaviour is that they are kept
|
|
|
|
// in sync between multiple instances.
|
2021-06-10 14:10:55 +00:00
|
|
|
m_symbol->SetValue( m_fields->at( VALUE_FIELD ).GetText() );
|
|
|
|
m_symbol->SetFootprint( m_fields->at( FOOTPRINT_FIELD ).GetText() );
|
2020-09-06 12:05:07 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
m_symbol->SetIncludeInBom( !m_cbExcludeFromBom->IsChecked() );
|
|
|
|
m_symbol->SetIncludeOnBoard( !m_cbExcludeFromBoard->IsChecked() );
|
2020-06-03 12:30:57 +00:00
|
|
|
|
|
|
|
// The value, footprint and datasheet fields and exclude from bill of materials setting
|
|
|
|
// should be kept 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;
|
|
|
|
constexpr bool appendUndo = true;
|
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
|
|
|
{
|
2020-10-24 20:55:32 +00:00
|
|
|
GetParent()->SaveCopyInUndoList( screen, otherUnit, UNDO_REDO::CHANGED,
|
|
|
|
appendUndo );
|
2020-11-12 21:31:41 +00:00
|
|
|
otherUnit->SetValue( m_fields->at( VALUE_FIELD ).GetText() );
|
|
|
|
otherUnit->SetFootprint( m_fields->at( FOOTPRINT_FIELD ).GetText() );
|
|
|
|
otherUnit->GetField( DATASHEET_FIELD )->SetText( m_fields->at( DATASHEET_FIELD ).GetText() );
|
2020-07-13 11:21:40 +00:00
|
|
|
otherUnit->SetIncludeInBom( !m_cbExcludeFromBom->IsChecked() );
|
|
|
|
otherUnit->SetIncludeOnBoard( !m_cbExcludeFromBoard->IsChecked() );
|
2021-10-06 03:10:20 +00:00
|
|
|
GetParent()->UpdateItem( otherUnit, false, true );
|
2020-07-13 11:21:40 +00:00
|
|
|
}
|
2018-01-06 12:36:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
// Update any assignments
|
2020-10-20 21:26:00 +00:00
|
|
|
if( m_dataModel )
|
2020-09-02 11:50:07 +00:00
|
|
|
{
|
2020-10-20 21:26:00 +00:00
|
|
|
for( const SCH_PIN& model_pin : *m_dataModel )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
// map from the edited copy back to the "real" pin in the symbol.
|
|
|
|
SCH_PIN* src_pin = m_symbol->GetPin( model_pin.GetLibPin() );
|
2020-10-20 21:26:00 +00:00
|
|
|
src_pin->SetAlt( model_pin.GetAlt() );
|
|
|
|
}
|
2020-09-02 11:50:07 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
currentScreen->Append( m_symbol );
|
2018-10-16 13:11:33 +00:00
|
|
|
GetParent()->TestDanglingEnds();
|
2021-10-06 03:10:20 +00:00
|
|
|
GetParent()->UpdateItem( m_symbol, false, true );
|
2018-10-18 09:50:43 +00:00
|
|
|
GetParent()->OnModify();
|
2020-08-13 21:30:30 +00:00
|
|
|
|
|
|
|
// This must go after OnModify() so that the connectivity graph will have been updated.
|
|
|
|
GetParent()->GetToolManager()->PostEvent( EVENTS::SelectedItemsModified );
|
2008-11-26 00:20:16 +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();
|
|
|
|
m_delayedFocusRow = event.GetRow();
|
|
|
|
m_delayedFocusColumn = event.GetCol();
|
2020-10-17 23:14:17 +00:00
|
|
|
m_delayedSelection = false;
|
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();
|
|
|
|
m_delayedFocusRow = event.GetRow();
|
|
|
|
m_delayedFocusColumn = event.GetCol();
|
2020-10-17 23:14:17 +00:00
|
|
|
m_delayedSelection = false;
|
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 )
|
2020-10-17 23:14:17 +00:00
|
|
|
m_delayedSelection= true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2020-05-23 15:50:08 +00:00
|
|
|
int fieldID = m_fields->size();
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_FIELD newField( wxPoint( 0, 0 ), fieldID, m_symbol,
|
2020-05-23 15:50:08 +00:00
|
|
|
TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldID ) );
|
2014-05-05 17:28:40 +00:00
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
newField.SetTextAngle( m_fields->at( REFERENCE_FIELD ).GetTextAngle() );
|
2020-05-23 15:50:08 +00:00
|
|
|
newField.SetTextSize( wxSize( 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 */ );
|
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();
|
|
|
|
|
|
|
|
if( m_pinGrid->GetCellValue( row, COL_ALT_NAME ) == m_dataModel->GetValue( row, COL_BASE_NAME ) )
|
|
|
|
m_dataModel->SetValue( row, COL_ALT_NAME, wxEmptyString );
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::AdjustGridColumns( int aWidth )
|
2008-11-24 21:06:50 +00:00
|
|
|
{
|
2020-09-02 11:50:07 +00:00
|
|
|
wxGridUpdateLocker deferRepaintsTillLeavingScope;
|
|
|
|
|
2019-02-27 07:07:32 +00:00
|
|
|
m_width = aWidth;
|
2020-09-02 11:50:07 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Account for scroll bars
|
2020-09-02 11:50:07 +00:00
|
|
|
int fieldsWidth = aWidth - ( m_fieldsGrid->GetSize().x - m_fieldsGrid->GetClientSize().x );
|
|
|
|
int pinTblWidth = aWidth - ( m_pinGrid->GetSize().x - m_pinGrid->GetClientSize().x );
|
|
|
|
|
|
|
|
m_fieldsGrid->AutoSizeColumn( 0 );
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-11-27 21:03:42 +00:00
|
|
|
int colSize = std::max( fieldsWidth - fixedColsWidth, -1 );
|
|
|
|
colSize = ( colSize == 0 ) ? -1 : colSize; // don't hide the column!
|
|
|
|
|
|
|
|
m_fieldsGrid->SetColSize( 1, colSize );
|
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
|
|
|
// Why? I haven't a clue....
|
|
|
|
pinTblWidth += 22;
|
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
|
|
|
{
|
2020-09-02 11:50:07 +00:00
|
|
|
wxString 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() )
|
|
|
|
AdjustGridColumns( m_fieldsGrid->GetRect().GetWidth() );
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Handle a delayed focus
|
|
|
|
if( m_delayedFocusRow >= 0 )
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
{
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->SetFocus();
|
|
|
|
m_fieldsGrid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn );
|
|
|
|
m_fieldsGrid->SetGridCursor( m_delayedFocusRow, m_delayedFocusColumn );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2020-09-02 11:50:07 +00:00
|
|
|
m_fieldsGrid->EnableCellEditControl( true );
|
|
|
|
m_fieldsGrid->ShowCellEditControl();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_delayedFocusRow = -1;
|
|
|
|
m_delayedFocusColumn = -1;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
}
|
2020-10-17 23:14:17 +00:00
|
|
|
|
|
|
|
// Handle a delayed selection
|
|
|
|
if( m_delayedSelection )
|
|
|
|
{
|
2020-11-12 21:31:41 +00:00
|
|
|
wxGridCellEditor* cellEditor = m_fieldsGrid->GetCellEditor( REFERENCE_FIELD, FDC_VALUE );
|
2020-10-17 23:14:17 +00:00
|
|
|
|
2020-10-20 23:28:56 +00:00
|
|
|
if( wxTextEntry* txt = dynamic_cast<wxTextEntry*>( cellEditor->GetControl() ) )
|
2020-10-25 16:41:38 +00:00
|
|
|
KIUI::SelectReferenceNumber( txt );
|
2020-10-17 23:14:17 +00:00
|
|
|
|
|
|
|
cellEditor->DecRef(); // we're done; must release
|
|
|
|
|
|
|
|
m_delayedSelection = false;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2017-08-25 11:37:21 +00:00
|
|
|
|
|
|
|
|
2020-10-17 23:25:39 +00:00
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnSizeGrid( wxSizeEvent& event )
|
2017-08-25 11:37:21 +00:00
|
|
|
{
|
2021-07-28 15:39:40 +00:00
|
|
|
int new_size = event.GetSize().GetX();
|
2017-08-25 11:37:21 +00:00
|
|
|
|
2019-02-27 07:07:32 +00:00
|
|
|
if( m_width != new_size )
|
|
|
|
{
|
|
|
|
AdjustGridColumns( new_size );
|
2021-03-15 23:41:05 +00:00
|
|
|
Layout();
|
2019-02-27 07:07:32 +00:00
|
|
|
}
|
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();
|
2019-02-27 07:07:32 +00:00
|
|
|
}
|
2021-10-25 11:34:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnCheckBox( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SYMBOL_PROPERTIES::OnChoice( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
OnModify();
|
|
|
|
}
|