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/Tools/SendForwardsTool.cs

    r2868 r4068  
    11using System;
     2using System.Collections;
     3using System.Collections.Generic;
    24using System.Diagnostics;
    3 using System.Collections;
    4 using System.Drawing;
    5 using System.Windows.Forms;
    6 using System.Collections.Generic;
    7 namespace Netron.Diagramming.Core
    8 {
     5namespace Netron.Diagramming.Core {
     6  /// <summary>
     7  /// Send forward tool which moves the selection up in the z-order.
     8  /// </summary>
     9  class SendForwardsTool : AbstractTool {
     10
     11    #region Fields
     12
     13    #endregion
     14
     15    #region Constructor
    916    /// <summary>
    10     /// Send forward tool which moves the selection up in the z-order.
     17    /// Initializes a new instance of the <see cref="T:SendBackwards"/> class.
    1118    /// </summary>
    12     class SendForwardsTool : AbstractTool
    13     {
     19    /// <param name="name">The name of the tool.</param>
     20    public SendForwardsTool(string name)
     21      : base(name) {
     22    }
     23    #endregion
    1424
    15         #region Fields
    16      
    17         #endregion
     25    #region Methods
    1826
    19         #region Constructor
    20         /// <summary>
    21         /// Initializes a new instance of the <see cref="T:SendBackwards"/> class.
    22         /// </summary>
    23         /// <param name="name">The name of the tool.</param>
    24         public SendForwardsTool(string name)
    25             : base(name)
    26         {
     27    /// <summary>
     28    /// Called when the tool is activated.
     29    /// </summary>
     30    protected override void OnActivateTool() {
     31      /*
     32       * A lot of stuff is calculated here for something which might seem at first sight
     33       * a really simple action. In general the calculations will be short since a user does not
     34       * usually shift many shapes at the same time and the overlap with the selection
     35       * is small.
     36       */
     37      if (this.Controller.Model.Selection.SelectedItems != null && this.Controller.Model.Selection.SelectedItems.Count > 0) {
     38
     39        /*
     40         * They should give me a Nobel prize for so much thinking early in the morning...
     41         */
     42        #region Preparation of the ordering
     43        Debug.Assert(this.Controller.Model.Selection.SelectedItems[0] != null, "A selection cannot contain a 'null' entity.");
     44        //the items have to be moved in the order of the Paintables; the SortedList automatically orders things for us.
     45        SortedList<int, IDiagramEntity> list = new SortedList<int, IDiagramEntity>();
     46        //We fetch a flattened selection, which means that if there is a group the constituents will be
     47        //returned rather than the group itself.
     48        foreach (IDiagramEntity entity in this.Controller.Model.Selection.FlattenedSelectionItems) {
     49          //the addition will automatically put the item in increasing order
     50          list.Add(this.Controller.Model.Paintables.IndexOf(entity), entity);
     51        }
     52        //if the highest z-value is the last one in the paintables we cannot shift anything, so we quit
     53        if (list.Keys[list.Count - 1] == this.Controller.Model.Paintables.Count - 1) return;
     54
     55        /*Send them forwards but make sure it's a visible effect!
     56        It's not enough to move it only once since the shape(s) above might be of
     57        high z-order degree, so we have to find which is the first shape overlapping with
     58        the selection and take as many steps as it takes to surpass it.
     59         If there is no overlap we'll shift the z-order with just one unit.
     60        */
     61        int delta = 1;
     62        int lowestZInSelection = list.Keys[0];
     63        bool found = false;
     64        //we can speed up the loop by noticing that the next shape in the z-stack is necessarily
     65        //above the first one of the selection
     66        for (int m = lowestZInSelection + 1; m < this.Controller.Model.Paintables.Count && !found; m++) {
     67          //the overlap has to be with an entity, not from the selection
     68          if (list.ContainsValue(this.Controller.Model.Paintables[m])) continue;
     69          for (int s = 0; s < list.Count; s++) {
     70            //if there is an overlap we found the required index
     71            if (this.Controller.Model.Paintables[m].Rectangle.IntersectsWith(list.Values[s].Rectangle)) {
     72              //an additional complication here; if the found shape is part of a group we have
     73              //to take the upper z-value of the group...
     74              if (this.Controller.Model.Paintables[m].Group != null) {
     75                int max = -1;
     76                CollectionBase<IDiagramEntity> leafs = new CollectionBase<IDiagramEntity>();
     77                Utils.TraverseCollect(this.Controller.Model.Paintables[m].Group, ref leafs);
     78                foreach (IDiagramEntity groupMember in leafs) {
     79                  max = Math.Max(max, this.Controller.Model.Paintables.IndexOf(groupMember));
     80                }
     81                //take the found z-value of the group rather than the one of the group-child
     82                m = max;
     83              }
     84              delta = m - lowestZInSelection;
     85              found = true;
     86              break;
     87            }
     88
     89          }
    2790        }
    2891        #endregion
     92        Debug.Assert(delta >= 1, "The shift cannot be less than one since we checked previous situations earlier.");
     93        for (int k = 0; k < list.Count; k++) {
     94          this.Controller.Model.SendForwards(list.Values[k], delta);
     95        }
     96      }
     97      DeactivateTool();
     98    }
    2999
    30         #region Methods
    31 
    32         /// <summary>
    33         /// Called when the tool is activated.
    34         /// </summary>
    35         protected override void OnActivateTool()
    36         {
    37             /*
    38              * A lot of stuff is calculated here for something which might seem at first sight
    39              * a really simple action. In general the calculations will be short since a user does not
    40              * usually shift many shapes at the same time and the overlap with the selection
    41              * is small.
    42              */
    43           if (this.Controller.Model.Selection.SelectedItems != null && this.Controller.Model.Selection.SelectedItems.Count > 0)
    44             {
    45                
    46                 /*
    47                  * They should give me a Nobel prize for so much thinking early in the morning...
    48                  */
    49                 #region Preparation of the ordering
    50             Debug.Assert(this.Controller.Model.Selection.SelectedItems[0] != null, "A selection cannot contain a 'null' entity.");               
    51                 //the items have to be moved in the order of the Paintables; the SortedList automatically orders things for us.
    52                 SortedList<int, IDiagramEntity> list = new SortedList<int,IDiagramEntity>();
    53                 //We fetch a flattened selection, which means that if there is a group the constituents will be
    54                 //returned rather than the group itself.
    55                 foreach (IDiagramEntity entity in this.Controller.Model.Selection.FlattenedSelectionItems)
    56                 {
    57                     //the addition will automatically put the item in increasing order
    58                     list.Add(this.Controller.Model.Paintables.IndexOf(entity), entity);                   
    59                 }
    60                 //if the highest z-value is the last one in the paintables we cannot shift anything, so we quit
    61                 if (list.Keys[list.Count - 1] == this.Controller.Model.Paintables.Count - 1) return;
    62                
    63                 /*Send them forwards but make sure it's a visible effect!
    64                 It's not enough to move it only once since the shape(s) above might be of
    65                 high z-order degree, so we have to find which is the first shape overlapping with
    66                 the selection and take as many steps as it takes to surpass it.
    67                  If there is no overlap we'll shift the z-order with just one unit.
    68                 */
    69                 int delta = 1;
    70                 int lowestZInSelection = list.Keys[0];
    71                 bool found = false;
    72                 //we can speed up the loop by noticing that the next shape in the z-stack is necessarily
    73                 //above the first one of the selection
    74                 for (int m = lowestZInSelection+1; m < this.Controller.Model.Paintables.Count && !found; m++)
    75                 {
    76                     //the overlap has to be with an entity, not from the selection
    77                     if(list.ContainsValue(this.Controller.Model.Paintables[m])) continue;
    78                     for(int s=0; s<list.Count; s++)
    79                     {
    80                         //if there is an overlap we found the required index
    81                         if (this.Controller.Model.Paintables[m].Rectangle.IntersectsWith(list.Values[s].Rectangle))
    82                         {
    83                             //an additional complication here; if the found shape is part of a group we have
    84                             //to take the upper z-value of the group...
    85                             if (this.Controller.Model.Paintables[m].Group != null)
    86                             {
    87                                 int max = -1;
    88                                 CollectionBase<IDiagramEntity> leafs = new CollectionBase<IDiagramEntity>();
    89                                 Utils.TraverseCollect(this.Controller.Model.Paintables[m].Group, ref leafs);
    90                                 foreach (IDiagramEntity groupMember in leafs)
    91                                 {
    92                                     max = Math.Max(max, this.Controller.Model.Paintables.IndexOf(groupMember));
    93                                 }
    94                                 //take the found z-value of the group rather than the one of the group-child
    95                                 m = max;
    96                             }
    97                             delta = m - lowestZInSelection;
    98                             found = true;
    99                             break;
    100                         }
    101 
    102                     }
    103                 }
    104                 #endregion
    105                 Debug.Assert(delta >= 1, "The shift cannot be less than one since we checked previous situations earlier.");
    106                 for (int k = 0; k < list.Count; k++)
    107                 {
    108                     this.Controller.Model.SendForwards(list.Values[k], delta);
    109                 }
    110             }
    111             DeactivateTool();
    112         }
    113        
    114         #endregion
     100    #endregion
    115101
    116102
    117     }
     103  }
    118104
    119105}
Note: See TracChangeset for help on using the changeset viewer.