Ejemplo n.º 1
0
        private static void MakeDrillCutOutOnCopperLayers(IPCBIWindow Parent, IMatrix matrix, IStep step)
        {
            IFilter filter            = new IFilter(Parent);
            int     counterDielectirc = 1;

            foreach (string layerName in matrix.GetAllDrillLayerNames())
            {
                ILayer drill_layer = step.GetLayer(layerName);

                bool lastWasSignal = false;
                foreach (string sigLayer in matrix.GetAllLayerWithThisDrills(layerName))
                {
                    var type = matrix.GetMatrixLayerType(sigLayer);
                    if (type != MatrixLayerType.Dielectric && !matrix.IsSignalLayer(sigLayer)) //only dielectric und signals
                    {
                        continue;
                    }
                    if ((type == MatrixLayerType.Power_ground || type == MatrixLayerType.Signal))
                    {
                        if (lastWasSignal)
                        {
                            //if last and current one are signals -> we need a dielectric between both
                            IODBLayer dielectric = filter.CreateEmptyODBLayer("dielectric_" + counterDielectirc, step.Name);
                            counterDielectirc++;
                            if (dielectric != null)
                            {
                                AddDrillObjects(filter, drill_layer, MatrixLayerType.Dielectric, dielectric);
                                matrix.SetMatrixLayerIndex(dielectric.GetLayerName(), matrix.GetRawIndexByName(sigLayer));
                                matrix.SetMatrixLayerParameter(dielectric.GetLayerName(), MatrixLayerContext.Board, MatrixLayerPolarity.Negative, MatrixLayerType.Dielectric, -1, -1);
                                matrix.SetLayerHeight(dielectric.GetLayerName(), 5); //value in mils
                                matrix.UpdateDataAndList();                          //update list for correct order
                            }
                            else
                            {
                                Debug.WriteLine("error, can't create dielectric...");
                            }
                        }

                        lastWasSignal = true;
                    }
                    else
                    {
                        lastWasSignal = false;
                    }

                    IODBLayer odb_sig_layer = (IODBLayer)step.GetLayer(sigLayer);

                    if (drill_layer.GetType() == typeof(IODBLayer))
                    {
                        AddDrillObjects(filter, drill_layer, type, odb_sig_layer);

                        drill_layer.EnableLayer(false);
                        odb_sig_layer.EnableLayer(true);
                    }
                }
            }

            matrix.UpdateDataAndList();
            Parent.UpdateControlsAndResetView();
        }
        public void Execute(IPCBIWindow parent)
        {
            IStep step = parent.GetCurrentStep();

            if (step == null)
            {
                return;
            }

            string    layernameTopHeightRestrictions = "drc_comp";
            ICMPLayer topCMPLayer            = step.GetCMPLayer(true); //for bottom change here to false
            ILayer    HeightRestirctionLayer = step.GetLayer(layernameTopHeightRestrictions);

            // check each cmp for height restrictions
            foreach (ICMPObject cmp in topCMPLayer.GetAllLayerObjects())
            {
                foreach (IODBObject surface in HeightRestirctionLayer.GetAllObjectInRectangle(cmp.Bounds))
                {
                    if (surface.IsPointOfSecondObjectIncluded(cmp, false)) //intersecting is ok?
                    {
                        //check height of cmp
                        IAttributeElement attributeMaxHeight = null;
                        foreach (IAttributeElement attribute in IAttribute.GetAllAttributes(surface))
                        {
                            if (attribute.AttributeEnum == PCBI.FeatureAttributeEnum.drc_max_height)
                            {
                                attributeMaxHeight = attribute;
                                break;
                            }
                        }
                        if (attributeMaxHeight == null)
                        {
                            continue;
                        }

                        if (cmp.CompHEIGHT > (double)attributeMaxHeight.Value) //we know this attribute has double values
                        {
                            cmp.ObjectColorTemporary(Color.LightCoral);        //change color to highlight cmps
                            //surface.ObjectColorTemporary(Color.Wheat);
                            surface.FreeText = "Check Height of " + cmp.Ref;
                            break;
                        }
                    }
                }
            }
            topCMPLayer.EnableLayer(true);
            HeightRestirctionLayer.EnableLayer(true);
            parent.UpdateView();
        }
        public void Execute(IPCBIWindow Parent)
        {
            IStep   step   = Parent.GetCurrentStep();
            IMatrix matrix = Parent.GetMatrix();

            if (step == null)
            {
                return;
            }
            IODBObject profile = step.GetPCBOutlineAsODBObject();

            foreach (string layerName in step.GetAllLayerNames())
            {
                if (matrix.GetMatrixLayerType(layerName) == MatrixLayerType.Component)
                {
                    continue; //no component layer
                }
                ILayer Layer = step.GetLayer(layerName);
                if (Layer is IODBLayer)
                {
                    bool      foundOne = false;
                    IODBLayer layer    = (IODBLayer)Layer;
                    foreach (IODBObject obj in layer.GetAllLayerObjects())
                    {
                        if (profile.IsPointOfSecondObjectIncluded(obj))
                        {
                            //inside not relevant
                        }
                        else
                        {
                            obj.Select(true);
                            foundOne = true;
                        }
                    }
                    if (foundOne)
                    {
                        Layer.EnableLayer(true);
                    }
                }
            }
            Parent.UpdateSelection();
            Parent.UpdateView();
        }
        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);
            }
        }