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)); }); } finally { if (MgaGateway.territory != null) { MgaGateway.territory.Destroy(); } MgaGateway = null; project = null; currentobj = null; selectedobjs = null; GMEConsole = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }
public void MainInTransaction(InterpreterMainParameters parameters) { this.mainParameters = (InterpreterMainParameters)parameters; if (GMEConsole == null) { GMEConsole = GMEConsole.CreateFromProject(mainParameters.Project); } var currentObject = mainParameters.CurrentFCO; var currentOutputDirectory = mainParameters.OutputDirectory; string artifactName = string.Empty; string metaBaseName = currentObject.MetaBase.Name; if (metaBaseName == typeof(CyPhyClasses.DesignContainer).Name) { artifactName = ExportToFile(CyPhyClasses.DesignContainer.Cast(currentObject), currentOutputDirectory); } else if (metaBaseName == typeof(CyPhyClasses.ComponentAssembly).Name) { artifactName = ExportToFile(CyPhyClasses.ComponentAssembly.Cast(currentObject), currentOutputDirectory); } else if (IsTestBenchType(metaBaseName)) { artifactName = ExportToFile(CyPhyClasses.TestBenchType.Cast(currentObject), currentOutputDirectory); } if (!string.IsNullOrWhiteSpace(artifactName)) { var manifest = AVM.DDP.MetaTBManifest.OpenForUpdate(currentOutputDirectory); manifest.AddArtifact(Path.GetFileName(artifactName), "Design Model"); manifest.Serialize(currentOutputDirectory); } }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { GMEConsole = GMEConsole.CreateFromProject(project); MgaGateway = new MgaGateway(project); MgaGateway.BeginTransaction(transactiontype_enum.TRANSACTION_NON_NESTED); try { Main(project, currentobj, selectedobjs, Convert(param)); } finally { MgaGateway.AbortTransaction(); } } 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) { GMEConsole = GMEConsole.CreateFromProject(project); GMEConsole.Out.WriteLine("Running the AddConnector interpreter..."); Boolean ownLogger = false; if (Logger == null) { ownLogger = true; Logger = new CyPhyGUIs.GMELogger(project, "AddConnector"); } GMEConsole.Out.WriteLine("\n======================================================================================================================================\n"); using (Logger) // Ensure Logger is disposed if there is an unexpected exception. MOT-84 { Logger.WriteInfo("Starting AddConnector."); AddConnector(currentobj, selectedobjs); Logger.WriteInfo("The AddConnector interpreter has finished."); } if (ownLogger) { Logger.Dispose(); Logger = null; } }
public void CallCyPhy2CADWithTransaction(MgaProject project, MgaFCO toplevelAssembly, int param) { if (GMEConsole == null) { GMEConsole = GMEConsole.CreateFromProject(project); } Dictionary <MgaFCO, MgaFCO> objectMap = new Dictionary <MgaFCO, MgaFCO>(); try { project.BeginTransactionInNewTerr(transactiontype_enum.TRANSACTION_NON_NESTED); handleEvents = false; GenerateCADAssemblyXml(project, toplevelAssembly, param); try { HighlightInTree(toplevelAssembly, 1); } catch (Exception e) { GMEConsole.Error.Write("Error during processing the model: " + e.Message); // Don't do anything, there won't be highlight } } finally { project.AbortTransaction(); handleEvents = true; } }
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param) { if (!enabled) { return; } try { MgaGateway = new MgaGateway(project); MgaGateway.PerformInTransaction(delegate { Main(project, currentobj, selectedobjs, Convert(param)); }, abort: 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 { GMEConsole = GMEConsole.CreateFromProject(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(); } }
/// <summary> /// This function is called for each interpreter invocation before Main. /// Don't perform MGA operations here unless you open a tansaction. /// </summary> /// <param name="project">The handle of the project opened in GME, for which the interpreter was called.</param> public void Initialize(MgaProject project) { // TODO: Add your initialization code here... Contract.Requires(project != null); GMEConsole = GMEConsole.CreateFromProject(project); MgaGateway = new MgaGateway(project); }
private bool getGMEConsole() { if (GMEConsole == null || GMEConsole.gme == null) { GMEConsole = GMEConsole.CreateFromProject(this.project); } return(GMEConsole != null && GMEConsole.gme != null); }
public FCOChooser(MgaGateway gateway, GMEConsole console) { this.MgaGateway = gateway; this.GMEConsole = console; InitializeComponent(); this.choose1.Click += new EventHandler(choose_Click); this.choose2.Click += new EventHandler(choose_Click); this.link.Click += new EventHandler(link_Click); }
/// <summary> /// Called when an FCO or folder changes /// </summary> /// <param name="subject">the object the event(s) happened to</param> /// <param name="eventMask">objectevent_enum values ORed together</param> /// <param name="param">extra information provided for cetertain event types</param> public void ObjectEvent(MgaObject subject, uint eventMask, object param) { // TODO: Handle object events (OR eventMask with the members of objectevent_enum) // Warning: Only those events are received that you have subscribed for by setting ComponentConfig.eventMask if (GMEConsole == null) { GMEConsole = GMEConsole.CreateFromProject(project); } TriggerQudtRefreshIfNeeded(); }
public Switcher(IMgaObject fco1Object, IMgaObject fco2Object, GMEConsole GMEConsole) { this.lib1Objects = new List <IMgaObject>() { fco1Object }; this.lib2Objects = new List <IMgaObject>() { fco2Object }; this.GMEConsole = GMEConsole; }
private void ConnectionClosed(Exception e) { SyncControl.BeginInvoke((System.Action) delegate { if (addon != null) { GMEConsole console = GMEConsole.CreateFromProject(addon.Project); console.Error.WriteLine("Connection to MetaLink lost."); //componentEditMessages.Clear(); interests.Clear(); AssemblyID = null; CloseMetaLinkBridge(); if (console.gme != null) { // Marshal.FinalReleaseComObject(console.gme); is this needed? } Enable(false); if (syncedComponents.Count > 0) { bool inTx = ((addon.Project.ProjectStatus & 8) != 0); if (inTx == false) { addon.Project.BeginTransactionInNewTerr(); } try { foreach (string id in syncedComponents.Keys) { ISIS.GME.Common.Interfaces.Base model = CyphyMetaLinkUtils.GetComponentAssemblyByGuid(addon.Project, id); if (model == null) { model = CyphyMetaLinkUtils.GetComponentByAvmId(addon.Project, id); } if (model != null) { HighlightInTree(model, 0); } } } finally { if (inTx == false) { addon.Project.AbortTransaction(); } } syncedComponents.Clear(); designIdToCadAssemblyXml.Clear(); } } }); }
void DragNDropHandler(string filename) { Tuple <Type, MethodInfo> method; if (dictofCATDnDMethods.TryGetValue(Path.GetExtension(filename), out method)) { CATModule newinst = CreateCATModuleLogged(method.Item1); method.Item2.Invoke(newinst, new object[] { filename }); GMEConsole console = GMEConsole.CreateFromProject(this.StashProject); console.Info.WriteLine("Processed " + filename); Marshal.ReleaseComObject(console.gme); } }
public static string ExportToFile(CyPhy.Component c, String s_outFilePath) { try { avm.Component avmComponent = CyPhy2ComponentModel.Convert.CyPhyML2AVMComponent(c); SerializeAvmComponent(avmComponent, s_outFilePath); return(s_outFilePath); } catch (Exception ex) { var console = GMEConsole.CreateFromProject(c.Impl.Project); console.Error.WriteLine("Exception Parsing {0}: {1}", Safeify(c.Name), ex.Message); return(null); } }
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(); } }
public static String ExportToFile(CyPhy.Component c, String s_outFolder) { try { avm.Component avmComponent = CyPhy2ComponentModel.Convert.CyPhyML2AVMComponent(c); String s_outFilePath = String.Format("{0}\\{1}.component.acm", s_outFolder, System.IO.Path.GetRandomFileName()); SerializeAvmComponent(avmComponent, s_outFilePath); return(s_outFilePath); } catch (Exception ex) { var console = GMEConsole.CreateFromProject(c.Impl.Project); console.Error.WriteLine("Exception Parsing {0}: {1}", Safeify(c.Name), ex.Message); return(null); } }
// Event handlers for addons #region MgaEventSink members public void GlobalEvent(globalevent_enum @event) { if (@event == globalevent_enum.GLOBALEVENT_CLOSE_PROJECT) { if (GMEConsole != null) { if (GMEConsole.gme != null) { Marshal.FinalReleaseComObject(GMEConsole.gme); } GMEConsole = null; } addon.Destroy(); Marshal.FinalReleaseComObject(addon); addon = null; } if (@event == globalevent_enum.APPEVENT_XML_IMPORT_BEGIN) { handleEvents = false; addon.EventMask = 0; } else if (@event == globalevent_enum.APPEVENT_XML_IMPORT_END) { unchecked { addon.EventMask = (uint)ComponentConfig.eventMask; } handleEvents = true; } else if (@event == globalevent_enum.APPEVENT_LIB_ATTACH_BEGIN) { addon.EventMask = 0; handleEvents = false; } else if (@event == globalevent_enum.APPEVENT_LIB_ATTACH_END) { unchecked { addon.EventMask = (uint)ComponentConfig.eventMask; } handleEvents = true; } if (!componentEnabled) { return; } // TODO: Handle global events // MessageBox.Show(@event.ToString()); }
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 FlexConsole(ConsoleType consoleType, MgaProject mgaProject = null) { switch (consoleType) { case ConsoleType.NONE: _info = _warning = _error = _out = new NullTextWriter(); break; case ConsoleType.CONSOLE: _info = _warning = _error = Console.Error; _out = Console.Out; break; case ConsoleType.GMECONSOLE: _gmeConsole = GMEConsole.CreateFromProject(mgaProject); _info = _gmeConsole.Info; _warning = _gmeConsole.Warning; _error = _gmeConsole.Error; _out = _gmeConsole.Out; break; } }
public myMigrator(MgaProject p) { project = p; GMEConsole = GMEConsole.CreateFromProject(p); oldToNewRole = new Dictionary <string, string>() { { "StructuralInterface", "Connector" }, { "AxisGeometry", "Axis" }, { "SurfaceGeometry", "Surface" }, { "PointGeometry", "Point" }, { "CoordinateSystemGeometry", "CoordinateSystem" }, { "StructuralInterfaceForwarder", "Connector" }, { "FeatureMap", "PortComposition" }, { "AnalysisPointMap", "PortComposition" }, { "AnalysisPoint", "Point" }, { "JoinStructures", "ConnectorComposition" }, //{"FeatureMap", "SurfaceReverseMap"}, //special, not general case //{"CADModel", ""}, //special, addition not replacement }; oldToNewFCO = new Dictionary <MgaFCO, MgaFCO>(); oldConnsAndRefs = new List <MgaFCO>(); oldSubsAndInstances = new List <MgaFCO>(); migratedModels = new List <MgaModel>(); foreach (MgaFolder child in project.RootFolder.ChildFolders) { if (child.MetaFolder.Name == "Components") { List <MgaFolder> folders = getAllFolders(child); foreach (MgaFolder folder in folders) { foreach (MgaModel model in folder.ChildObjects.OfType <MgaModel>()) { createNewFCOs(model); } } } } }
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(); } }
/// <summary> /// Called when an FCO or folder changes /// </summary> /// <param name="subject">the object the event(s) happened to</param> /// <param name="eventMask">objectevent_enum values ORed together</param> /// <param name="param">extra information provided for cetertain event types</param> public void ObjectEvent(MgaObject subject, uint eventMask, object param) { if (!componentEnabled || !handleEvents) { return; } if (GMEConsole == null) { GMEConsole = GMEConsole.CreateFromProject(subject.Project); } if ((eventMask & (uint)objectevent_enum.OBJEVENT_OPENMODEL) != 0) { openModels.Add(subject.AbsPath); #if (DEBUG) GMEConsole.Info.Write(String.Format("Opened Model: {0}", subject.AbsPath)); #endif } if ((eventMask & (uint)objectevent_enum.OBJEVENT_CLOSEMODEL) != 0) { openModels.Remove(subject.AbsPath); #if (DEBUG) GMEConsole.Info.Write(String.Format("Closed Model: {0}", subject.AbsPath)); #endif } // TODO: Handle object events (OR eventMask with the members of objectevent_enum) // Warning: Only those events are received that you have subscribed for by setting ComponentConfig.eventMask // If the event is OBJEVENT_DESTROYED, most operations on subject will fail // Safe operations: getting Project, ObjType, ID, MetaRole, Meta, MetaBase, Name, AbsPath // Operations that will fail: all others, including attribute access and graph navigation // Try handling OBJEVENT_PRE_DESTROYED if these operations are necessary // Be careful not to modify Library objects (check subject.IsLibObject) // MessageBox.Show(eventMask.ToString()); // GMEConsole.Out.WriteLine(subject.Name); }
private void TriggerQudtRefreshIfNeeded() { if (!firstTime) { // put the arguments into private variables where they can be reached by the timer code if (GMEConsole == null) { GMEConsole = GMEConsole.CreateFromProject(project); } #if DEBUG GMEConsole.Info.WriteLine("CyPhySignalBlocksAddOn starting up..."); #endif GMEConsole.Info.WriteLine(String.Format("This is OpenMETA version {0}", META.VersionInfo.MetaVersion)); //GMEConsole.Info.WriteLine(eventMask.ToString()); if (!componentEnabled) { GMEConsole.Info.WriteLine("CyPhySignalBlocksAddOn not enabled..."); return; } // First, check to see whether the libraries have already been loaded //CyPhy.RootFolder rootFolder = ISIS.GME.Common.Utils.CreateObject<CyPhyClasses.RootFolder>(rf as MgaObject); IMgaFolder rootFolder = project.RootFolder; IMgaFolders subFolders = rootFolder.ChildFolders; // META-1320: refactored some // Run this on any event, but only once (if not already loaded) QudtLibraryInfo.Go(); PortLibraryInfo.Go(); // portLibTimer.go(); MaterialLibraryInfo.Go(); CADResourceLibraryInfo.Go(); TestbenchesInfo.Go(); firstTime = true; } }
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 GMELogger(MgaProject project, string interpreterName = null) { this.m_project = project; this.GMEConsoleLoggingLevel = MessageType_enum.Success; var gme_console = GMEConsole.CreateFromProject(project); this.AddWriter(gme_console.Out); if (string.IsNullOrWhiteSpace(interpreterName) == false) { var logFilePath = Path.Combine(MgaExtensions.MgaExtensions.GetProjectDirectoryPath(project), "log"); Directory.CreateDirectory(logFilePath); string logFileName = string.Format("{0}.{1}.log", interpreterName, System.Diagnostics.Process.GetCurrentProcess().Id); this.AddWriter(Path.Combine(logFilePath, logFileName)); // TODO: would be nice to log as html file too. } }
public Checker(MgaFCO model, MgaProject project, IMgaTraceability traceability = null, CyPhyGUIs.GMELogger logger = null) { Model = model; Project = project; if (logger != null) { this.Logger = logger; } else { GMEConsole = GMEConsole.CreateFromProject(project); } registeredRules = new ConcurrentDictionary <string, List <RuleDescriptor> >(); if (traceability == null) { this.Traceability = new META.MgaTraceability(); } else { this.Traceability = traceability; } }
public Switcher(IEnumerable <IMgaObject> fco1Object, IEnumerable <IMgaObject> fco2Object, GMEConsole GMEConsole) { this.lib1Objects = fco1Object.ToList(); this.lib2Objects = fco2Object.ToList(); this.GMEConsole = GMEConsole; }
public AVMDesignImporter(GMEConsole console, IMgaProject project, object messageConsoleParameter = null) : base(CyPhyClasses.RootFolder.GetRootFolder((MgaProject)project), messageConsoleParameter) { projroot = Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length)); init(true); }
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(); } }