public string FormatDefinitions(DocProject docProject, DocPublication docPublication, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included) { StringBuilder sb = new StringBuilder(); foreach (DocSection docSection in docProject.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocType docType in docSchema.Types) { bool use = true; if (included != null) { use = false; included.TryGetValue(docType, out use); } if (use) { if (docType is DocDefined) { DocDefined docDefined = (DocDefined)docType; string text = this.FormatDefined(docDefined, map, included); sb.AppendLine(text); } else if (docType is DocSelect) { DocSelect docSelect = (DocSelect)docType; string text = this.FormatSelect(docSelect, map, included); sb.AppendLine(text); } else if (docType is DocEnumeration) { DocEnumeration docEnumeration = (DocEnumeration)docType; string text = this.FormatEnumeration(docEnumeration, map, included); sb.AppendLine(text); } } } foreach (DocEntity docEntity in docSchema.Entities) { bool use = true; if (included != null) { use = false; included.TryGetValue(docEntity, out use); } if (use) { string text = this.FormatEntity(docEntity, map, included); sb.AppendLine(text); } } } } return(sb.ToString()); }
public string FormatSelect(DocSelect docSelect, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included) { return ("public interface " + docSelect.Name + "\r\n" + "{\r\n" + "}"); }
/// <summary> /// Builds syntax for referencing select /// </summary> /// <param name="sb"></param> /// <param name="docEntity"></param> /// <param name="map"></param> /// <param name="included"></param> /// <param name="hasentry">Whether entries already listed; if not, then colon is added</param> private void BuildSelectEntries(StringBuilder sb, DocDefinition docEntity, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included, bool hasentry) { SortedList <string, DocSelect> listSelects = new SortedList <string, DocSelect>(); foreach (DocObject obj in map.Values) { if (obj is DocSelect) { DocSelect docSelect = (DocSelect)obj; foreach (DocSelectItem docItem in docSelect.Selects) { if (docItem.Name != null && docItem.Name.Equals(docEntity.Name) && !listSelects.ContainsKey(docSelect.Name)) { // found it; add it listSelects.Add(docSelect.Name, docSelect); } } } } foreach (DocSelect docSelect in listSelects.Values) { if (docSelect == listSelects.Values[0] && !hasentry) { sb.Append(" : "); } else { sb.Append(", "); } sb.Append(docSelect.Name); } }
// version for computer interpretable listing public string FormatSelectFull(DocSelect docSelect, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included, bool fullListing) { StringBuilder sb = new StringBuilder(); sb.AppendLine("ifc:" + docSelect.Name); sb.AppendLine("\trdf:type owl:Class ;"); if (!fullListing) { //possibly add the individuals here as a union sb.AppendLine("\towl:equivalentClass"); sb.AppendLine("\t\t["); sb.AppendLine("\t\t\trdf:type owl:Class ;"); sb.AppendLine("\t\t\towl:unionOf "); sb.AppendLine("\t\t\t\t( "); // entities foreach (DocSelectItem docItem in docSelect.Selects) { DocObject mapDef = null; if (map.TryGetValue(docItem.Name, out mapDef)) { if (included == null || included.ContainsKey(mapDef)) { sb.AppendLine("\t\t\t\t\tifc:" + docItem.Name + " "); } } } //close unionof sb.AppendLine("\t\t\t\t) "); sb.AppendLine("\t\t] ; "); } sb.AppendLine("\trdfs:subClassOf expr:SELECT ."); sb.AppendLine(); // add members of SELECT as subclasses if (fullListing) { foreach (DocSelectItem docItem in docSelect.Selects) { DocObject mapDef = null; if (map.TryGetValue(docItem.Name, out mapDef)) { if (included == null || included.ContainsKey(mapDef)) { sb.AppendLine("ifc:" + docItem.Name); sb.AppendLine("\trdfs:subClassOf ifc:" + docSelect.Name + " ."); sb.AppendLine(); } } } } return(sb.ToString()); }
public string FormatSelect(DocSelect docSelect, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included) { StringBuilder sb = new StringBuilder(); sb.Append("public interface " + docSelect.Name); BuildSelectEntries(sb, docSelect, map, included, false); sb.AppendLine(); sb.AppendLine("{"); sb.AppendLine("}"); return(sb.ToString()); }
public void Save() { string dirpath = System.IO.Path.GetDirectoryName(this.m_filename); if (!System.IO.Directory.Exists(this.m_filename)) { System.IO.Directory.CreateDirectory(dirpath); } using (System.IO.StreamWriter writer = new System.IO.StreamWriter(this.m_filename)) { writer.WriteLine("// This file was automatically generated from IFCDOC at www.buildingsmart-tech.org."); writer.WriteLine("// IFC content is copyright (C) 1996-2013 BuildingSMART International Ltd."); writer.WriteLine(); writer.WriteLine("using System;"); writer.WriteLine(); if (this.m_definition != null) { writer.WriteLine("namespace BuildingSmart.IFC"); writer.WriteLine("{"); if (this.m_definition is DocDefined) { DocDefined docDefined = (DocDefined)this.m_definition; string text = this.Indent(this.FormatDefined(docDefined), 1); writer.WriteLine(text); } else if (this.m_definition is DocSelect) { DocSelect docSelect = (DocSelect)this.m_definition; string text = this.Indent(this.FormatSelect(docSelect, this.m_map, null), 1); writer.WriteLine(text); } else if (this.m_definition is DocEnumeration) { DocEnumeration docEnumeration = (DocEnumeration)this.m_definition; string text = this.Indent(this.FormatEnumeration(docEnumeration), 1); writer.WriteLine(text); } else if (this.m_definition is DocEntity) { DocEntity docEntity = (DocEntity)this.m_definition; string text = this.Indent(this.FormatEntity(docEntity, this.m_map, null), 1); writer.WriteLine(docEntity); } writer.WriteLine("}"); } else { writer.WriteLine("namespace BuildingSmart.IFC.Properties"); writer.WriteLine("{"); writer.WriteLine(); Dictionary <string, string[]> mapEnums = new Dictionary <string, string[]>(); foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocPropertySet docPset in docSchema.PropertySets) { writer.WriteLine(" /// <summary>"); if (docPset.Documentation != null) { writer.WriteLine(" /// " + docPset.Documentation.Replace('\r', ' ').Replace('\n', ' ')); } writer.WriteLine(" /// </summary>"); writer.WriteLine(" public class " + docPset.Name + " : Pset"); writer.WriteLine(" {"); foreach (DocProperty docProperty in docPset.Properties) { writer.WriteLine(" /// <summary>"); if (docProperty.Documentation != null) { writer.WriteLine(" /// " + docProperty.Documentation.Replace('\r', ' ').Replace('\n', ' ')); } writer.WriteLine(" /// </summary>"); switch (docProperty.PropertyType) { case DocPropertyTemplateTypeEnum.P_SINGLEVALUE: writer.WriteLine(" public " + docProperty.PrimaryDataType + " " + docProperty.Name + " { get { return this.GetValue<" + docProperty.PrimaryDataType + ">(\"" + docProperty.Name + "\"); } set { this.SetValue<" + docProperty.PrimaryDataType + ">(\"" + docProperty.Name + "\", value); } }"); break; case DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE: { string typename = docProperty.SecondaryDataType; if (typename == null) { typename = docProperty.PrimaryDataType; // older version } int colon = typename.IndexOf(':'); if (colon > 0) { // backwards compatibility typename = typename.Substring(0, colon); } writer.WriteLine(" public " + typename + " " + docProperty.Name + " { get { return this.GetValue<" + typename + ">(\"" + docProperty.Name + "\"); } set { this.SetValue<" + typename + ">(\"" + docProperty.Name + "\", value); } }"); } break; case DocPropertyTemplateTypeEnum.P_BOUNDEDVALUE: writer.WriteLine(" public PBound<" + docProperty.PrimaryDataType + "> " + docProperty.Name + " { get { return this.GetBound<" + docProperty.PrimaryDataType + ">(\"" + docProperty.Name + "\"); } }"); break; case DocPropertyTemplateTypeEnum.P_LISTVALUE: break; case DocPropertyTemplateTypeEnum.P_TABLEVALUE: writer.WriteLine(" public PTable<" + docProperty.PrimaryDataType + ", " + docProperty.SecondaryDataType + "> " + docProperty.Name + " { get { return this.GetTable<" + docProperty.PrimaryDataType + ", " + docProperty.SecondaryDataType + ">(\"" + docProperty.Name + "\"); } }"); break; case DocPropertyTemplateTypeEnum.P_REFERENCEVALUE: if (docProperty.PrimaryDataType.Equals("IfcTimeSeries")) { string datatype = docProperty.SecondaryDataType; if (String.IsNullOrEmpty(datatype)) { datatype = "IfcReal"; } writer.WriteLine(" public PTimeSeries<" + datatype + "> " + docProperty.Name + " { get { return this.GetTimeSeries<" + datatype + ">(\"" + docProperty.Name + "\"); } }"); } // ... TBD break; case DocPropertyTemplateTypeEnum.COMPLEX: //... TBD break; } } writer.WriteLine(" }"); writer.WriteLine(); } foreach (DocPropertyEnumeration docEnum in docSchema.PropertyEnums) { writer.WriteLine(" /// <summary>"); writer.WriteLine(" /// </summary>"); writer.WriteLine(" public enum " + docEnum.Name); writer.WriteLine(" {"); int counter = 0; foreach (DocPropertyConstant docConst in docEnum.Constants) { int num = 0; string id = docConst.Name.ToUpper().Trim('.').Replace('-', '_'); switch (id) { case "OTHER": num = -1; break; case "NOTKNOWN": num = -2; break; case "UNSET": num = 0; break; default: counter++; num = counter; break; } if (id[0] >= '0' && id[0] <= '9') { id = "_" + id; // avoid numbers } writer.WriteLine(" /// <summary></summary>"); writer.WriteLine(" " + docConst.Name + " = " + num + ","); } writer.WriteLine(" }"); writer.WriteLine(); } //writer.WriteLine("}"); #if false // enums foreach (string strEnum in mapEnums.Keys) { string[] enums = mapEnums[strEnum]; writer.WriteLine(" /// <summary>"); writer.WriteLine(" /// </summary>"); writer.WriteLine(" public enum " + strEnum); writer.WriteLine(" {"); int counter = 0; foreach (string val in enums) { int num = 0; string id = val.ToUpper().Trim('.').Replace('-', '_'); switch (id) { case "OTHER": num = -1; break; case "NOTKNOWN": num = -2; break; case "UNSET": num = 0; break; default: counter++; num = counter; break; } if (id[0] >= '0' && id[0] <= '9') { id = "_" + id; // avoid numbers } writer.WriteLine(" /// <summary></summary>"); writer.WriteLine(" " + id + " = " + num + ","); } writer.WriteLine(" }"); writer.WriteLine(); } writer.WriteLine("}"); #endif } } } } }
public static void LoadAssembly(DocProject project, Assembly assem) { // look through classes of assembly foreach (Type t in assem.GetTypes()) { if (t.Namespace != null) { string[] namespaceparts = t.Namespace.Split('.'); string schema = namespaceparts[namespaceparts.Length - 1]; DocSection docSection = null; if (t.Namespace.EndsWith("Resource")) { docSection = project.Sections[7]; } else if (t.Namespace.EndsWith("Domain")) { docSection = project.Sections[6]; } else if (t.Namespace.Contains("Shared")) { docSection = project.Sections[5]; } else { docSection = project.Sections[4]; // kernel, extensions } // find schema DocSchema docSchema = null; foreach (DocSchema docEachSchema in docSection.Schemas) { if (docEachSchema.Name.Equals(schema)) { docSchema = docEachSchema; break; } } if (docSchema == null) { docSchema = new DocSchema(); docSchema.Name = schema; docSection.Schemas.Add(docSchema); docSection.SortSection(); } DocDefinition docDef = null; if (t.IsEnum) { DocEnumeration docEnum = new DocEnumeration(); docSchema.Types.Add(docEnum); docDef = docEnum; System.Reflection.FieldInfo[] fields = t.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); foreach (System.Reflection.FieldInfo field in fields) { DocConstant docConst = new DocConstant(); docEnum.Constants.Add(docConst); docConst.Name = field.Name; DescriptionAttribute[] attrs = (DescriptionAttribute[])field.GetCustomAttributes(typeof(DescriptionAttribute), false); if (attrs.Length == 1) { docConst.Documentation = attrs[0].Description; } } } else if (t.IsValueType) { PropertyInfo[] fields = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); if (fields.Length > 0) { Type typeField = fields[0].PropertyType; DocDefined docDefined = new DocDefined(); docSchema.Types.Add(docDefined); docDef = docDefined; docDefined.DefinedType = FormatCSC.GetExpressType(typeField); if (typeField.IsGenericType) { Type typeGeneric = typeField.GetGenericTypeDefinition(); typeField = typeField.GetGenericArguments()[0]; if (typeGeneric == typeof(ISet <>) || typeGeneric == typeof(HashSet <>)) { docDefined.Aggregation = new DocAttribute(); docDefined.Aggregation.AggregationType = (int)DocAggregationEnum.SET; } else if (typeGeneric == typeof(IList <>) || typeGeneric == typeof(List <>)) { docDefined.Aggregation = new DocAttribute(); docDefined.Aggregation.AggregationType = (int)DocAggregationEnum.LIST; } } MaxLengthAttribute mxa = (MaxLengthAttribute)fields[0].GetCustomAttribute(typeof(MaxLengthAttribute)); if (mxa != null) { docDefined.Length = mxa.Length; } } } else if (t.IsInterface) { DocSelect docSelect = new DocSelect(); docSchema.Types.Add(docSelect); docDef = docSelect; } else if (t.IsClass) { DocEntity docEntity = new DocEntity(); docSchema.Entities.Add(docEntity); docDef = docEntity; if (t.BaseType != null) { if (t.BaseType != typeof(object) && t.BaseType.Name != "SEntity") // back-compat for reflecting on IfcDoc types to generate Express { docEntity.BaseDefinition = t.BaseType.Name; } } docEntity.IsAbstract = t.IsAbstract; Dictionary <int, DocAttribute> attrsDirect = new Dictionary <int, DocAttribute>(); List <DocAttribute> attrsInverse = new List <DocAttribute>(); PropertyInfo[] fields = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | BindingFlags.DeclaredOnly); foreach (PropertyInfo field in fields) { DocAttribute docAttr = new DocAttribute(); docAttr.Name = field.Name; Type typeField = field.PropertyType; if (typeField.IsGenericType) { Type typeGeneric = typeField.GetGenericTypeDefinition(); typeField = typeField.GetGenericArguments()[0]; if (typeGeneric == typeof(Nullable <>)) { docAttr.IsOptional = true; } else if (typeGeneric == typeof(ISet <>) || typeGeneric == typeof(HashSet <>)) { docAttr.AggregationType = (int)DocAggregationEnum.SET; } else if (typeGeneric == typeof(IList <>) || typeGeneric == typeof(List <>)) { docAttr.AggregationType = (int)DocAggregationEnum.LIST; } } // primitives docAttr.DefinedType = FormatCSC.GetExpressType(typeField); MinLengthAttribute mla = (MinLengthAttribute)field.GetCustomAttribute(typeof(MinLengthAttribute)); if (mla != null) { docAttr.AggregationLower = mla.Length.ToString(); } MaxLengthAttribute mxa = (MaxLengthAttribute)field.GetCustomAttribute(typeof(MaxLengthAttribute)); if (mxa != null) { docAttr.AggregationUpper = mxa.Length.ToString(); } DescriptionAttribute da = (DescriptionAttribute)field.GetCustomAttribute(typeof(DescriptionAttribute)); if (da != null) { docAttr.Documentation = da.Description; } DataMemberAttribute dma = (DataMemberAttribute)field.GetCustomAttribute(typeof(DataMemberAttribute)); if (dma != null) { attrsDirect.Add(dma.Order, docAttr); RequiredAttribute rqa = (RequiredAttribute)field.GetCustomAttribute(typeof(RequiredAttribute)); if (rqa == null) { docAttr.IsOptional = true; } CustomValidationAttribute cva = (CustomValidationAttribute)field.GetCustomAttribute(typeof(CustomValidationAttribute)); if (cva != null) { docAttr.IsUnique = true; } } else { InversePropertyAttribute ipa = (InversePropertyAttribute)field.GetCustomAttribute(typeof(InversePropertyAttribute)); if (ipa != null) { docAttr.Inverse = ipa.Property; attrsInverse.Add(docAttr); } } // xml XmlIgnoreAttribute xia = (XmlIgnoreAttribute)field.GetCustomAttribute(typeof(XmlIgnoreAttribute)); if (xia != null) { docAttr.XsdFormat = DocXsdFormatEnum.Hidden; } else { XmlElementAttribute xea = (XmlElementAttribute)field.GetCustomAttribute(typeof(XmlElementAttribute)); if (xea != null) { if (!String.IsNullOrEmpty(xea.ElementName)) { docAttr.XsdFormat = DocXsdFormatEnum.Element; } else { docAttr.XsdFormat = DocXsdFormatEnum.Attribute; } } } } foreach (DocAttribute docAttr in attrsDirect.Values) { docEntity.Attributes.Add(docAttr); } foreach (DocAttribute docAttr in attrsInverse) { docEntity.Attributes.Add(docAttr); } // get derived attributes based on properties #if false PropertyInfo[] props = t.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); foreach (PropertyInfo prop in props) { // if no backing field, then derived FieldInfo field = t.GetField("_" + prop.Name, BindingFlags.NonPublic | BindingFlags.Instance); if (field == null) { DocAttribute docDerived = new DocAttribute(); docDerived.Name = prop.Name; docEntity.Attributes.Add(docDerived); } } #endif } if (docDef != null) { docDef.Name = t.Name; docDef.Uuid = t.GUID; } docSchema.SortTypes(); docSchema.SortEntities(); } } // pass 2: hook up selects foreach (Type t in assem.GetTypes()) { Type[] typeInterfaces = t.GetInterfaces(); Type[] typeInherit = null; if (t.BaseType != null) { typeInherit = t.BaseType.GetInterfaces(); } if (typeInterfaces.Length > 0) { foreach (Type typeI in typeInterfaces) { if (typeInherit == null || !typeInherit.Contains <Type>(typeI)) { DocSelect docSelect = project.GetDefinition(typeI.Name) as DocSelect; if (docSelect != null) { DocSelectItem docItem = new DocSelectItem(); docItem.Name = t.Name; docSelect.Selects.Add(docItem); } } } } } }
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); } } } } }
/// <summary> /// Creates or returns emitted type, or NULL if no such type. /// </summary> /// <param name="map"></param> /// <param name="typename"></param> /// <returns></returns> public Type RegisterType(string strtype) { // this implementation maps direct and inverse attributes to fields for brevity; a production implementation would use properties as well if (strtype == null) { return(typeof(SEntity)); } Type type = null; // resolve standard types switch (strtype) { case "INTEGER": type = typeof(long); break; case "REAL": case "NUMBER": type = typeof(double); break; case "BOOLEAN": case "LOGICAL": type = typeof(bool); break; case "STRING": type = typeof(string); break; case "BINARY": case "BINARY (32)": type = typeof(byte[]); break; } if (type != null) { return(type); } // check for existing mapped type if (this.m_types.TryGetValue(strtype, out type)) { return(type); } // look up DocObject docType = null; if (!this.m_definitions.TryGetValue(strtype, out docType)) { return(null); } string schema = this.m_namespaces[docType.Name]; // not yet exist: create it TypeAttributes attr = TypeAttributes.Public; if (docType is DocEntity) { attr |= TypeAttributes.Class; DocEntity docEntity = (DocEntity)docType; if (docEntity.IsAbstract()) { attr |= TypeAttributes.Abstract; } Type typebase = RegisterType(docEntity.BaseDefinition); // calling base class may result in this class getting defined (IFC2x3 schema with IfcBuildingElement), so check again if (this.m_types.TryGetValue(strtype, out type)) { return(type); } TypeBuilder tb = this.m_module.DefineType(schema + "." + docType.Name, attr, typebase); // add typebuilder to map temporarily in case referenced by an attribute within same class or base class this.m_types.Add(strtype, tb); // custom attributes (required for JSON serialization) ConstructorInfo conContract = (typeof(DataContractAttribute).GetConstructor(new Type[] { })); PropertyInfo propContractReference = typeof(DataContractAttribute).GetProperty("IsReference"); CustomAttributeBuilder cbContract = new CustomAttributeBuilder(conContract, new object[] { }, new PropertyInfo[] { propContractReference }, new object[] { false }); // consider setting IsReference to true if/when serializers like JSON support such referencing tb.SetCustomAttribute(cbContract); // interfaces implemented by type (SELECTS) foreach (DocDefinition docdef in this.m_definitions.Values) { if (docdef is DocSelect) { DocSelect docsel = (DocSelect)docdef; foreach (DocSelectItem dsi in docsel.Selects) { if (strtype.Equals(dsi.Name)) { // register Type typeinterface = this.RegisterType(docdef.Name); tb.AddInterfaceImplementation(typeinterface); } } } } Dictionary <string, FieldInfo> mapField = new Dictionary <string, FieldInfo>(); this.m_fields.Add(tb, mapField); ConstructorInfo conMember = typeof(DataMemberAttribute).GetConstructor(new Type[] { /*typeof(int)*/ }); ConstructorInfo conLookup = typeof(DataLookupAttribute).GetConstructor(new Type[] { typeof(string) }); PropertyInfo propMemberOrder = typeof(DataMemberAttribute).GetProperty("Order"); int order = 0; foreach (DocAttribute docAttribute in docEntity.Attributes) { // exclude derived attributes if (String.IsNullOrEmpty(docAttribute.Derived)) { Type typefield = RegisterType(docAttribute.DefinedType); if (typefield == null) { typefield = typeof(object); // excluded from scope } if (docAttribute.AggregationType != 0) { if (docAttribute.AggregationAttribute != null) { // nested collection, e.g. IfcCartesianPointList3D typefield = typeof(List <>).MakeGenericType(new Type[] { typefield }); } typefield = typeof(List <>).MakeGenericType(new Type[] { typefield }); } else if (typefield.IsValueType && docAttribute.IsOptional) { typefield = typeof(Nullable <>).MakeGenericType(new Type[] { typefield }); } FieldBuilder fb = tb.DefineField(docAttribute.Name, typefield, FieldAttributes.Public); // public for now mapField.Add(docAttribute.Name, fb); if (String.IsNullOrEmpty(docAttribute.Inverse)) { // direct attributes are fields marked for serialization //CustomAttributeBuilder cb = new CustomAttributeBuilder(conMember, new object[] { order }); CustomAttributeBuilder cb = new CustomAttributeBuilder(conMember, new object[] {}, new PropertyInfo[] { propMemberOrder }, new object[] { order }); fb.SetCustomAttribute(cb); order++; } else { // inverse attributes are fields marked for lookup CustomAttributeBuilder cb = new CustomAttributeBuilder(conLookup, new object[] { docAttribute.Inverse }); fb.SetCustomAttribute(cb); } } } // remove from typebuilder this.m_types.Remove(strtype); type = tb; // avoid circular conditions -- generate type afterwords } else if (docType is DocSelect) { attr |= TypeAttributes.Interface | TypeAttributes.Abstract; TypeBuilder tb = this.m_module.DefineType(schema + "." + docType.Name, attr); // interfaces implemented by type (SELECTS) foreach (DocDefinition docdef in this.m_definitions.Values) { if (docdef is DocSelect) { DocSelect docsel = (DocSelect)docdef; foreach (DocSelectItem dsi in docsel.Selects) { if (strtype.Equals(dsi.Name)) { // register Type typeinterface = this.RegisterType(docdef.Name); tb.AddInterfaceImplementation(typeinterface); } } } } type = tb.CreateType(); } else if (docType is DocEnumeration) { DocEnumeration docEnum = (DocEnumeration)docType; EnumBuilder eb = this.m_module.DefineEnum(schema + "." + docType.Name, TypeAttributes.Public, typeof(int)); for (int i = 0; i < docEnum.Constants.Count; i++) { DocConstant docConst = docEnum.Constants[i]; eb.DefineLiteral(docConst.Name, (int)i); } type = eb.CreateType(); } else if (docType is DocDefined) { DocDefined docDef = (DocDefined)docType; attr |= TypeAttributes.Sealed; if (docDef.DefinedType == docDef.Name) { return(null); } TypeBuilder tb = this.m_module.DefineType(schema + "." + docType.Name, attr, typeof(ValueType)); // interfaces implemented by type (SELECTS) foreach (DocDefinition docdef in this.m_definitions.Values) { if (docdef is DocSelect) { DocSelect docsel = (DocSelect)docdef; foreach (DocSelectItem dsi in docsel.Selects) { if (strtype.Equals(dsi.Name)) { // register Type typeinterface = RegisterType(docdef.Name); tb.AddInterfaceImplementation(typeinterface); } } } } Type typeliteral = RegisterType(docDef.DefinedType); if (typeliteral != null) { if (docDef.Aggregation != null && docDef.Aggregation.AggregationType != 0) { typeliteral = typeof(List <>).MakeGenericType(new Type[] { typeliteral }); } else { FieldInfo fieldval = typeliteral.GetField("Value"); while (fieldval != null) { typeliteral = fieldval.FieldType; fieldval = typeliteral.GetField("Value"); } } FieldBuilder fieldValue = tb.DefineField("Value", typeliteral, FieldAttributes.Public); type = tb.CreateType(); Dictionary <string, FieldInfo> mapField = new Dictionary <string, FieldInfo>(); mapField.Add("Value", fieldValue); this.m_fields.Add(type, mapField); } } this.m_types.Add(strtype, type); return(type); }
public void Save() { string xmlns = "http://www.buildingsmart-tech.org/ifcXML/IFC4/final"; if (this.m_views != null && this.m_views.Length == 1 && !String.IsNullOrEmpty(this.m_views[0].Code)) { DocModelView docView = this.m_views[0]; if (!String.IsNullOrEmpty(docView.XsdUri)) { xmlns = docView.XsdUri; } else if (!String.IsNullOrEmpty(docView.Code)) { xmlns = "http://www.buildingsmart-tech.org/ifcXML/MVD4/" + docView.Code; } } // build map of types Dictionary <string, DocObject> map = new Dictionary <string, DocObject>(); foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocEntity docEnt in docSchema.Entities) { if (!map.ContainsKey(docEnt.Name)) { map.Add(docEnt.Name, docEnt); } } foreach (DocType docType in docSchema.Types) { if (!map.ContainsKey(docType.Name)) { map.Add(docType.Name, docType); } } } } SortedList <string, DocDefined> mapDefined = new SortedList <string, DocDefined>(this); SortedList <string, DocEnumeration> mapEnum = new SortedList <string, DocEnumeration>(this); SortedList <string, DocSelect> mapSelect = new SortedList <string, DocSelect>(this); SortedList <string, DocEntity> mapEntity = new SortedList <string, DocEntity>(this); SortedList <string, DocFunction> mapFunction = new SortedList <string, DocFunction>(this); SortedList <string, DocGlobalRule> mapRule = new SortedList <string, DocGlobalRule>(this); SortedList <string, string> sort = new SortedList <string, string>(new FormatXSD(null)); foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { if (this.m_included == null || this.m_included.ContainsKey(docSchema)) { foreach (DocType docType in docSchema.Types) { if (this.m_included == null || this.m_included.ContainsKey(docType)) { if (docType is DocDefined) { if (!mapDefined.ContainsKey(docType.Name)) { mapDefined.Add(docType.Name, (DocDefined)docType); } } else if (docType is DocEnumeration) { mapEnum.Add(docType.Name, (DocEnumeration)docType); } else if (docType is DocSelect) { mapSelect.Add(docType.Name, (DocSelect)docType); } } } foreach (DocEntity docEnt in docSchema.Entities) { if (this.m_included == null || this.m_included.ContainsKey(docEnt)) { if (!mapEntity.ContainsKey(docEnt.Name)) { mapEntity.Add(docEnt.Name, docEnt); } // check for any attributes that are lists of value types requiring wrapper, e.g. IfcTextFontName foreach (DocAttribute docAttr in docEnt.Attributes) { DocObject docObjRef = null; if (docAttr.DefinedType != null && docAttr.GetAggregation() != DocAggregationEnum.NONE && map.TryGetValue(docAttr.DefinedType, out docObjRef) && docObjRef is DocDefined && docAttr.XsdFormat == DocXsdFormatEnum.Element && !(docAttr.XsdTagless == true) && !sort.ContainsKey(docAttr.DefinedType)) { sort.Add(docAttr.DefinedType, docAttr.DefinedType); } } } } foreach (DocFunction docFunc in docSchema.Functions) { if ((this.m_included == null || this.m_included.ContainsKey(docFunc)) && !mapFunction.ContainsKey(docFunc.Name)) { mapFunction.Add(docFunc.Name, docFunc); } } foreach (DocGlobalRule docRule in docSchema.GlobalRules) { if (this.m_included == null || this.m_included.ContainsKey(docRule)) { mapRule.Add(docRule.Name, docRule); } } } } } using (System.IO.StreamWriter writer = new System.IO.StreamWriter(this.m_filename)) { writer.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); writer.WriteLine("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" " + "xmlns:ifc=\"" + xmlns + "\" " + "targetNamespace=\"" + xmlns + "\" " + "elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\" >"); WriteResource(writer, "IfcDoc.xsd1.txt"); // Entities writer.WriteLine("\t<!-- element and complex type declarations (for ENTITY definitions) -->"); foreach (DocEntity docEntity in mapEntity.Values) { writer.Write(FormatEntity(docEntity, map, this.m_included)); } // Selects writer.WriteLine("\t<!-- group declarations (for SELECT data type definitions) -->"); foreach (DocSelect docSelect in mapSelect.Values) { writer.Write(FormatSelect(docSelect, map, this.m_included)); } // Enumerations writer.WriteLine("\t<!-- enumeration type declarations (for ENUMERATION data type definitions) -->"); foreach (DocEnumeration docEnum in mapEnum.Values) { writer.Write(FormatEnum(docEnum)); } // Defined Types writer.WriteLine("\t<!-- simple type declarations (for TYPE defined data type definitions) -->"); foreach (DocDefined docDefined in mapDefined.Values) { writer.Write(FormatDefinedSimple(docDefined)); } WriteResource(writer, "IfcDoc.xsd2.txt"); // sort selects alphabetically Queue <DocSelectItem> queue = new Queue <DocSelectItem>(); foreach (DocSelect docSelect in mapSelect.Values) { foreach (DocSelectItem docSelItem in docSelect.Selects) { queue.Enqueue(docSelItem); } } List <DocDefined> listWrapper = new List <DocDefined>(); // keep track of wrapped types while (queue.Count > 0) { DocSelectItem docItem = queue.Dequeue(); DocObject mapDef = null; if (map.TryGetValue(docItem.Name, out mapDef)) { if (mapDef is DocSelect) { // expand each DocSelect docSub = (DocSelect)mapDef; foreach (DocSelectItem dsi in docSub.Selects) { queue.Enqueue(dsi); } } else if (!sort.ContainsKey(docItem.Name)) { if (this.m_included == null || this.m_included.ContainsKey(mapDef)) { sort.Add(docItem.Name, docItem.Name); } } } } writer.WriteLine("\t<!-- base global wrapper declaration for atomic simple types (for embeded base schema definitions) -->"); foreach (string docItem in sort.Values) { DocObject mapDef = null; if (map.TryGetValue(docItem, out mapDef) && mapDef is DocType) { if (this.m_included == null || this.m_included.ContainsKey(mapDef)) { writer.Write(FormatTypeWrapper((DocType)mapDef, map)); } } } writer.WriteLine("</xs:schema>"); } }
public string FormatSelect(DocSelect docSelect, Dictionary<string, DocObject> map, Dictionary<DocObject, bool> included) { return "public interface " + docSelect.Name + "\r\n{\r\n}\r\n"; }
// version for computer interpretable listing public string FormatSelectFull(DocSelect docSelect, Dictionary<string, DocObject> map, Dictionary<DocObject, bool> included, bool fullListing) { StringBuilder sb = new StringBuilder(); sb.AppendLine("ifc:" + docSelect.Name); sb.AppendLine("\trdf:type owl:Class ;"); if (!fullListing) { //possibly add the individuals here as a union sb.AppendLine("\towl:equivalentClass"); sb.AppendLine("\t\t["); sb.AppendLine("\t\t\trdf:type owl:Class ;"); sb.AppendLine("\t\t\towl:unionOf "); sb.AppendLine("\t\t\t\t( "); // entities foreach (DocSelectItem docItem in docSelect.Selects) { DocObject mapDef = null; if (map.TryGetValue(docItem.Name, out mapDef)) { if (included == null || included.ContainsKey(mapDef)) { sb.AppendLine("\t\t\t\t\tifc:" + docItem.Name + " "); } } } //close unionof sb.AppendLine("\t\t\t\t) "); sb.AppendLine("\t\t] ; "); } sb.AppendLine("\trdfs:subClassOf expr:SELECT ."); sb.AppendLine(); // add members of SELECT as subclasses if (fullListing) { foreach (DocSelectItem docItem in docSelect.Selects) { DocObject mapDef = null; if (map.TryGetValue(docItem.Name, out mapDef)) { if (included == null || included.ContainsKey(mapDef)) { sb.AppendLine("ifc:" + docItem.Name); sb.AppendLine("\trdfs:subClassOf ifc:" + docSelect.Name + " ."); sb.AppendLine(); } } } } return sb.ToString(); }
public string FormatSelect(DocSelect docSelect, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included) { return(FormatSelectFull(docSelect, map, included, false)); }
/// <summary> /// Updates any connected geometry to match definition /// </summary> /// <param name="docDef"></param> public void LayoutDefinition(DocDefinition selection) { // then traverse all dependencies on selection if (selection is DocEntity) { DocEntity docEntity = (DocEntity)selection; foreach (DocAttribute docAttr in docEntity.Attributes) { LayoutLine(docEntity, docAttr.Definition, docAttr.DiagramLine); if (docAttr.DiagramLabel != null) { docAttr.DiagramLabel.X = docAttr.DiagramLine[0].X; docAttr.DiagramLabel.Y = docAttr.DiagramLine[2].Y - 20.0; } } foreach (DocLine docLine in docEntity.Tree) { LayoutTree(docEntity, docLine); } } else if (selection is DocDefinitionRef) { DocDefinitionRef docRef = (DocDefinitionRef)selection; foreach (DocLine docLine in docRef.Tree) { LayoutTree(docRef, docLine); } } else if (selection is DocDefined) { DocDefined docDef = (DocDefined)selection; LayoutLine(docDef, docDef.Definition, docDef.DiagramLine); } else if (selection is DocSelect) { DocSelect docSelect = (DocSelect)selection; foreach (DocLine docLine in docSelect.Tree) { LayoutTree(docSelect, docLine); } } else if (selection is DocPageTarget) { DocPageTarget docTarget = (DocPageTarget)selection; LayoutLine(docTarget.Definition, docTarget, docTarget.DiagramLine); docTarget.DiagramLine.Reverse(); } foreach (DocPageTarget docPageTarget in this.m_schema.PageTargets) { if (docPageTarget.Definition == selection) { LayoutLine(docPageTarget.Definition, docPageTarget, docPageTarget.DiagramLine); docPageTarget.DiagramLine.Reverse(); } } foreach (DocSchemaRef docSchemaRef in this.m_schema.SchemaRefs) { foreach (DocDefinitionRef docDefRef in docSchemaRef.Definitions) { foreach (DocLine docLine in docDefRef.Tree) { if (docLine.Definition == selection) { LayoutLine(docDefRef, docLine.Definition, docLine.DiagramLine); } else { foreach (DocLine docSub in docLine.Tree) { if (docSub.Definition == selection) { LayoutNode(docLine, docSub); } } } } } } foreach (DocEntity docEntity in this.m_schema.Entities) { // if there multile attributes refer to the same definition, then space evenly int count = 0; foreach (DocAttribute docAttr in docEntity.Attributes) { if (docAttr.Definition == selection) { count++; } } int each = 0; foreach (DocAttribute docAttr in docEntity.Attributes) { if (docAttr.Definition == selection) { LayoutLine(docEntity, docAttr.Definition, docAttr.DiagramLine); if (count > 1 && docAttr.DiagramLine.Count == 3) { each++; docAttr.DiagramLine[0].Y = selection.DiagramRectangle.Y + (selection.DiagramRectangle.Height * (double)each / (double)(count + 1)); docAttr.DiagramLine[1].Y = selection.DiagramRectangle.Y + (selection.DiagramRectangle.Height * (double)each / (double)(count + 1)); docAttr.DiagramLine[2].Y = selection.DiagramRectangle.Y + (selection.DiagramRectangle.Height * (double)each / (double)(count + 1)); } if (docAttr.DiagramLabel == null) { docAttr.DiagramLabel = new DocRectangle(); } docAttr.DiagramLabel.X = docAttr.DiagramLine[0].X; docAttr.DiagramLabel.Y = docAttr.DiagramLine[2].Y - 20.0; } } foreach (DocLine docLine in docEntity.Tree) { if (docLine.Definition == selection) { LayoutLine(docEntity, docLine.Definition, docLine.DiagramLine); } else { foreach (DocLine docSub in docLine.Tree) { if (docSub.Definition == selection) { LayoutNode(docLine, docSub); } } } } } foreach (DocType docType in this.m_schema.Types) { if (docType is DocDefined) { DocDefined docDef = (DocDefined)docType; if (docDef.Definition == selection) { LayoutLine(docDef, docDef.Definition, docDef.DiagramLine); } } else if (docType is DocSelect) { DocSelect docSel = (DocSelect)docType; foreach (DocLine docLine in docSel.Tree) { if (docLine.Definition == selection) { LayoutLine(docSel, selection, docLine.DiagramLine); } foreach (DocLine docSub in docLine.Tree) { if (docSub.Definition == selection) { LayoutNode(docLine, docSub); } } } } } // recalculate page extents and resize/repaginate if necessary double cx = 0.0; double cy = 0.0; foreach (DocType docDef in this.m_schema.Types) { ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy); } foreach (DocEntity docDef in this.m_schema.Entities) { ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy); } foreach (DocPrimitive docDef in this.m_schema.Primitives) { ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy); } foreach (DocPageTarget docDef in this.m_schema.PageTargets) { ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy); foreach (DocPageSource docSource in docDef.Sources) { ExpandExtents(docSource.DiagramRectangle, ref cx, ref cy); } } foreach (DocSchemaRef docRef in this.m_schema.SchemaRefs) { foreach (DocDefinitionRef docDef in docRef.Definitions) { ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy); } } foreach (DocComment docDef in this.m_schema.Comments) { ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy); } this.m_schema.DiagramPagesHorz = 1 + (int)Math.Floor(cx * Factor / PageX); this.m_schema.DiagramPagesVert = 1 + (int)Math.Floor(cy * Factor / PageY); }
/// <summary> /// Finds object at absolute point (regardless of scroll position or page) /// </summary> /// <param name="pt"></param> /// <returns></returns> private DocObject Pick(Point pt, out DocLine line, out ResizeHandle handle) { line = null; handle = ResizeHandle.None; if (this.m_schema == null) { return(null); } pt.X -= this.AutoScrollPosition.X; pt.Y -= this.AutoScrollPosition.Y; PointF ptFloat = new PointF(pt.X, pt.Y); foreach (DocType docType in this.m_schema.Types) { if (HitTest(docType.DiagramRectangle, pt, out handle)) { return(docType); } if (docType is DocSelect) { DocSelect docSel = (DocSelect)docType; foreach (DocLine docLine in docSel.Tree) { DocPoint docPoint = docLine.DiagramLine[docLine.DiagramLine.Count - 1]; PointF ptA = new PointF((float)(docPoint.X * Factor), (float)docPoint.Y * Factor); if (Math.Abs(ptFloat.X - ptA.X) < 4 && Math.Abs(ptFloat.Y - ptA.Y) <= 5) { handle = ResizeHandle.Move; line = docLine; return(docType); } } } } foreach (DocEntity docType in this.m_schema.Entities) { if (HitTest(docType.DiagramRectangle, pt, out handle)) { return(docType); } foreach (DocAttribute docAttr in docType.Attributes) { if (docAttr.DiagramLine != null) { for (int i = 0; i < docAttr.DiagramLine.Count - 1; i++) { PointF ptA = new PointF((float)(docAttr.DiagramLine[i].X * Factor), (float)docAttr.DiagramLine[i].Y * Factor); PointF ptB = new PointF((float)(docAttr.DiagramLine[i + 1].X * Factor), (float)docAttr.DiagramLine[i + 1].Y * Factor); PointF ptClosest = new PointF(); double distance = FindDistanceToSegment(ptFloat, ptA, ptB, out ptClosest); if (distance < 3.0) { return(docAttr); } } } } foreach (DocLine docLine in docType.Tree) { if (docLine.DiagramLine.Count > 0) { DocPoint docPoint = docLine.DiagramLine[docLine.DiagramLine.Count - 1]; PointF ptA = new PointF((float)(docPoint.X * Factor), (float)docPoint.Y * Factor); if (Math.Abs(ptFloat.X - ptA.X) < 4 && Math.Abs(ptFloat.Y - ptA.Y) <= 5) { line = docLine; handle = ResizeHandle.Move; return(docType); } } } } foreach (DocComment docType in this.m_schema.Comments) { if (HitTest(docType.DiagramRectangle, pt, out handle)) { return(docType); } } foreach (DocPageTarget docType in this.m_schema.PageTargets) { if (HitTest(docType.DiagramRectangle, pt, out handle)) { return(docType); } foreach (DocPageSource docSource in docType.Sources) { if (HitTest(docSource.DiagramRectangle, pt, out handle)) { return(docSource); } } } foreach (DocPrimitive docType in this.m_schema.Primitives) { if (HitTest(docType.DiagramRectangle, pt, out handle)) { return(docType); } } foreach (DocSchemaRef docSchemaRef in this.m_schema.SchemaRefs) { foreach (DocDefinitionRef docType in docSchemaRef.Definitions) { if (HitTest(docType.DiagramRectangle, pt, out handle)) { return(docType); } foreach (DocLine docLine in docType.Tree) { DocPoint docPoint = docLine.DiagramLine[docLine.DiagramLine.Count - 1]; PointF ptA = new PointF((float)(docPoint.X * Factor), (float)docPoint.Y * Factor); if (Math.Abs(ptFloat.X - ptA.X) < 4 && Math.Abs(ptFloat.Y - ptA.Y) <= 5) { handle = ResizeHandle.Move; line = docLine; return(docType); } } } } return(null); }
private void LoadSelect(TreeNode tnParent, DocSelect select) { if (select == null) { return; // no such entity } // add entity TreeNode tn = new TreeNode(); tn.Tag = select; tn.Text = select.Name; if (tnParent != null) { tnParent.Nodes.Add(tn); } else { this.treeViewInheritance.Nodes.Add(tn); } // add subtypes SortedList <string, DocDefinition> list = new SortedList <string, DocDefinition>(); foreach (DocSelectItem docItem in select.Selects) { // resolve to entity (inefficient, but short on time) foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocEntity docEntity in docSchema.Entities) { if (docEntity.Name.Equals(docItem.Name)) { list.Add(docEntity.Name, docEntity); } } foreach (DocType docType in docSchema.Types) { if (docType.Name.Equals(docItem.Name)) { list.Add(docType.Name, docType); } } } } } foreach (DocDefinition ent in list.Values) { if (ent is DocEntity) { LoadEntity(tn, (DocEntity)ent); } else if (ent is DocSelect) { LoadSelect(tn, (DocSelect)ent); } else if (ent is DocType) { LoadType(tn, (DocType)ent); } } }
public string FormatSelect(DocSelect docSelect, Dictionary<string, DocObject> map, Dictionary<DocObject, bool> included) { return null; // nothing to define }
public string FormatSelect(DocSelect docSelect, Dictionary<string, DocObject> map, Dictionary<DocObject, bool> included) { return FormatSelectFull(docSelect, map, included, false); }
public string FormatDefinitions(DocProject docProject, DocPublication docPublication, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included) { // clear containers listPropertiesOutput.Clear(); addedIndividuals.Clear(); attribInverses.Clear(); subTypesOfEntity.Clear(); StringBuilder sb = new StringBuilder(); string ifcversion = docProject.GetSchemaIdentifier(); //string ifcns = "http://www.buildingsmart-tech.org/ifcOWL/" + ifcversion; //string ifcns = "http://ifcowl.openbimstandards.org/" + ifcversion; string ifcns = "http://www.buildingsmart-tech.org/ifc/" + ifcversion; // namespace definitions sb.AppendLine("@prefix : <" + ifcns + "#> ."); sb.AppendLine("@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> ."); sb.AppendLine("@prefix dce: <http://purl.org/dc/elements/1.1/> ."); sb.AppendLine("@prefix owl: <http://www.w3.org/2002/07/owl#> ."); sb.AppendLine("@prefix xsd: <http://www.w3.org/2001/XMLSchema#> ."); sb.AppendLine("@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ."); sb.AppendLine("@prefix vann: <http://purl.org/vocab/vann/> ."); sb.AppendLine("@prefix list: <https://w3id.org/list#> ."); sb.AppendLine("@prefix expr: <https://w3id.org/express#> ."); sb.AppendLine("@prefix ifc: <" + ifcns + "#> ."); sb.AppendLine("@prefix cc: <http://creativecommons.org/ns#> ."); sb.AppendLine(""); // ontology definition sb.AppendLine("<" + ifcns + ">"); sb.AppendLine("\ta owl:Ontology ;"); sb.AppendLine("\trdfs:comment \"Ontology automatically generated from the EXPRESS schema using the IfcDoc functions developed by Pieter Pauwels ([email protected]) and Walter Terkaj ([email protected]) \" ;"); sb.AppendLine("\tcc:license <http://creativecommons.org/licenses/by/3.0/> ;"); sb.AppendLine("\tdce:contributor \"Jakob Beetz ([email protected])\" , \"Maria Poveda Villalon ([email protected])\" ;"); // \"Aleksandra Sojic ([email protected])\" , sb.AppendLine("\tdce:creator \"Pieter Pauwels ([email protected])\" , \"Walter Terkaj ([email protected])\" ;"); sb.AppendLine("\tdce:date \"2015/10/02\" ;"); sb.AppendLine("\tdce:description \"OWL ontology for the IFC conceptual data schema and exchange file format for Building Information Model (BIM) data\" ;"); sb.AppendLine("\tdce:identifier \"" + ifcversion + "\" ;"); sb.AppendLine("\tdce:language \"en\" ;"); sb.AppendLine("\tdce:title \"" + ifcversion + "\" ;"); sb.AppendLine("\tvann:preferredNamespacePrefix \"ifc\" ;"); sb.AppendLine("\tvann:preferredNamespaceUri \"" + ifcns + "\" ;"); sb.AppendLine("\towl:imports <https://w3id.org/express> ."); sb.AppendLine(); // check which Inverse Attributes must be discarded because of conflicts // get subtypes of an entity foreach (DocSection docSection in docProject.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocEntity docEntity in docSchema.Entities) { // get supertype/subtype if (docEntity.BaseDefinition != null) { if (!subTypesOfEntity.ContainsKey(docEntity.BaseDefinition)) { subTypesOfEntity.Add(docEntity.BaseDefinition, new HashSet <string>()); } subTypesOfEntity[docEntity.BaseDefinition].Add(docEntity.Name); } // check attributes foreach (DocAttribute docAttr in docEntity.Attributes) { if (docAttr.Inverse != null) { var key = new Tuple <string, string>(docAttr.Inverse, docAttr.DefinedType); if (!attribInverses.ContainsKey(key)) { attribInverses.Add(key, 1); } else { attribInverses[key] += 1; } } } } } } // generate definitions foreach (DocSection docSection in docProject.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocType docType in docSchema.Types) { bool use = false; included.TryGetValue(docType, out use); if (use) { if (docType is DocDefined) { DocDefined docDefined = (DocDefined)docType; string text = this.FormatDefinedFull(docDefined, true); sb.Append(text); } else if (docType is DocSelect) { DocSelect docSelect = (DocSelect)docType; string text = this.FormatSelectFull(docSelect, map, included, true); sb.Append(text); } else if (docType is DocEnumeration) { DocEnumeration docEnumeration = (DocEnumeration)docType; string text = this.FormatEnumerationFull(docEnumeration, true); sb.Append(text); } } } foreach (DocEntity docEntity in docSchema.Entities) { bool use = false; included.TryGetValue(docEntity, out use); if (use) { string text = this.FormatEntityFull(docEntity, map, included, true); sb.Append(text); } } } } listPropertiesOutput.Clear(); return(sb.ToString()); }
public string FormatSelect(DocSelect docSelect, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included) { return(null); // nothing to define }
private void LoadSelect(TreeNode tnParent, DocSelect select) { if (select == null) return; // no such entity // add entity TreeNode tn = new TreeNode(); tn.Tag = select; tn.Text = select.Name; if (tnParent != null) { tnParent.Nodes.Add(tn); } else { this.treeViewInheritance.Nodes.Add(tn); } // add subtypes SortedList<string, DocDefinition> list = new SortedList<string, DocDefinition>(); foreach (DocSelectItem docItem in select.Selects) { // resolve to entity (inefficient, but short on time) foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocEntity docEntity in docSchema.Entities) { if (docEntity.Name.Equals(docItem.Name)) { list.Add(docEntity.Name, docEntity); } } foreach (DocType docType in docSchema.Types) { if (docType.Name.Equals(docItem.Name)) { list.Add(docType.Name, docType); } } } } } foreach (DocDefinition ent in list.Values) { if (ent is DocEntity) { LoadEntity(tn, (DocEntity)ent); } else if (ent is DocSelect) { LoadSelect(tn, (DocSelect)ent); } else if (ent is DocType) { LoadType(tn, (DocType)ent); } } }
/// <summary> /// Creates or returns emitted type, or NULL if no such type. /// </summary> /// <param name="map"></param> /// <param name="typename"></param> /// <returns></returns> public Type RegisterType(string strtype) { // this implementation maps direct and inverse attributes to fields for brevity; a production implementation would use properties as well if (strtype == null) { return(typeof(object)); } Type type = null; // resolve standard types switch (strtype) { case "INTEGER": type = typeof(long); break; case "REAL": case "NUMBER": type = typeof(double); break; case "BOOLEAN": case "LOGICAL": type = typeof(bool); break; case "STRING": type = typeof(string); break; case "BINARY": case "BINARY (32)": type = typeof(byte[]); break; } if (type != null) { return(type); } // check for existing mapped type if (this.m_types.TryGetValue(strtype, out type)) { return(type); } // look up DocObject docType = null; if (!this.m_definitions.TryGetValue(strtype, out docType)) { return(null); } string schema = this.m_namespaces[docType.Name]; // not yet exist: create it TypeAttributes attr = TypeAttributes.Public; if (docType is DocEntity) { attr |= TypeAttributes.Class; DocEntity docEntity = (DocEntity)docType; if (docEntity.IsAbstract) { attr |= TypeAttributes.Abstract; } Type typebase = RegisterType(docEntity.BaseDefinition); // calling base class may result in this class getting defined (IFC2x3 schema with IfcBuildingElement), so check again if (this.m_types.TryGetValue(strtype, out type)) { return(type); } TypeBuilder tb = this.m_module.DefineType(this.m_rootnamespace + schema + "." + docType.Name, attr, typebase); // add typebuilder to map temporarily in case referenced by an attribute within same class or base class this.m_types.Add(strtype, tb); // custom attributes (required for JSON serialization) ConstructorInfo conContract = (typeof(DataContractAttribute).GetConstructor(new Type[] { })); PropertyInfo propContractReference = typeof(DataContractAttribute).GetProperty("IsReference"); CustomAttributeBuilder cbContract = new CustomAttributeBuilder(conContract, new object[] { }, new PropertyInfo[] { propContractReference }, new object[] { false }); // consider setting IsReference to true if/when serializers like JSON support such referencing tb.SetCustomAttribute(cbContract); string displayname = docType.Name; if (displayname != null) { ConstructorInfo conReq = typeof(DisplayNameAttribute).GetConstructor(new Type[] { typeof(string) }); CustomAttributeBuilder cabReq = new CustomAttributeBuilder(conReq, new object[] { displayname }); tb.SetCustomAttribute(cabReq); } string description = docType.Documentation; if (description != null) { ConstructorInfo conReq = typeof(DescriptionAttribute).GetConstructor(new Type[] { typeof(string) }); CustomAttributeBuilder cabReq = new CustomAttributeBuilder(conReq, new object[] { description }); tb.SetCustomAttribute(cabReq); } // interfaces implemented by type (SELECTS) foreach (DocDefinition docdef in this.m_definitions.Values) { if (docdef is DocSelect) { DocSelect docsel = (DocSelect)docdef; foreach (DocSelectItem dsi in docsel.Selects) { if (strtype.Equals(dsi.Name)) { // register Type typeinterface = this.RegisterType(docdef.Name); tb.AddInterfaceImplementation(typeinterface); } } } } Dictionary <string, FieldInfo> mapField = new Dictionary <string, FieldInfo>(); this.m_fields.Add(tb, mapField); ConstructorInfo conMember = typeof(DataMemberAttribute).GetConstructor(new Type[] { /*typeof(int)*/ }); ConstructorInfo conInverse = typeof(InversePropertyAttribute).GetConstructor(new Type[] { typeof(string) }); PropertyInfo propMemberOrder = typeof(DataMemberAttribute).GetProperty("Order"); int order = 0; foreach (DocAttribute docAttribute in docEntity.Attributes) { DocObject docRef = null; if (docAttribute.DefinedType != null) { this.m_definitions.TryGetValue(docAttribute.DefinedType, out docRef); } // exclude derived attributes if (String.IsNullOrEmpty(docAttribute.Derived)) { Type typefield = RegisterType(docAttribute.DefinedType); if (typefield == null) { typefield = typeof(object); // excluded from scope } if (docAttribute.AggregationType != 0) { if (docAttribute.AggregationAttribute != null) { // list of list switch (docAttribute.AggregationAttribute.GetAggregation()) { case DocAggregationEnum.SET: typefield = typeof(ISet <>).MakeGenericType(new Type[] { typefield }); break; case DocAggregationEnum.LIST: default: typefield = typeof(IList <>).MakeGenericType(new Type[] { typefield }); break; } } switch (docAttribute.GetAggregation()) { case DocAggregationEnum.SET: typefield = typeof(ISet <>).MakeGenericType(new Type[] { typefield }); break; case DocAggregationEnum.LIST: default: typefield = typeof(IList <>).MakeGenericType(new Type[] { typefield }); break; } } else if (typefield.IsValueType && docAttribute.IsOptional) { typefield = typeof(Nullable <>).MakeGenericType(new Type[] { typefield }); } FieldBuilder fb = tb.DefineField("_" + docAttribute.Name, typefield, FieldAttributes.Private); mapField.Add(docAttribute.Name, fb); PropertyBuilder pb = RegisterProperty(docAttribute.Name, typefield, tb, fb); if (String.IsNullOrEmpty(docAttribute.Inverse)) { // direct attributes are fields marked for serialization CustomAttributeBuilder cb = new CustomAttributeBuilder(conMember, new object[] { }, new PropertyInfo[] { propMemberOrder }, new object[] { order }); pb.SetCustomAttribute(cb); order++; // mark if required if (!docAttribute.IsOptional) { ConstructorInfo conReq = typeof(RequiredAttribute).GetConstructor(new Type[] { }); CustomAttributeBuilder cabReq = new CustomAttributeBuilder(conReq, new object[] { }); pb.SetCustomAttribute(cabReq); } } else { // inverse attributes are fields marked for lookup CustomAttributeBuilder cb = new CustomAttributeBuilder(conInverse, new object[] { docAttribute.Inverse }); pb.SetCustomAttribute(cb); } // XML ConstructorInfo conXSD; CustomAttributeBuilder cabXSD; if (docAttribute.AggregationAttribute == null && (docRef is DocDefined || docRef is DocEnumeration)) { conXSD = typeof(XmlAttributeAttribute).GetConstructor(new Type[] { }); cabXSD = new CustomAttributeBuilder(conXSD, new object[] { }); pb.SetCustomAttribute(cabXSD); } else { switch (docAttribute.XsdFormat) { case DocXsdFormatEnum.Element: conXSD = typeof(XmlElementAttribute).GetConstructor(new Type[] { typeof(string) }); cabXSD = new CustomAttributeBuilder(conXSD, new object[] { docAttribute.DefinedType }); pb.SetCustomAttribute(cabXSD); break; case DocXsdFormatEnum.Attribute: conXSD = typeof(XmlElementAttribute).GetConstructor(new Type[] { }); cabXSD = new CustomAttributeBuilder(conXSD, new object[] { }); pb.SetCustomAttribute(cabXSD); break; case DocXsdFormatEnum.Hidden: conXSD = typeof(XmlIgnoreAttribute).GetConstructor(new Type[] { }); cabXSD = new CustomAttributeBuilder(conXSD, new object[] { }); pb.SetCustomAttribute(cabXSD); break; } } // documentation string fielddisplayname = docAttribute.Name; if (displayname != null) { ConstructorInfo conReq = typeof(DisplayNameAttribute).GetConstructor(new Type[] { typeof(string) }); CustomAttributeBuilder cabReq = new CustomAttributeBuilder(conReq, new object[] { fielddisplayname }); pb.SetCustomAttribute(cabReq); } string fielddescription = docAttribute.Documentation; if (description != null) { ConstructorInfo conReq = typeof(DescriptionAttribute).GetConstructor(new Type[] { typeof(string) }); CustomAttributeBuilder cabReq = new CustomAttributeBuilder(conReq, new object[] { fielddescription }); pb.SetCustomAttribute(cabReq); } } } // remove from typebuilder this.m_types.Remove(strtype); type = tb; // avoid circular conditions -- generate type afterwords } else if (docType is DocSelect) { attr |= TypeAttributes.Interface | TypeAttributes.Abstract; TypeBuilder tb = this.m_module.DefineType(this.m_rootnamespace + schema + "." + docType.Name, attr); // interfaces implemented by type (SELECTS) foreach (DocDefinition docdef in this.m_definitions.Values) { if (docdef is DocSelect) { DocSelect docsel = (DocSelect)docdef; foreach (DocSelectItem dsi in docsel.Selects) { if (strtype.Equals(dsi.Name)) { // register Type typeinterface = this.RegisterType(docdef.Name); tb.AddInterfaceImplementation(typeinterface); } } } } type = tb.CreateType(); } else if (docType is DocEnumeration) { DocEnumeration docEnum = (DocEnumeration)docType; EnumBuilder eb = this.m_module.DefineEnum(schema + "." + docType.Name, TypeAttributes.Public, typeof(int)); for (int i = 0; i < docEnum.Constants.Count; i++) { DocConstant docConst = docEnum.Constants[i]; FieldBuilder fb = eb.DefineLiteral(docConst.Name, (int)i); foreach (DocLocalization docLocal in docConst.Localization) { CustomAttributeBuilder cab = docLocal.ToCustomAttributeBuilder(); if (cab != null) { fb.SetCustomAttribute(cab); } } } type = eb.CreateType(); } else if (docType is DocDefined) { DocDefined docDef = (DocDefined)docType; attr |= TypeAttributes.Sealed; if (docDef.DefinedType == docDef.Name) { return(null); } TypeBuilder tb = this.m_module.DefineType(this.m_rootnamespace + schema + "." + docType.Name, attr, typeof(ValueType)); // interfaces implemented by type (SELECTS) foreach (DocDefinition docdef in this.m_definitions.Values) { if (docdef is DocSelect) { DocSelect docsel = (DocSelect)docdef; foreach (DocSelectItem dsi in docsel.Selects) { if (strtype.Equals(dsi.Name)) { // register Type typeinterface = RegisterType(docdef.Name); tb.AddInterfaceImplementation(typeinterface); } } } } Type typeliteral = RegisterType(docDef.DefinedType); if (typeliteral != null) { if (docDef.Aggregation != null && docDef.Aggregation.AggregationType != 0) { switch (docDef.Aggregation.GetAggregation()) { case DocAggregationEnum.SET: typeliteral = typeof(ISet <>).MakeGenericType(new Type[] { typeliteral }); break; case DocAggregationEnum.LIST: default: typeliteral = typeof(IList <>).MakeGenericType(new Type[] { typeliteral }); break; } } else { #if false // now use direct type -- don't recurse FieldInfo fieldval = typeliteral.GetField("Value"); while (fieldval != null) { typeliteral = fieldval.FieldType; fieldval = typeliteral.GetField("Value"); } #endif } FieldBuilder fieldValue = tb.DefineField("Value", typeliteral, FieldAttributes.Public); RegisterProperty("Value", typeliteral, tb, fieldValue); type = tb.CreateType(); Dictionary <string, FieldInfo> mapField = new Dictionary <string, FieldInfo>(); mapField.Add("Value", fieldValue); this.m_fields.Add(type, mapField); } } this.m_types.Add(strtype, type); return(type); }
/// <summary> /// Loads all content from a folder hierarchy (overlaying anything already existing) /// </summary> /// <param name="project"></param> /// <param name="path"></param> public static void Load(DocProject project, string path) { // get all files within folder hierarchy string pathSchema = path + @"\schemas"; IEnumerable <string> en = System.IO.Directory.EnumerateFiles(pathSchema, "*.cs", System.IO.SearchOption.AllDirectories); List <string> list = new List <string>(); foreach (string s in en) { list.Add(s); } string[] files = list.ToArray(); Dictionary <string, string> options = new Dictionary <string, string> { { "CompilerVersion", "v4.0" } }; Microsoft.CSharp.CSharpCodeProvider prov = new Microsoft.CSharp.CSharpCodeProvider(options); System.CodeDom.Compiler.CompilerParameters parms = new System.CodeDom.Compiler.CompilerParameters(); parms.GenerateInMemory = true; parms.GenerateExecutable = false; parms.ReferencedAssemblies.Add("System.dll"); parms.ReferencedAssemblies.Add("System.Core.dll"); parms.ReferencedAssemblies.Add("System.ComponentModel.dll"); parms.ReferencedAssemblies.Add("System.ComponentModel.DataAnnotations.dll"); parms.ReferencedAssemblies.Add("System.Data.dll"); parms.ReferencedAssemblies.Add("System.Runtime.Serialization.dll"); parms.ReferencedAssemblies.Add("System.Xml.dll"); System.CodeDom.Compiler.CompilerResults results = prov.CompileAssemblyFromFile(parms, files); System.Reflection.Assembly assem = results.CompiledAssembly; // look through classes of assembly foreach (Type t in assem.GetTypes()) { string[] namespaceparts = t.Namespace.Split('.'); string schema = namespaceparts[namespaceparts.Length - 1]; DocSection docSection = null; if (t.Namespace.EndsWith("Resource")) { docSection = project.Sections[7]; } else if (t.Namespace.EndsWith("Domain")) { docSection = project.Sections[6]; } else if (t.Namespace.Contains("Shared")) { docSection = project.Sections[5]; } else { docSection = project.Sections[4]; // kernel, extensions } // find schema DocSchema docSchema = null; foreach (DocSchema docEachSchema in docSection.Schemas) { if (docEachSchema.Name.Equals(schema)) { docSchema = docEachSchema; break; } } if (docSchema == null) { docSchema = new DocSchema(); docSchema.Name = schema; docSection.Schemas.Add(docSchema); docSection.SortSchemas(); } DocDefinition docDef = null; if (t.IsEnum) { DocEnumeration docEnum = new DocEnumeration(); docSchema.Types.Add(docEnum); docDef = docEnum; System.Reflection.FieldInfo[] fields = t.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); foreach (System.Reflection.FieldInfo field in fields) { DocConstant docConst = new DocConstant(); docEnum.Constants.Add(docConst); docConst.Name = field.Name; DescriptionAttribute[] attrs = (DescriptionAttribute[])field.GetCustomAttributes(typeof(DescriptionAttribute), false); if (attrs.Length == 1) { docConst.Documentation = attrs[0].Description; } } } else if (t.IsValueType) { DocDefined docDefined = new DocDefined(); docSchema.Types.Add(docDefined); docDef = docDefined; PropertyInfo[] fields = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); docDefined.DefinedType = fields[0].PropertyType.Name; } else if (t.IsInterface) { DocSelect docSelect = new DocSelect(); docSchema.Types.Add(docSelect); docDef = docSelect; } else if (t.IsClass) { DocEntity docEntity = new DocEntity(); docSchema.Entities.Add(docEntity); docDef = docEntity; if (t.BaseType != typeof(object)) { docEntity.BaseDefinition = t.BaseType.Name; } if (!t.IsAbstract) { docEntity.EntityFlags = 0x20; } Dictionary <int, DocAttribute> attrsDirect = new Dictionary <int, DocAttribute>(); List <DocAttribute> attrsInverse = new List <DocAttribute>(); PropertyInfo[] fields = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | BindingFlags.DeclaredOnly); foreach (PropertyInfo field in fields) { DocAttribute docAttr = new DocAttribute(); docAttr.Name = field.Name.Substring(1); Type typeField = field.PropertyType; if (typeField.IsGenericType) { Type typeGeneric = typeField.GetGenericTypeDefinition(); typeField = typeField.GetGenericArguments()[0]; if (typeGeneric == typeof(Nullable <>)) { docAttr.IsOptional = true; } else if (typeGeneric == typeof(ISet <>)) { docAttr.AggregationType = (int)DocAggregationEnum.SET; } else if (typeGeneric == typeof(IList <>)) { docAttr.AggregationType = (int)DocAggregationEnum.LIST; } } docAttr.DefinedType = typeField.Name; MinLengthAttribute mla = (MinLengthAttribute)field.GetCustomAttribute(typeof(MinLengthAttribute)); if (mla != null) { docAttr.AggregationLower = mla.Length.ToString(); } MaxLengthAttribute mxa = (MaxLengthAttribute)field.GetCustomAttribute(typeof(MaxLengthAttribute)); if (mxa != null) { docAttr.AggregationUpper = mxa.Length.ToString(); } PropertyInfo propinfo = t.GetProperty(docAttr.Name); if (propinfo != null) { DescriptionAttribute da = (DescriptionAttribute)propinfo.GetCustomAttribute(typeof(DescriptionAttribute)); if (da != null) { docAttr.Documentation = da.Description; } } DataMemberAttribute dma = (DataMemberAttribute)field.GetCustomAttribute(typeof(DataMemberAttribute)); if (dma != null) { attrsDirect.Add(dma.Order, docAttr); RequiredAttribute rqa = (RequiredAttribute)field.GetCustomAttribute(typeof(RequiredAttribute)); if (rqa == null) { docAttr.IsOptional = true; } CustomValidationAttribute cva = (CustomValidationAttribute)field.GetCustomAttribute(typeof(CustomValidationAttribute)); if (cva != null) { docAttr.IsUnique = true; } } else { InversePropertyAttribute ipa = (InversePropertyAttribute)field.GetCustomAttribute(typeof(InversePropertyAttribute)); if (ipa != null) { docAttr.Inverse = ipa.Property; attrsInverse.Add(docAttr); } } // xml XmlIgnoreAttribute xia = (XmlIgnoreAttribute)field.GetCustomAttribute(typeof(XmlIgnoreAttribute)); if (xia != null) { docAttr.XsdFormat = DocXsdFormatEnum.Hidden; } else { XmlElementAttribute xea = (XmlElementAttribute)field.GetCustomAttribute(typeof(XmlElementAttribute)); if (xea != null) { if (!String.IsNullOrEmpty(xea.ElementName)) { docAttr.XsdFormat = DocXsdFormatEnum.Element; } else { docAttr.XsdFormat = DocXsdFormatEnum.Attribute; } } } } foreach (DocAttribute docAttr in attrsDirect.Values) { docEntity.Attributes.Add(docAttr); } foreach (DocAttribute docAttr in attrsInverse) { docEntity.Attributes.Add(docAttr); } // get derived attributes based on properties PropertyInfo[] props = t.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); foreach (PropertyInfo prop in props) { // if no backing field, then derived FieldInfo field = t.GetField("_" + prop.Name, BindingFlags.NonPublic | BindingFlags.Instance); if (field == null) { DocAttribute docDerived = new DocAttribute(); docDerived.Name = prop.Name; docEntity.Attributes.Add(docDerived); } } } if (docDef != null) { docDef.Name = t.Name; docDef.Uuid = t.GUID; } docSchema.SortTypes(); docSchema.SortEntities(); } // pass 2: hook up selects foreach (Type t in assem.GetTypes()) { Type[] typeInterfaces = t.GetInterfaces(); if (typeInterfaces.Length > 0) { foreach (Type typeI in typeInterfaces) { DocSelect docSelect = project.GetDefinition(typeI.Name) as DocSelect; if (docSelect != null) { DocSelectItem docItem = new DocSelectItem(); docItem.Name = t.Name; docSelect.Selects.Add(docItem); } } } } // EXPRESS rules (eventually in C#, though .exp file snippets for now) en = System.IO.Directory.EnumerateFiles(pathSchema, "*.exp", System.IO.SearchOption.AllDirectories); foreach (string file in en) { string name = Path.GetFileNameWithoutExtension(file); string expr = null; using (StreamReader readExpr = new StreamReader(file, Encoding.UTF8)) { expr = readExpr.ReadToEnd(); } if (name.Contains('-')) { // where rule string[] parts = name.Split('-'); if (parts.Length == 2) { DocWhereRule docWhere = new DocWhereRule(); docWhere.Name = parts[1]; docWhere.Expression = expr; DocDefinition docDef = project.GetDefinition(parts[0]); if (docDef is DocEntity) { DocEntity docEnt = (DocEntity)docDef; docEnt.WhereRules.Add(docWhere); } else if (docDef is DocDefined) { DocDefined docEnt = (DocDefined)docDef; docEnt.WhereRules.Add(docWhere); } else if (docDef == null) { //... global rule... } } } else { // function string schema = Path.GetDirectoryName(file); schema = Path.GetDirectoryName(schema); schema = Path.GetFileName(schema); DocSchema docSchema = project.GetSchema(schema); if (docSchema != null) { DocFunction docFunction = new DocFunction(); docSchema.Functions.Add(docFunction); docFunction.Name = name; docFunction.Expression = expr; } } } // now, hook up html documentation en = System.IO.Directory.EnumerateFiles(pathSchema, "*.htm", System.IO.SearchOption.AllDirectories); foreach (string file in en) { string name = Path.GetFileNameWithoutExtension(file); DocObject docObj = null; if (name == "schema") { string schema = Path.GetDirectoryName(file); schema = Path.GetFileName(schema); docObj = project.GetSchema(schema); } else if (name.Contains('-')) { // where rule string[] parts = name.Split('-'); if (parts.Length == 2) { DocDefinition docDef = project.GetDefinition(parts[0]); if (docDef is DocEntity) { DocEntity docEnt = (DocEntity)docDef; foreach (DocWhereRule docWhereRule in docEnt.WhereRules) { if (docWhereRule.Name.Equals(parts[1])) { docObj = docWhereRule; break; } } } else if (docDef is DocDefined) { DocDefined docEnt = (DocDefined)docDef; foreach (DocWhereRule docWhereRule in docEnt.WhereRules) { if (docWhereRule.Name.Equals(parts[1])) { docObj = docWhereRule; break; } } } } } else { docObj = project.GetDefinition(name); if (docObj == null) { docObj = project.GetFunction(name); } } if (docObj != null) { using (StreamReader readHtml = new StreamReader(file, Encoding.UTF8)) { docObj.Documentation = readHtml.ReadToEnd(); } } } // load schema diagrams en = System.IO.Directory.EnumerateFiles(pathSchema, "*.svg", System.IO.SearchOption.AllDirectories); foreach (string file in en) { string schema = Path.GetDirectoryName(file); schema = Path.GetFileName(schema); DocSchema docSchema = project.GetSchema(schema); if (docSchema != null) { using (IfcDoc.Schema.SVG.SchemaSVG schemaSVG = new IfcDoc.Schema.SVG.SchemaSVG(file, docSchema, project)) { schemaSVG.Load(); } } } // psets, qsets //... // exchanges en = System.IO.Directory.EnumerateFiles(path, "*.mvdxml", System.IO.SearchOption.AllDirectories); foreach (string file in en) { IfcDoc.Schema.MVD.SchemaMVD.Load(project, file); } // examples string pathExamples = path + @"\examples"; if (Directory.Exists(pathExamples)) { en = System.IO.Directory.EnumerateFiles(pathExamples, "*.htm", SearchOption.TopDirectoryOnly); foreach (string file in en) { DocExample docExample = new DocExample(); docExample.Name = Path.GetFileNameWithoutExtension(file); project.Examples.Add(docExample); using (StreamReader reader = new StreamReader(file)) { docExample.Documentation = reader.ReadToEnd(); } string dirpath = file.Substring(0, file.Length - 4); if (Directory.Exists(dirpath)) { IEnumerable <string> suben = System.IO.Directory.EnumerateFiles(dirpath, "*.ifc", SearchOption.TopDirectoryOnly); foreach (string ex in suben) { DocExample docEx = new DocExample(); docEx.Name = Path.GetFileNameWithoutExtension(ex); docExample.Examples.Add(docEx); // read the content of the file using (FileStream fs = new FileStream(ex, FileMode.Open, FileAccess.Read)) { docEx.File = new byte[fs.Length]; fs.Read(docEx.File, 0, docEx.File.Length); } // read documentation string exdoc = ex.Substring(0, ex.Length - 4) + ".htm"; if (File.Exists(exdoc)) { using (StreamReader reader = new StreamReader(exdoc)) { docEx.Documentation = reader.ReadToEnd(); } } } } } } // localization en = System.IO.Directory.EnumerateFiles(path, "*.txt", System.IO.SearchOption.AllDirectories); foreach (string file in en) { using (FormatCSV format = new FormatCSV(file)) { try { format.Instance = project; format.Load(); } catch { } } } }
public static string FormatSelect(DocSelect docSelect, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included) { StringBuilder sb = new StringBuilder(); sb.Append("\t<xs:group name=\""); sb.Append(docSelect.Name); sb.Append("\">"); sb.AppendLine(); sb.Append("\t\t<xs:choice>"); sb.AppendLine(); Queue <DocSelectItem> queue = new Queue <DocSelectItem>(); foreach (DocSelectItem docItem in docSelect.Selects) { queue.Enqueue(docItem); } // sort selects alphabetically SortedList <string, DocSelectItem> sort = new SortedList <string, DocSelectItem>(new FormatXSD(null)); while (queue.Count > 0) { DocSelectItem docItem = queue.Dequeue(); DocObject mapDef = null; if (map.TryGetValue(docItem.Name, out mapDef)) { if (mapDef is DocSelect) { // expand each DocSelect docSub = (DocSelect)mapDef; foreach (DocSelectItem dsi in docSub.Selects) { queue.Enqueue(dsi); } } else if ((included == null || included.ContainsKey(mapDef)) && !sort.ContainsKey(docItem.Name)) { //TODO: if abstract entity, then go through subtypes... sort.Add(docItem.Name, docItem); } } } // resolve selects into final elements // first entities, then wrappers // entities foreach (DocSelectItem docItem in sort.Values) { DocObject mapDef = null; if (map.TryGetValue(docItem.Name, out mapDef)) { if (included == null || included.ContainsKey(mapDef)) { sb.Append("\t\t\t<xs:element ref=\"ifc:"); sb.Append(docItem.Name); if (mapDef is DocDefined || mapDef is DocEnumeration) { sb.Append("-wrapper"); } sb.Append("\"/>"); sb.AppendLine(); } } } sb.Append("\t\t</xs:choice>"); sb.AppendLine(); sb.Append("\t</xs:group>"); sb.AppendLine(); return(sb.ToString()); }
private void toolStripMenuItemInsertSelect_Click(object sender, EventArgs e) { TreeNode tnParent = this.treeView.SelectedNode; DocSchema docSchema = (DocSchema)tnParent.Tag; DocType docType = new DocSelect(); InitDefinition(docType); docSchema.Types.Add(docType); this.treeView.SelectedNode = this.LoadNode(tnParent.Nodes[0], docType, null, true); toolStripMenuItemEditRename_Click(this, e); }
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(); } }
/// <summary> /// Indicates whether select includes another select, entity, or value type /// </summary> /// <param name="docSelect"></param> /// <param name="docDefinition"></param> /// <returns></returns> private static bool SelectIncludes(DocSelect docSelect, string defname, Dictionary<string, DocObject> map) { foreach (DocSelectItem docSelectItem in docSelect.Selects) { if (docSelectItem.Name == defname) return true; DocObject docObj = null; if (map.TryGetValue(docSelectItem.Name, out docObj)) { if (docObj is DocSelect) { bool result = SelectIncludes((DocSelect)docObj, defname, map); if (result) return true; } else if (docObj is DocEntity) { bool result = EntityIncludes((DocEntity)docObj, defname, map); if (result) return true; } } } return false; }