// 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); }