Changeset 12689 for branches/HiveStatistics/sources/HeuristicLab.Optimizer
- Timestamp:
- 07/08/15 15:32:12 (9 years ago)
- Location:
- branches/HiveStatistics/sources
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources
-
branches/HiveStatistics/sources/HeuristicLab.Optimizer
- Property svn:mergeinfo changed
/branches/EnumValue in CreateExperiment/HeuristicLab.Optimizer (added) merged: 12251-12252,12254,12267-12268,12466,12513,12678 /trunk/sources/HeuristicLab.Optimizer merged: 12649,12680
- Property svn:mergeinfo changed
-
branches/HiveStatistics/sources/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.cs
r12293 r12689 169 169 else boolParameters.Remove(parameter); 170 170 } 171 172 bool isEnumValue = parameter.Value != null && parameter.Value.GetType().IsGenericType 173 && typeof(EnumValue<>).IsAssignableFrom(parameter.Value.GetType().GetGenericTypeDefinition()); 174 if (isEnumValue) { 175 if (e.Item.Checked) multipleChoiceParameters.Add(parameter, new HashSet<IItem>(new EnumValueEqualityComparer())); 176 else multipleChoiceParameters.Remove(parameter); 177 } 171 178 } 172 179 … … 192 199 isOptionalConstrainedValueParameter 193 200 || typeof(ConstrainedValueParameter<>).Equals(parameter.GetType().GetGenericTypeDefinition()); 194 195 if (isConstrainedValueParameter) { 201 bool isEnumValue = parameter.Value != null && parameter.Value.GetType().IsGenericType 202 && typeof(EnumValue<>).IsAssignableFrom(parameter.Value.GetType().GetGenericTypeDefinition()); 203 204 if (isConstrainedValueParameter || isEnumValue) { 196 205 detailsTypeLabel.Text = "Choices:"; 197 206 choicesListView.Tag = parameter; 198 207 199 if (isOptionalConstrainedValueParameter) { 200 choicesListView.Items.Add(new ListViewItem("-") { 201 Tag = optionalNullChoice, 202 Checked = multipleChoiceParameters.ContainsKey(parameter) 203 && multipleChoiceParameters[parameter].Contains(optionalNullChoice) 204 }); 205 } 206 dynamic constrainedValuedParameter = parameter; 207 dynamic validValues = constrainedValuedParameter.ValidValues; 208 foreach (var choice in validValues) { 209 choicesListView.Items.Add(new ListViewItem(choice.ToString()) { 210 Tag = choice, 211 Checked = multipleChoiceParameters.ContainsKey(parameter) 212 && multipleChoiceParameters[parameter].Contains(choice) 213 }); 208 if (isConstrainedValueParameter) { 209 if (isOptionalConstrainedValueParameter) { 210 choicesListView.Items.Add(new ListViewItem("-") { 211 Tag = optionalNullChoice, 212 Checked = multipleChoiceParameters.ContainsKey(parameter) 213 && multipleChoiceParameters[parameter].Contains(optionalNullChoice) 214 }); 215 } 216 dynamic constrainedValuedParameter = parameter; 217 dynamic validValues = constrainedValuedParameter.ValidValues; 218 foreach (var choice in validValues) { 219 choicesListView.Items.Add(new ListViewItem(choice.ToString()) { 220 Tag = choice, 221 Checked = multipleChoiceParameters.ContainsKey(parameter) 222 && multipleChoiceParameters[parameter].Contains(choice) 223 }); 224 } 225 } 226 if (isEnumValue) { 227 var enumType = parameter.Value.GetType().GetGenericArguments()[0]; 228 var enumValueType = typeof(EnumValue<>).MakeGenericType(enumType); 229 foreach (var enumChoice in Enum.GetValues(enumType)) { 230 choicesListView.Items.Add(new ListViewItem(enumChoice.ToString()) { 231 Tag = Activator.CreateInstance(enumValueType, enumChoice), 232 Checked = multipleChoiceParameters.ContainsKey(parameter) 233 && multipleChoiceParameters[parameter].Any((dynamic item) => item.Value.Equals(enumChoice)) 234 }); 235 } 214 236 } 215 237 choicesListView.Enabled = multipleChoiceParameters.ContainsKey(parameter); … … 455 477 if (valueParam != null && (valueParam.Value is ValueTypeValue<bool> 456 478 || valueParam.Value is ValueTypeValue<int> 457 || valueParam.Value is ValueTypeValue<double>) 479 || valueParam.Value is ValueTypeValue<double> 480 || (valueParam.Value != null && valueParam.Value.GetType().IsGenericType 481 && typeof(EnumValue<>).IsAssignableFrom(valueParam.Value.GetType().GetGenericTypeDefinition()))) 458 482 || typeof(OptionalConstrainedValueParameter<>).IsAssignableFrom(param.GetType().GetGenericTypeDefinition()) 459 483 || typeof(ConstrainedValueParameter<>).IsAssignableFrom(param.GetType().GetGenericTypeDefinition())) … … 603 627 bool finished; 604 628 do { 629 foreach (var p in boolParameters) { 630 if (!configuration.ContainsKey(p)) 631 configuration.Add(p, false); 632 } 633 634 yield return configuration; 605 635 finished = true; 636 606 637 foreach (var p in boolParameters) { 607 if (!configuration.ContainsKey(p)) configuration.Add(p, false); 608 else { 609 if (configuration[p]) { 610 configuration[p] = false; 611 } else { 612 configuration[p] = true; 613 finished = false; 614 break; 615 } 616 } 617 } 618 yield return configuration; 638 if (configuration[p]) { 639 configuration[p] = false; 640 } else { 641 configuration[p] = true; 642 finished = false; 643 break; 644 } 645 } 619 646 } while (!finished); 620 647 } … … 650 677 } 651 678 #endregion 679 680 #region EnumValueEqualityComparer 681 private class EnumValueEqualityComparer : EqualityComparer<IItem> { 682 public override bool Equals(IItem x, IItem y) { 683 if (typeof(EnumValue<>).IsAssignableFrom(x.GetType().GetGenericTypeDefinition()) && 684 typeof(EnumValue<>).IsAssignableFrom(y.GetType().GetGenericTypeDefinition())) { 685 dynamic enumValueX = x; 686 dynamic enumValueY = y; 687 return enumValueX.Value.Equals(enumValueY.Value); 688 } else return object.ReferenceEquals(x, y); 689 } 690 691 public override int GetHashCode(IItem obj) { 692 if (typeof(EnumValue<>).IsAssignableFrom(obj.GetType().GetGenericTypeDefinition())) { 693 dynamic enumValue = obj; 694 return enumValue.Value.GetHashCode(); 695 } else return obj.GetHashCode(); 696 } 697 } 698 #endregion 699 652 700 #endregion 653 701 … … 832 880 if (multipleChoiceParameters.Any()) { 833 881 foreach (var m in mcEnumerator.Current) { 834 dynamic variantParam = variant.Parameters[m.Key.Name]; 835 if (m.Value == optionalNullChoice) { 836 variantParam.Value = null; 837 variant.Name += m.Key.Name + "=null, "; 838 continue; 839 } 840 var variantEnumerator = ((IEnumerable<object>)variantParam.ValidValues).GetEnumerator(); 841 var originalEnumerator = ((IEnumerable<object>)((dynamic)m.Key).ValidValues).GetEnumerator(); 842 while (variantEnumerator.MoveNext() && originalEnumerator.MoveNext()) { 843 if (m.Value == (IItem)originalEnumerator.Current) { 844 variantParam.Value = (dynamic)variantEnumerator.Current; 845 if (m.Value is INamedItem) 846 variant.Name += m.Key.Name + "=" + ((INamedItem)m.Value).Name + ", "; 847 else variant.Name += m.Key.Name + "=" + m.Value.ToString() + ", "; 848 break; 882 if (m.Key.Value != null && m.Key.Value.GetType().IsGenericType 883 && typeof(EnumValue<>).IsAssignableFrom(m.Key.Value.GetType().GetGenericTypeDefinition())) { 884 var valueParam = (IValueParameter)variant.Parameters[m.Key.Name]; 885 valueParam.Value = m.Value; 886 variant.Name += m.Key.Name + "=" + m.Value + ", "; 887 } else { 888 dynamic variantParam = variant.Parameters[m.Key.Name]; 889 if (m.Value == optionalNullChoice) { 890 variantParam.Value = null; 891 variant.Name += m.Key.Name + "=null, "; 892 continue; 893 } 894 var variantEnumerator = ((IEnumerable<object>)variantParam.ValidValues).GetEnumerator(); 895 var originalEnumerator = ((IEnumerable<object>)((dynamic)m.Key).ValidValues).GetEnumerator(); 896 while (variantEnumerator.MoveNext() && originalEnumerator.MoveNext()) { 897 if (m.Value == (IItem)originalEnumerator.Current) { 898 variantParam.Value = (dynamic)variantEnumerator.Current; 899 if (m.Value is INamedItem) 900 variant.Name += m.Key.Name + "=" + ((INamedItem)m.Value).Name + ", "; 901 else variant.Name += m.Key.Name + "=" + m.Value.ToString() + ", "; 902 break; 903 } 849 904 } 850 905 } -
branches/HiveStatistics/sources/HeuristicLab.Optimizer/3.3/NewItemDialog.cs
r12515 r12689 27 27 using System.Windows.Forms; 28 28 using HeuristicLab.Common; 29 using HeuristicLab.Common.Resources; 29 30 using HeuristicLab.Core; 30 31 using HeuristicLab.PluginInfrastructure; … … 93 94 94 95 private TreeNode CreateCategoryTree(IEnumerable<IGrouping<string, Type>> categories) { 95 imageList.Images.Add( HeuristicLab.Common.Resources.VSImageLibrary.Class); // default icon96 imageList.Images.Add( HeuristicLab.Common.Resources.VSImageLibrary.Namespace); // plugins96 imageList.Images.Add(VSImageLibrary.Class); // default icon 97 imageList.Images.Add(VSImageLibrary.Namespace); // plugins 97 98 98 99 var rootNode = new TreeNode(); … … 109 110 110 111 // Skip categories with same full name because the raw name can still be different (missing order) 111 if (rootNode.Nodes.Find(fullName, searchAllChildren:true).Length > 0)112 if (rootNode.Nodes.Find(fullName, true).Length > 0) 112 113 continue; 113 114 114 var categoryNode = new TreeNode(name, imageIndex: 1, selectedImageIndex:1) {115 var categoryNode = new TreeNode(name, 1, 1) { 115 116 Name = fullName, 116 117 Tag = rawName … … 133 134 rawName = rawName == null ? rawParentName : rawName + CreatableAttribute.Categories.SplitToken + rawParentName; 134 135 var fullName = CreatableAttribute.Categories.GetFullName(rawName); 135 parentNode = node.Nodes.Find(fullName, searchAllChildren:false).SingleOrDefault();136 parentNode = node.Nodes.Find(fullName, false).SingleOrDefault(); 136 137 if (parentNode == null) { 137 138 var name = CreatableAttribute.Categories.GetName(rawName); 138 parentNode = new TreeNode(name, imageIndex: 1, selectedImageIndex:1) {139 parentNode = new TreeNode(name, 1, 1) { 139 140 Name = fullName, 140 141 Tag = rawName … … 149 150 foreach (var category in categories) { 150 151 var fullName = CreatableAttribute.Categories.GetFullName(category.Key); 151 var categoryNode = node.Nodes.Find(fullName, searchAllChildren:true).Single();152 var categoryNode = node.Nodes.Find(fullName, true).Single(); 152 153 foreach (var creatable in category) { 153 154 var itemNode = CreateItemNode(creatable); … … 323 324 private void RestoreSelectedNode(TreeNode selectedNode) { 324 325 if (selectedNode != null) { 325 var node = typesTreeView.Nodes.Find(selectedNode.Name, searchAllChildren:true).SingleOrDefault();326 var node = typesTreeView.Nodes.Find(selectedNode.Name, true).SingleOrDefault(); 326 327 if (node != null) 327 328 typesTreeView.SelectedNode = node; … … 360 361 } 361 362 362 private TreeNode toolStripMenuNode = null;363 private TreeNode toolStripMenuNode; 363 364 private void typesTreeView_MouseDown(object sender, MouseEventArgs e) { 364 365 if (e.Button == MouseButtons.Right) { … … 440 441 } 441 442 } 442 private TreeNode LastVisibleNode {443 get {444 var node = FirstVisibleNode;445 while (node != null && node.NextVisibleNode != null) node = node.NextVisibleNode;446 return node;447 }448 }449 443 450 444 private class ItemTreeNodeComparer : IComparer { … … 456 450 if (lhs.Tag is string && rhs.Tag is string) { 457 451 return Comparer.Compare((string)lhs.Tag, (string)rhs.Tag); 458 } else if (lhs.Tag is string) { 452 } 453 if (lhs.Tag is string) { 459 454 return -1; 460 } else461 455 } 456 return 1; 462 457 } 463 458 }
Note: See TracChangeset
for help on using the changeset viewer.