DataTypes.hh 11.1 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40 41 42
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
43 44 45 46 47
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
\*===========================================================================*/




//=============================================================================
//
//  Types
//
//=============================================================================

/**
 * \file DataTypes.hh
 * This File contains the basic type informations
 */


#ifndef DATATYPES_HH
#define DATATYPES_HH

//== includes =================================================================


#include <OpenFlipper/common/GlobalDefines.hh>
72
#include <OpenFlipper/common/UpdateType.hh>
73 74 75

#include <ACG/Math/Matrix4x4T.hh>
#include <ACG/Math/VectorT.hh>
76
#include <climits>
77 78 79 80 81 82 83 84 85 86 87
#include <QIcon>
#include <QMetaType>

//== Global Typedefs  =================================================================

/** \brief Predefined datatypes
*
* Here are several datatypes which have predefined ids. This might be changed to runtime added
* datatypes in the future.
*/

88 89
/** \brief the internal DataType class
*
90
* Normally we could use an unsigned int here. But QT can't register an
91 92
* typedef unsigned int DataType as DataType and will recognize it as unsigned int and
* therefore DataType will still be unknown to QtScript.
Jan Möbius's avatar
Jan Möbius committed
93
* To overcome this Problem, we reimplement a wrapper around the int and provide additional
94 95
* functionality such as returning the name of the type directly
*/ 
Jan Möbius's avatar
Jan Möbius committed
96
class DLLEXPORT DataType  {
97 98 99 100
  public:
    DataType();
    DataType(const unsigned int& _i);
    
101 102
    bool operator!=( const unsigned int& _i ) const;
    bool operator!=( const DataType& _i ) const;
103
    
104 105
    bool operator==( const unsigned int& _i ) const;
    bool operator==(  const DataType& _i ) const;
106
    
107 108
    DataType& operator=( const unsigned int& _i );
    DataType& operator=( const DataType& _i );
109
    
110
    bool operator<( const unsigned int& _i ) const;
111 112
    bool operator<( const DataType& _i ) const;
    
Jan Möbius's avatar
Jan Möbius committed
113 114
    DataType& operator|=( const unsigned int& _i );
    DataType& operator|=( const DataType& _i );    
Jan Möbius's avatar
Jan Möbius committed
115
    
116
    bool operator&( const unsigned int& _i ) const;
117
    bool operator&( const DataType& _i ) const;
118 119 120

    DataType operator!();
    
121
    bool contains( const DataType& _i ) const;
122
    
123 124
    DataType operator|( const DataType& _i ) const;

125 126 127 128
    DataType operator++(int _unused);

    DataType& operator++();

129 130 131 132 133 134 135
    /** return the internal representation of the type which is an unsigned int at the moment.
    *
    * You should avoid using this directly as the internal representation might change in the future
    */
    unsigned int value() const;
      
    /// Return the name of this type as text
136
    QString name() const;
137 138 139 140 141
 
  private:
    unsigned int field;
};

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
class TypeInfo {

  public:

  TypeInfo(DataType _type, QString _name, QString _iconName, QString _readableName ) :
    type(_type),
    name(_name),
    iconName(_iconName),
    readableName(_readableName)
  {
    // Use internal name if no external name is given
    if ( _readableName == "" )
      readableName = _name;
  }

  /// The id of the datatype
  DataType type;

  /// The name of the datatype
  QString  name;

  /// The icon of the datatype
  QString  iconName;

  QIcon    icon;

  /// Human readable name
  QString readableName;
};

172 173 174
/// Identifier for all available objects
const DataType DATA_ALL(UINT_MAX);

175
/// None of the other Objects
176
const DataType DATA_UNKNOWN(0);
177 178

/// Items used for Grouping
179
const DataType DATA_GROUP(1);
180

181
std::ostream &operator<<(std::ostream &stream, DataType type);
182 183 184 185 186 187


//== TYPEDEFS =================================================================

/// Standard Type for 3d Vector used for scripting
typedef ACG::Vec3d Vector;
188 189 190

/// Standard Type for 4d Vector used for scripting
typedef ACG::Vec4d Vector4;
191
/// Standard Type for id Lists used for scripting
Jan Möbius's avatar
Jan Möbius committed
192
typedef std::vector< int > IdList;
193 194 195
/// Standard Type for a 4x4 Matrix used for scripting
typedef ACG::Matrix4x4d Matrix4x4;

Mike Kremer's avatar
Mike Kremer committed
196 197 198 199
Q_DECLARE_METATYPE(IdList)
Q_DECLARE_METATYPE(DataType)
Q_DECLARE_METATYPE(QVector< int >)
Q_DECLARE_METATYPE(Vector)
200
Q_DECLARE_METATYPE(Vector4)
Mike Kremer's avatar
Mike Kremer committed
201
Q_DECLARE_METATYPE(Matrix4x4)
202 203 204 205 206 207 208
Q_DECLARE_METATYPE(UpdateType)

/** Registers datatypes on runtime for signal/slots
 *
 */
DLLEXPORT
void registerTypes();
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234

//================================================================================================
/** @name Functions for adding dataTypes
* @{ */
//================================================================================================

/** Adds a datatype and returns the id for the new type
*
* @param _name Internal name for the new DataType
* @param _readableName Human readable Name for this type ( Use tr to make it translatable )
*/
DLLEXPORT
DataType addDataType(QString _name, QString _readableName);

/// Given a dataType Identifier string this function will return the id of the datatype
DLLEXPORT
DataType typeId(QString _name);

/** \brief Get the name of a type with given id
*
* The ids are organized in a bitfield. So use either the macro for getting the type id or
* use the id directly (they have to be power of 2! ... Bitfield)
*/
DLLEXPORT
QString typeName(DataType _id);

235 236 237 238 239 240
/** \brief Check if a type with the given name exists
*
*/
DLLEXPORT
bool typeExists( QString _name );

241 242 243 244 245
/** \brief Get the number of registered types
*
* This function will return the number of types registered to the core. You can use it to
* iterate over all types. 
*
Jan Möbius's avatar
Jan Möbius committed
246
* \note Remember that the types are organized in a bitfield!
247 248
*/
DLLEXPORT 
249
size_t typeCount();
250 251 252

/** @} */

253 254 255 256 257
//================================================================================================
/** @name Type iterators
* @{ */
//================================================================================================

258
/// Get iterator pointing to the first element in the types list
259 260 261
DLLEXPORT
std::vector< TypeInfo >::const_iterator typesBegin();

262
/// Get iterator pointing to the last element in the types list
263 264 265 266 267
DLLEXPORT
std::vector< TypeInfo >::const_iterator typesEnd();

/** @} */

268 269 270 271 272
//================================================================================================
/** @name Datatype Name handling
* @{ */
//================================================================================================

273
/// Get DataType Human readable name ( this name might change. Use the typeName instead! )
274 275 276
DLLEXPORT
QString dataTypeName( DataType _id );

277
/// Get DataType Human readable name ( this name might change. Use the typeName instead! )
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
DLLEXPORT
QString dataTypeName( QString _typeName);

/// Set DataType Human readable name
DLLEXPORT
void setDataTypeName( DataType _id, QString _name );

/// Set DataType Human readable name
DLLEXPORT
void setDataTypeName( QString _typeName, QString _name );


/** @} */

//================================================================================================
/** @name Datatype Icons
* @{ */
//================================================================================================

/// Get a string with the filename of the icon for the DataType name
DLLEXPORT
QString typeIconName(QString  _name);

/// Get a string with the filename of the icon for the DataType
DLLEXPORT
QString typeIconName(DataType _id);

305
/** \brief Get an QIcon associated with the given DataType
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
* 
* The icons are loaded once when set and then the reference is returned here.
* This reduces the time when frequently requesting the icons (e.g. DataControl)
*/
DLLEXPORT
QIcon& typeIcon(DataType _id);

/// Set an Icon for a given DataType
DLLEXPORT
void setTypeIcon( DataType _id   , QString _icon);

/// Set an Icon for a given DataType
DLLEXPORT
void setTypeIcon( QString  _name , QString _icon );

/** @} */





//=============================================================================
#endif // DATATYPES_HH defined
//=============================================================================