private void LoadFromFile(string fileName) { if (Path.GetExtension(fileName).Equals(".pcblib", StringComparison.InvariantCultureIgnoreCase)) { using (var reader = new PcbLibReader()) { var data = reader.Read(fileName); SetData(data); } } else if (Path.GetExtension(fileName).Equals(".schlib", StringComparison.InvariantCultureIgnoreCase)) { using (var reader = new SchLibReader()) { var data = reader.Read(fileName); SetData(data); } } else if (Path.GetExtension(fileName).Equals(".schdoc", StringComparison.InvariantCultureIgnoreCase)) { using (var reader = new SchDocReader()) { var data = reader.Read(fileName); SetData(data); } } }
private void LoadFromFile(string fileName) { _loading = true; try { SetActiveContainer(null); if (_propertyViewer != null) { _propertyViewer.Close(); _propertyViewer = null; } gridPcbLibComponents.Rows.Clear(); gridSchLibComponents.Rows.Clear(); Application.DoEvents(); if (Path.GetExtension(fileName).Equals(".pcblib", StringComparison.InvariantCultureIgnoreCase)) { tabComponents.SelectTab(tabPcbLib); using (var reader = new PcbLibReader(fileName)) { reader.Read(); foreach (var component in reader.Components) { var index = gridPcbLibComponents.Rows.Add(component.Name, component.Pads, component.Primitives.Count()); gridPcbLibComponents.Rows[index].Tag = component; } _displayUnit = reader.Header.DisplayUnit; _snapGridSize = reader.Header.SnapGridSize; _containers = reader.Components.Cast <IContainer>().ToList(); _renderer = new PcbLibRenderer(); } } else if (Path.GetExtension(fileName).Equals(".schlib", StringComparison.InvariantCultureIgnoreCase)) { tabComponents.SelectTab(tabSchLib); using (var reader = new SchLibReader(fileName)) { reader.Read(); foreach (var component in reader.Components) { var index = gridSchLibComponents.Rows.Add(component.Name, component.Description); gridSchLibComponents.Rows[index].Tag = component; } _displayUnit = reader.Header.DisplayUnit; _snapGridSize = reader.Header.SnapGridSize; _containers = reader.Components.Cast <IContainer>().ToList(); using (var assetsReader = new SchLibReader("assets.schlib")) { assetsReader.Read(); _renderer = new SchLibRenderer(reader.Header, reader.EmbeddedImages, assetsReader.Components); } } } else if (Path.GetExtension(fileName).Equals(".schdoc", StringComparison.InvariantCultureIgnoreCase)) { tabComponents.SelectTab(tabSchLib); using (var reader = new SchDocReader(fileName)) { reader.Read(); var index = gridSchLibComponents.Rows.Add(fileName); gridSchLibComponents.Rows[index].Tag = reader.Root; var sheet = reader.Root.GetPrimitivesOfType <SheetRecord>().Single(); _displayUnit = sheet.DisplayUnit; _snapGridSize = sheet.SnapGridSize; _containers = new List <IContainer> { reader.Root }; using (var assetsReader = new SchLibReader("assets.schlib")) { assetsReader.Read(); _renderer = new SchLibRenderer(sheet, reader.EmbeddedImages, assetsReader.Components); } } } SetActiveContainer(_containers.FirstOrDefault()); } finally { _loading = false; } }