/// <summary>
        /// Invoked when the state of a data-grid cell has changed.
        /// </summary>
        private void dataGrid_CellStateChanged(object sender, DataGridViewCellStateChangedEventArgs e)
        {
            DataGridViewSelectedCellCollection selectedCells = this.dataGrid.SelectedCells;

            TableListEntry entry = this.tableList.SelectedItem as TableListEntry;

            if (entry.Table.IsReadOnly)
            {
                this.smoothButton.Enabled = false;
            }
            else
            {
/*                DataGridViewCellStyle style = Util.DefaultStyle;
 *              style.BackColor = Color.Black;
 *              style.ForeColor = Color.White;
 *
 *              foreach (DataGridViewCell cell in this.dataGrid.SelectedCells)
 *              {
 *                  cell.Style = style;
 *              }
 */
                if (this.Smooth(selectedCells, false))
                {
                    this.smoothButton.Enabled = true;
                }
                else
                {
                    this.smoothButton.Enabled = false;
                }
            }
        }
Exemple #2
0
        private void undoButton_Click(object sender, EventArgs e)
        {
            Command command = CommandHistory.Instance.Undo();

            this.changingTables = true;
            TableListEntry entry = this.tableList.SelectedItem as TableListEntry;

            Util.ShowTable(this, entry.Table, this.dataGrid);
            this.dataGrid.ClearSelection();
            if (entry.Table == this.tables.InitialAdvanceTiming || entry.Table == this.tables.ModifiedAdvanceTiming)
            {
                Util.ColorTable(this.dataGrid, entry.Table, this.selectedColumn, this.selectedRow, advanceTimingCellHit);
            }
            else if (entry.Table == this.tables.InitialBaseTiming || entry.Table == this.tables.ModifiedBaseTiming)
            {
                Util.ColorTable(this.dataGrid, entry.Table, this.selectedColumn, this.selectedRow, baseTimingCellHit);
            }
            else
            {
                Util.ColorTable(this.dataGrid, entry.Table, this.selectedColumn, this.selectedRow, null);
            }
            this.changingTables = false;
            disposeCellPopup();
            this.DrawSideViews(this.selectedColumn, this.selectedRow);
        }
        /// <summary>
        /// Invoked when the Copy button is clicked.
        /// </summary>
        private void copyButton_Click(object sender, EventArgs e)
        {
            TableListEntry entry = this.tableList.SelectedItem as TableListEntry;

            if (entry == null)
            {
                return;
            }

            ITable copyFrom = entry.Table;

            if ((entry.Table == this.tables.InitialAdvanceTiming) || (entry.Table == this.tables.ModifiedAdvanceTiming))
            {
                if (this.advancePadding > 0)
                {
                    string message = string.Format("The advance table will have the leftmost {0} columns removed.", this.advancePadding);
                    MessageBox.Show(this, message, "Timing Editor", MessageBoxButtons.OK);
                    copyFrom = Util.TrimLeft(copyFrom, this.advancePadding);
                }
            }

            string text = Util.CopyTable(copyFrom);

            Clipboard.SetData(DataFormats.Text, text);
        }
        /// <summary>
        /// Invoked when the undo button is clicked.
        /// </summary>
        private void undoButton_Click(object sender, EventArgs e)
        {
            Command command = CommandHistory.Instance.Undo();

            this.changingTables = true;
            TableListEntry entry = this.tableList.SelectedItem as TableListEntry;

            Util.ShowTable(this, entry.Table, this.dataGrid);
            Util.ColorTable(this.dataGrid, entry.Table, this.selectedColumn, this.selectedRow);
            this.changingTables = false;
            this.DrawSideViews(this.selectedColumn, this.selectedRow);
        }
        /// <summary>
        /// Invoked when the mouse is entering a data-grid cell.
        /// </summary>
        private void dataGrid_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            this.inCellMouseEnter = true;
            this.selectedColumn   = e.ColumnIndex;
            this.selectedRow      = e.RowIndex;

            TableListEntry entry = this.tableList.SelectedItem as TableListEntry;

            this.DrawSideViews(this.selectedColumn, this.selectedRow);
            Util.ColorTable(this.dataGrid, entry.Table, this.selectedColumn, this.selectedRow);
            this.inCellMouseEnter = false;
        }
        /// <summary>
        /// Invoked when the value of a data grid cell has changed.
        /// </summary>
        private void dataGrid_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (this.changingTables || this.inCellMouseEnter)
            {
                return;
            }

            TableListEntry entry = this.tableList.SelectedItem as TableListEntry;

            if (entry == null)
            {
                return;
            }

            ITable table = entry.Table;

            if (table == null)
            {
                return;
            }

            if (table.IsReadOnly)
            {
                return;
            }

            object cellValue      = this.dataGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
            string newStringValue = cellValue as string;

            double value;

            if (double.TryParse(newStringValue, out value))
            {
                EditCell edit = new EditCell(table, e.ColumnIndex, e.RowIndex, value);
                CommandHistory.Instance.Execute(edit);

                // The "smooth" button stops working if this code is enabled...

/*                foreach (DataGridViewCell cell in this.dataGrid.SelectedCells)
 *              {
 *                  // TODO: create an "EditSelectedCells" command, execute that instead, for better undo/redo
 *                  EditCell edit = new EditCell(table, cell.ColumnIndex, cell.RowIndex, value);
 *                  CommandHistory.Instance.Execute(edit);
 *                  cell.Value = value;
 *              }
 */
            }

            this.DrawSideViews(e.ColumnIndex, e.RowIndex);
        }
Exemple #7
0
 private void dataGrid_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
 {
     this.SuspendLayout();
     if (this.dataGrid.ColumnCount > 0 && this.dataGrid.RowCount > 0)
     {
         this.inCellMouseEnter = true;
         this.selectedColumn   = e.ColumnIndex;
         this.selectedRow      = e.RowIndex;
         TableListEntry entry = this.tableList.SelectedItem as TableListEntry;
         Util.ColorTable(this.dataGrid, entry.Table, this.selectedColumn, this.selectedRow, null);
         this.inCellMouseEnter = false;
     }
     this.DrawSideViews(this.selectedColumn, this.selectedRow);
     this.ResumeLayout(false);
     this.PerformLayout();
 }
Exemple #8
0
 private void dataGrid_CellEnter(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         disposeCellPopup();
         TableListEntry entry = this.tableList.SelectedItem as TableListEntry;
         if (e.ColumnIndex >= 0 && e.RowIndex >= 0 && entry != null && dataGrid.GetCellCount(DataGridViewElementStates.Selected) == 1 &&
             dataGrid.SelectedCells[0].RowIndex == e.RowIndex && dataGrid.SelectedCells[0].ColumnIndex == e.ColumnIndex && dataGrid[e.ColumnIndex, e.RowIndex].IsInEditMode == false)
         {
             String[,] cellHit = null;
             if (entry.Table == this.tables.InitialAdvanceTiming || entry.Table == this.tables.ModifiedAdvanceTiming)
             {
                 cellHit = advanceTimingCellHit;
             }
             else if (entry.Table == this.tables.InitialBaseTiming || entry.Table == this.tables.ModifiedBaseTiming)
             {
                 cellHit = baseTimingCellHit;
             }
             if (cellHit != null)
             {
                 if (cellHit[e.ColumnIndex, e.RowIndex] != null)
                 {
                     cellPopup = new CellPopup();
                     cellPopup.textBox.Text = cellHit[e.ColumnIndex, e.RowIndex];
                     Rectangle r = dataGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
                     cellPopup.Location = dataGrid.PointToScreen(new Point(r.Location.X + r.Width, r.Location.Y - cellPopup.Height));
                     cellPopup.Show(dataGrid);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error: " + ex.Message);
     }
 }
Exemple #9
0
        private void smoothComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataGridViewSelectedCellCollection selectedCells = this.dataGrid.SelectedCells;
            TableListEntry entry = this.tableList.SelectedItem as TableListEntry;

            if (entry != null)
            {
                if (entry.Table.IsReadOnly)
                {
                    this.smoothButton.Enabled = false;
                }
                else
                {
                    if (this.Smooth(selectedCells, false))
                    {
                        this.smoothButton.Enabled = true;
                    }
                    else
                    {
                        this.smoothButton.Enabled = false;
                    }
                }
            }
        }
        /// <summary>
        /// Invoked when the paste button is clicked.
        /// </summary>
        private void pasteButton_Click(object sender, EventArgs e)
        {
            TableListEntry entry = this.tableList.SelectedItem as TableListEntry;

            if (entry == null)
            {
                return;
            }

            try
            {
                string tableText = Clipboard.GetData(System.Windows.Forms.DataFormats.Text) as string;
                if (string.IsNullOrEmpty(tableText))
                {
                    throw new ApplicationException("Doesn't contain text.");
                }

                this.changingTables = true;
                bool wasReadOnly = entry.Table.IsReadOnly;
                if (wasReadOnly)
                {
                    entry.Table.IsReadOnly = false;
                }

                Table temporaryTable = new Table();
                Util.LoadTable(tableText, temporaryTable);

                if ((entry.Table == this.tables.InitialAdvanceTiming) || (entry.Table == this.tables.ModifiedAdvanceTiming))
                {
                    if (temporaryTable.ColumnHeaders.Count < this.tables.InitialBaseTiming.ColumnHeaders.Count)
                    {
                        MessageBox.Show(this, "The advance table will have values added to the left side, to make it align with the base timing table.", "Timing Editor", MessageBoxButtons.OK);
                        this.advancePadding = this.tables.InitialBaseTiming.ColumnHeaders.Count - temporaryTable.ColumnHeaders.Count;
                        temporaryTable      = Util.PadLeft(temporaryTable, this.tables.InitialBaseTiming.ColumnHeaders.Count);
                    }
                    else
                    {
                        this.advancePadding = 0;
                    }
                }

                temporaryTable.CopyTo(entry.Table);

                if (wasReadOnly)
                {
                    entry.Table.IsReadOnly = true;
                }
                Util.ShowTable(this, entry.Table, this.dataGrid);
                this.changingTables = false;

                if (entry.Table == this.tables.InitialBaseTiming)
                {
                    temporaryTable.CopyTo(this.tables.ModifiedBaseTiming);
                    //Util.LoadTable(tableText, this.tables.ModifiedBaseTiming);
                }

                if (entry.Table == this.tables.InitialAdvanceTiming)
                {
                    temporaryTable.CopyTo(this.tables.ModifiedAdvanceTiming);
                    //Util.LoadTable(tableText, this.tables.ModifiedAdvanceTiming);
                }
            }
            catch (ApplicationException ex)
            {
                string errorMessageFormat = "Clipboard does not contain valid table data.\r\n{0}";
                MessageBox.Show(string.Format(errorMessageFormat, ex.Message));
            }
        }
        /// <summary>
        /// Invoked when the selected-index of the table list has changed.
        /// </summary>
        private void tableList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.tableList.SelectedItem == null)
            {
                return;
            }

            TableListEntry entry = this.tableList.SelectedItem as TableListEntry;
            string         title;

            if (this.singleTableMode)
            {
                this.statusStrip1.Items[0].Text = "This is a reduced-functionality version of Timing Editor, for use with a single table.";
                title = "Table Editor {0}";
            }
            else
            {
                title = "Timing Editor {0}: " + entry.Description;
                this.pasteButton.Enabled        = entry.AllowPaste;
                this.statusStrip1.Items[0].Text = entry.StatusText;
            }

            this.Text = string.Format(title, "v14");

            if (entry.Table.IsPopulated)
            {
                try
                {
                    List <int[]> selectedIndices = new List <int[]>(this.dataGrid.SelectedCells.Count);
                    DataGridViewSelectedCellCollection selected = this.dataGrid.SelectedCells;
                    foreach (DataGridViewCell cell in selected)
                    {
                        selectedIndices.Add(new int[2] {
                            cell.ColumnIndex, cell.RowIndex
                        });
                    }

                    this.dataGrid.ReadOnly = entry.Table.IsReadOnly;
                    this.changingTables    = true;
                    Util.ShowTable(this, entry.Table, this.dataGrid);
                    this.DrawSideViews(this.selectedColumn, this.selectedRow);
                    Util.ColorTable(this.dataGrid, entry.Table, this.selectedColumn, this.selectedRow);
                    this.dataGrid.ClearSelection();
                    this.changingTables = false;
                    foreach (int[] pair in selectedIndices)
                    {
                        dataGrid.Rows[pair[1]].Cells[pair[0]].Selected = true;
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    this.dataGrid.ClearSelection();
                    dataGrid.Rows.Clear();
                    this.statusStrip1.Items[0].Text = "This only works if the base and advance tables are the same size";
                }
            }
            else
            {
                this.changingTables = true;
                this.dataGrid.Columns.Clear();
                this.changingTables = false;
            }

            if (entry.Table.IsReadOnly)
            {
                this.smoothButton.Enabled = false;
            }

/*            DataGridViewCell cell;
 *          if (this.dataGrid.SelectedCells.Count == 1)
 *          {
 *              cell = this.dataGrid.SelectedCells[0];
 *              this.DrawSideViews(cell.ColumnIndex, cell.RowIndex);
 *          }            */
        }
Exemple #12
0
        private void logOverlayButton_Click(object sender, EventArgs e)
        {
            TableListEntry entry = this.tableList.SelectedItem as TableListEntry;

            if (entry != null)
            {
                disposeCellPopup();
                this.dataGrid.ClearSelection();
                if (entry.Table.IsReadOnly)
                {
                    this.logOverlayButton.Enabled = false;
                }
                else if (!entry.Table.IsPopulated)
                {
                    MessageBox.Show("Error: Please populate table first");
                }
                else
                {
                    String         line;
                    OpenFileDialog file = new OpenFileDialog();
                    if (file.ShowDialog() == DialogResult.OK)
                    {
                        StreamReader sr = new StreamReader(file.FileName, Encoding.Default);
                        try
                        {
                            line = sr.ReadLine();
                            if (line != null)
                            {
                                String[] header = line.Split(',');
                                int      i      = 0;
                                foreach (String h in header)
                                {
                                    header[i++] = h.Trim();
                                }
                                LogOverlay logOverlay = new LogOverlay();
                                logOverlay.LogParameters = header;
                                if (DialogResult.OK == logOverlay.ShowDialog(this))
                                {
                                    String[] selected = logOverlay.LogParameters;
                                    String   xAxis    = logOverlay.XAxis;
                                    String   yAxis    = logOverlay.YAxis;
                                    if (selected.Length > 0)
                                    {
                                        String[,] cellHit = null;
                                        if (entry.Table == this.tables.InitialAdvanceTiming || entry.Table == this.tables.ModifiedAdvanceTiming)
                                        {
                                            advanceTimingCellHit = new String [entry.Table.ColumnHeaders.Count, entry.Table.RowHeaders.Count];
                                            cellHit = advanceTimingCellHit;
                                        }
                                        else if (entry.Table == this.tables.InitialBaseTiming || entry.Table == this.tables.ModifiedBaseTiming)
                                        {
                                            baseTimingCellHit = new String [entry.Table.ColumnHeaders.Count, entry.Table.RowHeaders.Count];
                                            cellHit           = baseTimingCellHit;
                                        }
                                        int   xIdx    = Array.IndexOf(header, xAxis);
                                        int   yIdx    = Array.IndexOf(header, yAxis);
                                        int[] indeces = new int[selected.Length];
                                        for (i = 0; i < selected.Length; ++i)
                                        {
                                            indeces[i] = Array.IndexOf(header, selected[i]);
                                        }
                                        Cursor cursor = Cursor.Current;
                                        Cursor.Current = Cursors.WaitCursor;
                                        double X, Y, x, y, v;
                                        int    xArrIdx, yArrIdx;
                                        this.changingTables = true;
                                        try
                                        {
                                            List <double> xAxisArray = (List <double>)entry.Table.ColumnHeaders;
                                            List <double> yAxisArray = (List <double>)entry.Table.RowHeaders;
                                            Dictionary <int, Dictionary <int, Dictionary <String, String> > > xDict = new Dictionary <int, Dictionary <int, Dictionary <String, String> > >();
                                            Dictionary <int, Dictionary <String, String> > yDict;
                                            Dictionary <String, String> paramDict;
                                            String val;
                                            while ((line = sr.ReadLine()) != null)
                                            {
                                                String[] vals = line.Split(',');
                                                if (double.TryParse(vals[xIdx], out x) && double.TryParse(vals[yIdx], out y))
                                                {
                                                    X = xAxisArray[Util.ClosestValueIndex(x, xAxisArray)];
                                                    Y = yAxisArray[Util.ClosestValueIndex(y, yAxisArray)];
                                                    for (int idx = 0; idx < indeces.Length; ++idx)
                                                    {
                                                        if (idx == xIdx || idx == yIdx)
                                                        {
                                                            continue;
                                                        }
                                                        if (double.TryParse(vals[indeces[idx]], out v) && v != 0.0)
                                                        {
                                                            xArrIdx = xAxisArray.IndexOf(X);
                                                            yArrIdx = yAxisArray.IndexOf(Y);

                                                            if (!xDict.TryGetValue(xArrIdx, out yDict))
                                                            {
                                                                yDict          = new Dictionary <int, Dictionary <String, String> >();
                                                                xDict[xArrIdx] = yDict;
                                                            }
                                                            if (!yDict.TryGetValue(yArrIdx, out paramDict))
                                                            {
                                                                paramDict      = new Dictionary <String, String>();
                                                                yDict[yArrIdx] = paramDict;
                                                            }
                                                            if (!paramDict.TryGetValue(selected[idx], out val))
                                                            {
                                                                paramDict[selected[idx]] = "    [" + x + ", " + y + ", " + v + "]\r\n";
                                                            }
                                                            else
                                                            {
                                                                paramDict[selected[idx]] += ("    [" + x + ", " + y + ", " + v + "]\r\n");
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            foreach (KeyValuePair <int, Dictionary <int, Dictionary <String, String> > > xPair in xDict)
                                            {
                                                foreach (KeyValuePair <int, Dictionary <String, String> > yPair in xPair.Value)
                                                {
                                                    foreach (KeyValuePair <String, String> paramPair in yPair.Value)
                                                    {
                                                        if (cellHit[xPair.Key, yPair.Key] == null)
                                                        {
                                                            cellHit[xPair.Key, yPair.Key] = "";
                                                        }
                                                        cellHit[xPair.Key, yPair.Key] += (paramPair.Key + ":\r\n" + paramPair.Value);
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show("Error: " + ex.Message);
                                        }
                                        Util.ColorTable(this.dataGrid, entry.Table, this.selectedColumn, this.selectedRow, cellHit);
                                        this.dataGrid.Refresh();
                                        this.changingTables = false;
                                        Cursor.Current      = cursor;
                                    }
                                    else
                                    {
                                        MessageBox.Show("Error: No parameters were selected");
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error: " + ex.Message);
                        }
                        finally
                        {
                            sr.Close();
                        }
                    }
                }
            }
        }