We use own and third party cookies to improve our services and show related advertising to your preferences by analyzing your browsing habits. If you continue browsing, we consider that you accept their use. Can change the settings or get more information here

Ver sitio en español Go to homepage Contact me
viernes, 12 de mayo de 2017

Cellular automata, WinCA application IV

Once reviewed the operation of the WinCA application, dedicated to cellular automata, let's see how the source code is organized. In this article I will explain the properties of cell states, and how they can be extended to add new functionalities by implementing new classes with the corresponding interfaces.

Here you can find the first article of the series about WinCA application.

In this link you can download the WinCA application executables, and in this other one you can download the source code of the WinCA solution, written in CSharp with Visual Studio 2015.


The interfaces and classes with which the cell states properties are implemented are defined in the CommonObjects class library, in the Interfaces and Data namespaces. The IVariantValue interface is used to implement property values so that they can be used indifferently with any one of the following data types: int, double, bool, string or Color.

public interface IVariantValue
bool Mutable { get; }
int AsInt { get; set; }
double AsDouble { get; set; }
Color AsColor { get; set; }
string AsString { get; set; }
bool AsBool { get; set; }
object AsObject { get; set; }
Type NativeType { get; }
IVariantValue FromObject(object value);
IVariantValue ConvertFrom(IVariantValue value);
IVariantValue Clone();

This interface defines the following properties and functions:

  • Mutable: Returns the value true if it is allowed to change the value after the class has been created using the properties As<data type>.
  • AsInt, AsDouble, AsColor, AsString, AsBool: Get the converted value to the corresponding data type or set it from an object of the corresponding type.
  • AsObject: Gets or sets the value from a generic object value.
  • NativeType: Gets the data type with which the object was originally created.
  • FromObject: Gets a new IVariantValue object created from the object passed as a parameter. This object must be of one of the types indicated above.
  • ConvertFrom: Returns a new IVariantValue object built from that passed as a parameter, converted to the native data type of the class.
  • Clone: Returns a new IVariantValue object that is an exact copy of the current one.

This interface is implemented by the VariantValue class, in the Data namespace. It is an abstract class that serves as the basis for other classes specialized in a given value type. The idea of having these specialized classes is to optimize some of the operations without having to perform type conversions. These specialized classes are IntVariantValue, DoubleVariantValue, ColorVariantValue, StringVariantValue, and BoolVariantValue.

The properties implement the IObjectProperty interface, defined as follows:

public interface IObjectProperty
string Name { get; set; }
IVariantValue Value { get; }
Type DefaultValueType { get; set; }
IVariantValue CreateValue(object value);

Name allows you to get or set the name of the property, while Value returns its value. DefaultValueType is used to get or set the default data type, and CreateValue allows you to change the default value and type from a given object.

The properties also implement the standard interfaces IEquatable and IComparable. The property used to compare is the property name. Basically they are used to manage the lists of properties.

There are two types of properties: variables, whose value can be changed during execution of the automaton, and constants, which do not allow such a change and generate an exception if attempted. They are implemented in the Variable and Constant classes, in the Data namespace.

To manage a set of properties, you must implement the IPropertyProvider interface, defined in the Interfaces namespace:

public interface IPropertyProvider
string UID { get; }
string Name { get; set; }
IEnumerable<IObjectProperty> Properties { get; }
Type DefaultPropertyType { get; set; }
IObjectProperty GetProperty(string name);
IObjectProperty GetProperty(int index);
int IndexOf(IObjectProperty p);
int IndexOf(string name);
bool ExistsProperty(string name);
void AddProperty(IObjectProperty cons);
void AddProperties(IEnumerable<IObjectProperty> ps);
void RemoveProperty(string name);
void RemoveProperty(IObjectProperty p);
void ChangeProperty(string name, IObjectProperty p);
IObjectProperty CreateProperty(string name, object value);

The interface members are used as follows:

  • UID: Gets the unique identifier of the property set.
  • Name: Gets or sets the name of the property set.
  • Properties: Used to enumerate all the properties of the set.
  • DefaultPropertyType: Gets or sets the default data type of the new properties created by the object.
  • GetProperty: Gets a property from its name or its index within the set.
  • ExistsProperty: Returns true if the set contains a property with the given name.
  • AddProperty: Adds a new property to the set.
  • AddProperties: Adds a list of properties to the set.
  • RemoveProperty: Deletes a property from the set, identified by its name or by the property itself.
  • ChangeProperty: Change the property with the given name by a new property.
  • CreateProperty: Generates a new property with the given name and value.

There is a default implementation of this interface in the BasicPropertyProvider class, in the Data namespace.

In the WinCA application, the default property provider is defined in the configuration file, in the appSettings section, with the defaultPropertyProvider key. This class is used in the frmProperties form of the Forms namespace. This form uses the VariantValueListEditor control, defined in the Controls namespace of the WinCA application, to manage variable and constant property lists.

The frmProperties form implements the IPropertyManager interface, defined in the WinCA application Interfaces namespace as follows:

public interface IPropertyManager
event PropertyChangeEventHandler PropertyChanged;
IPropertyProvider ConstantProvider { get; set; }
IPropertyProvider VariableProvider { get; set; }
IMainForm MainForm { get; set; }

This interface allows you to link this property editor with other forms of the application, such as the states editor. The PropertyChanged event is subscribed to receive notifications when the property set changes, because properties are added or deleted, or their name or type is changed, as indicated by the Change enumeration.

Through the ConstantProvider and VariableProvider properties, you can get the IPropertyProvider objects that handle the lists of constants and variables.

Finally, MainForm allows the interaction of the form with the main form of the application, in the form of an IMainForm interface, implemented in the MainForm form and defined as follows:

public interface IMainForm
event PropertyManagerChangedEventHandler OnPropertyManagerChanged;
event StateManagerChangedEventHandler OnStateManagerChanged;
IEnumerable<IPropertyManager> PropertyManagers { get; }
IEnumerable<ICAStateManager> StateManagers { get; }
IPropertyManager CreatePropertyManager(PropertySerializationContainer pms,
string filename);
ICAStateManager CreateStateManager(StateSerializationContainer sms,
string filename);
ITransitionManager CreateTransitionManager(ICAStateManager mgr,
string filename);
ICAManager CreateCAManger(ICAStateManager mgr);
ICAManager CreateCAManger(ICANetwork ca, string filename);

This interface allows you to subscribe to the OnPropertyManagerChanged event in order to receive notifications when any of the properties are changed, and lists the IPropertyManager objects that are open at any given time with the PropertyManagers property.

The CreatePropertyManager function is used to create a new IPropertyManager object, which will be a frmProperties form, unless the implementation is modified. As a parameter you can pass null, to create an empty editor, or a PropertySerializacionContainer object to retrieve a set of properties stored in a file. It is a simple class, whose only task is to allow the serialization of the set of properties. It is defined in the Utils namespace of the WinCA application as follows:

public class PropertySerializationContainer
public PropertySerializationContainer()
public IPropertyProvider ConstantProvider { get; set; }
public IPropertyProvider VariableProvider { get; set; }

The remaining members of the interface are used with the rest of the editors and we will see them in successive articles. In the next article I will explain how the states of the automaton cells are implemented.

Share this article: Share in Twitter Share in Facebook Share in Google Plus Share in LinkedIn
Comments (0):
* (Your comment will be published after revision)





Change the CAPTCHA codeSpeak the CAPTCHA code