SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
Model.h
1 //=========================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //=========================================================================
10 #ifndef smtk_model_Model_h
11 #define smtk_model_Model_h
12 
13 #include "smtk/model/EntityRef.h"
14 
15 #include "smtk/model/CellEntity.h"
16 #include "smtk/model/Group.h"
17 
18 namespace smtk
19 {
20 namespace model
21 {
22 
23 class Model;
24 typedef std::vector<CellEntity> CellEntities;
25 typedef std::vector<Model> Models;
26 
30 class SMTKCORE_EXPORT Model : public EntityRef
31 {
32 public:
34 
35  ModelGeometryStyle geometryStyle() const;
36 
37  void setEmbeddingDimension(int dim);
38 
39  EntityRef parent() const;
40  SessionRef session() const;
41  void setSession(const SessionRef& sess);
42 
43  bool isModified() const;
44  void setIsModified(bool isModified);
45 
46  CellEntities cells() const;
47  Groups groups() const;
48  Models submodels() const;
49  AuxiliaryGeometries auxiliaryGeometry() const;
50 
51  template<typename T>
52  T cellsAs() const;
53  template<typename T>
54  T groupsAs() const;
55  template<typename T>
56  T submodelsAs() const;
57  template<typename T>
58  void appendCells(T& container) const;
59 
60  Model& addCell(const CellEntity& c, bool checkExists = true);
61  Model& removeCell(const CellEntity& c);
62  template<typename T>
63  Model& addCells(const T& container, bool checkExists = true);
64  template<typename T>
65  Model& removeCells(const T& container);
66 
67  Model& addGroup(const Group& g);
68  Model& removeGroup(const Group& g);
69  template<typename T>
70  Model& addGroups(const T& container);
71  template<typename T>
72  Model& removeGroups(const T& container);
73 
74  Model& addSubmodel(const Model& m);
75  Model& removeSubmodel(const Model& m);
76  template<typename T>
77  Model& addSubmodels(const T& container);
78  template<typename T>
79  Model& removeSubmodels(const T& container);
80 
81  Model& addAuxiliaryGeometry(const AuxiliaryGeometry& ag);
82  Model& removeAuxiliaryGeometry(const AuxiliaryGeometry& ag);
83  template<typename T>
84  Model& addAuxiliaryGeometries(const T& container);
85  template<typename T>
86  Model& removeAuxiliaryGeometries(const T& container);
87 
88  void assignDefaultNames();
89 
90  EntityRefs entitiesWithTessellation() const;
91 };
92 
94 template<typename T>
95 T Model::cellsAs() const
96 {
97  // TODO: This could be done more efficiently without a copy.
98  CellEntities tmp = this->cells();
99  T result;
100  for (CellEntities::iterator it = tmp.begin(); it != tmp.end(); ++it)
101  {
102  typename T::value_type entry(*it);
103  if (entry.isValid())
104  result.insert(result.end(), *it);
105  }
106  return result;
107 }
108 
110 template<typename T>
112 {
113  // TODO: This could be done more efficiently without a copy.
114  Groups tmp = this->groups();
115  T result;
116  for (Groups::iterator it = tmp.begin(); it != tmp.end(); ++it)
117  {
118  typename T::value_type entry(*it);
119  if (entry.isValid())
120  result.insert(result.end(), *it);
121  }
122  return result;
123 }
124 
126 template<typename T>
128 {
129  // TODO: This could be done more efficiently without a copy.
130  Models tmp = this->submodels();
131  T result;
132  for (Models::iterator it = tmp.begin(); it != tmp.end(); ++it)
133  {
134  typename T::value_type entry(*it);
135  if (entry.isValid())
136  result.insert(result.end(), *it);
137  }
138  return result;
139 }
140 
142 template<typename T>
143 void Model::appendCells(T& container) const
144 {
145  // TODO: This could be done more efficiently without a copy.
146  CellEntities tmp = this->cells();
147  for (CellEntities::iterator it = tmp.begin(); it != tmp.end(); ++it)
148  {
149  typename T::value_type entry(*it);
150  if (entry.isValid())
151  container.insert(container.end(), *it);
152  }
153 }
154 
160 template<typename T>
161 Model& Model::addCells(const T& container, bool checkExistence)
162 {
163  this->embedEntities(container, checkExistence);
164  return *this;
165 }
166 
168 template<typename T>
169 Model& Model::removeCells(const T& container)
170 {
171  this->unembedEntities(container);
172  return *this;
173 }
174 
176 template<typename T>
177 Model& Model::addGroups(const T& container)
178 {
179  for (typename T::const_iterator it = container.begin(); it != container.end(); ++it)
180  {
181  this->addGroup(*it);
182  }
183  return *this;
184 }
185 
187 template<typename T>
188 Model& Model::removeGroups(const T& container)
189 {
190  for (typename T::const_iterator it = container.begin(); it != container.end(); ++it)
191  {
192  this->removeGroup(*it);
193  }
194  return *this;
195 }
196 
198 template<typename T>
199 Model& Model::addSubmodels(const T& container)
200 {
201  for (typename T::const_iterator it = container.begin(); it != container.end(); ++it)
202  {
203  this->addSubmodel(*it);
204  }
205  return *this;
206 }
207 
209 template<typename T>
210 Model& Model::removeSubmodels(const T& container)
211 {
212  for (typename T::const_iterator it = container.begin(); it != container.end(); ++it)
213  {
214  this->removeSubmodel(*it);
215  }
216  return *this;
217 }
218 
220 template<typename T>
222 {
223  for (typename T::const_iterator it = container.begin(); it != container.end(); ++it)
224  {
225  this->addAuxiliaryGeometry(*it);
226  }
227  return *this;
228 }
229 
231 template<typename T>
233 {
234  for (typename T::const_iterator it = container.begin(); it != container.end(); ++it)
235  {
236  this->removeAuxiliaryGeometry(*it);
237  }
238  return *this;
239 }
240 
241 } // namespace model
242 } // namespace smtk
243 
244 #endif // smtk_model_Model_h
smtk
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
smtk::model::Model::addAuxiliaryGeometries
Model & addAuxiliaryGeometries(const T &container)
Add all the auxiliary geometry entities in container to this model.
Definition: Model.h:221
smtk::model::Model::removeGroups
Model & removeGroups(const T &container)
Add all the groups in container to this model.
Definition: Model.h:188
smtk::model::Model::addCells
Model & addCells(const T &container, bool checkExists=true)
Add all the free cells in container to this model.
Definition: Model.h:161
smtk::model::Model::addAuxiliaryGeometry
Model & addAuxiliaryGeometry(const AuxiliaryGeometry &ag)
Add the given auxiliary geometry to this model.
Definition: Model.cxx:263
smtk::model::AuxiliaryGeometries
std::vector< smtk::model::AuxiliaryGeometry > AuxiliaryGeometries
Definition: PublicPointerDefs.h:144
smtk::model::Model
A entityref subclass that provides methods specific to models.
Definition: Model.h:30
smtk::model::Model::cells
CellEntities cells() const
Return the cells directly owned by this model.
Definition: Model.cxx:114
EntityRef.h
smtk::model::CellEntity
A entityref subclass with methods specific to cell entities.
Definition: CellEntity.h:30
smtk::model::Model::addSubmodels
Model & addSubmodels(const T &container)
Add all the models in container as submodels to this model.
Definition: Model.h:199
smtk::model::Model::removeAuxiliaryGeometry
Model & removeAuxiliaryGeometry(const AuxiliaryGeometry &ag)
Remove the given auxiliary geometry from this model (if present as a top-level entry).
Definition: Model.cxx:273
smtk::model::AuxiliaryGeometry
An EntityRef subclass for representing unmodeled geometry to be included in a scene.
Definition: AuxiliaryGeometry.h:44
smtk::model::Model::removeSubmodels
Model & removeSubmodels(const T &container)
Remove all the models in container from this model (if they are submodels).
Definition: Model.h:210
smtk::model::Model::addGroups
Model & addGroups(const T &container)
Add all the groups in container to this model.
Definition: Model.h:177
smtk::model::EntityRef::embedEntities
EntityRef & embedEntities(const T &container, bool checkExistence=true)
Embed each of the entities in the container inside this entity.
Definition: EntityRef.h:425
smtk::model::ModelGeometryStyle
ModelGeometryStyle
Enumerate how model domains are represented.
Definition: EntityTypeBits.h:307
smtk::model::SessionRef
A entityref subclass that provides methods specific to entity use records.
Definition: SessionRef.h:28
smtk::model::Model::cellsAs
T cellsAs() const
Return the top-level (free) cells of this model in a container of the template type.
Definition: Model.h:95
smtk::model::Model::removeCells
Model & removeCells(const T &container)
Remove all the free cells in container from this model.
Definition: Model.h:169
smtk::model::Model::submodelsAs
T submodelsAs() const
Return the child models of this model in a container of the template type.
Definition: Model.h:127
smtk::model::Group
A entityref subclass that provides methods specific to entity use records.
Definition: Group.h:27
smtk::model::Model::groupsAs
T groupsAs() const
Return the top-level (free) groups of this model in a container of the template type.
Definition: Model.h:111
smtk::model::Model::appendCells
void appendCells(T &container) const
Append free cells of this model to the given container. Only valid cells are inserted.
Definition: Model.h:143
smtk::model::Model::groups
Groups groups() const
Return the groups directly owned by this model.
Definition: Model.cxx:141
smtk::model::Models
std::vector< smtk::model::Model > Models
Definition: PublicPointerDefs.h:200
SMTK_ENTITYREF_CLASS
#define SMTK_ENTITYREF_CLASS(thisclass, superclass, typecheck)
A macro to implement mandatory EntityRef-subclass constructors.
Definition: EntityRef.h:43
smtk::model::EntityRefs
std::set< smtk::model::EntityRef > EntityRefs
Definition: PublicPointerDefs.h:162
smtk::model::EntityRef
A lightweight entityref pointing to a model entity's resource.
Definition: EntityRef.h:112
smtk::model::Model::submodels
Models submodels() const
Return the models directly owned by this model.
Definition: Model.cxx:149
smtk::model::Model::removeAuxiliaryGeometries
Model & removeAuxiliaryGeometries(const T &container)
Remove all the auxiliary geometry entities in container from this model.
Definition: Model.h:232