public override void CommandOperation(object parameter)
 {
     ViewHelper = new AssociationClassViewHelper(Diagram, IncludedAssociationClass.Element)
     {
         X = X, Y = Y
     };
     Diagram.AddModelElement(IncludedAssociationClass.Element, ViewHelper);
 }
예제 #2
0
        /// <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();
        }