Exemplo n.º 1
0
        private VisualInstructionUserControl InsertOutputInstructionAtRight(bool after, VisualInstructionUserControl visualInstruction, InstructionList instructions)
        {
            int index = 0;
            int autToRetornInsertedInstruction = 0;

            switch (visualOutputInstructions.Count)
            {
            case 0:
                index = 0;

                if (instructions.Count > 1)
                {
                    instructions.InsertParallelBranch(InstructionList.ParallelBranchInsertionType.ParallelBranchCompleted);
                    autToRetornInsertedInstruction = -1;
                }

                break;

            case 1:
                index = VerifyPositionToInsert(after, visualInstruction, this.visualOutputInstructions);

                if (index == 0)
                {
                    instructions.InsertParallelBranch(InstructionList.ParallelBranchInsertionType.ParallelBranchInitialized);

                    line.Outputs.Insert(0, InstructionFactory.createInstruction(OperationCode.ParallelBranchNext));
                    InsertVisualInstructionAt(0, this.visualOutputInstructions, InstructionFactory.createInstruction(OperationCode.ParallelBranchNext));
                    line.Outputs.Insert(this.visualOutputInstructions.Count, InstructionFactory.createInstruction(OperationCode.ParallelBranchEnd));
                    InsertVisualInstructionAt(this.visualOutputInstructions.Count, this.visualOutputInstructions, InstructionFactory.createInstruction(OperationCode.ParallelBranchEnd));
                }
                else
                {
                    instructions.InsertParallelBranch(InstructionList.ParallelBranchInsertionType.ParallelBranchFinalized);
                    autToRetornInsertedInstruction = -1;

                    line.Outputs.Insert(0, InstructionFactory.createInstruction(OperationCode.ParallelBranchBegin));
                    InsertVisualInstructionAt(0, this.visualOutputInstructions, InstructionFactory.createInstruction(OperationCode.ParallelBranchBegin));
                    index++;
                }

                break;

            default:
                index = VerifyPositionToInsert(false, visualInstruction, this.visualOutputInstructions);

                switch (this.visualOutputInstructions[index].OpCode)
                {
                case OperationCode.ParallelBranchBegin:
                    instructions.InsertParallelBranch(InstructionList.ParallelBranchInsertionType.ParallelBranchInitialized);

                    line.Outputs[0].OpCode = OperationCode.ParallelBranchNext;
                    this.visualOutputInstructions[0].OpCode = OperationCode.ParallelBranchNext;
                    break;

                case OperationCode.ParallelBranchNext:
                    instructions.InsertParallelBranchNext();
                    break;

                case OperationCode.ParallelBranchEnd:
                    instructions.InsertParallelBranchNext();
                    break;

                default:
                    instructions.InsertParallelBranchNext();
                    index++;
                    break;
                }
                break;
            }

            foreach (Instruction instruction in instructions)
            {
                line.Outputs.Insert(index, instruction);
                InsertVisualInstructionAt(index, this.visualOutputInstructions, instruction);
                index++;
            }

            return(this.visualOutputInstructions[index - 1 + autToRetornInsertedInstruction]);
        }
Exemplo n.º 2
0
        public Instruction InsertToOutputs(Line line, InstructionList instructions)
        {
            int index = 0;
            int auxToPositionInsertedInstruciton = 0;

            switch (line.Outputs.Count)
            {
            case 0:
                /// case 0: First instruction to output, add only one
                /// instruction at output
                index = 0;

                if (instructions.Count > 1)
                {
                    instructions.InsertParallelBranch(InstructionList.ParallelBranchInsertionType.ParallelBranchCompleted);
                    auxToPositionInsertedInstruciton = -1;
                }

                break;

            case 1:
                /// case 1: If exists one output instruction, insert parallel branch
                /// automatically


                // here 0=before, 1=after
                if (index == 0)
                {
                    /// prepare to insert before the actual object
                    instructions.InsertParallelBranch(InstructionList.ParallelBranchInsertionType.ParallelBranchInitialized);

                    /// insert parallel branch next before the actual object
                    //line.Outputs.Insert(0, new Instruction(OperationCode.ParallelBranchNext));
                    line.Outputs.Insert(0, InstructionFactory.createInstruction(OperationCode.ParallelBranchNext));
                    /// insert parallel branch end after the actual object
                    //line.Outputs.Insert(line.Outputs.Count, new Instruction(OperationCode.ParallelBranchEnd));
                    line.Outputs.Insert(line.Outputs.Count, InstructionFactory.createInstruction(OperationCode.ParallelBranchEnd));
                }
                else
                {
                    instructions.InsertParallelBranch(InstructionList.ParallelBranchInsertionType.ParallelBranchFinalized);
                    auxToPositionInsertedInstruciton = -1;

                    line.Outputs.Insert(0, InstructionFactory.createInstruction(OperationCode.ParallelBranchBegin));
                    index++;
                }

                break;

            default:
                switch (line.Outputs[index].OpCode)
                {
                case OperationCode.ParallelBranchBegin:
                    instructions.InsertParallelBranch(InstructionList.ParallelBranchInsertionType.ParallelBranchInitialized);

                    line.Outputs[0].OpCode = OperationCode.ParallelBranchNext;
                    break;

                case OperationCode.ParallelBranchNext:
                    instructions.InsertParallelBranchNext();
                    break;

                case OperationCode.ParallelBranchEnd:
                    instructions.InsertParallelBranchNext();
                    break;

                default:
                    instructions.InsertParallelBranchNext();
                    index++;
                    break;
                }
                break;
            }

            foreach (Instruction instruction in instructions)
            {
                line.Outputs.Insert(index, instruction);
                index++;
            }
            return(line.Outputs[index - 1 + auxToPositionInsertedInstruciton]);
        }