Exemplo n.º 1
0
        public Geometry.Box BoxFromZoomBox(ZoomBox zoomBox)
        {
            // fragment of the window in window coordinates
            double w      = dst_orig_w;
            double h      = dst_orig_h;
            double zw     = zoomBox.Dim(0);
            double zh     = zoomBox.Dim(1);
            double zmin_x = (zoomBox.Min[0] + zw * viewFix) * w;
            double zmin_y = h - (zoomBox.Min[1] + zh * viewFix) * h;
            double zmax_x = (zoomBox.Max[0] - zw * viewFix) * w;
            double zmax_y = h - (zoomBox.Max[1] - zw * viewFix) * h;
            // convert to box coordinates
            double min_x = InverseConvertX(zmin_x);
            double min_y = InverseConvertY(zmin_y);
            double max_x = InverseConvertX(zmax_x);
            double max_y = InverseConvertY(zmax_y);

            return(new Geometry.Box(new Geometry.Point(min_x, min_y),
                                    new Geometry.Point(max_x, max_y)));
        }
Exemplo n.º 2
0
 // For PlotWatch
 public static Geometry.Box DrawPlots(Graphics graphics,
                                      IDrawable[] drawables, Geometry.Traits[] traits,
                                      Settings[] settings, Colors colors, ZoomBox zoomBox)
 {
     return(Draw(graphics, true, drawables, traits, settings, colors, zoomBox));
 }
Exemplo n.º 3
0
        // For GeometryWatch and PlotWatch
        static Geometry.Box Draw(Graphics graphics, bool ignoreTraits,
                                 IDrawable[] drawables, Geometry.Traits[] traits,
                                 Settings[] settings, Colors colors, ZoomBox zoomBox)
        {
            if (drawables.Length != traits.Length || drawables.Length != settings.Length)
            {
                throw new ArgumentOutOfRangeException("drawables.Length, traits.Length, settings.Length");
            }

            Geometry.Box box = new Geometry.Box();
            Geometry.AssignInverse(box);

            int drawnCount = 0;
            int count      = drawables.Length;

            bool[] drawnFlags = new bool[count];

            HashSet <int> dimensions = new HashSet <int>();
            HashSet <Geometry.CoordinateSystem> csystems = new HashSet <Geometry.CoordinateSystem>();
            HashSet <Geometry.Unit>             units    = new HashSet <Geometry.Unit>();

            for (int i = 0; i < count; ++i)
            {
                if (ignoreTraits)
                {
                    traits[i] = null;
                }

                if (drawables[i] != null)
                {
                    if (traits[i] != null)
                    {
                        dimensions.Add(traits[i].Dimension);
                        csystems.Add(traits[i].CoordinateSystem);
                        units.Add(traits[i].Unit);
                    }

                    Geometry.Box aabb = drawables[i].Aabb(traits[i], false);
                    Geometry.Expand(box, aabb);

                    ++drawnCount;
                    drawnFlags[i] = aabb.IsValid();
                }
            }

            if (drawnCount > 0)
            {
                if (csystems.Count > 1)
                {
                    throw new Exception("Multiple coordinate systems detected.");
                }
                if (csystems.Count > 0 && csystems.First() == Geometry.CoordinateSystem.SphericalPolar)
                {
                    throw new Exception("This coordinate system is not yet supported.");
                }
                if (units.Count > 1)
                {
                    throw new Exception("Multiple units detected.");
                }

                Geometry.Traits commonTraits = (dimensions.Count > 0 && csystems.Count > 0 && units.Count > 0)
                                                ? new Geometry.Traits(dimensions.Max(), csystems.First(), units.First())
                                                : null;

                bool fill = (commonTraits == null);

                // Fragment of the box
                if (box.IsValid() && zoomBox.IsZoomed())
                {
                    // window coordinates of the box
                    LocalCS cs = new LocalCS(box, graphics, fill);
                    box = cs.BoxFromZoomBox(zoomBox);

                    // TODO: With current approach changing the original box (resize, enlarge, etc.)
                    // may produce wierd results because zoomBox is relative to the original box.
                }

                // Axes
                if (box.IsValid())
                {
                    Geometry.Unit unit = commonTraits != null ? commonTraits.Unit : Geometry.Unit.None;
                    Drawer.DrawAxes(graphics, box, unit, colors, fill);
                }

                // Drawables
                for (int i = 0; i < count; ++i)
                {
                    if (drawables[i] != null && drawnFlags[i] == true)
                    {
                        drawables[i].Draw(box, graphics, settings[i], commonTraits);
                    }
                }

                // Scales
                if (box.IsValid())
                {
                    Drawer.DrawScales(graphics, box, colors, fill);
                }

                // CS info
                if (commonTraits != null)
                {
                    SolidBrush brush = new SolidBrush(colors.TextColor);
                    Font       font  = new Font(new FontFamily(System.Drawing.Text.GenericFontFamilies.SansSerif), 10);
                    string     str   = Geometry.Name(csystems.First());
                    if (units.First() != Geometry.Unit.None)
                    {
                        str += '[' + Geometry.Name(units.First()) + ']';
                    }
                    graphics.DrawString(str, font, brush, 0, 0);
                }

                return(box);
            }

            return(null);
        }