VR-Forces 4.2 Class Documentation
stringRepHelper.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2013 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 #pragma once
6 
8 #include "tdbutil/tdbUnits.h"
10 #include "vrfutil/rwRegData.h"
12 #include "vrfutil/rwVector.h"
13 #include "vrfutil/rwReal.h"
14 #include "vrfutil/rwString.h"
15 #include "vrfutil/rwInt.h"
16 
18 {
19 public:
21  {
22 
23  }
24 
25  virtual ~DtStringRepHelper()
26  {
27 
28  }
29 
30  virtual bool isDisplayableSymbol(const DtString& s) const
31  {
32  return true;
33  }
34 
35  virtual DtString stringRep(const DtRwVariableBindings& variables, const DtRwVariableBindings& variableDataTypes) const
36  {
37  DtString rep = "";
38  std::vector<DtReaderWriterRegistryData *>::const_iterator iter = variables.registry().registryData().begin();
39  std::vector<DtReaderWriterRegistryData *>::const_iterator endIter = variables.registry().registryData().end();
40 
41  for(; iter != endIter;)
42  {
43  bool added = false;
44  const DtReaderWriter* readerWriter = (*iter)->readerWriter();
45 
46  DtString label = DtStringRepHelper::convertToLuaSymbol(readerWriter->name().c_str());
47 
48  if (isDisplayableSymbol(label))
49  {
50  label += "=";
51 
54  const DtReaderWriter* type = variableDataTypes.findVariableBinding(readerWriter->name().c_str());
55 
56  if (type)
57  {
58  DtString dataType = *(dynamic_cast<const DtRwString*>(type));
59  if ((dataType == DtScriptedTaskLocationVariable) ||
61  {
62  label += formatLocation(*(dynamic_cast<const DtRwVector*>(readerWriter)));
63  }
64  else if (dataType == DtScriptedTaskOffsetLocationVariable)
65  {
66  label += formatOffset(*(dynamic_cast<const DtRwVector*>(readerWriter)));
67  }
68  else if (dataType == DtScriptedTaskRangeVariable)
69  {
70  label += formatDistance(*(dynamic_cast<const DtRwReal*>(readerWriter)));
71  }
72  else if (dataType == DtScriptedTaskHeadingVariable)
73  {
74  label += formatHeading(*(dynamic_cast<const DtRwReal*>(readerWriter)));
75  }
76  else if (dataType == DtScriptedTaskRateVariable)
77  {
78  label += formatRate(*(dynamic_cast<const DtRwReal*>(readerWriter)));
79  }
80  else if (dataType == DtScriptedTaskTurnRateVariable)
81  {
82  label += formatTurnRate(*(dynamic_cast<const DtRwReal*>(readerWriter)));
83  }
84  else if (dataType == DtScriptedTaskTimeVariable)
85  {
86  label += formatTime(*(dynamic_cast<const DtRwInt*>(readerWriter)));
87  }
88  else
89  {
90  label += readerWriter->prettyPrint();
91  }
92  }
93  else
94  {
95  label += readerWriter->prettyPrint();
96  }
97 
98  rep += label;
99  added = true;
100  }
101 
102  ++iter;
103 
104  if ((iter != endIter) && added)
105  {
106  rep += "; ";
107  }
108  }
109  return rep;
110  }
111 
112  virtual DtString convertToLuaSymbol(const DtString& inputString) const
113  {
114  DtString result;
115  for(int i = 0; i < inputString.size(); ++i)
116  {
117  char c = inputString[i];
118  if (c == '-')
119  {
120  result += '_';
121  }
122  else if (c == ' ')
123  {
124  continue;
125  }
126  else
127  {
128  result += c;
129  }
130  }
131  return result;
132  }
133 
134  virtual DtString formatTime(int time) const
135  {
136  int days = 0, hours = 0, minutes = 0, seconds = 0;
137 
138  days = time / (24 * 3600);
139  time -= (days * 24 * 3600);
140 
141  hours = time / 3600;
142  time -= hours * 3600;
143 
144  minutes = time / 60;
145  time -= minutes * 60;
146 
147  seconds = time;
148 
149  DtString rep;
150 
151  rep = DtString(days) + "d:" + DtString(hours) + "h:" + DtString(minutes) + "m:" + DtString(seconds) + "s";
152 
153  return rep;
154  }
155 
156  virtual DtString formatLocation(const DtVector& loc) const
157  {
158  return formatSourceToDisplay(loc);
159  }
160 
161 
162  virtual DtString formatDistance(double d) const
163  {
164  DtString rep;
165  DtString unitLabel;
166  DtString distance = formatSourceToDisplay(d, DtUnitDisplayDistance, DtUnitMeters, unitLabel);
167 
168  rep = distance;
169 
170  if (unitLabel.length())
171  {
172  rep += " (";
173  rep += unitLabel;
174  rep += ")";
175  }
176 
177  return rep;
178  }
179 
180  virtual DtString formatOffset(const DtVector& loc) const
181  {
182  DtString rep = "{";
183 
184  rep += formatDistance(loc.x());
185  rep += ", ";
186  rep += formatDistance(loc.y());
187  rep += ", ";
188  rep += formatDistance(loc.z());
189  rep += "}";
190 
191  return rep;
192  }
193 
194  virtual DtString formatHeading(double d) const
195  {
196  DtString rep;
197  DtString unitLabel;
198  DtString heading = formatSourceToDisplay(d, DtUnitDisplayOrientation, DtUnitRadians, unitLabel);
199 
200  rep = heading;
201 
202  if (unitLabel.length())
203  {
204  rep += " (";
205  rep += unitLabel;
206  rep += ")";
207  }
208 
209  return rep;
210  }
211 
212  virtual DtString formatRate(double d) const
213  {
214  DtString rep;
215  DtString unitLabel;
216  DtString heading = formatSourceToDisplay(d, DtUnitDisplayVelocity, DtUnitMetersPerSecond, unitLabel);
217 
218  rep = heading;
219 
220  if (unitLabel.length())
221  {
222  rep += " (";
223  rep += unitLabel;
224  rep += ")";
225  }
226 
227  return rep;
228  }
229 
230  virtual DtString formatTurnRate(double d) const
231  {
232  DtString rep;
233  DtString unitLabel;
234  DtString heading = formatSourceToDisplay(d, DtUnitDisplayRotationalVelocity, DtUnitRadians, unitLabel);
235 
236  rep = heading;
237 
238  if (unitLabel.length())
239  {
240  rep += " (";
241  rep += unitLabel;
242  rep += ")";
243  }
244 
245  return rep;
246  }
247 
248 };

Document ID: Generated on Sun Nov 24 19:49:21 EST 2013 from SVN revision 133924
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)