Ejemplo n.º 1
0
        public void Import(IEnumerable <string> lbrFiles)
        {
            project.Create("MGA=" + Path.GetFullPath(Path.Combine(".", "ComponentCreator", "Components")) + ".mga", "CyPhyML");

            IMgaComponent signalBlocksAddon = (IMgaComponent)Activator.CreateInstance(Type.GetTypeFromProgID("MGA.Addon.CyPhySignalBlocksAddOn"));

            signalBlocksAddon.Initialize(project);
            project.Notify(globalevent_enum.GLOBALEVENT_OPEN_PROJECT_FINISHED);
            System.Windows.Forms.Application.DoEvents(); // let CyPhySignalBlocksAddOn create libs

            project.BeginTransactionInNewTerr(transactiontype_enum.TRANSACTION_NON_NESTED);
            try
            {
                MgaMetaFolder componentsMeta = (MgaMetaFolder)project.RootMeta.RootFolder.DefinedFolderByName["Components", false];
                var           components     = project.RootFolder.CreateFolder(componentsMeta);
                components.Name = componentsMeta.Name;
            }
            finally
            {
                project.CommitTransaction();
            }

            foreach (string eagleFilePath in lbrFiles)
            {
                //Console.WriteLine(eagleFilePath);
                //Console.WriteLine(string.Join(" ", CyPhyComponentAuthoring.Modules.EDAModelImport.GetDevicesInEagleModel(eagleFilePath).ToArray()));
                foreach (string deviceName in CyPhyComponentAuthoring.Modules.EDAModelImport.GetDevicesInEagleModel(eagleFilePath))
                {
                    try
                    {
                        CreateNewComponentMga(eagleFilePath, deviceName);
                        Console.WriteLine("Imported {0} {1}", eagleFilePath, deviceName);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Import failed: " + e.ToString());
                    }
                }
            }
            project.Save("", true);
            project.Close(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="parent"></param>
        /// <param name="metaRef">meta ref of the new object</param>
        /// <param name="roleMetaRef">meta ref of the role (if the parent is a model)</param>
        /// <returns></returns>
        public static T CreateObject <T>(
            ISIS.GME.Common.Interfaces.Container parent,
            int metaRef,
            int roleMetaRef = 0)
            where T : ISIS.GME.Common.Classes.Base, new()
        {
            Contract.Requires(parent != null);

            T result = new T();

            if (parent.Impl is MgaModel)
            {
                MgaModel    model = parent.Impl as MgaModel;
                MgaMetaRole role  = null;
                try
                {
                    // try to use user defined role
                    role = (model.MetaBase as MgaMetaModel).
                           Roles.
                           Cast <MgaMetaRole>().
                           FirstOrDefault(x => x.MetaRef == roleMetaRef);
                }
                catch (Exception ex)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Role was not found in the container.");
                    sb.AppendLine("Paradigm violation.");
                    sb.AppendFormat("Container type: {0} Requested role: {1}",
                                    parent.Kind,
                                    result.GetType().Name);
                    throw new Exception(sb.ToString(), ex);
                }

                try
                {
                    IMgaFCO fco = model.CreateChildObject(role);
                    result.Impl = fco as IMgaObject;
                    return(result);
                }
                catch (Exception ex)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("New element could not be created.");
                    sb.AppendFormat("Container type: {0} Requested role: {1}",
                                    parent.Kind,
                                    result.GetType().Name);
                    throw new Exception(sb.ToString(), ex);
                }
            }
            else if (parent.Impl is MgaFolder)
            {
                try
                {
                    MgaFolder folder = parent.Impl as MgaFolder;

                    MgaMetaFolder item = folder.MetaFolder.
                                         LegalChildFolders.
                                         Cast <MgaMetaFolder>().
                                         FirstOrDefault(x => x.MetaRef == metaRef);

                    if (item != null)
                    {
                        // create new folder
                        MgaFolder f = folder.CreateFolder(item);
                        result.Impl = f as IMgaObject;
                        return(result);
                    }
                    else
                    {
                        MgaMetaFCO itemFco = folder.MetaFolder.
                                             LegalRootObjects.
                                             Cast <MgaMetaFCO>().
                                             FirstOrDefault(x => x.MetaRef == metaRef);

                        if (itemFco != null)
                        {
                            IMgaFCO f = folder.CreateRootObject(itemFco);
                            result.Impl = f as IMgaObject;
                            return(result);
                        }
                    }
                }
                catch (Exception ex)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("New element could not be created in folder.");
                    sb.AppendFormat("Container type: {0} Requested child type: {1}",
                                    parent.Kind,
                                    result.GetType().Name);
                    throw new Exception(sb.ToString(), ex);
                }
            }

            return(null);
        }