WSF
WsfDraw.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFDRAW_HPP
13#define WSFDRAW_HPP
14
15#include "wsf_export.h"
16
17#include <memory>
18#include <vector>
19
20#include "UtCallback.hpp"
21#include "UtColor.hpp"
22class UtInput;
23class UtScriptClass;
24class UtScriptTypes;
25#include "UtVec3.hpp"
26class WsfDrawManager;
27class WsfExtInterface;
28class WsfPlatform;
29class WsfRoute;
31#include "WsfStringId.hpp"
32
35{
36public:
37 static double cFOREVER;
38 static const unsigned int cSTRING_ID_MASK = 0x10000000;
39
53
65
79
89
95
109
111 {
113 unsigned int mID{0};
114 UtColor mColor;
116 float mDuration{0.0};
117 int mLineSize{0};
119 int mTextSize{0};
121 std::string mIcon;
122 std::string mText;
124 float mHeading{0.0};
125 float mPitch{0.0};
126 float mRoll{0.0};
127 float mAxisA{0.0}; // semi minor
128 float mAxisB{0.0}; // semi major
129 float mAxisC{0.0}; // for ellipsoids
130 };
131
132 using DrawEventList = std::vector<DrawEvent>;
133
134 WsfDraw(WsfDrawManager* aManagerPtr);
135 WsfDraw(WsfSimulation& aSimulation);
136 WsfDraw(const WsfDraw& aSrc);
137 WsfDraw& operator=(const WsfDraw&) = delete;
138
139 static WsfDrawManager* GetDrawManager(WsfSimulation& aSimulation);
140
141 void BeginLines();
142 void BeginPolyline();
143 void BeginPoints();
144 void BeginIcons(double aHeading, const std::string& aIconName = "Wedge");
145 void BeginEllipse(double aHeading, double aSemiMinor, double aSemiMajor);
146 void BeginEllipsoid(double aHeading, double aPitch, double aRoll, double aRadiusA, double aRadiusB, double aRadiusC);
147 void BeginQuadrilateral();
148 void BeginText(const std::string& aText);
149 void BeginTimer();
150 void End();
151
152 BeginState GetBeginState() const { return mBeginState; }
153
155 void SetId(unsigned int aId) { mID = aId; }
156
157 unsigned int GetNewId();
158
160 void SetId(WsfStringId aId) { mID = (int)(WsfStringInt(aId) | cSTRING_ID_MASK); }
161
163 int GetId() const { return mID; }
164
166 void SetPointSize(int aSize) { mPointSize = aSize; }
167
169 int GetPointSize() const { return mPointSize; }
170
172 void SetTextSize(int aSize) { mTextSize = aSize; }
173
175 void SetLineSize(int aSize) { mLineSize = aSize; }
176
178 int GetLineSize() const { return mLineSize; }
179
181 void SetLineStyle(LineStyle aStyle) { mLineStyle = aStyle; }
182
184 int GetLineStyle() const { return mLineStyle; }
185
187 void SetTimerSize(int aSize) { mTimerSize = aSize; }
188
190 int GetTimerSize() const { return mTimerSize; }
191
193 void SetEllipseMode(EllipseMode aMode) { mEllipseMode = aMode; }
194
196 int GetEllipseMode() const { return mEllipseMode; }
197
199 void SetColor(const UtColor& aColor) { mCurrentColor = aColor; }
200
202 const UtColor& GetColor() const { return mCurrentColor; }
203
205 void SetColor(double aRed, double aGreen, double aBlue, double aAlpha = 1.0)
206 {
207 mCurrentColor.Set((float)aRed, (float)aGreen, (float)aBlue, (float)aAlpha);
208 }
209
210 void SetTarget(const std::string& aTarget);
211
212 void SetLayer(const std::string& aLayer);
213
214 void Erase(unsigned int aId);
215
216 void Erase(WsfStringId aId);
217
218 void SetDuration(double aDuration) { mDuration = aDuration; }
219
220 double GetDuration() const { return mDuration; }
221
222 static std::unique_ptr<UtScriptClass> CreateScriptClass(const std::string& aClassName, UtScriptTypes* aScriptTypesPtr);
223
224 // Accessors needed to serialize the type:
225 double GetCurrentHeading() const { return mCurrentHeading; }
226 double GetCurrentPitch() const { return mCurrentPitch; }
227 double GetCurrentRoll() const { return mCurrentRoll; }
228 double GetCurrentAxisA() const { return mCurrentAxisA; }
229 double GetCurrentAxisB() const { return mCurrentAxisB; }
230 double GetCurrentAxisC() const { return mCurrentAxisC; }
231 std::string GetCurrentIconName() const { return mCurrentIconName; }
232 std::string GetTarget() const { return mTarget; }
233 std::string GetLayer() const { return mLayer; }
234 int GetUniqueId() const { return mUniqueId; }
235
236 unsigned int EventCount() const { return (unsigned int)mEvents.size(); }
237 const DrawEvent& GetEvent(unsigned int aIndex) const { return mEvents[aIndex]; }
238
239 void Reset();
240
241 void VertexLLA(double aLat, double aLon, double aAlt);
242 void VertexWCS(const double aWCS[3]);
243 void Vertex(WsfPlatform& aPlatform);
244 void VertexECS(WsfPlatform& aPlatform, double aLocationECS[3]);
245 void VertexNED(WsfPlatform& aPlatform, double aLocationNED[3]);
246 void VertexScreen(const double aLocation[3]);
247 void VertexScreenPlat(WsfPlatform& aPlatform, double aLocation[3]);
248 void VertexRoute(WsfRoute& aRoute);
249
250 WsfDrawManager* GetDrawManager();
251
252private:
253 void Flush();
254
255 void AddVertex(const VertexObject& aVertex);
256
257 void BeginClear();
258
259 void SetCurrentState(DrawEvent& aEvent);
260
261 UtColor mCurrentColor;
262 int mPointSize;
263 int mTextSize;
264 int mLineSize;
265 int mLineStyle;
266 int mTimerSize;
267 int mEllipseMode;
268 unsigned int mID;
269 double mDuration;
270 double mCurrentHeading;
271 double mCurrentPitch;
272 double mCurrentRoll;
273 double mCurrentAxisA; // semi minor
274 double mCurrentAxisB; // semi major
275 double mCurrentAxisC; // the third axis
276 std::vector<DrawEvent> mEvents;
277 std::string mCurrentText;
278 std::string mCurrentIconName;
279 std::string mTarget;
280 std::string mLayer;
281 int mUniqueId;
282 BeginState mBeginState;
283 std::vector<VertexObject> mVertexBuffer;
284 WsfDrawManager* mDrawManagerPtr;
285};
286
290{
291public:
292 static WsfDrawManager* Find(const WsfSimulation& aSimulation);
293
295 ~WsfDrawManager() override;
296 WsfDrawManager(const WsfDrawManager& aSrc);
298
299 WsfDrawManager* Clone() const override;
300 bool ProcessInput(UtInput& aInput) override;
301
302 unsigned int GetNewId() { return mNextNewId++; }
303
306 UtCallbackListN<void(const std::string&, const std::string&, const WsfDraw::DrawEventList&)> DrawUpdate;
307
308 void SendDrawUpdate(double aSimTime,
309 const std::string& aTarget,
310 const std::string& aLayer,
311 std::vector<WsfDraw::DrawEvent>& aEvents);
312
313private:
314 enum DrawType
315 {
316 cROUTE,
317 cROUTE_NETWORK
318 };
319
320 struct DrawCommand
321 {
322 DrawCommand();
323 int mDrawTypeId;
324 UtColor mColor1;
325 UtColor mColor2;
326 double mDuration;
327 WsfStringId mObjectNameId;
328 int mLineSize;
329 int mPointSize;
330 std::string mLayer;
331 };
332
333 void WriteToFile(double aSimTime,
334 const std::string& aTarget,
335 const std::string& aLayer,
336 std::vector<WsfDraw::DrawEvent>& aEvents);
337
338 void Start() override;
339
340 unsigned int mNextNewId;
341 std::vector<DrawCommand> mDrawCommands;
342 std::ofstream* mDrawFilePtr;
343 std::string mDrawFilePath;
344};
345
346#endif
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
Definition WsfDraw.hpp:290
WsfDrawManager & operator=(const WsfDrawManager &)=delete
void SendDrawUpdate(double aSimTime, const std::string &aTarget, const std::string &aLayer, std::vector< WsfDraw::DrawEvent > &aEvents)
Definition WsfDraw.cpp:168
UtCallbackListN< void(const std::string &, const std::string &, const WsfDraw::DrawEventList &)> DrawUpdate
Definition WsfDraw.hpp:306
WsfDrawManager * Clone() const override
Definition WsfDraw.cpp:386
unsigned int GetNewId()
Definition WsfDraw.hpp:302
WsfDrawManager()
Definition WsfDraw.cpp:66
bool ProcessInput(UtInput &aInput) override
Definition WsfDraw.cpp:91
static WsfDrawManager * Find(const WsfSimulation &aSimulation)
Definition WsfDraw.cpp:61
int GetLineStyle() const
Gets the style of lines drawn with DrawLine().
Definition WsfDraw.hpp:184
static double cFOREVER
Definition WsfDraw.hpp:37
std::string GetTarget() const
Definition WsfDraw.hpp:232
std::vector< DrawEvent > DrawEventList
Definition WsfDraw.hpp:132
double GetCurrentPitch() const
Definition WsfDraw.hpp:226
const UtColor & GetColor() const
Gets the color used to draw items.
Definition WsfDraw.hpp:202
DrawType
Definition WsfDraw.hpp:67
@ cNONE
Definition WsfDraw.hpp:77
@ cQUADRILATERAL
Definition WsfDraw.hpp:74
@ cPOINT
Definition WsfDraw.hpp:69
@ cTIMER
Definition WsfDraw.hpp:76
@ cELLIPSOID
Definition WsfDraw.hpp:73
@ cLINE
Definition WsfDraw.hpp:68
@ cTEXT
Definition WsfDraw.hpp:75
@ cELLIPSE
Definition WsfDraw.hpp:71
@ cICON
Definition WsfDraw.hpp:70
@ cERASE
Definition WsfDraw.hpp:72
VertexType
Definition WsfDraw.hpp:81
@ cRELATIVE_ECS
Definition WsfDraw.hpp:85
@ cRELATIVE_NED
Definition WsfDraw.hpp:86
@ cRELATIVE_ZERO
Definition WsfDraw.hpp:84
@ cUNSET_VERTEX
Definition WsfDraw.hpp:82
@ cABSOLUTE_SCREEN
Definition WsfDraw.hpp:87
@ cABSOLUTE_WCS
Definition WsfDraw.hpp:83
void SetTextSize(int aSize)
Sets the size of text.
Definition WsfDraw.hpp:172
void BeginEllipsoid(double aHeading, double aPitch, double aRoll, double aRadiusA, double aRadiusB, double aRadiusC)
Begin ellipsoid drawing mode. Draws a 3D ellipsoid at each vertex given by the following Vertex() com...
Definition WsfDraw.cpp:544
void SetId(WsfStringId aId)
Sets the ID given to items drawn.
Definition WsfDraw.hpp:160
int GetEllipseMode() const
Gets the style of an ellipse or ellipsoid.
Definition WsfDraw.hpp:196
double GetCurrentHeading() const
Definition WsfDraw.hpp:225
int GetTimerSize() const
Gets the size of points drawn with DrawPoint().
Definition WsfDraw.hpp:190
void SetLineStyle(LineStyle aStyle)
Sets the style of lines drawn with DrawLine().
Definition WsfDraw.hpp:181
void BeginPolyline()
Definition WsfDraw.cpp:509
void BeginLines()
Begins line drawing mode. Draws a line segment between each pair of Vertexes given by following Verte...
Definition WsfDraw.cpp:501
double GetCurrentAxisC() const
Definition WsfDraw.hpp:230
void SetLineSize(int aSize)
Sets the size (width) of lines drawn with DrawLine().
Definition WsfDraw.hpp:175
int GetUniqueId() const
Definition WsfDraw.hpp:234
void BeginEllipse(double aHeading, double aSemiMinor, double aSemiMajor)
Definition WsfDraw.cpp:532
double GetCurrentAxisB() const
Definition WsfDraw.hpp:229
void SetDuration(double aDuration)
Definition WsfDraw.hpp:218
WsfDraw(WsfDrawManager *aManagerPtr)
Definition WsfDraw.cpp:431
void SetEllipseMode(EllipseMode aMode)
Sets the style of an ellipse or ellipsoid.
Definition WsfDraw.hpp:193
void SetColor(double aRed, double aGreen, double aBlue, double aAlpha=1.0)
Sets the color used to draw items.
Definition WsfDraw.hpp:205
static WsfDrawManager * GetDrawManager(WsfSimulation &aSimulation)
Definition WsfDraw.cpp:930
WsfDraw & operator=(const WsfDraw &)=delete
LineStyle
Styles available for drawn lines.
Definition WsfDraw.hpp:56
@ cDASH_DOT
Definition WsfDraw.hpp:61
@ cDOTTED2
Definition WsfDraw.hpp:60
@ cDASH_DOT2
Definition WsfDraw.hpp:62
@ cDASHED
Definition WsfDraw.hpp:57
@ cLONG_DASHED
Definition WsfDraw.hpp:58
@ cSOLID
Definition WsfDraw.hpp:63
@ cDOTTED
Definition WsfDraw.hpp:59
void BeginPoints()
Begins point drawing mode. Draws a point at each vertex given by following Vertex() commands.
Definition WsfDraw.cpp:516
void SetTimerSize(int aSize)
Sets the size of timers drawn with DrawPoint().
Definition WsfDraw.hpp:187
void SetId(unsigned int aId)
Changes the ID assigned to new draw items. The sole purpose of Id is the Erase() method.
Definition WsfDraw.hpp:155
void BeginText(const std::string &aText)
Definition WsfDraw.cpp:567
std::string GetCurrentIconName() const
Definition WsfDraw.hpp:231
void SetColor(const UtColor &aColor)
Sets the color used to draw items.
Definition WsfDraw.hpp:199
static const unsigned int cSTRING_ID_MASK
Definition WsfDraw.hpp:38
int GetPointSize() const
Gets the size of points drawn with DrawPoint().
Definition WsfDraw.hpp:169
const DrawEvent & GetEvent(unsigned int aIndex) const
Definition WsfDraw.hpp:237
std::string GetLayer() const
Definition WsfDraw.hpp:233
void End()
Completes a drawing mode initiated with a Begin method.
Definition WsfDraw.cpp:582
void SetPointSize(int aSize)
Sets the size of points drawn with DrawPoint().
Definition WsfDraw.hpp:166
void BeginIcons(double aHeading, const std::string &aIconName="Wedge")
Begins icon drawing mode. Draws an icon each vertex given by following Vertex() commands.
Definition WsfDraw.cpp:523
BeginState
Definition WsfDraw.hpp:41
@ cBEGIN_ELLIPSOID
Definition WsfDraw.hpp:48
@ cBEGIN_NONE
Definition WsfDraw.hpp:42
@ cBEGIN_ELLIPSE
Definition WsfDraw.hpp:47
@ cBEGIN_POLYLINE
Definition WsfDraw.hpp:44
@ cBEGIN_ICONS
Definition WsfDraw.hpp:46
@ cBEGIN_QUADRILATERAL
Definition WsfDraw.hpp:49
@ cBEGIN_TEXT
Definition WsfDraw.hpp:50
@ cBEGIN_POINTS
Definition WsfDraw.hpp:45
@ cBEGIN_LINES
Definition WsfDraw.hpp:43
@ cBEGIN_TIMER
Definition WsfDraw.hpp:51
void BeginTimer()
Definition WsfDraw.cpp:575
double GetCurrentAxisA() const
Definition WsfDraw.hpp:228
unsigned int EventCount() const
Definition WsfDraw.hpp:236
double GetCurrentRoll() const
Definition WsfDraw.hpp:227
int GetLineSize() const
Gets the size (width) of lines drawn with DrawLine().
Definition WsfDraw.hpp:178
BeginState GetBeginState() const
Definition WsfDraw.hpp:152
double GetDuration() const
Definition WsfDraw.hpp:220
void BeginQuadrilateral()
Definition WsfDraw.cpp:561
EllipseMode
Definition WsfDraw.hpp:91
@ cELLIPSE_FILL
Definition WsfDraw.hpp:92
@ cELLIPSE_LINE
Definition WsfDraw.hpp:93
int GetId() const
Sets the ID given to items drawn.
Definition WsfDraw.hpp:163
The WSF Ext is code which is shared between common external interfaces like DIS and HLA.
Definition WsfExtInterface.hpp:183
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
A collection of WsfWaypoint objects that represent a path to be followed.
Definition WsfRoute.hpp:40
friend class WsfSimulation
Definition WsfSimulationExtension.hpp:43
The main controller for a simulation.
Definition WsfSimulation.hpp:109
Definition WsfStringId.hpp:29
Definition WsfDraw.hpp:111
VertexObject mVerts[4]
Definition WsfDraw.hpp:115
float mAxisA
Definition WsfDraw.hpp:127
unsigned int mID
Definition WsfDraw.hpp:113
std::string mIcon
Definition WsfDraw.hpp:121
int mEllipseMode
Definition WsfDraw.hpp:123
float mAxisC
Definition WsfDraw.hpp:129
float mRoll
Definition WsfDraw.hpp:126
int mLineStyle
Definition WsfDraw.hpp:120
float mAxisB
Definition WsfDraw.hpp:128
int mLineSize
Definition WsfDraw.hpp:117
int mTextSize
Definition WsfDraw.hpp:119
float mDuration
Definition WsfDraw.hpp:116
UtColor mColor
Definition WsfDraw.hpp:114
DrawType mDrawType
Definition WsfDraw.hpp:112
float mHeading
Definition WsfDraw.hpp:124
int mPointSize
Definition WsfDraw.hpp:118
float mPitch
Definition WsfDraw.hpp:125
std::string mText
Definition WsfDraw.hpp:122
Represents a vertex for a drawn item.
Definition WsfDraw.hpp:98
VertexObject()
Definition WsfDraw.hpp:99
size_t mPlatformIndex
Definition WsfDraw.hpp:106
VertexType mVertexType
Definition WsfDraw.hpp:105
UtVec3d mPosition
Definition WsfDraw.hpp:107
Copyrights Multiple, All Rights Reserved