示例#1
0
        private void Highlight(CodeLine codeLine)
        {
            if (null != lastHighlight)
            {
                lastHighlight.border.Highlight(false);
            }
            lastHighlight = codeLine;
            lastHighlight.border.Highlight(true);

            CodeShape borderRoot = codeLine.border;
            Point     start      = new Point(scrollViewer.HorizontalOffset, scrollViewer.VerticalOffset);
            Point     end        = borderRoot.grid.TranslatePoint(new Point(0, 0), canvas);

            end.X      = (end.X - widthSpace) * scaleView;
            end.Y      = (end.Y - heightSpace) * scaleView;
            scrollStep = 0;
            timer      = new Timer(_timer, new Point[] { start, end }, 0, 10);
        }
示例#2
0
        public void Display()
        {
            Cursor cursor = Mouse.OverrideCursor;

            Mouse.OverrideCursor = Cursors.Wait;

            try
            {
                canvas.Children.Clear();
                codeLines.Clear();
                subs.Clear();
                sbDocument = mainWindow.GetActiveDocument();
                //scaleView = 1;
                //scaleTransform.ScaleX = 1.0;
                //scaleTransform.ScaleY = 1.0;
                lastHighlight = null;

                Parse();

                maxrow = 0;
                maxcol = 0;
                foreach (CodeLine codeLine in codeLines)
                {
                    int row = codeLine.row;
                    int col = codeLine.col;

                    if (codeLine.block != eBlock.START && codeLine.block != eBlock.SUB && codeLine.block != eBlock.ELSE && codeLine.block != eBlock.ELSEIF)
                    {
                        ConnectEndIf(row, col, 0, col);
                    }

                    if (codeLine.block == eBlock.ELSE || codeLine.block == eBlock.ELSEIF)
                    {
                        Line connect = new Line()
                        {
                            X1              = borderSpace + (width + widthSpace) * col + 2,
                            X2              = borderSpace + (width + widthSpace) * col - widthSpace - 2,
                            Y1              = borderSpace + heightSpace * row + height / 2,
                            Y2              = borderSpace + heightSpace * row + height / 2,
                            Stroke          = new SolidColorBrush(foreground),
                            StrokeThickness = 2,
                        };
                        canvas.Children.Add(connect);

                        int testCol = col - 1;
                        while (null == HasSymbol(row, testCol) && testCol > 0)
                        {
                            Line connect2 = new Line()
                            {
                                X1              = borderSpace + (width + widthSpace) * (testCol + 1) + 2,
                                X2              = borderSpace + (width + widthSpace) * testCol - widthSpace - 2,
                                Y1              = borderSpace + heightSpace * row + height / 2,
                                Y2              = borderSpace + heightSpace * row + height / 2,
                                Stroke          = new SolidColorBrush(foreground),
                                StrokeThickness = 2,
                            };
                            canvas.Children.Add(connect2);
                            testCol--;
                        }

                        ImageSource arrow = MainWindow.ImageSourceFromBitmap(Properties.Resources.Arrow);
                        Image       img   = new Image()
                        {
                            Width  = 24,
                            Height = 24,
                            Source = arrow,
                        };
                        RotateTransform rotateTransform = new RotateTransform();
                        rotateTransform.CenterX = 12;
                        rotateTransform.CenterY = 12;
                        rotateTransform.Angle   = 180;
                        img.RenderTransform     = new TransformGroup();
                        ((TransformGroup)img.RenderTransform).Children.Add(rotateTransform);
                        canvas.Children.Add(img);
                        Canvas.SetLeft(img, borderSpace + (width + widthSpace) * col - 22);
                        Canvas.SetTop(img, borderSpace + heightSpace * row + height / 2 - 11);
                        Canvas.SetZIndex(img, 1);
                    }

                    if (codeLine.block == eBlock.IF || codeLine.block == eBlock.ELSEIF)
                    {
                        if (TFshape)
                        {
                            Grid imgTrue = CodeShape.GetBlock(Colors.Green, "T", 24, 24, eShape.ELLIPSE);
                            canvas.Children.Add(imgTrue);
                            Canvas.SetLeft(imgTrue, borderSpace + (width + widthSpace) * col + width / 2 - imgTrue.Width / 2);
                            Canvas.SetTop(imgTrue, borderSpace + heightSpace * row + height + 2);
                            Canvas.SetZIndex(imgTrue, 1);

                            Grid imgFalse = CodeShape.GetBlock(Colors.Red, "F", 24, 24, eShape.ELLIPSE);
                            canvas.Children.Add(imgFalse);
                            Canvas.SetLeft(imgFalse, borderSpace + (width + widthSpace) * col + width + 2);
                            Canvas.SetTop(imgFalse, borderSpace + heightSpace * row + height / 2 - imgTrue.Height / 2);
                            Canvas.SetZIndex(imgFalse, 1);
                        }
                        else
                        {
                            TextBlock condition = new TextBlock()
                            {
                                Foreground = new SolidColorBrush(foreground),
                                Text       = "True",
                            };
                            condition.Measure(new Size(double.MaxValue, double.MaxValue));
                            canvas.Children.Add(condition);
                            Canvas.SetLeft(condition, borderSpace + (width + widthSpace) * col + width / 2 + 2);
                            Canvas.SetTop(condition, borderSpace + heightSpace * row + height + 2);

                            condition = new TextBlock()
                            {
                                Foreground = new SolidColorBrush(foreground),
                                Text       = "False",
                            };
                            condition.Measure(new Size(double.MaxValue, double.MaxValue));
                            canvas.Children.Add(condition);
                            Canvas.SetLeft(condition, borderSpace + (width + widthSpace) * col + width + 2);
                            Canvas.SetTop(condition, borderSpace + heightSpace * row + height / 2 - condition.DesiredSize.Height - 2);
                        }
                    }

                    if (codeLine.block == eBlock.ENDIF)
                    {
                        int rowIf = codeLine.rootLine.row;
                        for (int colIf = 0; colIf <= maxcol; colIf++)
                        {
                            CodeLine cl = HasSymbol(rowIf, colIf);
                            if (null != cl && cl.rootLine == codeLine.rootLine)
                            {
                                ConnectEndIf(codeLine.row, codeLine.col, rowIf, colIf);
                            }
                        }
                    }

                    if (codeLine.block == eBlock.ENDFOR || codeLine.block == eBlock.ENDWHILE || codeLine.block == eBlock.GOTO)
                    {
                        ConnectLoop(codeLine.row, codeLine.col, codeLine.rootLine.row, codeLine.rootLine.col);
                    }

                    Color color;
                    switch (codeLine.block)
                    {
                    case eBlock.IF:
                    case eBlock.ELSE:
                    case eBlock.ELSEIF:
                        color = MainWindow.IntToColor(MainWindow.CHART_CONDITION_COLOR);
                        break;

                    case eBlock.START:
                    case eBlock.SUB:
                        color = MainWindow.IntToColor(MainWindow.CHART_START_COLOR);
                        break;

                    case eBlock.GOTO:
                    case eBlock.LABEL:
                    case eBlock.CALL:
                        color = MainWindow.IntToColor(MainWindow.CHART_CALL_COLOR);
                        break;

                    case eBlock.FOR:
                    case eBlock.ENDFOR:
                        color = MainWindow.IntToColor(MainWindow.CHART_FOR_COLOR);
                        break;

                    case eBlock.WHILE:
                    case eBlock.ENDWHILE:
                        color = MainWindow.IntToColor(MainWindow.CHART_WHILE_COLOR);
                        break;

                    default:
                        color = MainWindow.IntToColor(MainWindow.CHART_STATEMENT_COLOR);
                        break;
                    }

                    CodeShape border = new CodeShape(codeLine, width, height, color);
                    codeLine.border        = border;
                    border.grid.MouseDown += new MouseButtonEventHandler(codeClick);

                    canvas.Children.Add(border.grid);
                    Canvas.SetLeft(border.grid, borderSpace + (width + widthSpace) * col);
                    Canvas.SetTop(border.grid, borderSpace + heightSpace * row++);
                    maxcol = Math.Max(maxcol, col);
                    maxrow = Math.Max(maxrow, row);
                }

                canvas.Width  = -widthSpace + 2 * borderSpace + (width + widthSpace) * (maxcol + 1);
                canvas.Height = borderSpace + heightSpace * maxrow;
            }
            catch (Exception ex)
            {
                MainWindow.Errors.Add(new Error("Flow Chart : " + ex.Message));
                OnError();
            }
            Mouse.OverrideCursor = cursor;
        }