Exemple #1
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();
        }
Exemple #2
0
        /// <summary>
        /// Returns bounding rectangle of the element (rectangle containing all points of the junction).
        /// </summary>
        /// <returns>Bounding rectangle</returns>
        public Rect GetBounds()
        {
            Point[] p = new Point[Points.Count()];
            int     i = 0;

            foreach (JunctionPoint point in Points)
            {
                //p[i] = point.TranslatePoint(point.Position, XCaseCanvas);
                p[i] = point.CanvasPosition;
                i++;
            }
            return(RectExtensions.GetEncompassingRectangle(p));
        }
Exemple #3
0
        public override void Execute(object parameter)
        {
            IEnumerable <PIM_Class> selectedClasses = ActiveDiagramView.SelectedItems.OfType <PIM_Class>();

            Class[] classes = new Class[selectedClasses.Count()];
            int     i       = 0;

            foreach (PIM_Class xCaseClass in selectedClasses)
            {
                classes[i] = (Class)xCaseClass.ModelElement;
                i++;
            }

            Rect r = RectExtensions.GetEncompassingRectangle(selectedClasses.OfType <IConnectable>());

            if (selectedClasses.Count() > 2)
            {
                ActiveDiagramView.Controller.NewAssociationClass(null, classes);                 //r.GetCenter().X + 30, r.GetCenter().Y );
            }
            else
            {
                ActiveDiagramView.Controller.NewAssociationClass(null, classes);                 //r.GetCenter().X, r.GetCenter().Y + 20);
            }
        }
Exemple #4
0
        private void InitializeFromViewHelper()
        {
            if (ViewHelper.AssociationEndsViewHelpers.Count != Association.Ends.Count)
            {
                ViewHelper.CreateEndsViewHelpers(this.Association);
            }
            if (ViewHelper.ForceUseDiamond)
            {
                ViewHelper.UseDiamond = true;
            }
            ViewHelper.ForceUseDiamond = false;
            participantElements        = new Dictionary <AssociationEndViewHelper, IConnectable>();
            foreach (AssociationEndViewHelper endViewHelper in ViewHelper.AssociationEndsViewHelpers)
            {
                if (!(XCaseCanvas.ElementRepresentations[endViewHelper.AssociationEnd.Class] is IConnectable))
                {
                    throw new InvalidOperationException("One of the association ends is not visualized as IConnectable");
                }
                participantElements[endViewHelper]
                    = XCaseCanvas.ElementRepresentations[endViewHelper.AssociationEnd.Class] as IConnectable;
            }

            foreach (Control c in subControls)
            {
                if (c != null)
                {
                    c.MouseEnter -= junction_MouseEnter;
                    c.MouseLeave -= junction_MouseLeave;
                }
            }

            if (ViewHelper.UseDiamond)
            {
                // simpleAssociationJunction field won't be used if diamond is used
                if (simpleAssociationJunction != null)
                {
                    simpleAssociationJunction.DeleteFromCanvas();
                    ViewHelper.AssociationEndsViewHelpers[0].Points.Clear();
                }

                // prepare the diamond
                if (Diamond == null)
                {
                    Diamond = new AssociationDiamond(XCaseCanvas, this, ViewHelper);
                    XCaseCanvas.Children.Add(Diamond);
                }
                Rect r = RectExtensions.GetEncompassingRectangle(participantElements.Values);
                if (ViewHelper.X == 0 && ViewHelper.Y == 0)
                {
                    Diamond.X    = r.GetCenter().X - Diamond.ActualWidth / 2;
                    Diamond.Y    = r.GetCenter().Y - Diamond.ActualHeight / 2;
                    ViewHelper.X = Diamond.X;
                    ViewHelper.Y = Diamond.Y;
                }
                Diamond.UpdateLayout();

                /*
                 * for each association end there will be one junction between the diamond and the
                 * participating element. Start point of the junction will lay on the diamond, end
                 * point of the junction will lay on the participating element and will be bound to
                 * an association end.
                 */
                foreach (AssociationEndViewHelper endViewHelper in ViewHelper.AssociationEndsViewHelpers)
                {
                    //compute the start and end point of each junction if they are not already computed
                    if (endViewHelper.Points.Count < 2)
                    {
                        endViewHelper.Points.Clear();
                        endViewHelper.Points.AppendRange(JunctionGeometryHelper.ComputeOptimalConnection(Diamond, participantElements[endViewHelper]));
                        if (!Diamond.IsMeasureValid || !participantElements[endViewHelper].IsMeasureValid)
                        {
                            endViewHelper.Points.PointsInvalid = true;
                        }
                    }
                    XCaseJunction junction = new XCaseJunction(XCaseCanvas, this, endViewHelper.Points);
                    junction.NewConnection(Diamond, null, participantElements[endViewHelper], endViewHelper, endViewHelper.Points);
                    junction.StartPoint.Movable    = false;
                    junction.StartPoint.Visibility = Visibility.Hidden;
                    associationJunctions[endViewHelper.AssociationEnd] = junction;
                    XCaseCanvas.Children.Add(junction);
                }
            }
            else
            {
                foreach (XCaseJunction junction in associationJunctions.Values)
                {
                    junction.DeleteFromCanvas();
                }
                if (Diamond != null)
                {
                    Diamond.DeleteFromCanvas();
                    Diamond = null;
                }

                associationJunctions.Clear();

                IConnectable SourceElement = (IConnectable)XCaseCanvas.ElementRepresentations[ViewHelper.AssociationEndsViewHelpers[0].AssociationEnd.Class];
                IConnectable TargetElement;

                if (ViewHelper.AssociationEndsViewHelpers.Count == 2 &&
                    ViewHelper.AssociationEndsViewHelpers[0].AssociationEnd.Class == ViewHelper.AssociationEndsViewHelpers[1].AssociationEnd.Class)
                {
                    TargetElement = SourceElement;

                    if (ViewHelper.Points.Count == 0)
                    {
                        ViewHelper.Points.AppendRange(JunctionGeometryHelper.ComputePointsForSelfAssociation(SourceElement.GetBounds()));
                        if (!SourceElement.IsMeasureValid)
                        {
                            ViewHelper.Points.PointsInvalid = true;
                        }
                    }
                }

                /*
                 * two different classes are connected directly without using central diamond,
                 * association will consist of two points
                 * in optimal position to connect two rectangles.
                 */
                else if (ViewHelper.AssociationEndsViewHelpers.Count == 2)
                {
                    TargetElement = (IConnectable)XCaseCanvas.ElementRepresentations[ViewHelper.AssociationEndsViewHelpers[1].AssociationEnd.Class];
                    if (ViewHelper.Points.Count < 2)
                    {
                        ViewHelper.Points.Clear();
                        ViewHelper.Points.AppendRange(JunctionGeometryHelper.ComputeOptimalConnection(SourceElement, TargetElement));
                        if (!SourceElement.IsMeasureValid)
                        {
                            ViewHelper.Points.PointsInvalid = true;
                        }
                    }
                }
                else
                {
                    throw new InvalidOperationException("UseDiamond must be true if there are more association ends than 2");
                }

                /*
                 * diamond is not used, simpleAssociationJunction field will be used to
                 * represent the junction
                 */
                if (simpleAssociationJunction != null)
                {
                    simpleAssociationJunction.DeleteFromCanvas();
                }
                simpleAssociationJunction = new XCaseJunction(XCaseCanvas, this, ViewHelper.Points);
                if (Association.Ends.Count == 1)
                {
                    simpleAssociationJunction.NewConnection(SourceElement, null, TargetElement, ViewHelper.AssociationEndsViewHelpers[0], ViewHelper.Points);
                }
                else
                {
                    simpleAssociationJunction.NewConnection(SourceElement, ViewHelper.AssociationEndsViewHelpers[0], TargetElement, ViewHelper.AssociationEndsViewHelpers[1], ViewHelper.Points);
                }
                XCaseCanvas.Children.Add(simpleAssociationJunction);
            }

            foreach (Control c in subControls)
            {
                if (c != null)
                {
                    c.MouseEnter += junction_MouseEnter;
                    c.MouseLeave += junction_MouseLeave;
                }
            }
        }
Exemple #5
0
 public Rect GetBounds()
 {
     return(RectExtensions.GetEncompassingRectangle(Points.Select(p => p.CanvasPosition)));
 }