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

Use the new graph-resource `::initialize()`.

parent e984306e
......@@ -8,6 +8,9 @@ namespace markup
AnalyticShape::~AnalyticShape() = default;
void AnalyticShape::initialize(const nlohmann::json& data, json::Helper& helper)
{
}
} // namespace markup
} // namespace smtk
......@@ -22,14 +22,11 @@ public:
{
}
template<typename... Args>
AnalyticShape(const nlohmann::json* j, Args&&... args)
: smtk::markup::SpatialData(std::forward<Args>(args)...)
{
}
~AnalyticShape() override;
/// Provide an initializer for resources to call after construction.
void initialize(const nlohmann::json& data, json::Helper& helper) override;
protected:
};
......
......@@ -6,8 +6,17 @@ namespace smtk
namespace markup
{
BoundaryOperator::~BoundaryOperator() = default;
BoundaryOperator::BoundaryOperator(smtk::string::Token name)
: Domain(name)
{
// TODO: create mapping?
}
BoundaryOperator::BoundaryOperator(const nlohmann::json& data)
: Domain(data)
{
// TODO: Deserialize or create mapping
}
} // namespace markup
} // namespace smtk
......@@ -16,19 +16,10 @@ public:
smtkTypeMacro(smtk::markup::BoundaryOperator);
smtkSuperclassMacro(smtk::markup::Domain);
template<typename... Args>
BoundaryOperator(Args&&... args)
: smtk::markup::Domain(std::forward<Args>(args)...)
{
}
template<typename... Args>
BoundaryOperator(const nlohmann::json*, Args&&... args)
: smtk::markup::Domain(std::forward<Args>(args)...)
{
}
~BoundaryOperator() override;
BoundaryOperator() = default;
BoundaryOperator(smtk::string::Token name);
BoundaryOperator(const nlohmann::json& data);
~BoundaryOperator() override = default;
protected:
};
......
......@@ -8,6 +8,10 @@ namespace markup
Box::~Box() = default;
void Box::initialize(const nlohmann::json& data, json::Helper& helper)
{
}
bool Box::setRange(const std::array<std::array<double, 3>, 2>& range)
{
if (m_range == range)
......
......@@ -22,14 +22,11 @@ public:
{
}
template<typename... Args>
Box(const nlohmann::json* j, Args&&... args)
: smtk::markup::AnalyticShape(std::forward<Args>(args)...)
{
}
~Box() override;
/// Provide an initializer for resources to call after construction.
void initialize(const nlohmann::json& data, json::Helper& helper) override;
bool setRange(const std::array<std::array<double, 3>, 2>& range);
const std::array<std::array<double, 3>, 2>& range() const;
std::array<std::array<double, 3>, 2>& range();
......
......@@ -4,6 +4,7 @@
#include "smtk/markup/Group.h"
#include "smtk/markup/Label.h"
#include "smtk/markup/Resource.h"
#include "smtk/markup/json/Helper.h"
namespace smtk
{
......@@ -24,8 +25,19 @@ struct Component::ModifyName
std::string m_name;
};
Component::~Component() = default;
void Component::initialize(const nlohmann::json& data, json::Helper& helper)
{
(void)helper;
auto it = data.find("name");
if (it != data.end())
{
m_name = it->get<std::string>();
}
}
Component::Index Component::index() const
{
return std::type_index(typeid(*this)).hash_code();}
......
......@@ -14,6 +14,7 @@ namespace smtk
{
namespace markup
{
namespace json { class Helper; }
class Group;
class Label;
......@@ -31,24 +32,17 @@ public:
: smtk::graph::Component(std::forward<Args>(args)...)
{
}
template<typename... Args>
Component(const nlohmann::json* j, Args&&... args)
: smtk::graph::Component(std::forward<Args>(args)...)
{
auto it = j->find("name");
if (it != j->end())
{
m_name = it->get<std::string>();
}
}
~Component() override;
/// Provide an initializer for resources to call after construction.
virtual void initialize(const nlohmann::json& data, json::Helper& helper);
/// The index is a compile-time intrinsic of the derived resource; as such, it cannot be set.
Component::Index index() const;
/// Return the component's name.
std::string name() const override;
/// Set the component's name.
bool setName(const std::string& name);
......
......@@ -8,6 +8,10 @@ namespace markup
Cone::~Cone() = default;
void Cone::initialize(const nlohmann::json& data, json::Helper& helper)
{
}
bool Cone::setEndpoints(const std::array<std::array<double, 3>, 2>& endpoints)
{
if (m_endpoints == endpoints)
......
......@@ -22,14 +22,11 @@ public:
{
}
template<typename... Args>
Cone(const nlohmann::json* j, Args&&... args)
: smtk::markup::AnalyticShape(std::forward<Args>(args)...)
{
}
~Cone() override;
/// Provide an initializer for resources to call after construction.
void initialize(const nlohmann::json& data, json::Helper& helper) override;
bool setEndpoints(const std::array<std::array<double, 3>, 2>& endpoints);
const std::array<std::array<double, 3>, 2>& endpoints() const;
std::array<std::array<double, 3>, 2>& endpoints();
......
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
#include "smtk/markup/Domain.h"
#include "smtk/string/json/jsonToken.h"
namespace smtk
{
namespace markup
{
Domain::Domain(smtk::string::Token name)
: m_name(name)
{
}
Domain::Domain(const nlohmann::json& data)
: m_name(data.at("name").get<smtk::string::Token>())
{
}
} // namespace markup
} // namespace smtk
......@@ -7,6 +7,8 @@
#include "smtk/SharedFromThis.h"
#include "smtk/string/Token.h"
#include "nlohmann/json.hpp"
#include <memory>
namespace smtk
......@@ -21,9 +23,8 @@ public:
smtkTypeMacroBase(smtk::markup::Domain);
Domain() = default;
Domain(const smtk::string::Token& name)
: m_name(name)
{ }
Domain(smtk::string::Token name);
Domain(const nlohmann::json& data);
virtual ~Domain() = default;
smtk::string::Token name() const { return m_name; }
......
......@@ -21,13 +21,12 @@ using DomainFactory =
smtk::common::Factory<
smtk::markup::Domain,
// Possible constructor arguments:
// 0. Nothing:
void,
// 1. Just a token (name):
smtk::string::Token,
// 2. A JSON pointer (references cause problems) and token (name)
smtk::common::factory::Inputs<
const nlohmann::json*,
smtk::string::Token
>
// 2. A JSON object
const nlohmann::json&
>;
} // namespace markup
......
......@@ -8,6 +8,10 @@ namespace markup
ExplicitSubset::~ExplicitSubset() = default;
void ExplicitSubset::initialize(const nlohmann::json& data, json::Helper& helper)
{
}
bool ExplicitSubset::setMembers(const std::set<smtk::markup::AssignedIds::IdType>& members)
{
if (m_members == members)
......
......@@ -22,14 +22,11 @@ public:
{
}
template<typename... Args>
ExplicitSubset(const nlohmann::json* j, Args&&... args)
: smtk::markup::Subset(std::forward<Args>(args)...)
{
}
~ExplicitSubset() override;
/// Provide an initializer for resources to call after construction.
void initialize(const nlohmann::json& data, json::Helper& helper) override;
bool setMembers(const std::set<smtk::markup::AssignedIds::IdType>& members);
const std::set<smtk::markup::AssignedIds::IdType>& members() const;
std::set<smtk::markup::AssignedIds::IdType>& members();
......
......@@ -11,6 +11,10 @@ namespace markup
Field::~Field() = default;
void Field::initialize(const nlohmann::json& data, json::Helper& helper)
{
}
std::string Field::name() const
{
return m_name.data();
......
......@@ -27,14 +27,11 @@ public:
{
}
template<typename... Args>
Field(const nlohmann::json* j, Args&&... args)
: smtk::markup::Component(std::forward<Args>(args)...)
{
}
~Field() override;
/// Provide an initializer for resources to call after construction.
void initialize(const nlohmann::json& data, json::Helper& helper) override;
std::string name() const;
bool setName(const smtk::string::Token& name);
......
......@@ -8,6 +8,10 @@ namespace markup
Frame::~Frame() = default;
void Frame::initialize(const nlohmann::json& data, json::Helper& helper)
{
}
bool Frame::setAxes(const std::vector<std::vector<double>>& axes)
{
if (m_axes == axes)
......
......@@ -22,14 +22,11 @@ public:
{
}
template<typename... Args>
Frame(const nlohmann::json* j, Args&&... args)
: smtk::markup::SpatialData(std::forward<Args>(args)...)
{
}
~Frame() override;
/// Provide an initializer for resources to call after construction.
void initialize(const nlohmann::json& data, json::Helper& helper) override;
bool setAxes(const std::vector<std::vector<double>>& axes);
const std::vector<std::vector<double>>& axes() const;
std::vector<std::vector<double>>& axes();
......
......@@ -8,6 +8,10 @@ namespace markup
Grid::~Grid() = default;
void Grid::initialize(const nlohmann::json& data, json::Helper& helper)
{
}
bool Grid::setPoints(const std::weak_ptr<smtk::markup::AssignedIds>& points)
{
auto mlocked = m_points.lock();
......
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