private void AddDiagramToFile(Diagram diagram) { Graphics graphics = Graphics.FromImage(mMetafile); //Set the renderlists to the whole diagram Rectangle renderRect = new Rectangle(new Point(0,0),diagram.DiagramSize); diagram.GetRenderList(renderRect); //Set the render rectangle diagram.Render.RenderRectangle = renderRect; diagram.Render.RenderDiagramElements(graphics); graphics.Dispose(); }
//Determine if an element can dock public virtual bool CanDock(Diagram.MouseElements mouseElements) { //Check is shape or port if (InteractiveMode == InteractiveMode.Normal) { if (mouseElements.MouseMoveElement is Shape || mouseElements.MouseMoveElement is Port) { //return false if permission not available to dock if (mouseElements.MouseStartOrigin != null) { Origin origin = mouseElements.MouseStartOrigin; Line line = (Line) mouseElements.MouseStartElement; if (mouseElements.MouseMoveElement is Shape) { Shape shape = (Shape) mouseElements.MouseMoveElement; if (shape.Direction == Direction.None) return false; if (origin == line.Start && shape.Direction== Direction.In) return false; if (origin == line.End && shape.Direction == Direction.Out) return false; } if (mouseElements.MouseMoveElement is Port) { Port port = (Port) mouseElements.MouseMoveElement; if (port.Direction == Direction.None) return false; if (origin == line.Start && port.Direction == Direction.In) return false; if (origin == line.End && port.Direction == Direction.Out) return false; } } //Check that start and target elements have the same container if (mouseElements.MouseStartElement.Container == mouseElements.MouseMoveElement.Container) { return true; } //Check for case where line in group is docked to group port if (mouseElements.MouseStartElement.Container is Group && mouseElements.MouseMoveElement is Port) { Port port = (Port) mouseElements.MouseMoveElement; if (port.Parent == mouseElements.MouseStartElement.Container) return true; } } } //Can dock for interactive elements else { if (mouseElements.InteractiveElement is Line) { Line line = (Line) mouseElements.InteractiveElement; //Determine if applies to start or end origin if (mouseElements.InteractiveOrigin == line.Start) { if (mouseElements.MouseMoveElement is Shape) { Shape shape = (Shape) mouseElements.MouseMoveElement; if (shape.Direction == Direction.None) return false; if (shape.Direction== Direction.In) return false; } if (mouseElements.MouseMoveElement is Port) { Port port = (Port) mouseElements.MouseMoveElement; if (port.Direction == Direction.None) return false; if (port.Direction == Direction.In) return false; } } else { if (mouseElements.MouseMoveElement is Shape) { Shape shape = (Shape) mouseElements.MouseMoveElement; if (shape.Direction == Direction.None) return false; if (shape.Direction == Direction.Out) return false; } if (mouseElements.MouseMoveElement is Port) { Port port = (Port) mouseElements.MouseMoveElement; if (port.Direction == Direction.None) return false; if (port.Direction == Direction.Out) return false; } } return true; //Check that start and target elements have the same container if (line.Container == mouseElements.MouseMoveElement.Container) { return true; } //Check for case where line in group is docked to group port if (line.Container is Group && mouseElements.MouseMoveElement is Port) { Port port = (Port) mouseElements.MouseMoveElement; if (port.Parent == line.Container) return true; } } } return false; }
//Methods public virtual void AddDiagram(Diagram diagram) { AddDiagramToFile(diagram); }
protected virtual void SetMouseElements(Diagram.MouseElements elements) { mMouseElements = elements; }
public Diagram(Diagram prototype) { InitializeComponent(); SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true); SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true); SetStatus(Status.Default); //Create a new renderer SetRender(new Render()); //Sets up current layers reference etc ClearDiagram(); Margin = new Margin(); SuspendEvents = true; mDiagramSize = prototype.DiagramSize; mShowToolTips = prototype.ShowTooltips; mCheckBounds = prototype.CheckBounds; mMargin = prototype.Margin; Paged = prototype.Paged; WorkspaceColor = prototype.WorkspaceColor; SuspendEvents = false; }
//Constructor public Animator(Diagram diagram) { if (diagram == null) throw new ArgumentNullException("Diagram may not be a null reference."); SetDiagram(diagram); mFrameRate = 12; }
protected internal void SetDiagram(Diagram diagram) { mDiagram = diagram; }