Exemplo n.º 1
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);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void buttonAttributeType_Click(object sender, EventArgs e)
        {
            using (FormSelectEntity form = new FormSelectEntity(null, null, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type))
            {
                if (form.ShowDialog(this) == DialogResult.OK && form.SelectedEntity != null)
                {
                    // find existing type or reference type in schema
                    DocSchema docSchema = (DocSchema)this.m_path[1];
                    DocDefinition docDef = docSchema.GetDefinition(form.SelectedEntity.Name);
                    if (docDef == null)
                    {
                        // generate link to schema
                        foreach(DocSection docSection in this.m_project.Sections)
                        {
                            foreach (DocSchema docOtherSchema in docSection.Schemas)
                            {
                                docDef = docOtherSchema.GetDefinition(form.SelectedEntity.Name);
                                if (docDef is DocType || docDef is DocEntity)
                                {
                                    DocSchemaRef docSchemaReference = null;
                                    foreach(DocSchemaRef docSchemaRef in docSchema.SchemaRefs)
                                    {
                                        if (String.Equals(docSchemaRef.Name, docOtherSchema.Name, StringComparison.OrdinalIgnoreCase))
                                        {
                                            docSchemaReference = docSchemaRef;
                                            break;
                                        }
                                    }

                                    if (docSchemaReference == null)
                                    {
                                        docSchemaReference = new DocSchemaRef();
                                        docSchemaReference.Name = docOtherSchema.Name;
                                        docSchema.SchemaRefs.Add(docSchemaReference);
                                    }

                                    docDef = new DocDefinitionRef();
                                    docDef.Name = form.SelectedEntity.Name;
                                    docSchemaReference.Definitions.Add((DocDefinitionRef)docDef);

                                    break;
                                }
                            }

                            if (docDef != null)
                                break;
                        }
                    }

                    if (this.m_target is DocAttribute)
                    {
                        DocAttribute docAttr = (DocAttribute)this.m_target;

                        if (docAttr.Definition != null && docAttr.Definition.DiagramRectangle != null)
                        {
                            // find page target, make page reference
                            if(docDef is DocDefinitionRef)
                            {
                                DocDefinitionRef ddr = (DocDefinitionRef)docDef;
                                
                                // find existing page target
                                foreach(DocPageTarget docPageTarget in docSchema.PageTargets)
                                {
                                    if(docPageTarget.Definition == ddr)
                                    {
                                        // found it -- make page source
                                        DocPageSource docPageSource = new DocPageSource();
                                        docPageTarget.Sources.Add(docPageSource);
                                        docDef = docPageSource;
                                        break;
                                    }
                                }
                            }

                            if (docDef.DiagramRectangle == null)
                            {
                                docDef.DiagramRectangle = new DocRectangle();
                                docDef.DiagramNumber = docAttr.Definition.DiagramNumber;
                                docDef.DiagramRectangle.X = docAttr.Definition.DiagramRectangle.X;
                                docDef.DiagramRectangle.Y = docAttr.Definition.DiagramRectangle.Y;
                                docDef.DiagramRectangle.Width = docAttr.Definition.DiagramRectangle.Width;
                                docDef.DiagramRectangle.Height = docAttr.Definition.DiagramRectangle.Height;
                            }
                        }

                        docAttr.Definition = docDef;
                        docAttr.DefinedType = form.SelectedEntity.Name;
                        this.textBoxAttributeType.Text = docAttr.DefinedType;
                    }
                    else if(this.m_target is DocDefined)
                    {
                        DocDefined docDefined = (DocDefined)this.m_target;
                        if (docDefined.Definition.DiagramRectangle != null)
                        {
                            docDef.DiagramRectangle = new DocRectangle();
                            docDef.DiagramNumber = docDefined.Definition.DiagramNumber;
                            docDef.DiagramRectangle.X = docDefined.Definition.DiagramRectangle.X;
                            docDef.DiagramRectangle.Y = docDefined.Definition.DiagramRectangle.Y;
                            docDef.DiagramRectangle.Width = docDefined.Definition.DiagramRectangle.Width;
                            docDef.DiagramRectangle.Height = docDefined.Definition.DiagramRectangle.Height;
                        }

                        docDefined.Definition = docDef;
                        docDefined.DefinedType = form.SelectedEntity.Name;
                        this.textBoxAttributeType.Text = docDefined.DefinedType;
                    }
                }
            }
        }
Exemplo n.º 3
0
        private DocDefinition CreateLink(DocDefinition target, DocPoint docPoint)
        {
            if (target is DocPageTarget)
            {
                DocPageTarget docPageTarget = (DocPageTarget)target;
                DocPageSource docPageSource = new DocPageSource();
                docPageTarget.Sources.Add(docPageSource);

                //docPageSource.Target = docPageTarget;
                docPageSource.DiagramRectangle = new DocRectangle();
                docPageSource.DiagramRectangle.X = docPoint.X + 400.0;
                docPageSource.DiagramRectangle.Y = docPoint.Y;
                docPageSource.DiagramRectangle.Width = 400.0;
                docPageSource.DiagramRectangle.Height = 100.0;

                int px = (int)(docPageSource.DiagramRectangle.X / CtlExpressG.PageX);
                int py = (int)(docPageSource.DiagramRectangle.Y / CtlExpressG.PageY);
                int page = 1 + py * this.ctlExpressG.Schema.DiagramPagesHorz + px;
                docPageSource.DiagramNumber = page;

                return docPageSource;
            }
            else
            {
                return target;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a documentation schema from a VEX schema
        /// </summary>
        /// <param name="schemata">The VEX schema to import</param>
        /// <param name="project">The documentation project where the imported schema is to be created</param>
        /// <returns>The imported documentation schema</returns>
        internal static DocSchema ImportVex(SCHEMATA schemata, DocProject docProject, bool updateDescriptions)
        {
            DocSchema docSchema = docProject.RegisterSchema(schemata.name);
            if (updateDescriptions && schemata.comment != null && schemata.comment.text != null)
            {
                docSchema.Documentation = schemata.comment.text.text;
            }
            docSchema.DiagramPagesHorz = schemata.settings.page.nhorizontalpages;
            docSchema.DiagramPagesVert = schemata.settings.page.nverticalpages;

            // remember current types for deletion if they no longer exist
            List<DocObject> existing = new List<DocObject>();
            foreach (DocType doctype in docSchema.Types)
            {
                existing.Add(doctype);
            }
            foreach (DocEntity docentity in docSchema.Entities)
            {
                existing.Add(docentity);
            }
            foreach (DocFunction docfunction in docSchema.Functions)
            {
                existing.Add(docfunction);
            }
            foreach (DocGlobalRule docrule in docSchema.GlobalRules)
            {
                existing.Add(docrule);
            }

            docSchema.PageTargets.Clear();
            docSchema.SchemaRefs.Clear();
            docSchema.Comments.Clear();

            // remember references for fixing up attributes afterwords
            Dictionary<object, DocDefinition> mapRefs = new Dictionary<object, DocDefinition>();
            Dictionary<ATTRIBUTE_DEF, DocAttribute> mapAtts = new Dictionary<ATTRIBUTE_DEF, DocAttribute>();
            //Dictionary<SELECT_DEF, DocSelectItem> mapSels = new Dictionary<SELECT_DEF, DocSelectItem>();
            Dictionary<SELECT_DEF, DocLine> mapSL = new Dictionary<SELECT_DEF, DocLine>();
            Dictionary<SUBTYPE_DEF, DocLine> mapSubs = new Dictionary<SUBTYPE_DEF, DocLine>();
            Dictionary<PAGE_REF, DocPageTarget> mapPage = new Dictionary<PAGE_REF, DocPageTarget>();

            // entities and types
            foreach (object obj in schemata.objects)
            {
                if (obj is ENTITIES)
                {
                    ENTITIES ent = (ENTITIES)obj; // filter out orphaned entities having upper flags set
                    if ((ent.flag & 0xFFFF0000) == 0 && (ent.interfaceto == null || ent.interfaceto.theschema == null))
                    {
                        // create if doesn't exist
                        string name = ent.name.text;

                        string super = null;
                        if (ent.supertypes.Count > 0 && ent.supertypes[0].the_supertype is ENTITIES)
                        {
                            ENTITIES superent = (ENTITIES)ent.supertypes[0].the_supertype;
                            super = superent.name.text;
                        }

                        DocEntity docEntity = docSchema.RegisterEntity(name);
                        if (existing.Contains(docEntity))
                        {
                            existing.Remove(docEntity);
                        }
                        mapRefs.Add(obj, docEntity);

                        // clear out existing if merging
                        docEntity.BaseDefinition = null;

                        foreach(DocSubtype docSub in docEntity.Subtypes)
                        {
                            docSub.Delete();
                        }
                        docEntity.Subtypes.Clear();

                        foreach(DocUniqueRule docUniq in docEntity.UniqueRules)
                        {
                            docUniq.Delete();
                        }
                        docEntity.UniqueRules.Clear();

                        foreach(DocLine docLine in docEntity.Tree)
                        {
                            docLine.Delete();
                        }
                        docEntity.Tree.Clear();

                        if (updateDescriptions && ent.comment != null && ent.comment.text != null)
                        {
                            docEntity.Documentation = ent.comment.text.text;
                        }
                        if (ent.supertypes.Count > 0 && ent.supertypes[0].the_supertype is ENTITIES)
                        {
                            docEntity.BaseDefinition = ((ENTITIES)ent.supertypes[0].the_supertype).name.text;
                        }

                        docEntity.EntityFlags = ent.flag;
                        if (ent.subtypes != null)
                        {
                            foreach (SUBTYPE_DEF sd in ent.subtypes)
                            {
                                // new (3.8): intermediate subtypes for diagrams
                                DocLine docLine = new DocLine();
                                ImportVexLine(sd.layout, null, docLine.DiagramLine, null);
                                docEntity.Tree.Add(docLine);

                                OBJECT od = (OBJECT)sd.the_subtype;

                                // tunnel through page ref
                                if (od is PAGE_REF_TO)
                                {
                                    od = ((PAGE_REF_TO)od).pageref;
                                }

                                if (od is TREE)
                                {
                                    TREE tree = (TREE)od;
                                    foreach (OBJECT o in tree.list)
                                    {
                                        OBJECT os = o;
                                        OBJECT_LINE_LAYOUT linelayout = null;

                                        if (o is SUBTYPE_DEF)
                                        {
                                            SUBTYPE_DEF osd = (SUBTYPE_DEF)o;
                                            linelayout = osd.layout;

                                            os = ((SUBTYPE_DEF)o).the_subtype;
                                        }

                                        if (os is PAGE_REF_TO)
                                        {
                                            os = ((PAGE_REF_TO)os).pageref;
                                        }

                                        if (os is ENTITIES)
                                        {
                                            DocSubtype docSub = new DocSubtype();
                                            docSub.DefinedType = ((ENTITIES)os).name.text;
                                            docEntity.Subtypes.Add(docSub);

                                            DocLine docSubline = new DocLine();
                                            docLine.Tree.Add(docSubline);

                                            if (o is SUBTYPE_DEF)
                                            {
                                                mapSubs.Add((SUBTYPE_DEF)o, docSubline);
                                            }

                                            ImportVexLine(linelayout, null, docSubline.DiagramLine, null);
                                        }
                                        else
                                        {
                                            Debug.Assert(false);
                                        }
                                    }
                                }
                                else if (od is ENTITIES)
                                {
                                    DocSubtype docInt = new DocSubtype();
                                    docEntity.Subtypes.Add(docInt);

                                    docInt.DefinedType = ((ENTITIES)od).name.text;
                                }
                                else
                                {
                                    Debug.Assert(false);
                                }
                            }
                        }

                        // determine EXPRESS-G page based on placement (required for generating hyperlinks)
                        if (ent.layout != null)
                        {
                            ImportVexRectangle(docEntity, ent.layout.rectangle, schemata);
                        }

                        if (ent.attributes != null)
                        {
                            List<DocAttribute> existingattr = new List<DocAttribute>();
                            foreach (DocAttribute docAttr in docEntity.Attributes)
                            {
                                existingattr.Add(docAttr);
                            }

                            // attributes are replaced, not merged (template don't apply here)
                            foreach (ATTRIBUTE_DEF attr in ent.attributes)
                            {
                                if (attr.name != null)
                                {
                                    DocAttribute docAttr = docEntity.RegisterAttribute(attr.name.text);
                                    mapAtts.Add(attr, docAttr);

                                    if (existingattr.Contains(docAttr))
                                    {
                                        existingattr.Remove(docAttr);
                                    }

                                    if (updateDescriptions && attr.comment != null && attr.comment.text != null)
                                    {
                                        docAttr.Documentation = attr.comment.text.text;
                                    }

                                    if (docAttr.DiagramLabel != null)
                                    {
                                        docAttr.DiagramLabel.Delete();
                                        docAttr.DiagramLabel = null;
                                    }

                                    foreach(DocPoint docPoint in docAttr.DiagramLine)
                                    {
                                        docPoint.Delete();
                                    }
                                    docAttr.DiagramLine.Clear();

                                    if (attr.layout != null)
                                    {
                                        if (attr.layout.pline != null)
                                        {
                                            // intermediate lines
                                            if (attr.layout.pline.rpoint != null)
                                            {
                                                docAttr.DiagramLabel = new DocRectangle();
                                                ImportVexLine(attr.layout, attr.name.layout, docAttr.DiagramLine, docAttr.DiagramLabel);
                                            }
                                        }
                                    }

                                    OBJECT def = attr.the_attribute;
                                    if (attr.the_attribute is PAGE_REF_TO)
                                    {
                                        PAGE_REF_TO pr = (PAGE_REF_TO)attr.the_attribute;
                                        def = pr.pageref;
                                    }

                                    if (def is DEFINED_TYPE)
                                    {
                                        DEFINED_TYPE dt = (DEFINED_TYPE)def;
                                        docAttr.DefinedType = dt.name.text;
                                    }
                                    else if (def is ENTITIES)
                                    {
                                        ENTITIES en = (ENTITIES)def;
                                        docAttr.DefinedType = en.name.text;
                                    }
                                    else if (def is ENUMERATIONS)
                                    {
                                        ENUMERATIONS en = (ENUMERATIONS)def;
                                        docAttr.DefinedType = en.name.text;
                                    }
                                    else if (def is SELECTS)
                                    {
                                        SELECTS en = (SELECTS)def;
                                        docAttr.DefinedType = en.name.text;
                                    }
                                    else if (def is PRIMITIVE_TYPE)
                                    {
                                        PRIMITIVE_TYPE en = (PRIMITIVE_TYPE)def;

                                        string length = "";
                                        if (en.constraints > 0)
                                        {
                                            length = " (" + en.constraints.ToString() + ")";
                                        }
                                        else if (en.constraints < 0)
                                        {
                                            int len = -en.constraints;
                                            length = " (" + len.ToString() + ") FIXED";
                                        }

                                        docAttr.DefinedType = en.name.text + length;
                                    }
                                    else if (def is SCHEMA_REF)
                                    {
                                        SCHEMA_REF en = (SCHEMA_REF)def;
                                        docAttr.DefinedType = en.name.text;
                                    }
                                    else
                                    {
                                        Debug.Assert(false);
                                    }

                                    docAttr.AttributeFlags = attr.attributeflag;

                                    AGGREGATES vexAggregates = attr.aggregates;
                                    DocAttribute docAggregate = docAttr;
                                    while (vexAggregates != null)
                                    {
                                        // traverse nested aggregation (e.g. IfcStructuralLoadConfiguration)
                                        docAggregate.AggregationType = vexAggregates.aggrtype + 1;
                                        docAggregate.AggregationLower = vexAggregates.lower;
                                        docAggregate.AggregationUpper = vexAggregates.upper;
                                        docAggregate.AggregationFlag = vexAggregates.flag;

                                        vexAggregates = vexAggregates.next;
                                        if (vexAggregates != null)
                                        {
                                            // inner array (e.g. IfcStructuralLoadConfiguration)
                                            docAggregate.AggregationAttribute = new DocAttribute();
                                            docAggregate = docAggregate.AggregationAttribute;
                                        }
                                    }

                                    docAttr.Derived = attr.is_derived;

                                    if (attr.user_redeclaration != null)
                                    {
                                        docAttr.Inverse = attr.user_redeclaration;
                                    }
                                    else if (attr.is_inverse is ATTRIBUTE_DEF)
                                    {
                                        ATTRIBUTE_DEF adef = (ATTRIBUTE_DEF)attr.is_inverse;
                                        docAttr.Inverse = adef.name.text;
                                    }
                                    else if (attr.is_inverse != null)
                                    {
                                        Debug.Assert(false);
                                    }
                                }
                            }

                            foreach(DocAttribute docAttr in existingattr)
                            {
                                docEntity.Attributes.Remove(docAttr);
                                docAttr.Delete();
                            }
                        }

                        // unique rules
                        if (ent.uniquenes != null)
                        {
                            // rules are replaced, not merged (template don't apply here)
                            //docEntity.UniqueRules = new List<DocUniqueRule>();
                            foreach (UNIQUE_RULE rule in ent.uniquenes)
                            {
                                DocUniqueRule docRule = new DocUniqueRule();
                                docEntity.UniqueRules.Add(docRule);
                                docRule.Name = rule.name;

                                docRule.Items = new List<DocUniqueRuleItem>();
                                foreach (ATTRIBUTE_DEF ruleitem in rule.for_attribute)
                                {
                                    DocUniqueRuleItem item = new DocUniqueRuleItem();
                                    item.Name = ruleitem.name.text;
                                    docRule.Items.Add(item);
                                }
                            }
                        }

                        // where rules
                        if (ent.wheres != null)
                        {
                            List<DocWhereRule> existingattr = new List<DocWhereRule>();
                            foreach (DocWhereRule docWhere in docEntity.WhereRules)
                            {
                                existingattr.Add(docWhere);
                            }

                            foreach (WHERE_RULE where in ent.wheres)
                            {
                                DocWhereRule docWhere = docEntity.RegisterWhereRule(where.name);
                                docWhere.Expression = where.rule_context;

                                if(existingattr.Contains(docWhere))
                                {
                                    existingattr.Remove(docWhere);
                                }

                                if (updateDescriptions && where.comment != null && where.comment.text != null)
                                {
                                    docWhere.Documentation = where.comment.text.text;
                                }
                            }

                            foreach(DocWhereRule exist in existingattr)
                            {
                                exist.Delete();
                                docEntity.WhereRules.Remove(exist);
                            }
                        }
                    }
                }
                else if (obj is ENUMERATIONS)
                {
                    ENUMERATIONS ent = (ENUMERATIONS)obj;
                    if (ent.interfaceto == null || ent.interfaceto.theschema == null)
                    {
                        if (schemata.name.Equals("IfcConstructionMgmtDomain", StringComparison.OrdinalIgnoreCase) && ent.name.text.Equals("IfcNullStyle", StringComparison.OrdinalIgnoreCase))
                        {
                            // hack to workaround vex bug
                            Debug.Assert(true);
                        }
                        else
                        {

                            DocEnumeration docEnumeration = docSchema.RegisterType<DocEnumeration>(ent.name.text);
                            if (existing.Contains(docEnumeration))
                            {
                                existing.Remove(docEnumeration);
                            }
                            mapRefs.Add(obj, docEnumeration);

                            if (updateDescriptions && ent.comment != null && ent.comment.text != null)
                            {
                                docEnumeration.Documentation = ent.comment.text.text;
                            }

                            // determine EXPRESS-G page based on placement (required for generating hyperlinks)
                            if (ent.typelayout != null && schemata.settings != null && schemata.settings.page != null)
                            {
                                ImportVexRectangle(docEnumeration, ent.typelayout.rectangle, schemata);
                            }

                            // enumeration values are replaced, not merged (template don't apply here)
                            docEnumeration.Constants.Clear();
                            foreach (string s in ent.enums)
                            {
                                DocConstant docConstant = new DocConstant();
                                docEnumeration.Constants.Add(docConstant);
                                docConstant.Name = s;
                            }
                        }
                    }
                }
                else if (obj is DEFINED_TYPE)
                {
                    DEFINED_TYPE ent = (DEFINED_TYPE)obj;

                    if (ent.interfaceto == null || ent.interfaceto.theschema == null)
                    {
                        DocDefined docDefined = docSchema.RegisterType<DocDefined>(ent.name.text);
                        if (existing.Contains(docDefined))
                        {
                            existing.Remove(docDefined);
                        }

                        mapRefs.Add(obj, docDefined);

                        if (updateDescriptions && ent.comment != null && ent.comment.text != null)
                        {
                            docDefined.Documentation = ent.comment.text.text;
                        }

                        if (ent.layout != null)
                        {
                            ImportVexRectangle(docDefined, ent.layout.rectangle, schemata);
                        }

                        if(ent.defined.object_line_layout != null)
                        {
                            foreach(DocPoint docPoint in docDefined.DiagramLine)
                            {
                                docPoint.Delete();
                            }
                            docDefined.DiagramLine.Clear();
                            ImportVexLine(ent.defined.object_line_layout, null, docDefined.DiagramLine, null);
                        }

                        OBJECT os = (OBJECT)ent.defined.defined;
                        if (os is PAGE_REF_TO)
                        {
                            os = ((PAGE_REF_TO)os).pageref;
                        }

                        if (os is PRIMITIVE_TYPE)
                        {
                            PRIMITIVE_TYPE pt = (PRIMITIVE_TYPE)os;
                            docDefined.DefinedType = pt.name.text;

                            if (pt.constraints != 0)
                            {
                                docDefined.Length = pt.constraints;
                            }
                        }
                        else if (os is DEFINED_TYPE)
                        {
                            DEFINED_TYPE dt = (DEFINED_TYPE)os;
                            docDefined.DefinedType = dt.name.text;
                        }
                        else if (os is ENTITIES)
                        {
                            ENTITIES et = (ENTITIES)os;
                            docDefined.DefinedType = et.name.text;
                        }
                        else
                        {
                            Debug.Assert(false);
                        }

                        // aggregation
                        AGGREGATES vexAggregates = ent.defined.aggregates;
                        if (vexAggregates != null)
                        {
                            DocAttribute docAggregate = new DocAttribute();
                            docDefined.Aggregation = docAggregate;

                            docAggregate.AggregationType = vexAggregates.aggrtype + 1;
                            docAggregate.AggregationLower = vexAggregates.lower;
                            docAggregate.AggregationUpper = vexAggregates.upper;
                            docAggregate.AggregationFlag = vexAggregates.flag;
                        }

                        // where rules
                        if (ent.whererules != null)
                        {
                            // rules are replaced, not merged (template don't apply here)
                            foreach(DocWhereRule docWhere in docDefined.WhereRules)
                            {
                                docWhere.Delete();
                            }
                            docDefined.WhereRules.Clear();
                            foreach (WHERE_RULE where in ent.whererules)
                            {
                                DocWhereRule docWhere = new DocWhereRule();
                                docDefined.WhereRules.Add(docWhere);
                                docWhere.Name = where.name;
                                docWhere.Expression = where.rule_context;

                                if (where.comment != null && where.comment.text != null)
                                {
                                    docWhere.Documentation = where.comment.text.text;
                                }
                            }
                        }

                    }
                }
                else if (obj is SELECTS)
                {
                    SELECTS ent = (SELECTS)obj;
                    if (ent.interfaceto == null || ent.interfaceto.theschema == null)
                    {
                        DocSelect docSelect = docSchema.RegisterType<DocSelect>(ent.name.text);
                        if (existing.Contains(docSelect))
                        {
                            existing.Remove(docSelect);
                        }
                        mapRefs.Add(obj, docSelect);

                        if (updateDescriptions && ent.comment != null && ent.comment.text != null)
                        {
                            docSelect.Documentation = ent.comment.text.text;
                        }

                        // determine EXPRESS-G page based on placement (required for generating hyperlinks)
                        if (ent.typelayout != null)
                        {
                            ImportVexRectangle(docSelect, ent.typelayout.rectangle, schemata);
                        }

                        docSelect.Selects.Clear();
                        docSelect.Tree.Clear();
                        foreach (SELECT_DEF sdef in ent.selects)
                        {
                            DocLine docLine = new DocLine();
                            docSelect.Tree.Add(docLine);
                            ImportVexLine(sdef.layout, null, docLine.DiagramLine, null);

                            mapSL.Add(sdef, docLine);

                            if (sdef.def is TREE)
                            {
                                TREE tree = (TREE)sdef.def;

                                foreach (OBJECT o in tree.list)
                                {
                                    DocSelectItem dsi = new DocSelectItem();
                                    docSelect.Selects.Add(dsi);

                                    OBJECT os = o;
                                    if (o is SELECT_DEF)
                                    {
                                        SELECT_DEF selectdef = (SELECT_DEF)o;

                                        DocLine docLineSub = new DocLine();
                                        docLine.Tree.Add(docLineSub);
                                        ImportVexLine(selectdef.layout, null, docLineSub.DiagramLine, null);

                                        mapSL.Add(selectdef, docLineSub);

                                        os = ((SELECT_DEF)o).def;
                                    }
                                    else
                                    {
                                        Debug.Assert(false);
                                    }

                                    if (os is PAGE_REF_TO)
                                    {
                                        PAGE_REF_TO pr = (PAGE_REF_TO)os;
                                        os = pr.pageref;
                                    }

                                    if (os is DEFINITION)
                                    {
                                        dsi.Name = ((DEFINITION)os).name.text;
                                    }
                                }
                            }
                            else
                            {
                                OBJECT os = (OBJECT)sdef.def;

                                if (os is PAGE_REF_TO)
                                {
                                    PAGE_REF_TO pr = (PAGE_REF_TO)os;
                                    os = pr.pageref;
                                }

                                DocSelectItem dsi = new DocSelectItem();
                                docSelect.Selects.Add(dsi);
                                if (os is DEFINITION)
                                {
                                    dsi.Name = ((DEFINITION)os).name.text;
                                }
                            }
                        }
                    }
                }
                else if (obj is GLOBAL_RULE)
                {
                    GLOBAL_RULE func = (GLOBAL_RULE)obj;

                    DocGlobalRule docFunction = docSchema.RegisterRule(func.name);
                    if (existing.Contains(docFunction))
                    {
                        existing.Remove(docFunction);
                    }

                    // clear out existing if merging
                    docFunction.WhereRules.Clear();

                    if (updateDescriptions && func.comment != null && func.comment.text != null)
                    {
                        docFunction.Documentation = func.comment.text.text;
                    }
                    docFunction.Expression = func.rule_context;

                    foreach (WHERE_RULE wr in func.where_rule)
                    {
                        DocWhereRule docW = new DocWhereRule();
                        docW.Name = wr.name;
                        docW.Expression = wr.rule_context;
                        if (wr.comment != null)
                        {
                            docW.Documentation = wr.comment.text.text;
                        }
                        docFunction.WhereRules.Add(docW);
                    }

                    if (func.for_entities.Count == 1)
                    {
                        docFunction.ApplicableEntity = func.for_entities[0].ToString();
                    }
                }
                else if (obj is USER_FUNCTION)
                {
                    USER_FUNCTION func = (USER_FUNCTION)obj;

                    DocFunction docFunction = docSchema.RegisterFunction(func.name);
                    if (existing.Contains(docFunction))
                    {
                        existing.Remove(docFunction);
                    }

                    if (updateDescriptions && func.comment != null && func.comment.text != null)
                    {
                        docFunction.Documentation = func.comment.text.text;
                    }
                    docFunction.Expression = func.rule_context;

                    // NOTE: While the VEX schema can represent parameters and return values, Visual Express does not implement it!
                    // Rather, parameter info is also included in the 'rule_context'
                    if (func.return_value != null)
                    {
                        docFunction.ReturnValue = func.return_value.ToString();
                    }
                    else
                    {
                        docFunction.ReturnValue = null;
                    }
                    docFunction.Parameters.Clear();
                    if (func.parameter_list != null)
                    {
                        foreach (PARAMETER par in func.parameter_list)
                        {
                            DocParameter docParameter = new DocParameter();
                            docParameter.Name = par.name;
                            docParameter.DefinedType = par.parameter_type.ToString();
                            docFunction.Parameters.Add(docParameter);
                        }
                    }
                }
                else if (obj is PRIMITIVE_TYPE)
                {
                    PRIMITIVE_TYPE prim = (PRIMITIVE_TYPE)obj;

                    DocPrimitive docPrimitive = new DocPrimitive();
                    docPrimitive.Name = prim.name.text;
                    if (prim.layout != null)
                    {
                        ImportVexRectangle(docPrimitive, prim.layout.rectangle, schemata);
                    }

                    docSchema.Primitives.Add(docPrimitive);
                    mapRefs.Add(obj, docPrimitive);
                }
                else if (obj is COMMENT)
                {
                    COMMENT comment = (COMMENT)obj;

                    // only deal with comments that are part of EXPRESS-G layout -- ignore those referenced by definitions and old cruft left behind due to older versions of VisualE that were buggy
                    if (comment.layout != null)
                    {
                        DocComment docComment = new DocComment();
                        docComment.Documentation = comment.text.text;
                        ImportVexRectangle(docComment, comment.layout.rectangle, schemata);

                        docSchema.Comments.Add(docComment);
                    }
                }
                else if (obj is INTERFACE_SCHEMA)
                {
                    INTERFACE_SCHEMA iface = (INTERFACE_SCHEMA)obj;

                    DocSchemaRef docSchemaRef = new DocSchemaRef();
                    docSchema.SchemaRefs.Add(docSchemaRef);

                    docSchemaRef.Name = iface.schema_name;

                    foreach (object o in iface.item)
                    {
                        if (o is DEFINITION)
                        {
                            DocDefinitionRef docDefRef = new DocDefinitionRef();
                            docSchemaRef.Definitions.Add(docDefRef);
                            mapRefs.Add(o, docDefRef);

                            docDefRef.Name = ((DEFINITION)o).name.text;

                            if (o is DEFINED_TYPE)
                            {
                                DEFINED_TYPE dt = (DEFINED_TYPE)o;
                                if (dt.layout != null)
                                {
                                    ImportVexRectangle(docDefRef, dt.layout.rectangle, schemata);
                                }
                            }
                            else if (o is ENTITIES)
                            {
                                ENTITIES ents = (ENTITIES)o;
                                if (ents.layout != null) // null for IfcPolyline reference in IfcGeometricModelResource
                                {
                                    ImportVexRectangle(docDefRef, ents.layout.rectangle, schemata);
                                }

                                if (ents.subtypes != null)
                                {
                                    foreach (SUBTYPE_DEF subdef in ents.subtypes)
                                    {
                                        OBJECT_LINE_LAYOUT linelayout = subdef.layout;

                                        DocLine docSub = new DocLine();
                                        ImportVexLine(subdef.layout, null, docSub.DiagramLine, null);
                                        docDefRef.Tree.Add(docSub);

                                        if(subdef.the_subtype is TREE)
                                        {
                                            TREE tree = (TREE)subdef.the_subtype;
                                            foreach(object oo in tree.list)
                                            {
                                                if(oo is SUBTYPE_DEF)
                                                {
                                                    SUBTYPE_DEF subsubdef = (SUBTYPE_DEF)oo;
                                                    DocLine docSubSub = new DocLine();
                                                    docSub.Tree.Add(docSubSub);

                                                    ImportVexLine(subsubdef.layout, null, docSubSub.DiagramLine, null);

                                                    mapSubs.Add(subsubdef, docSubSub);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else if (o is ENUMERATIONS)
                            {
                                ENUMERATIONS enums = (ENUMERATIONS)o;
                                if (enums.typelayout != null)
                                {
                                    ImportVexRectangle(docDefRef, enums.typelayout.rectangle, schemata);
                                }
                            }
                            else if (o is SELECTS)
                            {
                                SELECTS sels = (SELECTS)o;
                                if (sels.typelayout != null)
                                {
                                    ImportVexRectangle(docDefRef, sels.typelayout.rectangle, schemata);
                                }
                            }
                            else if(o is SCHEMA_REF)
                            {
                                SCHEMA_REF sref = (SCHEMA_REF)o;
                                if(sref.layout != null)
                                {
                                    ImportVexRectangle(docDefRef, sref.layout.rectangle, schemata);
                                }
                            }
                        }
                        else if (o is USER_FUNCTION)
                        {
                            DocDefinitionRef docDefRef = new DocDefinitionRef();
                            docSchemaRef.Definitions.Add(docDefRef);

                            USER_FUNCTION uf = (USER_FUNCTION)o;
                            docDefRef.Name = uf.name;
                        }
                    }
                }
                else if (obj is PAGE_REF)
                {
                    PAGE_REF pageref = (PAGE_REF)obj;

                    DocPageTarget docPageTarget = new DocPageTarget();
                    docSchema.PageTargets.Add(docPageTarget);
                    docPageTarget.Name = pageref.text.text;
                    docPageTarget.DiagramNumber = pageref.pagenr;
                    ImportVexLine(pageref.pageline.layout, null, docPageTarget.DiagramLine, null);
                    ImportVexRectangle(docPageTarget, pageref.layout.rectangle, schemata);

                    foreach (PAGE_REF_TO pagerefto in pageref.pagerefto)
                    {
                        DocPageSource docPageSource = new DocPageSource();
                        docPageTarget.Sources.Add(docPageSource);

                        docPageSource.DiagramNumber = pagerefto.pagenr;
                        docPageSource.Name = pagerefto.text.text;
                        ImportVexRectangle(docPageSource, pagerefto.layout.rectangle, schemata);

                        mapRefs.Add(pagerefto, docPageSource);
                    }

                    mapPage.Add(pageref, docPageTarget);
                }
            }

            foreach (DocObject docobj in existing)
            {
                if (docobj is DocEntity)
                {
                    docSchema.Entities.Remove((DocEntity)docobj);
                }
                else if (docobj is DocType)
                {
                    docSchema.Types.Remove((DocType)docobj);
                }
                else if (docobj is DocFunction)
                {
                    docSchema.Functions.Remove((DocFunction)docobj);
                }
                else if (docobj is DocGlobalRule)
                {
                    docSchema.GlobalRules.Remove((DocGlobalRule)docobj);
                }

                docobj.Delete();
            }

            // now fix up attributes
            foreach (ATTRIBUTE_DEF docAtt in mapAtts.Keys)
            {
                DocAttribute docAttr = mapAtts[docAtt];
                docAttr.Definition = mapRefs[docAtt.the_attribute];
            }

            foreach (PAGE_REF page in mapPage.Keys)
            {
                DocPageTarget docPage = mapPage[page];
                docPage.Definition = mapRefs[page.pageline.pageref];
            }

            foreach (SELECT_DEF sd in mapSL.Keys)
            {
                DocLine docLine = mapSL[sd];
                if (mapRefs.ContainsKey(sd.def))
                {
                    docLine.Definition = mapRefs[sd.def];
                }
            }

            foreach (SUBTYPE_DEF sd in mapSubs.Keys)
            {
                DocLine docLine = mapSubs[sd];
                if (mapRefs.ContainsKey(sd.the_subtype))
                {
                    docLine.Definition = mapRefs[sd.the_subtype];
                }
            }

            foreach(object o in mapRefs.Keys)
            {
                if (o is DEFINED_TYPE)
                {
                    DEFINED_TYPE def = (DEFINED_TYPE)o;
                    if (def.interfaceto == null || def.interfaceto.theschema == null)
                    {
                        // declared within
                        DocDefined docDef = (DocDefined)mapRefs[o];
                        docDef.Definition = mapRefs[def.defined.defined];
                    }
                }
            }

            return docSchema;
        }
Exemplo n.º 5
0
        private void toolStripMenuItemInsertAttribute_Click(object sender, EventArgs e)
        {
            // prompt user to select type (or primitive)
            using(FormSelectEntity form = new FormSelectEntity(null, null, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type))
            {
                if(form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && form.SelectedEntity != null)
                {
                    TreeNode tnParent = this.treeView.SelectedNode;
                    DocSchema docSchema = (DocSchema)tnParent.Parent.Parent.Tag;
                    DocEntity docEntity = (DocEntity)tnParent.Tag;
                    DocAttribute docAttr = new DocAttribute();
                    docAttr.Name = String.Empty;
                    docAttr.DefinedType = form.SelectedEntity.Name;
                    docEntity.Attributes.Add(docAttr);

                    // is the selected type within the same schema?
                    if ((form.SelectedEntity is DocType && docSchema.Types.Contains((DocType)form.SelectedEntity)) ||
                        (form.SelectedEntity is DocEntity && docSchema.Entities.Contains((DocEntity)form.SelectedEntity)))
                    {
                        docAttr.Definition = form.SelectedEntity;

                        //docAttr.DiagramLine.Add(new DocPoint(docEntity.DiagramRectangle.X + docEntity.DiagramRectangle.Width, docEntity.DiagramRectangle.Y + docEntity.Attributes.IndexOf(docAttr) * 100.0));
                        //docAttr.DiagramLine.Add(new DocPoint(form.SelectedEntity.DiagramRectangle.X, form.SelectedEntity.DiagramRectangle.Y + form.SelectedEntity.DiagramRectangle.Height / 2));
                    }
                    else
                    {
                        // find existing reference
                        DocDefinitionRef docDefTarget = null;
                        foreach(DocSchemaRef docSchemaRef in docSchema.SchemaRefs)
                        {
                            foreach(DocDefinitionRef docDefinitionRef in docSchemaRef.Definitions)
                            {
                                if (docDefinitionRef.Name.Equals(form.SelectedEntity.Name))
                                {
                                    // found it
                                    docDefTarget = docDefinitionRef;
                                    break;
                                }
                            }

                            if (docDefTarget != null)
                                break;
                        }

                        if (docDefTarget == null)
                        {
                            // import it

                            // find the applicable schema...
                            DocSchema docTargetSchema = this.m_project.GetSchemaOfDefinition(form.SelectedEntity);
                            DocSchemaRef docTargetSchemaRef = null;
                            foreach(DocSchemaRef docSchemaRef in docSchema.SchemaRefs)
                            {
                                if(docSchemaRef.Name.Equals(docTargetSchema.Name))
                                {
                                    docTargetSchemaRef = docSchemaRef;
                                    break;
                                }
                            }

                            if (docTargetSchemaRef == null)
                            {
                                docTargetSchemaRef = new DocSchemaRef();
                                docTargetSchemaRef.Name = docTargetSchema.Name;
                                docSchema.SchemaRefs.Add(docTargetSchemaRef);
                            }

                            docDefTarget = new DocDefinitionRef();
                            docDefTarget.Name = form.SelectedEntity.Name;
                            docDefTarget.DiagramRectangle = new DocRectangle();
                            docDefTarget.DiagramRectangle.X = docEntity.DiagramRectangle.X + docEntity.DiagramRectangle.Width + 100;
                            docDefTarget.DiagramRectangle.Y = docEntity.DiagramRectangle.Y + (docEntity.Attributes.Count - 1) * 100;
                            docDefTarget.DiagramRectangle.Width = 400.0;
                            docDefTarget.DiagramRectangle.Height = 50.0;
                            docTargetSchemaRef.Definitions.Add(docDefTarget);

                            docAttr.Definition = docDefTarget;
                        }
                        else
                        {
                            docAttr.Definition = docDefTarget;
                        }

                    }

                    // check if there's a page reference target -- use that if it exists
                    foreach (DocPageTarget docPageTarget in docSchema.PageTargets)
                    {
                        if (docPageTarget.Definition == docAttr.Definition)
                        {
                            DocPageSource docPageSource = new DocPageSource();
                            docPageTarget.Sources.Add(docPageSource);
                            //docPageSource.Target = docPageTarget;
                            docPageSource.DiagramRectangle = new DocRectangle();
                            docPageSource.DiagramRectangle.X = docEntity.DiagramRectangle.X + docEntity.DiagramRectangle.Width + 100;
                            docPageSource.DiagramRectangle.Y = docEntity.DiagramRectangle.Y + (docEntity.Attributes.Count - 1) * 100;
                            docPageSource.DiagramRectangle.Width = 400.0;
                            docPageSource.DiagramRectangle.Height = 50.0;

                            docAttr.Definition = docPageSource;

                            docAttr.DiagramLine.Add(new DocPoint(docEntity.DiagramRectangle.X + docEntity.DiagramRectangle.Width, docPageSource.DiagramRectangle.Y + docPageSource.DiagramRectangle.Height / 2));
                            docAttr.DiagramLine.Add(new DocPoint(docPageSource.DiagramRectangle.X, docPageSource.DiagramRectangle.Y + docPageSource.DiagramRectangle.Height / 2));
                            break;
                        }
                    }

                    if (docAttr.DiagramLine.Count == 0 && docAttr.Definition.DiagramRectangle != null)
                    {
                        docAttr.DiagramLine.Add(new DocPoint(docEntity.DiagramRectangle.X + docEntity.DiagramRectangle.Width, docAttr.Definition.DiagramRectangle.Y + docAttr.Definition.DiagramRectangle.Height / 2));
                        docAttr.DiagramLine.Add(new DocPoint(docAttr.Definition.DiagramRectangle.X, docAttr.Definition.DiagramRectangle.Y + docAttr.Definition.DiagramRectangle.Height / 2));

                        docAttr.DiagramLabel = new DocRectangle();
                        docAttr.DiagramLabel.X = docAttr.DiagramLine[0].X;
                        docAttr.DiagramLabel.Y = docAttr.DiagramLine[0].Y;
                        docAttr.DiagramLabel.Width = 400.0;
                        docAttr.DiagramLabel.Height = 50.0;

                    }

                    this.treeView.SelectedNode = this.LoadNode(tnParent, docAttr, docAttr.ToString(), false, docEntity.Attributes.Count - 1);
                    toolStripMenuItemEditRename_Click(this, e);

                }
            }
        }