Пример #1
0
        public IInterpreterConfiguration DoGUIConfiguration(IInterpreterPreConfiguration preConfig, IInterpreterConfiguration previousConfig)
        {
            var          config    = (PrepareIFabConfig)preConfig;
            ComComponent cyPhy2CAD = new ComComponent("MGA.Interpreter.CyPhy2CAD_CSharp");

            cyPhy2CAD.DoGUIConfiguration(config.ProjectDirectory);
            // TODO: when CyPhy2CAD implements ICyPhyInterpreter, save its config in ours
            CyPhy2CAD_CSharp.CyPhy2CADSettings cadSettings = (CyPhy2CAD_CSharp.CyPhy2CADSettings)(cyPhy2CAD.InterpreterConfig);
            config.AuxiliaryDirectory = cadSettings.AuxiliaryDirectory;
            config.StepFormats        = cadSettings.StepFormats;

            return(config);
        }
Пример #2
0
        public IInterpreterConfiguration DoGUIConfiguration(IInterpreterPreConfiguration preConfig, IInterpreterConfiguration previousConfig)
        {
            var          config    = (CADAnalysisConfig)preConfig;
            ComComponent cyPhy2CAD = new ComComponent("MGA.Interpreter.CyPhy2CAD_CSharp");
            bool         cyPhy2CADConfigWasSuccessful = cyPhy2CAD.DoGUIConfiguration(config.ProjectDirectory);

            if (cyPhy2CADConfigWasSuccessful == false)
            {
                return(null);
            }
            // TODO: when CyPhy2CAD implements ICyPhyInterpreter, save its config in ours
            CyPhy2CAD_CSharp.CyPhy2CADSettings cadSettings = (CyPhy2CAD_CSharp.CyPhy2CADSettings)(cyPhy2CAD.InterpreterConfig);
            config.AuxiliaryDirectory = cadSettings.AuxiliaryDirectory;
            config.StepFormats        = cadSettings.StepFormats;

            return(config);
        }
Пример #3
0
        public static bool Run(string originalProjectDir, MgaProject project, MgaFCO testObj, bool copycomponents)
        {
            bool status = true;

            try
            {
                var outputdirname = GetProjectDir(project);
                if (copycomponents)
                {
                    CopyDirectory(Path.Combine(originalProjectDir, "components"), Path.Combine(outputdirname, "components"));
                }

                var interpreter = new CyPhy2CAD_CSharp.CyPhy2CAD_CSharpInterpreter();
                interpreter.Initialize(project);

                var mainParameters = new CyPhyGUIs.InterpreterMainParameters();
                var cadSettings    = new CyPhy2CAD_CSharp.CyPhy2CADSettings();
                cadSettings.OutputDirectory     = outputdirname;
                cadSettings.AuxiliaryDirectory  = "";
                mainParameters.config           = cadSettings;
                mainParameters.Project          = project;
                mainParameters.CurrentFCO       = testObj;
                mainParameters.SelectedFCOs     = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs"));
                mainParameters.StartModeParam   = 128;
                mainParameters.ConsoleMessages  = false;
                mainParameters.ProjectDirectory = Path.GetDirectoryName(GetProjectDir(project));
                mainParameters.OutputDirectory  = outputdirname;

                interpreter.Main(mainParameters);
            }
            catch (Exception)
            {
                status = false;
            }
            finally
            {
                project.Close();
            }

            return(status);
        }
Пример #4
0
        public static bool Run(string outputdirname, MgaProject project, MgaFCO testObj, bool copycomponents)
        {
            bool status = true;
            try
            {

                if (copycomponents)
                {
                    CopyDirectory(Path.Combine(GetProjectDir(project),"components"), Path.Combine(outputdirname, "components"));
                }

                var interpreter = new CyPhy2CAD_CSharp.CyPhy2CAD_CSharpInterpreter();
                interpreter.Initialize(project);

                var mainParameters = new CyPhyGUIs.InterpreterMainParameters();
                var cadSettings = new CyPhy2CAD_CSharp.CyPhy2CADSettings();
                cadSettings.OutputDirectory = outputdirname;
                cadSettings.AuxiliaryDirectory = "";
                mainParameters.config = cadSettings;
                mainParameters.Project = project;
                mainParameters.CurrentFCO = testObj;
                mainParameters.SelectedFCOs = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs"));
                mainParameters.StartModeParam = 128;
                mainParameters.ConsoleMessages = false;
                mainParameters.ProjectDirectory = Path.GetDirectoryName(GetProjectDir(project));
                mainParameters.OutputDirectory = outputdirname;

                interpreter.Main(mainParameters);
            }
            catch (Exception)
            {
                status = false;
            }
            finally
            {
                project.Close();
            }

            return status;

        }
Пример #5
0
        private void GenerateCADAssemblyXml(MgaProject project, MgaFCO currentobj, int param)
        {
            int origPrefs = project.Preferences;

            try
            {
                project.Preferences = project.Preferences | (int)GME.MGA.preference_flags.MGAPREF_IGNORECONNCHECKS | (int)GME.MGA.preference_flags.MGAPREF_FREEINSTANCEREFS;
                CyPhyML.ComponentAssembly assembly  = CyPhyMLClasses.ComponentAssembly.Cast(currentobj);
                List <string>             errorList = new List <string>();
                if (!VerifyAssembly(assembly, errorList))
                {
                    foreach (string s in errorList)
                    {
                        GMEConsole.Warning.WriteLine(s);
                    }
                    System.Windows.Forms.MessageBox.Show("Model verification failed for Meta-Link and it may not work properly for this model.", "Warning", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                }
                SyncedComponentData syncedCompData;
                if (!syncedComponents.TryGetValue(assembly.Guid.ToString(), out syncedCompData))
                {
                    throw new Exception("Internal error in GenerateCADAssemblyXml, can't find data for guid " + assembly.Guid);
                }

                HashSet <CyPhyML.Component> comps = CyphyMetaLinkUtils.CollectComponentsRecursive(assembly);

                // Prepare Meta-Link specific data based on the original model
                CyPhy2CAD_CSharp.MetaLinkData metaLinkData = new CyPhy2CAD_CSharp.MetaLinkData();
                try
                {
                    PrepareMetaLinkData(metaLinkData, assembly, "");
                }
                catch (Exception ex)
                {
                    throw new Exception("Error during collecting metalink data." + ex.Message);
                }

                DateTime t1 = DateTime.Now;
                // call elaborator and expand the references
                // Please note that elaborator will change "currentobj"'s internal structure
                Type t = Type.GetTypeFromProgID("MGA.Interpreter.CyPhyElaborateCS");
                if (t == null)
                {
                    throw new NullReferenceException("Cannot find MGA.Interpreter.CyPhyElaborate. Is it registered?");
                }
                IMgaComponentEx elaborator = Activator.CreateInstance(t) as IMgaComponentEx;
                elaborator.Initialize(project);
                elaborator.ComponentParameter["automated_expand"] = "true";
                elaborator.ComponentParameter["console_messages"] = "off";

                elaborator.InvokeEx(project, currentobj, (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs")), param);
                TimeSpan ts = DateTime.Now - t1;
                GMEConsole.Info.WriteLine("Elaborator was running for " + ts.TotalMilliseconds + "ms");

                CyPhy2CAD_CSharp.CyPhy2CADSettings cadSettings = new CyPhy2CAD_CSharp.CyPhy2CADSettings();
                cadSettings.AuxiliaryDirectory = syncedCompData.AuxDir;
                cadSettings.OutputDirectory    = syncedCompData.WorkingDir;
                cadSettings._metaLink          = true;

                CyPhy2CAD_CSharp.Logger.Instance.Reset();
                CyPhy2CAD_CSharp.CADFlatDataCreator datacreator = new CyPhy2CAD_CSharp.CADFlatDataCreator(cadSettings.OutputDirectory, GetProjectDir(), CadFormat, metalink: true);

                datacreator.CreateFlatData(assembly);
                CyPhy2CAD_CSharp.DataRep.CADContainer cadcontainer = datacreator.CreateCADDataContainer(assembly.Guid.ToString(), CyPhy2CAD_CSharp.UtilityHelpers.CleanString2(assembly.Name));

                cadcontainer.MergeAssemblies();

                // IF this is an empty design, add a root component
                if (cadcontainer.assemblies.Count == 0)
                {
                    cadcontainer.AddRootComponent(assembly);
                }

                cadcontainer.InjectMetaLinkData(assembly, metaLinkData);


                CyPhy2CAD_CSharp.TestBenchModel.TestBenchBase testbenchbase = new CyPhy2CAD_CSharp.TestBenchModel.TestBenchBase(cadSettings, cadSettings.OutputDirectory, GetProjectDir());
                testbenchbase.cadDataContainer = cadcontainer;
                testbenchbase.CollectDirectories();

                testbenchbase.GenerateCADXMLOutput();
                testbenchbase.GenerateScriptFiles();
                bool stop = CyPhy2CAD_CSharp.Logger.Instance.ErrorCnt > 0;
                CyPhy2CAD_CSharp.Logger.Instance.DumpLog(GMEConsole, "");
                if (stop)
                {
                    throw new Exception("There were errors during processing the model. Please look at the console log and fix these.");
                }

                string CADAssembly = File.ReadAllText(Path.Combine(cadSettings.OutputDirectory, CyPhy2CAD_CSharp.TestBenchModel.TestBenchBase.CADAssemblyFile));
                string designId    = new Guid(currentobj.GetGuidDisp()).ToString("D");
                SendInterest(null, syncedCompData.InstanceId);
                foreach (var comp in comps)
                {
                    //  SendInterest(null, ComponentTopic, comp.Attributes.AVMID);
                }
                SaveCadAssemblyXml(CADAssembly, designId);
            }
            finally
            {
                project.Preferences = origPrefs;
            }
        }
        private void GenerateCADAssemblyXml(MgaProject project, MgaFCO currentobj, int param)
        {
            int origPrefs = project.Preferences;
            try
            {
                project.Preferences = project.Preferences | (int)GME.MGA.preference_flags.MGAPREF_IGNORECONNCHECKS | (int)GME.MGA.preference_flags.MGAPREF_FREEINSTANCEREFS;
                CyPhyML.ComponentAssembly assembly = CyPhyMLClasses.ComponentAssembly.Cast(currentobj);
                List<string> errorList = new List<string>();
                if (!VerifyAssembly(assembly, errorList))
                {
                    System.Windows.Forms.MessageBox.Show("Model verification failed for Meta-Link and it may not work properly for this model.", "Warning", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                    foreach (string s in errorList)
                        GMEConsole.Warning.WriteLine(s);
                }
                SyncedComponentData syncedCompData;
                if (!syncedComponents.TryGetValue(assembly.Guid.ToString(), out syncedCompData))
                {
                    throw new Exception("Internal error in GenerateCADAssemblyXml, can't find data for guid " + assembly.Guid);
                }

                HashSet<CyPhyML.Component> comps = CyphyMetaLinkUtils.CollectComponentsRecursive(assembly);

                // Prepare Meta-Link specific data based on the original model
                CyPhy2CAD_CSharp.MetaLinkData metaLinkData = new CyPhy2CAD_CSharp.MetaLinkData();
                try
                {
                    PrepareMetaLinkData(metaLinkData, assembly, "");
                }
                catch (Exception ex)
                {
                    throw new Exception("Error during collecting metalink data." + ex.Message);
                }

                DateTime t1 = DateTime.Now;
                // call elaborator and expand the references
                // Please note that elaborator will change "currentobj"'s internal structure
                Type t = Type.GetTypeFromProgID("MGA.Interpreter.CyPhyElaborateCS");
                if (t == null)
                {
                    throw new NullReferenceException("Cannot find MGA.Interpreter.CyPhyElaborate. Is it registered?");
                }
                IMgaComponentEx elaborator = Activator.CreateInstance(t) as IMgaComponentEx;
                elaborator.Initialize(project);
                elaborator.ComponentParameter["automated_expand"] = "true";
                elaborator.ComponentParameter["console_messages"] = "off";

                elaborator.InvokeEx(project, currentobj, (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs")), param);
                TimeSpan ts = DateTime.Now - t1;
                GMEConsole.Info.WriteLine("Elaborator was running for " + ts.TotalMilliseconds + "ms");

                CyPhy2CAD_CSharp.CyPhy2CADSettings cadSettings = new CyPhy2CAD_CSharp.CyPhy2CADSettings();
                cadSettings.AuxiliaryDirectory = syncedCompData.AuxDir;
                cadSettings.OutputDirectory = syncedCompData.WorkingDir;
                cadSettings.MetaLink = true;

                CyPhy2CAD_CSharp.Logger.Instance.Reset();
                CyPhy2CAD_CSharp.CADFlatDataCreator datacreator = new CyPhy2CAD_CSharp.CADFlatDataCreator(cadSettings.OutputDirectory, GetProjectDir(), metalink: true);

                datacreator.CreateFlatData(assembly);
                CyPhy2CAD_CSharp.DataRep.CADContainer cadcontainer = datacreator.CreateCADDataContainer(assembly.Guid.ToString(), CyPhy2CAD_CSharp.UtilityHelpers.CleanString2(assembly.Name));

                cadcontainer.MergeAssemblies();

                // IF this is an empty design, add a root component
                if (cadcontainer.assemblies.Count == 0)
                {
                    cadcontainer.AddRootComponent(assembly);
                }

                cadcontainer.InjectMetaLinkData(assembly, metaLinkData);


                CyPhy2CAD_CSharp.TestBenchModel.TestBenchBase testbenchbase = new CyPhy2CAD_CSharp.TestBenchModel.TestBenchBase(cadSettings, cadSettings.OutputDirectory, GetProjectDir());
                testbenchbase.cadDataContainer = cadcontainer;
                testbenchbase.CollectDirectories();

                testbenchbase.GenerateCADXMLOutput();
                testbenchbase.GenerateScriptFiles();
                bool stop = CyPhy2CAD_CSharp.Logger.Instance.ErrorCnt > 0;
                CyPhy2CAD_CSharp.Logger.Instance.DumpLog(GMEConsole, "");
                if (stop)
                {
                    throw new Exception("There were errors during processing the model. Please look at the console log and fix these.");
                }

                string CADAssembly = File.ReadAllText(Path.Combine(cadSettings.OutputDirectory, CyPhy2CAD_CSharp.TestBenchModel.TestBenchBase.CADAssemblyFile));
                string designId = new Guid(currentobj.GetGuidDisp()).ToString("D");
                SendInterest(null, syncedCompData.InstanceId);
                foreach (var comp in comps)
                {
                    //  SendInterest(null, ComponentTopic, comp.Attributes.AVMID);
                }
                SaveCadAssemblyXml(CADAssembly, designId);
            }
            finally
            {
                project.Preferences = origPrefs;
            }
        }