예제 #1
0
        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);
            }
        }
예제 #2
0
 private void RaiseComponentClick(Circuit.Component C)
 {
     foreach (Action <Circuit.Component> i in componentClick)
     {
         i(C);
     }
 }
예제 #3
0
        /// <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);
            }
        }
예제 #4
0
 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
         }
     };
 }
예제 #5
0
        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();
        }
예제 #6
0
        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));
        }
예제 #7
0
        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
            };
        }
예제 #8
0
        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);
        }
예제 #9
0
 public SymbolControl(Circuit.Component C) : this(new Circuit.Symbol(C))
 {
 }
예제 #10
0
 public Component(Circuit.Component Instance, string Name, string Description)
 {
     instance = Instance;
     name     = Name;
     desc     = Description;
 }
예제 #11
0
        public void AddComponent(Circuit.Component C, KeyGesture[] keys = null)
        {
            DescriptionAttribute desc = C.GetType().CustomAttribute <DescriptionAttribute>();

            AddComponent(C, C.TypeName, desc?.Description, keys);
        }
예제 #12
0
        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);
        }
예제 #13
0
 public Component(Circuit.Component Instance, string Name, string Description)
 {
     instance = Instance;
     name = Name;
     desc = Description;
 }
예제 #14
0
        public void AddComponent(Circuit.Component C)
        {
            DescriptionAttribute desc = C.GetType().CustomAttribute <DescriptionAttribute>();

            AddComponent(C, C.TypeName, desc != null ? desc.Description : null);
        }
예제 #15
0
 public void AddComponent(Circuit.Component C, string Name, string Description)
 {
     Components.Add(new Component(C, Name, Description));
 }