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
No comments:
Post a Comment