Пример #1
0
 private void LoadSpiceLibrary(string Library, string Name)
 {
     // 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);
     }
 }
Пример #2
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);
            }
        }
Пример #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);
            }
        }