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); }
private void MoveRule(int offset) { TreeNode tnSelect = this.treeViewTemplate.SelectedNode; TreeNode tnParent = tnSelect.Parent; DocModelRule ruleSelect = (DocModelRule)tnSelect.Tag; if (tnParent.Tag is DocModelRule) { DocModelRule ruleParent = (DocModelRule)tnParent.Tag; int index = ruleParent.Rules.IndexOf(ruleSelect); ruleParent.Rules.RemoveAt(index); index += offset; ruleParent.Rules.Insert(index, ruleSelect); tnSelect.Remove(); tnParent.Nodes.Insert(index, tnSelect); } else if (tnParent.Tag is DocTemplateDefinition) { DocTemplateDefinition ruleParent = (DocTemplateDefinition)tnParent.Tag; int index = ruleParent.Rules.IndexOf(ruleSelect); ruleParent.Rules.RemoveAt(index); index += offset; ruleParent.Rules.Insert(index, ruleSelect); tnSelect.Remove(); tnParent.Nodes.Insert(index, tnSelect); } this.treeViewTemplate.SelectedNode = tnSelect; }
private void LoadTemplate(TreeNode tnParent, DocTemplateDefinition template) { // add entity TreeNode tn = new TreeNode(); tn.Tag = template; tn.Text = template.Name; if (tnParent != null) { tnParent.Nodes.Add(tn); } else { this.treeView.Nodes.Add(tn); } if (this.m_selection == template) { this.treeView.SelectedNode = tn; } this.LoadTemplates(tn, template.Templates); /* * foreach (DocTemplateDefinition sub in template.Templates) * { * LoadTemplate(tn, sub); * }*/ }
public object GetObject(int row, int col) { if (row < 0 || row >= this.m_listTemplate.Count) { return(null); } if (col < 0 || col >= this.m_view.Exchanges.Count) { return(null); } DocTemplateDefinition docTemplate = this.m_listTemplate[row]; DocExchangeDefinition docExchange = this.m_view.Exchanges[col]; foreach (DocTemplateUsage docUsage in this.m_root.Concepts) { if (docUsage.Definition == docTemplate) { foreach (DocExchangeItem docItem in docUsage.Exchanges) { if (docItem.Exchange == docExchange && docItem.Applicability == DocExchangeApplicabilityEnum.Export) { return(docItem); } } } } return(CellValue.None); }
private void toolStripButtonConceptTemplate_Click(object sender, EventArgs e) { DocTemplateDefinition docTemplate = null; if (this.m_conceptleaf != null) { docTemplate = this.m_conceptleaf.Definition; } else { docTemplate = this.m_conceptroot.ApplicableTemplate; } using (FormSelectTemplate form = new FormSelectTemplate(docTemplate, this.m_project, this.m_conceptroot.ApplicableEntity)) { if (form.ShowDialog(this) == DialogResult.OK && form.SelectedTemplate != null) { if (this.m_conceptleaf != null) { this.m_conceptleaf.Definition = form.SelectedTemplate; this.m_conceptleaf.Items.Clear(); } else { this.m_conceptroot.ApplicableTemplate = form.SelectedTemplate; this.m_conceptroot.ApplicableItems.Clear(); } this.LoadUsage(); this.LoadInheritance(); } } }
public static CvtValuePath FromTemplateDefinition(DocTemplateDefinition dtd, DocProject docProject) { if (dtd.Rules.Count > 0 && dtd.Rules[0] is DocModelRuleAttribute) { DocModelRuleAttribute docRuleAtt = (DocModelRuleAttribute)dtd.Rules[0]; DocEntity docEnt = docProject.GetDefinition(dtd.Type) as DocEntity; if (docEnt != null) { CvtValuePath pathInner = null; if (docRuleAtt.Rules.Count > 0 && docRuleAtt.Rules[0] is DocModelRuleEntity) { pathInner = FromModelRule((DocModelRuleEntity)docRuleAtt.Rules[0], docProject); } DocAttribute docAtt = docEnt.ResolveAttribute(docRuleAtt.Name, docProject); string identifier = null; if (docRuleAtt.Name.Equals("IsDefinedBy")) { // hack for compat docRuleAtt.ToString(); // look for identifier if (docRuleAtt.Rules.Count > 0) { try { DocModelRuleConstraint docRuleIndexCon = (DocModelRuleConstraint)docRuleAtt.Rules[0].Rules[0].Rules[0].Rules[1].Rules[0].Rules[0]; if (docRuleIndexCon != null) { if (docRuleIndexCon.Expression is DocOpStatement) { DocOpStatement docOpStatement = (DocOpStatement)docRuleIndexCon.Expression; if (docOpStatement.Value != null) { identifier = docOpStatement.Value.ToString(); if (identifier.StartsWith("'") && identifier.EndsWith("'")) { identifier = identifier.Substring(1, identifier.Length - 2); } } } } } catch { } } } CvtValuePath pathRoot = new CvtValuePath(docEnt, docAtt, identifier, pathInner); return(pathRoot); } } return(null); }
private void treeView_AfterSelect(object sender, TreeViewEventArgs e) { DocTemplateDefinition dtd = (DocTemplateDefinition)this.treeView.SelectedNode.Tag; this.ctlConcept.Project = this.m_project; this.ctlConcept.Template = dtd; this.ctlConcept.Enabled = true; SetContent(dtd); }
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); }
public FormRule(DocModelRule rule, DocProject project, DocTemplateDefinition template) : this() { this.m_rule = rule; this.m_project = project; this.m_template = template; this.Text = this.m_rule.Name; this.textBoxIdentifier.Text = this.m_rule.Identification; this.textBoxIdentifier.Enabled = !String.IsNullOrEmpty(this.m_rule.Identification); if (String.IsNullOrEmpty(this.m_rule.Identification)) { this.comboBoxUsage.SelectedIndex = 0; } else if (this.m_rule.Description != null && this.m_rule.Description.Equals("*")) { // convention indicating filter this.comboBoxUsage.SelectedIndex = 1; } else { // indicates parameter constraint this.comboBoxUsage.SelectedIndex = 2; } if (rule is DocModelRuleEntity) { this.textBoxPrefix.Enabled = true; this.textBoxPrefix.Text = ((DocModelRuleEntity)rule).Prefix; } if (this.m_rule.CardinalityMin == 0 && this.m_rule.CardinalityMax == 0) { this.comboBoxCardinality.SelectedIndex = 0; } else if (this.m_rule.CardinalityMin == -1 && this.m_rule.CardinalityMax == -1) { this.comboBoxCardinality.SelectedIndex = 1; } else if (this.m_rule.CardinalityMin == 0 && this.m_rule.CardinalityMax == 1) { this.comboBoxCardinality.SelectedIndex = 2; } else if (this.m_rule.CardinalityMin == 1 && this.m_rule.CardinalityMax == 1) { this.comboBoxCardinality.SelectedIndex = 3; } else if (this.m_rule.CardinalityMin == 1 && this.m_rule.CardinalityMax == -1) { this.comboBoxCardinality.SelectedIndex = 4; } }
public DocTemplateDefinition ToTemplateDefinition() { DocTemplateDefinition docTemplate = new DocTemplateDefinition(); DocModelRuleEntity docRule = this.ToModelRule(); if (docRule != null && docRule.Rules.Count > 0 && docRule.Rules[0] is DocModelRuleAttribute) { DocModelRuleAttribute docRuleAttr = (DocModelRuleAttribute)docRule.Rules[0]; docTemplate.Type = docRule.Name; docTemplate.Rules.Add(docRuleAttr); docRuleAttr.ParentRule = null; } return(docTemplate); }
public FormRule(DocModelRule rule, DocProject project, DocTemplateDefinition template) : this() { this.m_rule = rule; this.m_project = project; this.m_template = template; this.Text = this.m_rule.Name; this.textBoxIdentifier.Text = this.m_rule.Identification; this.textBoxIdentifier.Enabled = !String.IsNullOrEmpty(this.m_rule.Identification); if (String.IsNullOrEmpty(this.m_rule.Identification)) { this.comboBoxUsage.SelectedIndex = 0; } else if (this.m_rule.Description != null && this.m_rule.Description.Equals("*")) { // convention indicating filter this.comboBoxUsage.SelectedIndex = 1; } else { // indicates parameter constraint this.comboBoxUsage.SelectedIndex = 2; } if (this.m_rule.CardinalityMin == 0 && this.m_rule.CardinalityMax == 0) { this.comboBoxCardinality.SelectedIndex = 0; } else if (this.m_rule.CardinalityMin == -1 && this.m_rule.CardinalityMax == -1) { this.comboBoxCardinality.SelectedIndex = 1; } else if (this.m_rule.CardinalityMin == 0 && this.m_rule.CardinalityMax == 1) { this.comboBoxCardinality.SelectedIndex = 2; } else if (this.m_rule.CardinalityMin == 1 && this.m_rule.CardinalityMax == 1) { this.comboBoxCardinality.SelectedIndex = 3; } else if (this.m_rule.CardinalityMin == 1 && this.m_rule.CardinalityMax == -1) { this.comboBoxCardinality.SelectedIndex = 4; } this.UpdateBehavior(); }
private void toolStripButtonTemplateRemove_Click(object sender, EventArgs e) { if (this.treeViewTemplate.SelectedNode.Tag is DocTemplateDefinition) { DocTemplateDefinition dtd = (DocTemplateDefinition)this.treeViewTemplate.SelectedNode.Tag; if (treeViewTemplate.SelectedNode.Parent != null) { DocModelRuleEntity dme = (DocModelRuleEntity)this.treeViewTemplate.SelectedNode.Parent.Tag; dme.References.Remove(dtd); this.m_template.PropagateRule(this.treeViewTemplate.SelectedNode.Parent.FullPath); this.treeViewTemplate.SelectedNode.Remove(); } else { this.m_template.Type = null; this.treeViewTemplate.Nodes.Clear(); } UpdateCommands(); this.ContentChanged(this, EventArgs.Empty); return; } DocModelRule ruleTarget = this.treeViewTemplate.SelectedNode.Tag as DocModelRule; DocModelRule ruleParent = null; if (this.treeViewTemplate.SelectedNode.Parent != null) { ruleParent = this.treeViewTemplate.SelectedNode.Parent.Tag as DocModelRule; } if (ruleParent != null) { ruleParent.Rules.Remove(ruleTarget); } else { this.m_template.Rules.Remove(ruleTarget); } // copy to child templates (before clearing selection) this.m_template.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath); ruleTarget.Delete(); this.treeViewTemplate.SelectedNode.Remove(); this.ContentChanged(this, EventArgs.Empty); }
private void comboBoxTemplate_SelectedIndexChanged(object sender, EventArgs e) { DocModelRuleEntity sel = this.comboBoxTemplate.SelectedItem as DocModelRuleEntity; if (sel == null) { return; } if (sel.References.Count > 0) { DocTemplateDefinition docTemplateInner = sel.References[0]; DocTemplateUsage docConceptInner = ((DocTemplateItem)this.ConceptItem).RegisterParameterConcept(this.ConceptAttr.Identification, docTemplateInner); this.ConceptLeaf = docConceptInner; } }
private void toolStripButtonRuleRef_Click(object sender, EventArgs e) { TreeNode tnSelect = this.treeViewTemplate.SelectedNode; DocModelRuleEntity docRule = (DocModelRuleEntity)tnSelect.Tag as DocModelRuleEntity; if (docRule == null) { return; } DocEntity docEntity = this.m_project.GetDefinition(docRule.Name) as DocEntity; if (docEntity == null) { return; } using (FormSelectTemplate form = new FormSelectTemplate(null, this.Project, docEntity)) { if (form.ShowDialog(this) == DialogResult.OK && form.SelectedTemplate != null) { // check for possible recursion if (form.SelectedTemplate == this.m_template || form.SelectedTemplate.IsTemplateReferenced(this.m_template)) { MessageBox.Show("Recursive template referencing is not supported."); return; } DocTemplateDefinition dtd = form.SelectedTemplate; docRule.References.Add(dtd); TreeNode tnTemplate = LoadTemplateRuleNode(tnSelect, dtd, dtd.Name); if (dtd.Rules != null) { foreach (DocModelRule docTemplateRule in dtd.Rules) { LoadTemplateGraph(tnTemplate, docTemplateRule); } } this.m_template.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath); //LoadTemplateGraph(tnSelect, docRule); } } }
private void ChangeTemplate(DocTemplateDefinition docTemplateDefinition) { this.Template = docTemplateDefinition; // update link to template on concept or concept root if (this.Concept != null) { this.Concept.Definition = this.Template; } else if (this.ConceptRoot != null) { this.ConceptRoot.ApplicableTemplate = this.Template; this.ConceptRoot.ApplicableEntity = this.Project.GetDefinition(this.Template.Type) as DocEntity; } this.LoadTemplateGraph(); this.ContentChanged(this, EventArgs.Empty); }
private void ctlConcept_SelectionChanged(object sender, EventArgs e) { if (this.ctlConcept.CurrentAttribute != null) { SetContent(this.ctlConcept.CurrentAttribute); } else if (this.ctlConcept.Selection is DocModelRuleEntity) { DocModelRuleEntity dmr = (DocModelRuleEntity)this.ctlConcept.Selection; DocObject obj = null; this.m_map.TryGetValue(dmr.Name, out obj); this.SetContent(obj); } else { DocTemplateDefinition dtd = (DocTemplateDefinition)this.treeView.SelectedNode.Tag; this.SetContent(dtd); } }
public CellValue GetCell(int row, int col) { if (row < 0 || row >= this.m_listTemplate.Count) { return(CellValue.Unavailable); } if (col < 0 || col >= this.m_view.Exchanges.Count) { return(CellValue.Unavailable); } DocTemplateDefinition docTemplate = this.m_listTemplate[row]; DocExchangeDefinition docExchange = this.m_view.Exchanges[col]; foreach (DocTemplateUsage docUsage in this.m_root.Concepts) { if (docUsage.Definition == docTemplate) { foreach (DocExchangeItem docItem in docUsage.Exchanges) { if (docItem.Exchange == docExchange && docItem.Applicability == DocExchangeApplicabilityEnum.Export) { switch (docItem.Requirement) { case DocExchangeRequirementEnum.Mandatory: return(CellValue.Mandatory); case DocExchangeRequirementEnum.Optional: return(CellValue.Recommended); default: return(CellValue.None); } } } } } return(CellValue.None); }
private static string GenerateTemplateImage(DocTemplateDefinition docTemplate, Dictionary<string, DocObject> mapEntity, DocProject project, string path) { int cx = 0; int cy = 0; System.Drawing.Image image = IfcDoc.Format.PNG.FormatPNG.CreateTemplateDiagram(docTemplate, mapEntity, new Dictionary<System.Drawing.Rectangle, DocModelRule>(), project, null); if (image != null) { using (image) { cx = image.Width; cy = image.Height; string filepath = path + "\\" + docTemplate.Name.ToLower().Replace(' ', '-') + ".png"; image.Save(filepath, System.Drawing.Imaging.ImageFormat.Png); cx = cx / 2; cy = cy / 2; } } return "<br/><img src=\"" + docTemplate.Name.ToLower().Replace(' ', '-') + ".png\" width=\"" + cx + "\" height=\"" + cy + "\"/>"; }
public void SetCell(int row, int col, CellValue val) { DocTemplateDefinition docTemplate = this.m_listTemplate[row]; DocExchangeDefinition docExchange = this.m_view.Exchanges[col]; DocTemplateUsage docUsage = null; foreach (DocTemplateUsage eachUsage in this.m_root.Concepts) { if (eachUsage.Definition == docTemplate) { docUsage = eachUsage; break; } } if (docUsage == null) { docUsage = new DocTemplateUsage(); this.m_root.Concepts.Add(docUsage); docUsage.Definition = docTemplate; } DocExchangeRequirementEnum req = DocExchangeRequirementEnum.NotRelevant; switch (val) { case CellValue.Required: req = DocExchangeRequirementEnum.Mandatory; break; case CellValue.Optional: req = DocExchangeRequirementEnum.Optional; break; } docUsage.RegisterExchange(docExchange, req); }
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> /// /// </summary> /// <param name="selection">Selected template.</param> /// <param name="project">Projet containing templates.</param> /// <param name="entity">The entity for which templates are filtered.</param> public FormSelectTemplate(DocTemplateDefinition selection, DocProject project, DocEntity entity) : this() { this.m_selection = selection; this.m_project = project; this.m_entity = entity; // build map this.m_map = new Dictionary<string, DocObject>(); foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocEntity docEntity in docSchema.Entities) { if(!this.m_map.ContainsKey(docEntity.Name)) { m_map.Add(docEntity.Name, docEntity); } } foreach (DocType docType in docSchema.Types) { try { m_map.Add(docType.Name, docType); } catch { } } } } LoadTemplates(project.Templates); }
/// <summary> /// /// </summary> /// <param name="selection">Selected template.</param> /// <param name="project">Projet containing templates.</param> /// <param name="entity">The entity for which templates are filtered.</param> public FormSelectTemplate(DocTemplateDefinition selection, DocProject project, DocEntity entity) : this() { this.m_selection = selection; this.m_project = project; this.m_entity = entity; // build map this.m_map = new Dictionary <string, DocObject>(); foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocEntity docEntity in docSchema.Entities) { if (!this.m_map.ContainsKey(docEntity.Name)) { m_map.Add(docEntity.Name, docEntity); } } foreach (DocType docType in docSchema.Types) { try { m_map.Add(docType.Name, docType); } catch { } } } } LoadTemplates(null, project.Templates); }
private string FormatTemplateRule(DocTemplateDefinition template, string key) { foreach (DocModelRule rule in template.Rules) { string format = FormatRule(rule, key); if (format != null) { return format; } } return null; }
private void LoadTreeTemplate(TreeNode tnParent, DocTemplateDefinition docTemplate) { TreeNode tnTemplate = LoadNode(tnParent, docTemplate, docTemplate.Name, true); if(docTemplate.IsDisabled) { tnTemplate.ForeColor = Color.Gray; } if (docTemplate.Templates != null) { foreach (DocTemplateDefinition docSub in docTemplate.Templates) { LoadTreeTemplate(tnTemplate, docSub); } } }
private MethodInfo RegisterTemplate(DocTemplateDefinition dtd) { if (dtd == null || dtd.Rules == null) return null; MethodInfo methodexist = null; if (this.m_templates.TryGetValue(dtd, out methodexist)) return methodexist; Type[] paramtypes = null; DocModelRule[] parameters = dtd.GetParameterRules(); if(parameters != null && parameters.Length > 0) { paramtypes = new Type[parameters.Length]; for(int iParam = 0; iParam < parameters.Length; iParam++) { #if false DocModelRule param = parameters[iParam]; if (param is DocModelRuleAttribute) { DocDefinition paramtype = dtd.GetParameterType(param.Name, this.m_definitions); if (paramtype != null) { paramtypes[iParam] = RegisterType(paramtype.Name); } } else if(param is DocModelRuleEntity) { paramtypes[iParam] = RegisterType(param.Name); } #endif if(paramtypes[iParam] == null) { paramtypes[iParam] = typeof(string); // fallback } } } if (dtd.Type == null) return null; TypeBuilder tb = (System.Reflection.Emit.TypeBuilder)this.RegisterType(dtd.Type); if (tb == null) return null; string methodname = dtd.Name.Replace(' ', '_').Replace(':', '_').Replace('-', '_'); MethodBuilder method = tb.DefineMethod(methodname, MethodAttributes.Public, CallingConventions.HasThis, typeof(bool), paramtypes); ILGenerator generator = method.GetILGenerator(); foreach (DocModelRule docRule in dtd.Rules) { docRule.EmitInstructions(this, generator, dtd); } // if made it to the end, then successful, so return true generator.Emit(OpCodes.Ldc_I4_1); generator.Emit(OpCodes.Ret); return method; }
private void InitUsageFromTemplateRule(DocTemplateDefinition docTemp, DocTemplateDefinition docSource, DocModelRule docRule) { if (docRule is DocModelRuleEntity) { DocModelRuleEntity docRuleEntity = (DocModelRuleEntity)docRule; if (docRuleEntity.References.Contains(docSource)) { DocObject[] usagepath = new DocObject[] { docTemp }; ListViewItem lvi = new ListViewItem(); lvi.Tag = usagepath; lvi.Text = "[Template]"; lvi.SubItems.Add(docTemp.Name); this.listViewUsage.Items.Add(lvi); } } // recurse foreach(DocModelRule docInner in docRule.Rules) { InitUsageFromTemplateRule(docTemp, docSource, docInner); } }
private void TemplateReset(DocTemplateDefinition template) { template.Validation = null; foreach(DocTemplateDefinition sub in template.Templates) { TemplateReset(sub); } }
public void DoInsert() { if (this.m_template == null) { return; } if (this.treeViewTemplate.Nodes.Count == 0) { DocEntity docEntityBase = null; if (this.m_parent is DocTemplateDefinition) { string classname = ((DocTemplateDefinition)this.m_parent).Type; docEntityBase = this.m_project.GetDefinition(classname) as DocEntity; } // get selected entity DocEntity docEntityThis = this.m_project.GetDefinition(this.m_template.Type) as DocEntity; using (FormSelectEntity form = new FormSelectEntity(docEntityBase, docEntityThis, this.m_project, SelectDefinitionOptions.Entity)) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK && form.SelectedEntity != null) { this.m_template.Type = form.SelectedEntity.Name; this.LoadTemplateGraph(); this.ContentChanged(this, EventArgs.Empty); } } return; } if (this.m_attribute != null && !String.IsNullOrEmpty(this.m_attribute.DefinedType)) { DocTemplateDefinition docTemplate = this.m_template; DocAttribute docAttribute = this.m_attribute; string entityname = null; switch (this.m_attribute.DefinedType) { case "BOOLEAN": case "LOGICAL": case "BINARY": case "STRING": case "REAL": case "INTEGER": case "NUMBER": entityname = this.m_attribute.DefinedType; break; default: { // qualify schema DocObject docobj = null; if (!String.IsNullOrEmpty(this.m_template.Code)) { foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { if (docSchema.Name.Equals(this.m_template.Code, StringComparison.OrdinalIgnoreCase)) { docobj = docSchema.GetDefinition(docAttribute.DefinedType); break; } } } } if (docobj == null) { docobj = this.m_project.GetDefinition(docAttribute.DefinedType); } using (FormSelectEntity form = new FormSelectEntity((DocDefinition)docobj, null, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type)) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK && form.SelectedEntity != null) { entityname = form.SelectedEntity.Name; } } break; } } if (entityname != null) { // get or add attribute rule TreeNode tn = this.treeViewTemplate.SelectedNode; DocModelRuleAttribute docRuleAtt = null; if (this.treeViewTemplate.SelectedNode.Tag is DocModelRuleAttribute) { docRuleAtt = (DocModelRuleAttribute)this.treeViewTemplate.SelectedNode.Tag; } else { docRuleAtt = new DocModelRuleAttribute(); docRuleAtt.Name = docAttribute.Name; if (this.treeViewTemplate.SelectedNode.Tag is DocModelRuleEntity) { DocModelRuleEntity docRuleEnt = (DocModelRuleEntity)this.treeViewTemplate.SelectedNode.Tag; docRuleEnt.Rules.Add(docRuleAtt); } else if (this.treeViewTemplate.SelectedNode.Tag is DocTemplateDefinition) { docTemplate.Rules.Add(docRuleAtt); } tn = this.LoadTemplateGraph(tn, docRuleAtt); } // get and add entity rule DocModelRuleEntity docRuleEntity = new DocModelRuleEntity(); docRuleEntity.Name = entityname; docRuleAtt.Rules.Add(docRuleEntity); this.treeViewTemplate.SelectedNode = this.LoadTemplateGraph(tn, docRuleEntity); // copy to child templates docTemplate.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath); this.m_selection = docRuleEntity; this.ContentChanged(this, EventArgs.Empty); this.SelectionChanged(this, EventArgs.Empty); } } else { // pick attribute, including attribute that may be on subtype DocModelRule rule = null; if (this.treeViewTemplate.SelectedNode != null) { rule = this.treeViewTemplate.SelectedNode.Tag as DocModelRule; } //if (rule == null) // return; DocTemplateDefinition docTemplate = (DocTemplateDefinition)this.m_template; string typename = null; if (rule is DocModelRuleEntity) { DocModelRuleEntity docRuleEntity = (DocModelRuleEntity)rule; typename = docRuleEntity.Name; } else { // get applicable entity of target (or parent entity rule) typename = docTemplate.Type; } DocEntity docEntity = this.m_project.GetDefinition(typename) as DocEntity; if (docEntity == null) { // launch dialog for constraint using (FormConstraint form = new FormConstraint()) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK) { DocModelRuleConstraint docRuleConstraint = new DocModelRuleConstraint(); rule.Rules.Add(docRuleConstraint); docRuleConstraint.Description = form.Expression; docRuleConstraint.Name = form.Expression; // for viewing this.treeViewTemplate.SelectedNode = this.LoadTemplateGraph(this.treeViewTemplate.SelectedNode, docRuleConstraint); // copy to child templates docTemplate.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath); } } } else { // launch dialog to pick attribute of entity using (FormSelectAttribute form = new FormSelectAttribute(docEntity, this.m_project, null, true)) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK && form.Selection != null) { // then add and update tree DocModelRuleAttribute docRuleAttr = new DocModelRuleAttribute(); docRuleAttr.Name = form.Selection; if (rule != null) { rule.Rules.Add(docRuleAttr); } else { docTemplate.Rules.Add(docRuleAttr); } this.treeViewTemplate.SelectedNode = this.LoadTemplateGraph(this.treeViewTemplate.SelectedNode, docRuleAttr); // copy to child templates docTemplate.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath); } } } } }
private void toolStripMenuItemInsertTemplate_Click(object sender, EventArgs e) { TreeNode tn = this.treeView.SelectedNode; DocTemplateDefinition doctemplate = new DocTemplateDefinition(); if (tn != null && tn.Tag is DocTemplateDefinition) { // sub-template DocTemplateDefinition parent = (DocTemplateDefinition)tn.Tag; parent.Templates.Add(doctemplate); doctemplate.Type = parent.Type; // propagate rules if (parent.Rules != null) { foreach (DocModelRule docRule in parent.Rules) { doctemplate.Rules.Add((DocModelRule)docRule.Clone()); } } tn = LoadNode(tn, doctemplate, doctemplate.Name, true); this.treeView.SelectedNode = tn; } else { // root template this.m_project.Templates.Add(doctemplate); tn = this.treeView.Nodes[3]; // hard-coded tn = LoadNode(tn, doctemplate, doctemplate.Name, true); this.treeView.SelectedNode = tn; } toolStripMenuItemEditRename_Click(this, e); }
private static string FormatTemplate( DocProject docProject, DocTemplateDefinition def, List<ContentRef> listFigures, List<ContentRef> listTables, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema, Dictionary<DocObject, bool> included) { // format content StringBuilder sb = new StringBuilder(); // 1. manual content sb.Append(def.Documentation); // 2. instance diagram sb.Append(FormatDiagram(docProject, def, null, listFigures, mapEntity, mapSchema)); // 3. entity list { foreach (DocModelView docView in docProject.ModelViews) { if ((included == null || included.ContainsKey(docView)) && docView.Exchanges.Count > 0) { SortedList<string, DocTemplateUsage> mapUsage = new SortedList<string, DocTemplateUsage>(); foreach (DocConceptRoot docRoot in docView.ConceptRoots) { foreach (DocTemplateUsage docUsage in docRoot.Concepts) { if (docUsage.Definition == def && !mapUsage.ContainsKey(docRoot.ApplicableEntity.Name)) { mapUsage.Add(docRoot.ApplicableEntity.Name, docUsage); } } } if (mapUsage.Count > 0) { sb.AppendLine("<hr/>"); sb.AppendLine("<h4>" + docView.Name + "</h4>"); int cExchange = docView.Exchanges.Count; sb.AppendLine("<table class=\"exchange\">"); sb.Append("<tr><th>Entity</th>"); if (Properties.Settings.Default.Requirement) { foreach (DocExchangeDefinition docExchange in docView.Exchanges) { sb.Append("<th><a href=\"../views/"); sb.Append(MakeLinkName(docView)); sb.Append("/"); sb.Append(MakeLinkName(docExchange)); sb.Append(".htm\"><img width=\"16\" src=\"../../img/mvd-"); sb.Append(MakeLinkName(docExchange)); sb.Append(".png\" title=\""); sb.Append(docExchange.Name); sb.Append("\"/></a></th>"); sb.AppendLine(); } } sb.Append("</tr>"); foreach (string entname in mapUsage.Keys) { DocTemplateUsage docUsage = mapUsage[entname]; if (docUsage.Definition == def) { sb.Append("<tr><td><i>"); sb.Append(entname); sb.Append("</i></td>"); if (Properties.Settings.Default.Requirement) { foreach (DocExchangeDefinition docExchange in docView.Exchanges) { sb.Append("<td>"); DocExchangeRequirementEnum reqImport = DocExchangeRequirementEnum.NotRelevant; DocExchangeRequirementEnum reqExport = DocExchangeRequirementEnum.NotRelevant; foreach (DocExchangeItem dti in docUsage.Exchanges) { if (dti.Exchange == docExchange) { if (dti.Applicability == DocExchangeApplicabilityEnum.Import) { reqImport = dti.Requirement; } else if (dti.Applicability == DocExchangeApplicabilityEnum.Export) { reqExport = dti.Requirement; } } } AppendRequirement(sb, reqImport, 2); sb.Append("<br/>"); AppendRequirement(sb, reqExport, 2); sb.Append("</td>"); sb.AppendLine(); } } 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); } } } } } }
/// <summary> /// Generates documentation for template and all sub-templates recursively. /// </summary> /// <param name="docTemplate"></param> /// <param name="indexpath"></param> /// <param name="listFigures"></param> /// <param name="listTables"></param> private static void GenerateTemplate( DocProject docProject, DocTemplateDefinition docTemplate, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema, Dictionary<DocObject, bool> included, int[] indexpath, List<ContentRef> listFigures, List<ContentRef> listTables) { string pathTemplate = Properties.Settings.Default.OutputPath + @"\schema\templates\" + MakeLinkName(docTemplate) + ".htm"; using (FormatHTM htmTemplate = new FormatHTM(pathTemplate, mapEntity, mapSchema, included)) { htmTemplate.WriteHeader(docTemplate.Name, 2); string indexer = ""; foreach (int part in indexpath) { if (indexer.Length != 0) { indexer += "."; } indexer += part.ToString(); } htmTemplate.WriteLine( "\r\n" + "<script type=\"text/javascript\">\r\n" + "<!--\r\n" + " parent.index.location.replace(\"../toc-4.htm#" + indexer + "\");\r\n" + "//-->\r\n" + "</script>\r\n"); string tag = "h" + indexpath.Length.ToString(); // e.g. <h3> string id = MakeLinkName(docTemplate); htmTemplate.WriteLine("<" + tag + " class=\"std\">" + indexer + " " + docTemplate.Name + "</" + tag + ">"); string doc = FormatTemplate(docProject, docTemplate, listFigures, listTables, mapEntity, mapSchema, included); htmTemplate.WriteDocumentationForISO(doc, docTemplate, false); if (docProject.Examples != null) { List<DocExample> listExample = new List<DocExample>(); foreach (DocExample docExample in docProject.Examples) { BuildExampleList(listExample, docExample, docTemplate, included); } if (listExample.Count > 0) { htmTemplate.WriteLine("<p class=\"spec-head\">Examples:</p>"); htmTemplate.WriteLine("<ul>"); foreach (DocExample docExample in listExample) { if (docExample.Name != null) { htmTemplate.Write("<li><a href=\"../../annex/annex-e/"); htmTemplate.Write(MakeLinkName(docExample)); htmTemplate.Write(".htm\">"); htmTemplate.Write(docExample.Name); htmTemplate.Write("</a></li>"); htmTemplate.WriteLine(""); } } htmTemplate.WriteLine("</ul>"); } } // write url for incoming page link htmTemplate.WriteLinkTo(docTemplate); htmTemplate.WriteFooter(Properties.Settings.Default.Footer); } // recurse int iTemplate = 0; foreach (DocTemplateDefinition docSubTemplate in docTemplate.Templates) { if (included == null || included.ContainsKey(docSubTemplate)) { iTemplate++; int[] subindexpath = new int[indexpath.Length + 1]; indexpath.CopyTo(subindexpath, 0); subindexpath[subindexpath.Length - 1] = iTemplate; GenerateTemplate(docProject, docSubTemplate, mapEntity, mapSchema, included, subindexpath, listFigures, listTables); } } }
/// <summary> /// If matching figure exists, generates HTML including the figure and increments the figure count. /// </summary> /// <param name="docProject">The project</param> /// <param name="definition">Object for which to find figure.</param> /// <param name="dtd">Optional template for which to find figure.</param> /// <param name="caption">Caption of definition used in determining figure caption, e.g. 'Beam'</param> /// <param name="listFigures">List of figures for determining numbering; appended as applicable by function.</param> /// <returns></returns> private static string FormatFigure(DocProject docProject, DocObject definition, DocTemplateDefinition dtd, string caption, List<ContentRef> listFigures) { string title = null; string desc = null; if (!String.IsNullOrEmpty(caption)) { title = caption; desc = caption.Substring(0, 1).ToUpper() + caption.Substring(1); } else { title = "<i>" + definition.Name + "</i>"; desc = title; } StringBuilder sb = new StringBuilder(); if (definition is DocDefinition) //TODO: property set figures { DocSchema docSchema = docProject.GetSchemaOfDefinition((DocDefinition)definition); string filename = MakeLinkName(definition); if (dtd != null) { filename += "-" + MakeLinkName(dtd); } filename += ".png"; string filepath = Properties.Settings.Default.OutputPath + @"\figures\" + filename; if (System.IO.File.Exists(filepath)) { listFigures.Add(new ContentRef(desc, definition)); // "Sensor", "Port Use Definition" ==> "Sensor Port Use" string figuredef = "usage"; if (dtd != null) { figuredef = dtd.Name.ToLower(); } // Per ISO guidelines, all figures must be referenced from text. sb.Append("<p>Figure "); sb.Append(listFigures.Count); sb.Append(" illustrates "); sb.Append(title.ToLower()); sb.Append(" "); sb.Append(figuredef.ToLower()); sb.Append(".</p>\r\n"); // include the figure with formatting below per ISO sb.Append("<table><tr><td><img src=\"../../../figures/"); sb.Append(filename); sb.Append("\" alt=\""); sb.Append(figuredef); sb.Append("\"></td></tr><tr><td><p class=\"figure\">Figure "); sb.Append(listFigures.Count); sb.Append(" — "); sb.Append(desc); sb.Append(" "); sb.Append(figuredef); sb.Append("</p></td></tr></table>\r\n"); sb.AppendLine(); } } return sb.ToString(); }
private void LoadTemplate(TreeNode tnParent, DocTemplateDefinition template) { // add entity TreeNode tn = new TreeNode(); tn.Tag = template; tn.Text = template.Name; if (tnParent != null) { tnParent.Nodes.Add(tn); } else { this.treeView.Nodes.Add(tn); } if (this.m_selection == template) { this.treeView.SelectedNode = tn; } foreach (DocTemplateDefinition sub in template.Templates) { LoadTemplate(tn, sub); } }
public CheckGridConcept(DocTemplateDefinition docTemplate, DocModelView docView, DocProject docProject) { this.m_template = docTemplate; this.m_view = docView; this.m_project = docProject; }
internal static void ExportMvdTemplate(ConceptTemplate mvdTemplate, DocTemplateDefinition docTemplateDef, Dictionary<DocObject, bool> included, bool documentation) { ExportMvdObject(mvdTemplate, docTemplateDef, documentation); mvdTemplate.ApplicableEntity = docTemplateDef.Type; if (docTemplateDef.Rules != null && docTemplateDef.Rules.Count > 0) { mvdTemplate.Rules = new List<AttributeRule>(); foreach (DocModelRule docRule in docTemplateDef.Rules) { AttributeRule mvdAttr = new AttributeRule(); mvdTemplate.Rules.Add(mvdAttr); ExportMvdRule(mvdAttr, docRule); } } // recurse through sub-templates if (docTemplateDef.Templates != null && docTemplateDef.Templates.Count > 0) { foreach (DocTemplateDefinition docSub in docTemplateDef.Templates) { if (included == null || included.ContainsKey(docSub)) { if (mvdTemplate.SubTemplates == null) { mvdTemplate.SubTemplates = new List<ConceptTemplate>(); } ConceptTemplate mvdSub = new ConceptTemplate(); mvdTemplate.SubTemplates.Add(mvdSub); ExportMvdTemplate(mvdSub, docSub, included, documentation); } } } }
/// <summary> /// Expands list to include any inherited templates /// </summary> /// <param name="template"></param> /// <param name="list"></param> internal static void ExpandTemplateInheritance(DocTemplateDefinition template, List<DocTemplateDefinition> list) { if (template.Templates != null) { foreach (DocTemplateDefinition sub in template.Templates) { ExpandTemplateInheritance(sub, list); if (list.Contains(sub) && !list.Contains(template)) { list.Add(template); } } } }
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); }
private static void ImportMvdTemplate(ConceptTemplate mvdTemplate, DocTemplateDefinition docDef, Dictionary<EntityRule, DocModelRuleEntity> fixups) { ImportMvdObject(mvdTemplate, docDef); docDef.Type = mvdTemplate.ApplicableEntity; docDef.Rules.Clear(); if (mvdTemplate.Rules != null) { foreach (AttributeRule mvdRule in mvdTemplate.Rules) { DocModelRule docRule = ImportMvdRule(mvdRule, fixups); docDef.Rules.Add(docRule); } } // recurse through subtemplates if (mvdTemplate.SubTemplates != null) { foreach (ConceptTemplate mvdSub in mvdTemplate.SubTemplates) { DocTemplateDefinition docSub = docDef.GetTemplate(mvdSub.Uuid); if (docSub == null) { docSub = new DocTemplateDefinition(); docDef.Templates.Add(docSub); } ImportMvdTemplate(mvdSub, docSub, fixups); } } }
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); } } } } } }
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 } } } } }
private static void Dereference(DocExample docExample, DocTemplateDefinition docTemplate) { if (docExample.ApplicableTemplates != null && docExample.ApplicableTemplates.Contains(docTemplate)) { docExample.ApplicableTemplates.Remove(docTemplate); } if (docExample.Examples != null) { foreach (DocExample docSub in docExample.Examples) { Dereference(docSub, docTemplate); } } }
/// <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; } }
private void InitUsageFromTemplate(DocTemplateDefinition docTemp, DocTemplateDefinition docSource) { foreach (DocModelRule docRule in docTemp.Rules) { InitUsageFromTemplateRule(docTemp, docSource, docRule); } // recurse foreach(DocTemplateDefinition docSub in docTemp.Templates) { InitUsageFromTemplate(docSub, docSource); } }
/// <summary> /// Creates an instance diagram for a template. /// </summary> /// <param name="docTemplate"></param> /// <returns></returns> internal static Image CreateTemplateDiagram(DocTemplateDefinition docTemplate, Dictionary<string, DocObject> map, Dictionary<Rectangle, DocModelRule> layout, DocProject docProject, SEntity instance) { DocObject docTarget = null; if (docTemplate.Type == null || !map.TryGetValue(docTemplate.Type, out docTarget) || !(docTarget is DocEntity)) return null; DocEntity docEntity = (DocEntity)docTarget; DocSchema docSchema = docProject.GetSchemaOfDefinition(docEntity); // first, determine bounds of drawing List<int> lanes = new List<int>(); // keep track of position offsets in each lane for (int i = 0; i < 16; i++) { lanes.Add(0); } layout.Clear(); DrawEntity(null, 0, lanes, docEntity, null, docTemplate, null, map, layout, docProject, docSchema, instance); Rectangle rcBounds = new Rectangle(); foreach(Rectangle rc in layout.Keys) { if(rc.Right > rcBounds.Right) { rcBounds.Width = rc.Right; } if(rc.Bottom > rcBounds.Bottom) { rcBounds.Height = rc.Bottom; } } rcBounds.Width += FormatPNG.Border; rcBounds.Height += FormatPNG.Border; Image image = new Bitmap(rcBounds.Width, rcBounds.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); using (Graphics g = Graphics.FromImage(image)) { g.FillRectangle(Brushes.White, new Rectangle(0, 0, image.Width, image.Height)); lanes = new List<int>(); // keep track of position offsets in each lane for (int i = 0; i < 16; i++) { lanes.Add(0); } layout.Clear(); DrawEntity(g, 0, lanes, docEntity, null, docTemplate, null, map, layout, docProject, docSchema, instance); g.DrawRectangle(Pens.Black, 0, 0, rcBounds.Width - 1, rcBounds.Height - 1); } return image; }
private MethodInfo RegisterTemplate(DocTemplateDefinition dtd) { if (dtd == null || dtd.Rules == null) { return(null); } MethodInfo methodexist = null; if (this.m_templates.TryGetValue(dtd, out methodexist)) { return(methodexist); } Type[] paramtypes = null; DocModelRule[] parameters = dtd.GetParameterRules(); if (parameters != null && parameters.Length > 0) { paramtypes = new Type[parameters.Length]; for (int iParam = 0; iParam < parameters.Length; iParam++) { #if false DocModelRule param = parameters[iParam]; if (param is DocModelRuleAttribute) { DocDefinition paramtype = dtd.GetParameterType(param.Name, this.m_definitions); if (paramtype != null) { paramtypes[iParam] = RegisterType(paramtype.Name); } } else if (param is DocModelRuleEntity) { paramtypes[iParam] = RegisterType(param.Name); } #endif if (paramtypes[iParam] == null) { paramtypes[iParam] = typeof(string); // fallback } } } if (dtd.Type == null) { return(null); } TypeBuilder tb = (System.Reflection.Emit.TypeBuilder) this.RegisterType(dtd.Type); if (tb == null) { return(null); } string methodname; if (dtd.Name != null) { methodname = dtd.Name; } else { methodname = dtd.UniqueId; } methodname = methodname.Replace(' ', '_').Replace(':', '_').Replace('-', '_'); MethodBuilder method = tb.DefineMethod(methodname, MethodAttributes.Public, CallingConventions.HasThis, typeof(bool), paramtypes); ILGenerator generator = method.GetILGenerator(); foreach (DocModelRule docRule in dtd.Rules) { docRule.EmitInstructions(this, generator, dtd); } // if made it to the end, then successful, so return true generator.Emit(OpCodes.Ldc_I4_1); generator.Emit(OpCodes.Ret); return(method); }
/// <summary> /// Generates documentation for template and all sub-templates recursively. /// </summary> /// <param name="docTemplate"></param> /// <param name="indexpath"></param> /// <param name="listFigures"></param> /// <param name="listTables"></param> private static void GenerateTemplate( DocProject docProject, DocTemplateDefinition docTemplate, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema, Dictionary<DocObject, bool> included, int[] indexpath, List<ContentRef> listFigures, List<ContentRef> listTables, DocPublication docPublication, string path) { string pathTemplate = path + @"\schema\templates\" + MakeLinkName(docTemplate) + ".htm"; using (FormatHTM htmTemplate = new FormatHTM(pathTemplate, mapEntity, mapSchema, included)) { htmTemplate.WriteHeader(docTemplate.Name, 2, docPublication.Header); string indexer = ""; foreach (int part in indexpath) { if (indexer.Length != 0) { indexer += "."; } indexer += part.ToString(); } htmTemplate.WriteLine( "\r\n" + "<script type=\"text/javascript\">\r\n" + "<!--\r\n" + " parent.index.location.replace(\"../toc-4.htm#" + indexer + "\");\r\n" + "//-->\r\n" + "</script>\r\n"); string tag = "h" + indexpath.Length.ToString(); // e.g. <h3> string id = MakeLinkName(docTemplate); htmTemplate.WriteLine("<" + tag + " class=\"std\">" + indexer + " " + docTemplate.Name + "</" + tag + ">"); string doc = FormatTemplate(docProject, docTemplate, listFigures, listTables, mapEntity, mapSchema, included, path); htmTemplate.WriteDocumentationMarkup(doc, docTemplate, docPublication); // write formatted mvdXML //htmTemplate.WriteLine("<details open=\"open\">"); //htmTemplate.WriteLine("<summary>mvdXML</summary>"); ConceptTemplate mvdTemplate = new ConceptTemplate(); Program.ExportMvdTemplate(mvdTemplate, docTemplate, included, false); XmlSerializer ser = new XmlSerializer(typeof(ConceptTemplate)); StringBuilder mvdOutput = new StringBuilder(); using (System.IO.Stream streamMVD = new System.IO.MemoryStream()) { ser.Serialize(streamMVD, mvdTemplate, null); streamMVD.Position = 0; using(System.IO.StreamReader reader = new System.IO.StreamReader(streamMVD)) { while(!reader.EndOfStream) { string mvdLine = reader.ReadLine(); int pos = 0; while(pos < mvdLine.Length && mvdLine[pos] == ' ') { mvdOutput.Append("\t"); pos++; } // replace any leading spaces with tabs for proper formatting string mvdMark = mvdLine.Substring(pos, mvdLine.Length - pos); mvdOutput.AppendLine(mvdMark); } } } htmTemplate.WriteSummaryHeader("mvdXML Specification", false); htmTemplate.WriteLine("<div class=\"xsd\"><code class=\"xsd\">"); htmTemplate.WriteExpression(mvdOutput.ToString()); //... need to use tabs... htmTemplate.WriteLine("</code></div>"); htmTemplate.WriteSummaryFooter(); //htmTemplate.WriteLine("</details>"); if (docProject.Examples != null) { List<DocExample> listExample = new List<DocExample>(); foreach (DocExample docExample in docProject.Examples) { BuildExampleList(listExample, docExample, docTemplate, included); } if (listExample.Count > 0) { htmTemplate.WriteLine("<p class=\"spec-head\">Examples:</p>"); htmTemplate.WriteLine("<ul>"); foreach (DocExample docExample in listExample) { if (docExample.Name != null) { htmTemplate.Write("<li><a href=\"../../annex/annex-e/"); htmTemplate.Write(MakeLinkName(docExample)); htmTemplate.Write(".htm\">"); htmTemplate.Write(docExample.Name); htmTemplate.Write("</a></li>"); htmTemplate.WriteLine(""); } } htmTemplate.WriteLine("</ul>"); } } // write url for incoming page link htmTemplate.WriteLinkTo(docTemplate); htmTemplate.WriteFooter(docPublication.Footer); } // recurse int iTemplate = 0; foreach (DocTemplateDefinition docSubTemplate in docTemplate.Templates) { if (included == null || included.ContainsKey(docSubTemplate)) { iTemplate++; int[] subindexpath = new int[indexpath.Length + 1]; indexpath.CopyTo(subindexpath, 0); subindexpath[subindexpath.Length - 1] = iTemplate; GenerateTemplate(docProject, docSubTemplate, mapEntity, mapSchema, included, subindexpath, listFigures, listTables, docPublication, path); } } }
private bool TraceRule(DocTemplateDefinition template, DocModelRule rule, StringBuilder sb, SEntity ent, List<SEntity> population) { bool pass = true; if (rule is DocModelRuleConstraint) { DocModelRuleConstraint ruleCon = (DocModelRuleConstraint)rule; object result = TraceOperation(template, ruleCon.Expression, sb, ent, population, 0); if(result is bool && !((bool)result)) pass = false; } foreach(DocModelRule sub in rule.Rules) { bool eachpass = TraceRule(template, sub, sb, ent, population); if (!eachpass) pass = false; } return pass; }
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; 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) { // 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; } m_editcon = false; }
private object TraceOperation(DocTemplateDefinition template, DocOp op, StringBuilder sb, SEntity ent, List<SEntity> population, int level) { System.Collections.Hashtable hashtable = new System.Collections.Hashtable(); object result = op.Eval(ent, hashtable, template, null, null); if (hashtable.Count > 0) { // must evaluate all for uniqueness foreach (object other in population) { if (other == ent) // first instance will pass; following duplicate instances will fail break; // returning false means there's a duplicate (not unique). object otherresult = op.Eval(other, hashtable, template, null, null); if (otherresult is bool && !(bool)otherresult) { result = false; break; } } } if (result is bool && !((bool)result)) { for (int i = 0; i < level; i++ ) { sb.Append(" "); } sb.AppendLine(op.ToString(template) + "<br/>"); } // recurse if (op is DocOpLogical) { DocOpLogical oplog = (DocOpLogical)op; TraceOperation(template, oplog.ExpressionA, sb, ent, population, level + 1); TraceOperation(template, oplog.ExpressionB, sb, ent, population, level + 1); } return result; }
/// <summary> /// Builds list of items in order, using inherited concepts. /// </summary> /// <param name="entity"></param> /// <param name="template"></param> /// <param name="view"></param> private static DocTemplateItem[] FindTemplateItems(DocProject docProject, DocEntity entity, DocTemplateDefinition template, DocModelView view) { // inherited concepts first List<DocTemplateItem> listItems = new List<DocTemplateItem>(); DocEntity basetype = entity; bool inherit = true; while (basetype != null) { // find templates for base foreach (DocModelView docView in docProject.ModelViews) { if (view == docView || view.BaseView == docView.Name) { foreach (DocConceptRoot docRoot in docView.ConceptRoots) { if (docRoot.ApplicableEntity == basetype) { foreach (DocTemplateUsage eachusage in docRoot.Concepts) { if (eachusage.Definition == template) { // found it string[] parameters = template.GetParameterNames(); foreach (DocTemplateItem eachitem in eachusage.Items) { string[] values = new string[parameters.Length]; for (int iparam = 0; iparam < parameters.Length; iparam++) { values[iparam] = eachitem.GetParameterValue(parameters[iparam]); } // new (IfcDoc 4.9d): only add if we don't override by parameters matching exactly bool include = true; foreach (DocTemplateItem existitem in listItems) { bool samevalues = true; for (int iparam = 0; iparam < parameters.Length; iparam++) { string value = values[iparam]; string match = existitem.GetParameterValue(parameters[iparam]); if (match != value || (match != null && !match.Equals(value, StringComparison.Ordinal))) { samevalues = false; break; } } if (samevalues) { include = false; break; } } if (include) { listItems.Add(eachitem); } } inherit = !eachusage.Override; } } } } } } // inherit concepts from supertypes unless overriding if (basetype.BaseDefinition != null && inherit) { basetype = docProject.GetDefinition(basetype.BaseDefinition) as DocEntity; } else { basetype = null; } } return listItems.ToArray(); }
private void dataGridViewConceptRules_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0 || e.ColumnIndex < 0) { return; } // for button types, launch dialog DataGridViewCell cell = this.dataGridViewConceptRules.Rows[e.RowIndex].Cells[e.ColumnIndex]; DocDefinition docEntity = cell.Tag as DocDefinition; if (docEntity == null) { return; } DocDefinition docSelect = null; if (cell.Value != null && this.m_map.ContainsKey(cell.Value.ToString())) { docSelect = this.m_map[cell.Value.ToString()] as DocDefinition; } if (docEntity.Name != null && docEntity.Name.Equals("IfcReference")) { DocDefinition docDef = this.m_conceptroot.ApplicableEntity as DocDefinition; // special case for building reference paths using (FormReference form = new FormReference(this.m_project, docDef, this.m_map, cell.Value as string)) { DialogResult res = form.ShowDialog(this); if (res == System.Windows.Forms.DialogResult.OK) { if (form.ValuePath != null && form.ValuePath.StartsWith("\\")) { cell.Value = form.ValuePath.Substring(1); } else if (form.ValuePath == "") { cell.Value = String.Empty;// "\\"; } dataGridViewConceptRules_CellValidated(this, e); this.dataGridViewConceptRules.NotifyCurrentCellDirty(true); } } } else { // new: if a referenced concept template applies, then edit that; otherwise, edit type // get the model view DocTemplateDefinition docTemplateInner = null; DocModelRule docRule = this.m_columns[e.ColumnIndex]; if (docRule is DocModelRuleAttribute) { DocModelRuleAttribute dma = (DocModelRuleAttribute)docRule; if (dma.Rules.Count > 0 && dma.Rules[0] is DocModelRuleEntity) { DocModelRuleEntity dme = (DocModelRuleEntity)dma.Rules[0]; if (dme.References.Count == 1) { docTemplateInner = dme.References[0]; if (dma.Rules.Count > 1) { // prompt user to select which template... } } } } if (docTemplateInner != null) { DocTemplateItem docConceptItem = (DocTemplateItem)this.dataGridViewConceptRules.Rows[e.RowIndex].Tag; if (docConceptItem != null) { DocTemplateUsage docConceptInner = docConceptItem.RegisterParameterConcept(docRule.Identification, docTemplateInner); using (FormParameters form = new FormParameters()) { form.Project = this.m_project; form.ConceptRoot = this.m_conceptroot; form.ConceptItem = docConceptItem; form.ConceptLeaf = docConceptInner; form.CurrentInstance = this.m_instance; form.ShowDialog(this); } } } else { // set type of item using (FormSelectEntity form = new FormSelectEntity(docEntity, docSelect, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type)) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK && form.SelectedEntity != null) { cell.Value = form.SelectedEntity.Name; this.dataGridViewConceptRules.NotifyCurrentCellDirty(true); } } } } }