public FormSelectPropertyConstant(DocProject project, DocPropertyConstant selection) : this() { this.m_project = project; Dictionary <string, DocPropertyConstant> processed = new Dictionary <string, DocPropertyConstant>(); foreach (DocPropertyConstant constant in project.PropertyConstants) { ListViewItem lvi = new ListViewItem(); lvi.Tag = constant; lvi.Text = constant.Name + (processed.ContainsKey(constant.Name) ? "_" + BuildingSmart.Utilities.Conversion.GlobalId.Format(constant.Uuid) : ""); processed[constant.Name] = constant; lvi.ImageIndex = 0; this.listView.Items.Add(lvi); if (selection == constant) { lvi.Selected = true; } } }
private void SaveNode(TreeNode tn) { ChangeInfo info = (ChangeInfo)tn.Tag; if (tn.Checked) { if (info.Original == null) { // add new item if (info.Change is DocLocalization) { DocLocalization localChange = (DocLocalization)info.Change; ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag; DocObject docObj = (DocObject)parentinfo.Original; docObj.RegisterLocalization(localChange.Locale, localChange.Name, localChange.Documentation); } else if (info.Change is DocAttribute) { DocAttribute localAttr = (DocAttribute)info.Change; ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag; DocEntity docEntity = (DocEntity)parentinfo.Original; DocAttribute docAttr = (DocAttribute)localAttr.Clone(); docEntity.Attributes.Add(docAttr); } else if (info.Change is DocWhereRule) { DocWhereRule localAttr = (DocWhereRule)info.Change; ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag; DocEntity docEntity = (DocEntity)parentinfo.Original; DocWhereRule docAttr = (DocWhereRule)localAttr.Clone(); docEntity.WhereRules.Add(docAttr); } else if (info.Change is DocFunction) { DocFunction localAttr = (DocFunction)info.Change; ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag; DocSchema docSchema = (DocSchema)parentinfo.Original; DocFunction docAttr = (DocFunction)localAttr.Clone(); docSchema.Functions.Add(docAttr); } else if (info.Change is DocConstant) { this.ToString(); } else if (info.Change is DocProperty) { this.ToString(); DocProperty localProp = (DocProperty)info.Change; ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag; DocPropertySet docPset = (DocPropertySet)parentinfo.Original; DocProperty docProperty = (DocProperty)localProp.Clone(); docPset.Properties.Add(docProperty); } else if (info.Change is DocPropertyConstant) { this.ToString(); DocPropertyConstant localProp = (DocPropertyConstant)info.Change; ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag; DocPropertyEnumeration docPset = (DocPropertyEnumeration)parentinfo.Original; DocPropertyEnumeration docEnumChange = (DocPropertyEnumeration)parentinfo.Change; int index = docEnumChange.Constants.IndexOf(localProp); DocPropertyConstant docProperty = (DocPropertyConstant)localProp.Clone(); docPset.Constants.Insert(index, docProperty); } else { this.ToString(); } } else if (info.Change == null) { // removal of definition if (info.Original is DocAttribute) { DocAttribute docAttr = (DocAttribute)info.Original; ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag; DocEntity docEntity = (DocEntity)parentinfo.Original; docEntity.Attributes.Remove(docAttr); docAttr.Delete(); } else { this.ToString(); } } else { // change of documentation info.Original.Name = info.Change.Name; info.Original.Documentation = info.Change.Documentation; if (info.Original is DocWhereRule) { DocWhereRule whereOriginal = (DocWhereRule)info.Original; DocWhereRule whereChange = (DocWhereRule)info.Change; whereOriginal.Expression = whereChange.Expression; } else if (info.Original is DocFunction) { DocFunction whereOriginal = (DocFunction)info.Original; DocFunction whereChange = (DocFunction)info.Change; whereOriginal.Expression = whereChange.Expression; } } } foreach (TreeNode tnSub in tn.Nodes) { SaveNode(tnSub); } }
private static void extractListings(DocProject project, DocProperty property, Dictionary <string, DocPropertyEnumeration> encounteredPropertyEnumerations) { project.Properties.Add(property); if (string.IsNullOrEmpty(property.SecondaryDataType)) { property.SecondaryDataType = null; } else if (property.PropertyType == DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE && property.Enumeration == null) { string[] fields = property.SecondaryDataType.Split(":".ToCharArray()); if (fields.Length == 1) { string name = fields[0]; foreach (DocPropertyEnumeration docEnumeration in project.PropertyEnumerations) { if (string.Compare(name, docEnumeration.Name) == 0) { property.Enumeration = docEnumeration; property.SecondaryDataType = null; break; } } } else if (fields.Length == 2) { string name = fields[0]; DocPropertyEnumeration propertyEnumeration = null; if (encounteredPropertyEnumerations.TryGetValue(name, out propertyEnumeration)) { property.SecondaryDataType = null; property.Enumeration = propertyEnumeration; } else { foreach (DocPropertyEnumeration docEnumeration in project.PropertyEnumerations) { if (string.Compare(name, docEnumeration.Name) == 0) { property.Enumeration = docEnumeration; property.SecondaryDataType = null; break; } } if (property.Enumeration == null) { property.Enumeration = new DocPropertyEnumeration() { Name = name }; project.PropertyEnumerations.Add(property.Enumeration = property.Enumeration); encounteredPropertyEnumerations[name] = property.Enumeration; foreach (string str in fields[1].Split(",".ToCharArray())) { string constantName = str.Trim(); DocPropertyConstant constant = null; foreach (DocPropertyConstant docConstant in project.PropertyConstants) { if (string.Compare(docConstant.Name, constantName) == 0) { constant = docConstant; break; } } if (constant == null) { constant = new DocPropertyConstant() { Name = constantName }; project.PropertyConstants.Add(constant); } property.Enumeration.Constants.Add(constant); } property.SecondaryDataType = null; } } } } foreach (DocProperty element in property.Elements) { extractListings(project, element, encounteredPropertyEnumerations); } }
private void toolStripMenuItemInsertPropertyConstant_Click(object sender, EventArgs e) { TreeNode tnParent = this.treeView.SelectedNode; DocPropertyEnumeration docEnum = (DocPropertyEnumeration)tnParent.Tag; DocPropertyConstant docConst = new DocPropertyConstant(); docEnum.Constants.Add(docConst); this.treeView.SelectedNode = this.LoadNode(tnParent, docConst, docConst.ToString(), false); toolStripMenuItemEditRename_Click(this, e); }
private void LoadFile(string filename) { this.SetCurrentFile(filename); this.m_lastid = 0; this.m_instances.Clear(); this.m_mapTree.Clear(); this.m_clipboard = null; this.m_project = null; string ext = System.IO.Path.GetExtension(this.m_file).ToLower(); try { switch (ext) { case ".ifcdoc": using (FormatSPF format = new FormatSPF(this.m_file, SchemaDOC.Types, this.m_instances)) { format.Load(); } break; case ".mdb": using (FormatMDB format = new FormatMDB(this.m_file, SchemaDOC.Types, this.m_instances)) { format.Load(); } break; } } catch (Exception x) { MessageBox.Show(this, x.Message, "Error", MessageBoxButtons.OK); // force new as state is now invalid this.m_modified = false; this.toolStripMenuItemFileNew_Click(this, EventArgs.Empty); return; } List<SEntity> listDelete = new List<SEntity>(); List<DocTemplateDefinition> listTemplate = new List<DocTemplateDefinition>(); // get the project, determine the next OID to use foreach (SEntity o in this.m_instances.Values) { if (o is DocProject) { this.m_project = (DocProject)o; } else if (o is DocEntity) { DocEntity docent = (DocEntity)o; #if false // files before V5.3 had Description field; no longer needed so use regular Documentation field again. if (docent._Description != null) { docent.Documentation = docent._Description; docent._Description = null; } #endif } else if(o is DocAttribute) { #if false // files before V8.7 didn't have nullable tagless DocAttribute docAttr = (DocAttribute)o; if (docAttr.XsdTagless == false) { docAttr.XsdTagless = null; } #endif } else if (o is DocExchangeDefinition) { // files before V4.9 had Description field; no longer needed so use regular Documentation field again. DocExchangeDefinition docexchange = (DocExchangeDefinition)o; if (docexchange._Description != null) { docexchange.Documentation = docexchange._Description; docexchange._Description = null; } } else if (o is DocTemplateDefinition) { // files before V5.0 had Description field; no longer needed so use regular Documentation field again. DocTemplateDefinition doctemplate = (DocTemplateDefinition)o; if (doctemplate._Description != null) { doctemplate.Documentation = doctemplate._Description; doctemplate._Description = null; } listTemplate.Add((DocTemplateDefinition)o); } // ensure all objects have valid guid if (o is DocObject) { DocObject docobj = (DocObject)o; if (docobj.Uuid == Guid.Empty) { docobj.Uuid = Guid.NewGuid(); } #if false // ensure any image references are in lowercase if(docobj.Documentation != null && docobj.Documentation.Length > 0) { int i = 0; while (i != -1) { i = docobj.Documentation.IndexOf("../figures/", i + 1); if(i != -1) { int start = i + 11; int end = docobj.Documentation.IndexOf('"', start); if(end > start) { string strold = docobj.Documentation.Substring(start, end - start); string strnew = strold.ToLower(); docobj.Documentation = docobj.Documentation.Substring(0, start) + strnew + docobj.Documentation.Substring(end); System.Diagnostics.Debug.WriteLine(strnew); } } } } #endif } if (o.OID > this.m_lastid) { this.m_lastid = o.OID; } } if (this.m_project == null) { MessageBox.Show(this, "File is invalid; no project is defined.", "Error", MessageBoxButtons.OK); return; } // now capture any template definitions (upgrade in V3.5) foreach (DocModelView docModelView in this.m_project.ModelViews) { if (docModelView.ConceptRoots == null) { // must convert to new format docModelView.ConceptRoots = new List<DocConceptRoot>(); foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocEntity docEntity in docSchema.Entities) { if (docEntity.__Templates != null) { foreach (DocTemplateUsage docTemplateUsage in docEntity.__Templates) { // must generate or use existing concept root DocConceptRoot docConceptRoot = null; foreach (DocConceptRoot eachConceptRoot in docModelView.ConceptRoots) { if (eachConceptRoot.ApplicableEntity == docEntity) { docConceptRoot = eachConceptRoot; break; } } if (docConceptRoot == null) { docConceptRoot = new DocConceptRoot(); docConceptRoot.ApplicableEntity = docEntity; docModelView.ConceptRoots.Add(docConceptRoot); } docConceptRoot.Concepts.Add(docTemplateUsage); } } } } } } } #if false // temp fixup foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { //docSchema.PropertyEnums.Sort(); foreach (DocPropertyEnumeration docEnum in docSchema.PropertyEnums) { foreach(DocPropertyConstant docConst in docEnum.Constants) { docConst.Name = docConst.Name.ToUpper(); // ensure uppercase throughout switch(docConst.Name) { case "OTHER": docConst.RegisterLocalization("en", "(other)", "Value is not listed."); break; case "NOTKNOWN": docConst.RegisterLocalization("en", "(unknown)", "Value is unknown."); break; case "UNSET": docConst.RegisterLocalization("en", "(unset)", "Value has not been specified."); break; } } } } } #endif #if false // ensure property enumerations are defined (upgrade to V5.8) and provide localizations Dictionary<string, DocPropertyEnumeration> mapEnums = new Dictionary<string, DocPropertyEnumeration>(); foreach(DocSection docSection in this.m_project.Sections) { foreach(DocSchema docSchema in docSection.Schemas) { foreach(DocType docType in docSchema.Types) { EnsureLocalized(docType); } foreach(DocEntity docEntity in docSchema.Entities) { EnsureLocalized(docEntity); } foreach(DocFunction docFunction in docSchema.Functions) { EnsureLocalized(docFunction); } foreach(DocGlobalRule docRule in docSchema.GlobalRules) { EnsureLocalized(docRule); } foreach(DocPropertySet docPset in docSchema.PropertySets) { EnsureLocalized(docPset); foreach(DocProperty docProp in docPset.Properties) { EnsureLocalized(docProp); if (docProp.PropertyType == DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE) { // temporary migration string match = "PEnum_Status:"; if (docProp.SecondaryDataType.StartsWith(match)) { docProp.SecondaryDataType = "PEnum_ElementStatus:" + docProp.SecondaryDataType.Substring(match.Length); } string[] enumhost = docProp.SecondaryDataType.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (enumhost.Length == 2) { string enumname = enumhost[0]; DocPropertyEnumeration docEnum = null; if (docProp.PrimaryDataType != null && !mapEnums.TryGetValue(enumname, out docEnum)) { docEnum = new DocPropertyEnumeration(); docEnum.Name = enumname; docSchema.PropertyEnums.Add(docEnum); mapEnums.Add(docEnum.Name, docEnum); string[] enumvals = enumhost[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string val in enumvals) { DocPropertyConstant docConstant = new DocPropertyConstant(); docConstant.Name = val; docEnum.Constants.Add(docConstant); // localize constant StringBuilder sb = new StringBuilder(); // if constant is entirely uppercase, then convert such that only first character is uppercase for (int i = 0; i < val.Length; i++ ) { char ch = val[i]; if (ch == '_') { ch = ' '; } else if (Char.IsUpper(ch) && i > 0 && !Char.IsUpper(val[i - 1])) { sb.Append(" "); } else if(Char.IsUpper(ch) && i > 0 && Char.IsUpper(val[i-1])) { ch = Char.ToLower(ch); } sb.Append(ch); } // find description for constant string doc = null; int iDoc = docProp.Documentation.IndexOf(docConstant.Name + ":"); if(iDoc > 0) { int iTail = docProp.Documentation.IndexOfAny(new char[] { '.', ';', '\r', '\n'}, iDoc+1); if (iTail == -1) { iTail = docProp.Documentation.Length; } doc = docProp.Documentation.Substring(iDoc + docConstant.Name.Length + 2, iTail - iDoc - docConstant.Name.Length - 2); } docConstant.RegisterLocalization("en", sb.ToString(), doc); } } } } } } foreach(DocQuantitySet docQset in docSchema.QuantitySets) { EnsureLocalized(docQset); foreach(DocQuantity docQuantiy in docQset.Quantities) { EnsureLocalized(docQuantiy); } } } } #endif #if false // temp: garbage collection for files that didn't clean up properly StringBuilder sb = new StringBuilder(); this.m_project.Mark(); List<SEntity> collect = new List<SEntity>(); foreach (SEntity o in this.m_instances.Values) { if(!o.Existing) { collect.Add(o); } } for (int i = collect.Count - 1; i >= 0; i--) { SEntity ent = collect[i]; if(!ent.Existing) { sb.AppendLine("#" + ent.OID + "=" + ent.GetType().Name + ";"); this.m_instances.Remove(ent.OID); } } string sss = sb.ToString(); #endif // now clear out the lists going forward. LoadTree(); }