/// <summary> /// Adds a predefined shape /// </summary> /// <param name="type"></param> /// <param name="location"></param> public ShapeBase AddShape(ShapeTypes type, Point location) { ShapeBase shape = null; switch (type) { case ShapeTypes.Rectangular: shape = new SimpleRectangle(this); break; case ShapeTypes.Oval: shape = new OvalShape(this); break; case ShapeTypes.TextLabel: shape = new TextLabel(this); shape.Location = location; shape.ShapeColor = Color.Transparent; shape.Text = "A text label (change the text in the property grid)"; shape.Width = 350; shape.Height = 30; Shapes.Add(shape); return(shape); } if (shape == null) { return(null); } shape.ShapeColor = Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)); shape.Location = location; Shapes.Add(shape); return(shape); }
/// <summary> /// Adds a child to this shape /// </summary> /// <param name="text">the text of the newly created shape</param> /// <returns>the create shape</returns> public ShapeBase AddChild(string text) { SimpleRectangle shape = new SimpleRectangle(site); shape.Location = new Point(Width / 2 + 50, Height / 2 + 50); shape.Width = 50; shape.Height = 25; shape.Text = text; shape.ShapeColor = Color.Linen; shape.IsRoot = false; shape.parentNode = this; shape.Font = font; shape.level = level + 1; shape.Fit(); //fit the child //add to the collections site.graphAbstract.Shapes.Add(shape); this.childNodes.Add(shape); //add a connection; From=child, To=parent Connection con = new Connection(shape, this); site.Connections.Add(con); con.site = this.site; con.visible = true; shape.connection = con; if (visible) { Expand(); } else { shape.visible = false; con.visible = false; } Fit(); //the cild count added at the end will enlarge the rectangle, so we have to fit return(shape); }
/// <summary> /// Adds the root of the diagram to the canvas /// </summary> /// <param name="rootText"></param> private ShapeBase AddRoot(string rootText) { if (Shapes.Count > 0) { throw new Exception("You cannot set the root unless the diagram is empty"); } SimpleRectangle root = new SimpleRectangle(this); root.Location = new Point(Width / 2 + 50, Height / 2 + 50); root.Width = 50; root.Height = 25; root.Text = rootText; root.ShapeColor = Color.SteelBlue; root.IsRoot = true; root.Font = Font; root.visible = false; root.level = 0; Fit(root); //set the root of the diagram this.graphAbstract.Root = root; Shapes.Add(root); return(root); }
/// <summary> /// Adds a predefined shape /// </summary> /// <param name="type"></param> /// <param name="location"></param> public ShapeBase AddShape(ShapeTypes type, Point location) { ShapeBase shape = null; switch(type) { case ShapeTypes.Rectangular: shape = new SimpleRectangle(this); break; case ShapeTypes.Oval: shape = new OvalShape(this); break; case ShapeTypes.TextLabel: shape = new TextLabel(this); shape.Location = location; shape.ShapeColor = Color.Transparent; shape.Text = "A text label (change the text in the property grid)"; shape.Width = 350; shape.Height = 30; Shapes.Add(shape); return shape; } if(shape==null) return null; shape.ShapeColor = Color.FromArgb(rnd.Next(0,255),rnd.Next(0,255),rnd.Next(0,255)); shape.Location = location; Shapes.Add(shape); return shape; }
/// <summary> /// Adds the root of the diagram to the canvas /// </summary> /// <param name="rootText"></param> private ShapeBase AddRoot(string rootText) { if(Shapes.Count>0) throw new Exception("You cannot set the root unless the diagram is empty"); SimpleRectangle root = new SimpleRectangle(this); root.Location = new Point(Width/2+50,Height/2+50); root.Width = 50; root.Height = 25; root.Text = rootText; root.ShapeColor = Color.SteelBlue; root.IsRoot = true; root.Font = Font; root.visible = false; root.level = 0; Fit(root); //set the root of the diagram this.graphAbstract.Root = root; Shapes.Add(root); return root; }
/// <summary> /// Adds a child to this shape /// </summary> /// <param name="text">the text of the newly created shape</param> /// <returns>the create shape</returns> public ShapeBase AddChild(string text) { SimpleRectangle shape = new SimpleRectangle(site); shape.Location = new Point(Width/2+50,Height/2+50); shape.Width = 50; shape.Height = 25; shape.Text = text; shape.ShapeColor = Color.Linen; shape.IsRoot = false; shape.parentNode = this; shape.Font = font; shape.level = level+1; shape.Fit(); //fit the child //add to the collections site.graphAbstract.Shapes.Add(shape); this.childNodes.Add(shape); //add a connection; From=child, To=parent Connection con = new Connection(shape, this); site.Connections.Add(con); con.site = this.site; con.visible = true; shape.connection = con; if(visible) Expand(); else { shape.visible = false; con.visible = false; } Fit(); //the cild count added at the end will enlarge the rectangle, so we have to fit return shape; }