public object GetObject(int row, int col) { if (col >= this.m_listTemplate.Count || row >= this.m_view.ConceptRoots.Count) { return(null); } DocTemplateDefinition docTemplate = this.m_listTemplate[col]; DocConceptRoot docRoot = this.m_view.ConceptRoots[row]; foreach (DocTemplateUsage docUsage in docRoot.Concepts) { if (docUsage.Definition == docTemplate) { foreach (DocExchangeItem docExchangeItem in docUsage.Exchanges) { if (docExchangeItem.Exchange == this.m_exchange && docExchangeItem.Applicability == DocExchangeApplicabilityEnum.Export) { return(docUsage); } } } } return(null); }
public CellValue GetCell(int row, int col) { DocConceptRoot docRoot = this.m_view.ConceptRoots[row]; DocExchangeDefinition docExchange = this.m_view.Exchanges[col]; foreach (DocTemplateUsage docUsage in docRoot.Concepts) { if (docUsage.Definition == this.m_template) { foreach (DocExchangeItem docEx in docUsage.Exchanges) { if (docEx.Exchange == docExchange && docEx.Applicability == DocExchangeApplicabilityEnum.Export) { switch (docEx.Requirement) { case DocExchangeRequirementEnum.Mandatory: return(CellValue.Required); case DocExchangeRequirementEnum.Optional: return(CellValue.Optional); } } } return(CellValue.None); } } return(CellValue.None); }
public CheckGridEntity(DocConceptRoot docRoot, DocModelView docView, DocProject docProject, Dictionary <string, DocObject> map) { this.m_root = docRoot; this.m_view = docView; this.m_project = docProject; this.m_listTemplate = new List <DocTemplateDefinition>(); List <DocTemplateDefinition> listTemplate = docProject.GetTemplateList(); //... filter out templates to only those that apply to entity... foreach (DocTemplateDefinition docTemplate in listTemplate) { if (docTemplate.Rules != null && docTemplate.Rules.Count > 0) // don't include abstract/organizational templates { bool include = false; // check for inheritance DocObject docApplicableEntity = null; if (docTemplate.Type != null && map.TryGetValue(docTemplate.Type, out docApplicableEntity) && docApplicableEntity is DocEntity) { // check for inheritance DocEntity docBase = docRoot.ApplicableEntity; while (docBase != null) { if (docBase == docApplicableEntity) { include = true; break; } if (docBase.BaseDefinition == null) { break; } DocObject docEach = null; if (map.TryGetValue(docBase.BaseDefinition, out docEach)) { docBase = (DocEntity)docEach; } else { docBase = null; } } } if (include) { this.m_listTemplate.Add(docTemplate); } } } }
public CellValue GetCell(int row, int col) { if (col >= this.m_listTemplate.Count || row >= this.m_view.ConceptRoots.Count) { return(CellValue.Unavailable); } DocTemplateDefinition docTemplate = this.m_listTemplate[col]; DocConceptRoot docRoot = this.m_view.ConceptRoots[row]; // return Unavailable if template is incompatible with root bool applicable = false; DocDefinition docDef = this.m_project.GetDefinition(docTemplate.Type); DocEntity docEnt = docRoot.ApplicableEntity; while (docEnt != null) { if (docEnt == docDef) { applicable = true; break; } docEnt = this.m_project.GetDefinition(docEnt.BaseDefinition) as DocEntity; } if (!applicable) { return(CellValue.Unavailable); } foreach (DocTemplateUsage docUsage in docRoot.Concepts) { if (docUsage.Definition == docTemplate) { foreach (DocExchangeItem docExchangeItem in docUsage.Exchanges) { if (docExchangeItem.Exchange == this.m_exchange && docExchangeItem.Applicability == DocExchangeApplicabilityEnum.Export) { switch (docExchangeItem.Requirement) { case DocExchangeRequirementEnum.Mandatory: return(CellValue.Required); case DocExchangeRequirementEnum.Optional: return(CellValue.Optional); } } } } } return(CellValue.None); }
private void toolStripButtonConceptEntity_Click(object sender, EventArgs e) { DocConceptRoot docRoot = this.m_conceptroot; if (docRoot == null) { return; } using (FormSelectEntity form = new FormSelectEntity(null, docRoot.ApplicableEntity, this.m_project, SelectDefinitionOptions.Entity)) { if (form.ShowDialog(this) == DialogResult.OK) { docRoot.ApplicableEntity = form.SelectedEntity as DocEntity; } } }
public object GetObject(int row, int col) { DocConceptRoot docRoot = this.m_view.ConceptRoots[row]; DocExchangeDefinition docExchange = this.m_view.Exchanges[col]; foreach (DocTemplateUsage docUsage in docRoot.Concepts) { if (docUsage.Definition == this.m_template) { foreach (DocExchangeItem docEx in docUsage.Exchanges) { if (docEx.Exchange == docExchange && docEx.Applicability == DocExchangeApplicabilityEnum.Export) { return(docEx); } } return(null); } } return(null); }
public void SetCell(int row, int col, CellValue val) { DocTemplateDefinition docTemplate = this.m_listTemplate[col]; DocConceptRoot docRoot = this.m_view.ConceptRoots[row]; DocTemplateUsage docConcept = null; foreach (DocTemplateUsage docUsage in docRoot.Concepts) { if (docUsage.Definition == docTemplate) { docConcept = docUsage; break; } } if (docConcept == null) { docConcept = new DocTemplateUsage(); docRoot.Concepts.Add(docConcept); docConcept.Definition = docTemplate; } DocExchangeRequirementEnum req = DocExchangeRequirementEnum.NotRelevant; switch (val) { case CellValue.Mandatory: req = DocExchangeRequirementEnum.Mandatory; break; case CellValue.Recommended: req = DocExchangeRequirementEnum.Optional; break; } docConcept.RegisterExchange(this.m_exchange, req); }
/// <summary> /// Formats a template given an entity and optional template /// </summary> /// <param name="entity">The entity to format.</param> /// <param name="usage">Use definition to format, or null for all use definitions for entity.</param> /// <param name="iFigure">The last figure number used.</param> /// /// <param name="iFigure">The last table number used.</param> /// <returns></returns> private static string FormatConcept( DocProject docProject, DocEntity entity, DocConceptRoot root, DocTemplateUsage usage, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema, List<ContentRef> listFigures, List<ContentRef> listTables) { if (usage.Definition == null) return String.Empty; StringBuilder sb = new StringBuilder(); string anchorid = MakeLinkName(usage.Definition); // anchor sb.Append("<a id=\""); sb.Append(anchorid); sb.Append("\" />"); sb.AppendLine(); // Caption sb.Append("<p class=\"use-head\">"); sb.Append(usage.Definition.Name); sb.Append("</p>"); sb.AppendLine(); // filter by particular model view DocModelView docModelView = null; if (root != null) { foreach (DocModelView docView in docProject.ModelViews) { if (docView.ConceptRoots.Contains(root)) { docModelView = docView; break; } } } // new (2.0): capture inherited properties too DocTemplateItem[] listItems = FindTemplateItems(docProject, entity, usage.Definition, docModelView); // add stock sentence // typical values: "Material Constituents", "Documents", "Aggregation", "Nesting", "Representations" // Usage of the <i>Material Constituents</i> concept is shown in Table XXXX. // Usage of the <i>Nesting</i> concept is shown in Table XXXX. // Usage of the <i>Aggregation</i> concept is shown in Table XXXX: // get link of usage string deflink = MakeLinkName(usage.Definition) + ".htm"; if (listItems.Length > 0) { listTables.Add(new ContentRef(entity.Name + " " + usage.Definition.Name, entity)); sb.Append("<p>The <a href=\"../../templates/"); sb.Append(deflink); sb.Append("\">"); sb.Append(usage.Definition.Name); sb.Append("</a> concept applies to this entity as shown in Table "); sb.Append(listTables.Count); sb.Append("."); sb.AppendLine("<table>"); sb.AppendLine("<tr><td>"); string table = FormatConceptTable(docProject, docModelView, entity, root, usage, mapEntity, mapSchema); sb.Append(table); sb.AppendLine("</td></tr>"); sb.Append("<tr><td><p class=\"table\">Table "); sb.Append(listTables.Count); sb.Append(" — "); sb.Append(entity.Name); sb.Append(" "); sb.Append(usage.Definition.Name); sb.AppendLine("</td></tr></table>"); sb.AppendLine(); } else { sb.Append("<p>The <a href=\"../../templates/"); sb.Append(deflink); sb.Append("\">"); sb.Append(usage.Definition.Name); sb.Append("</a> concept applies to this entity.</p>"); } // add figure if it exists string fig = FormatFigure(docProject, entity, usage.Definition, entity.Text, listFigures); if (fig != null) { sb.Append(fig); } if (usage.Documentation != null) { sb.AppendLine(usage.Documentation); // special case if definition provides description, such as for classification } string req = FormatRequirements(usage, docModelView, true); if (req != null) { sb.AppendLine(req); } sb.AppendLine("<br/><br/>"); return sb.ToString(); }
private static void FormatEntityUsage(DocProject docProject, DocEntity entity, DocConceptRoot docRoot, DocTemplateUsage eachusage, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema, List<ContentRef> listFigures, List<ContentRef> listTables, Dictionary<DocObject, bool> included, StringBuilder sb) { if (eachusage.Definition != null) { if (included == null || included.ContainsKey(eachusage.Definition)) { if (eachusage.Documentation != null) { eachusage.Documentation = UpdateNumbering(eachusage.Documentation, listFigures, listTables, entity); } string eachtext = FormatConcept(docProject, entity, docRoot, eachusage, mapEntity, mapSchema, listFigures, listTables); sb.Append(eachtext); sb.AppendLine(); if (eachusage.Concepts.Count > 0) { sb.AppendLine("<details>"); sb.AppendLine("<summary>Concept alternates</summary>"); foreach (DocTemplateUsage innerusage in eachusage.Concepts) { FormatEntityUsage(docProject, entity, docRoot, innerusage, mapEntity, mapSchema, listFigures, listTables, included, sb); } sb.AppendLine("</details>"); } } } }
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; }
private static string FormatConceptTable( DocProject docProject, DocModelView docModelView, DocEntity entity, DocConceptRoot root, DocTemplateUsage usage, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema) { StringBuilder sb = new StringBuilder(); DocTemplateItem[] listItems = FindTemplateItems(docProject, entity, usage.Definition, docModelView); if(listItems.Length == 0) { // scenario for referenced inner templates listItems = usage.Items.ToArray(); } // new way with table DocModelRule[] parameters = usage.Definition.GetParameterRules(); if (parameters != null && parameters.Length > 0 && listItems.Length > 0) { // check if descriptions are provided bool showdescriptions = false; foreach (DocTemplateItem item in listItems) { if (item.Documentation != null) { showdescriptions = true; break; } } sb.AppendLine("<table class=\"gridtable\">"); // header sb.Append("<tr>"); foreach (DocModelRule parameter in parameters) { sb.Append("<th><b>"); sb.Append(parameter.Identification); sb.Append("</b></th>"); } if (showdescriptions) { sb.Append("<th><b>Description</b></th>"); } sb.AppendLine("</tr>"); // items foreach (DocTemplateItem item in listItems) { sb.Append("<tr>"); foreach (DocModelRule parameter in parameters) { string value = item.GetParameterValue(parameter.Identification); string schema = null; if(parameter.Name.Equals("Columns")) { parameter.ToString(); } sb.Append("<td>"); //if (value != null) { DocDefinition docDef = usage.Definition.GetParameterType(parameter.Identification, mapEntity); if (docDef is DocEnumeration) { if(value != null) { schema = mapSchema[docDef.Name]; sb.Append("<a href=\"../../"); sb.Append(schema.ToLower()); sb.Append("/lexical/"); sb.Append(docDef.Name.ToLower()); sb.Append(".htm\">"); sb.Append(value); sb.Append("</a>"); } } else if (docDef is DocEntity) { DocTemplateDefinition docTemplateInner = null; if (parameter is DocModelRuleAttribute) { DocModelRuleAttribute dma = (DocModelRuleAttribute)parameter; foreach(DocModelRule docInnerRule in dma.Rules) { if (docInnerRule is DocModelRuleEntity) { DocModelRuleEntity dme = (DocModelRuleEntity)docInnerRule; if (dme.References.Count == 1) { docTemplateInner = dme.References[0]; DocTemplateUsage docConceptInner = item.GetParameterConcept(parameter.Identification, docTemplateInner); if (docConceptInner != null) { string inner = FormatConceptTable(docProject, docModelView, (DocEntity)docDef, root, docConceptInner, mapEntity, mapSchema); sb.Append("<a href=\"../../templates/" + MakeLinkName(docTemplateInner) + ".htm\">" + docTemplateInner.Name + "</a><br/>"); sb.Append(inner); } } } } } if (docTemplateInner == null && value != null && mapSchema.TryGetValue(value, out schema)) { if(value.StartsWith("Pset_")) { value.ToString(); } sb.Append("<a href=\"../../"); sb.Append(schema.ToLower()); sb.Append("/lexical/"); sb.Append(value.ToLower()); sb.Append(".htm\">"); sb.Append(value); sb.Append("</a>"); } else if(docDef.Name.Equals("IfcReference")) { // ...hyperlinks if(value != null) { string[] parts = value.Split('\\'); foreach(string part in parts) { string[] tokens = part.Split('.'); if (tokens.Length > 0) { sb.Append("\\"); DocDefinition docToken = docProject.GetDefinition(tokens[0]); if (docToken != null) { DocSchema docSchema = docProject.GetSchemaOfDefinition(docToken); string relative = @"../../"; string hyperlink = relative + docSchema.Name.ToLower() + @"/lexical/" + docToken.Name.ToLower() + ".htm"; string format = "<a href=\"" + hyperlink + "\">" + tokens[0] + "</a>"; sb.Append(format); } if (tokens.Length > 1) { sb.Append("."); sb.Append(tokens[1]); } sb.Append("<br>"); } } } //sb.Append(value); } else if(value != null) { sb.Append(value); } } else if (docDef != null && value != null) { value = FormatField(docProject, value, value, docDef.Name, value); sb.Append(value); } else if (value != null) { sb.Append(value); } else { sb.Append(" "); } } /* else { sb.Append(" "); }*/ sb.Append("</td>"); } if (showdescriptions) { sb.Append("<td>"); if (item.Documentation != null) { sb.Append(item.Documentation); } else { sb.Append(" "); } sb.Append("</td>"); } sb.AppendLine("</tr>"); } sb.AppendLine("</table>"); } return sb.ToString(); }
private void toolStripMenuItemFileImport_Click(object sender, EventArgs e) { StringBuilder sbErrors = new StringBuilder(); DialogResult res = this.openFileDialogImport.ShowDialog(this); if (res == DialogResult.OK) { List<DocSchema> importedschemas = new List<DocSchema>(); bool updateDescriptions = false; if(this.openFileDialogImport.FileName.EndsWith(".vex")) { DialogResult resUpdate = MessageBox.Show(this, "Do you want to update the documentation? Click Yes to update documentation and definitions, or No to update just definitions.", "Import VEX", MessageBoxButtons.YesNoCancel); if (resUpdate == System.Windows.Forms.DialogResult.Cancel) return; if (resUpdate == System.Windows.Forms.DialogResult.Yes) updateDescriptions = true; } foreach (string filename in this.openFileDialogImport.FileNames) { string ext = System.IO.Path.GetExtension(filename).ToLower(); switch (ext) { case ".vex": using (FormatSPF format = new FormatSPF(filename, SchemaVEX.Types, null)) { format.Load(); // get the root schemata SCHEMATA vexschema = null; foreach (SEntity entity in format.Instances.Values) { if (entity is SCHEMATA) { vexschema = (SCHEMATA)entity; break; } } if (vexschema != null) { DocSchema schema = Program.ImportVex(vexschema, this.m_project, updateDescriptions); importedschemas.Add(schema); // add schemas from multiple files first, process later } } break; case ".xml": if (filename.Contains("Pset_")) { using (FormatXML format = new FormatXML(filename, typeof(PropertySetDef), "http://buildingSMART-tech.org/xml/psd/PSD_IFC4.xsd")) { format.Load(); PropertySetDef psd = (PropertySetDef)format.Instance; string schema = null; if (psd.Versions != null && psd.Versions.Count > 0) { schema = psd.Versions[0].schema; } if (String.IsNullOrEmpty(schema)) { // guess the schema according to applicable type value if (psd.ApplicableTypeValue != null) { string[] parts = psd.ApplicableTypeValue.Split(new char[] { '/', '[' }); TreeNode tnEntity = null; if (this.m_mapTree.TryGetValue(parts[0].ToLowerInvariant(), out tnEntity)) { DocSchema docschema = (DocSchema)tnEntity.Parent.Parent.Tag; schema = docschema.Name; } } } if(schema == null) { schema = "IfcProductExtension";//fallback } // find the schema TreeNode tn = null; if (schema != null && this.m_mapTree.TryGetValue(schema.ToLowerInvariant(), out tn)) { DocSchema docschema = (DocSchema)tn.Tag; // find existing pset if applicable DocPropertySet pset = docschema.RegisterPset(psd.Name); // use hashed guid if (pset.Uuid == Guid.Empty) { System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create(); byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(pset.Name)); pset.Uuid = new Guid(hash); } pset.Name = psd.Name; if (psd.Definition != null) { pset.Documentation = psd.Definition.Trim(); } if (psd.ApplicableTypeValue != null) { pset.ApplicableType = psd.ApplicableTypeValue.Replace("Type", "").Replace("[PerformanceHistory]", ""); // organize at occurrences; use pset type to determine type applicability } // for now, rely on naming convention (better to capture in pset schema eventually) if (psd.Name.Contains("PHistory")) // special naming convention { pset.PropertySetType = "PSET_PERFORMANCEDRIVEN"; } else if (psd.Name.Contains("Occurrence")) { pset.PropertySetType = "PSET_OCCURRENCEDRIVEN"; } else { pset.PropertySetType = "PSET_TYPEDRIVENOVERRIDE"; } // import localized definitions if (psd.PsetDefinitionAliases != null) { foreach (PsetDefinitionAlias pl in psd.PsetDefinitionAliases) { pset.RegisterLocalization(pl.lang, null, pl.Value); } } foreach (PropertyDef subdef in psd.PropertyDefs) { DocProperty docprop = pset.RegisterProperty(subdef.Name); Program.ImportPsdPropertyTemplate(subdef, docprop); } // add to Use Definition at applicable entity #if false if (pset.ApplicableType != null) { string[] apptypes = pset.ApplicableType.Split('/'); if (this.m_mapTree.TryGetValue(apptypes[0].ToLowerInvariant(), out tn)) { DocEntity entity = (DocEntity)tn.Tag; if (this.m_project.ModelViews.Count == 0) { // must have at least one model view for populating property set links this.m_project.ModelViews.Add(new DocModelView()); } foreach (DocModelView docView in this.m_project.ModelViews) { DocConceptRoot docRoot = null; foreach (DocConceptRoot eachRoot in docView.ConceptRoots) { if (eachRoot.ApplicableEntity == entity) { docRoot = eachRoot; break; } } if (docRoot == null) { docRoot = new DocConceptRoot(); docRoot.ApplicableEntity = entity; docView.ConceptRoots.Add(docRoot); } // find the pset template DocTemplateUsage templateuse = null; foreach (DocTemplateUsage eachtemplateuse in docRoot.Concepts) { if (eachtemplateuse.Definition != null && eachtemplateuse.Definition.Name.StartsWith("Property")) { templateuse = eachtemplateuse; break; } } DocTemplateDefinition docdefpset = this.m_project.GetTemplate(new Guid("f74255a6-0c0e-4f31-84ad-24981db62461")); if (docdefpset != null) { // if no template, add it if (templateuse == null) { // get the pset template templateuse = new DocTemplateUsage(); docRoot.Concepts.Add(templateuse); templateuse.Definition = docdefpset; } DocTemplateItem templateitem = new DocTemplateItem(); templateuse.Items.Add(templateitem); templateitem.RuleInstanceID = "IfcPropertySet"; if (apptypes.Length == 2) { templateitem.RuleParameters += "PredefinedType=" + apptypes[1] + ";"; } templateitem.RuleParameters += "Name=" + pset.Name + ";"; templateitem.RuleParameters += "TemplateType=" + pset.PropertySetType + ";"; // don't include documentation -- too wordy templateitem.Documentation = pset.Documentation; } } } else { sbErrors.Append(System.IO.Path.GetFileNameWithoutExtension(filename) + ": unrecognized ApplicableTypeValue; "); } } #endif } else { sbErrors.Append(System.IO.Path.GetFileNameWithoutExtension(filename) + ": unrecognized schema; "); } } } else if (filename.Contains("Qto_")) { using (FormatXML format = new FormatXML(filename, typeof(QtoSetDef))) { format.Load(); QtoSetDef qto = (QtoSetDef)format.Instance; string schema = qto.Versions[0].schema; TreeNode tn = null; if (schema != null && this.m_mapTree.TryGetValue(schema.ToLowerInvariant(), out tn)) { DocSchema docschema = (DocSchema)tn.Tag; // find existing pset if applicable DocQuantitySet qset = docschema.RegisterQset(qto.Name); // use hashed guid if (qset.Uuid == Guid.Empty) { System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create(); byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(qset.Name)); qset.Uuid = new Guid(hash); } // everything is currently named "Base Quantities"; get name from file instead; e.g. "Qto_Beam" qset.Name = System.IO.Path.GetFileNameWithoutExtension(filename); qset.Documentation = qto.Definition; qset.ApplicableType = qto.ApplicableClasses[0].Value; // fix: remove "Type" if (qset.ApplicableType.EndsWith("Type")) { qset.ApplicableType = qset.ApplicableType.Substring(0, qset.ApplicableType.Length - 4); } // import localized definitions if (qto.QtoDefinitionAliases != null) { foreach (QtoDefinitionAlias pl in qto.QtoDefinitionAliases) { qset.RegisterLocalization(pl.lang, null, pl.Value); } } foreach (QtoDef qtodef in qto.QtoDefs) { DocQuantity q = qset.RegisterQuantity(qtodef.Name); q.Documentation = qtodef.Definition; switch (qtodef.QtoType) { case "IfcQuantityCount": q.QuantityType = DocQuantityTemplateTypeEnum.Q_COUNT; break; case "IfcQuantityLength": q.QuantityType = DocQuantityTemplateTypeEnum.Q_LENGTH; break; case "IfcQuantityArea": q.QuantityType = DocQuantityTemplateTypeEnum.Q_AREA; break; case "IfcQuantityVolume": q.QuantityType = DocQuantityTemplateTypeEnum.Q_VOLUME; break; case "IfcQuantityWeight": q.QuantityType = DocQuantityTemplateTypeEnum.Q_WEIGHT; break; case "IfcQuantityTime": q.QuantityType = DocQuantityTemplateTypeEnum.Q_TIME; break; } foreach (NameAlias namealias in qtodef.NameAliases) { string desc = null; foreach (DefinitionAlias docalias in qtodef.DefinitionAliases) { if (docalias.lang.Equals(namealias.lang)) { desc = docalias.Value; break; } } q.RegisterLocalization(namealias.lang, namealias.Value, desc); } } // map to use definition if (this.m_mapTree.TryGetValue(qset.ApplicableType.ToLowerInvariant(), out tn)) { DocEntity entity = (DocEntity)tn.Tag; if (this.m_project.ModelViews.Count == 0) { // must have at least one model view for populating property set links this.m_project.ModelViews.Add(new DocModelView()); } foreach (DocModelView docView in this.m_project.ModelViews) { DocConceptRoot docRoot = null; foreach (DocConceptRoot eachRoot in docView.ConceptRoots) { if (eachRoot.ApplicableEntity == entity) { docRoot = eachRoot; break; } } if (docRoot == null) { docRoot = new DocConceptRoot(); docRoot.ApplicableEntity = entity; docView.ConceptRoots.Add(docRoot); } // find the qset template DocTemplateUsage templateuse = null; foreach (DocTemplateUsage eachtemplateuse in docRoot.Concepts) { if (eachtemplateuse.Definition.Name.StartsWith("Quantity")) { templateuse = eachtemplateuse; break; } } // if no template, add it if (templateuse == null) { // get the pset template templateuse = new DocTemplateUsage(); docRoot.Concepts.Add(templateuse); templateuse.Definition = this.m_project.GetTemplate(new Guid("6652398e-6579-4460-8cb4-26295acfacc7")); } if (templateuse != null) { DocTemplateItem templateitem = new DocTemplateItem(); templateuse.Items.Add(templateitem); templateitem.RuleInstanceID = "IfcElementQuantity"; templateitem.RuleParameters = "Name=" + qset.Name + ";TemplateType=QTO_OCCURRENCEDRIVEN;"; } } } } else { sbErrors.Append(System.IO.Path.GetFileNameWithoutExtension(filename) + ": unrecognized schema; "); } } } else if (filename.Contains("ifcXML")) { using (FormatXML format = new FormatXML(filename, typeof(configuration), null, SchemaCNF.Prefixes)) { try { this.m_loading = true; // prevent constructors from registering instances (xml serializer instantiates) format.Load(); DocModelView docView = null; using(FormSelectView form = new FormSelectView(this.m_project, null)) { if(form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && form.Selection != null && form.Selection.Length == 1) { docView = form.Selection[0]; } } configuration cnf = (configuration)format.Instance; Program.ImportCnf(cnf, this.m_project, docView); } catch (Exception xx) { MessageBox.Show(this, xx.Message, "Import CNFXML"); } finally { this.m_loading = false; } } } break; case ".mvdxml": this.ImportMVD(filename); break; case ".txt": using (FormatCSV format = new FormatCSV(filename)) { try { format.Instance = this.m_project; format.Load(); } catch (System.Exception xx) { MessageBox.Show(this, xx.Message, "Import CSV"); } } break; case ".ifd": using (FormatIFD format = new FormatIFD(filename)) { try { format.Instance = this.m_project; format.Load(); } catch (System.Exception xx) { MessageBox.Show(this, xx.Message, "Import IFD"); } } break; case ".xsd": using (FormatXML format = new FormatXML(filename, typeof(IfcDoc.Schema.XSD.schema), IfcDoc.Schema.XSD.SchemaXsd.DefaultNamespace)) { try { format.Load(); DocSchema docSchema = Program.ImportXsd((IfcDoc.Schema.XSD.schema)format.Instance, this.m_project); if(docSchema.Name == null) { docSchema.Name = System.IO.Path.GetFileNameWithoutExtension(filename); } } catch(System.Exception xx) { MessageBox.Show(this, xx.Message, "Import XSD"); } } break; } } // load tree before generating use definitions this.LoadTree(); // load tree again to pick up definitions if (importedschemas.Count > 0) { LoadTree(); } } if (sbErrors.Length > 0) { MessageBox.Show(this, "Import succeeded, however one or more definitions have missing or incorrect information:\r\n" + sbErrors.ToString(), "Import Errors"); } }
internal static void ExportMvdConceptRoot(ConceptRoot mvdConceptRoot, DocConceptRoot docRoot, bool documentation) { ExportMvdObject(mvdConceptRoot, docRoot, documentation); if (String.IsNullOrEmpty(mvdConceptRoot.Name)) { mvdConceptRoot.Name = docRoot.ApplicableEntity.Name; } mvdConceptRoot.ApplicableRootEntity = docRoot.ApplicableEntity.Name; if (docRoot.ApplicableTemplate != null) { mvdConceptRoot.Applicability = new ApplicabilityRules(); mvdConceptRoot.Applicability.Template = new TemplateRef(); mvdConceptRoot.Applicability.Template.Ref = docRoot.ApplicableTemplate.Uuid; mvdConceptRoot.Applicability.TemplateRules = new TemplateRules(); mvdConceptRoot.Applicability.TemplateRules.Operator = (TemplateOperator)Enum.Parse(typeof(TemplateOperator), docRoot.ApplicableOperator.ToString()); foreach (DocTemplateItem docItem in docRoot.ApplicableItems) { TemplateRule rule = ExportMvdItem(docItem); mvdConceptRoot.Applicability.TemplateRules.TemplateRule.Add(rule); } } foreach (DocTemplateUsage docTemplateUsage in docRoot.Concepts) { Concept mvdConceptLeaf = new Concept(); mvdConceptRoot.Concepts.Add(mvdConceptLeaf); ExportMvdConcept(mvdConceptLeaf, docTemplateUsage, documentation); } }
public CheckGridEntity(DocConceptRoot docRoot, DocModelView docView, DocProject docProject, Dictionary<string, DocObject> map) { this.m_root = docRoot; this.m_view = docView; this.m_project = docProject; this.m_listTemplate = new List<DocTemplateDefinition>(); List<DocTemplateDefinition> listTemplate = docProject.GetTemplateList(); //... filter out templates to only those that apply to entity... foreach (DocTemplateDefinition docTemplate in listTemplate) { if (docTemplate.Rules != null && docTemplate.Rules.Count > 0) // don't include abstract/organizational templates { bool include = false; // check for inheritance DocObject docApplicableEntity = null; if (docTemplate.Type != null && map.TryGetValue(docTemplate.Type, out docApplicableEntity) && docApplicableEntity is DocEntity) { // check for inheritance DocEntity docBase = docRoot.ApplicableEntity; while (docBase != null) { if (docBase == docApplicableEntity) { include = true; break; } if (docBase.BaseDefinition == null) break; DocObject docEach = null; if (map.TryGetValue(docBase.BaseDefinition, out docEach)) { docBase = (DocEntity)docEach; } else { docBase = null; } } } if (include) { this.m_listTemplate.Add(docTemplate); } } } }
private void LoadFile(string filename) { this.SetCurrentFile(filename); this.m_lastid = 0; this.m_instances.Clear(); this.m_mapTree.Clear(); this.m_clipboard = null; this.m_project = null; string ext = System.IO.Path.GetExtension(this.m_file).ToLower(); try { switch (ext) { case ".ifcdoc": using (FormatSPF format = new FormatSPF(this.m_file, SchemaDOC.Types, this.m_instances)) { format.Load(); } break; case ".mdb": using (FormatMDB format = new FormatMDB(this.m_file, SchemaDOC.Types, this.m_instances)) { format.Load(); } break; } } catch (Exception x) { MessageBox.Show(this, x.Message, "Error", MessageBoxButtons.OK); // force new as state is now invalid this.m_modified = false; this.toolStripMenuItemFileNew_Click(this, EventArgs.Empty); return; } List<SEntity> listDelete = new List<SEntity>(); List<DocTemplateDefinition> listTemplate = new List<DocTemplateDefinition>(); // get the project, determine the next OID to use foreach (SEntity o in this.m_instances.Values) { if (o is DocProject) { this.m_project = (DocProject)o; } else if (o is DocEntity) { DocEntity docent = (DocEntity)o; #if false // files before V5.3 had Description field; no longer needed so use regular Documentation field again. if (docent._Description != null) { docent.Documentation = docent._Description; docent._Description = null; } #endif } else if(o is DocAttribute) { #if false // files before V8.7 didn't have nullable tagless DocAttribute docAttr = (DocAttribute)o; if (docAttr.XsdTagless == false) { docAttr.XsdTagless = null; } #endif } else if (o is DocExchangeDefinition) { // files before V4.9 had Description field; no longer needed so use regular Documentation field again. DocExchangeDefinition docexchange = (DocExchangeDefinition)o; if (docexchange._Description != null) { docexchange.Documentation = docexchange._Description; docexchange._Description = null; } } else if (o is DocTemplateDefinition) { // files before V5.0 had Description field; no longer needed so use regular Documentation field again. DocTemplateDefinition doctemplate = (DocTemplateDefinition)o; if (doctemplate._Description != null) { doctemplate.Documentation = doctemplate._Description; doctemplate._Description = null; } listTemplate.Add((DocTemplateDefinition)o); } // ensure all objects have valid guid if (o is DocObject) { DocObject docobj = (DocObject)o; if (docobj.Uuid == Guid.Empty) { docobj.Uuid = Guid.NewGuid(); } #if false // ensure any image references are in lowercase if(docobj.Documentation != null && docobj.Documentation.Length > 0) { int i = 0; while (i != -1) { i = docobj.Documentation.IndexOf("../figures/", i + 1); if(i != -1) { int start = i + 11; int end = docobj.Documentation.IndexOf('"', start); if(end > start) { string strold = docobj.Documentation.Substring(start, end - start); string strnew = strold.ToLower(); docobj.Documentation = docobj.Documentation.Substring(0, start) + strnew + docobj.Documentation.Substring(end); System.Diagnostics.Debug.WriteLine(strnew); } } } } #endif } if (o.OID > this.m_lastid) { this.m_lastid = o.OID; } } if (this.m_project == null) { MessageBox.Show(this, "File is invalid; no project is defined.", "Error", MessageBoxButtons.OK); return; } // now capture any template definitions (upgrade in V3.5) foreach (DocModelView docModelView in this.m_project.ModelViews) { if (docModelView.ConceptRoots == null) { // must convert to new format docModelView.ConceptRoots = new List<DocConceptRoot>(); foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocEntity docEntity in docSchema.Entities) { if (docEntity.__Templates != null) { foreach (DocTemplateUsage docTemplateUsage in docEntity.__Templates) { // must generate or use existing concept root DocConceptRoot docConceptRoot = null; foreach (DocConceptRoot eachConceptRoot in docModelView.ConceptRoots) { if (eachConceptRoot.ApplicableEntity == docEntity) { docConceptRoot = eachConceptRoot; break; } } if (docConceptRoot == null) { docConceptRoot = new DocConceptRoot(); docConceptRoot.ApplicableEntity = docEntity; docModelView.ConceptRoots.Add(docConceptRoot); } docConceptRoot.Concepts.Add(docTemplateUsage); } } } } } } } #if false // temp fixup foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { //docSchema.PropertyEnums.Sort(); foreach (DocPropertyEnumeration docEnum in docSchema.PropertyEnums) { foreach(DocPropertyConstant docConst in docEnum.Constants) { docConst.Name = docConst.Name.ToUpper(); // ensure uppercase throughout switch(docConst.Name) { case "OTHER": docConst.RegisterLocalization("en", "(other)", "Value is not listed."); break; case "NOTKNOWN": docConst.RegisterLocalization("en", "(unknown)", "Value is unknown."); break; case "UNSET": docConst.RegisterLocalization("en", "(unset)", "Value has not been specified."); break; } } } } } #endif #if false // ensure property enumerations are defined (upgrade to V5.8) and provide localizations Dictionary<string, DocPropertyEnumeration> mapEnums = new Dictionary<string, DocPropertyEnumeration>(); foreach(DocSection docSection in this.m_project.Sections) { foreach(DocSchema docSchema in docSection.Schemas) { foreach(DocType docType in docSchema.Types) { EnsureLocalized(docType); } foreach(DocEntity docEntity in docSchema.Entities) { EnsureLocalized(docEntity); } foreach(DocFunction docFunction in docSchema.Functions) { EnsureLocalized(docFunction); } foreach(DocGlobalRule docRule in docSchema.GlobalRules) { EnsureLocalized(docRule); } foreach(DocPropertySet docPset in docSchema.PropertySets) { EnsureLocalized(docPset); foreach(DocProperty docProp in docPset.Properties) { EnsureLocalized(docProp); if (docProp.PropertyType == DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE) { // temporary migration string match = "PEnum_Status:"; if (docProp.SecondaryDataType.StartsWith(match)) { docProp.SecondaryDataType = "PEnum_ElementStatus:" + docProp.SecondaryDataType.Substring(match.Length); } string[] enumhost = docProp.SecondaryDataType.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (enumhost.Length == 2) { string enumname = enumhost[0]; DocPropertyEnumeration docEnum = null; if (docProp.PrimaryDataType != null && !mapEnums.TryGetValue(enumname, out docEnum)) { docEnum = new DocPropertyEnumeration(); docEnum.Name = enumname; docSchema.PropertyEnums.Add(docEnum); mapEnums.Add(docEnum.Name, docEnum); string[] enumvals = enumhost[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string val in enumvals) { DocPropertyConstant docConstant = new DocPropertyConstant(); docConstant.Name = val; docEnum.Constants.Add(docConstant); // localize constant StringBuilder sb = new StringBuilder(); // if constant is entirely uppercase, then convert such that only first character is uppercase for (int i = 0; i < val.Length; i++ ) { char ch = val[i]; if (ch == '_') { ch = ' '; } else if (Char.IsUpper(ch) && i > 0 && !Char.IsUpper(val[i - 1])) { sb.Append(" "); } else if(Char.IsUpper(ch) && i > 0 && Char.IsUpper(val[i-1])) { ch = Char.ToLower(ch); } sb.Append(ch); } // find description for constant string doc = null; int iDoc = docProp.Documentation.IndexOf(docConstant.Name + ":"); if(iDoc > 0) { int iTail = docProp.Documentation.IndexOfAny(new char[] { '.', ';', '\r', '\n'}, iDoc+1); if (iTail == -1) { iTail = docProp.Documentation.Length; } doc = docProp.Documentation.Substring(iDoc + docConstant.Name.Length + 2, iTail - iDoc - docConstant.Name.Length - 2); } docConstant.RegisterLocalization("en", sb.ToString(), doc); } } } } } } foreach(DocQuantitySet docQset in docSchema.QuantitySets) { EnsureLocalized(docQset); foreach(DocQuantity docQuantiy in docQset.Quantities) { EnsureLocalized(docQuantiy); } } } } #endif #if false // temp: garbage collection for files that didn't clean up properly StringBuilder sb = new StringBuilder(); this.m_project.Mark(); List<SEntity> collect = new List<SEntity>(); foreach (SEntity o in this.m_instances.Values) { if(!o.Existing) { collect.Add(o); } } for (int i = collect.Count - 1; i >= 0; i--) { SEntity ent = collect[i]; if(!ent.Existing) { sb.AppendLine("#" + ent.OID + "=" + ent.GetType().Name + ";"); this.m_instances.Remove(ent.OID); } } string sss = sb.ToString(); #endif // now clear out the lists going forward. LoadTree(); }
/// <summary> /// /// </summary> /// <param name="docProject"></param> /// <param name="docModelView"></param> /// <param name="entity"></param> /// <param name="root"></param> /// <param name="usage">Optional usage or NULL to format table from concept root applicability</param> /// <param name="mapEntity"></param> /// <param name="mapSchema"></param> /// <returns></returns> private static string FormatConceptTable( DocProject docProject, DocModelView docModelView, DocEntity entity, DocConceptRoot root, DocTemplateUsage usage, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema) { StringBuilder sb = new StringBuilder(); DocTemplateDefinition docTemplate = null; DocTemplateItem[] listItems = null; if (usage != null) { docTemplate = usage.Definition; listItems = FindTemplateItems(docProject, entity, usage.Definition, docModelView); if (usage.Override) { listItems = usage.Items.ToArray(); } if (listItems.Length == 0) { // scenario for referenced inner templates listItems = usage.Items.ToArray(); } } else { docTemplate = root.ApplicableTemplate; listItems = root.ApplicableItems.ToArray(); } // new way with table DocModelRule[] parameters = docTemplate.GetParameterRules(); if (parameters != null && parameters.Length > 0 && listItems.Length > 0) { // check if descriptions are provided bool showdescriptions = false; foreach (DocTemplateItem item in listItems) { if (item.Documentation != null) { showdescriptions = true; break; } } sb.AppendLine("<table class=\"gridtable\">"); // header sb.Append("<tr>"); foreach (DocModelRule parameter in parameters) { sb.Append("<th><b>"); // hack until fixed in data if (parameter.Identification.Equals("Name") && docTemplate.Name.Equals("External Data Constraints")) { sb.Append("Column"); } else { sb.Append(parameter.Identification); } sb.Append("</b></th>"); } if (showdescriptions) { sb.Append("<th><b>Description</b></th>"); } sb.AppendLine("</tr>"); // items foreach (DocTemplateItem item in listItems) { sb.Append("<tr>"); foreach (DocModelRule parameter in parameters) { string value = item.GetParameterValue(parameter.Identification); string schema = null; if(parameter.Name.Equals("Columns")) { parameter.ToString(); } sb.Append("<td>"); //if (value != null) { DocDefinition docDef = docTemplate.GetParameterType(parameter.Identification, mapEntity); if (docDef is DocEnumeration) { if(value != null) { schema = mapSchema[docDef.Name]; sb.Append("<a href=\"../../"); sb.Append(schema.ToLower()); sb.Append("/lexical/"); sb.Append(docDef.Name.ToLower()); sb.Append(".htm\">"); sb.Append(value); sb.Append("</a>"); } } else if (docDef is DocEntity) { DocTemplateDefinition docTemplateInner = null; if (parameter is DocModelRuleAttribute) { DocModelRuleAttribute dma = (DocModelRuleAttribute)parameter; foreach(DocModelRule docInnerRule in dma.Rules) { if (docInnerRule is DocModelRuleEntity) { DocModelRuleEntity dme = (DocModelRuleEntity)docInnerRule; if (dme.References.Count == 1) { docTemplateInner = dme.References[0]; DocTemplateUsage docConceptInner = item.GetParameterConcept(parameter.Identification, docTemplateInner); if (docConceptInner != null) { string inner = FormatConceptTable(docProject, docModelView, (DocEntity)docDef, root, docConceptInner, mapEntity, mapSchema); sb.Append("<a href=\"../../templates/" + MakeLinkName(docTemplateInner) + ".htm\">" + docTemplateInner.Name + "</a><br/>"); sb.Append(inner); } } } } } if (docTemplateInner == null && value != null && mapSchema.TryGetValue(value, out schema)) { if(value.StartsWith("Pset_")) { value.ToString(); } sb.Append("<a href=\"../../"); sb.Append(schema.ToLower()); sb.Append("/lexical/"); sb.Append(value.ToLower()); sb.Append(".htm\">"); sb.Append(value); sb.Append("</a>"); } else if(docDef.Name.Equals("IfcReference")) { // ...hyperlinks if(value != null) { string reftext = FormatReference(docProject, value); sb.Append(reftext); } //sb.Append(value); } else if(value != null) { sb.Append(value); } } else if (docDef != null && value != null) { value = FormatField(docProject, value, value, docDef.Name, value); sb.Append(value); } else if (value != null) { sb.Append(value); } else { sb.Append(" "); } } sb.Append("</td>"); } if (showdescriptions) { sb.Append("<td>"); if (item.Documentation != null) { sb.Append(item.Documentation); } else { sb.Append(" "); } sb.Append("</td>"); } sb.AppendLine("</tr>"); } sb.AppendLine("</table>"); } return sb.ToString(); }
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; }
private void buildFromSubschemaToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult res = this.openFileDialogExpress.ShowDialog(); if (res != System.Windows.Forms.DialogResult.OK) return; DocModelView docView = (DocModelView)this.treeView.SelectedNode.Tag; // for now, we don't actually import EXPRESS, we just do dumb lookup of strings to see if they are included in model view using (System.IO.StreamReader reader = new System.IO.StreamReader(this.openFileDialogExpress.FileName)) { string express = reader.ReadToEnd(); foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocEntity docEntity in docSchema.Entities) { string search1 = "ENTITY " + docEntity.Name + ";"; string search2 = "ENTITY " + docEntity.Name + "\r\n"; if (express.Contains(search1) || express.Contains(search2)) { // check for existing DocConceptRoot root = null; foreach (DocConceptRoot exist in docView.ConceptRoots) { if (exist.ApplicableEntity == docEntity) { root = exist; break; } } if (root == null) { root = new DocConceptRoot(); root.ApplicableEntity = docEntity; docView.ConceptRoots.Add(root); } } } } } } this.LoadTree(); }
private void toolStripMenuItemInsertConceptRoot_Click(object sender, EventArgs e) { DocEntity docEntity = (DocEntity)this.treeView.SelectedNode.Tag; // pick the model view definition using (FormSelectView form = new FormSelectView(this.m_project, null)) { if (form.ShowDialog(this) == DialogResult.OK && form.Selection != null && form.Selection.Length == 1) { DocModelView docView = form.Selection[0]; DocConceptRoot docConceptRoot = new DocConceptRoot(); docConceptRoot.ApplicableEntity = docEntity; docView.ConceptRoots.Add(docConceptRoot); // update tree this.treeView.SelectedNode = this.LoadNode(this.treeView.SelectedNode, docConceptRoot, docView.Name, false); } } }
private void BuildConceptForPropertySets(DocConceptRoot docRoot, DocTemplateDefinition docTemplatePset, DocPropertySet[] psets) { DocTemplateUsage docConcept = null; // get any existing concept for psets foreach (DocTemplateUsage docExistConcept in docRoot.Concepts) { if (docExistConcept.Definition == docTemplatePset) { docConcept = docExistConcept; break; } } if (psets.Length > 0) { if (docConcept == null) { docConcept = new DocTemplateUsage(); docConcept.Definition = docTemplatePset; docRoot.Concepts.Add(docConcept); LoadNode(this.treeView.SelectedNode, docConcept, docConcept.ToString(), false); } // remove old listings for (int iExist = docConcept.Items.Count - 1; iExist >= 0; iExist--) { docConcept.Items[iExist].Delete(); docConcept.Items.RemoveAt(iExist); } foreach (DocPropertySet docPset in psets) { //if (docPset.PropertySetType == "PSET_OCCURRENCEDRIVEN" || // docPset.PropertySetType == "PSET_TYPEDRIVENOVERRIDE") { // add new, in order DocTemplateItem docItemPset = new DocTemplateItem(); docItemPset.RuleParameters = "Name=" + docPset.Name + ";"; docConcept.Items.Add(docItemPset); //... predefined type //... properties... int order = 0; foreach (DocProperty docProp in docPset.Properties) { DocTemplateDefinition docInnerTemplate = null; string suffix = String.Empty; switch (docProp.PropertyType) { case DocPropertyTemplateTypeEnum.P_SINGLEVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("6655f6d0-29a8-47b8-8f3d-c9fce9c9a620")); break; case DocPropertyTemplateTypeEnum.P_BOUNDEDVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("3d67a2d2-761d-44d9-a09e-b7fbb1fa5632")); break; case DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("c148a099-c351-43a8-9266-5f3de0b45a95")); suffix = "Reference=" + docProp.SecondaryDataType.Substring(0, docProp.SecondaryDataType.IndexOf(':')); break; case DocPropertyTemplateTypeEnum.P_LISTVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("8e10b688-9179-4e3a-8db2-6abcaafe952d")); break; case DocPropertyTemplateTypeEnum.P_TABLEVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("35c947b0-6abc-4b13-8ec7-696ef2041721")); suffix = "Reference=" + docProp.SecondaryDataType; break; case DocPropertyTemplateTypeEnum.P_REFERENCEVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("e20bc116-889b-46cc-b193-31b3e2376a8e")); suffix = "Reference=" + docProp.SecondaryDataType; break; } if (docInnerTemplate != null) { order++; DocTemplateUsage docInnerConcept = docItemPset.RegisterParameterConcept("Properties", docInnerTemplate); DocTemplateItem docInnerItem = new DocTemplateItem(); docInnerItem.RuleParameters = "Order=" + order + ";Name=" + docProp.Name + ";Value=" + docProp.PrimaryDataType + ";" + suffix; docInnerConcept.Items.Add(docInnerItem); } } } } } }
public static DocProject LoadFile(string filePath) { List <object> instances = new List <object>(); string ext = System.IO.Path.GetExtension(filePath).ToLower(); string schema = ""; DocProject project = null; switch (ext) { case ".ifcdoc": using (FileStream streamDoc = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { Dictionary <long, object> dictionaryInstances = null; StepSerializer formatDoc = new StepSerializer(typeof(DocProject), SchemaDOC.Types); project = (DocProject)formatDoc.ReadObject(streamDoc, out dictionaryInstances); instances.AddRange(dictionaryInstances.Values); schema = formatDoc.Schema; } break; case ".ifcdocxml": using (FileStream streamDoc = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { Dictionary <string, object> dictionaryInstances = null; XmlSerializer formatDoc = new XmlSerializer(typeof(DocProject)); project = (DocProject)formatDoc.ReadObject(streamDoc, out dictionaryInstances); instances.AddRange(dictionaryInstances.Values); } break; default: MessageBox.Show("Unsupported file type " + ext, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; #if MDB case ".mdb": using (FormatMDB format = new FormatMDB(this.m_file, SchemaDOC.Types, this.m_instances)) { format.Load(); } break; #endif } if (project == null) { return(null); } double schemaVersion = 0; if (!string.IsNullOrEmpty(schema)) { string[] fields = schema.Split("_".ToCharArray()); int i = 0; if (fields.Length > 1) { if (int.TryParse(fields[1], out i)) { schemaVersion = i; } if (fields.Length > 2 && int.TryParse(fields[2], out i)) { schemaVersion += i / 10.0; } } } List <SEntity> listDelete = new List <SEntity>(); List <DocTemplateDefinition> listTemplate = new List <DocTemplateDefinition>(); foreach (object o in instances) { if (o is DocSchema) { DocSchema docSchema = (DocSchema)o; // renumber page references foreach (DocPageTarget docTarget in docSchema.PageTargets) { if (docTarget.Definition != null) // fix it up -- NULL bug from older .ifcdoc files { int page = docSchema.GetDefinitionPageNumber(docTarget); int item = docSchema.GetPageTargetItemNumber(docTarget); docTarget.Name = page + "," + item + " " + docTarget.Definition.Name; foreach (DocPageSource docSource in docTarget.Sources) { docSource.Name = docTarget.Name; } } } } else if (o is DocExchangeDefinition) { // files before V4.9 had Description field; no longer needed so use regular Documentation field again. DocExchangeDefinition docexchange = (DocExchangeDefinition)o; if (docexchange._Description != null) { docexchange.Documentation = docexchange._Description; docexchange._Description = null; } } else if (o is DocTemplateDefinition) { // files before V5.0 had Description field; no longer needed so use regular Documentation field again. DocTemplateDefinition doctemplate = (DocTemplateDefinition)o; if (doctemplate._Description != null) { doctemplate.Documentation = doctemplate._Description; doctemplate._Description = null; } listTemplate.Add((DocTemplateDefinition)o); } else if (o is DocConceptRoot) { // V12.0: ensure template is defined DocConceptRoot docConcRoot = (DocConceptRoot)o; if (docConcRoot.ApplicableTemplate == null && docConcRoot.ApplicableEntity != null) { docConcRoot.ApplicableTemplate = new DocTemplateDefinition(); docConcRoot.ApplicableTemplate.Type = docConcRoot.ApplicableEntity.Name; } } else if (o is DocTemplateUsage) { // V12.0: ensure template is defined DocTemplateUsage docUsage = (DocTemplateUsage)o; if (docUsage.Definition == null) { docUsage.Definition = new DocTemplateDefinition(); } } else if (o is DocLocalization) { DocLocalization localization = o as DocLocalization; if (!string.IsNullOrEmpty(localization.Name)) { localization.Name = localization.Name.Trim(); } } // ensure all objects have valid guid DocObject docObject = o as DocObject; if (docObject != null) { if (docObject.Uuid == Guid.Empty) { docObject.Uuid = Guid.NewGuid(); } if (!string.IsNullOrEmpty(docObject.Documentation)) { docObject.Documentation = docObject.Documentation.Trim(); } if (schemaVersion < 12.1) { DocChangeSet docChangeSet = docObject as DocChangeSet; if (docChangeSet != null) { docChangeSet.ChangesEntities.RemoveAll(x => !isUnchanged(x)); } else { if (schemaVersion < 12) { DocEntity entity = docObject as DocEntity; if (entity != null) { entity.ClearDefaultMember(); } } } } } } if (project == null) { return(null); } if (schemaVersion > 0 && schemaVersion < 12.1) { Dictionary <string, DocPropertyEnumeration> encounteredPropertyEnumerations = new Dictionary <string, DocPropertyEnumeration>(); foreach (DocSchema docSchema in project.Sections.SelectMany(x => x.Schemas)) { extractListingsV12_1(project, docSchema, encounteredPropertyEnumerations); } } foreach (DocModelView docModelView in project.ModelViews) { // sort alphabetically (V11.3+) docModelView.SortConceptRoots(); } // upgrade to Publications (V9.6) if (project.Annotations.Count == 4) { project.Publications.Clear(); DocAnnotation docCover = project.Annotations[0]; DocAnnotation docContents = project.Annotations[1]; DocAnnotation docForeword = project.Annotations[2]; DocAnnotation docIntro = project.Annotations[3]; DocPublication docPub = new DocPublication(); docPub.Name = "Default"; docPub.Documentation = docCover.Documentation; docPub.Owner = docCover.Owner; docPub.Author = docCover.Author; docPub.Code = docCover.Code; docPub.Copyright = docCover.Copyright; docPub.Status = docCover.Status; docPub.Version = docCover.Version; docPub.Annotations.Add(docForeword); docPub.Annotations.Add(docIntro); project.Publications.Add(docPub); docCover.Delete(); docContents.Delete(); project.Annotations.Clear(); } project.SortProject(); return(project); }
/// <summary> /// /// </summary> /// <param name="docProject"></param> /// <param name="docModelView"></param> /// <param name="entity"></param> /// <param name="root"></param> /// <param name="usage">Optional usage or NULL to format table from concept root applicability</param> /// <param name="mapEntity"></param> /// <param name="mapSchema"></param> /// <returns></returns> private static string FormatConceptTable( DocProject docProject, DocModelView docModelView, DocEntity entity, DocConceptRoot root, DocTemplateUsage usage, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema) { StringBuilder sb = new StringBuilder(); DocTemplateDefinition docTemplate = null; DocTemplateItem[] listItems = null; if (usage != null) { docTemplate = usage.Definition; listItems = FindTemplateItems(docProject, entity, usage.Definition, docModelView); if (usage.Override) { listItems = usage.Items.ToArray(); } if (listItems.Length == 0) { // scenario for referenced inner templates listItems = usage.Items.ToArray(); } } else { docTemplate = root.ApplicableTemplate; listItems = root.ApplicableItems.ToArray(); } // new way with table DocModelRule[] parameters = docTemplate.GetParameterRules(); if (parameters != null && parameters.Length > 0 && listItems.Length > 0) { // check if descriptions are provided bool showdescriptions = false; foreach (DocTemplateItem item in listItems) { if (item.Documentation != null) { showdescriptions = true; break; } } sb.AppendLine("<table class=\"gridtable\">"); // header sb.Append("<tr>"); foreach (DocModelRule parameter in parameters) { sb.Append("<th><b>"); // hack until fixed in data if (parameter.Identification.Equals("Name") && docTemplate.Name.Equals("External Data Constraints")) { sb.Append("Column"); } else { sb.Append(parameter.Identification); } sb.Append("</b></th>"); } if (showdescriptions) { sb.Append("<th><b>Description</b></th>"); } sb.AppendLine("</tr>"); // items foreach (DocTemplateItem item in listItems) { sb.Append("<tr>"); foreach (DocModelRule parameter in parameters) { string value = item.GetParameterValue(parameter.Identification); string schema = null; sb.Append("<td>"); //if (value != null) { DocDefinition docDef = docTemplate.GetParameterType(parameter.Identification, mapEntity); if (docDef is DocEnumeration) { if(value != null) { schema = mapSchema[docDef.Name]; sb.Append("<a href=\"../../"); sb.Append(schema.ToLower()); sb.Append("/lexical/"); sb.Append(docDef.Name.ToLower()); sb.Append(".htm\">"); sb.Append(value); sb.Append("</a>"); } } else if (docDef is DocEntity && docDef.Name.Equals("IfcReference")) { // ...hyperlinks if (value != null) { string reftext = FormatReference(docProject, value); sb.Append(reftext); } //sb.Append(value); } else if (docDef is DocEntity) { DocTemplateDefinition docTemplateInner = null; if (parameter is DocModelRuleAttribute) { List<string> cols = new List<string>(); List<DocTemplateItem> rows = new List<DocTemplateItem>(); List<DocTemplateUsage> usages = new List<DocTemplateUsage>(); DocModelRuleAttribute dma = (DocModelRuleAttribute)parameter; foreach(DocModelRule docInnerRule in dma.Rules) { if (docInnerRule is DocModelRuleEntity) { DocModelRuleEntity dme = (DocModelRuleEntity)docInnerRule; if (dme.References.Count == 1) { docTemplateInner = dme.References[0]; // new: combine nested tables -- properties are shown together DocTemplateUsage docConceptInner = item.GetParameterConcept(parameter.Identification, docTemplateInner); if (docConceptInner != null) { DocModelRule[] innerparameters = docTemplateInner.GetParameterRules(); foreach (DocModelRule innerparam in innerparameters) { if (!cols.Contains(innerparam.Identification)) { cols.Add(innerparam.Identification); } } foreach(DocTemplateItem docItemInner in docConceptInner.Items) { string orderstr = docItemInner.GetParameterValue("Order"); int ordernum; if(!String.IsNullOrEmpty(orderstr) && Int32.TryParse(orderstr, out ordernum)) { while (rows.Count < ordernum) { rows.Add(null); usages.Add(null); } rows[ordernum - 1] = docItemInner; usages[ordernum - 1] = docConceptInner; } } } //break; /* DocTemplateUsage docConceptInner = item.GetParameterConcept(parameter.Identification, docTemplateInner); if (docConceptInner != null) { string inner = FormatConceptTable(docProject, docModelView, (DocEntity)docDef, root, docConceptInner, mapEntity, mapSchema); sb.Append("<a href=\"../../templates/" + MakeLinkName(docTemplateInner) + ".htm\">" + docTemplateInner.Name + "</a><br/>"); sb.Append(inner); } */ } } } if(rows.Count > 0) { sb.Append("<table class=\"gridtable\"><tr>"); sb.Append("<th>Template</th>"); foreach(string colname in cols) { sb.Append("<th>"); sb.Append(colname); sb.Append("</th>"); } sb.AppendLine("</tr>"); for (int iSubRow = 0; iSubRow < rows.Count; iSubRow++ ) { DocTemplateItem docItem = rows[iSubRow]; DocTemplateUsage docUsage = usages[iSubRow]; //todo: show template with link... define icon at template... if (docItem != null) { sb.Append("<tr>"); sb.Append("<td><a href=\"../../templates/"); sb.Append(MakeLinkName(docUsage.Definition)); sb.Append(".htm\">"); sb.Append(docUsage.Definition.Name); sb.Append("</a></td>"); foreach (string colname in cols) { string pval = docItem.GetParameterValue(colname); pval = FormatField(docProject, pval, pval, pval, pval); sb.Append("<td>"); sb.Append(pval); sb.Append("</td>"); } sb.AppendLine("</tr>"); } } sb.Append("</table>"); } } if (docTemplateInner == null && value != null && mapSchema.TryGetValue(value, out schema)) { sb.Append("<a href=\"../../"); sb.Append(schema.ToLower()); sb.Append("/lexical/"); sb.Append(value.ToLower()); sb.Append(".htm\">"); sb.Append(value); sb.Append("</a>"); } else if(value != null) { sb.Append(value); } } else if (docDef != null && value != null) { value = FormatField(docProject, value, value, docDef.Name, value); sb.Append(value); } else if (value != null) { sb.Append(value); } else { sb.Append(" "); } } sb.Append("</td>"); } if (showdescriptions) { sb.Append("<td>"); if (item.Documentation != null) { sb.Append(item.Documentation); } else { sb.Append(" "); } sb.Append("</td>"); } sb.AppendLine("</tr>"); } sb.AppendLine("</table>"); } return sb.ToString(); }
private void BuildConceptForPropertySets(DocConceptRoot docRoot, DocTemplateDefinition docTemplatePset, DocPropertySet[] psets) { DocTemplateUsage docConcept = null; // get any existing concept for psets foreach (DocTemplateUsage docExistConcept in docRoot.Concepts) { if (docExistConcept.Definition == docTemplatePset) { docConcept = docExistConcept; break; } } if (psets.Length > 0) { if (docConcept == null) { docConcept = new DocTemplateUsage(); docConcept.Definition = docTemplatePset; docRoot.Concepts.Add(docConcept); LoadNode(this.treeView.SelectedNode, docConcept, docConcept.Name, false); } // remove old listings for (int iExist = docConcept.Items.Count - 1; iExist >= 0; iExist--) { docConcept.Items[iExist].Delete(); docConcept.Items.RemoveAt(iExist); } foreach (DocPropertySet docPset in psets) { //if (docPset.PropertySetType == "PSET_OCCURRENCEDRIVEN" || // docPset.PropertySetType == "PSET_TYPEDRIVENOVERRIDE") { // add new, in order DocTemplateItem docItemPset = new DocTemplateItem(); docItemPset.RuleParameters = "Name=" + docPset.Name + ";"; docConcept.Items.Add(docItemPset); //... predefined type //... properties... foreach (DocProperty docProp in docPset.Properties) { DocTemplateDefinition docInnerTemplate = null; switch (docProp.PropertyType) { case DocPropertyTemplateTypeEnum.P_SINGLEVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("6655f6d0-29a8-47b8-8f3d-c9fce9c9a620")); break; case DocPropertyTemplateTypeEnum.P_BOUNDEDVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("3d67a2d2-761d-44d9-a09e-b7fbb1fa5632")); break; case DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("c148a099-c351-43a8-9266-5f3de0b45a95")); break; } if (docInnerTemplate != null) { DocTemplateUsage docInnerConcept = docItemPset.RegisterParameterConcept("Properties", docInnerTemplate); DocTemplateItem docInnerItem = new DocTemplateItem(); docInnerItem.RuleParameters = "Name=" + docProp.Name + ";Value=" + docProp.PrimaryDataType + ";"; docInnerConcept.Items.Add(docInnerItem); } } } } } }
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 } } } } }
public string FormatDataConcept(DocProject docProject, DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <string, Type> typemap, Dictionary <long, SEntity> instances, SEntity root, bool markup, DocModelView docView, DocConceptRoot docRoot, DocTemplateUsage docConcept) { StringBuilder sb = new StringBuilder(); string table = docConcept.Items[0].GetParameterValue("Table"); string query = docConcept.Items[0].GetParameterValue("Reference"); sb.AppendLine("<h4>" + docConcept.Name + "</h4>"); sb.AppendLine("<table class=\"gridtable\">"); List <string> colstyles = new List <string>(); List <string> colformat = new List <string>(); List <CvtValuePath> colmaps = new List <CvtValuePath>(); // generate header row sb.AppendLine("<tr>"); foreach (DocTemplateItem docItem in docConcept.Items) { string name = docItem.GetParameterValue("Name"); string disp = "#" + docItem.GetColor().ToArgb().ToString("X8"); //docItem.GetParameterValue("Color");docItem.GetParameterValue("Color"); string expr = docItem.GetParameterValue("Reference"); string form = docItem.GetParameterValue("Format"); string style = ""; if (!String.IsNullOrEmpty(disp)) { style = " style=\"background-color:" + disp + ";\""; } colstyles.Add(style); string format = ""; if (!String.IsNullOrEmpty(form)) { format = form; } colformat.Add(format); string desc = ""; CvtValuePath valpath = CvtValuePath.Parse(expr, map); colmaps.Add(valpath); if (valpath != null) { desc = /*valpath.GetDescription(map) + " " + */ valpath.ToString().Replace("\\", " "); } sb.Append("<th><a href=\"../../schema/views/" + DocumentationISO.MakeLinkName(docView) + "/" + DocumentationISO.MakeLinkName(docExchange) + ".htm#" + DocumentationISO.MakeLinkName(docConcept) + "\" title=\"" + desc + "\">"); sb.Append(name); sb.Append("</a></th>"); } ; sb.AppendLine("</tr>"); // generate data rows List <DocModelRule> trace = new List <DocModelRule>(); foreach (SEntity e in instances.Values) { string eachname = e.GetType().Name; if (docRoot.ApplicableEntity.IsInstanceOfType(e)) { bool includerow = true; // if root has more complex rules, check them if (docRoot.ApplicableTemplate != null && docRoot.ApplicableItems.Count > 0) { includerow = false; // must check1 foreach (DocTemplateItem docItem in docRoot.ApplicableItems) { foreach (DocModelRule rule in docRoot.ApplicableTemplate.Rules) { try { trace.Clear(); bool?result = rule.Validate(e, docItem, typemap, trace, e, null, null); if (result == true && docRoot.ApplicableOperator == DocTemplateOperator.Or) { includerow = true; break; } } catch { docRoot.ToString(); } } // don't yet support AND or other operators if (includerow) { break; } } } if (includerow) { StringBuilder sbRow = new StringBuilder(); sbRow.Append("<tr>"); int iCol = 0; foreach (DocTemplateItem docItem in docConcept.Items) { sbRow.Append("<td" + colstyles[iCol]); CvtValuePath valpath = colmaps[iCol]; string format = colformat[iCol]; iCol++; if (valpath != null) { string nn = docItem.GetParameterValue("Name"); 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 (!String.IsNullOrEmpty(format)) { if (format.Equals("Required") && value == null) { includerow = false; } } if (value != null) { FieldInfo fieldValue = value.GetType().GetField("Value"); if (fieldValue != null) { value = fieldValue.GetValue(value); } if (format != null && format.Equals("True") && (value == null || !value.ToString().Equals("True"))) { includerow = false; } if (value is Double) { sbRow.Append(" align=\"right\">"); sbRow.Append(((Double)value).ToString("N3")); } else if (value is List <Int64> ) { sbRow.Append(">"); // latitude or longitude List <Int64> intlist = (List <Int64>)value; if (intlist.Count >= 3) { sbRow.Append(intlist[0] + "° " + intlist[1] + "' " + intlist[2] + "\""); } } else if (value != null) { sbRow.Append(">"); sbRow.Append(value.ToString()); // todo: html-encode } } else { sbRow.Append(">"); sbRow.Append(" "); } } else { sbRow.Append(">"); } sbRow.Append("</td>"); } sbRow.AppendLine("</tr>"); if (includerow) { sb.Append(sbRow.ToString()); } } } } sb.AppendLine("</table>"); sb.AppendLine("<br/>"); return(sb.ToString()); }
private void LoadFile(string filename) { this.SetCurrentFile(filename); this.m_lastid = 0; this.m_instances.Clear(); this.m_mapTree.Clear(); this.m_clipboard = null; this.m_project = null; List<DocChangeAction> listChange = new List<DocChangeAction>(); //temp string ext = System.IO.Path.GetExtension(this.m_file).ToLower(); try { switch (ext) { case ".ifcdoc": using (FormatSPF format = new FormatSPF(this.m_file, SchemaDOC.Types, this.m_instances)) { format.Load(); } break; #if MDB case ".mdb": using (FormatMDB format = new FormatMDB(this.m_file, SchemaDOC.Types, this.m_instances)) { format.Load(); } break; #endif } } catch (Exception x) { MessageBox.Show(this, x.Message, "Error", MessageBoxButtons.OK); // force new as state is now invalid this.m_modified = false; this.toolStripMenuItemFileNew_Click(this, EventArgs.Empty); return; } List<SEntity> listDelete = new List<SEntity>(); List<DocTemplateDefinition> listTemplate = new List<DocTemplateDefinition>(); // get the project, determine the next OID to use foreach (SEntity o in this.m_instances.Values) { if (o is DocProject) { this.m_project = (DocProject)o; } else if (o is DocEntity) { DocEntity docent = (DocEntity)o; #if false // files before V5.3 had Description field; no longer needed so use regular Documentation field again. if (docent._Description != null) { docent.Documentation = docent._Description; docent._Description = null; } #endif } else if(o is DocAttribute) { #if false // files before V8.7 didn't have nullable tagless DocAttribute docAttr = (DocAttribute)o; if (docAttr.XsdTagless == false) { docAttr.XsdTagless = null; } #endif } else if(o is DocSchema) { DocSchema docSchema = (DocSchema)o; // renumber page references foreach (DocPageTarget docTarget in docSchema.PageTargets) { int page = docSchema.GetDefinitionPageNumber(docTarget); int item = docSchema.GetPageTargetItemNumber(docTarget); docTarget.Name = page + "," + item + " " + docTarget.Definition.Name; foreach(DocPageSource docSource in docTarget.Sources) { docSource.Name = docTarget.Name; } } } else if (o is DocExchangeDefinition) { // files before V4.9 had Description field; no longer needed so use regular Documentation field again. DocExchangeDefinition docexchange = (DocExchangeDefinition)o; if (docexchange._Description != null) { docexchange.Documentation = docexchange._Description; docexchange._Description = null; } } else if (o is DocTemplateDefinition) { // files before V5.0 had Description field; no longer needed so use regular Documentation field again. DocTemplateDefinition doctemplate = (DocTemplateDefinition)o; if (doctemplate._Description != null) { doctemplate.Documentation = doctemplate._Description; doctemplate._Description = null; } listTemplate.Add((DocTemplateDefinition)o); } else if(o is DocChangeAction) { // tempdebug -- delete old change actions -- need to clean up //o.Delete(); listChange.Add((DocChangeAction)o); } // ensure all objects have valid guid if (o is DocObject) { DocObject docobj = (DocObject)o; if (docobj.Uuid == Guid.Empty) { docobj.Uuid = Guid.NewGuid(); } #if false // ensure any image references are in lowercase if(docobj.Documentation != null && docobj.Documentation.Length > 0) { int i = 0; while (i != -1) { i = docobj.Documentation.IndexOf("../figures/", i + 1); if(i != -1) { int start = i + 11; int end = docobj.Documentation.IndexOf('"', start); if(end > start) { string strold = docobj.Documentation.Substring(start, end - start); string strnew = strold.ToLower(); docobj.Documentation = docobj.Documentation.Substring(0, start) + strnew + docobj.Documentation.Substring(end); System.Diagnostics.Debug.WriteLine(strnew); } } } } #endif } if (o.OID > this.m_lastid) { this.m_lastid = o.OID; } } if (this.m_project == null) { MessageBox.Show(this, "File is invalid; no project is defined.", "Error", MessageBoxButtons.OK); return; } //tempcleanip //for (int i = listChange.Count - 1; i >= 0;i-- ) { //listChange[i].Delete(); } // now capture any template definitions (upgrade in V3.5) foreach (DocModelView docModelView in this.m_project.ModelViews) { if (docModelView.ConceptRoots == null) { // must convert to new format docModelView.ConceptRoots = new List<DocConceptRoot>(); foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocEntity docEntity in docSchema.Entities) { if (docEntity.__Templates != null) { foreach (DocTemplateUsage docTemplateUsage in docEntity.__Templates) { // must generate or use existing concept root DocConceptRoot docConceptRoot = null; foreach (DocConceptRoot eachConceptRoot in docModelView.ConceptRoots) { if (eachConceptRoot.ApplicableEntity == docEntity) { docConceptRoot = eachConceptRoot; break; } } if (docConceptRoot == null) { docConceptRoot = new DocConceptRoot(); docConceptRoot.ApplicableEntity = docEntity; docModelView.ConceptRoots.Add(docConceptRoot); } docConceptRoot.Concepts.Add(docTemplateUsage); } } } } } } } // upgrade to Publications (V9.6) if (this.m_project.Annotations.Count == 4) { this.m_project.Publications.Clear(); DocAnnotation docCover = this.m_project.Annotations[0]; DocAnnotation docContents = this.m_project.Annotations[1]; DocAnnotation docForeword = this.m_project.Annotations[2]; DocAnnotation docIntro = this.m_project.Annotations[3]; DocPublication docPub = new DocPublication(); docPub.Name = "Default"; docPub.Documentation = docCover.Documentation; docPub.Owner = docCover.Owner; docPub.Author = docCover.Author; docPub.Code = docCover.Code; docPub.Copyright = docCover.Copyright; docPub.Status = docCover.Status; docPub.Version = docCover.Version; docPub.Annotations.Add(docForeword); docPub.Annotations.Add(docIntro); this.m_project.Publications.Add(docPub); docCover.Delete(); docContents.Delete(); this.m_project.Annotations.Clear(); } LoadTree(); }