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 () const override
 mpInfoLayer has not bounding box. More...
 
virtual bool IsInfo () const 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 () const
 Returns the position of the upper left corner of the box (in pixels) More...
 
wxSize GetSize () const
 Returns the size of the box (in pixels) More...
 
const wxRect & GetRectangle () const
 Returns the current rectangle coordinates. More...
 
virtual double GetMinX () const
 Get inclusive left border of bounding box. More...
 
virtual double GetMaxX () const
 Get inclusive right border of bounding box. More...
 
virtual double GetMinY () const
 Get inclusive bottom border of bounding box. More...
 
virtual double GetMaxY () const
 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) const
 Get a small square bitmap filled with the colour of the pen used in the layer. More...
 
mpLayerType GetLayerType () const
 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 () const
 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 437 of file mathplot.h.

Constructor & Destructor Documentation

◆ mpInfoLegend() [1/2]

mpInfoLegend::mpInfoLegend ( )

Default constructor.

Definition at line 275 of file mathplot.cpp.

275  : mpInfoLayer()
276 {
277 }
mpInfoLayer()
Default constructor.
Definition: mathplot.cpp:94

◆ 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 280 of file mathplot.cpp.

280  : mpInfoLayer( rect, brush )
281 {
282 }
mpInfoLayer()
Default constructor.
Definition: mathplot.cpp:94

◆ ~mpInfoLegend()

mpInfoLegend::~mpInfoLegend ( )

Default destructor.

Definition at line 285 of file mathplot.cpp.

286 {
287 }

Member Function Documentation

◆ GetBrush()

const wxBrush& mpLayer::GetBrush ( ) const
inlineinherited

Get brush set for this layer.

Returns
brush.

Definition at line 306 of file mathplot.h.

306 { return m_brush; };
wxBrush m_brush
Definition: mathplot.h:316

◆ GetColourSquare()

wxBitmap mpLayer::GetColourSquare ( int  side = 16) const
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 74 of file mathplot.cpp.

75 {
76  wxBitmap square( side, side, -1 );
77  wxColour filler = m_pen.GetColour();
78  wxBrush brush( filler, wxBRUSHSTYLE_SOLID );
79  wxMemoryDC dc;
80 
81  dc.SelectObject( square );
82  dc.SetBackground( brush );
83  dc.Clear();
84  dc.SelectObject( wxNullBitmap );
85  return square;
86 }
wxPen m_pen
Definition: mathplot.h:315
double square(double x)

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 258 of file mathplot.h.

258 { return m_continuous; }
bool m_continuous
Definition: mathplot.h:318

◆ GetDrawOutsideMargins()

bool mpLayer::GetDrawOutsideMargins ( )
inlineinherited

Get Draw mode: inside or outside margins.

Returns
The draw mode

Definition at line 285 of file mathplot.h.

285 { return m_drawOutsideMargins; };
bool m_drawOutsideMargins
Definition: mathplot.h:320

◆ GetFont()

const wxFont& mpLayer::GetFont ( ) const
inlineinherited

Get font set for this layer.

Returns
Font

Definition at line 243 of file mathplot.h.

243 { return m_font; }
wxFont m_font
Definition: mathplot.h:310

◆ GetLayerType()

mpLayerType mpLayer::GetLayerType ( ) const
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 294 of file mathplot.h.

294 { return m_type; };
mpLayerType m_type
Definition: mathplot.h:321

Referenced by Plot().

◆ GetMaxX()

virtual double mpLayer::GetMaxX ( ) const
inlinevirtualinherited

Get inclusive right border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 180 of file mathplot.h.

180 { return 1.0; }

Referenced by mpFXY::UpdateScales().

◆ GetMaxY()

virtual double mpLayer::GetMaxY ( ) const
inlinevirtualinherited

Get inclusive top border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 190 of file mathplot.h.

190 { return 1.0; }

Referenced by mpFXY::UpdateScales().

◆ GetMinX()

virtual double mpLayer::GetMinX ( ) const
inlinevirtualinherited

Get inclusive left border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 175 of file mathplot.h.

175 { return -1.0; }

Referenced by mpFXY::UpdateScales().

◆ GetMinY()

virtual double mpLayer::GetMinY ( ) const
inlinevirtualinherited

Get inclusive bottom border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 185 of file mathplot.h.

185 { return -1.0; }

Referenced by mpFXY::UpdateScales().

◆ GetName()

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

Get layer name.

Returns
Name

Definition at line 238 of file mathplot.h.

238 { return m_name; }
wxString m_name
Definition: mathplot.h:317

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 248 of file mathplot.h.

248 { return m_pen; }
wxPen m_pen
Definition: mathplot.h:315

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

◆ GetPosition()

wxPoint mpInfoLayer::GetPosition ( ) const
inherited

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

Returns
The rectangle position

Definition at line 187 of file mathplot.cpp.

188 {
189  return m_dim.GetPosition();
190 }
wxRect m_dim
Definition: mathplot.h:392

References mpInfoLayer::m_dim.

◆ GetRectangle()

const wxRect& mpInfoLayer::GetRectangle ( ) const
inlineinherited

Returns the current rectangle coordinates.

Returns
The info layer rectangle

Definition at line 392 of file mathplot.h.

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

Referenced by mpWindow::OnMouseMove().

◆ GetSize()

wxSize mpInfoLayer::GetSize ( ) const
inherited

Returns the size of the box (in pixels)

Returns
The rectangle size

Definition at line 193 of file mathplot.cpp.

194 {
195  return m_dim.GetSize();
196 }
wxRect m_dim
Definition: mathplot.h:392

References mpInfoLayer::m_dim.

◆ HasBBox()

virtual bool mpInfoLayer::HasBBox ( ) const
inlineoverridevirtualinherited

mpInfoLayer has not bounding box.

See also
mpLayer::HasBBox
Returns
always false

Reimplemented from mpLayer.

Definition at line 357 of file mathplot.h.

357 { 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 126 of file mathplot.cpp.

127 {
128  return m_dim.Contains( point );
129 }
wxRect m_dim
Definition: mathplot.h:392

References mpInfoLayer::m_dim.

Referenced by mpWindow::IsInsideInfoLayer().

◆ IsInfo()

virtual bool mpInfoLayer::IsInfo ( ) const
inlineoverridevirtualinherited

Specifies that this is an Info box layer.

Returns
always true
See also
mpLayer::IsInfo

Reimplemented from mpLayer.

Definition at line 368 of file mathplot.h.

368 { return true; }

◆ IsVisible()

bool mpLayer::IsVisible ( ) const
inlineinherited

Checks whether the layer is visible or not.

Returns
true if visible

Definition at line 298 of file mathplot.h.

298 { return m_visible; };
bool m_visible
Definition: mathplot.h:322

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 132 of file mathplot.cpp.

133 {
134  m_dim.SetX( m_reference.x + delta.x );
135  m_dim.SetY( m_reference.y + delta.y );
136 }
wxRect m_dim
Definition: mathplot.h:392
wxPoint m_reference
Definition: mathplot.h:396
constexpr int delta

References delta, 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 295 of file mathplot.cpp.

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

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, 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 310 of file mathplot.h.

310 { m_brush = brush; };
wxBrush m_brush
Definition: mathplot.h:316

◆ 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 253 of file mathplot.h.

253 { m_continuous = continuity; }
bool m_continuous
Definition: mathplot.h:318

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 281 of file mathplot.h.

281 { m_drawOutsideMargins = drawModeOutside; };
bool m_drawOutsideMargins
Definition: mathplot.h:320

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 272 of file mathplot.h.

272 { m_font = font; }
wxFont m_font
Definition: mathplot.h:310

◆ SetName()

void mpLayer::SetName ( wxString  name)
inlineinherited

Set layer name.

Parameters
nameName, will be copied to internal class member

Definition at line 267 of file mathplot.h.

267 { m_name = name; }
const char * name
Definition: DXF_plotter.cpp:56
wxString m_name
Definition: mathplot.h:317

References name.

◆ SetPen()

void mpLayer::SetPen ( wxPen  pen)
inlineinherited

Set layer pen.

Parameters
penPen, will be copied to internal class member

Definition at line 277 of file mathplot.h.

277 { m_pen = pen; }
wxPen m_pen
Definition: mathplot.h:315

Referenced by SIM_PLOT_PANEL::EnableCursor(), and SIM_PLOT_PANEL::UpdateTraceStyle().

◆ SetVisible()

void mpLayer::SetVisible ( bool  show)
inlineinherited

Sets layer visibility.

Parameters
showvisibility bool.

Definition at line 302 of file mathplot.h.

302 { m_visible = show; };
bool m_visible
Definition: mathplot.h:322

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 262 of file mathplot.h.

262 { m_showName = show; };
bool m_showName
Definition: mathplot.h:319

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 290 of file mathplot.cpp.

291 {
292 }

◆ 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 139 of file mathplot.cpp.

140 {
141  m_reference.x = m_dim.x;
142  m_reference.y = m_dim.y;
143 }
wxRect m_dim
Definition: mathplot.h:392
wxPoint m_reference
Definition: mathplot.h:396

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 397 of file mathplot.h.

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

◆ m_continuous

bool mpLayer::m_continuous
protectedinherited

Definition at line 318 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 321 of file mathplot.h.

Referenced by mpInfoLayer::mpInfoLayer().

◆ m_visible

◆ m_winX

int mpInfoLayer::m_winX
protectedinherited

Definition at line 398 of file mathplot.h.

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

◆ m_winY

int mpInfoLayer::m_winY
protectedinherited

Definition at line 398 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: