Exemplo n.º 1
0
		// Expanded is passed so that the correct ContentNodes are expanded in the PositionedNode
		PositionedGraph BuildPositionedGraph(ObjectGraph objectGraph, Expanded expanded)
		{
			var positionedNodeFor = new Dictionary<ObjectGraphNode, PositionedNode>();
			var positionedGraph = new PositionedGraph();
			
			// create empty PositionedNodes
			foreach (ObjectGraphNode objectNode in objectGraph.ReachableNodes) {
				var posNode = new PositionedNode(objectNode, expanded);
				posNode.MeasureVisualControl();
				positionedGraph.AddNode(posNode);
				positionedNodeFor[objectNode] = posNode;
			}
			
			// create edges
			foreach (PositionedNode posNode in positionedGraph.Nodes)
			{
				foreach (PositionedNodeProperty property in posNode.Properties)	{
					if (property.ObjectGraphProperty.TargetNode != null) {
						ObjectGraphNode targetObjectNode = property.ObjectGraphProperty.TargetNode;
						PositionedNode edgeTarget = positionedNodeFor[targetObjectNode];
						property.Edge = new PositionedEdge {
							Name = property.Name, Source = property, Target = edgeTarget
						};
					}
				}
			}
			positionedGraph.Root = positionedNodeFor[objectGraph.Root];
			return positionedGraph;
		}
		/// <summary>
		/// Creates new PositionedNodeProperty.
		/// </summary>
		/// <param name="objectProperty">Underlying <see cref="ObjectProperty"/></param>
		public PositionedNodeProperty(ObjectGraphProperty objectProperty, PositionedNode containingNode, bool isPropertyExpanded)
		{
			if (containingNode == null) throw new ArgumentNullException("containingNode");
			if (objectProperty == null) throw new ArgumentNullException("objectProperty");
			this.objectGraphProperty = objectProperty;
			this.containingNode = containingNode;
			this.IsPropertyExpanded = isPropertyExpanded;
		}
Exemplo n.º 3
0
		PositionedNode MatchNode(PositionedNode oldNode, Dictionary<int, PositionedNode> newNodeMap)
		{
			PositionedNode newNodeFound = newNodeMap.GetValue(oldNode.ObjectNode.HashCode);
			if ((newNodeFound != null) && IsSameAddress(oldNode, newNodeFound))	{
				return newNodeFound;
			} else {
				return null;
			}
		}
		/// <summary>
		/// Sets the node to be displayed by this control.
		/// </summary>
		/// <param name="node"></param>
		public void SetDataContext(PositionedNode node)
		{
			if (node == null) {
				this.DataContext = null;
				this.listView.ItemsSource = null;
				return;
			}
			this.DataContext = node;
			this.Root = node.Content;
			this.items = GetInitialItems(this.Root);
			// data virtualization, ContentPropertyNode implements IEvaluate
			this.listView.ItemsSource = new VirtualizingObservableCollection<ContentNode>(this.items);
		}
Exemplo n.º 5
0
        /// <summary>
        /// Given SubtreeSize for each node, positions the nodes, in a left-to-right or top-to-bottom layout.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="lateralStart"></param>
        /// <param name="mainStart"></param>
        void CalculateNodePosRecursive(PositionedNode node, HashSet <PositionedEdge> treeEdges, double lateralBase, double mainBase)
        {
            double childsSubtreeSize = TreeChildNodes(node, treeEdges).Sum(child => child.SubtreeSize);
            double center            = TreeEdges(node, treeEdges).Count() == 0 ? 0 : 0.5 * (childsSubtreeSize - (GetLateralSizeWithMargin(node)));

            if (center < 0)
            {
                // if root is larger than subtree, it would be shifted below lateralStart
                // -> make whole layout start at lateralStart
                lateralBase -= center;
            }

            SetLateral(node, GetLateral(node) + lateralBase + center);
            SetMain(node, mainBase);

            double childLateral    = lateralBase;
            double childsMainFixed = GetMain(node) + GetMainSizeWithMargin(node);

            foreach (var child in TreeChildNodes(node, treeEdges))
            {
                CalculateNodePosRecursive(child, treeEdges, childLateral, childsMainFixed);
                childLateral += child.SubtreeSize;
            }
        }
Exemplo n.º 6
0
		void CalculateSubtreeSizesRecursive(PositionedNode root, HashSet<PositionedEdge> treeEdges)
		{
			double subtreeSize = 0;
			foreach (var child in TreeChildNodes(root, treeEdges)) {
				CalculateSubtreeSizesRecursive(child, treeEdges);
				// just sum up the sizes of children
				subtreeSize += child.SubtreeSize;
			}
			root.SubtreeSize = Math.Max(GetLateralSizeWithMargin(root), subtreeSize);
		}
Exemplo n.º 7
0
 internal void SetAdded(PositionedNode addedNode)
 {
     addedNodes.Add(addedNode);
 }
Exemplo n.º 8
0
		double GetMain(PositionedNode node)
		{
			return (this.LayoutDirection == LayoutDirection.LeftRight) ? node.Left : node.Top;
		}
Exemplo n.º 9
0
		IEnumerable<PositionedEdge> TreeEdges(PositionedNode node, HashSet<PositionedEdge> treeEdges)
		{
			return node.Edges.Where(e => treeEdges.Contains(e));
		}
Exemplo n.º 10
0
		internal void SetAdded(PositionedNode addedNode)
		{
			addedNodes.Add(addedNode);
		}
Exemplo n.º 11
0
		internal void SetMatching(PositionedNode matchFrom, PositionedNode matchTo)
		{
			matching[matchFrom] = matchTo;
			changedNodes.Add(matchFrom);
		}
Exemplo n.º 12
0
 public PositionedNode GetMatchingNewNode(PositionedNode oldNode)
 {
     return(matching.GetValue(oldNode));
 }
Exemplo n.º 13
0
		/// <summary>
		/// Given SubtreeSize for each node, positions the nodes, in a left-to-right or top-to-bottom layout.
		/// </summary>
		/// <param name="node"></param>
		/// <param name="lateralStart"></param>
		/// <param name="mainStart"></param>
		void CalculateNodePosRecursive(PositionedNode node, HashSet<PositionedEdge> treeEdges, double lateralBase, double mainBase)
		{
			double childsSubtreeSize = TreeChildNodes(node, treeEdges).Sum(child => child.SubtreeSize);
			double center = TreeEdges(node, treeEdges).Count() == 0 ? 0 : 0.5 * (childsSubtreeSize - (GetLateralSizeWithMargin(node)));
			if (center < 0)	{
				// if root is larger than subtree, it would be shifted below lateralStart
				// -> make whole layout start at lateralStart
				lateralBase -= center;
			}
			
			SetLateral(node, GetLateral(node) + lateralBase + center);
			SetMain(node, mainBase);
			
			double childLateral = lateralBase;
			double childsMainFixed = GetMain(node) + GetMainSizeWithMargin(node);
			foreach (var child in TreeChildNodes(node, treeEdges)) {
				CalculateNodePosRecursive(child, treeEdges, childLateral, childsMainFixed);
				childLateral += child.SubtreeSize;
			}
		}
Exemplo n.º 14
0
		public PositionedNode GetMatchingNewNode(PositionedNode oldNode)
		{
			return matching.GetValue(oldNode);
		}
Exemplo n.º 15
0
		public ContentPropertyNode(PositionedNode containingNode, ContentNode parent)
			: base(containingNode, parent)
		{
		}
Exemplo n.º 16
0
		IEnumerable<PositionedNode> TreeChildNodes(PositionedNode node, HashSet<PositionedEdge> treeEdges)
		{
			return TreeEdges(node, treeEdges).Select(e => e.Target);
		}
Exemplo n.º 17
0
		void SetLateral(PositionedNode node, double value)
		{
			if (this.LayoutDirection == LayoutDirection.LeftRight) {
				node.Top = value;
			} else {
				node.Left = value;
			}
		}
Exemplo n.º 18
0
		double GetLateral(PositionedNode node)
		{
			return (this.LayoutDirection == LayoutDirection.LeftRight) ? node.Top : node.Left;
		}
Exemplo n.º 19
0
 internal void SetRemoved(PositionedNode removeddNode)
 {
     deletedNodes.Add(removeddNode);
 }
 internal void AddNode(PositionedNode node)
 {
     this.nodes.Add(node);
 }
Exemplo n.º 21
0
 internal void SetMatching(PositionedNode matchFrom, PositionedNode matchTo)
 {
     matching[matchFrom] = matchTo;
     changedNodes.Add(matchFrom);
 }
Exemplo n.º 22
0
 IEnumerable <PositionedEdge> TreeEdges(PositionedNode node, HashSet <PositionedEdge> treeEdges)
 {
     return(node.Edges.Where(e => treeEdges.Contains(e)));
 }
Exemplo n.º 23
0
		public PositionedNode GetMatchingNewNode(PositionedNode oldNode)
		{
			return matching.GetOrDefault(oldNode);
		}
Exemplo n.º 24
0
 double GetLateralSizeWithMargin(PositionedNode node)
 {
     return((this.LayoutDirection == LayoutDirection.LeftRight) ? node.Height + NodeMarginV : node.Width + NodeMarginH);
 }
Exemplo n.º 25
0
		internal void SetRemoved(PositionedNode removeddNode)
		{
			deletedNodes.Add(removeddNode);
		}
Exemplo n.º 26
0
 double GetLateral(PositionedNode node)
 {
     return((this.LayoutDirection == LayoutDirection.LeftRight) ? node.Top : node.Left);
 }
Exemplo n.º 27
0
		bool IsSameAddress(PositionedNode node1, PositionedNode node2)
		{
			return node1.ObjectNode.PermanentReference.GetObjectAddress() == node2.ObjectNode.PermanentReference.GetObjectAddress();
		}
Exemplo n.º 28
0
		double GetLateralSizeWithMargin(PositionedNode node)
		{
			return (this.LayoutDirection == LayoutDirection.LeftRight) ? node.Height + NodeMarginV : node.Width + NodeMarginH;
		}
Exemplo n.º 29
0
 IEnumerable <PositionedNode> TreeChildNodes(PositionedNode node, HashSet <PositionedEdge> treeEdges)
 {
     return(TreeEdges(node, treeEdges).Select(e => e.Target));
 }
Exemplo n.º 30
0
 bool IsSameAddress(PositionedNode node1, PositionedNode node2)
 {
     return(node1.ObjectNode.PermanentReference.GetObjectAddress() == node2.ObjectNode.PermanentReference.GetObjectAddress());
 }
Exemplo n.º 31
0
 double GetMain(PositionedNode node)
 {
     return((this.LayoutDirection == LayoutDirection.LeftRight) ? node.Left : node.Top);
 }
Exemplo n.º 32
0
		internal void AddNode(PositionedNode node)
		{
			this.nodes.Add(node);
		}
Exemplo n.º 33
0
 public ContentPropertyNode(PositionedNode containingNode, ContentNode parent)
     : base(containingNode, parent)
 {
 }
Exemplo n.º 34
0
 public PositionedNode GetMatchingNewNode(PositionedNode oldNode)
 {
     return(matching.GetOrDefault(oldNode));
 }
Exemplo n.º 35
0
		PositionedGraphNodeControl AddNodeToCanvas(PositionedNode node)
		{
			canvas.Children.Add(node.NodeVisualControl);
			Canvas.SetLeft(node.NodeVisualControl, node.Left);
			Canvas.SetTop(node.NodeVisualControl, node.Top);
			return node.NodeVisualControl;
		}
Exemplo n.º 36
0
		HashSet<PositionedEdge> DetermineTreeEdges(PositionedNode root)
		{
			var treeEdges = new HashSet<PositionedEdge>();
			
			var seenNodes = new HashSet<PositionedNode>();
			var q = new Queue<PositionedNode>();
			q.Enqueue(root);
			seenNodes.Add(root);
			
			while (q.Count > 0) {
				var node = q.Dequeue();
				foreach (var property in node.Properties) {
					var edge = property.Edge;
					if (edge != null && edge.Target != null) {
						if (!seenNodes.Contains(edge.Target)) {
							treeEdges.Add(edge);
							seenNodes.Add(edge.Target);
							q.Enqueue(edge.Target);
						}
					}
				}
			}
			return treeEdges;
		}