Ignore:
Timestamp:
06/12/14 13:26:18 (5 years ago)
Author:
pfleck
Message:
  • Merged trunk into preprocessing branch.
Location:
branches/DataPreprocessing
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing

  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Views

  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DataAnalysisSolutionView.cs

    r10538 r11009  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.ComponentModel;
    2524using System.Drawing;
    2625using System.Linq;
    27 using System.Text;
    2826using System.Windows.Forms;
    2927using HeuristicLab.Core;
     
    5452      addButton.Enabled = false;
    5553      removeButton.Enabled = false;
    56       if (Content == null) {
    57         exportButton.Enabled = false;
    58         loadProblemDataButton.Enabled = false;
    59       } else {
    60         exportButton.Enabled = !Locked;
    61         loadProblemDataButton.Enabled = !Locked;
    62       }
     54      loadProblemDataButton.Enabled = Content != null && !Locked;
    6355    }
    6456
     
    133125    protected virtual void loadProblemDataButton_Click(object sender, EventArgs e) {
    134126      if (loadProblemDataFileDialog.ShowDialog(this) != DialogResult.OK) return;
    135       object hlFile = XmlParser.Deserialize(loadProblemDataFileDialog.FileName);
    136 
    137       IDataAnalysisProblemData problemData = null;
    138       if (hlFile is IDataAnalysisProblemData) {
    139         problemData = (IDataAnalysisProblemData)hlFile;
    140       } else if (hlFile is IDataAnalysisProblem) {
    141         problemData = ((IDataAnalysisProblem)hlFile).ProblemData;
    142       } else if (hlFile is IDataAnalysisSolution) {
    143         problemData = ((IDataAnalysisSolution)hlFile).ProblemData;
    144       }
    145 
    146       if (problemData == null) {
    147         ErrorHandling.ShowErrorDialog(this, new NullReferenceException("The problem data is null." + Environment.NewLine
    148                                       + "The .hl-file contains no DataAnalysisProblemData or DataAnylsisProblem."));
    149         return;
    150       }
    151 
    152       if (CheckCompatibilityOfProblemData(problemData)) {
     127      try {
     128        object hlFile = XmlParser.Deserialize(loadProblemDataFileDialog.FileName);
     129
     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        }
     138
     139        if (problemData == null)
     140          throw new InvalidOperationException("The chosen HeuristicLab file does not contain a ProblemData, Problem, or DataAnalysisSolution.");
     141
    153142        var solution = (IDataAnalysisSolution)Content.Clone();
     143        problemData.AdjustProblemDataProperties(solution.ProblemData);
    154144        solution.ProblemData = problemData;
    155         solution.Name += " with loaded problem data (" + loadProblemDataFileDialog + ")";
     145        if (!solution.Name.EndsWith(" with loaded problemData"))
     146          solution.Name += " with loaded problemData";
    156147        MainFormManager.MainForm.ShowContent(solution);
    157148      }
    158     }
    159 
    160     private void exportButton_Click(object sender, EventArgs e) {
    161       var exporters = ApplicationManager.Manager.GetInstances<IDataAnalysisSolutionExporter>()
    162         .Where(exporter => exporter.Supports(Content)).ToArray();
    163       exportFileDialog.Filter = exporters.Skip(1)
    164         .Aggregate(exporters.First().FileTypeFilter, (s, exporter) => s + "|" + exporter.FileTypeFilter);
    165       var result = exportFileDialog.ShowDialog();
    166       if (result == DialogResult.OK) {
    167 
    168         var name = exportFileDialog.FileName;
    169         var selectedExporter = exporters.Single(exporter => exporter.FileTypeFilter == exportFileDialog.Filter);
    170 
    171         using (BackgroundWorker bg = new BackgroundWorker()) {
    172           MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Exportion solution to " + name + ".");
    173           bg.DoWork += (_, __) => selectedExporter.Export(Content, name);
    174           bg.RunWorkerCompleted += (_, __) => MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    175           bg.RunWorkerAsync();
    176         }
     149      catch (InvalidOperationException invalidOperationException) {
     150        ErrorHandling.ShowErrorDialog(this, invalidOperationException);
     151      }
     152      catch (ArgumentException argumentException) {
     153        ErrorHandling.ShowErrorDialog(this, argumentException);
    177154      }
    178155    }
     
    224201      validDragOperation = false;
    225202      if (ReadOnly) return;
     203      if (e.Effect != DragDropEffects.Copy) return;
    226204
    227205      var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
    228       if (dropData is DataAnalysisProblemData) validDragOperation = true;
     206      if (dropData is IDataAnalysisProblemData) validDragOperation = true;
    229207      else if (dropData is IDataAnalysisProblem) validDragOperation = true;
    230208      else if (dropData is IValueParameter) {
     
    248226      }
    249227      if (problemData == null) return;
    250       CheckCompatibilityOfProblemData(problemData);
    251       Content.ProblemData = (IDataAnalysisProblemData)problemData.Clone();
     228
     229      try {
     230        problemData.AdjustProblemDataProperties(Content.ProblemData);
     231        Content.ProblemData = problemData;
     232
     233        if (!Content.Name.EndsWith(" with changed problemData"))
     234          Content.Name += " with changed problemData";
     235      }
     236      catch (InvalidOperationException invalidOperationException) {
     237        ErrorHandling.ShowErrorDialog(this, invalidOperationException);
     238      }
     239      catch (ArgumentException argumentException) {
     240        ErrorHandling.ShowErrorDialog(this, argumentException);
     241      }
    252242    }
    253243    #endregion
    254244
    255     #region load problem data
    256     protected virtual bool CheckCompatibilityOfProblemData(IDataAnalysisProblemData problemData) {
    257       StringBuilder message = new StringBuilder();
    258       List<string> variables = problemData.InputVariables.Select(x => x.Value).ToList();
    259       foreach (var item in Content.ProblemData.InputVariables.CheckedItems) {
    260         if (!variables.Contains(item.Value.Value))
    261           message.AppendLine("Input variable '" + item.Value.Value + "' is not in the new problem data.");
    262       }
    263 
    264       if (message.Length != 0) {
    265         ErrorHandling.ShowErrorDialog(this, new InvalidOperationException(message.ToString()));
    266         return false;
    267       }
    268       return true;
    269     }
    270     #endregion
    271245  }
    272246}
Note: See TracChangeset for help on using the changeset viewer.