コード例 #1
0
ファイル: CellDescriptor.cs プロジェクト: acivux/SvgMath
 public CellDescriptor(MathNode content, string halign, string valign, int colspan, int rowspan)
 {
     Content = content;
     HAlign = halign;
     VAlign = valign;
     ColSpan = colspan;
     RowSpan = rowspan;
 }
コード例 #2
0
        public static void HideProgress()
        {
#if DEBUG
            MathNode.Trace("Unloading progress message");
#endif
            if (_form != null)
            {
                if (_form.IsDisposed || _form.Disposing)
                {
                    _form = null;
                }
            }
            if (_form != null)
            {
                _form.Close();
            }
        }
コード例 #3
0
        public override CodeExpression ExportCode(IMethodCompile method)
        {
            MathNode.Trace("{0}.ExportCode for {1}", this.GetType().Name, operaterType);
            CodeExpression e1 = this[0].ExportCode(method);

            if (!(this[0].DataType.Type.Equals(typeof(bool))))
            {
                e1 = new CodeBinaryOperatorExpression(e1, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(0));
            }
            CodeExpression e2 = this[1].ExportCode(method);

            if (!(this[1].DataType.Type.Equals(typeof(bool))))
            {
                e2 = new CodeBinaryOperatorExpression(e2, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(0));
            }
            return(new CodeBinaryOperatorExpression(e1, operaterType, e2));
        }
コード例 #4
0
        public override Shader GetShader()
        {
            if (m_original.DisplayMaterial)
            {
                var front = GetShaderPart(m_original.Front);
                var back  = GetShaderPart(m_original.Back);

                var backfacing = new GeometryInfoNode("backfacepicker");
                var flipper    = new MixClosureNode("front or back");
                var lp         = new LightPathNode("lp for bf");
                var mlt        = new MathNode("toggle bf only when camera ray")
                {
                    Operation = MathNode.Operations.Multiply
                };

                m_shader.AddNode(backfacing);
                m_shader.AddNode(flipper);
                m_shader.AddNode(lp);
                m_shader.AddNode(mlt);

                lp.outs.IsCameraRay.Connect(mlt.ins.Value1);
                backfacing.outs.Backfacing.Connect(mlt.ins.Value2);

                mlt.outs.Value.Connect(flipper.ins.Fac);

                var frontclosure = front.GetClosureSocket();
                var backclosure  = back.GetClosureSocket();

                frontclosure.Connect(flipper.ins.Closure1);
                backclosure.Connect(flipper.ins.Closure2);

                flipper.outs.Closure.Connect(m_shader.Output.ins.Surface);
            }
            else
            {
                var last        = GetShaderPart(m_original.Front);
                var lastclosure = last.GetClosureSocket();

                lastclosure.Connect(m_shader.Output.ins.Surface);
            }


            m_shader.FinalizeGraph();

            return(m_shader);
        }
コード例 #5
0
        public override System.CodeDom.CodeExpression ExportCode(IMethodCompile method)
        {
            MathNode.Trace("{0}.ExportCode: [{1}]", this.GetType().Name, this[0].TraceInfo);
            CodeMethodReferenceExpression mr = new CodeMethodReferenceExpression();

            mr.MethodName   = "Sqrt";
            mr.TargetObject = new CodeTypeReferenceExpression(typeof(Math));
            CodeExpression[] ps = new CodeExpression[1];
            ps[0] = this[0].ExportCode(method);
            if (!this[0].DataType.Type.Equals(typeof(double)))
            {
                ps[0] = new CodeCastExpression(typeof(double), VPLUtil.GetCoreExpressionFromCast(ps[0]));
            }
            return(new CodeMethodInvokeExpression(
                       mr,
                       ps));
        }
コード例 #6
0
 public override bool Edit(UInt32 actionBranchId, Rectangle rcStart, ILimnorDesignerLoader loader, Form caller)
 {
     if (Owner == null)
     {
         Owner = loader.GetRootId();
     }
     try
     {
         _origiContext = VPLUtil.CurrentRunContext;
         if (loader.Project.IsWebApplication)
         {
             if (this.RunAt == EnumWebRunAt.Client)
             {
                 VPLUtil.CurrentRunContext = EnumRunContext.Client;
             }
             else
             {
                 VPLUtil.CurrentRunContext = EnumRunContext.Server;
             }
         }
         else
         {
             VPLUtil.CurrentRunContext = EnumRunContext.Server;
         }
         DlgMethod dlg = this.CreateMethodEditor(rcStart);
         dlg.LoadMethod(this, EnumParameterEditType.ReadOnly);
         if (dlg.EditSubAction(caller))
         {
             IsNewMethod = false;
             loader.GetRootId().SaveAction(this, loader.Writer);
             loader.NotifyChanges();
             return(true);
         }
     }
     catch (Exception err)
     {
         MathNode.Log(caller, err);
     }
     finally
     {
         ExitEditor();
         VPLUtil.CurrentRunContext = _origiContext;
     }
     return(false);
 }
コード例 #7
0
        public override object CloneExp(MathNode parent)
        {
            MathNodeVariable node = (MathNodeVariable)base.CloneExp(parent);

            node.VariableName  = _value;
            node.SubscriptName = _subscript;
            node._id           = ID;
            node.IsLocal       = IsLocal;
            node.IsParam       = IsParam;
            node.IsReturn      = IsReturn;
            node._passin       = _passin;
            if (_subscriptFont != null)
            {
                node._subscriptFont = (Font)_subscriptFont.Clone();
            }
            node.IsSuperscript = IsSuperscript;
            node.Position      = new Point(Position.X, Position.Y);
            if (VariableType == null)
            {
                throw new MathException("VariableType is null when clone it. {0}", _value);
            }
            else
            {
                node.VariableType = (RaisDataType)VariableType.Clone();
            }
            if (ClonePorts)
            {
                if (_outports != null)
                {
                    LinkLineNodeOutPort[] ports = new LinkLineNodeOutPort[_outports.Length];
                    for (int i = 0; i < ports.Length; i++)
                    {
                        _outports[i].ConstructorParameters = new object[] { node };
                        ports[i] = (LinkLineNodeOutPort)_outports[i].Clone();
                    }
                    node.OutPorts = ports;
                }
                if (_inport != null)
                {
                    _inport.ConstructorParameters = new object[] { node };
                    node.InPort = (LinkLineNodeInPort)_inport.Clone();
                }
            }
            return(node);
        }
コード例 #8
0
        void _timerX_Tick(object sender, EventArgs e)
        {
            if (_timerX != null)
            {
                _timerX.Enabled = false;
                _timerX         = null;
            }
            string src = string.Empty;
            string tgt = string.Empty;

            try
            {
                src = _htmlFile;
                tgt = Path.Combine(_projectFolder, Path.GetFileName(_htmlFile));
                File.Copy(src, tgt, true);
                src = Path.Combine(Path.GetDirectoryName(_htmlFile), string.Format(CultureInfo.InvariantCulture, "{0}.css", Path.GetFileNameWithoutExtension(_htmlFile)));
                if (File.Exists(src))
                {
                    tgt = Path.Combine(_projectFolder, Path.GetFileName(src));
                    File.Copy(src, tgt, true);
                }
            }
            catch (Exception err)
            {
                MathNode.LogError(string.Format(CultureInfo.InvariantCulture, "Error copying from [{0}] to [{1}]. {2}", src, tgt, err.Message));
            }
            int p = _htmlFile.LastIndexOf('.');

            if (p > 0)
            {
                src = string.Format(CultureInfo.InvariantCulture, "{0}.css", _htmlFile.Substring(0, p));
                if (File.Exists(src))
                {
                    tgt = Path.Combine(_projectFolder, Path.GetFileName(src));
                    try
                    {
                        File.Copy(src, tgt, true);
                    }
                    catch (Exception err)
                    {
                        MathNode.LogError(string.Format(CultureInfo.InvariantCulture, "Error copying from [{0}] to [{1}]. {2}", src, tgt, err.Message));
                    }
                }
            }
        }
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc != null)
            {
                edSvc.CloseDropDown();
                IMethodSelector ts = (IMethodSelector)MathNode.GetService(typeof(IMethodSelector));
                if (ts != null)
                {
                    UITypeEditorEditStyle style = ts.GetUIEditorStyle(context);
                    if (style == UITypeEditorEditStyle.DropDown)
                    {
                        IDataSelectionControl dropdown = ts.GetUIEditorDropdown(context, provider, value);
                        if (dropdown != null)
                        {
                            edSvc.DropDownControl((Control)dropdown);
                            object v = dropdown.UITypeEditorSelectedValue;
                            if (v != null)
                            {
                                return(v);
                            }
                        }
                    }
                    else if (style == UITypeEditorEditStyle.Modal)
                    {
                        IDataSelectionControl modal = ts.GetUIEditorModal(context, provider, value);
                        if (modal != null)
                        {
                            if (edSvc.ShowDialog((Form)modal) == DialogResult.OK)
                            {
                                IMethodNode mn = context.Instance as IMethodNode;
                                if (mn != null)
                                {
                                    mn.SetFunction(modal.UITypeEditorSelectedValue);
                                    return(mn.GetFunctionName());
                                }
                                return(modal.UITypeEditorSelectedValue);
                            }
                        }
                    }
                }
            }
            return(value);
        }
コード例 #10
0
        public override string CreatePhpScript(StringCollection method)
        {
            MathNode.Trace("{0}.CreatePhpScript", this.GetType().Name);
            string sum = ((IVariable)this[4]).CodeVariableName;

            this[2].AssignPhpScriptCodeExp(this.GetParameterCodePhp(method, 0), ((MathNodeVariable)this[3]).CodeVariableName);
            string fa = this.GetParameterCodePhp(method, 2);

            this[2].AssignPhpScriptCodeExp(this.GetParameterCodePhp(method, 1), ((MathNodeVariable)this[3]).CodeVariableName);
            string fb = this.GetParameterCodePhp(method, 2);

            this[2].AssignPhpScriptCodeExp(null, ((MathNodeVariable)this[3]).CodeVariableName);
            string f2 = MathNode.FormString("({0} + {1}) / 2.0", fa, fb);
            string f  = MathNode.FormString("{0} + {1}", f2, sum);
            string ba = MathNode.FormString("({0} - {1}) / {2}", this.GetParameterCodePhp(method, 1), this.GetParameterCodePhp(method, 0), _intervals);

            return(MathNode.FormString("({0}) * ({1})", ba, f));
        }
コード例 #11
0
        public void SetEventLink(IEvent e)
        {
            IEventPointer ep = e as IEventPointer;

            if (ep != null)
            {
                CompilerErrorCollection errors = DynamicLink.LinkEvent(ep, taskExecuter);
                if (errors != null && errors.Count > 0)
                {
                    StringCollection sc = new StringCollection();
                    for (int i = 0; i < errors.Count; i++)
                    {
                        sc.Add(errors[i].ErrorText);
                    }
                    MathNode.Log(sc);
                }
            }
        }
コード例 #12
0
        public override void OnReadFromXmlNode(IXmlCodeReader serializer, XmlNode node)
        {
            base.OnReadFromXmlNode(serializer, node);
            MethodId = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_handlerId);
            XmlObjectReader reader = (XmlObjectReader)serializer;
            ClassPointer    root   = reader.ObjectList.RootPointer as ClassPointer;
            MethodClass     mc     = root.GetCustomMethodById(MethodId);

            if (mc == null)
            {
                MathNode.LogError(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                "Method {0} not found in class {1}", MethodId, root.ClassId));
            }
            else
            {
                _method = mc;
            }
        }
コード例 #13
0
        protected override object OnEditValue(ITypeDescriptorContext context, IServiceProvider provider, System.Windows.Forms.Design.IWindowsFormsEditorService service, object value)
        {
            IWithProject mc = context.Instance as IWithProject;

            if (mc != null)
            {
                if (mc.Project == null)
                {
                    MathNode.Log(TraceLogClass.GetForm(provider), new DesignerException("Project not set for {0} [{1}]", mc, mc.GetType()));
                }
                else
                {
                    SetterClass          val      = value as SetterClass;
                    System.Drawing.Point curPoint = System.Windows.Forms.Cursor.Position;
                    rc.X = curPoint.X;
                    rc.Y = curPoint.Y;
                    DlgMethod dlg = val.CreateMethodEditor(rc);
                    try
                    {
                        dlg.LoadMethod(val, EnumParameterEditType.ReadOnly);
                        dlg.SetNameReadOnly();
                        if (service.ShowDialog((Form)dlg) == DialogResult.OK)
                        {
                            value = val;
                            ILimnorDesignerLoader l = LimnorProject.ActiveDesignerLoader as ILimnorDesignerLoader;
                            if (l != null)
                            {
                                DesignUtil.SaveCustomProperty(LimnorProject.ActiveDesignerLoader.Node, l.Writer, val.Property);
                                LimnorProject.ActiveDesignerLoader.NotifyChanges();
                            }
                        }
                    }
                    catch (Exception err)
                    {
                        MathNode.Log(TraceLogClass.GetForm(provider), err);
                    }
                    finally
                    {
                        val.ExitEditor();
                    }
                }
            }
            return(value);
        }
コード例 #14
0
        public static void ParseMML(XElement root, MathNode parentNode, MathConfig mc, int depth)
        {
            int recDepth = depth + 1;

            foreach (XElement element in root.Elements())
            {
                //ToDo: implement namespaces
                Console.WriteLine("{0} {1}", new String(' ', recDepth), element.Name);
                MathNode mn = new MathNode(
                    element.Name.LocalName,
                    element.Attributes().ToDictionary(kvp => kvp.Name.ToString(), kvp => kvp.Value),
                    mc, parentNode);
                element.Nodes()
                .Where(x => x.NodeType == System.Xml.XmlNodeType.Text || x.NodeType == System.Xml.XmlNodeType.Whitespace)
                .ToList()
                .ForEach(x => mn.Text = mn.Text + string.Join(" ", ((XText)x).Value.Split(null)));
                ParseMML(element, mn, mc, recDepth);
            }
        }
コード例 #15
0
        public override void LinkJumpedBranches(BranchList branches)
        {
            if (_jumpToId != 0)
            {
                if (_jumpToActionBranch == null || (_jumpToActionBranch.BranchId != _jumpToId && _jumpToActionBranch.FirstActionId != _jumpToId))
                {
                    _jumpToActionBranch = branches.GetJumpToActionBranch(_jumpToId);
                    if (_jumpToActionBranch == null)
                    {
                        throw new DesignerException("Invalid jump id [{0}] for branch [{1}]", _jumpToId, this.BranchId);
                    }

                    MathNode.Trace("Action string jump from [{0},{1}] to [{2},{3}]", this.BranchId, this.Name, _jumpToActionBranch.BranchId, _jumpToActionBranch.Name);
                }
                _jumpToActionBranch.SetPreviousAction(this);
                this.SetNextAction(_jumpToActionBranch);
            }
            base.LinkJumpedBranches(branches);
        }
        public bool OnSelectEntry(SearchTreeEntry entry, SearchWindowContext context)
        {
            if (!(entry is SearchTreeGroupEntry))
            {
                if (!GraphViewStaticBridge.HasGUIView(graphView))
                {
                    return(false);
                }

                MathNode node = ScriptableObject.CreateInstance(entry.userData as Type) as MathNode;

                AddNode(node);
                Node nodeUI = CreateNode(node) as Node;
                if (nodeUI != null)
                {
                    if (m_InsertStack != null)
                    {
                        MathStackNode stackNode = m_InsertStack.userData as MathStackNode;

                        stackNode.InsertNode(m_InsertIndex, node);
                        m_InsertStack.InsertElement(m_InsertIndex, nodeUI);
                    }
                    else
                    {
                        graphView.AddElement(nodeUI);

                        Vector2 pointInWindow = context.screenMousePosition - position.position;
                        Vector2 pointInGraph  = nodeUI.parent.WorldToLocal(pointInWindow);

                        nodeUI.SetPosition(new Rect(pointInGraph, Vector2.zero)); // it's ok to pass zero here because width/height is dynamic
                    }
                    nodeUI.Select(graphView, false);
                }
                else
                {
                    Debug.LogError("Failed to create element for " + node);
                    return(false);
                }

                return(true);
            }
            return(false);
        }
コード例 #17
0
        public override CodeExpression ExportCode(IMethodCompile method)
        {
            if (_passin != null)
            {
                return(_passin);
            }
            string s = method.GetParameterCodeNameById(this.Parameter.ID);

            if (string.IsNullOrEmpty(s))
            {
                MathNode.Trace("Argument '{0}' is not an argument for method '{1}'", ArgumentName, method.MethodName);
                return(ValueTypeUtil.GetDefaultCodeByType(Parameter.DataType.Type));
            }
            else
            {
                MathNode.Trace("{0}.ExportCode maps {1} to {2}", this.GetType().Name, ArgumentName, s);
                return(new CodeArgumentReferenceExpression(s));
            }
        }
コード例 #18
0
 public void DeleteSelectedComponents()
 {
     try
     {
         bool bSaved          = false;
         ISelectionService ss = (ISelectionService)dsf.GetService(typeof(ISelectionService));
         if (ss != null)
         {
             ICollection cc = ss.GetSelectedComponents();
             if (cc != null)
             {
                 IDesignerHost host = (IDesignerHost)dsf.GetService(typeof(IDesignerHost));
                 if (host != null)
                 {
                     CreateUndoTransaction("deleteSelectedComponent");
                     foreach (object v in cc)
                     {
                         if (v is System.ComponentModel.IComponent)
                         {
                             if (v != host.RootComponent)
                             {
                                 if (!bSaved)
                                 {
                                     bSaved   = true;
                                     bLoading = true;
                                     bLoading = false;
                                 }
                                 host.DestroyComponent((System.ComponentModel.IComponent)v);
                             }
                         }
                     }
                     root.Changed = true;
                     CommitUndoTransaction("deleteSelectedComponent");
                 }
             }
         }
     }
     catch (Exception err)
     {
         MathNode.Log(this.FindForm(), err);
         RollbackUndoTransaction("deleteSelectedComponent");
     }
 }
        public void RemoveEmptyScopes()
        {
            graphView.schedule.Execute(a =>
            {
                foreach (GraphElement element in graphView.graphElements.ToList())
                {
                    Scope scope = element as Scope;

                    if (scope != null && !(scope is Group) && scope.containedElements.Count() == 0)
                    {
                        MathNode mathNode = scope.userData as MathNode;

                        DestroyNode(mathNode);

                        graphView.RemoveElement(scope);
                    }
                }
            });
        }
コード例 #20
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            tvGac.LoadGac();
            //
            StringCollection sc   = new StringCollection();
            List <Assembly>  refs = _project.GetReferences(sc);

            if (sc.Count > 0)
            {
                MathNode.Log(sc);
            }
            foreach (Assembly a in refs)
            {
                tvGac.Nodes.Add(new TreeNodeAssembly(a));
            }
            //add an empty node to make sure all nodes are visible
            tvGac.Nodes.Add(new TreeNodeDummy());
        }
コード例 #21
0
        public override void ExportPhpScriptCodeStatements(StringCollection method)
        {
            MathNode.Trace("ExportPhpScriptCodeStatements for {0}", this.GetType());
            //0:function
            //1:index
            //2:begin
            //3:end
            //4:sum

            OnPreparePhpScriptVariable(method);
            string sum        = ((IVariable)this[4]).CodeVariableName;
            string declareSum = FormString("{0}={1};\r\n", ((IVariable)this[4]).CodeVariableName, ValueTypeUtil.GetDefaultPhpScriptCodeByType(((IVariable)this[4]).VariableType.Type));

            method.Add(declareSum);
            string idx = this[1].CreatePhpScript(method);

            method.Add(FormString("for({0}={1};{2}<={3};({2})++)\r\n{\r\n", ((IVariable)this[1]).CodeVariableName, this[2].CreatePhpScript(method), idx, this[3].CreatePhpScript(method)));
            method.Add(FormString("{0} = {0} + {1};\r\n", sum, this[0].CreatePhpScript(method)));
            method.Add("}\r\n");
        }
コード例 #22
0
        public override object CloneExp(MathNode parent)
        {
            MathNodeValue node = (MathNodeValue)base.CloneExp(parent);

            node.ValueType = this.ValueType;
            ICloneable ic = _value as ICloneable;

            if (ic != null)
            {
                node.Value = ic.Clone();
            }
            else
            {
                if (this.ValueType.Type.IsValueType)
                {
                    node.Value = _value;
                }
            }
            return(node);
        }
コード例 #23
0
        public RaisDataType GetRelatedType()
        {
            MathNode p = this.Parent;

            if (p != null)
            {
                int n = p.ChildNodeCount;
                if (n > 1)
                {
                    for (int i = 0; i < n; i++)
                    {
                        if (p[i] != this)
                        {
                            return(p[i].DataType);
                        }
                    }
                }
            }
            return(ValueType);
        }
コード例 #24
0
        protected override void OnEditAction()
        {
            MethodDiagramViewer mv = this.DiagramViewer;

            if (mv != null)
            {
                AB_ActionList av    = this.ActionObject as AB_ActionList;
                ActionList    aList = av.Actions;
                DlgActionList dlg   = new DlgActionList();
                dlg.LoadData(aList, mv.Method, mv.Project, mv.DesignerHolder);
                Form f = this.FindForm();
#if DEBUG
                MathNode.Trace("Showing dialog");
#endif
                if (dlg.ShowDialog(f) == DialogResult.OK)
                {
                    av.Actions = dlg.Result;
                    mv.Changed = true;
                    foreach (ActionItem a in aList)
                    {
                        if (a.Action != null && a.Action.Changed)
                        {
                            if (!mv.ChangedActions.ContainsKey(a.ActionId))
                            {
                                mv.ChangedActions.Add(a.ActionId, a.Action);
                            }
                        }
                    }
                }
                else
                {
                    foreach (ActionItem a in aList)
                    {
                        if (a.Action != null && a.Action.Changed)
                        {
                            a.Action.ReloadFromXmlNode();
                        }
                    }
                }
            }
        }
コード例 #25
0
        void mnu_separate(object sender, EventArgs e)
        {
            BinOperatorNode bin = Root.FocusedNode as BinOperatorNode;

            if (bin != null)
            {
                BinOperatorNode bin2 = bin[1] as BinOperatorNode;
                if (bin2 != null)
                {
                    //modify it from {0} b {b2} to
                    //{0} b {b2[0]} b2 {b2[1]}
                    //
                    //new b[1] = {b2[0]}
                    //new b2[0] = new b => {0} b {b2[0]}
                    //new b2[1] = {b2[1]}
                    //MathNode b1 = bin[1];
                    //
                    MathNode np = bin.Parent;
                    int      k  = -1;
                    for (int i = 0; i < np.ChildNodeCount; i++)
                    {
                        if (np[i] == bin)
                        {
                            k = i;
                            break;
                        }
                    }
                    if (k >= 0)
                    {
                        BinOperatorNode nb2 = (BinOperatorNode)Activator.CreateInstance(bin2.GetType(), bin.Parent);
                        bin[1] = bin2[0];
                        nb2[0] = bin;
                        nb2[1] = bin2[1];
                        //
                        np[k] = nb2;
                        this.Refresh();
                        Root.SetFocus(bin);
                    }
                }
            }
        }
コード例 #26
0
 /// <summary>
 /// edit this action
 /// </summary>
 /// <param name="exp"></param>
 private void showEditor(IMathExpression exp)
 {
     try
     {
         Rectangle     rc  = this.Parent.RectangleToScreen(this.Bounds);
         IMathEditor   dlg = exp.CreateEditor(rc);
         IMathDesigner md  = this.Parent as IMathDesigner;
         if (md.TestDisabled)
         {
             dlg.DisableTest();
         }
         if (((Form)dlg).ShowDialog(this.FindForm()) == DialogResult.OK)
         {
             setChanged();
         }
     }
     catch (Exception err)
     {
         MathNode.Log(this.FindForm(), err);
     }
 }
コード例 #27
0
 /// <summary>
 /// declare a variable and initialize it with default value.
 /// </summary>
 /// <param name="supprtStatements"></param>
 /// <param name="var"></param>
 public static void DeclareVariable(CodeStatementCollection supprtStatements, IVariable var)
 {
     if (var is MathNodeVariableDummy)
     {
         return;
     }
     if (!VariableDeclared(supprtStatements, var.CodeVariableName))
     {
         MathNode.Trace("Declare variable {0}", var.TraceInfo);
         CodeVariableDeclarationStatement p;
         if (var.VariableType.Type.IsValueType)
         {
             p = new CodeVariableDeclarationStatement(new CodeTypeReference(var.VariableType.Type), var.CodeVariableName);
         }
         else
         {
             p = new CodeVariableDeclarationStatement(new CodeTypeReference(var.VariableType.Type), var.CodeVariableName, ValueTypeUtil.GetDefaultCodeByType(var.VariableType.Type));
         }
         supprtStatements.Add(p);
     }
 }
コード例 #28
0
 public override void OnReplaceNode(MathNode replaced)
 {
     if (this.Parent != null && this.Parent.ChildNodeCount > 1)
     {
         for (int i = 0; i < this.Parent.ChildNodeCount; i++)
         {
             if (this.Parent[i] != this)
             {
                 if (!typeof(object).Equals(this.Parent[i].DataType.Type))
                 {
                     ValueType = this.Parent[i].DataType;
                 }
                 break;
             }
         }
     }
     else
     {
         ValueType = replaced.DataType;
     }
 }
コード例 #29
0
        public void Successfully_SortAscendingWithNestedMath()
        {
            var data   = Data(SortConf);
            var inner1 = new MathNode(MathOp.Add, Three, Two);
            var inner2 = new MathNode(MathOp.Add, Five, Four);
            var sub    = new MathNode(MathOp.Subtract, inner1, inner2);
            var inner3 = new MathNode(MathOp.Multiply, Six, One);
            var add    = new MathNode(MathOp.Add, sub, inner3);
            var group  = new GroupNode(null, new List <DiceAST> {
                add
            });
            var func = new FunctionNode(FunctionScope.Group, "expand", new DiceAST[0], data);

            func.Context.Expression = group;
            var node = new SortNode(SortDirection.Ascending)
            {
                Expression = func
            };

            EvaluateNode(node, data, 0, "{3 + 2 - (5 + 4) + 6 * 1}.expand().sortAsc() => (2 + 3 - (4 + 5) + 1 * 6) => 2");
        }
コード例 #30
0
        public override CodeExpression ExportCode(IMethodCompile method)
        {
            MathNode.Trace("{0}.ExportCode", this.GetType().Name);
            CodeExpression             e1   = this[0].ExportCode(method);
            CodeExpression             e2   = this[1].ExportCode(method);
            CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression();

            cmie.Method = new CodeMethodReferenceExpression();
            cmie.Method.TargetObject = new CodeTypeReferenceExpression(typeof(CodeDomHelper));
            if (shifLeft)
            {
                cmie.Method.MethodName = "ShifLeft";
            }
            else
            {
                cmie.Method.MethodName = "ShifRight";
            }
            cmie.Parameters.Add(e1);
            cmie.Parameters.Add(e2);
            return(cmie);
        }
コード例 #31
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));
            }
        }