File BaseClass.cs¶
File List > PGRControls > BaseClass.cs
Go to the documentation of this file
//=============================================================================
// Copyright (c) 2026 FLIR Integrated Imaging Solutions, Inc. All Rights Reserved.
//
// This software is the confidential and proprietary information of FLIR
// Integrated Imaging Solutions, Inc. ("Confidential Information"). You
// shall not disclose such Confidential Information and shall use it only in
// accordance with the terms of the license agreement you entered into
// with FLIR Integrated Imaging Solutions, Inc. (FLIR)
//
// FLIR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
// SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE, OR NON-INFRINGEMENT. FLIR SHALL NOT BE LIABLE FOR ANY DAMAGES
// SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
// THIS SOFTWARE OR ITS DERIVATIVES.
//=============================================================================
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Windows.Controls;
using System.Windows;
using System.ComponentModel;
using System.Windows.Data;
using System.Globalization;
using SpinnakerNET.GenApi;
using System.Collections.ObjectModel;
namespace SpinnakerNET.GUI
{
namespace WPFControls
{
public abstract class BaseClass : UserControl, ICameraControl, INotifyPropertyChanged, IDisposable
{
#region FIELDS
internal IMapper _mapper;
internal INodeMap _nodeMap;
internal Type _nodeType = typeof(Integer);
internal static IManagedSystem _system;
internal static List<IManagedInterface>_infList;
internal InterfaceEventListener _eventListener;
internal string _serialNumber;
internal string _formattedSerialNumber;
internal string _deviceModelName;
internal string _propertyToControl = string.Empty;
internal int _refreshTime = 0;
internal int _maxRefreshRateHz = 10;
internal IBool _boolNode;
internal bool _initializing = false;
internal bool _featureAvailable = false;
internal string _controlID = string.Empty;
internal System.Windows.Forms.Timer _timer;
internal bool _callbackRegistered = false;
internal bool _interfaceEventRegistered = false;
internal CameraControlCollection _dependencyControlList;
internal List<string>_dependencyStringList;
internal bool _isEditable;
internal string _tooltip;
internal bool _tooltipEnabled = true;
private int _decimalPlaces = 2;
protected const int MinDisplayPrecision = 0;
protected const int MaxDisplayPrecision = 15;
private bool _disposed = false;
internal string _controlNameLabel = "Label";
internal bool _nameLabelBoldness = false;
internal System.Windows.Visibility _nameLabelVisibility = System.Windows.Visibility.Visible;
internal bool _isUpdating = false;
internal PropertyGridInternal _propertyGridInternal;
#endregion
#region INOTIFYPROPERTYCHANGED_IMPLEMENTATION
public void NotifyPropertyChanged(String propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region PROPERTIES
protected string FormattedSerialNumber
{
get
{
if (!string.IsNullOrEmpty(_serialNumber))
{
_formattedSerialNumber = string.Format("[SN:{0}] ", _serialNumber);
}
else
{
_formattedSerialNumber = "";
}
return _formattedSerialNumber;
}
}
public int DecimalPlaces
{
get
{
return _decimalPlaces;
}
set
{
_decimalPlaces = Math.Min(MaxDisplayPrecision, Math.Max(MinDisplayPrecision, value));
}
}
public bool IsEditable
{
get
{
return _isEditable;
}
set
{
_isEditable = value;
NotifyPropertyChanged("IsNotEditable");
NotifyPropertyChanged("IsEditable");
}
}
public bool IsNotEditable
{
get
{
return !_isEditable && NodeIsMeantForControl();
}
set
{
_isEditable = !value;
NotifyPropertyChanged("IsEditable");
NotifyPropertyChanged("IsNotEditable");
}
}
public virtual INodeMap NodeMap
{
get
{
return _nodeMap;
}
}
public virtual Type GenICamNodeType
{
get
{
return _nodeType;
}
}
public virtual string PropertyToControl
{
get
{
return _propertyToControl;
}
}
public virtual Orientation ContentOrientation
{
get
{
return Orientation.Horizontal;
}
set
{
}
}
public virtual string ControlNameLabel
{
get
{
return _controlNameLabel;
}
set
{
_controlNameLabel = value;
NotifyPropertyChanged("ControlNameLabel");
}
}
public virtual string ControlToolTip
{
get
{
return _tooltip;
}
set
{
_tooltip = value;
if (String.IsNullOrEmpty(_tooltip))
{
ControlToolTipEnabled = false;
}
else
{
ControlToolTipEnabled = true;
}
NotifyPropertyChanged("ControlToolTip");
}
}
public virtual bool ControlToolTipEnabled
{
get
{
return _tooltipEnabled;
}
set
{
_tooltipEnabled = value;
NotifyPropertyChanged("ControlToolTipEnabled");
}
}
public virtual bool NameLabelBoldness
{
get
{
return _nameLabelBoldness;
}
set
{
if (_nameLabelBoldness != value)
{
this._nameLabelBoldness = value;
NotifyPropertyChanged("NameLabelBoldness");
}
}
}
public virtual System.Windows.Visibility NameLabelVisibility
{
get
{
return _nameLabelVisibility;
}
set
{
_nameLabelVisibility = value;
NotifyPropertyChanged("NameLabelVisibility");
}
}
public virtual System.Windows.Visibility ControlVisibility
{
get
{
return Visibility;
}
set
{
Visibility = value;
NotifyPropertyChanged("ControlVisibility");
}
}
public virtual Size MinControlSize
{
get
{
return new Size(MinWidth, MinHeight);
}
set
{
MinWidth = value.Width;
MinHeight = value.Height;
}
}
public virtual Size MaxControlSize
{
get
{
return new Size(MaxWidth, MaxHeight);
}
set
{
MaxWidth = value.Width;
MaxHeight = value.Height;
}
}
public virtual string ControlID
{
get
{
return _controlID;
}
set
{
_controlID = value;
}
}
public virtual List<string>DependencyStringList
{
get
{
if (_dependencyStringList == null)
{
_dependencyStringList = new List<string>();
if (_dependencyControlList == null)
{
return _dependencyStringList;
}
foreach(BaseClass baseClass in _dependencyControlList)
{
_dependencyStringList.Add(baseClass.GetControlID());
}
}
return _dependencyStringList;
}
}
public virtual int RefreshTime
{
get
{
return _refreshTime;
}
set
{
_refreshTime = value;
}
}
#endregion
#region ABSTRACT_METHODS
public BaseClass()
{
IsVisibleChanged += BaseIsVisibleChanged;
}
~BaseClass()
{
// Unregister interface event
UnregisterInterfaceEvents();
Dispose(false);
}
public abstract void Refresh();
public abstract void Connect(INodeMap nodemap, string nodename, string namelabel = "");
#endregion
#region IDisposble
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
Disconnect();
}
_disposed = true;
}
}
#endregion
#region METHODS
private void BaseIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (!IsVisible)
{
return;
}
// Control became visible in UI, refresh its' value
Refresh();
}
public static string RetrieveSerialNumber(INodeMap nodemap)
{
string deviceSerial = "";
try
{
var node = nodemap.GetNode<StringReg>("DeviceSerialNumber");
if (node != null && node.IsReadable)
{
deviceSerial = node.Value;
}
}
catch
{
}
return deviceSerial;
}
public static string RetrieveModelName(INodeMap nodemap)
{
string deviceModelName = "";
try
{
var node = nodemap.GetNode<StringReg>("DeviceModelName");
if (node != null && node.IsReadable)
{
deviceModelName = node.Value;
}
}
catch
{
}
return deviceModelName;
}
public static bool IsColorCamera(INodeMap nodeMap)
{
string nodeName = "PixelColorFilter";
if (nodeMap == null)
{
return false;
}
try
{
IEnum enumNode = nodeMap.GetNode<IEnum>(nodeName);
if (enumNode == null)
{
return false;
}
// Check if the node is available and readable
if (!enumNode.IsAvailable || !enumNode.IsReadable)
{
return false;
}
IEnumEntry noneEntry = enumNode.GetEntryByName("None");
// Ensure the "None" entry exists and is readable before using its value
if (noneEntry == null || !noneEntry.IsAvailable || !noneEntry.IsReadable)
{
return false;
}
if (enumNode.Value == noneEntry.Value)
{
return false;
}
else
{
return true;
}
}
catch (Exception ex)
{
Debug.WriteLine($"Error determining is color camera: {ex.Message} ");
return false;
}
}
protected virtual bool NodeIsMeantForControl()
{
try
{
return true;
}
catch (Exception /*ex*/)
{
// Assume node is controllable by default
return true;
}
}
public virtual void SetNameLabelVisibility(System.Windows.Visibility visibility)
{
NameLabelVisibility = visibility;
}
public virtual System.Windows.Visibility GetNameLabelVisibility()
{
return NameLabelVisibility;
}
public virtual void RegisterInterfaceEvents()
{
// Check whether interface event has already been registered.
if (_interfaceEventRegistered)
{
return;
}
// check to see if its an interface object
try
{
if (_nodeMap != null)
{
IString interfaceID = _nodeMap.GetNode<IString>("InterfaceID");
if (interfaceID != null)
{
// InterfaceID is only available on an interface
// and there are no removal events for interfaces
return;
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
// Keep a record of camera serial number
try
{
if (string.IsNullOrEmpty(_serialNumber))
{
_serialNumber = RetrieveSerialNumber(_nodeMap);
}
}
catch (Exception ex)
{
// Without serial number, removal events won't work
Debug.WriteLine(ex.Message);
return;
}
try
{
// Start event registration process
_eventListener = new InterfaceEventListener();
_eventListener.DeviceRemovalHandler += OnDeviceRemoval;
if (_system == null)
{
_system = new ManagedSystem();
}
if (_infList == null)
{
_infList = _system.GetInterfaces();
}
try
{
foreach(var inf in _infList)
{
inf.RegisterEventHandler(_eventListener);
}
_interfaceEventRegistered = true;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
catch (Exception ex)
{
Debug.Print("Problem registering interface event for {0}: {1}", PropertyToControl, ex.Message);
}
}
public virtual void UnregisterInterfaceEvents()
{
// Check whether interface event
// is registered
if (!_interfaceEventRegistered)
{
return;
}
try
{
if (_callbackRegistered && _eventListener != null && _system != null)
{
foreach(var inf in _system.GetInterfaces())
{
inf.UnregisterEventHandler(_eventListener);
}
if (_eventListener != null)
{
_eventListener.DeviceRemovalHandler -= OnDeviceRemoval;
_eventListener = null;
}
_interfaceEventRegistered = false;
}
if (_system != null)
{
_system = null;
}
}
catch (Exception ex)
{
Debug.Print("Problem unregistering interface event for {0}: {1}", PropertyToControl, ex.Message);
}
}
protected virtual void OnDeviceRemoval(IManagedCamera camera)
{
string serial = camera.GetDeviceSerialNumber();
try
{
if (serial == _serialNumber)
{
// Device has been removed
Dispatcher.BeginInvoke((ThreadStart) delegate() { IsEnabled = false; });
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
public virtual void SetToolTip(string tooltip)
{
ControlToolTip = tooltip;
}
public virtual void SetControlNameLabel(string nameLabel)
{
ControlNameLabel = nameLabel;
}
public virtual void SetNameLabelBoldness(bool status)
{
NameLabelBoldness = status;
}
internal virtual void SetMapper(IMapper mapper)
{
_mapper = mapper;
}
internal virtual IMapper GetMapper()
{
return _mapper;
}
public virtual string GetNodeToControl()
{
return _propertyToControl;
}
public virtual bool GetNameLabelBoldness()
{
return NameLabelBoldness;
}
public virtual void SetMargin(Thickness margin)
{
Margin = margin;
}
public virtual Thickness GetMargin()
{
return Margin;
}
public virtual void SetVisibility(System.Windows.Visibility visibility)
{
ControlVisibility = visibility;
}
public virtual void SetMinimumControlSize(Size newSize)
{
MinHeight = newSize.Height;
MinWidth = newSize.Width;
}
public virtual void SetMaximumControlSize(Size newSize)
{
MaxHeight = newSize.Height;
MaxWidth = newSize.Width;
}
public virtual void SetControlSize(Size newSize)
{
Width = newSize.Width;
Height = newSize.Height;
}
public virtual void SetControlWidth(double width)
{
Width = width;
}
public virtual void SetControlHeight(double height)
{
Height = height;
}
public virtual void SetControlID(string id)
{
_controlID = id;
}
public virtual void SetMin(double min)
{
}
public virtual void SetMax(double max)
{
}
public virtual void SetRefreshTime(int seconds)
{
_refreshTime = seconds;
}
public virtual void AssignDependencyControls(CameraControlCollection controlList)
{
if (_dependencyStringList == null || _dependencyStringList.Count == 0)
{
return;
}
try
{
_dependencyControlList = controlList;
}
catch (System.Exception /*ex*/)
{
}
}
public virtual double GetMin()
{
return 0;
}
public virtual double GetMax()
{
return 0;
}
public virtual string GetToolTip()
{
return _tooltip;
}
public virtual string GetControlNameLabel()
{
return _controlNameLabel;
}
public virtual System.Windows.Visibility GetVisibility()
{
return ControlVisibility;
}
public virtual Size GetMinimumControlSize()
{
return new Size(MinWidth, MinHeight);
}
public virtual Size GetMaximumControlSize()
{
return new Size(MaxWidth, MaxHeight);
}
public virtual Size GetControlSize()
{
return new Size(Width, Height);
}
public virtual double GetControlWidth()
{
return Width;
}
public virtual double GetControlHeight()
{
return Height;
}
public virtual string GetControlID()
{
return _controlID;
}
public virtual int GetRefreshTime()
{
return _refreshTime;
}
internal virtual CameraControlCollection GetDependencyControls()
{
return _dependencyControlList;
}
public virtual bool GetFeatureAvailability()
{
return _featureAvailable;
}
public virtual void Disconnect()
{
_nodeMap = null;
if (_mapper != null)
{
_mapper.Disconnect();
_mapper = null;
}
if (_infList != null)
{
foreach(var inf in _infList)
{
inf.Dispose();
}
_infList = null;
}
_system = null;
}
protected int ClampDisplayPrecision(long displayPrecision)
{
if (displayPrecision < MinDisplayPrecision)
{
return MinDisplayPrecision;
}
if (displayPrecision > MaxDisplayPrecision)
{
return MaxDisplayPrecision;
}
return (int)displayPrecision;
}
protected bool TryGetFloatIncrement(IFloat node, out double increment)
{
increment = 0;
if (node == null)
{
return false;
}
try
{
increment = node.Increment;
return increment > 0 && !double.IsNaN(increment) && !double.IsInfinity(increment);
}
catch
{
return false;
}
}
protected double NormalizeValueToIncrement(double value, double min, double max, double increment)
{
double steps = Math.Round((value - min) / increment, MidpointRounding.AwayFromZero);
double adjustedValue = min + (steps * increment);
if (adjustedValue < min)
{
adjustedValue = min;
}
else if (adjustedValue > max)
{
adjustedValue = max;
}
return adjustedValue;
}
protected double NormalizeFloatValueToNodeIncrement(IFloat node, double value)
{
if (node == null)
{
return value;
}
try
{
double min = node.Min;
double max = node.Max;
double increment;
if (TryGetFloatIncrement(node, out increment))
{
return NormalizeValueToIncrement(value, min, max, increment);
}
return Math.Min(max, Math.Max(min, value));
}
catch
{
return value;
}
}
public virtual void SetDecimalPlaces(int decimalPlaces)
{
this.DecimalPlaces = decimalPlaces;
}
public virtual int GetDecimalPlaces()
{
return this.DecimalPlaces;
}
internal void SetPropertyGridInternal(PropertyGridInternal propertyGrid)
{
_propertyGridInternal = propertyGrid;
}
public void LockIconButton_Click(object sender, RoutedEventArgs e)
{
if (_propertyGridInternal != null)
{
_propertyGridInternal.DisplayNodeLockInfo();
}
}
#endregion
#region ToString
public override string ToString()
{
string result = string.Empty;
if (_propertyToControl != string.Empty && _nodeMap != null)
{
if (_mapper != null)
{
result = _propertyToControl + "\t" + _mapper.FormatNodeValueToString(_propertyToControl);
}
else
{
result = _propertyToControl + "\t" + FetchNodeValue(_propertyToControl, _nodeMap);
}
}
else
{
if (_propertyToControl != null)
{
result = _propertyToControl;
}
}
return result;
}
protected void LogNodeCallback(log4net.ILog logger, string nodename, string logMessage)
{
try
{
if ((nodename.ToLower().Contains("chunk") || nodename.ToLower().Contains("event")))
{
logger.Info(logMessage);
}
else
{
logger.Debug(logMessage);
}
}
catch (Exception)
{
logger.Debug("Unexpected log message format");
}
}
protected void LogNodeUpdateAction(log4net.ILog logger, INode node, string newValue)
{
logger.Logger.Log(
null,
log4net.Core.Level.Notice,
string.Format("{0}Updating {1}. Value = {2}", FormattedSerialNumber, node.Name, newValue),
null);
}
protected void AnalyticsEventLog(
log4net.ILog analytics,
string source,
string action,
string value,
string cameraModelName = "")
{
var obj = new {name = "SpinnakerNETGUI",
source = source,
action = action,
value = value,
cameraModel = cameraModelName};
analytics.Logger.Log(null, log4net.Core.Level.Notice, obj, null);
}
protected void AnalyticsNodeUpdateAction(log4net.ILog analytics, INode node, string newValue)
{
var obj = new {name = "SpinnakerNETGUI",
source = "FeatureTree",
action = "Update Node",
value = string.Format("{0}={1}", node.Name, newValue),
cameraModel = _deviceModelName};
analytics.Logger.Log(null, log4net.Core.Level.Notice, obj, null);
}
protected string FetchNodeValue(string nodeName, INodeMap map)
{
if (string.IsNullOrEmpty(nodeName) || map == null)
{
return string.Empty;
}
try
{
IValue value = map.GetNode<IValue>(nodeName);
if (value.GetType() == typeof (StringReg))
{
IString stringNode = value.NodeMap.GetNode<IString>(value.Name);
return stringNode.Value;
}
else if (value.GetType() == typeof (Category))
{
ICategory categoryNode = value.NodeMap.GetNode<ICategory>(value.Name);
return categoryNode.Name;
}
else if (value.GetType() == typeof (Enumeration))
{
IEnum enumNode = value.NodeMap.GetNode<IEnum>(value.Name);
return enumNode.Value;
}
else if (value.GetType() == typeof (Float))
{
IFloat floatNode = value.NodeMap.GetNode<IFloat>(value.Name);
return floatNode.Value.ToString();
}
else if (value.GetType() == typeof (Integer))
{
IInteger intNode = value.NodeMap.GetNode<IInteger>(value.Name);
return intNode.Value.ToString();
}
else if (value.GetType() == typeof (BoolNode))
{
IBool boolNode = value.NodeMap.GetNode<IBool>(value.Name);
return boolNode.Value.ToString();
}
else if (value.GetType() == typeof (Command))
{
ICommand commandNode = value.NodeMap.GetNode<ICommand>(value.Name);
return commandNode.ToolTip;
}
else
{
return string.Empty;
}
}
catch (Exception ex)
{
Debug.WriteLine(string.Format("Problem connecting to {0}. {1}", nodeName, ex.Message));
return string.Empty;
}
}
#endregion
#region Decimal Places Formatter
private static string BuildNumericFormat(int decimalPlaces)
{
string formatter = "0";
if (decimalPlaces > 0)
{
formatter += ".";
for (int i = 0; i < decimalPlaces; i++)
{
formatter += "#";
}
}
return formatter;
}
protected static string FormatNumericToString(float input, int decimalPlaces)
{
return input.ToString(BuildNumericFormat(decimalPlaces));
}
protected static string FormatNumericToString(int input, int decimalPlaces)
{
return input.ToString(BuildNumericFormat(decimalPlaces));
}
protected static string FormatNumericToString(long input, int decimalPlaces)
{
return input.ToString(BuildNumericFormat(decimalPlaces));
}
protected static string FormatNumericToString(uint input, int decimalPlaces)
{
return input.ToString(BuildNumericFormat(decimalPlaces));
}
#endregion
}
[ValueConversion(typeof(bool), typeof(FontWeights))]
internal class LabelBoldnessConverter : DependencyObject,
IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
bool bold = (bool) value;
if (bold)
{
return FontWeights.Bold;
}
else
{
return FontWeights.Normal;
}
}
catch (System.Exception /*ex*/)
{
return FontWeights.Normal;
}
}
public object ConvertBack(object value, Type targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
internal class NodeStatus
{
public INode CurrentNode;
public Type NodeType;
public string NodeName;
public string NodeDisplayName;
public bool IsReadable;
public bool IsWritable;
public bool IsAvailable;
public bool IsImplemented;
public string Tooltip;
public string Description;
public double Min;
public double Max;
public double CurrentValue;
public string CurrentStringValue;
public bool CurrentBooleanValue;
public EnumValue CurrentEnumValue;
public string Unit;
public ObservableCollection<ComboBoxControl.Entry>Entries;
public Exception ExceptionObject;
public IMapper Mapper;
public int DecimalPlaces;
public NodeStatus(INode node, IMapper mapper = null, int decimalPlaces = 2)
{
CurrentNode = node;
this.Mapper = mapper;
this.DecimalPlaces = decimalPlaces;
try
{
NodeType = node.GetType();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
ExceptionObject = ex;
}
try
{
NodeName = node.Name;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
ExceptionObject = ex;
}
try
{
NodeDisplayName = node.DisplayName;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
ExceptionObject = ex;
}
try
{
IsReadable = node.IsReadable;
}
catch (Exception ex)
{
IsReadable = false;
Debug.WriteLine(ex.Message);
ExceptionObject = ex;
}
try
{
IsWritable = node.IsWritable;
}
catch (Exception ex)
{
IsWritable = false;
Debug.WriteLine(ex.Message);
ExceptionObject = ex;
}
try
{
IsImplemented = node.IsImplemented;
}
catch (Exception ex)
{
IsImplemented = false;
Debug.WriteLine(ex.Message);
ExceptionObject = ex;
}
try
{
IsAvailable = node.IsAvailable;
}
catch (Exception ex)
{
IsAvailable = false;
Debug.WriteLine(ex.Message);
ExceptionObject = ex;
}
try
{
Tooltip = node.ToolTip;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
ExceptionObject = ex;
}
try
{
Description = node.Description;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
ExceptionObject = ex;
}
// Set defaults
Min = 0;
Max = 0;
CurrentValue = 0;
CurrentStringValue = "";
CurrentBooleanValue = false;
Unit = "";
CurrentEnumValue = null;
Entries = new ObservableCollection<ComboBoxControl.Entry>();
if (!IsReadable)
{
return;
}
if (NodeType == typeof (Float) || NodeType == typeof (FloatReg))
{
IFloat floatNode = node as IFloat;
Unit = floatNode.Unit;
if (IsReadable)
{
try
{
CurrentValue = floatNode.Value;
string temp = "";
if (this.Mapper != null)
{
temp = this.Mapper.FormatNodeValueToString(NodeName, "", DecimalPlaces);
}
else
{
temp = NumericFormatter.FormatNumericToString(CurrentValue, DecimalPlaces);
}
CurrentStringValue = temp;
Min = floatNode.Min;
Max = floatNode.Max;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
ExceptionObject = ex;
return;
}
}
}
else if (NodeType == typeof (Integer) || NodeType == typeof (IntReg))
{
IInteger integerNode = node as IInteger;
if (IsReadable)
{
try
{
CurrentValue = integerNode.Value;
if (this.Mapper != null)
{
CurrentStringValue = this.Mapper.FormatNodeValueToString(NodeName);
}
else
{
CurrentStringValue = CurrentValue.ToString();
}
Min = integerNode.Min;
Max = integerNode.Max;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
ExceptionObject = ex;
return;
}
}
}
else if (NodeType == typeof (Enumeration))
{
IEnum enumNode = node as IEnum;
if (IsReadable)
{
try
{
CurrentEnumValue = enumNode.Value;
CurrentStringValue = CurrentEnumValue.ToString();
for (int i = 0; i < enumNode.Entries.Length; i++)
{
// Keep track of all possible entries and their Node value
if (enumNode.Entries[i].IsImplemented && enumNode.Entries[i].IsAvailable)
{
ComboBoxControl.Entry newEntry = new ComboBoxControl.Entry(
enumNode.Entries[i].DisplayName, enumNode.Entries[i].Value);
if (newEntry != null)
{
Entries.Add(newEntry);
}
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
ExceptionObject = ex;
return;
}
}
}
else if (NodeType == typeof (StringNode) || NodeType == typeof (StringReg))
{
IString stringNode = node as IString;
if (IsReadable)
{
try
{
if (this.Mapper != null)
{
CurrentStringValue = this.Mapper.FormatNodeValueToString(NodeName);
}
else
{
CurrentStringValue = stringNode.Value;
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
ExceptionObject = ex;
return;
}
}
}
else if (NodeType == typeof (BoolNode))
{
IBool boolNode = node as IBool;
if (IsReadable)
{
try
{
CurrentBooleanValue = boolNode.Value;
if (this.Mapper != null)
{
CurrentStringValue = this.Mapper.FormatNodeValueToString(NodeName);
}
else
{
CurrentStringValue = CurrentBooleanValue.ToString();
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
ExceptionObject = ex;
return;
}
}
}
}
}
}
}