public static void ImportXME(string xmePath, string mgaPath, bool enableAutoAddons=false) { MgaParser parser = new MgaParser(); string paradigm; string paradigmVersion; object paradigmGuid; string basename; string version; parser.GetXMLInfo(xmePath, out paradigm, out paradigmVersion, out paradigmGuid, out basename, out version); parser = new MgaParser(); MgaProject project = new MgaProject(); MgaResolver resolver = new MgaResolver(); resolver.IsInteractive = false; dynamic dynParser = parser; dynParser.Resolver = resolver; project.Create("MGA=" + Path.GetFullPath(mgaPath), paradigm); if (enableAutoAddons) { project.EnableAutoAddOns(true); } try { parser.ParseProject(project, xmePath); project.Save(); } finally { project.Close(); } }
public static MgaProject GetProject(String filename) { MgaProject result = null; if (filename != null && filename != "") { if (Path.GetExtension(filename) == ".mga") { result = new MgaProject(); if (System.IO.File.Exists(filename)) { Console.Out.Write("Opening {0} ... ", filename); bool ro_mode; result.Open("MGA=" + Path.GetFullPath(filename), out ro_mode); } else { Console.Out.Write("Creating {0} ... ", filename); result.Create("MGA=" + filename, "CyPhyML"); } Console.Out.WriteLine("Done."); } else { Console.Error.WriteLine("{0} file must be an mga project.", filename); } } else { Console.Error.WriteLine("Please specify an Mga project."); } return(result); }
public static MgaProject GetProject(String filename) { MgaProject result = null; if (filename != null && filename != "") { if (Path.GetExtension(filename) == ".mga") { result = new MgaProject(); if (System.IO.File.Exists(filename)) { Console.Out.Write("Opening {0} ... ", filename); bool ro_mode; result.Open("MGA=" + Path.GetFullPath(filename), out ro_mode); } else { Console.Out.Write("Creating {0} ... ", filename); result.Create("MGA=" + filename, "CyPhyML"); } Console.Out.WriteLine("Done."); } else { Console.Error.WriteLine("{0} file must be an mga project.", filename); } } else { Console.Error.WriteLine("Please specify an Mga project."); } return result; }
public static void ImportXME(string xmePath, string mgaPath, bool enableAutoAddons = false) { MgaParser parser = new MgaParser(); string paradigm; string paradigmVersion; object paradigmGuid; string basename; string version; parser.GetXMLInfo(xmePath, out paradigm, out paradigmVersion, out paradigmGuid, out basename, out version); parser = new MgaParser(); MgaProject project = new MgaProject(); MgaResolver resolver = new MgaResolver(); resolver.IsInteractive = false; dynamic dynParser = parser; dynParser.Resolver = resolver; project.Create("MGA=" + Path.GetFullPath(mgaPath), paradigm); if (enableAutoAddons) { project.EnableAutoAddOns(true); } try { parser.ParseProject(project, xmePath); project.Save(); } finally { project.Close(); } }
private MgaProject GetProject(String filename, String metaName) { MgaProject result = null; if (filename != null && filename != "") { if (Path.GetExtension(filename) == ".mga") { result = new MgaProject(); if (System.IO.File.Exists(filename)) { gmeConsole.Out.Write("Opening {0} ... ", filename); result.OpenEx("MGA=" + filename, metaName, null); } else { gmeConsole.Out.Write("Creating {0} ... ", filename); result.Create("MGA=" + filename, metaName); } gmeConsole.Out.WriteLine("Done."); } else { gmeConsole.Error.WriteLine("{0} file must be an mga project.", filename); _exitStatus |= Errors.FileError; } } else { gmeConsole.Error.WriteLine("Please specify an Mga project."); _exitStatus |= Errors.FileError; } return(result); }
public void TestAddCustomIconTool() { string TestName = System.Reflection.MethodBase.GetCurrentMethod().Name; string path_Test = Path.Combine(testcreatepath, TestName); string path_Mga = Path.Combine(path_Test, TestName + ".mga"); // delete any previous test results if (Directory.Exists(path_Test)) { Directory.Delete(path_Test, true); } // create a new blank project MgaProject proj = new MgaProject(); proj.Create("MGA=" + path_Mga, "CyPhyML"); // these are the actual steps of the test proj.PerformInTransaction(delegate { // create the environment for the Component authoring class CyPhy.RootFolder rf = CyPhyClasses.RootFolder.GetRootFolder(proj); CyPhy.Components components = CyPhyClasses.Components.Create(rf); CyPhy.Component testcomp = CyPhyClasses.Component.Create(components); // new instance of the class to test CyPhyComponentAuthoring.Modules.CustomIconAdd CATModule = new CyPhyComponentAuthoring.Modules.CustomIconAdd(); //// these class variables need to be set to avoid NULL references CATModule.SetCurrentDesignElement(testcomp); CATModule.CurrentObj = testcomp.Impl as MgaFCO; // call the primary function directly CATModule.AddCustomIcon(testiconpath); // verify results // 1. insure the icon file was copied to the back-end folder correctly string iconAbsolutePath = Path.Combine(testcomp.GetDirectoryPath(ComponentLibraryManager.PathConvention.ABSOLUTE), "Icon.png"); Assert.True(File.Exists(iconAbsolutePath), String.Format("Could not find the source file for the created resource, got {0}", iconAbsolutePath)); // 2. insure the resource path was created correctly var iconResource = testcomp.Children.ResourceCollection.Where(p => p.Name == "Icon.png").First(); Assert.True(iconResource.Attributes.Path == "Icon.png", String.Format("{0} Resource should have had value {1}; instead found {2}", iconResource.Name, "Icon.png", iconResource.Attributes.Path) ); // 3. Verify the registry entry exists string expected_registry_entry = Path.Combine(testcomp.GetDirectoryPath(ComponentLibraryManager.PathConvention.REL_TO_PROJ_ROOT), "Icon.png"); string registry_entry = (testcomp.Impl as GME.MGA.IMgaFCO).get_RegistryValue("icon"); Assert.True(registry_entry.Equals(expected_registry_entry), String.Format("Registry should have had value {0}; instead found {1}", expected_registry_entry, registry_entry) ); }); proj.Save(); proj.Close(); Directory.Delete(testcreatepath, true); }
public void TestAddMfgModelTool() { string TestName = System.Reflection.MethodBase.GetCurrentMethod().Name; string path_Test = Path.Combine(testcreatepath, TestName); string path_Mga = Path.Combine(path_Test, TestName + ".mga"); // delete any previous test results if (Directory.Exists(path_Test)) { Directory.Delete(path_Test, true); } // create a new blank project MgaProject proj = new MgaProject(); proj.Create("MGA=" + path_Mga, "CyPhyML"); // these are the actual steps of the test proj.PerformInTransaction(delegate { // create the environment for the Component authoring class CyPhy.RootFolder rf = CyPhyClasses.RootFolder.GetRootFolder(proj); CyPhy.Components components = CyPhyClasses.Components.Create(rf); CyPhy.Component testcomp = CyPhyClasses.Component.Create(components); // new instance of the class to test CyPhyComponentAuthoring.Modules.MfgModelImport CATModule = new CyPhyComponentAuthoring.Modules.MfgModelImport(); //// these class variables need to be set to avoid NULL references CATModule.SetCurrentDesignElement(testcomp); CATModule.CurrentObj = testcomp.Impl as MgaFCO; // call the primary function directly CATModule.import_manufacturing_model(testmfgmdlpath); // verify results // 1. insure the mfg file was copied to the backend folder correctly // insure the part file was copied to the backend folder correctly var getmfgmdl = testcomp.Children.ManufacturingModelCollection.First(); string returnedpath; getmfgmdl.TryGetResourcePath(out returnedpath, ComponentLibraryManager.PathConvention.ABSOLUTE); string demanglepathpath = returnedpath.Replace("\\", "/"); Assert.True(File.Exists(demanglepathpath), String.Format("Could not find the source file for the created resource, got {0}", demanglepathpath)); // 2. insure the resource path was created correctly var mfgResource = testcomp.Children.ResourceCollection.Where(p => p.Name == "generic_cots_mfg.xml").First(); Assert.True(mfgResource.Attributes.Path == Path.Combine("Manufacturing", "generic_cots_mfg.xml"), String.Format("{0} Resource should have had value {1}; instead found {2}", mfgResource.Name, "generic_cots_mfg.xml", mfgResource.Attributes.Path) ); }); proj.Save(); proj.Close(); }
public void TestCADImportResourceNaming() { string TestName = System.Reflection.MethodBase.GetCurrentMethod().Name; string path_Test = Path.Combine(testcreatepath, TestName); string path_Mga = Path.Combine(path_Test, TestName + ".mga"); // delete any previous test results if (Directory.Exists(path_Test)) { Directory.Delete(path_Test, true); } // create a new blank project MgaProject proj = new MgaProject(); proj.Create("MGA=" + path_Mga, "CyPhyML"); // these are the actual steps of the test proj.PerformInTransaction(delegate { // create the environment for the Component authoring class CyPhy.RootFolder rf = CyPhyClasses.RootFolder.GetRootFolder(proj); CyPhy.Components components = CyPhyClasses.Components.Create(rf); CyPhy.Component testcomp = CyPhyClasses.Component.Create(components); // new instance of the class to test CyPhyComponentAuthoring.Modules.CADModelImport testcam = new CyPhyComponentAuthoring.Modules.CADModelImport(); // these class variables need to be set to avoid NULL references testcam.SetCurrentDesignElement(testcomp); testcam.CurrentObj = testcomp.Impl as MgaFCO; // call the module with a part file to skip the CREO steps testcam.ImportCADModel(testpartpath); // verify results // insure the resource path was created correctly var correct_name = testcomp.Children.ResourceCollection.Where(p => p.Name == "damper.prt").First(); Assert.True(correct_name.Attributes.Path == "CAD\\damper.prt", String.Format("{0} should have had value {1}; instead found {2}", correct_name.Name, "CAD\\damper.prt", correct_name.Attributes.Path) ); // insure the part file was copied to the back-end folder correctly var getcadmdl = testcomp.Children.CADModelCollection.First(); string returnedpath; getcadmdl.TryGetResourcePath(out returnedpath, ComponentLibraryManager.PathConvention.ABSOLUTE); Assert.True(File.Exists(returnedpath + ".36"), String.Format("Could not find the source file for the created resource, got {0}", returnedpath)); }); proj.Save(); proj.Close(); }
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); }
public void DesignPackageImport() { // Clean the test directory var pathTest = Path.Combine(META.VersionInfo.MetaPath, "test", "InterchangeTest", "DesignInterchangeTest", "ImportTestUnits", "Package"); foreach (var path in Directory.EnumerateDirectories(pathTest)) { Directory.Delete(path, true); } foreach (var path in Directory.EnumerateFiles(pathTest, "*.*")) { if (!path.Contains("NestedFolders.adp")) { File.Delete(path); } } // Create a test project var proj = new MgaProject(); proj.Create("MGA=" + Path.Combine(pathTest,"testmodel.mga"), "CyPhyML"); try { String pathCA = null; proj.PerformInTransaction(() => { // Instantiate the importer and import the package var importer = new AVMDesignImporter(GMEConsole.CreateFromProject(proj), proj); var mdlCA = importer.ImportFile(Path.Combine(pathTest, "NestedFolders.adp"), AVMDesignImporter.DesignImportMode.CREATE_CAS); var ca = CyPhyClasses.ComponentAssembly.Cast(mdlCA.Impl); pathCA = ca.GetDirectoryPath(ComponentLibraryManager.PathConvention.ABSOLUTE); }); // Check the design's backend folder for all files except for the ADM. var filesExpected = new List<String> { "testObject.txt", "dir1/testObject.txt", "dir1/dir1a/testObject.txt", "dir2/testObject.txt" }; var filesInDir = Directory.GetFiles(pathCA, "*.*", SearchOption.AllDirectories); Assert.Equal(filesExpected.Count(), filesInDir.Count()); foreach (var file in filesExpected) { String fullPath = Path.Combine(pathCA, file); Assert.True(File.Exists(fullPath)); } } finally { proj.Save(); proj.Close(); } }
private MgaProject GetProject(String filename, String metaName) { MgaProject result = null; if (filename != null && filename != "") { if (Path.GetExtension(filename) == ".mga") { result = new MgaProject(); if (System.IO.File.Exists(filename)) { gmeConsole.Out.Write("Opening {0} ... ", filename); result.OpenEx("MGA=" + filename, metaName, null); } else { gmeConsole.Out.Write("Creating {0} ... ", filename); result.Create("MGA=" + filename, metaName); } gmeConsole.Out.WriteLine("Done."); } else { gmeConsole.Error.WriteLine("{0} file must be an mga project.", filename); _exitStatus |= Errors.FileError; } } else { gmeConsole.Error.WriteLine("Please specify an Mga project."); _exitStatus |= Errors.FileError; } return result; }
public void DesignPackageImport() { // Clean the test directory var pathTest = Path.Combine(META.VersionInfo.MetaPath, "test", "InterchangeTest", "DesignInterchangeTest", "ImportTestUnits", "Package"); foreach (var path in Directory.EnumerateDirectories(pathTest)) { Directory.Delete(path, true); } foreach (var path in Directory.EnumerateFiles(pathTest, "*.*")) { if (!path.Contains("NestedFolders.adp")) { File.Delete(path); } } // Create a test project var proj = new MgaProject(); proj.Create("MGA=" + Path.Combine(pathTest, "testmodel.mga"), "CyPhyML"); try { String pathCA = null; proj.PerformInTransaction(() => { // Instantiate the importer and import the package var importer = new AVMDesignImporter(GMEConsole.CreateFromProject(proj), proj); var mdlCA = importer.ImportFile(Path.Combine(pathTest, "NestedFolders.adp"), AVMDesignImporter.DesignImportMode.CREATE_CAS); var ca = CyPhyClasses.ComponentAssembly.Cast(mdlCA.Impl); pathCA = ca.GetDirectoryPath(ComponentLibraryManager.PathConvention.ABSOLUTE); }); // Check the design's backend folder for all files except for the ADM. var filesExpected = new List <String> { "testObject.txt", "dir1/testObject.txt", "dir1/dir1a/testObject.txt", "dir2/testObject.txt" }; var filesInDir = Directory.GetFiles(pathCA, "*.*", SearchOption.AllDirectories); Assert.Equal(filesExpected.Count(), filesInDir.Count()); foreach (var file in filesExpected) { String fullPath = Path.Combine(pathCA, file); Assert.True(File.Exists(fullPath)); } } finally { proj.Save(); proj.Close(); } }
public void TestCADFileReNaming() { // delete any previous test results if (Directory.Exists(testcreatepath)) { Directory.Delete(testcreatepath, true); } // create a new blank project MgaProject proj = new MgaProject(); proj.Create("MGA=" + testMGApath, "CyPhyML"); // these are the actual steps of the test proj.PerformInTransaction(delegate { // create the environment for the Component authoring class CyPhy.RootFolder rf = CyPhyClasses.RootFolder.GetRootFolder(proj); CyPhy.Components components = CyPhyClasses.Components.Create(rf); CyPhy.Component testcomp = CyPhyClasses.Component.Create(components); // Import a CAD file into the test project CyPhyComponentAuthoring.Modules.CADModelImport importcam = new CyPhyComponentAuthoring.Modules.CADModelImport(); // these class variables need to be set to avoid NULL references importcam.SetCurrentComp(testcomp); importcam.CurrentProj = proj; importcam.CurrentObj = testcomp.Impl as MgaFCO; // import the CAD file importcam.ImportCADModel(testpartpath); // Get a path to the imported Cad file var getcadmdl = testcomp.Children.CADModelCollection.First(); string importedpath; getcadmdl.TryGetResourcePath(out importedpath, ComponentLibraryManager.PathConvention.ABSOLUTE); // add in Creo version number importedpath += Path.GetExtension(testpartpath); // Rename the CAD file CyPhyComponentAuthoring.Modules.CADFileRename renamecam = new CyPhyComponentAuthoring.Modules.CADFileRename(); // these class variables need to be set to avoid NULL references renamecam.SetCurrentComp(testcomp); renamecam.CurrentProj = proj; renamecam.CurrentObj = testcomp.Impl as MgaFCO; // call the module with a part file and the new file name renamecam.RenameCADFile(importedpath, RenamedFileNameWithoutExtension); // verify results // 1. Verify the file was renamed var renamecadmdl = testcomp.Children.CADModelCollection.First(); string renamedpath; renamecadmdl.TryGetResourcePath(out renamedpath, ComponentLibraryManager.PathConvention.ABSOLUTE); // add in Creo version renamedpath += ".1"; Assert.True(File.Exists(renamedpath), String.Format("Could not find the renamed CAD file, found {0}", renamedpath)); // 2. Verify the Model was renamed bool model_not_found = false; try { var model_name = testcomp.Children.CADModelCollection.Where(p => p.Name == RenamedFileName).First(); } catch (Exception ex) { model_not_found = true; } Assert.False(model_not_found, String.Format("No CAD model found with the renamed name {0}", RenamedFileName) ); // 3. Verify the resource name and path were changed CyPhy.Resource resource_name = null; bool resource_not_found = false; try { resource_name = testcomp.Children.ResourceCollection.Where(p => p.Name == RenamedFileName).First(); } catch (Exception ex) { resource_not_found = true; } Assert.False(resource_not_found, String.Format("No resource found with the renamed name {0}", RenamedFileName) ); Assert.True(resource_name.Attributes.Path == RenamedFileNameRelativePath, String.Format("{0} should have had value {1}; instead found {2}", resource_name.Name, RenamedFileNameRelativePath, resource_name.Attributes.Path) ); }); proj.Save(); proj.Close(); }
private static void ConvertAllSchematicsToCyPhy(string path) { var schematics = ConvertAllDevices(path); // Create MGA project on the spot. var proj = new MgaProject(); String connectionString = String.Format("MGA={0}", Path.GetTempFileName()); proj.Create(connectionString, "CyPhyML"); proj.EnableAutoAddOns(true); var mgaGateway = new MgaGateway(proj); var module = new CyPhyComponentAuthoring.Modules.EDAModelImport(); Dictionary <String, String> d_failures = new Dictionary <string, string>(); mgaGateway.PerformInTransaction(delegate { var rf = CyPhyClasses.RootFolder.GetRootFolder(proj); var cf = CyPhyClasses.Components.Create(rf); foreach (var t in schematics) { var identifier = t.Item1; var schematic = t.Item2; CyPhy.Component component = CyPhyClasses.Component.Create(cf); component.Name = identifier; module.SetCurrentDesignElement(component); module.CurrentObj = component.Impl as MgaFCO; try { var cyphySchematicModel = module.BuildCyPhyEDAModel(schematic, component); Assert.Equal(component.Children.SchematicModelCollection.Count(), 1); } catch (Exception e) { d_failures[identifier] = e.ToString(); } } }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: true); proj.Save(); proj.Close(); if (d_failures.Any()) { String msg = String.Format("Failures in converting {0} component(s):" + Environment.NewLine, d_failures.Count); foreach (var kvp in d_failures) { msg += String.Format("{0}: {1}" + Environment.NewLine + Environment.NewLine, kvp.Key, kvp.Value); } Assert.True(false, msg); } }
private static void ConvertAllSchematicsToCyPhy(string path) { var schematics = ConvertAllDevices(path); // Create MGA project on the spot. var proj = new MgaProject(); String connectionString = String.Format("MGA={0}", Path.GetTempFileName()); proj.Create(connectionString, "CyPhyML"); proj.EnableAutoAddOns(true); var mgaGateway = new MgaGateway(proj); proj.CreateTerritoryWithoutSink(out mgaGateway.territory); var module = new CyPhyComponentAuthoring.Modules .EDAModelImport() { CurrentProj = proj }; Dictionary<String, String> d_failures = new Dictionary<string, string>(); mgaGateway.PerformInTransaction(delegate { var rf = CyPhyClasses.RootFolder.GetRootFolder(proj); var cf = CyPhyClasses.Components.Create(rf); foreach (var t in schematics) { var identifier = t.Item1; var schematic = t.Item2; CyPhy.Component component = CyPhyClasses.Component.Create(cf); component.Name = identifier; module.SetCurrentComp(component); try { var cyphySchematicModel = module.BuildCyPhyEDAModel(schematic, component); Assert.Equal(component.Children.SchematicModelCollection.Count(), 1); } catch (Exception e) { d_failures[identifier] = e.ToString(); } } }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: true); proj.Save(); proj.Close(); if (d_failures.Any()) { String msg = String.Format("Failures in converting {0} component(s):" + Environment.NewLine, d_failures.Count); foreach (var kvp in d_failures) { msg += String.Format("{0}: {1}" + Environment.NewLine + Environment.NewLine, kvp.Key, kvp.Value); } Assert.True(false, msg); } }