コード例 #1
0
ファイル: GraphModel.cs プロジェクト: xuchuansheng/GenXSource
		/// <summary>
		/// Returns a deep copy.
		/// </summary>
		/// <param name="model">The model the copy belongs to.</param>
		public ItemList Clone(GraphModel model) {
			ItemList l = new ItemList(model);
			for (int i = 0; i < Count; i++) {
				l.Add(this[i].Clone());
			}
			return l;
		}
コード例 #2
0
ファイル: Functions.cs プロジェクト: xuchuansheng/GenXSource
		/// <summary>
		/// A constructor that sets the model.
		/// </summary>
		public SourceLibrary(GraphModel m): base(m) {}
コード例 #3
0
 /// <summary>
 /// This method is called when printing starts. It creates a local copy of the
 /// <see cref="GraphModel">GraphModel</see> from the graph that was passed to the constructor.
 /// </summary>
 protected override void OnBeginPrint(PrintEventArgs e)
 {
     base.OnBeginPrint(e);
     model = (GraphModel)graph.Model.Clone();
 }
コード例 #4
0
		/// <summary>
		/// This method is called when printing starts. It creates a local copy of the
		/// <see cref="GraphModel">GraphModel</see> from the graph that was passed to the constructor. 
		/// </summary>
		protected override void OnBeginPrint(PrintEventArgs e) {
			base.OnBeginPrint (e);
			model = (GraphModel)graph.Model.Clone();
		}
コード例 #5
0
ファイル: GraphModel.cs プロジェクト: xuchuansheng/GenXSource
		/// <summary>
		/// Constructor setting the parent model for the ItemList.
		/// </summary>
		/// <param name="model"></param>
		public ItemList(GraphModel model) {
			this.model = model;
		}
コード例 #6
0
ファイル: GraphControl.cs プロジェクト: carlhuth/GenXSource
        /// <summary>
        /// Calculates the bounds of the plotting area inside the control.
        /// </summary>
        /// <param name="g">A Graphics object.</param>
        /// <param name="bounds">The bounds of the entire control.</param>
        private void CalcFrame(Graphics g, Rectangle bounds)
        {
            int    w = 0, h = 0, ww, wz = 0, n, W, H;
            double y0 = Model.y0, y1 = Model.y1, x0 = Model.x0, x1 = Model.x1, z0 = Model.z0, z1 = Model.z1,
                   rx = Model.rx, ry = Model.ry, rz = Model.rz,
                   dy = (y1 - y0) / bounds.Height, dz = (z1 - z0) / bounds.Height, x, y, z;
            SizeF  size;
            string label;
            float  Y, Z;

            y    = 0.5;
            size = g.MeasureString(y.ToString(GraphModel.NumberFormat(Model.xDigits, Model.xNumberStyle)),
                                   Model.ScaleFont);
            fd = (int)(size.Height + 0.5F);

            if (Model.Border)
            {
                if (Model.yScale)
                {
                    y = Math.Floor(y0 / ry) * ry;
                    n = 1;
                    while ((y + n * ry) < y1)
                    {
                        Y = bounds.Height - 1 - (float)((y + n * ry - y0) / dy);
                        if ((int)(bounds.Height - 1 - (float)(-y0 / dy) + 0.5F) == (int)(Y + 0.5F))
                        {
                            label = "0";
                        }
                        else
                        {
                            label = (y + n * ry).ToString(GraphModel.NumberFormat(Model.yDigits, Model.yNumberStyle));
                        }
                        size = g.MeasureString(label, Model.ScaleFont);
                        w    = Math.Max(w, (int)(size.Width + 0.5));
                        n++;
                    }
                }
                else
                {
                    w = 0;
                }

                if (Model.xScale)
                {
                    h     = fd;
                    x     = Math.Floor(x1 / rx) * rx;
                    label = x.ToString(GraphModel.NumberFormat(Model.xDigits, Model.xNumberStyle));
                    size  = g.MeasureString(label, Model.ScaleFont);
                    ww    = (int)(size.Width / 2 + 1);
                }
                else
                {
                    ww = 0;
                }

                if (Model.zScale)
                {
                    Function2D f = null;
                    for (int i = 0; i < Model.Items.Count; i++)
                    {
                        if (Model.Items[i] is Function2D)
                        {
                            f = (Function2D)Model.Items[i];
                        }
                    }
                    if (f != null)
                    {
                        z = Math.Floor(z0 / rz) * rz;
                        n = 1;
                        while ((z + n * rz) < z1)
                        {
                            Z = bounds.Height - 1 - (float)((z + n * rz - z0) / dz);
                            if ((int)(bounds.Height - 1 - (float)(-z0 / dz) + 0.5F) == (int)(Z + 0.5F))
                            {
                                label = "0";
                            }
                            else
                            {
                                label = (z + n * rz).ToString(GraphModel.NumberFormat(Model.zDigits, Model.zNumberStyle));
                            }
                            size = g.MeasureString(label, Model.ScaleFont);
                            wz   = Math.Max(wz, (int)(size.Width + 0.5));
                            n++;
                        }
                        wz += 3 * fd + D;
                    }
                    else
                    {
                        wz = 0;
                    }
                }
                else
                {
                    wz = 0;
                }

                fx = w + D;
                fy = D / 2 + fd / 2;
                W  = bounds.Width - w - (3 * D) / 2 - ww - wz;
                H  = bounds.Height - h - fd / 2 - (3 * D) / 2;
                if (W != fw && FixYtoX)
                {
                    fw = W; fh = H;
                    Model.SetRange(x0, x1, y0, y1, fw, fh);
                }
                fw = W; fh = H;
            }
            else
            {
                fx = bounds.X; fy = bounds.Y; fw = bounds.Width - 1; fh = bounds.Height - 2;
            }
        }
コード例 #7
0
ファイル: Functions.cs プロジェクト: xuchuansheng/GenXSource
		/// <summary>
		/// A constructor that sets the model of the function.
		/// </summary>
		/// <param name="m"></param>
		public FunctionColor(GraphModel m): base(m) {
			source = "return Color.White";
		}
コード例 #8
0
ファイル: Functions.cs プロジェクト: xuchuansheng/GenXSource
		/// <summary>
		/// The constructor of a function item that sets the items model.
		/// </summary>
		public FunctionItem(GraphModel m): base(m) {}
コード例 #9
0
 /// <summary>
 /// A constructor that sets the model of the function.
 /// </summary>
 /// <param name="m"></param>
 public FunctionColor(GraphModel m) : base(m)
 {
     source = "return Color.White";
 }
コード例 #10
0
 /// <summary>
 /// Constructor setting the parent model for the ItemList.
 /// </summary>
 /// <param name="model"></param>
 public ItemList(GraphModel model)
 {
     this.model = model;
 }
コード例 #11
0
ファイル: GraphModel.cs プロジェクト: xuchuansheng/GenXSource
		/// <summary>
		/// Returns a format string used by the ToString method.
		/// </summary>
		/// <param name="digits">The number of digits to display.</param>
		/// <param name="style">The number-style</param>
		/// <returns>A format string</returns>
		public static string NumberFormat(int digits, GraphModel.NumberStyle style) {
			switch (style) {
			case GraphModel.NumberStyle.Normal:
				return "G"+digits.ToString();
			case GraphModel.NumberStyle.Fixedpoint:
				return "F"+digits.ToString();
			case GraphModel.NumberStyle.Scientific:
				return "E"+digits.ToString();
			default:
				return "G3";
			}
		}
コード例 #12
0
ファイル: GraphModel.cs プロジェクト: xuchuansheng/GenXSource
		/// <summary>
		/// Creates a deep copy.
		/// </summary>
		public object Clone() {
			GraphModel m = new GraphModel();
			m.CopyFrom(this);
			return m;
		} 
コード例 #13
0
ファイル: GraphModel.cs プロジェクト: xuchuansheng/GenXSource
		/// <summary>
		/// Copies from another model with a deep copy.
		/// </summary>
		/// <param name="m">The model to copy from.</param>
		public void CopyFrom(GraphModel m)
		{
			X0 = m.X0;	X1 = m.X1; Y0 = m.Y0; Y1 = m.Y1; Z0 = m.Z0; Z1 = m.Z1;
			rx = m.rx; ry = m.ry; rz = m.rz;

			xAxis = m.xAxis; yAxis = m.yAxis; xRaster = m.xRaster; yRaster = m.yRaster;
			xGrid = m.xGrid; yGrid = m.yGrid;
			xScale = m.xScale; yScale = m.yScale; zScale = m.zScale;
			Border = m.Border; FixYtoX = m.FixYtoX; Legend = m.Legend; LegendBorder = m.LegendBorder;

			xDigits = m.xDigits; yDigits = m.yDigits; zDigits = m.zDigits;
			xNumberStyle = m.xNumberStyle; yNumberStyle = m.yNumberStyle; zNumberStyle = m.zNumberStyle;
			ScaleFont = m.ScaleFont;
			ScaleColor = m.ScaleColor;
			Filename = (string)m.Filename.Clone();

			Items = m.Items.Clone(this);
			Library = (SourceLibrary)m.Library.Clone();
			CompilerImports = (string[])m.CompilerImports.Clone();

			//Deep Copy of CompilerOptions
			CompilerOptions.Clear();
			IEnumerator keys, values;
			keys = m.CompilerOptions.Keys.GetEnumerator();
			values = m.CompilerOptions.Values.GetEnumerator();
			keys.Reset(); values.Reset();
			for (int i = 0; i < m.CompilerOptions.Count; i++) {
				keys.MoveNext(); values.MoveNext();
				CompilerOptions.Add(keys.Current, values.Current);
			}
			Modified = true;
		}
コード例 #14
0
ファイル: Functions.cs プロジェクト: xuchuansheng/GenXSource
		/// <summary>
		/// Initializes a <c>PlotItem</c> and sets the <c>GraphModel</c> the item belongs to.
		/// </summary>
		public PlotItem(GraphModel m) {
			model = m;
		}
コード例 #15
0
 /// <summary>
 /// A constructor that sets the model.
 /// </summary>
 public SourceLibrary(GraphModel m) : base(m)
 {
 }
コード例 #16
0
ファイル: Functions.cs プロジェクト: xuchuansheng/GenXSource
		/// <summary>
		/// Copies from another PlotItem with a deep copy.
		/// </summary>
		public virtual void CopyFrom(PlotItem item) {
			model = item.model;
			name = (string)item.name.Clone();
			color = item.color;
			lineStyle = item.lineStyle;
			lineWidth = item.lineWidth;
			recalc = item.recalc;
			code = item.code;
			errors = (string[])errors.Clone();
		}
コード例 #17
0
 /// <summary>
 /// Initializes a <c>PlotItem</c> and sets the <c>GraphModel</c> the item belongs to.
 /// </summary>
 public PlotItem(GraphModel m)
 {
     model = m;
 }
コード例 #18
0
ファイル: Functions.cs プロジェクト: xuchuansheng/GenXSource
		/// <summary>
		/// A constructor setting the model of the item.
		/// </summary>
		public Function2D(GraphModel m): base(m) {}
コード例 #19
0
 /// <summary>
 /// The constructor of a function item that sets the items model.
 /// </summary>
 public FunctionItem(GraphModel m) : base(m)
 {
 }
コード例 #20
0
ファイル: GraphControl.cs プロジェクト: carlhuth/GenXSource
 /// <summary>
 /// The default callback for a <c>Model.Invalidated</c> event.
 /// </summary>
 /// <param name="model">The <see cref="GraphModel">GraphModel</see> that was invalidated.</param>
 public void ModelInvalidated(GraphModel model)
 {
     Invalidate();
 }
コード例 #21
0
 /// <summary>
 /// A constructor that sets the items model.
 /// </summary>
 public Function1D(GraphModel m) : base(m)
 {
 }
コード例 #22
0
ファイル: GraphControl.cs プロジェクト: carlhuth/GenXSource
        /// <summary>
        /// Paints the control.
        /// </summary>
        /// <param name="g">The Graphics object to paint to.</param>
        public void PaintGraph(Graphics g)
        {
            double    x, y, z;
            float     X, Y, Z, d;
            int       n;
            Rectangle frame, bounds = this.Bounds;
            SizeF     size;
            Region    clip, frameclip, boundsclip;

            double x0 = Model.x0, y0 = Model.y0, z0 = Model.z0, x1 = Model.x1, y1 = Model.y1, z1 = Model.z1,
                   rx = Model.rx, ry = Model.ry, rz = Model.rz, srx = rx / 5, sry = ry / 5, srz = rz / 5;

            CalcFrame(g, bounds);
            g.TranslateTransform(fx, fy, MatrixOrder.Append);
            frame      = new Rectangle(0, 0, fw + 1, fh + 1);
            bounds     = new Rectangle(-fx, -fy, bounds.Width, bounds.Height);
            clip       = g.Clip.Clone();
            frameclip  = clip.Clone();
            boundsclip = clip.Clone();
            frameclip.Intersect(frame);
            boundsclip.Intersect(bounds);

            double dx = (x1 - x0) / fw;
            double dy = (y1 - y0) / fh;
            double dz = (z1 - z0) / fh;

            pen.DashStyle = DashStyle.Solid;
            pen.Width     = 1;

            g.SetClip(frameclip, CombineMode.Replace);

            //calculate functions
            Calc.Start(frame);

            if (!AsyncDraw)
            {
                while (!Calc.done)
                {
                }
            }

            //draw items
            for (int i = 0; i < Model.Items.Count; i++)
            {
                Model.Items[i].Draw(g, Calc);
            }

            // draw selection
            if (sw != 0 && sh != 0)
            {
                pen.Color = Color.White;
                g.DrawRectangle(pen, Math.Min(sx - fx, sx + sw - fx), Math.Min(sy - fy, sy + sh - fy),
                                Math.Abs(sw), Math.Abs(sh));
                pen.DashPattern = new float[2] {
                    3, 3
                };
                pen.DashStyle = DashStyle.Custom;
                pen.Color     = Color.Black;
                g.DrawRectangle(pen, Math.Min(sx - fx, sx + sw - fx), Math.Min(sy - fy, sy + sh - fy),
                                Math.Abs(sw), Math.Abs(sh));
                pen.DashStyle = DashStyle.Solid;
            }

            // draw raster
            pen.Color   = Model.ScaleColor;
            pen.Width   = Model.ScaleLineWidth;
            brush.Color = Model.ScaleColor;
            g.DrawRectangle(pen, 0, 0, fw, fh);
            string label;

            x = Math.Floor(x0 / rx) * rx + rx;
            n = -4;
            while (x + srx * n < x1)
            {
                X = (float)((x + srx * n - x0) / dx);
                if (Model.xGrid && n % 5 == 0 && !((int)(-x0 / dx + 0.5) == (int)(X + 0.5F) && Model.yAxis))
                {
                    pen.Color = Color.FromArgb(64, Model.ScaleColor);
                    g.DrawLine(pen, X, 0, X, fh);
                    pen.Color = Model.ScaleColor;
                }
                if (Model.xRaster && !((int)(-x0 / dx + 0.5) == (int)(X + 0.5F) && Model.yAxis))
                {
                    if (n % 5 == 0)
                    {
                        d = fd;
                    }
                    else
                    {
                        d = fd / 2;
                    }
                    g.DrawLine(pen, X, 0, X, d);
                    g.DrawLine(pen, X, fh - d, X, fh);
                }

                if (Model.xScale && (n % 5 == 0))
                {
                    if ((int)(-x0 / dx + 0.5) == (int)(X + 0.5F))
                    {
                        label = "0";
                    }
                    else
                    {
                        label = (x + srx * n).ToString(GraphModel.NumberFormat(Model.xDigits, Model.xNumberStyle));
                    }
                    size = g.MeasureString(label, Model.ScaleFont);
                    g.SetClip(boundsclip, CombineMode.Replace);
                    if (Model.Border)
                    {
                        g.DrawString(label, Model.ScaleFont, brush, new PointF(X - size.Width / 2, fh + D / 2));
                    }
                    else
                    {
                        g.DrawString(label, Model.ScaleFont, brush, new PointF(X - size.Width / 2, fh - 2 * fd - D / 2));
                    }
                    g.SetClip(frameclip, CombineMode.Replace);
                }
                if (yAxis && (int)(-x0 / dx + 0.5) == (int)(X + 0.5F))
                {
                    g.DrawLine(pen, X, 0, X, fh);
                }
                n++;
            }

            y = Math.Floor(y0 / ry) * ry + ry;
            n = -4;
            while (y + sry * n < y1)
            {
                Y = fh - 1 - (float)((y + sry * n - y0) / dy);
                if (Model.yGrid && n % 5 == 0 && !((int)(fh - 1 - (float)(-y0 / dy) + 0.5F) == (int)(Y + 0.5F) && xAxis))
                {
                    pen.Color = Color.FromArgb(64, Model.ScaleColor);
                    g.DrawLine(pen, 0, Y, fw, Y);
                    pen.Color = Model.ScaleColor;
                }
                if (Model.yRaster && !((int)(fh - 1 - (float)(-y0 / dy) + 0.5F) == (int)(Y + 0.5F) && xAxis))
                {
                    if (n % 5 == 0)
                    {
                        d = fd;
                    }
                    else
                    {
                        d = fd / 2;
                    }
                    g.DrawLine(pen, 0, Y, d, Y);
                    g.DrawLine(pen, fw - d, Y, fw, Y);
                }
                if (Model.yScale && (n % 5 == 0))
                {
                    if ((int)(fh - 1 - (float)(-y0 / dy) + 0.5F) == (int)(Y + 0.5F))
                    {
                        label = "0";
                    }
                    else
                    {
                        label = (y + sry * n).ToString(GraphModel.NumberFormat(Model.yDigits, Model.yNumberStyle));
                    }
                    size = g.MeasureString(label, Model.ScaleFont);
                    g.SetClip(boundsclip, CombineMode.Replace);
                    if (Model.Border)
                    {
                        g.DrawString(label, Model.ScaleFont, brush, new PointF(-size.Width - D / 2, Y - fd / 2));
                    }
                    else
                    {
                        g.DrawString(label, Model.ScaleFont, brush, new PointF(D / 2 + fd, Y - fd / 2));
                    }
                    g.SetClip(frameclip, CombineMode.Replace);
                }
                if (xAxis && (int)(fh - 1 - (float)(-y0 / dy) + 0.5F) == (int)(Y + 0.5F))
                {
                    g.DrawLine(pen, 0, Y, fw, Y);
                }
                n++;
            }

            //draw z-Scale
            if (Model.zScale && GetZBitmap())
            {
                g.SetClip(boundsclip, CombineMode.Replace);
                g.DrawImage(zscale.img, fw + fd, 0, fd, fh);
                g.DrawRectangle(pen, fw + fd, 0, fd, fh);

                z = Math.Floor(z0 / rz) * rz + rz;

                n = -4;
                while (z + srz * n < z1)
                {
                    Z = fh - 1 - (float)((z + srz * n - z0) / dz);
                    if (n % 5 == 0)
                    {
                        d = fd;
                    }
                    else
                    {
                        d = fd / 2;
                    }
                    g.DrawLine(pen, fw + 2 * fd, Z, fw + 2 * fd + d, Z);
                    if (n % 5 == 0)
                    {
                        if ((int)(fh - 1 - (float)(-z0 / dz) + 0.5F) == (int)(Z + 0.5F))
                        {
                            label = "0";
                        }
                        else
                        {
                            label = (z + srz * n).ToString(GraphModel.NumberFormat(Model.zDigits, Model.zNumberStyle));
                        }
                        //size = g.MeasureString(label, Model.ScaleFont);
                        g.DrawString(label, Model.ScaleFont, brush, new PointF(fw + D / 2 + 3 * fd, Z - fd / 2));
                    }
                    n++;
                }
            }

            //draw legend
            if (Model.Legend)
            {
                float lw = 0;
                int   m  = 0;
                pen.Color = Model.ScaleColor;
                for (n = 0; n < Model.Items.Count; n++)
                {
                    if (Model.Items[n] is Function1D ||
                        (Model.Items[n] is DataItem && ((DataItem)Model.Items[n]).lines))
                    {
                        m++;
                        size = g.MeasureString(Model.Items[n].name, Model.ScaleFont);
                        lw   = Math.Max(lw, size.Width);
                    }
                }
                int w = (int)(lw + 0.5) + (7 * fd) / 2, h = fd * m + D;

                if (Model.LegendBorder)
                {
                    brush.Color = Color.White;
                    g.FillRectangle(brush, fw - 2 * fd - w, fy + 2 * fd, w, h);
                    g.DrawRectangle(pen, fw - 2 * fd - w, fy + 2 * fd, w, h);
                }

                m = 0;
                for (n = 0; n < Model.Items.Count; n++)
                {
                    if (Model.Items[n] is Function1D ||
                        (Model.Items[n] is DataItem && ((DataItem)Model.Items[n]).lines))
                    {
                        brush.Color = Model.ScaleColor;
                        g.DrawString(Model.Items[n].name, Model.ScaleFont, brush, fw + fd - w, fy + 2 * fd + D / 2 + m * fd);
                        pen.DashStyle = Model.Items[n].lineStyle;
                        pen.Width     = Model.Items[n].lineWidth;
                        g.DrawLine(pen, fw - w - (3 * fd) / 2, fy + 3 * fd + D / 2 + m * fd - fd / 2,
                                   fw - w + fd / 2, fy + 3 * fd + D / 2 + m * fd - fd / 2);
                        m++;
                    }
                }
            }

            //draw status message
            if (!Calc.done)
            {
                brush.Color = Color.Red;
                g.DrawString("calculating...", Model.ScaleFont, brush, bounds.Width / 2, bounds.Height / 2);
            }
            else
            {
                if (Bar != null)
                {
                    lock (Bar) { Bar.Value = 0; }
                }
            }

            //reset Graphics
            g.ResetTransform();
            g.SetClip(clip, CombineMode.Replace);
        }
コード例 #23
0
ファイル: ImageForm.cs プロジェクト: xuchuansheng/GenXSource
		public void CopyNotify(GraphModel model) {
			lock(copy) {
				g = Graphics.FromImage(bitmap);
				g.Clear(Color.White);
				g.SmoothingMode = SmoothingMode.AntiAlias;
				copy.PaintGraph(g);
				picture.Image = bitmap;
			}
		}