Пример #1
0
            public void Reset(LibData data)
            {
                foreach (var tb in textBlocks)
                {
                    var d = data.dict[tb.DataContext as string];

                    Border borderActive = tb.Parent as Border;
                    borderActive.BorderThickness = new Thickness(1);
                    borderActive.BorderBrush     = d.isForeign
                                             ? Brushes.Black
                                             : Brushes.Blue;
                }
                textBlocks.Clear();

                foreach (var line in lines)
                {
                    canvas.Children.Remove(line);
                }
                lines.Clear();

                foreach (var path in paths)
                {
                    canvas.Children.Remove(path);
                }
                pathsPoints.Clear();
                paths.Clear();
            }
Пример #2
0
        private void buttonAnalyze_Click(object sender, RoutedEventArgs e)
        {
            // Clear states
            activeControls.Reset(data);
            lines.Clear();
            canvas.Children.Clear();

            // Analyze includes and create dictionary
            data = new LibData(textBoxDir.Text, textBoxFile.Text,
                               (bool)menu_IgnoreForeign.IsChecked,
                               (bool)menu_IgnoreComments.IsChecked);

            if ((bool)menu_Layout4.IsChecked)
            {
                gd = GraphLayout.ForceDirectedLayout(data.dict);
            }
            else if ((bool)menu_Layout3.IsChecked)
            {
                gd = GraphLayout.RadialHierarchicalLayout(textBoxDir.Text, data.dict);
            }
            else
            {
                GraphLayout.UseLevel useLevel = (bool)menu_Layout2.IsChecked
                                              ? GraphLayout.UseLevel.Max
                                              : GraphLayout.UseLevel.Min;
                gd = GraphLayout.LevelBasedLayout(data.dict, useLevel);
            }

            // Create textBlocks with borders for each include and calculate
            foreach (var d in data.dict)
            {
                TextBlock textBlock = new TextBlock();
                if (d.Value.duplicatedChildren)
                {
                    textBlock.Background = Brushes.Yellow;
                }
                else
                {
                    textBlock.Background = Brushes.White;
                }
                textBlock.Text        = Util.FileFromPath(d.Key);
                textBlock.Padding     = new Thickness(5);
                textBlock.Width       = d.Value.size.Width;
                textBlock.Height      = d.Value.size.Height;
                textBlock.DataContext = d.Key;
                string tooltip = d.Key
                                 + "\r\nLevels: [" + d.Value.minLevel + ", " + d.Value.maxLevel + "]"
                                 + (d.Value.duplicatedChildren ? "\r\nWARNING: duplicated includes" : "")
                                 + "\r\n";
                foreach (var c in d.Value.children)
                {
                    tooltip += "\r\n" + c;
                }
                textBlock.ToolTip    = tooltip;
                textBlock.MouseDown += TextBlock_MouseDown;

                d.Value.textBlock = textBlock;

                Border border = new Border();
                border.BorderThickness = new Thickness(1);
                border.BorderBrush     = d.Value.isForeign
                                   ? Brushes.Black
                                   : Brushes.Blue;
                border.Child = textBlock;
                double l = d.Value.center.X - d.Value.textBlock.Width / 2;
                double t = d.Value.center.Y - d.Value.textBlock.Height / 2;
                Canvas.SetLeft(border, l);
                Canvas.SetTop(border, t);
                Canvas.SetZIndex(border, 1);

                canvas.Children.Add(border);
            }

            // add all lines - connections between includes
            foreach (var d in data.dict)
            {
                double x = d.Value.center.X;
                double y = d.Value.center.Y;

                foreach (var cStr in d.Value.children)
                {
                    var c = data.dict[cStr];

                    double xC = c.center.X;
                    double yC = c.center.Y;

                    var line = new Line();
                    line.X1              = x;
                    line.Y1              = y;
                    line.X2              = xC;
                    line.Y2              = yC;
                    line.Stroke          = Brushes.DarkGray;
                    line.StrokeThickness = 1;
                    line.Visibility      = (bool)menu_ShowLines.IsChecked ? Visibility.Visible : Visibility.Hidden;
                    Canvas.SetZIndex(line, -1);

                    lines.Add(line);
                    canvas.Children.Add(line);
                }
            }

            // calculate the scale of graph in order to fit it to window
            double graphW       = gd.GraphSize.Width;
            double graphH       = gd.GraphSize.Height;
            double graphCenterX = graphW / 2;
            double graphCenterY = graphH / 2;
            double scaleW       = Math.Min(canvasGrid.ActualWidth / graphW, 1);
            double scaleH       = Math.Min(canvasGrid.ActualHeight / graphH, 1);
            double scale        = Math.Min(scaleW, scaleH);

            var matrix = Matrix.Identity;

            matrix.Scale(scale, scale);
            matrix.Translate(canvasGrid.ActualWidth / 2 - graphCenterX * scale, 0);
            canvas.RenderTransform = new MatrixTransform(matrix);

            if (data.dict.ContainsKey(data.rootPath))
            {
                TextBlock_MouseDown(data.dict[data.rootPath].textBlock, null);
            }
        }