Numeric Comparision Expression


Node Information
Compares two given numeric values, if the condition is met TRUE will be returned, else FALSE will be returned.
General Information
• This node doesn't have other available options.
• Some of the ports of this node can change their types and accept types automatically.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
A IN Int32 ONE FALSE TRUE
B IN Int32 ONE FALSE TRUE
Result OUT Boolean MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.Conditions
{
    [IsNode("Numeric Comparision Expression")]
    public class NumericComparisionExpression : Node
    {
        Port a = new Port(PortType.IN, typeof(int), AcceptsLinks.ONE, "A");
        Port b = new Port(PortType.IN, typeof(int), AcceptsLinks.ONE, "B");
        Port res = new Port(PortType.OUT, typeof(bool), AcceptsLinks.MULTIPLE, "Result");
        public NumberComparisonType Comparision
        {
            set
            {
                Settings[1] = value.ToString();
            }
            get
            {
                if (Settings[1] == string.Empty) { return NumberComparisonType.Equal; }
                else
                {
                    return (NumberComparisonType)Enum.Parse(typeof(NumberComparisonType), Settings[1]);
                }
            }
        }
        public double A
        {
            set { a.Value = value.ToString(); }
            get { return GetRuntimeValue(a); }
        }
        public double B
        {
            set { b.Value = value.ToString(); }
            get { return GetRuntimeValue(b); }
        }
        public NumericComparisionExpression()
        {
            NodeType = KGraph.NodeType.Function;
            ReturnType = typeof(bool);
            a.Value = "0";
            b.Value = "0";
            this.Name = "Numeric Comparision Expression";
            this.AddPort(a);
            this.AddPort(b);
            this.AddPort(res);
            a.CustomAcception = Accepts;
            b.CustomAcception = Accepts;
            Information = "Compares two given numeric values, if the condition is met TRUE will be returned, else FALSE will be returned.";
        }
        private bool Accepts(Port port)
        {
            if (port == null)
            {
                return false;
            }
            if (a.IsConnected || b.IsConnected || res.IsConnected)
            {
                if (port.DataType == a.DataType)
                {
                    return true;
                }
            }
            else if (GraphCore.IsNumeric(port.DataType))
            {
                ReturnType = port.DataType;
                a.DataType = port.DataType;
                a.Refresh();
                b.DataType = port.DataType;
                b.Refresh();
                res.DataType = port.DataType;
                res.Refresh();
                return true;
            }
            return false;
        }
        public override string Code()
        {
            string val1 = string.Empty;
            string val2 = string.Empty;
            string oprtor = string.Empty;
            switch (Comparision)
            {
                case NumberComparisonType.Equal:
                    oprtor = "==";
                    break;
                case NumberComparisonType.NotEqual:
                    oprtor = "!=";
                    break;
                case NumberComparisonType.Bigger:
                    oprtor = ">";
                    break;
                case NumberComparisonType.Smaller:
                    oprtor = "<"; break;="" case="" numbercomparisontype.equalorbigger:="" oprtor=">=" ;="" break;="" case="" numbercomparisontype.equalorsmaller:="" oprtor="<=" ;="" break;="" default:="" break;="" }="" if="" (a.isconnected)="" {="" val1="GetValue(a);" }="" else="" {="" val1="A.ToString();" }="" if="" (b.isconnected)="" {="" val2="GetValue(b);" }="" else="" {="" val2="B.ToString();" }="" string="" code=" bool ret = false; if (" +="" val1="" +="" oprtor="" +="" val2="" +="" ")="" {ret="true;}else{ret" =="" false;}="" return="" ret;";="" return="" code;="" }="" }="" }=""></";>