KiCad PCB EDA Suite
EDA_MSG_PANEL Class Reference

class EDA_MSG_PANEL is a panel to display various information messages. More...

#include <msgpanel.h>

Inheritance diagram for EDA_MSG_PANEL:

Public Member Functions

 EDA_MSG_PANEL (wxWindow *aParent, int aId, const wxPoint &aPosition, const wxSize &aSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxPanelNameStr)
 
 ~EDA_MSG_PANEL ()
 
void OnPaint (wxPaintEvent &aEvent)
 
void EraseMsgBox ()
 
void SetMessage (int aXPosition, const wxString &aUpperText, const wxString &aLowerText, COLOR4D aColor)
 Function SetMessage sets a message at aXPosition to aUpperText and aLowerText in the message panel. More...
 
void AppendMessage (const wxString &aUpperText, const wxString &aLowerText, COLOR4D aColor, int aPad=6)
 Function AppendMessage appends a message to the message panel. More...
 
void AppendMessage (const MSG_PANEL_ITEM &aMessageItem)
 Function AppendMessage appends aMessageItem to the message panel. More...
 

Static Public Member Functions

static int GetRequiredHeight ()
 Function GetRequiredHeight returns the required height (in pixels) of a EDA_MSG_PANEL. More...
 

Protected Member Functions

void showItem (wxDC &dc, const MSG_PANEL_ITEM &aItem)
 
void erase (wxDC *DC)
 
wxSize computeTextSize (const wxString &text) const
 Calculate the width and height of a text string using the system UI font. More...
 

Static Protected Member Functions

static wxSize computeFontSize ()
 Function getFontSize computes the height and width of a 'W' in the system font. More...
 

Protected Attributes

MSG_PANEL_ITEMS m_Items
 
int m_last_x
 the last used x coordinate More...
 
wxSize m_fontSize
 

Detailed Description

class EDA_MSG_PANEL is a panel to display various information messages.

Definition at line 111 of file msgpanel.h.

Constructor & Destructor Documentation

EDA_MSG_PANEL::EDA_MSG_PANEL ( wxWindow *  aParent,
int  aId,
const wxPoint aPosition,
const wxSize &  aSize,
long  style = wxTAB_TRAVERSAL,
const wxString &  name = wxPanelNameStr 
)

Definition at line 39 of file msgpanel.cpp.

41  :
42  wxPanel( aParent, aId, aPosition, aSize, style, name )
43 {
44  SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
45  SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
46  m_last_x = 0;
47 
49 }
wxSize m_fontSize
Definition: msgpanel.h:116
int m_last_x
the last used x coordinate
Definition: msgpanel.h:115
const char * name
static wxSize computeFontSize()
Function getFontSize computes the height and width of a 'W' in the system font.
Definition: msgpanel.cpp:57
EDA_MSG_PANEL::~EDA_MSG_PANEL ( )

Definition at line 52 of file msgpanel.cpp.

53 {
54 }

Member Function Documentation

void EDA_MSG_PANEL::AppendMessage ( const wxString &  aUpperText,
const wxString &  aLowerText,
COLOR4D  aColor,
int  aPad = 6 
)

Function AppendMessage appends a message to the message panel.

This method automatically adjusts for the width of the text string. Making consecutive calls to AppendMessage will append each message to the right of the last message. This message is not compatible with Affiche_1_Parametre.

Parameters
aUpperTextThe message upper text.
aLowerTextThe message lower text.
aColorA color to use for the message text
aPadNumber of spaces to pad between messages (default = 4).

Definition at line 110 of file msgpanel.cpp.

References computeTextSize(), MSG_PANEL_ITEM::m_Color, m_fontSize, m_Items, m_last_x, MSG_PANEL_ITEM::m_LowerText, MSG_PANEL_ITEM::m_LowerY, MSG_PANEL_ITEM::m_UpperText, MSG_PANEL_ITEM::m_UpperY, MSG_PANEL_ITEM::m_X, and Refresh().

Referenced by AppendMessage(), EDA_DRAW_FRAME::AppendMsgPanel(), and EDA_DRAW_FRAME::SetMsgPanel().

113 {
114  wxString text;
115  wxSize drawSize = GetClientSize();
116 
117  text = ( aUpperText.Len() > aLowerText.Len() ) ? aUpperText : aLowerText;
118  text.Append( ' ', aPad );
119 
120  MSG_PANEL_ITEM item;
121 
122  /* Don't put the first message a window client position 0. Offset by
123  * one 'W' character width. */
124  if( m_last_x == 0 )
125  m_last_x = m_fontSize.x;
126 
127  item.m_X = m_last_x;
128 
129  item.m_UpperY = ( drawSize.y / 2 ) - m_fontSize.y;
130  item.m_LowerY = drawSize.y - m_fontSize.y;
131 
132  item.m_UpperText = aUpperText;
133  item.m_LowerText = aLowerText;
134  item.m_Color = aColor;
135  m_Items.push_back( item );
136  m_last_x += computeTextSize( text ).x;
137 
138  // Add an extra space between texts for a better look:
139  m_last_x += m_fontSize.x;
140 
141  Refresh();
142 }
wxSize computeTextSize(const wxString &text) const
Calculate the width and height of a text string using the system UI font.
Definition: msgpanel.cpp:78
COLOR4D m_Color
Definition: msgpanel.h:60
MSG_PANEL_ITEMS m_Items
Definition: msgpanel.h:114
wxString m_LowerText
Definition: msgpanel.h:59
wxSize m_fontSize
Definition: msgpanel.h:116
void Refresh()
Update the board display after modifying it bu a python script (note: it is automatically called by a...
int m_last_x
the last used x coordinate
Definition: msgpanel.h:115
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
wxString m_UpperText
Definition: msgpanel.h:58
void EDA_MSG_PANEL::AppendMessage ( const MSG_PANEL_ITEM aMessageItem)
inline

Function AppendMessage appends aMessageItem to the message panel.

Parameters
aMessageItemis a reference to an MSG_PANEL_ITEM containing the message to append to the panel.

Definition at line 186 of file msgpanel.h.

References AppendMessage(), MSG_PANEL_ITEM::GetColor(), MSG_PANEL_ITEM::GetLowerText(), MSG_PANEL_ITEM::GetPadding(), and MSG_PANEL_ITEM::GetUpperText().

187  {
188  AppendMessage( aMessageItem.GetUpperText(), aMessageItem.GetLowerText(),
189  aMessageItem.GetColor(), aMessageItem.GetPadding() );
190  }
const wxString & GetLowerText() const
Definition: msgpanel.h:92
COLOR4D GetColor() const
Definition: msgpanel.h:95
void AppendMessage(const wxString &aUpperText, const wxString &aLowerText, COLOR4D aColor, int aPad=6)
Function AppendMessage appends a message to the message panel.
Definition: msgpanel.cpp:110
int GetPadding() const
Definition: msgpanel.h:98
const wxString & GetUpperText() const
Definition: msgpanel.h:89
wxSize EDA_MSG_PANEL::computeFontSize ( )
staticprotected

Function getFontSize computes the height and width of a 'W' in the system font.

Definition at line 57 of file msgpanel.cpp.

Referenced by GetRequiredHeight().

58 {
59  // Get size of the wxSYS_DEFAULT_GUI_FONT
60  wxSize fontSizeInPixels;
61 
62  wxScreenDC dc;
63 
64  dc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
65  dc.GetTextExtent( wxT( "W" ), &fontSizeInPixels.x, &fontSizeInPixels.y );
66 
67  return fontSizeInPixels;
68 }
wxSize EDA_MSG_PANEL::computeTextSize ( const wxString &  text) const
protected

Calculate the width and height of a text string using the system UI font.

Definition at line 78 of file msgpanel.cpp.

Referenced by AppendMessage().

79 {
80  // Get size of the wxSYS_DEFAULT_GUI_FONT
81  wxSize textSizeInPixels;
82 
83  wxScreenDC dc;
84 
85  dc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
86  dc.GetTextExtent( aText, &textSizeInPixels.x, &textSizeInPixels.y );
87 
88  return textSizeInPixels;
89 }
void EDA_MSG_PANEL::erase ( wxDC *  DC)
protected

Definition at line 223 of file msgpanel.cpp.

References color.

Referenced by OnPaint().

224 {
225  wxPen pen;
226  wxBrush brush;
227 
228  wxSize size = GetClientSize();
229  wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
230 
231  pen.SetColour( color );
232 
233  brush.SetColour( color );
234  brush.SetStyle( wxBRUSHSTYLE_SOLID );
235 
236  aDC->SetPen( pen );
237  aDC->SetBrush( brush );
238  aDC->DrawRectangle( 0, 0, size.x, size.y );
239 }
void EDA_MSG_PANEL::EraseMsgBox ( )

Definition at line 215 of file msgpanel.cpp.

References m_Items, m_last_x, and Refresh().

Referenced by EDA_DRAW_FRAME::ClearMsgPanel(), EDA_DRAW_FRAME::EraseMsgBox(), genPlacementRoutingMatrix(), and GERBVIEW_FRAME::Locate().

216 {
217  m_Items.clear();
218  m_last_x = 0;
219  Refresh();
220 }
MSG_PANEL_ITEMS m_Items
Definition: msgpanel.h:114
void Refresh()
Update the board display after modifying it bu a python script (note: it is automatically called by a...
int m_last_x
the last used x coordinate
Definition: msgpanel.h:115
int EDA_MSG_PANEL::GetRequiredHeight ( )
static

Function GetRequiredHeight returns the required height (in pixels) of a EDA_MSG_PANEL.

This takes into consideration the system gui font, wxSYS_DEFAULT_GUI_FONT.

Definition at line 71 of file msgpanel.cpp.

References computeFontSize().

Referenced by EDA_DRAW_FRAME::EDA_DRAW_FRAME().

72 {
73  // make space for two rows of text plus a number of pixels between them.
74  return 2 * computeFontSize().y + 0;
75 }
static wxSize computeFontSize()
Function getFontSize computes the height and width of a 'W' in the system font.
Definition: msgpanel.cpp:57
void EDA_MSG_PANEL::OnPaint ( wxPaintEvent &  aEvent)

Definition at line 92 of file msgpanel.cpp.

References erase(), m_Items, and showItem().

93 {
94  wxPaintDC dc( this );
95 
96  erase( &dc );
97 
98  dc.SetBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
99  dc.SetBackgroundMode( wxSOLID );
100  dc.SetTextBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
101  dc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) );
102 
103  for( unsigned i=0; i<m_Items.size(); ++i )
104  showItem( dc, m_Items[i] );
105 
106  aEvent.Skip();
107 }
void showItem(wxDC &dc, const MSG_PANEL_ITEM &aItem)
Definition: msgpanel.cpp:197
MSG_PANEL_ITEMS m_Items
Definition: msgpanel.h:114
void erase(wxDC *DC)
Definition: msgpanel.cpp:223
void EDA_MSG_PANEL::SetMessage ( int  aXPosition,
const wxString &  aUpperText,
const wxString &  aLowerText,
COLOR4D  aColor 
)

Function SetMessage sets a message at aXPosition to aUpperText and aLowerText in the message panel.

Parameters
aXPositionThe horizontal position to display the message or less than zero to set the message using the last message position.
aUpperTextThe text to be displayed in top line.
aLowerTextThe text to be displayed in bottom line.
aColorColor of the text to display.

Definition at line 145 of file msgpanel.cpp.

References MSG_PANEL_ITEM::m_Color, m_fontSize, m_Items, m_last_x, MSG_PANEL_ITEM::m_LowerText, MSG_PANEL_ITEM::m_LowerY, MSG_PANEL_ITEM::m_UpperText, MSG_PANEL_ITEM::m_UpperY, MSG_PANEL_ITEM::m_X, Refresh(), and wxPoint::x.

Referenced by genPlacementRoutingMatrix().

147 {
148  wxPoint pos;
149  wxSize drawSize = GetClientSize();
150 
151  if( aXPosition >= 0 )
152  m_last_x = pos.x = aXPosition * (m_fontSize.x + 2);
153  else
154  pos.x = m_last_x;
155 
156  MSG_PANEL_ITEM item;
157 
158  item.m_X = pos.x;
159 
160  item.m_UpperY = (drawSize.y / 2) - m_fontSize.y;
161  item.m_LowerY = drawSize.y - m_fontSize.y;
162 
163  item.m_UpperText = aUpperText;
164  item.m_LowerText = aLowerText;
165  item.m_Color = aColor;
166 
167  int ndx;
168 
169  // update the vector, which is sorted by m_X
170  int limit = m_Items.size();
171 
172  for( ndx=0; ndx<limit; ++ndx )
173  {
174  // replace any item with same X
175  if( m_Items[ndx].m_X == item.m_X )
176  {
177  m_Items[ndx] = item;
178  break;
179  }
180 
181  if( m_Items[ndx].m_X > item.m_X )
182  {
183  m_Items.insert( m_Items.begin() + ndx, item );
184  break;
185  }
186  }
187 
188  if( ndx == limit ) // mutually exclusive with two above if tests
189  {
190  m_Items.push_back( item );
191  }
192 
193  Refresh();
194 }
COLOR4D m_Color
Definition: msgpanel.h:60
MSG_PANEL_ITEMS m_Items
Definition: msgpanel.h:114
wxString m_LowerText
Definition: msgpanel.h:59
wxSize m_fontSize
Definition: msgpanel.h:116
void Refresh()
Update the board display after modifying it bu a python script (note: it is automatically called by a...
int m_last_x
the last used x coordinate
Definition: msgpanel.h:115
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
wxString m_UpperText
Definition: msgpanel.h:58
void EDA_MSG_PANEL::showItem ( wxDC &  dc,
const MSG_PANEL_ITEM aItem 
)
protected

Definition at line 197 of file msgpanel.cpp.

References color, MSG_PANEL_ITEM::m_Color, MSG_PANEL_ITEM::m_LowerText, MSG_PANEL_ITEM::m_LowerY, MSG_PANEL_ITEM::m_UpperText, MSG_PANEL_ITEM::m_UpperY, and MSG_PANEL_ITEM::m_X.

Referenced by OnPaint().

198 {
199  COLOR4D color = aItem.m_Color;
200 
201  aDC.SetTextForeground( color.ToColour() );
202 
203  if( !aItem.m_UpperText.IsEmpty() )
204  {
205  aDC.DrawText( aItem.m_UpperText, aItem.m_X, aItem.m_UpperY );
206  }
207 
208  if( !aItem.m_LowerText.IsEmpty() )
209  {
210  aDC.DrawText( aItem.m_LowerText, aItem.m_X, aItem.m_LowerY );
211  }
212 }
COLOR4D m_Color
Definition: msgpanel.h:60
wxString m_LowerText
Definition: msgpanel.h:59
wxString m_UpperText
Definition: msgpanel.h:58
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

Member Data Documentation

wxSize EDA_MSG_PANEL::m_fontSize
protected

Definition at line 116 of file msgpanel.h.

Referenced by AppendMessage(), and SetMessage().

MSG_PANEL_ITEMS EDA_MSG_PANEL::m_Items
protected

Definition at line 114 of file msgpanel.h.

Referenced by AppendMessage(), EraseMsgBox(), OnPaint(), and SetMessage().

int EDA_MSG_PANEL::m_last_x
protected

the last used x coordinate

Definition at line 115 of file msgpanel.h.

Referenced by AppendMessage(), EraseMsgBox(), and SetMessage().


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