public void Save() { svg s = new svg(); s.version = "1.1"; s.width = (this.m_schema.DiagramPagesHorz * CtlExpressG.PageX).ToString(); s.height = (this.m_schema.DiagramPagesVert * CtlExpressG.PageY).ToString(); foreach (DocEntity docEnt in this.m_schema.Entities) { g group = SaveDefinition(docEnt, null); s.g.Add(group); if (group != null) { SaveTree(group, docEnt.Tree, null, true); foreach (DocAttribute docAttr in docEnt.Attributes) { if (docAttr.DiagramLine != null && docAttr.DiagramLine.Count >= 2) { g attr = new g(); group.groups.Add(attr); attr.id = docAttr.Name; bool?linestyle = false; if (docAttr.IsOptional) { linestyle = null; } SaveLine(attr, docAttr.DiagramLine, null, linestyle); // calculate midpoint of line double mx = (docAttr.DiagramLine[0].X + docAttr.DiagramLine[docAttr.DiagramLine.Count - 1].X) * 0.5; double my = (docAttr.DiagramLine[0].Y + docAttr.DiagramLine[docAttr.DiagramLine.Count - 1].Y) * 0.5; // vex files define relative position double rx = docAttr.DiagramLabel.X - docAttr.DiagramLine[0].X; double ry = docAttr.DiagramLabel.Y - docAttr.DiagramLine[0].Y; // calculate absolute position double ax = mx + rx; double ay = my + ry; text t = new text(); attr.text.Add(t); t.value = (docAttr.Name + " " + docAttr.GetAggregationExpression()).Trim(); t.fill = "black"; t.x = (ax * CtlExpressG.Factor).ToString(); t.y = (ay * CtlExpressG.Factor).ToString(); t.alignment_baseline = "middle"; t.text_anchor = "middle"; t.font_size = "10"; t.font_family = "Arial, Helvetica, sans-serif"; } } } } foreach (DocType docEnt in this.m_schema.Types) { g group = SaveDefinition(docEnt, null); s.g.Add(group); if (docEnt is DocSelect) { DocSelect docSelect = (DocSelect)docEnt; SaveTree(group, docSelect.Tree, null, false); } } foreach (DocPrimitive docEnt in this.m_schema.Primitives) { g group = SaveDefinition(docEnt, null); s.g.Add(group); } foreach (DocSchemaRef docRef in this.m_schema.SchemaRefs) { g r = SaveDefinition(docRef, null); s.g.Add(r); foreach (DocDefinitionRef docDef in docRef.Definitions) { g group = SaveDefinition(docDef, docRef.Name + "\r\n" + docDef.Name); r.groups.Add(group); SaveTree(group, docDef.Tree, null, true); } } foreach (DocPageTarget docTarget in this.m_schema.PageTargets) { g target = SaveDefinition(docTarget, null); s.g.Add(target); SaveLine(target, docTarget.DiagramLine, null, false); foreach (DocPageSource docSource in docTarget.Sources) { g source = SaveDefinition(docSource, null); target.groups.Add(source); } } g grid = new g(); s.g.Add(grid); for (int iPageY = 0; iPageY < m_schema.DiagramPagesVert; iPageY++) { for (int iPageX = 0; iPageX < m_schema.DiagramPagesHorz; iPageX++) { rect r = new rect(); r.x = (iPageX * CtlExpressG.PageX).ToString(); r.y = (iPageY * CtlExpressG.PageY).ToString(); r.width = CtlExpressG.PageX.ToString(); r.height = CtlExpressG.PageY.ToString(); r.fill = "none"; r.stroke = "lime"; grid.rect.Add(r); } } using (FormatXML format = new FormatXML(this.m_filename, typeof(svg), "http://www.w3.org/2000/svg")) { format.Instance = s; format.Save(); } }
private g SaveDefinition(DocObject docObj, string displayname) { g group = new g(); group.id = docObj.Name; DocDefinition docDef = docObj as DocDefinition; if (docDef == null || docDef.DiagramRectangle == null) { return(group); } double x = docDef.DiagramRectangle.X * CtlExpressG.Factor; double y = docDef.DiagramRectangle.Y * CtlExpressG.Factor; double cx = docDef.DiagramRectangle.Width * CtlExpressG.Factor; double cy = docDef.DiagramRectangle.Height * CtlExpressG.Factor; rect r = new rect(); r.x = x.ToString(); r.y = y.ToString(); r.width = cx.ToString(); r.height = cy.ToString(); r.stroke = "black"; group.rect.Add(r); text t = new text(); t.x = (x + cx * 0.5).ToString(); t.y = (y + cy * 0.5).ToString(); t.fill = "black"; t.alignment_baseline = "middle"; t.text_anchor = "middle"; t.font_size = "10"; t.font_family = "Arial, Helvetica, sans-serif"; if (displayname != null) { t.value = displayname; } else { t.value = docDef.Name; } group.text.Add(t); if (docDef is DocEntity) { group.fill = "yellow"; } else if (docDef is DocType) { group.fill = "green"; } else if (docDef is DocPageTarget) { group.fill = "blue"; r.rx = "10"; r.ry = "10"; } else if (docDef is DocPageSource) { group.fill = "silver"; r.rx = "10"; r.ry = "10"; } else { group.fill = "grey"; } return(group); }