Changeset 9415


Ignore:
Timestamp:
05/02/13 10:45:44 (8 years ago)
Author:
bburlacu
Message:

#1265: Added save file functionality in emf and bitmap formats.

Location:
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartControl.Designer.cs

    r4776 r9415  
    5858      this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
    5959      this.propertiesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     60      this.saveImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    6061      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
     62      this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
    6163      ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
    6264      this.pictureBoxContextMenuStrip.SuspendLayout();
     
    6567      // pictureBox
    6668      //
    67       this.pictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    68                   | System.Windows.Forms.AnchorStyles.Left)
    69                   | System.Windows.Forms.AnchorStyles.Right)));
     69      this.pictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     70            | System.Windows.Forms.AnchorStyles.Left)
     71            | System.Windows.Forms.AnchorStyles.Right)));
    7072      this.pictureBox.BackColor = System.Drawing.Color.White;
    7173      this.pictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     
    7678      this.pictureBox.TabIndex = 0;
    7779      this.pictureBox.TabStop = false;
     80      this.pictureBox.SizeChanged += new System.EventHandler(this.pictureBox_SizeChanged);
    7881      this.pictureBox.VisibleChanged += new System.EventHandler(this.pictureBox_VisibleChanged);
    7982      this.pictureBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseDown);
    8083      this.pictureBox.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseMove);
    8184      this.pictureBox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseUp);
    82       this.pictureBox.SizeChanged += new System.EventHandler(this.pictureBox_SizeChanged);
    8385      //
    8486      // pictureBoxContextMenuStrip
     
    9496            this.intoBackgroundToolStripMenuItem,
    9597            this.toolStripMenuItem2,
    96             this.propertiesToolStripMenuItem});
     98            this.propertiesToolStripMenuItem,
     99            this.saveImageToolStripMenuItem});
    97100      this.pictureBoxContextMenuStrip.Name = "pictureBoxContextMenuStrip";
    98       this.pictureBoxContextMenuStrip.Size = new System.Drawing.Size(165, 192);
     101      this.pictureBoxContextMenuStrip.Size = new System.Drawing.Size(163, 214);
    99102      //
    100103      // moveToolStripMenuItem
     
    103106      this.moveToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
    104107      this.moveToolStripMenuItem.Name = "moveToolStripMenuItem";
    105       this.moveToolStripMenuItem.Size = new System.Drawing.Size(164, 22);
     108      this.moveToolStripMenuItem.Size = new System.Drawing.Size(162, 22);
    106109      this.moveToolStripMenuItem.Text = "&Move";
    107110      this.moveToolStripMenuItem.Click += new System.EventHandler(this.moveToolStripMenuItem_Click);
     
    110113      //
    111114      this.zoomToolStripMenuItem.Name = "zoomToolStripMenuItem";
    112       this.zoomToolStripMenuItem.Size = new System.Drawing.Size(164, 22);
     115      this.zoomToolStripMenuItem.Size = new System.Drawing.Size(162, 22);
    113116      this.zoomToolStripMenuItem.Text = "&Zoom";
    114117      this.zoomToolStripMenuItem.Click += new System.EventHandler(this.zoomToolStripMenuItem_Click);
     
    117120      //
    118121      this.selectToolStripMenuItem.Name = "selectToolStripMenuItem";
    119       this.selectToolStripMenuItem.Size = new System.Drawing.Size(164, 22);
     122      this.selectToolStripMenuItem.Size = new System.Drawing.Size(162, 22);
    120123      this.selectToolStripMenuItem.Text = "&Select";
    121124      this.selectToolStripMenuItem.Click += new System.EventHandler(this.selectToolStripMenuItem_Click);
     
    124127      //
    125128      this.toolStripMenuItem1.Name = "toolStripMenuItem1";
    126       this.toolStripMenuItem1.Size = new System.Drawing.Size(161, 6);
     129      this.toolStripMenuItem1.Size = new System.Drawing.Size(159, 6);
    127130      //
    128131      // oneLayerUpToolStripMenuItem
     
    130133      this.oneLayerUpToolStripMenuItem.Enabled = false;
    131134      this.oneLayerUpToolStripMenuItem.Name = "oneLayerUpToolStripMenuItem";
    132       this.oneLayerUpToolStripMenuItem.Size = new System.Drawing.Size(164, 22);
     135      this.oneLayerUpToolStripMenuItem.Size = new System.Drawing.Size(162, 22);
    133136      this.oneLayerUpToolStripMenuItem.Text = "One Layer &Up";
    134137      this.oneLayerUpToolStripMenuItem.Click += new System.EventHandler(this.oneLayerUpToolStripMenuItem_Click);
     
    138141      this.oneLayerDownToolStripMenuItem.Enabled = false;
    139142      this.oneLayerDownToolStripMenuItem.Name = "oneLayerDownToolStripMenuItem";
    140       this.oneLayerDownToolStripMenuItem.Size = new System.Drawing.Size(164, 22);
     143      this.oneLayerDownToolStripMenuItem.Size = new System.Drawing.Size(162, 22);
    141144      this.oneLayerDownToolStripMenuItem.Text = "OneLayer &Down";
    142145      this.oneLayerDownToolStripMenuItem.Click += new System.EventHandler(this.oneLayerDownToolStripMenuItem_Click);
     
    146149      this.intoForegroundToolStripMenuItem.Enabled = false;
    147150      this.intoForegroundToolStripMenuItem.Name = "intoForegroundToolStripMenuItem";
    148       this.intoForegroundToolStripMenuItem.Size = new System.Drawing.Size(164, 22);
     151      this.intoForegroundToolStripMenuItem.Size = new System.Drawing.Size(162, 22);
    149152      this.intoForegroundToolStripMenuItem.Text = "Into &Foreground";
    150153      this.intoForegroundToolStripMenuItem.Click += new System.EventHandler(this.intoForegroundToolStripMenuItem_Click);
     
    154157      this.intoBackgroundToolStripMenuItem.Enabled = false;
    155158      this.intoBackgroundToolStripMenuItem.Name = "intoBackgroundToolStripMenuItem";
    156       this.intoBackgroundToolStripMenuItem.Size = new System.Drawing.Size(164, 22);
     159      this.intoBackgroundToolStripMenuItem.Size = new System.Drawing.Size(162, 22);
    157160      this.intoBackgroundToolStripMenuItem.Text = "Into &Background";
    158161      this.intoBackgroundToolStripMenuItem.Click += new System.EventHandler(this.intoBackgroundToolStripMenuItem_Click);
     
    161164      //
    162165      this.toolStripMenuItem2.Name = "toolStripMenuItem2";
    163       this.toolStripMenuItem2.Size = new System.Drawing.Size(161, 6);
     166      this.toolStripMenuItem2.Size = new System.Drawing.Size(159, 6);
    164167      //
    165168      // propertiesToolStripMenuItem
     
    167170      this.propertiesToolStripMenuItem.Enabled = false;
    168171      this.propertiesToolStripMenuItem.Name = "propertiesToolStripMenuItem";
    169       this.propertiesToolStripMenuItem.Size = new System.Drawing.Size(164, 22);
     172      this.propertiesToolStripMenuItem.Size = new System.Drawing.Size(162, 22);
    170173      this.propertiesToolStripMenuItem.Text = "&Properties";
    171174      this.propertiesToolStripMenuItem.Click += new System.EventHandler(this.propertiesToolStripMenuItem_Click);
     175      //
     176      // saveImageToolStripMenuItem
     177      //
     178      this.saveImageToolStripMenuItem.Name = "saveImageToolStripMenuItem";
     179      this.saveImageToolStripMenuItem.Size = new System.Drawing.Size(162, 22);
     180      this.saveImageToolStripMenuItem.Text = "Save Image";
     181      this.saveImageToolStripMenuItem.Click += new System.EventHandler(this.saveImageToolStripMenuItem_Click);
     182      //
     183      // saveFileDialog
     184      //
     185      this.saveFileDialog.DefaultExt = "emf";
     186      this.saveFileDialog.FileName = "*.emf";
     187      this.saveFileDialog.Filter = "Enhanced metafile|*.emf|Bitmap files|*.bmp";
    172188      //
    173189      // ChartControl
     
    201217    protected System.Windows.Forms.ToolStripMenuItem intoBackgroundToolStripMenuItem;
    202218    protected System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
     219    private System.Windows.Forms.ToolStripMenuItem saveImageToolStripMenuItem;
     220    private System.Windows.Forms.SaveFileDialog saveFileDialog;
    203221
    204222  }
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartControl.cs

    r7780 r9415  
    2424using System.Drawing;
    2525using System.Drawing.Drawing2D;
     26using System.Drawing.Imaging;
    2627using System.Windows.Forms;
    2728
     
    2930  public partial class ChartControl : UserControl {
    3031    private Bitmap bitmap;
     32    public Bitmap Bitmap { get; private set; }
    3133    private bool renderingRequired;
    3234    private Point buttonDownPoint;
     
    135137    }
    136138
    137     private void pictureBox_MouseMove(object sender, MouseEventArgs e) {
     139    protected virtual void pictureBox_MouseMove(object sender, MouseEventArgs e) {
    138140      var text = Chart.GetToolTipText(e.Location);
    139141      if (toolTip.GetToolTip(pictureBox) != text)
     
    244246      Chart.Mode = mode;
    245247    }
     248
     249    private void SaveImageAsBitmap(string filename) {
     250      if (bitmap == null) throw new Exception("Bitmap is null.");
     251      bitmap.Save(filename);
     252    }
     253
     254    private void SaveImageAsEmf(string filename) {
     255      using (Graphics g = CreateGraphics()) {
     256        using (Metafile file = new Metafile(filename, g.GetHdc())) {
     257          using (Graphics emfFile = Graphics.FromImage(file)) {
     258            Chart.Render(emfFile, pictureBox.Width, pictureBox.Height);
     259          }
     260        }
     261        g.ReleaseHdc();
     262      }
     263    }
     264
     265    private void saveImageToolStripMenuItem_Click(object sender, EventArgs e) {
     266      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
     267        string filename = saveFileDialog.FileName.ToLower();
     268        if (filename.EndsWith("bmp")) SaveImageAsBitmap(filename);
     269        else if (filename.EndsWith("emf")) SaveImageAsEmf(filename);
     270        else SaveImageAsBitmap(filename);
     271      }
     272    }
    246273  }
    247274}
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/Group.cs

    r8219 r9415  
    117117      foreach (var primitive in myPrimitives.Where(primitive => primitive.ContainsPoint(point))) {
    118118        primitives.Add(primitive);
    119         var @group = primitive as IGroup;
    120         if (@group != null)
    121           primitives.AddRange((@group).Primitives);
     119        var group = primitive as IGroup;
     120        if (group != null)
     121          primitives.AddRange(group.Primitives);
    122122      }
    123123      return primitives;
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/LinearPrimitiveBase.cs

    r4776 r9415  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using System.Drawing;
    2623using System.Drawing.Drawing2D;
Note: See TracChangeset for help on using the changeset viewer.