INET Framework for OMNeT++/OMNEST
ProgressMeterFigure Class Reference

#include <ProgressMeterFigure.h>

Inheritance diagram for ProgressMeterFigure:
inet::IIndicatorFigure

Public Member Functions

 ProgressMeterFigure (const char *name=nullptr)
 
virtual ~ProgressMeterFigure ()
 
virtual void setValue (int series, simtime_t timestamp, double value) override
 
const ColorgetBackgroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetStripColor () const
 
void setStripColor (const Color &color)
 
double getCornerRadius () const
 
void setCornerRadius (double radius)
 
double getBorderWidth () const
 
void setBorderWidth (double width)
 
const char * getText () const
 
void setText (const char *text)
 
const Font & getTextFont () const
 
void setTextFont (const Font &font)
 
const ColorgetTextColor () const
 
void setTextColor (const Color &color)
 
const char * getLabel () const
 
void setLabel (const char *text)
 
const int getLabelOffset () const
 
void setLabelOffset (int)
 
const Font & getLabelFont () const
 
void setLabelFont (const Font &font)
 
const ColorgetLabelColor () const
 
void setLabelColor (const Color &color)
 
const Rectangle & getBounds () const
 
void setBounds (const Rectangle &bounds)
 
double getMinValue () const
 
void setMinValue (double value)
 
double getMaxValue () const
 
void setMaxValue (double value)
 
- Public Member Functions inherited from inet::IIndicatorFigure
virtual ~IIndicatorFigure ()
 
virtual int getNumSeries () const
 
virtual void refreshDisplay ()
 

Protected Member Functions

virtual void parse (cProperty *property) override
 
virtual const char ** getAllowedPropertyKeys () const override
 
void addChildren ()
 
void refresh ()
 
void layout ()
 

Private Attributes

cRectangleFigure * borderFigure
 
cRectangleFigure * stripFigure
 
cRectangleFigure * backgroundFigure
 
cTextFigure * valueFigure
 
cTextFigure * labelFigure
 
double min = 0
 
double max = 100
 
double value = NaN
 
int labelOffset = 10
 
std::string textFormat = "%g"
 

Constructor & Destructor Documentation

ProgressMeterFigure::ProgressMeterFigure ( const char *  name = nullptr)
46  : cGroupFigure(name)
47 {
48  addChildren();
49 }
void addChildren()
Definition: ProgressMeterFigure.cc:266
virtual ProgressMeterFigure::~ProgressMeterFigure ( )
inlinevirtual
51 {};

Member Function Documentation

void ProgressMeterFigure::addChildren ( )
protected

Referenced by ProgressMeterFigure().

267 {
268  borderFigure = new cRectangleFigure("border");
269  stripFigure = new cRectangleFigure("strip");
270  backgroundFigure = new cRectangleFigure("background");
271  valueFigure = new cTextFigure("value");
272  labelFigure = new cTextFigure("label");
273 
274  backgroundFigure->setOutlined(false);
275  backgroundFigure->setFilled(true);
276  backgroundFigure->setFillColor(Color("#b8afa6"));
277 
278  stripFigure->setOutlined(false);
279  stripFigure->setFilled(true);
280  stripFigure->setFillColor(Color("lightblue"));
281 
282  borderFigure->setOutlined(true);
283  borderFigure->setFilled(false);
284  borderFigure->setLineWidth(2);
285 
286  valueFigure->setAnchor(ANCHOR_CENTER);
287  labelFigure->setAnchor(ANCHOR_N);
288 
289  addFigure(backgroundFigure);
290  addFigure(stripFigure);
291  addFigure(borderFigure);
292  addFigure(valueFigure);
293  addFigure(labelFigure);
294 }
cRectangleFigure * stripFigure
Definition: ProgressMeterFigure.h:31
cRectangleFigure * backgroundFigure
Definition: ProgressMeterFigure.h:32
cRectangleFigure * borderFigure
Definition: ProgressMeterFigure.h:30
Color
Definition: DiffservUtil.h:30
cTextFigure * labelFigure
Definition: ProgressMeterFigure.h:34
cTextFigure * valueFigure
Definition: ProgressMeterFigure.h:33
const char ** ProgressMeterFigure::getAllowedPropertyKeys ( ) const
overrideprotectedvirtual
241 {
242  static const char *keys[32];
243  if (!keys[0]) {
244  const char *localKeys[] = {
245  PKEY_BACKGROUND_COLOR, PKEY_STRIP_COLOR, PKEY_CORNER_RADIUS, PKEY_BORDER_WIDTH,
246  PKEY_MIN_VALUE, PKEY_MAX_VALUE, PKEY_TEXT, PKEY_TEXT_FONT, PKEY_TEXT_COLOR, PKEY_LABEL,
247  PKEY_LABELOFFSET, PKEY_LABEL_FONT, PKEY_LABEL_COLOR, PKEY_INITIAL_VALUE, PKEY_POS,
248  PKEY_SIZE, PKEY_ANCHOR,
249  PKEY_BOUNDS, nullptr
250  };
251  concatArrays(keys, cGroupFigure::getAllowedPropertyKeys(), localKeys);
252  }
253  return keys;
254 }
std::vector< K > keys(const std::map< K, V > &m)
Definition: stlutils.h:96
const cFigure::Color & ProgressMeterFigure::getBackgroundColor ( ) const
52 {
53  return backgroundFigure->getFillColor();
54 }
cRectangleFigure * backgroundFigure
Definition: ProgressMeterFigure.h:32
double ProgressMeterFigure::getBorderWidth ( ) const
84 {
85  return borderFigure->getLineWidth();
86 }
cRectangleFigure * borderFigure
Definition: ProgressMeterFigure.h:30
const cFigure::Rectangle & ProgressMeterFigure::getBounds ( ) const

Referenced by parse(), and setLabelOffset().

169 {
170  return borderFigure->getBounds();
171 }
cRectangleFigure * borderFigure
Definition: ProgressMeterFigure.h:30
double ProgressMeterFigure::getCornerRadius ( ) const
72 {
73  return backgroundFigure->getCornerRx();
74 }
cRectangleFigure * backgroundFigure
Definition: ProgressMeterFigure.h:32
const char * ProgressMeterFigure::getLabel ( ) const
125 {
126  return labelFigure->getText();
127 }
cTextFigure * labelFigure
Definition: ProgressMeterFigure.h:34
const cFigure::Color & ProgressMeterFigure::getLabelColor ( ) const
159 {
160  return labelFigure->getColor();
161 }
cTextFigure * labelFigure
Definition: ProgressMeterFigure.h:34
const cFigure::Font & ProgressMeterFigure::getLabelFont ( ) const
149 {
150  return labelFigure->getFont();
151 }
cTextFigure * labelFigure
Definition: ProgressMeterFigure.h:34
const int ProgressMeterFigure::getLabelOffset ( ) const
135 {
136  return labelOffset;
137 }
int labelOffset
Definition: ProgressMeterFigure.h:39
double ProgressMeterFigure::getMaxValue ( ) const
192 {
193  return max;
194 }
double max
Definition: ProgressMeterFigure.h:37
double ProgressMeterFigure::getMinValue ( ) const
181 {
182  return min;
183 }
double min
Definition: ProgressMeterFigure.h:36
const cFigure::Color & ProgressMeterFigure::getStripColor ( ) const
62 {
63  return stripFigure->getFillColor();
64 }
cRectangleFigure * stripFigure
Definition: ProgressMeterFigure.h:31
const char * ProgressMeterFigure::getText ( ) const

Referenced by refresh().

94 {
95  return textFormat.c_str();
96 }
std::string textFormat
Definition: ProgressMeterFigure.h:40
const cFigure::Color & ProgressMeterFigure::getTextColor ( ) const
115 {
116  return valueFigure->getColor();
117 }
cTextFigure * valueFigure
Definition: ProgressMeterFigure.h:33
const cFigure::Font & ProgressMeterFigure::getTextFont ( ) const
105 {
106  return valueFigure->getFont();
107 }
cTextFigure * valueFigure
Definition: ProgressMeterFigure.h:33
void ProgressMeterFigure::layout ( )
protected

Referenced by setBounds().

257 {
258  Rectangle bounds = borderFigure->getBounds();
259  stripFigure->setBounds(bounds);
260  backgroundFigure->setBounds(bounds);
261 
262  valueFigure->setPosition(Point(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2));
263  labelFigure->setPosition(Point(bounds.x + bounds.width / 2, bounds.y + bounds.height + labelOffset));
264 }
cRectangleFigure * stripFigure
Definition: ProgressMeterFigure.h:31
cRectangleFigure * backgroundFigure
Definition: ProgressMeterFigure.h:32
cRectangleFigure * borderFigure
Definition: ProgressMeterFigure.h:30
cTextFigure * labelFigure
Definition: ProgressMeterFigure.h:34
int labelOffset
Definition: ProgressMeterFigure.h:39
cTextFigure * valueFigure
Definition: ProgressMeterFigure.h:33
void ProgressMeterFigure::parse ( cProperty *  property)
overrideprotectedvirtual
203 {
204  cGroupFigure::parse(property);
205 
206 
207  setBounds(parseBounds(property, getBounds()));
208 
209  const char *s;
210  if ((s = property->getValue(PKEY_BACKGROUND_COLOR)) != nullptr)
211  setBackgroundColor(parseColor(s));
212  if ((s = property->getValue(PKEY_STRIP_COLOR)) != nullptr)
213  setStripColor(parseColor(s));
214  if ((s = property->getValue(PKEY_CORNER_RADIUS)) != nullptr)
216  if ((s = property->getValue(PKEY_BORDER_WIDTH)) != nullptr)
218  if ((s = property->getValue(PKEY_MIN_VALUE)) != nullptr)
220  if ((s = property->getValue(PKEY_MAX_VALUE)) != nullptr)
222  if ((s = property->getValue(PKEY_TEXT)) != nullptr)
223  setText(s);
224  if ((s = property->getValue(PKEY_TEXT_FONT)) != nullptr)
225  setTextFont(parseFont(s));
226  if ((s = property->getValue(PKEY_TEXT_COLOR)) != nullptr)
227  setTextColor(parseColor(s));
228  if ((s = property->getValue(PKEY_LABEL)) != nullptr)
229  setLabel(s);
230  if ((s = property->getValue(PKEY_LABELOFFSET)) != nullptr)
231  setLabelOffset(atoi(s));
232  if ((s = property->getValue(PKEY_LABEL_FONT)) != nullptr)
233  setLabelFont(parseFont(s));
234  if ((s = property->getValue(PKEY_LABEL_COLOR)) != nullptr)
235  setLabelColor(parseColor(s));
236  if ((s = property->getValue(PKEY_INITIAL_VALUE)) != nullptr)
237  setValue(0, simTime(), utils::atod(s));
238 }
void setText(const char *text)
Definition: ProgressMeterFigure.cc:98
void setTextColor(const Color &color)
Definition: ProgressMeterFigure.cc:119
const Rectangle & getBounds() const
Definition: ProgressMeterFigure.cc:168
double atod(const char *s)
Converts string to double.
Definition: INETUtils.cc:38
void setBackgroundColor(const Color &color)
Definition: ProgressMeterFigure.cc:56
void setBorderWidth(double width)
Definition: ProgressMeterFigure.cc:88
void setLabelFont(const Font &font)
Definition: ProgressMeterFigure.cc:153
void setTextFont(const Font &font)
Definition: ProgressMeterFigure.cc:109
void setBounds(const Rectangle &bounds)
Definition: ProgressMeterFigure.cc:173
void setCornerRadius(double radius)
Definition: ProgressMeterFigure.cc:76
void setLabelOffset(int)
Definition: ProgressMeterFigure.cc:139
void setMinValue(double value)
Definition: ProgressMeterFigure.cc:185
void setLabelColor(const Color &color)
Definition: ProgressMeterFigure.cc:163
void setLabel(const char *text)
Definition: ProgressMeterFigure.cc:129
value< double, units::s > s
Definition: Units.h:1049
void setMaxValue(double value)
Definition: ProgressMeterFigure.cc:196
virtual void setValue(int series, simtime_t timestamp, double value) override
Definition: ProgressMeterFigure.cc:296
void setStripColor(const Color &color)
Definition: ProgressMeterFigure.cc:66
void ProgressMeterFigure::refresh ( )
protected

Referenced by setBounds(), setMaxValue(), setMinValue(), setText(), and setValue().

307 {
308  // adjust strip
309  double stripValue = std::isnan(value) ? min : std::max(min, std::min(max, value));
310  cFigure::Rectangle bounds = borderFigure->getBounds();
311  bounds.width = bounds.width * (stripValue - min) / (max - min);
312  stripFigure->setBounds(bounds);
313 
314  // update displayed number
315  if (std::isnan(value))
316  valueFigure->setText("");
317  else {
318  char buf[32];
319  double percent = (value - min) / (max - min) * 100;
320  sprintf(buf, getText(), value, percent);
321  if (value < min || value > max)
322  strcat(buf, "*");
323  valueFigure->setText(buf);
324  }
325 }
double min
Definition: ProgressMeterFigure.h:36
cRectangleFigure * stripFigure
Definition: ProgressMeterFigure.h:31
double value
Definition: ProgressMeterFigure.h:38
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SCTPAssociation.h:270
const char * getText() const
Definition: ProgressMeterFigure.cc:93
double max(double a, double b)
Returns the greater of the given parameters.
Definition: INETMath.h:161
cRectangleFigure * borderFigure
Definition: ProgressMeterFigure.h:30
Definition: Units.h:69
double max
Definition: ProgressMeterFigure.h:37
cTextFigure * valueFigure
Definition: ProgressMeterFigure.h:33
void ProgressMeterFigure::setBackgroundColor ( const Color color)

Referenced by parse().

57 {
58  backgroundFigure->setFillColor(color);
59 }
cRectangleFigure * backgroundFigure
Definition: ProgressMeterFigure.h:32
void ProgressMeterFigure::setBorderWidth ( double  width)

Referenced by parse().

89 {
90  borderFigure->setLineWidth(width);
91 }
cRectangleFigure * borderFigure
Definition: ProgressMeterFigure.h:30
void ProgressMeterFigure::setBounds ( const Rectangle &  bounds)

Referenced by parse().

174 {
175  borderFigure->setBounds(bounds);
176  layout();
177  refresh();
178 }
cRectangleFigure * borderFigure
Definition: ProgressMeterFigure.h:30
void refresh()
Definition: ProgressMeterFigure.cc:306
void layout()
Definition: ProgressMeterFigure.cc:256
void ProgressMeterFigure::setCornerRadius ( double  radius)

Referenced by parse().

77 {
78  backgroundFigure->setCornerRadius(radius);
79  stripFigure->setCornerRadius(radius);
80  borderFigure->setCornerRadius(radius);
81 }
cRectangleFigure * stripFigure
Definition: ProgressMeterFigure.h:31
cRectangleFigure * backgroundFigure
Definition: ProgressMeterFigure.h:32
cRectangleFigure * borderFigure
Definition: ProgressMeterFigure.h:30
void ProgressMeterFigure::setLabel ( const char *  text)

Referenced by parse().

130 {
131  labelFigure->setText(text);
132 }
cTextFigure * labelFigure
Definition: ProgressMeterFigure.h:34
void ProgressMeterFigure::setLabelColor ( const Color color)

Referenced by parse().

164 {
165  labelFigure->setColor(color);
166 }
cTextFigure * labelFigure
Definition: ProgressMeterFigure.h:34
void ProgressMeterFigure::setLabelFont ( const Font &  font)

Referenced by parse().

154 {
155  labelFigure->setFont(font);
156 }
cTextFigure * labelFigure
Definition: ProgressMeterFigure.h:34
void ProgressMeterFigure::setLabelOffset ( int  offset)

Referenced by parse().

140 {
141  if(labelOffset != offset) {
142  labelOffset = offset;
143  labelFigure->setPosition(Point(getBounds().x + getBounds().width / 2, getBounds().y + getBounds().height + labelOffset));
144  };
145 }
const Rectangle & getBounds() const
Definition: ProgressMeterFigure.cc:168
cTextFigure * labelFigure
Definition: ProgressMeterFigure.h:34
int labelOffset
Definition: ProgressMeterFigure.h:39
void ProgressMeterFigure::setMaxValue ( double  value)

Referenced by parse().

197 {
198  max = value;
199  refresh();
200 }
double value
Definition: ProgressMeterFigure.h:38
void refresh()
Definition: ProgressMeterFigure.cc:306
double max
Definition: ProgressMeterFigure.h:37
void ProgressMeterFigure::setMinValue ( double  value)

Referenced by parse().

186 {
187  min = value;
188  refresh();
189 }
double min
Definition: ProgressMeterFigure.h:36
double value
Definition: ProgressMeterFigure.h:38
void refresh()
Definition: ProgressMeterFigure.cc:306
void ProgressMeterFigure::setStripColor ( const Color color)

Referenced by parse().

67 {
68  stripFigure->setFillColor(color);
69 }
cRectangleFigure * stripFigure
Definition: ProgressMeterFigure.h:31
void ProgressMeterFigure::setText ( const char *  text)

Referenced by parse().

99 {
100  textFormat = text;
101  refresh();
102 }
void refresh()
Definition: ProgressMeterFigure.cc:306
std::string textFormat
Definition: ProgressMeterFigure.h:40
void ProgressMeterFigure::setTextColor ( const Color color)

Referenced by parse().

120 {
121  valueFigure->setColor(color);
122 }
cTextFigure * valueFigure
Definition: ProgressMeterFigure.h:33
void ProgressMeterFigure::setTextFont ( const Font &  font)

Referenced by parse().

110 {
111  valueFigure->setFont(font);
112 }
cTextFigure * valueFigure
Definition: ProgressMeterFigure.h:33
void ProgressMeterFigure::setValue ( int  series,
simtime_t  timestamp,
double  value 
)
overridevirtual

Implements inet::IIndicatorFigure.

Referenced by parse().

297 {
298  ASSERT(series == 0);
299  // Note: we currently ignore timestamp
300  if (value != newValue) {
301  value = newValue;
302  refresh();
303  }
304 }
double value
Definition: ProgressMeterFigure.h:38
void refresh()
Definition: ProgressMeterFigure.cc:306

Member Data Documentation

cRectangleFigure* ProgressMeterFigure::backgroundFigure
private
cRectangleFigure* ProgressMeterFigure::borderFigure
private
cTextFigure* ProgressMeterFigure::labelFigure
private
int ProgressMeterFigure::labelOffset = 10
private
double ProgressMeterFigure::max = 100
private

Referenced by getMaxValue(), refresh(), and setMaxValue().

double ProgressMeterFigure::min = 0
private

Referenced by getMinValue(), refresh(), and setMinValue().

cRectangleFigure* ProgressMeterFigure::stripFigure
private
std::string ProgressMeterFigure::textFormat = "%g"
private

Referenced by getText(), and setText().

double ProgressMeterFigure::value = NaN
private
cTextFigure* ProgressMeterFigure::valueFigure
private

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