[3884] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15973] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3884] | 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
|
---|
[5829] | 21 |
|
---|
[3884] | 22 | using System;
|
---|
[5829] | 23 | using System.Collections.Generic;
|
---|
[6612] | 24 | using System.Drawing;
|
---|
| 25 | using System.Linq;
|
---|
[3884] | 26 | using System.Windows.Forms;
|
---|
[6692] | 27 | using HeuristicLab.Core;
|
---|
[6652] | 28 | using HeuristicLab.Core.Views;
|
---|
[3884] | 29 | using HeuristicLab.MainForm;
|
---|
[6652] | 30 | using HeuristicLab.Optimization;
|
---|
[10175] | 31 | using HeuristicLab.Persistence.Default.Xml;
|
---|
[9973] | 32 | using HeuristicLab.PluginInfrastructure;
|
---|
[3884] | 33 |
|
---|
| 34 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
[9973] | 35 |
|
---|
[5834] | 36 | [View("DataAnalysisSolution View")]
|
---|
[6652] | 37 | [Content(typeof(DataAnalysisSolution), false)]
|
---|
[9974] | 38 | public partial class DataAnalysisSolutionView : NamedItemCollectionView<IResult> {
|
---|
[3884] | 39 | public DataAnalysisSolutionView() {
|
---|
| 40 | InitializeComponent();
|
---|
[6652] | 41 | viewHost.ViewsLabelVisible = false;
|
---|
[3884] | 42 | }
|
---|
| 43 |
|
---|
[5829] | 44 | public new DataAnalysisSolution Content {
|
---|
| 45 | get { return (DataAnalysisSolution)base.Content; }
|
---|
[3884] | 46 | set { base.Content = value; }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[6666] | 49 | protected override void SetEnabledStateOfControls() {
|
---|
| 50 | base.SetEnabledStateOfControls();
|
---|
| 51 | addButton.Enabled = false;
|
---|
| 52 | removeButton.Enabled = false;
|
---|
[10540] | 53 | loadProblemDataButton.Enabled = Content != null && !Locked;
|
---|
[6666] | 54 | }
|
---|
| 55 |
|
---|
| 56 | protected override void RegisterContentEvents() {
|
---|
| 57 | base.RegisterContentEvents();
|
---|
| 58 | Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
|
---|
| 59 | }
|
---|
| 60 | protected override void DeregisterContentEvents() {
|
---|
| 61 | base.DeregisterContentEvents();
|
---|
| 62 | Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
|
---|
| 63 | }
|
---|
| 64 | private void Content_ProblemDataChanged(object sender, EventArgs e) {
|
---|
| 65 | OnContentChanged();
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[3884] | 68 | protected override void OnContentChanged() {
|
---|
[5829] | 69 | string selectedName = null;
|
---|
| 70 | if ((itemsListView.SelectedItems.Count == 1) && (itemsListView.SelectedItems[0].Tag != null && itemsListView.SelectedItems[0].Tag is Type))
|
---|
| 71 | selectedName = itemsListView.SelectedItems[0].Text;
|
---|
| 72 |
|
---|
[3884] | 73 | base.OnContentChanged();
|
---|
[6642] | 74 | AddEvaluationViewTypes();
|
---|
[5829] | 75 |
|
---|
| 76 | //recover selection
|
---|
| 77 | if (selectedName != null) {
|
---|
| 78 | foreach (ListViewItem item in itemsListView.Items) {
|
---|
| 79 | if (item.Tag != null && item.Tag is Type && item.Text == selectedName)
|
---|
| 80 | item.Selected = true;
|
---|
| 81 | }
|
---|
[3884] | 82 | }
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[6652] | 85 | protected override IResult CreateItem() {
|
---|
| 86 | return null;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
[6642] | 89 | protected virtual void AddEvaluationViewTypes() {
|
---|
[6666] | 90 | if (Content != null && !Content.ProblemData.IsEmpty) {
|
---|
[6642] | 91 | var viewTypes = MainFormManager.GetViewTypes(Content.GetType(), true)
|
---|
| 92 | .Where(t => typeof(IDataAnalysisSolutionEvaluationView).IsAssignableFrom(t));
|
---|
| 93 | foreach (var viewType in viewTypes)
|
---|
| 94 | AddViewListViewItem(viewType, ((IDataAnalysisSolutionEvaluationView)Activator.CreateInstance(viewType)).ViewImage);
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[15973] | 98 | protected sealed override void itemsListView_DoubleClick(object sender, EventArgs e) {
|
---|
[6652] | 99 | if (itemsListView.SelectedItems.Count != 1) return;
|
---|
| 100 |
|
---|
| 101 | IResult result = itemsListView.SelectedItems[0].Tag as IResult;
|
---|
| 102 | Type viewType = itemsListView.SelectedItems[0].Tag as Type;
|
---|
| 103 | if (result != null) {
|
---|
[15973] | 104 | IContentView view = MainFormManager.MainForm.ShowContent(result.Value);
|
---|
[6652] | 105 | if (view != null) {
|
---|
[15973] | 106 | view.Caption = result.Name;
|
---|
[6652] | 107 | view.ReadOnly = ReadOnly;
|
---|
| 108 | view.Locked = Locked;
|
---|
| 109 | }
|
---|
| 110 | } else if (viewType != null) {
|
---|
[5829] | 111 | MainFormManager.MainForm.ShowContent(Content, viewType);
|
---|
[6652] | 112 | }
|
---|
[3884] | 113 | }
|
---|
[3915] | 114 |
|
---|
[5829] | 115 | protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 116 | if (itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag is Type) {
|
---|
| 117 | detailsGroupBox.Enabled = true;
|
---|
| 118 | Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
|
---|
| 119 | viewHost.ViewType = viewType;
|
---|
| 120 | viewHost.Content = Content;
|
---|
| 121 | } else
|
---|
| 122 | base.itemsListView_SelectedIndexChanged(sender, e);
|
---|
[3884] | 123 | }
|
---|
[3915] | 124 |
|
---|
[10175] | 125 | protected virtual void loadProblemDataButton_Click(object sender, EventArgs e) {
|
---|
| 126 | if (loadProblemDataFileDialog.ShowDialog(this) != DialogResult.OK) return;
|
---|
[10540] | 127 | try {
|
---|
| 128 | object hlFile = XmlParser.Deserialize(loadProblemDataFileDialog.FileName);
|
---|
[9973] | 129 |
|
---|
[10540] | 130 | IDataAnalysisProblemData problemData = null;
|
---|
| 131 | if (hlFile is IDataAnalysisProblemData) {
|
---|
| 132 | problemData = (IDataAnalysisProblemData)hlFile;
|
---|
| 133 | } else if (hlFile is IDataAnalysisProblem) {
|
---|
| 134 | problemData = ((IDataAnalysisProblem)hlFile).ProblemData;
|
---|
| 135 | } else if (hlFile is IDataAnalysisSolution) {
|
---|
| 136 | problemData = ((IDataAnalysisSolution)hlFile).ProblemData;
|
---|
| 137 | }
|
---|
[10175] | 138 |
|
---|
[10540] | 139 | if (problemData == null)
|
---|
| 140 | throw new InvalidOperationException("The chosen HeuristicLab file does not contain a ProblemData, Problem, or DataAnalysisSolution.");
|
---|
[10175] | 141 |
|
---|
| 142 | var solution = (IDataAnalysisSolution)Content.Clone();
|
---|
[10540] | 143 | problemData.AdjustProblemDataProperties(solution.ProblemData);
|
---|
[15973] | 144 |
|
---|
[10175] | 145 | solution.ProblemData = problemData;
|
---|
[10540] | 146 | if (!solution.Name.EndsWith(" with loaded problemData"))
|
---|
| 147 | solution.Name += " with loaded problemData";
|
---|
[10175] | 148 | MainFormManager.MainForm.ShowContent(solution);
|
---|
[13338] | 149 | } catch (InvalidOperationException invalidOperationException) {
|
---|
| 150 | MainFormManager.MainForm.ShowError(invalidOperationException.Message, invalidOperationException);
|
---|
| 151 | } catch (ArgumentException argumentException) {
|
---|
| 152 | MainFormManager.MainForm.ShowError(argumentException.Message, argumentException);
|
---|
[10175] | 153 | }
|
---|
[9973] | 154 | }
|
---|
| 155 |
|
---|
[6612] | 156 | protected void AddViewListViewItem(Type viewType, Image image) {
|
---|
[5829] | 157 | ListViewItem listViewItem = new ListViewItem();
|
---|
| 158 | listViewItem.Text = ViewAttribute.GetViewName(viewType);
|
---|
[6612] | 159 | itemsListView.SmallImageList.Images.Add(image);
|
---|
[5829] | 160 | listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
|
---|
| 161 | listViewItem.Tag = viewType;
|
---|
| 162 | itemsListView.Items.Add(listViewItem);
|
---|
| 163 |
|
---|
| 164 | AdjustListViewColumnSizes();
|
---|
[3915] | 165 | }
|
---|
[5829] | 166 |
|
---|
| 167 | protected void RemoveViewListViewItem(Type viewType) {
|
---|
[6612] | 168 | List<ListViewItem> itemsToRemove = itemsListView.Items.Cast<ListViewItem>().Where(item => item.Tag as Type == viewType).ToList();
|
---|
[5829] | 169 |
|
---|
| 170 | foreach (ListViewItem item in itemsToRemove)
|
---|
| 171 | itemsListView.Items.Remove(item);
|
---|
[3884] | 172 | }
|
---|
[6653] | 173 |
|
---|
[8125] | 174 | protected override void showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 175 | if (showDetailsCheckBox.Checked && itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag is Type) {
|
---|
| 176 | Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
|
---|
| 177 | viewHost.ViewType = viewType;
|
---|
| 178 | viewHost.Content = Content;
|
---|
| 179 | splitContainer.Panel2Collapsed = false;
|
---|
| 180 | detailsGroupBox.Enabled = true;
|
---|
| 181 | } else base.showDetailsCheckBox_CheckedChanged(sender, e);
|
---|
| 182 | }
|
---|
| 183 |
|
---|
[8798] | 184 | protected override void RebuildImageList() {
|
---|
| 185 | itemsListView.SmallImageList.Images.Clear();
|
---|
| 186 | foreach (ListViewItem listViewItem in itemsListView.Items) {
|
---|
| 187 | IResult result = listViewItem.Tag as IResult;
|
---|
| 188 | Type viewType = listViewItem.Tag as Type;
|
---|
| 189 | if (result != null) itemsListView.SmallImageList.Images.Add(result.ItemImage);
|
---|
| 190 | else if (viewType != null && typeof(IDataAnalysisSolutionEvaluationView).IsAssignableFrom(viewType))
|
---|
| 191 | itemsListView.SmallImageList.Images.Add(((IDataAnalysisSolutionEvaluationView)Activator.CreateInstance(viewType)).ViewImage);
|
---|
| 192 | else itemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Nothing);
|
---|
| 193 |
|
---|
| 194 | listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
|
---|
| 195 | }
|
---|
| 196 | }
|
---|
| 197 |
|
---|
[6653] | 198 | #region drag and drop
|
---|
| 199 | protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
|
---|
| 200 | validDragOperation = false;
|
---|
[6692] | 201 | if (ReadOnly) return;
|
---|
[10540] | 202 | if (e.Effect != DragDropEffects.Copy) return;
|
---|
[6692] | 203 |
|
---|
| 204 | var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
[10540] | 205 | if (dropData is IDataAnalysisProblemData) validDragOperation = true;
|
---|
[10173] | 206 | else if (dropData is IDataAnalysisProblem) validDragOperation = true;
|
---|
[6692] | 207 | else if (dropData is IValueParameter) {
|
---|
| 208 | var param = (IValueParameter)dropData;
|
---|
[10173] | 209 | if (param.Value is IDataAnalysisProblemData) validDragOperation = true;
|
---|
[6653] | 210 | }
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
|
---|
[15973] | 214 | if (e.Effect != DragDropEffects.Copy) return;
|
---|
[10174] | 215 |
|
---|
| 216 | IDataAnalysisProblemData problemData = null;
|
---|
| 217 | var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
| 218 | if (dropData is IDataAnalysisProblemData)
|
---|
| 219 | problemData = (IDataAnalysisProblemData)dropData;
|
---|
| 220 | else if (dropData is IDataAnalysisProblem)
|
---|
| 221 | problemData = ((IDataAnalysisProblem)dropData).ProblemData;
|
---|
| 222 | else if (dropData is IValueParameter) {
|
---|
| 223 | var param = (IValueParameter)dropData;
|
---|
| 224 | problemData = param.Value as DataAnalysisProblemData;
|
---|
[6653] | 225 | }
|
---|
[10174] | 226 | if (problemData == null) return;
|
---|
| 227 |
|
---|
[15973] | 228 | problemData = (IDataAnalysisProblemData)problemData.Clone();
|
---|
| 229 |
|
---|
[10540] | 230 | try {
|
---|
| 231 | problemData.AdjustProblemDataProperties(Content.ProblemData);
|
---|
| 232 | Content.ProblemData = problemData;
|
---|
[10174] | 233 |
|
---|
[10540] | 234 | if (!Content.Name.EndsWith(" with changed problemData"))
|
---|
| 235 | Content.Name += " with changed problemData";
|
---|
[15973] | 236 | Content.Filename = string.Empty;
|
---|
| 237 | MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().UpdateTitle();
|
---|
[13338] | 238 | } catch (InvalidOperationException invalidOperationException) {
|
---|
| 239 | MainFormManager.MainForm.ShowError(invalidOperationException.Message, invalidOperationException);
|
---|
| 240 | } catch (ArgumentException argumentException) {
|
---|
| 241 | MainFormManager.MainForm.ShowError(argumentException.Message, argumentException);
|
---|
[10174] | 242 | }
|
---|
| 243 | }
|
---|
| 244 | #endregion
|
---|
[10540] | 245 |
|
---|
[3884] | 246 | }
|
---|
| 247 | }
|
---|