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

WIP: More extensive testing.

parent 79f1892d
......@@ -61,7 +61,8 @@ public:
const ArcEditor<SourceNodeType, NodeType>& begin() { return *this; }
const ArcEditor<SourceNodeType, NodeType>& end() { return *this; }
protected:
typename smtk::graph::Arcs<SourceNodeType, NodeType>::API& m_api;
// TODO:
// typename smtk::graph::Arcs<SourceNodeType, NodeType>::API& m_api;
};
} // namespace markup
......
......@@ -16,6 +16,7 @@ list(APPEND classes
Collection
Ontology
Frame
Group
AnalyticShape
Plane
Sphere
......
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
#include "smtk/markup/Component.h"
#include "smtk/markup/Resource.h"
namespace smtk
{
namespace markup
{
struct Component::ModifyName
{
ModifyName(const std::string& nextName)
: m_name(nextName)
{
}
void operator()(Component::Ptr& c)
{
c->m_name = m_name;
}
std::string m_name;
};
Component::~Component() = default;
bool Component::setName(const std::string& name)
{
if (name == m_name)
{
return false;
}
auto owner = std::dynamic_pointer_cast<smtk::markup::Resource>(this->resource());
if (owner)
{
// We are not allowed to set our name directly since
// our owning resource has indexed us by name.
return owner->modifyComponent(*this, ModifyName(name));
}
m_name = name;
return true;
}
} // namespace markup
} // namespace smtk
......@@ -40,11 +40,20 @@ public:
*/
virtual Index index() const { return std::type_index(typeid(*this)).hash_code(); }
/// Return the component's name.
std::string name() const override { return m_name; }
/// Set the component's name.
bool setName(const std::string& name);
ArcEditor<SelfType, smtk::markup::Group> groups() const;
ArcEditor<SelfType, smtk::markup::Label> labels() const;
protected:
std::string m_name;
/// A functor for changing the name of a component.
struct ModifyName;
};
} // namespace markup
......
......@@ -50,6 +50,11 @@ bool& Group::ownsMembers()
return m_ownsMembers;
}
ArcEditor<Group, Component> Group::members() const
{
ArcEditor<Group, Component> stuff;
return stuff;
}
} // namespace markup
} // namespace smtk
......@@ -32,7 +32,7 @@ public:
const std::weak_ptr<smtk::markup::AssignedIds>& keys() const;
std::weak_ptr<smtk::markup::AssignedIds>& keys();
/// When removing a member arc, should the component be deleted?
/// When removing a member arc, should the component be deleted?
bool setOwnsMembers(const bool& ownsMembers);
const bool& ownsMembers() const;
bool& ownsMembers();
......
......@@ -31,5 +31,21 @@ Resource::Resource(smtk::resource::ManagerPtr manager)
this->queries().registerQueries<QueryTypes>();
}
std::function<bool(const smtk::resource::Component&)> Resource::queryOperation(
const std::string& query) const
{
// TODO: Use pegtl to parse query properly.
std::function<bool(const smtk::resource::Component&)> functor =
[&query](const smtk::resource::Component& c) -> bool
{
if (query == "*" || query == "any")
{
return true;
}
return (c.typeName() == query);
};
return functor;
}
} // namespace markup
} // namespace smtk
......@@ -24,7 +24,7 @@ class Volume;
class Model;
class Shape;
// Forward-declare bond types
// Forward-declare arc types
struct CellBoundary;
struct FreeCell;
......@@ -40,22 +40,43 @@ public:
smtkSuperclassMacro(smtk::resource::DerivedFrom<Resource, GraphResource>);
smtkSharedPtrCreateMacro(smtk::resource::PersistentObject);
Resource(const Resource&) = delete;
virtual ~Resource() = default;
// Wrap to avoid name conflict in MSVC.
template <typename componentT>
smtk::shared_ptr<componentT> createShape()
smtk::shared_ptr<componentT> createNode()
{
return GraphResource::create<componentT>();
}
Resource(const Resource&) = delete;
/// Return a boolean functor that classifies components according to \a query.
std::function<bool(const smtk::resource::Component&)> queryOperation(
const std::string& query) const override;
protected:
Resource(const smtk::common::UUID&, smtk::resource::Manager::Ptr manager = nullptr);
Resource(smtk::resource::Manager::Ptr manager = nullptr);
friend class Component;
template<typename Modifier>
bool modifyComponent(Component& component, const Modifier& modifier);
};
template<typename Modifier>
bool Resource::modifyComponent(Component& component, const Modifier& modifier)
{
auto& nodesById = NodeStorage::m_nodes.get<detail::IdTag>();
auto it = nodesById.find(component.id());
if (it != nodesById.end())
{
NodeStorage::m_nodes.modify(it, modifier);
return true;
}
return false;
}
} // namespace markup
} // namespace smtk
......
#include "smtk/markup/Resource.h"
#include "smtk/markup/Component.h"
#include "smtk/markup/Label.h"
#include "smtk/markup/Group.h"
#include "smtk/common/UUID.h"
#include "smtk/common/testing/cxx/helpers.h"
#include <iostream>
......@@ -9,7 +13,11 @@ using namespace smtk::markup;
int TestResource(int argc, char** argv)
{
auto resource = smtk::markup::Resource::create();
auto label = resource->createShape<Label>();
auto label = resource->createNode<Label>();
label->setName("foo");
auto group = std::make_shared<Group>(nullptr, smtk::common::UUID::random());
group->setName("barf");
resource->add(group);
auto components = resource->filter("*");
std::size_t nn = components.size();
std::cout << "Created " << resource << " with " << nn << " components.\n";
......@@ -17,5 +25,11 @@ int TestResource(int argc, char** argv)
{
std::cout << " " << component->typeName() << ": " << component->name() << "\n";
}
test(nn == 2, "Expected to create 2 components.");
components = resource->filter("smtk::markup::Label");
nn = components.size();
std::cout << "Found " << nn << " labels\n";
return 0;
}
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