-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathgridsupport.h
More file actions
458 lines (359 loc) · 12.4 KB
/
gridsupport.h
File metadata and controls
458 lines (359 loc) · 12.4 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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
/*
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 __gridsupport_h
#define __gridsupport_h
#include <wx/string.h>
#include <wx/grid.h>
#include <wx/frame.h>
#include <wx/renderer.h>
#include <wx/event.h>
#include <wx/dc.h>
#include <wx/button.h>
#include <wx/stattext.h>
#include <wex/uiform.h>
#include <wex/numeric.h>
#include <wex/exttext.h>
#include <wex/extgrid.h>
#include <wex/radiochoice.h>
#include <wex/diurnal.h>
#include "variables.h"
// UI widgets
#include "widgets.h"
#include "lossadj.h"
#include "ptlayoutctrl.h"
#include "troughloop.h"
#include "materials.h"
#include "shadingfactors.h"
#include "library.h"
#include <vector>
class Case;
class GridChoiceData : public wxGridTableBase
{
public:
virtual wxString GetChoices(int row, int col)=0;
virtual VarValue* GetVarValue(int row, int col) = 0;
virtual VarInfo* GetVarInfo(int row, int col) = 0;
virtual wxString GetVarName(int row, int col) = 0;
virtual Case* GetCase(int row, int col) = 0;
};
class GridCellVarValueRenderer : public wxGridCellRenderer
{
public:
GridCellVarValueRenderer();
virtual ~GridCellVarValueRenderer(void);
virtual void Draw(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected);
virtual wxSize GetBestSize(wxGrid &grid, wxGridCellAttr& attr, wxDC &dc, int row, int col);
virtual wxGridCellRenderer *Clone() const;
void SetTextColoursAndFont(const wxGrid& grid, const wxGridCellAttr& attr, wxDC& dc, bool isSelected);
private:
wxString m_ellipsis;
};
class VariablePopupDialog : public wxDialog
{
public:
VariablePopupDialog(wxWindow *parent, wxUIObject *obj, wxString &name, VarValue *vv, VarInfo *vi, Case *c);
~VariablePopupDialog();
wxUIObject *GetUIObject();
private:
wxUIObject *m_obj;
VarValue *m_vv;
VarInfo *m_vi;
Case* m_case;
};
class GridCellVarValueEditor : public wxEvtHandler, public wxGridCellEditor
{
public:
GridCellVarValueEditor();
virtual ~GridCellVarValueEditor(void);
virtual void PaintBackground(wxDC& dc,
const wxRect& rectCell,
const wxGridCellAttr& attr);
virtual void Create(wxWindow *parent, wxWindowID id, wxEvtHandler* pEvtHandler);
virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void SetSize(const wxRect &rect_orig);
virtual void BeginEdit(int row, int col, wxGrid *pGrid);
virtual bool EndEdit(int row, int col, const wxGrid *grid, const wxString &oldval, wxString *newval);
virtual void ApplyEdit(int row, int col, wxGrid *grid);
virtual void Reset();
virtual wxString GetValue() const;
virtual wxGridCellEditor *Clone() const;
private:
wxString m_cell_value;
wxString m_new_cell_value;
wxStaticText *m_text;
VarInfo *m_var_info;
VarValue *m_var_value;
wxWindow *m_parent;
VariablePopupDialog *m_vpe;
bool DisplayEditor(wxUIObject *obj, wxString &name, wxGrid *grid, VarValue *vv, VarInfo *vi, Case *c);
wxString GetDisplayString(wxString &var_string, int row, int col, const wxGrid *grid);
DECLARE_NO_COPY_CLASS(GridCellVarValueEditor)
};
// renders a text string using arrays from the corresponding VarValue
// based on wxGridCellStringRenderer
class GridCellArrayRenderer : public wxGridCellStringRenderer
{
public:
virtual void Draw(wxGrid& grid,
wxGridCellAttr& attr,
wxDC& dc,
const wxRect& rect,
int row, int col,
bool isSelected);
virtual wxSize GetBestSize(wxGrid& grid,
wxGridCellAttr& attr,
wxDC& dc,
int row, int col);
virtual wxGridCellRenderer *Clone() const;
protected:
wxString GetString(const wxGrid& grid, int row, int col);
};
class ArrayPopupDialog : public wxDialog
{
public:
ArrayPopupDialog(wxWindow *parent, const wxString &title, const wxString &label, VarValue *vv);
ArrayPopupDialog(wxWindow *parent, const wxString &title, const wxArrayString &labels, std::vector<std::vector<double> > &values_vec);
void SendToExcel();
#ifdef __WXMSW__
void SendToExcelSheet(wxExcelAutomation& xl, wxString& sheetName);
#endif
void GetTextData(wxString& dat, char sep, bool withHeader = true);
void GetParametricTextData(wxString& dat, char sep);
private:
void OnCommand(wxCommandEvent &evt);
void CopyToClipboard();
void SaveToCSV();
void CreateUI();
VarValue *m_vv;
wxGrid *m_grid;
DECLARE_EVENT_TABLE()
};
class AlignRightGridCellAttrProvider : public wxGridCellAttrProvider
{
public:
AlignRightGridCellAttrProvider();
virtual ~AlignRightGridCellAttrProvider();
virtual wxGridCellAttr *GetAttr(int row, int col,
wxGridCellAttr::wxAttrKind kind) const;
private:
wxGridCellAttr *m_attr_to_align_right;
};
class GridCellArrayEditor : public wxEvtHandler, public wxGridCellEditor
{
public:
GridCellArrayEditor();
virtual void PaintBackground(wxDC& dc,
const wxRect& rectCell,
const wxGridCellAttr& attr);
virtual void Create(wxWindow *parent, wxWindowID id, wxEvtHandler* pEvtHandler);
virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void SetSize(const wxRect &rect_orig);
virtual void BeginEdit(int row, int col, wxGrid *pGrid);
virtual bool EndEdit(int row, int col, const wxGrid *grid, const wxString &oldval, wxString *newval);
virtual void ApplyEdit(int row, int col, wxGrid *grid);
virtual void Reset();
virtual wxString GetValue() const;
virtual wxGridCellEditor *Clone() const;
private:
wxString m_cell_value;
wxString m_new_cell_value;
// wxStaticText *m_text;
wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
VarInfo *m_var_info;
VarValue *m_var_value;
wxWindow *m_parent;
VariablePopupDialog *m_vpe;
bool DisplayEditor(wxString &title, wxString &label, wxGrid *grid, VarValue *vv);
wxString GetString(int row, int col, const wxGrid *grid);
DECLARE_NO_COPY_CLASS(GridCellArrayEditor)
};
// renders a text string using calculated values from the corresponding VarValue
// based on wxGridCellStringRenderer
class GridCellCalculatedRenderer : public wxGridCellStringRenderer
{
public:
virtual void Draw(wxGrid& grid,
wxGridCellAttr& attr,
wxDC& dc,
const wxRect& rect,
int row, int col,
bool isSelected);
virtual wxSize GetBestSize(wxGrid& grid,
wxGridCellAttr& attr,
wxDC& dc,
int row, int col);
virtual wxGridCellRenderer *Clone() const;
protected:
wxString GetString(const wxGrid& grid, int row, int col);
};
class CalculatedGridCellAttrProvider : public wxGridCellAttrProvider
{
public:
CalculatedGridCellAttrProvider();
virtual ~CalculatedGridCellAttrProvider();
virtual wxGridCellAttr *GetAttr(int row, int col,
wxGridCellAttr::wxAttrKind kind) const;
private:
wxGridCellAttr *m_attr_to_calculated;
};
class GridCellCalculatedEditor : public wxEvtHandler, public wxGridCellEditor
{
public:
GridCellCalculatedEditor();
virtual void PaintBackground(wxDC& dc,
const wxRect& rectCell,
const wxGridCellAttr& attr);
virtual void Create(wxWindow *parent, wxWindowID id, wxEvtHandler* pEvtHandler);
virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void SetSize(const wxRect &rect_orig);
virtual void BeginEdit(int row, int col, wxGrid *pGrid);
virtual bool EndEdit(int row, int col, const wxGrid *grid, const wxString &oldval, wxString *newval);
virtual void ApplyEdit(int row, int col, wxGrid *grid);
virtual void Reset();
virtual wxString GetValue() const;
virtual wxGridCellEditor *Clone() const;
private:
wxString m_cell_value;
wxString m_new_cell_value;
// wxStaticText *m_text;
wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
VarInfo *m_var_info;
VarValue *m_var_value;
wxWindow *m_parent;
VariablePopupDialog *m_vpe;
bool DisplayEditor(wxString &title, wxString &label, wxGrid *grid, VarValue *vv);
wxString GetString(int row, int col, const wxGrid *grid);
DECLARE_NO_COPY_CLASS(GridCellCalculatedEditor)
};
// renders a text string using the corresponding VarInfo in GridTableBase for wxUIObject Choice
// based on wxGridCellEnumRenderer
class GridCellChoiceRenderer : public wxGridCellStringRenderer
{
public:
GridCellChoiceRenderer();
GridCellChoiceRenderer(const wxString& choices);
virtual void Draw(wxGrid& grid,
wxGridCellAttr& attr,
wxDC& dc,
const wxRect& rect,
int row, int col,
bool isSelected);
virtual wxSize GetBestSize(wxGrid& grid,
wxGridCellAttr& attr,
wxDC& dc,
int row, int col);
virtual wxGridCellRenderer *Clone() const;
void SetParameters(const wxString& params);
protected:
wxString GetString(const wxGrid& grid, int row, int col);
bool m_init;
wxArrayString m_choices;
};
class GridCellChoiceEditor : public wxGridCellEditor
{
public:
GridCellChoiceEditor();
GridCellChoiceEditor(const wxString& choices);
virtual void Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler);
virtual void SetSize(const wxRect& rect);
virtual void PaintBackground(wxDC& dc,
const wxRect& rectCell,
const wxGridCellAttr& attr);
virtual void Reset();
// parameters string format is "item1[,item2[...,itemN]]"
virtual void SetParameters(const wxString& params);
virtual wxGridCellEditor *Clone() const;
// added GetValue so we can get the value which is in the control
virtual wxString GetValue() const;
virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual bool EndEdit(int row, int col, const wxGrid* grid,
const wxString& oldval, wxString *newval);
virtual void ApplyEdit(int row, int col, wxGrid* grid);
// update with choices based on table base row and column
void UpdateComboBox();
private:
long m_index;
bool m_init;
wxComboBox *Combo() const { return (wxComboBox *)m_control; }
wxString m_value;
wxArrayString m_choices;
wxDECLARE_NO_COPY_CLASS(GridCellChoiceEditor);
};
// renders check box based on wxGridCellBoolRenderer and wxGridCellBoolEditor
// renderer for boolean fields
class GridCellCheckBoxRenderer : public wxGridCellRenderer
{
public:
// draw a check mark or nothing
virtual void Draw(wxGrid& grid,
wxGridCellAttr& attr,
wxDC& dc,
const wxRect& rect,
int row, int col,
bool isSelected);
// return the checkmark size
virtual wxSize GetBestSize(wxGrid& grid,
wxGridCellAttr& attr,
wxDC& dc,
int row, int col);
virtual wxGridCellRenderer *Clone() const
{
return new GridCellCheckBoxRenderer;
}
private:
static wxSize ms_sizeCheckMark;
};
class GridCellCheckBoxEditor : public wxGridCellEditor
{
public:
GridCellCheckBoxEditor() { }
virtual void Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler);
virtual void SetSize(const wxRect& rect);
virtual void Show(bool show, wxGridCellAttr *attr = NULL);
virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual bool EndEdit(int row, int col, const wxGrid* grid,
const wxString& oldval, wxString *newval);
virtual void ApplyEdit(int row, int col, wxGrid* grid);
virtual void Reset();
// virtual void StartingClick();
// virtual void StartingKey(wxKeyEvent& event);
virtual wxGridCellEditor *Clone() const
{
return new GridCellCheckBoxEditor;
}
virtual wxString GetValue() const;
protected:
wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
private:
bool m_value;
wxDECLARE_NO_COPY_CLASS(GridCellCheckBoxEditor);
};
#endif