-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBufferedLineToolOptionsViewModel.cs
116 lines (102 loc) · 4.03 KB
/
BufferedLineToolOptionsViewModel.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
// Copyright 2019 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
//
// https://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.Linq;
using System.Text;
using System.Threading.Tasks;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Controls;
using System.Xml.Linq;
using ArcGIS.Desktop.Editing;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace ArcSWAT3
{
//IEditingCreateToolControl
internal class PointToolOptionsViewModel : ToolOptionsEmbeddableControl
{
public PointToolOptionsViewModel(XElement options, bool canChangeOptions) : base(options, canChangeOptions) { }
internal const string BufferOptionName = nameof(Buffer);
internal const double DefaultBuffer = 25.0;
// binds in xaml
private double _buffer;
private double _originalBuffer;
public double Buffer {
get { return _buffer; }
set {
if (SetProperty(ref _buffer, value)) {
SetToolOption(BufferOptionName, value);
IsDirty = _buffer != _originalBuffer;
//** some scenario where IsValid = false especially in properties
if (!HostIsActiveTemplatePane) {
if (value > 30)
IsValid = false; // should deactivate the properties OK button
}
}
}
}
public override bool IsAutoOpen(string toolID) {
return true;
}
protected override Task LoadFromToolOptions() {
double? buffer = GetToolOption<double?>(BufferOptionName, DefaultBuffer, null);
_originalBuffer = buffer.GetValueOrDefault();
if (buffer.HasValue)
_buffer = buffer.Value;
else
_buffer = 0;
return Task.CompletedTask;
}
public override Task OpenAsync() {
return base.OpenAsync();
}
public override Task CloseAsync() {
return base.CloseAsync();
}
public override void OnInitialize(IEnumerable<ToolOptions> optionsCollection, bool hostIsActiveTmplatePane) {
base.OnInitialize(optionsCollection, hostIsActiveTmplatePane);
//var options = this.ToolOptions;
double val = double.NaN;
double firstVal = double.NaN;
foreach (var option in optionsCollection) {
val = option.GetProperty(BufferOptionName, DefaultBuffer);
if (double.IsNaN(firstVal))
firstVal = val;
else {
if (firstVal != val)
IsDifferentValue = true;
}
}
}
private bool _isDifferentValue;
public bool IsDifferentValue {
get => _isDifferentValue;
internal set => SetProperty(ref _isDifferentValue, value);
}
private BitmapImage _img = null;
public override ImageSource SelectorIcon {
get {
if (_img == null)
_img = new BitmapImage(new Uri(
"pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/AddFilter16.png", UriKind.Absolute));
return _img;
}
}
public new bool HostIsActiveTemplatePane => base.HostIsActiveTemplatePane;
public new bool HasMultipleTemplatesSelected => base.HasMultipleTemplatesSelected;
}
}