Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13514


Ignore:
Timestamp:
01/15/16 15:21:04 (9 years ago)
Author:
pfleck
Message:

#2559

  • Enabled pasting values with headers into preprocessing. The headers will be extracted and the columns renamed.
  • Removed an unnecessary interface.
Location:
trunk/sources
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.cs

    r13252 r13514  
    3131namespace HeuristicLab.DataPreprocessing.Views {
    3232  [View("Data Grid Content View")]
    33   [Content(typeof(IDataGridContent), true)]
     33  [Content(typeof(DataGridContent), true)]
    3434  public partial class DataGridContentView : StringConvertibleMatrixView {
    3535
     
    4242    private Tuple<int, int> currentCell;
    4343
    44     public new IDataGridContent Content {
    45       get { return (IDataGridContent)base.Content; }
     44    public new DataGridContent Content {
     45      get { return (DataGridContent)base.Content; }
    4646      set { base.Content = value; }
    4747    }
     
    145145    protected override void PasteValuesToDataGridView() {
    146146      string[,] values = SplitClipboardString(Clipboard.GetText());
     147      if (values.Length == 0) return;
    147148      int rowIndex = 0;
    148149      int columnIndex = 0;
     
    151152        columnIndex = dataGridView.CurrentCell.ColumnIndex;
    152153      }
    153       if (Content.Rows < values.GetLength(1) + rowIndex) Content.Rows = values.GetLength(1) + rowIndex;
    154       if (Content.Columns < values.GetLength(0) + columnIndex) Content.Columns = values.GetLength(0) + columnIndex;
     154
     155      bool containsHeader = false;
     156      var firstRow = Enumerable.Range(0, values.GetLength(0)).Select(col => values[col, 0]).ToList();
     157      if ((Content.Selection.Values.Sum(s => s.Count) == Content.Rows * Content.Columns)
     158          || (rowIndex == 0 && columnIndex == 0 && Content.Rows <= values.GetLength(1) && Content.Columns <= values.GetLength(0))) {
     159        // All is selected -or- top left selected and everything will be replaced
     160        double temp;
     161        containsHeader = !firstRow.All(string.IsNullOrEmpty) && firstRow.Any(r => !double.TryParse(r, out temp));
     162        if (containsHeader)
     163          rowIndex = columnIndex = 0;
     164      }
     165
     166      int newRows = values.GetLength(1) + rowIndex - (containsHeader ? 1 : 0);
     167      int newColumns = values.GetLength(0) + columnIndex;
     168      if (Content.Rows < newRows) Content.Rows = newRows;
     169      if (Content.Columns < newColumns) Content.Columns = newColumns;
    155170
    156171      ReplaceTransaction(() => {
    157172        Content.PreProcessingData.InTransaction(() => {
    158           for (int row = 0; row < values.GetLength(1); row++) {
     173          for (int row = containsHeader ? 1 : 0; row < values.GetLength(1); row++) {
    159174            for (int col = 0; col < values.GetLength(0); col++) {
    160               Content.SetValue(values[col, row], row + rowIndex, col + columnIndex);
     175              Content.SetValue(values[col, row], row + rowIndex - (containsHeader ? 1 : 0), col + columnIndex);
    161176            }
     177          }
     178          if (containsHeader) {
     179            for (int i = 0; i < firstRow.Count; i++)
     180              if (string.IsNullOrWhiteSpace(firstRow[i]))
     181                firstRow[i] = string.Format("<{0}>", i);
     182            Content.PreProcessingData.RenameColumns(firstRow);
    162183          }
    163184        });
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/DataGridContent.cs

    r13508 r13514  
    2626using HeuristicLab.Common;
    2727using HeuristicLab.Core;
     28using HeuristicLab.Data;
    2829
    2930namespace HeuristicLab.DataPreprocessing {
    3031
    3132  [Item("DataGrid", "Represents a data grid.")]
    32   public class DataGridContent : Item, IViewShortcut, IDataGridContent {
     33  public class DataGridContent : Item, IStringConvertibleMatrix, IViewShortcut {
    3334
    3435    public ITransactionalPreprocessingData PreProcessingData { get; private set; }
  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/HeuristicLab.DataPreprocessing-3.4.csproj

    r13508 r13514  
    108108    <Compile Include="Logic\SearchLogic.cs" />
    109109    <Compile Include="Logic\StatisticsLogic.cs" />
    110     <Compile Include="Content\IDataGridContent.cs" />
    111110    <Compile Include="Data\ITransactionalPreprocessingData.cs" />
    112111    <Compile Include="Plugin.cs" />
Note: See TracChangeset for help on using the changeset viewer.