public Origin(Port port) { SuspendEvents = true; Port = port; AllowMove = true; SuspendEvents = false; }
public Link(Port start,Port end) : base(start,end) { SuspendEvents = true; End.Marker = new Arrow(false); SuspendEvents = false; }
public ComplexLine(Port start,Port end): base(start,end) { mSegments = new Segments(); Segment segment = new Segment(Start,End); Segments.Add(segment); segment.SegmentInvalid += new EventHandler(segment_SegmentInvalid); AllowExpand = true; }
public Connector(Port start,Port end) : base(start,end) { SuspendEvents = true; Avoid = true; Padding = new SizeF(20,20); SmoothingMode = SmoothingMode.None; SuspendEvents = false; }
public Line(Port start,Port end) { SuspendEvents = true; AllowMove = true; DrawSelected = true; Start = new Origin(start); End = new Origin(end); Interaction = UserInteraction.BringToFront; Ports = new Elements(typeof(Port),"Port"); SuspendEvents = false; }
public virtual Port CreatePort(PortOrientation orientation) { Port port = new Port(orientation); OnCreateElement(port); return port; }
public virtual Line AddLine(string key, Port start, Port end) { Line line = Runtime.CreateLine(); line.Start.Port = start; line.End.Port = end; Runtime.ActiveContainer.Lines.Add(key,line); return line; }
public Curve(Port start,Port end): base(start,end) { mCurveType = CurveType.Spline; mTension = 0.5F; CreateControlPoints(); }
//Locate a port based on the orientation(side) of the parent and the percentage public virtual void LocatePort(Port port) { RectangleF shapeRect = TransformRectangle; PointF start = new PointF(); float ratio = port.Percent / 100; switch (port.Orientation) { case PortOrientation.Top: start = new PointF(shapeRect.X +(shapeRect.Width * ratio),shapeRect.Y-1); break; case PortOrientation.Bottom: start = new PointF(shapeRect.X +(shapeRect.Width * ratio),shapeRect.Y+shapeRect.Height+1); break; case PortOrientation.Left: start = new PointF(shapeRect.X-1,shapeRect.Y +(shapeRect.Height * ratio)); break; case PortOrientation.Right: start = new PointF(shapeRect.X + shapeRect.Width +1,shapeRect.Y +(shapeRect.Height * ratio)); break; default: break; } port.Validate = false; port.Location = Intercept(start); port.Validate = true; }
//Takes the port and validates its location against the shape's path public bool ValidatePortLocation(Port port,PointF location) { //Offset location to local co-ordinates and check outline location.X -= Rectangle.X; location.Y -= Rectangle.Y; return GetPathInternal().IsOutlineVisible(location,new Pen(Color.Black,1)); }
public virtual float GetPortPercentage(Port port,PointF location) { GetPortPercentages(); return port.Percent; }
public virtual Connector AddRecursiveLine(string key, Port start, Port end) { if (start.Parent != end.Parent) throw new ArgumentException("The start and end ports must belong to the same shape."); Connector line = Runtime.CreateConnector(); line.Start.Port = start; line.End.Port = end; Runtime.ActiveContainer.Lines.Add(key,line); return line; }
//Locate a port based on the percentage public override void LocatePort(Port port) { if (Points == null) return; //Work out total length of line PointF lastPoint = new Point(); float totalLength = 0; //Loop through and add each lenght to total foreach (PointF point in Points) { if (!lastPoint.IsEmpty) { if (point.X == lastPoint.X) { totalLength += Math.Abs(point.Y - lastPoint.Y); } else { totalLength += Math.Abs(point.X - lastPoint.X); } } lastPoint = point; } //Find position by float length = 0; float lengthPercent = totalLength * port.Percent / 100; PointF result = new PointF(); lastPoint = new PointF(); foreach (PointF point in Points) { if (!lastPoint.IsEmpty) { if (point.X == lastPoint.X) { length += Math.Abs(point.Y - lastPoint.Y); //check if we are in the right segment if (length > lengthPercent) { if (point.Y > lastPoint.Y) { result = new PointF(point.X, point.Y - (length - lengthPercent)); } else { result = new PointF(point.X, point.Y + (length - lengthPercent)); } break; } } else { length += Math.Abs(point.X - lastPoint.X); //check if we are in the right segment if (length > lengthPercent) { if (point.X > lastPoint.X) { result = new PointF(point.X - (length - lengthPercent),point.Y); } else { result = new PointF(point.X + (length - lengthPercent),point.Y); } break; } } } lastPoint = point; } port.Validate = false; port.Location = result; port.Validate = true; }
public virtual Connector AddConnector(Port start, Port end) { Connector line = Runtime.CreateConnector(); line.Start.Port = start; line.End.Port = end; Runtime.ActiveContainer.Lines.Add(Runtime.ActiveContainer.Lines.CreateKey(),line); return line; }
//Locate a port based on the percentage public override void LocatePort(Port port) { if (Points == null) return; //Work out total length of line PointF lastPoint = new Point(); double totalLength = 0; //Loop through and add each length to total foreach (PointF point in Points) { if (!lastPoint.IsEmpty) { RectangleF bounds = Geometry.CreateRectangle(point, lastPoint); totalLength += Geometry.DistancefromOrigin(new PointF(bounds.Width, bounds.Height)); } lastPoint = point; } //Find position by double length = 0; double lengthPercent = totalLength * port.Percent / 100; PointF result = new PointF(); lastPoint = new PointF(); foreach (PointF point in Points) { if (!lastPoint.IsEmpty) { double start = length; RectangleF bounds = Geometry.CreateRectangle(point, lastPoint); length += Geometry.DistancefromOrigin(new PointF(bounds.Width, bounds.Height)); //Check if we are in the right segment if (length > lengthPercent) { //Work out the degrees between the last points double rad = Geometry.GetAngle(lastPoint.X, lastPoint.Y, point.X, point.Y); //Now work out the sides from the angle and H double side1 = Math.Cos(rad) * (lengthPercent - start); double side2 = Math.Sin(rad) * (lengthPercent - start); result = new PointF(Convert.ToSingle(side1) + lastPoint.X, Convert.ToSingle(side2) + lastPoint.Y) ; break; } } lastPoint = point; } port.Validate = false; port.Location = result; port.Validate = true; }
public virtual PortOrientation GetPortOrientation(Port port,PointF location) { return Geometry.GetOrientation(location,Center,Rectangle); }
public virtual float GetPortPercentage(Port port,PointF location) { float ratio = 0; if (port.Orientation == PortOrientation.Top || port.Orientation == PortOrientation.Bottom) { ratio = (location.X-Rectangle.X) / (Rectangle.Right - Rectangle.Left); } else { ratio = (location.Y-Rectangle.Y) / (Rectangle.Bottom - Rectangle.Top); } return Convert.ToSingle(Math.Round(ratio * 100,1)); }
//Takes the port and validates its location against the shape's path public bool ValidatePortLocation(Port port,PointF location) { //Check for switch changes if (!port.AllowRotate) { PortOrientation orientation = Geometry.GetOrientation(location,Center,Rectangle); if (port.Orientation != orientation) return false; } //Offset location to local co-ordinates and check outline location.X -= Rectangle.X; location.Y -= Rectangle.Y; return TransformPath.IsOutlineVisible(location,new Pen(Color.Black,1)); }
public virtual Connector AddConnector(string key, Port start, Shape end) { Connector line = Runtime.CreateConnector(); line.Start.Port = start; line.End.Shape = end; Runtime.ActiveContainer.Lines.Add(key,line); return line; }
//Locate a port based on the percentage public virtual void LocatePort(Port port) { if (mPoints == null) return; PointF startPoint = (PointF) mPoints[0]; PointF endPoint = (PointF) mPoints[mPoints.Count-1]; PointF result = new PointF(); float ratio = 100 / port.Percent; float dx = (endPoint.X - startPoint.X) / ratio; float dy = (endPoint.Y - startPoint.Y) / ratio; result.X = startPoint.X + dx; result.Y = startPoint.Y + dy; port.Validate = false; port.Location = result; port.Validate = true; }
public Port(Port prototype): base(prototype) { SuspendEvents = true; Label = null; StencilItem = null; mAlignment = prototype.Alignment; mOffset = prototype.Offset; mAllowMove = prototype.AllowMove; mAllowRotate = prototype.AllowRotate; mDirection = prototype.Direction; mInteraction = prototype.Interaction; Label = null; mPortStyle = prototype.Style; Cursor = prototype.Cursor; mPercent = prototype.Percent; mOrientation = prototype.Orientation; //Needed for action mvoe mParent = prototype.Parent; SuspendEvents = false; }
//Always face up for now public virtual PortOrientation GetPortOrientation(Port port,PointF location) { return PortOrientation.Line; }