Пример #1
0
        public static void Execute(IPCBIWindow parent)
        {
            //check all selected lines, if lines on lines cut them

            IStep   step   = parent.GetCurrentStep();
            IFilter filter = new IFilter(parent);

            if (step == null)
            {
                return;
            }

            List <IODBObject> selectedElements = step.GetSelectedElements();

            PCB_Investigator.PCBIWindows.PCBIWorkingDialog working = new PCB_Investigator.PCBIWindows.PCBIWorkingDialog();
            StopCutting = false;
            working.SetStatusText("Working on splitting lines...");
            working.CancelPressed += Working_CancelPressed;
            working.CanCancel(true);
            working.SetAnimationStatus(false);

            working.ShowWorkingDlgAsThread();

            for (int i = 0; i < selectedElements.Count; i++)
            {
                if (StopCutting)
                {
                    break;
                }

                working.SetStatusPercent(i * 100 / selectedElements.Count);

                IODBObject evtlLine = selectedElements[i];
                if (evtlLine.Type != IObjectType.Line)
                {
                    continue;
                }

                ILineSpecificsD line = (ILineSpecificsD)evtlLine.GetSpecificsD();
                for (int j = i + 1; j < selectedElements.Count; j++)
                {
                    IODBObject evtlLine2 = selectedElements[j];
                    if (evtlLine2.Type != IObjectType.Line || evtlLine == evtlLine2)
                    {
                        continue;
                    }
                    ILineSpecificsD line2 = (ILineSpecificsD)evtlLine2.GetSpecificsD();

                    PointD crossingP = IMath.CrossingPoint(line.Start, line.End, line2.Start, line2.End, true);
                    if (PointD.InfPoint != crossingP)
                    {
                        CreateSplittedLines(step, filter, evtlLine2, line2, crossingP, ref selectedElements);
                        CreateSplittedLines(step, filter, evtlLine, line, crossingP, ref selectedElements);
                        line = (ILineSpecificsD)evtlLine.GetSpecificsD(); //changed, get it new
                    }
                }
            }
            working.DoClose();
        }
Пример #2
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)
        {
            bool allCMPHeightsInMM = true;
            //check all pads on top and bot signal layers and mask layers for open space in mask...

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

            if (step == null || matrix == null)
            {
                return;
            }

            PCB_Investigator.PCBIWindows.PCBIWorkingDialog working = new PCB_Investigator.PCBIWindows.PCBIWorkingDialog();
            working.CanCancel(false);
            working.SetStatusText("Creating 2D side views...");
            working.SetAnimationStatus(true);

            working.ShowWorkingDlgAsThread();

            ICMPLayer topCMPLayer = step.GetCMPLayer(true);
            ICMPLayer botCMPLayer = step.GetCMPLayer(false);

            IFilter filter = new IFilter(parent);

            IODBLayer frontLayer     = filter.CreateEmptyODBLayer("side_front", step.Name, false);
            IODBLayer sideLayer      = filter.CreateEmptyODBLayer("side_side", step.Name, false);
            float     boardThickness = GetBoardHeight(step);

            //board from side and front
            CreateBoardView(step, filter, frontLayer, boardThickness, true);
            CreateBoardView(step, filter, sideLayer, boardThickness, false);

            CreateComponents(true, topCMPLayer, frontLayer, sideLayer, boardThickness / 2, filter, allCMPHeightsInMM);
            CreateComponents(false, botCMPLayer, frontLayer, sideLayer, boardThickness / 2, filter, allCMPHeightsInMM);



            working.DoClose();

            PCB_Investigator.Localization.PCBILocalization.ShowMsgBox("See new layers side... for results.", "Views created", MessageBoxButtons.OK, MessageBoxIcon.Information);
            matrix.UpdateDataAndList();
            parent.UpdateView();
        }
        public void Execute(IPCBIWindow parent)
        {
            //check all pads on top and bot signal layers and mask layers for open space in mask...

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

            if (step == null || matrix == null)
            {
                return;
            }

            PCB_Investigator.PCBIWindows.PCBIWorkingDialog working = new PCB_Investigator.PCBIWindows.PCBIWorkingDialog();
            working.CanCancel(false);
            working.SetStatusText("Checking for free pads on Solder Mask...");
            working.SetAnimationStatus(true);

            working.ShowWorkingDlgAsThread();

            IODBLayer SMTLayerTop      = null;
            IODBLayer SMTLayerBot      = null;
            IODBLayer SignalTop        = (IODBLayer)step.GetLayer(matrix.GetTopSignalLayer());
            IODBLayer SignalBot        = (IODBLayer)step.GetLayer(matrix.GetBotSignalLayer(false));
            bool      signalBlockFound = false;

            foreach (string layername in step.GetAllLayerNames())
            {
                if (!signalBlockFound && matrix.GetMatrixLayerType(layername) == MatrixLayerType.Solder_mask && SMTLayerTop == null)
                {
                    SMTLayerTop = (IODBLayer)step.GetLayer(layername);
                }
                else if (signalBlockFound && matrix.GetMatrixLayerType(layername) == MatrixLayerType.Solder_mask && SMTLayerBot == null)
                {
                    SMTLayerBot = (IODBLayer)step.GetLayer(layername);
                }
            }
            //check signal pads free?

            bool topPadsFree = true;
            bool botPadsFree = true;

            if (SignalTop != null && SMTLayerTop != null)
            {
                ICMPLayer topCMPLayer = step.GetCMPLayer(true);
                if (topCMPLayer == null)
                {
                    foreach (IODBObject checkingPad in SignalTop.GetAllLayerObjects())
                    {
                        bool?foundFreeArea = CheckPadsForFreeMask(SMTLayerTop, checkingPad);
                        if (foundFreeArea == false)
                        {
                            checkingPad.ObjectColorTemporary(Color.DarkBlue);
                            topPadsFree = false;
                        }
                    }
                }
                else
                {
                    topPadsFree = CheckPadsForFreeMask(SMTLayerTop, SignalTop, topCMPLayer);
                }
            }
            if (SignalBot != null && SMTLayerBot != null)
            {
                ICMPLayer botCMPLayer = step.GetCMPLayer(false);
                if (botCMPLayer == null)
                {
                    foreach (IODBObject checkingPad in SignalBot.GetAllLayerObjects())
                    {
                        bool?foundFreeArea = CheckPadsForFreeMask(SMTLayerBot, checkingPad);
                        if (foundFreeArea == false)
                        {
                            checkingPad.ObjectColorTemporary(Color.DarkBlue);
                            botPadsFree = false;
                        }
                    }
                }
                else
                {
                    botPadsFree = CheckPadsForFreeMask(SMTLayerTop, SignalBot, botCMPLayer);
                }
            }

            working.DoClose();

            if (topPadsFree && botPadsFree)
            {
                PCB_Investigator.Localization.PCBILocalization.ShowMsgBox("Top and Bot Signal Layer Pads free on mask layers.", "Both Sides free", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (!topPadsFree && !botPadsFree)
            {
                PCB_Investigator.Localization.PCBILocalization.ShowMsgBox("Please check both sides manualy, there are closed pads found.", "No Side free", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                if (topPadsFree)
                {
                    PCB_Investigator.Localization.PCBILocalization.ShowMsgBox("Top Side is ok, all pads free on mask layer top.  Check bot layer for blue elements!", "Top OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    PCB_Investigator.Localization.PCBILocalization.ShowMsgBox("Bot Side is ok, all pads free on mask layer bot.  Check top layer for blue elements!", "Bot OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            parent.UpdateView();
        }
        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);
            }
        }
        public void Execute(IPCBIWindow parent)
        {
            //import excellon file output from Cadence Allegro (tools defined as comments)
            //insert digits for reading inner values of drill file (most no information in drill files, you can have a look on your gerber files to identify it).
            //If you load gerber and drill together there is a auto scaling implemented.
            int  LeadingDigits  = 2;
            int  TrailingDigits = 4;
            bool UseMils        = true;


            Parent = parent;
            IFilter filter = new IFilter(parent);

            if (!parent.JobIsLoaded)
            {
                filter.CreateAndLoadEmptyJob(Path.GetTempPath(), "GerberImport", "step");
            }
            stop = false;
            bool TryAutoSize = false;

            string DrillHeader = "Format  : " + LeadingDigits + "." + TrailingDigits + " / Absolute / INCH / Trailing*" + Environment.NewLine;

            DrillHeader += "Contents: Thru / Drill / Plated*" + Environment.NewLine;
            //   DrillHeader += "M48**" + Environment.NewLine;
            DrillHeader += "FMAT,1*" + Environment.NewLine;
            DrillHeader += "INCH,TZ*" + Environment.NewLine;
            DrillHeader += "ICI,OFF*";

            ILayer drillLayer = null;

            System.Windows.Forms.OpenFileDialog of = new System.Windows.Forms.OpenFileDialog();
            of.Multiselect = true;
            if (of.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                PCB_Investigator.PCBIWindows.PCBIWorkingDialog working = new PCB_Investigator.PCBIWindows.PCBIWorkingDialog();
                working.CanCancel(true);
                working.CancelPressed += working_CancelPressed;
                working.SetStatusText("Parsing files...");
                working.ShowWorkingDlgAsThread();
                double counter     = 1;
                double stepOneFile = 100f / of.FileNames.Length;
                foreach (string FileName in of.FileNames)
                {
                    if (stop)
                    {
                        break;
                    }
                    working.SetStatusPercent((int)counter);
                    FileStream   gfs        = new System.IO.FileStream(FileName, FileMode.Open);
                    StreamReader gsr        = new System.IO.StreamReader(gfs, Encoding.UTF8);
                    string       GerberFile = gsr.ReadToEnd();
                    gsr.Close();
                    gfs.Close();
                    string fullPath = Path.GetTempPath() + Path.GetFileName(FileName);

                    counter += stepOneFile;

                    if (File.Exists(fullPath))
                    {
                        try
                        {
                            File.Delete(fullPath);
                            System.Threading.Thread.Sleep(1000); //file delete takes some time...
                        }
                        catch
                        { }
                    }

                    FileStream   writeGerberFS  = new System.IO.FileStream(fullPath, FileMode.OpenOrCreate);
                    StreamWriter GerberWriterSW = new StreamWriter(writeGerberFS, Encoding.UTF8);
                    if (GerberFile.StartsWith("G"))
                    {
                        GerberWriterSW.WriteLine(GerberFile);
                        GerberWriterSW.Flush();
                        GerberWriterSW.Close();
                        IPCBIWindow.LoadInformation loadInfo = new IPCBIWindow.LoadInformation();
                        Parent.LoadData(fullPath, out loadInfo);
                    }
                    else if (GerberFile.StartsWith(";")) //most files out of cadance start with ;
                    {
                        GerberWriterSW.WriteLine(DrillHeader);

                        foreach (string s in GerberFile.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            //z.B. Tooldef. bzw. commentarte
                            //z.B. ;   Holesize 1. = 16.000000 Tolerance = +0.000000/-0.000000 PLATED MILS Quantity = 57
                            if (s.StartsWith(";")) //nur wenn keine tooldef dann check Holesize def
                            {
                                #region check for tool definition in comment
                                int indexHolesize = s.IndexOf("Holesize");
                                if (indexHolesize > 0)
                                {
                                    bool containsMil = s.Contains("MILS");
                                    bool containsMM  = s.Contains("MM");

                                    //check = nach holesize
                                    StringBuilder digitsOfDiameter = new StringBuilder();
                                    bool          started          = false;
                                    for (int i = indexHolesize + 9; i < s.Length; i++)
                                    {
                                        #region get diameter of holesize
                                        if (s[i] == '=')
                                        {
                                            if (started)
                                            {
                                                break;
                                            }
                                            started = true;
                                        }
                                        else
                                        if (started)
                                        {
                                            if (char.IsNumber(s[i]) || s[i] == '.')
                                            {
                                                digitsOfDiameter.Append(s[i]);
                                            }
                                            else if (s[i] == ' ' && digitsOfDiameter.Length == 0)
                                            {
                                            }
                                            else     //anderer Parameter gestartet...
                                            {
                                                break;
                                            }
                                        }
                                        #endregion
                                    }

                                    if (digitsOfDiameter.Length > 0)
                                    {
                                        if (containsMM && !containsMil)
                                        {
                                            double diameterTool = ParseHeader(digitsOfDiameter.ToString(), true) / 1000;
                                            GerberWriterSW.WriteLine(s.Substring(1, 3) + "C" + diameterTool.ToString().Replace(",", "."));
                                        }
                                        else
                                        {
                                            GerberWriterSW.WriteLine(s.Substring(1, 3) + "C" + digitsOfDiameter.ToString());
                                        }
                                    }
                                }
                                else
                                {
                                    GerberWriterSW.WriteLine(s);
                                }
                                #endregion
                            }
                        }

                        GerberWriterSW.WriteLine(GerberFile);
                        GerberWriterSW.Flush();
                        GerberWriterSW.Close();
                        IStep step = parent.GetCurrentStep();
                        working.DoClose();
                        MessageBox.Show("Parameter" + Environment.NewLine + "Leading " + LeadingDigits + " Trailing " + TrailingDigits + Environment.NewLine + "Unit " + (UseMils?"mils":"mm") + Environment.NewLine, "Drill Setup");
                        IMatrix matrix = parent.GetMatrix();

                        if (matrix != null)
                        {
                            matrix.DelateLayer(System.IO.Path.GetFileName(fullPath), false);
                        }

                        string drillLayername = step.AddGerberLayer(fullPath, true, PCBI.ImportOptions.FormatTypes.Excellon1, LeadingDigits, TrailingDigits, UseMils, TryAutoSize);

                        drillLayer = step.GetLayer(drillLayername);
                        Dictionary <double, int> diameterShapeList = new Dictionary <double, int>();
                    }
                }
                working.DoClose();
            }
            parent.UpdateControlsAndResetView();

            if (drillLayer != null)
            {
                drillLayer.EnableLayer(true);
            }
        }
Пример #7
0
            public void SetInfos(IPCBIWindow parentPCBI)
            {
                if (!parentPCBI.JobIsLoaded)
                {
                    return;
                }

                IStep   curStep = parentPCBI.GetCurrentStep();
                IMatrix matrix  = parentPCBI.GetMatrix();

                if (curStep == null || matrix == null)
                {
                    return;                                    //sollte nicht vorkommen wenn job geladen ist
                }
                PCB_Investigator.PCBIWindows.PCBIWorkingDialog working = new PCB_Investigator.PCBIWindows.PCBIWorkingDialog();
                working.CanCancel(false);
                working.SetAnimationStatus(true);
                working.ShowWorkingDlgAsThread();
                richTextBoxMain.Clear();

                bool mm = parentPCBI.GetUnit();

                richTextBoxMain.Font = new System.Drawing.Font("Verdana", 10);

                working.SetStatusText("Working on Step Information " + curStep.Name + "...");

                float boardArea = curStep.CalculateBoardArea();

                if (mm)
                {
                    boardArea = (float)Math.Round(boardArea * (25.4 * 25.4) / 1000000, 3);
                }

                foreach (ILayer activeLayer in curStep.GetActiveLayerList())
                {
                    richTextBoxMain.AppendText("Layer " + activeLayer.GetLayerName() + Environment.NewLine);
                    richTextBoxMain.AppendText(Environment.NewLine);

                    working.SetStatusText("Working on Layer " + activeLayer.GetLayerName() + "...");

                    #region size of layer
                    RectangleF bounds = activeLayer.GetBounds();

                    richTextBoxMain.AppendText("Bounds: " + Environment.NewLine +
                                               "XMin " + (mm ? (IMath.Mils2MM(bounds.Left).ToString("F3") + " mm") : (bounds.Left.ToString("F3") + " mil")) + Environment.NewLine +
                                               "YMin " + (mm ? (IMath.Mils2MM(bounds.Top).ToString("F3") + " mm") : (bounds.Top.ToString("F3") + " mil")) + Environment.NewLine +
                                               "XMax " + (mm ? (IMath.Mils2MM(bounds.Right).ToString("F3") + " mm") : (bounds.Right.ToString("F3") + " mil")) + Environment.NewLine +
                                               "YMax " + (mm ? (IMath.Mils2MM(bounds.Bottom).ToString("F3") + " mm") : (bounds.Bottom.ToString("F3") + " mil")) + Environment.NewLine
                                               );
                    richTextBoxMain.AppendText(Environment.NewLine);
                    richTextBoxMain.AppendText("Width  " + (mm ? (IMath.Mils2MM(bounds.Width).ToString("F3") + " mm") : (bounds.Width.ToString("F3") + " mil")) + Environment.NewLine);
                    richTextBoxMain.AppendText("Height " + (mm ? (IMath.Mils2MM(bounds.Height).ToString("F3") + " mm") : (bounds.Height.ToString("F3") + " mil")) + Environment.NewLine);

                    richTextBoxMain.AppendText(Environment.NewLine);
                    #endregion

                    #region area calculation
                    if (activeLayer is IODBLayer)
                    {
                        IODBLayer odbActiveLayer = (IODBLayer)activeLayer;

                        float areaOfLayer = odbActiveLayer.CalculateArea(true);
                        if (mm)
                        {
                            richTextBoxMain.AppendText("Used Area   " + (Math.Round(areaOfLayer * (25.4 * 25.4) / 1000000, 3).ToString("F3")) + " of " + boardArea.ToString("F3") + " mm?" + Environment.NewLine);
                        }
                        else
                        {
                            richTextBoxMain.AppendText("Used Area   " + Math.Round(areaOfLayer, 2).ToString("F2") + " of " + (boardArea.ToString("F2")) + " mils?" + Environment.NewLine);
                        }
                    }
                    #endregion

                    #region count elements
                    int counterArc      = 0;
                    int counterCMPs     = 0;
                    int counterLines    = 0;
                    int counterSurfaces = 0;
                    int counterText     = 0;
                    int counterPads     = 0;

                    foreach (IObject obj in activeLayer.GetAllLayerObjects()) //count all elements
                    {
                        if (obj.Type == IObjectType.Arc)
                        {
                            counterArc++;
                        }
                        else if (obj.Type == IObjectType.Component)
                        {
                            counterCMPs++;
                        }
                        else if (obj.Type == IObjectType.Line)
                        {
                            counterLines++;
                        }
                        else if (obj.Type == IObjectType.Pad)
                        {
                            counterPads++;
                        }
                        else if (obj.Type == IObjectType.Surface)
                        {
                            counterSurfaces++;
                        }
                        else if (obj.Type == IObjectType.Text)
                        {
                            counterText++;
                        }
                    }
                    richTextBoxMain.AppendText(Environment.NewLine);

                    if (counterArc > 0)
                    {
                        richTextBoxMain.AppendText("Count Arcs:         " + counterArc.ToString("N0") + Environment.NewLine);
                    }
                    if (counterCMPs > 0)
                    {
                        richTextBoxMain.AppendText("Count Components:   " + counterCMPs.ToString("N0") + Environment.NewLine);
                    }
                    if (counterLines > 0)
                    {
                        richTextBoxMain.AppendText("Count Lines:        " + counterLines.ToString("N0") + Environment.NewLine);
                    }
                    if (counterPads > 0)
                    {
                        richTextBoxMain.AppendText("Count Pads:         " + counterPads.ToString("N0") + Environment.NewLine);
                    }
                    if (counterSurfaces > 0)
                    {
                        richTextBoxMain.AppendText("Count Area Fills:   " + counterSurfaces.ToString("N0") + Environment.NewLine);
                    }
                    if (counterText > 0)
                    {
                        richTextBoxMain.AppendText("Count Texts:        " + counterText.ToString("N0") + Environment.NewLine);
                    }
                    richTextBoxMain.AppendText(Environment.NewLine);
                    #endregion

                    #region matrix infos
                    MatrixLayerContext  context  = matrix.GetMatrixLayerContext(activeLayer.GetLayerName());
                    MatrixLayerPolarity polarity = matrix.GetMatrixLayerPolarity(activeLayer.GetLayerName());
                    MatrixLayerType     type     = matrix.GetMatrixLayerType(activeLayer.GetLayerName());
                    int index = matrix.GetRawIndexByName(activeLayer.GetLayerName());

                    richTextBoxMain.AppendText("Matrix Index " + index + ", Context " + context + ", Polarity " + polarity + ", Type " + type + Environment.NewLine);
                    #endregion

                    richTextBoxMain.AppendText(Environment.NewLine);
                    richTextBoxMain.AppendText(Environment.NewLine);
                    richTextBoxMain.AppendText(Environment.NewLine);
                }

                working.DoClose();
            }
Пример #8
0
        public void Execute(IPCBIWindow parent)
        {
            //set all signal layers in one image
            string Rows = Microsoft.VisualBasic.Interaction.InputBox("How many rows do you wish?", "Setup", "2");
            int    rows = 2;

            try
            {
                rows = int.Parse(Rows);
            }
            catch (Exception re)
            {
                MessageBox.Show("Please provide a number\n" + re.ToString());
            }

            string pathForImage = System.IO.Path.GetTempPath() + "imageComplete.png"; //output somewhere

            stopImaging = false;                                                      //internal bool to use cancel button
            float DPI        = 1000;                                                  //in pixel foreach layer
            int   maxWidtBMP = 40000;                                                 //image class is dangerous for big RAM usage!

            int     countImagesEachLine           = rows;                             //maximum of image in one line
            bool    AddDrillsToImage              = true;                             //see where are the connections to other layers
            bool    AddCompToImageAsSeperateLayer = true;                             //see where are the connections to other layers
            IStep   step   = parent.GetCurrentStep();
            IMatrix matrix = parent.GetMatrix();

            if (step == null || matrix == null)
            {
                return;
            }
            PCB_Investigator.PCBIWindows.PCBIWorkingDialog working = null;
            try
            {
                working = new PCB_Investigator.PCBIWindows.PCBIWorkingDialog(); //show waiting dialog, because for some projects it is very slow
                working.CanCancel(true);
                working.CancelPressed += working_CancelPressed;
                working.SetAnimationStatus(false);
                working.ShowWorkingDlgAsThread();
                int curValPercentage = 0;
                working.SetStatusPercent(curValPercentage);

                List <string> allSignalLayerNames = matrix.GetAllSignalLayerNames();
                if (!AddCompToImageAsSeperateLayer)
                {
                    allSignalLayerNames.Insert(0, matrix.GetTopComponentLayer());
                    allSignalLayerNames.Add(matrix.GetBotComponentLayer());
                }
                List <ILayer> activeLayerList = step.GetActiveLayerList(); //remember active layer list to set them later back
                step.TurnOffAllLayer();

                int   maxHeight     = 0;
                int   maxWidth      = 0;
                int   completeWidth = 0;
                int   lines         = 1;
                bool  setBackHatch  = parent.IColorsetting.UseHatchMode;
                Color setBackColor  = parent.IColorsetting.SelectionColor;

                parent.IColorsetting.SelectionColor = Color.White; //highlight selection better with plane color
                parent.IColorsetting.UseHatchMode   = false;

                RectangleF boundsStep = step.GetBounds();
                boundsStep.Inflate(20, 20);

                int height = (int)(boundsStep.Height * DPI / 1000);
                int width  = (int)(boundsStep.Width * DPI / 1000); //set the step bounds with DPI
                if (height > maxHeight)
                {
                    maxHeight = height;
                }

                curValPercentage = 10;
                working.SetStatusPercent(curValPercentage);

                Dictionary <string, System.Drawing.Bitmap> allLayerImages = new Dictionary <string, System.Drawing.Bitmap>();
                int counterLayers = 0;
                foreach (string layername in allSignalLayerNames)
                {
                    if (stopImaging)
                    {
                        break;
                    }
                    counterLayers++;
                    working.SetStatusText("working on " + layername);
                    curValPercentage += 80 / allSignalLayerNames.Count; //we want only the part in the middle of the progress bar...
                    working.SetStatusPercent(curValPercentage);
                    Bitmap resultImage;
                    if (step.GetLayer(layername) is IODBLayer)
                    {
                        IODBLayer signalLayer = (IODBLayer)step.GetLayer(layername);
                        signalLayer.EnableLayer(true);
                        if (AddDrillsToImage)
                        {
                            List <ILayer> drawList = new List <ILayer>();
                            foreach (string layerDrillName in matrix.GetAllDrillLayersForThisLayer(layername))
                            {
                                drawList.Add(step.GetLayer(layerDrillName));
                            }
                            drawList.Add(signalLayer);
                            if (AddCompToImageAsSeperateLayer)
                            {
                                if (matrix.GetTopSignalLayer() == layername)
                                {
                                    ILayer layer = step.GetLayer(matrix.GetTopComponentLayer());
                                    if (layer != null)
                                    {
                                        drawList.Add(layer);
                                    }
                                }
                                if (matrix.GetBotSignalLayer() == layername)
                                {
                                    ILayer layer = step.GetLayer(matrix.GetBotComponentLayer());
                                    if (layer != null)
                                    {
                                        drawList.Add(layer);
                                    }
                                }
                            }
                            resultImage = step.GetBitmap(drawList, boundsStep, width, height, true, false, false, false);
                            // public Bitmap GetBitmap(	List<ILayer> Layers,RectangleF DetailRectangle,	int Width,	int Height,	bool DrawPCBOutline,	bool FillBoardOutline,	bool ShowComponentDetails,	bool IgnoreSelection,	bool DrawOnlySelection,	out RectangleF DrawnRectangle

                            Bitmap copyBitmap = new Bitmap(resultImage); //do copy the image before the old one will be disposed

                            resultImage = copyBitmap;
                        }
                        else
                        {
                            resultImage = step.GetBitmap(new List <ILayer>()
                            {
                                signalLayer
                            }, boundsStep, width, height, true, false, false, false);
                        }
                        if (resultImage != null)
                        {
                            allLayerImages.Add(layername, resultImage); //remember the layer image later
                        }
                        signalLayer.DisableLayer();
                    }
                    else if (!AddCompToImageAsSeperateLayer && step.GetLayer(layername) is ICMPLayer)
                    {
                        ICMPLayer cmpLayer = (ICMPLayer)step.GetLayer(layername);
                        resultImage = step.GetBitmap(new List <ILayer>()
                        {
                            cmpLayer
                        }, boundsStep, width, height, true, false, true, false);

                        allLayerImages.Add(layername, resultImage); //remember the layer image later
                    }

                    if (completeWidth + width > maxWidtBMP || counterLayers > countImagesEachLine) //max image size
                    {
                        lines++;
                        completeWidth = width;
                        counterLayers = 1;
                    }
                    else
                    {
                        completeWidth += width;
                    }

                    if (completeWidth > maxWidth)
                    {
                        maxWidth = completeWidth;
                    }
                }
                working.SetStatusText("built new image...");

                working.SetStatusPercent(85);
                Bitmap bitComplete   = null;
                bool   needDownScale = false;

                try
                {
                    bitComplete = new Bitmap(maxWidth, lines * (maxHeight + 100) + 60); //depending on your design this constructor sometimes throw an exception
                }
                catch
                {
                    bitComplete   = new Bitmap(maxWidth / 10, lines * (maxHeight + 1000) / 10 + 60);
                    needDownScale = true; //depending on your machine settings and RAM it can make problems by creating big images.
                }

                parent.IColorsetting.UseHatchMode   = setBackHatch;
                parent.IColorsetting.SelectionColor = setBackColor;

                Graphics g = Graphics.FromImage(bitComplete);
                g.Clear(Color.Transparent);
                int Xoff = 0;
                int Yoff = 0;
                working.SetStatusText("set images in one... ");

                Font f = new Font("Arial", needDownScale ? 20 : 40); //we need a font to write layernames
                int  counterImagesInLine = 0;
                foreach (string layer in allLayerImages.Keys)
                {
                    counterImagesInLine++;
                    if (needDownScale && (Xoff + allLayerImages[layer].Width / 10 > bitComplete.Width || counterImagesInLine > countImagesEachLine))
                    {
                        Yoff += maxHeight / 10 + 100; //space for text
                        Xoff  = 0;
                        counterImagesInLine = 1;
                    }
                    else if (Xoff + allLayerImages[layer].Width > maxWidtBMP || counterImagesInLine > countImagesEachLine)
                    {
                        Yoff += maxHeight + 100; //space for text
                        Xoff  = 0;
                        counterImagesInLine = 1;
                    }
                    if (needDownScale)
                    {
                        g.DrawImage(allLayerImages[layer], new RectangleF(Xoff, Yoff + 100, width / 10, height / 10), new RectangleF(0, 0, allLayerImages[layer].Width, allLayerImages[layer].Height), GraphicsUnit.Pixel);
                    }
                    else
                    {
                        g.DrawImage(allLayerImages[layer], new Point(Xoff, Yoff + 100));
                    }

                    g.DrawString(layer, f, Brushes.Red, new PointF(Xoff + 50, Yoff + 30)); //name of layer

                    if (needDownScale)
                    {
                        Xoff += allLayerImages[layer].Width / 10;
                    }
                    else
                    {
                        Xoff += allLayerImages[layer].Width;
                    }
                }
                string textForFooter = parent.GetJobName() + " - creation date: " + DateTime.Now.ToString() + "    www.PCB-Investigator.com";

                SizeF size = g.MeasureString(textForFooter, f);

                g.DrawString(textForFooter, f, Brushes.White, new PointF((bitComplete.Width - size.Width) / 2, bitComplete.Height - 60)); //name of layer

                working.SetStatusPercent(91);

                foreach (ILayer layerActive in activeLayerList)
                {
                    layerActive.EnableLayer(true);
                }
                working.SetStatusPercent(95);

                try
                {
                    working.SetStatusText("saving result...");
                    bitComplete.Save(pathForImage, ImageFormat.Png);

                    //open image with standard viewer
                    System.Diagnostics.Process.Start(pathForImage);
                }
                catch
                { }
                working.DoClose();
            }
            catch (Exception ex)
            {
                if (working != null)
                {
                    working.DoClose();
                }

                MessageBox.Show("Can't create image, because " + Environment.NewLine + ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }