Changeset 16544


Ignore:
Timestamp:
01/22/19 09:15:40 (3 years ago)
Author:
chaider
Message:

#2971

  • Added editorconfig
  • Added Getter for intervals in NamedIntervals class
  • Changed GridView to show starting values of dataset
Location:
branches/2971_named_intervals
Files:
2 added
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r16536 r16544  
    4141    <DebugType>full</DebugType>
    4242    <Optimize>false</Optimize>
    43     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     43    <OutputPath>..\..\..\..\trunk\bin\</OutputPath>
    4444    <DefineConstants>DEBUG;TRACE</DefineConstants>
    4545    <ErrorReport>prompt</ErrorReport>
     
    306306    <Compile Include="ProblemDataView.Designer.cs">
    307307      <DependentUpon>ProblemDataView.cs</DependentUpon>
     308    </Compile>
     309    <Compile Include="Regression\NamedIntervalsView.cs">
     310      <SubType>UserControl</SubType>
     311    </Compile>
     312    <Compile Include="Regression\NamedIntervalsView.Designer.cs">
     313      <DependentUpon>NamedIntervalsView.cs</DependentUpon>
    308314    </Compile>
    309315    <Compile Include="Regression\ConfidenceRegressionSolutionEstimatedValuesView.cs">
     
    575581      <DependentUpon>AbstractFeatureCorrelationView.cs</DependentUpon>
    576582    </EmbeddedResource>
     583    <EmbeddedResource Include="Regression\NamedIntervalsView.resx">
     584      <DependentUpon>NamedIntervalsView.cs</DependentUpon>
     585    </EmbeddedResource>
    577586  </ItemGroup>
    578587  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/NamedIntervalsView.Designer.cs

    r16535 r16544  
    1 namespace HeuristicLab.Data.Views {
    2   partial class BoolMatrixView {
     1namespace HeuristicLab.Problems.DataAnalysis.Views {
     2  partial class NamedIntervalsView {
    33    /// <summary>
    44    /// Required designer variable.
     
    2424    /// </summary>
    2525    private void InitializeComponent() {
    26       this.pictureBox = new System.Windows.Forms.PictureBox();
    27       ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
     26      this.dataGridView = new System.Windows.Forms.DataGridView();
     27      this.groupBox1 = new System.Windows.Forms.GroupBox();
     28      ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
     29      this.groupBox1.SuspendLayout();
    2830      this.SuspendLayout();
    2931      //
    30       // pictureBox
     32      // dataGridView
    3133      //
    32       this.pictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    33             | System.Windows.Forms.AnchorStyles.Left)
     34      this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     35            | System.Windows.Forms.AnchorStyles.Left) 
    3436            | System.Windows.Forms.AnchorStyles.Right)));
    35       this.pictureBox.Location = new System.Drawing.Point(3, 3);
    36       this.pictureBox.Name = "pictureBox";
    37       this.pictureBox.Size = new System.Drawing.Size(144, 144);
    38       this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
    39       this.pictureBox.TabIndex = 0;
    40       this.pictureBox.TabStop = false;
     37      this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
     38      this.dataGridView.Location = new System.Drawing.Point(6, 19);
     39      this.dataGridView.Name = "dataGridView";
     40      this.dataGridView.RowHeadersWidth = 120;
     41      this.dataGridView.Size = new System.Drawing.Size(461, 378);
     42      this.dataGridView.TabIndex = 0;
     43      this.dataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellEndEdit);
     44      this.dataGridView.CellValidating += new System.Windows.Forms.DataGridViewCellValidatingEventHandler(this.dataGridView_CellValidating);
     45      this.dataGridView.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellValueChanged);
    4146      //
    42       // BoolMatrixView
     47      // groupBox1
     48      //
     49      this.groupBox1.Controls.Add(this.dataGridView);
     50      this.groupBox1.Location = new System.Drawing.Point(6, 4);
     51      this.groupBox1.Name = "groupBox1";
     52      this.groupBox1.Size = new System.Drawing.Size(473, 403);
     53      this.groupBox1.TabIndex = 1;
     54      this.groupBox1.TabStop = false;
     55      this.groupBox1.Text = "Interval Boundaries";
     56      //
     57      // NamedIntervalsView
    4358      //
    4459      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    4560      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    46       this.Controls.Add(this.pictureBox);
    47       this.Name = "BoolMatrixView";
    48       ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
     61      this.Controls.Add(this.groupBox1);
     62      this.Name = "NamedIntervalsView";
     63      this.Size = new System.Drawing.Size(482, 410);
     64      ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
     65      this.groupBox1.ResumeLayout(false);
    4966      this.ResumeLayout(false);
    5067
     
    5370    #endregion
    5471
    55     private System.Windows.Forms.PictureBox pictureBox;
     72    protected System.Windows.Forms.DataGridView dataGridView;
     73    private System.Windows.Forms.GroupBox groupBox1;
    5674  }
    5775}
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/NamedIntervalsView.cs

    r16535 r16544  
    2323using System.ComponentModel;
    2424using System.Drawing;
    25 using HeuristicLab.Core.Views;
     25using System.Linq;
     26using System.Security.Permissions;
     27using System.Windows.Forms;
    2628using HeuristicLab.MainForm;
     29using HeuristicLab.MainForm.WindowsForms;
     30using HeuristicLab.Problems.DataAnalysis.Implementation;
    2731
    28 namespace HeuristicLab.Data.Views {
     32namespace HeuristicLab.Problems.DataAnalysis.Views {
    2933
    30   [View("BoolMatrixView")]
    31   [Content(typeof(BoolMatrix), IsDefaultView = false)]
    32   public sealed partial class BoolMatrixView : ItemView {
    33     private BackgroundWorker worker;
     34  [View("NamedIntervals View")]
     35  [Content(typeof(NamedIntervals), true)]
     36  public partial class NamedIntervalsView : AsynchronousContentView {
    3437
    35     public new BoolMatrix Content {
    36       get { return (BoolMatrix)base.Content; }
    37       set { base.Content = value; }
     38    public new NamedIntervals Content {
     39      get => (NamedIntervals)base.Content;
     40      set => base.Content = value;
    3841    }
    3942
    40     public BoolMatrixView() {
    41       InitializeComponent();
     43    public DataGridView DataGridView {
     44      get => dataGridView;
    4245    }
    4346
    44     protected override void DeregisterContentEvents() {
    45       Content.ToStringChanged -= Content_ToStringChanged;
    46       base.DeregisterContentEvents();
    47     }
    48 
    49     protected override void RegisterContentEvents() {
    50       base.RegisterContentEvents();
    51       Content.ToStringChanged += Content_ToStringChanged;
    52     }
    53 
    54     private void Content_ToStringChanged(object sender, EventArgs e) {
    55       Rebuild();
    56     }
    57 
    58     private void Rebuild() {
    59       int width = pictureBox.Width;
    60       int height = pictureBox.Height;
    61       int tileWidth = width / Content.Columns;
    62       int tileHeight = height / Content.Rows;
    63       int border = (int)Math.Round((tileWidth + tileHeight) / 2.0 * 0.05);
    64       var bitmap = new Bitmap(width, height);
    65 
    66       if (worker != null)
    67         worker.CancelAsync();
    68 
    69       if (tileWidth == 0 || tileHeight == 0) {
    70         using (Graphics g = Graphics.FromImage(bitmap)) {
    71           g.DrawString("BoolMatrix is too big to draw.", DefaultFont, new SolidBrush(Color.Black), 10.0f, height / 2.0f);
    72           g.Flush();
    73         }
    74         pictureBox.Image = bitmap;
    75         return;
    76       }
    77 
    78       worker = new BackgroundWorker();
    79       worker.WorkerSupportsCancellation = true;
    80       worker.DoWork += (s, a) => {
    81         using (Graphics g = Graphics.FromImage(bitmap)) {
    82           for (int i = 0; i < Content.Rows; i++) {
    83             for (int j = 0; j < Content.Columns; j++) {
    84               if (worker.CancellationPending) {
    85                 a.Cancel = true;
    86                 break;
    87               }
    88               g.FillRectangle(Content[i, j] ? Brushes.Black : Brushes.White, i * tileWidth, j * tileHeight,
    89                                                                     tileWidth - border, tileHeight - border);
    90             }
    91           }
    92           g.Flush();
    93         }
    94       };
    95       worker.RunWorkerCompleted += (s, a) => {
    96         if (!a.Cancelled)
    97           pictureBox.Image = bitmap;
    98         if (!worker.CancellationPending)
    99           worker = null;
    100       };
    101       worker.RunWorkerAsync();
     47    public NamedIntervalsView() {
     48      InitializeComponent();
     49      setColumnNames();
     50      dataGridView.AutoGenerateColumns = false;
     51      dataGridView.AllowUserToAddRows = false;
    10252    }
    10353
     
    10555      base.OnContentChanged();
    10656      if (Content == null) {
    107         pictureBox.Image = new Bitmap(1, 1);
    108       } else {
    109         Rebuild();
     57        DataGridView.Rows.Clear();
     58        DataGridView.Columns.Clear();
     59      } else if (!DataGridView.IsCurrentCellInEditMode) {
     60        UpdateData();
    11061      }
     62    }
     63
     64    protected override void SetEnabledStateOfControls() {
     65      base.SetEnabledStateOfControls();
     66      dataGridView.Enabled = Content != null;
     67      dataGridView.ReadOnly = ReadOnly;
     68    }
     69
     70    protected void UpdateData() {
     71      var variablesCount = Content.VariableIntervals.Count;
     72
     73      DataGridViewRow[] rows = new DataGridViewRow[variablesCount];
     74      for (var i = 0; i < variablesCount; ++i) {
     75        var row = new DataGridViewRow();
     76        rows[i] = row;
     77      }
     78      dataGridView.Rows.AddRange(rows);
     79
     80      setRowsHeader();
     81      FillRows();
     82
     83      dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.ColumnHeader);
     84      dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders);
     85      dataGridView.Enabled = true;
     86
     87    }
     88
     89    protected void FillRows() {
     90      for (var i = 0; i < dataGridView.RowCount; ++i) {
     91        var key = (string)dataGridView.Rows[i].HeaderCell.Value;
     92        dataGridView.Rows[i].Cells[0].Value = Content.VariableIntervals[key].LowerBound;
     93        dataGridView.Rows[i].Cells[1].Value = Content.VariableIntervals[key].UpperBound;
     94      }
     95    }
     96
     97    protected void setRowsHeader() {   
     98      for (var i = 0; i < Content.VariableIntervals.Count; ++i) {
     99        var item = Content.VariableIntervals.ElementAt(i);
     100        dataGridView.Rows[i].HeaderCell.Value = item.Key;
     101      }
     102    }
     103
     104    protected void setColumnNames() {
     105      dataGridView.Columns.Add("lowerBound", "Lower Bound");
     106      dataGridView.Columns.Add("upperBound", "Upper Bound");
     107    }
     108
     109    private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) {
     110     
     111    }
     112
     113    private void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) {
     114      double value;
     115
     116      if (!double.TryParse(e.FormattedValue.ToString(), out value)) {
     117        dataGridView.Rows[e.RowIndex].ErrorText = "Value has to be a double value";
     118        e.Cancel = true;
     119      } else if (string.IsNullOrEmpty(e.FormattedValue.ToString())) {
     120        dataGridView.Rows[e.RowIndex].ErrorText = "Value has to best";
     121        e.Cancel = true;
     122      } else if (double.Parse(dataGridView.Rows[e.RowIndex].Cells[0].Value.ToString()) >
     123                 double.Parse(dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString())) {
     124        dataGridView.Rows[e.RowIndex].ErrorText = "Lower Bound of Interval has to be smaller than Upper Bound";
     125        e.Cancel = true;
     126      }
     127    }
     128
     129    private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
     130      dataGridView.Rows[e.RowIndex].ErrorText = string.Empty;
    111131    }
    112132  }
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/NamedIntervals.cs

    r16426 r16544  
    2424    }
    2525
     26    public ObservableDictionary<string, Interval> VariableIntervals => variableIntervals;
     27
    2628    public bool InsertMany(IEnumerable<KeyValuePair<string, Interval>> entries) {
    2729      if (entries == null) throw new ArgumentNullException("The given dataset is null.");
  • branches/2971_named_intervals/NamedIntervals.sln

    r16536 r16544  
    1313Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{469869A8-5D45-4838-BD0C-03B9A73CE9CA}"
    1414  ProjectSection(SolutionItems) = preProject
     15    .editorconfig = .editorconfig
    1516    Build.cmd = Build.cmd
    1617    Build.ps1 = Build.ps1
Note: See TracChangeset for help on using the changeset viewer.