예제 #1
0
        private static void CreateSplittedLines(IStep step, IFilter filter, IODBObject evtlLine2, ILineSpecificsD line2, PointD pDest, ref List <IODBObject> selectedElements)
        {
            PointD lastEnd = line2.End;

            line2.End = pDest;
            if (Math.Abs(IMath.DistancePointToPoint(line2.End, line2.Start)) < errorLevel)
            {
                line2.End   = lastEnd;
                line2.Start = pDest;
                if (Math.Abs(IMath.DistancePointToPoint(line2.End, line2.Start)) > errorLevel)
                {
                    evtlLine2.SetSpecifics(line2);
                }
                else
                {
                    Debug.WriteLine("Line with length 0!");
                }
            }
            else
            {
                evtlLine2.SetSpecifics(line2);

                ILayer parentLayer = step.GetLayer(evtlLine2.GetParentLayerName());
                if (parentLayer != null)
                {
                    IODBObject line2Part2 = filter.CreateLine((IODBLayer)parentLayer);
                    line2.End   = lastEnd;
                    line2.Start = pDest;
                    line2Part2.SetSpecifics(line2);
                    selectedElements.Add(line2Part2);
                }
            }
        }
        private static bool CheckConnection(double tolerance, IODBObject selObj, PointD lineStart, List <IObject> relevantObjects, bool setColor)
        {
            foreach (IODBObject relObject in relevantObjects)
            {
                if (relObject == selObj)
                {
                    continue;
                }

                if (relObject.Type == IObjectType.Line)
                {
                    ILineSpecificsD lineRel = (ILineSpecificsD)relObject.GetSpecificsD();

                    if (IMath.DistancePointToPoint(lineRel.End, lineStart) < tolerance || IMath.DistancePointToPoint(lineRel.Start, lineStart) < tolerance)
                    {
                        setColor = false; break;
                    }
                }
                else if (relObject.Type == IObjectType.Arc)
                {
                    IArcSpecificsD arcRel = (IArcSpecificsD)relObject.GetSpecificsD();

                    if (IMath.DistancePointToPoint(arcRel.End, lineStart) < tolerance || IMath.DistancePointToPoint(arcRel.Start, lineStart) < tolerance)
                    {
                        setColor = false; break;
                    }
                }
            }
            return(setColor);
        }
        private static void CreateBoardView(IStep step, IFilter filter, IODBLayer frontLayer, float boardThickness, bool front)
        {
            if (boardThickness > 0)
            {
                #region draw board front
                int shapeIndexBoardHeight = IFilter.AddToolDefinitionRect(frontLayer, boardThickness, boardThickness, boardThickness, false);

                //add line with board symbol index to have correct thickness
                IODBObject boardLineFront = filter.CreateLine(frontLayer);

                ILineSpecificsD lineDetails = (ILineSpecificsD)boardLineFront.GetSpecificsD();
                if (front)
                {
                    lineDetails.Start = new PointD(step.GetBoundsD().Left + boardThickness / 2, 0);
                    lineDetails.End   = new PointD(step.GetBoundsD().Right - boardThickness / 2, 0);
                }
                else
                {
                    lineDetails.Start = new PointD(0, step.GetBoundsD().Top + boardThickness / 2);
                    lineDetails.End   = new PointD(0, step.GetBoundsD().Bottom - boardThickness / 2);
                }
                boardLineFront.SetSpecifics(lineDetails, shapeIndexBoardHeight);
                boardLineFront.ObjectColorTemporary(Color.Green);
                #endregion
            }
        }
        public void Execute(IPCBIWindow parent)
        {
            IFilter           filter         = new IFilter(parent);
            IODBObject        outlinePolygon = filter.CreateOutlinePolygon();
            IStep             parentStep     = parent.GetCurrentStep();
            ISurfaceSpecifics spec           = (ISurfaceSpecifics)outlinePolygon.GetSpecifics();

            spec.StartPolygon(false, new PointF());
            RectangleF newBounds = new RectangleF(0, 0, 15000, 10000);

            //create 4 lines and add them to an contour polygon
            PointF leftUp    = new PointF(newBounds.Left, newBounds.Top);
            PointF leftDown  = new PointF(newBounds.Left, newBounds.Bottom);
            PointF rightUp   = new PointF(newBounds.Right, newBounds.Top);
            PointF rightDown = new PointF(newBounds.Right, newBounds.Bottom);

            spec.AddLine(leftUp, rightUp);
            spec.AddLine(rightUp, rightDown);
            spec.AddLine(rightDown, leftDown);
            spec.AddLine(leftDown, leftUp);

            spec.EndPolygon(); //close the new contour

            parentStep.SetPCBOutline(spec);
            parent.UpdateView();
        }
예제 #5
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();
        }
예제 #6
0
        public void Execute(IPCBIWindow parent)
        {
            //your code here
            int count = 0;

            IStep step = parent.GetCurrentStep();

            IODBLayer outsideToplayer = step.GetOutsideODBLayer(true);
            IODBLayer outsideBotlayer = step.GetOutsideODBLayer(false);

            if (step.GetCMPLayer(true) != null)
            {
                step.GetCMPLayer(true).EnableLayer(true);
                foreach (ICMPObject cmp in step.GetCMPLayer(true).GetAllLayerObjects())
                {
                    foreach (IPin pin in cmp.GetPinList())
                    {
                        IODBObject po = pin.GetIPinPad(outsideToplayer, cmp);
                        if (po != null)
                        {
                            IPadSpecifics os = (IPadSpecifics)po.GetSpecifics();
                            if (os.Type == PCBI.Symbol_Type.r)
                            {
                                cmp.ObjectColor = Color.Red;
                                cmp.AddComponentAttribute("techno", "thr");
                                count++;

                                break;
                            }
                        }
                    }
                }
            }
            if (step.GetCMPLayer(false) != null)
            {
                step.GetCMPLayer(false).EnableLayer(true);
                foreach (ICMPObject cmp in step.GetCMPLayer(false).GetAllLayerObjects())
                {
                    foreach (IPin pin in cmp.GetPinList())
                    {
                        IODBObject po = pin.GetIPinPad(outsideBotlayer, cmp);
                        if (po != null)
                        {
                            IPadSpecifics os = (IPadSpecifics)po.GetSpecifics();
                            if (os.Type == PCBI.Symbol_Type.r)
                            {
                                cmp.ObjectColor = Color.Blue;
                                cmp.AddComponentAttribute("techno", "thr");
                                count++;

                                break;
                            }
                        }
                    }
                }
            }

            parent.UpdateView();
        }
예제 #7
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
            }
        }
        public void Execute(IPCBIWindow parent)
        {
            IStep     step          = parent.GetCurrentStep();
            IFilter   filter        = new IFilter(parent);
            IODBLayer layerPolygons = filter.CreateEmptyODBLayer("polygons_n", step.Name);

            bool polyStart = true;
            List <IODBObject> listOfSelection = step.GetSelectedElements();

            PCBI.MathUtils.IPolyClass poly = new PCBI.MathUtils.IPolyClass();

            foreach (IODBObject obj in listOfSelection)
            {
                IObjectSpecificsD os = obj.GetSpecificsD();

                if (os.GetType() == typeof(IArcSpecificsD))
                {
                    IArcSpecificsD aEdge = (IArcSpecificsD)os;

                    if (polyStart)
                    {
                        polyStart = false;
                    }
                    poly.AddEdge(aEdge.Start, aEdge.End, aEdge.Center, aEdge.ClockWise);
                }
                else if (os.GetType() == typeof(ILineSpecificsD))
                {
                    ILineSpecificsD aEdge = (ILineSpecificsD)os;
                    if (polyStart)
                    {
                        polyStart = false;
                    }
                    poly.AddEdge(aEdge.Start, aEdge.End);
                }
            }

            if (poly.GetSubPolygons().Count > 0)
            {
                foreach (PCBI.MathUtils.IPolyClass polyC in poly.GetSubPolygons())
                {
                    if (polyC.GetBounds().Width > 0.001 && polyC.GetBounds().Height > 0.001)
                    {
                        IODBObject surfaceFromPoly = polyC.GetSurfaceFromPolygon(layerPolygons);
                    }
                }
                layerPolygons.EnableLayer(true);
            }
            else
            {
                IODBObject suf = poly.GetSurfaceFromPolygon(layerPolygons);
                layerPolygons.EnableLayer(true);
            }

            parent.UpdateView();
            IMatrix matrix = parent.GetMatrix();

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

            if (step == null)
            {
                return;
            }

            List <string> columsStrings = new List <string>();

            columsStrings.Add("Analyse Resource");
            columsStrings.Add("Reference");
            columsStrings.Add("Distance");
            columsStrings.Add("Rule");
            columsStrings.Add("Start");
            columsStrings.Add("End");
            PCB_Investigator.PCBIWindows.PCBIResultDialog resultDLG = new PCB_Investigator.PCBIWindows.PCBIResultDialog(columsStrings);
            double unit     = 1;
            double distance = PCBI.MathUtils.IMath.MM2Mils(1.0f);

            if (parent.GetUnit())
            {
                unit = 25.4;
                //MessageBox.Show("Component to Outline distance: " + PCBI.MathUtils.IMath.Mils2MM(distance).ToString("N3") + " micron", "DRC Component to Board Outline");
            }
            else
            {
                //MessageBox.Show("Component to Outline distance: " + distance.ToString("N3") + " mils", "DRC Component to Board Outline");
                unit = 1;
            }
            foreach (ICMPObject cmp in step.GetAllCMPObjects())
            {
                PCBI.MathUtils.IPolyClass CMP_Poly = cmp.GetPolygonOutline(false);
                IODBObject boardOutline            = parent.GetCurrentStep().GetPCBOutlineAsODBObject();
                IPolyClass polyOutline             = boardOutline.GetPolygonOutline();
                PointD     start            = new PointD(0, 0);
                PointD     end              = new PointD(0, 0);
                double     measuredDistance = cmp.GetPolygonOutline().DistanceTo(polyOutline, ref start, ref end);
                if (measuredDistance < distance)
                {
                    ListViewItem lvi = new ListViewItem("Cpmp2Outline");
                    lvi.SubItems.Add(cmp.Ref);
                    lvi.SubItems.Add((measuredDistance * unit).ToString());
                    lvi.SubItems.Add((distance * unit).ToString());
                    lvi.SubItems.Add((start * unit).ToString());
                    lvi.SubItems.Add((end * unit).ToString());
                    lvi.Tag = cmp;
                    resultDLG.AddListViewItem(lvi);
                }
            }

            resultDLG.ItemSelectionChanged += ResultDLG_ItemSelectionChanged1;;
            resultDLG.Size = new Size(500, 350);
            resultDLG.Show();
        }
        private static void CreateVertLine(IFilter filter, IODBLayer rasterLayer, int shapeIndex, int y, int x)
        {
            IODBObject      rasterLine = filter.CreateLine(rasterLayer);
            ILineSpecificsD line       = (ILineSpecificsD)rasterLine.GetSpecificsD();

            line.Start      = new PCBI.MathUtils.PointD(x, y);
            line.End        = new PCBI.MathUtils.PointD(x, y + 50);
            line.ShapeIndex = shapeIndex;

            rasterLine.SetSpecifics(line);
        }
        private void CopyAllViasToNewLayer(IPCBIWindow parent, string layerName, string newLayerName)
        {
            IStep curStep = parent.GetCurrentStep();

            if (curStep == null)
            {
                MessageBox.Show("No Job loaded, please load a job before start this script!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            ILayer relevantLayer = curStep.GetLayer(layerName);
            ILayer NewLayer      = curStep.GetLayer(newLayerName);

            if (NewLayer == null || relevantLayer == null || !(NewLayer is IODBLayer))
            {
                MessageBox.Show("Check Layers, something is wrong!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            List <IODBObject> ViaList = new List <IODBObject>();

            //check all elements for via attribute
            foreach (IObject obj in relevantLayer.GetAllLayerObjects())
            {
                if (obj is IODBObject)
                {
                    if (((IODBObject)obj).Type == IObjectType.Pad)
                    {
                        Dictionary <PCBI.FeatureAttributeEnum, string> attributesOfPad = ((IODBObject)obj).GetAttributesDictionary();

                        if (attributesOfPad.ContainsKey(PCBI.FeatureAttributeEnum.pad_usage))
                        {
                            if (attributesOfPad[PCBI.FeatureAttributeEnum.pad_usage] == "via")
                            {
                                ViaList.Add((IODBObject)obj);
                            }
                        }
                    }
                }
            }
            IFilter filter = new IFilter(parent); //to create copies on new layer

            //add vias to new layer
            foreach (IODBObject viaPad in ViaList)
            {
                IPadSpecificsD padInfo = (IPadSpecificsD)viaPad.GetSpecificsD();

                int toolNr = IFilter.AddToolDefinitionRound((IODBLayer)NewLayer, (float)padInfo.Diameter, -1);

                IODBObject newViaPad = filter.CreatePad((IODBLayer)NewLayer);

                newViaPad.SetSpecifics(padInfo, toolNr);
                newViaPad.SetAttribute("pad_usage=via");
            }
        }
예제 #12
0
        public void CreateCopperLines()
        {
            IFilter filter = new IFilter(Parent);

            IStep curStep = Parent.GetCurrentStep();

            if (curStep == null)
            {
                MessageBox.Show("No Job loaded, please load a job before start this script!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                return;
            }
            IODBLayer fiducialLayer = filter.CreateEmptyODBLayer("copper", curStep.Name);

            if (fiducialLayer == null)
            {
                MessageBox.Show("Can't create new layer!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                return;
            }

            float outerDiameter = 1800;

            int shapeIndex = IFilter.AddToolDefinitionRound(fiducialLayer, outerDiameter / 25.4f, 0);

            PCBI.MathUtils.PointD startLine = new PCBI.MathUtils.PointD(0, 0);
            float distance = 2540 / 25.4f;

            for (int y = 0; y < 39; y++)
            {
                float lastX = 0;
                for (int i = 0; i < 63; i++)
                {
                    IODBObject      line = filter.CreateLine(fiducialLayer);
                    ILineSpecificsD ps   = new ILineSpecificsD();
                    ps.Start = new PCBI.MathUtils.PointD(startLine.X, startLine.Y);
                    float lineEnd = lastX + distance;
                    ps.End        = new PCBI.MathUtils.PointD(lineEnd, startLine.Y);
                    lastX         = lineEnd;
                    ps.ShapeIndex = shapeIndex;
                    ps.Positive   = true;
                    line.SetSpecifics(ps);
                    startLine.X += distance;
                }
                startLine.Y += distance;
                startLine.X  = 0;
            }
            IMatrix matrix = Parent.GetMatrix();

            matrix.UpdateDataAndList();
            Parent.UpdateView();
        }
        public void Execute(IPCBIWindow parent)
        {
            IFilter filter = new IFilter(parent);

            IStep curStep = parent.GetCurrentStep();

            if (curStep == null)
            {
                MessageBox.Show("No Job loaded, please load a job before start this script!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                return;
            }

            IODBLayer fiducialLayer = filter.CreateEmptyODBLayer("fiducial", curStep.Name);

            if (fiducialLayer == null)
            {
                MessageBox.Show("Can't create new layer!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                return;
            }

            int shapeIndex = IFilter.AddToolDefinitionDonut(fiducialLayer, (float)IMath.MM2Mils(2), (float)IMath.MM2Mils(1), -1);

            IODBObject pad = filter.CreatePad(fiducialLayer);

            PointD FidPoint = new PointD(IMath.MM2Mils(3), IMath.MM2Mils(3));

            pad.SetSpecifics(new IPadSpecificsD()
            {
                Location = FidPoint, ShapeIndex = shapeIndex, Positive = true
            });
            IAttributeElement attribute = new IAttributeElement(PCBI.FeatureAttributeEnum.fiducial_name);

            attribute.Value = "fid1";
            IAttribute.SetAttribute(attribute, pad);

            FidPoint = new PointD(IMath.MM2Mils(3), IMath.MM2Mils(147));
            pad      = filter.CreatePad(fiducialLayer);
            pad.SetSpecifics(new IPadSpecificsD()
            {
                Location = FidPoint, ShapeIndex = shapeIndex, Positive = true
            });
            attribute       = new IAttributeElement(PCBI.FeatureAttributeEnum.fiducial_name);
            attribute.Value = "fid1";
            IAttribute.SetAttribute(attribute, pad);
            parent.UpdateControlsAndResetView();
        }
예제 #14
0
        public void Execute(IPCBIWindow parent)
        {
            if (parent.GetCurrentStep() == null)
            {
                return;
            }
            IStep   step   = parent.GetCurrentStep();
            IFilter filter = new IFilter(parent);

            if (parent.GetCurrentStep() == null)
            {
                return;
            }

            if (step.GetCMPLayer(true) != null)
            {
                step.GetCMPLayer(true).EnableLayer(true);
            }
            if (step.GetCMPLayer(false) != null)
            {
                step.GetCMPLayer(false).EnableLayer(true);
            }
            double distance = PCBI.MathUtils.IMath.MM2Mils(0.5f);

            if (parent.GetUnit())
            {
                MessageBox.Show("Component to Outline distance: " + PCBI.MathUtils.IMath.Mils2MM(distance).ToString("N3") + " micron", "DRC Component to Board Outline");
            }
            else
            {
                MessageBox.Show("Component to Outline distance: " + distance.ToString("N3") + " mils", "DRC Component to Board Outline");
            }
            foreach (ICMPObject cmp in step.GetAllCMPObjects())
            {
                PCBI.MathUtils.IPolyClass CMP_Poly = cmp.GetPolygonOutline(false);
                IODBObject boardOutline            = parent.GetCurrentStep().GetPCBOutlineAsODBObject();
                IPolyClass polyOutline             = boardOutline.GetPolygonOutline();
                PointD     start = new PointD(0, 0);
                PointD     end   = new PointD(0, 0);

                if (cmp.GetPolygonOutline().DistanceTo(polyOutline, ref start, ref end) < distance)
                {
                    cmp.Select(true);
                }
            }
            parent.UpdateView();
        }
        private void SetOriginBotLeft(IPCBIWindow parent)
        {
            IStep              step           = parent.GetCurrentStep();
            IMatrix            PCB_Matrix     = parent.GetMatrix();
            IODBObject         profile        = step.GetPCBOutlineAsODBObject();
            ISurfaceSpecificsD profileSurface = (ISurfaceSpecificsD)profile.GetSpecificsD();;

            RectangleD profileRect = profileSurface.GetBounds();
            PointD     OriginPoint = new PointD(-profileRect.Left, -profileRect.Top);;

            foreach (string layerName in PCB_Matrix.GetAllBoardLayerNames(true))
            {
                step.GetLayer(layerName).MoveLayer(OriginPoint.ToPointF());
            }
            profile.SetOffset(OriginPoint);

            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)
        {
            IStep step = parent.GetCurrentStep();

            if (step == null)
            {
                return;
            }

            IFilter   PCBI_filter     = new IFilter(parent);
            IODBLayer newOutlineLayer = PCBI_filter.CreateEmptyODBLayer("poly_to_line", step.Name);

            float LineWith = 10;     //diameter symbol

            foreach (IODBObject obj in step.GetSelectedElements())
            {
                foreach (IObjectSpecifics os in obj.GetOutline())
                {
                    if (os.GetType() == typeof(ILineSpecifics))
                    {
                        ILineSpecifics lineEdges = (ILineSpecifics)os;
                        IODBObject     line      = PCBI_filter.CreateLine(newOutlineLayer);
                        lineEdges.ShapeIndex = CheckShapeIndexRound(PCBI_filter, newOutlineLayer, LineWith);
                        lineEdges.Type       = PCBI.Symbol_Type.r;
                        line.SetSpecifics(lineEdges, lineEdges.ShapeIndex);
                    }
                    else if (os.GetType() == typeof(IArcSpecifics))
                    {
                        IArcSpecifics arcEdges = (IArcSpecifics)os;
                        IODBObject    arc      = PCBI_filter.CreateArc(newOutlineLayer);
                        arcEdges.ShapeIndex = CheckShapeIndexRound(PCBI_filter, newOutlineLayer, LineWith);
                        arcEdges.Type       = PCBI.Symbol_Type.r;
                        arc.SetSpecifics(arcEdges, arcEdges.ShapeIndex);
                    }
                }
            }
            parent.UpdateView();
            IMatrix matrix = parent.GetMatrix();

            matrix.UpdateDataAndList();
        }
예제 #18
0
        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 layers
                }
                ILayer Layer = step.GetLayer(layerName);
                if (Layer is IODBLayer)
                {
                    List <IODBObject> objectsToDelete = new List <IODBObject>();
                    IODBLayer         layer           = (IODBLayer)Layer;
                    foreach (IODBObject obj in layer.GetAllLayerObjects())
                    {
                        if (profile.IsPointOfSecondObjectIncluded(obj))
                        {
                            //inside not delete
                        }
                        else
                        {
                            objectsToDelete.Add(obj);
                        }
                    }
                    layer.RemoveObjects(objectsToDelete);
                }
            }
            Parent.UpdateView();
        }
        private static bool?CheckPadsForFreeMask(IODBLayer SMLayer, IODBObject checkingPad)
        {
            if (checkingPad.Type == IObjectType.Pad)
            {
                bool foundFreeArea = false;
                //check is it free on mask layer?

                #region without cmps
                foreach (IODBObject maskObjects in SMLayer.GetAllObjectInRectangle(checkingPad.GetBoundsD()))
                {
                    if (maskObjects.Bounds.Contains(checkingPad.Bounds))                                                                             //bounds included in mask object?
                    {
                        if (!maskObjects.DoesIntersect(checkingPad) || maskObjects.GetPolygonOutline().isEqualsTol(checkingPad.GetPolygonOutline())) //no intersection?
                        {
                            if (maskObjects.Type == IObjectType.Surface)
                            {
                                //surface is special with holes and convex or concave elements -> one more test
                                if (maskObjects.IsPointOfSecondObjectIncluded(checkingPad))
                                {
                                    foundFreeArea = true;
                                    break;
                                }
                            }
                            else
                            {
                                //mask object should be free!
                                foundFreeArea = true;
                                break;
                            }
                        }
                    }
                }
                #endregion

                return(foundFreeArea);
            }
            return(null);
        }
예제 #20
0
        public void Execute(IPCBIWindow parent)
        {
            //only for current step
            IStep step = parent.GetCurrentStep();

            List <INet> allNets           = step.GetNets();
            IODBLayer   topSignal         = step.GetOutsideODBLayer(true);
            IODBLayer   botSignal         = step.GetOutsideODBLayer(false);
            int         countDifferentces = 0;

            foreach (INet net in allNets)
            {
                foreach (INetObject cmpPinCombi in net.ComponentList)
                {
                    IPin pinRel = cmpPinCombi.ICMP.GetPin(cmpPinCombi.PinIndex);

                    string netName = pinRel.GetNetNameOnIPin(cmpPinCombi.ICMP);

                    IODBObject relPad = pinRel.GetIPinPad(cmpPinCombi.ICMP.PlacedTop?topSignal:botSignal, cmpPinCombi.ICMP);

                    if (relPad != null && relPad.NetName != netName)
                    {
                        pinRel.SetPinColor(Color.AliceBlue, cmpPinCombi.ICMP);
                        countDifferentces++;
                    }
                    else
                    {
                        pinRel.SetPinColor(Color.BurlyWood, cmpPinCombi.ICMP);
                    }
                }
            }

            //you can add some code to show a report by using countDifferentces

            parent.UpdateView();
        }
        public void Execute(IPCBIWindow parent)
        {
            //this script replace mini arcs by lines
            try
            {
                IStep step = parent.GetCurrentStep();

                if (step == null)
                {
                    return;
                }

                double  minLenghtArcToReplaceByLine = IMath.MM2Mils(0.02); //20?m maximum for arcs
                IFilter objectCreator = new IFilter(parent);

                foreach (string layerName in step.GetAllLayerNames()) //check all layer
                {
                    ILayer gerberLayer = step.GetLayer(layerName);

                    if (gerberLayer == null)
                    {
                        continue;
                    }

                    if (gerberLayer is ICMPLayer)
                    {
                        continue;                           //should not be for gerberlayers
                    }
                    if (gerberLayer is IPictureLayer)
                    {
                        continue;                               //should not be for gerberlayers
                    }
                    //gerber layers always contain IODBObjects
                    foreach (IODBObject obj in gerberLayer.GetAllLayerObjects())
                    {
                        if (obj.Type == IObjectType.Arc)
                        {
                            #region one arc
                            IArcSpecificsD arc = (IArcSpecificsD)obj.GetSpecificsD();

                            double radius = IMath.DistancePointToPoint(arc.Start, arc.Center);
                            double angle  = IMath.GetAngle(arc.Start, arc.End, arc.Center, arc.ClockWise); //always >=0

                            if (angle > 0)                                                                 //ODB++ spec define arcs with Start == End as full circles (angle = 0 in this calculation)
                            {
                                double bogen = 2 * Math.PI * radius * angle / 360;

                                if (bogen < minLenghtArcToReplaceByLine && arc.PenWidth > bogen)//simple condition to identify mini arcs
                                {
                                    //replace by line
                                    IODBObject lineObj = objectCreator.CreateLine((IODBLayer)gerberLayer); //we know it's a gerber layer -> it must be a IODBLayer

                                    lineObj.SetSpecifics(new ILineSpecificsD()
                                    {
                                        Start = arc.Start, End = arc.End, ShapeIndex = arc.ShapeIndex, Positive = arc.Positive
                                    });

                                    if (!obj.ReplaceItemBy(lineObj)) //replace it
                                    {
                                        Console.WriteLine("Could not replace item!");
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error! " + ex.ToString());
            }
            parent.UpdateView(); //to show the replaced elements
        }
        public void Execute(IPCBIWindow parent)
        {
            IStep step = parent.GetCurrentStep();

            if (step == null)
            {
                return;
            }

            if (step.GetSelectedElementsCount() == 2) //this script is optimiezd for two line elements
            {
                List <IODBObject> selectedElements = step.GetSelectedElements();

                IODBObject obj1 = selectedElements[0];
                IODBObject obj2 = selectedElements[1];

                bool firstArc  = false;
                bool secondArc = false;
                if (obj1.Type == IObjectType.Arc)
                {
                    firstArc = true;
                }
                if (obj2.Type == IObjectType.Arc)
                {
                    secondArc = true;
                }

                if (!firstArc && obj1.Type != IObjectType.Line)
                {
                    return;
                }
                else if (!secondArc && obj2.Type != IObjectType.Line)
                {
                    return;
                }
                ILineSpecificsD obS1;
                ILineSpecificsD obS2;
                if (firstArc)
                {
                    obS1 = new ILineSpecificsD();

                    IArcSpecificsD arcS1 = (IArcSpecificsD)obj1.GetSpecificsD();
                    obS1.Start = arcS1.Start;
                    obS1.End   = arcS1.End;
                }
                else
                {
                    obS1 = (ILineSpecificsD)obj1.GetSpecificsD();
                }
                if (secondArc)
                {
                    obS2 = new ILineSpecificsD();

                    IArcSpecificsD arcS2 = (IArcSpecificsD)obj2.GetSpecificsD();
                    obS2.Start = arcS2.Start;
                    obS2.End   = arcS2.End;
                }
                else
                {
                    obS2 = (ILineSpecificsD)obj2.GetSpecificsD();
                }

                //make simple check for crossing point, this is nearly correct for arc endings
                PCBI.MathUtils.PointD crossingPoint = PCBI.MathUtils.IMath.CrossingPoint(obS1.Start, obS1.End, obS2.Start, obS2.End, false);

                if (PCBI.MathUtils.PointD.InfPoint == crossingPoint)
                {
                    return;                                                  //parallel lines do not work
                }
                #region set ends of lines to the crossing Point

                if (!firstArc)
                {
                    if (PCBI.MathUtils.IMath.DistancePointToPoint(crossingPoint, obS1.End) < PCBI.MathUtils.IMath.DistancePointToPoint(crossingPoint, obS1.Start))
                    {
                        obS1.End = crossingPoint;
                    }
                    else
                    {
                        obS1.Start = crossingPoint;
                    }

                    obj1.SetSpecifics(obS1);
                }
                else
                {
                    //special case for arc
                    IArcSpecificsD arcS1 = (IArcSpecificsD)obj1.GetSpecificsD();
                    if (PCBI.MathUtils.IMath.DistancePointToPoint(crossingPoint, obS1.End) < PCBI.MathUtils.IMath.DistancePointToPoint(crossingPoint, obS1.Start))
                    {
                        arcS1.End = crossingPoint;
                    }
                    else
                    {
                        arcS1.Start = crossingPoint;
                    }

                    obj1.SetSpecifics(arcS1);
                    obj1.UpdateInternal();
                }

                if (!secondArc)
                {
                    if (PCBI.MathUtils.IMath.DistancePointToPoint(crossingPoint, obS2.End) < PCBI.MathUtils.IMath.DistancePointToPoint(crossingPoint, obS2.Start))
                    {
                        obS2.End = crossingPoint;
                    }
                    else
                    {
                        obS2.Start = crossingPoint;
                    }

                    obj2.SetSpecifics(obS2);
                }
                else
                {
                    //special case for arc
                    IArcSpecificsD arcS2 = (IArcSpecificsD)obj2.GetSpecificsD();
                    if (PCBI.MathUtils.IMath.DistancePointToPoint(crossingPoint, arcS2.End) < PCBI.MathUtils.IMath.DistancePointToPoint(crossingPoint, arcS2.Start))
                    {
                        arcS2.End = crossingPoint;
                    }
                    else
                    {
                        arcS2.Start = crossingPoint;
                    }

                    obj2.SetSpecifics(arcS2);
                    obj2.UpdateInternal();
                }
                #endregion
            }

            parent.UpdateView();
        }
        public void Execute(IPCBIWindow parent)
        {
            IStep     step   = parent.GetCurrentStep();
            IODBLayer layer  = (IODBLayer)step.GetLayer("top");
            IFilter   filter = new IFilter(parent);

            // Pins
            foreach (ICMPObject cmp in step.GetAllCMPObjects())
            {
                foreach (IPin pin in cmp.GetPinList())
                {
                    IODBObject        outlinePolygon = filter.CreatePolygon(layer);
                    ISurfaceSpecifics specOutline    = (ISurfaceSpecifics)outlinePolygon.GetSpecifics();
                    bool   polyStart  = true;
                    PointF StartPoint = new PointF(0, 0);
                    PointF EndPoint   = new PointF(0, 0);
                    foreach (IEdge edge in pin.GetPolygonOutline(cmp).GetEdges())
                    {
                        if (polyStart)
                        {
                            polyStart  = false;
                            StartPoint = new PointF((float)edge.Begin.X, (float)edge.Begin.Y);
                            specOutline.StartPolygon(false, StartPoint);


                            if (edge is IArcEdge)
                            {
                                IArcEdge aEdge  = (IArcEdge)edge;
                                PointF   start  = new PointF((float)aEdge.Begin.X, (float)aEdge.Begin.Y);
                                PointF   end    = new PointF((float)aEdge.End.X, (float)aEdge.End.Y);
                                PointF   center = new PointF((float)aEdge.Center.X, (float)aEdge.Center.Y);
                                specOutline.AddArc(start, end, center, aEdge.ClockWise);
                                if (aEdge.ClockWise)
                                {
                                    EndPoint = end;
                                }
                                else
                                {
                                    EndPoint = start;
                                }
                            }
                            else if (edge is ILineEdge)
                            {
                                ILineEdge aEdge = (ILineEdge)edge;
                                PointF    start = new PointF((float)aEdge.Begin.X, (float)aEdge.Begin.Y);
                                PointF    end   = new PointF((float)aEdge.End.X, (float)aEdge.End.Y);
                                specOutline.AddLine(start, end);
                                EndPoint = end;
                            }
                        }
                        else
                        if (edge is IArcEdge)
                        {
                            IArcEdge aEdge  = (IArcEdge)edge;
                            PointF   start  = new PointF((float)aEdge.Begin.X, (float)aEdge.Begin.Y);
                            PointF   end    = new PointF((float)aEdge.End.X, (float)aEdge.End.Y);
                            PointF   center = new PointF((float)aEdge.Center.X, (float)aEdge.Center.Y);
                            specOutline.AddArc(start, end, center, aEdge.ClockWise);
                            if (aEdge.ClockWise)
                            {
                                EndPoint = end;
                            }
                            else
                            {
                                EndPoint = start;
                            }
                        }
                        else if (edge is ILineEdge)
                        {
                            ILineEdge aEdge = (ILineEdge)edge;
                            PointF    start = new PointF((float)aEdge.Begin.X, (float)aEdge.Begin.Y);
                            PointF    end   = new PointF((float)aEdge.End.X, (float)aEdge.End.Y);
                            specOutline.AddLine(start, end);
                            EndPoint = end;
                        }
                    }
                    //specOutline.AddLine(EndPoint, StartPoint);
                    specOutline.EndPolygon(); //close the new contour
                    outlinePolygon.SetSpecifics(specOutline);
                }
            }
            parent.UpdateView();
        }
        public void Execute(IPCBIWindow parent)
        {
            IFilter filter = new IFilter(parent);

            IStep curStep = parent.GetCurrentStep();

            if (curStep == null)
            {
                return;
            }

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

            //create list with all selected elements to make a new symbol of it
            List <IObjectSpecificsD> newSymbolSpecs = new List <IObjectSpecificsD>();
            string relLayerName = "";

            PCBI.MathUtils.RectangleD bounds = new PCBI.MathUtils.RectangleD();
            int indexOfLastElement           = 1;

            foreach (IODBObject obj in selectedElements)
            {
                newSymbolSpecs.Add(obj.GetSpecificsD());
                relLayerName = obj.GetParentLayerName();
                if (bounds == RectangleD.Empty)
                {
                    bounds = obj.GetBoundsD();
                }
                else
                {
                    bounds = PCBI.MathUtils.RectangleD.Union(bounds, obj.GetBoundsD());
                }
                indexOfLastElement = obj.GetIndexOnLayer();
            }

            IODBLayer relLayer = (IODBLayer)curStep.GetLayer(relLayerName);

            if (relLayer == null)
            {
                return;
            }

            //create new symbol for pads, the name must be unique. We try it with the index of one of the elements.
            int nr = IFilter.AddToolDefinitionSpecial(relLayer, parent, "testsymbol3" + indexOfLastElement, newSymbolSpecs, -bounds.GetMidPoint().X, -bounds.GetMidPoint().Y);

            if (nr < 0)
            {
                //no new symbol was created, maybe name is already existing
                return;
            }

            //delete old elements
            IAutomation.SuppressUserNotifications = false; //otherwise the delete action will be blocked
            parent.UIAction.Execute(ID_ActionItem.ID_DELETE);

            IODBObject pad = filter.CreatePad(relLayer);

            IPadSpecificsD padSpec = (IPadSpecificsD)pad.GetSpecificsD();

            padSpec.Location = bounds.GetMidPoint();
            pad.SetSpecifics(padSpec, nr);
            pad.SetAttribute("new symbol attribute");

            pad.Select(true);

            parent.UpdateView();
        }
        private static void CreateComponents(bool top, ICMPLayer CMPLayer, IODBLayer frontLayer, IODBLayer sideLayer, float offset, IFilter filter, bool allValuesInMM)
        {
            if (CMPLayer == null)
            {
                return;
            }
            foreach (ICMPObject component in CMPLayer.GetAllLayerObjects())
            {
                float height = (float)component.CompHEIGHT;
                IPackageSpecificsD usedPackage = component.GetPackageSpecificsD();
                if (height == 0)
                {
                    height = usedPackage.Height;
                }
                if (height == 0)
                {
                    #region check height
                    //check attributes
                    foreach (string attrib in component.GetComponentAttributes())
                    {
                        if (attrib.ToLowerInvariant().Contains("height"))
                        {
                            string[] attribtValueFinder = attrib.Split('=');

                            if (attribtValueFinder.Length > 1)
                            {
                                float.TryParse(attribtValueFinder[1], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out height);
                            }
                            else if (attribtValueFinder[0].Contains("\'"))
                            {
                                string subStr = attribtValueFinder[0].Substring(attribtValueFinder[0].IndexOf('\'') + 1);
                                if (subStr.Contains("\'"))
                                {
                                    subStr = subStr.Substring(0, subStr.IndexOf('\''));
                                    float.TryParse(subStr, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out height);
                                }
                            }
                        }
                    }
                    #endregion
                }
                if (allValuesInMM)
                {
                    height = (float)IMath.MM2Mils(height);
                }

                #region front layer
                int componentFront = IFilter.AddToolDefinitionRect(frontLayer, (float)component.Bounds.Width, height, (float)component.Bounds.Width, false);

                IODBObject cmpFront = filter.CreatePad(frontLayer);

                IPadSpecificsD padCMPFront = (IPadSpecificsD)cmpFront.GetSpecificsD();

                if (top)
                {
                    padCMPFront.Location = new PointD(component.Bounds.X + component.Bounds.Width / 2, offset + height / 2);
                }
                else
                {
                    padCMPFront.Location = new PointD(component.Bounds.X + component.Bounds.Width / 2, -(offset + height / 2));
                }

                cmpFront.SetSpecifics(padCMPFront, componentFront);
                cmpFront.FreeText = component.Ref;
                if (top)
                {
                    cmpFront.ObjectColorTemporary(Color.Silver);
                }
                else
                {
                    cmpFront.ObjectColorTemporary(Color.Gray);
                }
                #endregion
                #region side layer
                int componentSide = IFilter.AddToolDefinitionRect(sideLayer, (float)component.Bounds.Height, (float)component.Bounds.Height, height, false);

                IODBObject cmpSide = filter.CreatePad(sideLayer);

                IPadSpecificsD padCMPSide = (IPadSpecificsD)cmpSide.GetSpecificsD();

                if (top)
                {
                    padCMPSide.Location = new PointD(offset + height / 2, component.Bounds.Y + component.Bounds.Height / 2);
                }
                else
                {
                    padCMPSide.Location = new PointD(-(offset + height / 2), component.Bounds.Y + component.Bounds.Height / 2);
                }

                cmpSide.SetSpecifics(padCMPSide, componentSide);
                cmpSide.FreeText = component.Ref;
                if (top)
                {
                    cmpSide.ObjectColorTemporary(Color.Silver);
                }
                else
                {
                    cmpSide.ObjectColorTemporary(Color.Gray);
                }
                #endregion
            }
        }
        void CreateForOneSide(bool top, IStep step, IFilter filter, string PackageName, List <string> DrillLayers)
        {
            ICMPLayer compLayer = step.GetCMPLayer(top);

            if (compLayer == null)
            {
                return;
            }

            IODBLayer newLayer = filter.CreateEmptyODBLayer("testpoint_locations_" + (top ? "top" : "bot"), step.Name);

            if (newLayer == null)
            {
                return;
            }

            List <IODBLayer> allDrillLayers = new List <IODBLayer>();

            foreach (string drillName in DrillLayers)
            {
                allDrillLayers.Add((IODBLayer)step.GetLayer(drillName));
            }

            int shapeIndex           = IFilter.AddToolDefinitionRound(newLayer, 75);
            int shapeIndexConnection = IFilter.AddToolDefinitionRound(newLayer, 1);

            foreach (ICMPObject cmp in compLayer.GetAllLayerObjects())
            {
                if (!cmp.UsedPackageName.Contains(PackageName))
                {
                    continue;
                }

                IODBObject     markerPad = filter.CreatePad(newLayer);
                IPadSpecificsD pad       = (IPadSpecificsD)markerPad.GetSpecificsD();

                pad.Location   = new PCBI.MathUtils.PointD(cmp.Position);
                pad.ShapeIndex = shapeIndex;

                markerPad.SetSpecifics(pad);
                markerPad.ObjectColor = Color.Green;
                markerPad.SetAttribute("Steel needle <BST> (Testpoint)");
                bool special = false;
                foreach (IODBLayer drillLayer in allDrillLayers)
                {
                    #region check drills
                    foreach (IODBObject drill in drillLayer.GetAllObjectsOnPosition(cmp.Position))
                    {
                        Dictionary <PCBI.FeatureAttributeEnum, string> attribs = drill.GetAttributesDictionary();

                        if (attribs.ContainsKey(PCBI.FeatureAttributeEnum.drill))
                        {
                            if (attribs[PCBI.FeatureAttributeEnum.drill].ToUpperInvariant() == "VIA")
                            {
                                markerPad.ObjectColor = Color.Blue;
                                markerPad.SetAttribute("Pyramid <H> (Via)");
                                special = true;
                                break;
                            }
                        }
                    }
                    if (special)
                    {
                        break;
                    }
                    #endregion
                }
                if (!special)
                {
                    //check for component pin
                    foreach (ICMPObject comp in compLayer.GetAllObjectsOnPosition(cmp.Position))
                    {
                        if (comp == cmp)
                        {
                            continue;              //testpunkt selbst wird ignoriert
                        }
                        foreach (IPin pin in comp.GetPinList())
                        {
                            PCBI.MathUtils.IPolyClass cmpPoly = pin.GetPolygonOutline(comp);
                            if (cmpPoly.PointInPolygon(pad.Location))
                            {
                                markerPad.ObjectColor = Color.Red;
                                markerPad.SetAttribute("Serrated <C>"); //hier evtl noch überprüfen ob pin bzw. body drüber liegt?
                                special = true;                         //oder Serrated with overlapping plastic <CS>
                                break;
                            }
                        }
                        if (special)
                        {
                            break;
                        }
                    }
                }
            }
            foreach (ICMPObject cmp in compLayer.GetAllLayerObjects()) //neue schleife da erst alle pads plaziert werden sollen!
            {
                if (!cmp.UsedPackageName.Contains(PackageName))
                {
                    continue;
                }

                IODBObject      textForPad = filter.CreateText(newLayer);
                ITextSpecificsD text       = (ITextSpecificsD)textForPad.GetSpecificsD();

                text.Text        = cmp.Ref.Remove(0, 2); //Annahme das alle mit TP beginnen
                text.TextSize    = new SizeF(25, 50);
                text.Location    = new PCBI.MathUtils.PointD(cmp.Position.X + 50, cmp.Position.Y - 10);
                text.WidthFactor = 0.6;
                textForPad.SetSpecifics(text);
                textForPad.ObjectColor = Color.DarkGray;

                //text location should not be intersecting!
                List <IObject> otherObjectsOnSameLocation = newLayer.GetAllObjectInRectangle(textForPad.GetBoundsD());
                int            offset     = 50;
                bool           horChecked = false;
                while (otherObjectsOnSameLocation.Count > 1)
                {
                    //move text
                    if (horChecked)
                    {
                        text.Location = new PCBI.MathUtils.PointD(cmp.Position.X, cmp.Position.Y + offset);
                    }
                    else
                    {
                        text.Location = new PCBI.MathUtils.PointD(cmp.Position.X - offset - textForPad.GetBoundsD().Width, cmp.Position.Y - 10);
                    }
                    offset    += 50;
                    horChecked = true;
                    textForPad.SetSpecifics(text);
                    otherObjectsOnSameLocation = newLayer.GetAllObjectInRectangle(textForPad.GetBoundsD());
                }

                IODBObject      connectionLine = filter.CreateLine(newLayer);
                ILineSpecificsD line           = (ILineSpecificsD)connectionLine.GetSpecificsD();

                line.ShapeIndex = shapeIndexConnection;
                line.Start      = new PCBI.MathUtils.PointD(cmp.Position);
                line.End        = new PCBI.MathUtils.PointD(text.Location.X, text.Location.Y + 25);
                connectionLine.SetSpecifics(line);
                connectionLine.ObjectColor = Color.LightGray;
            }
        }
            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)
        {
            string PackageName    = "TESTPUNKT";
            bool   topSide        = true;
            bool   useFlattenStep = true;

            if (!parent.JobIsLoaded)
            {
                return;
            }
            IFilter filter = new IFilter(parent);
            IStep   step   = parent.GetCurrentStep();
            IMatrix matrix = parent.GetMatrix();

            if (matrix == null)
            {
                return;
            }

            step.TurnOffAllLayer();
            step.ClearSelection();
            //nicht für flatten step, da durch Threads zu langsam und dann evtl die neuen Daten wieder gelöscht werden!
            if (!useFlattenStep)
            {
                matrix.DelateLayer("testpoint_locations_top", false);
                matrix.DelateLayer("testpoint_locations_bot", false);
            }
            if (topSide)
            {
                CreateForOneSide(true, step, filter, PackageName, matrix.GetAllDrillLayersForThisLayer(matrix.GetTopSignalLayer()));
            }
            else
            {
                CreateForOneSide(false, step, filter, PackageName, matrix.GetAllDrillLayersForThisLayer(matrix.GetBotSignalLayer()));
            }

            //gitter 500x500

            IODBLayer  rasterLayer = filter.CreateEmptyODBLayer("raster", step.Name);
            int        shapeIndex  = IFilter.AddToolDefinitionRound(rasterLayer, 10);
            RectangleF boundsStep  = step.GetBounds();

            int countYLines = (int)(boundsStep.Height / 500) + 1;
            int countXLines = (int)(boundsStep.Width / 500) + 1;

            for (int y = 0; y <= countYLines; y++)
            {
                for (int x = 0; x <= countXLines; x++)
                {
                    for (int i = 0; i < 5; i++) //5 sublines
                    {
                        int yVal = y * 500;
                        int xVal = x * 500;
                        if (x < countXLines)
                        {
                            CreateHorLine(filter, rasterLayer, shapeIndex, yVal, xVal + i * 100 + 25);
                        }
                        if (y < countYLines)
                        {
                            CreateVertLine(filter, rasterLayer, shapeIndex, yVal + i * 100 + 25, xVal);
                        }
                    }
                }
            }

            for (int y = 0; y < countYLines; y++)
            {
                #region draw text
                IODBObject      textForPad = filter.CreateText(rasterLayer);
                ITextSpecificsD text       = (ITextSpecificsD)textForPad.GetSpecificsD();

                text.Text        = "Y" + (y + 1);
                text.TextSize    = new SizeF(50, 80);
                text.Location    = new PCBI.MathUtils.PointD(-120, y * 500 + 200);
                text.WidthFactor = 1;
                textForPad.SetSpecifics(text);

                //right side
                IODBObject      textForPad2 = filter.CreateText(rasterLayer);
                ITextSpecificsD text2       = (ITextSpecificsD)textForPad.GetSpecificsD();

                text2.Text        = text.Text;
                text2.TextSize    = new SizeF(50, 80);
                text2.Location    = new PCBI.MathUtils.PointD(countXLines * 500 + 120, y * 500 + 200);
                text2.WidthFactor = 1;
                textForPad2.SetSpecifics(text2);
            }
            for (int x = 0; x < countXLines; x++)
            {
                IODBObject      textForPad = filter.CreateText(rasterLayer);
                ITextSpecificsD text       = (ITextSpecificsD)textForPad.GetSpecificsD();

                text.Text        = "X" + (x + 1);
                text.TextSize    = new SizeF(50, 80);
                text.Location    = new PCBI.MathUtils.PointD(x * 500 + 200, -100);
                text.Rotation    = -90;
                text.WidthFactor = 1;
                textForPad.SetSpecifics(text);

                //top side
                IODBObject      textForPad2 = filter.CreateText(rasterLayer);
                ITextSpecificsD text2       = (ITextSpecificsD)textForPad.GetSpecificsD();

                text2.Text        = text.Text;
                text2.TextSize    = new SizeF(50, 80);
                text2.Location    = new PCBI.MathUtils.PointD(x * 500 + 300, countYLines * 500 + 100);
                text2.Rotation    = 90;
                text2.WidthFactor = 1;
                textForPad2.SetSpecifics(text2);
                #endregion
            }

            foreach (string drillName in matrix.GetAllDrillLayerNames())
            {
                IODBLayer drillLayer = (IODBLayer)step.GetLayer(drillName);

                foreach (IODBObject drill in drillLayer.GetAllLayerObjects())
                {
                    Dictionary <PCBI.FeatureAttributeEnum, string> attribs = drill.GetAttributesDictionary();

                    if (drill.Type == IObjectType.Pad && attribs.ContainsKey(PCBI.FeatureAttributeEnum.drill) && attribs.ContainsKey(PCBI.FeatureAttributeEnum.geometry))
                    {
                        if (attribs[PCBI.FeatureAttributeEnum.drill].ToUpperInvariant() == "NON_PLATED" && attribs[PCBI.FeatureAttributeEnum.geometry].ToUpperInvariant() == "ICTAUFNAHME")
                        {
                            IODBObject     drillMarker = filter.CreatePad(rasterLayer);
                            IPadSpecificsD drillSpec   = (IPadSpecificsD)drill.GetSpecificsD();

                            int shapeIndexNew = IFilter.AddToolDefinitionRound(rasterLayer, (float)drillSpec.Diameter);
                            drillSpec.ShapeIndex = shapeIndexNew;
                            drillMarker.SetSpecifics(drillSpec);
                        }
                    }
                }
            }

            matrix.UpdateDataAndList();

            if (!useFlattenStep)
            {
                parent.UIAction.Execute(ID_ActionItem.ID_PRINT_PREVIEW);
            }
        }
        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();
        }
        private static void AddNetInfos(IStep step, IODBLayer parentLayer, String NetName, IODBObject netItem)
        {
            if (NetName.Length == 0) //the default net
            {
                NetName = "$NONE$";
            }

            int  lastNetNr = step.GetNets().Count;
            INet outNet    = step.GetNet(NetName);
            int  netNr     = -1;

            if (outNet == null)
            {
                netNr = step.AddNet(NetName, "", out outNet);
            }
            else
            {
                netNr = outNet.GetNetNumber();
            }

            netItem.PcbNetNumber = outNet.GetNetNumber();                          //set the netinformation to the object
            int newNr = outNet.AddLayerRef(parentLayer.GetLayerName(), lastNetNr); //each net saves a list of all layers are used.

            if (newNr == lastNetNr)
            {
                lastNetNr++;
            }
            parentLayer.SetNetNumber(NetName, netItem.PcbNetNumber);                                       //for each object the layer needs information that this net is used.
            outNet.AddFID(PCBI.FidType.Copper, parentLayer.GetLayerName(), netItem.GetIndexOnLayer(), ""); //this is specific to ODB++, if you don't use it and save the data as ODB++ some information get lost.
        }