SPH
GuiSettingsDialog.cpp
Go to the documentation of this file.
2 #include "gui/Factory.h"
3 #include "gui/Project.h"
4 #include "gui/Utils.h"
6 #include "gui/windows/Widgets.h"
7 #include "io/Path.h"
8 #include <wx/button.h>
9 #include <wx/checkbox.h>
10 #include <wx/combobox.h>
11 #include <wx/sizer.h>
12 #include <wx/statbox.h>
13 #include <wx/stattext.h>
14 
16 
17 const static FlatMap<PlotEnum, wxString> sPlotTypes = {
18  { PlotEnum::TOTAL_MOMENTUM, "Total momentum" },
19  { PlotEnum::TOTAL_ANGULAR_MOMENTUM, "Total angular momentum" },
20  { PlotEnum::INTERNAL_ENERGY, "Total internal energy" },
21  { PlotEnum::KINETIC_ENERGY, "Total kinetic energy" },
22  { PlotEnum::TOTAL_ENERGY, "Total energy" },
23  { PlotEnum::RELATIVE_ENERGY_CHANGE, "Relative change of total energy" },
24  { PlotEnum::CURRENT_SFD, "Current SFD" },
25  { PlotEnum::PREDICTED_SFD, "Predicted SFD" },
26  { PlotEnum::SPEED_HISTOGRAM, "Speed histogram" },
27  { PlotEnum::ANGULAR_HISTOGRAM_OF_VELOCITIES, "Angular histogram of velocities" },
28  { PlotEnum::SELECTED_PARTICLE, "Selected particle" },
29 };
30 
32  : wxDialog(parent, wxID_ANY, "Visualization settings", wxDefaultPosition, wxSize(500, 340)) {
33  const Project& project = Project::getInstance();
34  const GuiSettings& gui = project.getGuiSettings();
35 
36  wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
37 
38  wxStaticBoxSizer* renderBox = new wxStaticBoxSizer(wxVERTICAL, this, "Rendering");
39 
40  wxBoxSizer* colorizerSizer = new wxBoxSizer(wxHORIZONTAL);
41  wxStaticText* colorizerText = new wxStaticText(renderBox->GetStaticBox(), wxID_ANY, "Default quantity");
42  colorizerSizer->Add(colorizerText, 0, wxALIGN_CENTER_VERTICAL);
43  colorizerSizer->AddStretchSpacer(1);
44  colorizerBox = new ComboBox(renderBox->GetStaticBox(), "");
46  colorizerIds = getColorizerIds();
47  for (const ExtColorizerId& id : colorizerIds) {
48  SharedPtr<IColorizer> colorizer = Factory::getColorizer(project, id);
49  colorizerBox->Append(colorizer->name());
50  if (id == defaultId) {
51  colorizerBox->SetSelection(colorizerBox->GetCount() - 1);
52  }
53  }
54  colorizerSizer->Add(colorizerBox, 1, wxEXPAND);
55  renderBox->Add(colorizerSizer);
56 
57  sizer->Add(renderBox, 1, wxEXPAND);
58 
59 
60  wxStaticBoxSizer* plotBox = new wxStaticBoxSizer(wxVERTICAL, this, "Plots");
61  wxGridSizer* plotGrid = new wxGridSizer(2, 1, 1);
63  wxCheckBox* sfdCheck1 = nullptr;
64  wxCheckBox* sfdCheck2 = nullptr;
65  for (const auto& p : sPlotTypes) {
66  wxCheckBox* check = new wxCheckBox(plotBox->GetStaticBox(), wxID_ANY, p.value);
67  check->SetValue(plotFlags.has(p.key));
68  if (p.key == PlotEnum::CURRENT_SFD) {
69  sfdCheck1 = check;
70  } else if (p.key == PlotEnum::PREDICTED_SFD) {
71  sfdCheck2 = check;
72  }
73  plotGrid->Add(check);
74  plotBoxMap.insert(check, p.key);
75  }
76  plotBox->Add(plotGrid);
77  sizer->Add(plotBox, 1, wxEXPAND);
78 
79  wxBoxSizer* periodSizer = new wxBoxSizer(wxHORIZONTAL);
80  wxStaticText* periodText = new wxStaticText(plotBox->GetStaticBox(), wxID_ANY, "Initial period [s]");
81  periodSizer->Add(periodText, 0, wxALIGN_CENTER_VERTICAL);
83  periodCtrl = new FloatTextCtrl(plotBox->GetStaticBox(), period, Interval(0._f, LARGE));
84  periodSizer->AddStretchSpacer(1);
85  periodSizer->Add(periodCtrl, 0, wxALIGN_CENTER_VERTICAL);
86  plotBox->Add(periodSizer, 1, wxEXPAND);
87 
88  wxBoxSizer* overplotSizer = new wxBoxSizer(wxHORIZONTAL);
89  wxStaticText* overplotText = new wxStaticText(plotBox->GetStaticBox(), wxID_ANY, "Reference SFD");
90  overplotSizer->Add(overplotText, 0, wxALIGN_CENTER_VERTICAL);
91  const std::string overplotSfd = gui.get<std::string>(GuiSettingsId::PLOT_OVERPLOT_SFD);
92  overplotPath = new wxTextCtrl(plotBox->GetStaticBox(), wxID_ANY, overplotSfd);
93  overplotPath->Enable(plotFlags.hasAny(PlotEnum::CURRENT_SFD, PlotEnum::PREDICTED_SFD));
94  overplotPath->SetMinSize(wxSize(250, -1));
95  overplotSizer->AddStretchSpacer(1);
96  overplotSizer->Add(overplotPath, 0, wxALIGN_CENTER_VERTICAL);
97  wxButton* overplotBrowse = new wxButton(plotBox->GetStaticBox(), wxID_ANY, "Select...");
98  overplotBrowse->Enable(plotFlags.hasAny(PlotEnum::CURRENT_SFD, PlotEnum::PREDICTED_SFD));
99  overplotSizer->Add(overplotBrowse, 0, wxALIGN_CENTER_VERTICAL);
100  plotBox->Add(overplotSizer, 1, wxEXPAND);
101 
102  sizer->AddSpacer(8);
103  wxBoxSizer* buttonSizer = new wxBoxSizer(wxHORIZONTAL);
104  wxButton* okButton = new wxButton(this, wxID_ANY, "OK");
105  wxButton* cancelButton = new wxButton(this, wxID_ANY, "Cancel");
106  buttonSizer->AddStretchSpacer(1);
107  buttonSizer->Add(okButton);
108  buttonSizer->Add(cancelButton);
109  sizer->Add(buttonSizer, 1, wxEXPAND);
110 
111  this->SetSizer(sizer);
112  this->Layout();
113 
114  auto enableOverplot = [=](wxCommandEvent& UNUSED(evt)) {
115  const bool doEnable = sfdCheck1->IsChecked() || sfdCheck2->IsChecked();
116  overplotPath->Enable(doEnable);
117  overplotBrowse->Enable(doEnable);
118  };
119  sfdCheck1->Bind(wxEVT_CHECKBOX, enableOverplot);
120  sfdCheck2->Bind(wxEVT_CHECKBOX, enableOverplot);
121 
122  overplotBrowse->Bind(wxEVT_BUTTON, [this](wxCommandEvent& UNUSED(evt)) {
123  Optional<Path> path = doOpenFileDialog("Select reference SFD", {});
124  if (path) {
125  overplotPath->SetValue(path->native());
126  }
127  });
128 
129  okButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent& UNUSED(evt)) { this->commit(); });
130  cancelButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent& UNUSED(evt)) { this->EndModal(wxID_CANCEL); });
131 }
132 
133 void GuiSettingsDialog::commit() {
134  Project& project = Project::getInstance();
135  GuiSettings& gui = project.getGuiSettings();
136 
137  const int index = colorizerBox->GetSelection();
138  SPH_ASSERT(index != wxNOT_FOUND);
139  const ColorizerId id(colorizerIds[index]);
141 
142  Flags<PlotEnum> enabledPlots = EMPTY_FLAGS;
143  for (const auto& p : plotBoxMap) {
144  enabledPlots.setIf(p.value, p.key->GetValue());
145  }
146  gui.set(GuiSettingsId::PLOT_INTEGRALS, enabledPlots);
147 
149  gui.set(GuiSettingsId::PLOT_OVERPLOT_SFD, std::string(overplotPath->GetValue()));
150 
151  this->EndModal(wxID_OK);
152 }
153 
155 
#define SPH_ASSERT(x,...)
Definition: Assert.h:94
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Object converting quantity values of particles into colors.
ColorizerId
Special colorizers that do not directly correspond to quantities.
Definition: Colorizer.h:136
Array< ExtColorizerId > getColorizerIds()
Returns IDs of all colorizers available in the application.
Definition: Controller.cpp:352
const EmptyFlags EMPTY_FLAGS
Definition: Flags.h:16
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
constexpr Float LARGE
Definition: MathUtils.h:34
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
Object representing a path on a filesystem, similar to std::filesystem::path in c++17.
Optional< Path > doOpenFileDialog(const std::string &title, Array< FileFormat > &&formats)
Definition: Utils.cpp:45
Random utility functions for drawing stuff to DC.
Helper type allowing to "derive" from enum class.
Definition: ExtendedEnum.h:24
Wrapper of an integral value providing functions for reading and modifying individual bits.
Definition: Flags.h:20
constexpr INLINE bool has(const TEnum flag) const
Checks if the object has a given flag.
Definition: Flags.h:77
constexpr INLINE bool hasAny(const TEnum flag, const TArgs... others) const
Checks if the object has any of given flags.
Definition: Flags.h:83
INLINE void setIf(const TEnum flag, const bool use)
Sets or removes given flag based given boolean value.
Definition: Flags.h:108
Container of key-value pairs.
Definition: FlatMap.h:19
INLINE TValue & insert(const TKey &key, const TValue &value)
Adds a new element into the map or sets new value of element with the same key.
Definition: FlatMap.h:65
double getValue() const
Definition: Widgets.h:21
GuiSettingsDialog(wxWindow *parent)
INLINE TValue get(const GuiSettingsId id) const
Definition: Settings.h:245
INLINE GuiSettings & set(const GuiSettingsId id, const TValue &value)
Definition: Settings.h:250
virtual std::string name() const =0
Returns the name of the colorizer.
Object representing a 1D interval of real numbers.
Definition: Interval.h:17
Wrapper of type value of which may or may not be present.
Definition: Optional.h:23
GuiSettings & getGuiSettings()
Definition: Project.h:51
static Project & getInstance()
Definition: Project.h:25
Flags< TValue > getFlags(const TEnum idx) const
Returns Flags from underlying value stored in settings.
Definition: Settings.h:348
PlotEnum
Definition: Settings.h:42
@ TOTAL_MOMENTUM
Evolution of the total momentum in time.
@ SPEED_HISTOGRAM
Speed histogram.
@ INTERNAL_ENERGY
Evolution of the total internal energy in time.
@ SELECTED_PARTICLE
Evolution of the selected quantity for the selected particle in time.
@ TOTAL_ANGULAR_MOMENTUM
Evolution of the total angular momentum in time.
@ KINETIC_ENERGY
Evolution of the total kinetic energy in time.
@ RELATIVE_ENERGY_CHANGE
Relative change of total energy.
@ CURRENT_SFD
Current size-frequency distribution.
@ ANGULAR_HISTOGRAM_OF_VELOCITIES
Angular histogram (in x-y plane) of velocity directions.
@ PREDICTED_SFD
Predicted size-frequency distribution.
AutoPtr< IColorizer > getColorizer(const Project &project, const ExtColorizerId id)
Definition: Factory.cpp:198