Browse Source

A first draft of dependency matrix.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6195 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Tomáš Linhart 16 years ago
parent
commit
3641142243
  1. 4
      src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj
  2. 15
      src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrix.cs
  3. 11
      src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrixControl.cs
  4. 31
      src/AddIns/Analysis/CodeQuality/Src/Controls/Matrix.cs
  5. 109
      src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs
  6. 70
      src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml
  7. 16
      src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs

4
src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj

@ -96,7 +96,11 @@ @@ -96,7 +96,11 @@
<Compile Include="Src\Controls\DependencyEdge.cs" />
<Compile Include="Src\Controls\DependencyGraph.cs" />
<Compile Include="Src\Controls\DependencyGraphLayout.cs" />
<Compile Include="Src\Controls\DependencyMatrixControl.cs" />
<Compile Include="Src\Controls\DependencyMatrix.cs" />
<Compile Include="Src\Controls\DependencyVertex.cs" />
<Compile Include="Src\Controls\Matrix.cs" />
<Compile Include="Src\Controls\MatrixControl.cs" />
<Compile Include="Src\DependencyGraphCommand.cs" />
<Compile Include="Src\Event.cs" />
<Compile Include="Src\Field.cs" />

15
src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrix.cs

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ICSharpCode.CodeQualityAnalysis.Controls
{
public class DependencyMatrix : Matrix<INode>
{
public override object EvaluateCell(MatrixCell<INode> rowHeader, MatrixCell<INode> columnHeader)
{
return rowHeader.Value == columnHeader.Value; // TODO: Add a new method to INode Uses(INode -> Boolean) or maybe Relatioship(INode -> Relatioship)
}
}
}

11
src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyMatrixControl.cs

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ICSharpCode.CodeQualityAnalysis.Controls
{
public class DependencyMatrixControl : MatrixControl<INode>
{
}
}

31
src/AddIns/Analysis/CodeQuality/Src/Controls/Matrix.cs

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ICSharpCode.CodeQualityAnalysis.Controls
{
public abstract class Matrix<TValue>
{
public List<MatrixCell<TValue>> HeaderRows { get; set; }
public List<MatrixCell<TValue>> HeaderColumns { get; set; }
protected Matrix()
{
HeaderRows = new List<MatrixCell<TValue>>();
HeaderColumns = new List<MatrixCell<TValue>>();
}
public abstract object EvaluateCell(MatrixCell<TValue> rowHeader, MatrixCell<TValue> columnHeader);
}
public class MatrixCell<TValue>
{
public TValue Value { get; set; }
public MatrixCell(TValue value)
{
Value = value;
}
}
}

109
src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs

@ -0,0 +1,109 @@ @@ -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<TValue> : Grid
{
public Matrix<TValue> Matrix { get; set; }
/// <summary>
/// TODO: Needs to be reworked for DataBinding and to XAML
/// </summary>
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);
}
}
}
}

70
src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml

@ -1,7 +1,6 @@ @@ -1,7 +1,6 @@
<Window x:Class="ICSharpCode.CodeQualityAnalysis.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls;assembly=ICSharpCode.WpfDesign.Designer"
xmlns:Graph="clr-namespace:ICSharpCode.CodeQualityAnalysis.Controls"
Title="Code Quality Analysis"
@ -13,40 +12,47 @@ @@ -13,40 +12,47 @@
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250px" />
<ColumnDefinition />
<ColumnDefinition Width="200px" />
</Grid.ColumnDefinitions>
<TabControl>
<TabItem Header="Dependency Graph">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<ToolBarTray Background="White" Grid.Row="0" Grid.ColumnSpan="2">
<ToolBar>
<Button Name="btnOpenAssembly" Click="btnOpenAssembly_Click" Margin="0 0 5 0">Open Assembly</Button>
<Button Name="btnRelayout" Click="btnRelayout_Click" Margin="0 0 5 0">Relayout</Button>
<Button Name="btnContinueLayout" Click="btnContinueLayout_Click" Margin="0 0 5 0">Continue Layout</Button>
<Button Name="btnResetGraph" Click="btnResetGraph_Click" Margin="0 0 5 0">Reset Graph</Button>
<Button Name="btnSaveImageGraph" Click="btnSaveImageGraph_Click">Save an Image of Graph</Button>
</ToolBar>
</ToolBarTray>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250px" />
<ColumnDefinition />
<ColumnDefinition Width="200px" />
</Grid.ColumnDefinitions>
<TreeView Name="definitionTree" Grid.Row="1" Grid.Column="0" SelectedItemChanged="definitionTree_SelectedItemChanged" />
<ToolBarTray Background="White" Grid.Row="0" Grid.ColumnSpan="2">
<ToolBar>
<Button Name="btnOpenAssembly" Click="btnOpenAssembly_Click" Margin="0 0 5 0">Open Assembly</Button>
<Button Name="btnRelayout" Click="btnRelayout_Click" Margin="0 0 5 0">Relayout</Button>
<Button Name="btnContinueLayout" Click="btnContinueLayout_Click" Margin="0 0 5 0">Continue Layout</Button>
<Button Name="btnResetGraph" Click="btnResetGraph_Click" Margin="0 0 5 0">Reset Graph</Button>
<Button Name="btnSaveImageGraph" Click="btnSaveImageGraph_Click">Save an Image of Graph</Button>
</ToolBar>
</ToolBarTray>
<Controls:ZoomControl Grid.Row="1" Grid.Column="1" Name="zoom" AlwaysShowZoomButtons="True" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
<Graph:DependencyGraphLayout x:Name="graphLayout"
LayoutAlgorithmType="LinLog"
OverlapRemovalAlgorithmType="FSA"
HighlightAlgorithmType="Simple"
VertexClick="graphLayout_VertexClick"
/>
</Controls:ZoomControl>
<TreeView Name="definitionTree" Grid.Row="1" Grid.Column="0" SelectedItemChanged="definitionTree_SelectedItemChanged" />
<Controls:ZoomControl Grid.Row="1" Grid.Column="1" Name="zoom" AlwaysShowZoomButtons="True" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
<Graph:DependencyGraphLayout x:Name="graphLayout"
LayoutAlgorithmType="LinLog"
OverlapRemovalAlgorithmType="FSA"
HighlightAlgorithmType="Simple"
VertexClick="graphLayout_VertexClick"
/>
</Controls:ZoomControl>
<TextBlock Name="txbTypeInfo" Grid.Column="3" Grid.Row="1"/>
</Grid>
<TextBlock Name="txbTypeInfo" Grid.Column="3" Grid.Row="1"/>
</Grid>
</TabItem>
<TabItem Header="Dependency Matrix">
<Graph:DependencyMatrixControl x:Name="matrixControl"></Graph:DependencyMatrixControl>
</TabItem>
</TabControl>
</Window>

16
src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs

@ -54,6 +54,8 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -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 @@ -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<INode>(ns));
matrix.HeaderColumns.Add(new MatrixCell<INode>(ns));
}
matrixControl.Matrix = matrix;
matrixControl.DrawMatrix();
}
private void definitionTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
var item = definitionTree.SelectedItem as MetricTreeViewItem;

Loading…
Cancel
Save