コード例 #1
0
ファイル: Group.cs プロジェクト: michaelrut/arcgis-diagrammer
        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();
        }
コード例 #2
0
        //Implements IClonable
        public object Clone()
        {
            RenderList copy = new RenderList();

            foreach (Element element in this)
            {
                copy.Add(element);
            }
            return(copy);
        }
コード例 #3
0
ファイル: Group.cs プロジェクト: michaelrut/arcgis-diagrammer
        public Group(Group prototype) : base(prototype)
        {
            Shapes      = new Elements(typeof(Shape), "Shape");
            Lines       = new Elements(typeof(Line), "Line");
            mRenderList = new RenderList();
            mMargin     = prototype.Margin;

            mCheckBounds    = prototype.CheckBounds;
            mDrawExpand     = prototype.DrawExpand;
            mExpanded       = prototype.Expanded;
            mContractedSize = prototype.ContractedSize;
            mExpandedSize   = prototype.ExpandedSize;
        }
コード例 #4
0
ファイル: Group.cs プロジェクト: savagemat/arcgis-diagrammer
		public Group(Group prototype): base(prototype)
		{
			Shapes = new Elements(typeof(Shape),"Shape");
			Lines = new Elements(typeof(Line),"Line");
			mRenderList = new RenderList();
			mMargin = prototype.Margin;

			mCheckBounds = prototype.CheckBounds;
			mDrawExpand = prototype.DrawExpand;
			mExpanded = prototype.Expanded;
			mContractedSize = prototype.ContractedSize;
			mExpandedSize = prototype.ExpandedSize;
		}
コード例 #5
0
        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();
        }
コード例 #6
0
ファイル: Group.cs プロジェクト: michaelrut/arcgis-diagrammer
        //Deserializes info into a new solid element
        protected Group(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            mRenderList = new RenderList();

            SuspendEvents = true;

            Shapes = (Elements)info.GetValue("Shapes", typeof(Elements));
            Lines  = (Elements)info.GetValue("Lines", typeof(Elements));
            Margin = (Margin)info.GetValue("Margin", typeof(Margin));

            CheckBounds    = info.GetBoolean("CheckBounds");
            DrawExpand     = info.GetBoolean("DrawExpand");
            ExpandedSize   = Serialize.GetSizeF(info.GetString("ExpandedSize"));
            ContractedSize = Serialize.GetSizeF(info.GetString("ContractedSize"));
            Expanded       = info.GetBoolean("Expanded");

            SuspendEvents = false;
        }
コード例 #7
0
ファイル: Group.cs プロジェクト: savagemat/arcgis-diagrammer
		//Deserializes info into a new solid element
		protected Group(SerializationInfo info, StreamingContext context): base(info,context)
		{
			mRenderList = new RenderList();

			SuspendEvents = true;
			
			Shapes = (Elements) info.GetValue("Shapes",typeof(Elements));
			Lines = (Elements) info.GetValue("Lines",typeof(Elements));
			Margin = (Margin) info.GetValue("Margin",typeof(Margin));
			
			CheckBounds = info.GetBoolean("CheckBounds");
			DrawExpand = info.GetBoolean("DrawExpand");
			ExpandedSize = Serialize.GetSizeF(info.GetString("ExpandedSize"));
			ContractedSize = Serialize.GetSizeF(info.GetString("ContractedSize"));
			Expanded = info.GetBoolean("Expanded");
			
			SuspendEvents = false;
		}
コード例 #8
0
ファイル: Group.cs プロジェクト: michaelrut/arcgis-diagrammer
        //Constructors
        public Group()
        {
            SuspendEvents = true;

            DrawBackground = false;
            DrawShadow     = false;
            BorderStyle    = DashStyle.Dash;
            ExpandedSize   = MaximumSize;
            ContractedSize = Size;
            DrawExpand     = true;
            Expanded       = true;
            CheckBounds    = true;

            //Set up objects and event handlers
            Shapes      = new Elements(typeof(Shape), "Shape");
            Lines       = new Elements(typeof(Line), "Line");
            mMargin     = new Margin();
            mRenderList = new RenderList();

            SuspendEvents = false;
        }
コード例 #9
0
ファイル: Group.cs プロジェクト: savagemat/arcgis-diagrammer
		//Constructors
		public Group()
		{
			SuspendEvents = true;

			DrawBackground = false;
			DrawShadow = false;
			BorderStyle = DashStyle.Dash;
			ExpandedSize = MaximumSize;
			ContractedSize = Size;
			DrawExpand = true;
			Expanded = true;
			CheckBounds = true;
            
			//Set up objects and event handlers
			Shapes = new Elements(typeof(Shape),"Shape");
			Lines = new Elements(typeof(Line),"Line");
			mMargin = new Margin();
			mRenderList = new RenderList();

			SuspendEvents = false;
		}
コード例 #10
0
		private void ClearDiagram()
		{
			SuspendEvents = true;

			//Set default layers collection, need for shapes and lines
			Layers = new Layers();
			mRenderList = new RenderList();

			//Set up shapes and lines, needed for navigation
			Shapes = new Elements(typeof(Shape),"Shape");
			Lines = new Elements(typeof(Line),"Line");
			
			mNavigate = new Navigation.Navigate(this);
			Route = new Route();
			Route.Container = this;
			
			SuspendEvents = false;
		}
コード例 #11
0
		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();
		}
コード例 #12
0
		protected virtual void RenderDiagramElementsLayer(Graphics graphics, RenderList renderlist, Layer layer)
		{
			foreach (Element element in renderlist)
			{
				if (element.Layer == layer && element.Visible)
				{
					//Draw shapes
					graphics.TranslateTransform(element.Rectangle.X,element.Rectangle.Y);
					RenderElement(graphics,element);

					//Render any elements in the container
					if (element is IContainer)
					{
						IContainer container = (IContainer) element;

						Region region = new Region(element.GetPathInternal());
						Region current = graphics.Clip;
						graphics.SetClip(region,CombineMode.Intersect);

						RenderDiagramElementsLayer(graphics,container.RenderList,layer);			

						//reset clip
						graphics.Clip = current;
					}

					graphics.TranslateTransform(-element.Rectangle.X,-element.Rectangle.Y);
				}
			}
		}
コード例 #13
0
ファイル: Model.cs プロジェクト: savagemat/arcgis-diagrammer
 protected virtual void OnCancelActions(RenderList actions)
 {
     if (!SuspendEvents && CancelActions != null) CancelActions(this, new UserActionEventArgs(actions));
 }
コード例 #14
0
ファイル: Model.cs プロジェクト: savagemat/arcgis-diagrammer
		private void AlignElementLocations(RenderList actions)
		{
			foreach (Element element in actions)
			{
				if (element is Shape)
				{
					Shape shape = (Shape) element;
					PointF location = shape.Location;
					SizeF gridSize = GridSize;

					Point newLocation = Point.Round(new PointF(location.X / gridSize.Width, location.Y / gridSize.Height));
					shape.Location = new PointF(newLocation.X * gridSize.Width,newLocation.Y * gridSize.Height) ;
				}
			}
		}
コード例 #15
0
ファイル: Model.cs プロジェクト: savagemat/arcgis-diagrammer
		private void ShowActionElements(RenderList actions)
		{
			//Suspend undo/redo
			UndoList.Suspend();

			foreach (Element element in actions)
			{
				if (!element.ActionElement.Visible && element.Visible) 
				{
					element.ActionElement.Visible = true;
				}
			}

			UndoList.Resume();
		}
コード例 #16
0
ファイル: Model.cs プロジェクト: savagemat/arcgis-diagrammer
		//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;
		}
コード例 #17
0
ファイル: Model.cs プロジェクト: savagemat/arcgis-diagrammer
		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();
		}
コード例 #18
0
		public UserActionEventArgs(RenderList actions)
		{
			mActions = actions;
		}
コード例 #19
0
ファイル: Group.cs プロジェクト: savagemat/arcgis-diagrammer
		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();
		}
コード例 #20
0
ファイル: Model.cs プロジェクト: savagemat/arcgis-diagrammer
		//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;
		}
コード例 #21
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);
		}
コード例 #22
0
ファイル: Model.cs プロジェクト: savagemat/arcgis-diagrammer
		//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);
		}
コード例 #23
0
		//Returns the top element from a diagram point
		private Element GetElement(PointF location, RenderList renderlist)
		{
			Element bestElement = null;
			Port bestPort = null;
			Layer currentLayer = Layers.CurrentLayer;

			if (!currentLayer.Visible) return null;

			foreach (Element element in renderlist)
			{
				if (element.Layer == currentLayer)
				{
					//Selection Handles always beat anything else
					if (element is ISelectable)
					{
						ISelectable selectable = (ISelectable) element;

						if (selectable.Selected && element.Handles != null) 
						{
							PointF local = new PointF(location.X - element.Rectangle.X, location.Y - element.Rectangle.Y);

							foreach (Handle handle in element.Handles)
							{
								if (handle.Path.IsVisible(local)) return element;
							}
						}
					}
				
					//Check for ports
					if (element is IPortContainer)
					{		
						IPortContainer container = (IPortContainer) element;
						foreach (Port port in container.Ports.Values)
						{
							if (port.Visible && port.Contains(location))
							{
								if (bestElement == null || element.ZOrder < bestElement.ZOrder) 
								{
									bestElement = element;	
									bestPort = port;
								}
							}
						}
					}

					//Check element by calling Contains method which is overriden in most classes
					if (element.Visible && element.Contains(location))
					{
						if (bestElement == null) bestElement = element;
						if (element.ZOrder < bestElement.ZOrder) 
						{
							bestElement = element;
							bestPort = null;
						}
					}
				}
			}

			//Get child element from container, calling this function recursively
			if (bestElement is IContainer)
			{
				IExpandable expand = null;
				
				if (bestElement is IExpandable) expand = (IExpandable) bestElement;
				
				if (expand == null || expand.Expanded)
				{
					IContainer container = (IContainer) bestElement;
					PointF containerLocation = location;
					Element bestContainerElement;

					containerLocation.X -= container.Offset.X;
					containerLocation.Y -= container.Offset.Y;
					
					bestContainerElement = GetElement(containerLocation,container.RenderList);
					if (bestContainerElement != null) return bestContainerElement;
				}
			}

			if (bestPort == null)
			{
				return bestElement;
			}
			else
			{
				return bestPort;
			}
		}
コード例 #24
0
ファイル: Model.cs プロジェクト: savagemat/arcgis-diagrammer
		//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;
				}
			}
		}
コード例 #25
0
		protected virtual void SetRenderList(RenderList renderList)
		{
			mRenderList = renderList;
			Render.Elements = renderList;
		}
コード例 #26
0
ファイル: Model.cs プロジェクト: savagemat/arcgis-diagrammer
		protected virtual void OnUpdateActions(RenderList actions)
		{
			if (! SuspendEvents && UpdateActions != null) UpdateActions(this, new UserActionEventArgs(actions));
		}
コード例 #27
0
		//Implements IClonable
		public object Clone()
		{
			RenderList copy = new RenderList();

			foreach (Element element in this)
			{
				copy.Add(element);
			}
			return copy;
		}
コード例 #28
0
ファイル: Model.cs プロジェクト: savagemat/arcgis-diagrammer
		protected virtual void OnRotating(RenderList actions)
		{
			if (! SuspendEvents && Rotating != null) Rotating(this, new UserActionEventArgs(actions));
		}
コード例 #29
0
 public UserActionEventArgs(RenderList actions)
 {
     mActions = actions;
 }