/// <summary> /// Creates graph from MEOop, or returns it from cache if already there /// </summary> /// <param name="m">The MEOop object</param> /// <returns>Graph object</returns> public static Graph MEOopToGraph(MetaEditAPI.MEOop m) { Hashtable graphTable = (Hashtable)ProjectTable[m.areaID]; Graph graph = null; if (graphTable == null) { graphTable = new Hashtable(); ProjectTable.Add(m.areaID, graphTable); } graph = (Graph)graphTable[m.objectID]; MetaEditAPI.MetaEditAPI port = Launcher.Port; if (graph == null) { MetaEditAPI.METype _graphType = port.type(m); string _typeName = (string)TypeNameTable[_graphType.name]; if (_typeName == null) { _typeName = port.typeName(_graphType); TypeNameTable.Add(_graphType.name, _typeName); } graph = new Graph(port.userPrintString(m), _graphType.name, _typeName, m.areaID, m.objectID); graphTable.Add(m.objectID, graph); } return(graph); }
///<summary> /// Runs generator for caller Graph. After calling ME+ to run generator, tries /// to import project with same name as the graph to workspace. ///</summary> ///<param name="generator">generator name of the generator to be run.</param> public void ExecuteGenerator(string generator) { this.WritePluginIniFile(); MetaEditAPI.MetaEditAPI port = Launcher.Port; // Run generator bool RunSuccess = this.RunGenerator(port, generator); // true if successful or unknown this.ReadAndRemoveIniFile(Settings.GetSettings().WorkingDir); if (RunSuccess) { this.ImportProject(); } }
private void ButtonOpen_Click(object sender, RoutedEventArgs e) { try { if (treeView1.SelectedItem == null) { return; } GraphViewModel gvm = (GraphViewModel)treeView1.SelectedItem; MetaEditAPI.MetaEditAPI port = Launcher.Port; MEAPI.AllowSetForegroundWindow(); port.open(gvm.getGraph().ToMEOop()); } catch (Exception err) { DialogProvider.ShowMessageDialog("API error: " + err.Message, "API error"); this.correctErrorSituation(); } }
/// <summary> /// Init graphs children recursively calling method for every children. Except /// those that are already initialized. /// </summary> public void InitChildren(MetaEditAPI.MetaEditAPI port, List <Graph> done) { if (done.Contains(this)) { return; } done.Add(this); MetaEditAPI.MEOop[] subgraphOops = null; subgraphOops = port.subgraphs(this.ToMEOop()); // Set the subgraph items to be children of this graph. if (subgraphOops.Length > 0 && subgraphOops != null) { Graph [] graphs = new Graph[subgraphOops.Length]; for (int i = 0; i < subgraphOops.Length; i++) { Graph g = graphs[i] = MEOopToGraph(subgraphOops[i]); g.SetIsChild(true); g.InitChildren(port, done); } this.SetChildren(graphs); } }
/// <summary> /// Runs the named generator /// </summary> /// <param name="port">Connection to MetaEdit+ API server.</param> /// <param name="generator">Name of the generator</param> /// <returns>Was the generation successful (unknown=true, e.g. for 4.5)</returns> public bool RunGenerator(MetaEditAPI.MetaEditAPI port, String generator) { bool success = true; MEAPI.AllowSetForegroundWindow(); try { if (Settings.GetSettings().Version.IsEqualOrGreaterThan("5.0")) { success = port.forGraphRun(this.ToMEOop(), generator); } else { MetaEditAPI.MENull meNull = new MetaEditAPI.MENull(); port.forName(meNull, this.Name, this.TypeName, generator); } } catch (Exception e) { DialogProvider.ShowMessageDialog("API error: " + e.Message, "API error"); success = false; } return(success); }