Changeset 13076
- Timestamp:
- 10/29/15 09:27:31 (9 years ago)
- Location:
- branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3
- Files:
-
- 5 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartControl.Designer.cs
r13045 r13076 55 55 this.propertiesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 56 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 57 this.buttonPanel = new System.Windows.Forms.FlowLayoutPanel(); 62 58 this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); … … 173 169 this.saveFileDialog.Filter = "Bitmap (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg|EMF (*.emf)|*.emf|PNG (*.png)|*.png|GIF (" + 174 170 "*.gif)|*.gif|TIFF (*.tif)|*.tif"; 175 //176 // selectButton177 //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 // moveButton191 //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 // zoomInButton205 //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 // zoomOutButton219 //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 // buttonPanel233 //234 171 this.buttonPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 235 172 | 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 173 this.buttonPanel.Location = new System.Drawing.Point(0, 0); 241 174 this.buttonPanel.Name = "buttonPanel"; … … 275 208 protected System.Windows.Forms.ToolStripSeparator toolStripMenuItem1; 276 209 protected System.Windows.Forms.ToolStripSeparator toolStripMenuItem2; 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 210 protected System.Windows.Forms.FlowLayoutPanel buttonPanel; 282 211 protected System.Windows.Forms.SaveFileDialog saveFileDialog; -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartControl.cs
r13045 r13076 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.ComponentModel; 24 25 using System.Drawing; 25 using System.Drawing.Drawing2D;26 26 using System.Drawing.Imaging; 27 27 using System.Linq; … … 30 30 namespace HeuristicLab.Visualization { 31 31 public partial class ChartControl : UserControl { 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 32 protected Bitmap Picture; 37 33 protected bool RenderingRequired; 38 protected Point ButtonDownPoint; 39 protected Point PreviousLocation; 40 protected int MouseClickCount; 34 protected Dictionary<Type, ChartMode> Modes = new Dictionary<Type, ChartMode>(); 41 35 42 36 protected bool SuppressEvents { get; set; } 43 37 private bool SuppressRender { get; set; } 38 39 public PictureBox PictureBox { get { return pictureBox; } } 44 40 45 41 private IChart chart; … … 78 74 InitializeComponent(); 79 75 ScaleOnResize = true; 80 Mode = ChartMode.Select;81 76 Chart = defaultChart ?? new Chart(0, 0, Width, Height); 77 } 78 79 public void AddChartModes(params ChartMode[] chartModes) { 80 foreach (var chartMode in chartModes) 81 Modes.Add(chartMode.GetType(), chartMode); 82 83 RebuildButtonPanel(); 84 } 85 86 protected virtual void RebuildButtonPanel() { 87 buttonPanel.Controls.Clear(); 88 89 int locationY = 3; 90 foreach (var chartMode in Modes.Values) { 91 var rb = CreateChartModeRadioButton(chartMode); 92 rb.Location = new Point(3, locationY); 93 toolTip.SetToolTip(rb, chartMode.ToolTip); 94 buttonPanel.Controls.Add(rb); 95 locationY += rb.Height + rb.Margin.Vertical; 96 } 82 97 } 83 98 … … 92 107 93 108 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; 109 foreach (var rb in buttonPanel.Controls.OfType<RadioButton>()) 110 rb.Checked = rb.Tag == Mode; 102 111 } 103 112 … … 107 116 108 117 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 if (mode == null) return null; 119 120 return mode.Cursor; 118 121 } 119 122 … … 150 153 151 154 protected virtual void PictureBoxOnMouseClick(object sender, MouseEventArgs e) { 152 155 if (mode == null) return; 156 mode.HandleOnMouseClick(sender, e); 153 157 } 154 158 155 159 protected virtual void PictureBoxOnMouseDoubleClick(object sender, MouseEventArgs e) { 156 160 if (mode == null) return; 161 mode.HandleOnMouseDoubleClick(sender, e); 157 162 } 158 163 159 164 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 } 165 if (mode == null) return; 166 mode.HandleOnKeyDown(sender, e); 169 167 } 170 168 171 169 protected virtual void OnKeyUp(object sender, KeyEventArgs e) { 172 170 if (mode == null) return; 171 mode.HandleOnKeyUp(sender, e); 173 172 } 174 173 175 174 protected virtual void PictureBoxOnMouseWheel(object sender, MouseEventArgs e) { 176 175 if (mode == null) return; 176 mode.HandleOnMouseWheel(sender, e); 177 177 } 178 178 179 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(); } 180 if (mode == null) return; 181 mode.HandleOnMouseDown(sender, e); 193 182 } 194 183 195 184 protected virtual void PictureBoxOnMouseUp(object sender, MouseEventArgs e) { 196 if (Chart == null) return; 197 if (e.Button == MouseButtons.Left) { 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) { 185 if (mode == null) return; 186 mode.HandleOnMouseUp(sender, e); 187 188 if (Chart == null) return; 189 190 if (e.Button == MouseButtons.Right) { 209 191 propertiesToolStripMenuItem.Enabled = Chart.Group.SelectedPrimitives.Count() == 1; 210 192 oneLayerUpToolStripMenuItem.Enabled = Chart.Group.SelectedPrimitives.Count() == 1; … … 212 194 intoForegroundToolStripMenuItem.Enabled = Chart.Group.SelectedPrimitives.Count() == 1; 213 195 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 196 } 225 197 } … … 227 199 protected virtual void PictureBoxOnMouseMove(object sender, MouseEventArgs e) { 228 200 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) { 259 pictureBox.Refresh(); 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 } 268 } 269 } 270 } finally { 271 PreviousLocation = e.Location; 272 pictureBox.Update(); 201 Invoke((Action<object, MouseEventArgs>)PictureBoxOnMouseMove, sender, e); 202 } else { 203 var toolTipText = Chart.GetToolTipText(e.Location); 204 if (toolTip.GetToolTip(pictureBox) != toolTipText) toolTip.SetToolTip(pictureBox, toolTipText); 205 206 if (mode == null) return; 207 208 mode.HandleOnMouseMove(sender, e); 209 210 SetPictureBoxCursor(mode.Cursor); 273 211 } 274 212 } … … 276 214 protected virtual void PictureBoxOnMouseEnter(object sender, EventArgs e) { 277 215 if (InvokeRequired) { 278 Invoke((Action< Object, MouseEventArgs>)PictureBoxOnMouseEnter, sender, e);216 Invoke((Action<object, MouseEventArgs>)PictureBoxOnMouseEnter, sender, e); 279 217 return; 280 218 } 281 219 if (!Focused) this.pictureBox.Focus(); 220 221 if (mode == null) return; 222 223 mode.HandleOnMouseEnter(sender, e); 282 224 } 283 225 284 226 protected virtual void PictureBoxOnMouseLeave(object sender, EventArgs e) { 285 227 if (mode == null) return; 228 mode.HandleOnMouseLeave(sender, e); 286 229 } 287 230 … … 292 235 } 293 236 if (!Focused) this.pictureBox.Focus(); 237 238 if (mode == null) return; 239 240 mode.HandleOnClick(sender, e); 294 241 } 295 242 #endregion … … 392 339 } 393 340 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 341 private void ChartControl_Load(object sender, EventArgs e) { 411 342 if (!SuppressRender) GenerateImage(); 412 343 } 344 345 #region Helpers 346 private RadioButton CreateChartModeRadioButton(ChartMode chartMode) { 347 var rb = new RadioButton { 348 Appearance = Appearance.Button, 349 Image = chartMode.Image, 350 Size = new Size(24, 24), 351 TabStop = true, 352 Tag = chartMode, 353 UseVisualStyleBackColor = true 354 }; 355 356 rb.CheckedChanged += (sender, args) => { if (rb.Checked) Mode = chartMode; }; 357 358 return rb; 359 } 360 #endregion 413 361 } 414 362 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartMode.cs
r13045 r13076 20 20 #endregion 21 21 22 using System; 23 using System.Drawing; 24 using System.Windows.Forms; 25 22 26 namespace HeuristicLab.Visualization { 23 public class ChartMode { 24 protected ChartMode() { } 27 public abstract class ChartMode { 28 protected readonly ChartControl chartControl; 29 protected Cursor cursor; 30 protected Point buttonDownPoint; 31 protected Point previousLocation; 32 protected int mouseClickCount; 25 33 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(); 34 public abstract Image Image { get; } 35 public abstract string ToolTip { get; } 36 37 public virtual Cursor Cursor { 38 get { return cursor ?? (cursor = Cursors.Default); } 39 } 40 41 protected ChartMode(ChartControl control) { 42 chartControl = control; 43 } 44 45 public virtual void HandleOnKeyDown(object sender, KeyEventArgs e) { } 46 public virtual void HandleOnKeyUp(object sender, KeyEventArgs e) { } 47 public virtual void HandleOnMouseClick(object sender, MouseEventArgs e) { } 48 public virtual void HandleOnMouseDoubleClick(object sender, MouseEventArgs e) { } 49 public virtual void HandleOnMouseWheel(object sender, MouseEventArgs e) { } 50 51 public virtual void HandleOnMouseDown(object sender, MouseEventArgs e) { 52 buttonDownPoint = e.Location; 53 mouseClickCount = e.Clicks; 54 } 55 56 public virtual void HandleOnMouseUp(object sender, MouseEventArgs e) { } 57 public virtual void HandleOnMouseMove(object sender, MouseEventArgs e) { } 58 public virtual void HandleOnMouseEnter(object sender, EventArgs e) { } 59 public virtual void HandleOnMouseLeave(object sender, EventArgs e) { } 60 public virtual void HandleOnClick(object sender, EventArgs e) { } 30 61 } 31 62 } -
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/HeuristicLab.Visualization-3.3.csproj
r13045 r13076 130 130 <Compile Include="ChartMode.cs" /> 131 131 <Compile Include="AxisType.cs" /> 132 <Compile Include="ChartModes\MoveChartMode.cs" /> 132 133 <Compile Include="Primitives\Grid.cs" /> 133 134 <Compile Include="Properties\Resources.Designer.cs"> … … 136 137 <DependentUpon>Resources.resx</DependentUpon> 137 138 </Compile> 139 <Compile Include="ChartModes\SelectChartMode.cs" /> 138 140 <Compile Include="Trees\LayoutEngines\BoxesLayoutEngine.cs" /> 139 141 <Compile Include="Trees\LayoutEngines\ILayoutEngine.cs" /> … … 142 144 <Compile Include="Trees\VisualTreeNode.cs" /> 143 145 <Compile Include="Trees\VisualTreeNodeConnection.cs" /> 146 <Compile Include="ChartModes\ZoomInChartMode.cs" /> 147 <Compile Include="ChartModes\ZoomOutChartMode.cs" /> 144 148 <None Include="Plugin.cs.frame" /> 145 149 <Compile Include="Plugin.cs" />
Note: See TracChangeset
for help on using the changeset viewer.