Skip to content

Commit

Permalink
Enhanced plugin system and editor.
Browse files Browse the repository at this point in the history
* Enhanced plugin format in XML files, also accepting old format. A plugin can have the c# code in a separate file (*.cs), to enable debugging into visual studio. Added validation of xml format.
* Added tab size of plugin editor to program properties.
* Enhanced comments on plugin template for new plugins, and also in shipped plugins.
  • Loading branch information
gatuno1 committed Aug 24, 2020
1 parent 70e132c commit 5474027
Show file tree
Hide file tree
Showing 20 changed files with 2,313 additions and 2,148 deletions.
26 changes: 13 additions & 13 deletions Gear/GUI/Emulator.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 56 additions & 42 deletions Gear/GUI/Emulator.cs
Expand Up @@ -21,30 +21,29 @@
* --------------------------------------------------------------------------------
*/

using Gear.EmulationCore;
using Gear.PluginSupport;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using System.Xml;

using Gear.EmulationCore;
using Gear.PluginSupport;

namespace Gear.GUI
{
/// @brief View class for PropellerCPU emulator instance.
/// @details This class implements a view over a propeller emulator, with interface to control
/// the chip, like start, go through steps, reset or reload.
public partial class Emulator : System.Windows.Forms.Form
public partial class Emulator : Form
{
private PropellerCPU Chip; //!< @brief Reference to PropellerCPU running instance.
private String Source; //!< @brief Name of Binary program loaded.
private readonly PropellerCPU Chip; //!< @brief Reference to PropellerCPU running instance.
private readonly String Source; //!< @brief Name of Binary program loaded.
private String LastFileName; //!< @brief Last file name opened.
public uint stepInterval; //!< @brief How many steps to update screen.
private List<Control> FloatControls;//!< @brief List of floating controls.
private readonly List<Control> FloatControls;//!< @brief List of floating controls.

/// @brief Stopwatch to periodically rerun a step of the emulation
private Timer runTimer;
private readonly Timer runTimer;

/// @brief Default Constructor.
/// @param[in] source Binary program loaded (path & name)
Expand Down Expand Up @@ -77,13 +76,9 @@ public Emulator(string source)
}

/// @brief Get the last binary opened successfully.
///
public string GetLastBinary
{
get
{
return LastFileName;
}
get { return LastFileName; }
}

/// @brief Make a stop on the emulation.
Expand All @@ -101,7 +96,7 @@ public void BreakPoint()
/// @param[in] plugin Instance of a Gear.PluginSupport.PluginBase class to be attached.
private void AttachPlugin(PluginBase plugin)
{
Chip.IncludePlugin(plugin); //include into plugin lists of a PropellerCPU instance
Chip.IncludePlugin(plugin); //include into plugin lists of a PropellerCPU instance
plugin.PresentChip(); //invoke initial setup of plugin.

TabPage t = new TabPage(plugin.Title);
Expand All @@ -110,10 +105,7 @@ private void AttachPlugin(PluginBase plugin)
plugin.Parent = t;
documentsTab.SelectedTab = t;
//Maintain the close button availability
if (plugin.IsClosable)
closeButton.Enabled = true;
else
closeButton.Enabled = false;
closeButton.Enabled = plugin.IsClosable;
}

/// @brief Delete a plugin from a propeller chip instance.
Expand Down Expand Up @@ -199,36 +191,58 @@ public PluginBase LoadPlugin(string FileName)
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreComments = true;
settings.IgnoreProcessingInstructions = true;
settings.IgnoreWhitespace = true;
settings.IgnoreWhitespace = true;
settings.DtdProcessing = DtdProcessing.Parse;
settings.ValidationType = ValidationType.DTD;
XmlReader tr = XmlReader.Create(FileName, settings);
bool ReadText = false;

List<string> references = new List<string>();
string instanceName = string.Empty;
string code = string.Empty;
string code = string.Empty;
string codeFileName = string.Empty;
string pluginVersion = "0.1";

try
{

while (tr.Read())
{
if (tr.NodeType == XmlNodeType.Text && ReadText)
{
code = tr.Value;
if (ReadText)
{
if (string.IsNullOrEmpty(codeFileName))
{
//Mantain compatibility with old plugins (using Text section)
if (tr.NodeType == XmlNodeType.Text ||
tr.NodeType == XmlNodeType.CDATA)
code = tr.Value;
}
else
{
codeFileName =
Path.Combine(Path.GetDirectoryName(FileName), codeFileName);
code = File.ReadAllText(codeFileName);
}
ReadText = false;
}

switch (tr.Name.ToLower())
{
{
case "plugin":
pluginVersion =
string.IsNullOrEmpty(tr.GetAttribute("version")) ?
pluginVersion :
tr.GetAttribute("version");
break;
case "reference":
if (!tr.IsEmptyElement) //prevent empty element generates error
if (!tr.IsEmptyElement)
references.Add(tr.GetAttribute("name"));
break;
case "instance":
instanceName = tr.GetAttribute("class");
break;
case "code":
ReadText = true;
ReadText = true;
codeFileName = tr.GetAttribute("codeFileName");
break;
}
}
Expand Down Expand Up @@ -287,7 +301,7 @@ public PluginBase LoadPlugin(string FileName)
/// @brief Select binary propeller image to load.
/// @param[in] sender Reference to object where event was raised.
/// @param[in] e Event data arguments.
private void openBinary_Click(object sender, EventArgs e)
private void OpenBinary_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Propeller Runtime Image (*.binary;*.eeprom)|*.binary;" +
Expand All @@ -303,7 +317,7 @@ private void openBinary_Click(object sender, EventArgs e)
/// @details It also reset the %Propeller Chip and all the plugins.
/// @param[in] sender Reference to object where event was raised.
/// @param[in] e Event data arguments.
private void reloadBinary_Click(object sender, EventArgs e)
private void ReloadBinary_Click(object sender, EventArgs e)
{
OpenFile(LastFileName);
Chip.Reset();
Expand Down Expand Up @@ -342,7 +356,7 @@ private void RepaintViews()
/// @brief Event to reset the whole %Propeller Chip.
/// @param[in] sender Reference to object where event was raised.
/// @param[in] e Event data arguments.
private void resetEmulator_Click(object sender, EventArgs e)
private void ResetEmulator_Click(object sender, EventArgs e)
{
Chip.Reset();
RepaintViews();
Expand All @@ -351,7 +365,7 @@ private void resetEmulator_Click(object sender, EventArgs e)
/// @brief Run only one instruction of the active cog, stopping after executed.
/// @param[in] sender Reference to object where event was raised.
/// @param[in] e Event data arguments.
private void stepEmulator_Click(object sender, EventArgs e)
private void StepEmulator_Click(object sender, EventArgs e)
{
Chip.Step();
RepaintViews();
Expand All @@ -362,7 +376,7 @@ private void stepEmulator_Click(object sender, EventArgs e)
/// what uses it.
/// @param[in] sender Reference to object where event was raised.
/// @param[in] e Event data arguments.
private void closeActiveTab_Click(object sender, EventArgs e)
private void CloseActiveTab_Click(object sender, EventArgs e)
{
TabPage tp = documentsTab.SelectedTab;
PluginBase p = (PluginBase)tp.Controls[0];
Expand All @@ -376,7 +390,7 @@ private void closeActiveTab_Click(object sender, EventArgs e)
//select the previous tab
documentsTab.SelectedIndex = documentsTab.SelectedIndex - 1;
//tab changing housekeeping for plugin close button
documentsTab_Click(this, e);
DocumentsTab_Click(this, e);
//detach the plugin from the emulator
this.DetachPlugin(p);
p.Dispose();
Expand All @@ -388,7 +402,7 @@ private void closeActiveTab_Click(object sender, EventArgs e)

/// @todo Document Gear.GUI.Emulator.floatActiveTab_Click()
///
private void floatActiveTab_Click(object sender, EventArgs e)
private void FloatActiveTab_Click(object sender, EventArgs e)
{
TabPage tp = documentsTab.SelectedTab;
tp.Parent = null;
Expand All @@ -409,7 +423,7 @@ private void floatActiveTab_Click(object sender, EventArgs e)

/// @todo Document Gear.GUI.Emulator.pinActiveTab_Click()
///
private void pinActiveTab_Click(object sender, EventArgs e)
private void PinActiveTab_Click(object sender, EventArgs e)
{
Control oldPin = pinnedPanel.GetNextControl(null, true);

Expand All @@ -434,7 +448,7 @@ private void pinActiveTab_Click(object sender, EventArgs e)

/// @todo Document Gear.GUI.Emulator.unpinButton_Click()
///
private void unpinButton_Click(object sender, EventArgs e)
private void UnpinButton_Click(object sender, EventArgs e)
{
Control oldPin = pinnedPanel.GetNextControl(null, true);

Expand All @@ -452,7 +466,7 @@ private void unpinButton_Click(object sender, EventArgs e)
/// @brief Event to run the emulator freely.
/// @param[in] sender Reference to the object where this event was called.
/// @param[in] e Class with the details event.
private void runEmulator_Click(object sender, EventArgs e)
private void RunEmulator_Click(object sender, EventArgs e)
{
runTimer.Start();
}
Expand All @@ -461,7 +475,7 @@ private void runEmulator_Click(object sender, EventArgs e)
/// @version V15.03.26 - Added the refresh of the screen.
/// @param[in] sender Reference to the object where this event was called.
/// @param[in] e Class with the details event.
private void stopEmulator_Click(object sender, EventArgs e)
private void StopEmulator_Click(object sender, EventArgs e)
{
runTimer.Stop();
RepaintViews(); //added the repaint, to refresh the views
Expand All @@ -470,7 +484,7 @@ private void stopEmulator_Click(object sender, EventArgs e)
/// @brief Event to run one instruction in emulator.
/// @param[in] sender Reference to the object where this event was called.
/// @param[in] e Class with the details event.
private void stepInstruction_Click(object sender, EventArgs e)
private void StepInstruction_Click(object sender, EventArgs e)
{
if (documentsTab.SelectedTab != null)
{
Expand Down Expand Up @@ -529,7 +543,7 @@ private void OnDeactivate(object sender, EventArgs e)
/// @param[in] sender Reference to object where event was raised.
/// @param[in] e Event data arguments.
/// @since V14.07.03 - Added.
private void documentsTab_Click(object sender, EventArgs e)
private void DocumentsTab_Click(object sender, EventArgs e)
{
TabPage tp = documentsTab.SelectedTab;
if (tp.Controls[0] is PluginBase)
Expand All @@ -550,7 +564,7 @@ private void documentsTab_Click(object sender, EventArgs e)

/// @todo Document Gear.GUI.Emulator.documentsTab_KeyPress()
///
private void documentsTab_KeyPress(object sender, KeyPressEventArgs e)
private void DocumentsTab_KeyPress(object sender, KeyPressEventArgs e)
{
if (ActiveControl is PluginBase)
{
Expand All @@ -563,7 +577,7 @@ private void documentsTab_KeyPress(object sender, KeyPressEventArgs e)
if (runTimer.Enabled)
runTimer.Stop();
else
stepInstruction_Click(sender, e);
StepInstruction_Click(sender, e);
}
if ((e.KeyChar == 'r') | (e.KeyChar == 'R'))
{
Expand Down

0 comments on commit 5474027

Please sign in to comment.