Commit feab9120 authored by David Thompson's avatar David Thompson
Browse files

More cursor subclasses; progress on EntityPhrase.

parent 1508fe48
......@@ -10,12 +10,15 @@ set(modelSrcs
EntityPhrase.cxx
ExportJSON.cxx
GroupItem.cxx
GroupEntity.cxx
GridInfo.cxx
GridInfo2D.cxx
GridInfo3D.cxx
ImportJSON.cxx
Item.cxx
InstanceEntity.cxx
Model.cxx
ModelEntity.cxx
PropertyListPhrase.cxx
PropertyValuePhrase.cxx
ShellEntity.h
......@@ -38,7 +41,9 @@ set(modelHeaders
EntityTypeBits.h
ExportJSON.h
FloatData.h
GroupEntity.h
ImportJSON.h
InstanceEntity.h
IntegerData.h
Item.h
GridInfo.h
......@@ -46,6 +51,7 @@ set(modelHeaders
GridInfo3D.h
GroupItem.h
Model.h
ModelEntity.h
PropertyListPhrase.h
PropertyValuePhrase.h
Storage.h
......
#include "smtk/model/EntityPhrase.h"
#include "smtk/model/CellEntity.h"
#include "smtk/model/EntityListPhrase.h"
#include "smtk/model/GroupEntity.h"
#include "smtk/model/InstanceEntity.h"
#include "smtk/model/ModelEntity.h"
#include "smtk/model/PropertyListPhrase.h"
#include "smtk/model/ShellEntity.h"
#include "smtk/model/UseEntity.h"
namespace smtk {
namespace model {
......@@ -40,25 +47,51 @@ Cursor EntityPhrase::relatedEntity() const
bool EntityPhrase::buildSubphrasesInternal()
{
// I. Add arrangement information
ArrangementKind kind;
for (int ikind = 0; ikind < KINDS_OF_ARRANGEMENTS; ++ikind)
{
kind = static_cast<ArrangementKind>(ikind);
int na = this->m_entity.numberOfArrangementsOfKind(kind);
for (int a = 0; a < na; ++a)
{
const Arrangement* arr = this->m_entity.findArrangement(kind, a);
if (!arr->details().empty())
{
CursorArray relations;
arr->relatedEntities(relations);
this->m_subphrases.push_back(
EntityListPhrase::create()->setup(
relations, shared_from_this()));
}
}
}
// This is dependent on both the entity type and the ArrangementKind
// so we cast to different cursor types and use their accessors to
// obtain lists of related entities.
{
UseEntity uent = this->m_entity.as<UseEntity>();
CellEntity cent = this->m_entity.as<CellEntity>();
ShellEntity sent = this->m_entity.as<ShellEntity>();
GroupEntity gent = this->m_entity.as<GroupEntity>();
ModelEntity ment = this->m_entity.as<ModelEntity>();
InstanceEntity ient = this->m_entity.as<InstanceEntity>();
if (uent.isValid())
{
}
else if (cent.isValid())
{
UseEntities relations = cent.uses();
if (!relations.empty())
{
this->m_subphrases.push_back(
EntityListPhrase::create()->setup(
relations, shared_from_this()));
}
}
else if (sent.isValid())
{
}
else if (gent.isValid())
{
}
else if (ment.isValid())
{
// TODO: Groups in model
// TODO: Submodels in model
CellEntities freeCellsInModel = ment.cells();
if (!freeCellsInModel.empty())
{
this->m_subphrases.push_back(
EntityListPhrase::create()->setup(
freeCellsInModel, shared_from_this()));
}
}
else if (ient.isValid())
{
}
}
// II. Add attribute information
// TODO.
// III. Add property information
......
#include "smtk/model/GroupEntity.h"
#include "smtk/model/CellEntity.h"
#include "smtk/model/Storage.h"
#include "smtk/model/Arrangement.h"
namespace smtk {
namespace model {
CellEntity GroupEntity::cell() const
{
if (this->isValid())
{
UUIDsToArrangements& all(this->m_storage->arrangements());
UUIDWithArrangementDictionary cellEntry = all.find(this->m_entity);
if (cellEntry != all.end())
{
ArrangementKindWithArrangements useIt = cellEntry->second.find(HAS_CELL);
if (useIt != cellEntry->second.end())
{
Entity* entRec = this->m_storage->findEntity(this->m_entity);
if (entRec)
{
smtk::util::UUIDArray const& relations(entRec->relations());
for (Arrangements::iterator arrIt = useIt->second.begin(); arrIt != useIt->second.end(); ++arrIt)
{
// Return the first cell referenced in the first non-empty HAS_CELL arrangement:
if (!arrIt->details().empty())
{
return CellEntity(this->m_storage, relations[arrIt->details().front()]);
}
}
}
}
}
}
return CellEntity();
}
} // namespace model
} // namespace smtk
#ifndef __smtk_model_GroupEntity_h
#define __smtk_model_GroupEntity_h
#include "smtk/model/Cursor.h"
namespace smtk {
namespace model {
class CellEntity;
/**\brief A cursor subclass that provides methods specific to entity use records.
*
*/
class SMTKCORE_EXPORT GroupEntity : public Cursor
{
public:
SMTK_CURSOR_CLASS(GroupEntity,Cursor,isGroupEntity);
CellEntity cell() const;
};
typedef std::vector<GroupEntity> GroupEntities;
} // namespace model
} // namespace smtk
#endif // __smtk_model_GroupEntity_h
#include "smtk/model/InstanceEntity.h"
#include "smtk/model/CellEntity.h"
#include "smtk/model/Storage.h"
#include "smtk/model/Arrangement.h"
namespace smtk {
namespace model {
CellEntity InstanceEntity::cell() const
{
if (this->isValid())
{
UUIDsToArrangements& all(this->m_storage->arrangements());
UUIDWithArrangementDictionary cellEntry = all.find(this->m_entity);
if (cellEntry != all.end())
{
ArrangementKindWithArrangements useIt = cellEntry->second.find(HAS_CELL);
if (useIt != cellEntry->second.end())
{
Entity* entRec = this->m_storage->findEntity(this->m_entity);
if (entRec)
{
smtk::util::UUIDArray const& relations(entRec->relations());
for (Arrangements::iterator arrIt = useIt->second.begin(); arrIt != useIt->second.end(); ++arrIt)
{
// Return the first cell referenced in the first non-empty HAS_CELL arrangement:
if (!arrIt->details().empty())
{
return CellEntity(this->m_storage, relations[arrIt->details().front()]);
}
}
}
}
}
}
return CellEntity();
}
} // namespace model
} // namespace smtk
#ifndef __smtk_model_InstanceEntity_h
#define __smtk_model_InstanceEntity_h
#include "smtk/model/Cursor.h"
namespace smtk {
namespace model {
class CellEntity;
/**\brief A cursor subclass that provides methods specific to entity use records.
*
*/
class SMTKCORE_EXPORT InstanceEntity : public Cursor
{
public:
SMTK_CURSOR_CLASS(InstanceEntity,Cursor,isInstanceEntity);
CellEntity cell() const;
};
typedef std::vector<InstanceEntity> InstanceEntities;
} // namespace model
} // namespace smtk
#endif // __smtk_model_InstanceEntity_h
#include "smtk/model/ModelEntity.h"
#include "smtk/model/CellEntity.h"
#include "smtk/model/Storage.h"
#include "smtk/model/Arrangement.h"
namespace smtk {
namespace model {
CellEntities ModelEntity::cells() const
{
CellEntities result;
if (this->isValid())
{
UUIDsToArrangements& all(this->m_storage->arrangements());
UUIDWithArrangementDictionary cellEntry = all.find(this->m_entity);
if (cellEntry != all.end())
{
ArrangementKindWithArrangements useIt = cellEntry->second.find(INCLUDES);
if (useIt != cellEntry->second.end())
{
Entity* entRec = this->m_storage->findEntity(this->m_entity);
if (entRec)
{
smtk::util::UUIDArray const& relations(entRec->relations());
for (Arrangements::iterator arrIt = useIt->second.begin(); arrIt != useIt->second.end(); ++arrIt)
{
for (std::vector<int>::iterator dit = arrIt->details().begin(); dit != arrIt->details().end(); ++dit)
{
result.push_back(CellEntity(this->m_storage, relations[*dit]));
}
}
}
}
}
}
return result;
}
} // namespace model
} // namespace smtk
#ifndef __smtk_model_ModelEntity_h
#define __smtk_model_ModelEntity_h
#include "smtk/model/Cursor.h"
namespace smtk {
namespace model {
class CellEntity;
class GroupEntity;
class ModelEntity;
typedef std::vector<CellEntity> CellEntities;
typedef std::vector<GroupEntity> GroupEntities;
typedef std::vector<ModelEntity> ModelEntities;
/**\brief A cursor subclass that provides methods specific to models.
*
*/
class SMTKCORE_EXPORT ModelEntity : public Cursor
{
public:
SMTK_CURSOR_CLASS(ModelEntity,Cursor,isModelEntity);
Cursor parent() const;
CellEntities cells() const;
GroupEntities groups() const;
ModelEntities models() const;
};
typedef std::vector<ModelEntity> ModelEntities;
} // namespace model
} // namespace smtk
#endif // __smtk_model_ModelEntity_h
......@@ -6,7 +6,9 @@
#include "smtk/model/testing/helpers.h"
#include <fstream>
#include <iostream>
#include <string>
#include <assert.h>
......@@ -28,19 +30,28 @@ void prindent(std::ostream& os, int indent, DescriptivePhrase::Ptr p)
int main(int argc, char* argv[])
{
(void)argc;
(void)argv;
StoragePtr sm = Storage::New();
UUIDArray uids = createTet(sm);
CursorArray ents;
int i = 16;
for (UUIDArray::iterator it = uids.begin() + 16; i < 21; ++it, ++i)
// Block to ensure timely destruction of JSON data.
{
ents.push_back(Cursor(sm, *it));
std::string fname(argc > 1 ? argv[1] : "smtkModel.json");
std::ifstream file(fname);
std::string data(
(std::istreambuf_iterator<char>(file)),
(std::istreambuf_iterator<char>()));
if (data.empty() || !ImportJSON::intoModel(data.c_str(), sm))
{
std::cerr << "Error importing model from file \"" << fname << "\"\n";
return 1;
}
}
sm->assignDefaultNames();
Cursors ents;
Cursor::CursorsFromUUIDs(
ents, sm, sm->entitiesMatchingFlags(MODEL_ENTITY, false));
DescriptivePhrase::Ptr dit;
EntityListPhrase::Ptr elist = EntityListPhrase::create()->setup(ents, dit);
prindent(std::cout, 0, elist);
......
......@@ -6,8 +6,8 @@
#include "cJSON.h"
#include <fstream>
#include <string>
#include <iostream>
#include <string>
#include <string.h>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment