-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathXmlFileHelper.cpp
More file actions
2754 lines (2320 loc) · 103 KB
/
XmlFileHelper.cpp
File metadata and controls
2754 lines (2320 loc) · 103 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
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
//-----------------------------------------------------------------------------
//----- Copyright MVR Group
//-----------------------------------------------------------------------------
#include "Prefix/StdAfx.h"
#include <cmath>
using namespace VectorworksMVR::VWFC;
#include "SceneDataExchange.h"
#include "GDTFManager.h"
#include "XmlFileHelper.h"
#include "HashManager.h"
#include "GdtfError.h"
#include "Utility.h"
using namespace SceneData;
/*static*/ TXString GdtfConverter::ConvertUUID(const VWFC::Tools::VWUUID& uuid)
{
// Currenty this is working on strings, but if the see performance issues we could switch to
// the actual integer operation for this
//------------------------------------------------------
// This is how Vectorworks prints to string
// "09E95D97-364C-43d5-8ADF-FF4CE0EC41A7"
TXString vwUuid = uuid.ToString(false);
// First check if the length is as aspected
ASSERTN(kEveryone, vwUuid.GetLength() == 36);
return vwUuid;
}
/*static*/ bool GdtfConverter::ConvertUUID(const TXString& inValue, const IXMLFileNodePtr& node, VWFC::Tools::VWUUID& uuid)
{
// First check if theinValuelength is as aspected
TXString uuidForRead;
if (inValue.GetLength() == 47)
{
// Remove white space
TXString value = inValue;
value.Replace(" ", "");
uuidForRead.SetLength(38);
uuidForRead[0] = '{';
uuidForRead[1] = value[0];
uuidForRead[2] = value[1];
uuidForRead[3] = value[2];
uuidForRead[4] = value[3];
uuidForRead[5] = value[4];
uuidForRead[6] = value[5];
uuidForRead[7] = value[6];
uuidForRead[8] = value[7];
uuidForRead[9] = '-';
uuidForRead[10] = value[8];
uuidForRead[11] = value[9];
uuidForRead[12] = value[10];
uuidForRead[13] = value[11];
uuidForRead[14] = '-';
uuidForRead[15] = value[12];
uuidForRead[16] = value[13];
uuidForRead[17] = value[14];
uuidForRead[18] = value[15];
uuidForRead[19] = '-';
uuidForRead[20] = value[16];
uuidForRead[21] = value[17];
uuidForRead[22] = value[18];
uuidForRead[23] = value[19];
uuidForRead[24] = '-';
uuidForRead[25] = value[20];
uuidForRead[26] = value[21];
uuidForRead[27] = value[22];
uuidForRead[28] = value[23];
uuidForRead[29] = value[24];
uuidForRead[30] = value[25];
uuidForRead[31] = value[26];
uuidForRead[32] = value[27];
uuidForRead[33] = value[28];
uuidForRead[34] = value[29];
uuidForRead[35] = value[30];
uuidForRead[36] = value[31];
uuidForRead[37] = '}';
}
else if(inValue.GetLength() == 36)
{
uuidForRead += '{';
uuidForRead += inValue;
uuidForRead += '}';
}
else if(inValue.GetLength() == 0)
{
return false;
}
else
{
DSTOP((kEveryone, "Invalid UUID Format"));
GdtfParsingError error (GdtfDefines::EGdtfParsingError::eValueError_UuidHasWrongFormat, node);
SceneData::GdtfFixture::AddError(error);
}
uuid = VWUUID(uuidForRead);
return true;
}
/*static*/ bool GdtfConverter::ConvertUUID(const TXString& inValue, MvrUUID& inUuid)
{
VWFC::Tools::VWUUID uuid;
// First check if theinValuelength is as aspected
TXString uuidForRead;
if (inValue.GetLength() == 47)
{
// Remove white space
TXString value = inValue;
value.Replace(" ", "");
uuidForRead.SetLength(38);
uuidForRead[0] = '{';
uuidForRead[1] = value[0];
uuidForRead[2] = value[1];
uuidForRead[3] = value[2];
uuidForRead[4] = value[3];
uuidForRead[5] = value[4];
uuidForRead[6] = value[5];
uuidForRead[7] = value[6];
uuidForRead[8] = value[7];
uuidForRead[9] = '-';
uuidForRead[10] = value[8];
uuidForRead[11] = value[9];
uuidForRead[12] = value[10];
uuidForRead[13] = value[11];
uuidForRead[14] = '-';
uuidForRead[15] = value[12];
uuidForRead[16] = value[13];
uuidForRead[17] = value[14];
uuidForRead[18] = value[15];
uuidForRead[19] = '-';
uuidForRead[20] = value[16];
uuidForRead[21] = value[17];
uuidForRead[22] = value[18];
uuidForRead[23] = value[19];
uuidForRead[24] = '-';
uuidForRead[25] = value[20];
uuidForRead[26] = value[21];
uuidForRead[27] = value[22];
uuidForRead[28] = value[23];
uuidForRead[29] = value[24];
uuidForRead[30] = value[25];
uuidForRead[31] = value[26];
uuidForRead[32] = value[27];
uuidForRead[33] = value[28];
uuidForRead[34] = value[29];
uuidForRead[35] = value[30];
uuidForRead[36] = value[31];
uuidForRead[37] = '}';
}
else if(inValue.GetLength() == 36)
{
uuidForRead += '{';
uuidForRead += inValue;
uuidForRead += '}';
}
else if(inValue.GetLength() == 0)
{
return false;
}
VWUUID u;
bool result = uuid.FromString(uuidForRead);
uuid.GetUUID(inUuid.a, inUuid.b, inUuid.c, inUuid.d);
return result;
}
/*static*/ TXString GdtfConverter::IntToString2Digits(Sint64 value)
/* Converts the int to an string with 2 digits. If the int has only one digit the string will get a leading "0".*/
{
ASSERTN(kEveryone ,value < 100);
if (value < 10)
{
return "0" + TXString().itoa(value);
}
return TXString().itoa(value);
}
/*static*/ TXString GdtfConverter::ConvertDate(const STime& date)
/* Return the date in UTC Format: yyyy-mm-ddThh:mm:ss
*/
{
TXString result;
result += TXString().itoa(date.fYear);
result += "-";
result += IntToString2Digits(date.fMonth);
result += "-";
result += IntToString2Digits(date.fDay);
result += "T";
result += IntToString2Digits(date.fHour);
result += ":";
result += IntToString2Digits(date.fMinute);
result += ":";
result += IntToString2Digits(date.fSecond);
return result;
}
/*static*/ bool GdtfConverter::ConvertDate(const TXString& value, const IXMLFileNodePtr& node, STime& date)
/* Convert from UTC Format (yyyy-mm-ddThh:mm:ss) */
{
// ------------------------------------------------------------
// Check if the string is empty, use the 0 date
if (value.IsEmpty()) { date.fYear = 0; date.fMonth = 0; date.fDay = 0; date.fHour = 0; date.fMinute = 0; date.fSecond = 0; return true; }
// ------------------------------------------------------------
// Split string
TXString strVal = value;
// Prepare Array
TSint32Array d_arr;
DeserializeUTC_Date(strVal, node, d_arr);
// ------------------------------------------------------------
// Check if you have three valies
ASSERTN(kEveryone, d_arr.size() == 6);
if (d_arr.size() != 6)
{
GdtfParsingError error (GdtfDefines::EGdtfParsingError::eValueError_DateHasWrongFormat, node);
SceneData::GdtfFixture::AddError(error);
date.fYear = 0; date.fMonth = 0; date.fDay = 0; date.fHour = 0; date.fMinute = 0; date.fSecond = 0;
return false;
}
// Set Out Date
date.fYear = d_arr[0]; date.fMonth = d_arr[1]; date.fDay = d_arr[2];
date.fHour = d_arr[3]; date.fMinute = d_arr[4]; date.fSecond = d_arr[5];
return true;
}
/*static*/ TXString GdtfConverter::ConvertColor(const CCieColor& color)
{
return (TXString() << color.Get_x() << "," << color.Get_y() << "," << color.Get_Y_luminance() );
}
/*static*/ bool GdtfConverter::ConvertColor(const TXString& value, const IXMLFileNodePtr& node, CCieColor& color)
{
// ------------------------------------------------------------
// Check if the string is empty, use the default color
if (value.IsEmpty()) { color = CCieColor(); return true; }
// ------------------------------------------------------------
// Split string
TXString strVal = value;
// Prepare Array
std::vector<double> d_arr;
Deserialize(strVal, node, d_arr);
// ------------------------------------------------------------
// Check if you have three valies
ASSERTN(kEveryone, d_arr.size() == 3);
if (d_arr.size() != 3)
{
GdtfParsingError error (GdtfDefines::EGdtfParsingError::eValueError_ColorHasWrongFormat, node);
SceneData::GdtfFixture::AddError(error);
color = CCieColor();
return false;
}
// Set Out Color and return true
color = CCieColor(d_arr[0],d_arr[1],d_arr[2]);
return true;
}
TXString SceneData::GdtfConverter::ConvertColorArray(TCCieColorArray & colors)
/* Takes an CCieColor-Array and returns it as string in the format: "{x,y,Y}{x,y,Y}...{x,y,Y}" */
{
TXString arrayStr;
// Add the Values
for (size_t idx = 0; idx < colors.size(); idx++)
{
CCieColorPtr color = colors.at(idx);
arrayStr << "{" << color->Get_x() << "," << color->Get_y() << "," << color->Get_Y_luminance() << "}";
}
return arrayStr;
}
bool SceneData::GdtfConverter::ConvertColorArray(TXString values, const IXMLFileNodePtr& node, TCCieColorArray& colorArray)
/* Takes string in the format: "{x,y,Y}{x,y,Y}...{x,y,Y}" and fills the values into the colorArray. */
{
// ----------------------------------------------------------------
// If the String is empty, use the DefaultMatrix
if (values.IsEmpty()) { return true; }
TXString strVal = values;
// ----------------------------------------------------------------
// Delete first element
ASSERTN(kEveryone, strVal.GetAt(0) == '{');
if (strVal.GetAt(0) == '{') { strVal.Delete(0,1); }
else
{
GdtfParsingError error (GdtfDefines::EGdtfParsingError::eValueError_ColorArrayWrongFormat, node);
SceneData::GdtfFixture::AddError(error);
}
// Delete last element
ASSERTN(kEveryone, strVal.GetLast() == '}');
if (strVal.GetLast() == '}') { strVal.DeleteLast(); }
else
{
GdtfParsingError error (GdtfDefines::EGdtfParsingError::eValueError_ColorArrayWrongFormat, node);
SceneData::GdtfFixture::AddError(error);
}
// ----------------------------------------------------------------
// Split into parts
std::vector<TXString> lines;
ptrdiff_t pos = strVal.Find("}{");
while (pos > 0 )
{
// Copy string
TXString strValInner;
for (ptrdiff_t i = 0; i < pos; i++) { strValInner += strVal.GetAt(i); }
// Try to cast
lines.push_back(strValInner);
// Delete and find next
strVal.Delete(0, pos + 2);
pos = strVal.Find("}{");
}
// Append the rest
lines.push_back(strVal);
// ----------------------------------------------------------------
// Do the conversion
for (size_t i = 0; i < lines.size(); i++)
{
std::vector<double> arr;
Deserialize(lines.at(i), node, arr);
// Use this for 4x4 matrix and 4x3 matrix
if (arr.size() == 3)
{
CCieColorPtr color = new CCieColor(arr[0], arr[1], arr[2]);
colorArray.push_back(color);
}
else
{
DSTOP((kEveryone, "Unexpected Format of ColorArray"));
GdtfParsingError error (GdtfDefines::EGdtfParsingError::eValueError_ColorArrayWrongFormat, node);
SceneData::GdtfFixture::AddError(error);
}
}
return true;
}
/*static*/ TXString GdtfConverter::ConvertDouble(double value)
{
TXString valueStr;
valueStr << value;
return valueStr;
}
/*static*/ bool GdtfConverter::ConvertDouble(const TXString& value, const IXMLFileNodePtr& node, double& doubleValue) // TODO: XXX unused Param node
{
if(value.IsEmpty()) { return false; }
// Try to convert
doubleValue = value.atof();
// Return ig the casting was good
return true;
}
/*static*/ TXString GdtfConverter::ConvertInteger(Sint32 value)
{
TXString valueStr;
valueStr << value;
return valueStr;
}
#ifdef IS64BIT
/*static*/ TXString GdtfConverter::ConvertInteger(Uint32 value)
{
TXString valueStr;
valueStr << value;
return valueStr;
}
#endif
/*static*/ bool GdtfConverter::ConvertDmxBreak(const TXString& value, const IXMLFileNodePtr& node,Sint32& intValue)
{
if(value.IsEmpty()) return false;
if(value == XML_GDTF_DMXChannelDMXBreak_OverwriteValue) { intValue = 0; return true; }
intValue = value.atoi();
return true;
}
/*static*/ bool GdtfConverter::ConvertInteger(const TXString& value, const IXMLFileNodePtr& node,Sint8& intValue)
{
if(value.IsEmpty()) return false;
intValue = value.atoi();
return true;
}
/*static*/ bool GdtfConverter::ConvertInteger(const TXString& value, const IXMLFileNodePtr& node, Uint8& intValue)
{
if(value.IsEmpty()) return false;
intValue = value.atoi();
return true;
}
/*static*/ bool GdtfConverter::ConvertInteger(const TXString& value, const IXMLFileNodePtr& node,size_t& intValue)
{
if(value.IsEmpty()) return false;
intValue = value.atoi();
return true;
}
/*static*/ bool GdtfConverter::ConvertInteger(const TXString& value, const IXMLFileNodePtr& node,Sint32& intValue)
{
if(value.IsEmpty()) return false;
intValue = value.atoi();
return true;
}
#ifdef IS64BIT
/*static*/ bool GdtfConverter::ConvertInteger(const TXString& value, const IXMLFileNodePtr& node, Uint32& intValue)
{
if(value.IsEmpty()) return false;
intValue = value.atoi();
return true;
}
#endif
TXString SceneData::GdtfConverter::ConvertDMXValue(DmxValue value, EGdtfChannelBitResolution chanlReso, bool noneValue)
/* Convert DmxValue to String */
{
// Return None if it is the none value
if (noneValue) { return XML_GDTF_DMXFChannel_NONEVALUE; }
// Otherwise convert and return the value
TXString dmxValueStr;
dmxValueStr << TXString().itoa(value) << "/" << TXString().itoa( (Sint64)chanlReso);
return dmxValueStr;
}
/*static*/ TXString GdtfConverter::ConvertInteger(Sint32 value, bool noneValue)
{
// Return None if it is the none value
if (noneValue) { return XML_GDTF_DMXFChannel_NONEVALUE; }
// Otherwise return the value
TXString valueStr;
valueStr << value;
return valueStr;
}
TXString SceneData::GdtfConverter::ConvertIntegerArray(TSint32Array & values, bool includeBrackets)
/* Takes an Int-Array and returns it as string in the format: "{Int, Int, ... Int}" */
{
TXString arrayStr;
if(includeBrackets) { arrayStr += "{"; }
// Add the Values
for (size_t idx = 0; idx < values.size(); idx++)
{
arrayStr += TXString().ToStringInt(values.at(idx));
// The last index is size-1. We want that no "," is appended at the last item
// so only append "," for idx < last_idx.
if (idx < values.size() - 1)
{
arrayStr += ",";
}
}
// CLose the Array Str
if(includeBrackets) { arrayStr += "}"; }
return arrayStr;
}
bool SceneData::GdtfConverter::ConvertIntegerArray(TXString values, const IXMLFileNodePtr& node, TSint32Array & intArray)
/* Takes string in the format: "{Int, Int, ... Int}" and fills the values into the IntArray. */
{
TXString intArrayString = values;
if (values.IsEmpty()) { return false; }
// Remove the barcets "{" and "}"
values.Replace("{", "");
values.Replace("}", "");
// Seperate the string by ","
GdtfConverter::Deserialize(values, node, intArray);
return true;
}
TXString SceneData::GdtfConverter::ConvertDoubleArray(TDoubleArray & values, bool includeBrackets)
/* Takes an Int-Array and returns it as string in the format: "{Int, Int, ... Int}" */
{
TXString arrayStr;
if(includeBrackets) { arrayStr += "{"; }
// Add the Values
for (size_t idx = 0; idx < values.size(); idx++)
{
arrayStr += (TXString() << values.at(idx));
// The last index is size-1. We want that no "," is appended at the last item
// so only append "," for idx < last_idx.
if (idx < values.size() - 1)
{
arrayStr += ",";
}
}
// Close the Array Str
if(includeBrackets) { arrayStr += "}"; }
return arrayStr;
}
bool SceneData::GdtfConverter::ConvertDoubleArray(TXString values, const IXMLFileNodePtr& node, TDoubleArray & doubleArray)
/* Takes string in the format: "{double, double, ... double}" and fills the values into the doubleArray. */
{
TXString doubleArrayString = values;
if (values.IsEmpty()) { return false; }
// Remove the brackets "{" and "}"
values.Replace("{", "");
values.Replace("}", "");
// Separate the string by ","
GdtfConverter::Deserialize(values, node, doubleArray);
return true;
}
/*static*/ TXString GdtfConverter::ConvertInteger(size_t value)
{
// Otherwise return the value
TXString valueStr;
valueStr = TXString().itoa(value);
return valueStr;
}
/*static*/ TXString GdtfConverter::ConvertDmxBreak(Sint32 value)
{
// If it is not set then it is Overwrite value
if(value == 0){ return TXString( XML_GDTF_DMXChannelDMXBreak_OverwriteValue );}
// Otherwise return the value
TXString valueStr;
valueStr << value;
return valueStr;
}
TXString SceneData::GdtfConverter::ConvertDMXAdress(DMXAddress value)
/* Convert DMXAdress to String */
{
/* Absolute DMX address (size 4 bytes);
Alternative format: Universe � integer universe number, starting with 1; XXX check this
Address: address within universe from 1 to 512. Format: integer */
return ConvertInteger(value);
}
/*static*/ bool GdtfConverter::ConvertInteger(const TXString& value, const IXMLFileNodePtr& node,Sint32& intValue, bool& noneValue)
{
noneValue = false;
if (value == XML_GDTF_DMXFChannel_NONEVALUE) { noneValue = true; intValue = 0; return true; ; }
return ConvertInteger(value, node, intValue);;
}
bool SceneData::GdtfConverter::ConvertDMXAdress(const TXString& value, const IXMLFileNodePtr& node, DMXAddress & intValue)
/* Convert String to DMXAdress*/
{
if(value.IsEmpty()) {intValue = 1; return false;}
ptrdiff_t dotPos = value.Find('.');
bool error = false;
if(dotPos > 0){
Uint16 universe = value.Left(dotPos).atoi();
Uint16 address = value.Right(value.GetLength() - dotPos - 1).atoi();
if (universe <= 0 || address <= 0 || address > 512)
{
ASSERTN(kEveryone, false);
error = true;
}
intValue = (universe - 1) * 512 + address;
}else{
intValue = value.atoi();
ASSERTN(kEveryone, intValue > 0);
if (intValue <= 0)
{
error = true;
}
}
if(error){
GdtfParsingError error (GdtfDefines::EGdtfParsingError::eValueError_DmxAdressHasWrongValue, node);
SceneData::GdtfFixture::AddError(error);
return false;
}
return true;
}
bool SplitStr(const TXString& str, TXString& part1, TXString& part2, size_t splitPos, bool includeSplitPos=false)
/*
Split the provided string into 2 seperate string at splitPos.
If includeSplitPos is true the part1 will include the char at splitPos.
Returns the succes of the operation.
*/
{
size_t strLen = str.GetLength();
if (strLen <= splitPos) { return false; }
part1 = "";
part2 = "";
// First Part
for (size_t i = 0; i < splitPos; i++)
{
part1 += str.GetAt(i);
}
// 2nd Part: Start at Split pos + 1 to exclude the spilt char from the result.
size_t start2ndPart = 0;
if (includeSplitPos) { start2ndPart = splitPos; }
else { start2ndPart = splitPos + 1; }
for (size_t i = start2ndPart; i < strLen; i++) { part2 += str.GetAt(i); }
return true;
}
bool SceneData::GdtfConverter::ConvertDMXValue(const TXString& strValue, const IXMLFileNodePtr& node, EGdtfChannelBitResolution chanlReso, DmxValue & intValue)
/* Converts a string to a DmxValue. returns succes of the opeation as bool (XXX this is always true at the moment.)*/
{
if(strValue.IsEmpty())
{
intValue = 0;
return true;
}
// Split the String ("ValRaw/byteSpecifier")
TXString firstPart;
TXString secndPart;
bool byteShifting = false;
// Find first entry
ptrdiff_t splitPos = strValue.Find("/");
if (splitPos == -1)
{
GdtfParsingError error (GdtfDefines::EGdtfParsingError::eValueError_DmxValueHasWrongValue, node);
SceneData::GdtfFixture::AddError(error);
return false;
}
SplitStr(strValue, firstPart, secndPart, (size_t)splitPos);
//-----------------------------------------------------------------------------------
if(secndPart.GetLast() == 's')
{
byteShifting = true;
secndPart.Truncate(secndPart.GetLength() - 1);
}
double dmxValueRaw = firstPart.atof();
Sint32 byteSpecifier = secndPart.atoi();
if( ! (firstPart.IsCompleteNumber() && secndPart.IsCompleteNumber()))
{
GdtfParsingError error (GdtfDefines::EGdtfParsingError::eValueError_DmxValueHasWrongValue, node);
SceneData::GdtfFixture::AddError(error);
dmxValueRaw = 0;
byteSpecifier = 1;
}
// Check if the ByteSpecifier is different to the ChannelResolution.
intValue = dmxValueRaw;
if(byteShifting)
{
if (byteSpecifier != chanlReso)
{
Sint32 shift = (8 * (chanlReso - byteSpecifier));
if(shift >= 0) { intValue = intValue << shift; }
else { intValue = intValue >> -shift; }
}
else
{
// We can take the value as it is defined in the document without scaling it to another BitResolution.
intValue = dmxValueRaw;
}
}
else
{
if (byteSpecifier != chanlReso)
{
DmxValue maxResolution = GetChannelMaxDmx((EGdtfChannelBitResolution)byteSpecifier);
DmxValue maxChannelUnit = GetChannelMaxDmx(chanlReso);
double percentage = (dmxValueRaw / maxResolution);
double result = percentage * maxChannelUnit;
// Clamp to avoid floating-point precision errors when converting from higher to lower resolution
if (result > maxChannelUnit) {
intValue = maxChannelUnit;
} else {
// Preserve ordering: ensure non-zero inputs stay non-zero
if (dmxValueRaw > 0 && result < 1.0) {
intValue = 1;
} else {
intValue = static_cast<DmxValue>(result + 0.5);
}
if (intValue > maxChannelUnit) {
intValue = maxChannelUnit;
}
}
}
else
{
// We can take the value as it is defined in the document without scaling it to another BitResolution.
intValue = dmxValueRaw;
}
}
if ( intValue > GetChannelMaxDmx(chanlReso))
{
GdtfParsingError error (GdtfDefines::EGdtfParsingError::eValueError_DmxValueHasWrongValue, node);
SceneData::GdtfFixture::AddError(error);
return false;
}
return true;
}
bool SceneData::GdtfConverter::ConvertDMXValue(const TXString & strValue, const IXMLFileNodePtr& node, EGdtfChannelBitResolution chanlReso, DmxValue & intValue, bool & noneValue)
/* Converts a string to a DmxValue */
{
noneValue = false;
if (strValue == XML_GDTF_DMXFChannel_NONEVALUE)
{
noneValue = true;
return true;
}
ConvertDMXValue(strValue, node, chanlReso, intValue);
return true;
}
/*static*/ TXString GdtfConverter::ConvertPrimitiveType(EGdtfModel_PrimitiveType value)
{
switch (value)
{
case eGdtfModel_PrimitiveType_Cube: return XML_GDTF_PrimitiveTypeEnum_Cube;
case eGdtfModel_PrimitiveType_Sphere: return XML_GDTF_PrimitiveTypeEnum_Sphere;
case eGdtfModel_PrimitiveType_Cylinder: return XML_GDTF_PrimitiveTypeEnum_Cylinder;
case eGdtfModel_PrimitiveType_Undefined: return XML_GDTF_PrimitiveTypeEnum_Undefined;
case eGdtfModel_PrimitiveType_Base: return XML_GDTF_PrimitiveTypeEnum_Base;
case eGdtfModel_PrimitiveType_Head: return XML_GDTF_PrimitiveTypeEnum_Head;
case eGdtfModel_PrimitiveType_Yoke: return XML_GDTF_PrimitiveTypeEnum_Yoke;
case eGdtfModel_PrimitiveType_Scanner: return XML_GDTF_PrimitiveTypeEnum_Scanner;
case eGdtfModel_PrimitiveType_Conventional: return XML_GDTF_PrimitiveTypeEnum_Conventional;
case eGdtfModel_PrimitiveType_Pigtail: return XML_GDTF_PrimitiveTypeEnum_Pigtail;
case eGdtfModel_PrimitiveType_Base1_1: return XML_GDTF_PrimitiveTypeEnum_Base1_1;
case eGdtfModel_PrimitiveType_Scanner1_1: return XML_GDTF_PrimitiveTypeEnum_Scanner1_1;
case eGdtfModel_PrimitiveType_Conventional1_1: return XML_GDTF_PrimitiveTypeEnum_Conventional1_1;
default: return XML_GDTF_PrimitiveTypeEnum_Undefined;
}
// Make Assert
ASSERTN(kEveryone, value == eGdtfModel_PrimitiveType_Cube ||
value == eGdtfModel_PrimitiveType_Sphere ||
value == eGdtfModel_PrimitiveType_Undefined ||
value == eGdtfModel_PrimitiveType_Base ||
value == eGdtfModel_PrimitiveType_Head ||
value == eGdtfModel_PrimitiveType_Yoke ||
value == eGdtfModel_PrimitiveType_Scanner ||
value == eGdtfModel_PrimitiveType_Conventional ||
value == eGdtfModel_PrimitiveType_Pigtail ||
value == eGdtfModel_PrimitiveType_Base1_1 ||
value == eGdtfModel_PrimitiveType_Scanner1_1 ||
value == eGdtfModel_PrimitiveType_Conventional1_1);
// Return default value
return XML_GDTF_PrimitiveTypeEnum_Undefined;
}
/*static*/ bool GdtfConverter::ConvertPrimitiveType(const TXString& value, const IXMLFileNodePtr& node, EGdtfModel_PrimitiveType& type)
{
if (value == XML_GDTF_PrimitiveTypeEnum_Cube) { type = eGdtfModel_PrimitiveType_Cube; }
else if (value == XML_GDTF_PrimitiveTypeEnum_Sphere) { type = eGdtfModel_PrimitiveType_Sphere; }
else if (value == XML_GDTF_PrimitiveTypeEnum_Cylinder) { type = eGdtfModel_PrimitiveType_Cylinder; }
else if (value == XML_GDTF_PrimitiveTypeEnum_Base) { type = eGdtfModel_PrimitiveType_Base; }
else if (value == XML_GDTF_PrimitiveTypeEnum_Head) { type = eGdtfModel_PrimitiveType_Head; }
else if (value == XML_GDTF_PrimitiveTypeEnum_Yoke) { type = eGdtfModel_PrimitiveType_Yoke; }
else if (value == XML_GDTF_PrimitiveTypeEnum_Scanner) { type = eGdtfModel_PrimitiveType_Scanner; }
else if (value == XML_GDTF_PrimitiveTypeEnum_Conventional) { type = eGdtfModel_PrimitiveType_Conventional; }
else if (value == XML_GDTF_PrimitiveTypeEnum_Undefined) { type = eGdtfModel_PrimitiveType_Undefined; }
else if (value == XML_GDTF_PrimitiveTypeEnum_Pigtail) { type = eGdtfModel_PrimitiveType_Pigtail; }
else if (value == XML_GDTF_PrimitiveTypeEnum_Base1_1) { type = eGdtfModel_PrimitiveType_Base1_1; }
else if (value == XML_GDTF_PrimitiveTypeEnum_Scanner1_1) { type = eGdtfModel_PrimitiveType_Scanner1_1; }
else if (value == XML_GDTF_PrimitiveTypeEnum_Conventional1_1) { type = eGdtfModel_PrimitiveType_Conventional1_1; }
else if (value == "") { type = eGdtfModel_PrimitiveType_Undefined; }
else
{
type = eGdtfModel_PrimitiveType_Undefined; DSTOP((kEveryone, "Unexpected Input for Primitive Type Enum"));
GdtfParsingError error (GdtfDefines::EGdtfParsingError::eValueError_NoMatchInEnum_ConvertPrimitiveType, node);
SceneData::GdtfFixture::AddError(error);
}
// Return true
return true;
}
/*static*/ TXString GdtfConverter::ConvertSpecialAttrEnum(EGdtfSpecial value)
{
switch (value)
{
case EGdtfSpecial::None: return XML_GDTFPhysicalUnitEnum_None;
case EGdtfSpecial::Dimmer: return XML_EGdtfSpecialEnum_Dimmer;
case EGdtfSpecial::Pan: return XML_EGdtfSpecialEnum_Pan;
case EGdtfSpecial::Tilt: return XML_EGdtfSpecialEnum_Tilt;
case EGdtfSpecial::X: return XML_EGdtfSpecialEnum_X;
case EGdtfSpecial::Y: return XML_EGdtfSpecialEnum_Y;
case EGdtfSpecial::Z: return XML_EGdtfSpecialEnum_Z;
case EGdtfSpecial::RGB: return XML_EGdtfSpecialEnum_RGB;
case EGdtfSpecial::Hue: return XML_EGdtfSpecialEnum_Hue;
case EGdtfSpecial::Saturation: return XML_EGdtfSpecialEnum_Saturation;
case EGdtfSpecial::Brightness: return XML_EGdtfSpecialEnum_Brightness;
case EGdtfSpecial::ColorWheel: return XML_EGdtfSpecialEnum_ColorWheel;
case EGdtfSpecial::Focus: return XML_EGdtfSpecialEnum_Focus;
case EGdtfSpecial::Zoom: return XML_EGdtfSpecialEnum_Zoom;
case EGdtfSpecial::Dummy: return XML_EGdtfSpecialEnum_Dummy;
default: DSTOP((kEveryone,"EGdtfSpecial enum is not implemented!"));
}
// Return default value
return XML_GDTFPhysicalUnitEnum_None;
}
/*static*/ bool GdtfConverter::ConvertSpecialAttrEnum(const TXString& value, const IXMLFileNodePtr& node,EGdtfSpecial& special)
{
if (value == XML_GDTFPhysicalUnitEnum_None) { special = EGdtfSpecial::None; }
else if (value == XML_EGdtfSpecialEnum_Dimmer) { special = EGdtfSpecial::Dimmer; }
else if (value == XML_EGdtfSpecialEnum_Pan) { special = EGdtfSpecial::Pan; }
else if (value == XML_EGdtfSpecialEnum_Tilt) { special = EGdtfSpecial::Tilt; }
else if (value == XML_EGdtfSpecialEnum_X) { special = EGdtfSpecial::X; }
else if (value == XML_EGdtfSpecialEnum_Y) { special = EGdtfSpecial::Y; }
else if (value == XML_EGdtfSpecialEnum_Z) { special = EGdtfSpecial::Z; }
else if (value == XML_EGdtfSpecialEnum_RGB) { special = EGdtfSpecial::RGB; }
else if (value == XML_EGdtfSpecialEnum_Hue) { special = EGdtfSpecial::Hue; }
else if (value == XML_EGdtfSpecialEnum_Saturation) { special = EGdtfSpecial::Saturation; }
else if (value == XML_EGdtfSpecialEnum_Brightness) { special = EGdtfSpecial::Brightness; }
else if (value == XML_EGdtfSpecialEnum_ColorWheel) { special = EGdtfSpecial::ColorWheel; }
else if (value == XML_EGdtfSpecialEnum_Focus) { special = EGdtfSpecial::Focus; }
else if (value == XML_EGdtfSpecialEnum_Zoom) { special = EGdtfSpecial::Zoom; }
else if (value == XML_EGdtfSpecialEnum_Dummy) { special = EGdtfSpecial::Dummy; }
else if (value == "") { special = EGdtfSpecial::None; }
else
{
special = EGdtfSpecial::None; DSTOP((kEveryone, "Unexpected Input for EGdtfSpecial Enum"));
GdtfParsingError error (GdtfDefines::EGdtfParsingError::eValueError_NoMatchInEnum_ConvertSpecialAttr, node);
SceneData::GdtfFixture::AddError(error);
}
// Return true
return true;
}
/*static*/ TXString GdtfConverter::ConvertPhysicalUnitEnum(EGdtfPhysicalUnit value)
{
switch (value)
{
case EGdtfPhysicalUnit::None: return XML_GDTFPhysicalUnitEnum_None;
case EGdtfPhysicalUnit::Percent: return XML_GDTFPhysicalUnitEnum_Percent;
case EGdtfPhysicalUnit::Length: return XML_GDTFPhysicalUnitEnum_Length;
case EGdtfPhysicalUnit::Mass: return XML_GDTFPhysicalUnitEnum_Mass;
case EGdtfPhysicalUnit::Time: return XML_GDTFPhysicalUnitEnum_Time;
case EGdtfPhysicalUnit::Temperatur: return XML_GDTFPhysicalUnitEnum_Temperatur;
case EGdtfPhysicalUnit::LuminousItensity: return XML_GDTFPhysicalUnitEnum_LuminousItensity;
case EGdtfPhysicalUnit::Angle: return XML_GDTFPhysicalUnitEnum_Angle;
case EGdtfPhysicalUnit::Force: return XML_GDTFPhysicalUnitEnum_Force;
case EGdtfPhysicalUnit::Frequeny: return XML_GDTFPhysicalUnitEnum_Frequeny;
case EGdtfPhysicalUnit::Current: return XML_GDTFPhysicalUnitEnum_Current;
case EGdtfPhysicalUnit::Voltage: return XML_GDTFPhysicalUnitEnum_Voltage;
case EGdtfPhysicalUnit::Power: return XML_GDTFPhysicalUnitEnum_Power;
case EGdtfPhysicalUnit::Energy: return XML_GDTFPhysicalUnitEnum_Energy;
case EGdtfPhysicalUnit::Area: return XML_GDTFPhysicalUnitEnum_Area;
case EGdtfPhysicalUnit::Volume: return XML_GDTFPhysicalUnitEnum_Volume;
case EGdtfPhysicalUnit::Speed: return XML_GDTFPhysicalUnitEnum_Speed;
case EGdtfPhysicalUnit::Acceleration: return XML_GDTFPhysicalUnitEnum_Acceleration;
case EGdtfPhysicalUnit::AngularSpeed: return XML_GDTFPhysicalUnitEnum_AngularSpeed;
case EGdtfPhysicalUnit::AngularAccc: return XML_GDTFPhysicalUnitEnum_AngularAccc;
case EGdtfPhysicalUnit::WaveLength: return XML_GDTFPhysicalUnitEnum_WaveLength;
case EGdtfPhysicalUnit::ColorComponent: return XML_GDTFPhysicalUnitEnum_ColorComponent;
default: DSTOP((kEveryone,"This enum for EGdtfPhysicalUnit was not implemented!"));
}
// Return default value
return XML_GDTFPhysicalUnitEnum_None;
}
/*static*/ bool GdtfConverter::ConvertPhysicalUnitEnum(const TXString& value, const IXMLFileNodePtr& node,EGdtfPhysicalUnit& unit)
{
if (value == XML_GDTFPhysicalUnitEnum_None) { unit = EGdtfPhysicalUnit::None; }
else if (value == XML_GDTFPhysicalUnitEnum_Percent) { unit = EGdtfPhysicalUnit::Percent; }
else if (value == XML_GDTFPhysicalUnitEnum_Length) { unit = EGdtfPhysicalUnit::Length; }
else if (value == XML_GDTFPhysicalUnitEnum_Mass) { unit = EGdtfPhysicalUnit::Mass; }
else if (value == XML_GDTFPhysicalUnitEnum_Time) { unit = EGdtfPhysicalUnit::Time; }
else if (value == XML_GDTFPhysicalUnitEnum_Temperatur) { unit = EGdtfPhysicalUnit::Temperatur; }
else if (value == XML_GDTFPhysicalUnitEnum_LuminousItensity){ unit = EGdtfPhysicalUnit::LuminousItensity;}
else if (value == XML_GDTFPhysicalUnitEnum_Angle) { unit = EGdtfPhysicalUnit::Angle; }
else if (value == XML_GDTFPhysicalUnitEnum_Force) { unit = EGdtfPhysicalUnit::Force; }
else if (value == XML_GDTFPhysicalUnitEnum_Frequeny) { unit = EGdtfPhysicalUnit::Frequeny; }
else if (value == XML_GDTFPhysicalUnitEnum_Current) { unit = EGdtfPhysicalUnit::Current; }
else if (value == XML_GDTFPhysicalUnitEnum_Voltage) { unit = EGdtfPhysicalUnit::Voltage; }
else if (value == XML_GDTFPhysicalUnitEnum_Power) { unit = EGdtfPhysicalUnit::Power; }
else if (value == XML_GDTFPhysicalUnitEnum_Energy) { unit = EGdtfPhysicalUnit::Energy; }
else if (value == XML_GDTFPhysicalUnitEnum_Area) { unit = EGdtfPhysicalUnit::Area; }
else if (value == XML_GDTFPhysicalUnitEnum_Volume) { unit = EGdtfPhysicalUnit::Volume; }
else if (value == XML_GDTFPhysicalUnitEnum_Speed) { unit = EGdtfPhysicalUnit::Speed; }
else if (value == XML_GDTFPhysicalUnitEnum_Acceleration) { unit = EGdtfPhysicalUnit::Acceleration; }
else if (value == XML_GDTFPhysicalUnitEnum_AngularSpeed) { unit = EGdtfPhysicalUnit::AngularSpeed; }
else if (value == XML_GDTFPhysicalUnitEnum_AngularAccc) { unit = EGdtfPhysicalUnit::AngularAccc; }
else if (value == XML_GDTFPhysicalUnitEnum_WaveLength) { unit = EGdtfPhysicalUnit::WaveLength; }
else if (value == XML_GDTFPhysicalUnitEnum_ColorComponent) { unit = EGdtfPhysicalUnit::ColorComponent; }
else if (value == "") { unit = EGdtfPhysicalUnit::None; }
else
{
unit = EGdtfPhysicalUnit::None; DSTOP((kEveryone, "Unexpected Input for EGdtfPhysicalUnit Enum"));
GdtfParsingError error (GdtfDefines::EGdtfParsingError::eValueError_NoMatchInEnum_ConvertPhysicalUnit, node);
SceneData::GdtfFixture::AddError(error);
}
// Return true
return true;
}
/*static*/ bool GdtfConverter::ConvertBeamType(const TXString& value, const IXMLFileNodePtr& node,EGdtfBeamType& unit)
{
if (value == XML_GDTF_BeamTypeEnum_Wash) { unit = EGdtfBeamType::eGdtfBeamType_Wash; }
else if (value == XML_GDTF_BeamTypeEnum_Spot) { unit = EGdtfBeamType::eGdtfBeamType_Spot; }
else if (value == XML_GDTF_BeamTypeEnum_None) { unit = EGdtfBeamType::eGdtfBeamType_None; }
else if (value == XML_GDTF_BeamTypeEnum_Rectangle) { unit = EGdtfBeamType::eGdtfBeamType_Rectangle; }