KiCad PCB EDA Suite
dialog_select_net_from_list.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020 Oleg Endo <olegendo@gcc.gnu.org>
5  * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
6  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #pragma once
27 
29 #include <eda_pattern_match.h>
30 
31 class PCB_EDIT_FRAME;
32 class NETINFO_ITEM;
33 class BOARD;
34 class CN_ITEM;
35 
37 {
38 public:
39  struct SETTINGS
40  {
41  wxString filter_string;
42  bool show_zero_pad_nets = true;
43  };
44 
45  DIALOG_SELECT_NET_FROM_LIST( PCB_EDIT_FRAME* aParent, const SETTINGS& aSettings );
47 
48  SETTINGS Settings() const;
49 
50  // returns true if a net was selected, and its name in aName
51  bool GetNetName( wxString& aName ) const;
52 
58  void HighlightNet( NETINFO_ITEM* aNet );
59 
60  virtual void OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
61  virtual void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
62  virtual void OnBoardNetSettingsChanged( BOARD& aBoard ) override;
63  virtual void OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
64  virtual void OnBoardHighlightNetChanged( BOARD& aBoard ) override;
65 
66 private:
67  struct COLUMN_ID;
68  static const COLUMN_ID COLUMN_NET;
69  static const COLUMN_ID COLUMN_NAME;
75 
76  struct ROW_DESC;
77 
78  ROW_DESC findRow( NETINFO_ITEM* aNet );
79  ROW_DESC findRow( int aNetCode );
80 
81  void deleteRow( const ROW_DESC& aRow );
82  void setValue( const ROW_DESC& aRow, const COLUMN_ID& aCol, wxString aVal );
83 
84  wxString formatNetCode( const NETINFO_ITEM* aNet ) const;
85  wxString formatNetName( const NETINFO_ITEM* aNet ) const;
86  wxString formatCount( unsigned int aValue ) const;
87  wxString formatLength( int aValue ) const;
88 
89  std::vector<CN_ITEM*> relevantConnectivityItems() const;
90  bool netFilterMatches( NETINFO_ITEM* aNet ) const;
91  void updateNet( NETINFO_ITEM* aNet );
92  void highlightNetOnBoard( NETINFO_ITEM* aNet ) const;
93 
94  void onSelChanged( wxDataViewEvent& event ) override;
95  void onFilterChange( wxCommandEvent& event ) override;
96  void onListSize( wxSizeEvent& event ) override;
97  void onAddNet( wxCommandEvent& event ) override;
98  void onRenameNet( wxCommandEvent& event ) override;
99  void onDeleteNet( wxCommandEvent& event ) override;
100  void onReport( wxCommandEvent& event ) override;
101 
102  void buildNetsList();
103  void adjustListColumns();
104 
105  void onParentWindowClosed( wxCommandEvent& event );
106  void onUnitsChanged( wxCommandEvent& event );
107  void onBoardChanged( wxCommandEvent& event );
108 
109  // in addition to the displayed list data, we also keep some auxiliary
110  // data for each list item in order to speed up update of the displayed list.
111  struct LIST_ITEM;
113 
114  // primary vector, sorted by rows
115  std::vector<LIST_ITEM> m_list_items;
116 
117  // we can't keep pointers to the elements in the primary vector because
118  // the underlyng storage might change when elements are added or removed.
119  // keep indices instead and look the them up in m_list_items.
120  std::vector<unsigned int> m_list_items_by_net;
121 
122 
124 
125  wxString m_selection;
129 };
DIALOG_SELECT_NET_FROM_LIST(PCB_EDIT_FRAME *aParent, const SETTINGS &aSettings)
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
virtual void OnBoardItemAdded(BOARD &aBoard, BOARD_ITEM *aBoardItem) override
std::vector< unsigned int > m_list_items_by_net
virtual void OnBoardItemRemoved(BOARD &aBoard, BOARD_ITEM *aBoardItem) override
void onListSize(wxSizeEvent &event) override
void onAddNet(wxCommandEvent &event) override
Abstract pattern-matching tool and implementations.
EDA_PATTERN_MATCH_WILDCARD m_netFilter
static const COLUMN_ID COLUMN_BOARD_LENGTH
void onDeleteNet(wxCommandEvent &event) override
wxString formatCount(unsigned int aValue) const
std::vector< CN_ITEM * > relevantConnectivityItems() const
void HighlightNet(NETINFO_ITEM *aNet)
Visually highlights a net in the list view.
void setValue(const ROW_DESC &aRow, const COLUMN_ID &aCol, wxString aVal)
void onBoardChanged(wxCommandEvent &event)
void onParentWindowClosed(wxCommandEvent &event)
wxString formatNetName(const NETINFO_ITEM *aNet) const
void onSelChanged(wxDataViewEvent &event) override
Class DIALOG_SELECT_NET_FROM_LIST_BASE.
void onFilterChange(wxCommandEvent &event) override
wxString formatNetCode(const NETINFO_ITEM *aNet) const
bool netFilterMatches(NETINFO_ITEM *aNet) const
wxString formatLength(int aValue) const
virtual void OnBoardItemChanged(BOARD &aBoard, BOARD_ITEM *aBoardItem) override
void onRenameNet(wxCommandEvent &event) override
static const COLUMN_ID COLUMN_TOTAL_LENGTH
virtual void OnBoardHighlightNetChanged(BOARD &aBoard) override
ROW_DESC findRow(NETINFO_ITEM *aNet)
bool GetNetName(wxString &aName) const
virtual void OnBoardNetSettingsChanged(BOARD &aBoard) override
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
void highlightNetOnBoard(NETINFO_ITEM *aNet) const
PCB_EDIT_FRAME is the main frame for Pcbnew.
void onUnitsChanged(wxCommandEvent &event)
static const COLUMN_ID COLUMN_CHIP_LENGTH
void onReport(wxCommandEvent &event) override