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 isVec3dOVMType(const PropertyInfo& propInfo);
105  static bool isVec3dOVMType(const TypeInfoWrapper& typeInfo);
106  static bool isVec3fType(const PropertyInfo& propInfo);
107  static bool isVec3fType(const TypeInfoWrapper& typeInfo);
108  static bool isVectorType(const PropertyInfo& propInfo);
109  static bool isVectorType(const TypeInfoWrapper& typeInfo);
110  static bool isVectorOVMType(const PropertyInfo& propInfo);
111  static bool isVectorOVMType(const TypeInfoWrapper& typeInfo);
112  static bool isMatrix3x3Type(const PropertyInfo& propInfo);
113  static bool isMatrix3x3Type(const TypeInfoWrapper& typeInfo);
114 
115 #define DECLARE_PROPTYPES(primitive) \
116  static const TypeInfoWrapper proptype_##primitive##_bool; \
117  static const TypeInfoWrapper proptype_##primitive##_int; \
118  static const TypeInfoWrapper proptype_##primitive##_uint; \
119  static const TypeInfoWrapper proptype_##primitive##_double; \
120  static const TypeInfoWrapper proptype_##primitive##_Vec3d; \
121  static const TypeInfoWrapper proptype_##primitive##_Vec3dOVM; \
122  static const TypeInfoWrapper proptype_##primitive##_Vec3f; \
123  static const TypeInfoWrapper proptype_##primitive##_Matrix3x3d;
124 
125  DECLARE_PROPTYPES(Cell)
126  DECLARE_PROPTYPES(Face)
127  DECLARE_PROPTYPES(HalfFace)
128  DECLARE_PROPTYPES(Edge)
129  DECLARE_PROPTYPES(HalfEdge)
130  DECLARE_PROPTYPES(Vertex)
131 #undef DECLARE_PROPTYPES
132 
133 protected:
134 
135  virtual QString getLoadFilenameFilter();
136  virtual QString getSaveFilenameFilter(unsigned int propId);
137 
138 private:
139 
141  virtual void combine();
142 
144  bool combinable(PropertyVisualizer* propertyVisualizer1, PropertyVisualizer* propertyVisualizer2) const;
145 
147  virtual void saveProperty();
148 
150  void gatherProperties( MeshT* mesh,
151  typename MeshT::Properties::const_iterator props_first,
152  typename MeshT::Properties::const_iterator props_last,
153  PropertyInfo::ENTITY_FILTER filter);
155  void gatherProperties();
156 
158  bool isSupported(OpenVolumeMesh::BaseProperty* const baseProp) const;
159 
161  bool isSupported(QString friendlyName) const;
162 
164  bool isNew(OpenVolumeMesh::BaseProperty* const baseProp, PropertyInfo::ENTITY_FILTER filter) const;
165 
167  bool isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo);
168 
171 
173  TypeInfoWrapper getSupportedTypeInfoWrapper(QString friendlyName, PropertyInfo::ENTITY_FILTER filter) const;
174 
175  bool isEntityType(const TypeInfoWrapper& typeInfo, PropertyInfo::ENTITY_FILTER entity_type) const;
176 
178  void addPropertyVisualizer(OpenVolumeMesh::BaseProperty* const baseProp, MeshT* mesh, PropertyInfo::ENTITY_FILTER filter);
179 
181  void addProperty(QString propName, QString friendlyTypeName, PropertyInfo::ENTITY_FILTER filter);
182 
183  void initializeSupportedPropertyTypes();
184 
185  MeshT* mesh_;
186 
187  int objectID_;
188 
189  QPushButton bCombine;
190  const PropertyInfo* mCombineProperty1;
191  const PropertyInfo* mCombineProperty2;
192 
193  LoadSaveWidget mLoadSaveWidget;
194 
195  PickWidget mPickWidget;
196 
197  bool pickModeActive;
198  std::string lastPickMode;
199  Viewer::ActionMode lastActionMode;
200 
201  typedef std::set<TypeInfoWrapper> TypeInfoWrapperSet;
202  TypeInfoWrapperSet supportedPropertyTypes;
203 
204 };
205 
206 #define INITIALIZE_PROPTYPES(primitive) \
207 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_bool \
208  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<bool>), "bool"); \
209 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_int \
210  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<int>), "int"); \
211 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_uint \
212  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<unsigned int>), "unsigned int"); \
213 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_double \
214  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<double>), "double"); \
215 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_Vec3d \
216  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<ACG::Vec3d>), "Vec3d"); \
217 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_Vec3dOVM \
218  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<OpenVolumeMesh::Vec3d>), "Vec3dOVM"); \
219 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_Vec3f \
220  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<ACG::Vec3f>), "Vec3f"); \
221 template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_Matrix3x3d \
222  = TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<ACG::Matrix3x3d>), "Matrix3x3d");
223 
224 INITIALIZE_PROPTYPES(Cell)
225 INITIALIZE_PROPTYPES(Face)
226 INITIALIZE_PROPTYPES(HalfFace)
227 INITIALIZE_PROPTYPES(Edge)
228 INITIALIZE_PROPTYPES(HalfEdge)
229 INITIALIZE_PROPTYPES(Vertex)
230 
231 #undef INITIALIZE_PROPTYPES
232 
233 
234 #if defined(INCLUDE_TEMPLATES) && !defined(OVM_PROPERTY_MODEL_CC)
235 #include "OVMPropertyModelT_impl.hh"
236 #endif
237 
238 #endif /* OVM_PROPERTY_MODEL_H */
239 
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.