Der vollständige Code ist in unserem SDK enthalten.

Dieses Beispiel demonstriert das Hinzufügen einer zusätzlichen Toolbar, falls Sie einen weiteren Button für das Ribbon-Menü benötigen, verwenden Sie bitte die im SDK enthaltene Klasse „PluginMenuItemDemo.cs“. Dort finden Sie diverse Beispiele zur Verwendung des IPluginRibbonCommand Interface.

using System;
using System.Collections.Generic;
using System.Text;
using PCBI.Plugin;
using PCBI.Plugin.Interfaces;
using System.Windows.Forms;
using System.Drawing;
using PCBI.Automation;
 
namespace PluginDemo
{
 
  [Plugin("PluginToolBarDemo", "FG", "PluginToolBarDemo shows two demo-actions for change the display in PCB-Investigator.", "1.0.0.0")]
  public class PluginToolBarDemo : ToolStrip, IPluginToolStrip
  {
    #region IPluginToolStrip Members
    //On which position should the toolbar dock.
    private ContainerPosition position = ContainerPosition.Left;
    public ContainerPosition Position
    {
      get
      {
        return position;
      }
      set
      {
        position = value;
      }
    }
    #endregion
 
    #region IPlugin Members
    //interface information
    private bool pluginEnabled;
    public bool PluginEnabled
    {
      get
      {
        return pluginEnabled;
      }
      set
      {
        pluginEnabled = value;
      }
    }
    private string assembly;
    public string Assembly
    {
      get
      {
        return assembly;
      }
      set
      {
        assembly = value;
      }
    }
    private string path;
    public string Path
    {
      get
      {
        return path;
      }
      set
      {
        path = Path;
      }
    }
    private Type type;
    public Type Type
    {
      get
      {
        return type;
      }
      set
      {
        type = value;
      }
    }
    IPCBIWindow parent;
    public IPCBIWindow Parent
    {
      get
      {
        return parent;
      }
      set
      {
        parent = value;
      }
    }
    private PluginDestinationWindow pluginDestination = PluginDestinationWindow.MainWindow;
    public PluginDestinationWindow PluginDestination
    {
      get
      {
        return pluginDestination;
      }
      set
      {
        pluginDestination = value;
      }
    }
    public bool IsActionAllowed(ID_ActionItem action)
    {
      return false;
    }
    public void InitEvents(IPCBIWindow Parent)
    {
    }
    #endregion
 
    #region Konstruktor
    public PluginToolBarDemo()
    {
 
      this.BackColor = Color.Red; //for the demo we want to highlight the tool bar
      this.Items.Add("Top View");
      this.Items[0].Click += new EventHandler(PluginToolBarDemoTopView_Click);
      position = ContainerPosition.Top;
      this.Items.Add("Bot View");
      this.Items[1].Click += new EventHandler(PluginToolBarDemoBotView_Click);
    }
    #endregion
 
    #region ToolBarClicks
    private void PluginToolBarDemoBotView_Click(object sender, EventArgs e)
    {
      //activate signal-bot, component-bot, drills and solder mask bot
      PCBI.Automation.IMatrix matrix = parent.GetMatrix();
      if (matrix == null) { MessageBox.Show("Error in matrix.", "MATRIX-ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
      PCBI.Automation.IStep step = parent.GetStep(matrix.GetStepNames()[0]);
      if (step == null) { MessageBox.Show("Error in step.", "NO STEP", MessageBoxButtons.OK, MessageBoxIcon.Information); return; }
 
      ActivateBotView(matrix, step);
 
      parent.UpdateView();
    }
 
    private void PluginToolBarDemoTopView_Click(object sender, EventArgs e)
    {
      //activate signal-top, component-top, drills and solder mask top
      if (!parent.JobIsLoaded) { MessageBox.Show("First load a job.", "NO JOB", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
 
      PCBI.Automation.IMatrix matrix = parent.GetMatrix();
      if (matrix == null) { MessageBox.Show("Error in matrix.", "MATRIX-ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
      PCBI.Automation.IStep step = parent.GetStep(matrix.GetStepNames()[0]);
      if (step == null) { MessageBox.Show("Error in step.", "NO STEP", MessageBoxButtons.OK, MessageBoxIcon.Information); return; }
      
      ActivateTopView(matrix, step);
 
      parent.UpdateView();
    }
 
    #endregion
 
    #region helper methodes
    /// <summary>
    /// This methode deaktivate all layer in a step.
    /// </summary>
    /// <param name="step">the relevant step</param>
    private static void DeactivateAllLayer(PCBI.Automation.IStep Step)
    {
      //make the same like: Step.TurnOffAllLayer();
 
      if (Step == null) return;
 
      foreach (string layerName in Step.GetAllLayerNames())
      {
        ILayer layer = Step.GetLayer(layerName);
        if (layer == null) continue;
 
        layer.DisableLayer();
      }
    }
    /// <summary>
    /// Activate all relevant layer for top view.
    /// </summary>
    /// <param name="Step">the relevant step</param>
    /// <param name="Matrix">the job matrix</param>
    private static void ActivateTopView(PCBI.Automation.IMatrix Matrix, PCBI.Automation.IStep Step)
    {
      if (Step == null || Matrix == null) return;
 
      DeactivateAllLayer(Step);
 
      string name = Matrix.GetTopComponentLayer();
      //If there is a error in the matrix you get null or "".
      if (name == null || name.Length < 1) { MessageBox.Show("Error in Top Component Layer.", "NO Top-CMP-Layer", MessageBoxButtons.OK, MessageBoxIcon.Error); }
      else
      {
        ILayer TopCMPLayer = Step.GetLayer(name);
        if (TopCMPLayer == null) { MessageBox.Show("Error in Top Component Layer.", "NO Top-CMP-Layer", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        else TopCMPLayer.EnableLayer(true);
      }
 
      name = Matrix.GetTopSignalLayer();
      if (name == null || name.Length < 1) { MessageBox.Show("Error in top signal layer.", "NO Top-Signal-Layer", MessageBoxButtons.OK, MessageBoxIcon.Error); }
      else
      {
        ILayer TopSigLayer = Step.GetLayer(name);
        if (TopSigLayer == null) { MessageBox.Show("Error in top signal layer.", "NO Top-Signal-Layer", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        else TopSigLayer.EnableLayer(true);
        ActivateDrillLayer(name, Step, Matrix);
      }
      FindAndAktivateMaskLayer(true, Step, Matrix);
      
    }
    /// <summary>
    /// Activate all relevant layer for bottom view.
    /// </summary>
    /// <param name="Step">the relevant step</param>
    /// <param name="Matrix">the job matrix</param>
    private static void ActivateBotView(PCBI.Automation.IMatrix Matrix, PCBI.Automation.IStep Step)
    {
      if (Step == null || Matrix == null) return;
 
      DeactivateAllLayer(Step);
 
      string name = Matrix.GetBotComponentLayer();
      //If there is a error in the matrix you get null or "".
      if (name == null || name.Length < 1) { MessageBox.Show("Error in Bot Component Layer.", "NO Bot-CMP-Layer", MessageBoxButtons.OK, MessageBoxIcon.Error); }
      else
      {
        ILayer BotCMPLayer = Step.GetLayer(name);
        if (BotCMPLayer == null) { MessageBox.Show("Error in Bot Component Layer.", "NO Bot-CMP-Layer", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        else BotCMPLayer.EnableLayer(true);
      }
      name = Matrix.GetBotSignalLayer();
      if (name == null || name.Length < 1) { MessageBox.Show("Error in bot signal layer.", "NO Bot-Signal-Layer", MessageBoxButtons.OK, MessageBoxIcon.Error); }
      else
      {
        ILayer BotSigLayer = Step.GetLayer(name);
        if (BotSigLayer == null) { MessageBox.Show("Error in bot signal layer.", "NO Bot-Signal-Layer", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        else BotSigLayer.EnableLayer(true);
        ActivateDrillLayer(name, Step, Matrix);
      }
      FindAndAktivateMaskLayer(false, Step, Matrix);
    }
    /// <summary>
    /// This methode search for solder mask layer and activate the first/last one.
    /// </summary>
    /// <param name="TopOne">Take the first mask layer?</param>
    /// <param name="Step">the relevant step</param>
    /// <param name="Matrix">the job matrix</param>
    private static void FindAndAktivateMaskLayer(bool TopOne, PCBI.Automation.IStep Step, PCBI.Automation.IMatrix Matrix)
    {
      if(Step==null|| Matrix==null) return;
 
      int IndexMask = -1;
      foreach (string layerName in Step.GetAllLayerNames())
      {
        if (Matrix.GetMatrixLayerContext(layerName) == MatrixLayerContext.Board && Matrix.GetMatrixLayerType(layerName) == MatrixLayerType.Solder_mask)
        {
          if (TopOne && (Matrix.GetRawIndexByName(layerName) < IndexMask || IndexMask < 0))
          {
            IndexMask = Matrix.GetRawIndexByName(layerName);
            break;
          }
          else if (!TopOne && (Matrix.GetRawIndexByName(layerName) > IndexMask))
            IndexMask = Matrix.GetRawIndexByName(layerName);
        }
      }
 
      string nameMaskLayer = Matrix.GetNameByRowIndex(IndexMask);
 
      if (nameMaskLayer != null && nameMaskLayer.Length > 0)
      {
        ILayer layer = Step.GetLayer(nameMaskLayer);
        if (layer != null) layer.EnableLayer(true);
      }
    }
 
    /// <summary>
    /// This methode activate all drill layer who dill through the relevantSignalLayer.
    /// </summary>
    /// <param name="RelevantSignalLayer">the relevant layer</param>
    /// <param name="Step">the relevant step</param>
    /// <param name="Matrix">the job matrix</param>
    private static void ActivateDrillLayer(string RelevantSignalLayer, PCBI.Automation.IStep Step, PCBI.Automation.IMatrix Matrix)
    {
      //check always for errors:
      if (Step == null || Matrix == null) return;
 
      int RowIndexMainLayer = Matrix.GetRawIndexByName(RelevantSignalLayer);
      if(RowIndexMainLayer<0) return;
 
      foreach (string layerName in Step.GetAllLayerNames())
      {
        if (Matrix.GetMatrixLayerType(layerName) == MatrixLayerType.Drill) //check is it a drill layer?
        {
          int startDrill = Matrix.GetStartDrillLayer(layerName);
          int endDrill = Matrix.GetEndDrillLayer(layerName);
 
          if ((startDrill <= RowIndexMainLayer && endDrill >= RowIndexMainLayer)||(startDrill==endDrill && startDrill==0))
          {
            ILayer drillLayer = Step.GetLayer(layerName);
            if (drillLayer != null) drillLayer.EnableLayer(true);
          }
        }
      }
    }
    #endregion
  }
}