public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { this.Logger.WriteInfo("Running Component Authoring interpreter."); // verify we are running in a component and that it is not an instance or library string return_msg; if (!CheckPreConditions(currentobj, out return_msg)) { this.Logger.WriteFailed(return_msg); return; } // assuming a component is open // stash off the project, currentobj and CurrentComponent parameters for use in the event handlers StashProject = project; StashCurrentObj = currentobj; StashCurrentComponent = CyPhyClasses.Component.Cast(currentobj); // use reflection to populate the dialog box objects PopulateDialogBox(); // To use the domain-specific API: // Create another project with the same name as the paradigm name // Copy the paradigm .mga file to the directory containing the new project // In the new project, install the GME DSMLGenerator NuGet package (search for DSMLGenerator) // Add a Reference in this project to the other project // Add "using [ParadigmName] = ISIS.GME.Dsml.[ParadigmName].Classes.Interfaces;" to the top of this file // if (currentobj.Meta.Name == "KindName") // [ParadigmName].[KindName] dsCurrentObj = ISIS.GME.Dsml.[ParadigmName].Classes.[KindName].Cast(currentobj); }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { GMEConsole = GMEConsole.CreateFromProject(project); MgaGateway = new MgaGateway(project); project.CreateTerritoryWithoutSink(out MgaGateway.territory); MgaGateway.PerformInTransaction(delegate { Main(project, currentobj, selectedobjs, Convert(param)); }, abort: true); } finally { if (MgaGateway.territory != null) { MgaGateway.territory.Destroy(); } MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GMEConsole = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { // TODO: Add your interpreter code gmeConsole.Out.WriteLine("Running Subtree Merge Utility ..."); string[] FileNames = null; DialogResult dr; using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.CheckFileExists = true; ofd.DefaultExt = "mga"; ofd.Multiselect = false; ofd.Filter = "mga files (*.mga)|*.mga|All files (*.*)|*.*"; dr = ofd.ShowDialog(); if (dr == DialogResult.OK) { FileNames = ofd.FileNames; } } if (dr == DialogResult.OK) { MgaGateway.PerformInTransaction(delegate { SubTreeMerge subTreeMerge = new SubTreeMerge(); subTreeMerge.gmeConsole = gmeConsole; subTreeMerge.merge(currentobj, FileNames[0]); }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: false); return; } else { gmeConsole.Warning.WriteLine("Subtree Merge Utility cancelled"); return; } }
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { // create a checker instance var ch = new Framework.Checker(currentobj, project, null); var checkerWindow = new RuleView(ch); checkerWindow.ShowDialog(); }
public void InvokeEx2(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { string projectPath = Path.GetDirectoryName(project.ProjectConnStr.Substring(4)); // skip mga= string projectName = Path.GetFileNameWithoutExtension(project.ProjectConnStr.Substring(4)); string cyphyFilename = project.ProjectConnStr.Substring(4); baseOutputDir = Path.Combine(projectPath, projectName + "_PRISMATIC"); GME.CSharp.GMEConsole console = GME.CSharp.GMEConsole.CreateFromProject(project); console.Out.WriteLine("Output directory is " + baseOutputDir); META_PATH = GetMetaPathValue(); if (!Directory.Exists(META_PATH)) { throw new ApplicationException("META_PATH='" + META_PATH + "' doesn't exist. Please install the META toolchain and restart GME."); } string metaPath = Path.Combine( META_PATH, "meta" ); if (!Directory.Exists(metaPath)) { throw new ApplicationException(metaPath + " doesn't exist"); } ensureDir(baseOutputDir); string CyPhyML_udm_xml_path = Path.Combine(metaPath, "CyPhyML_udm.xml"); if (!File.Exists(CyPhyML_udm_xml_path)) { CyPhyML_udm_xml_path = Path.Combine(metaPath, @"..\generated\CyPhyML\models\CyPhyML_udm.xml"); } string CyPhyML_xsd_path = Path.Combine(metaPath, "CyPhyML.xsd"); if (!File.Exists(CyPhyML_xsd_path)) { CyPhyML_xsd_path = Path.Combine(metaPath, @"..\generated\CyPhyML.xsd"); } console.Out.WriteLine("Extracting XML model..."); runProgram( Path.Combine(metaPath, @"..\bin\UdmCopy.exe"), new string[] { "-f", cyphyFilename, Path.Combine( baseOutputDir, projectName + ".xml" ), CyPhyML_udm_xml_path, CyPhyML_xsd_path } ); console.Out.WriteLine("Generating Prismatic files..."); runProgram( "C:\\Python26\\python.exe", new string[] { META_PATH + "\\bin\\Prismatic\\" + "cmc.py", Path.Combine( baseOutputDir, projectName + ".xml" ), baseOutputDir } ); console.Out.WriteLine("Running Prismatic..."); runProgram( "C:\\Python27\\python.exe", new string[] { baseOutputDir + "\\prismatic.py" }); console.Out.WriteLine("Prismatic work done."); }
private void ElaborateModel(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { // call elaborator and expand the references Type t = Type.GetTypeFromProgID("MGA.Interpreter.CyPhyElaborate"); IMgaComponentEx elaborator = Activator.CreateInstance(t) as IMgaComponentEx; elaborator.Initialize(project); elaborator.ComponentParameter["automated_expand"] = "true"; elaborator.ComponentParameter["console_messages"] = "off"; elaborator.InvokeEx(project, currentobj, selectedobjs, param); }
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { // TODO: Add your interpreter code GMEConsole.Out.WriteLine("Running interpreter..."); // Get RootFolder $GET_ROOTFOLDER_CODE$ // To use the domain-specific API: // Create another project with the same name as the paradigm name // Copy the paradigm .mga file to the directory containing the new project // In the new project, install the GME DSMLGenerator NuGet package (search for DSMLGenerator) // Add a Reference in this project to the other project // Add "using [ParadigmName] = ISIS.GME.Dsml.[ParadigmName].Interfaces;" to the top of this file // if (currentobj != null && currentobj.Meta.Name == "KindName") // [ParadigmName].[KindName] dsCurrentObj = ISIS.GME.Dsml.[ParadigmName].Classes.[KindName].Cast(currentobj); }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { GMEConsole = GMEConsole.CreateFromProject(project); if (currentobj == null) { // TODO: Add Ballistic TB here once supported. this.GMEConsole.Error.Write("CyPhyMultiJobRun must be called from either a BlastTestBench, CFDTestBench, or BallisticTestBench."); return; } MgaGateway = new MgaGateway(project); string kindName = null; MgaGateway.PerformInTransaction(delegate { kindName = currentobj.MetaBase.Name; }); if (kindName == "CFDTestBench" || kindName == "BlastTestBench" || kindName == "BallisticTestBench") { } else { this.GMEConsole.Error.Write("CyPhyMultiJobRun must be called from either a BlastTestBench or CFDTestBench, not '{0}'", kindName); return; } Main(project, currentobj, selectedobjs, Convert(param)); } finally { MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GMEConsole = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }
private bool Elaborate( MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { try { bool Expanded = this.componentParameters[OptionNameIFab] as String == "true"; if (!Expanded) { try { var elaborator = new CyPhyElaborateCS.CyPhyElaborateCSInterpreter(); elaborator.Logger = new GMELogger(project); elaborator.Logger.AddWriter(Logger.Instance); var result = elaborator.RunInTransaction(project, currentobj, selectedobjs, param); if (result == false) { throw new ApplicationException("see elaborator log"); } if (this.result.Traceability == null) { this.result.Traceability = new META.MgaTraceability(); } if (elaborator.Traceability != null) { elaborator.Traceability.CopyTo(this.result.Traceability); } } catch (Exception e) { Logger.Instance.AddLogMessage("Elaborator exception occurred: " + e.Message, Severity.Error); throw new Exception(e.Message); } } } catch (Exception ex) { Logger.Instance.AddLogMessage(ex.ToString(), Severity.Error); return(false); } return(true); }
public void Main( MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew(); GMEConsole.Out.WriteLine("Running interpreter..."); if (project.RootMeta.Name == "MetaGME") { GMEConsole.Out.WriteLine("Generating .NET API code"); GenerateDotNetCode(project, currentobj, selectedobjs, startMode); } GMEConsole.Out.WriteLine("Elapsed time: {0}", sw.Elapsed.ToString("c")); }
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { string[] fileNames = null; DialogResult dr; using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.CheckFileExists = true; ofd.DefaultExt = "design.adm"; ofd.Multiselect = true; ofd.Filter = "AVM design files (*.adm)|*.adm|All files (*.*)|*.*"; ofd.RestoreDirectory = true; if (project.ProjectConnStr.StartsWith("MGA=", true, System.Globalization.CultureInfo.InvariantCulture)) { ofd.InitialDirectory = Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length)); } dr = ofd.ShowDialog(); if (dr == DialogResult.OK) { fileNames = ofd.FileNames; } } if (dr == DialogResult.OK) { Model[] result = null; MgaGateway.PerformInTransaction(delegate { var importer = new AVMDesignImporter(GMEConsole, project); result = importer.ImportFiles(fileNames, mode: AVMDesignImporter.DesignImportMode.CREATE_CA_IF_NO_DS_CONCEPTS); }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: false); if (result.Length > 0 && GMEConsole.gme != null) { GMEConsole.gme.ShowFCO((MgaFCO)result[0].Impl); } return; } else { GMEConsole.Warning.WriteLine("Design Importer canceled"); return; } }
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { string[] fileNames = null; DialogResult dr; using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.CheckFileExists = true; ofd.DefaultExt = "testbench.atm"; ofd.Multiselect = true; ofd.Filter = "AVM testbench files (*.atm)|*.atm|All files (*.*)|*.*"; dr = ofd.ShowDialog(); if (dr == DialogResult.OK) { fileNames = ofd.FileNames; } } if (dr == DialogResult.OK) { MgaGateway.PerformInTransaction(delegate { foreach (var fileName in fileNames) { using (var streamReader = new StreamReader(fileName)) { var avmTestBench = XSD2CSharp.AvmXmlSerializer.Deserialize <avm.TestBench>(streamReader); CyPhy2TestBenchInterchange.TestBenchInterchange2CyPhy.Convert(avmTestBench, project); } } }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: false); //if (result.Any() && GMEConsole.gme != null) //{ // GMEConsole.gme.ShowFCO((MgaFCO)result.First().Impl); //} return; } else { GMEConsole.Warning.WriteLine("TestBench Importer canceled"); return; } }
public static void RunFormulaEvaluator(this ISIS.GME.Dsml.CyPhyML.Interfaces.Component component) { var project = component.Impl.Project; var currentobj = component.Impl as MgaFCO; // create formula evaluator type // FIXME: calling the elaborator is faster than calling the formula evaluator Type typeFormulaEval = Type.GetTypeFromProgID("MGA.Interpreter.CyPhyFormulaEvaluator"); IMgaComponentEx formulaEval = Activator.CreateInstance(typeFormulaEval) as IMgaComponentEx; // empty selected object set Type typeMgaFCOs = Type.GetTypeFromProgID("Mga.MgaFCOs"); MgaFCOs selectedObjs = Activator.CreateInstance(typeMgaFCOs) as MgaFCOs; // initialize formula evauator formulaEval.Initialize(project); // automation means no UI element shall be shown by the interpreter formulaEval.ComponentParameter["automation"] = "true"; // do not write to the console formulaEval.ComponentParameter["console_messages"] = "off"; // do not expand nor collapse the model formulaEval.ComponentParameter["expanded"] = "true"; // do not generate the post processing python scripts // FIXME: Why should we generate them ??? formulaEval.ComponentParameter["do_not_generate_post_processing"] = "true"; // call the formula evaluator and update all parameters starting from the current object try { formulaEval.InvokeEx(project, currentobj, selectedObjs, 128); } catch (COMException) { // FIXME: handle this exception properly // success = false; // this.Logger.WriteError(exceptionMessage); // this.Logger.WriteError("CyPhyFormulaEvaluator 1.0 finished with errors"); } }
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { string[] fileNames = null; DialogResult dr; using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.CheckFileExists = true; ofd.DefaultExt = "testbench.atm"; ofd.Multiselect = true; ofd.Filter = "AVM testbench files (*.atm)|*.atm|All files (*.*)|*.*"; dr = ofd.ShowDialog(); if (dr == DialogResult.OK) { fileNames = ofd.FileNames; } } if (dr == DialogResult.OK) { MgaGateway.PerformInTransaction(delegate { foreach (var fileName in fileNames) { using (var streamReader = new StreamReader(fileName)) { var avmTestBench = XSD2CSharp.AvmXmlSerializer.Deserialize<avm.TestBench>(streamReader); CyPhy2TestBenchInterchange.TestBenchInterchange2CyPhy.Convert(avmTestBench, project); } } }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: false); //if (result.Any() && GMEConsole.gme != null) //{ // GMEConsole.gme.ShowFCO((MgaFCO)result.First().Impl); //} return; } else { GMEConsole.Warning.WriteLine("TestBench Importer canceled"); return; } }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { if (Logger == null) { Logger = new GMELogger(project, ComponentName); } MgaGateway = new MgaGateway(project); this.mainParameters = new InterpreterMainParameters() { Project = project, CurrentFCO = currentobj as MgaFCO, SelectedFCOs = selectedobjs, StartModeParam = param }; _Main(this.mainParameters); //this.PrintRuntimeStatistics(); } catch (Exception ex) { Logger.WriteError("Exception: {0}<br> {1}", ex.Message, ex.StackTrace); } finally { MgaGateway = null; project = null; currentobj = null; selectedobjs = null; DisposeLogger(); GC.Collect(); GC.WaitForPendingFinalizers(); } }
private bool CallElaborator( MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param, bool expand = true) { bool result = false; try { this.Logger.WriteDebug("Elaborating model..."); var elaborator = new CyPhyElaborateCS.CyPhyElaborateCSInterpreter() { Logger = Logger }; elaborator.Initialize(project); int verbosity = 128; elaborator.UnrollConnectors = true; result = elaborator.RunInTransaction(project, currentobj, selectedobjs, verbosity, mainParameters.OutputDirectory); if (this.result.Traceability == null) { this.result.Traceability = new META.MgaTraceability(); } if (elaborator.Traceability != null) { elaborator.Traceability.CopyTo(this.result.Traceability); elaborator.Traceability.CopyTo(Logger.Traceability); } this.Logger.WriteDebug("Elaboration is done."); } catch (Exception ex) { this.Logger.WriteError("Exception occurred in Elaborator : {0}", ex.ToString()); result = false; } return(result); }
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { string OutputBaseDir = (string)componentParameters["output_dir"]; SotConfig sotConfig = new SotConfig(); sotConfig.MultiJobRun = true; sotConfig.OriginalProjectFileName = project.ProjectConnStr.Substring("MGA=".Length); sotConfig.ProjectFileName = Path.Combine(OutputBaseDir, Path.GetFileName(sotConfig.OriginalProjectFileName)); // can't be in a tx and save the project project.AbortTransaction(); project.Save("MGA=" + sotConfig.ProjectFileName, true); project.BeginTransactionInNewTerr(transactiontype_enum.TRANSACTION_NON_NESTED); MgaGateway.PerformInTransaction(delegate { sotConfig.SoTID = currentobj.ID; }, transactiontype_enum.TRANSACTION_READ_ONLY); using (StreamWriter writer = new StreamWriter(Path.Combine(OutputBaseDir, "manifest.sot.json"))) { writer.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(sotConfig, Newtonsoft.Json.Formatting.Indented)); } string configsDir = Path.Combine(Path.GetDirectoryName((string)componentParameters["original_project_file"]), "config"); if (Directory.Exists(configsDir)) { var configs = Directory.EnumerateFiles(configsDir, "*xml").ToList(); string sotConfigDir = Path.Combine(OutputBaseDir, "config"); Directory.CreateDirectory(sotConfigDir); foreach (var config in configs) { File.Copy(config, Path.Combine(sotConfigDir, Path.GetFileName(config))); } } //componentParameters["labels"] = ""; //componentParameters["runCommand"] = ; //componentParameters["results_zip_py"] as string; // result.LogFileDirectory = Path.Combine(MainParameters.ProjectDirectory, "log"); // componentParameters["build_query"] as string; }
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { string projroot = Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length)); // TODO: Add your interpreter code GMEConsole.Out.WriteLine("Running Component Importer..."); string[] FileNames = null; DialogResult dr; using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.CheckFileExists = true; ofd.DefaultExt = "component.acm"; ofd.Multiselect = true; ofd.Filter = "component files (*.acm;*.component.acm;*.zip)|*.acm;*.component.acm;*.zip|All files (*.*)|*.*"; dr = ofd.ShowDialog(); if (dr == DialogResult.OK) { FileNames = ofd.FileNames; } } if (dr == DialogResult.OK) { MgaGateway.PerformInTransaction(delegate { ImportFiles(project, projroot, FileNames); }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: false); return; } else { GMEConsole.Warning.WriteLine("Component Importer canceled"); return; } // Get RootFolder //IMgaFolder rootFolder = project.RootFolder; //GMEConsole.Out.WriteLine(rootFolder.Name); }
private void CallElaboratorAndMain(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { META_PATH = META.VersionInfo.MetaPath; GMEConsole = GMEConsole.CreateFromProject(project); #region Elaborate the TestBench // call elaborator and expand the references Type t = Type.GetTypeFromProgID("MGA.Interpreter.CyPhyElaborate"); IMgaComponentEx elaborator = Activator.CreateInstance(t) as IMgaComponentEx; elaborator.Initialize(project); elaborator.ComponentParameter["automated_expand"] = "true"; elaborator.ComponentParameter["console_messages"] = "off"; elaborator.InvokeEx(project, currentobj, selectedobjs, (int)ComponentStartMode.GME_SILENT_MODE); #endregion MgaGateway.PerformInTransaction(delegate { Main(project, currentobj, selectedobjs, Convert(param)); }); }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { GMEConsole = GMEConsole.CreateFromProject(project); MgaGateway = new MgaGateway(project); project.CreateTerritoryWithoutSink(out MgaGateway.territory); MgaGateway.PerformInTransaction(delegate { Main(project, currentobj, selectedobjs, Convert(param)); }); MgaGateway.PerformInTransaction(delegate { mig.DeleteAllOldTypes(project); mig.findOldPortTypes(project, false); }); } finally { if (MgaGateway.territory != null) { MgaGateway.territory.Destroy(); } MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GMEConsole = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }
public bool Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { // TODO: Add your interpreter code //GMEConsole.Clear(); GMEConsole.Out.WriteLine("Running CyPhy2CAD interpreter..."); // TODO: show how to initialize DSML-generated classes // Get RootFolder //IMgaFolder rootFolder = project.RootFolder; //GMEConsole.Out.WriteLine(rootFolder.Name); // Check Model // Grab all components // Create Intermediate Data Representations // Walk representation + find islands // Convert to DAG try { // META-1971: ADM + ACM file export for blast + ballistics // ACM { CallComponentExporter(project, currentobj); } result.Success = true; ProcessCAD(currentobj); Logger.Instance.DumpLog(GMEConsole, LogDir); GMEConsole.Out.WriteLine("Finished CyPhy2CAD with " + (result.Success ? "success" : "failure")); return(result.Success); } catch (Exception ex) { Logger.Instance.AddLogMessage(ex.Message, Severity.Error); Logger.Instance.DumpLog(GMEConsole, LogDir); GMEConsole.Out.WriteLine(ex.StackTrace.ToString()); GMEConsole.Out.WriteLine("Finished CyPhy2CAD with failure. Exception encountered."); return(false); } }
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { string projroot = Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length)); // TODO: Add your interpreter code Logger.WriteInfo("Running {0}...", this.ComponentName); string[] FileNames = null; DialogResult dr; using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.CheckFileExists = true; ofd.DefaultExt = "component.acm"; ofd.Multiselect = true; ofd.Filter = "component files (*.acm;*.component.acm;*.zip)|*.acm;*.component.acm;*.zip|All files (*.*)|*.*"; dr = ofd.ShowDialog(); if (dr == DialogResult.OK) { FileNames = ofd.FileNames; } } if (dr == DialogResult.OK) { MgaGateway.PerformInTransaction(delegate { ImportFiles(project, projroot, FileNames); }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: false); Logger.WriteSuccess("{0} complete", this.ComponentName); return; } else { Logger.WriteFailed("Component Importer canceled"); } return; }
private IMgaTraceability CallElaborator( MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param, bool expand = true) { bool result = false; try { if (Logger != null) { Logger.WriteInfo("Elaborating model..."); } var elaborator = new CyPhyElaborateCS.CyPhyElaborateCSInterpreter(); elaborator.Initialize(project); int verbosity = 128; elaborator.UnrollConnectors = false; result = elaborator.RunInTransaction(project, currentobj, selectedobjs, verbosity); if (Logger != null) { Logger.WriteInfo("Elaboration is done."); } if (result == true) { return(elaborator.Traceability); } } catch (Exception ex) { if (Logger != null) { Logger.WriteError("Exception occurred in Elaborator : {0}", ex.ToString()); } } throw new ApplicationException("Elaborator failed"); }
// JS: 7/15/13 private void CallComponentExporter( MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { Type tCAD = Type.GetTypeFromProgID("MGA.Interpreter.CyPhyComponentExporter"); if (tCAD == null) { GMEConsole.Info.WriteLine("CyPhyComponentExporter is not installed on your machine."); return; } ComComponent cyPhyCompExp = new ComComponent("MGA.Interpreter.CyPhyComponentExporter"); cyPhyCompExp.Initialize(project); // call component exporter to traverse design and build component index CyPhyComponentExporter.CyPhyComponentExporterInterpreter compExport = new CyPhyComponentExporter.CyPhyComponentExporterInterpreter(); compExport.Initialize(project); compExport.TraverseTestBenchForComponentExport(currentobj, this.OutputDirectory, this.ProjectRootDirectory); }
private bool CallElaborator( MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param, bool expand = true) { bool result = false; try { var elaborator = new CyPhyElaborateCS.CyPhyElaborateCSInterpreter(); elaborator.Initialize(project); Logger.WriteInfo("Elaborating model..."); System.Windows.Forms.Application.DoEvents(); int verbosity = 128; result = elaborator.RunInTransaction(project, currentobj, selectedobjs, verbosity); if (this.result.Traceability == null) { this.result.Traceability = new META.MgaTraceability(); } if (elaborator.Traceability != null) { elaborator.Traceability.CopyTo(this.result.Traceability); } //this.Logger.WriteDebug("Elaboration is done."); } catch (Exception ex) { Logger.WriteError(ex.Message); return(false); } return(true); }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { Main(project, currentobj, selectedobjs, Convert(param)); } finally { MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GMEConsole = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }
public void NullObjectAndInteractiveMode() { MgaProject project = null; MgaFCO currentObj = null; MgaFCOs fcos = null; MgaObject obj = null; MgaObjects objs = null; IMgaComponentEx interpreter = GetInterpreterByProgID(ProgID); Assert.Throws <ArgumentNullException>(() => { interpreter.Initialize(project); }); Assert.Throws <NotImplementedException>(() => { interpreter.ObjectsInvokeEx(project, obj, objs, 128); }); Assert.Throws <ArgumentNullException>(() => { interpreter.InvokeEx(project, currentObj, fcos, 128); }); Assert.True(File.Exists(this.mgaFile), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(this.mgaFile); project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { // project is set, but fcos are not Assert.DoesNotThrow(() => { interpreter.Initialize(project); }); Assert.Throws <ArgumentNullException>(() => { interpreter.InvokeEx(project, currentObj, fcos, 128); }); // fcos are set fcos = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs")); Assert.DoesNotThrow(() => { interpreter.InvokeEx(project, currentObj, fcos, 128); }); Assert.True(interpreter.InteractiveMode == false, "Interactive is not set correctly. (128) silent mode"); Assert.DoesNotThrow(() => { interpreter.InvokeEx(project, currentObj, fcos, 16); }); Assert.True(interpreter.InteractiveMode == true, "Interactive is not set correctly. (16)"); } finally { project.Close(true); } }
private bool CallElaborator( MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param, bool expand = true) { bool result = false; try { GMEConsole.Info.WriteLine("Calling elaborator..."); var elaborator = new CyPhyElaborateCS.CyPhyElaborateCSInterpreter(); elaborator.Initialize(project); int verbosity = 128; elaborator.UnrollConnectors = true; result = elaborator.RunInTransaction(project, currentobj, selectedobjs, verbosity); if (this.result.Traceability == null) { this.result.Traceability = new META.MgaTraceability(); } if (elaborator.Traceability != null) { elaborator.Traceability.CopyTo(this.result.Traceability); } GMEConsole.Info.WriteLine("Elaboration is done."); } catch (Exception ex) { GMEConsole.Error.WriteLine("Exception occurred in Elaborator : {0}", ex.ToString()); result = false; } return(result); }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { GMEConsole = GMEConsole.CreateFromProject(project); MgaGateway = new MgaGateway(project); project.CreateTerritoryWithoutSink(out MgaGateway.territory); MgaGateway.PerformInTransaction(delegate { Main(project, currentobj, selectedobjs, Convert(param)); }, transactiontype_enum.TRANSACTION_NON_NESTED); } finally { if (MgaGateway.territory != null) { MgaGateway.territory.Destroy(); } //ISIS.GME.Common.Utils.ObjectCache.Clear(); MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GMEConsole = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { this.project = project; GMEConsole = GMEConsole.CreateFromProject(project); MgaGateway = new MgaGateway(project); project.CreateAddOn(this, out addon); // addOn->put_EventMask(OBJEVENT_ATTR | OBJEVENT_CONNECTED)); MgaGateway.PerformInTransaction(delegate { component = Main(project, currentobj, selectedobjs, Convert(param)); }); if (GMEConsole.gme != null && component != null) { GMEConsole.gme.ShowFCO(component, false); } } 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 { var 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; } Main(project, currentobj, selectedobjs, Convert(param)); }); } catch (Exception ex) { } finally { MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }
private MgaFCO SurrogateMaster( MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param, bool expand = true) { MgaFolder f = currentobj.ParentFolder; if (f == null) { throw new Exception("Testbench does not have a TestFolder parent!"); } MgaFolder fNew = f.CreateFolder(f.MetaFolder); fNew.Name = currentobj.Name + DateTime.Now.ToString(" (MM-dd-yyyy HH:mm:ss)"); MgaFCO newTestbench = fNew.CopyFCODisp(currentobj); //newTestbench.Name += " TestName"; return(newTestbench); }
private void CallCAD( MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { Type tCAD = Type.GetTypeFromProgID("MGA.Interpreter.CyPhy2CAD_CSharp"); if (tCAD == null) { GMEConsole.Info.WriteLine("CyPhy2CAD is not installed on your machine."); return; } ComComponent cyPhy2CAD = new ComComponent("MGA.Interpreter.CyPhy2CAD_CSharp"); //cyPhy2CAD.WorkflowParameters["prepIFab"] = "true"; cyPhy2CAD.Initialize(project); cyPhy2CAD.InterpreterConfig = cadSettings; // TODO cyPhy2CAD.MainParameters.config.CADAnalysis = true; //cyPhy2CAD.MainParameters.ConsoleMessages = ; cyPhy2CAD.MainParameters.Project = project; cyPhy2CAD.MainParameters.CurrentFCO = currentobj; cyPhy2CAD.MainParameters.SelectedFCOs = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs")); cyPhy2CAD.MainParameters.StartModeParam = param; cyPhy2CAD.MainParameters.OutputDirectory = this.OutputDirectory; cyPhy2CAD.MainParameters.ProjectDirectory = this.ProjectRootDirectory; cyPhy2CAD.MainParameters.Traceability = (META.MgaTraceability) this.result.Traceability; cyPhy2CAD.Main(); this.componentParameters["results_zip_py"] = cyPhy2CAD.result.ZippyServerSideHook; }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { GMEConsole = GMEConsole.CreateFromProject(project); MgaGateway = new MgaGateway(project); this.Logger = new CyPhyGUIs.GMELogger(project, this.ComponentName); if (currentobj == null) { this.Logger.WriteError("Invalid context. This interpreter can only be run if open in the correct context (E.g., test bench)."); return; } GMEConsole.Out.WriteLine(DateTime.Now.ToString() + " running CyPhyPrepIFab Interpreter"); //InitLogger(); // [1] CyPhy2CAD // [2] Export DDP, Manufacture XML, Manufacture Manifest // [3] Generate AppendArtifact.py - script to append artifacts to testbench_manifest.json files // [4] Generate DesignModel1BOM.py - script to generate .bom.json from ddp file // [5] Generate main run bat file //CallCAD(project, currentobj, selectedobjs, param); // CyPhy2CAD MgaGateway.PerformInTransaction(delegate { string kindName = string.Empty; if (currentobj != null) { kindName = currentobj.MetaBase.Name; } if (string.IsNullOrEmpty(kindName) == false && kindName != typeof(CyPhyClasses.TestBench).Name) { Logger.WriteFailed("CyPhyPrepIFAB must be called from a TestBench."); return; } ElaborateModel(project, currentobj, selectedobjs, param); // elaborate model CallCAD(project, currentobj, selectedobjs, param); // CyPhy2CAD ManufacturingGeneration(currentobj); // DDP, Manufacture XML, Manufacture Manifest }, transactiontype_enum.TRANSACTION_NON_NESTED); GenerateAppendArtifactScript(); // AppendArtifact.py GenerateBOMGenScript(); // DesignModel1BOM.py GenerateRunBatFile(); // main run bat file GMEConsole.Out.WriteLine("CyPhyPrepIFab Interpreter Finished!"); } catch (Exception) { Logger.WriteError("{0} has finished with critical errors. Please see above.", this.ComponentName); } finally { //Trace.Close(); MgaGateway = null; if (Logger != null) Logger.Dispose(); project = null; currentobj = null; selectedobjs = null; GMEConsole = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }
// Old interface, it is never called for MgaComponentEx interfaces public void Invoke(MgaProject Project, MgaFCOs selectedobjs, int param) { throw new NotImplementedException(); }
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { string projroot = Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length)); // TODO: Add your interpreter code Logger.WriteInfo("Running {0}...", this.ComponentName); string[] FileNames = null; DialogResult dr; using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.CheckFileExists = true; ofd.DefaultExt = "component.acm"; ofd.Multiselect = true; ofd.Filter = "component files (*.acm;*.component.acm;*.zip)|*.acm;*.component.acm;*.zip|All files (*.*)|*.*"; dr = ofd.ShowDialog(); if (dr == DialogResult.OK) { FileNames = ofd.FileNames; } } if (dr == DialogResult.OK) { MgaGateway.PerformInTransaction(delegate { ImportFiles(project, projroot, FileNames); }, transactiontype_enum.TRANSACTION_NON_NESTED); Logger.WriteSuccess("{0} complete", this.ComponentName); } else { Logger.WriteFailed("Component Importer canceled"); } return; }
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 Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { MgaGateway = new MgaGateway(project); project.CreateTerritoryWithoutSink(out MgaGateway.territory); this.Logger = new CyPhyGUIs.GMELogger(project, this.GetType().Name); MgaGateway.PerformInTransaction(delegate { Main(project, currentobj, selectedobjs, Convert(param)); }); } finally { if (Logger != null) { Logger.Dispose(); } if (MgaGateway.territory != null) { MgaGateway.territory.Destroy(); } MgaGateway = null; Logger = null; project = null; currentobj = null; selectedobjs = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { throw new NotImplementedException("Function Main(MgaProject, MgaFCO, MgaFCOs, ComponentStartMode) not implemented."); }
// Old interface, it is never called for MgaComponentEx interfaces public void Invoke(MgaProject Project, MgaFCOs selectedobjs, int param) { }
private bool Elaborate( MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { try { bool Expanded = this.componentParameters[OptionNameIFab] as String == "true"; if (!Expanded) { try { var elaborator = new CyPhyElaborateCS.CyPhyElaborateCSInterpreter(); elaborator.Logger = new GMELogger(project); elaborator.Logger.AddWriter(Logger.Instance); var result = elaborator.RunInTransaction(project, currentobj, selectedobjs, param); if (result == false) { throw new ApplicationException("see elaborator log"); } if (this.result.Traceability == null) { this.result.Traceability = new META.MgaTraceability(); } if (elaborator.Traceability != null) { elaborator.Traceability.CopyTo(this.result.Traceability); } } catch (Exception e) { Logger.Instance.AddLogMessage("Elaborator exception occurred: " + e.Message, Severity.Error); throw new Exception(e.Message); } } } catch (Exception ex) { Logger.Instance.AddLogMessage(ex.ToString(), Severity.Error); return false; } return true; }
private void ElaborateModel(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { try { var elaborator = new CyPhyElaborateCS.CyPhyElaborateCSInterpreter(); elaborator.Logger = new GMELogger(project); //elaborator.Logger.AddWriter(Logger.Instance); var result = elaborator.RunInTransaction(project, currentobj, selectedobjs, param); if (result == false) { throw new ApplicationException("see elaborator log"); } if (this.result.Traceability == null) { this.result.Traceability = new META.MgaTraceability(); } if (elaborator.Traceability != null) { elaborator.Traceability.CopyTo(this.result.Traceability); } } catch (Exception e) { //Logger.Instance.AddLogMessage("Elaborator exception occurred: " + e.Message, Severity.Error); throw new Exception(e.Message); } }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { //ComponentIndex ci = new ComponentIndex(); GMEConsole = GMEConsole.CreateFromProject(project); MgaGateway = new MgaGateway(project); this.Logger = new CyPhyGUIs.GMELogger(project, this.ComponentName); if (currentobj == null) { this.Logger.WriteError("Invalid context. This interpreter can only be run if open in the correct context (E.g., test bench)."); return; } GMEConsole.Out.WriteLine(DateTime.Now.ToString() + " running CyPhyCADAnalysis Interpreter"); //InitLogger(); // [1] create avmproj string projectName = ""; MgaGateway.PerformInTransaction(delegate { projectName = project.Name; }, transactiontype_enum.TRANSACTION_NON_NESTED); // META-3080: use passed in project directory, especially in SOTs where .mga file is in a different directory than manifest.project.json if (String.IsNullOrEmpty(this.ProjectRootDirectory)) this.ProjectRootDirectory = Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length)); string avmProjFileName = Path.Combine(this.ProjectRootDirectory, "manifest.project.json"); //string avmProjFileName = Path.Combine(Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length)), "manifest.project.json"); //this.ProjectRootDirectory = Path.GetDirectoryName(avmProjFileName); AVM.DDP.MetaAvmProject avmProj = new AVM.DDP.MetaAvmProject(); if (File.Exists(avmProjFileName)) { string sjson = "{}"; using (StreamReader reader = new StreamReader(avmProjFileName)) { sjson = reader.ReadToEnd(); avmProj = JsonConvert.DeserializeObject<AVM.DDP.MetaAvmProject>(sjson); this.AVMComponentList = avmProj.Project.Components; } } // end create avmproj // [1] CyPhy2CAD // [2] Export DDP, Manufacture XML, Manufacture Manifest // [3] Generate AppendArtifact.py - script to append artifacts to testbench_manifest.json files // [4] Generate DesignModel1BOM.py - script to generate .bom.json from ddp file // [5] Generate main run bat file //CallCAD(project, currentobj, selectedobjs, param); // CyPhy2CAD MgaGateway.PerformInTransaction(delegate { string kindName = string.Empty; if (currentobj != null) { kindName = currentobj.MetaBase.Name; } if (string.IsNullOrEmpty(kindName) == false && kindName != typeof(CyPhyClasses.TestBench).Name) { Logger.WriteFailed("CyPhyCADAnalysis must be called from a TestBench."); return; } ElaborateModel(project, currentobj, selectedobjs, param); // elaborate model CallCAD(project, currentobj, selectedobjs, param); // CyPhy2CAD CallComponentExporter(project, currentobj, selectedobjs, param); // JS: 7-15-13 ManufacturingGeneration(currentobj); // DDP, Manufacture XML, Manufacture Manifest }, transactiontype_enum.TRANSACTION_NON_NESTED); GenerateAppendArtifactScript(); // AppendArtifact.py GenerateBOMGenScript(); // DesignModel1BOM.py //GenerateAnalysisFilesScript(wkflow_param); GenerateRunBatFile(); // main run bat file GMEConsole.Out.WriteLine("CyPhyCADAnalysis Interpreter Finished!"); } catch (Exception ex) { Logger.WriteError("{0} has finished with critical errors. Please see above.", this.ComponentName); Logger.WriteError("Error Message: {0}", ex.Message); } finally { if (Logger!=null) Logger.Dispose(); MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GMEConsole = null; GC.Collect(); GC.WaitForPendingFinalizers(); } Trace.Flush(); Trace.Close(); }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { Main(project, currentobj, selectedobjs, Convert(param)); } finally { DisposeLogger(); if (MgaGateway.territory != null) { MgaGateway.territory.Destroy(); } MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { throw new NotImplementedException(); // Not called by addon }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } if (currentobj == null) { MessageBox.Show("Please select the subtree to be replaced (via merge) so that it is displayed in the main window."); return; } currentMgaProject = project; try { gmeConsole = new FlexConsole(FlexConsole.ConsoleType.GMECONSOLE, project); MgaGateway = new MgaGateway(project); Main(project, currentobj, selectedobjs, Convert(param)); } 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 (project == null) { throw new ArgumentNullException("project"); } if (selectedobjs == null) { throw new ArgumentNullException("selectedobjs"); } this.InteractiveMode = this.Convert(param) != ComponentStartMode.GME_SILENT_MODE; try { GMEConsole = GMEConsole.CreateFromProject(project); MgaGateway = new MgaGateway(project); project.CreateTerritoryWithoutSink(out MgaGateway.territory); this.GMEConsole.Clear(); System.Windows.Forms.Application.DoEvents(); this.InteractiveMode = this.Convert(param) != ComponentStartMode.GME_SILENT_MODE; this.Logger = new CyPhyGUIs.GMELogger(project, this.GetType().Name); this.Logger.GMEConsoleLoggingLevel = Properties.Settings.Default.bVerboseLogging ? CyPhyGUIs.SmartLogger.MessageType_enum.Debug : CyPhyGUIs.SmartLogger.MessageType_enum.Info; //this.Logger.WriteDebug("Hello debug"); //this.Logger.WriteError("Hello error {0} {1} {2}", 1, "string", true); //this.Logger.WriteInfo("Hello info"); //this.Logger.WriteWarning("Hello WriteWarning"); //this.Logger.WriteFailed("Hello WriteFailed"); //this.Logger.WriteSuccess("Hello WriteSuccess"); //this.Logger.WriteCheckFailed("Hello WriteCheckFailed"); //this.Logger.WriteCheckPassed("Hello WriteCheckPassed"); this.Logger.WriteInfo("Master Interpreter 2.0"); System.Windows.Forms.Application.DoEvents(); this.Logger.MakeVersionInfoHeader(); // control was held this.Process(currentobj); foreach (var filename in this.Logger.LogFilenames) { this.Logger.WriteInfo("Log file was generated here: <a href=\"file:///{0}\" target=\"_blank\">{1}</a>", Path.GetDirectoryName(filename), filename); } this.Logger.WriteInfo("Master Interpreter 2.0 finished"); } finally { this.Logger.Dispose(); System.Windows.Forms.Application.DoEvents(); if (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 (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); } }); 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(CyPhy2CADPCB_Settings), this.ComponentProgID); CyPhy2CADPCB_Settings settings = (settings_ != null) ? settings_ as CyPhy2CADPCB_Settings : new CyPhy2CADPCB_Settings(); // Set configuration based on Workflow Parameters. This will override all [WorkflowConfigItem] members. settings = InitializeSettingsFromWorkflow(settings); // 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 { 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 (!enabled) { return; } try { GMEConsole = GMEConsole.CreateFromProject(project); if (currentobj == null) { // TODO: Add Ballistic TB here once supported. this.GMEConsole.Error.Write("CyPhyMultiJobRun must be called from either a BlastTestBench, CFDTestBench, or BallisticTestBench."); return; } MgaGateway = new MgaGateway(project); project.CreateTerritoryWithoutSink(out MgaGateway.territory); string kindName = null; MgaGateway.PerformInTransaction(delegate { kindName = currentobj.MetaBase.Name; }); if (kindName == "CFDTestBench" || kindName == "BlastTestBench" || kindName == "BallisticTestBench") { } else { this.GMEConsole.Error.Write("CyPhyMultiJobRun must be called from either a BlastTestBench or CFDTestBench, not '{0}'", kindName); return; } Main(project, currentobj, selectedobjs, Convert(param)); } finally { if (MgaGateway != null && MgaGateway.territory != null) { MgaGateway.territory.Destroy(); } MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GMEConsole = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }
/** * First we disconnect all connections to refports, then move the reference, then reconnect */ public static void MoveReferenceWithRefportConnections(IMgaFCO fco2, IMgaReference origref, WriteLineF WriteLine) { Queue <IMgaReference> references = new Queue <IMgaReference>(); references.Enqueue(origref); IMgaFCO targetModel = fco2; while (targetModel is IMgaReference) { targetModel = ((IMgaReference)targetModel).Referred; } MgaFCOs fco2ChildFCOs = ((IMgaModel)targetModel).ChildFCOs; Dictionary <string, IMgaFCO> newRefeChildren = GetNameMap(fco2ChildFCOs, x => { }); // TODO: warn, but only for refport-connected children //GMEConsole.Warning.WriteLine("Warning: " + fco2.Name + " has multiple children named " + x)); int origPrefs = fco2.Project.Preferences; // Magic word allows us to remove ConnPoints fco2.Project.Preferences = origPrefs | (int)GME.MGA.preference_flags.MGAPREF_IGNORECONNCHECKS | (int)GME.MGA.preference_flags.MGAPREF_FREEINSTANCEREFS; try { MgaConnection conn = null; var ReconnectList = MakeList(new { ConnRole = "src", Ref = origref, Port = fco2, Conn = conn }); while (references.Count != 0) { IMgaReference refe = references.Dequeue(); foreach (IMgaConnPoint connPoint in refe.UsedByConns) { if (connPoint.References[1] != refe) { continue; } IMgaFCO fco2Port; if (newRefeChildren.TryGetValue(connPoint.Target.Name, out fco2Port)) { if (fco2Port == null) { // fco2Port == null => multiple children with the same name // Try matching based on Kind too fco2Port = fco2ChildFCOs.Cast <IMgaFCO>().Where(x => x.Name == connPoint.Target.Name && x.Meta.MetaRef == connPoint.Target.Meta.MetaRef).FirstOrDefault(); } if (fco2Port != null) { ReconnectList.Add(new { ConnRole = connPoint.ConnRole, Ref = refe, Port = fco2Port, Conn = connPoint.Owner }); connPoint.Remove(); } } else { WriteLine((x, y) => "Can't find corresponding port for " + x + " in " + y, connPoint.Target, fco2); connPoint.Owner.DestroyObject(); } } foreach (IMgaReference x in refe.ReferencedBy.Cast <IMgaReference>()) { if (x.ID == origref.ID) { throw new Exception("Circular reference chain starting with " + origref.AbsPath); } references.Enqueue(x); } } origref.Referred = (MgaFCO)fco2; foreach (var reconnect in ReconnectList) { if (reconnect.ConnRole == "src") { (reconnect.Conn as IMgaSimpleConnection).SetSrc((MgaFCOs)GetRefChain(reconnect.Ref), (MgaFCO)reconnect.Port); } else { (reconnect.Conn as IMgaSimpleConnection).SetDst((MgaFCOs)GetRefChain(reconnect.Ref), (MgaFCO)reconnect.Port); } } } finally { fco2.Project.Preferences = origPrefs; } }
public bool Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode) { // TODO: Add your interpreter code //GMEConsole.Clear(); GMEConsole.Out.WriteLine("Running CyPhy2CAD interpreter..."); // TODO: show how to initialize DSML-generated classes // Get RootFolder //IMgaFolder rootFolder = project.RootFolder; //GMEConsole.Out.WriteLine(rootFolder.Name); // Check Model // Grab all components // Create Intermediate Data Representations // Walk representation + find islands // Convert to DAG try { // META-1971: ADM + ACM file export for blast + ballistics // ACM { CallComponentExporter(project, currentobj); } result.Success = true; ProcessCAD(currentobj); Logger.Instance.DumpLog(GMEConsole, LogDir); GMEConsole.Out.WriteLine("Finished CyPhy2CAD with " + (result.Success ? "success" : "failure")); return result.Success; } catch (Exception ex) { Logger.Instance.AddLogMessage(ex.Message, Severity.Error); Logger.Instance.DumpLog(GMEConsole, LogDir); GMEConsole.Out.WriteLine("Finished CyPhy2CAD with failure."); return false; } }
public void InvokeEx( MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } if (currentobj == null) { GMEConsole.Error.WriteLine("Please select a CADTestBench, Ballistic Testbench, FEA Testbench, Blast Testbench or CadAssembly."); return; } string currentWorkDir = System.IO.Directory.GetCurrentDirectory(); try { var parameters = new InterpreterMainParameters(); this.mainParameters = parameters; parameters.ProjectDirectory = Path.GetDirectoryName(currentobj.Project.ProjectConnStr.Substring("MGA=".Length)); FetchSettings(); // Show UI using (MainForm mf = new MainForm(settings)) { mf.ShowDialog(); DialogResult ok = mf.DialogResult; if (ok == DialogResult.OK) { settings = mf.ConfigOptions; parameters.OutputDirectory = settings.OutputDirectory; parameters.config = settings; } else { GMEConsole.Warning.WriteLine("Process was cancelled."); return; } } SaveSettings(); MgaGateway.PerformInTransaction(delegate { Elaborate(project, currentobj, selectedobjs, param); Main(project, currentobj, selectedobjs, Convert(param)); }, abort: true); } finally { MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GMEConsole = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }