2016-03-16 14:14:00 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-04-12 19:53:45 +00:00
|
|
|
* Copyright (C) 2020 Oleg Endo <olegendo@gcc.gnu.org>
|
2019-02-19 19:04:40 +00:00
|
|
|
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2021-01-06 14:37:38 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-03-16 14:14:00 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2020-12-16 13:31:32 +00:00
|
|
|
#include <tools/board_inspection_tool.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2021-06-06 23:34:21 +00:00
|
|
|
#include <confirm.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2020-11-11 12:59:59 +00:00
|
|
|
#include <dialog_net_inspector.h>
|
2016-03-16 14:14:00 +00:00
|
|
|
#include <eda_pattern_match.h>
|
2019-04-15 08:10:51 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2020-11-04 02:49:19 +00:00
|
|
|
#include <view/view.h>
|
2016-03-16 14:14:00 +00:00
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <pcb_painter.h>
|
2020-11-04 02:49:19 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
2020-04-12 19:20:30 +00:00
|
|
|
#include <connectivity/connectivity_algo.h>
|
2020-06-08 18:36:25 +00:00
|
|
|
#include <dialogs/dialog_text_entry.h>
|
|
|
|
#include <validators.h>
|
|
|
|
#include <bitmaps.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
#include <wx/tokenzr.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/filedlg.h>
|
|
|
|
#include <wx/dcclient.h>
|
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
#include <bitset>
|
2016-03-16 14:14:00 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
struct DIALOG_NET_INSPECTOR::COLUMN_DESC
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CSV_NONE = 0,
|
|
|
|
CSV_QUOTE = 1 << 0
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned int num;
|
|
|
|
wxString display_name;
|
|
|
|
wxString csv_name;
|
|
|
|
unsigned int csv_flags;
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
operator unsigned int() const
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
return num;
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
#define def_col( c, num, name, csv_name, csv_flags ) \
|
|
|
|
const DIALOG_NET_INSPECTOR::COLUMN_DESC DIALOG_NET_INSPECTOR::c = { num, \
|
|
|
|
name, \
|
|
|
|
csv_name, \
|
|
|
|
COLUMN_DESC::csv_flags }
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-04 02:53:06 +00:00
|
|
|
def_col( COLUMN_NET, 0, _( "Net" ), _( "Net Code" ), CSV_NONE );
|
|
|
|
def_col( COLUMN_NAME, 1, _( "Name" ), _( "Net Name" ), CSV_QUOTE );
|
|
|
|
def_col( COLUMN_PAD_COUNT, 2, _( "Pad Count" ), _( "Pad Count" ), CSV_NONE );
|
|
|
|
def_col( COLUMN_VIA_COUNT, 3, _( "Via Count" ), _( "Via Count" ), CSV_NONE );
|
|
|
|
def_col( COLUMN_VIA_LENGTH, 4, _( "Via Length" ), _( "Via Length" ), CSV_NONE );
|
2021-03-02 08:56:09 +00:00
|
|
|
def_col( COLUMN_BOARD_LENGTH, 5, _( "Track Length" ), _( "Track Length" ), CSV_NONE );
|
2020-11-04 02:53:06 +00:00
|
|
|
def_col( COLUMN_CHIP_LENGTH, 6, _( "Die Length" ), _( "Die Length" ), CSV_NONE );
|
|
|
|
def_col( COLUMN_TOTAL_LENGTH, 7, _( "Total Length" ), _( "Net Length" ), CSV_NONE );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
|
|
|
#undef def_col
|
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
class DIALOG_NET_INSPECTOR::LIST_ITEM
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
private:
|
|
|
|
// an item can be the child of only one parent at a time.
|
|
|
|
// FIXME: could use a more lightweight container like intrusive forward list.
|
|
|
|
LIST_ITEM* m_parent = nullptr;
|
|
|
|
std::vector<LIST_ITEM*> m_children;
|
|
|
|
|
|
|
|
bool m_is_group = false;
|
|
|
|
unsigned int m_group_number = 0;
|
|
|
|
NETINFO_ITEM* m_net = nullptr;
|
|
|
|
unsigned int m_pad_count = 0;
|
|
|
|
unsigned int m_via_count = 0;
|
|
|
|
uint64_t m_via_length = 0;
|
|
|
|
uint64_t m_board_wire_length = 0;
|
|
|
|
uint64_t m_chip_wire_length = 0;
|
|
|
|
|
|
|
|
// dirty bits to record when some attribute has changed. this is to
|
|
|
|
// avoid unnecessary resort operations.
|
|
|
|
std::bitset<5> m_column_changed;
|
|
|
|
|
|
|
|
// cached formatted net name for faster display sorting.
|
|
|
|
wxString m_net_name;
|
|
|
|
|
|
|
|
public:
|
2020-11-11 12:59:59 +00:00
|
|
|
LIST_ITEM( unsigned int aGroupNumber, const wxString& aGroupName ) :
|
|
|
|
m_is_group( true ),
|
|
|
|
m_group_number( aGroupNumber ),
|
|
|
|
m_net_name( aGroupName )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
LIST_ITEM( NETINFO_ITEM* aNet ) :
|
|
|
|
m_net( aNet )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
m_net_name = UnescapeString( aNet->GetNetname() );
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
LIST_ITEM& operator=( const LIST_ITEM& ) = delete;
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
bool GetIsGroup() const { return m_is_group; }
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
auto ChildrenBegin() const { return m_children.begin(); }
|
|
|
|
auto ChildrenEnd() const { return m_children.end(); }
|
|
|
|
unsigned int ChildrenCount() const { return m_children.size(); }
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
NETINFO_ITEM* GetNet() const { return m_net; }
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
int GetNetCode() const
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2020-12-08 13:02:08 +00:00
|
|
|
return GetIsGroup() ? ( 0 - int( m_group_number ) - 1 ) : m_net->GetNetCode();
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
const wxString& GetNetName() const { return m_net_name; }
|
|
|
|
const wxString& GetGroupName() const { return m_net_name; }
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void ResetColumnChangedBits()
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
m_column_changed.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
#define gen( mvar, chg_bit, get, set, add, sub, changed ) \
|
|
|
|
decltype( mvar ) get() const \
|
|
|
|
{ \
|
|
|
|
return mvar; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
bool changed() const \
|
|
|
|
{ \
|
|
|
|
return m_column_changed[chg_bit]; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void set( const decltype( mvar )& aValue ) \
|
|
|
|
{ \
|
|
|
|
if( m_parent ) \
|
|
|
|
m_parent->set( m_parent->get() - mvar + aValue ); \
|
|
|
|
\
|
2020-11-04 05:17:17 +00:00
|
|
|
static_assert( chg_bit < decltype( m_column_changed )().size(), "" ); \
|
2020-11-04 02:49:19 +00:00
|
|
|
m_column_changed[chg_bit] = m_column_changed[chg_bit] | ( mvar != aValue ); \
|
|
|
|
mvar = aValue; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void add( const decltype( mvar )& aValue ) \
|
|
|
|
{ \
|
|
|
|
if( m_parent ) \
|
|
|
|
m_parent->add( aValue ); \
|
|
|
|
\
|
2020-11-04 05:17:17 +00:00
|
|
|
static_assert( chg_bit < decltype( m_column_changed )().size(), "" ); \
|
2020-11-04 02:49:19 +00:00
|
|
|
m_column_changed[chg_bit] = m_column_changed[chg_bit] | ( aValue != 0 ); \
|
|
|
|
mvar += aValue; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void sub( const decltype( mvar )& aValue ) \
|
|
|
|
{ \
|
|
|
|
if( m_parent ) \
|
|
|
|
m_parent->sub( aValue ); \
|
|
|
|
\
|
2020-11-04 05:17:17 +00:00
|
|
|
static_assert( chg_bit < decltype( m_column_changed )().size(), "" ); \
|
2020-11-04 02:49:19 +00:00
|
|
|
m_column_changed[chg_bit] = m_column_changed[chg_bit] | ( aValue != 0 ); \
|
|
|
|
mvar -= aValue; \
|
|
|
|
}
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
gen( m_pad_count, 0, GetPadCount, SetPadCount, AddPadCount, SubPadCount, PadCountChanged );
|
|
|
|
gen( m_via_count, 1, GetViaCount, SetViaCount, AddViaCount, SubViaCount, ViaCountChanged );
|
|
|
|
gen( m_via_length, 2, GetViaLength, SetViaLength, AddViaLength, SubViaLength, ViaLengthChanged );
|
|
|
|
gen( m_board_wire_length, 3, GetBoardWireLength, SetBoardWireLength, AddBoardWireLength,
|
2021-01-06 13:09:54 +00:00
|
|
|
SubBoardWireLength, BoardWireLengthChanged );
|
2020-11-11 12:59:59 +00:00
|
|
|
gen( m_chip_wire_length, 4, GetChipWireLength, SetChipWireLength, AddChipWireLength,
|
2021-01-06 13:09:54 +00:00
|
|
|
SubChipWireLength, ChipWireLengthChanged );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
#undef gen
|
|
|
|
|
|
|
|
// the total length column is always computed, never stored.
|
2021-01-06 13:09:54 +00:00
|
|
|
unsigned long long int GetTotalLength() const
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
return GetBoardWireLength() + GetViaLength() + GetChipWireLength();
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
bool TotalLengthChanged() const
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2021-05-31 01:44:07 +00:00
|
|
|
return BoardWireLengthChanged() || ViaLengthChanged() || ChipWireLengthChanged();
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
LIST_ITEM* Parent() const
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
return m_parent;
|
|
|
|
}
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void SetParent( LIST_ITEM* aParent )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
if( m_parent == aParent )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( m_parent != nullptr )
|
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
m_parent->SubPadCount( GetPadCount() );
|
|
|
|
m_parent->SubViaCount( GetViaCount() );
|
|
|
|
m_parent->SubViaLength( GetViaLength() );
|
|
|
|
m_parent->SubBoardWireLength( GetBoardWireLength() );
|
|
|
|
m_parent->SubChipWireLength( GetChipWireLength() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
m_parent->m_children.erase( std::find( m_parent->m_children.begin(),
|
|
|
|
m_parent->m_children.end(), this ) );
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_parent = aParent;
|
|
|
|
|
|
|
|
if( m_parent != nullptr )
|
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
m_parent->AddPadCount( GetPadCount() );
|
|
|
|
m_parent->AddViaCount( GetViaCount() );
|
|
|
|
m_parent->AddViaLength( GetViaLength() );
|
|
|
|
m_parent->AddBoardWireLength( GetBoardWireLength() );
|
|
|
|
m_parent->AddChipWireLength( GetChipWireLength() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
m_parent->m_children.push_back( this );
|
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
struct DIALOG_NET_INSPECTOR::LIST_ITEM_NETCODE_CMP_LESS
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
template <typename T>
|
|
|
|
bool operator()( const T& a, const T& b ) const
|
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
return a->GetNetCode() < b->GetNetCode();
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool operator()( const T& a, int b ) const
|
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
return a->GetNetCode() < b;
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool operator()( int a, const T& b ) const
|
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
return a < b->GetNetCode();
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
class DIALOG_NET_INSPECTOR::DATA_MODEL : public wxDataViewModel
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
private:
|
2020-11-11 12:59:59 +00:00
|
|
|
DIALOG_NET_INSPECTOR& m_parent;
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
// primary container, sorted by netcode number.
|
|
|
|
// groups have netcode < 0, so they always come first, in the order
|
|
|
|
// of the filter strings as input by the user (group mode 0, 1) or
|
2021-06-09 19:32:58 +00:00
|
|
|
// in order of occurrence (group mode 2, 3).
|
2020-11-04 02:49:19 +00:00
|
|
|
std::vector<std::unique_ptr<LIST_ITEM>> m_items;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static const auto& columnDesc()
|
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
static const std::array<COLUMN_DESC, 8> r =
|
|
|
|
{ { COLUMN_NET,
|
|
|
|
COLUMN_NAME,
|
|
|
|
COLUMN_PAD_COUNT,
|
|
|
|
COLUMN_VIA_COUNT,
|
|
|
|
COLUMN_VIA_LENGTH,
|
|
|
|
COLUMN_BOARD_LENGTH,
|
|
|
|
COLUMN_CHIP_LENGTH,
|
|
|
|
COLUMN_TOTAL_LENGTH } };
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
DATA_MODEL( DIALOG_NET_INSPECTOR& parent ) : m_parent( parent )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int columnCount() const
|
|
|
|
{
|
|
|
|
return columnDesc().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int itemCount() const
|
|
|
|
{
|
|
|
|
return m_items.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxVariant valueAt( unsigned int aCol, unsigned int aRow ) const
|
|
|
|
{
|
|
|
|
wxVariant r;
|
|
|
|
GetValue( r, wxDataViewItem( const_cast<LIST_ITEM*>( &*( m_items[aRow] ) ) ), aCol );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LIST_ITEM& itemAt( unsigned int aRow ) const
|
|
|
|
{
|
|
|
|
return *m_items.at( aRow );
|
|
|
|
}
|
|
|
|
|
|
|
|
OPT<LIST_ITEM_ITER> findItem( int aNetCode )
|
|
|
|
{
|
|
|
|
auto i = std::lower_bound(
|
|
|
|
m_items.begin(), m_items.end(), aNetCode, LIST_ITEM_NETCODE_CMP_LESS() );
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
if( i == m_items.end() || ( *i )->GetNetCode() != aNetCode )
|
2020-11-04 02:49:19 +00:00
|
|
|
return {};
|
|
|
|
|
|
|
|
return { i };
|
|
|
|
}
|
|
|
|
|
|
|
|
OPT<LIST_ITEM_ITER> findItem( NETINFO_ITEM* aNet )
|
|
|
|
{
|
|
|
|
if( aNet != nullptr )
|
2020-12-08 13:02:08 +00:00
|
|
|
return findItem( aNet->GetNetCode() );
|
2020-11-04 02:49:19 +00:00
|
|
|
else
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
OPT<LIST_ITEM_ITER> addItem( std::unique_ptr<LIST_ITEM> aItem )
|
|
|
|
{
|
|
|
|
if( aItem == nullptr )
|
|
|
|
return {};
|
|
|
|
|
|
|
|
// make sure that the vector is always sorted. usually when new nets are added,
|
|
|
|
// they always get a higher netcode number than the already existing ones.
|
|
|
|
// however, if we've got filtering enabled, we might not have all the nets in
|
|
|
|
// our list, so do a sorted insertion.
|
|
|
|
|
2021-01-06 13:09:54 +00:00
|
|
|
auto new_iter = std::lower_bound( m_items.begin(), m_items.end(), aItem->GetNetCode(),
|
|
|
|
LIST_ITEM_NETCODE_CMP_LESS() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2021-01-06 13:09:54 +00:00
|
|
|
new_iter = m_items.insert( new_iter, std::move( aItem ) );
|
|
|
|
const std::unique_ptr<LIST_ITEM>& new_item = *new_iter;
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
if( m_parent.m_groupBy->IsChecked()
|
|
|
|
&& ( m_parent.m_groupByKind->GetSelection() == 0
|
|
|
|
|| m_parent.m_groupByKind->GetSelection() == 1 ) )
|
|
|
|
{
|
|
|
|
for( unsigned int j = 0; j < m_parent.m_groupFilter.size(); ++j )
|
|
|
|
{
|
2021-01-06 13:09:54 +00:00
|
|
|
if( m_parent.m_groupFilter[j]->Find( new_item->GetNetName() ) )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2021-01-06 13:09:54 +00:00
|
|
|
new_item->SetParent( &*m_items[j] );
|
2020-11-04 02:49:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( m_parent.m_groupBy->IsChecked()
|
|
|
|
&& ( m_parent.m_groupByKind->GetSelection() == 2
|
|
|
|
|| m_parent.m_groupByKind->GetSelection() == 3 ) )
|
|
|
|
{
|
|
|
|
auto groups_begin = m_items.begin();
|
2020-11-04 03:31:43 +00:00
|
|
|
auto groups_end = std::find_if_not( m_items.begin(), m_items.end(),
|
2021-01-06 13:09:54 +00:00
|
|
|
[]( const std::unique_ptr<LIST_ITEM>& x )
|
|
|
|
{
|
|
|
|
return x->GetIsGroup();
|
|
|
|
} );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
for( std::unique_ptr<EDA_PATTERN_MATCH>& f : m_parent.m_groupFilter )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2021-01-06 13:09:54 +00:00
|
|
|
EDA_PATTERN_MATCH::FIND_RESULT match = f->Find( new_item->GetNetName() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
if( match )
|
|
|
|
{
|
2021-01-06 13:09:54 +00:00
|
|
|
wxString match_str = new_item->GetNetName().substr( match.start, match.length );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
auto group = std::find_if( groups_begin, groups_end,
|
2021-01-06 13:09:54 +00:00
|
|
|
[&]( const std::unique_ptr<LIST_ITEM>& x )
|
|
|
|
{
|
|
|
|
return x->GetNetName() == match_str;
|
|
|
|
} );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
if( group == groups_end )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2021-01-06 13:09:54 +00:00
|
|
|
int dist = std::distance( groups_end, groups_begin );
|
2020-11-04 03:31:43 +00:00
|
|
|
group = m_items.insert( groups_end,
|
2021-01-06 13:09:54 +00:00
|
|
|
std::make_unique<LIST_ITEM>( dist, match_str ) );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
groups_end = group + 1;
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
ItemAdded( wxDataViewItem(( *group )->Parent() ),
|
2020-11-04 03:31:43 +00:00
|
|
|
wxDataViewItem( &**group ) );
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 13:09:54 +00:00
|
|
|
new_item->SetParent( &**group );
|
2020-11-04 02:49:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-06 13:09:54 +00:00
|
|
|
ItemAdded( wxDataViewItem( new_item->Parent() ), wxDataViewItem( new_item.get() ) );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2021-01-06 13:09:54 +00:00
|
|
|
return { new_iter };
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void addItems( std::vector<std::unique_ptr<LIST_ITEM>>&& aItems )
|
|
|
|
{
|
|
|
|
if( m_items.empty() )
|
|
|
|
{
|
|
|
|
m_items = std::move( aItems );
|
|
|
|
|
|
|
|
if( m_parent.m_groupBy->IsChecked()
|
|
|
|
&& ( m_parent.m_groupByKind->GetSelection() == 0
|
|
|
|
|| m_parent.m_groupByKind->GetSelection() == 1 ) )
|
|
|
|
{
|
|
|
|
// assume that there are fewer group filters than nets.
|
|
|
|
// walk over the list items and assign them to groups. note that the
|
|
|
|
// first items are group items themselves, so start after those.
|
|
|
|
for( unsigned int i = m_parent.m_groupFilter.size(); i < m_items.size(); ++i )
|
|
|
|
{
|
|
|
|
for( unsigned int j = 0; j < m_parent.m_groupFilter.size(); ++j )
|
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
if( m_parent.m_groupFilter[j]->Find( m_items[ i ]->GetNetName() ) )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
m_items[i]->SetParent( &*m_items[j] );
|
2020-11-04 02:49:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( m_parent.m_groupBy->IsChecked()
|
|
|
|
&& ( m_parent.m_groupByKind->GetSelection() == 2
|
|
|
|
|| m_parent.m_groupByKind->GetSelection() == 3 ) )
|
|
|
|
{
|
|
|
|
// assume that there will be fewer resulting groups than nets.
|
|
|
|
// dynamically generate groups for the actual strings of the match result.
|
|
|
|
// try out each filter on each item and group by the resulting substrings.
|
|
|
|
std::vector<std::unique_ptr<LIST_ITEM>> groups;
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
for( std::unique_ptr<LIST_ITEM>& i : m_items )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
for( std::unique_ptr<EDA_PATTERN_MATCH>& f : m_parent.m_groupFilter )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
EDA_PATTERN_MATCH::FIND_RESULT match = f->Find( i->GetNetName() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
if( match )
|
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
wxString match_str = i->GetNetName().substr( match.start, match.length );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
auto group = std::find_if( groups.begin(), groups.end(),
|
2021-01-06 13:09:54 +00:00
|
|
|
[&]( const std::unique_ptr<LIST_ITEM>& x )
|
|
|
|
{
|
|
|
|
return x->GetNetName() == match_str;
|
|
|
|
} );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
if( group == groups.end() )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
groups.emplace_back( std::make_unique<LIST_ITEM>( groups.size(),
|
|
|
|
match_str ) );
|
|
|
|
group = groups.end() - 1;
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
i->SetParent( &**group );
|
2020-11-04 02:49:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// insert the group items at the front of the items list.
|
2020-11-04 03:31:43 +00:00
|
|
|
for( std::unique_ptr<LIST_ITEM>& g : groups )
|
2020-11-04 02:49:19 +00:00
|
|
|
m_items.emplace_back( std::move( g ) );
|
|
|
|
|
|
|
|
std::rotate( m_items.begin(), m_items.end() - groups.size(), m_items.end() );
|
|
|
|
}
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
for( std::unique_ptr<LIST_ITEM>& i : m_items )
|
2020-11-11 12:59:59 +00:00
|
|
|
ItemAdded( wxDataViewItem( i->Parent() ), wxDataViewItem( &*i ) );
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_items.reserve( m_items.size() + aItems.size() );
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
for( std::unique_ptr<LIST_ITEM>& i : aItems )
|
2020-11-04 02:49:19 +00:00
|
|
|
addItem( std::move( i ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<LIST_ITEM> deleteItem( const OPT<LIST_ITEM_ITER>& aRow )
|
|
|
|
{
|
|
|
|
if( !aRow )
|
|
|
|
return {};
|
|
|
|
|
|
|
|
std::unique_ptr<LIST_ITEM> i = std::move( **aRow );
|
|
|
|
|
|
|
|
// if the row has a parent, detach it first
|
2020-11-11 12:59:59 +00:00
|
|
|
LIST_ITEM* parent = i->Parent();
|
|
|
|
i->SetParent( nullptr );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
m_items.erase( *aRow );
|
2021-02-22 09:39:14 +00:00
|
|
|
ItemDeleted( wxDataViewItem( parent ), wxDataViewItem( &*i ) );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2021-01-06 13:09:54 +00:00
|
|
|
if( parent )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2021-01-06 13:09:54 +00:00
|
|
|
ItemChanged( wxDataViewItem( parent ) );
|
2020-11-04 03:31:43 +00:00
|
|
|
|
2021-01-06 13:09:54 +00:00
|
|
|
// for grouping type 2,3 a group item might disappear if it becomes empty.
|
|
|
|
if( ( m_parent.m_groupByKind->GetSelection() == 2
|
|
|
|
|| m_parent.m_groupByKind->GetSelection() == 3 )
|
|
|
|
&& parent != nullptr && parent->ChildrenCount() == 0 )
|
|
|
|
{
|
|
|
|
auto p = std::find_if( m_items.begin(), m_items.end(),
|
2021-01-06 14:37:38 +00:00
|
|
|
[&]( std::unique_ptr<LIST_ITEM>& x )
|
|
|
|
{
|
|
|
|
return x.get() == parent;
|
|
|
|
} );
|
2021-01-06 13:09:54 +00:00
|
|
|
|
|
|
|
wxASSERT( p != m_items.end() );
|
|
|
|
m_items.erase( p );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2021-01-06 13:09:54 +00:00
|
|
|
ItemDeleted( wxDataViewItem( parent->Parent() ), wxDataViewItem( parent ) );
|
|
|
|
}
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 13:09:54 +00:00
|
|
|
Resort();
|
2020-11-04 02:49:19 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteAllItems()
|
|
|
|
{
|
2020-12-09 00:41:05 +00:00
|
|
|
BeforeReset();
|
2020-11-04 02:49:19 +00:00
|
|
|
m_items.clear();
|
2020-12-09 00:41:05 +00:00
|
|
|
AfterReset();
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void updateItem( const OPT<LIST_ITEM_ITER>& aRow )
|
|
|
|
{
|
2021-01-06 13:09:54 +00:00
|
|
|
if( aRow )
|
|
|
|
{
|
|
|
|
const std::unique_ptr<LIST_ITEM>& listItem = *aRow.get();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2021-01-06 13:09:54 +00:00
|
|
|
if( listItem->Parent() )
|
|
|
|
ItemChanged( wxDataViewItem( listItem->Parent() ) );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2021-01-06 13:09:54 +00:00
|
|
|
ItemChanged( wxDataViewItem( listItem.get() ) );
|
|
|
|
resortIfChanged( listItem.get() );
|
|
|
|
}
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void updateAllItems()
|
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
for( std::unique_ptr<LIST_ITEM>& i : m_items )
|
2021-01-06 13:09:54 +00:00
|
|
|
ItemChanged( wxDataViewItem( i.get() ) );
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void resortIfChanged( LIST_ITEM* aItem )
|
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
if( wxDataViewColumn* column = m_parent.m_netsList->GetSortingColumn() )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
bool changed = false;
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
for( const LIST_ITEM* i = aItem; i != nullptr; i = i->Parent() )
|
2020-11-04 03:31:43 +00:00
|
|
|
changed |= itemColumnChanged( i, column->GetModelColumn() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
for( LIST_ITEM* i = aItem; i != nullptr; i = i->Parent() )
|
|
|
|
i->ResetColumnChangedBits();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
if( changed )
|
|
|
|
Resort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool itemColumnChanged( const LIST_ITEM* aItem, unsigned int aCol ) const
|
|
|
|
{
|
|
|
|
if( aItem == nullptr || aCol >= columnDesc().size() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( aCol == COLUMN_PAD_COUNT )
|
2020-11-11 12:59:59 +00:00
|
|
|
return aItem->PadCountChanged();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
else if( aCol == COLUMN_VIA_COUNT )
|
2020-11-11 12:59:59 +00:00
|
|
|
return aItem->ViaCountChanged();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
else if( aCol == COLUMN_VIA_LENGTH )
|
2020-11-11 12:59:59 +00:00
|
|
|
return aItem->ViaLengthChanged();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
else if( aCol == COLUMN_BOARD_LENGTH )
|
2020-11-11 12:59:59 +00:00
|
|
|
return aItem->BoardWireLengthChanged();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
else if( aCol == COLUMN_CHIP_LENGTH )
|
2020-11-11 12:59:59 +00:00
|
|
|
return aItem->ChipWireLengthChanged();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
else if( aCol == COLUMN_TOTAL_LENGTH )
|
2020-11-11 12:59:59 +00:00
|
|
|
return aItem->TotalLengthChanged();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of wxDataViewModel interface
|
|
|
|
// these are used to query the data model by the GUI view implementation.
|
|
|
|
// these are not supposed to be used to modify the data model. for that
|
|
|
|
// use the public functions above.
|
|
|
|
|
|
|
|
protected:
|
2020-11-04 03:31:43 +00:00
|
|
|
unsigned int GetColumnCount() const override
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
return columnCount();
|
|
|
|
}
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
void GetValue( wxVariant& aOutValue, const wxDataViewItem& aItem,
|
|
|
|
unsigned int aCol ) const override
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
if( LIST_ITEM* i = static_cast<LIST_ITEM*>( aItem.GetID() ) )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
if( aCol == COLUMN_NET && !i->GetIsGroup() )
|
|
|
|
aOutValue = m_parent.formatNetCode( i->GetNet() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
else if( aCol == COLUMN_NET && i->GetIsGroup() )
|
2020-11-04 02:49:19 +00:00
|
|
|
aOutValue = "";
|
|
|
|
|
|
|
|
else if( aCol == COLUMN_NAME )
|
2020-11-11 12:59:59 +00:00
|
|
|
aOutValue = i->GetNetName();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
else if( aCol == COLUMN_PAD_COUNT )
|
2020-11-11 12:59:59 +00:00
|
|
|
aOutValue = m_parent.formatCount( i->GetPadCount() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
else if( aCol == COLUMN_VIA_COUNT )
|
2020-11-11 12:59:59 +00:00
|
|
|
aOutValue = m_parent.formatCount( i->GetViaCount() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
else if( aCol == COLUMN_VIA_LENGTH )
|
2020-11-11 12:59:59 +00:00
|
|
|
aOutValue = m_parent.formatLength( i->GetViaLength() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
else if( aCol == COLUMN_BOARD_LENGTH )
|
2020-11-11 12:59:59 +00:00
|
|
|
aOutValue = m_parent.formatLength( i->GetBoardWireLength() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
else if( aCol == COLUMN_CHIP_LENGTH )
|
2020-11-11 12:59:59 +00:00
|
|
|
aOutValue = m_parent.formatLength( i->GetChipWireLength() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
else if( aCol == COLUMN_TOTAL_LENGTH )
|
2020-11-11 12:59:59 +00:00
|
|
|
aOutValue = m_parent.formatLength( i->GetTotalLength() );
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compareUInt( uint64_t aValue1, uint64_t aValue2, bool aAsc )
|
|
|
|
{
|
|
|
|
if( aAsc )
|
|
|
|
return aValue1 < aValue2 ? -1 : 1;
|
|
|
|
else
|
|
|
|
return aValue2 < aValue1 ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
int Compare( const wxDataViewItem& aItem1, const wxDataViewItem& aItem2,
|
|
|
|
unsigned int aCol, bool aAsc ) const override
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
const LIST_ITEM& i1 = *static_cast<const LIST_ITEM*>( aItem1.GetID() );
|
|
|
|
const LIST_ITEM& i2 = *static_cast<const LIST_ITEM*>( aItem2.GetID() );
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
if( i1.GetIsGroup() && !i2.GetIsGroup() )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if( i2.GetIsGroup() && !i1.GetIsGroup() )
|
|
|
|
return 1;
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
if( aCol == COLUMN_NET && i1.GetNetCode() != i2.GetNetCode() )
|
2020-11-04 03:31:43 +00:00
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
return aAsc ? ( i2.GetNetCode() - i1.GetNetCode() ) : ( i1.GetNetCode() - i2.GetNetCode() );
|
2020-11-04 03:31:43 +00:00
|
|
|
}
|
2020-11-04 02:49:19 +00:00
|
|
|
else if( aCol == COLUMN_NAME )
|
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
const wxString& s1 = i1.GetNetName();
|
|
|
|
const wxString& s2 = i2.GetNetName();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
int res = aAsc ? s1.Cmp( s2 ) : s2.Cmp( s1 );
|
2020-11-04 03:31:43 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
if( res != 0 )
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
else if( aCol == COLUMN_PAD_COUNT && i1.GetPadCount() != i2.GetPadCount() )
|
|
|
|
return compareUInt( i1.GetPadCount(), i2.GetPadCount(), aAsc );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
else if( aCol == COLUMN_VIA_COUNT && i1.GetViaCount() != i2.GetViaCount() )
|
|
|
|
return compareUInt( i1.GetViaCount(), i2.GetViaCount(), aAsc );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
else if( aCol == COLUMN_VIA_LENGTH && i1.GetViaLength() != i2.GetViaLength() )
|
|
|
|
return compareUInt( i1.GetViaLength(), i2.GetViaLength(), aAsc );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
else if( aCol == COLUMN_BOARD_LENGTH && i1.GetBoardWireLength() != i2.GetBoardWireLength() )
|
|
|
|
return compareUInt( i1.GetBoardWireLength(), i2.GetBoardWireLength(), aAsc );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
else if( aCol == COLUMN_CHIP_LENGTH && i1.GetChipWireLength() != i2.GetChipWireLength() )
|
|
|
|
return compareUInt( i1.GetChipWireLength(), i2.GetChipWireLength(), aAsc );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
else if( aCol == COLUMN_TOTAL_LENGTH && i1.GetTotalLength() != i2.GetTotalLength() )
|
|
|
|
return compareUInt( i1.GetTotalLength(), i2.GetTotalLength(), aAsc );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
// when the item values compare equal resort to pointer comparison.
|
|
|
|
wxUIntPtr id1 = wxPtrToUInt( aItem1.GetID() );
|
|
|
|
wxUIntPtr id2 = wxPtrToUInt( aItem2.GetID() );
|
|
|
|
|
|
|
|
return aAsc ? id1 - id2 : id2 - id1;
|
|
|
|
}
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
bool SetValue( const wxVariant& aInValue, const wxDataViewItem& aItem,
|
|
|
|
unsigned int aCol ) override
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
wxDataViewItem GetParent( const wxDataViewItem& aItem ) const override
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
if( !aItem.IsOk() )
|
|
|
|
return wxDataViewItem();
|
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
return wxDataViewItem( static_cast<const LIST_ITEM*>( aItem.GetID() )->Parent() );
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
bool IsContainer( const wxDataViewItem& aItem ) const override
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
if( !aItem.IsOk() )
|
|
|
|
return true;
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
return static_cast<const LIST_ITEM*>( aItem.GetID() )->GetIsGroup();
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
bool HasContainerColumns( const wxDataViewItem& aItem ) const override
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
return IsContainer( aItem );
|
|
|
|
}
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
unsigned int GetChildren( const wxDataViewItem& aParent,
|
|
|
|
wxDataViewItemArray& aChildren ) const override
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
const LIST_ITEM* p = static_cast<const LIST_ITEM*>( aParent.GetID() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
if( !aParent.IsOk() )
|
|
|
|
{
|
|
|
|
aChildren.Alloc( m_items.size() );
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
for( const std::unique_ptr<LIST_ITEM>& i : m_items )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
if( i->Parent() == nullptr )
|
2020-11-04 02:49:19 +00:00
|
|
|
aChildren.Add( wxDataViewItem( &*i ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return aChildren.GetCount();
|
|
|
|
}
|
2020-11-11 12:59:59 +00:00
|
|
|
else if( p->GetIsGroup() )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
const int count = p->ChildrenCount();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
if( count == 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
aChildren.Alloc( count );
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
for( auto i = p->ChildrenBegin(), end = p->ChildrenEnd(); i != end; ++i )
|
2020-11-04 02:49:19 +00:00
|
|
|
aChildren.Add( wxDataViewItem( *i ) );
|
|
|
|
|
|
|
|
return aChildren.GetCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
wxString GetColumnType( unsigned int /* aCol */ ) const override
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
return wxS( "string" );
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-16 14:14:00 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
DIALOG_NET_INSPECTOR::DIALOG_NET_INSPECTOR( PCB_EDIT_FRAME* aParent,
|
|
|
|
const SETTINGS& aSettings ) :
|
|
|
|
DIALOG_NET_INSPECTOR_BASE( aParent ),
|
2020-11-12 13:15:49 +00:00
|
|
|
m_zero_netitem( nullptr ),
|
2020-06-08 18:36:25 +00:00
|
|
|
m_frame( aParent )
|
2016-03-16 14:14:00 +00:00
|
|
|
{
|
|
|
|
m_brd = aParent->GetBoard();
|
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
m_data_model = new DATA_MODEL( *this );
|
|
|
|
m_netsList->AssociateModel( &*m_data_model );
|
|
|
|
|
|
|
|
std::array<std::function<void( void )>, 8> add_col = {
|
2020-11-04 03:31:43 +00:00
|
|
|
[&]()
|
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
m_netsList->AppendTextColumn( COLUMN_NET.display_name, COLUMN_NET,
|
2020-11-04 03:31:43 +00:00
|
|
|
wxDATAVIEW_CELL_INERT, -1, wxALIGN_LEFT,
|
|
|
|
wxDATAVIEW_COL_SORTABLE );
|
2020-11-04 02:49:19 +00:00
|
|
|
},
|
2020-11-04 03:31:43 +00:00
|
|
|
[&]()
|
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
m_netsList->AppendTextColumn( COLUMN_NAME.display_name, COLUMN_NAME,
|
2020-11-04 03:31:43 +00:00
|
|
|
wxDATAVIEW_CELL_INERT, -1, wxALIGN_LEFT,
|
|
|
|
wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_REORDERABLE |
|
|
|
|
wxDATAVIEW_COL_SORTABLE );
|
2020-11-04 02:49:19 +00:00
|
|
|
},
|
2020-11-04 03:31:43 +00:00
|
|
|
[&]()
|
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
m_netsList->AppendTextColumn( COLUMN_PAD_COUNT.display_name, COLUMN_PAD_COUNT,
|
2020-11-04 03:31:43 +00:00
|
|
|
wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER,
|
|
|
|
wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE );
|
2020-11-04 02:49:19 +00:00
|
|
|
},
|
2020-11-04 03:31:43 +00:00
|
|
|
[&]()
|
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
m_netsList->AppendTextColumn( COLUMN_VIA_COUNT.display_name, COLUMN_VIA_COUNT,
|
2020-11-04 03:31:43 +00:00
|
|
|
wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER,
|
|
|
|
wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE );
|
2020-11-04 02:49:19 +00:00
|
|
|
},
|
2020-11-04 03:31:43 +00:00
|
|
|
[&]()
|
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
m_netsList->AppendTextColumn( COLUMN_VIA_LENGTH.display_name, COLUMN_VIA_LENGTH,
|
2020-11-04 03:31:43 +00:00
|
|
|
wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER,
|
|
|
|
wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE );
|
2020-11-04 02:49:19 +00:00
|
|
|
},
|
2020-11-04 03:31:43 +00:00
|
|
|
[&]()
|
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
m_netsList->AppendTextColumn( COLUMN_BOARD_LENGTH.display_name, COLUMN_BOARD_LENGTH,
|
2020-11-04 03:31:43 +00:00
|
|
|
wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER,
|
|
|
|
wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE );
|
2020-11-04 02:49:19 +00:00
|
|
|
},
|
2020-11-04 03:31:43 +00:00
|
|
|
[&]()
|
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
m_netsList->AppendTextColumn( COLUMN_CHIP_LENGTH.display_name, COLUMN_CHIP_LENGTH,
|
2020-11-04 03:31:43 +00:00
|
|
|
wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER,
|
|
|
|
wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE );
|
2020-11-04 02:49:19 +00:00
|
|
|
},
|
2020-11-04 03:31:43 +00:00
|
|
|
[&]()
|
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
m_netsList->AppendTextColumn( COLUMN_TOTAL_LENGTH.display_name, COLUMN_TOTAL_LENGTH,
|
2020-11-04 03:31:43 +00:00
|
|
|
wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER,
|
|
|
|
wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE );
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<int> col_order = aSettings.column_order;
|
|
|
|
|
|
|
|
if( col_order.size() != add_col.size() )
|
|
|
|
{
|
|
|
|
col_order.resize( add_col.size() );
|
|
|
|
|
|
|
|
for( unsigned int i = 0; i < add_col.size(); ++i )
|
|
|
|
col_order[i] = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( unsigned int i : col_order )
|
|
|
|
add_col.at( i )();
|
2020-06-08 18:36:25 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
m_netsList->SetExpanderColumn( m_netsList->GetColumn( 0 ) );
|
2018-02-28 09:44:22 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
// avoid onFilterChange for each of the settings as it will re-build the
|
|
|
|
// list over and over again.
|
|
|
|
m_filter_change_no_rebuild = true;
|
2018-02-28 09:44:22 +00:00
|
|
|
|
2020-04-13 11:54:35 +00:00
|
|
|
m_textCtrlFilter->SetValue( aSettings.filter_string );
|
|
|
|
m_cbShowZeroPad->SetValue( aSettings.show_zero_pad_nets );
|
2020-11-04 02:49:19 +00:00
|
|
|
m_groupBy->SetValue( aSettings.group_by );
|
|
|
|
m_groupByKind->SetSelection( aSettings.group_by_kind );
|
|
|
|
m_groupByText->SetValue( aSettings.group_by_text );
|
|
|
|
|
|
|
|
m_filter_change_no_rebuild = false;
|
2016-03-16 14:14:00 +00:00
|
|
|
buildNetsList();
|
|
|
|
|
2019-02-19 19:04:40 +00:00
|
|
|
adjustListColumns();
|
2018-02-28 09:44:22 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
m_addNet->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
|
|
|
|
m_renameNet->SetBitmap( KiBitmap( BITMAPS::small_edit ) );
|
|
|
|
m_deleteNet->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
|
2020-06-08 18:36:25 +00:00
|
|
|
|
2016-03-16 14:14:00 +00:00
|
|
|
m_sdbSizerOK->SetDefault();
|
2020-11-04 02:49:19 +00:00
|
|
|
m_renameNet->Disable();
|
|
|
|
m_deleteNet->Disable();
|
|
|
|
|
|
|
|
if( aSettings.sorting_column != -1 )
|
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
if( wxDataViewColumn* c = m_netsList->GetColumn( aSettings.sorting_column ) )
|
2020-12-21 18:00:36 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
c->SetSortOrder( aSettings.sort_order_asc );
|
2020-12-21 18:00:36 +00:00
|
|
|
m_data_model->Resort();
|
|
|
|
}
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
2018-05-17 23:42:27 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-12-18 12:21:02 +00:00
|
|
|
m_frame->Connect( wxEVT_CLOSE_WINDOW,
|
|
|
|
wxCommandEventHandler( DIALOG_NET_INSPECTOR::onParentWindowClosed ),
|
|
|
|
nullptr, this );
|
|
|
|
m_frame->Connect( UNITS_CHANGED,
|
|
|
|
wxCommandEventHandler( DIALOG_NET_INSPECTOR::onUnitsChanged ),
|
|
|
|
nullptr, this );
|
|
|
|
m_frame->Connect( BOARD_CHANGED,
|
|
|
|
wxCommandEventHandler( DIALOG_NET_INSPECTOR::onBoardChanged ),
|
|
|
|
nullptr, this );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
|
|
|
if( m_brd != nullptr )
|
2020-11-10 13:50:16 +00:00
|
|
|
{
|
|
|
|
// if the dialog is opened while something is highlighted on the board ...
|
|
|
|
OnBoardHighlightNetChanged( *m_brd );
|
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
m_brd->AddListener( this );
|
2020-11-10 13:50:16 +00:00
|
|
|
}
|
2016-03-16 14:14:00 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 14:35:29 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
DIALOG_NET_INSPECTOR::~DIALOG_NET_INSPECTOR()
|
2016-03-16 14:14:00 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
// the displayed list elements are going to be deleted before the list view itself.
|
|
|
|
// in some cases it might still do queries on the data model, which would crash
|
|
|
|
// from now on. so just disassociate it.
|
|
|
|
m_netsList->AssociateModel( nullptr );
|
|
|
|
|
2020-12-18 12:21:02 +00:00
|
|
|
m_frame->Disconnect( wxEVT_CLOSE_WINDOW,
|
|
|
|
wxCommandEventHandler( DIALOG_NET_INSPECTOR::onParentWindowClosed ),
|
|
|
|
nullptr, this );
|
|
|
|
m_frame->Disconnect( UNITS_CHANGED,
|
|
|
|
wxCommandEventHandler( DIALOG_NET_INSPECTOR::onUnitsChanged ),
|
|
|
|
nullptr, this );
|
|
|
|
m_frame->Disconnect( BOARD_CHANGED,
|
|
|
|
wxCommandEventHandler( DIALOG_NET_INSPECTOR::onBoardChanged ),
|
|
|
|
nullptr, this );
|
2016-03-16 14:14:00 +00:00
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
if( m_brd != nullptr )
|
|
|
|
m_brd->RemoveListener( this );
|
2020-08-23 19:42:20 +00:00
|
|
|
|
|
|
|
m_frame->GetCanvas()->SetFocus();
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
2016-03-16 14:14:00 +00:00
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
DIALOG_NET_INSPECTOR::SETTINGS DIALOG_NET_INSPECTOR::Settings() const
|
2020-04-13 11:54:35 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
std::vector<int> column_order( m_data_model->columnCount() );
|
|
|
|
|
|
|
|
for( unsigned int i = 0; i < column_order.size(); ++i )
|
|
|
|
column_order[i] = m_netsList->GetColumn( i )->GetModelColumn();
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
wxDataViewColumn* sorting_column = m_netsList->GetSortingColumn();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
SETTINGS r;
|
|
|
|
r.filter_string = m_textCtrlFilter->GetValue();
|
|
|
|
r.show_zero_pad_nets = m_cbShowZeroPad->IsChecked();
|
|
|
|
r.group_by = m_groupBy->IsChecked();
|
|
|
|
r.group_by_kind = m_groupByKind->GetSelection();
|
|
|
|
r.group_by_text = m_groupByText->GetValue();
|
2020-11-11 12:59:59 +00:00
|
|
|
r.sorting_column = sorting_column ? static_cast<int>( sorting_column->GetModelColumn() ) : -1;
|
|
|
|
r.sort_order_asc = sorting_column ? sorting_column->IsSortOrderAscending() : true;
|
|
|
|
r.column_order = column_order;
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
return r;
|
2020-04-13 11:54:35 +00:00
|
|
|
}
|
2019-02-22 08:45:27 +00:00
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::onParentWindowClosed( wxCommandEvent& event )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-04-13 11:54:35 +00:00
|
|
|
Close();
|
2020-04-12 19:53:45 +00:00
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::onUnitsChanged( wxCommandEvent& event )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
|
|
|
this->m_units = m_frame->GetUserUnits();
|
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
m_data_model->updateAllItems();
|
2020-04-12 19:53:45 +00:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::onBoardChanged( wxCommandEvent& event )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
|
|
|
m_brd = m_frame->GetBoard();
|
2019-02-22 08:45:27 +00:00
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
if( m_brd != nullptr )
|
|
|
|
m_brd->AddListener( this );
|
|
|
|
|
|
|
|
buildNetsList();
|
|
|
|
m_netsList->Refresh();
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
bool DIALOG_NET_INSPECTOR::netFilterMatches( NETINFO_ITEM* aNet ) const
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2016-03-16 14:14:00 +00:00
|
|
|
// Note: the filtering is case insensitive.
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2021-01-06 13:09:54 +00:00
|
|
|
// Never show the unconnected net
|
|
|
|
if( aNet->GetNetCode() <= 0 )
|
|
|
|
return false;
|
|
|
|
|
2021-01-22 13:04:43 +00:00
|
|
|
// Show unconnected nets only if specifically asked for by filter
|
2020-11-04 02:49:19 +00:00
|
|
|
if( m_netFilter.empty() )
|
2021-01-22 13:04:43 +00:00
|
|
|
return !aNet->GetNetname().StartsWith( "unconnected-(" );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
wxString net_str = UnescapeString( aNet->GetNetname() ).Upper();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
for( const std::unique_ptr<EDA_PATTERN_MATCH>& f : m_netFilter )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
if( f->Find( net_str ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct NETCODE_CMP_LESS
|
|
|
|
{
|
|
|
|
bool operator()( const CN_ITEM* a, const CN_ITEM* b ) const
|
2016-03-16 14:14:00 +00:00
|
|
|
{
|
2020-04-12 19:53:45 +00:00
|
|
|
return a->Net() < b->Net();
|
|
|
|
}
|
2016-03-16 14:14:00 +00:00
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
bool operator()( const CN_ITEM* a, int b ) const
|
|
|
|
{
|
|
|
|
return a->Net() < b;
|
|
|
|
}
|
2019-04-14 22:13:46 +00:00
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
bool operator()( int a, const CN_ITEM* b ) const
|
|
|
|
{
|
|
|
|
return a < b->Net();
|
|
|
|
}
|
|
|
|
};
|
2016-03-16 14:14:00 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
std::vector<CN_ITEM*> DIALOG_NET_INSPECTOR::relevantConnectivityItems() const
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
|
|
|
// pre-filter the connectivity items and sort them by netcode.
|
|
|
|
// this avoids quadratic runtime when building the whole net list and
|
|
|
|
// calculating the total length for each net.
|
|
|
|
|
|
|
|
const auto type_bits = std::bitset<MAX_STRUCT_TYPE_ID>()
|
2021-01-06 14:37:38 +00:00
|
|
|
.set( PCB_TRACE_T )
|
2021-04-16 01:06:35 +00:00
|
|
|
.set( PCB_ARC_T )
|
2021-01-06 14:37:38 +00:00
|
|
|
.set( PCB_VIA_T )
|
|
|
|
.set( PCB_PAD_T );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
|
|
|
std::vector<CN_ITEM*> cn_items;
|
|
|
|
cn_items.reserve( 1024 );
|
|
|
|
|
2020-06-08 18:36:25 +00:00
|
|
|
for( CN_ITEM* cn_item : m_brd->GetConnectivity()->GetConnectivityAlgo()->ItemList() )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
|
|
|
if( cn_item->Valid() && type_bits[cn_item->Parent()->Type()] )
|
|
|
|
cn_items.push_back( cn_item );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort( cn_items.begin(), cn_items.end(), NETCODE_CMP_LESS() );
|
|
|
|
|
|
|
|
return cn_items;
|
|
|
|
}
|
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::updateDisplayedRowValues( const OPT<LIST_ITEM_ITER>& aRow )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
|
|
|
if( !aRow )
|
|
|
|
return;
|
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
wxDataViewItemArray sel;
|
|
|
|
m_netsList->GetSelections( sel );
|
2016-03-16 14:14:00 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
m_data_model->updateItem( aRow );
|
2016-03-16 14:14:00 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
if( !sel.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_netsList->SetSelections( sel );
|
|
|
|
m_netsList->EnsureVisible( sel.Item( 0 ) );
|
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
wxString DIALOG_NET_INSPECTOR::formatNetCode( const NETINFO_ITEM* aNet ) const
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-12-08 13:02:08 +00:00
|
|
|
return wxString::Format( "%.3d", aNet->GetNetCode() );
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
wxString DIALOG_NET_INSPECTOR::formatNetName( const NETINFO_ITEM* aNet ) const
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
|
|
|
return UnescapeString( aNet->GetNetname() );
|
|
|
|
}
|
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
wxString DIALOG_NET_INSPECTOR::formatCount( unsigned int aValue ) const
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
|
|
|
return wxString::Format( "%u", aValue );
|
|
|
|
}
|
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
wxString DIALOG_NET_INSPECTOR::formatLength( int64_t aValue ) const
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
return MessageTextFromValue( GetUserUnits(), static_cast<long long int>( aValue ) );
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aBoardItem )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-04-21 06:40:47 +00:00
|
|
|
if( NETINFO_ITEM* net = dynamic_cast<NETINFO_ITEM*>( aBoardItem ) )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
|
|
|
// a new net has been added to the board. add it to our list if it
|
|
|
|
// passes the netname filter test.
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
if( netFilterMatches( net ) )
|
2019-02-22 08:45:27 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
std::unique_ptr<LIST_ITEM> new_item = std::make_unique<LIST_ITEM>( net );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
// the new net could have some pads already assigned, count them.
|
2020-12-08 13:02:08 +00:00
|
|
|
new_item->SetPadCount( m_brd->GetNodesCount( net->GetNetCode() ) );
|
2019-02-22 08:45:27 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
m_data_model->addItem( std::move( new_item ) );
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-04 03:31:43 +00:00
|
|
|
else if( BOARD_CONNECTED_ITEM* i = dynamic_cast<BOARD_CONNECTED_ITEM*>( aBoardItem ) )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
OPT<LIST_ITEM_ITER> r = m_data_model->findItem( i->GetNet() );
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
if( r )
|
|
|
|
{
|
|
|
|
// try to handle frequent operations quickly.
|
2021-06-11 21:07:02 +00:00
|
|
|
if( PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( i ) )
|
2019-02-22 08:45:27 +00:00
|
|
|
{
|
2021-01-06 14:37:38 +00:00
|
|
|
const std::unique_ptr<LIST_ITEM>& list_item = *r.get();
|
2020-04-12 19:53:45 +00:00
|
|
|
int len = track->GetLength();
|
2021-01-06 14:37:38 +00:00
|
|
|
|
|
|
|
list_item->AddBoardWireLength( len );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
2019-02-22 08:45:27 +00:00
|
|
|
{
|
2021-01-06 14:37:38 +00:00
|
|
|
list_item->AddViaCount( 1 );
|
|
|
|
list_item->AddViaLength( calculateViaLength( track ) );
|
2019-02-22 08:45:27 +00:00
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
updateDisplayedRowValues( r );
|
2020-04-12 19:53:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// resort to generic slower net update otherwise.
|
|
|
|
updateNet( i->GetNet() );
|
|
|
|
}
|
2020-11-13 15:15:52 +00:00
|
|
|
else if( FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( aBoardItem ) )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
for( const PAD* pad : footprint->Pads() )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
OPT<LIST_ITEM_ITER> r = m_data_model->findItem( pad->GetNet() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
if( !r )
|
|
|
|
{
|
|
|
|
// if show-zero-pads is off, we might not have this net
|
|
|
|
// in our list yet, so add it first.
|
|
|
|
// notice that at this point we are very certain that this net
|
|
|
|
// will have at least one pad.
|
|
|
|
|
|
|
|
if( netFilterMatches( pad->GetNet() ) )
|
|
|
|
r = m_data_model->addItem( std::make_unique<LIST_ITEM>( pad->GetNet() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( r )
|
|
|
|
{
|
2021-01-06 14:37:38 +00:00
|
|
|
const std::unique_ptr<LIST_ITEM>& list_item = *r.get();
|
2020-11-04 02:49:19 +00:00
|
|
|
int len = pad->GetPadToDieLength();
|
|
|
|
|
2021-01-06 14:37:38 +00:00
|
|
|
list_item->AddPadCount( 1 );
|
|
|
|
list_item->AddChipWireLength( len );
|
|
|
|
|
|
|
|
if( list_item->GetPadCount() == 0 && !m_cbShowZeroPad->IsChecked() )
|
2020-11-04 02:49:19 +00:00
|
|
|
m_data_model->deleteItem( r );
|
|
|
|
else
|
|
|
|
updateDisplayedRowValues( r );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-12-07 23:29:30 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::OnBoardItemsAdded( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItem )
|
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item : aBoardItem )
|
|
|
|
{
|
|
|
|
OnBoardItemAdded( aBoard, item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aBoardItem )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
if( NETINFO_ITEM* net = dynamic_cast<NETINFO_ITEM*>( aBoardItem ) )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
m_data_model->deleteItem( m_data_model->findItem( net ) );
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
2020-11-13 15:15:52 +00:00
|
|
|
else if( FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( aBoardItem ) )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
for( const PAD* pad : footprint->Pads() )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
OPT<LIST_ITEM_ITER> r = m_data_model->findItem( pad->GetNet() );
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
if( r )
|
|
|
|
{
|
2021-01-06 13:09:54 +00:00
|
|
|
const std::unique_ptr<LIST_ITEM>& list_item = *r.get();
|
2020-11-04 02:49:19 +00:00
|
|
|
int len = pad->GetPadToDieLength();
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2021-01-06 13:09:54 +00:00
|
|
|
list_item->SubPadCount( 1 );
|
|
|
|
list_item->SubChipWireLength( len );
|
|
|
|
|
|
|
|
if( list_item->GetPadCount() == 0 && !m_cbShowZeroPad->IsChecked() )
|
2020-11-04 02:49:19 +00:00
|
|
|
m_data_model->deleteItem( r );
|
2020-04-12 19:53:45 +00:00
|
|
|
else
|
2020-11-04 02:49:19 +00:00
|
|
|
updateDisplayedRowValues( r );
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-04 03:31:43 +00:00
|
|
|
else if( BOARD_CONNECTED_ITEM* i = dynamic_cast<BOARD_CONNECTED_ITEM*>( aBoardItem ) )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
OPT<LIST_ITEM_ITER> r = m_data_model->findItem( i->GetNet() );
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
if( r )
|
|
|
|
{
|
|
|
|
// try to handle frequent operations quickly.
|
2021-06-11 21:07:02 +00:00
|
|
|
if( PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( i ) )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2021-01-06 13:09:54 +00:00
|
|
|
const std::unique_ptr<LIST_ITEM>& list_item = *r.get();
|
2020-04-12 19:53:45 +00:00
|
|
|
int len = track->GetLength();
|
2021-01-06 13:09:54 +00:00
|
|
|
|
|
|
|
list_item->SubBoardWireLength( len );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
2019-02-22 08:45:27 +00:00
|
|
|
{
|
2021-01-06 13:09:54 +00:00
|
|
|
list_item->SubViaCount( 1 );
|
|
|
|
list_item->SubViaLength( calculateViaLength( track ) );
|
2019-02-22 08:45:27 +00:00
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
updateDisplayedRowValues( r );
|
2020-04-12 19:53:45 +00:00
|
|
|
return;
|
2019-02-22 08:45:27 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
// resort to generic slower net update otherwise.
|
|
|
|
updateNet( i->GetNet() );
|
2019-02-22 08:45:27 +00:00
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-12-21 18:00:36 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::OnBoardItemsRemoved( BOARD& aBoard,
|
|
|
|
std::vector<BOARD_ITEM*>& aBoardItems )
|
2020-12-07 23:29:30 +00:00
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item : aBoardItems )
|
|
|
|
{
|
|
|
|
OnBoardItemRemoved( aBoard, item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aBoardItem )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
|
|
|
if( dynamic_cast<BOARD_CONNECTED_ITEM*>( aBoardItem ) != nullptr
|
2020-11-13 15:15:52 +00:00
|
|
|
|| dynamic_cast<FOOTPRINT*>( aBoardItem ) != nullptr )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
|
|
|
buildNetsList();
|
|
|
|
m_netsList->Refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-12-21 18:00:36 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::OnBoardItemsChanged( BOARD& aBoard,
|
|
|
|
std::vector<BOARD_ITEM*>& aBoardItems )
|
2020-12-07 23:29:30 +00:00
|
|
|
{
|
|
|
|
buildNetsList();
|
|
|
|
m_netsList->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::OnBoardHighlightNetChanged( BOARD& aBoard )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
|
|
|
if( !m_brd->IsHighLightNetON() )
|
2020-12-21 18:00:36 +00:00
|
|
|
{
|
2020-04-12 19:53:45 +00:00
|
|
|
m_netsList->UnselectAll();
|
2020-12-21 18:00:36 +00:00
|
|
|
}
|
2020-11-04 02:49:19 +00:00
|
|
|
else
|
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
const std::set<int>& selected_codes = m_brd->GetHighLightNetCodes();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
wxDataViewItemArray new_selection;
|
|
|
|
new_selection.Alloc( selected_codes.size() );
|
|
|
|
|
|
|
|
for( int code : selected_codes )
|
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
if( OPT<LIST_ITEM_ITER> r = m_data_model->findItem( code ) )
|
2020-11-04 02:49:19 +00:00
|
|
|
new_selection.Add( wxDataViewItem( &***r ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_netsList->SetSelections( new_selection );
|
|
|
|
|
|
|
|
if( !new_selection.IsEmpty() )
|
|
|
|
m_netsList->EnsureVisible( new_selection.Item( 0 ) );
|
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::OnBoardNetSettingsChanged( BOARD& aBoard )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
|
|
|
buildNetsList();
|
|
|
|
m_netsList->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::updateNet( NETINFO_ITEM* aNet )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
|
|
|
// something for the specified net has changed, update that row.
|
2020-11-04 02:49:19 +00:00
|
|
|
// ignore nets that are not in our list because the filter doesn't match.
|
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
if( !netFilterMatches( aNet ) )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
m_data_model->deleteItem( m_data_model->findItem( aNet ) );
|
2020-04-12 19:53:45 +00:00
|
|
|
return;
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
|
|
|
|
// if the net had no pads before, it might not be in the displayed list yet.
|
|
|
|
// if it had pads and now doesn't anymore, we might need to remove it from the list.
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
OPT<LIST_ITEM_ITER> cur_net_row = m_data_model->findItem( aNet );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-12-08 13:02:08 +00:00
|
|
|
const unsigned int node_count = m_brd->GetNodesCount( aNet->GetNetCode() );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
|
|
|
if( node_count == 0 && !m_cbShowZeroPad->IsChecked() )
|
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
m_data_model->deleteItem( cur_net_row );
|
2020-04-12 19:53:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-06 13:09:54 +00:00
|
|
|
std::unique_ptr<LIST_ITEM> new_list_item = buildNewItem( aNet, node_count,
|
|
|
|
relevantConnectivityItems() );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
if( !cur_net_row )
|
2021-01-06 13:09:54 +00:00
|
|
|
{
|
|
|
|
m_data_model->addItem( std::move( new_list_item ) );
|
|
|
|
return;
|
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2021-01-06 13:09:54 +00:00
|
|
|
const std::unique_ptr<LIST_ITEM>& cur_list_item = *cur_net_row.get();
|
|
|
|
|
|
|
|
if( cur_list_item->GetNetName() != new_list_item->GetNetName() )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
// if the name has changed, it might require re-grouping.
|
|
|
|
// it's easier to remove and re-insert it
|
|
|
|
m_data_model->deleteItem( cur_net_row );
|
2021-01-06 13:09:54 +00:00
|
|
|
m_data_model->addItem( std::move( new_list_item ) );
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// update fields only
|
2021-01-06 13:09:54 +00:00
|
|
|
cur_list_item->SetPadCount( new_list_item->GetPadCount() );
|
|
|
|
cur_list_item->SetViaCount( new_list_item->GetViaCount() );
|
|
|
|
cur_list_item->SetBoardWireLength( new_list_item->GetBoardWireLength() );
|
|
|
|
cur_list_item->SetChipWireLength( new_list_item->GetChipWireLength() );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
updateDisplayedRowValues( cur_net_row );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
unsigned int DIALOG_NET_INSPECTOR::calculateViaLength( const PCB_TRACK* aTrack ) const
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
const PCB_VIA& via = dynamic_cast<const PCB_VIA&>( *aTrack );
|
2020-11-14 21:22:35 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_brd->GetDesignSettings();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-14 21:22:35 +00:00
|
|
|
// calculate the via length individually from the board stackup and via's start and end layer.
|
|
|
|
if( bds.m_HasStackup )
|
|
|
|
{
|
|
|
|
const BOARD_STACKUP& stackup = bds.GetStackupDescriptor();
|
2021-04-21 00:03:26 +00:00
|
|
|
return stackup.GetLayerDistance( via.TopLayer(), via.BottomLayer() );
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
2020-11-14 21:22:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
int dielectricLayers = bds.GetCopperLayerCount() - 1;
|
|
|
|
int layerThickness = bds.GetBoardThickness() / dielectricLayers;
|
|
|
|
int effectiveBottomLayer;
|
|
|
|
|
|
|
|
if( via.BottomLayer() == B_Cu )
|
|
|
|
effectiveBottomLayer = F_Cu + dielectricLayers;
|
|
|
|
else
|
|
|
|
effectiveBottomLayer = via.BottomLayer();
|
2020-11-11 12:59:59 +00:00
|
|
|
|
2020-11-14 21:22:35 +00:00
|
|
|
int layerCount = effectiveBottomLayer - via.TopLayer();
|
|
|
|
|
|
|
|
return layerCount * layerThickness;
|
|
|
|
}
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
2019-02-22 08:45:27 +00:00
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-12-21 18:00:36 +00:00
|
|
|
std::unique_ptr<DIALOG_NET_INSPECTOR::LIST_ITEM>
|
|
|
|
DIALOG_NET_INSPECTOR::buildNewItem( NETINFO_ITEM* aNet, unsigned int aPadCount,
|
|
|
|
const std::vector<CN_ITEM*>& aCNItems )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
std::unique_ptr<LIST_ITEM> new_item = std::make_unique<LIST_ITEM>( aNet );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
new_item->SetPadCount( aPadCount );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-12-08 13:02:08 +00:00
|
|
|
const auto cn_items = std::equal_range( aCNItems.begin(), aCNItems.end(), aNet->GetNetCode(),
|
2020-11-04 03:31:43 +00:00
|
|
|
NETCODE_CMP_LESS() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
for( auto i = cn_items.first; i != cn_items.second; ++i )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
BOARD_CONNECTED_ITEM* item = ( *i )->Parent();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
if( item->Type() == PCB_PAD_T )
|
2020-11-12 22:30:02 +00:00
|
|
|
new_item->AddChipWireLength( static_cast<PAD*>( item )->GetPadToDieLength() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
else if( PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( item ) )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
new_item->AddBoardWireLength( track->GetLength() );
|
2016-03-16 14:14:00 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
if( item->Type() == PCB_VIA_T )
|
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
new_item->AddViaCount( 1 );
|
|
|
|
new_item->AddViaLength( calculateViaLength( track ) );
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
return new_item;
|
2016-03-16 14:14:00 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::buildNetsList()
|
2018-02-15 14:35:29 +00:00
|
|
|
{
|
2020-11-11 00:18:35 +00:00
|
|
|
// Only build the list of nets if there is a board present
|
|
|
|
if( !m_brd )
|
|
|
|
return;
|
2020-11-10 13:50:16 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
m_in_build_nets_list = true;
|
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
// when rebuilding the netlist, try to keep the row selection
|
2020-11-04 02:49:19 +00:00
|
|
|
// FIXME: handle group selections, preserve expanded/collapsed group states
|
|
|
|
wxDataViewItemArray sel;
|
|
|
|
m_netsList->GetSelections( sel );
|
|
|
|
|
|
|
|
std::vector<int> prev_selected_netcodes;
|
|
|
|
prev_selected_netcodes.reserve( sel.GetCount() );
|
|
|
|
|
|
|
|
for( unsigned int i = 0; i < sel.GetCount(); ++i )
|
2021-01-06 13:09:54 +00:00
|
|
|
{
|
|
|
|
const LIST_ITEM* item = static_cast<const LIST_ITEM*>( sel.Item( i ).GetID() );
|
|
|
|
prev_selected_netcodes.push_back( item->GetNetCode() );
|
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
m_data_model->deleteAllItems();
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<LIST_ITEM>> new_items;
|
|
|
|
|
|
|
|
// for group mode 0,1 each group filter string represents one displayed group,
|
|
|
|
// so just add them first. for group mode 2,3 the groups are generated dynamically.
|
|
|
|
if( m_groupBy->IsChecked()
|
|
|
|
&& ( m_groupByKind->GetSelection() == 0 || m_groupByKind->GetSelection() == 1 ) )
|
|
|
|
{
|
|
|
|
for( unsigned int i = 0; i < m_groupFilter.size(); ++i )
|
2021-01-06 13:09:54 +00:00
|
|
|
{
|
|
|
|
const std::unique_ptr<EDA_PATTERN_MATCH>& filter = m_groupFilter[i];
|
|
|
|
new_items.emplace_back( std::make_unique<LIST_ITEM>( i, filter->GetPattern() ) );
|
|
|
|
}
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
|
|
|
|
std::vector<CN_ITEM*> prefiltered_cn_items = relevantConnectivityItems();
|
2018-02-28 09:44:22 +00:00
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
// collect all nets which pass the filter string and also remember the
|
|
|
|
// suffix after the filter match, if any.
|
2020-04-12 19:53:45 +00:00
|
|
|
struct NET_INFO
|
2018-02-28 09:44:22 +00:00
|
|
|
{
|
2020-04-12 19:53:45 +00:00
|
|
|
int netcode;
|
|
|
|
NETINFO_ITEM* net;
|
|
|
|
unsigned int pad_count;
|
|
|
|
};
|
2019-04-08 13:35:44 +00:00
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
struct NET_INFO_CMP_LESS
|
|
|
|
{
|
|
|
|
bool operator()( const NET_INFO& a, const NET_INFO& b ) const
|
|
|
|
{
|
|
|
|
return a.netcode < b.netcode;
|
|
|
|
}
|
|
|
|
bool operator()( const NET_INFO& a, int b ) const
|
|
|
|
{
|
|
|
|
return a.netcode < b;
|
|
|
|
}
|
|
|
|
bool operator()( int a, const NET_INFO& b ) const
|
|
|
|
{
|
|
|
|
return a < b.netcode;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<NET_INFO> nets;
|
|
|
|
nets.reserve( m_brd->GetNetInfo().NetsByNetcode().size() );
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
for( const std::pair<int, NETINFO_ITEM*> ni : m_brd->GetNetInfo().NetsByNetcode() )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
if( ni.first == 0 )
|
|
|
|
m_zero_netitem = ni.second;
|
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
if( netFilterMatches( ni.second ) )
|
|
|
|
nets.emplace_back( NET_INFO{ ni.first, ni.second, 0 } );
|
2018-02-28 09:44:22 +00:00
|
|
|
}
|
2018-02-15 14:35:29 +00:00
|
|
|
|
2020-04-12 19:53:45 +00:00
|
|
|
// count the pads for each net. since the nets are sorted by netcode
|
2020-11-13 11:17:15 +00:00
|
|
|
// iterating over the footprints' pads is faster.
|
2018-02-15 14:35:29 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_brd->Footprints() )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
auto i = std::lower_bound( nets.begin(), nets.end(), pad->GetNetCode(),
|
|
|
|
NET_INFO_CMP_LESS() );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
|
|
|
if( i != nets.end() && i->netcode == pad->GetNetCode() )
|
|
|
|
i->pad_count += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
for( NET_INFO& ni : nets )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
if( m_cbShowZeroPad->IsChecked() || ni.pad_count > 0 )
|
|
|
|
new_items.emplace_back( buildNewItem( ni.net, ni.pad_count, prefiltered_cn_items ) );
|
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
|
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
m_data_model->addItems( std::move( new_items ) );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
// try to restore the selected rows. set the ones that we can't find anymore to -1.
|
|
|
|
sel.Clear();
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
for( int& nc : prev_selected_netcodes )
|
|
|
|
{
|
|
|
|
auto r = m_data_model->findItem( nc );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
if( r )
|
2021-01-06 14:37:38 +00:00
|
|
|
{
|
|
|
|
const std::unique_ptr<LIST_ITEM>& list_item = *r.get();
|
|
|
|
sel.Add( wxDataViewItem( list_item.get() ) );
|
|
|
|
}
|
2020-11-04 02:49:19 +00:00
|
|
|
else
|
2021-01-06 14:37:38 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
nc = -1;
|
2021-01-06 14:37:38 +00:00
|
|
|
}
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
if( !sel.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_netsList->SetSelections( sel );
|
|
|
|
m_netsList->EnsureVisible( sel.Item( 0 ) );
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
2020-11-04 02:49:19 +00:00
|
|
|
else
|
2021-01-06 14:37:38 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
m_netsList->UnselectAll();
|
2021-01-06 14:37:38 +00:00
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2021-10-01 10:52:34 +00:00
|
|
|
alg::delete_matching( prev_selected_netcodes, -1 );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings()->SetHighlight( false );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
for( int& i : prev_selected_netcodes )
|
2020-11-04 02:49:19 +00:00
|
|
|
m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings()->SetHighlight( true, i, true );
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
m_frame->GetCanvas()->GetView()->UpdateAllLayersColor();
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
m_in_build_nets_list = false;
|
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::onFilterChange( wxCommandEvent& aEvent )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
wxStringTokenizer filters( m_textCtrlFilter->GetValue().Upper(), "," );
|
|
|
|
m_netFilter.clear();
|
|
|
|
|
|
|
|
while( filters.HasMoreTokens() )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
wxString t = filters.GetNextToken();
|
2020-11-04 02:49:19 +00:00
|
|
|
t.Trim( false );
|
|
|
|
t.Trim( true );
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
if( !t.IsEmpty() )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
m_netFilter.emplace_back( std::make_unique<EDA_PATTERN_MATCH_WILDCARD>() );
|
|
|
|
m_netFilter.back()->SetPattern( t );
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
wxStringTokenizer group_filters( m_groupByText->GetValue(), "," );
|
|
|
|
m_groupFilter.clear();
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
while( group_filters.HasMoreTokens() )
|
2020-04-12 19:53:45 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
wxString t = group_filters.GetNextToken();
|
2020-11-04 02:49:19 +00:00
|
|
|
t.Trim( false );
|
|
|
|
t.Trim( true );
|
|
|
|
|
|
|
|
if( !t.IsEmpty() )
|
|
|
|
{
|
|
|
|
if( m_groupByKind->GetSelection() == 0 || m_groupByKind->GetSelection() == 2 )
|
|
|
|
{
|
|
|
|
// type 2: wildcard match, use the matching substring as a group key.
|
|
|
|
// the number of groups is determined dynamically by the number of
|
|
|
|
// resulting matches in the whole set.
|
|
|
|
m_groupFilter.emplace_back( std::make_unique<EDA_PATTERN_MATCH_WILDCARD>() );
|
|
|
|
m_groupFilter.back()->SetPattern( t );
|
|
|
|
}
|
|
|
|
else if( m_groupByKind->GetSelection() == 1 || m_groupByKind->GetSelection() == 3 )
|
|
|
|
{
|
|
|
|
// type 3: regex match, use the matching substring as a group key.
|
|
|
|
// the number of groups is determined dynamically by the number of
|
|
|
|
// resulting matches in the whole set.
|
|
|
|
m_groupFilter.emplace_back( std::make_unique<EDA_PATTERN_MATCH_REGEX>() );
|
|
|
|
m_groupFilter.back()->SetPattern( t );
|
|
|
|
}
|
|
|
|
}
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
if( !m_filter_change_no_rebuild )
|
|
|
|
buildNetsList();
|
2020-04-12 19:53:45 +00:00
|
|
|
}
|
2018-02-15 14:35:29 +00:00
|
|
|
|
2020-04-21 06:31:44 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::onSelChanged( wxDataViewEvent& )
|
2018-05-17 23:42:27 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
onSelChanged();
|
|
|
|
}
|
2018-05-17 23:42:27 +00:00
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::onSelChanged()
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
// ignore selection changes while the whole list is being rebuilt.
|
|
|
|
if( m_in_build_nets_list )
|
2020-04-12 19:53:45 +00:00
|
|
|
return;
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
RENDER_SETTINGS* ps = m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings();
|
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
bool enable_rename_button = false;
|
|
|
|
bool enable_delete_button = false;
|
|
|
|
|
|
|
|
if( m_netsList->HasSelection() )
|
|
|
|
{
|
|
|
|
wxDataViewItemArray sel;
|
|
|
|
m_netsList->GetSelections( sel );
|
|
|
|
|
|
|
|
ps->SetHighlight( false );
|
|
|
|
|
|
|
|
enable_rename_button = sel.GetCount() == 1;
|
|
|
|
enable_delete_button = true;
|
|
|
|
|
|
|
|
for( unsigned int i = 0; i < sel.GetCount(); ++i )
|
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
const LIST_ITEM* ii = static_cast<const LIST_ITEM*>( sel.Item( i ).GetID() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
if( ii->GetIsGroup() )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
enable_rename_button = false;
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
for( auto c = ii->ChildrenBegin(), end = ii->ChildrenEnd(); c != end; ++c )
|
|
|
|
ps->SetHighlight( true, ( *c )->GetNetCode(), true );
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
|
|
|
else
|
2020-11-11 12:59:59 +00:00
|
|
|
ps->SetHighlight( true, ii->GetNetCode(), true );
|
2020-11-04 02:49:19 +00:00
|
|
|
}
|
2018-02-28 09:44:22 +00:00
|
|
|
}
|
2020-11-04 02:49:19 +00:00
|
|
|
else
|
2020-11-04 03:31:43 +00:00
|
|
|
ps->SetHighlight( false );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
m_frame->GetCanvas()->GetView()->UpdateAllLayersColor();
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
2020-04-12 19:53:45 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
m_renameNet->Enable( enable_rename_button );
|
|
|
|
m_deleteNet->Enable( enable_delete_button );
|
2018-05-17 23:42:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::onSortingChanged( wxDataViewEvent& aEvent )
|
2018-05-17 23:42:27 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
// FIXME: Whenever the sort criteria changes (sorting column)
|
|
|
|
// the visible row-numers of the selection get preserved, not the actual
|
|
|
|
// elements. Don't know at the moment how to preserve the selection,
|
|
|
|
// so just clear it for now.
|
|
|
|
|
|
|
|
m_netsList->UnselectAll();
|
2018-09-25 09:31:17 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings()->SetHighlight( false );
|
|
|
|
m_frame->GetCanvas()->GetView()->UpdateAllLayersColor();
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::adjustListColumns()
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2019-02-19 19:04:40 +00:00
|
|
|
/**
|
2020-06-08 18:36:25 +00:00
|
|
|
* Calculating optimal width of the first (Net) and the last (Pad Count) columns.
|
|
|
|
* That width must be enough to fit column header label and be not less than width of
|
|
|
|
* four chars (0000).
|
2019-02-19 19:04:40 +00:00
|
|
|
*/
|
2018-09-25 09:31:17 +00:00
|
|
|
|
2019-02-19 19:04:40 +00:00
|
|
|
wxClientDC dc( GetParent() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
int h, minw, minw_col0, minw_col1;
|
|
|
|
int w0, w1, w2, w3, w4, w5, w6, w7;
|
2018-09-25 09:31:17 +00:00
|
|
|
|
2020-07-26 17:18:01 +00:00
|
|
|
dc.GetTextExtent( COLUMN_NET.display_name, &w0, &h );
|
2021-07-03 20:12:49 +00:00
|
|
|
dc.GetTextExtent( "MMMMMMMMMMMMMMMM", &minw_col1, &h );
|
2020-07-26 17:18:01 +00:00
|
|
|
dc.GetTextExtent( COLUMN_PAD_COUNT.display_name, &w2, &h );
|
|
|
|
dc.GetTextExtent( COLUMN_VIA_COUNT.display_name, &w3, &h );
|
2020-11-04 02:49:19 +00:00
|
|
|
dc.GetTextExtent( COLUMN_VIA_LENGTH.display_name, &w4, &h );
|
|
|
|
dc.GetTextExtent( COLUMN_BOARD_LENGTH.display_name, &w5, &h );
|
|
|
|
dc.GetTextExtent( COLUMN_CHIP_LENGTH.display_name, &w6, &h );
|
|
|
|
dc.GetTextExtent( COLUMN_TOTAL_LENGTH.display_name, &w7, &h );
|
2020-07-26 17:18:01 +00:00
|
|
|
dc.GetTextExtent( "00000,000 mm", &minw, &h );
|
|
|
|
dc.GetTextExtent( "00000", &minw_col0, &h );
|
2018-09-25 09:31:17 +00:00
|
|
|
|
2019-02-19 19:04:40 +00:00
|
|
|
// Considering left and right margins.
|
|
|
|
// For wxRenderGeneric it is 5px.
|
2020-11-04 02:49:19 +00:00
|
|
|
// Also account for the sorting arrow in the column header.
|
|
|
|
// Column 0 also needs space for any potential expander icons.
|
|
|
|
const int extra_width = 30;
|
|
|
|
|
|
|
|
w0 = std::max( w0, minw_col0 ) + extra_width;
|
|
|
|
minw_col1 = minw_col1 + extra_width;
|
|
|
|
w2 = w2 + extra_width;
|
|
|
|
w3 = w3 + extra_width;
|
|
|
|
w4 = std::max( w4 + extra_width, minw );
|
|
|
|
w5 = std::max( w5 + extra_width, minw );
|
|
|
|
w6 = std::max( w6 + extra_width, minw );
|
|
|
|
w7 = std::max( w7 + extra_width, minw );
|
|
|
|
|
|
|
|
// the columns might have been reordered. we work on the column model numbers though.
|
|
|
|
std::vector<int> column_order( m_data_model->columnCount() );
|
|
|
|
|
|
|
|
for( unsigned int i = 0; i < column_order.size(); ++i )
|
|
|
|
column_order[m_netsList->GetColumn( i )->GetModelColumn()] = i;
|
|
|
|
|
|
|
|
assert( column_order.size() == 8 );
|
|
|
|
|
|
|
|
m_netsList->GetColumn( column_order[0] )->SetWidth( w0 );
|
|
|
|
m_netsList->GetColumn( column_order[1] )->SetMinWidth( minw_col1 );
|
|
|
|
m_netsList->GetColumn( column_order[2] )->SetWidth( w2 );
|
|
|
|
m_netsList->GetColumn( column_order[3] )->SetWidth( w3 );
|
|
|
|
m_netsList->GetColumn( column_order[4] )->SetWidth( w4 );
|
|
|
|
m_netsList->GetColumn( column_order[5] )->SetWidth( w5 );
|
|
|
|
m_netsList->GetColumn( column_order[6] )->SetWidth( w6 );
|
|
|
|
m_netsList->GetColumn( column_order[7] )->SetWidth( w7 );
|
2018-05-17 23:42:27 +00:00
|
|
|
|
2019-02-19 19:04:40 +00:00
|
|
|
// At resizing of the list the width of middle column (Net Names) changes only.
|
2020-07-26 17:18:01 +00:00
|
|
|
int width = m_netsList->GetClientSize().x - 24;
|
2020-11-04 02:49:19 +00:00
|
|
|
w1 = width - w0 - w2 - w3 - w4 - w5 - w6 - w7;
|
2018-05-17 23:42:27 +00:00
|
|
|
|
2021-07-03 20:12:49 +00:00
|
|
|
if( w1 > minw_col1 )
|
|
|
|
m_netsList->GetColumn( column_order[1] )->SetWidth( w1 );
|
2019-04-15 08:10:51 +00:00
|
|
|
|
|
|
|
m_netsList->Refresh();
|
2018-05-17 23:42:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::onListSize( wxSizeEvent& aEvent )
|
2016-03-16 14:14:00 +00:00
|
|
|
{
|
2019-02-19 19:04:40 +00:00
|
|
|
aEvent.Skip();
|
|
|
|
adjustListColumns();
|
2016-03-16 14:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::onAddNet( wxCommandEvent& aEvent )
|
2020-06-08 18:36:25 +00:00
|
|
|
{
|
|
|
|
wxString newNetName;
|
|
|
|
NETNAME_VALIDATOR validator( &newNetName );
|
|
|
|
|
|
|
|
WX_TEXT_ENTRY_DIALOG dlg( this, _( "Net name:" ), _( "New Net" ), newNetName );
|
|
|
|
dlg.SetTextValidator( validator );
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
|
|
|
if( dlg.ShowModal() != wxID_OK || dlg.GetValue().IsEmpty() )
|
|
|
|
return; //Aborted by user
|
|
|
|
|
|
|
|
newNetName = dlg.GetValue();
|
|
|
|
|
|
|
|
if( m_brd->FindNet( newNetName ) )
|
|
|
|
{
|
|
|
|
DisplayError( this, wxString::Format( _( "Net name '%s' is already in use." ),
|
|
|
|
newNetName ) );
|
|
|
|
newNetName = wxEmptyString;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NETINFO_ITEM *newnet = new NETINFO_ITEM( m_brd, dlg.GetValue(), 0 );
|
|
|
|
|
|
|
|
m_brd->Add( newnet );
|
|
|
|
m_frame->OnModify();
|
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
// We'll get an OnBoardItemAdded callback from this to update our listbox
|
2020-06-08 18:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::onRenameNet( wxCommandEvent& aEvent )
|
2020-06-08 18:36:25 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
if( m_netsList->GetSelectedItemsCount() == 1 )
|
2020-06-08 18:36:25 +00:00
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
const LIST_ITEM* sel = static_cast<const LIST_ITEM*>( m_netsList->GetSelection().GetID() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
if( sel->GetIsGroup() )
|
2020-11-04 02:49:19 +00:00
|
|
|
return;
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
NETINFO_ITEM* net = sel->GetNet();
|
2020-06-08 18:36:25 +00:00
|
|
|
wxString fullNetName = net->GetNetname();
|
|
|
|
wxString netPath;
|
|
|
|
wxString shortNetName;
|
|
|
|
|
|
|
|
if( fullNetName.Contains( "/" ) )
|
|
|
|
{
|
|
|
|
netPath = fullNetName.BeforeLast( '/' ) + '/';
|
|
|
|
shortNetName = fullNetName.AfterLast( '/' );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shortNetName = fullNetName;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString unescapedShortName = UnescapeString( shortNetName );
|
|
|
|
|
|
|
|
WX_TEXT_ENTRY_DIALOG dlg( this, _( "Net name:" ), _( "Rename Net" ), unescapedShortName );
|
|
|
|
NETNAME_VALIDATOR validator( &unescapedShortName );
|
|
|
|
dlg.SetTextValidator( validator );
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2020-07-21 00:23:51 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK || dlg.GetValue() == unescapedShortName )
|
|
|
|
return;
|
2020-06-08 18:36:25 +00:00
|
|
|
|
|
|
|
unescapedShortName = dlg.GetValue();
|
|
|
|
|
|
|
|
if( unescapedShortName.IsEmpty() )
|
|
|
|
{
|
|
|
|
DisplayError( this, wxString::Format( _( "Net name cannot be empty." ),
|
|
|
|
unescapedShortName ) );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
shortNetName = EscapeString( unescapedShortName, CTX_NETNAME );
|
|
|
|
fullNetName = netPath + shortNetName;
|
|
|
|
|
|
|
|
if( m_brd->FindNet( shortNetName ) || m_brd->FindNet( fullNetName ) )
|
|
|
|
{
|
|
|
|
DisplayError( this, wxString::Format( _( "Net name '%s' is already in use." ),
|
|
|
|
unescapedShortName ) );
|
|
|
|
unescapedShortName = wxEmptyString;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
// the changed name might require re-grouping. remove and re-insert
|
|
|
|
// is easier.
|
|
|
|
auto removed_item = m_data_model->deleteItem( m_data_model->findItem( net ) );
|
|
|
|
|
2021-04-21 01:15:42 +00:00
|
|
|
m_brd->GetNetInfo().RemoveNet( net );
|
2020-06-08 18:36:25 +00:00
|
|
|
net->SetNetname( fullNetName );
|
2021-04-21 01:15:42 +00:00
|
|
|
m_brd->GetNetInfo().AppendNet( net );
|
2020-06-08 18:36:25 +00:00
|
|
|
m_frame->OnModify();
|
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
if( netFilterMatches( net ) )
|
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
std::unique_ptr<LIST_ITEM> new_item = std::make_unique<LIST_ITEM>( net );
|
2020-11-11 12:59:59 +00:00
|
|
|
new_item->SetPadCount( removed_item->GetPadCount() );
|
|
|
|
new_item->SetViaCount( removed_item->GetViaCount() );
|
|
|
|
new_item->SetBoardWireLength( removed_item->GetBoardWireLength() );
|
|
|
|
new_item->SetChipWireLength( removed_item->GetChipWireLength() );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
OPT<LIST_ITEM_ITER> added_row = m_data_model->addItem( std::move( new_item ) );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
|
|
|
wxDataViewItemArray new_sel;
|
|
|
|
new_sel.Add( wxDataViewItem( &***added_row ) );
|
|
|
|
m_netsList->SetSelections( new_sel );
|
|
|
|
onSelChanged();
|
|
|
|
}
|
2020-09-03 13:36:20 +00:00
|
|
|
|
|
|
|
// Currently only tracks and pads have netname annotations and need to be redrawn,
|
|
|
|
// but zones are likely to follow. Since we don't have a way to ask what is current,
|
|
|
|
// just refresh all items.
|
|
|
|
m_frame->GetCanvas()->GetView()->UpdateAllItems( KIGFX::REPAINT );
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
2020-06-08 18:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::onDeleteNet( wxCommandEvent& aEvent )
|
2020-06-08 18:36:25 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
if( !m_netsList->HasSelection() )
|
|
|
|
return;
|
2020-06-08 18:36:25 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
wxDataViewItemArray sel;
|
|
|
|
m_netsList->GetSelections( sel );
|
2020-06-08 18:36:25 +00:00
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
auto delete_one =
|
|
|
|
[this]( const LIST_ITEM* i )
|
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
if( i->GetPadCount() == 0
|
2020-11-04 03:31:43 +00:00
|
|
|
|| IsOK( this, wxString::Format( _( "Net '%s' is in use. Delete anyway?" ),
|
2020-11-11 12:59:59 +00:00
|
|
|
i->GetNetName() ) ) )
|
2020-11-04 03:31:43 +00:00
|
|
|
{
|
2021-04-13 01:17:42 +00:00
|
|
|
// This is a bit hacky, but it will do for now, since this is the only path
|
|
|
|
// outside the netlist updater where you can remove a net from a BOARD.
|
|
|
|
int removedCode = i->GetNetCode();
|
|
|
|
|
|
|
|
m_frame->GetCanvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT,
|
|
|
|
[removedCode]( KIGFX::VIEW_ITEM* aItem ) -> bool
|
|
|
|
{
|
|
|
|
if( auto bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem ) )
|
|
|
|
return bci->GetNetCode() == removedCode;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} );
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
m_brd->Remove( i->GetNet() );
|
2020-11-04 03:31:43 +00:00
|
|
|
m_frame->OnModify();
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
// We'll get an OnBoardItemRemoved callback from this to update our listbox
|
|
|
|
}
|
|
|
|
};
|
2020-06-08 18:36:25 +00:00
|
|
|
|
2020-11-04 02:49:19 +00:00
|
|
|
for( unsigned int i = 0; i < sel.GetCount(); ++i )
|
|
|
|
{
|
2020-11-04 03:31:43 +00:00
|
|
|
const LIST_ITEM* ii = static_cast<const LIST_ITEM*>( sel.Item( i ).GetID() );
|
2020-06-08 18:36:25 +00:00
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
if( ii->GetIsGroup() )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
2020-11-11 12:59:59 +00:00
|
|
|
if( ii->ChildrenCount() != 0
|
2020-11-04 02:49:19 +00:00
|
|
|
&& IsOK( this, wxString::Format( _( "Delete all nets in group '%s'?" ),
|
2020-11-11 12:59:59 +00:00
|
|
|
ii->GetGroupName() ) ) )
|
2020-11-04 02:49:19 +00:00
|
|
|
{
|
|
|
|
// we can't be iterating the children container and deleting items from
|
|
|
|
// it at the same time. thus take a copy of it first.
|
|
|
|
std::vector<const LIST_ITEM*> children;
|
2020-11-11 12:59:59 +00:00
|
|
|
children.reserve( ii->ChildrenCount() );
|
|
|
|
std::copy( ii->ChildrenBegin(), ii->ChildrenEnd(), std::back_inserter( children ) );
|
2020-11-04 02:49:19 +00:00
|
|
|
|
2020-11-04 03:31:43 +00:00
|
|
|
for( const LIST_ITEM* c : children )
|
2020-11-04 02:49:19 +00:00
|
|
|
delete_one( c );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2020-11-11 12:59:59 +00:00
|
|
|
{
|
2020-11-04 02:49:19 +00:00
|
|
|
delete_one( ii );
|
2020-11-11 12:59:59 +00:00
|
|
|
}
|
2020-06-08 18:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
void DIALOG_NET_INSPECTOR::onReport( wxCommandEvent& aEvent )
|
2019-02-22 08:45:27 +00:00
|
|
|
{
|
2019-04-15 08:10:51 +00:00
|
|
|
wxFileDialog dlg( this, _( "Report file" ), "", "",
|
|
|
|
_( "Report file" ) + AddFileExtListToFilter( { "csv" } ),
|
|
|
|
wxFD_SAVE );
|
2019-04-14 22:13:46 +00:00
|
|
|
|
2019-04-15 08:10:51 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2019-04-14 22:13:46 +00:00
|
|
|
return;
|
|
|
|
|
2019-04-15 08:10:51 +00:00
|
|
|
wxTextFile f( dlg.GetPath() );
|
|
|
|
|
|
|
|
f.Create();
|
2019-04-14 22:13:46 +00:00
|
|
|
|
2019-04-15 08:10:51 +00:00
|
|
|
wxString txt;
|
2019-04-14 22:13:46 +00:00
|
|
|
|
2019-04-15 08:10:51 +00:00
|
|
|
// Print Header:
|
2020-11-04 02:49:19 +00:00
|
|
|
for( auto&& col : m_data_model->columnDesc() )
|
|
|
|
txt += '"' + col.csv_name + "\";";
|
|
|
|
|
2019-04-15 08:10:51 +00:00
|
|
|
f.AddLine( txt );
|
2019-04-14 22:13:46 +00:00
|
|
|
|
2019-04-15 08:10:51 +00:00
|
|
|
// Print list of nets:
|
2020-11-04 02:49:19 +00:00
|
|
|
const unsigned int num_rows = m_data_model->itemCount();
|
|
|
|
|
|
|
|
for( unsigned int row = 0; row < num_rows; row++ )
|
|
|
|
{
|
|
|
|
auto& i = m_data_model->itemAt( row );
|
|
|
|
|
2020-11-11 12:59:59 +00:00
|
|
|
if( i.GetIsGroup() || i.GetNetCode() == 0 )
|
2020-11-04 02:49:19 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
txt = "";
|
|
|
|
|
|
|
|
for( auto&& col : m_data_model->columnDesc() )
|
|
|
|
{
|
|
|
|
if( col.csv_flags & COLUMN_DESC::CSV_QUOTE )
|
|
|
|
txt += '"' + m_data_model->valueAt( col.num, row ).GetString() + "\";";
|
|
|
|
else
|
|
|
|
txt += m_data_model->valueAt( col.num, row ).GetString() + ';';
|
|
|
|
}
|
|
|
|
|
|
|
|
f.AddLine( txt );
|
|
|
|
}
|
|
|
|
|
|
|
|
f.Write();
|
|
|
|
f.Close();
|
2019-02-22 08:45:27 +00:00
|
|
|
}
|