private void DrawKsiBlock(Graphics graphics, Point point, SubMachineBlock block) { graphics.DrawPath(block.KsiBlockPen, block.Ksi.ToRoundedRect(KsiBlockRadius)); Point center = new Point(block.Ksi.X + block.Ksi.Width / 2, block.Ksi.Y + block.Ksi.Height / 2); graphics.DrawString("ѱ" + block.KeyName, Font, BlockBrush, center.X - ((int)((block.FSMInfo.KeyName.Length + 1) * 0.8 * Font.Size)) / 2, center.Y - Font.Size); }
private void DrawArrowsBetweenBlocks(Graphics graphics, SubMachineBlock firstBlock, SubMachineBlock secondBlock) { graphics.DrawArrow(firstBlock.ArrowPen, firstBlock.RightConnector, secondBlock.LeftConnector, ArrowheadLength, ArrowheadAngle); }
private void DrawOutputArrows(Graphics graphics, SubMachineBlock block) { var dY = (block.No + 1) * 10; var pt = new Point(block.RightConnector.X + SubFSMBlockSpace / 3, block.RightConnector.Y + SubFSMBlockSpace + dY); graphics.DrawArrow(block.ArrowPen, pt.X, pt.Y, GBlock.X, pt.Y, ArrowheadLength, ArrowheadAngle); }
private void DrawSubMachine(Graphics graphics, Point point, SubMachineBlock block) { DrawSubFSMBlock(graphics, point, block); DrawFBlock(graphics, point, block); DrawKsiBlock(graphics, point, block); DrawArrows(graphics, point, block); //graphics.DrawRectangle(BlockPen, block.BoundRect); }
private void DrawArrows(Graphics graphics, Point point, SubMachineBlock block) { graphics.DrawArrow(block.ArrowPen, block.F.X + block.F.Width, block.F.Y + block.F.Height / 2, block.FSMBlock.X, block.FSMBlock.Y + block.FSMBlock.Height / 2, ArrowheadLength, ArrowheadAngle); graphics.DrawArrow(block.ArrowPen, block.Ksi.X + block.Ksi.Width / 2, block.Ksi.Y + block.Ksi.Height, block.FSMBlock.X + block.FSMBlock.Width / 2, block.FSMBlock.Y, ArrowheadLength, ArrowheadAngle); }
private void DrawBoundArrows(Graphics graphics, SubMachineBlock firstBlock, SubMachineBlock lastBlock) { //graphics.DrawArrow(BlockPen, // firstBlock.LeftConnector.X - SubFSMBlockSpace, // firstBlock.LeftConnector.Y, // firstBlock.LeftConnector.X, // firstBlock.LeftConnector.Y, // ArrowheadLength, // ArrowheadAngle); graphics.DrawArrow(lastBlock.ArrowPen, lastBlock.RightConnector.X, lastBlock.RightConnector.Y, GBlock.X, GBlock.Y + GBlockHeigth / 2, ArrowheadLength, ArrowheadAngle); }
private void DrawSubFSMBlock(Graphics graphics, Point point, SubMachineBlock block) { graphics.DrawPath(block.FSMBlockPen, block.FSMBlock.ToRoundedRect(SubFSMBlockRadius)); graphics.DrawString("П/автомат " + block.FSMInfo.KeyName, Font, BlockBrush, point.X - ((int)((block.FSMInfo.KeyName.Length + 10) * 0.8 * Font.Size)) / 2, point.Y - Font.Size); }
private void DrawConnectionArrows(Graphics graphics, SubMachineBlock block, IEnumerable <SubMachineBlock> destinationBlocks) { var dY = (block.No + 1) * 10; var dX = (block.No - 1) * 10; var pt = new Point(block.RightConnector.X + SubFSMBlockSpace / 3, block.RightConnector.Y + SubFSMBlockSpace + dY); DrawPoint(graphics, BlockBrush, pt.X, block.RightConnector.Y); graphics.DrawLine(block.ArrowPen, pt.X, block.RightConnector.Y, pt.X, pt.Y); int minDestNo = destinationBlocks.Min(b => b.No); if (block.No > minDestNo) { if (block.No < SubMachineBlocks.Count - 1) { DrawPoint(graphics, BlockBrush, pt); } var firstBlock = destinationBlocks.First(b => b.No == minDestNo); graphics.DrawLine(block.ArrowPen, pt.X, pt.Y, firstBlock.LeftConnector.X - SubFSMBlockSpace / 2 + dX, pt.Y ); } int maxDestNo = destinationBlocks.Max(b => b.No); if (block.No < maxDestNo - 1) { var lastBlock = destinationBlocks.First(b => b.No == maxDestNo); graphics.DrawLine(block.ArrowPen, pt.X, pt.Y, lastBlock.LeftConnector.X - SubFSMBlockSpace / 2 + dX, pt.Y ); } foreach (var destinationBlock in destinationBlocks) { if (destinationBlock.No != block.No + 1) { if (destinationBlock.No > 0) { DrawPoint(graphics, BlockBrush, destinationBlock.LeftConnector.X - SubFSMBlockSpace / 2 + dX, pt.Y); } graphics.DrawLine(block.ArrowPen, destinationBlock.LeftConnector.X - SubFSMBlockSpace / 2 + dX, pt.Y, destinationBlock.LeftConnector.X - SubFSMBlockSpace / 2 + dX, destinationBlock.LeftConnector.Y + dY ); graphics.DrawArrow(block.ArrowPen, destinationBlock.LeftConnector.X - SubFSMBlockSpace / 2 + dX, destinationBlock.LeftConnector.Y + dY, destinationBlock.LeftConnector.X, destinationBlock.LeftConnector.Y + dY, ArrowheadLength, ArrowheadAngle ); } } }
protected override void OnPaint(PaintEventArgs e) { var old = e.Graphics.SmoothingMode; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;// AntiAlias; if (LogicComponent != null) { var size = CalcSize(); if (Size.Width > 0 && Size.Height > 0) { double widthRatio = (double)size.Width / Size.Width; double heigthRatio = (double)size.Height / Size.Height; double k = cnstRatio / Math.Max(widthRatio, heigthRatio); unit = (int)(unit * k); size = CalcSize(); } InputPoint = new Point((Size.Width - size.Width) / 2, (Size.Height - size.Height) / 2); Point pt = new Point(InputPoint.X + SubFSMBlockSpace * 4, InputPoint.Y + SubFSMBlockSpace * 2 + SubFSMBlockHeight / 2 + KsiBlockHeigth); //SubMachineBlocks.Clear(); foreach (var block in SubMachineBlocks.Values) { block.Exists = false; } int index = 0; foreach (var fsmInfo in LogicComponent.Components) { if (index > 0) { pt.X += SubFSMBlockSpace * 3 + SubFSMBlockWidth; } SubMachineBlock block = null; if (SubMachineBlocks.ContainsKey(fsmInfo.KeyName)) { block = SubMachineBlocks[fsmInfo.KeyName]; block.SolveCoords(pt); block.Exists = true; } else { block = new SubMachineBlock(index, this, pt, fsmInfo); block.Exists = true; SubMachineBlocks.Add(block.KeyName, block); } DrawSubMachine(e.Graphics, pt, block); ++index; } foreach (var blockKeyToDelete in SubMachineBlocks.Where(b => !b.Value.Exists).Select(b => b.Key).ToArray()) { SubMachineBlocks.Remove(blockKeyToDelete); } var pointG = new Point(pt.X + SubFSMBlockWidth / 2 + SubFSMBlockSpace * 2, pt.Y); DrawGBlock(e.Graphics, pointG); DrawOutputArrow(e.Graphics); DrawBoundArrows(e.Graphics, SubMachineBlocks.Values.First(), SubMachineBlocks.Values.Last()); DrawInputArrows(e.Graphics, InputPoint); for (int i = 0; i < SubMachineBlocks.Count; ++i) { if (i + 1 < SubMachineBlocks.Count) { DrawArrowsBetweenBlocks(e.Graphics, SubMachineBlocks.Values.ElementAt(i), SubMachineBlocks.Values.ElementAt(i + 1)); } } foreach (var block in SubMachineBlocks.Values) { DrawConnectionArrows(e.Graphics, block, SubMachineBlocks.Values.Except(new[] { block })); } foreach (var block in SubMachineBlocks.Values.Take(SubMachineBlocks.Count - 1)) { DrawOutputArrows(e.Graphics, block); } if (!flag) { flag = true; Invalidate(); } } e.Graphics.SmoothingMode = old; }