private void LoadLibrary(XDocument Doc, string Name) { XElement library = Doc.Element("Library"); if (library != null) { XAttribute category = library.Attribute("Category"); Category child = FindChild(category != null ? category.Value : Name); foreach (XElement i in library.Elements("Component")) { try { Circuit.Component C = Circuit.Component.Deserialize(i); child.AddComponent(C); } catch (Exception E) { Util.Log.Global.WriteLine(Util.MessageType.Warning, "Failed to load component: {0}", E.Message); } } } else if (Doc.Element("Schematic") != null) { Circuit.Schematic S = Circuit.Schematic.Deserialize(Doc.Element("Schematic")); Circuit.Circuit C = S.Build(); AddComponent(C, Name, C.Description); } }
private void RaiseComponentClick(Circuit.Component C) { foreach (Action <Circuit.Component> i in componentClick) { i(C); } }
/// <summary> /// Add the categories and components of the specified library to this Category. /// </summary> /// <param name="Library"></param> public void LoadLibrary(string Library) { string name = System.IO.Path.GetFileNameWithoutExtension(Library); try { // Try to load the library as a LiveSPICE XML document. XDocument doc = XDocument.Load(Library); XElement library = doc.Element("Library"); if (library != null) { XAttribute category = library.Attribute("Category"); Category child = FindChild(category != null ? category.Value : name); foreach (XElement i in library.Elements("Component")) { Circuit.Component C = Circuit.Component.Deserialize(i); child.AddComponent(C); } } else if (doc.Element("Schematic") != null) { Circuit.Schematic S = Circuit.Schematic.Deserialize(doc.Element("Schematic")); Circuit.Circuit C = S.Build(); AddComponent(C, name, C.Description); } } catch (System.Xml.XmlException) { // Try to load the library as a SPICE model library. try { Circuit.Spice.Statements statements = new Circuit.Spice.Statements() { Log = Util.Log.Global }; statements.Parse(Library); IEnumerable <Circuit.Spice.Model> models = statements.OfType <Circuit.Spice.Model>().Where(i => i.Component != null); if (models.Any()) { Category child = FindChild(name); foreach (Circuit.Spice.Model i in models) { child.AddComponent(i.Component, i.Component.PartNumber, i.Description); } } } catch (Exception Ex) { Util.Log.Global.WriteLine(Util.MessageType.Warning, "Failed to load component libary '{0}': {1}", Library, Ex.Message); } } catch (Exception Ex) { Util.Log.Global.WriteLine(Util.MessageType.Warning, "Failed to load component libary '{0}': {1}", Library, Ex.Message); } }
public SymbolTool(SchematicEditor Target, Circuit.Component C) : base(Target) { overlay = new SymbolControl(C) { Visibility = Visibility.Hidden, ShowText = false, Highlighted = true, Pen = new Pen(Brushes.Gray, 1.0) { StartLineCap = PenLineCap.Round, EndLineCap = PenLineCap.Round } }; }
private void OnLoaded(object sender, EventArgs e) { CommandBindingCollection commands = Window.GetWindow(this).CommandBindings; foreach (KeyValuePair <Type, KeyGesture[]> i in ShortcutKeys) { Circuit.Component C = (Circuit.Component)Activator.CreateInstance(i.Key); RoutedCommand command = new RoutedCommand(C.TypeName, GetType()); command.InputGestures.AddRange(i.Value); commands.Add(new CommandBinding(command, (x, y) => RaiseComponentClick(C))); } LoadComponents(); }
public void AddComponent(Circuit.Component C, string Name, string Description, KeyGesture[] keys = null) { if (keys != null) { string shortcuts = "(" + string.Join(", ", keys.Select(j => j.GetDisplayStringForCulture(CultureInfo.CurrentCulture))) + ")"; if (Description != null) { Description += " " + shortcuts; } else { Description = shortcuts; } } Components.Add(new Component(C, Name, Description)); }
protected void OnMouseMove(object sender, MouseEventArgs e) { Point x = e.GetPosition(this); Matrix transform = Transform; foreach (Circuit.Terminal i in Symbol.Terminals) { Circuit.Coord tx = layout.MapTerminal(i); Point tp = new Point(tx.x, tx.y); tp = transform.Transform(tp); if ((tp - x).Length < 5.0) { ToolTip = "Terminal '" + i.ToString() + "'"; return; } } TextBlock text = new TextBlock(); Circuit.Component component = Symbol.Component; text.Inlines.Add(new Bold(new Run(component.ToString()))); foreach (PropertyInfo i in component.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(j => j.CustomAttribute <Circuit.Serialize>() != null && (j.CustomAttribute <BrowsableAttribute>() == null || j.CustomAttribute <BrowsableAttribute>().Browsable))) { object value = i.GetValue(component, null); DefaultValueAttribute def = i.CustomAttribute <DefaultValueAttribute>(); if (def == null || !Equals(def.Value, value)) { System.ComponentModel.TypeConverter tc = System.ComponentModel.TypeDescriptor.GetConverter(i.PropertyType); text.Inlines.Add(new Run("\n" + i.Name + " = ")); text.Inlines.Add(new Bold(new Run(tc.ConvertToString(value)))); } } ToolTip = new ToolTip() { Content = text }; }
private void component_Click(Circuit.Component C) { SchematicEditor active = ActiveEditor; if (active == null) { active = (SchematicEditor)New().Schematic; } if (C is Circuit.Conductor) { active.Tool = new WireTool(active); } else { active.Tool = new SymbolTool(active, C.Clone()); } active.Focus(); Keyboard.Focus(active); }
public SymbolControl(Circuit.Component C) : this(new Circuit.Symbol(C)) { }
public Component(Circuit.Component Instance, string Name, string Description) { instance = Instance; name = Name; desc = Description; }
public void AddComponent(Circuit.Component C, KeyGesture[] keys = null) { DescriptionAttribute desc = C.GetType().CustomAttribute <DescriptionAttribute>(); AddComponent(C, C.TypeName, desc?.Description, keys); }
public void AddComponent(Circuit.Component C, KeyGesture[] keys = null) { string name = string.IsNullOrEmpty(C.PartNumber) ? C.TypeName : C.PartNumber; AddComponent(C, name, C.Description, keys); }
public Component(Circuit.Component Instance, string Name, string Description) { instance = Instance; name = Name; desc = Description; }
public void AddComponent(Circuit.Component C) { DescriptionAttribute desc = C.GetType().CustomAttribute <DescriptionAttribute>(); AddComponent(C, C.TypeName, desc != null ? desc.Description : null); }
public void AddComponent(Circuit.Component C, string Name, string Description) { Components.Add(new Component(C, Name, Description)); }