SPH
BatchDialog.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "gui/objects/Bitmap.h"
4 #include "run/Node.h"
5 #include <wx/dialog.h>
6 #include <wx/grid.h>
7 
9 
10 class Config;
11 
12 class BatchManager {
13 private:
14  struct Col {
15  SharedPtr<JobNode> node;
16  std::string key;
17  };
18 
19  Array<Col> cols;
20  Array<std::string> rows;
21 
22  Bitmap<std::string> cells;
23 
24 public:
26  this->resize(4, 3);
27  }
28 
29  BatchManager clone() const {
30  BatchManager copy;
31  copy.cols = cols.clone();
32  copy.rows = rows.clone();
33  copy.cells = cells.clone();
34  return copy;
35  }
36 
37  Size getRunCount() const {
38  return rows.size();
39  }
40 
41  std::string getRunName(const Size rowIdx) const {
42  if (rows[rowIdx].empty()) {
43  return "Run " + std::to_string(rowIdx + 1);
44  } else {
45  return rows[rowIdx];
46  }
47  }
48 
49  Size getParamCount() const {
50  return cols.size();
51  }
52 
53  std::string getParamKey(const Size colIdx) const {
54  return cols[colIdx].key;
55  }
56 
57  SharedPtr<JobNode> getParamNode(const Size colIdx) const {
58  return cols[colIdx].node;
59  }
60 
61  std::string getCell(const Size colIdx, const Size rowIdx) const {
62  return cells[Pixel(colIdx, rowIdx)];
63  }
64 
65  void setRunName(const Size rowIdx, const std::string& name) {
66  rows[rowIdx] = name;
67  }
68 
69  void setParam(const Size colIdx, const SharedPtr<JobNode>& node, const std::string& key) {
70  cols[colIdx].key = key;
71  cols[colIdx].node = node;
72  }
73 
74  void setCell(const Size colIdx, const Size rowIdx, const std::string& value) {
75  cells[Pixel(colIdx, rowIdx)] = value;
76  }
77 
78  void resize(const Size rowCnt, const Size colCnt) {
79  cols.resize(colCnt);
80  rows.resize(rowCnt);
81  Bitmap<std::string> oldCells = cells.clone();
82  cells.resize(Pixel(colCnt, rowCnt), "");
83 
84  const Size minRowCnt = min(cells.size().y, oldCells.size().y);
85  const Size minColCnt = min(cells.size().x, oldCells.size().x);
86  for (Size j = 0; j < minRowCnt; ++j) {
87  for (Size i = 0; i < minColCnt; ++i) {
88  cells[Pixel(i, j)] = oldCells[Pixel(i, j)];
89  }
90  }
91  }
92 
93  void duplicateRun(const Size rowIdx) {
94  const std::string runName = rows[rowIdx];
95  rows.insert(rowIdx, runName);
96 
97  Bitmap<std::string> newCells(Pixel(cols.size(), rows.size()));
98  for (Size j = 0; j < rows.size(); ++j) {
99  for (Size i = 0; i < cols.size(); ++i) {
100  const Size j0 = j <= rowIdx ? j : j - 1;
101  newCells[Pixel(i, j)] = cells[Pixel(i, j0)];
102  }
103  }
104  cells = std::move(newCells);
105  }
106 
107  void deleteRun(const Size rowIdx) {
108  rows.remove(rowIdx);
109  Bitmap<std::string> newCells(Pixel(cols.size(), rows.size()));
110  for (Size j = 0; j < rows.size(); ++j) {
111  for (Size i = 0; i < cols.size(); ++i) {
112  const Size j0 = j <= rowIdx ? j : j + 1;
113  newCells[Pixel(i, j)] = cells[Pixel(i, j0)];
114  }
115  }
116  cells = std::move(newCells);
117  }
118 
123  void modifyHierarchy(const Size runIdx, JobNode& node);
124 
125  void load(Config& config, ArrayView<const SharedPtr<JobNode>> nodes);
126  void save(Config& config);
127 
128 private:
129  void modifyNode(JobNode& node, const Size runIdx, const Size paramIdx);
130 };
131 
132 class BatchDialog : public wxDialog {
133 private:
134  BatchManager manager;
136 
137  wxGrid* grid;
138 
139 public:
140  BatchDialog(wxWindow* parent, const BatchManager& manager, Array<SharedPtr<JobNode>>&& nodes);
141 
142  ~BatchDialog();
143 
145  return manager;
146  }
147 
148 private:
150  void update();
151 };
152 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Wrapper of wxBitmap, will be possibly replaced by custom implementation.
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
NAMESPACE_SPH_BEGIN constexpr INLINE T min(const T &f1, const T &f2)
Minimum & Maximum value.
Definition: MathBasic.h:15
#define NAMESPACE_SPH_END
Definition: Object.h:12
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
void resize(const TCounter newSize)
Resizes the array to new size.
Definition: Array.h:215
void remove(const TCounter idx)
Removes an element with given index from the array.
Definition: Array.h:383
void insert(const TCounter position, U &&value)
Inserts a new element to given position in the array.
Definition: Array.h:345
INLINE TCounter size() const noexcept
Definition: Array.h:193
Array clone() const
Performs a deep copy of all elements of the array.
Definition: Array.h:147
BatchManager & getBatch()
Definition: BatchDialog.h:144
BatchDialog(wxWindow *parent, const BatchManager &manager, Array< SharedPtr< JobNode >> &&nodes)
std::string getParamKey(const Size colIdx) const
Definition: BatchDialog.h:53
void save(Config &config)
void setCell(const Size colIdx, const Size rowIdx, const std::string &value)
Definition: BatchDialog.h:74
void deleteRun(const Size rowIdx)
Definition: BatchDialog.h:107
Size getParamCount() const
Definition: BatchDialog.h:49
void load(Config &config, ArrayView< const SharedPtr< JobNode >> nodes)
Definition: BatchDialog.cpp:94
std::string getRunName(const Size rowIdx) const
Definition: BatchDialog.h:41
Size getRunCount() const
Definition: BatchDialog.h:37
void resize(const Size rowCnt, const Size colCnt)
Definition: BatchDialog.h:78
void duplicateRun(const Size rowIdx)
Definition: BatchDialog.h:93
void modifyHierarchy(const Size runIdx, JobNode &node)
Modifies the settings of the given node hierarchy.
Definition: BatchDialog.cpp:14
std::string getCell(const Size colIdx, const Size rowIdx) const
Definition: BatchDialog.h:61
void setRunName(const Size rowIdx, const std::string &name)
Definition: BatchDialog.h:65
BatchManager clone() const
Definition: BatchDialog.h:29
SharedPtr< JobNode > getParamNode(const Size colIdx) const
Definition: BatchDialog.h:57
void setParam(const Size colIdx, const SharedPtr< JobNode > &node, const std::string &key)
Definition: BatchDialog.h:69
void resize(const Pixel newResolution, const Type &value)
Definition: Bitmap.h:38
Bitmap clone() const
Definition: Bitmap.h:31
Pixel size() const
Definition: Bitmap.h:72
Provides functionality for reading and writing configuration files.
Definition: Config.h:272
Building block of a simulation hierarchy.
Definition: Node.h:88
Definition: Point.h:101