UpdateType.hh 8.14 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 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
*                                                                            *
\*===========================================================================*/

Jan Möbius's avatar
Jan Möbius committed
42
#pragma once
43

Jan Möbius's avatar
Jan Möbius committed
44
#include <OpenFlipper/common/GlobalDefines.hh>
45
#include <QString>
46

47
typedef uint64_t UpdateTypeSet;
48

49 50 51 52 53 54 55 56 57 58
/** \brief Update type class
 *
 *
 *  This class is used to specify the scope of updates. There are update types for
 *  selection,geometry,topology,colors,... specified here: \ref DefaultUpdateTypes
 *
 *  You can also find functions to add custom update types at runtime at
 *  \ref UpdateTypeFunctions
 *
 */
Jan Möbius's avatar
Jan Möbius committed
59
class DLLEXPORT UpdateType {
Jan Möbius's avatar
Jan Möbius committed
60
  public:
61 62
    UpdateType();

63
    UpdateType(const UpdateType& _type) = default;
Jan Möbius's avatar
Jan Möbius committed
64
    
65
    explicit UpdateType(const UpdateTypeSet& _set);
Jan Möbius's avatar
Jan Möbius committed
66 67 68
    
    /// Exact compare operator
    bool operator==(const UpdateType& _type) const;
69 70 71 72

    UpdateType operator|(const UpdateType& _type) const;

    UpdateType& operator|=(const UpdateType& _type);
Jan Möbius's avatar
Jan Möbius committed
73 74 75 76 77 78
    
    UpdateType& operator++();
    
    bool operator<( const UpdateType& _i ) const;
    
    /// Check if this update contains the given UpdateType
79
    bool contains( const UpdateType& _type ) const;
Jan Möbius's avatar
Jan Möbius committed
80
    
81 82 83 84
//    friend std::ostream &operator<< (
//            std::ostream &os, const UpdateType &type) {
//        return os << type.type_;
//    }
85

86
  private:
Jan Möbius's avatar
Jan Möbius committed
87 88
    UpdateTypeSet type_;
};
89

90 91 92 93 94 95
/** \defgroup DefaultUpdateTypes Default update types
 * The following update types are predefined for the general use cases
 * @{
 *
 */

96 97 98
/// Empty update for empty initialization of update type
const UpdateType UPDATE_NONE( UpdateTypeSet(0)  );

99
/// Identifier for all updates
Jan Möbius's avatar
Jan Möbius committed
100 101
const UpdateType UPDATE_ALL(              UpdateTypeSet(1)       );

102
/// This is the update identifier for global Object visibility ( show/hide )
103
const UpdateType UPDATE_VISIBILITY(       UpdateTypeSet(2) );
Jan Möbius's avatar
Jan Möbius committed
104 105 106 107 108 109 110


/** \brief Geometry updated
*
* Updated Geometry ( This update type has to be used if you only modify vertex positions of 
* an object. Everything else has to stay as before the update.
*/
111
const UpdateType UPDATE_GEOMETRY( UpdateTypeSet(4) );
Jan Möbius's avatar
Jan Möbius committed
112 113 114 115 116 117

/** \brief Topology updated
*
* Updated Topology ( This update type has to be used if you modify the topology
* of an object. This includes adding vertices or removing them! )
*/
118
const UpdateType UPDATE_TOPOLOGY( UpdateTypeSet(8) );
Jan Möbius's avatar
Jan Möbius committed
119 120 121 122 123 124 125


/** \brief Selection updated
*
* Updated Selection ( This update type has to be used if you modify the internal
* selection of an object. Like selecting a single vertex or a set of faces. ). 
*/
126
const UpdateType UPDATE_SELECTION( UpdateTypeSet(16) );
Jan Möbius's avatar
Jan Möbius committed
127 128 129 130 131

/** \brief Vertex selection has changed
*
* This is a more fine grained selection update. UPDATE_SELECTION will also match this update type.
*/
132
const UpdateType UPDATE_SELECTION_VERTICES( UpdateTypeSet(32) );
Jan Möbius's avatar
Jan Möbius committed
133 134 135 136 137 138


/** \brief Edge selection has changed
*
* This is a more fine grained selection update. UPDATE_SELECTION will also match this update type.
*/
139
const UpdateType UPDATE_SELECTION_EDGES( UpdateTypeSet(64) );
Jan Möbius's avatar
Jan Möbius committed
140

141

142
/** \brief Halfedge selection has changed
143 144 145
*
* This is a more fine grained selection update. UPDATE_SELECTION will also match this update type.
*/
146
const UpdateType UPDATE_SELECTION_HALFEDGES( UpdateTypeSet(128) );
147

Jan Möbius's avatar
Jan Möbius committed
148 149 150 151
/** \brief Face selection has changed
*
* This is a more fine grained selection update. UPDATE_SELECTION will also match this update type.
*/
152
const UpdateType UPDATE_SELECTION_FACES( UpdateTypeSet(256) );
153

154 155 156 157
/** \brief Knot selection has changed
*
* This is a more fine grained selection update. UPDATE_SELECTION will also match this update type.
*/
158
const UpdateType UPDATE_SELECTION_KNOTS( UpdateTypeSet(512) );
159

160 161 162 163
/** \brief Colors have changed
*
* Update the colors. This does not have to be called when topology is also updated
*/
164
const UpdateType UPDATE_COLOR( UpdateTypeSet(1024) );
165

166 167 168 169
/** \brief Textures have changed
*
* Update the Textures.
*/
170
const UpdateType UPDATE_TEXTURE( UpdateTypeSet(2048) );
171

172 173 174 175
/** \brief State has changed
*
* The object's state (target, source) has changed
*/
176
const UpdateType UPDATE_STATE( UpdateTypeSet(4096) );
177

Jan Möbius's avatar
Jan Möbius committed
178
/// marks the last used ID
179
const UpdateType UPDATE_UNUSED ( UpdateTypeSet(8192) );
180

181 182
/**@}*/

Jan Möbius's avatar
Jan Möbius committed
183
//=====================================================================================
184
// FUNCTIONS
Jan Möbius's avatar
Jan Möbius committed
185
//=====================================================================================
186

187 188 189 190 191 192 193

/** \defgroup UpdateTypeFunctions Runtime Update Types
 * Use these functions to add custom update types at runtime.
 * @{
 *
 */

194
/** Adds a UpdateType and returns the id for the new type
195
*
196 197
* @param _name Internal name for the new UpdateType
* @param _resetNeeded If a sceneGraph reset is needed for this update
198 199
*/
DLLEXPORT
200
UpdateType addUpdateType(QString _name, bool _resetNeeded = true);
201

202
/// Given an UpdateType Identifier string this function will return the id of the UpdateType
203 204 205 206 207
DLLEXPORT
UpdateType updateType(QString _name);

/** \brief Get the name of a type with given id
*
208 209
* The ids are organized in a bit field. So use either the macro for getting the type id or
* use the id directly (they have to be power of 2! ... Bit field)
210 211 212 213 214 215 216 217 218 219
*/
DLLEXPORT
QString updateTypeName(UpdateType _id);

/** \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. 
*/
DLLEXPORT 
220
size_t updateTypeCount();
221

222
/**@}*/
223

Jan Möbius's avatar
Jan Möbius committed
224