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) { 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(); }