Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceOverhaul/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Utils/Bundle.cs

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

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

File size: 7.2 KB
Line 
1using System;
2using System.Drawing;
3using System.Runtime.Serialization;
4using System.Windows.Forms;
5namespace Netron.Diagramming.Core {
6  /// <summary>
7  /// A bundle is a collection of diagram entities which does not
8  /// necessarily have a place in the scene graph but merely serves
9  /// to bundle items together. Various actions and functions are made
10  /// possible by bundles; cut/copy/paste, templates, user selections
11  /// and so on.  While a group can have sub-groups, bundles cannot be
12  /// contained in another and are not necessarily connected (in the sense
13  /// of a connected branch in the scene graph).
14  /// </summary>
15  [Serializable()]
16  public class Bundle : DiagramEntityBase, IBundle, ISerializable {
17
18    #region Fields
19    /// <summary>
20    /// the Shapes field
21    /// </summary>
22    private CollectionBase<IDiagramEntity> mEntities =
23        new CollectionBase<IDiagramEntity>();
24
25    #endregion
26
27    #region Properties
28    /// <summary>
29    /// Gets or sets the entities.
30    /// </summary>
31    /// <value>The m entities.</value>
32    public CollectionBase<IDiagramEntity> Entities {
33      get {
34        return mEntities;
35      }
36    }
37    /// <summary>
38    /// Gets the name of the entity.
39    /// </summary>
40    /// <value>The name of the entity.</value>
41    public override string EntityName {
42      get { return "bundle"; }
43    }
44
45    /// <summary>
46    /// Gets the area that all entities in the bundle encompass.
47    /// </summary>
48    /// <value>The rectangle.</value>
49    public override Rectangle Rectangle {
50      get {
51        if (mEntities.Count == 1) {
52          return mEntities[0].Rectangle;
53        } else if (mEntities.Count > 1) {
54          Rectangle union = mEntities[0].Rectangle;
55          for (int i = 1; i < mEntities.Count; i++) {
56            IDiagramEntity entity = mEntities[i];
57            if (entity.Rectangle != Rectangle.Empty) {
58              union = Rectangle.Union(union, entity.Rectangle);
59            }
60          }
61          //maybe this should be inflated a little here?
62          return union;
63        } else {
64          return Rectangle.Empty;
65        }
66      }
67      //set { throw new InconsistencyException("The rectangle of a bundle is the union of its constituents and cannot be set."); }
68    }
69
70    #endregion
71
72    #region Constructor
73
74    /// <summary>
75    /// Initializes a new instance of the <see cref="T:Bundle"/> class.
76    /// </summary>
77    public Bundle(IModel model)
78      : base(model) {
79      mEntities = new CollectionBase<IDiagramEntity>();
80    }
81
82    /// <summary>
83    /// Initializes a new instance of the <see cref="T:Bundle"/> class.
84    /// </summary>
85    /// <param name="info">The info.</param>
86    /// <param name="context">The context.</param>
87    protected Bundle(
88        SerializationInfo info,
89        StreamingContext context)
90      : base(info, context) {
91      throw new NotImplementedException();
92    }
93    /// <summary>
94    /// Initializes a new instance of the <see cref="T:Bundle"/> class.
95    /// </summary>
96    public Bundle()
97      : base() {
98      mEntities = new CollectionBase<IDiagramEntity>();
99    }
100
101    /// <summary>
102    /// Creates a new bundle using a given collection of diagram entities.
103    /// </summary>
104    /// <param name="collection"></param>
105    public Bundle(CollectionBase<IDiagramEntity> collection)
106      : base() {
107
108      mEntities = new CollectionBase<IDiagramEntity>();
109      //we could assign it directly but let's make sure the collection does not
110      //contain unwanted elements
111      foreach (IDiagramEntity entity in collection) {
112        if ((entity is IShape) || (entity is IConnection) || (entity is IGroup))
113          mEntities.Add(entity);
114      }
115
116      //the following line would give problem. The event handler attached to the Selection would be triggered when
117      //the mEntities collection is changed!
118      //mEntities = collection;
119
120    }
121
122    #endregion
123
124    #region Methods
125    /// <summary>
126    /// The custom menu to be added to the base menu of this entity
127    /// </summary>
128    /// <returns>ToolStripItem[]</returns>
129    public override ToolStripItem[] Menu() {
130      return null;
131    }
132
133    // ------------------------------------------------------------------
134    /// <summary>
135    /// Sets the 'IsSelected' property to false for all entities in the
136    /// bundle.
137    /// </summary>
138    // ------------------------------------------------------------------
139    public void DeSelectAll() {
140      foreach (IDiagramEntity entity in mEntities) {
141        entity.IsSelected = false;
142      }
143    }
144
145    // ------------------------------------------------------------------
146    /// <summary>
147    /// Sets the 'Hovered' property for all entities in the bundle to
148    /// the value specified.
149    /// </summary>
150    // ------------------------------------------------------------------
151    public void SetHovered(bool isHovered) {
152      foreach (IDiagramEntity entity in mEntities) {
153        entity.Hovered = isHovered;
154      }
155    }
156
157    // ------------------------------------------------------------------
158    /// <summary>
159    /// Populates a
160    /// <see cref="T:System.Runtime.Serialization.SerializationInfo"></see>
161    /// with the data needed to serialize the target object.
162    /// </summary>
163    /// <param name="info">The
164    /// <see cref="T:System.Runtime.Serialization.SerializationInfo"></see>
165    /// to populate with data.</param>
166    /// <param name="context">The destination (see
167    /// <see cref="T:System.Runtime.Serialization.StreamingContext"></see>)
168    /// for this serialization.</param>
169    /// <exception cref="T:System.Security.SecurityException">The caller
170    /// does not have the required permission. </exception>
171    // ------------------------------------------------------------------
172    public override void GetObjectData(
173        SerializationInfo info,
174        StreamingContext context) {
175      throw new NotImplementedException();
176    }
177
178    // ------------------------------------------------------------------
179    /// <summary>
180    /// Paints the bundle.
181    /// </summary>
182    /// <param name="g">Graphics</param>
183    // ------------------------------------------------------------------
184    public override void Paint(Graphics g) {
185      foreach (IDiagramEntity entity in mEntities) {
186        entity.Paint(g);
187      }
188    }
189
190    /// <summary>
191    /// Tests whether the bundle is hit by the mouse
192    /// </summary>
193    /// <param name="p"></param>
194    /// <returns></returns>
195    public override bool Hit(Point p) {
196      foreach (IDiagramEntity entity in mEntities) {
197        if (entity.Hit(p)) return true;
198      }
199      return false;
200    }
201
202    /// <summary>
203    /// Invalidates the entity
204    /// </summary>
205    public override void Invalidate() {
206      foreach (IDiagramEntity entity in mEntities) {
207        entity.Invalidate();
208      }
209    }
210
211    /// <summary>
212    /// Moves the entity on the canvas
213    /// </summary>
214    /// <param name="p">a shift vector</param>
215    public override void MoveBy(Point p) {
216      foreach (IDiagramEntity entity in mEntities) {
217        entity.MoveBy(p);
218      }
219    }
220
221    #endregion
222  }
223}
Note: See TracBrowser for help on using the repository browser.