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