첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestSolution.zip
다운로드

[TestLibrary 프로젝트]

▶ GraphLayout.cs

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
    }
}

 

728x90

 

▶ PhyloTreeLayout.cs

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
    }
}

 

300x250

 

▶ ILayoutCalculator.cs

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

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

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

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

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

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

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

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

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

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
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요