-
Notifications
You must be signed in to change notification settings - Fork 194
/
Model.cpp
7751 lines (7044 loc) · 317 KB
/
Model.cpp
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************
* This source files comes from the xLights project
* https://www.xlights.org
* https://github.com/xLightsSequencer/xLights
* See the github commit history for a record of contributing
* developers.
* Copyright claimed based on commit dates recorded in Github
* License: https://github.com/xLightsSequencer/xLights/blob/master/License.txt
**************************************************************/
#include <wx/propgrid/advprops.h>
#include <wx/propgrid/propgrid.h>
#include <wx/sstream.h>
#include <wx/stdpaths.h>
#include <wx/tokenzr.h>
#include <wx/wfstream.h>
#include <wx/wx.h>
#include <wx/xml/xml.h>
#include <wx/zipstrm.h>
#include "CachedFileDownloader.h"
#include "CustomModel.h"
#include "Model.h"
#include "ModelGroup.h"
#include "ModelManager.h"
#include "ModelScreenLocation.h"
#include "RulerObject.h"
#include "SubModel.h"
#include "../Color.h"
#include "../DimmingCurve.h"
#include "../EditAliasesDialog.h"
#include "../ExternalHooks.h"
#include "../ModelChainDialog.h"
#include "../ModelDimmingCurveDialog.h"
#include "../ModelFaceDialog.h"
#include "../ModelPreview.h"
#include "../ModelStateDialog.h"
#include "../Pixels.h"
#include "../StartChannelDialog.h"
#include "../StrandNodeNamesDialog.h"
#include "../SubModelsDialog.h"
#include "../UtilFunctions.h"
#include "../VendorModelDialog.h"
#include "../controllers/ControllerCaps.h"
#include "../outputs/Controller.h"
#include "../outputs/ControllerSerial.h"
#include "../outputs/IPOutput.h"
#include "../outputs/Output.h"
#include "../outputs/OutputManager.h"
#include "../utils/ip_utils.h"
#include "../xLightsApp.h"
#include "../xLightsMain.h" //for Preview and Other model collections
#include "../xLightsVersion.h"
#include "../xLightsXmlFile.h"
#include "XmlSerializer.h"
#include <log4cpp/Category.hh>
#include "../xSchedule/wxJSON/jsonreader.h"
#include <algorithm>
#define MOST_STRINGS_WE_EXPECT 480
#define MOST_CONTROLLER_PORTS_WE_EXPECT 128
const long Model::ID_LAYERSIZE_INSERT = wxNewId();
const long Model::ID_LAYERSIZE_DELETE = wxNewId();
static const int PORTS_PER_SMARTREMOTE = 4;
static const char* NODE_TYPE_VLUES[] = {
"RGB Nodes", "RBG Nodes", "GBR Nodes", "GRB Nodes",
"BRG Nodes", "BGR Nodes", "Node Single Color", "3 Channel RGB",
"4 Channel RGBW", "4 Channel WRGB", "Strobes", "Single Color",
"Single Color Intensity", "Superstring", "WRGB Nodes", "WRBG Nodes",
"WGBR Nodes", "WGRB Nodes", "WBRG Nodes", "WBGR Nodes", "RGBW Nodes",
"RBGW Nodes", "GBRW Nodes", "GRBW Nodes", "BRGW Nodes", "BGRW Nodes", "RGBWW Nodes"
};
static wxArrayString NODE_TYPES(27, NODE_TYPE_VLUES);
static const char* RGBW_HANDLING_VALUES[] = { "R=G=B -> W", "RGB Only", "White Only", "Advanced", "White On All" };
static wxArrayString RGBW_HANDLING(5, RGBW_HANDLING_VALUES);
static const char* PIXEL_STYLES_VALUES[] = { "Square", "Smooth", "Solid Circle", "Blended Circle" };
static wxArrayString PIXEL_STYLES(4, PIXEL_STYLES_VALUES);
static const char* CONTROLLER_DIRECTION_VALUES[] = { "Forward", "Reverse" };
static wxArrayString CONTROLLER_DIRECTION(2, CONTROLLER_DIRECTION_VALUES);
static const char* CONTROLLER_COLORORDER_VALUES[] = {
"RGB", "RBG", "GBR", "GRB", "BRG", "BGR",
"RGBW", "RBGW", "GBRW", "GRBW", "BRGW", "BGRW",
"WRGB", "WRBG", "WGBR", "WGRB", "WBRG", "WBGR"
};
wxArrayString Model::CONTROLLER_COLORORDER(18, CONTROLLER_COLORORDER_VALUES);
static wxArrayString LAYOUT_GROUPS;
static wxArrayString CONTROLLERS;
static wxArrayString OTHERMODELLIST;
static const std::string DEFAULT("Default");
static const std::string PER_PREVIEW("Per Preview");
static const std::string SINGLE_LINE("Single Line");
static const std::string AS_PIXEL("As Pixel");
static const std::string VERT_PER_STRAND("Vertical Per Strand");
static const std::string HORIZ_PER_STRAND("Horizontal Per Strand");
static const std::string HORIZ_PER_MODELSTRAND("Horizontal Per Model/Strand");
static const std::string VERT_PER_MODELSTRAND("Vertical Per Model/Strand");
static const std::string PER_PREVIEW_NO_OFFSET("Per Preview No Offset");
const std::vector<std::string> Model::DEFAULT_BUFFER_STYLES{ DEFAULT, PER_PREVIEW, SINGLE_LINE, AS_PIXEL };
static void clearUnusedProtocolProperties(wxXmlNode* node)
{
std::string protocol = node->GetAttribute("Protocol");
bool isDMX = IsSerialProtocol(protocol);
bool isPixel = IsPixelProtocol(protocol);
if (!isPixel) {
node->DeleteAttribute("gamma");
node->DeleteAttribute("brightness");
node->DeleteAttribute("nullNodes");
node->DeleteAttribute("endNullNodes");
node->DeleteAttribute("colorOrder");
node->DeleteAttribute("reverse");
node->DeleteAttribute("groupCount");
node->DeleteAttribute("zigZag");
node->DeleteAttribute("ts");
}
if (!isDMX) {
node->DeleteAttribute("channel");
}
}
static const std::string EFFECT_PREVIEW_CACHE("ModelPreviewEffectCache");
static const std::string MODEL_PREVIEW_CACHE_2D("ModelPreviewCache3D");
static const std::string MODEL_PREVIEW_CACHE_3D("ModelPreviewCache2D");
static const std::string LAYOUT_PREVIEW_CACHE_2D("LayoutPreviewCache3D");
static const std::string LAYOUT_PREVIEW_CACHE_3D("LayoutPreviewCache2D");
Model::Model(const ModelManager& manager) :
modelManager(manager)
{
}
Model::~Model()
{
deleteUIObjects();
if (modelDimmingCurve != nullptr) {
delete modelDimmingCurve;
}
for (const auto& it : subModels) {
Model* m = it;
delete m;
}
}
static const std::string CLICK_TO_EDIT("--Click To Edit--");
class StrandNodeNamesDialogAdapter : public wxPGEditorDialogAdapter
{
public:
StrandNodeNamesDialogAdapter(const Model* model) :
wxPGEditorDialogAdapter(), m_model(model)
{
}
virtual bool DoShowDialog(wxPropertyGrid* propGrid,
wxPGProperty* WXUNUSED(property)) override
{
StrandNodeNamesDialog dlg(propGrid);
dlg.Setup(m_model,
m_model->GetModelXml()->GetAttribute("NodeNames").ToStdString(),
m_model->GetModelXml()->GetAttribute("StrandNames").ToStdString());
if (dlg.ShowModal() == wxID_OK) {
m_model->GetModelXml()->DeleteAttribute("NodeNames");
m_model->GetModelXml()->DeleteAttribute("StrandNames");
m_model->GetModelXml()->AddAttribute("NodeNames", dlg.GetNodeNames());
m_model->GetModelXml()->AddAttribute("StrandNames", dlg.GetStrandNames());
wxVariant v(CLICK_TO_EDIT);
SetValue(v);
return true;
}
return false;
}
protected:
const Model* m_model;
};
class FacesDialogAdapter : public wxPGEditorDialogAdapter
{
public:
FacesDialogAdapter(Model* model, OutputManager* om) :
wxPGEditorDialogAdapter(), m_model(model), _outputManager(om)
{
}
virtual bool DoShowDialog(wxPropertyGrid* propGrid,
wxPGProperty* WXUNUSED(property)) override
{
ModelFaceDialog dlg(propGrid, _outputManager);
dlg.SetFaceInfo(m_model, m_model->GetFaceInfo());
if (dlg.ShowModal() == wxID_OK) {
m_model->SetFaceInfo(dlg.GetFaceInfo());
wxVariant v(CLICK_TO_EDIT);
SetValue(v);
return true;
}
return false;
}
protected:
Model* m_model = nullptr;
OutputManager* _outputManager = nullptr;
};
class AliasDialogAdapter : public wxPGEditorDialogAdapter
{
public:
AliasDialogAdapter(Model* model) :
wxPGEditorDialogAdapter(), m_model(model)
{
}
virtual bool DoShowDialog(wxPropertyGrid* propGrid,
wxPGProperty* WXUNUSED(property)) override
{
EditAliasesDialog dlg(propGrid, m_model);
if (dlg.ShowModal() == wxID_OK) {
wxVariant v(CLICK_TO_EDIT);
SetValue(v);
return true;
}
return false;
}
protected:
Model* m_model = nullptr;
};
class StatesDialogAdapter : public wxPGEditorDialogAdapter
{
public:
StatesDialogAdapter(Model* model, OutputManager* om) :
wxPGEditorDialogAdapter(), m_model(model), _outputManager(om)
{
}
virtual bool DoShowDialog(wxPropertyGrid* propGrid,
wxPGProperty* WXUNUSED(property)) override
{
ModelStateDialog dlg(propGrid, _outputManager);
dlg.SetStateInfo(m_model, m_model->GetStateInfo());
if (dlg.ShowModal() == wxID_OK) {
m_model->SetStateInfo(dlg.GetStateInfo());
wxVariant v(CLICK_TO_EDIT);
SetValue(v);
return true;
}
return false;
}
protected:
Model* m_model = nullptr;
OutputManager* _outputManager = nullptr;
};
std::map<std::string, std::map<std::string, std::string>> Model::GetDimmingInfo() const
{
std::map<std::string, std::map<std::string, std::string>> dimmingInfo;
wxXmlNode* f = GetModelXml()->GetChildren();
while (f != nullptr) {
if ("dimmingCurve" == f->GetName()) {
wxXmlNode* dc = f->GetChildren();
while (dc != nullptr) {
std::string name = dc->GetName().ToStdString();
wxXmlAttribute* att = dc->GetAttributes();
while (att != nullptr) {
dimmingInfo[name][att->GetName().ToStdString()] = att->GetValue();
att = att->GetNext();
}
dc = dc->GetNext();
}
}
f = f->GetNext();
}
return dimmingInfo;
}
class DimmingCurveDialogAdapter : public wxPGEditorDialogAdapter
{
public:
DimmingCurveDialogAdapter(const Model* model) :
wxPGEditorDialogAdapter(), m_model(model)
{
}
virtual bool DoShowDialog(wxPropertyGrid* propGrid,
wxPGProperty* WXUNUSED(property)) override
{
ModelDimmingCurveDialog dlg(propGrid);
auto dimmingInfo = m_model->GetDimmingInfo();
if (dimmingInfo.empty()) {
wxString b = m_model->GetModelXml()->GetAttribute("ModelBrightness", "0");
if (b.empty()) {
b = "0";
}
dimmingInfo["all"]["gamma"] = "1.0";
dimmingInfo["all"]["brightness"] = b;
}
dlg.Init(dimmingInfo);
if (dlg.ShowModal() == wxID_OK) {
dimmingInfo.clear();
dlg.Update(dimmingInfo);
wxXmlNode* f1 = m_model->GetModelXml()->GetChildren();
while (f1 != nullptr) {
if ("dimmingCurve" == f1->GetName()) {
m_model->GetModelXml()->RemoveChild(f1);
delete f1;
f1 = m_model->GetModelXml()->GetChildren();
} else {
f1 = f1->GetNext();
}
}
f1 = new wxXmlNode(wxXML_ELEMENT_NODE, "dimmingCurve");
m_model->GetModelXml()->AddChild(f1);
for (const auto& it : dimmingInfo) {
wxXmlNode* dc = new wxXmlNode(wxXML_ELEMENT_NODE, it.first);
f1->AddChild(dc);
for (const auto& it2 : it.second) {
dc->AddAttribute(it2.first, it2.second);
}
}
wxVariant v(CLICK_TO_EDIT);
SetValue(v);
return true;
}
return false;
}
protected:
const Model* m_model;
};
class SubModelsDialogAdapter : public wxPGEditorDialogAdapter
{
public:
SubModelsDialogAdapter(Model* model, OutputManager* om) :
wxPGEditorDialogAdapter(), m_model(model), _outputManager(om)
{
}
virtual bool DoShowDialog(wxPropertyGrid* propGrid,
wxPGProperty* WXUNUSED(property)) override
{
SubModelsDialog dlg(propGrid, _outputManager);
dlg.Setup(m_model);
if (dlg.ShowModal() == wxID_OK) {
dlg.Save();
wxVariant v(CLICK_TO_EDIT);
SetValue(v);
return true;
}
if (dlg.ReloadLayout) { // force grid to reload
wxCommandEvent eventForceRefresh(EVT_FORCE_SEQUENCER_REFRESH);
wxPostEvent(m_model->GetModelManager().GetXLightsFrame(), eventForceRefresh);
m_model->AddASAPWork(OutputModelManager::WORK_RELOAD_ALLMODELS, "Model::SubModelsDialog::SubModels");
m_model->AddASAPWork(OutputModelManager::WORK_MODELS_CHANGE_REQUIRING_RERENDER, "Model::SubModelsDialog::SubModels");
m_model->AddASAPWork(OutputModelManager::WORK_RGBEFFECTS_CHANGE, "Model::SubModelsDialog::SubModels");
}
return false;
}
protected:
Model* m_model = nullptr;
OutputManager* _outputManager = nullptr;
};
class ModelChainDialogAdapter : public wxPGEditorDialogAdapter
{
public:
ModelChainDialogAdapter(Model* model) :
wxPGEditorDialogAdapter(), m_model(model)
{
}
virtual bool DoShowDialog(wxPropertyGrid* propGrid,
wxPGProperty* property) override
{
ModelChainDialog dlg(propGrid);
dlg.Set(m_model, m_model->GetModelManager());
if (dlg.ShowModal() == wxID_OK) {
wxVariant v(dlg.Get());
SetValue(v);
return true;
}
return false;
}
protected:
Model* m_model = nullptr;
};
class PopupDialogProperty : public wxStringProperty
{
public:
PopupDialogProperty(Model* m,
OutputManager* om,
const wxString& label,
const wxString& name,
const wxString& value,
int type) :
wxStringProperty(label, name, value), m_model(m), m_tp(type), _outputManager(om)
{
}
// Set editor to have button
virtual const wxPGEditor* DoGetEditorClass() const override
{
return wxPGEditor_TextCtrlAndButton;
}
// Set what happens on button click
virtual wxPGEditorDialogAdapter* GetEditorDialog() const override
{
switch (m_tp) {
case 1:
return new StrandNodeNamesDialogAdapter(m_model);
case 2:
return new FacesDialogAdapter(m_model, _outputManager);
case 3:
return new DimmingCurveDialogAdapter(m_model);
case 4:
return new StatesDialogAdapter(m_model, _outputManager);
case 5:
return new SubModelsDialogAdapter(m_model, _outputManager);
case 6:
return new AliasDialogAdapter(m_model);
default:
break;
}
return nullptr;
}
protected:
Model* m_model = nullptr;
OutputManager* _outputManager = nullptr;
int m_tp = 0;
};
class StartChannelDialogAdapter : public wxPGEditorDialogAdapter
{
public:
StartChannelDialogAdapter(Model* model, std::string preview) :
wxPGEditorDialogAdapter(), m_model(model), _preview(preview)
{
}
virtual bool DoShowDialog(wxPropertyGrid* propGrid,
wxPGProperty* property) override
{
StartChannelDialog dlg(propGrid);
dlg.Set(property->GetValue().GetString(), m_model->GetModelManager(), _preview, m_model);
if (dlg.ShowModal() == wxID_OK) {
wxVariant v(dlg.Get());
SetValue(v);
return true;
}
return false;
}
protected:
Model* m_model = nullptr;
std::string _preview;
};
class StartChannelProperty : public wxStringProperty
{
public:
StartChannelProperty(Model* m,
int strand,
const wxString& label,
const wxString& name,
const wxString& value,
std::string preview) :
wxStringProperty(label, name, value), m_model(m), _preview(preview), m_strand(strand)
{
}
// Set editor to have button
virtual const wxPGEditor* DoGetEditorClass() const override
{
return wxPGEditor_TextCtrlAndButton;
}
// Set what happens on button click
virtual wxPGEditorDialogAdapter* GetEditorDialog() const override
{
return new StartChannelDialogAdapter(m_model, _preview);
}
protected:
Model* m_model = nullptr;
std::string _preview;
int m_strand = 0;
};
class ModelChainProperty : public wxStringProperty
{
public:
ModelChainProperty(Model* m,
const wxString& label,
const wxString& name,
const wxString& value) :
wxStringProperty(label, name, value), m_model(m)
{
}
// Set editor to have button
virtual const wxPGEditor* DoGetEditorClass() const override
{
return wxPGEditor_TextCtrlAndButton;
}
// Set what happens on button click
virtual wxPGEditorDialogAdapter* GetEditorDialog() const override
{
return new ModelChainDialogAdapter(m_model);
}
protected:
Model* m_model = nullptr;
};
wxArrayString Model::GetLayoutGroups(const ModelManager& mm)
{
wxArrayString lg;
lg.push_back("Default");
lg.push_back("All Previews");
lg.push_back("Unassigned");
wxXmlNode* layouts_node = mm.GetLayoutsNode();
for (wxXmlNode* e = layouts_node->GetChildren(); e != nullptr; e = e->GetNext()) {
if (e->GetName() == "layoutGroup") {
wxString grp_name = e->GetAttribute("name");
if (!grp_name.IsEmpty()) {
lg.push_back(grp_name.ToStdString());
}
}
}
return lg;
}
void Model::Rename(std::string const& newName)
{
auto oldname = ModelXml->GetAttribute("name", "");
name = Trim(newName);
ModelXml->DeleteAttribute("name");
ModelXml->AddAttribute("name", name);
if (oldname != "" && newName != "Iamgoingtodeletethismodel") {
if (wxMessageBox("Would you like to save the old name as an alias for this prop. This could be useful if you have sequences already sequenced against this prop using the old name.", "Save old name as alias", wxYES_NO | wxICON_QUESTION, GetModelManager().GetXLightsFrame()) == wxYES) {
AddAlias("oldname:" + oldname);
}
}
}
void Model::SetStartChannel(std::string const& startChannel)
{
// wxASSERT(!StartsWith(startChannel, "!:"));
if (startChannel == ModelXml->GetAttribute("StartChannel", "xyzzy_kw"))
return;
ModelXml->DeleteAttribute("StartChannel");
ModelXml->AddAttribute("StartChannel", startChannel);
ModelStartChannel = startChannel;
if (ModelXml->GetAttribute("Advanced") == "1") {
ModelXml->DeleteAttribute(StartChanAttrName(0));
ModelXml->AddAttribute(StartChanAttrName(0), startChannel);
}
AddASAPWork(OutputModelManager::WORK_CALCULATE_START_CHANNELS, "Model::SetStartChannel");
IncrementChangeCount();
}
void Model::SetProperty(wxString const& property, wxString const& value, bool apply)
{
if (ModelXml->HasAttribute(property)) {
ModelXml->DeleteAttribute(property);
ModelXml->AddAttribute(property, value);
} else {
ModelXml->AddAttribute(property, value);
}
if (apply) {
modelManager.GetXLightsFrame()->AbortRender();
SetFromXml(ModelXml);
}
}
void Model::UpdateProperties(wxPropertyGridInterface* grid, OutputManager* outputManager)
{
UpdateTypeProperties(grid);
if (grid->GetPropertyByName("Controller") != nullptr) {
grid->GetPropertyByName("Controller")->Enable(outputManager->GetAutoLayoutControllerNames().size() > 0);
}
if (HasOneString(DisplayAs) && grid->GetPropertyByName("ModelStartChannel") != nullptr) {
grid->GetPropertyByName("ModelStartChannel")->Enable(GetControllerName() == "" || _controller == 0);
} else {
if (grid->GetPropertyByName("ModelIndividualStartChannels") != nullptr) {
grid->GetPropertyByName("ModelIndividualStartChannels")->Enable(parm1 > 1 && (GetControllerName() == "" || _controller == 0));
if (parm1 > 1 && (GetControllerName() != "" && _controller != 0)) {
grid->GetPropertyByName("ModelIndividualStartChannels")->SetHelpString("Individual start channels cannot be set if you have assigned a model to a controller rather than using start channels.");
} else {
grid->GetPropertyByName("ModelIndividualStartChannels")->SetHelpString("");
}
}
if (grid->GetPropertyByName("ModelIndividualStartChannels.ModelStartChannel") != nullptr) {
grid->GetPropertyByName("ModelIndividualStartChannels.ModelStartChannel")->Enable(GetControllerName() == "" || _controller == 0);
}
}
if (grid->GetPropertyByName("ModelChain") != nullptr) {
grid->GetPropertyByName("ModelChain")->Enable(GetControllerName() != "" && GetControllerProtocol() != "" && GetControllerPort() != 0 && _controller != 0);
}
UpdateControllerProperties(grid);
if (grid->GetPropertyByName("ModelStringType") != nullptr) {
int i = grid->GetPropertyByName("ModelStringType")->GetValue().GetLong();
if (NODE_TYPES[i] == "Single Color" || NODE_TYPES[i] == "Single Color Intensity" || NODE_TYPES[i] == "Node Single Color") {
if (grid->GetPropertyByName("ModelStringColor") != nullptr) {
grid->GetPropertyByName("ModelStringColor")->Enable();
}
if (NODE_TYPES[i] == "Node Single Color") {
grid->GetPropertyByName("ModelStringType")->SetHelpString("This represents a string of single color LEDS which are individually controlled. These are very uncommon.");
} else {
grid->GetPropertyByName("ModelStringType")->SetHelpString("");
}
} else {
if (grid->GetPropertyByName("ModelStringColor") != nullptr) {
grid->GetPropertyByName("ModelStringColor")->Enable(false);
}
}
}
if (grid->GetPropertyByName("ModelRGBWHandling") != nullptr) {
grid->GetPropertyByName("ModelRGBWHandling")->Enable(!(HasSingleChannel(StringType) || GetNodeChannelCount(StringType) != 4));
}
}
void Model::ColourClashingChains(wxPGProperty* p)
{
if (p == nullptr)
return;
std::string tip;
if (GetControllerName() != "" && _controller != 0 && GetControllerProtocol() != "" && GetControllerPort() != 0 && p->IsEnabled()) {
if (!modelManager.IsValidControllerModelChain(this, tip)) {
p->SetHelpString(tip);
p->SetBackgroundColour(*wxRED);
} else {
p->SetHelpString("");
p->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX));
}
} else {
p->SetHelpString("");
p->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX));
}
}
uint32_t Model::ApplyLowDefinition(uint32_t val) const
{
if (_lowDefFactor == 100 || !SupportsLowDefinitionRender() || !GetModelManager().GetXLightsFrame()->IsLowDefinitionRender())
return val;
return (val * _lowDefFactor) / 100;
}
std::string Model::GetPixelStyleDescription(PIXEL_STYLE pixelStyle)
{
if ((int)pixelStyle < PIXEL_STYLES.size()) {
return PIXEL_STYLES[(int)pixelStyle];
}
return "";
}
int Model::GetNumPhysicalStrings() const
{
int ts = GetSmartTs();
if (ts <= 1) {
return parm1;
} else {
int strings = parm1 / ts;
if (strings == 0)
strings = 1;
return strings;
}
}
ControllerCaps* Model::GetControllerCaps() const
{
auto c = GetController();
if (c == nullptr)
return nullptr;
return c->GetControllerCaps();
}
Controller* Model::GetController() const
{
std::string controller = GetControllerName();
if (controller == "") {
if (StartsWith(ModelStartChannel, "!") && Contains(ModelStartChannel, ":")) {
controller = Trim(BeforeFirst(AfterFirst(ModelStartChannel, '!'), ':'));
}
}
if (controller == "") {
int32_t start;
Controller* cp = modelManager.GetXLightsFrame()->GetOutputManager()->GetController(GetFirstChannel() + 1, start);
if (cp != nullptr) {
return cp;
}
}
if (controller == "")
return nullptr;
return modelManager.GetXLightsFrame()->GetOutputManager()->GetController(controller);
}
bool Model::IsAlias(const std::string& alias, bool oldnameOnly) const
{
for (auto x = ModelXml->GetChildren(); x != nullptr; x = x->GetNext()) {
if (x->GetName() == "Aliases") {
for (auto xx = x->GetChildren(); xx != nullptr; xx = xx->GetNext()) {
if ((!oldnameOnly && Lower(alias) == xx->GetAttribute("name").Lower()) || Lower("oldname:" + alias) == xx->GetAttribute("name").Lower()) {
return true;
}
}
}
}
return false;
}
void Model::AddAlias(const std::string& alias)
{
if (IsAlias(alias))
return;
// a model name cant be its own alias
if (Lower(alias) == Lower(Name()))
return;
for (auto x = ModelXml->GetChildren(); x != nullptr; x = x->GetNext()) {
if (x->GetName() == "Aliases") {
auto n = new wxXmlNode(wxXmlNodeType::wxXML_ELEMENT_NODE, "alias");
n->AddAttribute("name", Lower(alias));
x->AddChild(n);
IncrementChangeCount();
return;
}
}
auto aliases = new wxXmlNode(wxXmlNodeType::wxXML_ELEMENT_NODE, "Aliases");
auto n = new wxXmlNode(wxXmlNodeType::wxXML_ELEMENT_NODE, "alias");
n->AddAttribute("name", Lower(alias));
aliases->AddChild(n);
IncrementChangeCount();
ModelXml->AddChild(aliases);
}
void Model::DeleteAlias(const std::string& alias)
{
while (IsAlias(alias)) { // while should not be required ... but just in case it ever ends up there more than once
for (auto x = ModelXml->GetChildren(); x != nullptr; x = x->GetNext()) {
if (x->GetName() == "Aliases") {
for (auto xx = x->GetChildren(); xx != nullptr; xx = xx->GetNext()) {
if (Lower(alias) == xx->GetContent().Lower()) {
x->RemoveChild(xx);
IncrementChangeCount();
return;
}
}
}
}
}
}
std::list<std::string> Model::GetAliases() const
{
std::list<std::string> aliases;
for (auto x = ModelXml->GetChildren(); x != nullptr; x = x->GetNext()) {
if (x->GetName() == "Aliases") {
for (auto xx = x->GetChildren(); xx != nullptr; xx = xx->GetNext()) {
aliases.push_back(xx->GetAttribute("name"));
}
}
}
return aliases;
}
void Model::SetAliases(std::list<std::string>& aliases)
{
AddAlias("dummy"); // this ensures the owning element exists
for (auto x = ModelXml->GetChildren(); x != nullptr; x = x->GetNext()) {
if (x->GetName() == "Aliases") {
while (x->GetChildren() != nullptr)
x->RemoveChild(x->GetChildren());
for (const auto& it : aliases) {
auto n = new wxXmlNode(wxXmlNodeType::wxXML_ELEMENT_NODE, "alias");
n->AddAttribute("name", Lower(it));
x->AddChild(n);
}
}
}
IncrementChangeCount();
}
void Model::AddProperties(wxPropertyGridInterface* grid, OutputManager* outputManager)
{
static log4cpp::Category& logger_base = log4cpp::Category::getInstance(std::string("log_base"));
wxStopWatch sw;
LAYOUT_GROUPS = Model::GetLayoutGroups(modelManager);
wxPGProperty* sp;
wxPGProperty* p;
grid->Append(new wxPropertyCategory(DisplayAs, "ModelType"));
AddTypeProperties(grid, outputManager);
if (SupportsLowDefinitionRender()) {
p = grid->Append(new wxUIntProperty("Low Definition Factor", "LowDefinition", _lowDefFactor));
p->SetAttribute("Min", 1);
p->SetAttribute("Max", 100);
p->SetEditor("SpinCtrl");
}
_controller = 0;
CONTROLLERS.clear();
CONTROLLERS.Add(USE_START_CHANNEL);
CONTROLLERS.Add(NO_CONTROLLER);
if (GetControllerName() == NO_CONTROLLER) {
_controller = 1;
}
for (const auto& it : outputManager->GetAutoLayoutControllerNames()) {
if (GetControllerName() == it) {
_controller = CONTROLLERS.size();
}
CONTROLLERS.Add(it);
}
if (CONTROLLERS.size() > 1) {
p = grid->Append(new wxEnumProperty("Controller", "Controller", CONTROLLERS, wxArrayInt(), _controller));
p->Enable(CONTROLLERS.size() > 0);
}
if (HasOneString(DisplayAs)) {
p = grid->Append(new StartChannelProperty(this, 0, "Start Channel", "ModelStartChannel", ModelXml->GetAttribute("StartChannel", "1"), modelManager.GetXLightsFrame()->GetSelectedLayoutPanelPreview()));
p->Enable(GetControllerName() == "" || _controller == 0);
} else {
bool hasIndiv = ModelXml->GetAttribute("Advanced", "0") == "1";
p = grid->Append(new wxBoolProperty("Indiv Start Chans", "ModelIndividualStartChannels", hasIndiv));
p->SetAttribute("UseCheckbox", true);
p->Enable(parm1 > 1 && (GetControllerName() == "" || _controller == 0));
if (parm1 > 1 && (GetControllerName() != "" && _controller != 0)) {
p->SetHelpString("Individual start channels cannot be set if you have assigned a model to a controller rather than using start channels.");
} else {
p->SetHelpString("");
}
sp = grid->AppendIn(p, new StartChannelProperty(this, 0, "Start Channel", "ModelStartChannel", ModelXml->GetAttribute("StartChannel", "1"), modelManager.GetXLightsFrame()->GetSelectedLayoutPanelPreview()));
sp->Enable(GetControllerName() == "" || _controller == 0);
if (hasIndiv) {
int c = Model::HasOneString(DisplayAs) ? 1 : parm1;
for (int x = 0; x < c; ++x) {
wxString nm = StartChanAttrName(x);
std::string val = ModelXml->GetAttribute(nm).ToStdString();
if (val == "") {
val = ComputeStringStartChannel(x);
ModelXml->DeleteAttribute(nm);
ModelXml->AddAttribute(nm, val);
}
if (x == 0) {
sp->SetLabel(nm);
sp->SetValue(val);
} else {
sp = grid->AppendIn(p, new StartChannelProperty(this, x, nm, nm, val, modelManager.GetXLightsFrame()->GetSelectedLayoutPanelPreview()));
}
}
} else {
// remove per strand start channels if individual isnt selected
for (uint32_t x = 0; x < MOST_STRINGS_WE_EXPECT; ++x) {
wxString nm = StartChanAttrName(x);
ModelXml->DeleteAttribute(nm);
}
wxASSERT(!ModelXml->HasAttribute(StartChanAttrName(MOST_STRINGS_WE_EXPECT))); // if this fires in debug then our magic # just isnt big enough
}
}
if (CONTROLLERS.size() > 1 && GetControllerName() != "" && GetControllerProtocol() != "" && GetControllerPort() != 0 && _controller != 0) {
p = grid->Append(new ModelChainProperty(this, "Model Chain", "ModelChain", GetModelChain() == "" ? _("Beginning").ToStdString() : GetModelChain()));
p->Enable(GetControllerName() != "" && GetControllerProtocol() != "" && GetControllerPort() != 0 && _controller != 0);
}
int shadowModelFor = 0;
OTHERMODELLIST.clear();
OTHERMODELLIST.Add("");
for (const auto& it : modelManager) {
auto da = it.second->GetDisplayAs();
if (da != "ModelGroup" && it.first != GetName()) {
if (GetShadowModelFor() == it.first) {
shadowModelFor = OTHERMODELLIST.size();
}
OTHERMODELLIST.Add(it.first);
}
}
grid->Append(new wxEnumProperty("Shadow Model For", "ShadowModelFor", OTHERMODELLIST, wxArrayInt(), shadowModelFor));
int layout_group_number = 0;
for (int grp = 0; grp < LAYOUT_GROUPS.Count(); ++grp) {
if (LAYOUT_GROUPS[grp] == layout_group) {
layout_group_number = grp;
break;
}
}
grid->Append(new wxStringProperty("Description", "Description", description));
grid->Append(new wxEnumProperty("Preview", "ModelLayoutGroup", LAYOUT_GROUPS, wxArrayInt(), layout_group_number));
p = grid->Append(new PopupDialogProperty(this, outputManager, "Strand/Node Names", "ModelStrandNodeNames", CLICK_TO_EDIT, 1));
grid->LimitPropertyEditing(p);
p = grid->Append(new PopupDialogProperty(this, outputManager, "Faces", "ModelFaces", CLICK_TO_EDIT, 2));
grid->LimitPropertyEditing(p);
p = grid->Append(new PopupDialogProperty(this, outputManager, "Dimming Curves", "ModelDimmingCurves", CLICK_TO_EDIT, 3));
grid->LimitPropertyEditing(p);
p = grid->Append(new PopupDialogProperty(this, outputManager, "States", "ModelStates", CLICK_TO_EDIT, 4));
grid->LimitPropertyEditing(p);
p = grid->Append(new PopupDialogProperty(this, outputManager, "SubModels", "SubModels", CLICK_TO_EDIT, 5));
grid->LimitPropertyEditing(p);
p = grid->Append(new PopupDialogProperty(this, outputManager, "Aliases", "Aliases", CLICK_TO_EDIT, 6));
grid->LimitPropertyEditing(p);
p->SetHelpString("Aliases are used in mapping to provide alternate names for this model which might match a model in a sequence you are importing from. To use it use the Auto Map button.");
auto modelGroups = modelManager.GetGroupsContainingModel(this);
if (modelGroups.size() > 0) {
std::string mgs;
std::string mgscr;
for (const auto& it : modelGroups) {
if (mgs != "") {
mgs += ", ";
mgscr += "\n";
}
mgs += it;
mgscr += it;
}
p = grid->Append(new wxStringProperty("In Model Groups", "MGS", mgs));
p->SetHelpString(mgscr);
p->SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
p->ChangeFlag(wxPGPropertyFlags::ReadOnly, true);
}
AddControllerProperties(grid);
p = grid->Append(new wxPropertyCategory("String Properties", "ModelStringProperties"));
int i = NODE_TYPES.Index(StringType);
if (i == wxNOT_FOUND) {
i = NODE_TYPES.Index("Single Color");
}
grid->AppendIn(p, new wxEnumProperty("String Type", "ModelStringType", NODE_TYPES, wxArrayInt(), i));
if (NODE_TYPES[i] == "Single Color" || NODE_TYPES[i] == "Single Color Intensity" || NODE_TYPES[i] == "Node Single Color") {
// get the color
wxColor v;
if (StringType == "Single Color Red") {
v = *wxRED;
} else if (StringType == "Single Color Green" || StringType == "G") {
v = *wxGREEN;
} else if (StringType == "Single Color Blue" || StringType == "B") {
v = *wxBLUE;
} else if (StringType == "Single Color White" || StringType == "W") {
v = *wxWHITE;
} else if (StringType == "Single Color Custom" || StringType == "Single Color Intensity" || StringType == "Node Single Color") {
v = customColor.asWxColor();
} else if (StringType[0] == '#') {
v = xlColor(StringType).asWxColor();
}
grid->AppendIn(p, new wxColourProperty("Color", "ModelStringColor", v));
if (NODE_TYPES[i] == "Node Single Color") {
grid->GetPropertyByName("ModelStringType")->SetHelpString("This represents a string of single color LEDS which are individually controlled. These are very uncommon.");
}
} else if (NODE_TYPES[i] == "Superstring") {
if (superStringColours.size() == 0) {
superStringColours.push_back(xlRED);
SaveSuperStringColours();
}
sp = grid->AppendIn(p, new wxIntProperty("Colours", "SuperStringColours", superStringColours.size()));
sp->SetAttribute("Min", 1);
sp->SetAttribute("Max", 32);
sp->SetEditor("SpinCtrl");
for (int i = 0; i < superStringColours.size(); ++i) {
grid->AppendIn(p, new wxColourProperty(wxString::Format("Colour %d", i + 1), wxString::Format("SuperStringColour%d", i), superStringColours[i].asWxColor()));
}