private bool cached = false; // at least 1 axis has been cached /// <summary> /// Cache the current axes /// </summary> public void CacheAxes() { if (!cached) { if (XAxis1 != null) { xAxis1Cache = (Axis)XAxis1.Clone(); cached = true; } if (XAxis2 != null) { xAxis2Cache = (Axis)XAxis2.Clone(); cached = true; } if (YAxis1 != null) { yAxis1Cache = (Axis)YAxis1.Clone(); cached = true; } if (YAxis2 != null) { yAxis2Cache = (Axis)YAxis2.Clone(); cached = true; } } }
void DetermineAxesToDraw(out Axis xAxis_1, out Axis xAxis_2, out Axis yAxis_1, out Axis yAxis_2) { xAxis_1 = XAxis1; xAxis_2 = XAxis2; yAxis_1 = YAxis1; yAxis_2 = YAxis2; if (XAxis1 == null) { if (XAxis2 == null) { throw new XwPlotException("Error: No X-Axis specified"); } xAxis_1 = (Axis)XAxis2.Clone(); xAxis_1.HideTickText = true; xAxis_1.TicksAngle = -Math.PI / 2; } if (XAxis2 == null) { // don't need to check if XAxis1 == null, as case already handled above. xAxis_2 = (Axis)XAxis1.Clone(); xAxis_2.HideTickText = true; xAxis_2.TicksAngle = Math.PI / 2.0; } if (YAxis1 == null) { if (YAxis2 == null) { throw new XwPlotException("Error: No Y-Axis specified"); } yAxis_1 = (Axis)YAxis2.Clone(); yAxis_1.HideTickText = true; yAxis_1.TicksAngle = Math.PI / 2.0; } if (YAxis2 == null) { // don't need to check if YAxis1 == null, as case already handled above. yAxis_2 = (Axis)YAxis1.Clone(); yAxis_2.HideTickText = true; yAxis_2.TicksAngle = -Math.PI / 2.0; } }
protected override void OnMouseUp(MouseEventArgs e) { if (e.Button == MouseButtons.Left && allowSelection_) { endPoint_.X = e.X; endPoint_.Y = e.Y; // terminate mouse action mouseActionInitiated_ = false; if (endPoint_ != unset_) { DrawRubberBand(startPoint_, endPoint_); } Point minPoint = new Point(0, 0); minPoint.X = Math.Min(startPoint_.X, endPoint_.X); minPoint.Y = Math.Min(startPoint_.Y, endPoint_.Y); Point maxPoint = new Point(0, 0); maxPoint.X = Math.Max(startPoint_.X, endPoint_.X); maxPoint.Y = Math.Max(startPoint_.Y, endPoint_.Y); Rectangle r = ps_.PlotAreaBoundingBoxCache; if (minPoint != maxPoint && (r.Contains(minPoint) || r.Contains(maxPoint))) { if (xAxis1Cache_ == null) { xAxis1Cache_ = (Axis)XAxis1.Clone(); xAxis2Cache_ = (Axis)XAxis2.Clone(); yAxis1Cache_ = (Axis)YAxis1.Clone(); yAxis2Cache_ = (Axis)YAxis2.Clone(); } // TODO: these bugger up if min/max point reversed. // think this implies can't have axes directed wrong way. // check out later. // middle wheel will be controlling zoom in future. left mouse may // be drag => stack zoom out not long term solution, so just make // zoom out go right out at this stage. if (XAxis1 != null) { double tempMin = PhysicalXAxis1Cache.PhysicalToWorld(minPoint, true); XAxis1.WorldMax = PhysicalXAxis1Cache.PhysicalToWorld(maxPoint, true); XAxis1.WorldMin = tempMin; } if (XAxis2 != null) { double tempMin = PhysicalXAxis2Cache.PhysicalToWorld(minPoint, true); XAxis2.WorldMax = PhysicalXAxis2Cache.PhysicalToWorld(maxPoint, true); XAxis2.WorldMin = tempMin; } if (YAxis1 != null) { double tempMin = PhysicalYAxis1Cache.PhysicalToWorld(maxPoint, true); YAxis1.WorldMax = PhysicalYAxis1Cache.PhysicalToWorld(minPoint, true); YAxis1.WorldMin = tempMin; } if (YAxis2 != null) { double tempMin = PhysicalYAxis2Cache.PhysicalToWorld(maxPoint, true); YAxis2.WorldMax = PhysicalYAxis2Cache.PhysicalToWorld(minPoint, true); YAxis2.WorldMin = tempMin; } // reset the start/end points startPoint_ = unset_; endPoint_ = unset_; Refresh(); } } else if (e.Button == MouseButtons.Right) { if (xAxis1Cache_ != null) { XAxis1 = xAxis1Cache_; XAxis2 = xAxis2Cache_; YAxis1 = yAxis1Cache_; YAxis2 = yAxis2Cache_; xAxis1Cache_ = null; xAxis2Cache_ = null; yAxis1Cache_ = null; yAxis2Cache_ = null; } Refresh(); } // don't fail to call the base method! base.OnMouseUp(e); }