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 FormatEnumeration(DocEnumeration docEnumeration) { StringBuilder sb = new StringBuilder(); sb.AppendLine("public enum " + docEnumeration.Name); sb.AppendLine("{"); int counter = 0; foreach (DocConstant docConstant in docEnumeration.Constants) { int val; if (docConstant.Name.Equals("NOTDEFINED")) { val = 0; } else if (docConstant.Name.Equals("USERDEFINED")) { val = -1; } else { counter++; val = counter; } sb.AppendLine("\t" + docConstant.Name + " = " + val + ","); } sb.Append("}"); return(sb.ToString()); }
private void LoadPredefined() { if ((this.m_options & SelectDefinitionOptions.Predefined) == 0) { return; } this.labelPredefined.Enabled = false; this.comboBoxPredefined.Enabled = false; this.comboBoxPredefined.Items.Clear(); this.comboBoxPredefined.SelectedIndex = -1; this.comboBoxPredefined.Text = String.Empty; if (this.treeViewInheritance.SelectedNode == null) { return; } DocEntity entity = this.treeViewInheritance.SelectedNode.Tag as DocEntity; if (entity == null) { return; } foreach (DocAttribute docAttr in entity.Attributes) { if (docAttr.Name.Equals("PredefinedType")) { // resolve the type foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocType docType in docSchema.Types) { if (docType is DocEnumeration && docType.Name.Equals(docAttr.DefinedType)) { this.comboBoxPredefined.Items.Clear(); // found it DocEnumeration docEnum = (DocEnumeration)docType; foreach (DocConstant docConst in docEnum.Constants) { // new: in combobox this.comboBoxPredefined.Items.Add(docConst); } this.labelPredefined.Enabled = true; this.comboBoxPredefined.Enabled = true; //return; } } } } } } }
public static string FormatEnum(DocEnumeration docEnum) { StringBuilder sb = new StringBuilder(); sb.Append("\t<xs:simpleType name=\""); sb.Append(docEnum.Name); sb.Append("\">"); sb.AppendLine(); sb.AppendLine("\t\t<xs:restriction base=\"xs:string\">"); foreach (DocConstant docConst in docEnum.Constants) { sb.Append("\t\t\t<xs:enumeration value=\""); sb.Append(docConst.Name.ToLower()); sb.Append("\"/>"); sb.AppendLine(); } sb.AppendLine("\t\t</xs:restriction>"); sb.Append("\t</xs:simpleType>"); sb.AppendLine(); return(sb.ToString()); }
public string FormatEnumeration(DocEnumeration docEnumeration, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included) { StringBuilder sb = new StringBuilder(); sb.AppendLine("public enum " + docEnumeration.Name); sb.AppendLine("{"); foreach (DocConstant docConstant in docEnumeration.Constants) { sb.AppendLine("\t" + docConstant.Name + ","); } sb.AppendLine("}"); return(sb.ToString()); }
public string FormatEnumeration(DocEnumeration docEnumeration) { StringBuilder sb = new StringBuilder(); sb.AppendLine("public enum " + docEnumeration.Name); sb.AppendLine("{"); foreach (DocConstant docConstant in docEnumeration.Constants) { sb.AppendLine("\t" + docConstant.Name + ","); } sb.AppendLine("}"); return(sb.ToString()); }
private void WriteList(System.IO.StreamWriter writer, SortedList <string, DocObject> sortlist) { foreach (string key in sortlist.Keys) { DocObject docEntity = sortlist[key]; WriteItem(writer, docEntity, 0, docEntity.Name); if (docEntity is DocEntity) { DocEntity docEnt = (DocEntity)docEntity; foreach (DocAttribute docAttr in docEnt.Attributes) { WriteItem(writer, docAttr, 1, docEntity.Name); } } else if (docEntity is DocEnumeration) { DocEnumeration docEnum = (DocEnumeration)docEntity; foreach (DocConstant docConst in docEnum.Constants) { WriteItem(writer, docConst, 1, docEntity.Name); } } else if (docEntity is DocPropertySet) { DocPropertySet docPset = (DocPropertySet)docEntity; foreach (DocProperty docProp in docPset.Properties) { WriteItem(writer, docProp, 1, docEntity.Name); } } else if (docEntity is DocPropertyEnumeration) { DocPropertyEnumeration docPE = (DocPropertyEnumeration)docEntity; foreach (DocPropertyConstant docPC in docPE.Constants) { WriteItem(writer, docPC, 1, docEntity.Name); } } else if (docEntity is DocQuantitySet) { DocQuantitySet docQset = (DocQuantitySet)docEntity; foreach (DocQuantity docQuan in docQset.Quantities) { WriteItem(writer, docQuan, 1, docEntity.Name); } } } }
// version for computer interpretable listing public string FormatEnumerationFull(DocEnumeration docEnumeration, bool fullListing) { StringBuilder sb = new StringBuilder(); sb.AppendLine("ifc:" + docEnumeration.Name); sb.AppendLine("\trdf:type owl:Class ;"); if (!fullListing) { //possibly add the items in a oneof sb.AppendLine("\towl:equivalentClass"); sb.AppendLine("\t\t["); sb.AppendLine("\t\t\trdf:type owl:Class ;"); sb.AppendLine("\t\t\towl:oneOf "); sb.AppendLine("\t\t\t\t( "); foreach (DocConstant docConst in docEnumeration.Constants) { sb.AppendLine("\t\t\t\tifc:" + docConst.Name.ToUpper() + " "); } //close oneof sb.AppendLine("\t\t\t\t) "); sb.AppendLine("\t\t] ; "); } sb.AppendLine("\trdfs:subClassOf expr:ENUMERATION ."); sb.AppendLine(); // define individuals if (fullListing) { foreach (DocConstant docConst in docEnumeration.Constants) { string indivLocalUri = docConst.Name.ToUpper(); if (!addedIndividuals.Contains(indivLocalUri)) { addedIndividuals.Add(indivLocalUri); sb.AppendLine("ifc:" + indivLocalUri); sb.AppendLine("\trdf:type " + "ifc:" + docEnumeration.Name + " , owl:NamedIndividual ;"); sb.AppendLine("\trdfs:label \"" + docConst.Name.ToUpper() + "\" ."); sb.AppendLine(); } else { sb.AppendLine("ifc:" + indivLocalUri); sb.AppendLine("\trdf:type " + "ifc:" + docEnumeration.Name + " ."); sb.AppendLine(); } } } return(sb.ToString()); }
private static void extractListingsV12_1(DocProject project, DocSchema schema, Dictionary <string, DocPropertyEnumeration> encounteredPropertyEnumerations) { foreach (DocPropertyEnumeration enumeration in schema.PropertyEnumerations) { if (encounteredPropertyEnumerations.ContainsKey(enumeration.Name)) { continue; } project.PropertyEnumerations.Add(enumeration); encounteredPropertyEnumerations[enumeration.Name] = enumeration; foreach (DocPropertyConstant constant in enumeration.Constants) { constant.Name = constant.Name.Trim(); if (!project.PropertyConstants.Contains(constant)) { project.PropertyConstants.Add(constant); } } } foreach (DocType t in schema.Types) { DocEnumeration enumeration = t as DocEnumeration; if (enumeration != null) { foreach (DocConstant constant in enumeration.Constants) { if (!project.Constants.Contains(constant)) { project.Constants.Add(constant); } } } } foreach (DocProperty property in schema.PropertySets.SelectMany(x => x.Properties)) { extractListings(project, property, encounteredPropertyEnumerations); //listings } foreach (DocQuantity quantity in schema.QuantitySets.SelectMany(x => x.Quantities)) { project.Quantities.Add(quantity); } }
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() { // prepare map Dictionary <string, DocObject> map = new Dictionary <string, DocObject>(); foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocEntity docEntity in docSchema.Entities) { map.Add(docEntity.Name, docEntity); } foreach (DocType docType in docSchema.Types) { map.Add(docType.Name, docType); } foreach (DocPropertySet docPropertySet in docSchema.PropertySets) { map.Add(docPropertySet.Name, docPropertySet); } foreach (DocQuantitySet docQuantitySet in docSchema.QuantitySets) { map.Add(docQuantitySet.Name, docQuantitySet); } foreach (DocPropertyEnumeration docPropertyEnumeration in docSchema.PropertyEnums) { map.Add(docPropertyEnumeration.Name, docPropertyEnumeration); } } } // use tabs for simplicity using (System.IO.StreamReader reader = new System.IO.StreamReader(this.m_filename)) { string headerline = reader.ReadLine(); string[] headercols = headerline.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); string blankline = reader.ReadLine(); // expect blank line // first column is name that identifies definition string[] locales = new string[headercols.Length]; string[] fields = new string[headercols.Length]; for (int icol = 0; icol < headercols.Length; icol++) { string col = headercols[icol]; int popen = col.IndexOf('('); int pclos = col.IndexOf(')'); if (popen > 0 && pclos > popen) { locales[icol] = col.Substring(popen + 1, pclos - popen - 1); fields[icol] = col.Substring(0, popen); } } // now rows while (!reader.EndOfStream) { string rowdata = reader.ReadLine(); string[] rowcells = rowdata.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); if (rowcells.Length > 1) { DocObject docObj = null; string[] fullID = rowcells[0].Split('.'); string identifier = fullID[0]; if (map.TryGetValue(identifier, out docObj)) { if (fullID.Length == 2) { string subType = fullID[1]; if (docObj is DocEntity) { DocEntity entity = (DocEntity)docObj; foreach (DocAttribute attr in entity.Attributes) { if (attr.Name == subType) { docObj = attr; break; } } } if (docObj is DocEnumeration) { DocEnumeration type = (DocEnumeration)docObj; foreach (DocConstant constnt in type.Constants) { docObj = type; break; } } if (docObj is DocPropertyEnumeration) { DocPropertyEnumeration propEnum = (DocPropertyEnumeration)docObj; foreach (DocPropertyConstant propConst in propEnum.Constants) { docObj = propEnum; break; } } if (docObj is DocPropertySet) { DocPropertySet propSet = (DocPropertySet)docObj; foreach (DocProperty docProp in propSet.Properties) { docObj = propSet; break; } } if (docObj is DocQuantitySet) { DocQuantitySet quantSet = (DocQuantitySet)docObj; foreach (DocQuantity docQuant in quantSet.Quantities) { docObj = quantSet; break; } } } for (int i = 1; i < rowcells.Length && i < headercols.Length; i++) { if (locales[i] != null) { // find existing DocLocalization docLocalization = null; foreach (DocLocalization docLocal in docObj.Localization) { if (docLocal.Locale.Equals(locales[i])) { docLocalization = docLocal; break; } } // create new if (docLocalization == null) { docLocalization = new DocLocalization(); docLocalization.Locale = locales[i]; docObj.Localization.Add(docLocalization); } string value = rowcells[i]; if (value != null && value.StartsWith("\"") && value.EndsWith("\"")) { // strip quotes value = value.Substring(1, value.Length - 2); } // update info switch (fields[i]) { case "Name": docLocalization.Name = value; break; case "Description": docLocalization.Documentation = value; break; } } } } } } } }
private void WriteList(System.IO.StreamWriter writer, SortedList <string, DocObject> sortlist) { foreach (string key in sortlist.Keys) { DocObject docEntity = sortlist[key]; WriteItem(writer, docEntity, 0, docEntity.Name); if (docEntity is DocEntity) { if ((this.m_scope & DocDefinitionScopeEnum.EntityAttribute) != 0) { DocEntity docEnt = (DocEntity)docEntity; foreach (DocAttribute docAttr in docEnt.Attributes) { WriteItem(writer, docAttr, 1, docEntity.Name); } } } else if (docEntity is DocEnumeration) { if ((this.m_scope & DocDefinitionScopeEnum.TypeConstant) != 0) { DocEnumeration docEnum = (DocEnumeration)docEntity; foreach (DocConstant docConst in docEnum.Constants) { WriteItem(writer, docConst, 1, docEntity.Name); } } } else if (docEntity is DocPropertySet) { if ((this.m_scope & DocDefinitionScopeEnum.PsetProperty) != 0) { DocPropertySet docPset = (DocPropertySet)docEntity; DocEntity docApp = null; DocEntity[] docApplicable = docPset.GetApplicableTypeDefinitions(this.m_project); if (docApplicable != null && docApplicable.Length > 0 && docApplicable[0] != null) { docApp = this.m_project.GetDefinition(docApplicable[0].BaseDefinition) as DocEntity; } foreach (DocProperty docProp in docPset.Properties) { // filter out leaf properties defined at common pset (e.g. Reference, Status) DocProperty docSuper = this.m_project.FindProperty(docProp.Name, docApp); if (docSuper == docProp || docSuper == null) { WriteItem(writer, docProp, 1, docEntity.Name); } } } } else if (docEntity is DocPropertyEnumeration) { if ((this.m_scope & DocDefinitionScopeEnum.PEnumConstant) != 0) { DocPropertyEnumeration docPE = (DocPropertyEnumeration)docEntity; foreach (DocPropertyConstant docPC in docPE.Constants) { WriteItem(writer, docPC, 1, docEntity.Name); } } } else if (docEntity is DocQuantitySet) { if ((this.m_scope & DocDefinitionScopeEnum.QsetQuantity) != 0) { DocQuantitySet docQset = (DocQuantitySet)docEntity; foreach (DocQuantity docQuan in docQset.Quantities) { WriteItem(writer, docQuan, 1, docEntity.Name); } } } } }
public static void Upload(DocProject docProject, BackgroundWorker worker, string baseurl, string username, string password, string parentid, DocModelView[] docViews) { string sessionid = Connect(docProject, worker, baseurl, username, password); #if false if (docViews != null && docViews.Length > 0) { foreach (DocModelView docView in docViews)//docProject.ModelViews) { // hack: only bridge view for now if (docView.Name.Contains("Bridge")) { string codename = docView.Name; if (!String.IsNullOrEmpty(docView.Code)) { codename = docView.Code; } IfdBase ifdView = CreateConcept(baseurl, sessionid, docView, codename, docView.Name, IfdConceptTypeEnum.BAG); //CreateRelationship(baseurl, sessionid, parentid, ifdView.guid, "COLLECTS"); // no top-level item for now foreach (DocConceptRoot docRoot in docView.ConceptRoots) { if (docRoot.Name != null) { System.Diagnostics.Debug.WriteLine(docRoot.ToString()); IfdBase ifdRoot = CreateConcept(baseurl, sessionid, docRoot, docRoot.ApplicableEntity.Name, docRoot.Name, IfdConceptTypeEnum.SUBJECT); CreateRelationship(baseurl, sessionid, ifdView.guid, ifdRoot.guid, IfdRelationshipTypeEnum.COLLECTS); foreach (DocTemplateUsage docConc in docRoot.Concepts) { UploadTemplateUsage(docProject, baseurl, sessionid, ifdRoot.guid, docConc); } } } } } } else #endif { // build list of types referenced by property sets Dictionary <string, IfdBase> mapEntities = new Dictionary <string, IfdBase>(); // core schema foreach (DocSection docSection in docProject.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { // only export objects that have associated property sets foreach (DocPropertySet docPset in docSchema.PropertySets) { IfdBase ifdPset = CreateConcept(baseurl, sessionid, docPset, docPset.Name, docPset.Name, docPset.PropertySetType.ToString(), IfdConceptTypeEnum.BAG); foreach (DocProperty docProp in docPset.Properties) { IfdBase ifdProp = CreateConcept(baseurl, sessionid, docProp, docProp.Name, docProp.Name, docProp.PropertyType.ToString(), IfdConceptTypeEnum.PROPERTY); if (ifdProp != null) { CreateRelationship(baseurl, sessionid, ifdPset.guid, ifdProp.guid, IfdRelationshipTypeEnum.COLLECTS); string paramval = docProp.PrimaryDataType; if (!String.IsNullOrEmpty(paramval)) { DocDefinition docDef = docProject.GetDefinition(paramval); if (docDef != null) { // get the measure type IfdBase ifdType = SearchConcept(baseurl, sessionid, docDef.Name, IfdConceptTypeEnum.MEASURE); if (ifdType == null) { // create concept ifdType = CreateConcept(baseurl, sessionid, docDef, docDef.Name, docDef.Name, null, IfdConceptTypeEnum.MEASURE); // for enums, get enumerated type if (docProp.PropertyType == DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE) { DocSchema docPropSchema = null; DocPropertyEnumeration docPropEnum = docProject.FindPropertyEnumeration(docProp.SecondaryDataType, out docPropSchema); if (docPropEnum != null) { foreach (DocPropertyConstant docPropConst in docPropEnum.Constants) { IfdBase ifdConst = CreateConcept(baseurl, sessionid, docPropConst, docPropConst.Name, docPropConst.Name, null, IfdConceptTypeEnum.VALUE); CreateRelationship(baseurl, sessionid, ifdType.guid, ifdConst.guid, IfdRelationshipTypeEnum.ASSIGNS_VALUES); } } } } CreateRelationship(baseurl, sessionid, ifdProp.guid, ifdType.guid, IfdRelationshipTypeEnum.ASSIGNS_MEASURES); // ??? fails for Pset_BuildingUse.NarrativeText / IfcText } } } } // now link the property set to applicable type DocEntity[] docEntities = docPset.GetApplicableTypeDefinitions(docProject); if (docEntities != null && docEntities.Length > 0) { // only the first one matters DocEntity docEnt = docEntities[0]; IfdBase ifdEnt = null; if (!mapEntities.TryGetValue(docEnt.Name, out ifdEnt)) { ifdEnt = CreateConcept(baseurl, sessionid, docEnt, docEnt.Name, docEnt.Name, null, IfdConceptTypeEnum.SUBJECT); mapEntities.Add(docEnt.Name, ifdEnt); // subtypes (predefined type) foreach (DocAttribute docAttr in docEnt.Attributes) { if (docAttr.Name.Equals("PredefinedType")) { DocEnumeration docEnum = docProject.GetDefinition(docAttr.DefinedType) as DocEnumeration; if (docEnum != null) { foreach (DocConstant docConst in docEnum.Constants) { IfdBase ifdConst = CreateConcept(baseurl, sessionid, docConst, docConst.Name, docConst.Name, null, IfdConceptTypeEnum.SUBJECT); CreateRelationship(baseurl, sessionid, ifdEnt.guid, ifdConst.guid, IfdRelationshipTypeEnum.SPECIALIZES); } } } } } CreateRelationship(baseurl, sessionid, ifdEnt.guid, ifdPset.guid, IfdRelationshipTypeEnum.ASSIGNS_COLLECTIONS); //!!! Fails with Forbidden!!! why??? // http://test.bsdd.buildingsmart.org/api/4.0/IfdRelationship/validrelations/SUBJECT/BAG indicates // <ifdRelationshipTypeEnums> // <IfdRelationshipType xmlns="http://peregrine.catenda.no/objects">ASSIGNS_COLLECTIONS</IfdRelationshipType> // </ifdRelationshipTypeEnums> } } foreach (DocQuantitySet docPset in docSchema.QuantitySets) { IfdBase ifdPset = CreateConcept(baseurl, sessionid, docPset, docPset.Name, docPset.Name, "QTO_OCCURRENCEDRIVEN", IfdConceptTypeEnum.BAG); foreach (DocQuantity docProp in docPset.Quantities) { IfdBase ifdProp = CreateConcept(baseurl, sessionid, docProp, docProp.Name, docProp.Name, docProp.QuantityType.ToString(), IfdConceptTypeEnum.PROPERTY); if (ifdProp != null) { CreateRelationship(baseurl, sessionid, ifdPset.guid, ifdProp.guid, IfdRelationshipTypeEnum.COLLECTS); string propclass = "IfcQuantityCount"; switch (docProp.QuantityType) { case DocQuantityTemplateTypeEnum.Q_AREA: propclass = "IfcQuantityArea"; break; case DocQuantityTemplateTypeEnum.Q_COUNT: propclass = "IfcQuantityCount"; break; case DocQuantityTemplateTypeEnum.Q_LENGTH: propclass = "IfcQuantityLength"; break; case DocQuantityTemplateTypeEnum.Q_TIME: propclass = "IfcQuantityTime"; break; case DocQuantityTemplateTypeEnum.Q_VOLUME: propclass = "IfcQuantityVolume"; break; case DocQuantityTemplateTypeEnum.Q_WEIGHT: propclass = "IfcQuantityWeight"; break; } string paramval = propclass; if (!String.IsNullOrEmpty(paramval)) { DocDefinition docDef = docProject.GetDefinition(paramval); if (docDef != null) { // get the measure type IfdBase ifdType = SearchConcept(baseurl, sessionid, docDef.Name, IfdConceptTypeEnum.MEASURE); if (ifdType == null) { // create concept ifdType = CreateConcept(baseurl, sessionid, docDef, docDef.Name, docDef.Name, null, IfdConceptTypeEnum.MEASURE); } CreateRelationship(baseurl, sessionid, ifdProp.guid, ifdType.guid, IfdRelationshipTypeEnum.ASSIGNS_MEASURES); // ??? fails for Pset_BuildingUse.NarrativeText / IfcText } } } } // now link the property set to applicable type DocEntity[] docEntities = docPset.GetApplicableTypeDefinitions(docProject); if (docEntities != null && docEntities.Length > 0) { // only the first one matters DocEntity docEnt = docEntities[0]; IfdBase ifdEnt = null; if (mapEntities.TryGetValue(docEnt.Name, out ifdEnt)) { CreateRelationship(baseurl, sessionid, ifdEnt.guid, ifdPset.guid, IfdRelationshipTypeEnum.ASSIGNS_COLLECTIONS); } } } } } } }
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(); if (this.m_definition != null) { writer.WriteLine("package buildingsmart.ifc"); writer.WriteLine("{"); if (this.m_definition is DocDefined) { // do nothing - don't make a separate type in Java, as that would require extra heap allocation } else if (this.m_definition is DocSelect) { writer.WriteLine("\tpublic interface " + this.m_definition.Name); writer.WriteLine("\t{"); writer.WriteLine("\t}"); } else if (this.m_definition is DocEnumeration) { DocEnumeration docEnumumeration = (DocEnumeration)this.m_definition; writer.WriteLine("\tpublic enum " + this.m_definition.Name); writer.WriteLine("\t{"); foreach (DocConstant docConstant in docEnumumeration.Constants) { writer.WriteLine("\t\t" + docConstant.Name + ","); } writer.WriteLine("\t}"); } else if (this.m_definition is DocEntity) { DocEntity docEntity = (DocEntity)this.m_definition; string basedef = docEntity.BaseDefinition; if (String.IsNullOrEmpty(basedef)) { basedef = "IfcBase"; } writer.WriteLine("\tpublic class " + this.m_definition.Name + " extends " + basedef); writer.WriteLine("\t{"); // fields foreach (DocAttribute docAttribute in docEntity.Attributes) { string deftype = docAttribute.DefinedType; // if defined type, use raw type (avoiding extra memory allocation) DocDefinition docDef = GetDefinition(deftype); if (docDef is DocDefined) { deftype = ((DocDefined)docDef).DefinedType; switch (deftype) { case "STRING": deftype = "string"; break; case "INTEGER": deftype = "int"; break; case "REAL": deftype = "double"; break; case "BOOLEAN": deftype = "bool"; break; case "LOGICAL": deftype = "int"; break; case "BINARY": deftype = "byte[]"; break; } } switch (docAttribute.GetAggregation()) { case DocAggregationEnum.SET: writer.WriteLine("\t\tprivate " + deftype + "[] " + docAttribute.Name + ";"); break; case DocAggregationEnum.LIST: writer.WriteLine("\t\tprivate " + deftype + "[] " + docAttribute.Name + ";"); break; default: writer.WriteLine("\t\tprivate " + deftype + " " + docAttribute.Name + ";"); break; } } writer.WriteLine("\t}"); } writer.WriteLine("}"); } else { #if false // TBD writer.WriteLine("package 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>"); 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>"); 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: // record enum for later { string[] parts = docProperty.SecondaryDataType.Split(':'); if (parts.Length == 2) { string typename = parts[0]; if (!mapEnums.ContainsKey(typename)) { string[] enums = parts[1].Split(','); mapEnums.Add(typename, enums); 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(); } } } // 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 string FormatEnumeration(DocEnumeration docEnumeration) { StringBuilder sb = new StringBuilder(); sb.AppendLine("public enum " + docEnumeration.Name); sb.AppendLine("{"); foreach (DocConstant docConstant in docEnumeration.Constants) { sb.AppendLine("\t" + docConstant.Name + ","); } sb.AppendLine("}"); return sb.ToString(); }
// version for computer interpretable listing public string FormatEnumerationFull(DocEnumeration docEnumeration, bool fullListing) { StringBuilder sb = new StringBuilder(); sb.AppendLine("ifc:" + docEnumeration.Name); sb.AppendLine("\trdf:type owl:Class ;"); if (!fullListing) { //possibly add the items in a oneof sb.AppendLine("\towl:equivalentClass"); sb.AppendLine("\t\t["); sb.AppendLine("\t\t\trdf:type owl:Class ;"); sb.AppendLine("\t\t\towl:oneOf "); sb.AppendLine("\t\t\t\t( "); foreach (DocConstant docConst in docEnumeration.Constants) { sb.AppendLine("\t\t\t\tifc:" + docConst.Name.ToUpper() + " "); } //close oneof sb.AppendLine("\t\t\t\t) "); sb.AppendLine("\t\t] ; "); } sb.AppendLine("\trdfs:subClassOf expr:ENUMERATION ."); sb.AppendLine(); // define individuals if (fullListing) { foreach (DocConstant docConst in docEnumeration.Constants) { string indivLocalUri = docConst.Name.ToUpper(); if (!addedIndividuals.Contains(indivLocalUri)) { addedIndividuals.Add(indivLocalUri); sb.AppendLine("ifc:" + indivLocalUri); sb.AppendLine("\trdf:type " + "ifc:" + docEnumeration.Name + " , owl:NamedIndividual ;"); sb.AppendLine("\trdfs:label \"" + docConst.Name.ToUpper() + "\" ."); sb.AppendLine(); } else { sb.AppendLine("ifc:" + indivLocalUri); sb.AppendLine("\trdf:type " + "ifc:" + docEnumeration.Name + " ."); sb.AppendLine(); } } } return sb.ToString(); }
/// <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 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 FormatEnumeration(DocEnumeration docEnumeration) { return(FormatEnumerationFull(docEnumeration, false)); }
public string FormatEnumeration(DocEnumeration docEnumeration, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included) { return(FormatEnumerationFull(docEnumeration, false)); }
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 } } } } }
/// <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 string FormatEnumeration(DocEnumeration docEnumeration) { return null; // nothing to define }
public Compiler(DocProject project, DocModelView[] views, DocExchangeDefinition exchange, bool psets) { this.m_project = project; this.m_views = views; this.m_exchange = exchange; this.m_psets = psets; // version needs to be included for extracting XML namespace (Major.Minor.Addendum.Corrigendum) string version = project.GetSchemaVersion(); ConstructorInfo conContract = (typeof(AssemblyVersionAttribute).GetConstructor(new Type[] { typeof(string) })); CustomAttributeBuilder cabAssemblyVersion = new CustomAttributeBuilder(conContract, new object[] { version }); string schemaid = project.GetSchemaIdentifier(); string assembly = "buildingSmart." + schemaid; string module = assembly + ".dll"; this.m_rootnamespace = assembly + "."; this.m_assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(assembly), AssemblyBuilderAccess.RunAndSave, new CustomAttributeBuilder[] { cabAssemblyVersion }); this.m_module = this.m_assembly.DefineDynamicModule(module, module); this.m_definitions = new Dictionary <string, DocObject>(); this.m_types = new Dictionary <string, Type>(); this.m_fields = new Dictionary <Type, Dictionary <string, FieldInfo> >(); this.m_templates = new Dictionary <DocTemplateDefinition, MethodInfo>(); this.m_namespaces = new Dictionary <string, string>(); Dictionary <DocObject, bool> included = null; if (this.m_views != null) { included = new Dictionary <DocObject, bool>(); foreach (DocModelView docView in this.m_views) { this.m_project.RegisterObjectsInScope(docView, included); } } if (psets) { foreach (DocPropertyEnumeration docPropEnum in project.PropertyEnumerations) { DocEnumeration docType = docPropEnum.ToEnumeration(); if (!this.m_definitions.ContainsKey(docType.Name)) { this.m_definitions.Add(docType.Name, docType); } } } foreach (DocSection docSection in project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocEntity docEntity in docSchema.Entities) { if (included == null || included.ContainsKey(docEntity)) { if (!this.m_definitions.ContainsKey(docEntity.Name)) { this.m_definitions.Add(docEntity.Name, docEntity); this.m_namespaces.Add(docEntity.Name, docSchema.Name); } } } foreach (DocType docType in docSchema.Types) { if (included == null || included.ContainsKey(docType)) { if (!this.m_definitions.ContainsKey(docType.Name)) { this.m_definitions.Add(docType.Name, docType); this.m_namespaces.Add(docType.Name, docSchema.Name); } } } } } // second pass: if (psets) { foreach (DocSection docSection in project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocPropertySet docPset in docSchema.PropertySets) { DocEntity docType = docPset.ToEntity(this.m_definitions); if (!this.m_definitions.ContainsKey(docType.Name)) { this.m_definitions.Add(docType.Name, docType); this.m_namespaces.Add(docType.Name, docSchema.Name); } } foreach (DocQuantitySet docQset in docSchema.QuantitySets) { DocEntity docType = docQset.ToEntity(this.m_definitions); if (!this.m_definitions.ContainsKey(docType.Name)) { this.m_definitions.Add(docType.Name, docType); this.m_namespaces.Add(docType.Name, docSchema.Name); } } } } } // first register types and fields foreach (string key in this.m_definitions.Keys) { Type typereg = RegisterType(key); // localization -- use custom attributes for now -- ideal way would be to use assembly resources, though has bugs in .net 4.0 if (typereg is TypeBuilder) { TypeBuilder tb = (TypeBuilder)typereg; DocObject docObj = this.m_definitions[key]; foreach (DocLocalization docLocal in docObj.Localization) { CustomAttributeBuilder cab = docLocal.ToCustomAttributeBuilder(); if (cab != null) { tb.SetCustomAttribute(cab); } } } } // now register template functions (may depend on fields existing) // find associated ConceptRoot for model view, define validation function if (this.m_views != null) { foreach (DocModelView view in this.m_views) { string viewname = view.Code; foreach (DocConceptRoot root in view.ConceptRoots) { Type tOpen = null; if (this.m_types.TryGetValue(root.ApplicableEntity.Name, out tOpen) && tOpen is TypeBuilder) { TypeBuilder tb = (TypeBuilder)tOpen; // new: generate type for concept root //if (view.Name != null && root.Name != null) { /* * string typename = this.m_rootnamespace + "." + view.Name.Replace(" ", "_") + "." + root.Name.Replace(" ", "_"); * //Type tbConceptRoot = RegisterType(typename); * TypeBuilder tbRoot = this.m_module.DefineType(typename, attr, typebase); */ // add typebuilder to map temporarily in case referenced by an attribute within same class or base class //this.m_types.Add(typename, tb); foreach (DocTemplateUsage concept in root.Concepts) { CompileConcept(concept, view, tb); } } } } } } //Dictionary<string, Stream> mapResStreams = new Dictionary<string, Stream>(); //Dictionary<string, ResXResourceWriter> mapResources = new Dictionary<string, ResXResourceWriter>(); // seal types once all are built List <TypeBuilder> listBase = new List <TypeBuilder>(); foreach (string key in this.m_definitions.Keys) { Type tOpen = this.m_types[key]; while (tOpen is TypeBuilder) { listBase.Add((TypeBuilder)tOpen); tOpen = tOpen.BaseType; } // seal in base class order for (int i = listBase.Count - 1; i >= 0; i--) { Type tClosed = listBase[i].CreateType(); this.m_types[tClosed.Name] = tClosed; } listBase.Clear(); // record bindings DocDefinition docDef = this.m_definitions[key] as DocDefinition; if (docDef != null) { docDef.RuntimeType = this.m_types[key]; if (docDef is DocEntity) { DocEntity docEnt = (DocEntity)docDef; foreach (DocAttribute docAttr in docEnt.Attributes) { docAttr.RuntimeField = docDef.RuntimeType.GetProperty(docAttr.Name); } } #if false // bug in .net framework 4.0+ -- can't read resources dynamically defined // capture localization foreach (DocLocalization docLocal in docDef.Localization) { if (!String.IsNullOrEmpty(docLocal.Locale)) { string major = docLocal.Locale.Substring(0, 2).ToLower(); ResXResourceWriter reswriter = null; if (!mapResources.TryGetValue(major, out reswriter)) { MemoryStream stream = new MemoryStream(); mapResStreams.Add(major, stream); reswriter = new ResXResourceWriter(stream); mapResources.Add(major, reswriter); } ResXDataNode node = new ResXDataNode(docDef.Name, docLocal.Name); node.Comment = docLocal.Documentation; reswriter.AddResource(node); } } #endif } } #if false foreach (string locale in mapResStreams.Keys) { ResXResourceWriter writer = mapResources[locale]; writer.Generate(); Stream stream = mapResStreams[locale]; stream.Seek(0, SeekOrigin.Begin); m_module.DefineManifestResource("Resources." + locale + ".resx", stream, ResourceAttributes.Public); } #endif }
public FormMerge(Dictionary <Guid, DocObject> mapOriginal, DocProject docChange) : this() { this.m_mapOriginal = mapOriginal; // add nodes for everything, then delete ones that haven't changed or don't have any children // iterate and find changes in documentation foreach (DocPropertyEnumeration docChangePset in docChange.PropertyEnumerations) { DocObject docOriginalPset = null; if (mapOriginal.TryGetValue(docChangePset.Uuid, out docOriginalPset)) { TreeNode tnPset = null; if (!String.Equals(docOriginalPset.Documentation, docChangePset.Documentation)) { tnPset = this.AddNode(null, new ChangeInfo(docOriginalPset.Name, docOriginalPset, docChangePset)); } foreach (DocPropertyConstant docChangeProp in docChangePset.Constants) { DocObject docOriginalProp = ((DocPropertyEnumeration)docOriginalPset).GetConstant(docChangeProp.Name); if (docOriginalProp != null) { TreeNode tnProperty = null; if (!String.Equals(docOriginalProp.Documentation, docChangeProp.Documentation)) { if (tnPset == null) { tnPset = this.AddNode(null, new ChangeInfo(docOriginalPset.Name, docOriginalPset, docChangePset)); } tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp)); } // localization foreach (DocLocalization docChangeLocal in docChangeProp.Localization) { DocLocalization docOriginalLocal = docOriginalProp.GetLocalization(docChangeLocal.Locale); if (docOriginalLocal != null) { if (!String.Equals(docOriginalLocal.Documentation, docChangeLocal.Documentation)) { if (tnPset == null) { tnPset = this.AddNode(null, new ChangeInfo(docOriginalPset.Name, docOriginalPset, docChangePset)); } if (tnProperty == null) { tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp)); } this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal)); } } else { if (tnPset == null) { tnPset = this.AddNode(null, new ChangeInfo(docOriginalPset.Name, docOriginalPset, docChangePset)); } if (tnProperty == null) { tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp)); } // new localization this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal)); } } } else { if (tnPset == null) { tnPset = this.AddNode(null, new ChangeInfo(docOriginalPset.Name, docOriginalPset, docChangePset)); } // NEW: this.AddNode(tnPset, new ChangeInfo(docChangePset.Name + "." + docChangeProp.Name, null, docChangeProp)); } } } else { // NEW: this.AddNode(null, new ChangeInfo(docChangePset.Name, null, docChangePset)); } } foreach (DocSection docChangeSection in docChange.Sections) { DocObject docOriginalSection = null; if (mapOriginal.TryGetValue(docChangeSection.Uuid, out docOriginalSection)) { foreach (DocSchema docChangeSchema in docChangeSection.Schemas) { DocObject docOriginalSchema; if (mapOriginal.TryGetValue(docChangeSchema.Uuid, out docOriginalSchema)) { // compare schemas TreeNode tnSchema = this.AddNode(null, new ChangeInfo(docOriginalSchema.Name, docOriginalSchema, docChangeSchema)); foreach (DocType docChangeType in docChangeSchema.Types) { DocObject docOriginalType = null; if (mapOriginal.TryGetValue(docChangeType.Uuid, out docOriginalType)) { TreeNode tnType = null; if (!String.Equals(docOriginalType.Documentation, docChangeType.Documentation)) { tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name, docOriginalType, docChangeType)); } if (docChangeType is DocEnumeration) { DocEnumeration docChangeEnum = (DocEnumeration)docChangeType; foreach (DocConstant docChangeConst in docChangeEnum.Constants) { DocObject docOriginalConst = null; if (mapOriginal.TryGetValue(docChangeConst.Uuid, out docOriginalConst)) { if (!String.Equals(docOriginalConst.Documentation, docChangeConst.Documentation)) { if (tnType == null) { tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name, docOriginalType, docChangeType)); } this.AddNode(tnType, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name + "." + docOriginalConst.Name, docOriginalConst, docChangeConst)); } } else { if (tnType == null) { tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name, docOriginalType, docChangeType)); } // NEW: this.AddNode(tnType, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name + "." + docOriginalConst.Name, null, docChangeConst)); } } } } } foreach (DocEntity docChangeEntity in docChangeSchema.Entities) { DocObject docOriginalObj = null; if (mapOriginal.TryGetValue(docChangeEntity.Uuid, out docOriginalObj)) { DocEntity docOriginalEntity = (DocEntity)docOriginalObj; TreeNode tnEntity = null; if (!String.Equals(docOriginalEntity.Documentation, docChangeEntity.Documentation)) { tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity)); } // add attributes foreach (DocAttribute docChangeAttr in docChangeEntity.Attributes) { DocObject docOriginalAttr = null; if (mapOriginal.TryGetValue(docChangeAttr.Uuid, out docOriginalAttr)) { if (!String.Equals(docOriginalAttr.Name, docChangeAttr.Name) || !String.Equals(docOriginalAttr.Documentation, docChangeAttr.Documentation)) { if (tnEntity == null) { tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity)); } this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalAttr.Name, docOriginalAttr, docChangeAttr)); } } else { if (tnEntity == null) { tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity)); } // new attribute this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docChangeAttr.Name, null, docChangeAttr)); } } // remove attributes foreach (DocAttribute docOriginalAttr in docOriginalEntity.Attributes) { bool bFound = false; foreach (DocAttribute docChangeAttr in docChangeEntity.Attributes) { if (docOriginalAttr.Uuid.Equals(docChangeAttr.Uuid)) { bFound = true; break; } } if (!bFound) { if (tnEntity == null) { tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity)); } // delete attribute this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalAttr.Name, docOriginalAttr, null)); } } foreach (DocWhereRule docChangeWhere in docChangeEntity.WhereRules) { DocObject docOriginalWhere = null; if (mapOriginal.TryGetValue(docChangeWhere.Uuid, out docOriginalWhere)) { DocWhereRule docOriginalWhereRule = (DocWhereRule)docOriginalWhere; if (!String.Equals(docOriginalWhere.Name, docChangeWhere.Name) || !String.Equals(docOriginalWhere.Documentation, docChangeWhere.Documentation) || !String.Equals(docOriginalWhereRule.Expression, docChangeWhere.Expression)) { if (tnEntity == null) { tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity)); } this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalWhere.Name, docOriginalWhere, docChangeWhere)); } } else { if (tnEntity == null) { tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity)); } // new where rule this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docChangeWhere.Name, null, docChangeWhere)); } } foreach (DocUniqueRule docChangeAttr in docChangeEntity.UniqueRules) { DocObject docOriginalAttr = null; if (mapOriginal.TryGetValue(docChangeAttr.Uuid, out docOriginalAttr)) { if (!String.Equals(docOriginalAttr.Documentation, docChangeAttr.Documentation)) { if (tnEntity == null) { tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity)); } this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalAttr.Name, docOriginalAttr, docChangeAttr)); } } } } } foreach (DocFunction docChangeFunction in docChangeSchema.Functions) { DocObject docOriginalFunc = null; if (mapOriginal.TryGetValue(docChangeFunction.Uuid, out docOriginalFunc)) { TreeNode tnType = null; DocFunction docOriginalFunction = (DocFunction)docOriginalFunc; if (!String.Equals(docOriginalFunction.Name, docChangeFunction.Name) || !String.Equals(docOriginalFunction.Documentation, docChangeFunction.Documentation) || !String.Equals(docOriginalFunction.Expression, docChangeFunction.Expression)) { tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalFunction.Name, docOriginalFunction, docChangeFunction)); } } else { // new attribute this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docChangeFunction.Name, null, docChangeFunction)); } } foreach (DocPropertySet docChangePset in docChangeSchema.PropertySets) { DocObject docOriginalPset = null; if (mapOriginal.TryGetValue(docChangePset.Uuid, out docOriginalPset)) { TreeNode tnPset = null; if (!String.Equals(docOriginalPset.Documentation, docChangePset.Documentation)) { tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } foreach (DocProperty docChangeProp in docChangePset.Properties) { DocObject docOriginalProp = ((DocPropertySet)docOriginalPset).GetProperty(docChangeProp.Name); if (docOriginalProp != null) { TreeNode tnProperty = null; if (!String.Equals(docOriginalProp.Documentation, docChangeProp.Documentation)) { if (tnPset == null) { tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp)); } // localization foreach (DocLocalization docChangeLocal in docChangeProp.Localization) { DocLocalization docOriginalLocal = docOriginalProp.GetLocalization(docChangeLocal.Locale); if (docOriginalLocal != null) { if (!String.Equals(docOriginalLocal.Documentation, docChangeLocal.Documentation)) { if (tnPset == null) { tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } if (tnProperty == null) { tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp)); } this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal)); } } else { if (tnPset == null) { tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } if (tnProperty == null) { tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp)); } // new localization this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal)); } } } else { if (tnPset == null) { tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } // NEW: this.AddNode(tnPset, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name + "." + docChangeProp.Name, null, docChangeProp)); } } } else { // NEW: this.AddNode(tnSchema, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name, null, docChangePset)); } } foreach (DocQuantitySet docChangePset in docChangeSchema.QuantitySets) { DocObject docOriginalPset = null; if (mapOriginal.TryGetValue(docChangePset.Uuid, out docOriginalPset)) { TreeNode tnQset = null; if (!String.Equals(docOriginalPset.Documentation, docChangePset.Documentation)) { tnQset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } foreach (DocQuantity docChangeProp in docChangePset.Quantities) { DocObject docOriginalProp = ((DocQuantitySet)docOriginalPset).GetQuantity(docChangeProp.Name); if (docOriginalProp != null) { if (!String.Equals(docOriginalProp.Documentation, docChangeProp.Documentation)) { if (tnQset == null) { tnQset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } this.AddNode(tnQset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp)); } } else { if (tnQset == null) { tnQset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } // NEW: this.AddNode(tnQset, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name + "." + docChangeProp.Name, null, docChangeProp)); } } } else { // NEW: this.AddNode(tnSchema, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name, null, docChangePset)); } } } } } } if (this.treeView.Nodes.Count > 0) { this.treeView.SelectedNode = this.treeView.Nodes[0]; } }
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; writer.WriteLine("\tpublic struct " + this.m_definition.Name); writer.WriteLine("\t{"); writer.WriteLine("\t\t" + docDefined.DefinedType + " Value;"); writer.WriteLine("\t}"); } else if (this.m_definition is DocSelect) { writer.WriteLine("\tpublic interface " + this.m_definition.Name); writer.WriteLine("\t{"); writer.WriteLine("\t}"); } else if (this.m_definition is DocEnumeration) { DocEnumeration docEnumumeration = (DocEnumeration)this.m_definition; writer.WriteLine("\tpublic enum " + this.m_definition.Name); writer.WriteLine("\t{"); int counter = 0; foreach (DocConstant docConstant in docEnumumeration.Constants) { counter++; int val = counter; if (docConstant.Name.Equals("NOTDEFINED")) { val = 0; } else if (docConstant.Name.Equals("USERDEFINED")) { val = -1; } writer.WriteLine("\t\t" + docConstant.Name + " = " + val + ","); } writer.WriteLine("\t}"); } else if (this.m_definition is DocEntity) { DocEntity docEntity = (DocEntity)this.m_definition; string basedef = docEntity.BaseDefinition; if (String.IsNullOrEmpty(basedef)) { basedef = "IfcBase"; } writer.WriteLine("\tpublic partial class " + this.m_definition.Name + " : " + basedef); writer.WriteLine("\t{"); // fields foreach (DocAttribute docAttribute in docEntity.Attributes) { switch (docAttribute.GetAggregation()) { case DocAggregationEnum.SET: writer.WriteLine("\t\tprivate ICollection<" + docAttribute.DefinedType + "> _" + docAttribute.Name + ";"); break; case DocAggregationEnum.LIST: writer.WriteLine("\t\tprivate IList<" + docAttribute.DefinedType + "> _" + docAttribute.Name + ";"); break; default: writer.WriteLine("\t\tprivate " + docAttribute.DefinedType + " _" + docAttribute.Name + ";"); break; } } // constructor writer.WriteLine(); writer.WriteLine("\t\tpublic " + docEntity.Name + "()"); writer.WriteLine("\t\t{"); //... values... writer.WriteLine("\t\t}"); // properties foreach (DocAttribute docAttribute in docEntity.Attributes) { writer.WriteLine(); switch (docAttribute.GetAggregation()) { case DocAggregationEnum.SET: writer.WriteLine("\t\tpublic ICollection<" + docAttribute.DefinedType + "> " + docAttribute.Name); break; case DocAggregationEnum.LIST: writer.WriteLine("\t\tpublic IList<" + docAttribute.DefinedType + "> " + docAttribute.Name); break; default: writer.WriteLine("\t\tpublic " + docAttribute.DefinedType + " " + docAttribute.Name); break; } writer.WriteLine("\t\t{"); writer.WriteLine("\t\t\tget"); writer.WriteLine("\t\t\t{"); writer.WriteLine("\t\t\t\treturn this._" + docAttribute.Name + ";"); writer.WriteLine("\t\t\t}"); if (docAttribute.GetAggregation() == DocAggregationEnum.NONE) { writer.WriteLine("\t\t\tset"); writer.WriteLine("\t\t\t{"); writer.WriteLine("\t\t\t\tthis.OnBeforePropertyChange(\"" + docAttribute.Name + "\");"); writer.WriteLine("\t\t\t\tthis._" + docAttribute.Name + " = value;"); writer.WriteLine("\t\t\t\tthis.OnAfterPropertyChange(\"" + docAttribute.Name + "\");"); writer.WriteLine("\t\t\t}"); } writer.WriteLine("\t\t}"); } // serialization writer.WriteLine(); writer.WriteLine("\t\tprivate void GetObjectData(SerializationInfo info, StreamingContext context)"); writer.WriteLine("\t\t{"); foreach (DocAttribute docAttribute in docEntity.Attributes) { if (docAttribute.Inverse == null && docAttribute.Derived == null) { writer.WriteLine("\t\t\tinfo.AddValue(\"" + docAttribute.Name + "\", this._" + docAttribute.Name + ");"); } } writer.WriteLine("\t\t}"); writer.WriteLine(); writer.WriteLine("\t\tprivate void SetObjectData(SerializationInfo info, StreamingContext context)"); writer.WriteLine("\t\t{"); foreach (DocAttribute docAttribute in docEntity.Attributes) { if (docAttribute.Inverse == null && docAttribute.Derived == null) { string method = "GetValue"; writer.WriteLine("\t\t\tthis._" + docAttribute.Name + " = info." + method + "(\"" + docAttribute.Name + "\");"); } } writer.WriteLine("\t\t}"); writer.WriteLine("\t}"); } 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>"); 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>"); 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: // record enum for later { string[] parts = docProperty.SecondaryDataType.Split(':'); if (parts.Length == 2) { string typename = parts[0]; if (!mapEnums.ContainsKey(typename)) { string[] enums = parts[1].Split(','); mapEnums.Add(typename, enums); 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(); } } } // 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("}"); } } }
public string FormatEnumeration(DocEnumeration docEnumeration) { return FormatEnumerationFull(docEnumeration, false); }
private void LoadUsage() { m_editcon = true; this.dataGridViewConceptRules.Rows.Clear(); this.dataGridViewConceptRules.Columns.Clear(); if (this.m_conceptroot == null) { return; } LoadInheritance(); List <DocTemplateItem> listItems = null; DocTemplateDefinition docTemplate = null; if (this.m_conceptleaf != null) { docTemplate = this.m_conceptleaf.Definition; if (docTemplate.Uuid == DocTemplateDefinition.guidTemplatePropertyBounded || docTemplate.Uuid == DocTemplateDefinition.guidTemplatePropertyEnumerated || docTemplate.Uuid == DocTemplateDefinition.guidTemplatePropertyList || docTemplate.Uuid == DocTemplateDefinition.guidTemplatePropertyReference || docTemplate.Uuid == DocTemplateDefinition.guidTemplatePropertySingle || docTemplate.Uuid == DocTemplateDefinition.guidTemplatePropertyTable) { listItems = new List <DocTemplateItem>(); foreach (DocTemplateUsage concept in ((DocTemplateItem)this.ConceptItem).Concepts) { if (concept.Items.Count != 0 && concept.Definition.Equals(docTemplate)) { listItems.Add(concept.Items[0]); } } } else { listItems = this.m_conceptleaf.Items; } } else { docTemplate = this.m_conceptroot.ApplicableTemplate; listItems = this.m_conceptroot.ApplicableItems; } // add usage column DataGridViewColumn colflag = new DataGridViewColumn(); colflag.HeaderText = "Usage"; DataGridViewComboBoxCell cellflag = new DataGridViewComboBoxCell(); colflag.CellTemplate = cellflag; colflag.Width = 80; cellflag.MaxDropDownItems = 32; cellflag.DropDownWidth = 80; cellflag.Items.Add("Key"); cellflag.Items.Add("Reference"); cellflag.Items.Add("Required"); cellflag.Items.Add("Optional"); cellflag.Items.Add("Calculated"); cellflag.Items.Add("System"); this.dataGridViewConceptRules.Columns.Add(colflag); if (docTemplate != null) { this.m_columns = docTemplate.GetParameterRules(); foreach (DocModelRule rule in this.m_columns) { DataGridViewColumn column = new DataGridViewColumn(); column.Tag = rule; column.HeaderText = rule.Identification; column.ValueType = typeof(string); //? column.CellTemplate = new DataGridViewTextBoxCell(); column.Width = 200; if (rule.IsCondition()) { column.HeaderText += "?"; } // override cell template for special cases DocConceptRoot docConceptRoot = (DocConceptRoot)this.m_conceptroot; DocEntity docEntity = this.m_project.GetDefinition(docTemplate.Type) as DocEntity; // docConceptRoot.ApplicableEntity; foreach (DocModelRuleAttribute docRule in docTemplate.Rules) { if (docEntity != null) { DocAttribute docAttribute = docEntity.ResolveParameterAttribute(docRule, rule.Identification, m_map); if (docAttribute == null && docConceptRoot.ApplicableEntity != null) { // try on type itself, e.g. PredefinedType docAttribute = docConceptRoot.ApplicableEntity.ResolveParameterAttribute(docRule, rule.Identification, m_map); } if (docAttribute != null) { DocObject docDef = null; if (this.m_map.TryGetValue(docAttribute.DefinedType, out docDef) && docDef is DocDefinition) { if (docDef is DocEnumeration) { DocEnumeration docEnum = (DocEnumeration)docDef; DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell(); cell.MaxDropDownItems = 32; cell.DropDownWidth = 200; // add blank item cell.Items.Add(String.Empty); foreach (DocConstant docConst in docEnum.Constants) { cell.Items.Add(docConst.Name); } column.CellTemplate = cell; } else if (docDef is DocEntity || docDef is DocSelect) { // button to launch dialog for picking entity DataGridViewButtonCell cell = new DataGridViewButtonCell(); cell.Tag = docDef; column.CellTemplate = cell; } } else if (docAttribute.DefinedType != null && (docAttribute.DefinedType.Equals("LOGICAL") || docAttribute.DefinedType.Equals("BOOLEAN"))) { DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell(); cell.MaxDropDownItems = 4; cell.DropDownWidth = 200; // add blank item cell.Items.Add(String.Empty); cell.Items.Add(Boolean.FalseString); cell.Items.Add(Boolean.TrueString); column.CellTemplate = cell; } } } } this.dataGridViewConceptRules.Columns.Add(column); } } // add description column DataGridViewColumn coldesc = new DataGridViewColumn(); coldesc.HeaderText = "Description"; coldesc.ValueType = typeof(string); //? coldesc.CellTemplate = new DataGridViewTextBoxCell(); coldesc.Width = 400; this.dataGridViewConceptRules.Columns.Add(coldesc); foreach (DocTemplateItem item in listItems) { string[] values = new string[this.dataGridViewConceptRules.Columns.Count]; values[0] = item.GetUsage(); if (this.m_columns != null) { for (int i = 0; i < this.m_columns.Length; i++) { string parmname = this.m_columns[i].Identification; string val = item.GetParameterValue(parmname); if (val != null) { values[i + 1] = val; } } } values[values.Length - 1] = item.Documentation; int row = this.dataGridViewConceptRules.Rows.Add(values); this.dataGridViewConceptRules.Rows[row].Tag = item; this.dataGridViewConceptRules.Rows[row].DefaultCellStyle.BackColor = item.GetColor(); } if (this.dataGridViewConceptRules.SelectedCells.Count > 0) { this.dataGridViewConceptRules.SelectedCells[0].Selected = false; } ToolStripButtonVisibility(); m_editcon = false; }
public string FormatEnumeration(DocEnumeration docEnumeration) { return(null); // nothing to define }
private void toolStripMenuItemInsertEnumeration_Click(object sender, EventArgs e) { TreeNode tnParent = this.treeView.SelectedNode; DocSchema docSchema = (DocSchema)tnParent.Tag; DocType docType = new DocEnumeration(); InitDefinition(docType); docSchema.Types.Add(docType); this.treeView.SelectedNode = this.LoadNode(tnParent.Nodes[0], docType, null, true); toolStripMenuItemEditRename_Click(this, e); }
/// <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); }
internal static void ImportXsdSimple(IfcDoc.Schema.XSD.simpleType simple, DocSchema docSchema, string name) { string thename = simple.name; if (simple.name == null) { thename = name; } if (simple.restriction != null && simple.restriction.enumeration.Count > 0) { DocEnumeration docEnum = new DocEnumeration(); docSchema.Types.Add(docEnum); docEnum.Name = thename; docEnum.Documentation = ImportXsdAnnotation(simple.annotation); foreach (IfcDoc.Schema.XSD.enumeration en in simple.restriction.enumeration) { DocConstant docConst = new DocConstant(); docConst.Name = en.value; docConst.Documentation = ImportXsdAnnotation(en.annotation); docEnum.Constants.Add(docConst); } } else { DocDefined docDef = new DocDefined(); docDef.Name = thename; docDef.Documentation = ImportXsdAnnotation(simple.annotation); if (simple.restriction != null) { docDef.DefinedType = ImportXsdType(simple.restriction.basetype); } docSchema.Types.Add(docDef); } }
private void LoadUsage() { m_editcon = true; this.dataGridViewConceptRules.Rows.Clear(); this.dataGridViewConceptRules.Columns.Clear(); if (this.m_conceptroot == null || this.m_conceptleaf == null)// || !this.m_conceptroot.Concepts.Contains(this.m_conceptleaf)) { return; } LoadInheritance(); DocTemplateUsage docUsage = (DocTemplateUsage)this.m_conceptleaf; if (docUsage.Definition != null) { this.m_columns = docUsage.Definition.GetParameterRules(); foreach (DocModelRule rule in this.m_columns) { DataGridViewColumn column = new DataGridViewColumn(); column.Tag = rule; column.HeaderText = rule.Identification; column.ValueType = typeof(string);//? column.CellTemplate = new DataGridViewTextBoxCell(); column.Width = 200; if (rule.IsCondition()) { column.HeaderText += "?"; } // override cell template for special cases DocConceptRoot docConceptRoot = (DocConceptRoot)this.m_conceptroot; DocEntity docEntity = this.m_project.GetDefinition(docUsage.Definition.Type) as DocEntity;// docConceptRoot.ApplicableEntity; foreach (DocModelRuleAttribute docRule in docUsage.Definition.Rules) { DocAttribute docAttribute = docEntity.ResolveParameterAttribute(docRule, rule.Identification, m_map); if (docAttribute != null) { DocObject docDef = null; if (this.m_map.TryGetValue(docAttribute.DefinedType, out docDef) && docDef is DocDefinition) { if (docDef is DocEnumeration) { DocEnumeration docEnum = (DocEnumeration)docDef; DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell(); cell.MaxDropDownItems = 32; cell.DropDownWidth = 200; // add blank item cell.Items.Add(String.Empty); foreach (DocConstant docConst in docEnum.Constants) { cell.Items.Add(docConst.Name); } column.CellTemplate = cell; } else if (docDef is DocEntity || docDef is DocSelect) { // button to launch dialog for picking entity DataGridViewButtonCell cell = new DataGridViewButtonCell(); cell.Tag = docDef; column.CellTemplate = cell; } } else if (docAttribute.DefinedType != null && (docAttribute.DefinedType.Equals("LOGICAL") || docAttribute.DefinedType.Equals("BOOLEAN"))) { DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell(); cell.MaxDropDownItems = 4; cell.DropDownWidth = 200; // add blank item cell.Items.Add(String.Empty); cell.Items.Add(Boolean.FalseString); cell.Items.Add(Boolean.TrueString); column.CellTemplate = cell; } } } this.dataGridViewConceptRules.Columns.Add(column); } } // add description column DataGridViewColumn coldesc = new DataGridViewColumn(); coldesc.HeaderText = "Description"; coldesc.ValueType = typeof(string);//? coldesc.CellTemplate = new DataGridViewTextBoxCell(); coldesc.Width = 400; this.dataGridViewConceptRules.Columns.Add(coldesc); foreach (DocTemplateItem item in docUsage.Items) { string[] values = new string[this.dataGridViewConceptRules.Columns.Count]; if (this.m_columns != null) { for (int i = 0; i < this.m_columns.Length; i++) { string parmname = this.m_columns[i].Identification; string val = item.GetParameterValue(parmname); if (val != null) { values[i] = val; } } } values[values.Length - 1] = item.Documentation; int row = this.dataGridViewConceptRules.Rows.Add(values); this.dataGridViewConceptRules.Rows[row].Tag = item; if (item.Optional) { this.dataGridViewConceptRules.Rows[row].DefaultCellStyle.ForeColor = Color.Gray; } } if (this.dataGridViewConceptRules.SelectedCells.Count > 0) { this.dataGridViewConceptRules.SelectedCells[0].Selected = false; } m_editcon = false; }
public string FormatEnumeration(DocEnumeration docEnumeration, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included) { return(null); // nothing to define }