Skip to content

Commit

Permalink
Add enabled flag to model warper ScalingStep
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Nov 28, 2024
1 parent 85c8263 commit 925256b
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 184 deletions.
10 changes: 10 additions & 0 deletions src/OpenSimCreator/Documents/Model/BasicModelStatePair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class osc::BasicModelStatePair::Impl final {
InitializeState(*m_Model);
}

explicit Impl(OpenSim::Model&& model) :
m_Model{std::make_unique<OpenSim::Model>(std::move(model))}
{
InitializeModel(*m_Model);
InitializeState(*m_Model);
}

Impl(const OpenSim::Model& m, const SimTK::State& st) :
Impl{m, st, 1.0f}
{}
Expand Down Expand Up @@ -113,6 +120,9 @@ osc::BasicModelStatePair::BasicModelStatePair(const IModelStatePair& p) :
osc::BasicModelStatePair::BasicModelStatePair(const std::filesystem::path& p) :
m_Impl{std::make_unique<Impl>(p)}
{}
osc::BasicModelStatePair::BasicModelStatePair(OpenSim::Model&& model) :
m_Impl{std::make_unique<Impl>(std::move(model))}
{}

osc::BasicModelStatePair::BasicModelStatePair(const OpenSim::Model& model, const SimTK::State& state) :
m_Impl{std::make_unique<Impl>(model, state)}
Expand Down
1 change: 1 addition & 0 deletions src/OpenSimCreator/Documents/Model/BasicModelStatePair.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace osc
BasicModelStatePair();
explicit BasicModelStatePair(const IModelStatePair&);
explicit BasicModelStatePair(const std::filesystem::path&);
explicit BasicModelStatePair(OpenSim::Model&&);
BasicModelStatePair(const OpenSim::Model&, const SimTK::State&);
BasicModelStatePair(const BasicModelStatePair&);
BasicModelStatePair(BasicModelStatePair&&) noexcept;
Expand Down
76 changes: 38 additions & 38 deletions src/OpenSimCreator/Documents/Model/IComponentAccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,42 @@ namespace OpenSim { class Component; }

namespace osc
{
class IComponentAccessor {
protected:
IComponentAccessor() = default;
IComponentAccessor(const IComponentAccessor&) = default;
IComponentAccessor(IComponentAccessor&&) noexcept = default;
IComponentAccessor& operator=(const IComponentAccessor&) = default;
IComponentAccessor& operator=(IComponentAccessor&&) noexcept = default;

friend bool operator==(const IComponentAccessor&, const IComponentAccessor&) = default;
public:
virtual ~IComponentAccessor() noexcept = default;

const OpenSim::Component& getComponent() const { return implGetComponent(); }
operator const OpenSim::Component& () const { return getComponent(); }

bool isReadonly() const { return not implCanUpdComponent(); }
bool canUpdComponent() const { return implCanUpdComponent(); }
OpenSim::Component& updComponent() { return implUpdComponent(); }

private:
// Implementors should return a const reference to an initialized (finalized properties, etc.) component
virtual const OpenSim::Component& implGetComponent() const = 0;

// Implementors may return whether the component contained by the concrete `IComponentAccessor` implementation
// can be modified in-place.
//
// If the response can be `true`, implementors must also override `implUpdComponent` accordingly.
virtual bool implCanUpdComponent() const { return false; }

// Implementors may return a mutable reference to the contained component. It is up to the caller
// of `updComponent` to ensure that the component is still valid + initialized after modification.
//
// If this is implemented, implementors should override `implCanUpdComponent` accordingly.
virtual OpenSim::Component& implUpdComponent()
{
throw std::runtime_error{"component updating not implemented for this IComponentAccessor"};
}
};
class IComponentAccessor {
protected:
IComponentAccessor() = default;
IComponentAccessor(const IComponentAccessor&) = default;
IComponentAccessor(IComponentAccessor&&) noexcept = default;
IComponentAccessor& operator=(const IComponentAccessor&) = default;
IComponentAccessor& operator=(IComponentAccessor&&) noexcept = default;

friend bool operator==(const IComponentAccessor&, const IComponentAccessor&) = default;
public:
virtual ~IComponentAccessor() noexcept = default;

const OpenSim::Component& getComponent() const { return implGetComponent(); }
operator const OpenSim::Component& () const { return getComponent(); }

bool isReadonly() const { return not implCanUpdComponent(); }
bool canUpdComponent() const { return implCanUpdComponent(); }
OpenSim::Component& updComponent() { return implUpdComponent(); }

private:
// Implementors should return a const reference to an initialized (finalized properties, etc.) component
virtual const OpenSim::Component& implGetComponent() const = 0;

// Implementors may return whether the component contained by the concrete `IComponentAccessor` implementation
// can be modified in-place.
//
// If the response can be `true`, implementors must also override `implUpdComponent` accordingly.
virtual bool implCanUpdComponent() const { return false; }

// Implementors may return a mutable reference to the contained component. It is up to the caller
// of `updComponent` to ensure that the component is still valid + initialized after modification.
//
// If this is implemented, implementors should override `implCanUpdComponent` accordingly.
virtual OpenSim::Component& implUpdComponent()
{
throw std::runtime_error{"component updating not implemented for this IComponentAccessor"};
}
};
}
30 changes: 15 additions & 15 deletions src/OpenSimCreator/Documents/Model/IVersionedComponentAccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

namespace osc
{
class IVersionedComponentAccessor : public IComponentAccessor {
public:
UID getComponentVersion() const { return implGetComponentVersion(); }
void setComponentVersion(UID id) { implSetComponentVersion(id); }
class IVersionedComponentAccessor : public IComponentAccessor {
public:
UID getComponentVersion() const { return implGetComponentVersion(); }
void setComponentVersion(UID id) { implSetComponentVersion(id); }

private:
// Implementors may return a `UID` that uniquely identifies the current version of the component.
virtual UID implGetComponentVersion() const
{
// assume the version always changes, unless the concrete implementation
// provides a way of knowing when it doesn't
return UID{};
}
private:
// Implementors may return a `UID` that uniquely identifies the current version of the component.
virtual UID implGetComponentVersion() const
{
// assume the version always changes, unless the concrete implementation
// provides a way of knowing when it doesn't
return UID{};
}

// Implementors may use this to manually set the version of the component (sometimes useful for caching)
virtual void implSetComponentVersion(UID) {}
};
// Implementors may use this to manually set the version of the component (sometimes useful for caching)
virtual void implSetComponentVersion(UID) {}
};
}
Loading

0 comments on commit 925256b

Please sign in to comment.