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