Free cookie consent management tool by TermsFeed Policy Generator

source: branches/SimulationCore/HeuristicLab.SimulationCore.Dsl/Dsl/GeneratedCode/Diagram.cs @ 10525

Last change on this file since 10525 was 10525, checked in by abeham, 10 years ago

#1610: added visual model

File size: 25.0 KB
Line 
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
10using DslModeling = global::Microsoft.VisualStudio.Modeling;
11using DslDesign = global::Microsoft.VisualStudio.Modeling.Design;
12using DslDiagrams = global::Microsoft.VisualStudio.Modeling.Diagrams;
13
14[module: global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Scope = "type", Target = "HeuristicLab.SimulationCore.HLSimDiagram")]
15
16namespace HeuristicLab.SimulationCore
17{
18  /// <summary>
19  /// DomainClass HLSimDiagram
20  /// Description for HeuristicLab.SimulationCore.HLSimDiagram
21  /// </summary>
22  [DslDesign::DisplayNameResource("HeuristicLab.SimulationCore.HLSimDiagram.DisplayName", typeof(global::HeuristicLab.SimulationCore.HLSimDomainModel), "HeuristicLab.SimulationCore.GeneratedCode.DomainModelResx")]
23  [DslDesign::DescriptionResource("HeuristicLab.SimulationCore.HLSimDiagram.Description", typeof(global::HeuristicLab.SimulationCore.HLSimDomainModel), "HeuristicLab.SimulationCore.GeneratedCode.DomainModelResx")]
24  [DslModeling::DomainModelOwner(typeof(global::HeuristicLab.SimulationCore.HLSimDomainModel))]
25  [global::System.CLSCompliant(true)]
26  [DslModeling::DomainObjectId("cf1c9f0b-eb8e-4d36-9fcc-6cd2455f9cba")]
27  public partial class HLSimDiagram : DslDiagrams::Diagram
28  {
29    #region Diagram boilerplate
30    private static DslDiagrams::StyleSet classStyleSet;
31    private static global::System.Collections.Generic.IList<DslDiagrams::ShapeField> shapeFields;
32    /// <summary>
33    /// Per-class style set for this shape.
34    /// </summary>
35    protected override DslDiagrams::StyleSet ClassStyleSet
36    {
37      get
38      {
39        if (classStyleSet == null)
40        {
41          classStyleSet = CreateClassStyleSet();
42        }
43        return classStyleSet;
44      }
45    }
46   
47    /// <summary>
48    /// Per-class ShapeFields for this shape
49    /// </summary>
50    public override global::System.Collections.Generic.IList<DslDiagrams::ShapeField> ShapeFields
51    {
52      get
53      {
54        if (shapeFields == null)
55        {
56          shapeFields = CreateShapeFields();
57        }
58        return shapeFields;
59      }
60    }
61    #endregion
62    #region Toolbox filters
63    private static global::System.ComponentModel.ToolboxItemFilterAttribute[] toolboxFilters = new global::System.ComponentModel.ToolboxItemFilterAttribute[] {
64          new global::System.ComponentModel.ToolboxItemFilterAttribute(global::HeuristicLab.SimulationCore.HLSimToolboxHelperBase.ToolboxFilterString, global::System.ComponentModel.ToolboxItemFilterType.Require) };
65   
66    /// <summary>
67    /// Toolbox item filter attributes for this diagram.
68    /// </summary>
69    public override global::System.Collections.ICollection TargetToolboxItemFilterAttributes
70    {
71      get
72      {
73        return toolboxFilters;
74      }
75    }
76    #endregion
77    #region Auto-placement
78    /// <summary>
79    /// Indicate that child shapes should added through view fixup should be placed automatically.
80    /// </summary>
81    public override bool ShouldAutoPlaceChildShapes
82    {
83      get
84      {
85        return true;
86      }
87    }
88    #endregion
89    #region Shape mapping
90    /// <summary>
91    /// Called during view fixup to ask the parent whether a shape should be created for the given child element.
92    /// </summary>
93    /// <remarks>
94    /// Always return true, since we assume there is only one diagram per model file for DSL scenarios.
95    /// </remarks>
96    protected override bool ShouldAddShapeForElement(DslModeling::ModelElement element)
97    {
98      return true;
99    }
100   
101    /// <summary>
102    /// Called during view fixup to configure the given child element, after it has been created.
103    /// </summary>
104    /// <remarks>
105    /// Custom code for choosing the shapes attached to either end of a connector is called from here.
106    /// </remarks>
107    protected override void OnChildConfiguring(DslDiagrams::ShapeElement child, bool createdDuringViewFixup)
108    {
109      DslDiagrams::NodeShape sourceShape;
110      DslDiagrams::NodeShape targetShape;
111      DslDiagrams::BinaryLinkShape connector = child as DslDiagrams::BinaryLinkShape;
112      if(connector == null)
113      {
114        base.OnChildConfiguring(child, createdDuringViewFixup);
115        return;
116      }
117      this.GetSourceAndTargetForConnector(connector, out sourceShape, out targetShape);
118     
119      global::System.Diagnostics.Debug.Assert(sourceShape != null && targetShape != null, "Unable to find source and target shapes for connector.");
120      connector.Connect(sourceShape, targetShape);
121    }
122   
123    /// <summary>
124    /// helper method to find the shapes for either end of a connector, including calling the user's custom code
125    /// </summary>
126    [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
127    internal void GetSourceAndTargetForConnector(DslDiagrams::BinaryLinkShape connector, out DslDiagrams::NodeShape sourceShape, out DslDiagrams::NodeShape targetShape)
128    {
129      sourceShape = null;
130      targetShape = null;
131     
132      if (sourceShape == null || targetShape == null)
133      {
134        DslDiagrams::NodeShape[] endShapes = GetEndShapesForConnector(connector);
135        if(sourceShape == null)
136        {
137          sourceShape = endShapes[0];
138        }
139        if(targetShape == null)
140        {
141          targetShape = endShapes[1];
142        }
143      }
144    }
145   
146    /// <summary>
147    /// Helper method to find shapes for either end of a connector by looking for shapes associated with either end of the relationship mapped to the connector.
148    /// </summary>
149    private DslDiagrams::NodeShape[] GetEndShapesForConnector(DslDiagrams::BinaryLinkShape connector)
150    {
151      DslModeling::ElementLink link = connector.ModelElement as DslModeling::ElementLink;
152      DslDiagrams::NodeShape sourceShape = null, targetShape = null;
153      if (link != null)
154      {
155        global::System.Collections.ObjectModel.ReadOnlyCollection<DslModeling::ModelElement> linkedElements = link.LinkedElements;
156        if (linkedElements.Count == 2)
157        {
158          DslDiagrams::Diagram currentDiagram = this.Diagram;
159          DslModeling::LinkedElementCollection<DslDiagrams::PresentationElement> presentationElements = DslDiagrams::PresentationViewsSubject.GetPresentation(linkedElements[0]);
160          foreach (DslDiagrams::PresentationElement presentationElement in presentationElements)
161          {
162            DslDiagrams::NodeShape shape = presentationElement as DslDiagrams::NodeShape;
163            if (shape != null && shape.Diagram == currentDiagram)
164            {
165              sourceShape = shape;
166              break;
167            }
168          }
169         
170          presentationElements = DslDiagrams::PresentationViewsSubject.GetPresentation(linkedElements[1]);
171          foreach (DslDiagrams::PresentationElement presentationElement in presentationElements)
172          {
173            DslDiagrams::NodeShape shape = presentationElement as DslDiagrams::NodeShape;
174            if (shape != null && shape.Diagram == currentDiagram)
175            {
176              targetShape = shape;
177              break;
178            }
179          }
180   
181        }
182      }
183     
184      return new DslDiagrams::NodeShape[] { sourceShape, targetShape };
185    }
186   
187    /// <summary>
188    /// Creates a new shape for the given model element as part of view fixup
189    /// </summary>
190    [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Justification = "Generated code.")]
191    [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Generated code.")]
192    protected override DslDiagrams::ShapeElement CreateChildShape(DslModeling::ModelElement element)
193    {
194      if(element is global::HeuristicLab.SimulationCore.Activity)
195      {
196        global::HeuristicLab.SimulationCore.ActivityShape newShape = new global::HeuristicLab.SimulationCore.ActivityShape(this.Partition);
197        if(newShape != null) newShape.Size = newShape.DefaultSize; // set default shape size
198        return newShape;
199      }
200      if(element is global::HeuristicLab.SimulationCore.Action)
201      {
202        global::HeuristicLab.SimulationCore.ActionShape newShape = new global::HeuristicLab.SimulationCore.ActionShape(this.Partition);
203        if(newShape != null) newShape.Size = newShape.DefaultSize; // set default shape size
204        return newShape;
205      }
206      if(element is global::HeuristicLab.SimulationCore.ActivityReferencesTriggers)
207      {
208        global::HeuristicLab.SimulationCore.Trigger newShape = new global::HeuristicLab.SimulationCore.Trigger(this.Partition);
209        return newShape;
210      }
211      if(element is global::HeuristicLab.SimulationCore.ActionReferencesListeners)
212      {
213        global::HeuristicLab.SimulationCore.Listener newShape = new global::HeuristicLab.SimulationCore.Listener(this.Partition);
214        return newShape;
215      }
216      return base.CreateChildShape(element);
217    }
218    #endregion
219    #region Decorator mapping
220    /// <summary>
221    /// Initialize shape decorator mappings.  This is done here rather than in individual shapes because decorator maps
222    /// are defined per diagram type rather than per shape type.
223    /// </summary>
224    protected override void InitializeShapeFields(global::System.Collections.Generic.IList<DslDiagrams::ShapeField> shapeFields)
225    {
226      base.InitializeShapeFields(shapeFields);
227      global::HeuristicLab.SimulationCore.ActivityShape.DecoratorsInitialized += ActivityShapeDecoratorMap.OnDecoratorsInitialized;
228      global::HeuristicLab.SimulationCore.ActionShape.DecoratorsInitialized += ActionShapeDecoratorMap.OnDecoratorsInitialized;
229    }
230   
231    /// <summary>
232    /// Class containing decorator path traversal methods for ActivityShape.
233    /// </summary>
234    internal static partial class ActivityShapeDecoratorMap
235    {
236      /// <summary>
237      /// Event handler called when decorator initialization is complete for ActivityShape.  Adds decorator mappings for this shape or connector.
238      /// </summary>
239      public static void OnDecoratorsInitialized(object sender, global::System.EventArgs e)
240      {
241        DslDiagrams::ShapeElement shape = (DslDiagrams::ShapeElement)sender;
242        DslDiagrams::AssociatedPropertyInfo propertyInfo;
243       
244        propertyInfo = new DslDiagrams::AssociatedPropertyInfo(global::HeuristicLab.SimulationCore.Activity.NameDomainPropertyId);
245        DslDiagrams::ShapeElement.FindDecorator(shape.Decorators, "NameDecorator").AssociateValueWith(shape.Store, propertyInfo);
246      }
247    }
248   
249    /// <summary>
250    /// Class containing decorator path traversal methods for ActionShape.
251    /// </summary>
252    internal static partial class ActionShapeDecoratorMap
253    {
254      /// <summary>
255      /// Event handler called when decorator initialization is complete for ActionShape.  Adds decorator mappings for this shape or connector.
256      /// </summary>
257      public static void OnDecoratorsInitialized(object sender, global::System.EventArgs e)
258      {
259        DslDiagrams::ShapeElement shape = (DslDiagrams::ShapeElement)sender;
260        DslDiagrams::AssociatedPropertyInfo propertyInfo;
261       
262        propertyInfo = new DslDiagrams::AssociatedPropertyInfo(global::HeuristicLab.SimulationCore.Action.NameDomainPropertyId);
263        DslDiagrams::ShapeElement.FindDecorator(shape.Decorators, "NameDecorator").AssociateValueWith(shape.Store, propertyInfo);
264      }
265    }
266   
267    #endregion
268   
269    #region Connect actions
270    private bool changingMouseAction;
271    private global::HeuristicLab.SimulationCore.TriggerConnectAction triggerConnectAction;
272    private global::HeuristicLab.SimulationCore.ListenerConnectAction listenerConnectAction;
273    /// <summary>
274    /// Virtual method to provide a filter when to select the mouse action
275    /// </summary>
276    /// <param name="activeView">Currently active view</param>
277    /// <param name="filter">filter string used to filter the toolbox items</param>
278    protected virtual bool SelectedToolboxItemSupportsFilterString(DslDiagrams::DiagramView activeView, string filter)
279    {
280      return activeView.SelectedToolboxItemSupportsFilterString(filter);
281    }
282    /// <summary>
283    /// Override to provide the right mouse action when trying
284    /// to create links on the diagram
285    /// </summary>
286    /// <param name="pointArgs"></param>
287    public override void OnViewMouseEnter(DslDiagrams::DiagramPointEventArgs pointArgs)
288    {
289      if (pointArgs  == null) throw new global::System.ArgumentNullException("pointArgs");
290   
291      DslDiagrams::DiagramView activeView = this.ActiveDiagramView;
292      if(activeView != null)
293      {
294        DslDiagrams::MouseAction action = null;
295        if (SelectedToolboxItemSupportsFilterString(activeView, global::HeuristicLab.SimulationCore.HLSimToolboxHelper.TriggerFilterString))
296        {
297          if (this.triggerConnectAction == null)
298          {
299            this.triggerConnectAction = new global::HeuristicLab.SimulationCore.TriggerConnectAction(this);
300            this.triggerConnectAction.MouseActionDeactivated += new DslDiagrams::MouseAction.MouseActionDeactivatedEventHandler(OnConnectActionDeactivated);
301          }
302          action = this.triggerConnectAction;
303        }
304        else if (SelectedToolboxItemSupportsFilterString(activeView, global::HeuristicLab.SimulationCore.HLSimToolboxHelper.ListenerFilterString))
305        {
306          if (this.listenerConnectAction == null)
307          {
308            this.listenerConnectAction = new global::HeuristicLab.SimulationCore.ListenerConnectAction(this);
309            this.listenerConnectAction.MouseActionDeactivated += new DslDiagrams::MouseAction.MouseActionDeactivatedEventHandler(OnConnectActionDeactivated);
310          }
311          action = this.listenerConnectAction;
312        }
313        else
314        {
315          action = null;
316        }
317       
318        if (pointArgs.DiagramClientView.ActiveMouseAction != action)
319        {
320          try
321          {
322            this.changingMouseAction = true;
323            pointArgs.DiagramClientView.ActiveMouseAction = action;
324          }
325          finally
326          {
327            this.changingMouseAction = false;
328          }
329        }
330      }
331    }
332   
333    /// <summary>
334    /// Snap toolbox selection back to regular pointer after using a custom connect action.
335    /// </summary>
336    private void OnConnectActionDeactivated(object sender, DslDiagrams::DiagramEventArgs e)
337    {
338      OnMouseActionDeactivated();
339    }
340   
341    /// <summary>
342    /// Overridable method to manage the mouse deactivation. The default implementation snap stoolbox selection back to regular pointer
343    /// after using a custom connect action.
344    /// </summary>
345    protected virtual void OnMouseActionDeactivated()
346    {
347      DslDiagrams::DiagramView activeView = this.ActiveDiagramView;
348   
349      if (activeView != null && activeView.Toolbox != null)
350      {
351        // If we're not changing mouse action due to changing toolbox selection change,
352        // reset toolbox selection.
353        if (!this.changingMouseAction)
354        {
355          activeView.Toolbox.SelectedToolboxItemUsed();
356        }
357      }
358    }
359    #endregion
360   
361    /// <summary>
362    /// Dispose of connect actions.
363    /// </summary>
364    protected override void Dispose(bool disposing)
365    {
366      try
367      {
368        if(disposing)
369        {
370          if(this.triggerConnectAction != null)
371          {
372            this.triggerConnectAction.Dispose();
373            this.triggerConnectAction = null;
374          }
375          if(this.listenerConnectAction != null)
376          {
377            this.listenerConnectAction.Dispose();
378            this.listenerConnectAction = null;
379          }
380        }
381      }
382      finally
383      {
384        base.Dispose(disposing);
385      }
386    }
387    #region Constructors, domain class Id
388 
389    /// <summary>
390    /// HLSimDiagram domain class Id.
391    /// </summary>
392    public static readonly new global::System.Guid DomainClassId = new global::System.Guid(0xcf1c9f0b, 0xeb8e, 0x4d36, 0x9f, 0xcc, 0x6c, 0xd2, 0x45, 0x5f, 0x9c, 0xba);
393    /// <summary>
394    /// Constructor
395    /// </summary>
396    /// <param name="store">Store where new element is to be created.</param>
397    /// <param name="propertyAssignments">List of domain property id/value pairs to set once the element is created.</param>
398    public HLSimDiagram(DslModeling::Store store, params DslModeling::PropertyAssignment[] propertyAssignments)
399      : this(store != null ? store.DefaultPartitionForClass(DomainClassId) : null, propertyAssignments)
400    {
401    }
402   
403    /// <summary>
404    /// Constructor
405    /// </summary>
406    /// <param name="partition">Partition where new element is to be created.</param>
407    /// <param name="propertyAssignments">List of domain property id/value pairs to set once the element is created.</param>
408    public HLSimDiagram(DslModeling::Partition partition, params DslModeling::PropertyAssignment[] propertyAssignments)
409      : base(partition, propertyAssignments)
410    {
411    }
412    #endregion
413  }
414}
415namespace HeuristicLab.SimulationCore
416{
417 
418    /// <summary>
419    /// Double derived implementation for the rule that initiates view fixup when an element that has an associated shape is added to the model.
420    /// This now enables the DSL author to everride the SkipFixUp() method
421    /// </summary>
422    internal partial class FixUpDiagramBase : DslModeling::AddRule
423    {
424      protected virtual bool SkipFixup(DslModeling::ModelElement childElement)
425      {
426        return childElement.IsDeleted;
427      }
428    }
429 
430    /// <summary>
431    /// Rule that initiates view fixup when an element that has an associated shape is added to the model.
432    /// </summary>
433    [DslModeling::RuleOn(typeof(global::HeuristicLab.SimulationCore.Activity), FireTime = DslModeling::TimeToFire.TopLevelCommit, Priority = DslDiagrams::DiagramFixupConstants.AddShapeParentExistRulePriority, InitiallyDisabled=true)]
434    [DslModeling::RuleOn(typeof(global::HeuristicLab.SimulationCore.Action), FireTime = DslModeling::TimeToFire.TopLevelCommit, Priority = DslDiagrams::DiagramFixupConstants.AddShapeParentExistRulePriority, InitiallyDisabled=true)]
435    [DslModeling::RuleOn(typeof(global::HeuristicLab.SimulationCore.ActivityReferencesTriggers), FireTime = DslModeling::TimeToFire.TopLevelCommit, Priority = DslDiagrams::DiagramFixupConstants.AddConnectionRulePriority, InitiallyDisabled=true)]
436    [DslModeling::RuleOn(typeof(global::HeuristicLab.SimulationCore.ActionReferencesListeners), FireTime = DslModeling::TimeToFire.TopLevelCommit, Priority = DslDiagrams::DiagramFixupConstants.AddConnectionRulePriority, InitiallyDisabled=true)]
437    internal sealed partial class FixUpDiagram : FixUpDiagramBase
438    {
439      [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
440      public override void ElementAdded(DslModeling::ElementAddedEventArgs e)
441      {
442        if(e == null) throw new global::System.ArgumentNullException("e");
443     
444        DslModeling::ModelElement childElement = e.ModelElement;
445        if (this.SkipFixup(childElement))
446          return;
447        DslModeling::ModelElement parentElement;
448        if(childElement is DslModeling::ElementLink)
449        {
450          parentElement = GetParentForRelationship((DslModeling::ElementLink)childElement);
451        } else
452        if(childElement is global::HeuristicLab.SimulationCore.Activity)
453        {
454          parentElement = GetParentForActivity((global::HeuristicLab.SimulationCore.Activity)childElement);
455        } else
456        if(childElement is global::HeuristicLab.SimulationCore.Action)
457        {
458          parentElement = GetParentForAction((global::HeuristicLab.SimulationCore.Action)childElement);
459        } else
460        {
461          parentElement = null;
462        }
463       
464        if(parentElement != null)
465        {
466          DslDiagrams::Diagram.FixUpDiagram(parentElement, childElement);
467        }
468      }
469      public static global::HeuristicLab.SimulationCore.SimulationModel GetParentForActivity( global::HeuristicLab.SimulationCore.Activity root )
470      {
471        // Segments 0 and 1
472        global::HeuristicLab.SimulationCore.SimulationModel result = root.SimulationModel;
473        if ( result == null ) return null;
474        return result;
475      }
476      public static global::HeuristicLab.SimulationCore.SimulationModel GetParentForAction( global::HeuristicLab.SimulationCore.Action root )
477      {
478        // Segments 0 and 1
479        global::HeuristicLab.SimulationCore.SimulationModel result = root.SimulationModel;
480        if ( result == null ) return null;
481        return result;
482      }
483      private static DslModeling::ModelElement GetParentForRelationship(DslModeling::ElementLink elementLink)
484      {
485        global::System.Collections.ObjectModel.ReadOnlyCollection<DslModeling::ModelElement> linkedElements = elementLink.LinkedElements;
486 
487        if (linkedElements.Count == 2)
488        {
489          DslDiagrams::ShapeElement sourceShape = linkedElements[0] as DslDiagrams::ShapeElement;
490          DslDiagrams::ShapeElement targetShape = linkedElements[1] as DslDiagrams::ShapeElement;
491 
492          if(sourceShape == null)
493          {
494            DslModeling::LinkedElementCollection<DslDiagrams::PresentationElement> presentationElements = DslDiagrams::PresentationViewsSubject.GetPresentation(linkedElements[0]);
495            foreach (DslDiagrams::PresentationElement presentationElement in presentationElements)
496            {
497              DslDiagrams::ShapeElement shape = presentationElement as DslDiagrams::ShapeElement;
498              if (shape != null)
499              {
500                sourceShape = shape;
501                break;
502              }
503            }
504          }
505         
506          if(targetShape == null)
507          {
508            DslModeling::LinkedElementCollection<DslDiagrams::PresentationElement> presentationElements = DslDiagrams::PresentationViewsSubject.GetPresentation(linkedElements[1]);
509            foreach (DslDiagrams::PresentationElement presentationElement in presentationElements)
510            {
511              DslDiagrams::ShapeElement shape = presentationElement as DslDiagrams::ShapeElement;
512              if (shape != null)
513              {
514                targetShape = shape;
515                break;
516              }
517            }
518          }
519         
520          if(sourceShape == null || targetShape == null)
521          {
522            global::System.Diagnostics.Debug.Fail("Unable to find source and/or target shape for view fixup.");
523            return null;
524          }
525 
526          DslDiagrams::ShapeElement sourceParent = sourceShape.ParentShape;
527          DslDiagrams::ShapeElement targetParent = targetShape.ParentShape;
528 
529          while (sourceParent != targetParent && sourceParent != null)
530          {
531            DslDiagrams::ShapeElement curParent = targetParent;
532            while (sourceParent != curParent && curParent != null)
533            {
534              curParent = curParent.ParentShape;
535            }
536 
537            if(sourceParent == curParent)
538            {
539              break;
540            }
541            else
542            {
543              sourceParent = sourceParent.ParentShape;
544            }
545          }
546 
547          while (sourceParent != null)
548          {
549            // ensure that the parent can parent connectors (i.e., a diagram or a swimlane).
550            if(sourceParent is DslDiagrams::Diagram || sourceParent is DslDiagrams::SwimlaneShape)
551            {
552              break;
553            }
554            else
555            {
556              sourceParent = sourceParent.ParentShape;
557            }
558          }
559 
560          global::System.Diagnostics.Debug.Assert(sourceParent != null && sourceParent.ModelElement != null, "Unable to find common parent for view fixup.");
561          return sourceParent.ModelElement;
562        }
563 
564        return null;
565      }
566    }
567   
568 
569    /// <summary>
570    /// Reroute a connector when the role players of its underlying relationship change
571    /// </summary>
572    [DslModeling::RuleOn(typeof(global::HeuristicLab.SimulationCore.ActivityReferencesTriggers), FireTime = DslModeling::TimeToFire.TopLevelCommit, Priority = DslDiagrams::DiagramFixupConstants.AddConnectionRulePriority, InitiallyDisabled=true)]
573    [DslModeling::RuleOn(typeof(global::HeuristicLab.SimulationCore.ActionReferencesListeners), FireTime = DslModeling::TimeToFire.TopLevelCommit, Priority = DslDiagrams::DiagramFixupConstants.AddConnectionRulePriority, InitiallyDisabled=true)]
574    internal sealed class ConnectorRolePlayerChanged : DslModeling::RolePlayerChangeRule
575    {
576      /// <summary>
577      /// Reroute a connector when the role players of its underlying relationship change
578      /// </summary>
579      public override void RolePlayerChanged(DslModeling::RolePlayerChangedEventArgs e)
580      {
581        if (e == null) throw new global::System.ArgumentNullException("e");
582 
583        global::System.Collections.ObjectModel.ReadOnlyCollection<DslDiagrams::PresentationViewsSubject> connectorLinks = DslDiagrams::PresentationViewsSubject.GetLinksToPresentation(e.ElementLink);
584        foreach (DslDiagrams::PresentationViewsSubject connectorLink in connectorLinks)
585        {
586          // Fix up any binary link shapes attached to the element link.
587          DslDiagrams::BinaryLinkShape linkShape = connectorLink.Presentation as DslDiagrams::BinaryLinkShape;
588          if (linkShape != null)
589          {
590            global::HeuristicLab.SimulationCore.HLSimDiagram diagram = linkShape.Diagram as global::HeuristicLab.SimulationCore.HLSimDiagram;
591            if (diagram != null)
592            {
593              if (e.NewRolePlayer != null)
594              {
595                DslDiagrams::NodeShape fromShape;
596                DslDiagrams::NodeShape toShape;
597                diagram.GetSourceAndTargetForConnector(linkShape, out fromShape, out toShape);
598                if (fromShape != null && toShape != null)
599                {
600                  if (!object.Equals(fromShape, linkShape.FromShape))
601                  {
602                    linkShape.FromShape = fromShape;
603                  }
604                  if (!object.Equals(linkShape.ToShape, toShape))
605                  {
606                    linkShape.ToShape = toShape;
607                  }
608                }
609                else
610                {
611                  // delete the connector if we cannot find an appropriate target shape.
612                  linkShape.Delete();
613                }
614              }
615              else
616              {
617                // delete the connector if the new role player is null.
618                linkShape.Delete();
619              }
620            }
621          }
622        }
623      }
624    }
625  }
Note: See TracBrowser for help on using the repository browser.