private void SetActiveComponent(IComponent component) { _activeComponent = component; _autoZoom = true; panelPart.Visible = false; gridPcbLibPrimitives.Rows.Clear(); gridSchLibPrimitives.Rows.Clear(); if (_activeComponent != null) { LoadPrimitives(_activeComponent); if (_activeComponent is SchComponent schComponent) { panelPart.Visible = schComponent.PartCount > 1; editPart.Maximum = schComponent.PartCount; editPart.Value = 1; labelPartTotal.Text = $"of {editPart.Maximum}"; } } else { SetActivePrimitives(null); } RequestRedraw(false); }
private void LoadPrimitives(IComponent component, bool activateFirst = false) { Primitive defaultPrimitive = null; if (component is PcbComponent pcbComponent) { var primitives = pcbComponent.Primitives; foreach (var primitive in primitives) { var info = primitive.GetDisplayInfo(); var i = gridPcbLibPrimitives.Rows.Add(primitive.Type, info.Name, info.SizeX?.ToString(_displayUnit), info.SizeY?.ToString(_displayUnit), primitive.Layer.Name); gridPcbLibPrimitives.Rows[i].Tag = primitive; } defaultPrimitive = pcbComponent.Primitives.FirstOrDefault(); } else if (component is SchComponent schComponent) { var pins = schComponent.Primitives.OfType <PinRecord>(); foreach (var pin in pins) { var i = gridSchLibPrimitives.Rows.Add(pin.Designator, pin.Name, pin.Electrical.ToString()); gridSchLibPrimitives.Rows[i].Tag = pin; } defaultPrimitive = pins.FirstOrDefault(); } SetActivePrimitives((activateFirst && defaultPrimitive != null) ? new[] { defaultPrimitive } : null); }