-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathBatchOutputParameterControl.cs
More file actions
183 lines (152 loc) · 5.27 KB
/
Copy pathBatchOutputParameterControl.cs
File metadata and controls
183 lines (152 loc) · 5.27 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
// -------------------------------------------------------------------------------------------
// <copyright file="BatchOutputParameterControl.cs" company="MapWindow OSS Team - www.mapwindow.org">
// MapWindow OSS Team - 2015
// </copyright>
// -------------------------------------------------------------------------------------------
using System;
using System.IO;
using System.Windows.Forms;
using MW5.Api.Enums;
using MW5.Plugins.Concrete;
using MW5.Plugins.Services;
using MW5.Tools.Controls.Parameters.Interfaces;
using MW5.Tools.Model;
using MW5.Tools.Model.Layers;
namespace MW5.Tools.Controls.Parameters
{
/// <summary>
/// Represents control to set path and name template for the names of output datasources.
/// </summary>
public partial class BatchOutputParameterControl : ParameterControlBase, IOuputputParameterControl
{
private readonly IFileDialogService _dialogService;
private string _extension = string.Empty;
private LayerType _layerType = LayerType.Invalid;
private string _template = string.Empty;
/// <summary>
/// Initializes a new instance of the <see cref="BatchOutputParameterControl"/> class.
/// </summary>
public BatchOutputParameterControl(IFileDialogService dialogService)
{
if (dialogService == null) throw new ArgumentNullException("dialogService");
_dialogService = dialogService;
InitializeComponent();
InitFlags();
RefreshControls();
txtPath.Cue = "<same folder as input>";
}
/// <summary>
/// Gets or sets the caption.
/// </summary>
public override string Caption
{
get { return label1.Text; }
set { label1.Text = value; }
}
/// <summary>
/// Gets control to display tooltip for.
/// </summary>
public override Control ToolTipControl
{
get { return txtTemplate; }
}
public void SetExtension(string extension)
{
_extension = extension;
RefreshTemplate();
}
public void OnFilenameChanged(string filename)
{
// do nothing
}
public void OnDatasourceChanged(IDatasourceInput input)
{
// do nothing
}
/// <summary>
/// Gets the control value.
/// </summary>
/// <returns>Instance of OutputLayerInfo class.</returns>
public override object GetValue()
{
SaveFlags();
var info = new OutputLayerInfo
{
AddToMap = chkAddToMap.Checked,
MemoryLayer = chkMemoryLayer.Checked,
Overwrite = chkOverwrite.Checked,
};
info.SetTemplate(txtPath.Text, txtTemplate.Text);
return info;
}
/// <summary>
/// Initializes output control with specified layer type.
/// </summary>
public void Initialize(LayerType layerType, bool supportsInMemory = true)
{
_layerType = layerType;
chkMemoryLayer.Enabled = supportsInMemory;
if (!supportsInMemory)
{
chkMemoryLayer.Checked = false;
}
}
/// <summary>
/// Sets the value.
/// </summary>
/// <param name="value">String value is expected.</param>
public override void SetValue(object value)
{
_template = Convert.ToString(value);
RefreshTemplate();
}
private void InitFlags()
{
chkAddToMap.Checked = AppConfig.Instance.ToolOutputAddToMap;
chkMemoryLayer.Checked = chkMemoryLayer.Enabled && AppConfig.Instance.ToolOutputInMemory;
chkOverwrite.Checked = AppConfig.Instance.ToolOutputOverwrite;
}
private void MemoryLayerChecked(object sender, EventArgs e)
{
RefreshControls();
}
private void OnOverwriteCheckedChanged(object sender, EventArgs e)
{
FireValueChanged();
}
private void OnSaveClick(object sender, EventArgs e)
{
string filename;
if (_dialogService.ChooseFolder(Directory.GetCurrentDirectory(), out filename))
{
txtPath.Text = filename;
}
}
private void RefreshControls()
{
if (chkMemoryLayer.Checked)
{
chkAddToMap.Checked = true;
}
chkAddToMap.Enabled = !chkMemoryLayer.Checked;
}
private void RefreshTemplate()
{
string s = _template;
if (!string.IsNullOrWhiteSpace(_extension))
{
s = Path.ChangeExtension(s, _extension);
}
txtTemplate.Text = s;
}
private void SaveFlags()
{
AppConfig.Instance.ToolOutputAddToMap = chkAddToMap.Checked;
AppConfig.Instance.ToolOutputOverwrite = chkOverwrite.Checked;
if (chkMemoryLayer.Enabled)
{
AppConfig.Instance.ToolOutputInMemory = chkMemoryLayer.Checked;
}
}
}
}