Ejemplo n.º 1
0
        public PropertyGridAdorner(UIElement adornedElement)
            : base(adornedElement)
        {
            ownerElement = ((Element)adornedElement);
            ownerCanvas = (GridCanvas)ownerElement.OwnerCanvas;
            visualChildren = new VisualCollection(this);

            BuildPropertyGrid();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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"));
            }
        }
Ejemplo n.º 5
0
 public void RemoveLinksToTarget(Element target)
 {
     var links= GetIncomingLinks(target).ToArray();
     foreach (Link l in links)
     {
         RemoveCurve(l.From);
         RemoveLink(l);
     }
 }
Ejemplo n.º 6
0
 public void AddElement(Element element)
 {
     elementList.Add(element);
     Children.Add(element);
     element.OwnerCanvas = this;
 }
Ejemplo n.º 7
0
 public ElementCaptionArgs(Element element, string oldCaption, string newCaption)
     : base(element)
 {
     OldCaption = oldCaption;
     NewCaption = newCaption;
 }
Ejemplo n.º 8
0
 bool IsElementConnectedTo(Element source, Element target)
 {
     return linkList.Any(l => l.SourceElement == source && l.TargetElement == target);
 }
Ejemplo n.º 9
0
 public IEnumerable<Link> GetOutgoingLinks(Element source)
 {
     return (from l in linkList where l.SourceElement == source select l);
 }
Ejemplo n.º 10
0
 public IEnumerable<Link> GetIncomingLinks(Element target)
 {
     return (from l in linkList where l.TargetElement == target select l);
 }
Ejemplo n.º 11
0
 public Element[] GetElementsDirectlyConnectedTo(Element source)
 {
     return (from e in elementList
             where IsElementConnectedTo(source, e)
             select e).ToArray();
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 13
0
 public Element[] GeIncomingConnectedElements(Element target)
 {
     return (from e in elementList
             where IsElementConnectedTo(e, target)
             select e).ToArray();
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 16
0
 bool HasConnections(Element element)
 {
     return linkList.Any(l => l.SourceElement == element || l.TargetElement == element);
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 18
0
 public ElementArgs(Element element)
 {
     Element = element;
 }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 20
0
 public LinkArgs(Element source, Element target)
 {
     Source = source;
     Target = target;
 }
Ejemplo n.º 21
0
 public void RemoveElement(Element element)
 {
     elementList.Remove(element);
     Children.Remove(element);
     OnElementRemoved(new ElementArgs(element));
 }
Ejemplo n.º 22
0
 public bool IsConnectionAllowedTo(ThumbPosition targetPosition, Element targetElement)
 {
     return Connections.Any(c =>
                             c.Value.TargetPosition == targetPosition && c.Value.TargetTypes.Contains(targetElement.GetType()));
 }
Ejemplo n.º 23
0
 public void RemoveLinksToSource(Element source)
 {
     var links = GetOutgoingLinks(source).ToArray();
     foreach (Link l in links)
     {
         RemoveCurve(l.From);
         RemoveLink(l);
     }
 }