public virtual Shape AddFlowShape(string key, PointF location, FlowchartStencilType type) { StencilItem stencil = Stencil[type]; Shape shape = CreateElement(ShapeMode, location, type); Shapes.Add(key, shape); return(shape); }
public virtual Shape AddFlowShape(PointF location, FlowchartStencilType type) { StencilItem stencil = Stencil[type]; Shape shape = CreateElement(ShapeMode, location, type); Model.Shapes.Add(Model.Shapes.CreateKey(), shape); return(shape); }
public virtual object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) { StencilItem item = (StencilItem)obj; SerializationInfoEnumerator enumerator = info.GetEnumerator(); //Enumerate the info object and apply to the appropriate properties while (enumerator.MoveNext()) { if (enumerator.Name == "Key") { item.Key = info.GetString("Key"); } else if (enumerator.Name == "Redraw") { item.Redraw = info.GetBoolean("Redraw"); } else if (enumerator.Name == "BasePath") { item.SetBasePath(Serialize.GetPath(info.GetString("BasePath"))); } //else if (enumerator.Name == "BaseSize") item.SetBaseSize(Serialize.GetSizeF(info.GetString("BaseSize"))); else if (enumerator.Name == "BaseInternalRectangle") { item.SetBaseInternalRectangle(Serialize.GetRectangleF(info.GetString("BaseInternalRectangle")), 0, 0); } else if (enumerator.Name == "BorderColor") { item.BorderColor = Color.FromArgb(Convert.ToInt32(info.GetString("BorderColor"))); } else if (enumerator.Name == "BorderStyle") { item.BorderStyle = (DashStyle)Enum.Parse(typeof(DashStyle), info.GetString("BorderStyle")); } else if (enumerator.Name == "SmoothingMode") { item.SmoothingMode = (SmoothingMode)Enum.Parse(typeof(SmoothingMode), info.GetString("SmoothingMode")); } else if (enumerator.Name == "BackColor") { item.BackColor = Color.FromArgb(Convert.ToInt32(info.GetString("BackColor"))); } else if (enumerator.Name == "GradientColor ") { item.GradientColor = Color.FromArgb(Convert.ToInt32(info.GetString("GradientColor"))); } else if (enumerator.Name == "GradientMode") { item.GradientMode = (LinearGradientMode)Enum.Parse(typeof(LinearGradientMode), info.GetString("GradientMode"), true); } else if (enumerator.Name == "DrawGradient") { item.DrawGradient = info.GetBoolean("DrawGradient"); } } return(item); }
//Methods public virtual void Add(string key, StencilItem value ) { if (! Modifiable) throw new CollectionNotModifiableException("This collection is not modifiable."); if (value == null) throw new ArgumentNullException("value","StencilItem parameter cannot be null reference."); if (key == null) throw new ArgumentNullException("key","Key may not be null."); if (key == "") throw new ArgumentException("Key may not be null string.","key"); value.mKey = key; Dictionary.Add(key, value ); OnInsert(key,value); }
private void CreateStencilItems() { SetModifiable(true); //Loop through each enumeration and add as a stencil item foreach (string type in Enum.GetNames(typeof(FlowchartStencilType))) { StencilItem item = new StencilItem(); item.DrawShape +=new DrawShapeEventHandler(StencilItem_DrawShape); Add(type,item); } SetModifiable(false); }
private void CreateStencilItems() { SetModifiable(true); //Loop through each enumeration and add as a stencil item foreach (string type in Enum.GetNames(typeof(FlowchartStencilType))) { StencilItem item = new StencilItem(); item.DrawShape += new DrawShapeEventHandler(StencilItem_DrawShape); Add(type, item); } SetModifiable(false); }
public virtual void GetObjectData(object obj, SerializationInfo info, StreamingContext context) { StencilItem item = (StencilItem)obj; info.AddValue("Key", item.Key); info.AddValue("Redraw", item.Redraw); info.AddValue("BasePath", Serialize.AddPath(item.BasePath)); //info.AddValue("BaseSize", Serialize.AddSizeF(item.BaseSize)); info.AddValue("BaseInternalRectangle", Serialize.AddRectangleF(item.BaseInternalRectangle)); info.AddValue("BorderColor", item.BorderColor.ToArgb().ToString()); info.AddValue("BorderStyle", Convert.ToInt32(item.BorderStyle).ToString()); info.AddValue("SmoothingMode", Convert.ToInt32(item.SmoothingMode).ToString()); info.AddValue("BackColor", item.BackColor.ToArgb().ToString()); info.AddValue("GradientColor", item.GradientColor.ToArgb().ToString()); info.AddValue("GradientMode", Convert.ToInt32(item.GradientMode).ToString()); info.AddValue("DrawGradient", item.DrawGradient); info.AddValue("Options", Convert.ToInt32(item.Options).ToString()); }
public Shape(StencilItem stencil) { SuspendEvents = true; AllowMove = true; AllowScale = true; AllowRotate = false; DrawSelected = true; Direction = Direction.Both; Interaction = UserInteraction.BringToFront; MinimumSize = new SizeF(32, 32); MaximumSize = new SizeF(320, 320); //Set up stencil StencilItem = stencil; stencil.CopyTo(this); Ports = new Elements(typeof(Port),"Port"); SuspendEvents = false; }
//Handles the DrawShape event private void StencilItem_DrawShape(object sender, DrawShapeEventArgs e) { //Get the stencil item to draw on, and the type of arrow from the key StencilItem stencil = (StencilItem)sender; ArrowType arrowType = (ArrowType)Enum.Parse(typeof(ArrowType), stencil.Key); //Draw the arrow using a 100x100 grid e.Path.AddLine(0, 30, 60, 30); e.Path.AddLine(60, 30, 60, 0); e.Path.AddLine(60, 0, 100, 50); e.Path.AddLine(100, 50, 60, 100); e.Path.AddLine(60, 100, 60, 70); e.Path.AddLine(60, 70, 0, 70); //Close the figure e.Path.CloseFigure(); //Rotate the path depending on the type of arrow Matrix translateMatrix = new Matrix(); if (arrowType == ArrowType.Right) { translateMatrix.RotateAt(180, new PointF(50, 50)); } if (arrowType == ArrowType.Up) { translateMatrix.RotateAt(-90, new PointF(50, 50)); } if (arrowType == ArrowType.Down) { translateMatrix.RotateAt(90, new PointF(50, 50)); } //Scale the matrix and apply it back to the path translateMatrix.Scale(e.Width / 100, e.Height / 100); e.Path.Transform(translateMatrix); }
public SolidElement(SolidElement prototype): base(prototype) { mBlend = prototype.Blend; mCustomBrush = prototype.CustomBrush; mDrawBackground = prototype.DrawBackground; mDrawBorder = prototype.DrawBorder; mDrawGradient = prototype.DrawGradient; mBackColor = prototype.BackColor; mGradientColor = prototype.GradientColor; mGradientMode = prototype.GradientMode; mRotation = prototype.Rotation; mTransformPath = prototype.TransformPath; mTransformRectangle = prototype.TransformRectangle; mTransformInternalRectangle = prototype.TransformInternalRectangle; if (prototype.Label != null) Label = (TextLabel) prototype.Label.Clone(); if (prototype.Image != null) Image = (Image) prototype.Image.Clone(); mStencilItem = prototype.StencilItem; //if (prototype.StencilItem != null) mStencilItem = (StencilItem) prototype.StencilItem.Clone(); mInternalRectangle = prototype.InternalRectangle; }
private void DrawStencilItem(StencilItem stencil, DrawShapeEventArgs e) { GraphicsPath path = e.Path; RectangleF rect = new Rectangle(); FlowchartStencilType stencilType = (FlowchartStencilType) Enum.Parse(typeof(FlowchartStencilType), stencil.Key); float width = e.Width; float height = e.Height; float percX = 0; float percY = 0; float perc = 0; float midX = 0; float midY = 0; rect.Width = width; rect.Height = height; midX = width / 2; midY = height / 2; if (stencilType == FlowchartStencilType.Default) { percX = 20; percY = 20; path.AddArc(0, 0, percX, percY, 180, 90); path.AddArc(width - percX, 0, percX, percY, 270, 90); path.AddArc(width - percX, height - percY, percX, percY, 0, 90); path.AddArc(0, height - percY, percX, percY, 90, 90); path.CloseFigure(); stencil.Redraw = true; } else if (stencilType == FlowchartStencilType.Card) { percX = width * 0.2F; percY = height * 0.2F; path.AddLine(percX, 0, width, 0); path.AddLine(width, 0, width, height); path.AddLine(width, height, 0, height); path.AddLine(0, height, 0, percY); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Collate) { path.AddLine(0, 0, width, 0); path.AddLine(width, 0, 0, height); path.AddLine(0, height, width, height); path.AddLine(width, height, 0, 0); } else if (stencilType == FlowchartStencilType.Connector) { percX = width * 0.5F; percY = height * 0.5F; path.AddEllipse(percX, percY, width, height); } else if (stencilType == FlowchartStencilType.Data) { path.AddLine(midX / 2, 0, width, 0); path.AddLine(width, 0, (midX / 2) + midX, height); path.AddLine((midX / 2) + midX, height, 0, height); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Decision) { path.AddLine(midX, 0, width, midY); path.AddLine(width, midY, midX, height); path.AddLine(midX, height, 0, midY); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Delay) { percX = width * 0.2F; path.AddArc(percX, 0 , width * 0.8F, height, 270, 180); path.AddLine(0, height, 0, 0); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Display) { percX = width * 0.2F; path.AddArc(percX, 0 , width * 0.8F, height, 270, 180); path.AddLine(percX, height, 0, height / 2); path.AddLine(0, height / 2,percX, 0); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Direct) { percX = width * 0.3F; path.AddLine(width * 0.7F, height, percX, height); path.AddArc(0, 0, percX, height, 90, 180); path.AddLine(width * 0.7F, 0, percX, 0); path.AddArc(width * 0.7F, 0, percX, height, 270, -180); path.CloseFigure(); path.StartFigure(); path.AddEllipse(width * 0.7F, 0, percX, height); } else if (stencilType == FlowchartStencilType.Document) { PointF[] points = new PointF[4]; points[0].X = 0; points[0].Y = height * 0.95F; points[1].X = width * 0.25F; points[1].Y = height; points[2].X = width * 0.75F; points[2].Y = height * 0.85F; points[3].X = width; points[3].Y = height * 0.8F; path.AddLine(new Point(0, 0), points[0]); path.AddCurve(points); path.AddLine(points[3], new PointF(width, 0)); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Extract) { percX = width * 0.25F; percY = height * 0.75F; path.AddLine(percX, 0, percX * 2, percY); path.AddLine(percX * 2, percY, 0, percY); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.InternalStorage) { perc = width * 0.15F; path.AddRectangle(rect); path.AddLine(perc, 0, perc, height); path.CloseFigure(); path.AddLine(0, perc, width, perc); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.ManualInput) { percY = height * 0.25F; path.AddLine(0, percY, width, 0); path.AddLine(width, 0, width, height); path.AddLine(width, height, 0, height); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.ManualOperation) { percX = width * 0.2F; path.AddLine(0, 0, width, 0); path.AddLine(width, 0, width - percX, height); path.AddLine(width - percX, height, percX, height); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.MultiDocument) { PointF[] points = new PointF[4]; width = width * 0.8F; points[0].X = 0; points[0].Y = height * 0.95F; points[1].X = width * 0.25F; points[1].Y = height; points[2].X = width * 0.75F; points[2].Y = height * 0.85F; points[3].X = width; points[3].Y = height * 0.8F; path.AddLine(new PointF(0, height * 0.2F), points[0]); path.AddCurve(points); path.AddLine(points[3], new PointF(width, height * 0.2F)); path.CloseFigure(); width = rect.Width; path.AddLine(width * 0.2F, height * 0.1F, width * 0.2F, 0); path.AddLine(width * 0.2F, 0, width, 0); path.AddLine(width, 0, width, height * 0.6F); path.AddLine(width, height * 0.6F, width * 0.9F, height * 0.6F); path.AddLine(width * 0.9F, height * 0.6F, width * 0.9F, height * 0.1F); path.CloseFigure(); path.AddLine(width * 0.1F, height * 0.2F, width * 0.1F, height * 0.1F); path.AddLine(width * 0.1F, height * 0.1F, width * 0.9F, height * 0.1F); path.AddLine(width * 0.9F, height * 0.1F, width * 0.9F, height * 0.7F); path.AddLine(width * 0.9F, height * 0.7F, width * 0.8F, height * 0.7F); path.AddLine(width * 0.8F, height * 0.7F, width * 0.8F, height * 0.2F); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.OffPageConnector) { percX = width * 0.5F; percY = height * 0.75F; path.AddLine(0, 0, width, 0); path.AddLine(width, 0, width , percY); path.AddLine(width, percY, percX, height); path.AddLine(percX, height, 0, percY); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.PredefinedProcess) { perc = width * 0.1F; path.AddRectangle(rect); path.CloseFigure(); path.AddLine(perc, 0, perc, height); path.CloseFigure(); path.AddLine(width - perc, 0, width - perc, height); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Preparation) { percX = width * 0.2F; path.AddLine(0, midY, percX, 0); path.AddLine(percX, 0, width - percX, 0); path.AddLine(width - percX, 0, width, midY); path.AddLine(width, midY, width - percX, height); path.AddLine(width - percX, height, percX, height); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Process) { path.AddRectangle(new RectangleF(0, 0, width, height)); } else if (stencilType == FlowchartStencilType.Process2) { percX = width * 0.2F; percY = height * 0.2F; if (percX < percY) { percY = percX; } else { percX = percY; } path.AddArc(0, 0, percX, percY, 180, 90); path.AddArc(width - percX, 0, percX, percY, 270, 90); path.AddArc(width - percX, height - percY, percX, percY, 0, 90); path.AddArc(0, height - percY, percX, percY, 90, 90); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Terminator) { percX = width * 0.5F; percY = height * 0.20F; path.AddArc(0, percY, percX, percY * 2, 90, 180); path.AddArc(width - percX, percY, percX, percY * 2, 270, 180); path.CloseFigure(); stencil.KeepAspect = true; } else if (stencilType == FlowchartStencilType.Tape) { PointF[] points = new PointF[5]; PointF[] pointsBottom = new PointF[5]; points[0].X = 0; points[0].Y = height * 0.05F; points[1].X = width * 0.25F; points[1].Y = height * 0.1F; points[2].X = width * 0.5F; points[2].Y = height * 0.05F; points[3].X = width * 0.75F; points[3].Y = 0; points[4].X = width; points[4].Y = height * 0.05F; pointsBottom[4].X = 0; pointsBottom[4].Y = height * 0.95F; pointsBottom[3].X = width * 0.25F; pointsBottom[3].Y = height; pointsBottom[2].X = width * 0.5F; pointsBottom[2].Y = height * 0.95F; pointsBottom[1].X = width * 0.75F; pointsBottom[1].Y = height * 0.9F; pointsBottom[0].X = width; pointsBottom[0].Y = height * 0.95F; path.AddCurve(points); path.AddLine(points[4], pointsBottom[0]); path.AddCurve(pointsBottom); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Junction) { percX = width * 0.25F; percY = height * 0.25F; if (percX > percY) { perc = percX; } else { perc = percY; } path.AddEllipse(perc, perc, perc * 2, perc * 2); path.CloseFigure(); path.StartFigure(); path.AddLine(perc * 2, perc, perc * 2, perc * 3); path.StartFigure(); path.AddLine(perc, perc * 2, perc * 3, perc * 2); Matrix matrix = new Matrix(1, 0, 0, 1, 0, 0); //Rotate the matrix through 45 degress perc = perc * 2; matrix.RotateAt(45, new PointF(perc, perc)); //Transform the graphicspath object path.Transform(matrix); } else if (stencilType == FlowchartStencilType.LogicalOr) { percX = width * 0.5F; percY = height * 0.5F; if (percX > percY) { perc = percX; } else { perc = percY; } path.AddEllipse(perc, perc, perc * 2, perc * 2); path.AddLine(perc * 2, perc, perc * 2, perc * 3); path.CloseFigure(); path.AddLine(perc, perc * 2, perc * 3, perc * 2); } else if (stencilType == FlowchartStencilType.Sort) { percX = width * 0.5F; percY = height * 0.5F; path.AddLine(0, percY, percX, 0); path.AddLine(percX, 0, width, percY); path.AddLine(width, percY, percX, height); path.AddLine(percX, height, 0, percY); path.CloseFigure(); path.StartFigure(); path.AddLine(0,percY, width, percY); } else if (stencilType == FlowchartStencilType.Merge) { path.AddLine(0, 0, width, 0); path.AddLine(width, 0, width * 0.5F, height); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.StoredData) { percX = width * 0.3F; path.AddArc(0, 0, percX, height, 90, 180); path.AddArc(width * 0.85F, 0, percX, height, 270, -180); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Sequential) { if (width > height) { perc = height; } else { perc = width; } path.AddArc(0, 0, perc, perc, 45, -315); path.AddLine(perc * 0.5F, perc, perc, perc); path.AddLine(perc, perc, perc, perc * 0.85F); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Magnetic) { percY = height * 0.4F; path.AddArc(0, - height * 0.2F, width, percY, 180, -180); path.AddLine(width, 0, width, height * 0.8F); path.AddArc(0, height * 0.6F, width, percY, 0, 180); path.AddLine(0, height * 0.8F, 0, 0); //path.CloseFigure(); //Define two shapes so that not see through path.StartFigure(); path.AddLine(0, 0, width, 0); path.AddArc(0, - height * 0.2F, width, percY, 0, 180); } }
private void CreateDefaultStencilItem() { mDefaultStencilItem = new StencilItem(); mDefaultStencilItem.Redraw = true; }
public virtual Shape AddShape(string key,PointF location,SizeF size, StencilItem stencil) { return AddShapeImplementation(key,location,stencil, size); }
private void StencilItem_DrawShape(object sender, DrawShapeEventArgs e) { StencilItem stencil = (StencilItem)sender; DrawStencilItem(stencil, e); }
private void DrawStencilItem(StencilItem stencil, DrawShapeEventArgs e) { ArrowStencilType stencilType = (ArrowStencilType) Enum.Parse(typeof(ArrowStencilType),stencil.Key); Matrix translateMatrix = new Matrix(); if (stencilType == ArrowStencilType.Left || stencilType == ArrowStencilType.Right || stencilType == ArrowStencilType.Up || stencilType == ArrowStencilType.Down) { //Draw the arrow using a 100x100 grid e.Path.AddLine(0,30,60,30); e.Path.AddLine(60,30,60,0); e.Path.AddLine(60,0,100,50); e.Path.AddLine(100,50,60,100); e.Path.AddLine(60,100,60,70); e.Path.AddLine(60,70,0,70); //Close the figure e.Path.CloseFigure(); //Rotate the path depending on the type of arrow if (stencilType == ArrowStencilType.Right) translateMatrix.RotateAt(180,new PointF(50,50)); if (stencilType == ArrowStencilType.Up) translateMatrix.RotateAt(-90,new PointF(50,50)); if (stencilType == ArrowStencilType.Down) translateMatrix.RotateAt(90,new PointF(50,50)); //Scale the matrix and apply it back to the path translateMatrix.Scale(e.Width / 100, e.Height / 100); e.Path.Transform(translateMatrix); } else if (stencilType == ArrowStencilType.LeftRight || stencilType == ArrowStencilType.UpDown) { //Draw the arrow using a 120x100 grid e.Path.AddLine(40,30,80,30); e.Path.AddLine(80,30,80,0); e.Path.AddLine(80,0,120,50); e.Path.AddLine(120,50,80,100); e.Path.AddLine(80,100,80,70); e.Path.AddLine(80,70,40,70); e.Path.AddLine(40,70,40,100); e.Path.AddLine(40,100,0,50); e.Path.AddLine(0,50,40,0); e.Path.AddLine(40,0,40,30); if (stencilType == ArrowStencilType.UpDown) translateMatrix.RotateAt(90,new PointF(50,50)); //Scale the matrix and apply it back to the path translateMatrix.Scale(e.Width / 120, e.Height / 100); e.Path.Transform(translateMatrix); stencil.Options = StencilItemOptions.InnerRectangleFull; } else if (stencilType == ArrowStencilType.LeftRightUpDown) { //Draw the arrow using a 140x140 grid e.Path.AddLine(80,60,110,60); e.Path.AddLine(110,60,110,50); e.Path.AddLine(110,50,140,70); e.Path.AddLine(140,70,110,90); e.Path.AddLine(110,90,110,80); e.Path.AddLine(110,80,80,80); e.Path.AddLine(80,80,80,110); e.Path.AddLine(80,110,90,110); e.Path.AddLine(90,110,70,140); e.Path.AddLine(70,140,50,110); e.Path.AddLine(50,110,60,110); e.Path.AddLine(60,110,60,80); e.Path.AddLine(60,80,30,80); e.Path.AddLine(30,80,30,90); e.Path.AddLine(30,90,0,70); e.Path.AddLine(0,70,30,50); e.Path.AddLine(30,50,30,60); e.Path.AddLine(30,60,60,60); e.Path.AddLine(60,60,60,30); e.Path.AddLine(60,30,50,30); e.Path.AddLine(50,30,70,0); e.Path.AddLine(70,0,90,30); e.Path.AddLine(90,30,80,30); e.Path.AddLine(80,30,80,60); //Scale the matrix and apply it back to the path translateMatrix.Scale(e.Width / 140, e.Height / 140); e.Path.Transform(translateMatrix); } if (stencilType == ArrowStencilType.Striped) { //Draw the arrow using a 100x100 grid e.Path.AddRectangle(new Rectangle(0,30,4,40)); e.Path.AddRectangle(new Rectangle(8,30,8,40)); e.Path.AddLine(20,30,60,30); e.Path.AddLine(60,30,60,0); e.Path.AddLine(60,0,100,50); e.Path.AddLine(100,50,60,100); e.Path.AddLine(60,100,60,70); e.Path.AddLine(60,70,20,70); //Close the figure e.Path.CloseFigure(); //Scale the matrix and apply it back to the path translateMatrix.Scale(e.Width / 100, e.Height / 100); e.Path.Transform(translateMatrix); stencil.Options = StencilItemOptions.InnerRectangleFull; } if (stencilType == ArrowStencilType.Notched) { //Draw the arrow using a 100x100 grid e.Path.AddLine(0,30,60,30); e.Path.AddLine(60,30,60,0); e.Path.AddLine(60,0,100,50); e.Path.AddLine(100,50,60,100); e.Path.AddLine(60,100,60,70); e.Path.AddLine(60,70,0,70); e.Path.AddLine(0,70,20,50); //Close the figure e.Path.CloseFigure(); //Scale the matrix and apply it back to the path translateMatrix.Scale(e.Width / 100, e.Height / 100); e.Path.Transform(translateMatrix); } if (stencilType == ArrowStencilType.Pentagon) { //Draw the arrow using a 120x100 grid e.Path.AddLine(0,0,80,0); e.Path.AddLine(80,0,120,50); e.Path.AddLine(120,50,80,100); e.Path.AddLine(80,100,0,100); //Close the figure e.Path.CloseFigure(); //Scale the matrix and apply it back to the path translateMatrix.Scale(e.Width / 100, e.Height / 100); e.Path.Transform(translateMatrix); } else if (stencilType == ArrowStencilType.Chevron) { //Draw the arrow using a 120x100 grid e.Path.AddLine(0,0,80,0); e.Path.AddLine(80,0,120,50); e.Path.AddLine(120,50,80,100); e.Path.AddLine(80,100,0,100); e.Path.AddLine(0,100,20,50); //Close the figure e.Path.CloseFigure(); //Scale the matrix and apply it back to the path translateMatrix.Scale(e.Width / 100, e.Height / 100); e.Path.Transform(translateMatrix); } else if (stencilType == ArrowStencilType.RightCallout || stencilType == ArrowStencilType.LeftCallout || stencilType == ArrowStencilType.UpCallout || stencilType == ArrowStencilType.DownCallout) { //Draw the arrow using a 120x100 grid e.Path.AddLine(0,0,80,0); e.Path.AddLine(80,0,80,40); e.Path.AddLine(80,40,90,40); e.Path.AddLine(90,40,90,30); e.Path.AddLine(90,30,120,50); e.Path.AddLine(120,50,90,70); e.Path.AddLine(90,70,90,60); e.Path.AddLine(90,60,80,60); e.Path.AddLine(80,60,80,100); e.Path.AddLine(80,100,0,100); //Close the figure e.Path.CloseFigure(); //Rotate the matrix depending on type if (stencilType == ArrowStencilType.LeftCallout) translateMatrix.RotateAt(180,new PointF(60,50)); if (stencilType == ArrowStencilType.UpCallout) translateMatrix.RotateAt(-90,new PointF(60,50)); if (stencilType == ArrowStencilType.DownCallout) translateMatrix.RotateAt(90,new PointF(60,50)); //Scale the matrix and apply it back to the path translateMatrix.Scale(e.Width / 100, e.Height / 100); e.Path.Transform(translateMatrix); } }
//Deserializes info into a new solid element protected SolidElement(SerializationInfo info, StreamingContext context): base(info,context) { SuspendEvents = true; BackColor = Color.FromArgb(Convert.ToInt32(info.GetString("BackColor"))); Clip = info.GetBoolean("Clip"); GradientMode = (LinearGradientMode) Enum.Parse(typeof(LinearGradientMode), info.GetString("GradientMode"),true); GradientColor = Color.FromArgb(Convert.ToInt32(info.GetString("GradientColor"))); DrawGradient = info.GetBoolean("DrawGradient"); DrawBorder = info.GetBoolean("DrawBorder"); DrawBackground = info.GetBoolean("DrawBackground"); Location = Serialize.GetPointF(info.GetString("Location")); SetInternalRectangle(Serialize.GetRectangleF(info.GetString("InternalRectangle"))); if (Serialize.Contains(info,"Rotation")) Rotation = info.GetSingle("Rotation"); if (Serialize.Contains(info,"Label",typeof(TextLabel))) Label = (TextLabel) info.GetValue("Label",typeof(TextLabel)); if (Serialize.Contains(info,"Image",typeof(Image))) Image = (Image) info.GetValue("Image",typeof(Image)); if (Serialize.Contains(info,"StencilItem",typeof(StencilItem))) mStencilItem = (StencilItem) info.GetValue("StencilItem",typeof(StencilItem)); SuspendEvents = false; }
private Shape AddShapeImplementation(string key,PointF location, StencilItem stencil, SizeF size) { Shape shape = Runtime.CreateShape(location,size); shape.Location = location; //Set values if not provided if (key == null || key == "") key = Runtime.ActiveContainer.Shapes.CreateKey(); if (stencil == null) stencil = Component.Instance.DefaultStencilItem; //Set size if (!size.IsEmpty) shape.Size = size; //Set shape's stencil shape.StencilItem = stencil; stencil.CopyTo(shape); //Add and return the new shape Runtime.ActiveContainer.Shapes.Add(key,shape); return shape; }
private void DrawStencilItem(StencilItem stencil, DrawShapeEventArgs e) { GraphicsPath path = e.Path; RectangleF rect = new Rectangle(); FlowchartStencilType stencilType = (FlowchartStencilType)Enum.Parse(typeof(FlowchartStencilType), stencil.Key); float width = e.Width; float height = e.Height; float percX = 0; float percY = 0; float perc = 0; float midX = 0; float midY = 0; rect.Width = width; rect.Height = height; midX = width / 2; midY = height / 2; if (stencilType == FlowchartStencilType.Default) { percX = 20; percY = 20; path.AddArc(0, 0, percX, percY, 180, 90); path.AddArc(width - percX, 0, percX, percY, 270, 90); path.AddArc(width - percX, height - percY, percX, percY, 0, 90); path.AddArc(0, height - percY, percX, percY, 90, 90); path.CloseFigure(); stencil.Redraw = true; } else if (stencilType == FlowchartStencilType.Card) { percX = width * 0.2F; percY = height * 0.2F; path.AddLine(percX, 0, width, 0); path.AddLine(width, 0, width, height); path.AddLine(width, height, 0, height); path.AddLine(0, height, 0, percY); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Collate) { path.AddLine(0, 0, width, 0); path.AddLine(width, 0, 0, height); path.AddLine(0, height, width, height); path.AddLine(width, height, 0, 0); } else if (stencilType == FlowchartStencilType.Connector) { percX = width * 0.5F; percY = height * 0.5F; path.AddEllipse(percX, percY, width, height); } else if (stencilType == FlowchartStencilType.Data) { path.AddLine(midX / 2, 0, width, 0); path.AddLine(width, 0, (midX / 2) + midX, height); path.AddLine((midX / 2) + midX, height, 0, height); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Decision) { path.AddLine(midX, 0, width, midY); path.AddLine(width, midY, midX, height); path.AddLine(midX, height, 0, midY); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Delay) { percX = width * 0.2F; path.AddArc(percX, 0, width * 0.8F, height, 270, 180); path.AddLine(0, height, 0, 0); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Display) { percX = width * 0.2F; path.AddArc(percX, 0, width * 0.8F, height, 270, 180); path.AddLine(percX, height, 0, height / 2); path.AddLine(0, height / 2, percX, 0); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Direct) { percX = width * 0.3F; path.AddLine(width * 0.7F, height, percX, height); path.AddArc(0, 0, percX, height, 90, 180); path.AddLine(width * 0.7F, 0, percX, 0); path.AddArc(width * 0.7F, 0, percX, height, 270, -180); path.CloseFigure(); path.StartFigure(); path.AddEllipse(width * 0.7F, 0, percX, height); } else if (stencilType == FlowchartStencilType.Document) { PointF[] points = new PointF[4]; points[0].X = 0; points[0].Y = height * 0.95F; points[1].X = width * 0.25F; points[1].Y = height; points[2].X = width * 0.75F; points[2].Y = height * 0.85F; points[3].X = width; points[3].Y = height * 0.8F; path.AddLine(new Point(0, 0), points[0]); path.AddCurve(points); path.AddLine(points[3], new PointF(width, 0)); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Extract) { percX = width * 0.25F; percY = height * 0.75F; path.AddLine(percX, 0, percX * 2, percY); path.AddLine(percX * 2, percY, 0, percY); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.InternalStorage) { perc = width * 0.15F; path.AddRectangle(rect); path.AddLine(perc, 0, perc, height); path.CloseFigure(); path.AddLine(0, perc, width, perc); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.ManualInput) { percY = height * 0.25F; path.AddLine(0, percY, width, 0); path.AddLine(width, 0, width, height); path.AddLine(width, height, 0, height); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.ManualOperation) { percX = width * 0.2F; path.AddLine(0, 0, width, 0); path.AddLine(width, 0, width - percX, height); path.AddLine(width - percX, height, percX, height); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.MultiDocument) { PointF[] points = new PointF[4]; width = width * 0.8F; points[0].X = 0; points[0].Y = height * 0.95F; points[1].X = width * 0.25F; points[1].Y = height; points[2].X = width * 0.75F; points[2].Y = height * 0.85F; points[3].X = width; points[3].Y = height * 0.8F; path.AddLine(new PointF(0, height * 0.2F), points[0]); path.AddCurve(points); path.AddLine(points[3], new PointF(width, height * 0.2F)); path.CloseFigure(); width = rect.Width; path.AddLine(width * 0.2F, height * 0.1F, width * 0.2F, 0); path.AddLine(width * 0.2F, 0, width, 0); path.AddLine(width, 0, width, height * 0.6F); path.AddLine(width, height * 0.6F, width * 0.9F, height * 0.6F); path.AddLine(width * 0.9F, height * 0.6F, width * 0.9F, height * 0.1F); path.CloseFigure(); path.AddLine(width * 0.1F, height * 0.2F, width * 0.1F, height * 0.1F); path.AddLine(width * 0.1F, height * 0.1F, width * 0.9F, height * 0.1F); path.AddLine(width * 0.9F, height * 0.1F, width * 0.9F, height * 0.7F); path.AddLine(width * 0.9F, height * 0.7F, width * 0.8F, height * 0.7F); path.AddLine(width * 0.8F, height * 0.7F, width * 0.8F, height * 0.2F); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.OffPageConnector) { percX = width * 0.5F; percY = height * 0.75F; path.AddLine(0, 0, width, 0); path.AddLine(width, 0, width, percY); path.AddLine(width, percY, percX, height); path.AddLine(percX, height, 0, percY); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.PredefinedProcess) { perc = width * 0.1F; path.AddRectangle(rect); path.CloseFigure(); path.AddLine(perc, 0, perc, height); path.CloseFigure(); path.AddLine(width - perc, 0, width - perc, height); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Preparation) { percX = width * 0.2F; path.AddLine(0, midY, percX, 0); path.AddLine(percX, 0, width - percX, 0); path.AddLine(width - percX, 0, width, midY); path.AddLine(width, midY, width - percX, height); path.AddLine(width - percX, height, percX, height); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Process) { path.AddRectangle(new RectangleF(0, 0, width, height)); } else if (stencilType == FlowchartStencilType.Process2) { percX = width * 0.2F; percY = height * 0.2F; if (percX < percY) { percY = percX; } else { percX = percY; } path.AddArc(0, 0, percX, percY, 180, 90); path.AddArc(width - percX, 0, percX, percY, 270, 90); path.AddArc(width - percX, height - percY, percX, percY, 0, 90); path.AddArc(0, height - percY, percX, percY, 90, 90); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Terminator) { percX = width * 0.5F; percY = height * 0.20F; path.AddArc(0, percY, percX, percY * 2, 90, 180); path.AddArc(width - percX, percY, percX, percY * 2, 270, 180); path.CloseFigure(); stencil.KeepAspect = true; } else if (stencilType == FlowchartStencilType.Tape) { PointF[] points = new PointF[5]; PointF[] pointsBottom = new PointF[5]; points[0].X = 0; points[0].Y = height * 0.05F; points[1].X = width * 0.25F; points[1].Y = height * 0.1F; points[2].X = width * 0.5F; points[2].Y = height * 0.05F; points[3].X = width * 0.75F; points[3].Y = 0; points[4].X = width; points[4].Y = height * 0.05F; pointsBottom[4].X = 0; pointsBottom[4].Y = height * 0.95F; pointsBottom[3].X = width * 0.25F; pointsBottom[3].Y = height; pointsBottom[2].X = width * 0.5F; pointsBottom[2].Y = height * 0.95F; pointsBottom[1].X = width * 0.75F; pointsBottom[1].Y = height * 0.9F; pointsBottom[0].X = width; pointsBottom[0].Y = height * 0.95F; path.AddCurve(points); path.AddLine(points[4], pointsBottom[0]); path.AddCurve(pointsBottom); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Junction) { percX = width * 0.25F; percY = height * 0.25F; if (percX > percY) { perc = percX; } else { perc = percY; } path.AddEllipse(perc, perc, perc * 2, perc * 2); path.CloseFigure(); path.StartFigure(); path.AddLine(perc * 2, perc, perc * 2, perc * 3); path.StartFigure(); path.AddLine(perc, perc * 2, perc * 3, perc * 2); Matrix matrix = new Matrix(1, 0, 0, 1, 0, 0); //Rotate the matrix through 45 degress perc = perc * 2; matrix.RotateAt(45, new PointF(perc, perc)); //Transform the graphicspath object path.Transform(matrix); } else if (stencilType == FlowchartStencilType.LogicalOr) { percX = width * 0.5F; percY = height * 0.5F; if (percX > percY) { perc = percX; } else { perc = percY; } path.AddEllipse(perc, perc, perc * 2, perc * 2); path.AddLine(perc * 2, perc, perc * 2, perc * 3); path.CloseFigure(); path.AddLine(perc, perc * 2, perc * 3, perc * 2); } else if (stencilType == FlowchartStencilType.Sort) { percX = width * 0.5F; percY = height * 0.5F; path.AddLine(0, percY, percX, 0); path.AddLine(percX, 0, width, percY); path.AddLine(width, percY, percX, height); path.AddLine(percX, height, 0, percY); path.CloseFigure(); path.StartFigure(); path.AddLine(0, percY, width, percY); } else if (stencilType == FlowchartStencilType.Merge) { path.AddLine(0, 0, width, 0); path.AddLine(width, 0, width * 0.5F, height); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.StoredData) { percX = width * 0.3F; path.AddArc(0, 0, percX, height, 90, 180); path.AddArc(width * 0.85F, 0, percX, height, 270, -180); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Sequential) { if (width > height) { perc = height; } else { perc = width; } path.AddArc(0, 0, perc, perc, 45, -315); path.AddLine(perc * 0.5F, perc, perc, perc); path.AddLine(perc, perc, perc, perc * 0.85F); path.CloseFigure(); } else if (stencilType == FlowchartStencilType.Magnetic) { percY = height * 0.4F; path.AddArc(0, -height * 0.2F, width, percY, 180, -180); path.AddLine(width, 0, width, height * 0.8F); path.AddArc(0, height * 0.6F, width, percY, 0, 180); path.AddLine(0, height * 0.8F, 0, 0); //path.CloseFigure(); //Define two shapes so that not see through path.StartFigure(); path.AddLine(0, 0, width, 0); path.AddArc(0, -height * 0.2F, width, percY, 0, 180); } }
public virtual Shape AddShape(PointF location, SizeF size, StencilItem stencil) { return AddShapeImplementation(Shapes.CreateKey(),location,stencil, size); }
private void DrawStencilItem(StencilItem stencil, DrawShapeEventArgs e) { GraphicsPath path = e.Path; RectangleF rect = new Rectangle(); BasicStencilType stencilType = (BasicStencilType) Enum.Parse(typeof(BasicStencilType),stencil.Key); float width = e.Width; float height = e.Height; float percX = 0; float percY = 0; float midX = 0; float midY = 0; rect.Width = width; rect.Height = height; if (stencilType == BasicStencilType.BottomTriangle) { path.AddLine(0, 0, width, 0); path.AddLine(width, 0, width / 2, height); path.CloseFigure(); } else if (stencilType == BasicStencilType.Circle) { percX = Convert.ToSingle(width * 0.5); percY = Convert.ToSingle(height * 0.5); path.AddEllipse(percX, percY, width, height); } else if (stencilType == BasicStencilType.Diamond) { percX = Convert.ToSingle(width * 0.5); percY = Convert.ToSingle(height * 0.5); path.AddLine(0, percY, percX, 0); path.AddLine(percX, 0, width, percY); path.AddLine(width, percY, percX, height); path.AddLine(percX, height, 0, percY); } else if (stencilType == BasicStencilType.Ellipse) { percX = Convert.ToSingle(width * 0.5); percY = Convert.ToSingle(height * 0.5); path.AddEllipse(percX, percY, width, height); } else if (stencilType == BasicStencilType.LeftTriangle) { percX = Convert.ToSingle(width * 0.5); percY = Convert.ToSingle(height * 0.5); path.AddLine(width, 0, 0, percY); path.AddLine(0, percY, width, height); path.CloseFigure(); } else if (stencilType == BasicStencilType.Octagon) { float thirdx = width * 0.3F; float twothirdx = width * 0.7F; float thirdy = height * 0.3F; float twothirdy = height *0.7F; path.AddLine(thirdx, 0, twothirdx, 0); path.AddLine(twothirdx, 0, width, thirdy); path.AddLine(width, thirdy, width, twothirdy); path.AddLine(width,twothirdy, twothirdx, height); path.AddLine(twothirdx, height, thirdx, height); path.AddLine(thirdx, height, 0, twothirdy); path.AddLine(0, twothirdy, 0, thirdy); path.CloseFigure(); } else if (stencilType == BasicStencilType.Rectangle) { path.AddRectangle(rect); } else if (stencilType == BasicStencilType.RightTriangle) { percY = height * 0.5F; path.AddLine(0, 0, width, percY); path.AddLine(width, percY, 0, height); path.CloseFigure(); } else if (stencilType == BasicStencilType.RoundedRectangle) { percX = Convert.ToSingle(width * 0.2); percY = Convert.ToSingle(height * 0.2); if (percX < percY) { percY = percX; } else { percX = percY; } path.AddArc(0, 0, percX, percY, 180, 90); path.AddArc(width - percX, 0, percX, percY, 270, 90); path.AddArc(width - percX, height - percY, percX, percY, 0, 90); path.AddArc(0, height - percY, percX, percY, 90, 90); path.CloseFigure(); stencil.Redraw = true; } else if (stencilType == BasicStencilType.TopTriangle) { percX = Convert.ToSingle(width * 0.5); path.AddLine(percX, 0, width, height); path.AddLine(width, height, 0, height); path.CloseFigure(); } }