Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Types.cc
Go to the documentation of this file.
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50
51
52
53 //=============================================================================
54 //
55 // Types
56 //
57 //=============================================================================
58
65 //== INCLUDES =================================================================
66
67 #include "TypesInternal.hh"
68
69 #include <OpenFlipper/common/GlobalOptions.hh>
70 #include <OpenFlipper/BasePlugin/LoggingInterface.hh>
71
72 #include <QCoreApplication>
73
74
78 static int nextTypeId_ = 2;
79
82 static std::map< DataType, QString > typeToString;
83
86 static std::map< QString , size_t > stringToTypeInfo;
87
90 static std::map< DataType , size_t > typeToTypeInfo;
91
92 static QIcon dummyIcon;
93
94 static std::vector< TypeInfo > types;
95
96 //== Functions =========================================================
97
98 std::ostream &operator<<(std::ostream &stream, DataType type)
99 {
100 stream << type.value() ;
101
102 return stream;
103 }
104
105 void initializeTypes() {
106 stringToTypeInfo["Unknown"] = types.size();
107 DataType test(DATA_UNKNOWN);
108 typeToTypeInfo[test] = types.size();
109 types.push_back( TypeInfo(DATA_UNKNOWN ,"Unknown" ,"Unknown.png", QCoreApplication::translate("Types","Unknown")) );
110
111 stringToTypeInfo["Group"] = types.size();
112 typeToTypeInfo[DATA_GROUP] = types.size();
113 types.push_back( TypeInfo(DATA_GROUP ,"Group" ,"group.png", QCoreApplication::translate("Types","Group")) );
114
115 stringToTypeInfo["All"] = types.size();
116 typeToTypeInfo[DATA_ALL] = types.size();
117 types.push_back( TypeInfo(DATA_ALL ,"All" ,"Unknown.png", QCoreApplication::translate("Types","All")) );
118
119 typeToString[DATA_UNKNOWN] = "Unknown";
120 typeToString[DATA_GROUP] = "Group";
121 typeToString[DATA_ALL] = "All";
122
123 // Preload the static icons
124 setTypeIcon(DATA_GROUP,"group.png");
125 }
126
128 DataType addDataType(QString _name, QString _readableName) {
129
130 // Check if datatype already exists.
131 // If so, we return the typeId that is used for it
132 if ( typeExists(_name) ) {
133 std::cerr << "Redefinition of existing data type!" << std::endl;
134 return typeId(_name);
135 }
136
137 int type = nextTypeId_;
138
139 stringToTypeInfo[ _name ] = types.size();
140 typeToTypeInfo[ type ] = types.size();
141 types.push_back( TypeInfo(type, _name, "Unknown.png", _readableName ));
142
143 typeToString[type] = _name;
144
145 nextTypeId_ *= 2;
146 return( type );
147 }
148
150 DataType typeId(QString _name) {
151
152 std::map<QString, size_t>::iterator index = stringToTypeInfo.find( _name );
153
154 if ( index != stringToTypeInfo.end() )
155 return types[ index->second ].type;
156 else {
157 #ifdef DEBUG
158 std::cerr << "Unknown Data type with name " << _name.toStdString() << std::endl;
159 #endif
160 return DATA_UNKNOWN;
161 }
162 }
163
165 QString typeName(DataType _id) {
166
167 std::map<DataType, QString>::iterator name = typeToString.find(_id);
168
169 if ( name != typeToString.end() )
170 return name->second;
171 else {
172 #ifdef DEBUG
173 std::cerr << "Unable to retrieve typeName for id " << _id << std::endl;
174 #endif
175 return "Unknown";
176 }
177 }
178
180 bool typeExists( QString _name ) {
181 return ( stringToTypeInfo.find( _name ) != stringToTypeInfo.end() );
182 }
183
184
186 size_t typeCount() {
187 return types.size();
188 }
189
191 std::vector< TypeInfo >::const_iterator typesBegin() {
192 return types.begin();
193 }
194
196 std::vector< TypeInfo >::const_iterator typesEnd() {
197 return types.end();
198 }
199
201 QString typeIconName(QString _name) {
202
203 std::map<QString, size_t>::iterator index = stringToTypeInfo.find( _name );
204
205 if ( index != stringToTypeInfo.end() )
206 return types[ index->second ].iconName;
207 else
208 return "Unknown.png";
209 }
210
212 QString typeIconName(DataType _id) {
213
214 std::map<DataType, size_t>::iterator index = typeToTypeInfo.find(_id);
215
216 if ( index != typeToTypeInfo.end() )
217 return types[ index->second ].iconName;
218 else
219 return "Unknown.png";
220 }
221
223 QIcon& typeIcon(DataType _id) {
224
225 std::map<DataType, size_t>::iterator index = typeToTypeInfo.find(_id);
226
227 if ( index != typeToTypeInfo.end() )
228 return types[ index->second ].icon;
229 else
230 return dummyIcon;
231 }
232
234 void setTypeIcon( DataType _id , QString _icon ) {
235
236 if ( OpenFlipper::Options::gui() ) {
237 std::map<DataType, size_t>::iterator index = typeToTypeInfo.find(_id);
238
239 if ( index != typeToTypeInfo.end() ) {
240 types[ index->second ].iconName = _icon;
241 types[ index->second ].icon = QIcon( OpenFlipper::Options::iconDirStr() + QDir::separator() + _icon );
242 } else
243 std::cerr << "Could not set icon for DataType. Type not found!" << std::endl;
244 }
245 }
246
248 void setTypeIcon( QString _name , QString _icon ) {
249
250 if ( OpenFlipper::Options::gui() ) {
251 std::map<QString, size_t>::iterator index = stringToTypeInfo.find( _name );
252
253 if ( index != stringToTypeInfo.end() ) {
254 types[ index->second ].iconName = _icon;
255 types[ index->second ].icon = QIcon( OpenFlipper::Options::iconDirStr() + QDir::separator() + _icon );
256 } else
257 std::cerr << "Could not set icon for DataType. Type not found!" << std::endl;
258 }
259 }
260
261
263 QString dataTypeName( DataType _id ) {
264
265 std::map<DataType, size_t>::iterator index = typeToTypeInfo.find(_id);
266
267 if ( index != typeToTypeInfo.end() )
268 return types[ index->second ].readableName ;
269 else
270 std::cerr << "Could not get human name for DataType. Type not found!" << std::endl;
271
272 return QString(QCoreApplication::translate("Types","Unknown Type"));
273 }
274
276 QString dataTypeName( QString _typeName ) {
277
278 std::map<QString, size_t>::iterator index = stringToTypeInfo.find( _typeName );
279
280 if ( index != stringToTypeInfo.end() )
281 return types[ index->second ].readableName ;
282 else
283 std::cerr << "Could not get human name for DataType. Type not found!" << std::endl;
284
285 return QString(QCoreApplication::translate("Types","Unknown Type"));
286 }
287
288
289
291 void setDataTypeName( DataType _id , QString _name ) {
292
293 std::map<DataType, size_t>::iterator index = typeToTypeInfo.find(_id);
294
295 if ( index != typeToTypeInfo.end() )
296 types[ index->second ].readableName = _name;
297 else
298 std::cerr << "Could not set human name for DataType. Type not found!" << std::endl;
299 }
300
302 void setDataTypeName( QString _typeName , QString _name ) {
303
304 std::map<QString, size_t>::iterator index = stringToTypeInfo.find( _typeName );
305
306 if ( index != stringToTypeInfo.end() )
307 types[ index->second ].readableName = _name;
308 else
309 std::cerr << "Could not set human name for DataType. Type not found!" << std::endl;
310 }
311
312
313 DataType::DataType():
314 field(0)
315 {
316 };
317
318 DataType::DataType(const unsigned int& _i):
319 field(_i)
320 {
321 };
322
323 //===========================================
324
325 bool DataType::operator!=( const unsigned int& _i ) const{
326 return (_i != field);
327 }
328
329 bool DataType::operator!=( const DataType& _i ) const{
330 return (field != _i.field);
331 }
332
333 //===========================================
334
335 bool DataType::operator==( const unsigned int& _i ) const {
336 return (_i == field);
337 }
338
339 bool DataType::operator==( const DataType& _i ) const{
340 return (_i.field == field);
341 }
342
343 //===========================================
344
345 DataType& DataType::operator=( const unsigned int& _i ) {
346 field = _i;
347 return (*this);
348 }
349
350 DataType& DataType::operator=( const DataType& _i ) {
351 field = _i.field;
352 return (*this);
353 }
354
355 //===========================================
356
357 bool DataType::operator<( const unsigned int& _i ) const {
358 return (field < _i);
359 }
360
361 bool DataType::operator<( const DataType& _i ) const {
362 return (field < _i.field);
363 }
364
365 //===========================================
366
367 bool DataType::operator&( const unsigned int& _i ) const {
368 return (field & _i);
369 }
370
371 bool DataType::operator&( const DataType& _i ) const {
372 return (field & _i.field);
373 }
374
375 //===========================================
376
377 DataType DataType::operator!() {
378 DataType inv = (*this);
379 inv.field = !inv.field;
380 return inv;
381 }
382
383 //===========================================
384
385 bool DataType::contains( const DataType& _i )const{
386 //its not magic
387 return ( (_i.field & field) == _i.field);
388 }
389
390 //===========================================
391
392 DataType& DataType::operator|=( const unsigned int& _i ) {
393 field |= _i;
394 return (*this);
395 }
396
397 DataType& DataType::operator|=( const DataType& _i ) {
398 field |= _i.field ;
399 return (*this);
400 }
401
402 //===========================================
403
404 DataType DataType::operator|( const DataType& _i ) const {
405 return (field | _i.field);
406 }
407
408 //===========================================
409
410 DataType DataType::operator++(int /*_unused*/) {
411 return (field *= 2);
412 }
413
414 //===========================================
415
416 DataType& DataType::operator++() {
417 field *= 2;
418 return (*this);
419 }
420
421 //===========================================
422
423 unsigned int DataType::value() const {
424 return( field );
425 }
426
427 QString DataType::name() const {
428 return typeName(field);
429 }
430
431 //=============================================================================
432
433 void registerTypes() {
434 qRegisterMetaType<IdList>("IdList");
435 qRegisterMetaType<DataType>("DataType");
436 qRegisterMetaType< QVector< int > >("QVector<int>");
437 qRegisterMetaType<Vector>("Vector");
438 qRegisterMetaType<Vector4>("Vector4");
439 qRegisterMetaType<Matrix4x4>("Matrix4x4");
440 qRegisterMetaType<UpdateType>("UpdateType");
441 qRegisterMetaType<Logtype>("LogType");
442 }
443
444 //=============================================================================
445 //=============================================================================
registerTypes
void registerTypes()
Definition: Types.cc:433
DATA_UNKNOWN
const DataType DATA_UNKNOWN(0)
None of the other Objects.
typeIconName
QString typeIconName(QString _name)
Get the icon of a given dataType.
Definition: Types.cc:201
DATA_GROUP
const DataType DATA_GROUP(1)
Items used for Grouping.
typeExists
bool typeExists(QString _name)
Check if a type with the given name exists.
Definition: Types.cc:180
addDataType
DataType addDataType(QString _name, QString _readableName)
Adds a datatype and returns the id for the new type.
Definition: Types.cc:128
LoggingInterface.hh
dataTypeName
QString dataTypeName(DataType _id)
Get DataType Human readable name ( this name might change. Use the typeName insted! ) ...
Definition: Types.cc:263
typesBegin
std::vector< TypeInfo >::const_iterator typesBegin()
Get iterator pointing to the first element in the tyoes list.
Definition: Types.cc:191
test
Definition: minimalExecutionTest.cc:5
typeCount
size_t typeCount()
Return the number of registered types.
Definition: Types.cc:186
typeIcon
QIcon & typeIcon(DataType _id)
get the icon of a given dataType
Definition: Types.cc:223
setTypeIcon
void setTypeIcon(DataType _id, QString _icon)
Set the icon for a given dataType.
Definition: Types.cc:234
OpenMesh::Utils::Timer::operator<<
std::ostream & operator<<(std::ostream &_o, const Timer &_t)
Definition: Timer.hh:201
setDataTypeName
void setDataTypeName(DataType _id, QString _name)
Set the icon for a given dataType.
Definition: Types.cc:291
typeId
DataType typeId(QString _name)
Get the id of a type with given name.
Definition: Types.cc:150
DATA_ALL
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
GlobalOptions.hh
TypesInternal.hh
typesEnd
std::vector< TypeInfo >::const_iterator typesEnd()
Get iterator pointing to the last element in the tyoes list.
Definition: Types.cc:196
DataType::value
unsigned int value() const
Definition: Types.cc:423
TypeInfo
Definition: DataTypes.hh:142
DataType
Predefined datatypes.
Definition: DataTypes.hh:96
typeName
QString typeName(DataType _id)
Get the name of a type with given id.
Definition: Types.cc:165
DataType::name
QString name() const
Return the name of this type as text.
Definition: Types.cc:427