/// <summary> /// Formats table for all exchanges within a view /// </summary> /// <param name="mvd"></param> /// <returns></returns> private static string FormatView(DocProject docProject, DocModelView docView, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema) { // format content StringBuilder sb = new StringBuilder(); // 1. manual content sb.Append(docView.Documentation); #if false // don't show anymore // 2. map of entities and templates -- Identity | Template | Import | Export sb.AppendLine("<p></p>"); SortedList<string, DocConceptRoot> sortlist = new SortedList<string, DocConceptRoot>(); // base view DocModelView docBase = docView; while (docBase != null) { foreach (DocConceptRoot docRoot in docBase.ConceptRoots) { if (!sortlist.ContainsKey(docRoot.ApplicableEntity.Name)) { sortlist.Add(docRoot.ApplicableEntity.Name, docRoot); } } if (!String.IsNullOrEmpty(docBase.BaseView)) { docBase = docProject.GetView(Guid.Parse(docBase.BaseView)); } else { docBase = null; } } int cols = 3 + docView.Exchanges.Count; // new style - table sb.AppendLine("<table class=\"exchange\">"); sb.AppendLine("<tr><th colspan=\"" + cols.ToString() + "\">" + docView.Name + "</th></tr>"); sb.Append("<tr><th>Entity/Concept</th><th>Attributes</th><th>Constraints</th>"); //<th>I</th><th>E</th></tr>"); foreach (DocExchangeDefinition docExchange in docView.Exchanges) { sb.Append("<th>"); sb.Append("<img src=\"../../../img/mvd-"); sb.Append(docExchange.Name.ToLower().Replace(' ', '-')); sb.Append(".png\" title=\""); sb.Append(docExchange.Name); sb.Append("\" />"); sb.Append("</th>"); } sb.AppendLine("</tr>"); foreach (string ent in sortlist.Keys) { DocConceptRoot docRoot = sortlist[ent]; sb.Append("<tr><td colspan=\"" + cols.ToString() + "\"><b><i>"); sb.Append(docRoot.ApplicableEntity.Name); sb.AppendLine("</i></b></td></tr>"); // determine schema string schema = mapSchema[ent]; foreach (DocTemplateUsage docConcept in docRoot.Concepts) { if (docConcept.Definition != null) { sb.Append("<tr><td> <a href=\"../../"); sb.Append(schema.ToLower()); sb.Append("/lexical/"); sb.Append(ent.ToLower()); sb.Append(".htm#"); sb.Append(docConcept.Definition.Name.ToLower().Replace(' ', '-')); sb.Append("\">"); sb.Append(docConcept.Definition.Name); sb.Append("</a></td><td>"); bool first = true; if (docConcept.Definition.Rules != null) { foreach (DocModelRule docRule in docConcept.Definition.Rules) { if (!first) { sb.Append("<br/>"); } sb.Append(docRule.Name); first = false; } } sb.Append("</td><td>"); // IfcDoc 6.4: use tables string table = FormatConceptTable(docProject, docView, docRoot.ApplicableEntity, docRoot, docConcept, mapEntity, mapSchema); sb.Append(table); #if false // build list of inherited items first = true; DocTemplateItem[] items = FindTemplateItems(docProject, docRoot.ApplicableEntity, docConcept.Definition, docView); foreach (DocTemplateItem docItem in items) { if (!first) { sb.Append("<br/>"); } sb.Append(docItem.RuleParameters); first = false; } #endif sb.Append("</td>"); foreach (DocExchangeDefinition docExchange in docView.Exchanges) { DocExchangeRequirementEnum reqExport = DocExchangeRequirementEnum.NotRelevant; foreach (DocExchangeItem docItem in docConcept.Exchanges) { if (docItem.Exchange == docExchange && docItem.Applicability == DocExchangeApplicabilityEnum.Export) { reqExport = docItem.Requirement; } } sb.Append("<td>"); AppendRequirement(sb, reqExport, 3); sb.Append("</td>"); } sb.AppendLine("</tr>"); } } } sb.AppendLine("</table>"); #endif return sb.ToString(); }
/// <summary> /// Draws entity and recurses. /// </summary> /// <param name="g">Graphics device.</param> /// <param name="lane">Horizontal lane for which to draw the entity.</param> /// <param name="lanes">List of lanes left-to-right.</param> /// <param name="docEntity">The entity to draw.</param> /// <param name="docView">The model view for which to draw the entity.</param> /// <param name="docTemplate">The template to draw.</param> /// <param name="docRule">Optional rule for recursing.</param> /// <param name="map">Map of definitions.</param> /// <param name="layout">Optional layout to receive rectangles for building image map</param> /// <param name="docProject">Required project.</param> /// <param name="instance">Optional instance where included or missing attributes are highlighted.</param> private static void DrawEntity( Graphics g, int lane, List<int> lanes, DocEntity docEntity, DocModelView docView, DocTemplateDefinition docTemplate, DocModelRuleEntity docRule, Dictionary<string, DocObject> map, Dictionary<Rectangle, DocModelRule> layout, DocProject docProject, DocSchema docSchema, object instance) { List<DocAttribute> listAttr = new List<DocAttribute>(); BuildAttributeList(docEntity, listAttr, map); while(lanes.Count < lane + 1) { int miny = 0; if (lanes.Count > lane) { miny = lanes[lane]; } lanes.Add(miny); } int x = lane * CX + FormatPNG.Border; int y = lanes[lane] + FormatPNG.Border; if (g != null) { Brush brush = Brushes.Black; if (instance != null) { brush = Brushes.Red; if (instance is System.Collections.IList) { string typename = instance.GetType().Name; // keep going until matching instance System.Collections.IList list = (System.Collections.IList)instance; foreach (object member in list) { string membertypename = member.GetType().Name; DocEntity docType = docProject.GetDefinition(membertypename) as DocEntity; while (docType != null) { if (docType == docEntity) { brush = Brushes.Lime; instance = member; break; } docType = docProject.GetDefinition(docType.BaseDefinition) as DocEntity; } if (brush != Brushes.Red) break; } } else { string typename = instance.GetType().Name; DocEntity docType = docProject.GetDefinition(typename) as DocEntity; while (docType != null) { if (docType == docEntity) { brush = Brushes.Lime; break; } docType = docProject.GetDefinition(docType.BaseDefinition) as DocEntity; } } } else if (docEntity.IsAbstract()) { brush = Brushes.Gray; } else { brush = Brushes.Black; } g.FillRectangle(brush, x, y, CX - DX, CY); g.DrawRectangle(Pens.Black, x, y, CX - DX, CY); using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f, FontStyle.Bold)) { g.DrawString(docEntity.Name, font, Brushes.White, x, y); } if (docRule != null && docRule.Identification == "Value") { // mark rule serving as default value g.FillEllipse(Brushes.Green, new Rectangle(x + CX - DX - CY, y, CY, CY)); } g.DrawRectangle(Pens.Black, x, y + CY, CX - DX, CY * listAttr.Count); using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f, FontStyle.Regular)) { for (int iAttr = 0; iAttr < listAttr.Count; iAttr++) { DocAttribute docAttr = listAttr[iAttr]; string display = docAttr.GetAggregationExpression(); brush = Brushes.Black; if (docAttr.Inverse != null) { brush = Brushes.Gray; } if(String.IsNullOrEmpty(display)) { if(docAttr.IsOptional) { display = "[0:1]"; } else { display = "[1:1]"; } } g.DrawString(docAttr.Name, font, brush, x, y + CY * (iAttr + 1)); using (StringFormat fmt = new StringFormat()) { fmt.Alignment = StringAlignment.Far; g.DrawString(display, font, brush, new RectangleF(x, y + CY * (iAttr + 1), CX - DX, CY), fmt); } } } } // record rectangle if (layout != null) { layout.Add(new Rectangle(x, y, CX - DX, CY + CY * listAttr.Count), docRule); } SortedList<int, List<DocModelRuleAttribute>> mapAttribute = new SortedList<int, List<DocModelRuleAttribute>>(); Dictionary<DocModelRuleAttribute, DocTemplateDefinition> mapTemplate = new Dictionary<DocModelRuleAttribute,DocTemplateDefinition>(); if (docRule != null && docRule.Rules != null) { // map inner rules // sort foreach (DocModelRule rule in docRule.Rules) { if (rule is DocModelRuleAttribute) { DocModelRuleAttribute ruleAttribute = (DocModelRuleAttribute)rule; for (int i = 0; i < listAttr.Count; i++) { if (listAttr[i].Name.Equals(ruleAttribute.Name)) { // found it if (!mapAttribute.ContainsKey(i)) { mapAttribute.Add(i, new List<DocModelRuleAttribute>()); } mapAttribute[i].Add(ruleAttribute); break; } } } } } else if (docTemplate != null) { if (docTemplate.Rules != null) { foreach (DocModelRuleAttribute ruleAttribute in docTemplate.Rules) { for (int i = 0; i < listAttr.Count; i++) { if (listAttr[i].Name != null && listAttr[i].Name.Equals(ruleAttribute.Name)) { // found it //iAttr = i; if (!mapAttribute.ContainsKey(i)) { mapAttribute.Add(i, new List<DocModelRuleAttribute>()); } mapAttribute[i].Add(ruleAttribute); break; } } } } } else { // map each use definition at top-level // build list of inherited views List<DocModelView> listViews = new List<DocModelView>(); DocModelView docBaseView = docView; while (docBaseView != null) { listViews.Add(docBaseView); if (!String.IsNullOrEmpty(docBaseView.BaseView)) { Guid guidBase = Guid.Parse(docBaseView.BaseView); if (guidBase != docBaseView.Uuid) { docBaseView = docProject.GetView(guidBase); } else { docBaseView = null; } } else { docBaseView = null; } } // build from inherited entities too List<DocTemplateDefinition> listTemplates = new List<DocTemplateDefinition>(); // keep track of templates so we don't repeat at supertypes List<DocTemplateDefinition> listSuppress = new List<DocTemplateDefinition>(); // list of templates that are suppressed DocEntity docEntitySuper = docEntity; while(docEntitySuper != null) { foreach (DocModelView docEachView in docProject.ModelViews) { if (docView == null || listViews.Contains(docEachView)) { foreach (DocConceptRoot docRoot in docEachView.ConceptRoots) { if (docRoot.ApplicableEntity == docEntitySuper) { foreach (DocTemplateUsage docUsage in docRoot.Concepts) { if (docUsage.Definition != null && docUsage.Definition.Rules != null && !listTemplates.Contains(docUsage.Definition) && !listSuppress.Contains(docUsage.Definition)) { if (docUsage.Suppress) { listSuppress.Add(docUsage.Definition); } else { listTemplates.Add(docUsage.Definition); foreach (DocModelRuleAttribute ruleAttribute in docUsage.Definition.Rules) { for (int i = 0; i < listAttr.Count; i++) { if (listAttr[i].Name.Equals(ruleAttribute.Name)) { // found it if (!mapAttribute.ContainsKey(i)) { mapAttribute.Add(i, new List<DocModelRuleAttribute>()); } mapAttribute[i].Add(ruleAttribute); if (!mapTemplate.ContainsKey(ruleAttribute)) { mapTemplate.Add(ruleAttribute, docUsage.Definition); } break; } } } } } } } } } } DocObject docTest = null; if (docEntitySuper.BaseDefinition != null && map.TryGetValue(docEntitySuper.BaseDefinition, out docTest)) { docEntitySuper = docTest as DocEntity; } else { docEntitySuper = null; } } } int offset = -mapAttribute.Values.Count / 2; DocTemplateDefinition lastTemplate = null; foreach (List<DocModelRuleAttribute> listSort in mapAttribute.Values) { if (docRule == null && docTemplate == null) { // offset all lanes int maxlane = 0; for (int i = 1; i < lanes.Count; i++) { if (lanes[i] > maxlane) { maxlane = lanes[i]; } } for (int i = 1; i < lanes.Count; i++) { lanes[i] = maxlane; } } foreach (DocModelRuleAttribute ruleAttributeSort in listSort) { // indicate each template DocTemplateDefinition eachTemplate = null; if (mapTemplate.TryGetValue(ruleAttributeSort, out eachTemplate)) { // offset for use definition int minlan = 0; for (int i = 1; i < lanes.Count; i++) { if (eachTemplate != lastTemplate) { lanes[i] += CY * 2; } if (lanes[i] > minlan) { minlan = lanes[i]; } } // verify this... for (int i = 1; i < lanes.Count; i++) { if (lanes[i] < minlan) { lanes[i] = minlan; } } if (g != null && eachTemplate != lastTemplate) { using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f, FontStyle.Italic)) { g.DrawString(eachTemplate.Name, font, Brushes.Gray, CX + FormatPNG.Border, lanes[1] - CY * 2 + FormatPNG.Border); } int lineY = lanes[1] - CY * 2 + FormatPNG.Border; g.DrawLine(Pens.Gray, CX + FormatPNG.Border, lineY, 1920, lineY); } lastTemplate = eachTemplate; } DrawAttribute(g, lane, lanes, docEntity, docView, ruleAttributeSort, map, offset, layout, docProject, docSchema, instance as SEntity); } offset++; } // increment lane offset int minlane = y + CY * (listAttr.Count + 2); if (lanes[lane] < minlane) { lanes[lane] = minlane; } }
internal static void ImportMvd(mvdXML mvd, DocProject docProject, string filepath) { if (mvd.Templates != null) { Dictionary<EntityRule, DocModelRuleEntity> fixups = new Dictionary<EntityRule, DocModelRuleEntity>(); foreach (ConceptTemplate mvdTemplate in mvd.Templates) { DocTemplateDefinition docDef = docProject.GetTemplate(mvdTemplate.Uuid); if (docDef == null) { docDef = new DocTemplateDefinition(); docProject.Templates.Add(docDef); } ImportMvdTemplate(mvdTemplate, docDef, fixups); } foreach(EntityRule er in fixups.Keys) { DocModelRuleEntity docEntityRule = fixups[er]; if(er.References != null) { foreach(TemplateRef tr in er.References) { DocTemplateDefinition dtd = docProject.GetTemplate(tr.Ref); if(dtd != null) { docEntityRule.References.Add(dtd); } } } } } if (mvd.Views != null) { foreach (ModelView mvdView in mvd.Views) { DocModelView docView = docProject.GetView(mvdView.Uuid); if (docView == null) { docView = new DocModelView(); docProject.ModelViews.Add(docView); } ImportMvdObject(mvdView, docView); docView.BaseView = mvdView.BaseView; docView.Exchanges.Clear(); Dictionary<Guid, ExchangeRequirement> mapExchange = new Dictionary<Guid, ExchangeRequirement>(); foreach (ExchangeRequirement mvdExchange in mvdView.ExchangeRequirements) { mapExchange.Add(mvdExchange.Uuid, mvdExchange); DocExchangeDefinition docExchange = new DocExchangeDefinition(); ImportMvdObject(mvdExchange, docExchange); docView.Exchanges.Add(docExchange); docExchange.Applicability = (DocExchangeApplicabilityEnum)mvdExchange.Applicability; // attempt to find icons if exists -- remove extention try { string iconpath = filepath.Substring(0, filepath.Length - 7) + @"\mvd-" + docExchange.Name.ToLower().Replace(' ', '-') + ".png"; if (System.IO.File.Exists(iconpath)) { docExchange.Icon = System.IO.File.ReadAllBytes(iconpath); } } catch { } } foreach (ConceptRoot mvdRoot in mvdView.Roots) { // find the entity DocEntity docEntity = LookupEntity(docProject, mvdRoot.ApplicableRootEntity); if (docEntity != null) { DocConceptRoot docConceptRoot = docView.GetConceptRoot(mvdRoot.Uuid); if (docConceptRoot == null) { docConceptRoot = new DocConceptRoot(); if (docView.ConceptRoots == null) { docView.ConceptRoots = new List<DocConceptRoot>(); } docView.ConceptRoots.Add(docConceptRoot); } ImportMvdObject(mvdRoot, docConceptRoot); docConceptRoot.ApplicableEntity = docEntity; if (mvdRoot.Applicability != null) { docConceptRoot.ApplicableTemplate = docProject.GetTemplate(mvdRoot.Applicability.Template.Ref); if(mvdRoot.Applicability.TemplateRules != null) { docConceptRoot.ApplicableOperator = (DocTemplateOperator)Enum.Parse(typeof(TemplateOperator), mvdRoot.Applicability.TemplateRules.Operator.ToString()); foreach (TemplateRule r in mvdRoot.Applicability.TemplateRules.TemplateRule) { DocTemplateItem docItem = ImportMvdItem(r, docProject, mapExchange); docConceptRoot.ApplicableItems.Add(docItem); } } } docConceptRoot.Concepts.Clear(); foreach (Concept mvdNode in mvdRoot.Concepts) { DocTemplateUsage docUse = new DocTemplateUsage(); docConceptRoot.Concepts.Add(docUse); ImportMvdConcept(mvdNode, docUse, docProject, mapExchange); } } else { //TODO: log error } } } } }