KiCad PCB EDA Suite
mpInfoLegend Class Reference

Implements the legend to be added to the plot This layer allows you to add a legend to describe the plots in the window. More...

#include <mathplot.h>

Inheritance diagram for mpInfoLegend:
mpInfoLayer mpLayer

Public Member Functions

 mpInfoLegend ()
 Default constructor. More...
 
 mpInfoLegend (wxRect rect, const wxBrush *brush=wxTRANSPARENT_BRUSH)
 Complete constructor, setting initial rectangle and background brush. More...
 
 ~mpInfoLegend ()
 Default destructor. More...
 
virtual void UpdateInfo (mpWindow &w, wxEvent &event) override
 Updates the content of the info box. More...
 
virtual void Plot (wxDC &dc, mpWindow &w) override
 Plot method. More...
 
virtual bool HasBBox () override
 mpInfoLayer has not bounding box. More...
 
virtual bool IsInfo () override
 Specifies that this is an Info box layer. More...
 
virtual bool Inside (wxPoint &point)
 Checks whether a point is inside the info box rectangle. More...
 
virtual void Move (wxPoint delta)
 Moves the layer rectangle of given pixel deltas. More...
 
virtual void UpdateReference ()
 Updates the rectangle reference point. More...
 
wxPoint GetPosition ()
 Returns the position of the upper left corner of the box (in pixels) More...
 
wxSize GetSize ()
 Returns the size of the box (in pixels) More...
 
const wxRect & GetRectangle ()
 Returns the current rectangle coordinates. More...
 
virtual double GetMinX ()
 Get inclusive left border of bounding box. More...
 
virtual double GetMaxX ()
 Get inclusive right border of bounding box. More...
 
virtual double GetMinY ()
 Get inclusive bottom border of bounding box. More...
 
virtual double GetMaxY ()
 Get inclusive top border of bounding box. More...
 
const wxString & GetName () const
 Get layer name. More...
 
const wxFont & GetFont () const
 Get font set for this layer. More...
 
const wxPen & GetPen () const
 Get pen set for this layer. More...
 
void SetContinuity (bool continuity)
 Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points). More...
 
bool GetContinuity () const
 Gets the 'continuity' property of the layer. More...
 
void ShowName (bool show)
 Shows or hides the text label with the name of the layer (default is visible). More...
 
void SetName (wxString name)
 Set layer name. More...
 
void SetFont (wxFont &font)
 Set layer font. More...
 
void SetPen (wxPen pen)
 Set layer pen. More...
 
void SetDrawOutsideMargins (bool drawModeOutside)
 Set Draw mode: inside or outside margins. More...
 
bool GetDrawOutsideMargins ()
 Get Draw mode: inside or outside margins. More...
 
wxBitmap GetColourSquare (int side=16)
 Get a small square bitmap filled with the colour of the pen used in the layer. More...
 
mpLayerType GetLayerType ()
 Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value. More...
 
bool IsVisible ()
 Checks whether the layer is visible or not. More...
 
void SetVisible (bool show)
 Sets layer visibility. More...
 
const wxBrush & GetBrush () const
 Get brush set for this layer. More...
 
void SetBrush (wxBrush brush)
 Set layer brush. More...
 

Protected Attributes

wxRect m_dim
 
wxPoint m_reference
 
wxBrush m_brush
 
int m_winX
 
int m_winY
 
wxFont m_font
 
wxPen m_pen
 
wxString m_name
 
bool m_continuous
 
bool m_showName
 
bool m_drawOutsideMargins
 
mpLayerType m_type
 
bool m_visible
 

Detailed Description

Implements the legend to be added to the plot This layer allows you to add a legend to describe the plots in the window.

The legend uses the layer name as a label, and displays only layers of type mpLAYER_PLOT.

Definition at line 438 of file mathplot.h.

Constructor & Destructor Documentation

◆ mpInfoLegend() [1/2]

mpInfoLegend::mpInfoLegend ( )

Default constructor.

Definition at line 284 of file mathplot.cpp.

284  : mpInfoLayer()
285 {
286 }
mpInfoLayer()
Default constructor.
Definition: mathplot.cpp:103

◆ mpInfoLegend() [2/2]

mpInfoLegend::mpInfoLegend ( wxRect  rect,
const wxBrush *  brush = wxTRANSPARENT_BRUSH 
)

Complete constructor, setting initial rectangle and background brush.

Parameters
rectThe initial bounding rectangle.
brushThe wxBrush to be used for box background: default is transparent
See also
mpInfoLayer::mpInfoLayer

Definition at line 289 of file mathplot.cpp.

289  : mpInfoLayer( rect, brush )
290 {
291 }
mpInfoLayer()
Default constructor.
Definition: mathplot.cpp:103

◆ ~mpInfoLegend()

mpInfoLegend::~mpInfoLegend ( )

Default destructor.

Definition at line 294 of file mathplot.cpp.

295 {
296 }

Member Function Documentation

◆ GetBrush()

const wxBrush& mpLayer::GetBrush ( ) const
inlineinherited

Get brush set for this layer.

Returns
brush.

Definition at line 307 of file mathplot.h.

307 { return m_brush; };
wxBrush m_brush
Definition: mathplot.h:317

◆ GetColourSquare()

wxBitmap mpLayer::GetColourSquare ( int  side = 16)
inherited

Get a small square bitmap filled with the colour of the pen used in the layer.

Useful to create legends or similar reference to the layers.

Parameters
sideside length in pixels
Returns
a wxBitmap filled with layer's colour

Definition at line 83 of file mathplot.cpp.

84 {
85  wxBitmap square( side, side, -1 );
86  wxColour filler = m_pen.GetColour();
87  wxBrush brush( filler, wxBRUSHSTYLE_SOLID );
88  wxMemoryDC dc;
89 
90  dc.SelectObject( square );
91  dc.SetBackground( brush );
92  dc.Clear();
93  dc.SelectObject( wxNullBitmap );
94  return square;
95 }
double square(double x)
wxPen m_pen
Definition: mathplot.h:316

References mpLayer::m_pen, and square().

◆ GetContinuity()

bool mpLayer::GetContinuity ( ) const
inlineinherited

Gets the 'continuity' property of the layer.

See also
SetContinuity

Definition at line 259 of file mathplot.h.

259 { return m_continuous; }
bool m_continuous
Definition: mathplot.h:319

◆ GetDrawOutsideMargins()

bool mpLayer::GetDrawOutsideMargins ( )
inlineinherited

Get Draw mode: inside or outside margins.

Returns
The draw mode

Definition at line 286 of file mathplot.h.

286 { return m_drawOutsideMargins; };
bool m_drawOutsideMargins
Definition: mathplot.h:321

◆ GetFont()

const wxFont& mpLayer::GetFont ( ) const
inlineinherited

Get font set for this layer.

Returns
Font

Definition at line 244 of file mathplot.h.

244 { return m_font; }
wxFont m_font
Definition: mathplot.h:311

◆ GetLayerType()

mpLayerType mpLayer::GetLayerType ( )
inlineinherited

Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value.

Returns
An integer indicating layer type

Definition at line 295 of file mathplot.h.

295 { return m_type; };
mpLayerType m_type
Definition: mathplot.h:322

Referenced by Plot().

◆ GetMaxX()

virtual double mpLayer::GetMaxX ( )
inlinevirtualinherited

Get inclusive right border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 181 of file mathplot.h.

181 { return 1.0; }

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

◆ GetMaxY()

virtual double mpLayer::GetMaxY ( )
inlinevirtualinherited

Get inclusive top border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 191 of file mathplot.h.

191 { return 1.0; }

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

◆ GetMinX()

virtual double mpLayer::GetMinX ( )
inlinevirtualinherited

Get inclusive left border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 176 of file mathplot.h.

176 { return -1.0; }

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

◆ GetMinY()

virtual double mpLayer::GetMinY ( )
inlinevirtualinherited

Get inclusive bottom border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 186 of file mathplot.h.

186 { return -1.0; }

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

◆ GetName()

const wxString& mpLayer::GetName ( void  ) const
inlineinherited

Get layer name.

Returns
Name

Definition at line 239 of file mathplot.h.

239 { return m_name; }
wxString m_name
Definition: mathplot.h:318

Referenced by SIM_PLOT_PANEL::GetLabelX(), SIM_PLOT_PANEL::GetLabelY1(), SIM_PLOT_PANEL::GetLabelY2(), Plot(), and mpText::Plot().

◆ GetPen()

const wxPen& mpLayer::GetPen ( ) const
inlineinherited

Get pen set for this layer.

Returns
Pen

Definition at line 249 of file mathplot.h.

249 { return m_pen; }
wxPen m_pen
Definition: mathplot.h:316

Referenced by Plot().

◆ GetPosition()

wxPoint mpInfoLayer::GetPosition ( )
inherited

Returns the position of the upper left corner of the box (in pixels)

Returns
The rectangle position

Definition at line 196 of file mathplot.cpp.

197 {
198  return m_dim.GetPosition();
199 }
wxRect m_dim
Definition: mathplot.h:393

References mpInfoLayer::m_dim.

◆ GetRectangle()

const wxRect& mpInfoLayer::GetRectangle ( )
inlineinherited

Returns the current rectangle coordinates.

Returns
The info layer rectangle

Definition at line 393 of file mathplot.h.

393 { return m_dim; };
wxRect m_dim
Definition: mathplot.h:393

Referenced by mpWindow::OnMouseMove().

◆ GetSize()

wxSize mpInfoLayer::GetSize ( )
inherited

Returns the size of the box (in pixels)

Returns
The rectangle size

Definition at line 202 of file mathplot.cpp.

203 {
204  return m_dim.GetSize();
205 }
wxRect m_dim
Definition: mathplot.h:393

References mpInfoLayer::m_dim.

◆ HasBBox()

virtual bool mpInfoLayer::HasBBox ( )
inlineoverridevirtualinherited

mpInfoLayer has not bounding box.

See also
mpLayer::HasBBox
Returns
always FALSE

Reimplemented from mpLayer.

Definition at line 358 of file mathplot.h.

358 { return false; }

◆ Inside()

bool mpInfoLayer::Inside ( wxPoint &  point)
virtualinherited

Checks whether a point is inside the info box rectangle.

Parameters
pointThe point to be checked
Returns
true if the point is inside the bounding box

Reimplemented in CURSOR.

Definition at line 135 of file mathplot.cpp.

136 {
137  return m_dim.Contains( point );
138 }
wxRect m_dim
Definition: mathplot.h:393

References mpInfoLayer::m_dim.

Referenced by mpWindow::IsInsideInfoLayer().

◆ IsInfo()

virtual bool mpInfoLayer::IsInfo ( )
inlineoverridevirtualinherited

Specifies that this is an Info box layer.

Returns
always TRUE
See also
mpLayer::IsInfo

Reimplemented from mpLayer.

Definition at line 369 of file mathplot.h.

369 { return true; }

◆ IsVisible()

bool mpLayer::IsVisible ( )
inlineinherited

Checks whether the layer is visible or not.

Returns
true if visible

Definition at line 299 of file mathplot.h.

299 { return m_visible; };
bool m_visible
Definition: mathplot.h:323

Referenced by mpWindow::IsLayerVisible(), SIM_PLOT_PANEL::IsLegendShown(), and Plot().

◆ Move()

void mpInfoLayer::Move ( wxPoint  delta)
virtualinherited

Moves the layer rectangle of given pixel deltas.

Parameters
deltaThe wxPoint container for delta coordinates along x and y. Units are in pixels.

Reimplemented in CURSOR.

Definition at line 141 of file mathplot.cpp.

142 {
143  m_dim.SetX( m_reference.x + delta.x );
144  m_dim.SetY( m_reference.y + delta.y );
145 }
wxRect m_dim
Definition: mathplot.h:393
wxPoint m_reference
Definition: mathplot.h:397

References mpInfoLayer::m_dim, and mpInfoLayer::m_reference.

Referenced by CURSOR::Move(), and mpWindow::OnMouseMove().

◆ Plot()

void mpInfoLegend::Plot ( wxDC &  dc,
mpWindow w 
)
overridevirtual

Plot method.

Parameters
dcthe device content where to plot
wthe window to plot
See also
mpLayer::Plot

Reimplemented from mpInfoLayer.

Definition at line 304 of file mathplot.cpp.

305 {
306  if( m_visible )
307  {
308  // Adjust relative position inside the window
309  int scrx = w.GetScrX();
310  int scry = w.GetScrY();
311 
312  if( (m_winX != scrx) || (m_winY != scry) )
313  {
314  if( m_winX > 1 )
315  m_dim.x = (int) floor( (double) (m_dim.x * scrx / m_winX) );
316 
317  if( m_winY > 1 )
318  {
319  m_dim.y = (int) floor( (double) (m_dim.y * scry / m_winY) );
320  UpdateReference();
321  }
322 
323  // Finally update window size
324  m_winX = scrx;
325  m_winY = scry;
326  }
327 
328  // wxImage image0(wxT("pixel.png"), wxBITMAP_TYPE_PNG);
329  // wxBitmap image1(image0);
330  // wxBrush semiWhite(image1);
331  dc.SetBrush( m_brush );
332  dc.SetFont( m_font );
333  const int baseWidth = (mpLEGEND_MARGIN * 2 + mpLEGEND_LINEWIDTH);
334  int textX = baseWidth, textY = mpLEGEND_MARGIN;
335  int plotCount = 0;
336  int posY = 0;
337  int tmpX = 0, tmpY = 0;
338  mpLayer* ly = NULL;
339  wxPen lpen;
340  wxString label;
341 
342  for( unsigned int p = 0; p < w.CountAllLayers(); p++ )
343  {
344  ly = w.GetLayer( p );
345 
346  if( (ly->GetLayerType() == mpLAYER_PLOT) && ( ly->IsVisible() ) )
347  {
348  label = ly->GetName();
349  dc.GetTextExtent( label, &tmpX, &tmpY );
350  textX =
351  ( textX > (tmpX + baseWidth) ) ? textX : (tmpX + baseWidth + mpLEGEND_MARGIN);
352  textY += (tmpY);
353  }
354  }
355 
356  dc.SetPen( m_pen );
357  dc.SetBrush( m_brush );
358  m_dim.width = textX;
359 
360  if( textY != mpLEGEND_MARGIN ) // Don't draw any thing if there are no visible layers
361  {
362  textY += mpLEGEND_MARGIN;
363  m_dim.height = textY;
364  dc.DrawRectangle( m_dim.x, m_dim.y, m_dim.width, m_dim.height );
365 
366  for( unsigned int p2 = 0; p2 < w.CountAllLayers(); p2++ )
367  {
368  ly = w.GetLayer( p2 );
369 
370  if( (ly->GetLayerType() == mpLAYER_PLOT) && ( ly->IsVisible() ) )
371  {
372  label = ly->GetName();
373  lpen = ly->GetPen();
374  dc.GetTextExtent( label, &tmpX, &tmpY );
375  dc.SetPen( lpen );
376  // textX = (textX > (tmpX + baseWidth)) ? textX : (tmpX + baseWidth);
377  // textY += (tmpY + mpLEGEND_MARGIN);
378  posY = m_dim.y + mpLEGEND_MARGIN + plotCount * tmpY + (tmpY >> 1);
379  dc.DrawLine( m_dim.x + mpLEGEND_MARGIN, // X start coord
380  posY, // Y start coord
381  m_dim.x + mpLEGEND_LINEWIDTH + mpLEGEND_MARGIN, // X end coord
382  posY );
383  // dc.DrawRectangle(m_dim.x + 5, m_dim.y + 5 + plotCount*tmpY, 5, 5);
384  dc.DrawText( label,
385  m_dim.x + baseWidth,
386  m_dim.y + mpLEGEND_MARGIN + plotCount * tmpY );
387  plotCount++;
388  }
389  }
390  }
391  }
392 }
int m_winX
Definition: mathplot.h:399
mpLayerType GetLayerType()
Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc,...
Definition: mathplot.h:295
mpLayer * GetLayer(int position)
Definition: mathplot.cpp:2949
const wxString & GetName() const
Get layer name.
Definition: mathplot.h:239
bool m_visible
Definition: mathplot.h:323
int m_winY
Definition: mathplot.h:399
#define NULL
bool IsVisible()
Checks whether the layer is visible or not.
Definition: mathplot.h:299
wxBrush m_brush
Definition: mathplot.h:398
int GetScrX(void) const
Get current view's X dimension in device context units.
Definition: mathplot.h:1135
wxFont m_font
Definition: mathplot.h:311
unsigned int CountAllLayers()
Counts the number of plot layers, whether or not they have a bounding box.
Definition: mathplot.h:1290
wxRect m_dim
Definition: mathplot.h:393
virtual void UpdateReference()
Updates the rectangle reference point.
Definition: mathplot.cpp:148
wxPen m_pen
Definition: mathplot.h:316
const wxPen & GetPen() const
Get pen set for this layer.
Definition: mathplot.h:249
#define mpLEGEND_MARGIN
Definition: mathplot.cpp:53
#define mpLEGEND_LINEWIDTH
Definition: mathplot.cpp:54
int GetScrY(void) const
Get current view's Y dimension in device context units.
Definition: mathplot.h:1144

References mpWindow::CountAllLayers(), mpWindow::GetLayer(), mpLayer::GetLayerType(), mpLayer::GetName(), mpLayer::GetPen(), mpWindow::GetScrX(), mpWindow::GetScrY(), mpLayer::IsVisible(), mpInfoLayer::m_brush, mpInfoLayer::m_dim, mpLayer::m_font, mpLayer::m_pen, mpLayer::m_visible, mpInfoLayer::m_winX, mpInfoLayer::m_winY, mpLAYER_PLOT, mpLEGEND_LINEWIDTH, mpLEGEND_MARGIN, NULL, and mpInfoLayer::UpdateReference().

◆ SetBrush()

void mpLayer::SetBrush ( wxBrush  brush)
inlineinherited

Set layer brush.

Parameters
brushbrush, will be copied to internal class member

Definition at line 311 of file mathplot.h.

311 { m_brush = brush; };
wxBrush m_brush
Definition: mathplot.h:317

◆ SetContinuity()

void mpLayer::SetContinuity ( bool  continuity)
inlineinherited

Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points).

See also
GetContinuity

Definition at line 254 of file mathplot.h.

254 { m_continuous = continuity; }
bool m_continuous
Definition: mathplot.h:319

Referenced by TRACE::TRACE().

◆ SetDrawOutsideMargins()

void mpLayer::SetDrawOutsideMargins ( bool  drawModeOutside)
inlineinherited

Set Draw mode: inside or outside margins.

Default is outside, which allows the layer to draw up to the mpWindow border.

Parameters
drawModeOutsideThe draw mode to be set

Definition at line 282 of file mathplot.h.

282 { m_drawOutsideMargins = drawModeOutside; };
bool m_drawOutsideMargins
Definition: mathplot.h:321

Referenced by CURSOR::CURSOR(), and TRACE::TRACE().

◆ SetFont()

void mpLayer::SetFont ( wxFont &  font)
inlineinherited

Set layer font.

Parameters
fontFont, will be copied to internal class member

Definition at line 273 of file mathplot.h.

273 { m_font = font; }
wxFont m_font
Definition: mathplot.h:311

◆ SetName()

void mpLayer::SetName ( wxString  name)
inlineinherited

Set layer name.

Parameters
nameName, will be copied to internal class member

Definition at line 268 of file mathplot.h.

268 { m_name = name; }
const char * name
Definition: DXF_plotter.cpp:59
wxString m_name
Definition: mathplot.h:318

References name.

◆ SetPen()

void mpLayer::SetPen ( wxPen  pen)
inlineinherited

Set layer pen.

Parameters
penPen, will be copied to internal class member

Definition at line 278 of file mathplot.h.

278 { m_pen = pen; }
wxPen m_pen
Definition: mathplot.h:316

Referenced by SIM_PLOT_PANEL::UpdateTraceStyle().

◆ SetVisible()

void mpLayer::SetVisible ( bool  show)
inlineinherited

Sets layer visibility.

Parameters
showvisibility bool.

Definition at line 303 of file mathplot.h.

303 { m_visible = show; };
bool m_visible
Definition: mathplot.h:323

Referenced by mpWindow::SetLayerVisible(), SIM_PLOT_PANEL::ShowLegend(), and SIM_PLOT_PANEL::SIM_PLOT_PANEL().

◆ ShowName()

void mpLayer::ShowName ( bool  show)
inlineinherited

Shows or hides the text label with the name of the layer (default is visible).

Definition at line 263 of file mathplot.h.

263 { m_showName = show; };
bool m_showName
Definition: mathplot.h:320

Referenced by TRACE::TRACE().

◆ UpdateInfo()

void mpInfoLegend::UpdateInfo ( mpWindow w,
wxEvent &  event 
)
overridevirtual

Updates the content of the info box.

Unused in this class.

Parameters
wparent mpWindow from which to obtain information
eventThe event which called the update.

Reimplemented from mpInfoLayer.

Definition at line 299 of file mathplot.cpp.

300 {
301 }

◆ UpdateReference()

void mpInfoLayer::UpdateReference ( )
virtualinherited

Updates the rectangle reference point.

Used by internal methods of mpWindow to correctly move mpInfoLayers.

Reimplemented in CURSOR.

Definition at line 148 of file mathplot.cpp.

149 {
150  m_reference.x = m_dim.x;
151  m_reference.y = m_dim.y;
152 }
wxRect m_dim
Definition: mathplot.h:393
wxPoint m_reference
Definition: mathplot.h:397

References mpInfoLayer::m_dim, and mpInfoLayer::m_reference.

Referenced by mpWindow::OnMouseLeftRelease(), mpInfoLayer::Plot(), mpInfoCoords::Plot(), and Plot().

Member Data Documentation

◆ m_brush

wxBrush mpInfoLayer::m_brush
protectedinherited

Definition at line 398 of file mathplot.h.

Referenced by mpInfoLayer::mpInfoLayer(), mpInfoLayer::Plot(), mpInfoCoords::Plot(), and Plot().

◆ m_continuous

bool mpLayer::m_continuous
protectedinherited

Definition at line 319 of file mathplot.h.

Referenced by CURSOR::Plot(), mpFXY::Plot(), and mpMovableObject::Plot().

◆ m_dim

◆ m_drawOutsideMargins

◆ m_font

◆ m_name

wxString mpLayer::m_name
protectedinherited

◆ m_pen

◆ m_reference

wxPoint mpInfoLayer::m_reference
protectedinherited

◆ m_showName

bool mpLayer::m_showName
protectedinherited

◆ m_type

mpLayerType mpLayer::m_type
protectedinherited

Definition at line 322 of file mathplot.h.

Referenced by mpInfoLayer::mpInfoLayer().

◆ m_visible

◆ m_winX

int mpInfoLayer::m_winX
protectedinherited

Definition at line 399 of file mathplot.h.

Referenced by mpInfoLayer::mpInfoLayer(), mpInfoLayer::Plot(), mpInfoCoords::Plot(), and Plot().

◆ m_winY

int mpInfoLayer::m_winY
protectedinherited

Definition at line 399 of file mathplot.h.

Referenced by mpInfoLayer::mpInfoLayer(), mpInfoLayer::Plot(), mpInfoCoords::Plot(), and Plot().


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