Exemplo n.º 1
0
 public override void Move(PlotterGraphics pg, Point offset)
 {
     foreach (Line l in _lines)
     {
         l.Move(pg, offset);
     }
 }
Exemplo n.º 2
0
        public override bool CursorIsOn(PlotterGraphics pg, Point p, int tol)
        {
            // p relative to _c0
            Complex pc = Complex.Subtract(new Complex(p.X, p.Y), new Complex(_c0.X, _c0.Y));

            return(pc.Magnitude < _r + tol && pc.Magnitude > _r - tol);
        }
Exemplo n.º 3
0
        private void OnMouseDown(object sender, MouseEventArgs e)
        {
            PlotterGraphics pg = new PlotterGraphics(_vr, _plot.CreateGraphics());

            _mouseDownAt = e.Location;
            _mouseMoveAt = e.Location;

            if (Control.ModifierKeys == Keys.Shift)
            {
                _band = true;
            }
            else if (Control.ModifierKeys == Keys.None)
            {
                if (_mapper != null && _mapper.CursorIsOn(pg, e.Location, _vr.CXSize / 100))
                {
                    _mapper.Select(pg);
                }
                else
                {
                    //if (_plotter != null)
                    //{
                    //    List<PointDO> ps = new List<PointDO>();
                    //    ps.Add(new PointDO(_vr.CToV(e.Location)));
                    //    _plotter.PlotPoints(ps);
                    //}
                }
            }
        }
Exemplo n.º 4
0
 public override void Draw(PlotterGraphics g)
 {
     foreach (Line l in _lines)
     {
         l.Draw(g);
     }
 }
Exemplo n.º 5
0
        public override bool CursorIsOn(PlotterGraphics pg, Point p, int tol)
        {
            Complex pc = new Complex((double)p.X, (double)p.Y);
            Complex c0 = new Complex((double)_p0.X, (double)_p0.Y);
            Complex c1 = new Complex((double)_p1.X, (double)_p1.Y);
            Complex xt = new Complex((double)tol, 0.0);
            Complex yt = new Complex(0.0, (double)tol);

            // has the p0 end been selected
            Complex ce = Complex.Subtract(pc, c0);

            if (ce.Magnitude < tol)
            {
                _mode = SelectMode.P0;
                return(true);
            }

            // has the p1 end been selected
            ce = Complex.Subtract(pc, c1);
            if (ce.Magnitude < tol)
            {
                _mode = SelectMode.P1;
                return(true);
            }

            // make c0 the left most point, i.e. c0 has smallest real value
            if (c0.Real > c1.Real)
            {
                Complex c = c0; c0 = c1; c1 = c;
            }

            // move origin to c0
            Complex c1p = Complex.Subtract(c1, c0);
            Complex pp  = Complex.Subtract(pc, c0);

            // rotate so that c1p lies on real axis
            Complex r = new Complex(c1p.Real / c1p.Magnitude, -c1p.Imaginary / c1p.Magnitude);

            c1p = Complex.Multiply(c1p, r);
            pp  = Complex.Multiply(pp, r);
            xt  = Complex.Multiply(xt, r);
            yt  = Complex.Multiply(yt, r);

            // take worst case of tolerances in x and y directions
            double dxp = Math.Max(Math.Abs(xt.Real), Math.Abs(yt.Real));
            double dyp = Math.Max(Math.Abs(xt.Imaginary), Math.Abs(yt.Imaginary));

            // is pp within tolerance of the line c0 (origin) to c1p
            if (pp.Real > -dxp && pp.Real < c1p.Real + dxp &&
                pp.Imaginary > -dyp && pp.Imaginary < c1p.Imaginary + dyp)
            {
                _mode = SelectMode.Line;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 6
0
 public virtual void Deselect(PlotterGraphics pg)
 {
     if (Selected)
     {
         Selected = false;
         Draw(pg);
     }
 }
Exemplo n.º 7
0
 public override void Select(PlotterGraphics pg)
 {
     foreach (Line l in _lines)
     {
         l.Select(pg);
     }
     Selected = true;
 }
Exemplo n.º 8
0
 public override void Deselect(PlotterGraphics pg)
 {
     foreach (Line l in _lines)
     {
         l.Deselect(pg);
     }
     Selected = false;
 }
Exemplo n.º 9
0
 public override void Move(PlotterGraphics pg, Point offset)
 {
     if (Selected)
     {
         _c0.Offset(offset);
         Draw(pg);
     }
 }
Exemplo n.º 10
0
        public void PlotPoints(List <PointDO> points)
        {
            _mainImage.Clear();
            PlotterGraphics pg = new PlotterGraphics(_vr, _mainImage.Graphics);

            _axes.Draw(pg);
            pg.PlotPoints(points);
            DisplayImage();
        }
Exemplo n.º 11
0
 public override bool CursorIsOn(PlotterGraphics pg, Point p, int tol)
 {
     foreach (Line l in _lines)
     {
         if (l.CursorIsOn(pg, p, tol))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 12
0
 public override void Draw(PlotterGraphics pg)
 {
     pg.DrawLineC(_p0, _p1, _color);
     if (Selected && _mode == SelectMode.P0)
     {
         pg.DrawCircleC(_p0, 5);
     }
     if (Selected && _mode == SelectMode.P1)
     {
         pg.DrawCircleC(_p1, 5);
     }
 }
Exemplo n.º 13
0
        private void OnMouseUp(object sender, MouseEventArgs e)
        {
            if (_band)
            {
                // clear the rubber band
                _bandImage.Clear();

                // re-calculate x axis
                int l = _mouseDownAt.X;
                int u = e.X;
                if (l > u)
                {
                    (l, u) = (u, l);
                }
                _axes.XAxis.Initialise(_vr.XCToV(l), _vr.XCToV(u), _origin.X, _noOfTicks);
                _vr.SetXExtent(new RangeD(_axes.XAxis.Min, _axes.XAxis.Max));

                // re-calculate y axis
                l = _mouseDownAt.Y;
                u = e.Y;
                if (l > u)
                {
                    (l, u) = (u, l);
                }
                _axes.YAxis.Initialise(_vr.YCToV(u), _vr.YCToV(l), _origin.Y, _noOfTicks);
                _vr.SetYExtent(new RangeD(_axes.YAxis.Min, _axes.YAxis.Max));

                // redraw
                Replot();
                _band = false;
            }
            else
            {
                if (_mapper != null && _mapper.Selected)
                {
                    _mapperImage.Clear();
                    PlotterGraphics pg = new PlotterGraphics(_vr, _mapperImage.Graphics);
                    _mapper.Deselect(pg);
                    DisplayImage();

                    if (_plotter != null)
                    {
                        _plotter.PlotPoints(_mapper.Values(_vr));
                    }
                }
            }
        }
Exemplo n.º 14
0
        public void Draw(PlotterGraphics pg)
        {
            double x  = pg.VR.VXMin;
            double xd = pg.VR.VXSize / (double)pg.VR.CXSize;
            PointD p0 = null;

            while (x < pg.VR.VXMax)
            {
                PointD p1 = new PointD(x, f(x));
                if (p0 != null)
                {
                    pg.DrawLineV(p0, p1);
                }
                p0 = p1;
                x += xd;
            }
        }
Exemplo n.º 15
0
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (_band)
            {
                // clear previous band
                _bandImage.Clear();

                // draw new band
                _bandImage.Graphics.
                DrawRectangle(new Pen(Color.Black, 1.0f),
                              _mouseDownAt.X, _mouseDownAt.Y,
                              e.Location.X - _mouseDownAt.X, e.Location.Y - _mouseDownAt.Y);
                DisplayImage();
            }
            else
            {
                if (_mapper != null && _mapper.Selected)
                {
                    // clear previous mapper
                    _mapperImage.Clear();

                    // draw mapper in new position
                    PlotterGraphics pg     = new PlotterGraphics(_vr, _mapperImage.Graphics);
                    Point           offset = new Point(e.Location.X - _mouseMoveAt.X, e.Location.Y - _mouseMoveAt.Y);
                    _mapper.Move(pg, offset);
                    DisplayImage();
                    _mouseMoveAt = e.Location;

                    if (_plotter != null)
                    {
                        _plotter.PlotPoints(_mapper.Values(_vr));
                    }
                }
            }

            if (_plotter != null)
            {
                _plotter.AtPoint(_vr.CToV(e.Location));
            }
        }
Exemplo n.º 16
0
        public override void Move(PlotterGraphics pg, Point offset)
        {
            if (Selected)
            {
                switch (_mode)
                {
                case SelectMode.Line:
                    _p0 = new Point(_p0.X + offset.X, _p0.Y + offset.Y);
                    _p1 = new Point(_p1.X + offset.X, _p1.Y + offset.Y);
                    break;

                case SelectMode.P0:
                    _p0 = new Point(_p0.X + offset.X, _p0.Y + offset.Y);
                    break;

                case SelectMode.P1:
                    _p1 = new Point(_p1.X + offset.X, _p1.Y + offset.Y);
                    break;
                }
                Draw(pg);
            }
        }
Exemplo n.º 17
0
 public virtual void Draw(PlotterGraphics g)
 {
 }
Exemplo n.º 18
0
 public override void Select(PlotterGraphics pg)
 {
     Selected = true;
     Draw(pg);
 }
Exemplo n.º 19
0
 public override void Draw(PlotterGraphics pg)
 {
     pg.DrawCircleC(_c0, _r);
 }
Exemplo n.º 20
0
 public virtual void Move(PlotterGraphics pg, Point offset)
 {
 }
Exemplo n.º 21
0
        public void Draw(PlotterGraphics g)
        {
            SolidBrush   b          = new SolidBrush(Color.Black);
            FontFamily   fontFamily = new FontFamily("Lucida Console");
            Font         f          = new Font(fontFamily, _fontSize, FontStyle.Regular, GraphicsUnit.Point);
            StringFormat sf         = new StringFormat(StringFormatFlags.DirectionVertical);
            SizeF        st         = g.Graphics.MeasureString("0", f);

            // draw x axis
            int oy = g.VR.YVToC(YAxis.Origin);

            g.DrawLineC(g.VR.CXMin, oy, g.VR.CXMax, oy);

            // draw x axis ticks and values
            for (int i = 0; i < XAxis.NoOfTicks; i++)
            {
                double tv = XAxis.Tick(i);
                int    tc = g.VR.XVToC(tv);

                if (tv != XAxis.Origin)
                {
                    // tick mark
                    g.DrawLineC(tc, oy - _tickSize, tc, oy + _tickSize);

                    // value
                    string stv = tv.ToString();
                    if (stv.Length < 4)
                    {
                        // horizontal text
                        g.Graphics.DrawString(stv, f, b, new PointF(tc - (st.Width), oy + _tickSize));
                    }
                    else
                    {
                        // vertical
                        g.Graphics.DrawString(stv, f, b, new PointF(tc - _fontSize, oy + _tickSize), sf);
                    }
                }
            }

            // draw y axis
            int ox = g.VR.XVToC(XAxis.Origin);

            g.DrawLineC(ox, g.VR.CYMin, ox, g.VR.CYMax);

            // draw y axis ticks
            for (int i = 0; i < YAxis.NoOfTicks; i++)
            {
                double tv = YAxis.Tick(i);
                int    tc = g.VR.YVToC(tv);

                if (tv != YAxis.Origin)
                {
                    // tick mark
                    g.DrawLineC(ox - _tickSize, tc, ox + _tickSize, tc);

                    // value
                    g.Graphics.DrawString(tv.ToString(), f, b, new PointF(ox + _tickSize, tc - (st.Height / 4)));
                }
            }

            // origin circle
            if (XAxis.Origin == 0.0 && YAxis.Origin == 0.0)
            {
                g.DrawEllipseC(ox - _tickSize, oy - _tickSize, _tickSize * 2, _tickSize * 2);
            }
        }
Exemplo n.º 22
0
 public virtual bool CursorIsOn(PlotterGraphics pg, Point p, int tol)
 {
     return(false);
 }
Exemplo n.º 23
0
 public virtual void Select(PlotterGraphics pg)
 {
 }