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