Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/3.2/CompositeShape.cs @ 1559

Last change on this file since 1559 was 1559, checked in by dwagner, 15 years ago

Added functionality: Markers on every datapoint. (#581)

File size: 1.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4
5namespace HeuristicLab.Visualization {
6  public class CompositeShape : IShape {
7    private IShape parent;
8    private bool showChildShapes = true;
9
10    protected readonly List<IShape> shapes = new List<IShape>();
11    protected RectangleD boundingBox = RectangleD.Empty;
12
13
14
15    public virtual void Draw(Graphics graphics) {
16      if(!showChildShapes)
17        return;
18      foreach (IShape shape in shapes) {
19        shape.Draw(graphics);
20      }
21    }
22
23    public RectangleD BoundingBox {
24      get {
25        if (shapes.Count == 0) {
26          throw new InvalidOperationException("No shapes, no bounding box.");
27        }
28
29        return boundingBox;
30      }
31    }
32
33    public RectangleD ClippingArea {
34      get { return Parent.ClippingArea; }
35    }
36
37    public Rectangle Viewport {
38      get { return Parent.Viewport; }
39    }
40
41    public IShape Parent {
42      get { return parent; }
43      set { parent = value; }
44    }
45
46    public bool ShowChildShapes {
47      get { return showChildShapes; }
48      set { showChildShapes = value; }
49    }
50
51    public void ClearShapes() {
52      shapes.Clear();
53      boundingBox = RectangleD.Empty;
54    }
55
56    public IShape GetShape(int index) {
57      return shapes[index];
58    }
59
60    public void AddShape(IShape shape) {
61      shape.Parent = this;
62
63      if (shapes.Count == 0) {
64        boundingBox = shape.BoundingBox;
65      } else {
66        boundingBox = new RectangleD(Math.Min(boundingBox.X1, shape.BoundingBox.X1),
67                                     Math.Min(boundingBox.Y1, shape.BoundingBox.Y1),
68                                     Math.Max(boundingBox.X2, shape.BoundingBox.X2),
69                                     Math.Max(boundingBox.Y2, shape.BoundingBox.Y2));
70      }
71      shapes.Add(shape);
72    }
73  }
74}
Note: See TracBrowser for help on using the repository browser.