Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Otykier
committed
Feb 22, 2018
1 parent
bd56626
commit 245b860
Showing
12 changed files
with
478 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Drawing; | ||
using TabularEditor.TOMWrapper; | ||
|
||
namespace VisualizeRelationships | ||
{ | ||
public class Diagram | ||
{ | ||
public Diagram(Model model) | ||
{ | ||
Tables.Clear(); | ||
TablesZOrder.Clear(); | ||
Relationships.Clear(); | ||
|
||
var i = 0; | ||
foreach (var t in model.Tables) | ||
{ | ||
var tv = new TableVisual(this, t, i); | ||
Tables.Add(t, tv); | ||
TablesZOrder.Add(tv); | ||
i++; | ||
} | ||
|
||
} | ||
public Dictionary<Table, TableVisual> Tables = new Dictionary<Table, TableVisual>(); | ||
public List<TableVisual> TablesZOrder = new List<TableVisual>(); | ||
public List<RelationshipVisual> Relationships = new List<RelationshipVisual>(); | ||
|
||
private HashSet<Relationship> DrawnRelationships = new HashSet<Relationship>(); | ||
|
||
public void Draw(Graphics gfx) | ||
{ | ||
DrawnRelationships.Clear(); | ||
foreach(var t in TablesZOrder) | ||
{ | ||
t.DrawRelationships(gfx); | ||
} | ||
for (int i = TablesZOrder.Count - 1; i >= 0; i--) | ||
{ | ||
TablesZOrder[i].Draw(gfx); | ||
} | ||
} | ||
|
||
public DiagramObject HitTest(Point pt) | ||
{ | ||
|
||
} | ||
|
||
public void ClearSelectedTables() | ||
{ | ||
foreach (var t in TablesZOrder) t.Selected = false; | ||
} | ||
|
||
public void ClearSelectedRelationships() | ||
{ | ||
foreach (var r in Relationships) r.Selected = false; | ||
} | ||
|
||
public void ClearSelected() | ||
{ | ||
ClearSelectedTables(); | ||
ClearSelectedRelationships(); | ||
} | ||
} | ||
|
||
public abstract class DiagramObject | ||
{ | ||
public DiagramObject(Diagram diagram) | ||
{ | ||
Diagram = diagram; | ||
} | ||
protected readonly Diagram Diagram; | ||
public bool Selected { get; set; } | ||
public abstract void Select(bool multiSelect); | ||
} | ||
|
||
public class RelationshipVisual: DiagramObject | ||
{ | ||
TableVisual T1 { get { return Diagram.Tables[Relationship.FromTable]; } } | ||
TableVisual T2 { get { return Diagram.Tables[Relationship.ToTable]; } } | ||
|
||
public RelationshipVisual(Diagram diagram, Relationship relationship) : base(diagram) { | ||
Relationship = relationship; | ||
} | ||
public Relationship Relationship; | ||
public override void Select(bool multiSelect) | ||
{ | ||
|
||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
public class TableVisual: DiagramObject | ||
{ | ||
public TableVisual(Diagram diagram, Table table, int increment = 0): base(diagram) | ||
{ | ||
Table = table; | ||
X = increment * 20; | ||
Y = increment * 10; | ||
Width = 100; | ||
Height = 100; | ||
} | ||
|
||
public override void Select(bool multiSelect) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Table Table; | ||
public int X; | ||
public int Y; | ||
public int Width; | ||
public int Height; | ||
|
||
public void Draw(Graphics gfx) | ||
{ | ||
|
||
var p = new Pen(Brushes.Black, Selected ? 2 : 1); | ||
|
||
gfx.FillRectangle(Selected ? Brushes.LightGray : Brushes.White, X, Y, Width, Height); | ||
gfx.DrawRectangle(p, X, Y, Width, Height); | ||
gfx.DrawString(Table.Name, SystemFonts.DefaultFont, Brushes.Black, new RectangleF(X + 2, Y + 2, Width - 4, SystemFonts.DefaultFont.SizeInPoints + 4)); | ||
} | ||
|
||
public void DrawRelationships(Graphics gfx) | ||
{ | ||
var rels = Table.UsedInRelationships.ToList(); | ||
|
||
} | ||
|
||
public bool HitTest(Point pt) | ||
{ | ||
return pt.X >= X && pt.X <= X + Width && pt.Y >= Y && pt.Y <= Y + Height; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="WindowsAPICodePack-Core" version="1.1.1" targetFramework="net46" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.