Exemplo n.º 1
0
        private void WriteList(System.IO.StreamWriter writer, SortedList <string, DocObject> sortlist)
        {
            foreach (string key in sortlist.Keys)
            {
                DocObject docEntity = sortlist[key];

                WriteItem(writer, docEntity, 0, docEntity.Name);

                if (docEntity is DocEntity)
                {
                    DocEntity docEnt = (DocEntity)docEntity;
                    foreach (DocAttribute docAttr in docEnt.Attributes)
                    {
                        WriteItem(writer, docAttr, 1, docEntity.Name);
                    }
                }
                else if (docEntity is DocEnumeration)
                {
                    DocEnumeration docEnum = (DocEnumeration)docEntity;
                    foreach (DocConstant docConst in docEnum.Constants)
                    {
                        WriteItem(writer, docConst, 1, docEntity.Name);
                    }
                }
                else if (docEntity is DocPropertySet)
                {
                    DocPropertySet docPset = (DocPropertySet)docEntity;
                    foreach (DocProperty docProp in docPset.Properties)
                    {
                        WriteItem(writer, docProp, 1, docEntity.Name);
                    }
                }
                else if (docEntity is DocPropertyEnumeration)
                {
                    DocPropertyEnumeration docPE = (DocPropertyEnumeration)docEntity;
                    foreach (DocPropertyConstant docPC in docPE.Constants)
                    {
                        WriteItem(writer, docPC, 1, docEntity.Name);
                    }
                }
                else if (docEntity is DocQuantitySet)
                {
                    DocQuantitySet docQset = (DocQuantitySet)docEntity;
                    foreach (DocQuantity docQuan in docQset.Quantities)
                    {
                        WriteItem(writer, docQuan, 1, docEntity.Name);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Load()
        {
            // prepare map
            Dictionary <string, DocObject> map = new Dictionary <string, DocObject>();

            foreach (DocSection docSection in this.m_project.Sections)
            {
                foreach (DocSchema docSchema in docSection.Schemas)
                {
                    foreach (DocEntity docEntity in docSchema.Entities)
                    {
                        map.Add(docEntity.Name, docEntity);
                    }
                    foreach (DocType docType in docSchema.Types)
                    {
                        map.Add(docType.Name, docType);
                    }
                    foreach (DocPropertySet docPropertySet in docSchema.PropertySets)
                    {
                        map.Add(docPropertySet.Name, docPropertySet);
                    }
                    foreach (DocQuantitySet docQuantitySet in docSchema.QuantitySets)
                    {
                        map.Add(docQuantitySet.Name, docQuantitySet);
                    }
                    foreach (DocPropertyEnumeration docPropertyEnumeration in docSchema.PropertyEnums)
                    {
                        map.Add(docPropertyEnumeration.Name, docPropertyEnumeration);
                    }
                }
            }

            // use tabs for simplicity
            using (System.IO.StreamReader reader = new System.IO.StreamReader(this.m_filename))
            {
                string   headerline = reader.ReadLine();
                string[] headercols = headerline.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                string blankline = reader.ReadLine(); // expect blank line

                // first column is name that identifies definition

                string[] locales = new string[headercols.Length];
                string[] fields  = new string[headercols.Length];
                for (int icol = 0; icol < headercols.Length; icol++)
                {
                    string col = headercols[icol];

                    int popen = col.IndexOf('(');
                    int pclos = col.IndexOf(')');
                    if (popen > 0 && pclos > popen)
                    {
                        locales[icol] = col.Substring(popen + 1, pclos - popen - 1);
                        fields[icol]  = col.Substring(0, popen);
                    }
                }

                // now rows
                while (!reader.EndOfStream)
                {
                    string rowdata = reader.ReadLine();

                    string[] rowcells = rowdata.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                    if (rowcells.Length > 1)
                    {
                        DocObject docObj     = null;
                        string[]  fullID     = rowcells[0].Split('.');
                        string    identifier = fullID[0];

                        if (map.TryGetValue(identifier, out docObj))
                        {
                            if (fullID.Length == 2)
                            {
                                string subType = fullID[1];

                                if (docObj is DocEntity)
                                {
                                    DocEntity entity = (DocEntity)docObj;

                                    foreach (DocAttribute attr in entity.Attributes)
                                    {
                                        if (attr.Name == subType)
                                        {
                                            docObj = attr;
                                            break;
                                        }
                                    }
                                }
                                if (docObj is DocEnumeration)
                                {
                                    DocEnumeration type = (DocEnumeration)docObj;

                                    foreach (DocConstant constnt in type.Constants)
                                    {
                                        docObj = type;
                                        break;
                                    }
                                }
                                if (docObj is DocPropertyEnumeration)
                                {
                                    DocPropertyEnumeration propEnum = (DocPropertyEnumeration)docObj;

                                    foreach (DocPropertyConstant propConst in propEnum.Constants)
                                    {
                                        docObj = propEnum;
                                        break;
                                    }
                                }
                                if (docObj is DocPropertySet)
                                {
                                    DocPropertySet propSet = (DocPropertySet)docObj;

                                    foreach (DocProperty docProp in propSet.Properties)
                                    {
                                        docObj = propSet;
                                        break;
                                    }
                                }
                                if (docObj is DocQuantitySet)
                                {
                                    DocQuantitySet quantSet = (DocQuantitySet)docObj;

                                    foreach (DocQuantity docQuant in quantSet.Quantities)
                                    {
                                        docObj = quantSet;
                                        break;
                                    }
                                }
                            }

                            for (int i = 1; i < rowcells.Length && i < headercols.Length; i++)
                            {
                                if (locales[i] != null)
                                {
                                    // find existing
                                    DocLocalization docLocalization = null;
                                    foreach (DocLocalization docLocal in docObj.Localization)
                                    {
                                        if (docLocal.Locale.Equals(locales[i]))
                                        {
                                            docLocalization = docLocal;
                                            break;
                                        }
                                    }

                                    // create new
                                    if (docLocalization == null)
                                    {
                                        docLocalization        = new DocLocalization();
                                        docLocalization.Locale = locales[i];
                                        docObj.Localization.Add(docLocalization);
                                    }

                                    string value = rowcells[i];
                                    if (value != null && value.StartsWith("\"") && value.EndsWith("\""))
                                    {
                                        // strip quotes
                                        value = value.Substring(1, value.Length - 2);
                                    }

                                    // update info
                                    switch (fields[i])
                                    {
                                    case "Name":
                                        docLocalization.Name = value;
                                        break;

                                    case "Description":
                                        docLocalization.Documentation = value;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void WriteList(System.IO.StreamWriter writer, SortedList <string, DocObject> sortlist)
        {
            foreach (string key in sortlist.Keys)
            {
                DocObject docEntity = sortlist[key];

                WriteItem(writer, docEntity, 0, docEntity.Name);

                if (docEntity is DocEntity)
                {
                    if ((this.m_scope & DocDefinitionScopeEnum.EntityAttribute) != 0)
                    {
                        DocEntity docEnt = (DocEntity)docEntity;
                        foreach (DocAttribute docAttr in docEnt.Attributes)
                        {
                            WriteItem(writer, docAttr, 1, docEntity.Name);
                        }
                    }
                }
                else if (docEntity is DocEnumeration)
                {
                    if ((this.m_scope & DocDefinitionScopeEnum.TypeConstant) != 0)
                    {
                        DocEnumeration docEnum = (DocEnumeration)docEntity;
                        foreach (DocConstant docConst in docEnum.Constants)
                        {
                            WriteItem(writer, docConst, 1, docEntity.Name);
                        }
                    }
                }
                else if (docEntity is DocPropertySet)
                {
                    if ((this.m_scope & DocDefinitionScopeEnum.PsetProperty) != 0)
                    {
                        DocPropertySet docPset       = (DocPropertySet)docEntity;
                        DocEntity      docApp        = null;
                        DocEntity[]    docApplicable = docPset.GetApplicableTypeDefinitions(this.m_project);
                        if (docApplicable != null && docApplicable.Length > 0 && docApplicable[0] != null)
                        {
                            docApp = this.m_project.GetDefinition(docApplicable[0].BaseDefinition) as DocEntity;
                        }
                        foreach (DocProperty docProp in docPset.Properties)
                        {
                            // filter out leaf properties defined at common pset (e.g. Reference, Status)
                            DocProperty docSuper = this.m_project.FindProperty(docProp.Name, docApp);
                            if (docSuper == docProp || docSuper == null)
                            {
                                WriteItem(writer, docProp, 1, docEntity.Name);
                            }
                        }
                    }
                }
                else if (docEntity is DocPropertyEnumeration)
                {
                    if ((this.m_scope & DocDefinitionScopeEnum.PEnumConstant) != 0)
                    {
                        DocPropertyEnumeration docPE = (DocPropertyEnumeration)docEntity;
                        foreach (DocPropertyConstant docPC in docPE.Constants)
                        {
                            WriteItem(writer, docPC, 1, docEntity.Name);
                        }
                    }
                }
                else if (docEntity is DocQuantitySet)
                {
                    if ((this.m_scope & DocDefinitionScopeEnum.QsetQuantity) != 0)
                    {
                        DocQuantitySet docQset = (DocQuantitySet)docEntity;
                        foreach (DocQuantity docQuan in docQset.Quantities)
                        {
                            WriteItem(writer, docQuan, 1, docEntity.Name);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static QtoSetDef ExportQto(DocQuantitySet docPset)
        {
            string[] apptypes = new string[0];
            if (docPset.ApplicableType != null)
            {
                apptypes = docPset.ApplicableType.Split(',');
            }

            // convert to psd schema
            QtoSetDef psd = new QtoSetDef();
            psd.Name = docPset.Name;
            psd.Definition = docPset.Documentation;
            psd.Versions = new List<IfcVersion>();
            psd.Versions.Add(new IfcVersion());
            psd.Versions[0].version = "IFC4";
            psd.ApplicableTypeValue = docPset.ApplicableType;
            psd.ApplicableClasses = new List<ClassName>();
            foreach (string app in apptypes)
            {
                ClassName cln = new ClassName();
                cln.Value = app;
                psd.ApplicableClasses.Add(cln);
            }

            psd.QtoDefinitionAliases = new List<QtoDefinitionAlias>();
            foreach (DocLocalization docLocal in docPset.Localization)
            {
                QtoDefinitionAlias alias = new QtoDefinitionAlias();
                psd.QtoDefinitionAliases.Add(alias);
                alias.lang = docLocal.Locale;
                alias.Value = docLocal.Documentation;
            }

            psd.QtoDefs = new List<QtoDef>();
            foreach (DocQuantity docProp in docPset.Quantities)
            {
                QtoDef prop = new QtoDef();
                psd.QtoDefs.Add(prop);
                prop.Name = docProp.Name;
                prop.Definition = docProp.Documentation;

                prop.NameAliases = new List<NameAlias>();
                prop.DefinitionAliases = new List<DefinitionAlias>();
                foreach (DocLocalization docLocal in docProp.Localization)
                {
                    NameAlias na = new NameAlias();
                    prop.NameAliases.Add(na);
                    na.lang = docLocal.Locale;
                    na.Value = docLocal.Name;

                    DefinitionAlias da = new DefinitionAlias();
                    prop.DefinitionAliases.Add(da);
                    da.lang = docLocal.Locale;
                    da.Value = docLocal.Documentation;
                }

                prop.QtoType = docProp.QuantityType.ToString();
            }

            return psd;
        }
Exemplo n.º 5
0
 private void toolStripMenuItemInsertQuantityset_Click(object sender, EventArgs e)
 {
     TreeNode tn = this.treeView.SelectedNode;
     if (tn.Parent.Tag is DocSchema)
     {
         tn = tn.Parent;
     }
     DocSchema docSchema = (DocSchema)tn.Tag;
     DocQuantitySet docPset = new DocQuantitySet();
     docSchema.QuantitySets.Add(docPset);
     this.treeView.SelectedNode = this.LoadNode(tn.Nodes[5], docPset, docPset.Name, true);
     this.toolStripMenuItemEditRename_Click(sender, e);
 }