Exemple #1
0
        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);
                }
            }

            // grid lines
            if (this.m_format == DiagramFormat.ExpressG)
            {
                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();
            }
        }
Exemple #2
0
        public void Load()
        {
            svg s = null;

            using (FormatXML format = new FormatXML(this.m_filename, typeof(svg), "http://www.w3.org/2000/svg"))
            {
                format.Load();
                s = format.Instance as svg;
            }

            if (s == null)
            {
                return;
            }

            // apply diagram to existing schema elements
            foreach (g group in s.g)
            {
                // primitive
                DocDefinition docDef = null;
                switch (group.id)
                {
                case "INTEGER":
                case "REAL":
                case "BOOLEAN":
                case "LOGICAL":
                case "STRING":
                case "BINARY":
                    docDef      = new DocPrimitive();
                    docDef.Name = group.id;
                    m_schema.Primitives.Add((DocPrimitive)docDef);
                    break;

                default:
                    docDef = this.m_schema.GetDefinition(group.id);
                    break;
                }

                if (docDef != null)
                {
                    docDef.DiagramRectangle = LoadRectangle(group);

                    // attributes, supertype...
                    if (docDef is DocEntity)
                    {
                        DocEntity docEnt = (DocEntity)docDef;
                        LoadTree(group, docEnt.Tree);

                        foreach (g subgroup in group.groups)
                        {
                            foreach (DocAttribute docAttr in docEnt.Attributes)
                            {
                                if (docAttr.Name.Equals(subgroup.id))
                                {
                                    LoadLine(subgroup, docAttr.DiagramLine);

                                    if (subgroup.text.Count == 1)
                                    {
                                        double ax = Double.Parse(subgroup.text[0].x) / CtlExpressG.Factor;
                                        double ay = Double.Parse(subgroup.text[0].y) / CtlExpressG.Factor;

                                        docAttr.DiagramLabel   = new DocRectangle();
                                        docAttr.DiagramLabel.X = ax;
                                        docAttr.DiagramLabel.Y = ay;
                                    }

                                    break;
                                }
                            }
                        }

                        // base type???
                    }
                    else if (docDef is DocDefined)
                    {
                        DocDefined docDefined = (DocDefined)docDef;
                        LoadLine(group, docDefined.DiagramLine);
                    }
                    else if (docDef is DocSelect)
                    {
                        DocSelect docSelect = (DocSelect)docDef;
                        LoadTree(group, docSelect.Tree);
                    }
                }
                else
                {
                    // schema ref
                    DocSchema docTargetSchema = this.m_project.GetSchema(group.id);
                    if (docTargetSchema != null)
                    {
                        DocSchemaRef docSchemaRef = new DocSchemaRef();
                        docSchemaRef.Name = group.id;
                        this.m_schema.SchemaRefs.Add(docSchemaRef);

                        foreach (g subgroup in group.groups)
                        {
                            DocDefinition docTargetDef = docTargetSchema.GetDefinition(subgroup.id);
                            if (docTargetDef != null)
                            {
                                DocDefinitionRef docDefRef = new DocDefinitionRef();
                                docDefRef.Name = subgroup.id;
                                docSchemaRef.Definitions.Add(docDefRef);
                                docDefRef.DiagramRectangle = LoadRectangle(subgroup);

                                LoadTree(subgroup, docDefRef.Tree);
                            }
                        }
                    }
                    else
                    {
                        // primitive?

                        // page targets
                        DocPageTarget docPageTarget = new DocPageTarget();
                        docPageTarget.Name = group.id;
                        this.m_schema.PageTargets.Add(docPageTarget);
                        docPageTarget.DiagramRectangle = LoadRectangle(group);
                        //...docPageTarget.Definition =
                        LoadLine(group, docPageTarget.DiagramLine);

                        foreach (g subgroup in group.groups)
                        {
                            DocPageSource docPageSource = new DocPageSource();
                            docPageSource.Name = subgroup.id;
                            docPageTarget.Sources.Add(docPageSource);
                            docPageSource.DiagramRectangle = LoadRectangle(subgroup);
                        }
                    }
                }
            }
        }