■ DiagramControl 클래스에서 커스텀 그래프 레이아웃 알고리즘을 사용하는 방법을 보여준다.
[TestLibrary 프로젝트]
▶ GraphLayout.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
using System.Collections.Generic; using Microsoft.Msagl.Core.Layout; using Microsoft.Msagl.Core.Routing; using DevExpress.Diagram.Core; using DevExpress.Diagram.Core.Layout; namespace TestLibrary { /// <summary> /// 그래프 레이아웃 /// </summary> public class GraphLayout { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 레이아웃 계산기 - LayoutCalculator /// <summary> /// 레이아웃 계산기 /// </summary> protected ILayoutCalculator LayoutCalculator { get; set; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region 기하 그래프 - GeometryGraph /// <summary> /// 기하 그래프 /// </summary> private GeometryGraph GeometryGraph { get; set; } #endregion #region 라우팅 모드 - RoutingMode /// <summary> /// 라우팅 모드 /// </summary> private EdgeRoutingMode RoutingMode { get { return LayoutCalculator.LayoutAlgorithmSettings.EdgeRoutingSettings.EdgeRoutingMode; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - GraphLayout(layoutCalculator) /// <summary> /// 생성자 /// </summary> /// <param name="layoutCalculator">레이아웃 계산기</param> public GraphLayout(ILayoutCalculator layoutCalculator) { LayoutCalculator = layoutCalculator; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 그래프 노드 위치 레이아웃 다시 설정하기 - RelayoutGraphNodePosition(graph) /// <summary> /// 그래프 노드 위치 레이아웃 다시 설정하기 /// </summary> /// <param name="graph">그래프</param> /// <returns>위치 정보 열거 가능 목록</returns> public virtual IEnumerable<PositionInfo<IDiagramItem>> RelayoutGraphNodePosition(Graph<IDiagramItem> graph) { GeometryGraph = MSAGLGeometryGraphHelper.GetGeometryGraph(graph); LayoutCalculator.CalculateLayout(GeometryGraph); return MSAGLGeometryGraphHelper.GetNodePositionInfo(GeometryGraph); } #endregion #region 다이어그램 커넥터 타입 구하기 - GetDiagramConnectorType() /// <summary> /// 다이어그램 커넥터 타입 구하기 /// </summary> /// <returns>다이어그램 커넥터 타입</returns> public ConnectorType GetDiagramConnectorType() { return RoutingHelper.GetDiagramConnectorType(RoutingMode); } #endregion } } |
▶ PhyloTreeLayout.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
using System.Collections.Generic; using Microsoft.Msagl.Prototype.Phylo; using DevExpress.Diagram.Core; using DevExpress.Diagram.Core.Layout; namespace TestLibrary { /// <summary> /// PHYLO 트리 레이아웃 /// </summary> public class PhyloTreeLayout : GraphLayout { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Private #region 트리 - Tree /// <summary> /// 트리 /// </summary> private PhyloTree Tree { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - PhyloTreeLayout(layoutCalculator) /// <summary> /// 생성자 /// </summary> /// <param name="layoutCalculator">레이아웃 계산기</param> public PhyloTreeLayout(ILayoutCalculator layoutCalculator) : base(layoutCalculator) { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 그래프 노드 위치 레이아웃 다시 설정하기 - RelayoutGraphNodePosition(graph) /// <summary> /// 그래프 노드 위치 레이아웃 다시 설정하기 /// </summary> /// <param name="graph">그래프</param> /// <returns>위치 정보 열거 가능 목록</returns> public override IEnumerable<PositionInfo<IDiagramItem>> RelayoutGraphNodePosition(Graph<IDiagramItem> graph) { Tree = MSAGLGeometryGraphHelper.GetPhyloTree(graph); LayoutCalculator.CalculateLayout(Tree); return MSAGLGeometryGraphHelper.GetNodePositionInfo(Tree); } #endregion } } |
▶ ILayoutCalculator.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
using Microsoft.Msagl.Core.Layout; namespace TestLibrary { /// <summary> /// 레이아웃 계산기 인터페이스 /// </summary> public interface ILayoutCalculator { //////////////////////////////////////////////////////////////////////////////////////////////////// Property #region 레이아웃 알고리즘 설정 - LayoutAlgorithmSettings /// <summary> /// 레이아웃 알고리즘 설정 /// </summary> LayoutAlgorithmSettings LayoutAlgorithmSettings { get; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method #region 레이아웃 계산하기 - CalculateLayout(geometryGraph) /// <summary> /// 레이아웃 계산하기 /// </summary> /// <param name="geometryGraph">기하 그래프</param> void CalculateLayout(GeometryGraph geometryGraph); #endregion } } |
▶ DisconnectedGraphsLayoutCaculator.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
using System; using System.Collections.Generic; using Microsoft.Msagl.Core.Geometry.Curves; using Microsoft.Msagl.Core.Layout; using Microsoft.Msagl.Core.Routing; using Microsoft.Msagl.Layout.Layered; using Microsoft.Msagl.Layout.MDS; namespace TestLibrary { /// <summary> /// 비연결 그래프 레이아웃 계산기 /// </summary> public class DisconnectedGraphsLayoutCalculator : ILayoutCalculator { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 레이아웃 알고리즘 설정 - LayoutAlgorithmSettings /// <summary> /// 레이아웃 알고리즘 설정 /// </summary> public LayoutAlgorithmSettings LayoutAlgorithmSettings { get { return new SugiyamaLayoutSettings() { Transformation = PlaneTransformation.Rotation(Math.PI), EdgeRoutingSettings = { EdgeRoutingMode = EdgeRoutingMode.StraightLine } }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 레이아웃 계산하기 - CalculateLayout(geometryGraph) /// <summary> /// 레이아웃 계산하기 /// </summary> /// <param name="geometryGraph">기하 그래프</param> public void CalculateLayout(GeometryGraph geometryGraph) { IEnumerable<GeometryGraph> componentEnumerable = GraphConnectedComponents.CreateComponents ( geometryGraph.Nodes, geometryGraph.Edges ); SugiyamaLayoutSettings setting = LayoutAlgorithmSettings as SugiyamaLayoutSettings; foreach(GeometryGraph component in componentEnumerable) { LayeredLayout layout = new LayeredLayout(component, setting); component.Margins = 100; layout.Run(); } MdsGraphLayout.PackGraphs(componentEnumerable, setting); geometryGraph.UpdateBoundingBox(); } #endregion } } |
▶ MDSLayoutCalculator.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
using Microsoft.Msagl.Core.Layout; using Microsoft.Msagl.Core.Routing; using Microsoft.Msagl.Layout.MDS; using Microsoft.Msagl.Miscellaneous; namespace TestLibrary { public class MDSLayoutCalculator : ILayoutCalculator { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 레이아웃 알고리즘 설정 - LayoutAlgorithmSettings /// <summary> /// 레이아웃 알고리즘 설정 /// </summary> public LayoutAlgorithmSettings LayoutAlgorithmSettings { get { return new MdsLayoutSettings() { EdgeRoutingSettings = { EdgeRoutingMode = EdgeRoutingMode.StraightLine } }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 레이아웃 계산하기 - CalculateLayout(geometryGraph) /// <summary> /// 레이아웃 계산하기 /// </summary> /// <param name="geometryGraph">기하 그래프</param> public void CalculateLayout(GeometryGraph geometryGraph) { LayoutHelpers.CalculateLayout(geometryGraph, LayoutAlgorithmSettings, null); } #endregion } } |
▶ PhyloTreeLayoutCalculator.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
using System; using Microsoft.Msagl.Core.Geometry.Curves; using Microsoft.Msagl.Core.Layout; using Microsoft.Msagl.Core.Routing; using Microsoft.Msagl.Layout.Layered; using Microsoft.Msagl.Miscellaneous; namespace TestLibrary { /// <summary> /// PHYLO 트리 레이아웃 계산기 /// </summary> public class PhyloTreeLayoutCalculator : ILayoutCalculator { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 레이아웃 알고리즘 설정 - LayoutAlgorithmSettings /// <summary> /// 레이아웃 알고리즘 설정 /// </summary> public LayoutAlgorithmSettings LayoutAlgorithmSettings { get { return new SugiyamaLayoutSettings() { Transformation = PlaneTransformation.Rotation(Math.PI), EdgeRoutingSettings = { EdgeRoutingMode = EdgeRoutingMode.StraightLine } }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 레이아웃 계산하기 - CalculateLayout(geometryGraph) /// <summary> /// 레이아웃 계산하기 /// </summary> /// <param name="geometryGraph">기하 그래프</param> public void CalculateLayout(GeometryGraph phyloTree) { LayoutHelpers.CalculateLayout(phyloTree, LayoutAlgorithmSettings, null); } #endregion } } |
▶ RankingLayoutCalculator.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
using System.Collections.Generic; using Microsoft.Msagl.Core.Layout; using Microsoft.Msagl.Core.Routing; using Microsoft.Msagl.Layout.MDS; using Microsoft.Msagl.Prototype.Ranking; namespace TestLibrary { /// <summary> /// 랭킹 레이아웃 계산기 /// </summary> public class RankingLayoutCalculator : ILayoutCalculator { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 레이아웃 알고리즘 설정 - LayoutAlgorithmSettings /// <summary> /// 레이아웃 알고리즘 설정 /// </summary> public LayoutAlgorithmSettings LayoutAlgorithmSettings { get { return new RankingLayoutSettings() { NodeSeparation = 30, EdgeRoutingSettings = { EdgeRoutingMode = EdgeRoutingMode.Rectilinear } }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 레이아웃 계산하기 - CalculateLayout(geometryGraph) /// <summary> /// 레이아웃 계산하기 /// </summary> /// <param name="geometryGraph">기하 그래프</param> public void CalculateLayout(GeometryGraph geometryGraph) { IEnumerable<GeometryGraph> componentEnumerable = GraphConnectedComponents.CreateComponents ( geometryGraph.Nodes, geometryGraph.Edges ); RankingLayoutSettings setting = LayoutAlgorithmSettings as RankingLayoutSettings; foreach(GeometryGraph component in componentEnumerable) { RankingLayout layout = new RankingLayout(setting, component); component.Margins = 30; layout.Run(); } MdsGraphLayout.PackGraphs(componentEnumerable, setting); geometryGraph.UpdateBoundingBox(); } #endregion } } |
▶ SugiyamaLayoutCalculator.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
using System; using Microsoft.Msagl.Core.Geometry.Curves; using Microsoft.Msagl.Core.Layout; using Microsoft.Msagl.Core.Routing; using Microsoft.Msagl.Layout.Layered; using Microsoft.Msagl.Miscellaneous; namespace TestLibrary { /// <summary> /// SUGIYAMA 레이아웃 계산기 /// </summary> public class SugiyamaLayoutCalculator : ILayoutCalculator { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 레이아웃 알고리즘 설정 - LayoutAlgorithmSettings /// <summary> /// 레이아웃 알고리즘 설정 /// </summary> public LayoutAlgorithmSettings LayoutAlgorithmSettings { get { return new SugiyamaLayoutSettings() { NodeSeparation = 30, Transformation = PlaneTransformation.Rotation(Math.PI / 2), EdgeRoutingSettings = { EdgeRoutingMode = EdgeRoutingMode.SugiyamaSplines } }; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 레이아웃 계산하기 - CalculateLayout(geometryGraph) /// <summary> /// 레이아웃 계산하기 /// </summary> /// <param name="geometryGraph">기하 그래프</param> public void CalculateLayout(GeometryGraph geometryGraph) { LayoutHelpers.CalculateLayout( geometryGraph, LayoutAlgorithmSettings, null); } #endregion } } |
▶ Converter.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
using System.Windows; using MSAGLPoint = Microsoft.Msagl.Core.Geometry.Point; namespace TestLibrary { /// <summary> /// 변환기 /// </summary> public static class Converter { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 포인트 구하기 - GetPoint(msaglPoint) /// <summary> /// 포인트 구하기 /// </summary> /// <param name="msaglPoint">MSAGL 포인트</param> /// <returns>포인트</returns> public static Point GetPoint(this MSAGLPoint msaglPoint) { return new Point(msaglPoint.X, msaglPoint.Y); } #endregion } } |
▶ MSAGLGeometryGraphHelper.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
using System.Linq; using System.Collections.Generic; using Microsoft.Msagl.Core.Geometry; using Microsoft.Msagl.Core.Geometry.Curves; using Microsoft.Msagl.Core.Layout; using Microsoft.Msagl.Prototype.Phylo; using DevExpress.Diagram.Core; using DevExpress.Diagram.Core.Layout; namespace TestLibrary { /// <summary> /// MSAGL 기하 그래프 헬퍼 /// </summary> public static class MSAGLGeometryGraphHelper { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 노드 위치 정보 구하기 - GetNodePositionInfo(geometryGraph) /// <summary> /// 노드 위치 정보 구하기 /// </summary> /// <param name="geometryGraph">기하 그래프</param> /// <returns>노드 위치 정보</returns> public static IEnumerable<PositionInfo<IDiagramItem>> GetNodePositionInfo(GeometryGraph geometryGraph) { return geometryGraph.Nodes.Select ( node => new PositionInfo<IDiagramItem> ( (IDiagramItem)node.UserData, Converter.GetPoint(node.BoundingBox.LeftTop) ) ); } #endregion #region PHYLO 트리 구하기 - GetPhyloTree(graph) /// <summary> /// PHYLO 트리 구하기 /// </summary> /// <param name="graph">그래프</param> /// <returns>PHYLO 트리</returns> public static PhyloTree GetPhyloTree(Graph<IDiagramItem> graph) { PhyloTree phyloTree = new PhyloTree(); foreach(IDiagramItem node in graph.Nodes) { AddNode(phyloTree, node); } foreach(Edge<IDiagramItem> edge in graph.Edges) { AddPhyloTreeEdge(phyloTree, edge.From, edge.To, edge.Weight); } return phyloTree; } #endregion #region 기하 그래프 구하기 - GetGeometryGraph(graph) /// <summary> /// 기하 그래프 구하기 /// </summary> /// <param name="graph">그래프</param> /// <returns>기하 그래프</returns> public static GeometryGraph GetGeometryGraph(Graph<IDiagramItem> graph) { GeometryGraph geometryGraph = new GeometryGraph(); foreach(IDiagramItem node in graph.Nodes) { AddNode(geometryGraph, node); } foreach(Edge<IDiagramItem> edge in graph.Edges) { AddEdge(geometryGraph, edge.From, edge.To, edge.Weight); } return geometryGraph; } #endregion #region 노드 추가하기 - AddNode(geometryGraph, item) /// <summary> /// 노드 추가하기 /// </summary> /// <param name="geometryGraph">기하 그래프</param> /// <param name="item">항목</param> /// <returns>노드</returns> public static Node AddNode(GeometryGraph geometryGraph, IDiagramItem item) { Node node = geometryGraph.FindNodeByUserData(item); if(node == null) { node = new Node(GetCurve(item), item); geometryGraph.Nodes.Add(node); } return node; } #endregion #region 에지 추가하기 - AddEdge(geometryGraph, parentNode, childNode, weight) /// <summary> /// 에지 추가하기 /// </summary> /// <param name="geometryGraph">기하 그래프</param> /// <param name="parentNode">부모 노드</param> /// <param name="childNode">자식 노드</param> /// <param name="weight">가중치</param> public static void AddEdge(GeometryGraph geometryGraph, IDiagramItem parentNode, IDiagramItem childNode, double weight) { Edge edge = new Edge ( AddNode(geometryGraph, parentNode), AddNode(geometryGraph, childNode ) ); edge.Weight = (int)weight; geometryGraph.Edges.Add(edge); } #endregion #region PHYLO 트리 에지 추가하기 - AddPhyloTreeEdge(phyloTree, parentNode, childNode, weight) /// <summary> /// PHYLO 트리 에지 추가하기 /// </summary> /// <param name="phyloTree">PHYLO 트리</param> /// <param name="parentNode">부모 노드</param> /// <param name="childNode">자식 노드</param> /// <param name="weight">가중치</param> public static void AddPhyloTreeEdge(PhyloTree phyloTree, IDiagramItem parentNode, IDiagramItem childNode, double weight = 1) { PhyloEdge edge = new PhyloEdge ( AddNode(phyloTree, parentNode), AddNode(phyloTree, childNode ) ); edge.Weight = (int)weight; phyloTree.Edges.Add(edge); } #endregion #region 커브 구하기 - GetCurve(item) /// <summary> /// 커브 구하기 /// </summary> /// <param name="item">항목</param> /// <returns>커브</returns> public static ICurve GetCurve(IDiagramItem item) { return CurveFactory.CreateRectangle(item.ActualSize.Width, item.ActualSize.Height, new Point()); } #endregion } } |
▶ RoutingHelper.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
using Microsoft.Msagl.Core.Routing; using DevExpress.Diagram.Core; namespace TestLibrary { /// <summary> /// 라우팅 헬퍼 /// </summary> public static class RoutingHelper { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 다이어그램 커넥터 타입 구하기 - GetDiagramConnectorType(routingMode) /// <summary> /// 다이어그램 커넥터 타입 구하기 /// </summary> /// <param name="routingMode">라우팅 모드</param> /// <returns>다이어그램 커넥터 타입</returns> public static ConnectorType GetDiagramConnectorType(EdgeRoutingMode routingMode) { if(routingMode == EdgeRoutingMode.StraightLine) { return ConnectorType.Straight; } else if ( routingMode == EdgeRoutingMode.Spline || routingMode == EdgeRoutingMode.SplineBundling || routingMode == EdgeRoutingMode.SugiyamaSplines ) { return ConnectorType.Curved; } else { return ConnectorType.RightAngle; } } #endregion } } |
[TestProject 프로젝트]
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
using System; using System.Linq; using System.Windows.Forms; using DevExpress.Diagram.Core; using DevExpress.Diagram.Core.Layout; using DevExpress.XtraBars; using DevExpress.XtraEditors; using TestLibrary; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.loadSugiyamaLayoutBarButtonItem.ItemClick += loadSugiyamaLayoutBarButtonItem_ItemClick; this.applySugiyamaLayoutBarButtonItem.ItemClick += applySugiyamaLayoutBarButtonItem_ItemClick; this.loadDisconnectedGraphLayoutBarButtonItem.ItemClick += loadDisconnectedGraphLayoutBarButtonItem_ItemClick; this.applyDisconnectedGraphLayoutBarButtonItem.ItemClick += applyDisconnectedGraphLayoutBarButtonItem_ItemClick; this.loadPhyloTreeLayoutBarButtonItem.ItemClick += loadPhyloTreeLayoutBarButtonItem_ItemClick; this.applyPhyloTreeLayoutBarButtonItem.ItemClick += applyPhyloTreeLayoutBarButtonItem_ItemClick; this.loadRankingLayoutBarButtonItem.ItemClick += loadRankingLayoutBarButtonItem_ItemClick; this.applyRankingLayoutBarButtonItem.ItemClick += applyRankingLayoutBarButtonItem_ItemClick; this.loadMDSLayoutBarButtonItem.ItemClick += loadMDSLayoutBarButtonItem_ItemClick; this.applyMDSLayoutBarButtonItem.ItemClick += applyMDSLayoutBarButtonItem_ItemClick; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region SUGIYAMA 레이아웃 로드 BAR 버튼 항목 클릭시 처리하기 - loadSugiyamaLayoutBarButtonItem_ItemClick(sender, e) /// <summary> /// SUGIYAMA 레이아웃 로드 BAR 버튼 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void loadSugiyamaLayoutBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) { this.diagramControl.LoadDocument("DATA/SugiyamaLayout.xml"); } #endregion #region SUGIYAMA 레이아웃 적용 BAR 버튼 항목 클릭시 처리하기 - applySugiyamaLayoutBarButtonItem_ItemClick(sender, e) /// <summary> /// SUGIYAMA 레이아웃 적용 BAR 버튼 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void applySugiyamaLayoutBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) { ApplyLayout(new GraphLayout(new SugiyamaLayoutCalculator())); } #endregion #region 비연결 그래프 레이아웃 로드 BAR 버튼 항목 클릭시 처리하기 - loadDisconnectedGraphLayoutBarButtonItem_ItemClick(sender, e) /// <summary> /// 비연결 그래프 레이아웃 로드 BAR 버튼 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void loadDisconnectedGraphLayoutBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) { this.diagramControl.LoadDocument("DATA/DisconnectedGraphLayout.xml"); } #endregion #region 비연결 그래프 레이아웃 적용 BAR 버튼 항목 클릭시 처리하기 - applyDisconnectedGraphLayoutBarButtonItem_ItemClick(sender, e) /// <summary> /// 비연결 그래프 레이아웃 적용 BAR 버튼 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void applyDisconnectedGraphLayoutBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) { ApplyLayout(new GraphLayout(new DisconnectedGraphsLayoutCalculator())); } #endregion #region PHYLO 트리 레이아웃 로드 BAR 버튼 항목 클릭시 처리하기 - loadPhyloTreeLayoutBarButtonItem_ItemClick(sender, e) /// <summary> /// PHYLO 트리 레이아웃 로드 BAR 버튼 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void loadPhyloTreeLayoutBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) { this.diagramControl.LoadDocument("DATA/PhyloTreeLayout.xml"); } #endregion #region PHYLO 트리 레이아웃 적용 BAR 버튼 항목 클릭시 처리하기 - applyPhyloTreeLayoutBarButtonItem_ItemClick(sender, e) /// <summary> /// PHYLO 트리 레이아웃 적용 BAR 버튼 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void applyPhyloTreeLayoutBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) { ApplyLayout(new PhyloTreeLayout(new PhyloTreeLayoutCalculator())); } #endregion #region 랭킹 레이아웃 로드 BAR 버튼 항목 클릭시 처리하기 - loadRankingLayoutBarButtonItem_ItemClick(sender, e) /// <summary> /// 랭킹 레이아웃 로드 BAR 버튼 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void loadRankingLayoutBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) { this.diagramControl.LoadDocument("DATA/RankingLayout.xml"); } #endregion #region 랭킹 레이아웃 적용 BAR 버튼 항목 클릭시 처리하기 - applyRankingLayoutBarButtonItem_ItemClick(sender, e) /// <summary> /// 랭킹 레이아웃 적용 BAR 버튼 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void applyRankingLayoutBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) { ApplyLayout(new GraphLayout(new RankingLayoutCalculator())); } #endregion #region MDS 레이아웃 로드 BAR 버튼 항목 클릭시 처리하기 - loadMDSLayoutBarButtonItem_ItemClick(sender, e) /// <summary> /// MDS 레이아웃 로드 BAR 버튼 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void loadMDSLayoutBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) { this.diagramControl.LoadDocument("DATA/MDSLayout.xml"); } #endregion #region MSD 레이아웃 적용 BAR 버튼 항목 클릭시 처리하기 - applyMDSLayoutBarButtonItem_ItemClick(sender, e) /// <summary> /// MSD 레이아웃 적용 BAR 버튼 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void applyMDSLayoutBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) { ApplyLayout(new GraphLayout(new MDSLayoutCalculator())); } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 레이아웃 적용하기 - ApplyLayout(layout) /// <summary> /// 레이아웃 적용하기 /// </summary> /// <param name="layout">레이아웃</param> private void ApplyLayout(GraphLayout layout) { try { this.diagramControl.RelayoutDiagramItems ( layout.RelayoutGraphNodePosition(GraphOperations.GetDiagramGraph(diagramControl)) ); foreach(IDiagramConnector connector in this.diagramControl.Items.OfType<IDiagramConnector>()) { connector.Type = layout.GetDiagramConnectorType(); connector.UpdateRoute(); }; diagramControl.FitToDrawing(); } catch(Exception exception) { XtraMessageBox.Show ( this, string.Format("에러 메시지 : '{0}'", exception.Message), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error ); } } #endregion } } |