CARMA C++
MonitorCell.h
Go to the documentation of this file.
1 #ifndef CARMA_UI_RTD_MONITORCELL_H
2 #define CARMA_UI_RTD_MONITORCELL_H
3 
12 
13 
16 #include "carma/ui/rtd/common/RtDisplay.h"
17 
18 #include "carma/szautil/DataType.h"
20 
22 
23 #include <boost/shared_ptr.hpp>
24 
25 #include <string>
26 #include <sstream>
27 #include <iostream>
28 #include <map>
29 
30 namespace carma {
31 
32 namespace monitor {
33 
34 class MonitorPoint;
35 class MonitorPointBool;
36 
37 } // namespace carma::monitor
38 
39 
40 namespace ui {
41 namespace rtd {
42 
43 class MonitorCell;
44 typedef boost::shared_ptr<MonitorCell> MonitorCellPtr;
45 
55 class MonitorCell : public Cell {
56  public:
57 
58  //------------------------------------------------------------
59  // Class for manging a monitor point condition
60  //------------------------------------------------------------
61 
62  class Condition {
63  public:
65  sza::util::DataType currVal_;
67  AntennaMapper::Antenna* antenna_;
68  int sampleNo_;
69 
70  Condition(monitor::MonitorPoint& mp, sza::util::MonitorCondition cond, int sampleNo) {
71  mp_ = &mp;
72  antenna_ = 0;
73  cond_ = cond;
74  sampleNo_ = sampleNo;
75  };
76 
77  Condition(AntennaMapper::Antenna* antenna, sza::util::MonitorCondition cond) {
78  mp_ = 0;
79  antenna_ = antenna;
80  cond_ = cond;
81  sampleNo_ = 0;
82  };
83 
84  void cacheCurrentValue() {
85 
86  std::ostringstream os;
87  os.str("");
88  os << "Inside CCV 0" << std::endl;
89  RtDisplay::appendToFile(os.str());
90 
91  if(mp_ != 0) {
92 
93  os.str("");
94  os << "Inside CCV 0a" << std::endl;
95  RtDisplay::appendToFile(os.str());
96 
97  switch (mp_->getValuetype()) {
98  case carma::monitor::MONITOR_VALUE_TYPE_SHORT:
99  currVal_ = mp_->getMonitorPointSample(sampleNo_).getMonitorValue().sh;
100  break;
101  case carma::monitor::MONITOR_VALUE_TYPE_INTEGER:
102  currVal_ = (int)mp_->getMonitorPointSample(sampleNo_).getMonitorValue().lo;
103  break;
104  case carma::monitor::MONITOR_VALUE_TYPE_FLOAT:
105  currVal_ = (float)mp_->getMonitorPointSample(sampleNo_).getMonitorValue().fl;
106  break;
107  case carma::monitor::MONITOR_VALUE_TYPE_DOUBLE:
108  currVal_ = (double)mp_->getMonitorPointSample(sampleNo_).getMonitorValue().db;
109  break;
110  default:
111  os.str("");
112  os << "Inside CCV 1" << std::endl;
113  RtDisplay::appendToFile(os.str());
114 
115  ThrowCarmaError("Unhandled CARMA data type");
116  break;
117  }
118  } else {
119  os.str("");
120  os << "Inside CCV 2" << std::endl;
121  RtDisplay::appendToFile(os.str());
122 
123  if(antenna_ == 0)
124  ThrowCarmaError("A condition was set on the current frequency, but this cell has an invalid antenna descriptor");
125 
126  os.str("");
127  os << "Inside CCV 3" << std::endl;
128  RtDisplay::appendToFile(os.str());
129 
130  currVal_ = antenna_->frequency_.GHz();
131  }
132  os.str("");
133  os << "Inside CCV 4" << std::endl;
134  RtDisplay::appendToFile(os.str());
135 
136  };
137 
138  bool isSatisfied() {
139 
140  std::ostringstream os;
141  os.str("");
142  os << "Inside isSatisfied 0" << std::endl;
143  RtDisplay::appendToFile(os.str());
144 
145  cacheCurrentValue();
146 
147  os.str("");
148  os << "Inside isSatisfied 1" << std::endl;
149  RtDisplay::appendToFile(os.str());
150 
151  bool res = cond_.isSatisfiedBy(currVal_);
152 
153  os.str("");
154  os << "Inside isSatisfied 2" << std::endl;
155  RtDisplay::appendToFile(os.str());
156 
157  return res;
158  };
159  };
160 
161  //------------------------------------------------------------
162  // Methods of MonitorCell
163  //------------------------------------------------------------
164 
165  static MonitorCellPtr makeCell(monitor::MonitorPoint& monitorPoint );
166 
167  static MonitorCellPtr makeCell(monitor::MonitorPoint& monitorPoint,
168  int sampleNo );
169 
170  static MonitorCellPtr makeCell(int cellWidth,
171  monitor::MonitorPoint& monitorPoint );
172 
173  static MonitorCellPtr makeCell(int cellWidth,
174  monitor::MonitorPoint& monitorPoint,
175  int sampleNo );
176 
177  static MonitorCellPtr makeCell(monitor::MonitorPoint& monitorPoint,
178  monitor::MonitorPoint& mpColor);
179 
180  static MonitorCellPtr makeCell(monitor::MonitorPoint& monitorPoint,
181  monitor::MonitorPoint& mpColor,
182  int sampleNo );
183 
184  static MonitorCellPtr makeCell(int cellWidth,
185  monitor::MonitorPoint& monitorPoint,
186  monitor::MonitorPoint& mpColor);
187 
188  static MonitorCellPtr makeCell(int cellWidth,
189  monitor::MonitorPoint& monitorPoint,
190  monitor::MonitorPoint& mpColor,
191  int sampleNo);
192 
194  virtual ~MonitorCell( );
195 
196  // Overrides Cell
197  virtual void update( );
198  virtual void updateColor( );
199 
201  void setNotruncate( );
202 
203  void setErrorColor( CellColor errorColor );
204  void setWarnColor( CellColor warnColor );
205  void setGoodColor( CellColor goodColor );
206 
207  void setGoodColorTextOverride( const ::std::string & text,
208  CellColor color );
209 
210  void removeGoodColorTextOverride( const ::std::string & text );
211 
212  std::string getName();
213 
214  void setAntenna(AntennaMapper::Antenna* ant);
215  bool hasAntenna();
216 
217  //------------------------------------------------------------
218  // Add conditions that must be met for this monitor point to
219  // be colored, else color the default color
220  //------------------------------------------------------------
221 
222  void colorIf(monitor::MonitorPoint& mp,
223  sza::util::MonitorCondition condition,
224  int sampleNo=0);
225 
226  // Special Condition for current LO frequency
227 
228  void colorIfFrequencyInGHz(sza::util::MonitorCondition condition);
229 
230  //------------------------------------------------------------
231  // Return true if all specified conditions are currently met
232  //------------------------------------------------------------
233 
234  bool conditionsAreMet();
235 
236  protected:
248  MonitorCell(int cellWidth,
249  bool setMpWidth,
250  monitor::MonitorPoint& monitorPoint,
251  monitor::MonitorPoint& mpColor,
252  int sampleNo);
253 
263  MonitorCell( int cellWidth,
264  bool setMpWidth,
265  monitor::MonitorPoint & monitorPoint,
266  int sampleNo );
267 
268  int getSampleNo( ) const;
269 
276 
277  virtual ::std::string computeText( );
278 
279  virtual CellColor computeColor( );
280 
281  virtual CellColor computeErrorColor( );
282  virtual CellColor computeWarnColor( );
283  virtual CellColor computeGoodColor( );
284 
285 
286  protected:
287  // No copying
288  MonitorCell( const MonitorCell & rhs );
289  MonitorCell & operator=( const MonitorCell & rhs );
290 
291  static MonitorCellPtr makeCell(int cellWidth,
292  bool setMpWidth,
293  monitor::MonitorPoint& monitorPoint,
294  int sampleNo );
295 
296  static MonitorCellPtr makeCell(int cellWidth,
297  bool setMpWidth,
298  monitor::MonitorPoint& monitorPoint,
299  monitor::MonitorPoint& mpColor,
300  int sampleNo );
301 
302  typedef ::std::map< ::std::string, CellColor > StringToColorMap;
303 
305  monitor::MonitorPoint& mpc_; // MP for background color
306 
307  // The sample number to display in this cell.
308  const int sampleNo_;
309 
310  CellColor errorColor_;
311  CellColor warnColor_;
312  CellColor defaultGoodColor_;
313 
314  ::std::auto_ptr< StringToColorMap > goodColorTextOverrides_;
315 
316  // Flag that determines whether data is truncated
317  bool truncateFlag_;
318 
319  // Antenna this cell is associated with (if any)
320 
321  AntennaMapper::Antenna* antenna_;
322 
323  // A vector of conditions for this monitor point
324 
325  std::vector<Condition> conditions_;
326 
327  private:
328  void initialize(int w, bool useW);
329 };
330 
331 
332 class MonitorCellComplex : public MonitorCell {
333  public:
334  MonitorCellComplex(
335  int cellWidth,
336  bool setMpWidth,
338  int sampleNo,
339  carma::monitor::MonitorPointComplex::stringValueReturnType
340  complexRep );
341 
342  MonitorCellComplex(
343  int cellWidth,
344  bool setMpWidth,
346  int sampleNo );
347 
348  protected:
349  ::std::string computeText( );
350 
351  private:
352  friend class MonitorCell;
354  const
355  carma::monitor::MonitorPointComplex::stringValueReturnType complexRep_;
356 
357 };
358 
359 
360 class MonitorCellBool : public MonitorCell {
361  friend class MonitorCell;
362 
363  public:
364  void overrideStateAppearances(
365  const ::std::string & trueStateText, CellColor trueStateColour,
366  const ::std::string & falseStateText, CellColor falseStateColour );
367 
368  void clearOverrides( );
369 
370  protected:
371  MonitorCellBool( int cellWidth,
372  bool setMpWidth,
373  monitor::MonitorPointBool & mpBool,
374  int sampleNo );
375 
376  virtual ::std::string computeText( );
377 
378  virtual CellColor computeGoodColor( );
379 
380  private:
381  monitor::MonitorPointBool & mpBool_;
382 
383  bool trueStateTextOverridden_;
384  ::std::string trueStateOverrideText_;
385 
386  bool trueStateColourOverridden_;
387  CellColor trueStateOverrideColour_;
388 
389  bool falseStateTextOverridden_;
390  ::std::string falseStateOverrideText_;
391 
392  bool falseStateColourOverridden_;
393  CellColor falseStateOverrideColour_;
394 };
395 
396 
397 } // namespace carma::ui::rtd
398 } // namespace carma::ui
399 } // namespace carma
400 
401 
402 #endif
Tagged: Tue Jun 22 22:32:16 UTC 2004.
int setMpWidthToFormatLength()
Sets the monitor point width to the internal Cell Format width.
Classes that provide the pecializations of monitor points and sense poiints for different datatypes...
Exception class for errors.
Tagged: Sun Oct 24 17:05:09 PDT 2004.
::std::string text
Formatted text.
Definition: RtDisplay.h:511
virtual ~MonitorCell()
destructor
virtual void update()
Creates a new string that is the dynamic ascii contents of this object.
MonitorCell(int cellWidth, bool setMpWidth, monitor::MonitorPoint &monitorPoint, monitor::MonitorPoint &mpColor, int sampleNo)
Constructor.
Abstract base class for a monitor point.
Definition: MonitorPoint.h:68
Tagged: Tue Sep 24 14:08:19 PDT 2013.
virtual void updateColor()
Automatically called as part of the update cycle to set background color.
void setNotruncate()
Don&#39;t truncate value string; display stars if it overflows cell.
An abstract realtime (dynamic) text Cell.
Definition: RtDisplay.h:300
A Cell that displays the current value of a MonitorPoint, with the background color gotten from a sec...
Definition: MonitorCell.h:55
A class for handling a condition for a monitor point.
enum carma::ui::rtd::CellColorEnum CellColor
Cell color choices.
Enumerate data types.
Definition: DataType.h:28