Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman.Views/3.3/CoordinatesTSPDataView.cs @ 17335

Last change on this file since 17335 was 17335, checked in by abeham, 5 years ago

#2521: Refactored pTSP to use compositional pattern

File size: 2.6 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.Windows.Forms;
23using HeuristicLab.Core.Views;
24using HeuristicLab.MainForm;
25using HeuristicLab.MainForm.WindowsForms;
26
27namespace HeuristicLab.Problems.TravelingSalesman.Views {
28  [View("Coordinates TSP Data View")]
29  [Content(typeof(CoordinatesTSPData), IsDefaultView = true)]
30  public partial class CoordinatesTSPDataView : NamedItemView, ITSPVisualizerView {
31   
32    private TSPVisualizer visualizer;
33    public TSPVisualizer Visualizer {
34      get => visualizer;
35      set {
36        if (visualizer == value) return;
37        visualizer = value;
38        if (Content != null) {
39          visualizer.Coordinates = Content.Coordinates;
40        }
41        GenerateImage();
42      }
43    }
44
45    public new CoordinatesTSPData Content {
46      get { return (CoordinatesTSPData)base.Content; }
47      set { base.Content = value; }
48    }
49
50    public CoordinatesTSPDataView() {
51      InitializeComponent();
52      visualizer = new TSPVisualizer();
53    }
54
55    protected override void OnContentChanged() {
56      base.OnContentChanged();
57      if (Content == null) {
58        coordinatesMatrixView.Content = null;
59        coordinatesPictureBox.Image = null;
60        Visualizer.Coordinates = null;
61      } else {
62        coordinatesMatrixView.Content = Content.Coordinates;
63        Visualizer.Coordinates = Content.Coordinates;
64        GenerateImage();
65      }
66    }
67
68    protected override void SetEnabledStateOfControls() {
69      base.SetEnabledStateOfControls();
70      coordinatesMatrixView.Enabled = !ReadOnly && !Locked && Content != null;
71    }
72
73    protected virtual void GenerateImage() {
74      coordinatesPictureBox.Image = Visualizer.Draw(coordinatesPictureBox.Width, coordinatesPictureBox.Height);
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.