INET Framework for OMNeT++/OMNEST
inet::ThermometerFigure Class Reference

#include <ThermometerFigure.h>

Inheritance diagram for inet::ThermometerFigure:
inet::IIndicatorFigure

Public Member Functions

 ThermometerFigure (const char *name=nullptr)
 
virtual ~ThermometerFigure ()
 
virtual const Point getSize () const override
 
virtual void setValue (int series, simtime_t timestamp, double value) override
 
const Rectangle & getBounds () const
 
void setBounds (const Rectangle &rect)
 
const ColorgetMercuryColor () const
 
void setMercuryColor (const Color &color)
 
const char * getLabel () const
 
void setLabel (const char *text)
 
int getLabelOffset () const
 
void setLabelOffset (int offset)
 
const Font & getLabelFont () const
 
void setLabelFont (const Font &font)
 
const ColorgetLabelColor () const
 
void setLabelColor (const Color &color)
 
double getMinValue () const
 
void setMinValue (double value)
 
double getMaxValue () const
 
void setMaxValue (double value)
 
double getTickSize () const
 
void setTickSize (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 getContainerGeometry (double &x, double &y, double &width, double &height, double &offset)
 
void setTickGeometry (cLineFigure *tick, int index)
 
void setNumberGeometry (cTextFigure *number, int index)
 
void setMercuryAndContainerGeometry ()
 
void redrawTicks ()
 
void layout ()
 
void refresh ()
 

Protected Attributes

cFigure::Rectangle bounds
 
cPathFigure * mercuryFigure
 
cPathFigure * containerFigure
 
cTextFigure * labelFigure
 
std::vector< cLineFigure * > tickFigures
 
std::vector< cTextFigure * > numberFigures
 
double min = 0
 
double max = 100
 
double tickSize = 10
 
double value = NaN
 
int numTicks = 0
 
double shifting = 0
 
int labelOffset = 10
 

Constructor & Destructor Documentation

◆ ThermometerFigure()

inet::ThermometerFigure::ThermometerFigure ( const char *  name = nullptr)
39  : cGroupFigure(name)
40 {
41  addChildren();
42 }

◆ ~ThermometerFigure()

inet::ThermometerFigure::~ThermometerFigure ( )
virtual
45 {
46  // delete figures which is not in canvas
47  for (size_t i = numTicks; i < tickFigures.size(); ++i) {
48  dropAndDelete(tickFigures[i]);
49  dropAndDelete(numberFigures[i]);
50  }
51 }

Member Function Documentation

◆ addChildren()

void inet::ThermometerFigure::addChildren ( )
protected
205 {
206  mercuryFigure = new cPathFigure("mercury");
207  containerFigure = new cPathFigure("container");
208  labelFigure = new cTextFigure("label");
209 
210  mercuryFigure->setFilled(true);
211  mercuryFigure->setFillColor("darkorange");
212  mercuryFigure->setLineOpacity(0);
213 
214  labelFigure->setAnchor(cFigure::ANCHOR_N);
215 
216  addFigure(mercuryFigure);
217  addFigure(containerFigure);
218  addFigure(labelFigure);
219 }

Referenced by ThermometerFigure().

◆ getAllowedPropertyKeys()

const char ** inet::ThermometerFigure::getAllowedPropertyKeys ( ) const
overrideprotectedvirtual
191 {
192  static const char *keys[32];
193  if (!keys[0]) {
194  const char *localKeys[] = {
195  PKEY_MERCURY_COLOR, PKEY_LABEL, PKEY_LABEL_FONT,
196  PKEY_LABEL_COLOR, PKEY_MIN_VALUE, PKEY_MAX_VALUE, PKEY_TICK_SIZE,
197  PKEY_INITIAL_VALUE, PKEY_POS, PKEY_SIZE, PKEY_ANCHOR, PKEY_BOUNDS, PKEY_LABEL_OFFSET, nullptr
198  };
199  concatArrays(keys, cGroupFigure::getAllowedPropertyKeys(), localKeys);
200  }
201  return keys;
202 }

◆ getBounds()

const cFigure::Rectangle & inet::ThermometerFigure::getBounds ( ) const

◆ getContainerGeometry()

void inet::ThermometerFigure::getContainerGeometry ( double &  x,
double &  y,
double &  width,
double &  height,
double &  offset 
)
protected
248 {
249  x = getBounds().x + getBounds().width * CONTAINER_POS_PERCENT;
250  y = getBounds().y + getBounds().width * CONTAINER_POS_PERCENT;
251  width = getBounds().width * CONTAINER_WIDTH_PERCENT;
252  offset = getBounds().height * CONTAINER_OFFSET_PERCENT;
253  height = getBounds().height - width * (1 + 2 * CONTAINER_POS_PERCENT) - getBounds().width * CONTAINER_POS_PERCENT - offset;
254 }

Referenced by setMercuryAndContainerGeometry(), setNumberGeometry(), and setTickGeometry().

◆ getLabel()

const char * inet::ThermometerFigure::getLabel ( ) const
75 {
76  return labelFigure->getText();
77 }

◆ getLabelColor()

const cFigure::Color & inet::ThermometerFigure::getLabelColor ( ) const
108 {
109  return labelFigure->getColor();
110 }

◆ getLabelFont()

const cFigure::Font & inet::ThermometerFigure::getLabelFont ( ) const
98 {
99  return labelFigure->getFont();
100 }

◆ getLabelOffset()

int inet::ThermometerFigure::getLabelOffset ( ) const
85 {
86  return labelOffset;
87 }

◆ getMaxValue()

double inet::ThermometerFigure::getMaxValue ( ) const
132 {
133  return max;
134 }

◆ getMercuryColor()

const cFigure::Color & inet::ThermometerFigure::getMercuryColor ( ) const
65 {
66  return mercuryFigure->getLineColor();
67 }

◆ getMinValue()

double inet::ThermometerFigure::getMinValue ( ) const
118 {
119  return min;
120 }

◆ getSize()

virtual const Point inet::ThermometerFigure::getSize ( ) const
inlineoverridevirtual

Implements inet::IIndicatorFigure.

51 { return getBounds().getSize(); }

◆ getTickSize()

double inet::ThermometerFigure::getTickSize ( ) const
146 {
147  return tickSize;
148 }

◆ layout()

void inet::ThermometerFigure::layout ( )
protected
379 {
381 
382  for (int i = 0; i < numTicks; ++i) {
385  }
386 
387  labelFigure->setPosition(Point(getBounds().getCenter().x, getBounds().y + getBounds().height + labelOffset));
388 }

Referenced by setBounds().

◆ parse()

void inet::ThermometerFigure::parse ( cProperty *  property)
overrideprotectedvirtual
160 {
161  cGroupFigure::parse(property);
162 
163  setBounds(parseBounds(property, getBounds()));
164 
165  // Set default
166  redrawTicks();
167 
168  const char *s;
169  if ((s = property->getValue(PKEY_MERCURY_COLOR)) != nullptr)
170  setMercuryColor(parseColor(s));
171  if ((s = property->getValue(PKEY_LABEL)) != nullptr)
172  setLabel(s);
173  if ((s = property->getValue(PKEY_LABEL_OFFSET)) != nullptr)
174  setLabelOffset(atoi(s));
175  if ((s = property->getValue(PKEY_LABEL_FONT)) != nullptr)
176  setLabelFont(parseFont(s));
177  if ((s = property->getValue(PKEY_LABEL_COLOR)) != nullptr)
178  setLabelColor(parseColor(s));
179  // This must be initialized before min and max, because it is possible to have too many unnecessary ticks
180  if ((s = property->getValue(PKEY_TICK_SIZE)) != nullptr)
182  if ((s = property->getValue(PKEY_MIN_VALUE)) != nullptr)
184  if ((s = property->getValue(PKEY_MAX_VALUE)) != nullptr)
186  if ((s = property->getValue(PKEY_INITIAL_VALUE)) != nullptr)
187  setValue(0, simTime(), utils::atod(s));
188 }

◆ redrawTicks()

void inet::ThermometerFigure::redrawTicks ( )
protected
323 {
324  ASSERT(tickFigures.size() == numberFigures.size());
325 
326  double fraction = std::abs(fmod(min / tickSize, 1));
327  shifting = tickSize * (min < 0 ? fraction : 1 - fraction);
328  // if fraction == 0 then shifting == tickSize therefore don't have to shift the ticks
329  if (shifting == tickSize)
330  shifting = 0;
331 
332  int prevNumTicks = numTicks;
333  numTicks = std::max(0.0, std::abs(max - min - shifting) / tickSize + 1);
334 
335  // Allocate ticks and numbers if needed
336  if ((size_t)numTicks > tickFigures.size()) {
337  while ((size_t)numTicks > tickFigures.size()) {
338  cLineFigure *tick = new cLineFigure();
339  cTextFigure *number = new cTextFigure();
340  take(tick);
341  take(number);
342 
343  number->setAnchor(cFigure::ANCHOR_W);
344 
345  tickFigures.push_back(tick);
346  numberFigures.push_back(number);
347  }
348  }
349 
350  // Add or remove figures from canvas according to previous number of ticks
351  for (int i = numTicks; i < prevNumTicks; ++i) {
352  removeFigure(tickFigures[i]);
353  removeFigure(numberFigures[i]);
354  take(tickFigures[i]);
355  take(numberFigures[i]);
356  }
357  for (int i = prevNumTicks; i < numTicks; ++i) {
358  drop(tickFigures[i]);
359  drop(numberFigures[i]);
360  addFigure(tickFigures[i]);
361  addFigure(numberFigures[i]);
362  }
363 
364  for (int i = 0; i < numTicks; ++i) {
366 
367  double number = min + i * tickSize + shifting;
368  if (std::abs(number) < tickSize / 2)
369  number = 0;
370 
371  char buf[32];
372  sprintf(buf, "%g", number);
373  numberFigures[i]->setText(buf);
375  }
376 }

Referenced by parse(), setMaxValue(), setMinValue(), and setTickSize().

◆ refresh()

void inet::ThermometerFigure::refresh ( )
protected

◆ setBounds()

void inet::ThermometerFigure::setBounds ( const Rectangle &  rect)
59 {
60  bounds = rect;
61  layout();
62 }

Referenced by parse().

◆ setLabel()

void inet::ThermometerFigure::setLabel ( const char *  text)
80 {
81  labelFigure->setText(text);
82 }

Referenced by parse().

◆ setLabelColor()

void inet::ThermometerFigure::setLabelColor ( const Color color)
113 {
114  labelFigure->setColor(color);
115 }

Referenced by parse().

◆ setLabelFont()

void inet::ThermometerFigure::setLabelFont ( const Font &  font)
103 {
104  labelFigure->setFont(font);
105 }

Referenced by parse().

◆ setLabelOffset()

void inet::ThermometerFigure::setLabelOffset ( int  offset)
90 {
91  if (labelOffset != offset) {
92  labelOffset = offset;
93  labelFigure->setPosition(Point(getBounds().getCenter().x, getBounds().y + getBounds().height + labelOffset));
94  }
95 }

Referenced by parse().

◆ setMaxValue()

void inet::ThermometerFigure::setMaxValue ( double  value)
137 {
138  if (max != value) {
139  max = value;
140  redrawTicks();
141  refresh();
142  }
143 }

Referenced by parse().

◆ setMercuryAndContainerGeometry()

void inet::ThermometerFigure::setMercuryAndContainerGeometry ( )
protected
275 {
276  containerFigure->clearPath();
277  mercuryFigure->clearPath();
278 
279  containerFigure->setLineWidth(getBounds().width * CONTAINER_LINE_WIDTH_PERCENT);
280 
281  double x, y, width, height, offset;
282  getContainerGeometry(x, y, width, height, offset);
283 
284  containerFigure->addMoveTo(x, y);
285  containerFigure->addLineRel(0, height + 2 * offset);
286  // TODO this does not work with Qtenv:
287 // containerFigure->addCubicBezierCurveRel(0, width, width, width, width, 0);
288  containerFigure->addArcRel(width / 2, width / 2, 0, true, false, width, 0);
289  containerFigure->addLineRel(0, -height - 2 * offset);
290  containerFigure->addArcRel(width / 2, width / 2, 0, true, false, -width, 0);
291 
292  double mercuryLevel;
293  double overflow = 0;
294  if (std::isnan(value))
295  return;
296  else if (value < min) {
297  mercuryFigure->addMoveTo(x, y + 2 * offset + height);
298  mercuryFigure->addArcRel(width / 2, width / 2, 0, true, false, width, 0);
299  mercuryFigure->addClosePath();
300  return;
301  }
302  else if (value > max) {
303  mercuryLevel = 1;
304  // value < max so the mercury will be overflow
305  overflow = 2 * offset;
306  offset = 0;
307  }
308  else
309  mercuryLevel = (value - min) / (max - min);
310 
311  mercuryFigure->addMoveTo(x, y + offset + height * (1 - mercuryLevel));
312  mercuryFigure->addLineRel(0, height * mercuryLevel + overflow + offset);
313  // TODO this does not work with Qtenv:
314 // mercuryFigure->addCubicBezierCurveRel(0, width, width, width, width, 0);
315  mercuryFigure->addArcRel(width / 2, width / 2, 0, true, false, width, 0);
316  mercuryFigure->addLineRel(0, -height * mercuryLevel - overflow - offset);
317  if (overflow > 0)
318  mercuryFigure->addArcRel(width / 2, width / 2, 0, true, false, -width, 0);
319  mercuryFigure->addClosePath();
320 }

Referenced by layout(), and refresh().

◆ setMercuryColor()

void inet::ThermometerFigure::setMercuryColor ( const Color color)
70 {
71  mercuryFigure->setFillColor(color);
72 }

Referenced by parse().

◆ setMinValue()

void inet::ThermometerFigure::setMinValue ( double  value)
123 {
124  if (min != value) {
125  min = value;
126  redrawTicks();
127  refresh();
128  }
129 }

Referenced by parse().

◆ setNumberGeometry()

void inet::ThermometerFigure::setNumberGeometry ( cTextFigure *  number,
int  index 
)
protected
257 {
258  if (numTicks - 1 == 0)
259  return;
260 
261  double x, y, width, height, offset;
262  getContainerGeometry(x, y, width, height, offset);
263 
264  double lineWidth = getBounds().height * TICK_LINE_WIDTH_PERCENT;
265  x += width + lineWidth + getBounds().width * TICK_LENGTH_PERCENT;
266  y += offset + height - height * (index * tickSize + shifting) / (max - min);
267 
268  double pointSize = getBounds().height * FONT_SIZE_PERCENT;
269 
270  number->setPosition(Point(x + pointSize * NUMBER_DISTANCE_FROM_TICK_PERCENT, y));
271  number->setFont(cFigure::Font("", pointSize, 0));
272 }

Referenced by layout(), and redrawTicks().

◆ setTickGeometry()

void inet::ThermometerFigure::setTickGeometry ( cLineFigure *  tick,
int  index 
)
protected
232 {
233  if (numTicks - 1 == 0)
234  return;
235 
236  double x, y, width, height, offset;
237  getContainerGeometry(x, y, width, height, offset);
238 
239  double lineWidth = getBounds().height * TICK_LINE_WIDTH_PERCENT / 2;
240  x += width + lineWidth;
241  y += offset + height - height * (index * tickSize + shifting) / (max - min);
242  tick->setStart(Point(x, y));
243  tick->setEnd(Point(x + getBounds().width * TICK_LENGTH_PERCENT, y));
244  tick->setLineWidth(lineWidth);
245 }

Referenced by layout(), and redrawTicks().

◆ setTickSize()

void inet::ThermometerFigure::setTickSize ( double  value)
151 {
152  if (tickSize != value) {
153  tickSize = value;
154  redrawTicks();
155  refresh();
156  }
157 }

Referenced by parse().

◆ setValue()

void inet::ThermometerFigure::setValue ( int  series,
simtime_t  timestamp,
double  value 
)
overridevirtual

Implements inet::IIndicatorFigure.

222 {
223  ASSERT(series == 0);
224  // Note: we currently ignore timestamp
225  if (value != newValue) {
226  value = newValue;
227  refresh();
228  }
229 }

Referenced by parse().

Member Data Documentation

◆ bounds

cFigure::Rectangle inet::ThermometerFigure::bounds
protected

Referenced by getBounds(), and setBounds().

◆ containerFigure

cPathFigure* inet::ThermometerFigure::containerFigure
protected

◆ labelFigure

cTextFigure* inet::ThermometerFigure::labelFigure
protected

◆ labelOffset

int inet::ThermometerFigure::labelOffset = 10
protected

◆ max

double inet::ThermometerFigure::max = 100
protected

◆ mercuryFigure

cPathFigure* inet::ThermometerFigure::mercuryFigure
protected

◆ min

double inet::ThermometerFigure::min = 0
protected

◆ numberFigures

std::vector<cTextFigure *> inet::ThermometerFigure::numberFigures
protected

◆ numTicks

int inet::ThermometerFigure::numTicks = 0
protected

◆ shifting

double inet::ThermometerFigure::shifting = 0
protected

◆ tickFigures

std::vector<cLineFigure *> inet::ThermometerFigure::tickFigures
protected

◆ tickSize

double inet::ThermometerFigure::tickSize = 10
protected

◆ value

double inet::ThermometerFigure::value = NaN
protected

The documentation for this class was generated from the following files:
inet::ThermometerFigure::setLabelOffset
void setLabelOffset(int offset)
Definition: ThermometerFigure.cc:89
inet::ThermometerFigure::setBounds
void setBounds(const Rectangle &rect)
Definition: ThermometerFigure.cc:58
inet::ThermometerFigure::min
double min
Definition: ThermometerFigure.h:25
inet::ThermometerFigure::setMercuryColor
void setMercuryColor(const Color &color)
Definition: ThermometerFigure.cc:69
inet::ThermometerFigure::setNumberGeometry
void setNumberGeometry(cTextFigure *number, int index)
Definition: ThermometerFigure.cc:256
inet::ThermometerFigure::addChildren
void addChildren()
Definition: ThermometerFigure.cc:204
inet::ThermometerFigure::tickFigures
std::vector< cLineFigure * > tickFigures
Definition: ThermometerFigure.h:23
inet::ThermometerFigure::redrawTicks
void redrawTicks()
Definition: ThermometerFigure.cc:322
inet::ThermometerFigure::tickSize
double tickSize
Definition: ThermometerFigure.h:27
inet::ThermometerFigure::numberFigures
std::vector< cTextFigure * > numberFigures
Definition: ThermometerFigure.h:24
inet::ThermometerFigure::setMaxValue
void setMaxValue(double value)
Definition: ThermometerFigure.cc:136
inet::units::values::s
value< double, units::s > s
Definition: Units.h:1235
inet::ThermometerFigure::labelOffset
int labelOffset
Definition: ThermometerFigure.h:31
inet::ThermometerFigure::setValue
virtual void setValue(int series, simtime_t timestamp, double value) override
Definition: ThermometerFigure.cc:221
inet::utils::atod
double atod(const char *s)
Converts string to double.
Definition: INETUtils.cc:80
inet::ThermometerFigure::setTickSize
void setTickSize(double value)
Definition: ThermometerFigure.cc:150
inet::ThermometerFigure::refresh
void refresh()
Definition: ThermometerFigure.cc:390
inet::keys
std::vector< K > keys(const std::map< K, V > &m)
Definition: stlutils.h:113
inet::ThermometerFigure::value
double value
Definition: ThermometerFigure.h:28
inet::ThermometerFigure::labelFigure
cTextFigure * labelFigure
Definition: ThermometerFigure.h:22
inet::ThermometerFigure::bounds
cFigure::Rectangle bounds
Definition: ThermometerFigure.h:19
inet::ThermometerFigure::getContainerGeometry
void getContainerGeometry(double &x, double &y, double &width, double &height, double &offset)
Definition: ThermometerFigure.cc:247
inet::ThermometerFigure::getBounds
const Rectangle & getBounds() const
Definition: ThermometerFigure.cc:53
inet::sctp::max
double max(const double a, const double b)
Returns the maximum of a and b.
Definition: SctpAssociation.h:266
inet::ThermometerFigure::max
double max
Definition: ThermometerFigure.h:26
inet::ThermometerFigure::setLabelFont
void setLabelFont(const Font &font)
Definition: ThermometerFigure.cc:102
inet::ThermometerFigure::setMercuryAndContainerGeometry
void setMercuryAndContainerGeometry()
Definition: ThermometerFigure.cc:274
inet::ThermometerFigure::containerFigure
cPathFigure * containerFigure
Definition: ThermometerFigure.h:21
inet::ThermometerFigure::setMinValue
void setMinValue(double value)
Definition: ThermometerFigure.cc:122
inet::ThermometerFigure::numTicks
int numTicks
Definition: ThermometerFigure.h:29
inet::ThermometerFigure::setTickGeometry
void setTickGeometry(cLineFigure *tick, int index)
Definition: ThermometerFigure.cc:231
inet::ThermometerFigure::mercuryFigure
cPathFigure * mercuryFigure
Definition: ThermometerFigure.h:20
inet::ThermometerFigure::layout
void layout()
Definition: ThermometerFigure.cc:378
inet::ThermometerFigure::shifting
double shifting
Definition: ThermometerFigure.h:30
inet::ThermometerFigure::setLabel
void setLabel(const char *text)
Definition: ThermometerFigure.cc:79
inet::ThermometerFigure::setLabelColor
void setLabelColor(const Color &color)
Definition: ThermometerFigure.cc:112