1 | //------------------------------------------------------------------------------
|
---|
2 | // <auto-generated>
|
---|
3 | // This code was generated by a tool.
|
---|
4 | //
|
---|
5 | // Changes to this file may cause incorrect behavior and will be lost if
|
---|
6 | // the code is regenerated.
|
---|
7 | // </auto-generated>
|
---|
8 | //------------------------------------------------------------------------------
|
---|
9 |
|
---|
10 | using DslModeling = global::Microsoft.VisualStudio.Modeling;
|
---|
11 | using DslDiagrams = global::Microsoft.VisualStudio.Modeling.Diagrams;
|
---|
12 |
|
---|
13 | namespace HeuristicLab.SimulationCore
|
---|
14 | {
|
---|
15 | /// <summary>
|
---|
16 | /// ConnectionBuilder class to provide logic for constructing connections between elements.
|
---|
17 | /// </summary>
|
---|
18 | public static partial class ActivityReferencesTriggersBuilder
|
---|
19 | {
|
---|
20 | #region Accept Connection Methods
|
---|
21 | /// <summary>
|
---|
22 | /// Test whether a given model element is acceptable to this ConnectionBuilder as the source of a connection.
|
---|
23 | /// </summary>
|
---|
24 | /// <param name="candidate">The model element to test.</param>
|
---|
25 | /// <returns>Whether the element can be used as the source of a connection.</returns>
|
---|
26 | [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
|
---|
27 | public static bool CanAcceptSource(DslModeling::ModelElement candidate)
|
---|
28 | {
|
---|
29 | if (candidate == null) return false;
|
---|
30 | else if (candidate is global::HeuristicLab.SimulationCore.Activity)
|
---|
31 | {
|
---|
32 | return true;
|
---|
33 | }
|
---|
34 | else
|
---|
35 | return false;
|
---|
36 | }
|
---|
37 |
|
---|
38 | /// <summary>
|
---|
39 | /// Test whether a given model element is acceptable to this ConnectionBuilder as the target of a connection.
|
---|
40 | /// </summary>
|
---|
41 | /// <param name="candidate">The model element to test.</param>
|
---|
42 | /// <returns>Whether the element can be used as the target of a connection.</returns>
|
---|
43 | [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
|
---|
44 | public static bool CanAcceptTarget(DslModeling::ModelElement candidate)
|
---|
45 | {
|
---|
46 | if (candidate == null) return false;
|
---|
47 | else if (candidate is global::HeuristicLab.SimulationCore.Action)
|
---|
48 | {
|
---|
49 | return true;
|
---|
50 | }
|
---|
51 | else
|
---|
52 | return false;
|
---|
53 | }
|
---|
54 |
|
---|
55 | /// <summary>
|
---|
56 | /// Test whether a given pair of model elements are acceptable to this ConnectionBuilder as the source and target of a connection
|
---|
57 | /// </summary>
|
---|
58 | /// <param name="candidateSource">The model element to test as a source</param>
|
---|
59 | /// <param name="candidateTarget">The model element to test as a target</param>
|
---|
60 | /// <returns>Whether the elements can be used as the source and target of a connection</returns>
|
---|
61 | [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
|
---|
62 | [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Generated code.")]
|
---|
63 | public static bool CanAcceptSourceAndTarget(DslModeling::ModelElement candidateSource, DslModeling::ModelElement candidateTarget)
|
---|
64 | {
|
---|
65 | // Accepts null, null; source, null; source, target but NOT null, target
|
---|
66 | if (candidateSource == null)
|
---|
67 | {
|
---|
68 | if (candidateTarget != null)
|
---|
69 | {
|
---|
70 | throw new global::System.ArgumentNullException("candidateSource");
|
---|
71 | }
|
---|
72 | else // Both null
|
---|
73 | {
|
---|
74 | return false;
|
---|
75 | }
|
---|
76 | }
|
---|
77 | bool acceptSource = CanAcceptSource(candidateSource);
|
---|
78 | // If the source wasn't accepted then there's no point checking targets.
|
---|
79 | // If there is no target then the source controls the accept.
|
---|
80 | if (!acceptSource || candidateTarget == null)
|
---|
81 | {
|
---|
82 | return acceptSource;
|
---|
83 | }
|
---|
84 | else // Check combinations
|
---|
85 | {
|
---|
86 | if (candidateSource is global::HeuristicLab.SimulationCore.Activity)
|
---|
87 | {
|
---|
88 | if (candidateTarget is global::HeuristicLab.SimulationCore.Action)
|
---|
89 | {
|
---|
90 | global::HeuristicLab.SimulationCore.Activity sourceActivity = (global::HeuristicLab.SimulationCore.Activity)candidateSource;
|
---|
91 | global::HeuristicLab.SimulationCore.Action targetAction = (global::HeuristicLab.SimulationCore.Action)candidateTarget;
|
---|
92 | if(targetAction == null || sourceActivity == null || global::HeuristicLab.SimulationCore.ActivityReferencesTriggers.GetLinks(sourceActivity, targetAction).Count > 0) return false;
|
---|
93 | return true;
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | }
|
---|
98 | return false;
|
---|
99 | }
|
---|
100 | #endregion
|
---|
101 |
|
---|
102 | #region Connection Methods
|
---|
103 | /// <summary>
|
---|
104 | /// Make a connection between the given pair of source and target elements
|
---|
105 | /// </summary>
|
---|
106 | /// <param name="source">The model element to use as the source of the connection</param>
|
---|
107 | /// <param name="target">The model element to use as the target of the connection</param>
|
---|
108 | /// <returns>A link representing the created connection</returns>
|
---|
109 | [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
|
---|
110 | [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Generated code.")]
|
---|
111 | public static DslModeling::ElementLink Connect(DslModeling::ModelElement source, DslModeling::ModelElement target)
|
---|
112 | {
|
---|
113 | if (source == null)
|
---|
114 | {
|
---|
115 | throw new global::System.ArgumentNullException("source");
|
---|
116 | }
|
---|
117 | if (target == null)
|
---|
118 | {
|
---|
119 | throw new global::System.ArgumentNullException("target");
|
---|
120 | }
|
---|
121 |
|
---|
122 | if (CanAcceptSourceAndTarget(source, target))
|
---|
123 | {
|
---|
124 | if (source is global::HeuristicLab.SimulationCore.Activity)
|
---|
125 | {
|
---|
126 | if (target is global::HeuristicLab.SimulationCore.Action)
|
---|
127 | {
|
---|
128 | global::HeuristicLab.SimulationCore.Activity sourceAccepted = (global::HeuristicLab.SimulationCore.Activity)source;
|
---|
129 | global::HeuristicLab.SimulationCore.Action targetAccepted = (global::HeuristicLab.SimulationCore.Action)target;
|
---|
130 | DslModeling::ElementLink result = new global::HeuristicLab.SimulationCore.ActivityReferencesTriggers(sourceAccepted, targetAccepted);
|
---|
131 | if (DslModeling::DomainClassInfo.HasNameProperty(result))
|
---|
132 | {
|
---|
133 | DslModeling::DomainClassInfo.SetUniqueName(result);
|
---|
134 | }
|
---|
135 | return result;
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|
139 | }
|
---|
140 | global::System.Diagnostics.Debug.Fail("Having agreed that the connection can be accepted we should never fail to make one.");
|
---|
141 | throw new global::System.InvalidOperationException();
|
---|
142 | }
|
---|
143 | #endregion
|
---|
144 | }
|
---|
145 | /// <summary>
|
---|
146 | /// ConnectionBuilder class to provide logic for constructing connections between elements.
|
---|
147 | /// </summary>
|
---|
148 | public static partial class ActionReferencesListenersBuilder
|
---|
149 | {
|
---|
150 | #region Accept Connection Methods
|
---|
151 | /// <summary>
|
---|
152 | /// Test whether a given model element is acceptable to this ConnectionBuilder as the source of a connection.
|
---|
153 | /// </summary>
|
---|
154 | /// <param name="candidate">The model element to test.</param>
|
---|
155 | /// <returns>Whether the element can be used as the source of a connection.</returns>
|
---|
156 | [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
|
---|
157 | public static bool CanAcceptSource(DslModeling::ModelElement candidate)
|
---|
158 | {
|
---|
159 | if (candidate == null) return false;
|
---|
160 | else if (candidate is global::HeuristicLab.SimulationCore.Action)
|
---|
161 | {
|
---|
162 | return true;
|
---|
163 | }
|
---|
164 | else
|
---|
165 | return false;
|
---|
166 | }
|
---|
167 |
|
---|
168 | /// <summary>
|
---|
169 | /// Test whether a given model element is acceptable to this ConnectionBuilder as the target of a connection.
|
---|
170 | /// </summary>
|
---|
171 | /// <param name="candidate">The model element to test.</param>
|
---|
172 | /// <returns>Whether the element can be used as the target of a connection.</returns>
|
---|
173 | [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
|
---|
174 | public static bool CanAcceptTarget(DslModeling::ModelElement candidate)
|
---|
175 | {
|
---|
176 | if (candidate == null) return false;
|
---|
177 | else if (candidate is global::HeuristicLab.SimulationCore.Activity)
|
---|
178 | {
|
---|
179 | return true;
|
---|
180 | }
|
---|
181 | else
|
---|
182 | return false;
|
---|
183 | }
|
---|
184 |
|
---|
185 | /// <summary>
|
---|
186 | /// Test whether a given pair of model elements are acceptable to this ConnectionBuilder as the source and target of a connection
|
---|
187 | /// </summary>
|
---|
188 | /// <param name="candidateSource">The model element to test as a source</param>
|
---|
189 | /// <param name="candidateTarget">The model element to test as a target</param>
|
---|
190 | /// <returns>Whether the elements can be used as the source and target of a connection</returns>
|
---|
191 | [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
|
---|
192 | [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Generated code.")]
|
---|
193 | public static bool CanAcceptSourceAndTarget(DslModeling::ModelElement candidateSource, DslModeling::ModelElement candidateTarget)
|
---|
194 | {
|
---|
195 | // Accepts null, null; source, null; source, target but NOT null, target
|
---|
196 | if (candidateSource == null)
|
---|
197 | {
|
---|
198 | if (candidateTarget != null)
|
---|
199 | {
|
---|
200 | throw new global::System.ArgumentNullException("candidateSource");
|
---|
201 | }
|
---|
202 | else // Both null
|
---|
203 | {
|
---|
204 | return false;
|
---|
205 | }
|
---|
206 | }
|
---|
207 | bool acceptSource = CanAcceptSource(candidateSource);
|
---|
208 | // If the source wasn't accepted then there's no point checking targets.
|
---|
209 | // If there is no target then the source controls the accept.
|
---|
210 | if (!acceptSource || candidateTarget == null)
|
---|
211 | {
|
---|
212 | return acceptSource;
|
---|
213 | }
|
---|
214 | else // Check combinations
|
---|
215 | {
|
---|
216 | if (candidateSource is global::HeuristicLab.SimulationCore.Action)
|
---|
217 | {
|
---|
218 | if (candidateTarget is global::HeuristicLab.SimulationCore.Activity)
|
---|
219 | {
|
---|
220 | global::HeuristicLab.SimulationCore.Action sourceAction = (global::HeuristicLab.SimulationCore.Action)candidateSource;
|
---|
221 | global::HeuristicLab.SimulationCore.Activity targetActivity = (global::HeuristicLab.SimulationCore.Activity)candidateTarget;
|
---|
222 | if(targetActivity == null || sourceAction == null || global::HeuristicLab.SimulationCore.ActionReferencesListeners.GetLinks(sourceAction, targetActivity).Count > 0) return false;
|
---|
223 | return true;
|
---|
224 | }
|
---|
225 | }
|
---|
226 |
|
---|
227 | }
|
---|
228 | return false;
|
---|
229 | }
|
---|
230 | #endregion
|
---|
231 |
|
---|
232 | #region Connection Methods
|
---|
233 | /// <summary>
|
---|
234 | /// Make a connection between the given pair of source and target elements
|
---|
235 | /// </summary>
|
---|
236 | /// <param name="source">The model element to use as the source of the connection</param>
|
---|
237 | /// <param name="target">The model element to use as the target of the connection</param>
|
---|
238 | /// <returns>A link representing the created connection</returns>
|
---|
239 | [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
|
---|
240 | [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Generated code.")]
|
---|
241 | public static DslModeling::ElementLink Connect(DslModeling::ModelElement source, DslModeling::ModelElement target)
|
---|
242 | {
|
---|
243 | if (source == null)
|
---|
244 | {
|
---|
245 | throw new global::System.ArgumentNullException("source");
|
---|
246 | }
|
---|
247 | if (target == null)
|
---|
248 | {
|
---|
249 | throw new global::System.ArgumentNullException("target");
|
---|
250 | }
|
---|
251 |
|
---|
252 | if (CanAcceptSourceAndTarget(source, target))
|
---|
253 | {
|
---|
254 | if (source is global::HeuristicLab.SimulationCore.Action)
|
---|
255 | {
|
---|
256 | if (target is global::HeuristicLab.SimulationCore.Activity)
|
---|
257 | {
|
---|
258 | global::HeuristicLab.SimulationCore.Action sourceAccepted = (global::HeuristicLab.SimulationCore.Action)source;
|
---|
259 | global::HeuristicLab.SimulationCore.Activity targetAccepted = (global::HeuristicLab.SimulationCore.Activity)target;
|
---|
260 | DslModeling::ElementLink result = new global::HeuristicLab.SimulationCore.ActionReferencesListeners(sourceAccepted, targetAccepted);
|
---|
261 | if (DslModeling::DomainClassInfo.HasNameProperty(result))
|
---|
262 | {
|
---|
263 | DslModeling::DomainClassInfo.SetUniqueName(result);
|
---|
264 | }
|
---|
265 | return result;
|
---|
266 | }
|
---|
267 | }
|
---|
268 |
|
---|
269 | }
|
---|
270 | global::System.Diagnostics.Debug.Fail("Having agreed that the connection can be accepted we should never fail to make one.");
|
---|
271 | throw new global::System.InvalidOperationException();
|
---|
272 | }
|
---|
273 | #endregion
|
---|
274 | }
|
---|
275 |
|
---|
276 | /// <summary>
|
---|
277 | /// Handles interaction between the ConnectionBuilder and the corresponding ConnectionTool.
|
---|
278 | /// </summary>
|
---|
279 | internal partial class TriggerConnectAction : DslDiagrams::ConnectAction
|
---|
280 | {
|
---|
281 | private DslDiagrams::ConnectionType[] connectionTypes;
|
---|
282 |
|
---|
283 | /// <summary>
|
---|
284 | /// Constructs a new TriggerConnectAction for the given Diagram.
|
---|
285 | /// </summary>
|
---|
286 | public TriggerConnectAction(DslDiagrams::Diagram diagram): base(diagram, true)
|
---|
287 | {
|
---|
288 | }
|
---|
289 |
|
---|
290 | /// <summary>
|
---|
291 | /// Gets the cursor corresponding to the given mouse position.
|
---|
292 | /// </summary>
|
---|
293 | /// <remarks>
|
---|
294 | /// Changes the cursor to Cursors.No before the first mouse click if the source shape is not valid.
|
---|
295 | /// </remarks>
|
---|
296 | public override global::System.Windows.Forms.Cursor GetCursor(global::System.Windows.Forms.Cursor currentCursor, DslDiagrams::DiagramClientView diagramClientView, DslDiagrams::PointD mousePosition)
|
---|
297 | {
|
---|
298 | if (this.MouseDownHitShape == null && currentCursor != global::System.Windows.Forms.Cursors.No)
|
---|
299 | {
|
---|
300 | DslDiagrams::DiagramHitTestInfo hitTestInfo = new DslDiagrams::DiagramHitTestInfo(diagramClientView);
|
---|
301 | this.Diagram.DoHitTest(mousePosition, hitTestInfo);
|
---|
302 | DslDiagrams::ShapeElement shape = hitTestInfo.HitDiagramItem.Shape;
|
---|
303 |
|
---|
304 | DslDiagrams::ConnectionType connectionType = GetConnectionTypes(shape, null)[0];
|
---|
305 | string warningString = string.Empty;
|
---|
306 | if (!connectionType.CanCreateConnection(shape, null, ref warningString))
|
---|
307 | {
|
---|
308 | return global::System.Windows.Forms.Cursors.No;
|
---|
309 | }
|
---|
310 | }
|
---|
311 | return base.GetCursor(currentCursor, diagramClientView, mousePosition);
|
---|
312 | }
|
---|
313 |
|
---|
314 |
|
---|
315 | /// <summary>
|
---|
316 | /// Returns the TriggerConnectionType associated with this action.
|
---|
317 | /// </summary>
|
---|
318 | protected override DslDiagrams::ConnectionType[] GetConnectionTypes(DslDiagrams::ShapeElement sourceShapeElement, DslDiagrams::ShapeElement targetShapeElement)
|
---|
319 | {
|
---|
320 | if(this.connectionTypes == null)
|
---|
321 | {
|
---|
322 | this.connectionTypes = new DslDiagrams::ConnectionType[] { new TriggerConnectionType() };
|
---|
323 | }
|
---|
324 |
|
---|
325 | return this.connectionTypes;
|
---|
326 | }
|
---|
327 |
|
---|
328 | private partial class TriggerConnectionTypeBase : DslDiagrams::ConnectionType
|
---|
329 | {
|
---|
330 | /// <summary>
|
---|
331 | /// Constructs a new the TriggerConnectionType with the given ConnectionBuilder.
|
---|
332 | /// </summary>
|
---|
333 | protected TriggerConnectionTypeBase() : base() {}
|
---|
334 |
|
---|
335 | private static DslDiagrams::ShapeElement RemovePassThroughShapes(DslDiagrams::ShapeElement shape)
|
---|
336 | {
|
---|
337 | if (shape is DslDiagrams::Compartment)
|
---|
338 | {
|
---|
339 | return shape.ParentShape;
|
---|
340 | }
|
---|
341 | DslDiagrams::SwimlaneShape swimlane = shape as DslDiagrams::SwimlaneShape;
|
---|
342 | if (swimlane != null && swimlane.ForwardDragDropToParent)
|
---|
343 | {
|
---|
344 | return shape.ParentShape;
|
---|
345 | }
|
---|
346 | return shape;
|
---|
347 | }
|
---|
348 |
|
---|
349 | /// <summary>
|
---|
350 | /// Called by the base ConnectAction class to determine if the given shapes can be connected.
|
---|
351 | /// </summary>
|
---|
352 | /// <remarks>
|
---|
353 | /// This implementation delegates calls to the ConnectionBuilder ActivityReferencesTriggersBuilder.
|
---|
354 | /// </remarks>
|
---|
355 | public override bool CanCreateConnection(DslDiagrams::ShapeElement sourceShapeElement, DslDiagrams::ShapeElement targetShapeElement, ref string connectionWarning)
|
---|
356 | {
|
---|
357 | bool canConnect = true;
|
---|
358 |
|
---|
359 | if(sourceShapeElement == null) throw new global::System.ArgumentNullException("sourceShapeElement");
|
---|
360 | sourceShapeElement = RemovePassThroughShapes(sourceShapeElement);
|
---|
361 | DslModeling::ModelElement sourceElement = sourceShapeElement.ModelElement;
|
---|
362 | if(sourceElement == null) sourceElement = sourceShapeElement;
|
---|
363 |
|
---|
364 | DslModeling::ModelElement targetElement = null;
|
---|
365 | if (targetShapeElement != null)
|
---|
366 | {
|
---|
367 | targetShapeElement = RemovePassThroughShapes(targetShapeElement);
|
---|
368 | targetElement = targetShapeElement.ModelElement;
|
---|
369 | if(targetElement == null) targetElement = targetShapeElement;
|
---|
370 |
|
---|
371 | }
|
---|
372 |
|
---|
373 | // base.CanCreateConnection must be called to check whether existing Locks prevent this link from getting created.
|
---|
374 | canConnect = base.CanCreateConnection(sourceShapeElement, targetShapeElement, ref connectionWarning);
|
---|
375 | if (canConnect)
|
---|
376 | {
|
---|
377 | if(targetShapeElement == null)
|
---|
378 | {
|
---|
379 | return ActivityReferencesTriggersBuilder.CanAcceptSource(sourceElement);
|
---|
380 | }
|
---|
381 | else
|
---|
382 | {
|
---|
383 | return ActivityReferencesTriggersBuilder.CanAcceptSourceAndTarget(sourceElement, targetElement);
|
---|
384 | }
|
---|
385 | }
|
---|
386 | else
|
---|
387 | {
|
---|
388 | //return false
|
---|
389 | return canConnect;
|
---|
390 | }
|
---|
391 | }
|
---|
392 |
|
---|
393 | /// <summary>
|
---|
394 | /// Called by the base ConnectAction class to ask whether the given source and target are valid.
|
---|
395 | /// </summary>
|
---|
396 | /// <remarks>
|
---|
397 | /// Always return true here, to give CanCreateConnection a chance to decide.
|
---|
398 | /// </remarks>
|
---|
399 | public override bool IsValidSourceAndTarget(DslDiagrams::ShapeElement sourceShapeElement, DslDiagrams::ShapeElement targetShapeElement)
|
---|
400 | {
|
---|
401 | return true;
|
---|
402 | }
|
---|
403 |
|
---|
404 | /// <summary>
|
---|
405 | /// Called by the base ConnectAction class to create the underlying relationship.
|
---|
406 | /// </summary>
|
---|
407 | /// <remarks>
|
---|
408 | /// This implementation delegates calls to the ConnectionBuilder ActivityReferencesTriggersBuilder.
|
---|
409 | /// </remarks>
|
---|
410 | public override void CreateConnection(DslDiagrams::ShapeElement sourceShapeElement, DslDiagrams::ShapeElement targetShapeElement, DslDiagrams::PaintFeedbackArgs paintFeedbackArgs)
|
---|
411 | {
|
---|
412 | if(sourceShapeElement == null) throw new global::System.ArgumentNullException("sourceShapeElement");
|
---|
413 | if(targetShapeElement == null) throw new global::System.ArgumentNullException("targetShapeElement");
|
---|
414 |
|
---|
415 | sourceShapeElement = RemovePassThroughShapes(sourceShapeElement);
|
---|
416 | targetShapeElement = RemovePassThroughShapes(targetShapeElement);
|
---|
417 |
|
---|
418 | DslModeling::ModelElement sourceElement = sourceShapeElement.ModelElement;
|
---|
419 | if(sourceElement == null) sourceElement = sourceShapeElement;
|
---|
420 | DslModeling::ModelElement targetElement = targetShapeElement.ModelElement;
|
---|
421 | if(targetElement == null) targetElement = targetShapeElement;
|
---|
422 | ActivityReferencesTriggersBuilder.Connect(sourceElement, targetElement);
|
---|
423 | }
|
---|
424 | }
|
---|
425 |
|
---|
426 | private partial class TriggerConnectionType : TriggerConnectionTypeBase
|
---|
427 | {
|
---|
428 | /// <summary>
|
---|
429 | /// Constructs a new the TriggerConnectionType with the given ConnectionBuilder.
|
---|
430 | /// </summary>
|
---|
431 | public TriggerConnectionType() : base() {}
|
---|
432 | }
|
---|
433 | }
|
---|
434 |
|
---|
435 | /// <summary>
|
---|
436 | /// Handles interaction between the ConnectionBuilder and the corresponding ConnectionTool.
|
---|
437 | /// </summary>
|
---|
438 | internal partial class ListenerConnectAction : DslDiagrams::ConnectAction
|
---|
439 | {
|
---|
440 | private DslDiagrams::ConnectionType[] connectionTypes;
|
---|
441 |
|
---|
442 | /// <summary>
|
---|
443 | /// Constructs a new ListenerConnectAction for the given Diagram.
|
---|
444 | /// </summary>
|
---|
445 | public ListenerConnectAction(DslDiagrams::Diagram diagram): base(diagram, true)
|
---|
446 | {
|
---|
447 | }
|
---|
448 |
|
---|
449 | /// <summary>
|
---|
450 | /// Gets the cursor corresponding to the given mouse position.
|
---|
451 | /// </summary>
|
---|
452 | /// <remarks>
|
---|
453 | /// Changes the cursor to Cursors.No before the first mouse click if the source shape is not valid.
|
---|
454 | /// </remarks>
|
---|
455 | public override global::System.Windows.Forms.Cursor GetCursor(global::System.Windows.Forms.Cursor currentCursor, DslDiagrams::DiagramClientView diagramClientView, DslDiagrams::PointD mousePosition)
|
---|
456 | {
|
---|
457 | if (this.MouseDownHitShape == null && currentCursor != global::System.Windows.Forms.Cursors.No)
|
---|
458 | {
|
---|
459 | DslDiagrams::DiagramHitTestInfo hitTestInfo = new DslDiagrams::DiagramHitTestInfo(diagramClientView);
|
---|
460 | this.Diagram.DoHitTest(mousePosition, hitTestInfo);
|
---|
461 | DslDiagrams::ShapeElement shape = hitTestInfo.HitDiagramItem.Shape;
|
---|
462 |
|
---|
463 | DslDiagrams::ConnectionType connectionType = GetConnectionTypes(shape, null)[0];
|
---|
464 | string warningString = string.Empty;
|
---|
465 | if (!connectionType.CanCreateConnection(shape, null, ref warningString))
|
---|
466 | {
|
---|
467 | return global::System.Windows.Forms.Cursors.No;
|
---|
468 | }
|
---|
469 | }
|
---|
470 | return base.GetCursor(currentCursor, diagramClientView, mousePosition);
|
---|
471 | }
|
---|
472 |
|
---|
473 |
|
---|
474 | /// <summary>
|
---|
475 | /// Returns the ListenerConnectionType associated with this action.
|
---|
476 | /// </summary>
|
---|
477 | protected override DslDiagrams::ConnectionType[] GetConnectionTypes(DslDiagrams::ShapeElement sourceShapeElement, DslDiagrams::ShapeElement targetShapeElement)
|
---|
478 | {
|
---|
479 | if(this.connectionTypes == null)
|
---|
480 | {
|
---|
481 | this.connectionTypes = new DslDiagrams::ConnectionType[] { new ListenerConnectionType() };
|
---|
482 | }
|
---|
483 |
|
---|
484 | return this.connectionTypes;
|
---|
485 | }
|
---|
486 |
|
---|
487 | private partial class ListenerConnectionTypeBase : DslDiagrams::ConnectionType
|
---|
488 | {
|
---|
489 | /// <summary>
|
---|
490 | /// Constructs a new the ListenerConnectionType with the given ConnectionBuilder.
|
---|
491 | /// </summary>
|
---|
492 | protected ListenerConnectionTypeBase() : base() {}
|
---|
493 |
|
---|
494 | private static DslDiagrams::ShapeElement RemovePassThroughShapes(DslDiagrams::ShapeElement shape)
|
---|
495 | {
|
---|
496 | if (shape is DslDiagrams::Compartment)
|
---|
497 | {
|
---|
498 | return shape.ParentShape;
|
---|
499 | }
|
---|
500 | DslDiagrams::SwimlaneShape swimlane = shape as DslDiagrams::SwimlaneShape;
|
---|
501 | if (swimlane != null && swimlane.ForwardDragDropToParent)
|
---|
502 | {
|
---|
503 | return shape.ParentShape;
|
---|
504 | }
|
---|
505 | return shape;
|
---|
506 | }
|
---|
507 |
|
---|
508 | /// <summary>
|
---|
509 | /// Called by the base ConnectAction class to determine if the given shapes can be connected.
|
---|
510 | /// </summary>
|
---|
511 | /// <remarks>
|
---|
512 | /// This implementation delegates calls to the ConnectionBuilder ActionReferencesListenersBuilder.
|
---|
513 | /// </remarks>
|
---|
514 | public override bool CanCreateConnection(DslDiagrams::ShapeElement sourceShapeElement, DslDiagrams::ShapeElement targetShapeElement, ref string connectionWarning)
|
---|
515 | {
|
---|
516 | bool canConnect = true;
|
---|
517 |
|
---|
518 | if(sourceShapeElement == null) throw new global::System.ArgumentNullException("sourceShapeElement");
|
---|
519 | sourceShapeElement = RemovePassThroughShapes(sourceShapeElement);
|
---|
520 | DslModeling::ModelElement sourceElement = sourceShapeElement.ModelElement;
|
---|
521 | if(sourceElement == null) sourceElement = sourceShapeElement;
|
---|
522 |
|
---|
523 | DslModeling::ModelElement targetElement = null;
|
---|
524 | if (targetShapeElement != null)
|
---|
525 | {
|
---|
526 | targetShapeElement = RemovePassThroughShapes(targetShapeElement);
|
---|
527 | targetElement = targetShapeElement.ModelElement;
|
---|
528 | if(targetElement == null) targetElement = targetShapeElement;
|
---|
529 |
|
---|
530 | }
|
---|
531 |
|
---|
532 | // base.CanCreateConnection must be called to check whether existing Locks prevent this link from getting created.
|
---|
533 | canConnect = base.CanCreateConnection(sourceShapeElement, targetShapeElement, ref connectionWarning);
|
---|
534 | if (canConnect)
|
---|
535 | {
|
---|
536 | if(targetShapeElement == null)
|
---|
537 | {
|
---|
538 | return ActionReferencesListenersBuilder.CanAcceptSource(sourceElement);
|
---|
539 | }
|
---|
540 | else
|
---|
541 | {
|
---|
542 | return ActionReferencesListenersBuilder.CanAcceptSourceAndTarget(sourceElement, targetElement);
|
---|
543 | }
|
---|
544 | }
|
---|
545 | else
|
---|
546 | {
|
---|
547 | //return false
|
---|
548 | return canConnect;
|
---|
549 | }
|
---|
550 | }
|
---|
551 |
|
---|
552 | /// <summary>
|
---|
553 | /// Called by the base ConnectAction class to ask whether the given source and target are valid.
|
---|
554 | /// </summary>
|
---|
555 | /// <remarks>
|
---|
556 | /// Always return true here, to give CanCreateConnection a chance to decide.
|
---|
557 | /// </remarks>
|
---|
558 | public override bool IsValidSourceAndTarget(DslDiagrams::ShapeElement sourceShapeElement, DslDiagrams::ShapeElement targetShapeElement)
|
---|
559 | {
|
---|
560 | return true;
|
---|
561 | }
|
---|
562 |
|
---|
563 | /// <summary>
|
---|
564 | /// Called by the base ConnectAction class to create the underlying relationship.
|
---|
565 | /// </summary>
|
---|
566 | /// <remarks>
|
---|
567 | /// This implementation delegates calls to the ConnectionBuilder ActionReferencesListenersBuilder.
|
---|
568 | /// </remarks>
|
---|
569 | public override void CreateConnection(DslDiagrams::ShapeElement sourceShapeElement, DslDiagrams::ShapeElement targetShapeElement, DslDiagrams::PaintFeedbackArgs paintFeedbackArgs)
|
---|
570 | {
|
---|
571 | if(sourceShapeElement == null) throw new global::System.ArgumentNullException("sourceShapeElement");
|
---|
572 | if(targetShapeElement == null) throw new global::System.ArgumentNullException("targetShapeElement");
|
---|
573 |
|
---|
574 | sourceShapeElement = RemovePassThroughShapes(sourceShapeElement);
|
---|
575 | targetShapeElement = RemovePassThroughShapes(targetShapeElement);
|
---|
576 |
|
---|
577 | DslModeling::ModelElement sourceElement = sourceShapeElement.ModelElement;
|
---|
578 | if(sourceElement == null) sourceElement = sourceShapeElement;
|
---|
579 | DslModeling::ModelElement targetElement = targetShapeElement.ModelElement;
|
---|
580 | if(targetElement == null) targetElement = targetShapeElement;
|
---|
581 | ActionReferencesListenersBuilder.Connect(sourceElement, targetElement);
|
---|
582 | }
|
---|
583 | }
|
---|
584 |
|
---|
585 | private partial class ListenerConnectionType : ListenerConnectionTypeBase
|
---|
586 | {
|
---|
587 | /// <summary>
|
---|
588 | /// Constructs a new the ListenerConnectionType with the given ConnectionBuilder.
|
---|
589 | /// </summary>
|
---|
590 | public ListenerConnectionType() : base() {}
|
---|
591 | }
|
---|
592 | }
|
---|
593 | }
|
---|
594 |
|
---|