[2653] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17181] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2653] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[3136] | 23 | using System.Drawing;
|
---|
[2818] | 24 | using HeuristicLab.Common;
|
---|
[2714] | 25 | using HeuristicLab.Core;
|
---|
[17097] | 26 | using HEAL.Attic;
|
---|
[2653] | 27 |
|
---|
[2714] | 28 | namespace HeuristicLab.Parameters {
|
---|
[2653] | 29 | /// <summary>
|
---|
[2740] | 30 | /// A base class for parameters.
|
---|
[2653] | 31 | /// </summary>
|
---|
[2664] | 32 | [Item("Parameter", "A base class for parameters.")]
|
---|
[17097] | 33 | [StorableType("EB8A33BD-466A-4035-8544-8F86E5FDA458")]
|
---|
[9195] | 34 | public abstract class Parameter : NamedItem, IParameter {
|
---|
[3136] | 35 | public override Image ItemImage {
|
---|
| 36 | get {
|
---|
| 37 | if ((dataType != null) && (typeof(IOperator).IsAssignableFrom(dataType)))
|
---|
[5287] | 38 | return HeuristicLab.Common.Resources.VSImageLibrary.Method;
|
---|
[3136] | 39 | else
|
---|
| 40 | return base.ItemImage;
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
[2653] | 43 | public override bool CanChangeName {
|
---|
| 44 | get { return false; }
|
---|
| 45 | }
|
---|
| 46 | public override bool CanChangeDescription {
|
---|
| 47 | get { return false; }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | [Storable]
|
---|
| 51 | private Type dataType;
|
---|
| 52 | public Type DataType {
|
---|
| 53 | get { return dataType; }
|
---|
| 54 | }
|
---|
[5193] | 55 |
|
---|
[5768] | 56 | [Storable(DefaultValue = false)]
|
---|
| 57 | private bool hidden;
|
---|
| 58 | public bool Hidden {
|
---|
| 59 | get { return hidden; }
|
---|
| 60 | set {
|
---|
| 61 | if (value != hidden) {
|
---|
| 62 | hidden = value;
|
---|
| 63 | OnHiddenChanged();
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[2757] | 68 | public IItem ActualValue {
|
---|
[9195] | 69 | get { return GetActualValue(); }
|
---|
| 70 | set { SetActualValue(value); }
|
---|
[2757] | 71 | }
|
---|
[2653] | 72 |
|
---|
[4722] | 73 | [StorableConstructor]
|
---|
[17097] | 74 | protected Parameter(StorableConstructorFlag _) : base(_) {
|
---|
[5193] | 75 | }
|
---|
[4722] | 76 | protected Parameter(Parameter original, Cloner cloner)
|
---|
| 77 | : base(original, cloner) {
|
---|
| 78 | dataType = original.dataType;
|
---|
[5768] | 79 | hidden = original.hidden;
|
---|
[4722] | 80 | }
|
---|
[2664] | 81 | protected Parameter()
|
---|
[2653] | 82 | : base("Anonymous") {
|
---|
| 83 | dataType = typeof(IItem);
|
---|
[5768] | 84 | hidden = false;
|
---|
[2653] | 85 | }
|
---|
[2756] | 86 | protected Parameter(string name, Type dataType)
|
---|
| 87 | : base(name) {
|
---|
| 88 | if (dataType == null) throw new ArgumentNullException();
|
---|
| 89 | this.dataType = dataType;
|
---|
[5768] | 90 | hidden = false;
|
---|
[2756] | 91 | }
|
---|
[2664] | 92 | protected Parameter(string name, string description, Type dataType)
|
---|
[2653] | 93 | : base(name, description) {
|
---|
| 94 | if (dataType == null) throw new ArgumentNullException();
|
---|
| 95 | this.dataType = dataType;
|
---|
[5768] | 96 | hidden = false;
|
---|
[6103] | 97 | }
|
---|
| 98 |
|
---|
[2669] | 99 | public override string ToString() {
|
---|
[3688] | 100 | return Name;
|
---|
[2669] | 101 | }
|
---|
[2757] | 102 |
|
---|
| 103 | protected abstract IItem GetActualValue();
|
---|
| 104 | protected abstract void SetActualValue(IItem value);
|
---|
[5768] | 105 |
|
---|
| 106 | public event EventHandler HiddenChanged;
|
---|
| 107 | protected virtual void OnHiddenChanged() {
|
---|
| 108 | EventHandler handler = HiddenChanged;
|
---|
| 109 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 110 | }
|
---|
[2653] | 111 | }
|
---|
| 112 | }
|
---|