Changeset 13839
- Timestamp:
- 05/09/16 13:55:42 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/NetworkVisualizationView.cs
r13833 r13839 24 24 using System.Linq; 25 25 using HeuristicLab.Collections; 26 using HeuristicLab.Core;27 26 using HeuristicLab.Core.Networks; 28 27 using HeuristicLab.Core.Networks.Views; … … 64 63 protected override void OnContentChanged() { 65 64 base.OnContentChanged(); 66 UpdateContent(); 67 if (Content != null) 68 LayoutNodes(Content.Nodes); 65 bool doLayout = Content != null && Content.Nodes.Any(x => x.VisualProperties == null); 66 UpdateContent(); 67 if (doLayout) { 68 LayoutNodes(); 69 LayoutPorts(); 70 } 69 71 chartControl.Tag = Content; 70 72 } … … 138 140 primitiveDict.Clear(); 139 141 chartControl.Chart.Group.Clear(); 140 DrawNodes( Content.Nodes);141 ConnectNodes( Content.Nodes);142 DrawNodes(); 143 ConnectNodes(); 142 144 } finally { 143 145 chartControl.ResumeRendering(); … … 145 147 } 146 148 147 private void DrawNodes( IKeyedItemCollection<string, INode> nodes) {148 foreach (var node in nodes) {149 private void DrawNodes() { 150 foreach (var node in Content.Nodes) { 149 151 var defaultPrimitive = PrimitiveAttribute.CreateDefaultPrimitive(node.GetType(), chartControl.Chart, node); 150 152 if (defaultPrimitive == null) continue; … … 154 156 } 155 157 156 private void ConnectNodes(IKeyedItemCollection<string, INode> nodes) { 157 var chart = chartControl.Chart; 158 foreach (var node in nodes) { 158 private void ConnectNodes() { 159 foreach (var node in Content.Nodes) { 159 160 var nodeRectangle = primitiveDict[node.Name] as NodeRectangle; 160 161 if (nodeRectangle == null) continue; … … 173 174 var rightPortRectangle = (PortRectangle)connectedRectangle.GetPortPrimitive(connectedPort); 174 175 175 var connectionShape = new ConnectionLine(chart , leftPortRectangle, rightPortRectangle);176 177 chart .Group.Add(connectionShape);178 } 179 } 180 } 181 182 private void LayoutNodes( IKeyedItemCollection<string, INode> nodes) {176 var connectionShape = new ConnectionLine(chartControl.Chart, leftPortRectangle, rightPortRectangle); 177 178 chartControl.Chart.Group.Add(connectionShape); 179 } 180 } 181 } 182 183 private void LayoutNodes() { 183 184 var layout = new Layout(); 184 185 var layoutNodes = new Dictionary<string, Layout.LayoutNode>(); 185 186 186 foreach (var node in nodes) {187 foreach (var node in Content.Nodes) { 187 188 var nodeRectangle = primitiveDict[node.Name] as NodeRectangle; 188 189 if (nodeRectangle == null) continue; … … 227 228 } 228 229 } 230 231 private void LayoutPorts() { 232 foreach (var node in Content.Nodes) { 233 var nodeRectangle = primitiveDict[node.Name] as NodeRectangle; 234 if (nodeRectangle == null) continue; 235 236 foreach (var port in node.Ports.OfType<IConnectablePort>()) { 237 var connectedPort = port.ConnectedPort as IConnectablePort; 238 if (connectedPort == null) continue; 239 240 var connectedNode = connectedPort.Parent; 241 if (connectedNode == null) continue; 242 243 var connectedRectangle = primitiveDict[connectedNode.Name] as NodeRectangle; 244 if (connectedRectangle == null) continue; 245 246 var leftCenter = nodeRectangle.Center(); 247 var rightCenter = connectedRectangle.Center(); 248 var line = new Line(null, rightCenter, leftCenter); 249 250 var leftIntersection = nodeRectangle.ComputeIntersect(line).Single(); 251 var rightIntersection = connectedRectangle.ComputeIntersect(line).Single(); 252 253 var leftPortRectangle = (PortRectangle)nodeRectangle.GetPortPrimitive(port); 254 leftPortRectangle.SetPosition(leftIntersection); 255 var rightPortRectangle = (PortRectangle)connectedRectangle.GetPortPrimitive(connectedPort); 256 rightPortRectangle.SetPosition(rightIntersection); 257 } 258 } 259 } 229 260 #endregion 230 261 }
Note: See TracChangeset
for help on using the changeset viewer.