Changeset 13799 for branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/PortRectangle.cs
- Timestamp:
- 04/26/16 15:05:28 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/PortRectangle.cs
r13135 r13799 35 35 protected readonly INodeVisualProperties nodeVisualProperties; 36 36 37 protected IPortVisualProperties VisualProperties { 38 get { return (IPortVisualProperties)networkItem.VisualProperties; } 39 set { 40 if (networkItem.VisualProperties == value) return; 41 networkItem.VisualProperties = value; 42 } 43 } 37 44 protected bool IgnoreVisualPropertiesChanges { get; set; } 38 45 … … 57 64 } 58 65 66 public override Brush Brush { 67 get { return base.Brush; } 68 set { 69 if (base.Brush == value) return; 70 base.Brush = value; 71 SaveVisualProperties(); 72 } 73 } 74 75 public override Pen Pen { 76 get { return base.Pen; } 77 set { 78 if (base.Pen == value) return; 79 base.Pen = value; 80 SaveVisualProperties(); 81 } 82 } 83 59 84 public PortRectangle(IChart chart, IPort port, INode node) 60 : base(chart, PointD.Empty, Size.Empty , Pens.Black, Brushes.Red) {85 : base(chart, PointD.Empty, Size.Empty) { 61 86 nodeVisualProperties = (INodeVisualProperties)node.VisualProperties; 62 87 nodeVisualProperties.Changed += NodeVisualProperties_Changed; … … 65 90 66 91 protected virtual void RegisterNetworkItemEvents() { 92 if (VisualProperties != null) { 93 VisualProperties.Changed += VisualProperties_Changed; 94 } 67 95 networkItem.NameChanged += NetworkItem_NameChanged; 68 if (networkItem.VisualProperties != null) {69 networkItem.VisualProperties.Changed += VisualProperties_Changed;70 }71 96 var connectablePort = networkItem as IConnectablePort; 72 97 if (connectablePort != null) { … … 76 101 77 102 protected virtual void DeregisterNetworkItemEvents() { 103 if (VisualProperties != null) { 104 VisualProperties.Changed -= VisualProperties_Changed; 105 } 78 106 networkItem.NameChanged -= NetworkItem_NameChanged; 79 if (networkItem.VisualProperties != null) {80 networkItem.VisualProperties.Changed -= VisualProperties_Changed;81 }82 107 var connectablePort = networkItem as IConnectablePort; 83 108 if (connectablePort != null) { … … 97 122 var p = Chart.TransformWorldToPixel(Point); 98 123 99 if (networkItem != null && networkItem.VisualProperties != null) {124 if (networkItem != null && VisualProperties != null) { 100 125 using (var font = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25 * Chart.WorldToPixelRatio.Width))) { 101 126 var textSize = graphics.MeasureString(networkItem.Name, font); 102 var vp = (IPortVisualProperties)networkItem.VisualProperties;127 var vp = VisualProperties; 103 128 switch (vp.Orientation) { 104 129 case Orientation.North: p = new Point((int)(p.X - textSize.Width / 2), (int)(p.Y - Size.Height - textSize.Height)); break; … … 179 204 180 205 #region Helpers 181 182 private IPortVisualProperties CreateDefaultVisualProperties() {183 return new PortVisualProperties(Orientation.South, 0.5);184 }185 186 206 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); 207 if (VisualProperties == null) 208 VisualProperties = new PortVisualProperties(); 209 210 var vp = VisualProperties; 211 IgnoreVisualPropertiesChanges = true; 212 try { 213 var p = PointD.Empty; 214 double nodeWidth = nodeVisualProperties.UpperRight.X - nodeVisualProperties.LowerLeft.X; 215 double nodeHeight = nodeVisualProperties.UpperRight.Y - nodeVisualProperties.LowerLeft.Y; 216 217 switch (vp.Orientation) { 218 case Orientation.North: 219 p.X = nodeVisualProperties.LowerLeft.X + vp.Offset * nodeWidth; 220 p.Y = nodeVisualProperties.UpperRight.Y; 221 break; 222 case Orientation.East: 223 p.X = nodeVisualProperties.UpperRight.X; 224 p.Y = nodeVisualProperties.UpperRight.Y - vp.Offset * nodeHeight; 225 break; 226 case Orientation.South: 227 p.X = nodeVisualProperties.UpperRight.X - vp.Offset * nodeWidth; 228 p.Y = nodeVisualProperties.LowerLeft.Y; 229 break; 230 case Orientation.West: 231 p.X = nodeVisualProperties.LowerLeft.X; 232 p.Y = nodeVisualProperties.LowerLeft.Y + vp.Offset * nodeHeight; 233 break; 234 } 235 236 SetPosition(p); 237 Brush = new SolidBrush(vp.BrushColor); 238 Pen = new Pen(vp.PenColor); 239 } finally { IgnoreVisualPropertiesChanges = false; } 215 240 } 216 241 217 242 private void SaveVisualProperties() { 218 if (networkItem == null) return; 219 220 var vp = (IPortVisualProperties)networkItem.VisualProperties; 221 243 if (networkItem == null || IgnoreVisualPropertiesChanges) return; 244 245 var vp = VisualProperties; 222 246 IgnoreVisualPropertiesChanges = true; 223 247 try { … … 245 269 } 246 270 } 247 } finally { 248 IgnoreVisualPropertiesChanges = false; 249 } 271 272 vp.BrushColor = ((SolidBrush)Brush).Color; 273 vp.PenColor = Pen.Color; 274 } finally { IgnoreVisualPropertiesChanges = false; } 250 275 } 251 276
Note: See TracChangeset
for help on using the changeset viewer.