Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisSolution.cs @ 7908

Last change on this file since 7908 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

File size: 5.7 KB
RevLine 
[5620]1#region License Information
2/* HeuristicLab
[7259]3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[5620]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
[5777]22using System;
23using System.Drawing;
[5620]24using HeuristicLab.Common;
[5777]25using HeuristicLab.Optimization;
[5620]26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Problems.DataAnalysis {
29  /// <summary>
30  /// Abstract base class for data analysis solutions
31  /// </summary>
32  [StorableClass]
33  public abstract class DataAnalysisSolution : ResultCollection, IDataAnalysisSolution {
34    private const string ModelResultName = "Model";
35    private const string ProblemDataResultName = "ProblemData";
[5624]36
[5909]37    public string Filename { get; set; }
38
[7201]39    public static new Image StaticItemImage {
[5624]40      get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; }
41    }
42
[5620]43    #region properties
44    public IDataAnalysisModel Model {
45      get { return (IDataAnalysisModel)this[ModelResultName].Value; }
[5717]46      protected set {
47        if (this[ModelResultName].Value != value) {
48          if (value != null) {
49            this[ModelResultName].Value = value;
[6606]50            OnModelChanged();
[5717]51          }
52        }
53      }
[5620]54    }
55
56    public IDataAnalysisProblemData ProblemData {
57      get { return (IDataAnalysisProblemData)this[ProblemDataResultName].Value; }
[6653]58      set {
[5717]59        if (this[ProblemDataResultName].Value != value) {
60          if (value != null) {
61            ProblemData.Changed -= new EventHandler(ProblemData_Changed);
62            this[ProblemDataResultName].Value = value;
63            ProblemData.Changed += new EventHandler(ProblemData_Changed);
[6606]64            OnProblemDataChanged();
[5717]65          }
66        }
67      }
[5620]68    }
69    #endregion
70
71    [StorableConstructor]
72    protected DataAnalysisSolution(bool deserializing) : base(deserializing) { }
73    protected DataAnalysisSolution(DataAnalysisSolution original, Cloner cloner)
74      : base(original, cloner) {
75      name = original.Name;
76      description = original.Description;
77    }
[5624]78    public DataAnalysisSolution(IDataAnalysisModel model, IDataAnalysisProblemData problemData)
[5620]79      : base() {
[5649]80      name = ItemName;
81      description = ItemDescription;
[6588]82      Add(new Result(ModelResultName, "The data analysis model.", model));
83      Add(new Result(ProblemDataResultName, "The data analysis problem data.", problemData));
[5624]84
[5914]85      problemData.Changed += new EventHandler(ProblemData_Changed);
[5620]86    }
87
[6411]88    protected abstract void RecalculateResults();
89
[5624]90    private void ProblemData_Changed(object sender, EventArgs e) {
[6606]91      OnProblemDataChanged();
[5624]92    }
93
[5620]94    public event EventHandler ModelChanged;
[6606]95    protected virtual void OnModelChanged() {
[6411]96      RecalculateResults();
[5620]97      var listeners = ModelChanged;
[6606]98      if (listeners != null) listeners(this, EventArgs.Empty);
[5620]99    }
100
101    public event EventHandler ProblemDataChanged;
[6606]102    protected virtual void OnProblemDataChanged() {
[6411]103      RecalculateResults();
[5620]104      var listeners = ProblemDataChanged;
[6606]105      if (listeners != null) listeners(this, EventArgs.Empty);
[5620]106    }
107
108    #region INamedItem Members
109    [Storable]
110    protected string name;
111    public string Name {
112      get { return name; }
113      set {
114        if (!CanChangeName) throw new NotSupportedException("Name cannot be changed.");
115        if (!(name.Equals(value) || (value == null) && (name == string.Empty))) {
116          CancelEventArgs<string> e = value == null ? new CancelEventArgs<string>(string.Empty) : new CancelEventArgs<string>(value);
117          OnNameChanging(e);
118          if (!e.Cancel) {
119            name = value == null ? string.Empty : value;
120            OnNameChanged();
121          }
122        }
123      }
124    }
125    public virtual bool CanChangeName {
126      get { return true; }
127    }
128    [Storable]
129    protected string description;
130    public string Description {
131      get { return description; }
132      set {
133        if (!CanChangeDescription) throw new NotSupportedException("Description cannot be changed.");
134        if (!(description.Equals(value) || (value == null) && (description == string.Empty))) {
135          description = value == null ? string.Empty : value;
136          OnDescriptionChanged();
137        }
138      }
139    }
140    public virtual bool CanChangeDescription {
141      get { return true; }
142    }
143
144    public override string ToString() {
145      return Name;
146    }
147
148    public event EventHandler<CancelEventArgs<string>> NameChanging;
149    protected virtual void OnNameChanging(CancelEventArgs<string> e) {
150      var handler = NameChanging;
151      if (handler != null) handler(this, e);
152    }
153
154    public event EventHandler NameChanged;
155    protected virtual void OnNameChanged() {
156      var handler = NameChanged;
157      if (handler != null) handler(this, EventArgs.Empty);
158      OnToStringChanged();
159    }
160
161    public event EventHandler DescriptionChanged;
162    protected virtual void OnDescriptionChanged() {
163      var handler = DescriptionChanged;
164      if (handler != null) handler(this, EventArgs.Empty);
165    }
166    #endregion
167  }
168}
Note: See TracBrowser for help on using the repository browser.