Developer Documentation
PropertyModelFactory.cc
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 #include "PropertyModelFactory.hh"
51 
52 #include "MultiObjectPropertyModel.hh"
53 #include "OpenMesh/OMPropertyModel.hh"
54 
55 #ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
56  #include "OpenVolumeMesh/OVMPropertyModel.hh"
57 #endif /* ENABLE_OPENVOLUMEMESH_SUPPORT */
58 
59 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
60 #endif /* ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT */
61 
62 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
63 #endif /* ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT */
64 
65 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
67 #endif
68 
69 
86 {
87  using namespace PluginFunctions;
88 
89  if (objectID == -13 || objectID == -14 || objectID == -15)
90  {
91  if (propertyModelMap.find(objectID) == propertyModelMap.end())
92  {
93  propertyModelMap[objectID] = 0;
94  }
95 
96  if (propertyModelMap[objectID])
97  {
98  delete propertyModelMap[objectID];
99  propertyModelMap[objectID] = 0;
100  }
101 
102  switch (objectID) {
103  case -13:
104  propertyModelMap[objectID] = new MultiObjectPropertyModel(ALL_OBJECTS);
105  break;
106  case -14:
107  propertyModelMap[objectID] = new MultiObjectPropertyModel(TARGET_OBJECTS);
108  break;
109  case -15:
110  propertyModelMap[objectID] = new MultiObjectPropertyModel(SOURCE_OBJECTS);
111  break;
112  }
113 
114  return propertyModelMap[objectID];
115  }
116 
117  PropertyModelMap::iterator it = propertyModelMap.find(objectID);
118  if (it != propertyModelMap.end())
119  return it->second;
120 
121  BaseObjectData* object = 0;
122 
123  PluginFunctions::getObject( objectID, object );
124 
125  PropertyModel* propertyModel;
126 
127  if (object == 0) {
128  return 0;
129  }
130 
131  if ( object->dataType(DATA_TRIANGLE_MESH) )
132  {
133  TriMesh* mesh = PluginFunctions::triMesh(object);
134  propertyModel = new OMPropertyModel<TriMesh>(mesh, objectID);
135  }
136  else if ( object->dataType(DATA_POLY_MESH) )
137  {
138  PolyMesh* mesh = PluginFunctions::polyMesh(object);
139  propertyModel = new OMPropertyModel<PolyMesh>(mesh, objectID);
140  }
141 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
142  else if ( object->dataType(DATA_POLYHEDRAL_MESH) )
143  {
145  propertyModel = new OVMPropertyModel<PolyhedralMesh>(mesh, objectID);
146  }
147 #endif /* ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT */
148 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
149  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) )
150  {
152  propertyModel = new OVMPropertyModel<HexahedralMesh>(mesh, objectID);
153  }
154 #endif /* ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT */
155 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
156  else if ( object->dataType(DATA_TETRAHEDRAL_MESH) )
157  {
158  TetrahedralMesh* mesh = PluginFunctions::tetrahedralMesh(object);
159  propertyModel = new OVMPropertyModel<TetrahedralMesh>(mesh, objectID);
160  }
161 #endif
162  else
163  {
164  return 0;
165  }
166 
167  propertyModelMap.insert(std::pair<int, PropertyModel*>(objectID, propertyModel));
168  return propertyModel;
169 }
170 
172 {
173  if (propertyModelMap.find(objectID) != propertyModelMap.end())
174  {
175  delete getModel(objectID);
176  propertyModelMap.erase(objectID);
177  }
178 }
PropertyModel * getModel(int objectID)
Returns the PropertyModel.
bool getObject(int _identifier, BSplineCurveObject *&_object)
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
const QStringList SOURCE_OBJECTS("source")
Iterable object range.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
#define DATA_POLYHEDRAL_MESH
const QStringList ALL_OBJECTS
Iterable object range.
#define DATA_HEXAHEDRAL_MESH
PolyhedralMesh * polyhedralMesh(BaseObjectData *_object)
Get an PolyhedralMesh from an object.
void deleteModel(int objectID)
Deletes the PropertyModel.
#define DATA_POLY_MESH
Definition: PolyMesh.hh:65
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:66
HexahedralMesh * hexahedralMesh(BaseObjectData *_object)
Get an HexahedralMesh from an object.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.