/// <summary>
        /// Check if menu entry for curve is selectable
        /// </summary>
        /// <param name="curve">Enumeration for curve</param>
        /// <returns>
        ///     <br>True: if curve menu entry is selectable</br>
        ///     <br>False: if curve menu entry is not selectable</br>
        /// </returns>
        private bool CheckCurve(CurveType curve)
        {
            switch (curve)
            {
                #region Editable Map

            case CurveType.EditableMap:
            {
                Button button = new Elements().EntryEditableMAP;
                if (button.Enabled)
                {
                    Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "CurveType [" + curve + "] could be selected.");
                    button.MoveTo();
                    return(true);
                }

                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Menu entry is not accessible.");
                return(false);
            }

                #endregion

                #region Envelope Curve

            case CurveType.EnvelopeCurve:
            {
                Button button = new Elements().EntryEnvelopeCurve;
                if (button.Enabled)
                {
                    Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "CurveType [" + curve + "] could be selected.");
                    button.MoveTo();
                    return(true);
                }

                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Menu entry is not accessible.");
                return(false);
            }

                #endregion

                #region First Echo Curve

            case CurveType.FirstEchoCurve:
            {
                Button button = new Elements().EntryFirstEchoCurve;
                if (button.Enabled)
                {
                    Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "CurveType [" + curve + "] could be selected.");
                    button.MoveTo();
                    return(true);
                }

                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Menu entry is not accessible.");
                return(false);
            }

                #endregion

                #region Free

            case CurveType.Free:
            {
                Button button = new Elements().EntryFree;
                if (button.Enabled)
                {
                    Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "CurveType [" + curve + "] could be selected.");
                    button.MoveTo();
                    return(true);
                }

                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Menu entry is not accessible.");
                return(false);
            }

                #endregion

                #region Ideal Echo Curve

            case CurveType.IdealEchoCurve:
            {
                Button button = new Elements().EntryIdealEcho;
                if (button.Enabled)
                {
                    Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "CurveType [" + curve + "] could be selected.");
                    button.MoveTo();
                    return(true);
                }

                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Menu entry is not accessible.");
                return(false);
            }

                #endregion

                #region Ideal Echo from File

            case CurveType.IdealEchoFromFile:
            {
                Button button = new Elements().EntryIdealEchoFromFile;
                if (button.Enabled)
                {
                    Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "CurveType [" + curve + "] could be selected.");
                    button.MoveTo();
                    return(true);
                }

                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Menu entry is not accessible.");
                return(false);
            }

                #endregion

                #region Map

            case CurveType.Map:
            {
                Button button = new Elements().EntryMAP;
                if (button.Enabled)
                {
                    Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "CurveType [" + curve + "] could be selected.");
                    button.MoveTo();
                    return(true);
                }

                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Menu entry is not accessible.");
                return(false);
            }

                #endregion

                #region Raw Envelope Curve

            case CurveType.RawEnvelopeCurve:
            {
                Button button = new Elements().EntryRawEnvelopeCurve;
                if (button.Enabled)
                {
                    Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "CurveType [" + curve + "] could be selected.");
                    button.MoveTo();
                    return(true);
                }

                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Menu entry is not accessible.");
                return(false);
            }

                #endregion

                #region Reference Curve

            case CurveType.ReferenceCurve:
            {
                Button button = new Elements().EntryReferenceCurve;
                if (button.Enabled)
                {
                    Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "CurveType [" + curve + "] could be selected.");
                    button.MoveTo();
                    return(true);
                }

                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Menu entry is not accessible.");
                return(false);
            }

                #endregion

                #region Threshold GPC

            case CurveType.ThresholdGpc:
            {
                Button button = new Elements().EntryThresholdGasPhaseCompensation;
                if (button.Enabled)
                {
                    Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "CurveType [" + curve + "] could be selected.");
                    button.MoveTo();
                    return(true);
                }

                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Menu entry is not accessible.");
                return(false);
            }

                #endregion

                #region Threshold Tank Bottom

            case CurveType.ThresholdTankBottom:
            {
                Button button = new Elements().EntryThresholdTankBottom;
                if (button.Enabled)
                {
                    Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "CurveType [" + curve + "] could be selected.");
                    button.MoveTo();
                    return(true);
                }

                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Menu entry is not accessible.");
                return(false);
            }

                #endregion

                #region Weighting Curve

            case CurveType.WeightingCurve:
            {
                Button button = new Elements().EntryWeightingCurve;
                if (button.Enabled)
                {
                    Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "CurveType [" + curve.ToString() + "] could be selected.");
                    button.MoveTo();
                    return(true);
                }

                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Menu entry is not accessible.");
                return(false);
            }

                #endregion

            default:
            {
                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Menu entry does not exist");
                return(false);
            }
            }
        }
Beispiel #2
0
        public static void AddKey(this AnimationCurve curve, Keyframe keyframe, TimelineKey lastKey)
        {
            var keys = curve.keys;

            //Early out - if this is the first key on this curve just add it
            if (keys.Length == 0)
            {
                curve.AddKey(keyframe);
                return;
            }

            if (lastKey == null)
            {
                Debug.Log(string.Format("ERROR: NULL lastkey passed to AddKey when curve contains {0} keys", keys.Length));
                return;
            }

            //Get the last keyframe
            Keyframe lastKeyframe = keys[keys.Length - 1];

            //If no TimelineKey is supplied, default to Linear curve
            CurveType curveType = lastKey.CurveType;

            switch (curveType)
            {
            case CurveType.Instant:
                lastKeyframe.outTangent = 0;
                curve.MoveKey(keys.Length - 1, lastKeyframe);

                keyframe.inTangent = float.PositiveInfinity;
                curve.AddKey(keyframe);
                break;

            case CurveType.Linear:
                var val = (keyframe.value - lastKeyframe.value) / (keyframe.time - lastKeyframe.time);
                lastKeyframe.outTangent = val;
                curve.MoveKey(keys.Length - 1, lastKeyframe);

                keyframe.inTangent = val;
                curve.AddKey(keyframe);
                break;

            case CurveType.Quadratic:
            {
                //Increase to cubic
                var c1 = (2 * lastKey.CurveParams[0]) / 3;
                var c2 = 1 - (2 * lastKey.CurveParams[0] + 1) / 3;

                //Convert [0,1] into unity-acceptable tangents
                c1 *= 3 * (keyframe.value - lastKeyframe.value) / (keyframe.time - lastKeyframe.time);
                c2 *= 3 * (keyframe.value - lastKeyframe.value) / (keyframe.time - lastKeyframe.time);

                //Set the out tangent for the previous frame and update
                lastKeyframe.outTangent = c1;
                curve.MoveKey(keys.Length - 1, lastKeyframe);

                //Set the in tangent for the current frame and add
                keyframe.inTangent = c2;
                curve.AddKey(keyframe);
                break;
            }

            case CurveType.Cubic:
            {
                //Get curve parameters
                var c1 = lastKey.CurveParams[0];
                var c2 = 1 - lastKey.CurveParams[1];

                //Convert [0,1] into unity-acceptable tangents
                c1 *= 3 * (keyframe.value - lastKeyframe.value) / (keyframe.time - lastKeyframe.time);
                c2 *= 3 * (keyframe.value - lastKeyframe.value) / (keyframe.time - lastKeyframe.time);

                //Set the out tangent for the previous frame and update
                lastKeyframe.outTangent = c1;
                curve.MoveKey(keys.Length - 1, lastKeyframe);

                //Set the in tangent for the current frame and add
                keyframe.inTangent = c2;
                curve.AddKey(keyframe);
                break;
            }

            default:
                Debug.LogWarning("CurveType " + curveType.ToString() + " not yet supported!");
                break;
            }
        }
Beispiel #3
0
        private void Run(string[] args)
        {
            string versionFile = @"d:\numbers\philip\pv.txt";
            int    version     =
                int
                .Parse
                    (File
                    .ReadAllText
                        (versionFile
                        )
                    )
            ;
            string    map          = args[0];
            int       imageWidth   = int.Parse(args[1]);
            int       imageHeight  = int.Parse(args[2]);
            float     unitWidth    = float.Parse(args[3]);
            float     unitHeight   = float.Parse(args[4]);
            float     lineWidth    = float.Parse(args[5]);
            float     borderPixels = float.Parse(args[6]);
            int       level        = 5;
            float     levelEmSize  = 18.5F;
            CurveType curveType    = CurveType.ZigZag;
            CorImage  image        = new CorImage(imageWidth, imageHeight, Color.White);
            SizeF     sizeF        = image.MeasureString(level.ToString(), "arial", levelEmSize);

            image
            .DrawString
                (level.ToString()
                , "arial"
                , levelEmSize
                , Color.Black
                , imageWidth / 2 - sizeF.Width / 2
                , imageHeight / 2 - sizeF.Height / 2
                )
            ;
            List <NavUnit> navUnits      = new List <NavUnit>(level);
            PhilipFractal  philipFractal = new PhilipFractal();

            map = philipFractal.Map(level);
            ConDeb.Print(map.ToUpper());
            navUnits
            .Drive
                (map
                , Direction.West
                , 0
                , 0
                , unitWidth
                , unitHeight
                )
            ;
            List <Color>         colors = SetupColors();
            ColorGradientFactory cgf    =
                new ColorGradientFactory
                    (colors.ToArray()
                    )
            ;

            navUnits.CentreGraph(imageWidth, imageHeight, borderPixels);
            navUnits.FitGraph(imageWidth, imageHeight, 10);
            navUnits.Draw(image, lineWidth, curveType, cgf);
            //image.DrawString("Hello", "Arial", 100.5F, Color.Black, 0, 0);
            image.Save(@"d:\numbers\philip\newphilip" + curveType.ToString() + level.ToString() + version.ToString() + ".gif", ImageFormat.Gif);
            image.Dispose();
            version++;
            File.WriteAllText(versionFile, version.ToString());
        }
Beispiel #4
0
        public string GetDescription()
        {
            string    desc      = "";
            CurveData cdDefault = new CurveData();

            // name mandatory
            if (String.IsNullOrEmpty(name_))
            {
                return("");
            }
            desc += "[" + name_ + "]" + Environment.NewLine;

            desc += "type=" + curveType_.ToString().ToLower() + Environment.NewLine;

            // equations
            switch (curveType_)
            {
            case CurveType.PARAMETRIC:
                desc += "x(t)=" + equation1_ + Environment.NewLine;
                desc += "y(t)=" + equation2_ + Environment.NewLine;
                break;

            case CurveType.POLAR:
                desc += "r(t)=" + equation1_ + Environment.NewLine;
                break;

            case CurveType.CARTESIAN:
                desc += "y(x)=" + equation1_ + Environment.NewLine;
                break;

            case CurveType.EQUALITY:
                desc += "0=" + equation1_ + Environment.NewLine;
                break;

            case CurveType.INEQUALITY:
                desc += "0<" + equation1_ + Environment.NewLine;
                break;
            }

            // write parameters values if different from default values

            CultureInfo culture = new CultureInfo("en-US");

            if (!Isometric)
            {
                desc += "isometric=" + Isometric.ToString(culture) + Environment.NewLine;
            }

            // if isometric, do not save x min and max
            if (!Isometric)
            {
                if (XVmin != cdDefault.XVmin)
                {
                    desc += "xv_min=" + XVmin.ToString(culture) + Environment.NewLine;
                }
                if (XVmax != cdDefault.XVmax)
                {
                    desc += "xv_max=" + XVmax.ToString(culture) + Environment.NewLine;
                }
            }

            if (YVmin != cdDefault.YVmin)
            {
                desc += "yv_min=" + YVmin.ToString(culture) + Environment.NewLine;
            }
            if (YVmax != cdDefault.YVmax)
            {
                desc += "yv_max=" + YVmax.ToString(culture) + Environment.NewLine;
            }

            switch (curveType_)
            {
            case CurveType.PARAMETRIC:
            case CurveType.POLAR:
                if (Pmin != cdDefault.Pmin)
                {
                    desc += "t_min=" + Pmin.ToString(culture) + Environment.NewLine;
                }
                if (Pmax != cdDefault.Pmax)
                {
                    desc += "t_max=" + Pmax.ToString(culture) + Environment.NewLine;
                }
                if (Pstep != cdDefault.Pstep)
                {
                    desc += "t_step=" + Pstep.ToString(culture) + Environment.NewLine;
                }
                break;

            case CurveType.CARTESIAN:
            case CurveType.EQUALITY:
            case CurveType.INEQUALITY:
                if (Pmin != cdDefault.Pmin)
                {
                    desc += "x_min=" + Pmin.ToString(culture) + Environment.NewLine;
                }
                if (Pmax != cdDefault.Pmax)
                {
                    desc += "x_max=" + Pmax.ToString(culture) + Environment.NewLine;
                }
                if (Pstep != cdDefault.Pstep)
                {
                    desc += "x_step=" + Pstep.ToString(culture) + Environment.NewLine;
                }
                break;
            }

            if (Thickness != cdDefault.Thickness)
            {
                desc += "thickness=" + Thickness + Environment.NewLine;
            }

            desc += Environment.NewLine;

            return(desc);
        }