Beispiel #1
0
        private bool CallCyPhy2CAD_CSharp(CyPhy.TestBenchType testBench)
        {
            var cyPhy2CAD = new META.ComComponent("MGA.Interpreter.CyPhy2CAD_CSharp");

            cyPhy2CAD.InterpreterConfig = META.ComComponent.DeserializeConfiguration(
                this.mainParameters.ProjectDirectory,
                typeof(CyPhy2CAD_CSharp.CyPhy2CADSettings),
                cyPhy2CAD.ProgId);

            cyPhy2CAD.Initialize(this.mainParameters.Project);

            var diTestBenchOutputDir = Directory.CreateDirectory(Path.Combine(OutputDirectory, "TestBench"));

            cyPhy2CAD.MainParameters.OutputDirectory = diTestBenchOutputDir.FullName;
            cyPhy2CAD.MainParameters.CurrentFCO = (MgaFCO)testBench.Impl;

            cyPhy2CAD.MainParameters.Project = this.mainParameters.Project;
            cyPhy2CAD.MainParameters.ProjectDirectory = this.mainParameters.ProjectDirectory;
            cyPhy2CAD.MainParameters.SelectedFCOs = this.mainParameters.SelectedFCOs;
            cyPhy2CAD.MainParameters.StartModeParam = this.mainParameters.StartModeParam;
            cyPhy2CAD.MainParameters.VerboseConsole = this.mainParameters.VerboseConsole;

            try
            {
                cyPhy2CAD.Main();
            }
            catch (META.InterpreterException)
            {
                //Trace.TraceError(ex.ToString());
                this.Logger.WriteError("CyPhy2CAD_CSharp failed!");
                return false;
            }

            if (cyPhy2CAD.result.Success)
            {
                this.result.Labels += cyPhy2CAD.result.Labels;
                return true;
            }
            else
            {
                return false;
            }
        }
Beispiel #2
0
        // used to get attached package names; these strings are invalid for certain uses in a CyPhy project
        private static void getExternalPackageNames(MgaFCO context)
        {
            if (externalPackageNames == null)
            {
                externalPackageNames = new List<string>();
                // get previous GUI config
                var cyPhy2Modelica_v2 = new META.ComComponent("MGA.Interpreter.CyPhy2Modelica_v2");
                var projectDir = GetProjectDir(context);
                var config = META.ComComponent.DeserializeConfiguration(projectDir, typeof(CyPhy2Modelica_v2Settings), cyPhy2Modelica_v2.ProgId);
                if (config == null)
                {
                    config = new CyPhy2Modelica_v2Settings();
                }
                
                var paths = (config as CyPhy2Modelica_v2Settings).IncludeDirectoryPath;
                foreach (var path in paths)
                {
                    externalPackageNames.Add(ModelicaLibrary.GetLibraryFromPath(path).Name);
                }

                externalPackageNames.Add("Modelica");
                externalPackageNames.Add(Modelica.CodeGenerator.MainPackage);
                // Cyber business
                externalPackageNames.Add(CyPhyClasses.CyberModel.AttributesClass.ModelType_enum.ESMoL.ToString());
                externalPackageNames.Add(CyPhyClasses.CyberModel.AttributesClass.ModelType_enum.SignalFlow.ToString());
                externalPackageNames.Add(CyPhyClasses.CyberModel.AttributesClass.ModelType_enum.Simulink.ToString());
            }
        }
Beispiel #3
0
        public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param)
        {
            if (!enabled)
            {
                return;
            }

            try
            {
                // Create a new instance of the logger
                this.Logger = new CyPhyGUIs.GMELogger(project, this.ComponentName);

                if (currentobj == null)
                {
                    this.Logger.WriteFailed("CyPhyPET must be called from a Parametric Exploration.");
                    return;
                }

                // Need to call this interpreter in the same way as the MasterInterpreter will call it.
                // initialize main parameters
                var parameters = new InterpreterMainParameters()
                {
                    Project = project,
                    CurrentFCO = currentobj,
                    SelectedFCOs = selectedobjs,
                    StartModeParam = param,
                    VerboseConsole = true
                };

                this.mainParameters = parameters;
                parameters.ProjectDirectory = Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length));


                // Check if the PCCPropertyInputEditor should be opend.
                // If so return after this transaction
                bool doReturn = false;

                int VK_CONTROL = 0x11;
                // If control was held, try to open GUI. 
                if ((bool)((GetKeyState(VK_CONTROL) & 0x8000) == 0x8000))
                {
                    MgaGateway.PerformInTransaction(delegate
                    {
                        doReturn = this.TryOpenPCCPropertyInputEditor();
                    }, abort: false);
                }

                if (doReturn)
                {
                    return;
                }

                string interpreterProgID = "";

                // Set up the output directory and check kind of currentObj.
                string kindName = string.Empty;
                MgaGateway.PerformInTransaction(delegate
                {
                    string outputDirName = project.Name;
                    if (currentobj != null)
                    {
                        outputDirName = currentobj.Name;
                        kindName = currentobj.MetaBase.Name;
                    }

                    parameters.OutputDirectory = Path.GetFullPath(Path.Combine(
                        parameters.ProjectDirectory,
                        "results",
                        outputDirName));
                    var testBenchRef = currentobj.ChildObjects.Cast<MgaFCO>().Where(c => c.MetaRole.Name == typeof(CyPhyClasses.TestBenchRef).Name).FirstOrDefault();
                    if (testBenchRef != null)
                    {
                        var tbRef = CyPhyClasses.TestBenchRef.Cast(testBenchRef);
                        if (tbRef.AllReferred is CyPhy.TestBench)
                        {
                            var testBench = CyPhyClasses.TestBenchRef.Cast(testBenchRef).Referred.TestBench;
                            interpreterProgID = Rules.Global.GetInterpreterProgIDFromTestBench(testBench);
                        }
                        else if (tbRef.AllReferred is CyPhy.TestBenchType)
                        {
                            // Assume CyPhy2CAD_CSharp for all other types of test-benches for now.
                            interpreterProgID = "MGA.Interpreter.CyPhy2CAD_CSharp";
                        }
                    }
                });

                if (string.IsNullOrEmpty(kindName) == false && kindName != typeof(CyPhyClasses.ParametricExploration).Name)
                {
                    this.Logger.WriteFailed("CyPhyPET must be called from a Parametric Exploration.");
                    return;
                }

                PreConfigArgs preConfigArgs = new PreConfigArgs();
                preConfigArgs.ProjectDirectory = parameters.ProjectDirectory;

                // call the preconfiguration with no parameters and get preconfig
                var preConfig = this.PreConfig(preConfigArgs);

                // get previous GUI config
                var previousConfig = META.ComComponent.DeserializeConfiguration(
                    parameters.ProjectDirectory,
                    typeof(CyPhyPET.CyPhyPETSettings),
                    this.ComponentProgID);

                // get interpreter config through GUI
                var config = this.DoGUIConfiguration(preConfig, previousConfig);
                if (config == null)
                {
                    this.Logger.WriteWarning("Operation cancelled by the user.");
                    return;
                }

                // External Interpreter configuration
                if (interpreterProgID == "MGA.Interpreter.CyPhy2Modelica_v2")
                {
                    var cyPhy2Modelica_v2 = new META.ComComponent("MGA.Interpreter.CyPhy2Modelica_v2");
                    if (cyPhy2Modelica_v2.DoGUIConfiguration(parameters.ProjectDirectory) == false)
                    {
                        this.Logger.WriteWarning("Operation cancelled by the user.");
                        return;
                    }
                }
                else if (interpreterProgID == "MGA.Interpreter.CyPhy2CAD_CSharp")
                {
                    var cyPhy2CAD_CSharp = new META.ComComponent("MGA.Interpreter.CyPhy2CAD_CSharp");
                    if (cyPhy2CAD_CSharp.DoGUIConfiguration(parameters.ProjectDirectory) == false)
                    {
                        this.Logger.WriteWarning("Operation cancelled by the user.");
                        return;
                    }
                }

                // if config is valid save it and update it on the file system
                META.ComComponent.SerializeConfiguration(parameters.ProjectDirectory, config, this.ComponentProgID);

                // assign the new configuration to mainParameters
                parameters.config = config;

                // call the main (ICyPhyComponent) function
                this.Main(parameters);

            }
            finally
            {
                if (this.Logger != null)
                {
                    this.Logger.Dispose();
                    this.Logger = null;
                }
                if (MgaGateway != null &&
                    MgaGateway.territory != null)
                {
                    MgaGateway.territory.Destroy();
                }
                MgaGateway = null;
                project = null;
                currentobj = null;
                selectedobjs = null;
                //GMEConsole = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Beispiel #4
0
        private bool CallCyPhyPython(CyPhy.TestBenchType testBench)  
        {
            var cyPhyPython = new META.ComComponent("MGA.Interpreter.CyPhyPython");

            //cyPhyPython.InterpreterConfig = META.ComComponent.DeserializeConfiguration(
            //    this.mainParameters.ProjectDirectory,
            //   typeof(CyPhyPython.CyPhyPythonSettings),
            //    cyPhyPython.ProgId);

            cyPhyPython.Initialize(this.mainParameters.Project);

            var workflowRef = testBench.Children.WorkflowRefCollection.FirstOrDefault();
            if (workflowRef == null || workflowRef.Referred.Workflow == null)
            {
                throw new ApplicationException("CyPhyPython testbench must have a WorkflowRef");
            }
            var task = workflowRef.Referred.Workflow.Children.TaskCollection.Where(t => t.Attributes.COMName == "MGA.Interpreter.CyPhyPython").FirstOrDefault();
            if (task == null)
            {
                throw new ApplicationException("CyPhyPython testbench must have Task");
            }
            try
            {
                cyPhyPython.WorkflowParameters = (Dictionary<string, string>)JsonConvert.DeserializeObject(task.Attributes.Parameters, typeof(Dictionary<string, string>));
                if (cyPhyPython.WorkflowParameters == null)
                {
                    cyPhyPython.WorkflowParameters = new Dictionary<string, string>();
                }
            }
            catch (JsonException ex)
            {
                throw new ApplicationException(String.Format("Could not parse Parameters for '{0}'", task.Name), ex);
            }
            cyPhyPython.DoGUIConfiguration(this.mainParameters.ProjectDirectory, false);

            var diTestBenchOutputDir = Directory.CreateDirectory(Path.Combine(OutputDirectory, "TestBench"));

            cyPhyPython.MainParameters.OutputDirectory = diTestBenchOutputDir.FullName;
            cyPhyPython.MainParameters.CurrentFCO = (MgaFCO)testBench.Impl;

            cyPhyPython.MainParameters.Project = this.mainParameters.Project;
            cyPhyPython.MainParameters.ProjectDirectory = this.mainParameters.ProjectDirectory;
            cyPhyPython.MainParameters.SelectedFCOs = this.mainParameters.SelectedFCOs;
            cyPhyPython.MainParameters.StartModeParam = this.mainParameters.StartModeParam;
            cyPhyPython.MainParameters.VerboseConsole = this.mainParameters.VerboseConsole;

            try
            {
                cyPhyPython.Main();
            }
            catch (META.InterpreterException)
            {
                //Trace.TraceError(ex.ToString());
                this.Logger.WriteError("CyPhyPython failed!");
                return false;
            }

            if (cyPhyPython.result.Success)
            {
                this.result.Labels += cyPhyPython.result.Labels;
                return true;
            }
            else
            {
                return false;
            }
        }