private loItem GetVisual(double x, double y) { List <loItem> objs = new List <loItem>(); GeometryHitTestParameters parameters = new GeometryHitTestParameters(new RectangleGeometry(new Rect(x - CELL_SIZE / 4, y - CELL_SIZE / 4, CELL_SIZE / 2, CELL_SIZE / 2))); VisualTreeHelper.HitTest(this, null, new HitTestResultCallback((hr) => { var rez = (GeometryHitTestResult)hr; var vis = hr.VisualHit as loItem; if (vis != null) { objs.Add(vis); } return(HitTestResultBehavior.Continue); }), parameters); loItem ret = null; if (objs.Count > 0) { ret = objs.FirstOrDefault(z => z is loPin); if (ret == null) { ret = objs.FirstOrDefault(z => z is loBinding); if (ret == null) { ret = objs.FirstOrDefault(z => z is loElement); } } } return(ret); }
private void MapRemove(loItem val) { lock (_map) { foreach (var i in _map.Where(z => z.Value == val).ToArray()) { _map.Remove(i.Key); } } }
private void DeleteLI(loItem el) { loBinding b = el as loBinding; DTopic t; if (b != null && (t = b.Output.GetModel()) != null) { t.SetField("cctor.LoBind", null); } else if ((t = el.GetModel()) != null && (t.Manifest == null || (JsLib.OfInt(t.Manifest, "attr", 0) & 1) != 1)) { t.Delete(); } }
/// <summary></summary> /// <param name="dir">0 - X+, 1 - Y-, 2 - Y+, 3 - X-</param> /// <param name="x">X</param> /// <param name="y">Y</param> /// <param name="val">item</param> private void MapSet(int dir, int x, int y, loItem val) { uint idx = (uint)(((y & 0x7FFF) << 17) | ((x & 0x7FFF) << 2) | (dir & 0x03)); lock (_map) { if (val == null) { _map.Remove(idx); } else { _map[idx] = val; } } }
public ObservableCollection <Control> MenuItems(DTopic t, loItem ctrl) { var l = new ObservableCollection <Control>(); JSC.JSValue v1; MenuItem mi; mi = new MenuItem() { Header = "Open in new tab", Tag = t }; mi.Click += miOpen_Click; l.Add(mi); mi = new MenuItem() { Header = "Show in Workspace", Tag = t }; mi.Click += miShow_Click; l.Add(mi); l.Add(new Separator()); if (ctrl is loPin) { bool ic = JsLib.ofBool(JsLib.GetField(t.Manifest, "Logram.trace"), false); mi = new MenuItem() { Header = "Trace", Tag = t, IsCheckable = true, IsChecked = ic }; mi.Click += miTrace_Click; l.Add(mi); l.Add(new Separator()); } if (t.Manifest != null && (v1 = t.Manifest["Children"]).ValueType == JSC.JSValueType.Object) { var ad = new Dictionary <string, JSC.JSValue>(); Jso2Acts(v1, ad); FillContextMenu(t, l, ad); } else if (t.Manifest != null && (v1 = t.Manifest["Children"]).ValueType == JSC.JSValueType.String) { t.GetAsync(v1.Value as string).ContinueWith(tt => FillContextMenuFromChildren(t, l, tt), TaskScheduler.FromCurrentSynchronizationContext()); } else { t.Connection.CoreTypes.GetAsync(null).ContinueWith(tt => FillContextMenuFromChildren(t, l, tt), TaskScheduler.FromCurrentSynchronizationContext()); } return(l); }
private void FindPath(List <Point> track) { PriorityQueue <PathFinderNode> mOpen = new PriorityQueue <PathFinderNode>(new ComparePFNode()); List <PathFinderNode> mClose = new List <PathFinderNode>(); int mSearchLimit = 3000; PathFinderNode parentNode; bool found = false; int startX = (int)(this.Input.Offset.X / CELL_SIZE + 0.5); int startY = (int)(this.Input.Offset.Y / CELL_SIZE + 0.5); int finishX = (int)(this.Output.Offset.X / CELL_SIZE + 0.5); int finishY = (int)(this.Output.Offset.Y / CELL_SIZE + 0.5); mOpen.Clear(); mClose.Clear(); parentNode.G = 0; parentNode.H = 1; parentNode.F = parentNode.G + parentNode.H; parentNode.X = startX; parentNode.Y = startY; parentNode.PX = startX - 1; parentNode.PY = startY; mOpen.Push(parentNode); while (mOpen.Count > 0) { parentNode = mOpen.Pop(); if (parentNode.X == finishX && parentNode.Y == finishY) { mClose.Add(parentNode); found = true; break; } if (mClose.Count > mSearchLimit) { return; } //Lets calculate each successors for (int i = 0; i < 4; i++) { PathFinderNode newNode; newNode.PX = parentNode.X; newNode.PY = parentNode.Y; newNode.X = parentNode.X + direction[i, 0]; newNode.Y = parentNode.Y + direction[i, 1]; int newG = this.GetWeigt(newNode.X, newNode.Y, i); if (newG > 100) { continue; } newG = Math.Max(newG, this.GetWeigt(newNode.PX, newNode.PY, direction[i, 2])); if (newG > 100) { continue; } newG += parentNode.G; // Дополнительная стоимиость поворотов if (Math.Abs(newNode.Y - parentNode.PY) == 1 || Math.Abs(newNode.X - parentNode.PX) == 1) { if (this.GetWeigt(parentNode.X, parentNode.Y, i) > 100) { continue; } newG += 8; } int foundInOpenIndex = -1; for (int j = 0; j < mOpen.Count; j++) { if (mOpen[j].X == newNode.X && mOpen[j].Y == newNode.Y) { foundInOpenIndex = j; break; } } if (foundInOpenIndex != -1 && mOpen[foundInOpenIndex].G <= newG) { continue; } int foundInCloseIndex = -1; for (int j = 0; j < mClose.Count; j++) { if (mClose[j].X == newNode.X && mClose[j].Y == newNode.Y) { foundInCloseIndex = j; break; } } if (foundInCloseIndex != -1 && mClose[foundInCloseIndex].G <= newG) { continue; } newNode.G = newG; newNode.H = 2 + Math.Sign(Math.Abs(newNode.X - finishX) + Math.Abs(newNode.Y - finishY) - Math.Abs(newNode.PX - finishX) - Math.Abs(newNode.PY - finishY)); newNode.F = newNode.G + newNode.H; mOpen.Push(newNode); } mClose.Add(parentNode); } if (found) { loItem pIt = null, cIt; track.Clear(); PathFinderNode fNode = mClose[mClose.Count - 1]; track.Add(new Point(finishX * CELL_SIZE, finishY * CELL_SIZE)); for (int i = mClose.Count - 1; i >= 0; i--) { if (fNode.PX == mClose[i].X && fNode.PY == mClose[i].Y || i == mClose.Count - 1) { fNode = mClose[i]; int dir = CalcDir(fNode.PX, fNode.X, fNode.PY, fNode.Y); int ndir = direction[dir, 2]; if ((lv.MapGet(ndir, fNode.PX, fNode.PY)) == null) { lv.MapSet(ndir, fNode.PX, fNode.PY, this); } if ((cIt = lv.MapGet(dir, fNode.X, fNode.Y)) == null) { lv.MapSet(dir, fNode.X, fNode.Y, this); } else { if (cIt == this || cIt == this.Input || cIt == this.Output) { cIt = null; } } if (i > 0 && i < mClose.Count - 1 && cIt != pIt) { track.Insert(0, new Point(fNode.X * CELL_SIZE, fNode.Y * CELL_SIZE)); track.Insert(0, new Point(fNode.X * CELL_SIZE, fNode.Y * CELL_SIZE)); //Log.Info("{0}: {1}; {2}, {3} - {4}; {5}, {6}", this.ToString(), pIt, fNode.X, fNode.Y, cIt, fNode.PX, fNode.PY); } else if (!EqD(track[0].X, fNode.PX * CELL_SIZE) && !EqD(track[0].Y, fNode.PY * CELL_SIZE)) { track.Insert(0, new Point(fNode.X * CELL_SIZE, fNode.Y * CELL_SIZE)); } //Log.Info("{0}: {1}; {2}, {3} - {4}; {5}, {6}", this.ToString(), pIt, fNode.X, fNode.Y, cIt, fNode.PX, fNode.PY); pIt = cIt; } } if (!EqD(track[0].X, startX * CELL_SIZE) || !EqD(track[0].Y, startY * CELL_SIZE)) { track.Insert(0, new Point(startX * CELL_SIZE, startY * CELL_SIZE)); } _mapped = true; } // Visu //using(DrawingContext dc = this.RenderOpen()) { // for(int i = 0; i < mClose.Count; i++) { // FormattedText txt = new FormattedText(mClose[i].G.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, LFont, CELL_SIZE * 0.3, Brushes.Violet); // dc.DrawText(txt, new Point(mClose[i].X * CELL_SIZE, mClose[i].Y * CELL_SIZE + CELL_SIZE / 2)); // dc.DrawLine(new Pen(Brushes.RosyBrown, 1), new Point(mClose[i].X * CELL_SIZE, CELL_SIZE + mClose[i].Y * CELL_SIZE), new Point(mClose[i].PX * CELL_SIZE, CELL_SIZE + mClose[i].PY * CELL_SIZE)); // } // for(int i = 0; i < _track.Count - 1; i++) { // dc.DrawLine(SelectionPen, _track[i], _track[i + 1]); // } //} }