Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisSolution.cs @ 5815

Last change on this file since 5815 was 5809, checked in by mkommend, 14 years ago

#1418: Reintegrated branch into trunk.

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