Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 19 additions & 34 deletions src/gui/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This file is part of Gambit
// Copyright (c) 1994-2026, The Gambit Project (https://www.gambit-project.org)
//
// FILE: src/gui/gambit.cc
// FILE: src/gui/app.cc
// Implementation of main wxApp class
//
// This program is free software; you can redistribute it and/or modify
Expand All @@ -20,8 +20,6 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//

#include <fstream>

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
Expand Down Expand Up @@ -181,48 +179,35 @@ class FileErrorDialog final : public wxDialog {

AppLoadResult Application::LoadFile(const wxString &p_filename, wxWindow *p_parent)
{
std::ifstream infile(p_filename.mb_str());
if (!infile.good()) {
const auto [result, doc] = GameDocument::Load(p_filename);

switch (result) {
case GameDocument::LoadResult::OpenFailed:
FileErrorDialog(p_parent, _("Unable to open file"),
_("Gambit could not open this file for reading."), p_filename)
.ShowModal();
return AppLoadResult::OpenFailed;
}

auto *doc = new GameDocument(NewTree());
if (doc->LoadWorkspace(p_filename)) {
doc->SetFilename(p_filename);
m_fileHistory.AddFileToHistory(p_filename);
m_fileHistory.Save(*wxConfigBase::Get());
(void)new GameFrame(nullptr, doc);
return AppLoadResult::Success;
}
delete doc;

try {
const Game game = ReadGame(infile);
if (game->IsAgg()) {
FileErrorDialog(p_parent, _("Unsupported game representation"),
_("Action graph games are not currently supported by the "
"graphical interface."),
p_filename)
.ShowModal();
return AppLoadResult::UnsupportedRepresentation;
}
case GameDocument::LoadResult::ParseFailed:
FileErrorDialog(p_parent, _("Unable to read file"),
_("File is not in a format Gambit recognizes."), p_filename)
.ShowModal();
return AppLoadResult::ParseFailed;

case GameDocument::LoadResult::UnsupportedRepresentation:
FileErrorDialog(p_parent, _("Unsupported game representation"),
_("Action graph games are not currently supported by the "
"graphical interface."),
p_filename)
.ShowModal();
return AppLoadResult::UnsupportedRepresentation;

case GameDocument::LoadResult::Success:
m_fileHistory.AddFileToHistory(p_filename);
m_fileHistory.Save(*wxConfigBase::Get());
doc = new GameDocument(game);
doc->SetFilename(p_filename);
(void)new GameFrame(nullptr, doc);
return AppLoadResult::Success;
}
catch (InvalidFileException &) {
FileErrorDialog(p_parent, _("Unable to read file"),
_("File is not in a format Gambit recognizes."), p_filename)
.ShowModal();
return AppLoadResult::ParseFailed;
}
}

void Application::SetCurrentDir(const wxString &p_dir)
Expand Down
8 changes: 4 additions & 4 deletions src/gui/dlefglogit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ namespace Gambit::GUI {
//! isn't resized/repainted on every single profile received.
//!
class LogitBehavTable final : public wxGridTableBase {
GameDocument *m_doc;
std::shared_ptr<GameDocument> m_doc;
Array<double> m_lambdas;
Array<std::shared_ptr<MixedBehaviorProfile<double>>> m_profiles;
int m_numCols{0};
int m_numRows{0};

public:
explicit LogitBehavTable(GameDocument *p_doc) : m_doc(p_doc) {}
explicit LogitBehavTable(const std::shared_ptr<GameDocument> &p_doc) : m_doc(p_doc) {}

int GetNumberRows() override { return m_numRows; }
int GetNumberCols() override { return m_numCols; }
Expand Down Expand Up @@ -172,7 +172,7 @@ class LogitBehavGrid final : public wxGrid {
//@}

public:
LogitBehavGrid(wxWindow *p_parent, GameDocument *p_doc)
LogitBehavGrid(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc)
: wxGrid(p_parent, wxID_ANY), m_gridTable(new LogitBehavTable(p_doc))
{
SetTable(m_gridTable, true);
Expand Down Expand Up @@ -258,7 +258,7 @@ class LogitBehavThreadRunner final : public wxThread {
void RequestCancel() { m_cancel.RequestCancel(); }
};

LogitBehavDialog::LogitBehavDialog(wxWindow *p_parent, GameDocument *p_doc)
LogitBehavDialog::LogitBehavDialog(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc)
: wxDialog(p_parent, wxID_ANY, wxT("Compute quantal response equilibria"), wxDefaultPosition),
m_doc(p_doc), m_behavList(new LogitBehavGrid(this, m_doc))
{
Expand Down
4 changes: 2 additions & 2 deletions src/gui/dlefglogit.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class LogitBehavGrid;
class LogitBehavThreadRunner;

class LogitBehavDialog final : public wxDialog {
GameDocument *m_doc;
std::shared_ptr<GameDocument> m_doc;
std::unique_ptr<LogitBehavThreadRunner> m_runner;
LogitBehavGrid *m_behavList;
wxStaticText *m_statusText;
Expand All @@ -47,7 +47,7 @@ class LogitBehavDialog final : public wxDialog {
void Start();

public:
LogitBehavDialog(wxWindow *p_parent, GameDocument *p_doc);
LogitBehavDialog(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc);
~LogitBehavDialog() override;
};

Expand Down
9 changes: 5 additions & 4 deletions src/gui/dlgameprop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class PlayerLabelPanel final : public wxPanel {
};

private:
GameDocument *m_doc;
std::shared_ptr<GameDocument> m_doc;
std::vector<Row> m_rows;
wxColour m_defaultBg;
std::function<void()> m_onChanged;
Expand All @@ -87,7 +87,7 @@ class PlayerLabelPanel final : public wxPanel {
wxBitmapButton *MakeColorButton(int p_index);

public:
PlayerLabelPanel(wxWindow *p_parent, GameDocument *p_doc,
PlayerLabelPanel(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc,
const std::function<void()> &p_onChanged);

int NumRows() const { return static_cast<int>(m_rows.size()); }
Expand All @@ -106,7 +106,7 @@ class PlayerLabelPanel final : public wxPanel {
wxString ValidateLabels();
};

PlayerLabelPanel::PlayerLabelPanel(wxWindow *p_parent, GameDocument *p_doc,
PlayerLabelPanel::PlayerLabelPanel(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc,
const std::function<void()> &p_onChanged)
: wxPanel(p_parent, wxID_ANY), m_doc(p_doc), m_onChanged(p_onChanged)
{
Expand Down Expand Up @@ -247,7 +247,8 @@ wxString PlayerLabelPanel::ValidateLabels()
// class GamePropertiesDialog
//========================================================================

GamePropertiesDialog::GamePropertiesDialog(wxWindow *p_parent, GameDocument *p_doc)
GamePropertiesDialog::GamePropertiesDialog(wxWindow *p_parent,
const std::shared_ptr<GameDocument> &p_doc)
: wxDialog(p_parent, wxID_ANY, _("Game properties"), wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
m_doc(p_doc)
Expand Down
4 changes: 2 additions & 2 deletions src/gui/dlgameprop.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Gambit::GUI {
class PlayerLabelPanel;

class GamePropertiesDialog final : public wxDialog {
GameDocument *m_doc;
std::shared_ptr<GameDocument> m_doc;
wxTextCtrl *m_title, *m_comment;
PlayerLabelPanel *m_playerPanel;
wxStaticText *m_errorText;
Expand All @@ -37,7 +37,7 @@ class GamePropertiesDialog final : public wxDialog {

public:
// Lifecycle
GamePropertiesDialog(wxWindow *p_parent, GameDocument *p_doc);
GamePropertiesDialog(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc);

// Data access (only valid when ShowModal() returns with wxID_OK)
wxString GetTitle() const override { return m_title->GetValue(); }
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dlinsertmove.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Gambit::GUI {
// InsertMoveDialog: Member functions
//=========================================================================

InsertMoveDialog::InsertMoveDialog(wxWindow *p_parent, GameDocument *p_doc)
InsertMoveDialog::InsertMoveDialog(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc)
: wxDialog(p_parent, wxID_ANY, _("Insert Move"), wxDefaultPosition), m_doc(p_doc)
{
m_playerItem = new wxChoice(this, wxID_ANY);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/dlinsertmove.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace Gambit::GUI {

class InsertMoveDialog final : public wxDialog {
GameDocument *m_doc;
std::shared_ptr<GameDocument> m_doc;

wxChoice *m_playerItem, *m_infosetItem;
wxSpinCtrl *m_actions;
Expand All @@ -39,7 +39,7 @@ class InsertMoveDialog final : public wxDialog {

public:
// Constructor
InsertMoveDialog(wxWindow *, GameDocument *);
InsertMoveDialog(wxWindow *, const std::shared_ptr<GameDocument> &);

// Data access (only valid if ShowModal() returns wxID_OK.
// If GetInfoset() returns null, user selected "new infoset"
Expand Down
6 changes: 3 additions & 3 deletions src/gui/dlnash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ wxString ParameterDescription(const NashMethodSpec &p_method)

} // namespace

NashChoiceDialog::NashChoiceDialog(wxWindow *p_parent, GameDocument *p_doc)
NashChoiceDialog::NashChoiceDialog(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc)
: wxDialog(p_parent, wxID_ANY, wxT("Compute Nash equilibria"), wxDefaultPosition), m_doc(p_doc)
{
auto *topSizer = new wxBoxSizer(wxVERTICAL);
Expand Down Expand Up @@ -432,10 +432,10 @@ std::shared_ptr<AnalysisOutput> NashChoiceDialog::GetCommand() const
const bool useBehavior = computation.representation == NashRepresentation::Behavior;
std::shared_ptr<AnalysisOutput> output;
if (UsesRationalOutput(computation.method)) {
output = std::make_shared<AnalysisProfileList<Rational>>(m_doc, useBehavior);
output = std::make_shared<AnalysisProfileList<Rational>>(m_doc.get(), useBehavior);
}
else {
output = std::make_shared<AnalysisProfileList<double>>(m_doc, useBehavior);
output = std::make_shared<AnalysisProfileList<double>>(m_doc.get(), useBehavior);
}

wxString count;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/dlnash.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace Gambit::GUI {
class NashChoiceDialog final : public wxDialog {
GameDocument *m_doc;
std::shared_ptr<GameDocument> m_doc;
wxChoice *m_countChoice, *m_methodChoice, *m_repChoice;

// Event handlers
Expand All @@ -38,7 +38,7 @@ class NashChoiceDialog final : public wxDialog {
NashComputationSpec GetComputation() const;

public:
NashChoiceDialog(wxWindow *, GameDocument *);
NashChoiceDialog(wxWindow *, const std::shared_ptr<GameDocument> &);

std::shared_ptr<AnalysisOutput> GetCommand() const;

Expand Down
9 changes: 5 additions & 4 deletions src/gui/dlnashmon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class SolverThreadRunner final : public wxThread {
};

class NashMonitorDialog final : public wxDialog {
GameDocument *m_doc;
std::shared_ptr<GameDocument> m_doc;
std::unique_ptr<class ExternalProcessRunner> m_runner;
std::unique_ptr<class SolverThreadRunner> m_threadRunner;
wxWindow *m_profileList;
Expand Down Expand Up @@ -354,11 +354,12 @@ class NashMonitorDialog final : public wxDialog {
}

public:
NashMonitorDialog(wxWindow *p_parent, GameDocument *p_doc,
NashMonitorDialog(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc,
const std::shared_ptr<AnalysisOutput> &p_command);
};

NashMonitorDialog::NashMonitorDialog(wxWindow *p_parent, GameDocument *p_doc,
NashMonitorDialog::NashMonitorDialog(wxWindow *p_parent,
const std::shared_ptr<GameDocument> &p_doc,
const std::shared_ptr<AnalysisOutput> &p_command)
: wxDialog(p_parent, wxID_ANY, wxT("Computing Nash equilibria"), wxDefaultPosition),
m_doc(p_doc), m_output(p_command)
Expand Down Expand Up @@ -547,7 +548,7 @@ void NashMonitorDialog::OnClose(wxCloseEvent &p_event)

namespace Gambit::GUI {

void ShowNashMonitorDialog(wxWindow *p_parent, GameDocument *p_doc,
void ShowNashMonitorDialog(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc,
const std::shared_ptr<AnalysisOutput> &p_command)
{
NashMonitorDialog dialog(p_parent, p_doc, p_command);
Expand Down
10 changes: 5 additions & 5 deletions src/gui/dlnfglogit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ namespace Gambit::GUI {
//! isn't resized/repainted on every single profile received.
//!
class LogitMixedTable final : public wxGridTableBase {
GameDocument *m_doc;
std::shared_ptr<GameDocument> m_doc;
Array<double> m_lambdas;
Array<std::shared_ptr<MixedStrategyProfile<double>>> m_profiles;
int m_numCols{0};
int m_numRows{0};

public:
explicit LogitMixedTable(GameDocument *p_doc) : m_doc(p_doc) {}
explicit LogitMixedTable(const std::shared_ptr<GameDocument> &p_doc) : m_doc(p_doc) {}

int GetNumberRows() override { return m_numRows; }
int GetNumberCols() override { return m_numCols; }
Expand Down Expand Up @@ -175,7 +175,7 @@ class LogitMixedGrid final : public wxGrid {
//@}

public:
LogitMixedGrid(wxWindow *p_parent, GameDocument *p_doc)
LogitMixedGrid(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc)
: wxGrid(p_parent, wxID_ANY), m_gridTable(new LogitMixedTable(p_doc))
{
SetTable(m_gridTable, true);
Expand Down Expand Up @@ -261,7 +261,7 @@ class LogitMixedThreadRunner final : public wxThread {
void RequestCancel() { m_cancel.RequestCancel(); }
};

LogitMixedDialog::LogitMixedDialog(wxWindow *p_parent, GameDocument *p_doc)
LogitMixedDialog::LogitMixedDialog(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc)
: wxDialog(p_parent, wxID_ANY, wxT("Compute quantal response equilibria"), wxDefaultPosition),
m_doc(p_doc), m_mixedList(new LogitMixedGrid(this, m_doc))
{
Expand Down Expand Up @@ -412,7 +412,7 @@ void LogitMixedDialog::OnSave(wxCommandEvent &)
}
}

void LogitStrategic(wxWindow *p_parent, GameDocument *p_doc)
void LogitStrategic(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc)
{
LogitMixedDialog(p_parent, p_doc).ShowModal();
}
Expand Down
6 changes: 3 additions & 3 deletions src/gui/dlnfglogit.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class LogitMixedGrid;
class LogitMixedThreadRunner;

class LogitMixedDialog final : public wxDialog {
GameDocument *m_doc;
std::shared_ptr<GameDocument> m_doc;
std::unique_ptr<LogitMixedThreadRunner> m_runner;
LogitMixedGrid *m_mixedList;
wxStaticText *m_statusText;
Expand All @@ -47,11 +47,11 @@ class LogitMixedDialog final : public wxDialog {
void Start();

public:
LogitMixedDialog(wxWindow *p_parent, GameDocument *p_doc);
LogitMixedDialog(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc);
~LogitMixedDialog() override;
};

void LogitStrategic(wxWindow *p_parent, GameDocument *p_doc);
void LogitStrategic(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc);

} // namespace Gambit::GUI

Expand Down
2 changes: 1 addition & 1 deletion src/gui/efgdisplay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ END_EVENT_TABLE()
// EfgDisplay: Constructor and destructor
//----------------------------------------------------------------------

EfgDisplay::EfgDisplay(wxWindow *p_parent, GameDocument *p_doc)
EfgDisplay::EfgDisplay(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc)
: wxScrolledWindow(p_parent), GameView(p_doc), m_layout(p_doc), m_zoom(100)
{
wxWindow::SetBackgroundColour(wxColour(250, 250, 250));
Expand Down
2 changes: 1 addition & 1 deletion src/gui/efgdisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class EfgDisplay final : public wxScrolledWindow, public GameView {
void ZoomByFactor(double p_factor, const wxPoint &p_clientPoint);

public:
EfgDisplay(wxWindow *p_parent, GameDocument *p_doc);
EfgDisplay(wxWindow *p_parent, const std::shared_ptr<GameDocument> &p_doc);

void OnDraw(wxDC &dc) override;
void OnDraw(wxDC &, double);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/efgdragdrop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Gambit::GUI {

class TreeDropTarget : public wxTextDropTarget {
EfgDisplay *m_owner;
GameDocument *m_model;
std::shared_ptr<GameDocument> m_model;

bool OnDropOutcome(const GameNode &p_node, const wxString &p_text, const wxPoint &p_pos);
bool OnDropTreeNode(const GameNode &p_node, const wxString &p_text, const wxPoint &p_pos);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/efglayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class TreeLayout final : public GameView {
void BuildNodeList(const Game &);

public:
explicit TreeLayout(GameDocument *p_doc) : GameView(p_doc) {}
explicit TreeLayout(const std::shared_ptr<GameDocument> &p_doc) : GameView(p_doc) {}
~TreeLayout() override = default;

void Layout(const Game &);
Expand Down
Loading
Loading