public PointD GetLocation(IPort port, IPortLocationModelParameter locationParameter) { var modelParameter = locationParameter as PointPortLocationModelParameter; if (modelParameter == null) { throw new ArgumentException("parameter is not supported", "locationParameter"); } return(modelParameter.Location); }
/// <inheritdoc/> public PointD GetLocation(IPort port, IPortLocationModelParameter locationParameter) { var anchorParameter = locationParameter as AnchorParameter; if (anchorParameter != null) { return(anchorParameter.anchor.ToPointD()); } else { var pointAnchorParameter = locationParameter as PointAnchorParameter; return(pointAnchorParameter != null ? pointAnchorParameter.anchor : PointD.Origin); } }
/// <summary> /// Recalculates the coordinates provided by <paramref name="parameter"/>. /// </summary> /// <remarks> /// This has only an effect when <paramref name="parameter"/> is created by this model and the owner of /// <paramref name="port"/> has a <see cref="RotatableNodeStyleDecorator"/>. /// </remarks> public PointD GetLocation(IPort port, IPortLocationModelParameter parameter) { var param = ((RotatablePortLocationModelDecoratorParameter)parameter).Wrapped; var coreLocation = Wrapped.GetLocation(port, param); var ownerNode = port.Owner as INode; if (ownerNode == null) { return(coreLocation); } var angle = GetAngle(ownerNode); if (Math.Abs(angle) < Eps) { return(coreLocation); } var center = ownerNode.Layout.GetCenter(); var result = RotateAt(-angle, center, coreLocation); return(new PointD(result.X, result.Y)); }
/// <summary> /// Determines the actual absolute world location of the port for the given parameter. /// </summary> /// <param name="port">The port to determine the location for.</param> /// <param name="parameter">The parameter to use.</param> /// <returns>The calculated location of the port.</returns> public PointD GetLocation(IPort port, IPortLocationModelParameter parameter) { var modelParameter = parameter as MyNodePortLocationModelParameter; var ownerNode = port.Owner as INode; if (modelParameter != null && ownerNode != null) { //If we have an actual owner node and the parameter can be really used by this model, //we just calculate the correct location, based on the node's layout. var layout = ownerNode.Layout; switch (modelParameter.Location) { case PortLocation.Center: return(layout.GetCenter()); case PortLocation.North: return((layout.GetTopLeft() + layout.GetTopRight()) * 0.5d + new PointD(0, Inset)); case PortLocation.South: return((layout.GetBottomLeft() + layout.GetBottomRight()) * 0.5d + new PointD(0, -Inset)); case PortLocation.East: return((layout.GetTopRight() + layout.GetBottomRight()) * 0.5d + new PointD(-Inset, 0)); case PortLocation.West: return((layout.GetTopLeft() + layout.GetBottomLeft()) * 0.5d + new PointD(Inset, 0)); default: throw new ArgumentOutOfRangeException(); } } else { //No owner node (e.g. an edge port), or parameter mismatch - return (0,0) return(PointD.Origin); } }
/// <summary> /// Creates a new instance wrapping the given location model parameter. /// </summary> public RotatablePortLocationModelDecoratorParameter(IPortLocationModelParameter wrapped, RotatablePortLocationModelDecorator model) { this.wrapped = wrapped; this.model = model; }
/// <summary> /// Returns the lookup of the wrapped location model. /// </summary> public ILookup GetContext(IPort port, IPortLocationModelParameter parameter) { return(Wrapped.GetContext(port, parameter)); }
/// <summary> /// Wrapes a given parameter so it can be automatically rotated /// </summary> /// <remarks> /// The <paramref name="coreParameter"/> is assumed to provide coordinates for an unrotated owner. /// </remarks> public IPortLocationModelParameter CreateWrappingParameter(IPortLocationModelParameter coreParameter) { return(new RotatablePortLocationModelDecoratorParameter(coreParameter, this)); }
/// <summary> /// Does nothing since we don't want to change the port location. /// </summary> protected override void SetParameter(IGraph graph, IPort port, IPortLocationModelParameter newParameter) { // do nothing }
public ILookup GetContext(IPort label, IPortLocationModelParameter parameter) { return(Lookups.Empty); }
/// <inheritdoc/> public ILookup GetContext(IPort port, IPortLocationModelParameter locationParameter) { return(Lookups.Empty); }