AssemblyInfo class
The AssemblyInfo class is the base class (deriving from EntityInfo) used to manage all data of an Assembly object that needs to be saved. Each constructor of an Assembly class contains an AssemblyInfo object as argument. If the AssemblyInfo class doesn’t contain all necessary fields to restore an assembly then a new class is used that derives from AssemblyInfo. The developer just has to add new public fields to that info class so that this data can be retrieved by the matching assembly constructor.
When saving the model Experior will serialize all AssemblyInfo objects into an Assemblies.XML file and compress it into the Experior model file.
When loading the model the process is reversed: Experior unzips the model file and de-serializes the Assemblies.XML file. Each newly created AssemblyInfo object is passed into the constructor of the matching Assembly class (which is derived from the fullname field).
Due to the nature and purpose of the AssemblyInfo objects they have an empty constructor and most fields are public.
When selecting an icon of the assembly in the catalog window then some class-properties are shown. They contain default values that will be used to create the new Assembly when you drag it onto the working area. By changing those default property values subsequent assemblies will be created with those new values.
Below is described some common fields of each AssemblyInfo object and explain mechanism of storing default properties and illustrate it with an example.
Main fields:
public string name: The saved name of the corresponding assembly
public string fullname: The saved fully qualifying class name of the corresponding assembly
public string section: The saved section name of the corresponding assembly
public Vector3 position: The saved global position of the corresponding assembly
public Matrix orientation: The saved orientation matrix of the corresponding assembly
public Vector3 localposition: The saved local position of the corresponding assembly related to its parent assembly
public Matrix localorientation: The saved local orientation matrix of the corresponding assembly related to its parent assembly
public object userdata: The saved custom user data of the corresponding assembly
public bool visible: The saved visibility state of the corresponding assembly
public bool locked: The saved locked state of the corresponding assembly
public float length: The saved length of the corresponding assembly
public float width: The saved width of the corresponding assembly
public float height: The saved height of the corresponding assembly
Storing default property values:
As mentioned above Experior supports a mechanism to modify the default properties that a used to create new assemblies. These default values are saved by Experior so that they can be retrieved even after Experior is closed and started again.
To allow a user to change the default value the AssemblyInfo class contains a GetProperty and SetProperty methods:
public string GetProperty(string tag): This method allows to retrieve the saved value of the property with as name the given tag. The value is returned as string.
public void SetProperty(string tag, object value): This method allows to save the value of the property with as name the given tag. Note that the value will be saved as a string.
Below is an example of its usage.
Suppose the assembly that we are creating has a property MinHeight. We want to store this for each assembly and therefore add a public field float MinHeight to the corresponding AssemblyInfo class.
public class MyAssemblyInfo : AssemblyInfo
{
private static MyAssemblyInfo properties = new MyAssemblyInfo();
public float minHeight=0.2f;
public static object Properties // used for showing default properties in property window when selecting icon of assembly in catalog window
{
get
{
properties.color = Experior.Core.Environment.Scene.DefaultColor;
return properties;
}
}
}
So by default the MinHeight value is 200 mm.
When we want to allow a user to change this default value and add this as a class property the following code can be added to the corresponding AssemblyInfo class:
[XmlIgnore]// to make sure that the MinHeight property is not serialised for each assembly
[CategoryAttribute("Size")]
[Description("Minimum Height in mm")]
[TypeConverter(typeof(FloatConverter))]
[PropertyOrder(0)]
public virtual float MinHeight
{
get
{
string value = GetProperty("MinHeight"); //retrieve the MinHeight property
if (value == string.Empty) // property has not been stored yet
minHeight = 0.3f;
else
minHeight = float.Parse(value); // assign the new value to the minHeight field
return minHeight;
}
set
{
minHeight = value;
SetProperty("MinHeight", value); // store the property
}
}
When a user selects the icon of the assembly in the catalog window then the selected method of the catalog is called.
public override object Selected(string title, string subtitle)
{
if (title == "MyAssemblyClass")
return MyAssemblyInfo.Properties;
else ...
}
As shown above this typically returns a static info object of the corresponding class which is used to display the default properties in the property window:
When changing the MinHeight value in the property window the setter of the MinHeight code shown above is executed and this causes to save the new value with the SetProperty method but also to modify the MinHeight field of the current info object. This info object is passed to the constructor of the matching Assembly class and hence the new value will be taken into account.