fixed: gcc8 compile issues
[opensg.git] / Source / Contrib / ComplexSceneManager / Helper / OSGGestureData.cpp
blobc5ce4d932d2c300a87a5944ccf333c3f7ee2007a
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2008 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include "OSGGestureData.h"
40 #include "OSGGestureDataFields.h"
41 #include "OSGFieldContainer.h"
43 #include "OSGSField.ins"
45 OSG_BEGIN_NAMESPACE
47 GestureData::GestureBlob::GestureBlob( UInt32 uiEvent,
48 Int32 iGestureId,
49 const std::string &szGesture,
50 Real32 rX,
51 Real32 rY,
52 UInt32 uiCoordSys) :
54 _uiEvent (uiEvent ),
55 _iGestureId(iGestureId ),
56 _vPosition (rX, rY, 0.f),
58 _uiCoordSys(uiCoordSys ),
60 _szGesture (szGesture )
64 //GestureData::GestureBlob::~GestureBlob(void)
65 //{
66 //}
68 bool GestureData::GestureBlob::operator ==(const GestureBlob &rhs) const
70 // gesture id and uievent uniquely identifies the gesture
71 return (_uiEvent == rhs._uiEvent && _iGestureId == rhs._iGestureId );
74 bool GestureData::GestureBlob::operator !=(const GestureBlob &rhs) const
76 return !(*this == rhs);
79 bool GestureData::GestureBlob::operator < (const GestureBlob &rhs) const
81 return ((_iGestureId < rhs._iGestureId) ||
82 (_iGestureId == rhs._iGestureId && _uiEvent < rhs._uiEvent));
87 GestureData::GestureData(void) :
88 _vBlobs ( ),
89 _vActiveBlobs( ),
90 _pWindow (NULL ),
91 _pCSMWindow (NULL )
96 GestureData::GestureData(const GestureData &source) :
97 _vBlobs (source._vBlobs ),
98 _vActiveBlobs(source._vActiveBlobs),
99 _pWindow (NULL ),
100 _pCSMWindow (NULL )
104 GestureData::~GestureData(void)
108 /*------------------------------ access -----------------------------------*/
110 const GestureData &GestureData::operator = (const GestureData &rhs)
112 _vBlobs = rhs._vBlobs;
114 _pWindow = rhs._pWindow;
115 _pCSMWindow = rhs._pCSMWindow;
117 return *this;
120 bool GestureData::operator ==(const GestureData &rhs) const
122 //return (_vBlobs == rhs._vBlobs &&
123 // _pWindow == rhs._pWindow );
124 // _pCSMWindow == rhs._pCSMWindow );
126 return (_vBlobs == rhs._vBlobs);
129 void GestureData::addGesture( UInt32 uiId,
130 const std::string &szGesture,
131 Real32 rX,
132 Real32 rY,
133 UInt32 uiCoordSys)
135 GestureBlob tmpBlob(GestureData::AddGesture,
136 uiId,
137 szGesture,
138 rX,
139 rY,
140 uiCoordSys );
142 GestureBlobStoreIt tbIt = std::lower_bound(_vBlobs.begin(),
143 _vBlobs.end (),
144 tmpBlob );
145 if(tbIt == _vBlobs.end())
147 _vBlobs.push_back(tmpBlob);
149 else if(tmpBlob != *tbIt)
151 _vBlobs.insert(tbIt, tmpBlob);
153 else
155 fprintf(stderr, "addC: blob %d mode %d already present\n",
156 uiId,
157 GestureData::AddGesture);
161 void GestureData::updateGesture( UInt32 uiId,
162 const std::string &szGesture,
163 Real32 rX,
164 Real32 rY,
165 UInt32 uiCoordSys)
167 ActiveBlobsStoreIt aIt = std::lower_bound(_vActiveBlobs.begin(),
168 _vActiveBlobs.end (),
169 uiId);
171 UInt32 uiEvent = GestureData::UpdateGesture;
173 if(aIt == _vActiveBlobs.end())
175 uiEvent = GestureData::AddGesture;
177 _vActiveBlobs.push_back(uiId);
179 else
181 if(uiId != *aIt)
183 uiEvent = GestureData::AddGesture;
185 _vActiveBlobs.insert(aIt, uiId);
189 GestureBlob tmpBlob(uiEvent, uiId, szGesture, rX, rY, uiCoordSys);
191 // fprintf(stderr, "update coursor %d / %f %f\n",
192 // uiId, rX, rY);
194 GestureBlobStoreIt tbIt = std::lower_bound(_vBlobs.begin(),
195 _vBlobs.end (),
196 tmpBlob );
198 if(tbIt == _vBlobs.end())
200 _vBlobs.push_back(tmpBlob);
202 else if(tmpBlob != *tbIt)
204 _vBlobs.insert(tbIt, tmpBlob);
206 else
208 *tbIt = tmpBlob;
212 void GestureData::removeGesture(UInt32 uiId)
214 GestureBlob tmpBlob(GestureData::RemoveGesture, uiId, "", 0.f, 0.f);
216 GestureBlobStoreIt tbIt = std::lower_bound(_vBlobs.begin(),
217 _vBlobs.end (),
218 tmpBlob );
220 if(tbIt == _vBlobs.end())
222 _vBlobs.push_back(tmpBlob);
224 else if(tmpBlob != *tbIt)
226 _vBlobs.insert(tbIt, tmpBlob);
228 else
230 fprintf(stderr, "remC: blob %d mode %d already present\n",
231 uiId,
232 GestureData::RemoveGesture);
235 ActiveBlobsStoreIt aIt = std::lower_bound(_vActiveBlobs.begin(),
236 _vActiveBlobs.end (),
237 uiId);
239 if(aIt != _vActiveBlobs.end())
241 if((*aIt) == uiId)
243 _vActiveBlobs.erase(aIt);
249 void GestureData::prepSubmission(void)
253 void GestureData::clear(void)
255 // fprintf(stderr, "clear\n");
256 // this->dump();
257 _vBlobs.clear();
260 void GestureData::dump(void) const
262 fprintf(stderr, "Blobs (%" PRISize ") :\n", _vBlobs.size());
263 for(UInt32 i = 0; i < _vBlobs.size(); ++i)
265 fprintf(stderr, " [%d] : %d %d %d | %f %f\n",
267 _vBlobs[i]._uiEvent,
268 _vBlobs[i]._iGestureId,
269 _vBlobs[i]._uiCoordSys,
270 _vBlobs[i]._vPosition[0],
271 _vBlobs[i]._vPosition[1]);
274 fprintf(stderr, "Active Blobs (%" PRISize ") :\n", _vActiveBlobs.size());
276 for(UInt32 i = 0; i < _vActiveBlobs.size(); ++i)
278 fprintf(stderr, "[%d] : %d\n",
280 _vActiveBlobs[i]);
284 DataType FieldTraits<GestureData>::_type("GestureData", "BaseType" );
286 OSG_FIELDTRAITS_GETTYPE ( GestureData )
287 OSG_FIELD_DLLEXPORT_DEF1(SField, GestureData )
289 OSG_END_NAMESPACE