private void LoadNode(PlanNode node) { // check if already loaded if (node.AddSubs) { return; } node.AddSubs = true; // go through downlinks OpLink[] downlinks = (from link in node.Link.Downlinks where node.Link.Confirmed.Contains(link.UserID) || Uplinks.Contains(link.UserID) select link).ToArray(); foreach (OpLink link in downlinks) { // if doesnt exist search for it if (!link.Trust.Loaded) { Trust.Research(link.UserID, ProjectID, false); continue; } Plans.Research(link.UserID); GuiUtils.InsertSubNode(node, CreateNode(link)); } }
private PlanNode CreateNode(OpLink link) { PlanNode node = new PlanNode(this, link, link.UserID == UserID); NodeMap[link.UserID] = node; return(node); }
void RecurseFocus(PlanNode node) { // add parent to focus list Core.KeepData.SafeAdd(node.Link.UserID, true); // iterate through sub items foreach (PlanNode sub in node.Nodes) { RecurseFocus(sub); } }
PlanNode GetSelected() { if (PlanStructure.SelectedNodes.Count == 0) { return(null); } PlanNode node = (PlanNode)PlanStructure.SelectedNodes[0]; return(node); }
public BlockRow(PlanNode node) { InitializeComponent(); Node = node; View = node.View; UserID = node.Link.UserID; SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); BlackPen.DashStyle = DashStyle.Dot; }
private void ExpandPath(PlanNode node, List <ulong> path) { if (!path.Contains(node.Link.UserID)) { return; } // expand triggers even loading nodes two levels down, one level shown, the other hidden node.Expand(); foreach (PlanNode sub in node.Nodes) { ExpandPath(sub, path); } }
void PlanStructure_NodeExpanding(object sender, EventArgs e) { PlanNode node = sender as PlanNode; if (node == null) { return; } Debug.Assert(node.AddSubs); // node now expanded, get next level below children foreach (PlanNode child in node.Nodes) { LoadNode(child); } }
private void PlanStructure_SelectedItemChanged(object sender, EventArgs e) { RefreshRows(); // updates selection box graphics // children searched on expand PlanNode node = GetSelected(); if (node == null) { SetDetails(null); return; } // link research Trust.Research(node.Link.UserID, ProjectID, false); // plan research Plans.Research(node.Link.UserID); }
private void VisiblePath(PlanNode node, List <ulong> path) { bool found = false; foreach (PlanNode sub in node.Nodes) { if (path.Contains(sub.Link.UserID)) { found = true; } } if (found) { node.Expand(); foreach (PlanNode sub in node.Nodes) { VisiblePath(sub, path); } } }
void PlanStructure_NodeCollapsed(object sender, EventArgs e) { PlanNode node = sender as PlanNode; if (node == null) { return; } if (!node.AddSubs) // this node is already collapsed { return; } // remove nodes 2 levels down foreach (PlanNode child in node.Nodes) { UnloadNode(child, null); } Debug.Assert(node.AddSubs); // this is the top level, children hidden underneath }
private void UnloadNode(PlanNode node, List <ulong> visible) { node.AddSubs = false; if (visible != null && node.IsVisible()) { visible.Add(node.Link.UserID); } // for each child, call unload node, then clear foreach (PlanNode child in node.Nodes) { if (NodeMap.ContainsKey(child.Link.UserID)) { NodeMap.Remove(child.Link.UserID); } UnloadNode(child, visible); } // unloads children of node, not the node itself node.Nodes.Clear(); node.Collapse(); }
private PlanNode CreateNode(OpLink link) { PlanNode node = new PlanNode(this, link, link.UserID == UserID); NodeMap[link.UserID] = node; return node; }
private void VisiblePath(PlanNode node, List<ulong> path) { bool found = false; foreach (PlanNode sub in node.Nodes) if (path.Contains(sub.Link.UserID)) found = true; if (found) { node.Expand(); foreach (PlanNode sub in node.Nodes) VisiblePath(sub, path); } }
private void LoadNode(PlanNode node) { // check if already loaded if (node.AddSubs) return; node.AddSubs = true; // go through downlinks OpLink[] downlinks = (from link in node.Link.Downlinks where node.Link.Confirmed.Contains(link.UserID) || Uplinks.Contains(link.UserID) select link).ToArray(); foreach (OpLink link in downlinks) { // if doesnt exist search for it if (!link.Trust.Loaded) { Trust.Research(link.UserID, ProjectID, false); continue; } Plans.Research(link.UserID); GuiUtils.InsertSubNode(node, CreateNode(link)); } }
private void ExpandPath(PlanNode node, List<ulong> path) { if (!path.Contains(node.Link.UserID)) return; // expand triggers even loading nodes two levels down, one level shown, the other hidden node.Expand(); foreach (PlanNode sub in node.Nodes) ExpandPath(sub, path); }
private void RemoveNode(PlanNode node) { UnloadNode(node, null); // unload subs NodeMap.Remove(node.Link.UserID); // remove from map node.Remove(); // remove from tree }
void RecurseFocus(PlanNode node) { // add parent to focus list Core.KeepData.SafeAdd(node.Link.UserID, true); // iterate through sub items foreach (PlanNode sub in node.Nodes) RecurseFocus(sub); }
void Trust_Update(ulong key) { // copied from linkTree's source OpLink link = Trust.GetLink(key, ProjectID); if (link == null) { if (NodeMap.ContainsKey(key)) { RemoveNode(NodeMap[key]); } return; } /*above should do this now * if (!link.Projects.Contains(ProjectID) && !link.Downlinks.ContainsKey(ProjectID)) * { * if (NodeMap.ContainsKey(key)) * RemoveNode(NodeMap[key]); * * return; * }*/ PlanNode node = null; if (NodeMap.ContainsKey(key)) { node = NodeMap[key]; } TreeListNode parent = null; OpLink uplink = GetTreeHigher(link); if (uplink == null) { parent = PlanStructure.virtualParent; } else if (NodeMap.ContainsKey(uplink.UserID)) { parent = NodeMap[uplink.UserID]; } else if (uplink.IsLoopRoot) { parent = new TreeListNode(); // ensures that tree is refreshed } // if nodes status unchanged if (node != null && parent != null && node.Parent == parent) { node.UpdateName(); Invalidate(); return; } // only if parent is visible if (parent != null) { RefreshUplinks(); RefreshStructure(); } //////////////////////////////////////////////////////////////////// /* * // update uplinks * if (key == DhtID || Uplinks.Contains(key)) * RefreshUplinks(); * * * // create a node item, or get the current one * PlanNode node = null; * * if (NodeMap.ContainsKey(key)) * node = NodeMap[key]; * else * node = new PlanNode(this, link, key == DhtID); * * * // get the right parent node for this item * TreeListNode parent = null; * * OpLink parentLink = link.GetHigher(ProjectID, false); * * if (parentLink == null) // dont combine below, causes next if to fail * parent = Uplinks.Contains(key) ? PlanStructure.virtualParent : null; * * else if (NodeMap.ContainsKey(parentLink.DhtID)) * parent = NodeMap[parentLink.DhtID]; * * else * parent = null; // branch this link is apart of is not visible in current display * * * // remember settings * bool selected = node.Selected; * * * if (node.Parent != parent) * { * List<ulong> visible = new List<ulong>(); * * // remove previous instance of node * if (node.Parent != null) * { * if (node.IsVisible()) * visible.Add(link.DhtID); * * UnloadNode(node, visible); * NodeMap.Remove(link.DhtID); * node.Remove(); * } * * * // if node changes to be sub of another root 3 levels down, whole branch must be reloaded * if (parent == null || parent == PlanStructure.virtualParent) * { * if(Uplinks.Contains(key)) * RefreshStructure(); * * return; * } * * // if new parent is hidden, dont bother adding till user expands * PlanNode newParent = parent as PlanNode; // null if root * * if (newParent != null && newParent.AddSubs == false) * return; * * * // copy node to start fresh * PlanNode newNode = CreateNode(node.Link); * * * // check if parent should be moved to project header * if (newParent != null) * { * Utilities.InsertSubNode(newParent, newNode); * * // if we are a visible child, must load hidden sub nodes * if (newParent.IsVisible() && newParent.IsExpanded) * LoadNode(newNode); * } * * // if node itself is the root * else * { * LoadNode(newNode); * * // remove previous * foreach (PlanNode old in PlanStructure.Nodes) * UnloadNode(old, visible); * * PlanStructure.Nodes.Clear(); * PlanStructure.Nodes.Add(newNode); * } * * node = newNode; * * * // recurse to each previously visible node * foreach (ulong id in visible) * { * List<ulong> uplinks = Links.GetUplinkIDs(id, ProjectID); * * foreach (PlanNode root in PlanStructure.Nodes) // should only be one root * VisiblePath(root, uplinks); * } * } * * node.UpdateName(); * * * node.Selected = selected;*/ }
private void BlockRow_Paint(object sender, PaintEventArgs e) { if (DisplayBuffer == null) { DisplayBuffer = new Bitmap(Width, Height); } if (!Redraw) { e.Graphics.DrawImage(DisplayBuffer, 0, 0); return; } Redraw = false; // background Graphics buffer = Graphics.FromImage(DisplayBuffer); buffer.Clear(Color.White); //buffer.SmoothingMode = SmoothingMode.AntiAlias; // draw tick lines foreach (int mark in View.ScheduleSlider.SmallMarks) { buffer.DrawLine(SmallPen, mark, 0, mark, Height); } foreach (int mark in View.ScheduleSlider.BigMarks) { buffer.DrawLine(BigPen, mark, 0, mark, Height); } //buffer.DrawLine(RefPen, View.ScheduleSlider.RefMark, 0, View.ScheduleSlider.RefMark, Height); // setup vars Rectangle tempRect = new Rectangle(); tempRect.Y = 0; tempRect.Height = Height; StartTime = View.GetStartTime().ToUniversalTime(); EndTime = View.GetEndTime().ToUniversalTime(); TicksperPixel = View.ScheduleSlider.TicksperPixel; // draw higher plans BlockAreas.Clear(); GoalAreas.Clear(); Uplinks = View.Core.Trust.GetUnconfirmedUplinkIDs(UserID, View.ProjectID); // upnodes just used for scope calc now List <PlanNode> upnodes = new List <PlanNode>(); PlanNode nextNode = Node; while (nextNode.Parent.GetType() == typeof(PlanNode)) { nextNode = (PlanNode)nextNode.Parent; upnodes.Add(nextNode); } upnodes.Reverse(); // draw plans for each node above in the current block layered on top of one another // if we want to change to loop doesnt inherit other loop member's plans, replace foreach uplinks with upnodes // not obvious behaviour int level = 0; //foreach (ulong uplink in Uplinks) foreach (PlanNode node in upnodes) { ulong uplink = node.Link.UserID; foreach (PlanBlock block in GetBlocks(uplink)) { // scope -1 everyone or current level 0 highest + scope is >= than current node if ((block.Scope == -1 || (level + block.Scope >= upnodes.Count)) && BlockinRange(block, ref tempRect)) { buffer.FillRectangle(GetMask(uplink, true), tempRect); BlockAreas.Add(new BlockArea(tempRect, block, level, false)); } } level++; } // draw local plans List <List <DrawBlock> > layers = new List <List <DrawBlock> >(); // arrange visible blocks foreach (PlanBlock block in GetBlocks(UserID)) { if (BlockinRange(block, ref tempRect)) { AddDrawBlock(new DrawBlock(block, tempRect), layers); } } List <KeyValuePair <string, PointF> > StringList = new List <KeyValuePair <string, PointF> >(); // draw blocks if (layers.Count > 0) { int y = 2; int yStep = (Height - 2) / layers.Count; foreach (List <DrawBlock> list in layers) { foreach (DrawBlock item in list) { if (item.Above == null) { item.Rect.Y = y; item.Rect.Height = yStep - 1; DrawBlock down = item.Below; while (down != null) { item.Rect.Height += yStep; down = down.Below; } BlockAreas.Add(new BlockArea(item.Rect, item.Block, level, true)); Rectangle fill = item.Rect; fill.Height = Height - y; buffer.FillRectangle(GetMask(UserID, true), fill); if (item.Block == View.SelectedBlock) { buffer.DrawRectangle(SelectPen, item.Rect); } SizeF size = buffer.MeasureString(item.Block.Title, Tahoma); if (size.Width < item.Rect.Width - 2 && size.Height < item.Rect.Height - 2) { StringList.Add(new KeyValuePair <string, PointF>(item.Block.Title, new PointF(item.Rect.X + (item.Rect.Width - size.Width) / 2, item.Rect.Y + (item.Rect.Height - size.Height) / 2))); } } } y += yStep; } } // scan higher's goal lists for assigned goals to this id if (View.SelectedGoalID != 0) { // cache what to draw, look at how goals control get progress status // color goal bars solid red / blue / gray // cache strings, draw after goals //Uplinks.Add(Node.Link.DhtID); // add self to scan upnodes.Add(Node); foreach (PlanNode node in upnodes) { ulong userID = node.Link.UserID; OpPlan upPlan = View.Plans.GetPlan(userID, true); if (upPlan != null) { if (upPlan.GoalMap.ContainsKey(View.SelectedGoalID)) { foreach (PlanGoal goal in upPlan.GoalMap[View.SelectedGoalID]) { if (goal.Project == View.ProjectID && goal.Person == UserID) { if (StartTime < goal.End && goal.End < EndTime) { int x = (int)((goal.End.Ticks - StartTime.Ticks) / TicksperPixel); int completed = 0, total = 0; View.Plans.GetEstimate(goal, ref completed, ref total); // draw divider line with little right triangles in top / bottom buffer.FillRectangle(WhiteBrush, new Rectangle(x - 4, 2, 2, Height - 4)); if (total > 0) { int progress = completed * (Height - 4) / total; buffer.FillRectangle(GreenBrush, new Rectangle(x - 4, 2 + (Height - 4) - progress, 2, progress)); } buffer.FillPolygon(GetMask(UserID, false), new Point[] { new Point(x - 6, 2), new Point(x, 2), new Point(x, Height - 2), new Point(x - 6, Height - 2), new Point(x - 2, Height - 2 - 5), new Point(x - 2, 2 + 5) }); GoalAreas.Add(new BlockArea(new Rectangle(x - 6, 2, 6, Height - 4), goal)); } } } } } } } // draw strings foreach (KeyValuePair <string, PointF> pair in StringList) { buffer.DrawString(pair.Key, Tahoma, blackBrush, pair.Value); } // draw selection if (Node.Selected) { if (View.PlanStructure.Focused) { buffer.FillRectangle(Highlight, 0, 0, Width, 2); buffer.FillRectangle(Highlight, 0, Height - 2, Width, 2); } else { buffer.DrawLine(BlackPen, 1, 0, Width - 1, 0); buffer.DrawLine(BlackPen, 0, Height - 1, Width, Height - 1); } } // Copy buffer to display e.Graphics.DrawImage(DisplayBuffer, 0, 0); }
private void RefreshStructure() { PlanStructure.BeginUpdate(); // save selected PlanNode selected = GetSelected(); // save visible while unloading List <ulong> visible = new List <ulong>(); foreach (TreeListNode node in PlanStructure.Nodes) { if (node.GetType() == typeof(PlanNode)) { UnloadNode((PlanNode)node, visible); } } NodeMap.Clear(); PlanStructure.Nodes.Clear(); // nodes ThreadedList <OpLink> roots = null; if (Trust.ProjectRoots.SafeTryGetValue(ProjectID, out roots)) { roots.LockReading(delegate() { foreach (OpLink root in roots) { if (Uplinks.Contains(root.UserID)) { PlanNode node = CreateNode(root); Plans.Research(root.UserID); LoadNode(node); GuiUtils.InsertSubNode(PlanStructure.virtualParent, node); ExpandPath(node, Uplinks); } if (root.IsLoopRoot && root.Downlinks.Count > 0 && Uplinks.Contains(root.Downlinks[0].UserID)) { foreach (OpLink downlink in root.Downlinks) { if (!root.IsLoopedTo(downlink)) { PlanNode node = CreateNode(downlink); Plans.Research(downlink.UserID); LoadNode(node); GuiUtils.InsertSubNode(PlanStructure.virtualParent, node); ExpandPath(node, Uplinks); } } } } }); } // restore visible foreach (ulong id in visible) { foreach (TreeListNode node in PlanStructure.Nodes) { if (node.GetType() == typeof(PlanNode)) { List <ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(id, ProjectID); uplinks.Add(id); VisiblePath((PlanNode)node, uplinks); } } } // restore selected if (selected != null) { if (NodeMap.ContainsKey(selected.Link.UserID)) { PlanStructure.Select(NodeMap[selected.Link.UserID]); } } PlanStructure.EndUpdate(); }
private void UnloadNode(PlanNode node, List<ulong> visible) { node.AddSubs = false; if (visible != null && node.IsVisible()) visible.Add(node.Link.UserID); // for each child, call unload node, then clear foreach (PlanNode child in node.Nodes) { if (NodeMap.ContainsKey(child.Link.UserID)) NodeMap.Remove(child.Link.UserID); UnloadNode(child, visible); } // unloads children of node, not the node itself node.Nodes.Clear(); node.Collapse(); }