Пример #1
0
        //CodeTransformer ct = new CodeTransformer();
        protected Node AddNode(GraphWriter g, IStatement ist, Stage stage)
        {
            if (ist is ICommentStatement)
            {
                return(null);
            }
            Node nd = GetNodeForStatement(ist, stage);

            if (nd != null)
            {
                nd.Label = Count + "," + nd.Label;
                Count++;
                return(nd);
            }
            DependencyInformation di = context.InputAttributes.Get <DependencyInformation>(ist);

            if ((di != null) && (di.IsOutput))
            {
                return(null);
            }
            string s = Count + ". " + StatementLabel(ist);

            nd          = g.AddNode("node" + Count);
            nd.UserData = Count++;
            SetNodeForStatement(ist, stage, nd);
            //if (di.IsOutput) nd.Fillcolor = Color.LightBlue;
            nd.Label = s;
            if (stage == Stage.Initialisation)
            {
                nd.FillColor = Color.LightGray;
            }
            if (ist is IExpressionStatement)
            {
                IExpressionStatement ies = (IExpressionStatement)ist;
                IAssignExpression    iae = ies.Expression as IAssignExpression;
                if ((iae != null) && (iae.Target is IVariableDeclarationExpression))
                {
                    nd.BorderWidth = 2;
                }
            }
            nd.Shape    = ShapeStyle.Box;
            nd.FontSize = 9;
            return(nd);
        }
Пример #2
0
        protected Node GetNode(GraphWriter g, ConditionContext context)
        {
            Node node;

            if (!nodeOfContext.TryGetValue(context, out node))
            {
                node = g.AddNode("node" + (Count++));
                nodeOfContext[context] = node;
                node.Label             = context.GetLabel();
                node.UserData          = this.GroupInstance;
                ConditionContext parent = context.GetParentContext();
                if (parent != null)
                {
                    var parentNode = GetNode(g, parent);
                    AddGroupEdge(g, parentNode, node);
                }
                var  variable      = context.GetConditionVariable();
                Node conditionNode = GetNode(g, variable);
                g.AddEdge(conditionNode.ID, node.ID);
            }
            return(node);
        }
Пример #3
0
        protected Node GetNode(GraphWriter g, IModelExpression expr)
        {
            if (nodeOfExpr.ContainsKey(expr))
            {
                return(nodeOfExpr[expr]);
            }
            Node nd = g.AddNode("node" + (Count++));

            nodeOfExpr[expr] = nd;
            nd.Label         = expr.ToString();
            nd.FontSize      = 9;
            if (expr is Variable)
            {
                Variable ve = (Variable)expr;
                if (ve.IsObserved)
                {
                    nd.Shape = ShapeStyle.None;

                    if (ve.IsBase)
                    {
                        // if the observed value is a ValueType, display it directly rather than the variable name
                        object value = ((HasObservedValue)ve).ObservedValue;
                        if (ReferenceEquals(value, null))
                        {
                            nd.Label = "null";
                        }
                        else if (value.GetType().IsValueType)
                        {
                            nd.Label = value.ToString();
                        }
                    }
                }
                if (!ve.IsReadOnly)
                {
                    nd.FontSize  = 10;
                    nd.FontColor = Color.Blue;
                }
                if (UseContainers && ve.Containers.Count > 0)
                {
                    var context = ConditionContext.GetContext(ve.Containers);
                    if (context != null)
                    {
                        var contextNode = GetNode(g, context);
                        AddGroupEdge(g, contextNode, nd);
                    }
                }
            }
            else if (expr is MethodInvoke)
            {
                MethodInvoke mi = (MethodInvoke)expr;
                nd.FillColor = Color.Black;
                nd.FontColor = Color.White;
                nd.Shape     = ShapeStyle.Box;
                nd.FontSize  = 8;
                string methodName = mi.method.Name;
                if (mi.op != null)
                {
                    methodName = mi.op.ToString();
                }
                nd.Label = methodName;
                if (UseContainers && mi.Containers.Count > 0)
                {
                    var context = ConditionContext.GetContext(mi.Containers);
                    if (context != null)
                    {
                        var contextNode = GetNode(g, context);
                        AddGroupEdge(g, contextNode, nd);
                    }
                }
            }
            return(nd);
        }