Es ist einfach an alle relevanten Informationen zu gelangen, um die Leiterplattengröße in PCB-Investigator anzeigen lassen zu können. Der Beispielcode nutzt den IPluginWorker, um das Zeichenevent abzupassen und zwei einfache Elemente mit einer Größe im Bereich von Tausendsteln zu zeichnen.
Es werden drei Event-Handler benötigt, um alle relevanten Events abzudecken: einen Event-Handler für das Öffnen von Daten im PCB-Investigator, einen für das Schließen und einen für das Main-Event, um eine neue Grafik im Grafikterminal des PCB-Investigators zu zeichnen.
Der vollständige Code ist in unserem SDK enthalten.
/// <summary>
/// Add the relevant events.
/// </summary>
/// <param name="Parent">The main window who sends the events</param>
public void InitEvents(IPCBIWindow Parent)
{
Parent.PCBIFormGraphicPaneDrawing += new IPCBIWindow.DrawingEventHandler(Parent_PCBIFormGraphicPaneDrawing);
Parent.PCBINewJobOpend += new EventHandler(eventManager_OpenNewJob);
Parent.PCBIJobClosed += new EventHandler(eventManager_CloseJob);
}
private bool showBoardDimension = false;
/// <summary>
/// If a new job is open a question for the dimensions will be shown.
/// </summary>
void eventManager_OpenNewJob(object sender, EventArgs e)
{
showBoardDimension = false;
//hole bounds
if (MessageBox.Show("Would you aktivate the board size display?", "Show Board Size", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
showBoardDimension = true;
parent.UpdateView();
}
/// <summary>
/// If the job is closed we don't want still drawing.
/// </summary>
void eventManager_CloseJob(object sender, EventArgs e)
{
showBoardDimension = false;
parent.UpdateView();
}
/// <summary>
/// Demo for drawing a line and refs between two components and select them.
/// </summary>
/// <param name="sender">the sender is the Graphics from the main graphic pane</param>
/// <param name="e">is null</param>
void Parent_PCBIFormGraphicPaneDrawing(Graphics g, int ClientWidth, int ClientHeight)
{
if (!parent.JobIsLoaded || !showBoardDimension) return;
RectangleF BoardSize = parent.GetJobBounds();
if (BoardSize == RectangleF.Empty) return;
Point locationBoard = parent.WorldToClient(BoardSize.Location);
//Be careful with top and bottom because the display is vertical mirrored!
Point rightTopBoard = parent.WorldToClient(new PointF(BoardSize.Right, BoardSize.Bottom));
#region draw down line
g.DrawLine(Pens.Aqua, new Point(locationBoard.X, locationBoard.Y + 15), new Point(rightTopBoard.X, locationBoard.Y + 15));
g.DrawLine(Pens.Aqua, new Point(locationBoard.X, locationBoard.Y + 10), new Point(locationBoard.X, locationBoard.Y + 20));
g.DrawLine(Pens.Aqua, new Point(rightTopBoard.X, locationBoard.Y + 10), new Point(rightTopBoard.X, locationBoard.Y + 20));
#endregion
#region draw right line
g.DrawLine(Pens.Aqua, new Point(rightTopBoard.X + 15, locationBoard.Y), new Point(rightTopBoard.X + 15, rightTopBoard.Y));
g.DrawLine(Pens.Aqua, new Point(rightTopBoard.X + 10, locationBoard.Y), new Point(rightTopBoard.X + 20, locationBoard.Y));
g.DrawLine(Pens.Aqua, new Point(rightTopBoard.X + 10, rightTopBoard.Y), new Point(rightTopBoard.X + 20, rightTopBoard.Y));
#endregion
//do translate for Strings
g.TranslateTransform(1, -1);
g.DrawString(Math.Round(BoardSize.Width, 3).ToString() + " mils", new Font("Arial", 10), Brushes.Aqua, new Point((int)((locationBoard.X + rightTopBoard.X) / 2.1), locationBoard.Y + 20));
g.DrawString(Math.Round(BoardSize.Height, 3).ToString() + " mils", new Font("Arial", 10), Brushes.Aqua, new Point(rightTopBoard.X + 20, (int)((rightTopBoard.Y + locationBoard.Y) / 2)-5));
}