public void UpdateNoodlePath(NoodleStyle style, object helper) { if (path != null) { path.Dispose(); } path = new GraphicsPath(); //recalculate the two points relative to the parent container //and adjust for scrollbar positions if (_outputPin.ParentNode != null) { if (_outputPin.ParentUIGraph != null) { _outputPoint = (_outputPin.ParentUIGraph as DaggerUIGraph).PointToClient((_outputPin.ParentNode.UINode as DaggerUINode).PointToScreen((_outputPin.PinUIElements as PinUI).PinLocation)); _outputPoint.X += (_outputPin.ParentNode.UINode.PinSize / 2) - (_outputPin.ParentUIGraph as DaggerUIGraph).AutoScrollPosition.X; _outputPoint.Y += (_outputPin.ParentNode.UINode.PinSize / 2) - (_outputPin.ParentUIGraph as DaggerUIGraph).AutoScrollPosition.Y; } } else { //it's an imported pin _outputPoint = (_outputPin.PinUIElements as PinUI).PinLocation; if (_outputPin.ParentUIGraph != null) { _outputPoint.X += (_outputPin.ParentUIGraph.PinSize / 2); _outputPoint.Y += (_outputPin.ParentUIGraph.PinSize / 2); } } if (_inputPin.ParentNode != null) { if (_inputPin.ParentUIGraph != null) { _inputPoint = (_inputPin.ParentUIGraph as DaggerUIGraph).PointToClient((_inputPin.ParentNode.UINode as DaggerUINode).PointToScreen((_inputPin.PinUIElements as PinUI).PinLocation)); _inputPoint.X += (_inputPin.ParentNode.UINode.PinSize / 2) - (_inputPin.ParentUIGraph as DaggerUIGraph).AutoScrollPosition.X; _inputPoint.Y += (_inputPin.ParentNode.UINode.PinSize / 2) - (_inputPin.ParentUIGraph as DaggerUIGraph).AutoScrollPosition.Y; } } else { //it's an exported pin _inputPoint = (_inputPin.PinUIElements as PinUI).PinLocation; if (_inputPin.ParentUIGraph != null) { _inputPoint.X += (_inputPin.ParentUIGraph.PinSize / 2); _inputPoint.Y += (_inputPin.ParentUIGraph.PinSize / 2); } } switch (style) { case NoodleStyle.Bezier: _bezierStyle(); break; case NoodleStyle.Lines: _lineStyle(); break; case NoodleStyle.CircuitBoardFine: case NoodleStyle.CircuitBoardCoarse: { AstarHelper bshelper = (AstarHelper)helper; path.AddLines(_pathFinder(bshelper.grid, bshelper.pathCost, bshelper.grain).ToArray()); } break; case NoodleStyle.Ramen: { AstarHelper bshelper = (AstarHelper)helper; path.AddCurve(_pathFinder(bshelper.grid, bshelper.pathCost, bshelper.grain).ToArray(), 0.75f); path.Flatten(); } break; case NoodleStyle.BendyStraws: { AstarHelper bshelper = (AstarHelper)helper; // traverse the points of the pathfinder and create 90 degree ellipses List <Point> points = _pathFinder(bshelper.grid, bshelper.pathCost, bshelper.grain); int pcount = 0; Point lastpoint = points[0]; while (pcount < points.Count - 2) { float yi = 0, xi = 0; float m1 = _slope(lastpoint, points[pcount + 1], ref yi, ref xi); float m2 = _slope(points[pcount + 1], points[pcount + 2], ref yi, ref xi); if (m1 != m2) { // an angle // get the mid point of seg2 and create bezier curve Point mpoint = (m2 == 0) ? _hmidPoint(points[pcount + 1], points[pcount + 2]) : _vmidPoint(points[pcount + 1], points[pcount + 2]); path.AddBezier(lastpoint, points[pcount + 1], points[pcount + 1], mpoint); lastpoint = mpoint; pcount++; } else { // strait line pcount++; } } // add the last line path.AddLine(lastpoint, points[points.Count - 1]); path.Flatten(); } break; default: break; } }
public void UpdateNoodles() { if (_updateRef == 0) { switch (_style) { case NoodleStyle.Default: case NoodleStyle.Bezier: { foreach (DaggerNoodle noodle in _noodles) { noodle.UpdateNoodlePath(NoodleStyle.Bezier, null); } } break; case NoodleStyle.Lines: { foreach (DaggerNoodle noodle in _noodles) { noodle.UpdateNoodlePath(NoodleStyle.Lines, null); } } break; case NoodleStyle.CircuitBoardCoarse: { // create the helper AstarHelper helper = new AstarHelper(); helper.grain = 24; helper.pathCost = 100; helper.diagonalCost = 50; // create the AStar path finder helper.grid = _createPathGrid(_uigraph, helper.grain, helper.diagonalCost); if (helper.grid == null) { return; } foreach (DaggerNoodle noodle in _noodles) { noodle.UpdateNoodlePath(NoodleStyle.CircuitBoardCoarse, helper); helper.grid.Reset(); } } break; case NoodleStyle.CircuitBoardFine: { // create the helper AstarHelper helper = new AstarHelper(); helper.grain = 16; helper.pathCost = 100; helper.diagonalCost = 20; // create the AStar path finder helper.grid = _createPathGrid(_uigraph, helper.grain, helper.diagonalCost); if (helper.grid == null) { return; } foreach (DaggerNoodle noodle in _noodles) { noodle.UpdateNoodlePath(NoodleStyle.CircuitBoardFine, helper); helper.grid.Reset(); } } break; case NoodleStyle.Ramen: { // create the helper AstarHelper helper = new AstarHelper(); helper.grain = 16; helper.pathCost = 100; helper.diagonalCost = 20; // create the AStar path finder helper.grid = _createPathGrid(_uigraph, helper.grain, helper.diagonalCost); if (helper.grid == null) { return; } foreach (DaggerNoodle noodle in _noodles) { noodle.UpdateNoodlePath(NoodleStyle.Ramen, helper); helper.grid.Reset(); } } break; case NoodleStyle.BendyStraws: { // create the helper AstarHelper helper = new AstarHelper(); helper.grain = 16; helper.pathCost = 200; helper.diagonalCost = 100; // create the AStar path finder helper.grid = _createPathGrid(_uigraph, helper.grain, helper.diagonalCost); if (helper.grid == null) { return; } foreach (DaggerNoodle noodle in _noodles) { noodle.UpdateNoodlePath(NoodleStyle.BendyStraws, helper); helper.grid.Reset(); } } break; default: break; } } }