KiCad PCB EDA Suite
mpInfoLayer Class Reference

Base class to create small rectangular info boxes mpInfoLayer is the base class to create a small rectangular info box in transparent overlay over plot layers. More...

#include <mathplot.h>

Inheritance diagram for mpInfoLayer:
mpLayer CURSOR mpInfoCoords mpInfoLegend

Public Member Functions

 mpInfoLayer ()
 Default constructor. More...
 
 mpInfoLayer (wxRect rect, const wxBrush *brush=wxTRANSPARENT_BRUSH)
 Complete constructor. More...
 
virtual ~mpInfoLayer ()
 Destructor. More...
 
virtual void UpdateInfo (mpWindow &w, wxEvent &event)
 Updates the content of the info box. More...
 
virtual bool HasBBox () override
 mpInfoLayer has not bounding box. More...
 
virtual void Plot (wxDC &dc, mpWindow &w) override
 Plot method. 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

Base class to create small rectangular info boxes mpInfoLayer is the base class to create a small rectangular info box in transparent overlay over plot layers.

It is used to implement objects like legends.

Definition at line 334 of file mathplot.h.

Constructor & Destructor Documentation

mpInfoLayer::mpInfoLayer ( )

Default constructor.

Definition at line 102 of file mathplot.cpp.

References mpLAYER_INFO.

103 {
104  m_dim = wxRect( 0, 0, 1, 1 );
105  m_brush = *wxTRANSPARENT_BRUSH;
106  m_reference.x = 0; m_reference.y = 0;
107  m_winX = 1; // parent->GetScrX();
108  m_winY = 1; // parent->GetScrY();
110 }
int m_winX
Definition: mathplot.h:397
int m_winY
Definition: mathplot.h:397
wxBrush m_brush
Definition: mathplot.h:396
wxRect m_dim
Definition: mathplot.h:391
wxPoint m_reference
Definition: mathplot.h:395
mpLayerType m_type
Definition: mathplot.h:320
mpInfoLayer::mpInfoLayer ( wxRect  rect,
const wxBrush *  brush = wxTRANSPARENT_BRUSH 
)

Complete constructor.

Parameters
rectSets the initial size rectangle of the layer.
brushpointer to a fill brush. Default is transparent

Definition at line 113 of file mathplot.cpp.

References m_brush, m_reference, mpLayer::m_type, m_winX, m_winY, mpLAYER_INFO, wxPoint::x, and wxPoint::y.

113  : m_dim( rect )
114 {
115  m_brush = *brush;
116  m_reference.x = rect.x;
117  m_reference.y = rect.y;
118  m_winX = 1; // parent->GetScrX();
119  m_winY = 1; // parent->GetScrY();
121 }
int m_winX
Definition: mathplot.h:397
int m_winY
Definition: mathplot.h:397
wxBrush m_brush
Definition: mathplot.h:396
wxRect m_dim
Definition: mathplot.h:391
wxPoint m_reference
Definition: mathplot.h:395
mpLayerType m_type
Definition: mathplot.h:320
mpInfoLayer::~mpInfoLayer ( )
virtual

Destructor.

Definition at line 124 of file mathplot.cpp.

125 {
126 }

Member Function Documentation

const wxBrush& mpLayer::GetBrush ( ) const
inlineinherited

Get brush set for this layer.

Returns
brush.

Definition at line 305 of file mathplot.h.

305 { return m_brush; };
wxBrush m_brush
Definition: mathplot.h:315
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 82 of file mathplot.cpp.

References mpLayer::m_pen, and square().

83 {
84  wxBitmap square( side, side, -1 );
85  wxColour filler = m_pen.GetColour();
86  wxBrush brush( filler, wxBRUSHSTYLE_SOLID );
87  wxMemoryDC dc;
88 
89  dc.SelectObject( square );
90  dc.SetBackground( brush );
91  dc.Clear();
92  dc.SelectObject( wxNullBitmap );
93  return square;
94 }
static double square(int x)
Definition: trigo.cpp:138
wxPen m_pen
Definition: mathplot.h:314
bool mpLayer::GetContinuity ( ) const
inlineinherited

Gets the 'continuity' property of the layer.

See also
SetContinuity

Definition at line 257 of file mathplot.h.

257 { return m_continuous; }
bool m_continuous
Definition: mathplot.h:317
bool mpLayer::GetDrawOutsideMargins ( )
inlineinherited

Get Draw mode: inside or outside margins.

Returns
The draw mode

Definition at line 284 of file mathplot.h.

284 { return m_drawOutsideMargins; };
bool m_drawOutsideMargins
Definition: mathplot.h:319
const wxFont& mpLayer::GetFont ( ) const
inlineinherited

Get font set for this layer.

Returns
Font

Definition at line 242 of file mathplot.h.

242 { return m_font; }
wxFont m_font
Definition: mathplot.h:309
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 293 of file mathplot.h.

Referenced by mpInfoLegend::Plot().

293 { return m_type; };
mpLayerType m_type
Definition: mathplot.h:320
virtual double mpLayer::GetMaxX ( )
inlinevirtualinherited

Get inclusive right border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 179 of file mathplot.h.

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

179 { return 1.0; }
virtual double mpLayer::GetMaxY ( )
inlinevirtualinherited

Get inclusive top border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 189 of file mathplot.h.

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

189 { return 1.0; }
virtual double mpLayer::GetMinX ( )
inlinevirtualinherited

Get inclusive left border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 174 of file mathplot.h.

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

174 { return -1.0; }
virtual double mpLayer::GetMinY ( )
inlinevirtualinherited

Get inclusive bottom border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 184 of file mathplot.h.

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

184 { return -1.0; }
const wxString& mpLayer::GetName ( void  ) const
inlineinherited

Get layer name.

Returns
Name

Definition at line 237 of file mathplot.h.

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

237 { return m_name; }
wxString m_name
Definition: mathplot.h:316
const wxPen& mpLayer::GetPen ( ) const
inlineinherited

Get pen set for this layer.

Returns
Pen

Definition at line 247 of file mathplot.h.

Referenced by mpInfoLegend::Plot().

247 { return m_pen; }
wxPen m_pen
Definition: mathplot.h:314
wxPoint mpInfoLayer::GetPosition ( )

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

Returns
The rectangle position

Definition at line 199 of file mathplot.cpp.

References m_dim.

200 {
201  return m_dim.GetPosition();
202 }
wxRect m_dim
Definition: mathplot.h:391
const wxRect& mpInfoLayer::GetRectangle ( )
inline

Returns the current rectangle coordinates.

Returns
The info layer rectangle

Definition at line 391 of file mathplot.h.

Referenced by mpWindow::OnMouseMove().

391 { return m_dim; };
wxRect m_dim
Definition: mathplot.h:391
wxSize mpInfoLayer::GetSize ( )

Returns the size of the box (in pixels)

Returns
The rectangle size

Definition at line 205 of file mathplot.cpp.

References m_dim.

206 {
207  return m_dim.GetSize();
208 }
wxRect m_dim
Definition: mathplot.h:391
virtual bool mpInfoLayer::HasBBox ( )
inlineoverridevirtual

mpInfoLayer has not bounding box.

See also
mpLayer::HasBBox
Returns
always FALSE

Reimplemented from mpLayer.

Definition at line 356 of file mathplot.h.

356 { return false; }
bool mpInfoLayer::Inside ( wxPoint point)
virtual

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

References m_dim.

Referenced by mpWindow::IsInsideInfoLayer().

135 {
136  return m_dim.Contains( point );
137 }
wxRect m_dim
Definition: mathplot.h:391
virtual bool mpInfoLayer::IsInfo ( )
inlineoverridevirtual

Specifies that this is an Info box layer.

Returns
always TRUE
See also
mpLayer::IsInfo

Reimplemented from mpLayer.

Definition at line 367 of file mathplot.h.

367 { return true; }
bool mpLayer::IsVisible ( )
inlineinherited

Checks whether the layer is visible or not.

Returns
true if visible

Definition at line 297 of file mathplot.h.

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

297 { return m_visible; };
bool m_visible
Definition: mathplot.h:321
void mpInfoLayer::Move ( wxPoint  delta)
virtual

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

References m_dim, m_reference, wxPoint::x, and wxPoint::y.

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

141 {
142  m_dim.SetX( m_reference.x + delta.x );
143  m_dim.SetY( m_reference.y + delta.y );
144 }
wxRect m_dim
Definition: mathplot.h:391
wxPoint m_reference
Definition: mathplot.h:395
void mpInfoLayer::Plot ( wxDC &  dc,
mpWindow w 
)
overridevirtual

Plot method.

Can be overidden by derived classes.

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

Implements mpLayer.

Reimplemented in mpInfoLegend, mpInfoCoords, and CURSOR.

Definition at line 154 of file mathplot.cpp.

References mpWindow::GetScrX(), mpWindow::GetScrY(), m_brush, m_dim, mpLayer::m_pen, mpLayer::m_visible, m_winX, m_winY, and UpdateReference().

155 {
156  if( m_visible )
157  {
158  // Adjust relative position inside the window
159  int scrx = w.GetScrX();
160  int scry = w.GetScrY();
161 
162  // Avoid dividing by 0
163  if( scrx == 0 )
164  scrx = 1;
165 
166  if( scry == 0 )
167  scry = 1;
168 
169  if( (m_winX != scrx) || (m_winY != scry) )
170  {
171 #ifdef MATHPLOT_DO_LOGGING
172  // wxLogMessage( "mpInfoLayer::Plot() screen size has changed from %d x %d to %d x %d", m_winX, m_winY, scrx, scry);
173 #endif
174 
175  if( m_winX > 1 )
176  m_dim.x = (int) floor( (double) (m_dim.x * scrx / m_winX) );
177 
178  if( m_winY > 1 )
179  {
180  m_dim.y = (int) floor( (double) (m_dim.y * scry / m_winY) );
181  UpdateReference();
182  }
183 
184  // Finally update window size
185  m_winX = scrx;
186  m_winY = scry;
187  }
188 
189  dc.SetPen( m_pen );
190  // wxImage image0(wxT("pixel.png"), wxBITMAP_TYPE_PNG);
191  // wxBitmap image1(image0);
192  // wxBrush semiWhite(image1);
193  dc.SetBrush( m_brush );
194  dc.DrawRectangle( m_dim.x, m_dim.y, m_dim.width, m_dim.height );
195  }
196 }
int m_winX
Definition: mathplot.h:397
int GetScrY(void) const
Get current view's Y dimension in device context units.
Definition: mathplot.h:1136
bool m_visible
Definition: mathplot.h:321
int m_winY
Definition: mathplot.h:397
wxBrush m_brush
Definition: mathplot.h:396
int GetScrX(void) const
Get current view's X dimension in device context units.
Definition: mathplot.h:1127
wxRect m_dim
Definition: mathplot.h:391
virtual void UpdateReference()
Updates the rectangle reference point.
Definition: mathplot.cpp:147
wxPen m_pen
Definition: mathplot.h:314
void mpLayer::SetBrush ( wxBrush  brush)
inlineinherited

Set layer brush.

Parameters
brushbrush, will be copied to internal class member

Definition at line 309 of file mathplot.h.

309 { m_brush = brush; };
wxBrush m_brush
Definition: mathplot.h:315
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 252 of file mathplot.h.

Referenced by TRACE::TRACE().

252 { m_continuous = continuity; }
bool m_continuous
Definition: mathplot.h:317
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 280 of file mathplot.h.

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

280 { m_drawOutsideMargins = drawModeOutside; };
bool m_drawOutsideMargins
Definition: mathplot.h:319
void mpLayer::SetFont ( wxFont &  font)
inlineinherited

Set layer font.

Parameters
fontFont, will be copied to internal class member

Definition at line 271 of file mathplot.h.

271 { m_font = font; }
wxFont m_font
Definition: mathplot.h:309
void mpLayer::SetName ( wxString  name)
inlineinherited

Set layer name.

Parameters
nameName, will be copied to internal class member

Definition at line 266 of file mathplot.h.

References name.

266 { m_name = name; }
const char * name
wxString m_name
Definition: mathplot.h:316
void mpLayer::SetPen ( wxPen  pen)
inlineinherited

Set layer pen.

Parameters
penPen, will be copied to internal class member

Definition at line 276 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::AddTrace().

276 { m_pen = pen; }
wxPen m_pen
Definition: mathplot.h:314
void mpLayer::SetVisible ( bool  show)
inlineinherited

Sets layer visibility.

Parameters
showvisibility bool.

Definition at line 301 of file mathplot.h.

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

301 { m_visible = show; };
bool m_visible
Definition: mathplot.h:321
void mpLayer::ShowName ( bool  show)
inlineinherited

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

Definition at line 261 of file mathplot.h.

Referenced by TRACE::TRACE().

261 { m_showName = show; };
bool m_showName
Definition: mathplot.h:318
void mpInfoLayer::UpdateInfo ( mpWindow w,
wxEvent &  event 
)
virtual

Updates the content of the info box.

Should be overidden by derived classes. Update may behave in different ways according to the type of event which called it.

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

Reimplemented in mpInfoLegend, and mpInfoCoords.

Definition at line 129 of file mathplot.cpp.

Referenced by mpWindow::OnMouseMove().

130 {
131 }
void mpInfoLayer::UpdateReference ( )
virtual

Updates the rectangle reference point.

Used by internal methods of mpWindow to correctly move mpInfoLayers.

Reimplemented in CURSOR.

Definition at line 147 of file mathplot.cpp.

References m_dim, m_reference, wxPoint::x, and wxPoint::y.

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

148 {
149  m_reference.x = m_dim.x;
150  m_reference.y = m_dim.y;
151 }
wxRect m_dim
Definition: mathplot.h:391
wxPoint m_reference
Definition: mathplot.h:395

Member Data Documentation

wxBrush mpInfoLayer::m_brush
protected

Definition at line 396 of file mathplot.h.

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

bool mpLayer::m_continuous
protectedinherited

Definition at line 317 of file mathplot.h.

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

wxRect mpInfoLayer::m_dim
protected
wxString mpLayer::m_name
protectedinherited
wxPoint mpInfoLayer::m_reference
protected

Definition at line 395 of file mathplot.h.

Referenced by Move(), mpInfoLayer(), CURSOR::SetX(), CURSOR::UpdateReference(), and UpdateReference().

bool mpLayer::m_showName
protectedinherited
mpLayerType mpLayer::m_type
protectedinherited

Definition at line 320 of file mathplot.h.

Referenced by mpInfoLayer().

int mpInfoLayer::m_winX
protected

Definition at line 397 of file mathplot.h.

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

int mpInfoLayer::m_winY
protected

Definition at line 397 of file mathplot.h.

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


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