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 static CvtValuePath FromModelRule(DocModelRuleEntity docRuleEntity, DocProject docProject) { DocDefinition docDef = docProject.GetDefinition(docRuleEntity.Name); DocAttribute docAtt = null; string identifier = null; CvtValuePath pathInner = null; if (docDef is DocEntity && docRuleEntity.Rules.Count > 0 && docRuleEntity.Rules[0] is DocModelRuleAttribute) { DocModelRuleAttribute docRuleAtt = (DocModelRuleAttribute)docRuleEntity.Rules[0]; DocEntity docEnt = (DocEntity)docDef; docAtt = docEnt.ResolveAttribute(docRuleAtt.Name, docProject); if (docRuleAtt.Rules.Count > 0 && docRuleAtt.Rules[0] is DocModelRuleEntity) { DocModelRuleEntity docRuleInner = (DocModelRuleEntity)docRuleAtt.Rules[0]; pathInner = FromModelRule(docRuleInner, docProject); // look for identifier if (docRuleInner.Rules.Count > 1 && docRuleInner.Rules[1] is DocModelRuleAttribute) { DocModelRuleAttribute docRuleIndexAtt = (DocModelRuleAttribute)docRuleInner.Rules[1]; if (docRuleIndexAtt.Rules.Count > 0) { DocModelRuleEntity docRuleIndexEnt = (DocModelRuleEntity)docRuleIndexAtt.Rules[0]; if (docRuleIndexEnt.Rules.Count > 0 && docRuleIndexEnt.Rules[0] is DocModelRuleConstraint) { DocModelRuleConstraint docRuleIndexCon = (DocModelRuleConstraint)docRuleIndexEnt.Rules[0]; 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); } } } } } } } } CvtValuePath pathOuter = new CvtValuePath(docDef, docAtt, identifier, pathInner); return(pathOuter); }
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); }
private void toolStripButtonSetDefault_Click(object sender, EventArgs e) { TreeNode tnSelect = this.treeViewTemplate.SelectedNode; if (tnSelect.Tag is DocModelRuleEntity) { DocModelRuleEntity rule = (DocModelRuleEntity)tnSelect.Tag; rule.Identification = "Value"; } else if (tnSelect.Tag is DocModelRuleAttribute) { DocModelRuleAttribute rule = (DocModelRuleAttribute)tnSelect.Tag; rule.Identification = "Name"; } if (this.ContentChanged != null) { this.ContentChanged(this, EventArgs.Empty); } }
private DocModelRuleEntity ToModelRule() { if (this.Type == null) { return(null); } DocModelRuleEntity docRuleEntity = new DocModelRuleEntity(); docRuleEntity.Name = this.Type.Name; if (this.Property != null) { DocModelRuleAttribute docRuleAttr = new DocModelRuleAttribute(); docRuleAttr.Name = this.Property.Name; docRuleEntity.Rules.Add(docRuleAttr); docRuleAttr.ParentRule = docRuleEntity; if (this.InnerPath != null) { DocModelRuleEntity docInner = this.InnerPath.ToModelRule(); if (docInner != null) { docRuleAttr.Rules.Add(docInner); docInner.ParentRule = docRuleAttr; } if (this.Identifier != null) { // traverse to the default attribute DocModelRuleEntity docApplicableRule = docInner; if (this.InnerPath.Type.Name.Equals("IfcRelDefinesByProperties")) { // hack for back compat DocModelRuleAttribute docPsetAttr = docInner.Rules[0] as DocModelRuleAttribute; DocModelRuleEntity docPsetEnt = docPsetAttr.Rules[0] as DocModelRuleEntity; docApplicableRule = docPsetEnt; } DocModelRuleAttribute docWhereAttr = new DocModelRuleAttribute(); docWhereAttr.Name = "Name";//... dynamically check... docApplicableRule.Rules.Add(docWhereAttr); docWhereAttr.ParentRule = docApplicableRule; DocModelRuleEntity docWhereEnt = new DocModelRuleEntity(); docWhereEnt.Name = "IfcLabel";//... dynamically check... docWhereAttr.Rules.Add(docWhereEnt); docWhereEnt.ParentRule = docWhereAttr; DocModelRuleConstraint docRuleConstraint = new DocModelRuleConstraint(); // general case docWhereEnt.Rules.Add(docRuleConstraint); docRuleConstraint.ParentRule = docWhereEnt; DocOpLiteral oplit = new DocOpLiteral(); oplit.Operation = DocOpCode.LoadString; oplit.Literal = this.Identifier; DocOpStatement op = new DocOpStatement(); op.Operation = DocOpCode.CompareEqual; op.Value = oplit; DocOpReference opref = new DocOpReference(); opref.Operation = DocOpCode.NoOperation; // ldfld... opref.EntityRule = docWhereEnt; op.Reference = opref; docRuleConstraint.Expression = op; } } } return(docRuleEntity); }
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 static void DrawAttribute( Graphics g, int lane, List<int> lanes, DocEntity docEntity, DocModelView docView, DocModelRuleAttribute ruleAttribute, Dictionary<string, DocObject> map, int offset, Dictionary<Rectangle, DocModelRule> layout, DocProject docProject, DocSchema docSchema, SEntity instance) { int x = lane * CX + FormatPNG.Border; int y = lanes[lane] + FormatPNG.Border; // find the index of the attribute List<DocAttribute> listAttr = new List<DocAttribute>(); BuildAttributeList(docEntity, listAttr, map); int iAttr = -1; for (int i = 0; i < listAttr.Count; i++) { if (listAttr[i].Name.Equals(ruleAttribute.Name)) { // found it iAttr = i; break; } } if (iAttr >= 0) { DocAttribute docAttr = listAttr[iAttr]; object valueinstance = null; if (instance != null) { System.Reflection.FieldInfo field = instance.GetType().GetField(docAttr.Name); if(field != null) { valueinstance = field.GetValue(instance); } } // map it foreach (DocModelRule ruleEach in ruleAttribute.Rules) { if (ruleEach is DocModelRuleEntity) { DocModelRuleEntity ruleEntity = (DocModelRuleEntity)ruleEach; DocObject docObj = null; if (docSchema != null) { docObj = docSchema.GetDefinition(ruleEntity.Name); if (docObj is DocDefinitionRef) docObj = null; } if (docObj == null) { map.TryGetValue(ruleEntity.Name, out docObj); } { int dest = FormatPNG.Border; if (lanes.Count > lane + 1) { dest = lanes[lane + 1] + FormatPNG.Border; } if (docObj is DocEntity) { DocEntity docEntityTarget = (DocEntity)docObj; // resolve inverse attribute List<DocAttribute> listTarget = new List<DocAttribute>(); BuildAttributeList(docEntityTarget, listTarget, map); for (int i = 0; i < listTarget.Count; i++) { DocAttribute docAttrTarget = listTarget[i]; if (docAttr.Inverse != null && docAttrTarget.Name.Equals(docAttr.Inverse)) { // found it dest += CY * (i + 1); break; } else if (docAttrTarget.Inverse != null && docAttr.Name.Equals(docAttrTarget.Inverse)) { //...also need to check for type compatibility bool found = false; DocEntity docTest = docEntity; while (docTest != null) { if (docTest.Name.Equals(docAttrTarget.DefinedType)) { found = true; break; } if (docTest.BaseDefinition == null) break; DocObject docBase = null; if (map.TryGetValue(docTest.BaseDefinition, out docBase)) { docTest = docBase as DocEntity; } else { break; } } // found it if (found) { dest += CY * (i + 1); break; } } } // draw the entity, recurse DrawEntity(g, lane + 1, lanes, docEntityTarget, docView, null, ruleEntity, map, layout, docProject, docSchema, valueinstance); } else { int targetY = lanes[lane + 1] + FormatPNG.Border; if (g != null) { Brush brush = Brushes.Black; if (instance != null) { if (valueinstance == null) { brush = Brushes.Red; } else if(valueinstance is System.Collections.IList) { brush = Brushes.Blue; } else { string typename = valueinstance.GetType().Name; if (typename == ruleEntity.Name) { brush = Brushes.Lime; } else { brush = Brushes.Red; } } } g.FillRectangle(brush, x + CX, targetY, CX - DX, CY); g.DrawRectangle(Pens.Black, x + CX, targetY, CX - DX, CY); using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f)) { string content = ruleEntity.Name;//docObj.Name; foreach (DocModelRule ruleConstraint in ruleEntity.Rules) { if (ruleConstraint.Description != null && ruleConstraint.Description.StartsWith("Value=")) { content = ruleConstraint.Description.Substring(6); using (StringFormat fmt = new StringFormat()) { fmt.Alignment = StringAlignment.Far; g.DrawString(content, font, Brushes.White, new RectangleF(x + CX, targetY, CX - DX, CY), fmt); } } } g.DrawString(ruleEntity.Name, font, Brushes.White, x + CX, targetY); if (ruleEntity.Identification == "Value") { // mark rule serving as default value g.FillEllipse(Brushes.Green, new Rectangle(x + CX - DX - CY, y, CY, CY)); } } } // record rectangle if (layout != null) { layout.Add(new Rectangle(x + CX, targetY, CX - DX, CY), ruleEntity); } // increment lane offset for all lanes int minlane = targetY + CY * 2; int i = lane + 1; if (lanes[i] < minlane) { lanes[i] = minlane; } } // draw arrow if (g != null) { int x0 = x + CX - DX; int y0 = y + CY * (iAttr + 1) + CY / 2; int x1 = x + CX; int y1 = dest + CY / 2; int xM = x0 + DX / 2 - offset * 2; if(!String.IsNullOrEmpty(ruleAttribute.Identification)) { // mark the attribute as using parameter //g.DrawRectangle(Pens.Blue, x, y + CY * (iAttr + 1), CX - DX, CY); using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f, FontStyle.Regular)) { using (StringFormat fmt = new StringFormat()) { fmt.Alignment = StringAlignment.Near; g.DrawString(docAttr.Name, font, Brushes.Blue, x, y + CY * (iAttr + 1), fmt); } } } g.DrawLine(Pens.Black, x0, y0, xM, y0); g.DrawLine(Pens.Black, xM, y0, xM, y1); g.DrawLine(Pens.Black, xM, y1, x1, y1); } } } } if (g != null && ruleAttribute.Identification == "Name") { // mark rule serving as default name g.FillEllipse(Brushes.Blue, new Rectangle(x + CX - DX - CY, y + CY * (iAttr+1), CY, CY)); } #if false string card = ruleAttribute.GetCardinalityExpression(); if (g != null && card != null) { card = card.Trim(); switch (docAttr.GetAggregation()) { case DocAggregationEnum.SET: card = "S" + card; break; case DocAggregationEnum.LIST: card = "L" + card; break; } int px = x + CX - DX; int py = y + CY * (iAttr + 1); g.FillRectangle(Brushes.White, px - CX / 5, py, CX / 5, CY); using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f, FontStyle.Regular)) { using (StringFormat fmt = new StringFormat()) { fmt.Alignment = StringAlignment.Far; g.DrawString(card, font, Brushes.Blue, px, py, fmt); } } } #endif } }
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) { #if false // constraints now edited at operations // 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); } } #endif } 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 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); } } } } }
internal static DocModelRule ImportMvdRule(AttributeRule mvdRule, Dictionary<EntityRule, DocModelRuleEntity> fixups) { DocModelRuleAttribute docRule = new DocModelRuleAttribute(); docRule.Name = mvdRule.AttributeName; docRule.Description = mvdRule.Description; docRule.Identification = mvdRule.RuleID; //ImportMvdCardinality(docRule, mvdRule.Cardinality); if (mvdRule.EntityRules != null) { foreach (EntityRule mvdEntityRule in mvdRule.EntityRules) { DocModelRuleEntity docRuleEntity = new DocModelRuleEntity(); docRuleEntity.Name = mvdEntityRule.EntityName; docRuleEntity.Description = mvdEntityRule.Description; docRuleEntity.Identification = mvdEntityRule.RuleID; //ImportMvdCardinality(docRule, mvdRule.Cardinality); docRule.Rules.Add(docRuleEntity); if (mvdEntityRule.AttributeRules != null) { foreach (AttributeRule mvdAttributeRule in mvdEntityRule.AttributeRules) { DocModelRule docRuleAttribute = ImportMvdRule(mvdAttributeRule, fixups); docRuleEntity.Rules.Add(docRuleAttribute); } } if (mvdEntityRule.Constraints != null) { foreach (Constraint mvdConstraint in mvdEntityRule.Constraints) { DocModelRuleConstraint docRuleConstraint = new DocModelRuleConstraint(); docRuleConstraint.Description = mvdConstraint.Expression; docRuleEntity.Rules.Add(docRuleConstraint); } } if(mvdEntityRule.References != null) { // add it later, as referenced templates may not necessarily be loaded yet fixups.Add(mvdEntityRule, docRuleEntity); } } } if (mvdRule.Constraints != null) { foreach (Constraint mvdConstraint in mvdRule.Constraints) { DocModelRuleConstraint docRuleConstraint = new DocModelRuleConstraint(); docRuleConstraint.Description = mvdConstraint.Expression; docRule.Rules.Add(docRuleConstraint); } } return docRule; }