Friday, April 15, 2022

22-Ideal Component Classes

Following the same pattern discussed in post 21-Lumped Components, add the InPort, OutPort, and Ground classes as follows:

InPort Class

  • Create a new class in the Ideal folder called InPort.cs
  • Make it a public class that inherits from Comp
  • Add two constructors: 1 with no arguments and 1 that initializes the component parameters
  • Add the print() method
  • Add the Draw() method
  • Modify MainForm.cs by adding an InPort button handler to create the InPort

        // Let the InPort draw itself called from the canvas paint event
        public override void Draw(Graphics gr)
        {
            Point p1 = Loc;      // Assume p1 is the end of the lead at the output of Pin
            Point p2 = new Point(p1.X - leadL, p1.Y);
            Point p3 = new Point(p2.X - 10, p2.Y - 10);
            Point p4 = new Point(p3.X - 30, p3.Y);
            Point p5 = new Point(p4.X, p4.Y + 20);
            Point p6 = new Point(p5.X + 30, p5.Y);
 
            gr.DrawLine(drawPen, p1, p2);
            gr.DrawLine(drawPen, p2, p3);
            gr.DrawLine(drawPen, p3, p4);
            gr.DrawLine(drawPen, p4, p5);
            gr.DrawLine(drawPen, p5, p6);
 
            gr.DrawLine(drawPen, p6, p2);
        }

OutPort Class

  • Create a new class in the Ideal folder called OutPort.cs
  • Make it a public class that inherits from Comp
  • Add two constructors: 1 with no arguments and 1 that initializes the component parameters
  • Add the print() method
  • Add the Draw() method
  • Modify MainForm.cs by adding an OutPort button handler to create the OutPort

        // Let the InPort draw itself called from the canvas paint event
        public override void Draw(Graphics gr)
        {
            Point p1 = Loc;      // Assume p1 is the end of the lead at the output of Pin
            Point p2 = new Point(p1.X + leadL, p1.Y);
            Point p3 = new Point(p2.X + 10, p2.Y - 10);
            Point p4 = new Point(p3.X + 30, p3.Y);
            Point p5 = new Point(p4.X, p4.Y + 20);
            Point p6 = new Point(p5.X - 30, p5.Y);
 
            gr.DrawLine(drawPen, p1, p2);
            gr.DrawLine(drawPen, p2, p3);
            gr.DrawLine(drawPen, p3, p4);
            gr.DrawLine(drawPen, p4, p5);
            gr.DrawLine(drawPen, p5, p6);
            gr.DrawLine(drawPen, p6, p2);
        }

Ground Class

  • Create a new class in the Ideal folder called Ground.cs
  • Make it a public class that inherits from Comp
  • Add two constructors: 1 with no arguments and 1 that initializes the component parameters
  • Add the print() method
  • Add the Draw() method
  • Modify MainForm.cs by adding a Ground button handler to create the Ground

       // Let the Ground draw itself called from the canvas paint event
        public override void Draw(Graphics gr)
        {
            // Define the points
            Point p1 = Loc;
            Point p2 = new Point(p1.X, p1.Y + leadL);
            Point p3 = new Point(p2.X - 10, p2.Y);
            Point p4 = new Point(p2.X + 10, p2.Y);
            Point p5 = new Point(p3.X + 5, p3.Y + 5);
            Point p6 = new Point(p5.X + 10, p5.Y);
            Point p7 = new Point(p5.X + 3, p5.Y + 5);
            Point p8 = new Point(p7.X + 4, p7.Y);
 
            // Draw the input lead
            gr.DrawLine(drawPen, p1, p2);
            gr.DrawLine(drawPen, p3, p4);
            gr.DrawLine(drawPen, p5, p6);
            gr.DrawLine(drawPen, p7, p8);
        }

Run the program and create InPort, OutPort, and Ground. The source code for this post is 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...