Ejemplo n.º 1
0
        /// <summary>
        /// Calculates the cache bitmap to draw the function.
        /// </summary>
        public override void Calc(CalcThread t)
        {
            int X, Y;

            if (Recalc)
            {
                Color  c;
                double dzinv = 1 / t.dz;
                for (Y = 0; Y < t.h; Y++)
                {
                    if (t.stop)
                    {
                        break;
                    }
                    for (X = 0; X < t.w; X++)
                    {
                        if (t.stop)
                        {
                            break;
                        }
                        try {
                            c = f(t.Graph.Model.x0 + X * t.dx, t.Graph.Model.y0 + Y * t.dy);
                        } catch (ThreadAbortException ex) { throw ex; } catch { c = Color.White; }
                        lock (this) {
                            cache.SetPixel(X, t.h - Y - 1, c);
                        }
                    }
                    t.OnStep();
                }
                Recalc = t.stop;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a deep copy of the CalcThread.
        /// </summary>
        public CalcThread Clone(GraphControl graph)
        {
            CalcThread t = new CalcThread(graph);

            t.CopyFrom(this);
            return(t);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Caluclates the items <see cref="cache">cache</see> field to draw the function.
        /// </summary>
        public override void Calc(CalcThread t)
        {
            const float BIG = 1e20F;
            int         X;
            float       F;

            if (Recalc)
            {
                for (X = 0; X < t.w; X++)
                {
                    if (t.stop)
                    {
                        break;
                    }
                    lock (this) {
                        try {
                            cache[X].X = X;
                            F          = (float)(t.h - 1 - (f(t.Graph.Model.x0 + X * t.dx) - t.Graph.Model.y0) / t.dy);
                            if (float.IsInfinity(F) || float.IsNaN(F) || Math.Abs(F) > BIG)
                            {
                                F = 0;
                            }
                            cache[X].Y = F;
                        } catch (ThreadAbortException ex) { throw ex; } catch { cache[X].Y = 0; }
                    }
                    t.OnStep();
                }
                Recalc = t.stop;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Copies from another GraphControl.
 /// </summary>
 /// <param name="graph">The control to copy from.</param>
 public void CopyFrom(GraphControl graph)
 {
     sx         = graph.sx; sy = graph.sy; sw = graph.sw; sh = graph.sh; zoomIn = graph.zoomIn;
     fx         = graph.fx; fy = graph.fy; fw = graph.fw; fh = graph.fh; fd = graph.fd;
     Model      = (GraphModel)graph.Model.Clone();
     Calc       = (CalcThread)graph.Calc.Clone(this);
     Calc.Step += new CalcStepEventHandler(CalcStep);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Draws the DataItem from the previously calculated cache.
 /// </summary>
 /// <param name="g">The Graphics object to draw to.</param>
 /// <param name="t">The calculating thread.</param>
 public override void Draw(Graphics g, CalcThread t)
 {
     lock (this) {
         if (cache != null)
         {
             g.DrawImage(cache, 0, 0, t.w, t.h);
         }
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Draws the function.
 /// </summary>
 public override void Draw(Graphics g, CalcThread t)
 {
     t.pen.Color     = color;
     t.pen.DashStyle = lineStyle;
     t.pen.Width     = lineWidth;
     lock (this) {
         try {
             g.DrawLines(t.pen, cache);
         } catch {}
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// The constructor of the control.
 /// </summary>
 public GraphControl()
 {
     Model              = new GraphModel();
     Model.Invalidated += new GraphModel.InvalidateEventHandler(ModelInvalidated);
     this.Cursor        = Cursors.Cross;
     this.BackColor     = Color.White;
     sx         = sy = -1; sw = sh = 0;
     zoomIn     = false;
     zscale.img = null;
     Calc       = new CalcThread(this);
     Calc.Step += new CalcStepEventHandler(CalcStep);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initiates the calculation of the function cache bitmap.
 /// </summary>
 public override void StartCalc(CalcThread t)
 {
     if (Modified)
     {
         Modified = false; Recalc = true;
         lock (this) {
             cache = new Bitmap(t.w, t.h, PixelFormat.Format32bppArgb);
             Graphics g = Graphics.FromImage(cache);
             g.Clear(Color.White);
         }
         t.maxprogress += t.h;
     }
 }
Ejemplo n.º 9
0
 private void CalcStep(CalcThread t)
 {
     if (Bar != null)
     {
         Bar.Value = t.progress;
     }
     t.nt++;
     if (t.nt >= 20)
     {
         Model.Invalidate();
         t.nt = 0;
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Initiates the background calculation of the <see cref="cache">cache</see> field.
 /// </summary>
 public override void StartCalc(CalcThread t)
 {
     if (Modified)
     {
         Modified = false; Recalc = true;
         lock (this) {
             cache = new PointF[t.w];
             for (int x = 0; x < t.w; x++)
             {
                 cache[x].X = x; cache[x].Y = t.h + 10;
             }
         }
         t.maxprogress += t.w;
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Calculates the cache bitmap to draw the function.
        /// </summary>
        public override void Calc(CalcThread t)
        {
            int    X, Y;
            double fx, dzinv;
            Color  c;

            if (Recalc)
            {
                dzinv = 1 / t.dz;
                for (Y = 0; Y < t.h; Y++)
                {
                    if (t.stop)
                    {
                        break;
                    }
                    for (X = 0; X < t.w; X++)
                    {
                        if (t.stop)
                        {
                            break;
                        }
                        try {
                            fx = (f(t.Graph.Model.x0 + X * t.dx, t.Graph.Model.y0 + Y * t.dy) - t.Graph.Model.z0) * dzinv;
                        } catch (ThreadAbortException ex) { throw ex; } catch { fx = 0; }
                        if (rgb)
                        {
                            c = RGBColor(fx);
                        }
                        else
                        {
                            c = FColor(fx);
                        }
                        lock (this) {
                            cache.SetPixel(X, t.h - Y - 1, c);
                        }
                    }
                    t.OnStep();
                }
                Recalc = t.stop;
            }
        }
Ejemplo n.º 12
0
		/// <summary>
		/// Draws the function.
		/// </summary>
		public override void Draw(Graphics g, CalcThread t) {
			t.pen.Color = color;
			t.pen.DashStyle = lineStyle;
			t.pen.Width = lineWidth;
			lock(this) {
				try {
					g.DrawLines(t.pen, cache);
				} catch {}
			}
		}
Ejemplo n.º 13
0
		/// <summary>
		/// Initiates the background calculation of the <see cref="cache">cache</see> field.
		/// </summary>
		public override void StartCalc(CalcThread t) {
			if (Modified) {
				Modified = false; Recalc = true;
				lock(this) {
					cache = new PointF[t.w];
					for (int x = 0; x < t.w; x++) {
						cache[x].X = x; cache[x].Y = t.h+10;
					}
				}
				t.maxprogress += t.w;
			}
		}
Ejemplo n.º 14
0
		/// <summary>
		/// Caluclates the items <see cref="cache">cache</see> field to draw the function.
		/// </summary>
		public override void Calc(CalcThread t) {
			const float BIG = 1e20F;
			int X;
			float F;
			if (Recalc) {
				for (X = 0; X < t.w; X++) {
					if (t.stop) break;
					lock(this) {
						try {
							cache[X].X = X;
							F = (float)(t.h - 1 - (f(t.Graph.Model.x0 + X*t.dx) - t.Graph.Model.y0)/t.dy);
							if (float.IsInfinity(F) || float.IsNaN(F) || Math.Abs(F) > BIG) F = 0;
							cache[X].Y = F;
						} catch (ThreadAbortException ex) { throw ex;
						} catch { cache[X].Y = 0; }
					}
					t.OnStep();
				}
				Recalc = t.stop;
			}
		}
Ejemplo n.º 15
0
		/// <summary>
		/// Draws the <c>PlotItem</c>.
		/// </summary>
		/// <param name="g">A graphics object that is used for drawing.</param>
		/// <param name="t">The <see cref="CalcThread">CalcThread</see> that calculated the items data.</param>
		public virtual void Draw(Graphics g, CalcThread t) {}
Ejemplo n.º 16
0
		/// <summary>
		/// Used internally. Called to initialize the process of calculating the items data.
		/// </summary>
		public virtual void StartCalc(CalcThread t) {Modified = false; Recalc = false;}
Ejemplo n.º 17
0
 /// <summary>
 /// Used internally. Called to initialize the process of calculating the items data.
 /// </summary>
 public virtual void StartCalc(CalcThread t)
 {
     Modified = false; Recalc = false;
 }
Ejemplo n.º 18
0
		/// <summary>
		/// Calculates the image-cache for the data in the background.
		/// </summary>
		/// <param name="t">The calculating thread.</param>
		public override void Calc(CalcThread t) {
			t.pen.Color = color;
			PointF[] points = new PointF[Length];
			Graphics g;
			lock (this) {
				g = Graphics.FromImage(cache);
			}
			float X, Y, DX, DY;
			for (int i = 0; i < Length; i++) {
				if (t.stop) break;
				try {
					X = (float)((x[i] - t.Graph.Model.x0)/t.dx);
					Y = t.h - 1 - (float)((y[i] - t.Graph.Model.y0)/t.dy);
					DX = (float)(dx[i]/t.dx)/2;
					DY = (float)(dy[i]/t.dy)/2;
					points[i].X = X; points[i].Y = Y;
					if (marks) {
						lock (this) {
							t.pen.DashStyle = DashStyle.Solid;
							t.pen.Width = lineWidth;
							if (DX < 3) DX = 5;
							else {
								g.DrawLine(t.pen, X-DX, Y-3, X-DX, Y+3);
								g.DrawLine(t.pen, X+DX, Y-3, X+DX, Y+3);
							}
							if (DY < 3) DY = 5;
							else {
								g.DrawLine(t.pen, X-3, Y-DY, X+3, Y-DY);
								g.DrawLine(t.pen, X-3, Y+DY, X+3, Y+DY);
							}
							g.DrawLine(t.pen, X-DX, Y, X+DX, Y);
							g.DrawLine(t.pen, X, Y-DY, X, Y+DY);
						}
					}
				} catch (System.Threading.ThreadAbortException ex) {
					throw ex;
				} catch {}
				t.OnStep();
			}
			if (lines && !t.stop) {
				t.pen.DashStyle = lineStyle;
				t.pen.Width = lineWidth;
				try {
					lock (this) {
						g.DrawLines(t.pen, points);
					}
				} catch (System.Threading.ThreadAbortException ex) {
					throw ex;
				} catch {}
			}
			Recalc = t.stop;
		}
Ejemplo n.º 19
0
 /// <summary>
 /// Copies from another CalcThread using a deep copy.
 /// </summary>
 public void CopyFrom(CalcThread t)
 {
     w = t.w; h = t.h; dx = t.dx; dy = t.dy; dz = t.dz;
     //Step = t.Step;
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Draws the <c>PlotItem</c>.
 /// </summary>
 /// <param name="g">A graphics object that is used for drawing.</param>
 /// <param name="t">The <see cref="CalcThread">CalcThread</see> that calculated the items data.</param>
 public virtual void Draw(Graphics g, CalcThread t)
 {
 }
Ejemplo n.º 21
0
		/// <summary>
		/// Calculates the cache bitmap to draw the function.
		/// </summary>
		public override void Calc(CalcThread t) {
			int X, Y;
			double fx, dzinv;
			Color c;
			if (Recalc) {
				dzinv = 1/t.dz;
				for (Y = 0; Y < t.h; Y++) {
					if (t.stop) break;
					for (X = 0; X < t.w; X++) {
						if (t.stop) break;
						try {
							fx = (f(t.Graph.Model.x0 + X*t.dx, t.Graph.Model.y0 + Y*t.dy) - t.Graph.Model.z0)*dzinv;
						} catch (ThreadAbortException ex) { throw ex;
						} catch { fx = 0; }
						if (rgb) c = RGBColor(fx);
						else c = FColor(fx);
						lock(this) {
							cache.SetPixel(X, t.h - Y - 1, c);
						}
					}						
					t.OnStep();
				}
				Recalc = t.stop;
			}
		}
Ejemplo n.º 22
0
		/// <summary>
		/// Copies from another CalcThread using a deep copy.
		/// </summary>
		public void CopyFrom(CalcThread t) {
			w = t.w; h = t.h; dx = t.dx; dy = t.dy; dz = t.dz;
			//Step = t.Step;		
		}
Ejemplo n.º 23
0
        /// <summary>
        /// Calculates the image-cache for the data in the background.
        /// </summary>
        /// <param name="t">The calculating thread.</param>
        public override void Calc(CalcThread t)
        {
            t.pen.Color = color;
            PointF[] points = new PointF[Length];
            Graphics g;

            lock (this) {
                g = Graphics.FromImage(cache);
            }
            float X, Y, DX, DY;

            for (int i = 0; i < Length; i++)
            {
                if (t.stop)
                {
                    break;
                }
                try {
                    X           = (float)((x[i] - t.Graph.Model.x0) / t.dx);
                    Y           = t.h - 1 - (float)((y[i] - t.Graph.Model.y0) / t.dy);
                    DX          = (float)(dx[i] / t.dx) / 2;
                    DY          = (float)(dy[i] / t.dy) / 2;
                    points[i].X = X; points[i].Y = Y;
                    if (marks)
                    {
                        lock (this) {
                            t.pen.DashStyle = DashStyle.Solid;
                            t.pen.Width     = lineWidth;
                            if (DX < 3)
                            {
                                DX = 5;
                            }
                            else
                            {
                                g.DrawLine(t.pen, X - DX, Y - 3, X - DX, Y + 3);
                                g.DrawLine(t.pen, X + DX, Y - 3, X + DX, Y + 3);
                            }
                            if (DY < 3)
                            {
                                DY = 5;
                            }
                            else
                            {
                                g.DrawLine(t.pen, X - 3, Y - DY, X + 3, Y - DY);
                                g.DrawLine(t.pen, X - 3, Y + DY, X + 3, Y + DY);
                            }
                            g.DrawLine(t.pen, X - DX, Y, X + DX, Y);
                            g.DrawLine(t.pen, X, Y - DY, X, Y + DY);
                        }
                    }
                } catch (System.Threading.ThreadAbortException ex) {
                    throw ex;
                } catch {}
                t.OnStep();
            }
            if (lines && !t.stop)
            {
                t.pen.DashStyle = lineStyle;
                t.pen.Width     = lineWidth;
                try {
                    lock (this) {
                        g.DrawLines(t.pen, points);
                    }
                } catch (System.Threading.ThreadAbortException ex) {
                    throw ex;
                } catch {}
            }
            Recalc = t.stop;
        }
Ejemplo n.º 24
0
		/// <summary>
		/// Used internally. Called by the calculation thread. Calculates the items data in the background. 
		/// </summary>
		/// <param name="t"></param>
		public virtual void Calc(CalcThread t) {Recalc = false;}
Ejemplo n.º 25
0
 /// <summary>
 /// Used internally. Called by the calculation thread. Calculates the items data in the background.
 /// </summary>
 /// <param name="t"></param>
 public virtual void Calc(CalcThread t)
 {
     Recalc = false;
 }
Ejemplo n.º 26
0
		/// <summary>
		/// Draws the DataItem from the previously calculated cache.
		/// </summary>
		/// <param name="g">The Graphics object to draw to.</param>
		/// <param name="t">The calculating thread.</param>
		public override void Draw(Graphics g, CalcThread t) {
			lock (this) {
				if (cache != null) {
					g.DrawImage(cache, 0, 0, t.w, t.h);
				}
			}
		}
Ejemplo n.º 27
0
		/// <summary>
		/// Calculates the cache bitmap to draw the function.
		/// </summary>
		public override void Calc(CalcThread t) {
			int X, Y;
			if (Recalc) {
				Color c;
				double dzinv = 1/t.dz;
				for (Y = 0; Y < t.h; Y++) {
					if (t.stop) break;
					for (X = 0; X < t.w; X++) {
						if (t.stop) break;
						try {
							c = f(t.Graph.Model.x0 + X*t.dx, t.Graph.Model.y0 + Y*t.dy);
						} catch (ThreadAbortException ex) { throw ex;
						} catch { c = Color.White; }
						lock(this) {
							cache.SetPixel(X, t.h - Y - 1, c);
						}
					}
					t.OnStep();
				}
				Recalc = t.stop;
			}
		}
Ejemplo n.º 28
0
		/// <summary>
		/// Initiates calculation of the DataItem.
		/// </summary>
		public override void StartCalc(CalcThread t) {
			if (Modified) {
				Modified = false; Recalc = true;
				lock(this) {
					cache = new Bitmap(t.w, t.h, PixelFormat.Format32bppArgb);
					Graphics g = Graphics.FromImage(cache);
					g.Clear(Color.FromArgb(0, Color.White));
				}
				t.maxprogress += Length/1000;
			}
		}
Ejemplo n.º 29
0
		/// <summary>
		/// Creates a deep copy of the CalcThread.
		/// </summary>
		public CalcThread Clone(GraphControl graph) {
			CalcThread t = new CalcThread(graph);
			t.CopyFrom(this);
			return t;
		}