public MouseElements(MouseElements prototype) { MouseStartElement = prototype.MouseStartElement; MouseMoveElement = prototype.MouseMoveElement; MouseStartOrigin = prototype.MouseStartOrigin; InteractiveElement = prototype.InteractiveElement; InteractiveOrigin = prototype.InteractiveOrigin; StartButton = prototype.StartButton; }
public Line(Shape start,Shape 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; }
//Constructors public Line() { SuspendEvents = true; AllowMove = true; DrawSelected = true; Start = new Origin(); End = new Origin(); Interaction = UserInteraction.BringToFront; SmoothingMode = SmoothingMode.HighQuality; Ports = new Elements(typeof(Port),"Port"); SuspendEvents = false; }
public Line(Line prototype): base(prototype) { mAllowMove = prototype.AllowMove; mLineJoin = prototype.LineJoin; mDrawSelected = prototype.DrawSelected; mInteraction = prototype.Interaction; //Set up new origins Start = new Origin(prototype.FirstPoint); End = new Origin(prototype.LastPoint); Start.Marker = prototype.Start.Marker; End.Marker = prototype.End.Marker; mPoints = (ArrayList) prototype.Points.Clone(); //Copy ports Ports = new Elements(typeof(Port),"Port"); foreach (Port port in prototype.Ports.Values) { Port clone = (Port) port.Clone(); Ports.Add(port.Key,clone); clone.SuspendValidation(); clone.Location = port.Location; clone.ResumeValidation(); } if (prototype.Animation != null) mAnimation = (Animation) prototype.Animation.Clone(); DrawPath(); }
//Returns the location if not docked, or the center if docked protected PointF GetSourceLocation(Origin source) { PointF sourceLocation; //Set up the source location (point,shape center, or port center) if (source.Shape == null && source.Port == null) { sourceLocation = source.Location; } else { sourceLocation = (source.Shape != null) ? source.Shape.Center : source.Port.Center; } return sourceLocation; }
//Returns the end point of a line depending on the starting shape and location protected internal PointF GetOriginLocation(Origin target,Origin source) { if (target.Shape == null && target.Port == null) return target.Location; //Set up location from source location, shape or marker SolidElement targetElement; PointF sourceLocation; //Set up the target element (shape or port) targetElement = (target.Shape != null) ? (SolidElement) target.Shape : (SolidElement) target.Port; sourceLocation = GetSourceLocation(source); //Adjust the source location for different containers if (source.DockedElement != null && source.DockedElement.Container != targetElement.Container) { if (source.DockedElement is Group) { IContainer container = (IContainer) source.DockedElement; sourceLocation = new PointF(sourceLocation.X - container.Offset.X,sourceLocation.Y - container.Offset.Y); } if (target.DockedElement is Group) { IContainer container = (IContainer) target.DockedElement; sourceLocation = new PointF(sourceLocation.X + container.Offset.X,sourceLocation.Y + container.Offset.Y); } } //Get the intercept PointF result = targetElement.Intercept(sourceLocation); //Readjust the source location for different containers if (source.DockedElement != null && source.DockedElement.Container != targetElement.Container) { if (target.DockedElement is Group) { IContainer container = (IContainer) target.DockedElement; result = new PointF(result.X - container.Offset.X,result.Y - container.Offset.Y); } } return result; }
public Segment(Origin start, Origin end) { SetStart(start); SetEnd(end); }
//Returns the end point of a line offset by the padding and orientation private PointF GetOriginOffset(Origin target,Origin source) { //If no port or shape for the origin then just return the location if (target.Shape == null && target.Port == null) { return target.Location; } PointF location = new PointF(); PortOrientation orientation; RectangleF rect = target.DockedElement.Rectangle; //If the target is a port, returns a point based only on the target if (target.Port != null) { location = target.Port.Location; orientation = target.Port.Orientation; //Move to edge of rectangle of shape (eg for parallelgram port problem) switch (orientation) { case PortOrientation.Top: location = new PointF(location.X,rect.Y); break; case PortOrientation.Bottom: location = new PointF(location.X,rect.Bottom); break; case PortOrientation.Left : location = new PointF(rect.X,location.Y); break; case PortOrientation.Right : location = new PointF(rect.Right,location.Y); break; } } //Work out starting point if a shape else { PointF center = target.Shape.Center; //Calculate the orientation based on orientation between the source and the target //The source center and target center is used orientation = Geometry.GetOrientation(GetSourceLocation(source),target.Shape.Center,target.Shape.Rectangle); switch (orientation) { case PortOrientation.Top: location = new PointF(center.X,rect.Y); break; case PortOrientation.Bottom: location = new PointF(center.X,rect.Bottom); break; case PortOrientation.Left : location = new PointF(rect.X,center.Y); break; case PortOrientation.Right : location = new PointF(rect.Right,center.Y); break; } } //Adjust the location to be orthogonal eg left,right,top,bottom depending on the orientation float width = Padding.Width +1 ; float height = Padding.Height + 1; switch (orientation) { case PortOrientation.Top: location.Y -= height; break; case PortOrientation.Bottom: location.Y += height; break; case PortOrientation.Left : location.X -= width; break; case PortOrientation.Right : location.X += width; break; } return location; }
//Methods protected internal void SetStart(Origin value) { mStart = value; }
protected internal void SetEnd(Origin value) { mEnd = value; }
//Reconnects an origin by adding an additional line point to a connector or extending an existing one private void ConnectOrigin(Origin origin) { if (Points == null) { return; } if (Points.Count < 2) { return; } if (origin.Shape == null && origin.Port == null) { return; } PointF source; PointF previous; PointF intercept; //Get the source if (origin == Start) { source = (PointF)Points[0]; previous = (PointF)Points[1]; } else { source = (PointF)Points[Points.Count - 1]; previous = (PointF)Points[Points.Count - 2]; } //Get the shape intercept point if (origin.Shape != null) { intercept = origin.Shape.Intercept(source); } //Get port intercept else { intercept = origin.Port.Intercept(source); } //Make sure that the intercept is orthogonal intercept = CheckOrthogonalIntercept(source, intercept); //If the intercept is in line with the previous then update if (intercept.X == previous.X || intercept.Y == previous.Y) { if (origin == Start) { Points[0] = intercept; } else { Points[Points.Count - 1] = intercept; } } //Else add a new point else { if (origin == Start) { Points.Insert(0, intercept); } else { Points.Add(intercept); } } }
//Returns the end point of a line offset by the padding and orientation private PointF GetOriginOffset(Origin target, Origin source) { //If no port or shape for the origin then just return the location if (target.Shape == null && target.Port == null) { return(target.Location); } PointF location = new PointF(); PortOrientation orientation; RectangleF rect = target.DockedElement.Rectangle; //If the target is a port, returns a point based only on the target if (target.Port != null) { location = target.Port.Location; orientation = target.Port.Orientation; //Move to edge of rectangle of shape (eg for parallelgram port problem) switch (orientation) { case PortOrientation.Top: location = new PointF(location.X, rect.Y); break; case PortOrientation.Bottom: location = new PointF(location.X, rect.Bottom); break; case PortOrientation.Left: location = new PointF(rect.X, location.Y); break; case PortOrientation.Right: location = new PointF(rect.Right, location.Y); break; } } //Work out starting point if a shape else { PointF center = target.Shape.Center; //Calculate the orientation based on orientation between the source and the target //The source center and target center is used orientation = Geometry.GetOrientation(GetSourceLocation(source), target.Shape.Center, target.Shape.Rectangle); switch (orientation) { case PortOrientation.Top: location = new PointF(center.X, rect.Y); break; case PortOrientation.Bottom: location = new PointF(center.X, rect.Bottom); break; case PortOrientation.Left: location = new PointF(rect.X, center.Y); break; case PortOrientation.Right: location = new PointF(rect.Right, center.Y); break; } } //Adjust the location to be orthogonal eg left,right,top,bottom depending on the orientation float width = Padding.Width + 1; float height = Padding.Height + 1; switch (orientation) { case PortOrientation.Top: location.Y -= height; break; case PortOrientation.Bottom: location.Y += height; break; case PortOrientation.Left: location.X -= width; break; case PortOrientation.Right: location.X += width; break; } return(location); }
//Reconnects an origin by adding an additional line point to a connector or extending an existing one private void ConnectOrigin(Origin origin) { if (Points == null) return; if (Points.Count < 2) return; if (origin.Shape == null && origin.Port == null) return; PointF source; PointF previous; PointF intercept; //Get the source if (origin == Start) { source = (PointF) Points[0]; previous = (PointF) Points[1]; } else { source = (PointF) Points[Points.Count-1] ; previous = (PointF) Points[Points.Count-2] ; } //Get the shape intercept point if (origin.Shape != null) { intercept = origin.Shape.Intercept(source); } //Get port intercept else { intercept = origin.Port.Intercept(source); } //Make sure that the intercept is orthogonal intercept = CheckOrthogonalIntercept(source,intercept); //If the intercept is in line with the previous then update if (intercept.X == previous.X || intercept.Y == previous.Y) { if (origin == Start) { Points[0] = intercept; } else { Points[Points.Count-1] = intercept; } } //Else add a new point else { if (origin == Start) { Points.Insert(0,intercept); } else { Points.Add(intercept); } } }
public void Clear() { MouseStartElement = null; MouseMoveElement = null; MouseStartOrigin = null; InteractiveElement = null; InteractiveOrigin = null; StartButton = MouseButtons.None; }
//Methods public virtual Segment AddSegment(int position, Origin origin) { //Valid the position if (position < 1) throw new ArgumentException("Position must be greater than zero.","position"); if (position > Segments.Count) throw new ArgumentException("Position cannot be greater than the total number of segments.","position"); if (origin == null) throw new ArgumentNullException("origin","Origin may not be null."); //Create new segment Segment segment = new Segment(origin,Segments[position-1].End); //Set the previous end to the new origin Segments[position-1].SetEnd(origin); Segments.Insert(position,segment); origin.OriginInvalid +=new EventHandler(Origin_OriginInvalid); segment.SegmentInvalid += new EventHandler(segment_SegmentInvalid); origin.SetLine(this); DrawPath(); OnElementInvalid(); return segment; }
//Loop through and scale the elements in the action renderlist protected virtual void ScaleElements() { //Calculate the percentage scale float dx = (mLastPoint.X - mStartPoint.X) * Render.ZoomFactor; //distance cursor has moved float dy = (mLastPoint.Y - mStartPoint.Y) * Render.ZoomFactor; float sx = 1; //scale float sy = 1; float mx = 0; //movement as a result of scale float my = 0; foreach (Element element in RenderDesign.Actions) { if (element.Visible) { //Scale shapes if (element is Shape) { Shape shape = (Shape) element; //a clone of the original shape, contained in the list Shape actionshape = (Shape) shape.ActionElement; //the actual shape being moved if (actionshape.AllowScale) { if (Route != null) Route.Reform(); PointF saveLocation = shape.Location; SizeF saveSize = shape.Size; //Reset the ports foreach (Port port in shape.Ports.Values) { Port actionPort = (Port) actionshape.Ports[port.Key]; port.SuspendValidation(); port.Location = actionPort.Location; port.ResumeValidation(); } //Reset shape location and size shape.Location = actionshape.Location; //reset location shape.SetSize(actionshape.Size,actionshape.InternalRectangle); //reset to original size //Reset children of a complex shape if (shape is ComplexShape) { ComplexShape complex = (ComplexShape) shape; foreach (SolidElement solid in complex.Children.Values) { SolidElement actionSolid = (SolidElement) solid.ActionElement; solid.Location = actionSolid.Location; //reset location solid.SetSize(actionSolid.Size,actionSolid.InternalRectangle); //reset to original size } } //Scale Right x if (mMouseHandle.Type == HandleType.TopRight || mMouseHandle.Type == HandleType.Right || mMouseHandle.Type == HandleType.BottomRight) { sx = ((dx) / shape.ActionElement.Rectangle.Width)+1; } //Scale Bottom y if (mMouseHandle.Type == HandleType.BottomLeft || mMouseHandle.Type == HandleType.Bottom || mMouseHandle.Type == HandleType.BottomRight) { sy = ((dy) /shape.ActionElement.Rectangle.Height)+1; } //Scale Left x if (mMouseHandle.Type == HandleType.TopLeft || mMouseHandle.Type == HandleType.Left || mMouseHandle.Type == HandleType.BottomLeft) { sx = ((-dx) / shape.ActionElement.Rectangle.Width)+1; mx = dx; if (shape.Rectangle.Width * sx < shape.MinimumSize.Width) mx = (shape.ActionElement.Rectangle.Width - shape.MinimumSize.Width); if (shape.Rectangle.Width * sx > shape.MaximumSize.Width) mx = (shape.ActionElement.Rectangle.Width - shape.MaximumSize.Width); } //Scale Top y if (mMouseHandle.Type == HandleType.TopLeft || mMouseHandle.Type == HandleType.Top || mMouseHandle.Type == HandleType.TopRight) { sy = ((-dy) /shape.ActionElement.Rectangle.Height)+1; my = dy; if (shape.Rectangle.Height * sy < shape.MinimumSize.Height) my = (shape.ActionElement.Rectangle.Height - shape.MinimumSize.Height); if (shape.Rectangle.Height * sy > shape.MaximumSize.Height) my = (shape.ActionElement.Rectangle.Height - shape.MaximumSize.Height); } shape.Scale(sx,sy,mx,my,ModifierKeys == Keys.Shift || shape.KeepAspect); //Restore shape bounds if not correct //if (!CheckBounds(element, element.Container)) if (!CheckBounds(shape, shape.Container)) { shape.Location = saveLocation; shape.Size = saveSize; } } } //Move line origins if (element is Line) { if (element is ComplexLine) { ComplexLine line = (ComplexLine) element; ComplexLine actionline = (ComplexLine) line.ActionElement; Segment segment; Segment actionSegment; if (mMouseHandle.Type == HandleType.Origin) { for (int i2 = 0; i2 < line.Segments.Count; i2++) { segment = line.Segments[i2]; actionSegment = actionline.Segments[i2]; if (actionSegment.Start == CurrentMouseElements.MouseStartOrigin && actionSegment.Start.AllowMove) { if (CheckBounds(actionSegment.Start.Location, dx, dy, actionline.Container)) { segment.Start.SuspendEvents = true; segment.Start.Location = (PointF) actionline.Points[i2]; //Resets the location segment.Start.Move(dx,dy); segment.Start.SuspendEvents = false; line.DrawPath(); } break; } if (actionSegment.End == CurrentMouseElements.MouseStartOrigin && actionSegment.End.AllowMove) { if (CheckBounds(actionSegment.End.Location, dx, dy, actionline.Container)) { segment.End.SuspendEvents = true; segment.End.Location = (PointF) actionline.Points[i2+1]; //Resets the location segment.End.Move(dx,dy); segment.End.SuspendEvents = false; line.DrawPath(); } break; } } } //Add the segment and reset the handle to an origin handle if (mMouseHandle.Type == HandleType.Expand) { //Find the segment ExpandHandle expand = (ExpandHandle) mMouseHandle; //Get origin locations PointF start = line.GetOriginLocation(expand.Segment.Start, expand.Segment.End); PointF end = line.GetOriginLocation(expand.Segment.End, expand.Segment.Start); Origin origin = new Origin(new PointF(start.X + ((end.X - start.X) / 2),start.Y + ((end.Y - start.Y) / 2))); Origin actionOrigin = new Origin(new PointF(origin.Location.X, origin.Location.Y)); line.AddSegment(expand.Index + 1, origin ); actionline.AddSegment(expand.Index + 1, actionOrigin); mMouseHandle = new Handle(HandleType.Origin); //Set up mouse elements MouseElements mouseElements = new MouseElements(CurrentMouseElements); mouseElements.MouseStartOrigin = actionOrigin; SetMouseElements(mouseElements); } } else if (element is Connector) { Connector line = (Connector) element; Connector actionLine = (Connector) element.ActionElement; //Move start or end of connector if (mMouseHandle.Type == HandleType.Origin) { Origin origin = null; PointF point = new PointF(); //Get the origin point if (actionLine.Start == CurrentMouseElements.MouseStartOrigin && actionLine.Start.AllowMove) { origin = line.Start; point = (PointF) actionLine.Points[0]; } if (actionLine.End == CurrentMouseElements.MouseStartOrigin && actionLine.End.AllowMove) { origin = line.End; point = (PointF) actionLine.Points[actionLine.Points.Count-1]; } if (origin != null) { if (CheckBounds(point, dx, dy, actionLine.Container)) { //Offset the origin point origin.Location = new PointF(point.X + dx, point.Y + dy); //Set to shape if current mouse element is shape if (IsModelDockable() && Runtime.CanDock(CurrentMouseElements)) { if (CurrentMouseElements.MouseMoveElement is Shape) { origin.Shape = (Shape) CurrentMouseElements.MouseMoveElement; } else if (CurrentMouseElements.MouseMoveElement is Port) { origin.Port = (Port) CurrentMouseElements.MouseMoveElement; } } line.CalculateRoute(); } } } //Move a connector segment else if (mMouseHandle.Type == HandleType.UpDown || mMouseHandle.Type == HandleType.LeftRight) { ConnectorHandle handle = (ConnectorHandle) mMouseHandle; if (handle != null) { PointF start = (PointF) actionLine.Points[handle.Index -1]; PointF end = (PointF) actionLine.Points[handle.Index]; //Move the two segment points and place them back in the correct place if (mMouseHandle.Type == HandleType.UpDown) { if (CheckBounds(start, 0, dy, actionLine.Container) && CheckBounds(end, 0, dy, actionLine.Container)) { start.Y += dy; end.Y += dy; //Update the line line.Points[handle.Index -1] = start; line.Points[handle.Index] = end; } } else if (mMouseHandle.Type == HandleType.LeftRight) { if (CheckBounds(end, dx, 0, actionLine.Container) && CheckBounds(end, dx, 0, actionLine.Container)) { start.X += dx; end.X += dx; //Update the line line.Points[handle.Index -1] = start; line.Points[handle.Index] = end; } } } } } else if (element is Curve) { Curve curve = (Curve) element; Curve actionCurve = (Curve) curve.ActionElement; if (CurrentMouseElements.MouseStartOrigin == actionCurve.Start && actionCurve.Start.AllowMove) { if (CheckBounds(actionCurve.FirstPoint, dx, dy, actionCurve.Container)) { curve.Start.SuspendEvents = true; curve.Start.Location = actionCurve.FirstPoint; //Resets the location curve.Start.Move(dx,dy); curve.Start.SuspendEvents = false; } } else if (CurrentMouseElements.MouseStartOrigin == actionCurve.End && actionCurve.End.AllowMove) { if (CheckBounds(actionCurve.LastPoint, dx, dy, actionCurve.Container)) { curve.End.SuspendEvents = true; curve.End.Location = actionCurve.LastPoint; //Resets the location curve.End.Move(dx,dy); curve.End.SuspendEvents = false; } } else { //Move control points int index = 0; foreach (PointF point in actionCurve.ControlPoints) { PointF location = new PointF(point.X - actionCurve.Rectangle.X - actionCurve.Container.Offset.X, point.Y - actionCurve.Rectangle.Y - actionCurve.Container.Offset.Y); if (mMouseHandle != null && mMouseHandle.Path != null && mMouseHandle.Path.IsVisible(location)) { curve.ControlPoints[index] = new PointF(actionCurve.ControlPoints[index].X + dx, actionCurve.ControlPoints[index].Y + dy); break; } index ++; } } } else if (element is Line) { Line line = (Line) element; Line actionline = (Line) line.ActionElement; if (CurrentMouseElements.MouseStartOrigin == actionline.Start && actionline.Start.AllowMove) { if (CheckBounds(actionline.FirstPoint, dx, dy, actionline.Container)) { line.Start.SuspendEvents = true; line.Start.Location = actionline.FirstPoint; //Resets the location line.Start.Move(dx,dy); line.Start.SuspendEvents = false; } } if (CurrentMouseElements.MouseStartOrigin == actionline.End && actionline.End.AllowMove) { if (CheckBounds(actionline.LastPoint, dx, dy, actionline.Container)) { line.End.SuspendEvents = true; line.End.Location = actionline.LastPoint; //Resets the location line.End.Move(dx,dy); line.End.SuspendEvents = false; } } } //Update docking if (CurrentMouseElements.MouseMoveElement != null && IsModelDockable() && Runtime.CanDock(CurrentMouseElements)) { Line line = (Line) element; Line actionline = (Line) line.ActionElement; if (CurrentMouseElements.MouseMoveElement is Shape) { if (CurrentMouseElements.MouseStartOrigin == actionline.Start && actionline.Start.AllowMove) { line.Start.SuspendEvents = true; line.Start.Shape = (Shape) CurrentMouseElements.MouseMoveElement; line.Start.SuspendEvents = false; } if (CurrentMouseElements.MouseStartOrigin == actionline.End && actionline.End.AllowMove) { line.End.SuspendEvents = true; line.End.Shape = (Shape) CurrentMouseElements.MouseMoveElement; line.End.SuspendEvents = false; } } else if (CurrentMouseElements.MouseMoveElement is Port) { if (CurrentMouseElements.MouseStartOrigin == actionline.Start && actionline.Start.AllowMove) { line.Start.SuspendEvents = true; line.Start.Port = (Port) CurrentMouseElements.MouseMoveElement; line.Start.SuspendEvents = false; } if (CurrentMouseElements.MouseStartOrigin == actionline.End && actionline.End.AllowMove) { line.End.SuspendEvents = true; line.End.Port = (Port) CurrentMouseElements.MouseMoveElement; line.End.SuspendEvents = false; } } } Line clone = (Line) element; clone.DrawPath(); //Update the action path } } } }
//Returns the end point of a line depending on the starting shape and location protected PointF GetOriginLocation(Origin target,Origin source) { if (target.Shape == null && target.Port == null) return target.Location; //Set up location from source location, shape or marker SolidElement targetElement; PointF sourceLocation; PortOrientation orientation; //Set up the target element (shape or port) targetElement = (target.Shape != null) ? (SolidElement) target.Shape : (SolidElement) target.Port; sourceLocation = GetOriginOffset(target,source); //Intercept may return value that isnt orthogonal PointF intercept = targetElement.Intercept(sourceLocation); return CheckOrthogonalIntercept(sourceLocation, intercept); }