Changeset 11501
- Timestamp:
- 10/25/14 02:54:42 (10 years ago)
- Location:
- branches/OptimizationNetworks
- Files:
-
- 8 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/GenericPortView.Designer.cs
r11500 r11501 39 39 this.connectedPortView = new HeuristicLab.Optimization.Networks.Views.PortView(); 40 40 this.cloneConnectedPortParametersButton = new System.Windows.Forms.Button(); 41 this.sendMessageButton = new System.Windows.Forms.Button(); 42 this.splitContainer = new System.Windows.Forms.SplitContainer(); 43 this.portParameterCollectionView = new HeuristicLab.Optimization.Networks.Views.PortParameterCollectionView(); 44 this.messageCollectionView = new HeuristicLab.Optimization.Networks.Views.MessageCollectionView(); 41 45 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 42 46 this.connectedPortGroupBox.SuspendLayout(); 47 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 48 this.splitContainer.Panel1.SuspendLayout(); 49 this.splitContainer.Panel2.SuspendLayout(); 50 this.splitContainer.SuspendLayout(); 43 51 this.SuspendLayout(); 44 //45 // portParameterCollectionView46 //47 this.portParameterCollectionView.Location = new System.Drawing.Point(0, 82);48 this.portParameterCollectionView.Size = new System.Drawing.Size(645, 435);49 this.portParameterCollectionView.TabIndex = 4;50 52 // 51 53 // nameTextBox … … 53 55 this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft); 54 56 this.errorProvider.SetIconPadding(this.nameTextBox, 2); 55 this.nameTextBox.Location = new System.Drawing.Point( 71, 0);56 this.nameTextBox.Size = new System.Drawing.Size(5 49, 20);57 this.nameTextBox.Location = new System.Drawing.Point(47, 0); 58 this.nameTextBox.Size = new System.Drawing.Size(573, 20); 57 59 // 58 60 // connectedPortGroupBox … … 63 65 this.connectedPortGroupBox.Controls.Add(this.clearConnectedPortButton); 64 66 this.connectedPortGroupBox.Controls.Add(this.connectedPortView); 65 this.connectedPortGroupBox.Location = new System.Drawing.Point( 0, 26);67 this.connectedPortGroupBox.Location = new System.Drawing.Point(47, 26); 66 68 this.connectedPortGroupBox.Name = "connectedPortGroupBox"; 67 this.connectedPortGroupBox.Size = new System.Drawing.Size( 645, 50);68 this.connectedPortGroupBox.TabIndex = 3;69 this.connectedPortGroupBox.Size = new System.Drawing.Size(598, 50); 70 this.connectedPortGroupBox.TabIndex = 4; 69 71 this.connectedPortGroupBox.TabStop = false; 70 72 this.connectedPortGroupBox.Text = "&Connected Port"; … … 101 103 this.connectedPortView.Name = "connectedPortView"; 102 104 this.connectedPortView.ReadOnly = true; 103 this.connectedPortView.Size = new System.Drawing.Size(5 54, 23);105 this.connectedPortView.Size = new System.Drawing.Size(507, 23); 104 106 this.connectedPortView.TabIndex = 2; 105 107 this.connectedPortView.DragDrop += new System.Windows.Forms.DragEventHandler(this.connectedPortView_DragDrop); … … 118 120 this.cloneConnectedPortParametersButton.Click += new System.EventHandler(this.cloneConnectedPortParametersButton_Click); 119 121 // 122 // sendMessageButton 123 // 124 this.sendMessageButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Exception; 125 this.sendMessageButton.Location = new System.Drawing.Point(6, 45); 126 this.sendMessageButton.Name = "sendMessageButton"; 127 this.sendMessageButton.Size = new System.Drawing.Size(24, 24); 128 this.sendMessageButton.TabIndex = 3; 129 this.toolTip.SetToolTip(this.sendMessageButton, "Send Message"); 130 this.sendMessageButton.UseVisualStyleBackColor = true; 131 this.sendMessageButton.Click += new System.EventHandler(this.sendMessageButton_Click); 132 // 133 // splitContainer 134 // 135 this.splitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 136 | System.Windows.Forms.AnchorStyles.Left) 137 | System.Windows.Forms.AnchorStyles.Right))); 138 this.splitContainer.Location = new System.Drawing.Point(0, 82); 139 this.splitContainer.Name = "splitContainer"; 140 this.splitContainer.Orientation = System.Windows.Forms.Orientation.Horizontal; 141 // 142 // splitContainer.Panel1 143 // 144 this.splitContainer.Panel1.Controls.Add(this.portParameterCollectionView); 145 // 146 // splitContainer.Panel2 147 // 148 this.splitContainer.Panel2.Controls.Add(this.messageCollectionView); 149 this.splitContainer.Size = new System.Drawing.Size(645, 435); 150 this.splitContainer.SplitterDistance = 218; 151 this.splitContainer.TabIndex = 7; 152 // 153 // portParameterCollectionView 154 // 155 this.portParameterCollectionView.Caption = "PortParameterCollection View"; 156 this.portParameterCollectionView.Content = null; 157 this.portParameterCollectionView.Dock = System.Windows.Forms.DockStyle.Fill; 158 this.portParameterCollectionView.Location = new System.Drawing.Point(0, 0); 159 this.portParameterCollectionView.Name = "portParameterCollectionView"; 160 this.portParameterCollectionView.ReadOnly = false; 161 this.portParameterCollectionView.ShowDetails = true; 162 this.portParameterCollectionView.Size = new System.Drawing.Size(645, 218); 163 this.portParameterCollectionView.TabIndex = 0; 164 // 165 // messageCollectionView 166 // 167 this.messageCollectionView.Caption = "MessageCollection View"; 168 this.messageCollectionView.Content = null; 169 this.messageCollectionView.Dock = System.Windows.Forms.DockStyle.Fill; 170 this.messageCollectionView.Location = new System.Drawing.Point(0, 0); 171 this.messageCollectionView.Name = "messageCollectionView"; 172 this.messageCollectionView.ReadOnly = false; 173 this.messageCollectionView.ShowDetails = true; 174 this.messageCollectionView.Size = new System.Drawing.Size(645, 213); 175 this.messageCollectionView.TabIndex = 0; 176 // 120 177 // GenericPortView 121 178 // 122 179 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 180 this.Controls.Add(this.sendMessageButton); 123 181 this.Controls.Add(this.cloneConnectedPortParametersButton); 124 182 this.Controls.Add(this.connectedPortGroupBox); 183 this.Controls.Add(this.splitContainer); 125 184 this.Name = "GenericPortView"; 126 this.Controls.SetChildIndex(this. portParameterCollectionView, 0);185 this.Controls.SetChildIndex(this.splitContainer, 0); 127 186 this.Controls.SetChildIndex(this.nameLabel, 0); 128 187 this.Controls.SetChildIndex(this.nameTextBox, 0); … … 130 189 this.Controls.SetChildIndex(this.connectedPortGroupBox, 0); 131 190 this.Controls.SetChildIndex(this.cloneConnectedPortParametersButton, 0); 191 this.Controls.SetChildIndex(this.sendMessageButton, 0); 132 192 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); 133 193 this.connectedPortGroupBox.ResumeLayout(false); 194 this.splitContainer.Panel1.ResumeLayout(false); 195 this.splitContainer.Panel2.ResumeLayout(false); 196 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); 197 this.splitContainer.ResumeLayout(false); 134 198 this.ResumeLayout(false); 135 199 this.PerformLayout(); … … 144 208 protected System.Windows.Forms.Button setConnectedPortButton; 145 209 protected System.Windows.Forms.Button cloneConnectedPortParametersButton; 210 protected System.Windows.Forms.Button sendMessageButton; 211 protected System.Windows.Forms.SplitContainer splitContainer; 212 protected PortParameterCollectionView portParameterCollectionView; 213 protected MessageCollectionView messageCollectionView; 146 214 147 215 -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/GenericPortView.cs
r11500 r11501 29 29 [Content(typeof(GenericPort), true)] 30 30 [Content(typeof(IGenericPort), false)] 31 public partial class GenericPortView : P arameterizedPortView {31 public partial class GenericPortView : PortView { 32 32 protected EntitySelectorDialog entitySelectorDialog; 33 33 … … 52 52 53 53 protected override void DeregisterContentEvents() { 54 Content.InterfaceChanged -= Content_InterfaceChanged; 54 55 Content.ConnectedPortChanged -= Content_ConnectedPortChanged; 55 56 base.DeregisterContentEvents(); … … 57 58 protected override void RegisterContentEvents() { 58 59 base.RegisterContentEvents(); 60 Content.InterfaceChanged += Content_InterfaceChanged; 59 61 Content.ConnectedPortChanged += Content_ConnectedPortChanged; 60 62 } … … 63 65 base.OnContentChanged(); 64 66 connectedPortView.Content = Content == null ? null : Content.ConnectedPort; 67 portParameterCollectionView.Content = Content == null ? null : Content.Parameters; 68 messageCollectionView.Content = Content == null ? null : Content.Messages; 65 69 errorProvider.SetError(connectedPortView, ((Content == null) || Content.PortConnectionValid) ? string.Empty : "Port connection is not valid"); 66 70 } … … 68 72 protected override void SetEnabledStateOfControls() { 69 73 base.SetEnabledStateOfControls(); 74 sendMessageButton.Enabled = Content != null; 70 75 connectedPortGroupBox.Enabled = Content != null && !ReadOnly; 71 76 setConnectedPortButton.Enabled = Content != null && !ReadOnly; 72 77 clearConnectedPortButton.Enabled = Content != null && Content.ConnectedPort != null && !ReadOnly; 78 portParameterCollectionView.Enabled = Content != null && !ReadOnly; 73 79 cloneConnectedPortParametersButton.Enabled = Content != null && Content.ConnectedPort != null && !ReadOnly; 80 messageCollectionView.Enabled = Content != null && !ReadOnly; 74 81 } 75 82 … … 83 90 } 84 91 } 85 protected overridevoid Content_InterfaceChanged(object sender, EventArgs e) {92 protected virtual void Content_InterfaceChanged(object sender, EventArgs e) { 86 93 if (InvokeRequired) 87 94 Invoke(new EventHandler(Content_InterfaceChanged), sender, e); 88 95 else { 89 base.Content_InterfaceChanged(sender, e);90 96 errorProvider.SetError(connectedPortView, Content.PortConnectionValid ? string.Empty : "Port connection is not valid"); 91 97 } 98 } 99 100 protected virtual void sendMessageButton_Click(object sender, EventArgs e) { 101 Content.SendMessageAsync(Content.PrepareMessage()); 92 102 } 93 103 -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/HeuristicLab.Optimization.Networks.Views-3.3.csproj
r11500 r11501 115 115 <DependentUpon>InputPortView.cs</DependentUpon> 116 116 </Compile> 117 <Compile Include="MessageCollectionView.cs"> 118 <SubType>UserControl</SubType> 119 </Compile> 120 <Compile Include="MessageCollectionView.Designer.cs"> 121 <DependentUpon>MessageCollectionView.cs</DependentUpon> 122 </Compile> 117 123 <Compile Include="### obsolete\ServiceParameterCollectionCollectionView.cs"> 118 124 <SubType>UserControl</SubType> … … 168 174 <Compile Include="MessageView.Designer.cs"> 169 175 <DependentUpon>MessageView.cs</DependentUpon> 176 </Compile> 177 <Compile Include="GenericNodeView.cs"> 178 <SubType>UserControl</SubType> 179 </Compile> 180 <Compile Include="GenericNodeView.Designer.cs"> 181 <DependentUpon>GenericNodeView.cs</DependentUpon> 170 182 </Compile> 171 183 <Compile Include="ParameterizedPortView.cs"> -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/HeuristicLab.Optimization.Networks-3.3.csproj
r11500 r11501 108 108 <Compile Include="### obsolete\ServiceParameter.cs" /> 109 109 <Compile Include="### obsolete\ServiceParameterCollection.cs" /> 110 <Compile Include="Nodes\GenericNode.cs" /> 111 <Compile Include="Nodes\IGenericNode.cs" /> 112 <Compile Include="Ports\MessageCollection.cs" /> 110 113 <Compile Include="### obsolete\ServiceParameterCollectionCollection.cs" /> 111 114 <Compile Include="### obsolete\ServiceParameterType.cs" /> -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Nodes/AlgorithmServiceNode.cs
r11500 r11501 82 82 } 83 83 84 private void UpdateParameter(IInputPort port) { 85 if (template != null) { 86 IParameter param = null; 87 if (template.Parameters.TryGetValue(port.Name, out param)) { 88 IValueParameter p = param as IValueParameter; 89 if ((p != null) && (port.Value != null)) { 90 p.Value = (IItem)port.Value; 84 protected virtual void UpdateParameters(IMessage message, CancellationToken token) { 85 // set template parameters 86 lock (locker) { 87 if (template != null) { 88 foreach (var v in message.Values) { 89 IParameter param = null; 90 if (Template.Parameters.TryGetValue(v.Name, out param)) { 91 var vp = param as IValueParameter; 92 if (vp != null) vp.Value = v.Value; 93 } 94 if (Template.Problem.Parameters.TryGetValue(v.Name, out param)) { 95 var vp = param as IValueParameter; 96 if (vp != null) vp.Value = v.Value; 97 } 91 98 } 92 99 } … … 94 101 } 95 102 96 protected virtual void Execute( ServiceParameterCollection parameters, CancellationToken token) {103 protected virtual void Execute(IMessage message, CancellationToken token) { 97 104 if (Template == null) throw new InvalidOperationException("Template is null"); 98 105 … … 104 111 105 112 // set parameters 106 foreach (var p in parameters.Where(x => x.Type == ServiceParameterType.Input)) {113 foreach (var v in message.Values) { 107 114 IParameter param = null; 108 if (algorithm.Parameters.TryGetValue( p.Name, out param)) {109 var v = param as IValueParameter;110 if (v != null) v.Value = p.Value;111 } 112 if (algorithm.Problem.Parameters.TryGetValue( p.Name, out param)) {113 var v = param as IValueParameter;114 if (v != null) v.Value = p.Value;115 if (algorithm.Parameters.TryGetValue(v.Name, out param)) { 116 var vp = param as IValueParameter; 117 if (vp != null) vp.Value = v.Value; 118 } 119 if (algorithm.Problem.Parameters.TryGetValue(v.Name, out param)) { 120 var vp = param as IValueParameter; 121 if (vp != null) vp.Value = v.Value; 115 122 } 116 123 } … … 140 147 // retrieve results 141 148 var run = algorithm.Runs.First(); 142 foreach (var p in parameters.Where(x => x.Type == ServiceParameterType.Output)) {149 foreach (var v in message.Values) { 143 150 IItem result = null; 144 if (run.Results.TryGetValue( p.Name, out result)) {145 p.Value = result;151 if (run.Results.TryGetValue(v.Name, out result)) { 152 v.Value = result; 146 153 } 147 154 } … … 205 212 #region Port Events 206 213 private void RegisterPortEvents(IPort port) { 207 IInputPort i = port as IInputPort; 208 if (i != null) { 209 i.NameChanged += InputPort_NameChanged; 210 i.ValueChanged += InputPort_ValueChanged; 211 UpdateParameter(i); 212 } 213 IServicePort s = port as IServicePort; 214 if (s != null) { 215 s.ProcessParameters += ServicePort_ProcessParameters; 216 } 217 } 218 214 IGenericPort g = port as IGenericPort; 215 if (g != null) { 216 g.MessageReceived += GenericPort_MessageReceived; 217 } 218 } 219 219 private void DeregisterPortEvents(IPort port) { 220 IInputPort i = port as IInputPort; 221 if (i != null) { 222 i.NameChanged -= InputPort_NameChanged; 223 i.ValueChanged -= InputPort_ValueChanged; 224 } 225 IServicePort s = port as IServicePort; 226 if (s != null) { 227 s.ProcessParameters -= ServicePort_ProcessParameters; 228 } 229 } 230 private void InputPort_NameChanged(object sender, EventArgs e) { 231 UpdateParameter((IInputPort)sender); 232 } 233 private void InputPort_ValueChanged(object sender, EventArgs e) { 234 UpdateParameter((IInputPort)sender); 235 } 236 private void ServicePort_ProcessParameters(object sender, EventArgs<ServiceParameterCollection, CancellationToken> e) { 237 Execute(e.Value, e.Value2); 220 IGenericPort g = port as IGenericPort; 221 if (g != null) { 222 g.MessageReceived -= GenericPort_MessageReceived; 223 } 224 } 225 private void GenericPort_MessageReceived(object sender, EventArgs<IMessage, CancellationToken> e) { 226 var port = (IGenericPort)sender; 227 if (port.Parameters.Any(p => p.Type.HasFlag(PortParameterType.Output))) 228 Execute(e.Value, e.Value2); // execute algorithm to compute output 229 else 230 UpdateParameters(e.Value, e.Value2); // update template parameters 238 231 } 239 232 #endregion -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/GenericPort.cs
r11500 r11501 65 65 } 66 66 } 67 [Storable] 68 protected MessageCollection messages; 69 public MessageCollection Messages { 70 get { return messages; } 71 } 67 72 68 73 [StorableConstructor] 69 74 protected GenericPort(bool deserializing) : base(deserializing) { } 70 protected GenericPort(GenericPort original, Cloner cloner) : base(original, cloner) { 75 protected GenericPort(GenericPort original, Cloner cloner) 76 : base(original, cloner) { 71 77 connectedPort = cloner.Clone(original.connectedPort); 72 78 portConnectionValid = original.portConnectionValid; 79 messages = cloner.Clone(original.messages); 73 80 RegisterConnectedPortEvents(); 74 81 } 75 public GenericPort() : base("GenericPort") { } 76 public GenericPort(string name) : base(name) { } 77 public GenericPort(string name, string description) : base(name, description) { } 82 public GenericPort() 83 : base("GenericPort") { 84 portConnectionValid = true; 85 messages = new MessageCollection(); 86 } 87 public GenericPort(string name) 88 : base(name) { 89 portConnectionValid = true; 90 messages = new MessageCollection(); 91 } 92 public GenericPort(string name, string description) 93 : base(name, description) { 94 portConnectionValid = true; 95 messages = new MessageCollection(); 96 } 78 97 79 98 [StorableHook(HookType.AfterDeserialization)] … … 164 183 public void SendMessage(IMessage message, CancellationToken token) { 165 184 if (!PortConnectionValid) throw new InvalidOperationException("Port connection is not valid"); 185 Messages.Add(message); 166 186 if (ConnectedPort != null) ConnectedPort.ReceiveMessage(message, token); 167 187 OnMessageSent(message, token); … … 180 200 181 201 public void ReceiveMessage(IMessage message, CancellationToken token) { 202 if (!PortConnectionValid) throw new InvalidOperationException("Port connection is not valid"); 203 Messages.Add(message); 182 204 OnMessageReceived(message, token); 183 205 } … … 195 217 196 218 protected override void OnInterfaceChanged() { 197 PortConnectionValid = (connectedPort != null) &&CanConnectToPort(connectedPort);219 PortConnectionValid = CanConnectToPort(connectedPort); 198 220 base.OnInterfaceChanged(); 199 221 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/IGenericPort.cs
r11500 r11501 29 29 IConnectedPort ConnectedPort { get; set; } 30 30 bool PortConnectionValid { get; } 31 MessageCollection Messages { get; } 31 32 32 33 event EventHandler ConnectedPortChanged; -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/PortParameter.cs
r11500 r11501 35 35 public override Image ItemImage { 36 36 get { 37 if (Type == PortParameterType.Input) return HeuristicLab.Common.Resources.VSImageLibrary.ArrowDown; 38 else if (Type == PortParameterType.Output) return HeuristicLab.Common.Resources.VSImageLibrary.ArrowUp; 39 else return base.ItemImage; 37 if (Type.HasFlag(PortParameterType.Input) && Type.HasFlag(PortParameterType.Output)) 38 return HeuristicLab.Common.Resources.VSImageLibrary.Field; 39 else if (Type.HasFlag(PortParameterType.Input)) 40 return HeuristicLab.Common.Resources.VSImageLibrary.ArrowDown; 41 else if (Type.HasFlag(PortParameterType.Output)) 42 return HeuristicLab.Common.Resources.VSImageLibrary.ArrowUp; 43 else 44 return base.ItemImage; 40 45 } 41 46 } … … 96 101 RegisterDefaultValueEvents(); 97 102 } 98 public PortParameter() : base("PortParameter") { } 99 public PortParameter(string name) : base(name) { } 100 public PortParameter(string name, string description) : base(name, description) { } 103 public PortParameter() 104 : base("PortParameter") { 105 type = PortParameterType.Input; 106 } 107 public PortParameter(string name) 108 : base(name) { 109 type = PortParameterType.Input; 110 } 111 public PortParameter(string name, string description) 112 : base(name, description) { 113 type = PortParameterType.Input; 114 } 101 115 102 116 [StorableHook(HookType.AfterDeserialization)] -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/PortParameterType.cs
r11500 r11501 25 25 [Flags] 26 26 public enum PortParameterType { 27 None = 0, 27 28 Input = 1, 28 29 Output = 2
Note: See TracChangeset
for help on using the changeset viewer.