Exemplo n.º 1
0
        private MyDebugNode CreateDebugNode(IMyExecutable executable)
        {
            MyDebugNode result;

            if (executable is MyTask)
            {
                result = new MyDebugTaskNode(executable as MyTask);
            }
            else
            {
                result = new MyDebugNode(executable);
            }

            if (executable is MyExecutionBlock)
            {
                foreach (IMyExecutable child in (executable as MyExecutionBlock).Children)
                {
                    if (child is MySignalTask)
                    {
                        if (showSignalsButton.Checked)
                        {
                            result.Nodes.Add(CreateDebugNode(child));
                        }
                    }
                    else if (showDisabledTasksButton.Checked || child.Enabled)
                    {
                        result.Nodes.Add(CreateDebugNode(child));
                    }
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        /// Executes current IMyExecutable children and moves to next one
        public virtual MyExecutionBlock ExecuteStep()
        {
            if (m_childIterator < m_children.Length)
            {
                IMyExecutable currentChild = m_children[m_childIterator];
                m_childIterator++;

                if (currentChild is MyExecutionBlock)
                {
                    MyExecutionBlock childList = currentChild as MyExecutionBlock;
                    childList.Reset();

                    return(childList);
                }
                else
                {
                    if (currentChild.Enabled)
                    {
                        MyLog.DEBUG.WriteLine("Executing: " + currentChild.Name);
                        currentChild.SimulationStep = SimulationStep;
                        currentChild.Execute();
                    }
                    return(this);
                }
            }
            else
            {
                return(Parent);
            }
        }
Exemplo n.º 3
0
        private MyDebugNode CreateDebugNode(IMyExecutable executable)
        {
            MyDebugNode result;

            if (executable is MyTask)
            {
                result = new MyDebugTaskNode(executable as MyTask);
            }
            else
            {
                result = new MyDebugNode(executable);
            }

            if (executable is MyExecutionBlock)
            {
                foreach (IMyExecutable child in (executable as MyExecutionBlock).Children)
                {
                    if (child is MySignalTask)
                    {
                        if (showSignalsButton.Checked)
                        {
                            result.Nodes.Add(CreateDebugNode(child));
                        }
                    }
                    else if (showDisabledTasksButton.Checked || child.Enabled)
                    {
                        result.Nodes.Add(CreateDebugNode(child));
                    }
                }
            }

            return result;
        }
Exemplo n.º 4
0
 private void ProfilingExecute(IMyExecutable child)
 {
     m_profilingStopwatch.Restart();
     try
     {
         child.Execute();
     }
     finally
     {
         EndMeasuring(child);
     }
 }
Exemplo n.º 5
0
        public MyExecutionBlock CreateCustomExecutionPlan(MyExecutionBlock defaultPlan)
        {
            //get rid of signal tasks
            IMyExecutable[] content = new IMyExecutable[defaultPlan.Children.Length - 2];
            Array.Copy(defaultPlan.Children, 1, content, 0, defaultPlan.Children.Length - 2);

            //place if block inside
            return new MyExecutionBlock(
                defaultPlan.Children[0],
                new MyIfBlock(IsActive, content),
                defaultPlan.Children.Last()) { Name = defaultPlan.Name };
        }
Exemplo n.º 6
0
        /// Executes all children elements
        public virtual void Execute()
        {
            for (int i = 0; i < m_children.Length; i++)
            {
                IMyExecutable child = m_children[i];

                if (child.Enabled)
                {
                    child.SimulationStep = SimulationStep;
                    child.Execute();
                }
            }
        }
Exemplo n.º 7
0
        /// Executes current IMyExecutable children and moves to next one
        public virtual MyExecutionBlock ExecuteStep()
        {
            if (m_childIterator < m_children.Length)
            {
                IMyExecutable currentChild = m_children[m_childIterator];
                m_childIterator++;

                var childList = currentChild as MyExecutionBlock;
                if (childList != null)
                {
                    childList.Reset();

                    // Profiling an inner block.
                    if (IsProfiling)
                    {
                        m_profilingStopwatch.Restart();
                    }

                    return(childList);
                }
                else
                {
                    if (currentChild.Enabled)
                    {
                        MyLog.DEBUG.WriteLine("Executing: " + currentChild.Name);
                        currentChild.SimulationStep = SimulationStep;

                        if (IsProfiling)
                        {
                            ProfilingExecute(currentChild);
                        }
                        else
                        {
                            currentChild.Execute();
                        }
                    }
                    return(this);
                }
            }
            else
            {
                // Control goes back to parent, en its measurement of this block.
                if (IsProfiling && Parent != null)
                {
                    Parent.EndChildBlockMeasuring(this);
                }

                return(Parent);
            }
        }
Exemplo n.º 8
0
        public MyExecutionBlock CreateCustomExecutionPlan(MyExecutionBlock defaultPlan)
        {
            //get rid of signal tasks
            IMyExecutable[] content = new IMyExecutable[defaultPlan.Children.Length - 2];
            Array.Copy(defaultPlan.Children, 1, content, 0, defaultPlan.Children.Length - 2);

            //place if block inside
            return(new MyExecutionBlock(
                       defaultPlan.Children[0],
                       new MyIfBlock(IsActive, content),
                       defaultPlan.Children.Last())
            {
                Name = defaultPlan.Name
            });
        }
Exemplo n.º 9
0
        private static void AlterText(DrawTextEventArgs e)
        {
            if (e.Node.Tag is MyDebugNode)
            {
                IMyExecutable executable = (e.Node.Tag as MyDebugNode).Executable;
                if (executable is MyExecutionBlock)
                {
                    e.Font = new Font(e.Font, FontStyle.Bold);
                }

                if (!executable.Enabled)
                {
                    e.TextColor = SystemColors.GrayText;
                }
            }
        }
Exemplo n.º 10
0
        public MyDebugNode(IMyExecutable executable) : base(executable.Name)
        {
            Executable = executable;

            if (Executable is MyIncomingSignalTask)
            {
                Icon = Properties.Resources.signal_in;
            }
            else if (Executable is MyOutgoingSignalTask)
            {
                Icon = Properties.Resources.signal_out;
            }
            else
            {
                Icon = Properties.Resources.gear_16xLG;
            }
        }
Exemplo n.º 11
0
        public MyDebugNode(IMyExecutable executable) : base(executable.Name ?? string.Empty)
        {
            BackgroundColor = Color.White;

            Executable = executable;

            if (Executable is MyIncomingSignalTask)
            {
                Icon = Properties.Resources.signal_in;
            }
            else if (Executable is MyOutgoingSignalTask)
            {
                Icon = Properties.Resources.signal_out;
            }
            else
            {
                Icon = Properties.Resources.gear_16xLG;
            }
        }
Exemplo n.º 12
0
        /// Executes all children elements
        public virtual void Execute()
        {
            // ReSharper disable once ForCanBeConvertedToForeach -- Performance critical loop.
            for (int i = 0; i < m_children.Length; i++)
            {
                IMyExecutable child = m_children[i];

                if (child.Enabled)
                {
                    child.SimulationStep = SimulationStep;

                    if (IsProfiling)
                    {
                        ProfilingExecute(child);
                    }
                    else
                    {
                        child.Execute();
                    }
                }
            }
        }
Exemplo n.º 13
0
        private MyDebugNode CreateDebugNode(IMyExecutable executable)
        {
            MyDebugNode result;

            if (executable is MyTask)
            {
                result = new MyDebugTaskNode(executable as MyTask, () => m_mainForm.TaskView.RefreshView());
            }
            else
            {
                result = new MyDebugNode(executable);
            }

            var executableBlock = executable as MyExecutionBlock;

            if (executableBlock != null)
            {
                foreach (IMyExecutable child in executableBlock.Children)
                {
                    if (child is MySignalTask)
                    {
                        if (showSignalsButton.Checked)
                        {
                            result.Nodes.Add(CreateDebugNode(child));
                        }
                    }
                    else if (showDisabledTasksButton.Checked || child.Enabled)
                    {
                        result.Nodes.Add(CreateDebugNode(child));
                    }
                }
            }

            result.BreakpointStateChanged += OnBreakpointStateChanged;

            return(result);
        }
Exemplo n.º 14
0
 private void ProfilingExecute(IMyExecutable child)
 {
     m_profilingStopwatch.Restart();
     try
     {
         child.Execute();
     }
     finally
     {
         EndMeasuring(child);
     }
 }
Exemplo n.º 15
0
        public MyDebugNode(IMyExecutable executable)
            : base(executable.Name)
        {
            Executable = executable;

            if (Executable is MyIncomingSignalTask)
            {
                Icon = Properties.Resources.signal_in;
            }
            else if (Executable is MyOutgoingSignalTask)
            {
                Icon = Properties.Resources.signal_out;
            }
            else
            {
                Icon = Properties.Resources.gear_16xLG;
            }
        }
Exemplo n.º 16
0
        public ParseResult Parse(ParseMode mode, out byte[] Instructions)
        {
            byte[] MagicBytes = new byte[4];

            // Open the file as read only.
            using (FileStream Reader = TargetFile.Open(FileMode.Open))
            {
                if (mode == ParseMode.AUTO)
                {
                    // There must be no less than 4 bytes in the file in order to determine its magic bytes. This is not necessarily true for
                    // every file type. If there are only 3 bytes in the read file, the user probably chose the wrong file anyway.
                    // Reader.Read() returns the number of bytes read.
                    if (Reader.Read(MagicBytes, 0, 4) != 4)
                    {
                        Logger.Log(LogCode.IO_INVALIDFILE, "File must be no less than 4 bytes in length");
                        Instructions = null;
                        return(ParseResult.INVALID);
                    }

                    // Order the bytes in big endian(because was read from a file) to form the signature of magic bytes.
                    // Most magic byte signatures are 4 bytes, especially for the purposes of this program.
                    int Signature = MagicBytes[3] + (MagicBytes[2] << 8) + (MagicBytes[1] << 16) + (MagicBytes[0] << 24);

                    // Check if the file type can be inferred from the magic byte signature from the signatures registered in the SignatureTable.
                    MagicDelegate ResultDel;
                    if (SignatureTable.TryGetValue(Signature, out ResultDel))
                    {
                        IMyExecutable Result = ResultDel(Reader);
                        // If $Result is null after parsing, there was an error in doing so.
                        if (Result == null)
                        {
                            Instructions = null;
                            return(ParseResult.INVALID);
                        }
                        else
                        {
                            Instructions = ResultDel(Reader).Instructions;
                            return(ParseResult.SUCCESS);
                        }
                    }
                    else
                    {
                        // If the file type cannot be inferred,
                        Instructions = null;
                        return(ParseResult.NOT_INFERRED);
                    }
                }

                // Other parse modes for forcing files to be interpreted as a particular format.
                else if (mode == ParseMode.BIN)
                {
                    Instructions = BIN.Parse(Reader).Instructions;
                    return(ParseResult.SUCCESS);
                }
                else if (mode == ParseMode.TXT)
                {
                    TXT Result = TXT.Parse(Reader);
                    // If $Result is null after parsing, there was an error in doing so.
                    if (Result == null)
                    {
                        Instructions = null;
                        return(ParseResult.INVALID);
                    }
                    else
                    {
                        Instructions = Result.Instructions;
                        return(ParseResult.SUCCESS);
                    }
                }
            }

            // This should never be reached.
            throw new System.Exception();
        }
Exemplo n.º 17
0
        private MyDebugNode CreateDebugNode(IMyExecutable executable)
        {
            MyDebugNode result;

            if (executable is MyTask)
            {
                result = new MyDebugTaskNode(executable as MyTask);
            }
            else
            {
                result = new MyDebugNode(executable);
            }

            var executableBlock = executable as MyExecutionBlock;
            if (executableBlock != null)
            {
                foreach (IMyExecutable child in executableBlock.Children)
                {
                    if (child is MySignalTask)
                    {
                        if (showSignalsButton.Checked)
                        {
                            result.Nodes.Add(CreateDebugNode(child));
                        }
                    }
                    else if (showDisabledTasksButton.Checked || child.Enabled)
                    {
                        result.Nodes.Add(CreateDebugNode(child));
                    }
                }
            }

            result.BreakpointStateChanged += OnBreakpointStateChanged;

            return result;
        }
Exemplo n.º 18
0
 private void EndMeasuring(IMyExecutable childBlock)
 {
     m_profilingStopwatch.Stop();
     ProfilingInfo[childBlock] = m_profilingStopwatch.Elapsed;
 }
Exemplo n.º 19
0
 private void EndMeasuring(IMyExecutable childBlock)
 {
     m_profilingStopwatch.Stop();
     ProfilingInfo[childBlock] = m_profilingStopwatch.Elapsed;
 }