Esempio n. 1
0
        public static bool Evaluate(Equation equation, Sail sail, out double result, bool showBox)
        {
            if (equation == null)
            {
                result = 0;
                return false;
            }

            bool worked = false;

            Expression ex = new Expression(equation.EquationText, EvaluateOptions.IgnoreCase);

            List<Equation> avails = sail.WatermarkEqs(equation);
            avails.ForEach(eq => ex.Parameters[eq.Label] = eq.Result);
            //Set up a custom delegate so NCalc will ask you for a parameter's value
            //   when it first comes across a variable

            ex.EvaluateFunction += delegate(string FunctionName, FunctionArgs args)
            {
                args.Result = EvaluateToDouble(args.Parameters[0].ParsedExpression.ToString(), FunctionName.ToLower(), sail);
            };

            try
            {
                result = Convert.ToDouble(ex.Evaluate());
                equation.SetResult(result);
                worked = true;
            }
            catch (Exception exx)
            {
                worked = double.TryParse(equation.EquationText, out result);
                equation.SetResult(result);
                Warps.Logger.logger.Instance.LogErrorException(exx);
            }
            finally
            {
                if (!worked)
                {
                    if (showBox)
                        System.Windows.Forms.MessageBox.Show("Error parsing equation");
                    result = double.NaN;
                }
            }

            return worked;
        }
Esempio n. 2
0
 void m_eqEditor_OnVariableDeleted(object sender, Equation DeleteMe)
 {
     //throw new NotImplementedException();
 }
Esempio n. 3
0
 void m_eqEditor_OnVariableAdded(object sender, Equation addedEq)
 {
     m_frame.Rebuild(m_group);
     m_edit.Equations = m_group.ToArray();
 }
Esempio n. 4
0
 internal void HighlightEquation(Equation equation)
 {
     if (m_edit != null)
         m_edit.HighlightEquation(equation);
 }
Esempio n. 5
0
        //public void OnCopy(object sender, EventArgs e)
        //{
        //IGroup group = Tree.SelectedTag as IGroup;
        //if (group == null)
        //    return;
        ////Lets say its my data format
        //Clipboard.Clear();
        ////Set data to clipboard
        //Clipboard.SetData(group.GetType().Name, Utilities.Serialize(group.WriteScript()));
        ////Get data from clipboard
        //m_frame.Status = String.Format("{0}:{1} Copied", group.GetType().Name, group.Label);
        //}
        public void OnPaste(object sender, EventArgs e)
        {
            //Equations should be able to be pasted into this group

            if (Utilities.GetClipboardObjType() != typeof(Equation))
                return;

            Type type = Utilities.GetClipboardObjType();
            if (type == null)
                return;

            List<string> result = (List<string>)Utilities.DeSerialize(Clipboard.GetData(type.Name).ToString());

            ScriptTools.ModifyScriptToShowCopied(ref result);

            VariableGroup group = (VariableGroup)Tree.SelectedTag;

            if (group == null)
                return;

            Equation eq = new Equation();
            //eq.sail = group.Sail;
            eq.ReadScript(group.Sail, result);
            //eq.Evaluate();
            group.Add(eq);
            m_frame.Rebuild(m_group);
        }
Esempio n. 6
0
 public FixedPoint(Equation ueq, Equation veq)
 {
     U = ueq;
     V = veq;
 }
Esempio n. 7
0
 public FixedPoint(double s, double u, double v)
 {
     m_s = s;
     U = new Equation("u", u.ToString());
     V = new Equation("v", v.ToString());
 }
Esempio n. 8
0
        public bool ReadScript(Sail sail, IList<string> txt)
        {
            if (txt.Count != 3)
                return false;

            txt[1] = txt[1].Trim('\t');
            txt[2] = txt[2].Trim('\t');
            string[] split = txt[1].Split(new char[] { ':' });
            U = new Equation(split[0],split[1]);
            split = txt[2].Split(new char[] { ':' });
            V = new Equation(split[0], split[1]);
            return Update(sail);
        }
Esempio n. 9
0
 public VariableTracker(Equation equ)
 {
     m_equ = equ;
 }
Esempio n. 10
0
 public static bool Evaluate(Equation labelToEvaluate, Sail sail, out double result)
 {
     return Evaluate(labelToEvaluate, sail, out result, false);
 }
Esempio n. 11
0
        public static List<string> ListParameters(Equation Equ)
        {
            List<string> param = new List<string>();
            Expression ex = new Expression(Equ.EquationText);

            ex.EvaluateFunction += delegate(string name, FunctionArgs args)
            {
                if (name == "Length")
                    param.Add(args.Parameters[0].ToString());
                args.Result = 1;
            };

            ex.EvaluateParameter += delegate(string name, ParameterArgs args)
            {
                param.Add(name);
                args.Result = 1;
            };
            if (ex.HasErrors())
                MessageBox.Show(ex.Error);
            ex.Evaluate();
            return param;
        }
Esempio n. 12
0
 public CurvePoint(double s, MouldCurve curve, Equation Sequ)
 {
     m_sPos = s;
     S_Equ = Sequ;
     m_curve = curve;
 }
Esempio n. 13
0
 public CurvePoint(double s, MouldCurve curve, double sCurve)
 {
     m_sPos = s;
     S_Equ = new Equation("s", sCurve.ToString());
     m_curve = curve;
 }
Esempio n. 14
0
        public bool ReadScript(Sail sail, IList<string> txt)
        {
            if (txt.Count != 3)
                return false;
            //[1] = "\t\tCurve: Luff"
            m_curve = sail.FindCurve(txt[1].Split(new char[]{':'})[1].Trim());
            txt[2] = txt[2].Trim('\t');

            string[] split = txt[2].Split(new char[] { ':' });

            S_Equ = new Equation(split[0], split[1]);

            return Update(sail);

            #region Old
            //string line;
            //double d;
            //foreach (string s in txt)
            //{
            //	line = s.TrimStart('\t');
            //	if (line.StartsWith("S-Cur: "))
            //	{
            //		if (double.TryParse(line.Substring(7), out d))
            //			m_sCurve = d;
            //	}
            //	else if (line.StartsWith("Curve: "))
            //	{
            //		string curlbl = line.Substring(7).Trim();
            //		m_curve = sail.FindCurve(curlbl);
            //	}

            //}

            //return true;
            #endregion
        }