Пример #1
0
		//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
					}
				}
			}
		}
Пример #2
0
		protected override void OnMouseMove(MouseEventArgs e)
		{
			//Check if in dragscroll and if so exit
			if (mSyncTimer) return;

			Point mousePoint = new Point(e.X,e.Y);

			if (IsAlignable(CurrentMouseElements.MouseStartElement)) mousePoint = AlignMouseCoordinates(e);

			//Check if handles mouse
			if (!mHandled && CurrentMouseElements.MouseMoveElement is IMouseEvents) mHandled = ((IMouseEvents) CurrentMouseElements.MouseMoveElement).OnMouseMove(e);

            if (CurrentMouseElements.StartButton != MouseButtons.None && CurrentMouseElements.StartButton != e.Button)
            {
                base.OnMouseMove(e);
                return;
            }

			if (!mHandled)
			{
				//Set the cursor
				if (e.Button == MouseButtons.None)
				{
					if (CurrentMouseElements.MouseMoveElement == null)
					{
						Cursor = Component.Instance.GetCursor(HandleType.None);
						CancelTooltip();
					}
					else
					{
						if (CurrentMouseElements.MouseMoveElement.Layer == Layers.CurrentLayer)
						{
							mMouseHandle = CurrentMouseElements.MouseMoveElement.Handle(PointToDiagram(e));

							if (CurrentMouseElements.MouseMoveElement.Cursor != null && mMouseHandle.Type == HandleType.Move)
							{
								Cursor = CurrentMouseElements.MouseMoveElement.Cursor;
							}
							else
							{
								Cursor = Component.Instance.GetCursor(mMouseHandle.Type);
							}

							//Set the tooltip if it is null or has changed
							if (mTooltip == null || (mTooltip.GetToolTip(this) != CurrentMouseElements.MouseMoveElement.Tooltip)) SetTooltip(CurrentMouseElements.MouseMoveElement);
						}
					}
				}

				//Check left button only
                bool leftButton = (e.Button & MouseButtons.Left) == MouseButtons.Left;

				if (leftButton && CurrentMouseElements.StartButton == e.Button)
				{
					Suspend();

					IRenderDesign render = (IRenderDesign) Render;
					render.Highlights = new RenderList();

					float dx  = (mousePoint.X - mLastPoint.X) / Render.ScaleFactor;
					float dy  = (mousePoint.Y - mLastPoint.Y) / Render.ScaleFactor;

                    if (Runtime.InteractiveMode == InteractiveMode.Normal && leftButton)
					{
						if (CurrentMouseElements.MouseStartElement == null)
						{
							//Set up drag rectangle
							if (DragSelect && !mStartPoint.Equals(new Point(e.X,e.Y)))
							{
								//Set the decoration selection rectangle
								Rectangle select = Rectangle.Round(Geometry.CreateRectangle(mStartPoint,new Point(e.X,e.Y)));

								//Select the elements in the rectangle
								SelectElements(select);

								//Offset the rectangle by the scroll for rendering
								select.Offset(-DisplayRectangle.X,-DisplayRectangle.Y);

								//Raise the event and set in the render
								if (render.SelectionRectangle.IsEmpty) OnBeginDragSelect(e);
								render.SelectionRectangle = select;
							}
						}
						else
						{
							//If this is the first mouse move then create the action renderlist and lock the renderer
							if (!render.Locked)
							{
								RenderList actions = CreateActionRenderList(CurrentMouseElements.MouseStartElement.Container.RenderList);

								//If align to grid then set up positions of shapes
								//Reset dx,dy because last mouse point wasnt aligned
								if (AlignGrid && mMouseHandle.Type == HandleType.Move) 
								{
									AlignElementLocations(actions);
									dx=0; 
									dy=0;
								}
								
								//Hide the actioned elements and render before lock
								if (Component.Instance.HideActions)
								{
									HideActionElements(actions);
									Render.RenderDiagram(Render.RenderRectangle);
								}

								render.Lock();
								render.Actions = actions;
							}

							//Loop through and offset each element in the action renderlist
							if (mMouseHandle != null)
							{
								if (mMouseHandle.Type == HandleType.Move) 
								{
									OffsetElements(dx,dy);
									OnMoving(RenderDesign.Actions);
								}
								else if (mMouseHandle.Type == HandleType.Rotate)
								{
									RotateElements();
									OnRotating(RenderDesign.Actions);
								}
								else
								{
									ScaleElements();
									OnScaling(RenderDesign.Actions);
								}
							}
						}

						//Set any highlights
						if (CurrentMouseElements.MouseStartOrigin != null && CurrentMouseElements.MouseStartOrigin.AllowMove && CurrentMouseElements.MouseMoveElement != null)
						{
							//Check origin is dockable, containers are compatible etc
							if (IsModelDockable())
							{
								if (Runtime.CanDock(CurrentMouseElements)) render.Highlights.Add(CurrentMouseElements.MouseMoveElement);
							}
						}

						//Set any feedback 
						if (Runtime.Feedback && mMouseHandle != null) 
						{
							Runtime.SetFeedback(mMouseHandle.Type);
							RenderDesign.FeedbackLocation = new Point(e.X + 16 - DisplayRectangle.X, e.Y + 16 - DisplayRectangle.Y);
						}
					}

					//Add interactive items
					if (Runtime.InteractiveMode != InteractiveMode.Normal)
					{
						//Create interactive items
						if (!render.Locked)
						{
							render.Actions = CreateInteractiveRenderList(mousePoint);
							render.Lock(); //Not locked as interactive creates a new item every time
						}
						//Loop through and offset each element in the action renderlist
						else if (CurrentMouseElements.MouseStartElement != null)
						{
							if (mMouseHandle.Type == HandleType.Move) 
							{
								OffsetElements(dx,dy);
							}
							else
							{
								ScaleElements();
							}
						}

						//Set any highlights
						if (Runtime.InteractiveMode != InteractiveMode.AddShape && Runtime.InteractiveMode != InteractiveMode.AddComplexShape && CurrentMouseElements.MouseMoveElement != null)
						{
							//Check origin is dockable, containers are compatible etc
							if (IsModelDockable())
							{
								if (Runtime.CanDock(CurrentMouseElements)) render.Highlights.Add(CurrentMouseElements.MouseMoveElement);
							}
						}

						//Set any feedback 
						if (Runtime.Feedback)
						{
							Runtime.SetFeedback(mMouseHandle.Type);
							RenderDesign.FeedbackLocation = new Point(e.X+16-DisplayRectangle.X,e.Y+16-DisplayRectangle.Y);
						}
					}

					Resume();
					Invalidate();
				}
			}

			mLastPoint = mousePoint;
			base.OnMouseMove (e);
		}
Пример #3
0
		protected override void OnMouseUp(MouseEventArgs e)
		{
			//Dispose of Dragscroll timer
			if (mTimer != null)
			{	
				mTimer.Stop();
				mTimer.Dispose();
				mTimer = null;
			}

			//Check if handles mouse
			if (!mHandled && CurrentMouseElements.MouseStartElement is IMouseEvents) mHandled = ((IMouseEvents) CurrentMouseElements.MouseStartElement).OnMouseUp(e);

            if (CurrentMouseElements.StartButton != MouseButtons.None && CurrentMouseElements.StartButton != e.Button)
            {
                base.OnMouseUp(e);
                return;
            }

			//Process left mouse button
			if (!mHandled)
			{
                //Set a mouse handle in case a mouse move has not been fired yet
                if (mMouseHandle == null) mMouseHandle = Component.Instance.DefaultHandle; 

                bool leftButton = (e.Button & MouseButtons.Left) == MouseButtons.Left;

				if (leftButton && CurrentMouseElements.StartButton == e.Button)
				{
					if (Runtime.InteractiveMode == InteractiveMode.Normal)
					{
						//Reset highlights
						RenderDesign.Highlights = new RenderList();
				
						if (CurrentMouseElements.MouseStartElement == null)
						{
							//Reset the selection rectangle decoration
							if (!RenderDesign.SelectionRectangle.IsEmpty)
							{
								RenderDesign.SelectionRectangle = new Rectangle();
								OnEndDragSelect(e);
							}
						}
						else
						{
							//Moves the elements according to the renderlist
							if (RenderDesign.Actions != null)
							{
								//Unhides the action elements
								if (Component.Instance.HideActions) ShowActionElements(RenderDesign.Actions);
								
								Suspend();
								UpdateElements();
								RedrawConnectors();
								Resume();
								Invalidate();

								OnUpdateActions(RenderDesign.Actions);
								RenderDesign.Actions = null;
								RenderDesign.Feedback = null;
								RenderDesign.FeedbackLocation = new Point();
								RenderDesign.Vector = new RectangleF();
								RenderDesign.Unlock();
							}
						}
					}

					if (Runtime.InteractiveMode != InteractiveMode.Normal)
					{
						//Reset highlights
						RenderDesign.Highlights = new RenderList();

						//Cant suspend as events are required
						UpdateInteractiveElements();

						OnUpdateActions(RenderDesign.Actions);
						RenderDesign.Actions = null;
						RenderDesign.Feedback = null;
						RenderDesign.FeedbackLocation = new Point();
						RenderDesign.Unlock();
					}
					Invalidate();
				}
			}

			mHandled = false;
			base.OnMouseUp (e);
		}
Пример #4
0
		//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;
		}
Пример #5
0
		protected override void CreateHandles()
		{
			if (Container == null) return;
			if (Points == null) return;
			SetHandles(new Handles());

			//Get the default graphics path and scale it
			IRender render = RenderFromContainer();
			GraphicsPath defaultPath = (GraphicsPath) Component.Instance.DefaultHandlePath.Clone();
			Matrix matrix = new Matrix();
			matrix.Scale(render.ZoomFactor,render.ZoomFactor);
			defaultPath.Transform(matrix);

			RectangleF pathRectangle = defaultPath.GetBounds();
			RectangleF halfRectangle = new RectangleF(0,0,pathRectangle.Width /2, pathRectangle.Height /2);

			//Loop through each point and add an offset handle
			GraphicsPath path;
			int count = 0;
			PointF previous = new PointF();

			foreach (PointF point in Points)
			{
				//Add the split segment 
				if (count > 0 && AllowExpand)
				{
					path = (GraphicsPath) defaultPath.Clone();
					matrix.Reset();
					matrix.Translate(previous.X - Rectangle.X - halfRectangle.Width + ((point.X - previous.X) / 2), previous.Y - Rectangle.Y - halfRectangle.Height+ ((point.Y - previous.Y) / 2));
					path.Transform(matrix);

					//Create a new expand handle
					ExpandHandle expand = new ExpandHandle(Segments[count-1]);
					expand.Path = path;
					expand.Index = count-1;
					expand.CanDock = false;
					Handles.Add(expand);
				}

				path = (GraphicsPath) defaultPath.Clone();
				matrix.Reset();
				matrix.Translate(point.X - Rectangle.X - halfRectangle.Width,point.Y - Rectangle.Y - halfRectangle.Height);
				path.Transform(matrix);
				
				//Create handle
				Handle handle = new Handle(path,HandleType.Origin);
				handle.CanDock = false;
				Handles.Add(handle);

				count ++;
				previous = point;
			}
			
			//Set up the docking
			Handles[0].CanDock = true;
			Handles[Handles.Count-1].CanDock = true;
		}
Пример #6
0
		private void CreateDefaultHandle()
		{
			mDefaultHandle = new Handle();
			mDefaultHandle.Type = HandleType.Move;
		}
Пример #7
0
		//Returns the index of an Handle
		public int IndexOf(Handle value)  
		{
			return List.IndexOf(value);
		}
Пример #8
0
		//Returns true if list contains Handle
		public bool Contains(Handle value)  
		{
			return List.Contains(value);
		}
Пример #9
0
		//Removes an Handle from the list
		public void Remove(Handle value )  
		{
			List.Remove(value);
		}
Пример #10
0
		//Inserts an elelemnt into the list
		public void Insert(int index, Handle value)  
		{
			if (value == null) throw new ArgumentNullException("Handle parameter cannot be null reference.","value");
			List.Insert(index, value);
		}
Пример #11
0
		//Adds an Handle to the list 
		public int Add(Handle value)  
		{
			if (value == null) throw new ArgumentNullException("Handle parameter cannot be null reference.","value");
			return List.Add(value);
		}