/// <summary> /// Initializes a view representation of a model element /// </summary> /// <param name="modelElement">Element to be represented</param> /// <param name="viewHelper">Element's viewHelper</param> /// <param name="controller">Element's controller</param> public override void InitializeRepresentant(Element modelElement, ViewHelper viewHelper, ElementController controller) { PIM_Association associationRepresentant = new PIM_Association(XCaseCanvas); associationRepresentant.InitializeRepresentant(modelElement, ((AssociationClassViewHelper)viewHelper).AssociationViewHelper, new AssociationController((Association)modelElement, controller.DiagramController)); Association = associationRepresentant; Association.AssociationClass = this; Association.AssociationName = null; Association.ViewHelper.MainLabelViewHelper.LabelVisible = false; AssociationClassViewHelper _viewHelper = (AssociationClassViewHelper)viewHelper; if (double.IsNaN(_viewHelper.X) || double.IsNaN(_viewHelper.Y)) { Rect r = RectExtensions.GetEncompassingRectangle(associationRepresentant.participantElements.Values); if (associationRepresentant.participantElements.Count > 2) { _viewHelper.X = r.GetCenter().X + 30; _viewHelper.Y = r.GetCenter().Y; } else { _viewHelper.X = r.GetCenter().X; _viewHelper.Y = r.GetCenter().Y + 20; } } base.InitializeRepresentant(modelElement, viewHelper, controller); if (associationRepresentant.ViewHelper.UseDiamond) { if (((AssociationClassViewHelper)ViewHelper).Points.Count == 0) { ((AssociationClassViewHelper)ViewHelper).Points.AppendRange( JunctionGeometryHelper.ComputeOptimalConnection(this, associationRepresentant.Diamond)); ((AssociationClassViewHelper)ViewHelper).Points.PointsInvalid = true; } junction = new XCaseJunction(XCaseCanvas, ((AssociationClassViewHelper)ViewHelper).Points) { Pen = MediaLibrary.DashedBlackPen }; XCaseCanvas.Children.Add(junction); junction.NewConnection(this, null, Association.Diamond, null, ((AssociationClassViewHelper)ViewHelper).Points); junction.SelectionOwner = this; } else { primitiveJunction = new XCasePrimitiveJunction(XCaseCanvas, this, Association) { Pen = MediaLibrary.DashedBlackPen }; } this.StartBindings(); }
/// <summary> /// Initializes a view representation of a model element /// </summary> /// <param name="modelElement">Element to be represented</param> /// <param name="viewHelper">Element's viewHelper</param> /// <param name="controller">Element's controller</param> public void InitializeRepresentant(Element modelElement, ViewHelper viewHelper, ElementController controller) { XCaseCanvas.Children.Add(this); Controller = (CommentController)controller; ViewHelper = (CommentViewHelper)viewHelper; /* CommentText must be assigned now :( because it defines comment dimension * which have to be known before initializing the junction */ this.CommentText = ((Comment)modelElement).Body; if (ModelComment.AnnotatedElement != null && !(ModelComment.AnnotatedElement is Package)) { X = ViewHelper.X; Y = ViewHelper.Y; UpdateLayout(); if (XCaseCanvas.ElementRepresentations[ModelComment.AnnotatedElement] is DragThumb) { SnapTo((DragThumb)XCaseCanvas.ElementRepresentations[ModelComment.AnnotatedElement], false); } object target = XCaseCanvas.ElementRepresentations[ModelComment.AnnotatedElement]; if (target is PIM_Association && ((PIM_Association)target).ViewHelper.UseDiamond) { target = ((PIM_Association)target).Diamond; } if (target is IConnectable) { if (ViewHelper.LinePoints.Count == 0) { ViewHelper.LinePoints.AppendRange(JunctionGeometryHelper.ComputeOptimalConnection(this, (IConnectable)target)); } junction = new XCaseJunction(XCaseCanvas, ViewHelper.LinePoints) { Pen = MediaLibrary.DashedBlackPen }; XCaseCanvas.Children.Add(junction); junction.NewConnection(this, null, (IConnectable)target, null, ViewHelper.LinePoints); } else if (target is IPrimitiveJunctionTarget) { primitiveJunction = new XCasePrimitiveJunction(XCaseCanvas, this, (IPrimitiveJunctionTarget)target); } else { throw new ArgumentException("Commentary can be connected only to IConnectable or IPrimitiveJunctionTarget"); } } this.StartBindings(); }
/// <summary> /// Invoked when an unhandled <see cref="System.Windows.Input.Mouse.PreviewMouseDownEvent"/>�attached event reaches /// an element in its route that is derived from this class. /// The event drops dragging and this method stops highlighting the association to which the association end belongs. /// </summary> /// <param name="e">The <see cref="T:System.Windows.Input.MouseButtonEventArgs"/> that contains the event data. The event data reports that one or more mouse buttons were pressed.</param> protected override void OnPreviewMouseDown(System.Windows.Input.MouseButtonEventArgs e) { IPrimitiveJunctionTarget targetJunction = null; if (Association != null) { Association.Highlight(); } if (PSM_Association != null) { PSM_Association.Junction.Highlight(); } if (highlightJunction == null) { if (Association != null && AssociationEnd != null) { targetJunction = Association.GetJunctionConnectingEnd(AssociationEnd); } if (PSM_Association != null) { targetJunction = PSM_Association; } if (targetJunction != null) { highlightJunction = new XCasePrimitiveJunction(XCaseCanvas, this, targetJunction) { Pen = MediaLibrary.DashedBlackPen }; } } if (highlightJunction != null) { highlightJunction.Visibility = Visibility.Visible; } base.OnPreviewMouseDown(e); }