OTX-Runtime for DotNet  
Assembly-Screen Implementation

An Assembly-Screen implementation is a DotNet class that is marked as a screen by special attributes, see table below. The attributes show the OTX Runtime which public methods, properties or events are used to open a screen or set a parameter. The screen can be implemented with an arbitrary complexity within the class, e.g. in WPF.

Note: The Assembly-Screen Implementation is the default implementation of ICustomScreenImplementation (see DefaultCustomScreenImplementation) delivered with the OTX runtime API.

The AssemblyScreen implementation supports the following DotNet window types for screens:

The AssemblyScreen implementation supports the following OTX data types:

  • All simple data types (Boolean, Integer, Float, String)
  • ByteField
  • BlackBox
  • List which contains one of the listed data type in an arbitrary depth
  • Map which contains the listed data types in an arbitrary depth
  • Structure which contains the listed data types in an arbitrary depth
  • Enumeration
  • ResourceLocation

Assembly Screen Attributes

The following table lists all supported attributes. The attributes are only a marker, that the mapping can find the right elements. You can create the attributes by yourself or you can use the file Attributes.cs inside the sample project above.

Attribute Description
[OtxScreenSignature] Class containing the screen. There can be several classes.
[OtxScreenSignatureTermParameter] Write property that sets the value of a ScreenSignatureTermParameter
[OtxScreenSignatureInParameter] Write property that sets the value of a ScreenSignatureInParameter
[OtxScreenSignatureOutParameter] Read property, which reads out the value of a ScreenSignatureOutParameter
[OtxScreenSignatureInOutParameter] Read and write property that reads or sets the value of a ScreenSignatureInOutParameter
[OtxScreenIsOpen] Reading property, which checks if the screen is open
[OtxOpenScreen] Method in which the screen is generated (returns a form object of this screen)
[OtxCloseScreen] Method in which closes the screen
[OtxHighlightScreen] Method in which the screen comes to the foreground
[OtxScreenSignatureParameterValueChangedEvent] Event that the OTX Runtime signals that a parameter has changed in the screen
[OtxStructure] Class describing an OTX structure
[OtxStructureElement] Read and write property within the class that describes an element of the structure
[Description] Optional description for display in the OTX Mapping Editor (from System.ComponentModel)

Assembly Screen Code Example

The example shows the C# code of an assembly screen implementation. The full code is inside this Sample OTX-Mapping PTX with including Visual Studio Project, see folder Apps/OtxMappingSample.

Sample OTX-Mapping PTX

Another OTF Sample Solution for OTX-Mapping with Player (source code see folder \EmotiveSampleSolution\OtxMappingSample\OTX-Mapping)

Note: The assembly (APP) must be copied into ExternalAppPath.

To see the complete example click here to fold.

// C# complete example for an assembly screen implementation
// =========================================================
using OtxMappingSample.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
namespace OtxMappingSample
{
[OtxScreenSignature]
public class Screen1
{
#region fields
private string inputText;
private bool checkedBox = false;
private static int count = 0;
private string buttonText;
private Screen1Form displayWindow;
private MyStructure myStructure = new MyStructure();
private MainColors mainColor = MainColors.None;
public delegate void ScreenSignatureParameterValueChangedEventHandler(string propertyName, object value);
#endregion
#region ctors
public Screen1()
{
}
#endregion
#region screen methods
[OtxScreenSignatureParameterValueChangedEvent]
public event ScreenSignatureParameterValueChangedEventHandler ScreenSignatureParameterValueChangedEvent;
[OtxOpenScreen]
public Form OpenScreen()
{
if (displayWindow == null)
{
displayWindow = new Screen1Form();
displayWindow.Closed += DiplayWindow_Closed;
displayWindow.textBoxTest.TextChanged += new EventHandler(textBoxText_TextChanged);
displayWindow.checkBoxTest.CheckedChanged += new EventHandler(checkBox_CheckedChanged);
displayWindow.buttonClick.Click += new EventHandler(buttonClick_Click);
displayWindow.buttonClose.Click += new EventHandler(buttonClose_Click);
displayWindow.comboBoxEnum.SelectedIndexChanged += ComboBoxEnum_SelectedIndexChanged;
displayWindow.buttonChangeStructure.Click += ButtonChangeStructure_Click;
}
return displayWindow;
}
[OtxCloseScreen]
public void CloseScreen()
{
if (displayWindow != null)
{
displayWindow.Closed -= DiplayWindow_Closed;
displayWindow.Close();
displayWindow = null;
}
}
[OtxHighlightScreen]
public void HighlightScreen()
{
if (displayWindow != null)
{
displayWindow.Activate();
}
}
[OtxScreenIsOpen]
public bool ScreenIsOpen
{
get { return displayWindow != null; }
}
#endregion
#region screen parameters
[OtxScreenSignatureInParameter]
[Description("The screen title")]
public string Title
{
set
{
if (displayWindow == null)
{
return;
}
displayWindow.labelTitle.Text = value;
}
}
[OtxScreenSignatureInOutParameter]
[Description("The input text")]
public string Text
{
get
{
return this.inputText;
}
set
{
this.inputText = value;
this.displayWindow.textBoxTest.Text = value;
}
}
[OtxScreenSignatureOutParameter]
[Description("The input text")]
public bool Checked
{
get
{
return this.checkedBox;
}
}
[OtxScreenSignatureOutParameter]
[Description("The input text")]
public string ButtonText
{
get
{
return this.buttonText;
}
}
[OtxScreenSignatureInOutParameter]
[Description("Also OTX-Structure can be mapped")]
public MyStructure MyStructure
{
get
{
this.myStructure.IntegerElement++;
return this.myStructure;
}
set
{
this.myStructure = value;
displayWindow.textBoxStructure.Text = "StringElement1 = " + value.StringElement.ToString() +
"\r\nIntegerElement = " + value.IntegerElement.ToString() +
"\r\nByteFieldElement = " + ByteArrayToString(value.ByteFieldElement) +
"\r\nListElement = " + ListToString(value.ListElement) +
"\r\nMapElement = " + MapToString(value.MapElement) +
"\r\nEnumElement = " + value.EnumElement.ToString();
}
}
[OtxScreenSignatureInOutParameter]
[Description("Also OTX-Enumeration can be mapped")]
public MainColors MainColor
{
get
{
return this.mainColor;
}
set
{
this.mainColor = value;
displayWindow.comboBoxEnum.Text = value.ToString();
}
}
#endregion
#region helper
private string ByteArrayToString(byte[] byteArray)
{
return "0x" + BitConverter.ToString(byteArray).Replace("-", "");
}
private string ListToString(List<int> list)
{
return "{ " + String.Join<int>(", ", list) + " }";
}
private string MapToString(Dictionary<string, string> map)
{
return "{ " + String.Join(", ", map.Select(x => x.Key + " : " + x.Value).ToArray()) + " }";
}
private void buttonClose_Click(object sender, EventArgs e)
{
this.CloseScreen();
}
private void buttonClick_Click(object sender, EventArgs e)
{
count++;
this.buttonText = displayWindow.buttonClick.Text + " " + count;
if (ScreenSignatureParameterValueChangedEvent != null)
{
ScreenSignatureParameterValueChangedEvent("ButtonText", this.buttonText);
}
}
private void checkBox_CheckedChanged(object sender, EventArgs e)
{
this.checkedBox = displayWindow.checkBoxTest.Checked;
if (ScreenSignatureParameterValueChangedEvent != null)
{
ScreenSignatureParameterValueChangedEvent("Checked", this.checkedBox);
}
}
private void textBoxText_TextChanged(object sender, EventArgs e)
{
this.inputText = displayWindow.textBoxTest.Text;
if (ScreenSignatureParameterValueChangedEvent != null)
{
ScreenSignatureParameterValueChangedEvent("Text", this.inputText);
}
}
private void ButtonChangeStructure_Click(object sender, EventArgs e)
{
if (ScreenSignatureParameterValueChangedEvent != null)
{
ScreenSignatureParameterValueChangedEvent("MyStructure", this.MyStructure);
}
}
private void ComboBoxEnum_SelectedIndexChanged(object sender, EventArgs e)
{
if (!Enum.TryParse(displayWindow.comboBoxEnum.Text, true, out this.mainColor))
{
this.mainColor = MainColors.None;
}
if (ScreenSignatureParameterValueChangedEvent != null)
{
ScreenSignatureParameterValueChangedEvent("MainColor", this.mainColor);
}
}
private void DiplayWindow_Closed(object sender, EventArgs e)
{
CloseScreen();
}
#endregion
#region enums
public enum MainColors
{
Red,
Green,
Blue
}
#endregion
#region classes
[OtxStructure]
public class MyStructure
{
private string stringElement = "Hello World";
private int integerElement = 12;
private byte[] byteFieldElement = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
private List<int> listElement = new List<int> { 1, 2, 34 };
private Dictionary<string, string> mapElement = new Dictionary<string, string>() { { "1", "a" }, { "2", "b" } };
private MainColors enumElement = MainColors.Green;
[OtxStructureElement]
public string StringElement
{
get { return stringElement; }
set { stringElement = value; }
}
[OtxStructureElement]
public int IntegerElement
{
get { return integerElement; }
set { integerElement = value; }
}
[OtxStructureElement]
public byte[] ByteFieldElement
{
get { return byteFieldElement; }
set { byteFieldElement = value; }
}
[OtxStructureElement]
public List<int> ListElement
{
get { return listElement; }
set { listElement = value; }
}
[OtxStructureElement]
public Dictionary<string, string> MapElement
{
get { return mapElement; }
set { mapElement = value; }
}
[OtxStructureElement]
public MainColors EnumElement
{
get { return enumElement; }
set { enumElement = value; }
}
}
#endregion
#region attributes
[AttributeUsage(AttributeTargets.Method)]
internal class OtxCloseScreen : Attribute
{
}
[AttributeUsage(AttributeTargets.Method)]
internal class OtxHighlightScreen : Attribute
{
}
[AttributeUsage(AttributeTargets.Method)]
internal class OtxOpenScreen : Attribute
{
}
[AttributeUsage(AttributeTargets.Property)]
internal class OtxScreenIsOpen : Attribute
{
}
[AttributeUsage(AttributeTargets.Class)]
internal class OtxScreenSignature : Attribute
{
}
[AttributeUsage(AttributeTargets.Property)]
internal class OtxScreenSignatureInOutParameter : Attribute
{
}
[AttributeUsage(AttributeTargets.Property)]
internal class OtxScreenSignatureInParameter : Attribute
{
}
[AttributeUsage(AttributeTargets.Property)]
internal class OtxScreenSignatureOutParameter : Attribute
{
}
[AttributeUsage(AttributeTargets.Property)]
internal class OtxScreenSignatureTermParameter : Attribute
{
}
[AttributeUsage(AttributeTargets.Event)]
internal class OtxScreenSignatureParameterValueChangedEvent : Attribute
{
}
[AttributeUsage(AttributeTargets.Class)]
internal class OtxStructure : Attribute
{
}
[AttributeUsage(AttributeTargets.Property)]
internal class OtxStructureElement : Attribute
{
}
#endregion
}
}
@ None
The connection state will be ignored (default)

// C# short example for an assembly screen implementation for DotNet Forms
// =======================================================================
namespace OtxMappingSample
{
[OtxScreenSignature]
public class Screen1
{
[OtxScreenSignatureParameterValueChangedEvent]
public event ScreenSignatureParameterValueChangedEventHandler ScreenSignatureParameterValueChangedEvent;
[OtxOpenScreen]
public System.Windows.Forms.Form OpenScreen() // Other window types are also supported, e.g. System.Windows.Window
{
if (displayWindow == null)
{
displayWindow = new Screen1Form();
// ...
}
return displayWindow;
}
[OtxScreenSignatureInParameter]
[Description("The screen title")]
public string Title
{
// ...
}
}
}

Note: The method indicated by the OpenScreen attribute can return NULL.