KiCad PCB EDA Suite
TEXT_MOD_GRID_TABLE Class Reference

#include <text_mod_grid_table.h>

Inheritance diagram for TEXT_MOD_GRID_TABLE:

Public Member Functions

 TEXT_MOD_GRID_TABLE (EDA_UNITS userUnits, PCB_BASE_FRAME *aFrame)
 
 ~TEXT_MOD_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 text_mod_grid_table.h.

Constructor & Destructor Documentation

◆ TEXT_MOD_GRID_TABLE()

TEXT_MOD_GRID_TABLE::TEXT_MOD_GRID_TABLE ( EDA_UNITS  userUnits,
PCB_BASE_FRAME aFrame 
)

Definition at line 41 of file text_mod_grid_table.cpp.

42  : m_userUnits( aUserUnits ), m_frame( aFrame )
43 {
44  // Build the column attributes.
45 
46  m_readOnlyAttr = new wxGridCellAttr;
47  m_readOnlyAttr->SetReadOnly( true );
48 
49  m_boolColAttr = new wxGridCellAttr;
50  m_boolColAttr->SetRenderer( new wxGridCellBoolRenderer() );
51  m_boolColAttr->SetEditor( new wxGridCellBoolEditor() );
52  m_boolColAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
53 
54  if( g_menuOrientations.IsEmpty() )
55  {
56  g_menuOrientations.push_back(
58  g_menuOrientations.push_back(
59  wxT( "90 " ) + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
60  g_menuOrientations.push_back(
61  wxT( "-90 " ) + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
62  g_menuOrientations.push_back(
63  wxT( "180 " ) + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
64  }
65 
66  m_orientationColAttr = new wxGridCellAttr;
68 
69  m_layerColAttr = new wxGridCellAttr;
70  m_layerColAttr->SetRenderer( new GRID_CELL_LAYER_RENDERER( m_frame ) );
72 }
wxGridCellAttr * m_boolColAttr
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, bool aUseMils, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:495
wxGridCellAttr * m_orientationColAttr
wxGridCellAttr * m_readOnlyAttr
PCB_BASE_FRAME * m_frame
wxArrayString g_menuOrientations
wxGridCellAttr * m_layerColAttr
static LSET ForbiddenTextLayers()
Function ForbiddenTextLayers Layers which are now allowed to have text on them.
Definition: lset.cpp:832

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

◆ ~TEXT_MOD_GRID_TABLE()

TEXT_MOD_GRID_TABLE::~TEXT_MOD_GRID_TABLE ( )

Definition at line 75 of file text_mod_grid_table.cpp.

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

References m_boolColAttr, m_layerColAttr, m_orientationColAttr, and m_readOnlyAttr.

Member Function Documentation

◆ CanGetValueAs()

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

Definition at line 115 of file text_mod_grid_table.cpp.

116 {
117  switch( aCol )
118  {
119  case TMC_TEXT:
120  case TMC_WIDTH:
121  case TMC_HEIGHT:
122  case TMC_THICKNESS:
123  case TMC_ORIENTATION:
124  case TMC_XOFFSET:
125  case TMC_YOFFSET:
126  return aTypeName == wxGRID_VALUE_STRING;
127 
128  case TMC_SHOWN:
129  case TMC_ITALIC:
130  case TMC_UPRIGHT:
131  return aTypeName == wxGRID_VALUE_BOOL;
132 
133  case TMC_LAYER:
134  return aTypeName == wxGRID_VALUE_NUMBER;
135 
136  default:
137  wxFAIL;
138  return false;
139  }
140 }

References TMC_HEIGHT, TMC_ITALIC, TMC_LAYER, TMC_ORIENTATION, TMC_SHOWN, TMC_TEXT, TMC_THICKNESS, TMC_UPRIGHT, TMC_WIDTH, TMC_XOFFSET, and TMC_YOFFSET.

Referenced by CanSetValueAs().

◆ CanSetValueAs()

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

Definition at line 143 of file text_mod_grid_table.cpp.

144 {
145  return CanGetValueAs( aRow, aCol, aTypeName );
146 }
bool CanGetValueAs(int aRow, int aCol, const wxString &aTypeName) override

References CanGetValueAs().

◆ GetAttr()

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

Definition at line 149 of file text_mod_grid_table.cpp.

150 {
151  switch( aCol )
152  {
153  case TMC_TEXT:
154  case TMC_WIDTH:
155  case TMC_HEIGHT:
156  case TMC_THICKNESS:
157  case TMC_XOFFSET:
158  case TMC_YOFFSET:
159  return nullptr;
160 
161  case TMC_SHOWN:
162  case TMC_ITALIC:
163  case TMC_UPRIGHT:
164  m_boolColAttr->IncRef();
165  return m_boolColAttr;
166 
167  case TMC_LAYER:
168  m_layerColAttr->IncRef();
169  return m_layerColAttr;
170 
171  case TMC_ORIENTATION:
172  m_orientationColAttr->IncRef();
173  return m_orientationColAttr;
174 
175  default:
176  wxFAIL;
177  return nullptr;
178  }
179 }
wxGridCellAttr * m_boolColAttr
wxGridCellAttr * m_orientationColAttr
wxGridCellAttr * m_layerColAttr

References m_boolColAttr, m_layerColAttr, m_orientationColAttr, TMC_HEIGHT, TMC_ITALIC, TMC_LAYER, TMC_ORIENTATION, TMC_SHOWN, TMC_TEXT, TMC_THICKNESS, TMC_UPRIGHT, TMC_WIDTH, TMC_XOFFSET, and TMC_YOFFSET.

◆ GetColLabelValue()

wxString TEXT_MOD_GRID_TABLE::GetColLabelValue ( int  aCol)
override

Definition at line 84 of file text_mod_grid_table.cpp.

85 {
86  switch( aCol )
87  {
88  case TMC_TEXT: return _( "Text Items" );
89  case TMC_SHOWN: return _( "Show" );
90  case TMC_WIDTH: return _( "Width" );
91  case TMC_HEIGHT: return _( "Height" );
92  case TMC_THICKNESS: return _( "Thickness" );
93  case TMC_ITALIC: return _( "Italic" );
94  case TMC_LAYER: return _( "Layer" );
95  case TMC_ORIENTATION: return _( "Orientation" );
96  case TMC_UPRIGHT: return _( "Keep Upright" );
97  case TMC_XOFFSET: return _( "X Offset" );
98  case TMC_YOFFSET: return _( "Y Offset" );
99  default: wxFAIL; return wxEmptyString;
100  }
101 }
#define _(s)
Definition: 3d_actions.cpp:33

References _, TMC_HEIGHT, TMC_ITALIC, TMC_LAYER, TMC_ORIENTATION, TMC_SHOWN, TMC_TEXT, TMC_THICKNESS, TMC_UPRIGHT, TMC_WIDTH, TMC_XOFFSET, and TMC_YOFFSET.

◆ GetNumberCols()

int TEXT_MOD_GRID_TABLE::GetNumberCols ( )
inlineoverride

Definition at line 61 of file text_mod_grid_table.h.

61 { return TMC_COUNT; }

References TMC_COUNT.

◆ GetNumberRows()

int TEXT_MOD_GRID_TABLE::GetNumberRows ( )
inlineoverride

◆ GetRowLabelValue()

wxString TEXT_MOD_GRID_TABLE::GetRowLabelValue ( int  aRow)
override

Definition at line 104 of file text_mod_grid_table.cpp.

105 {
106  switch( aRow )
107  {
108  case 0: return _( "Reference designator" );
109  case 1: return _( "Value" );
110  default: return wxEmptyString;
111  }
112 }
#define _(s)
Definition: 3d_actions.cpp:33

References _.

◆ GetValue()

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

Definition at line 182 of file text_mod_grid_table.cpp.

183 {
184  const TEXTE_MODULE& text = this->at( (size_t) aRow );
185 
186  switch( aCol )
187  {
188  case TMC_TEXT:
189  return text.GetText();
190 
191  case TMC_WIDTH:
192  return StringFromValue( m_userUnits, text.GetTextWidth(), true, true );
193 
194  case TMC_HEIGHT:
195  return StringFromValue( m_userUnits, text.GetTextHeight(), true, true );
196 
197  case TMC_THICKNESS:
198  return StringFromValue( m_userUnits, text.GetTextThickness(), true, true );
199 
200  case TMC_LAYER:
201  return text.GetLayerName();
202 
203  case TMC_ORIENTATION:
205  true );
206 
207  case TMC_XOFFSET:
208  return StringFromValue( m_userUnits, text.GetPos0().x, true );
209 
210  case TMC_YOFFSET:
211  return StringFromValue( m_userUnits, text.GetPos0().y, true );
212 
213  default:
214  // we can't assert here because wxWidgets sometimes calls this without checking
215  // the column type when trying to see if there's an overflow
216  return wxT( "bad wxWidgets!" );
217  }
218 }
double GetTextAngle() const
Definition: eda_text.h:174
int GetTextThickness() const
Definition: eda_text.h:159
int GetTextHeight() const
Definition: eda_text.h:245
const wxPoint & GetPos0() const
int GetTextWidth() const
Definition: eda_text.h:242
T NormalizeAnglePos(T Angle)
Normalize angle to be in the 0.0 .
Definition: trigo.h:248
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:127
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils, EDA_DATA_TYPE aType)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:233

References DEGREES, BOARD_ITEM::GetLayerName(), TEXTE_MODULE::GetPos0(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextHeight(), EDA_TEXT::GetTextThickness(), EDA_TEXT::GetTextWidth(), m_userUnits, NormalizeAnglePos(), StringFromValue(), TMC_HEIGHT, TMC_LAYER, TMC_ORIENTATION, TMC_TEXT, TMC_THICKNESS, TMC_WIDTH, TMC_XOFFSET, TMC_YOFFSET, wxPoint::x, and wxPoint::y.

◆ GetValueAsBool()

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

Definition at line 221 of file text_mod_grid_table.cpp.

222 {
223  TEXTE_MODULE& text = this->at( (size_t) aRow );
224 
225  switch( aCol )
226  {
227  case TMC_SHOWN: return text.IsVisible();
228  case TMC_ITALIC: return text.IsItalic();
229  case TMC_UPRIGHT: return text.IsKeepUpright();
230  default:
231  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
232  return false;
233  }
234 }
bool IsVisible() const
Definition: eda_text.h:186
bool IsItalic() const
Definition: eda_text.h:180
bool IsKeepUpright()
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205

References Format(), EDA_TEXT::IsItalic(), TEXTE_MODULE::IsKeepUpright(), EDA_TEXT::IsVisible(), TMC_ITALIC, TMC_SHOWN, and TMC_UPRIGHT.

◆ GetValueAsLong()

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

Definition at line 237 of file text_mod_grid_table.cpp.

238 {
239  TEXTE_MODULE& text = this->at( (size_t) aRow );
240 
241  switch( aCol )
242  {
243  case TMC_LAYER: return text.GetLayer();
244  default:
245  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a long value" ), aCol ) );
246  return 0;
247  }
248 }
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.

References Format(), BOARD_ITEM::GetLayer(), and TMC_LAYER.

◆ IsEmptyCell()

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

Definition at line 66 of file text_mod_grid_table.h.

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

◆ SetValue()

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

Definition at line 251 of file text_mod_grid_table.cpp.

252 {
253  TEXTE_MODULE& text = this->at( (size_t) aRow );
254  wxPoint pos;
255 
256  switch( aCol )
257  {
258  case TMC_TEXT:
259  text.SetText( aValue );
260  break;
261 
262  case TMC_WIDTH:
263  text.SetTextWidth( ValueFromString( m_userUnits, aValue, true ) );
264  break;
265 
266  case TMC_HEIGHT:
267  text.SetTextHeight( ValueFromString( m_userUnits, aValue, true ) );
268  break;
269 
270  case TMC_THICKNESS:text.SetTextThickness( ValueFromString( m_userUnits, aValue, true ));
271  break;
272 
273  case TMC_ORIENTATION:
275  text.SetDrawCoord();
276  break;
277 
278  case TMC_XOFFSET:
279  case TMC_YOFFSET:
280  pos = text.GetPos0();
281 
282  if( aCol == TMC_XOFFSET )
283  pos.x = ValueFromString( m_userUnits, aValue );
284  else
285  pos.y = ValueFromString( m_userUnits, aValue );
286 
287  text.SetPos0( pos );
288  text.SetDrawCoord();
289  break;
290 
291  default:
292  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a string value" ), aCol ) );
293  break;
294  }
295 
296  GetView()->Refresh();
297 }
double DoubleValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, bool aUseMils, EDA_DATA_TYPE aType)
Function DoubleValueFromString converts aTextValue to a double.
Definition: base_units.cpp:346
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
void SetTextAngle(double aAngle) override
void SetPos0(const wxPoint &aPos)
const wxPoint & GetPos0() const
void SetTextWidth(int aWidth)
Definition: eda_text.h:241
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void SetDrawCoord()
Set absolute coordinates.
void SetTextHeight(int aHeight)
Definition: eda_text.h:244
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:158
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, bool aUseMils, EDA_DATA_TYPE aType)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:471

References DEGREES, DoubleValueFromString(), Format(), TEXTE_MODULE::GetPos0(), m_userUnits, TEXTE_MODULE::SetDrawCoord(), TEXTE_MODULE::SetPos0(), EDA_TEXT::SetText(), TEXTE_MODULE::SetTextAngle(), EDA_TEXT::SetTextHeight(), EDA_TEXT::SetTextThickness(), EDA_TEXT::SetTextWidth(), TMC_HEIGHT, TMC_ORIENTATION, TMC_TEXT, TMC_THICKNESS, TMC_WIDTH, TMC_XOFFSET, TMC_YOFFSET, ValueFromString(), wxPoint::x, and wxPoint::y.

◆ SetValueAsBool()

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

Definition at line 300 of file text_mod_grid_table.cpp.

301 {
302  TEXTE_MODULE& text = this->at( (size_t) aRow );
303 
304  switch( aCol )
305  {
306  case TMC_SHOWN:
307  text.SetVisible( aValue );
308  break;
309 
310  case TMC_ITALIC:
311  text.SetItalic( aValue );
312  break;
313 
314  case TMC_UPRIGHT:text.SetKeepUpright( aValue );
315  break;
316 
317  default:
318  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
319  break;
320  }
321 }
void SetKeepUpright(bool aKeepUpright)
void SetItalic(bool isItalic)
Definition: eda_text.h:179
void SetVisible(bool aVisible)
Definition: eda_text.h:185
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205

References Format(), EDA_TEXT::SetItalic(), TEXTE_MODULE::SetKeepUpright(), EDA_TEXT::SetVisible(), TMC_ITALIC, TMC_SHOWN, and TMC_UPRIGHT.

◆ SetValueAsLong()

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

Definition at line 324 of file text_mod_grid_table.cpp.

325 {
326  TEXTE_MODULE& text = this->at( (size_t) aRow );
327 
328  switch( aCol )
329  {
330  case TMC_LAYER:
331  text.SetLayer( ToLAYER_ID( (int) aValue ) );
332  text.SetMirrored( IsBackLayer( text.GetLayer() ) );
333  break;
334 
335  default:
336  wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a long value" ), aCol ) );
337  break;
338  }
339 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:188
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:849

References Format(), BOARD_ITEM::GetLayer(), IsBackLayer(), BOARD_ITEM::SetLayer(), EDA_TEXT::SetMirrored(), TMC_LAYER, and ToLAYER_ID().

Member Data Documentation

◆ m_boolColAttr

wxGridCellAttr* TEXT_MOD_GRID_TABLE::m_boolColAttr
private

Definition at line 88 of file text_mod_grid_table.h.

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

◆ m_frame

PCB_BASE_FRAME* TEXT_MOD_GRID_TABLE::m_frame
private

Definition at line 85 of file text_mod_grid_table.h.

Referenced by TEXT_MOD_GRID_TABLE().

◆ m_layerColAttr

wxGridCellAttr* TEXT_MOD_GRID_TABLE::m_layerColAttr
private

Definition at line 90 of file text_mod_grid_table.h.

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

◆ m_orientationColAttr

wxGridCellAttr* TEXT_MOD_GRID_TABLE::m_orientationColAttr
private

Definition at line 89 of file text_mod_grid_table.h.

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

◆ m_readOnlyAttr

wxGridCellAttr* TEXT_MOD_GRID_TABLE::m_readOnlyAttr
private

Definition at line 87 of file text_mod_grid_table.h.

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

◆ m_userUnits

EDA_UNITS TEXT_MOD_GRID_TABLE::m_userUnits
private

Definition at line 84 of file text_mod_grid_table.h.

Referenced by GetValue(), and SetValue().


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