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 (EDA_UNITS userUnits, 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
 

Private Attributes

EDA_UNITS m_userUnits
 
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 ( EDA_UNITS  userUnits,
PCB_BASE_FRAME aFrame 
)

Definition at line 42 of file fp_text_grid_table.cpp.

43  : m_userUnits( aUserUnits ), m_frame( aFrame )
44 {
45  // Build the column attributes.
46 
47  m_readOnlyAttr = new wxGridCellAttr;
48  m_readOnlyAttr->SetReadOnly( true );
49 
50  m_boolColAttr = new wxGridCellAttr;
51  m_boolColAttr->SetRenderer( new wxGridCellBoolRenderer() );
52  m_boolColAttr->SetEditor( new wxGridCellBoolEditor() );
53  m_boolColAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
54 
55  if( g_menuOrientations.IsEmpty() )
56  {
57  g_menuOrientations.push_back(
59  g_menuOrientations.push_back(
60  wxT( "90 " ) + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
61  g_menuOrientations.push_back(
62  wxT( "-90 " ) + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
63  g_menuOrientations.push_back(
64  wxT( "180 " ) + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
65  }
66 
67  m_orientationColAttr = new wxGridCellAttr;
69 
70  m_layerColAttr = new wxGridCellAttr;
71  m_layerColAttr->SetRenderer( new GRID_CELL_LAYER_RENDERER( m_frame ) );
72  m_layerColAttr->SetEditor( new GRID_CELL_LAYER_SELECTOR( m_frame, {} ) );
73 }
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:424
wxGridCellAttr * m_readOnlyAttr
wxGridCellAttr * m_boolColAttr
PCB_BASE_FRAME * m_frame
wxArrayString g_menuOrientations

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

◆ ~FP_TEXT_GRID_TABLE()

FP_TEXT_GRID_TABLE::~FP_TEXT_GRID_TABLE ( )

Definition at line 76 of file fp_text_grid_table.cpp.

77 {
78  m_readOnlyAttr->DecRef();
79  m_boolColAttr->DecRef();
80  m_orientationColAttr->DecRef();
81  m_layerColAttr->DecRef();
82 }
wxGridCellAttr * m_orientationColAttr
wxGridCellAttr * m_layerColAttr
wxGridCellAttr * m_readOnlyAttr
wxGridCellAttr * m_boolColAttr

References m_boolColAttr, m_layerColAttr, m_orientationColAttr, and m_readOnlyAttr.

Member Function Documentation

◆ CanGetValueAs()

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

Definition at line 116 of file fp_text_grid_table.cpp.

117 {
118  switch( aCol )
119  {
120  case FPT_TEXT:
121  case FPT_WIDTH:
122  case FPT_HEIGHT:
123  case FPT_THICKNESS:
124  case FPT_ORIENTATION:
125  case FPT_XOFFSET:
126  case FPT_YOFFSET:
127  return aTypeName == wxGRID_VALUE_STRING;
128 
129  case FPT_SHOWN:
130  case FPT_ITALIC:
131  case FPT_UPRIGHT:
132  return aTypeName == wxGRID_VALUE_BOOL;
133 
134  case FPT_LAYER:
135  return aTypeName == wxGRID_VALUE_NUMBER;
136 
137  default:
138  wxFAIL;
139  return false;
140  }
141 }

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 144 of file fp_text_grid_table.cpp.

145 {
146  return CanGetValueAs( aRow, aCol, aTypeName );
147 }
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 150 of file fp_text_grid_table.cpp.

151 {
152  switch( aCol )
153  {
154  case FPT_TEXT:
155  case FPT_WIDTH:
156  case FPT_HEIGHT:
157  case FPT_THICKNESS:
158  case FPT_XOFFSET:
159  case FPT_YOFFSET:
160  return nullptr;
161 
162  case FPT_SHOWN:
163  case FPT_ITALIC:
164  case FPT_UPRIGHT:
165  m_boolColAttr->IncRef();
166  return m_boolColAttr;
167 
168  case FPT_LAYER:
169  m_layerColAttr->IncRef();
170  return m_layerColAttr;
171 
172  case FPT_ORIENTATION:
173  m_orientationColAttr->IncRef();
174  return m_orientationColAttr;
175 
176  default:
177  wxFAIL;
178  return nullptr;
179  }
180 }
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 85 of file fp_text_grid_table.cpp.

86 {
87  switch( aCol )
88  {
89  case FPT_TEXT: return _( "Text Items" );
90  case FPT_SHOWN: return _( "Show" );
91  case FPT_WIDTH: return _( "Width" );
92  case FPT_HEIGHT: return _( "Height" );
93  case FPT_THICKNESS: return _( "Thickness" );
94  case FPT_ITALIC: return _( "Italic" );
95  case FPT_LAYER: return _( "Layer" );
96  case FPT_ORIENTATION: return _( "Orientation" );
97  case FPT_UPRIGHT: return _( "Keep Upright" );
98  case FPT_XOFFSET: return _( "X Offset" );
99  case FPT_YOFFSET: return _( "Y Offset" );
100  default: wxFAIL; return wxEmptyString;
101  }
102 }
#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 105 of file fp_text_grid_table.cpp.

106 {
107  switch( aRow )
108  {
109  case 0: return _( "Reference designator" );
110  case 1: return _( "Value" );
111  default: return wxEmptyString;
112  }
113 }
#define _(s)

References _.

◆ GetValue()

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

Definition at line 183 of file fp_text_grid_table.cpp.

184 {
185  const FP_TEXT& text = this->at((size_t) aRow );
186 
187  switch( aCol )
188  {
189  case FPT_TEXT:
190  return text.GetText();
191 
192  case FPT_WIDTH:
193  return StringFromValue( m_userUnits, text.GetTextWidth() );
194 
195  case FPT_HEIGHT:
196  return StringFromValue( m_userUnits, text.GetTextHeight() );
197 
198  case FPT_THICKNESS:
199  return StringFromValue( m_userUnits, text.GetTextThickness() );
200 
201  case FPT_LAYER:
202  return text.GetLayerName();
203 
204  case FPT_ORIENTATION:
205  return StringFromValue( EDA_UNITS::DEGREES, (int) NormalizeAnglePos( text.GetTextAngle() ),
206  true );
207 
208  case FPT_XOFFSET:
209  return StringFromValue( m_userUnits, text.GetPos0().x );
210 
211  case FPT_YOFFSET:
212  return StringFromValue( m_userUnits, text.GetPos0().y );
213 
214  default:
215  // we can't assert here because wxWidgets sometimes calls this without checking
216  // the column type when trying to see if there's an overflow
217  return wxT( "bad wxWidgets!" );
218  }
219 }
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

References DEGREES, FPT_HEIGHT, FPT_LAYER, FPT_ORIENTATION, FPT_TEXT, FPT_THICKNESS, FPT_WIDTH, FPT_XOFFSET, FPT_YOFFSET, m_userUnits, NormalizeAnglePos(), StringFromValue(), and text.

◆ GetValueAsBool()

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

Definition at line 222 of file fp_text_grid_table.cpp.

223 {
224  FP_TEXT& text = this->at((size_t) aRow );
225 
226  switch( aCol )
227  {
228  case FPT_SHOWN: return text.IsVisible();
229  case FPT_ITALIC: return text.IsItalic();
230  case FPT_UPRIGHT: return text.IsKeepUpright();
231  default:
232  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
233  return false;
234  }
235 }
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 238 of file fp_text_grid_table.cpp.

239 {
240  FP_TEXT& text = this->at((size_t) aRow );
241 
242  switch( aCol )
243  {
244  case FPT_LAYER: return text.GetLayer();
245  default:
246  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a long value" ), aCol ) );
247  return 0;
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_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  }

◆ SetValue()

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

Definition at line 252 of file fp_text_grid_table.cpp.

253 {
254  FP_TEXT& text = this->at((size_t) aRow );
255  wxPoint pos;
256 
257  switch( aCol )
258  {
259  case FPT_TEXT:
260  text.SetText( aValue );
261  break;
262 
263  case FPT_WIDTH:
264  text.SetTextWidth( ValueFromString( m_userUnits, aValue ) );
265  break;
266 
267  case FPT_HEIGHT:
268  text.SetTextHeight( ValueFromString( m_userUnits, aValue ) );
269  break;
270 
271  case FPT_THICKNESS:text.SetTextThickness( ValueFromString( m_userUnits, aValue ) );
272  break;
273 
274  case FPT_ORIENTATION:
275  text.SetTextAngle( DoubleValueFromString( EDA_UNITS::DEGREES, aValue ) );
276  text.SetDrawCoord();
277  break;
278 
279  case FPT_XOFFSET:
280  case FPT_YOFFSET:
281  pos = text.GetPos0();
282 
283  if( aCol == FPT_XOFFSET )
284  pos.x = ValueFromString( m_userUnits, aValue );
285  else
286  pos.y = ValueFromString( m_userUnits, aValue );
287 
288  text.SetPos0( pos );
289  text.SetDrawCoord();
290  break;
291 
292  default:
293  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a string value" ), aCol ) );
294  break;
295  }
296 
297  GetView()->Refresh();
298 }
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:416
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:307

References DEGREES, DoubleValueFromString(), Format(), FPT_HEIGHT, FPT_ORIENTATION, FPT_TEXT, FPT_THICKNESS, FPT_WIDTH, FPT_XOFFSET, FPT_YOFFSET, m_userUnits, text, and ValueFromString().

◆ SetValueAsBool()

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

Definition at line 301 of file fp_text_grid_table.cpp.

302 {
303  FP_TEXT& text = this->at((size_t) aRow );
304 
305  switch( aCol )
306  {
307  case FPT_SHOWN:
308  text.SetVisible( aValue );
309  break;
310 
311  case FPT_ITALIC:
312  text.SetItalic( aValue );
313  break;
314 
315  case FPT_UPRIGHT:text.SetKeepUpright( aValue );
316  break;
317 
318  default:
319  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
320  break;
321  }
322 }
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 325 of file fp_text_grid_table.cpp.

326 {
327  FP_TEXT& text = this->at((size_t) aRow );
328 
329  switch( aCol )
330  {
331  case FPT_LAYER:
332  text.SetLayer( ToLAYER_ID( (int) aValue ) );
333  text.SetMirrored( IsBackLayer( text.GetLayer() ) );
334  break;
335 
336  default:
337  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a long value" ), aCol ) );
338  break;
339  }
340 }
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
Definition: layer_ids.h:895
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:905

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 88 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 85 of file fp_text_grid_table.h.

Referenced by FP_TEXT_GRID_TABLE().

◆ m_layerColAttr

wxGridCellAttr* FP_TEXT_GRID_TABLE::m_layerColAttr
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_orientationColAttr

wxGridCellAttr* FP_TEXT_GRID_TABLE::m_orientationColAttr
private

Definition at line 89 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 87 of file fp_text_grid_table.h.

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

◆ m_userUnits

EDA_UNITS FP_TEXT_GRID_TABLE::m_userUnits
private

Definition at line 84 of file fp_text_grid_table.h.

Referenced by GetValue(), and SetValue().


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