Пример #1
0
        public void Complex1()
        {
            string line = "Z11 G22 ; hoge";
            var    test = new LineCommand();

            Assert.AreEqual(test.Parse(line), true);
            Assert.AreEqual(test.Comment, "; hoge");
            Assert.AreEqual(test.Original, line);
            Assert.AreEqual(test.Count, 2);
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('G', out value, out pos), true);
                Assert.AreEqual(value, 22);
                Assert.AreEqual(pos, 1);
                Assert.AreEqual(test.GetFP('G'), 0);
            }
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('Z', out value, out pos), true);
                Assert.AreEqual(value, 11);
                Assert.AreEqual(pos, 0);
                Assert.AreEqual(test.GetFP('Z'), 0);
            }
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('A', out value, out pos), false);
                Assert.AreEqual(test.GetFP('A'), 0);
            }
        }
Пример #2
0
        public ICanvas Execute(ICanvas canvas)
        {
            var width  = this.End.X - this.Start.X;
            var height = this.End.Y - this.Start.Y;


            var line1 = new LineCommand(
                this.Start,
                new System.Drawing.Point(this.Start.X + width, this.Start.Y));

            canvas = line1.Execute(canvas);

            var line2 = new LineCommand(
                this.Start,
                new System.Drawing.Point(this.Start.X, this.Start.Y + height));

            canvas = line2.Execute(canvas);

            var line3 = new LineCommand(
                new System.Drawing.Point(this.Start.X, this.Start.Y + height),
                this.End);

            canvas = line3.Execute(canvas);


            var line4 = new LineCommand(
                new System.Drawing.Point(this.Start.X + width, this.Start.Y),
                this.End);

            canvas = line4.Execute(canvas);

            return(canvas);
        }
Пример #3
0
        public void Error1()
        {
            string line = "Z11 Z12";
            var    test = new LineCommand();

            Assert.AreEqual(test.Parse(line), false);
        }
Пример #4
0
        public void ActionLineTestToAbs()
        {
            var test = new ValueXYZEF();

            test.PreAction();

            string line   = "G91";
            var    parser = new LineCommand();

            test.X = 0.1;
            test.Y = 0.2;
            test.Z = 0.3;
            test.E = 0.4;
            test.F = 0.5;
            parser.Parse(line);
            test.ActionLine(parser);
            Assert.AreEqual(test.IsAbsolute, false);

            line = "G90";
            parser.Parse(line);
            test.ActionLine(parser);
            Assert.AreEqual(test.IsAbsolute, true);

            line = "G1 X1 Y2 Z3 E4 F5";
            parser.Parse(line);
            test.ActionLine(parser);

            Assert.AreEqual(test.X, 1);
            Assert.AreEqual(test.Y, 2);
            Assert.AreEqual(test.Z, 3);
            Assert.AreEqual(test.E, 4);
            Assert.AreEqual(test.F, 5);
        }
Пример #5
0
        public void ActionLineTestIncUnit()
        {
            var test = new ValueXYZEF();

            test.X = 0.1;
            test.Y = 0.2;
            test.Z = 0.3;
            test.E = 0.4;
            test.F = 0.5;

            string line   = "G20";
            var    parser = new LineCommand();

            parser.Parse(line);
            test.ActionLine(parser);
            line = "G91";
            parser.Parse(line);
            test.ActionLine(parser);

            line = "G1 X1 Y2 Z3 E4 F5";
            parser.Parse(line);
            test.ActionLine(parser);

            Assert.AreEqual(test.X, 2.54 * 1 + 0.1);
            Assert.AreEqual(test.Y, 2.54 * 2 + 0.2);
            Assert.AreEqual(test.Z, 2.54 * 3 + 0.3);
            Assert.AreEqual(test.E, 2.54 * 4 + 0.4);
            Assert.AreEqual(test.F, 2.54 * 5 + 0.5);
        }
Пример #6
0
        public void ActionLineTestInc1()
        {
            var test = new ValueXYZEF();

            test.PreAction();

            string line   = "G91";
            var    parser = new LineCommand();

            test.X = 0.1;
            test.Y = 0.2;
            test.Z = 0.3;
            test.E = 0.4;
            test.F = 0.5;
            parser.Parse(line);
            test.ActionLine(parser);

            line = "G1 X1 Y2 Z3 E4 F5";
            parser.Parse(line);
            test.ActionLine(parser);

            Assert.AreEqual(test.X, 1.1);
            Assert.AreEqual(test.Y, 2.2);
            Assert.AreEqual(test.Z, 3.3);
            Assert.AreEqual(test.E, 4.4);
            Assert.AreEqual(test.F, 5.5);
        }
Пример #7
0
        public void ActionLineTestInc2()
        {
            var test = new ValueXYZEF();

            test.PreAction();

            string line   = "G91";
            var    parser = new LineCommand();

            test.X = 0.1;
            test.Y = 0.2;
            test.Z = 0.3;
            test.E = 0.4;
            test.F = 0.5;
            parser.Parse(line);
            test.ActionLine(parser);

            line = "G1 X-1 Y-2 Z-3 E-4 F-5";
            parser.Parse(line);
            test.ActionLine(parser);

            Assert.AreEqual(test.X, -1 + 0.1);
            Assert.AreEqual(test.Y, -2 + 0.2);
            Assert.AreEqual(test.Z, -3 + 0.3);
            Assert.AreEqual(test.E, -4 + 0.4);
            Assert.AreEqual(test.F, -5 + 0.5);
        }
Пример #8
0
        public void Value2()
        {
            string line = "G1.0";
            var    test = new LineCommand();

            Assert.AreEqual(test.Parse(line), true);
            Assert.AreEqual(test.Comment, null);
            Assert.AreEqual(test.Original, line);
            Assert.AreEqual(test.Count, 1);
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('G', out value, out pos), true);
                Assert.AreEqual(value, 1.0);
                Assert.AreEqual(pos, 0);
                Assert.AreEqual(test.GetFP('G'), 1);
                Assert.AreEqual(test.Has('G'), true);
            }
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('A', out value, out pos), false);
                Assert.AreEqual(test.GetFP('A'), 0);
                Assert.AreEqual(test.Has('A'), false);
            }
        }
Пример #9
0
        public override void LoadLyric(WordLyric lyric)
        {
            OnAddLyricLine?.Invoke(lyric);

            commandList  = new SortedList <float, FlagCommand>();
            CurrentCusor = -1;
            for (int i = 0; i < lyric.Length; i++)
            {
                var line = lyric[i];
                //行切换的指令
                LineCommand lineCmd = new LineCommand(line)
                {
                    linecode = i
                };
                if (i + 1 < lyric.Length)
                {
                    lineCmd.SetupExitStatus(lyric[i + 1].ActiveTime);
                }
                else
                {
                    lineCmd.SetupExitStatus(float.PositiveInfinity);
                }

                commandList.Add(line.ActiveTime, lineCmd);
                //组切换的指令
                HandleGroupCollection(lineCmd, line.LyricGroup, false, lineCmd.enter_group_status, lineCmd.exit_group_status);
                HandleGroupCollection(lineCmd, line.TranslateGroup, true, lineCmd.enter_group_status_translate, lineCmd.exit_group_status_translate);
            }
        }
Пример #10
0
        public void TestSpriteFactoryLine()
        {
            SpriteCommand command = new LineCommand(1, 5, 1, 3);

            SpriteEntity sprite = SpriteFactory.GetSprite(command, Canvas);

            Assert.IsInstanceOfType(sprite, typeof(Line));
        }
Пример #11
0
        public void Comment1()
        {
            string line = ";hoge";
            var    test = new LineCommand();

            Assert.AreEqual(test.Parse(line), true);
            Assert.AreEqual(test.Comment, line);
            Assert.AreEqual(test.Original, line);
            Assert.AreEqual(test.Count == 0, true);
        }
Пример #12
0
        public void NullLine()
        {
            string line = "";
            var    test = new LineCommand();

            Assert.AreEqual(test.Parse(line), true);
            Assert.AreEqual(test.Comment, null);
            Assert.AreEqual(test.Original, line);
            Assert.AreEqual(test.Count == 0, true);
        }
Пример #13
0
        public void ToString10()
        {
            var    source = new LineCommand();
            string line   = "G1.1 A2.22 Z-3;comment";

            source.Parse(line);

            var result = OutputGCode.ToString(source, false);

            Assert.AreEqual(result, "G1.1 A2.22 Z-3");
        }
Пример #14
0
        public void CloneValues1()
        {
            string line = "G11.1 Z22.22";
            var    test = new LineCommand();

            Assert.AreEqual(test.Parse(line), true);
            Assert.AreEqual(test.Comment, null);
            Assert.AreEqual(test.Original, line);
            Assert.AreEqual(test.Count, 2);

            var val = test.CloneValues();

            Assert.AreEqual(val.Count, 2);
            Assert.AreEqual(val[0].Key, 'G');
            Assert.AreEqual(val[0].Value, 11.1);
            Assert.AreEqual(val[0].FP, 1);
            Assert.AreEqual(val[0].Position, 0);
            Assert.AreEqual(val[1].Key, 'Z');
            Assert.AreEqual(val[1].Value, 22.22);
            Assert.AreEqual(val[1].FP, 2);
            Assert.AreEqual(val[1].Position, 1);

            // CloneValuesでもらったデータを変更したら、オリジナル側が変わっていないことも確認
            val[0].Value    = 22.3;
            val[0].FP       = 0;
            val[0].Position = 1;
            val[1].Value    = 33.3;
            val[1].FP       = 0;
            val[1].Position = 0;

            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('G', out value, out pos), true);
                Assert.AreEqual(value, 11.1);
                Assert.AreEqual(pos, 0);
                Assert.AreEqual(test.GetFP('G'), 1);
            }
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('Z', out value, out pos), true);
                Assert.AreEqual(value, 22.22);
                Assert.AreEqual(pos, 1);
                Assert.AreEqual(test.GetFP('Z'), 2);
            }
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('A', out value, out pos), false);
                Assert.AreEqual(test.GetFP('A'), 0);
            }
        }
Пример #15
0
        public static Line CreateSprite(
            SpriteCommand command,
            Canvas canvas
            )
        {
            LineCommand lineCommand = (LineCommand)command;

            return(CreateSprite(
                       new Point(lineCommand.X1, lineCommand.Y1),
                       new Point(lineCommand.X2, lineCommand.Y2),
                       canvas
                       ));
        }
Пример #16
0
    // record a single line command
    void RecordLineCommand(LineCommand lc)
    {
        Debug.Log("RecordLineCommand");

        // Forget history to remove backtrace
        setupInstance.history.Forget(setupInstance.historyBacktraceOffset);
        setupInstance.totalHistoriesRecorded -= setupInstance.historyBacktraceOffset;
        setupInstance.historyBacktraceOffset  = 0;

        // record command at front of annal
        setupInstance.history.Record(lc);
        ++setupInstance.totalHistoriesRecorded;
    }
Пример #17
0
        public void TestLineCreateSprite1()
        {
            SpriteCommand command = new LineCommand(X1, Y1, X2, Y2);

            Line sprite = Line.CreateSprite(command, Canvas);

            Point point1 = new Point(X1, Y1);
            Point point2 = new Point(X2, Y2);

            AssertHelper.AssertEqual(point1, sprite.Point1);
            AssertHelper.AssertEqual(point2, sprite.Point2);
            Assert.AreEqual(C, sprite.C);
        }
Пример #18
0
        public static string Generate(LineCommand line)
        {
            string result = "";
            var    LstBinaryMatrixNumber = new List <int[, ]>();

            int size = line.Size;

            line.LstNumbers.ForEach(x => LstBinaryMatrixNumber.Add(MatrixCode.GetBinaryMatrixNumber(x)));

            for (int i = 0; i < 5; i++)
            {
                var newStringLine = "";
                for (int k = 0; k < LstBinaryMatrixNumber.Count; k++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        if (LstBinaryMatrixNumber[k][i, j] == 0)
                        {
                            if (j == 1)
                            {
                                for (int s = 0; s < size; s++)
                                {
                                    newStringLine += charSpace;
                                }
                            }
                            else
                            {
                                newStringLine += charSpace;
                            }
                        }
                        else
                        {
                            if (i % 2 == 0)
                            {
                                for (int s = 0; s < size; s++)
                                {
                                    newStringLine += charHorizontal;
                                }
                            }

                            else
                            {
                                newStringLine += charVertical;
                            }
                        }
                    }
                }
                result += ValidateDuplicationLine(i, size, newStringLine);
            }
            return(result);
        }
Пример #19
0
    void RedoLineCommand()
    {
        Debug.Log("RedoLineCommand");
        // have some commands to redo
        if (setupInstance.historyBacktraceOffset > 0)
        {
            // move offset up 1
            --setupInstance.historyBacktraceOffset;

            // execute linecommands in annal up to count times
            LineCommand lc = setupInstance.history.Recall(setupInstance.historyBacktraceOffset);
            ApplyCommand(ref lc);
        }
    }
Пример #20
0
        public void Add1()
        {
            var test = new LineCommand();

            Assert.AreEqual(test.Add('G', 10.1, 1), true);
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('G', out value, out pos), true);
                Assert.AreEqual(value, 10.1);
                Assert.AreEqual(pos, 0);
                Assert.AreEqual(test.GetFP('G'), 1);
            }
        }
Пример #21
0
        public void Values5()
        {
            string line = "ABCDE";
            var    test = new LineCommand();

            Assert.AreEqual(test.Parse(line), true);
            Assert.AreEqual(test.Count, 5);
            Assert.AreEqual(test.GetKey(-1), ' ');
            Assert.AreEqual(test.GetKey(5), ' ');
            Assert.AreEqual(test.GetKey(0), 'A');
            Assert.AreEqual(test.GetKey(1), 'B');
            Assert.AreEqual(test.GetKey(2), 'C');
            Assert.AreEqual(test.GetKey(3), 'D');
            Assert.AreEqual(test.GetKey(4), 'E');
        }
Пример #22
0
 void ApplyCommand(ref LineCommand lineCommand)
 {
     foreach (var go in lineCommand.gos)
     {
         // @TODO @FIX
         if (go != null)
         {
             var setLine = go.GetComponent <SetLine>();
             setLine.RunCommand(this, lineCommand);
         }
         else
         {
             Debug.LogWarning("Saving null objects because they can't be added to grid or something, fix this!");
         }
     }
 }
Пример #23
0
        public void Add3()
        {
            var line = "G10.00";
            var test = new LineCommand();

            test.Parse(line);
            Assert.AreEqual(test.Add('G', 10.1, 1), false);
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('G', out value, out pos), true);
                Assert.AreEqual(value, 10.0);
                Assert.AreEqual(pos, 0);
                Assert.AreEqual(test.GetFP('G'), 2);
            }
        }
Пример #24
0
        public void ActionLineTest4()
        {
            string line   = "X1 Y2 Z3 E4 F5";
            var    parser = new LineCommand();

            parser.Parse(line);
            var test = new ValueXYZEF();

            test.PreAction();
            test.ActionLine(parser);
            Assert.AreEqual(test.X, 0);
            Assert.AreEqual(test.Y, 0);
            Assert.AreEqual(test.Z, 0);
            Assert.AreEqual(test.E, 0);
            Assert.AreEqual(test.F, 0);
        }
Пример #25
0
    void UndoLineCommand()
    {
        Debug.Log("UndoLineCommmand");
        // If we have recorded the history AND have a record going back that far.
        if (setupInstance.totalHistoriesRecorded > setupInstance.historyBacktraceOffset &&
            setupInstance.history.size > setupInstance.historyBacktraceOffset)
        {
            // execute inverted co*mmand up to count times
            LineCommand lc = setupInstance.history.Recall(setupInstance.historyBacktraceOffset);
            lc.Invert();
            ApplyCommand(ref lc);

            // pull back historyOffset+1
            ++setupInstance.historyBacktraceOffset;
        }
    }
Пример #26
0
        /// <summary>
        /// Creates the command.
        /// </summary>
        /// <param name="input">The input command.</param>
        /// <returns></returns>
        public static ICommand CreateCommand(string input)
        {
            ICommand command = null;

            try
            {
                var inputSplit = input.Split(' ');
                switch (inputSplit[0])
                {
                case "C":
                    command = new CanvasCommand(inputSplit[1], inputSplit[2]);
                    break;

                case "L":
                    command = new LineCommand(inputSplit[1], inputSplit[2],
                                              inputSplit[3], inputSplit[4]);
                    break;

                case "R":
                    command = new RectCommand(inputSplit[1], inputSplit[2],
                                              inputSplit[3], inputSplit[4]);
                    break;

                case "B":
                    command = new FillCommand(inputSplit[1], inputSplit[2],
                                              inputSplit[3]);
                    break;

                case "Q":
                    command = new QuitCommand();
                    break;

                default:
                    break;
                }

                if (command != null && !command.IsValid)
                {
                    command = null;
                }
            }
            catch (System.Exception)
            {
                command = null;
            }
            return(command);
        }
Пример #27
0
            public void ShouldDrawVerticalLineRightToLeft()
            {
                var start = new System.Drawing.Point(6, 2);
                var end   = new System.Drawing.Point(6, 0);
                var cmd   = new LineCommand(start, end);

                var canvas = new Canvas(20, 5);

                var result = cmd.Execute(canvas);

                var expected = new char[20, 5];

                expected[6, 0] = 'x';
                expected[6, 1] = 'x';
                expected[6, 2] = 'x';

                Assert.Equal(expected, result.Data);
            }
Пример #28
0
    internal void RunCommand(Level level, LineCommand lineCommand)
    {
        switch (lineCommand.cmd)
        {
        case LineCommand.Command.None:
            break;

        case LineCommand.Command.Place:
            Place(level, lineCommand.flags);
            break;

        case LineCommand.Command.Remove:
            Remove(level, lineCommand.flags);
            break;

        case LineCommand.Command.Move:
            break;
        }
    }
Пример #29
0
        public void ActionLineTestAbs()
        {
            string line   = "G1 X1 Y2 Z3 E4 F5";
            var    parser = new LineCommand();

            parser.Parse(line);
            var test = new ValueXYZEF();

            test.X = 0.1;
            test.Y = 0.2;
            test.Z = 0.3;
            test.E = 0.4;
            test.F = 0.5;
            test.ActionLine(parser);
            Assert.AreEqual(test.X, 1);
            Assert.AreEqual(test.Y, 2);
            Assert.AreEqual(test.Z, 3);
            Assert.AreEqual(test.E, 4);
            Assert.AreEqual(test.F, 5);
        }
Пример #30
0
        public bool ActionLine(LineCommand line)
        {
            bool   hasXY = line.Has('X') || line.Has('Y');
            bool   hasZ  = line.Has('Z');
            Double prevE = current_.E;

            if (current_.ActionLine(line))
            {
                Double value;
                int    position;
                if (line.TryGetValue('G', out value, out position))
                {
                    switch (value)
                    {
                    case 92:
                        if (line.Has('E'))
                        {
                            totalE_ += prevE;
                        }
                        break;

                    case 1:
                        if (hasXY)
                        {
                            totalLength_ += prev_.LengthXYTo(current_);
                            totalTime_   += prev_.LengthXYTo(current_) / current_.F;
                        }
                        if (hasZ)
                        {
                            totalLength_ += prev_.LengthZTo(current_);
                            totalTime_   += prev_.LengthZTo(current_) / current_.F;
                        }
                        break;
                    }
                }
                prev_.Update(current_);
                return(true);
            }
            return(false);
        }
Пример #31
0
 private void AssertIf(LineCommand lineCommand, params int[] expected)
 {
     Assert.True(lineCommand.IsIf);
     AssertIf(lineCommand.AsIf().Item, expected, 0);
 }