/// <summary> /// Create a new graph based on a filter. Only edges based on "GraphDependsOnEdge" of TEdge /// will be included. /// </summary> /// <typeparam name="TResult">result graph</typeparam> /// <param name="filter">filter to create new graph by</param> /// <param name="factory">factory to create new graph, if null will use reflection to create</param> /// <returns>new graph based on filter</returns> public TResult Create <TResult>(IGraphFilter <TKey> filter, Func <TResult> factory = null) where TResult : GraphMap <TKey, TNode, TEdge> { filter.Verify(nameof(filter)).IsNotNull(); factory.Verify(nameof(factory)).IsNotNull(); // Create new graph TResult newGraph = factory?.Invoke() ?? (TResult)Create(); // Get connected nodes IReadOnlyList <TNode> childrenNodes = GetLinkedNodes(filter); // Add include nodes to the list var focusedNodes = filter.IncludeNodeKeys .Join(Nodes.Values, x => x, x => x.Key, (o, i) => i, KeyCompare) .Concat(childrenNodes) .GroupBy(x => x.Key, KeyCompare) .Select(x => x.First()); // Set nodes focusedNodes.ForEach(x => newGraph.Add(x)); // Get edges for nodes var focusedEdges = Edges.Values .Where(x => newGraph.Nodes.ContainsKey(x.FromNodeKey) && newGraph.Nodes.ContainsKey(x.ToNodeKey)); focusedEdges.ForEach(x => newGraph.Add(x)); return(newGraph); }
//public void PopToFilter(IGraphFilter filter1) //{ // PopToFilter(filter1); // return; // if (filter1 == null) // { // Repository.RemoveAll<FilterStackItem>(p => p.GraphId == this.Identifier && p.FilterId != RootFilterId); // } // else // { // foreach (var item in FilterStack) // { // if (item != filter1) // { // var item1 = item; // Repository.RemoveAll<FilterStackItem>(p => p.GraphId == this.Identifier && p.FilterId == item1.Identifier); // } // } // } // // Reset the lazy filter stack // _filterStack = null; //} //TODO : Fix Bug of Jumping error, may have bug, waiting to check !! public void PopToFilter(IGraphFilter filter1) { while (CurrentFilter != filter1) { PopFilter(); } }
public void FilterPushed(IGraphFilter filter) { if (!_persistedFilterStack.Contains(filter.Identifier)) { _persistedFilterStack.Add(filter.Identifier); } }
public bool HasPosition(IGraphFilter filter, IDiagramNode node) { if (Positions.ContainsKey(filter.Identifier)) { var filterData = Positions[filter.Identifier]; if (filterData.Keys.Contains(node.Identifier)) return true; } return false; }
public bool HasPosition(IGraphFilter filter, IDiagramNode node) { if (Positions.ContainsKey(filter.Identifier)) { var filterData = Positions[filter.Identifier]; if (filterData.Keys.Contains(node.Identifier)) { return(true); } } return(false); }
public void PushFilter(IGraphFilter filter) { var filterStack = new FilterStackItem(); filterStack.GraphId = this.Identifier; filterStack.FilterId = filter.Identifier; filterStack.Index = FilterStack.Count(); Repository.Add(filterStack); // Reset the lazy filter stack _filterStack = null; }
public static IEnumerable <IGraphItem> AllGraphItems(this IGraphFilter filter) { foreach (var item in filter.FilterNodes) { yield return(item); foreach (var child in item.GraphItems) { yield return(child); } } }
public static IEnumerable <IDiagramNode> GetImportableItems(this IGraphFilter filter) { if (filter == null) { throw new ArgumentNullException("filter"); } var items = filter.FilterNodes.Select(p => p.Identifier).ToArray(); return (filter.GetAllowedDiagramItems() .Where(p => !items.Contains(p.Identifier)) .ToArray()); }
public NavigationItem CreateNavigationItem(IGraphFilter filter) { var navigationItem = new NavigationItem() { Icon = "CommandIcon", Title = filter.Name, State = DiagramViewModel.GraphData != null && DiagramViewModel.GraphData.CurrentFilter == filter ? NavigationItemState.Current : NavigationItemState.Regular, NavigationAction = x => { InvertApplication.Execute(new LambdaCommand("Back", () => { DiagramViewModel.GraphData.PopToFilter(filter); })); } }; return(navigationItem); }
public static FilterItem ShowInFilter(this IGraphFilter filter, IDiagramNode node, Vector2 position, bool collapsed = false) { var filterItem = new FilterItem() { FilterId = filter.Identifier, NodeId = node.Identifier, Position = position, Collapsed = collapsed }; filter.Repository.Add(filterItem); var filterNode = filter as IDiagramNode; if (filterNode != null) { filterNode.NodeAddedInFilter(node); } return(filterItem); }
public void PopToFilter(IGraphFilter filter1) { if (filter1 == null) { Repository.RemoveAll <FilterStackItem>(p => p.GraphId == this.Identifier && p.FilterId != RootFilterId); } else { foreach (var item in FilterStack) { if (item != filter1) { var item1 = item; Repository.RemoveAll <FilterStackItem>(p => p.GraphId == this.Identifier && p.FilterId == item1.Identifier); } } } // Reset the lazy filter stack _filterStack = null; }
/// <summary> /// Get all the connected nodes for a node(s), including all relationships nodes /// </summary> /// <param name="filter">filter to apply</param> /// <returns>list of leaf children nodes</returns> public IReadOnlyList <TNode> GetLinkedNodes(IGraphFilter <TKey> filter) { filter.Verify(nameof(filter)).IsNotNull(); filter.IncludeNodeKeys.Count.Verify(nameof(filter.IncludeNodeKeys)).Assert(x => x > 0, "must be at lease 1"); HashSet <TKey> excludeKeys = null; // If there are exclude node keys, need to get this list first to exclude if (filter.ExcludeNodeKeys?.Count > 0) { var filterKeys = filter.ExcludeNodeKeys .ToHashSet(KeyCompare); IReadOnlyList <TNode> excludeNodes = GetLinkedNodes(filterKeys, filter.IncludeLinkedNodes, null, false, true); excludeKeys = excludeNodes .Select(x => x.Key) .Concat(filter.ExcludeNodeKeys) .ToHashSet(KeyCompare); } var focusedKeys = filter.IncludeNodeKeys .ToHashSet(KeyCompare); IReadOnlyList <TNode> result = GetLinkedNodes(focusedKeys, filter.IncludeLinkedNodes, excludeKeys, true, false); if (filter.IncludeDependentNodes) { IReadOnlyList <TNode> dependentLinks = GetLinkedNodes(focusedKeys, filter.IncludeLinkedNodes, excludeKeys, false, true); result = result .Concat(dependentLinks) .GroupBy(x => x.Key, KeyCompare) .Select(x => x.First()) .ToList(); } return(result); }
public static bool IsAllowed(this IGraphFilter filter, object item, Type t) { if (filter == item) { return(true); } if (!AllowedFilterNodes.ContainsKey(filter.GetType())) { return(false); } foreach (var x in AllowedFilterNodes[filter.GetType()]) { if (t.IsAssignableFrom(x)) { return(true); } } return(false); // return InvertGraphEditor.AllowedFilterNodes[filter.GetType()].Contains(t); }
public Vector2 this[IGraphFilter filter, string node] { get { if (Positions.ContainsKey(filter.Identifier)) { var filterData = Positions[filter.Identifier]; if (filterData.Keys.Contains(node)) return filterData[node]; } return Vector2.zero; } set { if (!Positions.ContainsKey(filter.Identifier)) { Positions.Add(filter.Identifier, new FilterLocations()); } Positions[filter.Identifier][node] = value; } }
public Vector2 this[IGraphFilter filter, string node] { get { if (Positions.ContainsKey(filter.Identifier)) { var filterData = Positions[filter.Identifier]; if (filterData.Keys.Contains(node)) { return(filterData[node]); } } return(Vector2.zero); } set { if (!Positions.ContainsKey(filter.Identifier)) { Positions.Add(filter.Identifier, new FilterLocations()); } Positions[filter.Identifier][node] = value; } }
public T DoNamedNodeStep <T>(IDocumentationBuilder builder, string requiredName, IGraphFilter requiredFilter = null, Action <IDocumentationBuilder> stepContent = null) where T : GenericNode { T existing = null; if (WorkspaceService.CurrentWorkspace == null || WorkspaceService.CurrentWorkspace.CurrentGraph == null) { } else { existing = WorkspaceService.Repository.All <T>().FirstOrDefault(p => p.Name == requiredName); } builder.ShowTutorialStep(new TutorialStep(string.Format("Create a '{0}' node with the name '{1}'", InvertApplication.Container.GetNodeConfig <T>().Name, requiredName), () => { if (existing == null) { if (requiredFilter != null) { if (WorkspaceService.CurrentWorkspace.CurrentGraph.CurrentFilter != requiredFilter) { return(string.Format("Double-click on the '{0}' Node.", requiredFilter.Name)); } } return("Node not created yet"); } return(null); }) { StepContent = _ => { var nodeTypeName = typeof(T).Name.Replace("Node", ""); _.Paragraph("In this step you need to create {0}.", nodeTypeName); _.Paragraph("To create any kind of node you need to right click on an empty space on the graph. Context menu will appear. It will contain different 'Add' commands. Each 'Add' command" + "allows you to add a new node to the graph. The types of nodes you can create may be different based on the context. For example, you can create elements only inside of subsystems, and " + "you can only create views inside of elements."); if (requiredFilter != null) { if (WorkspaceService.CurrentWorkspace.CurrentGraph.CurrentFilter != requiredFilter) { _.Paragraph("First of all you need to get into {0} node.", requiredFilter.Name); _.Paragraph( "At any time you can tell where you are, by refering to filter bar, which is located under opened tabs bar. It will show your current position in the hierarchy."); _.ImageByUrl("http://i.imgur.com/bPMlmOq.png"); _.Paragraph( "There are several ways you can navigate in the graph. First of all, you may switch graphs them selves. Each graph is represented as a graph node and is a filter on it's own. " + "You can double-click the headers of certain nodes. If it is possible, such node will become a current filter. This will show the graph filtered by this node. " + "If you double-click the header of the current filter, it will bring bring you back."); _.Paragraph("If {0} node is a graph node, just open the corresponding graph and select root in the filter bar.", requiredFilter.Name); _.Paragraph("If {0} node is a regular node, locate it and double-click it's header.", requiredFilter.Name); } else { _.Paragraph("It seems like you are inside of {0}, which is correct. Now you should be able to right-click on empty space of the graph and select Add {1}.", requiredFilter.Name, nodeTypeName); _.Paragraph("Finally you need to rename newly created node. To rename your node you have to right-click on the header of the node and click rename." + "Node title will become editable. Type in \"{0}\". Click anywhere else, to finish editing", requiredName); _.ImageByUrl("http://i.imgur.com/PDUZhsU.png", "This picture shows how to rename a node"); } } if (stepContent != null) { stepContent(_); } _.Break(); _.ToggleContentByNode <T>(null); } }); return(existing); }
public void PopToFilter(IGraphFilter filter1) { }
public void FilterPoped(IGraphFilter pop) { _persistedFilterStack.Remove(pop.Identifier); }
public void FilterPushed(IGraphFilter filter) { if (!_persistedFilterStack.Contains(filter.Identifier)) _persistedFilterStack.Add(filter.Identifier); }
public void Remove(IGraphFilter currentFilter, string identifier) { Positions[currentFilter.Identifier].Remove(identifier); }
public void PushFilter(IGraphFilter filter) { }
public static IEnumerable <IDiagramNode> GetAllowedDiagramItems(this IGraphFilter filter) { return(filter.Repository.AllOf <IDiagramNode>().Where(p => filter.IsAllowed(p, p.GetType()))); }
public static void HideInFilter(this IGraphFilter filter, IDiagramNode node) { filter.Repository.RemoveAll <FilterItem>(p => p.FilterId == filter.Identifier && p.NodeId == node.Identifier); }
/// <summary> /// Create a new default graph based on a filter.Only edges based on "GraphDependsOnEdge" of TEdge /// will be included. /// </summary> /// <param name="filter"></param> /// <returns>new graph based on filter</returns> public GraphMap <TKey, TNode, TEdge> Create(IGraphFilter <TKey> filter) { return(Create(filter, Create)); }
public static bool IsItemAllowed(this IGraphFilter filter, object item, Type t) { return(true); //return uFrameEditor.AllowedFilterItems[filter.GetType()].Contains(t); }
public void PopToFilter(IGraphFilter filter1) { if (filter1 == null) { Repository.RemoveAll<FilterStackItem>(p => p.GraphId == this.Identifier && p.FilterId != RootFilterId); } else { foreach (var item in FilterStack) { if (item != filter1) { var item1 = item; Repository.RemoveAll<FilterStackItem>(p => p.GraphId == this.Identifier && p.FilterId == item1.Identifier); } } } // Reset the lazy filter stack _filterStack = null; }
public GraphBuilder(IGraphFilter graphFilter, IGraphCoster graphCoster) { _filter = graphFilter; _graphCoster = graphCoster; }