-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy pathparametric.h
More file actions
369 lines (285 loc) · 10.3 KB
/
parametric.h
File metadata and controls
369 lines (285 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/*
BSD 3-Clause License
Copyright (c) Alliance for Energy Innovation, LLC. See also https://github.com/NatLabRockies/SAM/blob/develop/LICENSE
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __parametric_h
#define __parametric_h
#include <wx/datstrm.h>
#include <wx/panel.h>
#include <wx/grid.h>
#include <wex/numeric.h>
#include <wex/radiochoice.h>
#include "simulation.h"
#include "object.h"
#include "gridsupport.h"
#include "graph.h"
class ParametricData
{
public:
ParametricData( Case *c );
~ParametricData();
void ClearRuns();
void Copy(ParametricData &rhs);
struct Var {
wxString Name;
std::vector<VarValue> Values;
bool IsInput;
int ndxHybrid;
wxString varName;
};
std::vector<Var> Setup;
std::vector<Simulation*> Runs;
std::vector<wxArrayString> QuickSetup;
size_t QuickSetupMode;
int FindSetup(wxString &name, bool IsInput);
bool RemoveSetup(wxString &name, bool IsInput);
void Write( wxOutputStream & );
bool Read( wxInputStream & );
Case *GetCase() { return m_case; }
private:
Case *m_case;
};
class ParametricGridData : public GridChoiceData
{
public:
ParametricGridData(Case *cc);
~ParametricGridData();
virtual int GetNumberRows();
virtual int GetNumberCols();
virtual bool IsEmptyCell(int row, int col);
virtual wxString GetValue(int row, int col);
virtual void SetValue(int row, int col, const wxString& value);
virtual wxString GetColLabelValue(int col);
virtual void SetColLabelValue(int col, const wxString &label);
virtual wxString GetTypeName(int row, int col);
virtual bool AppendRows(size_t nrows);
virtual bool InsertRows(size_t pos=0, size_t nrows=1);
virtual bool DeleteRows(size_t pos=0, size_t nrows=1);
virtual bool AppendCols(size_t ncols=1);
virtual bool InsertCols(size_t pos=0, size_t ncols=1);
virtual bool DeleteCols(size_t pos=0, size_t ncols=1);
// set cell background based on input and output status
virtual wxGridCellAttr *GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind);
// for choice controls
wxString GetChoices(int row, int col);
int GetMaxChoice(int row, int col);
wxString GetChoice(int row, int col); // actual string choice
wxString GetVarName(int row, int col);
int GetNdxHybrid(int row, int col);
bool IsInput(int col);
bool IsInput(ParametricData::Var &var);
bool IsValid(const ParametricData::Var& pv);
VarInfo* GetVarInfo(int row, int col);
void SetVarInfo(int row, int col, VarInfo *vi);
VarValue* GetVarValue(int row, int col);
Case* GetCase(int , int ) { return m_case; }
int GetColumnForName(const wxString &name);
void SetVarValue(int row, int col, VarValue *vv);
void Init();
void UpdateSetup();
void UpdateView();
std::vector<Simulation*> PrepareSimulations();
wxArrayString GetInputNames();
wxArrayString GetOutputNames();
void AddSetup(ParametricData::Var &var);
void DeleteSetup(ParametricData::Var &var);
void UpdateNumberRows(int rows);
bool RunSimulations_single();
bool Generate_lk();
bool RunSimulations_multi();
void ClearResults(int row);
void ClearResults();
void UpdateInputs(wxArrayString &input_names);
void UpdateOutputs(wxArrayString &output_names);
double GetDouble(int row, int col);
std::vector<double> GetArray(int row, int col);
double *GetArray(int row, int col, size_t *n);
wxString GetUnits(int col);
void FillDown(int col, int rows=2);
void FillEvenly(int col);
std::vector<Simulation *> GetRuns();
void SortColumn(const int& col, const bool& asc);
int GetSortColumn();
void ClearSorting();
bool IsSorted();
bool IsSortedAscending();
int GetRunNumberForRowNumber(const int& rowNum);
std::vector<int> GetRowSortOrder();
ParametricData& GetParametricData() { return m_par; }
bool UpdateVarNameNdxHybrid(const wxString& input_name, wxString* var_name, size_t* ndx_hybrid);
private:
int m_sortColumn;
std::vector< std::pair<double, int> > m_rowSortOrder;
int m_rows;
int m_cols;
wxArrayString m_col_hdrs;
ParametricData &m_par;
Case *m_case;
wxArrayString m_input_names;
wxArrayString m_output_names;
wxArrayString m_var_names;
wxGridCellAttr *m_attr_for_inputs;
wxGridCellAttr *m_attr_for_valid_outputs;
wxGridCellAttr *m_attr_for_invalid_outputs;
wxColour m_color_for_inputs;
wxColour m_color_for_valid_outputs;
wxColour m_color_for_invalid_outputs;
std::vector<bool> m_valid_run;
};
class ParametricGrid : public wxExtGridCtrl
{
public:
ParametricGrid(wxWindow *parent, wxWindowID id, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr);
virtual ~ParametricGrid();
void OnLeftClick(wxGridEvent& evt);
void OnColSort(wxGridEvent& evt);
void OnGridCellChange(wxGridEvent& evt);
DECLARE_EVENT_TABLE()
};
class ParametricViewer : public wxPanel
{
public:
ParametricViewer( wxWindow *parent, Case *cc );
void Setup();
GraphCtrl *CreateNewGraph();
void DeleteGraph(GraphCtrl *);
void DeleteAll();
void SetGraphs(std::vector<Graph> &gl);
void GetGraphs(std::vector<Graph> &gl);
wxString RunSimulationsFromMacro();
bool ExportFromMacro(wxString path, bool asExcel = true);
bool ImportFromMacro(wxString path);
bool SetInputFromMacro(wxString varName, int index, wxString val);
void AddAllPlots();
void RemoveAllPlots();
enum ColumnFilterType {cft_less_than, cft_greater_than, cft_equal_to};
struct ColumnFilter {
ColumnFilter() {
filterColumn = -1;
filterType = ColumnFilterType::cft_less_than;
filterCriteria = 0.0;
};
ColumnFilter(int &col) {
filterColumn = col;
filterType = ColumnFilterType::cft_less_than;
filterCriteria = 0.0;
};
int filterColumn;
ColumnFilterType filterType;
double filterCriteria;
};
private:
void OnCommand(wxCommandEvent &evt);
void OnGridColLabelRightClick(wxGridEvent& evt);
void OnGridColSort(wxGridEvent& evt);
void OnMenuItem(wxCommandEvent &evt);
void FilterColumn(int& col);
int GetColumnFiltersIndexForColumn(int& col);
bool ShowRow(int& row);
void SelectInputs();
void SelectOutputs();
void UpdateGrid();
void UpdateNumRuns();
void RunSimulations();
void ClearResults();
void Generate_lk();
void AddPlot(const wxString& output_name);
void RemovePlot(const wxString &output_name);
bool Plot(int col, Graph &g);
bool IsLineInputs();
bool IsContourInputs();
void FillDown(int rows);
void ShowAllData();
bool ImportAsNumber(wxString& vals, VarValue& vv);
bool ImportAsArray(wxString& vals, VarValue& vv);
bool ImportAsMatrix(wxString& vals, VarValue& vv);
bool ImportAsTable(wxString& vals, VarValue& vv);
void ImportData(wxArrayString& vals, int& row, int& col);
void CopyToClipboard();
wxArrayString getFromCSV(const wxString& input_name, int& rows, int& cols);
wxArrayString getFromExcel(const wxString& input_name, int& rows, int& cols);
void SaveToCSV();
void SendToExcel();
void GetTextData(wxString &dat, char sep);
ParametricGrid *m_grid;
ParametricGridData *m_grid_data;
wxNumericCtrl *m_num_runs_ctrl;
wxCheckBox *m_run_multithreaded;
Case *m_case;
wxArrayString m_input_names;
wxArrayString m_output_names;
wxArrayString m_plot_var_names;
int m_selected_grid_col;
int m_selected_grid_row;
void UpdateGraph();
GraphCtrl* CurrentGraph();
void OnGraphSelect(wxCommandEvent &);
void SetCurrent(GraphCtrl *gc);
GraphCtrl *m_current_graph;
wxSnapLayout *m_layout;
std::vector<wxWindow*> m_graphs;
std::vector< ColumnFilter > m_columnFilters;
DECLARE_EVENT_TABLE();
};
class Parametric_QS : public wxDialog
{
public:
Parametric_QS(wxWindow *parent, Case *c);
void UpdateFromParametricData();
ParametricData &GetParametricData();
void OnEnableChange(wxCommandEvent &evt);
void OnRemoveVariable(wxCommandEvent &evt);
void OnAddVariable(wxCommandEvent &evt);
void OnVariableSelect(wxCommandEvent &evt);
void OnVarDblClick(wxCommandEvent &evt);
void OnEditValues(wxCommandEvent &evt);
void OnValueDblClick(wxCommandEvent &evt);
void RefreshVariableList();
void RefreshValuesList();
wxString GetBaseCaseValue(const wxString &input_name);
wxArrayString GetValuesList(const wxString &input_name);
wxArrayString GetValuesDisplayList(const wxString &input_name);
void SetValuesList(const wxString &input_name, const wxArrayString &values);
bool ShowEditValuesDialog(const wxString &title, wxArrayString &values, const wxString &varname, size_t &ndxHybrid);
bool ShowNumericValuesDialog(const wxString &title, wxArrayString &values);
bool ShowFixedDomainDialog(const wxString &title,
const wxArrayString &names, const wxArrayString &labels, wxArrayString &list,
bool expand_all);
void UpdateCaseParametricData();
void OnCommand(wxCommandEvent &evt);
size_t UpdateNumberRuns();
bool UpdateLinkedEnabled();
bool UpdateVarNameNdxHybrid(const wxString &input_name, wxString *var_name, size_t *ndx_hybrid);
private:
wxListBox *lstValues;
wxListBox *lstVariables;
wxRadioChoice *rchSetupOption;
wxNumericCtrl *numberRuns;
Case *m_case;
wxArrayString m_input_names;
std::vector<wxArrayString> m_input_values;
DECLARE_EVENT_TABLE()
};
#endif