Changeset 13799
- Timestamp:
- 04/26/16 15:05:28 (9 years ago)
- Location:
- branches/OptimizationNetworks
- Files:
-
- 2 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/ChartModes/AddNodesChartMode.cs
r13135 r13799 79 79 var lowerLeft = center - new Offset(size); 80 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)); 81 node.VisualProperties = new NodeVisualProperties { 82 LowerLeft = new Point2D<double>(lowerLeft.X, lowerLeft.Y), 83 UpperRight = new Point2D<double>(upperRight.X, upperRight.Y) 84 }; 83 85 network.Nodes.Add(node); 84 86 break; -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/ChartModes/SelectChartMode.cs
r13135 r13799 49 49 } 50 50 51 public override void HandleOnKeyDown(object sender, KeyEventArgs e) {52 try {53 if (!(chartControl.Tag is IUserDefinedNetwork)) return;54 55 switch (e.KeyCode) {56 case Keys.Delete:57 chartControl.SuspendRendering();58 59 var connectionLines = chartControl.Chart.Group.Primitives.OfType<ConnectionLine>().ToList();60 var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>().ToList();61 var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortPrimitive)).OfType<PortRectangle>().ToList();62 63 var deletedNodes = new HashSet<INode>();64 var deletedPorts = new HashSet<IMessagePort>();65 66 foreach (var nodeRectangle in nodeRectangles) {67 if (nodeRectangle.Selected) {68 var node = nodeRectangle.NetworkItem;69 if (node == null) continue;70 deletedNodes.Add(node);71 foreach (var port in node.Ports.OfType<IMessagePort>())72 deletedPorts.Add(port);73 }74 }75 76 foreach (var portRectangle in portRectangles) {77 if (portRectangle.Selected) {78 var port = portRectangle.NetworkItem as IMessagePort;79 if (port == null) continue;80 port.Parent.Ports.Remove(port);81 deletedPorts.Add(port);82 }83 }84 85 selectedPortRectangle = null;86 87 foreach (var connectionLine in connectionLines) {88 var startPortRectangle = connectionLine.StartPortRectangle;89 var endPortRectangle = connectionLine.EndPortRectangle;90 if (startPortRectangle == null || endPortRectangle == null) continue;91 92 var startPort = startPortRectangle.NetworkItem as IMessagePort;93 var endPort = endPortRectangle.NetworkItem as IMessagePort;94 if (startPort == null || endPort == null) continue;95 96 if (connectionLine.Selected || deletedPorts.Contains(startPort) || deletedPorts.Contains(endPort))97 startPort.ConnectedPort = null;98 }99 100 foreach (var node in deletedNodes)101 node.Parent.Nodes.Remove(node);102 break;103 }104 } finally {105 chartControl.ResumeRendering();106 }107 }108 109 51 public override void HandleOnMouseDown(object sender, MouseEventArgs e) { 110 52 try { … … 129 71 selectedPortRectangle = portRectangle; 130 72 constrainingNodeRectangle = nodeRectangle; 73 break; 131 74 } 132 75 } … … 134 77 135 78 if (selectedPortRectangle != null) 136 foreach (var sp in chartControl.Chart.Group.SelectedPrimitives) 79 foreach (var sp in chartControl.Chart.Group.SelectedPrimitives) { 137 80 sp.Selected = false; 138 else139 base.HandleOnMouseDown(sender, e);81 OnSelectedPrimitivesChanged(); 82 } else base.HandleOnMouseDown(sender, e); 140 83 break; 141 84 } … … 196 139 } 197 140 } 141 142 protected override void DeleteSelectedPrimitives() { 143 if (!(chartControl.Tag is IUserDefinedNetwork)) return; 144 145 try { 146 chartControl.SuspendRendering(); 147 148 var connectionLines = chartControl.Chart.Group.Primitives.OfType<ConnectionLine>().ToList(); 149 var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>().ToList(); 150 var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortPrimitive)).OfType<PortRectangle>().ToList(); 151 152 var deletedNodes = new HashSet<INode>(); 153 var deletedPorts = new HashSet<IMessagePort>(); 154 155 foreach (var nodeRectangle in nodeRectangles) { 156 if (nodeRectangle.Selected) { 157 var node = nodeRectangle.NetworkItem; 158 if (node == null) continue; 159 deletedNodes.Add(node); 160 foreach (var port in node.Ports.OfType<IMessagePort>()) 161 deletedPorts.Add(port); 162 } 163 } 164 165 foreach (var portRectangle in portRectangles) { 166 if (portRectangle.Selected) { 167 var port = portRectangle.NetworkItem as IMessagePort; 168 if (port == null) continue; 169 port.Parent.Ports.Remove(port); 170 deletedPorts.Add(port); 171 } 172 } 173 174 selectedPortRectangle = null; 175 176 foreach (var connectionLine in connectionLines) { 177 var startPortRectangle = connectionLine.StartPortRectangle; 178 var endPortRectangle = connectionLine.EndPortRectangle; 179 if (startPortRectangle == null || endPortRectangle == null) continue; 180 181 var startPort = startPortRectangle.NetworkItem as IMessagePort; 182 var endPort = endPortRectangle.NetworkItem as IMessagePort; 183 if (startPort == null || endPort == null) continue; 184 185 if (connectionLine.Selected || deletedPorts.Contains(startPort) || deletedPorts.Contains(endPort)) 186 startPort.ConnectedPort = null; 187 } 188 189 foreach (var node in deletedNodes) 190 node.Parent.Nodes.Remove(node); 191 } finally { chartControl.ResumeRendering(); } 192 } 198 193 } 199 194 } -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/NetworkVisualizationView.Designer.cs
r13077 r13799 25 25 private void InitializeComponent() { 26 26 this.chartControl = new HeuristicLab.Visualization.ChartControl(); 27 this.splitContainer = new System.Windows.Forms.SplitContainer(); 28 this.detailsToggleButton = new System.Windows.Forms.Button(); 29 this.detailsGroupBox = new System.Windows.Forms.GroupBox(); 30 this.viewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost(); 27 31 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 32 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 33 this.splitContainer.Panel1.SuspendLayout(); 34 this.splitContainer.Panel2.SuspendLayout(); 35 this.splitContainer.SuspendLayout(); 36 this.detailsGroupBox.SuspendLayout(); 28 37 this.SuspendLayout(); 29 38 // … … 39 48 | System.Windows.Forms.AnchorStyles.Right))); 40 49 this.chartControl.BackColor = System.Drawing.SystemColors.Control; 41 this.chartControl.Location = new System.Drawing.Point(3, 26); 50 this.chartControl.Location = new System.Drawing.Point(3, 3); 51 this.chartControl.Mode = null; 42 52 this.chartControl.Name = "chartControl"; 43 53 this.chartControl.ScaleOnResize = true; 44 this.chartControl.Size = new System.Drawing.Size(639, 488); 54 this.chartControl.ShowToolBar = true; 55 this.chartControl.Size = new System.Drawing.Size(408, 482); 56 this.chartControl.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 45 57 this.chartControl.TabIndex = 3; 58 // 59 // splitContainer 60 // 61 this.splitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 62 | System.Windows.Forms.AnchorStyles.Left) 63 | System.Windows.Forms.AnchorStyles.Right))); 64 this.splitContainer.Location = new System.Drawing.Point(3, 26); 65 this.splitContainer.Name = "splitContainer"; 66 // 67 // splitContainer.Panel1 68 // 69 this.splitContainer.Panel1.Controls.Add(this.detailsToggleButton); 70 this.splitContainer.Panel1.Controls.Add(this.chartControl); 71 // 72 // splitContainer.Panel2 73 // 74 this.splitContainer.Panel2.Controls.Add(this.detailsGroupBox); 75 this.splitContainer.Size = new System.Drawing.Size(639, 488); 76 this.splitContainer.SplitterDistance = 439; 77 this.splitContainer.TabIndex = 4; 78 // 79 // detailsToggleButton 80 // 81 this.detailsToggleButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 82 | System.Windows.Forms.AnchorStyles.Right))); 83 this.detailsToggleButton.Location = new System.Drawing.Point(417, 3); 84 this.detailsToggleButton.Name = "detailsToggleButton"; 85 this.detailsToggleButton.Size = new System.Drawing.Size(19, 482); 86 this.detailsToggleButton.TabIndex = 4; 87 this.detailsToggleButton.Text = ">"; 88 this.detailsToggleButton.UseVisualStyleBackColor = true; 89 this.detailsToggleButton.Click += new System.EventHandler(this.detailsToggleButton_Click); 90 // 91 // detailsGroupBox 92 // 93 this.detailsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 94 | System.Windows.Forms.AnchorStyles.Left) 95 | System.Windows.Forms.AnchorStyles.Right))); 96 this.detailsGroupBox.Controls.Add(this.viewHost); 97 this.detailsGroupBox.Location = new System.Drawing.Point(3, 3); 98 this.detailsGroupBox.Name = "detailsGroupBox"; 99 this.detailsGroupBox.Size = new System.Drawing.Size(190, 482); 100 this.detailsGroupBox.TabIndex = 1; 101 this.detailsGroupBox.TabStop = false; 102 this.detailsGroupBox.Text = "Details"; 103 // 104 // viewHost 105 // 106 this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 107 | System.Windows.Forms.AnchorStyles.Left) 108 | System.Windows.Forms.AnchorStyles.Right))); 109 this.viewHost.Caption = "View"; 110 this.viewHost.Content = null; 111 this.viewHost.Enabled = false; 112 this.viewHost.Location = new System.Drawing.Point(6, 19); 113 this.viewHost.Name = "viewHost"; 114 this.viewHost.ReadOnly = false; 115 this.viewHost.Size = new System.Drawing.Size(178, 457); 116 this.viewHost.TabIndex = 0; 117 this.viewHost.ViewsLabelVisible = true; 118 this.viewHost.ViewType = null; 46 119 // 47 120 // NetworkVisualizationView … … 49 122 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 50 123 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 51 this.Controls.Add(this. chartControl);124 this.Controls.Add(this.splitContainer); 52 125 this.Name = "NetworkVisualizationView"; 53 126 this.Controls.SetChildIndex(this.nameLabel, 0); 54 127 this.Controls.SetChildIndex(this.nameTextBox, 0); 55 128 this.Controls.SetChildIndex(this.infoLabel, 0); 56 this.Controls.SetChildIndex(this. chartControl, 0);129 this.Controls.SetChildIndex(this.splitContainer, 0); 57 130 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); 131 this.splitContainer.Panel1.ResumeLayout(false); 132 this.splitContainer.Panel2.ResumeLayout(false); 133 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); 134 this.splitContainer.ResumeLayout(false); 135 this.detailsGroupBox.ResumeLayout(false); 58 136 this.ResumeLayout(false); 59 137 this.PerformLayout(); … … 64 142 65 143 private Visualization.ChartControl chartControl; 144 private System.Windows.Forms.SplitContainer splitContainer; 145 private System.Windows.Forms.Button detailsToggleButton; 146 private System.Windows.Forms.GroupBox detailsGroupBox; 147 private MainForm.WindowsForms.ViewHost viewHost; 66 148 } 67 149 } -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/NetworkVisualizationView.cs
r13135 r13799 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 46 47 InitializeComponent(); 47 48 48 var initialMode = new SelectChartMode(chartControl); 49 var selectMode = new SelectChartMode(chartControl); 50 selectMode.SelectedPrimitivesChanged += SelectMode_SelectedPrimitivesChanged; 49 51 chartControl.AddChartModes( 50 initialMode,52 selectMode, 51 53 new PanChartMode(chartControl), 52 54 new RulerChartMode(chartControl), … … 57 59 new ConnectPortsChartMode(chartControl) 58 60 ); 59 chartControl.Mode = initialMode;61 chartControl.Mode = selectMode; 60 62 } 61 63 … … 87 89 88 90 #region Event Handlers 91 private void SelectMode_SelectedPrimitivesChanged(object sender, EventArgs e) { 92 var selectedPrimitives = chartControl.Chart.Group.SelectedPrimitives; 93 var nodePrimitive = selectedPrimitives.OfType<NodeRectangle>().SingleOrDefault(); 94 viewHost.Content = nodePrimitive != null ? nodePrimitive.NetworkItem : null; 95 } 96 89 97 #region Nodes Event Handlers 90 98 private void Nodes_ItemsAdded(object sender, CollectionItemsChangedEventArgs<INode> e) { … … 111 119 private void Ports_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IPort> e) { } 112 120 #endregion 121 122 private void detailsToggleButton_Click(object sender, EventArgs e) { 123 splitContainer.Panel2Collapsed = !splitContainer.Panel2Collapsed; 124 detailsToggleButton.Text = splitContainer.Panel2Collapsed ? "<" : ">"; 125 } 113 126 #endregion 114 127 -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/HeuristicLab.Networks.Views.NetworkVisualization-3.3.csproj
r13135 r13799 75 75 <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 76 76 <SpecificVersion>False</SpecificVersion> 77 <Private>False</Private> 77 78 </Reference> 78 79 <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 79 80 <SpecificVersion>False</SpecificVersion> 80 81 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath> 81 <Private> True</Private>82 <Private>False</Private> 82 83 </Reference> 83 84 <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 84 85 <SpecificVersion>False</SpecificVersion> 85 86 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath> 87 <Private>False</Private> 88 </Reference> 89 <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 90 <SpecificVersion>False</SpecificVersion> 91 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath> 86 92 <Private>False</Private> 87 93 </Reference> … … 101 107 <Reference Include="System.Core" /> 102 108 <Reference Include="System.Drawing" /> 109 <Reference Include="System.Windows.Forms" /> 103 110 </ItemGroup> 104 111 <ItemGroup> … … 109 116 <Compile Include="Orientation.cs" /> 110 117 <Compile Include="PortVisualProperties.cs" /> 118 <Compile Include="Primitives\AlgorithmNodeRectangle.cs" /> 111 119 <Compile Include="Primitives\ConnectionLine.cs" /> 112 120 <Compile Include="Plugin.cs" /> 121 <Compile Include="Primitives\MessagePortRectangle.cs" /> 113 122 <Compile Include="Primitives\NodeRectangle.cs" /> 114 123 <Compile Include="Primitives\PortRectangle.cs" /> -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/INodeVisualProperties.cs
r13135 r13799 20 20 #endregion 21 21 22 using System.Drawing; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core.Networks; … … 27 28 Point2D<double> LowerLeft { get; set; } 28 29 Point2D<double> UpperRight { get; set; } 30 Color BrushColor { get; set; } 31 Color PenColor { get; set; } 29 32 } 30 33 } -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/IPortVisualProperties.cs
r13135 r13799 20 20 #endregion 21 21 22 using System.Drawing; 22 23 using HeuristicLab.Core.Networks; 23 24 … … 26 27 Orientation Orientation { get; set; } 27 28 double Offset { get; set; } 29 Color BrushColor { get; set; } 30 Color PenColor { get; set; } 28 31 } 29 32 } -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/NodeVisualProperties.cs
r13135 r13799 20 20 #endregion 21 21 22 using System.Drawing; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core.Networks; … … 49 50 } 50 51 52 [Storable] 53 private Color brushColor; 54 public Color BrushColor { 55 get { return brushColor; } 56 set { 57 if (brushColor == value) return; 58 brushColor = value; 59 OnChanged(); 60 } 61 } 62 63 [Storable] 64 private Color penColor; 65 public Color PenColor { 66 get { return penColor; } 67 set { 68 if (penColor == value) return; 69 penColor = value; 70 OnChanged(); 71 } 72 } 73 51 74 #region Constructors & Cloning 52 75 [StorableConstructor] … … 56 79 lowerLeft = original.lowerLeft; 57 80 upperRight = original.upperRight; 81 brushColor = original.brushColor; 82 penColor = original.penColor; 58 83 } 59 84 60 public NodeVisualProperties(Point2D<double> lowerLeft, Point2D<double> upperRight) { 61 this.lowerLeft = lowerLeft; 62 this.upperRight = upperRight; 85 public NodeVisualProperties() { 86 lowerLeft = new Point2D<double>(0.0, 0.0); 87 upperRight = new Point2D<double>(200.0, 100.0); 88 brushColor = Color.FromArgb(255, 120, 200, 240); 89 penColor = Color.Black; 63 90 } 64 91 -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/PortVisualProperties.cs
r13135 r13799 20 20 #endregion 21 21 22 using System.Drawing; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core.Networks; … … 49 50 } 50 51 52 [Storable] 53 private Color brushColor; 54 public Color BrushColor { 55 get { return brushColor; } 56 set { 57 if (brushColor == value) return; 58 brushColor = value; 59 OnChanged(); 60 } 61 } 62 63 [Storable] 64 private Color penColor; 65 public Color PenColor { 66 get { return penColor; } 67 set { 68 if (penColor == value) return; 69 penColor = value; 70 OnChanged(); 71 } 72 } 73 51 74 #region Constructors & Cloning 52 75 [StorableConstructor] … … 56 79 orientation = original.orientation; 57 80 offset = original.offset; 81 brushColor = original.brushColor; 82 penColor = original.penColor; 58 83 } 59 84 60 public PortVisualProperties(Orientation orientation, double offset) { 61 this.orientation = orientation; 62 this.offset = offset; 85 public PortVisualProperties() { 86 orientation = Orientation.South; 87 offset = 0.5; 88 brushColor = Color.RosyBrown; 89 penColor = Color.Black; 63 90 } 64 91 -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/ConnectionLine.cs
r13135 r13799 81 81 double bx = -2.5 * ax - ay, by = -2.5 * ay + ax; 82 82 double cx = -2.5 * ax + ay, cy = -2.5 * ay - ax; 83 double mul = 4* Chart.WorldToPixelRatio.Width;83 double mul = 5 * Chart.WorldToPixelRatio.Width; 84 84 bx *= mul; by *= mul; 85 85 cx *= mul; cy *= mul; -
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/NodeRectangle.cs
r13135 r13799 23 23 using System.Collections.Generic; 24 24 using System.Drawing; 25 using System.Drawing.Drawing2D; 26 using System.Windows.Forms; 25 27 using HeuristicLab.Common; 26 28 using HeuristicLab.Core.Networks; … … 33 35 protected readonly IGroup portRectangles; 34 36 37 protected INodeVisualProperties VisualProperties { 38 get { return (INodeVisualProperties)networkItem.VisualProperties; } 39 set { 40 if (networkItem.VisualProperties == value) return; 41 networkItem.VisualProperties = value; 42 } 43 } 35 44 protected bool IgnoreVisualPropertiesChanges { get; set; } 36 45 … … 48 57 } 49 58 59 public override Brush Brush { 60 get { return base.Brush; } 61 set { 62 if (base.Brush == value) return; 63 base.Brush = value; 64 SaveVisualProperties(); 65 } 66 } 67 68 public override Pen Pen { 69 get { return base.Pen; } 70 set { 71 if (base.Pen == value) return; 72 base.Pen = value; 73 SaveVisualProperties(); 74 } 75 } 76 50 77 public NodeRectangle(IChart chart, INode node) 51 78 : base(chart, PointD.Empty, PointD.Empty) { 79 bool adjustSize = node.VisualProperties == null; 52 80 NetworkItem = node; 53 81 … … 59 87 } 60 88 portRectangles.RedrawRequired += (sender, args) => OnRedrawRequired(); 89 90 if (adjustSize) AdjustSize(); 61 91 } 62 92 63 93 protected virtual void RegisterNetworkItemEvents() { 94 if (VisualProperties != null) { 95 VisualProperties.Changed += VisualProperties_Changed; 96 } 64 97 networkItem.NameChanged += NetworkItem_NameChanged; 65 if (networkItem.VisualProperties != null) {66 networkItem.VisualProperties.Changed += VisualProperties_Changed;67 }68 98 if (networkItem.Ports != null) { 69 99 networkItem.Ports.ItemsAdded += Ports_ItemsAdded; … … 73 103 74 104 protected virtual void DeregisterNetworkItemEvents() { 105 if (VisualProperties != null) { 106 VisualProperties.Changed -= VisualProperties_Changed; 107 } 75 108 networkItem.NameChanged -= NetworkItem_NameChanged; 76 if (networkItem.VisualProperties != null) {77 networkItem.VisualProperties.Changed -= VisualProperties_Changed;78 }79 109 if (networkItem.Ports != null) { 80 110 networkItem.Ports.ItemsAdded -= Ports_ItemsAdded; … … 90 120 91 121 public override void Draw(Graphics graphics) { 92 base.Draw(graphics); 122 int cornerRadius = (int)Math.Round(6 * Chart.WorldToPixelRatio.Width); 123 var point = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height)); 124 var size = Chart.TransformWorldToPixel(Size); 125 var bounds = new System.Drawing.Rectangle(point.X, point.Y, size.Width, size.Height); 126 var arc = new System.Drawing.Rectangle(point, new Size(cornerRadius * 2, cornerRadius * 2)); 127 128 using (var path = new GraphicsPath()) { 129 path.AddArc(arc, 180f, 90f); 130 arc.X = bounds.Right - cornerRadius * 2; 131 path.AddArc(arc, 270f, 90); 132 arc.Y = bounds.Bottom - cornerRadius * 2; 133 path.AddArc(arc, 0f, 90f); 134 arc.X = bounds.Left; 135 path.AddArc(arc, 90f, 90f); 136 path.CloseFigure(); 137 138 graphics.FillPath(Brush, path); 139 graphics.DrawPath(Pen, path); 140 } 93 141 94 142 var p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height)); 95 143 96 144 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); 145 using (var headerFont = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25 * Chart.WorldToPixelRatio.Width), FontStyle.Bold)) 146 using (var contentFont = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25 * Chart.WorldToPixelRatio.Width))) { 147 int margin = 4, x, y, lastY; 148 149 x = p.X + (int)Math.Round(margin * Chart.WorldToPixelRatio.Width); 150 y = p.Y + (int)Math.Round(margin * Chart.WorldToPixelRatio.Height); 151 152 var imageSize = networkItem.ItemImage.Size; 153 float imageWidth = (float)Math.Round(imageSize.Width * Chart.WorldToPixelRatio.Width); 154 float imageHeight = (float)Math.Round(imageSize.Height * Chart.WorldToPixelRatio.Height); 155 graphics.DrawImage(networkItem.ItemImage, x, y, imageWidth, imageHeight); 156 lastY = y; 157 158 var textSize = graphics.MeasureString(networkItem.Name, headerFont); 159 x += (int)Math.Round((imageSize.Width + margin) * Chart.WorldToPixelRatio.Width); 160 y += (int)Math.Round((imageSize.Height - textSize.Height * Chart.PixelToWorldRatio.Height) / 2 * Chart.WorldToPixelRatio.Height); 161 graphics.DrawString(networkItem.Name, headerFont, Brushes.Black, x, y); 162 y = lastY + (int)Math.Round(imageSize.Height * Chart.WorldToPixelRatio.Height); 163 164 x = p.X; 165 y += (int)Math.Round(margin * Chart.WorldToPixelRatio.Height); 166 graphics.DrawLine(Pen, x, y, x + size.Width, y); 167 168 foreach (var port in networkItem.Ports) { 169 x = p.X + (int)Math.Round(margin * Chart.WorldToPixelRatio.Width); 170 y += (int)Math.Round(margin * Chart.WorldToPixelRatio.Height); 171 172 imageSize = port.ItemImage.Size; 173 imageWidth = (float)Math.Round(imageSize.Width * Chart.WorldToPixelRatio.Width); 174 imageHeight = (float)Math.Round(imageSize.Height * Chart.WorldToPixelRatio.Height); 175 graphics.DrawImage(port.ItemImage, x, y, imageWidth, imageHeight); 176 lastY = y; 177 178 textSize = graphics.MeasureString(port.Name, contentFont); 179 x += (int)Math.Round((imageSize.Width + margin) * Chart.WorldToPixelRatio.Width); 180 y += (int)Math.Round((imageSize.Height - textSize.Height * Chart.PixelToWorldRatio.Height) / 2 * Chart.WorldToPixelRatio.Height); 181 graphics.DrawString(port.Name, contentFont, Brushes.Black, x, y); 182 y = lastY + (int)Math.Round(imageSize.Height * Chart.WorldToPixelRatio.Height); 183 184 var parameterizedPort = port as IParameterizedPort; 185 if (parameterizedPort != null) { 186 foreach (var param in parameterizedPort.Parameters) { 187 x = p.X + (int)Math.Round(4 * margin * Chart.WorldToPixelRatio.Width); 188 y += (int)Math.Round(margin * Chart.WorldToPixelRatio.Height); 189 190 imageSize = param.ItemImage.Size; 191 imageWidth = (float)Math.Round(imageSize.Width * Chart.WorldToPixelRatio.Width); 192 imageHeight = (float)Math.Round(imageSize.Height * Chart.WorldToPixelRatio.Height); 193 graphics.DrawImage(param.ItemImage, x, y, imageWidth, imageHeight); 194 lastY = y; 195 196 textSize = graphics.MeasureString(param.Name, contentFont); 197 x += (int)Math.Round((imageSize.Width + margin) * Chart.WorldToPixelRatio.Width); 198 y += (int)Math.Round((imageSize.Height - textSize.Height * Chart.PixelToWorldRatio.Height) / 2 * Chart.WorldToPixelRatio.Height); 199 graphics.DrawString(param.Name, contentFont, Brushes.Black, x, y); 200 y = lastY + (int)Math.Round(imageSize.Height * Chart.WorldToPixelRatio.Height); 201 } 202 } 203 } 99 204 } 100 205 } … … 128 233 129 234 private void Ports_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 235 AdjustSize(); 236 130 237 foreach (var port in e.Items) { 131 238 var portRectangle = PrimitiveAttribute.CreateDefaultPrimitive(port.GetType(), Chart, port, networkItem); … … 133 240 portRectangles.Add(portRectangle); 134 241 } 135 136 OnRedrawRequired();137 242 } 138 243 139 244 private void Ports_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 245 AdjustSize(); 246 140 247 foreach (var port in e.Items) { 141 248 var portRectangle = port2primitive[port]; … … 143 250 portRectangles.Remove(portRectangle); 144 251 } 145 146 OnRedrawRequired();147 252 } 148 253 #endregion 149 254 150 255 #region Helpers 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));158 }159 160 256 private void LoadVisualProperties() { 161 if (networkItem.VisualProperties == null) 162 networkItem.VisualProperties = CreateDefaultVisualProperties(); 163 164 var vp = (INodeVisualProperties)networkItem.VisualProperties; 165 SetPosition(new PointD(vp.LowerLeft.X, vp.LowerLeft.Y), new PointD(vp.UpperRight.X, vp.UpperRight.Y)); 257 if (VisualProperties == null) 258 VisualProperties = new NodeVisualProperties(); 259 260 var vp = VisualProperties; 261 IgnoreVisualPropertiesChanges = true; 262 try { 263 SetPosition(new PointD(vp.LowerLeft.X, vp.LowerLeft.Y), new PointD(vp.UpperRight.X, vp.UpperRight.Y)); 264 Brush = new SolidBrush(vp.BrushColor); 265 Pen = new Pen(vp.PenColor); 266 } finally { IgnoreVisualPropertiesChanges = false; } 166 267 } 167 268 168 269 private void SaveVisualProperties() { 169 if (networkItem == null) return; 170 171 var vp = (INodeVisualProperties)networkItem.VisualProperties; 172 270 if (networkItem == null || IgnoreVisualPropertiesChanges) return; 271 272 var vp = VisualProperties; 173 273 IgnoreVisualPropertiesChanges = true; 174 274 try { 175 275 vp.LowerLeft = new Point2D<double>(LowerLeft.X, LowerLeft.Y); 176 276 vp.UpperRight = new Point2D<double>(UpperRight.X, UpperRight.Y); 277 vp.BrushColor = ((SolidBrush)Brush).Color; 278 vp.PenColor = Pen.Color; 177 279 } finally { IgnoreVisualPropertiesChanges = false; } 280 } 281 282 private void AdjustSize() { 283 if (networkItem == null) return; 284 285 var p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height)); 286 int margin = 4, x = p.X, y = p.Y; 287 using (var headerFont = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25), FontStyle.Bold)) 288 using (var contentFont = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25))) { 289 x += 2 * margin; y += 2 * margin; 290 int headerWidth = networkItem.ItemImage.Width + margin + TextRenderer.MeasureText(networkItem.Name, headerFont).Width; 291 y += networkItem.ItemImage.Height + margin; 292 int maxPortWidth = 0, maxPortParamWidth = 0; 293 foreach (var port in networkItem.Ports) { 294 int portWidth = port.ItemImage.Width + margin + TextRenderer.MeasureText(port.Name, contentFont).Width; 295 if (portWidth > maxPortWidth) maxPortWidth = portWidth; 296 y += margin + port.ItemImage.Height; 297 var parameterizedPort = port as IParameterizedPort; 298 if (parameterizedPort != null) { 299 foreach (var param in parameterizedPort.Parameters) { 300 int portParamWidth = param.ItemImage.Width + 3 * margin + TextRenderer.MeasureText(param.Name, contentFont).Width; 301 if (portParamWidth > maxPortParamWidth) maxPortParamWidth = portParamWidth; 302 y += margin + param.ItemImage.Height; 303 } 304 } 305 } 306 307 x += Math.Max(headerWidth, Math.Max(maxPortWidth, maxPortParamWidth)); 308 var ll = Chart.TransformPixelToWorld(new Point(p.X, y)); 309 var ur = Chart.TransformPixelToWorld(new Point(x, p.Y)); 310 SetPosition(ll, ur); 311 } 178 312 } 179 313 #endregion -
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 -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/AlgorithmNode.cs
r13459 r13799 59 59 } 60 60 61 [Storable] 62 private IItemCollection<IAlgorithm> startedAlgorithms; 63 public IItemCollection<IAlgorithm> StartedAlgorithms { 64 get { return startedAlgorithms; } 65 } 66 61 67 [StorableConstructor] 62 68 protected AlgorithmNode(bool deserializing) : base(deserializing) { } … … 65 71 algorithm = cloner.Clone(original.algorithm); 66 72 runs = cloner.Clone(original.runs); 73 startedAlgorithms = cloner.Clone(original.startedAlgorithms); 74 RegisterStartedAlgorithmsEvents(); 67 75 } 68 76 public AlgorithmNode() 69 77 : base("AlgorithmNode") { 70 78 runs = new RunCollection(); 71 } 79 startedAlgorithms = new ItemCollection<IAlgorithm>(); 80 RegisterStartedAlgorithmsEvents(); 81 } 82 72 83 public AlgorithmNode(string name) 73 84 : base(name) { 74 85 runs = new RunCollection(); 86 startedAlgorithms = new ItemCollection<IAlgorithm>(); 87 RegisterStartedAlgorithmsEvents(); 75 88 } 76 89 public AlgorithmNode(string name, string description) 77 90 : base(name, description) { 78 91 runs = new RunCollection(); 92 startedAlgorithms = new ItemCollection<IAlgorithm>(); 93 RegisterStartedAlgorithmsEvents(); 79 94 } 80 95 81 96 public override IDeepCloneable Clone(Cloner cloner) { 82 97 return new AlgorithmNode(this, cloner); 98 } 99 100 [StorableHook(HookType.AfterDeserialization)] 101 private void AfterDeserialization() { 102 RegisterStartedAlgorithmsEvents(); 103 } 104 105 protected virtual void RegisterStartedAlgorithmsEvents() { 106 startedAlgorithms.ItemsAdded += StartedAlgorithms_ItemsChanged; 107 startedAlgorithms.ItemsRemoved += StartedAlgorithms_ItemsChanged; 108 } 109 110 private void StartedAlgorithms_ItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IAlgorithm> e) { 111 OnStartedAlgorithmsChanged(); 83 112 } 84 113 … … 146 175 algorithm.Prepare(true); 147 176 algorithm.ExceptionOccurred += (sender, args) => { exception = args.Value; }; 148 algorithm.Started += (sender, args) => { started.Set(); };149 algorithm.Stopped += (sender, args) => { stopped.Set(); };177 algorithm.Started += (sender, args) => { started.Set(); startedAlgorithms.Add((IAlgorithm)sender); }; 178 algorithm.Stopped += (sender, args) => { stopped.Set(); startedAlgorithms.Remove((IAlgorithm)sender); }; 150 179 algorithm.Start(); 151 180 stopped.WaitOne(); … … 175 204 } 176 205 206 public event EventHandler StartedAlgorithmsChanged; 207 protected virtual void OnStartedAlgorithmsChanged() { 208 var handler = StartedAlgorithmsChanged; 209 if (handler != null) handler(this, EventArgs.Empty); 210 } 211 177 212 #region Ports Events 178 213 protected override void RegisterPortsEvents() { -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/IAlgorithmNode.cs
r11577 r13799 20 20 #endregion 21 21 22 using System; 23 using HeuristicLab.Core; 22 24 using HeuristicLab.Core.Networks; 23 25 using HeuristicLab.Optimization; 24 using System;25 26 26 27 namespace HeuristicLab.Networks { … … 29 30 IAlgorithm Algorithm { get; set; } 30 31 RunCollection Runs { get; } 32 IItemCollection<IAlgorithm> StartedAlgorithms { get; } 31 33 32 34 event EventHandler AlgorithmChanged; 35 event EventHandler StartedAlgorithmsChanged; 33 36 } 34 37 }
Note: See TracChangeset
for help on using the changeset viewer.