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

#include <IndexedImageFigure.h>

Inheritance diagram for inet::IndexedImageFigure:
inet::IIndicatorFigure

Public Member Functions

 IndexedImageFigure (const char *name=nullptr)
 
virtual ~IndexedImageFigure ()
 
virtual void setValue (int series, simtime_t timestamp, double value) override
 
const std::vector< std::string > & getImages () const
 
void setImages (const std::vector< std::string > &images)
 
double getTintAmount () const
 
void setTintAmount (double tintAmount)
 
const ColorgetTintColor () const
 
void setTintColor (const Color &color)
 
double getOpacity () const
 
void setOpacity (double opacity)
 
Interpolation getInterpolation () const
 
void setInterpolation (Interpolation interpolation)
 
const char * getLabel () const
 
void setLabel (const char *text)
 
const Font & getLabelFont () const
 
void setLabelFont (const Font &font)
 
const ColorgetLabelColor () const
 
void setLabelColor (const Color &color)
 
const Point getLabelOffset () const
 
void setLabelOffset (const Point &offset)
 
virtual const Point getSize () const override
 
void setSize (const Point &bounds)
 
const PointgetPos () const
 
void setPos (const Point &point)
 
Anchor getAnchor () const
 
void setAnchor (Anchor anchor)
 
- 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 ()
 

Private Attributes

std::vector< std::string > images
 
cImageFigure * image
 
cTextFigure * labelFigure
 
double value = NaN
 

Constructor & Destructor Documentation

◆ IndexedImageFigure()

inet::IndexedImageFigure::IndexedImageFigure ( const char *  name = nullptr)
31  : cGroupFigure(name)
32 {
33  addChildren();
34 }

◆ ~IndexedImageFigure()

virtual inet::IndexedImageFigure::~IndexedImageFigure ( )
inlinevirtual
32 {}

Member Function Documentation

◆ addChildren()

void inet::IndexedImageFigure::addChildren ( )
protected
227 {
228  labelFigure = new cTextFigure("label");
229  image = new cImageFigure("image");
230 
231  labelFigure->setAnchor(ANCHOR_N);
232 
233  addFigure(image);
234  addFigure(labelFigure);
235 }

Referenced by IndexedImageFigure().

◆ getAllowedPropertyKeys()

const char ** inet::IndexedImageFigure::getAllowedPropertyKeys ( ) const
overrideprotectedvirtual
212 {
213  static const char *keys[32];
214  if (!keys[0]) {
215  const char *localKeys[] = {
216  PKEY_IMAGES, PKEY_TINT_AMOUNT, PKEY_TINT_COLOR, PKEY_OPACITY,
217  PKEY_INTERPOLATION, PKEY_LABEL, PKEY_LABEL_FONT, PKEY_LABEL_COLOR,
218  PKEY_LABEL_OFFSET, PKEY_INITIAL_VALUE, PKEY_POS, PKEY_SIZE, PKEY_ANCHOR,
219  PKEY_BOUNDS, nullptr
220  };
221  concatArrays(keys, cGroupFigure::getAllowedPropertyKeys(), localKeys);
222  }
223  return keys;
224 }

◆ getAnchor()

cFigure::Anchor inet::IndexedImageFigure::getAnchor ( ) const
152 {
153  return image->getAnchor();
154 }

◆ getImages()

const std::vector< std::string > & inet::IndexedImageFigure::getImages ( ) const
37 {
38  return images;
39 }

Referenced by inet::visualizer::RadioCanvasVisualizer::setImageIndex().

◆ getInterpolation()

cFigure::Interpolation inet::IndexedImageFigure::getInterpolation ( ) const
79 {
80  return image->getInterpolation();
81 }

◆ getLabel()

const char * inet::IndexedImageFigure::getLabel ( ) const
89 {
90  return labelFigure->getText();
91 }

◆ getLabelColor()

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

◆ getLabelFont()

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

◆ getLabelOffset()

const cFigure::Point inet::IndexedImageFigure::getLabelOffset ( ) const
119 {
120  return labelFigure->getPosition() - image->getPosition();
121 }

Referenced by setPos().

◆ getOpacity()

double inet::IndexedImageFigure::getOpacity ( ) const
69 {
70  return image->getOpacity();
71 }

◆ getPos()

const cFigure::Point & inet::IndexedImageFigure::getPos ( ) const
140 {
141  return image->getPosition();
142 }

◆ getSize()

const cFigure::Point inet::IndexedImageFigure::getSize ( ) const
overridevirtual

Implements inet::IIndicatorFigure.

129 {
130  return Point(image->getWidth(), image->getHeight());
131 }

◆ getTintAmount()

double inet::IndexedImageFigure::getTintAmount ( ) const
49 {
50  return image->getTintAmount();
51 }

◆ getTintColor()

const cFigure::Color & inet::IndexedImageFigure::getTintColor ( ) const
59 {
60  return image->getTintColor();
61 }

◆ parse()

void inet::IndexedImageFigure::parse ( cProperty *  property)
overrideprotectedvirtual
162 {
163  ASSERT(property->getNumValues(PKEY_IMAGES));
164  cGroupFigure::parse(property);
165 
166  const char *s;
167 
168  std::vector<std::string> names;
169  for (int i = 0; i < property->getNumValues(PKEY_IMAGES); ++i)
170  names.push_back(property->getValue(PKEY_IMAGES, i));
171  setImages(names);
172 
173  if (property->containsKey(PKEY_BOUNDS)) {
174  if (property->containsKey(PKEY_POS) || property->containsKey(PKEY_SIZE) || property->containsKey(PKEY_ANCHOR))
175  throw cRuntimeError("%s, %s and %s are not allowed when %s is present", PKEY_POS, PKEY_SIZE, PKEY_ANCHOR, PKEY_BOUNDS);
176  if (property->getNumValues(PKEY_BOUNDS) != 4)
177  throw cRuntimeError("%s: x, y, width, height expected", PKEY_BOUNDS);
178  Point p = parsePoint(property, PKEY_BOUNDS, 0);
179  Point size = parsePoint(property, PKEY_BOUNDS, 2);
180  setPos(p);
181  setSize(size);
182  setAnchor(ANCHOR_NW);
183  }
184  else {
185  setPos(parsePoint(property, PKEY_POS, 0));
186  if ((s = property->getValue(PKEY_ANCHOR)) != nullptr)
187  setAnchor(parseAnchor(s));
188  if ((s = property->getValue(PKEY_SIZE)) != nullptr)
189  setSize(parsePoint(property, PKEY_SIZE, 0));
190  }
191  if ((s = property->getValue(PKEY_TINT_AMOUNT)) != nullptr)
193  if ((s = property->getValue(PKEY_TINT_COLOR)) != nullptr)
194  setTintColor(parseColor(s));
195  if ((s = property->getValue(PKEY_OPACITY)) != nullptr)
196  setOpacity(atof(s));
197  if ((s = property->getValue(PKEY_INTERPOLATION)) != nullptr)
198  setInterpolation(parseInterpolation(s));
199  if ((s = property->getValue(PKEY_LABEL)) != nullptr)
200  setLabel(s);
201  if ((s = property->getValue(PKEY_LABEL_FONT)) != nullptr)
202  setLabelFont(parseFont(s));
203  if ((s = property->getValue(PKEY_LABEL_COLOR)) != nullptr)
204  setLabelColor(parseColor(s));
205  if (property->containsKey(PKEY_LABEL_OFFSET))
206  setLabelOffset(parsePoint(property, PKEY_LABEL_OFFSET, 0));
207  if ((s = property->getValue(PKEY_INITIAL_VALUE)) != nullptr)
208  setValue(0, simTime(), utils::atod(s));
209 }

◆ refresh()

void inet::IndexedImageFigure::refresh ( )
protected
248 {
249  if (std::isnan(value)) {
250  image->setVisible(false);
251  return;
252  }
253 
254  image->setVisible(true);
255  int newValue = (int)value % images.size();
256  image->setImageName(images[newValue].c_str());
257 }

Referenced by setImages(), and setValue().

◆ setAnchor()

void inet::IndexedImageFigure::setAnchor ( Anchor  anchor)
157 {
158  image->setAnchor(anchor);
159 }

Referenced by parse().

◆ setImages()

void inet::IndexedImageFigure::setImages ( const std::vector< std::string > &  images)
42 {
43  ASSERT(images.size());
44  this->images = images;
45  refresh();
46 }

Referenced by inet::visualizer::RadioCanvasVisualizer::createRadioVisualization(), and parse().

◆ setInterpolation()

void inet::IndexedImageFigure::setInterpolation ( Interpolation  interpolation)
84 {
85  image->setInterpolation(interpolation);
86 }

Referenced by parse().

◆ setLabel()

void inet::IndexedImageFigure::setLabel ( const char *  text)
94 {
95  labelFigure->setText(text);
96 }

Referenced by parse().

◆ setLabelColor()

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

Referenced by parse().

◆ setLabelFont()

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

Referenced by parse().

◆ setLabelOffset()

void inet::IndexedImageFigure::setLabelOffset ( const Point offset)
124 {
125  labelFigure->setPosition(image->getPosition() + offset);
126 }

Referenced by parse(), and setPos().

◆ setOpacity()

void inet::IndexedImageFigure::setOpacity ( double  opacity)
74 {
75  image->setOpacity(opacity);
76 }

Referenced by parse().

◆ setPos()

void inet::IndexedImageFigure::setPos ( const Point point)
145 {
146  Point offset = getLabelOffset();
147  image->setPosition(pos);
148  setLabelOffset(offset);
149 }

Referenced by parse().

◆ setSize()

void inet::IndexedImageFigure::setSize ( const Point bounds)
134 {
135  image->setWidth(bounds.x);
136  image->setHeight(bounds.y);
137 }

Referenced by inet::visualizer::RadioCanvasVisualizer::createRadioVisualization(), and parse().

◆ setTintAmount()

void inet::IndexedImageFigure::setTintAmount ( double  tintAmount)
54 {
55  image->setTintAmount(tintAmount);
56 }

Referenced by parse().

◆ setTintColor()

void inet::IndexedImageFigure::setTintColor ( const Color color)
64 {
65  image->setTintColor(color);
66 }

Referenced by parse().

◆ setValue()

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

Implements inet::IIndicatorFigure.

238 {
239  ASSERT(series == 0);
240  // Note: we currently ignore timestamp
241  if (value != newValue) {
242  value = newValue;
243  refresh();
244  }
245 }

Referenced by parse(), and inet::visualizer::RadioCanvasVisualizer::setImageIndex().

Member Data Documentation

◆ image

◆ images

std::vector<std::string> inet::IndexedImageFigure::images
private

Referenced by getImages(), refresh(), and setImages().

◆ labelFigure

cTextFigure* inet::IndexedImageFigure::labelFigure
private

◆ value

double inet::IndexedImageFigure::value = NaN
private

Referenced by refresh(), and setValue().


The documentation for this class was generated from the following files:
inet::IndexedImageFigure::setImages
void setImages(const std::vector< std::string > &images)
Definition: IndexedImageFigure.cc:41
inet::IndexedImageFigure::refresh
void refresh()
Definition: IndexedImageFigure.cc:247
inet::IndexedImageFigure::setTintColor
void setTintColor(const Color &color)
Definition: IndexedImageFigure.cc:63
inet::IndexedImageFigure::setOpacity
void setOpacity(double opacity)
Definition: IndexedImageFigure.cc:73
inet::IndexedImageFigure::setPos
void setPos(const Point &point)
Definition: IndexedImageFigure.cc:144
inet::IndexedImageFigure::setLabelOffset
void setLabelOffset(const Point &offset)
Definition: IndexedImageFigure.cc:123
inet::IndexedImageFigure::labelFigure
cTextFigure * labelFigure
Definition: IndexedImageFigure.h:20
inet::IndexedImageFigure::value
double value
Definition: IndexedImageFigure.h:22
inet::IndexedImageFigure::image
cImageFigure * image
Definition: IndexedImageFigure.h:19
inet::IndexedImageFigure::setLabel
void setLabel(const char *text)
Definition: IndexedImageFigure.cc:93
inet::units::values::s
value< double, units::s > s
Definition: Units.h:1235
inet::IndexedImageFigure::addChildren
void addChildren()
Definition: IndexedImageFigure.cc:226
inet::IndexedImageFigure::setLabelFont
void setLabelFont(const Font &font)
Definition: IndexedImageFigure.cc:103
inet::utils::atod
double atod(const char *s)
Converts string to double.
Definition: INETUtils.cc:80
inet::IndexedImageFigure::setSize
void setSize(const Point &bounds)
Definition: IndexedImageFigure.cc:133
inet::IndexedImageFigure::setLabelColor
void setLabelColor(const Color &color)
Definition: IndexedImageFigure.cc:113
inet::keys
std::vector< K > keys(const std::map< K, V > &m)
Definition: stlutils.h:113
inet::IndexedImageFigure::getLabelOffset
const Point getLabelOffset() const
Definition: IndexedImageFigure.cc:118
inet::IndexedImageFigure::setTintAmount
void setTintAmount(double tintAmount)
Definition: IndexedImageFigure.cc:53
inet::IndexedImageFigure::setInterpolation
void setInterpolation(Interpolation interpolation)
Definition: IndexedImageFigure.cc:83
inet::IndexedImageFigure::images
std::vector< std::string > images
Definition: IndexedImageFigure.h:18
inet::IndexedImageFigure::setValue
virtual void setValue(int series, simtime_t timestamp, double value) override
Definition: IndexedImageFigure.cc:237
inet::IndexedImageFigure::setAnchor
void setAnchor(Anchor anchor)
Definition: IndexedImageFigure.cc:156