protected override LayoutData CreateConfiguredLayoutData(GraphControl graphControl, ILayoutAlgorithm layout) { var layoutData = new BusRouterData(); var graph = graphControl.Graph; var graphSelection = graphControl.Selection; var scopePartial = ScopeItem == EnumScope.Partial; var busIds = layoutData.EdgeDescriptors.Mapper; foreach (var edge in graph.Edges) { var isFixed = scopePartial && !graphSelection.IsSelected(edge.GetSourceNode()) && !graphSelection.IsSelected(edge.GetTargetNode()); var id = GetBusId(edge, BusesItem); var descriptor = new BusDescriptor(id, isFixed) { RoutingPolicy = RoutingPolicyItem }; busIds[edge] = descriptor; } HashSet <object> selectedIds; switch (ScopeItem) { case EnumScope.Subset: layoutData.AffectedEdges.Delegate = graphSelection.IsSelected; break; case EnumScope.SubsetBus: selectedIds = new HashSet <object>(graphSelection .SelectedEdges .Select(edge => busIds[edge].BusId)); layoutData.AffectedEdges.Delegate = edge => selectedIds.Contains(busIds[edge].BusId); break; case EnumScope.Partial: selectedIds = new HashSet <object>(graphSelection .SelectedNodes .SelectMany(node => graph.EdgesAt(node)) .Select(edge => busIds[edge].BusId)); layoutData.AffectedEdges.Delegate = edge => selectedIds.Contains(busIds[edge].BusId); var hideNonOrthogonalEdgesLayoutData = new GenericLayoutData(); hideNonOrthogonalEdgesLayoutData.AddItemCollection(HideNonOrthogonalEdgesStage.SelectedNodesDpKey).Source = graphSelection.SelectedNodes; return(layoutData.CombineWith(hideNonOrthogonalEdgesLayoutData)); } return(layoutData); }
protected override LayoutData CreateConfiguredLayoutData(GraphControl graphControl, ILayoutAlgorithm layout) { var layoutData = new BusRouterData(); var graph = graphControl.Graph; var graphSelection = graphControl.Selection; var scopePartial = ScopeItem == EnumScope.Partial; var busIds = layoutData.EdgeDescriptors.Mapper; foreach (var edge in graph.Edges) { var isFixed = scopePartial && !graphSelection.IsSelected(edge.GetSourceNode()) && !graphSelection.IsSelected(edge.GetTargetNode()); var id = GetBusId(edge, BusesItem); busIds[edge] = new BusDescriptor(id, isFixed); } HashSet <object> selectedIds; switch (ScopeItem) { case EnumScope.Subset: layoutData.AffectedEdges.Delegate = graphSelection.IsSelected; break; case EnumScope.SubsetBus: selectedIds = new HashSet <object>(graphSelection .SelectedEdges .Select(edge => busIds[edge].BusId)); layoutData.AffectedEdges.Delegate = edge => selectedIds.Contains(busIds[edge].BusId); break; case EnumScope.Partial: selectedIds = new HashSet <object>(graphSelection .SelectedNodes .SelectMany(node => graph.EdgesAt(node)) .Select(edge => busIds[edge].BusId)); layoutData.AffectedEdges.Delegate = edge => selectedIds.Contains(busIds[edge].BusId); return(new CompositeLayoutData { Items = { layoutData, new HideNonOrthogonalEdgesLayoutData { SelectedNodes = { Source = graphSelection.SelectedNodes } } } }); } return(layoutData); }
protected override async Task StartWithIGraph(IGraph graph, ILookup newContext) { OptionGroup layoutGroup = Handler.GetGroupByName(GROUP_LAYOUT); string busDetermination = (string)layoutGroup[BUSES].Value; ISelectionModel <IModelItem> selectionModel = newContext.Lookup <ISelectionModel <IModelItem> >(); var mapperRegistry = graph.MapperRegistry; var originalBusIds = mapperRegistry.GetMapper(BusRouter.EdgeDescriptorDpKey); IMapper <IEdge, BusDescriptor> busIds; if (busDetermination != CUSTOM) { mapperRegistry.RemoveMapper(BusRouter.EdgeDescriptorDpKey); busIds = mapperRegistry.CreateMapper <IEdge, BusDescriptor>(BusRouter.EdgeDescriptorDpKey); var scopePartial = (string)layoutGroup[SCOPE].Value == PARTIAL; foreach (var edge in graph.Edges) { bool isFixed = scopePartial && !IsSelected(selectionModel, edge.GetSourceNode()) && !IsSelected(selectionModel, edge.GetTargetNode()); busIds[edge] = new BusDescriptor(GetBusId(edge, busDetermination), isFixed); } } else { busIds = originalBusIds ?? mapperRegistry.CreateConstantMapper(BusRouter.EdgeDescriptorDpKey, new BusDescriptor(SingleBusId)); } var originalEdgeSubsetMapper = mapperRegistry.GetMapper(BusRouter.DefaultAffectedEdgesDpKey); if (originalEdgeSubsetMapper != null) { mapperRegistry.RemoveMapper(BusRouter.DefaultAffectedEdgesDpKey); } var selectedIds = new System.Collections.Generic.HashSet <object>(); switch ((string)layoutGroup[SCOPE].Value) { case SUBSET: mapperRegistry.CreateDelegateMapper(BusRouter.DefaultAffectedEdgesDpKey, e => IsSelected(selectionModel, e)); break; case SUBSET_BUS: foreach (var edge in graph.Edges.Where(edge => IsSelected(selectionModel, edge))) { selectedIds.Add(busIds[edge].BusId); } mapperRegistry.CreateDelegateMapper(BusRouter.DefaultAffectedEdgesDpKey, e => selectedIds.Contains(busIds[e].BusId)); break; case PARTIAL: foreach (var edge in graph.Nodes.Where(node => IsSelected(selectionModel, node)).SelectMany((node) => graph.EdgesAt(node))) { selectedIds.Add(busIds[edge].BusId); } mapperRegistry.CreateDelegateMapper(BusRouter.DefaultAffectedEdgesDpKey, e => selectedIds.Contains(busIds[e].BusId)); break; } try { await base.StartWithIGraph(graph, newContext); } finally { mapperRegistry.RemoveMapper(BusRouter.EdgeDescriptorDpKey); if (originalBusIds != null) { mapperRegistry.AddMapper(BusRouter.EdgeDescriptorDpKey, originalBusIds); } mapperRegistry.RemoveMapper(BusRouter.DefaultAffectedEdgesDpKey); if (originalEdgeSubsetMapper != null) { mapperRegistry.AddMapper(BusRouter.DefaultAffectedEdgesDpKey, originalEdgeSubsetMapper); } } }
protected override LayoutData CreateConfiguredLayoutData(GraphControl graphControl, ILayoutAlgorithm layout) { var layoutData = new HierarchicLayoutData(); var incrementalLayout = SelectedElementsIncrementallyItem; var selection = graphControl.Selection; var selectedElements = selection.SelectedEdges.Any() || selection.SelectedNodes.Any(); if (incrementalLayout && selectedElements) { // configure the mode var ihf = ((HierarchicLayout)layout).CreateIncrementalHintsFactory(); layoutData.IncrementalHints.Delegate = item => { // Return the correct hint type for each model item that appears in one of these sets if (item is INode && selection.IsSelected(item)) { return(ihf.CreateLayerIncrementallyHint(item)); } if (item is IEdge && selection.IsSelected(item)) { return(ihf.CreateSequenceIncrementallyHint(item)); } return(null); }; } if (RankingPolicyItem == LayeringStrategy.Bfs) { layoutData.BfsLayererCoreNodes.Delegate = selection.IsSelected; } if (GridEnabledItem) { var nld = ((HierarchicLayout)layout).NodeLayoutDescriptor; layoutData.NodeLayoutDescriptors.Delegate = node => { var descriptor = new NodeLayoutDescriptor(); descriptor.LayerAlignment = nld.LayerAlignment; descriptor.MinimumDistance = nld.MinimumDistance; descriptor.MinimumLayerHeight = nld.MinimumLayerHeight; descriptor.NodeLabelMode = nld.NodeLabelMode; // anchor nodes on grid according to their alignment within the layer descriptor.GridReference = new YPoint(0.0, (nld.LayerAlignment - 0.5) * node.Layout.Height); descriptor.PortAssignment = this.GridPortAssignmentItem; return(descriptor); }; } if (EdgeDirectednessItem) { layoutData.EdgeDirectedness.Delegate = edge => { if (edge.Style is IArrowOwner && !Equals(((IArrowOwner)edge.Style).TargetArrow, Arrows.None)) { return(1); } return(0); }; } if (EdgeThicknessItem) { layoutData.EdgeThickness.Delegate = edge => { var style = edge.Style as PolylineEdgeStyle; if (style != null) { return(style.Pen.Thickness); } return(1); }; } if (SubComponentsItem) { // layout all siblings with label 'TL' separately with tree layout var treeLayout = new TreeLayout { DefaultNodePlacer = new LeftRightNodePlacer() }; foreach (var listOfNodes in FindSubComponents(graphControl.Graph, "TL")) { layoutData.SubComponents.Add(treeLayout).Items = listOfNodes; } // layout all siblings with label 'HL' separately with hierarchical layout var hierarchicLayout = new HierarchicLayout { LayoutOrientation = LayoutOrientation.LeftToRight }; foreach (var listOfNodes in FindSubComponents(graphControl.Graph, "HL")) { layoutData.SubComponents.Add(hierarchicLayout).Items = listOfNodes; } // layout all siblings with label 'OL' separately with organic layout var organicLayout = new OrganicLayout { PreferredEdgeLength = 100, Deterministic = true }; foreach (var listOfNodes in FindSubComponents(graphControl.Graph, "OL")) { layoutData.SubComponents.Add(organicLayout).Items = listOfNodes; } } if (HighlightCriticalPath) { // highlight the longest path in the graph as critical path // since the longest path algorithm only works for acyclic graphs, // feedback edges and self loops have to be excluded here var feedbackEdgeSetResult = new FeedbackEdgeSet().Run(graphControl.Graph); var longestPath = new LongestPath { SubgraphEdges = { Excludes = { Delegate = edge => feedbackEdgeSetResult.FeedbackEdgeSet.Contains(edge) || edge.IsSelfloop() } } }.Run(graphControl.Graph); if (longestPath.Edges.Any()) { layoutData.CriticalEdgePriorities.Delegate = edge => { if (longestPath.Edges.Contains(edge)) { return(10); } return(1); }; } } if (AutomaticBusRouting) { var allBusNodes = new HashSet <INode>(); foreach (var node in graphControl.Graph.Nodes) { if (!graphControl.Graph.IsGroupNode(node) && !allBusNodes.Contains(node)) { // search for good opportunities for bus structures rooted at this node if (graphControl.Graph.InDegree(node) >= 4) { var busDescriptor = new BusDescriptor(); var busEdges = GetBusEdges(graphControl.Graph, node, allBusNodes, graphControl.Graph.InEdgesAt(node)); if (busEdges.Any()) { layoutData.Buses.Add(busDescriptor).Items = busEdges; } } if (graphControl.Graph.OutDegree(node) >= 4) { var busDescriptor = new BusDescriptor(); var busEdges = GetBusEdges(graphControl.Graph, node, allBusNodes, graphControl.Graph.OutEdgesAt(node)); if (busEdges.Any()) { layoutData.Buses.Add(busDescriptor).Items = busEdges; } } } } } return(layoutData.CombineWith( CreateLabelingLayoutData( graphControl.Graph, LabelPlacementAlongEdgeItem, LabelPlacementSideOfEdgeItem, LabelPlacementOrientationItem, LabelPlacementDistanceItem ) )); }