KiCad PCB EDA Suite
NET_GRID_TABLE Class Reference

#include <appearance_controls.h>

Inheritance diagram for NET_GRID_TABLE:

Public Types

enum  COLUMNS { COL_COLOR, COL_VISIBILITY, COL_LABEL, COL_SIZE }
 

Public Member Functions

 NET_GRID_TABLE (PCB_BASE_FRAME *aFrame, wxColor aBackgroundColor)
 
 ~NET_GRID_TABLE ()
 
int GetNumberRows () override
 
int GetNumberCols () override
 
wxGridCellAttr * GetAttr (int aRow, int aCol, wxGridCellAttr::wxAttrKind) override
 
wxString GetValue (int aRow, int aCol) override
 
void SetValue (int aRow, int aCol, const wxString &aValue) override
 
wxString GetTypeName (int aRow, int aCol) override
 
bool GetValueAsBool (int aRow, int aCol) override
 
void SetValueAsBool (int aRow, int aCol, bool aValue) override
 
void * GetValueAsCustom (int aRow, int aCol, const wxString &aTypeName) override
 
void SetValueAsCustom (int aRow, int aCol, const wxString &aTypeName, void *aValue) override
 
NET_GRID_ENTRYGetEntry (int aRow)
 
int GetRowByNetcode (int aCode) const
 
void Rebuild ()
 
void ShowAllNets ()
 
void HideOtherNets (const NET_GRID_ENTRY &aNet)
 

Static Public Member Functions

static void * ColorToVoid (COLOR4D &aColor)
 
static COLOR4D VoidToColor (void *aColor)
 

Private Member Functions

void updateNetVisibility (const NET_GRID_ENTRY &aNet)
 
void updateNetColor (const NET_GRID_ENTRY &aNet)
 

Private Attributes

PCB_BASE_FRAMEm_frame
 
std::vector< NET_GRID_ENTRYm_nets
 
wxGridCellAttr * m_defaultAttr
 
wxGridCellAttr * m_labelAttr
 

Detailed Description

Definition at line 62 of file appearance_controls.h.

Member Enumeration Documentation

◆ COLUMNS

Enumerator
COL_COLOR 
COL_VISIBILITY 
COL_LABEL 
COL_SIZE 

Definition at line 65 of file appearance_controls.h.

Constructor & Destructor Documentation

◆ NET_GRID_TABLE()

NET_GRID_TABLE::NET_GRID_TABLE ( PCB_BASE_FRAME aFrame,
wxColor  aBackgroundColor 
)

Definition at line 49 of file appearance_controls.cpp.

49  :
50  wxGridTableBase(),
51  m_frame( aFrame )
52 {
53  m_defaultAttr = new wxGridCellAttr;
54  m_defaultAttr->SetBackgroundColour( aBackgroundColor );
55 
56  m_labelAttr = new wxGridCellAttr;
57  m_labelAttr->SetRenderer( new GRID_CELL_ESCAPED_TEXT_RENDERER );
58  m_labelAttr->SetBackgroundColour( aBackgroundColor );
59 }
wxGridCellAttr * m_defaultAttr
wxGridCellAttr * m_labelAttr
PCB_BASE_FRAME * m_frame
A text renderer that can unescape text for display This is useful where it's desired to keep the unde...

References m_defaultAttr, and m_labelAttr.

◆ ~NET_GRID_TABLE()

NET_GRID_TABLE::~NET_GRID_TABLE ( )

Definition at line 62 of file appearance_controls.cpp.

63 {
64  m_defaultAttr->DecRef();
65  m_labelAttr->DecRef();
66 }
wxGridCellAttr * m_defaultAttr
wxGridCellAttr * m_labelAttr

References m_defaultAttr, and m_labelAttr.

Member Function Documentation

◆ ColorToVoid()

static void* NET_GRID_TABLE::ColorToVoid ( COLOR4D aColor)
inlinestatic

Definition at line 73 of file appearance_controls.h.

74  {
75  return static_cast<void*>( &aColor );
76  }

Referenced by GetValueAsCustom().

◆ GetAttr()

wxGridCellAttr * NET_GRID_TABLE::GetAttr ( int  aRow,
int  aCol,
wxGridCellAttr::wxAttrKind   
)
override

Definition at line 69 of file appearance_controls.cpp.

70 {
71  switch( aCol )
72  {
73  case COL_COLOR:
74  m_defaultAttr->IncRef();
75  return m_defaultAttr;
76 
77  case COL_VISIBILITY:
78  m_defaultAttr->IncRef();
79  return m_defaultAttr;
80 
81  case COL_LABEL:
82  m_labelAttr->IncRef();
83  return m_labelAttr;
84 
85  default:
86  wxFAIL;
87  return nullptr;
88  }
89 }
wxGridCellAttr * m_defaultAttr
wxGridCellAttr * m_labelAttr

References COL_COLOR, COL_LABEL, COL_VISIBILITY, m_defaultAttr, and m_labelAttr.

◆ GetEntry()

NET_GRID_ENTRY & NET_GRID_TABLE::GetEntry ( int  aRow)

Definition at line 204 of file appearance_controls.cpp.

205 {
206  wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
207  return m_nets[aRow];
208 }
std::vector< NET_GRID_ENTRY > m_nets

References m_nets.

Referenced by APPEARANCE_CONTROLS::onNetContextMenu(), and APPEARANCE_CONTROLS::OnNetGridMouseEvent().

◆ GetNumberCols()

int NET_GRID_TABLE::GetNumberCols ( )
inlineoverride

Definition at line 92 of file appearance_controls.h.

93  {
94  return COL_SIZE;
95  }

References COL_SIZE.

◆ GetNumberRows()

int NET_GRID_TABLE::GetNumberRows ( )
inlineoverride

Definition at line 87 of file appearance_controls.h.

88  {
89  return m_nets.size();
90  }
std::vector< NET_GRID_ENTRY > m_nets

References m_nets.

◆ GetRowByNetcode()

int NET_GRID_TABLE::GetRowByNetcode ( int  aCode) const

Definition at line 211 of file appearance_controls.cpp.

212 {
213  auto it = std::find_if( m_nets.cbegin(), m_nets.cend(),
214  [aCode]( const NET_GRID_ENTRY& aEntry )
215  {
216  return aEntry.code == aCode;
217  } );
218 
219  if( it == m_nets.cend() )
220  return -1;
221 
222  return std::distance( m_nets.cbegin(), it );
223 }
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
std::vector< NET_GRID_ENTRY > m_nets

References distance(), and m_nets.

Referenced by APPEARANCE_CONTROLS::showNetclass().

◆ GetTypeName()

wxString NET_GRID_TABLE::GetTypeName ( int  aRow,
int  aCol 
)
override

Definition at line 141 of file appearance_controls.cpp.

142 {
143  switch( aCol )
144  {
145  case COL_COLOR:
146  return wxT( "COLOR4D" );
147 
148  case COL_VISIBILITY:
149  return wxGRID_VALUE_BOOL;
150 
151  case COL_LABEL:
152  default:
153  return wxGRID_VALUE_STRING;
154  }
155 }

References COL_COLOR, COL_LABEL, and COL_VISIBILITY.

◆ GetValue()

wxString NET_GRID_TABLE::GetValue ( int  aRow,
int  aCol 
)
override

Definition at line 92 of file appearance_controls.cpp.

93 {
94  wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
95 
96  switch( aCol )
97  {
98  case COL_COLOR:
99  return m_nets[aRow].color.ToWxString( wxC2S_CSS_SYNTAX );
100 
101  case COL_VISIBILITY:
102  return m_nets[aRow].visible ? "1" : "0";
103 
104  case COL_LABEL:
105  return m_nets[aRow].name;
106 
107  default:
108  return wxEmptyString;
109  }
110 }
std::vector< NET_GRID_ENTRY > m_nets

References COL_COLOR, COL_LABEL, COL_VISIBILITY, and m_nets.

◆ GetValueAsBool()

bool NET_GRID_TABLE::GetValueAsBool ( int  aRow,
int  aCol 
)
override

Definition at line 158 of file appearance_controls.cpp.

159 {
160  wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
161  wxASSERT( aCol == COL_VISIBILITY );
162 
163  return m_nets[aRow].visible;
164 }
std::vector< NET_GRID_ENTRY > m_nets

References COL_VISIBILITY, and m_nets.

Referenced by APPEARANCE_CONTROLS::OnNetGridClick().

◆ GetValueAsCustom()

void * NET_GRID_TABLE::GetValueAsCustom ( int  aRow,
int  aCol,
const wxString &  aTypeName 
)
override

Definition at line 177 of file appearance_controls.cpp.

178 {
179  wxASSERT( aCol == COL_COLOR );
180  wxASSERT( aTypeName == wxT( "COLOR4D" ) );
181  wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
182 
183  return ColorToVoid( m_nets[aRow].color );
184 }
int color
Definition: DXF_plotter.cpp:60
static void * ColorToVoid(COLOR4D &aColor)
std::vector< NET_GRID_ENTRY > m_nets

References COL_COLOR, color, ColorToVoid(), and m_nets.

◆ HideOtherNets()

void NET_GRID_TABLE::HideOtherNets ( const NET_GRID_ENTRY aNet)

Definition at line 289 of file appearance_controls.cpp.

290 {
291  for( NET_GRID_ENTRY& net : m_nets )
292  {
293  net.visible = ( net.code == aNet.code );
294  updateNetVisibility( net );
295  }
296 
297  if( GetView() )
298  GetView()->ForceRefresh();
299 }
int code
std::vector< NET_GRID_ENTRY > m_nets
void updateNetVisibility(const NET_GRID_ENTRY &aNet)

References NET_GRID_ENTRY::code, m_nets, and updateNetVisibility().

Referenced by APPEARANCE_CONTROLS::onNetContextMenu().

◆ Rebuild()

void NET_GRID_TABLE::Rebuild ( )

Definition at line 226 of file appearance_controls.cpp.

227 {
228  BOARD* board = m_frame->GetBoard();
229  const NETNAMES_MAP& nets = board->GetNetInfo().NetsByName();
230 
231  KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
233 
234  std::set<int>& hiddenNets = rs->GetHiddenNets();
235  std::map<int, KIGFX::COLOR4D>& netColors = rs->GetNetColorMap();
236 
237  int deleted = m_nets.size();
238  m_nets.clear();
239 
240  if( GetView() )
241  {
242  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, deleted );
243  GetView()->ProcessTableMessage( msg );
244  }
245 
246  for( const std::pair<const wxString, NETINFO_ITEM*>& pair : nets )
247  {
248  int netCode = pair.second->GetNet();
249 
250  if( netCode > 0 )
251  {
252  COLOR4D color = netColors.count( netCode ) ? netColors.at( netCode ) :
253  COLOR4D::UNSPECIFIED;
254 
255  bool visible = hiddenNets.count( netCode ) == 0;
256 
257  m_nets.emplace_back( NET_GRID_ENTRY( netCode, pair.first, color, visible ) );
258  }
259  }
260 
261  // TODO(JE) move to ::Compare so we can re-sort easily
262  std::sort( m_nets.begin(), m_nets.end(),
263  []( const NET_GRID_ENTRY& a, const NET_GRID_ENTRY& b )
264  {
265  return a.name < b.name;
266  } );
267 
268  if( GetView() )
269  {
270  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_nets.size() );
271  GetView()->ProcessTableMessage( msg );
272  }
273 }
std::set< int > & GetHiddenNets()
Definition: pcb_painter.h:184
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
int color
Definition: DXF_plotter.cpp:60
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:719
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:201
const NETNAMES_MAP & NetsByName() const
Function GetPadCount.
Definition: netinfo.h:471
PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:64
virtual KIGFX::PCB_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
virtual RENDER_SETTINGS * GetSettings()=0
Function GetAdapter Returns pointer to current settings that are going to be used when drawing items.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:186
wxString name
std::vector< NET_GRID_ENTRY > m_nets
std::map< int, KIGFX::COLOR4D > & GetNetColorMap()
Definition: pcb_painter.h:182
BOARD * GetBoard() const
PCB_BASE_FRAME * m_frame
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100

References color, PCB_BASE_FRAME::GetBoard(), PCB_BASE_FRAME::GetCanvas(), KIGFX::PCB_RENDER_SETTINGS::GetHiddenNets(), KIGFX::PCB_RENDER_SETTINGS::GetNetColorMap(), BOARD::GetNetInfo(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), PCB_DRAW_PANEL_GAL::GetView(), m_frame, m_nets, NET_GRID_ENTRY::name, and NETINFO_LIST::NetsByName().

Referenced by APPEARANCE_CONTROLS::rebuildNets().

◆ SetValue()

void NET_GRID_TABLE::SetValue ( int  aRow,
int  aCol,
const wxString &  aValue 
)
override

Definition at line 113 of file appearance_controls.cpp.

114 {
115  wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
116 
117  NET_GRID_ENTRY& net = m_nets[aRow];
118 
119  switch( aCol )
120  {
121  case COL_COLOR:
122  net.color.SetFromWxString( aValue );
123  updateNetColor( net );
124  break;
125 
126  case COL_VISIBILITY:
127  net.visible = ( aValue != "0" );
128  updateNetVisibility( net );
129  break;
130 
131  case COL_LABEL:
132  net.name = aValue;
133  break;
134 
135  default:
136  break;
137  }
138 }
std::vector< NET_GRID_ENTRY > m_nets
void updateNetColor(const NET_GRID_ENTRY &aNet)
void updateNetVisibility(const NET_GRID_ENTRY &aNet)

References COL_COLOR, COL_LABEL, COL_VISIBILITY, m_nets, updateNetColor(), and updateNetVisibility().

◆ SetValueAsBool()

void NET_GRID_TABLE::SetValueAsBool ( int  aRow,
int  aCol,
bool  aValue 
)
override

Definition at line 167 of file appearance_controls.cpp.

168 {
169  wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
170  wxASSERT( aCol == COL_VISIBILITY );
171 
172  m_nets[aRow].visible = aValue;
173  updateNetVisibility( m_nets[aRow] );
174 }
std::vector< NET_GRID_ENTRY > m_nets
void updateNetVisibility(const NET_GRID_ENTRY &aNet)

References COL_VISIBILITY, m_nets, and updateNetVisibility().

Referenced by APPEARANCE_CONTROLS::OnNetGridClick(), and APPEARANCE_CONTROLS::showNetclass().

◆ SetValueAsCustom()

void NET_GRID_TABLE::SetValueAsCustom ( int  aRow,
int  aCol,
const wxString &  aTypeName,
void *  aValue 
)
override

Definition at line 187 of file appearance_controls.cpp.

188 {
189  wxASSERT( aCol == COL_COLOR );
190  wxASSERT( aTypeName == wxT( "COLOR4D" ) );
191  wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
192 
193  m_nets[aRow].color = VoidToColor( aValue );
194  updateNetColor( m_nets[aRow] );
195 
196  if( GetView() )
197  {
198  wxGridTableMessage msg( this, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES );
199  GetView()->ProcessTableMessage( msg );
200  }
201 }
static COLOR4D VoidToColor(void *aColor)
std::vector< NET_GRID_ENTRY > m_nets
void updateNetColor(const NET_GRID_ENTRY &aNet)

References COL_COLOR, m_nets, updateNetColor(), and VoidToColor().

◆ ShowAllNets()

void NET_GRID_TABLE::ShowAllNets ( )

Definition at line 276 of file appearance_controls.cpp.

277 {
278  for( NET_GRID_ENTRY& net : m_nets )
279  {
280  net.visible = true;
281  updateNetVisibility( net );
282  }
283 
284  if( GetView() )
285  GetView()->ForceRefresh();
286 }
std::vector< NET_GRID_ENTRY > m_nets
void updateNetVisibility(const NET_GRID_ENTRY &aNet)

References m_nets, and updateNetVisibility().

Referenced by APPEARANCE_CONTROLS::onNetContextMenu().

◆ updateNetColor()

void NET_GRID_TABLE::updateNetColor ( const NET_GRID_ENTRY aNet)
private

Definition at line 309 of file appearance_controls.cpp.

310 {
311  KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
313 
314  std::map<int, KIGFX::COLOR4D>& netColors = rs->GetNetColorMap();
315 
316  if( aNet.color != COLOR4D::UNSPECIFIED )
317  netColors[aNet.code] = aNet.color;
318  else
319  netColors.erase( aNet.code );
320 
323  m_frame->GetCanvas()->Refresh();
324 }
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
COLOR4D color
int code
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:201
void RedrawRatsnest()
Forces refresh of the ratsnest visual representation
PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:64
virtual KIGFX::PCB_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
virtual RENDER_SETTINGS * GetSettings()=0
Function GetAdapter Returns pointer to current settings that are going to be used when drawing items.
std::map< int, KIGFX::COLOR4D > & GetNetColorMap()
Definition: pcb_painter.h:182
PCB_BASE_FRAME * m_frame
void UpdateAllLayersColor()
Function UpdateAllLayersColor() Applies the new coloring scheme to all layers.
Definition: view.cpp:776

References NET_GRID_ENTRY::code, NET_GRID_ENTRY::color, PCB_BASE_FRAME::GetCanvas(), KIGFX::PCB_RENDER_SETTINGS::GetNetColorMap(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), PCB_DRAW_PANEL_GAL::GetView(), m_frame, PCB_DRAW_PANEL_GAL::RedrawRatsnest(), EDA_DRAW_PANEL_GAL::Refresh(), and KIGFX::VIEW::UpdateAllLayersColor().

Referenced by SetValue(), and SetValueAsCustom().

◆ updateNetVisibility()

void NET_GRID_TABLE::updateNetVisibility ( const NET_GRID_ENTRY aNet)
private

Definition at line 302 of file appearance_controls.cpp.

303 {
305  m_frame->GetToolManager()->RunAction( action, true, aNet.code );
306 }
static TOOL_ACTION hideNet
Definition: pcb_actions.h:447
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
int code
bool visible
static TOOL_ACTION showNet
Definition: pcb_actions.h:448
Represents a single user action.
Definition: tool_action.h:44
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:76
PCB_BASE_FRAME * m_frame

References NET_GRID_ENTRY::code, TOOLS_HOLDER::GetToolManager(), PCB_ACTIONS::hideNet, m_frame, TOOL_MANAGER::RunAction(), PCB_ACTIONS::showNet, and NET_GRID_ENTRY::visible.

Referenced by HideOtherNets(), SetValue(), SetValueAsBool(), and ShowAllNets().

◆ VoidToColor()

static COLOR4D NET_GRID_TABLE::VoidToColor ( void *  aColor)
inlinestatic

Definition at line 78 of file appearance_controls.h.

79  {
80  return *static_cast<COLOR4D*>( aColor );
81  }

Referenced by SetValueAsCustom().

Member Data Documentation

◆ m_defaultAttr

wxGridCellAttr* NET_GRID_TABLE::m_defaultAttr
private

Definition at line 133 of file appearance_controls.h.

Referenced by GetAttr(), NET_GRID_TABLE(), and ~NET_GRID_TABLE().

◆ m_frame

PCB_BASE_FRAME* NET_GRID_TABLE::m_frame
private

Definition at line 129 of file appearance_controls.h.

Referenced by Rebuild(), updateNetColor(), and updateNetVisibility().

◆ m_labelAttr

wxGridCellAttr* NET_GRID_TABLE::m_labelAttr
private

Definition at line 134 of file appearance_controls.h.

Referenced by GetAttr(), NET_GRID_TABLE(), and ~NET_GRID_TABLE().

◆ m_nets


The documentation for this class was generated from the following files: