10 #ifndef smtk_session_vtk_Session_h
11 #define smtk_session_vtk_Session_h
13 #include "smtk/session/vtk/Exports.h"
18 #include "smtk/common/UUID.h"
20 #include "vtkDataObjectTreeIterator.h"
21 #include "vtkInformation.h"
22 #include "vtkInformationObjectBaseVectorKey.h"
23 #include "vtkMultiBlockDataSet.h"
25 #include "vtkSmartPointer.h"
30 class vtkInformationDoubleKey;
31 class vtkInformationIntegerKey;
32 class vtkInformationStringKey;
63 SMTKVTKSESSION_EXPORT std::string EntityTypeNameString(EntityType etype);
75 EntityHandle(
int emod, vtkDataObject* obj, SessionPtr sess);
79 vtkDataObject* parent,
85 EntityType entityType()
const;
86 std::string name()
const;
90 int modelNumber()
const {
return this->m_modelNumber; }
98 T childrenAs(
int depth)
const
101 this->appendChildrenTo(container, depth);
106 void appendChildrenTo(T& container,
int depth)
const;
108 bool operator==(
const EntityHandle& other)
const
110 return this->m_session == other.m_session && this->m_object == other.m_object &&
111 this->m_modelNumber == other.m_modelNumber;
113 bool operator!=(
const EntityHandle& other)
const
115 return this->m_session != other.m_session || this->m_object != other.m_object ||
116 this->m_modelNumber != other.m_modelNumber;
121 typedef std::vector<EntityHandle> EntityHandleArray;
133 typedef std::vector<vtkSmartPointer<vtkMultiBlockDataSet>> ModelVector_t;
134 typedef std::map<smtk::model::EntityRef, EntityHandle> ReverseIdMap_t;
135 typedef std::pair<vtkDataObject*, int> ParentAndIndex_t;
136 typedef std::map<vtkDataObject*, ParentAndIndex_t> ChildParentMap_t;
156 static vtkInformationIntegerKey* SMTK_DIMENSION();
157 static vtkInformationIntegerKey* SMTK_VISIBILITY();
158 static vtkInformationIntegerKey* SMTK_GROUP_TYPE();
159 static vtkInformationIntegerKey* SMTK_PEDIGREE();
160 static vtkInformationIntegerKey* SMTK_OUTER_LABEL();
161 static vtkInformationObjectBaseVectorKey* SMTK_CHILDREN();
162 static vtkInformationDoubleKey* SMTK_LABEL_VALUE();
165 vtkSmartPointer<vtkMultiBlockDataSet>& model,
170 bool ensureChildParentMapEntry(vtkDataObject* child, vtkDataObject* parent,
int idxInParent);
172 ReverseIdMap_t& reverseIdMap() {
return m_revIdMap; }
174 size_t numberOfModels()
const;
181 static void setEnableTranscriptionChecks(
bool doCheck) { s_transcriptionChecks = doCheck; }
184 friend struct EntityHandle;
191 int depth = -1)
override;
193 ModelVector_t m_models;
194 ReverseIdMap_t m_revIdMap;
199 static bool s_transcriptionChecks;
201 vtkDataObject* modelOfHandle(
const EntityHandle& h)
const;
202 vtkDataObject* parent(vtkDataObject* obj)
const;
203 int parentIndex(vtkDataObject* obj)
const;
208 T* modelOfHandleAs(
const EntityHandle& h)
const
210 return T::SafeDownCast(this->modelOfHandle(h));
214 T* parentAs(vtkDataObject* obj)
const
216 return T::SafeDownCast(this->parent(obj));
224 T* EntityHandle::object()
const
234 return dynamic_cast<T*
>(this->
m_object.GetPointer());
240 void EntityHandle::appendChildrenTo(T& container,
int depth)
const
245 vtkDataObject* obj = this->object<vtkDataObject>();
249 vtkInformation* info = obj->GetInformation();
250 int objkids = Session::SMTK_CHILDREN()->Length(info);
251 vtkMultiBlockDataSet* data = vtkMultiBlockDataSet::SafeDownCast(obj);
252 if (!data && objkids < 1)
257 int nb = data->GetNumberOfBlocks();
258 for (
int i = 0; i < nb; ++i)
260 vtkDataObject* childData = data->GetBlock(i);
265 container.insert(container.end(), child);
267 vtkMultiBlockDataSet* mbds = vtkMultiBlockDataSet::SafeDownCast(childData);
268 if (mbds && depth != 0)
270 child.appendChildrenTo(container, depth < 0 ? depth : depth - 1);
276 for (
int i = 0; i < objkids; ++i)
278 vtkDataObject* childData =
279 vtkDataObject::SafeDownCast(Session::SMTK_CHILDREN()->Get(info, i));
284 container.insert(container.end(), child);
287 if (depth != 0 && Session::SMTK_CHILDREN()->Length(childData->GetInformation()) > 0)
289 child.appendChildrenTo(container, depth < 0 ? depth : depth - 1);
300 #endif // smtk_session_vtk_Session_h