How to display the board size

Its very simple to get the relevant information to display the board size in PCB-Investigator. The example code uses an IPluginWorker to wait for the drawing event and draw two simple elements with the size in mils.

There are three EventHandler needed to handle all relevant events, one for opening data in PCB-Investigator, one for closing the data and the main event for drawing a new image in the graphic pane of PCB-Investigator.

The complete code is included in our SDK, you can download it under here

/// <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));
 
    }