KiCad PCB EDA Suite
FP_TEXT_GRID_TABLE Class Reference

#include <fp_text_grid_table.h>

Inheritance diagram for FP_TEXT_GRID_TABLE:

Public Member Functions

 FP_TEXT_GRID_TABLE (PCB_BASE_FRAME *aFrame)
 
 ~FP_TEXT_GRID_TABLE ()
 
int GetNumberRows () override
 
int GetNumberCols () override
 
wxString GetColLabelValue (int aCol) override
 
wxString GetRowLabelValue (int aRow) override
 
bool IsEmptyCell (int row, int col) override
 
bool CanGetValueAs (int aRow, int aCol, const wxString &aTypeName) override
 
bool CanSetValueAs (int aRow, int aCol, const wxString &aTypeName) override
 
wxGridCellAttr * GetAttr (int row, int col, wxGridCellAttr::wxAttrKind kind) override
 
wxString GetValue (int aRow, int aCol) override
 
bool GetValueAsBool (int aRow, int aCol) override
 
long GetValueAsLong (int aRow, int aCol) override
 
void SetValue (int aRow, int aCol, const wxString &aValue) override
 
void SetValueAsBool (int aRow, int aCol, bool aValue) override
 
void SetValueAsLong (int aRow, int aCol, long aValue) override
 

Protected Member Functions

void onUnitsChanged (wxCommandEvent &aEvent)
 

Private Attributes

PCB_BASE_FRAMEm_frame
 
wxGridCellAttr * m_readOnlyAttr
 
wxGridCellAttr * m_boolColAttr
 
wxGridCellAttr * m_orientationColAttr
 
wxGridCellAttr * m_layerColAttr
 

Detailed Description

Definition at line 54 of file fp_text_grid_table.h.

Constructor & Destructor Documentation

◆ FP_TEXT_GRID_TABLE()

FP_TEXT_GRID_TABLE::FP_TEXT_GRID_TABLE ( PCB_BASE_FRAME aFrame)

Definition at line 43 of file fp_text_grid_table.cpp.

43  :
44  m_frame( aFrame )
45 {
46  // Build the column attributes.
47 
48  m_readOnlyAttr = new wxGridCellAttr;
49  m_readOnlyAttr->SetReadOnly( true );
50 
51  m_boolColAttr = new wxGridCellAttr;
52  m_boolColAttr->SetRenderer( new wxGridCellBoolRenderer() );
53  m_boolColAttr->SetEditor( new wxGridCellBoolEditor() );
54  m_boolColAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
55 
56  if( g_menuOrientations.IsEmpty() )
57  {
58  g_menuOrientations.push_back(
60  g_menuOrientations.push_back(
61  wxT( "90 " ) + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
62  g_menuOrientations.push_back(
63  wxT( "-90 " ) + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
64  g_menuOrientations.push_back(
65  wxT( "180 " ) + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
66  }
67 
68  m_orientationColAttr = new wxGridCellAttr;
70 
71  m_layerColAttr = new wxGridCellAttr;
72  m_layerColAttr->SetRenderer( new GRID_CELL_LAYER_RENDERER( m_frame ) );
73  m_layerColAttr->SetEditor( new GRID_CELL_LAYER_SELECTOR( m_frame, {} ) );
74 
75  m_frame->Bind( UNITS_CHANGED, &FP_TEXT_GRID_TABLE::onUnitsChanged, this );
76 }
wxGridCellAttr * m_orientationColAttr
wxGridCellAttr * m_layerColAttr
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:419
wxGridCellAttr * m_readOnlyAttr
void onUnitsChanged(wxCommandEvent &aEvent)
wxGridCellAttr * m_boolColAttr
PCB_BASE_FRAME * m_frame
wxArrayString g_menuOrientations

References DEGREES, g_menuOrientations, GetAbbreviatedUnitsLabel(), m_boolColAttr, m_frame, m_layerColAttr, m_orientationColAttr, m_readOnlyAttr, and onUnitsChanged().

◆ ~FP_TEXT_GRID_TABLE()

FP_TEXT_GRID_TABLE::~FP_TEXT_GRID_TABLE ( )

Definition at line 79 of file fp_text_grid_table.cpp.

80 {
81  m_readOnlyAttr->DecRef();
82  m_boolColAttr->DecRef();
83  m_orientationColAttr->DecRef();
84  m_layerColAttr->DecRef();
85 
86  m_frame->Unbind( UNITS_CHANGED, &FP_TEXT_GRID_TABLE::onUnitsChanged, this );
87 }
wxGridCellAttr * m_orientationColAttr
wxGridCellAttr * m_layerColAttr
wxGridCellAttr * m_readOnlyAttr
void onUnitsChanged(wxCommandEvent &aEvent)
wxGridCellAttr * m_boolColAttr
PCB_BASE_FRAME * m_frame

References m_boolColAttr, m_frame, m_layerColAttr, m_orientationColAttr, m_readOnlyAttr, and onUnitsChanged().

Member Function Documentation

◆ CanGetValueAs()

bool FP_TEXT_GRID_TABLE::CanGetValueAs ( int  aRow,
int  aCol,
const wxString &  aTypeName 
)
override

Definition at line 130 of file fp_text_grid_table.cpp.

131 {
132  switch( aCol )
133  {
134  case FPT_TEXT:
135  case FPT_WIDTH:
136  case FPT_HEIGHT:
137  case FPT_THICKNESS:
138  case FPT_ORIENTATION:
139  case FPT_XOFFSET:
140  case FPT_YOFFSET:
141  return aTypeName == wxGRID_VALUE_STRING;
142 
143  case FPT_SHOWN:
144  case FPT_ITALIC:
145  case FPT_UPRIGHT:
146  return aTypeName == wxGRID_VALUE_BOOL;
147 
148  case FPT_LAYER:
149  return aTypeName == wxGRID_VALUE_NUMBER;
150 
151  default:
152  wxFAIL;
153  return false;
154  }
155 }

References FPT_HEIGHT, FPT_ITALIC, FPT_LAYER, FPT_ORIENTATION, FPT_SHOWN, FPT_TEXT, FPT_THICKNESS, FPT_UPRIGHT, FPT_WIDTH, FPT_XOFFSET, and FPT_YOFFSET.

Referenced by CanSetValueAs().

◆ CanSetValueAs()

bool FP_TEXT_GRID_TABLE::CanSetValueAs ( int  aRow,
int  aCol,
const wxString &  aTypeName 
)
override

Definition at line 158 of file fp_text_grid_table.cpp.

159 {
160  return CanGetValueAs( aRow, aCol, aTypeName );
161 }
bool CanGetValueAs(int aRow, int aCol, const wxString &aTypeName) override

References CanGetValueAs().

◆ GetAttr()

wxGridCellAttr * FP_TEXT_GRID_TABLE::GetAttr ( int  row,
int  col,
wxGridCellAttr::wxAttrKind  kind 
)
override

Definition at line 164 of file fp_text_grid_table.cpp.

165 {
166  switch( aCol )
167  {
168  case FPT_TEXT:
169  case FPT_WIDTH:
170  case FPT_HEIGHT:
171  case FPT_THICKNESS:
172  case FPT_XOFFSET:
173  case FPT_YOFFSET:
174  return nullptr;
175 
176  case FPT_SHOWN:
177  case FPT_ITALIC:
178  case FPT_UPRIGHT:
179  m_boolColAttr->IncRef();
180  return m_boolColAttr;
181 
182  case FPT_LAYER:
183  m_layerColAttr->IncRef();
184  return m_layerColAttr;
185 
186  case FPT_ORIENTATION:
187  m_orientationColAttr->IncRef();
188  return m_orientationColAttr;
189 
190  default:
191  wxFAIL;
192  return nullptr;
193  }
194 }
wxGridCellAttr * m_orientationColAttr
wxGridCellAttr * m_layerColAttr
wxGridCellAttr * m_boolColAttr

References FPT_HEIGHT, FPT_ITALIC, FPT_LAYER, FPT_ORIENTATION, FPT_SHOWN, FPT_TEXT, FPT_THICKNESS, FPT_UPRIGHT, FPT_WIDTH, FPT_XOFFSET, FPT_YOFFSET, m_boolColAttr, m_layerColAttr, and m_orientationColAttr.

◆ GetColLabelValue()

wxString FP_TEXT_GRID_TABLE::GetColLabelValue ( int  aCol)
override

Definition at line 99 of file fp_text_grid_table.cpp.

100 {
101  switch( aCol )
102  {
103  case FPT_TEXT: return _( "Text Items" );
104  case FPT_SHOWN: return _( "Show" );
105  case FPT_WIDTH: return _( "Width" );
106  case FPT_HEIGHT: return _( "Height" );
107  case FPT_THICKNESS: return _( "Thickness" );
108  case FPT_ITALIC: return _( "Italic" );
109  case FPT_LAYER: return _( "Layer" );
110  case FPT_ORIENTATION: return _( "Orientation" );
111  case FPT_UPRIGHT: return _( "Keep Upright" );
112  case FPT_XOFFSET: return _( "X Offset" );
113  case FPT_YOFFSET: return _( "Y Offset" );
114  default: wxFAIL; return wxEmptyString;
115  }
116 }
#define _(s)

References _, FPT_HEIGHT, FPT_ITALIC, FPT_LAYER, FPT_ORIENTATION, FPT_SHOWN, FPT_TEXT, FPT_THICKNESS, FPT_UPRIGHT, FPT_WIDTH, FPT_XOFFSET, and FPT_YOFFSET.

◆ GetNumberCols()

int FP_TEXT_GRID_TABLE::GetNumberCols ( )
inlineoverride

Definition at line 61 of file fp_text_grid_table.h.

61 { return FPT_COUNT; }

References FPT_COUNT.

◆ GetNumberRows()

int FP_TEXT_GRID_TABLE::GetNumberRows ( )
inlineoverride

◆ GetRowLabelValue()

wxString FP_TEXT_GRID_TABLE::GetRowLabelValue ( int  aRow)
override

Definition at line 119 of file fp_text_grid_table.cpp.

120 {
121  switch( aRow )
122  {
123  case 0: return _( "Reference designator" );
124  case 1: return _( "Value" );
125  default: return wxEmptyString;
126  }
127 }
#define _(s)

References _.

◆ GetValue()

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

Definition at line 197 of file fp_text_grid_table.cpp.

198 {
199  const FP_TEXT& text = this->at((size_t) aRow );
200 
201  switch( aCol )
202  {
203  case FPT_TEXT:
204  return text.GetText();
205 
206  case FPT_WIDTH:
207  return StringFromValue( m_frame->GetUserUnits(), text.GetTextWidth(), true );
208 
209  case FPT_HEIGHT:
210  return StringFromValue( m_frame->GetUserUnits(), text.GetTextHeight(), true );
211 
212  case FPT_THICKNESS:
213  return StringFromValue( m_frame->GetUserUnits(), text.GetTextThickness(), true );
214 
215  case FPT_LAYER:
216  return text.GetLayerName();
217 
218  case FPT_ORIENTATION:
219  return StringFromValue( EDA_UNITS::DEGREES, (int) NormalizeAnglePos( text.GetTextAngle() ),
220  true );
221 
222  case FPT_XOFFSET:
223  return StringFromValue( m_frame->GetUserUnits(), text.GetPos0().x, true );
224 
225  case FPT_YOFFSET:
226  return StringFromValue( m_frame->GetUserUnits(), text.GetPos0().y, true );
227 
228  default:
229  // we can't assert here because wxWidgets sometimes calls this without checking
230  // the column type when trying to see if there's an overflow
231  return wxT( "bad wxWidgets!" );
232  }
233 }
PCB_BASE_FRAME * m_frame
T NormalizeAnglePos(T Angle)
Normalize angle to be in the 0.0 .. 360.0 range: angle is in 1/10 degrees.
Definition: trigo.h:281
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:204
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References DEGREES, FPT_HEIGHT, FPT_LAYER, FPT_ORIENTATION, FPT_TEXT, FPT_THICKNESS, FPT_WIDTH, FPT_XOFFSET, FPT_YOFFSET, EDA_BASE_FRAME::GetUserUnits(), m_frame, NormalizeAnglePos(), StringFromValue(), and text.

◆ GetValueAsBool()

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

Definition at line 236 of file fp_text_grid_table.cpp.

237 {
238  FP_TEXT& text = this->at((size_t) aRow );
239 
240  switch( aCol )
241  {
242  case FPT_SHOWN: return text.IsVisible();
243  case FPT_ITALIC: return text.IsItalic();
244  case FPT_UPRIGHT: return text.IsKeepUpright();
245  default:
246  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
247  return false;
248  }
249 }
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References Format(), FPT_ITALIC, FPT_SHOWN, FPT_UPRIGHT, and text.

◆ GetValueAsLong()

long FP_TEXT_GRID_TABLE::GetValueAsLong ( int  aRow,
int  aCol 
)
override

Definition at line 252 of file fp_text_grid_table.cpp.

253 {
254  FP_TEXT& text = this->at((size_t) aRow );
255 
256  switch( aCol )
257  {
258  case FPT_LAYER: return text.GetLayer();
259  default:
260  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a long value" ), aCol ) );
261  return 0;
262  }
263 }
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References Format(), FPT_LAYER, and text.

◆ IsEmptyCell()

bool FP_TEXT_GRID_TABLE::IsEmptyCell ( int  row,
int  col 
)
inlineoverride

Definition at line 66 of file fp_text_grid_table.h.

67  {
68  return false; // don't allow adjacent cell overflow, even if we are actually empty
69  }

◆ onUnitsChanged()

void FP_TEXT_GRID_TABLE::onUnitsChanged ( wxCommandEvent &  aEvent)
protected

Definition at line 90 of file fp_text_grid_table.cpp.

91 {
92  if( GetView() )
93  GetView()->ForceRefresh();
94 
95  aEvent.Skip();
96 }

Referenced by FP_TEXT_GRID_TABLE(), and ~FP_TEXT_GRID_TABLE().

◆ SetValue()

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

Definition at line 266 of file fp_text_grid_table.cpp.

267 {
268  FP_TEXT& text = this->at((size_t) aRow );
269  wxPoint pos;
270 
271  switch( aCol )
272  {
273  case FPT_TEXT:
274  text.SetText( aValue );
275  break;
276 
277  case FPT_WIDTH:
278  text.SetTextWidth( ValueFromString( m_frame->GetUserUnits(), aValue ) );
279  break;
280 
281  case FPT_HEIGHT:
282  text.SetTextHeight( ValueFromString( m_frame->GetUserUnits(), aValue ) );
283  break;
284 
285  case FPT_THICKNESS:text.SetTextThickness( ValueFromString( m_frame->GetUserUnits(), aValue ) );
286  break;
287 
288  case FPT_ORIENTATION:
289  text.SetTextAngle( DoubleValueFromString( EDA_UNITS::DEGREES, aValue ) );
290  text.SetDrawCoord();
291  break;
292 
293  case FPT_XOFFSET:
294  case FPT_YOFFSET:
295  pos = text.GetPos0();
296 
297  if( aCol == FPT_XOFFSET )
298  pos.x = ValueFromString( m_frame->GetUserUnits(), aValue );
299  else
300  pos.y = ValueFromString( m_frame->GetUserUnits(), aValue );
301 
302  text.SetPos0( pos );
303  text.SetDrawCoord();
304  break;
305 
306  default:
307  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a string value" ), aCol ) );
308  break;
309  }
310 
311  GetView()->Refresh();
312 }
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:411
PCB_BASE_FRAME * m_frame
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
double DoubleValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType)
Function DoubleValueFromString converts aTextValue to a double.
Definition: base_units.cpp:302
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References DEGREES, DoubleValueFromString(), Format(), FPT_HEIGHT, FPT_ORIENTATION, FPT_TEXT, FPT_THICKNESS, FPT_WIDTH, FPT_XOFFSET, FPT_YOFFSET, EDA_BASE_FRAME::GetUserUnits(), m_frame, text, and ValueFromString().

◆ SetValueAsBool()

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

Definition at line 315 of file fp_text_grid_table.cpp.

316 {
317  FP_TEXT& text = this->at((size_t) aRow );
318 
319  switch( aCol )
320  {
321  case FPT_SHOWN:
322  text.SetVisible( aValue );
323  break;
324 
325  case FPT_ITALIC:
326  text.SetItalic( aValue );
327  break;
328 
329  case FPT_UPRIGHT:text.SetKeepUpright( aValue );
330  break;
331 
332  default:
333  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
334  break;
335  }
336 }
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References Format(), FPT_ITALIC, FPT_SHOWN, FPT_UPRIGHT, and text.

◆ SetValueAsLong()

void FP_TEXT_GRID_TABLE::SetValueAsLong ( int  aRow,
int  aCol,
long  aValue 
)
override

Definition at line 339 of file fp_text_grid_table.cpp.

340 {
341  FP_TEXT& text = this->at((size_t) aRow );
342 
343  switch( aCol )
344  {
345  case FPT_LAYER:
346  text.SetLayer( ToLAYER_ID( (int) aValue ) );
347  text.SetMirrored( IsBackLayer( text.GetLayer() ) );
348  break;
349 
350  default:
351  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a long value" ), aCol ) );
352  break;
353  }
354 }
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
Definition: layer_ids.h:907
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:914

References Format(), FPT_LAYER, IsBackLayer(), text, and ToLAYER_ID().

Member Data Documentation

◆ m_boolColAttr

wxGridCellAttr* FP_TEXT_GRID_TABLE::m_boolColAttr
private

Definition at line 90 of file fp_text_grid_table.h.

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

◆ m_frame

PCB_BASE_FRAME* FP_TEXT_GRID_TABLE::m_frame
private

Definition at line 87 of file fp_text_grid_table.h.

Referenced by FP_TEXT_GRID_TABLE(), GetValue(), SetValue(), and ~FP_TEXT_GRID_TABLE().

◆ m_layerColAttr

wxGridCellAttr* FP_TEXT_GRID_TABLE::m_layerColAttr
private

Definition at line 92 of file fp_text_grid_table.h.

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

◆ m_orientationColAttr

wxGridCellAttr* FP_TEXT_GRID_TABLE::m_orientationColAttr
private

Definition at line 91 of file fp_text_grid_table.h.

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

◆ m_readOnlyAttr

wxGridCellAttr* FP_TEXT_GRID_TABLE::m_readOnlyAttr
private

Definition at line 89 of file fp_text_grid_table.h.

Referenced by FP_TEXT_GRID_TABLE(), and ~FP_TEXT_GRID_TABLE().


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