Skip to content

Commit

Permalink
Switch many UI classes to taking a parent pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Feb 14, 2025
1 parent fdc9fcf commit 78859df
Show file tree
Hide file tree
Showing 163 changed files with 633 additions and 599 deletions.
10 changes: 5 additions & 5 deletions libopensimcreator/Documents/Model/UndoableModelActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ void osc::ActionSaveCurrentModelAs(IModelStatePair& uim)
App::singleton<RecentFiles>()->push_back(*maybePath);
}

void osc::ActionNewModel(Widget& api)
void osc::ActionNewModel(Widget& parent)
{
auto tab = std::make_unique<ModelEditorTab>(api);
App::post_event<OpenTabEvent>(api, std::move(tab));
auto tab = std::make_unique<ModelEditorTab>(&parent);
App::post_event<OpenTabEvent>(parent, std::move(tab));
}

void osc::ActionOpenModel(Widget& api)
Expand Down Expand Up @@ -417,7 +417,7 @@ bool osc::ActionLoadSTOFileAgainstModel(
InitializeState(*modelCopy);

auto simulation = std::make_shared<Simulation>(StoFileSimulation{std::move(modelCopy), stoPath, uim.getFixupScaleFactor(), uim.tryUpdEnvironment()});
auto tab = std::make_unique<SimulationTab>(parent, simulation);
auto tab = std::make_unique<SimulationTab>(&parent, simulation);
App::post_event<OpenTabEvent>(parent, std::move(tab));

return true;
Expand All @@ -436,7 +436,7 @@ bool osc::ActionStartSimulatingModel(
ForwardDynamicSimulatorParams params = FromParamBlock(uim.tryUpdEnvironment()->getSimulationParams());

auto simulation = std::make_shared<Simulation>(ForwardDynamicSimulation{std::move(modelState), params});
auto tab = std::make_unique<SimulationTab>(parent, std::move(simulation));
auto tab = std::make_unique<SimulationTab>(&parent, std::move(simulation));
App::post_event<OpenTabEvent>(parent, std::move(tab));

return true;
Expand Down
2 changes: 1 addition & 1 deletion libopensimcreator/Documents/Model/UndoableModelActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace osc

// create a new model and show it in a new tab
void ActionNewModel(
Widget&
Widget& parent
);

// prompt a user to open a model file and open it in a new tab
Expand Down
34 changes: 18 additions & 16 deletions libopensimcreator/UI/FrameDefinition/FrameDefinitionTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,14 +911,16 @@ namespace
// other panels/widgets
namespace
{
class FrameDefinitionTabMainMenu final {
class FrameDefinitionTabMainMenu final : public Widget {
public:
explicit FrameDefinitionTabMainMenu(
Widget* parent,
std::shared_ptr<UndoableModelStatePair> model_,
std::shared_ptr<PanelManager> panelManager_) :

Widget{parent},
m_Model{std::move(model_)},
m_WindowMenu{std::move(panelManager_)}
m_WindowMenu{this, std::move(panelManager_)}
{}

void onDraw()
Expand Down Expand Up @@ -952,13 +954,13 @@ namespace
class osc::FrameDefinitionTab::Impl final : public TabPrivate {
public:

explicit Impl(FrameDefinitionTab& owner, Widget& parent_) :
TabPrivate{owner, &parent_, c_TabStringID},
m_Toolbar{&parent_, "##FrameDefinitionToolbar", m_Model}
explicit Impl(FrameDefinitionTab& owner, Widget* parent_) :
TabPrivate{owner, parent_, c_TabStringID},
m_Toolbar{&owner, "##FrameDefinitionToolbar", m_Model}
{
m_PanelManager->register_toggleable_panel(
"Navigator",
[this](std::string_view panelName)
[this](Widget*, std::string_view panelName)
{
return std::make_shared<NavigatorPanel>(
panelName,
Expand All @@ -978,28 +980,28 @@ class osc::FrameDefinitionTab::Impl final : public TabPrivate {
);
m_PanelManager->register_toggleable_panel(
"Properties",
[this](std::string_view panelName)
[this](Widget* parent, std::string_view panelName)
{
return std::make_shared<PropertiesPanel>(panelName, this->owner(), m_Model);
return std::make_shared<PropertiesPanel>(parent, panelName, m_Model);
}
);
m_PanelManager->register_toggleable_panel(
"Log",
[](std::string_view panelName)
[](Widget* parent, std::string_view panelName)
{
return std::make_shared<LogViewerPanel>(panelName);
return std::make_shared<LogViewerPanel>(parent, panelName);
}
);
m_PanelManager->register_toggleable_panel(
"Performance",
[](std::string_view panelName)
[](Widget* parent, std::string_view panelName)
{
return std::make_shared<PerfPanel>(panelName);
return std::make_shared<PerfPanel>(parent, panelName);
}
);
m_PanelManager->register_spawnable_panel(
"framedef_viewer",
[this](std::string_view panelName)
[this](Widget*, std::string_view panelName)
{
ModelViewerPanelParameters panelParams
{
Expand Down Expand Up @@ -1109,16 +1111,16 @@ class osc::FrameDefinitionTab::Impl final : public TabPrivate {
}

std::shared_ptr<UndoableModelStatePair> m_Model = MakeSharedUndoableFrameDefinitionModel();
std::shared_ptr<PanelManager> m_PanelManager = std::make_shared<PanelManager>();
std::shared_ptr<PanelManager> m_PanelManager = std::make_shared<PanelManager>(&owner());
PopupManager m_PopupManager;
FrameDefinitionTabMainMenu m_MainMenu{m_Model, m_PanelManager};
FrameDefinitionTabMainMenu m_MainMenu{&owner(), m_Model, m_PanelManager};
FrameDefinitionTabToolbar m_Toolbar;
};


CStringView osc::FrameDefinitionTab::id() { return c_TabStringID; }

osc::FrameDefinitionTab::FrameDefinitionTab(Widget& parent_) :
osc::FrameDefinitionTab::FrameDefinitionTab(Widget* parent_) :
Tab{std::make_unique<Impl>(*this, parent_)}
{}
void osc::FrameDefinitionTab::impl_on_mount() { private_data().on_mount(); }
Expand Down
2 changes: 1 addition & 1 deletion libopensimcreator/UI/FrameDefinition/FrameDefinitionTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace osc
public:
static CStringView id();

explicit FrameDefinitionTab(Widget&);
explicit FrameDefinitionTab(Widget*);

private:
void impl_on_mount() final;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ void osc::fd::ActionExportFrameDefinitionSceneModelToEditorTab(
Widget& parent,
const OpenSim::Model& model)
{
auto tab = std::make_unique<ModelEditorTab>(parent, MakeUndoableModelFromSceneModel(model));
auto tab = std::make_unique<ModelEditorTab>(&parent, MakeUndoableModelFromSceneModel(model));
App::post_event<OpenTabEvent>(parent, std::move(tab));
}
9 changes: 4 additions & 5 deletions libopensimcreator/UI/LoadingTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ class osc::LoadingTab::Impl final : public TabPrivate {
// add newly-loaded model to the "Recent Files" list
App::singleton<RecentFiles>()->push_back(m_OsimPath);

// there is an existing editor state
//
// recycle it so that users can keep their running sims, local edits, etc.
App::post_event<OpenTabEvent>(*parent(), std::make_unique<ModelEditorTab>(*parent(), std::move(result)));
App::post_event<CloseTabEvent>(*parent(), id());
// Post relevant "loaded" events to this widget, which should
// propagate up to something that can handle them.
App::post_event<OpenTabEvent>(owner(), std::make_unique<ModelEditorTab>(&owner(), std::move(result)));
App::post_event<CloseTabEvent>(owner(), id());
m_IsFinishedLoading = true;
}
}
Expand Down
10 changes: 5 additions & 5 deletions libopensimcreator/UI/MainUIScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace
{
if (auto maybeRequestedTab = settings.find_value("initial_tab")) {
if (std::optional<TabRegistryEntry> maybeEntry = tabRegistry.find_by_name(to<std::string>(*maybeRequestedTab))) {
return maybeEntry->construct_tab(parent);
return maybeEntry->construct_tab(&parent);
}

log_warn("%s: cannot find a tab with this name in the tab registry: ignoring", to<std::string>(*maybeRequestedTab).c_str());
Expand Down Expand Up @@ -536,19 +536,19 @@ class osc::MainUIScreen::Impl final : public ScreenPrivate {
void drawAddNewTabMenu()
{
if (ui::draw_menu_item(OSC_ICON_EDIT " Editor")) {
impl_select_tab(addTab(std::make_unique<ModelEditorTab>(owner())));
impl_select_tab(addTab(std::make_unique<ModelEditorTab>(&owner())));
}

if (ui::draw_menu_item(OSC_ICON_CUBE " Mesh Importer")) {
impl_select_tab(addTab(std::make_unique<mi::MeshImporterTab>(owner())));
impl_select_tab(addTab(std::make_unique<mi::MeshImporterTab>(&owner())));
}

const std::shared_ptr<const TabRegistry> tabRegistry = App::singleton<TabRegistry>();
if (not tabRegistry->empty()) {
if (ui::begin_menu("Experimental Tabs")) {
for (auto&& tabRegistryEntry : *tabRegistry) {
if (ui::draw_menu_item(tabRegistryEntry.name())) {
impl_select_tab(addTab(tabRegistryEntry.construct_tab(owner())));
impl_select_tab(addTab(tabRegistryEntry.construct_tab(&owner())));
}
}
ui::end_menu();
Expand Down Expand Up @@ -728,7 +728,7 @@ class osc::MainUIScreen::Impl final : public ScreenPrivate {
}

if (m_MaybeScreenshotRequest.valid() and m_MaybeScreenshotRequest.wait_for(std::chrono::seconds{0}) == std::future_status::ready) {
const UID tabID = addTab(std::make_unique<ScreenshotTab>(owner(), m_MaybeScreenshotRequest.get()));
const UID tabID = addTab(std::make_unique<ScreenshotTab>(&owner(), m_MaybeScreenshotRequest.get()));
impl_select_tab(tabID);
}
}
Expand Down
8 changes: 4 additions & 4 deletions libopensimcreator/UI/MeshHittestTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ using namespace osc;
class osc::MeshHittestTab::Impl final : public TabPrivate {
public:

explicit Impl(MeshHittestTab& owner, Widget& parent) :
TabPrivate{owner, &parent, OSC_ICON_COOKIE " MeshHittestTab"}
explicit Impl(MeshHittestTab& owner, Widget* parent) :
TabPrivate{owner, parent, OSC_ICON_COOKIE " MeshHittestTab"}
{
m_Camera.set_background_color(Color::white());
}
Expand Down Expand Up @@ -170,13 +170,13 @@ class osc::MeshHittestTab::Impl final : public TabPrivate {
Vec3 m_HitPos = {0.0f, 0.0f, 0.0f};
Line m_Ray{};

PerfPanel m_PerfPanel;
PerfPanel m_PerfPanel{&owner()};
};


CStringView osc::MeshHittestTab::id() { return "OpenSim/MeshHittest"; }

osc::MeshHittestTab::MeshHittestTab(Widget& parent) :
osc::MeshHittestTab::MeshHittestTab(Widget* parent) :
Tab{std::make_unique<Impl>(*this, parent)}
{}
void osc::MeshHittestTab::impl_on_tick() { private_data().on_tick(); }
Expand Down
2 changes: 1 addition & 1 deletion libopensimcreator/UI/MeshHittestTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace osc
public:
static CStringView id();

explicit MeshHittestTab(Widget&);
explicit MeshHittestTab(Widget*);

private:
void impl_on_tick() final;
Expand Down
8 changes: 5 additions & 3 deletions libopensimcreator/UI/MeshImporter/MeshImporterSharedState.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ namespace osc::mi
// data that's shared between multiple UI states.
class MeshImporterSharedState final {
public:
MeshImporterSharedState() :
MeshImporterSharedState{std::vector<std::filesystem::path>{}}
MeshImporterSharedState(Widget* parent) :
MeshImporterSharedState{parent, std::vector<std::filesystem::path>{}}
{}

explicit MeshImporterSharedState(std::vector<std::filesystem::path> meshFiles)
explicit MeshImporterSharedState(Widget* parent, std::vector<std::filesystem::path> meshFiles) :
m_Logviewer{parent},
m_PerfPanel{parent}
{
m_FloorMaterial.set_transparent(true);
pushMeshLoadRequests(std::move(meshFiles));
Expand Down
22 changes: 11 additions & 11 deletions libopensimcreator/UI/MeshImporter/MeshImporterTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ class osc::mi::MeshImporterTab::Impl final :
public:
explicit Impl(
MeshImporterTab& owner,
Widget& parent_) :
Widget* parent_) :

TabPrivate{owner, &parent_, "MeshImporterTab"},
m_Shared{std::make_shared<MeshImporterSharedState>()}
TabPrivate{owner, parent_, "MeshImporterTab"},
m_Shared{std::make_shared<MeshImporterSharedState>(&owner)}
{}

explicit Impl(
MeshImporterTab& owner,
Widget& parent_,
Widget* parent_,
std::vector<std::filesystem::path> meshPaths_) :

TabPrivate{owner, &parent_, "MeshImporterTab"},
m_Shared{std::make_shared<MeshImporterSharedState>(std::move(meshPaths_))}
TabPrivate{owner, parent_, "MeshImporterTab"},
m_Shared{std::make_shared<MeshImporterSharedState>(&owner, std::move(meshPaths_))}
{}

bool isUnsaved() const
Expand Down Expand Up @@ -162,11 +162,11 @@ class osc::mi::MeshImporterTab::Impl final :
// if some screen generated an OpenSim::Model, transition to the main editor
if (m_Shared->hasOutputModel()) {
auto tab = std::make_unique<ModelEditorTab>(
*parent(),
parent(),
std::move(m_Shared->updOutputModel()),
m_Shared->getSceneScaleFactor()
);
App::post_event<OpenTabEvent>(*parent(), std::move(tab));
App::post_event<OpenTabEvent>(owner(), std::move(tab));
}

set_name(m_Shared->getRecommendedTitle());
Expand All @@ -179,7 +179,7 @@ class osc::mi::MeshImporterTab::Impl final :

if (m_Shared->isNewMeshImpoterTabRequested())
{
App::post_event<OpenTabEvent>(*parent(), std::make_unique<MeshImporterTab>(*parent()));
App::post_event<OpenTabEvent>(*parent(), std::make_unique<MeshImporterTab>(parent()));
m_Shared->resetRequestNewMeshImporter();
}
}
Expand Down Expand Up @@ -2423,12 +2423,12 @@ class osc::mi::MeshImporterTab::Impl final :


osc::mi::MeshImporterTab::MeshImporterTab(
Widget& parent_) :
Widget* parent_) :

Tab{std::make_unique<Impl>(*this, parent_)}
{}
osc::mi::MeshImporterTab::MeshImporterTab(
Widget& parent_,
Widget* parent_,
std::vector<std::filesystem::path> files_) :

Tab{std::make_unique<Impl>(*this, parent_, std::move(files_))}
Expand Down
4 changes: 2 additions & 2 deletions libopensimcreator/UI/MeshImporter/MeshImporterTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace osc::mi
public:
static CStringView id() { return "OpenSim/MeshImporter"; }

explicit MeshImporterTab(Widget&);
MeshImporterTab(Widget&, std::vector<std::filesystem::path>);
explicit MeshImporterTab(Widget*);
explicit MeshImporterTab(Widget*, std::vector<std::filesystem::path>);

private:
bool impl_is_unsaved() const final;
Expand Down
Loading

0 comments on commit 78859df

Please sign in to comment.