Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/22/10 00:44:01 (14 years ago)
Author:
swagner
Message:

Sorted usings and removed unused usings in entire solution (#1094)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/UndoRedo/Commands/TransformCommand.cs

    r2768 r4068  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Text;
    42using System.Collections;
    53using System.Drawing;
    6 namespace Netron.Diagramming.Core
    7 {
    8     /// <summary>
    9     /// ICommand implementation of the transform action
    10     /// </summary>
    11     class TransformCommand : Command
    12     {
    13         #region Fields
    14         Hashtable transformers;
    15        
    16         double scalex, scaley;
    17         Point origin;
    18         #endregion
     4namespace Netron.Diagramming.Core {
     5  /// <summary>
     6  /// ICommand implementation of the transform action
     7  /// </summary>
     8  class TransformCommand : Command {
     9    #region Fields
     10    Hashtable transformers;
    1911
    20         #region Properties
     12    double scalex, scaley;
     13    Point origin;
     14    #endregion
     15
     16    #region Properties
    2117
    2218
    2319
    24         #endregion
     20    #endregion
    2521
    26         #region Constructor
    27         /// <summary>
    28         /// Initializes a new instance of the <see cref="T:TransformCommand"/> class.
    29         /// </summary>
    30         /// <param name="controller">The controller.</param>
    31         /// <param name="origin">The origin.</param>
    32         /// <param name="scalex">The scalex.</param>
    33         /// <param name="scaley">The scaley.</param>
    34         /// <param name="transformers">The transformers.</param>
    35         public TransformCommand(IController controller, Point origin, double scalex, double scaley, Hashtable transformers)
    36             : base(controller)
    37         {
    38             this.Text = "Transform selection";
    39             this.transformers = transformers;
    40             this.origin = origin;
    41             this.scalex = scalex;
    42             this.scaley = scaley;
    43         }
    44         #endregion
     22    #region Constructor
     23    /// <summary>
     24    /// Initializes a new instance of the <see cref="T:TransformCommand"/> class.
     25    /// </summary>
     26    /// <param name="controller">The controller.</param>
     27    /// <param name="origin">The origin.</param>
     28    /// <param name="scalex">The scalex.</param>
     29    /// <param name="scaley">The scaley.</param>
     30    /// <param name="transformers">The transformers.</param>
     31    public TransformCommand(IController controller, Point origin, double scalex, double scaley, Hashtable transformers)
     32      : base(controller) {
     33      this.Text = "Transform selection";
     34      this.transformers = transformers;
     35      this.origin = origin;
     36      this.scalex = scalex;
     37      this.scaley = scaley;
     38    }
     39    #endregion
    4540
    46         #region Methods
     41    #region Methods
    4742
    48         /// <summary>
    49         /// Perform redo of this command.
    50         /// </summary>
    51         public override void Redo()
    52         {
    53             //necessary to invalidate
    54             Rectangle recBefore = CalculateRectangle(this.transformers);
    55             recBefore.Inflate(20, 20);
    56             Transform(this.origin, scalex, scaley, transformers);
    57             Rectangle recAfter = CalculateRectangle(this.transformers);
    58             recAfter.Inflate(20, 20);
    59             this.Controller.View.Invalidate(recBefore);
    60             this.Controller.View.Invalidate(recAfter);
     43    /// <summary>
     44    /// Perform redo of this command.
     45    /// </summary>
     46    public override void Redo() {
     47      //necessary to invalidate
     48      Rectangle recBefore = CalculateRectangle(this.transformers);
     49      recBefore.Inflate(20, 20);
     50      Transform(this.origin, scalex, scaley, transformers);
     51      Rectangle recAfter = CalculateRectangle(this.transformers);
     52      recAfter.Inflate(20, 20);
     53      this.Controller.View.Invalidate(recBefore);
     54      this.Controller.View.Invalidate(recAfter);
    6155
    62         }
    63         /// <summary>
    64         /// Calculates the bounding rectangle of the transformed items.
    65         /// </summary>
    66         /// <param name="transformers">The transformers.</param>
    67         /// <returns></returns>
    68         public static Rectangle CalculateRectangle(Hashtable transformers)
    69         {
    70             Rectangle rec = Rectangle.Empty;
    71             if(transformers == null || transformers.Count == 0)
    72                 return Rectangle.Empty;
    73             bool first = true;
    74             foreach(object val in transformers.Values)
    75             {
    76                 EntityBone bone = (EntityBone) val;
    77                 if(bone.Rectangle.Equals(Rectangle.Empty))
    78                     continue;
    79                 if(first)
     56    }
     57    /// <summary>
     58    /// Calculates the bounding rectangle of the transformed items.
     59    /// </summary>
     60    /// <param name="transformers">The transformers.</param>
     61    /// <returns></returns>
     62    public static Rectangle CalculateRectangle(Hashtable transformers) {
     63      Rectangle rec = Rectangle.Empty;
     64      if (transformers == null || transformers.Count == 0)
     65        return Rectangle.Empty;
     66      bool first = true;
     67      foreach (object val in transformers.Values) {
     68        EntityBone bone = (EntityBone)val;
     69        if (bone.Rectangle.Equals(Rectangle.Empty))
     70          continue;
     71        if (first) {
     72          rec = bone.Rectangle;
     73          first = false;
     74        } else
     75          rec = Rectangle.Union(rec, bone.Rectangle);
     76
     77      }
     78      return rec;
     79    }
     80
     81    /// <summary>
     82    /// Perform undo of this command.
     83    /// </summary>
     84    public override void Undo() {
     85      //necessary to invalidate
     86      Rectangle recBefore = CalculateRectangle(this.transformers);
     87      recBefore.Inflate(20, 20);
     88      Transform(this.origin, 1, 1, transformers);
     89      Rectangle recAfter = CalculateRectangle(this.transformers);
     90      recAfter.Inflate(20, 20);
     91      this.Controller.View.Invalidate(recBefore);
     92      this.Controller.View.Invalidate(recAfter);
     93    }
     94
     95    public static void Transform(
     96        Point origin,
     97        double scalex,
     98        double scaley,
     99        Hashtable transformers) {
     100      Rectangle r;
     101      int x, y, w, h;
     102
     103      //the new location of the connector
     104
     105      EntityBone bone;
     106      IConnection conn;
     107      IShape shape;
     108
     109      //Scale the entities; this could be done via matrix transform but it seems some rounding is necessary since I got terrible
     110      //decimal accumulation mistakes without rounding off the double data type.
     111      //However, if one rotation of shapes will be added the matrix tranfromation will be unavoidable.
     112      foreach (object key in transformers.Keys) {
     113        bone = (EntityBone)transformers[key];
     114        r = bone.Rectangle;
     115        //Scale the rectangle if not empty. If the rectangle is empty it is a connection.
     116        if (r.Equals(Rectangle.Empty)) //the bone represents a connection
    80117                {
    81                     rec = bone.Rectangle;
    82                     first = false;
    83                 }
    84                 else
    85                     rec = Rectangle.Union(rec, bone.Rectangle);
     118          conn = key as IConnection;
     119          //scaling of the From connector
     120          if (!bone.ConnectorPoints[0].Equals(Point.Empty)) {
    86121
    87             }
    88             return rec;
    89         }
     122            x = Convert.ToInt32(Math.Round(((double)bone.ConnectorPoints[0].X - (double)origin.X) * scalex + origin.X - conn.From.Point.X, 1));
     123            y = Convert.ToInt32(Math.Round(((double)bone.ConnectorPoints[0].Y - (double)origin.Y) * scaley + origin.Y - conn.From.Point.Y, 1));
     124            //it's important to use the Move method because shifting the Point could entail additional moves on the attached connectors
     125            conn.From.MoveBy(new Point(x, y));
     126          }
     127          //scaling of the To connector
     128          if (!bone.ConnectorPoints[1].Equals(Point.Empty)) {
     129            x = Convert.ToInt32(Math.Round(((double)bone.ConnectorPoints[1].X - (double)origin.X) * scalex + origin.X - conn.To.Point.X, 1));
     130            y = Convert.ToInt32(Math.Round(((double)bone.ConnectorPoints[1].Y - (double)origin.Y) * scaley + origin.Y - conn.To.Point.Y, 1));
     131            conn.To.MoveBy(new Point(x, y));
     132          }
     133        } else    //it's a shape
     134                {
     135          shape = key as IShape;
    90136
    91         /// <summary>
    92         /// Perform undo of this command.
    93         /// </summary>
    94         public override void Undo()
    95         {
    96             //necessary to invalidate
    97             Rectangle recBefore = CalculateRectangle(this.transformers);
    98             recBefore.Inflate(20, 20);
    99             Transform(this.origin, 1, 1, transformers);
    100             Rectangle recAfter = CalculateRectangle(this.transformers);
    101             recAfter.Inflate(20, 20);
    102             this.Controller.View.Invalidate(recBefore);
    103             this.Controller.View.Invalidate(recAfter);
    104         }
     137          //TransformShape(ref origin, scalex, scaley, ref r, ref bone, key, out x, out y, out w, out h, out a, out b, out p, out shape);
     138          x = Convert.ToInt32(Math.Round(
     139              (r.X - origin.X) * scalex + origin.X, 1));
    105140
    106         public static void Transform(
    107             Point origin,
    108             double scalex,
    109             double scaley,
    110             Hashtable transformers)
    111         {
    112             Rectangle r;
    113             int x, y, w, h;
    114            
    115             //the new location of the connector
    116        
    117             EntityBone bone;           
    118             IConnection conn;
    119             IShape shape;
     141          y = Convert.ToInt32(Math.Round(
     142              (r.Y - origin.Y) * scaley + origin.Y, 1));
    120143
    121             //Scale the entities; this could be done via matrix transform but it seems some rounding is necessary since I got terrible
    122             //decimal accumulation mistakes without rounding off the double data type.
    123             //However, if one rotation of shapes will be added the matrix tranfromation will be unavoidable.
    124             foreach(object key in transformers.Keys)
    125             {
    126                 bone = (EntityBone) transformers[key];
    127                 r = bone.Rectangle;
    128                 //Scale the rectangle if not empty. If the rectangle is empty it is a connection.
    129                 if(r.Equals(Rectangle.Empty)) //the bone represents a connection
    130                 {
    131                     conn = key as IConnection;
    132                     //scaling of the From connector
    133                     if(!bone.ConnectorPoints[0].Equals(Point.Empty))
    134                     {
     144          w = Convert.ToInt32(r.Width * scalex);
    135145
    136                         x = Convert.ToInt32(Math.Round(((double) bone.ConnectorPoints[0].X - (double) origin.X) * scalex + origin.X - conn.From.Point.X, 1));
    137                         y = Convert.ToInt32(Math.Round(((double) bone.ConnectorPoints[0].Y - (double) origin.Y) * scaley + origin.Y - conn.From.Point.Y, 1));
    138                         //it's important to use the Move method because shifting the Point could entail additional moves on the attached connectors
    139                         conn.From.MoveBy(new Point(x, y));
    140                     }
    141                     //scaling of the To connector
    142                     if(!bone.ConnectorPoints[1].Equals(Point.Empty))
    143                     {
    144                         x = Convert.ToInt32(Math.Round(((double) bone.ConnectorPoints[1].X - (double) origin.X) * scalex + origin.X - conn.To.Point.X, 1));
    145                         y = Convert.ToInt32(Math.Round(((double) bone.ConnectorPoints[1].Y - (double) origin.Y) * scaley + origin.Y - conn.To.Point.Y, 1));
    146                         conn.To.MoveBy(new Point(x, y));
    147                     }
    148                 }
    149                 else    //it's a shape
    150                 {
    151                     shape = key as IShape;
     146          h = Convert.ToInt32(r.Height * scaley);
    152147
    153                     //TransformShape(ref origin, scalex, scaley, ref r, ref bone, key, out x, out y, out w, out h, out a, out b, out p, out shape);
    154                     x = Convert.ToInt32(Math.Round(
    155                         (r.X - origin.X) * scalex + origin.X, 1));
    156 
    157                     y = Convert.ToInt32(Math.Round(
    158                         (r.Y - origin.Y) * scaley + origin.Y, 1));
    159 
    160                     w = Convert.ToInt32(r.Width * scalex);
    161 
    162                     h = Convert.ToInt32(r.Height * scaley);
    163 
    164                     // Only perform the tranform if the rectangle's height
    165                     // and width are less than or equal to the shape's 
    166                     // min/max size.
    167                     if ((w <= shape.MaxSize.Width) &&
    168                         (h <= shape.MaxSize.Height) &&
    169                         (w >= shape.MinSize.Width) &&
    170                         (h >= shape.MinSize.Height))
    171                     {
    172                         shape.Transform(x, y, w, h);
    173                     }
    174 
    175                 }
    176 
    177             }
     148          // Only perform the tranform if the rectangle's height
     149          // and width are less than or equal to the shape's 
     150          // min/max size.
     151          if ((w <= shape.MaxSize.Width) &&
     152              (h <= shape.MaxSize.Height) &&
     153              (w >= shape.MinSize.Width) &&
     154              (h >= shape.MinSize.Height)) {
     155            shape.Transform(x, y, w, h);
     156          }
    178157
    179158        }
    180159
    181         //private static void TransformShape(ref Point origin, double scalex, double scaley, ref Rectangle r, ref EntityBone bone, object key, out int x, out int y, out int w, out int h, out double a, out double b, out Point p, out IShape shape)
    182         //{
     160      }
     161
     162    }
     163
     164    //private static void TransformShape(ref Point origin, double scalex, double scaley, ref Rectangle r, ref EntityBone bone, object key, out int x, out int y, out int w, out int h, out double a, out double b, out Point p, out IShape shape)
     165    //{
    183166
    184167
    185         //    //(key as IDiagramEntity).Rectangle = new Rectangle(x, y, w, h);
     168    //    //(key as IDiagramEntity).Rectangle = new Rectangle(x, y, w, h);
    186169
    187         //    if(bone.ConnectorPoints != null)
    188         //    {
    189         //        shape = key as IShape;
    190         //        for(int m = 0; m < bone.ConnectorPoints.Length; m++)
    191         //        {
    192         //            a = Math.Round(((double) bone.ConnectorPoints[m].X - (double) r.X) / (double) r.Width, 1) * w + x - shape.Connectors[m].Point.X;
    193         //            b = Math.Round(((double) bone.ConnectorPoints[m].Y - (double) r.Y) / (double) r.Height, 1) * h + y - shape.Connectors[m].Point.Y;
    194         //            p = new Point(Convert.ToInt32(a), Convert.ToInt32(b));
    195         //            shape.Connectors[m].Move(p);
    196         //        }
    197         //    }
    198         //}
     170    //    if(bone.ConnectorPoints != null)
     171    //    {
     172    //        shape = key as IShape;
     173    //        for(int m = 0; m < bone.ConnectorPoints.Length; m++)
     174    //        {
     175    //            a = Math.Round(((double) bone.ConnectorPoints[m].X - (double) r.X) / (double) r.Width, 1) * w + x - shape.Connectors[m].Point.X;
     176    //            b = Math.Round(((double) bone.ConnectorPoints[m].Y - (double) r.Y) / (double) r.Height, 1) * h + y - shape.Connectors[m].Point.Y;
     177    //            p = new Point(Convert.ToInt32(a), Convert.ToInt32(b));
     178    //            shape.Connectors[m].Move(p);
     179    //        }
     180    //    }
     181    //}
    199182
    200183
    201184
    202         #endregion
    203     }
     185    #endregion
     186  }
    204187
    205188}
Note: See TracChangeset for help on using the changeset viewer.