private TreeNode LoadTemplateGraph(TreeNode tnParent, DocModelRule docRule) { TreeNode tnRule = LoadTemplateRuleNode(tnParent, docRule, docRule.Name); UpdateTemplateGraph(tnRule); tnRule.Nodes.Clear(); foreach (DocModelRule docSub in docRule.Rules) { LoadTemplateGraph(tnRule, docSub); } if (docRule is DocModelRuleEntity) { DocModelRuleEntity dme = (DocModelRuleEntity)docRule; foreach (DocTemplateDefinition dtd in dme.References) { TreeNode tnTemplate = LoadTemplateRuleNode(tnRule, dtd, dtd.Name); if (dtd.Rules != null) { foreach (DocModelRule docTemplateRule in dtd.Rules) { LoadTemplateGraph(tnTemplate, docTemplateRule); } } } } return(tnRule); }
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; } docRule.References.Add(form.SelectedTemplate); LoadTemplateGraph(tnSelect, docRule); } } }
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 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 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); } }
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 SEntity Pick(Point pt, out int iAttr, out DocAttribute docAttribute, out Rectangle rc) { docAttribute = null; iAttr = -1; rc = new Rectangle(); foreach (Rectangle rect in this.m_hitmap.Keys) { if (rect.Contains(pt)) { rc = rect; iAttr = (pt.Y - rc.Top) / FormatPNG.CY - 1; SEntity sel = this.m_hitmap[rc]; if (sel is DocTemplateDefinition) { return(sel); } else { DocModelRuleEntity ruleEntity = sel as DocModelRuleEntity; DocEntity docEntity = null; if (ruleEntity != null) { DocObject docObjRef = null; if (this.m_template != null && !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)) { docObjRef = docSchema.GetDefinition(ruleEntity.Name); break; } } } } if (docObjRef == null) { docObjRef = this.m_project.GetDefinition(ruleEntity.Name); } if (docObjRef is DocEntity) { docEntity = (DocEntity)docObjRef; List <DocAttribute> listAttr = new List <DocAttribute>(); FormatPNG.BuildAttributeList(docEntity, listAttr, this.m_project); if (iAttr >= 0 && iAttr < listAttr.Count) { docAttribute = listAttr[iAttr]; foreach (DocModelRule ruleAttr in ruleEntity.Rules) { if (ruleAttr is DocModelRuleAttribute && ruleAttr.Name.Equals(docAttribute.Name)) { return(ruleAttr); } } } } } else if (this.m_template != null) { docEntity = this.m_project.GetDefinition(this.m_template.Type) as DocEntity; List <DocAttribute> listAttr = new List <DocAttribute>(); FormatPNG.BuildAttributeList(docEntity, listAttr, this.m_project); if (iAttr >= 0 && iAttr < listAttr.Count) { docAttribute = listAttr[iAttr]; if (this.m_template.Rules != null) { foreach (DocModelRule ruleAttr in this.m_template.Rules) { if (ruleAttr is DocModelRuleAttribute && ruleAttr.Name.Equals(docAttribute.Name)) { return(ruleAttr); } } } } } } return(sel); } } return(null); }
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); } } } } }
/// <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; } }
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; }