2

all.

I'm working on a personal project to learn more about C#. This project consists of a logic diagram editor and I'm using a TreeView component to show to the user all the possible objects that can be created on a panel to draw the logic diagram.

I've been able to instantiate new objects inside the panel every time one of the options is clicked in the TreeView, but I still have to work on each logic gate drawing. Until now I have used the GraphicsPath class to define the AND and the NAND gates and everything went fine. However, I'm facing some troubles to draw the OR gate.

I'm trying to follow the IEEE standard to draw all the logic gates with the correct proportion and based on this standard, the OR gate should be drawn like below:

OR gate per IEEE Std.

However, what I was able to get is the following:

My shameful attempt to draw an OR gate

The code I wrote to get this result is (this code is part of a custom control I created):

Pen pen = new Pen(Color.Black, 2);
GraphicsPath pathOR = new GraphicsPath();
pathOR.AddArc(7 - 2 * iHeight, 0 - iHeight / 2, 2 * iHeight, 2 * iHeight, 330, 60);
pathOR.AddLine(1, 1, 16, 1);
pathOR.AddArc(17 - iHeight, 1, 2 * iHeight, 2 * iHeight, 270, 56);
pathOR.AddArc(17 - iHeight, 0 - iHeight - 4, 2 * iHeight, 2 * iHeight, 33, 56);
pathOR.AddLine(16, iHeight - 3, 1, iHeight - 3);
e.Graphics.DrawPath(pen, pathOR);

iHeight contains the object's height.The tricky part is the leftmost arc, but I've already tried many variations and nothing solved the problem. What am I doing wrong?

Thank you for any support!

Marcelo C.
  • 23
  • 7
  • Why? Use a sprite. – 3Dave Sep 26 '21 at 23:57
  • Creating an arc properly from points (and angles) can be a real pain. See [here](https://stackoverflow.com/questions/58803957/creating-an-arc-between-two-points-with-arc-radius-and-rotation). I suggest especially the last answer, that replaces the arc for a bezier curve, which is defined by its endpoints anyway and just needs a good control point.. - Note: In the end the result from AddArc will be converted to bezier curves anyway, as __GraphicsPath can't do anything but lines and beziers__ , ie the arcs and ellipses will be converted to beziers!! – TaW Sep 27 '21 at 10:15
  • The control point should be the crossing of the two tangents in the endpoints. __Much easier__ to calculate that the arc's rectangle and angles.. – TaW Sep 27 '21 at 10:18
  • Hey, @3Dave… thanks for the suggestion, but I believe I may have issues with sprites in the future. It’s on my plans implementing a zoom in/out feature and the sprite will probably lose resolution. – Marcelo C. Sep 27 '21 at 13:18
  • Hi, @TaW. Thank you for your help. I’ll take a look at the links you shared. – Marcelo C. Sep 27 '21 at 13:19

0 Answers0