Friday, April 15, 2022

20-Component Base Class

In this post, we will add attributes and methods to the component base class called Comp.cs. First add the following set of attributes using the "protected" access keyword so that subclasses have access:

// Protected property variables for Property Grid
protected String _orientation = "Series";
protected String _type;
protected String _name;
protected float _value;
protected Point _loc;
protected int[] _nodes;
protected int _width;
protected int _height;

Add using System; to the C# libraries.

Property Setters & Getters

The properties will be made available in the property grid but first property setters & getters are added:

// Orientation property with category attribute and description attribute added  
[CategoryAttribute("Location Settings"), DescriptionAttribute("Orientation of the Component")]
public string Orientation
{
    get
    {
        return _orientation;
    }
    set
    {
        _orientation = value;
    }
}
 
// Location property with category attribute and description attribute added  
[CategoryAttribute("Location Settings"), DescriptionAttribute("Orientation of the Component")]
public Point Loc
{
    get
    {
        return _loc;
    }
    set
    {
        _loc = value;
    }
}
 
// Width property with category attribute and description attribute added  
[CategoryAttribute("Location Settings"), DescriptionAttribute("Orientation of the Component")]
public int Width
{
    get
    {
        return _width;
    }
    set
    {
        _width = value;
    }
}
 
// Location property with category attribute and description attribute added  
[CategoryAttribute("Location Settings"), DescriptionAttribute("Orientation of the Component")]
public int Height
{
    get
    {
        return _height;
    }
    set
    {
        _height = value;
    }
}
 
// Value property with category attribute and description attribute added  
[CategoryAttribute("Configuration Settings"), DescriptionAttribute("Configuration of the Component")]
public float Value
{
    get
    {
        return _value;
    }
    set
    {
        _value = value;
    }
}
 
// Type property with category attribute and description attribute added  
[CategoryAttribute("Configuration Settings"), DescriptionAttribute("Configuration of the Component")]
public string Type
{
    get
    {
        return _type;
    }
    set
    {
        _type = value;
    }
}
 
// Type property with category attribute and description attribute added  
[CategoryAttribute("Configuration Settings"), DescriptionAttribute("Configuration of the Component")]
public string Name
{
    get
    {
        return _name;
    }
    set
    {
        _name = value;
    }
}
 
// Type property with category attribute and description attribute added  
[CategoryAttribute("Configuration Settings"), DescriptionAttribute("Configuration of the Component")]
public int[] Nodes
{
    get
    {
        return _nodes;
    }
    set
    {
        _nodes = value;
    }
}

Add using System.ComponentModel; to the C# Library List to enable the Category and Desription Attributes. These attributes will appear in the property grid to group property types. The property grid will be used to edit the parameters of a component.

Virtual Methods

Polymophism will be used to allow components to draw themselves and to print debug messages to the output console. These methods are used in iterators such as a foreeach loop.

// Polymorphism: Virtual methods used in circuit component iteration
public virtual void print() { /* Do noting */ }
public virtual void Draw(Graphics gr) { /* Do noting */ }

Run the program to ensure that there are no errors at this point. In the next post, we will start designing the specific component classes. The source code for this post is found on GitHub.


No comments:

Post a Comment

34-Microwave Tools with Analysis (Series Final Post)

In this final blog post, I have integrated Y-Matrix analysis into the Microwave Tools project. This version has addition Lumped, Ideal, Micr...