Ejemplo n.º 1
0
        private static void AddDrillObjects(IFilter filter, ILayer drill_layer, MatrixLayerType type, IODBLayer odb_sig_layer)
        {
            Dictionary <int, int> symbolUsed = new Dictionary <int, int>();

            foreach (IODBObject obj in drill_layer.GetAllLayerObjects())
            {
                #region one drill layer
                obj.Select(true);
                if (obj.Type == IObjectType.Pad)
                {
                    IPadSpecifics ops = (IPadSpecifics)obj.GetSpecifics();
                    if (type != MatrixLayerType.Dielectric)
                    {
                        ops.Positive = false;
                    }
                    else
                    {
                        ops.Positive = true;
                    }

                    if (!symbolUsed.ContainsKey(ops.ShapeIndex))
                    {
                        int index = IFilter.AddToolFromODBString(odb_sig_layer, ops.ODBSymbol_String);
                        symbolUsed.Add(ops.ShapeIndex, index);
                    }

                    ops.ShapeIndex = symbolUsed[ops.ShapeIndex];

                    IODBObject pad = filter.CreatePad(odb_sig_layer);
                    pad.SetSpecifics(ops);
                }
                else if (obj.Type == IObjectType.Line)
                {
                    ILineSpecifics ops = (ILineSpecifics)obj.GetSpecifics();
                    if (type != MatrixLayerType.Dielectric)
                    {
                        ops.Positive = false;
                    }
                    else
                    {
                        ops.Positive = true;
                    }

                    if (!symbolUsed.ContainsKey(ops.ShapeIndex))
                    {
                        int index = IFilter.AddToolFromODBString(odb_sig_layer, ops.ODBSymbol_String);
                        symbolUsed.Add(ops.ShapeIndex, index);
                    }

                    ops.ShapeIndex = symbolUsed[ops.ShapeIndex];

                    IODBObject line = filter.CreateLine(odb_sig_layer);
                    line.SetSpecifics(ops);
                }

                #endregion
            }
        }
            private void CreateNewDrillODBLayer(PCBI.Automation.IFilter filter, string newLayerName, IPCBIWindow parent, List <IODBObject> currIODBObjectList, bool activateLayer)
            {
                if (currIODBObjectList.Count == 0)
                {
                    return;
                }

                IODBLayer layer = filter.CreateEmptyODBLayer(newLayerName, parent.GetCurrentStep().Name);
                Dictionary <string, int> shapeList = new Dictionary <string, int>();

                foreach (IODBObject obj in currIODBObjectList)
                {
                    if (obj.Type == IObjectType.Pad)
                    {
                        IPadSpecificsD specPad = (IPadSpecificsD)obj.GetSpecificsD();
                        if (!shapeList.ContainsKey(specPad.ODBSymbol_String))
                        {
                            int newShapeIndex = IFilter.AddToolFromODBString(layer, specPad.ODBSymbol_String, shapeList.Count);
                            shapeList.Add(specPad.ODBSymbol_String, newShapeIndex);
                        }
                        IODBObject     pad       = filter.CreatePad(layer);
                        IPadSpecificsD padInfosD = (IPadSpecificsD)obj.GetSpecificsD();
                        padInfosD.ShapeIndex = shapeList[specPad.ODBSymbol_String];
                        pad.SetSpecifics(padInfosD, shapeList[specPad.ODBSymbol_String]);
                    }
                    else if (obj.Type == IObjectType.Line)
                    {
                        ILineSpecificsD specLine = (ILineSpecificsD)obj.GetSpecificsD();
                        if (!shapeList.ContainsKey(specLine.ODBSymbol_String))
                        {
                            int newShapeIndex = IFilter.AddToolFromODBString(layer, specLine.ODBSymbol_String, shapeList.Count);
                            shapeList.Add(specLine.ODBSymbol_String, newShapeIndex);
                        }
                        IODBObject      line           = filter.CreateLine(layer);
                        ILineSpecificsD lineSpecificsD = (ILineSpecificsD)obj.GetSpecificsD();
                        lineSpecificsD.ShapeIndex = shapeList[specLine.ODBSymbol_String];
                        line.SetSpecifics(lineSpecificsD);
                    }
                    else if (obj.Type == IObjectType.Arc)
                    {
                        IArcSpecificsD specArc = (IArcSpecificsD)obj.GetSpecificsD();
                        if (!shapeList.ContainsKey(specArc.ODBSymbol_String))
                        {
                            int newShapeIndex = IFilter.AddToolFromODBString(layer, specArc.ODBSymbol_String, shapeList.Count);
                            shapeList.Add(specArc.ODBSymbol_String, newShapeIndex);
                        }
                        IODBObject     arc           = filter.CreateArc(layer);
                        IArcSpecificsD specificsArcD = (IArcSpecificsD)obj.GetSpecificsD();
                        specificsArcD.ShapeIndex = shapeList[specArc.ODBSymbol_String];
                        arc.SetSpecifics(specificsArcD);
                    }
                    else if (obj.Type == IObjectType.Surface)
                    {
                        IODBObject         surface           = filter.CreatePolygon(layer);
                        ISurfaceSpecificsD surfaceSpecificsD = (ISurfaceSpecificsD)obj.GetSpecificsD();
                        surface.SetSpecifics(surfaceSpecificsD);
                    }
                    else if (obj.Type == IObjectType.Text)
                    {
                        IODBObject      text           = filter.CreateText(layer);
                        ITextSpecificsD textSpecificsD = (ITextSpecificsD)obj.GetSpecificsD();
                        text.SetSpecifics(textSpecificsD);
                    }
                }
                if (activateLayer)
                {
                    layer.EnableLayer(true);
                }

                IMatrix matrix = parent.GetMatrix();

                matrix.SetMatrixLayerType(layer.LayerName, MatrixLayerType.Drill);
                matrix.SetMatrixLayerContext(layer.LayerName, MatrixLayerContext.Board);
            }
        public void Execute(IPCBIWindow parent)
        {
            IStep   step   = parent.GetCurrentStep();
            IMatrix matrix = parent.GetMatrix();

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

            IODBLayer IODBLayerOrg = null;
            IODBLayer IODBLayerNew = null;

            foreach (ILayer activeLayer in step.GetActiveLayerList()) //search for the first two active layer to copy from first to second
            {
                if (activeLayer is IODBLayer)
                {
                    if (IODBLayerOrg == null)
                    {
                        IODBLayerOrg = (IODBLayer)activeLayer;
                    }
                    else if (IODBLayerNew == null)
                    {
                        IODBLayerNew = (IODBLayer)activeLayer;
                    }
                    else
                    {
                        break; //only the first two layers...
                    }
                }
            }
            if (IODBLayerOrg == null || IODBLayerNew == null)
            {
                return;
            }

            IFilter filter = new IFilter(parent);

            if (IODBLayerOrg is IODBLayer)
            {
                Dictionary <int, int> ShapeIndexOldNew = new Dictionary <int, int>(); //set new shape index if symbol is created.

                foreach (IODBObject obj in IODBLayerOrg.GetAllLayerObjects())
                {
                    IODBObject        objNew = null;
                    IObjectSpecificsD spec   = obj.GetSpecificsD();
                    switch (obj.Type)
                    {
                    case IObjectType.Arc:
                        objNew = filter.CreateArc(IODBLayerNew);
                        if (!ShapeIndexOldNew.ContainsKey(((IArcSpecificsD)spec).ShapeIndex))
                        {
                            int indexNew = IFilter.AddToolFromODBString(IODBLayerNew, ((IArcSpecificsD)spec).ODBSymbol_String);
                            ShapeIndexOldNew.Add(((IArcSpecificsD)spec).ShapeIndex, indexNew);
                        }
                        ((IArcSpecificsD)spec).ShapeIndex = ShapeIndexOldNew[((IArcSpecificsD)spec).ShapeIndex];
                        break;

                    case IObjectType.Line:
                        objNew = filter.CreateLine(IODBLayerNew);
                        if (!ShapeIndexOldNew.ContainsKey(((ILineSpecificsD)spec).ShapeIndex))
                        {
                            int indexNew = IFilter.AddToolFromODBString(IODBLayerNew, ((ILineSpecificsD)spec).ODBSymbol_String);
                            ShapeIndexOldNew.Add(((ILineSpecificsD)spec).ShapeIndex, indexNew);
                        }
                        ((ILineSpecificsD)spec).ShapeIndex = ShapeIndexOldNew[((ILineSpecificsD)spec).ShapeIndex];
                        break;

                    case IObjectType.Pad:
                        objNew = filter.CreatePad(IODBLayerNew);
                        if (!ShapeIndexOldNew.ContainsKey(((IPadSpecificsD)spec).ShapeIndex))
                        {
                            IFilter.ToolDefinition toolDef = filter.GetSymbolByShapeIndex(((IPadSpecificsD)spec).ShapeIndex, (IODBLayer)IODBLayerOrg);
                            int indexNew = -1;
                            if (toolDef.Type == PCBI.Symbol_Type.special)
                            {
                                indexNew = IFilter.AddToolDefinitionSpecial(IODBLayerNew, (IODBLayer)IODBLayerOrg, toolDef.ShapeIndex);
                            }
                            else
                            {
                                indexNew = IFilter.AddToolFromODBString(IODBLayerNew, ((IPadSpecificsD)spec).ODBSymbol_String);
                            }
                            ShapeIndexOldNew.Add(((IPadSpecificsD)spec).ShapeIndex, indexNew);
                        }
                        ((IPadSpecificsD)spec).ShapeIndex = ShapeIndexOldNew[((IPadSpecificsD)spec).ShapeIndex];
                        break;

                    case IObjectType.Surface:
                        objNew = filter.CreatePolygon(IODBLayerNew);
                        break;

                    case IObjectType.Text:
                        objNew = filter.CreateText(IODBLayerNew);
                        break;

                    default:
                        System.Diagnostics.Debug.WriteLine("Case not possible!");
                        break;
                    }

                    if (objNew != null)
                    {
                        objNew.SetSpecifics(spec);
                    }
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Not implemented for components!");
            }
            parent.UpdateView();
        }