Developer Documentation
OVMPropertyModel.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 #ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
51 
52 #ifndef OVM_PROPERTY_MODEL_H
53 #define OVM_PROPERTY_MODEL_H
54 
55 #include "SingleObjectPropertyModel.hh"
56 #include "OVMPropertyVisualizer.hh"
57 #include "OVMPropertyVisualizerBoolean.hh"
58 #include "OVMPropertyVisualizerDouble.hh"
59 #include "OVMPropertyVisualizerInteger.hh"
60 #include "OVMPropertyVisualizerVector.hh"
61 #include "OVMPropertyVisualizerVectorFieldDifference.hh"
62 
63 #include "../Utils.hh"
64 #include <OpenVolumeMesh/Core/BaseProperty.hh>
65 
66 #include "Widgets/LoadSaveWidget.hh"
67 #include "Widgets/PickWidget.hh"
68 
69 #include <vector>
70 
71 #include "../Utils.hh"
72 
73 #define PROP_VIS "PropertyVisualization"
74 
75 class PropertyVisPlugin;
76 
77 /* This class adds signal/slot support for OVMPropertyModelSubclass. This needs
78  * to be done because "Sorry, Qt does not support templates that contain signals,
79  * slots or Q_OBJECT"
80  * http://doc.trolltech.com/qq/qq15-academic.html
81  */
82 class OVMPropertyModelSubclass: public SingleObjectPropertyModel
83 {
84 Q_OBJECT
85 public:
86  OVMPropertyModelSubclass(QObject *parent = 0)
88  {
89  }
90 
91 public slots:
92  virtual void slotCombine(){ combine(); }
93  virtual void slotSaveProperty(){ saveProperty(); }
94  virtual void slotLoadProperty(){ loadProperty(); }
95  virtual void slotPickProperty(){ pickProperty(); }
96 
97 private:
98  virtual void combine(){}
99  virtual void saveProperty(){}
100  virtual void pickProperty(){}
101 
102 };
103 
104 template<typename MeshT>
105 class OVMPropertyModel: public OVMPropertyModelSubclass {
106 
107 public:
108  OVMPropertyModel(MeshT* mesh, int objectID, QObject *parent = 0);
109  virtual ~OVMPropertyModel(){}
110 
111  virtual void updateWidget(const QModelIndexList& selectedIndices);
112 
114  void resetPicking();
115 
117  virtual void pickProperty();
118 
120  virtual void pickModeChanged(const std::string& _mode);
121 
123  virtual void mouseEvent(QMouseEvent* _event);
124 
125  virtual bool parseHeader(QString header, PropertyVisualizer*& propVis, unsigned int& n);
126 
127  static bool isBoolType(const PropertyInfo& propInfo);
128  static bool isBoolType(const TypeInfoWrapper& typeInfo);
129  static bool isIntType(const PropertyInfo& propInfo);
130  static bool isIntType(const TypeInfoWrapper& typeInfo);
131  static bool isDoubleType(const PropertyInfo& propInfo);
132  static bool isDoubleType(const TypeInfoWrapper& typeInfo);
133  static bool isUnsignedIntType(const PropertyInfo& propInfo);
134  static bool isUnsignedIntType(const TypeInfoWrapper& typeInfo);
135  static bool isVec3dType(const PropertyInfo& propInfo);
136  static bool isVec3dType(const TypeInfoWrapper& typeInfo);
137  static bool isVec3fType(const PropertyInfo& propInfo);
138  static bool isVec3fType(const TypeInfoWrapper& typeInfo);
139  static bool isVectorType(const PropertyInfo& propInfo);
140  static bool isVectorType(const TypeInfoWrapper& typeInfo);
141 
142 #define DECLARE_PROPTYPES(primitive) \
143  static const TypeInfoWrapper proptype_##primitive##_bool; \
144  static const TypeInfoWrapper proptype_##primitive##_int; \
145  static const TypeInfoWrapper proptype_##primitive##_uint; \
146  static const TypeInfoWrapper proptype_##primitive##_double; \
147  static const TypeInfoWrapper proptype_##primitive##_Vec3d; \
148  static const TypeInfoWrapper proptype_##primitive##_Vec3f;
149 
150  DECLARE_PROPTYPES(Cell)
151  DECLARE_PROPTYPES(Face)
152  DECLARE_PROPTYPES(HalfFace)
153  DECLARE_PROPTYPES(Edge)
154  DECLARE_PROPTYPES(HalfEdge)
155  DECLARE_PROPTYPES(Vertex)
156 #undef DECLARE_PROPTYPES
157 
158 protected:
159 
160  virtual QString getLoadFilenameFilter();
161  virtual QString getSaveFilenameFilter(unsigned int propId);
162 
163 private:
164 
166  virtual void combine();
167 
169  bool combinable(PropertyVisualizer* propertyVisualizer1, PropertyVisualizer* propertyVisualizer2) const;
170 
172  virtual void saveProperty();
173 
175  void gatherProperties( MeshT* mesh,
176  typename MeshT::Properties::const_iterator props_first,
177  typename MeshT::Properties::const_iterator props_last,
178  PropertyInfo::ENTITY_FILTER filter);
180  void gatherProperties();
181 
183  bool isSupported(OpenVolumeMesh::BaseProperty* const baseProp) const;
184 
186  bool isSupported(QString friendlyName) const;
187 
189  bool isNew(OpenVolumeMesh::BaseProperty* const baseProp, PropertyInfo::ENTITY_FILTER filter) const;
190 
192  bool isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo);
193 
195  TypeInfoWrapper getSupportedTypeInfoWrapper(OpenVolumeMesh::BaseProperty* const baseProp) const;
196 
198  TypeInfoWrapper getSupportedTypeInfoWrapper(QString friendlyName, PropertyInfo::ENTITY_FILTER filter) const;
199 
200  bool isEntityType(const TypeInfoWrapper& typeInfo, PropertyInfo::ENTITY_FILTER entity_type) const;
201 
203  void addPropertyVisualizer(OpenVolumeMesh::BaseProperty* const baseProp, MeshT* mesh, PropertyInfo::ENTITY_FILTER filter);
204 
206  void addProperty(QString propName, QString friendlyTypeName, PropertyInfo::ENTITY_FILTER filter);
207 
208  void initializeSupportedPropertyTypes();
209 
210  MeshT* mesh_;
211 
212  int objectID_;
213 
214  QPushButton bCombine;
215  const PropertyInfo* mCombineProperty1;
216  const PropertyInfo* mCombineProperty2;
217 
218  LoadSaveWidget mLoadSaveWidget;
219 
220  PickWidget mPickWidget;
221 
222  bool pickModeActive;
223  std::string lastPickMode;
224  Viewer::ActionMode lastActionMode;
225 
226  typedef std::set<TypeInfoWrapper> TypeInfoWrapperSet;
227  TypeInfoWrapperSet supportedPropertyTypes;
228 
229 };
230 
231 #define INITIALIZE_PROPTYPES(primitive) \
232 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_bool \
233  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<bool>), "bool"); \
234 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_int \
235  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<int>), "int"); \
236 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_uint \
237  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<unsigned int>), "unsigned int"); \
238 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_double \
239  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<double>), "double"); \
240 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_Vec3d \
241  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<ACG::Vec3d>), "Vec3d"); \
242 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_Vec3f \
243  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<ACG::Vec3f>), "Vec3f");
244 
245 INITIALIZE_PROPTYPES(Cell)
246 INITIALIZE_PROPTYPES(Face)
247 INITIALIZE_PROPTYPES(HalfFace)
248 INITIALIZE_PROPTYPES(Edge)
249 INITIALIZE_PROPTYPES(HalfEdge)
250 INITIALIZE_PROPTYPES(Vertex)
251 
252 #undef INITIALIZE_PROPTYPES
253 
254 
255 #if defined(INCLUDE_TEMPLATES) && !defined(OVM_PROPERTY_MODEL_CC)
256 #include "OVMPropertyModelT.cc"
257 #endif
258 
259 #endif /* OVM_PROPERTY_MODEL_H */
260 
261 #endif /* ENABLE_OPENVOLUMEMESH_SUPPORT */
Cellection of information about a property.
Definition: Utils.hh:115
This class vizualizes a property.
ActionMode
Enum listing action modes of the viewers.
void saveProperty(unsigned int propId)
Saves property.
Wraps the information of a type.
Definition: Utils.hh:79
This class manages the visualizers for a single object.