Example #1
0
        private void CreatePlacementNode(AbstractNode nextNode, int row, int column)
        {
            var placementNode = new PlacementNode(nextNode.Task, new Position(column, row));

            _graph.Nodes.Add(placementNode);
            _placedTasks.Add(nextNode.Task);
        }
 private static bool IsEmpty(PlacementNode node)
 {
     return(string.IsNullOrEmpty(node.Location) &&
            string.IsNullOrEmpty(node.ShapeType) &&
            (node.Alternates == null || node.Alternates.Length == 0) &&
            (node.Wrappers == null || node.Wrappers.Length == 0));
 }
Example #3
0
		public void ReParent(PlacementNode parent)
		{
			int newDepth = parent.Depth + 1;
			if (this.Depth < newDepth)
			{
				this.Depth = newDepth;
				RefreshDepth(newDepth);
			}
		}
Example #4
0
        private RenderNode CreateNode(PlacementNode node)
        {
            var position = RenderPosition(node);
            var elements = _layoutBuilder.Build(position, _config);

            return(new RenderNode(
                       task: node.Task,
                       position: position,
                       dimensions: _config.Dimensions,
                       elements: elements.ToList()
                       ));
        }
Example #5
0
		public PlacementNode(HamTimelineNode node, PlacementNode parent)
		{
			this.Node = node;
			this.Parent = parent;
			if (this.Parent != null)
			{
				this.Parent.Children.Add(this);
				this.Depth = this.Parent.Depth + 1;
			}
			else
			{
				this.Depth = 0;
			}
			this.Children = new List<PlacementNode>();
			this.Width = 0;
			this.WidthOffset = 0;
		}
        public async Task <IActionResult> Create(string suggestion, string returnUrl = null)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManagePlacements))
            {
                return(Forbid());
            }

            var template = new PlacementNode[] { new PlacementNode() };

            var viewModel = new EditShapePlacementViewModel
            {
                Creating  = true,
                ShapeType = suggestion,
                Nodes     = JsonConvert.SerializeObject(template, Formatting.Indented)
            };

            ViewData["ReturnUrl"] = returnUrl;
            return(View("Edit", viewModel));
        }
        public async Task <IActionResult> Edit(string shapeType, string displayType = null, string contentType = null, string contentPart = null, string differentiator = null, string returnUrl = null)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManagePlacements))
            {
                return(Forbid());
            }

            var placementNodes = (await _placementsManager.GetShapePlacementsAsync(shapeType))?.ToList() ?? new List <PlacementNode>();

            if (!placementNodes.Any() || ShouldCreateNode(placementNodes, displayType, contentType, contentPart, differentiator))
            {
                var generatedNode = new PlacementNode
                {
                    DisplayType    = displayType,
                    Differentiator = differentiator
                };
                if (!string.IsNullOrEmpty(contentType))
                {
                    generatedNode.Filters.Add("contentType", new JArray(contentType));
                }
                if (!string.IsNullOrEmpty(contentPart))
                {
                    generatedNode.Filters.Add("contentPart", new JArray(contentPart));
                }

                placementNodes.Add(generatedNode);
            }

            var viewModel = new EditShapePlacementViewModel
            {
                ShapeType = shapeType,
                Nodes     = JsonConvert.SerializeObject(placementNodes, Formatting.Indented)
            };

            ViewData["ReturnUrl"] = returnUrl;
            return(View(viewModel));
        }
Example #8
0
	public void GetNodePlacement(out Dictionary<int,Vector2> places)
	{
		places = new Dictionary<int,Vector2>();

		HashSet<int> visited = new HashSet<int>();
		Dictionary<int, PlacementNode> allNodes = new Dictionary<int, PlacementNode>();

		// Iterate through tree, one row of depth at a time, developing a parentage relationship as we go
		// The goal here is to find 0 or 1 unique parent for each node to determine its final position in the tree
		// There will still be odd linkages, but we'll ignore those in favor of generally looking good
		PlacementNode root = new PlacementNode(this.timeline.OriginNode, null);
		allNodes[root.Node.ID] = root;

		Queue<PlacementNode> unprocessed = new Queue<PlacementNode>();
		unprocessed.Enqueue(root);
		visited.Add(this.timeline.OriginNode.ID);

		Stack<PlacementNode> reverse = new Stack<PlacementNode>();
		while (unprocessed.Count > 0)
		{
			PlacementNode current = unprocessed.Dequeue();
			reverse.Push(current);
			List<int> dids = current.Node.GetDescendantIDs();
			bool hadChildren = false;
			for (int j = 0; j < dids.Count; ++j)
			{
				if (!visited.Contains(dids[j]))
				{
					PlacementNode child = new PlacementNode(this.timeline.Nodes[dids[j]], current);
					allNodes[child.Node.ID] = child;
#if PLACER_DEBUG
					Debug.Log("Parenting " + child.Describe() + " under " + current.Describe());
#endif
					unprocessed.Enqueue(child);
					visited.Add(dids[j]);
					hadChildren = true;
				}
				else if(this.attemptReparenting)
				{
					allNodes[dids[j]].ReParent(current);
				}
			}
			if (!hadChildren)
			{
				current.Width = 1;
			}
		}

		// Now run through the nodes in the opposite order, computing width as we go
		// Since we pushed the nodes onto a stack in the previous traversal, this should guarantee proper order traversing back up
		while (reverse.Count > 0)
		{
			PlacementNode current = reverse.Pop();
			if (current.Parent != null)
			{
				current.Parent.Width += current.Width;
			}
		}

		// We should now have a nice tree with depths and widths properly computed
		// Starting from the root, propagate back down the tree, setting offsets for the children as we go
		unprocessed.Enqueue(root);
		while (unprocessed.Count > 0)
		{
			PlacementNode current = unprocessed.Dequeue();
			float cumulative = 0f;
			float r = current.WidthOffset - (current.Width / 2f);
			for (int j = 0; j < current.Children.Count; ++j)
			{
				PlacementNode child = current.Children[j];
				child.WidthOffset = (child.Width / 2f) + cumulative + r;
				cumulative += child.Width;
				unprocessed.Enqueue(child);
			}

			Vector2 finalPosition = new Vector2(current.WidthOffset, current.Depth);
			places[current.Node.ID] = finalPosition;
#if PLACER_DEBUG
			Debug.Log("Computed position for " + current.Describe() + " of " + finalPosition);
#endif
		}
	}
Example #9
0
 private Position RenderPosition(PlacementNode node)
 {
     return(RenderPosition(node.Position, _config.Offsets, _config.Dimensions, _config.Intervals));
 }
 private static bool CheckFilter(ShapePlacementContext ctx, PlacementNode filter) => ShapePlacementParsingStrategy.CheckFilter(ctx, filter);