Model.h 5.32 KB
Newer Older
1
2
3
4
5
6
7
8
9
//=========================================================================
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
//
//  This software is distributed WITHOUT ANY WARRANTY; without even
//  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//  PURPOSE.  See the above copyright notice for more information.
//=========================================================================
10
11
#ifndef __smtk_model_Model_h
#define __smtk_model_Model_h
12

13
#include "smtk/model/EntityRef.h"
14
15
16
17
18

namespace smtk {
  namespace model {

class CellEntity;
19
20
class Group;
class Model;
21
typedef std::vector<CellEntity> CellEntities;
22
typedef std::vector<Model> Models;
23

24
/**\brief A entityref subclass that provides methods specific to models.
25
26
  *
  */
27
class SMTKCORE_EXPORT Model : public EntityRef
28
29
{
public:
30
  SMTK_ENTITYREF_CLASS(Model,EntityRef,isModel);
31

32
33
  ModelGeometryStyle geometryStyle() const;

34
35
  void setEmbeddingDimension(int dim);

36
  EntityRef parent() const;
37
38
  SessionRef session() const;
  void setSession(const SessionRef& sess);
39
40

  CellEntities cells() const;
41
42
  Groups groups() const;
  Models submodels() const;
43

44
45
46
  template<typename T> T cellsAs() const;
  template<typename T> T groupsAs() const;
  template<typename T> T submodelsAs() const;
47
  template<typename T> void appendCells(T& container) const;
48

49
50
51
52
  Model& addCell(const CellEntity& c);
  Model& removeCell(const CellEntity& c);
  template<typename T> Model& addCells(const T& container);
  template<typename T> Model& removeCells(const T& container);
53

54
55
56
57
  Model& addGroup(const Group& g);
  Model& removeGroup(const Group& g);
  template<typename T> Model& addGroups(const T& container);
  template<typename T> Model& removeGroups(const T& container);
58

59
60
61
62
  Model& addSubmodel(const Model& m);
  Model& removeSubmodel(const Model& m);
  template<typename T> Model& addSubmodels(const T& container);
  template<typename T> Model& removeSubmodels(const T& container);
63
64

  OperatorPtr op(const std::string& operatorName) const;
David Thompson's avatar
David Thompson committed
65
  StringList operatorNames() const;
66
67

  void assignDefaultNames();
68
69
};

70
71
72
/// Return the top-level (free) cells of this model in a container of the template type.
template<typename T> T Model::cellsAs() const
{
73
  // TODO: This could be done more efficiently without a copy.
74
  CellEntities tmp = this->cells();
75
76
77
78
79
80
81
82
  T result;
  for (CellEntities::iterator it = tmp.begin(); it != tmp.end(); ++it)
    {
    typename T::value_type entry(*it);
    if (entry.isValid())
      result.insert(result.end(), *it);
    }
  return result;
83
84
85
86
87
}

/// Return the top-level (free) groups of this model in a container of the template type.
template<typename T> T Model::groupsAs() const
{
88
  // TODO: This could be done more efficiently without a copy.
89
  Groups tmp = this->groups();
90
91
92
93
94
95
96
97
  T result;
  for (Groups::iterator it = tmp.begin(); it != tmp.end(); ++it)
    {
    typename T::value_type entry(*it);
    if (entry.isValid())
      result.insert(result.end(), *it);
    }
  return result;
98
99
100
101
102
}

/// Return the child models of this model in a container of the template type.
template<typename T> T Model::submodelsAs() const
{
103
  // TODO: This could be done more efficiently without a copy.
104
  Models tmp = this->submodels();
105
106
107
108
109
110
111
112
  T result;
  for (Models::iterator it = tmp.begin(); it != tmp.end(); ++it)
    {
    typename T::value_type entry(*it);
    if (entry.isValid())
      result.insert(result.end(), *it);
    }
  return result;
113
114
}

115
116
117
118
119
/// Append free cells of this model to the given \a container. Only valid cells are inserted.
template<typename T> void Model::appendCells(T& container) const
{
  // TODO: This could be done more efficiently without a copy.
  CellEntities tmp = this->cells();
120
121
122
123
124
125
  for (CellEntities::iterator it = tmp.begin(); it != tmp.end(); ++it)
    {
    typename T::value_type entry(*it);
    if (entry.isValid())
      container.insert(container.end(), *it);
    }
126
127
}

128
/// Add all the free cells in \a container to this model.
129
template<typename T> Model& Model::addCells(const T& container)
130
131
132
133
134
{
  this->embedEntities(container);
  return *this;
}

135
/// Add all the free cells in \a container to this model.
136
template<typename T> Model& Model::removeCells(const T& container)
137
138
139
140
141
{
  this->unembedEntities(container);
  return *this;
}

142
/// Add all the groups in \a container to this model.
143
template<typename T> Model& Model::addGroups(const T& container)
144
{
145
146
147
148
149
150
151
152
  for (typename T::const_iterator it = container.begin(); it != container.end(); ++it)
    {
    this->addGroup(*it);
    }
  return *this;
}

/// Add all the groups in \a container to this model.
153
template<typename T> Model& Model::removeGroups(const T& container)
154
155
156
157
158
{
  for (typename T::const_iterator it = container.begin(); it != container.end(); ++it)
    {
    this->removeGroup(*it);
    }
159
160
161
162
  return *this;
}

/// Add all the models in \a container as submodels to this model.
163
template<typename T> Model& Model::addSubmodels(const T& container)
164
{
165
166
167
168
169
170
171
172
  for (typename T::const_iterator it = container.begin(); it != container.end(); ++it)
    {
    this->addSubmodel(*it);
    }
  return *this;
}

/// Add all the models in \a container as submodels to this model.
173
template<typename T> Model& Model::removeSubmodels(const T& container)
174
175
176
177
178
{
  for (typename T::const_iterator it = container.begin(); it != container.end(); ++it)
    {
    this->removeSubmodel(*it);
    }
179
180
  return *this;
}
181
182
183
184

  } // namespace model
} // namespace smtk

185
#endif // __smtk_model_Model_h