コード例 #1
0
ファイル: Group.cs プロジェクト: preskenis/mana-schedule
        //Constructors
        public Group()
        {
            _elements = new ElementList();
            Elements.SetModifiable(false);

            DrawBackground = false;
            DrawShadow     = false;
            BorderStyle    = DashStyle.Dash;
            ExpandedSize   = MaximumSize;
            ContractedSize = Size;
            DrawExpand     = true;
            Expanded       = true;
            CheckBounds    = true;
        }
コード例 #2
0
        private void CreateRenderList()
        {
            _renderList = new ElementList();

            //Check for intersections with the zoomed rectangle;
            foreach (Solid solid in Children.Values)
            {
                if (solid.Visible)
                {
                    _renderList.Add(solid);
                }
            }
            _renderList.Sort();
            _renderList.SetModifiable(false);
        }
コード例 #3
0
        public virtual SizeF BoundsCheck(ElementList actions, SizeF delta)
        {
            //Return pass if the diagram does not have boundary checking
            if (!CheckBounds)
            {
                return(delta);
            }

            foreach (Element element in actions)
            {
                delta = BoundsCheck(element, delta);
                if (delta.IsEmpty)
                {
                    return(delta);
                }
            }
            return(delta);
        }
コード例 #4
0
 private void DoCutCopyDeleteSelectedLines(bool add, bool remove, Lines collection, ElementList results)
 {
     //Add any cut/copied lines
     foreach (Link line in collection.Values)
     {
         if (line.Selected)
         {
             if (remove && Controller.CanDelete(line))
             {
                 results.Add(line);
             }
             if (add)
             {
                 Controller.Clipboard.Elements.Add(line.Key, line);
             }
         }
     }
 }
コード例 #5
0
        private void DoCutCopyDeleteSelectedElement <T>(bool add, bool remove, Elements <T> collection, ElementList results)
            where T : Element
        {
            //Add any cut/copied lines
            foreach (Element element in collection.Values)
            {
                if (element is ISelectable)
                {
                    ISelectable selectable = element as ISelectable;

                    if (selectable.Selected)
                    {
                        if (remove && Controller.CanDelete(element))
                        {
                            results.Add(element);
                        }
                        if (add)
                        {
                            Controller.Clipboard.Elements.Add(element.Key, element);
                        }
                    }
                }
            }
        }
コード例 #6
0
        //Loop through each item in the copycut buffer and add it back to the diagram
        //Paste into centre of container
        private void DoPaste(PointF location)
        {
            if (Controller.Clipboard.Elements == null)
            {
                return;
            }

            //Create a renderlist and add the elements
            ElementList list = new ElementList();

            foreach (Element element in Controller.Clipboard.Elements.Values)
            {
                list.Add(element);
            }

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

            //Calculate
            float dx = -bounds.X + ((Controller.Model.Size.Width - bounds.Width) / 2);
            float dy = -bounds.Y + ((Controller.Model.Size.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 (Controller.Clipboard.Elements != null)
            {
                //Add Shapes
                foreach (Element element in Controller.Clipboard.Elements.Values)
                {
                    if (element is Shape)
                    {
                        Shape  shape    = (Shape)element;
                        Shape  newShape = (Shape)shape.Clone();
                        string key      = null;

                        //Set key
                        key = (Controller.Model.Shapes.ContainsKey(shape.Key)) ? Controller.Model.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 (Controller.RoundPixels)
                        {
                            newShape.Location = Point.Round(newShape.Location);
                            newShape.Size     = System.Drawing.Size.Round(newShape.Size);
                        }

                        //Add if allowed by the runtime
                        if (Controller.CanAdd(newShape))
                        {
                            Controller.Model.Shapes.Add(key, newShape);
                        }
                    }
                }

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

                        //Define the key
                        key = (Controller.Model.Lines.ContainsKey(line.Key)) ? Controller.Model.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;
                            List <PointF> points = new List <PointF>();

                            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 (Controller.CanAdd(newLine))
                        {
                            Controller.Model.Lines.Add(key, newLine);
                        }
                    }
                }

                //Remove any temporary action elements
                foreach (Element element in Controller.Clipboard.Elements.Values)
                {
                    element.ActionElement = null;
                }
            }
        }
コード例 #7
0
 public void SetElements(ElementList elements)
 {
     _elements = elements;
 }
コード例 #8
0
 public UserActionEventArgs(ElementList actions)
 {
     _actions = actions;
 }