public void SetGrid(Interop.Grid grid) { GridItemViewModel vm = CreateGridViewModel(grid); _Grid.Clear(); _Grid.Add(vm); }
private GridItemViewModel CreateGridViewModel(Interop.Grid grid) { GridItemViewModel root = new GridItemViewModel( new GridItem() { Name = grid.Name, Type = GridItemType.Root }, grid.Definitions, grid.Path ); foreach (KeyValuePair <string, List <Interop.TerminalBlock> > pair in grid.Blocks) { GridItemViewModel node = new GridItemViewModel( new GridItem() { Name = pair.Key, Type = GridItemType.Group }, root ); foreach (Interop.TerminalBlock block in pair.Value) { if (block.IsProgram) { node.AddChild( new GridItemViewModel( new GridItem() { Name = block.Name, EntityID = block.EntityID, Type = GridItemType.Program, Program = block.Program }, node ) ); } else { node.AddChild( new GridItemViewModel( new GridItem() { Name = block.Name, EntityID = block.EntityID, Type = GridItemType.Block }, node ) ); } } root.AddChild(node); } return(root); }
public ProjectItemViewModel AddChild(ProjectItem item, Interop.Grid grid) { ProjectItemViewModel vm = new ProjectItemViewModel(item, this); if (grid != null) { vm.Grid.Add(CreateGridViewModel(grid)); } _Children.Add(vm); Model.Children.Add(item); return(vm); }
public static void Import(string filename, out string name, out Interop.Grid grid) { name = string.Empty; grid = null; MyObjectBuilder_Definitions loaded = null; if (File.Exists(filename)) { using (FileStream stream = File.Open(filename, FileMode.Open)) { MyObjectBuilderSerializer.DeserializeXML <MyObjectBuilder_Definitions>(stream, out loaded); } } if (loaded != null) { foreach (MyObjectBuilder_ShipBlueprintDefinition blueprints in loaded.ShipBlueprints) { name = blueprints.Id.SubtypeId; grid = new Grid(loaded) { Name = name, Path = filename, }; foreach (MyObjectBuilder_CubeGrid cubegrid in blueprints.CubeGrids) { foreach (MyObjectBuilder_CubeBlock block in cubegrid.CubeBlocks) { if (block is MyObjectBuilder_TerminalBlock) { MyObjectBuilder_TerminalBlock terminalblock = (MyObjectBuilder_TerminalBlock)block; long entityid = terminalblock.EntityId; string type = GetBlockType(terminalblock.TypeId.ToString()); // TODO Use MyTexts.GetString(MyStringId id) to get default blocks names from MyTexts.resx (for localization) string customname = String.IsNullOrEmpty(terminalblock.CustomName) ? type : terminalblock.CustomName; if (block is MyObjectBuilder_MyProgrammableBlock) { MyObjectBuilder_MyProgrammableBlock prog = (MyObjectBuilder_MyProgrammableBlock)block; grid.AddBlock(type, new TerminalBlock() { Name = customname, EntityID = entityid, IsProgram = true, Program = prog.Program }); } else { grid.AddBlock(type, new TerminalBlock() { Name = customname, EntityID = entityid, IsProgram = false }); } } } } } } }