Beispiel #1
0
        public DependencyArrow(UMLElement firstBlock, UMLElement secondBlock, Tips type)
        {
            if (!(firstBlock is UMLClassBox) || !(secondBlock is UMLClassBox))
            {
                throw  new Exception("Один из элементов пустой");
            }
            fb    = firstBlock as UMLClassBox;
            sb    = secondBlock as UMLClassBox;
            fguid = fb.getGuid();
            sguid = sb.getGuid();
            mode  = type;
            t     = generateTip(type);
            switch (type)
            {
            case Tips.AssotiationArrow:
            case Tips.DerivArrow:
            case Tips.AggregationArrow:
            case Tips.CompositionArrow:
                r = new BetweenLine(getPointForFirstBLock(), t.GetEndPointForLine(), BetweenLine.Type.Solid);
                break;

            case Tips.DependenceArrow:
            case Tips.ImplementationArrow:
                r = new BetweenLine(getPointForFirstBLock(), t.GetEndPointForLine(), BetweenLine.Type.Dotted);
                break;
            }
            updateEvents();
            fieldsSync();
            fb.addObserver(this);
            sb.addObserver(this);
        }
Beispiel #2
0
        private void DrawCanvasOnPreviewMouseMove(object sender, MouseEventArgs e)
        {
            Point now = e.GetPosition((UIElement)sender);

            if (!last.HasValue)
            {
                last = now;
            }
            if (picked == State.ClassBox || picked == State.InterfaceBox)
            {
                if (!drawCanvas.Children.Contains(rectangle))
                {
                    drawCanvas.Children.Add(rectangle);
                }
                Canvas.SetTop(rectangle, now.Y - rectangle.Height / 2);
                Canvas.SetLeft(rectangle, now.X - rectangle.Width / 2);
            }
            else if (e.LeftButton == MouseButtonState.Pressed)
            {
                UMLElement g = getPickedElement(now);
                if (g != null)
                {
                    isMoving = true;
                    g.move(new Point(now.X - last.Value.X, now.Y - last.Value.Y), drawCanvas);
                }
            }

            last = now;
        }
        public static void Execute(
			UMLDiagram owningDiagram, 
			UMLElement fromElement, 
			UMLElement toElement
		)
        {
            UMLAssociation assoc = UMLAssociation.CreateNew (owningDiagram, fromElement, toElement);
            if (assoc != null) { owningDiagram.UMLCanvas.AddElement (assoc); }
        }
Beispiel #4
0
        private void Canvas_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Point now = e.GetPosition((UIElement)sender);

            if (picked == State.ClassBox || picked == State.InterfaceBox)
            {
                drawCanvas.Children.Remove(rectangle);
                now = new Point(now.X - rectangle.Width / 2, now.Y - rectangle.Height / 2);
                UMLClassBox box = new UMLClassBox("SomeClass", (picked == State.ClassBox)? UMLClassBox.BoxType.Class: UMLClassBox.BoxType.Interface, now, classes);
                box.initMenu(this);
                box.draw(drawCanvas);
                elements.Add(box);
                setMode(State.Editing);
            }
            else if (picked == State.Editing && !isMoving && e.ChangedButton == MouseButton.Left && e.ChangedButton != MouseButton.Right)
            {
                UMLElement g = getPickedElement(now);
                if (g != null)
                {
                    g.setPicked(!g.getPicked());
                    return;
                }
            }
            else if (picked != State.Editing)
            {
                if (!doubleClick)
                {
                    doubleClick = true;
                    fblock      = getPickedElement(now);
                }
                else
                {
                    DependencyArrow.Tips s;
                    s           = convertTip();
                    doubleClick = false;
                    DependencyArrow line = new DependencyArrow(fblock, getPickedElement(now), s);
                    line.draw(drawCanvas);
                    elements.Add(line);
                    setMode(State.Editing);
                }
            }

            isMoving = false;
        }
Beispiel #5
0
        public void ContextMenuAddParent(object sender, RoutedEventArgs e)
        {
            if (!(sender is MenuItem))
            {
                return;
            }
            string          guid   = ((MenuItem)sender).Name.Substring(1, ((MenuItem)sender).Name.Length - 1).Replace("_", "-");
            DependencyArrow link   = null;
            UMLClassBox     fblock = null;
            UMLClassBox     sblock = null;

            foreach (var val in elements)
            {
                if (val is DependencyArrow && (val as DependencyArrow).getFGUID() == guid && ((val as DependencyArrow).GetTip() == DependencyArrow.Tips.ImplementationArrow || (val as DependencyArrow).GetTip() == DependencyArrow.Tips.DerivArrow))
                {
                    link = val as DependencyArrow;
                }
                else if (val is UMLClassBox && (val as UMLClassBox).getGuid() == guid)
                {
                    fblock = val as UMLClassBox;
                }
                if (link != null && fblock != null)
                {
                    break;
                }
            }

            if (link != null)
            {
                foreach (var umlElement in elements)
                {
                    if (umlElement is UMLClassBox && (umlElement as UMLClassBox).getGuid() == link.getSGUID())
                    {
                        sblock = umlElement as UMLClassBox;
                        break;
                    }
                }
            }
            ParentDependencyWindow dependencyWindow = new ParentDependencyWindow(fblock.getFieldsList(), fblock.getMethodsList());

            if (dependencyWindow.ShowDialog() != true)
            {
                return;
            }
            if (link != null)
            {
                elements.Remove(link);
                link.removeGraphicFromCanvas(drawCanvas);
            }
            UMLClassBox newbox = dependencyWindow.generateParent(fblock.GetCenterPoint(), classes);

            fblock.move(new Point(160, 0), drawCanvas);
            DependencyArrow arrow = new DependencyArrow(fblock, newbox, DependencyArrow.Tips.DerivArrow);

            arrow.draw(drawCanvas);
            newbox.draw(drawCanvas);
            newbox.beforeLoadSets(classes);
            newbox.initMenu(this);
            elements.Add(arrow);
            elements.Add(newbox);
            if (link != null)
            {
                DependencyArrow sArrow = new DependencyArrow(newbox, sblock, link.GetTip());
                sArrow.draw(drawCanvas);
                elements.Add(sArrow);
            }
            //TODO: удалять отдельно связи
        }