Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/UndoRedo/Commands/UngroupCommand.cs @ 4068

Last change on this file since 4068 was 4068, checked in by swagner, 14 years ago

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

File size: 3.1 KB
Line 
1namespace Netron.Diagramming.Core {
2  /// <summary>
3  /// Ungroup command
4  /// </summary>
5  class UngroupCommand : Command {
6    #region Fields
7    IBundle bundle;
8    IController controller;
9    IGroup mGroup;
10    #endregion
11
12    #region Properties
13    /// <summary>
14    /// Gets the newly created group after <see cref="Redo"/> was called
15    /// </summary>
16    public IGroup Group {
17      get { return mGroup; }
18    }
19
20    /// <summary>
21    /// Gets the entities.
22    /// </summary>
23    /// <value>The shape.</value>
24    public CollectionBase<IDiagramEntity> Entities {
25      get { return bundle.Entities; }
26    }
27
28    #endregion
29
30    #region Constructor
31    /// <summary>
32    /// Initializes a new instance of the <see cref="T:UngroupCommand"/> class.
33    /// </summary>
34    /// <param name="controller">The controller.</param>
35    /// <param name="group">The group.</param>
36    public UngroupCommand(IController controller, IGroup group)
37      : base(controller) {
38      this.Text = "Ungroup";
39      this.controller = controller;
40      this.mGroup = group;
41      bundle = new Bundle();
42    }
43    #endregion
44
45    #region Methods
46
47    /// <summary>
48    /// Perform redo of this command.
49    /// </summary>
50    public override void Redo() {
51      //remove the group from the layer
52      this.Controller.Model.DefaultPage.DefaultLayer.Entities.Remove(mGroup);
53      //detach the entities from the group
54      foreach (IDiagramEntity entity in mGroup.Entities) {
55        //this will be recursive if an entity is itself an IGroup
56        entity.Group = null;
57        bundle.Entities.Add(entity);
58        //mGroup.Entities.Remove(entity);
59        Controller.Model.AddEntity(entity);
60      }
61      //change the visuals such that the entities in the group are selected
62
63      CollectionBase<IDiagramEntity> col = new CollectionBase<IDiagramEntity>();
64      col.AddRange(mGroup.Entities);
65
66      this.Controller.Model.Selection.SelectedItems = col;
67
68      mGroup.Invalidate();
69      mGroup = null;
70
71      //note that the entities have never been disconnected from the layer
72      //so they don't have to be re-attached to the anything.
73      //The insertion of the Group simply got pushed in the scene-graph.
74
75
76    }
77
78    /// <summary>
79    /// Perform undo of this command.
80    /// </summary>
81    public override void Undo() {
82
83      //create a new group
84      GroupShape group = new GroupShape(this.Controller.Model);
85      //asign the entities to the group
86      group.Entities = bundle.Entities;
87
88      foreach (IDiagramEntity entity in group.Entities) {
89        //this will be recursive if an entity is itself an IGroup
90        entity.Group = group;
91      }
92      //add the new group to the layer
93      this.Controller.Model.DefaultPage.DefaultLayer.Entities.Add(group);
94
95      mGroup = group;
96
97      //select the newly created group
98      CollectionBase<IDiagramEntity> col = new CollectionBase<IDiagramEntity>();
99      col.Add(mGroup);
100      this.Controller.Model.Selection.SelectedItems = col;
101      mGroup.Invalidate();
102
103
104    }
105
106
107    #endregion
108  }
109
110}
Note: See TracBrowser for help on using the repository browser.