From 3641142243dc3462e1d78e2410773680f441b2cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Linhart?= Date: Sat, 24 Jul 2010 04:39:04 +0000 Subject: [PATCH] A first draft of dependency matrix. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6195 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../CodeQuality/CodeQualityAnalysis.csproj | 4 + .../Src/Controls/DependencyMatrix.cs | 15 +++ .../Src/Controls/DependencyMatrixControl.cs | 11 ++ .../CodeQuality/Src/Controls/Matrix.cs | 31 +++++ .../CodeQuality/Src/Controls/MatrixControl.cs | 109 ++++++++++++++++++ .../Analysis/CodeQuality/Src/MainWindow.xaml | 70 ++++++----- .../CodeQuality/Src/MainWindow.xaml.cs | 16 +++ 7 files changed, 224 insertions(+), 32 deletions(-) create mode 100644 src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrix.cs create mode 100644 src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrixControl.cs create mode 100644 src/AddIns/Analysis/CodeQuality/Src/Controls/Matrix.cs create mode 100644 src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs diff --git a/src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj b/src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj index eee4de8016..fc98a8f3c6 100644 --- a/src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj +++ b/src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj @@ -96,7 +96,11 @@ + + + + diff --git a/src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrix.cs b/src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrix.cs new file mode 100644 index 0000000000..40219c1bf4 --- /dev/null +++ b/src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrix.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ICSharpCode.CodeQualityAnalysis.Controls +{ + public class DependencyMatrix : Matrix + { + public override object EvaluateCell(MatrixCell rowHeader, MatrixCell columnHeader) + { + return rowHeader.Value == columnHeader.Value; // TODO: Add a new method to INode Uses(INode -> Boolean) or maybe Relatioship(INode -> Relatioship) + } + } +} diff --git a/src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrixControl.cs b/src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrixControl.cs new file mode 100644 index 0000000000..fcb4d24d56 --- /dev/null +++ b/src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrixControl.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ICSharpCode.CodeQualityAnalysis.Controls +{ + public class DependencyMatrixControl : MatrixControl + { + } +} diff --git a/src/AddIns/Analysis/CodeQuality/Src/Controls/Matrix.cs b/src/AddIns/Analysis/CodeQuality/Src/Controls/Matrix.cs new file mode 100644 index 0000000000..6123dd0e7f --- /dev/null +++ b/src/AddIns/Analysis/CodeQuality/Src/Controls/Matrix.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ICSharpCode.CodeQualityAnalysis.Controls +{ + public abstract class Matrix + { + public List> HeaderRows { get; set; } + public List> HeaderColumns { get; set; } + + protected Matrix() + { + HeaderRows = new List>(); + HeaderColumns = new List>(); + } + + public abstract object EvaluateCell(MatrixCell rowHeader, MatrixCell columnHeader); + } + + public class MatrixCell + { + public TValue Value { get; set; } + + public MatrixCell(TValue value) + { + Value = value; + } + } +} diff --git a/src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs b/src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs new file mode 100644 index 0000000000..6c4b44972c --- /dev/null +++ b/src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; + +namespace ICSharpCode.CodeQualityAnalysis.Controls +{ + public class MatrixControl : Grid + { + public Matrix Matrix { get; set; } + + /// + /// TODO: Needs to be reworked for DataBinding and to XAML + /// + public void DrawMatrix() + { + DrawHeaders(); + + for (int i = 0; i < Matrix.HeaderRows.Count; i++) { + RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }); + + for (int j = 0; j < Matrix.HeaderColumns.Count; j++) { + ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }); + + var val = Matrix.EvaluateCell(Matrix.HeaderRows[i], Matrix.HeaderColumns[j]); + + var label = new Label { Content = val }; + + var style = new Style(); + + style.Setters.Add(new Setter + { + Property = Grid.RowProperty, + Value = i + 1 + }); + + style.Setters.Add(new Setter + { + Property = Grid.ColumnProperty, + Value = j + 1 + }); + + label.Style = style; + + Children.Add(label); + } + } + } + + protected void DrawHeaders() + { + RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }); + ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }); + + for (int i = 0; i < Matrix.HeaderRows.Count; i++) { + var label = new Label { Content = Matrix.HeaderRows[i].Value.ToString() }; + + var style = new Style(); + + style.Setters.Add(new Setter + { + Property = Grid.RowProperty, + Value = i + 1 + }); + + style.Setters.Add(new Setter + { + Property = Grid.ColumnProperty, + Value = 0 + }); + + label.Style = style; + + Children.Add(label); + } + + for (int i = 0; i < Matrix.HeaderColumns.Count; i++) { + var label = new Label { Content = Matrix.HeaderColumns[i].Value.ToString() }; + + var style = new Style(); + + style.Setters.Add(new Setter + { + Property = Grid.RowProperty, + Value = 0 + }); + + style.Setters.Add(new Setter + { + Property = Grid.ColumnProperty, + Value = i + 1 + }); + + label.Style = style; + /*label.RenderTransform = new RotateTransform() // need some tweaking + { + Angle = -90, + CenterX = -10, + CenterY = 40 + };*/ + + Children.Add(label); + } + } + } +} diff --git a/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml b/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml index d0798294a2..3192b119e2 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml +++ b/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml @@ -1,7 +1,6 @@  - - - - - - - - - - - + + + + + + + - - - - - - - - - + + + + + - + + + + + + + + + - - - + + + + + - - + + + + + + + diff --git a/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs b/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs index 86fe32641d..d850fb18e6 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs @@ -54,6 +54,8 @@ namespace ICSharpCode.CodeQualityAnalysis _metricsReader = new MetricsReader(fileDialog.FileName); FillTree(); + + FillMatrix(); } private void btnRelayout_Click(object sender, RoutedEventArgs e) @@ -129,6 +131,20 @@ namespace ICSharpCode.CodeQualityAnalysis } } + private void FillMatrix() + { + var matrix = new DependencyMatrix(); + + foreach (var ns in _metricsReader.MainModule.Namespaces) + { + matrix.HeaderRows.Add(new MatrixCell(ns)); + matrix.HeaderColumns.Add(new MatrixCell(ns)); + } + + matrixControl.Matrix = matrix; + matrixControl.DrawMatrix(); + } + private void definitionTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e) { var item = definitionTree.SelectedItem as MetricTreeViewItem;