2019-11-25 22:27:38 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright 2019 faddenSoft
|
|
|
|
|
*
|
|
|
|
|
* 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;
|
|
|
|
|
using System.Collections.Generic;
|
2019-11-27 02:54:42 +00:00
|
|
|
|
using System.Collections.ObjectModel;
|
2019-11-25 22:27:38 +00:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
2019-11-28 01:12:26 +00:00
|
|
|
|
using System.Windows.Media.Imaging;
|
2019-11-25 22:27:38 +00:00
|
|
|
|
using Asm65;
|
|
|
|
|
using PluginCommon;
|
|
|
|
|
|
|
|
|
|
namespace SourceGen.WpfGui {
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Visualization editor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class EditVisualization : Window, INotifyPropertyChanged {
|
2019-11-27 02:54:42 +00:00
|
|
|
|
private const int MIN_TRIMMED_TAG_LEN = 2;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Dialog result.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Visualization NewVis { get; private set; }
|
|
|
|
|
|
2019-11-25 22:27:38 +00:00
|
|
|
|
private DisasmProject mProject;
|
|
|
|
|
private Formatter mFormatter;
|
|
|
|
|
private Visualization mOrigVis;
|
|
|
|
|
|
2019-11-27 02:54:42 +00:00
|
|
|
|
private Brush mDefaultLabelColor = SystemColors.WindowTextBrush;
|
|
|
|
|
private Brush mErrorLabelColor = Brushes.Red;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// True if all properties are in valid ranges. Determines whether the OK button
|
|
|
|
|
/// is enabled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsValid {
|
|
|
|
|
get { return mIsValid; }
|
|
|
|
|
set { mIsValid = value; OnPropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
private bool mIsValid;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Visualization tag.
|
|
|
|
|
/// </summary>
|
2019-11-25 22:27:38 +00:00
|
|
|
|
public string TagString {
|
|
|
|
|
get { return mTagString; }
|
|
|
|
|
set { mTagString = value; OnPropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
private string mTagString;
|
|
|
|
|
|
2019-11-27 02:54:42 +00:00
|
|
|
|
public Brush TagLabelBrush {
|
|
|
|
|
get { return mTagLabelBrush; }
|
|
|
|
|
set { mTagLabelBrush = value; OnPropertyChanged(); }
|
2019-11-25 22:27:38 +00:00
|
|
|
|
}
|
2019-11-27 02:54:42 +00:00
|
|
|
|
private Brush mTagLabelBrush;
|
|
|
|
|
|
2019-11-28 01:12:26 +00:00
|
|
|
|
public class VisualizationItem {
|
|
|
|
|
public IPlugin_Visualizer Plugin { get; private set; }
|
|
|
|
|
public VisDescr VisDescriptor { get; private set; }
|
|
|
|
|
public VisualizationItem(IPlugin_Visualizer plugin, VisDescr descr) {
|
|
|
|
|
Plugin = plugin;
|
|
|
|
|
VisDescriptor = descr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-27 02:54:42 +00:00
|
|
|
|
/// <summary>
|
2019-11-28 01:12:26 +00:00
|
|
|
|
/// List of visualizers, for combo box.
|
2019-11-27 02:54:42 +00:00
|
|
|
|
/// </summary>
|
2019-11-28 01:12:26 +00:00
|
|
|
|
public List<VisualizationItem> VisualizationList { get; private set; }
|
2019-11-27 02:54:42 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-11-28 01:12:26 +00:00
|
|
|
|
/// ItemsSource for the ItemsControl with the generated parameter controls.
|
2019-11-27 02:54:42 +00:00
|
|
|
|
/// </summary>
|
2019-11-28 01:12:26 +00:00
|
|
|
|
public ObservableCollection<ParameterValue> ParameterList { get; private set; } =
|
|
|
|
|
new ObservableCollection<ParameterValue>();
|
2019-11-25 22:27:38 +00:00
|
|
|
|
|
|
|
|
|
// INotifyPropertyChanged implementation
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
private void OnPropertyChanged([CallerMemberName] string propertyName = "") {
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-01 01:52:33 +00:00
|
|
|
|
private class ScriptSupport : MarshalByRefObject, PluginCommon.IApplication {
|
|
|
|
|
public ScriptSupport() { }
|
|
|
|
|
public void DebugLog(string msg) {
|
|
|
|
|
Debug.WriteLine("Vis plugin: " + msg);
|
|
|
|
|
}
|
|
|
|
|
public bool SetOperandFormat(int offset, DataSubType subType, string label) {
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
|
|
|
|
public bool SetInlineDataFormat(int offset, int length, DataType type,
|
|
|
|
|
DataSubType subType, string label) {
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private ScriptSupport mScriptSupport = new ScriptSupport();
|
|
|
|
|
|
2019-11-27 02:54:42 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="owner">Owner window.</param>
|
|
|
|
|
/// <param name="proj">Project reference.</param>
|
|
|
|
|
/// <param name="formatter">Text formatter.</param>
|
|
|
|
|
/// <param name="vis">Visualization to edit, or null if this is new.</param>
|
2019-11-25 22:27:38 +00:00
|
|
|
|
public EditVisualization(Window owner, DisasmProject proj, Formatter formatter,
|
|
|
|
|
Visualization vis) {
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
Owner = owner;
|
|
|
|
|
DataContext = this;
|
|
|
|
|
|
|
|
|
|
mProject = proj;
|
|
|
|
|
mFormatter = formatter;
|
|
|
|
|
mOrigVis = vis;
|
|
|
|
|
|
2019-11-27 02:54:42 +00:00
|
|
|
|
if (vis != null) {
|
|
|
|
|
TagString = vis.Tag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int visSelection = 0;
|
2019-11-28 01:12:26 +00:00
|
|
|
|
VisualizationList = new List<VisualizationItem>();
|
2019-11-27 02:54:42 +00:00
|
|
|
|
List<IPlugin> plugins = proj.GetActivePlugins();
|
|
|
|
|
foreach (IPlugin chkPlug in plugins) {
|
|
|
|
|
if (!(chkPlug is IPlugin_Visualizer)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
IPlugin_Visualizer vplug = (IPlugin_Visualizer)chkPlug;
|
|
|
|
|
foreach (VisDescr descr in vplug.GetVisGenDescrs()) {
|
|
|
|
|
if (vis != null && vis.VisGenIdent == descr.Ident) {
|
|
|
|
|
visSelection = VisualizationList.Count;
|
|
|
|
|
}
|
2019-11-28 01:12:26 +00:00
|
|
|
|
VisualizationList.Add(new VisualizationItem(vplug, descr));
|
2019-11-27 02:54:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-25 22:27:38 +00:00
|
|
|
|
|
2019-11-27 02:54:42 +00:00
|
|
|
|
// Set the selection. This should cause the sel change event to fire.
|
|
|
|
|
visComboBox.SelectedIndex = visSelection;
|
2019-12-01 01:52:33 +00:00
|
|
|
|
mProject.PrepareScripts(mScriptSupport);
|
2019-11-25 22:27:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generates the list of parameter controls.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// We need to get the list of parameters from the VisGen plugin, then for each
|
|
|
|
|
/// parameter we need to merge the value from the Visualization's value list.
|
|
|
|
|
/// If we don't find a corresponding entry in the Visualization, we use the
|
|
|
|
|
/// default value.
|
|
|
|
|
/// </remarks>
|
2019-11-27 02:54:42 +00:00
|
|
|
|
private void GenerateParamControls(VisDescr descr) {
|
|
|
|
|
VisParamDescr[] paramDescrs = descr.VisParamDescrs;
|
2019-11-25 22:27:38 +00:00
|
|
|
|
|
2019-11-27 02:54:42 +00:00
|
|
|
|
ParameterList.Clear();
|
|
|
|
|
foreach (VisParamDescr vpd in paramDescrs) {
|
2019-11-25 22:27:38 +00:00
|
|
|
|
string rangeStr = string.Empty;
|
|
|
|
|
object defaultVal = vpd.DefaultValue;
|
|
|
|
|
if (mOrigVis.VisGenParams.TryGetValue(vpd.Name, out object val)) {
|
|
|
|
|
// Do we need to confirm that val has the correct type?
|
|
|
|
|
defaultVal = val;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-27 02:54:42 +00:00
|
|
|
|
// Set up rangeStr, if appropriate.
|
|
|
|
|
VisParamDescr altVpd = vpd;
|
2019-11-25 22:27:38 +00:00
|
|
|
|
if (vpd.CsType == typeof(int) || vpd.CsType == typeof(float)) {
|
|
|
|
|
if (vpd.Special == VisParamDescr.SpecialMode.Offset) {
|
|
|
|
|
defaultVal = mFormatter.FormatOffset24((int)defaultVal);
|
|
|
|
|
rangeStr = "[" + mFormatter.FormatOffset24(0) + "," +
|
|
|
|
|
mFormatter.FormatOffset24(mProject.FileDataLength - 1) + "]";
|
2019-11-27 02:54:42 +00:00
|
|
|
|
|
|
|
|
|
// Replace the vpd to provide a different min/max.
|
|
|
|
|
altVpd = new VisParamDescr(vpd.UiLabel, vpd.Name, vpd.CsType,
|
|
|
|
|
0, mProject.FileDataLength - 1, vpd.Special, vpd.DefaultValue);
|
2019-11-25 22:27:38 +00:00
|
|
|
|
} else {
|
|
|
|
|
rangeStr = "[" + vpd.Min + "," + vpd.Max + "]";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-27 02:54:42 +00:00
|
|
|
|
ParameterValue pv = new ParameterValue(altVpd, defaultVal, rangeStr);
|
2019-11-25 22:27:38 +00:00
|
|
|
|
|
2019-11-27 02:54:42 +00:00
|
|
|
|
ParameterList.Add(pv);
|
2019-11-25 22:27:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e) {
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-01 01:52:33 +00:00
|
|
|
|
private void Window_Closed(object sender, EventArgs e) {
|
|
|
|
|
mProject.UnprepareScripts();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-25 22:27:38 +00:00
|
|
|
|
private void OkButton_Click(object sender, RoutedEventArgs e) {
|
2019-11-28 01:12:26 +00:00
|
|
|
|
VisualizationItem item = (VisualizationItem)visComboBox.SelectedItem;
|
|
|
|
|
Debug.Assert(item != null);
|
|
|
|
|
Dictionary<string, object> valueDict = CreateVisGenParams();
|
|
|
|
|
NewVis = new Visualization(TagString, item.VisDescriptor.Ident, valueDict);
|
|
|
|
|
|
|
|
|
|
DialogResult = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Dictionary<string, object> CreateVisGenParams() {
|
2019-11-27 02:54:42 +00:00
|
|
|
|
// Generate value dictionary.
|
|
|
|
|
Dictionary<string, object> valueDict =
|
|
|
|
|
new Dictionary<string, object>(ParameterList.Count);
|
|
|
|
|
foreach (ParameterValue pv in ParameterList) {
|
|
|
|
|
if (pv.Descr.CsType == typeof(bool)) {
|
|
|
|
|
Debug.Assert(pv.Value is bool);
|
|
|
|
|
valueDict.Add(pv.Descr.Name, (bool)pv.Value);
|
|
|
|
|
} else if (pv.Descr.CsType == typeof(int)) {
|
|
|
|
|
int intVal;
|
|
|
|
|
if (pv.Value is int) {
|
|
|
|
|
intVal = (int)pv.Value;
|
|
|
|
|
} else {
|
|
|
|
|
bool ok = ParseInt((string)pv.Value, pv.Descr.Special, out intVal);
|
|
|
|
|
Debug.Assert(ok);
|
|
|
|
|
}
|
|
|
|
|
valueDict.Add(pv.Descr.Name, intVal);
|
|
|
|
|
} else if (pv.Descr.CsType == typeof(float)) {
|
|
|
|
|
float floatVal;
|
|
|
|
|
if (pv.Value is float || pv.Value is double) {
|
|
|
|
|
floatVal = (float)pv.Value;
|
|
|
|
|
} else {
|
|
|
|
|
bool ok = float.TryParse((string)pv.Value, out floatVal);
|
|
|
|
|
Debug.Assert(ok);
|
|
|
|
|
}
|
|
|
|
|
valueDict.Add(pv.Descr.Name, floatVal);
|
|
|
|
|
} else {
|
|
|
|
|
// skip it
|
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
}
|
2019-11-25 22:27:38 +00:00
|
|
|
|
}
|
2019-11-27 02:54:42 +00:00
|
|
|
|
|
2019-11-28 01:12:26 +00:00
|
|
|
|
return valueDict;
|
2019-11-27 02:54:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ParseInt(string str, VisParamDescr.SpecialMode special, out int intVal) {
|
|
|
|
|
int numBase = (special == VisParamDescr.SpecialMode.Offset) ? 16 : 10;
|
|
|
|
|
|
|
|
|
|
string trimStr = str.Trim();
|
|
|
|
|
if (trimStr.Length >= 1 && trimStr[0] == '+') {
|
|
|
|
|
// May be present for an offset. Just ignore it. Don't use it as a radix char.
|
|
|
|
|
trimStr = trimStr.Remove(0, 1);
|
|
|
|
|
} else if (trimStr.Length >= 1 && trimStr[0] == '$') {
|
|
|
|
|
numBase = 16;
|
|
|
|
|
trimStr = trimStr.Remove(0, 1);
|
|
|
|
|
} else if (trimStr.Length >= 2 && trimStr[0] == '0' &&
|
|
|
|
|
(trimStr[1] == 'x' || trimStr[1] == 'X')) {
|
|
|
|
|
numBase = 16;
|
|
|
|
|
trimStr = trimStr.Remove(0, 2);
|
|
|
|
|
}
|
|
|
|
|
if (trimStr.Length == 0) {
|
|
|
|
|
intVal = -1;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
intVal = Convert.ToInt32(trimStr, numBase);
|
|
|
|
|
return true;
|
|
|
|
|
} catch (Exception) {
|
|
|
|
|
intVal = -1;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-28 01:12:26 +00:00
|
|
|
|
private void UpdateControls() {
|
2019-11-27 02:54:42 +00:00
|
|
|
|
IsValid = true;
|
|
|
|
|
|
|
|
|
|
string trimTag = TagString.Trim();
|
|
|
|
|
if (trimTag.Length < MIN_TRIMMED_TAG_LEN) {
|
|
|
|
|
IsValid = false;
|
|
|
|
|
TagLabelBrush = mErrorLabelColor;
|
|
|
|
|
} else {
|
|
|
|
|
TagLabelBrush = mDefaultLabelColor;
|
|
|
|
|
}
|
|
|
|
|
// TODO: verify tag is unique
|
|
|
|
|
|
|
|
|
|
foreach (ParameterValue pv in ParameterList) {
|
|
|
|
|
pv.ForegroundBrush = mDefaultLabelColor;
|
|
|
|
|
if (pv.Descr.CsType == typeof(bool)) {
|
|
|
|
|
// always fine
|
|
|
|
|
continue;
|
|
|
|
|
} else if (pv.Descr.CsType == typeof(int)) {
|
|
|
|
|
// integer, possibly Offset special
|
|
|
|
|
bool ok = true;
|
|
|
|
|
int intVal;
|
|
|
|
|
if (pv.Value is int) {
|
|
|
|
|
// happens initially, before the TextBox can futz with it
|
|
|
|
|
intVal = (int)pv.Value;
|
|
|
|
|
} else if (!ParseInt((string)pv.Value, pv.Descr.Special, out intVal)) {
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
|
|
|
|
if (ok && (intVal < (int)pv.Descr.Min || intVal > (int)pv.Descr.Max)) {
|
|
|
|
|
// TODO(someday): make the range text red instead of the label
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
|
|
|
|
if (!ok) {
|
|
|
|
|
pv.ForegroundBrush = mErrorLabelColor;
|
|
|
|
|
IsValid = false;
|
|
|
|
|
}
|
|
|
|
|
} else if (pv.Descr.CsType == typeof(float)) {
|
|
|
|
|
// float
|
|
|
|
|
} else {
|
|
|
|
|
// unexpected
|
|
|
|
|
Debug.Assert(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-28 01:12:26 +00:00
|
|
|
|
|
|
|
|
|
if (!IsValid) {
|
2019-12-01 01:52:33 +00:00
|
|
|
|
// TODO(xyzzy): default to a meaningful image
|
2019-11-28 01:12:26 +00:00
|
|
|
|
previewImage.Source = new BitmapImage(new Uri("pack://application:,,,/Res/Logo.png"));
|
|
|
|
|
} else {
|
|
|
|
|
VisualizationItem item = (VisualizationItem)visComboBox.SelectedItem;
|
2019-12-01 01:52:33 +00:00
|
|
|
|
IVisualization2d vis2d;
|
|
|
|
|
try {
|
|
|
|
|
vis2d = item.Plugin.Generate2d(item.VisDescriptor,
|
|
|
|
|
CreateVisGenParams());
|
|
|
|
|
if (vis2d == null) {
|
|
|
|
|
Debug.WriteLine("Vis generator returned null");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
// TODO(xyzzy): use different image for failure
|
|
|
|
|
Debug.WriteLine("Vis generation failed: " + ex.Message);
|
|
|
|
|
vis2d = null;
|
|
|
|
|
}
|
|
|
|
|
if (vis2d == null) {
|
|
|
|
|
previewImage.Source = new BitmapImage(new Uri("pack://application:,,,/Res/Logo.png"));
|
|
|
|
|
} else {
|
|
|
|
|
previewImage.Source = Visualization.ConvertToBitmapSource(vis2d);
|
|
|
|
|
}
|
2019-11-28 01:12:26 +00:00
|
|
|
|
}
|
2019-11-27 02:54:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void VisComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
2019-11-28 01:12:26 +00:00
|
|
|
|
VisualizationItem item = (VisualizationItem)visComboBox.SelectedItem;
|
2019-11-27 02:54:42 +00:00
|
|
|
|
if (item == null) {
|
|
|
|
|
Debug.Assert(false); // not expected
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-11-28 01:12:26 +00:00
|
|
|
|
Debug.WriteLine("VisComboBox sel change: " + item.VisDescriptor.Ident);
|
|
|
|
|
GenerateParamControls(item.VisDescriptor);
|
|
|
|
|
UpdateControls();
|
2019-11-25 22:27:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TextBox_TextChanged(object sender, TextChangedEventArgs e) {
|
|
|
|
|
TextBox src = (TextBox)sender;
|
|
|
|
|
ParameterValue pv = (ParameterValue)src.DataContext;
|
2019-11-27 02:54:42 +00:00
|
|
|
|
//Debug.WriteLine("TEXT CHANGE " + pv + ": " + src.Text);
|
2019-11-28 01:12:26 +00:00
|
|
|
|
UpdateControls();
|
2019-11-27 02:54:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckBox_Changed(object sender, RoutedEventArgs e) {
|
|
|
|
|
CheckBox src = (CheckBox)sender;
|
|
|
|
|
ParameterValue pv = (ParameterValue)src.DataContext;
|
|
|
|
|
//Debug.WriteLine("CHECK CHANGE" + pv);
|
2019-11-28 01:12:26 +00:00
|
|
|
|
UpdateControls();
|
2019-11-25 22:27:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Describes a parameter and holds its value while being edited by WPF.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
2019-11-27 02:54:42 +00:00
|
|
|
|
/// We currently detect updates with change events. We could also tweak the Value setter
|
|
|
|
|
/// to fire an event back to the window class when things change. I don't know that there's
|
|
|
|
|
/// an advantage to doing so.
|
2019-11-25 22:27:38 +00:00
|
|
|
|
/// </remarks>
|
2019-11-27 02:54:42 +00:00
|
|
|
|
public class ParameterValue : INotifyPropertyChanged {
|
|
|
|
|
public VisParamDescr Descr { get; private set; }
|
|
|
|
|
public string UiString { get; private set; }
|
2019-11-25 22:27:38 +00:00
|
|
|
|
public string RangeText { get; private set; }
|
|
|
|
|
|
2019-11-27 02:54:42 +00:00
|
|
|
|
private object mValue;
|
|
|
|
|
public object Value {
|
|
|
|
|
get { return mValue; }
|
|
|
|
|
set { mValue = value; OnPropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Brush mForegroundBrush;
|
|
|
|
|
public Brush ForegroundBrush {
|
|
|
|
|
get { return mForegroundBrush; }
|
|
|
|
|
set { mForegroundBrush = value; OnPropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// INotifyPropertyChanged implementation
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
private void OnPropertyChanged([CallerMemberName] string propertyName = "") {
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ParameterValue(VisParamDescr vpd, object val, string rangeText) {
|
|
|
|
|
Descr = vpd;
|
2019-11-25 22:27:38 +00:00
|
|
|
|
Value = val;
|
|
|
|
|
RangeText = rangeText;
|
2019-11-27 02:54:42 +00:00
|
|
|
|
|
|
|
|
|
char labelSuffix = (vpd.CsType == typeof(bool)) ? '?' : ':';
|
|
|
|
|
UiString = vpd.UiLabel + labelSuffix;
|
2019-11-25 22:27:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString() {
|
2019-11-27 02:54:42 +00:00
|
|
|
|
return "[PV: " + Descr.Name + "=" + Value + "]";
|
2019-11-25 22:27:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ParameterTemplateSelector : DataTemplateSelector {
|
|
|
|
|
private DataTemplate mBoolTemplate;
|
|
|
|
|
public DataTemplate BoolTemplate {
|
|
|
|
|
get { return mBoolTemplate; }
|
|
|
|
|
set { mBoolTemplate = value; }
|
|
|
|
|
}
|
|
|
|
|
private DataTemplate mIntTemplate;
|
|
|
|
|
public DataTemplate IntTemplate {
|
|
|
|
|
get { return mIntTemplate; }
|
|
|
|
|
set { mIntTemplate = value; }
|
|
|
|
|
}
|
|
|
|
|
private DataTemplate mFloatTemplate;
|
|
|
|
|
public DataTemplate FloatTemplate {
|
|
|
|
|
get { return mFloatTemplate; }
|
|
|
|
|
set { mFloatTemplate = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override DataTemplate SelectTemplate(object item, DependencyObject container) {
|
|
|
|
|
if (item is ParameterValue) {
|
|
|
|
|
ParameterValue parm = (ParameterValue)item;
|
2019-11-27 02:54:42 +00:00
|
|
|
|
if (parm.Descr.CsType == typeof(bool)) {
|
2019-11-25 22:27:38 +00:00
|
|
|
|
return BoolTemplate;
|
2019-11-27 02:54:42 +00:00
|
|
|
|
} else if (parm.Descr.CsType == typeof(int)) {
|
2019-11-25 22:27:38 +00:00
|
|
|
|
return IntTemplate;
|
2019-11-27 02:54:42 +00:00
|
|
|
|
} else if (parm.Descr.CsType == typeof(float)) {
|
2019-11-25 22:27:38 +00:00
|
|
|
|
return FloatTemplate;
|
|
|
|
|
} else {
|
|
|
|
|
Debug.WriteLine("WHA?" + parm.Value.GetType());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return base.SelectTemplate(item, container);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|