public MouseElements(MouseElements prototype) { MouseStartElement = prototype.MouseStartElement; MouseMoveElement = prototype.MouseMoveElement; MouseStartOrigin = prototype.MouseStartOrigin; InteractiveElement = prototype.InteractiveElement; InteractiveOrigin = prototype.InteractiveOrigin; StartButton = prototype.StartButton; }
//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 } } } }
//Builds up a renderlist containing copies of the elements to be rendered in an action private RenderList CreateInteractiveRenderList(Point mousePoint) { RenderList actions = new RenderList(); PointF start = PointToDiagram(mStartPoint.X,mStartPoint.Y); PointF end = PointToDiagram(mousePoint.X,mousePoint.Y); IContainer container = this; //Prepare a new mouse elements structure MouseElements mouseElements = new MouseElements(CurrentMouseElements); //Set the correct container if (CurrentMouseElements.MouseStartElement != null) { container = CurrentMouseElements.MouseStartElement.Container; start.X -= container.Offset.X; start.Y -= container.Offset.Y; end.X -= container.Offset.X; end.Y -= container.Offset.Y; } //Add a line interactively if (Runtime.InteractiveMode == InteractiveMode.AddLine) { //Create new line Line line = Runtime.CreateLine(start,end); //Set temporary container and layer line.SetLayer(Layers.CurrentLayer); //Set line container line.SetContainer(container); line.DrawPath(); //Create action line Line newLine = (Line) line.Clone(); newLine.ActionElement = line; actions.Add(newLine); mMouseHandle = new Handle(HandleType.Origin); mMouseHandle.CanDock = true; //Set up mouse elements mouseElements.MouseStartElement = line; mouseElements.MouseStartOrigin = line.End; } //Add an connector interactively if (Runtime.InteractiveMode == InteractiveMode.AddConnector) { //Create new line Connector line = Runtime.CreateConnector(start,end); //Set temporary container and layer line.SetLayer(Layers.CurrentLayer); //Set line container line.SetContainer(container); line.Avoid = true; line.CalculateRoute(); line.DrawPath(); //Create action line Connector newLine = (Connector) line.Clone(); newLine.ActionElement = line; newLine.Avoid = true; actions.Add(newLine); mMouseHandle = new Handle(HandleType.Origin); mMouseHandle.CanDock = true; //Set up mouse elements mouseElements.MouseStartElement = line; mouseElements.MouseStartOrigin = line.End; } if (Runtime.InteractiveMode == InteractiveMode.AddComplexLine) { //Create new line ComplexLine line = Runtime.CreateComplexLine(start,end); //Set temporary container and layer line.SetLayer(Layers.CurrentLayer); //Set line container line.SetContainer(container); line.DrawPath(); //Create action line Line newLine = (ComplexLine) line.Clone(); newLine.ActionElement = line; actions.Add(newLine); mMouseHandle = new Handle(HandleType.Origin); mMouseHandle.CanDock = true; //Set up mouse elements mouseElements.MouseStartElement = line; mouseElements.MouseStartOrigin = line.End; } if (Runtime.InteractiveMode == InteractiveMode.AddCurve) { //Create new line Curve line = Runtime.CreateCurve(start,end); //Set temporary container and layer line.SetLayer(Layers.CurrentLayer); //Set line container line.SetContainer(container); line.DrawPath(); //Create action line Line newLine = (Curve) line.Clone(); newLine.ActionElement = line; actions.Add(newLine); mMouseHandle = new Handle(HandleType.Origin); mMouseHandle.CanDock = true; //Set up mouse elements mouseElements.MouseStartElement = line; mouseElements.MouseStartOrigin = line.End; } if (Runtime.InteractiveMode == InteractiveMode.AddShape) { SizeF size = new SizeF(end.X - start.X,end.Y - start.Y); Shape shape = Runtime.CreateShape(start,size); //Set temporary container and layer shape.SetLayer(Layers.CurrentLayer); //Set line container shape.SetContainer(container); //Create action shape Shape newShape = (Shape) shape.Clone(); newShape.ActionElement = shape; actions.Add(newShape); mMouseHandle = new Handle(HandleType.BottomRight); } if (Runtime.InteractiveMode == InteractiveMode.AddComplexShape) { SizeF size = new SizeF(end.X - start.X,end.Y - start.Y); ComplexShape shape = Runtime.CreateComplexShape(start,size); //Set temporary container and layer shape.SetLayer(Layers.CurrentLayer); //Set line container shape.SetContainer(container); //Create action shape ComplexShape newShape = (ComplexShape) shape.Clone(); newShape.ActionElement = shape; actions.Add(newShape); //Set the action shapes for the complex shape children foreach (SolidElement solid in newShape.Children.Values) { solid.ActionElement = shape.Children[solid.Key]; } mMouseHandle = new Handle(HandleType.BottomRight); } //Check for interactive docking if (Runtime.InteractiveMode == InteractiveMode.AddLine || Runtime.InteractiveMode == InteractiveMode.AddConnector || Runtime.InteractiveMode == InteractiveMode.AddComplexLine || Runtime.InteractiveMode == InteractiveMode.AddCurve) { foreach (Element element in actions) { if (element is Line) { Line line = (Line) element; Line action = (Line) line.ActionElement; //Set up the elements mouseElements.InteractiveElement = line; mouseElements.InteractiveOrigin = line.Start; mouseElements.MouseMoveElement = CurrentMouseElements.MouseMoveElement; //Check if start is shape if (CurrentMouseElements.MouseMoveElement is Shape && Runtime.CanDock(mouseElements)) { //line.Start.Shape = (Shape) CurrentMouseElements.MouseStartElement; action.Start.Shape = (Shape) CurrentMouseElements.MouseStartElement; } //Check if start is port if (CurrentMouseElements.MouseMoveElement is Port && Runtime.CanDock(mouseElements)) { //line.Start.Port = (Port) CurrentMouseElements.MouseStartElement; action.Start.Port = (Port) CurrentMouseElements.MouseStartElement; } } } } ConnectInteractiveElements(actions); //Set mouse elements SetMouseElements(mouseElements); return actions; }
protected virtual void SetMouseElements(Diagram.MouseElements elements) { mMouseElements = elements; }