Click here to Skip to main content
11,629,614 members (71,411 online)
Click here to Skip to main content
Add your own
alternative version

Equation Calculator with Graphing

, 25 Nov 2010 CPOL 70.4K 3K 152
Equation Calculator with Graphing
JespersCalculator03.2.zip
CommonUtils
bin
Debug
CommonUtils.dll
Color
Equation
GraphicalCanvas
Properties
Settings.settings
Themes
Calculator
Calculator
bin
Debug
Calculator.exe
Calculator.vshost.exe
Calculator.vshost.exe.manifest
CommonUtils.dll
Graphing
Properties
Settings.settings
Calculator.suo
JespersCalculator03_toremov.zip
CommonUtils.dll
Settings.settings
Calculator.exe
Calculator.vshost.exe
Calculator.vshost.exe.manifest
CommonUtils.dll
Settings.settings
Calculator.suo
JespersCalculator3.3.zip
Calculator.application
Calculator.exe
Calculator.exe.manifest
Calculator.vshost.application
Calculator.vshost.exe
Calculator.vshost.exe.manifest
CommonUtils.dll
Calculator.csproj.user
Calculator.csproj.vspscc
MSSCCPRJ.SCC
Settings.settings
Calculator.suo
Calculator.vssscc
MSSCCPRJ.SCC
CommonUtils.dll
CommonUtils.csproj.vspscc
MSSCCPRJ.SCC
Settings.settings
JespersCalculator3.4.zip
Release
CommonUtils.csproj.vspscc
MSSCCPRJ.SCC
Settings.settings
Calculator.application
Calculator.exe
Calculator.exe.manifest
Calculator.vshost.application
Calculator.vshost.exe
Calculator.vshost.exe.manifest
CommonUtils.dll
Calculator.csproj.user
Calculator.csproj.vspscc
MSSCCPRJ.SCC
Settings.settings
Calculator.suo
Calculator.vssscc
MSSCCPRJ.SCC
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Xml;
using CommonUtils;
using System.ComponentModel;
using System.Windows.Media;
using System.Windows;
using System.Windows.Controls;

namespace Calculator
{
	public class GraphItem : CommonUtils.IXmlSerialize, INotifyPropertyChanged
	{
		bool m_isEnabled = false;
		string m_equation = string.Empty;
		Brush m_color;
		public bool IsSelected {get; set;}
		public bool IsEnabled
		{
			get { return m_isEnabled; }
			set
			{
				if (m_isEnabled != value)
				{
					m_isEnabled = value;
					NotifyChange("IsEnabled");
				}
			}
		}
		public string Equation
		{
			get { return m_equation;}
			set
			{
				m_equation = value;
				NotifyChange("Equation");
			}
		}
		public string Vars {get; set;}
		public Brush GraphColor 
		{
			get { return m_color; }
			set
			{
				m_color = value;
				NotifyChange("GraphColor");
			}
		}

		public GraphItem()
		{
			GraphColor = Brushes.Beige;
		}
		public GraphItem(XmlElement node)
		{
			Read(node);
		}
		public void Read(XmlElement node)
		{
			try
			{
				if (node != null && node.Name == "graphitem")
				{
					IsEnabled = node.GetBool("enable", true);
					Equation = node.GetString("eq", string.Empty);
					Vars = node.GetString("vars", string.Empty);
					GraphColor = node.GetBrush("color", Brushes.Blue);
				}
			}
			catch { }
		}
		public void Write(XmlTextWriter wr)
		{
			wr.WriteStartElement("graphitem");
			wr.WriteAttribute("enable", IsEnabled);
			wr.WriteAttribute("eq", Equation);
			wr.WriteAttribute("vars", Vars);
			wr.WriteAttribute("color", GraphColor);
			wr.WriteEndElement();
		}

		#region INotifyPropertyChanged Members
		void NotifyChange(string property)
		{
			if (PropertyChanged != null)
				PropertyChanged(this, new PropertyChangedEventArgs(property));
		}
		public event PropertyChangedEventHandler PropertyChanged;

		#endregion
	}

	public class NewGraphItem : GraphItem
	{
	}

	public class GraphItemCollection : ObservableCollection<GraphItem>, CommonUtils.IXmlSerialize
	{
		public const string xmlTag = "graphitems";
		public new void Add(GraphItem item)
		{
			RemoveNewItem();
			base.Add(item);
			AddNewItem();
		}
		public void Read(XmlElement node)
		{
			try
			{
				if (node != null && node.Name == xmlTag)
				{
					Clear();
					foreach (XmlNode child in node.ChildNodes)
					{
						XmlElement element = child as XmlElement;
						if (element == null)
							continue;
						base.Add(new GraphItem(element));
					}
					AddNewItem();
				}
			}
			catch { }
		}
		public void Write(XmlTextWriter wr)
		{
			wr.WriteStartElement("graphitems");
			foreach(IXmlSerialize item in this)
			{
				if (item is NewGraphItem)
					continue;
				item.Write(wr);
			}
			wr.WriteEndElement();
		}
		void RemoveNewItem()
		{
			for (int index = Count - 1; index >= 0; index--)
			{
				if (this[index] is NewGraphItem)
					RemoveAt(index);
			}
		}
		void AddNewItem()
		{
			base.Add(new NewGraphItem());
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

jkristia
Software Developer (Senior)
United States United States
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150723.1 | Last Updated 25 Nov 2010
Article Copyright 2010 by jkristia
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid