Esempio n. 1
0
        private void table_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            DataGrid dg = sender as DataGrid;

            if (dg == null || e == null)
            {
                return;
            }

            if (e.AddedCells != null && e.AddedCells.Count > 0)
            {
                BigTableRow item = e.AddedCells[0].Item as BigTableRow;
                if (item != null)
                {
                    int row_ind = item.Col00_Index - 1;

                    int col_ind = e.AddedCells[0].Column.DisplayIndex;

                    string content = item.GetColAt(col_ind);
                    double value   = 0;
                    bool   success = double.TryParse(content, NumberStyles.Float, BigTableRow.FORMATTER, out value);
                    if (success)
                    {
                        RectangularValue rv = new RectangularValue()
                        {
                            RightBottom = value,
                            RightTop    = value,
                            LeftBottom  = value,
                            LeftTop     = value
                        };
                        MultiValPointer pointer = new MultiValPointer(new List <int> {
                            row_ind, col_ind, 0
                        }, new Point(1, 1), new Point(0, 0), true, rv, false);
                        if (pointer != MultiValPointer.INVALID)
                        {
                            this.DataField.MVDisplayVector = pointer;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        protected override void line_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Line line = sender as Line;

            if (line == null)
            {
                return;
            }
            if (this.canvas == null)
            {
                return;
            }
            if (this.fact_x == 0 || this.fact_y == 0)
            {
                return;
            }

            // save the graph indices (added 27.10.2016)
            int ind_graph     = -1;
            int ind_line_segm = -1;

            if (line.Tag != null)
            {
                if (line.Tag is Point)
                {
                    Point p = (Point)line.Tag;
                    ind_graph     = (int)p.X;
                    ind_line_segm = (int)p.Y;
                }
            }

            // communicate to others
            this.MarkSet = true;

            Point pos = e.GetPosition(this.canvas);

            // apply snap
            if (Math.Abs(line.X1 - pos.X) <= MValueFunct2DBase.SNAP_DIST_PX &&
                Math.Abs(line.Y1 - pos.Y) <= MValueFunct2DBase.SNAP_DIST_PX)
            {
                pos.X = line.X1;
                pos.Y = line.Y1;
            }
            if (Math.Abs(line.X2 - pos.X) <= MValueFunct2DBase.SNAP_DIST_PX &&
                Math.Abs(line.Y2 - pos.Y) <= MValueFunct2DBase.SNAP_DIST_PX)
            {
                pos.X = line.X2;
                pos.Y = line.Y2;
            }

            double x_left   = Math.Min(line.X1, line.X2);
            double x_right  = Math.Max(line.X1, line.X2);
            double y_top    = Math.Min(line.Y1, line.Y2);
            double y_bottom = Math.Max(line.Y1, line.Y2);

            double y_left  = 0;
            double y_right = 0;

            if (x_left == line.X1)
            {
                y_left  = line.Y1;
                y_right = line.Y2;
            }
            else
            {
                y_left  = line.Y2;
                y_right = line.Y1;
            }

            Point pos_rel = new Point(0, 0);

            pos_rel.X = (Math.Abs(line.X1 - line.X2) < ParameterStructure.Parameter.Calculation.MIN_DOUBLE_VAL) ? 1 : Math.Abs(x_left - pos.X) / Math.Abs(line.X1 - line.X2);
            pos_rel.Y = (Math.Abs(line.Y1 - line.Y2) < ParameterStructure.Parameter.Calculation.MIN_DOUBLE_VAL) ? 1 : Math.Abs(y_bottom - pos.Y) / Math.Abs(line.Y1 - line.Y2);
            if (pos_rel.X < 0)
            {
                pos_rel.X = 0;
            }
            if (pos_rel.X > 1)
            {
                pos_rel.X = 1;
            }
            if (pos_rel.Y < 0)
            {
                pos_rel.Y = 0;
            }
            if (pos_rel.Y > 1)
            {
                pos_rel.Y = 1;
            }

            // calculate the interpolated value
            // scaling ACTUAL -> SCALED
            // double x1_scaled = (_x1 - this.xs[0]) * this.fact_x;
            // double y1_scaled = this.canvas.Height - (_y1 - this.ys[0]) * this.fact_y;

            // scaling SCALED -> ACTUAL
            RectangularValue rv = new RectangularValue();

            if (Math.Abs(x_left - x_right) >= ParameterStructure.Parameter.Calculation.MIN_DOUBLE_VAL)
            {
                rv.LeftBottom  = (this.canvas.Height - y_left) / this.fact_y + this.ys[0];
                rv.LeftTop     = rv.LeftBottom;
                rv.RightBottom = (this.canvas.Height - y_right) / this.fact_y + this.ys[0];
                rv.RightTop    = rv.RightBottom;
            }
            else
            {
                // account for vertical function segments
                rv.LeftBottom  = (this.canvas.Height - y_bottom) / this.fact_y + this.ys[0];
                rv.RightBottom = rv.LeftBottom;
                rv.LeftTop     = (this.canvas.Height - y_top) / this.fact_y + this.ys[0];
                rv.RightTop    = rv.LeftTop;
            }

            MultiValPointer pointer = new MultiValPointer(new List <int> {
                ind_graph, ind_line_segm, this.Depth
            },
                                                          new Point(Math.Abs(line.X1 - line.X2), Math.Abs(line.Y1 - line.Y2)),
                                                          pos_rel,
                                                          false, rv, true,
                                                          x_left, y_top);

            this.DataField.MVDisplayVector = pointer;
            if (pointer != MultiValPointer.INVALID)
            {
                this.SetMark(pos, pointer.Value);
            }
        }
Esempio n. 3
0
        private void rect_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Rectangle rect = sender as Rectangle;

            if (rect == null)
            {
                return;
            }

            // communicate to others
            this.MarkSet = true;

            // detect position in the grid
            string name = rect.Name;

            string[] grid_pos = name.Split(new string[] { "x_", "__y_" }, StringSplitOptions.RemoveEmptyEntries);
            if (grid_pos == null || grid_pos.Length != 2)
            {
                return;
            }

            int row_index = -1, col_index = -1;

            int.TryParse(grid_pos[0], out col_index);
            int.TryParse(grid_pos[1], out row_index);
            if (row_index < 0 || col_index < 0)
            {
                return;
            }

            // detect position in the value table
            if (!(rect.Tag is RectangularValue))
            {
                return;
            }

            RectangularValue rv = (RectangularValue)rect.Tag;

            Point pos = e.GetPosition(rect);

            // apply snap
            if ((rect.Width - pos.X) <= MValueField2DBase.SNAP_DIST_PX)
            {
                pos.X = rect.Width;
            }
            if (pos.X <= MValueField2DBase.SNAP_DIST_PX)
            {
                pos.X = 0;
            }
            if ((rect.Height - pos.Y) <= MValueField2DBase.SNAP_DIST_PX)
            {
                pos.Y = rect.Height;
            }
            if (pos.Y <= MValueField2DBase.SNAP_DIST_PX)
            {
                pos.Y = 0;
            }

            MultiValPointer pointer = new MultiValPointer(new List <int> {
                row_index, col_index, this.Depth
            },
                                                          new Point(this.column_width, this.row_height),
                                                          pos,
                                                          true, rv, this.DataField.MVCanInterpolate);

            this.DataField.MVDisplayVector = pointer;
            if (pointer != MultiValPointer.INVALID)
            {
                this.SetMark(pointer.CellIndices[0], pointer.CellIndices[1], pointer.PosInCell_AbsolutePx, pointer.Value);
            }
        }
Esempio n. 4
0
        protected override void FillDataCells()
        {
            for (int c = 2; c < this.nr_columns + 2; c++)
            {
                for (int r = 2; r < this.nr_rows + 2; r++)
                {
                    // cell
                    Rectangle rect = new Rectangle();
                    rect.Height          = Math.Max(this.row_height, 1);
                    rect.Width           = Math.Max(this.column_width, 1);
                    rect.Fill            = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#CCFFFFFF"));
                    rect.StrokeThickness = 0.5;
                    rect.StrokeDashArray = new DoubleCollection {
                        5, 5
                    };
                    rect.Stroke   = new SolidColorBrush(Colors.Black);
                    rect.Name     = "x_" + c + "__y_" + (this.nr_rows + 1 - r);
                    rect.MouseUp += this.rect_MouseUp;

                    RectangularValue rv = new RectangularValue();
                    rv.LeftBottom  = this.DataField.Field[new Point3D(c - 2, r - 2, this.Depth)];
                    rv.RightBottom = (c == this.nr_columns + 1) ? rv.LeftBottom : this.DataField.Field[new Point3D(c - 1, r - 2, this.Depth)];
                    rv.LeftTop     = (r == this.nr_rows + 1) ? rv.LeftBottom : this.DataField.Field[new Point3D(c - 2, r - 1, this.Depth)];
                    if (c == this.nr_columns + 1 && r == this.nr_rows + 1)
                    {
                        rv.RightTop = rv.LeftBottom;
                    }
                    else if (c == this.nr_columns + 1 && r < this.nr_rows + 1)
                    {
                        rv.RightTop = this.DataField.Field[new Point3D(c - 2, r - 1, this.Depth)];
                    }
                    else if (c < this.nr_columns + 1 && r == this.nr_rows + 1)
                    {
                        rv.RightTop = this.DataField.Field[new Point3D(c - 1, r - 2, this.Depth)];
                    }
                    else
                    {
                        rv.RightTop = this.DataField.Field[new Point3D(c - 1, r - 1, this.Depth)];
                    }
                    rect.Tag = rv;

                    Grid.SetRow(rect, this.nr_rows + 1 - r);
                    Grid.SetColumn(rect, c);
                    this.Children.Add(rect);

                    // value
                    TextBlock tbl = new TextBlock();
                    tbl.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    tbl.VerticalAlignment   = System.Windows.VerticalAlignment.Bottom;
                    tbl.Margin           = new Thickness(1);
                    tbl.FontSize         = 10;
                    tbl.Foreground       = new SolidColorBrush(Colors.Black);
                    tbl.Tag              = new Point3D(c - 2, r - 2, 0);
                    tbl.Text             = this.Fxys[(r - 2) * MValueField2DBase.MAX_NR_COLS + (c - 2)].Z.ToString("F2", MValueField2DBase.FORMATTER);
                    tbl.IsHitTestVisible = false;

                    Grid.SetRow(tbl, this.nr_rows + 1 - r);
                    Grid.SetColumn(tbl, c);
                    this.Children.Add(tbl);
                }
            }
        }