Developer Documentation
OVMPropertyModelT.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 OVM_PROPERTY_MODEL_H
45 #define OVM_PROPERTY_MODEL_H
46 
47 #include "OVMPropertyVisualizer.hh"
48 #include "OVMPropertyVisualizerBoolean.hh"
49 #include "OVMPropertyVisualizerDouble.hh"
50 #include "OVMPropertyVisualizerInteger.hh"
51 #include "OVMPropertyVisualizerMatrix3x3.hh"
52 #include "OVMPropertyVisualizerVector.hh"
53 #include "OVMPropertyVisualizerVectorFieldDifference.hh"
54 
55 #include "../Utils.hh"
56 #include <OpenVolumeMesh/Core/BaseProperty.hh>
57 
58 #include "Widgets/LoadSaveWidget.hh"
59 #include "Widgets/PickWidget.hh"
60 
61 #include <vector>
62 
63 #include "../Utils.hh"
64 
65 #define PROP_VIS "PropertyVisualization"
66 
67 #include "OVMPropertyModelSubclass.hh"
68 
69 class PropertyVisPlugin;
70 
71 template<typename MeshT>
73 
74 public:
75  OVMPropertyModel(MeshT* mesh, int objectID, QObject *parent = 0);
76  virtual ~OVMPropertyModel(){}
77 
78  virtual void updateWidget(const QModelIndexList& selectedIndices);
79 
81  void resetPicking();
82 
84  virtual void pickProperty();
85 
87  virtual void pickModeChanged(const std::string& _mode);
88 
90  virtual void mouseEvent(QMouseEvent* _event);
91 
92  virtual bool parseHeader(QString header, PropertyVisualizer*& propVis, unsigned int& n);
93 
94  static bool isBoolType(const PropertyInfo& propInfo);
95  static bool isBoolType(const TypeInfoWrapper& typeInfo);
96  static bool isIntType(const PropertyInfo& propInfo);
97  static bool isIntType(const TypeInfoWrapper& typeInfo);
98  static bool isDoubleType(const PropertyInfo& propInfo);
99  static bool isDoubleType(const TypeInfoWrapper& typeInfo);
100  static bool isUnsignedIntType(const PropertyInfo& propInfo);
101  static bool isUnsignedIntType(const TypeInfoWrapper& typeInfo);
102  static bool isVec3dType(const PropertyInfo& propInfo);
103  static bool isVec3dType(const TypeInfoWrapper& typeInfo);
104  static bool isVec3fType(const PropertyInfo& propInfo);
105  static bool isVec3fType(const TypeInfoWrapper& typeInfo);
106  static bool isVectorType(const PropertyInfo& propInfo);
107  static bool isVectorType(const TypeInfoWrapper& typeInfo);
108  static bool isMatrix3x3Type(const PropertyInfo& propInfo);
109  static bool isMatrix3x3Type(const TypeInfoWrapper& typeInfo);
110 
111 #define DECLARE_PROPTYPES(primitive) \
112  static const TypeInfoWrapper proptype_##primitive##_bool; \
113  static const TypeInfoWrapper proptype_##primitive##_int; \
114  static const TypeInfoWrapper proptype_##primitive##_uint; \
115  static const TypeInfoWrapper proptype_##primitive##_double; \
116  static const TypeInfoWrapper proptype_##primitive##_Vec3d; \
117  static const TypeInfoWrapper proptype_##primitive##_Vec3f; \
118  static const TypeInfoWrapper proptype_##primitive##_Matrix3x3d;
119 
120  DECLARE_PROPTYPES(Cell)
121  DECLARE_PROPTYPES(Face)
122  DECLARE_PROPTYPES(HalfFace)
123  DECLARE_PROPTYPES(Edge)
124  DECLARE_PROPTYPES(HalfEdge)
125  DECLARE_PROPTYPES(Vertex)
126 #undef DECLARE_PROPTYPES
127 
128 protected:
129 
130  virtual QString getLoadFilenameFilter();
131  virtual QString getSaveFilenameFilter(unsigned int propId);
132 
133 private:
134 
136  virtual void combine();
137 
139  bool combinable(PropertyVisualizer* propertyVisualizer1, PropertyVisualizer* propertyVisualizer2) const;
140 
142  virtual void saveProperty();
143 
145  void gatherProperties( MeshT* mesh,
146  typename MeshT::Properties::const_iterator props_first,
147  typename MeshT::Properties::const_iterator props_last,
148  PropertyInfo::ENTITY_FILTER filter);
150  void gatherProperties();
151 
153  bool isSupported(OpenVolumeMesh::BaseProperty* const baseProp) const;
154 
156  bool isSupported(QString friendlyName) const;
157 
159  bool isNew(OpenVolumeMesh::BaseProperty* const baseProp, PropertyInfo::ENTITY_FILTER filter) const;
160 
162  bool isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo);
163 
166 
168  TypeInfoWrapper getSupportedTypeInfoWrapper(QString friendlyName, PropertyInfo::ENTITY_FILTER filter) const;
169 
170  bool isEntityType(const TypeInfoWrapper& typeInfo, PropertyInfo::ENTITY_FILTER entity_type) const;
171 
173  void addPropertyVisualizer(OpenVolumeMesh::BaseProperty* const baseProp, MeshT* mesh, PropertyInfo::ENTITY_FILTER filter);
174 
176  void addProperty(QString propName, QString friendlyTypeName, PropertyInfo::ENTITY_FILTER filter);
177 
178  void initializeSupportedPropertyTypes();
179 
180  MeshT* mesh_;
181 
182  int objectID_;
183 
184  QPushButton bCombine;
185  const PropertyInfo* mCombineProperty1;
186  const PropertyInfo* mCombineProperty2;
187 
188  LoadSaveWidget mLoadSaveWidget;
189 
190  PickWidget mPickWidget;
191 
192  bool pickModeActive;
193  std::string lastPickMode;
194  Viewer::ActionMode lastActionMode;
195 
196  typedef std::set<TypeInfoWrapper> TypeInfoWrapperSet;
197  TypeInfoWrapperSet supportedPropertyTypes;
198 
199 };
200 
201 #define INITIALIZE_PROPTYPES(primitive) \
202 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_bool \
203  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<bool>), "bool"); \
204 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_int \
205  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<int>), "int"); \
206 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_uint \
207  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<unsigned int>), "unsigned int"); \
208 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_double \
209  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<double>), "double"); \
210 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_Vec3d \
211  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<ACG::Vec3d>), "Vec3d"); \
212 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_Vec3f \
213  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<ACG::Vec3f>), "Vec3f"); \
214 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_Matrix3x3d \
215  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<ACG::Matrix3x3d>), "Matrix3x3d");
216 
217 INITIALIZE_PROPTYPES(Cell)
218 INITIALIZE_PROPTYPES(Face)
219 INITIALIZE_PROPTYPES(HalfFace)
220 INITIALIZE_PROPTYPES(Edge)
221 INITIALIZE_PROPTYPES(HalfEdge)
222 INITIALIZE_PROPTYPES(Vertex)
223 
224 #undef INITIALIZE_PROPTYPES
225 
226 
227 #if defined(INCLUDE_TEMPLATES) && !defined(OVM_PROPERTY_MODEL_CC)
228 #include "OVMPropertyModelT_impl.hh"
229 #endif
230 
231 #endif /* OVM_PROPERTY_MODEL_H */
232 
virtual void pickProperty()
Toggle picking on and off.
Wraps the information of a type.
Definition: Utils.hh:73
ActionMode
Enum listing action modes of the viewers.
virtual void mouseEvent(QMouseEvent *_event)
Handles mouse events for picking.
virtual void updateWidget(const QModelIndexList &selectedIndices)
Updates the widget.
void addProperty(QString propName, QString friendlyTypeName, PropertyInfo::ENTITY_FILTER filter)
Adds a new property to the mesh.
TypeInfoWrapper getSupportedTypeInfoWrapper(OpenVolumeMesh::BaseProperty *const baseProp) const
Returns the TypeInfoWrapper for the property if it is supported.
bool isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Checks if a property name is still available for an entity type and a property type.
virtual void pickModeChanged(const std::string &_mode)
Handles changing of pick mode.
virtual void saveProperty()
Saves the currently slected properties.
bool isSupported(OpenVolumeMesh::BaseProperty *const baseProp) const
Checks if visualizing this property is supported.
void addPropertyVisualizer(OpenVolumeMesh::BaseProperty *const baseProp, MeshT *mesh, PropertyInfo::ENTITY_FILTER filter)
Adds a new PropertyVisualizer.
Cellection of information about a property.
Definition: Utils.hh:109
virtual QString getLoadFilenameFilter()
Returns the filename filter for loading.
void resetPicking()
Disables picking.
This class vizualizes a property.
void gatherProperties()
Searches for all properties and creates the visualizers.
virtual void combine()
Combines two properties.
virtual bool parseHeader(QString header, PropertyVisualizer *&propVis, unsigned int &n)
Parses the property file header.
virtual QString getSaveFilenameFilter(unsigned int propId)
Returns the filename filter for saving.
bool combinable(PropertyVisualizer *propertyVisualizer1, PropertyVisualizer *propertyVisualizer2) const
Checks if two properties are combinable.
bool isNew(OpenVolumeMesh::BaseProperty *const baseProp, PropertyInfo::ENTITY_FILTER filter) const
Checks if we already created a PropertyVisualizer for this property.