INET Framework for OMNeT++/OMNEST
IndexedImageFigure Class Reference

#include <IndexedImageFigure.h>

Inheritance diagram for 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)
 
const Point getSize () const
 
void setSize (const Point &bounds)
 
const Point & getPos () 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::IndexedImageFigure ( const char *  name = nullptr)
42  : cGroupFigure(name)
43 {
44  addChildren();
45 }
void addChildren()
Definition: IndexedImageFigure.cc:237
virtual IndexedImageFigure::~IndexedImageFigure ( )
inlinevirtual
44 {};

Member Function Documentation

void IndexedImageFigure::addChildren ( )
protected

Referenced by IndexedImageFigure().

238 {
239  labelFigure = new cTextFigure("label");
240  image = new cImageFigure("image");
241 
242  labelFigure->setAnchor(ANCHOR_N);
243 
244  addFigure(image);
245  addFigure(labelFigure);
246 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
cTextFigure * labelFigure
Definition: IndexedImageFigure.h:32
const char ** IndexedImageFigure::getAllowedPropertyKeys ( ) const
overrideprotectedvirtual
223 {
224  static const char *keys[32];
225  if (!keys[0]) {
226  const char *localKeys[] = {
227  PKEY_IMAGES, PKEY_TINT_AMOUNT, PKEY_TINT_COLOR, PKEY_OPACITY,
228  PKEY_INTERPOLATION, PKEY_LABEL, PKEY_LABEL_FONT, PKEY_LABEL_COLOR,
229  PKEY_LABEL_OFFSET, PKEY_INITIAL_VALUE, PKEY_POS, PKEY_SIZE, PKEY_ANCHOR,
230  PKEY_BOUNDS, nullptr
231  };
232  concatArrays(keys, cGroupFigure::getAllowedPropertyKeys(), localKeys);
233  }
234  return keys;
235 }
std::vector< K > keys(const std::map< K, V > &m)
Definition: stlutils.h:96
cFigure::Anchor IndexedImageFigure::getAnchor ( ) const
163 {
164  return image->getAnchor();
165 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
const std::vector< std::string > & IndexedImageFigure::getImages ( ) const

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

48 {
49  return images;
50 }
std::vector< std::string > images
Definition: IndexedImageFigure.h:30
cFigure::Interpolation IndexedImageFigure::getInterpolation ( ) const
90 {
91  return image->getInterpolation();
92 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
const char * IndexedImageFigure::getLabel ( ) const
100 {
101  return labelFigure->getText();
102 }
cTextFigure * labelFigure
Definition: IndexedImageFigure.h:32
const cFigure::Color & IndexedImageFigure::getLabelColor ( ) const
120 {
121  return labelFigure->getColor();
122 }
cTextFigure * labelFigure
Definition: IndexedImageFigure.h:32
const cFigure::Font & IndexedImageFigure::getLabelFont ( ) const
110 {
111  return labelFigure->getFont();
112 }
cTextFigure * labelFigure
Definition: IndexedImageFigure.h:32
const cFigure::Point IndexedImageFigure::getLabelOffset ( ) const

Referenced by setPos().

130 {
131  return labelFigure->getPosition() - image->getPosition();
132 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
cTextFigure * labelFigure
Definition: IndexedImageFigure.h:32
double IndexedImageFigure::getOpacity ( ) const
80 {
81  return image->getOpacity();
82 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
const cFigure::Point & IndexedImageFigure::getPos ( ) const
151 {
152  return image->getPosition();
153 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
const cFigure::Point IndexedImageFigure::getSize ( ) const
140 {
141  return Point(image->getWidth(), image->getHeight());
142 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
double IndexedImageFigure::getTintAmount ( ) const
60 {
61  return image->getTintAmount();
62 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
const cFigure::Color & IndexedImageFigure::getTintColor ( ) const
70 {
71  return image->getTintColor();
72 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
void IndexedImageFigure::parse ( cProperty *  property)
overrideprotectedvirtual
173 {
174  ASSERT(property->getNumValues(PKEY_IMAGES));
175  cGroupFigure::parse(property);
176 
177  const char *s;
178 
179  std::vector<std::string> names;
180  for (int i = 0; i < property->getNumValues(PKEY_IMAGES); ++i)
181  names.push_back(property->getValue(PKEY_IMAGES, i));
182  setImages(names);
183 
184  if (property->containsKey(PKEY_BOUNDS)) {
185  if (property->containsKey(PKEY_POS) || property->containsKey(PKEY_SIZE) || property->containsKey(PKEY_ANCHOR))
186  throw cRuntimeError("%s, %s and %s are not allowed when %s is present", PKEY_POS, PKEY_SIZE, PKEY_ANCHOR, PKEY_BOUNDS);
187  if (property->getNumValues(PKEY_BOUNDS) != 4)
188  throw cRuntimeError("%s: x, y, width, height expected", PKEY_BOUNDS);
189  Point p = parsePoint(property, PKEY_BOUNDS, 0);
190  Point size = parsePoint(property, PKEY_BOUNDS, 2);
191  setPos(p);
192  setSize(size);
193  setAnchor(ANCHOR_NW);
194  }
195  else {
196  setPos(parsePoint(property, PKEY_POS, 0));
197  if ((s = property->getValue(PKEY_ANCHOR)) != nullptr)
198  setAnchor(parseAnchor(s));
199  if ((s = property->getValue(PKEY_SIZE)) != nullptr)
200  setSize(parsePoint(property, PKEY_SIZE, 0));
201  }
202  if ((s = property->getValue(PKEY_TINT_AMOUNT)) != nullptr)
204  if ((s = property->getValue(PKEY_TINT_COLOR)) != nullptr)
205  setTintColor(parseColor(s));
206  if ((s = property->getValue(PKEY_OPACITY)) != nullptr)
207  setOpacity(atof(s));
208  if ((s = property->getValue(PKEY_INTERPOLATION)) != nullptr)
209  setInterpolation(parseInterpolation(s));
210  if ((s = property->getValue(PKEY_LABEL)) != nullptr)
211  setLabel(s);
212  if ((s = property->getValue(PKEY_LABEL_FONT)) != nullptr)
213  setLabelFont(parseFont(s));
214  if ((s = property->getValue(PKEY_LABEL_COLOR)) != nullptr)
215  setLabelColor(parseColor(s));
216  if (property->containsKey(PKEY_LABEL_OFFSET))
217  setLabelOffset(parsePoint(property, PKEY_LABEL_OFFSET, 0));
218  if ((s = property->getValue(PKEY_INITIAL_VALUE)) != nullptr)
219  setValue(0, simTime(), utils::atod(s));
220 }
void setLabelColor(const Color &color)
Definition: IndexedImageFigure.cc:124
void setOpacity(double opacity)
Definition: IndexedImageFigure.cc:84
void setLabel(const char *text)
Definition: IndexedImageFigure.cc:104
void setAnchor(Anchor anchor)
Definition: IndexedImageFigure.cc:167
double atod(const char *s)
Converts string to double.
Definition: INETUtils.cc:38
void setSize(const Point &bounds)
Definition: IndexedImageFigure.cc:144
void setPos(const Point &point)
Definition: IndexedImageFigure.cc:155
void setInterpolation(Interpolation interpolation)
Definition: IndexedImageFigure.cc:94
value< double, units::s > s
Definition: Units.h:1049
void setImages(const std::vector< std::string > &images)
Definition: IndexedImageFigure.cc:52
void setLabelOffset(const Point &offset)
Definition: IndexedImageFigure.cc:134
void setTintColor(const Color &color)
Definition: IndexedImageFigure.cc:74
void setLabelFont(const Font &font)
Definition: IndexedImageFigure.cc:114
void setTintAmount(double tintAmount)
Definition: IndexedImageFigure.cc:64
virtual void setValue(int series, simtime_t timestamp, double value) override
Definition: IndexedImageFigure.cc:248
void IndexedImageFigure::refresh ( )
protected

Referenced by setImages(), and setValue().

259 {
260  if (std::isnan(value)) {
261  image->setVisible(false);
262  return;
263  }
264 
265  image->setVisible(true);
266  int newValue = (int)value % images.size();
267  image->setImageName(images[newValue].c_str());
268 }
double value
Definition: IndexedImageFigure.h:34
cImageFigure * image
Definition: IndexedImageFigure.h:31
std::vector< std::string > images
Definition: IndexedImageFigure.h:30
void IndexedImageFigure::setAnchor ( Anchor  anchor)

Referenced by parse().

168 {
169  image->setAnchor(anchor);
170 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
void IndexedImageFigure::setImages ( const std::vector< std::string > &  images)

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

53 {
54  ASSERT(images.size());
55  this->images = images;
56  refresh();
57 }
std::vector< std::string > images
Definition: IndexedImageFigure.h:30
void refresh()
Definition: IndexedImageFigure.cc:258
void IndexedImageFigure::setInterpolation ( Interpolation  interpolation)

Referenced by parse().

95 {
96  image->setInterpolation(interpolation);
97 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
void IndexedImageFigure::setLabel ( const char *  text)

Referenced by parse().

105 {
106  labelFigure->setText(text);
107 }
cTextFigure * labelFigure
Definition: IndexedImageFigure.h:32
void IndexedImageFigure::setLabelColor ( const Color color)

Referenced by parse().

125 {
126  labelFigure->setColor(color);
127 }
cTextFigure * labelFigure
Definition: IndexedImageFigure.h:32
void IndexedImageFigure::setLabelFont ( const Font &  font)

Referenced by parse().

115 {
116  labelFigure->setFont(font);
117 }
cTextFigure * labelFigure
Definition: IndexedImageFigure.h:32
void IndexedImageFigure::setLabelOffset ( const Point &  offset)

Referenced by parse(), and setPos().

135 {
136  labelFigure->setPosition(image->getPosition() + offset);
137 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
cTextFigure * labelFigure
Definition: IndexedImageFigure.h:32
void IndexedImageFigure::setOpacity ( double  opacity)

Referenced by parse().

85 {
86  image->setOpacity(opacity);
87 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
void IndexedImageFigure::setPos ( const Point &  point)

Referenced by parse().

156 {
157  Point offset = getLabelOffset();
158  image->setPosition(pos);
159  setLabelOffset(offset);
160 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
const Point getLabelOffset() const
Definition: IndexedImageFigure.cc:129
void setLabelOffset(const Point &offset)
Definition: IndexedImageFigure.cc:134
void IndexedImageFigure::setSize ( const Point &  bounds)

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

145 {
146  image->setWidth(bounds.x);
147  image->setHeight(bounds.y);
148 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
void IndexedImageFigure::setTintAmount ( double  tintAmount)

Referenced by parse().

65 {
66  image->setTintAmount(tintAmount);
67 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
void IndexedImageFigure::setTintColor ( const Color color)

Referenced by parse().

75 {
76  image->setTintColor(color);
77 }
cImageFigure * image
Definition: IndexedImageFigure.h:31
void IndexedImageFigure::setValue ( int  series,
simtime_t  timestamp,
double  value 
)
overridevirtual

Implements inet::IIndicatorFigure.

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

249 {
250  ASSERT(series == 0);
251  // Note: we currently ignore timestamp
252  if (value != newValue) {
253  value = newValue;
254  refresh();
255  }
256 }
double value
Definition: IndexedImageFigure.h:34
void refresh()
Definition: IndexedImageFigure.cc:258

Member Data Documentation

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

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

cTextFigure* IndexedImageFigure::labelFigure
private
double IndexedImageFigure::value = NaN
private

Referenced by refresh(), and setValue().


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