Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringSolutionView.cs

Last change on this file was 17533, checked in by abeham, 4 years ago

#2521: Unified architecture

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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.ComponentModel;
23using HeuristicLab.Core.Views;
24using HeuristicLab.MainForm;
25
26namespace HeuristicLab.Problems.Orienteering.Views {
27  [View("OrienteeringSolution View")]
28  [Content(typeof(IOrienteeringSolution), true)]
29  public partial class OrienteeringSolutionView : ItemView {
30    public OrienteeringVisualizer Visualizer { get; set; }
31
32    public new IOrienteeringSolution Content {
33      get { return (IOrienteeringSolution)base.Content; }
34      set { base.Content = value; }
35    }
36    public OrienteeringSolutionView() {
37      InitializeComponent();
38      Visualizer = new OrienteeringVisualizer();
39      tspSolutionView.Visualizer = Visualizer;
40    }
41
42    protected override void DeregisterContentEvents() {
43      Content.PropertyChanged -= ContentOnPropertyChanged;
44      base.DeregisterContentEvents();
45    }
46    protected override void RegisterContentEvents() {
47      base.RegisterContentEvents();
48      Content.PropertyChanged += ContentOnPropertyChanged;
49    }
50
51    protected virtual void ContentOnPropertyChanged(object sender, PropertyChangedEventArgs e) {
52      switch (e.PropertyName) {
53        case nameof(Content.Quality):
54          qualityValueView.Content = Content.Quality;
55          break;
56        case nameof(Content.Score):
57          scoreValueView.Content = Content.Score;
58          break;
59      }
60    }
61
62    protected override void OnContentChanged() {
63      if (Content == null) {
64        qualityValueView.Content = null;
65        scoreValueView.Content = null;
66        Visualizer.Data = null;
67        Visualizer.IsFeasible = false;
68      } else {
69        qualityValueView.Content = Content.Quality;
70        scoreValueView.Content = Content.Score;
71        Visualizer.Data = Content.Data;
72        Visualizer.IsFeasible = Content.TravelCosts.Value <= Content.Data.MaximumTravelCosts;
73      }
74      tspSolutionView.Content = Content;
75      base.OnContentChanged();
76    }
77
78    protected override void SetEnabledStateOfControls() {
79      base.SetEnabledStateOfControls();
80      qualityValueView.Enabled = Content != null && !ReadOnly && !Locked;
81      scoreValueView.Enabled = Content != null && !ReadOnly && !Locked;
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.