private void toolStripButtonConceptEntity_Click(object sender, EventArgs e) { DocConceptRoot docRoot = this.m_conceptroot; if (docRoot == null) { return; } using (FormSelectEntity form = new FormSelectEntity(null, docRoot.ApplicableEntity, this.m_project, SelectDefinitionOptions.Entity)) { if (form.ShowDialog(this) == DialogResult.OK) { docRoot.ApplicableEntity = form.SelectedEntity as DocEntity; } } }
private void buttonViewEntity_Click(object sender, EventArgs e) { DocModelView docView = (DocModelView)this.m_target; using(FormSelectEntity form = new FormSelectEntity(null, null, this.m_project, SelectDefinitionOptions.Entity)) { if(form.ShowDialog(this) == DialogResult.OK) { if (form.SelectedEntity != null) { docView.RootEntity = form.SelectedEntity.Name; } else { docView.RootEntity = null; } } } this.textBoxViewRoot.Text = docView.RootEntity; }
private void buttonEntityBase_Click(object sender, EventArgs e) { DocEntity docEntity = (DocEntity)this.m_target; DocObject docBase = null; if (docEntity.BaseDefinition != null) { this.m_map.TryGetValue(docEntity.BaseDefinition, out docBase); } using (FormSelectEntity form = new FormSelectEntity(null, (DocEntity)docBase, this.m_project, SelectDefinitionOptions.Entity)) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK && form.SelectedEntity != null) { docEntity.BaseDefinition = form.SelectedEntity.Name; this.textBoxEntityBase.Text = docEntity.BaseDefinition; } } }
private void buttonViewXsdAttribute_Click(object sender, EventArgs e) { using (FormSelectEntity form = new FormSelectEntity(null, null, this.m_project, SelectDefinitionOptions.Entity)) { if (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && form.SelectedEntity is DocEntity) { using(FormSelectAttribute formAttr = new FormSelectAttribute((DocEntity)form.SelectedEntity, this.m_project, null, false)) { if(formAttr.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { DocXsdFormat docFormat = new DocXsdFormat(); docFormat.Entity = form.SelectedEntity.Name; docFormat.Attribute = formAttr.SelectedAttribute.Name; DocModelView docView = (DocModelView)this.m_target; docView.XsdFormats.Add(docFormat); ListViewItem lvi = new ListViewItem(); lvi.Tag = docFormat; lvi.Text = docFormat.Entity; lvi.SubItems.Add(docFormat.Attribute); lvi.SubItems.Add(docFormat.XsdFormat.ToString()); lvi.SubItems.Add(docFormat.XsdTagless.ToString()); this.listViewViewXsd.Items.Add(lvi); lvi.Selected = true; } } } } }
private void buttonPropertyEnumInsert_Click(object sender, EventArgs e) { if (this.comboBoxPropertyType.SelectedIndex == 5) { // reference value -- pick type of column for table or time series DocObject docBase = null; if (this.m_map.TryGetValue("IfcValue", out docBase)) { using (FormSelectEntity form = new FormSelectEntity(docBase as DocDefinition, null, this.m_project, SelectDefinitionOptions.Type)) { if (form.ShowDialog(this) == DialogResult.OK && form.SelectedEntity != null) { ListViewItem lvi = new ListViewItem(); lvi.Tag = form.SelectedEntity; lvi.Text = form.SelectedEntity.Name; this.listViewPropertyEnums.Items.Add(lvi); this.SavePropertyEnums(); } } } } else { ListViewItem lvi = new ListViewItem(); this.listViewPropertyEnums.Items.Add(lvi); lvi.BeginEdit(); } }
private void buttonAttributeType_Click(object sender, EventArgs e) { using (FormSelectEntity form = new FormSelectEntity(null, null, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type)) { if (form.ShowDialog(this) == DialogResult.OK && form.SelectedEntity != null) { // find existing type or reference type in schema DocSchema docSchema = (DocSchema)this.m_path[1]; DocDefinition docDef = docSchema.GetDefinition(form.SelectedEntity.Name); if (docDef == null) { // generate link to schema foreach(DocSection docSection in this.m_project.Sections) { foreach (DocSchema docOtherSchema in docSection.Schemas) { docDef = docOtherSchema.GetDefinition(form.SelectedEntity.Name); if (docDef is DocType || docDef is DocEntity) { DocSchemaRef docSchemaReference = null; foreach(DocSchemaRef docSchemaRef in docSchema.SchemaRefs) { if (String.Equals(docSchemaRef.Name, docOtherSchema.Name, StringComparison.OrdinalIgnoreCase)) { docSchemaReference = docSchemaRef; break; } } if (docSchemaReference == null) { docSchemaReference = new DocSchemaRef(); docSchemaReference.Name = docOtherSchema.Name; docSchema.SchemaRefs.Add(docSchemaReference); } docDef = new DocDefinitionRef(); docDef.Name = form.SelectedEntity.Name; docSchemaReference.Definitions.Add((DocDefinitionRef)docDef); break; } } if (docDef != null) break; } } if (this.m_target is DocAttribute) { DocAttribute docAttr = (DocAttribute)this.m_target; if (docAttr.Definition != null && docAttr.Definition.DiagramRectangle != null) { // find page target, make page reference if(docDef is DocDefinitionRef) { DocDefinitionRef ddr = (DocDefinitionRef)docDef; // find existing page target foreach(DocPageTarget docPageTarget in docSchema.PageTargets) { if(docPageTarget.Definition == ddr) { // found it -- make page source DocPageSource docPageSource = new DocPageSource(); docPageTarget.Sources.Add(docPageSource); docDef = docPageSource; break; } } } if (docDef.DiagramRectangle == null) { docDef.DiagramRectangle = new DocRectangle(); docDef.DiagramNumber = docAttr.Definition.DiagramNumber; docDef.DiagramRectangle.X = docAttr.Definition.DiagramRectangle.X; docDef.DiagramRectangle.Y = docAttr.Definition.DiagramRectangle.Y; docDef.DiagramRectangle.Width = docAttr.Definition.DiagramRectangle.Width; docDef.DiagramRectangle.Height = docAttr.Definition.DiagramRectangle.Height; } } docAttr.Definition = docDef; docAttr.DefinedType = form.SelectedEntity.Name; this.textBoxAttributeType.Text = docAttr.DefinedType; } else if(this.m_target is DocDefined) { DocDefined docDefined = (DocDefined)this.m_target; if (docDefined.Definition.DiagramRectangle != null) { docDef.DiagramRectangle = new DocRectangle(); docDef.DiagramNumber = docDefined.Definition.DiagramNumber; docDef.DiagramRectangle.X = docDefined.Definition.DiagramRectangle.X; docDef.DiagramRectangle.Y = docDefined.Definition.DiagramRectangle.Y; docDef.DiagramRectangle.Width = docDefined.Definition.DiagramRectangle.Width; docDef.DiagramRectangle.Height = docDefined.Definition.DiagramRectangle.Height; } docDefined.Definition = docDef; docDefined.DefinedType = form.SelectedEntity.Name; this.textBoxAttributeType.Text = docDefined.DefinedType; } } } }
private void buttonPropertyData_Click(object sender, EventArgs e) { DocProperty docTemplate = (DocProperty)this.m_target; if(docTemplate.PropertyType == DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE) { // browse for property enumeration using(FormSelectPropertyEnum form = new FormSelectPropertyEnum(this.m_project, null)) { if (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { if (form.Selection != null) { docTemplate.PrimaryDataType = form.Selection.Name; } else { docTemplate.PrimaryDataType = String.Empty; } this.textBoxPropertyData.Text = docTemplate.PrimaryDataType; } } return; } string basetypename = "IfcValue"; switch (docTemplate.PropertyType) { case DocPropertyTemplateTypeEnum.P_REFERENCEVALUE: basetypename = "IfcObjectReferenceSelect"; break; } DocObject docobj = null; DocDefinition docEntity = null; if (this.m_map.TryGetValue(basetypename, out docobj)) { docEntity = (DocDefinition)docobj; } // get selected entity DocObject target = null; DocDefinition entity = null; if (docTemplate.PrimaryDataType != null && m_map.TryGetValue(docTemplate.PrimaryDataType, out target)) { entity = (DocDefinition)target; } using (FormSelectEntity form = new FormSelectEntity(docEntity, entity, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type)) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK && form.SelectedEntity != null) { docTemplate.PrimaryDataType = form.SelectedEntity.Name; this.textBoxPropertyData.Text = docTemplate.PrimaryDataType; } } }
private void buttonPropertyData_Click(object sender, EventArgs e) { DocProperty docTemplate = (DocProperty)this.m_target; string basetypename = "IfcValue"; switch (docTemplate.PropertyType) { case DocPropertyTemplateTypeEnum.P_REFERENCEVALUE: basetypename = "IfcObjectReferenceSelect"; break; } DocObject docobj = null; DocDefinition docEntity = null; if (this.m_map.TryGetValue(basetypename, out docobj)) { docEntity = (DocDefinition)docobj; } // get selected entity DocObject target = null; DocDefinition entity = null; if (docTemplate.PrimaryDataType != null && m_map.TryGetValue(docTemplate.PrimaryDataType, out target)) { entity = (DocDefinition)target; } using (FormSelectEntity form = new FormSelectEntity(docEntity, entity, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type)) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK && form.SelectedEntity != null) { docTemplate.PrimaryDataType = form.SelectedEntity.Name; this.textBoxPropertyDataPrimary.Text = docTemplate.PrimaryDataType; } } }
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); } } } } }
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); } } } } }
private void toolStripMenuItemInsertReference_Click(object sender, EventArgs e) { using(FormSelectEntity form = new FormSelectEntity(null, null, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type)) { if(form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && form.SelectedEntity != null) { // determine the schema DocSchema targetschema = null; foreach(DocSection docSection in this.m_project.Sections) { foreach(DocSchema docSchema in docSection.Schemas) { if(form.SelectedEntity is DocEntity && docSchema.Entities.Contains((DocEntity)form.SelectedEntity) || form.SelectedEntity is DocType && docSchema.Types.Contains((DocType)form.SelectedEntity)) { targetschema = docSchema; break; } } } if (targetschema == null) { return; } DocSchema sourceschema = (DocSchema)this.treeView.SelectedNode.Tag; if(sourceschema == targetschema) { MessageBox.Show(this, "The selected item is in the current schema; references may only be made to definitions from other schemas.", "Reference"); return; } // check for schema reference DocSchemaRef targetschemaref = null; TreeNode tnTargetSchema = null; foreach (DocSchemaRef docSchemaRef in sourceschema.SchemaRefs) { if(docSchemaRef.Name != null && docSchemaRef.Name.Equals(targetschema.Name, StringComparison.OrdinalIgnoreCase)) { // found it targetschemaref = docSchemaRef; int index = sourceschema.SchemaRefs.IndexOf(docSchemaRef); tnTargetSchema = this.treeView.SelectedNode.Nodes[6].Nodes[index]; break; } } if (targetschemaref == null) { targetschemaref = new DocSchemaRef(); targetschemaref.Name = targetschema.Name.ToUpper(); sourceschema.SchemaRefs.Add(targetschemaref); tnTargetSchema = LoadNode(this.treeView.SelectedNode.Nodes[6], targetschemaref, targetschemaref.Name, false); } // add definition reference DocDefinitionRef targetdef = null; foreach(DocDefinitionRef docDefRef in targetschemaref.Definitions) { if(docDefRef.Name.Equals(form.SelectedEntity.Name)) { targetdef = docDefRef; break; } } if(targetdef != null) { // select it... MessageBox.Show(this, "The selected item has already been referenced in this schema."); return; } targetdef = new DocDefinitionRef(); targetdef.Name = form.SelectedEntity.Name; InitDefinition(targetdef); targetschemaref.Definitions.Add(targetdef); TreeNode tnTargetDef = LoadNode(tnTargetSchema, targetdef, targetdef.Name, false); this.treeView.SelectedNode = tnTargetDef; } } }
private void toolStripMenuItemInsertAttribute_Click(object sender, EventArgs e) { // prompt user to select type (or primitive) using(FormSelectEntity form = new FormSelectEntity(null, null, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type)) { if(form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && form.SelectedEntity != null) { TreeNode tnParent = this.treeView.SelectedNode; DocSchema docSchema = (DocSchema)tnParent.Parent.Parent.Tag; DocEntity docEntity = (DocEntity)tnParent.Tag; DocAttribute docAttr = new DocAttribute(); docAttr.Name = String.Empty; docAttr.DefinedType = form.SelectedEntity.Name; docEntity.Attributes.Add(docAttr); // is the selected type within the same schema? if ((form.SelectedEntity is DocType && docSchema.Types.Contains((DocType)form.SelectedEntity)) || (form.SelectedEntity is DocEntity && docSchema.Entities.Contains((DocEntity)form.SelectedEntity))) { docAttr.Definition = form.SelectedEntity; //docAttr.DiagramLine.Add(new DocPoint(docEntity.DiagramRectangle.X + docEntity.DiagramRectangle.Width, docEntity.DiagramRectangle.Y + docEntity.Attributes.IndexOf(docAttr) * 100.0)); //docAttr.DiagramLine.Add(new DocPoint(form.SelectedEntity.DiagramRectangle.X, form.SelectedEntity.DiagramRectangle.Y + form.SelectedEntity.DiagramRectangle.Height / 2)); } else { // find existing reference DocDefinitionRef docDefTarget = null; foreach(DocSchemaRef docSchemaRef in docSchema.SchemaRefs) { foreach(DocDefinitionRef docDefinitionRef in docSchemaRef.Definitions) { if (docDefinitionRef.Name.Equals(form.SelectedEntity.Name)) { // found it docDefTarget = docDefinitionRef; break; } } if (docDefTarget != null) break; } if (docDefTarget == null) { // import it // find the applicable schema... DocSchema docTargetSchema = this.m_project.GetSchemaOfDefinition(form.SelectedEntity); DocSchemaRef docTargetSchemaRef = null; foreach(DocSchemaRef docSchemaRef in docSchema.SchemaRefs) { if(docSchemaRef.Name.Equals(docTargetSchema.Name)) { docTargetSchemaRef = docSchemaRef; break; } } if (docTargetSchemaRef == null) { docTargetSchemaRef = new DocSchemaRef(); docTargetSchemaRef.Name = docTargetSchema.Name; docSchema.SchemaRefs.Add(docTargetSchemaRef); } docDefTarget = new DocDefinitionRef(); docDefTarget.Name = form.SelectedEntity.Name; docDefTarget.DiagramRectangle = new DocRectangle(); docDefTarget.DiagramRectangle.X = docEntity.DiagramRectangle.X + docEntity.DiagramRectangle.Width + 100; docDefTarget.DiagramRectangle.Y = docEntity.DiagramRectangle.Y + (docEntity.Attributes.Count - 1) * 100; docDefTarget.DiagramRectangle.Width = 400.0; docDefTarget.DiagramRectangle.Height = 50.0; docTargetSchemaRef.Definitions.Add(docDefTarget); docAttr.Definition = docDefTarget; } else { docAttr.Definition = docDefTarget; } } // check if there's a page reference target -- use that if it exists foreach (DocPageTarget docPageTarget in docSchema.PageTargets) { if (docPageTarget.Definition == docAttr.Definition) { DocPageSource docPageSource = new DocPageSource(); docPageTarget.Sources.Add(docPageSource); //docPageSource.Target = docPageTarget; docPageSource.DiagramRectangle = new DocRectangle(); docPageSource.DiagramRectangle.X = docEntity.DiagramRectangle.X + docEntity.DiagramRectangle.Width + 100; docPageSource.DiagramRectangle.Y = docEntity.DiagramRectangle.Y + (docEntity.Attributes.Count - 1) * 100; docPageSource.DiagramRectangle.Width = 400.0; docPageSource.DiagramRectangle.Height = 50.0; docAttr.Definition = docPageSource; docAttr.DiagramLine.Add(new DocPoint(docEntity.DiagramRectangle.X + docEntity.DiagramRectangle.Width, docPageSource.DiagramRectangle.Y + docPageSource.DiagramRectangle.Height / 2)); docAttr.DiagramLine.Add(new DocPoint(docPageSource.DiagramRectangle.X, docPageSource.DiagramRectangle.Y + docPageSource.DiagramRectangle.Height / 2)); break; } } if (docAttr.DiagramLine.Count == 0 && docAttr.Definition.DiagramRectangle != null) { docAttr.DiagramLine.Add(new DocPoint(docEntity.DiagramRectangle.X + docEntity.DiagramRectangle.Width, docAttr.Definition.DiagramRectangle.Y + docAttr.Definition.DiagramRectangle.Height / 2)); docAttr.DiagramLine.Add(new DocPoint(docAttr.Definition.DiagramRectangle.X, docAttr.Definition.DiagramRectangle.Y + docAttr.Definition.DiagramRectangle.Height / 2)); docAttr.DiagramLabel = new DocRectangle(); docAttr.DiagramLabel.X = docAttr.DiagramLine[0].X; docAttr.DiagramLabel.Y = docAttr.DiagramLine[0].Y; docAttr.DiagramLabel.Width = 400.0; docAttr.DiagramLabel.Height = 50.0; } this.treeView.SelectedNode = this.LoadNode(tnParent, docAttr, docAttr.ToString(), false, docEntity.Attributes.Count - 1); toolStripMenuItemEditRename_Click(this, e); } } }
private void buttonPsetEntity_Click(object sender, EventArgs e) { DocObject target = null; DocEntity entity = null; // get selected entity if (this.m_target is DocVariableSet) { DocVariableSet docTemplate = (DocVariableSet)this.m_target; if (docTemplate.ApplicableType != null && m_map.TryGetValue(docTemplate.ApplicableType, out target)) { entity = (DocEntity)target; } using (FormSelectEntity form = new FormSelectEntity(null, entity, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Predefined)) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK && form.SelectedEntity != null) { if (String.IsNullOrEmpty(docTemplate.ApplicableType)) { docTemplate.ApplicableType = form.SelectedEntity.Name; } else { docTemplate.ApplicableType += "," + form.SelectedEntity.Name; } // append predefined type, if any if (form.SelectedConstant != null) { docTemplate.ApplicableType += "/" + form.SelectedConstant.Name; } this.LoadApplicability(); } } } }
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 buttonInsert_Click(object sender, EventArgs e) { DocDefinition docBase = this.m_base; DocDefinition docDefinition = null; // for now, clear it -- future: allow incremental replacement CvtValuePath valuepathouter = null; CvtValuePath valuepathinner = null; // keep building while (docBase != null) { using (FormSelectEntity formEntity = new FormSelectEntity(docBase, docDefinition, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type)) { if (formEntity.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && formEntity.SelectedEntity != null) { CvtValuePath valuepath = null; if (formEntity.SelectedEntity is DocEntity) { using (FormSelectAttribute formAttribute = new FormSelectAttribute((DocEntity)formEntity.SelectedEntity, this.m_project, null, false)) { if (formAttribute.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && formAttribute.SelectedAttribute != null) { string item = null; switch (formAttribute.SelectedAttribute.GetAggregation()) { case DocAggregationEnum.SET: // if set collection, then qualify by name // future: more intelligent UI for picking property sets, properties using (FormSelectItem formItem = new FormSelectItem()) { if (formItem.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { item = formItem.Item; } } break; case DocAggregationEnum.LIST: // if list collection, then qualify by index // future: more intelligent UI for picking list indices using (FormSelectItem formItem = new FormSelectItem()) { if (formItem.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { item = formItem.Item; } } break; } // now add entry to listview valuepath = new CvtValuePath(formEntity.SelectedEntity, formAttribute.SelectedAttribute, item, null); if (valuepathinner != null) { valuepathinner.InnerPath = valuepath; } valuepathinner = valuepath; if (valuepathouter == null) { valuepathouter = valuepath; } // drill in if (this.m_map.ContainsKey(formAttribute.SelectedAttribute.DefinedType)) { docBase = this.m_map[formAttribute.SelectedAttribute.DefinedType] as DocDefinition; } } else { break; } } } else if (formEntity.SelectedEntity is DocType) { valuepath = new CvtValuePath(formEntity.SelectedEntity, null, null, null); if (valuepathinner != null) { valuepathinner.InnerPath = valuepath; } valuepathinner = valuepath; if (valuepathouter == null) { valuepathouter = valuepath; } docBase = null; } } else { break; } } } this.LoadValuePath(valuepathouter); }