Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13045


Ignore:
Timestamp:
10/21/15 14:18:31 (8 years ago)
Author:
jkarder
Message:

#1265: merged changes from abeham

Location:
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3
Files:
8 added
2 deleted
27 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Chart.cs

    r12535 r13045  
    2323using System.Collections.Generic;
    2424using System.Drawing;
    25 using System.Linq;
    2625using System.Windows.Forms;
    2726
     
    3029    private PointD originalLowerLeft;
    3130    private PointD originalUpperRight;
    32     private List<Offset> zoomHistory;
    33 
    34     private ChartMode myMode;
    35     public virtual ChartMode Mode {
    36       get { return myMode; }
     31    protected List<Offset> zoomHistory;
     32
     33    private bool enabled;
     34    public bool Enabled {
     35      get { return enabled; }
    3736      set {
    38         myMode = value;
    39         OnUpdate();
    40       }
    41     }
     37        if (enabled == value) return;
     38        enabled = value;
     39        OnRedrawRequired();
     40      }
     41    }
     42
     43    protected bool SuppressRedraw { get; set; }
     44
     45    public bool SuppressEvents { get; set; }
    4246
    4347    private PointD myLowerLeft;
     
    5357    }
    5458    private Size mySizeInPixels;
     59
    5560    public Size SizeInPixels {
    5661      get { return mySizeInPixels; }
     
    6267      get { return new SizeD(SizeInPixels.Width / Size.Width, SizeInPixels.Height / Size.Height); }
    6368    }
    64 
    65     private IGroup myGroup;
    66     public IGroup Group {
    67       get { return myGroup; }
    68     }
    69 
    70     private bool myUpdateEnabled;
    71     public bool UpdateEnabled {
    72       get { return myUpdateEnabled; }
    73       set { myUpdateEnabled = value; }
    74     }
     69    public double Scale { get; set; }
     70    public double MinimumZoomDistance { get; set; }
     71    public IGroup Group { get; protected set; }
    7572
    7673    public Chart(PointD lowerLeft, PointD upperRight) {
    77       myUpdateEnabled = false;
    7874      zoomHistory = new List<Offset>();
    79       myMode = ChartMode.Move;
    8075      SetPosition(lowerLeft, upperRight);
    81       mySizeInPixels = new Size(100, 100);
    82       myGroup = new Group(this);
    83       Group.Update += new EventHandler(Group_Update);
    84       myUpdateEnabled = true;
    85     }
     76      mySizeInPixels = new Size((int)Size.Width, (int)Size.Height);
     77      Scale = 1.0;
     78      Group = new Group(this);
     79      Group.RedrawRequired += GroupOnRedrawRequired;
     80      MinimumZoomDistance = 0.01;
     81    }
     82
    8683    public Chart(double x1, double y1, double x2, double y2)
    87       : this(new PointD(x1, y1), new PointD(x2, y2)) {
    88     }
     84      : this(new PointD(x1, y1), new PointD(x2, y2)) { }
    8985
    9086    public PointD TransformPixelToWorld(Point point) {
    91       double x = LowerLeft.X + point.X * PixelToWorldRatio.Width;
    92       double y = LowerLeft.Y + (SizeInPixels.Height - point.Y) * PixelToWorldRatio.Height;
     87      var x = LowerLeft.X + point.X * PixelToWorldRatio.Width;
     88      var y = LowerLeft.Y + (SizeInPixels.Height - point.Y) * PixelToWorldRatio.Height;
    9389      return new PointD(x, y);
    9490    }
     91
    9592    public SizeD TransformPixelToWorld(Size size) {
    96       double width = size.Width * PixelToWorldRatio.Width;
    97       double height = size.Height * PixelToWorldRatio.Height;
     93      var width = size.Width * PixelToWorldRatio.Width;
     94      var height = size.Height * PixelToWorldRatio.Height;
    9895      return new SizeD(width, height);
    9996    }
     97
    10098    public Point TransformWorldToPixel(PointD point) {
    101       int x = (int)((point.X - LowerLeft.X) * WorldToPixelRatio.Width);
    102       int y = (int)((UpperRight.Y - point.Y) * WorldToPixelRatio.Height);
     99      var x = (int)((point.X - LowerLeft.X) * WorldToPixelRatio.Width);
     100      var y = (int)((UpperRight.Y - point.Y) * WorldToPixelRatio.Height);
    103101      return new Point(x, y);
    104102    }
     103
    105104    public Size TransformWorldToPixel(SizeD size) {
    106       int width = (int)(size.Width * WorldToPixelRatio.Width);
    107       int height = (int)(size.Height * WorldToPixelRatio.Height);
     105      var width = (int)(size.Width * WorldToPixelRatio.Width);
     106      var height = (int)(size.Height * WorldToPixelRatio.Height);
    108107      return new Size(width, height);
    109108    }
     
    118117      myLowerLeft = lowerLeft;
    119118      myUpperRight = upperRight;
    120       OnUpdate();
    121     }
    122     public void SetPosition(double x1, double y1, double x2, double y2) {
    123       SetPosition(new PointD(x1, y1), new PointD(x2, y2));
    124     }
     119      OnRedrawRequired();
     120    }
     121
    125122    public virtual void Move(Offset delta) {
    126123      myLowerLeft += delta;
    127124      myUpperRight += delta;
    128       OnUpdate();
    129     }
    130     public void Move(double dx, double dy) {
    131       Move(new Offset(dx, dy));
     125      OnRedrawRequired();
     126    }
     127
     128    public virtual void Zoom(Point mousePosition, double delta) {
     129      var cursor = TransformPixelToWorld(mousePosition);
     130
     131      double zoomLevel = (100 + delta) / 100;
     132      double width = this.UpperRight.X - this.LowerLeft.X;
     133      double height = this.UpperRight.Y - this.LowerLeft.Y;
     134      double newWidth = width * zoomLevel;
     135      double newHeight = height * zoomLevel;
     136      double xAdaption = (UpperRight.X - cursor.X) / width;
     137      double yAdaption = (UpperRight.Y - cursor.Y) / height;
     138
     139      ZoomIn(new PointD(cursor.X - newWidth * (1 - xAdaption), cursor.Y - newHeight * (1 - yAdaption)), new PointD(cursor.X + newWidth * xAdaption, cursor.Y + newHeight * yAdaption));
     140      OnRedrawRequired();
     141    }
     142
     143    public virtual void ZoomIn(Point mousePosition) {
     144      Zoom(mousePosition, -10);
    132145    }
    133146
    134147    public virtual void ZoomIn(PointD lowerLeft, PointD upperRight) {
     148      // maintain a 1:1 ratio between x and y axis
     149      var pixels = SizeInPixels;
     150      var diagonal = upperRight - lowerLeft;
     151      var windowRatio = pixels.Height / (double)pixels.Width;
     152      var viewRatio = diagonal.DY / diagonal.DX;
     153      if (viewRatio < windowRatio) {
     154        var neededHeight = windowRatio * diagonal.DX;
     155        var diff = (neededHeight - diagonal.DY) / 2.0;
     156        lowerLeft.Y -= diff;
     157        upperRight.Y += diff;
     158      } else {
     159        var neededWidth = diagonal.DY / windowRatio;
     160        var diff = (neededWidth - diagonal.DX) / 2.0;
     161        lowerLeft.X -= diff;
     162        upperRight.X += diff;
     163      }
     164      if ((lowerLeft - upperRight).Length < MinimumZoomDistance) return;
    135165      zoomHistory.Insert(0, LowerLeft - lowerLeft);
    136166      zoomHistory.Insert(0, UpperRight - upperRight);
    137167      myLowerLeft = lowerLeft;
    138168      myUpperRight = upperRight;
    139       OnUpdate();
    140     }
    141     public void ZoomIn(double x1, double y1, double x2, double y2) {
    142       ZoomIn(new PointD(x1, y1), new PointD(x2, y2));
    143     }
     169      OnRedrawRequired();
     170    }
     171
    144172    public virtual void ZoomIn(Point lowerLeft, Point upperRight) {
    145173      ZoomIn(TransformPixelToWorld(lowerLeft), TransformPixelToWorld(upperRight));
    146174    }
    147     public void ZoomIn(int x1, int y1, int x2, int y2) {
    148       ZoomIn(new Point(x1, y1), new Point(x2, y2));
    149     }
     175
    150176    public virtual void ZoomOut() {
    151177      if (zoomHistory.Count > 0) {
     
    156182        myLowerLeft = LowerLeft + lowerLeft;
    157183        myUpperRight = UpperRight + upperRight;
    158         OnUpdate();
     184        OnRedrawRequired();
    159185      } else {
    160         myLowerLeft.X -= Size.Width / 4;
    161         myLowerLeft.Y -= Size.Height / 4;
    162         myUpperRight.X += Size.Width / 4;
    163         myUpperRight.Y += Size.Height / 4;
    164         OnUpdate();
    165       }
    166     }
     186        var lowerLeft = new PointD(myLowerLeft.X - Size.Width / 4, myLowerLeft.Y - Size.Height / 4);
     187        var upperRight = new PointD(myUpperRight.X + Size.Width / 4, myUpperRight.Y + Size.Height / 4);
     188        ZoomIn(lowerLeft, upperRight);
     189        if (zoomHistory.Count >= 2) {
     190          zoomHistory.RemoveRange(0, 2);
     191        }
     192      }
     193    }
     194
    167195    public virtual void Unzoom() {
    168196      SetPosition(originalLowerLeft, originalUpperRight);
    169197    }
    170198
     199    public virtual void IntoForeground(IPrimitive primitive) {
     200      Group.IntoForeground(primitive);
     201    }
     202    public virtual void IntoBackground(IPrimitive primitive) {
     203      Group.IntoBackground(primitive);
     204    }
     205    public virtual void OneLayerUp(IPrimitive primitive) {
     206      Group.OneLayerUp(primitive);
     207    }
     208    public virtual void OneLayerDown(IPrimitive primitive) {
     209      Group.OneLayerDown(primitive);
     210    }
     211
     212    public virtual Cursor GetCursor(Point point) {
     213      return Group.GetCursor(TransformPixelToWorld(point)) ?? Cursors.Default;
     214    }
     215
     216    public virtual string GetToolTipText(Point point) {
     217      return Group.GetToolTipText(TransformPixelToWorld(point));
     218    }
     219
    171220    public virtual IPrimitive GetPrimitive(Point point) {
    172221      return Group.GetPrimitive(TransformPixelToWorld(point));
    173222    }
    174     public IPrimitive GetPrimitive(int x, int y) {
    175       return GetPrimitive(new Point(x, y));
    176     }
    177     public virtual IList<IPrimitive> GetAllPrimitives(Point point) {
     223
     224    public virtual IEnumerable<IPrimitive> GetAllPrimitives(Point point) {
    178225      return Group.GetAllPrimitives(TransformPixelToWorld(point));
    179     }
    180     public IList<IPrimitive> GetAllPrimitives(int x, int y) {
    181       return GetAllPrimitives(new Point(x, y));
    182     }
    183 
    184     public virtual Cursor GetCursor(Point point) {
    185       Cursor cursor = Group.GetCursor(TransformPixelToWorld(point));
    186       if (cursor != null) return cursor;
    187 
    188       if (Mode == ChartMode.Move) return Cursors.Hand;
    189       if (Mode == ChartMode.Select) return Cursors.Arrow;
    190       if (Mode == ChartMode.Zoom) return Cursors.Arrow;
    191       return Cursors.Default;
    192     }
    193     public Cursor GetCursor(int x, int y) {
    194       return GetCursor(new Point(x, y));
    195     }
    196     public virtual string GetToolTipText(Point point) {
    197       return Group.GetToolTipText(TransformPixelToWorld(point));
    198     }
    199     public string GetToolTipText(int x, int y) {
    200       return GetToolTipText(new Point(x, y));
    201     }
    202 
    203     public virtual void MouseClick(Point point, MouseButtons button) {
    204       if (Mode == ChartMode.Select) {
    205         if (button == MouseButtons.Left) {
    206           IPrimitive clicked = GetPrimitive(point);
    207           UpdateEnabled = false;
    208           foreach (IPrimitive primitive in Group.SelectedPrimitives)
    209             primitive.Selected = false;
    210           UpdateEnabled = true;
    211           if (clicked != null) {
    212             PointD p = TransformPixelToWorld(point);
    213             clicked.MouseClick(p, button);
    214           } else OnUpdate();
    215         }
    216       } else if (Mode == ChartMode.Move) {
    217         if (button == MouseButtons.Middle) {
    218           PointD center = LowerLeft + new Offset(Size.Width / 2, Size.Height / 2);
    219           Move(TransformPixelToWorld(point) - center);
    220         }
    221       }
    222     }
    223     public void MouseClick(int x, int y, MouseButtons button) {
    224       MouseClick(new Point(x, y), button);
    225     }
    226     public virtual void MouseDoubleClick(Point point, MouseButtons button) {
    227     }
    228     public void MouseDoubleClick(int x, int y, MouseButtons button) {
    229       MouseDoubleClick(new Point(x, y), button);
    230     }
    231     public virtual void MouseMove(Point start, Point end) {
    232     }
    233     public void MouseMove(int x1, int y1, int x2, int y2) {
    234       MouseMove(new Point(x1, y1), new Point(x2, y2));
    235     }
    236     public virtual void MouseDrag(Point start, Point end, MouseButtons button) {
    237       PointD p1 = TransformPixelToWorld(start);
    238       PointD p2 = TransformPixelToWorld(end);
    239       Offset offset = p2 - p1;
    240       if (Mode == ChartMode.Move) {
    241         Move(-1 * offset.DX, -1 * offset.DY);
    242       } else if (Mode == ChartMode.Select) {
    243         if (button == MouseButtons.Left) {
    244           IList<IPrimitive> selected = Group.SelectedPrimitives.Where(p => p.ContainsPoint(p1)).ToList();
    245           UpdateEnabled = false;
    246           foreach (IPrimitive primitive in selected)
    247             primitive.MouseDrag(p1, offset, button);
    248           UpdateEnabled = true;
    249           OnUpdate();
    250         }
    251       }
    252     }
    253     public void MouseDrag(int x1, int y1, int x2, int y2, MouseButtons button) {
    254       MouseDrag(new Point(x1, y1), new Point(x2, y2), button);
    255226    }
    256227
     
    260231      Group.Draw(graphics);
    261232      Group.PostDraw(graphics);
    262     }
    263 
    264     public event EventHandler Update;
    265     public void EnforceUpdate() {
    266       if (Update != null) {
    267         Update(this, new EventArgs());
    268       }
    269     }
    270     protected virtual void OnUpdate() {
    271       if ((UpdateEnabled) && (Update != null)) {
    272         Update(this, new EventArgs());
    273       }
    274     }
    275     private void Group_Update(object sender, EventArgs e) {
    276       OnUpdate();
     233      if (!enabled) {
     234        var disabledColor = Color.FromArgb(150, SystemColors.Control);
     235        var brush = new SolidBrush(disabledColor);
     236        var rectangle = new System.Drawing.Rectangle(new Point(0, 0), mySizeInPixels);
     237        graphics.FillRectangle(brush, rectangle);
     238      }
     239    }
     240
     241    public event EventHandler RedrawRequired;
     242    protected virtual void OnRedrawRequired() {
     243      if (SuppressRedraw) return;
     244      var handler = RedrawRequired;
     245      if (handler != null) handler(this, EventArgs.Empty);
     246    }
     247
     248    public void RaiseRedrawRequired() {
     249      var handler = RedrawRequired;
     250      if (handler != null) handler(this, EventArgs.Empty);
     251    }
     252
     253    private void GroupOnRedrawRequired(object sender, EventArgs e) {
     254      OnRedrawRequired();
    277255    }
    278256  }
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartControl.Designer.cs

    r12535 r13045  
    4848      this.pictureBox = new System.Windows.Forms.PictureBox();
    4949      this.pictureBoxContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
    50       this.moveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    51       this.zoomToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    52       this.selectToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    53       this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
    5450      this.oneLayerUpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5551      this.oneLayerDownToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5652      this.intoForegroundToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5753      this.intoBackgroundToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     54      this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
     55      this.propertiesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     56      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
     57      this.selectButton = new System.Windows.Forms.RadioButton();
     58      this.moveButton = new System.Windows.Forms.RadioButton();
     59      this.zoomInButton = new System.Windows.Forms.RadioButton();
     60      this.zoomOutButton = new System.Windows.Forms.RadioButton();
     61      this.buttonPanel = new System.Windows.Forms.FlowLayoutPanel();
     62      this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
     63      this.saveImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5864      this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
    59       this.propertiesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    60       this.saveImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    61       this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    62       this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
    6365      ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
    6466      this.pictureBoxContextMenuStrip.SuspendLayout();
     67      this.buttonPanel.SuspendLayout();
    6568      this.SuspendLayout();
    6669      //
     
    7174            | System.Windows.Forms.AnchorStyles.Right)));
    7275      this.pictureBox.BackColor = System.Drawing.Color.White;
     76      this.pictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    7377      this.pictureBox.ContextMenuStrip = this.pictureBoxContextMenuStrip;
    74       this.pictureBox.Location = new System.Drawing.Point(0, 0);
     78      this.pictureBox.Location = new System.Drawing.Point(35, 0);
    7579      this.pictureBox.Name = "pictureBox";
    76       this.pictureBox.Size = new System.Drawing.Size(266, 236);
     80      this.pictureBox.Size = new System.Drawing.Size(685, 500);
    7781      this.pictureBox.TabIndex = 0;
    7882      this.pictureBox.TabStop = false;
    79       this.pictureBox.SizeChanged += new System.EventHandler(this.pictureBox_SizeChanged);
    80       this.pictureBox.VisibleChanged += new System.EventHandler(this.pictureBox_VisibleChanged);
    81       this.pictureBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseDown);
    82       this.pictureBox.MouseEnter += new System.EventHandler(this.pictureBox_MouseEnter);
    83       this.pictureBox.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseMove);
    84       this.pictureBox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseUp);
    85       this.pictureBox.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseWheel);
    86 
     83      this.pictureBox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.OnKeyUp);
     84      this.pictureBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OnKeyDown);
     85      this.pictureBox.SizeChanged += new System.EventHandler(this.PictureBoxOnSizeChanged);
     86      this.pictureBox.VisibleChanged += new System.EventHandler(this.PictureBoxOnVisibleChanged);
     87      this.pictureBox.Click += new System.EventHandler(this.PictureBoxOnClick);
     88      this.pictureBox.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PictureBoxOnMouseClick);
     89      this.pictureBox.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.PictureBoxOnMouseDoubleClick);
     90      this.pictureBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PictureBoxOnMouseDown);
     91      this.pictureBox.MouseEnter += new System.EventHandler(this.PictureBoxOnMouseEnter);
     92      this.pictureBox.MouseLeave += new System.EventHandler(this.PictureBoxOnMouseLeave);
     93      this.pictureBox.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PictureBoxOnMouseMove);
     94      this.pictureBox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PictureBoxOnMouseUp);
     95      this.pictureBox.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.PictureBoxOnMouseWheel);
    8796      //
    8897      // pictureBoxContextMenuStrip
    8998      //
    9099      this.pictureBoxContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    91             this.moveToolStripMenuItem,
    92             this.zoomToolStripMenuItem,
    93             this.selectToolStripMenuItem,
    94             this.toolStripMenuItem1,
    95100            this.oneLayerUpToolStripMenuItem,
    96101            this.oneLayerDownToolStripMenuItem,
    97102            this.intoForegroundToolStripMenuItem,
    98103            this.intoBackgroundToolStripMenuItem,
     104            this.toolStripMenuItem1,
     105            this.propertiesToolStripMenuItem,
    99106            this.toolStripMenuItem2,
    100             this.propertiesToolStripMenuItem,
    101107            this.saveImageToolStripMenuItem});
    102108      this.pictureBoxContextMenuStrip.Name = "pictureBoxContextMenuStrip";
    103       this.pictureBoxContextMenuStrip.Size = new System.Drawing.Size(163, 214);
    104       //
    105       // moveToolStripMenuItem
    106       //
    107       this.moveToolStripMenuItem.Checked = true;
    108       this.moveToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
    109       this.moveToolStripMenuItem.Name = "moveToolStripMenuItem";
    110       this.moveToolStripMenuItem.Size = new System.Drawing.Size(162, 22);
    111       this.moveToolStripMenuItem.Text = "&Move";
    112       this.moveToolStripMenuItem.Click += new System.EventHandler(this.moveToolStripMenuItem_Click);
    113       //
    114       // zoomToolStripMenuItem
    115       //
    116       this.zoomToolStripMenuItem.Name = "zoomToolStripMenuItem";
    117       this.zoomToolStripMenuItem.Size = new System.Drawing.Size(162, 22);
    118       this.zoomToolStripMenuItem.Text = "&Zoom";
    119       this.zoomToolStripMenuItem.Click += new System.EventHandler(this.zoomToolStripMenuItem_Click);
    120       //
    121       // selectToolStripMenuItem
    122       //
    123       this.selectToolStripMenuItem.Name = "selectToolStripMenuItem";
    124       this.selectToolStripMenuItem.Size = new System.Drawing.Size(162, 22);
    125       this.selectToolStripMenuItem.Text = "&Select";
    126       this.selectToolStripMenuItem.Click += new System.EventHandler(this.selectToolStripMenuItem_Click);
    127       //
    128       // toolStripMenuItem1
    129       //
    130       this.toolStripMenuItem1.Name = "toolStripMenuItem1";
    131       this.toolStripMenuItem1.Size = new System.Drawing.Size(159, 6);
     109      this.pictureBoxContextMenuStrip.Size = new System.Drawing.Size(163, 170);
     110      this.pictureBoxContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.PictureBoxContextMenuStripOnOpening);
    132111      //
    133112      // oneLayerUpToolStripMenuItem
     
    163142      this.intoBackgroundToolStripMenuItem.Click += new System.EventHandler(this.intoBackgroundToolStripMenuItem_Click);
    164143      //
    165       // toolStripMenuItem2
    166       //
    167       this.toolStripMenuItem2.Name = "toolStripMenuItem2";
    168       this.toolStripMenuItem2.Size = new System.Drawing.Size(159, 6);
     144      // toolStripMenuItem1
     145      //
     146      this.toolStripMenuItem1.Name = "toolStripMenuItem1";
     147      this.toolStripMenuItem1.Size = new System.Drawing.Size(159, 6);
    169148      //
    170149      // propertiesToolStripMenuItem
     
    176155      this.propertiesToolStripMenuItem.Click += new System.EventHandler(this.propertiesToolStripMenuItem_Click);
    177156      //
     157      // toolStripMenuItem2
     158      //
     159      this.toolStripMenuItem2.Name = "toolStripMenuItem2";
     160      this.toolStripMenuItem2.Size = new System.Drawing.Size(159, 6);
     161      //
    178162      // saveImageToolStripMenuItem
    179163      //
    180164      this.saveImageToolStripMenuItem.Name = "saveImageToolStripMenuItem";
    181165      this.saveImageToolStripMenuItem.Size = new System.Drawing.Size(162, 22);
    182       this.saveImageToolStripMenuItem.Text = "Save Image";
     166      this.saveImageToolStripMenuItem.Text = "&Save Image";
    183167      this.saveImageToolStripMenuItem.Click += new System.EventHandler(this.saveImageToolStripMenuItem_Click);
    184168      //
     
    187171      this.saveFileDialog.DefaultExt = "emf";
    188172      this.saveFileDialog.FileName = "*.emf";
    189       this.saveFileDialog.Filter = "Enhanced metafile|*.emf|Bitmap files|*.bmp";
     173      this.saveFileDialog.Filter = "Bitmap (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg|EMF (*.emf)|*.emf|PNG (*.png)|*.png|GIF (" +
     174    "*.gif)|*.gif|TIFF (*.tif)|*.tif";
     175      //
     176      // selectButton
     177      //
     178      this.selectButton.Appearance = System.Windows.Forms.Appearance.Button;
     179      this.selectButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Pointer;
     180      this.selectButton.Location = new System.Drawing.Point(3, 3);
     181      this.selectButton.Name = "selectButton";
     182      this.selectButton.Size = new System.Drawing.Size(26, 24);
     183      this.selectButton.TabIndex = 1;
     184      this.selectButton.TabStop = true;
     185      this.selectButton.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
     186      this.toolTip.SetToolTip(this.selectButton, "Select");
     187      this.selectButton.UseVisualStyleBackColor = true;
     188      this.selectButton.CheckedChanged += new System.EventHandler(this.SelectButtonOnCheckedChanged);
     189      //
     190      // moveButton
     191      //
     192      this.moveButton.Appearance = System.Windows.Forms.Appearance.Button;
     193      this.moveButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Breakpoint;
     194      this.moveButton.Location = new System.Drawing.Point(3, 33);
     195      this.moveButton.Name = "moveButton";
     196      this.moveButton.Size = new System.Drawing.Size(26, 24);
     197      this.moveButton.TabIndex = 1;
     198      this.moveButton.TabStop = true;
     199      this.moveButton.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
     200      this.toolTip.SetToolTip(this.moveButton, "Move");
     201      this.moveButton.UseVisualStyleBackColor = true;
     202      this.moveButton.CheckedChanged += new System.EventHandler(this.MoveButtonOnCheckedChanged);
     203      //
     204      // zoomInButton
     205      //
     206      this.zoomInButton.Appearance = System.Windows.Forms.Appearance.Button;
     207      this.zoomInButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.ZoomIn;
     208      this.zoomInButton.Location = new System.Drawing.Point(3, 63);
     209      this.zoomInButton.Name = "zoomInButton";
     210      this.zoomInButton.Size = new System.Drawing.Size(26, 24);
     211      this.zoomInButton.TabIndex = 1;
     212      this.zoomInButton.TabStop = true;
     213      this.zoomInButton.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
     214      this.toolTip.SetToolTip(this.zoomInButton, "Zoom In");
     215      this.zoomInButton.UseVisualStyleBackColor = true;
     216      this.zoomInButton.CheckedChanged += new System.EventHandler(this.ZoomInButtonOnCheckedChanged);
     217      //
     218      // zoomOutButton
     219      //
     220      this.zoomOutButton.Appearance = System.Windows.Forms.Appearance.Button;
     221      this.zoomOutButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.ZoomOut;
     222      this.zoomOutButton.Location = new System.Drawing.Point(3, 93);
     223      this.zoomOutButton.Name = "zoomOutButton";
     224      this.zoomOutButton.Size = new System.Drawing.Size(26, 24);
     225      this.zoomOutButton.TabIndex = 1;
     226      this.zoomOutButton.TabStop = true;
     227      this.zoomOutButton.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
     228      this.toolTip.SetToolTip(this.zoomOutButton, "Zoom Out");
     229      this.zoomOutButton.UseVisualStyleBackColor = true;
     230      this.zoomOutButton.CheckedChanged += new System.EventHandler(this.ZoomOutButtonOnCheckedChanged);
     231      //
     232      // buttonPanel
     233      //
     234      this.buttonPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     235            | System.Windows.Forms.AnchorStyles.Left)));
     236      this.buttonPanel.Controls.Add(this.selectButton);
     237      this.buttonPanel.Controls.Add(this.moveButton);
     238      this.buttonPanel.Controls.Add(this.zoomInButton);
     239      this.buttonPanel.Controls.Add(this.zoomOutButton);
     240      this.buttonPanel.Location = new System.Drawing.Point(0, 0);
     241      this.buttonPanel.Name = "buttonPanel";
     242      this.buttonPanel.Size = new System.Drawing.Size(32, 500);
     243      this.buttonPanel.TabIndex = 2;
    190244      //
    191245      // ChartControl
    192246      //
    193       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    194       this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     247      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    195248      this.BackColor = System.Drawing.SystemColors.Control;
     249      this.Controls.Add(this.buttonPanel);
    196250      this.Controls.Add(this.pictureBox);
     251      this.DoubleBuffered = true;
    197252      this.Name = "ChartControl";
    198       this.Size = new System.Drawing.Size(266, 236);
    199       this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ChartControl_KeyDown);
     253      this.Size = new System.Drawing.Size(720, 500);
     254      this.Load += new System.EventHandler(this.ChartControl_Load);
     255      this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OnKeyDown);
     256      this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.OnKeyUp);
    200257      ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
    201258      this.pictureBoxContextMenuStrip.ResumeLayout(false);
     259      this.buttonPanel.ResumeLayout(false);
    202260      this.ResumeLayout(false);
    203261
     
    209267    protected System.Windows.Forms.ToolTip toolTip;
    210268    protected System.Windows.Forms.ContextMenuStrip pictureBoxContextMenuStrip;
    211     protected System.Windows.Forms.ToolStripMenuItem moveToolStripMenuItem;
    212     protected System.Windows.Forms.ToolStripMenuItem zoomToolStripMenuItem;
    213     protected System.Windows.Forms.ToolStripMenuItem selectToolStripMenuItem;
    214     protected System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;
     269    protected System.Windows.Forms.ToolStripMenuItem saveImageToolStripMenuItem;
    215270    protected System.Windows.Forms.ToolStripMenuItem propertiesToolStripMenuItem;
    216271    protected System.Windows.Forms.ToolStripMenuItem oneLayerUpToolStripMenuItem;
     
    218273    protected System.Windows.Forms.ToolStripMenuItem intoForegroundToolStripMenuItem;
    219274    protected System.Windows.Forms.ToolStripMenuItem intoBackgroundToolStripMenuItem;
     275    protected System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;
    220276    protected System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
    221     private System.Windows.Forms.ToolStripMenuItem saveImageToolStripMenuItem;
    222     private System.Windows.Forms.SaveFileDialog saveFileDialog;
    223 
     277    protected System.Windows.Forms.RadioButton selectButton;
     278    protected System.Windows.Forms.RadioButton moveButton;
     279    protected System.Windows.Forms.RadioButton zoomInButton;
     280    protected System.Windows.Forms.RadioButton zoomOutButton;
     281    protected System.Windows.Forms.FlowLayoutPanel buttonPanel;
     282    protected System.Windows.Forms.SaveFileDialog saveFileDialog;
    224283  }
    225284}
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartControl.cs

    r12535 r13045  
    2121
    2222using System;
    23 using System.Collections.Generic;
     23using System.ComponentModel;
    2424using System.Drawing;
    2525using System.Drawing.Drawing2D;
    2626using System.Drawing.Imaging;
     27using System.Linq;
    2728using System.Windows.Forms;
    2829
    2930namespace HeuristicLab.Visualization {
    3031  public partial class ChartControl : UserControl {
    31     public Bitmap Bitmap { get; private set; }
    32 
    33     private bool renderingRequired;
    34     private Point buttonDownPoint;
    35     private Point mousePosition;
    36     private int mouseClickCount;
    37 
    38     private Chart myChart;
    39     public Chart Chart {
    40       get { return myChart; }
     32    public static readonly Cursor HandCursor = new Cursor(typeof(ChartControl), "Resources.Hand.cur");
     33    public static readonly Cursor ZoomOutCursor = new Cursor(typeof(ChartControl), "Resources.ZoomOut.cur");
     34    public static readonly Cursor ZoomInCursor = new Cursor(typeof(ChartControl), "Resources.ZoomIn.cur");
     35
     36    protected Bitmap Picture;
     37    protected bool RenderingRequired;
     38    protected Point ButtonDownPoint;
     39    protected Point PreviousLocation;
     40    protected int MouseClickCount;
     41
     42    protected bool SuppressEvents { get; set; }
     43    private bool SuppressRender { get; set; }
     44
     45    private IChart chart;
     46    public IChart Chart {
     47      get { return chart; }
     48      protected set {
     49        if (chart != null) DeregisterChartEvents(chart);
     50        chart = value;
     51        chart.Enabled = Enabled;
     52        pictureBox.Enabled = Enabled;
     53        if (chart != null) RegisterChartEvents(chart);
     54      }
     55    }
     56
     57    private ChartMode mode;
     58    public ChartMode Mode {
     59      get { return mode; }
    4160      set {
    42         if (myChart != null) myChart.Update -= new EventHandler(myChart_Update);
    43         myChart = value;
    44         if (myChart != null) {
    45           myChart.Update += new EventHandler(myChart_Update);
    46           SetMode(Chart.Mode);
    47         }
    48         GenerateImage();
    49       }
    50     }
    51     private bool myScaleOnResize;
    52     public bool ScaleOnResize {
    53       get { return myScaleOnResize; }
    54       set { myScaleOnResize = value; }
    55     }
    56 
    57     public ChartControl() {
     61        if (mode == value) return;
     62        mode = value;
     63        SetButtonCheckedSate();
     64        SetPictureBoxCursor(GetPictureBoxCursor());
     65        OnModeChanged();
     66        if (chart != null) {
     67          GenerateImage();
     68        }
     69      }
     70    }
     71
     72    public bool ScaleOnResize { get; set; }
     73
     74    public bool IsRenderingPaused { get { return SuppressRender; } }
     75
     76    public ChartControl() : this(null) { }
     77    public ChartControl(IChart defaultChart) {
    5878      InitializeComponent();
    59       myScaleOnResize = true;
     79      ScaleOnResize = true;
     80      Mode = ChartMode.Select;
     81      Chart = defaultChart ?? new Chart(0, 0, Width, Height);
     82    }
     83
     84    public void SuspendRendering() {
     85      SuppressRender = true;
     86    }
     87
     88    public void ResumeRendering() {
     89      SuppressRender = false;
     90      if (Chart != null) GenerateImage();
     91    }
     92
     93    protected virtual void SetButtonCheckedSate() {
     94      selectButton.Checked = false;
     95      moveButton.Checked = false;
     96      zoomInButton.Checked = false;
     97      zoomOutButton.Checked = false;
     98      if (mode == ChartMode.Select) selectButton.Checked = true;
     99      else if (mode == ChartMode.Move) moveButton.Checked = true;
     100      else if (mode == ChartMode.ZoomIn) zoomInButton.Checked = true;
     101      else if (mode == ChartMode.ZoomOut) zoomOutButton.Checked = true;
     102    }
     103
     104    protected virtual void SetPictureBoxCursor(Cursor cursor) {
     105      if (pictureBox.Cursor != cursor) pictureBox.Cursor = cursor;
     106    }
     107
     108    protected virtual Cursor GetPictureBoxCursor() {
     109      if (Mode == ChartMode.Select)
     110        return DefaultCursor;
     111      if (Mode == ChartMode.Move)
     112        return HandCursor;
     113      if (Mode == ChartMode.ZoomIn)
     114        return ZoomInCursor;
     115      if (Mode == ChartMode.ZoomOut)
     116        return ZoomOutCursor;
     117      return null;
     118    }
     119
     120    protected virtual void RegisterChartEvents(IChart chart) {
     121      chart.RedrawRequired += ChartOnUpdateRequired;
     122    }
     123
     124    protected virtual void DeregisterChartEvents(IChart chart) {
     125      chart.RedrawRequired -= ChartOnUpdateRequired;
     126    }
     127
     128    protected virtual void ChartOnUpdateRequired(object sender, EventArgs e) {
     129      if (SuppressRender) return;
    60130      GenerateImage();
    61131    }
    62132
    63     private void myChart_Update(object sender, EventArgs e) {
    64       GenerateImage();
    65     }
    66     private void pictureBox_SizeChanged(object sender, EventArgs e) {
     133    #region PictureBox Events
     134    protected virtual void PictureBoxOnSizeChanged(object sender, EventArgs e) {
     135      if (Chart == null) return;
    67136      if (ScaleOnResize) {
    68137        if ((pictureBox.Width > 0) && (pictureBox.Height > 0) && (Chart != null)) {
    69           PointD point = Chart.TransformPixelToWorld(new Point(pictureBox.Width, Chart.SizeInPixels.Height - pictureBox.Height));
    70           Chart.SetPosition(Chart.LowerLeft, point);
     138          var point = Chart.TransformPixelToWorld(new Point(pictureBox.Width, Chart.SizeInPixels.Height - pictureBox.Height));
     139          var diff = Chart.UpperRight - point;
     140          Chart.SetPosition(new PointD(Chart.LowerLeft.X + (diff.DX / 2.0), Chart.LowerLeft.Y + (diff.DY / 2.0)),
     141            new PointD(Chart.UpperRight.X - (diff.DX / 2.0), Chart.UpperRight.Y - (diff.DY / 2.0)));
    71142        }
    72143      }
    73144      GenerateImage();
    74145    }
    75     private void pictureBox_VisibleChanged(object sender, EventArgs e) {
    76       if (pictureBox.Visible && renderingRequired) {
    77         GenerateImage();
    78       }
    79     }
    80 
    81     private void pictureBox_MouseDown(object sender, MouseEventArgs e) {
    82       buttonDownPoint = e.Location;
    83       mouseClickCount = e.Clicks;
    84     }
    85     protected virtual void pictureBox_MouseUp(object sender, MouseEventArgs e) {
     146
     147    protected virtual void PictureBoxOnVisibleChanged(object sender, EventArgs e) {
     148      if (pictureBox.Visible && RenderingRequired) GenerateImage();
     149    }
     150
     151    protected virtual void PictureBoxOnMouseClick(object sender, MouseEventArgs e) {
     152
     153    }
     154
     155    protected virtual void PictureBoxOnMouseDoubleClick(object sender, MouseEventArgs e) {
     156
     157    }
     158
     159    protected virtual void OnKeyDown(object sender, KeyEventArgs e) {
     160      if (Mode == ChartMode.Select) {
     161        if (e.KeyCode == Keys.Delete) {
     162          try {
     163            SuspendRendering();
     164            foreach (var primitive in Chart.Group.SelectedPrimitives)
     165              Chart.Group.Remove(primitive);
     166          } finally { ResumeRendering(); }
     167        }
     168      }
     169    }
     170
     171    protected virtual void OnKeyUp(object sender, KeyEventArgs e) {
     172
     173    }
     174
     175    protected virtual void PictureBoxOnMouseWheel(object sender, MouseEventArgs e) {
     176
     177    }
     178
     179    protected virtual void PictureBoxOnMouseDown(object sender, MouseEventArgs e) {
     180      if (Chart == null) return;
     181      MouseClickCount = e.Clicks;
     182      ButtonDownPoint = e.Location;
     183      if (Mode != ChartMode.Select) return;
     184
     185      try {
     186        SuspendRendering();
     187        var worldLocation = Chart.TransformPixelToWorld(e.Location);
     188        foreach (var sp in Chart.Group.SelectedPrimitives.Where(x => !x.ContainsPoint(worldLocation)))
     189          sp.Selected = false;
     190        var p = Chart.GetPrimitive(e.Location);
     191        if (p != null) p.Selected = true;
     192      } finally { ResumeRendering(); }
     193    }
     194
     195    protected virtual void PictureBoxOnMouseUp(object sender, MouseEventArgs e) {
     196      if (Chart == null) return;
    86197      if (e.Button == MouseButtons.Left) {
    87         if (Chart.Mode == ChartMode.Zoom) {
     198        if (Mode == ChartMode.ZoomIn) {
     199          //pictureBox.Refresh();
     200          var lowerLeft = new Point(Math.Min(e.X, ButtonDownPoint.X), Math.Max(e.Y, ButtonDownPoint.Y));
     201          var upperRight = new Point(Math.Max(e.X, ButtonDownPoint.X), Math.Min(e.Y, ButtonDownPoint.Y));
     202          if ((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y))
     203            Chart.ZoomIn(lowerLeft, upperRight);
     204          else Chart.ZoomIn(ButtonDownPoint);
     205        } else if (Mode == ChartMode.ZoomOut) {
     206          Chart.ZoomOut();
     207        }
     208      } else if (e.Button == MouseButtons.Right) {
     209        propertiesToolStripMenuItem.Enabled = Chart.Group.SelectedPrimitives.Count() == 1;
     210        oneLayerUpToolStripMenuItem.Enabled = Chart.Group.SelectedPrimitives.Count() == 1;
     211        oneLayerDownToolStripMenuItem.Enabled = Chart.Group.SelectedPrimitives.Count() == 1;
     212        intoForegroundToolStripMenuItem.Enabled = Chart.Group.SelectedPrimitives.Count() == 1;
     213        intoBackgroundToolStripMenuItem.Enabled = Chart.Group.SelectedPrimitives.Count() == 1;
     214      } else if (e.Button == MouseButtons.Middle) {
     215        if (Mode == ChartMode.Select) {
     216          try {
     217            SuspendRendering();
     218            foreach (var p in Chart.Group.SelectedPrimitives)
     219              p.Selected = false;
     220          } finally { ResumeRendering(); }
     221        } else if (Mode == ChartMode.Move || Mode == ChartMode.ZoomIn || Mode == ChartMode.ZoomOut) {
     222          Chart.Unzoom();
     223        }
     224      }
     225    }
     226
     227    protected virtual void PictureBoxOnMouseMove(object sender, MouseEventArgs e) {
     228      if (InvokeRequired) {
     229        Invoke((Action<Object, MouseEventArgs>)PictureBoxOnMouseMove, sender, e);
     230        return;
     231      }
     232      var toolTipText = Chart.GetToolTipText(e.Location);
     233      if (toolTip.GetToolTip(pictureBox) != toolTipText) toolTip.SetToolTip(pictureBox, toolTipText);
     234
     235      Cursor cursor;
     236      if (Mode == ChartMode.Select) {
     237        cursor = Chart.GetCursor(e.Location) ?? GetPictureBoxCursor();
     238      } else cursor = GetPictureBoxCursor();
     239      SetPictureBoxCursor(cursor);
     240
     241      try {
     242        if (e.Button == MouseButtons.None) return;
     243
     244        if (Mode == ChartMode.Select && e.Button == MouseButtons.Left) {
     245          var previousWorldLocation = Chart.TransformPixelToWorld(PreviousLocation);
     246          var worldLocation = Chart.TransformPixelToWorld(e.Location);
     247          var offset = worldLocation - previousWorldLocation;
     248          try {
     249            SuspendRendering();
     250            foreach (var primitive in Chart.Group.SelectedPrimitives.Where(p => p.ContainsPoint(previousWorldLocation)))
     251              primitive.Move(previousWorldLocation, offset);
     252          } finally { ResumeRendering(); }
     253        } else if (Mode == ChartMode.Move) {
     254          var previousWorldLocation = Chart.TransformPixelToWorld(PreviousLocation);
     255          var worldLocation = Chart.TransformPixelToWorld(e.Location);
     256          var offset = worldLocation - previousWorldLocation;
     257          Chart.Move(new Offset(-1 * offset.DX, -1 * offset.DY));
     258        } else if (Mode == ChartMode.ZoomIn && e.Button == MouseButtons.Left) {
    88259          pictureBox.Refresh();
    89           // some code to preserve the aspect ratio when zooming
    90           //       +---------------------+ (Width,Height)
    91           //       |  (x1,y1)            |
    92           //       |      +-------+      |
    93           //       |      |       |      |
    94           //       |      |       |      |
    95           //       |      +-------+      |
    96           //       |             (x2,y2) |
    97           // (0,0) +---------------------+
    98           //
    99           double aspectRatio = (double)Width / Height;
    100           double x1 = Math.Min(e.X, buttonDownPoint.X);
    101           double y1 = Math.Max(e.Y, buttonDownPoint.Y);
    102           double x2 = Math.Max(e.X, buttonDownPoint.X);
    103           double y2 = Math.Min(e.Y, buttonDownPoint.Y);
    104           // consider the relative ratios between the X and Y dimensions of the selection
    105           // area and the Width and Height, respectively. The "dominant" dimension is the
    106           // one with a ratio closer to 1, and it stays fixed while the other is adjusted
    107           // in order to preserve the aspect ratio
    108           if ((x2 - x1) / Width > (y1 - y2) / Height) {
    109             y1 = y2 + (x2 - x1) / aspectRatio;
    110           } else {
    111             x2 = aspectRatio * (y1 - y2) + x1;
     260          using (var graphics = pictureBox.CreateGraphics()) {
     261            using (var pen = new Pen(Color.Gray) { DashStyle = DashStyle.Dash }) {
     262              graphics.DrawRectangle(pen,
     263                Math.Min(e.X, ButtonDownPoint.X),
     264                Math.Min(e.Y, ButtonDownPoint.Y),
     265                Math.Abs(e.X - ButtonDownPoint.X),
     266                Math.Abs(e.Y - ButtonDownPoint.Y));
     267            }
    112268          }
    113           var lowerLeft = new Point((int)x1, (int)y1);
    114           var upperRight = new Point((int)x2, (int)y2);
    115           if ((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y)) {
    116             Chart.ZoomIn(lowerLeft, upperRight);
     269        }
     270      } finally {
     271        PreviousLocation = e.Location;
     272        pictureBox.Update();
     273      }
     274    }
     275
     276    protected virtual void PictureBoxOnMouseEnter(object sender, EventArgs e) {
     277      if (InvokeRequired) {
     278        Invoke((Action<Object, MouseEventArgs>)PictureBoxOnMouseEnter, sender, e);
     279        return;
     280      }
     281      if (!Focused) this.pictureBox.Focus();
     282    }
     283
     284    protected virtual void PictureBoxOnMouseLeave(object sender, EventArgs e) {
     285
     286    }
     287
     288    protected virtual void PictureBoxOnClick(object sender, EventArgs e) {
     289      if (InvokeRequired) {
     290        Invoke((Action<Object, MouseEventArgs>)PictureBoxOnClick, sender, e);
     291        return;
     292      }
     293      if (!Focused) this.pictureBox.Focus();
     294    }
     295    #endregion
     296
     297    protected virtual void PictureBoxContextMenuStripOnOpening(object sender, CancelEventArgs e) { }
     298
     299    protected virtual void oneLayerUpToolStripMenuItem_Click(object sender, EventArgs e) {
     300      if (Chart == null) return;
     301      if (Chart.Group.SelectedPrimitives.Count() == 1) {
     302        Chart.OneLayerUp(Chart.Group.SelectedPrimitives.First());
     303      }
     304    }
     305    protected virtual void oneLayerDownToolStripMenuItem_Click(object sender, EventArgs e) {
     306      if (Chart == null) return;
     307      if (Chart.Group.SelectedPrimitives.Count() == 1) {
     308        Chart.OneLayerDown(Chart.Group.SelectedPrimitives.First());
     309      }
     310    }
     311    protected virtual void intoForegroundToolStripMenuItem_Click(object sender, EventArgs e) {
     312      if (Chart == null) return;
     313      if (Chart.Group.SelectedPrimitives.Count() == 1) {
     314        Chart.IntoForeground(Chart.Group.SelectedPrimitives.First());
     315      }
     316    }
     317    protected virtual void intoBackgroundToolStripMenuItem_Click(object sender, EventArgs e) {
     318      if (Chart == null) return;
     319      if (Chart.Group.SelectedPrimitives.Count() == 1) {
     320        Chart.IntoBackground(Chart.Group.SelectedPrimitives.First());
     321      }
     322    }
     323    protected virtual void propertiesToolStripMenuItem_Click(object sender, EventArgs e) {
     324      if (Chart == null) return;
     325      if (Chart.Group.SelectedPrimitives.Count() == 1) {
     326        using (var dialog = new PropertiesDialog(Chart.Group.SelectedPrimitives.First())) {
     327          dialog.ShowDialog(this);
     328        }
     329      }
     330    }
     331    protected virtual void saveImageToolStripMenuItem_Click(object sender, EventArgs e) {
     332      if (Picture == null) return;
     333
     334      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
     335        var format = ImageFormat.Bmp;
     336        var filename = saveFileDialog.FileName.ToLower();
     337        if (filename.EndsWith("emf")) {
     338          using (var g1 = Graphics.FromImage(Picture)) {
     339            var rectangle = new System.Drawing.Rectangle(0, 0, Picture.Width, Picture.Height);
     340            using (var metafile = new Metafile(filename, g1.GetHdc(), rectangle, MetafileFrameUnit.Pixel, EmfType.EmfPlusDual))
     341            using (var g2 = Graphics.FromImage(metafile))
     342              Chart.Render(g2, pictureBox.Width, pictureBox.Height);
    117343          }
    118         }
    119       } else if (e.Button == MouseButtons.Right) {
    120         propertiesToolStripMenuItem.Enabled = Chart.Group.SelectedPrimitives.Count == 1;
    121         oneLayerUpToolStripMenuItem.Enabled = Chart.Group.SelectedPrimitives.Count == 1;
    122         oneLayerDownToolStripMenuItem.Enabled = Chart.Group.SelectedPrimitives.Count == 1;
    123         intoForegroundToolStripMenuItem.Enabled = Chart.Group.SelectedPrimitives.Count == 1;
    124         intoBackgroundToolStripMenuItem.Enabled = Chart.Group.SelectedPrimitives.Count == 1;
    125       } else if (e.Button == MouseButtons.Middle) {
    126         if (Chart.Mode == ChartMode.Zoom) {
    127           if (mouseClickCount == 1) Chart.ZoomOut();
    128           else if (mouseClickCount == 2) Chart.Unzoom();
    129         }
    130       }
    131       if (buttonDownPoint == e.Location) {
    132         if (mouseClickCount == 1)
    133           Chart.MouseClick(e.Location, e.Button);
    134         else if (mouseClickCount == 2)
    135           Chart.MouseDoubleClick(e.Location, e.Button);
    136       }
    137     }
    138 
    139     protected virtual void pictureBox_MouseMove(object sender, MouseEventArgs e) {
    140       var text = Chart.GetToolTipText(e.Location);
    141       if (toolTip.GetToolTip(pictureBox) != text)
    142         toolTip.SetToolTip(pictureBox, text);
    143       Cursor cursor = Chart.GetCursor(e.Location);
    144       if (cursor != null) pictureBox.Cursor = cursor;
    145       else pictureBox.Cursor = Cursors.Default;
    146 
    147       if (e.Button != MouseButtons.None) {
    148         if ((Chart.Mode == ChartMode.Zoom) && (e.Button == MouseButtons.Left)) {
    149           pictureBox.Refresh();
    150           Graphics graphics = pictureBox.CreateGraphics();
    151           Pen pen = new Pen(Color.Gray);
    152           pen.DashStyle = DashStyle.Dash;
    153           graphics.DrawRectangle(pen,
    154                                  Math.Min(e.X, buttonDownPoint.X),
    155                                  Math.Min(e.Y, buttonDownPoint.Y),
    156                                  Math.Abs(e.X - buttonDownPoint.X),
    157                                  Math.Abs(e.Y - buttonDownPoint.Y));
    158           pen.Dispose();
    159           graphics.Dispose();
    160         }
    161         Chart.MouseDrag(mousePosition, e.Location, e.Button);
    162       } else {
    163         Chart.MouseMove(mousePosition, e.Location);
    164       }
    165       mousePosition = e.Location;
    166     }
    167 
    168     protected virtual void pictureBox_MouseWheel(object sender, MouseEventArgs e) {
    169       if (e.Delta > 0) {
    170         // zoom in
    171         double x1 = Chart.LowerLeft.X + Chart.Size.Width / 8;
    172         double y1 = Chart.LowerLeft.Y + Chart.Size.Height / 8;
    173         double x2 = Chart.UpperRight.X - Chart.Size.Width / 8;
    174         double y2 = Chart.UpperRight.Y - Chart.Size.Height / 8;
    175         Chart.ZoomIn(x1, y1, x2, y2);
    176       } else if (e.Delta < 0) {
    177         // zoom out
    178         double x1 = Chart.LowerLeft.X - Chart.Size.Width / 8;
    179         double y1 = Chart.LowerLeft.Y - Chart.Size.Height / 8;
    180         double x2 = Chart.UpperRight.X + Chart.Size.Width / 8;
    181         double y2 = Chart.UpperRight.Y + Chart.Size.Height / 8;
    182         Chart.ZoomIn(x1, y1, x2, y2);
    183       }
    184     }
    185 
    186     private void pictureBox_MouseEnter(object sender, EventArgs e) {
    187       pictureBox.Focus();
    188     }
    189 
    190     protected virtual void ChartControl_KeyDown(object sender, KeyEventArgs e) {
    191       if (Chart.Mode == ChartMode.Select) {
    192         if (e.KeyCode == Keys.Delete) {
    193           IList<IPrimitive> selected = Chart.Group.SelectedPrimitives;
    194           Chart.UpdateEnabled = false;
    195           foreach (IPrimitive primitive in selected)
    196             Chart.Group.Remove(primitive);
    197           Chart.UpdateEnabled = true;
    198           Chart.EnforceUpdate();
    199         }
    200       }
    201     }
    202 
    203     private void moveToolStripMenuItem_Click(object sender, EventArgs e) {
    204       SetMode(ChartMode.Move);
    205     }
    206     private void zoomToolStripMenuItem_Click(object sender, EventArgs e) {
    207       SetMode(ChartMode.Zoom);
    208     }
    209     private void selectToolStripMenuItem_Click(object sender, EventArgs e) {
    210       SetMode(ChartMode.Select);
    211     }
    212     private void oneLayerUpToolStripMenuItem_Click(object sender, EventArgs e) {
    213       if (Chart.Group.SelectedPrimitives.Count == 1) {
    214         Chart.Group.SelectedPrimitives[0].OneLayerUp();
    215       }
    216     }
    217     private void oneLayerDownToolStripMenuItem_Click(object sender, EventArgs e) {
    218       if (Chart.Group.SelectedPrimitives.Count == 1) {
    219         Chart.Group.SelectedPrimitives[0].OneLayerDown();
    220       }
    221     }
    222     private void intoForegroundToolStripMenuItem_Click(object sender, EventArgs e) {
    223       if (Chart.Group.SelectedPrimitives.Count == 1) {
    224         Chart.Group.SelectedPrimitives[0].IntoForeground();
    225       }
    226     }
    227     private void intoBackgroundToolStripMenuItem_Click(object sender, EventArgs e) {
    228       if (Chart.Group.SelectedPrimitives.Count == 1) {
    229         Chart.Group.SelectedPrimitives[0].IntoBackground();
    230       }
    231     }
    232     private void propertiesToolStripMenuItem_Click(object sender, EventArgs e) {
    233       if (Chart.Group.SelectedPrimitives.Count == 1) {
    234         PropertiesDialog dialog = new PropertiesDialog(Chart.Group.SelectedPrimitives[0]);
    235         dialog.ShowDialog(this);
    236         dialog.Dispose();
    237       }
    238     }
    239 
    240     private void GenerateImage() {
     344        } else {
     345          using (var graphics = Graphics.FromImage(Picture))
     346            Chart.Render(graphics, Picture.Width, Picture.Height);
     347
     348          if (filename.EndsWith("jpg")) {
     349            format = ImageFormat.Jpeg;
     350          } else if (filename.EndsWith("gif")) {
     351            format = ImageFormat.Gif;
     352          } else if (filename.EndsWith("png")) {
     353            format = ImageFormat.Png;
     354          } else if (filename.EndsWith("tif")) {
     355            format = ImageFormat.Tiff;
     356          }
     357
     358          Picture.Save(saveFileDialog.FileName, format);
     359        }
     360      }
     361    }
     362
     363    protected virtual void GenerateImage() {
     364      if (InvokeRequired) {
     365        Invoke((Action)GenerateImage);
     366        return;
     367      }
    241368      if (!Visible) {
    242         renderingRequired = true;
     369        RenderingRequired = true;
    243370      } else {
    244371        if ((pictureBox.Width == 0) || (pictureBox.Height == 0)) {
    245           Bitmap = null;
     372          pictureBox.Image = pictureBox.ErrorImage;
     373          if (Picture != null) Picture.Dispose();
     374          Picture = null;
    246375        } else {
    247           Bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
    248           if (Chart != null) {
    249             Graphics graphics = Graphics.FromImage(Bitmap);
     376          if (Picture != null) Picture.Dispose();
     377          Picture = new Bitmap(pictureBox.Width, pictureBox.Height);
     378          using (var graphics = Graphics.FromImage(Picture)) {
    250379            graphics.SetClip(new System.Drawing.Rectangle(0, 0, pictureBox.Width, pictureBox.Height));
    251380            Chart.Render(graphics, pictureBox.Width, pictureBox.Height);
    252             graphics.Dispose();
    253381          }
    254382        }
    255         if (pictureBox.Image != null) pictureBox.Image.Dispose();
    256         pictureBox.Image = Bitmap;
    257         renderingRequired = false;
    258       }
    259     }
    260 
    261     private void SetMode(ChartMode mode) {
    262       moveToolStripMenuItem.Checked = false;
    263       zoomToolStripMenuItem.Checked = false;
    264       selectToolStripMenuItem.Checked = false;
    265       if (mode == ChartMode.Move) moveToolStripMenuItem.Checked = true;
    266       else if (mode == ChartMode.Zoom) zoomToolStripMenuItem.Checked = true;
    267       else if (mode == ChartMode.Select) selectToolStripMenuItem.Checked = true;
    268       Chart.Mode = mode;
    269     }
    270 
    271     private void SaveImageAsBitmap(string filename) {
    272       if (Bitmap == null) throw new Exception("Bitmap is null.");
    273       Bitmap.Save(filename);
    274     }
    275 
    276     private void SaveImageAsEmf(string filename) {
    277       using (Graphics g = CreateGraphics()) {
    278         using (Metafile file = new Metafile(filename, g.GetHdc())) {
    279           using (Graphics emfFile = Graphics.FromImage(file)) {
    280             Chart.Render(emfFile, pictureBox.Width, pictureBox.Height);
    281           }
    282         }
    283         g.ReleaseHdc();
    284       }
    285     }
    286 
    287     private void saveImageToolStripMenuItem_Click(object sender, EventArgs e) {
    288       if (saveFileDialog.ShowDialog() == DialogResult.OK) {
    289         string filename = saveFileDialog.FileName.ToLower();
    290         if (filename.EndsWith("bmp")) SaveImageAsBitmap(filename);
    291         else if (filename.EndsWith("emf")) SaveImageAsEmf(filename);
    292         else SaveImageAsBitmap(filename);
    293       }
     383        pictureBox.Image = Picture;
     384        RenderingRequired = false;
     385      }
     386    }
     387
     388    public event EventHandler ModeChanged;
     389    protected void OnModeChanged() {
     390      var handler = ModeChanged;
     391      if (handler != null) handler(this, EventArgs.Empty);
     392    }
     393
     394    protected virtual void SelectButtonOnCheckedChanged(object sender, EventArgs e) {
     395      if (selectButton.Checked) Mode = ChartMode.Select;
     396    }
     397
     398    protected virtual void MoveButtonOnCheckedChanged(object sender, EventArgs e) {
     399      if (moveButton.Checked) Mode = ChartMode.Move;
     400    }
     401
     402    protected virtual void ZoomInButtonOnCheckedChanged(object sender, EventArgs e) {
     403      if (zoomInButton.Checked) Mode = ChartMode.ZoomIn;
     404    }
     405
     406    protected virtual void ZoomOutButtonOnCheckedChanged(object sender, EventArgs e) {
     407      if (zoomOutButton.Checked) Mode = ChartMode.ZoomOut;
     408    }
     409
     410    private void ChartControl_Load(object sender, EventArgs e) {
     411      if (!SuppressRender) GenerateImage();
    294412    }
    295413  }
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartMode.cs

    r12536 r13045  
    2121
    2222namespace HeuristicLab.Visualization {
    23   public enum ChartMode {
    24     Move,
    25     Zoom,
    26     Select
     23  public class ChartMode {
     24    protected ChartMode() { }
     25
     26    public static readonly ChartMode Select = new ChartMode();
     27    public static readonly ChartMode Move = new ChartMode();
     28    public static readonly ChartMode ZoomIn = new ChartMode();
     29    public static readonly ChartMode ZoomOut = new ChartMode();
    2730  }
    2831}
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/HeuristicLab.Visualization-3.3.csproj

    r12536 r13045  
    104104  </PropertyGroup>
    105105  <ItemGroup>
    106     <Reference Include="HeuristicLab.PluginInfrastructure-3.3">
    107       <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
     106    <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     107      <SpecificVersion>False</SpecificVersion>
     108      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath>
     109      <Private>False</Private>
     110    </Reference>
     111    <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     112      <SpecificVersion>False</SpecificVersion>
     113      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
     114      <Private>False</Private>
    108115    </Reference>
    109116    <Reference Include="System" />
     
    123130    <Compile Include="ChartMode.cs" />
    124131    <Compile Include="AxisType.cs" />
     132    <Compile Include="Primitives\Grid.cs" />
     133    <Compile Include="Properties\Resources.Designer.cs">
     134      <AutoGen>True</AutoGen>
     135      <DesignTime>True</DesignTime>
     136      <DependentUpon>Resources.resx</DependentUpon>
     137    </Compile>
    125138    <Compile Include="Trees\LayoutEngines\BoxesLayoutEngine.cs" />
    126139    <Compile Include="Trees\LayoutEngines\ILayoutEngine.cs" />
     
    131144    <None Include="Plugin.cs.frame" />
    132145    <Compile Include="Plugin.cs" />
     146    <Compile Include="Interfaces\IGrid.cs" />
    133147    <Compile Include="Interfaces\IGroup.cs" />
    134148    <Compile Include="Interfaces\IChart.cs" />
     
    159173  </ItemGroup>
    160174  <ItemGroup>
    161     <EmbeddedResource Include="ChartControl.resx">
    162       <DependentUpon>ChartControl.cs</DependentUpon>
    163       <SubType>Designer</SubType>
     175    <EmbeddedResource Include="Properties\Resources.resx">
     176      <Generator>ResXFileCodeGenerator</Generator>
     177      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
    164178    </EmbeddedResource>
    165     <EmbeddedResource Include="PropertiesDialog.resx">
    166       <DependentUpon>PropertiesDialog.cs</DependentUpon>
    167       <SubType>Designer</SubType>
    168     </EmbeddedResource>
    169   </ItemGroup>
    170   <ItemGroup>
    171     <None Include="ClassDiagram.cd" />
     179  </ItemGroup>
     180  <ItemGroup>
    172181    <None Include="HeuristicLab.snk" />
    173182    <None Include="Properties\AssemblyInfo.frame" />
     
    190199    </BootstrapperPackage>
    191200  </ItemGroup>
     201  <ItemGroup>
     202    <EmbeddedResource Include="Resources\Hand.cur" />
     203  </ItemGroup>
     204  <ItemGroup>
     205    <EmbeddedResource Include="Resources\ZoomIn.cur" />
     206  </ItemGroup>
     207  <ItemGroup>
     208    <EmbeddedResource Include="Resources\ZoomOut.cur" />
     209  </ItemGroup>
    192210  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
    193211  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Interfaces/IChart.cs

    r12536 r13045  
    2727namespace HeuristicLab.Visualization {
    2828  public interface IChart {
    29     ChartMode Mode { get; set; }
     29    bool Enabled { get; set; }
     30
    3031    PointD LowerLeft { get; }
    3132    PointD UpperRight { get; }
     
    3536    SizeD WorldToPixelRatio { get; }
    3637    IGroup Group { get; }
    37     bool UpdateEnabled { get; }
    3838
    3939    PointD TransformPixelToWorld(Point point);
     
    4343
    4444    void SetPosition(PointD lowerLeft, PointD upperRight);
    45     void SetPosition(double x1, double y1, double x2, double y2);
    4645    void Move(Offset delta);
    47     void Move(double dx, double dy);
    4846
     47    void ZoomIn(Point mousePosition);
    4948    void ZoomIn(PointD lowerLeft, PointD upperRight);
    50     void ZoomIn(double x1, double y1, double x2, double y2);
    5149    void ZoomIn(Point lowerLeft, Point upperRight);
    52     void ZoomIn(int x1, int y1, int x2, int y2);
    5350    void ZoomOut();
    5451    void Unzoom();
    5552
     53    void IntoForeground(IPrimitive primitive);
     54    void IntoBackground(IPrimitive primitive);
     55    void OneLayerUp(IPrimitive primitive);
     56    void OneLayerDown(IPrimitive primitive);
     57
     58    string GetToolTipText(Point point);
     59    Cursor GetCursor(Point point);
     60
    5661    IPrimitive GetPrimitive(Point point);
    57     IPrimitive GetPrimitive(int x, int y);
    58     IList<IPrimitive> GetAllPrimitives(Point point);
    59     IList<IPrimitive> GetAllPrimitives(int x, int y);
    60 
    61     Cursor GetCursor(Point point);
    62     Cursor GetCursor(int x, int y);
    63     string GetToolTipText(Point point);
    64     string GetToolTipText(int x, int y);
    65 
    66     void MouseClick(Point point, MouseButtons button);
    67     void MouseClick(int x, int y, MouseButtons button);
    68     void MouseDoubleClick(Point point, MouseButtons button);
    69     void MouseDoubleClick(int x, int y, MouseButtons button);
    70     void MouseMove(Point start, Point end);
    71     void MouseMove(int x1, int y1, int x2, int y2);
    72     void MouseDrag(Point start, Point end, MouseButtons button);
    73     void MouseDrag(int x1, int y1, int x2, int y2, MouseButtons button);
     62    IEnumerable<IPrimitive> GetAllPrimitives(Point point);
    7463
    7564    void Render(Graphics graphics, int width, int height);
    7665
    77     event EventHandler Update;
    78     void EnforceUpdate();
     66    event EventHandler RedrawRequired;
     67    void RaiseRedrawRequired();
    7968  }
    8069}
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Interfaces/IGroup.cs

    r12535 r13045  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Collections.ObjectModel;
    25 using System.Text;
    2624
    2725namespace HeuristicLab.Visualization {
    28   public interface IGroup : IPrimitive {
    29     ReadOnlyCollection<IPrimitive> Primitives { get; }
    30     ReadOnlyCollection<IPrimitive> SelectedPrimitives { get; }
     26  public interface IGroup : IPrimitive, IEnumerable<IPrimitive> {
     27    IEnumerable<IPrimitive> Primitives { get; }
     28    IEnumerable<IPrimitive> SelectedPrimitives { get; }
    3129
    3230    void Add(IPrimitive primitive);
     
    3735
    3836    IPrimitive GetPrimitive(PointD point);
    39     IPrimitive GetPrimitive(double x, double y);
    40     IList<IPrimitive> GetAllPrimitives(PointD point);
    41     IList<IPrimitive> GetAllPrimitives(double x, double y);
     37    IEnumerable<IPrimitive> GetAllPrimitives(PointD point);
    4238
    4339    void OneLayerUp(IPrimitive primitive);
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Interfaces/IPrimitive.cs

    r12535 r13045  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using System.Drawing;
    2624using System.Windows.Forms;
     
    2826namespace HeuristicLab.Visualization {
    2927  public interface IPrimitive {
    30     IChart Chart { get; }
    31     IGroup Group { get; set; }
    3228    Pen Pen { get; set; }
    3329    Brush Brush { get; set; }
    34     bool UpdateEnabled { get; }
    3530    bool Selected { get; set; }
    3631    string ToolTipText { get; set; }
     
    3833
    3934    void Move(Offset delta);
    40     void Move(double dx, double dy);
     35    void Move(PointD point, Offset delta);
     36
     37    void SnapToGrid(IGrid grid);
     38    void SnapToGrid(PointD point, IGrid grid);
    4139
    4240    bool ContainsPoint(PointD point);
    43     bool ContainsPoint(double x, double y);
    44 
    4541    Cursor GetCursor(PointD point);
    46     Cursor GetCursor(double x, double y);
    4742    string GetToolTipText(PointD point);
    48     string GetToolTipText(double x, double y);
    49 
    50     void OneLayerUp();
    51     void OneLayerDown();
    52     void IntoForeground();
    53     void IntoBackground();
    54 
    55     void MouseClick(PointD point, MouseButtons button);
    56     void MouseClick(double x, double y, MouseButtons button);
    57     void MouseDoubleClick(PointD point, MouseButtons button);
    58     void MouseDoubleClick(double x, double y, MouseButtons button);
    59     void MouseMove(PointD point, Offset offset);
    60     void MouseMove(double x, double y, double dx, double dy);
    61     void MouseDrag(PointD point, Offset offset, MouseButtons button);
    62     void MouseDrag(double x, double y, double dx, double dy, MouseButtons button);
    6343
    6444    void PreDraw(Graphics graphics);
     
    6646    void PostDraw(Graphics graphics);
    6747
    68     event EventHandler Update;
    69     void EnforceUpdate();
     48    event EventHandler RedrawRequired;
    7049  }
    7150}
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Plugin.cs.frame

    r12535 r13045  
    2626
    2727namespace HeuristicLab.Visualization {
    28   [Plugin("HeuristicLab.Visualization", "3.3.1.$WCREV$")]
     28  [Plugin("HeuristicLab.Visualization", "3.3.12.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Visualization-3.3.dll", PluginFileType.Assembly)]
     30  [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
    3031  public class HeuristicLabVisualizationPlugin : PluginBase { }
    3132}
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/Axis.cs

    r12535 r13045  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using System.Drawing;
    2624
    2725namespace HeuristicLab.Visualization {
    2826  public class Axis : AxisPrimitiveBase {
     27    protected const int PixelsPerInterval = 100;
     28
    2929    public Axis(IChart chart, PointD point, AxisType axisType)
    3030      : base(chart, point, axisType) {
    31     }
    32     public Axis(IChart chart, double x, double y, AxisType axisType)
    33       : this(chart, new PointD(x, y), axisType) {
    3431    }
    3532    public Axis(IChart chart, PointD point, AxisType axisType, Pen pen, Brush brush)
    3633      : base(chart, point, axisType, pen, brush) {
    3734    }
    38     public Axis(IChart chart, double x, double y, AxisType axisType, Pen pen, Brush brush)
    39       : this(chart, new PointD(x, y), axisType, pen, brush) {
    40     }
    4135
    4236    public override void Draw(Graphics graphics) {
    43       int pixelsPerInterval = 100;
    44       Font axisValuesFont = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular, GraphicsUnit.Pixel);
    45       Font axisLabelsFont = new Font(FontFamily.GenericSansSerif, 14, FontStyle.Regular, GraphicsUnit.Pixel);
     37      var axisValuesFont = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular, GraphicsUnit.Pixel);
     38      var axisLabelsFont = new Font(FontFamily.GenericSansSerif, 14, FontStyle.Regular, GraphicsUnit.Pixel);
    4639
    4740      if ((AxisType & AxisType.Horizontal) == AxisType.Horizontal) {
    48         int intervals = Chart.SizeInPixels.Width / pixelsPerInterval;
     41        int intervals = Chart.SizeInPixels.Width / PixelsPerInterval;
    4942
    5043        if (intervals > 0) {
     
    5750
    5851          double x = Math.Floor(Chart.LowerLeft.X / step) * step;
    59           PointD current = new PointD(x, Point.Y);
     52          var current = new PointD(x, Point.Y);
    6053          while (current.X <= Chart.UpperRight.X) {
    6154            Point p = Chart.TransformWorldToPixel(current);
     
    8376      }
    8477      if ((AxisType & AxisType.Vertical) == AxisType.Vertical) {
    85         int intervals = Chart.SizeInPixels.Height / pixelsPerInterval;
     78        int intervals = Chart.SizeInPixels.Height / PixelsPerInterval;
    8679
    8780        if (intervals > 0) {
     
    9487
    9588          double y = Math.Floor(Chart.LowerLeft.Y / step) * step;
    96           PointD current = new PointD(Point.X, y);
     89          var current = new PointD(Point.X, y);
    9790          while (current.Y <= Chart.UpperRight.Y) {
    9891            Point p = Chart.TransformWorldToPixel(current);
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/AxisPrimitiveBase.cs

    r12535 r13045  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using System.Drawing;
    2623
     
    4138        if (value != myShowGrid) {
    4239          myShowGrid = value;
    43           OnUpdate();
     40          OnRedrawRequired();
    4441        }
    4542      }
     
    5148        if (value != myHorizontalLabel) {
    5249          myHorizontalLabel = value;
    53           OnUpdate();
     50          OnRedrawRequired();
    5451        }
    5552      }
     
    6158        if (value != myVerticalLabel) {
    6259          myVerticalLabel = value;
    63           OnUpdate();
     60          OnRedrawRequired();
    6461        }
    6562      }
     
    6764
    6865    protected AxisPrimitiveBase(IChart chart, PointD point, AxisType axisType)
    69       : base(chart) {
    70       Brush = Brushes.Black;
    71       myPoint = point;
    72       myAxisType = axisType;
    73       myShowGrid = true;
    74     }
    75     protected AxisPrimitiveBase(IChart chart, double x, double y, AxisType axisType)
    76       : this(chart, new PointD(x, y), axisType) {
    77     }
     66      : this(chart, point, axisType, Pens.Black, Brushes.Black) { }
    7867    protected AxisPrimitiveBase(IChart chart, PointD point, AxisType axisType, Pen pen, Brush brush)
    7968      : base(chart, pen, brush) {
     
    8271      myShowGrid = true;
    8372    }
    84     protected AxisPrimitiveBase(IChart chart, double x, double y, AxisType axisType, Pen pen, Brush brush)
    85       : this(chart, new PointD(x, y), axisType, pen, brush) {
    86     }
    8773
    8874    public virtual void SetPosition(PointD point) {
    8975      myPoint = point;
    90       OnUpdate();
     76      OnRedrawRequired();
    9177    }
    92     public void SetPosition(double x, double y) {
    93       SetPosition(new PointD(x, y));
    94     }
     78
    9579    public override void Move(Offset delta) {
    9680      SetPosition(Point + delta);
    9781    }
    9882
     83    public override void Move(PointD point, Offset delta) {
     84      Move(delta);
     85    }
     86
     87    public override void SnapToGrid(IGrid grid) {
     88      Move(grid.GetBottomLeftGridPoint(myPoint) - myPoint);
     89    }
     90
     91    public override void SnapToGrid(PointD point, IGrid grid) {
     92      SnapToGrid(grid);
     93    }
     94
    9995    public override bool ContainsPoint(PointD point) {
    100       SizeD size = Chart.TransformPixelToWorld(new Size(5, 5));
     96      var size = Chart.TransformPixelToWorld(new Size(5, 5));
    10197      bool result = false;
    10298      if ((AxisType & AxisType.Horizontal) == AxisType.Horizontal)
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/Ellipse.cs

    r12535 r13045  
    2828      : base(chart, lowerLeft, upperRight) {
    2929    }
    30     public Ellipse(IChart chart, double x1, double y1, double x2, double y2)
    31       : this(chart, new PointD(x1, y1), new PointD(x2, y2)) {
    32     }
    3330    public Ellipse(IChart chart, PointD lowerLeft, PointD upperRight, Pen pen, Brush brush)
    3431      : base(chart, lowerLeft, upperRight, pen, brush) {
    35     }
    36     public Ellipse(IChart chart, double x1, double y1, double x2, double y2, Pen pen, Brush brush)
    37       : this(chart, new PointD(x1, y1), new PointD(x2, y2), pen, brush) {
    3832    }
    3933
     
    6761
    6862    public override void Draw(Graphics graphics) {
    69       Point p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height));
    70       Size s = Chart.TransformWorldToPixel(Size);
     63      var p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height));
     64      var s = Chart.TransformWorldToPixel(Size);
    7165      if (Brush != null)
    7266        graphics.FillEllipse(Brush, p.X, p.Y, s.Width, s.Height);
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/FixedSizeCircle.cs

    r12535 r13045  
    2727      : base(chart, point, new Size(diameter, diameter)) {
    2828    }
    29     public FixedSizeCircle(IChart chart, double x, double y, int diameter)
    30       : this(chart, new PointD(x, y), diameter) {
    31     }
    3229    public FixedSizeCircle(IChart chart, PointD point, int diameter, Pen pen, Brush brush)
    3330      : base(chart, point, new Size(diameter, diameter), pen, brush) {
    34     }
    35     public FixedSizeCircle(IChart chart, double x, double y, int diameter, Pen pen, Brush brush)
    36       : this(chart, new PointD(x, y), diameter, pen, brush) {
    3731    }
    3832
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/FixedSizePrimitiveBase.cs

    r12535 r13045  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using System.Drawing;
    2624
     
    4139      mySize = size;
    4240    }
    43     protected FixedSizePrimitiveBase(IChart chart, double x, double y, Size size)
    44       : this(chart, new PointD(x, y), size) {
    45     }
    4641    protected FixedSizePrimitiveBase(IChart chart, PointD point, Size size, Pen pen, Brush brush)
    4742      : base(chart, pen, brush) {
     
    4944      mySize = size;
    5045    }
    51     protected FixedSizePrimitiveBase(IChart chart, double x, double y, Size size, Pen pen, Brush brush)
    52       : this(chart, new PointD(x, y), size, pen, brush) {
    53     }
    5446
    5547    public virtual void SetPosition(PointD point) {
    5648      myPoint = point;
    57       OnUpdate();
     49      OnRedrawRequired();
    5850    }
    59     public void SetPosition(double x, double y) {
     51
     52    public override void Move(Offset delta) {
     53      SetPosition(Point + delta);
     54    }
     55
     56    public override void Move(PointD point, Offset delta) {
     57      Move(delta);
     58    }
     59
     60    public override void SnapToGrid(IGrid grid) {
     61      var bl = grid.GetBottomLeftGridPoint(Point);
     62      var ur = grid.GetUpperRightGridPoint(Point);
     63      var x = Math.Abs(bl.X - Point.X) <= Math.Abs(ur.X - Point.X) ? bl.X : ur.X;
     64      var y = Math.Abs(bl.Y - Point.Y) <= Math.Abs(ur.Y - Point.Y) ? bl.Y : ur.Y;
    6065      SetPosition(new PointD(x, y));
    6166    }
    62     public override void Move(Offset delta) {
    63       SetPosition(Point + delta);
     67
     68    public override void SnapToGrid(PointD point, IGrid grid) {
     69      SnapToGrid(grid);
    6470    }
    6571
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/FixedSizeRectangle.cs

    r12535 r13045  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using System.Drawing;
    2623
     
    3027      : base(chart, point, size) {
    3128    }
    32     public FixedSizeRectangle(IChart chart, double x, double y, Size size)
    33       : this(chart, new PointD(x, y), size) {
    34     }
    3529    public FixedSizeRectangle(IChart chart, PointD point, Size size, Pen pen, Brush brush)
    3630      : base(chart, point, size, pen, brush) {
    37     }
    38     public FixedSizeRectangle(IChart chart, double x, double y, Size size, Pen pen, Brush brush)
    39       : this(chart, new PointD(x, y), size, pen, brush) {
    4031    }
    4132
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/Group.cs

    r12535 r13045  
    2121
    2222using System;
     23using System.Collections;
    2324using System.Collections.Generic;
    24 using System.Collections.ObjectModel;
    2525using System.Drawing;
    2626using System.Linq;
     
    2929namespace HeuristicLab.Visualization {
    3030  public class Group : PrimitiveBase, IGroup {
    31     private LinkedList<IPrimitive> myPrimitives;
    32     private HashSet<IPrimitive> myPrimitivesLookup;
    33     public virtual ReadOnlyCollection<IPrimitive> Primitives {
    34       get { return new ReadOnlyCollection<IPrimitive>(new List<IPrimitive>(myPrimitives)); }
    35     }
    36     public virtual ReadOnlyCollection<IPrimitive> SelectedPrimitives {
    37       get {
    38         List<IPrimitive> selected = new List<IPrimitive>();
    39         foreach (IPrimitive primitive in myPrimitives) {
    40           if (primitive.Selected) selected.Add(primitive);
    41         }
    42         return new ReadOnlyCollection<IPrimitive>(selected);
    43       }
    44     }
     31    private readonly LinkedList<IPrimitive> primitives;
     32    private readonly HashSet<IPrimitive> primitivesLookup;
     33
     34    public virtual IEnumerable<IPrimitive> Primitives {
     35      get { return primitives.ToArray(); }
     36    }
     37    public virtual IEnumerable<IPrimitive> SelectedPrimitives {
     38      get { return primitives.Where(x => x.Selected).ToArray(); }
     39    }
     40
    4541    public override bool Selected {
    4642      get { return base.Selected; }
    4743      set {
    48         bool updateEnabled = UpdateEnabled;
    49         UpdateEnabled = false;
    50         foreach (IPrimitive primitive in myPrimitives)
    51           primitive.Selected = value;
    52         UpdateEnabled = updateEnabled;
    53         base.Selected = value;
     44        SuppressEvents = true;
     45        try {
     46          foreach (var primitive in primitives)
     47            primitive.Selected = value;
     48          base.Selected = value;
     49        } finally {
     50          SuppressEvents = false;
     51          OnRedrawRequired();
     52        }
    5453      }
    5554    }
     
    5756    public Group(IChart chart)
    5857      : base(chart) {
    59       myPrimitives = new LinkedList<IPrimitive>();
    60       myPrimitivesLookup = new HashSet<IPrimitive>();
     58      primitives = new LinkedList<IPrimitive>();
     59      primitivesLookup = new HashSet<IPrimitive>();
    6160    }
    6261
    6362    public virtual void Add(IPrimitive primitive) {
    64       if (Contains(primitive))
    65         throw new ArgumentException("Primitive already added");
    66 
    67       myPrimitives.AddFirst(primitive);
    68       myPrimitivesLookup.Add(primitive);
    69       primitive.Group = this;
    70       primitive.Update += new EventHandler(primitive_Update);
    71       OnUpdate();
     63      if (Contains(primitive)) throw new ArgumentException("Primitive already added");
     64      primitives.AddFirst(primitive);
     65      primitivesLookup.Add(primitive);
     66      primitive.RedrawRequired += PrimitiveOnRedrawRequired;
     67      OnRedrawRequired();
    7268    }
    7369    public virtual void AddRange(IEnumerable<IPrimitive> primitives) {
    74       foreach (IPrimitive primitive in primitives) {
    75         if (Contains(primitive))
    76           throw new ArgumentException("Primitive already added");
    77 
    78         myPrimitives.AddFirst(primitive);
    79         myPrimitivesLookup.Add(primitive);
    80         primitive.Group = this;
    81         primitive.Update += new EventHandler(primitive_Update);
    82       }
    83       OnUpdate();
    84     }
     70      foreach (var primitive in this.primitives) {
     71        if (Contains(primitive)) throw new ArgumentException("Primitive already added");
     72        this.primitives.AddFirst(primitive);
     73        primitivesLookup.Add(primitive);
     74        primitive.RedrawRequired += PrimitiveOnRedrawRequired;
     75      }
     76      OnRedrawRequired();
     77    }
     78
    8579    public virtual bool Contains(IPrimitive primitive) {
    86       return myPrimitivesLookup.Contains(primitive);
    87     }
     80      return primitivesLookup.Contains(primitive);
     81    }
     82
    8883    public virtual bool Remove(IPrimitive primitive) {
    89       if (myPrimitives.Remove(primitive)) {
    90         primitive.Group = null;
    91         primitive.Update -= new EventHandler(primitive_Update);
    92         OnUpdate();
    93         return true;
    94       } else {
    95         return false;
    96       }
    97     }
     84      if (!primitives.Remove(primitive)) return false;
     85      primitivesLookup.Remove(primitive);
     86
     87      primitive.RedrawRequired -= PrimitiveOnRedrawRequired;
     88      OnRedrawRequired();
     89      return true;
     90    }
     91
    9892    public virtual void Clear() {
    99       foreach (IPrimitive primitive in myPrimitives) {
    100         primitive.Group = null;
    101         primitive.Update -= new EventHandler(primitive_Update);
    102       }
    103       myPrimitives.Clear();
    104       myPrimitivesLookup.Clear();
    105       OnUpdate();
     93      foreach (var primitive in primitives) {
     94        primitive.RedrawRequired -= PrimitiveOnRedrawRequired;
     95      }
     96      primitives.Clear();
     97      primitivesLookup.Clear();
     98      OnRedrawRequired();
    10699    }
    107100
    108101    public virtual IPrimitive GetPrimitive(PointD point) {
    109       return myPrimitives.FirstOrDefault(primitive => primitive.ContainsPoint(point));
    110     }
    111 
    112     public IPrimitive GetPrimitive(double x, double y) {
    113       return GetPrimitive(new PointD(x, y));
    114     }
    115     public virtual IList<IPrimitive> GetAllPrimitives(PointD point) {
    116       var primitives = new List<IPrimitive>();
    117       foreach (var primitive in myPrimitives.Where(primitive => primitive.ContainsPoint(point))) {
    118         primitives.Add(primitive);
     102      return primitives.FirstOrDefault(primitive => primitive.ContainsPoint(point));
     103    }
     104
     105    public virtual IEnumerable<IPrimitive> GetAllPrimitives(PointD point) {
     106      var result = new List<IPrimitive>();
     107      foreach (var primitive in primitives.Where(primitive => primitive.ContainsPoint(point))) {
     108        result.Add(primitive);
    119109        var group = primitive as IGroup;
    120110        if (group != null)
    121           primitives.AddRange(group.Primitives);
    122       }
    123       return primitives;
    124     }
    125     public IList<IPrimitive> GetAllPrimitives(double x, double y) {
    126       return GetAllPrimitives(new PointD(x, y));
     111          result.AddRange(group.GetAllPrimitives(point));
     112      }
     113      return result;
    127114    }
    128115
    129116    public override void Move(Offset delta) {
    130       bool updateEnabled = UpdateEnabled;
    131       UpdateEnabled = false;
    132       foreach (IPrimitive primitive in myPrimitives)
    133         primitive.Move(delta);
    134       UpdateEnabled = updateEnabled;
    135       OnUpdate();
     117      SuppressEvents = true;
     118      try {
     119        foreach (var primitive in primitives)
     120          primitive.Move(delta);
     121      } finally {
     122        SuppressEvents = false;
     123        OnRedrawRequired();
     124      }
     125    }
     126
     127    public override void Move(PointD point, Offset delta) {
     128      SuppressEvents = true;
     129      try {
     130        foreach (var primitive in primitives)
     131          primitive.Move(point, delta);
     132      } finally {
     133        SuppressEvents = false;
     134        OnRedrawRequired();
     135      }
     136    }
     137
     138    public override void SnapToGrid(IGrid grid) {
     139      SuppressEvents = true;
     140      try {
     141        foreach (var primitive in primitives)
     142          primitive.SnapToGrid(grid);
     143      } finally {
     144        SuppressEvents = false;
     145        OnRedrawRequired();
     146      }
     147    }
     148
     149    public override void SnapToGrid(PointD point, IGrid grid) {
     150      SuppressEvents = true;
     151      try {
     152        foreach (var primitive in primitives)
     153          primitive.SnapToGrid(point, grid);
     154      } finally {
     155        SuppressEvents = false;
     156        OnRedrawRequired();
     157      }
    136158    }
    137159
     
    141163
    142164    public override Cursor GetCursor(PointD point) {
    143       IPrimitive primitive = GetPrimitive(point);
    144       if (primitive != null) return primitive.GetCursor(point);
    145       else return base.GetCursor(point);
    146     }
     165      var primitive = GetPrimitive(point);
     166      return primitive != null ? primitive.GetCursor(point) : base.GetCursor(point);
     167    }
     168
    147169    public override string GetToolTipText(PointD point) {
    148       IPrimitive primitive = GetPrimitive(point);
    149       if (primitive != null) return primitive.GetToolTipText(point);
    150       else return base.GetToolTipText(point);
     170      var primitive = GetPrimitive(point);
     171      return primitive != null ? primitive.GetToolTipText(point) : base.GetToolTipText(point);
    151172    }
    152173
    153174    public void OneLayerUp(IPrimitive primitive) {
    154       if (!Contains(primitive))
    155         throw new ArgumentException("Primitive not found");
    156 
    157       var curr = myPrimitives.Find(primitive);
     175      if (!Contains(primitive)) throw new ArgumentException("Primitive not found");
     176
     177      var curr = primitives.Find(primitive);
    158178      if (curr == null) return;
    159179      var prev = curr.Previous;
     
    162182      prev.Value = temp;
    163183
    164       OnUpdate();
    165     }
    166 
     184      OnRedrawRequired();
     185    }
    167186    public void OneLayerDown(IPrimitive primitive) {
    168       if (!Contains(primitive))
    169         throw new ArgumentException("Primitive not found");
    170 
    171       var curr = myPrimitives.Find(primitive);
     187      if (!Contains(primitive)) throw new ArgumentException("Primitive not found");
     188
     189      var curr = primitives.Find(primitive);
    172190      if (curr == null) return;
    173191      var next = curr.Next;
     
    177195    }
    178196    public void IntoForeground(IPrimitive primitive) {
    179       if (!Contains(primitive))
    180         throw new ArgumentException("Primitive not found");
    181 
    182       myPrimitives.Remove(primitive);
    183       myPrimitives.AddFirst(primitive);
    184       OnUpdate();
     197      if (!Contains(primitive)) throw new ArgumentException("Primitive not found");
     198      primitives.Remove(primitive);
     199      primitives.AddFirst(primitive);
     200      OnRedrawRequired();
    185201    }
    186202    public void IntoBackground(IPrimitive primitive) {
    187       if (!Contains(primitive))
    188         throw new ArgumentException("Primitive not found");
    189 
    190       myPrimitives.Remove(primitive);
    191       myPrimitives.AddLast(primitive);
    192       OnUpdate();
     203      if (!Contains(primitive)) throw new ArgumentException("Primitive not found");
     204
     205      primitives.Remove(primitive);
     206      primitives.AddLast(primitive);
     207      OnRedrawRequired();
    193208    }
    194209
    195210    public override void Draw(Graphics graphics) {
    196       var current = myPrimitives.Last;
     211      var current = primitives.Last;
    197212      while (current != null) {
    198213        var primitive = current.Value;
     
    204219    }
    205220
    206     private void primitive_Update(object sender, EventArgs e) {
    207       OnUpdate();
     221    private void PrimitiveOnRedrawRequired(object sender, EventArgs e) {
     222      if (SuppressEvents) return;
     223      OnRedrawRequired();
     224    }
     225
     226    public IEnumerator<IPrimitive> GetEnumerator() {
     227      return primitives.GetEnumerator();
     228    }
     229
     230    IEnumerator IEnumerable.GetEnumerator() {
     231      return GetEnumerator();
    208232    }
    209233  }
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/Line.cs

    r12536 r13045  
    2828      : base(chart, start, end) {
    2929    }
    30     public Line(IChart chart, double x1, double y1, double x2, double y2)
    31       : this(chart, new PointD(x1, y1), new PointD(x2, y2)) {
    32     }
    3330    public Line(IChart chart, PointD start, PointD end, Pen pen)
    3431      : base(chart, start, end, pen, null) {
    35     }
    36     public Line(IChart chart, double x1, double y1, double x2, double y2, Pen pen)
    37       : this(chart, new PointD(x1, y1), new PointD(x2, y2), pen) {
    3832    }
    3933
     
    4135      if (base.ContainsPoint(point)) return true;
    4236
    43       double penWidthX = Chart.PixelToWorldRatio.Width * (Pen.Width + 1);
    44       double penWidthY = Chart.PixelToWorldRatio.Height * (Pen.Width + 1);
     37      double penWidthX = Chart.PixelToWorldRatio.Width * (Pen.Width + 3);
     38      double penWidthY = Chart.PixelToWorldRatio.Height * (Pen.Width + 3);
    4539
    4640      if ((point.X < (Math.Min(Start.X, End.X) - (penWidthX / 2))) ||
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/LinearPrimitiveBase.cs

    r12535 r13045  
    2020#endregion
    2121
     22using System;
    2223using System.Drawing;
    2324using System.Drawing.Drawing2D;
     
    2627namespace HeuristicLab.Visualization {
    2728  public abstract class LinearPrimitiveBase : PrimitiveBase {
    28     protected IGroup selectionRectangles;
     29    protected IGroup SelectionRectangles;
    2930
    3031    private PointD myStart;
     
    4546    protected LinearPrimitiveBase(IChart chart, PointD start, PointD end)
    4647      : base(chart) {
    47       selectionRectangles = new Group(chart);
     48      SelectionRectangles = new Group(chart);
    4849      myStart = start;
    4950      myEnd = end;
    5051    }
    51     protected LinearPrimitiveBase(IChart chart, double x1, double y1, double x2, double y2)
    52       : this(chart, new PointD(x1, y1), new PointD(x2, y2)) {
    53     }
    5452    protected LinearPrimitiveBase(IChart chart, PointD start, PointD end, Pen pen, Brush brush)
    5553      : base(chart, pen, brush) {
    56       selectionRectangles = new Group(chart);
     54      SelectionRectangles = new Group(chart);
    5755      myStart = start;
    5856      myEnd = end;
    59     }
    60     protected LinearPrimitiveBase(IChart chart, double x1, double y1, double x2, double y2, Pen pen, Brush brush)
    61       : this(chart, new PointD(x1, y1), new PointD(x2, y2), pen, brush) {
    6257    }
    6358
     
    6560      myStart = start;
    6661      myEnd = end;
    67       OnUpdate();
     62      OnRedrawRequired();
    6863    }
    69     public void SetPosition(double x1, double y1, double x2, double y2) {
    70       SetPosition(new PointD(x1, y1), new PointD(x2, y2));
    71     }
     64
    7265    public override void Move(Offset delta) {
    7366      SetPosition(Start + delta, End + delta);
    7467    }
    7568
    76     public override bool ContainsPoint(PointD point) {
    77       if (Selected) {
    78         if (selectionRectangles.GetPrimitive(point) != null) return true;
    79       }
    80       return false;
     69    public override void Move(PointD point, Offset delta) {
     70      if (Selected && SelectionRectangles.ContainsPoint(point)) {
     71        var rect = (SelectionRectangle)SelectionRectangles.GetPrimitive(point);
     72        if (rect.Point == Start) {
     73          SetPosition(Start + delta, End);
     74        } else if (rect.Point == End) {
     75          SetPosition(Start, End + delta);
     76        }
     77      } else SetPosition(Start + delta, End + delta);
    8178    }
    8279
    83     public override void MouseDrag(PointD point, Offset offset, MouseButtons button) {
    84       if (button == MouseButtons.Left) {
    85         if (Selected) {
    86           if (selectionRectangles.ContainsPoint(point)) {
    87             SelectionRectangle rect = (SelectionRectangle)selectionRectangles.GetPrimitive(point);
    88             if (rect.Point == Start) {
    89               SetPosition(Start + offset, End);
    90             } else if (rect.Point == End) {
    91               SetPosition(Start, End + offset);
    92             }
    93           } else {
    94             base.MouseDrag(point, offset, button);
    95           }
     80    public override void SnapToGrid(IGrid grid) {
     81      var bl = grid.GetBottomLeftGridPoint(Start);
     82      var ur = grid.GetUpperRightGridPoint(Start);
     83      var sx = Math.Abs(bl.X - Start.X) <= Math.Abs(ur.X - Start.X) ? bl.X : ur.X;
     84      var sy = Math.Abs(bl.Y - Start.Y) <= Math.Abs(ur.Y - Start.Y) ? bl.Y : ur.Y;
     85
     86      var end = new PointD(End.X + (sx - Start.X), End.Y + (sy - Start.Y));
     87
     88      bl = grid.GetBottomLeftGridPoint(end);
     89      ur = grid.GetUpperRightGridPoint(end);
     90      var ex = Math.Abs(bl.X - end.X) <= Math.Abs(ur.X - end.X) ? bl.X : ur.X;
     91      var ey = Math.Abs(bl.Y - end.Y) <= Math.Abs(ur.Y - end.Y) ? bl.Y : ur.Y;
     92
     93      SetPosition(new PointD(sx, sy), new PointD(ex, ey));
     94    }
     95
     96    public override void SnapToGrid(PointD point, IGrid grid) {
     97      if (Selected && SelectionRectangles.ContainsPoint(point)) {
     98        var rect = (SelectionRectangle)SelectionRectangles.GetPrimitive(point);
     99        if (rect.Point == Start) {
     100          var bl = grid.GetBottomLeftGridPoint(Start);
     101          var ur = grid.GetUpperRightGridPoint(Start);
     102          var sx = Math.Abs(bl.X - Start.X) <= Math.Abs(ur.X - Start.X) ? bl.X : ur.X;
     103          var sy = Math.Abs(bl.Y - Start.Y) <= Math.Abs(ur.Y - Start.Y) ? bl.Y : ur.Y;
     104          SetPosition(new PointD(sx, sy), End);
     105        } else if (rect.Point == End) {
     106          var bl = grid.GetBottomLeftGridPoint(End);
     107          var ur = grid.GetUpperRightGridPoint(End);
     108          var ex = Math.Abs(bl.X - End.X) <= Math.Abs(ur.X - End.X) ? bl.X : ur.X;
     109          var ey = Math.Abs(bl.Y - End.Y) <= Math.Abs(ur.Y - End.Y) ? bl.Y : ur.Y;
     110          SetPosition(Start, new PointD(ex, ey));
    96111        }
    97       }
     112      } else SnapToGrid(grid);
     113    }
     114
     115    public override bool ContainsPoint(PointD point) {
     116      if (Selected && SelectionRectangles.GetPrimitive(point) != null) return true;
     117      return false;
    98118    }
    99119
    100120    public override Cursor GetCursor(PointD point) {
    101121      if (Selected) {
    102         Cursor cursor = selectionRectangles.GetCursor(point);
     122        var cursor = SelectionRectangles.GetCursor(point);
    103123        if (cursor != null) return cursor;
    104124      }
     
    107127
    108128    public override void PostDraw(Graphics graphics) {
    109       selectionRectangles.Clear();
     129      SelectionRectangles.Clear();
    110130      if (Selected) {
    111         Pen pen = new Pen(Color.LightGray, 3);
    112         pen.DashStyle = DashStyle.Dash;
     131        var pen = new Pen(Color.LightGray, 3) { DashStyle = DashStyle.Dash };
    113132        graphics.DrawLine(pen,
    114133                          Chart.TransformWorldToPixel(Start),
    115134                          Chart.TransformWorldToPixel(End));
    116         selectionRectangles.Add(new SelectionRectangle(Chart, Start, Cursors.SizeAll));
    117         selectionRectangles.Add(new SelectionRectangle(Chart, End, Cursors.SizeAll));
     135        SelectionRectangles.Add(new SelectionRectangle(Chart, Start, Cursors.SizeAll));
     136        SelectionRectangles.Add(new SelectionRectangle(Chart, End, Cursors.SizeAll));
    118137
    119         selectionRectangles.Draw(graphics);
     138        SelectionRectangles.Draw(graphics);
    120139      }
    121140    }
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/PrimitiveBase.cs

    r12535 r13045  
    2626namespace HeuristicLab.Visualization {
    2727  public abstract class PrimitiveBase : IPrimitive {
    28     private IChart myChart;
     28    private readonly IChart chart;
    2929    public IChart Chart {
    30       get { return myChart; }
    31     }
    32     private IGroup myGroup;
    33     public IGroup Group {
    34       get { return myGroup; }
    35       set { myGroup = value; }
     30      get { return chart; }
    3631    }
    3732
    38     private Pen myPen;
     33    private Pen pen;
    3934    public virtual Pen Pen {
    40       get { return myPen; }
     35      get { return pen; }
    4136      set {
    42         myPen = value;
    43         OnUpdate();
     37        pen = value;
     38        OnRedrawRequired();
    4439      }
    4540    }
    46     private Brush myBrush;
     41    private Brush brush;
    4742    public virtual Brush Brush {
    48       get { return myBrush; }
     43      get { return brush; }
    4944      set {
    50         myBrush = value;
    51         OnUpdate();
     45        brush = value;
     46        OnRedrawRequired();
    5247      }
    5348    }
    5449
    55     private bool myUpdateEnabled;
    56     public bool UpdateEnabled {
    57       get { return myUpdateEnabled; }
    58       set { myUpdateEnabled = value; }
    59     }
     50    public string ToolTipText { get; set; }
    6051
    61     private bool mySelected;
     52    public object Tag { get; set; }
     53
     54    protected bool SuppressEvents { get; set; }
     55
     56    private bool selected;
    6257    public virtual bool Selected {
    63       get { return mySelected; }
     58      get { return selected; }
    6459      set {
    65         mySelected = value;
    66         OnUpdate();
     60        if (selected == value) return;
     61        selected = value;
     62        OnRedrawRequired();
    6763      }
    6864    }
    6965
    70     private string myToolTipText;
    71     public string ToolTipText {
    72       get { return myToolTipText; }
    73       set { myToolTipText = value; }
     66    protected PrimitiveBase(IChart chart)
     67      : this(chart, Pens.Black, Brushes.White) {
    7468    }
    75 
    76     private object myTag;
    77     public object Tag {
    78       get { return myTag; }
    79       set { myTag = value; }
    80     }
    81 
    82     protected PrimitiveBase(IChart chart) {
    83       myChart = chart;
    84       myGroup = null;
    85       myPen = Pens.Black;
    86       myBrush = Brushes.White;
    87       myUpdateEnabled = true;
    88       mySelected = false;
    89       myToolTipText = null;
    90       myTag = null;
    91     }
    92     protected PrimitiveBase(IChart chart, Pen pen, Brush brush)
    93       : this(chart) {
    94       myPen = pen;
    95       myBrush = brush;
     69    protected PrimitiveBase(IChart chart, Pen pen, Brush brush) {
     70      this.chart = chart;
     71      this.pen = pen;
     72      this.brush = brush;
     73      selected = false;
     74      ToolTipText = null;
     75      Tag = null;
    9676    }
    9777
    9878    public abstract void Move(Offset delta);
    99     public void Move(double dx, double dy) {
    100       Move(new Offset(dx, dy));
    101     }
     79    public abstract void Move(PointD point, Offset delta);
     80
     81    public abstract void SnapToGrid(IGrid grid);
     82    public abstract void SnapToGrid(PointD point, IGrid grid);
    10283
    10384    public abstract bool ContainsPoint(PointD point);
    104     public bool ContainsPoint(double x, double y) {
    105       return ContainsPoint(new PointD(x, y));
    106     }
    10785
    10886    public virtual Cursor GetCursor(PointD point) {
    10987      return null;
    11088    }
    111     public Cursor GetCursor(double x, double y) {
    112       return GetCursor(new PointD(x, y));
    113     }
     89
    11490    public virtual string GetToolTipText(PointD point) {
    11591      return ToolTipText;
    11692    }
    117     public string GetToolTipText(double x, double y) {
    118       return GetToolTipText(new PointD(x, y));
    119     }
    12093
    121     public void OneLayerUp() {
    122       Group.OneLayerUp(this);
    123     }
    124     public void OneLayerDown() {
    125       Group.OneLayerDown(this);
    126     }
    127     public void IntoForeground() {
    128       Group.IntoForeground(this);
    129     }
    130     public void IntoBackground() {
    131       Group.IntoBackground(this);
    132     }
     94    public virtual void PreDraw(Graphics graphics) { }
     95    public virtual void Draw(Graphics graphics) { }
     96    public virtual void PostDraw(Graphics graphics) { }
    13397
    134     public virtual void MouseClick(PointD point, MouseButtons button) {
    135       if (button == MouseButtons.Left) {
    136         Selected = true;
    137       }
    138     }
    139     public void MouseClick(double x, double y, MouseButtons button) {
    140       MouseClick(new PointD(x, y), button);
    141     }
    142     public virtual void MouseDoubleClick(PointD point, MouseButtons button) {
    143     }
    144     public void MouseDoubleClick(double x, double y, MouseButtons button) {
    145       MouseDoubleClick(new PointD(x, y), button);
    146     }
    147     public virtual void MouseMove(PointD point, Offset offset) {
    148     }
    149     public void MouseMove(double x, double y, double dx, double dy) {
    150       MouseMove(new PointD(x, y), new Offset(dx, dy));
    151     }
    152     public virtual void MouseDrag(PointD point, Offset offset, MouseButtons button) {
    153       if (button == MouseButtons.Left) {
    154         Move(offset);
    155       }
    156     }
    157     public void MouseDrag(double x, double y, double dx, double dy, MouseButtons button) {
    158       MouseDrag(new PointD(x, y), new Offset(dx, dy), button);
    159     }
    160 
    161     public virtual void PreDraw(Graphics graphics) {
    162     }
    163     public virtual void Draw(Graphics graphics) {
    164     }
    165     public virtual void PostDraw(Graphics graphics) {
    166     }
    167 
    168     public event EventHandler Update;
    169     public void EnforceUpdate() {
    170       if (Update != null) {
    171         Update(this, new EventArgs());
    172       }
    173     }
    174     protected virtual void OnUpdate() {
    175       if ((UpdateEnabled) && (Update != null)) {
    176         Update(this, new EventArgs());
    177       }
     98    public event EventHandler RedrawRequired;
     99    protected virtual void OnRedrawRequired() {
     100      var handler = RedrawRequired;
     101      if (!SuppressEvents && handler != null) handler(this, EventArgs.Empty);
    178102    }
    179103  }
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/Rectangle.cs

    r12536 r13045  
    2727      : base(chart, lowerLeft, upperRight) {
    2828    }
    29     public Rectangle(IChart chart, double x1, double y1, double x2, double y2)
    30       : this(chart, new PointD(x1, y1), new PointD(x2, y2)) {
    31     }
    3229    public Rectangle(IChart chart, PointD lowerLeft, PointD upperRight, Pen pen, Brush brush)
    3330      : base(chart, lowerLeft, upperRight, pen, brush) {
    34     }
    35     public Rectangle(IChart chart, double x1, double y1, double x2, double y2, Pen pen, Brush brush)
    36       : this(chart, new PointD(x1, y1), new PointD(x2, y2), pen, brush) {
    3731    }
    3832
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/RectangularPrimitiveBase.cs

    r12535 r13045  
    4141    }
    4242
    43     public string Text { get; set; }
    44     public Font Font { get; set; }
    45     public float MaximumFontSize { get; set; }
    46 
    4743    protected RectangularPrimitiveBase(IChart chart, PointD lowerLeft, PointD upperRight)
    4844      : base(chart) {
    4945      selectionRectangles = new Group(chart);
    5046      SetPosition(lowerLeft, upperRight);
    51 
    52       MaximumFontSize = 12;
    53     }
    54     protected RectangularPrimitiveBase(IChart chart, double x1, double y1, double x2, double y2)
    55       : this(chart, new PointD(x1, y1), new PointD(x2, y2)) {
    5647    }
    5748    protected RectangularPrimitiveBase(IChart chart, PointD lowerLeft, PointD upperRight, Pen pen, Brush brush)
     
    5950      selectionRectangles = new Group(chart);
    6051      SetPosition(lowerLeft, upperRight);
    61     }
    62     protected RectangularPrimitiveBase(IChart chart, double x1, double y1, double x2, double y2, Pen pen, Brush brush)
    63       : this(chart, new PointD(x1, y1), new PointD(x2, y2), pen, brush) {
    6452    }
    6553
     
    7058      myLowerLeft = lowerLeft;
    7159      myUpperRight = upperRight;
    72       OnUpdate();
     60      OnRedrawRequired();
    7361    }
    74     public void SetPosition(double x1, double y1, double x2, double y2) {
    75       SetPosition(new PointD(x1, y1), new PointD(x2, y2));
    76     }
     62
    7763    public override void Move(Offset delta) {
    7864      SetPosition(LowerLeft + delta, UpperRight + delta);
     65    }
     66
     67    public override void Move(PointD point, Offset delta) {
     68      if (Selected && selectionRectangles.ContainsPoint(point)) {
     69        var rect = (SelectionRectangle)selectionRectangles.GetPrimitive(point);
     70        var point1 = PointD.Empty;
     71        var point2 = PointD.Empty;
     72        if (rect.Point == LowerLeft) {
     73          point1 = LowerLeft + delta;
     74          point2 = UpperRight;
     75        } else if (rect.Point == UpperRight) {
     76          point1 = LowerLeft;
     77          point2 = UpperRight + delta;
     78        } else if (rect.Point.X == LowerLeft.X && rect.Point.Y == UpperRight.Y) {
     79          point1 = new PointD(LowerLeft.X + delta.DX, LowerLeft.Y);
     80          point2 = new PointD(UpperRight.X, UpperRight.Y + delta.DY);
     81        } else if (rect.Point.X == UpperRight.X && rect.Point.Y == LowerLeft.Y) {
     82          point1 = new PointD(LowerLeft.X, LowerLeft.Y + delta.DY);
     83          point2 = new PointD(UpperRight.X + delta.DX, UpperRight.Y);
     84        }
     85        SetPosition(new PointD(Math.Min(point1.X, point2.X), Math.Min(point1.Y, point2.Y)),
     86                    new PointD(Math.Max(point1.X, point2.X), Math.Max(point1.Y, point2.Y)));
     87      } else SetPosition(LowerLeft + delta, UpperRight + delta);
     88    }
     89
     90    public override void SnapToGrid(IGrid grid) {
     91      var bl = grid.GetBottomLeftGridPoint(LowerLeft);
     92      var ur = grid.GetUpperRightGridPoint(LowerLeft);
     93      var sx = Math.Abs(bl.X - LowerLeft.X) <= Math.Abs(ur.X - LowerLeft.X) ? bl.X : ur.X;
     94      var sy = Math.Abs(bl.Y - LowerLeft.Y) <= Math.Abs(ur.Y - LowerLeft.Y) ? bl.Y : ur.Y;
     95
     96      var end = new PointD(UpperRight.X + (sx - LowerLeft.X), UpperRight.Y + (sy - LowerLeft.Y));
     97
     98      bl = grid.GetBottomLeftGridPoint(end);
     99      ur = grid.GetUpperRightGridPoint(end);
     100      var ex = Math.Abs(bl.X - end.X) <= Math.Abs(ur.X - end.X) ? bl.X : ur.X;
     101      var ey = Math.Abs(bl.Y - end.Y) <= Math.Abs(ur.Y - end.Y) ? bl.Y : ur.Y;
     102
     103      SetPosition(new PointD(sx, sy), new PointD(ex, ey));
     104    }
     105
     106    public override void SnapToGrid(PointD point, IGrid grid) {
     107      if (Selected && selectionRectangles.ContainsPoint(point)) {
     108        var rect = (SelectionRectangle)selectionRectangles.GetPrimitive(point);
     109        var point1 = LowerLeft;
     110        var point2 = UpperRight;
     111        if (rect.Point == LowerLeft) {
     112          var bl = grid.GetBottomLeftGridPoint(LowerLeft);
     113          var ur = grid.GetUpperRightGridPoint(LowerLeft);
     114          var x = Math.Abs(bl.X - LowerLeft.X) <= Math.Abs(ur.X - LowerLeft.X) ? bl.X : ur.X;
     115          var y = Math.Abs(bl.Y - LowerLeft.Y) <= Math.Abs(ur.Y - LowerLeft.Y) ? bl.Y : ur.Y;
     116          point1 = new PointD(x, y);
     117        } else if (rect.Point == UpperRight) {
     118          var bl = grid.GetBottomLeftGridPoint(UpperRight);
     119          var ur = grid.GetUpperRightGridPoint(UpperRight);
     120          var x = Math.Abs(bl.X - UpperRight.X) <= Math.Abs(ur.X - UpperRight.X) ? bl.X : ur.X;
     121          var y = Math.Abs(bl.Y - UpperRight.Y) <= Math.Abs(ur.Y - UpperRight.Y) ? bl.Y : ur.Y;
     122          point2 = new PointD(x, y);
     123        } else if (rect.Point.X == LowerLeft.X && rect.Point.Y == UpperRight.Y) {
     124          var upperLeft = new PointD(LowerLeft.X, UpperRight.Y);
     125          var bl = grid.GetBottomLeftGridPoint(upperLeft);
     126          var ur = grid.GetUpperRightGridPoint(upperLeft);
     127          var x = Math.Abs(bl.X - upperLeft.X) <= Math.Abs(ur.X - upperLeft.X) ? bl.X : ur.X;
     128          var y = Math.Abs(bl.Y - upperLeft.Y) <= Math.Abs(ur.Y - upperLeft.Y) ? bl.Y : ur.Y;
     129          point1 = new PointD(x, LowerLeft.Y);
     130          point2 = new PointD(UpperRight.X, y);
     131        } else if (rect.Point.X == UpperRight.X && rect.Point.Y == LowerLeft.Y) {
     132          var lowerRight = new PointD(UpperRight.X, LowerLeft.Y);
     133          var bl = grid.GetBottomLeftGridPoint(lowerRight);
     134          var ur = grid.GetUpperRightGridPoint(lowerRight);
     135          var x = Math.Abs(bl.X - lowerRight.X) <= Math.Abs(ur.X - lowerRight.X) ? bl.X : ur.X;
     136          var y = Math.Abs(bl.Y - lowerRight.Y) <= Math.Abs(ur.Y - lowerRight.Y) ? bl.Y : ur.Y;
     137          point1 = new PointD(LowerLeft.X, y);
     138          point2 = new PointD(x, UpperRight.Y);
     139        }
     140        SetPosition(new PointD(Math.Min(point1.X, point2.X), Math.Min(point1.Y, point2.Y)),
     141                    new PointD(Math.Max(point1.X, point2.X), Math.Max(point1.Y, point2.Y)));
     142      } else SnapToGrid(grid);
    79143    }
    80144
     
    86150    }
    87151
    88     public override void MouseDrag(PointD point, Offset offset, MouseButtons button) {
    89       if (button == MouseButtons.Left) {
    90         if (Selected) {
    91           if (selectionRectangles.ContainsPoint(point)) {
    92             SelectionRectangle rect = (SelectionRectangle)selectionRectangles.GetPrimitive(point);
    93             PointD point1 = PointD.Empty;
    94             PointD point2 = PointD.Empty;
    95             if (rect.Point == LowerLeft) {
    96               point1 = LowerLeft + offset;
    97               point2 = UpperRight;
    98             } else if (rect.Point == UpperRight) {
    99               point1 = LowerLeft;
    100               point2 = UpperRight + offset;
    101             } else if ((rect.Point.X == LowerLeft.X) && (rect.Point.Y == UpperRight.Y)) {
    102               point1 = new PointD(LowerLeft.X + offset.DX, LowerLeft.Y);
    103               point2 = new PointD(UpperRight.X, UpperRight.Y + offset.DY);
    104             } else if ((rect.Point.X == UpperRight.X) && (rect.Point.Y == LowerLeft.Y)) {
    105               point1 = new PointD(LowerLeft.X, LowerLeft.Y + offset.DY);
    106               point2 = new PointD(UpperRight.X + offset.DX, UpperRight.Y);
    107             }
    108             SetPosition(Math.Min(point1.X, point2.X), Math.Min(point1.Y, point2.Y),
    109                         Math.Max(point1.X, point2.X), Math.Max(point1.Y, point2.Y));
    110           } else {
    111             base.MouseDrag(point, offset, button);
    112           }
    113         }
    114       }
    115     }
    116 
    117152    public override Cursor GetCursor(PointD point) {
    118153      if (Selected) {
    119         Cursor cursor = selectionRectangles.GetCursor(point);
     154        var cursor = selectionRectangles.GetCursor(point);
    120155        if (cursor != null) return cursor;
    121156      }
     
    139174      }
    140175    }
    141 
    142     protected virtual void DrawText(Graphics graphics) {
    143       // draw the text in the center of the bounding rectangle
    144       var p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y));
    145       var s = Chart.TransformWorldToPixel(Size);
    146 
    147       var stringSize = graphics.MeasureString(Text, Font);
    148       var fontSize = (float)(Math.Round(Font.Size * Math.Min(s.Width / stringSize.Width, s.Height / stringSize.Height)));
    149       if (fontSize > MaximumFontSize) { fontSize = MaximumFontSize; }
    150       Font = new Font(Font.FontFamily, fontSize, GraphicsUnit.Pixel);
    151       stringSize = graphics.MeasureString(Text, Font);
    152       graphics.DrawString(Text, Font, new SolidBrush(Pen.Color), p.X + (s.Width - stringSize.Width) / 2f, p.Y - (s.Height + stringSize.Height) / 2f);
    153     }
    154 
    155     public override void Draw(Graphics graphics) {
    156       if (!string.IsNullOrEmpty(Text))
    157         DrawText(graphics);
    158       base.Draw(graphics);
    159     }
    160176  }
    161177}
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/SelectionRectangle.cs

    r12535 r13045  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using System.Drawing;
    2623using System.Windows.Forms;
     
    4138    }
    4239
     40    public override void SnapToGrid(IGrid grid) { }
     41    public override void SnapToGrid(PointD point, IGrid grid) { }
     42
    4343    public override Cursor GetCursor(PointD point) {
    4444      return cursor;
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Properties/AssemblyInfo.frame

    r12535 r13045  
    5353// You can specify all the values or you can default the Revision and Build Numbers
    5454// by using the '*' as shown below:
    55 [assembly: AssemblyVersion("3.3.0.$WCREV$")]
    56 [assembly: AssemblyFileVersion("3.3.1.$WCREV$")]
     55[assembly: AssemblyVersion("3.3.0.0")]
     56[assembly: AssemblyFileVersion("3.3.12.$WCREV$")]
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/PropertiesDialog.Designer.cs

    r12535 r13045  
    7474      this.AcceptButton = this.okButton;
    7575      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    76       this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     76      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    7777      this.ClientSize = new System.Drawing.Size(506, 306);
    7878      this.Controls.Add(this.propertyGrid);
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/PropertiesDialog.cs

    r12535 r13045  
    2323using System.Collections.Generic;
    2424using System.ComponentModel;
    25 using System.Data;
    2625using System.Drawing;
    2726using System.Text;
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Structs/Offset.cs

    r12535 r13045  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Drawing;
    2623
    2724namespace HeuristicLab.Visualization {
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Structs/PointD.cs

    r12535 r13045  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using System.Drawing;
    2624
     
    8684    }
    8785    public static bool operator !=(PointD point1, PointD point2) {
    88       return (point1.X != point2.X) && (point1.Y != point2.Y);
     86      return !(point1 == point2);
     87    }
     88    public static explicit operator Point(PointD point) {
     89      return new Point((int)Math.Round(point.X), (int)Math.Round(point.Y));
     90    }
     91    public static explicit operator PointF(PointD point) {
     92      float fx = (float)point.X;
     93      float fy = (float)point.Y;
     94      return new PointF(float.IsPositiveInfinity(fx) ? float.MaxValue : fx, float.IsNegativeInfinity(fy) ? float.MinValue : fy);
    8995    }
    9096    public static explicit operator SizeD(PointD point) {
Note: See TracChangeset for help on using the changeset viewer.