/// <summary> /// Gets the Attributes attribute. /// </summary> /// <param name="codeElement">The code element.</param> /// <returns>Attributes as a comma-separated list.</returns> private static string GetAttributesAttribute(ICodeElement codeElement) { StringBuilder attributesBuilder = new StringBuilder(); AttributedElement attributedElement = codeElement as AttributedElement; if (attributedElement != null) { for (int attributeIndex = 0; attributeIndex < attributedElement.Attributes.Count; attributeIndex++) { IAttributeElement attribute = attributedElement.Attributes[attributeIndex]; attributesBuilder.Append(attribute.Name); foreach (ICodeElement attributeChild in attribute.Children) { IAttributeElement childAttributeElement = attributeChild as IAttributeElement; if (childAttributeElement != null) { attributesBuilder.Append(", "); attributesBuilder.Append(childAttributeElement.Name); } } if (attributeIndex < attributedElement.Attributes.Count - 1) { attributesBuilder.Append(", "); } } } return(attributesBuilder.ToString()); }
/// <summary> /// Removes an attribute from this element. /// </summary> /// <param name="attributeElement">Attribute element to remove.</param> public void RemoveAttribute(IAttributeElement attributeElement) { if (attributeElement != null && BaseAttributes.Contains(attributeElement)) { lock (_attributesLock) { if (attributeElement != null && BaseAttributes.Contains(attributeElement)) { BaseAttributes.Remove(attributeElement); attributeElement.Parent = null; } } } }
/// <summary> /// Adds an attribute to this code element. /// </summary> /// <param name="attributeElement">Attribute element to add.</param> public void AddAttribute(IAttributeElement attributeElement) { if (attributeElement != null && !BaseAttributes.Contains(attributeElement)) { lock (_attributesLock) { if (attributeElement != null && !BaseAttributes.Contains(attributeElement)) { BaseAttributes.Add(attributeElement); attributeElement.Parent = this; } } } }
private void AddGroup() { FolderBrowserDialog fb = new FolderBrowserDialog(); fb.SelectedPath = Environment.CurrentDirectory; if (fb.ShowDialog() == DialogResult.OK) { string FilePath = fb.SelectedPath; DirectoryInfo di = new DirectoryInfo(FilePath); groupsPerNet.Clear(); foreach (FileInfo fi in di.GetFiles()) { if (fi.Extension.ToLowerInvariant() == ".harness") { AddNetGroup(fi.FullName); } } IStep step = parent.GetCurrentStep(); if (step != null) { List <INet> nets = step.GetNets(); if (nets != null) { foreach (INet net in nets) { string group = null; if (groupsPerNet.ContainsKey(net.NetName)) { group = groupsPerNet[net.NetName].Key; } if (string.IsNullOrWhiteSpace(group)) { IAttribute.RemoveAttribute(PCBI.FeatureAttributeEnum.net_type, net); IAttribute.RemoveAttribute("NET_DESCRIPTION", net, parent); } else { IAttributeElement attr = new IAttributeElement(PCBI.FeatureAttributeEnum.net_type); attr.Value = group; IAttribute.SetAttribute(attr, net); IAttributeElement netDesAttr = IAttributeElement.CreateUserAttribute("NET_DESCRIPTION", groupsPerNet[net.NetName].Value, PCBI.ODBEntityEnum.Net, parent); IAttribute.SetAttribute(netDesAttr, net); } } } } } }
public void Execute(IPCBIWindow parent) { IStep step = parent.GetCurrentStep(); if (step == null) { return; } string layernameTopHeightRestrictions = "drc_comp"; ICMPLayer topCMPLayer = step.GetCMPLayer(true); //for bottom change here to false ILayer HeightRestirctionLayer = step.GetLayer(layernameTopHeightRestrictions); // check each cmp for height restrictions foreach (ICMPObject cmp in topCMPLayer.GetAllLayerObjects()) { foreach (IODBObject surface in HeightRestirctionLayer.GetAllObjectInRectangle(cmp.Bounds)) { if (surface.IsPointOfSecondObjectIncluded(cmp, false)) //intersecting is ok? { //check height of cmp IAttributeElement attributeMaxHeight = null; foreach (IAttributeElement attribute in IAttribute.GetAllAttributes(surface)) { if (attribute.AttributeEnum == PCBI.FeatureAttributeEnum.drc_max_height) { attributeMaxHeight = attribute; break; } } if (attributeMaxHeight == null) { continue; } if (cmp.CompHEIGHT > (double)attributeMaxHeight.Value) //we know this attribute has double values { cmp.ObjectColorTemporary(Color.LightCoral); //change color to highlight cmps //surface.ObjectColorTemporary(Color.Wheat); surface.FreeText = "Check Height of " + cmp.Ref; break; } } } } topCMPLayer.EnableLayer(true); HeightRestirctionLayer.EnableLayer(true); parent.UpdateView(); }
public void Execute(IPCBIWindow parent) { 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(); }
/// <summary> /// Removes all attributes elements. /// </summary> public void ClearAttributes() { lock (_attributesLock) { for (int attributeIndex = 0; attributeIndex < Attributes.Count; attributeIndex++) { IAttributeElement attribute = Attributes[attributeIndex]; if (attribute != null && attribute.Parent != null) { attribute.Parent = null; attributeIndex--; } } BaseAttributes.Clear(); } }
/// <summary> /// Creates a clone of the instance and copies any state. /// </summary> /// <returns>A clone of the instance.</returns> protected override sealed CodeElement DoClone() { AttributedElement clone = DoAttributedClone(); // // Copy state // clone._access = _access; lock (_attributesLock) { for (int attributeIndex = 0; attributeIndex < Attributes.Count; attributeIndex++) { IAttributeElement attribute = Attributes[attributeIndex]; IAttributeElement attributeClone = attribute.Clone() as IAttributeElement; clone.AddAttribute(attributeClone); } } return(clone); }
public static bool Is(this IAttributeElement attributeElement, Type type) { string fullName = attributeElement.GetDeclaration(false).FullName; return(fullName == type.FullName); }
public void Execute(IPCBIWindow parent) { double sizeRouting = PCBI.MathUtils.IMath.MM2Mils(2); //2 mm double sizeCutout = PCBI.MathUtils.IMath.MM2Mils(2); //2 mm double spaceCutout = PCBI.MathUtils.IMath.MM2Mils(100); //100 mm double lengthCutout = PCBI.MathUtils.IMath.MM2Mils(5); //5 mm double sumUpLength = 0; //offset for start IStep step = parent.GetCurrentStep(); if (step == null) { return; } PCBI.MathUtils.IPolyClass polyOfOutline = step.GetPCBOutlinePoly(); if (polyOfOutline.GetEdgeCount() == 0) { return; } IFilter filter = new IFilter(parent); IODBLayer HelperLayer = filter.CreateEmptyODBLayer("rout_outline_helper", step.Name); //this helper layer contains the uncutted line elements IODBLayer outlineLayerRouting = filter.CreateEmptyODBLayer("rout_outline", step.Name); IODBLayer cutoutLayerRouting = filter.CreateEmptyODBLayer("rout_cutout", step.Name); #region clean layers for multi use List <IODBObject> objListToRemove = new List <IODBObject>(); foreach (IODBObject obj in HelperLayer.GetAllLayerObjects()) { objListToRemove.Add(obj); } HelperLayer.RemoveObjects(objListToRemove); objListToRemove = new List <IODBObject>(); foreach (IODBObject obj in cutoutLayerRouting.GetAllLayerObjects()) { objListToRemove.Add(obj); } cutoutLayerRouting.RemoveObjects(objListToRemove); objListToRemove = new List <IODBObject>(); foreach (IODBObject obj in outlineLayerRouting.GetAllLayerObjects()) { objListToRemove.Add(obj); } outlineLayerRouting.RemoveObjects(objListToRemove); #endregion int shapeIndexOutlinediameter = IFilter.AddToolDefinitionRound(HelperLayer, (float)sizeRouting); foreach (PCBI.MathUtils.IEdge edge in polyOfOutline.GetEdges()) { #region outline elements if (edge.Type == IEdgeType.Arc) { IODBObject newArc = filter.CreateArc(HelperLayer); IArcSpecificsD arc = (IArcSpecificsD)newArc.GetSpecificsD(); arc.ClockWise = ((IArcEdge)edge).ClockWise; if (arc.ClockWise) { arc.Start = edge.Begin; arc.End = edge.End; } else { arc.End = edge.Begin; arc.Start = edge.End; } arc.Center = ((PCBI.MathUtils.IArcEdge)edge).Center; arc.ShapeIndex = shapeIndexOutlinediameter; newArc.SetSpecifics(arc); } else { IODBObject newLine = filter.CreateLine(HelperLayer); ILineSpecificsD line = (ILineSpecificsD)newLine.GetSpecificsD(); line.Start = edge.Begin; line.End = edge.End; line.ShapeIndex = shapeIndexOutlinediameter; newLine.SetSpecifics(line); } #endregion } //make one surface of all lines and arcs HelperLayer.CreateLayerNetList(true); HelperLayer.PolygonizeLayer(0, false); PointD lastPToIdentifyHole = PointD.InfPoint; foreach (IODBObject surface in HelperLayer.GetAllLayerObjects()) { #region replace surfaces by routing lines and arcs if (surface.Type != IObjectType.Surface) { continue; } objListToRemove.Add(surface); List <ISurfaceSpecificsD> isle = ((ISurfaceSpecificsD)surface.GetSpecificsD()).SplitInIsleAndHoles(parent); if (isle.Count > 0) { for (int i = 0; i < isle.Count; i++) { bool foundelement = false; foreach (IODBObject linesAndArcs in isle[i].GetOutline()) { if (linesAndArcs.Type == IObjectType.Arc) { #region arc IODBObject newArc = filter.CreateArc(HelperLayer); IArcSpecificsD arc = (IArcSpecificsD)linesAndArcs.GetSpecificsD(); if (lastPToIdentifyHole == PointD.InfPoint || !(lastPToIdentifyHole != arc.Start && lastPToIdentifyHole != arc.End)) { lastPToIdentifyHole = arc.End; } else { break; } newArc.SetSpecifics(arc); #endregion } else { #region line IODBObject newLine = filter.CreateLine(HelperLayer); ILineSpecificsD line = (ILineSpecificsD)linesAndArcs.GetSpecificsD(); if (lastPToIdentifyHole == PointD.InfPoint || line.Start == lastPToIdentifyHole) { lastPToIdentifyHole = line.End; } else { break; } newLine.SetSpecifics(line); #endregion } foundelement = true; } if (foundelement) { break; } } } #endregion } HelperLayer.RemoveObjects(objListToRemove); //surface remove int shapeIndexCutoutdiameter = IFilter.AddToolDefinitionRound(outlineLayerRouting, (float)sizeCutout); int shapeIndexCutoutdiameter2 = IFilter.AddToolDefinitionRound(cutoutLayerRouting, (float)sizeCutout); double sumUpGap = 0; foreach (IODBObject lineOrArc in HelperLayer.GetAllLayerObjects()) { if (lineOrArc.Type == IObjectType.Line) { #region lines ILineSpecificsD line = (ILineSpecificsD)lineOrArc.GetSpecificsD(); double length = IMath.DistancePointToPoint(line.Start, line.End); double lengthComplete = length; while (true) { if (length <= lengthCutout) { #region short lines sumUpLength += lengthCutout; if (sumUpLength > spaceCutout) { sumUpGap += lengthCutout; IODBObject lineObj = filter.CreateLine(cutoutLayerRouting); ILineSpecificsD lineSub = (ILineSpecificsD)lineOrArc.GetSpecificsD(); lineSub.ShapeIndex = shapeIndexCutoutdiameter2; lineSub.Start = IMath.GetPointOnLine(line.Start, line.End, lengthComplete - length); length = 0; lineSub.End = IMath.GetPointOnLine(line.Start, line.End, lengthComplete - length); lineObj.SetSpecifics(lineSub); if (sumUpGap > lengthCutout) { sumUpGap = 0; sumUpLength = 0; } IAttributeElement attribRoutningComp = new IAttributeElement(PCBI.FeatureAttributeEnum.comp); attribRoutningComp.Value = "none"; IAttribute.SetAttribute(attribRoutningComp, lineObj); } else { IODBObject lineObj = filter.CreateLine(outlineLayerRouting); ILineSpecificsD lineSub = (ILineSpecificsD)lineOrArc.GetSpecificsD(); lineSub.ShapeIndex = shapeIndexCutoutdiameter; lineSub.Start = IMath.GetPointOnLine(line.Start, line.End, lengthComplete - length); length = 0; lineSub.End = IMath.GetPointOnLine(line.Start, line.End, lengthComplete - length); lineObj.SetSpecifics(lineSub); IAttributeElement attribRoutningComp = new IAttributeElement(PCBI.FeatureAttributeEnum.comp); attribRoutningComp.Value = "none"; IAttribute.SetAttribute(attribRoutningComp, lineObj); } break; #endregion } else { #region long lines sumUpLength += lengthCutout; if (sumUpLength > spaceCutout || sumUpGap > 0) { sumUpGap += lengthCutout; IODBObject lineObj = filter.CreateLine(cutoutLayerRouting); ILineSpecificsD lineSub = (ILineSpecificsD)lineOrArc.GetSpecificsD(); lineSub.ShapeIndex = shapeIndexCutoutdiameter2; lineSub.Start = IMath.GetPointOnLine(line.Start, line.End, lengthComplete - length); length -= lengthCutout; lineSub.End = IMath.GetPointOnLine(line.Start, line.End, lengthComplete - length); lineObj.SetSpecifics(lineSub); if (sumUpGap > lengthCutout) { sumUpGap = 0; sumUpLength = 0; } IAttributeElement attribRoutningComp = new IAttributeElement(PCBI.FeatureAttributeEnum.comp); attribRoutningComp.Value = "none"; IAttribute.SetAttribute(attribRoutningComp, lineObj); } else { IODBObject lineObj = filter.CreateLine(outlineLayerRouting); ILineSpecificsD lineSub = (ILineSpecificsD)lineOrArc.GetSpecificsD(); lineSub.ShapeIndex = shapeIndexCutoutdiameter; lineSub.Start = IMath.GetPointOnLine(line.Start, line.End, lengthComplete - length); length -= lengthCutout; lineSub.End = IMath.GetPointOnLine(line.Start, line.End, lengthComplete - length); lineObj.SetSpecifics(lineSub); IAttributeElement attribRoutningComp = new IAttributeElement(PCBI.FeatureAttributeEnum.comp); attribRoutningComp.Value = "none"; IAttribute.SetAttribute(attribRoutningComp, lineObj); } #endregion } } #endregion } else if (lineOrArc.Type == IObjectType.Arc) { #region arcs IArcSpecificsD arc = (IArcSpecificsD)lineOrArc.GetSpecificsD(); double arcLength = IMath.DistancePointToPoint(arc.Start, arc.End); sumUpLength += arcLength; if (sumUpLength > spaceCutout || sumUpGap > 0) { sumUpGap += arcLength; IODBObject arcObj = filter.CreateArc(cutoutLayerRouting); arc.ShapeIndex = shapeIndexCutoutdiameter2; arcObj.SetSpecifics(arc); if (sumUpGap > lengthCutout) { sumUpGap = 0; sumUpLength = 0; } IAttributeElement attribRoutningComp = new IAttributeElement(PCBI.FeatureAttributeEnum.comp); attribRoutningComp.Value = "none"; IAttribute.SetAttribute(attribRoutningComp, arcObj); } else { IODBObject arcObj = filter.CreateArc(outlineLayerRouting); arc.ShapeIndex = shapeIndexCutoutdiameter; arcObj.SetSpecifics(arc); IAttributeElement attribRoutningComp = new IAttributeElement(PCBI.FeatureAttributeEnum.comp); attribRoutningComp.Value = "none"; IAttribute.SetAttribute(attribRoutningComp, arcObj); } #endregion } } //additional attributes are .feed, .speed, .rout_flag, .comp. and .rout_chain IMatrix matrix = parent.GetMatrix(); if (matrix != null) { matrix.UpdateDataAndList(); } parent.UpdateView(); }