Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
82 {
83  using namespace PluginFunctions;
84 
85  if (objectID == -13 || objectID == -14 || objectID == -15)
86  {
87  if (propertyModelMap.find(objectID) == propertyModelMap.end())
88  {
89  propertyModelMap[objectID] = 0;
90  }
91 
92  if (propertyModelMap[objectID])
93  {
94  delete propertyModelMap[objectID];
95  propertyModelMap[objectID] = 0;
96  }
97 
98  switch (objectID) {
99  case -13:
100  propertyModelMap[objectID] = new MultiObjectPropertyModel(ALL_OBJECTS);
101  break;
102  case -14:
103  propertyModelMap[objectID] = new MultiObjectPropertyModel(TARGET_OBJECTS);
104  break;
105  case -15:
106  propertyModelMap[objectID] = new MultiObjectPropertyModel(SOURCE_OBJECTS);
107  break;
108  }
109 
110  return propertyModelMap[objectID];
111  }
112 
113  PropertyModelMap::iterator it = propertyModelMap.find(objectID);
114  if (it != propertyModelMap.end())
115  return it->second;
116 
117  BaseObjectData* object = 0;
118 
119  PluginFunctions::getObject( objectID, object );
120 
121  PropertyModel* propertyModel;
122 
123  if (object == 0) {
124  return 0;
125  }
126 
127  if ( object->dataType(DATA_TRIANGLE_MESH) )
128  {
129  TriMesh* mesh = PluginFunctions::triMesh(object);
130  propertyModel = new OMPropertyModel<TriMesh>(mesh, objectID);
131  }
132  else if ( object->dataType(DATA_POLY_MESH) )
133  {
134  PolyMesh* mesh = PluginFunctions::polyMesh(object);
135  propertyModel = new OMPropertyModel<PolyMesh>(mesh, objectID);
136  }
137 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
138  else if ( object->dataType(DATA_POLYHEDRAL_MESH) )
139  {
141  propertyModel = new OVMPropertyModel<PolyhedralMesh>(mesh, objectID);
142  }
143 #endif /* ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT */
144 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
145  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) )
146  {
148  propertyModel = new OVMPropertyModel<HexahedralMesh>(mesh, objectID);
149  }
150 #endif /* ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT */
151  else
152  {
153  return 0;
154  }
155 
156  propertyModelMap.insert(std::pair<int, PropertyModel*>(objectID, propertyModel));
157  return propertyModel;
158 }
159 
161 {
162  if (propertyModelMap.find(objectID) != propertyModelMap.end())
163  {
164  delete getModel(objectID);
165  propertyModelMap.erase(objectID);
166  }
167 }
const QStringList ALL_OBJECTS
Iterable object range.
#define DATA_POLYHEDRAL_MESH
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.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
void deleteModel(int objectID)
Deletes the PropertyModel.
#define DATA_POLY_MESH
Definition: PolyMesh.hh:65
PropertyModel * getModel(int objectID)
Returns the PropertyModel.
#define DATA_HEXAHEDRAL_MESH
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:66
HexahedralMesh * hexahedralMesh(BaseObjectData *_object)
Get an HexahedralMesh from an object.
PolyhedralMesh * polyhedralMesh(BaseObjectData *_object)
Get an PolyhedralMesh from an object.