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