Exemplo n.º 1
0
        public void Defaults()
        {
            PrinterOptions options = new PrinterOptions();

            Assert.AreEqual(new Vector3(200f, 200f, 200f), options.GetBuildAreaSize());
            Assert.AreEqual(Vector3.Zero, options.GetHomePosition());
            Assert.AreEqual(0.4f, options.ExtruderDiameter);
            Assert.AreEqual(200f, options.ExtruderTemperature);
            Assert.AreEqual(true, options.TableHeating);
            Assert.AreEqual(100f, options.TableTemperature);
            Assert.AreEqual(0.01f, options.FilamentRate);
            Assert.AreEqual(5.7f, options.RetractDistance);
            Assert.AreEqual(7200, options.SpeedXYFast);
            Assert.AreEqual(1134, options.SpeedXYSlow);
            Assert.AreEqual(1002, options.SpeedZ);
            Assert.AreEqual(4800, options.SpeedE);
        }
Exemplo n.º 2
0
        public void CopyFrom()
        {
            PrinterOptions other = new PrinterOptions()
            {
                BuildAreaWidth      = 450f,
                BuildAreaDepth      = 350f,
                BuildAreaHeight     = 500f,
                HomePositionX       = 100f,
                HomePositionY       = 50f,
                ExtruderDiameter    = 0.2f,
                ExtruderTemperature = 180f,
                TableHeating        = false,
                TableTemperature    = 55f,
                FilamentRate        = 0.5f,
                RetractDistance     = 3f,
                SpeedXYFast         = 6400,
                SpeedXYSlow         = 2400,
                SpeedE = 3600,
                SpeedZ = 1500
            };

            PrinterOptions options = new PrinterOptions();

            options.CopyFrom(other);

            Assert.AreEqual(new Vector3(450f, 350f, 500f), options.GetBuildAreaSize());
            Assert.AreEqual(new Vector3(100f, 50f, 0f), options.GetHomePosition());
            Assert.AreEqual(0.2f, options.ExtruderDiameter);
            Assert.AreEqual(180f, options.ExtruderTemperature);
            Assert.AreEqual(false, options.TableHeating);
            Assert.AreEqual(55f, options.TableTemperature);
            Assert.AreEqual(0.5f, options.FilamentRate);
            Assert.AreEqual(3f, options.RetractDistance);
            Assert.AreEqual(6400, options.SpeedXYFast);
            Assert.AreEqual(2400, options.SpeedXYSlow);
            Assert.AreEqual(1500, options.SpeedZ);
            Assert.AreEqual(3600, options.SpeedE);
        }
Exemplo n.º 3
0
        public void LineEndings_Should_Not_Affect_Printed_Output_With_Verbatim_String()
        {
            // this is a verbatim string that is just the right size to format differently if it has \n vs \r\n in it
            var code =
                @"class ClassName
{
    private string blah = @""one11111111111111111111111111111111
two
three
four"";
}
";
            var codeWithLf   = code.Replace("\r\n", "\n");
            var codeWithCrLf = codeWithLf.Replace("\n", "\r\n");

            var formatter      = new CodeFormatter();
            var printerOptions = new PrinterOptions {
                EndOfLine = EndOfLine.Auto, Width = 80
            };
            var lfResult   = formatter.Format(codeWithLf, printerOptions);
            var crLfResult = formatter.Format(codeWithCrLf, printerOptions);

            lfResult.Code.Should().Be(crLfResult.Code.Replace("\r\n", "\n"));
        }
Exemplo n.º 4
0
        public void Reset()
        {
            PrinterOptions options = new PrinterOptions()
            {
                BuildAreaWidth      = 450f,
                BuildAreaDepth      = 350f,
                BuildAreaHeight     = 500f,
                HomePositionX       = 100f,
                HomePositionY       = 50f,
                ExtruderDiameter    = 0.2f,
                ExtruderTemperature = 180f,
                TableHeating        = false,
                TableTemperature    = 55f,
                FilamentRate        = 0.5f,
                RetractDistance     = 3f,
                SpeedXYFast         = 6400,
                SpeedXYSlow         = 2400,
                SpeedE = 3600,
                SpeedZ = 1500
            };

            options.Reset();

            Assert.AreEqual(new Vector3(200f, 200f, 200f), options.GetBuildAreaSize());
            Assert.AreEqual(Vector3.Zero, options.GetHomePosition());
            Assert.AreEqual(0.4f, options.ExtruderDiameter);
            Assert.AreEqual(200f, options.ExtruderTemperature);
            Assert.AreEqual(true, options.TableHeating);
            Assert.AreEqual(100f, options.TableTemperature);
            Assert.AreEqual(0.01f, options.FilamentRate);
            Assert.AreEqual(5.7f, options.RetractDistance);
            Assert.AreEqual(7200, options.SpeedXYFast);
            Assert.AreEqual(1134, options.SpeedXYSlow);
            Assert.AreEqual(1002, options.SpeedZ);
            Assert.AreEqual(4800, options.SpeedE);
        }
Exemplo n.º 5
0
 public Indenter(PrinterOptions printerOptions)
 {
     PrinterOptions = printerOptions;
 }
Exemplo n.º 6
0
        private static bool Fits(
            PrintCommand nextCommand,
            Stack <PrintCommand> remainingCommands,
            int remainingWidth,
            PrinterOptions printerOptions,
            bool mustBeFlat = false
            )
        {
            var returnFalseIfMoreStringsFound = false;
            var newCommands = new Stack <PrintCommand>();

            newCommands.Push(nextCommand);

            void Push(Doc doc, PrintMode printMode, Indent indent)
            {
                newCommands.Push(new PrintCommand(indent, printMode, doc));
            }

            var output = new StringBuilder();

            for (var x = 0; x < remainingCommands.Count || newCommands.Count > 0;)
            {
                if (remainingWidth < 0)
                {
                    return(false);
                }

                PrintCommand command;
                if (newCommands.Count > 0)
                {
                    command = newCommands.Pop();
                }
                else
                {
                    command = remainingCommands.ElementAt(x);
                    x++;
                }

                var(currentIndent, currentMode, currentDoc) = command;

                if (currentDoc is StringDoc stringDoc)
                {
                    if (stringDoc.Value == null)
                    {
                        continue;
                    }

                    if (returnFalseIfMoreStringsFound)
                    {
                        return(false);
                    }

                    output.Append(stringDoc.Value);
                    remainingWidth -= GetStringWidth(stringDoc.Value);
                }
                else if (currentDoc != Doc.Null)
                {
                    switch (currentDoc)
                    {
                    case LeadingComment:
                    case TrailingComment:
                        if (output.Length > 0)
                        {
                            returnFalseIfMoreStringsFound = true;
                        }
                        break;

                    case Concat concat:
                        for (var i = concat.Contents.Count - 1; i >= 0; i--)
                        {
                            Push(concat.Contents[i], currentMode, currentIndent);
                        }
                        break;

                    case IndentDoc indent:
                        Push(
                            indent.Contents,
                            currentMode,
                            IndentBuilder.Make(currentIndent, printerOptions)
                            );
                        break;

                    case Trim:
                        remainingWidth += TrimOutput(output);
                        break;

                    case Group group:
                        if (mustBeFlat && group.Break)
                        {
                            return(false);
                        }

                        var groupMode = group.Break ? PrintMode.MODE_BREAK : currentMode;

                        Push(group.Contents, groupMode, currentIndent);

                        if (group.GroupId != null)
                        {
                            groupModeMap ![group.GroupId] = groupMode;
Exemplo n.º 7
0
        private static Indent GenerateIndent(
            Indent indent,
            IndentType newPart,
            PrinterOptions printerOptions
            )
        {
            var queue = new List <IndentType>(indent.Queue);

            if (newPart.Type == "dedent")
            {
                queue.RemoveAt(queue.Count - 1);
            }
            else
            {
                queue.Add(newPart);
            }

            var value    = new StringBuilder();
            var length   = 0;
            var lastTabs = 0;

            var lastSpaces = 0;

            foreach (var part in queue)
            {
                switch (part.Type)
                {
                case "indent":
                    Flush();
                    if (printerOptions.UseTabs)
                    {
                        AddTabs(1);
                    }
                    else
                    {
                        AddSpaces(printerOptions.TabWidth);
                    }
                    break;

                default:
                    throw new Exception(part.Type);
                }
            }

            FlushSpaces();

            void AddTabs(int count)
            {
                value.Append('\t', count);
                length += printerOptions.TabWidth * count;
            }

            void AddSpaces(int count)
            {
                value.Append(' ', count);
                length += count;
            }

            void Flush()
            {
                if (printerOptions.UseTabs)
                {
                    FlushTabs();
                }
                else
                {
                    FlushSpaces();
                }
            }

            void FlushTabs()
            {
                if (lastTabs > 0)
                {
                    AddTabs(lastTabs);
                }

                ResetLast();
            }

            void FlushSpaces()
            {
                if (lastSpaces > 0)
                {
                    AddSpaces(lastSpaces);
                }

                ResetLast();
            }

            void ResetLast()
            {
                lastTabs   = 0;
                lastSpaces = 0;
            }

            return(new Indent(value.ToString(), length, queue));
        }
Exemplo n.º 8
0
 public static Indent Make(Indent indent, PrinterOptions printerOptions)
 {
     return(GenerateIndent(indent, newPart: new IndentType("indent", 0), printerOptions));
 }