// Done! #region Control Events // Done! private void ComputePath_Click(object sender, EventArgs e) { var index1 = this.startNode.SelectedIndex; var index2 = this.closeNode.SelectedIndex; if (index1 == -1) { MessageBox.Show("Invalid Start MapNode"); return; } if (index2 == -1) { MessageBox.Show("Invalid Goal MapNode"); return; } string nStart = this.startNode.Items[index1].ToString(); string nClose = this.startNode.Items[index2].ToString(); var map = this.RealParent.VisualMap; VisualMapNode vStart = map.FindByName(nStart); VisualMapNode vClose = map.FindByName(nClose); FindPath(vStart, vClose); }
// Done! #region Events // Done! #region Helpers // Done! private void GenerateExitOptions(VisualMapNode vmp, MapNode e) { List <string> sort = new List <string>(); for (int i = 0; i < this.VisualMap.Count; ++i) { if (vmp != this.VisualMap[i]) { sort.Add(this.VisualMap[i].ConcreteNode.Name); } } sort.Sort(); var oc = this.listOfPossibleExits.Items; oc.Clear(); oc.Add(string.Empty); for (int i = 0; i < sort.Count; ++i) { oc.Add(sort[i]); } this.listOfPossibleExits.Enabled = true; // Select an item if that's the case! if (e.Exits.Count > 0 && e.Exits[0] != null) { var i = oc.IndexOf(e.Exits[0].Name); this.listOfPossibleExits.SelectedIndex = i == -1 ? 0 : i; } }
// Done! private void DrawSlopes(Graphics g) { var was = this.WorkAreaState; if (was.SlopeVector0 == null || was.SlopeVector1 == null || was.LastSelectedAnchor == null || was.ShowSlopes == false) { return; } Vector vc = Vector.Transform(was.LastSelectedAnchor, was.Scale, was.DeltaX, was.DeltaY); Vector v0 = Vector.Transform(was.SlopeVector0, was.Scale, was.DeltaX, was.DeltaY); Vector v1 = Vector.Transform(was.SlopeVector1, was.Scale, was.DeltaX, was.DeltaY); if (Vector.Slope(vc, v0) != Vector.Slope(v1, vc) == false) { VisualMapNode.DrawSlope(g, v0, vc, -1); } else { VisualMapNode.DrawSlope(g, v0, vc, 0); VisualMapNode.DrawSlope(g, v1, vc, 1); if (was.ShowAngles == true) { VisualMapNode.DrawAngle(g, v0, v1, vc); } } }
// Done! private void DrawSelections(Graphics g) { var artifact = GetDetectedArtifact(this.WorkAreaState); switch (artifact) { case Artifact.Anchor: { VisualMapNode.DrawSelectedAnchor(g, this.WorkAreaState); } break; case Artifact.Exit: { VisualMapNode.DrawSelectedExit(g, this.WorkAreaState); } break; case Artifact.Geometry: { VisualMapNode.DrawSelectedGeometry(g, this.WorkAreaState); if (WorkAreaState.ShowBounds) { VisualMapNode.DrawBounds(g, this.WorkAreaState); } } break; } }
// Done! #region Demos! // Done! private void GeneralDemo(string nStart, string nClose) { var map = this.RealParent.VisualMap; VisualMapNode vStart = map.FindByName(nStart); VisualMapNode vClose = map.FindByName(nClose); FindPath(vStart, vClose); }
// Done! #region Other // Done! internal void FakeSelection(VisualMapNode vmn) { var was = this.WorkAreaState; was.SelectedArtifact = was.LastSelectedArtifact = Artifact.Geometry; was.LastSelectedShape = was.SelectedShape = vmn; this.ForceUpdate(); SafeInvoker(SelectionChanged, was); }
// Done! #region Artifacts // Done! #region Helpers // Done! private bool IsArtifactDetectable(Point location, VisualMapNode vmn) { var was = this.WorkAreaState; var s = vmn.Visuals.AnchorSize; var p1 = Vector.Transform(new Vector(vmn.Min.X, vmn.Min.Y), was.Scale, was.DeltaX, was.DeltaY); var p2 = Vector.Transform(new Vector(vmn.Max.X, vmn.Max.Y), was.Scale, was.DeltaX, was.DeltaY); shapeSelection = new RectangleF(p1.X, p1.Y, p2.X - p1.X + s, p2.Y - p1.Y + s); return(Helpers.IsInsideRectangle(location, shapeSelection)); }
// Done! private static Vector FindAnchorAfter(VisualMapNode vmn, Vector vector) { var mn = vmn.ConcreteNode.Geometry; for (int i = 0; i < mn.Count; ++i) { if (mn[i] == vector) { return((i == mn.Count - 1) ? mn[0] : mn[i + 1]); } } return(null); }
// Done! private void FindPath(VisualMapNode vStart, VisualMapNode vClose) { if (vStart == null) { MessageBox.Show("Invalid Start MapNode"); return; } if (vClose == null) { MessageBox.Show("Invalid Goal MapNode"); return; } this.ClearPathSelection(); var start = vStart.ConcreteNode; var close = vClose.ConcreteNode; var startStub = MapNode.ToVirtual(start, Vector.Average(start.Geometry)); // Change to Exact Location var closeStub = ConcreteMap.AdaptNodeToGoal(close, Vector.Average(close.Geometry)); // Change to Exact Location if (this.cognitive.Checked == true) { ICognitiveStateSearchable <MapNode> iss = new CognitiveAStar <MapNode>(startStub, closeStub, this.agentCharacter); iss.FindPath(); var path = iss.Path; path.Add(closeStub.Clone()); //FillGeometryPath(map, path); this.ForceParentUpdate(path); } else { IStateSearchable <MapNode> iss = new AStar <MapNode>(startStub, closeStub); iss.FindPath(); var path = iss.Path; path.Add(closeStub.Clone()); //FillGeometryPath(map, path); this.ForceParentUpdate(path); } ConcreteMap.RestoreNodeFromGoal(close); }
// Done! // Todo: Account for areas that overcome paint area! private bool IsInsideWorkArea(VisualMapNode vmn) { if (this.WorkAreaState.TweakAgentView == true) { drawArea = this.defaultAgentView; } var was = this.WorkAreaState; var p1 = Vector.Transform(new Vector(vmn.Min.X, vmn.Min.Y), was.Scale, was.DeltaX, was.DeltaY); var p2 = Vector.Transform(new Vector(vmn.Max.X, vmn.Min.Y), was.Scale, was.DeltaX, was.DeltaY); var p3 = Vector.Transform(new Vector(vmn.Min.X, vmn.Max.Y), was.Scale, was.DeltaX, was.DeltaY); var p4 = Vector.Transform(new Vector(vmn.Max.X, vmn.Max.Y), was.Scale, was.DeltaX, was.DeltaY); return(Helpers.IsInsideRectangle(p1, drawArea) || Helpers.IsInsideRectangle(p2, drawArea) || Helpers.IsInsideRectangle(p3, drawArea) || Helpers.IsInsideRectangle(p4, drawArea)); }
// Done! #region Menu Controls // Done! #region Helpers // Done! private void AddNewShape() { if (this.VisualMap.Count == 0) { this.nodeController.Enabled = true; } var vmn = new VisualMapNode { IsLocked = false, IsVisible = true, ConcreteNode = new MapNode(string.Format("<NoName:{0}>", nodeCounter++), NodeType.Geometry) }; this.VisualMap.Add(vmn); this.WorkAreaState.LastSelectedShape = this.WorkAreaState.SelectedShape = vmn; SafeInvoker(this.StateChanged, this.WorkAreaState); SafeInvoker(this.NodeAdded, this.WorkAreaState); this.ForceUpdate(); }
// Done! private void Draw(Graphics g, bool toImage) { if (this.WorkAreaState.HighQuality == true) { Helpers.SetHighQualityMode(g); } if (WorkAreaState.ShowOnlyConnectors == false) { if (WorkAreaState.IsAnchorOnTop) { DrawGeometry(g, toImage); DrawAnchorSet(g, toImage); } else { DrawAnchorSet(g, toImage); DrawGeometry(g, toImage); } } DrawExitSet(g, toImage); VisualMapNode.DrawPath(g, this.WorkAreaState); }
// Done! private bool ShouldDraw(VisualMapNode vmn, bool toImage) { return(vmn.IsVisible == false || (toImage == false && IsInsideWorkArea(vmn) == false)); }