Ejemplo n.º 1
0
        public void ConvertToNodes()
        {
            var col = new Collection <Instruction>()
            {
                X.NamespacePrefixDeclaration(RootNs),
                X.StartObject <DummyClass>(),
                X.StartMember <DummyClass>(@class => @class.Child),
                X.StartObject <ChildClass>(),
                X.EndObject(),
                X.EndMember(),
                X.EndObject(),
            };

            var result = NodeVisualizer.ToTree(col);
        }
Ejemplo n.º 2
0
        public XamlToolsControl()
        {
            InitializeComponent();

            VisualizeTagsCommand = new RelayCommand(Execute.Safely(_ => OpenTagVisualizer(NodeVisualizer.ToTags(ConvertToNodes(Xaml.ToStream())))));
            VisualizeTreeCommand = new RelayCommand(Execute.Safely(_ => OpenTreeVisualizer(NodeVisualizer.ToTree(ConvertToNodes(Xaml.ToStream())))));
        }
Ejemplo n.º 3
0
        public EvaluationContext Analyze()
        {
            VariableContext vc = CreateVariebleContext();


            MathyLanguageService service = new MathyLanguageService();

            List <Step> steps = new List <Step>();

            List <string> existingInVariables = new List <string>();


            int index = 0;

            foreach (SourceExpression expression in plan.Expressions)
            {
                Step step = new Step();
                step.SourceExpression = expression;

                try
                {
                    step.Expressions = service.Compile(expression.Expression, vc);
                }
                catch (CompileException ex)
                {
                    throw new Exception(string.Format("步骤{0}表达式编译错误:\r\n{1}", index + 1, ex.Message));
                }

                if (string.IsNullOrEmpty(expression.Condition))
                {
                    step.Conditions = new Expression[] { };
                }
                else
                {
                    try
                    {
                        step.Conditions = service.Compile(expression.Condition, vc);
                    }
                    catch (CompileException ex)
                    {
                        throw new Exception(string.Format("步骤{0}条件编译错误:\r\n{1}", index + 1, ex.Message));
                    }
                }

                Bitmap expressionImage = new NodeVisualizer(
                    step.Expressions
                    .Select(i => new NodeConverter().Convert(i))
                    .ToArray()).VisulizeAsBitmap();

                Bitmap conditionImage = step.Conditions.Length == 0 ? null :
                                        new NodeVisualizer(
                    step.Conditions
                    .Select(i => new NodeConverter().Convert(i))
                    .ToArray()).VisulizeAsBitmap();

                step.Image        = StackImages(expressionImage, conditionImage);
                step.ImageData    = Funcs.ImageToBytes(step.Image);
                step.OutVariables = CollectOutVariables(step.Expressions).ToArray();


                string[] inVariables = CollectVariables(step.Expressions)
                                       .Where(i => !step.OutVariables.Contains(i))
                                       .ToArray();

                string[] conditionVariables = CollectVariables(step.Conditions);

                step.InSourceVariables  = plan.Variables.Where(i => inVariables.Contains(i.Name) && !existingInVariables.Contains(i.Name)).ToArray();
                step.InValues           = new object[step.InSourceVariables.Length];
                step.DependentVariables = plan.Variables.Where(i => inVariables.Contains(i.Name)).ToArray();
                step.DependentValues    = new object[step.DependentVariables.Length];
                step.InTempVariables    = inVariables.Where(i => plan.Variables.All(j => j.Name != i)).ToArray();
                step.ConditionVariables = conditionVariables;

                existingInVariables.AddRange(step.InSourceVariables.Select(i => i.Name));

                steps.Add(step);


                index++;
            }

            foreach (Step step in steps)
            {
                List <Step> froms = new List <Step>();
                foreach (string tempVariable in step.InTempVariables)
                {
                    froms.AddRange(steps.Where(i => i.OutVariables.Contains(tempVariable)));
                }

                foreach (string tempVariable in step.ConditionVariables)
                {
                    froms.AddRange(steps.Where(i => i.OutVariables.Contains(tempVariable)));
                }


                step.Froms = froms.Where(i => i != null).Distinct().ToArray();
            }


            EvaluationContext context = new EvaluationContext(plan, steps.ToArray());

            foreach (SourceVariable variable in plan.Variables)
            {
                context.SetValue(variable.Name, null);
            }


            return(context);
        }
Ejemplo n.º 4
0
        private static RenderBranch Create(double x, double y, int angle, TreeBranch branch, VariableContext variables, Graphics g, Font font)
        {
            double x2 = x - branch.Position * Math.Cos(angle * Math.PI / 180);
            double y2 = y + branch.Position * Math.Sin(angle * Math.PI / 180);

            double x1 = x2 + branch.Length * Math.Cos((angle + branch.Angle) * Math.PI / 180);
            double y1 = y2 - branch.Length * Math.Sin((angle + branch.Angle) * Math.PI / 180);

            double a = Funcs.Atan(x1, y1, x2, y2);

            x2 = x1 + (branch.Length - 2) * Math.Cos(a);
            y2 = y1 - (branch.Length - 2) * Math.Sin(a);

            RenderBranch[] branches = branch.Branches.Select(i => Create(x2, y2, angle + branch.Angle - 180, i, variables, g, font)).ToArray();


            string description;

            double imageX          = 0;
            double imageY          = 0;
            Bitmap expressionImage = null;

            if (branch is ExpressionBranch)
            {
                string[] preVariables = variables.GetAllVariables();

                Expression[] expressions = new MathyLanguageService().Compile((branch as ExpressionBranch).Expression, variables);
                foreach (Expression expression in expressions)
                {
                    new MathyLanguageService().CreateEvaluator().Evaluate(expression, variables);
                }


                StringBuilder b = new StringBuilder();

                foreach (string variableName in variables.GetAllVariables().Where(i => !preVariables.Contains(i)))
                {
                    b.AppendFormat("{0}={1}", variableName, variables.GetValue(variableName));
                }


                description = branch.Description + "\r\n" + b.ToString();


                double xt = x2 + (branch as ExpressionBranch).ImageX * Math.Cos(a + Math.PI);
                double yt = y2 - (branch as ExpressionBranch).ImageX * Math.Sin(a + Math.PI);

                double d = (branch as ExpressionBranch).ImageY;

                imageX = xt + d * Math.Cos(a + Math.PI / 2);
                imageY = yt - d * Math.Sin(a + Math.PI / 2);

                expressionImage = new NodeVisualizer(expressions.Select(i => new NodeConverter().Convert(i)).ToArray()).VisulizeAsBitmap();
            }
            else
            {
                string variableName = (branch as VariableBranch).VariableName;
                object value        = variables.GetValue(variableName);
                description = string.Format("{0}\r\n{1}={2}", branch.Description, variableName, value);
            }


            double dx;
            double dy;

            EvaluateDescriptionPosition(branch, description, x1, y1, x2, y2, g, font, out dx, out dy);


            return(new RenderBranch()
            {
                X1 = x1,
                Y1 = y1,
                X2 = x2,
                Y2 = y2,
                IsVariable = branch is VariableBranch,
                ImageX = imageX,
                ImageY = imageY,
                Image = expressionImage,
                Branches = branches,
                DescriptionX = dx,
                DescriptionY = dy,
                Description = description
            });
        }