Changeset 11538 for branches/OptimizationNetworks
- Timestamp:
- 11/12/14 01:43:03 (10 years ago)
- Location:
- branches/OptimizationNetworks
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/Core.Networks.Views/MessagePortView.Designer.cs
r11530 r11538 38 38 this.clearConnectedPortButton = new System.Windows.Forms.Button(); 39 39 this.connectedPortView = new HeuristicLab.Core.Networks.Views.PortView(); 40 this.clone ConnectedPortParametersButton = new System.Windows.Forms.Button();40 this.cloneParametersFromPortButton = new System.Windows.Forms.Button(); 41 41 this.sendMessageButton = new System.Windows.Forms.Button(); 42 42 this.splitContainer = new System.Windows.Forms.SplitContainer(); 43 43 this.portParameterCollectionView = new HeuristicLab.Core.Networks.Views.PortParameterCollectionView(); 44 this. messageCollectionView = new HeuristicLab.Core.Networks.Views.MessageCollectionView();45 this.l ogMessagesCheckBox = new System.Windows.Forms.CheckBox();44 this.lastMessageGroupBox = new System.Windows.Forms.GroupBox(); 45 this.lastMessageView = new HeuristicLab.Core.Networks.Views.MessageView(); 46 46 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 47 47 this.connectedPortGroupBox.SuspendLayout(); … … 50 50 this.splitContainer.Panel2.SuspendLayout(); 51 51 this.splitContainer.SuspendLayout(); 52 this.lastMessageGroupBox.SuspendLayout(); 52 53 this.SuspendLayout(); 53 54 // … … 112 113 this.connectedPortView.DragOver += new System.Windows.Forms.DragEventHandler(this.connectedPortView_DragEnterOver); 113 114 // 114 // clone ConnectedPortParametersButton115 // 116 this.clone ConnectedPortParametersButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Clone;117 this.clone ConnectedPortParametersButton.Location = new System.Drawing.Point(156, 101);118 this.clone ConnectedPortParametersButton.Name = "cloneConnectedPortParametersButton";119 this.clone ConnectedPortParametersButton.Size = new System.Drawing.Size(24, 24);120 this.clone ConnectedPortParametersButton.TabIndex = 5;121 this.toolTip.SetToolTip(this.clone ConnectedPortParametersButton, "Clone Parameters from Connected Port");122 this.clone ConnectedPortParametersButton.UseVisualStyleBackColor = true;123 this.clone ConnectedPortParametersButton.Click += new System.EventHandler(this.cloneConnectedPortParametersButton_Click);115 // cloneParametersFromPortButton 116 // 117 this.cloneParametersFromPortButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Clone; 118 this.cloneParametersFromPortButton.Location = new System.Drawing.Point(156, 101); 119 this.cloneParametersFromPortButton.Name = "cloneParametersFromPortButton"; 120 this.cloneParametersFromPortButton.Size = new System.Drawing.Size(24, 24); 121 this.cloneParametersFromPortButton.TabIndex = 5; 122 this.toolTip.SetToolTip(this.cloneParametersFromPortButton, "Clone parameters from another port"); 123 this.cloneParametersFromPortButton.UseVisualStyleBackColor = true; 124 this.cloneParametersFromPortButton.Click += new System.EventHandler(this.cloneParametersFromPortButton_Click); 124 125 // 125 126 // sendMessageButton … … 149 150 // splitContainer.Panel2 150 151 // 151 this.splitContainer.Panel2.Controls.Add(this.logMessagesCheckBox); 152 this.splitContainer.Panel2.Controls.Add(this.messageCollectionView); 152 this.splitContainer.Panel2.Controls.Add(this.lastMessageGroupBox); 153 153 this.splitContainer.Size = new System.Drawing.Size(645, 435); 154 154 this.splitContainer.SplitterDistance = 218; … … 167 167 this.portParameterCollectionView.TabIndex = 0; 168 168 // 169 // messageCollectionView 170 // 171 this.messageCollectionView.Caption = "MessageCollection View"; 172 this.messageCollectionView.Content = null; 173 this.messageCollectionView.Dock = System.Windows.Forms.DockStyle.Fill; 174 this.messageCollectionView.Location = new System.Drawing.Point(0, 0); 175 this.messageCollectionView.Name = "messageCollectionView"; 176 this.messageCollectionView.ReadOnly = false; 177 this.messageCollectionView.ShowDetails = true; 178 this.messageCollectionView.Size = new System.Drawing.Size(645, 213); 179 this.messageCollectionView.TabIndex = 0; 180 // 181 // logMessagesCheckBox 182 // 183 this.logMessagesCheckBox.AutoSize = true; 184 this.logMessagesCheckBox.Location = new System.Drawing.Point(156, 24); 185 this.logMessagesCheckBox.Name = "logMessagesCheckBox"; 186 this.logMessagesCheckBox.Size = new System.Drawing.Size(95, 17); 187 this.logMessagesCheckBox.TabIndex = 1; 188 this.logMessagesCheckBox.Text = "&Log Messages"; 189 this.logMessagesCheckBox.UseVisualStyleBackColor = true; 190 this.logMessagesCheckBox.CheckedChanged += new System.EventHandler(this.logMessagesCheckBox_CheckedChanged); 169 // lastMessageGroupBox 170 // 171 this.lastMessageGroupBox.Controls.Add(this.lastMessageView); 172 this.lastMessageGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; 173 this.lastMessageGroupBox.Location = new System.Drawing.Point(0, 0); 174 this.lastMessageGroupBox.Name = "lastMessageGroupBox"; 175 this.lastMessageGroupBox.Size = new System.Drawing.Size(645, 213); 176 this.lastMessageGroupBox.TabIndex = 0; 177 this.lastMessageGroupBox.TabStop = false; 178 this.lastMessageGroupBox.Text = "Last Message"; 179 // 180 // lastMessageView 181 // 182 this.lastMessageView.Caption = "Message View"; 183 this.lastMessageView.Content = null; 184 this.lastMessageView.Dock = System.Windows.Forms.DockStyle.Fill; 185 this.lastMessageView.Location = new System.Drawing.Point(3, 16); 186 this.lastMessageView.Name = "lastMessageView"; 187 this.lastMessageView.ReadOnly = true; 188 this.lastMessageView.Size = new System.Drawing.Size(639, 194); 189 this.lastMessageView.TabIndex = 0; 191 190 // 192 191 // MessagePortView … … 194 193 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 195 194 this.Controls.Add(this.sendMessageButton); 196 this.Controls.Add(this.clone ConnectedPortParametersButton);195 this.Controls.Add(this.cloneParametersFromPortButton); 197 196 this.Controls.Add(this.connectedPortGroupBox); 198 197 this.Controls.Add(this.splitContainer); … … 203 202 this.Controls.SetChildIndex(this.infoLabel, 0); 204 203 this.Controls.SetChildIndex(this.connectedPortGroupBox, 0); 205 this.Controls.SetChildIndex(this.clone ConnectedPortParametersButton, 0);204 this.Controls.SetChildIndex(this.cloneParametersFromPortButton, 0); 206 205 this.Controls.SetChildIndex(this.sendMessageButton, 0); 207 206 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); … … 209 208 this.splitContainer.Panel1.ResumeLayout(false); 210 209 this.splitContainer.Panel2.ResumeLayout(false); 211 this.splitContainer.Panel2.PerformLayout();212 210 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); 213 211 this.splitContainer.ResumeLayout(false); 212 this.lastMessageGroupBox.ResumeLayout(false); 214 213 this.ResumeLayout(false); 215 214 this.PerformLayout(); … … 223 222 protected System.Windows.Forms.Button clearConnectedPortButton; 224 223 protected System.Windows.Forms.Button setConnectedPortButton; 225 protected System.Windows.Forms.Button clone ConnectedPortParametersButton;224 protected System.Windows.Forms.Button cloneParametersFromPortButton; 226 225 protected System.Windows.Forms.Button sendMessageButton; 227 226 protected System.Windows.Forms.SplitContainer splitContainer; 228 227 protected PortParameterCollectionView portParameterCollectionView; 229 protected MessageCollectionView messageCollectionView;230 protected System.Windows.Forms.CheckBox logMessagesCheckBox;228 protected System.Windows.Forms.GroupBox lastMessageGroupBox; 229 protected MessageView lastMessageView; 231 230 232 231 -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/Core.Networks.Views/MessagePortView.cs
r11530 r11538 54 54 Content.ConnectedPortChanged -= Content_ConnectedPortChanged; 55 55 Content.PortConnectionValidChanged -= Content_PortConnectionValidChanged; 56 Content.L ogMessagesChanged -= Content_LogMessagesChanged;56 Content.LastMessageChanged -= Content_LastMessageChanged; 57 57 base.DeregisterContentEvents(); 58 58 } … … 61 61 Content.ConnectedPortChanged += Content_ConnectedPortChanged; 62 62 Content.PortConnectionValidChanged += Content_PortConnectionValidChanged; 63 Content.L ogMessagesChanged += Content_LogMessagesChanged;63 Content.LastMessageChanged += Content_LastMessageChanged; 64 64 } 65 65 … … 69 69 connectedPortView.Content = Content == null ? null : Content.ConnectedPort; 70 70 portParameterCollectionView.Content = Content == null ? null : Content.Parameters; 71 logMessagesCheckBox.Checked = Content == null ? false : Content.LogMessages; 72 messageCollectionView.Content = Content == null ? null : Content.Messages; 71 lastMessageView.Content = Content == null ? null : Content.LastMessage; 73 72 errorProvider.SetError(connectedPortView, ((Content == null) || Content.PortConnectionValid) ? string.Empty : "Port connection is not valid"); 74 73 } … … 81 80 clearConnectedPortButton.Enabled = Content != null && Content.ConnectedPort != null && !ReadOnly; 82 81 portParameterCollectionView.Enabled = Content != null && !ReadOnly; 83 cloneConnectedPortParametersButton.Enabled = Content != null && Content.ConnectedPort != null && !ReadOnly; 84 logMessagesCheckBox.Enabled = Content != null && !ReadOnly; 85 messageCollectionView.Enabled = Content != null && !ReadOnly; 82 cloneParametersFromPortButton.Enabled = Content != null && Content.ConnectedPort != null && !ReadOnly; 83 lastMessageView.Enabled = Content != null && !ReadOnly; 86 84 } 87 85 … … 91 89 else { 92 90 clearConnectedPortButton.Enabled = Content.ConnectedPort != null && !ReadOnly; 93 clone ConnectedPortParametersButton.Enabled = Content.ConnectedPort != null && !ReadOnly;91 cloneParametersFromPortButton.Enabled = Content.ConnectedPort != null && !ReadOnly; 94 92 connectedPortView.Content = Content.ConnectedPort; 95 93 } … … 102 100 } 103 101 } 104 protected virtual void Content_L ogMessagesChanged(object sender, EventArgs e) {102 protected virtual void Content_LastMessageChanged(object sender, EventArgs e) { 105 103 if (InvokeRequired) 106 Invoke(new EventHandler(Content_L ogMessagesChanged), sender, e);104 Invoke(new EventHandler(Content_LastMessageChanged), sender, e); 107 105 else { 108 l ogMessagesCheckBox.Checked = Content.LogMessages;106 lastMessageView.Content = Content.LastMessage; 109 107 } 110 108 } … … 115 113 116 114 protected virtual void setConnectedPortButton_Click(object sender, EventArgs e) { 117 if (networkItemSelectorDialog == null) { 118 networkItemSelectorDialog = new NetworkItemSelectorDialog(); 119 networkItemSelectorDialog.Caption = "Select Connected Port"; 120 networkItemSelectorDialog.NetworkItemSelector.Caption = "Available Ports"; 121 } 115 if (networkItemSelectorDialog == null) networkItemSelectorDialog = new NetworkItemSelectorDialog(); 116 networkItemSelectorDialog.Caption = "Select Connected Port"; 117 networkItemSelectorDialog.NetworkItemSelector.Caption = "Available Ports"; 122 118 123 119 try { … … 145 141 protected virtual void connectedPortView_DragEnterOver(object sender, DragEventArgs e) { 146 142 e.Effect = DragDropEffects.None; 147 var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as I MessagePort;143 var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IPort; 148 144 149 145 if (!ReadOnly && (data != null) && (Content.CanConnectToPort(data))) { … … 157 153 } 158 154 } 159 protected virtual void cloneConnectedPortParametersButton_Click(object sender, EventArgs e) { 160 Content.CloneParametersFromPort(Content.ConnectedPort); 161 } 162 protected virtual void logMessagesCheckBox_CheckedChanged(object sender, EventArgs e) { 163 Content.LogMessages = logMessagesCheckBox.Checked; 155 protected virtual void cloneParametersFromPortButton_Click(object sender, EventArgs e) { 156 if (networkItemSelectorDialog == null) networkItemSelectorDialog = new NetworkItemSelectorDialog(); 157 networkItemSelectorDialog.Caption = "Select Port to Clone Parameters from"; 158 networkItemSelectorDialog.NetworkItemSelector.Caption = "Available Ports"; 159 160 INetworkItem root = Content; 161 while (root.Parent != null) 162 root = root.Parent; 163 networkItemSelectorDialog.NetworkItemSelector.Configure( 164 root, 165 null, 166 typeof(IParameterizedPort) 167 ); 168 169 if (networkItemSelectorDialog.ShowDialog(this) == DialogResult.OK) { 170 Content.CloneParametersFromPort(networkItemSelectorDialog.NetworkItemSelector.SelectedNetworkItem as IParameterizedPort); 171 } 164 172 } 165 173 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/Core.Networks.Views/NetworkItemView.cs
r11528 r11538 22 22 using HeuristicLab.Core.Views; 23 23 using HeuristicLab.MainForm; 24 using System;25 24 using System.Windows.Forms; 26 25 … … 38 37 InitializeComponent(); 39 38 } 40 41 protected override void DeregisterContentEvents() {42 Content.PathChanged -= Content_PathChanged;43 base.DeregisterContentEvents();44 }45 protected override void RegisterContentEvents() {46 base.RegisterContentEvents();47 Content.PathChanged += Content_PathChanged;48 }49 50 protected override void OnContentChanged() {51 base.OnContentChanged();52 toolTip.SetToolTip(nameTextBox, Content != null ? Content.Path : string.Empty);53 }54 55 protected virtual void Content_PathChanged(object sender, System.EventArgs e) {56 if (InvokeRequired)57 Invoke(new EventHandler(Content_PathChanged), sender, e);58 else {59 toolTip.SetToolTip(nameTextBox, Content != null ? Content.Path : string.Empty);60 }61 }62 39 } 63 40 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Core.Networks/IMessagePort.cs
r11530 r11538 26 26 27 27 namespace HeuristicLab.Core.Networks { 28 public interface IMessagePort : IParameterizedPort { 29 IMessagePort ConnectedPort { get; set; } 30 bool PortConnectionValid { get; } 31 bool LogMessages { get; set; } 32 MessageCollection Messages { get; } 28 public interface IMessagePort : IParameterizedPort, IConnectablePort { 29 new IMessagePort ConnectedPort { get; set; } 33 30 34 bool CanConnectToPort(IPort port); 35 36 event EventHandler ConnectedPortChanged; 37 event EventHandler PortConnectionValidChanged; 38 event EventHandler LogMessagesChanged; 31 IMessage LastMessage { get; } 32 event EventHandler LastMessageChanged; 39 33 40 34 IMessage PrepareMessage(); -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Core.Networks/INetworkItem.cs
r11528 r11538 27 27 INetworkItem Parent { get; } 28 28 IEnumerable<INetworkItem> Children { get; } 29 string Path { get; }30 event EventHandler PathChanged;31 29 } 32 30 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Core.Networks/MessagePort.cs
r11530 r11538 54 54 RegisterConnectedPortEvents(); 55 55 OnConnectedPortChanged(); 56 OnInterfaceChanged(); 57 } 56 CheckPortConnection(); 57 } 58 } 59 } 60 IPort IConnectablePort.ConnectedPort { 61 get { return ConnectedPort; } 62 set { 63 if (!(value is IMessagePort)) 64 throw new InvalidOperationException("Type mismatch. ConnectedPort is not an IMessagePort."); 65 ConnectedPort = (IMessagePort)value; 58 66 } 59 67 } … … 71 79 } 72 80 [Storable] 73 protected bool logMessages; 74 public bool LogMessages { 75 get { return logMessages; } 76 set { 77 if (value != logMessages) { 78 logMessages = value; 79 OnLogMessagesChanged(); 80 } 81 } 82 } 83 [Storable] 84 protected MessageCollection messages; 85 public MessageCollection Messages { 86 get { return messages; } 81 protected IMessage lastMessage; 82 public IMessage LastMessage { 83 get { return lastMessage; } 84 protected set { 85 if (value != lastMessage) { 86 lastMessage = value; 87 OnLastMessageChanged(); 88 } 89 } 87 90 } 88 91 … … 93 96 connectedPort = cloner.Clone(original.connectedPort); 94 97 portConnectionValid = original.portConnectionValid; 95 logMessages = original.logMessages; 96 messages = cloner.Clone(original.messages); 98 lastMessage = null; 97 99 RegisterConnectedPortEvents(); 98 100 } … … 100 102 : base("MessagePort") { 101 103 portConnectionValid = true; 102 logMessages = false; 103 messages = new MessageCollection(); 104 lastMessage = null; 104 105 } 105 106 public MessagePort(string name) 106 107 : base(name) { 107 108 portConnectionValid = true; 108 logMessages = false; 109 messages = new MessageCollection(); 109 lastMessage = null; 110 110 } 111 111 public MessagePort(string name, string description) 112 112 : base(name, description) { 113 113 portConnectionValid = true; 114 logMessages = false; 115 messages = new MessageCollection(); 114 lastMessage = null; 116 115 } 117 116 … … 126 125 127 126 public bool CanConnectToPort(IPort port) { 128 if (port == null) return true; 129 130 var p = port as IMessagePort; 131 if (p == null) return false; 132 133 // check if the local parameters are compatible to the input parameters of the port 134 if (!ParametersCompatibleToTarget(Parameters, p.Parameters)) return false; 135 // check if the parameters of the port are compatible to the local input parameters 136 if (!ParametersCompatibleToTarget(p.Parameters, Parameters)) return false; 137 138 return true; 127 return (port == null) || (port is IMessagePort); 139 128 } 140 129 … … 162 151 public void SendMessage(IMessage message, CancellationToken token) { 163 152 if (!PortConnectionValid) throw new InvalidOperationException("Port connection is not valid"); 164 if (LogMessages) Messages.Add(message);153 LastMessage = message; 165 154 if (ConnectedPort != null) ConnectedPort.ReceiveMessage(message, token); 166 155 OnMessageSent(message, token); … … 180 169 public void ReceiveMessage(IMessage message, CancellationToken token) { 181 170 if (!PortConnectionValid) throw new InvalidOperationException("Port connection is not valid"); 182 if (LogMessages) Messages.Add(message);171 LastMessage = message; 183 172 OnMessageReceived(message, token); 184 173 } … … 199 188 if (handler != null) handler(this, EventArgs.Empty); 200 189 } 201 public event EventHandler L ogMessagesChanged;202 protected virtual void OnL ogMessagesChanged() {203 var handler = L ogMessagesChanged;190 public event EventHandler LastMessageChanged; 191 protected virtual void OnLastMessageChanged() { 192 var handler = LastMessageChanged; 204 193 if (handler != null) handler(this, EventArgs.Empty); 205 194 } 206 195 207 196 protected override void OnInterfaceChanged() { 208 PortConnectionValid = CanConnectToPort(connectedPort);197 CheckPortConnection(); 209 198 base.OnInterfaceChanged(); 210 199 } … … 224 213 } 225 214 protected virtual void ConnectedPort_InterfaceChanged(object sender, EventArgs e) { 226 OnInterfaceChanged();215 CheckPortConnection(); 227 216 } 228 217 protected virtual void ConnectedPort_MessageSent(object sender, EventArgs<IMessage, CancellationToken> e) { … … 232 221 233 222 #region Helpers 223 protected virtual void CheckPortConnection() { 224 PortConnectionValid = (ConnectedPort == null) || 225 (ParametersCompatibleToTarget(Parameters, ConnectedPort.Parameters) && 226 ParametersCompatibleToTarget(ConnectedPort.Parameters, Parameters)); 227 } 234 228 protected virtual bool ParametersCompatibleToTarget(IEnumerable<IPortParameter> source, IEnumerable<IPortParameter> target) { 235 229 // checks if the source parameters are compatible to the input parameters of the target -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Core.Networks/NetworkItem.cs
r11528 r11538 31 31 [StorableClass] 32 32 public abstract class NetworkItem : NamedItem, INetworkItem { 33 public static readonly string PathSeparator = " => ";34 33 public static new Image StaticItemImage { 35 34 get { return HeuristicLab.Common.Resources.VSImageLibrary.Class; } … … 41 40 protected set { 42 41 if (value != parent) { 43 DeregisterParentEvents();44 42 parent = value; 45 RegisterParentEvents();46 OnPathChanged();47 43 } 48 44 } … … 50 46 public virtual IEnumerable<INetworkItem> Children { 51 47 get { return Enumerable.Empty<INetworkItem>(); } 52 }53 public string Path {54 get {55 return parent != null ? parent.Path + PathSeparator + Name : Name;56 }57 48 } 58 49 … … 63 54 protected NetworkItem(string name) : base(name) { } 64 55 protected NetworkItem(string name, string description) : base(name, description) { } 65 66 protected override void OnNameChanging(CancelEventArgs<string> e) {67 base.OnNameChanging(e);68 e.Cancel = e.Cancel || e.Value.Contains(PathSeparator);69 }70 protected override void OnNameChanged() {71 base.OnNameChanged();72 OnPathChanged();73 }74 75 public event EventHandler PathChanged;76 protected virtual void OnPathChanged() {77 var handler = PathChanged;78 if (handler != null) handler(this, EventArgs.Empty);79 }80 81 #region Parent Events82 protected virtual void RegisterParentEvents() {83 if (parent != null) {84 parent.PathChanged += Parent_PathChanged;85 }86 }87 protected virtual void DeregisterParentEvents() {88 if (parent != null) {89 parent.PathChanged -= Parent_PathChanged;90 }91 }92 void Parent_PathChanged(object sender, EventArgs e) {93 OnPathChanged();94 }95 #endregion96 56 } 97 57 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/HeuristicLab.Optimization.Networks-3.3.csproj
r11530 r11538 90 90 </ItemGroup> 91 91 <ItemGroup> 92 <Compile Include="Core.Networks\IConnectablePort.cs" /> 92 93 <Compile Include="Core.Networks\IUserDefinedMessagePort.cs" /> 93 94 <Compile Include="Core.Networks\IMessagePort.cs" />
Note: See TracChangeset
for help on using the changeset viewer.