Ejemplo n.º 1
0
        public void Execute(IPCBIWindow parent)
        {
            wdlg = new PCB_Investigator.PCBIWindows.PCBIWorkingDialog();
            wdlg.SetAnimationStatus(false);
            wdlg.SetStatusPercent(0);
            wdlg.SetStatusText("Working");
            wdlg.CanCancel(true);

            IStep curStep = parent.GetCurrentStep();

            if (curStep == null)
            {
                return;
            }

            Dictionary <string, double> smallestDiameterList = new Dictionary <string, double>();
            StringBuilder sbResult = new StringBuilder();

            wdlg.ShowWorkingDlgAsThread();

            List <string> netNames  = curStep.GetAllNetNames();
            double        value     = 0;
            double        valueStep = ((100.0 / netNames.Count));


            foreach (string netName in curStep.GetAllNetNames())
            {
                INet net = curStep.GetNet(netName);

                wdlg.SetStatusText("Working on " + netName + "...");
                value += valueStep;
                wdlg.SetStatusPercent((int)(value));

                List <IODBObject> allNetElements = net.GetAllNetObjects(parent);
                if (allNetElements.Count == 0)
                {
                    continue;
                }

                double smallestDiameter = allNetElements[0].GetDiameter();
                foreach (IODBObject netElement in allNetElements)
                {
                    double currentDiameter = netElement.GetDiameter();
                    if (currentDiameter < 0)
                    {
                        continue;                      //e.g. surfaces have no diameter
                    }
                    if (currentDiameter < smallestDiameter)
                    {
                        smallestDiameter = currentDiameter;
                    }
                }

                smallestDiameterList.Add(netName, smallestDiameter);
                sbResult.AppendLine(netName + ": " + smallestDiameter.ToString() + " mils");
            }
            wdlg.Dispose();
            PCB_Investigator.Localization.PCBILocalization.ShowMsgBox("All smallest Net Diameters:" + Environment.NewLine + sbResult.ToString(), "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        public void Execute(IPCBIWindow parent)
        {
            //example to check first solder paste with first solder mask distances.
            double maxDist = 2; //mils

            wdlg = new PCB_Investigator.PCBIWindows.PCBIWorkingDialog();
            wdlg.SetAnimationStatus(false);
            wdlg.SetStatusPercent(0);
            wdlg.SetStatusText("Working");
            wdlg.CanCancel(true);


            IMatrix matrix = parent.GetMatrix();
            IStep   step   = parent.GetCurrentStep();

            wdlg.ShowWorkingDlgAsThread();

            List <string> layerNames = step.GetAllLayerNames();
            double        value      = 0;
            double        valueStep  = ((100.0 / layerNames.Count));

            Dictionary <IODBObject.DistanceResultClass, IODBObject> DistanceList = new Dictionary <IODBObject.DistanceResultClass, IODBObject>();
            IODBLayer SMTLayer = null;
            IODBLayer SPLayer  = null;

            foreach (string layername in step.GetAllLayerNames())
            {
                wdlg.SetStatusText("Working on " + layername + "...");
                value += valueStep;
                wdlg.SetStatusPercent((int)(value));

                if (matrix.GetMatrixLayerType(layername) == MatrixLayerType.Solder_paste && SPLayer == null) //find top solderpaste
                {
                    SPLayer = (IODBLayer)step.GetLayer(layername);
                }
                else if (matrix.GetMatrixLayerType(layername) == MatrixLayerType.Solder_mask && SMTLayer == null) //find top mask layer
                {
                    SMTLayer = (IODBLayer)step.GetLayer(layername);
                }

                if (SMTLayer != null && SPLayer != null)
                {
                    foreach (IODBObject IODBO1 in SPLayer.GetAllLayerObjects())
                    {
                        RectangleD boundsToInflate = IODBO1.GetBoundsD();
                        boundsToInflate.Inflate(maxDist, maxDist);
                        foreach (IODBObject IODBO2 in SMTLayer.GetAllObjectInRectangle(boundsToInflate))
                        {
                            IODBObject.DistanceResultClass distance = IODBO1.DistanceTo(IODBO2);
                            if (distance.Distance >= 0)
                            {
                                DistanceList.Add(distance, IODBO2);
                                IODBO2.ObjectColorTemporary(Color.DarkRed);
                            }
                        }
                    }
                    break;
                }
            }
            wdlg.Dispose();
            if (DistanceList.Count > 0) //write result to excel
            {
                StringBuilder sb = new StringBuilder();

                var     excelType = Type.GetTypeFromProgID("Excel.Application");
                dynamic excel     = Activator.CreateInstance(excelType);
                excel.Visible = true;
                excel.Workbooks.Add();

                foreach (IODBObject.DistanceResultClass distanceResult in DistanceList.Keys)
                {
                    sb.Append("\t" + DistanceList[distanceResult].PcbNetNumber + "\t" + distanceResult.From + "\t" + distanceResult.To + "\t" + distanceResult.Distance + Environment.NewLine);
                }

                string     LVText       = "Distances\tNet Number\tMask Layer\tSolder Paste\tValue" + Environment.NewLine + sb.ToString();
                string     LVCsv        = sb.ToString();
                DataObject LVDataObject = new DataObject();
                LVDataObject.SetData(DataFormats.Text, true, LVText);
                LVDataObject.SetData(DataFormats.CommaSeparatedValue, true, LVCsv);
                Clipboard.SetDataObject(LVDataObject, true);

                excel.ActiveSheet.Paste();

                //release the object
                System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
            }
            else
            {
                MessageBox.Show("No Results found...\n Please check Layers for Paste- or Mask layers!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }