#region License Information /* HeuristicLab * Copyright (C) 2002-2013 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 HeuristicLab.DataImporter.Command.View; using HeuristicLab.DataImporter.Data; using HeuristicLab.DataImporter.Data.CommandBase; using HeuristicLab.DataImporter.Data.Model; using HEAL.Attic; namespace HeuristicLab.DataImporter.Command { [StorableType("424BD4DD-1055-4DFF-96B3-69FF9846BB0D")] [ViewableCommandInfoAttribute("Linear Transformation", 1, ColumnGroupState.DoubleColumnSelected, "Change Values", Position = 6, OptionsView = typeof(LinearTransformationCommandView))] public class LinearTransformationCommand : ColumnGroupCommandWithAffectedColumnsBase { [StorableConstructor] protected LinearTransformationCommand(StorableConstructorFlag _) : base(_) { } public LinearTransformationCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns) : base(dataSet, columnGroupName, affectedColumns) { } [Storable] private double slope; public double Slope { get { return this.slope; } set { this.slope = value; } } [Storable] private double offset; public double Offset { get { return this.offset; } set { this.offset = value; } } public override string Description { get { return "Lineare Transformation"; } } public override void Execute() { base.Execute(); DoubleColumn column; foreach (int col in AffectedColumns) { if (ColumnGroup.GetColumn(col) is DoubleColumn) { column = (DoubleColumn)ColumnGroup.GetColumn(col); for (int i = 0; i < column.TotalValuesCount; i++) if (column.GetValue(i) != null) column.ChangeValue(i, (double)column.GetValue(i) * slope + offset); } } ColumnGroup.FireChanged(); ColumnGroup = null; } public override void UndoExecute() { base.UndoExecute(); DoubleColumn column; foreach (int col in AffectedColumns) { if (ColumnGroup.GetColumn(col) is DoubleColumn) { column = (DoubleColumn)ColumnGroup.GetColumn(col); for (int i = 0; i < column.TotalValuesCount; i++) if (column.GetValue(i) != null) column.ChangeValue(i, ((double)column.GetValue(i) - offset) / slope); } } ColumnGroup.FireChanged(); ColumnGroup = null; } } }