Beispiel #1
0
        private void CreateRenderList()
        {
            mRenderList = new RenderList();

            //Check for intersections with the zoomed rectangle;
            foreach (Shape shape in mShapes.Values)
            {
                if (shape.Visible)
                {
                    mRenderList.Add(shape);
                }
            }

            if (mLines != null)             //Can be null when shapes first set
            {
                foreach (Line line in mLines.Values)
                {
                    if (line.Visible)
                    {
                        mRenderList.Add(line);
                    }
                }
            }
            mRenderList.Sort();
        }
Beispiel #2
0
        //Implements IClonable
        public object Clone()
        {
            RenderList copy = new RenderList();

            foreach (Element element in this)
            {
                copy.Add(element);
            }
            return(copy);
        }
        private void CreateRenderList()
        {
            mRenderList = new RenderList();

            //Check for intersections with the zoomed rectangle;
            foreach (SolidElement solid in Children.Values)
            {
                if (solid.Visible)
                {
                    mRenderList.Add(solid);
                }
            }
            mRenderList.Sort();
        }
Beispiel #4
0
		//Loop through each item in the copycut buffer and add it back to the model
		//Paste into centre of container
		private void DoPaste(IContainer container, PointF location)
		{
			if (mClipboard.Elements == null) return;

			//Create a renderlist and add the elements
			RenderList list = new RenderList();
			foreach (Element element in mClipboard.Elements.Values)
			{
				list.Add(element);
			}

			//Get the bounds
			RectangleF bounds = list.GetBounds();

			//Calculate
			float dx = -bounds.X + ((container.ContainerSize.Width - bounds.Width) / 2);
			float dy = -bounds.Y + ((container.ContainerSize.Height - bounds.Height) / 2);

			dx = Convert.ToSingle(Math.Round(dx,0));
			dy = Convert.ToSingle(Math.Round(dy,0));

			//Loop through each element and add
			if (mClipboard.Elements != null)
			{
				//Add Shapes
				foreach (Element element in mClipboard.Elements.Values)
				{
					if (element is Shape && (! (element is IContainer && container is Group)))
					{
						Shape shape = (Shape) element;
						Shape newShape = (Shape) shape.Clone();
						string key = null;

						//Set key
						key = (container.Shapes.Contains(shape.Key)) ? container.Shapes.CreateKey(): shape.Key;

						//Set temporary action element
						shape.ActionElement = newShape;

						//Change any settings required
						newShape.SetLayer(null);
						newShape.Selected = true;

						//Offset by container offset
						newShape.Move(dx,dy);

						//Round values if appropriate
						if (Runtime.RoundPixels)
						{
							newShape.Location = Point.Round(newShape.Location);
							newShape.Size = System.Drawing.Size.Round(newShape.Size);
						}

						//Add if allowed by the runtime
						if (Runtime.CanAdd(newShape)) container.Shapes.Add(key,newShape);
					}
				}

				//Add Lines
				foreach (Element element in mClipboard.Elements.Values)
				{
					if (element is Line)
					{
						Line line = (Line) element;
						Line newLine = (Line) line.Clone();
						string key = null;

						//Define the key
						key = (container.Lines.Contains(line.Key)) ? container.Lines.CreateKey(): key = line.Key;

						//Change any settings required
						newLine.SetLayer(null);
						newLine.Selected = true;

						if (element is ComplexLine)
						{
							ComplexLine complexLine = (ComplexLine) newLine;
							Segment segment = null;

							for (int i=0; i<complexLine.Segments.Count; i++)
							{
								segment = complexLine.Segments[i];
								segment.Start.Move(dx,dy);								
							}
						}
						else if (element is Curve)
						{
							Curve curve = (Curve) newLine;
							
							curve.Start.Move(dx,dy);
							curve.End.Move(dx,dy);
							
							PointF[] newPoints = new PointF[curve.ControlPoints.GetUpperBound(0)+1];
							for(int i=0; i<=curve.ControlPoints.GetUpperBound(0); i++)
							{
								newPoints[i] = new PointF(curve.ControlPoints[i].X + dx,curve.ControlPoints[i].Y + dy);
							}
							curve.ControlPoints = newPoints;
						}
						else if (element is Connector) //Connectors cannot be moved in this way
						{
							Connector conn = (Connector) newLine;
							ArrayList points = new ArrayList();
                            
							foreach (PointF point in conn.Points)
							{
								points.Add(new PointF(point.X + dx, point.Y + dy));
							}
							conn.SetPoints(points);
							conn.DrawPath();
						}
						else
						{
							newLine.Start.Move(dx,dy);
							newLine.End.Move(dx,dy);
							newLine.DrawPath();
						}

						//Reconnect start origins
						if (line.Start.DockedElement != null)
						{
							if (line.Start.Shape != null && line.Start.Shape.ActionElement != null)
							{
								newLine.Start.Shape = (Shape) line.Start.Shape.ActionElement; 
							}
							else if (line.Start.Port != null && line.Start.Port.Parent is Shape)
							{
								Shape shape = (Shape) line.Start.Port.Parent;
								Shape newShape = (Shape) shape.ActionElement;
								
								newLine.Start.Port = (Port) newShape.Ports[line.Start.Port.Key];
							}
						}

						//Reconnect end origins
						if (line.End.DockedElement != null)
						{
							if (line.End.Shape != null && line.End.Shape.ActionElement != null)
							{
								newLine.End.Shape = (Shape) line.End.Shape.ActionElement; 
							}
							else if (line.End.Port != null && line.End.Port.Parent is Shape)
							{
								Shape shape = (Shape) line.End.Port.Parent;
								Shape newShape = (Shape) shape.ActionElement;
								
								newLine.End.Port = (Port) newShape.Ports[line.End.Port.Key];
							}
						}

						//Create and add to lines collection
						if (Runtime.CanAdd(newLine)) container.Lines.Add(key,newLine);
					}
				}

				//Remove any temporary action elements
				foreach (Element element in mClipboard.Elements.Values)
				{
					element.ActionElement = null;
				}
			}
		}
Beispiel #5
0
		//Connect any shapes and lines, adding any non-selected items as hidden actions
		private void ConnectInteractiveElements(RenderList actions)
		{
			//Set up origins for any lines
			RenderList hidden = new RenderList();

			foreach (Element element in actions)
			{
				if (element is Line)
				{
					Line line = (Line) element;
					Line actionLine = (Line) element.ActionElement;
					Shape newShape;
					Element newElement;
					IPortContainer ports;

					line.Start.SuspendEvents = true;
					line.End.SuspendEvents = true;

					//Add any shapes and shapes with ports that are connected to lines as invisible items
					if (actionLine.Start.Shape != null)
					{
						if (!actions.ContainsKey(actionLine.Start.Shape.Key))
						{
							newShape = (Shape) actionLine.Start.Shape.Clone();
							newShape.ActionElement = actionLine.Start.Shape;
							newShape.SetKey(actionLine.Start.Shape.Key);
							newShape.Visible = false;
							hidden.Add(newShape);

							line.Start.Shape = newShape;
						}
						else
						{
							line.Start.Shape = (Shape) actions[actionLine.Start.Shape.Key];
						}
					}
					else if (actionLine.Start.Port != null)
					{
						Element parent = (Element) actionLine.Start.Port.Parent;
						
						if (!actions.ContainsKey(parent.Key))
						{
							newElement = (Element) parent.Clone();
							newElement.ActionElement = parent;
							newElement.SetKey(parent.Key);
							newElement.Visible = false;
							hidden.Add(newElement);
							
							ports = (IPortContainer) newElement;
							line.Start.Port = (Port) ports.Ports[actionLine.Start.Port.Key];
						}
						else
						{
							ports = (IPortContainer) actions[parent.Key];
							line.Start.Port =(Port) ports.Ports[actionLine.Start.Port.Key];
						}
					}

					if (actionLine.End.Shape != null)
					{
						if (!actions.ContainsKey(actionLine.End.Shape.Key))
						{
							newShape = (Shape) actionLine.End.Shape.Clone();
							newShape.ActionElement = actionLine.End.Shape;
							newShape.SetKey(actionLine.End.Shape.Key);
							newShape.Visible = false;
							hidden.Add(newShape);
							line.End.Shape = newShape;
						}
						else
						{
							line.End.Shape = (Shape) actions[actionLine.End.Shape.Key];
						}
					}
					else if (actionLine.End.Port != null)
					{
						Element parent = (Element) actionLine.End.Port.Parent;

						if (!actions.ContainsKey(parent.Key))
						{
							newElement = (Element) parent.Clone();
							newElement.ActionElement = parent;
							newElement.SetKey(parent.Key);
							newElement.Visible = false;
							hidden.Add(newElement);
							
							ports = (IPortContainer) newElement;
							line.End.Port = (Port) ports.Ports[actionLine.End.Port.Key];
						}
						else
						{
							ports = (IPortContainer) actions[parent.Key];
							line.End.Port =(Port) ports.Ports[actionLine.End.Port.Key];
						}
					}

					line.Start.SuspendEvents = false;
					line.End.SuspendEvents = false;
				}
			}
			
			//Add any hidden shapes to the actions renderlist
			if (hidden.Count > 0) actions.AddRange(hidden);
		}
Beispiel #6
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;
		}
Beispiel #7
0
		//Builds up a renderlist containing copies of the elements to be rendered in an action
		protected virtual RenderList CreateActionRenderList(RenderList renderList)
		{
			RenderList actions = new RenderList();
			Element newElement;
			Port newPort;
						
			foreach (Element element in renderList)
			{
				if (element is ISelectable && element.Layer == Layers.CurrentLayer)
				{
					//Add shapes and lines
					ISelectable selectable = (ISelectable) element;

					if (selectable.Selected) 
					{
						newElement = (Element) element.Clone();
						newElement.ActionElement = element;
						newElement.SetKey(element.Key);
						actions.Add(newElement);
					
						//Set the action shapes for the complex shape children
						if (element is ComplexShape)
						{
							ComplexShape complex = (ComplexShape) element;
							ComplexShape newComplex = (ComplexShape) newElement;
						
							foreach (SolidElement solid in newComplex.Children.Values)
							{
								solid.ActionElement = complex.Children[solid.Key];
							}
						}

						//Keep size of table
						if (element is Table)
						{
							Table table = (Table) element;
							Table newTable = (Table) newElement;

							newTable.Size = table.Size;
						}
					}
				}
			}

			//Connect any shapes and lines, adding any non-selected items as hidden actions
			ConnectInteractiveElements(actions);
				
			//Loop through and connect the lines
			foreach (Element element in actions)
			{
				if (element is Line)
				{
					Line line = (Line) element;
					if (line.Start.Shape != null) line.Start.Shape = (Shape) actions[line.Start.Shape.Key];
					if (line.End.Shape != null) line.End.Shape = (Shape) actions[line.End.Shape.Key];
				}
			}

			//Add any ports
			if (CurrentMouseElements.MouseStartElement is Port)
			{
				newPort = (Port) CurrentMouseElements.MouseStartElement.Clone();
				newPort.Validate = true;
				newPort.ActionElement = CurrentMouseElements.MouseStartElement;
				actions.Add(newPort);
			}

			return actions;
		}
Beispiel #8
0
		protected override void OnDragDrop(DragEventArgs drgevent)
		{
			SaveStatus();
			SetStatus(Status.DragDrop);

			if (DragElement != null)
			{
				Suspend();

				//Set the container
				IContainer container = this;

				//Translate the drag point from screen co-ordinates to control co-ordinates
				Point controlPoint = PointToClient(new Point(drgevent.X, drgevent.Y));
				
				//Get any container elements under the cursor
				Element element = ElementFromPoint(controlPoint.X, controlPoint.Y);
				if (element != null && element is IContainer) container = (IContainer) element;

				PointF dropPoint = OffsetDrop(controlPoint,DragElement.Rectangle);

				dropPoint.X -= container.Offset.X;
				dropPoint.Y -= container.Offset.Y;

				//Move any ports
				if (DragElement is IPortContainer)
				{
					IPortContainer portContainer = (IPortContainer) DragElement;
 
					//Store values before updating underlying rectangle
					float dx = dropPoint.X - DragElement.Rectangle.X;
					float dy = dropPoint.Y - DragElement.Rectangle.Y;
					
					//Move ports by change in x and y
					if (portContainer.Ports != null)
					{
						foreach(Port port in portContainer.Ports.Values)
						{
							port.SuspendValidation();
							port.Move(dx,dy);
							port.ResumeValidation();
						}
					}
				}

				//Change settings				
				DragElement.SetRectangle(dropPoint);
				if (DragElement is SolidElement)
				{
					SolidElement solid = (SolidElement) DragElement;
					solid.SetTransformRectangle(dropPoint);
				}

				DragElement.SetLayer(null);

				if (DragElement is Shape)
				{
					Shape shape = (Shape) DragElement;

					shape.AllowMove = true;
					shape.AllowScale = true;
					shape.MinimumSize = new SizeF(32, 32);
					shape.MaximumSize = new SizeF(320, 320);

					//Align to grid using common grid alignment
					if (AlignGrid)
					{
						RenderList list = new RenderList();
						list.Add(shape);
						AlignElementLocations(list);
					}

					//Add the element to lines or shapes
					container.Shapes.Add(container.Shapes.CreateKey(),DragElement);
				}

				//Clear the render path
				RenderDesign.DecorationPath = null;
				RenderDesign.Highlights = null;
	
				//Repaint
				Resume();
				Refresh();
			}
			
			base.OnDragDrop(drgevent);
			DragElement = null; //Set to null only after the event
			
			RestoreStatus();
		}
		//Implements IClonable
		public object Clone()
		{
			RenderList copy = new RenderList();

			foreach (Element element in this)
			{
				copy.Add(element);
			}
			return copy;
		}
Beispiel #10
0
		private void CreateScrollRenderList(RectangleF rect, bool sort)
		{
			RectangleF zoomRect = TranslateRectangle(rect);

			//Get a local reference and clear the renderlist
			RenderList newList = new RenderList();
			Hashtable additional = new Hashtable();

			//Check all elements from the previous render that intersect with the new rectangle
			foreach (Element element in mRenderList)
			{
				if (element.Rectangle.IntersectsWith(zoomRect))
				{
					if (element is Line)
					{
						Line line = (Line) element;

						//Add connected shapes to the list of possible additions
						if (line.Start.DockedElement != null && !additional.ContainsKey(line.Start.DockedElement.Key)) additional.Add(line.Start.DockedElement.Key, line.Start.DockedElement);
						if (line.End.DockedElement != null && !additional.ContainsKey(line.End.DockedElement.Key)) additional.Add(line.End.DockedElement.Key, line.End.DockedElement);

						newList.Add(element);
					}
					else if (element is Shape && !additional.ContainsKey(element.Key))
					{
						newList.Add(element);
					}
				}
			}

			//Add additional shapes from connected lines
			foreach (Shape shape in additional.Values)
			{
				if (shape.Rectangle.IntersectsWith(zoomRect))
				{
					newList.Add(shape);
				}
			}

			if (sort) newList.Sort();
			SetRenderList(newList);
		}
Beispiel #11
0
		private void CreateRenderList()
		{
			mRenderList = new RenderList();

			//Check for intersections with the zoomed rectangle;
			foreach (Shape shape in mShapes.Values)
			{
				if (shape.Visible) mRenderList.Add(shape);
			}

			if (mLines != null) //Can be null when shapes first set
			{
				foreach (Line line in mLines.Values)
				{
					if (line.Visible) mRenderList.Add(line);
				}
			}
			mRenderList.Sort();
		}
		private void CreateRenderList()
		{
			mRenderList = new RenderList();

			//Check for intersections with the zoomed rectangle;
			foreach (SolidElement solid in Children.Values)
			{
				if (solid.Visible) mRenderList.Add(solid);
			}
			mRenderList.Sort();
		}