Skip to content

Commit

Permalink
Implement prototypical ModelWarperV3 (step-by-step design) tab
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Nov 27, 2024
1 parent c143cd0 commit 7a08854
Show file tree
Hide file tree
Showing 24 changed files with 1,458 additions and 184 deletions.
5 changes: 5 additions & 0 deletions src/OpenSimCreator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ add_library(OpenSimCreator STATIC
Documents/Model/BasicModelStatePair.h
Documents/Model/Environment.cpp
Documents/Model/Environment.h
Documents/Model/IComponentAccessor.h
Documents/Model/IModelStatePair.cpp
Documents/Model/IModelStatePair.h
Documents/Model/IVersionedComponentAccessor.h
Documents/Model/ModelStateCommit.cpp
Documents/Model/ModelStateCommit.h
Documents/Model/ModelStatePairInfo.cpp
Expand Down Expand Up @@ -300,6 +303,8 @@ add_library(OpenSimCreator STATIC
UI/MeshWarper/MeshWarpingTabToolbar.cpp
UI/MeshWarper/MeshWarpingTabToolbar.h
UI/MeshWarper/MeshWarpingTabUserSelection.h
UI/ModelWarperV3/ModelWarperV3Tab.cpp
UI/ModelWarperV3/ModelWarperV3Tab.h

UI/ModelEditor/AddBodyPopup.cpp
UI/ModelEditor/AddBodyPopup.h
Expand Down
49 changes: 49 additions & 0 deletions src/OpenSimCreator/Documents/Model/IComponentAccessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

#include <oscar/Utils/UID.h>

#include <stdexcept>

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"};
}
};
}
7 changes: 7 additions & 0 deletions src/OpenSimCreator/Documents/Model/IModelStatePair.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "IModelStatePair.h"

#include <OpenSim/Common/Component.h>
#include <OpenSim/Simulation/Model/Model.h>

const OpenSim::Component& osc::IModelStatePair::implGetComponent() const { return implGetModel(); }
OpenSim::Component& osc::IModelStatePair::implUpdComponent() { return implUpdModel(); }
11 changes: 10 additions & 1 deletion src/OpenSimCreator/Documents/Model/IModelStatePair.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <OpenSimCreator/Documents/Model/IVersionedComponentAccessor.h>

#include <oscar/Utils/UID.h>

#include <filesystem>
Expand All @@ -16,7 +18,7 @@ namespace osc
{
// virtual accessor to an `OpenSim::Model` + `SimTK::State` pair, with
// additional opt-in overrides to aid rendering/UX etc.
class IModelStatePair {
class IModelStatePair : public IVersionedComponentAccessor {
protected:
IModelStatePair() = default;
IModelStatePair(const IModelStatePair&) = default;
Expand Down Expand Up @@ -93,6 +95,13 @@ namespace osc
void setUpToDateWithFilesystem(std::filesystem::file_time_type t) { implSetUpToDateWithFilesystem(t); }

private:
// overrides + specializes `IComponentAccessor` API
const OpenSim::Component& implGetComponent() const final;
bool implCanUpdComponent() const { return implCanUpdModel(); }
OpenSim::Component& implUpdComponent() final;
UID implGetComponentVersion() const final { return implGetModelVersion(); }
void implSetComponentVersion(UID newVersion) final { implSetModelVersion(newVersion); }

// Implementors should return a const reference to an initialized (finalized properties, etc.) model.
virtual const OpenSim::Model& implGetModel() const = 0;

Expand Down
24 changes: 24 additions & 0 deletions src/OpenSimCreator/Documents/Model/IVersionedComponentAccessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <OpenSimCreator/Documents/Model/IComponentAccessor.h>

namespace osc
{
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{};
}

// Implementors may use this to manually set the version of the component (sometimes useful for caching)
virtual void implSetComponentVersion(UID) {}
};
}
2 changes: 1 addition & 1 deletion src/OpenSimCreator/UI/ModelEditor/AddComponentPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class osc::AddComponentPopup::Impl final : public StandardPopup {
StandardPopup{popupName},
m_Model{std::move(model)},
m_Proto{std::move(prototype)},
m_PrototypePropertiesEditor{parent, m_Model, [proto = m_Proto]() { return proto.get(); }}
m_PrototypePropertiesEditor{&parent, m_Model, [proto = m_Proto]() { return proto.get(); }}
{}

private:
Expand Down
Loading

0 comments on commit 7a08854

Please sign in to comment.