Example #1
0
        public override void ExportCodeStatements(IMethodCompile method)
        {
            RaisDataType targetType = this[0].DataType;
            RaisDataType sourceType = this[1].DataType;
            Type         target     = targetType.Type;
            Type         source     = sourceType.Type;

            if (target.Equals(source))
            {
                MathNode.Trace("MathNodeAssign, code 1: same type:{0}", target);
                method.MethodCode.Statements.Add(new CodeAssignStatement(this[0].ExportCode(method), this[1].ExportCode(method)));
            }
            else
            {
                MathNode.Trace("MathNodeAssign");
                CodeExpression code = RaisDataType.GetConversionCode(sourceType, this[1].ExportCode(method), targetType, method.MethodCode.Statements);
                if (code != null)
                {
                    method.MethodCode.Statements.Add(new CodeAssignStatement(this[0].ExportCode(method), code));
                }
                else
                {
                    if (!target.Equals(typeof(void)))
                    {
                    }
                }
            }
        }
        public ReturnIcon(RaisDataType dataType)
        {
            Location = new Point(300, 300);
            SaveLocation();
            this.Size = new Size(32, 32);
            System.Drawing.ToolboxBitmapAttribute tba = TypeDescriptor.GetAttributes(this.GetType())[typeof(System.Drawing.ToolboxBitmapAttribute)] as System.Drawing.ToolboxBitmapAttribute;
            if (tba != null)
            {
                bmp = (System.Drawing.Bitmap)tba.GetImage(this.GetType());
            }
            MathNodeRoot root = new MathNodeRoot();

            root.IsVariableHolder = true;
            var     = new MathNodeVariableDummy(root);
            root[0] = var;
            if (dataType != null)
            {
                var.VariableType = dataType;
                var.TypeDefined  = true;
            }
            LinkLineNodeInPort port = new LinkLineNodeInPort(var);

            port.ClearLine();
            port.SetPrevious(null);
            port.Owner = this;
            port.HideLabel();
            var.InPort         = port;
            port.Owner         = this;
            port.Label.Visible = false;
            port.Location      = new Point(this.Left + this.Width / 2 - port.Width / 2, this.Top - port.Height);
            port.SaveLocation();
        }
Example #3
0
        public IDataSelectionControl GetUIEditorDropdown(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc != null)
            {
                PrimaryTypeList c = new PrimaryTypeList();
                Type            t = value as Type;
                if (t == null)
                {
                    RaisDataType rt = value as RaisDataType;
                    if (rt != null)
                    {
                        t = rt.LibType;
                    }
                }
                if (t != null)
                {
                    c.SelectType(t);
                }
                MathNodeValue mv = context.Instance as MathNodeValue;
                if (mv != null)
                {
                    RaisDataType rt = mv.GetRelatedType();
                    c.InsertType(rt.LibType, rt.LibType.Name);
                }
                c.SetCaller(edSvc);
                return(c);
            }
            return(null);
        }
Example #4
0
        protected override MathNode OnCreateClone(MathNode parent)
        {
            ParameterDef[] ps = null;
            if (_methodRef.Parameters != null)
            {
                ps = new ParameterDef[_methodRef.Parameters.Length];
                for (int i = 0; i < _methodRef.Parameters.Length; i++)
                {
                    ps[i] = (ParameterDef)_methodRef.Parameters[i].Clone();
                }
            }
            ObjectRef ow = null;

            if (_methodRef.MethodOwner != null)
            {
                ow = (ObjectRef)_methodRef.MethodOwner.Clone();
            }
            RaisDataType ret;

            if (_methodRef.ReturnType != null)
            {
                ret = (RaisDataType)_methodRef.ReturnType.Clone();
            }
            else
            {
                ret = new RaisDataType(typeof(void));
            }
            return(new MathNodeMethodInvoke(parent, ow, _methodRef.MethodName, _methodRef.MethodID, ret, ps));
        }
Example #5
0
        protected override void OnLoad(XmlNode node)
        {
            object v = XmlSerialization.ReadFromChildXmlNode(GetReader(), node, "ValueType");

            if (v != null)
            {
                _dataType = (RaisDataType)v;
            }
        }
Example #6
0
        public ReturnIcon CreateReturnIcon(RaisDataType t)
        {
            root.ResultValueType = t;
            ReturnIcon ri = new ReturnIcon(t);

            root.Controls.Add(ri);
            root.Controls.Add(ri.InPort);
            return(ri);
        }
Example #7
0
        public override CodeExpression ExportCode(IMethodCompile method)        //)
        {
            CodeStatementCollection supprtStatements = method.MethodCode.Statements;

            if (this.UseDefaultValue)
            {
                if (_default == null)
                {
                    MathNode.Trace("MathNodeParameter.ExportCode: Use default case 0:null");
                    return(ValueTypeUtil.GetDefaultCodeByType(this.DataType.Type));
                }
                else
                {
                    MathNode.Trace("MathNodeParameter.ExportCode: Use default case 1:{0}", _default);
                    return(ObjectCreationCodeGen.ObjectCreationCode(_default));
                }
            }
            else
            {
                if (this.InPort != null && this.InPort.LinkedPortID != 0)
                {
                    MathNode.Trace("MathNodeParameter.ExportCode: call linked item");
                    IMathExpression rootContainer = this.root.RootContainer;
                    if (rootContainer == null)
                    {
                        throw new MathException(XmlSerialization.FormatString("Parameter {0} not associated with a root container", this.TraceInfo));
                    }
                    MathExpItem LinkedItem = rootContainer.GetItemByID(this.InPort.LinkedPortID);
                    if (LinkedItem == null)
                    {
                        throw new MathException(string.Format("Linked Port ID {0} from ({1}) does not match an item", InPort.LinkedPortID, this.TraceInfo));
                    }
                    CodeExpression ce = LinkedItem.ReturnCodeExpression(method);
                    return(RaisDataType.GetConversionCode(LinkedItem.MathExpression.DataType, ce, this.DataType, supprtStatements));
                }
                //
                MathNode.Trace("MathNodeParameter.ExportCode: call MathNodeVariable.ExportCode");
                return(base.ExportCode(method));
            }
        }
Example #8
0
        protected override void OnLoad(XmlNode node)
        {
            _name = XmlUtil.GetNameAttribute(node);
            XmlNode nd = node.SelectSingleNode(XmlTags.XML_ObjProperty);

            if (nd != null)
            {
                XmlSerializer.XmlObjectReader xr = this.root.Reader as XmlSerializer.XmlObjectReader;
                if (xr != null)
                {
                    _typePointer = (DataTypePointer)xr.ReadObject(nd, this);
                    if (_typePointer != null)
                    {
                        _dataType = new RaisDataType(_typePointer.ObjectType);
                    }
                }
                else
                {
                    throw new DesignerException("Reader not available calling MathNodeField.OnLoad");
                }
            }
        }
        protected override void OnLoad(XmlNode node)
        {
            object v;
            string s;

            _value = XmlSerialization.GetAttribute(node, XmlSerialization.XMLATT_NAME);
            if (string.IsNullOrEmpty(_value))
            {
                _value = "_";
            }
            _subscript = XmlSerialization.GetAttribute(node, "subscript");
            _isInPort  = XmlSerialization.GetAttributeBool(node, "asInport");
            s          = XmlSerialization.GetAttribute(node, "typeDefined");
            if (!string.IsNullOrEmpty(s))
            {
                if (string.Compare(s, "true", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    _typeDefined = true;
                }
            }
            s = XmlSerialization.GetAttribute(node, XmlSerialization.XMLATT_ID);
            if (!string.IsNullOrEmpty(s))
            {
                _id = Convert.ToUInt32(s);
            }
            v = XmlSerialization.ReadFromChildXmlNode(GetReader(), node, "ValueType");
            if (v != null)
            {
                _dataType = (RaisDataType)v;
            }
            else
            {
                _dataType         = new RaisDataType();
                _dataType.LibType = typeof(double);
            }
            LoadPorts(node);
        }
Example #10
0
 public override void OnReplaceNode(MathNode replaced)
 {
     if (replaced != null)
     {
         _dataType = replaced.DataType;
         int n = this.ChildNodeCount;
         for (int i = 0; i < n; i++)
         {
             MathNodeCondition mc = this[i] as MathNodeCondition;
             if (mc != null)
             {
                 mc[1] = replaced.CloneExp(mc) as MathNode;
             }
             else
             {
                 MathNodeValue v = this[i] as MathNodeValue;
                 if (v != null)
                 {
                     v.ValueType = replaced.DataType.Clone() as RaisDataType;
                 }
             }
         }
     }
 }
 public void SetVariableType(RaisDataType t)
 {
     _dataType = t;
 }
        public override System.CodeDom.CodeExpression ExportCode(IMethodCompile method)
        {
            MathNode.Trace("{0}.ExportCode for value [{1}] as type [{2}]", this.GetType().Name, _value, this.CompileDataType.Type);
            if (CompileDataType.IsInteger)
            {
                double d = Math.Floor(_value);
                if (d == _value)
                {
                    switch (Type.GetTypeCode(CompileDataType.Type))
                    {
                    case TypeCode.Byte:
                        if (_value >= byte.MinValue && _value <= byte.MaxValue)
                        {
                            byte by = (byte)_value;
                            ActualCompiledType = new RaisDataType(typeof(byte));
                            return(new CodePrimitiveExpression(by));
                        }
                        break;

                    case TypeCode.Int16:
                        if (_value >= Int16.MinValue && _value <= Int16.MaxValue)
                        {
                            Int16 by = (Int16)_value;
                            ActualCompiledType = new RaisDataType(typeof(Int16));
                            return(new CodePrimitiveExpression(by));
                        }
                        break;

                    case TypeCode.Int32:
                        if (_value >= Int32.MinValue && _value <= Int32.MaxValue)
                        {
                            Int32 by = (Int32)_value;
                            ActualCompiledType = new RaisDataType(typeof(Int32));
                            return(new CodePrimitiveExpression(by));
                        }
                        break;

                    case TypeCode.Int64:
                        if (_value >= Int64.MinValue && _value <= Int64.MaxValue)
                        {
                            Int64 by = (Int64)_value;
                            ActualCompiledType = new RaisDataType(typeof(Int64));
                            return(new CodePrimitiveExpression(by));
                        }
                        break;

                    case TypeCode.SByte:
                        if (_value >= sbyte.MinValue && _value <= sbyte.MaxValue)
                        {
                            sbyte by = (sbyte)_value;
                            ActualCompiledType = new RaisDataType(typeof(sbyte));
                            return(new CodePrimitiveExpression(by));
                        }
                        break;

                    case TypeCode.UInt16:
                        if (_value >= UInt16.MinValue && _value <= UInt16.MaxValue)
                        {
                            UInt16 by = (UInt16)_value;
                            ActualCompiledType = new RaisDataType(typeof(UInt16));
                            return(new CodePrimitiveExpression(by));
                        }
                        break;

                    case TypeCode.UInt32:
                        if (_value >= UInt32.MinValue && _value <= UInt32.MaxValue)
                        {
                            UInt32 by = (UInt32)_value;
                            ActualCompiledType = new RaisDataType(typeof(UInt32));
                            return(new CodePrimitiveExpression(by));
                        }
                        break;

                    case TypeCode.UInt64:
                        if (_value >= UInt64.MinValue && _value <= UInt64.MaxValue)
                        {
                            UInt64 by = (UInt64)_value;
                            ActualCompiledType = new RaisDataType(typeof(UInt64));
                            return(new CodePrimitiveExpression(by));
                        }
                        break;
                    }
                }
            }
            ActualCompiledType = CompileDataType;
            return(new CodeCastExpression(CompileDataType.Type, new CodePrimitiveExpression(_value)));
        }
 public LogicVariable(MathNode parent)
     : base(parent)
 {
     VariableType         = new RaisDataType();
     VariableType.LibType = typeof(bool);
 }
Example #14
0
 public override CodeExpression ExportCode(IMethodCompile method)
 {
     if (_methodRef.MethodOwner == null)
     {
         throw new Exception("methodOwner is not assigned to MethodNode.");
     }
     MathNode.Trace("{0}:ExportCode for {1}", this.GetType().Name, this.TraceInfo);
     if (_methodRef.Parameters != null)
     {
         int n = ChildNodeCount;
         if (_methodRef.ParameterCount != n)
         {
             throw new MathException("method parameters are not initialized for {0}.", this.GetType().Name);
         }
         MathNode.Trace("{0} parameter(s)", n);
         MathNode.IndentIncrement();
         parameterCode = new CodeExpression[n];
         for (int i = 0; i < n; i++)
         {
             MathNode.Trace("parameter {0}: {1}", i, this[i].TraceInfo);
             CodeExpression ce = this[i].ExportCode(method);
             if (!_methodRef.Parameters[i].DataType.IsSameType(this[i].DataType))
             {
                 ce = RaisDataType.GetConversionCode(this[i].DataType, ce, _methodRef.Parameters[i].DataType, method.MethodCode.Statements);
             }
             parameterCode[i] = ce;
             if (_methodRef.Parameters[i].Direction != FieldDirection.In)
             {
                 parameterCode[i] = new CodeDirectionExpression(_methodRef.Parameters[i].Direction, parameterCode[i]);
             }
         }
         MathNode.IndentDecrement();
     }
     else
     {
         parameterCode = new CodeExpression[] { };
     }
     if (_methodRef.MethodOwner.Type == ObjectRefType.Type)            //a static function
     {
         MathNode.Trace("Invoke static function {0}.{1}", _methodRef.MethodOwner.Value.LibType, _methodRef.MethodName);
         CodeMethodInvokeExpression e = new CodeMethodInvokeExpression(
             new CodeTypeReferenceExpression(_methodRef.MethodOwner.Value.LibType),
             _methodRef.MethodName, parameterCode);
         return(e);
     }
     else
     {
         if (_methodRef.MethodName == XmlSerialization.CONSTRUCTOR_METHOD)
         {
             MathNode.Trace("Invoke constructor for {0}", _methodRef.MethodOwner.TypeString);
             CodeObjectCreateExpression oc = new CodeObjectCreateExpression(_methodRef.MethodOwner.TypeString, parameterCode);
             return(oc);
         }
         MathNode.Trace("Invoke member function {0} from {1}", FunctionName, _methodRef.MethodOwner.Name);
         if (TargetObject == null)
         {
             if (_methodRef.IsStatic)
             {
                 TargetObject = new CodeTypeReferenceExpression(_methodRef.MethodOwner.TypeString);
             }
             else
             {
                 TargetObject = this.MethodOwner.ExportCode(_methodRef.MethodOwner.XPath);
             }
         }
         //
         CodeMethodInvokeExpression e = new CodeMethodInvokeExpression(
             TargetObject, _methodRef.MethodName, parameterCode);
         return(e);
     }
 }
 public void CreateReturnIcon(RaisDataType t)
 {
     holder.CreateReturnIcon(t);
 }
Example #16
0
 public IntegerVariable(MathNode parent)
     : base(parent)
 {
     VariableType         = new RaisDataType();
     VariableType.LibType = typeof(int);
 }
Example #17
0
 public MathNodeMethodInvoke(MathNode parent, ObjectRef obj, string name, int id, RaisDataType retType, ParameterDef[] parameters)
     : base(parent)
 {
     _methodRef = new MethodRef(obj, name, id, parameters, retType);
     OnParametersSet();
 }
 public MathNodeValue(MathNode parent)
     : base(parent)
 {
     _dataType = new RaisDataType(typeof(double));
 }
 protected override void OnLoad(XmlNode node)
 {
     _dataType = (RaisDataType)XmlSerialization.ReadFromChildXmlNode(GetReader(), node, "ValueType");
     XmlSerialization.ReadValueFromChildNode(node, "Value", out _value);
 }
 public void SetType(RaisDataType t)
 {
     var.VariableType = t;
 }
Example #21
0
        public static void CreateTestMethod(IMathExpression result, CodeTypeDeclaration t, CodeNamespace ns, CodeMemberMethod m, AssemblyRefList imports, VariableList parameters, List <IPropertyPointer> pointerList)
        {
            result.GetAllImports(imports);
            //
            m.ReturnType = new CodeTypeReference(result.DataType.Type);
            //
            m.Comments.Add(new CodeCommentStatement("Variable mapping:"));
            m.Comments.Add(new CodeCommentStatement("In formula:  method parameter"));
            //
            MethodType mt = new MethodType();

            mt.MethodCode = m;
            result.GenerateInputVariables();
            VariableList variables = result.InputVariables;
            Dictionary <string, IPropertyPointer> pointers = new Dictionary <string, IPropertyPointer>();

            result.GetPointers(pointers);
            int n = variables.Count;

            MathNode.Trace("Generate arguments from {0} input variables", n);
            MathNode.IndentIncrement();
            for (int k = 0; k < n; k++)
            {
                IVariable var = variables[k];
                MathNode.Trace(k, var);
                if (!(var is MathNodeVariableDummy) && !var.IsParam && !var.IsConst)
                {
                    string paramName = "";
                    parameters.Add(var);
                    paramName = var.CodeVariableName;
                    CodeParameterDeclarationExpression p = new CodeParameterDeclarationExpression(new CodeTypeReference(var.VariableType.Type), paramName);
                    m.Parameters.Add(p);
                    //add comment
                    string sub = var.SubscriptName;
                    if (string.IsNullOrEmpty(sub))
                    {
                        sub = " ";
                    }
                    m.Comments.Add(new CodeCommentStatement(string.Format("{0}{1}:\t {2}", var.VariableName, sub, var.CodeVariableName)));
                    MathNode.IndentIncrement();
                    MathNode.Trace("Argument {0} {1} for {2}, {3}", var.VariableType.Type, paramName, var.TraceInfo, var.GetType());
                    MathNode.IndentDecrement();
                    //
                    result.AssignCodeExp(new CodeArgumentReferenceExpression(paramName), var.CodeVariableName);
                }
            }
            MathNode.Trace("Generate arguments from {0} pointers", pointers.Count);
            foreach (KeyValuePair <string, IPropertyPointer> kv in pointers)
            {
                string paramName = "";
                pointerList.Add(kv.Value);
                paramName = kv.Value.CodeName;
                CodeParameterDeclarationExpression p = new CodeParameterDeclarationExpression(new CodeTypeReference(kv.Value.ObjectType), paramName);
                m.Parameters.Add(p);
                //add comment
                m.Comments.Add(new CodeCommentStatement(string.Format("{0}:\t {1}", kv.Value.ToString(), paramName)));
                MathNode.IndentIncrement();
                MathNode.Trace("Argument {0} {1} for {2}", kv.Value.ObjectType, paramName, kv.Value.ToString());
                MathNode.IndentDecrement();
            }
            MathNode.IndentDecrement();
            //do the compiling
            CodeExpression ce = result.ReturnCodeExpression(mt);

            //
            MathNode.Trace("Test method returns {0}, compiled type: {1}", result.DataType.Type, result.ActualCompileDataType.Type);
            if (result.ActualCompileDataType.Type.Equals(result.DataType.Type))
            {
                CodeMethodReturnStatement mr = new CodeMethodReturnStatement(ce);
                m.Statements.Add(mr);
            }
            else
            {
                if (result.ActualCompileDataType.IsVoid)
                {
                    m.Statements.Add(new CodeExpressionStatement(ce));
                    CodeMethodReturnStatement mr = new CodeMethodReturnStatement(ValueTypeUtil.GetDefaultValueByType(result.DataType.Type));
                    m.Statements.Add(mr);
                }
                else
                {
                    if (result.DataType.IsVoid)
                    {
                        m.Statements.Add(new CodeExpressionStatement(ce));
                    }
                    else
                    {
                        if (result.DataType.Type.Equals(typeof(string)))
                        {
                            CodeMethodReturnStatement mr = new CodeMethodReturnStatement(new CodeMethodInvokeExpression(ce, "ToString", new CodeExpression[] { }));
                            m.Statements.Add(mr);
                        }
                        else
                        {
                            CodeExpression mie = RaisDataType.GetConversionCode(result.ActualCompileDataType, ce, result.DataType, m.Statements);
                            if (mie != null)
                            {
                                CodeMethodReturnStatement mr = new CodeMethodReturnStatement(mie);
                                m.Statements.Add(mr);
                            }
                        }
                    }
                }
            }
        }
Example #22
0
 public void SetDataType(RaisDataType t)
 {
     _dataType    = t;
     _typePointer = new DataTypePointer(new TypePointer(t.LibType));
 }