public void OnTreeConfirmSubmit(object sender, EventArgs e) { object SelectedItem = TreeLogic.GetSelectedItem(Table, Tree); TreeConfirmEventArgs E = new TreeConfirmEventArgs(SelectedItem); TreeConfirmSubmit(Caller, E); }
public string Ancestor(TreeModel tree) { string result = string.Empty; try { TreeLogic treeLogic = new TreeLogic(tree); bool err = false; string ancestor = treeLogic.GetAncestor(tree.Child1, tree.Child2, ref err); if (err) { result = ancestor; } else { result = $"El ancestro más cercado entre {tree.Child1} y {tree.Child2} es {ancestor}"; } return(result); } catch (Exception ex) { result = $"Ocurrio un error inesperado. El error generado es el siguiente: {ex.Message}"; return(result); } }
public void Execute(object parameter) { var values = (object[])parameter; var showSections = (bool)values[0]; var menueAction = (string)values[1]; if (menueAction == "menuIniNew") { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Text Files|*.txt"; if (dialog.ShowDialog() != true) { return; } FileName = dialog.FileName; } var _textFile = new StreamReader(FileName); var tree = new TreeLogic(); tree.ShowSections = showSections; string line; string matchViews; string matchPartitionsPath; char[] trim = { ' ' }; try { while ((line = _textFile.ReadLine()) != null) { line = line.TrimEnd(trim); matchViews = Regex.Match(line, "ViewsToDisplay: ?(.+)").Groups[1].Value; matchPartitionsPath = Regex.Match(line, "PartitionsFile: ?(.+)").Groups[1].Value; if (!String.IsNullOrEmpty(matchViews)) { Enum.TryParse(matchViews, out ViewEnum viewMode); vm.SelectView(viewMode); } else if (!String.IsNullOrEmpty(matchPartitionsPath)) { Task4.TextReader text = new Task4.TextReader(matchPartitionsPath); MemoryPartitionsParser mpp = new MemoryPartitionsParser(text.Text); vm.PopulatePartitionsTree(mpp.GetMemoryPartitions()); } else { string[] words = line.Split(','); tree.AddStructure(words); } } vm.PopulateTree(tree.Root); } catch { MessageBox.Show("Incorrect file format!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public static void TreeEntityMove <T>(T t, MoveTreeModel model) where T : TreeEntity, new() { TreeLogic.FixRouteAndNames(t, model); t.Save(); if (MixinDeclarations.IsDeclared(typeof(T), typeof(DisabledMixin)) && model.NewParent != null && model.NewParent.InDB(e => e.Mixin <DisabledMixin>().IsDisabled) && !t.Mixin <DisabledMixin>().IsDisabled) { t.Execute(DisableOperation.Disable); } }
public static void TreeEntitySave <T>(T t) where T : TreeEntity, new() { if (t.IsNew) { t.Route = CalculateRoute(t); if (MixinDeclarations.IsDeclared(typeof(T), typeof(DisabledMixin)) && t.ParentOrSibling != null) { t.Mixin <DisabledMixin>().IsDisabled = t.Parent() !.Mixin <DisabledMixin>().IsDisabled; } } TreeLogic.FixName(t); }
public override void OnNodeClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Button == MouseButtons.Left && e.Node != null) { Tree.SelectedNode = e.Node; Table.DataSource = TreeLogic.GetTableSource(e.Node); Table.AutoResizeColumns(); } else if (e.Button == MouseButtons.Right && e.Node != null) { Tree.SelectedNode = e.Node; RightMenu.Show(MousePosition); } }
public void GetAncestor() { #region Arrange TreeModel treeModel = new TreeModel(); List <TreeNodesModel> treeNodesModel = new List <TreeNodesModel>(); treeNodesModel.Add(new TreeNodesModel { ParentLv1 = "55", NodeLv1 = "84, 21, 62", ParentLv2 = "21", NodeLv2 = "14, 57, 95" }); treeNodesModel.Add(new TreeNodesModel { ParentLv1 = "33", NodeLv1 = "12, 28, 53", ParentLv2 = "53", NodeLv2 = "91, 38, 15" }); treeModel.Parent = 100; treeModel.Child1 = 21; treeModel.Child2 = 84; treeModel.Nodes = treeNodesModel; string resultExpected = "55"; #endregion #region Act TreeLogic treeLogic = new TreeLogic(treeModel); bool err = false; string result = treeLogic.GetAncestor(treeModel.Child1, treeModel.Child2, ref err); #endregion #region Assert Assert.AreEqual(resultExpected, result); #endregion }
public void TerrainBuild() { for (int i = 0; i < worldScript.objects.Length; i++) { int number = Random.Range(1, 8); if (number == 3) { number = Random.Range(1, 4); if (number == 1) { terrainPrefab = tree; } if (number == 2) { terrainPrefab = tree1; } if (number == 3) { terrainPrefab = tree2; } GameObject[] groundPieces = GameObject.FindGameObjectsWithTag("Ground"); Vector3 pos = groundPieces[i].transform.position; currentObject = Instantiate(terrainPrefab); currentObject.transform.SetPositionAndRotation(new Vector3(pos.x, currentObject.transform.position.y, pos.z), transform.rotation); worldScript.Xpositions[i] = currentObject.transform.position.x; worldScript.Ypositions[i] = currentObject.transform.position.y; worldScript.Zpositions[i] = currentObject.transform.position.z; worldScript.objects[i] = terrainPrefab.name; TreeLogic treeScript = currentObject.GetComponent <TreeLogic>(); treeScript.treeNumber = i; currentObject.name = "Tree" + treeScript.treeNumber; } } }
public override ContextMenuStrip LoadRightMenu() { return(TreeLogic.GetRightMenu(Imgs)); }
public static void RegisterOperations <T>(Func <T, MoveTreeModel, T>?copy) where T : TreeEntity, new() { Graph <T> .Construct.Untyped(TreeOperation.CreateRoot).Do(c => { c.Construct = (_) => new T { ParentOrSibling = null, Level = 1, IsSibling = false }; c.Register(); }); Graph <T> .ConstructFrom <T> .Untyped(TreeOperation.CreateChild).Do(c => { c.Construct = (t, _) => new T { ParentOrSibling = t.ToLite(), Level = (short)(t.Level !+1), IsSibling = false // }; c.Register(); }); Graph <T> .ConstructFrom <T> .Untyped(TreeOperation.CreateNextSibling).Do(c => { c.Construct = (t, _) => new T { ParentOrSibling = t.ToLite(), Level = t.Level, IsSibling = true // }; c.Register(); }); new Graph <T> .Execute(TreeOperation.Save) { CanBeNew = true, CanBeModified = true, Execute = (t, _) => { TreeEntitySave(t); } } .Register(); new Graph <T> .Execute(TreeOperation.Move) { Execute = (t, args) => { var model = args.GetArg <MoveTreeModel>(); TreeEntityMove(t, model); } } .Register(); if (copy != null) { Graph <T> .ConstructFrom <T> .Untyped(TreeOperation.Copy).Do(c => { c.Construct = (t, args) => { var model = args.GetArg <MoveTreeModel>(); var newRoute = GetNewPosition <T>(model, t); var descendants = t.Descendants().OrderBy(a => a.Route).ToList(); var hasDisabledMixin = MixinDeclarations.IsDeclared(typeof(T), typeof(DisabledMixin)); var isParentDisabled = hasDisabledMixin && model.NewParent != null && model.NewParent.InDB(e => e.Mixin <DisabledMixin>().IsDisabled); var list = descendants.Select(oldNode => { var newNode = copy !(oldNode, model); if (hasDisabledMixin) { newNode.Mixin <DisabledMixin>().IsDisabled = oldNode.Mixin <DisabledMixin>().IsDisabled || isParentDisabled; } newNode.ParentOrSibling = model.NewParent; newNode.Route = oldNode.Route.GetReparentedValue(t.Route, newRoute); newNode.SetFullName(newNode.Name); return(newNode); }).ToList(); list.SaveList(); foreach (T h in list) { CalculateFullName(h); h.Save(); } return(list.First()); }; }).Register(); } new Graph <T> .Delete(TreeOperation.Delete) { Delete = (f, args) => { TreeLogic.RemoveDescendants(f); } } .Register(); }