public bool DoGUIConfiguration(string projectDir, bool showGUI=true) { bool success = false; if (MgaComponent is ICyPhyInterpreter) { PreConfigArgs preConfigArgs = new PreConfigArgs(); preConfigArgs.ProjectDirectory = projectDir; // FIXME: fill in other preConfigArgs this.InterpreterConfig = META.ComComponent.DeserializeConfiguration(projectDir, InterpreterConfig.GetType(), ProgId); IInterpreterPreConfiguration preConfig = (MgaComponent as ICyPhyInterpreter).PreConfig(preConfigArgs); // Set configuration based on Workflow Parameters. This will override all [WorkflowConfigItem] members. this.SetWorkflowParameterValues(); if (showGUI == false) { return true; } var newConfig = (MgaComponent as ICyPhyInterpreter).DoGUIConfiguration(preConfig, this.InterpreterConfig); if (newConfig != null) { success = true; InterpreterConfig = newConfig; // save the updated configuration that we got if they hit OK META.ComComponent.SerializeConfiguration(projectDir, InterpreterConfig, ProgId); } } else { success = true; if (showGUI) { MgaComponent.ComponentParameter["do_config_now"] = projectDir; } this.SetWorkflowParameterValues(); } return success; }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { if (currentobj == null) { GMEConsole.Error.WriteLine("No model opened."); return; } var parameters = new InterpreterMainParameters() { Project = project, CurrentFCO = currentobj, SelectedFCOs = selectedobjs, VerboseConsole = true }; parameters.ProjectDirectory = Path.GetDirectoryName(currentobj.Project.ProjectConnStr.Substring("MGA=".Length)); MgaGateway.PerformInTransaction(delegate { string outputDirName = project.Name; if (currentobj != null) { outputDirName = currentobj.Name; } parameters.OutputDirectory = Path.GetFullPath(Path.Combine( parameters.ProjectDirectory, "results", outputDirName)); }); 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(CyPhyCarSettings), this.ComponentProgID); // get interpreter config through GUI var config = this.DoGUIConfiguration(preConfig, previousConfig); // 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 { MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GMEConsole = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }
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(); } }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { // 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 }; this.mainParameters = parameters; parameters.ProjectDirectory = Path.GetDirectoryName(currentobj.Project.ProjectConnStr.Substring("MGA=".Length)); // set up the output directory MgaGateway.PerformInTransaction(delegate { string outputDirName = project.Name; if (currentobj != null) { outputDirName = currentobj.Name; } parameters.OutputDirectory = Path.GetFullPath(Path.Combine( parameters.ProjectDirectory, "results", outputDirName)); //this.Parameters.PackageName = SystemC.Factory.GetModifiedName(currentobj.Name); }); 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(CyPhy2RF_Settings), this.ComponentProgID); // get interpreter config through GUI var config = this.DoGUIConfiguration(preConfig, previousConfig); if (config == null) { 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); } catch (Exception ex) { Logger.WriteError("Interpretation failed {0}<br>{1}", ex.Message, ex.StackTrace); } finally { if (MgaGateway != null && MgaGateway.territory != null) { MgaGateway.territory.Destroy(); } MgaGateway = null; project = null; currentobj = null; selectedobjs = null; if (Logger != null) { Logger.Dispose(); Logger = null; } GC.Collect(); GC.WaitForPendingFinalizers(); } }
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("CyPhyReliabilityAnalysis must be called from a Test Bench."); 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)); // 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)); }); if (string.IsNullOrEmpty(kindName) == false && kindName != "TestBench") { this.Logger.WriteFailed("CyPhyReliabilityAnalysis must be called from a Test Bench."); 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(CyPhyReliabilityAnalysisSettings), 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; } //#region CyPhy2Modelica_v2Configuration //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; //} //#endregion // TODO: put here any other interpreters that we have to call. // 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; } MgaGateway = null; project = null; currentobj = null; selectedobjs = null; //GMEConsole = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (this.enabled == false) { return; } try { // 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 }; this.mainParameters = parameters; parameters.ProjectDirectory = project.GetRootDirectoryPath(); // set up the output directory MgaGateway.PerformInTransaction(delegate { string outputDirName = project.Name; if (currentobj != null) { outputDirName = currentobj.Name; } var outputDirAbsPath = Path.GetFullPath(Path.Combine( parameters.ProjectDirectory, "results", outputDirName)); parameters.OutputDirectory = outputDirAbsPath; if (Directory.Exists(outputDirAbsPath)) { Logger.WriteWarning("Output directory {0} already exists. Unexpected behavior may result.", outputDirAbsPath); } else { Directory.CreateDirectory(outputDirAbsPath); } //this.Parameters.PackageName = Schematic.Factory.GetModifiedName(currentobj.Name); }); PreConfigArgs preConfigArgs = new PreConfigArgs() { ProjectDirectory = parameters.ProjectDirectory, Project = parameters.Project }; // call the preconfiguration with no parameters and get preconfig var preConfig = this.PreConfig(preConfigArgs); // get previous GUI config var settings_ = META.ComComponent.DeserializeConfiguration(parameters.ProjectDirectory, typeof(CyPhy2Schematic_Settings), this.ComponentProgID); CyPhy2Schematic_Settings settings = (settings_ != null) ? settings_ as CyPhy2Schematic_Settings : new CyPhy2Schematic_Settings(); // Set configuration based on Workflow Parameters. This will override all [WorkflowConfigItem] members. settings = InitializeSettingsFromWorkflow(settings); // Don't skip GUI -- we've been invoked directly here. settings.skipGUI = null; // get interpreter config through GUI var config = this.DoGUIConfiguration(preConfig, settings); if (config == null) { Logger.WriteWarning("Operation canceled 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); } catch (Exception ex) { Logger.WriteError("Interpretation failed {0}<br>{1}", ex.Message, ex.StackTrace); } finally { if (MgaGateway != null && MgaGateway.territory != null) { MgaGateway.territory.Destroy(); } DisposeLogger(); MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (this.enabled == false) { return; } try { this.Logger = new CyPhyGUIs.GMELogger(project, this.ComponentName); // Need to call this interpreter in the same way as the MasterInterpreter will call it. // initialize main parameters if (currentobj == null) { this.Logger.WriteError("CyPhy2Modelica_v2 must be invoked on a Test Bench."); return; } var parameters = new InterpreterMainParameters() { Project = project, CurrentFCO = currentobj, SelectedFCOs = selectedobjs, StartModeParam = param, VerboseConsole = true }; this.mainParameters = parameters; parameters.ProjectDirectory = Path.GetDirectoryName(currentobj.Project.ProjectConnStr.Substring("MGA=".Length)); // set up the output directory MgaGateway.PerformInTransaction(delegate { string outputDirName = project.Name; if (currentobj != null) { outputDirName = currentobj.Name; } parameters.OutputDirectory = Path.GetFullPath(Path.Combine( parameters.ProjectDirectory, "results", outputDirName)); //this.Parameters.PackageName = Modelica.Factory.GetModifiedName(currentobj.Name); }); 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(CyPhy2Modelica_v2Settings), 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; } // 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; } MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } }