1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.Windows.Forms;
|
---|
4 | namespace Netron.Diagramming.Core
|
---|
5 | {
|
---|
6 | // ----------------------------------------------------------------------
|
---|
7 | /// <summary>
|
---|
8 | /// Interface of the "Model" in the Model - View - Controller framework.
|
---|
9 | /// </summary>
|
---|
10 | // ----------------------------------------------------------------------
|
---|
11 | public interface IModel : IVersion
|
---|
12 | {
|
---|
13 |
|
---|
14 | #region Events
|
---|
15 |
|
---|
16 | // ------------------------------------------------------------------
|
---|
17 | /// <summary>
|
---|
18 | /// Occurs when the current page has changed.
|
---|
19 | /// </summary>
|
---|
20 | // ------------------------------------------------------------------
|
---|
21 | event CurrentPageChangedEventHandler OnCurrentPageChanged;
|
---|
22 |
|
---|
23 | // ------------------------------------------------------------------
|
---|
24 | /// <summary>
|
---|
25 | /// Occurs when the <see cref="Ambience"/> is changed.
|
---|
26 | /// </summary>
|
---|
27 | // ------------------------------------------------------------------
|
---|
28 | event EventHandler<AmbienceEventArgs> OnAmbienceChanged;
|
---|
29 |
|
---|
30 | // ------------------------------------------------------------------
|
---|
31 | /// <summary>
|
---|
32 | /// Occurs the collection of connections is changed
|
---|
33 | /// </summary>
|
---|
34 | // ------------------------------------------------------------------
|
---|
35 | event EventHandler<ConnectionCollectionEventArgs> OnConnectionCollectionChanged;
|
---|
36 |
|
---|
37 | // ------------------------------------------------------------------
|
---|
38 | /// <summary>
|
---|
39 | /// Occurs when the diagram information has changed
|
---|
40 | /// </summary>
|
---|
41 | // ------------------------------------------------------------------
|
---|
42 | event EventHandler<DiagramInformationEventArgs> OnDiagramInformationChanged;
|
---|
43 |
|
---|
44 | // ------------------------------------------------------------------
|
---|
45 | /// <summary>
|
---|
46 | /// Occurs when an underlying element (usually an entity) asks to
|
---|
47 | /// repaint the whole canvas.
|
---|
48 | /// </summary>
|
---|
49 | // ------------------------------------------------------------------
|
---|
50 | event EventHandler OnInvalidate;
|
---|
51 |
|
---|
52 | // ------------------------------------------------------------------
|
---|
53 | /// <summary>
|
---|
54 | /// Occurs when an underlying element (usually an entity) asks to
|
---|
55 | /// repaint part of the canvas.
|
---|
56 | /// </summary>
|
---|
57 | // ------------------------------------------------------------------
|
---|
58 | event EventHandler<RectangleEventArgs> OnInvalidateRectangle;
|
---|
59 |
|
---|
60 | // ------------------------------------------------------------------
|
---|
61 | /// <summary>
|
---|
62 | /// Occurs when an entity is added to the model.
|
---|
63 | /// </summary>
|
---|
64 | // ------------------------------------------------------------------
|
---|
65 | event EventHandler<EntityEventArgs> OnEntityAdded;
|
---|
66 |
|
---|
67 | // ------------------------------------------------------------------
|
---|
68 | /// <summary>
|
---|
69 | /// Occurs when an entity is removed from the model.
|
---|
70 | /// </summary>
|
---|
71 | // ------------------------------------------------------------------
|
---|
72 | event EventHandler<EntityEventArgs> OnEntityRemoved;
|
---|
73 |
|
---|
74 | // ------------------------------------------------------------------
|
---|
75 | /// <summary>
|
---|
76 | /// Occurs when the cursor changes and the surface has to effectively
|
---|
77 | /// show a different cursor.
|
---|
78 | /// </summary>
|
---|
79 | // ------------------------------------------------------------------
|
---|
80 | event EventHandler<CursorEventArgs> OnCursorChange;
|
---|
81 |
|
---|
82 | #endregion
|
---|
83 |
|
---|
84 | #region Properties
|
---|
85 |
|
---|
86 | // ------------------------------------------------------------------
|
---|
87 | /// <summary>
|
---|
88 | /// Gets or sets if all shape's connectors should be shown.
|
---|
89 | /// </summary>
|
---|
90 | // ------------------------------------------------------------------
|
---|
91 | bool ShowConnectors
|
---|
92 | {
|
---|
93 | get;
|
---|
94 | set;
|
---|
95 | }
|
---|
96 |
|
---|
97 | Selection Selection { get; set; }
|
---|
98 |
|
---|
99 | float MeasurementScale
|
---|
100 | {
|
---|
101 | get;
|
---|
102 | set;
|
---|
103 | }
|
---|
104 |
|
---|
105 | GraphicsUnit MeasurementUnits
|
---|
106 | {
|
---|
107 | get;
|
---|
108 | set;
|
---|
109 | }
|
---|
110 |
|
---|
111 | // ------------------------------------------------------------------
|
---|
112 | /// <summary>
|
---|
113 | /// Gets or sets the layout root.
|
---|
114 | /// </summary>
|
---|
115 | /// <value>The layout root.</value>
|
---|
116 | // ------------------------------------------------------------------
|
---|
117 | IShape LayoutRoot
|
---|
118 | {
|
---|
119 | get;
|
---|
120 | set;
|
---|
121 | }
|
---|
122 |
|
---|
123 | // ------------------------------------------------------------------
|
---|
124 | /// <summary>
|
---|
125 | /// Gets the connections.
|
---|
126 | /// </summary>
|
---|
127 | /// <value>The connections.</value>
|
---|
128 | // ------------------------------------------------------------------
|
---|
129 | CollectionBase<IConnection> Connections
|
---|
130 | {
|
---|
131 | get;
|
---|
132 | }
|
---|
133 |
|
---|
134 | // ------------------------------------------------------------------
|
---|
135 | /// <summary>
|
---|
136 | /// Gets the shapes.
|
---|
137 | /// </summary>
|
---|
138 | /// <value>The shapes.</value>
|
---|
139 | // ------------------------------------------------------------------
|
---|
140 | CollectionBase<IShape> Shapes
|
---|
141 | {
|
---|
142 | get;
|
---|
143 | }
|
---|
144 |
|
---|
145 | // ------------------------------------------------------------------
|
---|
146 | /// <summary>
|
---|
147 | /// Gets the paintables.
|
---|
148 | /// </summary>
|
---|
149 | /// <value>The paintables.</value>
|
---|
150 | // ------------------------------------------------------------------
|
---|
151 | CollectionBase<IDiagramEntity> Paintables
|
---|
152 | {
|
---|
153 | get;
|
---|
154 | }
|
---|
155 |
|
---|
156 | // ------------------------------------------------------------------
|
---|
157 | /// <summary>
|
---|
158 | /// Gets the current page.
|
---|
159 | /// </summary>
|
---|
160 | /// <value>The current page.</value>
|
---|
161 | // ------------------------------------------------------------------
|
---|
162 | IPage CurrentPage
|
---|
163 | {
|
---|
164 | get;
|
---|
165 | }
|
---|
166 |
|
---|
167 | // ------------------------------------------------------------------
|
---|
168 | /// <summary>
|
---|
169 | /// Gets the pages of the diagram control. Use method 'AddPage' to
|
---|
170 | /// add a page so the page gets attached to this Model.
|
---|
171 | /// </summary>
|
---|
172 | /// <value>The pages.</value>
|
---|
173 | // ------------------------------------------------------------------
|
---|
174 | CollectionBase<IPage> Pages
|
---|
175 | {
|
---|
176 | get;
|
---|
177 | }
|
---|
178 |
|
---|
179 | // ------------------------------------------------------------------
|
---|
180 | /// <summary>
|
---|
181 | /// Gets the default page.
|
---|
182 | /// </summary>
|
---|
183 | /// <value>The default page.</value>
|
---|
184 | // ------------------------------------------------------------------
|
---|
185 | IPage DefaultPage
|
---|
186 | {
|
---|
187 | get;
|
---|
188 | }
|
---|
189 |
|
---|
190 | #endregion
|
---|
191 |
|
---|
192 | #region Methods
|
---|
193 |
|
---|
194 | #region Diagram actions
|
---|
195 |
|
---|
196 | // ------------------------------------------------------------------
|
---|
197 | /// <summary>
|
---|
198 | /// Returns the number of shapes in the current page that are of
|
---|
199 | /// the type specified.
|
---|
200 | /// </summary>
|
---|
201 | /// <param name="type">Type</param>
|
---|
202 | /// <returns>int</returns>
|
---|
203 | // ------------------------------------------------------------------
|
---|
204 | int NumberOfShapes(Type type);
|
---|
205 |
|
---|
206 | // ------------------------------------------------------------------
|
---|
207 | /// <summary>
|
---|
208 | /// Adds an entity to the diagram
|
---|
209 | /// </summary>
|
---|
210 | /// <param name="entity">IDiagramEntity: The entity to add.</param>
|
---|
211 | /// <returns>IDiagramEntity: The added entity.</returns>
|
---|
212 | // ------------------------------------------------------------------
|
---|
213 | IDiagramEntity AddEntity(IDiagramEntity entity);
|
---|
214 |
|
---|
215 | // ------------------------------------------------------------------
|
---|
216 | /// <summary>
|
---|
217 | /// Adds a connection to the diagram.
|
---|
218 | /// </summary>
|
---|
219 | /// <param name="connection">The connection.</param>
|
---|
220 | // ------------------------------------------------------------------
|
---|
221 | IConnection AddConnection(IConnection connection);
|
---|
222 |
|
---|
223 | // ------------------------------------------------------------------
|
---|
224 | /// <summary>
|
---|
225 | /// Adds a page. This should be used when adding pages rather than
|
---|
226 | /// though the Pages property so the page gets attached to the Model.
|
---|
227 | /// </summary>
|
---|
228 | /// <param name="page">IPage: The page to add.</param>
|
---|
229 | /// <returns>IPage</returns>
|
---|
230 | // ------------------------------------------------------------------
|
---|
231 | IPage AddPage(IPage page);
|
---|
232 |
|
---|
233 | // ------------------------------------------------------------------
|
---|
234 | /// <summary>
|
---|
235 | /// Adds a page. This should be used when adding pages rather than
|
---|
236 | /// though the Pages property so the page gets attached to the Model.
|
---|
237 | /// The page name is set to "Page" plus the new number of pages.
|
---|
238 | /// For example, if there are currently two pages, then "Page3" is
|
---|
239 | /// set as the new page name.
|
---|
240 | /// </summary>
|
---|
241 | /// <returns>IPage</returns>
|
---|
242 | // ------------------------------------------------------------------
|
---|
243 | IPage AddPage();
|
---|
244 |
|
---|
245 | // ------------------------------------------------------------------
|
---|
246 | /// <summary>
|
---|
247 | /// Deletes the page specified if it is not the default page.
|
---|
248 | /// </summary>
|
---|
249 | /// <param name="page">IPage: The page to remove.</param>
|
---|
250 | /// <param name="allowWarnings">bool: Specifies if the user should
|
---|
251 | /// be given the option to cancel the action if the current page
|
---|
252 | /// has entities. Also, when set to true, if the current page is
|
---|
253 | /// the default page, then a message box is shown informing the
|
---|
254 | /// user that the default page cannot be deleted.</param>
|
---|
255 | /// <returns>bool: If the delete was successful. True is returned
|
---|
256 | /// if the current page was removed.</returns>
|
---|
257 | // ------------------------------------------------------------------
|
---|
258 | bool RemovePage(IPage page, bool allowWarnings);
|
---|
259 |
|
---|
260 | // ------------------------------------------------------------------
|
---|
261 | /// <summary>
|
---|
262 | /// Returns a new page name that's unique from all the others.
|
---|
263 | /// </summary>
|
---|
264 | /// <returns>string: Returns "Page" plus the number of pages IF A
|
---|
265 | /// NEW PAGE WERE ADDED. For example, if there are currently two
|
---|
266 | /// pages, then "Page3" is returned.</returns>
|
---|
267 | // ------------------------------------------------------------------
|
---|
268 | string GetDefaultNewPageName();
|
---|
269 |
|
---|
270 | // ------------------------------------------------------------------
|
---|
271 | /// <summary>
|
---|
272 | /// Adds a shape to the diagram.
|
---|
273 | /// </summary>
|
---|
274 | /// <param name="shape">The shape.</param>
|
---|
275 | // ------------------------------------------------------------------
|
---|
276 | IShape AddShape(IShape shape);
|
---|
277 |
|
---|
278 | // ------------------------------------------------------------------
|
---|
279 | /// <summary>
|
---|
280 | /// Gets the shape at the specified location. If no shape could be
|
---|
281 | /// found then 'null' is returned.
|
---|
282 | /// </summary>
|
---|
283 | /// <param name="surfacePoint">Point: The location.</param>
|
---|
284 | /// <returns>IShape</returns>
|
---|
285 | // ------------------------------------------------------------------
|
---|
286 | IShape GetShapeAt(Point surfacePoint);
|
---|
287 |
|
---|
288 | // ------------------------------------------------------------------
|
---|
289 | /// <summary>
|
---|
290 | /// Clears the diagram.
|
---|
291 | /// </summary>
|
---|
292 | // ------------------------------------------------------------------
|
---|
293 | void Clear();
|
---|
294 |
|
---|
295 | // ------------------------------------------------------------------
|
---|
296 | /// <summary>
|
---|
297 | /// Removes the shape from the diagram.
|
---|
298 | /// </summary>
|
---|
299 | /// <param name="shape">The shape.</param>
|
---|
300 | // ------------------------------------------------------------------
|
---|
301 | void RemoveShape(IShape shape);
|
---|
302 |
|
---|
303 | // ------------------------------------------------------------------
|
---|
304 | /// <summary>
|
---|
305 | /// Removes the specified entity.
|
---|
306 | /// </summary>
|
---|
307 | /// <param name="entity">The entity.</param>
|
---|
308 | // ------------------------------------------------------------------
|
---|
309 | void Remove(IDiagramEntity entity);
|
---|
310 |
|
---|
311 | // ------------------------------------------------------------------
|
---|
312 | /// <summary>
|
---|
313 | /// Removes all entities that are currently selected.
|
---|
314 | /// </summary>
|
---|
315 | /// <param name="entity">The entity.</param>
|
---|
316 | // ------------------------------------------------------------------
|
---|
317 | void RemoveSelectedItems();
|
---|
318 |
|
---|
319 | // ------------------------------------------------------------------
|
---|
320 | /// <summary>
|
---|
321 | /// Sends the given entity to the front of the z-order.
|
---|
322 | /// </summary>
|
---|
323 | /// <param name="entity">The entity.</param>
|
---|
324 | // ------------------------------------------------------------------
|
---|
325 | void SendToFront(IDiagramEntity entity);
|
---|
326 |
|
---|
327 | // ------------------------------------------------------------------
|
---|
328 | /// <summary>
|
---|
329 | /// Sends the given entity backwards in the z-order.
|
---|
330 | /// </summary>
|
---|
331 | /// <param name="entity">The entity.</param>
|
---|
332 | /// <param name="zShift">The z shift.</param>
|
---|
333 | // ------------------------------------------------------------------
|
---|
334 | void SendBackwards(IDiagramEntity entity, int zShift);
|
---|
335 |
|
---|
336 | // ------------------------------------------------------------------
|
---|
337 | /// <summary>
|
---|
338 | /// Sends the given entity to the back of the z-order.
|
---|
339 | /// </summary>
|
---|
340 | /// <param name="entity">The entity.</param>
|
---|
341 | // ------------------------------------------------------------------
|
---|
342 | void SendToBack(IDiagramEntity entity);
|
---|
343 |
|
---|
344 | // ------------------------------------------------------------------
|
---|
345 | /// <summary>
|
---|
346 | /// Sends the given entity forwards in the z-order.
|
---|
347 | /// </summary>
|
---|
348 | /// <param name="entity">The entity.</param>
|
---|
349 | // ------------------------------------------------------------------
|
---|
350 | void SendForwards(IDiagramEntity entity);
|
---|
351 |
|
---|
352 | // ------------------------------------------------------------------
|
---|
353 | /// <summary>
|
---|
354 | /// Sends the given entity forwards in the z-order.
|
---|
355 | /// </summary>
|
---|
356 | /// <param name="entity">The entity.</param>
|
---|
357 | /// <param name="zShift">The z shift.</param>
|
---|
358 | // ------------------------------------------------------------------
|
---|
359 | void SendForwards(IDiagramEntity entity, int zShift);
|
---|
360 |
|
---|
361 | // ------------------------------------------------------------------
|
---|
362 | /// <summary>
|
---|
363 | /// Unwraps the specified collection.
|
---|
364 | /// </summary>
|
---|
365 | /// <param name="collection">The collection.</param>
|
---|
366 | // ------------------------------------------------------------------
|
---|
367 | void Unwrap(CollectionBase<IDiagramEntity> collection);
|
---|
368 |
|
---|
369 | #endregion
|
---|
370 |
|
---|
371 | // ------------------------------------------------------------------
|
---|
372 | /// <summary>
|
---|
373 | /// Sets the current page.
|
---|
374 | /// </summary>
|
---|
375 | /// <param name="page">The page.</param>
|
---|
376 | // ------------------------------------------------------------------
|
---|
377 | void SetCurrentPage(IPage page);
|
---|
378 |
|
---|
379 | // ------------------------------------------------------------------
|
---|
380 | /// <summary>
|
---|
381 | /// Sets the current page.
|
---|
382 | /// </summary>
|
---|
383 | /// <param name="pageIndex">Index of the page.</param>
|
---|
384 | // ------------------------------------------------------------------
|
---|
385 | void SetCurrentPage(int pageIndex);
|
---|
386 |
|
---|
387 | // ------------------------------------------------------------------
|
---|
388 | /// <summary>
|
---|
389 | /// Raises the on invalidate.
|
---|
390 | /// </summary>
|
---|
391 | // ------------------------------------------------------------------
|
---|
392 | void RaiseOnInvalidate();
|
---|
393 |
|
---|
394 | // ------------------------------------------------------------------
|
---|
395 | /// <summary>
|
---|
396 | /// Raises the OnInvalidateRectangle event.
|
---|
397 | /// </summary>
|
---|
398 | /// <param name="rectangle">The rectangle.</param>
|
---|
399 | // ------------------------------------------------------------------
|
---|
400 | void RaiseOnInvalidateRectangle(Rectangle rectangle);
|
---|
401 |
|
---|
402 | // ------------------------------------------------------------------
|
---|
403 | /// <summary>
|
---|
404 | /// Raises the OnCursorChange event.
|
---|
405 | /// </summary>
|
---|
406 | /// <param name="cursor">The cursor.</param>
|
---|
407 | // ------------------------------------------------------------------
|
---|
408 | void RaiseOnCursorChange(Cursor cursor);
|
---|
409 |
|
---|
410 | #endregion
|
---|
411 | }
|
---|
412 | }
|
---|