예제 #1
0
        public PropertyGridAdorner(UIElement adornedElement)
            : base(adornedElement)
        {
            ownerElement = ((Element)adornedElement);
            ownerCanvas = (GridCanvas)ownerElement.OwnerCanvas;
            visualChildren = new VisualCollection(this);

            BuildPropertyGrid();
        }
예제 #2
0
        public ConnectorAdorner(UIElement adornedElement, Element owner)
            : base(adornedElement)
        {
            ownerElement = owner;
            visualChildren = new VisualCollection(this);
            ownerCanvas = Global.WorkArea;

            // Call a helper method to initialize the Thumbs
            // with a customized cursors.
            BuildAdornerThumb(ref left, Cursors.Cross, ThumbPosition.Left);
            BuildAdornerThumb(ref right, Cursors.SizeNESW, ThumbPosition.Right);
            BuildAdornerThumb(ref top, Cursors.SizeNESW, ThumbPosition.Top);
            BuildAdornerThumb(ref bottom, Cursors.SizeNWSE, ThumbPosition.Bottom);
        }
예제 #3
0
        public void UpdateCurveTarget(string id, Element target, ThumbPosition thumbPosition)
        {
            var curves = Children.OfType<Path>();
            curves.Count().ToString();

            foreach (Path curve in Curves.Values.Where(curve => curve.Name.StartsWith(id)))
            {
                Point thumbLocation = target.GetCanvasThumbPosition(thumbPosition);
                PathGeometry curveGeometry = (PathGeometry)curve.Data;
                PathFigure curveFigure = curveGeometry.Figures[0];
                BezierSegment bezierSegment = (BezierSegment)curveFigure.Segments[0];
                bezierSegment.Point2 = ComputeBezierSegmentPoint(thumbPosition, thumbLocation);
                bezierSegment.Point3 = thumbLocation;
            }
        }
예제 #4
0
        public void UnhighlightConnectors(Element element, ThumbPosition sourcePosition)
        {
            if (!element.HasConnectionsAllowedFrom(sourcePosition))
                return;

            var connectors = (from e in UnconnectedElements
                              let c = element.Connections[sourcePosition]
                              where c.TargetTypes.Contains(e.GetType())
                              select new { Element = e, ThumbPosition = c.TargetPosition });
            foreach (var connector in connectors)
            {
                connector.Element.CircleAdorner.SetBackground(connector.ThumbPosition,
                                                              (SolidColorBrush)FindResource("ConnectorUnconnected"));
            }
        }
예제 #5
0
 public void RemoveLinksToTarget(Element target)
 {
     var links= GetIncomingLinks(target).ToArray();
     foreach (Link l in links)
     {
         RemoveCurve(l.From);
         RemoveLink(l);
     }
 }
예제 #6
0
 public void AddElement(Element element)
 {
     elementList.Add(element);
     Children.Add(element);
     element.OwnerCanvas = this;
 }
예제 #7
0
 public ElementCaptionArgs(Element element, string oldCaption, string newCaption)
     : base(element)
 {
     OldCaption = oldCaption;
     NewCaption = newCaption;
 }
예제 #8
0
 bool IsElementConnectedTo(Element source, Element target)
 {
     return linkList.Any(l => l.SourceElement == source && l.TargetElement == target);
 }
예제 #9
0
 public IEnumerable<Link> GetOutgoingLinks(Element source)
 {
     return (from l in linkList where l.SourceElement == source select l);
 }
예제 #10
0
 public IEnumerable<Link> GetIncomingLinks(Element target)
 {
     return (from l in linkList where l.TargetElement == target select l);
 }
예제 #11
0
 public Element[] GetElementsDirectlyConnectedTo(Element source)
 {
     return (from e in elementList
             where IsElementConnectedTo(source, e)
             select e).ToArray();
 }
예제 #12
0
        /// <summary>
        /// Restituisce gli elementi connessi all'elemento source tramite un elemento connector.
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public Element[] GetElementsConnectedTo(Element source)
        {
            Element[] elements = GetElementsDirectlyConnectedTo(source);
            var connectors = from ce in elements.OfType<Connector>()
                             select ce;
            List<Element> elementList = new List<Element>();
            elementList.AddRange(elements);

            if (connectors.Count() > 0)
            {

                foreach (Connector connector in connectors)
                {
                    elementList.AddRange(GetElementsConnectedTo(connector));
                }
                return elementList.ToArray();
            }
            else
                return elements;
        }
예제 #13
0
 public Element[] GeIncomingConnectedElements(Element target)
 {
     return (from e in elementList
             where IsElementConnectedTo(e, target)
             select e).ToArray();
 }
예제 #14
0
        public void EstablishLink(string curveId, Element source, ThumbPosition sourcePosition, Element target, ThumbPosition targetPosition)
        {
            Link sourceLink = new Link(source, sourcePosition, target, targetPosition, true);

            source.SetLink(sourcePosition, sourceLink);
            linkList.Add(sourceLink);

            Path curve = Curves.Values.First(c => c.Name == curveId + "_i");
            curve.Stroke = (Brush)FindResource("ConnectedLink");

            source.CircleAdorner.SetBackground(sourcePosition, Brushes.LightGreen);
            target.CircleAdorner.SetBackground(targetPosition, Brushes.LightGreen);

            OnLinkEstablished(new LinkArgs(source, target));
        }
예제 #15
0
        Element ElementNearestToPoint(Point position, Element caller, out double minDistance, out ThumbPosition nearestThumbPosition)
        {
            minDistance = double.PositiveInfinity;
            Element hitElement = null;
            nearestThumbPosition = ThumbPosition.NotSet;

            foreach (Element element in UnconnectedElements)
            {
                if(element == caller) continue;

                foreach (ThumbPosition thumbPosition in element.AvailableIncomingConnectors)
                {
                    Point elementLocation = element.GetCanvasThumbPosition(thumbPosition);
                    double distance = position.Distance(elementLocation);
                    if(distance < minDistance)
                    {
                        minDistance = distance;
                        hitElement = element;
                        nearestThumbPosition = thumbPosition;
                    }
                }
            }

            return hitElement;
        }
예제 #16
0
 bool HasConnections(Element element)
 {
     return linkList.Any(l => l.SourceElement == element || l.TargetElement == element);
 }
예제 #17
0
        public bool HandleCollisions(Point position, Element caller, ThumbPosition sourcePosition, out Element targetElement, out ThumbPosition targetPosition)
        {
            double distance;
            targetElement = ElementNearestToPoint(position, caller, out distance, out targetPosition);

            if (Math.Abs(distance)<= 20 && (caller.IsConnectionAllowedTo(targetPosition, targetElement)))
            {
                targetElement.CircleAdorner.SetBackground(targetPosition, (SolidColorBrush)FindResource("ConnectorAvailable"));
                LinkCurve(caller.GetLink(sourcePosition).From,
                    caller, sourcePosition, targetElement, targetPosition);
                return true;
            }
            return false;
        }
예제 #18
0
 public ElementArgs(Element element)
 {
     Element = element;
 }
예제 #19
0
        public void LinkCurve(string curveId, Element source, ThumbPosition sourcePosition, Element target, ThumbPosition targetPosition)
        {
            foreach (Path curve in Curves.Values.Where(curve => curve.Name.StartsWith(curveId)))
            {
                Point thumbLocation = target.GetCanvasThumbPosition(targetPosition);
                PathGeometry curveGeometry = (PathGeometry)curve.Data;
                PathFigure curveFigure = curveGeometry.Figures[0];
                BezierSegment bezierSegment = (BezierSegment)curveFigure.Segments[0];

                bezierSegment.Point2 = ComputeBezierSegmentPoint(targetPosition, thumbLocation);
                bezierSegment.Point3 = thumbLocation;
            }
        }
예제 #20
0
 public LinkArgs(Element source, Element target)
 {
     Source = source;
     Target = target;
 }
예제 #21
0
 public void RemoveElement(Element element)
 {
     elementList.Remove(element);
     Children.Remove(element);
     OnElementRemoved(new ElementArgs(element));
 }
예제 #22
0
 public bool IsConnectionAllowedTo(ThumbPosition targetPosition, Element targetElement)
 {
     return Connections.Any(c =>
                             c.Value.TargetPosition == targetPosition && c.Value.TargetTypes.Contains(targetElement.GetType()));
 }
예제 #23
0
 public void RemoveLinksToSource(Element source)
 {
     var links = GetOutgoingLinks(source).ToArray();
     foreach (Link l in links)
     {
         RemoveCurve(l.From);
         RemoveLink(l);
     }
 }