Ejemplo n.º 1
0
 public SimpleSteps()
 {
     _ratchet           = new Ratchet();
     _logProxy          = MockRepository.GenerateMock <ILogProxy>();
     _ratchet.MyLogger  = _logProxy;
     _ratchet.InputType = "direct";
 }
Ejemplo n.º 2
0
        public static ProcessResultArray <Clip> ProcessCommand(Command command, Clip[] incomingClips, ClipMetaData targetMetadata)
        {
            var clips = new Clip[incomingClips.Length];

            for (var i = 0; i < incomingClips.Length; i++)
            {
                clips[i] = new Clip(incomingClips[i]);
            }

            return(command.Id switch
            {
                TokenType.Arpeggiate => Arpeggiate.Apply(command, clips),
                TokenType.Concat => Concat.Apply(clips),
                TokenType.Crop => Crop.Apply(command, clips),
                TokenType.Filter => Filter.Apply(command, clips),
                TokenType.Interleave => Interleave.Apply(command, targetMetadata, clips),
                TokenType.Legato => Legato.Apply(clips),
                TokenType.Mask => Mask.Apply(command, clips),
                TokenType.Monophonize => Monophonize.Apply(clips),
                TokenType.Padding => Padding.Apply(command, clips),
                TokenType.Quantize => Quantize.Apply(command, clips),
                TokenType.Ratchet => Ratchet.Apply(command, clips),
                TokenType.Relength => Relength.Apply(command, clips),
                TokenType.Remap => Remap.Apply(command, clips),
                TokenType.Resize => Resize.Apply(command, clips),
                TokenType.Scale => Scale.Apply(command, clips),
                TokenType.Scan => Scan.Apply(command, clips),
                TokenType.SetLength => SetLength.Apply(command, clips),
                TokenType.SetPitch => SetPitch.Apply(command, clips),
                TokenType.SetRhythm => SetRhythm.Apply(command, clips),
                TokenType.Shuffle => Shuffle.Apply(command, clips),
                TokenType.Skip => Skip.Apply(command, clips),
                TokenType.Slice => Slice.Apply(command, clips),
                TokenType.Take => Take.Apply(command, clips),
                TokenType.Transpose => Transpose.Apply(command, clips),
                TokenType.VelocityScale => VelocityScale.Apply(command, clips),
                TokenType.InterleaveEvent => ((Func <ProcessResultArray <Clip> >)(() =>
                {
                    var(success, msg) = OptionParser.TryParseOptions(command, out InterleaveOptions options);
                    if (!success)
                    {
                        return new ProcessResultArray <Clip>(msg);
                    }

                    options.Mode = InterleaveMode.Event;
                    return Interleave.Apply(options, targetMetadata, clips);
                }))(),
                _ => new ProcessResultArray <Clip>($"Unsupported command {command.Id}")
            });
Ejemplo n.º 3
0
        public async Task Foo()
        {
            var browser = new Ratchet <WebApplication.Startup>();

            await browser.OpenUrl("/home/About");

            var Document = await browser.WaitDocumentLoad();

            var t = Document.TextContent;
            var c = browser.WaitNextConsoleLog();

            browser.ExecuteJavaScript("console.log('Hello World');");

            TestContext.WriteLine("con: " + await c);

            // TestContext Output : Hello World
        }
Ejemplo n.º 4
0
    public static ProcessResult <Clip[]> ProcessCommand(Command command, Clip[] incomingClips, ClipMetaData targetMetadata)
    {
        var clips = new Clip[incomingClips.Length];

        for (var i = 0; i < incomingClips.Length; i++)
        {
            clips[i] = new Clip(incomingClips[i]);
        }

        return(command.Id switch
        {
            TokenType.Arpeggiate => Arpeggiate.Apply(command, clips),
            TokenType.Concat => Concat.Apply(clips),
            TokenType.Crop => Crop.Apply(command, clips),
            TokenType.Echo => Echo.Apply(command, clips),
            TokenType.Extract => Take.Apply(command, clips, true),
            TokenType.Filter => Filter.Apply(command, clips),
            TokenType.Invert => Invert.Apply(command, clips),
            TokenType.Interleave => Interleave.Apply(command, targetMetadata, clips, InterleaveMode.NotSpecified),
            TokenType.InterleaveEvent => Interleave.Apply(command, targetMetadata, clips, InterleaveMode.Event),
            TokenType.Legato => Legato.Apply(clips),
            TokenType.Loop => Loop.Apply(command, clips),
            TokenType.Mask => Mask.Apply(command, clips),
            TokenType.Monophonize => Monophonize.Apply(clips),
            TokenType.Padding => Padding.Apply(command, clips),
            TokenType.Quantize => Quantize.Apply(command, clips),
            TokenType.Ratchet => Ratchet.Apply(command, clips),
            TokenType.Relength => Relength.Apply(command, clips),
            TokenType.Remap => Remap.Apply(command, clips),
            TokenType.Resize => Resize.Apply(command, clips),
            TokenType.Scale => Scale.Apply(command, clips),
            TokenType.Scan => Scan.Apply(command, clips),
            TokenType.SetLength => SetLength.Apply(command, clips),
            TokenType.SetPitch => SetPitch.Apply(command, clips),
            TokenType.SetRhythm => SetRhythm.Apply(command, clips),
            TokenType.Shuffle => Shuffle.Apply(command, clips),
            TokenType.Skip => Skip.Apply(command, clips),
            TokenType.Slice => Slice.Apply(command, clips),
            TokenType.Take => Take.Apply(command, clips),
            TokenType.Transpose => Transpose.Apply(command, clips),
            TokenType.VelocityScale => VelocityScale.Apply(command, clips),
            _ => new ProcessResult <Clip[]>($"Unsupported command {command.Id}")
        });
Ejemplo n.º 5
0
        public GearProfiles CalcRatchetImage(RatchetParams gParams)
        {
            if (gParams == null)
            {
                throw new ArgumentNullException(nameof(gParams));
            }

            Ratchet gear = new Ratchet(
                gParams.Teeth,
                double.Parse(gParams.Module),
                double.Parse(gParams.Tolerance),
                double.Parse(gParams.InnerDiameter),
                double.Parse(gParams.CutterDiameter));

            Cutouts cutoutCalculator = new Cutouts(
                gear,
                double.Parse(gParams.SpindleDiameter),
                double.Parse(gParams.InlayDiameter),
                double.Parse(gParams.KeyFlatWidth));

            return(CreateGearPlot(cutoutCalculator, gear.PitchCircleDiameter));
        }
Ejemplo n.º 6
0
 public virtual void SetUp()
 {
     _ratchet = new Ratchet();
 }
Ejemplo n.º 7
0
        public static ProcessResultArray <Clip> ProcessCommand(Command command, Clip[] incomingClips, ClipMetaData targetMetadata)
        {
            var clips = new Clip[incomingClips.Length];

            for (var i = 0; i < incomingClips.Length; i++)
            {
                clips[i] = new Clip(incomingClips[i]);
            }

            ProcessResultArray <Clip> resultContainer;

            switch (command.Id)
            {
            case TokenType.Arpeggiate:
                resultContainer = Arpeggiate.Apply(command, clips);
                break;

            case TokenType.Concat:
                resultContainer = Concat.Apply(clips);
                break;

            case TokenType.Crop:
                resultContainer = Crop.Apply(command, clips);
                break;

            case TokenType.Filter:
                resultContainer = Filter.Apply(command, clips);
                break;

            case TokenType.Interleave:
                resultContainer = Interleave.Apply(command, targetMetadata, clips);
                break;

            case TokenType.InterleaveEvent:
                var(success, msg) = OptionParser.TryParseOptions(command, out InterleaveOptions options);
                if (!success)
                {
                    return(new ProcessResultArray <Clip>(msg));
                }
                options.Mode    = InterleaveMode.Event;
                resultContainer = Interleave.Apply(options, targetMetadata, clips);
                break;

            case TokenType.Legato:
                resultContainer = Legato.Apply(clips);
                break;

            case TokenType.Mask:
                resultContainer = Mask.Apply(command, clips);
                break;

            case TokenType.Monophonize:
                resultContainer = Monophonize.Apply(clips);
                break;

            case TokenType.Quantize:
                resultContainer = Quantize.Apply(command, clips);
                break;

            case TokenType.Ratchet:
                resultContainer = Ratchet.Apply(command, clips);
                break;

            case TokenType.Relength:
                resultContainer = Relength.Apply(command, clips);
                break;

            case TokenType.Resize:
                resultContainer = Resize.Apply(command, clips);
                break;

            case TokenType.Scale:
                resultContainer = Scale.Apply(command, clips);
                break;

            case TokenType.Scan:
                resultContainer = Scan.Apply(command, clips);
                break;

            case TokenType.SetLength:
                resultContainer = SetLength.Apply(command, clips);
                break;

            case TokenType.SetRhythm:
                resultContainer = SetRhythm.Apply(command, clips);
                break;

            case TokenType.Shuffle:
                resultContainer = Shuffle.Apply(command, clips);
                break;

            case TokenType.Skip:
                resultContainer = Skip.Apply(command, clips);
                break;

            case TokenType.Slice:
                resultContainer = Slice.Apply(command, clips);
                break;

            case TokenType.Take:
                resultContainer = Take.Apply(command, clips);
                break;

            case TokenType.Transpose:
                resultContainer = Transpose.Apply(command, clips);
                break;

            default:
                return(new ProcessResultArray <Clip>($"Unsupported command {command.Id}"));
            }
            return(resultContainer);
        }
Ejemplo n.º 8
0
        private static void Main(string[] args)
        {
            // First chop the spindle description off the end of the arg list

            string[] spindleArgs = null;
            int      idx         = Array.FindIndex(args, a => string.Compare(a, "-s", true) == 0);

            if (idx >= 0)
            {
                spindleArgs = new string[args.Length - idx];
                Array.Copy(args, idx, spindleArgs, 0, spindleArgs.Length);
                string[] newArgs = new string[idx];
                Array.Copy(args, 0, newArgs, 0, idx);
                args = newArgs;
            }

            if (args.Length > 0)
            {
                if (args[0] == "-h")
                {
                    Usage(null);
                    return;
                }
                if (args[0] == "-m")
                {
                    if (args.Length != 5 ||
                        !int.TryParse(args[1], out int numerator) || !int.TryParse(args[2], out int denominator) ||
                        !int.TryParse(args[3], out int minTeeth) | !int.TryParse(args[4], out int maxTeeth))
                    {
                        Usage("-m option needs 4 arguments");
                        return;
                    }
                    Console.WriteLine(GearParameters.MatchedPairs(numerator, denominator, minTeeth, maxTeeth));
                    return;
                }
                if (args[0] == "-C")
                {
                    if (args.Length != 2)
                    {
                        Usage("-C option needs just a filename as an argument");
                        return;
                    }
                    int[] pressureAngles = new int[] { 145, 200, 250 };
                    int[] teeth          = new int[] { 8, 10, 12, 14, 16, 18, 24, 30, 36, 48, 72, 144 };
                    using StreamWriter sw = new StreamWriter(args[1]);
                    sw.Write(GenerateGearTables(pressureAngles, teeth, 100, 0));
                    return;
                }
                if (args[0] == "-c")
                {
                    if (args.Length != 6)
                    {
                        Usage("-c option needs 5 arguments");
                        return;
                    }
                    string[] values = args[2].Split(',', StringSplitOptions.RemoveEmptyEntries);

                    List <int> angles = new List <int>();
                    foreach (string s in values)
                    {
                        if (int.TryParse(s, out int result))
                        {
                            angles.Add(result);
                        }
                        else
                        {
                            Usage("Pressure angles should be a comma-separated list of integers, measured in tenths of a degree");
                            return;
                        }
                    }

                    values = args[3].Split(',', StringSplitOptions.RemoveEmptyEntries);
                    List <int> toothList = new List <int>();
                    foreach (string s in values)
                    {
                        if (int.TryParse(s, out int result))
                        {
                            toothList.Add(result);
                        }
                        else
                        {
                            Usage("Tooth counts should be a comma-separated list of integers");
                            return;
                        }
                    }

                    if (!int.TryParse(args[4], out int module))
                    {
                        Usage("Module should be an integer measured in 100ths of a mm");
                        return;
                    }

                    if (!int.TryParse(args[5], out int cutterDiameter))
                    {
                        Usage("Cutter diameter should be an integer measured in 100ths of a mm");
                        return;
                    }

                    using StreamWriter sw = new StreamWriter(args[1]);
                    sw.Write(GenerateGearTables(angles, toothList, module, cutterDiameter));
                    return;
                }
                if (args[0].ToLower() == "-p")
                {
                    if (args.Length != 8 ||
                        !int.TryParse(args[1], out int teeth) ||
                        !int.TryParse(args[2], out int shift) ||
                        !int.TryParse(args[3], out int maxErr) ||
                        !int.TryParse(args[4], out int pressureAngle) ||
                        !int.TryParse(args[5], out int module) ||
                        !int.TryParse(args[6], out int backlash) ||
                        !int.TryParse(args[7], out int cutterDiameter))
                    {
                        Usage("-p and -P options need seven arguments, plus an optional following -s argument list");
                        return;
                    }
                    GearParameters gear = new GearParameters(
                        teeth,
                        module / 100.0,
                        Math.PI * pressureAngle / 1800.0,
                        shift / 1000.0,
                        maxErr / 100.0,
                        backlash / (double)module,
                        cutterDiameter / 100.0);

                    Cutouts cutoutCalculator = CreateCutouts(gear, spindleArgs);

                    // Generate the SVG version of the gear path

                    GearGenerator.GenerateSVGFile(cutoutCalculator, (float)gear.AddendumCircleDiameter,
                                                  $"t{gear.ToothCount}p{shift}a{pressureAngle}m{module}b{backlash}c{cutterDiameter}");

                    // Create the output plot file of the gear

                    int    limit = gear.ToothCount;
                    double angle = Math.PI;
                    if (args[0] == "-P")
                    {
                        limit = 1;
                        angle = gear.ToothAngle / 2;
                    }

                    List <IEnumerable <PointF> > gearPoints = new List <IEnumerable <PointF> >
                    {
                        Involutes.CirclePoints(-angle, angle, Involutes.AngleStep, gear.PitchCircleDiameter / 2),
                        Involutes.CirclePoints(-angle, angle, Involutes.AngleStep, gear.BaseCircleDiameter / 2)
                    };

                    //IEnumerable<PointF> addendCircle = Involutes.CirclePoints(-Math.PI / gear.ToothCount, Math.PI / gear.ToothCount, GearParameters.AngleStep, gear.AddendumCircleDiameter / 2);
                    //IEnumerable<PointF> dedendCircle = Involutes.CirclePoints(-Math.PI / gear.ToothCount, Math.PI / gear.ToothCount, GearParameters.AngleStep, gear.DedendumCircleDiameter / 2);

                    for (int i = 0; i < limit; i++)
                    {
                        gearPoints.AddRange(gear.GeneratePointsForOnePitch(i));
                    }

                    if (args[0] == "-p")
                    {
                        GearGenerator.GenerateCutoutPlot(cutoutCalculator, gearPoints);
                    }

                    // Report what was created

                    Console.WriteLine(gear.Information);
                    Console.WriteLine(cutoutCalculator.Information);

                    using Image img = Plot.PlotGraphs(gearPoints, 2048, 2048);
                    img.Save($"t{gear.ToothCount}p{shift}a{pressureAngle}m{module}b{backlash}c{cutterDiameter}.png", ImageFormat.Png);
                }
                if (args[0].ToLower() == "-e")
                {
                    if (args.Length != 8 ||
                        !int.TryParse(args[1], out int teeth) ||
                        !int.TryParse(args[2], out int maxErr) ||
                        !int.TryParse(args[3], out int undercutAngle) ||
                        !int.TryParse(args[4], out int module) ||
                        !int.TryParse(args[5], out int toothFaceLength) ||
                        !int.TryParse(args[6], out int tipPitch) ||
                        !int.TryParse(args[7], out int cutDiameter))
                    {
                        Usage("-e and -E options require 7 arguments, plus an optional -s argument list");
                        return;
                    }
                    EscapeGearParameters gear = new EscapeGearParameters(
                        teeth,
                        module / 100.0,
                        Math.PI * undercutAngle / 1800.0,
                        toothFaceLength / 100.0,
                        tipPitch / 100.0,
                        cutDiameter / 100.0,
                        maxErr / 100.0
                        );

                    Cutouts cutoutCalculator = CreateCutouts(gear, spindleArgs);

                    // Generate the SVG version of the gear path

                    GearGenerator.GenerateSVGFile(cutoutCalculator, (float)gear.PitchCircleDiameter,
                                                  $"e{gear.ToothCount}u{undercutAngle}m{module}f{toothFaceLength}p{tipPitch}d{cutDiameter}");

                    // Create the output plot file of the gear

                    List <IEnumerable <PointF> > gearPoints = new List <IEnumerable <PointF> >();
                    int    limit = gear.ToothCount;
                    double angle = 2 * Math.PI;
                    if (args[0] == "-E")
                    {
                        limit = 1;
                        angle = gear.ToothAngle;

                        gearPoints.Add(Involutes
                                       .CirclePoints(0, angle, Involutes.AngleStep, gear.PitchCircleDiameter / 2));
                        gearPoints.Add(Involutes
                                       .CirclePoints(0, angle, Involutes.AngleStep, gear.InnerDiameter / 2));
                    }

                    for (int i = 0; i < limit; i++)
                    {
                        gearPoints.Add(gear.ToothProfile(i));
                    }

                    if (args[0] == "-e")
                    {
                        GearGenerator.GenerateCutoutPlot(cutoutCalculator, gearPoints);
                    }

                    // Report what was created

                    Console.WriteLine(gear.Information);
                    Console.WriteLine(cutoutCalculator.Information);

                    using Image img = Plot.PlotGraphs(gearPoints, 2048, 2048);
                    img.Save($"e{gear.ToothCount}u{undercutAngle}m{module}f{toothFaceLength}p{tipPitch}d{cutDiameter}.png", ImageFormat.Png);
                }
                if (args[0].ToLower() == "-r")
                {
                    if (args.Length != 6 ||
                        !int.TryParse(args[1], out int teeth) ||
                        !int.TryParse(args[2], out int maxErr) ||
                        !int.TryParse(args[3], out int module) ||
                        !int.TryParse(args[4], out int innerDiameter) ||
                        !int.TryParse(args[5], out int cutterrDiameter))
                    {
                        Usage("-r option requires 5 arguments, plus an optional -s argument list");
                        return;
                    }
                    Ratchet gear = new Ratchet(
                        teeth,
                        module / 100.0,
                        maxErr / 100.0,
                        innerDiameter / 100.0,
                        cutterrDiameter / 100.0
                        );

                    Cutouts cutoutCalculator = CreateCutouts(gear, spindleArgs);

                    // Generate the SVG version of the gear path

                    GearGenerator.GenerateSVGFile(cutoutCalculator, (float)gear.PitchCircleDiameter,
                                                  $"t{gear.ToothCount}m{module}i{innerDiameter}");

                    // Create the output plot file of the gear

                    List <IEnumerable <PointF> > gearPoints = new List <IEnumerable <PointF> >();
                    for (int i = 0; i < gear.ToothCount; i++)
                    {
                        gearPoints.Add(gear.ToothProfile(i));
                    }

                    GearGenerator.GenerateCutoutPlot(cutoutCalculator, gearPoints);

                    // Report what was created

                    Console.WriteLine(gear.Information);
                    Console.WriteLine(cutoutCalculator.Information);

                    using Image img = Plot.PlotGraphs(gearPoints, 2048, 2048);
                    img.Save($"t{teeth}m{module}e{maxErr}i{innerDiameter}.png", ImageFormat.Png);
                }
            }
            else
            {
                Usage("Missing or unrecognised arguments");
            }
        }