[4068] | 1 | using System.Drawing;
|
---|
[2768] | 2 | using System.Windows.Forms;
|
---|
| 3 |
|
---|
[4068] | 4 | namespace Netron.Diagramming.Core {
|
---|
| 5 | public abstract class AlignmentToolBase : AbstractTool {
|
---|
| 6 | protected IDiagramEntity firstEntity;
|
---|
| 7 | protected int xLocationOfFirstEntity;
|
---|
| 8 | protected int yLocationOfFirstEntity;
|
---|
| 9 | protected int topEdgeOfFirstEntity;
|
---|
| 10 | protected int bottomEdgeOfFirstEntity;
|
---|
| 11 | protected Point centerOfFirstEntity;
|
---|
| 12 | protected int rightEdgeOfFirstEntity;
|
---|
[2768] | 13 |
|
---|
[4068] | 14 | // ------------------------------------------------------------------
|
---|
| 15 | /// <summary>
|
---|
| 16 | /// Constructor.
|
---|
| 17 | /// </summary>
|
---|
| 18 | /// <param name="toolName">string: The name of this tool</param>
|
---|
| 19 | // ------------------------------------------------------------------
|
---|
| 20 | public AlignmentToolBase(string toolName)
|
---|
| 21 | : base(toolName) {
|
---|
| 22 | }
|
---|
[2768] | 23 |
|
---|
[4068] | 24 | // ------------------------------------------------------------------
|
---|
| 25 | /// <summary>
|
---|
| 26 | /// Activates the tool. First a check is performed to ensure there
|
---|
| 27 | /// are at least two IDiagramEntities selected. If so, then the
|
---|
| 28 | /// x, y, top edge, bottom edge, and center of the first entity
|
---|
| 29 | /// is stored in local, protected variables for all other alignment
|
---|
| 30 | /// tools to use.
|
---|
| 31 | /// </summary>
|
---|
| 32 | // ------------------------------------------------------------------
|
---|
| 33 | protected override void OnActivateTool() {
|
---|
| 34 | base.OnActivateTool();
|
---|
[2768] | 35 |
|
---|
[4068] | 36 | // Make sure enough items were selected.
|
---|
| 37 | if (this.Controller.Model.Selection.SelectedItems == null) {
|
---|
| 38 | MessageBox.Show(
|
---|
| 39 | "Nothing is selected, you need to select at " +
|
---|
| 40 | "least two items to align.",
|
---|
| 41 | "Nothing selected.",
|
---|
| 42 | MessageBoxButtons.OK,
|
---|
| 43 | MessageBoxIcon.Hand);
|
---|
[2768] | 44 |
|
---|
[4068] | 45 | return;
|
---|
| 46 | }
|
---|
[2768] | 47 |
|
---|
[4068] | 48 | if (this.Controller.Model.Selection.SelectedItems.Count <= 1) {
|
---|
| 49 | MessageBox.Show(
|
---|
| 50 | "You need to select at least two items to align.",
|
---|
| 51 | "Nothing selected.",
|
---|
| 52 | MessageBoxButtons.OK,
|
---|
| 53 | MessageBoxIcon.Hand);
|
---|
[2768] | 54 |
|
---|
[4068] | 55 | return;
|
---|
| 56 | }
|
---|
[2768] | 57 |
|
---|
[4068] | 58 | // Since there are enough items, peform the alignment. But
|
---|
| 59 | // first get all aspects about the location of the first
|
---|
| 60 | // entity.
|
---|
| 61 | this.firstEntity = this.Controller.Model.Selection.SelectedItems[0];
|
---|
| 62 | this.xLocationOfFirstEntity = firstEntity.Rectangle.X;
|
---|
| 63 | this.yLocationOfFirstEntity = firstEntity.Rectangle.Y;
|
---|
| 64 | this.topEdgeOfFirstEntity = firstEntity.Rectangle.Top;
|
---|
| 65 | this.bottomEdgeOfFirstEntity = firstEntity.Rectangle.Bottom;
|
---|
| 66 | this.rightEdgeOfFirstEntity = firstEntity.Rectangle.Right;
|
---|
| 67 | this.centerOfFirstEntity = firstEntity.Center;
|
---|
[2768] | 68 |
|
---|
[4068] | 69 | this.Align(this.Controller.Model.Selection.SelectedItems.ToArray());
|
---|
[2768] | 70 |
|
---|
[4068] | 71 | // Reset the Tracker.
|
---|
| 72 | this.Controller.View.ShowTracker();
|
---|
| 73 | DeactivateTool();
|
---|
| 74 | }
|
---|
[2768] | 75 |
|
---|
[4068] | 76 | // ------------------------------------------------------------------
|
---|
| 77 | /// <summary>
|
---|
| 78 | /// Abstract method to be implemented by all alignment tools.
|
---|
| 79 | /// </summary>
|
---|
| 80 | /// <param name="entities">IDiagramEntity[]: All selected
|
---|
| 81 | /// entities.</param>
|
---|
| 82 | // ------------------------------------------------------------------
|
---|
| 83 | public abstract void Align(IDiagramEntity[] entities);
|
---|
| 84 | }
|
---|
[2768] | 85 | }
|
---|