#region License Information /* HeuristicLab * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.Linq; using System.Windows.Forms; using HeuristicLab.Core.Views; using HeuristicLab.MainForm; using HeuristicLab.MainForm.WindowsForms; namespace HeuristicLab.Clients.OKB { [View("Experiment View")] [Content(typeof(Experiment), true)] public partial class ExperimentView : ItemView { public new Experiment Content { get { return (Experiment)base.Content; } set { base.Content = value; } } public ExperimentView() { InitializeComponent(); } protected override void OnContentChanged() { base.OnContentChanged(); runCollectionView.Content = null; if (Content == null) { algorithmTextBox.Text = string.Empty; toolTip.SetToolTip(algorithmTextBox, string.Empty); problemTextBox.Text = string.Empty; toolTip.SetToolTip(problemTextBox, string.Empty); } else { Algorithm algorithm = OKBClient.Instance.Algorithms.FirstOrDefault(x => x.Id == Content.AlgorithmId); algorithmTextBox.Text = algorithm == null ? string.Empty : algorithm.Name; toolTip.SetToolTip(algorithmTextBox, algorithm == null ? string.Empty : algorithm.Description); Problem problem = OKBClient.Instance.Problems.FirstOrDefault(x => x.Id == Content.ProblemId); problemTextBox.Text = problem == null ? string.Empty : problem.Name; toolTip.SetToolTip(problemTextBox, problem == null ? string.Empty : problem.Description); } FillParametersListView(); } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); algorithmTextBox.Enabled = Content != null; problemTextBox.Enabled = Content != null; parametersListView.Enabled = Content != null; refreshRunsButton.Enabled = Content != null; } private void FillParametersListView() { parametersListView.Items.Clear(); parametersListView.SmallImageList.Images.Clear(); if (Content != null) { foreach (AlgorithmParameterValue parameterValue in Content.AlgorithmParameterValues) { AlgorithmParameter parameter = OKBClient.Instance.GetAlgorithmParameter(parameterValue.AlgorithmParameterId); ListViewItem item = new ListViewItem(parameter.Name); item.ToolTipText = parameter.Description; if (parameterValue is AlgorithmParameterBoolValue) { item.SubItems.Add(((AlgorithmParameterBoolValue)parameterValue).Value.ToString()); } else if (parameterValue is AlgorithmParameterIntValue) { item.SubItems.Add(((AlgorithmParameterIntValue)parameterValue).Value.ToString()); } else if (parameterValue is AlgorithmParameterFloatValue) { item.SubItems.Add(((AlgorithmParameterFloatValue)parameterValue).Value.ToString()); } else if (parameterValue is AlgorithmParameterStringValue) { item.SubItems.Add(((AlgorithmParameterStringValue)parameterValue).Value); } else if (parameterValue is AlgorithmParameterBlobValue) { DataType dataType = OKBClient.Instance.DataTypes.FirstOrDefault(x => x.Id == parameterValue.DataTypeId); item.SubItems.Add(dataType == null ? "-" : dataType.Name); } item.Group = parametersListView.Groups["algorithmParametersGroup"]; parametersListView.Items.Add(item); } foreach (ProblemParameterValue parameterValue in Content.ProblemParameterValues) { ProblemParameter parameter = OKBClient.Instance.GetProblemParameter(parameterValue.ProblemParameterId); ListViewItem item = new ListViewItem(parameter.Name); item.ToolTipText = parameter.Description; if (parameterValue is ProblemParameterBoolValue) { item.SubItems.Add(((ProblemParameterBoolValue)parameterValue).Value.ToString()); } else if (parameterValue is ProblemParameterIntValue) { item.SubItems.Add(((ProblemParameterIntValue)parameterValue).Value.ToString()); } else if (parameterValue is ProblemParameterFloatValue) { item.SubItems.Add(((ProblemParameterFloatValue)parameterValue).Value.ToString()); } else if (parameterValue is ProblemParameterStringValue) { item.SubItems.Add(((ProblemParameterStringValue)parameterValue).Value); } else if (parameterValue is ProblemParameterBlobValue) { DataType dataType = OKBClient.Instance.DataTypes.FirstOrDefault(x => x.Id == parameterValue.DataTypeId); item.SubItems.Add(dataType == null ? "-" : dataType.Name); } item.Group = parametersListView.Groups["problemParametersGroup"]; parametersListView.Items.Add(item); } if (parametersListView.Items.Count > 0) { for (int i = 0; i < parametersListView.Columns.Count; i++) parametersListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); } } } private void refreshRunsButton_Click(object sender, System.EventArgs e) { runCollectionView.Content = OKBClient.Instance.GetRuns(Content.Id); } } }