SPH
SessionDialog.cpp
Go to the documentation of this file.
2 #include "run/jobs/Presets.h"
3 #include <wx/button.h>
4 #include <wx/listbox.h>
5 #include <wx/msgdlg.h>
6 #include <wx/radiobut.h>
7 #include <wx/sizer.h>
8 #include <wx/stattext.h>
9 
11 
13  : wxDialog(parent, wxID_ANY, "New session", wxDefaultPosition, wxSize(500, 400)) {
14 
15  wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
16  sizer->Add(new wxStaticText(this, wxID_ANY, "New session:"));
17 
18  wxRadioButton* emptyButton =
19  new wxRadioButton(this, wxID_ANY, "Empty session", wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
20  sizer->Add(emptyButton);
21 
22  wxRadioButton* presetButton = new wxRadioButton(this, wxID_ANY, "Select a preset:");
23  sizer->Add(presetButton);
24 
25  wxArrayString options;
26  for (Presets::Id id : EnumMap::getAll<Presets::Id>()) {
27  std::string name = replaceAll(EnumMap::toString(id), "_", " ");
28  options.Add(name);
29  }
30  int height = this->GetClientSize().y - 100;
31  wxListBox* list =
32  new wxListBox(this, wxID_ANY, wxDefaultPosition, wxSize(450, height), options, wxLB_SINGLE);
33  list->Enable(false);
34  sizer->Add(list, 0, wxALIGN_CENTER_HORIZONTAL);
35 
36  emptyButton->Bind(wxEVT_RADIOBUTTON, [list](wxCommandEvent&) { list->Enable(false); });
37  presetButton->Bind(wxEVT_RADIOBUTTON, [list](wxCommandEvent&) { list->Enable(true); });
38 
39  sizer->AddSpacer(5);
40  wxBoxSizer* buttonSizer = new wxBoxSizer(wxHORIZONTAL);
41  wxButton* createButton = new wxButton(this, wxID_ANY, "Create");
42  wxButton* cancelButton = new wxButton(this, wxID_ANY, "Cancel");
43  buttonSizer->Add(createButton);
44  buttonSizer->Add(cancelButton);
45  sizer->Add(buttonSizer, 0, wxALIGN_RIGHT);
46 
47  auto createSession = [=, &nameMgr](wxCommandEvent& UNUSED(evt)) {
48  if (presetButton->GetValue()) {
49  int idx = list->GetSelection();
50  if (idx == wxNOT_FOUND) {
51  wxMessageBox("Select a preset to create", "No preset", wxOK | wxCENTRE);
52  return;
53  } else {
54  Presets::Id id = Presets::Id(idx);
55  preset = Presets::make(id, nameMgr);
56 
58  }
59  }
60  this->EndModal(wxID_OK);
61  };
62  list->Bind(wxEVT_LISTBOX_DCLICK, createSession);
63  createButton->Bind(wxEVT_BUTTON, createSession);
64  cancelButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent& UNUSED(evt)) { this->EndModal(wxID_CANCEL); });
65 
66  this->SetSizer(sizer);
67 }
68 
70 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
std::string replaceAll(const std::string &source, const std::string &old, const std::string &s)
Replaces all occurences of string with a new string.
static std::string toString(const TEnum value)
Definition: EnumMap.h:67
SessionDialog(wxWindow *parent, UniqueNameManager &nameMgr)
SharedPtr< JobNode > make(const Id id, UniqueNameManager &nameMgr, const Size particleCnt=10000)
Creates a node tree for the preset with given ID.
Definition: Presets.cpp:39