[2851] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2851] | 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;
|
---|
[2916] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
[2851] | 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
[2916] | 28 | using HeuristicLab.PluginInfrastructure;
|
---|
[2851] | 29 |
|
---|
[2852] | 30 | namespace HeuristicLab.Optimization.Views {
|
---|
[2851] | 31 | /// <summary>
|
---|
| 32 | /// The base class for visual representations of items.
|
---|
| 33 | /// </summary>
|
---|
[2917] | 34 | [View("EngineAlgorithm View")]
|
---|
[2851] | 35 | [Content(typeof(EngineAlgorithm), true)]
|
---|
| 36 | public partial class EngineAlgorithmView : AlgorithmView {
|
---|
[2916] | 37 | private List<Type> engineTypes;
|
---|
[2851] | 38 |
|
---|
| 39 | public new EngineAlgorithm Content {
|
---|
| 40 | get { return (EngineAlgorithm)base.Content; }
|
---|
| 41 | set { base.Content = value; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | /// <summary>
|
---|
| 45 | /// Initializes a new instance of <see cref="ItemBaseView"/>.
|
---|
| 46 | /// </summary>
|
---|
| 47 | public EngineAlgorithmView() {
|
---|
| 48 | InitializeComponent();
|
---|
| 49 | }
|
---|
[2916] | 50 |
|
---|
[2851] | 51 | protected override void DeregisterContentEvents() {
|
---|
[3361] | 52 | Content.EngineChanged -= new EventHandler(Content_EngineChanged);
|
---|
| 53 | Content.OperatorGraphChanged -= new EventHandler(Content_OperatorGraphChanged);
|
---|
[2851] | 54 | base.DeregisterContentEvents();
|
---|
| 55 | }
|
---|
| 56 | protected override void RegisterContentEvents() {
|
---|
| 57 | base.RegisterContentEvents();
|
---|
[3361] | 58 | Content.EngineChanged += new EventHandler(Content_EngineChanged);
|
---|
| 59 | Content.OperatorGraphChanged += new EventHandler(Content_OperatorGraphChanged);
|
---|
[2851] | 60 | }
|
---|
| 61 |
|
---|
| 62 | protected override void OnContentChanged() {
|
---|
| 63 | base.OnContentChanged();
|
---|
[2916] | 64 |
|
---|
| 65 | if (engineTypes == null) {
|
---|
| 66 | engineTypes = ApplicationManager.Manager.GetTypes(typeof(IEngine)).
|
---|
| 67 | OrderBy(x => {
|
---|
| 68 | string name = ItemAttribute.GetName(x);
|
---|
| 69 | if (name != null) return name;
|
---|
| 70 | else return x.GetPrettyName();
|
---|
| 71 | }).ToList();
|
---|
| 72 | foreach (Type t in engineTypes) {
|
---|
| 73 | string name = ItemAttribute.GetName(t);
|
---|
| 74 | if (name == null) name = t.GetPrettyName();
|
---|
| 75 | engineComboBox.Items.Add(name);
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[2851] | 79 | if (Content == null) {
|
---|
[2916] | 80 | engineViewHost.Content = null;
|
---|
[3361] | 81 | operatorGraphViewHost.Content = null;
|
---|
[2851] | 82 | } else {
|
---|
[2916] | 83 | if (Content.Engine == null)
|
---|
[3214] | 84 | engineComboBox.SelectedIndex = -1;
|
---|
[2916] | 85 | else
|
---|
| 86 | engineComboBox.SelectedIndex = engineTypes.IndexOf(Content.Engine.GetType());
|
---|
[2949] | 87 | engineViewHost.ViewType = null;
|
---|
[2916] | 88 | engineViewHost.Content = Content.Engine;
|
---|
[3361] | 89 | operatorGraphViewHost.ViewType = null;
|
---|
| 90 | operatorGraphViewHost.Content = Content.OperatorGraph;
|
---|
[2851] | 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[3904] | 94 | protected override void SetEnabledStateOfControls() {
|
---|
| 95 | base.SetEnabledStateOfControls();
|
---|
[3454] | 96 | engineViewHost.Enabled = Content != null;
|
---|
| 97 | newOperatorGraphButton.Enabled = false;
|
---|
| 98 | openOperatorGraphButton.Enabled = false;
|
---|
| 99 | operatorGraphViewHost.Enabled = Content != null;
|
---|
[3640] | 100 | operatorGraphViewHost.ReadOnly = true;
|
---|
[3454] | 101 | engineComboBox.Enabled = Content != null && !ReadOnly;
|
---|
[3367] | 102 | }
|
---|
| 103 |
|
---|
[2998] | 104 | protected virtual void Content_EngineChanged(object sender, System.EventArgs e) {
|
---|
| 105 | if (InvokeRequired)
|
---|
[2851] | 106 | Invoke(new EventHandler(Content_EngineChanged), sender, e);
|
---|
[2916] | 107 | else {
|
---|
| 108 | if (Content.Engine == null)
|
---|
[3214] | 109 | engineComboBox.SelectedIndex = -1;
|
---|
[2916] | 110 | else
|
---|
| 111 | engineComboBox.SelectedIndex = engineTypes.IndexOf(Content.Engine.GetType());
|
---|
[2949] | 112 | engineViewHost.ViewType = null;
|
---|
[2916] | 113 | engineViewHost.Content = Content.Engine;
|
---|
| 114 | }
|
---|
[2851] | 115 | }
|
---|
[3361] | 116 | private void Content_OperatorGraphChanged(object sender, EventArgs e) {
|
---|
| 117 | if (InvokeRequired)
|
---|
| 118 | Invoke(new EventHandler(Content_OperatorGraphChanged), sender, e);
|
---|
| 119 | else {
|
---|
| 120 | operatorGraphViewHost.ViewType = null;
|
---|
| 121 | operatorGraphViewHost.Content = Content.OperatorGraph;
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
[2851] | 124 |
|
---|
[2998] | 125 | protected virtual void engineComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
[2916] | 126 | if (Content != null) {
|
---|
[3214] | 127 | if (engineComboBox.SelectedIndex == -1)
|
---|
[2916] | 128 | Content.Engine = null;
|
---|
[3214] | 129 | else {
|
---|
| 130 | Type t = engineTypes[engineComboBox.SelectedIndex];
|
---|
| 131 | if ((Content.Engine == null) || (Content.Engine.GetType() != t))
|
---|
| 132 | Content.Engine = (IEngine)Activator.CreateInstance(t);
|
---|
| 133 | }
|
---|
[2851] | 134 | }
|
---|
| 135 | }
|
---|
| 136 | }
|
---|
| 137 | }
|
---|