Changeset 13045
- Timestamp:
- 10/21/15 14:18:31 (9 years ago)
- 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 23 23 using System.Collections.Generic; 24 24 using System.Drawing; 25 using System.Linq;26 25 using System.Windows.Forms; 27 26 … … 30 29 private PointD originalLowerLeft; 31 30 private PointD originalUpperRight; 32 pr ivateList<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; } 37 36 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; } 42 46 43 47 private PointD myLowerLeft; … … 53 57 } 54 58 private Size mySizeInPixels; 59 55 60 public Size SizeInPixels { 56 61 get { return mySizeInPixels; } … … 62 67 get { return new SizeD(SizeInPixels.Width / Size.Width, SizeInPixels.Height / Size.Height); } 63 68 } 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; } 75 72 76 73 public Chart(PointD lowerLeft, PointD upperRight) { 77 myUpdateEnabled = false;78 74 zoomHistory = new List<Offset>(); 79 myMode = ChartMode.Move;80 75 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 86 83 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)) { } 89 85 90 86 public PointD TransformPixelToWorld(Point point) { 91 doublex = LowerLeft.X + point.X * PixelToWorldRatio.Width;92 doubley = 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; 93 89 return new PointD(x, y); 94 90 } 91 95 92 public SizeD TransformPixelToWorld(Size size) { 96 doublewidth = size.Width * PixelToWorldRatio.Width;97 doubleheight = size.Height * PixelToWorldRatio.Height;93 var width = size.Width * PixelToWorldRatio.Width; 94 var height = size.Height * PixelToWorldRatio.Height; 98 95 return new SizeD(width, height); 99 96 } 97 100 98 public Point TransformWorldToPixel(PointD point) { 101 intx = (int)((point.X - LowerLeft.X) * WorldToPixelRatio.Width);102 inty = (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); 103 101 return new Point(x, y); 104 102 } 103 105 104 public Size TransformWorldToPixel(SizeD size) { 106 intwidth = (int)(size.Width * WorldToPixelRatio.Width);107 intheight = (int)(size.Height * WorldToPixelRatio.Height);105 var width = (int)(size.Width * WorldToPixelRatio.Width); 106 var height = (int)(size.Height * WorldToPixelRatio.Height); 108 107 return new Size(width, height); 109 108 } … … 118 117 myLowerLeft = lowerLeft; 119 118 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 125 122 public virtual void Move(Offset delta) { 126 123 myLowerLeft += delta; 127 124 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); 132 145 } 133 146 134 147 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; 135 165 zoomHistory.Insert(0, LowerLeft - lowerLeft); 136 166 zoomHistory.Insert(0, UpperRight - upperRight); 137 167 myLowerLeft = lowerLeft; 138 168 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 144 172 public virtual void ZoomIn(Point lowerLeft, Point upperRight) { 145 173 ZoomIn(TransformPixelToWorld(lowerLeft), TransformPixelToWorld(upperRight)); 146 174 } 147 public void ZoomIn(int x1, int y1, int x2, int y2) { 148 ZoomIn(new Point(x1, y1), new Point(x2, y2)); 149 } 175 150 176 public virtual void ZoomOut() { 151 177 if (zoomHistory.Count > 0) { … … 156 182 myLowerLeft = LowerLeft + lowerLeft; 157 183 myUpperRight = UpperRight + upperRight; 158 On Update();184 OnRedrawRequired(); 159 185 } 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 167 195 public virtual void Unzoom() { 168 196 SetPosition(originalLowerLeft, originalUpperRight); 169 197 } 170 198 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 171 220 public virtual IPrimitive GetPrimitive(Point point) { 172 221 return Group.GetPrimitive(TransformPixelToWorld(point)); 173 222 } 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) { 178 225 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);255 226 } 256 227 … … 260 231 Group.Draw(graphics); 261 232 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(); 277 255 } 278 256 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartControl.Designer.cs
r12535 r13045 48 48 this.pictureBox = new System.Windows.Forms.PictureBox(); 49 49 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();54 50 this.oneLayerUpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 55 51 this.oneLayerDownToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 56 52 this.intoForegroundToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 57 53 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(); 58 64 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();63 65 ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); 64 66 this.pictureBoxContextMenuStrip.SuspendLayout(); 67 this.buttonPanel.SuspendLayout(); 65 68 this.SuspendLayout(); 66 69 // … … 71 74 | System.Windows.Forms.AnchorStyles.Right))); 72 75 this.pictureBox.BackColor = System.Drawing.Color.White; 76 this.pictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 73 77 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); 75 79 this.pictureBox.Name = "pictureBox"; 76 this.pictureBox.Size = new System.Drawing.Size( 266, 236);80 this.pictureBox.Size = new System.Drawing.Size(685, 500); 77 81 this.pictureBox.TabIndex = 0; 78 82 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); 87 96 // 88 97 // pictureBoxContextMenuStrip 89 98 // 90 99 this.pictureBoxContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 91 this.moveToolStripMenuItem,92 this.zoomToolStripMenuItem,93 this.selectToolStripMenuItem,94 this.toolStripMenuItem1,95 100 this.oneLayerUpToolStripMenuItem, 96 101 this.oneLayerDownToolStripMenuItem, 97 102 this.intoForegroundToolStripMenuItem, 98 103 this.intoBackgroundToolStripMenuItem, 104 this.toolStripMenuItem1, 105 this.propertiesToolStripMenuItem, 99 106 this.toolStripMenuItem2, 100 this.propertiesToolStripMenuItem,101 107 this.saveImageToolStripMenuItem}); 102 108 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); 132 111 // 133 112 // oneLayerUpToolStripMenuItem … … 163 142 this.intoBackgroundToolStripMenuItem.Click += new System.EventHandler(this.intoBackgroundToolStripMenuItem_Click); 164 143 // 165 // toolStripMenuItem 2166 // 167 this.toolStripMenuItem 2.Name = "toolStripMenuItem2";168 this.toolStripMenuItem 2.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); 169 148 // 170 149 // propertiesToolStripMenuItem … … 176 155 this.propertiesToolStripMenuItem.Click += new System.EventHandler(this.propertiesToolStripMenuItem_Click); 177 156 // 157 // toolStripMenuItem2 158 // 159 this.toolStripMenuItem2.Name = "toolStripMenuItem2"; 160 this.toolStripMenuItem2.Size = new System.Drawing.Size(159, 6); 161 // 178 162 // saveImageToolStripMenuItem 179 163 // 180 164 this.saveImageToolStripMenuItem.Name = "saveImageToolStripMenuItem"; 181 165 this.saveImageToolStripMenuItem.Size = new System.Drawing.Size(162, 22); 182 this.saveImageToolStripMenuItem.Text = " Save Image";166 this.saveImageToolStripMenuItem.Text = "&Save Image"; 183 167 this.saveImageToolStripMenuItem.Click += new System.EventHandler(this.saveImageToolStripMenuItem_Click); 184 168 // … … 187 171 this.saveFileDialog.DefaultExt = "emf"; 188 172 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; 190 244 // 191 245 // ChartControl 192 246 // 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; 195 248 this.BackColor = System.Drawing.SystemColors.Control; 249 this.Controls.Add(this.buttonPanel); 196 250 this.Controls.Add(this.pictureBox); 251 this.DoubleBuffered = true; 197 252 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); 200 257 ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); 201 258 this.pictureBoxContextMenuStrip.ResumeLayout(false); 259 this.buttonPanel.ResumeLayout(false); 202 260 this.ResumeLayout(false); 203 261 … … 209 267 protected System.Windows.Forms.ToolTip toolTip; 210 268 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; 215 270 protected System.Windows.Forms.ToolStripMenuItem propertiesToolStripMenuItem; 216 271 protected System.Windows.Forms.ToolStripMenuItem oneLayerUpToolStripMenuItem; … … 218 273 protected System.Windows.Forms.ToolStripMenuItem intoForegroundToolStripMenuItem; 219 274 protected System.Windows.Forms.ToolStripMenuItem intoBackgroundToolStripMenuItem; 275 protected System.Windows.Forms.ToolStripSeparator toolStripMenuItem1; 220 276 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; 224 283 } 225 284 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartControl.cs
r12535 r13045 21 21 22 22 using System; 23 using System.Co llections.Generic;23 using System.ComponentModel; 24 24 using System.Drawing; 25 25 using System.Drawing.Drawing2D; 26 26 using System.Drawing.Imaging; 27 using System.Linq; 27 28 using System.Windows.Forms; 28 29 29 30 namespace HeuristicLab.Visualization { 30 31 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; } 41 60 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) { 58 78 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; 60 130 GenerateImage(); 61 131 } 62 132 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; 67 136 if (ScaleOnResize) { 68 137 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))); 71 142 } 72 143 } 73 144 GenerateImage(); 74 145 } 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; 86 197 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) { 88 259 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 } 112 268 } 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); 117 343 } 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 } 241 368 if (!Visible) { 242 renderingRequired = true;369 RenderingRequired = true; 243 370 } else { 244 371 if ((pictureBox.Width == 0) || (pictureBox.Height == 0)) { 245 Bitmap = null; 372 pictureBox.Image = pictureBox.ErrorImage; 373 if (Picture != null) Picture.Dispose(); 374 Picture = null; 246 375 } 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)) { 250 379 graphics.SetClip(new System.Drawing.Rectangle(0, 0, pictureBox.Width, pictureBox.Height)); 251 380 Chart.Render(graphics, pictureBox.Width, pictureBox.Height); 252 graphics.Dispose();253 381 } 254 382 } 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(); 294 412 } 295 413 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartMode.cs
r12536 r13045 21 21 22 22 namespace 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(); 27 30 } 28 31 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/HeuristicLab.Visualization-3.3.csproj
r12536 r13045 104 104 </PropertyGroup> 105 105 <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> 108 115 </Reference> 109 116 <Reference Include="System" /> … … 123 130 <Compile Include="ChartMode.cs" /> 124 131 <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> 125 138 <Compile Include="Trees\LayoutEngines\BoxesLayoutEngine.cs" /> 126 139 <Compile Include="Trees\LayoutEngines\ILayoutEngine.cs" /> … … 131 144 <None Include="Plugin.cs.frame" /> 132 145 <Compile Include="Plugin.cs" /> 146 <Compile Include="Interfaces\IGrid.cs" /> 133 147 <Compile Include="Interfaces\IGroup.cs" /> 134 148 <Compile Include="Interfaces\IChart.cs" /> … … 159 173 </ItemGroup> 160 174 <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> 164 178 </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> 172 181 <None Include="HeuristicLab.snk" /> 173 182 <None Include="Properties\AssemblyInfo.frame" /> … … 190 199 </BootstrapperPackage> 191 200 </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> 192 210 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> 193 211 <!-- 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 27 27 namespace HeuristicLab.Visualization { 28 28 public interface IChart { 29 ChartMode Mode { get; set; } 29 bool Enabled { get; set; } 30 30 31 PointD LowerLeft { get; } 31 32 PointD UpperRight { get; } … … 35 36 SizeD WorldToPixelRatio { get; } 36 37 IGroup Group { get; } 37 bool UpdateEnabled { get; }38 38 39 39 PointD TransformPixelToWorld(Point point); … … 43 43 44 44 void SetPosition(PointD lowerLeft, PointD upperRight); 45 void SetPosition(double x1, double y1, double x2, double y2);46 45 void Move(Offset delta); 47 void Move(double dx, double dy);48 46 47 void ZoomIn(Point mousePosition); 49 48 void ZoomIn(PointD lowerLeft, PointD upperRight); 50 void ZoomIn(double x1, double y1, double x2, double y2);51 49 void ZoomIn(Point lowerLeft, Point upperRight); 52 void ZoomIn(int x1, int y1, int x2, int y2);53 50 void ZoomOut(); 54 51 void Unzoom(); 55 52 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 56 61 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); 74 63 75 64 void Render(Graphics graphics, int width, int height); 76 65 77 event EventHandler Update;78 void EnforceUpdate();66 event EventHandler RedrawRequired; 67 void RaiseRedrawRequired(); 79 68 } 80 69 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Interfaces/IGroup.cs
r12535 r13045 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Collections.ObjectModel; 25 using System.Text;26 24 27 25 namespace 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; } 31 29 32 30 void Add(IPrimitive primitive); … … 37 35 38 36 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); 42 38 43 39 void OneLayerUp(IPrimitive primitive); -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Interfaces/IPrimitive.cs
r12535 r13045 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Text;25 23 using System.Drawing; 26 24 using System.Windows.Forms; … … 28 26 namespace HeuristicLab.Visualization { 29 27 public interface IPrimitive { 30 IChart Chart { get; }31 IGroup Group { get; set; }32 28 Pen Pen { get; set; } 33 29 Brush Brush { get; set; } 34 bool UpdateEnabled { get; }35 30 bool Selected { get; set; } 36 31 string ToolTipText { get; set; } … … 38 33 39 34 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); 41 39 42 40 bool ContainsPoint(PointD point); 43 bool ContainsPoint(double x, double y);44 45 41 Cursor GetCursor(PointD point); 46 Cursor GetCursor(double x, double y);47 42 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);63 43 64 44 void PreDraw(Graphics graphics); … … 66 46 void PostDraw(Graphics graphics); 67 47 68 event EventHandler Update; 69 void EnforceUpdate(); 48 event EventHandler RedrawRequired; 70 49 } 71 50 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Plugin.cs.frame
r12535 r13045 26 26 27 27 namespace HeuristicLab.Visualization { 28 [Plugin("HeuristicLab.Visualization", "3.3.1 .$WCREV$")]28 [Plugin("HeuristicLab.Visualization", "3.3.12.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Visualization-3.3.dll", PluginFileType.Assembly)] 30 [PluginDependency("HeuristicLab.Common.Resources", "3.3")] 30 31 public class HeuristicLabVisualizationPlugin : PluginBase { } 31 32 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/Axis.cs
r12535 r13045 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Text;25 23 using System.Drawing; 26 24 27 25 namespace HeuristicLab.Visualization { 28 26 public class Axis : AxisPrimitiveBase { 27 protected const int PixelsPerInterval = 100; 28 29 29 public Axis(IChart chart, PointD point, AxisType axisType) 30 30 : base(chart, point, axisType) { 31 }32 public Axis(IChart chart, double x, double y, AxisType axisType)33 : this(chart, new PointD(x, y), axisType) {34 31 } 35 32 public Axis(IChart chart, PointD point, AxisType axisType, Pen pen, Brush brush) 36 33 : base(chart, point, axisType, pen, brush) { 37 34 } 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 }41 35 42 36 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); 46 39 47 40 if ((AxisType & AxisType.Horizontal) == AxisType.Horizontal) { 48 int intervals = Chart.SizeInPixels.Width / pixelsPerInterval;41 int intervals = Chart.SizeInPixels.Width / PixelsPerInterval; 49 42 50 43 if (intervals > 0) { … … 57 50 58 51 double x = Math.Floor(Chart.LowerLeft.X / step) * step; 59 PointDcurrent = new PointD(x, Point.Y);52 var current = new PointD(x, Point.Y); 60 53 while (current.X <= Chart.UpperRight.X) { 61 54 Point p = Chart.TransformWorldToPixel(current); … … 83 76 } 84 77 if ((AxisType & AxisType.Vertical) == AxisType.Vertical) { 85 int intervals = Chart.SizeInPixels.Height / pixelsPerInterval;78 int intervals = Chart.SizeInPixels.Height / PixelsPerInterval; 86 79 87 80 if (intervals > 0) { … … 94 87 95 88 double y = Math.Floor(Chart.LowerLeft.Y / step) * step; 96 PointDcurrent = new PointD(Point.X, y);89 var current = new PointD(Point.X, y); 97 90 while (current.Y <= Chart.UpperRight.Y) { 98 91 Point p = Chart.TransformWorldToPixel(current); -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/AxisPrimitiveBase.cs
r12535 r13045 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Text;25 22 using System.Drawing; 26 23 … … 41 38 if (value != myShowGrid) { 42 39 myShowGrid = value; 43 On Update();40 OnRedrawRequired(); 44 41 } 45 42 } … … 51 48 if (value != myHorizontalLabel) { 52 49 myHorizontalLabel = value; 53 On Update();50 OnRedrawRequired(); 54 51 } 55 52 } … … 61 58 if (value != myVerticalLabel) { 62 59 myVerticalLabel = value; 63 On Update();60 OnRedrawRequired(); 64 61 } 65 62 } … … 67 64 68 65 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) { } 78 67 protected AxisPrimitiveBase(IChart chart, PointD point, AxisType axisType, Pen pen, Brush brush) 79 68 : base(chart, pen, brush) { … … 82 71 myShowGrid = true; 83 72 } 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 }87 73 88 74 public virtual void SetPosition(PointD point) { 89 75 myPoint = point; 90 On Update();76 OnRedrawRequired(); 91 77 } 92 public void SetPosition(double x, double y) { 93 SetPosition(new PointD(x, y)); 94 } 78 95 79 public override void Move(Offset delta) { 96 80 SetPosition(Point + delta); 97 81 } 98 82 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 99 95 public override bool ContainsPoint(PointD point) { 100 SizeDsize = Chart.TransformPixelToWorld(new Size(5, 5));96 var size = Chart.TransformPixelToWorld(new Size(5, 5)); 101 97 bool result = false; 102 98 if ((AxisType & AxisType.Horizontal) == AxisType.Horizontal) -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/Ellipse.cs
r12535 r13045 28 28 : base(chart, lowerLeft, upperRight) { 29 29 } 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 }33 30 public Ellipse(IChart chart, PointD lowerLeft, PointD upperRight, Pen pen, Brush brush) 34 31 : 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) {38 32 } 39 33 … … 67 61 68 62 public override void Draw(Graphics graphics) { 69 Pointp = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height));70 Sizes = Chart.TransformWorldToPixel(Size);63 var p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height)); 64 var s = Chart.TransformWorldToPixel(Size); 71 65 if (Brush != null) 72 66 graphics.FillEllipse(Brush, p.X, p.Y, s.Width, s.Height); -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/FixedSizeCircle.cs
r12535 r13045 27 27 : base(chart, point, new Size(diameter, diameter)) { 28 28 } 29 public FixedSizeCircle(IChart chart, double x, double y, int diameter)30 : this(chart, new PointD(x, y), diameter) {31 }32 29 public FixedSizeCircle(IChart chart, PointD point, int diameter, Pen pen, Brush brush) 33 30 : 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) {37 31 } 38 32 -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/FixedSizePrimitiveBase.cs
r12535 r13045 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Text;25 23 using System.Drawing; 26 24 … … 41 39 mySize = size; 42 40 } 43 protected FixedSizePrimitiveBase(IChart chart, double x, double y, Size size)44 : this(chart, new PointD(x, y), size) {45 }46 41 protected FixedSizePrimitiveBase(IChart chart, PointD point, Size size, Pen pen, Brush brush) 47 42 : base(chart, pen, brush) { … … 49 44 mySize = size; 50 45 } 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 }54 46 55 47 public virtual void SetPosition(PointD point) { 56 48 myPoint = point; 57 On Update();49 OnRedrawRequired(); 58 50 } 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; 60 65 SetPosition(new PointD(x, y)); 61 66 } 62 public override void Move(Offset delta) { 63 SetPosition(Point + delta); 67 68 public override void SnapToGrid(PointD point, IGrid grid) { 69 SnapToGrid(grid); 64 70 } 65 71 -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/FixedSizeRectangle.cs
r12535 r13045 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Text;25 22 using System.Drawing; 26 23 … … 30 27 : base(chart, point, size) { 31 28 } 32 public FixedSizeRectangle(IChart chart, double x, double y, Size size)33 : this(chart, new PointD(x, y), size) {34 }35 29 public FixedSizeRectangle(IChart chart, PointD point, Size size, Pen pen, Brush brush) 36 30 : 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) {40 31 } 41 32 -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/Group.cs
r12535 r13045 21 21 22 22 using System; 23 using System.Collections; 23 24 using System.Collections.Generic; 24 using System.Collections.ObjectModel;25 25 using System.Drawing; 26 26 using System.Linq; … … 29 29 namespace HeuristicLab.Visualization { 30 30 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 45 41 public override bool Selected { 46 42 get { return base.Selected; } 47 43 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 } 54 53 } 55 54 } … … 57 56 public Group(IChart chart) 58 57 : base(chart) { 59 myPrimitives = new LinkedList<IPrimitive>();60 myPrimitivesLookup = new HashSet<IPrimitive>();58 primitives = new LinkedList<IPrimitive>(); 59 primitivesLookup = new HashSet<IPrimitive>(); 61 60 } 62 61 63 62 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(); 72 68 } 73 69 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 85 79 public virtual bool Contains(IPrimitive primitive) { 86 return myPrimitivesLookup.Contains(primitive); 87 } 80 return primitivesLookup.Contains(primitive); 81 } 82 88 83 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 98 92 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(); 106 99 } 107 100 108 101 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); 119 109 var group = primitive as IGroup; 120 110 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; 127 114 } 128 115 129 116 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 } 136 158 } 137 159 … … 141 163 142 164 public override Cursor GetCursor(PointD point) { 143 IPrimitiveprimitive = 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 147 169 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); 151 172 } 152 173 153 174 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); 158 178 if (curr == null) return; 159 179 var prev = curr.Previous; … … 162 182 prev.Value = temp; 163 183 164 OnUpdate(); 165 } 166 184 OnRedrawRequired(); 185 } 167 186 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); 172 190 if (curr == null) return; 173 191 var next = curr.Next; … … 177 195 } 178 196 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(); 185 201 } 186 202 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(); 193 208 } 194 209 195 210 public override void Draw(Graphics graphics) { 196 var current = myPrimitives.Last;211 var current = primitives.Last; 197 212 while (current != null) { 198 213 var primitive = current.Value; … … 204 219 } 205 220 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(); 208 232 } 209 233 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/Line.cs
r12536 r13045 28 28 : base(chart, start, end) { 29 29 } 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 }33 30 public Line(IChart chart, PointD start, PointD end, Pen pen) 34 31 : 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) {38 32 } 39 33 … … 41 35 if (base.ContainsPoint(point)) return true; 42 36 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); 45 39 46 40 if ((point.X < (Math.Min(Start.X, End.X) - (penWidthX / 2))) || -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/LinearPrimitiveBase.cs
r12535 r13045 20 20 #endregion 21 21 22 using System; 22 23 using System.Drawing; 23 24 using System.Drawing.Drawing2D; … … 26 27 namespace HeuristicLab.Visualization { 27 28 public abstract class LinearPrimitiveBase : PrimitiveBase { 28 protected IGroup selectionRectangles;29 protected IGroup SelectionRectangles; 29 30 30 31 private PointD myStart; … … 45 46 protected LinearPrimitiveBase(IChart chart, PointD start, PointD end) 46 47 : base(chart) { 47 selectionRectangles = new Group(chart);48 SelectionRectangles = new Group(chart); 48 49 myStart = start; 49 50 myEnd = end; 50 51 } 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 }54 52 protected LinearPrimitiveBase(IChart chart, PointD start, PointD end, Pen pen, Brush brush) 55 53 : base(chart, pen, brush) { 56 selectionRectangles = new Group(chart);54 SelectionRectangles = new Group(chart); 57 55 myStart = start; 58 56 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) {62 57 } 63 58 … … 65 60 myStart = start; 66 61 myEnd = end; 67 On Update();62 OnRedrawRequired(); 68 63 } 69 public void SetPosition(double x1, double y1, double x2, double y2) { 70 SetPosition(new PointD(x1, y1), new PointD(x2, y2)); 71 } 64 72 65 public override void Move(Offset delta) { 73 66 SetPosition(Start + delta, End + delta); 74 67 } 75 68 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); 81 78 } 82 79 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)); 96 111 } 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; 98 118 } 99 119 100 120 public override Cursor GetCursor(PointD point) { 101 121 if (Selected) { 102 Cursor cursor = selectionRectangles.GetCursor(point);122 var cursor = SelectionRectangles.GetCursor(point); 103 123 if (cursor != null) return cursor; 104 124 } … … 107 127 108 128 public override void PostDraw(Graphics graphics) { 109 selectionRectangles.Clear();129 SelectionRectangles.Clear(); 110 130 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 }; 113 132 graphics.DrawLine(pen, 114 133 Chart.TransformWorldToPixel(Start), 115 134 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)); 118 137 119 selectionRectangles.Draw(graphics);138 SelectionRectangles.Draw(graphics); 120 139 } 121 140 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/PrimitiveBase.cs
r12535 r13045 26 26 namespace HeuristicLab.Visualization { 27 27 public abstract class PrimitiveBase : IPrimitive { 28 private IChart myChart;28 private readonly IChart chart; 29 29 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; } 36 31 } 37 32 38 private Pen myPen;33 private Pen pen; 39 34 public virtual Pen Pen { 40 get { return myPen; }35 get { return pen; } 41 36 set { 42 myPen = value;43 On Update();37 pen = value; 38 OnRedrawRequired(); 44 39 } 45 40 } 46 private Brush myBrush;41 private Brush brush; 47 42 public virtual Brush Brush { 48 get { return myBrush; }43 get { return brush; } 49 44 set { 50 myBrush = value;51 On Update();45 brush = value; 46 OnRedrawRequired(); 52 47 } 53 48 } 54 49 55 private bool myUpdateEnabled; 56 public bool UpdateEnabled { 57 get { return myUpdateEnabled; } 58 set { myUpdateEnabled = value; } 59 } 50 public string ToolTipText { get; set; } 60 51 61 private bool mySelected; 52 public object Tag { get; set; } 53 54 protected bool SuppressEvents { get; set; } 55 56 private bool selected; 62 57 public virtual bool Selected { 63 get { return mySelected; }58 get { return selected; } 64 59 set { 65 mySelected = value; 66 OnUpdate(); 60 if (selected == value) return; 61 selected = value; 62 OnRedrawRequired(); 67 63 } 68 64 } 69 65 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) { 74 68 } 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; 96 76 } 97 77 98 78 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); 102 83 103 84 public abstract bool ContainsPoint(PointD point); 104 public bool ContainsPoint(double x, double y) {105 return ContainsPoint(new PointD(x, y));106 }107 85 108 86 public virtual Cursor GetCursor(PointD point) { 109 87 return null; 110 88 } 111 public Cursor GetCursor(double x, double y) { 112 return GetCursor(new PointD(x, y)); 113 } 89 114 90 public virtual string GetToolTipText(PointD point) { 115 91 return ToolTipText; 116 92 } 117 public string GetToolTipText(double x, double y) {118 return GetToolTipText(new PointD(x, y));119 }120 93 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) { } 133 97 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); 178 102 } 179 103 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/Rectangle.cs
r12536 r13045 27 27 : base(chart, lowerLeft, upperRight) { 28 28 } 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 }32 29 public Rectangle(IChart chart, PointD lowerLeft, PointD upperRight, Pen pen, Brush brush) 33 30 : 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) {37 31 } 38 32 -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/RectangularPrimitiveBase.cs
r12535 r13045 41 41 } 42 42 43 public string Text { get; set; }44 public Font Font { get; set; }45 public float MaximumFontSize { get; set; }46 47 43 protected RectangularPrimitiveBase(IChart chart, PointD lowerLeft, PointD upperRight) 48 44 : base(chart) { 49 45 selectionRectangles = new Group(chart); 50 46 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)) {56 47 } 57 48 protected RectangularPrimitiveBase(IChart chart, PointD lowerLeft, PointD upperRight, Pen pen, Brush brush) … … 59 50 selectionRectangles = new Group(chart); 60 51 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) {64 52 } 65 53 … … 70 58 myLowerLeft = lowerLeft; 71 59 myUpperRight = upperRight; 72 On Update();60 OnRedrawRequired(); 73 61 } 74 public void SetPosition(double x1, double y1, double x2, double y2) { 75 SetPosition(new PointD(x1, y1), new PointD(x2, y2)); 76 } 62 77 63 public override void Move(Offset delta) { 78 64 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); 79 143 } 80 144 … … 86 150 } 87 151 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 117 152 public override Cursor GetCursor(PointD point) { 118 153 if (Selected) { 119 Cursor cursor = selectionRectangles.GetCursor(point);154 var cursor = selectionRectangles.GetCursor(point); 120 155 if (cursor != null) return cursor; 121 156 } … … 139 174 } 140 175 } 141 142 protected virtual void DrawText(Graphics graphics) {143 // draw the text in the center of the bounding rectangle144 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 }160 176 } 161 177 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/SelectionRectangle.cs
r12535 r13045 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Text;25 22 using System.Drawing; 26 23 using System.Windows.Forms; … … 41 38 } 42 39 40 public override void SnapToGrid(IGrid grid) { } 41 public override void SnapToGrid(PointD point, IGrid grid) { } 42 43 43 public override Cursor GetCursor(PointD point) { 44 44 return cursor; -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Properties/AssemblyInfo.frame
r12535 r13045 53 53 // You can specify all the values or you can default the Revision and Build Numbers 54 54 // 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 74 74 this.AcceptButton = this.okButton; 75 75 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 76 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode. Font;76 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 77 77 this.ClientSize = new System.Drawing.Size(506, 306); 78 78 this.Controls.Add(this.propertyGrid); -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/PropertiesDialog.cs
r12535 r13045 23 23 using System.Collections.Generic; 24 24 using System.ComponentModel; 25 using System.Data;26 25 using System.Drawing; 27 26 using System.Text; -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Structs/Offset.cs
r12535 r13045 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Text;25 using System.Drawing;26 23 27 24 namespace HeuristicLab.Visualization { -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Structs/PointD.cs
r12535 r13045 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Text;25 23 using System.Drawing; 26 24 … … 86 84 } 87 85 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); 89 95 } 90 96 public static explicit operator SizeD(PointD point) {
Note: See TracChangeset
for help on using the changeset viewer.