Changeset 13135
- Timestamp:
- 11/11/15 13:53:10 (9 years ago)
- Location:
- branches/OptimizationNetworks
- Files:
-
- 7 added
- 7 deleted
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/ChartModes/AddNodesChartMode.cs
r13077 r13135 24 24 using System.Drawing.Drawing2D; 25 25 using System.Windows.Forms; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Common.Resources; 27 28 using HeuristicLab.Core.Networks; … … 36 37 37 38 public override Image Image { get { return VSImageLibrary.RadialChart; } } 38 public override string ToolTip { get { return "Add Nodes"; } } 39 public override string Text { get { return "Add &Nodes"; } } 40 public override string ToolTipText { get { return "Add Nodes"; } } 39 41 40 42 public AddNodesChartMode(ChartControl control) : base(control) { } 41 43 42 44 public override void HandleOnMouseMove(object sender, MouseEventArgs e) { 43 base.HandleOnMouseMove(sender, e); 45 try { 46 if (!(chartControl.Tag is IUserDefinedNetwork)) return; 44 47 45 if (!(chartControl.Tag is IUserDefinedNetwork)) return; 46 47 try { 48 chartControl.PictureBox.Refresh(); 48 chartControl.RefreshPicture(); 49 49 50 50 var size = new Size(200, 100); 51 using (var graphics = chartControl.PictureBox.CreateGraphics()) 51 52 using (var graphics = chartControl.CreatePictureGraphics()) 52 53 using (var pen = new Pen(Color.Gray) { DashStyle = DashStyle.Dash }) { 53 54 graphics.DrawRectangle(pen, … … 57 58 size.Height); 58 59 } 60 59 61 } finally { 60 chartControl.PictureBox.Update(); 62 chartControl.UpdatePicture(); 63 base.HandleOnMouseMove(sender, e); 61 64 } 62 65 } 63 66 64 public override void HandleOnMouseUp(object sender, MouseEventArgs e) { 65 base.HandleOnMouseUp(sender, e); 67 public override void HandleOnMouseDown(object sender, MouseEventArgs e) { 68 try { 69 switch (e.Button) { 70 case MouseButtons.Left: 71 var network = chartControl.Tag as IUserDefinedNetwork; 72 if (network == null) return; 66 73 67 switch (e.Button) { 68 case MouseButtons.Left: 69 var network = chartControl.Tag as IUserDefinedNetwork; 70 if (network == null) return; 74 var node = CreateNode(network); 75 if (node == null) return; 71 76 72 var node = CreateNode(network); 73 var visualizableNode = node as IVisualizableNode; 74 if (visualizableNode == null) return; 77 var center = chartControl.Chart.TransformPixelToWorld(e.Location); 78 var size = chartControl.Chart.TransformPixelToWorld(new Size(100, 50)); 79 var lowerLeft = center - new Offset(size); 80 var upperRight = center + new Offset(size); 81 node.VisualProperties = new NodeVisualProperties(new Point2D<double>(lowerLeft.X, lowerLeft.Y), 82 new Point2D<double>(upperRight.X, upperRight.Y)); 83 network.Nodes.Add(node); 84 break; 85 } 86 } finally { 87 base.HandleOnMouseDown(sender, e); 88 } 89 } 75 90 76 var center = chartControl.Chart.TransformPixelToWorld(e.Location); 77 var size = chartControl.Chart.TransformPixelToWorld(new Size(200, 100)); 78 79 visualizableNode.VisualProperties.X = center.X; 80 visualizableNode.VisualProperties.Y = center.Y; 81 visualizableNode.VisualProperties.Width = size.Width; 82 visualizableNode.VisualProperties.Height = size.Height; 83 84 network.Nodes.Add(node); 85 break; 86 } 91 public override void HandleOnMouseLeave(object sender, EventArgs e) { 92 chartControl.RefreshPicture(); 93 base.HandleOnMouseLeave(sender, e); 87 94 } 88 95 -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/ChartModes/AddPortsChartMode.cs
r13077 r13135 36 36 37 37 public override Image Image { get { return VSImageLibrary.Interface; } } 38 public override string ToolTip { get { return "Add Ports"; } } 38 public override string Text { get { return "Add Por&ts"; } } 39 public override string ToolTipText { get { return "Add Ports"; } } 39 40 40 41 public AddPortsChartMode(ChartControl control) : base(control) { } 41 42 42 43 public override void HandleOnMouseMove(object sender, MouseEventArgs e) { 43 base.HandleOnMouseMove(sender, e); 44 try { 45 if (!(chartControl.Tag is IUserDefinedNetwork)) return; 44 46 45 if (!(chartControl.Tag is IUserDefinedNetwork)) return; 46 47 try { 48 chartControl.PictureBox.Refresh(); 47 chartControl.RefreshPicture(); 49 48 50 49 var nodeRectangles = chartControl.Chart.GetAllPrimitives(e.Location).OfType<NodeRectangle>(); … … 56 55 var ur = chartControl.Chart.TransformWorldToPixel(nodeRectangle.UpperRight); 57 56 58 using (var graphics = chartControl.PictureBox.CreateGraphics()) 59 using (var pen = new Pen(Color.Green) { Width = 2f }) { 57 var node = nodeRectangle.NetworkItem; 58 bool nodeValid = node is IAlgorithmNode || node is IUserDefinedNode; 59 60 using (var graphics = chartControl.CreatePictureGraphics()) 61 using (var pen = new Pen(nodeValid ? Color.Green : Color.Red) { Width = 2f }) { 60 62 graphics.DrawRectangle(pen, 61 63 ll.X, … … 65 67 } 66 68 } finally { 67 chartControl.PictureBox.Update(); 69 chartControl.UpdatePicture(); 70 base.HandleOnMouseMove(sender, e); 68 71 } 69 72 } 70 73 71 public override void HandleOnMouseUp(object sender, MouseEventArgs e) { 72 base.HandleOnMouseUp(sender, e); 74 public override void HandleOnMouseDown(object sender, MouseEventArgs e) { 75 try { 76 switch (e.Button) { 77 case MouseButtons.Left: 78 if (!(chartControl.Tag is IUserDefinedNetwork)) return; 73 79 74 switch (e.Button) { 75 case MouseButtons.Left: 76 var network = chartControl.Tag as IUserDefinedNetwork; 77 if (network == null) return; 80 var nodeRectangles = chartControl.Chart.GetAllPrimitives(e.Location).OfType<NodeRectangle>(); 81 var nodeRectangle = nodeRectangles.FirstOrDefault(); 82 if (nodeRectangle == null) return; 78 83 79 var nodeRectangles = chartControl.Chart.GetAllPrimitives(e.Location).OfType<NodeRectangle>();80 var nodeRectangle = nodeRectangles.FirstOrDefault();81 if (nodeRectangle == null) return;84 var node = nodeRectangle.NetworkItem; 85 bool nodeValid = node is IAlgorithmNode || node is IUserDefinedNode; 86 if (!nodeValid) return; 82 87 83 var node = nodeRectangle.NetworkItem;84 var port = CreatePort(node);88 var port = CreatePort(node); 89 if (port == null) return; 85 90 86 var algNode = node as IAlgorithmNode;87 if (algNode != null) {88 algNode.Ports.Add(port);89 return;90 }91 var algNode = node as IAlgorithmNode; 92 if (algNode != null) { 93 algNode.Ports.Add(port); 94 return; 95 } 91 96 92 var userDefNode = node as IUserDefinedNode; 93 if (userDefNode != null) { 97 var userDefNode = (IUserDefinedNode)node; 94 98 userDefNode.Ports.Add(port); 95 return; 96 } 97 break; 99 break; 100 } 101 } finally { 102 base.HandleOnMouseDown(sender, e); 98 103 } 99 104 } -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/ChartModes/ConnectPortsChartMode.cs
r13077 r13135 35 35 36 36 public override Image Image { get { return VSImageLibrary.OrgChart; } } 37 public override string ToolTip { get { return "Connect Ports"; } } 37 public override string Text { get { return "&Connect Ports"; } } 38 public override string ToolTipText { get { return "Connect Ports"; } } 38 39 39 40 public ConnectPortsChartMode(ChartControl control) : base(control) { } 40 41 41 public override void HandleOnMouseDown(object sender, MouseEventArgs e) { 42 base.HandleOnMouseDown(sender, e); 42 public override void HandleOnMouseMove(object sender, MouseEventArgs e) { 43 try { 44 if (!(chartControl.Tag is IUserDefinedNetwork)) return; 43 45 44 if (!(chartControl.Tag is IUserDefinedNetwork)) return;46 chartControl.RefreshPicture(); 45 47 46 switch (e.Button) { 47 case MouseButtons.Left: 48 var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location); 49 var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>(); 50 var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortRectangle)); 51 startPortRectangle = portRectangles.FirstOrDefault(x => x.ContainsPoint(worldLocation)); 52 break; 48 var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location); 49 var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>(); 50 var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortPrimitive)); 51 var currentPortRectangle = (PortRectangle)portRectangles.FirstOrDefault(x => x.ContainsPoint(worldLocation)); 52 53 // TODO: highlight allowed port connections only 54 55 using (var graphics = chartControl.CreatePictureGraphics()) { 56 Point startLocation = Point.Empty; 57 if (startPortRectangle != null) { 58 DrawCircleAroundPortRectangle(graphics, startPortRectangle, startPortRectangle.NetworkItem is IConnectablePort); 59 startLocation = chartControl.Chart.TransformWorldToPixel(startPortRectangle.Point); 60 } 61 62 Point endLocation = e.Location; 63 if (currentPortRectangle != null && (startPortRectangle != null || e.Button == MouseButtons.None)) { 64 DrawCircleAroundPortRectangle(graphics, currentPortRectangle, currentPortRectangle.NetworkItem is IConnectablePort); 65 endLocation = chartControl.Chart.TransformWorldToPixel(currentPortRectangle.Point); 66 } 67 68 bool connectionValid = startPortRectangle != null && startPortRectangle.NetworkItem is IConnectablePort; 69 connectionValid &= currentPortRectangle == null || currentPortRectangle.NetworkItem is IConnectablePort; 70 71 if (startPortRectangle != null) 72 DrawLineBetweenLocations(graphics, startLocation, endLocation, connectionValid); 73 } 74 } finally { 75 chartControl.UpdatePicture(); 76 base.HandleOnMouseMove(sender, e); 53 77 } 54 78 } 55 79 56 public override void HandleOnMouseMove(object sender, MouseEventArgs e) { 57 base.HandleOnMouseMove(sender, e); 80 public override void HandleOnMouseDown(object sender, MouseEventArgs e) { 81 try { 82 var network = chartControl.Tag as IUserDefinedNetwork; 83 if (network == null) return; 58 84 59 if (!(chartControl.Tag is IUserDefinedNetwork)) return; 60 61 try { 62 chartControl.PictureBox.Refresh(); 63 64 var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location); 65 var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>(); 66 var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortRectangle)).ToList(); 67 var currentPortRectangle = portRectangles.FirstOrDefault(x => x.ContainsPoint(worldLocation)); 68 69 // TODO: highlight allowed port connections only 70 71 Point startLocation = Point.Empty; 72 if (startPortRectangle != null) { 73 DrawCircleAroundPortRectangle(startPortRectangle); 74 startLocation = chartControl.Chart.TransformWorldToPixel(startPortRectangle.Point); 85 switch (e.Button) { 86 case MouseButtons.Left: 87 var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location); 88 var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>(); 89 var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortPrimitive)); 90 startPortRectangle = (PortRectangle)portRectangles.FirstOrDefault(x => x.ContainsPoint(worldLocation)); 91 break; 75 92 } 76 77 Point endLocation = e.Location;78 if (currentPortRectangle != null) {79 DrawCircleAroundPortRectangle(currentPortRectangle);80 endLocation = chartControl.Chart.TransformWorldToPixel(currentPortRectangle.Point);81 }82 83 if (startPortRectangle != null)84 DrawLineBetweenLocations(startLocation, endLocation);85 93 } finally { 86 chartControl.PictureBox.Update();94 base.HandleOnMouseDown(sender, e); 87 95 } 88 96 } 89 97 90 98 public override void HandleOnMouseUp(object sender, MouseEventArgs e) { 91 base.HandleOnMouseUp(sender, e); 99 try { 100 var network = chartControl.Tag as IUserDefinedNetwork; 101 if (network == null) return; 92 102 93 if (!(chartControl.Tag is IUserDefinedNetwork)) return; 103 switch (e.Button) { 104 case MouseButtons.Left: 105 var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location); 106 var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>(); 107 var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortPrimitive)); 108 endPortRectangle = (PortRectangle)portRectangles.FirstOrDefault(x => x.ContainsPoint(worldLocation)); 94 109 95 switch (e.Button) { 96 case MouseButtons.Left: 97 var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location); 98 var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>(); 99 var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortRectangle)).ToList(); 100 endPortRectangle = portRectangles.FirstOrDefault(x => x.ContainsPoint(worldLocation)); 110 if (startPortRectangle == endPortRectangle || startPortRectangle == null || endPortRectangle == null) { 111 startPortRectangle = null; 112 endPortRectangle = null; 113 return; 114 } 101 115 102 if (startPortRectangle == endPortRectangle && startPortRectangle == null || endPortRectangle == null) { 116 var startPort = (IConnectablePort)startPortRectangle.NetworkItem; 117 var endPort = (IConnectablePort)endPortRectangle.NetworkItem; 118 119 // TODO: check if port connection is allowed 120 121 startPort.ConnectedPort = endPort; 122 103 123 startPortRectangle = null; 104 124 endPortRectangle = null; 105 return; 106 } 107 108 var startPort = (IConnectablePort)startPortRectangle.NetworkItem; 109 var endPort = (IConnectablePort)endPortRectangle.NetworkItem; 110 111 // TODO: check if port connection is allowed 112 113 startPort.ConnectedPort = endPort; 114 115 startPortRectangle = null; 116 endPortRectangle = null; 117 break; 125 break; 126 } 127 } finally { 128 base.HandleOnMouseUp(sender, e); 118 129 } 119 130 } 120 131 121 protected virtual void DrawCircleAroundPortRectangle(PortRectangle portRectangle) { 132 #region Helpers 133 protected virtual void DrawCircleAroundPortRectangle(Graphics graphics, PortRectangle portRectangle, bool valid) { 122 134 var centerP = chartControl.Chart.TransformWorldToPixel(portRectangle.Point); 123 135 int a = (int)Math.Round(portRectangle.Size.Width / 2.0 * Math.Sqrt(2)); 124 136 int b = (int)Math.Round(portRectangle.Size.Height / 2.0 * Math.Sqrt(2)); 125 137 126 using (var graphics = chartControl.PictureBox.CreateGraphics()) 127 using (var pen = new Pen(Color.Green) { Width = 2f }) { 138 using (var pen = new Pen(valid ? Color.Green : Color.Red) { Width = 2f }) { 128 139 graphics.DrawEllipse(pen, 129 140 centerP.X - a, … … 134 145 } 135 146 136 protected virtual void DrawLineBetweenLocations(Point startLocation, Point endLocation) { 137 using (var graphics = chartControl.PictureBox.CreateGraphics()) 138 using (var pen = new Pen(Color.Green) { DashStyle = DashStyle.Dash, Width = 2f }) 147 protected virtual void DrawLineBetweenLocations(Graphics graphics, Point startLocation, Point endLocation, bool valid) { 148 using (var pen = new Pen(valid ? Color.Green : Color.Red) { DashStyle = DashStyle.Dash, Width = 2f }) 139 149 graphics.DrawLine(pen, startLocation.X, startLocation.Y, endLocation.X, endLocation.Y); 140 150 } 151 #endregion 141 152 } 142 153 } -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/HeuristicLab.Networks.Views.NetworkVisualization.Views-3.3.csproj
r13077 r13135 120 120 <Compile Include="ChartModes\AddNodesChartMode.cs" /> 121 121 <Compile Include="ChartModes\AddPortsChartMode.cs" /> 122 <Compile Include="ChartModes\ NetworkSelectChartMode.cs" />122 <Compile Include="ChartModes\SelectChartMode.cs" /> 123 123 <Compile Include="ChartModes\ConnectPortsChartMode.cs" /> 124 124 <Compile Include="NetworkVisualizationView.cs"> -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/NetworkVisualizationView.cs
r13077 r13135 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using System.Linq; 23 24 using HeuristicLab.Collections; … … 28 29 using HeuristicLab.Networks.Views.NetworkVisualization.Views.ChartModes; 29 30 using HeuristicLab.Visualization; 31 using HeuristicLab.Visualization.ChartModes; 30 32 31 33 namespace HeuristicLab.Networks.Views.NetworkVisualization.Views { … … 34 36 [Content(typeof(INetwork), false)] 35 37 public partial class NetworkVisualizationView : NetworkItemView { 38 private Dictionary<string, IPrimitive> primitiveDict = new Dictionary<string, IPrimitive>(); 39 36 40 public new INetwork Content { 37 41 get { return (INetwork)base.Content; } … … 42 46 InitializeComponent(); 43 47 44 var initialMode = new NetworkSelectChartMode(chartControl);48 var initialMode = new SelectChartMode(chartControl); 45 49 chartControl.AddChartModes( 46 50 initialMode, 47 new MoveChartMode(chartControl), 51 new PanChartMode(chartControl), 52 new RulerChartMode(chartControl), 48 53 new ZoomInChartMode(chartControl), 49 54 new ZoomOutChartMode(chartControl), … … 81 86 } 82 87 83 private void UpdateContent() {84 if (Content == null) return;85 86 chartControl.Chart.Group.Clear();87 DrawNodes(Content.Nodes);88 ConnectNodes(Content.Nodes);89 }90 91 private void DrawNodes(IKeyedItemCollection<string, INode> nodes) {92 var chart = chartControl.Chart;93 94 foreach (var node in nodes.OfType<IVisualizableNode>()) {95 var nodeShape = new NodeRectangle(chart, node);96 chart.Group.Add(nodeShape);97 }98 }99 100 private void ConnectNodes(IKeyedItemCollection<string, INode> nodes) {101 var chart = chartControl.Chart;102 var nodeRectangles = chart.Group.Primitives.OfType<NodeRectangle>();103 var node2NodeShape = nodeRectangles.ToDictionary(k => k.NetworkItem.Name, v => v);104 105 foreach (var node in nodes) {106 var nodeShape = node2NodeShape[node.Name];107 foreach (var port in node.Ports.OfType<IConnectablePort>()) {108 var connectedPort = port.ConnectedPort as IConnectablePort;109 if (connectedPort == null) continue;110 111 var connectedNode = connectedPort.Parent;112 if (connectedNode == null) continue;113 114 var connectedShape = node2NodeShape[connectedNode.Name];115 var leftPortRectangle = nodeShape.GetPortRectangle(port);116 var rightPortRectangle = connectedShape.GetPortRectangle(connectedPort);117 118 var connectionShape = new ConnectionLine(chart, leftPortRectangle, rightPortRectangle);119 120 chart.Group.Add(connectionShape);121 }122 }123 }124 125 88 #region Event Handlers 126 89 #region Nodes Event Handlers … … 149 112 #endregion 150 113 #endregion 114 115 #region Helpers 116 private void UpdateContent() { 117 if (Content == null) return; 118 119 chartControl.SuspendRendering(); 120 try { 121 chartControl.Chart.Group.Clear(); 122 DrawNodes(Content.Nodes); 123 ConnectNodes(Content.Nodes); 124 } finally { 125 chartControl.ResumeRendering(); 126 } 127 } 128 129 private void DrawNodes(IKeyedItemCollection<string, INode> nodes) { 130 foreach (var node in nodes) { 131 var defaultPrimitive = PrimitiveAttribute.CreateDefaultPrimitive(node.GetType(), chartControl.Chart, node); 132 if (defaultPrimitive == null) continue; 133 chartControl.Chart.Group.Add(defaultPrimitive); 134 primitiveDict[node.Name] = defaultPrimitive; 135 } 136 } 137 138 private void ConnectNodes(IKeyedItemCollection<string, INode> nodes) { 139 var chart = chartControl.Chart; 140 foreach (var node in nodes) { 141 var nodeRectangle = primitiveDict[node.Name] as NodeRectangle; 142 if (nodeRectangle == null) continue; 143 144 foreach (var port in node.Ports.OfType<IConnectablePort>()) { 145 var connectedPort = port.ConnectedPort as IConnectablePort; 146 if (connectedPort == null) continue; 147 148 var connectedNode = connectedPort.Parent; 149 if (connectedNode == null) continue; 150 151 var connectedRectangle = primitiveDict[connectedNode.Name] as NodeRectangle; 152 if (connectedRectangle == null) continue; 153 154 var leftPortRectangle = (PortRectangle)nodeRectangle.GetPortPrimitive(port); 155 var rightPortRectangle = (PortRectangle)connectedRectangle.GetPortPrimitive(connectedPort); 156 157 var connectionShape = new ConnectionLine(chart, leftPortRectangle, rightPortRectangle); 158 159 chart.Group.Add(connectionShape); 160 } 161 } 162 } 163 #endregion 151 164 } 152 165 } -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/HeuristicLab.Networks.Views.NetworkVisualization-3.3.csproj
r13077 r13135 86 86 <Private>False</Private> 87 87 </Reference> 88 <Reference Include="HeuristicLab.Persistence-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 89 <Private>False</Private> 90 </Reference> 88 91 <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 89 92 <SpecificVersion>False</SpecificVersion> … … 98 101 <Reference Include="System.Core" /> 99 102 <Reference Include="System.Drawing" /> 100 <Reference Include="System.Windows.Forms" />101 <Reference Include="System.Xml.Linq" />102 <Reference Include="System.Data.DataSetExtensions" />103 <Reference Include="System.Data" />104 <Reference Include="System.Net.Http" />105 <Reference Include="System.Xml" />106 103 </ItemGroup> 107 104 <ItemGroup> 108 105 <Compile Include="Interfaces\INetworkItemPrimitive.cs" /> 106 <Compile Include="INodeVisualProperties.cs" /> 107 <Compile Include="IPortVisualProperties.cs" /> 108 <Compile Include="NodeVisualProperties.cs" /> 109 <Compile Include="Orientation.cs" /> 110 <Compile Include="PortVisualProperties.cs" /> 109 111 <Compile Include="Primitives\ConnectionLine.cs" /> 110 112 <Compile Include="Plugin.cs" /> … … 123 125 </ProjectReference> 124 126 </ItemGroup> 127 <ItemGroup /> 125 128 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 126 129 <PropertyGroup> -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/ConnectionLine.cs
r13077 r13135 59 59 protected virtual void RegisterPortRectangleEvents(PortRectangle portRectangle) { 60 60 portRectangle.RedrawRequired += PortRectangle_RedrawRequired; 61 portRectangle.NetworkItemChanged += PortRectangleNetworkItemChanged;62 if (portRectangle.NetworkItem != null) {63 var port = portRectangle.NetworkItem;64 port.NameChanged += Port_NameChanged;65 }66 61 } 67 62 68 63 protected virtual void DeregisterPortRectangleEvents(PortRectangle portRectangle) { 69 64 portRectangle.RedrawRequired -= PortRectangle_RedrawRequired; 70 portRectangle.NetworkItemChanged -= PortRectangleNetworkItemChanged;71 if (portRectangle.NetworkItem != null) {72 var port = portRectangle.NetworkItem;73 port.NameChanged -= Port_NameChanged;74 }75 65 } 76 66 … … 105 95 } 106 96 } 107 108 97 #endregion 109 98 … … 111 100 public event EventHandler StartPortRectangleChanged; 112 101 protected virtual void OnStartPortRectangleChanged() { 113 UpdateToolTip();114 102 var handler = StartPortRectangleChanged; 115 103 if (handler != null) handler(this, EventArgs.Empty); … … 118 106 public event EventHandler EndPortRectangleChanged; 119 107 protected virtual void OnEndPortRectangleChanged() { 120 UpdateToolTip();121 108 var handler = EndPortRectangleChanged; 122 109 if (handler != null) handler(this, EventArgs.Empty); … … 128 115 SetPosition(startPortRectangle.Point, endPortRectangle.Point); 129 116 } 130 131 private void PortRectangleNetworkItemChanged(object sender, EventArgs e) {132 UpdateToolTip();133 }134 135 private void Port_NameChanged(object sender, EventArgs e) {136 UpdateToolTip();137 }138 #endregion139 140 #region Helpers141 private void UpdateToolTip() {142 string startText = "null", endText = "null";143 144 if (startPortRectangle != null) {145 var startPort = startPortRectangle.NetworkItem;146 if (startPort != null) {147 startText = startPort.Name;148 var startNode = startPort.Parent;149 startText = (startNode != null ? startNode.Name : "null") + "." + startText;150 }151 }152 153 if (endPortRectangle != null) {154 var endPort = endPortRectangle.NetworkItem;155 if (endPort != null) {156 endText = endPort.Name;157 var endNode = endPort.Parent;158 endText = (endNode != null ? endNode.Name : "null") + "." + endText;159 }160 }161 162 ToolTipText = string.Format("[{0}] --> [{1}]", startText, endText);163 }164 117 #endregion 165 118 } -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/NodeRectangle.cs
r13077 r13135 23 23 using System.Collections.Generic; 24 24 using System.Drawing; 25 using System.Linq;25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core.Networks; 27 27 using HeuristicLab.Visualization; 28 28 29 29 namespace HeuristicLab.Networks.Views.NetworkVisualization { 30 public class NodeRectangle : Visualization.Rectangle, INetworkItemPrimitive<IVisualizableNode> {31 private readonly Dictionary<IPort, PortRectangle> port2PortRectangle = new Dictionary<IPort, PortRectangle>();32 33 protected IGroup portRectangles;30 [Primitive(typeof(INode), true)] 31 public class NodeRectangle : Visualization.Rectangle, INetworkItemPrimitive<INode> { 32 protected readonly Dictionary<IPort, IPrimitive> port2primitive = new Dictionary<IPort, IPrimitive>(); 33 protected readonly IGroup portRectangles; 34 34 35 35 protected bool IgnoreVisualPropertiesChanges { get; set; } 36 36 37 protected I VisualizableNode networkItem;38 public I VisualizableNode NetworkItem {37 protected INode networkItem; 38 public INode NetworkItem { 39 39 get { return networkItem; } 40 40 set { … … 43 43 networkItem = value; 44 44 if (networkItem != null) RegisterNetworkItemEvents(); 45 UpdateToolTip();46 45 LoadVisualProperties(); 47 46 OnNetworkItemChanged(); … … 49 48 } 50 49 51 public NodeRectangle(IChart chart, I VisualizableNode node)52 : base(chart, Point .Empty, Point.Empty) {50 public NodeRectangle(IChart chart, INode node) 51 : base(chart, PointD.Empty, PointD.Empty) { 53 52 NetworkItem = node; 54 53 55 54 portRectangles = new Group(chart); 56 55 foreach (var port in node.Ports) { 57 var port Rectangle = new PortRectangle(this, port);58 port2 PortRectangle.Add(port, portRectangle);59 portRectangles.Add(port Rectangle);56 var portPrimitive = PrimitiveAttribute.CreateDefaultPrimitive(port.GetType(), chart, port, node); // TODO: port.Parent != node 57 port2primitive.Add(port, portPrimitive); 58 portRectangles.Add(portPrimitive); 60 59 } 61 UpdatePortRectangles();62 60 portRectangles.RedrawRequired += (sender, args) => OnRedrawRequired(); 63 61 } 64 62 65 63 protected virtual void RegisterNetworkItemEvents() { 66 networkItem.NameChanged += NetworkItem NameChanged;64 networkItem.NameChanged += NetworkItem_NameChanged; 67 65 if (networkItem.VisualProperties != null) { 68 66 networkItem.VisualProperties.Changed += VisualProperties_Changed; … … 75 73 76 74 protected virtual void DeregisterNetworkItemEvents() { 77 networkItem.NameChanged -= NetworkItem NameChanged;75 networkItem.NameChanged -= NetworkItem_NameChanged; 78 76 if (networkItem.VisualProperties != null) { 79 77 networkItem.VisualProperties.Changed -= VisualProperties_Changed; … … 87 85 #region Overrides 88 86 public override void SetPosition(PointD lowerLeft, PointD upperRight) { 89 SuppressEvents = true; 90 try { 91 base.SetPosition(lowerLeft, upperRight); 92 SaveVisualProperties(); 93 UpdatePortRectangles(); 94 } finally { 95 SuppressEvents = false; 96 OnRedrawRequired(); 97 } 87 base.SetPosition(lowerLeft, upperRight); 88 SaveVisualProperties(); 98 89 } 99 90 … … 103 94 var p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height)); 104 95 105 using (var font = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25 * Chart.WorldToPixelRatio.Width))) { 106 graphics.DrawString(ToolTipText, font, Brushes.Black, p.X + 5, p.Y + 5); 96 if (networkItem != null) { 97 using (var font = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25 * Chart.WorldToPixelRatio.Width))) { 98 graphics.DrawString(networkItem.Name, font, Brushes.Black, p.X + 5, p.Y + 5); 99 } 107 100 } 108 101 … … 111 104 #endregion 112 105 113 public PortRectangle GetPortRectangle(IPort name) {114 PortRectangle portRectangle;115 port2 PortRectangle.TryGetValue(name, out portRectangle);116 return port Rectangle;106 public IPrimitive GetPortPrimitive(IPort name) { 107 IPrimitive portPrimitive; 108 port2primitive.TryGetValue(name, out portPrimitive); 109 return portPrimitive; 117 110 } 118 111 … … 126 119 127 120 #region Event Handlers 128 private void NetworkItemNameChanged(object sender, EventArgs e) {129 UpdateToolTip();130 }131 132 121 private void VisualProperties_Changed(object sender, EventArgs e) { 133 122 if (IgnoreVisualPropertiesChanges) return; 123 134 124 LoadVisualProperties(); 135 125 } 136 126 127 private void NetworkItem_NameChanged(object sender, EventArgs e) { OnRedrawRequired(); } 128 137 129 private void Ports_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 138 130 foreach (var port in e.Items) { 139 var portRectangle = new PortRectangle(this, port);140 port2 PortRectangle.Add(port, portRectangle);131 var portRectangle = PrimitiveAttribute.CreateDefaultPrimitive(port.GetType(), Chart, port, networkItem); 132 port2primitive.Add(port, portRectangle); 141 133 portRectangles.Add(portRectangle); 142 134 } 143 135 144 SuppressEvents = true; 145 try { 146 UpdatePortRectangles(); 147 } finally { 148 SuppressEvents = false; 149 OnRedrawRequired(); 150 } 136 OnRedrawRequired(); 151 137 } 152 138 153 139 private void Ports_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 154 140 foreach (var port in e.Items) { 155 var portRectangle = port2 PortRectangle[port];156 port2 PortRectangle.Remove(port);141 var portRectangle = port2primitive[port]; 142 port2primitive.Remove(port); 157 143 portRectangles.Remove(portRectangle); 158 144 } 159 145 160 UpdatePortRectangles();161 146 OnRedrawRequired(); 162 147 } … … 164 149 165 150 #region Helpers 166 private void UpdateToolTip() { 167 ToolTipText = networkItem.Name; 151 private INodeVisualProperties CreateDefaultVisualProperties() { 152 var offset = Chart.UpperRight - Chart.LowerLeft; 153 var center = new PointD(Chart.LowerLeft.X + offset.DX * 0.5, Chart.LowerLeft.Y + offset.DY * 0.5); 154 var size = Chart.TransformPixelToWorld(new Size(200, 100)); 155 var lowerLeft = center - new Offset(size.Width * 0.5, size.Height * 0.5); 156 var upperRight = center + new Offset(size.Width * 0.5, size.Height * 0.5); 157 return new NodeVisualProperties(new Point2D<double>(lowerLeft.X, lowerLeft.Y), new Point2D<double>(upperRight.X, upperRight.Y)); 168 158 } 169 159 170 160 private void LoadVisualProperties() { 171 var offset = Chart.UpperRight - Chart.LowerLeft; 172 var center = new PointD(Chart.LowerLeft.X + offset.DX * 0.5, Chart.LowerLeft.Y + offset.DY * 0.5); 173 var size = Chart.TransformPixelToWorld(new Size(200, 100)); 161 if (networkItem.VisualProperties == null) 162 networkItem.VisualProperties = CreateDefaultVisualProperties(); 174 163 175 bool vpAvailable = networkItem != null && networkItem.VisualProperties != null; 176 bool useDefaultLocation = !vpAvailable || double.IsNaN(networkItem.VisualProperties.X); 177 bool useDefaultSize = !vpAvailable || double.IsNaN(networkItem.VisualProperties.Width); 178 179 if (!useDefaultLocation) { 180 center.X = networkItem.VisualProperties.X; 181 center.Y = networkItem.VisualProperties.Y; 182 } 183 184 if (!useDefaultSize) { 185 size.Width = networkItem.VisualProperties.Width; 186 size.Height = networkItem.VisualProperties.Height; 187 } 188 189 var ll = new PointD(center.X - size.Width * 0.5, center.Y - size.Height * 0.5); 190 var ur = ll + new Offset(size.Width, size.Height); 191 192 SetPosition(ll, ur); 164 var vp = (INodeVisualProperties)networkItem.VisualProperties; 165 SetPosition(new PointD(vp.LowerLeft.X, vp.LowerLeft.Y), new PointD(vp.UpperRight.X, vp.UpperRight.Y)); 193 166 } 194 167 … … 196 169 if (networkItem == null) return; 197 170 198 var visualProperties = networkItem.VisualProperties; 199 var centerW = new PointD(LowerLeft.X + Size.Width * 0.5, UpperRight.Y - Size.Height * 0.5); 171 var vp = (INodeVisualProperties)networkItem.VisualProperties; 200 172 201 173 IgnoreVisualPropertiesChanges = true; 202 174 try { 203 visualProperties.X = centerW.X; 204 visualProperties.Y = centerW.Y; 205 visualProperties.Width = Size.Width; 206 visualProperties.Height = Size.Height; 175 vp.LowerLeft = new Point2D<double>(LowerLeft.X, LowerLeft.Y); 176 vp.UpperRight = new Point2D<double>(UpperRight.X, UpperRight.Y); 207 177 } finally { IgnoreVisualPropertiesChanges = false; } 208 209 OnRedrawRequired();210 }211 212 private void UpdatePortRectangles() {213 if (portRectangles == null) return;214 215 var rectangles = portRectangles.OfType<PortRectangle>().ToArray();216 double space = Size.Width / (rectangles.Length + 1);217 for (int i = 0; i < rectangles.Length; i++) {218 double dx = Math.Round(space * (i + 1));219 var point = LowerLeft + new Offset(dx, 0);220 rectangles[i].SetPosition(point);221 }222 178 } 223 179 #endregion -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/PortRectangle.cs
r13077 r13135 22 22 using System; 23 23 using System.Drawing; 24 using System.Drawing.Drawing2D; 24 25 using System.Linq; 26 using HeuristicLab.Common; 25 27 using HeuristicLab.Core.Networks; 26 28 using HeuristicLab.Visualization; 27 29 28 30 namespace HeuristicLab.Networks.Views.NetworkVisualization { 31 [Primitive(typeof(IPort), true)] 29 32 public class PortRectangle : FixedSizeRectangle, INetworkItemPrimitive<IPort> { 30 33 private const int size = 10; 34 35 protected readonly INodeVisualProperties nodeVisualProperties; 36 37 protected bool IgnoreVisualPropertiesChanges { get; set; } 31 38 32 39 public override Size Size { … … 45 52 networkItem = value; 46 53 if (networkItem != null) RegisterNetworkItemEvents(); 54 LoadVisualProperties(); 47 55 OnNetworkItemChanged(); 48 56 } 49 57 } 50 58 51 public PortRectangle(NodeRectangle nodeRectangle, IPort port) 52 : base(nodeRectangle.Chart, PointD.Empty, Size.Empty, Pens.Black, Brushes.Red) { 59 public PortRectangle(IChart chart, IPort port, INode node) 60 : base(chart, PointD.Empty, Size.Empty, Pens.Black, Brushes.Red) { 61 nodeVisualProperties = (INodeVisualProperties)node.VisualProperties; 62 nodeVisualProperties.Changed += NodeVisualProperties_Changed; 53 63 NetworkItem = port; 54 64 } 55 65 56 66 protected virtual void RegisterNetworkItemEvents() { 57 networkItem.NameChanged += NetworkItemNameChanged; 67 networkItem.NameChanged += NetworkItem_NameChanged; 68 if (networkItem.VisualProperties != null) { 69 networkItem.VisualProperties.Changed += VisualProperties_Changed; 70 } 58 71 var connectablePort = networkItem as IConnectablePort; 59 72 if (connectablePort != null) { … … 63 76 64 77 protected virtual void DeregisterNetworkItemEvents() { 65 networkItem.NameChanged -= NetworkItemNameChanged; 78 networkItem.NameChanged -= NetworkItem_NameChanged; 79 if (networkItem.VisualProperties != null) { 80 networkItem.VisualProperties.Changed -= VisualProperties_Changed; 81 } 66 82 var connectablePort = networkItem as IConnectablePort; 67 83 if (connectablePort != null) { … … 70 86 } 71 87 88 #region Overrides 89 public override void SetPosition(PointD point) { 90 base.SetPosition(point); 91 SaveVisualProperties(); 92 } 93 94 public override void Draw(Graphics graphics) { 95 base.Draw(graphics); 96 97 var p = Chart.TransformWorldToPixel(Point); 98 99 if (networkItem != null && networkItem.VisualProperties != null) { 100 using (var font = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25 * Chart.WorldToPixelRatio.Width))) { 101 var textSize = graphics.MeasureString(networkItem.Name, font); 102 var vp = (IPortVisualProperties)networkItem.VisualProperties; 103 switch (vp.Orientation) { 104 case Orientation.North: p = new Point((int)(p.X - textSize.Width / 2), (int)(p.Y - Size.Height - textSize.Height)); break; 105 case Orientation.East: p = new Point(p.X + Size.Width, (int)(p.Y - textSize.Height / 2)); break; 106 case Orientation.South: p = new Point((int)(p.X - textSize.Width / 2), p.Y + Size.Height); break; 107 case Orientation.West: p = new Point((int)(p.X - Size.Width - textSize.Width), (int)(p.Y - textSize.Height / 2)); break; 108 } 109 110 graphics.DrawString(networkItem.Name, font, Brushes.Black, p); 111 } 112 } 113 } 114 115 public override void PostDraw(Graphics graphics) { 116 base.PostDraw(graphics); 117 118 if (Selected) { 119 var p = Chart.TransformWorldToPixel(Point); 120 using (var pen = new Pen(Color.LightGray, 3) { DashStyle = DashStyle.Dash }) 121 graphics.DrawRectangle(pen, p.X - Size.Width / 2, p.Y - Size.Height / 2, Size.Width, Size.Height); 122 } 123 } 124 125 #endregion 126 72 127 #region Events 128 73 129 public event EventHandler NetworkItemChanged; 130 74 131 protected virtual void OnNetworkItemChanged() { 75 UpdateToolTip();76 132 var handler = NetworkItemChanged; 77 133 if (handler != null) handler(this, EventArgs.Empty); 78 134 } 79 135 80 public event EventHandler NodeRectangleChanged;81 protected virtual void OnNodeRectangleChanged() {82 var handler = NodeRectangleChanged;83 if (handler != null) handler(this, EventArgs.Empty);84 }85 136 #endregion 86 137 87 138 #region Event Handlers 88 private void NetworkItemNameChanged(object sender, EventArgs e) { 89 UpdateToolTip(); 139 140 private void NodeVisualProperties_Changed(object sender, EventArgs e) { 141 if (IgnoreVisualPropertiesChanges) return; 142 143 LoadVisualProperties(); 144 } 145 146 private void VisualProperties_Changed(object sender, EventArgs e) { 147 if (IgnoreVisualPropertiesChanges) return; 148 149 LoadVisualProperties(); 150 } 151 152 private void NetworkItem_NameChanged(object sender, EventArgs e) { 153 OnRedrawRequired(); 90 154 } 91 155 92 156 private void Port_ConnectedPortChanged(object sender, EventArgs e) { 93 var connectablePort = (IConnectablePort)networkItem;94 95 157 var connectionLines = Chart.Group.GetAllPrimitives(Point).OfType<ConnectionLine>(); 96 158 var outgoingLines = connectionLines.Where(x => x.StartPortRectangle == this); 97 98 foreach (var l in outgoingLines) 99 Chart.Group.Remove(l); 100 159 foreach (var l in outgoingLines) Chart.Group.Remove(l); 160 161 var connectablePort = (IConnectablePort)networkItem; 101 162 var connectedPort = connectablePort.ConnectedPort as IConnectablePort; 102 163 if (connectedPort == null) return; 103 104 var connectedNode = connectedPort.Parent;105 if (connectedNode == null) return;106 164 107 165 var nodeRectangles = Chart.Group.Primitives.OfType<NodeRectangle>(); 108 166 PortRectangle endPortRectangle = null; 109 167 foreach (var nodeRectangle in nodeRectangles) { 110 endPortRectangle = nodeRectangle.GetPortRectangle(connectedPort);168 endPortRectangle = (PortRectangle)nodeRectangle.GetPortPrimitive(connectedPort); 111 169 if (endPortRectangle != null) break; 112 170 } … … 116 174 var connectionShape = new ConnectionLine(Chart, this, endPortRectangle); 117 175 Chart.Group.Add(connectionShape); 118 119 } 176 } 177 120 178 #endregion 121 179 122 180 #region Helpers 123 private void UpdateToolTip() { 124 ToolTipText = networkItem.Name; 125 } 181 182 private IPortVisualProperties CreateDefaultVisualProperties() { 183 return new PortVisualProperties(Orientation.South, 0.5); 184 } 185 186 private void LoadVisualProperties() { 187 if (networkItem.VisualProperties == null) 188 networkItem.VisualProperties = CreateDefaultVisualProperties(); 189 190 var vp = (IPortVisualProperties)networkItem.VisualProperties; 191 var p = PointD.Empty; 192 double nodeWidth = nodeVisualProperties.UpperRight.X - nodeVisualProperties.LowerLeft.X; 193 double nodeHeight = nodeVisualProperties.UpperRight.Y - nodeVisualProperties.LowerLeft.Y; 194 195 switch (vp.Orientation) { 196 case Orientation.North: 197 p.X = nodeVisualProperties.LowerLeft.X + vp.Offset * nodeWidth; 198 p.Y = nodeVisualProperties.UpperRight.Y; 199 break; 200 case Orientation.East: 201 p.X = nodeVisualProperties.UpperRight.X; 202 p.Y = nodeVisualProperties.UpperRight.Y - vp.Offset * nodeHeight; 203 break; 204 case Orientation.South: 205 p.X = nodeVisualProperties.UpperRight.X - vp.Offset * nodeWidth; 206 p.Y = nodeVisualProperties.LowerLeft.Y; 207 break; 208 case Orientation.West: 209 p.X = nodeVisualProperties.LowerLeft.X; 210 p.Y = nodeVisualProperties.LowerLeft.Y + vp.Offset * nodeHeight; 211 break; 212 } 213 214 SetPosition(p); 215 } 216 217 private void SaveVisualProperties() { 218 if (networkItem == null) return; 219 220 var vp = (IPortVisualProperties)networkItem.VisualProperties; 221 222 IgnoreVisualPropertiesChanges = true; 223 try { 224 var lowerLeft = nodeVisualProperties.LowerLeft; 225 var upperRight = nodeVisualProperties.UpperRight; 226 227 if (lowerLeft.X <= Point.X && Point.X <= upperRight.X) { 228 // check N/S 229 if (Point.Y.IsAlmost(upperRight.Y)) { 230 vp.Orientation = Orientation.North; 231 vp.Offset = (Point.X - lowerLeft.X) / (upperRight.X - lowerLeft.X); 232 } else if (Point.Y.IsAlmost(lowerLeft.Y)) { 233 vp.Orientation = Orientation.South; 234 vp.Offset = (upperRight.X - Point.X) / (upperRight.X - lowerLeft.X); 235 } 236 } 237 if (lowerLeft.Y <= Point.Y && Point.Y <= upperRight.Y) { 238 // check E/W 239 if (Point.X.IsAlmost(upperRight.X)) { 240 vp.Orientation = Orientation.East; 241 vp.Offset = (upperRight.Y - Point.Y) / (upperRight.Y - lowerLeft.Y); 242 } else if (Point.X.IsAlmost(lowerLeft.X)) { 243 vp.Orientation = Orientation.West; 244 vp.Offset = (Point.Y - lowerLeft.Y) / (upperRight.Y - lowerLeft.Y); 245 } 246 } 247 } finally { 248 IgnoreVisualPropertiesChanges = false; 249 } 250 } 251 126 252 #endregion 127 253 } -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Core/INetworkItem.cs
r13077 r13135 23 23 24 24 namespace HeuristicLab.Core.Networks { 25 public interface INetworkItem : INamedItem {25 public interface INetworkItem : INamedItem, IVisualizable { 26 26 INetworkItem Parent { get; } 27 27 IEnumerable<INetworkItem> Children { get; } -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Core/IVisualProperties.cs
r13077 r13135 21 21 22 22 using System; 23 using HeuristicLab.Common; 23 24 24 25 namespace HeuristicLab.Core.Networks { 25 public interface IVisualProperties {26 public interface IVisualProperties : IDeepCloneable { 26 27 event EventHandler Changed; 27 28 } -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Core/NetworkItem.cs
r13077 r13135 47 47 } 48 48 49 [Storable] 50 public IVisualProperties VisualProperties { get; set; } 51 49 52 [StorableConstructor] 50 53 protected NetworkItem(bool deserializing) : base(deserializing) { } 51 protected NetworkItem(NetworkItem original, Cloner cloner) : base(original, cloner) { } 54 protected NetworkItem(NetworkItem original, Cloner cloner) : base(original, cloner) { 55 VisualProperties = cloner.Clone(original.VisualProperties); 56 } 52 57 protected NetworkItem() : base("NetworkItem") { } 53 58 protected NetworkItem(string name) : base(name) { } -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Core/Node.cs
r13077 r13135 29 29 [Item("Node", "Abstract base class for nodes of a network.")] 30 30 [StorableClass] 31 public abstract class Node : NetworkItem, I VisualizableNode {31 public abstract class Node : NetworkItem, INode { 32 32 public static new Image StaticItemImage { 33 33 get { return HeuristicLab.Common.Resources.VSImageLibrary.RadialChart; } … … 55 55 if (readOnlyPorts == null) readOnlyPorts = ports.AsReadOnly(); 56 56 return readOnlyPorts; 57 }58 }59 60 public string VisualName { get { return Name; } }61 62 [Storable]63 private INodeVisualProperties visualProperties;64 public INodeVisualProperties VisualProperties {65 get {66 if (visualProperties == null)67 visualProperties = new NodeVisualProperties();68 return visualProperties;69 57 } 70 58 } -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Core/Port.cs
r13077 r13135 27 27 [Item("Port", "Abstract base class for ports of network nodes.")] 28 28 [StorableClass] 29 public abstract class Port : NetworkItem, I VisualizablePort {29 public abstract class Port : NetworkItem, IPort { 30 30 public static new Image StaticItemImage { 31 31 get { return HeuristicLab.Common.Resources.VSImageLibrary.Interface; } … … 40 40 } 41 41 42 [Storable]43 private IPortVisualProperties visualProperties;44 public IPortVisualProperties VisualProperties {45 get {46 if (visualProperties == null)47 visualProperties = new PortVisualProperties();48 return visualProperties;49 }50 }51 52 42 [StorableConstructor] 53 43 protected Port(bool deserializing) : base(deserializing) { } -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Core/VisualProperties.cs
r13077 r13135 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using HeuristicLab.Common; 3 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 5 26 namespace HeuristicLab.Core.Networks { 6 27 [StorableClass] 7 public class VisualProperties : DeepCloneable, IVisualProperties {28 public abstract class VisualProperties : DeepCloneable, IVisualProperties { 8 29 #region Constructors & Cloning 9 30 [StorableConstructor] 10 31 protected VisualProperties(bool deserializing) : base() { } 11 protected VisualProperties(VisualProperties original, Cloner cloner) 12 : base(original, cloner) { } 32 protected VisualProperties(VisualProperties original, Cloner cloner) : base(original, cloner) { } 13 33 14 public VisualProperties() { } 15 16 public override IDeepCloneable Clone(Cloner cloner) { 17 return new VisualProperties(this, cloner); 18 } 34 protected VisualProperties() { } 19 35 #endregion 20 36 -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/HeuristicLab.Networks-3.3.csproj
r13077 r13135 203 203 </Compile> 204 204 <Compile Include="ConfigurationPort.cs" /> 205 <Compile Include="Core\INodeVisualProperties.cs" /> 206 <Compile Include="Core\IPortVisualProperties.cs" /> 207 <Compile Include="Core\IVisualizableNode.cs" /> 208 <Compile Include="Core\IVisualizablePort.cs" /> 205 <Compile Include="Core\IVisualizable.cs" /> 209 206 <Compile Include="Core\IVisualProperties.cs" /> 210 <Compile Include="Core\NodeVisualProperties.cs" />211 <Compile Include="Core\PortVisualProperties.cs" />212 207 <Compile Include="Core\VisualProperties.cs" /> 213 208 <Compile Include="ExecutionPort.cs" /> -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable/ProgrammableNetworkItem.cs
r13077 r13135 98 98 get { return CompiledNetworkItem.Children; } 99 99 } 100 101 [Storable] 102 public IVisualProperties VisualProperties { get; set; } 100 103 #endregion 101 104 … … 169 172 variableStore = cloner.Clone(original.variableStore); 170 173 CompiledNetworkItem = cloner.Clone(original.compiledNetworkItem); 174 VisualProperties = cloner.Clone(original.VisualProperties); 171 175 } 172 176 protected ProgrammableNetworkItem() … … 358 362 get { return Enumerable.Empty<INetworkItem>(); } 359 363 } 364 365 // TODO: no visual properties needed here 366 public IVisualProperties VisualProperties { 367 get { return Context.VisualProperties; } 368 set { Context.VisualProperties = value; } 369 } 360 370 #endregion 361 371 -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable/ProgrammableNode.cs
r13077 r13135 32 32 [Item("ProgrammableNode", "Abstract base class for programmable nodes of a network.")] 33 33 [StorableClass] 34 public abstract class ProgrammableNode : ProgrammableNetworkItem, IProgrammableNode , IVisualizableNode{34 public abstract class ProgrammableNode : ProgrammableNetworkItem, IProgrammableNode { 35 35 public static new Image StaticItemImage { 36 36 get { return HeuristicLab.Common.Resources.VSImageLibrary.RadialChart; } … … 58 58 } 59 59 } 60 61 public string VisualName { get { return Name; } }62 63 [Storable]64 private INodeVisualProperties visualProperties;65 public INodeVisualProperties VisualProperties {66 get {67 if (visualProperties == null)68 visualProperties = new NodeVisualProperties();69 return visualProperties;70 }71 }72 60 #endregion 73 61 … … 127 115 IKeyedItemCollection<string, IPort> INode.Ports { 128 116 get { return Ports; } 129 }130 131 public string VisualName { get { return Context.VisualName; } }132 133 public INodeVisualProperties VisualProperties {134 get { return Context.VisualProperties; }135 117 } 136 118 #endregion
Note: See TracChangeset
for help on using the changeset viewer.