Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
UpdateType.cc
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 #include "TypesInternal.hh"
51 #include "UpdateType.hh"
52 #include <QCoreApplication>
54 
55 
58 static std::map< UpdateType, QString > updateTypeToString;
59 
62 static std::map< QString , size_t > stringToUpdateTypeInfo;
63 
66 static std::map< UpdateType , size_t > updateTypeToTypeInfo;
67 
70 static UpdateType firstFreeID_(UPDATE_UNUSED);
71 
72 UpdateType::UpdateType()
73 :type_(0)
74 {
75 
76 }
77 
78 UpdateType::UpdateType(const UpdateType& _type)
79 :type_(_type.type_)
80 {
81 
82 }
83 
84 UpdateType::UpdateType(UpdateTypeSet _set)
85 : type_(_set)
86 {
87 
88 }
89 
90 bool UpdateType::operator==(const UpdateType& _type) const {
91  return ((type_ & _type.type_).any());
92 };
93 
95 UpdateType::operator|(const UpdateType& _type) const
96 {
97  return (type_ | _type.type_);
98 }
99 
100 
101 UpdateType&
102 UpdateType::operator|=(const UpdateType& _type)
103 {
104  type_ |= _type.type_;
105 
106  return(*this);
107 }
108 
109 
111 bool UpdateType::contains( const UpdateType& _type ) const {
112 
113  if ( type_ == UPDATE_ALL.type_ )
114  return true;
115 
116  // Catch the specialization of updates
117  if ( _type == UPDATE_SELECTION ) {
118  if ( type_ == UPDATE_SELECTION_VERTICES.type_ || type_ == UPDATE_SELECTION_EDGES.type_ || type_ == UPDATE_SELECTION_HALFEDGES.type_ || type_ == UPDATE_SELECTION_FACES.type_ || type_ == UPDATE_SELECTION_KNOTS.type_ )
119  return true;
120  }
121 
122  return ((type_ & _type.type_).any());
123 }
124 
125 UpdateType& UpdateType::operator++() {
126  if ( type_.count() != 1 ) {
127  std::cerr << "Operator ++ for UpdateType which is not atomic!!" << std::endl;
128  }
129 
130  type_ <<= 1;
131 
132  return (*this);
133 }
134 
135 bool UpdateType::operator<( const UpdateType& _i ) const {
136  return (type_.to_ulong() < _i.type_.to_ulong());
137 }
138 
140 
141  public:
142 
143  UpdateTypeInfo(UpdateType _type, QString _name, bool _needsScenegraphReset ) :
144  type(_type),
145  name(_name),
146  resetNeeded(_needsScenegraphReset)
147  {
148  }
149 
152 
154  QString name;
155 
158 };
159 
160 static std::vector< UpdateTypeInfo > updateTypes;
161 
162 
163 // functions -------------------------------------------------
164 
165 
166 void initializeUpdateTypes() {
167 
168  stringToUpdateTypeInfo["All"] = updateTypes.size();
169  updateTypeToTypeInfo[UPDATE_ALL] = updateTypes.size();
170  updateTypes.push_back( UpdateTypeInfo(UPDATE_ALL, "All", true) );
171 
172  stringToUpdateTypeInfo["Visibility"] = updateTypes.size();
173  updateTypeToTypeInfo[UPDATE_VISIBILITY] = updateTypes.size();
174  updateTypes.push_back( UpdateTypeInfo(UPDATE_VISIBILITY, "Visibility", true) );
175 
176  stringToUpdateTypeInfo["Geometry"] = updateTypes.size();
177  updateTypeToTypeInfo[UPDATE_GEOMETRY] = updateTypes.size();
178  updateTypes.push_back( UpdateTypeInfo(UPDATE_GEOMETRY, "Geometry", true) );
179 
180  stringToUpdateTypeInfo["Topology"] = updateTypes.size();
181  updateTypeToTypeInfo[UPDATE_TOPOLOGY] = updateTypes.size();
182  updateTypes.push_back( UpdateTypeInfo(UPDATE_TOPOLOGY, "Topology", true) );
183 
184  stringToUpdateTypeInfo["Selection"] = updateTypes.size();
185  updateTypeToTypeInfo[UPDATE_SELECTION] = updateTypes.size();
186  updateTypes.push_back( UpdateTypeInfo(UPDATE_SELECTION, "Selection", true) );
187 
188  stringToUpdateTypeInfo["VertexSelection"] = updateTypes.size();
189  updateTypeToTypeInfo[UPDATE_SELECTION_VERTICES] = updateTypes.size();
190  updateTypes.push_back( UpdateTypeInfo(UPDATE_SELECTION_VERTICES, "VertexSelection", true) );
191 
192  stringToUpdateTypeInfo["EdgeSelection"] = updateTypes.size();
193  updateTypeToTypeInfo[UPDATE_SELECTION_EDGES] = updateTypes.size();
194  updateTypes.push_back( UpdateTypeInfo(UPDATE_SELECTION_EDGES, "EdgeSelection", true) );
195 
196  stringToUpdateTypeInfo["HalfedgeSelection"] = updateTypes.size();
197  updateTypeToTypeInfo[UPDATE_SELECTION_HALFEDGES] = updateTypes.size();
198  updateTypes.push_back( UpdateTypeInfo(UPDATE_SELECTION_HALFEDGES, "HalfedgeSelection", true) );
199 
200  stringToUpdateTypeInfo["FaceSelection"] = updateTypes.size();
201  updateTypeToTypeInfo[UPDATE_SELECTION_FACES] = updateTypes.size();
202  updateTypes.push_back( UpdateTypeInfo(UPDATE_SELECTION_FACES, "FaceSelection", true) );
203 
204  stringToUpdateTypeInfo["KnotSelection"] = updateTypes.size();
205  updateTypeToTypeInfo[UPDATE_SELECTION_KNOTS] = updateTypes.size();
206  updateTypes.push_back( UpdateTypeInfo(UPDATE_SELECTION_KNOTS, "KnotSelection", true) );
207 
208  stringToUpdateTypeInfo["Color"] = updateTypes.size();
209  updateTypeToTypeInfo[UPDATE_COLOR] = updateTypes.size();
210  updateTypes.push_back( UpdateTypeInfo(UPDATE_COLOR, "Color", true) );
211 
212  stringToUpdateTypeInfo["Texture"] = updateTypes.size();
213  updateTypeToTypeInfo[UPDATE_TEXTURE] = updateTypes.size();
214  updateTypes.push_back( UpdateTypeInfo(UPDATE_TEXTURE, "Texture", true) );
215 
216  stringToUpdateTypeInfo["State"] = updateTypes.size();
217  updateTypeToTypeInfo[UPDATE_STATE] = updateTypes.size();
218  updateTypes.push_back( UpdateTypeInfo(UPDATE_STATE, "State", true) );
219 
220  updateTypeToString[UPDATE_ALL] = "All";
221  updateTypeToString[UPDATE_VISIBILITY] = "Visibility";
222  updateTypeToString[UPDATE_GEOMETRY] = "Geometry";
223  updateTypeToString[UPDATE_TOPOLOGY] = "Topology";
224  updateTypeToString[UPDATE_SELECTION] = "Selection";
225  updateTypeToString[UPDATE_SELECTION_VERTICES] = "VertexSelection";
226  updateTypeToString[UPDATE_SELECTION_EDGES] = "EdgeSelection";
227  updateTypeToString[UPDATE_SELECTION_HALFEDGES]= "HalfedgeSelection";
228  updateTypeToString[UPDATE_SELECTION_FACES] = "FaceSelection";
229  updateTypeToString[UPDATE_SELECTION_KNOTS] = "KnotSelection";
230  updateTypeToString[UPDATE_COLOR] = "Color";
231  updateTypeToString[UPDATE_TEXTURE] = "Texture";
232  updateTypeToString[UPDATE_STATE] = "State";
233 }
234 
236 UpdateType addUpdateType(QString _name, bool _resetNeeded) {
237 
238  //first check if it's already available
239  std::map<QString, size_t>::iterator index = stringToUpdateTypeInfo.find( _name );
240 
241  if ( index != stringToUpdateTypeInfo.end() )
242  return updateTypes[ index->second ].type;
243  else {
244 
245  UpdateType type = firstFreeID_;
246 
247  stringToUpdateTypeInfo[ _name ] = updateTypes.size();
248  updateTypeToTypeInfo[ type ] = updateTypes.size();
249  updateTypes.push_back( UpdateTypeInfo(type, _name, _resetNeeded ) );
250 
251  updateTypeToString[type] = _name;
252 
253  ++firstFreeID_;
254  return( type );
255  }
256 }
257 
259 UpdateType updateType(QString _name) {
260 
261  std::map<QString, size_t>::iterator index = stringToUpdateTypeInfo.find( _name );
262 
263  if ( index != stringToUpdateTypeInfo.end() )
264  return updateTypes[ index->second ].type;
265  else {
266  #ifdef DEBUG
267  std::cerr << "Unknown UpdateType with name " << _name.toStdString() << std::endl;
268  #endif
269  return UPDATE_ALL;
270  }
271 }
272 
275 
276  std::map<UpdateType, QString>::iterator name = updateTypeToString.find(_id);
277 
278  if ( name != updateTypeToString.end() )
279  return name->second;
280  else {
281  #ifdef DEBUG
282  std::cerr << "Unable to retrieve updateTypeName" << std::endl;
283  #endif
284  return "Unknown";
285  }
286 }
287 
289 size_t updateTypeCount() {
290  return updateTypes.size();
291 }
QString name
The name of the UpdateType.
Definition: UpdateType.cc:154
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
const UpdateType UPDATE_SELECTION_VERTICES(UpdateTypeSet(1)<< 5)
Vertex selection has changed.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
Definition: UpdateType.cc:111
Update type class.
Definition: UpdateType.hh:70
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
UpdateType addUpdateType(QString _name, bool _resetNeeded)
Adds a updateType and returns the id for the new type.
Definition: UpdateType.cc:236
bool operator==(const UpdateType &_type) const
Exact compare operator.
Definition: UpdateType.cc:90
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
UpdateType type
The id of the UpdateType.
Definition: UpdateType.cc:151
bool resetNeeded
is a sceneGraph reset needed for this update
Definition: UpdateType.cc:157
const UpdateType UPDATE_STATE(UpdateTypeSet(1)<< 12)
State has changed.
const UpdateType UPDATE_UNUSED(UpdateTypeSet(1)<< 13)
marks the last used ID
const UpdateType UPDATE_TEXTURE(UpdateTypeSet(1)<< 11)
Textures have changed.
const UpdateType UPDATE_SELECTION_EDGES(UpdateTypeSet(1)<< 6)
Edge selection has changed.
const UpdateType UPDATE_TOPOLOGY(UpdateTypeSet(1)<< 3)
Topology updated.
const UpdateType UPDATE_SELECTION_KNOTS(UpdateTypeSet(1)<< 9)
Knot selection has changed.
const UpdateType UPDATE_SELECTION_HALFEDGES(UpdateTypeSet(1)<< 7)
Halfedge selection has changed.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
UpdateType updateType(QString _name)
Get the id of a type with given name.
Definition: UpdateType.cc:259
QString updateTypeName(UpdateType _id)
Get the name of a type with given id.
Definition: UpdateType.cc:274
size_t updateTypeCount()
Return the number of registered types.
Definition: UpdateType.cc:289
const UpdateType UPDATE_VISIBILITY(UpdateTypeSet(1)<< 1)
This is the update identifier for global Object visibility ( show/hide )
const UpdateType UPDATE_SELECTION_FACES(UpdateTypeSet(1)<< 8)
Face selection has changed.