Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
namespace OxyRectangle
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    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;
        }
    }
}
Posted
Updated 18-Jun-15 22:43pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900