public PropertyGridAdorner(UIElement adornedElement) : base(adornedElement) { ownerElement = ((Element)adornedElement); ownerCanvas = (GridCanvas)ownerElement.OwnerCanvas; visualChildren = new VisualCollection(this); BuildPropertyGrid(); }
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); }
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; } }
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")); } }
public void RemoveLinksToTarget(Element target) { var links= GetIncomingLinks(target).ToArray(); foreach (Link l in links) { RemoveCurve(l.From); RemoveLink(l); } }
public void AddElement(Element element) { elementList.Add(element); Children.Add(element); element.OwnerCanvas = this; }
public ElementCaptionArgs(Element element, string oldCaption, string newCaption) : base(element) { OldCaption = oldCaption; NewCaption = newCaption; }
bool IsElementConnectedTo(Element source, Element target) { return linkList.Any(l => l.SourceElement == source && l.TargetElement == target); }
public IEnumerable<Link> GetOutgoingLinks(Element source) { return (from l in linkList where l.SourceElement == source select l); }
public IEnumerable<Link> GetIncomingLinks(Element target) { return (from l in linkList where l.TargetElement == target select l); }
public Element[] GetElementsDirectlyConnectedTo(Element source) { return (from e in elementList where IsElementConnectedTo(source, e) select e).ToArray(); }
/// <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; }
public Element[] GeIncomingConnectedElements(Element target) { return (from e in elementList where IsElementConnectedTo(e, target) select e).ToArray(); }
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)); }
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; }
bool HasConnections(Element element) { return linkList.Any(l => l.SourceElement == element || l.TargetElement == element); }
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; }
public ElementArgs(Element element) { Element = element; }
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; } }
public LinkArgs(Element source, Element target) { Source = source; Target = target; }
public void RemoveElement(Element element) { elementList.Remove(element); Children.Remove(element); OnElementRemoved(new ElementArgs(element)); }
public bool IsConnectionAllowedTo(ThumbPosition targetPosition, Element targetElement) { return Connections.Any(c => c.Value.TargetPosition == targetPosition && c.Value.TargetTypes.Contains(targetElement.GetType())); }
public void RemoveLinksToSource(Element source) { var links = GetOutgoingLinks(source).ToArray(); foreach (Link l in links) { RemoveCurve(l.From); RemoveLink(l); } }