static public ShapeTemplate GetShapeTemplate(GraphicStencil stencil) { int i; if (stencil != null) { ElementTemplate[] elementTemplate = new ElementTemplate[stencil.Elements.Count]; i = 0; foreach (Element element in stencil.Elements) { elementTemplate[i] = Element(element); i++; } ElementTemplate[] decorationTemplate = new ElementTemplate[stencil.Decorations.Count]; i = 0; foreach (Element decoration in stencil.Decorations) { decorationTemplate[i] = Element(decoration); i++; } return (new ShapeTemplate(elementTemplate, decorationTemplate, null, stencil.fillMode, stencil.Tag)); } else return null; }
private void UpdateStencil(ModelStencil modelStencil) { double minX = float.MaxValue; double maxX = float.MinValue; double minY = float.MaxValue; double maxY = float.MinValue; UpdateStencil(modelStencil.Elements, ref minX, ref minY, ref maxX, ref maxY); UpdateStencil(modelStencil.Decorations, ref minX, ref minY, ref maxX, ref maxY); double anchorMinX = minX; double anchorMaxX = maxX; double anchorMinY = minY; double anchorMaxY = maxY; UpdateStencil(modelStencil.Anchors, ref anchorMinX, ref anchorMinY, ref anchorMaxX, ref anchorMaxY); ScaleStencil(modelStencil.Elements, minX, minY, maxX, maxY); ScaleStencil(modelStencil.Decorations, minX, minY, maxX, maxY); ScaleStencil(modelStencil.Anchors, minX, minY, maxX, maxY); double scale = 1000.0F / Math.Max((maxX - minX), (maxY - minY)); SysCAD.Protocol.Rectangle rect = new SysCAD.Protocol.Rectangle(minX * scale, minY * scale, (maxX - minX) * scale, (maxY - minY) * scale); box2.BoundingRect = rect; { int i; ModelStencil stencil = modelStencil; bool mirrorX = false; bool mirrorY = false; ElementTemplate[] elementTemplate = new ElementTemplate[stencil.Elements.Count]; i = 0; foreach (Element element in stencil.Elements) { if (element is Arc) { Arc arc = element as Arc; elementTemplate[i] = new ArcTemplate((float)arc.x, (float)arc.y, (float)arc.w, (float)arc.h, (float)arc.a, (float)arc.s); } if (element is Line) { Line line = element as Line; double x1, y1, x2, y2; if (mirrorX) x1 = 100.0 - line.x1; else x1 = line.x1; if (mirrorY) y1 = 100.0 - line.y1; else y1 = line.y1; if (mirrorX) x2 = 100.0F - line.x2; else x2 = line.x2; if (mirrorY) y2 = 100.0 - line.y2; else y2 = line.y2; elementTemplate[i] = new LineTemplate((float)x1, (float)y1, (float)x2, (float)y2); } if (element is Bezier) { Bezier bezier = element as Bezier; double x1, y1, x2, y2, x3, y3, x4, y4; if (mirrorX) x1 = 100.0 - bezier.x1; else x1 = bezier.x1; if (mirrorY) y1 = 100.0 - bezier.y1; else y1 = bezier.y1; if (mirrorX) x2 = 100.0 - bezier.x2; else x2 = bezier.x2; if (mirrorY) y2 = 100.0 - bezier.y2; else y2 = bezier.y2; if (mirrorX) x3 = 100.0 - bezier.x3; else x3 = bezier.x3; if (mirrorY) y3 = 100.0 - bezier.y3; else y3 = bezier.y3; if (mirrorX) x4 = 100.0 - bezier.x4; else x4 = bezier.x4; if (mirrorY) y4 = 100.0 - bezier.y4; else y4 = bezier.y4; elementTemplate[i] = new BezierTemplate((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4); } i++; } ElementTemplate[] decorationTemplate = new ElementTemplate[stencil.Decorations.Count]; i = 0; foreach (Element decoration in stencil.Decorations) { if (decoration is Arc) { Arc arc = decoration as Arc; decorationTemplate[i] = new ArcTemplate((float)arc.x, (float)arc.y, (float)arc.w, (float)arc.h, (float)arc.a, (float)arc.s); } if (decoration is Line) { Line line = decoration as Line; double x1, y1, x2, y2; if (mirrorX) x1 = 100.0 - line.x1; else x1 = line.x1; if (mirrorY) y1 = 100.0 - line.y1; else y1 = line.y1; if (mirrorX) x2 = 100.0 - line.x2; else x2 = line.x2; if (mirrorY) y2 = 100.0 - line.y2; else y2 = line.y2; decorationTemplate[i] = new LineTemplate((float)x1, (float)y1, (float)x2, (float)y2); } if (decoration is Bezier) { Bezier bezier = decoration as Bezier; double x1, y1, x2, y2, x3, y3, x4, y4; if (mirrorX) x1 = 100.0 - bezier.x1; else x1 = bezier.x1; if (mirrorY) y1 = 100.0 - bezier.y1; else y1 = bezier.y1; if (mirrorX) x2 = 100.0 - bezier.x2; else x2 = bezier.x2; if (mirrorY) y2 = 100.0 - bezier.y2; else y2 = bezier.y2; if (mirrorX) x3 = 100.0 - bezier.x3; else x3 = bezier.x3; if (mirrorY) y3 = 100.0 - bezier.y3; else y3 = bezier.y3; if (mirrorX) x4 = 100.0 - bezier.x4; else x4 = bezier.x4; if (mirrorY) y4 = 100.0 - bezier.y4; else y4 = bezier.y4; decorationTemplate[i] = new BezierTemplate((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4); } i++; } box2.Shape = (new ShapeTemplate(elementTemplate, decorationTemplate, null, stencil.FillMode, stencil.Tag)); } SysCAD.Protocol.Rectangle anchorRect = new SysCAD.Protocol.Rectangle(anchorMinX * scale, anchorMinY * scale, (anchorMaxX - anchorMinX) * scale, (anchorMaxY - anchorMinY) * scale); foreach (Box box in anchorPointBoxes) flowChart2.DeleteObject(box); anchorPointBoxes.Clear(); foreach (Anchor anchor in modelStencil.Anchors) { RectangleF displayRect = new RectangleF((float)(((anchor.Positions[0] as SysCAD.Protocol.Point).X / 100.0F * (maxX - minX) + minX) * scale), (float)(((anchor.Positions[0] as SysCAD.Protocol.Point).Y / 100.0F * (maxY - minY) + minY) * scale), 0.0F, 0.0F); displayRect.Inflate(20.0F, 20.0F); Box box = flowChart2.CreateBox(displayRect.X, displayRect.Y, displayRect.Width, displayRect.Height); anchorPointBoxes.Add(box); box.Style = BoxStyle.Ellipse; box.ZTop(); box.FillColor = Color.Red; box.FillColor = Color.FromArgb(100, box.FillColor); } anchorRect.Inflate((maxX - minX) * scale / 10.0F, (maxY - minY) * scale / 10.0F); flowChart2.DocExtents = anchorRect; flowChart2.ZoomToRect(anchorRect); }
private void UpdateStencil(GraphicStencil graphicStencil) { double minX = double.MaxValue; double maxX = double.MinValue; double minY = double.MaxValue; double maxY = double.MinValue; UpdateStencil(graphicStencil.Elements, ref minX, ref minY, ref maxX, ref maxY); UpdateStencil(graphicStencil.Decorations, ref minX, ref minY, ref maxX, ref maxY); double textMinX = double.MaxValue; double textMaxX = double.MinValue; double textMinY = double.MaxValue; double textMaxY = double.MinValue; UpdateStencil(graphicStencil.TagArea, ref textMinX, ref textMinY, ref textMaxX, ref textMaxY); ScaleStencil(graphicStencil.Elements, minX, minY, maxX, maxY); ScaleStencil(graphicStencil.Decorations, minX, minY, maxX, maxY); double scale = 1000.0 / Math.Max((maxX - minX), (maxY - minY)); SysCAD.Protocol.Rectangle rect = new SysCAD.Protocol.Rectangle(minX * scale, minY * scale, (maxX - minX) * scale, (maxY - minY) * scale); graphicStencil.defaultSize = new SysCAD.Protocol.Size((maxX - minX), (maxY - minY)); box1.BoundingRect = rect; { GraphicStencil stencil = graphicStencil; bool mirrorX = false; bool mirrorY = false; ElementTemplate[] elementTemplate = new ElementTemplate[stencil.Elements.Count]; { int i = 0; foreach (Element element in stencil.Elements) { if (element is Arc) { elementTemplate[i] = new ArcTemplate( (float)(element as Arc).x, (float)(element as Arc).y, (float)(element as Arc).w, (float)(element as Arc).h, (float)(element as Arc).a, (float)(element as Arc).s); } if (element is Line) { Line line = element as Line; double x1, y1, x2, y2; if (mirrorX) x1 = 100.0 - line.x1; else x1 = line.x1; if (mirrorY) y1 = 100.0 - line.y1; else y1 = line.y1; if (mirrorX) x2 = 100.0 - line.x2; else x2 = line.x2; if (mirrorY) y2 = 100.0 - line.y2; else y2 = line.y2; elementTemplate[i] = new LineTemplate((float)x1, (float)y1, (float)x2, (float)y2); } if (element is Bezier) { Bezier bezier = element as Bezier; double x1, y1, x2, y2, x3, y3, x4, y4; if (mirrorX) x1 = 100.0 - bezier.x1; else x1 = bezier.x1; if (mirrorY) y1 = 100.0 - bezier.y1; else y1 = bezier.y1; if (mirrorX) x2 = 100.0 - bezier.x2; else x2 = bezier.x2; if (mirrorY) y2 = 100.0 - bezier.y2; else y2 = bezier.y2; if (mirrorX) x3 = 100.0 - bezier.x3; else x3 = bezier.x3; if (mirrorY) y3 = 100.0 - bezier.y3; else y3 = bezier.y3; if (mirrorX) x4 = 100.0 - bezier.x4; else x4 = bezier.x4; if (mirrorY) y4 = 100.0 - bezier.y4; else y4 = bezier.y4; elementTemplate[i] = new BezierTemplate((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4); } i++; } } ElementTemplate[] decorationTemplate = new ElementTemplate[stencil.Decorations.Count]; { int i = 0; foreach (Element decoration in stencil.Decorations) { if (decoration is Arc) { decorationTemplate[i] = new ArcTemplate( (float)(decoration as Arc).x, (float)(decoration as Arc).y, (float)(decoration as Arc).w, (float)(decoration as Arc).h, (float)(decoration as Arc).a, (float)(decoration as Arc).s); } if (decoration is Line) { decorationTemplate[i] = new LineTemplate( (float)(decoration as Line).x1, (float)(decoration as Line).y1, (float)(decoration as Line).x2, (float)(decoration as Line).y2); } if (decoration is Bezier) { decorationTemplate[i] = new BezierTemplate( (float)(decoration as Bezier).x1, (float)(decoration as Bezier).y1, (float)(decoration as Bezier).x2, (float)(decoration as Bezier).y2, (float)(decoration as Bezier).x3, (float)(decoration as Bezier).y3, (float)(decoration as Bezier).x4, (float)(decoration as Bezier).y4); } i++; } } box1.Shape = (new ShapeTemplate(elementTemplate, decorationTemplate, new ElementTemplate[0], stencil.fillMode, stencil.Tag)); } SysCAD.Protocol.Rectangle textRect = new SysCAD.Protocol.Rectangle(textMinX * scale, textMinY * scale, (textMaxX - textMinX) * scale, (textMaxY - textMinY) * scale); textBox1.BoundingRect = textRect; //textBox1.Shape = graphicStencil.TextShapeTemplate(false, false); textBox1.ZTop(); textBox1.FillColor = Color.FromArgb(100, Color.HotPink); double bothMinX = Math.Min(minX, textMinX); double bothMaxX = Math.Max(maxX, textMaxX); double bothMinY = Math.Min(minY, textMinY); double bothMaxY = Math.Max(maxY, textMaxY); SysCAD.Protocol.Rectangle bothRect = new SysCAD.Protocol.Rectangle(bothMinX * scale, bothMinY * scale, (bothMaxX - bothMinX) * scale, (bothMaxY - bothMinY) * scale); bothRect.Inflate((maxX - minX) * scale / 10.0F, (maxY - minY) * scale / 10.0F); flowChart1.DocExtents = bothRect; flowChart1.ZoomToRect(bothRect); }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { elementTextBox.Text = ""; decorationTextBox.Text = ""; tagAreaTextBox.Text = ""; Text = "*Untitled*"; graphicStencil.Elements = new System.Collections.ArrayList(); graphicStencil.Decorations = new System.Collections.ArrayList(); modelStencil.Elements = new System.Collections.ArrayList(); modelStencil.Decorations = new System.Collections.ArrayList(); modelStencil.Anchors = new System.Collections.ArrayList(); flowChart1.DocExtents = new RectangleF(-1.0F, -1.0F, 2.0F, 2.0F); flowChart1.ZoomToRect(new RectangleF(-1.0F, -1.0F, 2.0F, 2.0F)); box1 = flowChart1.CreateBox(-1.0F, -1.0F, 2.0F, 2.0F); box1.Locked = true; box1.Style = MindFusion.FlowChartX.BoxStyle.Shape; { GraphicStencil stencil = graphicStencil; bool mirrorX = false; bool mirrorY = false; ElementTemplate[] elementTemplate = new ElementTemplate[stencil.Elements.Count]; { int i = 0; foreach (Element element in stencil.Elements) { if (element is Arc) { elementTemplate[i] = new ArcTemplate( (float)(element as Arc).x, (float)(element as Arc).y, (float)(element as Arc).w, (float)(element as Arc).h, (float)(element as Arc).a, (float)(element as Arc).s); } if (element is Line) { Line line = element as Line; double x1, y1, x2, y2; if (mirrorX) x1 = 100.0 - line.x1; else x1 = line.x1; if (mirrorY) y1 = 100.0 - line.y1; else y1 = line.y1; if (mirrorX) x2 = 100.0 - line.x2; else x2 = line.x2; if (mirrorY) y2 = 100.0 - line.y2; else y2 = line.y2; elementTemplate[i] = new LineTemplate((float)x1, (float)y1, (float)x2, (float)y2); } if (element is Bezier) { Bezier bezier = element as Bezier; double x1, y1, x2, y2, x3, y3, x4, y4; if (mirrorX) x1 = 100.0 - bezier.x1; else x1 = bezier.x1; if (mirrorY) y1 = 100.0 - bezier.y1; else y1 = bezier.y1; if (mirrorX) x2 = 100.0 - bezier.x2; else x2 = bezier.x2; if (mirrorY) y2 = 100.0 - bezier.y2; else y2 = bezier.y2; if (mirrorX) x3 = 100.0 - bezier.x3; else x3 = bezier.x3; if (mirrorY) y3 = 100.0 - bezier.y3; else y3 = bezier.y3; if (mirrorX) x4 = 100.0 - bezier.x4; else x4 = bezier.x4; if (mirrorY) y4 = 100.0 - bezier.y4; else y4 = bezier.y4; elementTemplate[i] = new BezierTemplate((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4); } i++; } } ElementTemplate[] decorationTemplate = new ElementTemplate[stencil.Decorations.Count]; { int i = 0; foreach (Element decoration in stencil.Decorations) { if (decoration is Arc) { decorationTemplate[i] = new ArcTemplate( (float)(decoration as Arc).x, (float)(decoration as Arc).y, (float)(decoration as Arc).w, (float)(decoration as Arc).h, (float)(decoration as Arc).a, (float)(decoration as Arc).s); } if (decoration is Line) { decorationTemplate[i] = new LineTemplate( (float)(decoration as Line).x1, (float)(decoration as Line).y1, (float)(decoration as Line).x2, (float)(decoration as Line).y2); } if (decoration is Bezier) { decorationTemplate[i] = new BezierTemplate( (float)(decoration as Bezier).x1, (float)(decoration as Bezier).y1, (float)(decoration as Bezier).x2, (float)(decoration as Bezier).y2, (float)(decoration as Bezier).x3, (float)(decoration as Bezier).y3, (float)(decoration as Bezier).x4, (float)(decoration as Bezier).y4); } i++; } } box1.Shape = (new ShapeTemplate(elementTemplate, decorationTemplate, new ElementTemplate[0], stencil.fillMode, stencil.Tag)); } textBox1 = flowChart1.CreateBox(-1.0F, -1.0F, 2.0F, 2.0F); textBox1.Locked = true; //textBox1.Style = MindFusion.FlowChartX.BoxStyle.Shape; //textBox1.Shape = graphicStencil.TextShapeTemplate(false, false); textBox1.Shape = MindFusion.FlowChartX.ShapeTemplate.Decision; flowChart2.DocExtents = new RectangleF(-1.0F, -1.0F, 2.0F, 2.0F); flowChart2.ZoomToRect(new RectangleF(-1.0F, -1.0F, 2.0F, 2.0F)); box2 = flowChart2.CreateBox(-1.0F, -1.0F, 2.0F, 2.0F); box2.Locked = true; box2.Style = MindFusion.FlowChartX.BoxStyle.Shape; { int i; ModelStencil stencil = modelStencil; bool mirrorX = false; bool mirrorY = false; ElementTemplate[] elementTemplate = new ElementTemplate[stencil.Elements.Count]; i = 0; foreach (Element element in stencil.Elements) { if (element is Arc) { Arc arc = element as Arc; elementTemplate[i] = new ArcTemplate((float)arc.x, (float)arc.y, (float)arc.w, (float)arc.h, (float)arc.a, (float)arc.s); } if (element is Line) { Line line = element as Line; double x1, y1, x2, y2; if (mirrorX) x1 = 100.0 - line.x1; else x1 = line.x1; if (mirrorY) y1 = 100.0 - line.y1; else y1 = line.y1; if (mirrorX) x2 = 100.0 - line.x2; else x2 = line.x2; if (mirrorY) y2 = 100.0 - line.y2; else y2 = line.y2; elementTemplate[i] = new LineTemplate((float)x1, (float)y1, (float)x2, (float)y2); } if (element is Bezier) { Bezier bezier = element as Bezier; double x1, y1, x2, y2, x3, y3, x4, y4; if (mirrorX) x1 = 100.0 - bezier.x1; else x1 = bezier.x1; if (mirrorY) y1 = 100.0 - bezier.y1; else y1 = bezier.y1; if (mirrorX) x2 = 100.0 - bezier.x2; else x2 = bezier.x2; if (mirrorY) y2 = 100.0 - bezier.y2; else y2 = bezier.y2; if (mirrorX) x3 = 100.0 - bezier.x3; else x3 = bezier.x3; if (mirrorY) y3 = 100.0 - bezier.y3; else y3 = bezier.y3; if (mirrorX) x4 = 100.0 - bezier.x4; else x4 = bezier.x4; if (mirrorY) y4 = 100.0 - bezier.y4; else y4 = bezier.y4; elementTemplate[i] = new BezierTemplate((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4); } i++; } ElementTemplate[] decorationTemplate = new ElementTemplate[stencil.Decorations.Count]; i = 0; foreach (Element decoration in stencil.Decorations) { if (decoration is Arc) { Arc arc = decoration as Arc; decorationTemplate[i] = new ArcTemplate((float)arc.x, (float)arc.y, (float)arc.w, (float)arc.h, (float)arc.a, (float)arc.s); } if (decoration is Line) { Line line = decoration as Line; double x1, y1, x2, y2; if (mirrorX) x1 = 100.0 - line.x1; else x1 = line.x1; if (mirrorY) y1 = 100.0 - line.y1; else y1 = line.y1; if (mirrorX) x2 = 100.0 - line.x2; else x2 = line.x2; if (mirrorY) y2 = 100.0 - line.y2; else y2 = line.y2; decorationTemplate[i] = new LineTemplate((float)x1, (float)y1, (float)x2, (float)y2); } if (decoration is Bezier) { Bezier bezier = decoration as Bezier; double x1, y1, x2, y2, x3, y3, x4, y4; if (mirrorX) x1 = 100.0 - bezier.x1; else x1 = bezier.x1; if (mirrorY) y1 = 100.0 - bezier.y1; else y1 = bezier.y1; if (mirrorX) x2 = 100.0 - bezier.x2; else x2 = bezier.x2; if (mirrorY) y2 = 100.0 - bezier.y2; else y2 = bezier.y2; if (mirrorX) x3 = 100.0 - bezier.x3; else x3 = bezier.x3; if (mirrorY) y3 = 100.0 - bezier.y3; else y3 = bezier.y3; if (mirrorX) x4 = 100.0 - bezier.x4; else x4 = bezier.x4; if (mirrorY) y4 = 100.0 - bezier.y4; else y4 = bezier.y4; decorationTemplate[i] = new BezierTemplate((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4); } i++; } box2.Shape = (new ShapeTemplate(elementTemplate, decorationTemplate, null, stencil.FillMode, stencil.Tag)); } }
static public ShapeTemplate GetShapeTemplate(ModelStencil stencil, bool mirrorX, bool mirrorY) { int i; if (stencil != null) { ElementTemplate[] elementTemplate = new ElementTemplate[stencil.Elements.Count]; i = 0; foreach (Element element in stencil.Elements) { elementTemplate[i] = MirroredElement(element, mirrorX, mirrorY); i++; } ElementTemplate[] decorationTemplate = new ElementTemplate[stencil.Decorations.Count]; i = 0; foreach (Element decoration in stencil.Decorations) { decorationTemplate[i] = MirroredElement(decoration, mirrorX, mirrorY); i++; } return (new ShapeTemplate(elementTemplate, decorationTemplate, null, FillMode.Alternate, stencil.Tag)); } else return null; }
public ShapeTemplate CreateShapeTemplate() { int count = 0; ArrayList alDecorations = new ArrayList(); RectangleF rect = getBoundingRect(); ElementTemplate[] etContour = null; ElementTemplate[] etTextArea = null; ElementTemplate[] etDecorations = null; etContour = ((Outline)outLines[0]).getElements(rect); for (int i = 1; i < outLines.Count; ++i) { Outline outLine = (Outline)outLines[i]; if (outLine is Contour) etTextArea = outLine.getElements(rect); else { etDecorations = outLine.getElements(rect); alDecorations.Add(etDecorations); count += etDecorations.Length; } } ElementTemplate[] allDecorations = new ElementTemplate[count]; count = 0; foreach (ElementTemplate[] eta in alDecorations) { eta.CopyTo(allDecorations, count); count += eta.Length; } return new ShapeTemplate(etContour, allDecorations, etTextArea, System.Drawing.Drawing2D.FillMode.Winding, "test"); }
public override bool SameAs(ElementTemplate obj) { if(!(obj is LineTemplate)) return false; LineTemplate tmpl = (LineTemplate)obj; for(int i = 0; i < pts.Length; i++) if(Math.Abs(pts[i] - tmpl.pts[i]) >= 0.0001) return false; return true; }
public ShapeTemplate(ElementTemplate[] elements, ElementTemplate[] decorations, ElementTemplate[] textArea, FillMode fillMode, string id) { this.elements = elements; this.decorations = decorations; this.textArea = textArea; this.fillMode = fillMode; this.image = null; // Add to the map if(id != null && id != "") { defaultShapes[id] = this; if (ShapeAdded != null) ShapeAdded(this, new EventArgs()); } // check whether a part of the text area lays outside the shape bounds textOutside = false; if (textArea != null) { for (int i = 0; i < textArea.Length; i++) { if (textArea[i].outsideBounds()) { textOutside = true; break; } } } }
public ShapeTemplate(byte[] outline, string id) { if (outline == null) throw new ArgumentException("outline cannot be null/Nothing."); int len = outline.Length; if (len < 6) throw new ArgumentException("The outline must contain at least 3 points."); if (len % 2 != 0) throw new ArgumentException("outline must contain even number of coordinates."); ElementTemplate[] lines = new ElementTemplate[len / 2]; for (int l = 0; l < len / 2; ++l) { float x1 = outline[l * 2 + 0]; float y1 = outline[l * 2 + 1]; float x2 = outline[(l * 2 + 2) % len]; float y2 = outline[(l * 2 + 3) % len]; lines[l] = new LineTemplate(x1, y1, x2, y2); } this.elements = lines; this.decorations = null; this.textArea = null; this.fillMode = FillMode.Winding; this.image = null; // Add to the map if (id != null && id != "") { defaultShapes[id] = this; if (ShapeAdded != null) ShapeAdded(this, new EventArgs()); } textOutside = false; }
public ShapeTemplate(ElementTemplate[] elements, ElementTemplate[] decorations, ElementTemplate[] textArea, FillMode fillMode) : this(elements, decorations, textArea, fillMode, "") { }
public ShapeTemplate(ElementTemplate[] elements, FillMode fillMode, string id) { this.elements = elements; this.decorations = null; this.textArea = null; this.fillMode = fillMode; this.image = null; // Add to the map if(id != null && id != "") { defaultShapes[id] = this; if (ShapeAdded != null) ShapeAdded(this, new EventArgs()); } textOutside = false; }
public ShapeTemplate(ElementTemplate[] elements, FillMode fillMode) : this(elements, fillMode, "") { }
public abstract bool SameAs(ElementTemplate obj);
/// <summary> /// Produces SVG string path and .NET GraphicsPath using Flowchart.NET box reference /// </summary> /// <param name="newBox">Box reference</param> /// <param name="gr">GraphicsPath reference</param> /// <param name="eta">Flowchart.NET ElementTemplate[] for complex shapes</param> /// <returns>Returns SVG string path data</returns> public string Shape2Path( Box newBox, ref GraphicsPath gr , ElementTemplate[] eta ) { string sResult = ""; PointF pt0 = new PointF(0,0), pt1 = new PointF(0,0), pt2 = new PointF(0,0), pt3 = new PointF(0,0); switch (newBox.Style) { case BoxStyle.Rectangle: Rect2Path(newBox.BoundingRect , ref gr); break; case BoxStyle.Ellipse: gr.AddEllipse(newBox.BoundingRect.X, newBox.BoundingRect.Y, newBox.BoundingRect.Width, newBox.BoundingRect.Height); sResult = Rect2Path(newBox.BoundingRect, ref gr ,false); break; case BoxStyle.RoundedRectangle: gr = Utilities.getRoundRect(newBox.BoundingRect.X, newBox.BoundingRect.Y, newBox.BoundingRect.Width, newBox.BoundingRect.Height, 10); sResult = Rect2Path(newBox.BoundingRect, ref gr, false); break; case BoxStyle.Delay: sResult = Rect2Path(newBox.BoundingRect, ref gr); break; case BoxStyle.Rhombus: pt0 = new PointF( (newBox.BoundingRect.Left + newBox.BoundingRect.Right) / 2, newBox.BoundingRect.Top); pt1 = new PointF( Math.Max(newBox.BoundingRect.Right, newBox.BoundingRect.Left), (newBox.BoundingRect.Top + newBox.BoundingRect.Bottom) / 2); pt2 = new PointF( pt0.X, Math.Max(newBox.BoundingRect.Bottom, newBox.BoundingRect.Top)); pt3 = new PointF( newBox.BoundingRect.Left, pt1.Y); pt1.X+=5; pt3.X-=5; pt2.Y+=5; pt0.Y-=5; PointF[] pts = { pt0, pt1, pt2, pt3 }; gr.AddPolygon(pts); sResult = String.Format("M {0},{1} L{2},{3} L{4},{5} L{6},{7} z", Unit2Pix((newBox.BoundingRect.Left + newBox.BoundingRect.Right) / 2) ,Unit2Pix(newBox.BoundingRect.Top), Unit2Pix(Math.Max(newBox.BoundingRect.Right, newBox.BoundingRect.Left)), Unit2Pix((newBox.BoundingRect.Top + newBox.BoundingRect.Bottom)/2), Unit2Pix(pt0.X) , Unit2Pix(Math.Max(newBox.BoundingRect.Bottom, newBox.BoundingRect.Top)), Unit2Pix(newBox.BoundingRect.Left), Unit2Pix(pt1.Y)); break; case BoxStyle.Shape: if ( eta != null ) { sResult = Complex2Path(newBox.BoundingRect, eta , ref gr); } break; } return sResult; }
public object Clone() { ElementTemplate[] clonedElements = new ElementTemplate[elements.GetLength(0)]; for (int i = 0; i < elements.GetLength(0); ++i) clonedElements[i] = (ElementTemplate)elements[i].Clone(); ElementTemplate[] clonedDecorations = null; if (decorations != null) { clonedDecorations = new ElementTemplate[decorations.Length]; for (int i = 0; i < decorations.Length; i++) clonedDecorations[i] = (ElementTemplate)decorations[i].Clone(); } ElementTemplate[] clonedTextArea = null; if (textArea != null) { clonedTextArea = new ElementTemplate[textArea.Length]; for (int i = 0; i < textArea.Length; i++) clonedTextArea[i] = (ElementTemplate)textArea[i].Clone(); } return new ShapeTemplate(clonedElements, clonedDecorations, clonedTextArea, fillMode); }
/// <summary> /// Produces SVG string path and .NET GraphicsPath using Flowchart.NET complex shape data /// </summary> /// <param name="rect">Shapes Bounding Rect</param> /// <param name="eta">Flowchart.NET ElementTemplate[] for complex shapes</param> /// <param name="gr">GraphicsPath reference</param> /// <returns>Returns SVG string path data</returns> public string Complex2Path ( RectangleF rect , ElementTemplate[] eta , ref GraphicsPath gr ) { string sPath = "", sPartPath = ""; float X = 0, Y = 0, X1 = 0, Y1 = 0, X2 = 0 , Y2 = 0, X3 = 0, Y3 = 0; bool FirstPass = true; foreach (ElementTemplate et in eta ) { sPartPath = ""; switch ( et.getClassId()) { case 28: // arc ArcTemplate at = ( ArcTemplate ) et; double rx = 0, ry = 0 , cx = 0, cy = 0; double angle1 = 0, angle2 = 0; rx = rect.Width * (at.Bounds.Width/200); ry = rect.Height * (at.Bounds.Height/200); cx = rect.X + rect.Width*(at.Bounds.X/100) + rx; cy = rect.Y + rect.Height*(at.Bounds.Y/100) + ry; angle1 = at.StartAngle>0 ? (360 - at.StartAngle) : Math.Abs(at.StartAngle); angle2 = (360 - (( at.StartAngle + at.SweepAngle) % 360)); X2 = (float) (cx+rx*Math.Cos(angle1*Math.PI/180)); Y2 = (float) (cy+ry*Math.Sin(angle1*Math.PI/180)); X1 = (float) (cx+rx*Math.Cos(angle2*Math.PI/180)); Y1 = (float) (cy+ry*Math.Sin(angle2*Math.PI/180)); if ( FirstPass ) { FirstPass = false; sPartPath = String.Format("M{0},{1} A{2},{3} {4} {5},{6} {7},{8} " , Unit2Pix(X1), Unit2Pix(Y1), Unit2Pix(ry), Unit2Pix(rx), angle2, ( angle2 > 180 ) ? 1 : 0, ( at.SweepAngle > 0 ) ? 1 : 0, Unit2Pix(X2), Unit2Pix(Y2)); } else { sPartPath = String.Format("A{0},{1} {2} {3},{4} {5},{6} " , Unit2Pix(ry), Unit2Pix(rx), angle2, ( angle2 > 180 ) ? 1 : 0, ( at.SweepAngle > 0 ) ? 1 : 0, Unit2Pix(X2), Unit2Pix(Y2)); } gr.AddArc(rect.X, rect.Y, rect.Width , rect.Height , at.StartAngle , at.SweepAngle ); break; case 29: // bezier BezierTemplate bt = ( BezierTemplate ) et; X = rect.X + rect.Width * (bt.Coordinates[0]/100); Y = rect.Y + rect.Height* (bt.Coordinates[1]/100); X1 = rect.X + rect.Width * (bt.Coordinates[2]/100); Y1 = rect.Y + rect.Height* (bt.Coordinates[3]/100); X2 = rect.X + rect.Width * (bt.Coordinates[4]/100); Y2 = rect.Y + rect.Height* (bt.Coordinates[5]/100); X3 = rect.X + rect.Width * (bt.Coordinates[6]/100); Y3 = rect.Y + rect.Height* (bt.Coordinates[7]/100); if ( FirstPass ) { FirstPass = false; sPartPath = String.Format("M{0},{1} C{2},{3} {4},{5} {6},{7} " , Unit2Pix(X), Unit2Pix(Y), Unit2Pix(X1), Unit2Pix(Y1), Unit2Pix(X2), Unit2Pix(Y2), Unit2Pix(X3), Unit2Pix(Y3)); } else { sPartPath = String.Format("C{0},{1} {2},{3} {4},{5} " , Unit2Pix(X1), Unit2Pix(Y1), Unit2Pix(X2), Unit2Pix(Y2), Unit2Pix(X3), Unit2Pix(Y3)); } gr.AddBezier(X,Y,X1,Y1,X2,Y2,X3,Y3); break; case 30: // line LineTemplate lt = (LineTemplate) et; X = rect.X + rect.Width * (lt.Coordinates[0]/100); Y = rect.Y + rect.Height* (lt.Coordinates[1]/100); sPartPath = String.Format( FirstPass ? "M{0},{1} " : "L{0},{1} ", Unit2Pix(X), Unit2Pix(Y) ); if ( FirstPass ) FirstPass = false; X1 = X; Y1 = Y; for ( int i=2; i<lt.Coordinates.GetLength(0);i = i+2) { X = rect.X + rect.Width * (lt.Coordinates[i]/100); Y = rect.Y + rect.Height* (lt.Coordinates[i+1]/100); X2 = X; Y2 = Y; sPartPath+=String.Format("L{0},{1} ", Unit2Pix(X), Unit2Pix(Y)); } gr.AddLine(X1,Y1,X2,Y2); break; } sPath+=sPartPath; } return sPath; }
private ShapeTemplate GetShapeTemplate(SysCAD.Protocol.ModelStencil stencil) { int i; if (stencil != null) { ElementTemplate[] elementTemplate = new ElementTemplate[stencil.Elements.Count]; i = 0; foreach (Element element in stencil.Elements) { elementTemplate[i] = Element(element); i++; } ElementTemplate[] decorationTemplate = new ElementTemplate[stencil.Decorations.Count]; i = 0; foreach (Element decoration in stencil.Decorations) { decorationTemplate[i] = Element(decoration); i++; } return (new ShapeTemplate(elementTemplate, decorationTemplate, null, System.Drawing.Drawing2D.FillMode.Alternate, stencil.Tag)); } else return null; }
/// <summary> /// Produces DXF output for Flowchart shape /// </summary> /// <param name="rect">Bounding Rectangle</param> /// <param name="ShapeStyle">Flowchart shape style</param> /// <param name="st">ElementTemplate reference if shape is complex null otherwise</param> /// <param name="crLine">Line color</param> /// <param name="RA">Rotation angle</param> /// <param name="dash">DashStyle</param> /// <param name="LineWidth">Line width ( not used)</param> /// <param name="Offset">Offset if it's necessary</param> /// <param name="WCS2UCS">if true conversion for world-coordinate to user-coordinate is required</param> /// <param name="gr">GraphicsPath to be assigned</param> /// <param name="result">>DXF output string</param> /// <returns>true if successfull otherwise false</returns> public bool Shape2Str( RectangleF rect, BoxStyle ShapeStyle, ElementTemplate[] st, Color crLine, float RA, DashStyle dash, Single LineWidth, float Offset, bool WCS2UCS, ref GraphicsPath gr, ref string result ) { float X = 0, Y = 0, X1 = 0, Y1 = 0, X2 = 0, Y2 = 0, X3 = 0, Y3 = 0; bool DisableStringOutput = false; PointF[] pts = null; bool bOk = false; string PathPart = ""; GraphicsPath gr_temp = new GraphicsPath(FillMode.Winding); try { if ( gr == null ) throw new Exception("Empty Graphics Path reference passed"); DisableStringOutput = ( result == null ); // Detecting box's style switch (ShapeStyle) { case BoxStyle.Rectangle: gr.AddRectangle(rect); break; case BoxStyle.Ellipse: gr.AddEllipse(rect.X,rect.Y,rect.Width, rect.Height); break; case BoxStyle.RoundedRectangle: gr = Utilities.getRoundRect(rect.X, rect.Y, rect.Width, rect.Height,10); break; case BoxStyle.Delay: gr.AddRectangle(rect); break; case BoxStyle.Rhombus: pts = new PointF[4] {new PointF((rect.Left + rect.Right) / 2, rect.Top - Offset), new PointF(Math.Max(rect.Right, rect.Left) + Offset, (rect.Top + rect.Bottom) / 2), new PointF((rect.Left + rect.Right) / 2, Math.Max(rect.Bottom, rect.Top) + Offset), new PointF(rect.Left - Offset,(rect.Top + rect.Bottom) / 2)}; gr.AddPolygon(pts); break; case BoxStyle.Shape: // if shape is complex then processing all its elements if (st == null) throw new Exception("Empty shape reference in the complex shape"); foreach (ElementTemplate et in st ) { switch ( et.getClassId()) { case 28: // If shape element is arc ArcTemplate at = et as ArcTemplate; double rx = 0, ry = 0 , cx = 0, cy = 0; rx = rect.Width * (at.Bounds.Width/200); ry = rect.Height * (at.Bounds.Height/200); cx = rect.X + rect.Width*(at.Bounds.X/100) + rx; cy = rect.Y + rect.Height*(at.Bounds.Y/100) + ry; gr.AddArc((float) (cx - rx), (float) ( cy - ry) , (float) rx*2, (float) ry*2, at.StartAngle ,at.SweepAngle); float StartAngle = 180 + at.StartAngle + (360 - at.SweepAngle) - RA, EndAngle = StartAngle + at.SweepAngle; if ( rx != ry ) { float iAngleC = 0; double majorx = 0, majory = 0; if (at.StartAngle<0) iAngleC = 360 - Math.Abs(at.StartAngle); else iAngleC = at.StartAngle; majorx = (rx < ry) ? 0 : rx; majory = (rx < ry) ? ry : 0; if (( iAngleC >=0 ) && (iAngleC<90)) { majorx*=-1; majory*=-1; } else if (( iAngleC >=90 ) && (iAngleC<180)) { } else if (( iAngleC >=180 ) && (iAngleC<270)) { majorx*=-1; majory*=-1; } else if (( iAngleC >=270 ) && (iAngleC<=360)) { } StartAngle = at.StartAngle + RA; EndAngle = StartAngle + at.SweepAngle; if ((at.SweepAngle>=270) && (at.SweepAngle<360)) { if ( ry > rx ) { StartAngle = at.StartAngle + RA + 90 + ( 360 - at.SweepAngle); EndAngle = at.StartAngle + RA + 90; } } else if (at.SweepAngle>=180) { if (ry>rx) { StartAngle-=90; EndAngle-=90; } } PathPart = String.Format(provider, " 0\nELLIPSE\n 100\nAcDbEntity\n{0:HAN} 8\n{5}\n 62\n{6:ACI}\n 100\nAcDbEllipse\n 10\n{0:U}\n 20\n{1:U}\n 11\n{7:U}\n 21\n{8:U}\n 40\n{9:U}\n 41\n{3:U}\n 42\n{4:U}\n", cx, m_FlowChart.DocExtents.Height - cy,0, (StartAngle*Math.PI)/180 , (EndAngle*Math.PI)/180, SHAPE_LAYER, crLine, majorx , majory , (rx < ry) ? rx/ry : ry/rx); } else { PathPart = String.Format(provider, " 0\nARC\n 100\nAcDbEntity\n{0:HAN} 8\n{5}\n 62\n{6:ACI}\n 100\nAcDbCircle\n 10\n{0:U}\n 20\n{1:U}\n 40\n{2:U}\n 100\nAcDbArc\n 50\n{3}\n 51\n{4}\n", cx, m_FlowChart.DocExtents.Height - cy,rx, StartAngle , EndAngle, SHAPE_LAYER, crLine); } break; case 29: // If shape element is bezier curve BezierTemplate bt = et as BezierTemplate; X = rect.X + rect.Width * (bt.Coordinates[0]/100); Y = rect.Y + rect.Height* (bt.Coordinates[1]/100); X1 = rect.X + rect.Width * (bt.Coordinates[2]/100); Y1 = rect.Y + rect.Height* (bt.Coordinates[3]/100); X2 = rect.X + rect.Width * (bt.Coordinates[4]/100); Y2 = rect.Y + rect.Height* (bt.Coordinates[5]/100); X3 = rect.X + rect.Width * (bt.Coordinates[6]/100); Y3 = rect.Y + rect.Height* (bt.Coordinates[7]/100); gr_temp.Reset(); gr_temp.AddBezier(X,Y,X1,Y1,X2,Y2,X3,Y3); gr.AddBezier(X,Y,X1,Y1,X2,Y2,X3,Y3); // Applying rotation if it's necessary pts = RotatePoints(RA , new PointF(rect.X + rect.Width/2,rect.Y + rect.Height/2), gr_temp); gr_temp.Flatten(); PointF[] pts2 = gr_temp.PathData.Points.Clone() as PointF[]; PathPart = String.Format(provider, "0\nPOLYLINE\n{0:HAN} 100\nAcDbEntity\n8\n{0}\n 62\n{1:ACI}\n 100\nAcDb2dPolyline\n 66\n1\n 70\n4\n 75\n6\n{2}{3}0\nSEQEND\n 100\nAcDbEntity\n{0:HAN}", SHAPE_LAYER, crLine, Pt2String(pts,crLine,SHAPE_LAYER,DxLineType.ltVertex, dash, 16), Pt2String(pts2,crLine,SHAPE_LAYER,DxLineType.ltVertex, dash, 8)); break; case 30: // If shape element is line LineTemplate lt = et as LineTemplate; X1 = rect.X + rect.Width * (lt.Coordinates[0]/100); Y1 = rect.Y + rect.Height* (lt.Coordinates[1]/100); X2 = rect.X + rect.Width * (lt.Coordinates[2]/100); Y2 = rect.Y + rect.Height* (lt.Coordinates[3]/100); gr_temp.Reset(); gr_temp.AddLine(X1,Y1,X2,Y2); gr.AddLine(X1,Y1,X2,Y2); // Applying rotation if it's necessary pts = RotatePoints(RA , new PointF(rect.X + rect.Width/2,rect.Y + rect.Height/2), gr_temp); PathPart = Pt2String(pts, crLine,SHAPE_LAYER,DxLineType.ltSingle,DashStyle.Solid, 1); break; } result+=PathPart; } break; default: gr.AddRectangle(rect); break; } // Converting shapes coordinates from UCS to WSC TranslateCoords(RA , new PointF(rect.X + rect.Width/2,rect.Y + rect.Height/2), WCS2UCS, ref gr); gr.Flatten(); // If string output is required producing DXF string if (!DisableStringOutput) { if ( result=="" ) { pts = gr.PathPoints.Clone() as PointF[]; result = Pt2String(pts, crLine, SHAPE_LAYER, DxLineType.ltClosedSingle, dash, LineWidth); } } bOk = true; } catch ( Exception ex) { Trace.WriteLine(String.Format("{0} error {1}\n","Box2Str",ex.Message)); bOk = false; } return bOk; }
public override bool SameAs(ElementTemplate obj) { if(!(obj is ArcTemplate)) return false; ArcTemplate tmpl = (ArcTemplate)obj; return (Math.Abs(x - tmpl.x) < 0.0001 && Math.Abs(y - tmpl.y) < 0.0001 && Math.Abs(w - tmpl.w) < 0.0001 && Math.Abs(h - tmpl.h) < 0.0001 && Math.Abs(a - tmpl.a) < 0.0001 && Math.Abs(s - tmpl.s) < 0.0001); }