forked from Esri/military-symbology
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSymbolAttributeSet.cs
899 lines (733 loc) · 33.3 KB
/
SymbolAttributeSet.cs
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
/*******************************************************************************
* Copyright 2016 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
using System;
using System.Collections.Generic;
using System.Windows.Media.Imaging;
using ArcGIS.Core.Data;
using ArcGIS.Desktop.Framework.Contracts;
using System.Web.Script.Serialization;
using System.ComponentModel;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
namespace ProSymbolEditor
{
/// <summary>
/// This is the model for the entire set of information known about a military symbol
/// It is also how a symbol is serialized as a "favorite"
/// </summary>
[DisplayName("Symbol Attributes")]
public class SymbolAttributeSet : PropertyChangedBase
{
public SymbolAttributeSet()
{
Initialize();
}
public SymbolAttributeSet(Dictionary<string, string> fieldValues)
{
Initialize();
SetPropertiesFromFieldAttributes(fieldValues);
}
private void Initialize()
{
//Used to make a SymbolAttributeSet from field data in a feature
DisplayAttributes = new DisplayAttributes();
DisplayAttributes.PropertyChanged += Attributes_PropertyChanged;
LabelAttributes = new LabelAttributes();
LabelAttributes.PropertyChanged += LabelAttributes_PropertyChanged;
StandardVersion = ProSymbolUtilities.StandardString;
}
public override bool Equals(object obj)
{
if ((obj == null) || (GetType() != obj.GetType()))
return false;
SymbolAttributeSet compareObj = obj as SymbolAttributeSet;
if ((compareObj == null) || (DisplayAttributes == null) || (LabelAttributes == null))
return false;
return DisplayAttributes.Equals(compareObj.DisplayAttributes)
&& LabelAttributes.Equals(compareObj.LabelAttributes);
}
public override int GetHashCode()
{
if ((DisplayAttributes == null) || (LabelAttributes == null))
return 0;
else
return DisplayAttributes.GetHashCode() ^ LabelAttributes.GetHashCode();
}
[ScriptIgnore]
public Dictionary<string, string> AttributesDictionary
{
get
{
Dictionary<string, string> dict = new Dictionary<string, string>();
dict.Add("SymbolType", this.Name);
foreach (var prop in DisplayAttributes.GetType().GetProperties())
{
string key = prop.Name;
object value = prop.GetValue(DisplayAttributes, null);
if (value == null)
continue;
string valueAsString = value.ToString();
// Skip non-value types
if (valueAsString.StartsWith("ProSymbolEditor"))
continue;
// If debug needed:
// System.Diagnostics.Trace.WriteLine(string.Format("{0}={1}", key, valueAsString));
if (string.IsNullOrEmpty(valueAsString) || dict.ContainsKey(key))
continue;
dict.Add(key, valueAsString);
}
foreach (var prop in LabelAttributes.GetType().GetProperties())
{
string key = prop.Name;
object value = prop.GetValue(LabelAttributes, null);
if (value == null)
continue;
string valueAsString = value.ToString();
// Skip non-value types
if (valueAsString.StartsWith("ProSymbolEditor"))
continue;
// If debug needed:
// System.Diagnostics.Trace.WriteLine(string.Format("{0}={1}", key, valueAsString));
if (string.IsNullOrEmpty(valueAsString) || dict.ContainsKey(key))
continue;
dict.Add(key, valueAsString);
}
if (!string.IsNullOrEmpty(StandardVersion))
dict.Add("Standard", StandardVersion);
return dict;
}
}
#region Getters/Setters
[ExpandableObject]
public DisplayAttributes DisplayAttributes { get; set; }
[ExpandableObject]
public LabelAttributes LabelAttributes { get; set; }
public string Name
{
get
{
return ProSymbolUtilities.TagsToSymbolName(SymbolTags);
}
}
public string FavoriteId { get; set; }
private string _standardVersion = string.Empty;
public string StandardVersion {
get { return _standardVersion; }
set
{
if (value != _standardVersion)
{
_standardVersion = value;
NotifyPropertyChanged(() => StandardVersion);
}
}
}
/// <summary>
/// These are the symbol tags retrieved from a military feature style file or favorite
/// See the style file documentation: https://github.com/Esri/military-features-data
/// IMPORTANT/TRICKY:
/// Because all information known about a symbol comes from these style/favorite tags, key
/// tags have a particular position in the tag list so they can be found, this order is:
/// GEOMETRY_TYPE=tags[-3] (3rd to last list item)
/// SYMBOL_NAME=tags[-2] (2nd to last list item)
/// SYMBOL_ID=tags[-1] (last list item)
/// General tag format: {other tags};GEOMETRY_TYPE;SYMBOL_NAME;SYMBOL_ID
/// Example tags: Infantry; Land Unit; POINT; Land Unit : Infantry : 10110110
/// If you are modifying or overwriting these tags, the tag order for these last 3 tags must
/// be maintained because several places in the code depend on this information:
/// ex when loading a new style item or new favorite.
/// </summary>
public string SymbolTags { get; set; }
public bool IsValid
{
get
{
if (DisplayAttributes == null)
return false;
// Check any properties that indicate this object is not initialized/valid
if (string.IsNullOrEmpty(DisplayAttributes.SymbolSet) &&
string.IsNullOrEmpty(DisplayAttributes.ExtendedFunctionCode))
return false;
return true;
}
}
private BitmapImage _symbolImage = null;
[ScriptIgnore]
public BitmapImage SymbolImage
{
get
{
if (_symbolImage == null)
return UnknownSymbolImage;
return _symbolImage;
}
}
private BitmapImage _unknownSymbolImage = null;
[ScriptIgnore]
public BitmapImage UnknownSymbolImage
{
get
{
if (_unknownSymbolImage == null)
{
Uri oUri = new Uri(@"pack://application:,,,/MilitarySymbolEditor;component/Images/UnknownSymbol.png");
_unknownSymbolImage = new BitmapImage(oUri);
}
return _unknownSymbolImage;
}
}
#endregion
private System.Threading.Tasks.Task<System.Windows.Media.ImageSource> GetBitmapImageAsync(Dictionary<string, object> attributes)
{
if ((attributes == null) || (attributes.Count == 0))
return null;
return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => {
try
{
string standard = ProSymbolUtilities.GetDictionaryString();
ArcGIS.Core.CIM.CIMSymbol symbol = ArcGIS.Desktop.Mapping.SymbolFactory.Instance.GetDictionarySymbol(standard, attributes);
if (symbol == null)
return null;
// IMPORTANT + WORKAROUND + TRICKY:
// Pro SDK does not directly provide a way to set a PATCH_SIZE > 64 pixels
// However you can do this if the value is negative (-1) but it transforms/flips the image
// Therefore we flip the image back in:
// Views\MilitarySymbolDockpane.xaml.cs - Image.RenderTransform
// ViewModels\MilitarySymbolDockpaneViewModel.cs - GetClipboardImage
// If this ever gets changed/fixed in ProSDK, you must remove the flip there
const int PATCH_SIZE = -256; // negative value is a workaround
var si = new ArcGIS.Desktop.Mapping.SymbolStyleItem()
{
Symbol = symbol,
PatchHeight = PATCH_SIZE,
PatchWidth = PATCH_SIZE
};
return si.PreviewImage;
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine("Exception in GetBitmapImageAsync: " + ex.Message);
return null;
}
});
}
public async void GeneratePreviewSymbol()
{
// Step 1: Create a dictionary/map of well known attribute names to values
Dictionary<string, object> attributeSet = GenerateAttributeSetDictionary();
if ((attributeSet == null) || (attributeSet.Count == 0))
{
_symbolImage = null;
return;
}
_symbolImage = await GetBitmapImageAsync(attributeSet) as BitmapImage;
NotifyPropertyChanged(() => SymbolImage);
}
public Dictionary<string, object> GenerateAttributeSetDictionary()
{
Dictionary<string, object> attributeSet = new Dictionary<string, object>();
if (ProSymbolUtilities.Standard == ProSymbolUtilities.SupportedStandardsType.mil2525c_b2)
{
if (!string.IsNullOrEmpty(DisplayAttributes.ExtendedFunctionCode))
{
attributeSet["extendedfunctioncode"] = DisplayAttributes.ExtendedFunctionCode;
}
if (!string.IsNullOrEmpty(DisplayAttributes.Identity))
{
attributeSet["affiliation"] = DisplayAttributes.Identity;
}
if (!string.IsNullOrEmpty(DisplayAttributes.Status))
{
attributeSet["status"] = DisplayAttributes.Status;
}
if (!string.IsNullOrEmpty(DisplayAttributes.Indicator))
{
attributeSet["hqtffd"] = DisplayAttributes.Indicator;
}
if (!string.IsNullOrEmpty(DisplayAttributes.Echelon))
{
attributeSet["echelonmobility"] = DisplayAttributes.Echelon;
}
}
else // 2525D
{
if (!string.IsNullOrEmpty(DisplayAttributes.Identity))
{
attributeSet["identity"] = DisplayAttributes.Identity;
}
if (!string.IsNullOrEmpty(DisplayAttributes.SymbolSet))
{
attributeSet["symbolset"] = DisplayAttributes.SymbolSet;
}
if (!string.IsNullOrEmpty(DisplayAttributes.SymbolEntity))
{
attributeSet["symbolentity"] = DisplayAttributes.SymbolEntity;
}
if (!string.IsNullOrEmpty(DisplayAttributes.Indicator))
{
attributeSet["indicator"] = DisplayAttributes.Indicator;
}
//Echelon or Mobility
if (!string.IsNullOrEmpty(DisplayAttributes.Echelon))
{
attributeSet["echelon"] = DisplayAttributes.Echelon;
}
if (!string.IsNullOrEmpty(DisplayAttributes.Mobility))
{
attributeSet["echelon"] = DisplayAttributes.Mobility;
}
//Statuses or Operation
if (!string.IsNullOrEmpty(DisplayAttributes.OperationalCondition))
{
attributeSet["operationalcondition"] = DisplayAttributes.OperationalCondition;
}
if (!string.IsNullOrEmpty(DisplayAttributes.Status))
{
attributeSet["operationalcondition"] = DisplayAttributes.Status;
}
//Delta attributes
if (!string.IsNullOrEmpty(DisplayAttributes.Context))
{
attributeSet["context"] = DisplayAttributes.Context;
}
if (!string.IsNullOrEmpty(DisplayAttributes.Modifier1))
{
attributeSet["modifier1"] = DisplayAttributes.Modifier1;
}
if (!string.IsNullOrEmpty(DisplayAttributes.Modifier2))
{
attributeSet["modifier2"] = DisplayAttributes.Modifier2;
}
}
return attributeSet;
}
public void PopulateRowBufferWithAttributes(ref RowBuffer rowBuffer)
{
if (rowBuffer == null)
{
// not normally possible with ref parameter, but check just in case
System.Diagnostics.Debug.WriteLine("Null RowBuffer passed to PopulateRowBufferWithAttributes");
return;
}
if (ProSymbolUtilities.Standard == ProSymbolUtilities.SupportedStandardsType.mil2525c_b2)
{
if (!string.IsNullOrEmpty(DisplayAttributes.ExtendedFunctionCode))
{
rowBuffer["extendedfunctioncode"] = DisplayAttributes.ExtendedFunctionCode;
}
if (!string.IsNullOrEmpty(DisplayAttributes.Identity))
{
rowBuffer["affiliation"] = DisplayAttributes.Identity;
}
if (!string.IsNullOrEmpty(DisplayAttributes.Indicator))
{
rowBuffer["hqtffd"] = DisplayAttributes.Indicator;
}
if (!string.IsNullOrEmpty(DisplayAttributes.Echelon))
{
rowBuffer["echelonmobility"] = DisplayAttributes.Echelon;
}
}
else
{
if (!string.IsNullOrEmpty(DisplayAttributes.Identity))
{
rowBuffer["identity"] = DisplayAttributes.Identity;
}
if (!string.IsNullOrEmpty(DisplayAttributes.SymbolSet))
{
rowBuffer["symbolset"] = Convert.ToInt32(DisplayAttributes.SymbolSet);
}
if (!string.IsNullOrEmpty(DisplayAttributes.SymbolEntity))
{
rowBuffer["symbolentity"] = Convert.ToInt32(DisplayAttributes.SymbolEntity);
}
//Indicator / HQTFFD /
if (!string.IsNullOrEmpty(DisplayAttributes.Indicator))
{
rowBuffer["indicator"] = DisplayAttributes.Indicator;
}
//Echelon or Mobility
if (!string.IsNullOrEmpty(DisplayAttributes.Echelon))
{
rowBuffer["echelon"] = DisplayAttributes.Echelon;
}
if (!string.IsNullOrEmpty(DisplayAttributes.Mobility))
{
rowBuffer["mobility"] = DisplayAttributes.Mobility;
}
//Statuses or Operation
if (!string.IsNullOrEmpty(DisplayAttributes.OperationalCondition))
{
rowBuffer["operationalcondition"] = DisplayAttributes.OperationalCondition;
}
//Delta attributes
if (!string.IsNullOrEmpty(DisplayAttributes.Context))
{
rowBuffer["context"] = DisplayAttributes.Context;
}
if (!string.IsNullOrEmpty(DisplayAttributes.Modifier1))
{
rowBuffer["modifier1"] = DisplayAttributes.Modifier1;
}
if (!string.IsNullOrEmpty(DisplayAttributes.Modifier2))
{
rowBuffer["modifier2"] = DisplayAttributes.Modifier2;
}
}
if (!string.IsNullOrEmpty(DisplayAttributes.Status))
{
rowBuffer["status"] = DisplayAttributes.Status;
}
//LABELS
if (LabelAttributes.DateTimeValid != null)
{
rowBuffer["datetimevalid"] = LabelAttributes.DateTimeValid.ToString();
}
if (LabelAttributes.DateTimeExpired != null)
{
rowBuffer["datetimeexpired"] = LabelAttributes.DateTimeExpired.ToString();
}
if (!string.IsNullOrEmpty(LabelAttributes.UniqueDesignation))
{
rowBuffer["uniquedesignation"] = LabelAttributes.UniqueDesignation;
}
if (!string.IsNullOrEmpty(LabelAttributes.StaffComments))
{
rowBuffer["staffcomment"] = LabelAttributes.StaffComments;
}
if (!string.IsNullOrEmpty(LabelAttributes.AdditionalInformation))
{
rowBuffer["additionalinformation"] = LabelAttributes.AdditionalInformation;
}
if (!string.IsNullOrEmpty(LabelAttributes.Type))
{
rowBuffer["type"] = LabelAttributes.Type;
}
if (!string.IsNullOrEmpty(LabelAttributes.CommonIdentifier))
{
rowBuffer["commonidentifier"] = LabelAttributes.CommonIdentifier;
}
if (LabelAttributes.Speed != null)
{
//Short
rowBuffer["speed"] = LabelAttributes.Speed;
}
if (!string.IsNullOrEmpty(LabelAttributes.HigherFormation))
{
rowBuffer["higherFormation"] = LabelAttributes.HigherFormation;
}
if (!string.IsNullOrEmpty(LabelAttributes.Reinforced))
{
rowBuffer["reinforced"] = LabelAttributes.Reinforced;
}
if (!string.IsNullOrEmpty(LabelAttributes.Credibility))
{
rowBuffer["credibility"] = LabelAttributes.Credibility;
}
if (!string.IsNullOrEmpty(LabelAttributes.Reliability))
{
rowBuffer["reliability"] = LabelAttributes.Reliability;
}
if (!string.IsNullOrEmpty(LabelAttributes.CountryCode))
{
rowBuffer["countrycode"] = LabelAttributes.CountryCode;
}
}
public void PopulateFeatureWithAttributes(ref Feature feature)
{
if (feature == null)
{
// not normally possible with ref parameter, but check just in case
System.Diagnostics.Debug.WriteLine("Null Feature passed to PopulateFeatureWithAttributes");
return;
}
// Implementation Note: feature fields with domains attached can not be set to null
// so these fields with domains must also be checked for IsNullOrEmpty
if (ProSymbolUtilities.Standard == ProSymbolUtilities.SupportedStandardsType.mil2525c_b2)
{
if (!string.IsNullOrEmpty(DisplayAttributes.ExtendedFunctionCode) &&
(feature.FindField("extendedfunctioncode") >= 0))
feature["extendedfunctioncode"] = DisplayAttributes.ExtendedFunctionCode;
if (!string.IsNullOrEmpty(DisplayAttributes.Identity) &&
(feature.FindField("affiliation") >= 0))
feature["affiliation"] = DisplayAttributes.Identity;
if (!string.IsNullOrEmpty(DisplayAttributes.Indicator) &&
(feature.FindField("hqtffd") >= 0))
feature["hqtffd"] = DisplayAttributes.Indicator;
if (!string.IsNullOrEmpty(DisplayAttributes.Echelon) &&
(feature.FindField("echelonmobility") >= 0))
feature["echelonmobility"] = DisplayAttributes.Echelon;
}
else // 2525D/Delta attributes
{
if (!string.IsNullOrEmpty(DisplayAttributes.Identity) &&
(feature.FindField("identity") >= 0))
feature["identity"] = DisplayAttributes.Identity;
if (!string.IsNullOrEmpty(DisplayAttributes.SymbolSet) &&
(feature.FindField("symbolset") >= 0))
feature["symbolset"] = Convert.ToInt32(DisplayAttributes.SymbolSet);
if (!string.IsNullOrEmpty(DisplayAttributes.SymbolEntity) &&
(feature.FindField("symbolentity") >= 0))
feature["symbolentity"] = Convert.ToInt32(DisplayAttributes.SymbolEntity);
//Indicator / HQTFFD
if (!string.IsNullOrEmpty(DisplayAttributes.Indicator) &&
(feature.FindField("indicator") >= 0))
feature["indicator"] = DisplayAttributes.Indicator;
//Echelon or Mobility
if (!string.IsNullOrEmpty(DisplayAttributes.Echelon) &&
(feature.FindField("echelon") >= 0))
feature["echelon"] = DisplayAttributes.Echelon;
if (!string.IsNullOrEmpty(DisplayAttributes.Mobility) &&
(feature.FindField("mobility") >= 0))
feature["mobility"] = DisplayAttributes.Mobility;
//Statuses or Operation
if (!string.IsNullOrEmpty(DisplayAttributes.OperationalCondition) &&
(feature.FindField("operationalcondition") >= 0))
feature["operationalcondition"] = DisplayAttributes.OperationalCondition;
if (!string.IsNullOrEmpty(DisplayAttributes.Context) &&
(feature.FindField("context") >= 0))
feature["context"] = DisplayAttributes.Context;
//Modifiers
if (!string.IsNullOrEmpty(DisplayAttributes.Modifier1) &&
(feature.FindField("modifier1") >= 0))
feature["modifier1"] = DisplayAttributes.Modifier1;
if (!string.IsNullOrEmpty(DisplayAttributes.Modifier2) &&
(feature.FindField("modifier2") >= 0))
feature["modifier2"] = DisplayAttributes.Modifier2;
}
// Apply to all versions of the standard
if (!string.IsNullOrEmpty(DisplayAttributes.Status) &&
(feature.FindField("status") >= 0))
feature["status"] = DisplayAttributes.Status;
//LABELS
if ((LabelAttributes.DateTimeValid != null) &&
(feature.FindField("datetimevalid") >= 0))
{
feature["datetimevalid"] = LabelAttributes.DateTimeValid.ToString();
}
if ((LabelAttributes.DateTimeExpired != null) &&
(feature.FindField("datetimeexpired") >= 0))
{
feature["datetimeexpired"] = LabelAttributes.DateTimeExpired.ToString();
}
if (feature.FindField("uniquedesignation") >= 0)
feature["uniquedesignation"] = LabelAttributes.UniqueDesignation;
if (feature.FindField("staffcomment") >= 0)
feature["staffcomment"] = LabelAttributes.StaffComments;
if (feature.FindField("additionalinformation") >= 0)
feature["additionalinformation"] = LabelAttributes.AdditionalInformation;
if (feature.FindField("type") >= 0)
feature["type"] = LabelAttributes.Type;
if (feature.FindField("commonidentifier") >= 0)
feature["commonidentifier"] = LabelAttributes.CommonIdentifier;
if (feature.FindField("speed") >= 0)
feature["speed"] = LabelAttributes.Speed;
if (feature.FindField("higherFormation") >= 0)
feature["higherFormation"] = LabelAttributes.HigherFormation;
if (!string.IsNullOrEmpty(LabelAttributes.Reinforced) &&
(feature.FindField("reinforced") >= 0))
feature["reinforced"] = LabelAttributes.Reinforced;
if (!string.IsNullOrEmpty(LabelAttributes.Credibility) &&
(feature.FindField("credibility") >= 0))
feature["credibility"] = LabelAttributes.Credibility;
if (!string.IsNullOrEmpty(LabelAttributes.Reliability) &&
(feature.FindField("reliability") >= 0))
feature["reliability"] = LabelAttributes.Reliability;
if (!string.IsNullOrEmpty(LabelAttributes.CountryCode) &&
(feature.FindField("countrycode") >= 0))
feature["countrycode"] = LabelAttributes.CountryCode;
}
private void SetPropertiesFromFieldAttributes(Dictionary<string, string> fieldValues)
{
if (fieldValues == null)
return;
if (ProSymbolUtilities.Standard == ProSymbolUtilities.SupportedStandardsType.mil2525c_b2)
{
if (fieldValues.ContainsKey("extendedfunctioncode"))
{
DisplayAttributes.ExtendedFunctionCode = fieldValues["extendedfunctioncode"];
}
if (fieldValues.ContainsKey("affiliation"))
{
DisplayAttributes.Identity = fieldValues["affiliation"];
}
if (fieldValues.ContainsKey("hqtffd"))
{
DisplayAttributes.Indicator = fieldValues["hqtffd"];
}
if (fieldValues.ContainsKey("echelonmobility"))
{
DisplayAttributes.Echelon = fieldValues["echelonmobility"];
}
}
else
{
if (fieldValues.ContainsKey("identity"))
{
DisplayAttributes.Identity = fieldValues["identity"];
}
if (fieldValues.ContainsKey("symbolset"))
{
// Tricky symbolset string expected to be len 2 - fixes bug with "01" "02" "05" symbol sets
string symbolSetValue = fieldValues["symbolset"];
if (!string.IsNullOrEmpty(symbolSetValue))
{
string paddedSymbolSet = symbolSetValue.PadLeft(2, '0');
DisplayAttributes.SymbolSet = paddedSymbolSet;
}
}
if (fieldValues.ContainsKey("symbolentity"))
{
DisplayAttributes.SymbolEntity = fieldValues["symbolentity"];
}
if (fieldValues.ContainsKey("indicator"))
{
DisplayAttributes.Indicator = fieldValues["indicator"];
}
if (fieldValues.ContainsKey("echelon"))
{
DisplayAttributes.Echelon = fieldValues["echelon"];
}
if (fieldValues.ContainsKey("mobility"))
{
DisplayAttributes.Mobility = fieldValues["mobility"];
}
if (fieldValues.ContainsKey("operationalcondition"))
{
DisplayAttributes.OperationalCondition = fieldValues["operationalcondition"];
}
if (fieldValues.ContainsKey("context"))
{
DisplayAttributes.Context = fieldValues["context"];
}
if (fieldValues.ContainsKey("modifier1"))
{
DisplayAttributes.Modifier1 = fieldValues["modifier1"];
}
if (fieldValues.ContainsKey("modifier2"))
{
DisplayAttributes.Modifier2 = fieldValues["modifier2"];
}
}
if (fieldValues.ContainsKey("status"))
{
DisplayAttributes.Status = fieldValues["status"];
}
//LABELS
if (fieldValues.ContainsKey("datetimevalid"))
{
// TODO: add tryparse
LabelAttributes.DateTimeValid = DateTime.Parse(fieldValues["datetimevalid"]);
}
if (fieldValues.ContainsKey("datetimeexpired"))
{
// TODO: add tryparse
LabelAttributes.DateTimeExpired = DateTime.Parse(fieldValues["datetimeexpired"]);
}
if (fieldValues.ContainsKey("uniquedesignation"))
{
LabelAttributes.UniqueDesignation = fieldValues["uniquedesignation"];
}
if (fieldValues.ContainsKey("staffcomment"))
{
LabelAttributes.StaffComments = fieldValues["staffcomment"];
}
if (fieldValues.ContainsKey("additionalinformation"))
{
LabelAttributes.AdditionalInformation = fieldValues["additionalinformation"];
}
if (fieldValues.ContainsKey("type"))
{
LabelAttributes.Type = fieldValues["type"];
}
if (fieldValues.ContainsKey("commonidentifier"))
{
LabelAttributes.CommonIdentifier = fieldValues["commonidentifier"];
}
if (fieldValues.ContainsKey("speed"))
{
LabelAttributes.Speed = short.Parse(fieldValues["speed"]);
}
if (fieldValues.ContainsKey("higherFormation"))
{
LabelAttributes.HigherFormation = fieldValues["higherFormation"];
}
if (fieldValues.ContainsKey("reinforced"))
{
LabelAttributes.Reinforced = fieldValues["reinforced"];
}
if (fieldValues.ContainsKey("credibility"))
{
LabelAttributes.Credibility = fieldValues["credibility"];
}
if (fieldValues.ContainsKey("reliability"))
{
LabelAttributes.Reliability = fieldValues["reliability"];
}
if (fieldValues.ContainsKey("countrycode"))
{
LabelAttributes.CountryCode = fieldValues["countrycode"];
}
}
public void ResetAttributes()
{
//Reset attributes
_symbolImage = null;
DisplayAttributes.SymbolSet = "";
DisplayAttributes.SymbolEntity = "";
DisplayAttributes.ExtendedFunctionCode = "";
DisplayAttributes.Echelon = "";
DisplayAttributes.Identity = "";
DisplayAttributes.OperationalCondition = "";
DisplayAttributes.Status = "";
DisplayAttributes.Mobility = "";
DisplayAttributes.Indicator = "";
DisplayAttributes.Context = "";
DisplayAttributes.Modifier1 = "";
DisplayAttributes.Modifier2 = "";
//Reset label text attributes
LabelAttributes.DateTimeValid = null;
LabelAttributes.DateTimeExpired = null;
LabelAttributes.UniqueDesignation = "";
LabelAttributes.StaffComments = "";
LabelAttributes.AdditionalInformation = "";
LabelAttributes.Type = "";
LabelAttributes.CommonIdentifier = "";
LabelAttributes.Speed = null;
LabelAttributes.HigherFormation = "";
LabelAttributes.Reinforced = "";
LabelAttributes.Credibility = null;
LabelAttributes.Reliability = "";
LabelAttributes.CountryCode = "";
SymbolTags = "";
StandardVersion = ProSymbolUtilities.StandardString;
NotifyPropertyChanged(() => IsValid);
}
private void Attributes_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
GeneratePreviewSymbol();
// Tell the proprties datagrids to get the updated info
NotifyPropertyChanged(() => Name);
NotifyPropertyChanged(() => AttributesDictionary);
}
private void LabelAttributes_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
// Tell the proprties datagrids to get the updated info
NotifyPropertyChanged(() => Name);
NotifyPropertyChanged(() => AttributesDictionary);
}
}
}