I have strange problem with coordinates transformation. Why after axis changing all transformation of old coordinates for example
"rectangle.MaximumX = XAxis.InverseTransform(XAxis.Transform(this.MyMemento._rectangle.MaximumX));"
Is NaN? Without axis changing all is ok.
namespace OxyRectangle
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new RectangleScale();
}
}
public class RectangleScale
{
public PlotModel PlotModel { get; set; }
RectangleAnnotation Rectum;
private LinearAxis XAxis;
private LinearAxis YAxis;
public Memento MyMemento { get; set; }
public RectangleScale()
{
PlotModel = new PlotModel();
XAxis = new LinearAxis
{
Position = AxisPosition.Bottom
};
YAxis = new LinearAxis
{
Position= AxisPosition.Left,
IsPanEnabled=false
};
Rectum = new RectangleAnnotation();
SetRectum(Rectum, 1, 1, 10, 10);
MyMemento = new Memento(Rectum);
PlotModel.Axes.Add(XAxis);
PlotModel.Axes.Add(YAxis);
PlotModel.Annotations.Add(Rectum);
ChangeAxis(PlotModel, 100, 200);
ConvertOldRectangle(Rectum);
PlotModel.InvalidatePlot(true);
}
public void SetRectum(RectangleAnnotation rectangle, double xmin, double ymin, double xmax, double ymax)
{
rectangle.MinimumX = xmin;
rectangle.MinimumY = ymin;
rectangle.MaximumX = xmax;
rectangle.MaximumY = ymax;
}
public void ChangeAxis(PlotModel _plotmodel,int minimum,int maximum)
{
_plotmodel.Axes.Clear();
LinearAxis XAxis = new LinearAxis
{
Position = AxisPosition.Bottom,
Minimum=minimum,
Maximum=maximum
};
LinearAxis YAxis = new LinearAxis
{
Position = AxisPosition.Left,
Minimum=minimum,
Maximum=maximum,
IsPanEnabled = false
};
_plotmodel.Axes.Add(XAxis);
_plotmodel.Axes.Add(YAxis);
_plotmodel.InvalidatePlot(true);
}
public void ConvertOldRectangle(RectangleAnnotation _rectangle)
{
_rectangle.MaximumX = XAxis.InverseTransform(XAxis.Transform(this.MyMemento._rectangle.MaximumX));
_rectangle.MinimumX = XAxis.InverseTransform(XAxis.Transform(this.MyMemento._rectangle.MinimumX));
_rectangle.MaximumY = YAxis.InverseTransform(XAxis.Transform(this.MyMemento._rectangle.MaximumY));
_rectangle.MinimumY = YAxis.InverseTransform(XAxis.Transform(this.MyMemento._rectangle.MinimumY));
}
public void Revert()
{
Rectum = this.MyMemento._rectangle;
}
}
public class Memento
{
public readonly RectangleAnnotation _rectangle;
public Memento(RectangleAnnotation rectangle)
{
_rectangle = rectangle;
}
}
}