// INSTANCE methods public SEntity() { if (SEntity.EntityCreated != null) { SEntity.EntityCreated(this, EventArgs.Empty); } }
public override void Delete() { if (SEntity.EntityDeleted != null) { SEntity.EntityDeleted(this, EventArgs.Empty); } // call base AFTER event notification such that OID remains while removing from list base.Delete(); }
public string FormatData(DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary<string, DocObject> map, Dictionary<long, SEntity> instances, SEntity root, bool markup) { this.m_stream = new System.IO.MemoryStream(); this.Instance = root; this.Markup = markup; this.Save(); this.m_stream.Position = 0; StreamReader reader = new StreamReader(this.m_stream); string content = reader.ReadToEnd(); return content; }
public static FieldInfo GetFieldByName(Type type, string name) { IList <FieldInfo> fields = SEntity.GetFieldsOrdered(type); foreach (FieldInfo field in fields) { if (field.Name.Equals(name)) { return(field); } } return(null); }
/// <summary> /// Marks object as in-use (setting Exists to True) such that any unmarked objects may then be garbage collected. /// </summary> public void Mark() { if (this.Existing) { return; } this.Existing = true; Type t = this.GetType(); IList <FieldInfo> listFields = SEntity.GetFieldsOrdered(t); foreach (FieldInfo field in listFields) { if (typeof(SEntity).IsAssignableFrom(field.FieldType)) { SEntity obj = field.GetValue(this) as SEntity; if (obj != null) { obj.Mark(); } } else if (field.FieldType.IsGenericType && field.FieldType.GetGenericTypeDefinition() == typeof(List <>) && typeof(SEntity).IsAssignableFrom(field.FieldType.GetGenericArguments()[0])) { System.Collections.IList list = (System.Collections.IList)field.GetValue(this) as System.Collections.IList; if (list != null) { foreach (object obj in list) { if (obj is SEntity) { SEntity ent = (SEntity)obj; ent.Mark(); } } } } } }
private static void GenerateExample( DocPublication docPublication, DocExample docExample, List<DocXsdFormat> listFormats, string path, List<int> indexpath, Dictionary<DocObject, bool> included, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema, Dictionary<string, Type> typemap, List<ContentRef> listFigures, List<ContentRef> listTables, FormatHTM htmTOC, FormatHTM htmSectionTOC, Dictionary<DocFormatSchemaEnum, IFormatData> mapFormats, Dictionary<long, SEntity> outerinstancemap, // instance data of parent example, if inherited SEntity outerinstanceroot ) { if (included == null || included.ContainsKey(docExample)) { indexpath[indexpath.Count - 1]++; StringBuilder indexpathname = new StringBuilder(); indexpathname.Append("E"); foreach(int x in indexpath) { indexpathname.Append("."); indexpathname.Append(x); } string indexpathstring = indexpathname.ToString(); string pathExample = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".htm"; using (FormatHTM htmExample = new FormatHTM(pathExample, mapEntity, mapSchema, included)) { htmExample.WriteHeader(docExample.Name, 2, docPublication.Header); htmExample.WriteScript(-5, indexpath[0], 0, 0); htmExample.WriteLine("<h3 class=\"std\">" + indexpathstring + " " + docExample.Name + "</h3>"); // table of files if (docExample.File != null) { htmExample.Write("<table class=\"gridtable\">"); htmExample.Write("<tr><th>Format</th><th>ASCII</th><th>HTML</th></tr>"); foreach(DocFormat docFormat in docPublication.Formats) { if (docFormat.FormatOptions == DocFormatOptionEnum.Examples) { string ext = docFormat.ExtensionInstances; htmExample.WriteLine("<tr><td>" + docFormat.FormatType.ToString() + "</td><td><a href=\"" + MakeLinkName(docExample) + "." + ext + "\">File</a></td><td><a href=\"" + MakeLinkName(docExample) + "." + ext + ".htm\">Markup</a></td></tr>"); } } htmExample.Write("</table>"); htmExample.Write("<table class=\"gridtable\">"); htmExample.Write("<tr><th>View</th></tr>"); foreach (DocModelView docView in docExample.Views) { if (included != null && included.ContainsKey(docView)) { string hyperlink = "../../schema/views/" + MakeLinkName(docView) + "/index.htm"; htmExample.Write("<tr><td><a href=\"" + hyperlink + "\">" + docView.Name + "</td></tr>"); } } htmExample.Write("</table>"); if (docExample.ApplicableType != null) { string[] ApplicableTypesArray = docExample.ApplicableType.Split(','); htmExample.Write("<table class=\"gridtable\">"); htmExample.Write("<tr><th>Entity</th></tr>"); for (int i = 0; i < ApplicableTypesArray.Length; i++) { string hyperlink = "../../schema/" + mapSchema[ApplicableTypesArray.GetValue(i).ToString()].ToString().ToLower() + "/lexical/" + ApplicableTypesArray.GetValue(i).ToString().ToLower() + ".htm"; htmExample.Write("<tr><td><a href=" + hyperlink + ">" + ApplicableTypesArray.GetValue(i) + "</td></tr>"); } htmExample.Write("</table>"); } } docExample.Documentation = UpdateNumbering(docExample.Documentation, listFigures, listTables, docExample); htmExample.WriteDocumentationMarkup(docExample.Documentation, docExample, docPublication); if (docExample.File == null && outerinstancemap != null) { // if specific to exchange, capture inline if (docExample.Views.Count > 0) { // hack for now based on example name matching exchange name -- make explicit later foreach (DocExchangeDefinition docExchange in docExample.Views[0].Exchanges) { if (docExample.Name.Equals(docExchange.Name)) { // matches -- generate FormatSQL fmt = new FormatSQL(); string content = fmt.FormatData(docPublication, docExchange, mapEntity, outerinstancemap, outerinstanceroot, false); htmExample.Write(content); break; } } } } htmExample.WriteLinkTo(docExample); htmExample.WriteFooter(docPublication.Footer); } if (docExample.File != null && !Properties.Settings.Default.SkipDiagrams) { string pathIFC = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ifc"; using (System.IO.FileStream filestream = new System.IO.FileStream(pathIFC, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read)) { filestream.Write(docExample.File, 0, docExample.File.Length); } using (FormatSPF spfExample = new FormatSPF(new System.IO.MemoryStream(docExample.File, false), typemap, null)) { string pathListing = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ifc.htm"; if (docPublication.GetFormatOption(DocFormatSchemaEnum.STEP) == DocFormatOptionEnum.Examples)//Properties.Settings.Default.ExampleSPF) { using (FormatHTM htmListing = new FormatHTM(pathListing, mapEntity, mapSchema, included)) { htmListing.WriteHeader(docExample.Name, 2, docPublication.Header); htmListing.WriteLine("<tt class=\"spf\">"); string htm = null; try { htm = spfExample.LoadMarkup(); outerinstancemap = spfExample.Instances; } catch { } htmListing.Write(htm); htmListing.Write("</tt>"); htmListing.WriteFooter(String.Empty); } } #if false else if(Properties.Settings.Default.ExampleXML) { // must load file in any case in order to generate xml try { spfExample.Load(); } catch { } } #endif // find the IfcProject SEntity rootproject = null; foreach (SEntity ent in spfExample.Instances.Values) { if (ent.GetType().Name.Equals("IfcProject")) { rootproject = ent; break; } } foreach (DocFormat docFormat in docPublication.Formats) { // generate example in other formats... if (docFormat.FormatOptions == DocFormatOptionEnum.Examples) { switch(docFormat.FormatType) { case DocFormatSchemaEnum.STEP: break; // do nothing #if false case DocFormatSchemaEnum.XML: // TODO: use generic formatter { // use xml namespace of first view string xmlns = "http://www.buildingsmart-tech.org/ifcXML/IFC4/final"; if (docExample.Views.Count > 0 && !String.IsNullOrEmpty(docExample.Views[0].XsdUri)) { xmlns = docExample.Views[0].XsdUri; } string pathXML = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ifcxml"; using (FormatSML xmlExample = new FormatSML(new System.IO.FileStream(pathXML, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite), listFormats, xmlns, docPublication.Code)) { xmlExample.Instance = rootproject; xmlExample.Save(); } string pathXMH = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ifcxml.htm"; using (FormatSML xmlExample = new FormatSML(new System.IO.FileStream(pathXMH, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite), listFormats, xmlns, docPublication.Code)) { xmlExample.Instance = rootproject; xmlExample.Markup = true; xmlExample.Save(); } } break; #endif // now use generic formatters case DocFormatSchemaEnum.TTL: { string ns = "http://ifcowl.openbimstandards.org/IFC4_ADD1#"; string pathTTL = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ttl"; Console.Out.WriteLine("------------------------------------------------"); Console.Out.WriteLine("converting file: " + MakeLinkName(docExample) + ".ttl"); Console.Out.WriteLine("------------------------------------------------"); using (FormatTTL_Stream TTLExample = new FormatTTL_Stream(new System.IO.FileStream(pathTTL, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite), ns)) { TTLExample.Instances = spfExample.Instances; TTLExample.Save(); } //TODO: redo the HTM part later on //string pathTTLHTM = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ttl.htm"; //using (FormatTTL_Stream TTLExample = new FormatTTL_Stream(new System.IO.FileStream(pathTTLHTM, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite), ns)) //{ // TTLExample.Instances = spfExample.Instances; // TTLExample.Markup = true; // TTLExample.Save(); //} } break; #if false case DocFormatTypeEnum.SQL: // todo: support others... // use formatter { FormatSQL fmt = new FormatSQL(); string content = fmt.FormatData(docPublication, null, mapEntity, spfExample.Instances); string pathRAW = path + @"\annex\annex-e\" + MakeLinkName(docExample) + "." + docFormat.ExtensionInstances; using (System.IO.StreamWriter writer = new System.IO.StreamWriter(pathRAW, false)) { writer.Write(content); } string pathHTM = pathRAW + ".htm"; using (FormatHTM fmtHTM = new FormatHTM(pathHTM, mapEntity, mapSchema, included)) { fmtHTM.WriteHeader(docExample.Name, 2, docPublication.Header); fmtHTM.Write(content); fmtHTM.WriteFooter(""); } } break; #endif default: // pluggable formatters { IFormatData formatext = null; if(mapFormats.TryGetValue(docFormat.FormatType, out formatext)) { string content = formatext.FormatData(docPublication, null, mapEntity, spfExample.Instances, rootproject, false); string pathRAW = path + @"\annex\annex-e\" + MakeLinkName(docExample) + "." + docFormat.ExtensionInstances; using (System.IO.StreamWriter writer = new System.IO.StreamWriter(pathRAW, false)) { writer.Write(content); } string conmark = formatext.FormatData(docPublication, null, mapEntity, spfExample.Instances, rootproject, true); string pathHTM = pathRAW + ".htm"; using (FormatHTM fmtHTM = new FormatHTM(pathHTM, mapEntity, mapSchema, included)) { fmtHTM.WriteHeader(docExample.Name, 2, docPublication.Header); fmtHTM.Write(conmark); fmtHTM.WriteFooter(""); } } } break; } } } } } using (FormatHTM htmLink = new FormatHTM(path + "/link/" + MakeLinkName(docExample) + ".htm", mapEntity, mapSchema, included)) { string linkurl = "../annex/annex-e/" + MakeLinkName(docExample) + ".htm"; htmLink.WriteLinkPage(linkurl, docPublication); } string urlExample = "annex-e/" + MakeLinkName(docExample) + ".htm"; htmTOC.WriteTOC(2, "<a class=\"listing-link\" href=\"annex/" + urlExample + "\" >" + indexpathstring + " " + docExample.Name + "</a>"); string linkid = ""; if(indexpath.Count == 1) { linkid = indexpath[0].ToString(); } string htmllink = "<a class=\"listing-link\" id=\"" + linkid + "\" href=\"" + urlExample + "\" target=\"info\">" + docExample.Name + "</a>"; htmSectionTOC.WriteLine("<tr class=\"std\"><td class=\"menu\">" + indexpathstring + " " + htmllink + "</td></tr>"); if (docExample.Examples.Count > 0) { indexpath.Add(0); foreach(DocExample docSub in docExample.Examples) { GenerateExample(docPublication, docSub, listFormats, path, indexpath, included, mapEntity, mapSchema, typemap, listFigures, listTables, htmTOC, htmSectionTOC, mapFormats, outerinstancemap, outerinstanceroot); } indexpath.RemoveAt(indexpath.Count - 1); } } }
private void WriteEntity(SEntity o) { // sanity check if (this.m_indent > 100) { return; } if (o == null) return; Type t = o.GetType(); string hyperlink = "../../schema/" + t.Namespace.ToLower() + "/lexical/" + t.Name.ToLower() + ".htm"; this.WriteStartElementEntity(t.Name, hyperlink); bool close = this.WriteEntityAttributes(o); if (close) { this.WriteEndElementEntity(t.Name); } else { this.WriteCloseElementEntity(); } }
private SEntity _OwnerHistory; // IfcOwnerHistory : exclude #endregion Fields #region Constructors public IfcRoot() { this._GlobalId = SGuid.New().ToString(); this._OwnerHistory = null; }
/// <summary> /// Creates an instance diagram for a template. /// </summary> /// <param name="docTemplate"></param> /// <returns></returns> internal static Image CreateTemplateDiagram(DocTemplateDefinition docTemplate, Dictionary<string, DocObject> map, Dictionary<Rectangle, DocModelRule> layout, DocProject docProject, SEntity instance) { DocObject docTarget = null; if (docTemplate.Type == null || !map.TryGetValue(docTemplate.Type, out docTarget) || !(docTarget is DocEntity)) return null; DocEntity docEntity = (DocEntity)docTarget; DocSchema docSchema = docProject.GetSchemaOfDefinition(docEntity); // first, determine bounds of drawing List<int> lanes = new List<int>(); // keep track of position offsets in each lane for (int i = 0; i < 16; i++) { lanes.Add(0); } layout.Clear(); DrawEntity(null, 0, lanes, docEntity, null, docTemplate, null, map, layout, docProject, docSchema, instance); Rectangle rcBounds = new Rectangle(); foreach(Rectangle rc in layout.Keys) { if(rc.Right > rcBounds.Right) { rcBounds.Width = rc.Right; } if(rc.Bottom > rcBounds.Bottom) { rcBounds.Height = rc.Bottom; } } rcBounds.Width += FormatPNG.Border; rcBounds.Height += FormatPNG.Border; Image image = new Bitmap(rcBounds.Width, rcBounds.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); using (Graphics g = Graphics.FromImage(image)) { g.FillRectangle(Brushes.White, new Rectangle(0, 0, image.Width, image.Height)); lanes = new List<int>(); // keep track of position offsets in each lane for (int i = 0; i < 16; i++) { lanes.Add(0); } layout.Clear(); DrawEntity(g, 0, lanes, docEntity, null, docTemplate, null, map, layout, docProject, docSchema, instance); g.DrawRectangle(Pens.Black, 0, 0, rcBounds.Width - 1, rcBounds.Height - 1); } return image; }
/// <summary> /// Gets value referenced by path. /// </summary> /// <param name="target">The relative object to retrieve the value.</param> /// <param name="parameters">Optional parameters for substitution.</param> /// <returns>The value on the object along the expression path.</returns> public object GetValue(SEntity target, Dictionary<string, SEntity> parameters) { if (target == null) throw new ArgumentNullException("target"); if (this.m_type == null) { return target.GetType(); } if (!this.m_type.IsInstanceOfType(target)) return null; // doesn't apply if (this.m_property == null) { return target; // for general case, if no attribute specified, then return object itself //return target.GetType(); // need some way to extract type directly such as for COBie } object value = null; if (this.m_property.PropertyType.IsGenericType && typeof(System.Collections.IList).IsAssignableFrom(this.m_property.PropertyType) && (typeof(SEntity).IsAssignableFrom(this.m_property.PropertyType.GetGenericArguments()[0]) || this.m_property.PropertyType.GetGenericArguments()[0].IsInterface)) { System.Collections.IList list = (System.Collections.IList)this.m_property.GetValue(target, null); // if expecting array, then return it. //if (this.m_vector) if (this.m_vector || (this.m_identifier == null && this.m_inner == null)) // 2014-01-20: RICS export of door schedules to show quantity { return list; } else if (this.m_identifier != null && this.m_identifier.StartsWith("@") && parameters == null) { // return filtered list based on expected type -- may be none if no compatible types -- e.g. COBie properties only return IfcPropertyEnumeratedValue if (this.InnerPath != null && this.InnerPath.Type != null) { List<SEntity> listFilter = null; foreach (SEntity ent in list) { if (this.InnerPath.Type.IsInstanceOfType(ent)) { if (listFilter == null) { listFilter = new List<SEntity>(); } listFilter.Add(ent); } } return listFilter; } else { return list; } } if (list != null) { foreach (object eachelem in list) { // derived class may have its own specific property (e.g. IfcSIUnit, IfcConversionBasedUnit) if (this.m_identifier != null) { Type eachtype = eachelem.GetType(); DefaultPropertyAttribute[] attrs = (DefaultPropertyAttribute[])eachtype.GetCustomAttributes(typeof(DefaultPropertyAttribute), true); PropertyInfo propElem = null; if (attrs.Length > 0) { propElem = eachtype.GetProperty(attrs[0].Name); } else { propElem = eachtype.GetProperty("Name"); } if (propElem != null) { object eachname = propElem.GetValue(eachelem, null); // IStepValueString, or Enum (e.g. IfcNamedUnit.UnitType) #if false // special case for properties/quantities if (eachname == null && eachelem is IfcRelDefinesByProperties) { IfcRelDefinesByProperties rdp = (IfcRelDefinesByProperties)eachelem; eachname = rdp.RelatingPropertyDefinition.Name.GetValueOrDefault().Value; } #endif if (eachname != null) { if (this.m_identifier.StartsWith("@")) { // parameterized query -- substitute parameter if (parameters != null) { SEntity specelem = null; if (parameters.TryGetValue(this.m_identifier.Substring(1), out specelem)) { if (this.m_inner != null) { object eachvalue = this.m_inner.GetValue(specelem, parameters); return eachvalue; // return no matter what, since specific element was requested. } else { return specelem; } } } else { return null; // no parameters specified, so can't resolve value. } } else if (this.m_identifier.Equals(eachname.ToString())) { if (this.m_inner != null) { // yes -- drill in object eachvalue = this.m_inner.GetValue((SEntity)eachelem, parameters); if (eachvalue != null) { return eachvalue; // if no value, keep going until compatible match is found } } else { return eachelem; } } } } } else if (this.m_inner != null) { object eachvalue = this.m_inner.GetValue((SEntity)eachelem, parameters); if (eachvalue != null) { return eachvalue; } } else { return eachelem; } } } } else if (this.m_inner != null) { value = this.m_property.GetValue(target, null); if (value is SEntity) { value = this.m_inner.GetValue((SEntity)value, parameters); if (this.m_identifier != null && value != null) { // qualify the value Type eachtype = value.GetType(); DefaultMemberAttribute[] attrs = (DefaultMemberAttribute[])eachtype.GetCustomAttributes(typeof(DefaultMemberAttribute), true); PropertyInfo propElem = null; if (attrs.Length > 0) { propElem = eachtype.GetProperty(attrs[0].MemberName); } else { propElem = eachtype.GetProperty("Name"); } if (propElem != null) { object name = propElem.GetValue(value, null); if (name == null || !this.m_identifier.Equals(name.ToString())) { return null; } } } } } else { value = this.m_property.GetValue(target, null); } return value; }
private void WriteAttribute(SEntity o, FieldInfo f) { object v = f.GetValue(o); if (v == null) return; this.WriteStartElement(f.Name, null); this.WriteOpenElement(); Type ft = f.FieldType; if (typeof(System.Collections.ICollection).IsAssignableFrom(ft)) { System.Collections.IList list = (System.Collections.IList)v; for (int i = 0; i < list.Count; i++) { object e = list[i]; if (e is SEntity) { this.WriteEntity((SEntity)e); //...WriteReference(writer, (SEntity)e); } else if(e is System.Collections.IList) { System.Collections.IList listInner = (System.Collections.IList)e; for (int j = 0; j < listInner.Count; j++) { object oi = listInner[j]; Type et = oi.GetType(); while (et.IsValueType && !et.IsPrimitive) { FieldInfo fieldValue = et.GetField("Value"); if (fieldValue != null) { oi = fieldValue.GetValue(oi); et = fieldValue.FieldType; } else { break; } } // write each value in sequence with spaces delimiting string sval = oi.ToString(); this.m_writer.Write(sval); this.m_writer.Write(" "); } } else { Type et = e.GetType(); while (et.IsValueType && !et.IsPrimitive) { FieldInfo fieldValue = et.GetField("Value"); if (fieldValue != null) { e = fieldValue.GetValue(e); et = fieldValue.FieldType; } else { break; } } // write each value in sequence with spaces delimiting string sval = e.ToString(); this.m_writer.Write(sval); this.m_writer.Write(" "); } } } else if (v is SEntity) { // if rooted, then check if we need to use reference; otherwise embed this.WriteEntity((SEntity)v); //this.WriteReference(writer, (SEntity)v); } else { // qualified value type this.WriteValue(v); } WriteEndElement(f.Name); }
/// <summary> /// Returns true if any elements written (requiring closing tag); or false if not /// </summary> /// <param name="o"></param> /// <returns></returns> private bool WriteEntityAttributes(SEntity o) { Type t = o.GetType(); long oid = 0; if (this.m_saved.Contains(o)) { // give it an ID if needed (first pass) if (!this.m_idmap.TryGetValue(o, out oid)) { this.m_nextID++; this.m_idmap[o] = this.m_nextID; } // reference existing; return this.WriteReference(oid); return false; } // mark as saved this.m_saved.Add(o); if (this.m_idmap.TryGetValue(o, out oid)) { this.WriteIdentifier(oid); } bool previousattribute = false; // write fields as attributes bool haselements = false; IList<FieldInfo> fields = SEntity.GetFieldsAll(t); foreach (FieldInfo f in fields) { DocXsdFormat xsdformat = this.GetXsdFormat(f); if (f.IsDefined(typeof(DataMemberAttribute)) && (xsdformat == null || (xsdformat.XsdFormat != DocXsdFormatEnum.Element && xsdformat.XsdFormat != DocXsdFormatEnum.Attribute))) { // direct field Type ft = f.FieldType; bool isvaluelist = (ft.IsGenericType && ft.GetGenericTypeDefinition() == typeof(List<>) && ft.GetGenericArguments()[0].IsValueType); bool isvaluelistlist = (ft.IsGenericType && // e.g. IfcTriangulatedFaceSet.Normals ft.GetGenericTypeDefinition() == typeof(List<>) && ft.GetGenericArguments()[0].IsGenericType && ft.GetGenericArguments()[0].GetGenericTypeDefinition() == typeof(List<>) && ft.GetGenericArguments()[0].GetGenericArguments()[0].IsValueType); if (isvaluelistlist || isvaluelist || ft.IsValueType) { object v = f.GetValue(o); if (v != null) { if (previousattribute) { this.WriteAttributeDelimiter(); } previousattribute = true; this.WriteStartAttribute(f.Name); if (isvaluelistlist) { ft = ft.GetGenericArguments()[0].GetGenericArguments()[0]; FieldInfo fieldValue = ft.GetField("Value"); System.Collections.IList list = (System.Collections.IList)v; for (int i = 0; i < list.Count; i++) { System.Collections.IList listInner = (System.Collections.IList)list[i]; for (int j = 0; j < listInner.Count; j++) { if (i > 0 || j > 0) { this.m_writer.Write(" "); } object elem = listInner[j]; if (elem != null) // should never be null, but be safe { elem = fieldValue.GetValue(elem); string encodedvalue = System.Security.SecurityElement.Escape(elem.ToString()); this.m_writer.Write(encodedvalue); } } } } else if (isvaluelist) { ft = ft.GetGenericArguments()[0]; FieldInfo fieldValue = ft.GetField("Value"); System.Collections.IList list = (System.Collections.IList)v; for (int i = 0; i < list.Count; i++) { if (i > 0) { this.m_writer.Write(" "); } object elem = list[i]; if (elem != null) // should never be null, but be safe { elem = fieldValue.GetValue(elem); if (elem is byte[]) { // IfcPixelTexture.Pixels byte[] bytes = (byte[])elem; char[] s_hexchar = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; StringBuilder sb = new StringBuilder(bytes.Length * 2); for (int z = 0; z < bytes.Length; z++) { byte b = bytes[z]; sb.Append(s_hexchar[b / 0x10]); sb.Append(s_hexchar[b % 0x10]); } v = sb.ToString(); this.m_writer.Write(v); } else { string encodedvalue = System.Security.SecurityElement.Escape(elem.ToString()); this.m_writer.Write(encodedvalue); } } } } else { if (ft.IsGenericType && ft.GetGenericTypeDefinition() == typeof(Nullable<>)) { // special case for Nullable types ft = ft.GetGenericArguments()[0]; } Type typewrap = null; while (ft.IsValueType && !ft.IsPrimitive) { FieldInfo fieldValue = ft.GetField("Value"); if (fieldValue != null) { v = fieldValue.GetValue(v); if (typewrap == null) { typewrap = ft; } ft = fieldValue.FieldType; } else { break; } } if (ft.IsEnum || ft == typeof(bool)) { v = v.ToString().ToLowerInvariant(); } if (v is System.Collections.IList) { // IfcCompoundPlaneAngleMeasure System.Collections.IList list = (System.Collections.IList)v; for (int i = 0; i < list.Count; i++) { if (i > 0) { this.m_writer.Write(" "); } object elem = list[i]; if (elem != null) // should never be null, but be safe { string encodedvalue = System.Security.SecurityElement.Escape(elem.ToString()); this.m_writer.Write(encodedvalue); } } } else if (v != null) { string encodedvalue = System.Security.SecurityElement.Escape(v.ToString()); m_writer.Write(encodedvalue); //... escape it } } this.WriteEndAttribute(); } } else { haselements = true; } } else { // inverse haselements = true; } } if (haselements) { bool open = false; // write direct object references and lists foreach (FieldInfo f in fields) { DocXsdFormat format = GetXsdFormat(f); if (f.IsDefined(typeof(DataMemberAttribute)) && (format == null || (format.XsdFormat != DocXsdFormatEnum.Element && format.XsdFormat != DocXsdFormatEnum.Attribute))) { Type ft = f.FieldType; bool isvaluelist = (ft.IsGenericType && ft.GetGenericTypeDefinition() == typeof(List<>) && ft.GetGenericArguments()[0].IsValueType); bool isvaluelistlist = (ft.IsGenericType && // e.g. IfcTriangulatedFaceSet.Normals ft.GetGenericTypeDefinition() == typeof(List<>) && ft.GetGenericArguments()[0].IsGenericType && ft.GetGenericArguments()[0].GetGenericTypeDefinition() == typeof(List<>) && ft.GetGenericArguments()[0].GetGenericArguments()[0].IsValueType); // hide fields where inverse attribute used instead if (!f.FieldType.IsValueType && !isvaluelist && !isvaluelistlist && (format == null || (format.XsdFormat != DocXsdFormatEnum.Hidden))) { object value = f.GetValue(o); if (value != null) { if (!open) { WriteOpenElement(); open = true; } if (previousattribute) { this.WriteAttributeDelimiter(); } previousattribute = true; WriteAttribute(o, f, format); } } } else if (format != null && (format.XsdFormat == DocXsdFormatEnum.Element || format.XsdFormat == DocXsdFormatEnum.Attribute)) { object value = f.GetValue(o); if (value != null) { if (!open) { WriteOpenElement(); open = true; } if (previousattribute) { this.WriteAttributeDelimiter(); } previousattribute = true; WriteAttribute(o, f, format); } } else { object value = f.GetValue(o); // inverse // record it for downstream serialization if (value is System.Collections.IList) { System.Collections.IList invlist = (System.Collections.IList)value; foreach (SEntity invobj in invlist) { if (!this.m_saved.Contains(invobj)) { this.m_queue.Enqueue(invobj); } } } } } this.WriteAttributeTerminator(); return open; } else { this.WriteAttributeTerminator(); return false; } }
/// <summary> /// </summary> /// <param name="o"></param> /// <returns></returns> private void WriteEntityAttributes(SEntity o) { Type t = o.GetType(); if (t.Name.Equals("IfcPixelTexture")) { this.ToString(); } IList<FieldInfo> fields = SEntity.GetFieldsAll(t); foreach (FieldInfo f in fields) { if (f.IsDefined(typeof(DataMemberAttribute))) { // write data type properties Type ft = f.FieldType; Console.Out.WriteLine("\r\n++ writing attribute: " + ft.Name); bool isvaluelist = (ft.IsGenericType && ft.GetGenericTypeDefinition() == typeof(List<>) && ft.GetGenericArguments()[0].IsValueType); bool isvaluelistlist = (ft.IsGenericType && // e.g. IfcTriangulatedFaceSet.Normals ft.GetGenericTypeDefinition() == typeof(List<>) && ft.GetGenericArguments()[0].IsGenericType && ft.GetGenericArguments()[0].GetGenericTypeDefinition() == typeof(List<>) && ft.GetGenericArguments()[0].GetGenericArguments()[0].IsValueType); if (isvaluelistlist || isvaluelist || ft.IsValueType) { //Console.Out.WriteLine("WriteDataValueAttribute()"); object v = f.GetValue(o); if (v != null) { m_writer.Write(";" + "\r\n"); //m_writer.Write(" "); WriteIndent(); ObjectProperty p = GetObjectProperty(f.Name + "_" + t.Name); if (p == null) Console.Out.WriteLine("Warning: objectproperty not found : " + f.Name + "_" + t.Name); m_writer.Write("ifcowl:" + p.name + " "); if (isvaluelistlist) { System.Collections.IList list = (System.Collections.IList)v; WriteListOfListWithValues(ft, list); } else if (isvaluelist) { System.Collections.IList list = (System.Collections.IList)v; WriteListWithValues(ft, list); } else { WriteTypeValue(ft,v); } } else { //Console.Out.WriteLine("Empty value: skipping"); } } else { //Console.Out.WriteLine("WriteObjectPropertyAttribute()"); //Writing object properties ObjectProperty p = GetObjectProperty(f.Name + "_" + o.GetType().Name); if (p == null) Console.Out.WriteLine("Warning: objectproperty not found : " + f.Name + "_" + o.GetType().Name); //Writing output object v = f.GetValue(o); if (v != null) { if (v.GetType() == typeof(SEntity)) { //WriteAttribute(o, f, owlClass); //m_writer.Write(owlClass + "_" + ((SEntity)value).OID); Console.Out.WriteLine("WARNING: ATTR object prop exception : " + v.ToString() + " - " + f.Name + " - " + ft.ToString()); } else { if (typeof(System.Collections.ICollection).IsAssignableFrom(ft)) { System.Collections.IList list = (System.Collections.IList)v; WriteListKindOfObjectProperty(f, v, ft, p, list); } else if (v is SEntity) { //found simple object property. give propertyname and URI num m_writer.Write(";" + "\r\n"); WriteIndent(); m_writer.Write("ifcowl:" + p.name + " "); Type vt = v.GetType(); this.m_writer.Write("inst:" + vt.Name + "_" + ((SEntity)v).OID); //There is more in the WriteAttibute method (HTM notation) } else if (f.FieldType.IsInterface && v is ValueType) { m_writer.Write(";" + "\r\n"); WriteIndent(); m_writer.Write("ifcowl:" + p.name + " "); Type vt = v.GetType(); Console.Out.WriteLine("WriteEntityAttributes.GetURIObject()"); URIObject newUriObject = GetURIObject(vt.Name, vt.GetField("Value").GetValue(v).ToString(), vt.GetField("Value").FieldType.Name); m_writer.Write("inst:" + newUriObject.URI); //this.WriteValueWrapper(v); } else if (f.FieldType.IsValueType) // must be IfcBinary { Console.Out.WriteLine("MESSAGE-CHECK: Write IfcBinary 1"); m_writer.Write(";" + "\r\n"); WriteIndent(); m_writer.Write("ifcowl:" + p.name + " "); FieldInfo fieldValue = f.FieldType.GetField("Value"); if (fieldValue != null) { v = fieldValue.GetValue(v); if (v is byte[]) { // binary data type - we don't support anything other than 8-bit aligned, though IFC doesn't either so no point in supporting extraBits byte[] bytes = (byte[])v; char[] s_hexchar = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; StringBuilder sb = new StringBuilder(bytes.Length * 2); for (int i = 0; i < bytes.Length; i++) { byte b = bytes[i]; sb.Append(s_hexchar[b / 0x10]); sb.Append(s_hexchar[b % 0x10]); } v = sb.ToString(); this.m_writer.WriteLine("\""+v+ "\""); } } } else { Console.Out.WriteLine("Warning: Found some other kind of object property: " + p.domain + " - " + p.name); } } } else { Console.Out.WriteLine("Empty value: skipping"); } } } else { //Console.Out.WriteLine("Found inverse property - skipping : " + f.Name); } } m_writer.Write(".\r\n\r\n"); Console.Out.WriteLine("End of attribute"); return; }
public string FormatData(DocProject docProject, DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary<string, DocObject> map, Dictionary<long, SEntity> instances, SEntity root, bool markup) { // load properties this.m_fullpropertynames.Clear(); foreach(DocSection docSection in docProject.Sections) { foreach(DocSchema docSchema in docSection.Schemas) { foreach(DocEntity docEntity in docSchema.Entities) { if(!docEntity.IsAbstract()) { DocEntity docClass = docEntity; while(docClass != null) { foreach(DocAttribute docAttr in docClass.Attributes) { if (String.IsNullOrEmpty(docAttr.Derived) && String.IsNullOrEmpty(docAttr.Inverse)) { string row0 = docEntity.Name; string row1 = docAttr.Name; string row2 = docAttr.Name + "_" + docClass.Name; string row3 = "ENTITY"; DocAggregationEnum docAggr = docAttr.GetAggregation(); if(docAggr == DocAggregationEnum.SET) { row3 = "SET"; } else if(docAggr == DocAggregationEnum.LIST) { row3 = "LIST"; } this.m_fullpropertynames.Add(row1 + "_" + row0, new ObjectProperty(row0, row1, row2, row3)); } } docClass = docProject.GetDefinition(docClass.BaseDefinition) as DocEntity; } } } } } this.m_stream = new System.IO.MemoryStream(); this.Instances = instances; this.Markup = markup; this.Save(); this.m_stream.Position = 0; StreamReader reader = new StreamReader(this.m_stream); string content = reader.ReadToEnd(); return content; }
public void Register(SEntity entity) { this.m_lastOID++; entity.OID = this.m_lastOID; this.Instances.Add(this.m_lastOID, entity); }
public string FormatData(DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary<string, DocObject> map, Dictionary<long, SEntity> instances, SEntity root, bool markup) { //Guid guidMapping = Guid.Parse("");//... StringBuilder sb = new StringBuilder(); foreach (DocModelView docView in docPublication.Views) { foreach (DocConceptRoot docRoot in docView.ConceptRoots) { // look for specific concept root dealing with mappings foreach (DocTemplateUsage docConcept in docRoot.Concepts) { if (docConcept.Definition != null && docConcept.Definition.Name.Equals("External Data Constraints") && docConcept.Items.Count > 0)//... { bool included = true; if (docExchange != null) { included = false; // if exhcnage specified, check for inclusion foreach (DocExchangeItem docExchangeItem in docConcept.Exchanges) { if (docExchangeItem.Exchange == docExchange && docExchangeItem.Requirement == DocExchangeRequirementEnum.Mandatory) { included = true; break; } } } if (included) { string table = docConcept.Items[0].GetParameterValue("Table"); string query = docConcept.Items[0].GetParameterValue("Reference"); //if (query == null) //{ // query = String.Empty; //} //int cap = query.IndexOf('.'); //string typename = query.Substring(0, cap); // find corresponding type? //instance.GetType().Assembly.GetType(typename); // query all data of given type //... sb.AppendLine("<h4>" + docConcept.Name + "</h4>"); sb.AppendLine("<table class=\"gridtable\">"); // generate header row sb.AppendLine("<tr>"); foreach (DocTemplateItem docItem in docConcept.Items) { string name = docItem.GetParameterValue("Name"); string color = docItem.GetParameterValue("Color"); //... use color... sb.Append("<th>"); sb.Append(name); sb.Append("</th>"); }; sb.AppendLine("</tr>"); // generate data rows foreach (SEntity e in instances.Values) { string eachname = e.GetType().Name; if (docRoot.ApplicableEntity.IsInstanceOfType(e)) { sb.Append("<tr>"); foreach (DocTemplateItem docItem in docConcept.Items) { sb.Append("<td>"); string expr = docItem.GetParameterValue("Reference"); CvtValuePath valpath = CvtValuePath.Parse(expr, map); //todo: move out of loop if (valpath != null) { object value = valpath.GetValue(e, null); if (value == e) { value = e.GetType().Name; } else if (value is SEntity) { // use name FieldInfo fieldValue = value.GetType().GetField("Name"); if (fieldValue != null) { value = fieldValue.GetValue(value); } } else if (value is System.Collections.IList) { System.Collections.IList list = (System.Collections.IList)value; StringBuilder sbList = new StringBuilder(); foreach(object elem in list) { FieldInfo fieldName = elem.GetType().GetField("Name"); if(fieldName != null) { object elemname = fieldName.GetValue(elem); if(elemname != null) { FieldInfo fieldValue = elemname.GetType().GetField("Value"); if (fieldValue != null) { object elemval = fieldValue.GetValue(elemname); sbList.Append(elemval.ToString()); } } } sbList.Append("; <br/>"); } value = sbList.ToString(); } else if (value is Type) { value = ((Type)value).Name; } if (value != null) { FieldInfo fieldValue = value.GetType().GetField("Value"); if (fieldValue != null) { value = fieldValue.GetValue(value); } if (value != null) { sb.Append(value.ToString()); // todo: html-encode } } else { sb.Append(" "); } } sb.Append("</td>"); } sb.AppendLine("</tr>"); } } sb.AppendLine("</table>"); sb.AppendLine("<br/>"); } } } } } return sb.ToString(); }
private void DrawObjectBorder(Graphics g, SEntity obj, Pen pen) { if (obj is DocDefinition && ((DocDefinition)obj).DiagramRectangle != null) { DocRectangle docRect = ((DocDefinition)obj).DiagramRectangle; Rectangle rc = new Rectangle( (int)(docRect.X * Factor), (int)(docRect.Y * Factor), (int)(docRect.Width * Factor), (int)(docRect.Height * Factor)); rc.Inflate(-2, -2); g.DrawRectangle(pen, rc); } else if (obj is DocAttribute) { DocAttribute docAttr = (DocAttribute)obj; if (docAttr.DiagramLine != null) { for (int i = 0; i < docAttr.DiagramLine.Count - 1; i++) { g.DrawLine(pen, new Point((int)(docAttr.DiagramLine[i].X * Factor), (int)(docAttr.DiagramLine[i].Y * Factor)), new Point((int)(docAttr.DiagramLine[i + 1].X * Factor), (int)(docAttr.DiagramLine[i + 1].Y * Factor))); } } } else if(obj is DocLine) { // tree point DocLine docLine = (DocLine)obj; DocPoint docPoint = docLine.DiagramLine[docLine.DiagramLine.Count - 1]; Rectangle rc = new Rectangle((int)(docPoint.X * Factor), (int)(docPoint.Y * Factor), 0, 0); rc.Inflate(6, 6); g.DrawEllipse(pen, rc); } }
private void WriteEntity(SEntity o, long ID) { string newline = "\r\n"; if (this.m_markup) newline = "<br/>"; Type t = o.GetType(); string hyperlink = "../../schema/" + t.Namespace.ToLower() + "/lexical/" + t.Name.ToLower() + "_" + ID + ".htm"; this.WriteStartElement(t.Name+"_"+ID, hyperlink); this.m_writer.Write(newline); m_indent++; Console.Out.WriteLine("\r\n--- Writing entity : " + t.Name.ToString()); Console.Out.WriteLine("-----------------------------------"); this.WriteType("ifcowl:" + t.Name.ToString()); this.WriteEntityAttributes(o); Console.Out.WriteLine("--------------done---------------------"); }
public virtual object Clone() { Type t = this.GetType(); // make a copy, attached to broker SEntity clone = (SEntity)Activator.CreateInstance(t); // reference all registered fields IList <FieldInfo> fields = SEntity.GetFieldsOrdered(t); foreach (FieldInfo field in fields) { if (field.FieldType.IsValueType || field.FieldType == typeof(string)) { // copy over value types object val = field.GetValue(this); field.SetValue(clone, val); } else if (field.FieldType.IsInterface || typeof(SEntity).IsAssignableFrom(field.FieldType)) { // make unique copy of referenced type except for owner history!!! object val = field.GetValue(this); if (val is SEntity) { SEntity sentity = (SEntity)val; SEntity valclone = (SEntity)sentity.Clone(); field.SetValue(clone, valclone); } else { field.SetValue(clone, val); } } else if (typeof(IList).IsAssignableFrom(field.FieldType)) { IList listSource = (IList)field.GetValue(this); if (listSource != null) { // don't copy collections, but initialize new collection System.Collections.IList listClone = (System.Collections.IList)Activator.CreateInstance(field.FieldType); field.SetValue(clone, listClone); Type[] genericargs = field.FieldType.GetGenericArguments(); if (genericargs.Length == 1) { foreach (object element in listSource) { object elemClone = null; // clone resources -- don't carry over rooted objects if (element is ICloneable) { // clone resources, list of list, e.g. IfcBSplineSurface elemClone = ((ICloneable)element).Clone(); } else { // i.e. length coordinate elemClone = element; } // now add to list, INCLUDING IF NULL such as blank entries of table listClone.Add(elemClone); } } } } } return(clone); }
private void WriteEntity(SEntity o) { // sanity check if(this.m_indent > 100) { return; } Type t = o.GetType(); string hyperlink = "../../schema/" + t.Namespace.ToLower() + "/lexical/" + t.Name.ToLower() + ".htm"; this.WriteStartElement(t.Name, hyperlink); #if false // id if (gen != null) { bool firstTime; long id = gen.GetId(o, out firstTime); writer.WriteAttributeString("id", "i" + id.ToString()); } #endif /* writer.WriteStartAttribute("id"); writer.WriteValue("i" + id.ToString()); writer.WriteEndAttribute();*/ // write fields as attributes bool haselements = false; IList<FieldInfo> fields = SEntity.GetFieldsOrdered(t); foreach (FieldInfo f in fields) { object v = f.GetValue(o); if(v != null) { if (f.FieldType.IsValueType) { Type ft = f.FieldType; if (ft.IsGenericType && ft.GetGenericTypeDefinition() == typeof(Nullable<>)) { // special case for Nullable types ft = ft.GetGenericArguments()[0]; } Type typewrap = null; while (ft.IsValueType && !ft.IsPrimitive) { FieldInfo fieldValue = ft.GetField("Value"); if (fieldValue != null) { v = fieldValue.GetValue(v); if (typewrap == null) { typewrap = ft; } ft = fieldValue.FieldType; } else { break; } } if (v != null) { string encodedvalue = System.Security.SecurityElement.Escape(v.ToString()); m_writer.Write(" "); m_writer.Write(f.Name); m_writer.Write("=\""); m_writer.Write(encodedvalue); //... escape it m_writer.Write("\""); } } else { haselements = true; } } } IList<FieldInfo> inverses = SEntity.GetFieldsInverse(t); if (haselements || inverses.Count > 0) { WriteOpenElement(); // write direct object references and lists foreach (FieldInfo f in fields) { DocXsdFormat format = GetXsdFormat(f); // hide fields where inverse attribute used instead if (!f.FieldType.IsValueType && (format == null || (format.XsdFormat != DocXsdFormatEnum.Hidden))) { WriteAttribute(o, f); } } // write inverse object references and lists foreach (FieldInfo f in inverses) { DocXsdFormat format = GetXsdFormat(f); if (format != null && format.XsdFormat == DocXsdFormatEnum.Element)//... check this { WriteAttribute(o, f); //... careful - don't write back-references... } } WriteEndElement(t.Name); } else { // close opening tag if (this.m_markup) { this.m_writer.WriteLine("/><br/>"); } else { this.m_writer.WriteLine("/>"); } this.m_indent--; } }
private static void GenerateExample( DocProject docProject, DocPublication docPublication, DocExample docExample, List<DocXsdFormat> listFormats, string path, List<int> indexpath, Dictionary<DocObject, bool> included, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema, Dictionary<string, Type> typemap, List<ContentRef> listFigures, List<ContentRef> listTables, FormatHTM htmTOC, FormatHTM htmSectionTOC, Dictionary<DocFormatSchemaEnum, IFormatData> mapFormats, Dictionary<long, SEntity> outerinstancemap, // instance data of parent example, if inherited SEntity outerinstanceroot ) { if (included == null || included.ContainsKey(docExample)) { indexpath[indexpath.Count - 1]++; StringBuilder indexpathname = new StringBuilder(); indexpathname.Append("E"); foreach(int x in indexpath) { indexpathname.Append("."); indexpathname.Append(x); } string indexpathstring = indexpathname.ToString(); string pathExample = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".htm"; using (FormatHTM htmExample = new FormatHTM(pathExample, mapEntity, mapSchema, included)) { htmExample.WriteHeader(docExample.Name, 2, docPublication.Header); htmExample.WriteScript(-5, indexpath[0], 0, 0); htmExample.WriteLine("<h3 class=\"std\">" + indexpathstring + " " + docExample.Name + "</h3>"); // table of files if (docExample.File != null) { htmExample.Write("<table class=\"gridtable\">"); htmExample.Write("<tr><th>Format</th><th>ASCII</th><th>HTML</th><th>Size</th></tr>"); if (docExample.File != null && !Properties.Settings.Default.SkipDiagrams) { string pathIFC = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ifc"; using (System.IO.FileStream filestream = new System.IO.FileStream(pathIFC, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read)) { filestream.Write(docExample.File, 0, docExample.File.Length); } using (FormatSPF spfExample = new FormatSPF(new System.IO.MemoryStream(docExample.File, false), typemap, null)) { string pathListing = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ifc.htm"; if (docPublication.GetFormatOption(DocFormatSchemaEnum.STEP) == DocFormatOptionEnum.Examples)//Properties.Settings.Default.ExampleSPF) { using (FormatHTM htmListing = new FormatHTM(pathListing, mapEntity, mapSchema, included)) { htmListing.WriteHeader(docExample.Name, 2, docPublication.Header); htmListing.WriteLine("<tt class=\"spf\">"); string htm = null; try { htm = spfExample.LoadMarkup(); outerinstancemap = spfExample.Instances; } catch { } htmListing.Write(htm); htmListing.Write("</tt>"); htmListing.WriteFooter(String.Empty); } } // find the IfcProject SEntity rootproject = null; foreach (SEntity ent in spfExample.Instances.Values) { if (ent.GetType().Name.Equals("IfcProject")) { rootproject = ent; break; } } foreach (DocFormat docFormat in docPublication.Formats) { // generate example in other formats... if (docFormat.FormatOptions == DocFormatOptionEnum.Examples) { long filesize = docExample.File.LongLength; if (docFormat.FormatType != DocFormatSchemaEnum.STEP) { IFormatData formatext = null; if (mapFormats.TryGetValue(docFormat.FormatType, out formatext)) { string content = formatext.FormatData(docProject, docPublication, null, mapEntity, spfExample.Instances, rootproject, false); string pathRAW = path + @"\annex\annex-e\" + MakeLinkName(docExample) + "." + docFormat.ExtensionInstances; using (System.IO.StreamWriter writer = new System.IO.StreamWriter(pathRAW, false)) { writer.Write(content); } string conmark = formatext.FormatData(docProject, docPublication, null, mapEntity, spfExample.Instances, rootproject, true); string pathHTM = pathRAW + ".htm"; using (FormatHTM fmtHTM = new FormatHTM(pathHTM, mapEntity, mapSchema, included)) { fmtHTM.WriteHeader(docExample.Name, 2, docPublication.Header); fmtHTM.Write(conmark); fmtHTM.WriteFooter(""); } filesize = content.Length; } } string sizetext = filesize.ToString(); string ext = docFormat.ExtensionInstances; htmExample.WriteLine("<tr><td>" + docFormat.FormatType.ToString() + "</td><td><a href=\"" + MakeLinkName(docExample) + "." + ext + "\">File</a></td><td><a href=\"" + MakeLinkName(docExample) + "." + ext + ".htm\">Markup</a></td><td style=\"text-align:right\">" + sizetext + "</td></tr>"); } } } } htmExample.Write("</table>"); htmExample.Write("<table class=\"gridtable\">"); htmExample.Write("<tr><th>View</th></tr>"); foreach (DocModelView docView in docExample.Views) { if (included != null && included.ContainsKey(docView)) { string hyperlink = "../../schema/views/" + MakeLinkName(docView) + "/index.htm"; htmExample.Write("<tr><td><a href=\"" + hyperlink + "\">" + docView.Name + "</td></tr>"); } } htmExample.Write("</table>"); if (docExample.ApplicableType != null) { string[] ApplicableTypesArray = docExample.ApplicableType.Split(','); htmExample.Write("<table class=\"gridtable\">"); htmExample.Write("<tr><th>Entity</th></tr>"); for (int i = 0; i < ApplicableTypesArray.Length; i++) { string hyperlink = "../../schema/" + mapSchema[ApplicableTypesArray.GetValue(i).ToString()].ToString().ToLower() + "/lexical/" + ApplicableTypesArray.GetValue(i).ToString().ToLower() + ".htm"; htmExample.Write("<tr><td><a href=" + hyperlink + ">" + ApplicableTypesArray.GetValue(i) + "</td></tr>"); } htmExample.Write("</table>"); } } docExample.Documentation = UpdateNumbering(docExample.Documentation, listFigures, listTables, docExample); htmExample.WriteDocumentationMarkup(docExample.Documentation, docExample, docPublication); if (docExample.File == null && outerinstancemap != null) { // if specific to exchange, capture inline if (docExample.Views.Count > 0) { // hack for now based on example name matching exchange name -- make explicit later foreach (DocExchangeDefinition docExchange in docExample.Views[0].Exchanges) { if (docExample.Name.Equals(docExchange.Name)) { // matches -- generate FormatSQL fmt = new FormatSQL(); string content = fmt.FormatData(docProject, docPublication, docExchange, mapEntity, outerinstancemap, outerinstanceroot, false); htmExample.Write(content); break; } } } } htmExample.WriteLinkTo(docExample); htmExample.WriteFooter(docPublication.Footer); } using (FormatHTM htmLink = new FormatHTM(path + "/link/" + MakeLinkName(docExample) + ".htm", mapEntity, mapSchema, included)) { string linkurl = "../annex/annex-e/" + MakeLinkName(docExample) + ".htm"; htmLink.WriteLinkPage(linkurl, docPublication); } string urlExample = "annex-e/" + MakeLinkName(docExample) + ".htm"; htmTOC.WriteTOC(2, "<a class=\"listing-link\" href=\"annex/" + urlExample + "\" >" + indexpathstring + " " + docExample.Name + "</a>"); string linkid = ""; if(indexpath.Count == 1) { linkid = indexpath[0].ToString(); } string htmllink = "<a class=\"listing-link\" id=\"" + linkid + "\" href=\"" + urlExample + "\" target=\"info\">" + docExample.Name + "</a>"; htmSectionTOC.WriteLine("<tr class=\"std\"><td class=\"menu\">" + indexpathstring + " " + htmllink + "</td></tr>"); if (docExample.Examples.Count > 0) { indexpath.Add(0); foreach(DocExample docSub in docExample.Examples) { GenerateExample(docProject, docPublication, docSub, listFormats, path, indexpath, included, mapEntity, mapSchema, typemap, listFigures, listTables, htmTOC, htmSectionTOC, mapFormats, outerinstancemap, outerinstanceroot); } indexpath.RemoveAt(indexpath.Count - 1); } } }
private void WriteReference(XmlWriter writer, SEntity r) { writer.WriteStartElement(r.GetType().Name); writer.WriteStartAttribute("xsi", "nil", null); writer.WriteValue(true); writer.WriteEndAttribute(); writer.WriteStartAttribute("ref"); writer.WriteValue("i" + r.OID.ToString()); writer.WriteEndAttribute(); writer.WriteEndElement(); }
private void LoadInstance(TreeNode tnParent, SEntity instance) { if (instance == null) return; // recursion stop limit (if user hits star button) if (tnParent != null && tnParent.Level > 32) return; if (tnParent != null && tnParent.Nodes.Count > 0 && tnParent.Nodes[0].Tag != null) { return; } if (tnParent != null) { tnParent.Nodes.Clear(); // remove placeholder } Dictionary<string, DocObject> mapEntity = new Dictionary<string, DocObject>(); Dictionary<string, string> mapSchema = new Dictionary<string, string>(); BuildMaps(mapEntity, mapSchema); Type t = instance.GetType(); DocDefinition docDef = this.m_project.GetDefinition(t.Name); if (docDef is DocEntity) { DocEntity docEntity = (DocEntity)docDef; List<DocAttribute> listAttr = new List<DocAttribute>(); FormatPNG.BuildAttributeList(docEntity, listAttr, mapEntity); foreach (DocAttribute docAttr in listAttr) { object value = null; System.Reflection.FieldInfo field = t.GetField(docAttr.Name); if (field != null) { value = field.GetValue(instance); // drill into underlying value if (value != null && !(value is SEntity)) { System.Reflection.FieldInfo fValue = value.GetType().GetField("Value"); if (fValue != null) { value = fValue.GetValue(value); } } } if (value != null) { TreeNode tn = new TreeNode(); tn.Tag = docAttr; tn.Text = docAttr.Name; if (value is SEntity) { tn.Text += " = " + value.GetType().Name;//((SEntity)value).OID; } else if (value is System.Collections.IList) { System.Collections.IList list = (System.Collections.IList)value; tn.Text += " = [" + list.Count + "]"; } else if (value != null) { tn.Text += " = " + value.ToString(); } if (tnParent != null) { tnParent.Nodes.Add(tn); } else { this.treeViewInstance.Nodes.Add(tn); } if (value is SEntity) { LoadInstance(tn, (SEntity)value); } else if (value is System.Collections.IList) { System.Collections.IList list = (System.Collections.IList)value; for (int i = 0; i < list.Count; i++) { TreeNode tnItem = new TreeNode(); tnItem.Tag = list[i]; tnItem.Text = (i + 1).ToString() + " = " + list[i].GetType().Name; tn.Nodes.Add(tnItem); TreeNode tnNull = new TreeNode(); tnItem.Nodes.Add(tnNull); } } } } } }
/// <summary> /// Creates a concept diagram for a particular entity, including all concepts at specified view and base view(s). /// </summary> /// <param name="docEntity"></param> /// <param name="docView"></param> /// <param name="map"></param> /// <param name="layout"></param> /// <param name="docProject"></param> /// <param name="instance"></param> /// <returns></returns> internal static Image CreateConceptDiagram(DocEntity docEntity, DocModelView docView, Dictionary<string, DocObject> map, Dictionary<Rectangle, DocModelRule> layout, DocProject docProject, SEntity instance) { DocSchema docSchema = docProject.GetSchemaOfDefinition(docEntity); layout.Clear(); List<int> lanes = new List<int>(); // keep track of position offsets in each lane for (int i = 0; i < 16; i++) { lanes.Add(0); } // determine boundaries DrawEntity(null, 0, lanes, docEntity, docView, null, null, map, layout, docProject, docSchema, instance); Rectangle rcBounds = Rectangle.Empty; foreach (Rectangle rc in layout.Keys) { if (rc.Right > rcBounds.Width) { rcBounds.Width = rc.Right; } if (rc.Bottom > rcBounds.Bottom) { rcBounds.Height = rc.Bottom; } } rcBounds.Width += FormatPNG.Border; rcBounds.Height += FormatPNG.Border; Image image = new Bitmap(rcBounds.Width, rcBounds.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); using (Graphics g = Graphics.FromImage(image)) { g.FillRectangle(Brushes.White, new Rectangle(0, 0, image.Width, image.Height)); layout.Clear(); lanes = new List<int>(); // keep track of position offsets in each lane for (int i = 0; i < 16; i++) { lanes.Add(0); } DrawEntity(g, 0, lanes, docEntity, docView, null, null, map, layout, docProject, docSchema, instance); g.DrawRectangle(Pens.Black, 0, 0, rcBounds.Width - 1, rcBounds.Height - 1); } return image; }
private object TraceOperation(DocTemplateDefinition template, DocOp op, StringBuilder sb, SEntity ent, List<SEntity> population, int level) { System.Collections.Hashtable hashtable = new System.Collections.Hashtable(); object result = op.Eval(ent, hashtable, template, null, null); if (hashtable.Count > 0) { // must evaluate all for uniqueness foreach (object other in population) { if (other == ent) // first instance will pass; following duplicate instances will fail break; // returning false means there's a duplicate (not unique). object otherresult = op.Eval(other, hashtable, template, null, null); if (otherresult is bool && !(bool)otherresult) { result = false; break; } } } if (result is bool && !((bool)result)) { for (int i = 0; i < level; i++ ) { sb.Append(" "); } sb.AppendLine(op.ToString(template) + "<br/>"); } // recurse if (op is DocOpLogical) { DocOpLogical oplog = (DocOpLogical)op; TraceOperation(template, oplog.ExpressionA, sb, ent, population, level + 1); TraceOperation(template, oplog.ExpressionB, sb, ent, population, level + 1); } return result; }
private static void DrawAttribute( Graphics g, int lane, List<int> lanes, DocEntity docEntity, DocModelView docView, DocModelRuleAttribute ruleAttribute, Dictionary<string, DocObject> map, int offset, Dictionary<Rectangle, DocModelRule> layout, DocProject docProject, DocSchema docSchema, SEntity instance) { int x = lane * CX + FormatPNG.Border; int y = lanes[lane] + FormatPNG.Border; // find the index of the attribute List<DocAttribute> listAttr = new List<DocAttribute>(); BuildAttributeList(docEntity, listAttr, map); int iAttr = -1; for (int i = 0; i < listAttr.Count; i++) { if (listAttr[i].Name.Equals(ruleAttribute.Name)) { // found it iAttr = i; break; } } if (iAttr >= 0) { DocAttribute docAttr = listAttr[iAttr]; object valueinstance = null; if (instance != null) { System.Reflection.FieldInfo field = instance.GetType().GetField(docAttr.Name); if(field != null) { valueinstance = field.GetValue(instance); } } // map it foreach (DocModelRule ruleEach in ruleAttribute.Rules) { if (ruleEach is DocModelRuleEntity) { DocModelRuleEntity ruleEntity = (DocModelRuleEntity)ruleEach; DocObject docObj = null; if (docSchema != null) { docObj = docSchema.GetDefinition(ruleEntity.Name); if (docObj is DocDefinitionRef) docObj = null; } if (docObj == null) { map.TryGetValue(ruleEntity.Name, out docObj); } { int dest = FormatPNG.Border; if (lanes.Count > lane + 1) { dest = lanes[lane + 1] + FormatPNG.Border; } if (docObj is DocEntity) { DocEntity docEntityTarget = (DocEntity)docObj; // resolve inverse attribute List<DocAttribute> listTarget = new List<DocAttribute>(); BuildAttributeList(docEntityTarget, listTarget, map); for (int i = 0; i < listTarget.Count; i++) { DocAttribute docAttrTarget = listTarget[i]; if (docAttr.Inverse != null && docAttrTarget.Name.Equals(docAttr.Inverse)) { // found it dest += CY * (i + 1); break; } else if (docAttrTarget.Inverse != null && docAttr.Name.Equals(docAttrTarget.Inverse)) { //...also need to check for type compatibility bool found = false; DocEntity docTest = docEntity; while (docTest != null) { if (docTest.Name.Equals(docAttrTarget.DefinedType)) { found = true; break; } if (docTest.BaseDefinition == null) break; DocObject docBase = null; if (map.TryGetValue(docTest.BaseDefinition, out docBase)) { docTest = docBase as DocEntity; } else { break; } } // found it if (found) { dest += CY * (i + 1); break; } } } // draw the entity, recurse DrawEntity(g, lane + 1, lanes, docEntityTarget, docView, null, ruleEntity, map, layout, docProject, docSchema, valueinstance); } else { int targetY = lanes[lane + 1] + FormatPNG.Border; if (g != null) { Brush brush = Brushes.Black; if (instance != null) { if (valueinstance == null) { brush = Brushes.Red; } else if(valueinstance is System.Collections.IList) { brush = Brushes.Blue; } else { string typename = valueinstance.GetType().Name; if (typename == ruleEntity.Name) { brush = Brushes.Lime; } else { brush = Brushes.Red; } } } g.FillRectangle(brush, x + CX, targetY, CX - DX, CY); g.DrawRectangle(Pens.Black, x + CX, targetY, CX - DX, CY); using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f)) { string content = ruleEntity.Name;//docObj.Name; foreach (DocModelRule ruleConstraint in ruleEntity.Rules) { if (ruleConstraint.Description != null && ruleConstraint.Description.StartsWith("Value=")) { content = ruleConstraint.Description.Substring(6); using (StringFormat fmt = new StringFormat()) { fmt.Alignment = StringAlignment.Far; g.DrawString(content, font, Brushes.White, new RectangleF(x + CX, targetY, CX - DX, CY), fmt); } } } g.DrawString(ruleEntity.Name, font, Brushes.White, x + CX, targetY); if (ruleEntity.Identification == "Value") { // mark rule serving as default value g.FillEllipse(Brushes.Green, new Rectangle(x + CX - DX - CY, y, CY, CY)); } } } // record rectangle if (layout != null) { layout.Add(new Rectangle(x + CX, targetY, CX - DX, CY), ruleEntity); } // increment lane offset for all lanes int minlane = targetY + CY * 2; int i = lane + 1; if (lanes[i] < minlane) { lanes[i] = minlane; } } // draw arrow if (g != null) { int x0 = x + CX - DX; int y0 = y + CY * (iAttr + 1) + CY / 2; int x1 = x + CX; int y1 = dest + CY / 2; int xM = x0 + DX / 2 - offset * 2; if(!String.IsNullOrEmpty(ruleAttribute.Identification)) { // mark the attribute as using parameter //g.DrawRectangle(Pens.Blue, x, y + CY * (iAttr + 1), CX - DX, CY); using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f, FontStyle.Regular)) { using (StringFormat fmt = new StringFormat()) { fmt.Alignment = StringAlignment.Near; g.DrawString(docAttr.Name, font, Brushes.Blue, x, y + CY * (iAttr + 1), fmt); } } } g.DrawLine(Pens.Black, x0, y0, xM, y0); g.DrawLine(Pens.Black, xM, y0, xM, y1); g.DrawLine(Pens.Black, xM, y1, x1, y1); } } } } if (g != null && ruleAttribute.Identification == "Name") { // mark rule serving as default name g.FillEllipse(Brushes.Blue, new Rectangle(x + CX - DX - CY, y + CY * (iAttr+1), CY, CY)); } #if false string card = ruleAttribute.GetCardinalityExpression(); if (g != null && card != null) { card = card.Trim(); switch (docAttr.GetAggregation()) { case DocAggregationEnum.SET: card = "S" + card; break; case DocAggregationEnum.LIST: card = "L" + card; break; } int px = x + CX - DX; int py = y + CY * (iAttr + 1); g.FillRectangle(Brushes.White, px - CX / 5, py, CX / 5, CY); using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f, FontStyle.Regular)) { using (StringFormat fmt = new StringFormat()) { fmt.Alignment = StringAlignment.Far; g.DrawString(card, font, Brushes.Blue, px, py, fmt); } } } #endif } }
private bool TraceRule(DocTemplateDefinition template, DocModelRule rule, StringBuilder sb, SEntity ent, List<SEntity> population) { bool pass = true; if (rule is DocModelRuleConstraint) { DocModelRuleConstraint ruleCon = (DocModelRuleConstraint)rule; object result = TraceOperation(template, ruleCon.Expression, sb, ent, population, 0); if(result is bool && !((bool)result)) pass = false; } foreach(DocModelRule sub in rule.Rules) { bool eachpass = TraceRule(template, sub, sb, ent, population); if (!eachpass) pass = false; } return pass; }
//UNUSED!!!! => Use FormatTTL_Stream.FormatData() instead public string FormatData(DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary<string, DocObject> map, Dictionary<long, SEntity> instances, SEntity root, bool markup) { //UNUSED!!!! => Use FormatTTL_Stream.FormatData() instead return null; }
private void WriteAttribute(SEntity o, FieldInfo f, DocXsdFormat format) { if (f.Name.Equals("ConversionFactor") && this is IfcDoc.Format.JSN.FormatJSN) { this.ToString(); } object v = f.GetValue(o); if (v == null) return; this.WriteStartElementAttribute(f.Name, null); Type ft = f.FieldType; if (format == null || format.XsdFormat != DocXsdFormatEnum.Attribute) { this.WriteOpenElement(); } if (typeof(System.Collections.ICollection).IsAssignableFrom(ft)) { System.Collections.IList list = (System.Collections.IList)v; // for nested lists, flatten; e.g. IfcBSplineSurfaceWithKnots.ControlPointList if (typeof(System.Collections.ICollection).IsAssignableFrom(ft.GetGenericArguments()[0])) { System.Collections.ArrayList flatlist = new System.Collections.ArrayList(); foreach (System.Collections.ICollection innerlist in list) { foreach (object e in innerlist) { flatlist.Add(e); } } list = flatlist; } if(list.Count > 0 && list[0] is SEntity) { this.WriteCollectionStart(); } for (int i = 0; i < list.Count; i++) { object e = list[i]; if (e is SEntity) { if (format != null && format.XsdFormat == DocXsdFormatEnum.Attribute) { // only one item, e.g. StyledByItem\IfcStyledItem this.WriteEntityStart(); bool closeelem = this.WriteEntityAttributes((SEntity)e); if (!closeelem) { this.WriteCloseElementAttribute(); return; } this.WriteEntityEnd(); } else { this.WriteEntity((SEntity)e); } if(i < list.Count-1) { this.WriteCollectionDelimiter(); } } else if (e is System.Collections.IList) { System.Collections.IList listInner = (System.Collections.IList)e; for (int j = 0; j < listInner.Count; j++) { object oi = listInner[j]; Type et = oi.GetType(); while (et.IsValueType && !et.IsPrimitive) { FieldInfo fieldValue = et.GetField("Value"); if (fieldValue != null) { oi = fieldValue.GetValue(oi); et = fieldValue.FieldType; } else { break; } } // write each value in sequence with spaces delimiting string sval = oi.ToString(); this.m_writer.Write(sval); this.m_writer.Write(" "); } } else { // if flat-list (e.g. structural load Locations) or list of strings (e.g. IfcPostalAddress.AddressLines), must wrap this.WriteValueWrapper(e); } } if (list.Count > 0 && list[0] is SEntity) { this.WriteCollectionEnd(); } } else if (v is SEntity) { if (format != null && format.XsdFormat == DocXsdFormatEnum.Attribute) { this.WriteEntityStart(); Type vt = v.GetType(); if (ft != vt) { string hyperlink = "../../schema/" + vt.Namespace.ToLower() + "/lexical/" + vt.Name.ToLower() + ".htm"; this.WriteType(vt.Name, hyperlink); } bool closeelem = this.WriteEntityAttributes((SEntity)v); if (!closeelem) { this.WriteCloseElementEntity(); return; } this.WriteEntityEnd(); } else { // if rooted, then check if we need to use reference; otherwise embed this.WriteEntity((SEntity)v); } } else if (f.FieldType.IsInterface && v is ValueType) { this.WriteValueWrapper(v); } else if (f.FieldType.IsValueType) // must be IfcBinary { FieldInfo fieldValue = f.FieldType.GetField("Value"); if (fieldValue != null) { v = fieldValue.GetValue(v); if (v is byte[]) { this.WriteOpenElement(); // binary data type - we don't support anything other than 8-bit aligned, though IFC doesn't either so no point in supporting extraBits byte[] bytes = (byte[])v; char[] s_hexchar = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; StringBuilder sb = new StringBuilder(bytes.Length * 2); for (int i = 0; i < bytes.Length; i++) { byte b = bytes[i]; sb.Append(s_hexchar[b / 0x10]); sb.Append(s_hexchar[b % 0x10]); } v = sb.ToString(); this.m_writer.WriteLine(v); } } } else { //??? this.ToString(); } WriteEndElementAttribute(f.Name); }