private String GetSorterName(NodeSorter sorter) { String displayName = OutlinerPlugins.GetPlugin(sorter.GetType()).DisplayName; if (sorter is NodePropertySorter) displayName += " (" + ((NodePropertySorter)sorter).Property + ")"; return displayName; }
public void Sort() { NodeSorter Sorter = new NodeSorter(); SortedList <Node, Node> list = new SortedList <Node, Node>(m_nodes.Count, Sorter); foreach (Node node in m_nodes) { list.Add(node, node); } m_nodes = new List <Node>(list.Values); }
private RecordDeclarationSyntax SortRecordNode(RecordDeclarationSyntax recordDeclaration) { var membersOfRecord = recordDeclaration.Members.ToList(); var nodeData = membersOfRecord.ToDictionary(x => x, x => new CSharpSyntaxNodeData(x)); IComparer <MemberDeclarationSyntax> comparer = new NodeSorter(nodeData, sortingConfiguration); membersOfRecord.Sort(comparer); RecordDeclarationSyntax recordDeclarationNodeWithoutNodes = recordDeclaration.RemoveNodes(membersOfRecord, SyntaxRemoveOptions.KeepNoTrivia); RecordDeclarationSyntax finalRecordDeclarationNode = recordDeclarationNodeWithoutNodes.WithMembers(new SyntaxList <MemberDeclarationSyntax>(membersOfRecord)); return(finalRecordDeclarationNode); }
private void AddSorterToTree(NodeSorter sorter, Tree.TreeNodeCollection parentCollection) { if (sorter == null) return; Tree.TreeNode tn = new Tree.TreeNode(this.GetSorterName(sorter)); tn.Tag = sorter; tn.IsExpanded = true; this.treeNodes.Add(sorter, tn); parentCollection.Add(tn); this.AddSorterToTree(sorter.SecondarySorter, parentCollection); }
private InterfaceDeclarationSyntax SortInterfaceNode(InterfaceDeclarationSyntax interfaceDeclaration) { var membersOfInterface = interfaceDeclaration.Members.ToList(); var nodeData = membersOfInterface.ToDictionary(x => x, x => new CSharpSyntaxNodeData(x)); IComparer <MemberDeclarationSyntax> comparer = new NodeSorter(nodeData, sortingConfiguration); membersOfInterface.Sort(comparer); InterfaceDeclarationSyntax interfaceDeclarationNodeWithoutNodes = interfaceDeclaration.RemoveNodes(membersOfInterface, SyntaxRemoveOptions.KeepNoTrivia); InterfaceDeclarationSyntax finalInterfaceDeclarationNode = interfaceDeclarationNodeWithoutNodes.WithMembers(new SyntaxList <MemberDeclarationSyntax>(membersOfInterface)); return(finalInterfaceDeclarationNode); }
private ClassDeclarationSyntax SortClassNode(ClassDeclarationSyntax classDeclaration) { var membersOfClass = classDeclaration.Members.ToList(); var nodeData = membersOfClass.ToDictionary(x => x, x => new CSharpSyntaxNodeData(x)); IComparer <MemberDeclarationSyntax> comparer = new NodeSorter(nodeData, sortingConfiguration); membersOfClass.Sort(comparer); ClassDeclarationSyntax classDeclarationNodeWithoutNodes = classDeclaration.RemoveNodes(membersOfClass, SyntaxRemoveOptions.KeepNoTrivia); ClassDeclarationSyntax finalClassDeclarationNode = classDeclarationNodeWithoutNodes.WithMembers(new SyntaxList <MemberDeclarationSyntax>(membersOfClass)); return(finalClassDeclarationNode); }
private StructDeclarationSyntax SortStructNode(StructDeclarationSyntax structDeclaration) { var membersOfStruct = structDeclaration.Members.ToList(); var nodeData = membersOfStruct.ToDictionary(x => x, x => new CSharpSyntaxNodeData(x)); IComparer <MemberDeclarationSyntax> comparer = new NodeSorter(nodeData, sortingConfiguration); membersOfStruct.Sort(comparer); StructDeclarationSyntax structDeclarationNodeWithoutNodes = structDeclaration.RemoveNodes(membersOfStruct, SyntaxRemoveOptions.KeepNoTrivia); StructDeclarationSyntax finalStructDeclarationNode = structDeclarationNodeWithoutNodes.WithMembers(new SyntaxList <MemberDeclarationSyntax>(membersOfStruct)); return(finalStructDeclarationNode); }
int[] graphDistances(int[][] g, int s) { int[] distances = new int[g.GetLength(0)]; for (int i = 0; i < distances.Length; i++) { distances[i] = int.MaxValue; } distances[s] = 0; var unvistedNodes = new List <int>() { s }; if (s > 0) { unvistedNodes = unvistedNodes.Concat(Enumerable.Range(0, s)).ToList(); } if (distances.Length - 1 - s > 0) { unvistedNodes = unvistedNodes.Concat(Enumerable.Range(s + 1, distances.Length - 1 - s)).ToList(); } var sorter = new NodeSorter(distances); while (unvistedNodes.Count > 0) { int currentNode = unvistedNodes[0]; unvistedNodes.RemoveAt(0); foreach (var connectedNode in ConnectedNodes(currentNode, g)) { int dst = distances[currentNode] + g[currentNode][connectedNode]; if (dst < distances[connectedNode]) { distances[connectedNode] = dst; } } unvistedNodes.Sort(sorter); } return(distances); }
internal void CompendiumMapDepthMap_KeyDown(object sender, KeyEventArgs e) { // TODO: This needs to be done better. if (e.OriginalSource is TextBox) { return; } INodeTypeProxy nodeType = null; if (e.Key == Key.I || e.Key == Key.A || e.Key == Key.P || e.Key == Key.D1 || e.Key == Key.NumPad1) { // I, A, P, ! or 1 nodeType = _typeManager.GetNodeType("CompendiumIdeaNode"); } else if (e.PlatformKeyCode == 187 || e.Key == Key.Add && Keyboard.Modifiers != ModifierKeys.Control) { // + or = nodeType = _typeManager.GetNodeType("CompendiumProNode"); } else if (e.PlatformKeyCode == 189 || e.Key == Key.Subtract && Keyboard.Modifiers != ModifierKeys.Control) { // - nodeType = _typeManager.GetNodeType("CompendiumConNode"); } else if (e.Key == Key.Q || e.Key == Key.Divide || e.PlatformKeyCode == 191) { // Q, ? or / nodeType = _typeManager.GetNodeType("CompendiumQuestionNode"); } else if (e.Key == Key.M) { // M nodeType = _typeManager.GetNodeType("CompendiumMapNode"); } else if (e.Key == Key.D) { // D nodeType = _typeManager.GetNodeType("CompendiumDecisionNode"); } else if (e.Key == Key.Delete) { Navigator.DeleteNodes(SelectedNodes); Navigator.DeleteRelationships(SelectedRelationships); } else if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.Enter) { if (SelectedNodes.Length == 1) { NPDHelper.ShowNodePropertiesDialog(SelectedNodes[0]); } } else if (Keyboard.Modifiers == ModifierKeys.Shift && e.Key == Key.R) { //Ctrl+R NodeSorter.SortLeftToRight(); } else if (e.Key == Key.Down) { translateTransform.Y -= 10; } else if (e.Key == Key.Up) { translateTransform.Y += 10; } else if (e.Key == Key.Left) { translateTransform.X += 10; } else if (e.Key == Key.Right) { translateTransform.X -= 10; } else if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.Add) { Zoom(new Point(this.ActualWidth / 2, this.ActualHeight / 2), 0.2); } else if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.Subtract) { Zoom(new Point(this.ActualWidth / 2, this.ActualHeight / 2), -0.2); } else if (e.Key == Key.Back) { Navigator.GoBack(); } if (nodeType != null) { Navigator.AddNode(nodeType, "", _currentMousePosition); } }
/// <summary> /// Sorts the node in a node collection /// </summary> /// <param name="nodeCollection"></param> private void SortNodes(TreeNodeCollection nodeCollection, bool recursive) { ArrayList list = new ArrayList(nodeCollection.Count); foreach (TreeNode node in nodeCollection) { if (recursive && node.Nodes.Count > 0) { SortNodes(node.Nodes, recursive); } list.Add(node); } NodeSorter ns = new NodeSorter(); list.Sort(ns); nodeCollection.Clear(); foreach (TreeNode node in list) { nodeCollection.Add(node); } }
private NodeSorter GetParent(NodeSorter sorter) { if (sorter == null) return null; NodeSorter parent = this.sorterConfiguration.Sorter; while (parent != null && parent.SecondarySorter != sorter) { parent = parent.SecondarySorter; } if (parent == null || parent.SecondarySorter != sorter) return null; else return parent; }
private void SelectSorter(NodeSorter sorter) { Tree.TreeNode tn = null; if (this.treeNodes.TryGetValue(sorter, out tn)) { this.sortersTree.SelectNode(tn, true); this.sortersTree.OnSelectionChanged(); } }
private void MoveDown(NodeSorter sorter) { if (sorter == null || sorter.SecondarySorter == null) return; NodeSorter parent = this.GetParent(sorter); NodeSorter child = sorter.SecondarySorter; if (parent == null) { this.sorterConfiguration.Sorter = child; } else parent.SecondarySorter = child; sorter.SecondarySorter = child.SecondarySorter; child.SecondarySorter = sorter; }
private void MoveUp(NodeSorter sorter) { if (this.sorterConfiguration.Sorter == null || this.sorterConfiguration.Sorter == sorter) return; NodeSorter parent = this.GetParent(sorter); this.MoveDown(parent); }
public Vector MakeMove(Vector currentPosition, Vector targetPosition) { Vector direction = new Vector(); Point targetCell = World.Instance.Map.PointToCell(targetPosition); // Lists to hold the cells that have been checked and still should be checked List <Node> closed = new List <Node>(); List <Node> queue = new List <Node>(); Node startNode = new Node(World.Instance.Map.PointToCell(currentPosition)); if (startNode.Cell != currentCell || previousPosition == currentPosition) { currentCell = startNode.Cell; toNewCenter = true; } previousPosition = currentPosition; // Check if we are at the center of our current cell Vector targetCenter = World.Instance.Map.CellCenter(startNode.Cell); double distance = (targetCenter - currentPosition).Length(); if (toNewCenter && distance >= 2) { return(targetCenter - currentPosition); } else { toNewCenter = false; } NodeSorter nodeSorter = new NodeSorter(); startNode.Cost = 0; queue.Add(startNode); Node currentNode = startNode; // Keep looping until all nodes have been processed (simple A*) while (queue.Count > 0) { currentNode = queue[0]; queue.Remove(currentNode); // Check if this is the cell to be reached; if so: exit loop if (currentNode.Cell == targetCell) { break; } // Mark cell as visited closed.Add(currentNode); foreach (Node adjacent in AvailableNodes(currentNode.Cell)) { // See if we already visited this cell; if so: skip if (closed.IndexOf(adjacent) >= 0) { continue; } // Is the cell easier to access via this path; if so: update if (currentNode.Cost + 1 < adjacent.Cost) { adjacent.Cost = currentNode.Cost + 1; adjacent.Estimate = Math.Abs(adjacent.Cell.X - targetCell.X) + Math.Abs(adjacent.Cell.Y - targetCell.Y); adjacent.FromNode = currentNode; } if (queue.IndexOf(adjacent) == -1) { queue.Add(adjacent); } } // Sort the nodes so the best guesses are evaluated first queue.Sort(nodeSorter); } // Determine the next node by traversing the node list while (currentNode.FromNode != null && currentNode.FromNode.Cell != startNode.Cell) { currentNode = currentNode.FromNode; } // Set the target position to the center of the next cell and move towards it targetPosition = World.Instance.Map.CellCenter(currentNode.Cell); return(targetPosition - currentPosition); }