/// <summary>
        /// Initializes this class. This must be called before calling Execute().
        /// </summary>
        public void Configure(EvaluationControlPointInput evalInput, Expression expression)
        {
            this.OutputIsValid = false;

            this.evalInput = evalInput;
            this.expression = expression;

            this.expression.EvaluateFunction += FunctionHandler;
            SetExpressionBaseParameters((EvaluationInput) evalInput);
        }
        /// <summary>
        /// Initializes this class. This must be called before calling Execute().
        /// </summary>
        public void Configure(EvaluationControlPointInput evalInput, Expression expression)
        {
            this.OutputIsValid = false;

            this.evalInput  = evalInput;
            this.expression = expression;

            this.expression.EvaluateFunction += FunctionHandler;
            SetExpressionBaseParameters((EvaluationInput)evalInput);
        }
        /// <summary>
        /// Calculates the X and Y coordinates of each control point and stores them in this.controlPointValues
        /// </summary>
        /// <param name="erroneousControlPointIndexSet">
        /// empty if all points had valid equations. Otherwise contains the index of at least one point with an invalid equation.
        /// </param>
        /// <returns>True on success, False if the control point equations could not be evaluated.</returns>
        protected ReturnStatus <List <XyPoint <double> > > CalculateControlPointValues(
            List <MssParamInfo> variableParamInfoList,
            List <MssParamInfo> transformParamInfoList,
            List <XyPoint <string> > pointEquations,
            ref HashSet <int> erroneousControlPointIndexSet)
        {
            Logger.HighVolume(26, string.Format("CalculateControlPointValues - pointEquations: {0}, transformParamInfoList: {1}",
                                                EnumerableUtils.ToString(pointEquations), EnumerableUtils.ToString(transformParamInfoList)));

            erroneousControlPointIndexSet.Clear();

            var controlPointList = new List <XyPoint <double> >();

            //Create the input for the control point jobs. The expression string will be
            //individually set for each equation.
            EvaluationControlPointInput pointEvalInput = new EvaluationControlPointInput();

            pointEvalInput.Init(variableParamInfoList,
                                transformParamInfoList,
                                "");

            //Create jobs to evaluate the x and y coordinates for a control point
            EvaluationControlPointJob pointXEvalJob = new EvaluationControlPointJob();
            EvaluationControlPointJob pointYEvalJob = new EvaluationControlPointJob();


            double previousPointXVal = 0;

            //Itterate through each control point equation and evaluate it's X and Y coordinates.
            for (int i = 0; i < pointEquations.Count; i++)
            {
                XyPoint <string> pointEquation = pointEquations[i];

                var xEquationStatus = CreateExpressionFromString(pointEquation.X, EvalType.ControlPoint);
                var yEquationStatus = CreateExpressionFromString(pointEquation.Y, EvalType.ControlPoint);

                if (!xEquationStatus.IsValid || !yEquationStatus.IsValid)
                {
                    Logger.HighVolume(27, string.Format("The x or y equation for control point {0} was not a valid equation. Equations: {1}",
                                                        i, pointEquation));
                    erroneousControlPointIndexSet.Add(i);
                    return(new ReturnStatus <List <XyPoint <double> > >(controlPointList, false));
                }

                //Evaluate the equation for the current control point's X value
                pointEvalInput.EquationStr = pointEquation.X;
                pointXEvalJob.Configure(pointEvalInput, xEquationStatus.Value);
                pointXEvalJob.Execute();

                //Evaluate the equation for the current control point's Y value
                pointEvalInput.EquationStr = pointEquation.Y;
                pointYEvalJob.Configure(pointEvalInput, yEquationStatus.Value);
                pointYEvalJob.Execute();

                //If one of the equations could not be evaluated return false
                if (pointXEvalJob.OutputIsValid == false || pointYEvalJob.OutputIsValid == false)
                {
                    Logger.HighVolume(28, string.Format("The x or y equation for control point {0} encountered an error while being evaluated. Equations: {1}",
                                                        i, pointEquation));

                    erroneousControlPointIndexSet.Add(i);
                    return(new ReturnStatus <List <XyPoint <double> > >(controlPointList, false));
                }

                //Store the current control point's X and Y coordinates in this.controlPointValues.
                XyPoint <double> curPoint = new XyPoint <double>(pointXEvalJob.OutputVal, pointYEvalJob.OutputVal);
                controlPointList.Add(curPoint);

                previousPointXVal = pointXEvalJob.OutputVal;
            }

            for (int i = 1; i < controlPointList.Count; i++)
            {
                //If the control points are not in order from smallest to largest then return an
                //invalid return status.
                if (controlPointList[i - 1].X > controlPointList[i].X)
                {
                    Logger.HighVolume(29, string.Format("The control points are not in order. X{0}: {1}, X{2}, {3}",
                                                        i - 1, controlPointList[i - 1].X, i, controlPointList[i].X));
                    erroneousControlPointIndexSet.Add(i);
                    erroneousControlPointIndexSet.Add(i - 1);
                    return(new ReturnStatus <List <XyPoint <double> > >(controlPointList, false));
                }
            }

            return(new ReturnStatus <List <XyPoint <double> > >(controlPointList, true));
        }
Example #4
0
        /// <summary>
        /// Calculates the X and Y coordinates of each control point and stores them in this.controlPointValues
        /// </summary>
        /// <param name="erroneousControlPointIndexSet">
        /// empty if all points had valid equations. Otherwise contains the index of at least one point with an invalid equation.
        /// </param>
        /// <returns>True on success, False if the control point equations could not be evaluated.</returns>
        protected ReturnStatus<List<XyPoint<double>>> CalculateControlPointValues(
            List<MssParamInfo> variableParamInfoList,
            List<MssParamInfo> transformParamInfoList,
            List<XyPoint<string>> pointEquations,
            ref HashSet<int> erroneousControlPointIndexSet)
        {
            Logger.HighVolume(26, string.Format("CalculateControlPointValues - pointEquations: {0}, transformParamInfoList: {1}",
                EnumerableUtils.ToString(pointEquations), EnumerableUtils.ToString(transformParamInfoList)));

            erroneousControlPointIndexSet.Clear();

            var controlPointList = new List<XyPoint<double>>();

            //Create the input for the control point jobs. The expression string will be
            //individually set for each equation.
            EvaluationControlPointInput pointEvalInput = new EvaluationControlPointInput();
            pointEvalInput.Init(variableParamInfoList,
                                transformParamInfoList,
                                "");

            //Create jobs to evaluate the x and y coordinates for a control point
            EvaluationControlPointJob pointXEvalJob = new EvaluationControlPointJob();
            EvaluationControlPointJob pointYEvalJob = new EvaluationControlPointJob();

            double previousPointXVal = 0;
            //Itterate through each control point equation and evaluate it's X and Y coordinates.
            for (int i = 0; i < pointEquations.Count; i++)
            {
                XyPoint<string> pointEquation = pointEquations[i];

                var xEquationStatus = CreateExpressionFromString(pointEquation.X, EvalType.ControlPoint);
                var yEquationStatus = CreateExpressionFromString(pointEquation.Y, EvalType.ControlPoint);

                if (!xEquationStatus.IsValid || !yEquationStatus.IsValid) {
                    Logger.HighVolume(27, string.Format("The x or y equation for control point {0} was not a valid equation. Equations: {1}",
                        i, pointEquation));
                    erroneousControlPointIndexSet.Add(i);
                    return new ReturnStatus<List<XyPoint<double>>>(controlPointList, false);
                }

                //Evaluate the equation for the current control point's X value
                pointEvalInput.EquationStr = pointEquation.X;
                pointXEvalJob.Configure(pointEvalInput, xEquationStatus.Value);
                pointXEvalJob.Execute();

                //Evaluate the equation for the current control point's Y value
                pointEvalInput.EquationStr = pointEquation.Y;
                pointYEvalJob.Configure(pointEvalInput, yEquationStatus.Value);
                pointYEvalJob.Execute();

                //If one of the equations could not be evaluated return false
                if (pointXEvalJob.OutputIsValid == false || pointYEvalJob.OutputIsValid == false)
                {
                    Logger.HighVolume(28, string.Format("The x or y equation for control point {0} encountered an error while being evaluated. Equations: {1}",
                       i, pointEquation));

                    erroneousControlPointIndexSet.Add(i);
                    return new ReturnStatus<List<XyPoint<double>>>(controlPointList, false);
                }

                //Store the current control point's X and Y coordinates in this.controlPointValues.
                XyPoint<double> curPoint = new XyPoint<double>(pointXEvalJob.OutputVal, pointYEvalJob.OutputVal);
                controlPointList.Add(curPoint);

                previousPointXVal = pointXEvalJob.OutputVal;
            }

            for (int i = 1; i < controlPointList.Count; i++)
            {
                //If the control points are not in order from smallest to largest then return an
                //invalid return status.
                if (controlPointList[i - 1].X > controlPointList[i].X)
                {
                    Logger.HighVolume(29, string.Format("The control points are not in order. X{0}: {1}, X{2}, {3}",
                        i - 1, controlPointList[i - 1].X, i, controlPointList[i].X));
                    erroneousControlPointIndexSet.Add(i);
                    erroneousControlPointIndexSet.Add(i - 1);
                    return new ReturnStatus<List<XyPoint<double>>>(controlPointList, false);
                }
            }

            return new ReturnStatus<List<XyPoint<double>>>(controlPointList, true);
        }