コード例 #1
0
        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);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        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();
            }
        }
コード例 #5
0
        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();
            }
        }
コード例 #6
0
        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();
        }