Developer Documentation
Utils.hh
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#ifndef UTILS_H
45#define UTILS_H
46
47#include <vector>
48#include <iostream>
49#include <set>
50#include <typeinfo>
51
52#include <QObject>
53#include <QMessageBox>
54
57
58#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
60#endif
61
62#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
64#endif
65
74 public:
75 TypeInfoWrapper(const std::type_info & ti, const char *friendlyName) : ti(&ti), friendlyName(friendlyName) {}
76 TypeInfoWrapper(const std::type_info & ti) : ti(&ti),friendlyName("") {}
77
78 operator const std::type_info *() const { return ti; }
79 operator const std::type_info &() const { return *ti; }
80 operator const char *() const { return friendlyName; }
81
82 const std::type_info *operator->() const { return ti; }
83 const std::type_info &get() const { return *ti; }
84 const char *getName() const { return friendlyName; }
85
86 bool operator==(const TypeInfoWrapper & other) const {
87 /*
88 * We compare name strings, not the type ids themselves because
89 * the same type from different SOs will give different type ids.
90 */
91 return strcmp(ti->name(), other.ti->name()) == 0;
92 }
93
94 bool operator<(const TypeInfoWrapper & other) const {
95 return strcmp(ti->name(), other.ti->name()) < 0;
96 }
97
98 private:
99 const std::type_info *ti;
100 const char *friendlyName;
101};
102
110 public:
111 enum ENTITY_FILTER {
112 EF_ANY = 0xFF,
113 EF_FACE = 0x01,
114 EF_EDGE = 0x02,
115 EF_HALFEDGE = 0x04,
116 EF_VERTEX = 0x08,
117 EF_HALFFACE = 0x10,
118 EF_CELL = 0x20
119 };
120
122 static const char* entity2str(ENTITY_FILTER entity);
123
124 PropertyInfo(const std::string &propName, const TypeInfoWrapper &typeinfo, ENTITY_FILTER entity) :
125 propName_(propName), typeinfo_(typeinfo), entity(entity) {}
126
127 QString toString() const {
128 return QObject::tr("%3 %1 : %2").arg(propName_.c_str()).arg(friendlyTypeName()).arg(QString::fromUtf8(entity2str(entity)));
129 }
130
131 bool operator==(const PropertyInfo &rhs) const {
132 return propName_ == rhs.propName_ && typeinfo_ == rhs.typeinfo_ && entity == rhs.entity;
133 }
134
135 bool operator<(const PropertyInfo &rhs) const {
136 if (entity != rhs.entity) return entity < rhs.entity;
137
138 int result = propName_.compare(rhs.propName_);
139 if (result) return result < 0;
140
141 return typeinfo_ < rhs.typeinfo_;
142 }
143
144 inline bool isCellProp() const { return entity == EF_CELL; }
145 inline bool isFaceProp() const { return entity == EF_FACE; }
146 inline bool isHalffaceProp() const { return entity == EF_HALFFACE; }
147 inline bool isEdgeProp() const { return entity == EF_EDGE; }
148 inline bool isHalfedgeProp() const { return entity == EF_HALFEDGE; }
149 inline bool isVertexProp() const { return entity == EF_VERTEX; }
150
151 inline const std::string &propName() const { return propName_; }
152 inline const char *friendlyTypeName() const { return typeinfo_.getName(); }
153 inline const TypeInfoWrapper &typeinfo() const { return typeinfo_; }
154 inline ENTITY_FILTER entityType() const { return entity; }
155
156 private:
157 std::string propName_;
158 TypeInfoWrapper typeinfo_;
159 ENTITY_FILTER entity;
160};
161
162
170class NewNameMessageBox: public QMessageBox
171{
172 Q_OBJECT
173
174public:
175 explicit NewNameMessageBox(QString propName);
176
177private slots:
178 void slotReplace() { replace = true; }
179 void slotRename() { rename = true; }
180 void slotCancel() { cancel = true; }
181
182private:
183 QLabel* problemDescription;
184
185 QPushButton* buttonRename;
186 QPushButton* buttonReplace;
187 QPushButton* buttonCancel;
188
189 QString propName;
190
191public:
192 bool replace;
193 bool rename;
194 bool cancel;
195
196};
197
198static inline DataType supportedDataTypes()
199{
201
202 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT
204 #endif
205
206 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
208 #endif
209
210 return res;
211}
212
213#endif /* UTILS_H */
#define DATA_HEXAHEDRAL_MESH
#define DATA_POLYHEDRAL_MESH
#define DATA_POLY_MESH
Definition: PolyMesh.hh:59
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:60
Predefined datatypes.
Definition: DataTypes.hh:83
Asks the user how to proceed after a name clash.
Definition: Utils.hh:171
Cellection of information about a property.
Definition: Utils.hh:109
static const char * entity2str(ENTITY_FILTER entity)
Returns a symbol representation for an entity.
Definition: Utils.cc:48
Wraps the information of a type.
Definition: Utils.hh:73